Yes, in your case the serialized size will remain the same because you are
using simple fixed-size fields and always initializing them.
There are a few things to watch out for, though:
- If you use proto3 syntax, zero-valued fields will be omitted from the
serialized output because zero is the default anyway. (But based on your
example you're using proto2, so that's not an issue.)
- Varints of course will be variable sized, so you will have to avoid those
and stick to fixed-size types.
- If you parse a message that has any unknown fields then those unknown
fields could take up an arbitrary amount of space when you reserialize the
On Mon, Sep 26, 2016 at 12:06 PM, <job4char...@gmail.com> wrote:
> 在 2016年9月26日星期一 UTC-4下午2:57:14，job4c...@gmail.com写道：
>> Will Google Protocol Buffer ensure this? This is a very important I think.
> Notes: My message only uses fixed32 and all fields are initialized(values
> might vary)
> Message test_msg
> optional fixed32 field1 = 1;
> optional fixed32 field2 = 2;
> test_msg msg;
> int size = msg.ByteSize(); // will this be a fixed length even if I
> upgrade Google Protocol Buffer?
> 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 firstname.lastname@example.org.
> 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 post to this group, send email to email@example.com.
Visit this group at https://groups.google.com/group/protobuf.
For more options, visit https://groups.google.com/d/optout.