[protobuf] encode ID (?)

32 weergaven
Naar het eerste ongelezen bericht

lamer lamerovich

ongelezen,
8 dec 2011, 01:30:3908-12-2011
aan 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

ongelezen,
10 dec 2011, 14:10:1410-12-2011
aan 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;

Allen beantwoorden
Auteur beantwoorden
Doorsturen
0 nieuwe berichten