diff options
author | David Symonds <dsymonds@golang.org> | 2014-10-12 16:24:13 +1100 |
---|---|---|
committer | David Symonds <dsymonds@golang.org> | 2014-10-12 16:24:13 +1100 |
commit | bebcf5de5700fa221a8bc51e46263e7fb4082110 (patch) | |
tree | 01b03b11df1f1dff2bb23bf7929b88b716740152 | |
parent | 0ec36a25a231c827c20a7cf194b1f99b7336d529 (diff) | |
download | protobuf-bebcf5de5700fa221a8bc51e46263e7fb4082110.tar.gz |
goprotobuf: Add method to extending message to get list of messages extended.
LGTM=gmlewis
R=gmlewis
CC=golang-codereviews
https://codereview.appspot.com/159790043
-rw-r--r-- | protoc-gen-go/generator/generator.go | 7 | ||||
-rw-r--r-- | protoc-gen-go/testdata/my_test/test.pb.go | 76 | ||||
-rw-r--r-- | protoc-gen-go/testdata/my_test/test.pb.go.golden | 76 | ||||
-rw-r--r-- | protoc-gen-go/testdata/my_test/test.proto | 15 |
4 files changed, 170 insertions, 4 deletions
diff --git a/protoc-gen-go/generator/generator.go b/protoc-gen-go/generator/generator.go index 4f99191..a86a121 100644 --- a/protoc-gen-go/generator/generator.go +++ b/protoc-gen-go/generator/generator.go @@ -160,13 +160,12 @@ func (e *EnumDescriptor) TypeName() (s []string) { // Everything but the last element of the full type name, CamelCased. // The values of type Foo.Bar are call Foo_value1... not Foo_Bar_value1... . func (e *EnumDescriptor) prefix() string { - typeName := e.TypeName() - ccPrefix := CamelCaseSlice(typeName[0:len(typeName)-1]) + "_" if e.parent == nil { // If the enum is not part of a message, the prefix is just the type name. - ccPrefix = CamelCase(*e.Name) + "_" + return CamelCase(*e.Name) + "_" } - return ccPrefix + typeName := e.TypeName() + return CamelCaseSlice(typeName[0:len(typeName)-1]) + "_" } // The integer value of the named constant in this enumerated type. diff --git a/protoc-gen-go/testdata/my_test/test.pb.go b/protoc-gen-go/testdata/my_test/test.pb.go index 548f458..1165dea 100644 --- a/protoc-gen-go/testdata/my_test/test.pb.go +++ b/protoc-gen-go/testdata/my_test/test.pb.go @@ -11,7 +11,9 @@ It is generated from these files: It has these top-level messages: Request Reply + OtherBase ReplyExtensions + OtherReplyExtensions OldReply */ package my_test @@ -317,6 +319,37 @@ func (m *Reply_Entry) GetXMyFieldName_2() int64 { return 0 } +type OtherBase struct { + Name *string `protobuf:"bytes,1,opt,name=name" json:"name,omitempty"` + XXX_extensions map[int32]proto.Extension `json:"-"` + XXX_unrecognized []byte `json:"-"` +} + +func (m *OtherBase) Reset() { *m = OtherBase{} } +func (m *OtherBase) String() string { return proto.CompactTextString(m) } +func (*OtherBase) ProtoMessage() {} + +var extRange_OtherBase = []proto.ExtensionRange{ + {100, 536870911}, +} + +func (*OtherBase) ExtensionRangeArray() []proto.ExtensionRange { + return extRange_OtherBase +} +func (m *OtherBase) ExtensionMap() map[int32]proto.Extension { + if m.XXX_extensions == nil { + m.XXX_extensions = make(map[int32]proto.Extension) + } + return m.XXX_extensions +} + +func (m *OtherBase) GetName() string { + if m != nil && m.Name != nil { + return *m.Name + } + return "" +} + type ReplyExtensions struct { XXX_unrecognized []byte `json:"-"` } @@ -333,6 +366,38 @@ var E_ReplyExtensions_Time = &proto.ExtensionDesc{ Tag: "fixed64,101,opt,name=time", } +var E_ReplyExtensions_Carrot = &proto.ExtensionDesc{ + ExtendedType: (*Reply)(nil), + ExtensionType: (*ReplyExtensions)(nil), + Field: 105, + Name: "my.test.ReplyExtensions.carrot", + Tag: "bytes,105,opt,name=carrot", +} + +var E_ReplyExtensions_Donut = &proto.ExtensionDesc{ + ExtendedType: (*OtherBase)(nil), + ExtensionType: (*ReplyExtensions)(nil), + Field: 101, + Name: "my.test.ReplyExtensions.donut", + Tag: "bytes,101,opt,name=donut", +} + +type OtherReplyExtensions struct { + Key *int32 `protobuf:"varint,1,opt,name=key" json:"key,omitempty"` + XXX_unrecognized []byte `json:"-"` +} + +func (m *OtherReplyExtensions) Reset() { *m = OtherReplyExtensions{} } +func (m *OtherReplyExtensions) String() string { return proto.CompactTextString(m) } +func (*OtherReplyExtensions) ProtoMessage() {} + +func (m *OtherReplyExtensions) GetKey() int32 { + if m != nil && m.Key != nil { + return *m.Key + } + return 0 +} + type OldReply struct { XXX_extensions map[int32]proto.Extension `json:"-"` XXX_unrecognized []byte `json:"-"` @@ -375,11 +440,22 @@ var E_Tag = &proto.ExtensionDesc{ Tag: "bytes,103,opt,name=tag", } +var E_Donut = &proto.ExtensionDesc{ + ExtendedType: (*Reply)(nil), + ExtensionType: (*OtherReplyExtensions)(nil), + Field: 106, + Name: "my.test.donut", + Tag: "bytes,106,opt,name=donut", +} + func init() { proto.RegisterEnum("my.test.HatType", HatType_name, HatType_value) proto.RegisterEnum("my.test.Days", Days_name, Days_value) proto.RegisterEnum("my.test.Request_Color", Request_Color_name, Request_Color_value) proto.RegisterEnum("my.test.Reply_Entry_Game", Reply_Entry_Game_name, Reply_Entry_Game_value) proto.RegisterExtension(E_ReplyExtensions_Time) + proto.RegisterExtension(E_ReplyExtensions_Carrot) + proto.RegisterExtension(E_ReplyExtensions_Donut) proto.RegisterExtension(E_Tag) + proto.RegisterExtension(E_Donut) } diff --git a/protoc-gen-go/testdata/my_test/test.pb.go.golden b/protoc-gen-go/testdata/my_test/test.pb.go.golden index 548f458..1165dea 100644 --- a/protoc-gen-go/testdata/my_test/test.pb.go.golden +++ b/protoc-gen-go/testdata/my_test/test.pb.go.golden @@ -11,7 +11,9 @@ It is generated from these files: It has these top-level messages: Request Reply + OtherBase ReplyExtensions + OtherReplyExtensions OldReply */ package my_test @@ -317,6 +319,37 @@ func (m *Reply_Entry) GetXMyFieldName_2() int64 { return 0 } +type OtherBase struct { + Name *string `protobuf:"bytes,1,opt,name=name" json:"name,omitempty"` + XXX_extensions map[int32]proto.Extension `json:"-"` + XXX_unrecognized []byte `json:"-"` +} + +func (m *OtherBase) Reset() { *m = OtherBase{} } +func (m *OtherBase) String() string { return proto.CompactTextString(m) } +func (*OtherBase) ProtoMessage() {} + +var extRange_OtherBase = []proto.ExtensionRange{ + {100, 536870911}, +} + +func (*OtherBase) ExtensionRangeArray() []proto.ExtensionRange { + return extRange_OtherBase +} +func (m *OtherBase) ExtensionMap() map[int32]proto.Extension { + if m.XXX_extensions == nil { + m.XXX_extensions = make(map[int32]proto.Extension) + } + return m.XXX_extensions +} + +func (m *OtherBase) GetName() string { + if m != nil && m.Name != nil { + return *m.Name + } + return "" +} + type ReplyExtensions struct { XXX_unrecognized []byte `json:"-"` } @@ -333,6 +366,38 @@ var E_ReplyExtensions_Time = &proto.ExtensionDesc{ Tag: "fixed64,101,opt,name=time", } +var E_ReplyExtensions_Carrot = &proto.ExtensionDesc{ + ExtendedType: (*Reply)(nil), + ExtensionType: (*ReplyExtensions)(nil), + Field: 105, + Name: "my.test.ReplyExtensions.carrot", + Tag: "bytes,105,opt,name=carrot", +} + +var E_ReplyExtensions_Donut = &proto.ExtensionDesc{ + ExtendedType: (*OtherBase)(nil), + ExtensionType: (*ReplyExtensions)(nil), + Field: 101, + Name: "my.test.ReplyExtensions.donut", + Tag: "bytes,101,opt,name=donut", +} + +type OtherReplyExtensions struct { + Key *int32 `protobuf:"varint,1,opt,name=key" json:"key,omitempty"` + XXX_unrecognized []byte `json:"-"` +} + +func (m *OtherReplyExtensions) Reset() { *m = OtherReplyExtensions{} } +func (m *OtherReplyExtensions) String() string { return proto.CompactTextString(m) } +func (*OtherReplyExtensions) ProtoMessage() {} + +func (m *OtherReplyExtensions) GetKey() int32 { + if m != nil && m.Key != nil { + return *m.Key + } + return 0 +} + type OldReply struct { XXX_extensions map[int32]proto.Extension `json:"-"` XXX_unrecognized []byte `json:"-"` @@ -375,11 +440,22 @@ var E_Tag = &proto.ExtensionDesc{ Tag: "bytes,103,opt,name=tag", } +var E_Donut = &proto.ExtensionDesc{ + ExtendedType: (*Reply)(nil), + ExtensionType: (*OtherReplyExtensions)(nil), + Field: 106, + Name: "my.test.donut", + Tag: "bytes,106,opt,name=donut", +} + func init() { proto.RegisterEnum("my.test.HatType", HatType_name, HatType_value) proto.RegisterEnum("my.test.Days", Days_name, Days_value) proto.RegisterEnum("my.test.Request_Color", Request_Color_name, Request_Color_value) proto.RegisterEnum("my.test.Reply_Entry_Game", Reply_Entry_Game_name, Reply_Entry_Game_value) proto.RegisterExtension(E_ReplyExtensions_Time) + proto.RegisterExtension(E_ReplyExtensions_Carrot) + proto.RegisterExtension(E_ReplyExtensions_Donut) proto.RegisterExtension(E_Tag) + proto.RegisterExtension(E_Donut) } diff --git a/protoc-gen-go/testdata/my_test/test.proto b/protoc-gen-go/testdata/my_test/test.proto index 551585d..c957326 100644 --- a/protoc-gen-go/testdata/my_test/test.proto +++ b/protoc-gen-go/testdata/my_test/test.proto @@ -90,15 +90,30 @@ message Reply { extensions 100 to max; } +message OtherBase { + optional string name = 1; + extensions 100 to max; +} + message ReplyExtensions { extend Reply { optional double time = 101; + optional ReplyExtensions carrot = 105; } + extend OtherBase { + optional ReplyExtensions donut = 101; + } +} + +message OtherReplyExtensions { + optional int32 key = 1; } // top-level extension extend Reply { optional string tag = 103; + optional OtherReplyExtensions donut = 106; +// optional imp.ImportedMessage elephant = 107; // extend with message from another file. } message OldReply { |