cmd/protoc-gen-go: generate getters

Refactor fieldGoType to return the non-pointer type for scalar types
(i.e., "int", not "*int"), and a bool indicating whether the struct
field is a pointer to that type.

Change-Id: Ic80220e92f0b190e41ead847440d57af5c6cc919
Reviewed-on: https://go-review.googlesource.com/135336
Reviewed-by: Joe Tsai <thebrokentoaster@gmail.com>
This commit is contained in:
Damien Neil 2018-09-13 10:59:17 -07:00
parent fa02f4eaa6
commit 77f82fe6bc
6 changed files with 899 additions and 31 deletions

View File

@ -259,7 +259,11 @@ func genMessage(gen *protogen.Plugin, g *protogen.GeneratedFile, f *File, messag
continue
}
genComment(g, f, field.Path)
g.P(field.GoIdent, " ", fieldGoType(g, field), fmt.Sprintf(" `protobuf:%q json:%q`", fieldProtobufTag(field), fieldJSONTag(field)))
goType, pointer := fieldGoType(g, field)
if pointer {
goType = "*" + goType
}
g.P(field.GoIdent, " ", goType, fmt.Sprintf(" `protobuf:%q json:%q`", fieldProtobufTag(field), fieldJSONTag(field)))
}
g.P("XXX_NoUnkeyedLiteral struct{} `json:\"-\"`")
// TODO XXX_InternalExtensions
@ -368,65 +372,78 @@ func genMessage(gen *protogen.Plugin, g *protogen.GeneratedFile, f *File, messag
g.P("const ", defVarName, " ", goType, " = ", f)
}
default:
goType := fieldGoType(g, field)
goType = strings.TrimPrefix(goType, "*")
goType, _ := fieldGoType(g, field)
g.P("const ", defVarName, " ", goType, " = ", def.Interface())
}
}
g.P()
// TODO: getters
// Getters.
for _, field := range message.Fields {
goType, pointer := fieldGoType(g, field)
defaultValue := fieldDefaultValue(g, message, field)
g.P("func (m *", message.GoIdent, ") Get", field.GoIdent, "() ", goType, " {")
if field.Desc.Syntax() == protoreflect.Proto3 || defaultValue == "nil" {
g.P("if m != nil {")
} else {
g.P("if m != nil && m.", field.GoIdent, " != nil {")
}
star := ""
if pointer {
star = "*"
}
g.P("return ", star, " m.", field.GoIdent)
g.P("}")
g.P("return ", defaultValue)
g.P("}")
g.P()
}
for _, nested := range message.Messages {
genMessage(gen, g, f, nested)
}
}
func fieldGoType(g *protogen.GeneratedFile, field *protogen.Field) string {
// fieldGoType returns the Go type used for a field.
//
// If it returns pointer=true, the struct field is a pointer to the type.
func fieldGoType(g *protogen.GeneratedFile, field *protogen.Field) (goType string, pointer bool) {
// TODO: map types
var typ string
pointer = true
switch field.Desc.Kind() {
case protoreflect.BoolKind:
typ = "bool"
goType = "bool"
case protoreflect.EnumKind:
typ = g.QualifiedGoIdent(field.EnumType.GoIdent)
goType = g.QualifiedGoIdent(field.EnumType.GoIdent)
case protoreflect.Int32Kind, protoreflect.Sint32Kind, protoreflect.Sfixed32Kind:
typ = "int32"
goType = "int32"
case protoreflect.Uint32Kind, protoreflect.Fixed32Kind:
typ = "uint32"
goType = "uint32"
case protoreflect.Int64Kind, protoreflect.Sint64Kind, protoreflect.Sfixed64Kind:
typ = "int64"
goType = "int64"
case protoreflect.Uint64Kind, protoreflect.Fixed64Kind:
typ = "uint64"
goType = "uint64"
case protoreflect.FloatKind:
typ = "float32"
goType = "float32"
case protoreflect.DoubleKind:
typ = "float64"
goType = "float64"
case protoreflect.StringKind:
typ = "string"
goType = "string"
case protoreflect.BytesKind:
typ = "[]byte"
goType = "[]byte"
pointer = false
case protoreflect.MessageKind, protoreflect.GroupKind:
typ = "*" + g.QualifiedGoIdent(field.MessageType.GoIdent)
goType = "*" + g.QualifiedGoIdent(field.MessageType.GoIdent)
pointer = false
}
if field.Desc.Cardinality() == protoreflect.Repeated {
return "[]" + typ
goType = "[]" + goType
pointer = false
}
if field.Desc.Syntax() == protoreflect.Proto3 {
return typ
pointer = false
}
if field.Desc.OneofType() != nil {
return typ
}
nonPointerKinds := map[protoreflect.Kind]bool{
protoreflect.GroupKind: true,
protoreflect.MessageKind: true,
protoreflect.BytesKind: true,
}
if !nonPointerKinds[field.Desc.Kind()] {
return "*" + typ
}
return typ
return goType, pointer
}
func fieldProtobufTag(field *protogen.Field) string {
@ -503,6 +520,31 @@ func fieldProtobufTag(field *protogen.Field) string {
return strings.Join(tag, ",")
}
func fieldDefaultValue(g *protogen.GeneratedFile, message *protogen.Message, field *protogen.Field) string {
if field.Desc.Cardinality() == protoreflect.Repeated {
return "nil"
}
if field.Desc.HasDefault() {
defVarName := "Default_" + message.GoIdent.GoName + "_" + field.GoIdent.GoName
if field.Desc.Kind() == protoreflect.BytesKind {
return "append([]byte(nil), " + defVarName + "...)"
}
return defVarName
}
switch field.Desc.Kind() {
case protoreflect.BoolKind:
return "false"
case protoreflect.StringKind:
return `""`
case protoreflect.MessageKind, protoreflect.GroupKind, protoreflect.BytesKind:
return "nil"
case protoreflect.EnumKind:
return g.QualifiedGoIdent(field.EnumType.Values[0].GoIdent)
default:
return "0"
}
}
var wireTypes = map[protoreflect.Kind]string{
protoreflect.BoolKind: "varint",
protoreflect.EnumKind: "varint",

View File

@ -64,6 +64,125 @@ func (m *Message) XXX_DiscardUnknown() {
var xxx_messageInfo_Message proto.InternalMessageInfo
func (m *Message) GetFieldOne() string {
if m != nil && m.FieldOne != nil {
return *m.FieldOne
}
return ""
}
func (m *Message) GetFieldTwo() string {
if m != nil && m.FieldTwo != nil {
return *m.FieldTwo
}
return ""
}
func (m *Message) GetFieldThree() string {
if m != nil && m.FieldThree != nil {
return *m.FieldThree
}
return ""
}
func (m *Message) GetField_Four() string {
if m != nil && m.Field_Four != nil {
return *m.Field_Four
}
return ""
}
func (m *Message) GetDescriptor_() string {
if m != nil && m.Descriptor_ != nil {
return *m.Descriptor_
}
return ""
}
func (m *Message) GetMarshal_() string {
if m != nil && m.Marshal_ != nil {
return *m.Marshal_
}
return ""
}
func (m *Message) GetUnmarshal_() string {
if m != nil && m.Unmarshal_ != nil {
return *m.Unmarshal_
}
return ""
}
func (m *Message) GetProtoMessage_() string {
if m != nil && m.ProtoMessage_ != nil {
return *m.ProtoMessage_
}
return ""
}
func (m *Message) GetCamelCase() string {
if m != nil && m.CamelCase != nil {
return *m.CamelCase
}
return ""
}
func (m *Message) GetCamelCase_() string {
if m != nil && m.CamelCase_ != nil {
return *m.CamelCase_
}
return ""
}
func (m *Message) GetCamelCase__() string {
if m != nil && m.CamelCase__ != nil {
return *m.CamelCase__
}
return ""
}
func (m *Message) GetCamelCase___() string {
if m != nil && m.CamelCase___ != nil {
return *m.CamelCase___
}
return ""
}
func (m *Message) GetGetName() string {
if m != nil && m.GetName != nil {
return *m.GetName
}
return ""
}
func (m *Message) GetName_() string {
if m != nil && m.Name_ != nil {
return *m.Name_
}
return ""
}
func (m *Message) GetOneofConflictA() string {
if m != nil && m.OneofConflictA != nil {
return *m.OneofConflictA
}
return ""
}
func (m *Message) GetOneofNoConflict() string {
if m != nil && m.OneofNoConflict != nil {
return *m.OneofNoConflict
}
return ""
}
func (m *Message) GetOneofConflictB() string {
if m != nil && m.OneofConflictB != nil {
return *m.OneofConflictB
}
return ""
}
func init() { proto.RegisterFile("fieldnames/fieldnames.proto", fileDescriptor_6bbe3f70febb9403) }
var fileDescriptor_6bbe3f70febb9403 = []byte{

View File

@ -184,6 +184,538 @@ var Default_FieldTestMessage_DefaultDoubleNeginf float64 = math.Inf(-1)
var Default_FieldTestMessage_DefaultDoublePosinf float64 = math.Inf(1)
var Default_FieldTestMessage_DefaultDoubleNan float64 = math.NaN()
func (m *FieldTestMessage) GetOptionalBool() bool {
if m != nil && m.OptionalBool != nil {
return *m.OptionalBool
}
return false
}
func (m *FieldTestMessage) GetOptionalEnum() FieldTestMessage_Enum {
if m != nil && m.OptionalEnum != nil {
return *m.OptionalEnum
}
return FieldTestMessage_ZERO
}
func (m *FieldTestMessage) GetOptionalInt32() int32 {
if m != nil && m.OptionalInt32 != nil {
return *m.OptionalInt32
}
return 0
}
func (m *FieldTestMessage) GetOptionalSint32() int32 {
if m != nil && m.OptionalSint32 != nil {
return *m.OptionalSint32
}
return 0
}
func (m *FieldTestMessage) GetOptionalUint32() uint32 {
if m != nil && m.OptionalUint32 != nil {
return *m.OptionalUint32
}
return 0
}
func (m *FieldTestMessage) GetOptionalInt64() int64 {
if m != nil && m.OptionalInt64 != nil {
return *m.OptionalInt64
}
return 0
}
func (m *FieldTestMessage) GetOptionalSint64() int64 {
if m != nil && m.OptionalSint64 != nil {
return *m.OptionalSint64
}
return 0
}
func (m *FieldTestMessage) GetOptionalUint64() uint64 {
if m != nil && m.OptionalUint64 != nil {
return *m.OptionalUint64
}
return 0
}
func (m *FieldTestMessage) GetOptionalSfixed32() int32 {
if m != nil && m.OptionalSfixed32 != nil {
return *m.OptionalSfixed32
}
return 0
}
func (m *FieldTestMessage) GetOptionalFixed32() uint32 {
if m != nil && m.OptionalFixed32 != nil {
return *m.OptionalFixed32
}
return 0
}
func (m *FieldTestMessage) GetOptionalFloat() float32 {
if m != nil && m.OptionalFloat != nil {
return *m.OptionalFloat
}
return 0
}
func (m *FieldTestMessage) GetOptionalSfixed64() int64 {
if m != nil && m.OptionalSfixed64 != nil {
return *m.OptionalSfixed64
}
return 0
}
func (m *FieldTestMessage) GetOptionalFixed64() uint64 {
if m != nil && m.OptionalFixed64 != nil {
return *m.OptionalFixed64
}
return 0
}
func (m *FieldTestMessage) GetOptionalDouble() float64 {
if m != nil && m.OptionalDouble != nil {
return *m.OptionalDouble
}
return 0
}
func (m *FieldTestMessage) GetOptionalString() string {
if m != nil && m.OptionalString != nil {
return *m.OptionalString
}
return ""
}
func (m *FieldTestMessage) GetOptionalBytes() []byte {
if m != nil {
return m.OptionalBytes
}
return nil
}
func (m *FieldTestMessage) GetOptional_Message() *FieldTestMessage_Message {
if m != nil {
return m.Optional_Message
}
return nil
}
func (m *FieldTestMessage) GetOptionalgroup() *FieldTestMessage_OptionalGroup {
if m != nil {
return m.Optionalgroup
}
return nil
}
func (m *FieldTestMessage) GetRequiredBool() bool {
if m != nil && m.RequiredBool != nil {
return *m.RequiredBool
}
return false
}
func (m *FieldTestMessage) GetRequiredEnum() FieldTestMessage_Enum {
if m != nil && m.RequiredEnum != nil {
return *m.RequiredEnum
}
return FieldTestMessage_ZERO
}
func (m *FieldTestMessage) GetRequiredInt32() int32 {
if m != nil && m.RequiredInt32 != nil {
return *m.RequiredInt32
}
return 0
}
func (m *FieldTestMessage) GetRequiredSint32() int32 {
if m != nil && m.RequiredSint32 != nil {
return *m.RequiredSint32
}
return 0
}
func (m *FieldTestMessage) GetRequiredUint32() uint32 {
if m != nil && m.RequiredUint32 != nil {
return *m.RequiredUint32
}
return 0
}
func (m *FieldTestMessage) GetRequiredInt64() int64 {
if m != nil && m.RequiredInt64 != nil {
return *m.RequiredInt64
}
return 0
}
func (m *FieldTestMessage) GetRequiredSint64() int64 {
if m != nil && m.RequiredSint64 != nil {
return *m.RequiredSint64
}
return 0
}
func (m *FieldTestMessage) GetRequiredUint64() uint64 {
if m != nil && m.RequiredUint64 != nil {
return *m.RequiredUint64
}
return 0
}
func (m *FieldTestMessage) GetRequiredSfixed32() int32 {
if m != nil && m.RequiredSfixed32 != nil {
return *m.RequiredSfixed32
}
return 0
}
func (m *FieldTestMessage) GetRequiredFixed32() uint32 {
if m != nil && m.RequiredFixed32 != nil {
return *m.RequiredFixed32
}
return 0
}
func (m *FieldTestMessage) GetRequiredFloat() float32 {
if m != nil && m.RequiredFloat != nil {
return *m.RequiredFloat
}
return 0
}
func (m *FieldTestMessage) GetRequiredSfixed64() int64 {
if m != nil && m.RequiredSfixed64 != nil {
return *m.RequiredSfixed64
}
return 0
}
func (m *FieldTestMessage) GetRequiredFixed64() uint64 {
if m != nil && m.RequiredFixed64 != nil {
return *m.RequiredFixed64
}
return 0
}
func (m *FieldTestMessage) GetRequiredDouble() float64 {
if m != nil && m.RequiredDouble != nil {
return *m.RequiredDouble
}
return 0
}
func (m *FieldTestMessage) GetRequiredString() string {
if m != nil && m.RequiredString != nil {
return *m.RequiredString
}
return ""
}
func (m *FieldTestMessage) GetRequiredBytes() []byte {
if m != nil {
return m.RequiredBytes
}
return nil
}
func (m *FieldTestMessage) GetRequired_Message() *FieldTestMessage_Message {
if m != nil {
return m.Required_Message
}
return nil
}
func (m *FieldTestMessage) GetRequiredgroup() *FieldTestMessage_RequiredGroup {
if m != nil {
return m.Requiredgroup
}
return nil
}
func (m *FieldTestMessage) GetRepeatedBool() []bool {
if m != nil {
return m.RepeatedBool
}
return nil
}
func (m *FieldTestMessage) GetRepeatedEnum() []FieldTestMessage_Enum {
if m != nil {
return m.RepeatedEnum
}
return nil
}
func (m *FieldTestMessage) GetRepeatedInt32() []int32 {
if m != nil {
return m.RepeatedInt32
}
return nil
}
func (m *FieldTestMessage) GetRepeatedSint32() []int32 {
if m != nil {
return m.RepeatedSint32
}
return nil
}
func (m *FieldTestMessage) GetRepeatedUint32() []uint32 {
if m != nil {
return m.RepeatedUint32
}
return nil
}
func (m *FieldTestMessage) GetRepeatedInt64() []int64 {
if m != nil {
return m.RepeatedInt64
}
return nil
}
func (m *FieldTestMessage) GetRepeatedSint64() []int64 {
if m != nil {
return m.RepeatedSint64
}
return nil
}
func (m *FieldTestMessage) GetRepeatedUint64() []uint64 {
if m != nil {
return m.RepeatedUint64
}
return nil
}
func (m *FieldTestMessage) GetRepeatedSfixed32() []int32 {
if m != nil {
return m.RepeatedSfixed32
}
return nil
}
func (m *FieldTestMessage) GetRepeatedFixed32() []uint32 {
if m != nil {
return m.RepeatedFixed32
}
return nil
}
func (m *FieldTestMessage) GetRepeatedFloat() []float32 {
if m != nil {
return m.RepeatedFloat
}
return nil
}
func (m *FieldTestMessage) GetRepeatedSfixed64() []int64 {
if m != nil {
return m.RepeatedSfixed64
}
return nil
}
func (m *FieldTestMessage) GetRepeatedFixed64() []uint64 {
if m != nil {
return m.RepeatedFixed64
}
return nil
}
func (m *FieldTestMessage) GetRepeatedDouble() []float64 {
if m != nil {
return m.RepeatedDouble
}
return nil
}
func (m *FieldTestMessage) GetRepeatedString() []string {
if m != nil {
return m.RepeatedString
}
return nil
}
func (m *FieldTestMessage) GetRepeatedBytes() [][]byte {
if m != nil {
return m.RepeatedBytes
}
return nil
}
func (m *FieldTestMessage) GetRepeated_Message() []*FieldTestMessage_Message {
if m != nil {
return m.Repeated_Message
}
return nil
}
func (m *FieldTestMessage) GetRepeatedgroup() []*FieldTestMessage_RepeatedGroup {
if m != nil {
return m.Repeatedgroup
}
return nil
}
func (m *FieldTestMessage) GetDefaultBool() bool {
if m != nil && m.DefaultBool != nil {
return *m.DefaultBool
}
return Default_FieldTestMessage_DefaultBool
}
func (m *FieldTestMessage) GetDefaultEnum() FieldTestMessage_Enum {
if m != nil && m.DefaultEnum != nil {
return *m.DefaultEnum
}
return Default_FieldTestMessage_DefaultEnum
}
func (m *FieldTestMessage) GetDefaultInt32() int32 {
if m != nil && m.DefaultInt32 != nil {
return *m.DefaultInt32
}
return Default_FieldTestMessage_DefaultInt32
}
func (m *FieldTestMessage) GetDefaultSint32() int32 {
if m != nil && m.DefaultSint32 != nil {
return *m.DefaultSint32
}
return Default_FieldTestMessage_DefaultSint32
}
func (m *FieldTestMessage) GetDefaultUint32() uint32 {
if m != nil && m.DefaultUint32 != nil {
return *m.DefaultUint32
}
return Default_FieldTestMessage_DefaultUint32
}
func (m *FieldTestMessage) GetDefaultInt64() int64 {
if m != nil && m.DefaultInt64 != nil {
return *m.DefaultInt64
}
return Default_FieldTestMessage_DefaultInt64
}
func (m *FieldTestMessage) GetDefaultSint64() int64 {
if m != nil && m.DefaultSint64 != nil {
return *m.DefaultSint64
}
return Default_FieldTestMessage_DefaultSint64
}
func (m *FieldTestMessage) GetDefaultUint64() uint64 {
if m != nil && m.DefaultUint64 != nil {
return *m.DefaultUint64
}
return Default_FieldTestMessage_DefaultUint64
}
func (m *FieldTestMessage) GetDefaultSfixed32() int32 {
if m != nil && m.DefaultSfixed32 != nil {
return *m.DefaultSfixed32
}
return Default_FieldTestMessage_DefaultSfixed32
}
func (m *FieldTestMessage) GetDefaultFixed32() uint32 {
if m != nil && m.DefaultFixed32 != nil {
return *m.DefaultFixed32
}
return Default_FieldTestMessage_DefaultFixed32
}
func (m *FieldTestMessage) GetDefaultFloat() float32 {
if m != nil && m.DefaultFloat != nil {
return *m.DefaultFloat
}
return Default_FieldTestMessage_DefaultFloat
}
func (m *FieldTestMessage) GetDefaultSfixed64() int64 {
if m != nil && m.DefaultSfixed64 != nil {
return *m.DefaultSfixed64
}
return Default_FieldTestMessage_DefaultSfixed64
}
func (m *FieldTestMessage) GetDefaultFixed64() uint64 {
if m != nil && m.DefaultFixed64 != nil {
return *m.DefaultFixed64
}
return Default_FieldTestMessage_DefaultFixed64
}
func (m *FieldTestMessage) GetDefaultDouble() float64 {
if m != nil && m.DefaultDouble != nil {
return *m.DefaultDouble
}
return Default_FieldTestMessage_DefaultDouble
}
func (m *FieldTestMessage) GetDefaultString() string {
if m != nil && m.DefaultString != nil {
return *m.DefaultString
}
return Default_FieldTestMessage_DefaultString
}
func (m *FieldTestMessage) GetDefaultBytes() []byte {
if m != nil && m.DefaultBytes != nil {
return m.DefaultBytes
}
return append([]byte(nil), Default_FieldTestMessage_DefaultBytes...)
}
func (m *FieldTestMessage) GetDefaultFloatNeginf() float32 {
if m != nil && m.DefaultFloatNeginf != nil {
return *m.DefaultFloatNeginf
}
return Default_FieldTestMessage_DefaultFloatNeginf
}
func (m *FieldTestMessage) GetDefaultFloatPosinf() float32 {
if m != nil && m.DefaultFloatPosinf != nil {
return *m.DefaultFloatPosinf
}
return Default_FieldTestMessage_DefaultFloatPosinf
}
func (m *FieldTestMessage) GetDefaultFloatNan() float32 {
if m != nil && m.DefaultFloatNan != nil {
return *m.DefaultFloatNan
}
return Default_FieldTestMessage_DefaultFloatNan
}
func (m *FieldTestMessage) GetDefaultDoubleNeginf() float64 {
if m != nil && m.DefaultDoubleNeginf != nil {
return *m.DefaultDoubleNeginf
}
return Default_FieldTestMessage_DefaultDoubleNeginf
}
func (m *FieldTestMessage) GetDefaultDoublePosinf() float64 {
if m != nil && m.DefaultDoublePosinf != nil {
return *m.DefaultDoublePosinf
}
return Default_FieldTestMessage_DefaultDoublePosinf
}
func (m *FieldTestMessage) GetDefaultDoubleNan() float64 {
if m != nil && m.DefaultDoubleNan != nil {
return *m.DefaultDoubleNan
}
return Default_FieldTestMessage_DefaultDoubleNan
}
type FieldTestMessage_OptionalGroup struct {
OptionalGroup *string `protobuf:"bytes,19,opt,name=optional_group,json=optionalGroup" json:"optional_group,omitempty"`
XXX_NoUnkeyedLiteral struct{} `json:"-"`
@ -215,6 +747,13 @@ func (m *FieldTestMessage_OptionalGroup) XXX_DiscardUnknown() {
var xxx_messageInfo_FieldTestMessage_OptionalGroup proto.InternalMessageInfo
func (m *FieldTestMessage_OptionalGroup) GetOptionalGroup() string {
if m != nil && m.OptionalGroup != nil {
return *m.OptionalGroup
}
return ""
}
type FieldTestMessage_RequiredGroup struct {
RequiredGroup *string `protobuf:"bytes,119,req,name=required_group,json=requiredGroup" json:"required_group,omitempty"`
XXX_NoUnkeyedLiteral struct{} `json:"-"`
@ -246,6 +785,13 @@ func (m *FieldTestMessage_RequiredGroup) XXX_DiscardUnknown() {
var xxx_messageInfo_FieldTestMessage_RequiredGroup proto.InternalMessageInfo
func (m *FieldTestMessage_RequiredGroup) GetRequiredGroup() string {
if m != nil && m.RequiredGroup != nil {
return *m.RequiredGroup
}
return ""
}
type FieldTestMessage_RepeatedGroup struct {
RepeatedGroup []string `protobuf:"bytes,219,rep,name=repeated_group,json=repeatedGroup" json:"repeated_group,omitempty"`
XXX_NoUnkeyedLiteral struct{} `json:"-"`
@ -277,6 +823,13 @@ func (m *FieldTestMessage_RepeatedGroup) XXX_DiscardUnknown() {
var xxx_messageInfo_FieldTestMessage_RepeatedGroup proto.InternalMessageInfo
func (m *FieldTestMessage_RepeatedGroup) GetRepeatedGroup() []string {
if m != nil {
return m.RepeatedGroup
}
return nil
}
type FieldTestMessage_Message struct {
XXX_NoUnkeyedLiteral struct{} `json:"-"`
XXX_unrecognized []byte `json:"-"`

View File

@ -43,6 +43,20 @@ func (m *Layer1) XXX_DiscardUnknown() {
var xxx_messageInfo_Layer1 proto.InternalMessageInfo
func (m *Layer1) GetL2() *Layer1_Layer2 {
if m != nil {
return m.L2
}
return nil
}
func (m *Layer1) GetL3() *Layer1_Layer2_Layer3 {
if m != nil {
return m.L3
}
return nil
}
type Layer1_Layer2 struct {
L3 *Layer1_Layer2_Layer3 `protobuf:"bytes,1,opt,name=l3" json:"l3,omitempty"`
XXX_NoUnkeyedLiteral struct{} `json:"-"`
@ -74,6 +88,13 @@ func (m *Layer1_Layer2) XXX_DiscardUnknown() {
var xxx_messageInfo_Layer1_Layer2 proto.InternalMessageInfo
func (m *Layer1_Layer2) GetL3() *Layer1_Layer2_Layer3 {
if m != nil {
return m.L3
}
return nil
}
type Layer1_Layer2_Layer3 struct {
XXX_NoUnkeyedLiteral struct{} `json:"-"`
XXX_unrecognized []byte `json:"-"`

View File

@ -43,6 +43,20 @@ func (m *Message) XXX_DiscardUnknown() {
var xxx_messageInfo_Message proto.InternalMessageInfo
func (m *Message) GetI32() int32 {
if m != nil && m.I32 != nil {
return *m.I32
}
return 0
}
func (m *Message) GetM() *Message {
if m != nil {
return m.M
}
return nil
}
func init() { proto.RegisterFile("proto2/proto2.proto", fileDescriptor_d756bbe8817c03c1) }
var fileDescriptor_d756bbe8817c03c1 = []byte{

View File

@ -80,6 +80,125 @@ func (m *FieldTestMessage) XXX_DiscardUnknown() {
var xxx_messageInfo_FieldTestMessage proto.InternalMessageInfo
func (m *FieldTestMessage) GetOptionalBool() string {
if m != nil {
return m.OptionalBool
}
return ""
}
func (m *FieldTestMessage) GetOptionalEnum() FieldTestMessage_Enum {
if m != nil {
return m.OptionalEnum
}
return FieldTestMessage_ZERO
}
func (m *FieldTestMessage) GetOptionalInt32() int32 {
if m != nil {
return m.OptionalInt32
}
return 0
}
func (m *FieldTestMessage) GetOptionalSint32() int32 {
if m != nil {
return m.OptionalSint32
}
return 0
}
func (m *FieldTestMessage) GetOptionalUint32() uint32 {
if m != nil {
return m.OptionalUint32
}
return 0
}
func (m *FieldTestMessage) GetOptionalInt64() int64 {
if m != nil {
return m.OptionalInt64
}
return 0
}
func (m *FieldTestMessage) GetOptionalSint64() int64 {
if m != nil {
return m.OptionalSint64
}
return 0
}
func (m *FieldTestMessage) GetOptionalUint64() uint64 {
if m != nil {
return m.OptionalUint64
}
return 0
}
func (m *FieldTestMessage) GetOptionalSfixed32() int32 {
if m != nil {
return m.OptionalSfixed32
}
return 0
}
func (m *FieldTestMessage) GetOptionalFixed32() uint32 {
if m != nil {
return m.OptionalFixed32
}
return 0
}
func (m *FieldTestMessage) GetOptionalFloat() float32 {
if m != nil {
return m.OptionalFloat
}
return 0
}
func (m *FieldTestMessage) GetOptionalSfixed64() int64 {
if m != nil {
return m.OptionalSfixed64
}
return 0
}
func (m *FieldTestMessage) GetOptionalFixed64() uint64 {
if m != nil {
return m.OptionalFixed64
}
return 0
}
func (m *FieldTestMessage) GetOptionalDouble() float64 {
if m != nil {
return m.OptionalDouble
}
return 0
}
func (m *FieldTestMessage) GetOptionalString() string {
if m != nil {
return m.OptionalString
}
return ""
}
func (m *FieldTestMessage) GetOptionalBytes() []byte {
if m != nil {
return m.OptionalBytes
}
return nil
}
func (m *FieldTestMessage) GetOptional_Message() *FieldTestMessage_Message {
if m != nil {
return m.Optional_Message
}
return nil
}
type FieldTestMessage_Message struct {
XXX_NoUnkeyedLiteral struct{} `json:"-"`
XXX_unrecognized []byte `json:"-"`