zero size of a protobuf message

25 views
Skip to first unread message

Евгений Х

unread,
Apr 17, 2020, 5:53:56 PM4/17/20
to Protocol Buffers
Hello!
I have the protobuf message like this:

message SomeMessage {
    optional uint32 result = 1;
}

When I don't fill the result field and then call the ByteSize function it returns 0.

Is it correct?

P.S. C++ program

Nadav Samet

unread,
Apr 17, 2020, 6:22:46 PM4/17/20
to Евгений Х, Protocol Buffers
Yes, this is the expected behavior. Unset optional fields are not serialized, so the total size of the serialized message is zero. You can parse back an empty array of bytes to get an instance of SomeMessage with an unset `result` field.


--
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+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/protobuf/77dc856a-9814-417c-82fa-e922a7c48107%40googlegroups.com.


--
-Nadav

Евгений Х

unread,
Apr 17, 2020, 6:33:54 PM4/17/20
to Protocol Buffers
Thanks for response
Reply all
Reply to author
Forward
0 new messages