[英]new version of protoc-gen-go drops already known types
There are two .proto files 有两个.proto文件
1st file | 第一个文件| name "a.proto"
名称为“ a.proto”
syntax = "proto3";
package a;
message AMsg{
fixed64 smth1 = 1;
fixed64 smth2 = 2;
}
2nd file | 第二档| name "b.proto"
名称“ b.proto”
syntax = "proto3";
package b;
import "a.proto";
message BMsg {
a.AMsg msg1 = 1;
a.AMsg msg2 = 2;
}
previous versions of protoc-gen-go generated the following code: protoc-gen-go的早期版本生成以下代码:
file "a.pb.go" 文件“ a.pb.go”
package b
import proto "github.com/golang/protobuf/proto"
import fmt "fmt"
import math "math"
. . .
type AMsg struct {
smth1 uint64
smth2 uint64
}
. . .
file "b.pb.go" 文件“ b.pb.go”
package b
import proto "github.com/golang/protobuf/proto"
import fmt "fmt"
import math "math"
import "a"
. . .
type BMsg struct {
msg1 *a.AMsg
msg2 *a.AMsg
}
. . .
and everything was alright, 一切都很好,
but 但
one day a new version of protoc-gen-go had come 有一天,新版本的protoc-gen-go来了
and file "b.pb.go" now looks like this: 现在, 文件“ b.pb.go”如下所示:
package b
import proto "github.com/golang/protobuf/proto"
import fmt "fmt"
import math "math"
. . .
type BMsg struct {
msg1 *AMsg
msg2 *AMsg
}
. . .
you can notice that already known types are dropped here, but i can't find out the reason. 您可以注意到此处已经删除了已知类型,但是我找不到原因。 (ie prefix "a." i missing)
(即前缀“ a”。我不见了)
this link https://developers.google.com/protocol-buffers/docs/reference/go-generated says nothing about the new approach 此链接https://developers.google.com/protocol-buffers/docs/reference/go-genic并没有说明新方法
What should I do to make protoc-gen-go to generate "b.pb.go" without these drops? 我该怎么做才能使protoc-gen-go生成没有这些滴的“ b.pb.go”?
go_package
option solved this, you should explicitly specify the package in a.proto
go_package
选项解决了这个问题,您应该在a.proto
明确指定软件包
like this: 像这样:
syntax = "proto3";
package a;
option go_package= "some_path/A";
message AMsg{
fixed64 smth1 = 1;
fixed64 smth2 = 2;
}
so you will get right generated types from a.proto
in other proto files 因此您将从其他proto文件中的
a.proto
获取正确的生成类型
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.