Thanks Petteri, that makes sense.
So I was playing around with the union example. If rather than constructing just a submessage as in
/* Send message of type 3 */
MsgType3 msg = {3, 1415};
status = encode_unionmessage(&stream, MsgType3_fields, &msg);
instead I build from a top-level UnionMessage as follows:
UnionMessage uMsg = UnionMessage_init_zero;
uMsg.has_msg3 = true;
uMsg.msg3.value1 = 3;
uMsg.msg3.value2 = 1415;
status = pb_encode( &stream, UnionMessage_fields, &uMsg );
in both cases the data written to the stream (and the length) is the same:
Wrote 7 bytes:
1a 05 08 03 10 87 0b
Is that generally true? If so, is there a benefit to building just a submessage as opposed to a top-level with the optional parts filled in? Or is that the point of the example: to show that they are equivalent :)
Thanks again,
-- Ryan