singular: a well-formed message can have zero or one of this field (but not more than one).Message fields can be one of the following: Similarly, you cannot use any previously reserved field numbers. You also cannot use the numbers 19000 through 19999 ( FieldDescriptor::kFirstReservedNumber through FieldDescriptor::kLastReservedNumber), as they are reserved for the Protocol Buffers implementation-the protocol buffer compiler will complain if you use one of these reserved numbers in your. The smallest field number you can specify is 1, and the largest is 2 29 - 1, or 536,870,911. Remember to leave some room for frequently occurring elements that might be added in the future. So you should reserve the numbers 1 through 15 for very frequently occurring message elements.
Field numbers in the range 16 through 2047 take two bytes. Note that field numbers in the range 1 through 15 take one byte to encode, including the field number and the field's type (you can find out more about this in Protocol Buffer Encoding).
These field numbers are used to identify your fields in the message binary format, and should not be changed once your message type is in use. Assigning Field NumbersĪs you can see, each field in the message definition has a unique number. However, you can also specify composite types for your fields, including enumerations and other message types. In the above example, all the fields are scalar types: two integers ( page_number and result_per_page) and a string ( query).
proto file syntax and how to generate data access classes from your. This guide describes how to use the protocol buffer language to structure your protocol buffer data, including.