From 712ed9f90677d3c47970b3395f261db2cf1c89ec Mon Sep 17 00:00:00 2001 From: Kazuyoshi Kato Date: Wed, 16 Feb 2022 22:32:47 +0000 Subject: [PATCH] Use google.golang.org/protobuf instead of github.com/gogo/protobuf This change replaces github.com/gogo/protobuf with google.golang.org/protobuf, except for the code generators. All proto-encoded structs are now generated from .proto files, which include ttrpc.Request and ttrpc.Response. Signed-off-by: Kazuyoshi Kato --- .github/workflows/ci.yml | 13 +- Protobuild.toml | 19 + client.go | 2 +- client_test.go | 4 +- codec.go | 2 +- example/Protobuild.toml | 17 +- example/cmd/main.go | 6 +- example/example.pb.go | 1024 ++++++++--------------------------- example/example.proto | 1 - example/example_ttrpc.pb.go | 57 ++ go.mod | 1 + internal/test.pb.go | 164 ++++++ proto/status.proto | 5 + request.pb.go | 396 ++++++++++++++ request.proto | 29 + server_linux_test.go | 7 +- server_test.go | 81 +-- services.go | 2 +- test.proto | 11 + types.go | 61 --- 20 files changed, 982 insertions(+), 920 deletions(-) create mode 100644 Protobuild.toml create mode 100644 example/example_ttrpc.pb.go create mode 100644 internal/test.pb.go create mode 100644 proto/status.proto create mode 100644 request.pb.go create mode 100644 request.proto create mode 100644 test.proto delete mode 100644 types.go diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a1bf74128..4902d1cda 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -120,23 +120,20 @@ jobs: sudo chmod -R go+rX /usr/local/include sudo chmod go+x /usr/local/bin/protoc - - name: Install gogo/protobuf + - name: Install protoc-gen-go run: | - cd $GOPATH/src - mkdir -p github.com/gogo - cd github.com/gogo - git clone --depth 1 --branch v1.3.2 https://github.com/gogo/protobuf + go install google.golang.org/protobuf/cmd/protoc-gen-go@v1.27.1 - - name: Build protoc-gen-gogottrpc + - name: Build protoc-gen-go-ttrpc working-directory: src/github.com/containerd/ttrpc run: | - go build ./cmd/protoc-gen-gogottrpc + go build ./cmd/protoc-gen-go-ttrpc - name: Run Protobuild working-directory: src/github.com/containerd/ttrpc run: | export PATH=$GOPATH/bin:$PWD:$PATH go install github.com/containerd/protobuild@7e5ee24bc1f70e9e289fef15e2631eb3491320bf - cd example protobuild + (cd example && protobuild) git diff --exit-code diff --git a/Protobuild.toml b/Protobuild.toml new file mode 100644 index 000000000..d2aba1f72 --- /dev/null +++ b/Protobuild.toml @@ -0,0 +1,19 @@ +version = "2" +generators = ["go"] + +# Control protoc include paths. Below are usually some good defaults, but feel +# free to try it without them if it works for your project. +[includes] + # Include paths that will be added before all others. Typically, you want to + # treat the root of the project as an include, but this may not be necessary. + before = ["."] + + # Paths that will be added untouched to the end of the includes. We use + # `/usr/local/include` to pickup the common install location of protobuf. + # This is the default. + after = ["/usr/local/include"] + +# This section maps protobuf imports to Go packages. These will become +# `-M` directives in the call to the go protobuf generator. +[packages] + "proto/status.proto" = "google.golang.org/genproto/googleapis/rpc/status" diff --git a/client.go b/client.go index d755a1469..3e98847f4 100644 --- a/client.go +++ b/client.go @@ -27,10 +27,10 @@ import ( "syscall" "time" - "github.com/gogo/protobuf/proto" "github.com/sirupsen/logrus" "google.golang.org/grpc/codes" "google.golang.org/grpc/status" + "google.golang.org/protobuf/proto" ) // ErrClosed is returned by client methods when the underlying connection is diff --git a/client_test.go b/client_test.go index 779d744f0..5c9f10a92 100644 --- a/client_test.go +++ b/client_test.go @@ -20,6 +20,8 @@ import ( "context" "testing" "time" + + "github.com/containerd/ttrpc/internal" ) func TestUserOnCloseWait(t *testing.T) { @@ -46,7 +48,7 @@ func TestUserOnCloseWait(t *testing.T) { }), ) - tp testPayload + tp internal.TestPayload tclient = newTestingClient(client) ) diff --git a/codec.go b/codec.go index 880634c27..3e82722a4 100644 --- a/codec.go +++ b/codec.go @@ -19,7 +19,7 @@ package ttrpc import ( "fmt" - "github.com/gogo/protobuf/proto" + "google.golang.org/protobuf/proto" ) type codec struct{} diff --git a/example/Protobuild.toml b/example/Protobuild.toml index d66a4df51..03ed2edb4 100644 --- a/example/Protobuild.toml +++ b/example/Protobuild.toml @@ -1,6 +1,5 @@ -version = "unstable" -generator = "gogottrpc" -plugins = ["ttrpc"] +version = "2" +generators = ["go", "go-ttrpc"] # Control protoc include paths. Below are usually some good defaults, but feel # free to try it without them if it works for your project. @@ -9,11 +8,6 @@ plugins = ["ttrpc"] # treat the root of the project as an include, but this may not be necessary. # before = ["./protobuf"] - # Paths that should be treated as include roots in relation to the vendor - # directory. These will be calculated with the vendor directory nearest the - # target package. - packages = ["github.com/gogo/protobuf"] - # Paths that will be added untouched to the end of the includes. We use # `/usr/local/include` to pickup the common install location of protobuf. # This is the default. @@ -22,11 +16,4 @@ plugins = ["ttrpc"] # This section maps protobuf imports to Go packages. These will become # `-M` directives in the call to the go protobuf generator. [packages] - "gogoproto/gogo.proto" = "github.com/gogo/protobuf/gogoproto" - "google/protobuf/any.proto" = "github.com/gogo/protobuf/types" - "google/protobuf/empty.proto" = "github.com/gogo/protobuf/types" - "google/protobuf/descriptor.proto" = "github.com/gogo/protobuf/protoc-gen-gogo/descriptor" - "google/protobuf/field_mask.proto" = "github.com/gogo/protobuf/types" - "google/protobuf/timestamp.proto" = "github.com/gogo/protobuf/types" - "google/protobuf/duration.proto" = "github.com/gogo/protobuf/types" "google/rpc/status.proto" = "github.com/containerd/containerd/protobuf/google/rpc" diff --git a/example/cmd/main.go b/example/cmd/main.go index da924ebd3..8c83c2c99 100644 --- a/example/cmd/main.go +++ b/example/cmd/main.go @@ -26,7 +26,7 @@ import ( ttrpc "github.com/containerd/ttrpc" "github.com/containerd/ttrpc/example" - "github.com/gogo/protobuf/types" + "google.golang.org/protobuf/types/known/emptypb" ) const socket = "example-ttrpc-server" @@ -130,6 +130,6 @@ func (s *exampleServer) Method1(ctx context.Context, r *example.Method1Request) }, nil } -func (s *exampleServer) Method2(ctx context.Context, r *example.Method1Request) (*types.Empty, error) { - return &types.Empty{}, nil +func (s *exampleServer) Method2(ctx context.Context, r *example.Method1Request) (*emptypb.Empty, error) { + return &emptypb.Empty{}, nil } diff --git a/example/example.pb.go b/example/example.pb.go index 530638dd0..264d3fbf9 100644 --- a/example/example.pb.go +++ b/example/example.pb.go @@ -1,860 +1,308 @@ -// Code generated by protoc-gen-gogo. DO NOT EDIT. +// Code generated by protoc-gen-go. DO NOT EDIT. +// versions: +// protoc-gen-go v1.27.1 +// protoc v3.5.0 // source: github.com/containerd/ttrpc/example/example.proto package example import ( - context "context" - fmt "fmt" - github_com_containerd_ttrpc "github.com/containerd/ttrpc" - _ "github.com/gogo/protobuf/gogoproto" - proto "github.com/gogo/protobuf/proto" - types "github.com/gogo/protobuf/types" - io "io" - math "math" - math_bits "math/bits" + empty "github.com/golang/protobuf/ptypes/empty" + protoreflect "google.golang.org/protobuf/reflect/protoreflect" + protoimpl "google.golang.org/protobuf/runtime/protoimpl" reflect "reflect" - strings "strings" + sync "sync" ) -// Reference imports to suppress errors if they are not otherwise used. -var _ = proto.Marshal -var _ = fmt.Errorf -var _ = math.Inf - -// This is a compile-time assertion to ensure that this generated file -// is compatible with the proto package it is being compiled against. -// A compilation error at this line likely means your copy of the -// proto package needs to be updated. -const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package +const ( + // Verify that this generated code is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) + // Verify that runtime/protoimpl is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) +) type Method1Request struct { - Foo string `protobuf:"bytes,1,opt,name=foo,proto3" json:"foo,omitempty"` - Bar string `protobuf:"bytes,2,opt,name=bar,proto3" json:"bar,omitempty"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` -} + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields -func (m *Method1Request) Reset() { *m = Method1Request{} } -func (*Method1Request) ProtoMessage() {} -func (*Method1Request) Descriptor() ([]byte, []int) { - return fileDescriptor_d5b23bbed948ff84, []int{0} -} -func (m *Method1Request) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *Method1Request) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_Method1Request.Marshal(b, m, deterministic) - } else { - b = b[:cap(b)] - n, err := m.MarshalToSizedBuffer(b) - if err != nil { - return nil, err - } - return b[:n], nil - } -} -func (m *Method1Request) XXX_Merge(src proto.Message) { - xxx_messageInfo_Method1Request.Merge(m, src) -} -func (m *Method1Request) XXX_Size() int { - return m.Size() -} -func (m *Method1Request) XXX_DiscardUnknown() { - xxx_messageInfo_Method1Request.DiscardUnknown(m) -} - -var xxx_messageInfo_Method1Request proto.InternalMessageInfo - -type Method1Response struct { - Foo string `protobuf:"bytes,1,opt,name=foo,proto3" json:"foo,omitempty"` - Bar string `protobuf:"bytes,2,opt,name=bar,proto3" json:"bar,omitempty"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` + Foo string `protobuf:"bytes,1,opt,name=foo,proto3" json:"foo,omitempty"` + Bar string `protobuf:"bytes,2,opt,name=bar,proto3" json:"bar,omitempty"` } -func (m *Method1Response) Reset() { *m = Method1Response{} } -func (*Method1Response) ProtoMessage() {} -func (*Method1Response) Descriptor() ([]byte, []int) { - return fileDescriptor_d5b23bbed948ff84, []int{1} -} -func (m *Method1Response) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *Method1Response) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_Method1Response.Marshal(b, m, deterministic) - } else { - b = b[:cap(b)] - n, err := m.MarshalToSizedBuffer(b) - if err != nil { - return nil, err - } - return b[:n], nil +func (x *Method1Request) Reset() { + *x = Method1Request{} + if protoimpl.UnsafeEnabled { + mi := &file_github_com_containerd_ttrpc_example_example_proto_msgTypes[0] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) } } -func (m *Method1Response) XXX_Merge(src proto.Message) { - xxx_messageInfo_Method1Response.Merge(m, src) -} -func (m *Method1Response) XXX_Size() int { - return m.Size() -} -func (m *Method1Response) XXX_DiscardUnknown() { - xxx_messageInfo_Method1Response.DiscardUnknown(m) -} -var xxx_messageInfo_Method1Response proto.InternalMessageInfo - -type Method2Request struct { - Action string `protobuf:"bytes,1,opt,name=action,proto3" json:"action,omitempty"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` +func (x *Method1Request) String() string { + return protoimpl.X.MessageStringOf(x) } -func (m *Method2Request) Reset() { *m = Method2Request{} } -func (*Method2Request) ProtoMessage() {} -func (*Method2Request) Descriptor() ([]byte, []int) { - return fileDescriptor_d5b23bbed948ff84, []int{2} -} -func (m *Method2Request) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *Method2Request) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_Method2Request.Marshal(b, m, deterministic) - } else { - b = b[:cap(b)] - n, err := m.MarshalToSizedBuffer(b) - if err != nil { - return nil, err +func (*Method1Request) ProtoMessage() {} + +func (x *Method1Request) ProtoReflect() protoreflect.Message { + mi := &file_github_com_containerd_ttrpc_example_example_proto_msgTypes[0] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) } - return b[:n], nil + return ms } -} -func (m *Method2Request) XXX_Merge(src proto.Message) { - xxx_messageInfo_Method2Request.Merge(m, src) -} -func (m *Method2Request) XXX_Size() int { - return m.Size() -} -func (m *Method2Request) XXX_DiscardUnknown() { - xxx_messageInfo_Method2Request.DiscardUnknown(m) -} - -var xxx_messageInfo_Method2Request proto.InternalMessageInfo - -func init() { - proto.RegisterType((*Method1Request)(nil), "ttrpc.example.v1.Method1Request") - proto.RegisterType((*Method1Response)(nil), "ttrpc.example.v1.Method1Response") - proto.RegisterType((*Method2Request)(nil), "ttrpc.example.v1.Method2Request") -} - -func init() { - proto.RegisterFile("github.com/containerd/ttrpc/example/example.proto", fileDescriptor_d5b23bbed948ff84) + return mi.MessageOf(x) } -var fileDescriptor_d5b23bbed948ff84 = []byte{ - // 279 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x32, 0x4c, 0xcf, 0x2c, 0xc9, - 0x28, 0x4d, 0xd2, 0x4b, 0xce, 0xcf, 0xd5, 0x4f, 0xce, 0xcf, 0x2b, 0x49, 0xcc, 0xcc, 0x4b, 0x2d, - 0x4a, 0xd1, 0x2f, 0x29, 0x29, 0x2a, 0x48, 0xd6, 0x4f, 0xad, 0x48, 0xcc, 0x2d, 0xc8, 0x49, 0x85, - 0xd1, 0x7a, 0x05, 0x45, 0xf9, 0x25, 0xf9, 0x42, 0x02, 0x60, 0x49, 0x3d, 0x98, 0x60, 0x99, 0xa1, - 0x94, 0x74, 0x7a, 0x7e, 0x7e, 0x7a, 0x4e, 0xaa, 0x3e, 0x58, 0x3e, 0xa9, 0x34, 0x4d, 0x3f, 0x35, - 0xb7, 0xa0, 0xa4, 0x12, 0xa2, 0x5c, 0x4a, 0x24, 0x3d, 0x3f, 0x3d, 0x1f, 0xcc, 0xd4, 0x07, 0xb1, - 0x20, 0xa2, 0x4a, 0x26, 0x5c, 0x7c, 0xbe, 0xa9, 0x25, 0x19, 0xf9, 0x29, 0x86, 0x41, 0xa9, 0x85, - 0xa5, 0xa9, 0xc5, 0x25, 0x42, 0x02, 0x5c, 0xcc, 0x69, 0xf9, 0xf9, 0x12, 0x8c, 0x0a, 0x8c, 0x1a, - 0x9c, 0x41, 0x20, 0x26, 0x48, 0x24, 0x29, 0xb1, 0x48, 0x82, 0x09, 0x22, 0x92, 0x94, 0x58, 0xa4, - 0x64, 0xca, 0xc5, 0x0f, 0xd7, 0x55, 0x5c, 0x90, 0x9f, 0x57, 0x9c, 0x4a, 0x94, 0x36, 0x0d, 0x98, - 0x65, 0x46, 0x30, 0xcb, 0xc4, 0xb8, 0xd8, 0x12, 0x93, 0x4b, 0x32, 0xf3, 0xf3, 0xa0, 0x1a, 0xa1, - 0x3c, 0xa3, 0x79, 0x8c, 0x5c, 0xec, 0xae, 0x10, 0x8f, 0x09, 0xf9, 0x71, 0xb1, 0x43, 0x2d, 0x13, - 0x52, 0xd0, 0x43, 0xf7, 0xb3, 0x1e, 0xaa, 0xeb, 0xa5, 0x14, 0xf1, 0xa8, 0x80, 0xba, 0xd4, 0x19, - 0x66, 0x9e, 0x11, 0x11, 0xe6, 0x89, 0xe9, 0x41, 0xc2, 0x54, 0x0f, 0x16, 0xa6, 0x7a, 0xae, 0xa0, - 0x30, 0x75, 0x72, 0x3d, 0xf1, 0x50, 0x8e, 0xe1, 0xc6, 0x43, 0x39, 0x86, 0x86, 0x47, 0x72, 0x8c, - 0x27, 0x1e, 0xc9, 0x31, 0x5e, 0x78, 0x24, 0xc7, 0xf8, 0xe0, 0x91, 0x1c, 0x63, 0x94, 0x36, 0x11, - 0x31, 0x69, 0x0d, 0xa5, 0x93, 0xd8, 0xc0, 0xc6, 0x1a, 0x03, 0x02, 0x00, 0x00, 0xff, 0xff, 0x4a, - 0xc9, 0x2c, 0xdc, 0xff, 0x01, 0x00, 0x00, +// Deprecated: Use Method1Request.ProtoReflect.Descriptor instead. +func (*Method1Request) Descriptor() ([]byte, []int) { + return file_github_com_containerd_ttrpc_example_example_proto_rawDescGZIP(), []int{0} } -func (m *Method1Request) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalToSizedBuffer(dAtA[:size]) - if err != nil { - return nil, err +func (x *Method1Request) GetFoo() string { + if x != nil { + return x.Foo } - return dAtA[:n], nil -} - -func (m *Method1Request) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) + return "" } -func (m *Method1Request) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - if m.XXX_unrecognized != nil { - i -= len(m.XXX_unrecognized) - copy(dAtA[i:], m.XXX_unrecognized) - } - if len(m.Bar) > 0 { - i -= len(m.Bar) - copy(dAtA[i:], m.Bar) - i = encodeVarintExample(dAtA, i, uint64(len(m.Bar))) - i-- - dAtA[i] = 0x12 - } - if len(m.Foo) > 0 { - i -= len(m.Foo) - copy(dAtA[i:], m.Foo) - i = encodeVarintExample(dAtA, i, uint64(len(m.Foo))) - i-- - dAtA[i] = 0xa +func (x *Method1Request) GetBar() string { + if x != nil { + return x.Bar } - return len(dAtA) - i, nil + return "" } -func (m *Method1Response) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalToSizedBuffer(dAtA[:size]) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} +type Method1Response struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields -func (m *Method1Response) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) + Foo string `protobuf:"bytes,1,opt,name=foo,proto3" json:"foo,omitempty"` + Bar string `protobuf:"bytes,2,opt,name=bar,proto3" json:"bar,omitempty"` } -func (m *Method1Response) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - if m.XXX_unrecognized != nil { - i -= len(m.XXX_unrecognized) - copy(dAtA[i:], m.XXX_unrecognized) +func (x *Method1Response) Reset() { + *x = Method1Response{} + if protoimpl.UnsafeEnabled { + mi := &file_github_com_containerd_ttrpc_example_example_proto_msgTypes[1] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) } - if len(m.Bar) > 0 { - i -= len(m.Bar) - copy(dAtA[i:], m.Bar) - i = encodeVarintExample(dAtA, i, uint64(len(m.Bar))) - i-- - dAtA[i] = 0x12 - } - if len(m.Foo) > 0 { - i -= len(m.Foo) - copy(dAtA[i:], m.Foo) - i = encodeVarintExample(dAtA, i, uint64(len(m.Foo))) - i-- - dAtA[i] = 0xa - } - return len(dAtA) - i, nil } -func (m *Method2Request) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalToSizedBuffer(dAtA[:size]) - if err != nil { - return nil, err - } - return dAtA[:n], nil +func (x *Method1Response) String() string { + return protoimpl.X.MessageStringOf(x) } -func (m *Method2Request) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} +func (*Method1Response) ProtoMessage() {} -func (m *Method2Request) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - if m.XXX_unrecognized != nil { - i -= len(m.XXX_unrecognized) - copy(dAtA[i:], m.XXX_unrecognized) - } - if len(m.Action) > 0 { - i -= len(m.Action) - copy(dAtA[i:], m.Action) - i = encodeVarintExample(dAtA, i, uint64(len(m.Action))) - i-- - dAtA[i] = 0xa +func (x *Method1Response) ProtoReflect() protoreflect.Message { + mi := &file_github_com_containerd_ttrpc_example_example_proto_msgTypes[1] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms } - return len(dAtA) - i, nil + return mi.MessageOf(x) } -func encodeVarintExample(dAtA []byte, offset int, v uint64) int { - offset -= sovExample(v) - base := offset - for v >= 1<<7 { - dAtA[offset] = uint8(v&0x7f | 0x80) - v >>= 7 - offset++ - } - dAtA[offset] = uint8(v) - return base -} -func (m *Method1Request) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - l = len(m.Foo) - if l > 0 { - n += 1 + l + sovExample(uint64(l)) - } - l = len(m.Bar) - if l > 0 { - n += 1 + l + sovExample(uint64(l)) - } - if m.XXX_unrecognized != nil { - n += len(m.XXX_unrecognized) - } - return n +// Deprecated: Use Method1Response.ProtoReflect.Descriptor instead. +func (*Method1Response) Descriptor() ([]byte, []int) { + return file_github_com_containerd_ttrpc_example_example_proto_rawDescGZIP(), []int{1} } -func (m *Method1Response) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - l = len(m.Foo) - if l > 0 { - n += 1 + l + sovExample(uint64(l)) +func (x *Method1Response) GetFoo() string { + if x != nil { + return x.Foo } - l = len(m.Bar) - if l > 0 { - n += 1 + l + sovExample(uint64(l)) - } - if m.XXX_unrecognized != nil { - n += len(m.XXX_unrecognized) - } - return n + return "" } -func (m *Method2Request) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - l = len(m.Action) - if l > 0 { - n += 1 + l + sovExample(uint64(l)) +func (x *Method1Response) GetBar() string { + if x != nil { + return x.Bar } - if m.XXX_unrecognized != nil { - n += len(m.XXX_unrecognized) - } - return n + return "" } -func sovExample(x uint64) (n int) { - return (math_bits.Len64(x|1) + 6) / 7 -} -func sozExample(x uint64) (n int) { - return sovExample(uint64((x << 1) ^ uint64((int64(x) >> 63)))) -} -func (this *Method1Request) String() string { - if this == nil { - return "nil" - } - s := strings.Join([]string{`&Method1Request{`, - `Foo:` + fmt.Sprintf("%v", this.Foo) + `,`, - `Bar:` + fmt.Sprintf("%v", this.Bar) + `,`, - `XXX_unrecognized:` + fmt.Sprintf("%v", this.XXX_unrecognized) + `,`, - `}`, - }, "") - return s -} -func (this *Method1Response) String() string { - if this == nil { - return "nil" - } - s := strings.Join([]string{`&Method1Response{`, - `Foo:` + fmt.Sprintf("%v", this.Foo) + `,`, - `Bar:` + fmt.Sprintf("%v", this.Bar) + `,`, - `XXX_unrecognized:` + fmt.Sprintf("%v", this.XXX_unrecognized) + `,`, - `}`, - }, "") - return s -} -func (this *Method2Request) String() string { - if this == nil { - return "nil" - } - s := strings.Join([]string{`&Method2Request{`, - `Action:` + fmt.Sprintf("%v", this.Action) + `,`, - `XXX_unrecognized:` + fmt.Sprintf("%v", this.XXX_unrecognized) + `,`, - `}`, - }, "") - return s -} -func valueToStringExample(v interface{}) string { - rv := reflect.ValueOf(v) - if rv.IsNil() { - return "nil" - } - pv := reflect.Indirect(rv).Interface() - return fmt.Sprintf("*%v", pv) -} +type Method2Request struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields -type ExampleService interface { - Method1(ctx context.Context, req *Method1Request) (*Method1Response, error) - Method2(ctx context.Context, req *Method1Request) (*types.Empty, error) + Action string `protobuf:"bytes,1,opt,name=action,proto3" json:"action,omitempty"` } -func RegisterExampleService(srv *github_com_containerd_ttrpc.Server, svc ExampleService) { - srv.Register("ttrpc.example.v1.Example", map[string]github_com_containerd_ttrpc.Method{ - "Method1": func(ctx context.Context, unmarshal func(interface{}) error) (interface{}, error) { - var req Method1Request - if err := unmarshal(&req); err != nil { - return nil, err - } - return svc.Method1(ctx, &req) - }, - "Method2": func(ctx context.Context, unmarshal func(interface{}) error) (interface{}, error) { - var req Method1Request - if err := unmarshal(&req); err != nil { - return nil, err - } - return svc.Method2(ctx, &req) - }, - }) +func (x *Method2Request) Reset() { + *x = Method2Request{} + if protoimpl.UnsafeEnabled { + mi := &file_github_com_containerd_ttrpc_example_example_proto_msgTypes[2] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } } -type exampleClient struct { - client *github_com_containerd_ttrpc.Client +func (x *Method2Request) String() string { + return protoimpl.X.MessageStringOf(x) } -func NewExampleClient(client *github_com_containerd_ttrpc.Client) ExampleService { - return &exampleClient{ - client: client, - } -} +func (*Method2Request) ProtoMessage() {} -func (c *exampleClient) Method1(ctx context.Context, req *Method1Request) (*Method1Response, error) { - var resp Method1Response - if err := c.client.Call(ctx, "ttrpc.example.v1.Example", "Method1", req, &resp); err != nil { - return nil, err +func (x *Method2Request) ProtoReflect() protoreflect.Message { + mi := &file_github_com_containerd_ttrpc_example_example_proto_msgTypes[2] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms } - return &resp, nil + return mi.MessageOf(x) } -func (c *exampleClient) Method2(ctx context.Context, req *Method1Request) (*types.Empty, error) { - var resp types.Empty - if err := c.client.Call(ctx, "ttrpc.example.v1.Example", "Method2", req, &resp); err != nil { - return nil, err - } - return &resp, nil +// Deprecated: Use Method2Request.ProtoReflect.Descriptor instead. +func (*Method2Request) Descriptor() ([]byte, []int) { + return file_github_com_containerd_ttrpc_example_example_proto_rawDescGZIP(), []int{2} +} + +func (x *Method2Request) GetAction() string { + if x != nil { + return x.Action + } + return "" +} + +var File_github_com_containerd_ttrpc_example_example_proto protoreflect.FileDescriptor + +var file_github_com_containerd_ttrpc_example_example_proto_rawDesc = []byte{ + 0x0a, 0x31, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x63, 0x6f, 0x6e, + 0x74, 0x61, 0x69, 0x6e, 0x65, 0x72, 0x64, 0x2f, 0x74, 0x74, 0x72, 0x70, 0x63, 0x2f, 0x65, 0x78, + 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x2f, 0x65, 0x78, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x2e, 0x70, 0x72, + 0x6f, 0x74, 0x6f, 0x12, 0x10, 0x74, 0x74, 0x72, 0x70, 0x63, 0x2e, 0x65, 0x78, 0x61, 0x6d, 0x70, + 0x6c, 0x65, 0x2e, 0x76, 0x31, 0x1a, 0x1b, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2f, 0x70, 0x72, + 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2f, 0x65, 0x6d, 0x70, 0x74, 0x79, 0x2e, 0x70, 0x72, 0x6f, + 0x74, 0x6f, 0x22, 0x34, 0x0a, 0x0e, 0x4d, 0x65, 0x74, 0x68, 0x6f, 0x64, 0x31, 0x52, 0x65, 0x71, + 0x75, 0x65, 0x73, 0x74, 0x12, 0x10, 0x0a, 0x03, 0x66, 0x6f, 0x6f, 0x18, 0x01, 0x20, 0x01, 0x28, + 0x09, 0x52, 0x03, 0x66, 0x6f, 0x6f, 0x12, 0x10, 0x0a, 0x03, 0x62, 0x61, 0x72, 0x18, 0x02, 0x20, + 0x01, 0x28, 0x09, 0x52, 0x03, 0x62, 0x61, 0x72, 0x22, 0x35, 0x0a, 0x0f, 0x4d, 0x65, 0x74, 0x68, + 0x6f, 0x64, 0x31, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x10, 0x0a, 0x03, 0x66, + 0x6f, 0x6f, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x66, 0x6f, 0x6f, 0x12, 0x10, 0x0a, + 0x03, 0x62, 0x61, 0x72, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x62, 0x61, 0x72, 0x22, + 0x28, 0x0a, 0x0e, 0x4d, 0x65, 0x74, 0x68, 0x6f, 0x64, 0x32, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, + 0x74, 0x12, 0x16, 0x0a, 0x06, 0x61, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x18, 0x01, 0x20, 0x01, 0x28, + 0x09, 0x52, 0x06, 0x61, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x32, 0x9e, 0x01, 0x0a, 0x07, 0x45, 0x78, + 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x12, 0x4e, 0x0a, 0x07, 0x4d, 0x65, 0x74, 0x68, 0x6f, 0x64, 0x31, + 0x12, 0x20, 0x2e, 0x74, 0x74, 0x72, 0x70, 0x63, 0x2e, 0x65, 0x78, 0x61, 0x6d, 0x70, 0x6c, 0x65, + 0x2e, 0x76, 0x31, 0x2e, 0x4d, 0x65, 0x74, 0x68, 0x6f, 0x64, 0x31, 0x52, 0x65, 0x71, 0x75, 0x65, + 0x73, 0x74, 0x1a, 0x21, 0x2e, 0x74, 0x74, 0x72, 0x70, 0x63, 0x2e, 0x65, 0x78, 0x61, 0x6d, 0x70, + 0x6c, 0x65, 0x2e, 0x76, 0x31, 0x2e, 0x4d, 0x65, 0x74, 0x68, 0x6f, 0x64, 0x31, 0x52, 0x65, 0x73, + 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x43, 0x0a, 0x07, 0x4d, 0x65, 0x74, 0x68, 0x6f, 0x64, 0x32, + 0x12, 0x20, 0x2e, 0x74, 0x74, 0x72, 0x70, 0x63, 0x2e, 0x65, 0x78, 0x61, 0x6d, 0x70, 0x6c, 0x65, + 0x2e, 0x76, 0x31, 0x2e, 0x4d, 0x65, 0x74, 0x68, 0x6f, 0x64, 0x31, 0x52, 0x65, 0x71, 0x75, 0x65, + 0x73, 0x74, 0x1a, 0x16, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, + 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x42, 0x2d, 0x5a, 0x2b, 0x67, 0x69, + 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x63, 0x6f, 0x6e, 0x74, 0x61, 0x69, 0x6e, + 0x65, 0x72, 0x64, 0x2f, 0x74, 0x74, 0x72, 0x70, 0x63, 0x2f, 0x65, 0x78, 0x61, 0x6d, 0x70, 0x6c, + 0x65, 0x3b, 0x65, 0x78, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, + 0x33, } -func (m *Method1Request) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowExample - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: Method1Request: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: Method1Request: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Foo", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowExample - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthExample - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return ErrInvalidLengthExample - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Foo = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 2: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Bar", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowExample - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthExample - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return ErrInvalidLengthExample - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Bar = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipExample(dAtA[iNdEx:]) - if err != nil { - return err - } - if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLengthExample - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - m.XXX_unrecognized = append(m.XXX_unrecognized, dAtA[iNdEx:iNdEx+skippy]...) - iNdEx += skippy - } - } - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *Method1Response) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowExample - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: Method1Response: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: Method1Response: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Foo", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowExample - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthExample - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return ErrInvalidLengthExample - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Foo = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 2: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Bar", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowExample - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthExample - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return ErrInvalidLengthExample - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Bar = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipExample(dAtA[iNdEx:]) - if err != nil { - return err - } - if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLengthExample - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - m.XXX_unrecognized = append(m.XXX_unrecognized, dAtA[iNdEx:iNdEx+skippy]...) - iNdEx += skippy - } - } +var ( + file_github_com_containerd_ttrpc_example_example_proto_rawDescOnce sync.Once + file_github_com_containerd_ttrpc_example_example_proto_rawDescData = file_github_com_containerd_ttrpc_example_example_proto_rawDesc +) - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *Method2Request) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowExample - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: Method2Request: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: Method2Request: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Action", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowExample - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthExample - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return ErrInvalidLengthExample - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Action = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipExample(dAtA[iNdEx:]) - if err != nil { - return err - } - if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLengthExample - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF +func file_github_com_containerd_ttrpc_example_example_proto_rawDescGZIP() []byte { + file_github_com_containerd_ttrpc_example_example_proto_rawDescOnce.Do(func() { + file_github_com_containerd_ttrpc_example_example_proto_rawDescData = protoimpl.X.CompressGZIP(file_github_com_containerd_ttrpc_example_example_proto_rawDescData) + }) + return file_github_com_containerd_ttrpc_example_example_proto_rawDescData +} + +var file_github_com_containerd_ttrpc_example_example_proto_msgTypes = make([]protoimpl.MessageInfo, 3) +var file_github_com_containerd_ttrpc_example_example_proto_goTypes = []interface{}{ + (*Method1Request)(nil), // 0: ttrpc.example.v1.Method1Request + (*Method1Response)(nil), // 1: ttrpc.example.v1.Method1Response + (*Method2Request)(nil), // 2: ttrpc.example.v1.Method2Request + (*empty.Empty)(nil), // 3: google.protobuf.Empty +} +var file_github_com_containerd_ttrpc_example_example_proto_depIdxs = []int32{ + 0, // 0: ttrpc.example.v1.Example.Method1:input_type -> ttrpc.example.v1.Method1Request + 0, // 1: ttrpc.example.v1.Example.Method2:input_type -> ttrpc.example.v1.Method1Request + 1, // 2: ttrpc.example.v1.Example.Method1:output_type -> ttrpc.example.v1.Method1Response + 3, // 3: ttrpc.example.v1.Example.Method2:output_type -> google.protobuf.Empty + 2, // [2:4] is the sub-list for method output_type + 0, // [0:2] is the sub-list for method input_type + 0, // [0:0] is the sub-list for extension type_name + 0, // [0:0] is the sub-list for extension extendee + 0, // [0:0] is the sub-list for field type_name +} + +func init() { file_github_com_containerd_ttrpc_example_example_proto_init() } +func file_github_com_containerd_ttrpc_example_example_proto_init() { + if File_github_com_containerd_ttrpc_example_example_proto != nil { + return + } + if !protoimpl.UnsafeEnabled { + file_github_com_containerd_ttrpc_example_example_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*Method1Request); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil } - m.XXX_unrecognized = append(m.XXX_unrecognized, dAtA[iNdEx:iNdEx+skippy]...) - iNdEx += skippy } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func skipExample(dAtA []byte) (n int, err error) { - l := len(dAtA) - iNdEx := 0 - depth := 0 - for iNdEx < l { - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowExample - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break + file_github_com_containerd_ttrpc_example_example_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*Method1Response); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil } } - wireType := int(wire & 0x7) - switch wireType { - case 0: - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowExample - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - iNdEx++ - if dAtA[iNdEx-1] < 0x80 { - break - } - } - case 1: - iNdEx += 8 - case 2: - var length int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowExample - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - length |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if length < 0 { - return 0, ErrInvalidLengthExample + file_github_com_containerd_ttrpc_example_example_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*Method2Request); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil } - iNdEx += length - case 3: - depth++ - case 4: - if depth == 0 { - return 0, ErrUnexpectedEndOfGroupExample - } - depth-- - case 5: - iNdEx += 4 - default: - return 0, fmt.Errorf("proto: illegal wireType %d", wireType) - } - if iNdEx < 0 { - return 0, ErrInvalidLengthExample - } - if depth == 0 { - return iNdEx, nil } } - return 0, io.ErrUnexpectedEOF + type x struct{} + out := protoimpl.TypeBuilder{ + File: protoimpl.DescBuilder{ + GoPackagePath: reflect.TypeOf(x{}).PkgPath(), + RawDescriptor: file_github_com_containerd_ttrpc_example_example_proto_rawDesc, + NumEnums: 0, + NumMessages: 3, + NumExtensions: 0, + NumServices: 1, + }, + GoTypes: file_github_com_containerd_ttrpc_example_example_proto_goTypes, + DependencyIndexes: file_github_com_containerd_ttrpc_example_example_proto_depIdxs, + MessageInfos: file_github_com_containerd_ttrpc_example_example_proto_msgTypes, + }.Build() + File_github_com_containerd_ttrpc_example_example_proto = out.File + file_github_com_containerd_ttrpc_example_example_proto_rawDesc = nil + file_github_com_containerd_ttrpc_example_example_proto_goTypes = nil + file_github_com_containerd_ttrpc_example_example_proto_depIdxs = nil } - -var ( - ErrInvalidLengthExample = fmt.Errorf("proto: negative length found during unmarshaling") - ErrIntOverflowExample = fmt.Errorf("proto: integer overflow") - ErrUnexpectedEndOfGroupExample = fmt.Errorf("proto: unexpected end of group") -) diff --git a/example/example.proto b/example/example.proto index 8584e1cdd..c8dee34c9 100644 --- a/example/example.proto +++ b/example/example.proto @@ -3,7 +3,6 @@ syntax = "proto3"; package ttrpc.example.v1; import "google/protobuf/empty.proto"; -import "gogoproto/gogo.proto"; option go_package = "github.com/containerd/ttrpc/example;example"; diff --git a/example/example_ttrpc.pb.go b/example/example_ttrpc.pb.go new file mode 100644 index 000000000..92c309547 --- /dev/null +++ b/example/example_ttrpc.pb.go @@ -0,0 +1,57 @@ +// Code generated by protoc-gen-go-ttrpc. DO NOT EDIT. +// source: github.com/containerd/ttrpc/example/example.proto +package example + +import ( + context "context" + ttrpc "github.com/containerd/ttrpc" + empty "github.com/golang/protobuf/ptypes/empty" +) + +type ExampleService interface { + Method1(ctx context.Context, req *Method1Request) (*Method1Response, error) + Method2(ctx context.Context, req *Method1Request) (*empty.Empty, error) +} + +func RegisterExampleService(srv *ttrpc.Server, svc ExampleService) { + srv.Register("ttrpc.example.v1.Example", map[string]ttrpc.Method{ + "Method1": func(ctx context.Context, unmarshal func(interface{}) error) (interface{}, error) { + var req Method1Request + if err := unmarshal(&req); err != nil { + return nil, err + } + return svc.Method1(ctx, &req) + }, + "Method2": func(ctx context.Context, unmarshal func(interface{}) error) (interface{}, error) { + var req Method1Request + if err := unmarshal(&req); err != nil { + return nil, err + } + return svc.Method2(ctx, &req) + }, + }) +} + +type exampleClient struct { + client *ttrpc.Client +} + +func NewExampleClient(client *ttrpc.Client) ExampleService { + return &exampleClient{ + client: client, + } +} +func (c *exampleClient) Method1(ctx context.Context, req *Method1Request) (*Method1Response, error) { + var resp Method1Response + if err := c.client.Call(ctx, "ttrpc.example.v1.Example", "Method1", req, &resp); err != nil { + return nil, err + } + return &resp, nil +} +func (c *exampleClient) Method2(ctx context.Context, req *Method1Request) (*empty.Empty, error) { + var resp empty.Empty + if err := c.client.Call(ctx, "ttrpc.example.v1.Example", "Method2", req, &resp); err != nil { + return nil, err + } + return &resp, nil +} diff --git a/go.mod b/go.mod index efc00860c..7e18a9b41 100644 --- a/go.mod +++ b/go.mod @@ -4,6 +4,7 @@ go 1.13 require ( github.com/gogo/protobuf v1.3.2 + github.com/golang/protobuf v1.5.0 github.com/prometheus/procfs v0.6.0 github.com/sirupsen/logrus v1.8.1 golang.org/x/sys v0.0.0-20210124154548-22da62e12c0c diff --git a/internal/test.pb.go b/internal/test.pb.go new file mode 100644 index 000000000..786bfee6f --- /dev/null +++ b/internal/test.pb.go @@ -0,0 +1,164 @@ +// Code generated by protoc-gen-go. DO NOT EDIT. +// versions: +// protoc-gen-go v1.27.1 +// protoc v3.5.0 +// source: github.com/containerd/ttrpc/test.proto + +package internal + +import ( + protoreflect "google.golang.org/protobuf/reflect/protoreflect" + protoimpl "google.golang.org/protobuf/runtime/protoimpl" + reflect "reflect" + sync "sync" +) + +const ( + // Verify that this generated code is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) + // Verify that runtime/protoimpl is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) +) + +type TestPayload struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Foo string `protobuf:"bytes,1,opt,name=foo,proto3" json:"foo,omitempty"` + Deadline int64 `protobuf:"varint,2,opt,name=deadline,proto3" json:"deadline,omitempty"` + Metadata string `protobuf:"bytes,3,opt,name=metadata,proto3" json:"metadata,omitempty"` +} + +func (x *TestPayload) Reset() { + *x = TestPayload{} + if protoimpl.UnsafeEnabled { + mi := &file_github_com_containerd_ttrpc_test_proto_msgTypes[0] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *TestPayload) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*TestPayload) ProtoMessage() {} + +func (x *TestPayload) ProtoReflect() protoreflect.Message { + mi := &file_github_com_containerd_ttrpc_test_proto_msgTypes[0] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use TestPayload.ProtoReflect.Descriptor instead. +func (*TestPayload) Descriptor() ([]byte, []int) { + return file_github_com_containerd_ttrpc_test_proto_rawDescGZIP(), []int{0} +} + +func (x *TestPayload) GetFoo() string { + if x != nil { + return x.Foo + } + return "" +} + +func (x *TestPayload) GetDeadline() int64 { + if x != nil { + return x.Deadline + } + return 0 +} + +func (x *TestPayload) GetMetadata() string { + if x != nil { + return x.Metadata + } + return "" +} + +var File_github_com_containerd_ttrpc_test_proto protoreflect.FileDescriptor + +var file_github_com_containerd_ttrpc_test_proto_rawDesc = []byte{ + 0x0a, 0x26, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x63, 0x6f, 0x6e, + 0x74, 0x61, 0x69, 0x6e, 0x65, 0x72, 0x64, 0x2f, 0x74, 0x74, 0x72, 0x70, 0x63, 0x2f, 0x74, 0x65, + 0x73, 0x74, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x05, 0x74, 0x74, 0x72, 0x70, 0x63, 0x22, + 0x57, 0x0a, 0x0b, 0x54, 0x65, 0x73, 0x74, 0x50, 0x61, 0x79, 0x6c, 0x6f, 0x61, 0x64, 0x12, 0x10, + 0x0a, 0x03, 0x66, 0x6f, 0x6f, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x66, 0x6f, 0x6f, + 0x12, 0x1a, 0x0a, 0x08, 0x64, 0x65, 0x61, 0x64, 0x6c, 0x69, 0x6e, 0x65, 0x18, 0x02, 0x20, 0x01, + 0x28, 0x03, 0x52, 0x08, 0x64, 0x65, 0x61, 0x64, 0x6c, 0x69, 0x6e, 0x65, 0x12, 0x1a, 0x0a, 0x08, + 0x6d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, + 0x6d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0x42, 0x26, 0x5a, 0x24, 0x67, 0x69, 0x74, 0x68, + 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x63, 0x6f, 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x65, 0x72, + 0x64, 0x2f, 0x74, 0x74, 0x72, 0x70, 0x63, 0x2f, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x61, 0x6c, + 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, +} + +var ( + file_github_com_containerd_ttrpc_test_proto_rawDescOnce sync.Once + file_github_com_containerd_ttrpc_test_proto_rawDescData = file_github_com_containerd_ttrpc_test_proto_rawDesc +) + +func file_github_com_containerd_ttrpc_test_proto_rawDescGZIP() []byte { + file_github_com_containerd_ttrpc_test_proto_rawDescOnce.Do(func() { + file_github_com_containerd_ttrpc_test_proto_rawDescData = protoimpl.X.CompressGZIP(file_github_com_containerd_ttrpc_test_proto_rawDescData) + }) + return file_github_com_containerd_ttrpc_test_proto_rawDescData +} + +var file_github_com_containerd_ttrpc_test_proto_msgTypes = make([]protoimpl.MessageInfo, 1) +var file_github_com_containerd_ttrpc_test_proto_goTypes = []interface{}{ + (*TestPayload)(nil), // 0: ttrpc.TestPayload +} +var file_github_com_containerd_ttrpc_test_proto_depIdxs = []int32{ + 0, // [0:0] is the sub-list for method output_type + 0, // [0:0] is the sub-list for method input_type + 0, // [0:0] is the sub-list for extension type_name + 0, // [0:0] is the sub-list for extension extendee + 0, // [0:0] is the sub-list for field type_name +} + +func init() { file_github_com_containerd_ttrpc_test_proto_init() } +func file_github_com_containerd_ttrpc_test_proto_init() { + if File_github_com_containerd_ttrpc_test_proto != nil { + return + } + if !protoimpl.UnsafeEnabled { + file_github_com_containerd_ttrpc_test_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*TestPayload); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + } + type x struct{} + out := protoimpl.TypeBuilder{ + File: protoimpl.DescBuilder{ + GoPackagePath: reflect.TypeOf(x{}).PkgPath(), + RawDescriptor: file_github_com_containerd_ttrpc_test_proto_rawDesc, + NumEnums: 0, + NumMessages: 1, + NumExtensions: 0, + NumServices: 0, + }, + GoTypes: file_github_com_containerd_ttrpc_test_proto_goTypes, + DependencyIndexes: file_github_com_containerd_ttrpc_test_proto_depIdxs, + MessageInfos: file_github_com_containerd_ttrpc_test_proto_msgTypes, + }.Build() + File_github_com_containerd_ttrpc_test_proto = out.File + file_github_com_containerd_ttrpc_test_proto_rawDesc = nil + file_github_com_containerd_ttrpc_test_proto_goTypes = nil + file_github_com_containerd_ttrpc_test_proto_depIdxs = nil +} diff --git a/proto/status.proto b/proto/status.proto new file mode 100644 index 000000000..4186d4c79 --- /dev/null +++ b/proto/status.proto @@ -0,0 +1,5 @@ +syntax = "proto3"; + +message Status { + int32 code = 1; +} diff --git a/request.pb.go b/request.pb.go new file mode 100644 index 000000000..bb9dd549b --- /dev/null +++ b/request.pb.go @@ -0,0 +1,396 @@ +// Code generated by protoc-gen-go. DO NOT EDIT. +// versions: +// protoc-gen-go v1.27.1 +// protoc v3.5.0 +// source: github.com/containerd/ttrpc/request.proto + +package ttrpc + +import ( + status "google.golang.org/genproto/googleapis/rpc/status" + protoreflect "google.golang.org/protobuf/reflect/protoreflect" + protoimpl "google.golang.org/protobuf/runtime/protoimpl" + reflect "reflect" + sync "sync" +) + +const ( + // Verify that this generated code is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) + // Verify that runtime/protoimpl is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) +) + +type Request struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Service string `protobuf:"bytes,1,opt,name=service,proto3" json:"service,omitempty"` + Method string `protobuf:"bytes,2,opt,name=method,proto3" json:"method,omitempty"` + Payload []byte `protobuf:"bytes,3,opt,name=payload,proto3" json:"payload,omitempty"` + TimeoutNano int64 `protobuf:"varint,4,opt,name=timeout_nano,json=timeoutNano,proto3" json:"timeout_nano,omitempty"` + Metadata []*KeyValue `protobuf:"bytes,5,rep,name=metadata,proto3" json:"metadata,omitempty"` +} + +func (x *Request) Reset() { + *x = Request{} + if protoimpl.UnsafeEnabled { + mi := &file_github_com_containerd_ttrpc_request_proto_msgTypes[0] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *Request) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*Request) ProtoMessage() {} + +func (x *Request) ProtoReflect() protoreflect.Message { + mi := &file_github_com_containerd_ttrpc_request_proto_msgTypes[0] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use Request.ProtoReflect.Descriptor instead. +func (*Request) Descriptor() ([]byte, []int) { + return file_github_com_containerd_ttrpc_request_proto_rawDescGZIP(), []int{0} +} + +func (x *Request) GetService() string { + if x != nil { + return x.Service + } + return "" +} + +func (x *Request) GetMethod() string { + if x != nil { + return x.Method + } + return "" +} + +func (x *Request) GetPayload() []byte { + if x != nil { + return x.Payload + } + return nil +} + +func (x *Request) GetTimeoutNano() int64 { + if x != nil { + return x.TimeoutNano + } + return 0 +} + +func (x *Request) GetMetadata() []*KeyValue { + if x != nil { + return x.Metadata + } + return nil +} + +type Response struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Status *status.Status `protobuf:"bytes,1,opt,name=status,proto3" json:"status,omitempty"` + Payload []byte `protobuf:"bytes,2,opt,name=payload,proto3" json:"payload,omitempty"` +} + +func (x *Response) Reset() { + *x = Response{} + if protoimpl.UnsafeEnabled { + mi := &file_github_com_containerd_ttrpc_request_proto_msgTypes[1] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *Response) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*Response) ProtoMessage() {} + +func (x *Response) ProtoReflect() protoreflect.Message { + mi := &file_github_com_containerd_ttrpc_request_proto_msgTypes[1] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use Response.ProtoReflect.Descriptor instead. +func (*Response) Descriptor() ([]byte, []int) { + return file_github_com_containerd_ttrpc_request_proto_rawDescGZIP(), []int{1} +} + +func (x *Response) GetStatus() *status.Status { + if x != nil { + return x.Status + } + return nil +} + +func (x *Response) GetPayload() []byte { + if x != nil { + return x.Payload + } + return nil +} + +type StringList struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + List []string `protobuf:"bytes,1,rep,name=list,proto3" json:"list,omitempty"` +} + +func (x *StringList) Reset() { + *x = StringList{} + if protoimpl.UnsafeEnabled { + mi := &file_github_com_containerd_ttrpc_request_proto_msgTypes[2] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *StringList) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*StringList) ProtoMessage() {} + +func (x *StringList) ProtoReflect() protoreflect.Message { + mi := &file_github_com_containerd_ttrpc_request_proto_msgTypes[2] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use StringList.ProtoReflect.Descriptor instead. +func (*StringList) Descriptor() ([]byte, []int) { + return file_github_com_containerd_ttrpc_request_proto_rawDescGZIP(), []int{2} +} + +func (x *StringList) GetList() []string { + if x != nil { + return x.List + } + return nil +} + +type KeyValue struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Key string `protobuf:"bytes,1,opt,name=key,proto3" json:"key,omitempty"` + Value string `protobuf:"bytes,2,opt,name=value,proto3" json:"value,omitempty"` +} + +func (x *KeyValue) Reset() { + *x = KeyValue{} + if protoimpl.UnsafeEnabled { + mi := &file_github_com_containerd_ttrpc_request_proto_msgTypes[3] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *KeyValue) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*KeyValue) ProtoMessage() {} + +func (x *KeyValue) ProtoReflect() protoreflect.Message { + mi := &file_github_com_containerd_ttrpc_request_proto_msgTypes[3] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use KeyValue.ProtoReflect.Descriptor instead. +func (*KeyValue) Descriptor() ([]byte, []int) { + return file_github_com_containerd_ttrpc_request_proto_rawDescGZIP(), []int{3} +} + +func (x *KeyValue) GetKey() string { + if x != nil { + return x.Key + } + return "" +} + +func (x *KeyValue) GetValue() string { + if x != nil { + return x.Value + } + return "" +} + +var File_github_com_containerd_ttrpc_request_proto protoreflect.FileDescriptor + +var file_github_com_containerd_ttrpc_request_proto_rawDesc = []byte{ + 0x0a, 0x29, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x63, 0x6f, 0x6e, + 0x74, 0x61, 0x69, 0x6e, 0x65, 0x72, 0x64, 0x2f, 0x74, 0x74, 0x72, 0x70, 0x63, 0x2f, 0x72, 0x65, + 0x71, 0x75, 0x65, 0x73, 0x74, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x05, 0x74, 0x74, 0x72, + 0x70, 0x63, 0x1a, 0x12, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2f, 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, + 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0xa5, 0x01, 0x0a, 0x07, 0x52, 0x65, 0x71, 0x75, 0x65, + 0x73, 0x74, 0x12, 0x18, 0x0a, 0x07, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x18, 0x01, 0x20, + 0x01, 0x28, 0x09, 0x52, 0x07, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x12, 0x16, 0x0a, 0x06, + 0x6d, 0x65, 0x74, 0x68, 0x6f, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x6d, 0x65, + 0x74, 0x68, 0x6f, 0x64, 0x12, 0x18, 0x0a, 0x07, 0x70, 0x61, 0x79, 0x6c, 0x6f, 0x61, 0x64, 0x18, + 0x03, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x07, 0x70, 0x61, 0x79, 0x6c, 0x6f, 0x61, 0x64, 0x12, 0x21, + 0x0a, 0x0c, 0x74, 0x69, 0x6d, 0x65, 0x6f, 0x75, 0x74, 0x5f, 0x6e, 0x61, 0x6e, 0x6f, 0x18, 0x04, + 0x20, 0x01, 0x28, 0x03, 0x52, 0x0b, 0x74, 0x69, 0x6d, 0x65, 0x6f, 0x75, 0x74, 0x4e, 0x61, 0x6e, + 0x6f, 0x12, 0x2b, 0x0a, 0x08, 0x6d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0x18, 0x05, 0x20, + 0x03, 0x28, 0x0b, 0x32, 0x0f, 0x2e, 0x74, 0x74, 0x72, 0x70, 0x63, 0x2e, 0x4b, 0x65, 0x79, 0x56, + 0x61, 0x6c, 0x75, 0x65, 0x52, 0x08, 0x6d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0x22, 0x45, + 0x0a, 0x08, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x1f, 0x0a, 0x06, 0x73, 0x74, + 0x61, 0x74, 0x75, 0x73, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x07, 0x2e, 0x53, 0x74, 0x61, + 0x74, 0x75, 0x73, 0x52, 0x06, 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, 0x12, 0x18, 0x0a, 0x07, 0x70, + 0x61, 0x79, 0x6c, 0x6f, 0x61, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x07, 0x70, 0x61, + 0x79, 0x6c, 0x6f, 0x61, 0x64, 0x22, 0x20, 0x0a, 0x0a, 0x53, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x4c, + 0x69, 0x73, 0x74, 0x12, 0x12, 0x0a, 0x04, 0x6c, 0x69, 0x73, 0x74, 0x18, 0x01, 0x20, 0x03, 0x28, + 0x09, 0x52, 0x04, 0x6c, 0x69, 0x73, 0x74, 0x22, 0x32, 0x0a, 0x08, 0x4b, 0x65, 0x79, 0x56, 0x61, + 0x6c, 0x75, 0x65, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, + 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x14, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, + 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x42, 0x1d, 0x5a, 0x1b, 0x67, + 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x63, 0x6f, 0x6e, 0x74, 0x61, 0x69, + 0x6e, 0x65, 0x72, 0x64, 0x2f, 0x74, 0x74, 0x72, 0x70, 0x63, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, + 0x6f, 0x33, +} + +var ( + file_github_com_containerd_ttrpc_request_proto_rawDescOnce sync.Once + file_github_com_containerd_ttrpc_request_proto_rawDescData = file_github_com_containerd_ttrpc_request_proto_rawDesc +) + +func file_github_com_containerd_ttrpc_request_proto_rawDescGZIP() []byte { + file_github_com_containerd_ttrpc_request_proto_rawDescOnce.Do(func() { + file_github_com_containerd_ttrpc_request_proto_rawDescData = protoimpl.X.CompressGZIP(file_github_com_containerd_ttrpc_request_proto_rawDescData) + }) + return file_github_com_containerd_ttrpc_request_proto_rawDescData +} + +var file_github_com_containerd_ttrpc_request_proto_msgTypes = make([]protoimpl.MessageInfo, 4) +var file_github_com_containerd_ttrpc_request_proto_goTypes = []interface{}{ + (*Request)(nil), // 0: ttrpc.Request + (*Response)(nil), // 1: ttrpc.Response + (*StringList)(nil), // 2: ttrpc.StringList + (*KeyValue)(nil), // 3: ttrpc.KeyValue + (*status.Status)(nil), // 4: Status +} +var file_github_com_containerd_ttrpc_request_proto_depIdxs = []int32{ + 3, // 0: ttrpc.Request.metadata:type_name -> ttrpc.KeyValue + 4, // 1: ttrpc.Response.status:type_name -> Status + 2, // [2:2] is the sub-list for method output_type + 2, // [2:2] is the sub-list for method input_type + 2, // [2:2] is the sub-list for extension type_name + 2, // [2:2] is the sub-list for extension extendee + 0, // [0:2] is the sub-list for field type_name +} + +func init() { file_github_com_containerd_ttrpc_request_proto_init() } +func file_github_com_containerd_ttrpc_request_proto_init() { + if File_github_com_containerd_ttrpc_request_proto != nil { + return + } + if !protoimpl.UnsafeEnabled { + file_github_com_containerd_ttrpc_request_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*Request); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_github_com_containerd_ttrpc_request_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*Response); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_github_com_containerd_ttrpc_request_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*StringList); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_github_com_containerd_ttrpc_request_proto_msgTypes[3].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*KeyValue); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + } + type x struct{} + out := protoimpl.TypeBuilder{ + File: protoimpl.DescBuilder{ + GoPackagePath: reflect.TypeOf(x{}).PkgPath(), + RawDescriptor: file_github_com_containerd_ttrpc_request_proto_rawDesc, + NumEnums: 0, + NumMessages: 4, + NumExtensions: 0, + NumServices: 0, + }, + GoTypes: file_github_com_containerd_ttrpc_request_proto_goTypes, + DependencyIndexes: file_github_com_containerd_ttrpc_request_proto_depIdxs, + MessageInfos: file_github_com_containerd_ttrpc_request_proto_msgTypes, + }.Build() + File_github_com_containerd_ttrpc_request_proto = out.File + file_github_com_containerd_ttrpc_request_proto_rawDesc = nil + file_github_com_containerd_ttrpc_request_proto_goTypes = nil + file_github_com_containerd_ttrpc_request_proto_depIdxs = nil +} diff --git a/request.proto b/request.proto new file mode 100644 index 000000000..37da334fc --- /dev/null +++ b/request.proto @@ -0,0 +1,29 @@ +syntax = "proto3"; + +package ttrpc; + +import "proto/status.proto"; + +option go_package = "github.com/containerd/ttrpc"; + +message Request { + string service = 1; + string method = 2; + bytes payload = 3; + int64 timeout_nano = 4; + repeated KeyValue metadata = 5; +} + +message Response { + Status status = 1; + bytes payload = 2; +} + +message StringList { + repeated string list = 1; +} + +message KeyValue { + string key = 1; + string value = 2; +} diff --git a/server_linux_test.go b/server_linux_test.go index 4dd79a736..e150f1494 100644 --- a/server_linux_test.go +++ b/server_linux_test.go @@ -22,6 +22,7 @@ import ( "testing" "time" + "github.com/containerd/ttrpc/internal" "github.com/prometheus/procfs" ) @@ -41,7 +42,7 @@ func TestUnixSocketHandshake(t *testing.T) { registerTestingService(server, &testingServer{}) - var tp testPayload + var tp internal.TestPayload // server shutdown, but we still make a call. if err := client.Call(ctx, serviceName, "Test", &tp, &tp); err != nil { t.Fatalf("unexpected error making call: %v", err) @@ -70,7 +71,7 @@ func BenchmarkRoundTripUnixSocketCreds(b *testing.B) { go server.Serve(ctx, listener) defer server.Shutdown(ctx) - var tp testPayload + var tp internal.TestPayload b.ResetTimer() for i := 0; i < b.N; i++ { @@ -96,7 +97,7 @@ func TestServerEOF(t *testing.T) { registerTestingService(server, &testingServer{}) - tp := &testPayload{} + tp := &internal.TestPayload{} // do a regular call if err := client.Call(ctx, serviceName, "Test", tp, tp); err != nil { t.Fatalf("unexpected error during test call: %v", err) diff --git a/server_test.go b/server_test.go index ef8092c59..0633541a4 100644 --- a/server_test.go +++ b/server_test.go @@ -17,20 +17,21 @@ package ttrpc import ( + "bytes" "context" "errors" "fmt" "net" - "reflect" "runtime" "strings" "sync" "testing" "time" - "github.com/gogo/protobuf/proto" + "github.com/containerd/ttrpc/internal" "google.golang.org/grpc/codes" "google.golang.org/grpc/status" + "google.golang.org/protobuf/proto" ) const serviceName = "testService" @@ -40,7 +41,7 @@ const serviceName = "testService" // Typically, this is generated. We define it here to ensure that that package // primitive has what is required for generated code. type testingService interface { - Test(ctx context.Context, req *testPayload) (*testPayload, error) + Test(ctx context.Context, req *internal.TestPayload) (*internal.TestPayload, error) } type testingClient struct { @@ -53,26 +54,16 @@ func newTestingClient(client *Client) *testingClient { } } -func (tc *testingClient) Test(ctx context.Context, req *testPayload) (*testPayload, error) { - var tp testPayload +func (tc *testingClient) Test(ctx context.Context, req *internal.TestPayload) (*internal.TestPayload, error) { + var tp internal.TestPayload return &tp, tc.client.Call(ctx, serviceName, "Test", req, &tp) } -type testPayload struct { - Foo string `protobuf:"bytes,1,opt,name=foo,proto3"` - Deadline int64 `protobuf:"varint,2,opt,name=deadline,proto3"` - Metadata string `protobuf:"bytes,3,opt,name=metadata,proto3"` -} - -func (r *testPayload) Reset() { *r = testPayload{} } -func (r *testPayload) String() string { return fmt.Sprintf("%+#v", r) } -func (r *testPayload) ProtoMessage() {} - // testingServer is what would be implemented by the user of this package. type testingServer struct{} -func (s *testingServer) Test(ctx context.Context, req *testPayload) (*testPayload, error) { - tp := &testPayload{Foo: strings.Repeat(req.Foo, 2)} +func (s *testingServer) Test(ctx context.Context, req *internal.TestPayload) (*internal.TestPayload, error) { + tp := &internal.TestPayload{Foo: strings.Repeat(req.Foo, 2)} if dl, ok := ctx.Deadline(); ok { tp.Deadline = dl.UnixNano() } @@ -90,7 +81,7 @@ func (s *testingServer) Test(ctx context.Context, req *testPayload) (*testPayloa func registerTestingService(srv *Server, svc testingService) { srv.Register(serviceName, map[string]Method{ "Test": func(ctx context.Context, unmarshal func(interface{}) error) (interface{}, error) { - var req testPayload + var req internal.TestPayload if err := unmarshal(&req); err != nil { return nil, err } @@ -99,10 +90,16 @@ func registerTestingService(srv *Server, svc testingService) { }) } -func init() { - proto.RegisterType((*testPayload)(nil), "testPayload") - proto.RegisterType((*Request)(nil), "Request") - proto.RegisterType((*Response)(nil), "Response") +func protoEqual(a, b proto.Message) (bool, error) { + ma, err := proto.Marshal(a) + if err != nil { + return false, err + } + mb, err := proto.Marshal(a) + if err != nil { + return false, err + } + return bytes.Equal(ma, mb), nil } func TestServer(t *testing.T) { @@ -136,8 +133,12 @@ func TestServer(t *testing.T) { if result.err != nil { t.Fatalf("(%s): %v", result.name, result.err) } - if !reflect.DeepEqual(result.received, result.expected) { - t.Fatalf("(%s): unexpected response: %+#v != %+#v", result.name, result.received, result.expected) + equal, err := protoEqual(result.received, result.expected) + if err != nil { + t.Fatalf("failed to compare %s and %s: %s", result.received, result.expected, err) + } + if !equal { + t.Fatalf("unexpected response: %+#v != %+#v", result.received, result.expected) } i++ } @@ -157,7 +158,7 @@ func TestServerUnimplemented(t *testing.T) { errs <- server.Serve(ctx, listener) }() - var tp testPayload + var tp internal.TestPayload if err := client.Call(ctx, "Not", "Found", &tp, &tp); err == nil { t.Fatalf("expected error from non-existent service call") } else if status, ok := status.FromError(err); !ok { @@ -220,14 +221,14 @@ func TestServerShutdown(t *testing.T) { // register a service that takes until we tell it to stop server.Register(serviceName, map[string]Method{ "Test": func(ctx context.Context, unmarshal func(interface{}) error) (interface{}, error) { - var req testPayload + var req internal.TestPayload if err := unmarshal(&req); err != nil { return nil, err } handlersStartedCloseOnce.Do(func() { close(handlersStarted) }) <-proceed - return &testPayload{Foo: "waited"}, nil + return &internal.TestPayload{Foo: "waited"}, nil }, }) @@ -240,7 +241,7 @@ func TestServerShutdown(t *testing.T) { callwg.Add(1) go func(i int) { callwg.Done() - tp := testPayload{Foo: "half" + fmt.Sprint(i)} + tp := internal.TestPayload{Foo: "half" + fmt.Sprint(i)} callErrs <- client.Call(ctx, serviceName, "Test", &tp, &tp) }(i) } @@ -316,7 +317,7 @@ func TestOversizeCall(t *testing.T) { registerTestingService(server, &testingServer{}) - tp := &testPayload{ + tp := &internal.TestPayload{ Foo: strings.Repeat("a", 1+messageLengthMax), } if err := client.Call(ctx, serviceName, "Test", tp, tp); err == nil { @@ -351,7 +352,7 @@ func TestClientEOF(t *testing.T) { registerTestingService(server, &testingServer{}) - tp := &testPayload{} + tp := &internal.TestPayload{} // do a regular call if err := client.Call(ctx, serviceName, "Test", tp, tp); err != nil { t.Fatalf("unexpected error: %v", err) @@ -380,7 +381,7 @@ func TestServerRequestTimeout(t *testing.T) { addr, listener = newTestListener(t) testImpl = &testingServer{} client, cleanup = newTestClient(t, addr) - result testPayload + result internal.TestPayload ) defer cancel() defer cleanup() @@ -391,7 +392,7 @@ func TestServerRequestTimeout(t *testing.T) { go server.Serve(ctx, listener) defer server.Shutdown(ctx) - if err := client.Call(ctx, serviceName, "Test", &testPayload{}, &result); err != nil { + if err := client.Call(ctx, serviceName, "Test", &internal.TestPayload{}, &result); err != nil { t.Fatalf("unexpected error making call: %v", err) } @@ -417,7 +418,7 @@ func TestServerConnectionsLeak(t *testing.T) { registerTestingService(server, &testingServer{}) - tp := &testPayload{} + tp := &internal.TestPayload{} // do a regular call if err := client.Call(ctx, serviceName, "Test", tp, tp); err != nil { t.Fatalf("unexpected error during test call: %v", err) @@ -466,7 +467,7 @@ func BenchmarkRoundTrip(b *testing.B) { go server.Serve(ctx, listener) defer server.Shutdown(ctx) - var tp testPayload + var tp internal.TestPayload b.ResetTimer() for i := 0; i < b.N; i++ { @@ -490,17 +491,23 @@ func checkServerShutdown(t *testing.T, server *Server) { } type callResult struct { +<<<<<<< HEAD name string err error input *testPayload expected *testPayload received *testPayload +======= + input *internal.TestPayload + expected *internal.TestPayload + received *internal.TestPayload +>>>>>>> 039bd6d (Use google.golang.org/protobuf instead of github.com/gogo/protobuf) } func roundTrip(ctx context.Context, client *testingClient, name string) callResult { var ( - tp = &testPayload{ - Foo: name, + tp = &internal.TestPayload{ + Foo: "bar", } ) @@ -517,7 +524,7 @@ func roundTrip(ctx context.Context, client *testingClient, name string) callResu return callResult{ name: name, input: tp, - expected: &testPayload{Foo: strings.Repeat(tp.Foo, 2), Metadata: name}, + expected: &internal.TestPayload{Foo: strings.Repeat(tp.Foo, 2), Metadata: "bar"}, received: resp, } } diff --git a/services.go b/services.go index f359e9611..57c8f8022 100644 --- a/services.go +++ b/services.go @@ -25,9 +25,9 @@ import ( "path" "unsafe" - "github.com/gogo/protobuf/proto" "google.golang.org/grpc/codes" "google.golang.org/grpc/status" + "google.golang.org/protobuf/proto" ) type Method func(ctx context.Context, unmarshal func(interface{}) error) (interface{}, error) diff --git a/test.proto b/test.proto new file mode 100644 index 000000000..deeed946b --- /dev/null +++ b/test.proto @@ -0,0 +1,11 @@ +syntax = "proto3"; + +package ttrpc; + +option go_package = "github.com/containerd/ttrpc/internal"; + +message TestPayload { + string foo = 1; + int64 deadline = 2; + string metadata = 3; +} diff --git a/types.go b/types.go deleted file mode 100644 index c4dcb82b5..000000000 --- a/types.go +++ /dev/null @@ -1,61 +0,0 @@ -/* - Copyright The containerd Authors. - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -*/ - -package ttrpc - -import ( - "fmt" - - spb "google.golang.org/genproto/googleapis/rpc/status" -) - -type Request struct { - Service string `protobuf:"bytes,1,opt,name=service,proto3"` - Method string `protobuf:"bytes,2,opt,name=method,proto3"` - Payload []byte `protobuf:"bytes,3,opt,name=payload,proto3"` - TimeoutNano int64 `protobuf:"varint,4,opt,name=timeout_nano,proto3"` - Metadata []*KeyValue `protobuf:"bytes,5,rep,name=metadata,proto3"` -} - -func (r *Request) Reset() { *r = Request{} } -func (r *Request) String() string { return fmt.Sprintf("%+#v", r) } -func (r *Request) ProtoMessage() {} - -type Response struct { - Status *spb.Status `protobuf:"bytes,1,opt,name=status,proto3"` - Payload []byte `protobuf:"bytes,2,opt,name=payload,proto3"` -} - -func (r *Response) Reset() { *r = Response{} } -func (r *Response) String() string { return fmt.Sprintf("%+#v", r) } -func (r *Response) ProtoMessage() {} - -type StringList struct { - List []string `protobuf:"bytes,1,rep,name=list,proto3"` -} - -func (r *StringList) Reset() { *r = StringList{} } -func (r *StringList) String() string { return fmt.Sprintf("%+#v", r) } -func (r *StringList) ProtoMessage() {} - -type KeyValue struct { - Key string `protobuf:"bytes,1,opt,name=key,proto3"` - Value string `protobuf:"bytes,2,opt,name=value,proto3"` -} - -func (m *KeyValue) Reset() { *m = KeyValue{} } -func (*KeyValue) ProtoMessage() {} -func (m *KeyValue) String() string { return fmt.Sprintf("%+#v", m) }