gogo / protobuf

[Deprecated] Protocol Buffers for Go with Gadgets
Other
5.66k stars 806 forks source link

gogoproto.customtype unable to create slice pointer array #496

Open Nagaraj007 opened 5 years ago

Nagaraj007 commented 5 years ago
  os : osx  
  lang : golang
  proto : proto 3

I am trying the below proto file to create the slice array pointer to BondedValidators, its generating the array slice.

   syntax = 'proto3';
   package grpc;

  import "github.com/gogo/protobuf/gogoproto/gogo.proto";
  import "google/api/annotations.proto";
  import "google/protobuf/struct.proto";

 option (gogoproto.marshaler_all) = false;
 option (gogoproto.unmarshaler_all) = false;
 option (gogoproto.sizer_all) = false;
 option (gogoproto.goproto_registration) = true;
 option (gogoproto.messagename_all) = true;
option (gogoproto.protosizer_all) =false;

 service Accounts {
  rpc GetValidators(Empty) returns (Validator);
 }

  message Validator  {
     uint64 BlockHeight  = 1 ;       
     repeated google.protobuf.ListValue  BondedValidators  = 2   [(gogoproto.customtype) =      "github.com/gallactic/gallactic/core/validator.Validator", (gogoproto.nullable) = false];
     repeated google.protobuf.ListValue  UnbondingValidators  = 3 [(gogoproto.customtype) =   "github.com/gallactic/gallactic/core/validator.Validator", (gogoproto.nullable) = false];
  }

I am using below line to generate .pb.go :

          **protoc -I/usr/local/include -I. -I$GOPATH/src-I$GOPATH/src/github.com/grpcecosystem/grpc-gateway/third_party/googleapis --gofast_out=plugins=grpc:./ ./protobuf/account.proto**

output is generated

      type ValidatorOutput struct {
                BlockHeight          uint64                        `protobuf:"varint,1,opt,name=BlockHeight,proto3"   json:"BlockHeight,omitempty"`
               BondedValidators     []github_com_gallactic_gallactic_core_validator.Validator `protobuf:"bytes,2,rep,name=BondedValidators,customtype=github.com/gallactic/gallactic/core/validator.Validator" json:"BondedValidators"`
              UnbondingValidators  []github_com_gallactic_gallactic_core_validator.Validator  `protobuf:"bytes,3,rep,name=UnbondingValidators,customtype=github.com/gallactic/gallactic/core/validator.Validator" json:"UnbondingValidators"`
            XXX_NoUnkeyedLiteral struct{}                                                   `json:"-"`
            XXX_unrecognized     []byte                                                     `json:"-"`
            XXX_sizecache        int32                                                      `json:"-"`

}

Output need to be generated :

      type ValidatorOutput struct {
        BlockHeight          uint64                                                      `protobuf:"varint,1,opt,name=BlockHeight,proto3" json:"BlockHeight,omitempty"`
         BondedValidators     []*github_com_gallactic_gallactic_core_validator.Validator `protobuf:"bytes,2,rep,name=BondedValidators,customtype=github.com/gallactic/gallactic/core/validator.Validator" json:"BondedValidators"`
         UnbondingValidators  []*github_com_gallactic_gallactic_core_validator.Validator `protobuf:"bytes,3,rep,name=UnbondingValidators,customtype=github.com/gallactic/gallactic/core/validator.Validator" json:"UnbondingValidators"`
          } 
donaldgraham commented 5 years ago

This should work if you remove the (gogoproto.nullable) = false option.

phemmer commented 5 years ago

I'm having this same issue. I am not using (gogoproto.nullable) = false. Also if I explicitly set (gogoproto.nullable) = true, I still get the same result.