本文整理汇总了C++中ObResultCode::serialize方法的典型用法代码示例。如果您正苦于以下问题:C++ ObResultCode::serialize方法的具体用法?C++ ObResultCode::serialize怎么用?C++ ObResultCode::serialize使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ObResultCode
的用法示例。
在下文中一共展示了ObResultCode::serialize方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: handle_send_log
int handle_send_log(ObPacket* ob_packet)
{
int ret = OB_SUCCESS;
ObDataBuffer* data_buffer = ob_packet->get_buffer();
if (NULL == data_buffer)
{
TBSYS_LOG(ERROR, "data_buffer is NUll should not reach this");
ret = OB_ERROR;
}
else
{
tbnet::Connection* connection = ob_packet->get_connection();
char buf[10 * 1024];
ObDataBuffer out_buffer(buf, sizeof(buf));
ObResultCode response;
response.result_code_ = OB_SUCCESS;
response.serialize(out_buffer.get_data(), out_buffer.get_capacity(),
out_buffer.get_position());
TBSYS_LOG(DEBUG, "recv send log request, ret=%d", ret);
int32_t version = 1;
int32_t channel_id = ob_packet->getChannelId();
ret = send_response(OB_SEND_LOG_RES, version, out_buffer, connection, channel_id);
TBSYS_LOG(DEBUG, "send log response, ret=%d", ret);
}
return ret;
}
示例2: ms_scan
int MockMergeServer::ms_scan(const int64_t start_time,const int32_t version,const int32_t channel_id,tbnet::Connection* connection,common::ObDataBuffer& in_buffer,common::ObDataBuffer& out_buffer,const int64_t timeout_us)
{
ObResultCode rc;
rc.result_code_ = OB_SUCCESS;
int ret = OB_SUCCESS;
const int32_t MS_SCAN_VERSION = 1;
ret = rc.serialize(out_buffer.get_data(), out_buffer.get_capacity(), out_buffer.get_position());
if (OB_SUCCESS == ret)
{
ObScanner result_scanner;
ObCellInfo cell;
cell.table_name_.assign((char*)"table1", 6);
//TODO
char rowkey[30 * 1024];
cell.row_key_.assign(rowkey, 30 * 1024);
cell.column_name_.assign((char*)"column1", 7);
cell.value_.set_int(0xff);
ret = result_scanner.add_cell(cell);
result_scanner.set_is_req_fullfilled(true, 1);
if (OB_SUCCESS == ret)
{
ret = result_scanner.serialize(out_buffer.get_data(),out_buffer.get_capacity(), out_buffer.get_position());
}
if (OB_SUCCESS == ret)
{
ret = this->send_response(OB_SCAN_RESPONSE, MS_SCAN_VERSION, out_buffer, connection, channel_id, 0);
}
}
return ret;
}
示例3: handle_grant_lease
int handle_grant_lease(ObPacket* ob_packet)
{
int ret = OB_SUCCESS;
ObDataBuffer* data_buffer = ob_packet->get_buffer();
if (NULL == data_buffer)
{
TBSYS_LOG(ERROR, "data_buffer is NUll should not reach this");
ret = OB_ERROR;
}
else
{
tbnet::Connection* connection = ob_packet->get_connection();
char buf[10 * 1024];
ObDataBuffer out_buffer(buf, sizeof(buf));
ObLease lease;
ret = lease.deserialize(data_buffer->get_data(), data_buffer->get_capacity(),
data_buffer->get_position());
TBSYS_LOG(DEBUG, "recv grant lease request, lease_time=%ld, lease_interval=%ld, "
"ret=%d", lease.lease_time, lease.lease_interval, ret);
ObResultCode response;
response.result_code_ = OB_SUCCESS;
response.serialize(out_buffer.get_data(), out_buffer.get_capacity(),
out_buffer.get_position());
int32_t version = 1;
int32_t channel_id = ob_packet->getChannelId();
ret = send_response(OB_GRANT_LEASE_RESPONSE, version, out_buffer, connection, channel_id);
TBSYS_LOG(DEBUG, "send grant lease response, ret=%d", ret);
}
return ret;
}
示例4: handle_renew_lease
int handle_renew_lease(ObPacket* ob_packet)
{
int ret = OB_SUCCESS;
ObDataBuffer* data_buffer = ob_packet->get_buffer();
if (NULL == data_buffer)
{
TBSYS_LOG(ERROR, "data_buffer is NUll should not reach this");
ret = OB_ERROR;
}
else
{
ObServer slave_addr;
char addr_buf[1024];
ret = slave_addr.deserialize(data_buffer->get_data(), data_buffer->get_capacity(),
data_buffer->get_position());
slave_addr.to_string(addr_buf, sizeof(addr_buf));
addr_buf[sizeof(addr_buf) - 1] = '\0';
TBSYS_LOG(DEBUG, "recv renew lease request, slave_addr=%s, ret=%d", addr_buf, ret);
tbnet::Connection* connection = ob_packet->get_connection();
char buf[10 * 1024];
ObDataBuffer out_buffer(buf, sizeof(buf));
ObResultCode response;
response.result_code_ = OB_SUCCESS;
response.serialize(out_buffer.get_data(), out_buffer.get_capacity(),
out_buffer.get_position());
int32_t version = 1;
int32_t channel_id = ob_packet->getChannelId();
ret = send_response(OB_RENEW_LEASE_RESPONSE, version, out_buffer, connection, channel_id);
TBSYS_LOG(DEBUG, "send renew lease response, ret=%d", ret);
}
return ret;
}
示例5: handle_send_file_request
int ObFileService::handle_send_file_request(
const int32_t version,
const int32_t channel_id,
easy_request_t* request,
common::ObDataBuffer& in_buffer,
common::ObDataBuffer& out_buffer)
{
int ret = OB_SUCCESS;
bool inc_concurrency_count_flag = false;
int32_t response_cid = channel_id;
int64_t session_id = queue_thread_->generate_session_id();
const char* src_ip;
//FILL_TRACE_LOG("handle_send_file_request");
if (!inited_)
{
ret = OB_NOT_INIT;
TBSYS_LOG(ERROR, "ob file client is not inited yet.");
}
if (OB_SUCCESS == ret && NULL == request)
{
ret = OB_INVALID_ARGUMENT;
TBSYS_LOG(WARN, "Connection param in receive_file_loop should not be null");
}
if (request != NULL && request->ms != NULL && request->ms->c != NULL)
{
src_ip = get_peer_ip(request);
}
else
{
src_ip = "";
TBSYS_LOG(WARN, "can't get src ip for send_file_request");
}
if (DEFAULT_VERSION != version)
{
ret = OB_ERROR_FUNC_VERSION;
TBSYS_LOG(ERROR, "Can'd handle send_file_request in different version:"
"Server version:%d, Packet version:%d", DEFAULT_VERSION, version);
// send back error message
ObResultCode rc;
rc.result_code_ = OB_ERROR_FUNC_VERSION;
int err = OB_SUCCESS;
out_buffer.get_position() = 0;
err = rc.serialize(out_buffer.get_data(), out_buffer.get_capacity(),
out_buffer.get_position());
if (OB_SUCCESS != err)
{
TBSYS_LOG(WARN, "Encode result code failed:ret=[%d]", err);
}
else
{
err = server_->send_response(OB_SEND_FILE_REQUEST_RESPONSE,
DEFAULT_VERSION, out_buffer, request, response_cid, session_id);
if (OB_SUCCESS != err)
{
TBSYS_LOG(WARN, "Send error message for OB_SEND_FILE_REQUEST failed:"
"ret[%d]", err);
}
}
}
if (OB_SUCCESS == ret)
{
ret = inc_concurrency_count();
if(OB_SUCCESS == ret)
{
inc_concurrency_count_flag = true;
}
else
{
// send back error message
ObResultCode rc;
int err = OB_SUCCESS;
rc.result_code_ = ret;
out_buffer.get_position() = 0;
err = rc.serialize(out_buffer.get_data(), out_buffer.get_capacity(),
out_buffer.get_position());
if (OB_SUCCESS != err)
{
TBSYS_LOG(WARN, "Encode result code failed:ret=[%d]", err);
}
else
{
err = server_->send_response(OB_SEND_FILE_REQUEST_RESPONSE,
DEFAULT_VERSION, out_buffer, request, response_cid, session_id);
if (OB_SUCCESS != err)
{
TBSYS_LOG(WARN, "Send error message for OB_SEND_FILE_REQUEST failed:"
"ret[%d]", err);
}
}
}
}
// handle...
ObFileAppender file_appender;
int64_t file_size;
//.........这里部分代码省略.........
示例6: receive_file_end
int ObFileService::receive_file_end(ObString& file_path, ObString& tmp_file_path,
const int64_t file_size, easy_request_t* request, ObDataBuffer& out_buffer,
int32_t& response_cid, const int64_t session_id)
{
int ret = OB_SUCCESS;
struct stat file_stat;
char tmp_path_buf[OB_MAX_FILE_NAME_LENGTH];
char path_buf[OB_MAX_FILE_NAME_LENGTH];
int n = snprintf(tmp_path_buf, OB_MAX_FILE_NAME_LENGTH, "%.*s",
tmp_file_path.length(), tmp_file_path.ptr());
if (n<0 || n>=OB_MAX_FILE_NAME_LENGTH)
{
TBSYS_LOG(ERROR, "failed to get tmp_file_path length[%d] [%.*s]",
n, tmp_file_path.length(), tmp_file_path.ptr());
ret = OB_SIZE_OVERFLOW;
}
else if (stat(tmp_path_buf, &file_stat) != 0)
{
TBSYS_LOG(ERROR, "stat tmp_file_path[%s] failed: %s",
tmp_path_buf, strerror(errno));
ret = OB_IO_ERROR;
}
n = snprintf(path_buf, OB_MAX_FILE_NAME_LENGTH, "%.*s",
file_path.length(), file_path.ptr());
if (OB_SUCCESS == ret && (n<0 || n>=OB_MAX_FILE_NAME_LENGTH))
{
TBSYS_LOG(ERROR, "failed to get path_buf length[%d] [%.*s]",
n, file_path.length(), file_path.ptr());
ret = OB_SIZE_OVERFLOW;
}
if (OB_SUCCESS == ret && file_stat.st_size != file_size)
{
TBSYS_LOG(ERROR, "The size of received tmp file size[%ld], "
"remote file size[%ld]", file_stat.st_size, file_size);
ret = OB_INVALID_DATA;
}
if (OB_SUCCESS == ret && 0 != rename(tmp_path_buf, path_buf))
{
TBSYS_LOG(ERROR, "Rename [%s] to path[%s] failed: errno[%d] %s",
tmp_path_buf, path_buf, errno, strerror(errno));
ret = OB_IO_ERROR;
}
int err = OB_SUCCESS;
ObResultCode rc;
rc.result_code_ = ret;
err = rc.serialize(out_buffer.get_data(), out_buffer.get_capacity(),
out_buffer.get_position());
if (OB_SUCCESS != err)
{
TBSYS_LOG(WARN, "Encode result code failed:ret=[%d]", err);
}
if (OB_SUCCESS == err)
{
err = server_->send_response(OB_SEND_FILE_REQUEST_RESPONSE, DEFAULT_VERSION,
out_buffer, request, response_cid, session_id);
if (OB_SUCCESS != err)
{
TBSYS_LOG(WARN, "Send send_file_end_response failed:ret[%d]", err);
}
}
if (OB_SUCCESS == ret && OB_SUCCESS != err)
{
ret = err;
}
return ret;
}
示例7: receive_file_block
int ObFileService::receive_file_block(ObFileAppender& file_appender,
char* block_buf, easy_request_t* request, ObDataBuffer& in_buffer,
ObDataBuffer& out_buffer, int32_t & response_cid, const int64_t session_id)
{
int err = OB_SUCCESS;
int64_t offset;
int64_t read_size = -1;
//FILL_TRACE_LOG("Start receive_file_block");
if (OB_SUCCESS == err)
{
err = serialization::decode_i64(in_buffer.get_data(),
in_buffer.get_capacity(), in_buffer.get_position(), &offset);
if (OB_SUCCESS != err)
{
TBSYS_LOG(WARN, "Decode offset failed: err=[%d]", err);
}
}
if (OB_SUCCESS == err)
{
if (NULL == serialization::decode_vstr(in_buffer.get_data(),
in_buffer.get_capacity(), in_buffer.get_position(),
block_buf, block_size_, &read_size))
{
err = OB_DESERIALIZE_ERROR;
TBSYS_LOG(WARN, "Decode block failed");
}
}
//FILL_TRACE_LOG("decode end");
// write file block
if (OB_SUCCESS == err)
{
const bool is_fsync = false;
err = file_appender.append(block_buf, read_size, is_fsync);
if (OB_SUCCESS != err)
{
TBSYS_LOG(WARN, "Appender file block failed:err=[%d]", err);
}
}
//FILL_TRACE_LOG("append end");
// send response
ObResultCode rc;
int ret = OB_SUCCESS;
rc.result_code_ = err;
if (OB_SUCCESS == ret)
{
ret = rc.serialize(out_buffer.get_data(), out_buffer.get_capacity(),
out_buffer.get_position());
if (OB_SUCCESS != ret)
{
TBSYS_LOG(WARN, "Encode result code failed:ret=[%d]", ret);
}
}
//FILL_TRACE_LOG("encode end");
if (OB_SUCCESS == ret)
{
ret = queue_thread_->prepare_for_next_request(session_id);
if(OB_SUCCESS != ret)
{
TBSYS_LOG(WARN, "prepare for next request fail:ret[%d]", ret);
}
}
if (OB_SUCCESS == ret)
{
ret = server_->send_response(OB_SEND_FILE_REQUEST_RESPONSE, DEFAULT_VERSION,
out_buffer, request, response_cid, session_id);
if (OB_SUCCESS != ret)
{
TBSYS_LOG(WARN, "Send send_file_end_response failed:ret[%d]", ret);
}
}
//FILL_TRACE_LOG("send response end");
if (OB_SUCCESS == ret && OB_SUCCESS != err)
{
ret = err;
}
return ret;
}
示例8: receive_file_pre
int ObFileService::receive_file_pre(ObFileAppender& file_appender,
int64_t& file_size, ObString& file_path, ObString& tmp_file_path,
easy_request_t* request, ObDataBuffer& in_buffer,
ObDataBuffer& out_buffer, int32_t& response_cid, const int64_t session_id)
{
int err = OB_SUCCESS;
if (OB_SUCCESS == err)
{
err = serialization::decode_i64(in_buffer.get_data(),
in_buffer.get_capacity(), in_buffer.get_position(), &file_size);
if (OB_SUCCESS != err)
{
TBSYS_LOG(WARN, "Decode file_info failed: err=[%d]", err);
}
}
char dest_dir_buf[OB_MAX_FILE_NAME_LENGTH];
ObString dest_dir;
dest_dir.assign_buffer(dest_dir_buf, sizeof(dest_dir_buf));
if (OB_SUCCESS == err)
{
err = dest_dir.deserialize(in_buffer.get_data(), in_buffer.get_capacity(),
in_buffer.get_position());
if (OB_SUCCESS != err)
{
TBSYS_LOG(WARN, "Decode dest_dir failed:err=[%d]", err);
}
}
char dest_file_name_buf[OB_MAX_FILE_NAME_LENGTH];
ObString dest_file_name;
dest_file_name.assign_buffer(dest_file_name_buf, sizeof(dest_file_name_buf));
if (OB_SUCCESS == err)
{
err = dest_file_name.deserialize(in_buffer.get_data(),
in_buffer.get_capacity(), in_buffer.get_position());
if (OB_SUCCESS != err)
{
TBSYS_LOG(WARN, "Decode dest_file_name failed:err=[%d]", err);
}
}
// check dir
if (OB_SUCCESS == err)
{
err = check_dir(dest_dir, file_size);
if (OB_SUCCESS != err)
{
TBSYS_LOG(WARN, "Check dir failed:err=[%d]", err);
}
}
// generate tmp_file_path and file_path
char file_path_buf[OB_MAX_FILE_NAME_LENGTH];
char tmp_file_path_buf[OB_MAX_FILE_NAME_LENGTH];
if (OB_SUCCESS == err)
{
const char tmp_file_prefix[]= "tmp_";
int64_t count = 0;
count = snprintf(file_path_buf, OB_MAX_FILE_NAME_LENGTH, "%.*s/%.*s",
dest_dir.length(), dest_dir.ptr(), dest_file_name.length(), dest_file_name.ptr());
if (count<0 || count >= OB_MAX_FILE_NAME_LENGTH)
{
err = OB_SIZE_OVERFLOW;
TBSYS_LOG(WARN, "snprintf file name failed, return[%ld] [%.*s]/[%.*s]",
count, dest_dir.length(), dest_dir.ptr(), dest_file_name.length(), dest_file_name.ptr());
}
count = file_path.write(file_path_buf,
static_cast<ObString::obstr_size_t>(strlen(file_path_buf)));
if (count != static_cast<int>(strlen(file_path_buf)))
{
err = OB_SIZE_OVERFLOW;
TBSYS_LOG(WARN, "Write file_path_buf to ObString failed");
}
count = snprintf(tmp_file_path_buf, OB_MAX_FILE_NAME_LENGTH, "%.*s/%s%.*s",
dest_dir.length(), dest_dir.ptr(), tmp_file_prefix, dest_file_name.length(), dest_file_name.ptr());
if (count <0 || count >= OB_MAX_FILE_NAME_LENGTH)
{
err = OB_SIZE_OVERFLOW;
TBSYS_LOG(WARN, "snprintf tmp file name failed, return[%ld] [%.*s]/[%s][%.*s]",
count, dest_dir.length(), dest_dir.ptr(), tmp_file_prefix, dest_file_name.length(), dest_file_name.ptr());
}
count = tmp_file_path.write(tmp_file_path_buf,
static_cast<ObString::obstr_size_t>(strlen(tmp_file_path_buf)));
if (count != static_cast<int>(strlen(tmp_file_path_buf)))
{
err = OB_SIZE_OVERFLOW;
TBSYS_LOG(WARN, "Write tmp_file_path_buf to ObString failed");
}
}
// check if the tmp_file and the dest file exist already
if (OB_SUCCESS == err)
{
if (0 == access(tmp_file_path_buf, F_OK))
//.........这里部分代码省略.........