【问题标题】:Deserializing buffer Protocol Buffer反序列化缓冲区协议缓冲区
【发布时间】:2018-11-14 00:15:31
【问题描述】:

我正在尝试从套接字反序列化缓冲区。 它被定义为 C 结构。

struct 的一个成员是 uint8[5]。
我坚持如何用 .proto 文件表达这一点。

sender的原始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 字节大小的数组。 proto3 规范中没有 uint8 和固定大小的字节。

【问题讨论】:

    标签: protocol-buffers


    【解决方案1】:

    protobuf 确实没有固定大小的数组,固定大小的整数也不包括 5 个字节。所以;您最好的选择可能是 bytes,只需使其始终包含正好 5 个字节。

    注意:protobuf 并非用于解析任意协议/有效负载(例如套接字帧或原始 C 样式转储)的机制。它用于 protobuf 本身。

    【讨论】: