我正在尝试从套接字反序列化缓冲区。它被定义为C结构。
struct的一个成员是uint85。
我讨论了如何用.proto文件来表达这个问题。
发件人的原始C结构在下面。
typedef struct {
uint32_t body_length;
uint8_t body_version;
uint8_t reserved[5];
}我的struct.proto试用期在下面。
syntax = "proto3";
message message_t {
uint32 body_version = 1;
uint8 body_version = 2; //uint8_t body_version;
bytes reserved = 3; //uint8 reservered[5];
}我不知道如何表示uint8和5字节大小的数组。在uint8规范中没有proto3和固定大小的字节。
发布于 2018-11-14 09:23:16
protobuf实际上没有固定大小的数组,固定大小的整数不包括5个字节。因此,您最好的选择可能是bytes,只需使其始终包含精确的5个字节。
注意: protobuf不是用来解析任意协议/有效负载的机制,例如套接字框架或原始C样式转储。它是,仅适用于与protobuf本身一起使用的。
https://stackoverflow.com/questions/53291355
复制相似问题