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

Language guide: 'Any' → 'google.protobuf.Any' #828

Closed
wking opened this issue Sep 26, 2015 · 0 comments
Closed

Language guide: 'Any' → 'google.protobuf.Any' #828

wking opened this issue Sep 26, 2015 · 0 comments

Comments

@wking
Copy link

wking commented Sep 26, 2015

I couldn't find the repository behind the Any docs, so I'm filing this here.

The current example:

$ cat test.proto
syntax = "proto3";

import "google/protobuf/any.proto";

message ErrorStatus {
  string message = 1;
  repeated Any details = 2;
}

Fails to compile:

$ protoc --go_out=./go test.proto 
test.proto:7:12: "Any" is not defined.
[libprotobuf WARNING google/protobuf/descriptor.cc:6135] Warning: Unused import: "test.proto" imports "google/protobuf/any.proto" which is not used.

But with a namepaced google.protobuf.Any it works:

$ sed -i 's/Any/google.protobuf.Any/' test.proto
$ protoc --go_out=./go test.proto
$ echo $?
0
wking added a commit to wking/opencontainer-runtime-spec that referenced this issue Sep 26, 2015
Define syntax to fix [1]:

  protoc --go_out=./go config.proto
  [libprotobuf WARNING google/protobuf/compiler/parser.cc:492] No
    syntax specified for the proto file. Please use 'syntax =
    "proto2";' or 'syntax = "proto3";' to specify a syntax
    version. (Defaulted to proto2 syntax.)

Drop 'optional' (with 'sed -i 's/\toptional /\t/' *.proto') to fix:

  protoc --go_out=./go config.proto
  config.proto:9:18: Explicit 'optional' labels are disallowed in the
    Proto3 syntax. To define 'optional' fields in Proto3, simply
    remove the 'optional' label, as fields are 'optional' by default.

Replace the User extensions with 'Any' [2,3] to fix:

  protoc --go_out=./go config.proto
  config.proto: Extensions in proto3 are only allowed for defining
    options.

Drop required (with 'sed -i 's/\trequired /\t/' *.proto') to fix:

  protoc --go_out=./go runtime_config.proto
  runtime_config.proto: Required fields are not allowed in proto3.

Drop DefaultState to fix:

  protoc --go_out=./go runtime_config.proto
  runtime_config.proto: Explicit default values are not allowed in
    proto3.

There's still some trouble with the resulting Go:

  go run ./example.go
  go/config.pb.go:26:8: cannot find package "google/protobuf" in any of:
          /usr/lib/go/src/google/protobuf (from $GOROOT)
          /home/wking/.local/lib/go/src/google/protobuf (from $GOPATH)
  Makefile:31: recipe for target 'example' failed

But I haven't been able to figure that out yet.

[1]: https://developers.google.com/protocol-buffers/docs/proto3#simple
[2]: https://developers.google.com/protocol-buffers/docs/proto3#any
[3]: protocolbuffers/protobuf#828

Signed-off-by: W. Trevor King <wking@tremily.us>
@xfxyjwf xfxyjwf closed this as completed Mar 7, 2017
adellahlou pushed a commit to adellahlou/protobuf that referenced this issue Apr 20, 2023
"minimal" doesn't include `Root`, as mentioned in protocolbuffers#828 and protocolbuffers#856. Probably caused by protocolbuffers#813.
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

2 participants