extending field and message options

41 views
Skip to first unread message

Arpit Baldeva

unread,
Mar 13, 2017, 4:15:28 PM3/13/17
to Protocol Buffers
Hi,

I have my proto file like following.

package example;

message ExFieldOptions 
{
  map<string, string> meta_data = 1;
}

extend google.protobuf.FieldOptions 
{
    ExFieldOptions exOptions = 4245; 
}

extend google.protobuf.MessageOptions 
{
    ExFieldOptions exOptions = 4245; 

When I run it through ProtoC (for C++ code generation), I run into an error

"exOptions" is already defined in "example".

Is this a bug? Or is it required that extension name need to be unique across options?

Thanks. 

Adam Cozzette

unread,
Mar 14, 2017, 10:37:26 AM3/14/17
to Arpit Baldeva, Protocol Buffers
I believe this is to be expected, because these top-level extensions would end up having the same name. For example in C++ they would both be called example::exOptions and so there would be a conflict there. To get around this you can either give them different names or keep the same names but nest them inside of messages, like this:

message MessageOptionsExtension {

--
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+unsubscribe@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.

Josh Humphries

unread,
Mar 14, 2017, 2:59:17 PM3/14/17
to Arpit Baldeva, Protocol Buffers
All fully-qualified symbols must be a unique for an invocation of protoc. In the generated code, you can refer to the generated extension (just like referring to generated messages, enums, and services), and if their fully-qualified names weren't unique, it would result in compilation errors in the generated code.

----
Josh Humphries
jh...@bluegosling.com

--
Reply all
Reply to author
Forward
0 new messages