Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get slice of concrete type (not pointers) in go protobuff

For protofile:

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;
}

I get the following proto struct:

type ResponseHeader struct {
    L     []*PutRequest `protobuf:"bytes,3,rep,name=l" json:"l,omitempty"`
}

But how do I get following protostruct:

type ResponseHeader struct {
    L     []PutRequest `protobuf:"bytes,3,rep,name=l" json:"l,omitempty"`
}

That is I want having data locality (and thus slices of contig data, not pointers to spread out stuff)

like image 280
nmiculinic Avatar asked Mar 08 '23 00:03

nmiculinic


1 Answers

I needed to use: [(gogoproto.nullable) = false] as in:

repeated PutRequest l = 3 [(gogoproto.nullable) = false];

And got:

    L     []PutRequest `protobuf:"bytes,3,rep,name=l" json:"l"`
like image 63
nmiculinic Avatar answered Apr 27 '23 18:04

nmiculinic