protocolbuffers / protobuf

Protocol Buffers - Google's data interchange format
http://protobuf.dev
Other
65.67k stars 15.5k forks source link

text_format Augmented map syntax #10251

Closed semtexzv closed 9 months ago

semtexzv commented 2 years ago

What language does this apply to? text_format

Describe the problem you are trying to solve. Currently, the text_format s a nice debugging tool, However, there are a few drawbacks, when trying to use it as a proper developer-facing interface. One of the issues is maps. We currently don't have a native syntax for specifying maps, apart from emulating them with messages.

Describe the solution you'd like Add following lines to text_format spec and implement the changes in text_format parser and generator.

Section Fields:

MapMessageField = ScalarValue ":" ( MessageValue | MessageList ) [ ";" | "," ];
MapScalarField = ScalarValue ":" ( ScalarValue | ScalarList ) [ ";" | "," ];
change:
Field = ScalarField | MessageField ;
to: 
Field = ScalarField | MessageField | MapScalarField | MapMessageField ;

This would allow us to write a following syntax:

position_map {
  "name": 1 ,
  "value: 2
}
map_field {
  0: "Hello"
  1: "World"
}

This format is already used by protoc --decode_raw.

Drawbacks Since we're adding new variants to the Field syntactic elements, All parsers would have to have one more branch to reject this element if not applicable

Describe alternatives you've considered Changing the spec in following way

MessageField = ScalarValue, [ ":" ], ( MessageValue | MessageList ) [ ";" | "," ];
ScalarField  = ScalarValue, ":",     ( ScalarValue  | ScalarList  ) [ ";" | "," ];

Would result in a much simpler grammar, but in this grammar, parser for each message would have to deal with field keys that are literals, and fail if it did not accept the map syntax.

Additional context I'm implementing a protobuf implementation that contains this feature, and since this has been a very useful feature so far, I want to standardize it.

acozzette commented 2 years ago

This sounds like it would be a nice thing to have, but unfortunately I don't think we will be able to prioritize this any time soon. Text format changes are not easy to do since they have to be implemented in all languages for consistency.

github-actions[bot] commented 9 months ago

We triage inactive PRs and issues in order to make it easier to find active work. If this issue should remain active or becomes active again, please add a comment.

This issue is labeled inactive because the last activity was over 90 days ago.

github-actions[bot] commented 9 months ago

We triage inactive PRs and issues in order to make it easier to find active work. If this issue should remain active or becomes active again, please reopen it.

This issue was closed and archived because there has been no new activity in the 14 days since the inactive label was added.