【发布时间】:2018-11-15 04:33:55
【问题描述】:
我正在编写一个关于 gRPC 的 tutorial。当我生成.pb.go 文件时,我的结构中得到了一些XXX_* 类型。
这是我的consignment.proto 文件:
syntax = "proto3";
package go.micro.srv.consignment;
service ShippingService {
rpc CreateConsignment(Consignment) returns (Response) {}
}
message Consignment {
string id = 1;
string description = 2;
int32 weight = 3;
repeated Container containers = 4;
string vessel_id = 5;
}
message Container {
string id = 1;
string customer_id = 2;
string origin = 3;
string user_id = 4;
}
message Response {
bool created = 1;
Consignment consignment = 2;
}
这是.pb.go 文件中的结构。有人可以告诉我为什么我的struct 中有 3 个XXX 类型吗?结构不应该反映我在proto 中定义的内容吗?
type Consignment struct {
Id string `protobuf:"bytes,1,opt,name=id" json:"id,omitempty"`
Description string `protobuf:"bytes,2,opt,name=description" json:"description,omitempty"`
Weight int32 `protobuf:"varint,3,opt,name=weight" json:"weight,omitempty"`
Containers []*Container `protobuf:"bytes,4,rep,name=containers" json:"containers,omitempty"`
VesselId string `protobuf:"bytes,5,opt,name=vessel_id,json=vesselId" json:"vessel_id,omitempty"`
XXX_NoUnkeyedLiteral struct{} `json:"-"`
XXX_unrecognized []byte `json:"-"`
XXX_sizecache int32 `json:"-"`
}
【问题讨论】:
-
这些是实现细节。可以关注相关问题中的讨论:github.com/golang/protobuf/issues/276
标签: go protocol-buffers grpc