[protobuf] encode ID (?)

32 views
Skip to first unread message

lamer lamerovich

unread,
Dec 8, 2011, 1:30:39 AM12/8/11
to Protocol Buffers
I study a format protobuf

message Test1 {
optional int32 a = 0;
}

ERROR
>protoc.exe --cpp_out=CPP2 sample.txt
sample.txt:2:22: Field numbers must be positive integers.

IF

message Test1 {
optional int32 a = 1;
}

OK!

For what the ZERO is reserved?

Tom Swirly

unread,
Dec 10, 2011, 2:10:14 PM12/10/11
to prot...@googlegroups.com
A simple and somewhat-accurate answer is "it's reserved to mean 'no field'".

It's certainly handy in your code to use 0 that way - for example:

if (uint tag = possiblyComputeSomeTagID(thing))
  doStuff(tag);
else
  LOG(ERROR) << "No tag for: " << thing;

Reply all
Reply to author
Forward
0 new messages