TEST(ObObj,Serialize_bool) { ObObj t; t.set_bool(true); int64_t len = t.get_serialize_size(); ASSERT_EQ(len,2); char *buf = (char *)malloc(len); int64_t pos = 0; ASSERT_EQ(t.serialize(buf,len,pos),OB_SUCCESS); ASSERT_EQ(pos,len); ObObj f; pos = 0; ASSERT_EQ(f.deserialize(buf,len,pos),OB_SUCCESS); ASSERT_EQ(pos,len); bool r = false; bool l = false; ASSERT_EQ(f.get_type(),t.get_type()); f.get_bool(r); t.get_bool(l); ASSERT_EQ(r,l); free(buf); }
ObExprObj ObExprObjTest::bool_obj(MyBool t1) { ObExprObj ret; ObObj obj; switch(t1) { case MY_TRUE: obj.set_bool(true); break; case MY_FALSE: obj.set_bool(false); break; default: obj.set_null(); break; } ret.assign(obj); return ret; }
int64_t ObSqlReadParam::get_basic_param_serialize_size(void) const { int64_t total_size = 0; ObObj obj; // consistency obj.set_int(get_is_read_consistency()); total_size += obj.get_serialize_size(); // result cached obj.set_int(get_is_result_cached()); total_size += obj.get_serialize_size(); // data version obj.set_int(get_data_version()); total_size += obj.get_serialize_size(); // table id obj.set_int(table_id_); total_size += obj.get_serialize_size(); // renamed table id obj.set_int(renamed_table_id_); total_size += obj.get_serialize_size(); // only_static_data obj.set_bool(only_static_data_); total_size += obj.get_serialize_size(); return total_size; }
////////////////////// SERIALIZATION /////////////////////// int ObSqlReadParam::serialize_basic_param(char * buf, const int64_t buf_len, int64_t & pos) const { ObObj obj; int ret = OB_SUCCESS; // read consistency if (ret == OB_SUCCESS) { obj.set_int(get_is_read_consistency()); if (OB_SUCCESS != (ret = obj.serialize(buf, buf_len, pos))) { TBSYS_LOG(WARN, "fail to serialize basic param. buf=%p, buf_len=%ld, pos=%ld, ret=%d", buf, buf_len, pos, ret); } } // result cached if (ret == OB_SUCCESS) { obj.set_int(get_is_result_cached()); if (OB_SUCCESS != (ret = obj.serialize(buf, buf_len, pos))) { TBSYS_LOG(WARN, "fail to serialize basic param. buf=%p, buf_len=%ld, pos=%ld, ret=%d", buf, buf_len, pos, ret); } } // data version if (ret == OB_SUCCESS) { obj.set_int(get_data_version()); if (OB_SUCCESS != (ret = obj.serialize(buf, buf_len, pos))) { TBSYS_LOG(WARN, "fail to serialize basic param. buf=%p, buf_len=%ld, pos=%ld, ret=%d", buf, buf_len, pos, ret); } } // table id if (OB_SUCCESS == ret) { if (OB_INVALID_ID != table_id_) { obj.set_int(table_id_); if (OB_SUCCESS != (ret = obj.serialize(buf, buf_len, pos))) { TBSYS_LOG(WARN, "fail to serialize table id = %lu", table_id_); } } else { TBSYS_LOG(WARN, "Invalid table_id_. table_id_=%ld", table_id_); ret = OB_INVALID_ARGUMENT; } } // renamed table id if (OB_SUCCESS == ret) { if (OB_INVALID_ID != renamed_table_id_) { obj.set_int(renamed_table_id_); if (OB_SUCCESS != (ret = obj.serialize(buf, buf_len, pos))) { TBSYS_LOG(WARN, "fail to serialize renamed table id = %lu", renamed_table_id_); } } else { TBSYS_LOG(WARN, "Invalid renamed_table_id_. renamed_table_id_=%ld", renamed_table_id_); ret = OB_INVALID_ARGUMENT; } } if (OB_SUCCESS == ret) { obj.set_bool(only_static_data_); if (OB_SUCCESS != (ret = obj.serialize(buf, buf_len, pos))) { TBSYS_LOG(WARN, "fail to serialize bool:ret[%d]", ret); } } return ret; }