Skip to content

Commit

Permalink
encoding/protobuf: parse message options
Browse files Browse the repository at this point in the history
Converted to CUE attributes.

Fixes #366

Change-Id: Id5434d8f1f1296d12a6e56ca7fd0b5ce3e7fcdcc
Reviewed-on: https://cue-review.googlesource.com/c/cue/+/7284
Reviewed-by: CUE cueckoo <cueckoo@gmail.com>
Reviewed-by: Marcel van Lohuizen <mpvl@golang.org>
  • Loading branch information
mpvl committed Oct 2, 2020
1 parent 65468d5 commit 3af2683
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
9 changes: 9 additions & 0 deletions encoding/protobuf/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -543,6 +543,15 @@ func (p *protoConverter) messageField(s *ast.StructLit, i int, v proto.Visitee)
case *proto.Extensions, *proto.Reserved:
// no need to handle

case *proto.Option:
opt := fmt.Sprintf("@protobuf(option %s=%s)", x.Name, x.Constant.Source)
attr := &ast.Attribute{
At: p.toCUEPos(x.Position),
Text: opt,
}
addComments(attr, i, x.Doc(), x.InlineComment)
s.Elts = append(s.Elts, attr)

default:
failf(scanner.Position{}, "unsupported field type %T", v)
}
Expand Down
4 changes: 4 additions & 0 deletions encoding/protobuf/testdata/acme/test.proto
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,9 @@ syntax = "proto3";
package acme.test;

message Test {
// doc comment
option (yoyo.foo) = true; // line comment

option (yoyo.bar) = false;
int32 test = 1;
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package test

#Test: {
// doc comment
@protobuf(option (yoyo.foo)=true) // line comment
@protobuf(option (yoyo.bar)=false)
test?: int32 @protobuf(1)
}

0 comments on commit 3af2683

Please sign in to comment.