[英]Google-protobuf: How to create unions using Google protocol buffer
[英]google protobuf - how to access size of buffer as specified in .proto file?
我的 protobuf 文件是
message Msg{
// User Authentication data as bytes.
bytes MsgData = 1 [(nanopb).max_size = 2048];
}
當我生成C API 時,相關部分是:
#define PB_BYTES_ARRAY_T(n) struct { pb_size_t size; pb_byte_t bytes[n]; }
/* Struct definitions */
typedef PB_BYTES_ARRAY_T(2048) Msg_AuthenticationData_t;
/* Maximum encoded size of messages (where known) */
#define Msg_size 2051
問題 - 1
緩沖區的大小,為2048
; 如何使用 API 訪問該值?
我知道我可以做sizeof(Msg_AuthenticationData_t.bytes)
因為它在編譯時設置為2048
但似乎應該有一個 API。
問題2
2051
是怎么回事? 那怎么用?
sizeof(Msg_AuthenticationData_t.bytes)
是獲取數組大小的 API。 這就是它適用於任何 C 類型的方式。
編碼消息大小是pb_encode()
輸出的最大大小。 由於protobuf encoding中的字段類型和長度標頭,它可能比有效負載大幾個字節。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.