//! Loading for std::array primitive types //! using binary serialization, if supported template <class Archive, class T, size_t N> inline typename std::enable_if<traits::is_input_serializable<BinaryData<T>, Archive>::value && std::is_arithmetic<T>::value, void>::type CEREAL_LOAD_FUNCTION_NAME( Archive & ar, std::array<T, N> & array ) { ar( binary_data( array.data(), sizeof(array) ) ); }
//! Loading for std::array primitive types //! using binary serialization, if supported template <class Archive, class T, size_t N> inline typename std::enable_if<traits::is_input_serializable<BinaryData<T>, Archive>() && std::is_arithmetic<T>::value, void>::type load( Archive & ar, std::array<T, N> & array ) { ar( binary_data( array.data(), N * sizeof(T) ) ); }
//! Saving for std::array primitive types //! using binary serialization, if supported template <class Archive, class T, size_t N> inline typename std::enable_if<traits::is_output_serializable<BinaryData<T>, Archive>::value && std::is_arithmetic<T>::value, void>::type save( Archive & ar, std::array<T, N> const & array ) { ar( binary_data( array.data(), sizeof(array) ) ); }
int ZCE_General_Config_Table::select_one(unsigned int table_id, AI_IIJIMA_BINARY_DATA *conf_data) { sql_select_one(table_id, conf_data->index_1_, conf_data->index_2_); ZCE_SQLite_STMTHdl stmt_handler(sqlite_handler_); int ret = 0; ret = stmt_handler.prepare(sql_string_); if (ret != 0) { return ret; } bool hash_result = false; ret = stmt_handler.execute_stmt_sql(hash_result); if (ret != 0 ) { return ret; } if (false == hash_result) { return -1; } ZCE_SQLite_STMTHdl::BIN_Result binary_data((void *)conf_data->ai_iijima_data_, &(conf_data->ai_data_length_)); stmt_handler >> binary_data; stmt_handler >> conf_data->last_mod_time_; return 0; }
//! Saving for std::valarray arithmetic types, using binary serialization, if supported template<class Archive, class T> inline typename std::enable_if< traits::is_output_serializable<BinaryData<T>, Archive>::value && std::is_arithmetic<T>::value, void>::type CEREAL_SAVE_FUNCTION_NAME( Archive & ar, std::valarray<T> const & valarray) { ar(make_size_tag(static_cast<size_type>(valarray.size()))); // number of elements ar(binary_data(&valarray[0], valarray.size() * sizeof(T))); // &valarray[0] ok since guaranteed contiguous }
// Render message binary_data request::render(const binary_data & nl_delimiter) { // Make up title switch(m_req_method) { case REQUEST_GET: // GET m_title = const_get; m_title += const_space; b_has_body = false; break; case REQUEST_POST: // POST m_title = const_post; m_title += const_space; b_has_body = true; break; case REQUEST_OPTIONS: // OPTIONS m_title = const_options; m_title += const_space; b_has_body = true; break; case REQUEST_HEAD: // HEAD m_title = const_head; m_title += const_space; b_has_body = true; break; case REQUEST_PUT: // PUT m_title = const_put; m_title += const_space; b_has_body = true; break; case REQUEST_TRACE: // TRACE m_title = const_trace; m_title += const_space; b_has_body = true; break; case REQUEST_DELETE: // DELETE m_title = const_delete; m_title += const_space; b_has_body = true; break; case REQUEST_CONNECT: // CONNECT m_title = const_connect; m_title += const_space; b_has_body = true; break; case REQUEST_CUSTOM: // CUSTOM (extended) m_title = m_custom_method; m_title += const_space; b_has_body = true; break; } m_title += binary_data(m_uri.full()); m_title += const_space; m_title += m_http_version; // Render the message return message::render(nl_delimiter); }
//! Serialization for basic_string types, if binary data is supported template<class Archive, class CharT, class Traits, class Alloc> inline typename std::enable_if<traits::is_output_serializable<BinaryData<CharT>, Archive>(), void>::type save(Archive & ar, std::basic_string<CharT, Traits, Alloc> const & str) { // Save number of chars + the data ar( make_size_tag( str.size() ) ); ar( binary_data( str.data(), str.size() * sizeof(CharT) ) ); }
//! Serialization for std::vectors of arithmetic (but not bool) using binary serialization, if supported template <class Archive, class T, class A> inline typename std::enable_if<traits::is_output_serializable<BinaryData<T>, Archive>::value && std::is_arithmetic<T>::value && !std::is_same<T, bool>::value, void>::type save( Archive & ar, std::vector<T, A> const & vector ) { ar( make_size_tag( static_cast<size_type>(vector.size()) ) ); // number of elements ar( binary_data( vector.data(), vector.size() * sizeof(T) ) ); }
//! Serialization for basic_string types, if binary data is supported template<class Archive, class CharT, class Traits, class Alloc> inline typename std::enable_if<traits::is_input_serializable<BinaryData<CharT>, Archive>::value, void>::type CEREAL_LOAD_FUNCTION_NAME(Archive & ar, std::basic_string<CharT, Traits, Alloc> & str) { size_type size; ar( make_size_tag( size ) ); str.resize(static_cast<std::size_t>(size)); ar( binary_data( const_cast<CharT *>( str.data() ), static_cast<std::size_t>(size) * sizeof(CharT) ) ); }
//! Serialization for basic_string types, if binary data is supported template<class Archive, class CharT, class Traits, class Alloc> inline typename std::enable_if<traits::is_input_serializable<BinaryData<CharT>, Archive>(), void>::type load(Archive & ar, std::basic_string<CharT, Traits, Alloc> & str) { size_t size; ar( make_size_tag( size ) ); str.resize(size); ar( binary_data( &(*str.begin()), size * sizeof(CharT) ) ); }
//! Loading for std::valarray arithmetic types, using binary serialization, if supported template <class Archive, class T> inline typename std::enable_if<traits::is_input_serializable<BinaryData<T>, Archive>::value && std::is_arithmetic<T>::value, void>::type CEREAL_LOAD_FUNCTION_NAME( Archive & ar, std::valarray<T> & valarray ) { size_type valarraySize; ar( make_size_tag( valarraySize ) ); valarray.resize( static_cast<std::size_t>( valarraySize ) ); ar( binary_data( &valarray[0], static_cast<std::size_t>( valarraySize ) * sizeof(T) ) ); }
//! Serialization for std::vectors of arithmetic (but not bool) using binary serialization, if supported template <class Archive, class T, class A> inline typename std::enable_if<traits::is_input_serializable<BinaryData<T>, Archive>::value && std::is_arithmetic<T>::value && !std::is_same<T, bool>::value, void>::type load( Archive & ar, std::vector<T, A> & vector ) { size_type vectorSize; ar( make_size_tag( vectorSize ) ); vector.resize( static_cast<std::size_t>( vectorSize ) ); ar( binary_data( vector.data(), static_cast<std::size_t>( vectorSize ) * sizeof(T) ) ); }
int ZCE_General_Config_Table::replace_array(unsigned int table_id, const ARRARY_OF_AI_IIJIMA_BINARY *ary_ai_iijma) { //构造后面的SQL sql_replace_bind(table_id); ZCE_SQLite_STMTHdl stmt_handler(sqlite_handler_); int ret = 0; ret = stmt_handler.begin_transaction(); if (ret != 0) { return ret; } const size_t ary_size = ary_ai_iijma->size(); for (size_t i = 0; i < ary_size; ++i) { //感觉SQLite3的 STMT欠火候,第二次使用还要 ret = stmt_handler.prepare(sql_string_); if (ret != 0) { return ret; } ZCE_SQLite_STMTHdl::BIN_Param binary_data((void *)(*ary_ai_iijma)[i].ai_iijima_data_, (*ary_ai_iijma)[i].ai_data_length_); stmt_handler << (*ary_ai_iijma)[i].index_1_; stmt_handler << (*ary_ai_iijma)[i].index_2_; stmt_handler << binary_data; stmt_handler << (*ary_ai_iijma)[i].last_mod_time_; bool hash_result = false; ret = stmt_handler.execute_stmt_sql(hash_result); if (ret != 0) { return ret; } } ret = stmt_handler.commit_transction(); if (ret != 0) { return ret; } return 0; }
// static bool LLDispatcher::unpackMessage( LLMessageSystem* msg, LLDispatcher::key_t& method, LLUUID& invoice, LLDispatcher::sparam_t& parameters) { char buf[MAX_STRING]; /*Flawfinder: ignore*/ msg->getStringFast(_PREHASH_MethodData, _PREHASH_Method, method); msg->getUUIDFast(_PREHASH_MethodData, _PREHASH_Invoice, invoice); S32 size; S32 count = msg->getNumberOfBlocksFast(_PREHASH_ParamList); for (S32 i = 0; i < count; ++i) { // we treat the SParam as binary data (since it might be an // LLUUID in compressed form which may have embedded \0's,) size = msg->getSizeFast(_PREHASH_ParamList, i, _PREHASH_Parameter); if (size >= 0) { msg->getBinaryDataFast( _PREHASH_ParamList, _PREHASH_Parameter, buf, size, i, MAX_STRING-1); // If the last byte of the data is 0x0, this is either a normally // packed string, or a binary packed UUID (which for these messages // are packed with a 17th byte 0x0). Unpack into a std::string // without the trailing \0, so "abc\0" becomes std::string("abc", 3) // which matches const char* "abc". if (size > 0 && buf[size-1] == 0x0) { // special char*/size constructor because UUIDs may have embedded // 0x0 bytes. std::string binary_data(buf, size-1); parameters.push_back(binary_data); } else { // This is either a NULL string, or a string that was packed // incorrectly as binary data, without the usual trailing '\0'. std::string string_data(buf, size); parameters.push_back(string_data); } } } return true; }
//更新一条记录, int ZCE_General_Config_Table::replace_one(unsigned int table_id, const AI_IIJIMA_BINARY_DATA *conf_data) { //构造后面的SQL sql_replace_bind(table_id); ZCE_SQLite_STMTHdl stmt_handler(sqlite_handler_); int ret = 0; ret = stmt_handler.begin_transaction(); if (ret != 0) { return ret; } ret = stmt_handler.prepare(sql_string_); if (ret != 0) { return ret; } ZCE_SQLite_STMTHdl::BIN_Param binary_data((void *)conf_data->ai_iijima_data_, conf_data->ai_data_length_); stmt_handler << conf_data->index_1_; stmt_handler << conf_data->index_2_; stmt_handler << binary_data; stmt_handler << conf_data->last_mod_time_; bool hash_result = false; ret = stmt_handler.execute_stmt_sql(hash_result); if (ret != 0) { return ret; } ret = stmt_handler.commit_transction(); if (ret != 0) { return ret; } return 0; }
/*! @internal */ template <class Archive, class T> inline void serializeArray( Archive & ar, T & array, std::true_type /* binary_supported */ ) { ar( binary_data( array, sizeof(array) ) ); }
//查询所有的队列 int ZCE_General_Config_Table::select_array(unsigned int table_id, unsigned int startno, unsigned int numquery, ARRARY_OF_AI_IIJIMA_BINARY *ary_ai_iijma) { int ret = 0; //先计算数量 unsigned int num_counter = 0; ret = counter(table_id, startno, numquery, &num_counter); if (0 != ret) { return ret; } //没有找到数据 if (num_counter == 0) { return -1; } ary_ai_iijma->resize(num_counter); sql_select_array(table_id, startno, numquery); ZCE_SQLite_STMTHdl stmt_handler(sqlite_handler_); ret = stmt_handler.prepare(sql_string_); if (ret != 0) { return ret; } bool hash_result; ret = stmt_handler.execute_stmt_sql(hash_result); for (size_t i = 0; ret == 0 && hash_result == true; ++i) { stmt_handler >> (*ary_ai_iijma)[i].index_1_; stmt_handler >> (*ary_ai_iijma)[i].index_2_; int blob_len = stmt_handler.cur_column_bytes(); if (blob_len > AI_IIJIMA_BINARY_DATA::MAX_LEN_OF_AI_IIJIMA_DATA) { ZCE_LOG(RS_ERROR, "Error current column bytes length [%u] > " "AI_IIJIMA_BINARY_DATA::MAX_LEN_OF_AI_IIJIMA_DATA [%u]." , blob_len, AI_IIJIMA_BINARY_DATA::MAX_LEN_OF_AI_IIJIMA_DATA); return -1; } ZCE_SQLite_STMTHdl::BIN_Result binary_data((void *)(*ary_ai_iijma)[i].ai_iijima_data_, &((*ary_ai_iijma)[i].ai_data_length_)); stmt_handler >> binary_data; stmt_handler >> (*ary_ai_iijma)[i].last_mod_time_; ret = stmt_handler.execute_stmt_sql(hash_result); } //出现错误或者没有找到 if (0 != ret) { return ret; } return 0; }
inline typename std::enable_if<traits::is_output_serializable<BinaryData<T>, Archive>::value && std::is_arithmetic<T>::value, void>::type CEREAL_SAVE_FUNCTION_NAME(Archive &ar, std::array<T, N> const &array) { ar(binary_data(array.data(), sizeof(array))); }
namespace http { const binary_data request::const_get = binary_data("GET"); const binary_data request::const_post = binary_data("POST"); const binary_data request::const_options = binary_data("OPTIONS"); const binary_data request::const_head = binary_data("HEAD"); const binary_data request::const_put = binary_data("PUT"); const binary_data request::const_delete = binary_data("DELETE"); const binary_data request::const_trace = binary_data("TRACE"); const binary_data request::const_connect = binary_data("CONNECT"); request::request(void) { // Default options m_req_method = REQUEST_GET; m_uri = url("/"); m_http_version = const_http_ver1_1; } request::~request(void) { } // Copy constructor request::request(const request & r): message(r) { // Copy data m_uri = r.m_uri; m_req_method = r.m_req_method; m_http_version = r.m_http_version; m_custom_method = r.m_custom_method; } // Copy Operator request & request::operator=(const request & r) { // Copy parent message::operator =(r); // Copy data m_uri = r.m_uri; m_req_method = r.m_req_method; m_http_version = r.m_http_version; m_custom_method = r.m_custom_method; return *this; } // Render message binary_data request::render(const binary_data & nl_delimiter) { // Make up title switch(m_req_method) { case REQUEST_GET: // GET m_title = const_get; m_title += const_space; b_has_body = false; break; case REQUEST_POST: // POST m_title = const_post; m_title += const_space; b_has_body = true; break; case REQUEST_OPTIONS: // OPTIONS m_title = const_options; m_title += const_space; b_has_body = true; break; case REQUEST_HEAD: // HEAD m_title = const_head; m_title += const_space; b_has_body = true; break; case REQUEST_PUT: // PUT m_title = const_put; m_title += const_space; b_has_body = true; break; case REQUEST_TRACE: // TRACE m_title = const_trace; m_title += const_space; b_has_body = true; break; case REQUEST_DELETE: // DELETE m_title = const_delete; m_title += const_space; b_has_body = true; break; case REQUEST_CONNECT: // CONNECT m_title = const_connect; m_title += const_space; b_has_body = true; break; case REQUEST_CUSTOM: // CUSTOM (extended) m_title = m_custom_method; m_title += const_space; b_has_body = true; break; } m_title += binary_data(m_uri.full()); m_title += const_space; m_title += m_http_version; // Render the message return message::render(nl_delimiter); } // Parse message bool request::parse(const binary_data & dt_in, binary_data * dt_remain) { size_t commandend_pos, urlend_pos; binary_data _command_string; // Parse message if(!message::parse(dt_in, dt_remain)) return false; // Get Command if ((commandend_pos = m_title.find(const_space))== binary_data::npos) OONET_THROW_EXCEPTION(ExceptionWrongFormat, "This is not an http request message"); _command_string = m_title.sub_data(0, commandend_pos); if (_command_string.size() == 0) OONET_THROW_EXCEPTION(ExceptionWrongFormat, "This is not an http request message"); else if (_command_string == const_get) // GET m_req_method = REQUEST_GET; else if (_command_string == const_post) // POST m_req_method = REQUEST_POST; else if (_command_string == const_head) // HEAD m_req_method = REQUEST_HEAD; else if (_command_string == const_put) // PUT m_req_method = REQUEST_PUT; else if (_command_string == const_delete) // DELETE m_req_method = REQUEST_DELETE; else if (_command_string == const_options) // OPTIONS m_req_method = REQUEST_OPTIONS; else if (_command_string == const_trace) // TRACE m_req_method = REQUEST_TRACE; else if (_command_string == const_connect) // CONNECT m_req_method = REQUEST_CONNECT; else // CUSTOM (extended) { m_req_method = REQUEST_CUSTOM; m_custom_method = _command_string; } // Get URL commandend_pos ++; // Start one position lower if ((urlend_pos = m_title.find(const_space, commandend_pos)) == binary_data::npos) OONET_THROW_EXCEPTION(ExceptionWrongFormat, "This is not an http request message"); m_uri = url(title().sub_data(commandend_pos, urlend_pos - commandend_pos).to_string()); if (m_uri.full() == "") OONET_THROW_EXCEPTION(ExceptionWrongFormat, "This is not an http request message"); // Get version urlend_pos ++; m_http_version = m_title.get_from(urlend_pos); if ((m_http_version != const_http_ver1_1) && (m_http_version != const_http_ver1_0)) OONET_THROW_EXCEPTION(ExceptionWrongFormat, "This is not an http request message"); return true; } }; // !http namespace
/*! @internal */ template <class Archive, class T> inline void serializeArray( Archive & ar, T & array, std::true_type /* binary_supported */ ) { ar( binary_data( array, traits::sizeof_array<T>() * sizeof(typename std::remove_all_extents<T>::type) ) ); }