Browse Source

protoc-gen-go: expand import_public test files

Convert all the import_public protos to proto2 to allow testing more
features.

Add usage of groups, extensions, and default values.
Damien Neil 7 years ago
parent
commit
d18af0db6e

+ 12 - 8
protoc-gen-go/testdata/import_public/a.pb.go

@@ -21,6 +21,8 @@ var _ = math.Inf
 // proto package needs to be updated.
 const _ = proto.ProtoPackageIsVersion2 // please upgrade the proto package
 
+const Default_M_DefaultField = sub.Default_M_DefaultField
+
 // M from public import import_public/sub/a.proto
 type M = sub.M
 type M_OneofInt32 = sub.M_OneofInt32
@@ -55,10 +57,12 @@ var M_Submessage_Submessage_Subenum_value = sub.M_Submessage_Submessage_Subenum_
 
 const M_Submessage_M_SUBMESSAGE_ZERO = M_Submessage_Submessage_Subenum(sub.M_Submessage_M_SUBMESSAGE_ZERO)
 
+var E_ExtensionField = sub.E_ExtensionField
+
 type Public struct {
-	M                    *sub.M   `protobuf:"bytes,1,opt,name=m,proto3" json:"m,omitempty"`
-	E                    sub.E    `protobuf:"varint,2,opt,name=e,proto3,enum=goproto.test.import_public.sub.E" json:"e,omitempty"`
-	Local                *Local   `protobuf:"bytes,3,opt,name=local,proto3" json:"local,omitempty"`
+	M                    *sub.M   `protobuf:"bytes,1,opt,name=m" json:"m,omitempty"`
+	E                    *sub.E   `protobuf:"varint,2,opt,name=e,enum=goproto.test.import_public.sub.E" json:"e,omitempty"`
+	Local                *Local   `protobuf:"bytes,3,opt,name=local" json:"local,omitempty"`
 	XXX_NoUnkeyedLiteral struct{} `json:"-"`
 	XXX_unrecognized     []byte   `json:"-"`
 	XXX_sizecache        int32    `json:"-"`
@@ -97,8 +101,8 @@ func (m *Public) GetM() *sub.M {
 }
 
 func (m *Public) GetE() sub.E {
-	if m != nil {
-		return m.E
+	if m != nil && m.E != nil {
+		return *m.E
 	}
 	return sub.E_ZERO
 }
@@ -117,7 +121,7 @@ func init() {
 func init() { proto.RegisterFile("import_public/a.proto", fileDescriptor_73b7577c95fa6b70) }
 
 var fileDescriptor_73b7577c95fa6b70 = []byte{
-	// 200 bytes of a gzipped FileDescriptorProto
+	// 195 bytes of a gzipped FileDescriptorProto
 	0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x12, 0xcd, 0xcc, 0x2d, 0xc8,
 	0x2f, 0x2a, 0x89, 0x2f, 0x28, 0x4d, 0xca, 0xc9, 0x4c, 0xd6, 0x4f, 0xd4, 0x2b, 0x28, 0xca, 0x2f,
 	0xc9, 0x17, 0x92, 0x4a, 0xcf, 0x07, 0x33, 0xf4, 0x4a, 0x52, 0x8b, 0x4b, 0xf4, 0x50, 0xd4, 0x48,
@@ -129,6 +133,6 @@ var fileDescriptor_73b7577c95fa6b70 = []byte{
 	0x04, 0x51, 0xef, 0xe4, 0x18, 0x65, 0x9f, 0x9e, 0x59, 0x92, 0x51, 0x9a, 0xa4, 0x97, 0x9c, 0x9f,
 	0xab, 0x9f, 0x9e, 0x9f, 0x93, 0x98, 0x97, 0xae, 0x0f, 0xd6, 0x9a, 0x54, 0x9a, 0x06, 0x61, 0x24,
 	0xeb, 0xa6, 0xa7, 0xe6, 0xe9, 0xa6, 0xe7, 0xeb, 0x83, 0xcc, 0x4a, 0x49, 0x2c, 0x49, 0xd4, 0x47,
-	0x31, 0x2f, 0x80, 0x21, 0x80, 0x31, 0x89, 0x0d, 0xac, 0xd2, 0x18, 0x10, 0x00, 0x00, 0xff, 0xff,
-	0x70, 0xc5, 0xc3, 0x79, 0x5a, 0x01, 0x00, 0x00,
+	0x31, 0x2f, 0x80, 0x21, 0x80, 0x11, 0x10, 0x00, 0x00, 0xff, 0xff, 0x17, 0x83, 0x2d, 0xd4, 0x52,
+	0x01, 0x00, 0x00,
 }

+ 4 - 4
protoc-gen-go/testdata/import_public/a.proto

@@ -29,7 +29,7 @@
 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
-syntax = "proto3";
+syntax = "proto2";
 
 package goproto.test.import_public;
 
@@ -39,7 +39,7 @@ import public "import_public/sub/a.proto"; // Different Go package.
 import public "import_public/b.proto";     // Same Go package.
 
 message Public {
-  goproto.test.import_public.sub.M m = 1;
-  goproto.test.import_public.sub.E e = 2;
-  Local local = 3;
+  optional goproto.test.import_public.sub.M m = 1;
+  optional goproto.test.import_public.sub.E e = 2;
+  optional Local local = 3;
 }

+ 7 - 7
protoc-gen-go/testdata/import_public/b.pb.go

@@ -22,8 +22,8 @@ var _ = math.Inf
 const _ = proto.ProtoPackageIsVersion2 // please upgrade the proto package
 
 type Local struct {
-	M                    *sub.M   `protobuf:"bytes,1,opt,name=m,proto3" json:"m,omitempty"`
-	E                    sub.E    `protobuf:"varint,2,opt,name=e,proto3,enum=goproto.test.import_public.sub.E" json:"e,omitempty"`
+	M                    *sub.M   `protobuf:"bytes,1,opt,name=m" json:"m,omitempty"`
+	E                    *sub.E   `protobuf:"varint,2,opt,name=e,enum=goproto.test.import_public.sub.E" json:"e,omitempty"`
 	XXX_NoUnkeyedLiteral struct{} `json:"-"`
 	XXX_unrecognized     []byte   `json:"-"`
 	XXX_sizecache        int32    `json:"-"`
@@ -62,8 +62,8 @@ func (m *Local) GetM() *sub.M {
 }
 
 func (m *Local) GetE() sub.E {
-	if m != nil {
-		return m.E
+	if m != nil && m.E != nil {
+		return *m.E
 	}
 	return sub.E_ZERO
 }
@@ -75,7 +75,7 @@ func init() {
 func init() { proto.RegisterFile("import_public/b.proto", fileDescriptor_84995586b3d09710) }
 
 var fileDescriptor_84995586b3d09710 = []byte{
-	// 174 bytes of a gzipped FileDescriptorProto
+	// 169 bytes of a gzipped FileDescriptorProto
 	0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x12, 0xcd, 0xcc, 0x2d, 0xc8,
 	0x2f, 0x2a, 0x89, 0x2f, 0x28, 0x4d, 0xca, 0xc9, 0x4c, 0xd6, 0x4f, 0xd2, 0x2b, 0x28, 0xca, 0x2f,
 	0xc9, 0x17, 0x92, 0x4a, 0xcf, 0x07, 0x33, 0xf4, 0x4a, 0x52, 0x8b, 0x4b, 0xf4, 0x50, 0xd4, 0x48,
@@ -85,6 +85,6 @@ var fileDescriptor_84995586b3d09710 = []byte{
 	0x04, 0x93, 0x02, 0xa3, 0x06, 0x1f, 0x61, 0x0d, 0xae, 0x41, 0x8c, 0xa9, 0x4e, 0x8e, 0x51, 0xf6,
 	0xe9, 0x99, 0x25, 0x19, 0xa5, 0x49, 0x7a, 0xc9, 0xf9, 0xb9, 0xfa, 0xe9, 0xf9, 0x39, 0x89, 0x79,
 	0xe9, 0xfa, 0x60, 0x6d, 0x49, 0xa5, 0x69, 0x10, 0x46, 0xb2, 0x6e, 0x7a, 0x6a, 0x9e, 0x6e, 0x7a,
-	0xbe, 0x3e, 0xc8, 0x9c, 0x94, 0xc4, 0x92, 0x44, 0x7d, 0x14, 0xb3, 0x92, 0xd8, 0xc0, 0xaa, 0x8c,
-	0x01, 0x01, 0x00, 0x00, 0xff, 0xff, 0xd6, 0x2b, 0x5f, 0x8e, 0x04, 0x01, 0x00, 0x00,
+	0xbe, 0x3e, 0xc8, 0x9c, 0x94, 0xc4, 0x92, 0x44, 0x7d, 0x14, 0xb3, 0x00, 0x01, 0x00, 0x00, 0xff,
+	0xff, 0x35, 0x0e, 0x6a, 0x82, 0xfc, 0x00, 0x00, 0x00,
 }

+ 3 - 3
protoc-gen-go/testdata/import_public/b.proto

@@ -29,7 +29,7 @@
 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
-syntax = "proto3";
+syntax = "proto2";
 
 package goproto.test.import_public;
 
@@ -38,6 +38,6 @@ option go_package = "github.com/golang/protobuf/protoc-gen-go/testdata/import_pu
 import "import_public/sub/a.proto";
 
 message Local {
-  goproto.test.import_public.sub.M m = 1;
-  goproto.test.import_public.sub.E e = 2;
+  optional goproto.test.import_public.sub.M m = 1;
+  optional goproto.test.import_public.sub.E e = 2;
 }

+ 147 - 28
protoc-gen-go/testdata/import_public/sub/a.pb.go

@@ -34,10 +34,25 @@ var E_value = map[string]int32{
 	"ZERO": 0,
 }
 
+func (x E) Enum() *E {
+	p := new(E)
+	*p = x
+	return p
+}
+
 func (x E) String() string {
 	return proto.EnumName(E_name, int32(x))
 }
 
+func (x *E) UnmarshalJSON(data []byte) error {
+	value, err := proto.UnmarshalJSONEnum(E_value, data, "E")
+	if err != nil {
+		return err
+	}
+	*x = E(value)
+	return nil
+}
+
 func (E) EnumDescriptor() ([]byte, []int) {
 	return fileDescriptor_382f7805394b5c4e, []int{0}
 }
@@ -56,10 +71,25 @@ var M_Subenum_value = map[string]int32{
 	"M_ZERO": 0,
 }
 
+func (x M_Subenum) Enum() *M_Subenum {
+	p := new(M_Subenum)
+	*p = x
+	return p
+}
+
 func (x M_Subenum) String() string {
 	return proto.EnumName(M_Subenum_name, int32(x))
 }
 
+func (x *M_Subenum) UnmarshalJSON(data []byte) error {
+	value, err := proto.UnmarshalJSONEnum(M_Subenum_value, data, "M_Subenum")
+	if err != nil {
+		return err
+	}
+	*x = M_Subenum(value)
+	return nil
+}
+
 func (M_Subenum) EnumDescriptor() ([]byte, []int) {
 	return fileDescriptor_382f7805394b5c4e, []int{0, 0}
 }
@@ -78,21 +108,38 @@ var M_Submessage_Submessage_Subenum_value = map[string]int32{
 	"M_SUBMESSAGE_ZERO": 0,
 }
 
+func (x M_Submessage_Submessage_Subenum) Enum() *M_Submessage_Submessage_Subenum {
+	p := new(M_Submessage_Submessage_Subenum)
+	*p = x
+	return p
+}
+
 func (x M_Submessage_Submessage_Subenum) String() string {
 	return proto.EnumName(M_Submessage_Submessage_Subenum_name, int32(x))
 }
 
+func (x *M_Submessage_Submessage_Subenum) UnmarshalJSON(data []byte) error {
+	value, err := proto.UnmarshalJSONEnum(M_Submessage_Submessage_Subenum_value, data, "M_Submessage_Submessage_Subenum")
+	if err != nil {
+		return err
+	}
+	*x = M_Submessage_Submessage_Subenum(value)
+	return nil
+}
+
 func (M_Submessage_Submessage_Subenum) EnumDescriptor() ([]byte, []int) {
-	return fileDescriptor_382f7805394b5c4e, []int{0, 0, 0}
+	return fileDescriptor_382f7805394b5c4e, []int{0, 1, 0}
 }
 
 type M struct {
 	// Field using a type in the same Go package, but a different source file.
-	M2 *M2 `protobuf:"bytes,1,opt,name=m2,proto3" json:"m2,omitempty"`
+	M2 *M2 `protobuf:"bytes,1,opt,name=m2" json:"m2,omitempty"`
 	// Types that are valid to be assigned to OneofField:
 	//	*M_OneofInt32
 	//	*M_OneofInt64
 	OneofField           isM_OneofField `protobuf_oneof:"oneof_field"`
+	Grouping             *M_Grouping    `protobuf:"group,4,opt,name=Grouping,json=grouping" json:"grouping,omitempty"`
+	DefaultField         *string        `protobuf:"bytes,6,opt,name=default_field,json=defaultField,def=def" json:"default_field,omitempty"`
 	XXX_NoUnkeyedLiteral struct{}       `json:"-"`
 	XXX_unrecognized     []byte         `json:"-"`
 	XXX_sizecache        int32          `json:"-"`
@@ -123,6 +170,8 @@ func (m *M) XXX_DiscardUnknown() {
 
 var xxx_messageInfo_M proto.InternalMessageInfo
 
+const Default_M_DefaultField string = "def"
+
 func (m *M) GetM2() *M2 {
 	if m != nil {
 		return m.M2
@@ -135,11 +184,11 @@ type isM_OneofField interface {
 }
 
 type M_OneofInt32 struct {
-	OneofInt32 int32 `protobuf:"varint,2,opt,name=oneof_int32,json=oneofInt32,proto3,oneof"`
+	OneofInt32 int32 `protobuf:"varint,2,opt,name=oneof_int32,json=oneofInt32,oneof"`
 }
 
 type M_OneofInt64 struct {
-	OneofInt64 int64 `protobuf:"varint,3,opt,name=oneof_int64,json=oneofInt64,proto3,oneof"`
+	OneofInt64 int64 `protobuf:"varint,3,opt,name=oneof_int64,json=oneofInt64,oneof"`
 }
 
 func (*M_OneofInt32) isM_OneofField() {}
@@ -167,6 +216,20 @@ func (m *M) GetOneofInt64() int64 {
 	return 0
 }
 
+func (m *M) GetGrouping() *M_Grouping {
+	if m != nil {
+		return m.Grouping
+	}
+	return nil
+}
+
+func (m *M) GetDefaultField() string {
+	if m != nil && m.DefaultField != nil {
+		return *m.DefaultField
+	}
+	return Default_M_DefaultField
+}
+
 // XXX_OneofFuncs is for the internal use of the proto package.
 func (*M) XXX_OneofFuncs() (func(msg proto.Message, b *proto.Buffer) error, func(msg proto.Message, tag, wire int, b *proto.Buffer) (bool, error), func(msg proto.Message) (n int), []interface{}) {
 	return _M_OneofMarshaler, _M_OneofUnmarshaler, _M_OneofSizer, []interface{}{
@@ -231,6 +294,45 @@ func _M_OneofSizer(msg proto.Message) (n int) {
 	return n
 }
 
+type M_Grouping struct {
+	GroupField           *string  `protobuf:"bytes,5,opt,name=group_field,json=groupField" json:"group_field,omitempty"`
+	XXX_NoUnkeyedLiteral struct{} `json:"-"`
+	XXX_unrecognized     []byte   `json:"-"`
+	XXX_sizecache        int32    `json:"-"`
+}
+
+func (m *M_Grouping) Reset()         { *m = M_Grouping{} }
+func (m *M_Grouping) String() string { return proto.CompactTextString(m) }
+func (*M_Grouping) ProtoMessage()    {}
+func (*M_Grouping) Descriptor() ([]byte, []int) {
+	return fileDescriptor_382f7805394b5c4e, []int{0, 0}
+}
+
+func (m *M_Grouping) XXX_Unmarshal(b []byte) error {
+	return xxx_messageInfo_M_Grouping.Unmarshal(m, b)
+}
+func (m *M_Grouping) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
+	return xxx_messageInfo_M_Grouping.Marshal(b, m, deterministic)
+}
+func (m *M_Grouping) XXX_Merge(src proto.Message) {
+	xxx_messageInfo_M_Grouping.Merge(m, src)
+}
+func (m *M_Grouping) XXX_Size() int {
+	return xxx_messageInfo_M_Grouping.Size(m)
+}
+func (m *M_Grouping) XXX_DiscardUnknown() {
+	xxx_messageInfo_M_Grouping.DiscardUnknown(m)
+}
+
+var xxx_messageInfo_M_Grouping proto.InternalMessageInfo
+
+func (m *M_Grouping) GetGroupField() string {
+	if m != nil && m.GroupField != nil {
+		return *m.GroupField
+	}
+	return ""
+}
+
 type M_Submessage struct {
 	// Types that are valid to be assigned to SubmessageOneofField:
 	//	*M_Submessage_SubmessageOneofInt32
@@ -245,7 +347,7 @@ func (m *M_Submessage) Reset()         { *m = M_Submessage{} }
 func (m *M_Submessage) String() string { return proto.CompactTextString(m) }
 func (*M_Submessage) ProtoMessage()    {}
 func (*M_Submessage) Descriptor() ([]byte, []int) {
-	return fileDescriptor_382f7805394b5c4e, []int{0, 0}
+	return fileDescriptor_382f7805394b5c4e, []int{0, 1}
 }
 
 func (m *M_Submessage) XXX_Unmarshal(b []byte) error {
@@ -271,11 +373,11 @@ type isM_Submessage_SubmessageOneofField interface {
 }
 
 type M_Submessage_SubmessageOneofInt32 struct {
-	SubmessageOneofInt32 int32 `protobuf:"varint,1,opt,name=submessage_oneof_int32,json=submessageOneofInt32,proto3,oneof"`
+	SubmessageOneofInt32 int32 `protobuf:"varint,1,opt,name=submessage_oneof_int32,json=submessageOneofInt32,oneof"`
 }
 
 type M_Submessage_SubmessageOneofInt64 struct {
-	SubmessageOneofInt64 int64 `protobuf:"varint,2,opt,name=submessage_oneof_int64,json=submessageOneofInt64,proto3,oneof"`
+	SubmessageOneofInt64 int64 `protobuf:"varint,2,opt,name=submessage_oneof_int64,json=submessageOneofInt64,oneof"`
 }
 
 func (*M_Submessage_SubmessageOneofInt32) isM_Submessage_SubmessageOneofField() {}
@@ -367,36 +469,53 @@ func _M_Submessage_OneofSizer(msg proto.Message) (n int) {
 	return n
 }
 
+var E_ExtensionField = &proto.ExtensionDesc{
+	ExtendedType:  (*M2)(nil),
+	ExtensionType: (*string)(nil),
+	Field:         1,
+	Name:          "goproto.test.import_public.sub.extension_field",
+	Tag:           "bytes,1,opt,name=extension_field",
+	Filename:      "import_public/sub/a.proto",
+}
+
 func init() {
 	proto.RegisterEnum("goproto.test.import_public.sub.E", E_name, E_value)
 	proto.RegisterEnum("goproto.test.import_public.sub.M_Subenum", M_Subenum_name, M_Subenum_value)
 	proto.RegisterEnum("goproto.test.import_public.sub.M_Submessage_Submessage_Subenum", M_Submessage_Submessage_Subenum_name, M_Submessage_Submessage_Subenum_value)
 	proto.RegisterType((*M)(nil), "goproto.test.import_public.sub.M")
+	proto.RegisterType((*M_Grouping)(nil), "goproto.test.import_public.sub.M.Grouping")
 	proto.RegisterType((*M_Submessage)(nil), "goproto.test.import_public.sub.M.Submessage")
+	proto.RegisterExtension(E_ExtensionField)
 }
 
 func init() { proto.RegisterFile("import_public/sub/a.proto", fileDescriptor_382f7805394b5c4e) }
 
 var fileDescriptor_382f7805394b5c4e = []byte{
-	// 314 bytes of a gzipped FileDescriptorProto
-	0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x7c, 0x91, 0xd1, 0x4e, 0xfa, 0x30,
-	0x14, 0xc6, 0xe9, 0xf8, 0xff, 0xd1, 0x1c, 0x42, 0xa2, 0x8d, 0x98, 0xc9, 0x85, 0xc1, 0x5d, 0x11,
-	0x0d, 0x5d, 0x32, 0x96, 0xdd, 0x8b, 0x59, 0xd4, 0x8b, 0x85, 0x84, 0xc5, 0x1b, 0x6e, 0x9a, 0x15,
-	0x4a, 0x5d, 0x42, 0x57, 0x42, 0xdb, 0x27, 0xf4, 0x69, 0x7c, 0x0b, 0x43, 0x01, 0x81, 0x88, 0xde,
-	0x9d, 0x9e, 0xf3, 0xfd, 0xbe, 0xaf, 0xed, 0x81, 0x9b, 0x52, 0x2e, 0xd5, 0xca, 0xd0, 0xa5, 0x65,
-	0x8b, 0x72, 0x1a, 0x6a, 0xcb, 0xc2, 0x82, 0x2c, 0x57, 0xca, 0x28, 0x7c, 0x2b, 0x94, 0x2b, 0x88,
-	0xe1, 0xda, 0x90, 0x23, 0x1d, 0xd1, 0x96, 0x75, 0x4e, 0xa0, 0x6c, 0x83, 0x06, 0x9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 0x73, 0x40, 0x01, 0x9e, 0xc2, 0xa4, 0xeb,
+	0x5e, 0x7f, 0x85, 0xe7, 0xec, 0x87, 0x62, 0xa2, 0x29, 0xa4, 0xe8, 0x14, 0xf8, 0x11, 0xa7, 0x61,
+	0x82, 0x38, 0x8d, 0x9e, 0x6d, 0x51, 0x93, 0xe3, 0x2a, 0xb8, 0xff, 0xc4, 0x0b, 0xf5, 0x5d, 0x53,
+	0xb2, 0x96, 0x95, 0xcb, 0x65, 0x99, 0x0a, 0xee, 0x1a, 0x2b, 0xaa, 0xf3, 0xee, 0xb1, 0xbe, 0xe2,
+	0x4c, 0x5c, 0x71, 0xe9, 0xb6, 0xde, 0x59, 0xaa, 0x52, 0xf7, 0x8f, 0xab, 0xfd, 0x1d, 0x00, 0x00,
+	0xff, 0xff, 0x13, 0x4f, 0x31, 0x07, 0x04, 0x03, 0x00, 0x00,
 }

+ 12 - 2
protoc-gen-go/testdata/import_public/sub/a.proto

@@ -29,7 +29,7 @@
 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
-syntax = "proto3";
+syntax = "proto2";
 
 package goproto.test.import_public.sub;
 
@@ -39,13 +39,19 @@ import "import_public/sub/b.proto";
 
 message M {
   // Field using a type in the same Go package, but a different source file.
-  M2 m2 = 1;
+  optional M2 m2 = 1;
 
   oneof oneof_field {
     int32 oneof_int32 = 2;
     int64 oneof_int64 = 3;
   }
 
+  optional group Grouping = 4  {
+    optional string group_field = 5;
+  }
+
+  optional string default_field = 6 [default="def"];
+
   message Submessage {
     enum Submessage_Subenum {
       M_SUBMESSAGE_ZERO = 0;
@@ -65,3 +71,7 @@ message M {
 enum E {
   ZERO = 0;
 }
+
+extend M2 {
+  optional string extension_field = 1;
+}

+ 19 - 9
protoc-gen-go/testdata/import_public/sub/b.pb.go

@@ -21,9 +21,10 @@ var _ = math.Inf
 const _ = proto.ProtoPackageIsVersion2 // please upgrade the proto package
 
 type M2 struct {
-	XXX_NoUnkeyedLiteral struct{} `json:"-"`
-	XXX_unrecognized     []byte   `json:"-"`
-	XXX_sizecache        int32    `json:"-"`
+	XXX_NoUnkeyedLiteral         struct{} `json:"-"`
+	proto.XXX_InternalExtensions `json:"-"`
+	XXX_unrecognized             []byte `json:"-"`
+	XXX_sizecache                int32  `json:"-"`
 }
 
 func (m *M2) Reset()         { *m = M2{} }
@@ -33,6 +34,14 @@ func (*M2) Descriptor() ([]byte, []int) {
 	return fileDescriptor_fc66afda3d7c2232, []int{0}
 }
 
+var extRange_M2 = []proto.ExtensionRange{
+	{Start: 1, End: 536870911},
+}
+
+func (*M2) ExtensionRangeArray() []proto.ExtensionRange {
+	return extRange_M2
+}
+
 func (m *M2) XXX_Unmarshal(b []byte) error {
 	return xxx_messageInfo_M2.Unmarshal(m, b)
 }
@@ -58,13 +67,14 @@ func init() {
 func init() { proto.RegisterFile("import_public/sub/b.proto", fileDescriptor_fc66afda3d7c2232) }
 
 var fileDescriptor_fc66afda3d7c2232 = []byte{
-	// 127 bytes of a gzipped FileDescriptorProto
+	// 132 bytes of a gzipped FileDescriptorProto
 	0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x92, 0xcc, 0xcc, 0x2d, 0xc8,
 	0x2f, 0x2a, 0x89, 0x2f, 0x28, 0x4d, 0xca, 0xc9, 0x4c, 0xd6, 0x2f, 0x2e, 0x4d, 0xd2, 0x4f, 0xd2,
 	0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x92, 0x4b, 0xcf, 0x07, 0x33, 0xf4, 0x4a, 0x52, 0x8b, 0x4b,
-	0xf4, 0x50, 0xd4, 0xe9, 0x15, 0x97, 0x26, 0x29, 0xb1, 0x70, 0x31, 0xf9, 0x1a, 0x39, 0xb9, 0x46,
-	0x39, 0xa7, 0x67, 0x96, 0x64, 0x94, 0x26, 0xe9, 0x25, 0xe7, 0xe7, 0xea, 0xa7, 0xe7, 0xe7, 0x24,
-	0xe6, 0xa5, 0xeb, 0x83, 0xf5, 0x25, 0x95, 0xa6, 0x41, 0x18, 0xc9, 0xba, 0xe9, 0xa9, 0x79, 0xba,
-	0xe9, 0xf9, 0xfa, 0x20, 0x83, 0x52, 0x12, 0x4b, 0x12, 0xf5, 0x31, 0x2c, 0x4d, 0x62, 0x03, 0xab,
-	0x34, 0x06, 0x04, 0x00, 0x00, 0xff, 0xff, 0x64, 0x42, 0xe4, 0xa8, 0x90, 0x00, 0x00, 0x00,
+	0xf4, 0x50, 0xd4, 0xe9, 0x15, 0x97, 0x26, 0x29, 0xf1, 0x71, 0x31, 0xf9, 0x1a, 0x69, 0x71, 0x70,
+	0x30, 0x0a, 0x34, 0x34, 0x34, 0x34, 0x30, 0x39, 0xb9, 0x46, 0x39, 0xa7, 0x67, 0x96, 0x64, 0x94,
+	0x26, 0xe9, 0x25, 0xe7, 0xe7, 0xea, 0xa7, 0xe7, 0xe7, 0x24, 0xe6, 0xa5, 0xeb, 0x83, 0x4d, 0x48,
+	0x2a, 0x4d, 0x83, 0x30, 0x92, 0x75, 0xd3, 0x53, 0xf3, 0x74, 0xd3, 0xf3, 0xf5, 0x41, 0x46, 0xa6,
+	0x24, 0x96, 0x24, 0xea, 0x63, 0x58, 0x0f, 0x08, 0x00, 0x00, 0xff, 0xff, 0x87, 0x44, 0x22, 0x2d,
+	0x92, 0x00, 0x00, 0x00,
 }

+ 2 - 1
protoc-gen-go/testdata/import_public/sub/b.proto

@@ -29,11 +29,12 @@
 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
-syntax = "proto3";
+syntax = "proto2";
 
 package goproto.test.import_public.sub;
 
 option go_package = "github.com/golang/protobuf/protoc-gen-go/testdata/import_public/sub";
 
 message M2 {
+  extensions 1 to max;
 }

+ 4 - 4
protoc-gen-go/testdata/import_public_test.go

@@ -46,18 +46,18 @@ func TestImportPublicLink(t *testing.T) {
 	var _ mainpb.E = subpb.E(0)
 	_ = &mainpb.Public{
 		M: &mainpb.M{},
-		E: mainpb.E_ZERO,
+		E: mainpb.E_ZERO.Enum(),
 		Local: &mainpb.Local{
 			M: &mainpb.M{},
-			E: mainpb.E_ZERO,
+			E: mainpb.E_ZERO.Enum(),
 		},
 	}
 	_ = &mainpb.Public{
 		M: &subpb.M{},
-		E: subpb.E_ZERO,
+		E: subpb.E_ZERO.Enum(),
 		Local: &mainpb.Local{
 			M: &subpb.M{},
-			E: subpb.E_ZERO,
+			E: subpb.E_ZERO.Enum(),
 		},
 	}
 	_ = &mainpb.M{