Impl GetMsgTypes
This commit is contained in:
@@ -0,0 +1,66 @@
|
||||
#include <map>
|
||||
|
||||
#include "log.h"
|
||||
#include "pb_util.h"
|
||||
#include "wcf.pb.h"
|
||||
|
||||
#define BUF_SIZE (1024 * 1024)
|
||||
static char buf[BUF_SIZE] = { 0 };
|
||||
|
||||
typedef std::map<int, std::string> MsgTypes_t;
|
||||
|
||||
void log_buffer(uint8_t *buffer, size_t len)
|
||||
{
|
||||
size_t j = sprintf_s(buf, BUF_SIZE, "Encoded message[%ld]: ", len);
|
||||
for (size_t i = 0; i < len; i++) {
|
||||
j += sprintf_s(buf + j, BUF_SIZE, "%02X ", buffer[i]);
|
||||
if (j > BUF_SIZE - 3) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
LOG_INFO(buf);
|
||||
}
|
||||
|
||||
bool encode_string(pb_ostream_t *stream, const pb_field_t *field, void *const *arg)
|
||||
{
|
||||
const char *str = (const char *)*arg;
|
||||
|
||||
if (!pb_encode_tag_for_field(stream, field)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return pb_encode_string(stream, (uint8_t *)str, strlen(str));
|
||||
}
|
||||
|
||||
bool decode_string(pb_istream_t *stream, const pb_field_t *field, void **arg)
|
||||
{
|
||||
std::string *str = static_cast<std::string *>(*arg);
|
||||
size_t len = stream->bytes_left;
|
||||
str->resize(len);
|
||||
if (!pb_read(stream, (uint8_t *)str->data(), len)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool encode_types(pb_ostream_t *stream, const pb_field_t *field, void *const *arg)
|
||||
{
|
||||
MsgTypes_t *m = (MsgTypes_t *)*arg;
|
||||
MsgTypes_TypesEntry message = MsgTypes_TypesEntry_init_default;
|
||||
|
||||
for (auto it = m->begin(); it != m->end(); it++) {
|
||||
message.key = it->first;
|
||||
message.value.funcs.encode = &encode_string;
|
||||
message.value.arg = (void *)it->second.c_str();
|
||||
|
||||
if (!pb_encode_tag_for_field(stream, field)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!pb_encode_submessage(stream, MsgTypes_TypesEntry_fields, &message)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
#pragma once
|
||||
|
||||
#include <pb_decode.h>
|
||||
#include <pb_encode.h>
|
||||
|
||||
void log_buffer(uint8_t *buffer, size_t len);
|
||||
bool encode_string(pb_ostream_t *stream, const pb_field_t *field, void *const *arg);
|
||||
bool decode_string(pb_istream_t *stream, const pb_field_t *field, void **arg);
|
||||
bool encode_types(pb_ostream_t *stream, const pb_field_t *field, void *const *arg);
|
||||
@@ -1,6 +1,5 @@
|
||||
# Generate all fields as pointers.
|
||||
* mangle_names:M_STRIP_PACKAGE
|
||||
* fallback_type:FT_POINTER
|
||||
MsgTypes.types max_count:10
|
||||
MsgTypes.TypesEntry.value max_size:16
|
||||
# MsgTypes.* max_size:16
|
||||
MsgTypes* fallback_type:FT_CALLBACK
|
||||
RpcContact* fallback_type:FT_CALLBACK
|
||||
|
||||
+7
-7
@@ -55,14 +55,14 @@ message Response
|
||||
Functions func = 1;
|
||||
oneof msg
|
||||
{
|
||||
int32 status = 2;
|
||||
string str = 3;
|
||||
WxMsg wxmsg = 4;
|
||||
MsgTypes types = 5;
|
||||
int32 status = 2;
|
||||
string str = 3;
|
||||
WxMsg wxmsg = 4;
|
||||
MsgTypes types = 5;
|
||||
RpcContacts contacts = 6;
|
||||
DbNames dbs = 7;
|
||||
DbTables tables = 8;
|
||||
DbRows rows = 9;
|
||||
DbNames dbs = 7;
|
||||
DbTables tables = 8;
|
||||
DbRows rows = 9;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user