I am trying to use the protobuf-c
library to send messages in between sockets in C.
Steps to reproduce
- Create a
.proto
file with the messages:
syntax = "proto3";
message MyMsg {}
Compile it with
protoc c_out=. rpc.proto
I get my rpc.pb-c.h/c files ready to use.Include the header, try to pack an empty message.
int main () {
MyMsg msg = MY_MSG__INIT;
size_t buflen = my_msg__get_packed_size(&msg);
printf("buflen: %zu\n", buflen);
}
prints 0.
Further details
Even if I ignore this and I allocate a larger buffer for packing the msg, the my_msg__pack(buf)
, function will not write any bytes into the buffer.
If I define a non-empty message, I do get some bytes into the buffer. Still, it seems to me the generated code only packs the body of the message, not the header, indicating the type of the message.
Question
Is there some other API I need to use in order to pack the whole message?