本文整理汇总了C++中MessagePtr::reset方法的典型用法代码示例。如果您正苦于以下问题:C++ MessagePtr::reset方法的具体用法?C++ MessagePtr::reset怎么用?C++ MessagePtr::reset使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MessagePtr
的用法示例。
在下文中一共展示了MessagePtr::reset方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Alloc
MessagePtr Message::Alloc(uint32_t len)
{
MessagePtr msg;
if (len > 0)
{
msg.reset(new Message(len));
}
return msg;
}
示例2: Parse
static MessagePtr Parse(const char* buf, int len, ErrorCode* error)
{
MessagePtr message;
typedef google::protobuf::int32 int32;
// check sum
int32 expectedCheckSum = async::detail::AsInt32(buf + len - kHeaderLen);
int32 checkSum = static_cast<int32>(0
/*::adler32(1,
reinterpret_cast<const Bytef*>(buf),
static_cast<int>(len - kHeaderLen))*/);
if (checkSum == expectedCheckSum)
{
// get message type name
int32 nameLen = async::detail::AsInt32(buf);
if (nameLen >= 2 && nameLen <= len - 2 * kHeaderLen)
{
std::string typeName(buf + kHeaderLen, buf + kHeaderLen + nameLen - 1);
// create message object
message.reset(CreateMessage(typeName));
if (message)
{
// parse from buffer
const char* data = buf + kHeaderLen + nameLen;
int32 dataLen = len - nameLen - 2 * kHeaderLen;
if (message->ParseFromArray(data, dataLen))
{
*error = kNoError;
}
else
{
*error = kParseError;
}
}
else
{
*error = kUnknownMessageType;
}
}
else
{
*error = kInvalidNameLen;
}
}
else
{
*error = kCheckSumError;
}
return message;
}
示例3: parse
MessagePtr protobuf_codec::parse(const char* buf, const uint32_t len, uint32_t& error)
{
MessagePtr message;
do
{
//msg_name_len include the end character '\0'
const uint16_t msg_name_len = *(const uint16_t*)&buf[0]; //TODO: ntoh()
if (msg_name_len > 128 || msg_name_len < MIN_MSG_NAME_SIZE || msg_name_len + MSG_NAME_LENGTH_SIZE > len)
{
LOG(ERROR)<<"message name length error length = "<<msg_name_len<<", total="<<len;
error = 1;
break;
}
char msgname[128] = {'\0'};
strncpy(msgname, (const char*)(buf + MSG_NAME_LENGTH_SIZE), msg_name_len);
const uint16_t n = strlen(msgname) + 1;
if (n != msg_name_len)
{
LOG(ERROR)<<"message name length error (received="<<n<<", expected="<<msg_name_len<<", msgname="<<msgname<<")";
error = 2;
break;
}
LOG(INFO)<<"[protobuf_codec],parse, msg_name_len="<<msg_name_len<<", msgname="<<msgname;
message.reset(createMessage(msgname));
if (!message)
{
LOG(ERROR)<<"unrecognized message name = "<<msgname;
error = 3;
break;
}
if (!message->ParseFromString(std::string(buf + MSG_NAME_LENGTH_SIZE + msg_name_len, len - MSG_NAME_LENGTH_SIZE - msg_name_len)))
{
LOG(ERROR)<<"Parse error msgname="<<msgname;
error = 4;
break;
}
}while(false);
return message;
}
示例4: parse
MessagePtr ProtobufCodec::parse(char *buf,int len)
{
MessagePtr message;
int32_t nameLen = asInt32(buf);
if(nameLen >=2 && nameLen <= len - kHeaderLen)
{
std::string typeName(buf + kHeaderLen,buf + kHeaderLen + nameLen -1);
//创建消息对象
message.reset(createMessage(typeName));
if(message)
{
const char *data = buf + kHeaderLen + nameLen;
int32_t dataLen = len - nameLen - 2*kHeaderLen;
//从Buffer中获取完整的消息格式
if(message->ParseFromArray(data,dataLen))
{
printf("解析消息成功\n");
}
}
}
return message;
}