作者:Ruby | 来源:互联网 | 2022-12-30 11:14
对于原型:
syntax = "proto3";
package messagepb;
import "github.com/gogo/protobuf/gogoproto/gogo.proto";
option (gogoproto.marshaler_all) = true;
option (gogoproto.sizer_all) = true;
option (gogoproto.unmarshaler_all) = true;
option (gogoproto.goproto_getters_all) = false;
service KV {
// Put puts the given key into the store.
// A put request increases the revision of the store,
// and generates one event in the event history.
rpc Put(PutRequest) returns (PutResponse) {}
}
message PutRequest {
bytes key = 1;
bytes value = 2;
}
message ResponseHeader {
repeated PutRequest l = 3;
}
我得到以下原型结构:
type ResponseHeader struct {
L []*PutRequest `protobuf:"bytes,3,rep,name=l" json:"l,omitempty"`
}
但是我如何遵循protostruct:
type ResponseHeader struct {
L []PutRequest `protobuf:"bytes,3,rep,name=l" json:"l,omitempty"`
}
那就是我想拥有数据局部性(因此有连续数据的切片,而不是散布东西的指针)
1> nmiculinic..:
我需要使用:[(gogoproto.nullable)= false]如下所示:
repeated PutRequest l = 3 [(gogoproto.nullable) = false];
并得到:
L []PutRequest `protobuf:"bytes,3,rep,name=l" json:"l"`
是的,我问了一个问题,然后几个小时后找到了解决方案