-
Notifications
You must be signed in to change notification settings - Fork 811
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
CustomType has no getter? #477
Comments
Hey. |
Sure. Below is an example/test proto that was generated with gogo (not gogofaster). But behaviour is the same. And as you can see both the fields that have the protoc \
--plugin=bin/protoc-gen-gojay \
--proto_path=$(GOPATH)/src \
--proto_path=$(GOPATH)/src/protobuf/proto \
--proto_path=$(GOPATH)/src/github.com/gogo/protobuf/protobuf \
--proto_path=. \
--gogo_out=Mgoogle/protobuf/timestamp.proto=github.com/gogo/protobuf/types:$(GOPATH)/src \
--gojay_out=Mgoogle/protobuf/timestamp.proto=github.com/gogo/protobuf/types:$(GOPATH)/src \
test/examplepb/examplepb.proto This is the proto file. syntax = "proto3";
package examplepb;
import "protoc-gen-gojay/gojay.proto";
import "github.com/gogo/protobuf/gogoproto/gogo.proto";
import "google/protobuf/timestamp.proto";
import "common/big_decimal.proto";
option go_package = "examplepb";
option (gogoproto.equal_all) = true;
option (gogoproto.verbose_equal_all) = true;
message RequestMessage {
enum RequestEnum {
ZERO = 0;
ONE = 1;
TWO = 2;
THREE = 3;
FOUR = 4;
FIVE = 5;
}
string string_value = 1;
RequestEnum enum_value = 2;
}
enum ResponseEnum {
ZERO = 0;
ONE = 1;
TWO = 2;
THREE = 3;
FOUR = 4;
FIVE = 5;
}
message ResponseMessage {
enum NestedResponseEnum {
ZERO = 0;
ONE = 1;
TWO = 2;
THREE = 3;
FOUR = 4;
FIVE = 5;
}
message NestedResponseMessage {
enum DeepNestedResponseEnum {
ZERO = 0;
ONE = 1;
TWO = 2;
THREE = 3;
FOUR = 4;
FIVE = 5;
}
string string_value = 1;
DeepNestedResponseEnum nested_response_enum = 2;
}
double double_value = 1;
float float_value = 2;
int32 int32_value = 3;
int64 int64_value = 4;
uint32 uint32_value = 5;
uint64 uint64_value = 6;
sint32 sint32_value = 7;
sint64 sint64_value = 8;
fixed32 fixed32_value = 9;
fixed64 fixed64_value = 10;
sfixed32 sfixed32_value = 11;
sfixed64 sfixed64_value = 12;
bool bool_value = 13;
string string_value = 14;
bytes bytes_value = 15;
common.BigDecimal big_decimal_value = 16 [(gogoproto.customtype) = "go-decimal/pbdecimal.Decimal"];
google.protobuf.Timestamp date_value = 17 [(gogoproto.stdtime) = true, (gojayproto.stdtime_format) = "date"];
google.protobuf.Timestamp date_time_value = 18 [(gogoproto.stdtime) = true, (gojayproto.stdtime_format) = "date-time"];
ResponseEnum enum_value = 19;
NestedResponseEnum nested_enum_value = 38;
NestedResponseMessage nested_message_value = 20;
NestedResponseMessage.DeepNestedResponseEnum deep_nested_enum_value = 21;
repeated double repeated_double_value = 22;
repeated float repeated_float_value = 23;
repeated int32 repeated_int32_value = 24;
repeated int64 repeated_int64_value = 25;
repeated uint32 repeated_uint32_value = 26;
repeated uint64 repeated_uint64_value = 27;
repeated sint32 repeated_sint32_value = 28;
repeated sint64 repeated_sint64_value = 29;
repeated fixed32 repeated_fixed32_value = 30;
repeated fixed64 repeated_fixed64_value = 31;
repeated sfixed32 repeated_sfixed32_value = 32;
repeated sfixed64 repeated_sfixed64_value = 33;
repeated bool repeated_bool_value = 34;
repeated string repeated_string_value = 35;
repeated bytes repeated_bytes_value = 36;
repeated common.BigDecimal repeated_big_decimal_value = 37 [(gogoproto.customtype) = "go-decimal/pbdecimal.Decimal"];
repeated ResponseEnum repeated_enum_value = 39;
repeated NestedResponseEnum repeated_nested_enum_value = 40;
repeated NestedResponseMessage repeated_nested_message_value = 41;
repeated NestedResponseMessage.DeepNestedResponseEnum repeated_deep_nested_enum_value = 42;
} This is my BigDecimal message. syntax = "proto3";
package common;
import "github.com/gogo/protobuf/gogoproto/gogo.proto";
option go_package = "pbdecimal";
message BigDecimal {
int32 scale = 1;
BigInteger bigInteger = 2;
}
message BigInteger {
bytes value = 1;
} Extract from the generated go code. type ResponseMessage struct {
DoubleValue float64 `protobuf:"fixed64,1,opt,name=double_value,json=doubleValue,proto3" json:"double_value,omitempty"`
FloatValue float32 `protobuf:"fixed32,2,opt,name=float_value,json=floatValue,proto3" json:"float_value,omitempty"`
Int32Value int32 `protobuf:"varint,3,opt,name=int32_value,json=int32Value,proto3" json:"int32_value,omitempty"`
Int64Value int64 `protobuf:"varint,4,opt,name=int64_value,json=int64Value,proto3" json:"int64_value,omitempty"`
Uint32Value uint32 `protobuf:"varint,5,opt,name=uint32_value,json=uint32Value,proto3" json:"uint32_value,omitempty"`
Uint64Value uint64 `protobuf:"varint,6,opt,name=uint64_value,json=uint64Value,proto3" json:"uint64_value,omitempty"`
Sint32Value int32 `protobuf:"zigzag32,7,opt,name=sint32_value,json=sint32Value,proto3" json:"sint32_value,omitempty"`
Sint64Value int64 `protobuf:"zigzag64,8,opt,name=sint64_value,json=sint64Value,proto3" json:"sint64_value,omitempty"`
Fixed32Value uint32 `protobuf:"fixed32,9,opt,name=fixed32_value,json=fixed32Value,proto3" json:"fixed32_value,omitempty"`
Fixed64Value uint64 `protobuf:"fixed64,10,opt,name=fixed64_value,json=fixed64Value,proto3" json:"fixed64_value,omitempty"`
Sfixed32Value int32 `protobuf:"fixed32,11,opt,name=sfixed32_value,json=sfixed32Value,proto3" json:"sfixed32_value,omitempty"`
Sfixed64Value int64 `protobuf:"fixed64,12,opt,name=sfixed64_value,json=sfixed64Value,proto3" json:"sfixed64_value,omitempty"`
BoolValue bool `protobuf:"varint,13,opt,name=bool_value,json=boolValue,proto3" json:"bool_value,omitempty"`
StringValue string `protobuf:"bytes,14,opt,name=string_value,json=stringValue,proto3" json:"string_value,omitempty"`
BytesValue []byte `protobuf:"bytes,15,opt,name=bytes_value,json=bytesValue,proto3" json:"bytes_value,omitempty"`
BigDecimalValue *go_decimal_pbdecimal.Decimal `protobuf:"bytes,16,opt,name=big_decimal_value,json=bigDecimalValue,customtype=go-decimal/pbdecimal.Decimal" json:"big_decimal_value,omitempty"`
DateValue *time.Time `protobuf:"bytes,17,opt,name=date_value,json=dateValue,stdtime" json:"date_value,omitempty"`
DateTimeValue *time.Time `protobuf:"bytes,18,opt,name=date_time_value,json=dateTimeValue,stdtime" json:"date_time_value,omitempty"`
EnumValue ResponseEnum `protobuf:"varint,19,opt,name=enum_value,json=enumValue,proto3,enum=examplepb.ResponseEnum" json:"enum_value,omitempty"`
NestedEnumValue ResponseMessage_NestedResponseEnum `protobuf:"varint,38,opt,name=nested_enum_value,json=nestedEnumValue,proto3,enum=examplepb.ResponseMessage_NestedResponseEnum" json:"nested_enum_value,omitempty"`
NestedMessageValue *ResponseMessage_NestedResponseMessage `protobuf:"bytes,20,opt,name=nested_message_value,json=nestedMessageValue" json:"nested_message_value,omitempty"`
DeepNestedEnumValue ResponseMessage_NestedResponseMessage_DeepNestedResponseEnum `protobuf:"varint,21,opt,name=deep_nested_enum_value,json=deepNestedEnumValue,proto3,enum=examplepb.ResponseMessage_NestedResponseMessage_DeepNestedResponseEnum" json:"deep_nested_enum_value,omitempty"`
RepeatedDoubleValue []float64 `protobuf:"fixed64,22,rep,packed,name=repeated_double_value,json=repeatedDoubleValue" json:"repeated_double_value,omitempty"`
RepeatedFloatValue []float32 `protobuf:"fixed32,23,rep,packed,name=repeated_float_value,json=repeatedFloatValue" json:"repeated_float_value,omitempty"`
RepeatedInt32Value []int32 `protobuf:"varint,24,rep,packed,name=repeated_int32_value,json=repeatedInt32Value" json:"repeated_int32_value,omitempty"`
RepeatedInt64Value []int64 `protobuf:"varint,25,rep,packed,name=repeated_int64_value,json=repeatedInt64Value" json:"repeated_int64_value,omitempty"`
RepeatedUint32Value []uint32 `protobuf:"varint,26,rep,packed,name=repeated_uint32_value,json=repeatedUint32Value" json:"repeated_uint32_value,omitempty"`
RepeatedUint64Value []uint64 `protobuf:"varint,27,rep,packed,name=repeated_uint64_value,json=repeatedUint64Value" json:"repeated_uint64_value,omitempty"`
RepeatedSint32Value []int32 `protobuf:"zigzag32,28,rep,packed,name=repeated_sint32_value,json=repeatedSint32Value" json:"repeated_sint32_value,omitempty"`
RepeatedSint64Value []int64 `protobuf:"zigzag64,29,rep,packed,name=repeated_sint64_value,json=repeatedSint64Value" json:"repeated_sint64_value,omitempty"`
RepeatedFixed32Value []uint32 `protobuf:"fixed32,30,rep,packed,name=repeated_fixed32_value,json=repeatedFixed32Value" json:"repeated_fixed32_value,omitempty"`
RepeatedFixed64Value []uint64 `protobuf:"fixed64,31,rep,packed,name=repeated_fixed64_value,json=repeatedFixed64Value" json:"repeated_fixed64_value,omitempty"`
RepeatedSfixed32Value []int32 `protobuf:"fixed32,32,rep,packed,name=repeated_sfixed32_value,json=repeatedSfixed32Value" json:"repeated_sfixed32_value,omitempty"`
RepeatedSfixed64Value []int64 `protobuf:"fixed64,33,rep,packed,name=repeated_sfixed64_value,json=repeatedSfixed64Value" json:"repeated_sfixed64_value,omitempty"`
RepeatedBoolValue []bool `protobuf:"varint,34,rep,packed,name=repeated_bool_value,json=repeatedBoolValue" json:"repeated_bool_value,omitempty"`
RepeatedStringValue []string `protobuf:"bytes,35,rep,name=repeated_string_value,json=repeatedStringValue" json:"repeated_string_value,omitempty"`
RepeatedBytesValue [][]byte `protobuf:"bytes,36,rep,name=repeated_bytes_value,json=repeatedBytesValue" json:"repeated_bytes_value,omitempty"`
RepeatedBigDecimalValue []go_decimal_pbdecimal.Decimal `protobuf:"bytes,37,rep,name=repeated_big_decimal_value,json=repeatedBigDecimalValue,customtype=go-decimal/pbdecimal.Decimal" json:"repeated_big_decimal_value,omitempty"`
RepeatedEnumValue []ResponseEnum `protobuf:"varint,39,rep,packed,name=repeated_enum_value,json=repeatedEnumValue,enum=examplepb.ResponseEnum" json:"repeated_enum_value,omitempty"`
RepeatedNestedEnumValue []ResponseMessage_NestedResponseEnum `protobuf:"varint,40,rep,packed,name=repeated_nested_enum_value,json=repeatedNestedEnumValue,enum=examplepb.ResponseMessage_NestedResponseEnum" json:"repeated_nested_enum_value,omitempty"`
RepeatedNestedMessageValue []*ResponseMessage_NestedResponseMessage `protobuf:"bytes,41,rep,name=repeated_nested_message_value,json=repeatedNestedMessageValue" json:"repeated_nested_message_value,omitempty"`
RepeatedDeepNestedEnumValue []ResponseMessage_NestedResponseMessage_DeepNestedResponseEnum `protobuf:"varint,42,rep,packed,name=repeated_deep_nested_enum_value,json=repeatedDeepNestedEnumValue,enum=examplepb.ResponseMessage_NestedResponseMessage_DeepNestedResponseEnum" json:"repeated_deep_nested_enum_value,omitempty"`
XXX_NoUnkeyedLiteral struct{} `json:"-"`
XXX_unrecognized []byte `json:"-"`
XXX_sizecache int32 `json:"-"`
}
func (m *ResponseMessage) Reset() { *m = ResponseMessage{} }
func (m *ResponseMessage) String() string { return proto.CompactTextString(m) }
func (*ResponseMessage) ProtoMessage() {}
func (*ResponseMessage) Descriptor() ([]byte, []int) {
return fileDescriptor_examplepb_fade1495dedaf83f, []int{1}
}
func (m *ResponseMessage) XXX_Unmarshal(b []byte) error {
return xxx_messageInfo_ResponseMessage.Unmarshal(m, b)
}
func (m *ResponseMessage) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
return xxx_messageInfo_ResponseMessage.Marshal(b, m, deterministic)
}
func (dst *ResponseMessage) XXX_Merge(src proto.Message) {
xxx_messageInfo_ResponseMessage.Merge(dst, src)
}
func (m *ResponseMessage) XXX_Size() int {
return xxx_messageInfo_ResponseMessage.Size(m)
}
func (m *ResponseMessage) XXX_DiscardUnknown() {
xxx_messageInfo_ResponseMessage.DiscardUnknown(m)
}
var xxx_messageInfo_ResponseMessage proto.InternalMessageInfo
func (m *ResponseMessage) GetDoubleValue() float64 {
if m != nil {
return m.DoubleValue
}
return 0
}
func (m *ResponseMessage) GetFloatValue() float32 {
if m != nil {
return m.FloatValue
}
return 0
}
func (m *ResponseMessage) GetInt32Value() int32 {
if m != nil {
return m.Int32Value
}
return 0
}
func (m *ResponseMessage) GetInt64Value() int64 {
if m != nil {
return m.Int64Value
}
return 0
}
func (m *ResponseMessage) GetUint32Value() uint32 {
if m != nil {
return m.Uint32Value
}
return 0
}
func (m *ResponseMessage) GetUint64Value() uint64 {
if m != nil {
return m.Uint64Value
}
return 0
}
func (m *ResponseMessage) GetSint32Value() int32 {
if m != nil {
return m.Sint32Value
}
return 0
}
func (m *ResponseMessage) GetSint64Value() int64 {
if m != nil {
return m.Sint64Value
}
return 0
}
func (m *ResponseMessage) GetFixed32Value() uint32 {
if m != nil {
return m.Fixed32Value
}
return 0
}
func (m *ResponseMessage) GetFixed64Value() uint64 {
if m != nil {
return m.Fixed64Value
}
return 0
}
func (m *ResponseMessage) GetSfixed32Value() int32 {
if m != nil {
return m.Sfixed32Value
}
return 0
}
func (m *ResponseMessage) GetSfixed64Value() int64 {
if m != nil {
return m.Sfixed64Value
}
return 0
}
func (m *ResponseMessage) GetBoolValue() bool {
if m != nil {
return m.BoolValue
}
return false
}
func (m *ResponseMessage) GetStringValue() string {
if m != nil {
return m.StringValue
}
return ""
}
func (m *ResponseMessage) GetBytesValue() []byte {
if m != nil {
return m.BytesValue
}
return nil
}
func (m *ResponseMessage) GetDateValue() *time.Time {
if m != nil {
return m.DateValue
}
return nil
}
func (m *ResponseMessage) GetDateTimeValue() *time.Time {
if m != nil {
return m.DateTimeValue
}
return nil
}
func (m *ResponseMessage) GetEnumValue() ResponseEnum {
if m != nil {
return m.EnumValue
}
return ResponseEnum_ZERO
}
func (m *ResponseMessage) GetNestedEnumValue() ResponseMessage_NestedResponseEnum {
if m != nil {
return m.NestedEnumValue
}
return ResponseMessage_ZERO
}
func (m *ResponseMessage) GetNestedMessageValue() *ResponseMessage_NestedResponseMessage {
if m != nil {
return m.NestedMessageValue
}
return nil
}
func (m *ResponseMessage) GetDeepNestedEnumValue() ResponseMessage_NestedResponseMessage_DeepNestedResponseEnum {
if m != nil {
return m.DeepNestedEnumValue
}
return ResponseMessage_NestedResponseMessage_ZERO
}
func (m *ResponseMessage) GetRepeatedDoubleValue() []float64 {
if m != nil {
return m.RepeatedDoubleValue
}
return nil
}
func (m *ResponseMessage) GetRepeatedFloatValue() []float32 {
if m != nil {
return m.RepeatedFloatValue
}
return nil
}
func (m *ResponseMessage) GetRepeatedInt32Value() []int32 {
if m != nil {
return m.RepeatedInt32Value
}
return nil
}
func (m *ResponseMessage) GetRepeatedInt64Value() []int64 {
if m != nil {
return m.RepeatedInt64Value
}
return nil
}
func (m *ResponseMessage) GetRepeatedUint32Value() []uint32 {
if m != nil {
return m.RepeatedUint32Value
}
return nil
}
func (m *ResponseMessage) GetRepeatedUint64Value() []uint64 {
if m != nil {
return m.RepeatedUint64Value
}
return nil
}
func (m *ResponseMessage) GetRepeatedSint32Value() []int32 {
if m != nil {
return m.RepeatedSint32Value
}
return nil
}
func (m *ResponseMessage) GetRepeatedSint64Value() []int64 {
if m != nil {
return m.RepeatedSint64Value
}
return nil
}
func (m *ResponseMessage) GetRepeatedFixed32Value() []uint32 {
if m != nil {
return m.RepeatedFixed32Value
}
return nil
}
func (m *ResponseMessage) GetRepeatedFixed64Value() []uint64 {
if m != nil {
return m.RepeatedFixed64Value
}
return nil
}
func (m *ResponseMessage) GetRepeatedSfixed32Value() []int32 {
if m != nil {
return m.RepeatedSfixed32Value
}
return nil
}
func (m *ResponseMessage) GetRepeatedSfixed64Value() []int64 {
if m != nil {
return m.RepeatedSfixed64Value
}
return nil
}
func (m *ResponseMessage) GetRepeatedBoolValue() []bool {
if m != nil {
return m.RepeatedBoolValue
}
return nil
}
func (m *ResponseMessage) GetRepeatedStringValue() []string {
if m != nil {
return m.RepeatedStringValue
}
return nil
}
func (m *ResponseMessage) GetRepeatedBytesValue() [][]byte {
if m != nil {
return m.RepeatedBytesValue
}
return nil
}
func (m *ResponseMessage) GetRepeatedEnumValue() []ResponseEnum {
if m != nil {
return m.RepeatedEnumValue
}
return nil
}
func (m *ResponseMessage) GetRepeatedNestedEnumValue() []ResponseMessage_NestedResponseEnum {
if m != nil {
return m.RepeatedNestedEnumValue
}
return nil
}
func (m *ResponseMessage) GetRepeatedNestedMessageValue() []*ResponseMessage_NestedResponseMessage {
if m != nil {
return m.RepeatedNestedMessageValue
}
return nil
}
func (m *ResponseMessage) GetRepeatedDeepNestedEnumValue() []ResponseMessage_NestedResponseMessage_DeepNestedResponseEnum {
if m != nil {
return m.RepeatedDeepNestedEnumValue
}
return nil
} |
Another observation related to |
Thanks for your example. I had a look and you are right, we are currently not generating 'getters' for customtype fields. I think one problem with In the mean time you could add getter methods in the same package as your generated code. message foo {
bytes customtype = 1 [(gogoproto.customtype) = "T"];
} func (m *Foo) GetTValue() *T {
if m != nil {
return m.Customtype
}
return &T{}
} I will also add this to the list of Warning and Issues on the custom type documentation:
Thanks.
Yes, please do so. |
Sure, that is my current workaround. I.e. having an additional plugin that generates getters for those |
Great. The logic of the getter generation resides here: |
I thought about it a bit more keeping: |
Hi, I haven't had any bandwidth to dig into this. But you are quite right. It seems like it would be hard. With regards to func (m *ResponseMessage) GetDateValue() *time.Time {
if m != nil {
return m.DateValue
}
return nil
} |
Hello, I have faced with it too. Is it still hard to implement? Maybe something changed? |
Are customtype Fields not supposed to generate a getter? The field is of message type. All other Fields generate with a getter. Even timestamp Fields having the stdtime extension. I’m using gogofaster.
The text was updated successfully, but these errors were encountered: