On Fri, Aug 19, 2016 at 10:50 AM, <[email protected]> wrote: > The question is: > > My message looks like: > > Message data > { > optional uint32 object_id = 1; > optional uint32 next_id = 2; > } > > I might define my message object like below: > > data; > size_t msg_size_before = data.ByteSize(); > > uint32 id = CreateNewId(); > uint32 next_id = GetCurNextId(); > > data.set_object_id(id); > data.set_next_id(next_id); > > size_t msg_size_after = data.ByteSize(); > > > Since I defined only integers in my message type, can I always assume > assert "msg_size_before == msg_size_after" ???? > No, you can't.
In protobuf an uint32 field type uses variable-length encoding. That means its byte size depends on the actual value of the field. If you set a new value, the byte size can change as well. > -- > You received this message because you are subscribed to the Google Groups > "Protocol Buffers" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > To post to this group, send email to [email protected]. > Visit this group at https://groups.google.com/group/protobuf. > For more options, visit https://groups.google.com/d/optout. > -- You received this message because you are subscribed to the Google Groups "Protocol Buffers" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at https://groups.google.com/group/protobuf. For more options, visit https://groups.google.com/d/optout.
