コード例 #1
0
ファイル: common.cpp プロジェクト: yinzhigang/tfs
    int32_t BlockBase::deserialize(tbnet::DataBuffer& input, const int32_t length, int32_t& offset, const int8_t)
    {
      if (input.getDataLen() <= 0 || offset >= length)
      {
        return TFS_ERROR;
      }

      int64_t pos = 0;
      int32_t len = input.getDataLen();
      int32_t ret = info_.deserialize(input.getData(), input.getDataLen(), pos);
      if (TFS_SUCCESS == ret)
        input.drainData(info_.length());

      int8_t server_size = input.readInt8();
      while (server_size > 0)
      {
        ServerInfo server_info;
        server_info.server_id_ = input.readInt64();
        server_info.family_id_ = input.readInt64();
        server_info.version_   = input.readInt32();

        server_list_.push_back(server_info);
        server_size--;
      }

      offset += (len - input.getDataLen());
      return TFS_SUCCESS;
    }
コード例 #2
0
ファイル: common.cpp プロジェクト: alimy/tfs
    int32_t BlockBase::deserialize(tbnet::DataBuffer& input, const int32_t length, int32_t& offset, const int8_t type)
    {
      // type must contain SSM_CHILD_BLOCK_TYPE_INFO at lease
      if (input.getDataLen() <= 0 || offset >= length || 0 == (type & SSM_CHILD_BLOCK_TYPE_INFO))
      {
        return EXIT_PARAMETER_ERROR;
      }

      int64_t pos = 0;
      int32_t len = input.getDataLen();
      int32_t ret = info_.deserialize(input.getData(), input.getDataLen(), pos);
      if (TFS_SUCCESS == ret)
      {
        input.drainData(info_.length());
        if (type & SSM_CHILD_BLOCK_TYPE_SERVER)
        {
          int8_t server_size = input.readInt8();
          while (server_size > 0)
          {
            ServerInfo server_info;
            server_info.server_id_ = input.readInt64();
            server_info.family_id_ = input.readInt64();
            server_info.version_   = input.readInt32();

            server_list_.push_back(server_info);
            server_size--;
          }
        }
        if (type & SSM_CHILD_BLOCK_TYPE_STATUS)
        {
          expire_time_ = input.readInt64();
          create_flag_ = input.readInt8();
          in_replicate_queue_ = input.readInt8();
          has_lease_ = input.readInt8();
          choose_master_ = input.readInt8();
          last_leave_time_ = input.readInt64();
        }
        offset += (len - input.getDataLen());
      }
      return ret;
    }