This commit is contained in:
aozhiwei 2019-09-14 21:09:47 +08:00
parent 552f9efc7d
commit 09f55254d5
2 changed files with 20 additions and 10 deletions

View File

@ -166,8 +166,9 @@ void App::AddSocketMsg(SocketFrom_e sockfrom,
p->buf = nullptr;
p->buflen = bodylen;
if (bodylen > 0) {
p->buf = (char*)malloc(bodylen);
p->buf = (char*)malloc(bodylen + 1);
memmove(p->buf, msgbody, bodylen);
p->buf[bodylen] = '\0';
}
msg_mutex_->lock();
if (bot_node_) {

View File

@ -28,63 +28,72 @@ bool CustomParser(f8::MsgHdr& hdr, google::protobuf::Message* msg)
switch (field_desc->cpp_type()) {
case google::protobuf::FieldDescriptor::CPPTYPE_STRING:
{
#if 0
reflection->SetString(msg, field_desc, reader.GetValue(field_name));
#endif
if ((size_t)hdr.offset >= (size_t)hdr.buflen) {
abort();
}
std::string val(&hdr.buf[hdr.offset]);
reflection->SetString(msg, field_desc, val);
hdr.offset += val.size() + 1;
}
break;
case google::protobuf::FieldDescriptor::CPPTYPE_INT32:
{
if (hdr.offset + sizeof(int) < hdr.buflen) {
if (hdr.offset + sizeof(int) < (size_t)hdr.buflen) {
abort();
}
int* p_val = (int*)&hdr.buf[hdr.offset];
reflection->SetInt32(msg, field_desc, *p_val);
hdr.offset += sizeof(*p_val);
}
break;
case google::protobuf::FieldDescriptor::CPPTYPE_UINT32:
{
if (hdr.offset + sizeof(unsigned int) < hdr.buflen) {
if (hdr.offset + sizeof(unsigned int) < (size_t)hdr.buflen) {
abort();
}
unsigned int* p_val = (unsigned int*)&hdr.buf[hdr.offset];
reflection->SetUInt32(msg, field_desc, *p_val);
hdr.offset += sizeof(*p_val);
}
break;
case google::protobuf::FieldDescriptor::CPPTYPE_INT64:
{
if (hdr.offset + sizeof(long long) < hdr.buflen) {
if (hdr.offset + sizeof(long long) < (size_t)hdr.buflen) {
abort();
}
long long* p_val = (long long*)&hdr.buf[hdr.offset];
reflection->SetInt64(msg, field_desc, *p_val);
hdr.offset += sizeof(*p_val);
}
break;
case google::protobuf::FieldDescriptor::CPPTYPE_UINT64:
{
if (hdr.offset + sizeof(unsigned long long) < hdr.buflen) {
if (hdr.offset + sizeof(unsigned long long) < (size_t)hdr.buflen) {
abort();
}
unsigned long long* p_val = (unsigned long long*)&hdr.buf[hdr.offset];
reflection->SetUInt64(msg, field_desc, *p_val);
hdr.offset += sizeof(*p_val);
}
break;
case google::protobuf::FieldDescriptor::CPPTYPE_FLOAT:
{
if (hdr.offset + sizeof(float) < hdr.buflen) {
if (hdr.offset + sizeof(float) < (size_t)hdr.buflen) {
abort();
}
float* p_val = (float*)&hdr.buf[hdr.offset];
reflection->SetFloat(msg, field_desc, *p_val);
hdr.offset += sizeof(*p_val);
}
break;
case google::protobuf::FieldDescriptor::CPPTYPE_DOUBLE:
{
if (hdr.offset + sizeof(double) < hdr.buflen) {
if (hdr.offset + sizeof(double) < (size_t)hdr.buflen) {
abort();
}
double* p_val = (double*)&hdr.buf[hdr.offset];
reflection->SetFloat(msg, field_desc, *p_val);
hdr.offset += sizeof(*p_val);
}
break;
default: