Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Aggregate option syntax not supported #95

Closed
boolking opened this issue Dec 27, 2013 · 10 comments
Closed

Aggregate option syntax not supported #95

boolking opened this issue Dec 27, 2013 · 10 comments

Comments

@boolking
Copy link

According official protobuf documentation, options can be written in aggregate syntax, so repeated field in option's message can be supported:

import "google/protobuf/descriptor.proto";

message FooOption {
  optional int32 opt1 = 1;
  optional string opt2 = 2;
}

message FooOptions {
  repeated FooOption options = 1;
}

extend google.protobuf.FieldOptions {
  optional FooOptions foo_options = 1234;
}

// usage:
message Bar {
  // alternative aggregate syntax (uses TextFormat):
  optional int32 b = 2 
  [(foo_options) = {options { opt1: 1234 opt2: "baz" } options { opt1: 4321 opt2: "foo" }} ];
}

Official protobuf parser implemented text format parser and use it in aggregate option syntax parsing.

@dcodeIO
Copy link
Member

dcodeIO commented Dec 27, 2013

Interesting, never heard of that. Can you provide me with a link?

@boolking
Copy link
Author

Just above this link:
https://developers.google.com/protocol-buffers/docs/proto#generating
And official parser code resident in parser.cc, ParseOption() -> ParseUninterpretedBlock()) and descriptor.cc, SetAggregateOption().

@sjincho
Copy link

sjincho commented May 30, 2015

Hi,

Is there any progress in this? The aggregate syntax is also described here, at the bottom of the custom options section:
https://developers.google.com/protocol-buffers/docs/proto#customoptions

@callmehiphop
Copy link

/bump

has any progress been made on this?

@dcodeIO
Copy link
Member

dcodeIO commented Jul 16, 2015

Just thought I could do it and gave it a try, but I then realized that this is one of the edges where the initial custom design bites back. The internal workings of ProtoBuf.js do not rely on any descriptors to be present and thus it just parses any options "as is". In this exact case however, there is no way to know whether an option is repeated or something. I am sure it can be done "somehow", but that old parser code gives me headaches.

dcodeIO added a commit that referenced this issue Jul 17, 2015
@dcodeIO
Copy link
Member

dcodeIO commented Jul 17, 2015

Works now:

optional string desc3 = 4 [(foo_options) = { opt1: 123 opt2: "baz" }];

Parses now, but exposes just the last array-option element:

optional string desc4 = 5 [(foo_options) = {options { opt1: 1234 opt2: "baz" } options { opt1: 4321 opt2: "foo" }} ];

@dcodeIO
Copy link
Member

dcodeIO commented Jul 17, 2015

The latter now also works, but as ProtoBuf.js doesn't know what exactly is repeated, it just converts duplicate options to arrays. The result is:

{
  "(foo_options).options.opt1": [1234, 4321],
  "(foo_options).options.opt2": ["baz", "foo"]
}

@callmehiphop
Copy link

awesome! 👍

@AmandaCameron
Copy link

This doesn't seem to work with options defined in imported files, not under Proto3 at least. I can whip up a sample tomorrow if you'd like, just thought I'd comment now. :)

@dcodeIO
Copy link
Member

dcodeIO commented Nov 28, 2016

Closing this for now.

protobuf.js 6.0.0

Feel free to send a pull request if this is still a requirement.

@dcodeIO dcodeIO closed this as completed Nov 28, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants