Hi; default values *are not sent*, especially in proto3 where zero is default and default is zero. Likewise, the root object in a message is not wrapped in any way - only fields *on* the root object.
This means that the binary encoding of a CommandRequest with Code.RESET is: zero bytes, which is a perfectly valid size in protobuf. Sometimes, people find it convenient / helpful to use a DEFAULT / NONE / UNKNOWN = 0, with their *actual* enum values above that. This makes the default experience easier to understand, and avoid problems. Marc On Thu, 16 Jan 2020 at 08:08, Burak Kirazli <[email protected]> wrote: > Hello, > > I am new to protobuf. > > I have a request message like that > > message CommandRequest > { > enum Code > { > RESET = 0; > ERASE_APP = 2; > ERASE_OTA = 3; > } > > Code code = 1; > } > > When I am trying to encode a request with zero value, i see that encoded > size is zero. What will be exchanged? > > //Qt project > > CommandRequest req; > req.set_code(CommandRequest_Code::CommandRequest_Code_RESET); > qDebug() << req.ByteSizeLong() << endl; > > //Output of this code is: > 0 > > > Thanks. > > -- > 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 view this discussion on the web visit > https://groups.google.com/d/msgid/protobuf/376341b9-b429-4abe-b9ea-aeb2834c6f58%40googlegroups.com > <https://groups.google.com/d/msgid/protobuf/376341b9-b429-4abe-b9ea-aeb2834c6f58%40googlegroups.com?utm_medium=email&utm_source=footer> > . > -- Regards, Marc -- 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 view this discussion on the web visit https://groups.google.com/d/msgid/protobuf/CAF95VAx2iLESr0Q18dF3ph-6xosCHEPet468qF-X7dyojGVT-g%40mail.gmail.com.
