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; }
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; }
int ServerBase::deserialize(tbnet::DataBuffer& input, const int32_t length, int32_t& offset, const int8_t type) { int ret = server_stat_.deserialize(input, length, offset); int len = 0; if (TFS_SUCCESS == ret) { if (type & SERVER_TYPE_BLOCK_LIST) { len = input.getDataLen(); int32_t hold_size = input.readInt32(); while (hold_size > 0) { hold_.insert(input.readInt64()); hold_size--; } offset += (len - input.getDataLen()); } if (type & SERVER_TYPE_BLOCK_WRITABLE) { len = input.getDataLen(); int32_t writable_size = input.readInt32(); while (writable_size > 0) { writable_.insert(input.readInt64()); writable_size--; } offset += (len - input.getDataLen()); } if (type & SERVER_TYPE_BLOCK_MASTER) { len = input.getDataLen(); int32_t master_size = input.readInt32(); while (master_size > 0) { master_.insert(input.readInt64()); master_size--; } offset += (len - input.getDataLen()); } } return ret; }