Re: [protobuf] Enum field encoding question

2020-01-16 Thread Marc Gravell
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  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 protobuf+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/protobuf/376341b9-b429-4abe-b9ea-aeb2834c6f58%40googlegroups.com
> 
> .
>


-- 
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 protobuf+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/protobuf/CAF95VAx2iLESr0Q18dF3ph-6xosCHEPet468qF-X7dyojGVT-g%40mail.gmail.com.


[protobuf] Enum field encoding question

2020-01-16 Thread Burak Kirazli
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 protobuf+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/protobuf/376341b9-b429-4abe-b9ea-aeb2834c6f58%40googlegroups.com.