我在一个小型系统上使用protobuf-embedded-c将不同的数据从它传输到PC.问题是,如果我在两端都使用嵌入式库,一切正常.如果我在PC上使用谷歌C++它不再工作.我想我将问题追溯到每个消息中都有长度前缀的嵌入式库,但我似乎无法在C++库中以良好的方式做到这一点.这是我用来调试它的测试应用程序:
person.proto:
enum PhoneType {
MOBILE = 0;
HOME = 1;
WORK = 2;
}
message PhoneNumber {
required float number = 1;
required PhoneType type = 2;
}
Run Code Online (Sandbox Code Playgroud)
main.cpp中:
#include <stdint.h>
#include <stdio.h>
#define __PROTOBUF_CPP_IMPL
#ifdef __PROTOBUF_CPP_IMPL
#include "person.pb.h"
#else
extern "C"{
#include "person.h"
}
#endif
int main(int argc, char *argv[])
{
static const uint32_t outputbuflen = 1024;
uint8_t outputbuffer[outputbuflen];
uint32_t writtenlenght = 0;
#ifdef __PROTOBUF_CPP_IMPL
// C++ implementation.
printf("Google C++ implementation;\n");
PhoneNumber number;
number.set_number(0800123123.0);
number.set_type(MOBILE);
writtenlenght …Run Code Online (Sandbox Code Playgroud)