99 lines
3.3 KiB
C++
Executable File
99 lines
3.3 KiB
C++
Executable File
#include "precompile.h"
|
|
|
|
#include <google/protobuf/message.h>
|
|
|
|
#include "global.h"
|
|
|
|
time_t Global::BetweenDays(time_t time1, time_t time2)
|
|
{
|
|
return (time1 + g_time_zone*3600)/3600/24 - (time2 + g_time_zone*3600)/3600/24;
|
|
}
|
|
|
|
time_t Global::GetDaySeconds(time_t time, int incdays)
|
|
{
|
|
return time_t((time + g_time_zone * 3600)/3600/24 + incdays) * 3600 * 24 - 3600 * g_time_zone;
|
|
}
|
|
|
|
int Global::g_nowtime = time(nullptr);
|
|
int Global::g_time_zone = 8;
|
|
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;
|
|
}
|