ProtobufCBuffer struct
Structure for defining a virtual append-only buffer. Used by protobuf_c_message_pack_to_buffer() to abstract the consumption of serialized bytes. `ProtobufCBuffer` "subclasses" may be defined on the stack. For example, to write to a `FILE` object: ~~~{.c} typedef struct { ProtobufCBuffer base; FILE *fp; } BufferAppendToFile; static void my_buffer_file_append(ProtobufCBuffer *buffer, size_t len, const uint8_t *data) { BufferAppendToFile *file_buf = (BufferAppendToFile *) buffer; fwrite(data, len, 1, file_buf->fp); // XXX: No error handling! } ~~~ To use this new type of ProtobufCBuffer, it could be called as follows: ~~~{.c} ... BufferAppendToFile tmp = {0}; tmp.base.append = my_buffer_file_append; tmp.fp = fp; protobuf_c_message_pack_to_buffer(&message, &tmp); ... ~~~