发布于 2015-07-08 07:52:03
在C中,二进制字符串只是一个uint8_t数组。(请注意,普通的C字符串不能包含二进制数据,因此不能用于存储protobuf消息。)
因此,pb_ostream_from_buffer()是将结果作为“字符串”获得的正确方法。
从simple.c示例获得
uint8_t buffer[128];
pb_ostream_t stream = pb_ostream_from_buffer(buffer, sizeof(buffer));
status = pb_encode(&stream, SimpleMessage_fields, &message);在此之后,编码的消息在buffer中,具有stream.bytes_written的长度。那是你想要的绳子。
https://stackoverflow.com/questions/31272735
复制相似问题