why
why

Reputation: 24851

What does "1", "2", "3" mean in protobuf?

package tutorial;

message Person {
  required string name = 1;
  required int32 id = 2;
  optional string email = 3;
}

What does "1", "2", "3" mean ?

Upvotes: 15

Views: 6263

Answers (2)

user647772
user647772

Reputation:

Each field in the message definition has a unique numbered tag. These tags are used to identify your fields in the message binary format, and should not be changed once your message type is in use.

https://web.archive.org/web/20120321055631/http://code.google.com/intl/de-DE/apis/protocolbuffers/docs/proto.html

Upvotes: 13

Jon Skeet
Jon Skeet

Reputation: 1500825

They're the field numbers - they're used in the wire representation to identify which field is associated with a value. This means that renaming a field isn't a breaking change (in terms of wire format) and the names themselves don't have to be serialized.

Upvotes: 8

Related Questions