diff options
author | Damien Neil <dneil@google.com> | 2018-10-24 14:26:35 -0700 |
---|---|---|
committer | Damien Neil <neild@users.noreply.github.com> | 2018-10-24 15:28:26 -0700 |
commit | 3ed0fc6514d1378a29be51817ec3a195b5e25864 (patch) | |
tree | f75a481e42a55bddaf88e87db600dfe7811873f1 | |
parent | d7fc20193620986259ffb1f9b9da752114ee14a4 (diff) | |
download | golang-protobuf-3ed0fc6514d1378a29be51817ec3a195b5e25864.tar.gz |
protoc-gen-go: add test case for deprecated oneof field
-rw-r--r-- | protoc-gen-go/testdata/deprecated/deprecated.pb.go | 124 | ||||
-rw-r--r-- | protoc-gen-go/testdata/deprecated/deprecated.proto | 5 |
2 files changed, 108 insertions, 21 deletions
diff --git a/protoc-gen-go/testdata/deprecated/deprecated.pb.go b/protoc-gen-go/testdata/deprecated/deprecated.pb.go index fed0a241..f35a4e0a 100644 --- a/protoc-gen-go/testdata/deprecated/deprecated.pb.go +++ b/protoc-gen-go/testdata/deprecated/deprecated.pb.go @@ -84,10 +84,15 @@ var xxx_messageInfo_DeprecatedRequest proto.InternalMessageInfo // Deprecated: Do not use. type DeprecatedResponse struct { // DeprecatedField contains a DeprecatedEnum. - DeprecatedField DeprecatedEnum `protobuf:"varint,1,opt,name=deprecated_field,json=deprecatedField,proto3,enum=deprecated.DeprecatedEnum" json:"deprecated_field,omitempty"` // Deprecated: Do not use. - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` + DeprecatedField DeprecatedEnum `protobuf:"varint,1,opt,name=deprecated_field,json=deprecatedField,proto3,enum=deprecated.DeprecatedEnum" json:"deprecated_field,omitempty"` // Deprecated: Do not use. + // DeprecatedOneof contains a deprecated field. + // + // Types that are valid to be assigned to DeprecatedOneof: + // *DeprecatedResponse_DeprecatedOneofField + DeprecatedOneof isDeprecatedResponse_DeprecatedOneof `protobuf_oneof:"deprecated_oneof"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` } func (m *DeprecatedResponse) Reset() { *m = DeprecatedResponse{} } @@ -123,6 +128,81 @@ func (m *DeprecatedResponse) GetDeprecatedField() DeprecatedEnum { return DeprecatedEnum_DEPRECATED } +type isDeprecatedResponse_DeprecatedOneof interface { + isDeprecatedResponse_DeprecatedOneof() +} + +type DeprecatedResponse_DeprecatedOneofField struct { + DeprecatedOneofField string `protobuf:"bytes,2,opt,name=deprecated_oneof_field,json=deprecatedOneofField,proto3,oneof"` +} + +func (*DeprecatedResponse_DeprecatedOneofField) isDeprecatedResponse_DeprecatedOneof() {} + +func (m *DeprecatedResponse) GetDeprecatedOneof() isDeprecatedResponse_DeprecatedOneof { + if m != nil { + return m.DeprecatedOneof + } + return nil +} + +func (m *DeprecatedResponse) GetDeprecatedOneofField() string { + if x, ok := m.GetDeprecatedOneof().(*DeprecatedResponse_DeprecatedOneofField); ok { + return x.DeprecatedOneofField + } + return "" +} + +// XXX_OneofFuncs is for the internal use of the proto package. +func (*DeprecatedResponse) 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 _DeprecatedResponse_OneofMarshaler, _DeprecatedResponse_OneofUnmarshaler, _DeprecatedResponse_OneofSizer, []interface{}{ + (*DeprecatedResponse_DeprecatedOneofField)(nil), + } +} + +func _DeprecatedResponse_OneofMarshaler(msg proto.Message, b *proto.Buffer) error { + m := msg.(*DeprecatedResponse) + // deprecated_oneof + switch x := m.DeprecatedOneof.(type) { + case *DeprecatedResponse_DeprecatedOneofField: + b.EncodeVarint(2<<3 | proto.WireBytes) + b.EncodeStringBytes(x.DeprecatedOneofField) + case nil: + default: + return fmt.Errorf("DeprecatedResponse.DeprecatedOneof has unexpected type %T", x) + } + return nil +} + +func _DeprecatedResponse_OneofUnmarshaler(msg proto.Message, tag, wire int, b *proto.Buffer) (bool, error) { + m := msg.(*DeprecatedResponse) + switch tag { + case 2: // deprecated_oneof.deprecated_oneof_field + if wire != proto.WireBytes { + return true, proto.ErrInternalBadWireType + } + x, err := b.DecodeStringBytes() + m.DeprecatedOneof = &DeprecatedResponse_DeprecatedOneofField{x} + return true, err + default: + return false, nil + } +} + +func _DeprecatedResponse_OneofSizer(msg proto.Message) (n int) { + m := msg.(*DeprecatedResponse) + // deprecated_oneof + switch x := m.DeprecatedOneof.(type) { + case *DeprecatedResponse_DeprecatedOneofField: + n += 1 // tag and wire + n += proto.SizeVarint(uint64(len(x.DeprecatedOneofField))) + n += len(x.DeprecatedOneofField) + case nil: + default: + panic(fmt.Sprintf("proto: unexpected type %T in oneof", x)) + } + return n +} + func init() { proto.RegisterEnum("deprecated.DeprecatedEnum", DeprecatedEnum_name, DeprecatedEnum_value) proto.RegisterType((*DeprecatedRequest)(nil), "deprecated.DeprecatedRequest") @@ -132,23 +212,25 @@ func init() { func init() { proto.RegisterFile("deprecated/deprecated.proto", fileDescriptor_f64ba265cd7eae3f) } var fileDescriptor_f64ba265cd7eae3f = []byte{ - // 248 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x92, 0x4e, 0x49, 0x2d, 0x28, - 0x4a, 0x4d, 0x4e, 0x2c, 0x49, 0x4d, 0xd1, 0x47, 0x30, 0xf5, 0x0a, 0x8a, 0xf2, 0x4b, 0xf2, 0x85, - 0xb8, 0x10, 0x22, 0x4a, 0xe2, 0x5c, 0x82, 0x2e, 0x70, 0x5e, 0x50, 0x6a, 0x61, 0x69, 0x6a, 0x71, - 0x89, 0x15, 0x93, 0x04, 0xa3, 0x52, 0x32, 0x97, 0x10, 0xb2, 0x44, 0x71, 0x41, 0x7e, 0x5e, 0x71, - 0xaa, 0x90, 0x27, 0x97, 0x00, 0x42, 0x73, 0x7c, 0x5a, 0x66, 0x6a, 0x4e, 0x8a, 0x04, 0xa3, 0x02, - 0xa3, 0x06, 0x9f, 0x91, 0x94, 0x1e, 0x92, 0x3d, 0x08, 0x9d, 0xae, 0x79, 0xa5, 0xb9, 0x4e, 0x4c, - 0x12, 0x8c, 0x41, 0xfc, 0x08, 0x69, 0x37, 0x90, 0x36, 0x90, 0x25, 0x5a, 0x1a, 0x5c, 0x7c, 0xa8, - 0x4a, 0x85, 0x84, 0xb8, 0xb8, 0x5c, 0x5c, 0x03, 0x82, 0x5c, 0x9d, 0x1d, 0x43, 0x5c, 0x5d, 0x04, - 0x18, 0xa4, 0x98, 0x38, 0x18, 0xa5, 0x98, 0x24, 0x18, 0x8d, 0xf2, 0x90, 0xdd, 0x19, 0x9c, 0x5a, - 0x54, 0x96, 0x99, 0x9c, 0x2a, 0x14, 0x82, 0xac, 0xdd, 0x39, 0x31, 0x27, 0x47, 0x48, 0x16, 0xbb, - 0x2b, 0xa0, 0x1e, 0x93, 0x92, 0xc3, 0x25, 0x0d, 0xf1, 0x9e, 0x12, 0x73, 0x07, 0x13, 0xa3, 0x14, - 0x88, 0x70, 0x72, 0x8c, 0xb2, 0x49, 0xcf, 0x2c, 0xc9, 0x28, 0x4d, 0xd2, 0x4b, 0xce, 0xcf, 0xd5, - 0x4f, 0xcf, 0xcf, 0x49, 0xcc, 0x4b, 0xd7, 0x07, 0x07, 0x5f, 0x52, 0x69, 0x1a, 0x84, 0x91, 0xac, - 0x9b, 0x9e, 0x9a, 0xa7, 0x9b, 0x9e, 0xaf, 0x5f, 0x92, 0x5a, 0x5c, 0x92, 0x92, 0x58, 0x92, 0x88, - 0x14, 0xd2, 0x3b, 0x18, 0x19, 0x93, 0xd8, 0xc0, 0xaa, 0x8c, 0x01, 0x01, 0x00, 0x00, 0xff, 0xff, - 0x0e, 0xf5, 0x6c, 0x87, 0x8c, 0x01, 0x00, 0x00, + // 287 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x74, 0x91, 0xcd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, 0x05, 0x73, 0x6e, 0x0e, 0xfe, 0x84, 0xed, 0x7b, 0x95, 0x21, 0x5b, 0x9b, 0xf8, + 0x2a, 0xa9, 0x6b, 0x76, 0xf1, 0xfb, 0x54, 0xbb, 0x4d, 0xd9, 0x97, 0x7f, 0xc9, 0xdb, 0x75, 0x39, + 0xff, 0x3e, 0x08, 0xd8, 0xea, 0x13, 0x2c, 0x9f, 0x6f, 0xca, 0x4a, 0xbe, 0xf6, 0xa9, 0x97, 0x89, + 0x8d, 0x5f, 0x8a, 0x3a, 0xe1, 0xa5, 0x3f, 0xdc, 0x23, 0xed, 0x8b, 0x6d, 0x90, 0xcd, 0x4a, 0xe4, + 0xb3, 0x52, 0xf8, 0x12, 0x3b, 0x99, 0x27, 0x32, 0x31, 0x4e, 0xf7, 0x05, 0x90, 0xfe, 0x1f, 0x5c, + 0xd7, 0xdf, 0x01, 0x00, 0x00, 0xff, 0xff, 0x08, 0xd5, 0xa0, 0x89, 0xdd, 0x01, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. diff --git a/protoc-gen-go/testdata/deprecated/deprecated.proto b/protoc-gen-go/testdata/deprecated/deprecated.proto index b314166d..192b1582 100644 --- a/protoc-gen-go/testdata/deprecated/deprecated.proto +++ b/protoc-gen-go/testdata/deprecated/deprecated.proto @@ -49,6 +49,11 @@ message DeprecatedResponse { option deprecated = true; // DeprecatedField contains a DeprecatedEnum. DeprecatedEnum deprecated_field = 1 [deprecated=true]; + // DeprecatedOneof contains a deprecated field. + oneof deprecated_oneof { + // DeprecatedOneofField is a deprecated field. + string deprecated_oneof_field = 2 [deprecated=true]; + } } // DeprecatedEnum contains deprecated values. |