使用 protobuf 定义一个结构
message One {
required uint32 type = 1;
required uint32 value = 2;
required uint32 size = 3;
}
使用 protobuf 官方的 go 插件得到的代码
type One struct {
Type *uint32 `protobuf:"varint,1,req,name=type" json:"type,omitempty"`
Value *uint32 `protobuf:"varint,2,req,name=value" json:"value,omitempty"`
Size *uint32 `protobuf:"varint,3,req,name=size" json:"size,omitempty"`
XXX_unrecognized []byte `json:"-"`
}
这里的 Size 字段是正常的,没有被修改,如果使用 gogoproto 插件生成的代码,就是这样的
type One1 struct {
Type *uint32 `protobuf:"varint,1,req,name=type" json:"type,omitempty"`
Value *uint32 `protobuf:"varint,2,req,name=value" json:"value,omitempty"`
Size_ *uint32 `protobuf:"varint,3,req,name=size" json:"size,omitempty"`
XXX_NoUnkeyedLiteral struct{} `json:"-"`
XXX_unrecognized []byte `json:"-"`
XXX_sizecache int32 `json:"-"`
}
Size 字段被编译成 Size_了 有没有办法解决这个问题呢
如果是新项目还好,这个是老的项目,有很多关联代码,修改起来好痛苦😭