Exemplo n.º 1
0
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);
}
    int ObSqlReadParam::deserialize_basic_param(const char * buf, const int64_t data_len, int64_t & pos)
    {
      ObObj obj;
      int ret = OB_SUCCESS;
      int64_t int_value = 0;
      // read consistency
      if (OB_SUCCESS == ret)
      {
        ret = obj.deserialize(buf, data_len, pos);
        if (OB_SUCCESS == ret)
        {
          ret = obj.get_int(int_value);
          if (OB_SUCCESS == ret)
          {
            //is read consistency
            set_is_read_consistency(int_value);
          }
          else
          {
            TBSYS_LOG(WARN, "fail to get int. obj type=%d", obj.get_type());
          }
        }
        else
        {
          TBSYS_LOG(WARN, "fail to deserialize obj. ret=%d", ret);
        }
      }
      // result cached
      if (OB_SUCCESS == ret)
      {
        ret = obj.deserialize(buf, data_len, pos);
        if (OB_SUCCESS == ret)
        {
          ret = obj.get_int(int_value);
          if (OB_SUCCESS == ret)
          {
            //is read consistency
            set_is_result_cached(int_value > 0);
          }
          else
          {
            TBSYS_LOG(WARN, "fail to get int. obj type=%d", obj.get_type());
          }
        }
        else
        {
          TBSYS_LOG(WARN, "fail to deserialize obj. ret=%d", ret);
        }
      }
      // data_version
      if (OB_SUCCESS == ret)
      {
        ret = obj.deserialize(buf, data_len, pos);
        if (OB_SUCCESS == ret)
        {
          ret = obj.get_int(int_value);
          if (OB_SUCCESS == ret)
          {
            // data version
            set_data_version(int_value);
          }
          else
          {
            TBSYS_LOG(WARN, "fail to get int. obj type=%d", obj.get_type());
          }
        }
        else
        {
          TBSYS_LOG(WARN, "fail to deserialize obj. ret=%d", ret);
        }
      }
      // table id
      if (OB_SUCCESS == ret)
      {
        ret = obj.deserialize(buf, data_len, pos);
        if (OB_SUCCESS == ret)
        {
          ret = obj.get_int(int_value);
          if (OB_SUCCESS == ret)
          {
            table_id_ = int_value;
          }
          else
          {
            TBSYS_LOG(WARN, "fail to get int. obj type=%d", obj.get_type());
          }
        }
        else
        {
          TBSYS_LOG(WARN, "fail to deserialize obj. ret=%d", ret);
        }
      }
      // renamed table id
      if (OB_SUCCESS == ret)
      {
        ret = obj.deserialize(buf, data_len, pos);
        if (OB_SUCCESS == ret)
        {
          ret = obj.get_int(int_value);
          if (OB_SUCCESS == ret)
          {
            renamed_table_id_ = int_value;
          }
          else
          {
            TBSYS_LOG(WARN, "fail to get int. obj type=%d", obj.get_type());
          }
        }
        else
        {
          TBSYS_LOG(WARN, "fail to deserialize obj. ret=%d", ret);
        }
      }

      if (OB_SUCCESS == ret)
      {
        if (OB_SUCCESS != (ret = obj.deserialize(buf, data_len, pos)))
        {
          TBSYS_LOG(WARN, "fail to deserialize obj:ret[%d]", ret);
        }
        else if (OB_SUCCESS != (ret = obj.get_bool(only_static_data_)))
        {
          TBSYS_LOG(WARN, "fail to get bool:ret[%d]", ret);
        }
      }
      return ret;
    }