1
This commit is contained in:
parent
552f9efc7d
commit
09f55254d5
@ -166,8 +166,9 @@ void App::AddSocketMsg(SocketFrom_e sockfrom,
|
|||||||
p->buf = nullptr;
|
p->buf = nullptr;
|
||||||
p->buflen = bodylen;
|
p->buflen = bodylen;
|
||||||
if (bodylen > 0) {
|
if (bodylen > 0) {
|
||||||
p->buf = (char*)malloc(bodylen);
|
p->buf = (char*)malloc(bodylen + 1);
|
||||||
memmove(p->buf, msgbody, bodylen);
|
memmove(p->buf, msgbody, bodylen);
|
||||||
|
p->buf[bodylen] = '\0';
|
||||||
}
|
}
|
||||||
msg_mutex_->lock();
|
msg_mutex_->lock();
|
||||||
if (bot_node_) {
|
if (bot_node_) {
|
||||||
|
@ -28,63 +28,72 @@ bool CustomParser(f8::MsgHdr& hdr, google::protobuf::Message* msg)
|
|||||||
switch (field_desc->cpp_type()) {
|
switch (field_desc->cpp_type()) {
|
||||||
case google::protobuf::FieldDescriptor::CPPTYPE_STRING:
|
case google::protobuf::FieldDescriptor::CPPTYPE_STRING:
|
||||||
{
|
{
|
||||||
#if 0
|
if ((size_t)hdr.offset >= (size_t)hdr.buflen) {
|
||||||
reflection->SetString(msg, field_desc, reader.GetValue(field_name));
|
abort();
|
||||||
#endif
|
}
|
||||||
|
std::string val(&hdr.buf[hdr.offset]);
|
||||||
|
reflection->SetString(msg, field_desc, val);
|
||||||
|
hdr.offset += val.size() + 1;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case google::protobuf::FieldDescriptor::CPPTYPE_INT32:
|
case google::protobuf::FieldDescriptor::CPPTYPE_INT32:
|
||||||
{
|
{
|
||||||
if (hdr.offset + sizeof(int) < hdr.buflen) {
|
if (hdr.offset + sizeof(int) < (size_t)hdr.buflen) {
|
||||||
abort();
|
abort();
|
||||||
}
|
}
|
||||||
int* p_val = (int*)&hdr.buf[hdr.offset];
|
int* p_val = (int*)&hdr.buf[hdr.offset];
|
||||||
reflection->SetInt32(msg, field_desc, *p_val);
|
reflection->SetInt32(msg, field_desc, *p_val);
|
||||||
|
hdr.offset += sizeof(*p_val);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case google::protobuf::FieldDescriptor::CPPTYPE_UINT32:
|
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();
|
abort();
|
||||||
}
|
}
|
||||||
unsigned int* p_val = (unsigned int*)&hdr.buf[hdr.offset];
|
unsigned int* p_val = (unsigned int*)&hdr.buf[hdr.offset];
|
||||||
reflection->SetUInt32(msg, field_desc, *p_val);
|
reflection->SetUInt32(msg, field_desc, *p_val);
|
||||||
|
hdr.offset += sizeof(*p_val);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case google::protobuf::FieldDescriptor::CPPTYPE_INT64:
|
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();
|
abort();
|
||||||
}
|
}
|
||||||
long long* p_val = (long long*)&hdr.buf[hdr.offset];
|
long long* p_val = (long long*)&hdr.buf[hdr.offset];
|
||||||
reflection->SetInt64(msg, field_desc, *p_val);
|
reflection->SetInt64(msg, field_desc, *p_val);
|
||||||
|
hdr.offset += sizeof(*p_val);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case google::protobuf::FieldDescriptor::CPPTYPE_UINT64:
|
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();
|
abort();
|
||||||
}
|
}
|
||||||
unsigned long long* p_val = (unsigned long long*)&hdr.buf[hdr.offset];
|
unsigned long long* p_val = (unsigned long long*)&hdr.buf[hdr.offset];
|
||||||
reflection->SetUInt64(msg, field_desc, *p_val);
|
reflection->SetUInt64(msg, field_desc, *p_val);
|
||||||
|
hdr.offset += sizeof(*p_val);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case google::protobuf::FieldDescriptor::CPPTYPE_FLOAT:
|
case google::protobuf::FieldDescriptor::CPPTYPE_FLOAT:
|
||||||
{
|
{
|
||||||
if (hdr.offset + sizeof(float) < hdr.buflen) {
|
if (hdr.offset + sizeof(float) < (size_t)hdr.buflen) {
|
||||||
abort();
|
abort();
|
||||||
}
|
}
|
||||||
float* p_val = (float*)&hdr.buf[hdr.offset];
|
float* p_val = (float*)&hdr.buf[hdr.offset];
|
||||||
reflection->SetFloat(msg, field_desc, *p_val);
|
reflection->SetFloat(msg, field_desc, *p_val);
|
||||||
|
hdr.offset += sizeof(*p_val);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case google::protobuf::FieldDescriptor::CPPTYPE_DOUBLE:
|
case google::protobuf::FieldDescriptor::CPPTYPE_DOUBLE:
|
||||||
{
|
{
|
||||||
if (hdr.offset + sizeof(double) < hdr.buflen) {
|
if (hdr.offset + sizeof(double) < (size_t)hdr.buflen) {
|
||||||
abort();
|
abort();
|
||||||
}
|
}
|
||||||
double* p_val = (double*)&hdr.buf[hdr.offset];
|
double* p_val = (double*)&hdr.buf[hdr.offset];
|
||||||
reflection->SetFloat(msg, field_desc, *p_val);
|
reflection->SetFloat(msg, field_desc, *p_val);
|
||||||
|
hdr.offset += sizeof(*p_val);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user