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 #8

Closed
zealic opened this issue Sep 6, 2017 · 1 comment
Closed

Aggregate option syntax not supported #8

zealic opened this issue Sep 6, 2017 · 1 comment

Comments

@zealic
Copy link

zealic commented Sep 6, 2017

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

See also: https://developers.google.com/protocol-buffers/docs/proto#customoptions

Input (test.proto)

syntax = "proto3";
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):
  int32 b = 2 [(foo_options) = {
    opt1: 123,
    opt2: "baz"
  }];
}

TestCode

package main

import (
	"os"

	"github.com/emicklei/proto"
)

func main() {
	reader, _ := os.Open("test.proto")
	defer reader.Close()
	parser := proto.NewParser(reader)
	definition, _ := parser.Parse()
	formatter := proto.NewFormatter(os.Stdout, "   ")
	formatter.Format(definition)
}

Output

syntax = "proto3";
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;
}
@emicklei
Copy link
Owner

emicklei commented Sep 6, 2017

thank you for reporting this and providing a test example.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants