> On Aug 19, 2016, at 10:45 AM, job4char...@gmail.com 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.

Protobuf uses variable-length integer encodings, so the size will change 
depending on the exact integer values.

If you need the size to be the same, you can use "fixed32" field type instead 
of "uint32".

Tim



-- 
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 protobuf+unsubscr...@googlegroups.com.
To post to this group, send email to protobuf@googlegroups.com.
Visit this group at https://groups.google.com/group/protobuf.
For more options, visit https://groups.google.com/d/optout.

Reply via email to