#Proto messages and structs

7 messages · Page 1 of 1 (latest)

vague wraith
#

Hi, currently i got a message like

message Fee {
  int32 year = 1;
  int32 month = 2;
  float price = 3;
}

and a struct like

type Fee struct {
    Year                  int     `json:"year"`
    Month                 int     `json:"month"`
    Price                 float64 `json:"price"`
}

But i am getting a literalcompilerIncompatibleAssign error when trying to send it as response.

I tried creating a .proto file with

message Fee {
  int32 year = 1;
  int32 month = 2;
  double price = 3;
}

and generating the .pb file so this message is converted like

type Fee struct {
    state         protoimpl.MessageState
    sizeCache     protoimpl.SizeCache
    unknownFields protoimpl.UnknownFields

    Year                  int32   `protobuf:"varint,1,opt,name=year,proto3" json:"year,omitempty"`
    Month                 int32   `protobuf:"varint,2,opt,name=month,proto3" json:"month,omitempty"`
    Price                 float64 `protobuf:"fixed64,3,opt,name=price,proto3" json:"price,omitempty"`
}

But i cannot consume this last struct as i am not using state, sizeCache and unknownFields

flint karma
#

You would manually assign the fields you want

vague wraith
#

like adding something to state, sizeCache and unknownFields?

flint karma
#

Like converting the generated protobuf type into the Go type you described above

vague wraith
#

i am not getting it sorry, when converting it, i am getting those 3 extra props which make my go code not compile

#

if i do : Fee{protoimpl., 0, []byte{} ...

#

then i still get the errror cannot use fees (variable of type []amortizations.Fee) as []*protopb.Fee value in struct literal