Reserved keyword usage in protobuf 2.5.0

7,853 views
Skip to first unread message

Marcos Juarez

unread,
May 25, 2016, 5:44:38 PM5/25/16
to Protocol Buffers
I ran into a situation today in which I needed to use the "reserved" keyword in a protobuf definition, so that in the future, nobody would use those fields.  I've attached a screenshot of what the docs say, from https://developers.google.com/protocol-buffers/docs/proto#reserved 

Inline image 1

However, when I try to use that keyword in an actual message with field definitions, protoc always complains with the following error:

Expected "required", "optional", or "repeated".

My protobuf definition looks like this:

message MyMessage {
      // Some comments
      reserved, 4, 108, 109;
      
      // Some more comments
      required string event_uuid            = 1     ;
      required string date                  = 2     ;
      required string timezone              = 3     ;

      optional string field1                = 101   ;
      optional string field2                = 110   ;
}
     
Am I reading that spec wrong, or is the reserved keyword broken?

Marcos

Ilia Mirkin

unread,
May 25, 2016, 5:47:08 PM5/25/16
to Marcos Juarez, Protocol Buffers
On Wed, May 25, 2016 at 5:44 PM, Marcos Juarez <mju...@gmail.com> wrote:
I ran into a situation today in which I needed to use the "reserved" keyword in a protobuf definition, so that in the future, nobody would use those fields.  I've attached a screenshot of what the docs say, from https://developers.google.com/protocol-buffers/docs/proto#reserved 

Inline image 1

However, when I try to use that keyword in an actual message with field definitions, protoc always complains with the following error:

Expected "required", "optional", or "repeated".

My protobuf definition looks like this:

message MyMessage {
      // Some comments
      reserved, 4, 108, 109;

Did you mean "reserved 4, 108, 109;"?

  -ilia

Marcos Juarez

unread,
May 25, 2016, 5:50:03 PM5/25/16
to Protocol Buffers
I just realized, there's a typo in my example.  It should say:  

   reserved 4, 108, 109;

Note there's no comma after the reserved keyword.  

Also, I checked, and the protoc compiler I'm using reports itself as:  libprotoc 2.5.0

Feng Xiao

unread,
May 25, 2016, 10:01:58 PM5/25/16
to Marcos Juarez, Protocol Buffers
On Wed, May 25, 2016 at 5:49 PM, Marcos Juarez <mju...@gmail.com> wrote:
I just realized, there's a typo in my example.  It should say:  

   reserved 4, 108, 109;

Note there's no comma after the reserved keyword.  

Also, I checked, and the protoc compiler I'm using reports itself as:  libprotoc 2.5.0
The reserved keyword was added in v3.0.0-alpha-3:

You have to upgrade your protobuf version to use it.
 


On Wed, May 25, 2016 at 3:44 PM, Marcos Juarez <mju...@gmail.com> wrote:
I ran into a situation today in which I needed to use the "reserved" keyword in a protobuf definition, so that in the future, nobody would use those fields.  I've attached a screenshot of what the docs say, from https://developers.google.com/protocol-buffers/docs/proto#reserved 

Inline image 1

However, when I try to use that keyword in an actual message with field definitions, protoc always complains with the following error:

Expected "required", "optional", or "repeated".

My protobuf definition looks like this:

message MyMessage {
      // Some comments
      reserved, 4, 108, 109;
      
      // Some more comments
      required string event_uuid            = 1     ;
      required string date                  = 2     ;
      required string timezone              = 3     ;

      optional string field1                = 101   ;
      optional string field2                = 110   ;
}
     
Am I reading that spec wrong, or is the reserved keyword broken?

Marcos

--
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+u...@googlegroups.com.
To post to this group, send email to prot...@googlegroups.com.
Visit this group at https://groups.google.com/group/protobuf.
For more options, visit https://groups.google.com/d/optout.

Marcos Juarez

unread,
May 26, 2016, 12:25:06 PM5/26/16
to Feng Xiao, Protocol Buffers
Thanks Feng.  

It does look like the documentation is wrong then.  I checked, and the "Reserved" section shows up when looking at the Language Guide for both proto2 and proto3.

Feng Xiao

unread,
May 26, 2016, 9:29:07 PM5/26/16
to Marcos Juarez, Protocol Buffers
On Thu, May 26, 2016 at 12:25 PM, Marcos Juarez <mju...@gmail.com> wrote:
Thanks Feng.  

It does look like the documentation is wrong then.  I checked, and the "Reserved" section shows up when looking at the Language Guide for both proto2 and proto3.
It might be a little confusing but proto2 doesn't correspond to v2.x and proto3 doesn't correspond to v3.x. Proto2 and proto3 are two proto language versions that are both supported in v3.x and some proto2 features are added in v3.x (e.g., map fields).
Reply all
Reply to author
Forward
0 new messages