1
This commit is contained in:
parent
99e2abfc68
commit
552f9efc7d
@ -1,4 +1,7 @@
|
|||||||
#include "precompile.h"
|
#include "precompile.h"
|
||||||
|
|
||||||
|
#include <google/protobuf/message.h>
|
||||||
|
|
||||||
#include "global.h"
|
#include "global.h"
|
||||||
|
|
||||||
time_t Global::BetweenDays(time_t time1, time_t time2)
|
time_t Global::BetweenDays(time_t time1, time_t time2)
|
||||||
@ -14,3 +17,82 @@ time_t Global::GetDaySeconds(time_t time, int incdays)
|
|||||||
int Global::g_nowtime = time(nullptr);
|
int Global::g_nowtime = time(nullptr);
|
||||||
int Global::g_time_zone = 8;
|
int Global::g_time_zone = 8;
|
||||||
bool Global::g_shutdown = false;
|
bool Global::g_shutdown = false;
|
||||||
|
|
||||||
|
bool CustomParser(f8::MsgHdr& hdr, google::protobuf::Message* msg)
|
||||||
|
{
|
||||||
|
const google::protobuf::Descriptor* descriptor = msg->GetDescriptor();
|
||||||
|
const google::protobuf::Reflection* reflection = msg->GetReflection();
|
||||||
|
|
||||||
|
for (int i = 0; i < descriptor->field_count(); ++i) {
|
||||||
|
const google::protobuf::FieldDescriptor* field_desc = descriptor->field(i);
|
||||||
|
switch (field_desc->cpp_type()) {
|
||||||
|
case google::protobuf::FieldDescriptor::CPPTYPE_STRING:
|
||||||
|
{
|
||||||
|
#if 0
|
||||||
|
reflection->SetString(msg, field_desc, reader.GetValue(field_name));
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case google::protobuf::FieldDescriptor::CPPTYPE_INT32:
|
||||||
|
{
|
||||||
|
if (hdr.offset + sizeof(int) < hdr.buflen) {
|
||||||
|
abort();
|
||||||
|
}
|
||||||
|
int* p_val = (int*)&hdr.buf[hdr.offset];
|
||||||
|
reflection->SetInt32(msg, field_desc, *p_val);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case google::protobuf::FieldDescriptor::CPPTYPE_UINT32:
|
||||||
|
{
|
||||||
|
if (hdr.offset + sizeof(unsigned int) < hdr.buflen) {
|
||||||
|
abort();
|
||||||
|
}
|
||||||
|
unsigned int* p_val = (unsigned int*)&hdr.buf[hdr.offset];
|
||||||
|
reflection->SetUInt32(msg, field_desc, *p_val);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case google::protobuf::FieldDescriptor::CPPTYPE_INT64:
|
||||||
|
{
|
||||||
|
if (hdr.offset + sizeof(long long) < hdr.buflen) {
|
||||||
|
abort();
|
||||||
|
}
|
||||||
|
long long* p_val = (long long*)&hdr.buf[hdr.offset];
|
||||||
|
reflection->SetInt64(msg, field_desc, *p_val);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case google::protobuf::FieldDescriptor::CPPTYPE_UINT64:
|
||||||
|
{
|
||||||
|
if (hdr.offset + sizeof(unsigned long long) < hdr.buflen) {
|
||||||
|
abort();
|
||||||
|
}
|
||||||
|
unsigned long long* p_val = (unsigned long long*)&hdr.buf[hdr.offset];
|
||||||
|
reflection->SetUInt64(msg, field_desc, *p_val);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case google::protobuf::FieldDescriptor::CPPTYPE_FLOAT:
|
||||||
|
{
|
||||||
|
if (hdr.offset + sizeof(float) < hdr.buflen) {
|
||||||
|
abort();
|
||||||
|
}
|
||||||
|
float* p_val = (float*)&hdr.buf[hdr.offset];
|
||||||
|
reflection->SetFloat(msg, field_desc, *p_val);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case google::protobuf::FieldDescriptor::CPPTYPE_DOUBLE:
|
||||||
|
{
|
||||||
|
if (hdr.offset + sizeof(double) < hdr.buflen) {
|
||||||
|
abort();
|
||||||
|
}
|
||||||
|
double* p_val = (double*)&hdr.buf[hdr.offset];
|
||||||
|
reflection->SetFloat(msg, field_desc, *p_val);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
{
|
||||||
|
abort();
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}//end switch
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
@ -1,5 +1,18 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
namespace f8
|
||||||
|
{
|
||||||
|
struct MsgHdr;
|
||||||
|
}
|
||||||
|
|
||||||
|
namespace google
|
||||||
|
{
|
||||||
|
namespace protobuf
|
||||||
|
{
|
||||||
|
class Message;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
class Global : public a8::Singleton<Global>
|
class Global : public a8::Singleton<Global>
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
@ -13,3 +26,5 @@ class Global : public a8::Singleton<Global>
|
|||||||
static int g_time_zone; // 默认东八区
|
static int g_time_zone; // 默认东八区
|
||||||
static bool g_shutdown;
|
static bool g_shutdown;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
bool CustomParser(f8::MsgHdr& hdr, google::protobuf::Message* msg);
|
||||||
|
@ -26,85 +26,6 @@ static void _GMOpsReload(f8::JsonHttpRequest* request)
|
|||||||
a8::UdpLog::Instance()->Warning("reload config files", {});
|
a8::UdpLog::Instance()->Warning("reload config files", {});
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool CustomParser(f8::MsgHdr& hdr, google::protobuf::Message* msg)
|
|
||||||
{
|
|
||||||
const google::protobuf::Descriptor* descriptor = msg->GetDescriptor();
|
|
||||||
const google::protobuf::Reflection* reflection = msg->GetReflection();
|
|
||||||
|
|
||||||
for (int i = 0; i < descriptor->field_count(); ++i) {
|
|
||||||
const google::protobuf::FieldDescriptor* field_desc = descriptor->field(i);
|
|
||||||
switch (field_desc->cpp_type()) {
|
|
||||||
case google::protobuf::FieldDescriptor::CPPTYPE_STRING:
|
|
||||||
{
|
|
||||||
#if 0
|
|
||||||
reflection->SetString(msg, field_desc, reader.GetValue(field_name));
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case google::protobuf::FieldDescriptor::CPPTYPE_INT32:
|
|
||||||
{
|
|
||||||
if (hdr.offset + sizeof(int) < hdr.buflen) {
|
|
||||||
abort();
|
|
||||||
}
|
|
||||||
int* p_val = (int*)&hdr.buf[hdr.offset];
|
|
||||||
reflection->SetInt32(msg, field_desc, *p_val);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case google::protobuf::FieldDescriptor::CPPTYPE_UINT32:
|
|
||||||
{
|
|
||||||
if (hdr.offset + sizeof(unsigned int) < hdr.buflen) {
|
|
||||||
abort();
|
|
||||||
}
|
|
||||||
unsigned int* p_val = (unsigned int*)&hdr.buf[hdr.offset];
|
|
||||||
reflection->SetUInt32(msg, field_desc, *p_val);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case google::protobuf::FieldDescriptor::CPPTYPE_INT64:
|
|
||||||
{
|
|
||||||
if (hdr.offset + sizeof(long long) < hdr.buflen) {
|
|
||||||
abort();
|
|
||||||
}
|
|
||||||
long long* p_val = (long long*)&hdr.buf[hdr.offset];
|
|
||||||
reflection->SetInt64(msg, field_desc, *p_val);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case google::protobuf::FieldDescriptor::CPPTYPE_UINT64:
|
|
||||||
{
|
|
||||||
if (hdr.offset + sizeof(unsigned long long) < hdr.buflen) {
|
|
||||||
abort();
|
|
||||||
}
|
|
||||||
unsigned long long* p_val = (unsigned long long*)&hdr.buf[hdr.offset];
|
|
||||||
reflection->SetUInt64(msg, field_desc, *p_val);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case google::protobuf::FieldDescriptor::CPPTYPE_FLOAT:
|
|
||||||
{
|
|
||||||
if (hdr.offset + sizeof(float) < hdr.buflen) {
|
|
||||||
abort();
|
|
||||||
}
|
|
||||||
float* p_val = (float*)&hdr.buf[hdr.offset];
|
|
||||||
reflection->SetFloat(msg, field_desc, *p_val);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case google::protobuf::FieldDescriptor::CPPTYPE_DOUBLE:
|
|
||||||
{
|
|
||||||
if (hdr.offset + sizeof(double) < hdr.buflen) {
|
|
||||||
abort();
|
|
||||||
}
|
|
||||||
double* p_val = (double*)&hdr.buf[hdr.offset];
|
|
||||||
reflection->SetFloat(msg, field_desc, *p_val);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
{
|
|
||||||
abort();
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}//end switch
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
void HandlerMgr::Init()
|
void HandlerMgr::Init()
|
||||||
{
|
{
|
||||||
RegisterNetMsgHandlers();
|
RegisterNetMsgHandlers();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user