本文整理汇总了C++中ObPacket::encode方法的典型用法代码示例。如果您正苦于以下问题:C++ ObPacket::encode方法的具体用法?C++ ObPacket::encode怎么用?C++ ObPacket::encode使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ObPacket
的用法示例。
在下文中一共展示了ObPacket::encode方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: encode
int ObTbnetCallback::encode(easy_request_t *r, void *data)
{
int ret = EASY_OK;
easy_buf_t* b = NULL;
char* buff = NULL;
ObPacket* packet = reinterpret_cast<ObPacket*>(data);
int64_t header_size = 0;
uint16_t ob_packet_header_size = 0;
#if !defined(_OB_VERSION) || _OB_VERSION<=300
/* 0.3 ObPacket 头格式: 16 bytes */
/* 2 bytes 2 bytes 8 bytes 4 bytes
*----------------------------------------------------------------------
*| ob_packet_header_size_== 0 | api_version_ | session_id_ | timeout_ |
*----------------------------------------------------------------------
*/
ob_packet_header_size = 0;
header_size = sizeof(uint16_t)/* ob_packet_header_size_ */ + sizeof(int16_t) /* api_version_ */+ sizeof(int64_t) /* session_id_ */+ sizeof(int32_t)/* timeout_ */;
#elif _OB_VERSION>300
/* 0.4 ObPacket 头格式: 24 bytes */
/* 2 bytes 2 bytes 8 bytes 4 bytes 8 bytes 8 bytes
*--------------------------------------------------------------------------------------
*| ob_packet_header_size_ | api_version_ | session_id_ | timeout_ |trace_id_|req_sign_|
*--------------------------------------------------------------------------------------
*/
ob_packet_header_size = (uint16_t)(sizeof(ob_packet_header_size) + sizeof(int16_t)/* api_version_ */ + sizeof(int64_t) /* session_id_ */ + sizeof(int32_t)/* timeout_ */ + sizeof(uint64_t)/* trace_id_ */ + sizeof(uint64_t) /* req_sign_ */);
header_size = ob_packet_header_size;
#endif
packet->set_ob_packet_header_size(ob_packet_header_size);
int64_t size = packet->get_inner_buffer()->get_position() + OB_TBNET_HEADER_LENGTH + header_size;
b = reinterpret_cast<easy_buf_t *>(easy_pool_alloc(r->ms->pool,
static_cast<uint32_t>(sizeof(easy_buf_t) + size)));
if (NULL == b)
{
TBSYS_LOG(WARN, "alloc mem for send buffer failed buf=%p size is %lu", b,
sizeof(easy_buf_t) + size);
ret = EASY_ERROR;
}
else
{
//skip sizeof(easy_buf_t) bytes
buff = reinterpret_cast<char *>(b + 1);
//b->pos = buff;
//b->end = buff + size;
//set packet length
init_easy_buf(b, buff, r, size);
packet->set_packet_len(static_cast<int>(
packet->get_inner_buffer()->get_position() + header_size));
if (false == packet->encode(buff, size))
{
ret = EASY_ERROR;
TBSYS_LOG(WARN, "encode failed packet is %p, buff is %p, size is %ld", packet, buff, size);
}
if (EASY_OK == ret)
{
easy_buf_set_data(r->ms->pool, b, buff, static_cast<uint32_t>(size));
easy_request_addbuf(r, b);
//add rpc bytes out statistics
OB_STAT_INC(COMMON, RPC_BYTES_OUT, size);
TBSYS_LOG(DEBUG, "encode packet success packet code is %d, c is %s",packet->get_packet_code(),
easy_connection_str(r->ms->c));
}
}
return ret;
}