Skip to content

Using FieldOptions in both Go and C++ #97

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

Closed
hochhaus opened this issue Nov 12, 2015 · 4 comments
Closed

Using FieldOptions in both Go and C++ #97

hochhaus opened this issue Nov 12, 2015 · 4 comments

Comments

@hochhaus
Copy link

I have a *.proto file which uses FieldOptions.

syntax = "proto2";

import "google/protobuf/descriptor.proto";

enum Int64Encoding {
  JS_DEFAULT = 0;
  JS_NUMBER = 1;
}

extend google.protobuf.FieldOptions {
  optional Int64Encoding jstype = 50001;
}

I wish to use this protocol buffer from both C++ and go.

However, protoc-gen-go generates the following import path in the *.pb.go file:

import google_protobuf "google/protobuf"

However, in the go protobuf implementation descriptor.pb.go lives at a different path location. It seems to me that possibly protoc-gen-go should be special cased to write the import as:

import google_protobuf "github.com/golang/protobuf/protoc-gen-go/descriptor"

Does this seem like reasonable behavior for descriptor.proto imports? If so, I will send a patch set. If not, I can easily work around this in our build layer.

@dsymonds
Copy link
Contributor

The Go code generator doesn't treat any import paths as particularly special (that might change as part of #50), so the "google/protobuf" import path is simply a mechanical transformation. You can use the M parameter to declare what the import path should be.

The descriptor package in this repo is really only meant to be for protoc-gen-go's use.

@zeroZshadow
Copy link

Sorry to ask after closing, but how does the M parameter work?

@hochhaus
Copy link
Author

You can include "M" in your --go_out flag in the following form:

protoc --go_out=M<.proto>=<package>:. <proto>

So if you want to rewrite descriptor.proto (as per my original question), that would look like:

protoc --go_out=Mgoogle/protobuf/descriptor.proto=github.com/golang/protobuf/protoc-gen-go/descriptor:. <file.proto>

You can also include multiple "M" arguments as a comma separated list.

@Antonboom
Copy link

@hochhaus

Where can I read more about this "M" option?

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

4 participants