c - Nanopb get string from pb_ostream_t -
i using nanopb can implement protobuf small, cross compiled code. have base of working encoded protobuf message string sending via udp (on system). full blown protobuf library message.serializetostring(). nanopb doesn't seem have that, surely it's common thing do. examples given nanopb use pb_ostream_t struct , pb_ostream_from_buffer() ideas?
in c, binary string uint8_t array. (note normal c string cannot contain binary data cannot used store protobuf messages.)
so pb_ostream_from_buffer() correct way result "string".
taking simple.c example:
uint8_t buffer[128]; pb_ostream_t stream = pb_ostream_from_buffer(buffer, sizeof(buffer)); status = pb_encode(&stream, simplemessage_fields, &message); after encoded message in buffer , has length of stream.bytes_written. string want.
Comments
Post a Comment