Protobufs: options in .proto files

540 views
Skip to first unread message

Tess Rinearson

unread,
Jan 7, 2015, 8:24:40 PM1/7/15
to golan...@googlegroups.com
TL;DR: Does golang/protobuf support custom options? 

I’m playing around with generating files from .proto files. We have a service written in JS that uses proto files to generate JS objects, and we want to be able to use the same proto files for our Go services.

I can get golang/protobuf working with the example .proto file, which looks like this: 

package example;

enum FOO { X = 17; };

message Test {
  required string label = 1;
  optional int32 type = 2 [default=77];
  repeated int64 reps = 3;
  optional group OptionalGroup = 4 {
    required string RequiredField = 5;
  }
}

This file doesn’t have any options or field options other than “default,” which is a built-in field option,  I think. (I’m kind of a protobuf noob, so bear with me please.) 

Anyways, our preexisting proto files use options and custom field options, kind of like this: 

package example;

message Vegetable {
  option key = "Vegetable";

  optional string vegetable_id = 1;
  optional string name = 2  [removed=true];
}

When I try to run protoc on that, I get: 

example.proto:7:30: Option "removed" unknown.
example.proto:4:10: Option "key" unknown.

Does that mean that golang/protobuf doesn’t support custom options? 

There’s a line in golang/protobuf that says “TODO: options.” (https://github.com/golang/protobuf/blob/3ea3e05dbfae8d2dd0cc219b5f0f0ba4606d15eb/protoc-gen-go/generator/generator.go#L1424) which makes me think that they’re not supported yet, but I wanted to double check. :) Is this something that the team is already working on? And if not, is that something I (or one of my coworkers) could contribute?

If options are already supported--Is there something else I need to do to add my custom options to get the generator to recognize them?

Or, if they’re not supported and golang/protobuf won’t be able support them anytime soon, does anyone have a good way to add custom options to protos for golang? 

Thank you! 

Tess

Rob Pike

unread,
Jan 7, 2015, 8:29:13 PM1/7/15
to Tess Rinearson, golan...@googlegroups.com
They are not supported. There are no plans to support them but that may change.

However, your example looks more like user error. The message is coming from protoc, not the Go plugin. You're using a custom option that is not defined.

-rob


--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Tess Rinearson

unread,
Jan 8, 2015, 2:44:54 PM1/8/15
to golan...@googlegroups.com, tess.ri...@gmail.com
Oops. Well, that's embarrassing.

Anyways, thanks for pointing that out and also for clarifying the state of custom option support! 

kwi...@gmail.com

unread,
Jan 30, 2016, 11:36:18 AM1/30/16
to golang-nuts, tess.ri...@gmail.com
It seems go doesn't support custom protobuf options still.  Are there any plans for support?
Reply all
Reply to author
Forward
0 new messages