作者:真实的小莹_808 | 来源:互联网 | 2022-12-14 21:27
我正在编写有关gRPC 的教程。当我生成.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
文件中的结构。有人可以告诉我为什么我有3 XXX
种类型struct
吗?该结构不应该反映我在自己中定义的内容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:"-"`
}
Carl Mastran..
8
XXX_
Protobuf库使用这些类型来存储未知字段。解码原型时,序列化数据中可能会有其他字段,库不知道该如何处理。例如,当数据的读取器和写入器使用原始文件的不同副本时,可能会发生这种情况。此功能有助于在客户端之间向后兼容,并在不同时间构建服务。
另外,XXX字段允许您公开扩展,它们是Proto2的一部分。它们在Proto3中被删除,以支持Any,但是库仍然需要支持它们。
至于你应该怎么做呢?我只是让他们独自一人,不要引用它们。您不需要设置它们,也不需要阅读它们。Go protobuf库将为您处理它们。
1> Carl Mastran..:
XXX_
Protobuf库使用这些类型来存储未知字段。解码原型时,序列化数据中可能会有其他字段,库不知道该如何处理。例如,当数据的读取器和写入器使用原始文件的不同副本时,可能会发生这种情况。此功能有助于在客户端之间向后兼容,并在不同时间构建服务。
另外,XXX字段允许您公开扩展,它们是Proto2的一部分。它们在Proto3中被删除,以支持Any,但是库仍然需要支持它们。
至于你应该怎么做呢?我只是让他们独自一人,不要引用它们。您不需要设置它们,也不需要阅读它们。Go protobuf库将为您处理它们。