nmiculinic
nmiculinic

Reputation: 2474

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)

Upvotes: 4

Views: 1385

Answers (1)

nmiculinic
nmiculinic

Reputation: 2474

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"`

Upvotes: 7

Related Questions