diff --git a/.gitignore b/.gitignore index 1c570c5..6b8382a 100644 --- a/.gitignore +++ b/.gitignore @@ -48,3 +48,4 @@ grpc_gen/ go.mod go.sum bin +thrift_streaming/binaries diff --git a/.licenserc.yaml b/.licenserc.yaml index ed6c1f7..2113c0d 100644 --- a/.licenserc.yaml +++ b/.licenserc.yaml @@ -12,5 +12,11 @@ header: paths-ignore: - 'kitex_gen/**/*.go;' + - 'thrift_streaming/kitex_gen/**/*.go' + - 'thrift_streaming/kitex_gen_slim/**/*.go' + - 'thrift_streaming/kitex_gen_old/**/*.go' + - 'thrift_streaming/kitex_gen_cross/**/*.go' + - 'thrift_streaming/thrift_slim_amd64_test.go' + - 'thrift_streaming/thrift_slim_others_test.go' comment: on-failure diff --git a/run.sh b/run.sh index 3816ac8..e37cd7b 100755 --- a/run.sh +++ b/run.sh @@ -125,10 +125,14 @@ packages=( ./generic/http/... ./generic/map/... ./grpc/... +./thrift_streaming/... ) for pkg in ${packages[@]} do + if [ "$pkg" == "./thrift_streaming/..." ]; then + ./thrift_streaming/generate.sh + fi if [[ -n $LOCAL_REPO ]]; then go test -covermode=atomic -coverprofile=${LOCAL_REPO}/coverage.txt.tmp -coverpkg=github.com/cloudwego/kitex/... $pkg if [[ "$OSTYPE" =~ ^darwin ]]; diff --git a/thrift_streaming/generate.sh b/thrift_streaming/generate.sh new file mode 100755 index 0000000..5a0ba17 --- /dev/null +++ b/thrift_streaming/generate.sh @@ -0,0 +1,117 @@ +#!/bin/bash + +# Copyright 2023 CloudWeGo 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. + + +# Regenerate kitex_gen* directories when there's any related change to codegen (both kitex&thriftgo) + +cd `dirname $0` +ROOT=`pwd` + +set -e + +# Old binaries: kitex <= v0.8.0 && thriftgo <= v0.3.4 +OLD=$ROOT/binaries/github-old + +# New binaries: kitex >= v0.8.1 && thriftgo >= v0.3.5 +NEW=$ROOT/binaries/github-new + +# kitex >= v0.8.1 && thriftgo <= v0.3.4 +NEW_THRIFTGO_OLD_KITEX=$ROOT/binaries/github-new-thriftgo-old-kitex + +module='-module github.com/cloudwego/kitex-tests' +idl=idl/api.thrift + +SAVE_PATH=$PATH + +# generate with old kitex and thriftgo WITHOUT thrift streaming support +function generate_old() { + echo -e "\n\ngenerate_old\n" + dir=$OLD + export PATH=$OLD:$SAVE_PATH + + mkdir -p $dir + GOBIN=$dir go install github.com/cloudwego/kitex/tool/cmd/kitex@v0.8.0 + GOBIN=$dir go install github.com/cloudwego/thriftgo@v0.3.4 + if [ ! -f "$dir/kitex" -o ! -f "$dir/thriftgo" ]; then + echo "[old] Unable to install kitex or thriftgo to $dir, please check before continue." + exit 1 + fi + + # Thrift Old + rm -rf kitex_gen_old + kitex -gen-path kitex_gen_old $module $idl +} + +function generate_new() { + echo -e "\n\ngenerate_new\n" + dir=$NEW + export PATH=$dir:$SAVE_PATH + + mkdir -p $dir + GOBIN=$dir go install github.com/cloudwego/thriftgo@latest + if [ -d "$LOCAL_REPO" ]; then + SAVE_DIR=`pwd` + cd $LOCAL_REPO/tool/cmd/kitex && go build && cp kitex $dir + cd $SAVE_DIR + else + echo "Please set local kitex directory in the environment variable $LOCAL_REPO" + exit 1 + fi + + if [ ! -f "$dir/kitex" -o ! -f "$dir/thriftgo" ]; then + echo "[new] Unable to install kitex or thriftgo to $dir, please check before continue." + exit 1 + fi + + rm -rf kitex_gen + + # Thrift + kitex $module $idl + + # Thrift Slim + kitex -thrift template=slim -gen-path kitex_gen_slim $module $idl + + # KitexPB + kitex $module idl/api.proto + + # GRPC + kitex $module idl/api_no_stream.proto +} + +function generate_new_thriftgo_old_kitex() { + echo -e "\n\ngenerate_new_thriftgo_old_kitex\n" + dir=$NEW_THRIFTGO_OLD_KITEX + export PATH=$dir:$SAVE_PATH + + mkdir -p $dir + GOBIN=$dir go install github.com/cloudwego/kitex/tool/cmd/kitex@v0.8.0 + GOBIN=$dir go install github.com/cloudwego/thriftgo@latest + if [ ! -f "$dir/kitex" -o ! -f "$dir/thriftgo" ]; then + echo "[cross] Unable to install kitex or thriftgo to $dir, please check before continue." + exit 1 + fi + + rm -rf kitex_gen_cross + # Thrift + kitex -gen-path kitex_gen_cross $module $idl +} + +generate_new + +generate_new_thriftgo_old_kitex + +# Uncomment this to regenerate kitex_gen_old (using kitex 0.8.0/thriftgo 0.3.4 without thrift-streaming support) +# generate_old \ No newline at end of file diff --git a/thrift_streaming/grpcpb_handler.go b/thrift_streaming/grpcpb_handler.go new file mode 100644 index 0000000..5f04a36 --- /dev/null +++ b/thrift_streaming/grpcpb_handler.go @@ -0,0 +1,97 @@ +// Copyright 2023 CloudWeGo 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 thrift_streaming + +import ( + "context" + "strconv" + + "github.com/cloudwego/kitex/pkg/klog" + + "github.com/cloudwego/kitex-tests/thrift_streaming/kitex_gen/grpc_pb" +) + +type GRPCPBServiceImpl struct{} + +func (G *GRPCPBServiceImpl) Echo(stream grpc_pb.PBService_EchoServer) (err error) { + klog.Infof("[GRPCPBServiceImpl.Echo] Echo called") + count := GetInt(stream.Context(), KeyCount, 0) + klog.Infof("count: %d", count) + for i := 0; i < count; i++ { + var req *grpc_pb.Request + if req, err = stream.Recv(); err != nil { + klog.Infof("[GRPCPBServiceImpl.Echo] recv error: %v", err) + return err + } + klog.Infof("[GRPCPBServiceImpl.Echo] recv success: %s", req.Message) + + resp := &grpc_pb.Response{ + Message: req.Message, + } + if err = stream.Send(resp); err != nil { + klog.Infof("[GRPCPBServiceImpl.Echo] send error: %v", err) + return + } + klog.Infof("[GRPCPBServiceImpl.Echo] send success: %v", resp) + } + return +} + +func (G *GRPCPBServiceImpl) EchoClient(stream grpc_pb.PBService_EchoClientServer) (err error) { + klog.Infof("[GRPCPBServiceImpl.EchoClient] EchoClient called") + count := GetInt(stream.Context(), KeyCount, 0) + klog.Infof("count: %d", count) + for i := 0; i < count; i++ { + var req *grpc_pb.Request + if req, err = stream.Recv(); err != nil { + klog.Infof("[GRPCPBServiceImpl.EchoClient] recv error: %v", err) + return err + } + klog.Infof("[GRPCPBServiceImpl.EchoClient] recv success: %s", req.Message) + } + + resp := &grpc_pb.Response{ + Message: strconv.Itoa(count), + } + err = stream.SendAndClose(resp) + klog.Infof("[GRPCPBServiceImpl.EchoClient] send: err = %v, resp = %v", err, resp) + return err +} + +func (G *GRPCPBServiceImpl) EchoServer(req *grpc_pb.Request, stream grpc_pb.PBService_EchoServerServer) (err error) { + klog.Infof("[GRPCPBServiceImpl.EchoServer] recv req = %s", req.Message) + count := GetInt(stream.Context(), KeyCount, 0) + klog.Infof("count: %d", count) + for i := 0; i < count; i++ { + resp := &grpc_pb.Response{ + Message: req.Message + "-" + strconv.Itoa(i), + } + if err = stream.Send(resp); err != nil { + klog.Infof("[GRPCPBServiceImpl.EchoServer] send error: %v", err) + return err + } + klog.Infof("[GRPCPBServiceImpl.EchoServer] send success: %s", resp.Message) + } + return nil +} + +func (G *GRPCPBServiceImpl) EchoPingPong(ctx context.Context, req *grpc_pb.Request) (resp *grpc_pb.Response, err error) { + klog.Infof("[GRPCPBServiceImpl.EchoPingPong] recv: %s", req.Message) + resp = &grpc_pb.Response{ + Message: req.Message, + } + klog.Infof("[GRPCPBServiceImpl.EchoPingPong] send: %s", resp.Message) + return resp, nil +} diff --git a/thrift_streaming/grpcpb_test.go b/thrift_streaming/grpcpb_test.go new file mode 100644 index 0000000..e251f57 --- /dev/null +++ b/thrift_streaming/grpcpb_test.go @@ -0,0 +1,438 @@ +// Copyright 2023 CloudWeGo 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 thrift_streaming + +import ( + "context" + "fmt" + "strconv" + "testing" + + "github.com/bytedance/gopkg/cloud/metainfo" + "github.com/cloudwego/kitex/client" + "github.com/cloudwego/kitex/client/streamclient" + "github.com/cloudwego/kitex/pkg/endpoint" + "github.com/cloudwego/kitex/pkg/klog" + "github.com/cloudwego/kitex/pkg/streaming" + "github.com/cloudwego/kitex/pkg/utils/kitexutil" + "github.com/cloudwego/kitex/server" + + "github.com/cloudwego/kitex-tests/pkg/test" + "github.com/cloudwego/kitex-tests/thrift_streaming/kitex_gen/grpc_pb" + grpcpbservice "github.com/cloudwego/kitex-tests/thrift_streaming/kitex_gen/grpc_pb/pbservice" + "github.com/cloudwego/kitex-tests/thrift_streaming/kitex_gen/kitex_pb" + kitexpbservice "github.com/cloudwego/kitex-tests/thrift_streaming/kitex_gen/kitex_pb/pbservice" +) + +func TestGRPCPB(t *testing.T) { + cli := grpcpbservice.MustNewClient("service", client.WithHostPorts(grpcAddr)) + t.Run("pingpong", func(t *testing.T) { + resp, err := cli.EchoPingPong(context.Background(), &grpc_pb.Request{ + Message: "hello", + }) + test.Assert(t, err == nil) + test.Assert(t, resp.Message == "hello") + }) + t.Run("client", func(t *testing.T) { + count := 2 + ctx := metainfo.WithValue(context.Background(), KeyCount, strconv.Itoa(count)) + stream, err := cli.EchoClient(ctx) + test.Assert(t, err == nil) + for i := 0; i < count; i++ { + err = stream.Send(&grpc_pb.Request{ + Message: "hello-" + strconv.Itoa(i), + }) + test.Assert(t, err == nil) + } + resp, err := stream.CloseAndRecv() + test.Assert(t, err == nil) + test.Assert(t, resp.Message == strconv.Itoa(count)) + }) + t.Run("server", func(t *testing.T) { + count := 2 + ctx := metainfo.WithValue(context.Background(), KeyCount, strconv.Itoa(count)) + req := &grpc_pb.Request{ + Message: "hello", + } + stream, err := cli.EchoServer(ctx, req) + test.Assert(t, err == nil) + for i := 0; i < count; i++ { + resp, err := stream.Recv() + test.Assert(t, err == nil) + test.Assert(t, resp.Message == "hello-"+strconv.Itoa(i)) + } + }) + t.Run("bidirectional", func(t *testing.T) { + count := 2 + ctx := metainfo.WithValue(context.Background(), KeyCount, strconv.Itoa(count)) + stream, err := cli.Echo(ctx) + test.Assert(t, err == nil) + for i := 0; i < count; i++ { + req := &grpc_pb.Request{ + Message: "hello-" + strconv.Itoa(i), + } + err = stream.Send(req) + test.Assert(t, err == nil) + + resp, err := stream.Recv() + test.Assert(t, err == nil) + test.Assert(t, resp.Message == req.Message, resp.Message) + } + }) +} + +func TestGRPCPBStreamClient(t *testing.T) { + t.Run("client", func(t *testing.T) { + count := 2 + cli := grpcpbservice.MustNewStreamClient("service", streamclient.WithHostPorts(grpcAddr), + streamclient.WithMiddleware(func(next endpoint.Endpoint) endpoint.Endpoint { + return func(ctx context.Context, req, resp interface{}) (err error) { + _, ok := resp.(*streaming.Result) + test.Assert(t, ok) + return next(ctx, req, resp) + } + }), + streamclient.WithSendMiddleware(func(next endpoint.SendEndpoint) endpoint.SendEndpoint { + i := 0 + return func(stream streaming.Stream, message interface{}) (err error) { + req := message.(*grpc_pb.Request) + test.Assert(t, req.Message == "hello-"+strconv.Itoa(i)) + i++ + return next(stream, message) + } + }), + streamclient.WithRecvMiddleware(func(next endpoint.RecvEndpoint) endpoint.RecvEndpoint { + return func(stream streaming.Stream, message interface{}) (err error) { + err = next(stream, message) + resp := message.(*grpc_pb.Response) + test.Assert(t, resp.Message == strconv.Itoa(count)) + resp.Message += "_recv_middleware" + return err + } + })) + ctx := metainfo.WithValue(context.Background(), KeyCount, strconv.Itoa(count)) + stream, err := cli.EchoClient(ctx) + test.Assert(t, err == nil) + for i := 0; i < count; i++ { + err = stream.Send(&grpc_pb.Request{ + Message: "hello-" + strconv.Itoa(i), + }) + test.Assert(t, err == nil) + } + resp, err := stream.CloseAndRecv() + test.Assert(t, err == nil) + test.Assert(t, resp.Message == strconv.Itoa(count)+"_recv_middleware") + }) + t.Run("server", func(t *testing.T) { + count := 2 + cli := grpcpbservice.MustNewStreamClient("service", streamclient.WithHostPorts(grpcAddr), + streamclient.WithMiddleware(func(next endpoint.Endpoint) endpoint.Endpoint { + return func(ctx context.Context, req, resp interface{}) (err error) { + _, ok := resp.(*streaming.Result) + test.Assert(t, ok) + return next(ctx, req, resp) + } + }), + streamclient.WithSendMiddleware(func(next endpoint.SendEndpoint) endpoint.SendEndpoint { + return func(stream streaming.Stream, message interface{}) (err error) { + req := message.(*grpc_pb.Request) + test.Assert(t, req.Message == "hello") + return next(stream, message) + } + }), + streamclient.WithRecvMiddleware(func(next endpoint.RecvEndpoint) endpoint.RecvEndpoint { + i := 0 + return func(stream streaming.Stream, message interface{}) (err error) { + err = next(stream, message) + resp := message.(*grpc_pb.Response) + test.Assert(t, resp.Message == "hello-"+strconv.Itoa(i), resp.Message) + i++ + resp.Message += "_recv_middleware" + return err + } + })) + ctx := metainfo.WithValue(context.Background(), KeyCount, strconv.Itoa(count)) + req := &grpc_pb.Request{ + Message: "hello", + } + stream, err := cli.EchoServer(ctx, req) + test.Assert(t, err == nil) + for i := 0; i < count; i++ { + resp, err := stream.Recv() + test.Assert(t, err == nil) + test.Assert(t, resp.Message == "hello-"+strconv.Itoa(i)+"_recv_middleware") + } + }) + t.Run("bidirectional", func(t *testing.T) { + count := 2 + cli := grpcpbservice.MustNewStreamClient("service", streamclient.WithHostPorts(grpcAddr), + streamclient.WithMiddleware(func(next endpoint.Endpoint) endpoint.Endpoint { + return func(ctx context.Context, req, resp interface{}) (err error) { + _, ok := resp.(*streaming.Result) + test.Assert(t, ok) + return next(ctx, req, resp) + } + }), + streamclient.WithSendMiddleware(func(next endpoint.SendEndpoint) endpoint.SendEndpoint { + i := 0 + return func(stream streaming.Stream, message interface{}) (err error) { + req := message.(*grpc_pb.Request) + test.Assert(t, req.Message == "hello-"+strconv.Itoa(i)) + i++ + return next(stream, message) + } + }), + streamclient.WithRecvMiddleware(func(next endpoint.RecvEndpoint) endpoint.RecvEndpoint { + i := 0 + return func(stream streaming.Stream, message interface{}) (err error) { + err = next(stream, message) + resp := message.(*grpc_pb.Response) + test.Assert(t, resp.Message == "hello-"+strconv.Itoa(i)) + i++ + resp.Message += "_recv_middleware" + return err + } + })) + ctx := metainfo.WithValue(context.Background(), KeyCount, strconv.Itoa(count)) + stream, err := cli.Echo(ctx) + test.Assert(t, err == nil) + for i := 0; i < count; i++ { + req := &grpc_pb.Request{ + Message: "hello-" + strconv.Itoa(i), + } + err = stream.Send(req) + test.Assert(t, err == nil) + + resp, err := stream.Recv() + test.Assert(t, err == nil) + test.Assert(t, resp.Message == req.Message+"_recv_middleware", resp.Message) + } + }) + + t.Run("call kitex_pb server", func(t *testing.T) { + cli := grpcpbservice.MustNewClient("service", client.WithHostPorts(pbAddr)) + req := &grpc_pb.Request{ + Message: "To KitexPBServer.EchoPingPong", + } + resp, err := cli.EchoPingPong(context.Background(), req) + test.Assert(t, err == nil) + test.Assert(t, resp.Message == req.Message, resp.Message) // no middleware + }) +} + +func TestGRPCPBServerMiddleware(t *testing.T) { + addr := addrAllocator() + svr := RunGRPCPBServer(&GRPCPBServiceImpl{}, addr, + server.WithMiddleware(func(e endpoint.Endpoint) endpoint.Endpoint { + return func(ctx context.Context, req, resp interface{}) (err error) { + method, _ := kitexutil.GetMethod(ctx) + _, ok := req.(*streaming.Args) + isKitexPB, _ := metainfo.GetValue(ctx, "TEST_KITEX_PB") + if !ok && isKitexPB != "1" { + return fmt.Errorf("invalid request type: %T, method = %v", req, method) + } + if isKitexPB == "1" { + req.(*grpcpbservice.EchoPingPongArgs).Req.Message += "_mwReq" + } + err = e(ctx, req, resp) + if isKitexPB == "1" { + resp.(*grpcpbservice.EchoPingPongResult).Success.Message += "_mwResp" + } + return + } + }), + server.WithRecvMiddleware(func(e endpoint.RecvEndpoint) endpoint.RecvEndpoint { + return func(stream streaming.Stream, message interface{}) (err error) { + err = e(stream, message) + method, _ := kitexutil.GetMethod(stream.Context()) + req := message.(*grpc_pb.Request) + if req.Message != method { + return fmt.Errorf("invalid message: %v, method = %v", req.Message, method) + } + req.Message += "_recv" + return + } + }), + server.WithSendMiddleware(func(e endpoint.SendEndpoint) endpoint.SendEndpoint { + return func(stream streaming.Stream, message interface{}) (err error) { + resp := message.(*grpc_pb.Response) + resp.Message += "_send" + return e(stream, message) + } + }), + ) + defer svr.Stop() + + t.Run("pingpong", func(t *testing.T) { + cli := grpcpbservice.MustNewClient("service", client.WithHostPorts(addr)) + resp, err := cli.EchoPingPong(context.Background(), &grpc_pb.Request{ + Message: "EchoPingPong", + }) + test.Assert(t, err == nil) + test.Assert(t, resp.Message == "EchoPingPong_recv_send", resp.Message) + }) + + t.Run("client", func(t *testing.T) { + count := 2 + cli := grpcpbservice.MustNewStreamClient("service", streamclient.WithHostPorts(addr)) + ctx := metainfo.WithValue(context.Background(), KeyCount, strconv.Itoa(count)) + stream, err := cli.EchoClient(ctx) + test.Assert(t, err == nil) + for i := 0; i < count; i++ { + err = stream.Send(&grpc_pb.Request{ + Message: "EchoClient", + }) + test.Assert(t, err == nil) + } + resp, err := stream.CloseAndRecv() + test.Assert(t, err == nil) + test.Assert(t, resp.Message == strconv.Itoa(count)+"_send", resp.Message) + }) + + t.Run("server", func(t *testing.T) { + count := 2 + cli := grpcpbservice.MustNewStreamClient("service", streamclient.WithHostPorts(addr)) + ctx := metainfo.WithValue(context.Background(), KeyCount, strconv.Itoa(count)) + req := &grpc_pb.Request{ + Message: "EchoServer", + } + stream, err := cli.EchoServer(ctx, req) + test.Assert(t, err == nil) + for i := 0; i < count; i++ { + resp, err := stream.Recv() + test.Assert(t, err == nil) + test.Assert(t, resp.Message == req.Message+"_recv-"+strconv.Itoa(i)+"_send", resp.Message) + } + }) + + t.Run("bidirectional", func(t *testing.T) { + count := 2 + cli := grpcpbservice.MustNewStreamClient("service", streamclient.WithHostPorts(addr)) + ctx := metainfo.WithValue(context.Background(), KeyCount, strconv.Itoa(count)) + stream, err := cli.Echo(ctx) + test.Assert(t, err == nil) + for i := 0; i < count; i++ { + req := &grpc_pb.Request{ + Message: "Echo", + } + err = stream.Send(req) + test.Assert(t, err == nil) + + resp, err := stream.Recv() + test.Assert(t, err == nil) + test.Assert(t, resp.Message == req.Message+"_recv_send", resp.Message) + } + }) + + t.Run("kitex_pb client", func(t *testing.T) { + cli := kitexpbservice.MustNewClient("service", client.WithHostPorts(addr)) + ctx := metainfo.WithValue(context.Background(), "TEST_KITEX_PB", "1") + req := &kitex_pb.Request{ + Message: "EchoPingPong", + } + resp, err := cli.EchoPingPong(ctx, req) + test.Assert(t, err == nil) + // KitexPB requests will not be processed by recv/send middlewares + test.Assertf(t, resp.Message == "EchoPingPong_mwReq_mwResp", resp.Message, "msg: %v", resp.Message) + }) +} + +func TestGRPCPBServiceWithCompatibleMiddleware(t *testing.T) { + addr := addrAllocator() + svr := RunGRPCPBServer( + &GRPCPBServiceImpl{}, + addr, + server.WithCompatibleMiddlewareForUnary(), + server.WithMiddleware(func(e endpoint.Endpoint) endpoint.Endpoint { + return func(ctx context.Context, req, resp interface{}) (err error) { + method, _ := kitexutil.GetMethod(ctx) + klog.Infof("svr mw method: %s", method) + if method == "EchoPingPong" { + realReq, ok := req.(*grpcpbservice.EchoPingPongArgs) + if !ok { + return fmt.Errorf("invalid req type %T", req) + } + realReq.Req.Message += "_mwReq" + err = e(ctx, req, resp) + realResp, ok := resp.(*grpcpbservice.EchoPingPongResult) + if !ok { + return fmt.Errorf("invalid resp type %T", resp) + } + realResp.Success.Message += "_mwResp" + } else { + err = e(ctx, req, resp) + } + return err + } + }), + server.WithRecvMiddleware(func(next endpoint.RecvEndpoint) endpoint.RecvEndpoint { + return func(stream streaming.Stream, message interface{}) (err error) { + method, _ := kitexutil.GetMethod(stream.Context()) + klog.Infof("svr recvMW method: %s", method) + if method == "EchoPingPong" { + return fmt.Errorf("should not be called") + } else { + if err = next(stream, message); err != nil { + return err + } + if _, ok := message.(*grpc_pb.Request); !ok { + return fmt.Errorf("invalid req type %T", message) + } + return err + } + } + }), + server.WithSendMiddleware(func(next endpoint.SendEndpoint) endpoint.SendEndpoint { + return func(stream streaming.Stream, message interface{}) (err error) { + method, _ := kitexutil.GetMethod(stream.Context()) + klog.Infof("svr sendMW method: %s", method) + if method == "EchoPingPong" { + return fmt.Errorf("should not be called") + } else { + if err = next(stream, message); err != nil { + return err + } + if _, ok := message.(*grpc_pb.Response); !ok { + return fmt.Errorf("invalid req type %T", message) + } + return err + } + } + }), + ) + defer svr.Stop() + + // GRPC Over HTTP2 + streamCli := grpcpbservice.MustNewClient("service", client.WithHostPorts(addr)) + resp, err := streamCli.EchoPingPong(context.Background(), &grpc_pb.Request{Message: "hello"}) + test.Assert(t, err == nil, err) + test.Assert(t, resp.Message == "hello_mwReq_mwResp", resp.Message) + + // KitexPB + cli := kitexpbservice.MustNewClient("service", client.WithHostPorts(addr)) + resp1, err := cli.EchoPingPong(context.Background(), &kitex_pb.Request{Message: "hello"}) + test.Assert(t, err == nil, err) + test.Assert(t, resp1.Message == "hello_mwReq_mwResp", resp1.Message) + + ctx := metainfo.WithValue(context.Background(), KeyCount, "1") + stream, err := streamCli.EchoClient(ctx) + test.Assert(t, err == nil, err) + err = stream.Send(&grpc_pb.Request{ + Message: "hello", + }) + test.Assert(t, err == nil, err) + _, err = stream.CloseAndRecv() + test.Assert(t, err == nil, err) +} diff --git a/thrift_streaming/idl/api.proto b/thrift_streaming/idl/api.proto new file mode 100644 index 0000000..19978e1 --- /dev/null +++ b/thrift_streaming/idl/api.proto @@ -0,0 +1,33 @@ +// Copyright 2023 CloudWeGo 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. + +syntax = "proto3"; +package grpc_pb; +// The greeting service definition. +option go_package = "grpc_pb"; + +message Request { + string message = 1; +} + +message Response { + string message = 1; +} + +service PBService { + rpc Echo (stream Request) returns (stream Response) {} + rpc EchoClient (stream Request) returns (Response) {} + rpc EchoServer (Request) returns (stream Response) {} + rpc EchoPingPong (Request) returns (Response) {} +} diff --git a/thrift_streaming/idl/api.thrift b/thrift_streaming/idl/api.thrift new file mode 100644 index 0000000..db57dd4 --- /dev/null +++ b/thrift_streaming/idl/api.thrift @@ -0,0 +1,41 @@ +// Copyright 2023 CloudWeGo 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. + +namespace go echo + +struct EchoRequest { + 1: required string message, +} + +struct EchoResponse { + 1: required string message, +} + +exception EchoException { + 1: string message +} + + +service EchoService { + // streaming api (HTTP2) + EchoResponse EchoBidirectional (1: EchoRequest req1) (streaming.mode="bidirectional"), + EchoResponse EchoClient (1: EchoRequest req1) (streaming.mode="client"), + EchoResponse EchoServer (1: EchoRequest req1) (streaming.mode="server"), + EchoResponse EchoUnary (1: EchoRequest req1) (streaming.mode="unary"), + + // KitexThrift + EchoResponse EchoPingPong (1: EchoRequest req1, 2: EchoRequest req2) throws (1: EchoException e), + void EchoOneway(1: EchoRequest req1), + void Ping(), +} diff --git a/thrift_streaming/idl/api_no_stream.proto b/thrift_streaming/idl/api_no_stream.proto new file mode 100644 index 0000000..1794d11 --- /dev/null +++ b/thrift_streaming/idl/api_no_stream.proto @@ -0,0 +1,30 @@ +// Copyright 2023 CloudWeGo 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. + +syntax = "proto3"; +package kitex_pb; +// The greeting service definition. +option go_package = "kitex_pb"; + +message Request { +string message = 1; +} + +message Response { +string message = 1; +} + +service PBService { + rpc EchoPingPong (Request) returns (Response) {} +} diff --git a/thrift_streaming/kitex_gen/echo/api.go b/thrift_streaming/kitex_gen/echo/api.go new file mode 100644 index 0000000..edd4aae --- /dev/null +++ b/thrift_streaming/kitex_gen/echo/api.go @@ -0,0 +1,3127 @@ +// Code generated by thriftgo (0.3.5). DO NOT EDIT. + +package echo + +import ( + "context" + "fmt" + "github.com/apache/thrift/lib/go/thrift" + "github.com/cloudwego/kitex/pkg/streaming" + "strings" +) + +type EchoRequest struct { + Message string `thrift:"message,1,required" frugal:"1,required,string" json:"message"` +} + +func NewEchoRequest() *EchoRequest { + return &EchoRequest{} +} + +func (p *EchoRequest) InitDefault() { + *p = EchoRequest{} +} + +func (p *EchoRequest) GetMessage() (v string) { + return p.Message +} +func (p *EchoRequest) SetMessage(val string) { + p.Message = val +} + +var fieldIDToName_EchoRequest = map[int16]string{ + 1: "message", +} + +func (p *EchoRequest) Read(iprot thrift.TProtocol) (err error) { + + var fieldTypeId thrift.TType + var fieldId int16 + var issetMessage bool = false + + if _, err = iprot.ReadStructBegin(); err != nil { + goto ReadStructBeginError + } + + for { + _, fieldTypeId, fieldId, err = iprot.ReadFieldBegin() + if err != nil { + goto ReadFieldBeginError + } + if fieldTypeId == thrift.STOP { + break + } + + switch fieldId { + case 1: + if fieldTypeId == thrift.STRING { + if err = p.ReadField1(iprot); err != nil { + goto ReadFieldError + } + issetMessage = true + } else if err = iprot.Skip(fieldTypeId); err != nil { + goto SkipFieldError + } + default: + if err = iprot.Skip(fieldTypeId); err != nil { + goto SkipFieldError + } + } + if err = iprot.ReadFieldEnd(); err != nil { + goto ReadFieldEndError + } + } + if err = iprot.ReadStructEnd(); err != nil { + goto ReadStructEndError + } + + if !issetMessage { + fieldId = 1 + goto RequiredFieldNotSetError + } + return nil +ReadStructBeginError: + return thrift.PrependError(fmt.Sprintf("%T read struct begin error: ", p), err) +ReadFieldBeginError: + return thrift.PrependError(fmt.Sprintf("%T read field %d begin error: ", p, fieldId), err) +ReadFieldError: + return thrift.PrependError(fmt.Sprintf("%T read field %d '%s' error: ", p, fieldId, fieldIDToName_EchoRequest[fieldId]), err) +SkipFieldError: + return thrift.PrependError(fmt.Sprintf("%T field %d skip type %d error: ", p, fieldId, fieldTypeId), err) + +ReadFieldEndError: + return thrift.PrependError(fmt.Sprintf("%T read field end error", p), err) +ReadStructEndError: + return thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err) +RequiredFieldNotSetError: + return thrift.NewTProtocolExceptionWithType(thrift.INVALID_DATA, fmt.Errorf("required field %s is not set", fieldIDToName_EchoRequest[fieldId])) +} + +func (p *EchoRequest) ReadField1(iprot thrift.TProtocol) error { + + if v, err := iprot.ReadString(); err != nil { + return err + } else { + p.Message = v + } + return nil +} + +func (p *EchoRequest) Write(oprot thrift.TProtocol) (err error) { + var fieldId int16 + if err = oprot.WriteStructBegin("EchoRequest"); err != nil { + goto WriteStructBeginError + } + if p != nil { + if err = p.writeField1(oprot); err != nil { + fieldId = 1 + goto WriteFieldError + } + } + if err = oprot.WriteFieldStop(); err != nil { + goto WriteFieldStopError + } + if err = oprot.WriteStructEnd(); err != nil { + goto WriteStructEndError + } + return nil +WriteStructBeginError: + return thrift.PrependError(fmt.Sprintf("%T write struct begin error: ", p), err) +WriteFieldError: + return thrift.PrependError(fmt.Sprintf("%T write field %d error: ", p, fieldId), err) +WriteFieldStopError: + return thrift.PrependError(fmt.Sprintf("%T write field stop error: ", p), err) +WriteStructEndError: + return thrift.PrependError(fmt.Sprintf("%T write struct end error: ", p), err) +} + +func (p *EchoRequest) writeField1(oprot thrift.TProtocol) (err error) { + if err = oprot.WriteFieldBegin("message", thrift.STRING, 1); err != nil { + goto WriteFieldBeginError + } + if err := oprot.WriteString(p.Message); err != nil { + return err + } + if err = oprot.WriteFieldEnd(); err != nil { + goto WriteFieldEndError + } + return nil +WriteFieldBeginError: + return thrift.PrependError(fmt.Sprintf("%T write field 1 begin error: ", p), err) +WriteFieldEndError: + return thrift.PrependError(fmt.Sprintf("%T write field 1 end error: ", p), err) +} + +func (p *EchoRequest) String() string { + if p == nil { + return "" + } + return fmt.Sprintf("EchoRequest(%+v)", *p) + +} + +func (p *EchoRequest) DeepEqual(ano *EchoRequest) bool { + if p == ano { + return true + } else if p == nil || ano == nil { + return false + } + if !p.Field1DeepEqual(ano.Message) { + return false + } + return true +} + +func (p *EchoRequest) Field1DeepEqual(src string) bool { + + if strings.Compare(p.Message, src) != 0 { + return false + } + return true +} + +type EchoResponse struct { + Message string `thrift:"message,1,required" frugal:"1,required,string" json:"message"` +} + +func NewEchoResponse() *EchoResponse { + return &EchoResponse{} +} + +func (p *EchoResponse) InitDefault() { + *p = EchoResponse{} +} + +func (p *EchoResponse) GetMessage() (v string) { + return p.Message +} +func (p *EchoResponse) SetMessage(val string) { + p.Message = val +} + +var fieldIDToName_EchoResponse = map[int16]string{ + 1: "message", +} + +func (p *EchoResponse) Read(iprot thrift.TProtocol) (err error) { + + var fieldTypeId thrift.TType + var fieldId int16 + var issetMessage bool = false + + if _, err = iprot.ReadStructBegin(); err != nil { + goto ReadStructBeginError + } + + for { + _, fieldTypeId, fieldId, err = iprot.ReadFieldBegin() + if err != nil { + goto ReadFieldBeginError + } + if fieldTypeId == thrift.STOP { + break + } + + switch fieldId { + case 1: + if fieldTypeId == thrift.STRING { + if err = p.ReadField1(iprot); err != nil { + goto ReadFieldError + } + issetMessage = true + } else if err = iprot.Skip(fieldTypeId); err != nil { + goto SkipFieldError + } + default: + if err = iprot.Skip(fieldTypeId); err != nil { + goto SkipFieldError + } + } + if err = iprot.ReadFieldEnd(); err != nil { + goto ReadFieldEndError + } + } + if err = iprot.ReadStructEnd(); err != nil { + goto ReadStructEndError + } + + if !issetMessage { + fieldId = 1 + goto RequiredFieldNotSetError + } + return nil +ReadStructBeginError: + return thrift.PrependError(fmt.Sprintf("%T read struct begin error: ", p), err) +ReadFieldBeginError: + return thrift.PrependError(fmt.Sprintf("%T read field %d begin error: ", p, fieldId), err) +ReadFieldError: + return thrift.PrependError(fmt.Sprintf("%T read field %d '%s' error: ", p, fieldId, fieldIDToName_EchoResponse[fieldId]), err) +SkipFieldError: + return thrift.PrependError(fmt.Sprintf("%T field %d skip type %d error: ", p, fieldId, fieldTypeId), err) + +ReadFieldEndError: + return thrift.PrependError(fmt.Sprintf("%T read field end error", p), err) +ReadStructEndError: + return thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err) +RequiredFieldNotSetError: + return thrift.NewTProtocolExceptionWithType(thrift.INVALID_DATA, fmt.Errorf("required field %s is not set", fieldIDToName_EchoResponse[fieldId])) +} + +func (p *EchoResponse) ReadField1(iprot thrift.TProtocol) error { + + if v, err := iprot.ReadString(); err != nil { + return err + } else { + p.Message = v + } + return nil +} + +func (p *EchoResponse) Write(oprot thrift.TProtocol) (err error) { + var fieldId int16 + if err = oprot.WriteStructBegin("EchoResponse"); err != nil { + goto WriteStructBeginError + } + if p != nil { + if err = p.writeField1(oprot); err != nil { + fieldId = 1 + goto WriteFieldError + } + } + if err = oprot.WriteFieldStop(); err != nil { + goto WriteFieldStopError + } + if err = oprot.WriteStructEnd(); err != nil { + goto WriteStructEndError + } + return nil +WriteStructBeginError: + return thrift.PrependError(fmt.Sprintf("%T write struct begin error: ", p), err) +WriteFieldError: + return thrift.PrependError(fmt.Sprintf("%T write field %d error: ", p, fieldId), err) +WriteFieldStopError: + return thrift.PrependError(fmt.Sprintf("%T write field stop error: ", p), err) +WriteStructEndError: + return thrift.PrependError(fmt.Sprintf("%T write struct end error: ", p), err) +} + +func (p *EchoResponse) writeField1(oprot thrift.TProtocol) (err error) { + if err = oprot.WriteFieldBegin("message", thrift.STRING, 1); err != nil { + goto WriteFieldBeginError + } + if err := oprot.WriteString(p.Message); err != nil { + return err + } + if err = oprot.WriteFieldEnd(); err != nil { + goto WriteFieldEndError + } + return nil +WriteFieldBeginError: + return thrift.PrependError(fmt.Sprintf("%T write field 1 begin error: ", p), err) +WriteFieldEndError: + return thrift.PrependError(fmt.Sprintf("%T write field 1 end error: ", p), err) +} + +func (p *EchoResponse) String() string { + if p == nil { + return "" + } + return fmt.Sprintf("EchoResponse(%+v)", *p) + +} + +func (p *EchoResponse) DeepEqual(ano *EchoResponse) bool { + if p == ano { + return true + } else if p == nil || ano == nil { + return false + } + if !p.Field1DeepEqual(ano.Message) { + return false + } + return true +} + +func (p *EchoResponse) Field1DeepEqual(src string) bool { + + if strings.Compare(p.Message, src) != 0 { + return false + } + return true +} + +type EchoException struct { + Message string `thrift:"message,1" frugal:"1,default,string" json:"message"` +} + +func NewEchoException() *EchoException { + return &EchoException{} +} + +func (p *EchoException) InitDefault() { + *p = EchoException{} +} + +func (p *EchoException) GetMessage() (v string) { + return p.Message +} +func (p *EchoException) SetMessage(val string) { + p.Message = val +} + +var fieldIDToName_EchoException = map[int16]string{ + 1: "message", +} + +func (p *EchoException) Read(iprot thrift.TProtocol) (err error) { + + var fieldTypeId thrift.TType + var fieldId int16 + + if _, err = iprot.ReadStructBegin(); err != nil { + goto ReadStructBeginError + } + + for { + _, fieldTypeId, fieldId, err = iprot.ReadFieldBegin() + if err != nil { + goto ReadFieldBeginError + } + if fieldTypeId == thrift.STOP { + break + } + + switch fieldId { + case 1: + if fieldTypeId == thrift.STRING { + if err = p.ReadField1(iprot); err != nil { + goto ReadFieldError + } + } else if err = iprot.Skip(fieldTypeId); err != nil { + goto SkipFieldError + } + default: + if err = iprot.Skip(fieldTypeId); err != nil { + goto SkipFieldError + } + } + if err = iprot.ReadFieldEnd(); err != nil { + goto ReadFieldEndError + } + } + if err = iprot.ReadStructEnd(); err != nil { + goto ReadStructEndError + } + + return nil +ReadStructBeginError: + return thrift.PrependError(fmt.Sprintf("%T read struct begin error: ", p), err) +ReadFieldBeginError: + return thrift.PrependError(fmt.Sprintf("%T read field %d begin error: ", p, fieldId), err) +ReadFieldError: + return thrift.PrependError(fmt.Sprintf("%T read field %d '%s' error: ", p, fieldId, fieldIDToName_EchoException[fieldId]), err) +SkipFieldError: + return thrift.PrependError(fmt.Sprintf("%T field %d skip type %d error: ", p, fieldId, fieldTypeId), err) + +ReadFieldEndError: + return thrift.PrependError(fmt.Sprintf("%T read field end error", p), err) +ReadStructEndError: + return thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err) +} + +func (p *EchoException) ReadField1(iprot thrift.TProtocol) error { + + if v, err := iprot.ReadString(); err != nil { + return err + } else { + p.Message = v + } + return nil +} + +func (p *EchoException) Write(oprot thrift.TProtocol) (err error) { + var fieldId int16 + if err = oprot.WriteStructBegin("EchoException"); err != nil { + goto WriteStructBeginError + } + if p != nil { + if err = p.writeField1(oprot); err != nil { + fieldId = 1 + goto WriteFieldError + } + } + if err = oprot.WriteFieldStop(); err != nil { + goto WriteFieldStopError + } + if err = oprot.WriteStructEnd(); err != nil { + goto WriteStructEndError + } + return nil +WriteStructBeginError: + return thrift.PrependError(fmt.Sprintf("%T write struct begin error: ", p), err) +WriteFieldError: + return thrift.PrependError(fmt.Sprintf("%T write field %d error: ", p, fieldId), err) +WriteFieldStopError: + return thrift.PrependError(fmt.Sprintf("%T write field stop error: ", p), err) +WriteStructEndError: + return thrift.PrependError(fmt.Sprintf("%T write struct end error: ", p), err) +} + +func (p *EchoException) writeField1(oprot thrift.TProtocol) (err error) { + if err = oprot.WriteFieldBegin("message", thrift.STRING, 1); err != nil { + goto WriteFieldBeginError + } + if err := oprot.WriteString(p.Message); err != nil { + return err + } + if err = oprot.WriteFieldEnd(); err != nil { + goto WriteFieldEndError + } + return nil +WriteFieldBeginError: + return thrift.PrependError(fmt.Sprintf("%T write field 1 begin error: ", p), err) +WriteFieldEndError: + return thrift.PrependError(fmt.Sprintf("%T write field 1 end error: ", p), err) +} + +func (p *EchoException) String() string { + if p == nil { + return "" + } + return fmt.Sprintf("EchoException(%+v)", *p) + +} +func (p *EchoException) Error() string { + return p.String() +} + +func (p *EchoException) DeepEqual(ano *EchoException) bool { + if p == ano { + return true + } else if p == nil || ano == nil { + return false + } + if !p.Field1DeepEqual(ano.Message) { + return false + } + return true +} + +func (p *EchoException) Field1DeepEqual(src string) bool { + + if strings.Compare(p.Message, src) != 0 { + return false + } + return true +} + +type EchoService interface { + EchoBidirectional(stream EchoService_EchoBidirectionalServer) (err error) + + EchoClient(stream EchoService_EchoClientServer) (err error) + + EchoServer(req *EchoRequest, stream EchoService_EchoServerServer) (err error) + + EchoUnary(ctx context.Context, req1 *EchoRequest) (r *EchoResponse, err error) + + EchoPingPong(ctx context.Context, req1 *EchoRequest, req2 *EchoRequest) (r *EchoResponse, err error) + + EchoOneway(ctx context.Context, req1 *EchoRequest) (err error) + + Ping(ctx context.Context) (err error) +} + +type EchoServiceClient struct { + c thrift.TClient +} + +func NewEchoServiceClientFactory(t thrift.TTransport, f thrift.TProtocolFactory) *EchoServiceClient { + return &EchoServiceClient{ + c: thrift.NewTStandardClient(f.GetProtocol(t), f.GetProtocol(t)), + } +} + +func NewEchoServiceClientProtocol(t thrift.TTransport, iprot thrift.TProtocol, oprot thrift.TProtocol) *EchoServiceClient { + return &EchoServiceClient{ + c: thrift.NewTStandardClient(iprot, oprot), + } +} + +func NewEchoServiceClient(c thrift.TClient) *EchoServiceClient { + return &EchoServiceClient{ + c: c, + } +} + +func (p *EchoServiceClient) Client_() thrift.TClient { + return p.c +} + +func (p *EchoServiceClient) EchoBidirectional(stream EchoService_EchoBidirectionalServer) (err error) { + panic("streaming method EchoService.EchoBidirectional(mode = bidirectional) not available, please use Kitex Thrift Streaming Client.") +} + +type EchoService_EchoBidirectionalServer interface { + streaming.Stream + + Recv() (*EchoRequest, error) + + Send(*EchoResponse) error +} + +func (p *EchoServiceClient) EchoClient(stream EchoService_EchoClientServer) (err error) { + panic("streaming method EchoService.EchoClient(mode = client) not available, please use Kitex Thrift Streaming Client.") +} + +type EchoService_EchoClientServer interface { + streaming.Stream + + Recv() (*EchoRequest, error) + + SendAndClose(*EchoResponse) error +} + +func (p *EchoServiceClient) EchoServer(req *EchoRequest, stream EchoService_EchoServerServer) (err error) { + panic("streaming method EchoService.EchoServer(mode = server) not available, please use Kitex Thrift Streaming Client.") +} + +type EchoService_EchoServerServer interface { + streaming.Stream + + Send(*EchoResponse) error +} + +func (p *EchoServiceClient) EchoUnary(ctx context.Context, req1 *EchoRequest) (r *EchoResponse, err error) { + panic("streaming method EchoService.EchoUnary(mode = unary) not available, please use Kitex Thrift Streaming Client.") +} +func (p *EchoServiceClient) EchoPingPong(ctx context.Context, req1 *EchoRequest, req2 *EchoRequest) (r *EchoResponse, err error) { + var _args EchoServiceEchoPingPongArgs + _args.Req1 = req1 + _args.Req2 = req2 + var _result EchoServiceEchoPingPongResult + if err = p.Client_().Call(ctx, "EchoPingPong", &_args, &_result); err != nil { + return + } + switch { + case _result.E != nil: + return r, _result.E + } + return _result.GetSuccess(), nil +} +func (p *EchoServiceClient) EchoOneway(ctx context.Context, req1 *EchoRequest) (err error) { + var _args EchoServiceEchoOnewayArgs + _args.Req1 = req1 + var _result EchoServiceEchoOnewayResult + if err = p.Client_().Call(ctx, "EchoOneway", &_args, &_result); err != nil { + return + } + return nil +} +func (p *EchoServiceClient) Ping(ctx context.Context) (err error) { + var _args EchoServicePingArgs + var _result EchoServicePingResult + if err = p.Client_().Call(ctx, "Ping", &_args, &_result); err != nil { + return + } + return nil +} + +type EchoServiceProcessor struct { + processorMap map[string]thrift.TProcessorFunction + handler EchoService +} + +func (p *EchoServiceProcessor) AddToProcessorMap(key string, processor thrift.TProcessorFunction) { + p.processorMap[key] = processor +} + +func (p *EchoServiceProcessor) GetProcessorFunction(key string) (processor thrift.TProcessorFunction, ok bool) { + processor, ok = p.processorMap[key] + return processor, ok +} + +func (p *EchoServiceProcessor) ProcessorMap() map[string]thrift.TProcessorFunction { + return p.processorMap +} + +func NewEchoServiceProcessor(handler EchoService) *EchoServiceProcessor { + self := &EchoServiceProcessor{handler: handler, processorMap: make(map[string]thrift.TProcessorFunction)} + self.AddToProcessorMap("EchoBidirectional", &echoServiceProcessorEchoBidirectional{handler: handler}) + self.AddToProcessorMap("EchoClient", &echoServiceProcessorEchoClient{handler: handler}) + self.AddToProcessorMap("EchoServer", &echoServiceProcessorEchoServer{handler: handler}) + self.AddToProcessorMap("EchoUnary", &echoServiceProcessorEchoUnary{handler: handler}) + self.AddToProcessorMap("EchoPingPong", &echoServiceProcessorEchoPingPong{handler: handler}) + self.AddToProcessorMap("EchoOneway", &echoServiceProcessorEchoOneway{handler: handler}) + self.AddToProcessorMap("Ping", &echoServiceProcessorPing{handler: handler}) + return self +} +func (p *EchoServiceProcessor) Process(ctx context.Context, iprot, oprot thrift.TProtocol) (success bool, err thrift.TException) { + name, _, seqId, err := iprot.ReadMessageBegin() + if err != nil { + return false, err + } + if processor, ok := p.GetProcessorFunction(name); ok { + return processor.Process(ctx, seqId, iprot, oprot) + } + iprot.Skip(thrift.STRUCT) + iprot.ReadMessageEnd() + x := thrift.NewTApplicationException(thrift.UNKNOWN_METHOD, "Unknown function "+name) + oprot.WriteMessageBegin(name, thrift.EXCEPTION, seqId) + x.Write(oprot) + oprot.WriteMessageEnd() + oprot.Flush(ctx) + return false, x +} + +type echoServiceProcessorEchoBidirectional struct { + handler EchoService +} + +func (p *echoServiceProcessorEchoBidirectional) Process(ctx context.Context, seqId int32, iprot, oprot thrift.TProtocol) (success bool, err thrift.TException) { + panic("streaming method EchoService.EchoBidirectional(mode = bidirectional) not available, please use Kitex Thrift Streaming Client.") +} + +type echoServiceProcessorEchoClient struct { + handler EchoService +} + +func (p *echoServiceProcessorEchoClient) Process(ctx context.Context, seqId int32, iprot, oprot thrift.TProtocol) (success bool, err thrift.TException) { + panic("streaming method EchoService.EchoClient(mode = client) not available, please use Kitex Thrift Streaming Client.") +} + +type echoServiceProcessorEchoServer struct { + handler EchoService +} + +func (p *echoServiceProcessorEchoServer) Process(ctx context.Context, seqId int32, iprot, oprot thrift.TProtocol) (success bool, err thrift.TException) { + panic("streaming method EchoService.EchoServer(mode = server) not available, please use Kitex Thrift Streaming Client.") +} + +type echoServiceProcessorEchoUnary struct { + handler EchoService +} + +func (p *echoServiceProcessorEchoUnary) Process(ctx context.Context, seqId int32, iprot, oprot thrift.TProtocol) (success bool, err thrift.TException) { + panic("streaming method EchoService.EchoUnary(mode = unary) not available, please use Kitex Thrift Streaming Client.") +} + +type echoServiceProcessorEchoPingPong struct { + handler EchoService +} + +func (p *echoServiceProcessorEchoPingPong) Process(ctx context.Context, seqId int32, iprot, oprot thrift.TProtocol) (success bool, err thrift.TException) { + args := EchoServiceEchoPingPongArgs{} + if err = args.Read(iprot); err != nil { + iprot.ReadMessageEnd() + x := thrift.NewTApplicationException(thrift.PROTOCOL_ERROR, err.Error()) + oprot.WriteMessageBegin("EchoPingPong", thrift.EXCEPTION, seqId) + x.Write(oprot) + oprot.WriteMessageEnd() + oprot.Flush(ctx) + return false, err + } + + iprot.ReadMessageEnd() + var err2 error + result := EchoServiceEchoPingPongResult{} + var retval *EchoResponse + if retval, err2 = p.handler.EchoPingPong(ctx, args.Req1, args.Req2); err2 != nil { + switch v := err2.(type) { + case *EchoException: + result.E = v + default: + x := thrift.NewTApplicationException(thrift.INTERNAL_ERROR, "Internal error processing EchoPingPong: "+err2.Error()) + oprot.WriteMessageBegin("EchoPingPong", thrift.EXCEPTION, seqId) + x.Write(oprot) + oprot.WriteMessageEnd() + oprot.Flush(ctx) + return true, err2 + } + } else { + result.Success = retval + } + if err2 = oprot.WriteMessageBegin("EchoPingPong", thrift.REPLY, seqId); err2 != nil { + err = err2 + } + if err2 = result.Write(oprot); err == nil && err2 != nil { + err = err2 + } + if err2 = oprot.WriteMessageEnd(); err == nil && err2 != nil { + err = err2 + } + if err2 = oprot.Flush(ctx); err == nil && err2 != nil { + err = err2 + } + if err != nil { + return + } + return true, err +} + +type echoServiceProcessorEchoOneway struct { + handler EchoService +} + +func (p *echoServiceProcessorEchoOneway) Process(ctx context.Context, seqId int32, iprot, oprot thrift.TProtocol) (success bool, err thrift.TException) { + args := EchoServiceEchoOnewayArgs{} + if err = args.Read(iprot); err != nil { + iprot.ReadMessageEnd() + x := thrift.NewTApplicationException(thrift.PROTOCOL_ERROR, err.Error()) + oprot.WriteMessageBegin("EchoOneway", thrift.EXCEPTION, seqId) + x.Write(oprot) + oprot.WriteMessageEnd() + oprot.Flush(ctx) + return false, err + } + + iprot.ReadMessageEnd() + var err2 error + result := EchoServiceEchoOnewayResult{} + if err2 = p.handler.EchoOneway(ctx, args.Req1); err2 != nil { + x := thrift.NewTApplicationException(thrift.INTERNAL_ERROR, "Internal error processing EchoOneway: "+err2.Error()) + oprot.WriteMessageBegin("EchoOneway", thrift.EXCEPTION, seqId) + x.Write(oprot) + oprot.WriteMessageEnd() + oprot.Flush(ctx) + return true, err2 + } + if err2 = oprot.WriteMessageBegin("EchoOneway", thrift.REPLY, seqId); err2 != nil { + err = err2 + } + if err2 = result.Write(oprot); err == nil && err2 != nil { + err = err2 + } + if err2 = oprot.WriteMessageEnd(); err == nil && err2 != nil { + err = err2 + } + if err2 = oprot.Flush(ctx); err == nil && err2 != nil { + err = err2 + } + if err != nil { + return + } + return true, err +} + +type echoServiceProcessorPing struct { + handler EchoService +} + +func (p *echoServiceProcessorPing) Process(ctx context.Context, seqId int32, iprot, oprot thrift.TProtocol) (success bool, err thrift.TException) { + args := EchoServicePingArgs{} + if err = args.Read(iprot); err != nil { + iprot.ReadMessageEnd() + x := thrift.NewTApplicationException(thrift.PROTOCOL_ERROR, err.Error()) + oprot.WriteMessageBegin("Ping", thrift.EXCEPTION, seqId) + x.Write(oprot) + oprot.WriteMessageEnd() + oprot.Flush(ctx) + return false, err + } + + iprot.ReadMessageEnd() + var err2 error + result := EchoServicePingResult{} + if err2 = p.handler.Ping(ctx); err2 != nil { + x := thrift.NewTApplicationException(thrift.INTERNAL_ERROR, "Internal error processing Ping: "+err2.Error()) + oprot.WriteMessageBegin("Ping", thrift.EXCEPTION, seqId) + x.Write(oprot) + oprot.WriteMessageEnd() + oprot.Flush(ctx) + return true, err2 + } + if err2 = oprot.WriteMessageBegin("Ping", thrift.REPLY, seqId); err2 != nil { + err = err2 + } + if err2 = result.Write(oprot); err == nil && err2 != nil { + err = err2 + } + if err2 = oprot.WriteMessageEnd(); err == nil && err2 != nil { + err = err2 + } + if err2 = oprot.Flush(ctx); err == nil && err2 != nil { + err = err2 + } + if err != nil { + return + } + return true, err +} + +type EchoServiceEchoBidirectionalArgs struct { + Req1 *EchoRequest `thrift:"req1,1" frugal:"1,default,EchoRequest" json:"req1"` +} + +func NewEchoServiceEchoBidirectionalArgs() *EchoServiceEchoBidirectionalArgs { + return &EchoServiceEchoBidirectionalArgs{} +} + +func (p *EchoServiceEchoBidirectionalArgs) InitDefault() { + *p = EchoServiceEchoBidirectionalArgs{} +} + +var EchoServiceEchoBidirectionalArgs_Req1_DEFAULT *EchoRequest + +func (p *EchoServiceEchoBidirectionalArgs) GetReq1() (v *EchoRequest) { + if !p.IsSetReq1() { + return EchoServiceEchoBidirectionalArgs_Req1_DEFAULT + } + return p.Req1 +} +func (p *EchoServiceEchoBidirectionalArgs) SetReq1(val *EchoRequest) { + p.Req1 = val +} + +var fieldIDToName_EchoServiceEchoBidirectionalArgs = map[int16]string{ + 1: "req1", +} + +func (p *EchoServiceEchoBidirectionalArgs) IsSetReq1() bool { + return p.Req1 != nil +} + +func (p *EchoServiceEchoBidirectionalArgs) Read(iprot thrift.TProtocol) (err error) { + + var fieldTypeId thrift.TType + var fieldId int16 + + if _, err = iprot.ReadStructBegin(); err != nil { + goto ReadStructBeginError + } + + for { + _, fieldTypeId, fieldId, err = iprot.ReadFieldBegin() + if err != nil { + goto ReadFieldBeginError + } + if fieldTypeId == thrift.STOP { + break + } + + switch fieldId { + case 1: + if fieldTypeId == thrift.STRUCT { + if err = p.ReadField1(iprot); err != nil { + goto ReadFieldError + } + } else if err = iprot.Skip(fieldTypeId); err != nil { + goto SkipFieldError + } + default: + if err = iprot.Skip(fieldTypeId); err != nil { + goto SkipFieldError + } + } + if err = iprot.ReadFieldEnd(); err != nil { + goto ReadFieldEndError + } + } + if err = iprot.ReadStructEnd(); err != nil { + goto ReadStructEndError + } + + return nil +ReadStructBeginError: + return thrift.PrependError(fmt.Sprintf("%T read struct begin error: ", p), err) +ReadFieldBeginError: + return thrift.PrependError(fmt.Sprintf("%T read field %d begin error: ", p, fieldId), err) +ReadFieldError: + return thrift.PrependError(fmt.Sprintf("%T read field %d '%s' error: ", p, fieldId, fieldIDToName_EchoServiceEchoBidirectionalArgs[fieldId]), err) +SkipFieldError: + return thrift.PrependError(fmt.Sprintf("%T field %d skip type %d error: ", p, fieldId, fieldTypeId), err) + +ReadFieldEndError: + return thrift.PrependError(fmt.Sprintf("%T read field end error", p), err) +ReadStructEndError: + return thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err) +} + +func (p *EchoServiceEchoBidirectionalArgs) ReadField1(iprot thrift.TProtocol) error { + p.Req1 = NewEchoRequest() + if err := p.Req1.Read(iprot); err != nil { + return err + } + return nil +} + +func (p *EchoServiceEchoBidirectionalArgs) Write(oprot thrift.TProtocol) (err error) { + var fieldId int16 + if err = oprot.WriteStructBegin("EchoBidirectional_args"); err != nil { + goto WriteStructBeginError + } + if p != nil { + if err = p.writeField1(oprot); err != nil { + fieldId = 1 + goto WriteFieldError + } + } + if err = oprot.WriteFieldStop(); err != nil { + goto WriteFieldStopError + } + if err = oprot.WriteStructEnd(); err != nil { + goto WriteStructEndError + } + return nil +WriteStructBeginError: + return thrift.PrependError(fmt.Sprintf("%T write struct begin error: ", p), err) +WriteFieldError: + return thrift.PrependError(fmt.Sprintf("%T write field %d error: ", p, fieldId), err) +WriteFieldStopError: + return thrift.PrependError(fmt.Sprintf("%T write field stop error: ", p), err) +WriteStructEndError: + return thrift.PrependError(fmt.Sprintf("%T write struct end error: ", p), err) +} + +func (p *EchoServiceEchoBidirectionalArgs) writeField1(oprot thrift.TProtocol) (err error) { + if err = oprot.WriteFieldBegin("req1", thrift.STRUCT, 1); err != nil { + goto WriteFieldBeginError + } + if err := p.Req1.Write(oprot); err != nil { + return err + } + if err = oprot.WriteFieldEnd(); err != nil { + goto WriteFieldEndError + } + return nil +WriteFieldBeginError: + return thrift.PrependError(fmt.Sprintf("%T write field 1 begin error: ", p), err) +WriteFieldEndError: + return thrift.PrependError(fmt.Sprintf("%T write field 1 end error: ", p), err) +} + +func (p *EchoServiceEchoBidirectionalArgs) String() string { + if p == nil { + return "" + } + return fmt.Sprintf("EchoServiceEchoBidirectionalArgs(%+v)", *p) + +} + +func (p *EchoServiceEchoBidirectionalArgs) DeepEqual(ano *EchoServiceEchoBidirectionalArgs) bool { + if p == ano { + return true + } else if p == nil || ano == nil { + return false + } + if !p.Field1DeepEqual(ano.Req1) { + return false + } + return true +} + +func (p *EchoServiceEchoBidirectionalArgs) Field1DeepEqual(src *EchoRequest) bool { + + if !p.Req1.DeepEqual(src) { + return false + } + return true +} + +type EchoServiceEchoBidirectionalResult struct { + Success *EchoResponse `thrift:"success,0,optional" frugal:"0,optional,EchoResponse" json:"success,omitempty"` +} + +func NewEchoServiceEchoBidirectionalResult() *EchoServiceEchoBidirectionalResult { + return &EchoServiceEchoBidirectionalResult{} +} + +func (p *EchoServiceEchoBidirectionalResult) InitDefault() { + *p = EchoServiceEchoBidirectionalResult{} +} + +var EchoServiceEchoBidirectionalResult_Success_DEFAULT *EchoResponse + +func (p *EchoServiceEchoBidirectionalResult) GetSuccess() (v *EchoResponse) { + if !p.IsSetSuccess() { + return EchoServiceEchoBidirectionalResult_Success_DEFAULT + } + return p.Success +} +func (p *EchoServiceEchoBidirectionalResult) SetSuccess(x interface{}) { + p.Success = x.(*EchoResponse) +} + +var fieldIDToName_EchoServiceEchoBidirectionalResult = map[int16]string{ + 0: "success", +} + +func (p *EchoServiceEchoBidirectionalResult) IsSetSuccess() bool { + return p.Success != nil +} + +func (p *EchoServiceEchoBidirectionalResult) Read(iprot thrift.TProtocol) (err error) { + + var fieldTypeId thrift.TType + var fieldId int16 + + if _, err = iprot.ReadStructBegin(); err != nil { + goto ReadStructBeginError + } + + for { + _, fieldTypeId, fieldId, err = iprot.ReadFieldBegin() + if err != nil { + goto ReadFieldBeginError + } + if fieldTypeId == thrift.STOP { + break + } + + switch fieldId { + case 0: + if fieldTypeId == thrift.STRUCT { + if err = p.ReadField0(iprot); err != nil { + goto ReadFieldError + } + } else if err = iprot.Skip(fieldTypeId); err != nil { + goto SkipFieldError + } + default: + if err = iprot.Skip(fieldTypeId); err != nil { + goto SkipFieldError + } + } + if err = iprot.ReadFieldEnd(); err != nil { + goto ReadFieldEndError + } + } + if err = iprot.ReadStructEnd(); err != nil { + goto ReadStructEndError + } + + return nil +ReadStructBeginError: + return thrift.PrependError(fmt.Sprintf("%T read struct begin error: ", p), err) +ReadFieldBeginError: + return thrift.PrependError(fmt.Sprintf("%T read field %d begin error: ", p, fieldId), err) +ReadFieldError: + return thrift.PrependError(fmt.Sprintf("%T read field %d '%s' error: ", p, fieldId, fieldIDToName_EchoServiceEchoBidirectionalResult[fieldId]), err) +SkipFieldError: + return thrift.PrependError(fmt.Sprintf("%T field %d skip type %d error: ", p, fieldId, fieldTypeId), err) + +ReadFieldEndError: + return thrift.PrependError(fmt.Sprintf("%T read field end error", p), err) +ReadStructEndError: + return thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err) +} + +func (p *EchoServiceEchoBidirectionalResult) ReadField0(iprot thrift.TProtocol) error { + p.Success = NewEchoResponse() + if err := p.Success.Read(iprot); err != nil { + return err + } + return nil +} + +func (p *EchoServiceEchoBidirectionalResult) Write(oprot thrift.TProtocol) (err error) { + var fieldId int16 + if err = oprot.WriteStructBegin("EchoBidirectional_result"); err != nil { + goto WriteStructBeginError + } + if p != nil { + if err = p.writeField0(oprot); err != nil { + fieldId = 0 + goto WriteFieldError + } + } + if err = oprot.WriteFieldStop(); err != nil { + goto WriteFieldStopError + } + if err = oprot.WriteStructEnd(); err != nil { + goto WriteStructEndError + } + return nil +WriteStructBeginError: + return thrift.PrependError(fmt.Sprintf("%T write struct begin error: ", p), err) +WriteFieldError: + return thrift.PrependError(fmt.Sprintf("%T write field %d error: ", p, fieldId), err) +WriteFieldStopError: + return thrift.PrependError(fmt.Sprintf("%T write field stop error: ", p), err) +WriteStructEndError: + return thrift.PrependError(fmt.Sprintf("%T write struct end error: ", p), err) +} + +func (p *EchoServiceEchoBidirectionalResult) writeField0(oprot thrift.TProtocol) (err error) { + if p.IsSetSuccess() { + if err = oprot.WriteFieldBegin("success", thrift.STRUCT, 0); err != nil { + goto WriteFieldBeginError + } + if err := p.Success.Write(oprot); err != nil { + return err + } + if err = oprot.WriteFieldEnd(); err != nil { + goto WriteFieldEndError + } + } + return nil +WriteFieldBeginError: + return thrift.PrependError(fmt.Sprintf("%T write field 0 begin error: ", p), err) +WriteFieldEndError: + return thrift.PrependError(fmt.Sprintf("%T write field 0 end error: ", p), err) +} + +func (p *EchoServiceEchoBidirectionalResult) String() string { + if p == nil { + return "" + } + return fmt.Sprintf("EchoServiceEchoBidirectionalResult(%+v)", *p) + +} + +func (p *EchoServiceEchoBidirectionalResult) DeepEqual(ano *EchoServiceEchoBidirectionalResult) bool { + if p == ano { + return true + } else if p == nil || ano == nil { + return false + } + if !p.Field0DeepEqual(ano.Success) { + return false + } + return true +} + +func (p *EchoServiceEchoBidirectionalResult) Field0DeepEqual(src *EchoResponse) bool { + + if !p.Success.DeepEqual(src) { + return false + } + return true +} + +type EchoServiceEchoClientArgs struct { + Req1 *EchoRequest `thrift:"req1,1" frugal:"1,default,EchoRequest" json:"req1"` +} + +func NewEchoServiceEchoClientArgs() *EchoServiceEchoClientArgs { + return &EchoServiceEchoClientArgs{} +} + +func (p *EchoServiceEchoClientArgs) InitDefault() { + *p = EchoServiceEchoClientArgs{} +} + +var EchoServiceEchoClientArgs_Req1_DEFAULT *EchoRequest + +func (p *EchoServiceEchoClientArgs) GetReq1() (v *EchoRequest) { + if !p.IsSetReq1() { + return EchoServiceEchoClientArgs_Req1_DEFAULT + } + return p.Req1 +} +func (p *EchoServiceEchoClientArgs) SetReq1(val *EchoRequest) { + p.Req1 = val +} + +var fieldIDToName_EchoServiceEchoClientArgs = map[int16]string{ + 1: "req1", +} + +func (p *EchoServiceEchoClientArgs) IsSetReq1() bool { + return p.Req1 != nil +} + +func (p *EchoServiceEchoClientArgs) Read(iprot thrift.TProtocol) (err error) { + + var fieldTypeId thrift.TType + var fieldId int16 + + if _, err = iprot.ReadStructBegin(); err != nil { + goto ReadStructBeginError + } + + for { + _, fieldTypeId, fieldId, err = iprot.ReadFieldBegin() + if err != nil { + goto ReadFieldBeginError + } + if fieldTypeId == thrift.STOP { + break + } + + switch fieldId { + case 1: + if fieldTypeId == thrift.STRUCT { + if err = p.ReadField1(iprot); err != nil { + goto ReadFieldError + } + } else if err = iprot.Skip(fieldTypeId); err != nil { + goto SkipFieldError + } + default: + if err = iprot.Skip(fieldTypeId); err != nil { + goto SkipFieldError + } + } + if err = iprot.ReadFieldEnd(); err != nil { + goto ReadFieldEndError + } + } + if err = iprot.ReadStructEnd(); err != nil { + goto ReadStructEndError + } + + return nil +ReadStructBeginError: + return thrift.PrependError(fmt.Sprintf("%T read struct begin error: ", p), err) +ReadFieldBeginError: + return thrift.PrependError(fmt.Sprintf("%T read field %d begin error: ", p, fieldId), err) +ReadFieldError: + return thrift.PrependError(fmt.Sprintf("%T read field %d '%s' error: ", p, fieldId, fieldIDToName_EchoServiceEchoClientArgs[fieldId]), err) +SkipFieldError: + return thrift.PrependError(fmt.Sprintf("%T field %d skip type %d error: ", p, fieldId, fieldTypeId), err) + +ReadFieldEndError: + return thrift.PrependError(fmt.Sprintf("%T read field end error", p), err) +ReadStructEndError: + return thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err) +} + +func (p *EchoServiceEchoClientArgs) ReadField1(iprot thrift.TProtocol) error { + p.Req1 = NewEchoRequest() + if err := p.Req1.Read(iprot); err != nil { + return err + } + return nil +} + +func (p *EchoServiceEchoClientArgs) Write(oprot thrift.TProtocol) (err error) { + var fieldId int16 + if err = oprot.WriteStructBegin("EchoClient_args"); err != nil { + goto WriteStructBeginError + } + if p != nil { + if err = p.writeField1(oprot); err != nil { + fieldId = 1 + goto WriteFieldError + } + } + if err = oprot.WriteFieldStop(); err != nil { + goto WriteFieldStopError + } + if err = oprot.WriteStructEnd(); err != nil { + goto WriteStructEndError + } + return nil +WriteStructBeginError: + return thrift.PrependError(fmt.Sprintf("%T write struct begin error: ", p), err) +WriteFieldError: + return thrift.PrependError(fmt.Sprintf("%T write field %d error: ", p, fieldId), err) +WriteFieldStopError: + return thrift.PrependError(fmt.Sprintf("%T write field stop error: ", p), err) +WriteStructEndError: + return thrift.PrependError(fmt.Sprintf("%T write struct end error: ", p), err) +} + +func (p *EchoServiceEchoClientArgs) writeField1(oprot thrift.TProtocol) (err error) { + if err = oprot.WriteFieldBegin("req1", thrift.STRUCT, 1); err != nil { + goto WriteFieldBeginError + } + if err := p.Req1.Write(oprot); err != nil { + return err + } + if err = oprot.WriteFieldEnd(); err != nil { + goto WriteFieldEndError + } + return nil +WriteFieldBeginError: + return thrift.PrependError(fmt.Sprintf("%T write field 1 begin error: ", p), err) +WriteFieldEndError: + return thrift.PrependError(fmt.Sprintf("%T write field 1 end error: ", p), err) +} + +func (p *EchoServiceEchoClientArgs) String() string { + if p == nil { + return "" + } + return fmt.Sprintf("EchoServiceEchoClientArgs(%+v)", *p) + +} + +func (p *EchoServiceEchoClientArgs) DeepEqual(ano *EchoServiceEchoClientArgs) bool { + if p == ano { + return true + } else if p == nil || ano == nil { + return false + } + if !p.Field1DeepEqual(ano.Req1) { + return false + } + return true +} + +func (p *EchoServiceEchoClientArgs) Field1DeepEqual(src *EchoRequest) bool { + + if !p.Req1.DeepEqual(src) { + return false + } + return true +} + +type EchoServiceEchoClientResult struct { + Success *EchoResponse `thrift:"success,0,optional" frugal:"0,optional,EchoResponse" json:"success,omitempty"` +} + +func NewEchoServiceEchoClientResult() *EchoServiceEchoClientResult { + return &EchoServiceEchoClientResult{} +} + +func (p *EchoServiceEchoClientResult) InitDefault() { + *p = EchoServiceEchoClientResult{} +} + +var EchoServiceEchoClientResult_Success_DEFAULT *EchoResponse + +func (p *EchoServiceEchoClientResult) GetSuccess() (v *EchoResponse) { + if !p.IsSetSuccess() { + return EchoServiceEchoClientResult_Success_DEFAULT + } + return p.Success +} +func (p *EchoServiceEchoClientResult) SetSuccess(x interface{}) { + p.Success = x.(*EchoResponse) +} + +var fieldIDToName_EchoServiceEchoClientResult = map[int16]string{ + 0: "success", +} + +func (p *EchoServiceEchoClientResult) IsSetSuccess() bool { + return p.Success != nil +} + +func (p *EchoServiceEchoClientResult) Read(iprot thrift.TProtocol) (err error) { + + var fieldTypeId thrift.TType + var fieldId int16 + + if _, err = iprot.ReadStructBegin(); err != nil { + goto ReadStructBeginError + } + + for { + _, fieldTypeId, fieldId, err = iprot.ReadFieldBegin() + if err != nil { + goto ReadFieldBeginError + } + if fieldTypeId == thrift.STOP { + break + } + + switch fieldId { + case 0: + if fieldTypeId == thrift.STRUCT { + if err = p.ReadField0(iprot); err != nil { + goto ReadFieldError + } + } else if err = iprot.Skip(fieldTypeId); err != nil { + goto SkipFieldError + } + default: + if err = iprot.Skip(fieldTypeId); err != nil { + goto SkipFieldError + } + } + if err = iprot.ReadFieldEnd(); err != nil { + goto ReadFieldEndError + } + } + if err = iprot.ReadStructEnd(); err != nil { + goto ReadStructEndError + } + + return nil +ReadStructBeginError: + return thrift.PrependError(fmt.Sprintf("%T read struct begin error: ", p), err) +ReadFieldBeginError: + return thrift.PrependError(fmt.Sprintf("%T read field %d begin error: ", p, fieldId), err) +ReadFieldError: + return thrift.PrependError(fmt.Sprintf("%T read field %d '%s' error: ", p, fieldId, fieldIDToName_EchoServiceEchoClientResult[fieldId]), err) +SkipFieldError: + return thrift.PrependError(fmt.Sprintf("%T field %d skip type %d error: ", p, fieldId, fieldTypeId), err) + +ReadFieldEndError: + return thrift.PrependError(fmt.Sprintf("%T read field end error", p), err) +ReadStructEndError: + return thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err) +} + +func (p *EchoServiceEchoClientResult) ReadField0(iprot thrift.TProtocol) error { + p.Success = NewEchoResponse() + if err := p.Success.Read(iprot); err != nil { + return err + } + return nil +} + +func (p *EchoServiceEchoClientResult) Write(oprot thrift.TProtocol) (err error) { + var fieldId int16 + if err = oprot.WriteStructBegin("EchoClient_result"); err != nil { + goto WriteStructBeginError + } + if p != nil { + if err = p.writeField0(oprot); err != nil { + fieldId = 0 + goto WriteFieldError + } + } + if err = oprot.WriteFieldStop(); err != nil { + goto WriteFieldStopError + } + if err = oprot.WriteStructEnd(); err != nil { + goto WriteStructEndError + } + return nil +WriteStructBeginError: + return thrift.PrependError(fmt.Sprintf("%T write struct begin error: ", p), err) +WriteFieldError: + return thrift.PrependError(fmt.Sprintf("%T write field %d error: ", p, fieldId), err) +WriteFieldStopError: + return thrift.PrependError(fmt.Sprintf("%T write field stop error: ", p), err) +WriteStructEndError: + return thrift.PrependError(fmt.Sprintf("%T write struct end error: ", p), err) +} + +func (p *EchoServiceEchoClientResult) writeField0(oprot thrift.TProtocol) (err error) { + if p.IsSetSuccess() { + if err = oprot.WriteFieldBegin("success", thrift.STRUCT, 0); err != nil { + goto WriteFieldBeginError + } + if err := p.Success.Write(oprot); err != nil { + return err + } + if err = oprot.WriteFieldEnd(); err != nil { + goto WriteFieldEndError + } + } + return nil +WriteFieldBeginError: + return thrift.PrependError(fmt.Sprintf("%T write field 0 begin error: ", p), err) +WriteFieldEndError: + return thrift.PrependError(fmt.Sprintf("%T write field 0 end error: ", p), err) +} + +func (p *EchoServiceEchoClientResult) String() string { + if p == nil { + return "" + } + return fmt.Sprintf("EchoServiceEchoClientResult(%+v)", *p) + +} + +func (p *EchoServiceEchoClientResult) DeepEqual(ano *EchoServiceEchoClientResult) bool { + if p == ano { + return true + } else if p == nil || ano == nil { + return false + } + if !p.Field0DeepEqual(ano.Success) { + return false + } + return true +} + +func (p *EchoServiceEchoClientResult) Field0DeepEqual(src *EchoResponse) bool { + + if !p.Success.DeepEqual(src) { + return false + } + return true +} + +type EchoServiceEchoServerArgs struct { + Req1 *EchoRequest `thrift:"req1,1" frugal:"1,default,EchoRequest" json:"req1"` +} + +func NewEchoServiceEchoServerArgs() *EchoServiceEchoServerArgs { + return &EchoServiceEchoServerArgs{} +} + +func (p *EchoServiceEchoServerArgs) InitDefault() { + *p = EchoServiceEchoServerArgs{} +} + +var EchoServiceEchoServerArgs_Req1_DEFAULT *EchoRequest + +func (p *EchoServiceEchoServerArgs) GetReq1() (v *EchoRequest) { + if !p.IsSetReq1() { + return EchoServiceEchoServerArgs_Req1_DEFAULT + } + return p.Req1 +} +func (p *EchoServiceEchoServerArgs) SetReq1(val *EchoRequest) { + p.Req1 = val +} + +var fieldIDToName_EchoServiceEchoServerArgs = map[int16]string{ + 1: "req1", +} + +func (p *EchoServiceEchoServerArgs) IsSetReq1() bool { + return p.Req1 != nil +} + +func (p *EchoServiceEchoServerArgs) Read(iprot thrift.TProtocol) (err error) { + + var fieldTypeId thrift.TType + var fieldId int16 + + if _, err = iprot.ReadStructBegin(); err != nil { + goto ReadStructBeginError + } + + for { + _, fieldTypeId, fieldId, err = iprot.ReadFieldBegin() + if err != nil { + goto ReadFieldBeginError + } + if fieldTypeId == thrift.STOP { + break + } + + switch fieldId { + case 1: + if fieldTypeId == thrift.STRUCT { + if err = p.ReadField1(iprot); err != nil { + goto ReadFieldError + } + } else if err = iprot.Skip(fieldTypeId); err != nil { + goto SkipFieldError + } + default: + if err = iprot.Skip(fieldTypeId); err != nil { + goto SkipFieldError + } + } + if err = iprot.ReadFieldEnd(); err != nil { + goto ReadFieldEndError + } + } + if err = iprot.ReadStructEnd(); err != nil { + goto ReadStructEndError + } + + return nil +ReadStructBeginError: + return thrift.PrependError(fmt.Sprintf("%T read struct begin error: ", p), err) +ReadFieldBeginError: + return thrift.PrependError(fmt.Sprintf("%T read field %d begin error: ", p, fieldId), err) +ReadFieldError: + return thrift.PrependError(fmt.Sprintf("%T read field %d '%s' error: ", p, fieldId, fieldIDToName_EchoServiceEchoServerArgs[fieldId]), err) +SkipFieldError: + return thrift.PrependError(fmt.Sprintf("%T field %d skip type %d error: ", p, fieldId, fieldTypeId), err) + +ReadFieldEndError: + return thrift.PrependError(fmt.Sprintf("%T read field end error", p), err) +ReadStructEndError: + return thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err) +} + +func (p *EchoServiceEchoServerArgs) ReadField1(iprot thrift.TProtocol) error { + p.Req1 = NewEchoRequest() + if err := p.Req1.Read(iprot); err != nil { + return err + } + return nil +} + +func (p *EchoServiceEchoServerArgs) Write(oprot thrift.TProtocol) (err error) { + var fieldId int16 + if err = oprot.WriteStructBegin("EchoServer_args"); err != nil { + goto WriteStructBeginError + } + if p != nil { + if err = p.writeField1(oprot); err != nil { + fieldId = 1 + goto WriteFieldError + } + } + if err = oprot.WriteFieldStop(); err != nil { + goto WriteFieldStopError + } + if err = oprot.WriteStructEnd(); err != nil { + goto WriteStructEndError + } + return nil +WriteStructBeginError: + return thrift.PrependError(fmt.Sprintf("%T write struct begin error: ", p), err) +WriteFieldError: + return thrift.PrependError(fmt.Sprintf("%T write field %d error: ", p, fieldId), err) +WriteFieldStopError: + return thrift.PrependError(fmt.Sprintf("%T write field stop error: ", p), err) +WriteStructEndError: + return thrift.PrependError(fmt.Sprintf("%T write struct end error: ", p), err) +} + +func (p *EchoServiceEchoServerArgs) writeField1(oprot thrift.TProtocol) (err error) { + if err = oprot.WriteFieldBegin("req1", thrift.STRUCT, 1); err != nil { + goto WriteFieldBeginError + } + if err := p.Req1.Write(oprot); err != nil { + return err + } + if err = oprot.WriteFieldEnd(); err != nil { + goto WriteFieldEndError + } + return nil +WriteFieldBeginError: + return thrift.PrependError(fmt.Sprintf("%T write field 1 begin error: ", p), err) +WriteFieldEndError: + return thrift.PrependError(fmt.Sprintf("%T write field 1 end error: ", p), err) +} + +func (p *EchoServiceEchoServerArgs) String() string { + if p == nil { + return "" + } + return fmt.Sprintf("EchoServiceEchoServerArgs(%+v)", *p) + +} + +func (p *EchoServiceEchoServerArgs) DeepEqual(ano *EchoServiceEchoServerArgs) bool { + if p == ano { + return true + } else if p == nil || ano == nil { + return false + } + if !p.Field1DeepEqual(ano.Req1) { + return false + } + return true +} + +func (p *EchoServiceEchoServerArgs) Field1DeepEqual(src *EchoRequest) bool { + + if !p.Req1.DeepEqual(src) { + return false + } + return true +} + +type EchoServiceEchoServerResult struct { + Success *EchoResponse `thrift:"success,0,optional" frugal:"0,optional,EchoResponse" json:"success,omitempty"` +} + +func NewEchoServiceEchoServerResult() *EchoServiceEchoServerResult { + return &EchoServiceEchoServerResult{} +} + +func (p *EchoServiceEchoServerResult) InitDefault() { + *p = EchoServiceEchoServerResult{} +} + +var EchoServiceEchoServerResult_Success_DEFAULT *EchoResponse + +func (p *EchoServiceEchoServerResult) GetSuccess() (v *EchoResponse) { + if !p.IsSetSuccess() { + return EchoServiceEchoServerResult_Success_DEFAULT + } + return p.Success +} +func (p *EchoServiceEchoServerResult) SetSuccess(x interface{}) { + p.Success = x.(*EchoResponse) +} + +var fieldIDToName_EchoServiceEchoServerResult = map[int16]string{ + 0: "success", +} + +func (p *EchoServiceEchoServerResult) IsSetSuccess() bool { + return p.Success != nil +} + +func (p *EchoServiceEchoServerResult) Read(iprot thrift.TProtocol) (err error) { + + var fieldTypeId thrift.TType + var fieldId int16 + + if _, err = iprot.ReadStructBegin(); err != nil { + goto ReadStructBeginError + } + + for { + _, fieldTypeId, fieldId, err = iprot.ReadFieldBegin() + if err != nil { + goto ReadFieldBeginError + } + if fieldTypeId == thrift.STOP { + break + } + + switch fieldId { + case 0: + if fieldTypeId == thrift.STRUCT { + if err = p.ReadField0(iprot); err != nil { + goto ReadFieldError + } + } else if err = iprot.Skip(fieldTypeId); err != nil { + goto SkipFieldError + } + default: + if err = iprot.Skip(fieldTypeId); err != nil { + goto SkipFieldError + } + } + if err = iprot.ReadFieldEnd(); err != nil { + goto ReadFieldEndError + } + } + if err = iprot.ReadStructEnd(); err != nil { + goto ReadStructEndError + } + + return nil +ReadStructBeginError: + return thrift.PrependError(fmt.Sprintf("%T read struct begin error: ", p), err) +ReadFieldBeginError: + return thrift.PrependError(fmt.Sprintf("%T read field %d begin error: ", p, fieldId), err) +ReadFieldError: + return thrift.PrependError(fmt.Sprintf("%T read field %d '%s' error: ", p, fieldId, fieldIDToName_EchoServiceEchoServerResult[fieldId]), err) +SkipFieldError: + return thrift.PrependError(fmt.Sprintf("%T field %d skip type %d error: ", p, fieldId, fieldTypeId), err) + +ReadFieldEndError: + return thrift.PrependError(fmt.Sprintf("%T read field end error", p), err) +ReadStructEndError: + return thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err) +} + +func (p *EchoServiceEchoServerResult) ReadField0(iprot thrift.TProtocol) error { + p.Success = NewEchoResponse() + if err := p.Success.Read(iprot); err != nil { + return err + } + return nil +} + +func (p *EchoServiceEchoServerResult) Write(oprot thrift.TProtocol) (err error) { + var fieldId int16 + if err = oprot.WriteStructBegin("EchoServer_result"); err != nil { + goto WriteStructBeginError + } + if p != nil { + if err = p.writeField0(oprot); err != nil { + fieldId = 0 + goto WriteFieldError + } + } + if err = oprot.WriteFieldStop(); err != nil { + goto WriteFieldStopError + } + if err = oprot.WriteStructEnd(); err != nil { + goto WriteStructEndError + } + return nil +WriteStructBeginError: + return thrift.PrependError(fmt.Sprintf("%T write struct begin error: ", p), err) +WriteFieldError: + return thrift.PrependError(fmt.Sprintf("%T write field %d error: ", p, fieldId), err) +WriteFieldStopError: + return thrift.PrependError(fmt.Sprintf("%T write field stop error: ", p), err) +WriteStructEndError: + return thrift.PrependError(fmt.Sprintf("%T write struct end error: ", p), err) +} + +func (p *EchoServiceEchoServerResult) writeField0(oprot thrift.TProtocol) (err error) { + if p.IsSetSuccess() { + if err = oprot.WriteFieldBegin("success", thrift.STRUCT, 0); err != nil { + goto WriteFieldBeginError + } + if err := p.Success.Write(oprot); err != nil { + return err + } + if err = oprot.WriteFieldEnd(); err != nil { + goto WriteFieldEndError + } + } + return nil +WriteFieldBeginError: + return thrift.PrependError(fmt.Sprintf("%T write field 0 begin error: ", p), err) +WriteFieldEndError: + return thrift.PrependError(fmt.Sprintf("%T write field 0 end error: ", p), err) +} + +func (p *EchoServiceEchoServerResult) String() string { + if p == nil { + return "" + } + return fmt.Sprintf("EchoServiceEchoServerResult(%+v)", *p) + +} + +func (p *EchoServiceEchoServerResult) DeepEqual(ano *EchoServiceEchoServerResult) bool { + if p == ano { + return true + } else if p == nil || ano == nil { + return false + } + if !p.Field0DeepEqual(ano.Success) { + return false + } + return true +} + +func (p *EchoServiceEchoServerResult) Field0DeepEqual(src *EchoResponse) bool { + + if !p.Success.DeepEqual(src) { + return false + } + return true +} + +type EchoServiceEchoUnaryArgs struct { + Req1 *EchoRequest `thrift:"req1,1" frugal:"1,default,EchoRequest" json:"req1"` +} + +func NewEchoServiceEchoUnaryArgs() *EchoServiceEchoUnaryArgs { + return &EchoServiceEchoUnaryArgs{} +} + +func (p *EchoServiceEchoUnaryArgs) InitDefault() { + *p = EchoServiceEchoUnaryArgs{} +} + +var EchoServiceEchoUnaryArgs_Req1_DEFAULT *EchoRequest + +func (p *EchoServiceEchoUnaryArgs) GetReq1() (v *EchoRequest) { + if !p.IsSetReq1() { + return EchoServiceEchoUnaryArgs_Req1_DEFAULT + } + return p.Req1 +} +func (p *EchoServiceEchoUnaryArgs) SetReq1(val *EchoRequest) { + p.Req1 = val +} + +var fieldIDToName_EchoServiceEchoUnaryArgs = map[int16]string{ + 1: "req1", +} + +func (p *EchoServiceEchoUnaryArgs) IsSetReq1() bool { + return p.Req1 != nil +} + +func (p *EchoServiceEchoUnaryArgs) Read(iprot thrift.TProtocol) (err error) { + + var fieldTypeId thrift.TType + var fieldId int16 + + if _, err = iprot.ReadStructBegin(); err != nil { + goto ReadStructBeginError + } + + for { + _, fieldTypeId, fieldId, err = iprot.ReadFieldBegin() + if err != nil { + goto ReadFieldBeginError + } + if fieldTypeId == thrift.STOP { + break + } + + switch fieldId { + case 1: + if fieldTypeId == thrift.STRUCT { + if err = p.ReadField1(iprot); err != nil { + goto ReadFieldError + } + } else if err = iprot.Skip(fieldTypeId); err != nil { + goto SkipFieldError + } + default: + if err = iprot.Skip(fieldTypeId); err != nil { + goto SkipFieldError + } + } + if err = iprot.ReadFieldEnd(); err != nil { + goto ReadFieldEndError + } + } + if err = iprot.ReadStructEnd(); err != nil { + goto ReadStructEndError + } + + return nil +ReadStructBeginError: + return thrift.PrependError(fmt.Sprintf("%T read struct begin error: ", p), err) +ReadFieldBeginError: + return thrift.PrependError(fmt.Sprintf("%T read field %d begin error: ", p, fieldId), err) +ReadFieldError: + return thrift.PrependError(fmt.Sprintf("%T read field %d '%s' error: ", p, fieldId, fieldIDToName_EchoServiceEchoUnaryArgs[fieldId]), err) +SkipFieldError: + return thrift.PrependError(fmt.Sprintf("%T field %d skip type %d error: ", p, fieldId, fieldTypeId), err) + +ReadFieldEndError: + return thrift.PrependError(fmt.Sprintf("%T read field end error", p), err) +ReadStructEndError: + return thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err) +} + +func (p *EchoServiceEchoUnaryArgs) ReadField1(iprot thrift.TProtocol) error { + p.Req1 = NewEchoRequest() + if err := p.Req1.Read(iprot); err != nil { + return err + } + return nil +} + +func (p *EchoServiceEchoUnaryArgs) Write(oprot thrift.TProtocol) (err error) { + var fieldId int16 + if err = oprot.WriteStructBegin("EchoUnary_args"); err != nil { + goto WriteStructBeginError + } + if p != nil { + if err = p.writeField1(oprot); err != nil { + fieldId = 1 + goto WriteFieldError + } + } + if err = oprot.WriteFieldStop(); err != nil { + goto WriteFieldStopError + } + if err = oprot.WriteStructEnd(); err != nil { + goto WriteStructEndError + } + return nil +WriteStructBeginError: + return thrift.PrependError(fmt.Sprintf("%T write struct begin error: ", p), err) +WriteFieldError: + return thrift.PrependError(fmt.Sprintf("%T write field %d error: ", p, fieldId), err) +WriteFieldStopError: + return thrift.PrependError(fmt.Sprintf("%T write field stop error: ", p), err) +WriteStructEndError: + return thrift.PrependError(fmt.Sprintf("%T write struct end error: ", p), err) +} + +func (p *EchoServiceEchoUnaryArgs) writeField1(oprot thrift.TProtocol) (err error) { + if err = oprot.WriteFieldBegin("req1", thrift.STRUCT, 1); err != nil { + goto WriteFieldBeginError + } + if err := p.Req1.Write(oprot); err != nil { + return err + } + if err = oprot.WriteFieldEnd(); err != nil { + goto WriteFieldEndError + } + return nil +WriteFieldBeginError: + return thrift.PrependError(fmt.Sprintf("%T write field 1 begin error: ", p), err) +WriteFieldEndError: + return thrift.PrependError(fmt.Sprintf("%T write field 1 end error: ", p), err) +} + +func (p *EchoServiceEchoUnaryArgs) String() string { + if p == nil { + return "" + } + return fmt.Sprintf("EchoServiceEchoUnaryArgs(%+v)", *p) + +} + +func (p *EchoServiceEchoUnaryArgs) DeepEqual(ano *EchoServiceEchoUnaryArgs) bool { + if p == ano { + return true + } else if p == nil || ano == nil { + return false + } + if !p.Field1DeepEqual(ano.Req1) { + return false + } + return true +} + +func (p *EchoServiceEchoUnaryArgs) Field1DeepEqual(src *EchoRequest) bool { + + if !p.Req1.DeepEqual(src) { + return false + } + return true +} + +type EchoServiceEchoUnaryResult struct { + Success *EchoResponse `thrift:"success,0,optional" frugal:"0,optional,EchoResponse" json:"success,omitempty"` +} + +func NewEchoServiceEchoUnaryResult() *EchoServiceEchoUnaryResult { + return &EchoServiceEchoUnaryResult{} +} + +func (p *EchoServiceEchoUnaryResult) InitDefault() { + *p = EchoServiceEchoUnaryResult{} +} + +var EchoServiceEchoUnaryResult_Success_DEFAULT *EchoResponse + +func (p *EchoServiceEchoUnaryResult) GetSuccess() (v *EchoResponse) { + if !p.IsSetSuccess() { + return EchoServiceEchoUnaryResult_Success_DEFAULT + } + return p.Success +} +func (p *EchoServiceEchoUnaryResult) SetSuccess(x interface{}) { + p.Success = x.(*EchoResponse) +} + +var fieldIDToName_EchoServiceEchoUnaryResult = map[int16]string{ + 0: "success", +} + +func (p *EchoServiceEchoUnaryResult) IsSetSuccess() bool { + return p.Success != nil +} + +func (p *EchoServiceEchoUnaryResult) Read(iprot thrift.TProtocol) (err error) { + + var fieldTypeId thrift.TType + var fieldId int16 + + if _, err = iprot.ReadStructBegin(); err != nil { + goto ReadStructBeginError + } + + for { + _, fieldTypeId, fieldId, err = iprot.ReadFieldBegin() + if err != nil { + goto ReadFieldBeginError + } + if fieldTypeId == thrift.STOP { + break + } + + switch fieldId { + case 0: + if fieldTypeId == thrift.STRUCT { + if err = p.ReadField0(iprot); err != nil { + goto ReadFieldError + } + } else if err = iprot.Skip(fieldTypeId); err != nil { + goto SkipFieldError + } + default: + if err = iprot.Skip(fieldTypeId); err != nil { + goto SkipFieldError + } + } + if err = iprot.ReadFieldEnd(); err != nil { + goto ReadFieldEndError + } + } + if err = iprot.ReadStructEnd(); err != nil { + goto ReadStructEndError + } + + return nil +ReadStructBeginError: + return thrift.PrependError(fmt.Sprintf("%T read struct begin error: ", p), err) +ReadFieldBeginError: + return thrift.PrependError(fmt.Sprintf("%T read field %d begin error: ", p, fieldId), err) +ReadFieldError: + return thrift.PrependError(fmt.Sprintf("%T read field %d '%s' error: ", p, fieldId, fieldIDToName_EchoServiceEchoUnaryResult[fieldId]), err) +SkipFieldError: + return thrift.PrependError(fmt.Sprintf("%T field %d skip type %d error: ", p, fieldId, fieldTypeId), err) + +ReadFieldEndError: + return thrift.PrependError(fmt.Sprintf("%T read field end error", p), err) +ReadStructEndError: + return thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err) +} + +func (p *EchoServiceEchoUnaryResult) ReadField0(iprot thrift.TProtocol) error { + p.Success = NewEchoResponse() + if err := p.Success.Read(iprot); err != nil { + return err + } + return nil +} + +func (p *EchoServiceEchoUnaryResult) Write(oprot thrift.TProtocol) (err error) { + var fieldId int16 + if err = oprot.WriteStructBegin("EchoUnary_result"); err != nil { + goto WriteStructBeginError + } + if p != nil { + if err = p.writeField0(oprot); err != nil { + fieldId = 0 + goto WriteFieldError + } + } + if err = oprot.WriteFieldStop(); err != nil { + goto WriteFieldStopError + } + if err = oprot.WriteStructEnd(); err != nil { + goto WriteStructEndError + } + return nil +WriteStructBeginError: + return thrift.PrependError(fmt.Sprintf("%T write struct begin error: ", p), err) +WriteFieldError: + return thrift.PrependError(fmt.Sprintf("%T write field %d error: ", p, fieldId), err) +WriteFieldStopError: + return thrift.PrependError(fmt.Sprintf("%T write field stop error: ", p), err) +WriteStructEndError: + return thrift.PrependError(fmt.Sprintf("%T write struct end error: ", p), err) +} + +func (p *EchoServiceEchoUnaryResult) writeField0(oprot thrift.TProtocol) (err error) { + if p.IsSetSuccess() { + if err = oprot.WriteFieldBegin("success", thrift.STRUCT, 0); err != nil { + goto WriteFieldBeginError + } + if err := p.Success.Write(oprot); err != nil { + return err + } + if err = oprot.WriteFieldEnd(); err != nil { + goto WriteFieldEndError + } + } + return nil +WriteFieldBeginError: + return thrift.PrependError(fmt.Sprintf("%T write field 0 begin error: ", p), err) +WriteFieldEndError: + return thrift.PrependError(fmt.Sprintf("%T write field 0 end error: ", p), err) +} + +func (p *EchoServiceEchoUnaryResult) String() string { + if p == nil { + return "" + } + return fmt.Sprintf("EchoServiceEchoUnaryResult(%+v)", *p) + +} + +func (p *EchoServiceEchoUnaryResult) DeepEqual(ano *EchoServiceEchoUnaryResult) bool { + if p == ano { + return true + } else if p == nil || ano == nil { + return false + } + if !p.Field0DeepEqual(ano.Success) { + return false + } + return true +} + +func (p *EchoServiceEchoUnaryResult) Field0DeepEqual(src *EchoResponse) bool { + + if !p.Success.DeepEqual(src) { + return false + } + return true +} + +type EchoServiceEchoPingPongArgs struct { + Req1 *EchoRequest `thrift:"req1,1" frugal:"1,default,EchoRequest" json:"req1"` + Req2 *EchoRequest `thrift:"req2,2" frugal:"2,default,EchoRequest" json:"req2"` +} + +func NewEchoServiceEchoPingPongArgs() *EchoServiceEchoPingPongArgs { + return &EchoServiceEchoPingPongArgs{} +} + +func (p *EchoServiceEchoPingPongArgs) InitDefault() { + *p = EchoServiceEchoPingPongArgs{} +} + +var EchoServiceEchoPingPongArgs_Req1_DEFAULT *EchoRequest + +func (p *EchoServiceEchoPingPongArgs) GetReq1() (v *EchoRequest) { + if !p.IsSetReq1() { + return EchoServiceEchoPingPongArgs_Req1_DEFAULT + } + return p.Req1 +} + +var EchoServiceEchoPingPongArgs_Req2_DEFAULT *EchoRequest + +func (p *EchoServiceEchoPingPongArgs) GetReq2() (v *EchoRequest) { + if !p.IsSetReq2() { + return EchoServiceEchoPingPongArgs_Req2_DEFAULT + } + return p.Req2 +} +func (p *EchoServiceEchoPingPongArgs) SetReq1(val *EchoRequest) { + p.Req1 = val +} +func (p *EchoServiceEchoPingPongArgs) SetReq2(val *EchoRequest) { + p.Req2 = val +} + +var fieldIDToName_EchoServiceEchoPingPongArgs = map[int16]string{ + 1: "req1", + 2: "req2", +} + +func (p *EchoServiceEchoPingPongArgs) IsSetReq1() bool { + return p.Req1 != nil +} + +func (p *EchoServiceEchoPingPongArgs) IsSetReq2() bool { + return p.Req2 != nil +} + +func (p *EchoServiceEchoPingPongArgs) Read(iprot thrift.TProtocol) (err error) { + + var fieldTypeId thrift.TType + var fieldId int16 + + if _, err = iprot.ReadStructBegin(); err != nil { + goto ReadStructBeginError + } + + for { + _, fieldTypeId, fieldId, err = iprot.ReadFieldBegin() + if err != nil { + goto ReadFieldBeginError + } + if fieldTypeId == thrift.STOP { + break + } + + switch fieldId { + case 1: + if fieldTypeId == thrift.STRUCT { + if err = p.ReadField1(iprot); err != nil { + goto ReadFieldError + } + } else if err = iprot.Skip(fieldTypeId); err != nil { + goto SkipFieldError + } + case 2: + if fieldTypeId == thrift.STRUCT { + if err = p.ReadField2(iprot); err != nil { + goto ReadFieldError + } + } else if err = iprot.Skip(fieldTypeId); err != nil { + goto SkipFieldError + } + default: + if err = iprot.Skip(fieldTypeId); err != nil { + goto SkipFieldError + } + } + if err = iprot.ReadFieldEnd(); err != nil { + goto ReadFieldEndError + } + } + if err = iprot.ReadStructEnd(); err != nil { + goto ReadStructEndError + } + + return nil +ReadStructBeginError: + return thrift.PrependError(fmt.Sprintf("%T read struct begin error: ", p), err) +ReadFieldBeginError: + return thrift.PrependError(fmt.Sprintf("%T read field %d begin error: ", p, fieldId), err) +ReadFieldError: + return thrift.PrependError(fmt.Sprintf("%T read field %d '%s' error: ", p, fieldId, fieldIDToName_EchoServiceEchoPingPongArgs[fieldId]), err) +SkipFieldError: + return thrift.PrependError(fmt.Sprintf("%T field %d skip type %d error: ", p, fieldId, fieldTypeId), err) + +ReadFieldEndError: + return thrift.PrependError(fmt.Sprintf("%T read field end error", p), err) +ReadStructEndError: + return thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err) +} + +func (p *EchoServiceEchoPingPongArgs) ReadField1(iprot thrift.TProtocol) error { + p.Req1 = NewEchoRequest() + if err := p.Req1.Read(iprot); err != nil { + return err + } + return nil +} +func (p *EchoServiceEchoPingPongArgs) ReadField2(iprot thrift.TProtocol) error { + p.Req2 = NewEchoRequest() + if err := p.Req2.Read(iprot); err != nil { + return err + } + return nil +} + +func (p *EchoServiceEchoPingPongArgs) Write(oprot thrift.TProtocol) (err error) { + var fieldId int16 + if err = oprot.WriteStructBegin("EchoPingPong_args"); err != nil { + goto WriteStructBeginError + } + if p != nil { + if err = p.writeField1(oprot); err != nil { + fieldId = 1 + goto WriteFieldError + } + if err = p.writeField2(oprot); err != nil { + fieldId = 2 + goto WriteFieldError + } + } + if err = oprot.WriteFieldStop(); err != nil { + goto WriteFieldStopError + } + if err = oprot.WriteStructEnd(); err != nil { + goto WriteStructEndError + } + return nil +WriteStructBeginError: + return thrift.PrependError(fmt.Sprintf("%T write struct begin error: ", p), err) +WriteFieldError: + return thrift.PrependError(fmt.Sprintf("%T write field %d error: ", p, fieldId), err) +WriteFieldStopError: + return thrift.PrependError(fmt.Sprintf("%T write field stop error: ", p), err) +WriteStructEndError: + return thrift.PrependError(fmt.Sprintf("%T write struct end error: ", p), err) +} + +func (p *EchoServiceEchoPingPongArgs) writeField1(oprot thrift.TProtocol) (err error) { + if err = oprot.WriteFieldBegin("req1", thrift.STRUCT, 1); err != nil { + goto WriteFieldBeginError + } + if err := p.Req1.Write(oprot); err != nil { + return err + } + if err = oprot.WriteFieldEnd(); err != nil { + goto WriteFieldEndError + } + return nil +WriteFieldBeginError: + return thrift.PrependError(fmt.Sprintf("%T write field 1 begin error: ", p), err) +WriteFieldEndError: + return thrift.PrependError(fmt.Sprintf("%T write field 1 end error: ", p), err) +} + +func (p *EchoServiceEchoPingPongArgs) writeField2(oprot thrift.TProtocol) (err error) { + if err = oprot.WriteFieldBegin("req2", thrift.STRUCT, 2); err != nil { + goto WriteFieldBeginError + } + if err := p.Req2.Write(oprot); err != nil { + return err + } + if err = oprot.WriteFieldEnd(); err != nil { + goto WriteFieldEndError + } + return nil +WriteFieldBeginError: + return thrift.PrependError(fmt.Sprintf("%T write field 2 begin error: ", p), err) +WriteFieldEndError: + return thrift.PrependError(fmt.Sprintf("%T write field 2 end error: ", p), err) +} + +func (p *EchoServiceEchoPingPongArgs) String() string { + if p == nil { + return "" + } + return fmt.Sprintf("EchoServiceEchoPingPongArgs(%+v)", *p) + +} + +func (p *EchoServiceEchoPingPongArgs) DeepEqual(ano *EchoServiceEchoPingPongArgs) bool { + if p == ano { + return true + } else if p == nil || ano == nil { + return false + } + if !p.Field1DeepEqual(ano.Req1) { + return false + } + if !p.Field2DeepEqual(ano.Req2) { + return false + } + return true +} + +func (p *EchoServiceEchoPingPongArgs) Field1DeepEqual(src *EchoRequest) bool { + + if !p.Req1.DeepEqual(src) { + return false + } + return true +} +func (p *EchoServiceEchoPingPongArgs) Field2DeepEqual(src *EchoRequest) bool { + + if !p.Req2.DeepEqual(src) { + return false + } + return true +} + +type EchoServiceEchoPingPongResult struct { + Success *EchoResponse `thrift:"success,0,optional" frugal:"0,optional,EchoResponse" json:"success,omitempty"` + E *EchoException `thrift:"e,1,optional" frugal:"1,optional,EchoException" json:"e,omitempty"` +} + +func NewEchoServiceEchoPingPongResult() *EchoServiceEchoPingPongResult { + return &EchoServiceEchoPingPongResult{} +} + +func (p *EchoServiceEchoPingPongResult) InitDefault() { + *p = EchoServiceEchoPingPongResult{} +} + +var EchoServiceEchoPingPongResult_Success_DEFAULT *EchoResponse + +func (p *EchoServiceEchoPingPongResult) GetSuccess() (v *EchoResponse) { + if !p.IsSetSuccess() { + return EchoServiceEchoPingPongResult_Success_DEFAULT + } + return p.Success +} + +var EchoServiceEchoPingPongResult_E_DEFAULT *EchoException + +func (p *EchoServiceEchoPingPongResult) GetE() (v *EchoException) { + if !p.IsSetE() { + return EchoServiceEchoPingPongResult_E_DEFAULT + } + return p.E +} +func (p *EchoServiceEchoPingPongResult) SetSuccess(x interface{}) { + p.Success = x.(*EchoResponse) +} +func (p *EchoServiceEchoPingPongResult) SetE(val *EchoException) { + p.E = val +} + +var fieldIDToName_EchoServiceEchoPingPongResult = map[int16]string{ + 0: "success", + 1: "e", +} + +func (p *EchoServiceEchoPingPongResult) IsSetSuccess() bool { + return p.Success != nil +} + +func (p *EchoServiceEchoPingPongResult) IsSetE() bool { + return p.E != nil +} + +func (p *EchoServiceEchoPingPongResult) Read(iprot thrift.TProtocol) (err error) { + + var fieldTypeId thrift.TType + var fieldId int16 + + if _, err = iprot.ReadStructBegin(); err != nil { + goto ReadStructBeginError + } + + for { + _, fieldTypeId, fieldId, err = iprot.ReadFieldBegin() + if err != nil { + goto ReadFieldBeginError + } + if fieldTypeId == thrift.STOP { + break + } + + switch fieldId { + case 0: + if fieldTypeId == thrift.STRUCT { + if err = p.ReadField0(iprot); err != nil { + goto ReadFieldError + } + } else if err = iprot.Skip(fieldTypeId); err != nil { + goto SkipFieldError + } + case 1: + if fieldTypeId == thrift.STRUCT { + if err = p.ReadField1(iprot); err != nil { + goto ReadFieldError + } + } else if err = iprot.Skip(fieldTypeId); err != nil { + goto SkipFieldError + } + default: + if err = iprot.Skip(fieldTypeId); err != nil { + goto SkipFieldError + } + } + if err = iprot.ReadFieldEnd(); err != nil { + goto ReadFieldEndError + } + } + if err = iprot.ReadStructEnd(); err != nil { + goto ReadStructEndError + } + + return nil +ReadStructBeginError: + return thrift.PrependError(fmt.Sprintf("%T read struct begin error: ", p), err) +ReadFieldBeginError: + return thrift.PrependError(fmt.Sprintf("%T read field %d begin error: ", p, fieldId), err) +ReadFieldError: + return thrift.PrependError(fmt.Sprintf("%T read field %d '%s' error: ", p, fieldId, fieldIDToName_EchoServiceEchoPingPongResult[fieldId]), err) +SkipFieldError: + return thrift.PrependError(fmt.Sprintf("%T field %d skip type %d error: ", p, fieldId, fieldTypeId), err) + +ReadFieldEndError: + return thrift.PrependError(fmt.Sprintf("%T read field end error", p), err) +ReadStructEndError: + return thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err) +} + +func (p *EchoServiceEchoPingPongResult) ReadField0(iprot thrift.TProtocol) error { + p.Success = NewEchoResponse() + if err := p.Success.Read(iprot); err != nil { + return err + } + return nil +} +func (p *EchoServiceEchoPingPongResult) ReadField1(iprot thrift.TProtocol) error { + p.E = NewEchoException() + if err := p.E.Read(iprot); err != nil { + return err + } + return nil +} + +func (p *EchoServiceEchoPingPongResult) Write(oprot thrift.TProtocol) (err error) { + var fieldId int16 + if err = oprot.WriteStructBegin("EchoPingPong_result"); err != nil { + goto WriteStructBeginError + } + if p != nil { + if err = p.writeField0(oprot); err != nil { + fieldId = 0 + goto WriteFieldError + } + if err = p.writeField1(oprot); err != nil { + fieldId = 1 + goto WriteFieldError + } + } + if err = oprot.WriteFieldStop(); err != nil { + goto WriteFieldStopError + } + if err = oprot.WriteStructEnd(); err != nil { + goto WriteStructEndError + } + return nil +WriteStructBeginError: + return thrift.PrependError(fmt.Sprintf("%T write struct begin error: ", p), err) +WriteFieldError: + return thrift.PrependError(fmt.Sprintf("%T write field %d error: ", p, fieldId), err) +WriteFieldStopError: + return thrift.PrependError(fmt.Sprintf("%T write field stop error: ", p), err) +WriteStructEndError: + return thrift.PrependError(fmt.Sprintf("%T write struct end error: ", p), err) +} + +func (p *EchoServiceEchoPingPongResult) writeField0(oprot thrift.TProtocol) (err error) { + if p.IsSetSuccess() { + if err = oprot.WriteFieldBegin("success", thrift.STRUCT, 0); err != nil { + goto WriteFieldBeginError + } + if err := p.Success.Write(oprot); err != nil { + return err + } + if err = oprot.WriteFieldEnd(); err != nil { + goto WriteFieldEndError + } + } + return nil +WriteFieldBeginError: + return thrift.PrependError(fmt.Sprintf("%T write field 0 begin error: ", p), err) +WriteFieldEndError: + return thrift.PrependError(fmt.Sprintf("%T write field 0 end error: ", p), err) +} + +func (p *EchoServiceEchoPingPongResult) writeField1(oprot thrift.TProtocol) (err error) { + if p.IsSetE() { + if err = oprot.WriteFieldBegin("e", thrift.STRUCT, 1); err != nil { + goto WriteFieldBeginError + } + if err := p.E.Write(oprot); err != nil { + return err + } + if err = oprot.WriteFieldEnd(); err != nil { + goto WriteFieldEndError + } + } + return nil +WriteFieldBeginError: + return thrift.PrependError(fmt.Sprintf("%T write field 1 begin error: ", p), err) +WriteFieldEndError: + return thrift.PrependError(fmt.Sprintf("%T write field 1 end error: ", p), err) +} + +func (p *EchoServiceEchoPingPongResult) String() string { + if p == nil { + return "" + } + return fmt.Sprintf("EchoServiceEchoPingPongResult(%+v)", *p) + +} + +func (p *EchoServiceEchoPingPongResult) DeepEqual(ano *EchoServiceEchoPingPongResult) bool { + if p == ano { + return true + } else if p == nil || ano == nil { + return false + } + if !p.Field0DeepEqual(ano.Success) { + return false + } + if !p.Field1DeepEqual(ano.E) { + return false + } + return true +} + +func (p *EchoServiceEchoPingPongResult) Field0DeepEqual(src *EchoResponse) bool { + + if !p.Success.DeepEqual(src) { + return false + } + return true +} +func (p *EchoServiceEchoPingPongResult) Field1DeepEqual(src *EchoException) bool { + + if !p.E.DeepEqual(src) { + return false + } + return true +} + +type EchoServiceEchoOnewayArgs struct { + Req1 *EchoRequest `thrift:"req1,1" frugal:"1,default,EchoRequest" json:"req1"` +} + +func NewEchoServiceEchoOnewayArgs() *EchoServiceEchoOnewayArgs { + return &EchoServiceEchoOnewayArgs{} +} + +func (p *EchoServiceEchoOnewayArgs) InitDefault() { + *p = EchoServiceEchoOnewayArgs{} +} + +var EchoServiceEchoOnewayArgs_Req1_DEFAULT *EchoRequest + +func (p *EchoServiceEchoOnewayArgs) GetReq1() (v *EchoRequest) { + if !p.IsSetReq1() { + return EchoServiceEchoOnewayArgs_Req1_DEFAULT + } + return p.Req1 +} +func (p *EchoServiceEchoOnewayArgs) SetReq1(val *EchoRequest) { + p.Req1 = val +} + +var fieldIDToName_EchoServiceEchoOnewayArgs = map[int16]string{ + 1: "req1", +} + +func (p *EchoServiceEchoOnewayArgs) IsSetReq1() bool { + return p.Req1 != nil +} + +func (p *EchoServiceEchoOnewayArgs) Read(iprot thrift.TProtocol) (err error) { + + var fieldTypeId thrift.TType + var fieldId int16 + + if _, err = iprot.ReadStructBegin(); err != nil { + goto ReadStructBeginError + } + + for { + _, fieldTypeId, fieldId, err = iprot.ReadFieldBegin() + if err != nil { + goto ReadFieldBeginError + } + if fieldTypeId == thrift.STOP { + break + } + + switch fieldId { + case 1: + if fieldTypeId == thrift.STRUCT { + if err = p.ReadField1(iprot); err != nil { + goto ReadFieldError + } + } else if err = iprot.Skip(fieldTypeId); err != nil { + goto SkipFieldError + } + default: + if err = iprot.Skip(fieldTypeId); err != nil { + goto SkipFieldError + } + } + if err = iprot.ReadFieldEnd(); err != nil { + goto ReadFieldEndError + } + } + if err = iprot.ReadStructEnd(); err != nil { + goto ReadStructEndError + } + + return nil +ReadStructBeginError: + return thrift.PrependError(fmt.Sprintf("%T read struct begin error: ", p), err) +ReadFieldBeginError: + return thrift.PrependError(fmt.Sprintf("%T read field %d begin error: ", p, fieldId), err) +ReadFieldError: + return thrift.PrependError(fmt.Sprintf("%T read field %d '%s' error: ", p, fieldId, fieldIDToName_EchoServiceEchoOnewayArgs[fieldId]), err) +SkipFieldError: + return thrift.PrependError(fmt.Sprintf("%T field %d skip type %d error: ", p, fieldId, fieldTypeId), err) + +ReadFieldEndError: + return thrift.PrependError(fmt.Sprintf("%T read field end error", p), err) +ReadStructEndError: + return thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err) +} + +func (p *EchoServiceEchoOnewayArgs) ReadField1(iprot thrift.TProtocol) error { + p.Req1 = NewEchoRequest() + if err := p.Req1.Read(iprot); err != nil { + return err + } + return nil +} + +func (p *EchoServiceEchoOnewayArgs) Write(oprot thrift.TProtocol) (err error) { + var fieldId int16 + if err = oprot.WriteStructBegin("EchoOneway_args"); err != nil { + goto WriteStructBeginError + } + if p != nil { + if err = p.writeField1(oprot); err != nil { + fieldId = 1 + goto WriteFieldError + } + } + if err = oprot.WriteFieldStop(); err != nil { + goto WriteFieldStopError + } + if err = oprot.WriteStructEnd(); err != nil { + goto WriteStructEndError + } + return nil +WriteStructBeginError: + return thrift.PrependError(fmt.Sprintf("%T write struct begin error: ", p), err) +WriteFieldError: + return thrift.PrependError(fmt.Sprintf("%T write field %d error: ", p, fieldId), err) +WriteFieldStopError: + return thrift.PrependError(fmt.Sprintf("%T write field stop error: ", p), err) +WriteStructEndError: + return thrift.PrependError(fmt.Sprintf("%T write struct end error: ", p), err) +} + +func (p *EchoServiceEchoOnewayArgs) writeField1(oprot thrift.TProtocol) (err error) { + if err = oprot.WriteFieldBegin("req1", thrift.STRUCT, 1); err != nil { + goto WriteFieldBeginError + } + if err := p.Req1.Write(oprot); err != nil { + return err + } + if err = oprot.WriteFieldEnd(); err != nil { + goto WriteFieldEndError + } + return nil +WriteFieldBeginError: + return thrift.PrependError(fmt.Sprintf("%T write field 1 begin error: ", p), err) +WriteFieldEndError: + return thrift.PrependError(fmt.Sprintf("%T write field 1 end error: ", p), err) +} + +func (p *EchoServiceEchoOnewayArgs) String() string { + if p == nil { + return "" + } + return fmt.Sprintf("EchoServiceEchoOnewayArgs(%+v)", *p) + +} + +func (p *EchoServiceEchoOnewayArgs) DeepEqual(ano *EchoServiceEchoOnewayArgs) bool { + if p == ano { + return true + } else if p == nil || ano == nil { + return false + } + if !p.Field1DeepEqual(ano.Req1) { + return false + } + return true +} + +func (p *EchoServiceEchoOnewayArgs) Field1DeepEqual(src *EchoRequest) bool { + + if !p.Req1.DeepEqual(src) { + return false + } + return true +} + +type EchoServiceEchoOnewayResult struct { +} + +func NewEchoServiceEchoOnewayResult() *EchoServiceEchoOnewayResult { + return &EchoServiceEchoOnewayResult{} +} + +func (p *EchoServiceEchoOnewayResult) InitDefault() { + *p = EchoServiceEchoOnewayResult{} +} + +var fieldIDToName_EchoServiceEchoOnewayResult = map[int16]string{} + +func (p *EchoServiceEchoOnewayResult) Read(iprot thrift.TProtocol) (err error) { + + var fieldTypeId thrift.TType + var fieldId int16 + + if _, err = iprot.ReadStructBegin(); err != nil { + goto ReadStructBeginError + } + + for { + _, fieldTypeId, fieldId, err = iprot.ReadFieldBegin() + if err != nil { + goto ReadFieldBeginError + } + if fieldTypeId == thrift.STOP { + break + } + if err = iprot.Skip(fieldTypeId); err != nil { + goto SkipFieldTypeError + } + if err = iprot.ReadFieldEnd(); err != nil { + goto ReadFieldEndError + } + } + if err = iprot.ReadStructEnd(); err != nil { + goto ReadStructEndError + } + + return nil +ReadStructBeginError: + return thrift.PrependError(fmt.Sprintf("%T read struct begin error: ", p), err) +ReadFieldBeginError: + return thrift.PrependError(fmt.Sprintf("%T read field %d begin error: ", p, fieldId), err) +SkipFieldTypeError: + return thrift.PrependError(fmt.Sprintf("%T skip field type %d error", p, fieldTypeId), err) + +ReadFieldEndError: + return thrift.PrependError(fmt.Sprintf("%T read field end error", p), err) +ReadStructEndError: + return thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err) +} + +func (p *EchoServiceEchoOnewayResult) Write(oprot thrift.TProtocol) (err error) { + if err = oprot.WriteStructBegin("EchoOneway_result"); err != nil { + goto WriteStructBeginError + } + if p != nil { + } + if err = oprot.WriteFieldStop(); err != nil { + goto WriteFieldStopError + } + if err = oprot.WriteStructEnd(); err != nil { + goto WriteStructEndError + } + return nil +WriteStructBeginError: + return thrift.PrependError(fmt.Sprintf("%T write struct begin error: ", p), err) +WriteFieldStopError: + return thrift.PrependError(fmt.Sprintf("%T write field stop error: ", p), err) +WriteStructEndError: + return thrift.PrependError(fmt.Sprintf("%T write struct end error: ", p), err) +} + +func (p *EchoServiceEchoOnewayResult) String() string { + if p == nil { + return "" + } + return fmt.Sprintf("EchoServiceEchoOnewayResult(%+v)", *p) + +} + +func (p *EchoServiceEchoOnewayResult) DeepEqual(ano *EchoServiceEchoOnewayResult) bool { + if p == ano { + return true + } else if p == nil || ano == nil { + return false + } + return true +} + +type EchoServicePingArgs struct { +} + +func NewEchoServicePingArgs() *EchoServicePingArgs { + return &EchoServicePingArgs{} +} + +func (p *EchoServicePingArgs) InitDefault() { + *p = EchoServicePingArgs{} +} + +var fieldIDToName_EchoServicePingArgs = map[int16]string{} + +func (p *EchoServicePingArgs) Read(iprot thrift.TProtocol) (err error) { + + var fieldTypeId thrift.TType + var fieldId int16 + + if _, err = iprot.ReadStructBegin(); err != nil { + goto ReadStructBeginError + } + + for { + _, fieldTypeId, fieldId, err = iprot.ReadFieldBegin() + if err != nil { + goto ReadFieldBeginError + } + if fieldTypeId == thrift.STOP { + break + } + if err = iprot.Skip(fieldTypeId); err != nil { + goto SkipFieldTypeError + } + if err = iprot.ReadFieldEnd(); err != nil { + goto ReadFieldEndError + } + } + if err = iprot.ReadStructEnd(); err != nil { + goto ReadStructEndError + } + + return nil +ReadStructBeginError: + return thrift.PrependError(fmt.Sprintf("%T read struct begin error: ", p), err) +ReadFieldBeginError: + return thrift.PrependError(fmt.Sprintf("%T read field %d begin error: ", p, fieldId), err) +SkipFieldTypeError: + return thrift.PrependError(fmt.Sprintf("%T skip field type %d error", p, fieldTypeId), err) + +ReadFieldEndError: + return thrift.PrependError(fmt.Sprintf("%T read field end error", p), err) +ReadStructEndError: + return thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err) +} + +func (p *EchoServicePingArgs) Write(oprot thrift.TProtocol) (err error) { + if err = oprot.WriteStructBegin("Ping_args"); err != nil { + goto WriteStructBeginError + } + if p != nil { + } + if err = oprot.WriteFieldStop(); err != nil { + goto WriteFieldStopError + } + if err = oprot.WriteStructEnd(); err != nil { + goto WriteStructEndError + } + return nil +WriteStructBeginError: + return thrift.PrependError(fmt.Sprintf("%T write struct begin error: ", p), err) +WriteFieldStopError: + return thrift.PrependError(fmt.Sprintf("%T write field stop error: ", p), err) +WriteStructEndError: + return thrift.PrependError(fmt.Sprintf("%T write struct end error: ", p), err) +} + +func (p *EchoServicePingArgs) String() string { + if p == nil { + return "" + } + return fmt.Sprintf("EchoServicePingArgs(%+v)", *p) + +} + +func (p *EchoServicePingArgs) DeepEqual(ano *EchoServicePingArgs) bool { + if p == ano { + return true + } else if p == nil || ano == nil { + return false + } + return true +} + +type EchoServicePingResult struct { +} + +func NewEchoServicePingResult() *EchoServicePingResult { + return &EchoServicePingResult{} +} + +func (p *EchoServicePingResult) InitDefault() { + *p = EchoServicePingResult{} +} + +var fieldIDToName_EchoServicePingResult = map[int16]string{} + +func (p *EchoServicePingResult) Read(iprot thrift.TProtocol) (err error) { + + var fieldTypeId thrift.TType + var fieldId int16 + + if _, err = iprot.ReadStructBegin(); err != nil { + goto ReadStructBeginError + } + + for { + _, fieldTypeId, fieldId, err = iprot.ReadFieldBegin() + if err != nil { + goto ReadFieldBeginError + } + if fieldTypeId == thrift.STOP { + break + } + if err = iprot.Skip(fieldTypeId); err != nil { + goto SkipFieldTypeError + } + if err = iprot.ReadFieldEnd(); err != nil { + goto ReadFieldEndError + } + } + if err = iprot.ReadStructEnd(); err != nil { + goto ReadStructEndError + } + + return nil +ReadStructBeginError: + return thrift.PrependError(fmt.Sprintf("%T read struct begin error: ", p), err) +ReadFieldBeginError: + return thrift.PrependError(fmt.Sprintf("%T read field %d begin error: ", p, fieldId), err) +SkipFieldTypeError: + return thrift.PrependError(fmt.Sprintf("%T skip field type %d error", p, fieldTypeId), err) + +ReadFieldEndError: + return thrift.PrependError(fmt.Sprintf("%T read field end error", p), err) +ReadStructEndError: + return thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err) +} + +func (p *EchoServicePingResult) Write(oprot thrift.TProtocol) (err error) { + if err = oprot.WriteStructBegin("Ping_result"); err != nil { + goto WriteStructBeginError + } + if p != nil { + } + if err = oprot.WriteFieldStop(); err != nil { + goto WriteFieldStopError + } + if err = oprot.WriteStructEnd(); err != nil { + goto WriteStructEndError + } + return nil +WriteStructBeginError: + return thrift.PrependError(fmt.Sprintf("%T write struct begin error: ", p), err) +WriteFieldStopError: + return thrift.PrependError(fmt.Sprintf("%T write field stop error: ", p), err) +WriteStructEndError: + return thrift.PrependError(fmt.Sprintf("%T write struct end error: ", p), err) +} + +func (p *EchoServicePingResult) String() string { + if p == nil { + return "" + } + return fmt.Sprintf("EchoServicePingResult(%+v)", *p) + +} + +func (p *EchoServicePingResult) DeepEqual(ano *EchoServicePingResult) bool { + if p == ano { + return true + } else if p == nil || ano == nil { + return false + } + return true +} diff --git a/thrift_streaming/kitex_gen/echo/echoservice/client.go b/thrift_streaming/kitex_gen/echo/echoservice/client.go new file mode 100644 index 0000000..f50d2b8 --- /dev/null +++ b/thrift_streaming/kitex_gen/echo/echoservice/client.go @@ -0,0 +1,140 @@ +// Code generated by Kitex v0.8.0. DO NOT EDIT. + +package echoservice + +import ( + "context" + echo "github.com/cloudwego/kitex-tests/thrift_streaming/kitex_gen/echo" + client "github.com/cloudwego/kitex/client" + callopt "github.com/cloudwego/kitex/client/callopt" + "github.com/cloudwego/kitex/client/callopt/streamcall" + "github.com/cloudwego/kitex/client/streamclient" + streaming "github.com/cloudwego/kitex/pkg/streaming" + transport "github.com/cloudwego/kitex/transport" +) + +// Client is designed to provide IDL-compatible methods with call-option parameter for kitex framework. +type Client interface { + EchoPingPong(ctx context.Context, req1 *echo.EchoRequest, req2 *echo.EchoRequest, callOptions ...callopt.Option) (r *echo.EchoResponse, err error) + EchoOneway(ctx context.Context, req1 *echo.EchoRequest, callOptions ...callopt.Option) (err error) + Ping(ctx context.Context, callOptions ...callopt.Option) (err error) +} + +// StreamClient is designed to provide Interface for Streaming APIs. +type StreamClient interface { + EchoBidirectional(ctx context.Context, callOptions ...streamcall.Option) (stream EchoService_EchoBidirectionalClient, err error) + EchoClient(ctx context.Context, callOptions ...streamcall.Option) (stream EchoService_EchoClientClient, err error) + EchoServer(ctx context.Context, req1 *echo.EchoRequest, callOptions ...streamcall.Option) (stream EchoService_EchoServerClient, err error) + EchoUnary(ctx context.Context, req1 *echo.EchoRequest, callOptions ...streamcall.Option) (r *echo.EchoResponse, err error) +} + +type EchoService_EchoBidirectionalClient interface { + streaming.Stream + Send(*echo.EchoRequest) error + Recv() (*echo.EchoResponse, error) +} + +type EchoService_EchoClientClient interface { + streaming.Stream + Send(*echo.EchoRequest) error + CloseAndRecv() (*echo.EchoResponse, error) +} + +type EchoService_EchoServerClient interface { + streaming.Stream + Recv() (*echo.EchoResponse, error) +} + +// NewClient creates a client for the service defined in IDL. +func NewClient(destService string, opts ...client.Option) (Client, error) { + var options []client.Option + options = append(options, client.WithDestService(destService)) + + options = append(options, opts...) + + kc, err := client.NewClient(serviceInfoForClient(), options...) + if err != nil { + return nil, err + } + return &kEchoServiceClient{ + kClient: newServiceClient(kc), + }, nil +} + +// MustNewClient creates a client for the service defined in IDL. It panics if any error occurs. +func MustNewClient(destService string, opts ...client.Option) Client { + kc, err := NewClient(destService, opts...) + if err != nil { + panic(err) + } + return kc +} + +type kEchoServiceClient struct { + *kClient +} + +func (p *kEchoServiceClient) EchoPingPong(ctx context.Context, req1 *echo.EchoRequest, req2 *echo.EchoRequest, callOptions ...callopt.Option) (r *echo.EchoResponse, err error) { + ctx = client.NewCtxWithCallOptions(ctx, callOptions) + return p.kClient.EchoPingPong(ctx, req1, req2) +} + +func (p *kEchoServiceClient) EchoOneway(ctx context.Context, req1 *echo.EchoRequest, callOptions ...callopt.Option) (err error) { + ctx = client.NewCtxWithCallOptions(ctx, callOptions) + return p.kClient.EchoOneway(ctx, req1) +} + +func (p *kEchoServiceClient) Ping(ctx context.Context, callOptions ...callopt.Option) (err error) { + ctx = client.NewCtxWithCallOptions(ctx, callOptions) + return p.kClient.Ping(ctx) +} + +// NewStreamClient creates a stream client for the service's streaming APIs defined in IDL. +func NewStreamClient(destService string, opts ...streamclient.Option) (StreamClient, error) { + var options []client.Option + options = append(options, client.WithDestService(destService)) + options = append(options, client.WithTransportProtocol(transport.GRPC)) + options = append(options, streamclient.GetClientOptions(opts)...) + + kc, err := client.NewClient(serviceInfoForStreamClient(), options...) + if err != nil { + return nil, err + } + return &kEchoServiceStreamClient{ + kClient: newServiceClient(kc), + }, nil +} + +// MustNewStreamClient creates a stream client for the service's streaming APIs defined in IDL. +// It panics if any error occurs. +func MustNewStreamClient(destService string, opts ...streamclient.Option) StreamClient { + kc, err := NewStreamClient(destService, opts...) + if err != nil { + panic(err) + } + return kc +} + +type kEchoServiceStreamClient struct { + *kClient +} + +func (p *kEchoServiceStreamClient) EchoBidirectional(ctx context.Context, callOptions ...streamcall.Option) (stream EchoService_EchoBidirectionalClient, err error) { + ctx = client.NewCtxWithCallOptions(ctx, streamcall.GetCallOptions(callOptions)) + return p.kClient.EchoBidirectional(ctx) +} + +func (p *kEchoServiceStreamClient) EchoClient(ctx context.Context, callOptions ...streamcall.Option) (stream EchoService_EchoClientClient, err error) { + ctx = client.NewCtxWithCallOptions(ctx, streamcall.GetCallOptions(callOptions)) + return p.kClient.EchoClient(ctx) +} + +func (p *kEchoServiceStreamClient) EchoServer(ctx context.Context, req1 *echo.EchoRequest, callOptions ...streamcall.Option) (stream EchoService_EchoServerClient, err error) { + ctx = client.NewCtxWithCallOptions(ctx, streamcall.GetCallOptions(callOptions)) + return p.kClient.EchoServer(ctx, req1) +} + +func (p *kEchoServiceStreamClient) EchoUnary(ctx context.Context, req1 *echo.EchoRequest, callOptions ...streamcall.Option) (r *echo.EchoResponse, err error) { + ctx = client.NewCtxWithCallOptions(ctx, streamcall.GetCallOptions(callOptions)) + return p.kClient.EchoUnary(ctx, req1) +} diff --git a/thrift_streaming/kitex_gen/echo/echoservice/echoservice.go b/thrift_streaming/kitex_gen/echo/echoservice/echoservice.go new file mode 100644 index 0000000..cd20618 --- /dev/null +++ b/thrift_streaming/kitex_gen/echo/echoservice/echoservice.go @@ -0,0 +1,442 @@ +// Code generated by Kitex v0.8.0. DO NOT EDIT. + +package echoservice + +import ( + "context" + "errors" + "fmt" + echo "github.com/cloudwego/kitex-tests/thrift_streaming/kitex_gen/echo" + client "github.com/cloudwego/kitex/client" + kitex "github.com/cloudwego/kitex/pkg/serviceinfo" + streaming "github.com/cloudwego/kitex/pkg/streaming" +) + +var errInvalidMessageType = errors.New("invalid message type for service method handler") + +var _ = streaming.KitexUnusedProtection + +var serviceMethods = map[string]kitex.MethodInfo{ + "EchoBidirectional": kitex.NewMethodInfo( + echoBidirectionalHandler, + newEchoServiceEchoBidirectionalArgs, + newEchoServiceEchoBidirectionalResult, + false, + kitex.WithStreamingMode(kitex.StreamingBidirectional), + ), + "EchoClient": kitex.NewMethodInfo( + echoClientHandler, + newEchoServiceEchoClientArgs, + newEchoServiceEchoClientResult, + false, + kitex.WithStreamingMode(kitex.StreamingClient), + ), + "EchoServer": kitex.NewMethodInfo( + echoServerHandler, + newEchoServiceEchoServerArgs, + newEchoServiceEchoServerResult, + false, + kitex.WithStreamingMode(kitex.StreamingServer), + ), + "EchoUnary": kitex.NewMethodInfo( + echoUnaryHandler, + newEchoServiceEchoUnaryArgs, + newEchoServiceEchoUnaryResult, + false, + kitex.WithStreamingMode(kitex.StreamingUnary), + ), + "EchoPingPong": kitex.NewMethodInfo( + echoPingPongHandler, + newEchoServiceEchoPingPongArgs, + newEchoServiceEchoPingPongResult, + false, + kitex.WithStreamingMode(kitex.StreamingNone), + ), + "EchoOneway": kitex.NewMethodInfo( + echoOnewayHandler, + newEchoServiceEchoOnewayArgs, + newEchoServiceEchoOnewayResult, + false, + kitex.WithStreamingMode(kitex.StreamingNone), + ), + "Ping": kitex.NewMethodInfo( + pingHandler, + newEchoServicePingArgs, + newEchoServicePingResult, + false, + kitex.WithStreamingMode(kitex.StreamingNone), + ), +} + +var ( + echoServiceServiceInfo = NewServiceInfo() + echoServiceServiceInfoForClient = NewServiceInfoForClient() + echoServiceServiceInfoForStreamClient = NewServiceInfoForStreamClient() +) + +// for server +func serviceInfo() *kitex.ServiceInfo { + return echoServiceServiceInfo +} + +// for client +func serviceInfoForStreamClient() *kitex.ServiceInfo { + return echoServiceServiceInfoForStreamClient +} + +// for stream client +func serviceInfoForClient() *kitex.ServiceInfo { + return echoServiceServiceInfoForClient +} + +// NewServiceInfo creates a new ServiceInfo containing all methods +func NewServiceInfo() *kitex.ServiceInfo { + return newServiceInfo(true, true, true) +} + +// NewServiceInfo creates a new ServiceInfo containing non-streaming methods +func NewServiceInfoForClient() *kitex.ServiceInfo { + return newServiceInfo(false, false, true) +} +func NewServiceInfoForStreamClient() *kitex.ServiceInfo { + return newServiceInfo(true, true, false) +} + +func newServiceInfo(hasStreaming bool, keepStreamingMethods bool, keepNonStreamingMethods bool) *kitex.ServiceInfo { + serviceName := "EchoService" + handlerType := (*echo.EchoService)(nil) + methods := map[string]kitex.MethodInfo{} + for name, m := range serviceMethods { + if m.IsStreaming() && !keepStreamingMethods { + continue + } + if !m.IsStreaming() && !keepNonStreamingMethods { + continue + } + methods[name] = m + } + extra := map[string]interface{}{ + "PackageName": "echo", + } + if hasStreaming { + extra["streaming"] = hasStreaming + } + svcInfo := &kitex.ServiceInfo{ + ServiceName: serviceName, + HandlerType: handlerType, + Methods: methods, + PayloadCodec: kitex.Thrift, + KiteXGenVersion: "v0.8.0", + Extra: extra, + } + return svcInfo +} + +func echoBidirectionalHandler(ctx context.Context, handler interface{}, arg, result interface{}) error { + st, ok := arg.(*streaming.Args) + if !ok { + return errors.New("EchoService.EchoBidirectional is a thrift streaming method, please call with Kitex StreamClient") + } + stream := &echoServiceEchoBidirectionalServer{st.Stream} + return handler.(echo.EchoService).EchoBidirectional(stream) +} + +type echoServiceEchoBidirectionalClient struct { + streaming.Stream +} + +func (x *echoServiceEchoBidirectionalClient) Send(m *echo.EchoRequest) error { + return x.Stream.SendMsg(m) +} +func (x *echoServiceEchoBidirectionalClient) Recv() (*echo.EchoResponse, error) { + m := new(echo.EchoResponse) + return m, x.Stream.RecvMsg(m) +} + +type echoServiceEchoBidirectionalServer struct { + streaming.Stream +} + +func (x *echoServiceEchoBidirectionalServer) Send(m *echo.EchoResponse) error { + return x.Stream.SendMsg(m) +} + +func (x *echoServiceEchoBidirectionalServer) Recv() (*echo.EchoRequest, error) { + m := new(echo.EchoRequest) + return m, x.Stream.RecvMsg(m) +} + +func newEchoServiceEchoBidirectionalArgs() interface{} { + return echo.NewEchoServiceEchoBidirectionalArgs() +} + +func newEchoServiceEchoBidirectionalResult() interface{} { + return echo.NewEchoServiceEchoBidirectionalResult() +} + +func echoClientHandler(ctx context.Context, handler interface{}, arg, result interface{}) error { + st, ok := arg.(*streaming.Args) + if !ok { + return errors.New("EchoService.EchoClient is a thrift streaming method, please call with Kitex StreamClient") + } + stream := &echoServiceEchoClientServer{st.Stream} + return handler.(echo.EchoService).EchoClient(stream) +} + +type echoServiceEchoClientClient struct { + streaming.Stream +} + +func (x *echoServiceEchoClientClient) Send(m *echo.EchoRequest) error { + return x.Stream.SendMsg(m) +} +func (x *echoServiceEchoClientClient) CloseAndRecv() (*echo.EchoResponse, error) { + if err := x.Stream.Close(); err != nil { + return nil, err + } + m := new(echo.EchoResponse) + return m, x.Stream.RecvMsg(m) +} + +type echoServiceEchoClientServer struct { + streaming.Stream +} + +func (x *echoServiceEchoClientServer) SendAndClose(m *echo.EchoResponse) error { + return x.Stream.SendMsg(m) +} + +func (x *echoServiceEchoClientServer) Recv() (*echo.EchoRequest, error) { + m := new(echo.EchoRequest) + return m, x.Stream.RecvMsg(m) +} + +func newEchoServiceEchoClientArgs() interface{} { + return echo.NewEchoServiceEchoClientArgs() +} + +func newEchoServiceEchoClientResult() interface{} { + return echo.NewEchoServiceEchoClientResult() +} + +func echoServerHandler(ctx context.Context, handler interface{}, arg, result interface{}) error { + st, ok := arg.(*streaming.Args) + if !ok { + return errors.New("EchoService.EchoServer is a thrift streaming method, please call with Kitex StreamClient") + } + stream := &echoServiceEchoServerServer{st.Stream} + req := new(echo.EchoRequest) + if err := st.Stream.RecvMsg(req); err != nil { + return err + } + return handler.(echo.EchoService).EchoServer(req, stream) +} + +type echoServiceEchoServerClient struct { + streaming.Stream +} + +func (x *echoServiceEchoServerClient) Recv() (*echo.EchoResponse, error) { + m := new(echo.EchoResponse) + return m, x.Stream.RecvMsg(m) +} + +type echoServiceEchoServerServer struct { + streaming.Stream +} + +func (x *echoServiceEchoServerServer) Send(m *echo.EchoResponse) error { + return x.Stream.SendMsg(m) +} + +func newEchoServiceEchoServerArgs() interface{} { + return echo.NewEchoServiceEchoServerArgs() +} + +func newEchoServiceEchoServerResult() interface{} { + return echo.NewEchoServiceEchoServerResult() +} + +func echoUnaryHandler(ctx context.Context, handler interface{}, arg, result interface{}) error { + if streaming.GetStream(ctx) == nil { + return errors.New("EchoService.EchoUnary is a thrift streaming unary method, please call with Kitex StreamClient or remove the annotation streaming.mode") + } + realArg := arg.(*echo.EchoServiceEchoUnaryArgs) + realResult := result.(*echo.EchoServiceEchoUnaryResult) + success, err := handler.(echo.EchoService).EchoUnary(ctx, realArg.Req1) + if err != nil { + return err + } + realResult.Success = success + return nil +} +func newEchoServiceEchoUnaryArgs() interface{} { + return echo.NewEchoServiceEchoUnaryArgs() +} + +func newEchoServiceEchoUnaryResult() interface{} { + return echo.NewEchoServiceEchoUnaryResult() +} + +func echoPingPongHandler(ctx context.Context, handler interface{}, arg, result interface{}) error { + realArg := arg.(*echo.EchoServiceEchoPingPongArgs) + realResult := result.(*echo.EchoServiceEchoPingPongResult) + success, err := handler.(echo.EchoService).EchoPingPong(ctx, realArg.Req1, realArg.Req2) + if err != nil { + switch v := err.(type) { + case *echo.EchoException: + realResult.E = v + default: + return err + } + } else { + realResult.Success = success + } + return nil +} +func newEchoServiceEchoPingPongArgs() interface{} { + return echo.NewEchoServiceEchoPingPongArgs() +} + +func newEchoServiceEchoPingPongResult() interface{} { + return echo.NewEchoServiceEchoPingPongResult() +} + +func echoOnewayHandler(ctx context.Context, handler interface{}, arg, result interface{}) error { + realArg := arg.(*echo.EchoServiceEchoOnewayArgs) + + err := handler.(echo.EchoService).EchoOneway(ctx, realArg.Req1) + if err != nil { + return err + } + + return nil +} +func newEchoServiceEchoOnewayArgs() interface{} { + return echo.NewEchoServiceEchoOnewayArgs() +} + +func newEchoServiceEchoOnewayResult() interface{} { + return echo.NewEchoServiceEchoOnewayResult() +} + +func pingHandler(ctx context.Context, handler interface{}, arg, result interface{}) error { + _ = arg.(*echo.EchoServicePingArgs) + + err := handler.(echo.EchoService).Ping(ctx) + if err != nil { + return err + } + + return nil +} +func newEchoServicePingArgs() interface{} { + return echo.NewEchoServicePingArgs() +} + +func newEchoServicePingResult() interface{} { + return echo.NewEchoServicePingResult() +} + +type kClient struct { + c client.Client +} + +func newServiceClient(c client.Client) *kClient { + return &kClient{ + c: c, + } +} + +func (p *kClient) EchoBidirectional(ctx context.Context) (EchoService_EchoBidirectionalClient, error) { + streamClient, ok := p.c.(client.Streaming) + if !ok { + return nil, fmt.Errorf("client not support streaming") + } + res := new(streaming.Result) + err := streamClient.Stream(ctx, "EchoBidirectional", nil, res) + if err != nil { + return nil, err + } + stream := &echoServiceEchoBidirectionalClient{res.Stream} + return stream, nil +} + +func (p *kClient) EchoClient(ctx context.Context) (EchoService_EchoClientClient, error) { + streamClient, ok := p.c.(client.Streaming) + if !ok { + return nil, fmt.Errorf("client not support streaming") + } + res := new(streaming.Result) + err := streamClient.Stream(ctx, "EchoClient", nil, res) + if err != nil { + return nil, err + } + stream := &echoServiceEchoClientClient{res.Stream} + return stream, nil +} + +func (p *kClient) EchoServer(ctx context.Context, req1 *echo.EchoRequest) (EchoService_EchoServerClient, error) { + streamClient, ok := p.c.(client.Streaming) + if !ok { + return nil, fmt.Errorf("client not support streaming") + } + res := new(streaming.Result) + err := streamClient.Stream(ctx, "EchoServer", nil, res) + if err != nil { + return nil, err + } + stream := &echoServiceEchoServerClient{res.Stream} + + if err := stream.Stream.SendMsg(req1); err != nil { + return nil, err + } + if err := stream.Stream.Close(); err != nil { + return nil, err + } + return stream, nil +} + +func (p *kClient) EchoUnary(ctx context.Context, req1 *echo.EchoRequest) (r *echo.EchoResponse, err error) { + var _args echo.EchoServiceEchoUnaryArgs + _args.Req1 = req1 + var _result echo.EchoServiceEchoUnaryResult + if err = p.c.Call(ctx, "EchoUnary", &_args, &_result); err != nil { + return + } + return _result.GetSuccess(), nil +} + +func (p *kClient) EchoPingPong(ctx context.Context, req1 *echo.EchoRequest, req2 *echo.EchoRequest) (r *echo.EchoResponse, err error) { + var _args echo.EchoServiceEchoPingPongArgs + _args.Req1 = req1 + _args.Req2 = req2 + var _result echo.EchoServiceEchoPingPongResult + if err = p.c.Call(ctx, "EchoPingPong", &_args, &_result); err != nil { + return + } + switch { + case _result.E != nil: + return r, _result.E + } + return _result.GetSuccess(), nil +} + +func (p *kClient) EchoOneway(ctx context.Context, req1 *echo.EchoRequest) (err error) { + var _args echo.EchoServiceEchoOnewayArgs + _args.Req1 = req1 + var _result echo.EchoServiceEchoOnewayResult + if err = p.c.Call(ctx, "EchoOneway", &_args, &_result); err != nil { + return + } + return nil +} + +func (p *kClient) Ping(ctx context.Context) (err error) { + var _args echo.EchoServicePingArgs + var _result echo.EchoServicePingResult + if err = p.c.Call(ctx, "Ping", &_args, &_result); err != nil { + return + } + return nil +} diff --git a/thrift_streaming/kitex_gen/echo/echoservice/invoker.go b/thrift_streaming/kitex_gen/echo/echoservice/invoker.go new file mode 100644 index 0000000..43818c6 --- /dev/null +++ b/thrift_streaming/kitex_gen/echo/echoservice/invoker.go @@ -0,0 +1,24 @@ +// Code generated by Kitex v0.8.0. DO NOT EDIT. + +package echoservice + +import ( + echo "github.com/cloudwego/kitex-tests/thrift_streaming/kitex_gen/echo" + server "github.com/cloudwego/kitex/server" +) + +// NewInvoker creates a server.Invoker with the given handler and options. +func NewInvoker(handler echo.EchoService, opts ...server.Option) server.Invoker { + var options []server.Option + + options = append(options, opts...) + + s := server.NewInvoker(options...) + if err := s.RegisterService(serviceInfo(), handler); err != nil { + panic(err) + } + if err := s.Init(); err != nil { + panic(err) + } + return s +} diff --git a/thrift_streaming/kitex_gen/echo/echoservice/server.go b/thrift_streaming/kitex_gen/echo/echoservice/server.go new file mode 100644 index 0000000..c634884 --- /dev/null +++ b/thrift_streaming/kitex_gen/echo/echoservice/server.go @@ -0,0 +1,21 @@ +// Code generated by Kitex v0.8.0. DO NOT EDIT. +package echoservice + +import ( + echo "github.com/cloudwego/kitex-tests/thrift_streaming/kitex_gen/echo" + server "github.com/cloudwego/kitex/server" +) + +// NewServer creates a server.Server with the given handler and options. +func NewServer(handler echo.EchoService, opts ...server.Option) server.Server { + var options []server.Option + + options = append(options, opts...) + options = append(options, server.WithCompatibleMiddlewareForUnary()) + + svr := server.NewServer(options...) + if err := svr.RegisterService(serviceInfo(), handler); err != nil { + panic(err) + } + return svr +} diff --git a/thrift_streaming/kitex_gen/echo/k-api.go b/thrift_streaming/kitex_gen/echo/k-api.go new file mode 100644 index 0000000..8d6dc2b --- /dev/null +++ b/thrift_streaming/kitex_gen/echo/k-api.go @@ -0,0 +1,2228 @@ +// Code generated by Kitex v0.8.0. DO NOT EDIT. + +package echo + +import ( + "bytes" + "fmt" + "reflect" + "strings" + + "github.com/apache/thrift/lib/go/thrift" + + "github.com/cloudwego/kitex/pkg/protocol/bthrift" +) + +// unused protection +var ( + _ = fmt.Formatter(nil) + _ = (*bytes.Buffer)(nil) + _ = (*strings.Builder)(nil) + _ = reflect.Type(nil) + _ = thrift.TProtocol(nil) + _ = bthrift.BinaryWriter(nil) +) + +func (p *EchoRequest) FastRead(buf []byte) (int, error) { + var err error + var offset int + var l int + var fieldTypeId thrift.TType + var fieldId int16 + var issetMessage bool = false + _, l, err = bthrift.Binary.ReadStructBegin(buf) + offset += l + if err != nil { + goto ReadStructBeginError + } + + for { + _, fieldTypeId, fieldId, l, err = bthrift.Binary.ReadFieldBegin(buf[offset:]) + offset += l + if err != nil { + goto ReadFieldBeginError + } + if fieldTypeId == thrift.STOP { + break + } + switch fieldId { + case 1: + if fieldTypeId == thrift.STRING { + l, err = p.FastReadField1(buf[offset:]) + offset += l + if err != nil { + goto ReadFieldError + } + issetMessage = true + } else { + l, err = bthrift.Binary.Skip(buf[offset:], fieldTypeId) + offset += l + if err != nil { + goto SkipFieldError + } + } + default: + l, err = bthrift.Binary.Skip(buf[offset:], fieldTypeId) + offset += l + if err != nil { + goto SkipFieldError + } + } + + l, err = bthrift.Binary.ReadFieldEnd(buf[offset:]) + offset += l + if err != nil { + goto ReadFieldEndError + } + } + l, err = bthrift.Binary.ReadStructEnd(buf[offset:]) + offset += l + if err != nil { + goto ReadStructEndError + } + + if !issetMessage { + fieldId = 1 + goto RequiredFieldNotSetError + } + return offset, nil +ReadStructBeginError: + return offset, thrift.PrependError(fmt.Sprintf("%T read struct begin error: ", p), err) +ReadFieldBeginError: + return offset, thrift.PrependError(fmt.Sprintf("%T read field %d begin error: ", p, fieldId), err) +ReadFieldError: + return offset, thrift.PrependError(fmt.Sprintf("%T read field %d '%s' error: ", p, fieldId, fieldIDToName_EchoRequest[fieldId]), err) +SkipFieldError: + return offset, thrift.PrependError(fmt.Sprintf("%T field %d skip type %d error: ", p, fieldId, fieldTypeId), err) +ReadFieldEndError: + return offset, thrift.PrependError(fmt.Sprintf("%T read field end error", p), err) +ReadStructEndError: + return offset, thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err) +RequiredFieldNotSetError: + return offset, thrift.NewTProtocolExceptionWithType(thrift.INVALID_DATA, fmt.Errorf("required field %s is not set", fieldIDToName_EchoRequest[fieldId])) +} + +func (p *EchoRequest) FastReadField1(buf []byte) (int, error) { + offset := 0 + + if v, l, err := bthrift.Binary.ReadString(buf[offset:]); err != nil { + return offset, err + } else { + offset += l + + p.Message = v + + } + return offset, nil +} + +// for compatibility +func (p *EchoRequest) FastWrite(buf []byte) int { + return 0 +} + +func (p *EchoRequest) FastWriteNocopy(buf []byte, binaryWriter bthrift.BinaryWriter) int { + offset := 0 + offset += bthrift.Binary.WriteStructBegin(buf[offset:], "EchoRequest") + if p != nil { + offset += p.fastWriteField1(buf[offset:], binaryWriter) + } + offset += bthrift.Binary.WriteFieldStop(buf[offset:]) + offset += bthrift.Binary.WriteStructEnd(buf[offset:]) + return offset +} + +func (p *EchoRequest) BLength() int { + l := 0 + l += bthrift.Binary.StructBeginLength("EchoRequest") + if p != nil { + l += p.field1Length() + } + l += bthrift.Binary.FieldStopLength() + l += bthrift.Binary.StructEndLength() + return l +} + +func (p *EchoRequest) fastWriteField1(buf []byte, binaryWriter bthrift.BinaryWriter) int { + offset := 0 + offset += bthrift.Binary.WriteFieldBegin(buf[offset:], "message", thrift.STRING, 1) + offset += bthrift.Binary.WriteStringNocopy(buf[offset:], binaryWriter, p.Message) + + offset += bthrift.Binary.WriteFieldEnd(buf[offset:]) + return offset +} + +func (p *EchoRequest) field1Length() int { + l := 0 + l += bthrift.Binary.FieldBeginLength("message", thrift.STRING, 1) + l += bthrift.Binary.StringLengthNocopy(p.Message) + + l += bthrift.Binary.FieldEndLength() + return l +} + +func (p *EchoResponse) FastRead(buf []byte) (int, error) { + var err error + var offset int + var l int + var fieldTypeId thrift.TType + var fieldId int16 + var issetMessage bool = false + _, l, err = bthrift.Binary.ReadStructBegin(buf) + offset += l + if err != nil { + goto ReadStructBeginError + } + + for { + _, fieldTypeId, fieldId, l, err = bthrift.Binary.ReadFieldBegin(buf[offset:]) + offset += l + if err != nil { + goto ReadFieldBeginError + } + if fieldTypeId == thrift.STOP { + break + } + switch fieldId { + case 1: + if fieldTypeId == thrift.STRING { + l, err = p.FastReadField1(buf[offset:]) + offset += l + if err != nil { + goto ReadFieldError + } + issetMessage = true + } else { + l, err = bthrift.Binary.Skip(buf[offset:], fieldTypeId) + offset += l + if err != nil { + goto SkipFieldError + } + } + default: + l, err = bthrift.Binary.Skip(buf[offset:], fieldTypeId) + offset += l + if err != nil { + goto SkipFieldError + } + } + + l, err = bthrift.Binary.ReadFieldEnd(buf[offset:]) + offset += l + if err != nil { + goto ReadFieldEndError + } + } + l, err = bthrift.Binary.ReadStructEnd(buf[offset:]) + offset += l + if err != nil { + goto ReadStructEndError + } + + if !issetMessage { + fieldId = 1 + goto RequiredFieldNotSetError + } + return offset, nil +ReadStructBeginError: + return offset, thrift.PrependError(fmt.Sprintf("%T read struct begin error: ", p), err) +ReadFieldBeginError: + return offset, thrift.PrependError(fmt.Sprintf("%T read field %d begin error: ", p, fieldId), err) +ReadFieldError: + return offset, thrift.PrependError(fmt.Sprintf("%T read field %d '%s' error: ", p, fieldId, fieldIDToName_EchoResponse[fieldId]), err) +SkipFieldError: + return offset, thrift.PrependError(fmt.Sprintf("%T field %d skip type %d error: ", p, fieldId, fieldTypeId), err) +ReadFieldEndError: + return offset, thrift.PrependError(fmt.Sprintf("%T read field end error", p), err) +ReadStructEndError: + return offset, thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err) +RequiredFieldNotSetError: + return offset, thrift.NewTProtocolExceptionWithType(thrift.INVALID_DATA, fmt.Errorf("required field %s is not set", fieldIDToName_EchoResponse[fieldId])) +} + +func (p *EchoResponse) FastReadField1(buf []byte) (int, error) { + offset := 0 + + if v, l, err := bthrift.Binary.ReadString(buf[offset:]); err != nil { + return offset, err + } else { + offset += l + + p.Message = v + + } + return offset, nil +} + +// for compatibility +func (p *EchoResponse) FastWrite(buf []byte) int { + return 0 +} + +func (p *EchoResponse) FastWriteNocopy(buf []byte, binaryWriter bthrift.BinaryWriter) int { + offset := 0 + offset += bthrift.Binary.WriteStructBegin(buf[offset:], "EchoResponse") + if p != nil { + offset += p.fastWriteField1(buf[offset:], binaryWriter) + } + offset += bthrift.Binary.WriteFieldStop(buf[offset:]) + offset += bthrift.Binary.WriteStructEnd(buf[offset:]) + return offset +} + +func (p *EchoResponse) BLength() int { + l := 0 + l += bthrift.Binary.StructBeginLength("EchoResponse") + if p != nil { + l += p.field1Length() + } + l += bthrift.Binary.FieldStopLength() + l += bthrift.Binary.StructEndLength() + return l +} + +func (p *EchoResponse) fastWriteField1(buf []byte, binaryWriter bthrift.BinaryWriter) int { + offset := 0 + offset += bthrift.Binary.WriteFieldBegin(buf[offset:], "message", thrift.STRING, 1) + offset += bthrift.Binary.WriteStringNocopy(buf[offset:], binaryWriter, p.Message) + + offset += bthrift.Binary.WriteFieldEnd(buf[offset:]) + return offset +} + +func (p *EchoResponse) field1Length() int { + l := 0 + l += bthrift.Binary.FieldBeginLength("message", thrift.STRING, 1) + l += bthrift.Binary.StringLengthNocopy(p.Message) + + l += bthrift.Binary.FieldEndLength() + return l +} + +func (p *EchoException) FastRead(buf []byte) (int, error) { + var err error + var offset int + var l int + var fieldTypeId thrift.TType + var fieldId int16 + _, l, err = bthrift.Binary.ReadStructBegin(buf) + offset += l + if err != nil { + goto ReadStructBeginError + } + + for { + _, fieldTypeId, fieldId, l, err = bthrift.Binary.ReadFieldBegin(buf[offset:]) + offset += l + if err != nil { + goto ReadFieldBeginError + } + if fieldTypeId == thrift.STOP { + break + } + switch fieldId { + case 1: + if fieldTypeId == thrift.STRING { + l, err = p.FastReadField1(buf[offset:]) + offset += l + if err != nil { + goto ReadFieldError + } + } else { + l, err = bthrift.Binary.Skip(buf[offset:], fieldTypeId) + offset += l + if err != nil { + goto SkipFieldError + } + } + default: + l, err = bthrift.Binary.Skip(buf[offset:], fieldTypeId) + offset += l + if err != nil { + goto SkipFieldError + } + } + + l, err = bthrift.Binary.ReadFieldEnd(buf[offset:]) + offset += l + if err != nil { + goto ReadFieldEndError + } + } + l, err = bthrift.Binary.ReadStructEnd(buf[offset:]) + offset += l + if err != nil { + goto ReadStructEndError + } + + return offset, nil +ReadStructBeginError: + return offset, thrift.PrependError(fmt.Sprintf("%T read struct begin error: ", p), err) +ReadFieldBeginError: + return offset, thrift.PrependError(fmt.Sprintf("%T read field %d begin error: ", p, fieldId), err) +ReadFieldError: + return offset, thrift.PrependError(fmt.Sprintf("%T read field %d '%s' error: ", p, fieldId, fieldIDToName_EchoException[fieldId]), err) +SkipFieldError: + return offset, thrift.PrependError(fmt.Sprintf("%T field %d skip type %d error: ", p, fieldId, fieldTypeId), err) +ReadFieldEndError: + return offset, thrift.PrependError(fmt.Sprintf("%T read field end error", p), err) +ReadStructEndError: + return offset, thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err) +} + +func (p *EchoException) FastReadField1(buf []byte) (int, error) { + offset := 0 + + if v, l, err := bthrift.Binary.ReadString(buf[offset:]); err != nil { + return offset, err + } else { + offset += l + + p.Message = v + + } + return offset, nil +} + +// for compatibility +func (p *EchoException) FastWrite(buf []byte) int { + return 0 +} + +func (p *EchoException) FastWriteNocopy(buf []byte, binaryWriter bthrift.BinaryWriter) int { + offset := 0 + offset += bthrift.Binary.WriteStructBegin(buf[offset:], "EchoException") + if p != nil { + offset += p.fastWriteField1(buf[offset:], binaryWriter) + } + offset += bthrift.Binary.WriteFieldStop(buf[offset:]) + offset += bthrift.Binary.WriteStructEnd(buf[offset:]) + return offset +} + +func (p *EchoException) BLength() int { + l := 0 + l += bthrift.Binary.StructBeginLength("EchoException") + if p != nil { + l += p.field1Length() + } + l += bthrift.Binary.FieldStopLength() + l += bthrift.Binary.StructEndLength() + return l +} + +func (p *EchoException) fastWriteField1(buf []byte, binaryWriter bthrift.BinaryWriter) int { + offset := 0 + offset += bthrift.Binary.WriteFieldBegin(buf[offset:], "message", thrift.STRING, 1) + offset += bthrift.Binary.WriteStringNocopy(buf[offset:], binaryWriter, p.Message) + + offset += bthrift.Binary.WriteFieldEnd(buf[offset:]) + return offset +} + +func (p *EchoException) field1Length() int { + l := 0 + l += bthrift.Binary.FieldBeginLength("message", thrift.STRING, 1) + l += bthrift.Binary.StringLengthNocopy(p.Message) + + l += bthrift.Binary.FieldEndLength() + return l +} + +func (p *EchoServiceEchoBidirectionalArgs) FastRead(buf []byte) (int, error) { + var err error + var offset int + var l int + var fieldTypeId thrift.TType + var fieldId int16 + _, l, err = bthrift.Binary.ReadStructBegin(buf) + offset += l + if err != nil { + goto ReadStructBeginError + } + + for { + _, fieldTypeId, fieldId, l, err = bthrift.Binary.ReadFieldBegin(buf[offset:]) + offset += l + if err != nil { + goto ReadFieldBeginError + } + if fieldTypeId == thrift.STOP { + break + } + switch fieldId { + case 1: + if fieldTypeId == thrift.STRUCT { + l, err = p.FastReadField1(buf[offset:]) + offset += l + if err != nil { + goto ReadFieldError + } + } else { + l, err = bthrift.Binary.Skip(buf[offset:], fieldTypeId) + offset += l + if err != nil { + goto SkipFieldError + } + } + default: + l, err = bthrift.Binary.Skip(buf[offset:], fieldTypeId) + offset += l + if err != nil { + goto SkipFieldError + } + } + + l, err = bthrift.Binary.ReadFieldEnd(buf[offset:]) + offset += l + if err != nil { + goto ReadFieldEndError + } + } + l, err = bthrift.Binary.ReadStructEnd(buf[offset:]) + offset += l + if err != nil { + goto ReadStructEndError + } + + return offset, nil +ReadStructBeginError: + return offset, thrift.PrependError(fmt.Sprintf("%T read struct begin error: ", p), err) +ReadFieldBeginError: + return offset, thrift.PrependError(fmt.Sprintf("%T read field %d begin error: ", p, fieldId), err) +ReadFieldError: + return offset, thrift.PrependError(fmt.Sprintf("%T read field %d '%s' error: ", p, fieldId, fieldIDToName_EchoServiceEchoBidirectionalArgs[fieldId]), err) +SkipFieldError: + return offset, thrift.PrependError(fmt.Sprintf("%T field %d skip type %d error: ", p, fieldId, fieldTypeId), err) +ReadFieldEndError: + return offset, thrift.PrependError(fmt.Sprintf("%T read field end error", p), err) +ReadStructEndError: + return offset, thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err) +} + +func (p *EchoServiceEchoBidirectionalArgs) FastReadField1(buf []byte) (int, error) { + offset := 0 + + tmp := NewEchoRequest() + if l, err := tmp.FastRead(buf[offset:]); err != nil { + return offset, err + } else { + offset += l + } + p.Req1 = tmp + return offset, nil +} + +// for compatibility +func (p *EchoServiceEchoBidirectionalArgs) FastWrite(buf []byte) int { + return 0 +} + +func (p *EchoServiceEchoBidirectionalArgs) FastWriteNocopy(buf []byte, binaryWriter bthrift.BinaryWriter) int { + offset := 0 + offset += bthrift.Binary.WriteStructBegin(buf[offset:], "EchoBidirectional_args") + if p != nil { + offset += p.fastWriteField1(buf[offset:], binaryWriter) + } + offset += bthrift.Binary.WriteFieldStop(buf[offset:]) + offset += bthrift.Binary.WriteStructEnd(buf[offset:]) + return offset +} + +func (p *EchoServiceEchoBidirectionalArgs) BLength() int { + l := 0 + l += bthrift.Binary.StructBeginLength("EchoBidirectional_args") + if p != nil { + l += p.field1Length() + } + l += bthrift.Binary.FieldStopLength() + l += bthrift.Binary.StructEndLength() + return l +} + +func (p *EchoServiceEchoBidirectionalArgs) fastWriteField1(buf []byte, binaryWriter bthrift.BinaryWriter) int { + offset := 0 + offset += bthrift.Binary.WriteFieldBegin(buf[offset:], "req1", thrift.STRUCT, 1) + offset += p.Req1.FastWriteNocopy(buf[offset:], binaryWriter) + offset += bthrift.Binary.WriteFieldEnd(buf[offset:]) + return offset +} + +func (p *EchoServiceEchoBidirectionalArgs) field1Length() int { + l := 0 + l += bthrift.Binary.FieldBeginLength("req1", thrift.STRUCT, 1) + l += p.Req1.BLength() + l += bthrift.Binary.FieldEndLength() + return l +} + +func (p *EchoServiceEchoBidirectionalResult) FastRead(buf []byte) (int, error) { + var err error + var offset int + var l int + var fieldTypeId thrift.TType + var fieldId int16 + _, l, err = bthrift.Binary.ReadStructBegin(buf) + offset += l + if err != nil { + goto ReadStructBeginError + } + + for { + _, fieldTypeId, fieldId, l, err = bthrift.Binary.ReadFieldBegin(buf[offset:]) + offset += l + if err != nil { + goto ReadFieldBeginError + } + if fieldTypeId == thrift.STOP { + break + } + switch fieldId { + case 0: + if fieldTypeId == thrift.STRUCT { + l, err = p.FastReadField0(buf[offset:]) + offset += l + if err != nil { + goto ReadFieldError + } + } else { + l, err = bthrift.Binary.Skip(buf[offset:], fieldTypeId) + offset += l + if err != nil { + goto SkipFieldError + } + } + default: + l, err = bthrift.Binary.Skip(buf[offset:], fieldTypeId) + offset += l + if err != nil { + goto SkipFieldError + } + } + + l, err = bthrift.Binary.ReadFieldEnd(buf[offset:]) + offset += l + if err != nil { + goto ReadFieldEndError + } + } + l, err = bthrift.Binary.ReadStructEnd(buf[offset:]) + offset += l + if err != nil { + goto ReadStructEndError + } + + return offset, nil +ReadStructBeginError: + return offset, thrift.PrependError(fmt.Sprintf("%T read struct begin error: ", p), err) +ReadFieldBeginError: + return offset, thrift.PrependError(fmt.Sprintf("%T read field %d begin error: ", p, fieldId), err) +ReadFieldError: + return offset, thrift.PrependError(fmt.Sprintf("%T read field %d '%s' error: ", p, fieldId, fieldIDToName_EchoServiceEchoBidirectionalResult[fieldId]), err) +SkipFieldError: + return offset, thrift.PrependError(fmt.Sprintf("%T field %d skip type %d error: ", p, fieldId, fieldTypeId), err) +ReadFieldEndError: + return offset, thrift.PrependError(fmt.Sprintf("%T read field end error", p), err) +ReadStructEndError: + return offset, thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err) +} + +func (p *EchoServiceEchoBidirectionalResult) FastReadField0(buf []byte) (int, error) { + offset := 0 + + tmp := NewEchoResponse() + if l, err := tmp.FastRead(buf[offset:]); err != nil { + return offset, err + } else { + offset += l + } + p.Success = tmp + return offset, nil +} + +// for compatibility +func (p *EchoServiceEchoBidirectionalResult) FastWrite(buf []byte) int { + return 0 +} + +func (p *EchoServiceEchoBidirectionalResult) FastWriteNocopy(buf []byte, binaryWriter bthrift.BinaryWriter) int { + offset := 0 + offset += bthrift.Binary.WriteStructBegin(buf[offset:], "EchoBidirectional_result") + if p != nil { + offset += p.fastWriteField0(buf[offset:], binaryWriter) + } + offset += bthrift.Binary.WriteFieldStop(buf[offset:]) + offset += bthrift.Binary.WriteStructEnd(buf[offset:]) + return offset +} + +func (p *EchoServiceEchoBidirectionalResult) BLength() int { + l := 0 + l += bthrift.Binary.StructBeginLength("EchoBidirectional_result") + if p != nil { + l += p.field0Length() + } + l += bthrift.Binary.FieldStopLength() + l += bthrift.Binary.StructEndLength() + return l +} + +func (p *EchoServiceEchoBidirectionalResult) fastWriteField0(buf []byte, binaryWriter bthrift.BinaryWriter) int { + offset := 0 + if p.IsSetSuccess() { + offset += bthrift.Binary.WriteFieldBegin(buf[offset:], "success", thrift.STRUCT, 0) + offset += p.Success.FastWriteNocopy(buf[offset:], binaryWriter) + offset += bthrift.Binary.WriteFieldEnd(buf[offset:]) + } + return offset +} + +func (p *EchoServiceEchoBidirectionalResult) field0Length() int { + l := 0 + if p.IsSetSuccess() { + l += bthrift.Binary.FieldBeginLength("success", thrift.STRUCT, 0) + l += p.Success.BLength() + l += bthrift.Binary.FieldEndLength() + } + return l +} + +func (p *EchoServiceEchoClientArgs) FastRead(buf []byte) (int, error) { + var err error + var offset int + var l int + var fieldTypeId thrift.TType + var fieldId int16 + _, l, err = bthrift.Binary.ReadStructBegin(buf) + offset += l + if err != nil { + goto ReadStructBeginError + } + + for { + _, fieldTypeId, fieldId, l, err = bthrift.Binary.ReadFieldBegin(buf[offset:]) + offset += l + if err != nil { + goto ReadFieldBeginError + } + if fieldTypeId == thrift.STOP { + break + } + switch fieldId { + case 1: + if fieldTypeId == thrift.STRUCT { + l, err = p.FastReadField1(buf[offset:]) + offset += l + if err != nil { + goto ReadFieldError + } + } else { + l, err = bthrift.Binary.Skip(buf[offset:], fieldTypeId) + offset += l + if err != nil { + goto SkipFieldError + } + } + default: + l, err = bthrift.Binary.Skip(buf[offset:], fieldTypeId) + offset += l + if err != nil { + goto SkipFieldError + } + } + + l, err = bthrift.Binary.ReadFieldEnd(buf[offset:]) + offset += l + if err != nil { + goto ReadFieldEndError + } + } + l, err = bthrift.Binary.ReadStructEnd(buf[offset:]) + offset += l + if err != nil { + goto ReadStructEndError + } + + return offset, nil +ReadStructBeginError: + return offset, thrift.PrependError(fmt.Sprintf("%T read struct begin error: ", p), err) +ReadFieldBeginError: + return offset, thrift.PrependError(fmt.Sprintf("%T read field %d begin error: ", p, fieldId), err) +ReadFieldError: + return offset, thrift.PrependError(fmt.Sprintf("%T read field %d '%s' error: ", p, fieldId, fieldIDToName_EchoServiceEchoClientArgs[fieldId]), err) +SkipFieldError: + return offset, thrift.PrependError(fmt.Sprintf("%T field %d skip type %d error: ", p, fieldId, fieldTypeId), err) +ReadFieldEndError: + return offset, thrift.PrependError(fmt.Sprintf("%T read field end error", p), err) +ReadStructEndError: + return offset, thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err) +} + +func (p *EchoServiceEchoClientArgs) FastReadField1(buf []byte) (int, error) { + offset := 0 + + tmp := NewEchoRequest() + if l, err := tmp.FastRead(buf[offset:]); err != nil { + return offset, err + } else { + offset += l + } + p.Req1 = tmp + return offset, nil +} + +// for compatibility +func (p *EchoServiceEchoClientArgs) FastWrite(buf []byte) int { + return 0 +} + +func (p *EchoServiceEchoClientArgs) FastWriteNocopy(buf []byte, binaryWriter bthrift.BinaryWriter) int { + offset := 0 + offset += bthrift.Binary.WriteStructBegin(buf[offset:], "EchoClient_args") + if p != nil { + offset += p.fastWriteField1(buf[offset:], binaryWriter) + } + offset += bthrift.Binary.WriteFieldStop(buf[offset:]) + offset += bthrift.Binary.WriteStructEnd(buf[offset:]) + return offset +} + +func (p *EchoServiceEchoClientArgs) BLength() int { + l := 0 + l += bthrift.Binary.StructBeginLength("EchoClient_args") + if p != nil { + l += p.field1Length() + } + l += bthrift.Binary.FieldStopLength() + l += bthrift.Binary.StructEndLength() + return l +} + +func (p *EchoServiceEchoClientArgs) fastWriteField1(buf []byte, binaryWriter bthrift.BinaryWriter) int { + offset := 0 + offset += bthrift.Binary.WriteFieldBegin(buf[offset:], "req1", thrift.STRUCT, 1) + offset += p.Req1.FastWriteNocopy(buf[offset:], binaryWriter) + offset += bthrift.Binary.WriteFieldEnd(buf[offset:]) + return offset +} + +func (p *EchoServiceEchoClientArgs) field1Length() int { + l := 0 + l += bthrift.Binary.FieldBeginLength("req1", thrift.STRUCT, 1) + l += p.Req1.BLength() + l += bthrift.Binary.FieldEndLength() + return l +} + +func (p *EchoServiceEchoClientResult) FastRead(buf []byte) (int, error) { + var err error + var offset int + var l int + var fieldTypeId thrift.TType + var fieldId int16 + _, l, err = bthrift.Binary.ReadStructBegin(buf) + offset += l + if err != nil { + goto ReadStructBeginError + } + + for { + _, fieldTypeId, fieldId, l, err = bthrift.Binary.ReadFieldBegin(buf[offset:]) + offset += l + if err != nil { + goto ReadFieldBeginError + } + if fieldTypeId == thrift.STOP { + break + } + switch fieldId { + case 0: + if fieldTypeId == thrift.STRUCT { + l, err = p.FastReadField0(buf[offset:]) + offset += l + if err != nil { + goto ReadFieldError + } + } else { + l, err = bthrift.Binary.Skip(buf[offset:], fieldTypeId) + offset += l + if err != nil { + goto SkipFieldError + } + } + default: + l, err = bthrift.Binary.Skip(buf[offset:], fieldTypeId) + offset += l + if err != nil { + goto SkipFieldError + } + } + + l, err = bthrift.Binary.ReadFieldEnd(buf[offset:]) + offset += l + if err != nil { + goto ReadFieldEndError + } + } + l, err = bthrift.Binary.ReadStructEnd(buf[offset:]) + offset += l + if err != nil { + goto ReadStructEndError + } + + return offset, nil +ReadStructBeginError: + return offset, thrift.PrependError(fmt.Sprintf("%T read struct begin error: ", p), err) +ReadFieldBeginError: + return offset, thrift.PrependError(fmt.Sprintf("%T read field %d begin error: ", p, fieldId), err) +ReadFieldError: + return offset, thrift.PrependError(fmt.Sprintf("%T read field %d '%s' error: ", p, fieldId, fieldIDToName_EchoServiceEchoClientResult[fieldId]), err) +SkipFieldError: + return offset, thrift.PrependError(fmt.Sprintf("%T field %d skip type %d error: ", p, fieldId, fieldTypeId), err) +ReadFieldEndError: + return offset, thrift.PrependError(fmt.Sprintf("%T read field end error", p), err) +ReadStructEndError: + return offset, thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err) +} + +func (p *EchoServiceEchoClientResult) FastReadField0(buf []byte) (int, error) { + offset := 0 + + tmp := NewEchoResponse() + if l, err := tmp.FastRead(buf[offset:]); err != nil { + return offset, err + } else { + offset += l + } + p.Success = tmp + return offset, nil +} + +// for compatibility +func (p *EchoServiceEchoClientResult) FastWrite(buf []byte) int { + return 0 +} + +func (p *EchoServiceEchoClientResult) FastWriteNocopy(buf []byte, binaryWriter bthrift.BinaryWriter) int { + offset := 0 + offset += bthrift.Binary.WriteStructBegin(buf[offset:], "EchoClient_result") + if p != nil { + offset += p.fastWriteField0(buf[offset:], binaryWriter) + } + offset += bthrift.Binary.WriteFieldStop(buf[offset:]) + offset += bthrift.Binary.WriteStructEnd(buf[offset:]) + return offset +} + +func (p *EchoServiceEchoClientResult) BLength() int { + l := 0 + l += bthrift.Binary.StructBeginLength("EchoClient_result") + if p != nil { + l += p.field0Length() + } + l += bthrift.Binary.FieldStopLength() + l += bthrift.Binary.StructEndLength() + return l +} + +func (p *EchoServiceEchoClientResult) fastWriteField0(buf []byte, binaryWriter bthrift.BinaryWriter) int { + offset := 0 + if p.IsSetSuccess() { + offset += bthrift.Binary.WriteFieldBegin(buf[offset:], "success", thrift.STRUCT, 0) + offset += p.Success.FastWriteNocopy(buf[offset:], binaryWriter) + offset += bthrift.Binary.WriteFieldEnd(buf[offset:]) + } + return offset +} + +func (p *EchoServiceEchoClientResult) field0Length() int { + l := 0 + if p.IsSetSuccess() { + l += bthrift.Binary.FieldBeginLength("success", thrift.STRUCT, 0) + l += p.Success.BLength() + l += bthrift.Binary.FieldEndLength() + } + return l +} + +func (p *EchoServiceEchoServerArgs) FastRead(buf []byte) (int, error) { + var err error + var offset int + var l int + var fieldTypeId thrift.TType + var fieldId int16 + _, l, err = bthrift.Binary.ReadStructBegin(buf) + offset += l + if err != nil { + goto ReadStructBeginError + } + + for { + _, fieldTypeId, fieldId, l, err = bthrift.Binary.ReadFieldBegin(buf[offset:]) + offset += l + if err != nil { + goto ReadFieldBeginError + } + if fieldTypeId == thrift.STOP { + break + } + switch fieldId { + case 1: + if fieldTypeId == thrift.STRUCT { + l, err = p.FastReadField1(buf[offset:]) + offset += l + if err != nil { + goto ReadFieldError + } + } else { + l, err = bthrift.Binary.Skip(buf[offset:], fieldTypeId) + offset += l + if err != nil { + goto SkipFieldError + } + } + default: + l, err = bthrift.Binary.Skip(buf[offset:], fieldTypeId) + offset += l + if err != nil { + goto SkipFieldError + } + } + + l, err = bthrift.Binary.ReadFieldEnd(buf[offset:]) + offset += l + if err != nil { + goto ReadFieldEndError + } + } + l, err = bthrift.Binary.ReadStructEnd(buf[offset:]) + offset += l + if err != nil { + goto ReadStructEndError + } + + return offset, nil +ReadStructBeginError: + return offset, thrift.PrependError(fmt.Sprintf("%T read struct begin error: ", p), err) +ReadFieldBeginError: + return offset, thrift.PrependError(fmt.Sprintf("%T read field %d begin error: ", p, fieldId), err) +ReadFieldError: + return offset, thrift.PrependError(fmt.Sprintf("%T read field %d '%s' error: ", p, fieldId, fieldIDToName_EchoServiceEchoServerArgs[fieldId]), err) +SkipFieldError: + return offset, thrift.PrependError(fmt.Sprintf("%T field %d skip type %d error: ", p, fieldId, fieldTypeId), err) +ReadFieldEndError: + return offset, thrift.PrependError(fmt.Sprintf("%T read field end error", p), err) +ReadStructEndError: + return offset, thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err) +} + +func (p *EchoServiceEchoServerArgs) FastReadField1(buf []byte) (int, error) { + offset := 0 + + tmp := NewEchoRequest() + if l, err := tmp.FastRead(buf[offset:]); err != nil { + return offset, err + } else { + offset += l + } + p.Req1 = tmp + return offset, nil +} + +// for compatibility +func (p *EchoServiceEchoServerArgs) FastWrite(buf []byte) int { + return 0 +} + +func (p *EchoServiceEchoServerArgs) FastWriteNocopy(buf []byte, binaryWriter bthrift.BinaryWriter) int { + offset := 0 + offset += bthrift.Binary.WriteStructBegin(buf[offset:], "EchoServer_args") + if p != nil { + offset += p.fastWriteField1(buf[offset:], binaryWriter) + } + offset += bthrift.Binary.WriteFieldStop(buf[offset:]) + offset += bthrift.Binary.WriteStructEnd(buf[offset:]) + return offset +} + +func (p *EchoServiceEchoServerArgs) BLength() int { + l := 0 + l += bthrift.Binary.StructBeginLength("EchoServer_args") + if p != nil { + l += p.field1Length() + } + l += bthrift.Binary.FieldStopLength() + l += bthrift.Binary.StructEndLength() + return l +} + +func (p *EchoServiceEchoServerArgs) fastWriteField1(buf []byte, binaryWriter bthrift.BinaryWriter) int { + offset := 0 + offset += bthrift.Binary.WriteFieldBegin(buf[offset:], "req1", thrift.STRUCT, 1) + offset += p.Req1.FastWriteNocopy(buf[offset:], binaryWriter) + offset += bthrift.Binary.WriteFieldEnd(buf[offset:]) + return offset +} + +func (p *EchoServiceEchoServerArgs) field1Length() int { + l := 0 + l += bthrift.Binary.FieldBeginLength("req1", thrift.STRUCT, 1) + l += p.Req1.BLength() + l += bthrift.Binary.FieldEndLength() + return l +} + +func (p *EchoServiceEchoServerResult) FastRead(buf []byte) (int, error) { + var err error + var offset int + var l int + var fieldTypeId thrift.TType + var fieldId int16 + _, l, err = bthrift.Binary.ReadStructBegin(buf) + offset += l + if err != nil { + goto ReadStructBeginError + } + + for { + _, fieldTypeId, fieldId, l, err = bthrift.Binary.ReadFieldBegin(buf[offset:]) + offset += l + if err != nil { + goto ReadFieldBeginError + } + if fieldTypeId == thrift.STOP { + break + } + switch fieldId { + case 0: + if fieldTypeId == thrift.STRUCT { + l, err = p.FastReadField0(buf[offset:]) + offset += l + if err != nil { + goto ReadFieldError + } + } else { + l, err = bthrift.Binary.Skip(buf[offset:], fieldTypeId) + offset += l + if err != nil { + goto SkipFieldError + } + } + default: + l, err = bthrift.Binary.Skip(buf[offset:], fieldTypeId) + offset += l + if err != nil { + goto SkipFieldError + } + } + + l, err = bthrift.Binary.ReadFieldEnd(buf[offset:]) + offset += l + if err != nil { + goto ReadFieldEndError + } + } + l, err = bthrift.Binary.ReadStructEnd(buf[offset:]) + offset += l + if err != nil { + goto ReadStructEndError + } + + return offset, nil +ReadStructBeginError: + return offset, thrift.PrependError(fmt.Sprintf("%T read struct begin error: ", p), err) +ReadFieldBeginError: + return offset, thrift.PrependError(fmt.Sprintf("%T read field %d begin error: ", p, fieldId), err) +ReadFieldError: + return offset, thrift.PrependError(fmt.Sprintf("%T read field %d '%s' error: ", p, fieldId, fieldIDToName_EchoServiceEchoServerResult[fieldId]), err) +SkipFieldError: + return offset, thrift.PrependError(fmt.Sprintf("%T field %d skip type %d error: ", p, fieldId, fieldTypeId), err) +ReadFieldEndError: + return offset, thrift.PrependError(fmt.Sprintf("%T read field end error", p), err) +ReadStructEndError: + return offset, thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err) +} + +func (p *EchoServiceEchoServerResult) FastReadField0(buf []byte) (int, error) { + offset := 0 + + tmp := NewEchoResponse() + if l, err := tmp.FastRead(buf[offset:]); err != nil { + return offset, err + } else { + offset += l + } + p.Success = tmp + return offset, nil +} + +// for compatibility +func (p *EchoServiceEchoServerResult) FastWrite(buf []byte) int { + return 0 +} + +func (p *EchoServiceEchoServerResult) FastWriteNocopy(buf []byte, binaryWriter bthrift.BinaryWriter) int { + offset := 0 + offset += bthrift.Binary.WriteStructBegin(buf[offset:], "EchoServer_result") + if p != nil { + offset += p.fastWriteField0(buf[offset:], binaryWriter) + } + offset += bthrift.Binary.WriteFieldStop(buf[offset:]) + offset += bthrift.Binary.WriteStructEnd(buf[offset:]) + return offset +} + +func (p *EchoServiceEchoServerResult) BLength() int { + l := 0 + l += bthrift.Binary.StructBeginLength("EchoServer_result") + if p != nil { + l += p.field0Length() + } + l += bthrift.Binary.FieldStopLength() + l += bthrift.Binary.StructEndLength() + return l +} + +func (p *EchoServiceEchoServerResult) fastWriteField0(buf []byte, binaryWriter bthrift.BinaryWriter) int { + offset := 0 + if p.IsSetSuccess() { + offset += bthrift.Binary.WriteFieldBegin(buf[offset:], "success", thrift.STRUCT, 0) + offset += p.Success.FastWriteNocopy(buf[offset:], binaryWriter) + offset += bthrift.Binary.WriteFieldEnd(buf[offset:]) + } + return offset +} + +func (p *EchoServiceEchoServerResult) field0Length() int { + l := 0 + if p.IsSetSuccess() { + l += bthrift.Binary.FieldBeginLength("success", thrift.STRUCT, 0) + l += p.Success.BLength() + l += bthrift.Binary.FieldEndLength() + } + return l +} + +func (p *EchoServiceEchoUnaryArgs) FastRead(buf []byte) (int, error) { + var err error + var offset int + var l int + var fieldTypeId thrift.TType + var fieldId int16 + _, l, err = bthrift.Binary.ReadStructBegin(buf) + offset += l + if err != nil { + goto ReadStructBeginError + } + + for { + _, fieldTypeId, fieldId, l, err = bthrift.Binary.ReadFieldBegin(buf[offset:]) + offset += l + if err != nil { + goto ReadFieldBeginError + } + if fieldTypeId == thrift.STOP { + break + } + switch fieldId { + case 1: + if fieldTypeId == thrift.STRUCT { + l, err = p.FastReadField1(buf[offset:]) + offset += l + if err != nil { + goto ReadFieldError + } + } else { + l, err = bthrift.Binary.Skip(buf[offset:], fieldTypeId) + offset += l + if err != nil { + goto SkipFieldError + } + } + default: + l, err = bthrift.Binary.Skip(buf[offset:], fieldTypeId) + offset += l + if err != nil { + goto SkipFieldError + } + } + + l, err = bthrift.Binary.ReadFieldEnd(buf[offset:]) + offset += l + if err != nil { + goto ReadFieldEndError + } + } + l, err = bthrift.Binary.ReadStructEnd(buf[offset:]) + offset += l + if err != nil { + goto ReadStructEndError + } + + return offset, nil +ReadStructBeginError: + return offset, thrift.PrependError(fmt.Sprintf("%T read struct begin error: ", p), err) +ReadFieldBeginError: + return offset, thrift.PrependError(fmt.Sprintf("%T read field %d begin error: ", p, fieldId), err) +ReadFieldError: + return offset, thrift.PrependError(fmt.Sprintf("%T read field %d '%s' error: ", p, fieldId, fieldIDToName_EchoServiceEchoUnaryArgs[fieldId]), err) +SkipFieldError: + return offset, thrift.PrependError(fmt.Sprintf("%T field %d skip type %d error: ", p, fieldId, fieldTypeId), err) +ReadFieldEndError: + return offset, thrift.PrependError(fmt.Sprintf("%T read field end error", p), err) +ReadStructEndError: + return offset, thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err) +} + +func (p *EchoServiceEchoUnaryArgs) FastReadField1(buf []byte) (int, error) { + offset := 0 + + tmp := NewEchoRequest() + if l, err := tmp.FastRead(buf[offset:]); err != nil { + return offset, err + } else { + offset += l + } + p.Req1 = tmp + return offset, nil +} + +// for compatibility +func (p *EchoServiceEchoUnaryArgs) FastWrite(buf []byte) int { + return 0 +} + +func (p *EchoServiceEchoUnaryArgs) FastWriteNocopy(buf []byte, binaryWriter bthrift.BinaryWriter) int { + offset := 0 + offset += bthrift.Binary.WriteStructBegin(buf[offset:], "EchoUnary_args") + if p != nil { + offset += p.fastWriteField1(buf[offset:], binaryWriter) + } + offset += bthrift.Binary.WriteFieldStop(buf[offset:]) + offset += bthrift.Binary.WriteStructEnd(buf[offset:]) + return offset +} + +func (p *EchoServiceEchoUnaryArgs) BLength() int { + l := 0 + l += bthrift.Binary.StructBeginLength("EchoUnary_args") + if p != nil { + l += p.field1Length() + } + l += bthrift.Binary.FieldStopLength() + l += bthrift.Binary.StructEndLength() + return l +} + +func (p *EchoServiceEchoUnaryArgs) fastWriteField1(buf []byte, binaryWriter bthrift.BinaryWriter) int { + offset := 0 + offset += bthrift.Binary.WriteFieldBegin(buf[offset:], "req1", thrift.STRUCT, 1) + offset += p.Req1.FastWriteNocopy(buf[offset:], binaryWriter) + offset += bthrift.Binary.WriteFieldEnd(buf[offset:]) + return offset +} + +func (p *EchoServiceEchoUnaryArgs) field1Length() int { + l := 0 + l += bthrift.Binary.FieldBeginLength("req1", thrift.STRUCT, 1) + l += p.Req1.BLength() + l += bthrift.Binary.FieldEndLength() + return l +} + +func (p *EchoServiceEchoUnaryResult) FastRead(buf []byte) (int, error) { + var err error + var offset int + var l int + var fieldTypeId thrift.TType + var fieldId int16 + _, l, err = bthrift.Binary.ReadStructBegin(buf) + offset += l + if err != nil { + goto ReadStructBeginError + } + + for { + _, fieldTypeId, fieldId, l, err = bthrift.Binary.ReadFieldBegin(buf[offset:]) + offset += l + if err != nil { + goto ReadFieldBeginError + } + if fieldTypeId == thrift.STOP { + break + } + switch fieldId { + case 0: + if fieldTypeId == thrift.STRUCT { + l, err = p.FastReadField0(buf[offset:]) + offset += l + if err != nil { + goto ReadFieldError + } + } else { + l, err = bthrift.Binary.Skip(buf[offset:], fieldTypeId) + offset += l + if err != nil { + goto SkipFieldError + } + } + default: + l, err = bthrift.Binary.Skip(buf[offset:], fieldTypeId) + offset += l + if err != nil { + goto SkipFieldError + } + } + + l, err = bthrift.Binary.ReadFieldEnd(buf[offset:]) + offset += l + if err != nil { + goto ReadFieldEndError + } + } + l, err = bthrift.Binary.ReadStructEnd(buf[offset:]) + offset += l + if err != nil { + goto ReadStructEndError + } + + return offset, nil +ReadStructBeginError: + return offset, thrift.PrependError(fmt.Sprintf("%T read struct begin error: ", p), err) +ReadFieldBeginError: + return offset, thrift.PrependError(fmt.Sprintf("%T read field %d begin error: ", p, fieldId), err) +ReadFieldError: + return offset, thrift.PrependError(fmt.Sprintf("%T read field %d '%s' error: ", p, fieldId, fieldIDToName_EchoServiceEchoUnaryResult[fieldId]), err) +SkipFieldError: + return offset, thrift.PrependError(fmt.Sprintf("%T field %d skip type %d error: ", p, fieldId, fieldTypeId), err) +ReadFieldEndError: + return offset, thrift.PrependError(fmt.Sprintf("%T read field end error", p), err) +ReadStructEndError: + return offset, thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err) +} + +func (p *EchoServiceEchoUnaryResult) FastReadField0(buf []byte) (int, error) { + offset := 0 + + tmp := NewEchoResponse() + if l, err := tmp.FastRead(buf[offset:]); err != nil { + return offset, err + } else { + offset += l + } + p.Success = tmp + return offset, nil +} + +// for compatibility +func (p *EchoServiceEchoUnaryResult) FastWrite(buf []byte) int { + return 0 +} + +func (p *EchoServiceEchoUnaryResult) FastWriteNocopy(buf []byte, binaryWriter bthrift.BinaryWriter) int { + offset := 0 + offset += bthrift.Binary.WriteStructBegin(buf[offset:], "EchoUnary_result") + if p != nil { + offset += p.fastWriteField0(buf[offset:], binaryWriter) + } + offset += bthrift.Binary.WriteFieldStop(buf[offset:]) + offset += bthrift.Binary.WriteStructEnd(buf[offset:]) + return offset +} + +func (p *EchoServiceEchoUnaryResult) BLength() int { + l := 0 + l += bthrift.Binary.StructBeginLength("EchoUnary_result") + if p != nil { + l += p.field0Length() + } + l += bthrift.Binary.FieldStopLength() + l += bthrift.Binary.StructEndLength() + return l +} + +func (p *EchoServiceEchoUnaryResult) fastWriteField0(buf []byte, binaryWriter bthrift.BinaryWriter) int { + offset := 0 + if p.IsSetSuccess() { + offset += bthrift.Binary.WriteFieldBegin(buf[offset:], "success", thrift.STRUCT, 0) + offset += p.Success.FastWriteNocopy(buf[offset:], binaryWriter) + offset += bthrift.Binary.WriteFieldEnd(buf[offset:]) + } + return offset +} + +func (p *EchoServiceEchoUnaryResult) field0Length() int { + l := 0 + if p.IsSetSuccess() { + l += bthrift.Binary.FieldBeginLength("success", thrift.STRUCT, 0) + l += p.Success.BLength() + l += bthrift.Binary.FieldEndLength() + } + return l +} + +func (p *EchoServiceEchoPingPongArgs) FastRead(buf []byte) (int, error) { + var err error + var offset int + var l int + var fieldTypeId thrift.TType + var fieldId int16 + _, l, err = bthrift.Binary.ReadStructBegin(buf) + offset += l + if err != nil { + goto ReadStructBeginError + } + + for { + _, fieldTypeId, fieldId, l, err = bthrift.Binary.ReadFieldBegin(buf[offset:]) + offset += l + if err != nil { + goto ReadFieldBeginError + } + if fieldTypeId == thrift.STOP { + break + } + switch fieldId { + case 1: + if fieldTypeId == thrift.STRUCT { + l, err = p.FastReadField1(buf[offset:]) + offset += l + if err != nil { + goto ReadFieldError + } + } else { + l, err = bthrift.Binary.Skip(buf[offset:], fieldTypeId) + offset += l + if err != nil { + goto SkipFieldError + } + } + case 2: + if fieldTypeId == thrift.STRUCT { + l, err = p.FastReadField2(buf[offset:]) + offset += l + if err != nil { + goto ReadFieldError + } + } else { + l, err = bthrift.Binary.Skip(buf[offset:], fieldTypeId) + offset += l + if err != nil { + goto SkipFieldError + } + } + default: + l, err = bthrift.Binary.Skip(buf[offset:], fieldTypeId) + offset += l + if err != nil { + goto SkipFieldError + } + } + + l, err = bthrift.Binary.ReadFieldEnd(buf[offset:]) + offset += l + if err != nil { + goto ReadFieldEndError + } + } + l, err = bthrift.Binary.ReadStructEnd(buf[offset:]) + offset += l + if err != nil { + goto ReadStructEndError + } + + return offset, nil +ReadStructBeginError: + return offset, thrift.PrependError(fmt.Sprintf("%T read struct begin error: ", p), err) +ReadFieldBeginError: + return offset, thrift.PrependError(fmt.Sprintf("%T read field %d begin error: ", p, fieldId), err) +ReadFieldError: + return offset, thrift.PrependError(fmt.Sprintf("%T read field %d '%s' error: ", p, fieldId, fieldIDToName_EchoServiceEchoPingPongArgs[fieldId]), err) +SkipFieldError: + return offset, thrift.PrependError(fmt.Sprintf("%T field %d skip type %d error: ", p, fieldId, fieldTypeId), err) +ReadFieldEndError: + return offset, thrift.PrependError(fmt.Sprintf("%T read field end error", p), err) +ReadStructEndError: + return offset, thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err) +} + +func (p *EchoServiceEchoPingPongArgs) FastReadField1(buf []byte) (int, error) { + offset := 0 + + tmp := NewEchoRequest() + if l, err := tmp.FastRead(buf[offset:]); err != nil { + return offset, err + } else { + offset += l + } + p.Req1 = tmp + return offset, nil +} + +func (p *EchoServiceEchoPingPongArgs) FastReadField2(buf []byte) (int, error) { + offset := 0 + + tmp := NewEchoRequest() + if l, err := tmp.FastRead(buf[offset:]); err != nil { + return offset, err + } else { + offset += l + } + p.Req2 = tmp + return offset, nil +} + +// for compatibility +func (p *EchoServiceEchoPingPongArgs) FastWrite(buf []byte) int { + return 0 +} + +func (p *EchoServiceEchoPingPongArgs) FastWriteNocopy(buf []byte, binaryWriter bthrift.BinaryWriter) int { + offset := 0 + offset += bthrift.Binary.WriteStructBegin(buf[offset:], "EchoPingPong_args") + if p != nil { + offset += p.fastWriteField1(buf[offset:], binaryWriter) + offset += p.fastWriteField2(buf[offset:], binaryWriter) + } + offset += bthrift.Binary.WriteFieldStop(buf[offset:]) + offset += bthrift.Binary.WriteStructEnd(buf[offset:]) + return offset +} + +func (p *EchoServiceEchoPingPongArgs) BLength() int { + l := 0 + l += bthrift.Binary.StructBeginLength("EchoPingPong_args") + if p != nil { + l += p.field1Length() + l += p.field2Length() + } + l += bthrift.Binary.FieldStopLength() + l += bthrift.Binary.StructEndLength() + return l +} + +func (p *EchoServiceEchoPingPongArgs) fastWriteField1(buf []byte, binaryWriter bthrift.BinaryWriter) int { + offset := 0 + offset += bthrift.Binary.WriteFieldBegin(buf[offset:], "req1", thrift.STRUCT, 1) + offset += p.Req1.FastWriteNocopy(buf[offset:], binaryWriter) + offset += bthrift.Binary.WriteFieldEnd(buf[offset:]) + return offset +} + +func (p *EchoServiceEchoPingPongArgs) fastWriteField2(buf []byte, binaryWriter bthrift.BinaryWriter) int { + offset := 0 + offset += bthrift.Binary.WriteFieldBegin(buf[offset:], "req2", thrift.STRUCT, 2) + offset += p.Req2.FastWriteNocopy(buf[offset:], binaryWriter) + offset += bthrift.Binary.WriteFieldEnd(buf[offset:]) + return offset +} + +func (p *EchoServiceEchoPingPongArgs) field1Length() int { + l := 0 + l += bthrift.Binary.FieldBeginLength("req1", thrift.STRUCT, 1) + l += p.Req1.BLength() + l += bthrift.Binary.FieldEndLength() + return l +} + +func (p *EchoServiceEchoPingPongArgs) field2Length() int { + l := 0 + l += bthrift.Binary.FieldBeginLength("req2", thrift.STRUCT, 2) + l += p.Req2.BLength() + l += bthrift.Binary.FieldEndLength() + return l +} + +func (p *EchoServiceEchoPingPongResult) FastRead(buf []byte) (int, error) { + var err error + var offset int + var l int + var fieldTypeId thrift.TType + var fieldId int16 + _, l, err = bthrift.Binary.ReadStructBegin(buf) + offset += l + if err != nil { + goto ReadStructBeginError + } + + for { + _, fieldTypeId, fieldId, l, err = bthrift.Binary.ReadFieldBegin(buf[offset:]) + offset += l + if err != nil { + goto ReadFieldBeginError + } + if fieldTypeId == thrift.STOP { + break + } + switch fieldId { + case 0: + if fieldTypeId == thrift.STRUCT { + l, err = p.FastReadField0(buf[offset:]) + offset += l + if err != nil { + goto ReadFieldError + } + } else { + l, err = bthrift.Binary.Skip(buf[offset:], fieldTypeId) + offset += l + if err != nil { + goto SkipFieldError + } + } + case 1: + if fieldTypeId == thrift.STRUCT { + l, err = p.FastReadField1(buf[offset:]) + offset += l + if err != nil { + goto ReadFieldError + } + } else { + l, err = bthrift.Binary.Skip(buf[offset:], fieldTypeId) + offset += l + if err != nil { + goto SkipFieldError + } + } + default: + l, err = bthrift.Binary.Skip(buf[offset:], fieldTypeId) + offset += l + if err != nil { + goto SkipFieldError + } + } + + l, err = bthrift.Binary.ReadFieldEnd(buf[offset:]) + offset += l + if err != nil { + goto ReadFieldEndError + } + } + l, err = bthrift.Binary.ReadStructEnd(buf[offset:]) + offset += l + if err != nil { + goto ReadStructEndError + } + + return offset, nil +ReadStructBeginError: + return offset, thrift.PrependError(fmt.Sprintf("%T read struct begin error: ", p), err) +ReadFieldBeginError: + return offset, thrift.PrependError(fmt.Sprintf("%T read field %d begin error: ", p, fieldId), err) +ReadFieldError: + return offset, thrift.PrependError(fmt.Sprintf("%T read field %d '%s' error: ", p, fieldId, fieldIDToName_EchoServiceEchoPingPongResult[fieldId]), err) +SkipFieldError: + return offset, thrift.PrependError(fmt.Sprintf("%T field %d skip type %d error: ", p, fieldId, fieldTypeId), err) +ReadFieldEndError: + return offset, thrift.PrependError(fmt.Sprintf("%T read field end error", p), err) +ReadStructEndError: + return offset, thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err) +} + +func (p *EchoServiceEchoPingPongResult) FastReadField0(buf []byte) (int, error) { + offset := 0 + + tmp := NewEchoResponse() + if l, err := tmp.FastRead(buf[offset:]); err != nil { + return offset, err + } else { + offset += l + } + p.Success = tmp + return offset, nil +} + +func (p *EchoServiceEchoPingPongResult) FastReadField1(buf []byte) (int, error) { + offset := 0 + + tmp := NewEchoException() + if l, err := tmp.FastRead(buf[offset:]); err != nil { + return offset, err + } else { + offset += l + } + p.E = tmp + return offset, nil +} + +// for compatibility +func (p *EchoServiceEchoPingPongResult) FastWrite(buf []byte) int { + return 0 +} + +func (p *EchoServiceEchoPingPongResult) FastWriteNocopy(buf []byte, binaryWriter bthrift.BinaryWriter) int { + offset := 0 + offset += bthrift.Binary.WriteStructBegin(buf[offset:], "EchoPingPong_result") + if p != nil { + offset += p.fastWriteField0(buf[offset:], binaryWriter) + offset += p.fastWriteField1(buf[offset:], binaryWriter) + } + offset += bthrift.Binary.WriteFieldStop(buf[offset:]) + offset += bthrift.Binary.WriteStructEnd(buf[offset:]) + return offset +} + +func (p *EchoServiceEchoPingPongResult) BLength() int { + l := 0 + l += bthrift.Binary.StructBeginLength("EchoPingPong_result") + if p != nil { + l += p.field0Length() + l += p.field1Length() + } + l += bthrift.Binary.FieldStopLength() + l += bthrift.Binary.StructEndLength() + return l +} + +func (p *EchoServiceEchoPingPongResult) fastWriteField0(buf []byte, binaryWriter bthrift.BinaryWriter) int { + offset := 0 + if p.IsSetSuccess() { + offset += bthrift.Binary.WriteFieldBegin(buf[offset:], "success", thrift.STRUCT, 0) + offset += p.Success.FastWriteNocopy(buf[offset:], binaryWriter) + offset += bthrift.Binary.WriteFieldEnd(buf[offset:]) + } + return offset +} + +func (p *EchoServiceEchoPingPongResult) fastWriteField1(buf []byte, binaryWriter bthrift.BinaryWriter) int { + offset := 0 + if p.IsSetE() { + offset += bthrift.Binary.WriteFieldBegin(buf[offset:], "e", thrift.STRUCT, 1) + offset += p.E.FastWriteNocopy(buf[offset:], binaryWriter) + offset += bthrift.Binary.WriteFieldEnd(buf[offset:]) + } + return offset +} + +func (p *EchoServiceEchoPingPongResult) field0Length() int { + l := 0 + if p.IsSetSuccess() { + l += bthrift.Binary.FieldBeginLength("success", thrift.STRUCT, 0) + l += p.Success.BLength() + l += bthrift.Binary.FieldEndLength() + } + return l +} + +func (p *EchoServiceEchoPingPongResult) field1Length() int { + l := 0 + if p.IsSetE() { + l += bthrift.Binary.FieldBeginLength("e", thrift.STRUCT, 1) + l += p.E.BLength() + l += bthrift.Binary.FieldEndLength() + } + return l +} + +func (p *EchoServiceEchoOnewayArgs) FastRead(buf []byte) (int, error) { + var err error + var offset int + var l int + var fieldTypeId thrift.TType + var fieldId int16 + _, l, err = bthrift.Binary.ReadStructBegin(buf) + offset += l + if err != nil { + goto ReadStructBeginError + } + + for { + _, fieldTypeId, fieldId, l, err = bthrift.Binary.ReadFieldBegin(buf[offset:]) + offset += l + if err != nil { + goto ReadFieldBeginError + } + if fieldTypeId == thrift.STOP { + break + } + switch fieldId { + case 1: + if fieldTypeId == thrift.STRUCT { + l, err = p.FastReadField1(buf[offset:]) + offset += l + if err != nil { + goto ReadFieldError + } + } else { + l, err = bthrift.Binary.Skip(buf[offset:], fieldTypeId) + offset += l + if err != nil { + goto SkipFieldError + } + } + default: + l, err = bthrift.Binary.Skip(buf[offset:], fieldTypeId) + offset += l + if err != nil { + goto SkipFieldError + } + } + + l, err = bthrift.Binary.ReadFieldEnd(buf[offset:]) + offset += l + if err != nil { + goto ReadFieldEndError + } + } + l, err = bthrift.Binary.ReadStructEnd(buf[offset:]) + offset += l + if err != nil { + goto ReadStructEndError + } + + return offset, nil +ReadStructBeginError: + return offset, thrift.PrependError(fmt.Sprintf("%T read struct begin error: ", p), err) +ReadFieldBeginError: + return offset, thrift.PrependError(fmt.Sprintf("%T read field %d begin error: ", p, fieldId), err) +ReadFieldError: + return offset, thrift.PrependError(fmt.Sprintf("%T read field %d '%s' error: ", p, fieldId, fieldIDToName_EchoServiceEchoOnewayArgs[fieldId]), err) +SkipFieldError: + return offset, thrift.PrependError(fmt.Sprintf("%T field %d skip type %d error: ", p, fieldId, fieldTypeId), err) +ReadFieldEndError: + return offset, thrift.PrependError(fmt.Sprintf("%T read field end error", p), err) +ReadStructEndError: + return offset, thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err) +} + +func (p *EchoServiceEchoOnewayArgs) FastReadField1(buf []byte) (int, error) { + offset := 0 + + tmp := NewEchoRequest() + if l, err := tmp.FastRead(buf[offset:]); err != nil { + return offset, err + } else { + offset += l + } + p.Req1 = tmp + return offset, nil +} + +// for compatibility +func (p *EchoServiceEchoOnewayArgs) FastWrite(buf []byte) int { + return 0 +} + +func (p *EchoServiceEchoOnewayArgs) FastWriteNocopy(buf []byte, binaryWriter bthrift.BinaryWriter) int { + offset := 0 + offset += bthrift.Binary.WriteStructBegin(buf[offset:], "EchoOneway_args") + if p != nil { + offset += p.fastWriteField1(buf[offset:], binaryWriter) + } + offset += bthrift.Binary.WriteFieldStop(buf[offset:]) + offset += bthrift.Binary.WriteStructEnd(buf[offset:]) + return offset +} + +func (p *EchoServiceEchoOnewayArgs) BLength() int { + l := 0 + l += bthrift.Binary.StructBeginLength("EchoOneway_args") + if p != nil { + l += p.field1Length() + } + l += bthrift.Binary.FieldStopLength() + l += bthrift.Binary.StructEndLength() + return l +} + +func (p *EchoServiceEchoOnewayArgs) fastWriteField1(buf []byte, binaryWriter bthrift.BinaryWriter) int { + offset := 0 + offset += bthrift.Binary.WriteFieldBegin(buf[offset:], "req1", thrift.STRUCT, 1) + offset += p.Req1.FastWriteNocopy(buf[offset:], binaryWriter) + offset += bthrift.Binary.WriteFieldEnd(buf[offset:]) + return offset +} + +func (p *EchoServiceEchoOnewayArgs) field1Length() int { + l := 0 + l += bthrift.Binary.FieldBeginLength("req1", thrift.STRUCT, 1) + l += p.Req1.BLength() + l += bthrift.Binary.FieldEndLength() + return l +} + +func (p *EchoServiceEchoOnewayResult) FastRead(buf []byte) (int, error) { + var err error + var offset int + var l int + var fieldTypeId thrift.TType + var fieldId int16 + _, l, err = bthrift.Binary.ReadStructBegin(buf) + offset += l + if err != nil { + goto ReadStructBeginError + } + + for { + _, fieldTypeId, fieldId, l, err = bthrift.Binary.ReadFieldBegin(buf[offset:]) + offset += l + if err != nil { + goto ReadFieldBeginError + } + if fieldTypeId == thrift.STOP { + break + } + l, err = bthrift.Binary.Skip(buf[offset:], fieldTypeId) + offset += l + if err != nil { + goto SkipFieldError + } + + l, err = bthrift.Binary.ReadFieldEnd(buf[offset:]) + offset += l + if err != nil { + goto ReadFieldEndError + } + } + l, err = bthrift.Binary.ReadStructEnd(buf[offset:]) + offset += l + if err != nil { + goto ReadStructEndError + } + + return offset, nil +ReadStructBeginError: + return offset, thrift.PrependError(fmt.Sprintf("%T read struct begin error: ", p), err) +ReadFieldBeginError: + return offset, thrift.PrependError(fmt.Sprintf("%T read field %d begin error: ", p, fieldId), err) +SkipFieldError: + return offset, thrift.PrependError(fmt.Sprintf("%T field %d skip type %d error: ", p, fieldId, fieldTypeId), err) +ReadFieldEndError: + return offset, thrift.PrependError(fmt.Sprintf("%T read field end error", p), err) +ReadStructEndError: + return offset, thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err) +} + +// for compatibility +func (p *EchoServiceEchoOnewayResult) FastWrite(buf []byte) int { + return 0 +} + +func (p *EchoServiceEchoOnewayResult) FastWriteNocopy(buf []byte, binaryWriter bthrift.BinaryWriter) int { + offset := 0 + offset += bthrift.Binary.WriteStructBegin(buf[offset:], "EchoOneway_result") + if p != nil { + } + offset += bthrift.Binary.WriteFieldStop(buf[offset:]) + offset += bthrift.Binary.WriteStructEnd(buf[offset:]) + return offset +} + +func (p *EchoServiceEchoOnewayResult) BLength() int { + l := 0 + l += bthrift.Binary.StructBeginLength("EchoOneway_result") + if p != nil { + } + l += bthrift.Binary.FieldStopLength() + l += bthrift.Binary.StructEndLength() + return l +} + +func (p *EchoServicePingArgs) FastRead(buf []byte) (int, error) { + var err error + var offset int + var l int + var fieldTypeId thrift.TType + var fieldId int16 + _, l, err = bthrift.Binary.ReadStructBegin(buf) + offset += l + if err != nil { + goto ReadStructBeginError + } + + for { + _, fieldTypeId, fieldId, l, err = bthrift.Binary.ReadFieldBegin(buf[offset:]) + offset += l + if err != nil { + goto ReadFieldBeginError + } + if fieldTypeId == thrift.STOP { + break + } + l, err = bthrift.Binary.Skip(buf[offset:], fieldTypeId) + offset += l + if err != nil { + goto SkipFieldError + } + + l, err = bthrift.Binary.ReadFieldEnd(buf[offset:]) + offset += l + if err != nil { + goto ReadFieldEndError + } + } + l, err = bthrift.Binary.ReadStructEnd(buf[offset:]) + offset += l + if err != nil { + goto ReadStructEndError + } + + return offset, nil +ReadStructBeginError: + return offset, thrift.PrependError(fmt.Sprintf("%T read struct begin error: ", p), err) +ReadFieldBeginError: + return offset, thrift.PrependError(fmt.Sprintf("%T read field %d begin error: ", p, fieldId), err) +SkipFieldError: + return offset, thrift.PrependError(fmt.Sprintf("%T field %d skip type %d error: ", p, fieldId, fieldTypeId), err) +ReadFieldEndError: + return offset, thrift.PrependError(fmt.Sprintf("%T read field end error", p), err) +ReadStructEndError: + return offset, thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err) +} + +// for compatibility +func (p *EchoServicePingArgs) FastWrite(buf []byte) int { + return 0 +} + +func (p *EchoServicePingArgs) FastWriteNocopy(buf []byte, binaryWriter bthrift.BinaryWriter) int { + offset := 0 + offset += bthrift.Binary.WriteStructBegin(buf[offset:], "Ping_args") + if p != nil { + } + offset += bthrift.Binary.WriteFieldStop(buf[offset:]) + offset += bthrift.Binary.WriteStructEnd(buf[offset:]) + return offset +} + +func (p *EchoServicePingArgs) BLength() int { + l := 0 + l += bthrift.Binary.StructBeginLength("Ping_args") + if p != nil { + } + l += bthrift.Binary.FieldStopLength() + l += bthrift.Binary.StructEndLength() + return l +} + +func (p *EchoServicePingResult) FastRead(buf []byte) (int, error) { + var err error + var offset int + var l int + var fieldTypeId thrift.TType + var fieldId int16 + _, l, err = bthrift.Binary.ReadStructBegin(buf) + offset += l + if err != nil { + goto ReadStructBeginError + } + + for { + _, fieldTypeId, fieldId, l, err = bthrift.Binary.ReadFieldBegin(buf[offset:]) + offset += l + if err != nil { + goto ReadFieldBeginError + } + if fieldTypeId == thrift.STOP { + break + } + l, err = bthrift.Binary.Skip(buf[offset:], fieldTypeId) + offset += l + if err != nil { + goto SkipFieldError + } + + l, err = bthrift.Binary.ReadFieldEnd(buf[offset:]) + offset += l + if err != nil { + goto ReadFieldEndError + } + } + l, err = bthrift.Binary.ReadStructEnd(buf[offset:]) + offset += l + if err != nil { + goto ReadStructEndError + } + + return offset, nil +ReadStructBeginError: + return offset, thrift.PrependError(fmt.Sprintf("%T read struct begin error: ", p), err) +ReadFieldBeginError: + return offset, thrift.PrependError(fmt.Sprintf("%T read field %d begin error: ", p, fieldId), err) +SkipFieldError: + return offset, thrift.PrependError(fmt.Sprintf("%T field %d skip type %d error: ", p, fieldId, fieldTypeId), err) +ReadFieldEndError: + return offset, thrift.PrependError(fmt.Sprintf("%T read field end error", p), err) +ReadStructEndError: + return offset, thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err) +} + +// for compatibility +func (p *EchoServicePingResult) FastWrite(buf []byte) int { + return 0 +} + +func (p *EchoServicePingResult) FastWriteNocopy(buf []byte, binaryWriter bthrift.BinaryWriter) int { + offset := 0 + offset += bthrift.Binary.WriteStructBegin(buf[offset:], "Ping_result") + if p != nil { + } + offset += bthrift.Binary.WriteFieldStop(buf[offset:]) + offset += bthrift.Binary.WriteStructEnd(buf[offset:]) + return offset +} + +func (p *EchoServicePingResult) BLength() int { + l := 0 + l += bthrift.Binary.StructBeginLength("Ping_result") + if p != nil { + } + l += bthrift.Binary.FieldStopLength() + l += bthrift.Binary.StructEndLength() + return l +} + +func (p *EchoServiceEchoBidirectionalArgs) GetFirstArgument() interface{} { + return p.Req1 +} + +func (p *EchoServiceEchoBidirectionalResult) GetResult() interface{} { + return p.Success +} + +func (p *EchoServiceEchoClientArgs) GetFirstArgument() interface{} { + return p.Req1 +} + +func (p *EchoServiceEchoClientResult) GetResult() interface{} { + return p.Success +} + +func (p *EchoServiceEchoServerArgs) GetFirstArgument() interface{} { + return p.Req1 +} + +func (p *EchoServiceEchoServerResult) GetResult() interface{} { + return p.Success +} + +func (p *EchoServiceEchoUnaryArgs) GetFirstArgument() interface{} { + return p.Req1 +} + +func (p *EchoServiceEchoUnaryResult) GetResult() interface{} { + return p.Success +} + +func (p *EchoServiceEchoPingPongArgs) GetFirstArgument() interface{} { + return p.Req1 +} + +func (p *EchoServiceEchoPingPongResult) GetResult() interface{} { + return p.Success +} + +func (p *EchoServiceEchoOnewayArgs) GetFirstArgument() interface{} { + return p.Req1 +} + +func (p *EchoServiceEchoOnewayResult) GetResult() interface{} { + return nil +} + +func (p *EchoServicePingArgs) GetFirstArgument() interface{} { + return nil +} + +func (p *EchoServicePingResult) GetResult() interface{} { + return nil +} diff --git a/thrift_streaming/kitex_gen/echo/k-consts.go b/thrift_streaming/kitex_gen/echo/k-consts.go new file mode 100644 index 0000000..cf25014 --- /dev/null +++ b/thrift_streaming/kitex_gen/echo/k-consts.go @@ -0,0 +1,4 @@ +package echo + +// KitexUnusedProtection is used to prevent 'imported and not used' error. +var KitexUnusedProtection = struct{}{} diff --git a/thrift_streaming/kitex_gen/grpc_pb/api.pb.fast.go b/thrift_streaming/kitex_gen/grpc_pb/api.pb.fast.go new file mode 100644 index 0000000..191a376 --- /dev/null +++ b/thrift_streaming/kitex_gen/grpc_pb/api.pb.fast.go @@ -0,0 +1,135 @@ +// Code generated by Fastpb v0.0.2. DO NOT EDIT. + +package grpc_pb + +import ( + fmt "fmt" + fastpb "github.com/cloudwego/fastpb" +) + +var ( + _ = fmt.Errorf + _ = fastpb.Skip +) + +func (x *Request) FastRead(buf []byte, _type int8, number int32) (offset int, err error) { + switch number { + case 1: + offset, err = x.fastReadField1(buf, _type) + if err != nil { + goto ReadFieldError + } + default: + offset, err = fastpb.Skip(buf, _type, number) + if err != nil { + goto SkipFieldError + } + } + return offset, nil +SkipFieldError: + return offset, fmt.Errorf("%T cannot parse invalid wire-format data, error: %s", x, err) +ReadFieldError: + return offset, fmt.Errorf("%T read field %d '%s' error: %s", x, number, fieldIDToName_Request[number], err) +} + +func (x *Request) fastReadField1(buf []byte, _type int8) (offset int, err error) { + x.Message, offset, err = fastpb.ReadString(buf, _type) + return offset, err +} + +func (x *Response) FastRead(buf []byte, _type int8, number int32) (offset int, err error) { + switch number { + case 1: + offset, err = x.fastReadField1(buf, _type) + if err != nil { + goto ReadFieldError + } + default: + offset, err = fastpb.Skip(buf, _type, number) + if err != nil { + goto SkipFieldError + } + } + return offset, nil +SkipFieldError: + return offset, fmt.Errorf("%T cannot parse invalid wire-format data, error: %s", x, err) +ReadFieldError: + return offset, fmt.Errorf("%T read field %d '%s' error: %s", x, number, fieldIDToName_Response[number], err) +} + +func (x *Response) fastReadField1(buf []byte, _type int8) (offset int, err error) { + x.Message, offset, err = fastpb.ReadString(buf, _type) + return offset, err +} + +func (x *Request) FastWrite(buf []byte) (offset int) { + if x == nil { + return offset + } + offset += x.fastWriteField1(buf[offset:]) + return offset +} + +func (x *Request) fastWriteField1(buf []byte) (offset int) { + if x.Message == "" { + return offset + } + offset += fastpb.WriteString(buf[offset:], 1, x.GetMessage()) + return offset +} + +func (x *Response) FastWrite(buf []byte) (offset int) { + if x == nil { + return offset + } + offset += x.fastWriteField1(buf[offset:]) + return offset +} + +func (x *Response) fastWriteField1(buf []byte) (offset int) { + if x.Message == "" { + return offset + } + offset += fastpb.WriteString(buf[offset:], 1, x.GetMessage()) + return offset +} + +func (x *Request) Size() (n int) { + if x == nil { + return n + } + n += x.sizeField1() + return n +} + +func (x *Request) sizeField1() (n int) { + if x.Message == "" { + return n + } + n += fastpb.SizeString(1, x.GetMessage()) + return n +} + +func (x *Response) Size() (n int) { + if x == nil { + return n + } + n += x.sizeField1() + return n +} + +func (x *Response) sizeField1() (n int) { + if x.Message == "" { + return n + } + n += fastpb.SizeString(1, x.GetMessage()) + return n +} + +var fieldIDToName_Request = map[int32]string{ + 1: "Message", +} + +var fieldIDToName_Response = map[int32]string{ + 1: "Message", +} diff --git a/thrift_streaming/kitex_gen/grpc_pb/api.pb.go b/thrift_streaming/kitex_gen/grpc_pb/api.pb.go new file mode 100644 index 0000000..2647dbd --- /dev/null +++ b/thrift_streaming/kitex_gen/grpc_pb/api.pb.go @@ -0,0 +1,260 @@ +// Code generated by protoc-gen-go. DO NOT EDIT. +// versions: +// protoc-gen-go v1.28.1 +// protoc v3.21.12 +// source: idl/api.proto + +package grpc_pb + +import ( + context "context" + streaming "github.com/cloudwego/kitex/pkg/streaming" + 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 + + Message string `protobuf:"bytes,1,opt,name=message,proto3" json:"message,omitempty"` +} + +func (x *Request) Reset() { + *x = Request{} + if protoimpl.UnsafeEnabled { + mi := &file_idl_api_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_idl_api_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_idl_api_proto_rawDescGZIP(), []int{0} +} + +func (x *Request) GetMessage() string { + if x != nil { + return x.Message + } + return "" +} + +type Response struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Message string `protobuf:"bytes,1,opt,name=message,proto3" json:"message,omitempty"` +} + +func (x *Response) Reset() { + *x = Response{} + if protoimpl.UnsafeEnabled { + mi := &file_idl_api_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_idl_api_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_idl_api_proto_rawDescGZIP(), []int{1} +} + +func (x *Response) GetMessage() string { + if x != nil { + return x.Message + } + return "" +} + +var File_idl_api_proto protoreflect.FileDescriptor + +var file_idl_api_proto_rawDesc = []byte{ + 0x0a, 0x0d, 0x69, 0x64, 0x6c, 0x2f, 0x61, 0x70, 0x69, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, + 0x07, 0x67, 0x72, 0x70, 0x63, 0x5f, 0x70, 0x62, 0x22, 0x23, 0x0a, 0x07, 0x52, 0x65, 0x71, 0x75, + 0x65, 0x73, 0x74, 0x12, 0x18, 0x0a, 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x18, 0x01, + 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x22, 0x24, 0x0a, + 0x08, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x18, 0x0a, 0x07, 0x6d, 0x65, 0x73, + 0x73, 0x61, 0x67, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x6d, 0x65, 0x73, 0x73, + 0x61, 0x67, 0x65, 0x32, 0xe3, 0x01, 0x0a, 0x09, 0x50, 0x42, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, + 0x65, 0x12, 0x31, 0x0a, 0x04, 0x45, 0x63, 0x68, 0x6f, 0x12, 0x10, 0x2e, 0x67, 0x72, 0x70, 0x63, + 0x5f, 0x70, 0x62, 0x2e, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x11, 0x2e, 0x67, 0x72, + 0x70, 0x63, 0x5f, 0x70, 0x62, 0x2e, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, + 0x28, 0x01, 0x30, 0x01, 0x12, 0x35, 0x0a, 0x0a, 0x45, 0x63, 0x68, 0x6f, 0x43, 0x6c, 0x69, 0x65, + 0x6e, 0x74, 0x12, 0x10, 0x2e, 0x67, 0x72, 0x70, 0x63, 0x5f, 0x70, 0x62, 0x2e, 0x52, 0x65, 0x71, + 0x75, 0x65, 0x73, 0x74, 0x1a, 0x11, 0x2e, 0x67, 0x72, 0x70, 0x63, 0x5f, 0x70, 0x62, 0x2e, 0x52, + 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x28, 0x01, 0x12, 0x35, 0x0a, 0x0a, 0x45, + 0x63, 0x68, 0x6f, 0x53, 0x65, 0x72, 0x76, 0x65, 0x72, 0x12, 0x10, 0x2e, 0x67, 0x72, 0x70, 0x63, + 0x5f, 0x70, 0x62, 0x2e, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x11, 0x2e, 0x67, 0x72, + 0x70, 0x63, 0x5f, 0x70, 0x62, 0x2e, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, + 0x30, 0x01, 0x12, 0x35, 0x0a, 0x0c, 0x45, 0x63, 0x68, 0x6f, 0x50, 0x69, 0x6e, 0x67, 0x50, 0x6f, + 0x6e, 0x67, 0x12, 0x10, 0x2e, 0x67, 0x72, 0x70, 0x63, 0x5f, 0x70, 0x62, 0x2e, 0x52, 0x65, 0x71, + 0x75, 0x65, 0x73, 0x74, 0x1a, 0x11, 0x2e, 0x67, 0x72, 0x70, 0x63, 0x5f, 0x70, 0x62, 0x2e, 0x52, + 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x42, 0x45, 0x5a, 0x43, 0x67, 0x69, 0x74, + 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x63, 0x6c, 0x6f, 0x75, 0x64, 0x77, 0x65, 0x67, + 0x6f, 0x2f, 0x6b, 0x69, 0x74, 0x65, 0x78, 0x2d, 0x74, 0x65, 0x73, 0x74, 0x73, 0x2f, 0x74, 0x68, + 0x72, 0x69, 0x66, 0x74, 0x5f, 0x73, 0x74, 0x72, 0x65, 0x61, 0x6d, 0x69, 0x6e, 0x67, 0x2f, 0x6b, + 0x69, 0x74, 0x65, 0x78, 0x5f, 0x67, 0x65, 0x6e, 0x2f, 0x67, 0x72, 0x70, 0x63, 0x5f, 0x70, 0x62, + 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, +} + +var ( + file_idl_api_proto_rawDescOnce sync.Once + file_idl_api_proto_rawDescData = file_idl_api_proto_rawDesc +) + +func file_idl_api_proto_rawDescGZIP() []byte { + file_idl_api_proto_rawDescOnce.Do(func() { + file_idl_api_proto_rawDescData = protoimpl.X.CompressGZIP(file_idl_api_proto_rawDescData) + }) + return file_idl_api_proto_rawDescData +} + +var file_idl_api_proto_msgTypes = make([]protoimpl.MessageInfo, 2) +var file_idl_api_proto_goTypes = []interface{}{ + (*Request)(nil), // 0: grpc_pb.Request + (*Response)(nil), // 1: grpc_pb.Response +} +var file_idl_api_proto_depIdxs = []int32{ + 0, // 0: grpc_pb.PBService.Echo:input_type -> grpc_pb.Request + 0, // 1: grpc_pb.PBService.EchoClient:input_type -> grpc_pb.Request + 0, // 2: grpc_pb.PBService.EchoServer:input_type -> grpc_pb.Request + 0, // 3: grpc_pb.PBService.EchoPingPong:input_type -> grpc_pb.Request + 1, // 4: grpc_pb.PBService.Echo:output_type -> grpc_pb.Response + 1, // 5: grpc_pb.PBService.EchoClient:output_type -> grpc_pb.Response + 1, // 6: grpc_pb.PBService.EchoServer:output_type -> grpc_pb.Response + 1, // 7: grpc_pb.PBService.EchoPingPong:output_type -> grpc_pb.Response + 4, // [4:8] is the sub-list for method output_type + 0, // [0:4] 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_idl_api_proto_init() } +func file_idl_api_proto_init() { + if File_idl_api_proto != nil { + return + } + if !protoimpl.UnsafeEnabled { + file_idl_api_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_idl_api_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 + } + } + } + type x struct{} + out := protoimpl.TypeBuilder{ + File: protoimpl.DescBuilder{ + GoPackagePath: reflect.TypeOf(x{}).PkgPath(), + RawDescriptor: file_idl_api_proto_rawDesc, + NumEnums: 0, + NumMessages: 2, + NumExtensions: 0, + NumServices: 1, + }, + GoTypes: file_idl_api_proto_goTypes, + DependencyIndexes: file_idl_api_proto_depIdxs, + MessageInfos: file_idl_api_proto_msgTypes, + }.Build() + File_idl_api_proto = out.File + file_idl_api_proto_rawDesc = nil + file_idl_api_proto_goTypes = nil + file_idl_api_proto_depIdxs = nil +} + +var _ context.Context + +// Code generated by Kitex v0.8.0. DO NOT EDIT. + +type PBService interface { + Echo(stream PBService_EchoServer) (err error) + EchoClient(stream PBService_EchoClientServer) (err error) + EchoServer(req *Request, stream PBService_EchoServerServer) (err error) + EchoPingPong(ctx context.Context, req *Request) (res *Response, err error) +} + +type PBService_EchoServer interface { + streaming.Stream + Recv() (*Request, error) + Send(*Response) error +} + +type PBService_EchoClientServer interface { + streaming.Stream + Recv() (*Request, error) + SendAndClose(*Response) error +} + +type PBService_EchoServerServer interface { + streaming.Stream + Send(*Response) error +} diff --git a/thrift_streaming/kitex_gen/grpc_pb/pbservice/client.go b/thrift_streaming/kitex_gen/grpc_pb/pbservice/client.go new file mode 100644 index 0000000..6d93321 --- /dev/null +++ b/thrift_streaming/kitex_gen/grpc_pb/pbservice/client.go @@ -0,0 +1,142 @@ +// Code generated by Kitex v0.8.0. DO NOT EDIT. + +package pbservice + +import ( + "context" + grpc_pb "github.com/cloudwego/kitex-tests/thrift_streaming/kitex_gen/grpc_pb" + client "github.com/cloudwego/kitex/client" + callopt "github.com/cloudwego/kitex/client/callopt" + streaming "github.com/cloudwego/kitex/pkg/streaming" + transport "github.com/cloudwego/kitex/transport" + "github.com/cloudwego/kitex/client/streamclient" + "github.com/cloudwego/kitex/client/callopt/streamcall" +) + +// Client is designed to provide IDL-compatible methods with call-option parameter for kitex framework. +type Client interface { + Echo(ctx context.Context, callOptions ...callopt.Option) (stream PBService_EchoClient, err error) + EchoClient(ctx context.Context, callOptions ...callopt.Option) (stream PBService_EchoClientClient, err error) + EchoServer(ctx context.Context, Req *grpc_pb.Request, callOptions ...callopt.Option) (stream PBService_EchoServerClient, err error) + EchoPingPong(ctx context.Context, Req *grpc_pb.Request, callOptions ...callopt.Option) (r *grpc_pb.Response, err error) +} + +// StreamClient is designed to provide Interface for Streaming APIs. +type StreamClient interface { + Echo(ctx context.Context, callOptions ...streamcall.Option) (stream PBService_EchoClient, err error) + EchoClient(ctx context.Context, callOptions ...streamcall.Option) (stream PBService_EchoClientClient, err error) + EchoServer(ctx context.Context, Req *grpc_pb.Request, callOptions ...streamcall.Option) (stream PBService_EchoServerClient, err error) +} + +type PBService_EchoClient interface { + streaming.Stream + Send(*grpc_pb.Request) error + Recv() (*grpc_pb.Response, error) +} + +type PBService_EchoClientClient interface { + streaming.Stream + Send(*grpc_pb.Request) error + CloseAndRecv() (*grpc_pb.Response, error) +} + +type PBService_EchoServerClient interface { + streaming.Stream + Recv() (*grpc_pb.Response, error) +} + +// NewClient creates a client for the service defined in IDL. +func NewClient(destService string, opts ...client.Option) (Client, error) { + var options []client.Option + options = append(options, client.WithDestService(destService)) + + options = append(options, client.WithTransportProtocol(transport.GRPC)) + + options = append(options, opts...) + + kc, err := client.NewClient(serviceInfo(), options...) + if err != nil { + return nil, err + } + return &kPBServiceClient{ + kClient: newServiceClient(kc), + }, nil +} + +// MustNewClient creates a client for the service defined in IDL. It panics if any error occurs. +func MustNewClient(destService string, opts ...client.Option) Client { + kc, err := NewClient(destService, opts...) + if err != nil { + panic(err) + } + return kc +} + +type kPBServiceClient struct { + *kClient +} + +func (p *kPBServiceClient) Echo(ctx context.Context, callOptions ...callopt.Option) (stream PBService_EchoClient, err error) { + ctx = client.NewCtxWithCallOptions(ctx, callOptions) + return p.kClient.Echo(ctx) +} + +func (p *kPBServiceClient) EchoClient(ctx context.Context, callOptions ...callopt.Option) (stream PBService_EchoClientClient, err error) { + ctx = client.NewCtxWithCallOptions(ctx, callOptions) + return p.kClient.EchoClient(ctx) +} + +func (p *kPBServiceClient) EchoServer(ctx context.Context, Req *grpc_pb.Request, callOptions ...callopt.Option) (stream PBService_EchoServerClient, err error) { + ctx = client.NewCtxWithCallOptions(ctx, callOptions) + return p.kClient.EchoServer(ctx, Req) +} + +func (p *kPBServiceClient) EchoPingPong(ctx context.Context, Req *grpc_pb.Request, callOptions ...callopt.Option) (r *grpc_pb.Response, err error) { + ctx = client.NewCtxWithCallOptions(ctx, callOptions) + return p.kClient.EchoPingPong(ctx, Req) +} + +// NewStreamClient creates a stream client for the service's streaming APIs defined in IDL. +func NewStreamClient(destService string, opts ...streamclient.Option) (StreamClient, error) { + var options []client.Option + options = append(options, client.WithDestService(destService)) + options = append(options, client.WithTransportProtocol(transport.GRPC)) + options = append(options, streamclient.GetClientOptions(opts)...) + + kc, err := client.NewClient(serviceInfoForStreamClient(), options...) + if err != nil { + return nil, err + } + return &kPBServiceStreamClient{ + kClient: newServiceClient(kc), + }, nil +} + +// MustNewStreamClient creates a stream client for the service's streaming APIs defined in IDL. +// It panics if any error occurs. +func MustNewStreamClient(destService string, opts ...streamclient.Option) StreamClient { + kc, err := NewStreamClient(destService, opts...) + if err != nil { + panic(err) + } + return kc +} + +type kPBServiceStreamClient struct { + *kClient +} + +func (p *kPBServiceStreamClient) Echo(ctx context.Context, callOptions ...streamcall.Option) (stream PBService_EchoClient, err error) { + ctx = client.NewCtxWithCallOptions(ctx, streamcall.GetCallOptions(callOptions)) + return p.kClient.Echo(ctx) +} + +func (p *kPBServiceStreamClient) EchoClient(ctx context.Context, callOptions ...streamcall.Option) (stream PBService_EchoClientClient, err error) { + ctx = client.NewCtxWithCallOptions(ctx, streamcall.GetCallOptions(callOptions)) + return p.kClient.EchoClient(ctx) +} + +func (p *kPBServiceStreamClient) EchoServer(ctx context.Context, Req *grpc_pb.Request, callOptions ...streamcall.Option) (stream PBService_EchoServerClient, err error) { + ctx = client.NewCtxWithCallOptions(ctx, streamcall.GetCallOptions(callOptions)) + return p.kClient.EchoServer(ctx, Req) +} diff --git a/thrift_streaming/kitex_gen/grpc_pb/pbservice/invoker.go b/thrift_streaming/kitex_gen/grpc_pb/pbservice/invoker.go new file mode 100644 index 0000000..d35eb3f --- /dev/null +++ b/thrift_streaming/kitex_gen/grpc_pb/pbservice/invoker.go @@ -0,0 +1,24 @@ +// Code generated by Kitex v0.8.0. DO NOT EDIT. + +package pbservice + +import ( + grpc_pb "github.com/cloudwego/kitex-tests/thrift_streaming/kitex_gen/grpc_pb" + server "github.com/cloudwego/kitex/server" +) + +// NewInvoker creates a server.Invoker with the given handler and options. +func NewInvoker(handler grpc_pb.PBService, opts ...server.Option) server.Invoker { + var options []server.Option + + options = append(options, opts...) + + s := server.NewInvoker(options...) + if err := s.RegisterService(serviceInfo(), handler); err != nil { + panic(err) + } + if err := s.Init(); err != nil { + panic(err) + } + return s +} diff --git a/thrift_streaming/kitex_gen/grpc_pb/pbservice/pbservice.go b/thrift_streaming/kitex_gen/grpc_pb/pbservice/pbservice.go new file mode 100644 index 0000000..3b8c52e --- /dev/null +++ b/thrift_streaming/kitex_gen/grpc_pb/pbservice/pbservice.go @@ -0,0 +1,811 @@ +// Code generated by Kitex v0.8.0. DO NOT EDIT. + +package pbservice + +import ( + "context" + "errors" + "fmt" + grpc_pb "github.com/cloudwego/kitex-tests/thrift_streaming/kitex_gen/grpc_pb" + client "github.com/cloudwego/kitex/client" + kitex "github.com/cloudwego/kitex/pkg/serviceinfo" + streaming "github.com/cloudwego/kitex/pkg/streaming" + proto "google.golang.org/protobuf/proto" +) + +var errInvalidMessageType = errors.New("invalid message type for service method handler") + +var _ = streaming.KitexUnusedProtection + +var serviceMethods = map[string]kitex.MethodInfo{ + "Echo": kitex.NewMethodInfo( + echoHandler, + newEchoArgs, + newEchoResult, + false, + kitex.WithStreamingMode(kitex.StreamingBidirectional), + ), + "EchoClient": kitex.NewMethodInfo( + echoClientHandler, + newEchoClientArgs, + newEchoClientResult, + false, + kitex.WithStreamingMode(kitex.StreamingClient), + ), + "EchoServer": kitex.NewMethodInfo( + echoServerHandler, + newEchoServerArgs, + newEchoServerResult, + false, + kitex.WithStreamingMode(kitex.StreamingServer), + ), + "EchoPingPong": kitex.NewMethodInfo( + echoPingPongHandler, + newEchoPingPongArgs, + newEchoPingPongResult, + false, + kitex.WithStreamingMode(kitex.StreamingUnary), + ), +} + +var ( + pBServiceServiceInfo = NewServiceInfo() + pBServiceServiceInfoForClient = NewServiceInfoForClient() + pBServiceServiceInfoForStreamClient = NewServiceInfoForStreamClient() +) + +// for server +func serviceInfo() *kitex.ServiceInfo { + return pBServiceServiceInfo +} + +// for client +func serviceInfoForStreamClient() *kitex.ServiceInfo { + return pBServiceServiceInfoForStreamClient +} + +// for stream client +func serviceInfoForClient() *kitex.ServiceInfo { + return pBServiceServiceInfoForClient +} + +// NewServiceInfo creates a new ServiceInfo containing all methods +func NewServiceInfo() *kitex.ServiceInfo { + return newServiceInfo(true, true, true) +} + +// NewServiceInfo creates a new ServiceInfo containing non-streaming methods +func NewServiceInfoForClient() *kitex.ServiceInfo { + return newServiceInfo(false, false, true) +} +func NewServiceInfoForStreamClient() *kitex.ServiceInfo { + return newServiceInfo(true, true, false) +} + +func newServiceInfo(hasStreaming bool, keepStreamingMethods bool, keepNonStreamingMethods bool) *kitex.ServiceInfo { + serviceName := "PBService" + handlerType := (*grpc_pb.PBService)(nil) + methods := map[string]kitex.MethodInfo{} + for name, m := range serviceMethods { + if m.IsStreaming() && !keepStreamingMethods { + continue + } + if !m.IsStreaming() && !keepNonStreamingMethods { + continue + } + methods[name] = m + } + extra := map[string]interface{}{ + "PackageName": "grpc_pb", + } + if hasStreaming { + extra["streaming"] = hasStreaming + } + svcInfo := &kitex.ServiceInfo{ + ServiceName: serviceName, + HandlerType: handlerType, + Methods: methods, + PayloadCodec: kitex.Protobuf, + KiteXGenVersion: "v0.8.0", + Extra: extra, + } + return svcInfo +} + +func echoHandler(ctx context.Context, handler interface{}, arg, result interface{}) error { + st := arg.(*streaming.Args).Stream + stream := &pBServiceEchoServer{st} + return handler.(grpc_pb.PBService).Echo(stream) +} + +type pBServiceEchoClient struct { + streaming.Stream +} + +func (x *pBServiceEchoClient) Send(m *grpc_pb.Request) error { + return x.Stream.SendMsg(m) +} +func (x *pBServiceEchoClient) Recv() (*grpc_pb.Response, error) { + m := new(grpc_pb.Response) + return m, x.Stream.RecvMsg(m) +} + +type pBServiceEchoServer struct { + streaming.Stream +} + +func (x *pBServiceEchoServer) Send(m *grpc_pb.Response) error { + return x.Stream.SendMsg(m) +} + +func (x *pBServiceEchoServer) Recv() (*grpc_pb.Request, error) { + m := new(grpc_pb.Request) + return m, x.Stream.RecvMsg(m) +} + +func newEchoArgs() interface{} { + return &EchoArgs{} +} + +func newEchoResult() interface{} { + return &EchoResult{} +} + +type EchoArgs struct { + Req *grpc_pb.Request +} + +func (p *EchoArgs) FastRead(buf []byte, _type int8, number int32) (n int, err error) { + if !p.IsSetReq() { + p.Req = new(grpc_pb.Request) + } + return p.Req.FastRead(buf, _type, number) +} + +func (p *EchoArgs) FastWrite(buf []byte) (n int) { + if !p.IsSetReq() { + return 0 + } + return p.Req.FastWrite(buf) +} + +func (p *EchoArgs) Size() (n int) { + if !p.IsSetReq() { + return 0 + } + return p.Req.Size() +} + +func (p *EchoArgs) Marshal(out []byte) ([]byte, error) { + if !p.IsSetReq() { + return out, nil + } + return proto.Marshal(p.Req) +} + +func (p *EchoArgs) Unmarshal(in []byte) error { + msg := new(grpc_pb.Request) + if err := proto.Unmarshal(in, msg); err != nil { + return err + } + p.Req = msg + return nil +} + +var EchoArgs_Req_DEFAULT *grpc_pb.Request + +func (p *EchoArgs) GetReq() *grpc_pb.Request { + if !p.IsSetReq() { + return EchoArgs_Req_DEFAULT + } + return p.Req +} + +func (p *EchoArgs) IsSetReq() bool { + return p.Req != nil +} + +func (p *EchoArgs) GetFirstArgument() interface{} { + return p.Req +} + +type EchoResult struct { + Success *grpc_pb.Response +} + +var EchoResult_Success_DEFAULT *grpc_pb.Response + +func (p *EchoResult) FastRead(buf []byte, _type int8, number int32) (n int, err error) { + if !p.IsSetSuccess() { + p.Success = new(grpc_pb.Response) + } + return p.Success.FastRead(buf, _type, number) +} + +func (p *EchoResult) FastWrite(buf []byte) (n int) { + if !p.IsSetSuccess() { + return 0 + } + return p.Success.FastWrite(buf) +} + +func (p *EchoResult) Size() (n int) { + if !p.IsSetSuccess() { + return 0 + } + return p.Success.Size() +} + +func (p *EchoResult) Marshal(out []byte) ([]byte, error) { + if !p.IsSetSuccess() { + return out, nil + } + return proto.Marshal(p.Success) +} + +func (p *EchoResult) Unmarshal(in []byte) error { + msg := new(grpc_pb.Response) + if err := proto.Unmarshal(in, msg); err != nil { + return err + } + p.Success = msg + return nil +} + +func (p *EchoResult) GetSuccess() *grpc_pb.Response { + if !p.IsSetSuccess() { + return EchoResult_Success_DEFAULT + } + return p.Success +} + +func (p *EchoResult) SetSuccess(x interface{}) { + p.Success = x.(*grpc_pb.Response) +} + +func (p *EchoResult) IsSetSuccess() bool { + return p.Success != nil +} + +func (p *EchoResult) GetResult() interface{} { + return p.Success +} + +func echoClientHandler(ctx context.Context, handler interface{}, arg, result interface{}) error { + st := arg.(*streaming.Args).Stream + stream := &pBServiceEchoClientServer{st} + return handler.(grpc_pb.PBService).EchoClient(stream) +} + +type pBServiceEchoClientClient struct { + streaming.Stream +} + +func (x *pBServiceEchoClientClient) Send(m *grpc_pb.Request) error { + return x.Stream.SendMsg(m) +} +func (x *pBServiceEchoClientClient) CloseAndRecv() (*grpc_pb.Response, error) { + if err := x.Stream.Close(); err != nil { + return nil, err + } + m := new(grpc_pb.Response) + return m, x.Stream.RecvMsg(m) +} + +type pBServiceEchoClientServer struct { + streaming.Stream +} + +func (x *pBServiceEchoClientServer) SendAndClose(m *grpc_pb.Response) error { + return x.Stream.SendMsg(m) +} + +func (x *pBServiceEchoClientServer) Recv() (*grpc_pb.Request, error) { + m := new(grpc_pb.Request) + return m, x.Stream.RecvMsg(m) +} + +func newEchoClientArgs() interface{} { + return &EchoClientArgs{} +} + +func newEchoClientResult() interface{} { + return &EchoClientResult{} +} + +type EchoClientArgs struct { + Req *grpc_pb.Request +} + +func (p *EchoClientArgs) FastRead(buf []byte, _type int8, number int32) (n int, err error) { + if !p.IsSetReq() { + p.Req = new(grpc_pb.Request) + } + return p.Req.FastRead(buf, _type, number) +} + +func (p *EchoClientArgs) FastWrite(buf []byte) (n int) { + if !p.IsSetReq() { + return 0 + } + return p.Req.FastWrite(buf) +} + +func (p *EchoClientArgs) Size() (n int) { + if !p.IsSetReq() { + return 0 + } + return p.Req.Size() +} + +func (p *EchoClientArgs) Marshal(out []byte) ([]byte, error) { + if !p.IsSetReq() { + return out, nil + } + return proto.Marshal(p.Req) +} + +func (p *EchoClientArgs) Unmarshal(in []byte) error { + msg := new(grpc_pb.Request) + if err := proto.Unmarshal(in, msg); err != nil { + return err + } + p.Req = msg + return nil +} + +var EchoClientArgs_Req_DEFAULT *grpc_pb.Request + +func (p *EchoClientArgs) GetReq() *grpc_pb.Request { + if !p.IsSetReq() { + return EchoClientArgs_Req_DEFAULT + } + return p.Req +} + +func (p *EchoClientArgs) IsSetReq() bool { + return p.Req != nil +} + +func (p *EchoClientArgs) GetFirstArgument() interface{} { + return p.Req +} + +type EchoClientResult struct { + Success *grpc_pb.Response +} + +var EchoClientResult_Success_DEFAULT *grpc_pb.Response + +func (p *EchoClientResult) FastRead(buf []byte, _type int8, number int32) (n int, err error) { + if !p.IsSetSuccess() { + p.Success = new(grpc_pb.Response) + } + return p.Success.FastRead(buf, _type, number) +} + +func (p *EchoClientResult) FastWrite(buf []byte) (n int) { + if !p.IsSetSuccess() { + return 0 + } + return p.Success.FastWrite(buf) +} + +func (p *EchoClientResult) Size() (n int) { + if !p.IsSetSuccess() { + return 0 + } + return p.Success.Size() +} + +func (p *EchoClientResult) Marshal(out []byte) ([]byte, error) { + if !p.IsSetSuccess() { + return out, nil + } + return proto.Marshal(p.Success) +} + +func (p *EchoClientResult) Unmarshal(in []byte) error { + msg := new(grpc_pb.Response) + if err := proto.Unmarshal(in, msg); err != nil { + return err + } + p.Success = msg + return nil +} + +func (p *EchoClientResult) GetSuccess() *grpc_pb.Response { + if !p.IsSetSuccess() { + return EchoClientResult_Success_DEFAULT + } + return p.Success +} + +func (p *EchoClientResult) SetSuccess(x interface{}) { + p.Success = x.(*grpc_pb.Response) +} + +func (p *EchoClientResult) IsSetSuccess() bool { + return p.Success != nil +} + +func (p *EchoClientResult) GetResult() interface{} { + return p.Success +} + +func echoServerHandler(ctx context.Context, handler interface{}, arg, result interface{}) error { + st := arg.(*streaming.Args).Stream + stream := &pBServiceEchoServerServer{st} + req := new(grpc_pb.Request) + if err := st.RecvMsg(req); err != nil { + return err + } + return handler.(grpc_pb.PBService).EchoServer(req, stream) +} + +type pBServiceEchoServerClient struct { + streaming.Stream +} + +func (x *pBServiceEchoServerClient) Recv() (*grpc_pb.Response, error) { + m := new(grpc_pb.Response) + return m, x.Stream.RecvMsg(m) +} + +type pBServiceEchoServerServer struct { + streaming.Stream +} + +func (x *pBServiceEchoServerServer) Send(m *grpc_pb.Response) error { + return x.Stream.SendMsg(m) +} + +func newEchoServerArgs() interface{} { + return &EchoServerArgs{} +} + +func newEchoServerResult() interface{} { + return &EchoServerResult{} +} + +type EchoServerArgs struct { + Req *grpc_pb.Request +} + +func (p *EchoServerArgs) FastRead(buf []byte, _type int8, number int32) (n int, err error) { + if !p.IsSetReq() { + p.Req = new(grpc_pb.Request) + } + return p.Req.FastRead(buf, _type, number) +} + +func (p *EchoServerArgs) FastWrite(buf []byte) (n int) { + if !p.IsSetReq() { + return 0 + } + return p.Req.FastWrite(buf) +} + +func (p *EchoServerArgs) Size() (n int) { + if !p.IsSetReq() { + return 0 + } + return p.Req.Size() +} + +func (p *EchoServerArgs) Marshal(out []byte) ([]byte, error) { + if !p.IsSetReq() { + return out, nil + } + return proto.Marshal(p.Req) +} + +func (p *EchoServerArgs) Unmarshal(in []byte) error { + msg := new(grpc_pb.Request) + if err := proto.Unmarshal(in, msg); err != nil { + return err + } + p.Req = msg + return nil +} + +var EchoServerArgs_Req_DEFAULT *grpc_pb.Request + +func (p *EchoServerArgs) GetReq() *grpc_pb.Request { + if !p.IsSetReq() { + return EchoServerArgs_Req_DEFAULT + } + return p.Req +} + +func (p *EchoServerArgs) IsSetReq() bool { + return p.Req != nil +} + +func (p *EchoServerArgs) GetFirstArgument() interface{} { + return p.Req +} + +type EchoServerResult struct { + Success *grpc_pb.Response +} + +var EchoServerResult_Success_DEFAULT *grpc_pb.Response + +func (p *EchoServerResult) FastRead(buf []byte, _type int8, number int32) (n int, err error) { + if !p.IsSetSuccess() { + p.Success = new(grpc_pb.Response) + } + return p.Success.FastRead(buf, _type, number) +} + +func (p *EchoServerResult) FastWrite(buf []byte) (n int) { + if !p.IsSetSuccess() { + return 0 + } + return p.Success.FastWrite(buf) +} + +func (p *EchoServerResult) Size() (n int) { + if !p.IsSetSuccess() { + return 0 + } + return p.Success.Size() +} + +func (p *EchoServerResult) Marshal(out []byte) ([]byte, error) { + if !p.IsSetSuccess() { + return out, nil + } + return proto.Marshal(p.Success) +} + +func (p *EchoServerResult) Unmarshal(in []byte) error { + msg := new(grpc_pb.Response) + if err := proto.Unmarshal(in, msg); err != nil { + return err + } + p.Success = msg + return nil +} + +func (p *EchoServerResult) GetSuccess() *grpc_pb.Response { + if !p.IsSetSuccess() { + return EchoServerResult_Success_DEFAULT + } + return p.Success +} + +func (p *EchoServerResult) SetSuccess(x interface{}) { + p.Success = x.(*grpc_pb.Response) +} + +func (p *EchoServerResult) IsSetSuccess() bool { + return p.Success != nil +} + +func (p *EchoServerResult) GetResult() interface{} { + return p.Success +} + +func echoPingPongHandler(ctx context.Context, handler interface{}, arg, result interface{}) error { + switch s := arg.(type) { + case *streaming.Args: + st := s.Stream + req := new(grpc_pb.Request) + if err := st.RecvMsg(req); err != nil { + return err + } + resp, err := handler.(grpc_pb.PBService).EchoPingPong(ctx, req) + if err != nil { + return err + } + return st.SendMsg(resp) + case *EchoPingPongArgs: + success, err := handler.(grpc_pb.PBService).EchoPingPong(ctx, s.Req) + if err != nil { + return err + } + realResult := result.(*EchoPingPongResult) + realResult.Success = success + return nil + default: + return errInvalidMessageType + } +} +func newEchoPingPongArgs() interface{} { + return &EchoPingPongArgs{} +} + +func newEchoPingPongResult() interface{} { + return &EchoPingPongResult{} +} + +type EchoPingPongArgs struct { + Req *grpc_pb.Request +} + +func (p *EchoPingPongArgs) FastRead(buf []byte, _type int8, number int32) (n int, err error) { + if !p.IsSetReq() { + p.Req = new(grpc_pb.Request) + } + return p.Req.FastRead(buf, _type, number) +} + +func (p *EchoPingPongArgs) FastWrite(buf []byte) (n int) { + if !p.IsSetReq() { + return 0 + } + return p.Req.FastWrite(buf) +} + +func (p *EchoPingPongArgs) Size() (n int) { + if !p.IsSetReq() { + return 0 + } + return p.Req.Size() +} + +func (p *EchoPingPongArgs) Marshal(out []byte) ([]byte, error) { + if !p.IsSetReq() { + return out, nil + } + return proto.Marshal(p.Req) +} + +func (p *EchoPingPongArgs) Unmarshal(in []byte) error { + msg := new(grpc_pb.Request) + if err := proto.Unmarshal(in, msg); err != nil { + return err + } + p.Req = msg + return nil +} + +var EchoPingPongArgs_Req_DEFAULT *grpc_pb.Request + +func (p *EchoPingPongArgs) GetReq() *grpc_pb.Request { + if !p.IsSetReq() { + return EchoPingPongArgs_Req_DEFAULT + } + return p.Req +} + +func (p *EchoPingPongArgs) IsSetReq() bool { + return p.Req != nil +} + +func (p *EchoPingPongArgs) GetFirstArgument() interface{} { + return p.Req +} + +type EchoPingPongResult struct { + Success *grpc_pb.Response +} + +var EchoPingPongResult_Success_DEFAULT *grpc_pb.Response + +func (p *EchoPingPongResult) FastRead(buf []byte, _type int8, number int32) (n int, err error) { + if !p.IsSetSuccess() { + p.Success = new(grpc_pb.Response) + } + return p.Success.FastRead(buf, _type, number) +} + +func (p *EchoPingPongResult) FastWrite(buf []byte) (n int) { + if !p.IsSetSuccess() { + return 0 + } + return p.Success.FastWrite(buf) +} + +func (p *EchoPingPongResult) Size() (n int) { + if !p.IsSetSuccess() { + return 0 + } + return p.Success.Size() +} + +func (p *EchoPingPongResult) Marshal(out []byte) ([]byte, error) { + if !p.IsSetSuccess() { + return out, nil + } + return proto.Marshal(p.Success) +} + +func (p *EchoPingPongResult) Unmarshal(in []byte) error { + msg := new(grpc_pb.Response) + if err := proto.Unmarshal(in, msg); err != nil { + return err + } + p.Success = msg + return nil +} + +func (p *EchoPingPongResult) GetSuccess() *grpc_pb.Response { + if !p.IsSetSuccess() { + return EchoPingPongResult_Success_DEFAULT + } + return p.Success +} + +func (p *EchoPingPongResult) SetSuccess(x interface{}) { + p.Success = x.(*grpc_pb.Response) +} + +func (p *EchoPingPongResult) IsSetSuccess() bool { + return p.Success != nil +} + +func (p *EchoPingPongResult) GetResult() interface{} { + return p.Success +} + +type kClient struct { + c client.Client +} + +func newServiceClient(c client.Client) *kClient { + return &kClient{ + c: c, + } +} + +func (p *kClient) Echo(ctx context.Context) (PBService_EchoClient, error) { + streamClient, ok := p.c.(client.Streaming) + if !ok { + return nil, fmt.Errorf("client not support streaming") + } + res := new(streaming.Result) + err := streamClient.Stream(ctx, "Echo", nil, res) + if err != nil { + return nil, err + } + stream := &pBServiceEchoClient{res.Stream} + return stream, nil +} + +func (p *kClient) EchoClient(ctx context.Context) (PBService_EchoClientClient, error) { + streamClient, ok := p.c.(client.Streaming) + if !ok { + return nil, fmt.Errorf("client not support streaming") + } + res := new(streaming.Result) + err := streamClient.Stream(ctx, "EchoClient", nil, res) + if err != nil { + return nil, err + } + stream := &pBServiceEchoClientClient{res.Stream} + return stream, nil +} + +func (p *kClient) EchoServer(ctx context.Context, req *grpc_pb.Request) (PBService_EchoServerClient, error) { + streamClient, ok := p.c.(client.Streaming) + if !ok { + return nil, fmt.Errorf("client not support streaming") + } + res := new(streaming.Result) + err := streamClient.Stream(ctx, "EchoServer", nil, res) + if err != nil { + return nil, err + } + stream := &pBServiceEchoServerClient{res.Stream} + + if err := stream.Stream.SendMsg(req); err != nil { + return nil, err + } + if err := stream.Stream.Close(); err != nil { + return nil, err + } + return stream, nil +} + +func (p *kClient) EchoPingPong(ctx context.Context, Req *grpc_pb.Request) (r *grpc_pb.Response, err error) { + var _args EchoPingPongArgs + _args.Req = Req + var _result EchoPingPongResult + if err = p.c.Call(ctx, "EchoPingPong", &_args, &_result); err != nil { + return + } + return _result.GetSuccess(), nil +} diff --git a/thrift_streaming/kitex_gen/grpc_pb/pbservice/server.go b/thrift_streaming/kitex_gen/grpc_pb/pbservice/server.go new file mode 100644 index 0000000..aa66822 --- /dev/null +++ b/thrift_streaming/kitex_gen/grpc_pb/pbservice/server.go @@ -0,0 +1,20 @@ +// Code generated by Kitex v0.8.0. DO NOT EDIT. +package pbservice + +import ( + grpc_pb "github.com/cloudwego/kitex-tests/thrift_streaming/kitex_gen/grpc_pb" + server "github.com/cloudwego/kitex/server" +) + +// NewServer creates a server.Server with the given handler and options. +func NewServer(handler grpc_pb.PBService, opts ...server.Option) server.Server { + var options []server.Option + + options = append(options, opts...) + + svr := server.NewServer(options...) + if err := svr.RegisterService(serviceInfo(), handler); err != nil { + panic(err) + } + return svr +} diff --git a/thrift_streaming/kitex_gen/kitex_pb/api_no_stream.pb.fast.go b/thrift_streaming/kitex_gen/kitex_pb/api_no_stream.pb.fast.go new file mode 100644 index 0000000..aca5f22 --- /dev/null +++ b/thrift_streaming/kitex_gen/kitex_pb/api_no_stream.pb.fast.go @@ -0,0 +1,135 @@ +// Code generated by Fastpb v0.0.2. DO NOT EDIT. + +package kitex_pb + +import ( + fmt "fmt" + fastpb "github.com/cloudwego/fastpb" +) + +var ( + _ = fmt.Errorf + _ = fastpb.Skip +) + +func (x *Request) FastRead(buf []byte, _type int8, number int32) (offset int, err error) { + switch number { + case 1: + offset, err = x.fastReadField1(buf, _type) + if err != nil { + goto ReadFieldError + } + default: + offset, err = fastpb.Skip(buf, _type, number) + if err != nil { + goto SkipFieldError + } + } + return offset, nil +SkipFieldError: + return offset, fmt.Errorf("%T cannot parse invalid wire-format data, error: %s", x, err) +ReadFieldError: + return offset, fmt.Errorf("%T read field %d '%s' error: %s", x, number, fieldIDToName_Request[number], err) +} + +func (x *Request) fastReadField1(buf []byte, _type int8) (offset int, err error) { + x.Message, offset, err = fastpb.ReadString(buf, _type) + return offset, err +} + +func (x *Response) FastRead(buf []byte, _type int8, number int32) (offset int, err error) { + switch number { + case 1: + offset, err = x.fastReadField1(buf, _type) + if err != nil { + goto ReadFieldError + } + default: + offset, err = fastpb.Skip(buf, _type, number) + if err != nil { + goto SkipFieldError + } + } + return offset, nil +SkipFieldError: + return offset, fmt.Errorf("%T cannot parse invalid wire-format data, error: %s", x, err) +ReadFieldError: + return offset, fmt.Errorf("%T read field %d '%s' error: %s", x, number, fieldIDToName_Response[number], err) +} + +func (x *Response) fastReadField1(buf []byte, _type int8) (offset int, err error) { + x.Message, offset, err = fastpb.ReadString(buf, _type) + return offset, err +} + +func (x *Request) FastWrite(buf []byte) (offset int) { + if x == nil { + return offset + } + offset += x.fastWriteField1(buf[offset:]) + return offset +} + +func (x *Request) fastWriteField1(buf []byte) (offset int) { + if x.Message == "" { + return offset + } + offset += fastpb.WriteString(buf[offset:], 1, x.GetMessage()) + return offset +} + +func (x *Response) FastWrite(buf []byte) (offset int) { + if x == nil { + return offset + } + offset += x.fastWriteField1(buf[offset:]) + return offset +} + +func (x *Response) fastWriteField1(buf []byte) (offset int) { + if x.Message == "" { + return offset + } + offset += fastpb.WriteString(buf[offset:], 1, x.GetMessage()) + return offset +} + +func (x *Request) Size() (n int) { + if x == nil { + return n + } + n += x.sizeField1() + return n +} + +func (x *Request) sizeField1() (n int) { + if x.Message == "" { + return n + } + n += fastpb.SizeString(1, x.GetMessage()) + return n +} + +func (x *Response) Size() (n int) { + if x == nil { + return n + } + n += x.sizeField1() + return n +} + +func (x *Response) sizeField1() (n int) { + if x.Message == "" { + return n + } + n += fastpb.SizeString(1, x.GetMessage()) + return n +} + +var fieldIDToName_Request = map[int32]string{ + 1: "Message", +} + +var fieldIDToName_Response = map[int32]string{ + 1: "Message", +} diff --git a/thrift_streaming/kitex_gen/kitex_pb/api_no_stream.pb.go b/thrift_streaming/kitex_gen/kitex_pb/api_no_stream.pb.go new file mode 100644 index 0000000..94f11bb --- /dev/null +++ b/thrift_streaming/kitex_gen/kitex_pb/api_no_stream.pb.go @@ -0,0 +1,224 @@ +// Code generated by protoc-gen-go. DO NOT EDIT. +// versions: +// protoc-gen-go v1.28.1 +// protoc v3.21.12 +// source: idl/api_no_stream.proto + +package kitex_pb + +import ( + context "context" + 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 + + Message string `protobuf:"bytes,1,opt,name=message,proto3" json:"message,omitempty"` +} + +func (x *Request) Reset() { + *x = Request{} + if protoimpl.UnsafeEnabled { + mi := &file_idl_api_no_stream_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_idl_api_no_stream_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_idl_api_no_stream_proto_rawDescGZIP(), []int{0} +} + +func (x *Request) GetMessage() string { + if x != nil { + return x.Message + } + return "" +} + +type Response struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Message string `protobuf:"bytes,1,opt,name=message,proto3" json:"message,omitempty"` +} + +func (x *Response) Reset() { + *x = Response{} + if protoimpl.UnsafeEnabled { + mi := &file_idl_api_no_stream_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_idl_api_no_stream_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_idl_api_no_stream_proto_rawDescGZIP(), []int{1} +} + +func (x *Response) GetMessage() string { + if x != nil { + return x.Message + } + return "" +} + +var File_idl_api_no_stream_proto protoreflect.FileDescriptor + +var file_idl_api_no_stream_proto_rawDesc = []byte{ + 0x0a, 0x17, 0x69, 0x64, 0x6c, 0x2f, 0x61, 0x70, 0x69, 0x5f, 0x6e, 0x6f, 0x5f, 0x73, 0x74, 0x72, + 0x65, 0x61, 0x6d, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x08, 0x6b, 0x69, 0x74, 0x65, 0x78, + 0x5f, 0x70, 0x62, 0x22, 0x23, 0x0a, 0x07, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x18, + 0x0a, 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, + 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x22, 0x24, 0x0a, 0x08, 0x52, 0x65, 0x73, 0x70, + 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x18, 0x0a, 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x18, + 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x32, 0x44, + 0x0a, 0x09, 0x50, 0x42, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x12, 0x37, 0x0a, 0x0c, 0x45, + 0x63, 0x68, 0x6f, 0x50, 0x69, 0x6e, 0x67, 0x50, 0x6f, 0x6e, 0x67, 0x12, 0x11, 0x2e, 0x6b, 0x69, + 0x74, 0x65, 0x78, 0x5f, 0x70, 0x62, 0x2e, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x12, + 0x2e, 0x6b, 0x69, 0x74, 0x65, 0x78, 0x5f, 0x70, 0x62, 0x2e, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, + 0x73, 0x65, 0x22, 0x00, 0x42, 0x46, 0x5a, 0x44, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, + 0x6f, 0x6d, 0x2f, 0x63, 0x6c, 0x6f, 0x75, 0x64, 0x77, 0x65, 0x67, 0x6f, 0x2f, 0x6b, 0x69, 0x74, + 0x65, 0x78, 0x2d, 0x74, 0x65, 0x73, 0x74, 0x73, 0x2f, 0x74, 0x68, 0x72, 0x69, 0x66, 0x74, 0x5f, + 0x73, 0x74, 0x72, 0x65, 0x61, 0x6d, 0x69, 0x6e, 0x67, 0x2f, 0x6b, 0x69, 0x74, 0x65, 0x78, 0x5f, + 0x67, 0x65, 0x6e, 0x2f, 0x6b, 0x69, 0x74, 0x65, 0x78, 0x5f, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, + 0x6f, 0x74, 0x6f, 0x33, +} + +var ( + file_idl_api_no_stream_proto_rawDescOnce sync.Once + file_idl_api_no_stream_proto_rawDescData = file_idl_api_no_stream_proto_rawDesc +) + +func file_idl_api_no_stream_proto_rawDescGZIP() []byte { + file_idl_api_no_stream_proto_rawDescOnce.Do(func() { + file_idl_api_no_stream_proto_rawDescData = protoimpl.X.CompressGZIP(file_idl_api_no_stream_proto_rawDescData) + }) + return file_idl_api_no_stream_proto_rawDescData +} + +var file_idl_api_no_stream_proto_msgTypes = make([]protoimpl.MessageInfo, 2) +var file_idl_api_no_stream_proto_goTypes = []interface{}{ + (*Request)(nil), // 0: kitex_pb.Request + (*Response)(nil), // 1: kitex_pb.Response +} +var file_idl_api_no_stream_proto_depIdxs = []int32{ + 0, // 0: kitex_pb.PBService.EchoPingPong:input_type -> kitex_pb.Request + 1, // 1: kitex_pb.PBService.EchoPingPong:output_type -> kitex_pb.Response + 1, // [1:2] is the sub-list for method output_type + 0, // [0:1] 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_idl_api_no_stream_proto_init() } +func file_idl_api_no_stream_proto_init() { + if File_idl_api_no_stream_proto != nil { + return + } + if !protoimpl.UnsafeEnabled { + file_idl_api_no_stream_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_idl_api_no_stream_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 + } + } + } + type x struct{} + out := protoimpl.TypeBuilder{ + File: protoimpl.DescBuilder{ + GoPackagePath: reflect.TypeOf(x{}).PkgPath(), + RawDescriptor: file_idl_api_no_stream_proto_rawDesc, + NumEnums: 0, + NumMessages: 2, + NumExtensions: 0, + NumServices: 1, + }, + GoTypes: file_idl_api_no_stream_proto_goTypes, + DependencyIndexes: file_idl_api_no_stream_proto_depIdxs, + MessageInfos: file_idl_api_no_stream_proto_msgTypes, + }.Build() + File_idl_api_no_stream_proto = out.File + file_idl_api_no_stream_proto_rawDesc = nil + file_idl_api_no_stream_proto_goTypes = nil + file_idl_api_no_stream_proto_depIdxs = nil +} + +var _ context.Context + +// Code generated by Kitex v0.8.0. DO NOT EDIT. + +type PBService interface { + EchoPingPong(ctx context.Context, req *Request) (res *Response, err error) +} diff --git a/thrift_streaming/kitex_gen/kitex_pb/pbservice/client.go b/thrift_streaming/kitex_gen/kitex_pb/pbservice/client.go new file mode 100644 index 0000000..f3f3ce9 --- /dev/null +++ b/thrift_streaming/kitex_gen/kitex_pb/pbservice/client.go @@ -0,0 +1,49 @@ +// Code generated by Kitex v0.8.0. DO NOT EDIT. + +package pbservice + +import ( + "context" + kitex_pb "github.com/cloudwego/kitex-tests/thrift_streaming/kitex_gen/kitex_pb" + client "github.com/cloudwego/kitex/client" + callopt "github.com/cloudwego/kitex/client/callopt" +) + +// Client is designed to provide IDL-compatible methods with call-option parameter for kitex framework. +type Client interface { + EchoPingPong(ctx context.Context, Req *kitex_pb.Request, callOptions ...callopt.Option) (r *kitex_pb.Response, err error) +} + +// NewClient creates a client for the service defined in IDL. +func NewClient(destService string, opts ...client.Option) (Client, error) { + var options []client.Option + options = append(options, client.WithDestService(destService)) + + options = append(options, opts...) + + kc, err := client.NewClient(serviceInfo(), options...) + if err != nil { + return nil, err + } + return &kPBServiceClient{ + kClient: newServiceClient(kc), + }, nil +} + +// MustNewClient creates a client for the service defined in IDL. It panics if any error occurs. +func MustNewClient(destService string, opts ...client.Option) Client { + kc, err := NewClient(destService, opts...) + if err != nil { + panic(err) + } + return kc +} + +type kPBServiceClient struct { + *kClient +} + +func (p *kPBServiceClient) EchoPingPong(ctx context.Context, Req *kitex_pb.Request, callOptions ...callopt.Option) (r *kitex_pb.Response, err error) { + ctx = client.NewCtxWithCallOptions(ctx, callOptions) + return p.kClient.EchoPingPong(ctx, Req) +} diff --git a/thrift_streaming/kitex_gen/kitex_pb/pbservice/invoker.go b/thrift_streaming/kitex_gen/kitex_pb/pbservice/invoker.go new file mode 100644 index 0000000..159bb61 --- /dev/null +++ b/thrift_streaming/kitex_gen/kitex_pb/pbservice/invoker.go @@ -0,0 +1,24 @@ +// Code generated by Kitex v0.8.0. DO NOT EDIT. + +package pbservice + +import ( + kitex_pb "github.com/cloudwego/kitex-tests/thrift_streaming/kitex_gen/kitex_pb" + server "github.com/cloudwego/kitex/server" +) + +// NewInvoker creates a server.Invoker with the given handler and options. +func NewInvoker(handler kitex_pb.PBService, opts ...server.Option) server.Invoker { + var options []server.Option + + options = append(options, opts...) + + s := server.NewInvoker(options...) + if err := s.RegisterService(serviceInfo(), handler); err != nil { + panic(err) + } + if err := s.Init(); err != nil { + panic(err) + } + return s +} diff --git a/thrift_streaming/kitex_gen/kitex_pb/pbservice/pbservice.go b/thrift_streaming/kitex_gen/kitex_pb/pbservice/pbservice.go new file mode 100644 index 0000000..e2fce69 --- /dev/null +++ b/thrift_streaming/kitex_gen/kitex_pb/pbservice/pbservice.go @@ -0,0 +1,264 @@ +// Code generated by Kitex v0.8.0. DO NOT EDIT. + +package pbservice + +import ( + "context" + "errors" + kitex_pb "github.com/cloudwego/kitex-tests/thrift_streaming/kitex_gen/kitex_pb" + client "github.com/cloudwego/kitex/client" + kitex "github.com/cloudwego/kitex/pkg/serviceinfo" + streaming "github.com/cloudwego/kitex/pkg/streaming" + proto "google.golang.org/protobuf/proto" +) + +var errInvalidMessageType = errors.New("invalid message type for service method handler") + +var _ = streaming.KitexUnusedProtection + +var serviceMethods = map[string]kitex.MethodInfo{ + "EchoPingPong": kitex.NewMethodInfo( + echoPingPongHandler, + newEchoPingPongArgs, + newEchoPingPongResult, + false, + kitex.WithStreamingMode(kitex.StreamingUnary), + ), +} + +var ( + pBServiceServiceInfo = NewServiceInfo() + pBServiceServiceInfoForClient = NewServiceInfoForClient() + pBServiceServiceInfoForStreamClient = NewServiceInfoForStreamClient() +) + +// for server +func serviceInfo() *kitex.ServiceInfo { + return pBServiceServiceInfo +} + +// for client +func serviceInfoForStreamClient() *kitex.ServiceInfo { + return pBServiceServiceInfoForStreamClient +} + +// for stream client +func serviceInfoForClient() *kitex.ServiceInfo { + return pBServiceServiceInfoForClient +} + +// NewServiceInfo creates a new ServiceInfo containing all methods +func NewServiceInfo() *kitex.ServiceInfo { + return newServiceInfo(false, true, true) +} + +// NewServiceInfo creates a new ServiceInfo containing non-streaming methods +func NewServiceInfoForClient() *kitex.ServiceInfo { + return newServiceInfo(false, false, true) +} +func NewServiceInfoForStreamClient() *kitex.ServiceInfo { + return newServiceInfo(true, true, false) +} + +func newServiceInfo(hasStreaming bool, keepStreamingMethods bool, keepNonStreamingMethods bool) *kitex.ServiceInfo { + serviceName := "PBService" + handlerType := (*kitex_pb.PBService)(nil) + methods := map[string]kitex.MethodInfo{} + for name, m := range serviceMethods { + if m.IsStreaming() && !keepStreamingMethods { + continue + } + if !m.IsStreaming() && !keepNonStreamingMethods { + continue + } + methods[name] = m + } + extra := map[string]interface{}{ + "PackageName": "kitex_pb", + } + if hasStreaming { + extra["streaming"] = hasStreaming + } + svcInfo := &kitex.ServiceInfo{ + ServiceName: serviceName, + HandlerType: handlerType, + Methods: methods, + PayloadCodec: kitex.Protobuf, + KiteXGenVersion: "v0.8.0", + Extra: extra, + } + return svcInfo +} + +func echoPingPongHandler(ctx context.Context, handler interface{}, arg, result interface{}) error { + switch s := arg.(type) { + case *streaming.Args: + st := s.Stream + req := new(kitex_pb.Request) + if err := st.RecvMsg(req); err != nil { + return err + } + resp, err := handler.(kitex_pb.PBService).EchoPingPong(ctx, req) + if err != nil { + return err + } + return st.SendMsg(resp) + case *EchoPingPongArgs: + success, err := handler.(kitex_pb.PBService).EchoPingPong(ctx, s.Req) + if err != nil { + return err + } + realResult := result.(*EchoPingPongResult) + realResult.Success = success + return nil + default: + return errInvalidMessageType + } +} +func newEchoPingPongArgs() interface{} { + return &EchoPingPongArgs{} +} + +func newEchoPingPongResult() interface{} { + return &EchoPingPongResult{} +} + +type EchoPingPongArgs struct { + Req *kitex_pb.Request +} + +func (p *EchoPingPongArgs) FastRead(buf []byte, _type int8, number int32) (n int, err error) { + if !p.IsSetReq() { + p.Req = new(kitex_pb.Request) + } + return p.Req.FastRead(buf, _type, number) +} + +func (p *EchoPingPongArgs) FastWrite(buf []byte) (n int) { + if !p.IsSetReq() { + return 0 + } + return p.Req.FastWrite(buf) +} + +func (p *EchoPingPongArgs) Size() (n int) { + if !p.IsSetReq() { + return 0 + } + return p.Req.Size() +} + +func (p *EchoPingPongArgs) Marshal(out []byte) ([]byte, error) { + if !p.IsSetReq() { + return out, nil + } + return proto.Marshal(p.Req) +} + +func (p *EchoPingPongArgs) Unmarshal(in []byte) error { + msg := new(kitex_pb.Request) + if err := proto.Unmarshal(in, msg); err != nil { + return err + } + p.Req = msg + return nil +} + +var EchoPingPongArgs_Req_DEFAULT *kitex_pb.Request + +func (p *EchoPingPongArgs) GetReq() *kitex_pb.Request { + if !p.IsSetReq() { + return EchoPingPongArgs_Req_DEFAULT + } + return p.Req +} + +func (p *EchoPingPongArgs) IsSetReq() bool { + return p.Req != nil +} + +func (p *EchoPingPongArgs) GetFirstArgument() interface{} { + return p.Req +} + +type EchoPingPongResult struct { + Success *kitex_pb.Response +} + +var EchoPingPongResult_Success_DEFAULT *kitex_pb.Response + +func (p *EchoPingPongResult) FastRead(buf []byte, _type int8, number int32) (n int, err error) { + if !p.IsSetSuccess() { + p.Success = new(kitex_pb.Response) + } + return p.Success.FastRead(buf, _type, number) +} + +func (p *EchoPingPongResult) FastWrite(buf []byte) (n int) { + if !p.IsSetSuccess() { + return 0 + } + return p.Success.FastWrite(buf) +} + +func (p *EchoPingPongResult) Size() (n int) { + if !p.IsSetSuccess() { + return 0 + } + return p.Success.Size() +} + +func (p *EchoPingPongResult) Marshal(out []byte) ([]byte, error) { + if !p.IsSetSuccess() { + return out, nil + } + return proto.Marshal(p.Success) +} + +func (p *EchoPingPongResult) Unmarshal(in []byte) error { + msg := new(kitex_pb.Response) + if err := proto.Unmarshal(in, msg); err != nil { + return err + } + p.Success = msg + return nil +} + +func (p *EchoPingPongResult) GetSuccess() *kitex_pb.Response { + if !p.IsSetSuccess() { + return EchoPingPongResult_Success_DEFAULT + } + return p.Success +} + +func (p *EchoPingPongResult) SetSuccess(x interface{}) { + p.Success = x.(*kitex_pb.Response) +} + +func (p *EchoPingPongResult) IsSetSuccess() bool { + return p.Success != nil +} + +func (p *EchoPingPongResult) GetResult() interface{} { + return p.Success +} + +type kClient struct { + c client.Client +} + +func newServiceClient(c client.Client) *kClient { + return &kClient{ + c: c, + } +} + +func (p *kClient) EchoPingPong(ctx context.Context, Req *kitex_pb.Request) (r *kitex_pb.Response, err error) { + var _args EchoPingPongArgs + _args.Req = Req + var _result EchoPingPongResult + if err = p.c.Call(ctx, "EchoPingPong", &_args, &_result); err != nil { + return + } + return _result.GetSuccess(), nil +} diff --git a/thrift_streaming/kitex_gen/kitex_pb/pbservice/server.go b/thrift_streaming/kitex_gen/kitex_pb/pbservice/server.go new file mode 100644 index 0000000..5bf8bae --- /dev/null +++ b/thrift_streaming/kitex_gen/kitex_pb/pbservice/server.go @@ -0,0 +1,20 @@ +// Code generated by Kitex v0.8.0. DO NOT EDIT. +package pbservice + +import ( + kitex_pb "github.com/cloudwego/kitex-tests/thrift_streaming/kitex_gen/kitex_pb" + server "github.com/cloudwego/kitex/server" +) + +// NewServer creates a server.Server with the given handler and options. +func NewServer(handler kitex_pb.PBService, opts ...server.Option) server.Server { + var options []server.Option + + options = append(options, opts...) + + svr := server.NewServer(options...) + if err := svr.RegisterService(serviceInfo(), handler); err != nil { + panic(err) + } + return svr +} diff --git a/thrift_streaming/kitex_gen_cross/echo/api.go b/thrift_streaming/kitex_gen_cross/echo/api.go new file mode 100644 index 0000000..ff1c0f4 --- /dev/null +++ b/thrift_streaming/kitex_gen_cross/echo/api.go @@ -0,0 +1,1685 @@ +// Code generated by thriftgo (0.3.5). DO NOT EDIT. + +package echo + +import ( + "context" + "fmt" + "github.com/apache/thrift/lib/go/thrift" + "strings" +) + +type EchoRequest struct { + Message string `thrift:"message,1,required" frugal:"1,required,string" json:"message"` +} + +func NewEchoRequest() *EchoRequest { + return &EchoRequest{} +} + +func (p *EchoRequest) InitDefault() { + *p = EchoRequest{} +} + +func (p *EchoRequest) GetMessage() (v string) { + return p.Message +} +func (p *EchoRequest) SetMessage(val string) { + p.Message = val +} + +var fieldIDToName_EchoRequest = map[int16]string{ + 1: "message", +} + +func (p *EchoRequest) Read(iprot thrift.TProtocol) (err error) { + + var fieldTypeId thrift.TType + var fieldId int16 + var issetMessage bool = false + + if _, err = iprot.ReadStructBegin(); err != nil { + goto ReadStructBeginError + } + + for { + _, fieldTypeId, fieldId, err = iprot.ReadFieldBegin() + if err != nil { + goto ReadFieldBeginError + } + if fieldTypeId == thrift.STOP { + break + } + + switch fieldId { + case 1: + if fieldTypeId == thrift.STRING { + if err = p.ReadField1(iprot); err != nil { + goto ReadFieldError + } + issetMessage = true + } else if err = iprot.Skip(fieldTypeId); err != nil { + goto SkipFieldError + } + default: + if err = iprot.Skip(fieldTypeId); err != nil { + goto SkipFieldError + } + } + if err = iprot.ReadFieldEnd(); err != nil { + goto ReadFieldEndError + } + } + if err = iprot.ReadStructEnd(); err != nil { + goto ReadStructEndError + } + + if !issetMessage { + fieldId = 1 + goto RequiredFieldNotSetError + } + return nil +ReadStructBeginError: + return thrift.PrependError(fmt.Sprintf("%T read struct begin error: ", p), err) +ReadFieldBeginError: + return thrift.PrependError(fmt.Sprintf("%T read field %d begin error: ", p, fieldId), err) +ReadFieldError: + return thrift.PrependError(fmt.Sprintf("%T read field %d '%s' error: ", p, fieldId, fieldIDToName_EchoRequest[fieldId]), err) +SkipFieldError: + return thrift.PrependError(fmt.Sprintf("%T field %d skip type %d error: ", p, fieldId, fieldTypeId), err) + +ReadFieldEndError: + return thrift.PrependError(fmt.Sprintf("%T read field end error", p), err) +ReadStructEndError: + return thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err) +RequiredFieldNotSetError: + return thrift.NewTProtocolExceptionWithType(thrift.INVALID_DATA, fmt.Errorf("required field %s is not set", fieldIDToName_EchoRequest[fieldId])) +} + +func (p *EchoRequest) ReadField1(iprot thrift.TProtocol) error { + + if v, err := iprot.ReadString(); err != nil { + return err + } else { + p.Message = v + } + return nil +} + +func (p *EchoRequest) Write(oprot thrift.TProtocol) (err error) { + var fieldId int16 + if err = oprot.WriteStructBegin("EchoRequest"); err != nil { + goto WriteStructBeginError + } + if p != nil { + if err = p.writeField1(oprot); err != nil { + fieldId = 1 + goto WriteFieldError + } + } + if err = oprot.WriteFieldStop(); err != nil { + goto WriteFieldStopError + } + if err = oprot.WriteStructEnd(); err != nil { + goto WriteStructEndError + } + return nil +WriteStructBeginError: + return thrift.PrependError(fmt.Sprintf("%T write struct begin error: ", p), err) +WriteFieldError: + return thrift.PrependError(fmt.Sprintf("%T write field %d error: ", p, fieldId), err) +WriteFieldStopError: + return thrift.PrependError(fmt.Sprintf("%T write field stop error: ", p), err) +WriteStructEndError: + return thrift.PrependError(fmt.Sprintf("%T write struct end error: ", p), err) +} + +func (p *EchoRequest) writeField1(oprot thrift.TProtocol) (err error) { + if err = oprot.WriteFieldBegin("message", thrift.STRING, 1); err != nil { + goto WriteFieldBeginError + } + if err := oprot.WriteString(p.Message); err != nil { + return err + } + if err = oprot.WriteFieldEnd(); err != nil { + goto WriteFieldEndError + } + return nil +WriteFieldBeginError: + return thrift.PrependError(fmt.Sprintf("%T write field 1 begin error: ", p), err) +WriteFieldEndError: + return thrift.PrependError(fmt.Sprintf("%T write field 1 end error: ", p), err) +} + +func (p *EchoRequest) String() string { + if p == nil { + return "" + } + return fmt.Sprintf("EchoRequest(%+v)", *p) + +} + +func (p *EchoRequest) DeepEqual(ano *EchoRequest) bool { + if p == ano { + return true + } else if p == nil || ano == nil { + return false + } + if !p.Field1DeepEqual(ano.Message) { + return false + } + return true +} + +func (p *EchoRequest) Field1DeepEqual(src string) bool { + + if strings.Compare(p.Message, src) != 0 { + return false + } + return true +} + +type EchoResponse struct { + Message string `thrift:"message,1,required" frugal:"1,required,string" json:"message"` +} + +func NewEchoResponse() *EchoResponse { + return &EchoResponse{} +} + +func (p *EchoResponse) InitDefault() { + *p = EchoResponse{} +} + +func (p *EchoResponse) GetMessage() (v string) { + return p.Message +} +func (p *EchoResponse) SetMessage(val string) { + p.Message = val +} + +var fieldIDToName_EchoResponse = map[int16]string{ + 1: "message", +} + +func (p *EchoResponse) Read(iprot thrift.TProtocol) (err error) { + + var fieldTypeId thrift.TType + var fieldId int16 + var issetMessage bool = false + + if _, err = iprot.ReadStructBegin(); err != nil { + goto ReadStructBeginError + } + + for { + _, fieldTypeId, fieldId, err = iprot.ReadFieldBegin() + if err != nil { + goto ReadFieldBeginError + } + if fieldTypeId == thrift.STOP { + break + } + + switch fieldId { + case 1: + if fieldTypeId == thrift.STRING { + if err = p.ReadField1(iprot); err != nil { + goto ReadFieldError + } + issetMessage = true + } else if err = iprot.Skip(fieldTypeId); err != nil { + goto SkipFieldError + } + default: + if err = iprot.Skip(fieldTypeId); err != nil { + goto SkipFieldError + } + } + if err = iprot.ReadFieldEnd(); err != nil { + goto ReadFieldEndError + } + } + if err = iprot.ReadStructEnd(); err != nil { + goto ReadStructEndError + } + + if !issetMessage { + fieldId = 1 + goto RequiredFieldNotSetError + } + return nil +ReadStructBeginError: + return thrift.PrependError(fmt.Sprintf("%T read struct begin error: ", p), err) +ReadFieldBeginError: + return thrift.PrependError(fmt.Sprintf("%T read field %d begin error: ", p, fieldId), err) +ReadFieldError: + return thrift.PrependError(fmt.Sprintf("%T read field %d '%s' error: ", p, fieldId, fieldIDToName_EchoResponse[fieldId]), err) +SkipFieldError: + return thrift.PrependError(fmt.Sprintf("%T field %d skip type %d error: ", p, fieldId, fieldTypeId), err) + +ReadFieldEndError: + return thrift.PrependError(fmt.Sprintf("%T read field end error", p), err) +ReadStructEndError: + return thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err) +RequiredFieldNotSetError: + return thrift.NewTProtocolExceptionWithType(thrift.INVALID_DATA, fmt.Errorf("required field %s is not set", fieldIDToName_EchoResponse[fieldId])) +} + +func (p *EchoResponse) ReadField1(iprot thrift.TProtocol) error { + + if v, err := iprot.ReadString(); err != nil { + return err + } else { + p.Message = v + } + return nil +} + +func (p *EchoResponse) Write(oprot thrift.TProtocol) (err error) { + var fieldId int16 + if err = oprot.WriteStructBegin("EchoResponse"); err != nil { + goto WriteStructBeginError + } + if p != nil { + if err = p.writeField1(oprot); err != nil { + fieldId = 1 + goto WriteFieldError + } + } + if err = oprot.WriteFieldStop(); err != nil { + goto WriteFieldStopError + } + if err = oprot.WriteStructEnd(); err != nil { + goto WriteStructEndError + } + return nil +WriteStructBeginError: + return thrift.PrependError(fmt.Sprintf("%T write struct begin error: ", p), err) +WriteFieldError: + return thrift.PrependError(fmt.Sprintf("%T write field %d error: ", p, fieldId), err) +WriteFieldStopError: + return thrift.PrependError(fmt.Sprintf("%T write field stop error: ", p), err) +WriteStructEndError: + return thrift.PrependError(fmt.Sprintf("%T write struct end error: ", p), err) +} + +func (p *EchoResponse) writeField1(oprot thrift.TProtocol) (err error) { + if err = oprot.WriteFieldBegin("message", thrift.STRING, 1); err != nil { + goto WriteFieldBeginError + } + if err := oprot.WriteString(p.Message); err != nil { + return err + } + if err = oprot.WriteFieldEnd(); err != nil { + goto WriteFieldEndError + } + return nil +WriteFieldBeginError: + return thrift.PrependError(fmt.Sprintf("%T write field 1 begin error: ", p), err) +WriteFieldEndError: + return thrift.PrependError(fmt.Sprintf("%T write field 1 end error: ", p), err) +} + +func (p *EchoResponse) String() string { + if p == nil { + return "" + } + return fmt.Sprintf("EchoResponse(%+v)", *p) + +} + +func (p *EchoResponse) DeepEqual(ano *EchoResponse) bool { + if p == ano { + return true + } else if p == nil || ano == nil { + return false + } + if !p.Field1DeepEqual(ano.Message) { + return false + } + return true +} + +func (p *EchoResponse) Field1DeepEqual(src string) bool { + + if strings.Compare(p.Message, src) != 0 { + return false + } + return true +} + +type EchoException struct { + Message string `thrift:"message,1" frugal:"1,default,string" json:"message"` +} + +func NewEchoException() *EchoException { + return &EchoException{} +} + +func (p *EchoException) InitDefault() { + *p = EchoException{} +} + +func (p *EchoException) GetMessage() (v string) { + return p.Message +} +func (p *EchoException) SetMessage(val string) { + p.Message = val +} + +var fieldIDToName_EchoException = map[int16]string{ + 1: "message", +} + +func (p *EchoException) Read(iprot thrift.TProtocol) (err error) { + + var fieldTypeId thrift.TType + var fieldId int16 + + if _, err = iprot.ReadStructBegin(); err != nil { + goto ReadStructBeginError + } + + for { + _, fieldTypeId, fieldId, err = iprot.ReadFieldBegin() + if err != nil { + goto ReadFieldBeginError + } + if fieldTypeId == thrift.STOP { + break + } + + switch fieldId { + case 1: + if fieldTypeId == thrift.STRING { + if err = p.ReadField1(iprot); err != nil { + goto ReadFieldError + } + } else if err = iprot.Skip(fieldTypeId); err != nil { + goto SkipFieldError + } + default: + if err = iprot.Skip(fieldTypeId); err != nil { + goto SkipFieldError + } + } + if err = iprot.ReadFieldEnd(); err != nil { + goto ReadFieldEndError + } + } + if err = iprot.ReadStructEnd(); err != nil { + goto ReadStructEndError + } + + return nil +ReadStructBeginError: + return thrift.PrependError(fmt.Sprintf("%T read struct begin error: ", p), err) +ReadFieldBeginError: + return thrift.PrependError(fmt.Sprintf("%T read field %d begin error: ", p, fieldId), err) +ReadFieldError: + return thrift.PrependError(fmt.Sprintf("%T read field %d '%s' error: ", p, fieldId, fieldIDToName_EchoException[fieldId]), err) +SkipFieldError: + return thrift.PrependError(fmt.Sprintf("%T field %d skip type %d error: ", p, fieldId, fieldTypeId), err) + +ReadFieldEndError: + return thrift.PrependError(fmt.Sprintf("%T read field end error", p), err) +ReadStructEndError: + return thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err) +} + +func (p *EchoException) ReadField1(iprot thrift.TProtocol) error { + + if v, err := iprot.ReadString(); err != nil { + return err + } else { + p.Message = v + } + return nil +} + +func (p *EchoException) Write(oprot thrift.TProtocol) (err error) { + var fieldId int16 + if err = oprot.WriteStructBegin("EchoException"); err != nil { + goto WriteStructBeginError + } + if p != nil { + if err = p.writeField1(oprot); err != nil { + fieldId = 1 + goto WriteFieldError + } + } + if err = oprot.WriteFieldStop(); err != nil { + goto WriteFieldStopError + } + if err = oprot.WriteStructEnd(); err != nil { + goto WriteStructEndError + } + return nil +WriteStructBeginError: + return thrift.PrependError(fmt.Sprintf("%T write struct begin error: ", p), err) +WriteFieldError: + return thrift.PrependError(fmt.Sprintf("%T write field %d error: ", p, fieldId), err) +WriteFieldStopError: + return thrift.PrependError(fmt.Sprintf("%T write field stop error: ", p), err) +WriteStructEndError: + return thrift.PrependError(fmt.Sprintf("%T write struct end error: ", p), err) +} + +func (p *EchoException) writeField1(oprot thrift.TProtocol) (err error) { + if err = oprot.WriteFieldBegin("message", thrift.STRING, 1); err != nil { + goto WriteFieldBeginError + } + if err := oprot.WriteString(p.Message); err != nil { + return err + } + if err = oprot.WriteFieldEnd(); err != nil { + goto WriteFieldEndError + } + return nil +WriteFieldBeginError: + return thrift.PrependError(fmt.Sprintf("%T write field 1 begin error: ", p), err) +WriteFieldEndError: + return thrift.PrependError(fmt.Sprintf("%T write field 1 end error: ", p), err) +} + +func (p *EchoException) String() string { + if p == nil { + return "" + } + return fmt.Sprintf("EchoException(%+v)", *p) + +} +func (p *EchoException) Error() string { + return p.String() +} + +func (p *EchoException) DeepEqual(ano *EchoException) bool { + if p == ano { + return true + } else if p == nil || ano == nil { + return false + } + if !p.Field1DeepEqual(ano.Message) { + return false + } + return true +} + +func (p *EchoException) Field1DeepEqual(src string) bool { + + if strings.Compare(p.Message, src) != 0 { + return false + } + return true +} + +type EchoService interface { + EchoPingPong(ctx context.Context, req1 *EchoRequest, req2 *EchoRequest) (r *EchoResponse, err error) + + EchoOneway(ctx context.Context, req1 *EchoRequest) (err error) + + Ping(ctx context.Context) (err error) +} + +type EchoServiceClient struct { + c thrift.TClient +} + +func NewEchoServiceClientFactory(t thrift.TTransport, f thrift.TProtocolFactory) *EchoServiceClient { + return &EchoServiceClient{ + c: thrift.NewTStandardClient(f.GetProtocol(t), f.GetProtocol(t)), + } +} + +func NewEchoServiceClientProtocol(t thrift.TTransport, iprot thrift.TProtocol, oprot thrift.TProtocol) *EchoServiceClient { + return &EchoServiceClient{ + c: thrift.NewTStandardClient(iprot, oprot), + } +} + +func NewEchoServiceClient(c thrift.TClient) *EchoServiceClient { + return &EchoServiceClient{ + c: c, + } +} + +func (p *EchoServiceClient) Client_() thrift.TClient { + return p.c +} + +func (p *EchoServiceClient) EchoPingPong(ctx context.Context, req1 *EchoRequest, req2 *EchoRequest) (r *EchoResponse, err error) { + var _args EchoServiceEchoPingPongArgs + _args.Req1 = req1 + _args.Req2 = req2 + var _result EchoServiceEchoPingPongResult + if err = p.Client_().Call(ctx, "EchoPingPong", &_args, &_result); err != nil { + return + } + switch { + case _result.E != nil: + return r, _result.E + } + return _result.GetSuccess(), nil +} +func (p *EchoServiceClient) EchoOneway(ctx context.Context, req1 *EchoRequest) (err error) { + var _args EchoServiceEchoOnewayArgs + _args.Req1 = req1 + var _result EchoServiceEchoOnewayResult + if err = p.Client_().Call(ctx, "EchoOneway", &_args, &_result); err != nil { + return + } + return nil +} +func (p *EchoServiceClient) Ping(ctx context.Context) (err error) { + var _args EchoServicePingArgs + var _result EchoServicePingResult + if err = p.Client_().Call(ctx, "Ping", &_args, &_result); err != nil { + return + } + return nil +} + +type EchoServiceProcessor struct { + processorMap map[string]thrift.TProcessorFunction + handler EchoService +} + +func (p *EchoServiceProcessor) AddToProcessorMap(key string, processor thrift.TProcessorFunction) { + p.processorMap[key] = processor +} + +func (p *EchoServiceProcessor) GetProcessorFunction(key string) (processor thrift.TProcessorFunction, ok bool) { + processor, ok = p.processorMap[key] + return processor, ok +} + +func (p *EchoServiceProcessor) ProcessorMap() map[string]thrift.TProcessorFunction { + return p.processorMap +} + +func NewEchoServiceProcessor(handler EchoService) *EchoServiceProcessor { + self := &EchoServiceProcessor{handler: handler, processorMap: make(map[string]thrift.TProcessorFunction)} + self.AddToProcessorMap("EchoPingPong", &echoServiceProcessorEchoPingPong{handler: handler}) + self.AddToProcessorMap("EchoOneway", &echoServiceProcessorEchoOneway{handler: handler}) + self.AddToProcessorMap("Ping", &echoServiceProcessorPing{handler: handler}) + return self +} +func (p *EchoServiceProcessor) Process(ctx context.Context, iprot, oprot thrift.TProtocol) (success bool, err thrift.TException) { + name, _, seqId, err := iprot.ReadMessageBegin() + if err != nil { + return false, err + } + if processor, ok := p.GetProcessorFunction(name); ok { + return processor.Process(ctx, seqId, iprot, oprot) + } + iprot.Skip(thrift.STRUCT) + iprot.ReadMessageEnd() + x := thrift.NewTApplicationException(thrift.UNKNOWN_METHOD, "Unknown function "+name) + oprot.WriteMessageBegin(name, thrift.EXCEPTION, seqId) + x.Write(oprot) + oprot.WriteMessageEnd() + oprot.Flush(ctx) + return false, x +} + +type echoServiceProcessorEchoPingPong struct { + handler EchoService +} + +func (p *echoServiceProcessorEchoPingPong) Process(ctx context.Context, seqId int32, iprot, oprot thrift.TProtocol) (success bool, err thrift.TException) { + args := EchoServiceEchoPingPongArgs{} + if err = args.Read(iprot); err != nil { + iprot.ReadMessageEnd() + x := thrift.NewTApplicationException(thrift.PROTOCOL_ERROR, err.Error()) + oprot.WriteMessageBegin("EchoPingPong", thrift.EXCEPTION, seqId) + x.Write(oprot) + oprot.WriteMessageEnd() + oprot.Flush(ctx) + return false, err + } + + iprot.ReadMessageEnd() + var err2 error + result := EchoServiceEchoPingPongResult{} + var retval *EchoResponse + if retval, err2 = p.handler.EchoPingPong(ctx, args.Req1, args.Req2); err2 != nil { + switch v := err2.(type) { + case *EchoException: + result.E = v + default: + x := thrift.NewTApplicationException(thrift.INTERNAL_ERROR, "Internal error processing EchoPingPong: "+err2.Error()) + oprot.WriteMessageBegin("EchoPingPong", thrift.EXCEPTION, seqId) + x.Write(oprot) + oprot.WriteMessageEnd() + oprot.Flush(ctx) + return true, err2 + } + } else { + result.Success = retval + } + if err2 = oprot.WriteMessageBegin("EchoPingPong", thrift.REPLY, seqId); err2 != nil { + err = err2 + } + if err2 = result.Write(oprot); err == nil && err2 != nil { + err = err2 + } + if err2 = oprot.WriteMessageEnd(); err == nil && err2 != nil { + err = err2 + } + if err2 = oprot.Flush(ctx); err == nil && err2 != nil { + err = err2 + } + if err != nil { + return + } + return true, err +} + +type echoServiceProcessorEchoOneway struct { + handler EchoService +} + +func (p *echoServiceProcessorEchoOneway) Process(ctx context.Context, seqId int32, iprot, oprot thrift.TProtocol) (success bool, err thrift.TException) { + args := EchoServiceEchoOnewayArgs{} + if err = args.Read(iprot); err != nil { + iprot.ReadMessageEnd() + x := thrift.NewTApplicationException(thrift.PROTOCOL_ERROR, err.Error()) + oprot.WriteMessageBegin("EchoOneway", thrift.EXCEPTION, seqId) + x.Write(oprot) + oprot.WriteMessageEnd() + oprot.Flush(ctx) + return false, err + } + + iprot.ReadMessageEnd() + var err2 error + result := EchoServiceEchoOnewayResult{} + if err2 = p.handler.EchoOneway(ctx, args.Req1); err2 != nil { + x := thrift.NewTApplicationException(thrift.INTERNAL_ERROR, "Internal error processing EchoOneway: "+err2.Error()) + oprot.WriteMessageBegin("EchoOneway", thrift.EXCEPTION, seqId) + x.Write(oprot) + oprot.WriteMessageEnd() + oprot.Flush(ctx) + return true, err2 + } + if err2 = oprot.WriteMessageBegin("EchoOneway", thrift.REPLY, seqId); err2 != nil { + err = err2 + } + if err2 = result.Write(oprot); err == nil && err2 != nil { + err = err2 + } + if err2 = oprot.WriteMessageEnd(); err == nil && err2 != nil { + err = err2 + } + if err2 = oprot.Flush(ctx); err == nil && err2 != nil { + err = err2 + } + if err != nil { + return + } + return true, err +} + +type echoServiceProcessorPing struct { + handler EchoService +} + +func (p *echoServiceProcessorPing) Process(ctx context.Context, seqId int32, iprot, oprot thrift.TProtocol) (success bool, err thrift.TException) { + args := EchoServicePingArgs{} + if err = args.Read(iprot); err != nil { + iprot.ReadMessageEnd() + x := thrift.NewTApplicationException(thrift.PROTOCOL_ERROR, err.Error()) + oprot.WriteMessageBegin("Ping", thrift.EXCEPTION, seqId) + x.Write(oprot) + oprot.WriteMessageEnd() + oprot.Flush(ctx) + return false, err + } + + iprot.ReadMessageEnd() + var err2 error + result := EchoServicePingResult{} + if err2 = p.handler.Ping(ctx); err2 != nil { + x := thrift.NewTApplicationException(thrift.INTERNAL_ERROR, "Internal error processing Ping: "+err2.Error()) + oprot.WriteMessageBegin("Ping", thrift.EXCEPTION, seqId) + x.Write(oprot) + oprot.WriteMessageEnd() + oprot.Flush(ctx) + return true, err2 + } + if err2 = oprot.WriteMessageBegin("Ping", thrift.REPLY, seqId); err2 != nil { + err = err2 + } + if err2 = result.Write(oprot); err == nil && err2 != nil { + err = err2 + } + if err2 = oprot.WriteMessageEnd(); err == nil && err2 != nil { + err = err2 + } + if err2 = oprot.Flush(ctx); err == nil && err2 != nil { + err = err2 + } + if err != nil { + return + } + return true, err +} + +type EchoServiceEchoPingPongArgs struct { + Req1 *EchoRequest `thrift:"req1,1" frugal:"1,default,EchoRequest" json:"req1"` + Req2 *EchoRequest `thrift:"req2,2" frugal:"2,default,EchoRequest" json:"req2"` +} + +func NewEchoServiceEchoPingPongArgs() *EchoServiceEchoPingPongArgs { + return &EchoServiceEchoPingPongArgs{} +} + +func (p *EchoServiceEchoPingPongArgs) InitDefault() { + *p = EchoServiceEchoPingPongArgs{} +} + +var EchoServiceEchoPingPongArgs_Req1_DEFAULT *EchoRequest + +func (p *EchoServiceEchoPingPongArgs) GetReq1() (v *EchoRequest) { + if !p.IsSetReq1() { + return EchoServiceEchoPingPongArgs_Req1_DEFAULT + } + return p.Req1 +} + +var EchoServiceEchoPingPongArgs_Req2_DEFAULT *EchoRequest + +func (p *EchoServiceEchoPingPongArgs) GetReq2() (v *EchoRequest) { + if !p.IsSetReq2() { + return EchoServiceEchoPingPongArgs_Req2_DEFAULT + } + return p.Req2 +} +func (p *EchoServiceEchoPingPongArgs) SetReq1(val *EchoRequest) { + p.Req1 = val +} +func (p *EchoServiceEchoPingPongArgs) SetReq2(val *EchoRequest) { + p.Req2 = val +} + +var fieldIDToName_EchoServiceEchoPingPongArgs = map[int16]string{ + 1: "req1", + 2: "req2", +} + +func (p *EchoServiceEchoPingPongArgs) IsSetReq1() bool { + return p.Req1 != nil +} + +func (p *EchoServiceEchoPingPongArgs) IsSetReq2() bool { + return p.Req2 != nil +} + +func (p *EchoServiceEchoPingPongArgs) Read(iprot thrift.TProtocol) (err error) { + + var fieldTypeId thrift.TType + var fieldId int16 + + if _, err = iprot.ReadStructBegin(); err != nil { + goto ReadStructBeginError + } + + for { + _, fieldTypeId, fieldId, err = iprot.ReadFieldBegin() + if err != nil { + goto ReadFieldBeginError + } + if fieldTypeId == thrift.STOP { + break + } + + switch fieldId { + case 1: + if fieldTypeId == thrift.STRUCT { + if err = p.ReadField1(iprot); err != nil { + goto ReadFieldError + } + } else if err = iprot.Skip(fieldTypeId); err != nil { + goto SkipFieldError + } + case 2: + if fieldTypeId == thrift.STRUCT { + if err = p.ReadField2(iprot); err != nil { + goto ReadFieldError + } + } else if err = iprot.Skip(fieldTypeId); err != nil { + goto SkipFieldError + } + default: + if err = iprot.Skip(fieldTypeId); err != nil { + goto SkipFieldError + } + } + if err = iprot.ReadFieldEnd(); err != nil { + goto ReadFieldEndError + } + } + if err = iprot.ReadStructEnd(); err != nil { + goto ReadStructEndError + } + + return nil +ReadStructBeginError: + return thrift.PrependError(fmt.Sprintf("%T read struct begin error: ", p), err) +ReadFieldBeginError: + return thrift.PrependError(fmt.Sprintf("%T read field %d begin error: ", p, fieldId), err) +ReadFieldError: + return thrift.PrependError(fmt.Sprintf("%T read field %d '%s' error: ", p, fieldId, fieldIDToName_EchoServiceEchoPingPongArgs[fieldId]), err) +SkipFieldError: + return thrift.PrependError(fmt.Sprintf("%T field %d skip type %d error: ", p, fieldId, fieldTypeId), err) + +ReadFieldEndError: + return thrift.PrependError(fmt.Sprintf("%T read field end error", p), err) +ReadStructEndError: + return thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err) +} + +func (p *EchoServiceEchoPingPongArgs) ReadField1(iprot thrift.TProtocol) error { + p.Req1 = NewEchoRequest() + if err := p.Req1.Read(iprot); err != nil { + return err + } + return nil +} +func (p *EchoServiceEchoPingPongArgs) ReadField2(iprot thrift.TProtocol) error { + p.Req2 = NewEchoRequest() + if err := p.Req2.Read(iprot); err != nil { + return err + } + return nil +} + +func (p *EchoServiceEchoPingPongArgs) Write(oprot thrift.TProtocol) (err error) { + var fieldId int16 + if err = oprot.WriteStructBegin("EchoPingPong_args"); err != nil { + goto WriteStructBeginError + } + if p != nil { + if err = p.writeField1(oprot); err != nil { + fieldId = 1 + goto WriteFieldError + } + if err = p.writeField2(oprot); err != nil { + fieldId = 2 + goto WriteFieldError + } + } + if err = oprot.WriteFieldStop(); err != nil { + goto WriteFieldStopError + } + if err = oprot.WriteStructEnd(); err != nil { + goto WriteStructEndError + } + return nil +WriteStructBeginError: + return thrift.PrependError(fmt.Sprintf("%T write struct begin error: ", p), err) +WriteFieldError: + return thrift.PrependError(fmt.Sprintf("%T write field %d error: ", p, fieldId), err) +WriteFieldStopError: + return thrift.PrependError(fmt.Sprintf("%T write field stop error: ", p), err) +WriteStructEndError: + return thrift.PrependError(fmt.Sprintf("%T write struct end error: ", p), err) +} + +func (p *EchoServiceEchoPingPongArgs) writeField1(oprot thrift.TProtocol) (err error) { + if err = oprot.WriteFieldBegin("req1", thrift.STRUCT, 1); err != nil { + goto WriteFieldBeginError + } + if err := p.Req1.Write(oprot); err != nil { + return err + } + if err = oprot.WriteFieldEnd(); err != nil { + goto WriteFieldEndError + } + return nil +WriteFieldBeginError: + return thrift.PrependError(fmt.Sprintf("%T write field 1 begin error: ", p), err) +WriteFieldEndError: + return thrift.PrependError(fmt.Sprintf("%T write field 1 end error: ", p), err) +} + +func (p *EchoServiceEchoPingPongArgs) writeField2(oprot thrift.TProtocol) (err error) { + if err = oprot.WriteFieldBegin("req2", thrift.STRUCT, 2); err != nil { + goto WriteFieldBeginError + } + if err := p.Req2.Write(oprot); err != nil { + return err + } + if err = oprot.WriteFieldEnd(); err != nil { + goto WriteFieldEndError + } + return nil +WriteFieldBeginError: + return thrift.PrependError(fmt.Sprintf("%T write field 2 begin error: ", p), err) +WriteFieldEndError: + return thrift.PrependError(fmt.Sprintf("%T write field 2 end error: ", p), err) +} + +func (p *EchoServiceEchoPingPongArgs) String() string { + if p == nil { + return "" + } + return fmt.Sprintf("EchoServiceEchoPingPongArgs(%+v)", *p) + +} + +func (p *EchoServiceEchoPingPongArgs) DeepEqual(ano *EchoServiceEchoPingPongArgs) bool { + if p == ano { + return true + } else if p == nil || ano == nil { + return false + } + if !p.Field1DeepEqual(ano.Req1) { + return false + } + if !p.Field2DeepEqual(ano.Req2) { + return false + } + return true +} + +func (p *EchoServiceEchoPingPongArgs) Field1DeepEqual(src *EchoRequest) bool { + + if !p.Req1.DeepEqual(src) { + return false + } + return true +} +func (p *EchoServiceEchoPingPongArgs) Field2DeepEqual(src *EchoRequest) bool { + + if !p.Req2.DeepEqual(src) { + return false + } + return true +} + +type EchoServiceEchoPingPongResult struct { + Success *EchoResponse `thrift:"success,0,optional" frugal:"0,optional,EchoResponse" json:"success,omitempty"` + E *EchoException `thrift:"e,1,optional" frugal:"1,optional,EchoException" json:"e,omitempty"` +} + +func NewEchoServiceEchoPingPongResult() *EchoServiceEchoPingPongResult { + return &EchoServiceEchoPingPongResult{} +} + +func (p *EchoServiceEchoPingPongResult) InitDefault() { + *p = EchoServiceEchoPingPongResult{} +} + +var EchoServiceEchoPingPongResult_Success_DEFAULT *EchoResponse + +func (p *EchoServiceEchoPingPongResult) GetSuccess() (v *EchoResponse) { + if !p.IsSetSuccess() { + return EchoServiceEchoPingPongResult_Success_DEFAULT + } + return p.Success +} + +var EchoServiceEchoPingPongResult_E_DEFAULT *EchoException + +func (p *EchoServiceEchoPingPongResult) GetE() (v *EchoException) { + if !p.IsSetE() { + return EchoServiceEchoPingPongResult_E_DEFAULT + } + return p.E +} +func (p *EchoServiceEchoPingPongResult) SetSuccess(x interface{}) { + p.Success = x.(*EchoResponse) +} +func (p *EchoServiceEchoPingPongResult) SetE(val *EchoException) { + p.E = val +} + +var fieldIDToName_EchoServiceEchoPingPongResult = map[int16]string{ + 0: "success", + 1: "e", +} + +func (p *EchoServiceEchoPingPongResult) IsSetSuccess() bool { + return p.Success != nil +} + +func (p *EchoServiceEchoPingPongResult) IsSetE() bool { + return p.E != nil +} + +func (p *EchoServiceEchoPingPongResult) Read(iprot thrift.TProtocol) (err error) { + + var fieldTypeId thrift.TType + var fieldId int16 + + if _, err = iprot.ReadStructBegin(); err != nil { + goto ReadStructBeginError + } + + for { + _, fieldTypeId, fieldId, err = iprot.ReadFieldBegin() + if err != nil { + goto ReadFieldBeginError + } + if fieldTypeId == thrift.STOP { + break + } + + switch fieldId { + case 0: + if fieldTypeId == thrift.STRUCT { + if err = p.ReadField0(iprot); err != nil { + goto ReadFieldError + } + } else if err = iprot.Skip(fieldTypeId); err != nil { + goto SkipFieldError + } + case 1: + if fieldTypeId == thrift.STRUCT { + if err = p.ReadField1(iprot); err != nil { + goto ReadFieldError + } + } else if err = iprot.Skip(fieldTypeId); err != nil { + goto SkipFieldError + } + default: + if err = iprot.Skip(fieldTypeId); err != nil { + goto SkipFieldError + } + } + if err = iprot.ReadFieldEnd(); err != nil { + goto ReadFieldEndError + } + } + if err = iprot.ReadStructEnd(); err != nil { + goto ReadStructEndError + } + + return nil +ReadStructBeginError: + return thrift.PrependError(fmt.Sprintf("%T read struct begin error: ", p), err) +ReadFieldBeginError: + return thrift.PrependError(fmt.Sprintf("%T read field %d begin error: ", p, fieldId), err) +ReadFieldError: + return thrift.PrependError(fmt.Sprintf("%T read field %d '%s' error: ", p, fieldId, fieldIDToName_EchoServiceEchoPingPongResult[fieldId]), err) +SkipFieldError: + return thrift.PrependError(fmt.Sprintf("%T field %d skip type %d error: ", p, fieldId, fieldTypeId), err) + +ReadFieldEndError: + return thrift.PrependError(fmt.Sprintf("%T read field end error", p), err) +ReadStructEndError: + return thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err) +} + +func (p *EchoServiceEchoPingPongResult) ReadField0(iprot thrift.TProtocol) error { + p.Success = NewEchoResponse() + if err := p.Success.Read(iprot); err != nil { + return err + } + return nil +} +func (p *EchoServiceEchoPingPongResult) ReadField1(iprot thrift.TProtocol) error { + p.E = NewEchoException() + if err := p.E.Read(iprot); err != nil { + return err + } + return nil +} + +func (p *EchoServiceEchoPingPongResult) Write(oprot thrift.TProtocol) (err error) { + var fieldId int16 + if err = oprot.WriteStructBegin("EchoPingPong_result"); err != nil { + goto WriteStructBeginError + } + if p != nil { + if err = p.writeField0(oprot); err != nil { + fieldId = 0 + goto WriteFieldError + } + if err = p.writeField1(oprot); err != nil { + fieldId = 1 + goto WriteFieldError + } + } + if err = oprot.WriteFieldStop(); err != nil { + goto WriteFieldStopError + } + if err = oprot.WriteStructEnd(); err != nil { + goto WriteStructEndError + } + return nil +WriteStructBeginError: + return thrift.PrependError(fmt.Sprintf("%T write struct begin error: ", p), err) +WriteFieldError: + return thrift.PrependError(fmt.Sprintf("%T write field %d error: ", p, fieldId), err) +WriteFieldStopError: + return thrift.PrependError(fmt.Sprintf("%T write field stop error: ", p), err) +WriteStructEndError: + return thrift.PrependError(fmt.Sprintf("%T write struct end error: ", p), err) +} + +func (p *EchoServiceEchoPingPongResult) writeField0(oprot thrift.TProtocol) (err error) { + if p.IsSetSuccess() { + if err = oprot.WriteFieldBegin("success", thrift.STRUCT, 0); err != nil { + goto WriteFieldBeginError + } + if err := p.Success.Write(oprot); err != nil { + return err + } + if err = oprot.WriteFieldEnd(); err != nil { + goto WriteFieldEndError + } + } + return nil +WriteFieldBeginError: + return thrift.PrependError(fmt.Sprintf("%T write field 0 begin error: ", p), err) +WriteFieldEndError: + return thrift.PrependError(fmt.Sprintf("%T write field 0 end error: ", p), err) +} + +func (p *EchoServiceEchoPingPongResult) writeField1(oprot thrift.TProtocol) (err error) { + if p.IsSetE() { + if err = oprot.WriteFieldBegin("e", thrift.STRUCT, 1); err != nil { + goto WriteFieldBeginError + } + if err := p.E.Write(oprot); err != nil { + return err + } + if err = oprot.WriteFieldEnd(); err != nil { + goto WriteFieldEndError + } + } + return nil +WriteFieldBeginError: + return thrift.PrependError(fmt.Sprintf("%T write field 1 begin error: ", p), err) +WriteFieldEndError: + return thrift.PrependError(fmt.Sprintf("%T write field 1 end error: ", p), err) +} + +func (p *EchoServiceEchoPingPongResult) String() string { + if p == nil { + return "" + } + return fmt.Sprintf("EchoServiceEchoPingPongResult(%+v)", *p) + +} + +func (p *EchoServiceEchoPingPongResult) DeepEqual(ano *EchoServiceEchoPingPongResult) bool { + if p == ano { + return true + } else if p == nil || ano == nil { + return false + } + if !p.Field0DeepEqual(ano.Success) { + return false + } + if !p.Field1DeepEqual(ano.E) { + return false + } + return true +} + +func (p *EchoServiceEchoPingPongResult) Field0DeepEqual(src *EchoResponse) bool { + + if !p.Success.DeepEqual(src) { + return false + } + return true +} +func (p *EchoServiceEchoPingPongResult) Field1DeepEqual(src *EchoException) bool { + + if !p.E.DeepEqual(src) { + return false + } + return true +} + +type EchoServiceEchoOnewayArgs struct { + Req1 *EchoRequest `thrift:"req1,1" frugal:"1,default,EchoRequest" json:"req1"` +} + +func NewEchoServiceEchoOnewayArgs() *EchoServiceEchoOnewayArgs { + return &EchoServiceEchoOnewayArgs{} +} + +func (p *EchoServiceEchoOnewayArgs) InitDefault() { + *p = EchoServiceEchoOnewayArgs{} +} + +var EchoServiceEchoOnewayArgs_Req1_DEFAULT *EchoRequest + +func (p *EchoServiceEchoOnewayArgs) GetReq1() (v *EchoRequest) { + if !p.IsSetReq1() { + return EchoServiceEchoOnewayArgs_Req1_DEFAULT + } + return p.Req1 +} +func (p *EchoServiceEchoOnewayArgs) SetReq1(val *EchoRequest) { + p.Req1 = val +} + +var fieldIDToName_EchoServiceEchoOnewayArgs = map[int16]string{ + 1: "req1", +} + +func (p *EchoServiceEchoOnewayArgs) IsSetReq1() bool { + return p.Req1 != nil +} + +func (p *EchoServiceEchoOnewayArgs) Read(iprot thrift.TProtocol) (err error) { + + var fieldTypeId thrift.TType + var fieldId int16 + + if _, err = iprot.ReadStructBegin(); err != nil { + goto ReadStructBeginError + } + + for { + _, fieldTypeId, fieldId, err = iprot.ReadFieldBegin() + if err != nil { + goto ReadFieldBeginError + } + if fieldTypeId == thrift.STOP { + break + } + + switch fieldId { + case 1: + if fieldTypeId == thrift.STRUCT { + if err = p.ReadField1(iprot); err != nil { + goto ReadFieldError + } + } else if err = iprot.Skip(fieldTypeId); err != nil { + goto SkipFieldError + } + default: + if err = iprot.Skip(fieldTypeId); err != nil { + goto SkipFieldError + } + } + if err = iprot.ReadFieldEnd(); err != nil { + goto ReadFieldEndError + } + } + if err = iprot.ReadStructEnd(); err != nil { + goto ReadStructEndError + } + + return nil +ReadStructBeginError: + return thrift.PrependError(fmt.Sprintf("%T read struct begin error: ", p), err) +ReadFieldBeginError: + return thrift.PrependError(fmt.Sprintf("%T read field %d begin error: ", p, fieldId), err) +ReadFieldError: + return thrift.PrependError(fmt.Sprintf("%T read field %d '%s' error: ", p, fieldId, fieldIDToName_EchoServiceEchoOnewayArgs[fieldId]), err) +SkipFieldError: + return thrift.PrependError(fmt.Sprintf("%T field %d skip type %d error: ", p, fieldId, fieldTypeId), err) + +ReadFieldEndError: + return thrift.PrependError(fmt.Sprintf("%T read field end error", p), err) +ReadStructEndError: + return thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err) +} + +func (p *EchoServiceEchoOnewayArgs) ReadField1(iprot thrift.TProtocol) error { + p.Req1 = NewEchoRequest() + if err := p.Req1.Read(iprot); err != nil { + return err + } + return nil +} + +func (p *EchoServiceEchoOnewayArgs) Write(oprot thrift.TProtocol) (err error) { + var fieldId int16 + if err = oprot.WriteStructBegin("EchoOneway_args"); err != nil { + goto WriteStructBeginError + } + if p != nil { + if err = p.writeField1(oprot); err != nil { + fieldId = 1 + goto WriteFieldError + } + } + if err = oprot.WriteFieldStop(); err != nil { + goto WriteFieldStopError + } + if err = oprot.WriteStructEnd(); err != nil { + goto WriteStructEndError + } + return nil +WriteStructBeginError: + return thrift.PrependError(fmt.Sprintf("%T write struct begin error: ", p), err) +WriteFieldError: + return thrift.PrependError(fmt.Sprintf("%T write field %d error: ", p, fieldId), err) +WriteFieldStopError: + return thrift.PrependError(fmt.Sprintf("%T write field stop error: ", p), err) +WriteStructEndError: + return thrift.PrependError(fmt.Sprintf("%T write struct end error: ", p), err) +} + +func (p *EchoServiceEchoOnewayArgs) writeField1(oprot thrift.TProtocol) (err error) { + if err = oprot.WriteFieldBegin("req1", thrift.STRUCT, 1); err != nil { + goto WriteFieldBeginError + } + if err := p.Req1.Write(oprot); err != nil { + return err + } + if err = oprot.WriteFieldEnd(); err != nil { + goto WriteFieldEndError + } + return nil +WriteFieldBeginError: + return thrift.PrependError(fmt.Sprintf("%T write field 1 begin error: ", p), err) +WriteFieldEndError: + return thrift.PrependError(fmt.Sprintf("%T write field 1 end error: ", p), err) +} + +func (p *EchoServiceEchoOnewayArgs) String() string { + if p == nil { + return "" + } + return fmt.Sprintf("EchoServiceEchoOnewayArgs(%+v)", *p) + +} + +func (p *EchoServiceEchoOnewayArgs) DeepEqual(ano *EchoServiceEchoOnewayArgs) bool { + if p == ano { + return true + } else if p == nil || ano == nil { + return false + } + if !p.Field1DeepEqual(ano.Req1) { + return false + } + return true +} + +func (p *EchoServiceEchoOnewayArgs) Field1DeepEqual(src *EchoRequest) bool { + + if !p.Req1.DeepEqual(src) { + return false + } + return true +} + +type EchoServiceEchoOnewayResult struct { +} + +func NewEchoServiceEchoOnewayResult() *EchoServiceEchoOnewayResult { + return &EchoServiceEchoOnewayResult{} +} + +func (p *EchoServiceEchoOnewayResult) InitDefault() { + *p = EchoServiceEchoOnewayResult{} +} + +var fieldIDToName_EchoServiceEchoOnewayResult = map[int16]string{} + +func (p *EchoServiceEchoOnewayResult) Read(iprot thrift.TProtocol) (err error) { + + var fieldTypeId thrift.TType + var fieldId int16 + + if _, err = iprot.ReadStructBegin(); err != nil { + goto ReadStructBeginError + } + + for { + _, fieldTypeId, fieldId, err = iprot.ReadFieldBegin() + if err != nil { + goto ReadFieldBeginError + } + if fieldTypeId == thrift.STOP { + break + } + if err = iprot.Skip(fieldTypeId); err != nil { + goto SkipFieldTypeError + } + if err = iprot.ReadFieldEnd(); err != nil { + goto ReadFieldEndError + } + } + if err = iprot.ReadStructEnd(); err != nil { + goto ReadStructEndError + } + + return nil +ReadStructBeginError: + return thrift.PrependError(fmt.Sprintf("%T read struct begin error: ", p), err) +ReadFieldBeginError: + return thrift.PrependError(fmt.Sprintf("%T read field %d begin error: ", p, fieldId), err) +SkipFieldTypeError: + return thrift.PrependError(fmt.Sprintf("%T skip field type %d error", p, fieldTypeId), err) + +ReadFieldEndError: + return thrift.PrependError(fmt.Sprintf("%T read field end error", p), err) +ReadStructEndError: + return thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err) +} + +func (p *EchoServiceEchoOnewayResult) Write(oprot thrift.TProtocol) (err error) { + if err = oprot.WriteStructBegin("EchoOneway_result"); err != nil { + goto WriteStructBeginError + } + if p != nil { + } + if err = oprot.WriteFieldStop(); err != nil { + goto WriteFieldStopError + } + if err = oprot.WriteStructEnd(); err != nil { + goto WriteStructEndError + } + return nil +WriteStructBeginError: + return thrift.PrependError(fmt.Sprintf("%T write struct begin error: ", p), err) +WriteFieldStopError: + return thrift.PrependError(fmt.Sprintf("%T write field stop error: ", p), err) +WriteStructEndError: + return thrift.PrependError(fmt.Sprintf("%T write struct end error: ", p), err) +} + +func (p *EchoServiceEchoOnewayResult) String() string { + if p == nil { + return "" + } + return fmt.Sprintf("EchoServiceEchoOnewayResult(%+v)", *p) + +} + +func (p *EchoServiceEchoOnewayResult) DeepEqual(ano *EchoServiceEchoOnewayResult) bool { + if p == ano { + return true + } else if p == nil || ano == nil { + return false + } + return true +} + +type EchoServicePingArgs struct { +} + +func NewEchoServicePingArgs() *EchoServicePingArgs { + return &EchoServicePingArgs{} +} + +func (p *EchoServicePingArgs) InitDefault() { + *p = EchoServicePingArgs{} +} + +var fieldIDToName_EchoServicePingArgs = map[int16]string{} + +func (p *EchoServicePingArgs) Read(iprot thrift.TProtocol) (err error) { + + var fieldTypeId thrift.TType + var fieldId int16 + + if _, err = iprot.ReadStructBegin(); err != nil { + goto ReadStructBeginError + } + + for { + _, fieldTypeId, fieldId, err = iprot.ReadFieldBegin() + if err != nil { + goto ReadFieldBeginError + } + if fieldTypeId == thrift.STOP { + break + } + if err = iprot.Skip(fieldTypeId); err != nil { + goto SkipFieldTypeError + } + if err = iprot.ReadFieldEnd(); err != nil { + goto ReadFieldEndError + } + } + if err = iprot.ReadStructEnd(); err != nil { + goto ReadStructEndError + } + + return nil +ReadStructBeginError: + return thrift.PrependError(fmt.Sprintf("%T read struct begin error: ", p), err) +ReadFieldBeginError: + return thrift.PrependError(fmt.Sprintf("%T read field %d begin error: ", p, fieldId), err) +SkipFieldTypeError: + return thrift.PrependError(fmt.Sprintf("%T skip field type %d error", p, fieldTypeId), err) + +ReadFieldEndError: + return thrift.PrependError(fmt.Sprintf("%T read field end error", p), err) +ReadStructEndError: + return thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err) +} + +func (p *EchoServicePingArgs) Write(oprot thrift.TProtocol) (err error) { + if err = oprot.WriteStructBegin("Ping_args"); err != nil { + goto WriteStructBeginError + } + if p != nil { + } + if err = oprot.WriteFieldStop(); err != nil { + goto WriteFieldStopError + } + if err = oprot.WriteStructEnd(); err != nil { + goto WriteStructEndError + } + return nil +WriteStructBeginError: + return thrift.PrependError(fmt.Sprintf("%T write struct begin error: ", p), err) +WriteFieldStopError: + return thrift.PrependError(fmt.Sprintf("%T write field stop error: ", p), err) +WriteStructEndError: + return thrift.PrependError(fmt.Sprintf("%T write struct end error: ", p), err) +} + +func (p *EchoServicePingArgs) String() string { + if p == nil { + return "" + } + return fmt.Sprintf("EchoServicePingArgs(%+v)", *p) + +} + +func (p *EchoServicePingArgs) DeepEqual(ano *EchoServicePingArgs) bool { + if p == ano { + return true + } else if p == nil || ano == nil { + return false + } + return true +} + +type EchoServicePingResult struct { +} + +func NewEchoServicePingResult() *EchoServicePingResult { + return &EchoServicePingResult{} +} + +func (p *EchoServicePingResult) InitDefault() { + *p = EchoServicePingResult{} +} + +var fieldIDToName_EchoServicePingResult = map[int16]string{} + +func (p *EchoServicePingResult) Read(iprot thrift.TProtocol) (err error) { + + var fieldTypeId thrift.TType + var fieldId int16 + + if _, err = iprot.ReadStructBegin(); err != nil { + goto ReadStructBeginError + } + + for { + _, fieldTypeId, fieldId, err = iprot.ReadFieldBegin() + if err != nil { + goto ReadFieldBeginError + } + if fieldTypeId == thrift.STOP { + break + } + if err = iprot.Skip(fieldTypeId); err != nil { + goto SkipFieldTypeError + } + if err = iprot.ReadFieldEnd(); err != nil { + goto ReadFieldEndError + } + } + if err = iprot.ReadStructEnd(); err != nil { + goto ReadStructEndError + } + + return nil +ReadStructBeginError: + return thrift.PrependError(fmt.Sprintf("%T read struct begin error: ", p), err) +ReadFieldBeginError: + return thrift.PrependError(fmt.Sprintf("%T read field %d begin error: ", p, fieldId), err) +SkipFieldTypeError: + return thrift.PrependError(fmt.Sprintf("%T skip field type %d error", p, fieldTypeId), err) + +ReadFieldEndError: + return thrift.PrependError(fmt.Sprintf("%T read field end error", p), err) +ReadStructEndError: + return thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err) +} + +func (p *EchoServicePingResult) Write(oprot thrift.TProtocol) (err error) { + if err = oprot.WriteStructBegin("Ping_result"); err != nil { + goto WriteStructBeginError + } + if p != nil { + } + if err = oprot.WriteFieldStop(); err != nil { + goto WriteFieldStopError + } + if err = oprot.WriteStructEnd(); err != nil { + goto WriteStructEndError + } + return nil +WriteStructBeginError: + return thrift.PrependError(fmt.Sprintf("%T write struct begin error: ", p), err) +WriteFieldStopError: + return thrift.PrependError(fmt.Sprintf("%T write field stop error: ", p), err) +WriteStructEndError: + return thrift.PrependError(fmt.Sprintf("%T write struct end error: ", p), err) +} + +func (p *EchoServicePingResult) String() string { + if p == nil { + return "" + } + return fmt.Sprintf("EchoServicePingResult(%+v)", *p) + +} + +func (p *EchoServicePingResult) DeepEqual(ano *EchoServicePingResult) bool { + if p == ano { + return true + } else if p == nil || ano == nil { + return false + } + return true +} diff --git a/thrift_streaming/kitex_gen_cross/echo/echoservice/client.go b/thrift_streaming/kitex_gen_cross/echo/echoservice/client.go new file mode 100644 index 0000000..3c89408 --- /dev/null +++ b/thrift_streaming/kitex_gen_cross/echo/echoservice/client.go @@ -0,0 +1,61 @@ +// Code generated by Kitex v0.8.0. DO NOT EDIT. + +package echoservice + +import ( + "context" + echo "github.com/cloudwego/kitex-tests/thrift_streaming/kitex_gen_cross/echo" + client "github.com/cloudwego/kitex/client" + callopt "github.com/cloudwego/kitex/client/callopt" +) + +// Client is designed to provide IDL-compatible methods with call-option parameter for kitex framework. +type Client interface { + EchoPingPong(ctx context.Context, req1 *echo.EchoRequest, req2 *echo.EchoRequest, callOptions ...callopt.Option) (r *echo.EchoResponse, err error) + EchoOneway(ctx context.Context, req1 *echo.EchoRequest, callOptions ...callopt.Option) (err error) + Ping(ctx context.Context, callOptions ...callopt.Option) (err error) +} + +// NewClient creates a client for the service defined in IDL. +func NewClient(destService string, opts ...client.Option) (Client, error) { + var options []client.Option + options = append(options, client.WithDestService(destService)) + + options = append(options, opts...) + + kc, err := client.NewClient(serviceInfo(), options...) + if err != nil { + return nil, err + } + return &kEchoServiceClient{ + kClient: newServiceClient(kc), + }, nil +} + +// MustNewClient creates a client for the service defined in IDL. It panics if any error occurs. +func MustNewClient(destService string, opts ...client.Option) Client { + kc, err := NewClient(destService, opts...) + if err != nil { + panic(err) + } + return kc +} + +type kEchoServiceClient struct { + *kClient +} + +func (p *kEchoServiceClient) EchoPingPong(ctx context.Context, req1 *echo.EchoRequest, req2 *echo.EchoRequest, callOptions ...callopt.Option) (r *echo.EchoResponse, err error) { + ctx = client.NewCtxWithCallOptions(ctx, callOptions) + return p.kClient.EchoPingPong(ctx, req1, req2) +} + +func (p *kEchoServiceClient) EchoOneway(ctx context.Context, req1 *echo.EchoRequest, callOptions ...callopt.Option) (err error) { + ctx = client.NewCtxWithCallOptions(ctx, callOptions) + return p.kClient.EchoOneway(ctx, req1) +} + +func (p *kEchoServiceClient) Ping(ctx context.Context, callOptions ...callopt.Option) (err error) { + ctx = client.NewCtxWithCallOptions(ctx, callOptions) + return p.kClient.Ping(ctx) +} diff --git a/thrift_streaming/kitex_gen_cross/echo/echoservice/echoservice.go b/thrift_streaming/kitex_gen_cross/echo/echoservice/echoservice.go new file mode 100644 index 0000000..d99a961 --- /dev/null +++ b/thrift_streaming/kitex_gen_cross/echo/echoservice/echoservice.go @@ -0,0 +1,142 @@ +// Code generated by Kitex v0.8.0. DO NOT EDIT. + +package echoservice + +import ( + "context" + echo "github.com/cloudwego/kitex-tests/thrift_streaming/kitex_gen_cross/echo" + client "github.com/cloudwego/kitex/client" + kitex "github.com/cloudwego/kitex/pkg/serviceinfo" +) + +func serviceInfo() *kitex.ServiceInfo { + return echoServiceServiceInfo +} + +var echoServiceServiceInfo = NewServiceInfo() + +func NewServiceInfo() *kitex.ServiceInfo { + serviceName := "EchoService" + handlerType := (*echo.EchoService)(nil) + methods := map[string]kitex.MethodInfo{ + "EchoPingPong": kitex.NewMethodInfo(echoPingPongHandler, newEchoServiceEchoPingPongArgs, newEchoServiceEchoPingPongResult, false), + "EchoOneway": kitex.NewMethodInfo(echoOnewayHandler, newEchoServiceEchoOnewayArgs, newEchoServiceEchoOnewayResult, false), + "Ping": kitex.NewMethodInfo(pingHandler, newEchoServicePingArgs, newEchoServicePingResult, false), + } + extra := map[string]interface{}{ + "PackageName": "echo", + "ServiceFilePath": `idl/api.thrift`, + } + svcInfo := &kitex.ServiceInfo{ + ServiceName: serviceName, + HandlerType: handlerType, + Methods: methods, + PayloadCodec: kitex.Thrift, + KiteXGenVersion: "v0.8.0", + Extra: extra, + } + return svcInfo +} + +func echoPingPongHandler(ctx context.Context, handler interface{}, arg, result interface{}) error { + realArg := arg.(*echo.EchoServiceEchoPingPongArgs) + realResult := result.(*echo.EchoServiceEchoPingPongResult) + success, err := handler.(echo.EchoService).EchoPingPong(ctx, realArg.Req1, realArg.Req2) + if err != nil { + switch v := err.(type) { + case *echo.EchoException: + realResult.E = v + default: + return err + } + } else { + realResult.Success = success + } + return nil +} +func newEchoServiceEchoPingPongArgs() interface{} { + return echo.NewEchoServiceEchoPingPongArgs() +} + +func newEchoServiceEchoPingPongResult() interface{} { + return echo.NewEchoServiceEchoPingPongResult() +} + +func echoOnewayHandler(ctx context.Context, handler interface{}, arg, result interface{}) error { + realArg := arg.(*echo.EchoServiceEchoOnewayArgs) + + err := handler.(echo.EchoService).EchoOneway(ctx, realArg.Req1) + if err != nil { + return err + } + + return nil +} +func newEchoServiceEchoOnewayArgs() interface{} { + return echo.NewEchoServiceEchoOnewayArgs() +} + +func newEchoServiceEchoOnewayResult() interface{} { + return echo.NewEchoServiceEchoOnewayResult() +} + +func pingHandler(ctx context.Context, handler interface{}, arg, result interface{}) error { + + err := handler.(echo.EchoService).Ping(ctx) + if err != nil { + return err + } + + return nil +} +func newEchoServicePingArgs() interface{} { + return echo.NewEchoServicePingArgs() +} + +func newEchoServicePingResult() interface{} { + return echo.NewEchoServicePingResult() +} + +type kClient struct { + c client.Client +} + +func newServiceClient(c client.Client) *kClient { + return &kClient{ + c: c, + } +} + +func (p *kClient) EchoPingPong(ctx context.Context, req1 *echo.EchoRequest, req2 *echo.EchoRequest) (r *echo.EchoResponse, err error) { + var _args echo.EchoServiceEchoPingPongArgs + _args.Req1 = req1 + _args.Req2 = req2 + var _result echo.EchoServiceEchoPingPongResult + if err = p.c.Call(ctx, "EchoPingPong", &_args, &_result); err != nil { + return + } + switch { + case _result.E != nil: + return r, _result.E + } + return _result.GetSuccess(), nil +} + +func (p *kClient) EchoOneway(ctx context.Context, req1 *echo.EchoRequest) (err error) { + var _args echo.EchoServiceEchoOnewayArgs + _args.Req1 = req1 + var _result echo.EchoServiceEchoOnewayResult + if err = p.c.Call(ctx, "EchoOneway", &_args, &_result); err != nil { + return + } + return nil +} + +func (p *kClient) Ping(ctx context.Context) (err error) { + var _args echo.EchoServicePingArgs + var _result echo.EchoServicePingResult + if err = p.c.Call(ctx, "Ping", &_args, &_result); err != nil { + return + } + return nil +} diff --git a/thrift_streaming/kitex_gen_cross/echo/echoservice/invoker.go b/thrift_streaming/kitex_gen_cross/echo/echoservice/invoker.go new file mode 100644 index 0000000..dff9d77 --- /dev/null +++ b/thrift_streaming/kitex_gen_cross/echo/echoservice/invoker.go @@ -0,0 +1,24 @@ +// Code generated by Kitex v0.8.0. DO NOT EDIT. + +package echoservice + +import ( + echo "github.com/cloudwego/kitex-tests/thrift_streaming/kitex_gen_cross/echo" + server "github.com/cloudwego/kitex/server" +) + +// NewInvoker creates a server.Invoker with the given handler and options. +func NewInvoker(handler echo.EchoService, opts ...server.Option) server.Invoker { + var options []server.Option + + options = append(options, opts...) + + s := server.NewInvoker(options...) + if err := s.RegisterService(serviceInfo(), handler); err != nil { + panic(err) + } + if err := s.Init(); err != nil { + panic(err) + } + return s +} diff --git a/thrift_streaming/kitex_gen_cross/echo/echoservice/server.go b/thrift_streaming/kitex_gen_cross/echo/echoservice/server.go new file mode 100644 index 0000000..6b82db9 --- /dev/null +++ b/thrift_streaming/kitex_gen_cross/echo/echoservice/server.go @@ -0,0 +1,20 @@ +// Code generated by Kitex v0.8.0. DO NOT EDIT. +package echoservice + +import ( + echo "github.com/cloudwego/kitex-tests/thrift_streaming/kitex_gen_cross/echo" + server "github.com/cloudwego/kitex/server" +) + +// NewServer creates a server.Server with the given handler and options. +func NewServer(handler echo.EchoService, opts ...server.Option) server.Server { + var options []server.Option + + options = append(options, opts...) + + svr := server.NewServer(options...) + if err := svr.RegisterService(serviceInfo(), handler); err != nil { + panic(err) + } + return svr +} diff --git a/thrift_streaming/kitex_gen_cross/echo/k-api.go b/thrift_streaming/kitex_gen_cross/echo/k-api.go new file mode 100644 index 0000000..4715987 --- /dev/null +++ b/thrift_streaming/kitex_gen_cross/echo/k-api.go @@ -0,0 +1,1164 @@ +// Code generated by Kitex v0.8.0. DO NOT EDIT. + +package echo + +import ( + "bytes" + "fmt" + "reflect" + "strings" + + "github.com/apache/thrift/lib/go/thrift" + + "github.com/cloudwego/kitex/pkg/protocol/bthrift" +) + +// unused protection +var ( + _ = fmt.Formatter(nil) + _ = (*bytes.Buffer)(nil) + _ = (*strings.Builder)(nil) + _ = reflect.Type(nil) + _ = thrift.TProtocol(nil) + _ = bthrift.BinaryWriter(nil) +) + +func (p *EchoRequest) FastRead(buf []byte) (int, error) { + var err error + var offset int + var l int + var fieldTypeId thrift.TType + var fieldId int16 + var issetMessage bool = false + _, l, err = bthrift.Binary.ReadStructBegin(buf) + offset += l + if err != nil { + goto ReadStructBeginError + } + + for { + _, fieldTypeId, fieldId, l, err = bthrift.Binary.ReadFieldBegin(buf[offset:]) + offset += l + if err != nil { + goto ReadFieldBeginError + } + if fieldTypeId == thrift.STOP { + break + } + switch fieldId { + case 1: + if fieldTypeId == thrift.STRING { + l, err = p.FastReadField1(buf[offset:]) + offset += l + if err != nil { + goto ReadFieldError + } + issetMessage = true + } else { + l, err = bthrift.Binary.Skip(buf[offset:], fieldTypeId) + offset += l + if err != nil { + goto SkipFieldError + } + } + default: + l, err = bthrift.Binary.Skip(buf[offset:], fieldTypeId) + offset += l + if err != nil { + goto SkipFieldError + } + } + + l, err = bthrift.Binary.ReadFieldEnd(buf[offset:]) + offset += l + if err != nil { + goto ReadFieldEndError + } + } + l, err = bthrift.Binary.ReadStructEnd(buf[offset:]) + offset += l + if err != nil { + goto ReadStructEndError + } + + if !issetMessage { + fieldId = 1 + goto RequiredFieldNotSetError + } + return offset, nil +ReadStructBeginError: + return offset, thrift.PrependError(fmt.Sprintf("%T read struct begin error: ", p), err) +ReadFieldBeginError: + return offset, thrift.PrependError(fmt.Sprintf("%T read field %d begin error: ", p, fieldId), err) +ReadFieldError: + return offset, thrift.PrependError(fmt.Sprintf("%T read field %d '%s' error: ", p, fieldId, fieldIDToName_EchoRequest[fieldId]), err) +SkipFieldError: + return offset, thrift.PrependError(fmt.Sprintf("%T field %d skip type %d error: ", p, fieldId, fieldTypeId), err) +ReadFieldEndError: + return offset, thrift.PrependError(fmt.Sprintf("%T read field end error", p), err) +ReadStructEndError: + return offset, thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err) +RequiredFieldNotSetError: + return offset, thrift.NewTProtocolExceptionWithType(thrift.INVALID_DATA, fmt.Errorf("required field %s is not set", fieldIDToName_EchoRequest[fieldId])) +} + +func (p *EchoRequest) FastReadField1(buf []byte) (int, error) { + offset := 0 + + if v, l, err := bthrift.Binary.ReadString(buf[offset:]); err != nil { + return offset, err + } else { + offset += l + + p.Message = v + + } + return offset, nil +} + +// for compatibility +func (p *EchoRequest) FastWrite(buf []byte) int { + return 0 +} + +func (p *EchoRequest) FastWriteNocopy(buf []byte, binaryWriter bthrift.BinaryWriter) int { + offset := 0 + offset += bthrift.Binary.WriteStructBegin(buf[offset:], "EchoRequest") + if p != nil { + offset += p.fastWriteField1(buf[offset:], binaryWriter) + } + offset += bthrift.Binary.WriteFieldStop(buf[offset:]) + offset += bthrift.Binary.WriteStructEnd(buf[offset:]) + return offset +} + +func (p *EchoRequest) BLength() int { + l := 0 + l += bthrift.Binary.StructBeginLength("EchoRequest") + if p != nil { + l += p.field1Length() + } + l += bthrift.Binary.FieldStopLength() + l += bthrift.Binary.StructEndLength() + return l +} + +func (p *EchoRequest) fastWriteField1(buf []byte, binaryWriter bthrift.BinaryWriter) int { + offset := 0 + offset += bthrift.Binary.WriteFieldBegin(buf[offset:], "message", thrift.STRING, 1) + offset += bthrift.Binary.WriteStringNocopy(buf[offset:], binaryWriter, p.Message) + + offset += bthrift.Binary.WriteFieldEnd(buf[offset:]) + return offset +} + +func (p *EchoRequest) field1Length() int { + l := 0 + l += bthrift.Binary.FieldBeginLength("message", thrift.STRING, 1) + l += bthrift.Binary.StringLengthNocopy(p.Message) + + l += bthrift.Binary.FieldEndLength() + return l +} + +func (p *EchoResponse) FastRead(buf []byte) (int, error) { + var err error + var offset int + var l int + var fieldTypeId thrift.TType + var fieldId int16 + var issetMessage bool = false + _, l, err = bthrift.Binary.ReadStructBegin(buf) + offset += l + if err != nil { + goto ReadStructBeginError + } + + for { + _, fieldTypeId, fieldId, l, err = bthrift.Binary.ReadFieldBegin(buf[offset:]) + offset += l + if err != nil { + goto ReadFieldBeginError + } + if fieldTypeId == thrift.STOP { + break + } + switch fieldId { + case 1: + if fieldTypeId == thrift.STRING { + l, err = p.FastReadField1(buf[offset:]) + offset += l + if err != nil { + goto ReadFieldError + } + issetMessage = true + } else { + l, err = bthrift.Binary.Skip(buf[offset:], fieldTypeId) + offset += l + if err != nil { + goto SkipFieldError + } + } + default: + l, err = bthrift.Binary.Skip(buf[offset:], fieldTypeId) + offset += l + if err != nil { + goto SkipFieldError + } + } + + l, err = bthrift.Binary.ReadFieldEnd(buf[offset:]) + offset += l + if err != nil { + goto ReadFieldEndError + } + } + l, err = bthrift.Binary.ReadStructEnd(buf[offset:]) + offset += l + if err != nil { + goto ReadStructEndError + } + + if !issetMessage { + fieldId = 1 + goto RequiredFieldNotSetError + } + return offset, nil +ReadStructBeginError: + return offset, thrift.PrependError(fmt.Sprintf("%T read struct begin error: ", p), err) +ReadFieldBeginError: + return offset, thrift.PrependError(fmt.Sprintf("%T read field %d begin error: ", p, fieldId), err) +ReadFieldError: + return offset, thrift.PrependError(fmt.Sprintf("%T read field %d '%s' error: ", p, fieldId, fieldIDToName_EchoResponse[fieldId]), err) +SkipFieldError: + return offset, thrift.PrependError(fmt.Sprintf("%T field %d skip type %d error: ", p, fieldId, fieldTypeId), err) +ReadFieldEndError: + return offset, thrift.PrependError(fmt.Sprintf("%T read field end error", p), err) +ReadStructEndError: + return offset, thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err) +RequiredFieldNotSetError: + return offset, thrift.NewTProtocolExceptionWithType(thrift.INVALID_DATA, fmt.Errorf("required field %s is not set", fieldIDToName_EchoResponse[fieldId])) +} + +func (p *EchoResponse) FastReadField1(buf []byte) (int, error) { + offset := 0 + + if v, l, err := bthrift.Binary.ReadString(buf[offset:]); err != nil { + return offset, err + } else { + offset += l + + p.Message = v + + } + return offset, nil +} + +// for compatibility +func (p *EchoResponse) FastWrite(buf []byte) int { + return 0 +} + +func (p *EchoResponse) FastWriteNocopy(buf []byte, binaryWriter bthrift.BinaryWriter) int { + offset := 0 + offset += bthrift.Binary.WriteStructBegin(buf[offset:], "EchoResponse") + if p != nil { + offset += p.fastWriteField1(buf[offset:], binaryWriter) + } + offset += bthrift.Binary.WriteFieldStop(buf[offset:]) + offset += bthrift.Binary.WriteStructEnd(buf[offset:]) + return offset +} + +func (p *EchoResponse) BLength() int { + l := 0 + l += bthrift.Binary.StructBeginLength("EchoResponse") + if p != nil { + l += p.field1Length() + } + l += bthrift.Binary.FieldStopLength() + l += bthrift.Binary.StructEndLength() + return l +} + +func (p *EchoResponse) fastWriteField1(buf []byte, binaryWriter bthrift.BinaryWriter) int { + offset := 0 + offset += bthrift.Binary.WriteFieldBegin(buf[offset:], "message", thrift.STRING, 1) + offset += bthrift.Binary.WriteStringNocopy(buf[offset:], binaryWriter, p.Message) + + offset += bthrift.Binary.WriteFieldEnd(buf[offset:]) + return offset +} + +func (p *EchoResponse) field1Length() int { + l := 0 + l += bthrift.Binary.FieldBeginLength("message", thrift.STRING, 1) + l += bthrift.Binary.StringLengthNocopy(p.Message) + + l += bthrift.Binary.FieldEndLength() + return l +} + +func (p *EchoException) FastRead(buf []byte) (int, error) { + var err error + var offset int + var l int + var fieldTypeId thrift.TType + var fieldId int16 + _, l, err = bthrift.Binary.ReadStructBegin(buf) + offset += l + if err != nil { + goto ReadStructBeginError + } + + for { + _, fieldTypeId, fieldId, l, err = bthrift.Binary.ReadFieldBegin(buf[offset:]) + offset += l + if err != nil { + goto ReadFieldBeginError + } + if fieldTypeId == thrift.STOP { + break + } + switch fieldId { + case 1: + if fieldTypeId == thrift.STRING { + l, err = p.FastReadField1(buf[offset:]) + offset += l + if err != nil { + goto ReadFieldError + } + } else { + l, err = bthrift.Binary.Skip(buf[offset:], fieldTypeId) + offset += l + if err != nil { + goto SkipFieldError + } + } + default: + l, err = bthrift.Binary.Skip(buf[offset:], fieldTypeId) + offset += l + if err != nil { + goto SkipFieldError + } + } + + l, err = bthrift.Binary.ReadFieldEnd(buf[offset:]) + offset += l + if err != nil { + goto ReadFieldEndError + } + } + l, err = bthrift.Binary.ReadStructEnd(buf[offset:]) + offset += l + if err != nil { + goto ReadStructEndError + } + + return offset, nil +ReadStructBeginError: + return offset, thrift.PrependError(fmt.Sprintf("%T read struct begin error: ", p), err) +ReadFieldBeginError: + return offset, thrift.PrependError(fmt.Sprintf("%T read field %d begin error: ", p, fieldId), err) +ReadFieldError: + return offset, thrift.PrependError(fmt.Sprintf("%T read field %d '%s' error: ", p, fieldId, fieldIDToName_EchoException[fieldId]), err) +SkipFieldError: + return offset, thrift.PrependError(fmt.Sprintf("%T field %d skip type %d error: ", p, fieldId, fieldTypeId), err) +ReadFieldEndError: + return offset, thrift.PrependError(fmt.Sprintf("%T read field end error", p), err) +ReadStructEndError: + return offset, thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err) +} + +func (p *EchoException) FastReadField1(buf []byte) (int, error) { + offset := 0 + + if v, l, err := bthrift.Binary.ReadString(buf[offset:]); err != nil { + return offset, err + } else { + offset += l + + p.Message = v + + } + return offset, nil +} + +// for compatibility +func (p *EchoException) FastWrite(buf []byte) int { + return 0 +} + +func (p *EchoException) FastWriteNocopy(buf []byte, binaryWriter bthrift.BinaryWriter) int { + offset := 0 + offset += bthrift.Binary.WriteStructBegin(buf[offset:], "EchoException") + if p != nil { + offset += p.fastWriteField1(buf[offset:], binaryWriter) + } + offset += bthrift.Binary.WriteFieldStop(buf[offset:]) + offset += bthrift.Binary.WriteStructEnd(buf[offset:]) + return offset +} + +func (p *EchoException) BLength() int { + l := 0 + l += bthrift.Binary.StructBeginLength("EchoException") + if p != nil { + l += p.field1Length() + } + l += bthrift.Binary.FieldStopLength() + l += bthrift.Binary.StructEndLength() + return l +} + +func (p *EchoException) fastWriteField1(buf []byte, binaryWriter bthrift.BinaryWriter) int { + offset := 0 + offset += bthrift.Binary.WriteFieldBegin(buf[offset:], "message", thrift.STRING, 1) + offset += bthrift.Binary.WriteStringNocopy(buf[offset:], binaryWriter, p.Message) + + offset += bthrift.Binary.WriteFieldEnd(buf[offset:]) + return offset +} + +func (p *EchoException) field1Length() int { + l := 0 + l += bthrift.Binary.FieldBeginLength("message", thrift.STRING, 1) + l += bthrift.Binary.StringLengthNocopy(p.Message) + + l += bthrift.Binary.FieldEndLength() + return l +} + +func (p *EchoServiceEchoPingPongArgs) FastRead(buf []byte) (int, error) { + var err error + var offset int + var l int + var fieldTypeId thrift.TType + var fieldId int16 + _, l, err = bthrift.Binary.ReadStructBegin(buf) + offset += l + if err != nil { + goto ReadStructBeginError + } + + for { + _, fieldTypeId, fieldId, l, err = bthrift.Binary.ReadFieldBegin(buf[offset:]) + offset += l + if err != nil { + goto ReadFieldBeginError + } + if fieldTypeId == thrift.STOP { + break + } + switch fieldId { + case 1: + if fieldTypeId == thrift.STRUCT { + l, err = p.FastReadField1(buf[offset:]) + offset += l + if err != nil { + goto ReadFieldError + } + } else { + l, err = bthrift.Binary.Skip(buf[offset:], fieldTypeId) + offset += l + if err != nil { + goto SkipFieldError + } + } + case 2: + if fieldTypeId == thrift.STRUCT { + l, err = p.FastReadField2(buf[offset:]) + offset += l + if err != nil { + goto ReadFieldError + } + } else { + l, err = bthrift.Binary.Skip(buf[offset:], fieldTypeId) + offset += l + if err != nil { + goto SkipFieldError + } + } + default: + l, err = bthrift.Binary.Skip(buf[offset:], fieldTypeId) + offset += l + if err != nil { + goto SkipFieldError + } + } + + l, err = bthrift.Binary.ReadFieldEnd(buf[offset:]) + offset += l + if err != nil { + goto ReadFieldEndError + } + } + l, err = bthrift.Binary.ReadStructEnd(buf[offset:]) + offset += l + if err != nil { + goto ReadStructEndError + } + + return offset, nil +ReadStructBeginError: + return offset, thrift.PrependError(fmt.Sprintf("%T read struct begin error: ", p), err) +ReadFieldBeginError: + return offset, thrift.PrependError(fmt.Sprintf("%T read field %d begin error: ", p, fieldId), err) +ReadFieldError: + return offset, thrift.PrependError(fmt.Sprintf("%T read field %d '%s' error: ", p, fieldId, fieldIDToName_EchoServiceEchoPingPongArgs[fieldId]), err) +SkipFieldError: + return offset, thrift.PrependError(fmt.Sprintf("%T field %d skip type %d error: ", p, fieldId, fieldTypeId), err) +ReadFieldEndError: + return offset, thrift.PrependError(fmt.Sprintf("%T read field end error", p), err) +ReadStructEndError: + return offset, thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err) +} + +func (p *EchoServiceEchoPingPongArgs) FastReadField1(buf []byte) (int, error) { + offset := 0 + + tmp := NewEchoRequest() + if l, err := tmp.FastRead(buf[offset:]); err != nil { + return offset, err + } else { + offset += l + } + p.Req1 = tmp + return offset, nil +} + +func (p *EchoServiceEchoPingPongArgs) FastReadField2(buf []byte) (int, error) { + offset := 0 + + tmp := NewEchoRequest() + if l, err := tmp.FastRead(buf[offset:]); err != nil { + return offset, err + } else { + offset += l + } + p.Req2 = tmp + return offset, nil +} + +// for compatibility +func (p *EchoServiceEchoPingPongArgs) FastWrite(buf []byte) int { + return 0 +} + +func (p *EchoServiceEchoPingPongArgs) FastWriteNocopy(buf []byte, binaryWriter bthrift.BinaryWriter) int { + offset := 0 + offset += bthrift.Binary.WriteStructBegin(buf[offset:], "EchoPingPong_args") + if p != nil { + offset += p.fastWriteField1(buf[offset:], binaryWriter) + offset += p.fastWriteField2(buf[offset:], binaryWriter) + } + offset += bthrift.Binary.WriteFieldStop(buf[offset:]) + offset += bthrift.Binary.WriteStructEnd(buf[offset:]) + return offset +} + +func (p *EchoServiceEchoPingPongArgs) BLength() int { + l := 0 + l += bthrift.Binary.StructBeginLength("EchoPingPong_args") + if p != nil { + l += p.field1Length() + l += p.field2Length() + } + l += bthrift.Binary.FieldStopLength() + l += bthrift.Binary.StructEndLength() + return l +} + +func (p *EchoServiceEchoPingPongArgs) fastWriteField1(buf []byte, binaryWriter bthrift.BinaryWriter) int { + offset := 0 + offset += bthrift.Binary.WriteFieldBegin(buf[offset:], "req1", thrift.STRUCT, 1) + offset += p.Req1.FastWriteNocopy(buf[offset:], binaryWriter) + offset += bthrift.Binary.WriteFieldEnd(buf[offset:]) + return offset +} + +func (p *EchoServiceEchoPingPongArgs) fastWriteField2(buf []byte, binaryWriter bthrift.BinaryWriter) int { + offset := 0 + offset += bthrift.Binary.WriteFieldBegin(buf[offset:], "req2", thrift.STRUCT, 2) + offset += p.Req2.FastWriteNocopy(buf[offset:], binaryWriter) + offset += bthrift.Binary.WriteFieldEnd(buf[offset:]) + return offset +} + +func (p *EchoServiceEchoPingPongArgs) field1Length() int { + l := 0 + l += bthrift.Binary.FieldBeginLength("req1", thrift.STRUCT, 1) + l += p.Req1.BLength() + l += bthrift.Binary.FieldEndLength() + return l +} + +func (p *EchoServiceEchoPingPongArgs) field2Length() int { + l := 0 + l += bthrift.Binary.FieldBeginLength("req2", thrift.STRUCT, 2) + l += p.Req2.BLength() + l += bthrift.Binary.FieldEndLength() + return l +} + +func (p *EchoServiceEchoPingPongResult) FastRead(buf []byte) (int, error) { + var err error + var offset int + var l int + var fieldTypeId thrift.TType + var fieldId int16 + _, l, err = bthrift.Binary.ReadStructBegin(buf) + offset += l + if err != nil { + goto ReadStructBeginError + } + + for { + _, fieldTypeId, fieldId, l, err = bthrift.Binary.ReadFieldBegin(buf[offset:]) + offset += l + if err != nil { + goto ReadFieldBeginError + } + if fieldTypeId == thrift.STOP { + break + } + switch fieldId { + case 0: + if fieldTypeId == thrift.STRUCT { + l, err = p.FastReadField0(buf[offset:]) + offset += l + if err != nil { + goto ReadFieldError + } + } else { + l, err = bthrift.Binary.Skip(buf[offset:], fieldTypeId) + offset += l + if err != nil { + goto SkipFieldError + } + } + case 1: + if fieldTypeId == thrift.STRUCT { + l, err = p.FastReadField1(buf[offset:]) + offset += l + if err != nil { + goto ReadFieldError + } + } else { + l, err = bthrift.Binary.Skip(buf[offset:], fieldTypeId) + offset += l + if err != nil { + goto SkipFieldError + } + } + default: + l, err = bthrift.Binary.Skip(buf[offset:], fieldTypeId) + offset += l + if err != nil { + goto SkipFieldError + } + } + + l, err = bthrift.Binary.ReadFieldEnd(buf[offset:]) + offset += l + if err != nil { + goto ReadFieldEndError + } + } + l, err = bthrift.Binary.ReadStructEnd(buf[offset:]) + offset += l + if err != nil { + goto ReadStructEndError + } + + return offset, nil +ReadStructBeginError: + return offset, thrift.PrependError(fmt.Sprintf("%T read struct begin error: ", p), err) +ReadFieldBeginError: + return offset, thrift.PrependError(fmt.Sprintf("%T read field %d begin error: ", p, fieldId), err) +ReadFieldError: + return offset, thrift.PrependError(fmt.Sprintf("%T read field %d '%s' error: ", p, fieldId, fieldIDToName_EchoServiceEchoPingPongResult[fieldId]), err) +SkipFieldError: + return offset, thrift.PrependError(fmt.Sprintf("%T field %d skip type %d error: ", p, fieldId, fieldTypeId), err) +ReadFieldEndError: + return offset, thrift.PrependError(fmt.Sprintf("%T read field end error", p), err) +ReadStructEndError: + return offset, thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err) +} + +func (p *EchoServiceEchoPingPongResult) FastReadField0(buf []byte) (int, error) { + offset := 0 + + tmp := NewEchoResponse() + if l, err := tmp.FastRead(buf[offset:]); err != nil { + return offset, err + } else { + offset += l + } + p.Success = tmp + return offset, nil +} + +func (p *EchoServiceEchoPingPongResult) FastReadField1(buf []byte) (int, error) { + offset := 0 + + tmp := NewEchoException() + if l, err := tmp.FastRead(buf[offset:]); err != nil { + return offset, err + } else { + offset += l + } + p.E = tmp + return offset, nil +} + +// for compatibility +func (p *EchoServiceEchoPingPongResult) FastWrite(buf []byte) int { + return 0 +} + +func (p *EchoServiceEchoPingPongResult) FastWriteNocopy(buf []byte, binaryWriter bthrift.BinaryWriter) int { + offset := 0 + offset += bthrift.Binary.WriteStructBegin(buf[offset:], "EchoPingPong_result") + if p != nil { + offset += p.fastWriteField0(buf[offset:], binaryWriter) + offset += p.fastWriteField1(buf[offset:], binaryWriter) + } + offset += bthrift.Binary.WriteFieldStop(buf[offset:]) + offset += bthrift.Binary.WriteStructEnd(buf[offset:]) + return offset +} + +func (p *EchoServiceEchoPingPongResult) BLength() int { + l := 0 + l += bthrift.Binary.StructBeginLength("EchoPingPong_result") + if p != nil { + l += p.field0Length() + l += p.field1Length() + } + l += bthrift.Binary.FieldStopLength() + l += bthrift.Binary.StructEndLength() + return l +} + +func (p *EchoServiceEchoPingPongResult) fastWriteField0(buf []byte, binaryWriter bthrift.BinaryWriter) int { + offset := 0 + if p.IsSetSuccess() { + offset += bthrift.Binary.WriteFieldBegin(buf[offset:], "success", thrift.STRUCT, 0) + offset += p.Success.FastWriteNocopy(buf[offset:], binaryWriter) + offset += bthrift.Binary.WriteFieldEnd(buf[offset:]) + } + return offset +} + +func (p *EchoServiceEchoPingPongResult) fastWriteField1(buf []byte, binaryWriter bthrift.BinaryWriter) int { + offset := 0 + if p.IsSetE() { + offset += bthrift.Binary.WriteFieldBegin(buf[offset:], "e", thrift.STRUCT, 1) + offset += p.E.FastWriteNocopy(buf[offset:], binaryWriter) + offset += bthrift.Binary.WriteFieldEnd(buf[offset:]) + } + return offset +} + +func (p *EchoServiceEchoPingPongResult) field0Length() int { + l := 0 + if p.IsSetSuccess() { + l += bthrift.Binary.FieldBeginLength("success", thrift.STRUCT, 0) + l += p.Success.BLength() + l += bthrift.Binary.FieldEndLength() + } + return l +} + +func (p *EchoServiceEchoPingPongResult) field1Length() int { + l := 0 + if p.IsSetE() { + l += bthrift.Binary.FieldBeginLength("e", thrift.STRUCT, 1) + l += p.E.BLength() + l += bthrift.Binary.FieldEndLength() + } + return l +} + +func (p *EchoServiceEchoOnewayArgs) FastRead(buf []byte) (int, error) { + var err error + var offset int + var l int + var fieldTypeId thrift.TType + var fieldId int16 + _, l, err = bthrift.Binary.ReadStructBegin(buf) + offset += l + if err != nil { + goto ReadStructBeginError + } + + for { + _, fieldTypeId, fieldId, l, err = bthrift.Binary.ReadFieldBegin(buf[offset:]) + offset += l + if err != nil { + goto ReadFieldBeginError + } + if fieldTypeId == thrift.STOP { + break + } + switch fieldId { + case 1: + if fieldTypeId == thrift.STRUCT { + l, err = p.FastReadField1(buf[offset:]) + offset += l + if err != nil { + goto ReadFieldError + } + } else { + l, err = bthrift.Binary.Skip(buf[offset:], fieldTypeId) + offset += l + if err != nil { + goto SkipFieldError + } + } + default: + l, err = bthrift.Binary.Skip(buf[offset:], fieldTypeId) + offset += l + if err != nil { + goto SkipFieldError + } + } + + l, err = bthrift.Binary.ReadFieldEnd(buf[offset:]) + offset += l + if err != nil { + goto ReadFieldEndError + } + } + l, err = bthrift.Binary.ReadStructEnd(buf[offset:]) + offset += l + if err != nil { + goto ReadStructEndError + } + + return offset, nil +ReadStructBeginError: + return offset, thrift.PrependError(fmt.Sprintf("%T read struct begin error: ", p), err) +ReadFieldBeginError: + return offset, thrift.PrependError(fmt.Sprintf("%T read field %d begin error: ", p, fieldId), err) +ReadFieldError: + return offset, thrift.PrependError(fmt.Sprintf("%T read field %d '%s' error: ", p, fieldId, fieldIDToName_EchoServiceEchoOnewayArgs[fieldId]), err) +SkipFieldError: + return offset, thrift.PrependError(fmt.Sprintf("%T field %d skip type %d error: ", p, fieldId, fieldTypeId), err) +ReadFieldEndError: + return offset, thrift.PrependError(fmt.Sprintf("%T read field end error", p), err) +ReadStructEndError: + return offset, thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err) +} + +func (p *EchoServiceEchoOnewayArgs) FastReadField1(buf []byte) (int, error) { + offset := 0 + + tmp := NewEchoRequest() + if l, err := tmp.FastRead(buf[offset:]); err != nil { + return offset, err + } else { + offset += l + } + p.Req1 = tmp + return offset, nil +} + +// for compatibility +func (p *EchoServiceEchoOnewayArgs) FastWrite(buf []byte) int { + return 0 +} + +func (p *EchoServiceEchoOnewayArgs) FastWriteNocopy(buf []byte, binaryWriter bthrift.BinaryWriter) int { + offset := 0 + offset += bthrift.Binary.WriteStructBegin(buf[offset:], "EchoOneway_args") + if p != nil { + offset += p.fastWriteField1(buf[offset:], binaryWriter) + } + offset += bthrift.Binary.WriteFieldStop(buf[offset:]) + offset += bthrift.Binary.WriteStructEnd(buf[offset:]) + return offset +} + +func (p *EchoServiceEchoOnewayArgs) BLength() int { + l := 0 + l += bthrift.Binary.StructBeginLength("EchoOneway_args") + if p != nil { + l += p.field1Length() + } + l += bthrift.Binary.FieldStopLength() + l += bthrift.Binary.StructEndLength() + return l +} + +func (p *EchoServiceEchoOnewayArgs) fastWriteField1(buf []byte, binaryWriter bthrift.BinaryWriter) int { + offset := 0 + offset += bthrift.Binary.WriteFieldBegin(buf[offset:], "req1", thrift.STRUCT, 1) + offset += p.Req1.FastWriteNocopy(buf[offset:], binaryWriter) + offset += bthrift.Binary.WriteFieldEnd(buf[offset:]) + return offset +} + +func (p *EchoServiceEchoOnewayArgs) field1Length() int { + l := 0 + l += bthrift.Binary.FieldBeginLength("req1", thrift.STRUCT, 1) + l += p.Req1.BLength() + l += bthrift.Binary.FieldEndLength() + return l +} + +func (p *EchoServiceEchoOnewayResult) FastRead(buf []byte) (int, error) { + var err error + var offset int + var l int + var fieldTypeId thrift.TType + var fieldId int16 + _, l, err = bthrift.Binary.ReadStructBegin(buf) + offset += l + if err != nil { + goto ReadStructBeginError + } + + for { + _, fieldTypeId, fieldId, l, err = bthrift.Binary.ReadFieldBegin(buf[offset:]) + offset += l + if err != nil { + goto ReadFieldBeginError + } + if fieldTypeId == thrift.STOP { + break + } + l, err = bthrift.Binary.Skip(buf[offset:], fieldTypeId) + offset += l + if err != nil { + goto SkipFieldError + } + + l, err = bthrift.Binary.ReadFieldEnd(buf[offset:]) + offset += l + if err != nil { + goto ReadFieldEndError + } + } + l, err = bthrift.Binary.ReadStructEnd(buf[offset:]) + offset += l + if err != nil { + goto ReadStructEndError + } + + return offset, nil +ReadStructBeginError: + return offset, thrift.PrependError(fmt.Sprintf("%T read struct begin error: ", p), err) +ReadFieldBeginError: + return offset, thrift.PrependError(fmt.Sprintf("%T read field %d begin error: ", p, fieldId), err) +SkipFieldError: + return offset, thrift.PrependError(fmt.Sprintf("%T field %d skip type %d error: ", p, fieldId, fieldTypeId), err) +ReadFieldEndError: + return offset, thrift.PrependError(fmt.Sprintf("%T read field end error", p), err) +ReadStructEndError: + return offset, thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err) +} + +// for compatibility +func (p *EchoServiceEchoOnewayResult) FastWrite(buf []byte) int { + return 0 +} + +func (p *EchoServiceEchoOnewayResult) FastWriteNocopy(buf []byte, binaryWriter bthrift.BinaryWriter) int { + offset := 0 + offset += bthrift.Binary.WriteStructBegin(buf[offset:], "EchoOneway_result") + if p != nil { + } + offset += bthrift.Binary.WriteFieldStop(buf[offset:]) + offset += bthrift.Binary.WriteStructEnd(buf[offset:]) + return offset +} + +func (p *EchoServiceEchoOnewayResult) BLength() int { + l := 0 + l += bthrift.Binary.StructBeginLength("EchoOneway_result") + if p != nil { + } + l += bthrift.Binary.FieldStopLength() + l += bthrift.Binary.StructEndLength() + return l +} + +func (p *EchoServicePingArgs) FastRead(buf []byte) (int, error) { + var err error + var offset int + var l int + var fieldTypeId thrift.TType + var fieldId int16 + _, l, err = bthrift.Binary.ReadStructBegin(buf) + offset += l + if err != nil { + goto ReadStructBeginError + } + + for { + _, fieldTypeId, fieldId, l, err = bthrift.Binary.ReadFieldBegin(buf[offset:]) + offset += l + if err != nil { + goto ReadFieldBeginError + } + if fieldTypeId == thrift.STOP { + break + } + l, err = bthrift.Binary.Skip(buf[offset:], fieldTypeId) + offset += l + if err != nil { + goto SkipFieldError + } + + l, err = bthrift.Binary.ReadFieldEnd(buf[offset:]) + offset += l + if err != nil { + goto ReadFieldEndError + } + } + l, err = bthrift.Binary.ReadStructEnd(buf[offset:]) + offset += l + if err != nil { + goto ReadStructEndError + } + + return offset, nil +ReadStructBeginError: + return offset, thrift.PrependError(fmt.Sprintf("%T read struct begin error: ", p), err) +ReadFieldBeginError: + return offset, thrift.PrependError(fmt.Sprintf("%T read field %d begin error: ", p, fieldId), err) +SkipFieldError: + return offset, thrift.PrependError(fmt.Sprintf("%T field %d skip type %d error: ", p, fieldId, fieldTypeId), err) +ReadFieldEndError: + return offset, thrift.PrependError(fmt.Sprintf("%T read field end error", p), err) +ReadStructEndError: + return offset, thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err) +} + +// for compatibility +func (p *EchoServicePingArgs) FastWrite(buf []byte) int { + return 0 +} + +func (p *EchoServicePingArgs) FastWriteNocopy(buf []byte, binaryWriter bthrift.BinaryWriter) int { + offset := 0 + offset += bthrift.Binary.WriteStructBegin(buf[offset:], "Ping_args") + if p != nil { + } + offset += bthrift.Binary.WriteFieldStop(buf[offset:]) + offset += bthrift.Binary.WriteStructEnd(buf[offset:]) + return offset +} + +func (p *EchoServicePingArgs) BLength() int { + l := 0 + l += bthrift.Binary.StructBeginLength("Ping_args") + if p != nil { + } + l += bthrift.Binary.FieldStopLength() + l += bthrift.Binary.StructEndLength() + return l +} + +func (p *EchoServicePingResult) FastRead(buf []byte) (int, error) { + var err error + var offset int + var l int + var fieldTypeId thrift.TType + var fieldId int16 + _, l, err = bthrift.Binary.ReadStructBegin(buf) + offset += l + if err != nil { + goto ReadStructBeginError + } + + for { + _, fieldTypeId, fieldId, l, err = bthrift.Binary.ReadFieldBegin(buf[offset:]) + offset += l + if err != nil { + goto ReadFieldBeginError + } + if fieldTypeId == thrift.STOP { + break + } + l, err = bthrift.Binary.Skip(buf[offset:], fieldTypeId) + offset += l + if err != nil { + goto SkipFieldError + } + + l, err = bthrift.Binary.ReadFieldEnd(buf[offset:]) + offset += l + if err != nil { + goto ReadFieldEndError + } + } + l, err = bthrift.Binary.ReadStructEnd(buf[offset:]) + offset += l + if err != nil { + goto ReadStructEndError + } + + return offset, nil +ReadStructBeginError: + return offset, thrift.PrependError(fmt.Sprintf("%T read struct begin error: ", p), err) +ReadFieldBeginError: + return offset, thrift.PrependError(fmt.Sprintf("%T read field %d begin error: ", p, fieldId), err) +SkipFieldError: + return offset, thrift.PrependError(fmt.Sprintf("%T field %d skip type %d error: ", p, fieldId, fieldTypeId), err) +ReadFieldEndError: + return offset, thrift.PrependError(fmt.Sprintf("%T read field end error", p), err) +ReadStructEndError: + return offset, thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err) +} + +// for compatibility +func (p *EchoServicePingResult) FastWrite(buf []byte) int { + return 0 +} + +func (p *EchoServicePingResult) FastWriteNocopy(buf []byte, binaryWriter bthrift.BinaryWriter) int { + offset := 0 + offset += bthrift.Binary.WriteStructBegin(buf[offset:], "Ping_result") + if p != nil { + } + offset += bthrift.Binary.WriteFieldStop(buf[offset:]) + offset += bthrift.Binary.WriteStructEnd(buf[offset:]) + return offset +} + +func (p *EchoServicePingResult) BLength() int { + l := 0 + l += bthrift.Binary.StructBeginLength("Ping_result") + if p != nil { + } + l += bthrift.Binary.FieldStopLength() + l += bthrift.Binary.StructEndLength() + return l +} + +func (p *EchoServiceEchoPingPongArgs) GetFirstArgument() interface{} { + return p.Req1 +} + +func (p *EchoServiceEchoPingPongResult) GetResult() interface{} { + return p.Success +} + +func (p *EchoServiceEchoOnewayArgs) GetFirstArgument() interface{} { + return p.Req1 +} + +func (p *EchoServiceEchoOnewayResult) GetResult() interface{} { + return nil +} + +func (p *EchoServicePingArgs) GetFirstArgument() interface{} { + return nil +} + +func (p *EchoServicePingResult) GetResult() interface{} { + return nil +} diff --git a/thrift_streaming/kitex_gen_cross/echo/k-consts.go b/thrift_streaming/kitex_gen_cross/echo/k-consts.go new file mode 100644 index 0000000..cf25014 --- /dev/null +++ b/thrift_streaming/kitex_gen_cross/echo/k-consts.go @@ -0,0 +1,4 @@ +package echo + +// KitexUnusedProtection is used to prevent 'imported and not used' error. +var KitexUnusedProtection = struct{}{} diff --git a/thrift_streaming/kitex_gen_old/echo/api.go b/thrift_streaming/kitex_gen_old/echo/api.go new file mode 100644 index 0000000..ddc7867 --- /dev/null +++ b/thrift_streaming/kitex_gen_old/echo/api.go @@ -0,0 +1,3285 @@ +// Code generated by thriftgo (0.3.4). DO NOT EDIT. + +package echo + +import ( + "context" + "fmt" + "github.com/apache/thrift/lib/go/thrift" + "strings" +) + +type EchoRequest struct { + Message string `thrift:"message,1,required" frugal:"1,required,string" json:"message"` +} + +func NewEchoRequest() *EchoRequest { + return &EchoRequest{} +} + +func (p *EchoRequest) InitDefault() { + *p = EchoRequest{} +} + +func (p *EchoRequest) GetMessage() (v string) { + return p.Message +} +func (p *EchoRequest) SetMessage(val string) { + p.Message = val +} + +var fieldIDToName_EchoRequest = map[int16]string{ + 1: "message", +} + +func (p *EchoRequest) Read(iprot thrift.TProtocol) (err error) { + + var fieldTypeId thrift.TType + var fieldId int16 + var issetMessage bool = false + + if _, err = iprot.ReadStructBegin(); err != nil { + goto ReadStructBeginError + } + + for { + _, fieldTypeId, fieldId, err = iprot.ReadFieldBegin() + if err != nil { + goto ReadFieldBeginError + } + if fieldTypeId == thrift.STOP { + break + } + + switch fieldId { + case 1: + if fieldTypeId == thrift.STRING { + if err = p.ReadField1(iprot); err != nil { + goto ReadFieldError + } + issetMessage = true + } else if err = iprot.Skip(fieldTypeId); err != nil { + goto SkipFieldError + } + default: + if err = iprot.Skip(fieldTypeId); err != nil { + goto SkipFieldError + } + } + if err = iprot.ReadFieldEnd(); err != nil { + goto ReadFieldEndError + } + } + if err = iprot.ReadStructEnd(); err != nil { + goto ReadStructEndError + } + + if !issetMessage { + fieldId = 1 + goto RequiredFieldNotSetError + } + return nil +ReadStructBeginError: + return thrift.PrependError(fmt.Sprintf("%T read struct begin error: ", p), err) +ReadFieldBeginError: + return thrift.PrependError(fmt.Sprintf("%T read field %d begin error: ", p, fieldId), err) +ReadFieldError: + return thrift.PrependError(fmt.Sprintf("%T read field %d '%s' error: ", p, fieldId, fieldIDToName_EchoRequest[fieldId]), err) +SkipFieldError: + return thrift.PrependError(fmt.Sprintf("%T field %d skip type %d error: ", p, fieldId, fieldTypeId), err) + +ReadFieldEndError: + return thrift.PrependError(fmt.Sprintf("%T read field end error", p), err) +ReadStructEndError: + return thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err) +RequiredFieldNotSetError: + return thrift.NewTProtocolExceptionWithType(thrift.INVALID_DATA, fmt.Errorf("required field %s is not set", fieldIDToName_EchoRequest[fieldId])) +} + +func (p *EchoRequest) ReadField1(iprot thrift.TProtocol) error { + + if v, err := iprot.ReadString(); err != nil { + return err + } else { + p.Message = v + } + return nil +} + +func (p *EchoRequest) Write(oprot thrift.TProtocol) (err error) { + var fieldId int16 + if err = oprot.WriteStructBegin("EchoRequest"); err != nil { + goto WriteStructBeginError + } + if p != nil { + if err = p.writeField1(oprot); err != nil { + fieldId = 1 + goto WriteFieldError + } + } + if err = oprot.WriteFieldStop(); err != nil { + goto WriteFieldStopError + } + if err = oprot.WriteStructEnd(); err != nil { + goto WriteStructEndError + } + return nil +WriteStructBeginError: + return thrift.PrependError(fmt.Sprintf("%T write struct begin error: ", p), err) +WriteFieldError: + return thrift.PrependError(fmt.Sprintf("%T write field %d error: ", p, fieldId), err) +WriteFieldStopError: + return thrift.PrependError(fmt.Sprintf("%T write field stop error: ", p), err) +WriteStructEndError: + return thrift.PrependError(fmt.Sprintf("%T write struct end error: ", p), err) +} + +func (p *EchoRequest) writeField1(oprot thrift.TProtocol) (err error) { + if err = oprot.WriteFieldBegin("message", thrift.STRING, 1); err != nil { + goto WriteFieldBeginError + } + if err := oprot.WriteString(p.Message); err != nil { + return err + } + if err = oprot.WriteFieldEnd(); err != nil { + goto WriteFieldEndError + } + return nil +WriteFieldBeginError: + return thrift.PrependError(fmt.Sprintf("%T write field 1 begin error: ", p), err) +WriteFieldEndError: + return thrift.PrependError(fmt.Sprintf("%T write field 1 end error: ", p), err) +} + +func (p *EchoRequest) String() string { + if p == nil { + return "" + } + return fmt.Sprintf("EchoRequest(%+v)", *p) + +} + +func (p *EchoRequest) DeepEqual(ano *EchoRequest) bool { + if p == ano { + return true + } else if p == nil || ano == nil { + return false + } + if !p.Field1DeepEqual(ano.Message) { + return false + } + return true +} + +func (p *EchoRequest) Field1DeepEqual(src string) bool { + + if strings.Compare(p.Message, src) != 0 { + return false + } + return true +} + +type EchoResponse struct { + Message string `thrift:"message,1,required" frugal:"1,required,string" json:"message"` +} + +func NewEchoResponse() *EchoResponse { + return &EchoResponse{} +} + +func (p *EchoResponse) InitDefault() { + *p = EchoResponse{} +} + +func (p *EchoResponse) GetMessage() (v string) { + return p.Message +} +func (p *EchoResponse) SetMessage(val string) { + p.Message = val +} + +var fieldIDToName_EchoResponse = map[int16]string{ + 1: "message", +} + +func (p *EchoResponse) Read(iprot thrift.TProtocol) (err error) { + + var fieldTypeId thrift.TType + var fieldId int16 + var issetMessage bool = false + + if _, err = iprot.ReadStructBegin(); err != nil { + goto ReadStructBeginError + } + + for { + _, fieldTypeId, fieldId, err = iprot.ReadFieldBegin() + if err != nil { + goto ReadFieldBeginError + } + if fieldTypeId == thrift.STOP { + break + } + + switch fieldId { + case 1: + if fieldTypeId == thrift.STRING { + if err = p.ReadField1(iprot); err != nil { + goto ReadFieldError + } + issetMessage = true + } else if err = iprot.Skip(fieldTypeId); err != nil { + goto SkipFieldError + } + default: + if err = iprot.Skip(fieldTypeId); err != nil { + goto SkipFieldError + } + } + if err = iprot.ReadFieldEnd(); err != nil { + goto ReadFieldEndError + } + } + if err = iprot.ReadStructEnd(); err != nil { + goto ReadStructEndError + } + + if !issetMessage { + fieldId = 1 + goto RequiredFieldNotSetError + } + return nil +ReadStructBeginError: + return thrift.PrependError(fmt.Sprintf("%T read struct begin error: ", p), err) +ReadFieldBeginError: + return thrift.PrependError(fmt.Sprintf("%T read field %d begin error: ", p, fieldId), err) +ReadFieldError: + return thrift.PrependError(fmt.Sprintf("%T read field %d '%s' error: ", p, fieldId, fieldIDToName_EchoResponse[fieldId]), err) +SkipFieldError: + return thrift.PrependError(fmt.Sprintf("%T field %d skip type %d error: ", p, fieldId, fieldTypeId), err) + +ReadFieldEndError: + return thrift.PrependError(fmt.Sprintf("%T read field end error", p), err) +ReadStructEndError: + return thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err) +RequiredFieldNotSetError: + return thrift.NewTProtocolExceptionWithType(thrift.INVALID_DATA, fmt.Errorf("required field %s is not set", fieldIDToName_EchoResponse[fieldId])) +} + +func (p *EchoResponse) ReadField1(iprot thrift.TProtocol) error { + + if v, err := iprot.ReadString(); err != nil { + return err + } else { + p.Message = v + } + return nil +} + +func (p *EchoResponse) Write(oprot thrift.TProtocol) (err error) { + var fieldId int16 + if err = oprot.WriteStructBegin("EchoResponse"); err != nil { + goto WriteStructBeginError + } + if p != nil { + if err = p.writeField1(oprot); err != nil { + fieldId = 1 + goto WriteFieldError + } + } + if err = oprot.WriteFieldStop(); err != nil { + goto WriteFieldStopError + } + if err = oprot.WriteStructEnd(); err != nil { + goto WriteStructEndError + } + return nil +WriteStructBeginError: + return thrift.PrependError(fmt.Sprintf("%T write struct begin error: ", p), err) +WriteFieldError: + return thrift.PrependError(fmt.Sprintf("%T write field %d error: ", p, fieldId), err) +WriteFieldStopError: + return thrift.PrependError(fmt.Sprintf("%T write field stop error: ", p), err) +WriteStructEndError: + return thrift.PrependError(fmt.Sprintf("%T write struct end error: ", p), err) +} + +func (p *EchoResponse) writeField1(oprot thrift.TProtocol) (err error) { + if err = oprot.WriteFieldBegin("message", thrift.STRING, 1); err != nil { + goto WriteFieldBeginError + } + if err := oprot.WriteString(p.Message); err != nil { + return err + } + if err = oprot.WriteFieldEnd(); err != nil { + goto WriteFieldEndError + } + return nil +WriteFieldBeginError: + return thrift.PrependError(fmt.Sprintf("%T write field 1 begin error: ", p), err) +WriteFieldEndError: + return thrift.PrependError(fmt.Sprintf("%T write field 1 end error: ", p), err) +} + +func (p *EchoResponse) String() string { + if p == nil { + return "" + } + return fmt.Sprintf("EchoResponse(%+v)", *p) + +} + +func (p *EchoResponse) DeepEqual(ano *EchoResponse) bool { + if p == ano { + return true + } else if p == nil || ano == nil { + return false + } + if !p.Field1DeepEqual(ano.Message) { + return false + } + return true +} + +func (p *EchoResponse) Field1DeepEqual(src string) bool { + + if strings.Compare(p.Message, src) != 0 { + return false + } + return true +} + +type EchoException struct { + Message string `thrift:"message,1" frugal:"1,default,string" json:"message"` +} + +func NewEchoException() *EchoException { + return &EchoException{} +} + +func (p *EchoException) InitDefault() { + *p = EchoException{} +} + +func (p *EchoException) GetMessage() (v string) { + return p.Message +} +func (p *EchoException) SetMessage(val string) { + p.Message = val +} + +var fieldIDToName_EchoException = map[int16]string{ + 1: "message", +} + +func (p *EchoException) Read(iprot thrift.TProtocol) (err error) { + + var fieldTypeId thrift.TType + var fieldId int16 + + if _, err = iprot.ReadStructBegin(); err != nil { + goto ReadStructBeginError + } + + for { + _, fieldTypeId, fieldId, err = iprot.ReadFieldBegin() + if err != nil { + goto ReadFieldBeginError + } + if fieldTypeId == thrift.STOP { + break + } + + switch fieldId { + case 1: + if fieldTypeId == thrift.STRING { + if err = p.ReadField1(iprot); err != nil { + goto ReadFieldError + } + } else if err = iprot.Skip(fieldTypeId); err != nil { + goto SkipFieldError + } + default: + if err = iprot.Skip(fieldTypeId); err != nil { + goto SkipFieldError + } + } + if err = iprot.ReadFieldEnd(); err != nil { + goto ReadFieldEndError + } + } + if err = iprot.ReadStructEnd(); err != nil { + goto ReadStructEndError + } + + return nil +ReadStructBeginError: + return thrift.PrependError(fmt.Sprintf("%T read struct begin error: ", p), err) +ReadFieldBeginError: + return thrift.PrependError(fmt.Sprintf("%T read field %d begin error: ", p, fieldId), err) +ReadFieldError: + return thrift.PrependError(fmt.Sprintf("%T read field %d '%s' error: ", p, fieldId, fieldIDToName_EchoException[fieldId]), err) +SkipFieldError: + return thrift.PrependError(fmt.Sprintf("%T field %d skip type %d error: ", p, fieldId, fieldTypeId), err) + +ReadFieldEndError: + return thrift.PrependError(fmt.Sprintf("%T read field end error", p), err) +ReadStructEndError: + return thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err) +} + +func (p *EchoException) ReadField1(iprot thrift.TProtocol) error { + + if v, err := iprot.ReadString(); err != nil { + return err + } else { + p.Message = v + } + return nil +} + +func (p *EchoException) Write(oprot thrift.TProtocol) (err error) { + var fieldId int16 + if err = oprot.WriteStructBegin("EchoException"); err != nil { + goto WriteStructBeginError + } + if p != nil { + if err = p.writeField1(oprot); err != nil { + fieldId = 1 + goto WriteFieldError + } + } + if err = oprot.WriteFieldStop(); err != nil { + goto WriteFieldStopError + } + if err = oprot.WriteStructEnd(); err != nil { + goto WriteStructEndError + } + return nil +WriteStructBeginError: + return thrift.PrependError(fmt.Sprintf("%T write struct begin error: ", p), err) +WriteFieldError: + return thrift.PrependError(fmt.Sprintf("%T write field %d error: ", p, fieldId), err) +WriteFieldStopError: + return thrift.PrependError(fmt.Sprintf("%T write field stop error: ", p), err) +WriteStructEndError: + return thrift.PrependError(fmt.Sprintf("%T write struct end error: ", p), err) +} + +func (p *EchoException) writeField1(oprot thrift.TProtocol) (err error) { + if err = oprot.WriteFieldBegin("message", thrift.STRING, 1); err != nil { + goto WriteFieldBeginError + } + if err := oprot.WriteString(p.Message); err != nil { + return err + } + if err = oprot.WriteFieldEnd(); err != nil { + goto WriteFieldEndError + } + return nil +WriteFieldBeginError: + return thrift.PrependError(fmt.Sprintf("%T write field 1 begin error: ", p), err) +WriteFieldEndError: + return thrift.PrependError(fmt.Sprintf("%T write field 1 end error: ", p), err) +} + +func (p *EchoException) String() string { + if p == nil { + return "" + } + return fmt.Sprintf("EchoException(%+v)", *p) + +} +func (p *EchoException) Error() string { + return p.String() +} + +func (p *EchoException) DeepEqual(ano *EchoException) bool { + if p == ano { + return true + } else if p == nil || ano == nil { + return false + } + if !p.Field1DeepEqual(ano.Message) { + return false + } + return true +} + +func (p *EchoException) Field1DeepEqual(src string) bool { + + if strings.Compare(p.Message, src) != 0 { + return false + } + return true +} + +type EchoService interface { + EchoBidirectional(ctx context.Context, req1 *EchoRequest) (r *EchoResponse, err error) + + EchoClient(ctx context.Context, req1 *EchoRequest) (r *EchoResponse, err error) + + EchoServer(ctx context.Context, req1 *EchoRequest) (r *EchoResponse, err error) + + EchoUnary(ctx context.Context, req1 *EchoRequest) (r *EchoResponse, err error) + + EchoPingPong(ctx context.Context, req1 *EchoRequest, req2 *EchoRequest) (r *EchoResponse, err error) + + EchoOneway(ctx context.Context, req1 *EchoRequest) (err error) + + Ping(ctx context.Context) (err error) +} + +type EchoServiceClient struct { + c thrift.TClient +} + +func NewEchoServiceClientFactory(t thrift.TTransport, f thrift.TProtocolFactory) *EchoServiceClient { + return &EchoServiceClient{ + c: thrift.NewTStandardClient(f.GetProtocol(t), f.GetProtocol(t)), + } +} + +func NewEchoServiceClientProtocol(t thrift.TTransport, iprot thrift.TProtocol, oprot thrift.TProtocol) *EchoServiceClient { + return &EchoServiceClient{ + c: thrift.NewTStandardClient(iprot, oprot), + } +} + +func NewEchoServiceClient(c thrift.TClient) *EchoServiceClient { + return &EchoServiceClient{ + c: c, + } +} + +func (p *EchoServiceClient) Client_() thrift.TClient { + return p.c +} + +func (p *EchoServiceClient) EchoBidirectional(ctx context.Context, req1 *EchoRequest) (r *EchoResponse, err error) { + var _args EchoServiceEchoBidirectionalArgs + _args.Req1 = req1 + var _result EchoServiceEchoBidirectionalResult + if err = p.Client_().Call(ctx, "EchoBidirectional", &_args, &_result); err != nil { + return + } + return _result.GetSuccess(), nil +} +func (p *EchoServiceClient) EchoClient(ctx context.Context, req1 *EchoRequest) (r *EchoResponse, err error) { + var _args EchoServiceEchoClientArgs + _args.Req1 = req1 + var _result EchoServiceEchoClientResult + if err = p.Client_().Call(ctx, "EchoClient", &_args, &_result); err != nil { + return + } + return _result.GetSuccess(), nil +} +func (p *EchoServiceClient) EchoServer(ctx context.Context, req1 *EchoRequest) (r *EchoResponse, err error) { + var _args EchoServiceEchoServerArgs + _args.Req1 = req1 + var _result EchoServiceEchoServerResult + if err = p.Client_().Call(ctx, "EchoServer", &_args, &_result); err != nil { + return + } + return _result.GetSuccess(), nil +} +func (p *EchoServiceClient) EchoUnary(ctx context.Context, req1 *EchoRequest) (r *EchoResponse, err error) { + var _args EchoServiceEchoUnaryArgs + _args.Req1 = req1 + var _result EchoServiceEchoUnaryResult + if err = p.Client_().Call(ctx, "EchoUnary", &_args, &_result); err != nil { + return + } + return _result.GetSuccess(), nil +} +func (p *EchoServiceClient) EchoPingPong(ctx context.Context, req1 *EchoRequest, req2 *EchoRequest) (r *EchoResponse, err error) { + var _args EchoServiceEchoPingPongArgs + _args.Req1 = req1 + _args.Req2 = req2 + var _result EchoServiceEchoPingPongResult + if err = p.Client_().Call(ctx, "EchoPingPong", &_args, &_result); err != nil { + return + } + switch { + case _result.E != nil: + return r, _result.E + } + return _result.GetSuccess(), nil +} +func (p *EchoServiceClient) EchoOneway(ctx context.Context, req1 *EchoRequest) (err error) { + var _args EchoServiceEchoOnewayArgs + _args.Req1 = req1 + var _result EchoServiceEchoOnewayResult + if err = p.Client_().Call(ctx, "EchoOneway", &_args, &_result); err != nil { + return + } + return nil +} +func (p *EchoServiceClient) Ping(ctx context.Context) (err error) { + var _args EchoServicePingArgs + var _result EchoServicePingResult + if err = p.Client_().Call(ctx, "Ping", &_args, &_result); err != nil { + return + } + return nil +} + +type EchoServiceProcessor struct { + processorMap map[string]thrift.TProcessorFunction + handler EchoService +} + +func (p *EchoServiceProcessor) AddToProcessorMap(key string, processor thrift.TProcessorFunction) { + p.processorMap[key] = processor +} + +func (p *EchoServiceProcessor) GetProcessorFunction(key string) (processor thrift.TProcessorFunction, ok bool) { + processor, ok = p.processorMap[key] + return processor, ok +} + +func (p *EchoServiceProcessor) ProcessorMap() map[string]thrift.TProcessorFunction { + return p.processorMap +} + +func NewEchoServiceProcessor(handler EchoService) *EchoServiceProcessor { + self := &EchoServiceProcessor{handler: handler, processorMap: make(map[string]thrift.TProcessorFunction)} + self.AddToProcessorMap("EchoBidirectional", &echoServiceProcessorEchoBidirectional{handler: handler}) + self.AddToProcessorMap("EchoClient", &echoServiceProcessorEchoClient{handler: handler}) + self.AddToProcessorMap("EchoServer", &echoServiceProcessorEchoServer{handler: handler}) + self.AddToProcessorMap("EchoUnary", &echoServiceProcessorEchoUnary{handler: handler}) + self.AddToProcessorMap("EchoPingPong", &echoServiceProcessorEchoPingPong{handler: handler}) + self.AddToProcessorMap("EchoOneway", &echoServiceProcessorEchoOneway{handler: handler}) + self.AddToProcessorMap("Ping", &echoServiceProcessorPing{handler: handler}) + return self +} +func (p *EchoServiceProcessor) Process(ctx context.Context, iprot, oprot thrift.TProtocol) (success bool, err thrift.TException) { + name, _, seqId, err := iprot.ReadMessageBegin() + if err != nil { + return false, err + } + if processor, ok := p.GetProcessorFunction(name); ok { + return processor.Process(ctx, seqId, iprot, oprot) + } + iprot.Skip(thrift.STRUCT) + iprot.ReadMessageEnd() + x := thrift.NewTApplicationException(thrift.UNKNOWN_METHOD, "Unknown function "+name) + oprot.WriteMessageBegin(name, thrift.EXCEPTION, seqId) + x.Write(oprot) + oprot.WriteMessageEnd() + oprot.Flush(ctx) + return false, x +} + +type echoServiceProcessorEchoBidirectional struct { + handler EchoService +} + +func (p *echoServiceProcessorEchoBidirectional) Process(ctx context.Context, seqId int32, iprot, oprot thrift.TProtocol) (success bool, err thrift.TException) { + args := EchoServiceEchoBidirectionalArgs{} + if err = args.Read(iprot); err != nil { + iprot.ReadMessageEnd() + x := thrift.NewTApplicationException(thrift.PROTOCOL_ERROR, err.Error()) + oprot.WriteMessageBegin("EchoBidirectional", thrift.EXCEPTION, seqId) + x.Write(oprot) + oprot.WriteMessageEnd() + oprot.Flush(ctx) + return false, err + } + + iprot.ReadMessageEnd() + var err2 error + result := EchoServiceEchoBidirectionalResult{} + var retval *EchoResponse + if retval, err2 = p.handler.EchoBidirectional(ctx, args.Req1); err2 != nil { + x := thrift.NewTApplicationException(thrift.INTERNAL_ERROR, "Internal error processing EchoBidirectional: "+err2.Error()) + oprot.WriteMessageBegin("EchoBidirectional", thrift.EXCEPTION, seqId) + x.Write(oprot) + oprot.WriteMessageEnd() + oprot.Flush(ctx) + return true, err2 + } else { + result.Success = retval + } + if err2 = oprot.WriteMessageBegin("EchoBidirectional", thrift.REPLY, seqId); err2 != nil { + err = err2 + } + if err2 = result.Write(oprot); err == nil && err2 != nil { + err = err2 + } + if err2 = oprot.WriteMessageEnd(); err == nil && err2 != nil { + err = err2 + } + if err2 = oprot.Flush(ctx); err == nil && err2 != nil { + err = err2 + } + if err != nil { + return + } + return true, err +} + +type echoServiceProcessorEchoClient struct { + handler EchoService +} + +func (p *echoServiceProcessorEchoClient) Process(ctx context.Context, seqId int32, iprot, oprot thrift.TProtocol) (success bool, err thrift.TException) { + args := EchoServiceEchoClientArgs{} + if err = args.Read(iprot); err != nil { + iprot.ReadMessageEnd() + x := thrift.NewTApplicationException(thrift.PROTOCOL_ERROR, err.Error()) + oprot.WriteMessageBegin("EchoClient", thrift.EXCEPTION, seqId) + x.Write(oprot) + oprot.WriteMessageEnd() + oprot.Flush(ctx) + return false, err + } + + iprot.ReadMessageEnd() + var err2 error + result := EchoServiceEchoClientResult{} + var retval *EchoResponse + if retval, err2 = p.handler.EchoClient(ctx, args.Req1); err2 != nil { + x := thrift.NewTApplicationException(thrift.INTERNAL_ERROR, "Internal error processing EchoClient: "+err2.Error()) + oprot.WriteMessageBegin("EchoClient", thrift.EXCEPTION, seqId) + x.Write(oprot) + oprot.WriteMessageEnd() + oprot.Flush(ctx) + return true, err2 + } else { + result.Success = retval + } + if err2 = oprot.WriteMessageBegin("EchoClient", thrift.REPLY, seqId); err2 != nil { + err = err2 + } + if err2 = result.Write(oprot); err == nil && err2 != nil { + err = err2 + } + if err2 = oprot.WriteMessageEnd(); err == nil && err2 != nil { + err = err2 + } + if err2 = oprot.Flush(ctx); err == nil && err2 != nil { + err = err2 + } + if err != nil { + return + } + return true, err +} + +type echoServiceProcessorEchoServer struct { + handler EchoService +} + +func (p *echoServiceProcessorEchoServer) Process(ctx context.Context, seqId int32, iprot, oprot thrift.TProtocol) (success bool, err thrift.TException) { + args := EchoServiceEchoServerArgs{} + if err = args.Read(iprot); err != nil { + iprot.ReadMessageEnd() + x := thrift.NewTApplicationException(thrift.PROTOCOL_ERROR, err.Error()) + oprot.WriteMessageBegin("EchoServer", thrift.EXCEPTION, seqId) + x.Write(oprot) + oprot.WriteMessageEnd() + oprot.Flush(ctx) + return false, err + } + + iprot.ReadMessageEnd() + var err2 error + result := EchoServiceEchoServerResult{} + var retval *EchoResponse + if retval, err2 = p.handler.EchoServer(ctx, args.Req1); err2 != nil { + x := thrift.NewTApplicationException(thrift.INTERNAL_ERROR, "Internal error processing EchoServer: "+err2.Error()) + oprot.WriteMessageBegin("EchoServer", thrift.EXCEPTION, seqId) + x.Write(oprot) + oprot.WriteMessageEnd() + oprot.Flush(ctx) + return true, err2 + } else { + result.Success = retval + } + if err2 = oprot.WriteMessageBegin("EchoServer", thrift.REPLY, seqId); err2 != nil { + err = err2 + } + if err2 = result.Write(oprot); err == nil && err2 != nil { + err = err2 + } + if err2 = oprot.WriteMessageEnd(); err == nil && err2 != nil { + err = err2 + } + if err2 = oprot.Flush(ctx); err == nil && err2 != nil { + err = err2 + } + if err != nil { + return + } + return true, err +} + +type echoServiceProcessorEchoUnary struct { + handler EchoService +} + +func (p *echoServiceProcessorEchoUnary) Process(ctx context.Context, seqId int32, iprot, oprot thrift.TProtocol) (success bool, err thrift.TException) { + args := EchoServiceEchoUnaryArgs{} + if err = args.Read(iprot); err != nil { + iprot.ReadMessageEnd() + x := thrift.NewTApplicationException(thrift.PROTOCOL_ERROR, err.Error()) + oprot.WriteMessageBegin("EchoUnary", thrift.EXCEPTION, seqId) + x.Write(oprot) + oprot.WriteMessageEnd() + oprot.Flush(ctx) + return false, err + } + + iprot.ReadMessageEnd() + var err2 error + result := EchoServiceEchoUnaryResult{} + var retval *EchoResponse + if retval, err2 = p.handler.EchoUnary(ctx, args.Req1); err2 != nil { + x := thrift.NewTApplicationException(thrift.INTERNAL_ERROR, "Internal error processing EchoUnary: "+err2.Error()) + oprot.WriteMessageBegin("EchoUnary", thrift.EXCEPTION, seqId) + x.Write(oprot) + oprot.WriteMessageEnd() + oprot.Flush(ctx) + return true, err2 + } else { + result.Success = retval + } + if err2 = oprot.WriteMessageBegin("EchoUnary", thrift.REPLY, seqId); err2 != nil { + err = err2 + } + if err2 = result.Write(oprot); err == nil && err2 != nil { + err = err2 + } + if err2 = oprot.WriteMessageEnd(); err == nil && err2 != nil { + err = err2 + } + if err2 = oprot.Flush(ctx); err == nil && err2 != nil { + err = err2 + } + if err != nil { + return + } + return true, err +} + +type echoServiceProcessorEchoPingPong struct { + handler EchoService +} + +func (p *echoServiceProcessorEchoPingPong) Process(ctx context.Context, seqId int32, iprot, oprot thrift.TProtocol) (success bool, err thrift.TException) { + args := EchoServiceEchoPingPongArgs{} + if err = args.Read(iprot); err != nil { + iprot.ReadMessageEnd() + x := thrift.NewTApplicationException(thrift.PROTOCOL_ERROR, err.Error()) + oprot.WriteMessageBegin("EchoPingPong", thrift.EXCEPTION, seqId) + x.Write(oprot) + oprot.WriteMessageEnd() + oprot.Flush(ctx) + return false, err + } + + iprot.ReadMessageEnd() + var err2 error + result := EchoServiceEchoPingPongResult{} + var retval *EchoResponse + if retval, err2 = p.handler.EchoPingPong(ctx, args.Req1, args.Req2); err2 != nil { + switch v := err2.(type) { + case *EchoException: + result.E = v + default: + x := thrift.NewTApplicationException(thrift.INTERNAL_ERROR, "Internal error processing EchoPingPong: "+err2.Error()) + oprot.WriteMessageBegin("EchoPingPong", thrift.EXCEPTION, seqId) + x.Write(oprot) + oprot.WriteMessageEnd() + oprot.Flush(ctx) + return true, err2 + } + } else { + result.Success = retval + } + if err2 = oprot.WriteMessageBegin("EchoPingPong", thrift.REPLY, seqId); err2 != nil { + err = err2 + } + if err2 = result.Write(oprot); err == nil && err2 != nil { + err = err2 + } + if err2 = oprot.WriteMessageEnd(); err == nil && err2 != nil { + err = err2 + } + if err2 = oprot.Flush(ctx); err == nil && err2 != nil { + err = err2 + } + if err != nil { + return + } + return true, err +} + +type echoServiceProcessorEchoOneway struct { + handler EchoService +} + +func (p *echoServiceProcessorEchoOneway) Process(ctx context.Context, seqId int32, iprot, oprot thrift.TProtocol) (success bool, err thrift.TException) { + args := EchoServiceEchoOnewayArgs{} + if err = args.Read(iprot); err != nil { + iprot.ReadMessageEnd() + x := thrift.NewTApplicationException(thrift.PROTOCOL_ERROR, err.Error()) + oprot.WriteMessageBegin("EchoOneway", thrift.EXCEPTION, seqId) + x.Write(oprot) + oprot.WriteMessageEnd() + oprot.Flush(ctx) + return false, err + } + + iprot.ReadMessageEnd() + var err2 error + result := EchoServiceEchoOnewayResult{} + if err2 = p.handler.EchoOneway(ctx, args.Req1); err2 != nil { + x := thrift.NewTApplicationException(thrift.INTERNAL_ERROR, "Internal error processing EchoOneway: "+err2.Error()) + oprot.WriteMessageBegin("EchoOneway", thrift.EXCEPTION, seqId) + x.Write(oprot) + oprot.WriteMessageEnd() + oprot.Flush(ctx) + return true, err2 + } + if err2 = oprot.WriteMessageBegin("EchoOneway", thrift.REPLY, seqId); err2 != nil { + err = err2 + } + if err2 = result.Write(oprot); err == nil && err2 != nil { + err = err2 + } + if err2 = oprot.WriteMessageEnd(); err == nil && err2 != nil { + err = err2 + } + if err2 = oprot.Flush(ctx); err == nil && err2 != nil { + err = err2 + } + if err != nil { + return + } + return true, err +} + +type echoServiceProcessorPing struct { + handler EchoService +} + +func (p *echoServiceProcessorPing) Process(ctx context.Context, seqId int32, iprot, oprot thrift.TProtocol) (success bool, err thrift.TException) { + args := EchoServicePingArgs{} + if err = args.Read(iprot); err != nil { + iprot.ReadMessageEnd() + x := thrift.NewTApplicationException(thrift.PROTOCOL_ERROR, err.Error()) + oprot.WriteMessageBegin("Ping", thrift.EXCEPTION, seqId) + x.Write(oprot) + oprot.WriteMessageEnd() + oprot.Flush(ctx) + return false, err + } + + iprot.ReadMessageEnd() + var err2 error + result := EchoServicePingResult{} + if err2 = p.handler.Ping(ctx); err2 != nil { + x := thrift.NewTApplicationException(thrift.INTERNAL_ERROR, "Internal error processing Ping: "+err2.Error()) + oprot.WriteMessageBegin("Ping", thrift.EXCEPTION, seqId) + x.Write(oprot) + oprot.WriteMessageEnd() + oprot.Flush(ctx) + return true, err2 + } + if err2 = oprot.WriteMessageBegin("Ping", thrift.REPLY, seqId); err2 != nil { + err = err2 + } + if err2 = result.Write(oprot); err == nil && err2 != nil { + err = err2 + } + if err2 = oprot.WriteMessageEnd(); err == nil && err2 != nil { + err = err2 + } + if err2 = oprot.Flush(ctx); err == nil && err2 != nil { + err = err2 + } + if err != nil { + return + } + return true, err +} + +type EchoServiceEchoBidirectionalArgs struct { + Req1 *EchoRequest `thrift:"req1,1" frugal:"1,default,EchoRequest" json:"req1"` +} + +func NewEchoServiceEchoBidirectionalArgs() *EchoServiceEchoBidirectionalArgs { + return &EchoServiceEchoBidirectionalArgs{} +} + +func (p *EchoServiceEchoBidirectionalArgs) InitDefault() { + *p = EchoServiceEchoBidirectionalArgs{} +} + +var EchoServiceEchoBidirectionalArgs_Req1_DEFAULT *EchoRequest + +func (p *EchoServiceEchoBidirectionalArgs) GetReq1() (v *EchoRequest) { + if !p.IsSetReq1() { + return EchoServiceEchoBidirectionalArgs_Req1_DEFAULT + } + return p.Req1 +} +func (p *EchoServiceEchoBidirectionalArgs) SetReq1(val *EchoRequest) { + p.Req1 = val +} + +var fieldIDToName_EchoServiceEchoBidirectionalArgs = map[int16]string{ + 1: "req1", +} + +func (p *EchoServiceEchoBidirectionalArgs) IsSetReq1() bool { + return p.Req1 != nil +} + +func (p *EchoServiceEchoBidirectionalArgs) Read(iprot thrift.TProtocol) (err error) { + + var fieldTypeId thrift.TType + var fieldId int16 + + if _, err = iprot.ReadStructBegin(); err != nil { + goto ReadStructBeginError + } + + for { + _, fieldTypeId, fieldId, err = iprot.ReadFieldBegin() + if err != nil { + goto ReadFieldBeginError + } + if fieldTypeId == thrift.STOP { + break + } + + switch fieldId { + case 1: + if fieldTypeId == thrift.STRUCT { + if err = p.ReadField1(iprot); err != nil { + goto ReadFieldError + } + } else if err = iprot.Skip(fieldTypeId); err != nil { + goto SkipFieldError + } + default: + if err = iprot.Skip(fieldTypeId); err != nil { + goto SkipFieldError + } + } + if err = iprot.ReadFieldEnd(); err != nil { + goto ReadFieldEndError + } + } + if err = iprot.ReadStructEnd(); err != nil { + goto ReadStructEndError + } + + return nil +ReadStructBeginError: + return thrift.PrependError(fmt.Sprintf("%T read struct begin error: ", p), err) +ReadFieldBeginError: + return thrift.PrependError(fmt.Sprintf("%T read field %d begin error: ", p, fieldId), err) +ReadFieldError: + return thrift.PrependError(fmt.Sprintf("%T read field %d '%s' error: ", p, fieldId, fieldIDToName_EchoServiceEchoBidirectionalArgs[fieldId]), err) +SkipFieldError: + return thrift.PrependError(fmt.Sprintf("%T field %d skip type %d error: ", p, fieldId, fieldTypeId), err) + +ReadFieldEndError: + return thrift.PrependError(fmt.Sprintf("%T read field end error", p), err) +ReadStructEndError: + return thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err) +} + +func (p *EchoServiceEchoBidirectionalArgs) ReadField1(iprot thrift.TProtocol) error { + p.Req1 = NewEchoRequest() + if err := p.Req1.Read(iprot); err != nil { + return err + } + return nil +} + +func (p *EchoServiceEchoBidirectionalArgs) Write(oprot thrift.TProtocol) (err error) { + var fieldId int16 + if err = oprot.WriteStructBegin("EchoBidirectional_args"); err != nil { + goto WriteStructBeginError + } + if p != nil { + if err = p.writeField1(oprot); err != nil { + fieldId = 1 + goto WriteFieldError + } + } + if err = oprot.WriteFieldStop(); err != nil { + goto WriteFieldStopError + } + if err = oprot.WriteStructEnd(); err != nil { + goto WriteStructEndError + } + return nil +WriteStructBeginError: + return thrift.PrependError(fmt.Sprintf("%T write struct begin error: ", p), err) +WriteFieldError: + return thrift.PrependError(fmt.Sprintf("%T write field %d error: ", p, fieldId), err) +WriteFieldStopError: + return thrift.PrependError(fmt.Sprintf("%T write field stop error: ", p), err) +WriteStructEndError: + return thrift.PrependError(fmt.Sprintf("%T write struct end error: ", p), err) +} + +func (p *EchoServiceEchoBidirectionalArgs) writeField1(oprot thrift.TProtocol) (err error) { + if err = oprot.WriteFieldBegin("req1", thrift.STRUCT, 1); err != nil { + goto WriteFieldBeginError + } + if err := p.Req1.Write(oprot); err != nil { + return err + } + if err = oprot.WriteFieldEnd(); err != nil { + goto WriteFieldEndError + } + return nil +WriteFieldBeginError: + return thrift.PrependError(fmt.Sprintf("%T write field 1 begin error: ", p), err) +WriteFieldEndError: + return thrift.PrependError(fmt.Sprintf("%T write field 1 end error: ", p), err) +} + +func (p *EchoServiceEchoBidirectionalArgs) String() string { + if p == nil { + return "" + } + return fmt.Sprintf("EchoServiceEchoBidirectionalArgs(%+v)", *p) + +} + +func (p *EchoServiceEchoBidirectionalArgs) DeepEqual(ano *EchoServiceEchoBidirectionalArgs) bool { + if p == ano { + return true + } else if p == nil || ano == nil { + return false + } + if !p.Field1DeepEqual(ano.Req1) { + return false + } + return true +} + +func (p *EchoServiceEchoBidirectionalArgs) Field1DeepEqual(src *EchoRequest) bool { + + if !p.Req1.DeepEqual(src) { + return false + } + return true +} + +type EchoServiceEchoBidirectionalResult struct { + Success *EchoResponse `thrift:"success,0,optional" frugal:"0,optional,EchoResponse" json:"success,omitempty"` +} + +func NewEchoServiceEchoBidirectionalResult() *EchoServiceEchoBidirectionalResult { + return &EchoServiceEchoBidirectionalResult{} +} + +func (p *EchoServiceEchoBidirectionalResult) InitDefault() { + *p = EchoServiceEchoBidirectionalResult{} +} + +var EchoServiceEchoBidirectionalResult_Success_DEFAULT *EchoResponse + +func (p *EchoServiceEchoBidirectionalResult) GetSuccess() (v *EchoResponse) { + if !p.IsSetSuccess() { + return EchoServiceEchoBidirectionalResult_Success_DEFAULT + } + return p.Success +} +func (p *EchoServiceEchoBidirectionalResult) SetSuccess(x interface{}) { + p.Success = x.(*EchoResponse) +} + +var fieldIDToName_EchoServiceEchoBidirectionalResult = map[int16]string{ + 0: "success", +} + +func (p *EchoServiceEchoBidirectionalResult) IsSetSuccess() bool { + return p.Success != nil +} + +func (p *EchoServiceEchoBidirectionalResult) Read(iprot thrift.TProtocol) (err error) { + + var fieldTypeId thrift.TType + var fieldId int16 + + if _, err = iprot.ReadStructBegin(); err != nil { + goto ReadStructBeginError + } + + for { + _, fieldTypeId, fieldId, err = iprot.ReadFieldBegin() + if err != nil { + goto ReadFieldBeginError + } + if fieldTypeId == thrift.STOP { + break + } + + switch fieldId { + case 0: + if fieldTypeId == thrift.STRUCT { + if err = p.ReadField0(iprot); err != nil { + goto ReadFieldError + } + } else if err = iprot.Skip(fieldTypeId); err != nil { + goto SkipFieldError + } + default: + if err = iprot.Skip(fieldTypeId); err != nil { + goto SkipFieldError + } + } + if err = iprot.ReadFieldEnd(); err != nil { + goto ReadFieldEndError + } + } + if err = iprot.ReadStructEnd(); err != nil { + goto ReadStructEndError + } + + return nil +ReadStructBeginError: + return thrift.PrependError(fmt.Sprintf("%T read struct begin error: ", p), err) +ReadFieldBeginError: + return thrift.PrependError(fmt.Sprintf("%T read field %d begin error: ", p, fieldId), err) +ReadFieldError: + return thrift.PrependError(fmt.Sprintf("%T read field %d '%s' error: ", p, fieldId, fieldIDToName_EchoServiceEchoBidirectionalResult[fieldId]), err) +SkipFieldError: + return thrift.PrependError(fmt.Sprintf("%T field %d skip type %d error: ", p, fieldId, fieldTypeId), err) + +ReadFieldEndError: + return thrift.PrependError(fmt.Sprintf("%T read field end error", p), err) +ReadStructEndError: + return thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err) +} + +func (p *EchoServiceEchoBidirectionalResult) ReadField0(iprot thrift.TProtocol) error { + p.Success = NewEchoResponse() + if err := p.Success.Read(iprot); err != nil { + return err + } + return nil +} + +func (p *EchoServiceEchoBidirectionalResult) Write(oprot thrift.TProtocol) (err error) { + var fieldId int16 + if err = oprot.WriteStructBegin("EchoBidirectional_result"); err != nil { + goto WriteStructBeginError + } + if p != nil { + if err = p.writeField0(oprot); err != nil { + fieldId = 0 + goto WriteFieldError + } + } + if err = oprot.WriteFieldStop(); err != nil { + goto WriteFieldStopError + } + if err = oprot.WriteStructEnd(); err != nil { + goto WriteStructEndError + } + return nil +WriteStructBeginError: + return thrift.PrependError(fmt.Sprintf("%T write struct begin error: ", p), err) +WriteFieldError: + return thrift.PrependError(fmt.Sprintf("%T write field %d error: ", p, fieldId), err) +WriteFieldStopError: + return thrift.PrependError(fmt.Sprintf("%T write field stop error: ", p), err) +WriteStructEndError: + return thrift.PrependError(fmt.Sprintf("%T write struct end error: ", p), err) +} + +func (p *EchoServiceEchoBidirectionalResult) writeField0(oprot thrift.TProtocol) (err error) { + if p.IsSetSuccess() { + if err = oprot.WriteFieldBegin("success", thrift.STRUCT, 0); err != nil { + goto WriteFieldBeginError + } + if err := p.Success.Write(oprot); err != nil { + return err + } + if err = oprot.WriteFieldEnd(); err != nil { + goto WriteFieldEndError + } + } + return nil +WriteFieldBeginError: + return thrift.PrependError(fmt.Sprintf("%T write field 0 begin error: ", p), err) +WriteFieldEndError: + return thrift.PrependError(fmt.Sprintf("%T write field 0 end error: ", p), err) +} + +func (p *EchoServiceEchoBidirectionalResult) String() string { + if p == nil { + return "" + } + return fmt.Sprintf("EchoServiceEchoBidirectionalResult(%+v)", *p) + +} + +func (p *EchoServiceEchoBidirectionalResult) DeepEqual(ano *EchoServiceEchoBidirectionalResult) bool { + if p == ano { + return true + } else if p == nil || ano == nil { + return false + } + if !p.Field0DeepEqual(ano.Success) { + return false + } + return true +} + +func (p *EchoServiceEchoBidirectionalResult) Field0DeepEqual(src *EchoResponse) bool { + + if !p.Success.DeepEqual(src) { + return false + } + return true +} + +type EchoServiceEchoClientArgs struct { + Req1 *EchoRequest `thrift:"req1,1" frugal:"1,default,EchoRequest" json:"req1"` +} + +func NewEchoServiceEchoClientArgs() *EchoServiceEchoClientArgs { + return &EchoServiceEchoClientArgs{} +} + +func (p *EchoServiceEchoClientArgs) InitDefault() { + *p = EchoServiceEchoClientArgs{} +} + +var EchoServiceEchoClientArgs_Req1_DEFAULT *EchoRequest + +func (p *EchoServiceEchoClientArgs) GetReq1() (v *EchoRequest) { + if !p.IsSetReq1() { + return EchoServiceEchoClientArgs_Req1_DEFAULT + } + return p.Req1 +} +func (p *EchoServiceEchoClientArgs) SetReq1(val *EchoRequest) { + p.Req1 = val +} + +var fieldIDToName_EchoServiceEchoClientArgs = map[int16]string{ + 1: "req1", +} + +func (p *EchoServiceEchoClientArgs) IsSetReq1() bool { + return p.Req1 != nil +} + +func (p *EchoServiceEchoClientArgs) Read(iprot thrift.TProtocol) (err error) { + + var fieldTypeId thrift.TType + var fieldId int16 + + if _, err = iprot.ReadStructBegin(); err != nil { + goto ReadStructBeginError + } + + for { + _, fieldTypeId, fieldId, err = iprot.ReadFieldBegin() + if err != nil { + goto ReadFieldBeginError + } + if fieldTypeId == thrift.STOP { + break + } + + switch fieldId { + case 1: + if fieldTypeId == thrift.STRUCT { + if err = p.ReadField1(iprot); err != nil { + goto ReadFieldError + } + } else if err = iprot.Skip(fieldTypeId); err != nil { + goto SkipFieldError + } + default: + if err = iprot.Skip(fieldTypeId); err != nil { + goto SkipFieldError + } + } + if err = iprot.ReadFieldEnd(); err != nil { + goto ReadFieldEndError + } + } + if err = iprot.ReadStructEnd(); err != nil { + goto ReadStructEndError + } + + return nil +ReadStructBeginError: + return thrift.PrependError(fmt.Sprintf("%T read struct begin error: ", p), err) +ReadFieldBeginError: + return thrift.PrependError(fmt.Sprintf("%T read field %d begin error: ", p, fieldId), err) +ReadFieldError: + return thrift.PrependError(fmt.Sprintf("%T read field %d '%s' error: ", p, fieldId, fieldIDToName_EchoServiceEchoClientArgs[fieldId]), err) +SkipFieldError: + return thrift.PrependError(fmt.Sprintf("%T field %d skip type %d error: ", p, fieldId, fieldTypeId), err) + +ReadFieldEndError: + return thrift.PrependError(fmt.Sprintf("%T read field end error", p), err) +ReadStructEndError: + return thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err) +} + +func (p *EchoServiceEchoClientArgs) ReadField1(iprot thrift.TProtocol) error { + p.Req1 = NewEchoRequest() + if err := p.Req1.Read(iprot); err != nil { + return err + } + return nil +} + +func (p *EchoServiceEchoClientArgs) Write(oprot thrift.TProtocol) (err error) { + var fieldId int16 + if err = oprot.WriteStructBegin("EchoClient_args"); err != nil { + goto WriteStructBeginError + } + if p != nil { + if err = p.writeField1(oprot); err != nil { + fieldId = 1 + goto WriteFieldError + } + } + if err = oprot.WriteFieldStop(); err != nil { + goto WriteFieldStopError + } + if err = oprot.WriteStructEnd(); err != nil { + goto WriteStructEndError + } + return nil +WriteStructBeginError: + return thrift.PrependError(fmt.Sprintf("%T write struct begin error: ", p), err) +WriteFieldError: + return thrift.PrependError(fmt.Sprintf("%T write field %d error: ", p, fieldId), err) +WriteFieldStopError: + return thrift.PrependError(fmt.Sprintf("%T write field stop error: ", p), err) +WriteStructEndError: + return thrift.PrependError(fmt.Sprintf("%T write struct end error: ", p), err) +} + +func (p *EchoServiceEchoClientArgs) writeField1(oprot thrift.TProtocol) (err error) { + if err = oprot.WriteFieldBegin("req1", thrift.STRUCT, 1); err != nil { + goto WriteFieldBeginError + } + if err := p.Req1.Write(oprot); err != nil { + return err + } + if err = oprot.WriteFieldEnd(); err != nil { + goto WriteFieldEndError + } + return nil +WriteFieldBeginError: + return thrift.PrependError(fmt.Sprintf("%T write field 1 begin error: ", p), err) +WriteFieldEndError: + return thrift.PrependError(fmt.Sprintf("%T write field 1 end error: ", p), err) +} + +func (p *EchoServiceEchoClientArgs) String() string { + if p == nil { + return "" + } + return fmt.Sprintf("EchoServiceEchoClientArgs(%+v)", *p) + +} + +func (p *EchoServiceEchoClientArgs) DeepEqual(ano *EchoServiceEchoClientArgs) bool { + if p == ano { + return true + } else if p == nil || ano == nil { + return false + } + if !p.Field1DeepEqual(ano.Req1) { + return false + } + return true +} + +func (p *EchoServiceEchoClientArgs) Field1DeepEqual(src *EchoRequest) bool { + + if !p.Req1.DeepEqual(src) { + return false + } + return true +} + +type EchoServiceEchoClientResult struct { + Success *EchoResponse `thrift:"success,0,optional" frugal:"0,optional,EchoResponse" json:"success,omitempty"` +} + +func NewEchoServiceEchoClientResult() *EchoServiceEchoClientResult { + return &EchoServiceEchoClientResult{} +} + +func (p *EchoServiceEchoClientResult) InitDefault() { + *p = EchoServiceEchoClientResult{} +} + +var EchoServiceEchoClientResult_Success_DEFAULT *EchoResponse + +func (p *EchoServiceEchoClientResult) GetSuccess() (v *EchoResponse) { + if !p.IsSetSuccess() { + return EchoServiceEchoClientResult_Success_DEFAULT + } + return p.Success +} +func (p *EchoServiceEchoClientResult) SetSuccess(x interface{}) { + p.Success = x.(*EchoResponse) +} + +var fieldIDToName_EchoServiceEchoClientResult = map[int16]string{ + 0: "success", +} + +func (p *EchoServiceEchoClientResult) IsSetSuccess() bool { + return p.Success != nil +} + +func (p *EchoServiceEchoClientResult) Read(iprot thrift.TProtocol) (err error) { + + var fieldTypeId thrift.TType + var fieldId int16 + + if _, err = iprot.ReadStructBegin(); err != nil { + goto ReadStructBeginError + } + + for { + _, fieldTypeId, fieldId, err = iprot.ReadFieldBegin() + if err != nil { + goto ReadFieldBeginError + } + if fieldTypeId == thrift.STOP { + break + } + + switch fieldId { + case 0: + if fieldTypeId == thrift.STRUCT { + if err = p.ReadField0(iprot); err != nil { + goto ReadFieldError + } + } else if err = iprot.Skip(fieldTypeId); err != nil { + goto SkipFieldError + } + default: + if err = iprot.Skip(fieldTypeId); err != nil { + goto SkipFieldError + } + } + if err = iprot.ReadFieldEnd(); err != nil { + goto ReadFieldEndError + } + } + if err = iprot.ReadStructEnd(); err != nil { + goto ReadStructEndError + } + + return nil +ReadStructBeginError: + return thrift.PrependError(fmt.Sprintf("%T read struct begin error: ", p), err) +ReadFieldBeginError: + return thrift.PrependError(fmt.Sprintf("%T read field %d begin error: ", p, fieldId), err) +ReadFieldError: + return thrift.PrependError(fmt.Sprintf("%T read field %d '%s' error: ", p, fieldId, fieldIDToName_EchoServiceEchoClientResult[fieldId]), err) +SkipFieldError: + return thrift.PrependError(fmt.Sprintf("%T field %d skip type %d error: ", p, fieldId, fieldTypeId), err) + +ReadFieldEndError: + return thrift.PrependError(fmt.Sprintf("%T read field end error", p), err) +ReadStructEndError: + return thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err) +} + +func (p *EchoServiceEchoClientResult) ReadField0(iprot thrift.TProtocol) error { + p.Success = NewEchoResponse() + if err := p.Success.Read(iprot); err != nil { + return err + } + return nil +} + +func (p *EchoServiceEchoClientResult) Write(oprot thrift.TProtocol) (err error) { + var fieldId int16 + if err = oprot.WriteStructBegin("EchoClient_result"); err != nil { + goto WriteStructBeginError + } + if p != nil { + if err = p.writeField0(oprot); err != nil { + fieldId = 0 + goto WriteFieldError + } + } + if err = oprot.WriteFieldStop(); err != nil { + goto WriteFieldStopError + } + if err = oprot.WriteStructEnd(); err != nil { + goto WriteStructEndError + } + return nil +WriteStructBeginError: + return thrift.PrependError(fmt.Sprintf("%T write struct begin error: ", p), err) +WriteFieldError: + return thrift.PrependError(fmt.Sprintf("%T write field %d error: ", p, fieldId), err) +WriteFieldStopError: + return thrift.PrependError(fmt.Sprintf("%T write field stop error: ", p), err) +WriteStructEndError: + return thrift.PrependError(fmt.Sprintf("%T write struct end error: ", p), err) +} + +func (p *EchoServiceEchoClientResult) writeField0(oprot thrift.TProtocol) (err error) { + if p.IsSetSuccess() { + if err = oprot.WriteFieldBegin("success", thrift.STRUCT, 0); err != nil { + goto WriteFieldBeginError + } + if err := p.Success.Write(oprot); err != nil { + return err + } + if err = oprot.WriteFieldEnd(); err != nil { + goto WriteFieldEndError + } + } + return nil +WriteFieldBeginError: + return thrift.PrependError(fmt.Sprintf("%T write field 0 begin error: ", p), err) +WriteFieldEndError: + return thrift.PrependError(fmt.Sprintf("%T write field 0 end error: ", p), err) +} + +func (p *EchoServiceEchoClientResult) String() string { + if p == nil { + return "" + } + return fmt.Sprintf("EchoServiceEchoClientResult(%+v)", *p) + +} + +func (p *EchoServiceEchoClientResult) DeepEqual(ano *EchoServiceEchoClientResult) bool { + if p == ano { + return true + } else if p == nil || ano == nil { + return false + } + if !p.Field0DeepEqual(ano.Success) { + return false + } + return true +} + +func (p *EchoServiceEchoClientResult) Field0DeepEqual(src *EchoResponse) bool { + + if !p.Success.DeepEqual(src) { + return false + } + return true +} + +type EchoServiceEchoServerArgs struct { + Req1 *EchoRequest `thrift:"req1,1" frugal:"1,default,EchoRequest" json:"req1"` +} + +func NewEchoServiceEchoServerArgs() *EchoServiceEchoServerArgs { + return &EchoServiceEchoServerArgs{} +} + +func (p *EchoServiceEchoServerArgs) InitDefault() { + *p = EchoServiceEchoServerArgs{} +} + +var EchoServiceEchoServerArgs_Req1_DEFAULT *EchoRequest + +func (p *EchoServiceEchoServerArgs) GetReq1() (v *EchoRequest) { + if !p.IsSetReq1() { + return EchoServiceEchoServerArgs_Req1_DEFAULT + } + return p.Req1 +} +func (p *EchoServiceEchoServerArgs) SetReq1(val *EchoRequest) { + p.Req1 = val +} + +var fieldIDToName_EchoServiceEchoServerArgs = map[int16]string{ + 1: "req1", +} + +func (p *EchoServiceEchoServerArgs) IsSetReq1() bool { + return p.Req1 != nil +} + +func (p *EchoServiceEchoServerArgs) Read(iprot thrift.TProtocol) (err error) { + + var fieldTypeId thrift.TType + var fieldId int16 + + if _, err = iprot.ReadStructBegin(); err != nil { + goto ReadStructBeginError + } + + for { + _, fieldTypeId, fieldId, err = iprot.ReadFieldBegin() + if err != nil { + goto ReadFieldBeginError + } + if fieldTypeId == thrift.STOP { + break + } + + switch fieldId { + case 1: + if fieldTypeId == thrift.STRUCT { + if err = p.ReadField1(iprot); err != nil { + goto ReadFieldError + } + } else if err = iprot.Skip(fieldTypeId); err != nil { + goto SkipFieldError + } + default: + if err = iprot.Skip(fieldTypeId); err != nil { + goto SkipFieldError + } + } + if err = iprot.ReadFieldEnd(); err != nil { + goto ReadFieldEndError + } + } + if err = iprot.ReadStructEnd(); err != nil { + goto ReadStructEndError + } + + return nil +ReadStructBeginError: + return thrift.PrependError(fmt.Sprintf("%T read struct begin error: ", p), err) +ReadFieldBeginError: + return thrift.PrependError(fmt.Sprintf("%T read field %d begin error: ", p, fieldId), err) +ReadFieldError: + return thrift.PrependError(fmt.Sprintf("%T read field %d '%s' error: ", p, fieldId, fieldIDToName_EchoServiceEchoServerArgs[fieldId]), err) +SkipFieldError: + return thrift.PrependError(fmt.Sprintf("%T field %d skip type %d error: ", p, fieldId, fieldTypeId), err) + +ReadFieldEndError: + return thrift.PrependError(fmt.Sprintf("%T read field end error", p), err) +ReadStructEndError: + return thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err) +} + +func (p *EchoServiceEchoServerArgs) ReadField1(iprot thrift.TProtocol) error { + p.Req1 = NewEchoRequest() + if err := p.Req1.Read(iprot); err != nil { + return err + } + return nil +} + +func (p *EchoServiceEchoServerArgs) Write(oprot thrift.TProtocol) (err error) { + var fieldId int16 + if err = oprot.WriteStructBegin("EchoServer_args"); err != nil { + goto WriteStructBeginError + } + if p != nil { + if err = p.writeField1(oprot); err != nil { + fieldId = 1 + goto WriteFieldError + } + } + if err = oprot.WriteFieldStop(); err != nil { + goto WriteFieldStopError + } + if err = oprot.WriteStructEnd(); err != nil { + goto WriteStructEndError + } + return nil +WriteStructBeginError: + return thrift.PrependError(fmt.Sprintf("%T write struct begin error: ", p), err) +WriteFieldError: + return thrift.PrependError(fmt.Sprintf("%T write field %d error: ", p, fieldId), err) +WriteFieldStopError: + return thrift.PrependError(fmt.Sprintf("%T write field stop error: ", p), err) +WriteStructEndError: + return thrift.PrependError(fmt.Sprintf("%T write struct end error: ", p), err) +} + +func (p *EchoServiceEchoServerArgs) writeField1(oprot thrift.TProtocol) (err error) { + if err = oprot.WriteFieldBegin("req1", thrift.STRUCT, 1); err != nil { + goto WriteFieldBeginError + } + if err := p.Req1.Write(oprot); err != nil { + return err + } + if err = oprot.WriteFieldEnd(); err != nil { + goto WriteFieldEndError + } + return nil +WriteFieldBeginError: + return thrift.PrependError(fmt.Sprintf("%T write field 1 begin error: ", p), err) +WriteFieldEndError: + return thrift.PrependError(fmt.Sprintf("%T write field 1 end error: ", p), err) +} + +func (p *EchoServiceEchoServerArgs) String() string { + if p == nil { + return "" + } + return fmt.Sprintf("EchoServiceEchoServerArgs(%+v)", *p) + +} + +func (p *EchoServiceEchoServerArgs) DeepEqual(ano *EchoServiceEchoServerArgs) bool { + if p == ano { + return true + } else if p == nil || ano == nil { + return false + } + if !p.Field1DeepEqual(ano.Req1) { + return false + } + return true +} + +func (p *EchoServiceEchoServerArgs) Field1DeepEqual(src *EchoRequest) bool { + + if !p.Req1.DeepEqual(src) { + return false + } + return true +} + +type EchoServiceEchoServerResult struct { + Success *EchoResponse `thrift:"success,0,optional" frugal:"0,optional,EchoResponse" json:"success,omitempty"` +} + +func NewEchoServiceEchoServerResult() *EchoServiceEchoServerResult { + return &EchoServiceEchoServerResult{} +} + +func (p *EchoServiceEchoServerResult) InitDefault() { + *p = EchoServiceEchoServerResult{} +} + +var EchoServiceEchoServerResult_Success_DEFAULT *EchoResponse + +func (p *EchoServiceEchoServerResult) GetSuccess() (v *EchoResponse) { + if !p.IsSetSuccess() { + return EchoServiceEchoServerResult_Success_DEFAULT + } + return p.Success +} +func (p *EchoServiceEchoServerResult) SetSuccess(x interface{}) { + p.Success = x.(*EchoResponse) +} + +var fieldIDToName_EchoServiceEchoServerResult = map[int16]string{ + 0: "success", +} + +func (p *EchoServiceEchoServerResult) IsSetSuccess() bool { + return p.Success != nil +} + +func (p *EchoServiceEchoServerResult) Read(iprot thrift.TProtocol) (err error) { + + var fieldTypeId thrift.TType + var fieldId int16 + + if _, err = iprot.ReadStructBegin(); err != nil { + goto ReadStructBeginError + } + + for { + _, fieldTypeId, fieldId, err = iprot.ReadFieldBegin() + if err != nil { + goto ReadFieldBeginError + } + if fieldTypeId == thrift.STOP { + break + } + + switch fieldId { + case 0: + if fieldTypeId == thrift.STRUCT { + if err = p.ReadField0(iprot); err != nil { + goto ReadFieldError + } + } else if err = iprot.Skip(fieldTypeId); err != nil { + goto SkipFieldError + } + default: + if err = iprot.Skip(fieldTypeId); err != nil { + goto SkipFieldError + } + } + if err = iprot.ReadFieldEnd(); err != nil { + goto ReadFieldEndError + } + } + if err = iprot.ReadStructEnd(); err != nil { + goto ReadStructEndError + } + + return nil +ReadStructBeginError: + return thrift.PrependError(fmt.Sprintf("%T read struct begin error: ", p), err) +ReadFieldBeginError: + return thrift.PrependError(fmt.Sprintf("%T read field %d begin error: ", p, fieldId), err) +ReadFieldError: + return thrift.PrependError(fmt.Sprintf("%T read field %d '%s' error: ", p, fieldId, fieldIDToName_EchoServiceEchoServerResult[fieldId]), err) +SkipFieldError: + return thrift.PrependError(fmt.Sprintf("%T field %d skip type %d error: ", p, fieldId, fieldTypeId), err) + +ReadFieldEndError: + return thrift.PrependError(fmt.Sprintf("%T read field end error", p), err) +ReadStructEndError: + return thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err) +} + +func (p *EchoServiceEchoServerResult) ReadField0(iprot thrift.TProtocol) error { + p.Success = NewEchoResponse() + if err := p.Success.Read(iprot); err != nil { + return err + } + return nil +} + +func (p *EchoServiceEchoServerResult) Write(oprot thrift.TProtocol) (err error) { + var fieldId int16 + if err = oprot.WriteStructBegin("EchoServer_result"); err != nil { + goto WriteStructBeginError + } + if p != nil { + if err = p.writeField0(oprot); err != nil { + fieldId = 0 + goto WriteFieldError + } + } + if err = oprot.WriteFieldStop(); err != nil { + goto WriteFieldStopError + } + if err = oprot.WriteStructEnd(); err != nil { + goto WriteStructEndError + } + return nil +WriteStructBeginError: + return thrift.PrependError(fmt.Sprintf("%T write struct begin error: ", p), err) +WriteFieldError: + return thrift.PrependError(fmt.Sprintf("%T write field %d error: ", p, fieldId), err) +WriteFieldStopError: + return thrift.PrependError(fmt.Sprintf("%T write field stop error: ", p), err) +WriteStructEndError: + return thrift.PrependError(fmt.Sprintf("%T write struct end error: ", p), err) +} + +func (p *EchoServiceEchoServerResult) writeField0(oprot thrift.TProtocol) (err error) { + if p.IsSetSuccess() { + if err = oprot.WriteFieldBegin("success", thrift.STRUCT, 0); err != nil { + goto WriteFieldBeginError + } + if err := p.Success.Write(oprot); err != nil { + return err + } + if err = oprot.WriteFieldEnd(); err != nil { + goto WriteFieldEndError + } + } + return nil +WriteFieldBeginError: + return thrift.PrependError(fmt.Sprintf("%T write field 0 begin error: ", p), err) +WriteFieldEndError: + return thrift.PrependError(fmt.Sprintf("%T write field 0 end error: ", p), err) +} + +func (p *EchoServiceEchoServerResult) String() string { + if p == nil { + return "" + } + return fmt.Sprintf("EchoServiceEchoServerResult(%+v)", *p) + +} + +func (p *EchoServiceEchoServerResult) DeepEqual(ano *EchoServiceEchoServerResult) bool { + if p == ano { + return true + } else if p == nil || ano == nil { + return false + } + if !p.Field0DeepEqual(ano.Success) { + return false + } + return true +} + +func (p *EchoServiceEchoServerResult) Field0DeepEqual(src *EchoResponse) bool { + + if !p.Success.DeepEqual(src) { + return false + } + return true +} + +type EchoServiceEchoUnaryArgs struct { + Req1 *EchoRequest `thrift:"req1,1" frugal:"1,default,EchoRequest" json:"req1"` +} + +func NewEchoServiceEchoUnaryArgs() *EchoServiceEchoUnaryArgs { + return &EchoServiceEchoUnaryArgs{} +} + +func (p *EchoServiceEchoUnaryArgs) InitDefault() { + *p = EchoServiceEchoUnaryArgs{} +} + +var EchoServiceEchoUnaryArgs_Req1_DEFAULT *EchoRequest + +func (p *EchoServiceEchoUnaryArgs) GetReq1() (v *EchoRequest) { + if !p.IsSetReq1() { + return EchoServiceEchoUnaryArgs_Req1_DEFAULT + } + return p.Req1 +} +func (p *EchoServiceEchoUnaryArgs) SetReq1(val *EchoRequest) { + p.Req1 = val +} + +var fieldIDToName_EchoServiceEchoUnaryArgs = map[int16]string{ + 1: "req1", +} + +func (p *EchoServiceEchoUnaryArgs) IsSetReq1() bool { + return p.Req1 != nil +} + +func (p *EchoServiceEchoUnaryArgs) Read(iprot thrift.TProtocol) (err error) { + + var fieldTypeId thrift.TType + var fieldId int16 + + if _, err = iprot.ReadStructBegin(); err != nil { + goto ReadStructBeginError + } + + for { + _, fieldTypeId, fieldId, err = iprot.ReadFieldBegin() + if err != nil { + goto ReadFieldBeginError + } + if fieldTypeId == thrift.STOP { + break + } + + switch fieldId { + case 1: + if fieldTypeId == thrift.STRUCT { + if err = p.ReadField1(iprot); err != nil { + goto ReadFieldError + } + } else if err = iprot.Skip(fieldTypeId); err != nil { + goto SkipFieldError + } + default: + if err = iprot.Skip(fieldTypeId); err != nil { + goto SkipFieldError + } + } + if err = iprot.ReadFieldEnd(); err != nil { + goto ReadFieldEndError + } + } + if err = iprot.ReadStructEnd(); err != nil { + goto ReadStructEndError + } + + return nil +ReadStructBeginError: + return thrift.PrependError(fmt.Sprintf("%T read struct begin error: ", p), err) +ReadFieldBeginError: + return thrift.PrependError(fmt.Sprintf("%T read field %d begin error: ", p, fieldId), err) +ReadFieldError: + return thrift.PrependError(fmt.Sprintf("%T read field %d '%s' error: ", p, fieldId, fieldIDToName_EchoServiceEchoUnaryArgs[fieldId]), err) +SkipFieldError: + return thrift.PrependError(fmt.Sprintf("%T field %d skip type %d error: ", p, fieldId, fieldTypeId), err) + +ReadFieldEndError: + return thrift.PrependError(fmt.Sprintf("%T read field end error", p), err) +ReadStructEndError: + return thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err) +} + +func (p *EchoServiceEchoUnaryArgs) ReadField1(iprot thrift.TProtocol) error { + p.Req1 = NewEchoRequest() + if err := p.Req1.Read(iprot); err != nil { + return err + } + return nil +} + +func (p *EchoServiceEchoUnaryArgs) Write(oprot thrift.TProtocol) (err error) { + var fieldId int16 + if err = oprot.WriteStructBegin("EchoUnary_args"); err != nil { + goto WriteStructBeginError + } + if p != nil { + if err = p.writeField1(oprot); err != nil { + fieldId = 1 + goto WriteFieldError + } + } + if err = oprot.WriteFieldStop(); err != nil { + goto WriteFieldStopError + } + if err = oprot.WriteStructEnd(); err != nil { + goto WriteStructEndError + } + return nil +WriteStructBeginError: + return thrift.PrependError(fmt.Sprintf("%T write struct begin error: ", p), err) +WriteFieldError: + return thrift.PrependError(fmt.Sprintf("%T write field %d error: ", p, fieldId), err) +WriteFieldStopError: + return thrift.PrependError(fmt.Sprintf("%T write field stop error: ", p), err) +WriteStructEndError: + return thrift.PrependError(fmt.Sprintf("%T write struct end error: ", p), err) +} + +func (p *EchoServiceEchoUnaryArgs) writeField1(oprot thrift.TProtocol) (err error) { + if err = oprot.WriteFieldBegin("req1", thrift.STRUCT, 1); err != nil { + goto WriteFieldBeginError + } + if err := p.Req1.Write(oprot); err != nil { + return err + } + if err = oprot.WriteFieldEnd(); err != nil { + goto WriteFieldEndError + } + return nil +WriteFieldBeginError: + return thrift.PrependError(fmt.Sprintf("%T write field 1 begin error: ", p), err) +WriteFieldEndError: + return thrift.PrependError(fmt.Sprintf("%T write field 1 end error: ", p), err) +} + +func (p *EchoServiceEchoUnaryArgs) String() string { + if p == nil { + return "" + } + return fmt.Sprintf("EchoServiceEchoUnaryArgs(%+v)", *p) + +} + +func (p *EchoServiceEchoUnaryArgs) DeepEqual(ano *EchoServiceEchoUnaryArgs) bool { + if p == ano { + return true + } else if p == nil || ano == nil { + return false + } + if !p.Field1DeepEqual(ano.Req1) { + return false + } + return true +} + +func (p *EchoServiceEchoUnaryArgs) Field1DeepEqual(src *EchoRequest) bool { + + if !p.Req1.DeepEqual(src) { + return false + } + return true +} + +type EchoServiceEchoUnaryResult struct { + Success *EchoResponse `thrift:"success,0,optional" frugal:"0,optional,EchoResponse" json:"success,omitempty"` +} + +func NewEchoServiceEchoUnaryResult() *EchoServiceEchoUnaryResult { + return &EchoServiceEchoUnaryResult{} +} + +func (p *EchoServiceEchoUnaryResult) InitDefault() { + *p = EchoServiceEchoUnaryResult{} +} + +var EchoServiceEchoUnaryResult_Success_DEFAULT *EchoResponse + +func (p *EchoServiceEchoUnaryResult) GetSuccess() (v *EchoResponse) { + if !p.IsSetSuccess() { + return EchoServiceEchoUnaryResult_Success_DEFAULT + } + return p.Success +} +func (p *EchoServiceEchoUnaryResult) SetSuccess(x interface{}) { + p.Success = x.(*EchoResponse) +} + +var fieldIDToName_EchoServiceEchoUnaryResult = map[int16]string{ + 0: "success", +} + +func (p *EchoServiceEchoUnaryResult) IsSetSuccess() bool { + return p.Success != nil +} + +func (p *EchoServiceEchoUnaryResult) Read(iprot thrift.TProtocol) (err error) { + + var fieldTypeId thrift.TType + var fieldId int16 + + if _, err = iprot.ReadStructBegin(); err != nil { + goto ReadStructBeginError + } + + for { + _, fieldTypeId, fieldId, err = iprot.ReadFieldBegin() + if err != nil { + goto ReadFieldBeginError + } + if fieldTypeId == thrift.STOP { + break + } + + switch fieldId { + case 0: + if fieldTypeId == thrift.STRUCT { + if err = p.ReadField0(iprot); err != nil { + goto ReadFieldError + } + } else if err = iprot.Skip(fieldTypeId); err != nil { + goto SkipFieldError + } + default: + if err = iprot.Skip(fieldTypeId); err != nil { + goto SkipFieldError + } + } + if err = iprot.ReadFieldEnd(); err != nil { + goto ReadFieldEndError + } + } + if err = iprot.ReadStructEnd(); err != nil { + goto ReadStructEndError + } + + return nil +ReadStructBeginError: + return thrift.PrependError(fmt.Sprintf("%T read struct begin error: ", p), err) +ReadFieldBeginError: + return thrift.PrependError(fmt.Sprintf("%T read field %d begin error: ", p, fieldId), err) +ReadFieldError: + return thrift.PrependError(fmt.Sprintf("%T read field %d '%s' error: ", p, fieldId, fieldIDToName_EchoServiceEchoUnaryResult[fieldId]), err) +SkipFieldError: + return thrift.PrependError(fmt.Sprintf("%T field %d skip type %d error: ", p, fieldId, fieldTypeId), err) + +ReadFieldEndError: + return thrift.PrependError(fmt.Sprintf("%T read field end error", p), err) +ReadStructEndError: + return thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err) +} + +func (p *EchoServiceEchoUnaryResult) ReadField0(iprot thrift.TProtocol) error { + p.Success = NewEchoResponse() + if err := p.Success.Read(iprot); err != nil { + return err + } + return nil +} + +func (p *EchoServiceEchoUnaryResult) Write(oprot thrift.TProtocol) (err error) { + var fieldId int16 + if err = oprot.WriteStructBegin("EchoUnary_result"); err != nil { + goto WriteStructBeginError + } + if p != nil { + if err = p.writeField0(oprot); err != nil { + fieldId = 0 + goto WriteFieldError + } + } + if err = oprot.WriteFieldStop(); err != nil { + goto WriteFieldStopError + } + if err = oprot.WriteStructEnd(); err != nil { + goto WriteStructEndError + } + return nil +WriteStructBeginError: + return thrift.PrependError(fmt.Sprintf("%T write struct begin error: ", p), err) +WriteFieldError: + return thrift.PrependError(fmt.Sprintf("%T write field %d error: ", p, fieldId), err) +WriteFieldStopError: + return thrift.PrependError(fmt.Sprintf("%T write field stop error: ", p), err) +WriteStructEndError: + return thrift.PrependError(fmt.Sprintf("%T write struct end error: ", p), err) +} + +func (p *EchoServiceEchoUnaryResult) writeField0(oprot thrift.TProtocol) (err error) { + if p.IsSetSuccess() { + if err = oprot.WriteFieldBegin("success", thrift.STRUCT, 0); err != nil { + goto WriteFieldBeginError + } + if err := p.Success.Write(oprot); err != nil { + return err + } + if err = oprot.WriteFieldEnd(); err != nil { + goto WriteFieldEndError + } + } + return nil +WriteFieldBeginError: + return thrift.PrependError(fmt.Sprintf("%T write field 0 begin error: ", p), err) +WriteFieldEndError: + return thrift.PrependError(fmt.Sprintf("%T write field 0 end error: ", p), err) +} + +func (p *EchoServiceEchoUnaryResult) String() string { + if p == nil { + return "" + } + return fmt.Sprintf("EchoServiceEchoUnaryResult(%+v)", *p) + +} + +func (p *EchoServiceEchoUnaryResult) DeepEqual(ano *EchoServiceEchoUnaryResult) bool { + if p == ano { + return true + } else if p == nil || ano == nil { + return false + } + if !p.Field0DeepEqual(ano.Success) { + return false + } + return true +} + +func (p *EchoServiceEchoUnaryResult) Field0DeepEqual(src *EchoResponse) bool { + + if !p.Success.DeepEqual(src) { + return false + } + return true +} + +type EchoServiceEchoPingPongArgs struct { + Req1 *EchoRequest `thrift:"req1,1" frugal:"1,default,EchoRequest" json:"req1"` + Req2 *EchoRequest `thrift:"req2,2" frugal:"2,default,EchoRequest" json:"req2"` +} + +func NewEchoServiceEchoPingPongArgs() *EchoServiceEchoPingPongArgs { + return &EchoServiceEchoPingPongArgs{} +} + +func (p *EchoServiceEchoPingPongArgs) InitDefault() { + *p = EchoServiceEchoPingPongArgs{} +} + +var EchoServiceEchoPingPongArgs_Req1_DEFAULT *EchoRequest + +func (p *EchoServiceEchoPingPongArgs) GetReq1() (v *EchoRequest) { + if !p.IsSetReq1() { + return EchoServiceEchoPingPongArgs_Req1_DEFAULT + } + return p.Req1 +} + +var EchoServiceEchoPingPongArgs_Req2_DEFAULT *EchoRequest + +func (p *EchoServiceEchoPingPongArgs) GetReq2() (v *EchoRequest) { + if !p.IsSetReq2() { + return EchoServiceEchoPingPongArgs_Req2_DEFAULT + } + return p.Req2 +} +func (p *EchoServiceEchoPingPongArgs) SetReq1(val *EchoRequest) { + p.Req1 = val +} +func (p *EchoServiceEchoPingPongArgs) SetReq2(val *EchoRequest) { + p.Req2 = val +} + +var fieldIDToName_EchoServiceEchoPingPongArgs = map[int16]string{ + 1: "req1", + 2: "req2", +} + +func (p *EchoServiceEchoPingPongArgs) IsSetReq1() bool { + return p.Req1 != nil +} + +func (p *EchoServiceEchoPingPongArgs) IsSetReq2() bool { + return p.Req2 != nil +} + +func (p *EchoServiceEchoPingPongArgs) Read(iprot thrift.TProtocol) (err error) { + + var fieldTypeId thrift.TType + var fieldId int16 + + if _, err = iprot.ReadStructBegin(); err != nil { + goto ReadStructBeginError + } + + for { + _, fieldTypeId, fieldId, err = iprot.ReadFieldBegin() + if err != nil { + goto ReadFieldBeginError + } + if fieldTypeId == thrift.STOP { + break + } + + switch fieldId { + case 1: + if fieldTypeId == thrift.STRUCT { + if err = p.ReadField1(iprot); err != nil { + goto ReadFieldError + } + } else if err = iprot.Skip(fieldTypeId); err != nil { + goto SkipFieldError + } + case 2: + if fieldTypeId == thrift.STRUCT { + if err = p.ReadField2(iprot); err != nil { + goto ReadFieldError + } + } else if err = iprot.Skip(fieldTypeId); err != nil { + goto SkipFieldError + } + default: + if err = iprot.Skip(fieldTypeId); err != nil { + goto SkipFieldError + } + } + if err = iprot.ReadFieldEnd(); err != nil { + goto ReadFieldEndError + } + } + if err = iprot.ReadStructEnd(); err != nil { + goto ReadStructEndError + } + + return nil +ReadStructBeginError: + return thrift.PrependError(fmt.Sprintf("%T read struct begin error: ", p), err) +ReadFieldBeginError: + return thrift.PrependError(fmt.Sprintf("%T read field %d begin error: ", p, fieldId), err) +ReadFieldError: + return thrift.PrependError(fmt.Sprintf("%T read field %d '%s' error: ", p, fieldId, fieldIDToName_EchoServiceEchoPingPongArgs[fieldId]), err) +SkipFieldError: + return thrift.PrependError(fmt.Sprintf("%T field %d skip type %d error: ", p, fieldId, fieldTypeId), err) + +ReadFieldEndError: + return thrift.PrependError(fmt.Sprintf("%T read field end error", p), err) +ReadStructEndError: + return thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err) +} + +func (p *EchoServiceEchoPingPongArgs) ReadField1(iprot thrift.TProtocol) error { + p.Req1 = NewEchoRequest() + if err := p.Req1.Read(iprot); err != nil { + return err + } + return nil +} +func (p *EchoServiceEchoPingPongArgs) ReadField2(iprot thrift.TProtocol) error { + p.Req2 = NewEchoRequest() + if err := p.Req2.Read(iprot); err != nil { + return err + } + return nil +} + +func (p *EchoServiceEchoPingPongArgs) Write(oprot thrift.TProtocol) (err error) { + var fieldId int16 + if err = oprot.WriteStructBegin("EchoPingPong_args"); err != nil { + goto WriteStructBeginError + } + if p != nil { + if err = p.writeField1(oprot); err != nil { + fieldId = 1 + goto WriteFieldError + } + if err = p.writeField2(oprot); err != nil { + fieldId = 2 + goto WriteFieldError + } + } + if err = oprot.WriteFieldStop(); err != nil { + goto WriteFieldStopError + } + if err = oprot.WriteStructEnd(); err != nil { + goto WriteStructEndError + } + return nil +WriteStructBeginError: + return thrift.PrependError(fmt.Sprintf("%T write struct begin error: ", p), err) +WriteFieldError: + return thrift.PrependError(fmt.Sprintf("%T write field %d error: ", p, fieldId), err) +WriteFieldStopError: + return thrift.PrependError(fmt.Sprintf("%T write field stop error: ", p), err) +WriteStructEndError: + return thrift.PrependError(fmt.Sprintf("%T write struct end error: ", p), err) +} + +func (p *EchoServiceEchoPingPongArgs) writeField1(oprot thrift.TProtocol) (err error) { + if err = oprot.WriteFieldBegin("req1", thrift.STRUCT, 1); err != nil { + goto WriteFieldBeginError + } + if err := p.Req1.Write(oprot); err != nil { + return err + } + if err = oprot.WriteFieldEnd(); err != nil { + goto WriteFieldEndError + } + return nil +WriteFieldBeginError: + return thrift.PrependError(fmt.Sprintf("%T write field 1 begin error: ", p), err) +WriteFieldEndError: + return thrift.PrependError(fmt.Sprintf("%T write field 1 end error: ", p), err) +} + +func (p *EchoServiceEchoPingPongArgs) writeField2(oprot thrift.TProtocol) (err error) { + if err = oprot.WriteFieldBegin("req2", thrift.STRUCT, 2); err != nil { + goto WriteFieldBeginError + } + if err := p.Req2.Write(oprot); err != nil { + return err + } + if err = oprot.WriteFieldEnd(); err != nil { + goto WriteFieldEndError + } + return nil +WriteFieldBeginError: + return thrift.PrependError(fmt.Sprintf("%T write field 2 begin error: ", p), err) +WriteFieldEndError: + return thrift.PrependError(fmt.Sprintf("%T write field 2 end error: ", p), err) +} + +func (p *EchoServiceEchoPingPongArgs) String() string { + if p == nil { + return "" + } + return fmt.Sprintf("EchoServiceEchoPingPongArgs(%+v)", *p) + +} + +func (p *EchoServiceEchoPingPongArgs) DeepEqual(ano *EchoServiceEchoPingPongArgs) bool { + if p == ano { + return true + } else if p == nil || ano == nil { + return false + } + if !p.Field1DeepEqual(ano.Req1) { + return false + } + if !p.Field2DeepEqual(ano.Req2) { + return false + } + return true +} + +func (p *EchoServiceEchoPingPongArgs) Field1DeepEqual(src *EchoRequest) bool { + + if !p.Req1.DeepEqual(src) { + return false + } + return true +} +func (p *EchoServiceEchoPingPongArgs) Field2DeepEqual(src *EchoRequest) bool { + + if !p.Req2.DeepEqual(src) { + return false + } + return true +} + +type EchoServiceEchoPingPongResult struct { + Success *EchoResponse `thrift:"success,0,optional" frugal:"0,optional,EchoResponse" json:"success,omitempty"` + E *EchoException `thrift:"e,1,optional" frugal:"1,optional,EchoException" json:"e,omitempty"` +} + +func NewEchoServiceEchoPingPongResult() *EchoServiceEchoPingPongResult { + return &EchoServiceEchoPingPongResult{} +} + +func (p *EchoServiceEchoPingPongResult) InitDefault() { + *p = EchoServiceEchoPingPongResult{} +} + +var EchoServiceEchoPingPongResult_Success_DEFAULT *EchoResponse + +func (p *EchoServiceEchoPingPongResult) GetSuccess() (v *EchoResponse) { + if !p.IsSetSuccess() { + return EchoServiceEchoPingPongResult_Success_DEFAULT + } + return p.Success +} + +var EchoServiceEchoPingPongResult_E_DEFAULT *EchoException + +func (p *EchoServiceEchoPingPongResult) GetE() (v *EchoException) { + if !p.IsSetE() { + return EchoServiceEchoPingPongResult_E_DEFAULT + } + return p.E +} +func (p *EchoServiceEchoPingPongResult) SetSuccess(x interface{}) { + p.Success = x.(*EchoResponse) +} +func (p *EchoServiceEchoPingPongResult) SetE(val *EchoException) { + p.E = val +} + +var fieldIDToName_EchoServiceEchoPingPongResult = map[int16]string{ + 0: "success", + 1: "e", +} + +func (p *EchoServiceEchoPingPongResult) IsSetSuccess() bool { + return p.Success != nil +} + +func (p *EchoServiceEchoPingPongResult) IsSetE() bool { + return p.E != nil +} + +func (p *EchoServiceEchoPingPongResult) Read(iprot thrift.TProtocol) (err error) { + + var fieldTypeId thrift.TType + var fieldId int16 + + if _, err = iprot.ReadStructBegin(); err != nil { + goto ReadStructBeginError + } + + for { + _, fieldTypeId, fieldId, err = iprot.ReadFieldBegin() + if err != nil { + goto ReadFieldBeginError + } + if fieldTypeId == thrift.STOP { + break + } + + switch fieldId { + case 0: + if fieldTypeId == thrift.STRUCT { + if err = p.ReadField0(iprot); err != nil { + goto ReadFieldError + } + } else if err = iprot.Skip(fieldTypeId); err != nil { + goto SkipFieldError + } + case 1: + if fieldTypeId == thrift.STRUCT { + if err = p.ReadField1(iprot); err != nil { + goto ReadFieldError + } + } else if err = iprot.Skip(fieldTypeId); err != nil { + goto SkipFieldError + } + default: + if err = iprot.Skip(fieldTypeId); err != nil { + goto SkipFieldError + } + } + if err = iprot.ReadFieldEnd(); err != nil { + goto ReadFieldEndError + } + } + if err = iprot.ReadStructEnd(); err != nil { + goto ReadStructEndError + } + + return nil +ReadStructBeginError: + return thrift.PrependError(fmt.Sprintf("%T read struct begin error: ", p), err) +ReadFieldBeginError: + return thrift.PrependError(fmt.Sprintf("%T read field %d begin error: ", p, fieldId), err) +ReadFieldError: + return thrift.PrependError(fmt.Sprintf("%T read field %d '%s' error: ", p, fieldId, fieldIDToName_EchoServiceEchoPingPongResult[fieldId]), err) +SkipFieldError: + return thrift.PrependError(fmt.Sprintf("%T field %d skip type %d error: ", p, fieldId, fieldTypeId), err) + +ReadFieldEndError: + return thrift.PrependError(fmt.Sprintf("%T read field end error", p), err) +ReadStructEndError: + return thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err) +} + +func (p *EchoServiceEchoPingPongResult) ReadField0(iprot thrift.TProtocol) error { + p.Success = NewEchoResponse() + if err := p.Success.Read(iprot); err != nil { + return err + } + return nil +} +func (p *EchoServiceEchoPingPongResult) ReadField1(iprot thrift.TProtocol) error { + p.E = NewEchoException() + if err := p.E.Read(iprot); err != nil { + return err + } + return nil +} + +func (p *EchoServiceEchoPingPongResult) Write(oprot thrift.TProtocol) (err error) { + var fieldId int16 + if err = oprot.WriteStructBegin("EchoPingPong_result"); err != nil { + goto WriteStructBeginError + } + if p != nil { + if err = p.writeField0(oprot); err != nil { + fieldId = 0 + goto WriteFieldError + } + if err = p.writeField1(oprot); err != nil { + fieldId = 1 + goto WriteFieldError + } + } + if err = oprot.WriteFieldStop(); err != nil { + goto WriteFieldStopError + } + if err = oprot.WriteStructEnd(); err != nil { + goto WriteStructEndError + } + return nil +WriteStructBeginError: + return thrift.PrependError(fmt.Sprintf("%T write struct begin error: ", p), err) +WriteFieldError: + return thrift.PrependError(fmt.Sprintf("%T write field %d error: ", p, fieldId), err) +WriteFieldStopError: + return thrift.PrependError(fmt.Sprintf("%T write field stop error: ", p), err) +WriteStructEndError: + return thrift.PrependError(fmt.Sprintf("%T write struct end error: ", p), err) +} + +func (p *EchoServiceEchoPingPongResult) writeField0(oprot thrift.TProtocol) (err error) { + if p.IsSetSuccess() { + if err = oprot.WriteFieldBegin("success", thrift.STRUCT, 0); err != nil { + goto WriteFieldBeginError + } + if err := p.Success.Write(oprot); err != nil { + return err + } + if err = oprot.WriteFieldEnd(); err != nil { + goto WriteFieldEndError + } + } + return nil +WriteFieldBeginError: + return thrift.PrependError(fmt.Sprintf("%T write field 0 begin error: ", p), err) +WriteFieldEndError: + return thrift.PrependError(fmt.Sprintf("%T write field 0 end error: ", p), err) +} + +func (p *EchoServiceEchoPingPongResult) writeField1(oprot thrift.TProtocol) (err error) { + if p.IsSetE() { + if err = oprot.WriteFieldBegin("e", thrift.STRUCT, 1); err != nil { + goto WriteFieldBeginError + } + if err := p.E.Write(oprot); err != nil { + return err + } + if err = oprot.WriteFieldEnd(); err != nil { + goto WriteFieldEndError + } + } + return nil +WriteFieldBeginError: + return thrift.PrependError(fmt.Sprintf("%T write field 1 begin error: ", p), err) +WriteFieldEndError: + return thrift.PrependError(fmt.Sprintf("%T write field 1 end error: ", p), err) +} + +func (p *EchoServiceEchoPingPongResult) String() string { + if p == nil { + return "" + } + return fmt.Sprintf("EchoServiceEchoPingPongResult(%+v)", *p) + +} + +func (p *EchoServiceEchoPingPongResult) DeepEqual(ano *EchoServiceEchoPingPongResult) bool { + if p == ano { + return true + } else if p == nil || ano == nil { + return false + } + if !p.Field0DeepEqual(ano.Success) { + return false + } + if !p.Field1DeepEqual(ano.E) { + return false + } + return true +} + +func (p *EchoServiceEchoPingPongResult) Field0DeepEqual(src *EchoResponse) bool { + + if !p.Success.DeepEqual(src) { + return false + } + return true +} +func (p *EchoServiceEchoPingPongResult) Field1DeepEqual(src *EchoException) bool { + + if !p.E.DeepEqual(src) { + return false + } + return true +} + +type EchoServiceEchoOnewayArgs struct { + Req1 *EchoRequest `thrift:"req1,1" frugal:"1,default,EchoRequest" json:"req1"` +} + +func NewEchoServiceEchoOnewayArgs() *EchoServiceEchoOnewayArgs { + return &EchoServiceEchoOnewayArgs{} +} + +func (p *EchoServiceEchoOnewayArgs) InitDefault() { + *p = EchoServiceEchoOnewayArgs{} +} + +var EchoServiceEchoOnewayArgs_Req1_DEFAULT *EchoRequest + +func (p *EchoServiceEchoOnewayArgs) GetReq1() (v *EchoRequest) { + if !p.IsSetReq1() { + return EchoServiceEchoOnewayArgs_Req1_DEFAULT + } + return p.Req1 +} +func (p *EchoServiceEchoOnewayArgs) SetReq1(val *EchoRequest) { + p.Req1 = val +} + +var fieldIDToName_EchoServiceEchoOnewayArgs = map[int16]string{ + 1: "req1", +} + +func (p *EchoServiceEchoOnewayArgs) IsSetReq1() bool { + return p.Req1 != nil +} + +func (p *EchoServiceEchoOnewayArgs) Read(iprot thrift.TProtocol) (err error) { + + var fieldTypeId thrift.TType + var fieldId int16 + + if _, err = iprot.ReadStructBegin(); err != nil { + goto ReadStructBeginError + } + + for { + _, fieldTypeId, fieldId, err = iprot.ReadFieldBegin() + if err != nil { + goto ReadFieldBeginError + } + if fieldTypeId == thrift.STOP { + break + } + + switch fieldId { + case 1: + if fieldTypeId == thrift.STRUCT { + if err = p.ReadField1(iprot); err != nil { + goto ReadFieldError + } + } else if err = iprot.Skip(fieldTypeId); err != nil { + goto SkipFieldError + } + default: + if err = iprot.Skip(fieldTypeId); err != nil { + goto SkipFieldError + } + } + if err = iprot.ReadFieldEnd(); err != nil { + goto ReadFieldEndError + } + } + if err = iprot.ReadStructEnd(); err != nil { + goto ReadStructEndError + } + + return nil +ReadStructBeginError: + return thrift.PrependError(fmt.Sprintf("%T read struct begin error: ", p), err) +ReadFieldBeginError: + return thrift.PrependError(fmt.Sprintf("%T read field %d begin error: ", p, fieldId), err) +ReadFieldError: + return thrift.PrependError(fmt.Sprintf("%T read field %d '%s' error: ", p, fieldId, fieldIDToName_EchoServiceEchoOnewayArgs[fieldId]), err) +SkipFieldError: + return thrift.PrependError(fmt.Sprintf("%T field %d skip type %d error: ", p, fieldId, fieldTypeId), err) + +ReadFieldEndError: + return thrift.PrependError(fmt.Sprintf("%T read field end error", p), err) +ReadStructEndError: + return thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err) +} + +func (p *EchoServiceEchoOnewayArgs) ReadField1(iprot thrift.TProtocol) error { + p.Req1 = NewEchoRequest() + if err := p.Req1.Read(iprot); err != nil { + return err + } + return nil +} + +func (p *EchoServiceEchoOnewayArgs) Write(oprot thrift.TProtocol) (err error) { + var fieldId int16 + if err = oprot.WriteStructBegin("EchoOneway_args"); err != nil { + goto WriteStructBeginError + } + if p != nil { + if err = p.writeField1(oprot); err != nil { + fieldId = 1 + goto WriteFieldError + } + } + if err = oprot.WriteFieldStop(); err != nil { + goto WriteFieldStopError + } + if err = oprot.WriteStructEnd(); err != nil { + goto WriteStructEndError + } + return nil +WriteStructBeginError: + return thrift.PrependError(fmt.Sprintf("%T write struct begin error: ", p), err) +WriteFieldError: + return thrift.PrependError(fmt.Sprintf("%T write field %d error: ", p, fieldId), err) +WriteFieldStopError: + return thrift.PrependError(fmt.Sprintf("%T write field stop error: ", p), err) +WriteStructEndError: + return thrift.PrependError(fmt.Sprintf("%T write struct end error: ", p), err) +} + +func (p *EchoServiceEchoOnewayArgs) writeField1(oprot thrift.TProtocol) (err error) { + if err = oprot.WriteFieldBegin("req1", thrift.STRUCT, 1); err != nil { + goto WriteFieldBeginError + } + if err := p.Req1.Write(oprot); err != nil { + return err + } + if err = oprot.WriteFieldEnd(); err != nil { + goto WriteFieldEndError + } + return nil +WriteFieldBeginError: + return thrift.PrependError(fmt.Sprintf("%T write field 1 begin error: ", p), err) +WriteFieldEndError: + return thrift.PrependError(fmt.Sprintf("%T write field 1 end error: ", p), err) +} + +func (p *EchoServiceEchoOnewayArgs) String() string { + if p == nil { + return "" + } + return fmt.Sprintf("EchoServiceEchoOnewayArgs(%+v)", *p) + +} + +func (p *EchoServiceEchoOnewayArgs) DeepEqual(ano *EchoServiceEchoOnewayArgs) bool { + if p == ano { + return true + } else if p == nil || ano == nil { + return false + } + if !p.Field1DeepEqual(ano.Req1) { + return false + } + return true +} + +func (p *EchoServiceEchoOnewayArgs) Field1DeepEqual(src *EchoRequest) bool { + + if !p.Req1.DeepEqual(src) { + return false + } + return true +} + +type EchoServiceEchoOnewayResult struct { +} + +func NewEchoServiceEchoOnewayResult() *EchoServiceEchoOnewayResult { + return &EchoServiceEchoOnewayResult{} +} + +func (p *EchoServiceEchoOnewayResult) InitDefault() { + *p = EchoServiceEchoOnewayResult{} +} + +var fieldIDToName_EchoServiceEchoOnewayResult = map[int16]string{} + +func (p *EchoServiceEchoOnewayResult) Read(iprot thrift.TProtocol) (err error) { + + var fieldTypeId thrift.TType + var fieldId int16 + + if _, err = iprot.ReadStructBegin(); err != nil { + goto ReadStructBeginError + } + + for { + _, fieldTypeId, fieldId, err = iprot.ReadFieldBegin() + if err != nil { + goto ReadFieldBeginError + } + if fieldTypeId == thrift.STOP { + break + } + if err = iprot.Skip(fieldTypeId); err != nil { + goto SkipFieldTypeError + } + if err = iprot.ReadFieldEnd(); err != nil { + goto ReadFieldEndError + } + } + if err = iprot.ReadStructEnd(); err != nil { + goto ReadStructEndError + } + + return nil +ReadStructBeginError: + return thrift.PrependError(fmt.Sprintf("%T read struct begin error: ", p), err) +ReadFieldBeginError: + return thrift.PrependError(fmt.Sprintf("%T read field %d begin error: ", p, fieldId), err) +SkipFieldTypeError: + return thrift.PrependError(fmt.Sprintf("%T skip field type %d error", p, fieldTypeId), err) + +ReadFieldEndError: + return thrift.PrependError(fmt.Sprintf("%T read field end error", p), err) +ReadStructEndError: + return thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err) +} + +func (p *EchoServiceEchoOnewayResult) Write(oprot thrift.TProtocol) (err error) { + if err = oprot.WriteStructBegin("EchoOneway_result"); err != nil { + goto WriteStructBeginError + } + if p != nil { + } + if err = oprot.WriteFieldStop(); err != nil { + goto WriteFieldStopError + } + if err = oprot.WriteStructEnd(); err != nil { + goto WriteStructEndError + } + return nil +WriteStructBeginError: + return thrift.PrependError(fmt.Sprintf("%T write struct begin error: ", p), err) +WriteFieldStopError: + return thrift.PrependError(fmt.Sprintf("%T write field stop error: ", p), err) +WriteStructEndError: + return thrift.PrependError(fmt.Sprintf("%T write struct end error: ", p), err) +} + +func (p *EchoServiceEchoOnewayResult) String() string { + if p == nil { + return "" + } + return fmt.Sprintf("EchoServiceEchoOnewayResult(%+v)", *p) + +} + +func (p *EchoServiceEchoOnewayResult) DeepEqual(ano *EchoServiceEchoOnewayResult) bool { + if p == ano { + return true + } else if p == nil || ano == nil { + return false + } + return true +} + +type EchoServicePingArgs struct { +} + +func NewEchoServicePingArgs() *EchoServicePingArgs { + return &EchoServicePingArgs{} +} + +func (p *EchoServicePingArgs) InitDefault() { + *p = EchoServicePingArgs{} +} + +var fieldIDToName_EchoServicePingArgs = map[int16]string{} + +func (p *EchoServicePingArgs) Read(iprot thrift.TProtocol) (err error) { + + var fieldTypeId thrift.TType + var fieldId int16 + + if _, err = iprot.ReadStructBegin(); err != nil { + goto ReadStructBeginError + } + + for { + _, fieldTypeId, fieldId, err = iprot.ReadFieldBegin() + if err != nil { + goto ReadFieldBeginError + } + if fieldTypeId == thrift.STOP { + break + } + if err = iprot.Skip(fieldTypeId); err != nil { + goto SkipFieldTypeError + } + if err = iprot.ReadFieldEnd(); err != nil { + goto ReadFieldEndError + } + } + if err = iprot.ReadStructEnd(); err != nil { + goto ReadStructEndError + } + + return nil +ReadStructBeginError: + return thrift.PrependError(fmt.Sprintf("%T read struct begin error: ", p), err) +ReadFieldBeginError: + return thrift.PrependError(fmt.Sprintf("%T read field %d begin error: ", p, fieldId), err) +SkipFieldTypeError: + return thrift.PrependError(fmt.Sprintf("%T skip field type %d error", p, fieldTypeId), err) + +ReadFieldEndError: + return thrift.PrependError(fmt.Sprintf("%T read field end error", p), err) +ReadStructEndError: + return thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err) +} + +func (p *EchoServicePingArgs) Write(oprot thrift.TProtocol) (err error) { + if err = oprot.WriteStructBegin("Ping_args"); err != nil { + goto WriteStructBeginError + } + if p != nil { + } + if err = oprot.WriteFieldStop(); err != nil { + goto WriteFieldStopError + } + if err = oprot.WriteStructEnd(); err != nil { + goto WriteStructEndError + } + return nil +WriteStructBeginError: + return thrift.PrependError(fmt.Sprintf("%T write struct begin error: ", p), err) +WriteFieldStopError: + return thrift.PrependError(fmt.Sprintf("%T write field stop error: ", p), err) +WriteStructEndError: + return thrift.PrependError(fmt.Sprintf("%T write struct end error: ", p), err) +} + +func (p *EchoServicePingArgs) String() string { + if p == nil { + return "" + } + return fmt.Sprintf("EchoServicePingArgs(%+v)", *p) + +} + +func (p *EchoServicePingArgs) DeepEqual(ano *EchoServicePingArgs) bool { + if p == ano { + return true + } else if p == nil || ano == nil { + return false + } + return true +} + +type EchoServicePingResult struct { +} + +func NewEchoServicePingResult() *EchoServicePingResult { + return &EchoServicePingResult{} +} + +func (p *EchoServicePingResult) InitDefault() { + *p = EchoServicePingResult{} +} + +var fieldIDToName_EchoServicePingResult = map[int16]string{} + +func (p *EchoServicePingResult) Read(iprot thrift.TProtocol) (err error) { + + var fieldTypeId thrift.TType + var fieldId int16 + + if _, err = iprot.ReadStructBegin(); err != nil { + goto ReadStructBeginError + } + + for { + _, fieldTypeId, fieldId, err = iprot.ReadFieldBegin() + if err != nil { + goto ReadFieldBeginError + } + if fieldTypeId == thrift.STOP { + break + } + if err = iprot.Skip(fieldTypeId); err != nil { + goto SkipFieldTypeError + } + if err = iprot.ReadFieldEnd(); err != nil { + goto ReadFieldEndError + } + } + if err = iprot.ReadStructEnd(); err != nil { + goto ReadStructEndError + } + + return nil +ReadStructBeginError: + return thrift.PrependError(fmt.Sprintf("%T read struct begin error: ", p), err) +ReadFieldBeginError: + return thrift.PrependError(fmt.Sprintf("%T read field %d begin error: ", p, fieldId), err) +SkipFieldTypeError: + return thrift.PrependError(fmt.Sprintf("%T skip field type %d error", p, fieldTypeId), err) + +ReadFieldEndError: + return thrift.PrependError(fmt.Sprintf("%T read field end error", p), err) +ReadStructEndError: + return thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err) +} + +func (p *EchoServicePingResult) Write(oprot thrift.TProtocol) (err error) { + if err = oprot.WriteStructBegin("Ping_result"); err != nil { + goto WriteStructBeginError + } + if p != nil { + } + if err = oprot.WriteFieldStop(); err != nil { + goto WriteFieldStopError + } + if err = oprot.WriteStructEnd(); err != nil { + goto WriteStructEndError + } + return nil +WriteStructBeginError: + return thrift.PrependError(fmt.Sprintf("%T write struct begin error: ", p), err) +WriteFieldStopError: + return thrift.PrependError(fmt.Sprintf("%T write field stop error: ", p), err) +WriteStructEndError: + return thrift.PrependError(fmt.Sprintf("%T write struct end error: ", p), err) +} + +func (p *EchoServicePingResult) String() string { + if p == nil { + return "" + } + return fmt.Sprintf("EchoServicePingResult(%+v)", *p) + +} + +func (p *EchoServicePingResult) DeepEqual(ano *EchoServicePingResult) bool { + if p == ano { + return true + } else if p == nil || ano == nil { + return false + } + return true +} diff --git a/thrift_streaming/kitex_gen_old/echo/echoservice/client.go b/thrift_streaming/kitex_gen_old/echo/echoservice/client.go new file mode 100644 index 0000000..d8209ad --- /dev/null +++ b/thrift_streaming/kitex_gen_old/echo/echoservice/client.go @@ -0,0 +1,85 @@ +// Code generated by Kitex v0.8.0. DO NOT EDIT. + +package echoservice + +import ( + "context" + echo "github.com/cloudwego/kitex-tests/thrift_streaming/kitex_gen_old/echo" + client "github.com/cloudwego/kitex/client" + callopt "github.com/cloudwego/kitex/client/callopt" +) + +// Client is designed to provide IDL-compatible methods with call-option parameter for kitex framework. +type Client interface { + EchoBidirectional(ctx context.Context, req1 *echo.EchoRequest, callOptions ...callopt.Option) (r *echo.EchoResponse, err error) + EchoClient(ctx context.Context, req1 *echo.EchoRequest, callOptions ...callopt.Option) (r *echo.EchoResponse, err error) + EchoServer(ctx context.Context, req1 *echo.EchoRequest, callOptions ...callopt.Option) (r *echo.EchoResponse, err error) + EchoUnary(ctx context.Context, req1 *echo.EchoRequest, callOptions ...callopt.Option) (r *echo.EchoResponse, err error) + EchoPingPong(ctx context.Context, req1 *echo.EchoRequest, req2 *echo.EchoRequest, callOptions ...callopt.Option) (r *echo.EchoResponse, err error) + EchoOneway(ctx context.Context, req1 *echo.EchoRequest, callOptions ...callopt.Option) (err error) + Ping(ctx context.Context, callOptions ...callopt.Option) (err error) +} + +// NewClient creates a client for the service defined in IDL. +func NewClient(destService string, opts ...client.Option) (Client, error) { + var options []client.Option + options = append(options, client.WithDestService(destService)) + + options = append(options, opts...) + + kc, err := client.NewClient(serviceInfo(), options...) + if err != nil { + return nil, err + } + return &kEchoServiceClient{ + kClient: newServiceClient(kc), + }, nil +} + +// MustNewClient creates a client for the service defined in IDL. It panics if any error occurs. +func MustNewClient(destService string, opts ...client.Option) Client { + kc, err := NewClient(destService, opts...) + if err != nil { + panic(err) + } + return kc +} + +type kEchoServiceClient struct { + *kClient +} + +func (p *kEchoServiceClient) EchoBidirectional(ctx context.Context, req1 *echo.EchoRequest, callOptions ...callopt.Option) (r *echo.EchoResponse, err error) { + ctx = client.NewCtxWithCallOptions(ctx, callOptions) + return p.kClient.EchoBidirectional(ctx, req1) +} + +func (p *kEchoServiceClient) EchoClient(ctx context.Context, req1 *echo.EchoRequest, callOptions ...callopt.Option) (r *echo.EchoResponse, err error) { + ctx = client.NewCtxWithCallOptions(ctx, callOptions) + return p.kClient.EchoClient(ctx, req1) +} + +func (p *kEchoServiceClient) EchoServer(ctx context.Context, req1 *echo.EchoRequest, callOptions ...callopt.Option) (r *echo.EchoResponse, err error) { + ctx = client.NewCtxWithCallOptions(ctx, callOptions) + return p.kClient.EchoServer(ctx, req1) +} + +func (p *kEchoServiceClient) EchoUnary(ctx context.Context, req1 *echo.EchoRequest, callOptions ...callopt.Option) (r *echo.EchoResponse, err error) { + ctx = client.NewCtxWithCallOptions(ctx, callOptions) + return p.kClient.EchoUnary(ctx, req1) +} + +func (p *kEchoServiceClient) EchoPingPong(ctx context.Context, req1 *echo.EchoRequest, req2 *echo.EchoRequest, callOptions ...callopt.Option) (r *echo.EchoResponse, err error) { + ctx = client.NewCtxWithCallOptions(ctx, callOptions) + return p.kClient.EchoPingPong(ctx, req1, req2) +} + +func (p *kEchoServiceClient) EchoOneway(ctx context.Context, req1 *echo.EchoRequest, callOptions ...callopt.Option) (err error) { + ctx = client.NewCtxWithCallOptions(ctx, callOptions) + return p.kClient.EchoOneway(ctx, req1) +} + +func (p *kEchoServiceClient) Ping(ctx context.Context, callOptions ...callopt.Option) (err error) { + ctx = client.NewCtxWithCallOptions(ctx, callOptions) + return p.kClient.Ping(ctx) +} diff --git a/thrift_streaming/kitex_gen_old/echo/echoservice/echoservice.go b/thrift_streaming/kitex_gen_old/echo/echoservice/echoservice.go new file mode 100644 index 0000000..e116532 --- /dev/null +++ b/thrift_streaming/kitex_gen_old/echo/echoservice/echoservice.go @@ -0,0 +1,258 @@ +// Code generated by Kitex v0.8.0. DO NOT EDIT. + +package echoservice + +import ( + "context" + echo "github.com/cloudwego/kitex-tests/thrift_streaming/kitex_gen_old/echo" + client "github.com/cloudwego/kitex/client" + kitex "github.com/cloudwego/kitex/pkg/serviceinfo" +) + +func serviceInfo() *kitex.ServiceInfo { + return echoServiceServiceInfo +} + +var echoServiceServiceInfo = NewServiceInfo() + +func NewServiceInfo() *kitex.ServiceInfo { + serviceName := "EchoService" + handlerType := (*echo.EchoService)(nil) + methods := map[string]kitex.MethodInfo{ + "EchoBidirectional": kitex.NewMethodInfo(echoBidirectionalHandler, newEchoServiceEchoBidirectionalArgs, newEchoServiceEchoBidirectionalResult, false), + "EchoClient": kitex.NewMethodInfo(echoClientHandler, newEchoServiceEchoClientArgs, newEchoServiceEchoClientResult, false), + "EchoServer": kitex.NewMethodInfo(echoServerHandler, newEchoServiceEchoServerArgs, newEchoServiceEchoServerResult, false), + "EchoUnary": kitex.NewMethodInfo(echoUnaryHandler, newEchoServiceEchoUnaryArgs, newEchoServiceEchoUnaryResult, false), + "EchoPingPong": kitex.NewMethodInfo(echoPingPongHandler, newEchoServiceEchoPingPongArgs, newEchoServiceEchoPingPongResult, false), + "EchoOneway": kitex.NewMethodInfo(echoOnewayHandler, newEchoServiceEchoOnewayArgs, newEchoServiceEchoOnewayResult, false), + "Ping": kitex.NewMethodInfo(pingHandler, newEchoServicePingArgs, newEchoServicePingResult, false), + } + extra := map[string]interface{}{ + "PackageName": "echo", + "ServiceFilePath": `idl/api.thrift`, + } + svcInfo := &kitex.ServiceInfo{ + ServiceName: serviceName, + HandlerType: handlerType, + Methods: methods, + PayloadCodec: kitex.Thrift, + KiteXGenVersion: "v0.8.0", + Extra: extra, + } + return svcInfo +} + +func echoBidirectionalHandler(ctx context.Context, handler interface{}, arg, result interface{}) error { + realArg := arg.(*echo.EchoServiceEchoBidirectionalArgs) + realResult := result.(*echo.EchoServiceEchoBidirectionalResult) + success, err := handler.(echo.EchoService).EchoBidirectional(ctx, realArg.Req1) + if err != nil { + return err + } + realResult.Success = success + return nil +} +func newEchoServiceEchoBidirectionalArgs() interface{} { + return echo.NewEchoServiceEchoBidirectionalArgs() +} + +func newEchoServiceEchoBidirectionalResult() interface{} { + return echo.NewEchoServiceEchoBidirectionalResult() +} + +func echoClientHandler(ctx context.Context, handler interface{}, arg, result interface{}) error { + realArg := arg.(*echo.EchoServiceEchoClientArgs) + realResult := result.(*echo.EchoServiceEchoClientResult) + success, err := handler.(echo.EchoService).EchoClient(ctx, realArg.Req1) + if err != nil { + return err + } + realResult.Success = success + return nil +} +func newEchoServiceEchoClientArgs() interface{} { + return echo.NewEchoServiceEchoClientArgs() +} + +func newEchoServiceEchoClientResult() interface{} { + return echo.NewEchoServiceEchoClientResult() +} + +func echoServerHandler(ctx context.Context, handler interface{}, arg, result interface{}) error { + realArg := arg.(*echo.EchoServiceEchoServerArgs) + realResult := result.(*echo.EchoServiceEchoServerResult) + success, err := handler.(echo.EchoService).EchoServer(ctx, realArg.Req1) + if err != nil { + return err + } + realResult.Success = success + return nil +} +func newEchoServiceEchoServerArgs() interface{} { + return echo.NewEchoServiceEchoServerArgs() +} + +func newEchoServiceEchoServerResult() interface{} { + return echo.NewEchoServiceEchoServerResult() +} + +func echoUnaryHandler(ctx context.Context, handler interface{}, arg, result interface{}) error { + realArg := arg.(*echo.EchoServiceEchoUnaryArgs) + realResult := result.(*echo.EchoServiceEchoUnaryResult) + success, err := handler.(echo.EchoService).EchoUnary(ctx, realArg.Req1) + if err != nil { + return err + } + realResult.Success = success + return nil +} +func newEchoServiceEchoUnaryArgs() interface{} { + return echo.NewEchoServiceEchoUnaryArgs() +} + +func newEchoServiceEchoUnaryResult() interface{} { + return echo.NewEchoServiceEchoUnaryResult() +} + +func echoPingPongHandler(ctx context.Context, handler interface{}, arg, result interface{}) error { + realArg := arg.(*echo.EchoServiceEchoPingPongArgs) + realResult := result.(*echo.EchoServiceEchoPingPongResult) + success, err := handler.(echo.EchoService).EchoPingPong(ctx, realArg.Req1, realArg.Req2) + if err != nil { + switch v := err.(type) { + case *echo.EchoException: + realResult.E = v + default: + return err + } + } else { + realResult.Success = success + } + return nil +} +func newEchoServiceEchoPingPongArgs() interface{} { + return echo.NewEchoServiceEchoPingPongArgs() +} + +func newEchoServiceEchoPingPongResult() interface{} { + return echo.NewEchoServiceEchoPingPongResult() +} + +func echoOnewayHandler(ctx context.Context, handler interface{}, arg, result interface{}) error { + realArg := arg.(*echo.EchoServiceEchoOnewayArgs) + + err := handler.(echo.EchoService).EchoOneway(ctx, realArg.Req1) + if err != nil { + return err + } + + return nil +} +func newEchoServiceEchoOnewayArgs() interface{} { + return echo.NewEchoServiceEchoOnewayArgs() +} + +func newEchoServiceEchoOnewayResult() interface{} { + return echo.NewEchoServiceEchoOnewayResult() +} + +func pingHandler(ctx context.Context, handler interface{}, arg, result interface{}) error { + + err := handler.(echo.EchoService).Ping(ctx) + if err != nil { + return err + } + + return nil +} +func newEchoServicePingArgs() interface{} { + return echo.NewEchoServicePingArgs() +} + +func newEchoServicePingResult() interface{} { + return echo.NewEchoServicePingResult() +} + +type kClient struct { + c client.Client +} + +func newServiceClient(c client.Client) *kClient { + return &kClient{ + c: c, + } +} + +func (p *kClient) EchoBidirectional(ctx context.Context, req1 *echo.EchoRequest) (r *echo.EchoResponse, err error) { + var _args echo.EchoServiceEchoBidirectionalArgs + _args.Req1 = req1 + var _result echo.EchoServiceEchoBidirectionalResult + if err = p.c.Call(ctx, "EchoBidirectional", &_args, &_result); err != nil { + return + } + return _result.GetSuccess(), nil +} + +func (p *kClient) EchoClient(ctx context.Context, req1 *echo.EchoRequest) (r *echo.EchoResponse, err error) { + var _args echo.EchoServiceEchoClientArgs + _args.Req1 = req1 + var _result echo.EchoServiceEchoClientResult + if err = p.c.Call(ctx, "EchoClient", &_args, &_result); err != nil { + return + } + return _result.GetSuccess(), nil +} + +func (p *kClient) EchoServer(ctx context.Context, req1 *echo.EchoRequest) (r *echo.EchoResponse, err error) { + var _args echo.EchoServiceEchoServerArgs + _args.Req1 = req1 + var _result echo.EchoServiceEchoServerResult + if err = p.c.Call(ctx, "EchoServer", &_args, &_result); err != nil { + return + } + return _result.GetSuccess(), nil +} + +func (p *kClient) EchoUnary(ctx context.Context, req1 *echo.EchoRequest) (r *echo.EchoResponse, err error) { + var _args echo.EchoServiceEchoUnaryArgs + _args.Req1 = req1 + var _result echo.EchoServiceEchoUnaryResult + if err = p.c.Call(ctx, "EchoUnary", &_args, &_result); err != nil { + return + } + return _result.GetSuccess(), nil +} + +func (p *kClient) EchoPingPong(ctx context.Context, req1 *echo.EchoRequest, req2 *echo.EchoRequest) (r *echo.EchoResponse, err error) { + var _args echo.EchoServiceEchoPingPongArgs + _args.Req1 = req1 + _args.Req2 = req2 + var _result echo.EchoServiceEchoPingPongResult + if err = p.c.Call(ctx, "EchoPingPong", &_args, &_result); err != nil { + return + } + switch { + case _result.E != nil: + return r, _result.E + } + return _result.GetSuccess(), nil +} + +func (p *kClient) EchoOneway(ctx context.Context, req1 *echo.EchoRequest) (err error) { + var _args echo.EchoServiceEchoOnewayArgs + _args.Req1 = req1 + var _result echo.EchoServiceEchoOnewayResult + if err = p.c.Call(ctx, "EchoOneway", &_args, &_result); err != nil { + return + } + return nil +} + +func (p *kClient) Ping(ctx context.Context) (err error) { + var _args echo.EchoServicePingArgs + var _result echo.EchoServicePingResult + if err = p.c.Call(ctx, "Ping", &_args, &_result); err != nil { + return + } + return nil +} diff --git a/thrift_streaming/kitex_gen_old/echo/echoservice/invoker.go b/thrift_streaming/kitex_gen_old/echo/echoservice/invoker.go new file mode 100644 index 0000000..9875a06 --- /dev/null +++ b/thrift_streaming/kitex_gen_old/echo/echoservice/invoker.go @@ -0,0 +1,24 @@ +// Code generated by Kitex v0.8.0. DO NOT EDIT. + +package echoservice + +import ( + echo "github.com/cloudwego/kitex-tests/thrift_streaming/kitex_gen_old/echo" + server "github.com/cloudwego/kitex/server" +) + +// NewInvoker creates a server.Invoker with the given handler and options. +func NewInvoker(handler echo.EchoService, opts ...server.Option) server.Invoker { + var options []server.Option + + options = append(options, opts...) + + s := server.NewInvoker(options...) + if err := s.RegisterService(serviceInfo(), handler); err != nil { + panic(err) + } + if err := s.Init(); err != nil { + panic(err) + } + return s +} diff --git a/thrift_streaming/kitex_gen_old/echo/echoservice/server.go b/thrift_streaming/kitex_gen_old/echo/echoservice/server.go new file mode 100644 index 0000000..9597d55 --- /dev/null +++ b/thrift_streaming/kitex_gen_old/echo/echoservice/server.go @@ -0,0 +1,20 @@ +// Code generated by Kitex v0.8.0. DO NOT EDIT. +package echoservice + +import ( + echo "github.com/cloudwego/kitex-tests/thrift_streaming/kitex_gen_old/echo" + server "github.com/cloudwego/kitex/server" +) + +// NewServer creates a server.Server with the given handler and options. +func NewServer(handler echo.EchoService, opts ...server.Option) server.Server { + var options []server.Option + + options = append(options, opts...) + + svr := server.NewServer(options...) + if err := svr.RegisterService(serviceInfo(), handler); err != nil { + panic(err) + } + return svr +} diff --git a/thrift_streaming/kitex_gen_old/echo/k-api.go b/thrift_streaming/kitex_gen_old/echo/k-api.go new file mode 100644 index 0000000..8d6dc2b --- /dev/null +++ b/thrift_streaming/kitex_gen_old/echo/k-api.go @@ -0,0 +1,2228 @@ +// Code generated by Kitex v0.8.0. DO NOT EDIT. + +package echo + +import ( + "bytes" + "fmt" + "reflect" + "strings" + + "github.com/apache/thrift/lib/go/thrift" + + "github.com/cloudwego/kitex/pkg/protocol/bthrift" +) + +// unused protection +var ( + _ = fmt.Formatter(nil) + _ = (*bytes.Buffer)(nil) + _ = (*strings.Builder)(nil) + _ = reflect.Type(nil) + _ = thrift.TProtocol(nil) + _ = bthrift.BinaryWriter(nil) +) + +func (p *EchoRequest) FastRead(buf []byte) (int, error) { + var err error + var offset int + var l int + var fieldTypeId thrift.TType + var fieldId int16 + var issetMessage bool = false + _, l, err = bthrift.Binary.ReadStructBegin(buf) + offset += l + if err != nil { + goto ReadStructBeginError + } + + for { + _, fieldTypeId, fieldId, l, err = bthrift.Binary.ReadFieldBegin(buf[offset:]) + offset += l + if err != nil { + goto ReadFieldBeginError + } + if fieldTypeId == thrift.STOP { + break + } + switch fieldId { + case 1: + if fieldTypeId == thrift.STRING { + l, err = p.FastReadField1(buf[offset:]) + offset += l + if err != nil { + goto ReadFieldError + } + issetMessage = true + } else { + l, err = bthrift.Binary.Skip(buf[offset:], fieldTypeId) + offset += l + if err != nil { + goto SkipFieldError + } + } + default: + l, err = bthrift.Binary.Skip(buf[offset:], fieldTypeId) + offset += l + if err != nil { + goto SkipFieldError + } + } + + l, err = bthrift.Binary.ReadFieldEnd(buf[offset:]) + offset += l + if err != nil { + goto ReadFieldEndError + } + } + l, err = bthrift.Binary.ReadStructEnd(buf[offset:]) + offset += l + if err != nil { + goto ReadStructEndError + } + + if !issetMessage { + fieldId = 1 + goto RequiredFieldNotSetError + } + return offset, nil +ReadStructBeginError: + return offset, thrift.PrependError(fmt.Sprintf("%T read struct begin error: ", p), err) +ReadFieldBeginError: + return offset, thrift.PrependError(fmt.Sprintf("%T read field %d begin error: ", p, fieldId), err) +ReadFieldError: + return offset, thrift.PrependError(fmt.Sprintf("%T read field %d '%s' error: ", p, fieldId, fieldIDToName_EchoRequest[fieldId]), err) +SkipFieldError: + return offset, thrift.PrependError(fmt.Sprintf("%T field %d skip type %d error: ", p, fieldId, fieldTypeId), err) +ReadFieldEndError: + return offset, thrift.PrependError(fmt.Sprintf("%T read field end error", p), err) +ReadStructEndError: + return offset, thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err) +RequiredFieldNotSetError: + return offset, thrift.NewTProtocolExceptionWithType(thrift.INVALID_DATA, fmt.Errorf("required field %s is not set", fieldIDToName_EchoRequest[fieldId])) +} + +func (p *EchoRequest) FastReadField1(buf []byte) (int, error) { + offset := 0 + + if v, l, err := bthrift.Binary.ReadString(buf[offset:]); err != nil { + return offset, err + } else { + offset += l + + p.Message = v + + } + return offset, nil +} + +// for compatibility +func (p *EchoRequest) FastWrite(buf []byte) int { + return 0 +} + +func (p *EchoRequest) FastWriteNocopy(buf []byte, binaryWriter bthrift.BinaryWriter) int { + offset := 0 + offset += bthrift.Binary.WriteStructBegin(buf[offset:], "EchoRequest") + if p != nil { + offset += p.fastWriteField1(buf[offset:], binaryWriter) + } + offset += bthrift.Binary.WriteFieldStop(buf[offset:]) + offset += bthrift.Binary.WriteStructEnd(buf[offset:]) + return offset +} + +func (p *EchoRequest) BLength() int { + l := 0 + l += bthrift.Binary.StructBeginLength("EchoRequest") + if p != nil { + l += p.field1Length() + } + l += bthrift.Binary.FieldStopLength() + l += bthrift.Binary.StructEndLength() + return l +} + +func (p *EchoRequest) fastWriteField1(buf []byte, binaryWriter bthrift.BinaryWriter) int { + offset := 0 + offset += bthrift.Binary.WriteFieldBegin(buf[offset:], "message", thrift.STRING, 1) + offset += bthrift.Binary.WriteStringNocopy(buf[offset:], binaryWriter, p.Message) + + offset += bthrift.Binary.WriteFieldEnd(buf[offset:]) + return offset +} + +func (p *EchoRequest) field1Length() int { + l := 0 + l += bthrift.Binary.FieldBeginLength("message", thrift.STRING, 1) + l += bthrift.Binary.StringLengthNocopy(p.Message) + + l += bthrift.Binary.FieldEndLength() + return l +} + +func (p *EchoResponse) FastRead(buf []byte) (int, error) { + var err error + var offset int + var l int + var fieldTypeId thrift.TType + var fieldId int16 + var issetMessage bool = false + _, l, err = bthrift.Binary.ReadStructBegin(buf) + offset += l + if err != nil { + goto ReadStructBeginError + } + + for { + _, fieldTypeId, fieldId, l, err = bthrift.Binary.ReadFieldBegin(buf[offset:]) + offset += l + if err != nil { + goto ReadFieldBeginError + } + if fieldTypeId == thrift.STOP { + break + } + switch fieldId { + case 1: + if fieldTypeId == thrift.STRING { + l, err = p.FastReadField1(buf[offset:]) + offset += l + if err != nil { + goto ReadFieldError + } + issetMessage = true + } else { + l, err = bthrift.Binary.Skip(buf[offset:], fieldTypeId) + offset += l + if err != nil { + goto SkipFieldError + } + } + default: + l, err = bthrift.Binary.Skip(buf[offset:], fieldTypeId) + offset += l + if err != nil { + goto SkipFieldError + } + } + + l, err = bthrift.Binary.ReadFieldEnd(buf[offset:]) + offset += l + if err != nil { + goto ReadFieldEndError + } + } + l, err = bthrift.Binary.ReadStructEnd(buf[offset:]) + offset += l + if err != nil { + goto ReadStructEndError + } + + if !issetMessage { + fieldId = 1 + goto RequiredFieldNotSetError + } + return offset, nil +ReadStructBeginError: + return offset, thrift.PrependError(fmt.Sprintf("%T read struct begin error: ", p), err) +ReadFieldBeginError: + return offset, thrift.PrependError(fmt.Sprintf("%T read field %d begin error: ", p, fieldId), err) +ReadFieldError: + return offset, thrift.PrependError(fmt.Sprintf("%T read field %d '%s' error: ", p, fieldId, fieldIDToName_EchoResponse[fieldId]), err) +SkipFieldError: + return offset, thrift.PrependError(fmt.Sprintf("%T field %d skip type %d error: ", p, fieldId, fieldTypeId), err) +ReadFieldEndError: + return offset, thrift.PrependError(fmt.Sprintf("%T read field end error", p), err) +ReadStructEndError: + return offset, thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err) +RequiredFieldNotSetError: + return offset, thrift.NewTProtocolExceptionWithType(thrift.INVALID_DATA, fmt.Errorf("required field %s is not set", fieldIDToName_EchoResponse[fieldId])) +} + +func (p *EchoResponse) FastReadField1(buf []byte) (int, error) { + offset := 0 + + if v, l, err := bthrift.Binary.ReadString(buf[offset:]); err != nil { + return offset, err + } else { + offset += l + + p.Message = v + + } + return offset, nil +} + +// for compatibility +func (p *EchoResponse) FastWrite(buf []byte) int { + return 0 +} + +func (p *EchoResponse) FastWriteNocopy(buf []byte, binaryWriter bthrift.BinaryWriter) int { + offset := 0 + offset += bthrift.Binary.WriteStructBegin(buf[offset:], "EchoResponse") + if p != nil { + offset += p.fastWriteField1(buf[offset:], binaryWriter) + } + offset += bthrift.Binary.WriteFieldStop(buf[offset:]) + offset += bthrift.Binary.WriteStructEnd(buf[offset:]) + return offset +} + +func (p *EchoResponse) BLength() int { + l := 0 + l += bthrift.Binary.StructBeginLength("EchoResponse") + if p != nil { + l += p.field1Length() + } + l += bthrift.Binary.FieldStopLength() + l += bthrift.Binary.StructEndLength() + return l +} + +func (p *EchoResponse) fastWriteField1(buf []byte, binaryWriter bthrift.BinaryWriter) int { + offset := 0 + offset += bthrift.Binary.WriteFieldBegin(buf[offset:], "message", thrift.STRING, 1) + offset += bthrift.Binary.WriteStringNocopy(buf[offset:], binaryWriter, p.Message) + + offset += bthrift.Binary.WriteFieldEnd(buf[offset:]) + return offset +} + +func (p *EchoResponse) field1Length() int { + l := 0 + l += bthrift.Binary.FieldBeginLength("message", thrift.STRING, 1) + l += bthrift.Binary.StringLengthNocopy(p.Message) + + l += bthrift.Binary.FieldEndLength() + return l +} + +func (p *EchoException) FastRead(buf []byte) (int, error) { + var err error + var offset int + var l int + var fieldTypeId thrift.TType + var fieldId int16 + _, l, err = bthrift.Binary.ReadStructBegin(buf) + offset += l + if err != nil { + goto ReadStructBeginError + } + + for { + _, fieldTypeId, fieldId, l, err = bthrift.Binary.ReadFieldBegin(buf[offset:]) + offset += l + if err != nil { + goto ReadFieldBeginError + } + if fieldTypeId == thrift.STOP { + break + } + switch fieldId { + case 1: + if fieldTypeId == thrift.STRING { + l, err = p.FastReadField1(buf[offset:]) + offset += l + if err != nil { + goto ReadFieldError + } + } else { + l, err = bthrift.Binary.Skip(buf[offset:], fieldTypeId) + offset += l + if err != nil { + goto SkipFieldError + } + } + default: + l, err = bthrift.Binary.Skip(buf[offset:], fieldTypeId) + offset += l + if err != nil { + goto SkipFieldError + } + } + + l, err = bthrift.Binary.ReadFieldEnd(buf[offset:]) + offset += l + if err != nil { + goto ReadFieldEndError + } + } + l, err = bthrift.Binary.ReadStructEnd(buf[offset:]) + offset += l + if err != nil { + goto ReadStructEndError + } + + return offset, nil +ReadStructBeginError: + return offset, thrift.PrependError(fmt.Sprintf("%T read struct begin error: ", p), err) +ReadFieldBeginError: + return offset, thrift.PrependError(fmt.Sprintf("%T read field %d begin error: ", p, fieldId), err) +ReadFieldError: + return offset, thrift.PrependError(fmt.Sprintf("%T read field %d '%s' error: ", p, fieldId, fieldIDToName_EchoException[fieldId]), err) +SkipFieldError: + return offset, thrift.PrependError(fmt.Sprintf("%T field %d skip type %d error: ", p, fieldId, fieldTypeId), err) +ReadFieldEndError: + return offset, thrift.PrependError(fmt.Sprintf("%T read field end error", p), err) +ReadStructEndError: + return offset, thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err) +} + +func (p *EchoException) FastReadField1(buf []byte) (int, error) { + offset := 0 + + if v, l, err := bthrift.Binary.ReadString(buf[offset:]); err != nil { + return offset, err + } else { + offset += l + + p.Message = v + + } + return offset, nil +} + +// for compatibility +func (p *EchoException) FastWrite(buf []byte) int { + return 0 +} + +func (p *EchoException) FastWriteNocopy(buf []byte, binaryWriter bthrift.BinaryWriter) int { + offset := 0 + offset += bthrift.Binary.WriteStructBegin(buf[offset:], "EchoException") + if p != nil { + offset += p.fastWriteField1(buf[offset:], binaryWriter) + } + offset += bthrift.Binary.WriteFieldStop(buf[offset:]) + offset += bthrift.Binary.WriteStructEnd(buf[offset:]) + return offset +} + +func (p *EchoException) BLength() int { + l := 0 + l += bthrift.Binary.StructBeginLength("EchoException") + if p != nil { + l += p.field1Length() + } + l += bthrift.Binary.FieldStopLength() + l += bthrift.Binary.StructEndLength() + return l +} + +func (p *EchoException) fastWriteField1(buf []byte, binaryWriter bthrift.BinaryWriter) int { + offset := 0 + offset += bthrift.Binary.WriteFieldBegin(buf[offset:], "message", thrift.STRING, 1) + offset += bthrift.Binary.WriteStringNocopy(buf[offset:], binaryWriter, p.Message) + + offset += bthrift.Binary.WriteFieldEnd(buf[offset:]) + return offset +} + +func (p *EchoException) field1Length() int { + l := 0 + l += bthrift.Binary.FieldBeginLength("message", thrift.STRING, 1) + l += bthrift.Binary.StringLengthNocopy(p.Message) + + l += bthrift.Binary.FieldEndLength() + return l +} + +func (p *EchoServiceEchoBidirectionalArgs) FastRead(buf []byte) (int, error) { + var err error + var offset int + var l int + var fieldTypeId thrift.TType + var fieldId int16 + _, l, err = bthrift.Binary.ReadStructBegin(buf) + offset += l + if err != nil { + goto ReadStructBeginError + } + + for { + _, fieldTypeId, fieldId, l, err = bthrift.Binary.ReadFieldBegin(buf[offset:]) + offset += l + if err != nil { + goto ReadFieldBeginError + } + if fieldTypeId == thrift.STOP { + break + } + switch fieldId { + case 1: + if fieldTypeId == thrift.STRUCT { + l, err = p.FastReadField1(buf[offset:]) + offset += l + if err != nil { + goto ReadFieldError + } + } else { + l, err = bthrift.Binary.Skip(buf[offset:], fieldTypeId) + offset += l + if err != nil { + goto SkipFieldError + } + } + default: + l, err = bthrift.Binary.Skip(buf[offset:], fieldTypeId) + offset += l + if err != nil { + goto SkipFieldError + } + } + + l, err = bthrift.Binary.ReadFieldEnd(buf[offset:]) + offset += l + if err != nil { + goto ReadFieldEndError + } + } + l, err = bthrift.Binary.ReadStructEnd(buf[offset:]) + offset += l + if err != nil { + goto ReadStructEndError + } + + return offset, nil +ReadStructBeginError: + return offset, thrift.PrependError(fmt.Sprintf("%T read struct begin error: ", p), err) +ReadFieldBeginError: + return offset, thrift.PrependError(fmt.Sprintf("%T read field %d begin error: ", p, fieldId), err) +ReadFieldError: + return offset, thrift.PrependError(fmt.Sprintf("%T read field %d '%s' error: ", p, fieldId, fieldIDToName_EchoServiceEchoBidirectionalArgs[fieldId]), err) +SkipFieldError: + return offset, thrift.PrependError(fmt.Sprintf("%T field %d skip type %d error: ", p, fieldId, fieldTypeId), err) +ReadFieldEndError: + return offset, thrift.PrependError(fmt.Sprintf("%T read field end error", p), err) +ReadStructEndError: + return offset, thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err) +} + +func (p *EchoServiceEchoBidirectionalArgs) FastReadField1(buf []byte) (int, error) { + offset := 0 + + tmp := NewEchoRequest() + if l, err := tmp.FastRead(buf[offset:]); err != nil { + return offset, err + } else { + offset += l + } + p.Req1 = tmp + return offset, nil +} + +// for compatibility +func (p *EchoServiceEchoBidirectionalArgs) FastWrite(buf []byte) int { + return 0 +} + +func (p *EchoServiceEchoBidirectionalArgs) FastWriteNocopy(buf []byte, binaryWriter bthrift.BinaryWriter) int { + offset := 0 + offset += bthrift.Binary.WriteStructBegin(buf[offset:], "EchoBidirectional_args") + if p != nil { + offset += p.fastWriteField1(buf[offset:], binaryWriter) + } + offset += bthrift.Binary.WriteFieldStop(buf[offset:]) + offset += bthrift.Binary.WriteStructEnd(buf[offset:]) + return offset +} + +func (p *EchoServiceEchoBidirectionalArgs) BLength() int { + l := 0 + l += bthrift.Binary.StructBeginLength("EchoBidirectional_args") + if p != nil { + l += p.field1Length() + } + l += bthrift.Binary.FieldStopLength() + l += bthrift.Binary.StructEndLength() + return l +} + +func (p *EchoServiceEchoBidirectionalArgs) fastWriteField1(buf []byte, binaryWriter bthrift.BinaryWriter) int { + offset := 0 + offset += bthrift.Binary.WriteFieldBegin(buf[offset:], "req1", thrift.STRUCT, 1) + offset += p.Req1.FastWriteNocopy(buf[offset:], binaryWriter) + offset += bthrift.Binary.WriteFieldEnd(buf[offset:]) + return offset +} + +func (p *EchoServiceEchoBidirectionalArgs) field1Length() int { + l := 0 + l += bthrift.Binary.FieldBeginLength("req1", thrift.STRUCT, 1) + l += p.Req1.BLength() + l += bthrift.Binary.FieldEndLength() + return l +} + +func (p *EchoServiceEchoBidirectionalResult) FastRead(buf []byte) (int, error) { + var err error + var offset int + var l int + var fieldTypeId thrift.TType + var fieldId int16 + _, l, err = bthrift.Binary.ReadStructBegin(buf) + offset += l + if err != nil { + goto ReadStructBeginError + } + + for { + _, fieldTypeId, fieldId, l, err = bthrift.Binary.ReadFieldBegin(buf[offset:]) + offset += l + if err != nil { + goto ReadFieldBeginError + } + if fieldTypeId == thrift.STOP { + break + } + switch fieldId { + case 0: + if fieldTypeId == thrift.STRUCT { + l, err = p.FastReadField0(buf[offset:]) + offset += l + if err != nil { + goto ReadFieldError + } + } else { + l, err = bthrift.Binary.Skip(buf[offset:], fieldTypeId) + offset += l + if err != nil { + goto SkipFieldError + } + } + default: + l, err = bthrift.Binary.Skip(buf[offset:], fieldTypeId) + offset += l + if err != nil { + goto SkipFieldError + } + } + + l, err = bthrift.Binary.ReadFieldEnd(buf[offset:]) + offset += l + if err != nil { + goto ReadFieldEndError + } + } + l, err = bthrift.Binary.ReadStructEnd(buf[offset:]) + offset += l + if err != nil { + goto ReadStructEndError + } + + return offset, nil +ReadStructBeginError: + return offset, thrift.PrependError(fmt.Sprintf("%T read struct begin error: ", p), err) +ReadFieldBeginError: + return offset, thrift.PrependError(fmt.Sprintf("%T read field %d begin error: ", p, fieldId), err) +ReadFieldError: + return offset, thrift.PrependError(fmt.Sprintf("%T read field %d '%s' error: ", p, fieldId, fieldIDToName_EchoServiceEchoBidirectionalResult[fieldId]), err) +SkipFieldError: + return offset, thrift.PrependError(fmt.Sprintf("%T field %d skip type %d error: ", p, fieldId, fieldTypeId), err) +ReadFieldEndError: + return offset, thrift.PrependError(fmt.Sprintf("%T read field end error", p), err) +ReadStructEndError: + return offset, thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err) +} + +func (p *EchoServiceEchoBidirectionalResult) FastReadField0(buf []byte) (int, error) { + offset := 0 + + tmp := NewEchoResponse() + if l, err := tmp.FastRead(buf[offset:]); err != nil { + return offset, err + } else { + offset += l + } + p.Success = tmp + return offset, nil +} + +// for compatibility +func (p *EchoServiceEchoBidirectionalResult) FastWrite(buf []byte) int { + return 0 +} + +func (p *EchoServiceEchoBidirectionalResult) FastWriteNocopy(buf []byte, binaryWriter bthrift.BinaryWriter) int { + offset := 0 + offset += bthrift.Binary.WriteStructBegin(buf[offset:], "EchoBidirectional_result") + if p != nil { + offset += p.fastWriteField0(buf[offset:], binaryWriter) + } + offset += bthrift.Binary.WriteFieldStop(buf[offset:]) + offset += bthrift.Binary.WriteStructEnd(buf[offset:]) + return offset +} + +func (p *EchoServiceEchoBidirectionalResult) BLength() int { + l := 0 + l += bthrift.Binary.StructBeginLength("EchoBidirectional_result") + if p != nil { + l += p.field0Length() + } + l += bthrift.Binary.FieldStopLength() + l += bthrift.Binary.StructEndLength() + return l +} + +func (p *EchoServiceEchoBidirectionalResult) fastWriteField0(buf []byte, binaryWriter bthrift.BinaryWriter) int { + offset := 0 + if p.IsSetSuccess() { + offset += bthrift.Binary.WriteFieldBegin(buf[offset:], "success", thrift.STRUCT, 0) + offset += p.Success.FastWriteNocopy(buf[offset:], binaryWriter) + offset += bthrift.Binary.WriteFieldEnd(buf[offset:]) + } + return offset +} + +func (p *EchoServiceEchoBidirectionalResult) field0Length() int { + l := 0 + if p.IsSetSuccess() { + l += bthrift.Binary.FieldBeginLength("success", thrift.STRUCT, 0) + l += p.Success.BLength() + l += bthrift.Binary.FieldEndLength() + } + return l +} + +func (p *EchoServiceEchoClientArgs) FastRead(buf []byte) (int, error) { + var err error + var offset int + var l int + var fieldTypeId thrift.TType + var fieldId int16 + _, l, err = bthrift.Binary.ReadStructBegin(buf) + offset += l + if err != nil { + goto ReadStructBeginError + } + + for { + _, fieldTypeId, fieldId, l, err = bthrift.Binary.ReadFieldBegin(buf[offset:]) + offset += l + if err != nil { + goto ReadFieldBeginError + } + if fieldTypeId == thrift.STOP { + break + } + switch fieldId { + case 1: + if fieldTypeId == thrift.STRUCT { + l, err = p.FastReadField1(buf[offset:]) + offset += l + if err != nil { + goto ReadFieldError + } + } else { + l, err = bthrift.Binary.Skip(buf[offset:], fieldTypeId) + offset += l + if err != nil { + goto SkipFieldError + } + } + default: + l, err = bthrift.Binary.Skip(buf[offset:], fieldTypeId) + offset += l + if err != nil { + goto SkipFieldError + } + } + + l, err = bthrift.Binary.ReadFieldEnd(buf[offset:]) + offset += l + if err != nil { + goto ReadFieldEndError + } + } + l, err = bthrift.Binary.ReadStructEnd(buf[offset:]) + offset += l + if err != nil { + goto ReadStructEndError + } + + return offset, nil +ReadStructBeginError: + return offset, thrift.PrependError(fmt.Sprintf("%T read struct begin error: ", p), err) +ReadFieldBeginError: + return offset, thrift.PrependError(fmt.Sprintf("%T read field %d begin error: ", p, fieldId), err) +ReadFieldError: + return offset, thrift.PrependError(fmt.Sprintf("%T read field %d '%s' error: ", p, fieldId, fieldIDToName_EchoServiceEchoClientArgs[fieldId]), err) +SkipFieldError: + return offset, thrift.PrependError(fmt.Sprintf("%T field %d skip type %d error: ", p, fieldId, fieldTypeId), err) +ReadFieldEndError: + return offset, thrift.PrependError(fmt.Sprintf("%T read field end error", p), err) +ReadStructEndError: + return offset, thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err) +} + +func (p *EchoServiceEchoClientArgs) FastReadField1(buf []byte) (int, error) { + offset := 0 + + tmp := NewEchoRequest() + if l, err := tmp.FastRead(buf[offset:]); err != nil { + return offset, err + } else { + offset += l + } + p.Req1 = tmp + return offset, nil +} + +// for compatibility +func (p *EchoServiceEchoClientArgs) FastWrite(buf []byte) int { + return 0 +} + +func (p *EchoServiceEchoClientArgs) FastWriteNocopy(buf []byte, binaryWriter bthrift.BinaryWriter) int { + offset := 0 + offset += bthrift.Binary.WriteStructBegin(buf[offset:], "EchoClient_args") + if p != nil { + offset += p.fastWriteField1(buf[offset:], binaryWriter) + } + offset += bthrift.Binary.WriteFieldStop(buf[offset:]) + offset += bthrift.Binary.WriteStructEnd(buf[offset:]) + return offset +} + +func (p *EchoServiceEchoClientArgs) BLength() int { + l := 0 + l += bthrift.Binary.StructBeginLength("EchoClient_args") + if p != nil { + l += p.field1Length() + } + l += bthrift.Binary.FieldStopLength() + l += bthrift.Binary.StructEndLength() + return l +} + +func (p *EchoServiceEchoClientArgs) fastWriteField1(buf []byte, binaryWriter bthrift.BinaryWriter) int { + offset := 0 + offset += bthrift.Binary.WriteFieldBegin(buf[offset:], "req1", thrift.STRUCT, 1) + offset += p.Req1.FastWriteNocopy(buf[offset:], binaryWriter) + offset += bthrift.Binary.WriteFieldEnd(buf[offset:]) + return offset +} + +func (p *EchoServiceEchoClientArgs) field1Length() int { + l := 0 + l += bthrift.Binary.FieldBeginLength("req1", thrift.STRUCT, 1) + l += p.Req1.BLength() + l += bthrift.Binary.FieldEndLength() + return l +} + +func (p *EchoServiceEchoClientResult) FastRead(buf []byte) (int, error) { + var err error + var offset int + var l int + var fieldTypeId thrift.TType + var fieldId int16 + _, l, err = bthrift.Binary.ReadStructBegin(buf) + offset += l + if err != nil { + goto ReadStructBeginError + } + + for { + _, fieldTypeId, fieldId, l, err = bthrift.Binary.ReadFieldBegin(buf[offset:]) + offset += l + if err != nil { + goto ReadFieldBeginError + } + if fieldTypeId == thrift.STOP { + break + } + switch fieldId { + case 0: + if fieldTypeId == thrift.STRUCT { + l, err = p.FastReadField0(buf[offset:]) + offset += l + if err != nil { + goto ReadFieldError + } + } else { + l, err = bthrift.Binary.Skip(buf[offset:], fieldTypeId) + offset += l + if err != nil { + goto SkipFieldError + } + } + default: + l, err = bthrift.Binary.Skip(buf[offset:], fieldTypeId) + offset += l + if err != nil { + goto SkipFieldError + } + } + + l, err = bthrift.Binary.ReadFieldEnd(buf[offset:]) + offset += l + if err != nil { + goto ReadFieldEndError + } + } + l, err = bthrift.Binary.ReadStructEnd(buf[offset:]) + offset += l + if err != nil { + goto ReadStructEndError + } + + return offset, nil +ReadStructBeginError: + return offset, thrift.PrependError(fmt.Sprintf("%T read struct begin error: ", p), err) +ReadFieldBeginError: + return offset, thrift.PrependError(fmt.Sprintf("%T read field %d begin error: ", p, fieldId), err) +ReadFieldError: + return offset, thrift.PrependError(fmt.Sprintf("%T read field %d '%s' error: ", p, fieldId, fieldIDToName_EchoServiceEchoClientResult[fieldId]), err) +SkipFieldError: + return offset, thrift.PrependError(fmt.Sprintf("%T field %d skip type %d error: ", p, fieldId, fieldTypeId), err) +ReadFieldEndError: + return offset, thrift.PrependError(fmt.Sprintf("%T read field end error", p), err) +ReadStructEndError: + return offset, thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err) +} + +func (p *EchoServiceEchoClientResult) FastReadField0(buf []byte) (int, error) { + offset := 0 + + tmp := NewEchoResponse() + if l, err := tmp.FastRead(buf[offset:]); err != nil { + return offset, err + } else { + offset += l + } + p.Success = tmp + return offset, nil +} + +// for compatibility +func (p *EchoServiceEchoClientResult) FastWrite(buf []byte) int { + return 0 +} + +func (p *EchoServiceEchoClientResult) FastWriteNocopy(buf []byte, binaryWriter bthrift.BinaryWriter) int { + offset := 0 + offset += bthrift.Binary.WriteStructBegin(buf[offset:], "EchoClient_result") + if p != nil { + offset += p.fastWriteField0(buf[offset:], binaryWriter) + } + offset += bthrift.Binary.WriteFieldStop(buf[offset:]) + offset += bthrift.Binary.WriteStructEnd(buf[offset:]) + return offset +} + +func (p *EchoServiceEchoClientResult) BLength() int { + l := 0 + l += bthrift.Binary.StructBeginLength("EchoClient_result") + if p != nil { + l += p.field0Length() + } + l += bthrift.Binary.FieldStopLength() + l += bthrift.Binary.StructEndLength() + return l +} + +func (p *EchoServiceEchoClientResult) fastWriteField0(buf []byte, binaryWriter bthrift.BinaryWriter) int { + offset := 0 + if p.IsSetSuccess() { + offset += bthrift.Binary.WriteFieldBegin(buf[offset:], "success", thrift.STRUCT, 0) + offset += p.Success.FastWriteNocopy(buf[offset:], binaryWriter) + offset += bthrift.Binary.WriteFieldEnd(buf[offset:]) + } + return offset +} + +func (p *EchoServiceEchoClientResult) field0Length() int { + l := 0 + if p.IsSetSuccess() { + l += bthrift.Binary.FieldBeginLength("success", thrift.STRUCT, 0) + l += p.Success.BLength() + l += bthrift.Binary.FieldEndLength() + } + return l +} + +func (p *EchoServiceEchoServerArgs) FastRead(buf []byte) (int, error) { + var err error + var offset int + var l int + var fieldTypeId thrift.TType + var fieldId int16 + _, l, err = bthrift.Binary.ReadStructBegin(buf) + offset += l + if err != nil { + goto ReadStructBeginError + } + + for { + _, fieldTypeId, fieldId, l, err = bthrift.Binary.ReadFieldBegin(buf[offset:]) + offset += l + if err != nil { + goto ReadFieldBeginError + } + if fieldTypeId == thrift.STOP { + break + } + switch fieldId { + case 1: + if fieldTypeId == thrift.STRUCT { + l, err = p.FastReadField1(buf[offset:]) + offset += l + if err != nil { + goto ReadFieldError + } + } else { + l, err = bthrift.Binary.Skip(buf[offset:], fieldTypeId) + offset += l + if err != nil { + goto SkipFieldError + } + } + default: + l, err = bthrift.Binary.Skip(buf[offset:], fieldTypeId) + offset += l + if err != nil { + goto SkipFieldError + } + } + + l, err = bthrift.Binary.ReadFieldEnd(buf[offset:]) + offset += l + if err != nil { + goto ReadFieldEndError + } + } + l, err = bthrift.Binary.ReadStructEnd(buf[offset:]) + offset += l + if err != nil { + goto ReadStructEndError + } + + return offset, nil +ReadStructBeginError: + return offset, thrift.PrependError(fmt.Sprintf("%T read struct begin error: ", p), err) +ReadFieldBeginError: + return offset, thrift.PrependError(fmt.Sprintf("%T read field %d begin error: ", p, fieldId), err) +ReadFieldError: + return offset, thrift.PrependError(fmt.Sprintf("%T read field %d '%s' error: ", p, fieldId, fieldIDToName_EchoServiceEchoServerArgs[fieldId]), err) +SkipFieldError: + return offset, thrift.PrependError(fmt.Sprintf("%T field %d skip type %d error: ", p, fieldId, fieldTypeId), err) +ReadFieldEndError: + return offset, thrift.PrependError(fmt.Sprintf("%T read field end error", p), err) +ReadStructEndError: + return offset, thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err) +} + +func (p *EchoServiceEchoServerArgs) FastReadField1(buf []byte) (int, error) { + offset := 0 + + tmp := NewEchoRequest() + if l, err := tmp.FastRead(buf[offset:]); err != nil { + return offset, err + } else { + offset += l + } + p.Req1 = tmp + return offset, nil +} + +// for compatibility +func (p *EchoServiceEchoServerArgs) FastWrite(buf []byte) int { + return 0 +} + +func (p *EchoServiceEchoServerArgs) FastWriteNocopy(buf []byte, binaryWriter bthrift.BinaryWriter) int { + offset := 0 + offset += bthrift.Binary.WriteStructBegin(buf[offset:], "EchoServer_args") + if p != nil { + offset += p.fastWriteField1(buf[offset:], binaryWriter) + } + offset += bthrift.Binary.WriteFieldStop(buf[offset:]) + offset += bthrift.Binary.WriteStructEnd(buf[offset:]) + return offset +} + +func (p *EchoServiceEchoServerArgs) BLength() int { + l := 0 + l += bthrift.Binary.StructBeginLength("EchoServer_args") + if p != nil { + l += p.field1Length() + } + l += bthrift.Binary.FieldStopLength() + l += bthrift.Binary.StructEndLength() + return l +} + +func (p *EchoServiceEchoServerArgs) fastWriteField1(buf []byte, binaryWriter bthrift.BinaryWriter) int { + offset := 0 + offset += bthrift.Binary.WriteFieldBegin(buf[offset:], "req1", thrift.STRUCT, 1) + offset += p.Req1.FastWriteNocopy(buf[offset:], binaryWriter) + offset += bthrift.Binary.WriteFieldEnd(buf[offset:]) + return offset +} + +func (p *EchoServiceEchoServerArgs) field1Length() int { + l := 0 + l += bthrift.Binary.FieldBeginLength("req1", thrift.STRUCT, 1) + l += p.Req1.BLength() + l += bthrift.Binary.FieldEndLength() + return l +} + +func (p *EchoServiceEchoServerResult) FastRead(buf []byte) (int, error) { + var err error + var offset int + var l int + var fieldTypeId thrift.TType + var fieldId int16 + _, l, err = bthrift.Binary.ReadStructBegin(buf) + offset += l + if err != nil { + goto ReadStructBeginError + } + + for { + _, fieldTypeId, fieldId, l, err = bthrift.Binary.ReadFieldBegin(buf[offset:]) + offset += l + if err != nil { + goto ReadFieldBeginError + } + if fieldTypeId == thrift.STOP { + break + } + switch fieldId { + case 0: + if fieldTypeId == thrift.STRUCT { + l, err = p.FastReadField0(buf[offset:]) + offset += l + if err != nil { + goto ReadFieldError + } + } else { + l, err = bthrift.Binary.Skip(buf[offset:], fieldTypeId) + offset += l + if err != nil { + goto SkipFieldError + } + } + default: + l, err = bthrift.Binary.Skip(buf[offset:], fieldTypeId) + offset += l + if err != nil { + goto SkipFieldError + } + } + + l, err = bthrift.Binary.ReadFieldEnd(buf[offset:]) + offset += l + if err != nil { + goto ReadFieldEndError + } + } + l, err = bthrift.Binary.ReadStructEnd(buf[offset:]) + offset += l + if err != nil { + goto ReadStructEndError + } + + return offset, nil +ReadStructBeginError: + return offset, thrift.PrependError(fmt.Sprintf("%T read struct begin error: ", p), err) +ReadFieldBeginError: + return offset, thrift.PrependError(fmt.Sprintf("%T read field %d begin error: ", p, fieldId), err) +ReadFieldError: + return offset, thrift.PrependError(fmt.Sprintf("%T read field %d '%s' error: ", p, fieldId, fieldIDToName_EchoServiceEchoServerResult[fieldId]), err) +SkipFieldError: + return offset, thrift.PrependError(fmt.Sprintf("%T field %d skip type %d error: ", p, fieldId, fieldTypeId), err) +ReadFieldEndError: + return offset, thrift.PrependError(fmt.Sprintf("%T read field end error", p), err) +ReadStructEndError: + return offset, thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err) +} + +func (p *EchoServiceEchoServerResult) FastReadField0(buf []byte) (int, error) { + offset := 0 + + tmp := NewEchoResponse() + if l, err := tmp.FastRead(buf[offset:]); err != nil { + return offset, err + } else { + offset += l + } + p.Success = tmp + return offset, nil +} + +// for compatibility +func (p *EchoServiceEchoServerResult) FastWrite(buf []byte) int { + return 0 +} + +func (p *EchoServiceEchoServerResult) FastWriteNocopy(buf []byte, binaryWriter bthrift.BinaryWriter) int { + offset := 0 + offset += bthrift.Binary.WriteStructBegin(buf[offset:], "EchoServer_result") + if p != nil { + offset += p.fastWriteField0(buf[offset:], binaryWriter) + } + offset += bthrift.Binary.WriteFieldStop(buf[offset:]) + offset += bthrift.Binary.WriteStructEnd(buf[offset:]) + return offset +} + +func (p *EchoServiceEchoServerResult) BLength() int { + l := 0 + l += bthrift.Binary.StructBeginLength("EchoServer_result") + if p != nil { + l += p.field0Length() + } + l += bthrift.Binary.FieldStopLength() + l += bthrift.Binary.StructEndLength() + return l +} + +func (p *EchoServiceEchoServerResult) fastWriteField0(buf []byte, binaryWriter bthrift.BinaryWriter) int { + offset := 0 + if p.IsSetSuccess() { + offset += bthrift.Binary.WriteFieldBegin(buf[offset:], "success", thrift.STRUCT, 0) + offset += p.Success.FastWriteNocopy(buf[offset:], binaryWriter) + offset += bthrift.Binary.WriteFieldEnd(buf[offset:]) + } + return offset +} + +func (p *EchoServiceEchoServerResult) field0Length() int { + l := 0 + if p.IsSetSuccess() { + l += bthrift.Binary.FieldBeginLength("success", thrift.STRUCT, 0) + l += p.Success.BLength() + l += bthrift.Binary.FieldEndLength() + } + return l +} + +func (p *EchoServiceEchoUnaryArgs) FastRead(buf []byte) (int, error) { + var err error + var offset int + var l int + var fieldTypeId thrift.TType + var fieldId int16 + _, l, err = bthrift.Binary.ReadStructBegin(buf) + offset += l + if err != nil { + goto ReadStructBeginError + } + + for { + _, fieldTypeId, fieldId, l, err = bthrift.Binary.ReadFieldBegin(buf[offset:]) + offset += l + if err != nil { + goto ReadFieldBeginError + } + if fieldTypeId == thrift.STOP { + break + } + switch fieldId { + case 1: + if fieldTypeId == thrift.STRUCT { + l, err = p.FastReadField1(buf[offset:]) + offset += l + if err != nil { + goto ReadFieldError + } + } else { + l, err = bthrift.Binary.Skip(buf[offset:], fieldTypeId) + offset += l + if err != nil { + goto SkipFieldError + } + } + default: + l, err = bthrift.Binary.Skip(buf[offset:], fieldTypeId) + offset += l + if err != nil { + goto SkipFieldError + } + } + + l, err = bthrift.Binary.ReadFieldEnd(buf[offset:]) + offset += l + if err != nil { + goto ReadFieldEndError + } + } + l, err = bthrift.Binary.ReadStructEnd(buf[offset:]) + offset += l + if err != nil { + goto ReadStructEndError + } + + return offset, nil +ReadStructBeginError: + return offset, thrift.PrependError(fmt.Sprintf("%T read struct begin error: ", p), err) +ReadFieldBeginError: + return offset, thrift.PrependError(fmt.Sprintf("%T read field %d begin error: ", p, fieldId), err) +ReadFieldError: + return offset, thrift.PrependError(fmt.Sprintf("%T read field %d '%s' error: ", p, fieldId, fieldIDToName_EchoServiceEchoUnaryArgs[fieldId]), err) +SkipFieldError: + return offset, thrift.PrependError(fmt.Sprintf("%T field %d skip type %d error: ", p, fieldId, fieldTypeId), err) +ReadFieldEndError: + return offset, thrift.PrependError(fmt.Sprintf("%T read field end error", p), err) +ReadStructEndError: + return offset, thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err) +} + +func (p *EchoServiceEchoUnaryArgs) FastReadField1(buf []byte) (int, error) { + offset := 0 + + tmp := NewEchoRequest() + if l, err := tmp.FastRead(buf[offset:]); err != nil { + return offset, err + } else { + offset += l + } + p.Req1 = tmp + return offset, nil +} + +// for compatibility +func (p *EchoServiceEchoUnaryArgs) FastWrite(buf []byte) int { + return 0 +} + +func (p *EchoServiceEchoUnaryArgs) FastWriteNocopy(buf []byte, binaryWriter bthrift.BinaryWriter) int { + offset := 0 + offset += bthrift.Binary.WriteStructBegin(buf[offset:], "EchoUnary_args") + if p != nil { + offset += p.fastWriteField1(buf[offset:], binaryWriter) + } + offset += bthrift.Binary.WriteFieldStop(buf[offset:]) + offset += bthrift.Binary.WriteStructEnd(buf[offset:]) + return offset +} + +func (p *EchoServiceEchoUnaryArgs) BLength() int { + l := 0 + l += bthrift.Binary.StructBeginLength("EchoUnary_args") + if p != nil { + l += p.field1Length() + } + l += bthrift.Binary.FieldStopLength() + l += bthrift.Binary.StructEndLength() + return l +} + +func (p *EchoServiceEchoUnaryArgs) fastWriteField1(buf []byte, binaryWriter bthrift.BinaryWriter) int { + offset := 0 + offset += bthrift.Binary.WriteFieldBegin(buf[offset:], "req1", thrift.STRUCT, 1) + offset += p.Req1.FastWriteNocopy(buf[offset:], binaryWriter) + offset += bthrift.Binary.WriteFieldEnd(buf[offset:]) + return offset +} + +func (p *EchoServiceEchoUnaryArgs) field1Length() int { + l := 0 + l += bthrift.Binary.FieldBeginLength("req1", thrift.STRUCT, 1) + l += p.Req1.BLength() + l += bthrift.Binary.FieldEndLength() + return l +} + +func (p *EchoServiceEchoUnaryResult) FastRead(buf []byte) (int, error) { + var err error + var offset int + var l int + var fieldTypeId thrift.TType + var fieldId int16 + _, l, err = bthrift.Binary.ReadStructBegin(buf) + offset += l + if err != nil { + goto ReadStructBeginError + } + + for { + _, fieldTypeId, fieldId, l, err = bthrift.Binary.ReadFieldBegin(buf[offset:]) + offset += l + if err != nil { + goto ReadFieldBeginError + } + if fieldTypeId == thrift.STOP { + break + } + switch fieldId { + case 0: + if fieldTypeId == thrift.STRUCT { + l, err = p.FastReadField0(buf[offset:]) + offset += l + if err != nil { + goto ReadFieldError + } + } else { + l, err = bthrift.Binary.Skip(buf[offset:], fieldTypeId) + offset += l + if err != nil { + goto SkipFieldError + } + } + default: + l, err = bthrift.Binary.Skip(buf[offset:], fieldTypeId) + offset += l + if err != nil { + goto SkipFieldError + } + } + + l, err = bthrift.Binary.ReadFieldEnd(buf[offset:]) + offset += l + if err != nil { + goto ReadFieldEndError + } + } + l, err = bthrift.Binary.ReadStructEnd(buf[offset:]) + offset += l + if err != nil { + goto ReadStructEndError + } + + return offset, nil +ReadStructBeginError: + return offset, thrift.PrependError(fmt.Sprintf("%T read struct begin error: ", p), err) +ReadFieldBeginError: + return offset, thrift.PrependError(fmt.Sprintf("%T read field %d begin error: ", p, fieldId), err) +ReadFieldError: + return offset, thrift.PrependError(fmt.Sprintf("%T read field %d '%s' error: ", p, fieldId, fieldIDToName_EchoServiceEchoUnaryResult[fieldId]), err) +SkipFieldError: + return offset, thrift.PrependError(fmt.Sprintf("%T field %d skip type %d error: ", p, fieldId, fieldTypeId), err) +ReadFieldEndError: + return offset, thrift.PrependError(fmt.Sprintf("%T read field end error", p), err) +ReadStructEndError: + return offset, thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err) +} + +func (p *EchoServiceEchoUnaryResult) FastReadField0(buf []byte) (int, error) { + offset := 0 + + tmp := NewEchoResponse() + if l, err := tmp.FastRead(buf[offset:]); err != nil { + return offset, err + } else { + offset += l + } + p.Success = tmp + return offset, nil +} + +// for compatibility +func (p *EchoServiceEchoUnaryResult) FastWrite(buf []byte) int { + return 0 +} + +func (p *EchoServiceEchoUnaryResult) FastWriteNocopy(buf []byte, binaryWriter bthrift.BinaryWriter) int { + offset := 0 + offset += bthrift.Binary.WriteStructBegin(buf[offset:], "EchoUnary_result") + if p != nil { + offset += p.fastWriteField0(buf[offset:], binaryWriter) + } + offset += bthrift.Binary.WriteFieldStop(buf[offset:]) + offset += bthrift.Binary.WriteStructEnd(buf[offset:]) + return offset +} + +func (p *EchoServiceEchoUnaryResult) BLength() int { + l := 0 + l += bthrift.Binary.StructBeginLength("EchoUnary_result") + if p != nil { + l += p.field0Length() + } + l += bthrift.Binary.FieldStopLength() + l += bthrift.Binary.StructEndLength() + return l +} + +func (p *EchoServiceEchoUnaryResult) fastWriteField0(buf []byte, binaryWriter bthrift.BinaryWriter) int { + offset := 0 + if p.IsSetSuccess() { + offset += bthrift.Binary.WriteFieldBegin(buf[offset:], "success", thrift.STRUCT, 0) + offset += p.Success.FastWriteNocopy(buf[offset:], binaryWriter) + offset += bthrift.Binary.WriteFieldEnd(buf[offset:]) + } + return offset +} + +func (p *EchoServiceEchoUnaryResult) field0Length() int { + l := 0 + if p.IsSetSuccess() { + l += bthrift.Binary.FieldBeginLength("success", thrift.STRUCT, 0) + l += p.Success.BLength() + l += bthrift.Binary.FieldEndLength() + } + return l +} + +func (p *EchoServiceEchoPingPongArgs) FastRead(buf []byte) (int, error) { + var err error + var offset int + var l int + var fieldTypeId thrift.TType + var fieldId int16 + _, l, err = bthrift.Binary.ReadStructBegin(buf) + offset += l + if err != nil { + goto ReadStructBeginError + } + + for { + _, fieldTypeId, fieldId, l, err = bthrift.Binary.ReadFieldBegin(buf[offset:]) + offset += l + if err != nil { + goto ReadFieldBeginError + } + if fieldTypeId == thrift.STOP { + break + } + switch fieldId { + case 1: + if fieldTypeId == thrift.STRUCT { + l, err = p.FastReadField1(buf[offset:]) + offset += l + if err != nil { + goto ReadFieldError + } + } else { + l, err = bthrift.Binary.Skip(buf[offset:], fieldTypeId) + offset += l + if err != nil { + goto SkipFieldError + } + } + case 2: + if fieldTypeId == thrift.STRUCT { + l, err = p.FastReadField2(buf[offset:]) + offset += l + if err != nil { + goto ReadFieldError + } + } else { + l, err = bthrift.Binary.Skip(buf[offset:], fieldTypeId) + offset += l + if err != nil { + goto SkipFieldError + } + } + default: + l, err = bthrift.Binary.Skip(buf[offset:], fieldTypeId) + offset += l + if err != nil { + goto SkipFieldError + } + } + + l, err = bthrift.Binary.ReadFieldEnd(buf[offset:]) + offset += l + if err != nil { + goto ReadFieldEndError + } + } + l, err = bthrift.Binary.ReadStructEnd(buf[offset:]) + offset += l + if err != nil { + goto ReadStructEndError + } + + return offset, nil +ReadStructBeginError: + return offset, thrift.PrependError(fmt.Sprintf("%T read struct begin error: ", p), err) +ReadFieldBeginError: + return offset, thrift.PrependError(fmt.Sprintf("%T read field %d begin error: ", p, fieldId), err) +ReadFieldError: + return offset, thrift.PrependError(fmt.Sprintf("%T read field %d '%s' error: ", p, fieldId, fieldIDToName_EchoServiceEchoPingPongArgs[fieldId]), err) +SkipFieldError: + return offset, thrift.PrependError(fmt.Sprintf("%T field %d skip type %d error: ", p, fieldId, fieldTypeId), err) +ReadFieldEndError: + return offset, thrift.PrependError(fmt.Sprintf("%T read field end error", p), err) +ReadStructEndError: + return offset, thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err) +} + +func (p *EchoServiceEchoPingPongArgs) FastReadField1(buf []byte) (int, error) { + offset := 0 + + tmp := NewEchoRequest() + if l, err := tmp.FastRead(buf[offset:]); err != nil { + return offset, err + } else { + offset += l + } + p.Req1 = tmp + return offset, nil +} + +func (p *EchoServiceEchoPingPongArgs) FastReadField2(buf []byte) (int, error) { + offset := 0 + + tmp := NewEchoRequest() + if l, err := tmp.FastRead(buf[offset:]); err != nil { + return offset, err + } else { + offset += l + } + p.Req2 = tmp + return offset, nil +} + +// for compatibility +func (p *EchoServiceEchoPingPongArgs) FastWrite(buf []byte) int { + return 0 +} + +func (p *EchoServiceEchoPingPongArgs) FastWriteNocopy(buf []byte, binaryWriter bthrift.BinaryWriter) int { + offset := 0 + offset += bthrift.Binary.WriteStructBegin(buf[offset:], "EchoPingPong_args") + if p != nil { + offset += p.fastWriteField1(buf[offset:], binaryWriter) + offset += p.fastWriteField2(buf[offset:], binaryWriter) + } + offset += bthrift.Binary.WriteFieldStop(buf[offset:]) + offset += bthrift.Binary.WriteStructEnd(buf[offset:]) + return offset +} + +func (p *EchoServiceEchoPingPongArgs) BLength() int { + l := 0 + l += bthrift.Binary.StructBeginLength("EchoPingPong_args") + if p != nil { + l += p.field1Length() + l += p.field2Length() + } + l += bthrift.Binary.FieldStopLength() + l += bthrift.Binary.StructEndLength() + return l +} + +func (p *EchoServiceEchoPingPongArgs) fastWriteField1(buf []byte, binaryWriter bthrift.BinaryWriter) int { + offset := 0 + offset += bthrift.Binary.WriteFieldBegin(buf[offset:], "req1", thrift.STRUCT, 1) + offset += p.Req1.FastWriteNocopy(buf[offset:], binaryWriter) + offset += bthrift.Binary.WriteFieldEnd(buf[offset:]) + return offset +} + +func (p *EchoServiceEchoPingPongArgs) fastWriteField2(buf []byte, binaryWriter bthrift.BinaryWriter) int { + offset := 0 + offset += bthrift.Binary.WriteFieldBegin(buf[offset:], "req2", thrift.STRUCT, 2) + offset += p.Req2.FastWriteNocopy(buf[offset:], binaryWriter) + offset += bthrift.Binary.WriteFieldEnd(buf[offset:]) + return offset +} + +func (p *EchoServiceEchoPingPongArgs) field1Length() int { + l := 0 + l += bthrift.Binary.FieldBeginLength("req1", thrift.STRUCT, 1) + l += p.Req1.BLength() + l += bthrift.Binary.FieldEndLength() + return l +} + +func (p *EchoServiceEchoPingPongArgs) field2Length() int { + l := 0 + l += bthrift.Binary.FieldBeginLength("req2", thrift.STRUCT, 2) + l += p.Req2.BLength() + l += bthrift.Binary.FieldEndLength() + return l +} + +func (p *EchoServiceEchoPingPongResult) FastRead(buf []byte) (int, error) { + var err error + var offset int + var l int + var fieldTypeId thrift.TType + var fieldId int16 + _, l, err = bthrift.Binary.ReadStructBegin(buf) + offset += l + if err != nil { + goto ReadStructBeginError + } + + for { + _, fieldTypeId, fieldId, l, err = bthrift.Binary.ReadFieldBegin(buf[offset:]) + offset += l + if err != nil { + goto ReadFieldBeginError + } + if fieldTypeId == thrift.STOP { + break + } + switch fieldId { + case 0: + if fieldTypeId == thrift.STRUCT { + l, err = p.FastReadField0(buf[offset:]) + offset += l + if err != nil { + goto ReadFieldError + } + } else { + l, err = bthrift.Binary.Skip(buf[offset:], fieldTypeId) + offset += l + if err != nil { + goto SkipFieldError + } + } + case 1: + if fieldTypeId == thrift.STRUCT { + l, err = p.FastReadField1(buf[offset:]) + offset += l + if err != nil { + goto ReadFieldError + } + } else { + l, err = bthrift.Binary.Skip(buf[offset:], fieldTypeId) + offset += l + if err != nil { + goto SkipFieldError + } + } + default: + l, err = bthrift.Binary.Skip(buf[offset:], fieldTypeId) + offset += l + if err != nil { + goto SkipFieldError + } + } + + l, err = bthrift.Binary.ReadFieldEnd(buf[offset:]) + offset += l + if err != nil { + goto ReadFieldEndError + } + } + l, err = bthrift.Binary.ReadStructEnd(buf[offset:]) + offset += l + if err != nil { + goto ReadStructEndError + } + + return offset, nil +ReadStructBeginError: + return offset, thrift.PrependError(fmt.Sprintf("%T read struct begin error: ", p), err) +ReadFieldBeginError: + return offset, thrift.PrependError(fmt.Sprintf("%T read field %d begin error: ", p, fieldId), err) +ReadFieldError: + return offset, thrift.PrependError(fmt.Sprintf("%T read field %d '%s' error: ", p, fieldId, fieldIDToName_EchoServiceEchoPingPongResult[fieldId]), err) +SkipFieldError: + return offset, thrift.PrependError(fmt.Sprintf("%T field %d skip type %d error: ", p, fieldId, fieldTypeId), err) +ReadFieldEndError: + return offset, thrift.PrependError(fmt.Sprintf("%T read field end error", p), err) +ReadStructEndError: + return offset, thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err) +} + +func (p *EchoServiceEchoPingPongResult) FastReadField0(buf []byte) (int, error) { + offset := 0 + + tmp := NewEchoResponse() + if l, err := tmp.FastRead(buf[offset:]); err != nil { + return offset, err + } else { + offset += l + } + p.Success = tmp + return offset, nil +} + +func (p *EchoServiceEchoPingPongResult) FastReadField1(buf []byte) (int, error) { + offset := 0 + + tmp := NewEchoException() + if l, err := tmp.FastRead(buf[offset:]); err != nil { + return offset, err + } else { + offset += l + } + p.E = tmp + return offset, nil +} + +// for compatibility +func (p *EchoServiceEchoPingPongResult) FastWrite(buf []byte) int { + return 0 +} + +func (p *EchoServiceEchoPingPongResult) FastWriteNocopy(buf []byte, binaryWriter bthrift.BinaryWriter) int { + offset := 0 + offset += bthrift.Binary.WriteStructBegin(buf[offset:], "EchoPingPong_result") + if p != nil { + offset += p.fastWriteField0(buf[offset:], binaryWriter) + offset += p.fastWriteField1(buf[offset:], binaryWriter) + } + offset += bthrift.Binary.WriteFieldStop(buf[offset:]) + offset += bthrift.Binary.WriteStructEnd(buf[offset:]) + return offset +} + +func (p *EchoServiceEchoPingPongResult) BLength() int { + l := 0 + l += bthrift.Binary.StructBeginLength("EchoPingPong_result") + if p != nil { + l += p.field0Length() + l += p.field1Length() + } + l += bthrift.Binary.FieldStopLength() + l += bthrift.Binary.StructEndLength() + return l +} + +func (p *EchoServiceEchoPingPongResult) fastWriteField0(buf []byte, binaryWriter bthrift.BinaryWriter) int { + offset := 0 + if p.IsSetSuccess() { + offset += bthrift.Binary.WriteFieldBegin(buf[offset:], "success", thrift.STRUCT, 0) + offset += p.Success.FastWriteNocopy(buf[offset:], binaryWriter) + offset += bthrift.Binary.WriteFieldEnd(buf[offset:]) + } + return offset +} + +func (p *EchoServiceEchoPingPongResult) fastWriteField1(buf []byte, binaryWriter bthrift.BinaryWriter) int { + offset := 0 + if p.IsSetE() { + offset += bthrift.Binary.WriteFieldBegin(buf[offset:], "e", thrift.STRUCT, 1) + offset += p.E.FastWriteNocopy(buf[offset:], binaryWriter) + offset += bthrift.Binary.WriteFieldEnd(buf[offset:]) + } + return offset +} + +func (p *EchoServiceEchoPingPongResult) field0Length() int { + l := 0 + if p.IsSetSuccess() { + l += bthrift.Binary.FieldBeginLength("success", thrift.STRUCT, 0) + l += p.Success.BLength() + l += bthrift.Binary.FieldEndLength() + } + return l +} + +func (p *EchoServiceEchoPingPongResult) field1Length() int { + l := 0 + if p.IsSetE() { + l += bthrift.Binary.FieldBeginLength("e", thrift.STRUCT, 1) + l += p.E.BLength() + l += bthrift.Binary.FieldEndLength() + } + return l +} + +func (p *EchoServiceEchoOnewayArgs) FastRead(buf []byte) (int, error) { + var err error + var offset int + var l int + var fieldTypeId thrift.TType + var fieldId int16 + _, l, err = bthrift.Binary.ReadStructBegin(buf) + offset += l + if err != nil { + goto ReadStructBeginError + } + + for { + _, fieldTypeId, fieldId, l, err = bthrift.Binary.ReadFieldBegin(buf[offset:]) + offset += l + if err != nil { + goto ReadFieldBeginError + } + if fieldTypeId == thrift.STOP { + break + } + switch fieldId { + case 1: + if fieldTypeId == thrift.STRUCT { + l, err = p.FastReadField1(buf[offset:]) + offset += l + if err != nil { + goto ReadFieldError + } + } else { + l, err = bthrift.Binary.Skip(buf[offset:], fieldTypeId) + offset += l + if err != nil { + goto SkipFieldError + } + } + default: + l, err = bthrift.Binary.Skip(buf[offset:], fieldTypeId) + offset += l + if err != nil { + goto SkipFieldError + } + } + + l, err = bthrift.Binary.ReadFieldEnd(buf[offset:]) + offset += l + if err != nil { + goto ReadFieldEndError + } + } + l, err = bthrift.Binary.ReadStructEnd(buf[offset:]) + offset += l + if err != nil { + goto ReadStructEndError + } + + return offset, nil +ReadStructBeginError: + return offset, thrift.PrependError(fmt.Sprintf("%T read struct begin error: ", p), err) +ReadFieldBeginError: + return offset, thrift.PrependError(fmt.Sprintf("%T read field %d begin error: ", p, fieldId), err) +ReadFieldError: + return offset, thrift.PrependError(fmt.Sprintf("%T read field %d '%s' error: ", p, fieldId, fieldIDToName_EchoServiceEchoOnewayArgs[fieldId]), err) +SkipFieldError: + return offset, thrift.PrependError(fmt.Sprintf("%T field %d skip type %d error: ", p, fieldId, fieldTypeId), err) +ReadFieldEndError: + return offset, thrift.PrependError(fmt.Sprintf("%T read field end error", p), err) +ReadStructEndError: + return offset, thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err) +} + +func (p *EchoServiceEchoOnewayArgs) FastReadField1(buf []byte) (int, error) { + offset := 0 + + tmp := NewEchoRequest() + if l, err := tmp.FastRead(buf[offset:]); err != nil { + return offset, err + } else { + offset += l + } + p.Req1 = tmp + return offset, nil +} + +// for compatibility +func (p *EchoServiceEchoOnewayArgs) FastWrite(buf []byte) int { + return 0 +} + +func (p *EchoServiceEchoOnewayArgs) FastWriteNocopy(buf []byte, binaryWriter bthrift.BinaryWriter) int { + offset := 0 + offset += bthrift.Binary.WriteStructBegin(buf[offset:], "EchoOneway_args") + if p != nil { + offset += p.fastWriteField1(buf[offset:], binaryWriter) + } + offset += bthrift.Binary.WriteFieldStop(buf[offset:]) + offset += bthrift.Binary.WriteStructEnd(buf[offset:]) + return offset +} + +func (p *EchoServiceEchoOnewayArgs) BLength() int { + l := 0 + l += bthrift.Binary.StructBeginLength("EchoOneway_args") + if p != nil { + l += p.field1Length() + } + l += bthrift.Binary.FieldStopLength() + l += bthrift.Binary.StructEndLength() + return l +} + +func (p *EchoServiceEchoOnewayArgs) fastWriteField1(buf []byte, binaryWriter bthrift.BinaryWriter) int { + offset := 0 + offset += bthrift.Binary.WriteFieldBegin(buf[offset:], "req1", thrift.STRUCT, 1) + offset += p.Req1.FastWriteNocopy(buf[offset:], binaryWriter) + offset += bthrift.Binary.WriteFieldEnd(buf[offset:]) + return offset +} + +func (p *EchoServiceEchoOnewayArgs) field1Length() int { + l := 0 + l += bthrift.Binary.FieldBeginLength("req1", thrift.STRUCT, 1) + l += p.Req1.BLength() + l += bthrift.Binary.FieldEndLength() + return l +} + +func (p *EchoServiceEchoOnewayResult) FastRead(buf []byte) (int, error) { + var err error + var offset int + var l int + var fieldTypeId thrift.TType + var fieldId int16 + _, l, err = bthrift.Binary.ReadStructBegin(buf) + offset += l + if err != nil { + goto ReadStructBeginError + } + + for { + _, fieldTypeId, fieldId, l, err = bthrift.Binary.ReadFieldBegin(buf[offset:]) + offset += l + if err != nil { + goto ReadFieldBeginError + } + if fieldTypeId == thrift.STOP { + break + } + l, err = bthrift.Binary.Skip(buf[offset:], fieldTypeId) + offset += l + if err != nil { + goto SkipFieldError + } + + l, err = bthrift.Binary.ReadFieldEnd(buf[offset:]) + offset += l + if err != nil { + goto ReadFieldEndError + } + } + l, err = bthrift.Binary.ReadStructEnd(buf[offset:]) + offset += l + if err != nil { + goto ReadStructEndError + } + + return offset, nil +ReadStructBeginError: + return offset, thrift.PrependError(fmt.Sprintf("%T read struct begin error: ", p), err) +ReadFieldBeginError: + return offset, thrift.PrependError(fmt.Sprintf("%T read field %d begin error: ", p, fieldId), err) +SkipFieldError: + return offset, thrift.PrependError(fmt.Sprintf("%T field %d skip type %d error: ", p, fieldId, fieldTypeId), err) +ReadFieldEndError: + return offset, thrift.PrependError(fmt.Sprintf("%T read field end error", p), err) +ReadStructEndError: + return offset, thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err) +} + +// for compatibility +func (p *EchoServiceEchoOnewayResult) FastWrite(buf []byte) int { + return 0 +} + +func (p *EchoServiceEchoOnewayResult) FastWriteNocopy(buf []byte, binaryWriter bthrift.BinaryWriter) int { + offset := 0 + offset += bthrift.Binary.WriteStructBegin(buf[offset:], "EchoOneway_result") + if p != nil { + } + offset += bthrift.Binary.WriteFieldStop(buf[offset:]) + offset += bthrift.Binary.WriteStructEnd(buf[offset:]) + return offset +} + +func (p *EchoServiceEchoOnewayResult) BLength() int { + l := 0 + l += bthrift.Binary.StructBeginLength("EchoOneway_result") + if p != nil { + } + l += bthrift.Binary.FieldStopLength() + l += bthrift.Binary.StructEndLength() + return l +} + +func (p *EchoServicePingArgs) FastRead(buf []byte) (int, error) { + var err error + var offset int + var l int + var fieldTypeId thrift.TType + var fieldId int16 + _, l, err = bthrift.Binary.ReadStructBegin(buf) + offset += l + if err != nil { + goto ReadStructBeginError + } + + for { + _, fieldTypeId, fieldId, l, err = bthrift.Binary.ReadFieldBegin(buf[offset:]) + offset += l + if err != nil { + goto ReadFieldBeginError + } + if fieldTypeId == thrift.STOP { + break + } + l, err = bthrift.Binary.Skip(buf[offset:], fieldTypeId) + offset += l + if err != nil { + goto SkipFieldError + } + + l, err = bthrift.Binary.ReadFieldEnd(buf[offset:]) + offset += l + if err != nil { + goto ReadFieldEndError + } + } + l, err = bthrift.Binary.ReadStructEnd(buf[offset:]) + offset += l + if err != nil { + goto ReadStructEndError + } + + return offset, nil +ReadStructBeginError: + return offset, thrift.PrependError(fmt.Sprintf("%T read struct begin error: ", p), err) +ReadFieldBeginError: + return offset, thrift.PrependError(fmt.Sprintf("%T read field %d begin error: ", p, fieldId), err) +SkipFieldError: + return offset, thrift.PrependError(fmt.Sprintf("%T field %d skip type %d error: ", p, fieldId, fieldTypeId), err) +ReadFieldEndError: + return offset, thrift.PrependError(fmt.Sprintf("%T read field end error", p), err) +ReadStructEndError: + return offset, thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err) +} + +// for compatibility +func (p *EchoServicePingArgs) FastWrite(buf []byte) int { + return 0 +} + +func (p *EchoServicePingArgs) FastWriteNocopy(buf []byte, binaryWriter bthrift.BinaryWriter) int { + offset := 0 + offset += bthrift.Binary.WriteStructBegin(buf[offset:], "Ping_args") + if p != nil { + } + offset += bthrift.Binary.WriteFieldStop(buf[offset:]) + offset += bthrift.Binary.WriteStructEnd(buf[offset:]) + return offset +} + +func (p *EchoServicePingArgs) BLength() int { + l := 0 + l += bthrift.Binary.StructBeginLength("Ping_args") + if p != nil { + } + l += bthrift.Binary.FieldStopLength() + l += bthrift.Binary.StructEndLength() + return l +} + +func (p *EchoServicePingResult) FastRead(buf []byte) (int, error) { + var err error + var offset int + var l int + var fieldTypeId thrift.TType + var fieldId int16 + _, l, err = bthrift.Binary.ReadStructBegin(buf) + offset += l + if err != nil { + goto ReadStructBeginError + } + + for { + _, fieldTypeId, fieldId, l, err = bthrift.Binary.ReadFieldBegin(buf[offset:]) + offset += l + if err != nil { + goto ReadFieldBeginError + } + if fieldTypeId == thrift.STOP { + break + } + l, err = bthrift.Binary.Skip(buf[offset:], fieldTypeId) + offset += l + if err != nil { + goto SkipFieldError + } + + l, err = bthrift.Binary.ReadFieldEnd(buf[offset:]) + offset += l + if err != nil { + goto ReadFieldEndError + } + } + l, err = bthrift.Binary.ReadStructEnd(buf[offset:]) + offset += l + if err != nil { + goto ReadStructEndError + } + + return offset, nil +ReadStructBeginError: + return offset, thrift.PrependError(fmt.Sprintf("%T read struct begin error: ", p), err) +ReadFieldBeginError: + return offset, thrift.PrependError(fmt.Sprintf("%T read field %d begin error: ", p, fieldId), err) +SkipFieldError: + return offset, thrift.PrependError(fmt.Sprintf("%T field %d skip type %d error: ", p, fieldId, fieldTypeId), err) +ReadFieldEndError: + return offset, thrift.PrependError(fmt.Sprintf("%T read field end error", p), err) +ReadStructEndError: + return offset, thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err) +} + +// for compatibility +func (p *EchoServicePingResult) FastWrite(buf []byte) int { + return 0 +} + +func (p *EchoServicePingResult) FastWriteNocopy(buf []byte, binaryWriter bthrift.BinaryWriter) int { + offset := 0 + offset += bthrift.Binary.WriteStructBegin(buf[offset:], "Ping_result") + if p != nil { + } + offset += bthrift.Binary.WriteFieldStop(buf[offset:]) + offset += bthrift.Binary.WriteStructEnd(buf[offset:]) + return offset +} + +func (p *EchoServicePingResult) BLength() int { + l := 0 + l += bthrift.Binary.StructBeginLength("Ping_result") + if p != nil { + } + l += bthrift.Binary.FieldStopLength() + l += bthrift.Binary.StructEndLength() + return l +} + +func (p *EchoServiceEchoBidirectionalArgs) GetFirstArgument() interface{} { + return p.Req1 +} + +func (p *EchoServiceEchoBidirectionalResult) GetResult() interface{} { + return p.Success +} + +func (p *EchoServiceEchoClientArgs) GetFirstArgument() interface{} { + return p.Req1 +} + +func (p *EchoServiceEchoClientResult) GetResult() interface{} { + return p.Success +} + +func (p *EchoServiceEchoServerArgs) GetFirstArgument() interface{} { + return p.Req1 +} + +func (p *EchoServiceEchoServerResult) GetResult() interface{} { + return p.Success +} + +func (p *EchoServiceEchoUnaryArgs) GetFirstArgument() interface{} { + return p.Req1 +} + +func (p *EchoServiceEchoUnaryResult) GetResult() interface{} { + return p.Success +} + +func (p *EchoServiceEchoPingPongArgs) GetFirstArgument() interface{} { + return p.Req1 +} + +func (p *EchoServiceEchoPingPongResult) GetResult() interface{} { + return p.Success +} + +func (p *EchoServiceEchoOnewayArgs) GetFirstArgument() interface{} { + return p.Req1 +} + +func (p *EchoServiceEchoOnewayResult) GetResult() interface{} { + return nil +} + +func (p *EchoServicePingArgs) GetFirstArgument() interface{} { + return nil +} + +func (p *EchoServicePingResult) GetResult() interface{} { + return nil +} diff --git a/thrift_streaming/kitex_gen_old/echo/k-consts.go b/thrift_streaming/kitex_gen_old/echo/k-consts.go new file mode 100644 index 0000000..cf25014 --- /dev/null +++ b/thrift_streaming/kitex_gen_old/echo/k-consts.go @@ -0,0 +1,4 @@ +package echo + +// KitexUnusedProtection is used to prevent 'imported and not used' error. +var KitexUnusedProtection = struct{}{} diff --git a/thrift_streaming/kitex_gen_slim/echo/api.go b/thrift_streaming/kitex_gen_slim/echo/api.go new file mode 100644 index 0000000..f47ce7a --- /dev/null +++ b/thrift_streaming/kitex_gen_slim/echo/api.go @@ -0,0 +1,131 @@ +// Code generated by thriftgo (0.3.5). DO NOT EDIT. + +package echo + +import ( + "context" + "fmt" + "github.com/cloudwego/kitex/pkg/streaming" +) + +type EchoRequest struct { + Message string `thrift:"message,1,required" frugal:"1,required,string" json:"message"` +} + +func NewEchoRequest() *EchoRequest { + return &EchoRequest{} +} + +func (p *EchoRequest) InitDefault() { + *p = EchoRequest{} +} + +func (p *EchoRequest) GetMessage() (v string) { + return p.Message +} +func (p *EchoRequest) SetMessage(val string) { + p.Message = val +} + +func (p *EchoRequest) String() string { + if p == nil { + return "" + } + return fmt.Sprintf("EchoRequest(%+v)", *p) +} + +type EchoResponse struct { + Message string `thrift:"message,1,required" frugal:"1,required,string" json:"message"` +} + +func NewEchoResponse() *EchoResponse { + return &EchoResponse{} +} + +func (p *EchoResponse) InitDefault() { + *p = EchoResponse{} +} + +func (p *EchoResponse) GetMessage() (v string) { + return p.Message +} +func (p *EchoResponse) SetMessage(val string) { + p.Message = val +} + +func (p *EchoResponse) String() string { + if p == nil { + return "" + } + return fmt.Sprintf("EchoResponse(%+v)", *p) +} + +type EchoException struct { + Message string `thrift:"message,1" frugal:"1,default,string" json:"message"` +} + +func NewEchoException() *EchoException { + return &EchoException{} +} + +func (p *EchoException) InitDefault() { + *p = EchoException{} +} + +func (p *EchoException) GetMessage() (v string) { + return p.Message +} +func (p *EchoException) SetMessage(val string) { + p.Message = val +} + +func (p *EchoException) String() string { + if p == nil { + return "" + } + return fmt.Sprintf("EchoException(%+v)", *p) +} +func (p *EchoException) Error() string { + return p.String() +} + +type EchoService interface { + EchoBidirectional(stream EchoService_EchoBidirectionalServer) (err error) + + EchoClient(stream EchoService_EchoClientServer) (err error) + + EchoServer(req *EchoRequest, stream EchoService_EchoServerServer) (err error) + + EchoUnary(ctx context.Context, req1 *EchoRequest) (r *EchoResponse, err error) + + EchoPingPong(ctx context.Context, req1 *EchoRequest, req2 *EchoRequest) (r *EchoResponse, err error) + + EchoOneway(ctx context.Context, req1 *EchoRequest) (err error) + + Ping(ctx context.Context) (err error) +} + +type EchoService_EchoBidirectionalServer interface { + streaming.Stream + + Recv() (*EchoRequest, error) + + Send(*EchoResponse) error +} +type EchoService_EchoClientServer interface { + streaming.Stream + + Recv() (*EchoRequest, error) + + SendAndClose(*EchoResponse) error +} +type EchoService_EchoServerServer interface { + streaming.Stream + + Send(*EchoResponse) error +} + +// exceptions of methods in EchoService. +var ( + _ error = (*EchoException)(nil) +) diff --git a/thrift_streaming/kitex_gen_slim/echo/echoservice/client.go b/thrift_streaming/kitex_gen_slim/echo/echoservice/client.go new file mode 100644 index 0000000..212cca8 --- /dev/null +++ b/thrift_streaming/kitex_gen_slim/echo/echoservice/client.go @@ -0,0 +1,140 @@ +// Code generated by Kitex v0.8.0. DO NOT EDIT. + +package echoservice + +import ( + "context" + echo "github.com/cloudwego/kitex-tests/thrift_streaming/kitex_gen_slim/echo" + client "github.com/cloudwego/kitex/client" + callopt "github.com/cloudwego/kitex/client/callopt" + "github.com/cloudwego/kitex/client/callopt/streamcall" + "github.com/cloudwego/kitex/client/streamclient" + streaming "github.com/cloudwego/kitex/pkg/streaming" + transport "github.com/cloudwego/kitex/transport" +) + +// Client is designed to provide IDL-compatible methods with call-option parameter for kitex framework. +type Client interface { + EchoPingPong(ctx context.Context, req1 *echo.EchoRequest, req2 *echo.EchoRequest, callOptions ...callopt.Option) (r *echo.EchoResponse, err error) + EchoOneway(ctx context.Context, req1 *echo.EchoRequest, callOptions ...callopt.Option) (err error) + Ping(ctx context.Context, callOptions ...callopt.Option) (err error) +} + +// StreamClient is designed to provide Interface for Streaming APIs. +type StreamClient interface { + EchoBidirectional(ctx context.Context, callOptions ...streamcall.Option) (stream EchoService_EchoBidirectionalClient, err error) + EchoClient(ctx context.Context, callOptions ...streamcall.Option) (stream EchoService_EchoClientClient, err error) + EchoServer(ctx context.Context, req1 *echo.EchoRequest, callOptions ...streamcall.Option) (stream EchoService_EchoServerClient, err error) + EchoUnary(ctx context.Context, req1 *echo.EchoRequest, callOptions ...streamcall.Option) (r *echo.EchoResponse, err error) +} + +type EchoService_EchoBidirectionalClient interface { + streaming.Stream + Send(*echo.EchoRequest) error + Recv() (*echo.EchoResponse, error) +} + +type EchoService_EchoClientClient interface { + streaming.Stream + Send(*echo.EchoRequest) error + CloseAndRecv() (*echo.EchoResponse, error) +} + +type EchoService_EchoServerClient interface { + streaming.Stream + Recv() (*echo.EchoResponse, error) +} + +// NewClient creates a client for the service defined in IDL. +func NewClient(destService string, opts ...client.Option) (Client, error) { + var options []client.Option + options = append(options, client.WithDestService(destService)) + + options = append(options, opts...) + + kc, err := client.NewClient(serviceInfoForClient(), options...) + if err != nil { + return nil, err + } + return &kEchoServiceClient{ + kClient: newServiceClient(kc), + }, nil +} + +// MustNewClient creates a client for the service defined in IDL. It panics if any error occurs. +func MustNewClient(destService string, opts ...client.Option) Client { + kc, err := NewClient(destService, opts...) + if err != nil { + panic(err) + } + return kc +} + +type kEchoServiceClient struct { + *kClient +} + +func (p *kEchoServiceClient) EchoPingPong(ctx context.Context, req1 *echo.EchoRequest, req2 *echo.EchoRequest, callOptions ...callopt.Option) (r *echo.EchoResponse, err error) { + ctx = client.NewCtxWithCallOptions(ctx, callOptions) + return p.kClient.EchoPingPong(ctx, req1, req2) +} + +func (p *kEchoServiceClient) EchoOneway(ctx context.Context, req1 *echo.EchoRequest, callOptions ...callopt.Option) (err error) { + ctx = client.NewCtxWithCallOptions(ctx, callOptions) + return p.kClient.EchoOneway(ctx, req1) +} + +func (p *kEchoServiceClient) Ping(ctx context.Context, callOptions ...callopt.Option) (err error) { + ctx = client.NewCtxWithCallOptions(ctx, callOptions) + return p.kClient.Ping(ctx) +} + +// NewStreamClient creates a stream client for the service's streaming APIs defined in IDL. +func NewStreamClient(destService string, opts ...streamclient.Option) (StreamClient, error) { + var options []client.Option + options = append(options, client.WithDestService(destService)) + options = append(options, client.WithTransportProtocol(transport.GRPC)) + options = append(options, streamclient.GetClientOptions(opts)...) + + kc, err := client.NewClient(serviceInfoForStreamClient(), options...) + if err != nil { + return nil, err + } + return &kEchoServiceStreamClient{ + kClient: newServiceClient(kc), + }, nil +} + +// MustNewStreamClient creates a stream client for the service's streaming APIs defined in IDL. +// It panics if any error occurs. +func MustNewStreamClient(destService string, opts ...streamclient.Option) StreamClient { + kc, err := NewStreamClient(destService, opts...) + if err != nil { + panic(err) + } + return kc +} + +type kEchoServiceStreamClient struct { + *kClient +} + +func (p *kEchoServiceStreamClient) EchoBidirectional(ctx context.Context, callOptions ...streamcall.Option) (stream EchoService_EchoBidirectionalClient, err error) { + ctx = client.NewCtxWithCallOptions(ctx, streamcall.GetCallOptions(callOptions)) + return p.kClient.EchoBidirectional(ctx) +} + +func (p *kEchoServiceStreamClient) EchoClient(ctx context.Context, callOptions ...streamcall.Option) (stream EchoService_EchoClientClient, err error) { + ctx = client.NewCtxWithCallOptions(ctx, streamcall.GetCallOptions(callOptions)) + return p.kClient.EchoClient(ctx) +} + +func (p *kEchoServiceStreamClient) EchoServer(ctx context.Context, req1 *echo.EchoRequest, callOptions ...streamcall.Option) (stream EchoService_EchoServerClient, err error) { + ctx = client.NewCtxWithCallOptions(ctx, streamcall.GetCallOptions(callOptions)) + return p.kClient.EchoServer(ctx, req1) +} + +func (p *kEchoServiceStreamClient) EchoUnary(ctx context.Context, req1 *echo.EchoRequest, callOptions ...streamcall.Option) (r *echo.EchoResponse, err error) { + ctx = client.NewCtxWithCallOptions(ctx, streamcall.GetCallOptions(callOptions)) + return p.kClient.EchoUnary(ctx, req1) +} diff --git a/thrift_streaming/kitex_gen_slim/echo/echoservice/echoservice.go b/thrift_streaming/kitex_gen_slim/echo/echoservice/echoservice.go new file mode 100644 index 0000000..ab9ef60 --- /dev/null +++ b/thrift_streaming/kitex_gen_slim/echo/echoservice/echoservice.go @@ -0,0 +1,442 @@ +// Code generated by Kitex v0.8.0. DO NOT EDIT. + +package echoservice + +import ( + "context" + "errors" + "fmt" + echo "github.com/cloudwego/kitex-tests/thrift_streaming/kitex_gen_slim/echo" + client "github.com/cloudwego/kitex/client" + kitex "github.com/cloudwego/kitex/pkg/serviceinfo" + streaming "github.com/cloudwego/kitex/pkg/streaming" +) + +var errInvalidMessageType = errors.New("invalid message type for service method handler") + +var _ = streaming.KitexUnusedProtection + +var serviceMethods = map[string]kitex.MethodInfo{ + "EchoBidirectional": kitex.NewMethodInfo( + echoBidirectionalHandler, + newEchoServiceEchoBidirectionalArgs, + newEchoServiceEchoBidirectionalResult, + false, + kitex.WithStreamingMode(kitex.StreamingBidirectional), + ), + "EchoClient": kitex.NewMethodInfo( + echoClientHandler, + newEchoServiceEchoClientArgs, + newEchoServiceEchoClientResult, + false, + kitex.WithStreamingMode(kitex.StreamingClient), + ), + "EchoServer": kitex.NewMethodInfo( + echoServerHandler, + newEchoServiceEchoServerArgs, + newEchoServiceEchoServerResult, + false, + kitex.WithStreamingMode(kitex.StreamingServer), + ), + "EchoUnary": kitex.NewMethodInfo( + echoUnaryHandler, + newEchoServiceEchoUnaryArgs, + newEchoServiceEchoUnaryResult, + false, + kitex.WithStreamingMode(kitex.StreamingUnary), + ), + "EchoPingPong": kitex.NewMethodInfo( + echoPingPongHandler, + newEchoServiceEchoPingPongArgs, + newEchoServiceEchoPingPongResult, + false, + kitex.WithStreamingMode(kitex.StreamingNone), + ), + "EchoOneway": kitex.NewMethodInfo( + echoOnewayHandler, + newEchoServiceEchoOnewayArgs, + newEchoServiceEchoOnewayResult, + false, + kitex.WithStreamingMode(kitex.StreamingNone), + ), + "Ping": kitex.NewMethodInfo( + pingHandler, + newEchoServicePingArgs, + newEchoServicePingResult, + false, + kitex.WithStreamingMode(kitex.StreamingNone), + ), +} + +var ( + echoServiceServiceInfo = NewServiceInfo() + echoServiceServiceInfoForClient = NewServiceInfoForClient() + echoServiceServiceInfoForStreamClient = NewServiceInfoForStreamClient() +) + +// for server +func serviceInfo() *kitex.ServiceInfo { + return echoServiceServiceInfo +} + +// for client +func serviceInfoForStreamClient() *kitex.ServiceInfo { + return echoServiceServiceInfoForStreamClient +} + +// for stream client +func serviceInfoForClient() *kitex.ServiceInfo { + return echoServiceServiceInfoForClient +} + +// NewServiceInfo creates a new ServiceInfo containing all methods +func NewServiceInfo() *kitex.ServiceInfo { + return newServiceInfo(true, true, true) +} + +// NewServiceInfo creates a new ServiceInfo containing non-streaming methods +func NewServiceInfoForClient() *kitex.ServiceInfo { + return newServiceInfo(false, false, true) +} +func NewServiceInfoForStreamClient() *kitex.ServiceInfo { + return newServiceInfo(true, true, false) +} + +func newServiceInfo(hasStreaming bool, keepStreamingMethods bool, keepNonStreamingMethods bool) *kitex.ServiceInfo { + serviceName := "EchoService" + handlerType := (*echo.EchoService)(nil) + methods := map[string]kitex.MethodInfo{} + for name, m := range serviceMethods { + if m.IsStreaming() && !keepStreamingMethods { + continue + } + if !m.IsStreaming() && !keepNonStreamingMethods { + continue + } + methods[name] = m + } + extra := map[string]interface{}{ + "PackageName": "echo", + } + if hasStreaming { + extra["streaming"] = hasStreaming + } + svcInfo := &kitex.ServiceInfo{ + ServiceName: serviceName, + HandlerType: handlerType, + Methods: methods, + PayloadCodec: kitex.Thrift, + KiteXGenVersion: "v0.8.0", + Extra: extra, + } + return svcInfo +} + +func echoBidirectionalHandler(ctx context.Context, handler interface{}, arg, result interface{}) error { + st, ok := arg.(*streaming.Args) + if !ok { + return errors.New("EchoService.EchoBidirectional is a thrift streaming method, please call with Kitex StreamClient") + } + stream := &echoServiceEchoBidirectionalServer{st.Stream} + return handler.(echo.EchoService).EchoBidirectional(stream) +} + +type echoServiceEchoBidirectionalClient struct { + streaming.Stream +} + +func (x *echoServiceEchoBidirectionalClient) Send(m *echo.EchoRequest) error { + return x.Stream.SendMsg(m) +} +func (x *echoServiceEchoBidirectionalClient) Recv() (*echo.EchoResponse, error) { + m := new(echo.EchoResponse) + return m, x.Stream.RecvMsg(m) +} + +type echoServiceEchoBidirectionalServer struct { + streaming.Stream +} + +func (x *echoServiceEchoBidirectionalServer) Send(m *echo.EchoResponse) error { + return x.Stream.SendMsg(m) +} + +func (x *echoServiceEchoBidirectionalServer) Recv() (*echo.EchoRequest, error) { + m := new(echo.EchoRequest) + return m, x.Stream.RecvMsg(m) +} + +func newEchoServiceEchoBidirectionalArgs() interface{} { + return echo.NewEchoServiceEchoBidirectionalArgs() +} + +func newEchoServiceEchoBidirectionalResult() interface{} { + return echo.NewEchoServiceEchoBidirectionalResult() +} + +func echoClientHandler(ctx context.Context, handler interface{}, arg, result interface{}) error { + st, ok := arg.(*streaming.Args) + if !ok { + return errors.New("EchoService.EchoClient is a thrift streaming method, please call with Kitex StreamClient") + } + stream := &echoServiceEchoClientServer{st.Stream} + return handler.(echo.EchoService).EchoClient(stream) +} + +type echoServiceEchoClientClient struct { + streaming.Stream +} + +func (x *echoServiceEchoClientClient) Send(m *echo.EchoRequest) error { + return x.Stream.SendMsg(m) +} +func (x *echoServiceEchoClientClient) CloseAndRecv() (*echo.EchoResponse, error) { + if err := x.Stream.Close(); err != nil { + return nil, err + } + m := new(echo.EchoResponse) + return m, x.Stream.RecvMsg(m) +} + +type echoServiceEchoClientServer struct { + streaming.Stream +} + +func (x *echoServiceEchoClientServer) SendAndClose(m *echo.EchoResponse) error { + return x.Stream.SendMsg(m) +} + +func (x *echoServiceEchoClientServer) Recv() (*echo.EchoRequest, error) { + m := new(echo.EchoRequest) + return m, x.Stream.RecvMsg(m) +} + +func newEchoServiceEchoClientArgs() interface{} { + return echo.NewEchoServiceEchoClientArgs() +} + +func newEchoServiceEchoClientResult() interface{} { + return echo.NewEchoServiceEchoClientResult() +} + +func echoServerHandler(ctx context.Context, handler interface{}, arg, result interface{}) error { + st, ok := arg.(*streaming.Args) + if !ok { + return errors.New("EchoService.EchoServer is a thrift streaming method, please call with Kitex StreamClient") + } + stream := &echoServiceEchoServerServer{st.Stream} + req := new(echo.EchoRequest) + if err := st.Stream.RecvMsg(req); err != nil { + return err + } + return handler.(echo.EchoService).EchoServer(req, stream) +} + +type echoServiceEchoServerClient struct { + streaming.Stream +} + +func (x *echoServiceEchoServerClient) Recv() (*echo.EchoResponse, error) { + m := new(echo.EchoResponse) + return m, x.Stream.RecvMsg(m) +} + +type echoServiceEchoServerServer struct { + streaming.Stream +} + +func (x *echoServiceEchoServerServer) Send(m *echo.EchoResponse) error { + return x.Stream.SendMsg(m) +} + +func newEchoServiceEchoServerArgs() interface{} { + return echo.NewEchoServiceEchoServerArgs() +} + +func newEchoServiceEchoServerResult() interface{} { + return echo.NewEchoServiceEchoServerResult() +} + +func echoUnaryHandler(ctx context.Context, handler interface{}, arg, result interface{}) error { + if streaming.GetStream(ctx) == nil { + return errors.New("EchoService.EchoUnary is a thrift streaming unary method, please call with Kitex StreamClient or remove the annotation streaming.mode") + } + realArg := arg.(*echo.EchoServiceEchoUnaryArgs) + realResult := result.(*echo.EchoServiceEchoUnaryResult) + success, err := handler.(echo.EchoService).EchoUnary(ctx, realArg.Req1) + if err != nil { + return err + } + realResult.Success = success + return nil +} +func newEchoServiceEchoUnaryArgs() interface{} { + return echo.NewEchoServiceEchoUnaryArgs() +} + +func newEchoServiceEchoUnaryResult() interface{} { + return echo.NewEchoServiceEchoUnaryResult() +} + +func echoPingPongHandler(ctx context.Context, handler interface{}, arg, result interface{}) error { + realArg := arg.(*echo.EchoServiceEchoPingPongArgs) + realResult := result.(*echo.EchoServiceEchoPingPongResult) + success, err := handler.(echo.EchoService).EchoPingPong(ctx, realArg.Req1, realArg.Req2) + if err != nil { + switch v := err.(type) { + case *echo.EchoException: + realResult.E = v + default: + return err + } + } else { + realResult.Success = success + } + return nil +} +func newEchoServiceEchoPingPongArgs() interface{} { + return echo.NewEchoServiceEchoPingPongArgs() +} + +func newEchoServiceEchoPingPongResult() interface{} { + return echo.NewEchoServiceEchoPingPongResult() +} + +func echoOnewayHandler(ctx context.Context, handler interface{}, arg, result interface{}) error { + realArg := arg.(*echo.EchoServiceEchoOnewayArgs) + + err := handler.(echo.EchoService).EchoOneway(ctx, realArg.Req1) + if err != nil { + return err + } + + return nil +} +func newEchoServiceEchoOnewayArgs() interface{} { + return echo.NewEchoServiceEchoOnewayArgs() +} + +func newEchoServiceEchoOnewayResult() interface{} { + return echo.NewEchoServiceEchoOnewayResult() +} + +func pingHandler(ctx context.Context, handler interface{}, arg, result interface{}) error { + _ = arg.(*echo.EchoServicePingArgs) + + err := handler.(echo.EchoService).Ping(ctx) + if err != nil { + return err + } + + return nil +} +func newEchoServicePingArgs() interface{} { + return echo.NewEchoServicePingArgs() +} + +func newEchoServicePingResult() interface{} { + return echo.NewEchoServicePingResult() +} + +type kClient struct { + c client.Client +} + +func newServiceClient(c client.Client) *kClient { + return &kClient{ + c: c, + } +} + +func (p *kClient) EchoBidirectional(ctx context.Context) (EchoService_EchoBidirectionalClient, error) { + streamClient, ok := p.c.(client.Streaming) + if !ok { + return nil, fmt.Errorf("client not support streaming") + } + res := new(streaming.Result) + err := streamClient.Stream(ctx, "EchoBidirectional", nil, res) + if err != nil { + return nil, err + } + stream := &echoServiceEchoBidirectionalClient{res.Stream} + return stream, nil +} + +func (p *kClient) EchoClient(ctx context.Context) (EchoService_EchoClientClient, error) { + streamClient, ok := p.c.(client.Streaming) + if !ok { + return nil, fmt.Errorf("client not support streaming") + } + res := new(streaming.Result) + err := streamClient.Stream(ctx, "EchoClient", nil, res) + if err != nil { + return nil, err + } + stream := &echoServiceEchoClientClient{res.Stream} + return stream, nil +} + +func (p *kClient) EchoServer(ctx context.Context, req1 *echo.EchoRequest) (EchoService_EchoServerClient, error) { + streamClient, ok := p.c.(client.Streaming) + if !ok { + return nil, fmt.Errorf("client not support streaming") + } + res := new(streaming.Result) + err := streamClient.Stream(ctx, "EchoServer", nil, res) + if err != nil { + return nil, err + } + stream := &echoServiceEchoServerClient{res.Stream} + + if err := stream.Stream.SendMsg(req1); err != nil { + return nil, err + } + if err := stream.Stream.Close(); err != nil { + return nil, err + } + return stream, nil +} + +func (p *kClient) EchoUnary(ctx context.Context, req1 *echo.EchoRequest) (r *echo.EchoResponse, err error) { + var _args echo.EchoServiceEchoUnaryArgs + _args.Req1 = req1 + var _result echo.EchoServiceEchoUnaryResult + if err = p.c.Call(ctx, "EchoUnary", &_args, &_result); err != nil { + return + } + return _result.GetSuccess(), nil +} + +func (p *kClient) EchoPingPong(ctx context.Context, req1 *echo.EchoRequest, req2 *echo.EchoRequest) (r *echo.EchoResponse, err error) { + var _args echo.EchoServiceEchoPingPongArgs + _args.Req1 = req1 + _args.Req2 = req2 + var _result echo.EchoServiceEchoPingPongResult + if err = p.c.Call(ctx, "EchoPingPong", &_args, &_result); err != nil { + return + } + switch { + case _result.E != nil: + return r, _result.E + } + return _result.GetSuccess(), nil +} + +func (p *kClient) EchoOneway(ctx context.Context, req1 *echo.EchoRequest) (err error) { + var _args echo.EchoServiceEchoOnewayArgs + _args.Req1 = req1 + var _result echo.EchoServiceEchoOnewayResult + if err = p.c.Call(ctx, "EchoOneway", &_args, &_result); err != nil { + return + } + return nil +} + +func (p *kClient) Ping(ctx context.Context) (err error) { + var _args echo.EchoServicePingArgs + var _result echo.EchoServicePingResult + if err = p.c.Call(ctx, "Ping", &_args, &_result); err != nil { + return + } + return nil +} diff --git a/thrift_streaming/kitex_gen_slim/echo/echoservice/invoker.go b/thrift_streaming/kitex_gen_slim/echo/echoservice/invoker.go new file mode 100644 index 0000000..fe70d63 --- /dev/null +++ b/thrift_streaming/kitex_gen_slim/echo/echoservice/invoker.go @@ -0,0 +1,24 @@ +// Code generated by Kitex v0.8.0. DO NOT EDIT. + +package echoservice + +import ( + echo "github.com/cloudwego/kitex-tests/thrift_streaming/kitex_gen_slim/echo" + server "github.com/cloudwego/kitex/server" +) + +// NewInvoker creates a server.Invoker with the given handler and options. +func NewInvoker(handler echo.EchoService, opts ...server.Option) server.Invoker { + var options []server.Option + + options = append(options, opts...) + + s := server.NewInvoker(options...) + if err := s.RegisterService(serviceInfo(), handler); err != nil { + panic(err) + } + if err := s.Init(); err != nil { + panic(err) + } + return s +} diff --git a/thrift_streaming/kitex_gen_slim/echo/echoservice/server.go b/thrift_streaming/kitex_gen_slim/echo/echoservice/server.go new file mode 100644 index 0000000..26f42a2 --- /dev/null +++ b/thrift_streaming/kitex_gen_slim/echo/echoservice/server.go @@ -0,0 +1,21 @@ +// Code generated by Kitex v0.8.0. DO NOT EDIT. +package echoservice + +import ( + echo "github.com/cloudwego/kitex-tests/thrift_streaming/kitex_gen_slim/echo" + server "github.com/cloudwego/kitex/server" +) + +// NewServer creates a server.Server with the given handler and options. +func NewServer(handler echo.EchoService, opts ...server.Option) server.Server { + var options []server.Option + + options = append(options, opts...) + options = append(options, server.WithCompatibleMiddlewareForUnary()) + + svr := server.NewServer(options...) + if err := svr.RegisterService(serviceInfo(), handler); err != nil { + panic(err) + } + return svr +} diff --git a/thrift_streaming/kitex_gen_slim/echo/k-api.go b/thrift_streaming/kitex_gen_slim/echo/k-api.go new file mode 100644 index 0000000..e2ba3f1 --- /dev/null +++ b/thrift_streaming/kitex_gen_slim/echo/k-api.go @@ -0,0 +1,536 @@ +// Code generated by Kitex v0.8.0. DO NOT EDIT. + +package echo + +import ( + "bytes" + "fmt" + "reflect" + "strings" + + "github.com/apache/thrift/lib/go/thrift" +) + +// unused protection +var ( + _ = fmt.Formatter(nil) + _ = (*bytes.Buffer)(nil) + _ = (*strings.Builder)(nil) + _ = reflect.Type(nil) + _ = thrift.TProtocol(nil) +) + +type EchoServiceEchoBidirectionalArgs struct { + Req1 *EchoRequest `thrift:"req1,1" frugal:"1,default,EchoRequest" json:"req1"` +} + +func NewEchoServiceEchoBidirectionalArgs() *EchoServiceEchoBidirectionalArgs { + return &EchoServiceEchoBidirectionalArgs{} +} + +func (p *EchoServiceEchoBidirectionalArgs) InitDefault() { + *p = EchoServiceEchoBidirectionalArgs{} +} + +var EchoServiceEchoBidirectionalArgs_Req1_DEFAULT *EchoRequest + +func (p *EchoServiceEchoBidirectionalArgs) GetReq1() (v *EchoRequest) { + if !p.IsSetReq1() { + return EchoServiceEchoBidirectionalArgs_Req1_DEFAULT + } + return p.Req1 +} +func (p *EchoServiceEchoBidirectionalArgs) SetReq1(val *EchoRequest) { + p.Req1 = val +} + +func (p *EchoServiceEchoBidirectionalArgs) IsSetReq1() bool { + return p.Req1 != nil +} + +func (p *EchoServiceEchoBidirectionalArgs) String() string { + if p == nil { + return "" + } + return fmt.Sprintf("EchoServiceEchoBidirectionalArgs(%+v)", *p) +} +func (p *EchoServiceEchoBidirectionalArgs) GetFirstArgument() interface{} { + return p.Req1 +} + +type EchoServiceEchoBidirectionalResult struct { + Success *EchoResponse `thrift:"success,0,optional" frugal:"0,optional,EchoResponse" json:"success,omitempty"` +} + +func NewEchoServiceEchoBidirectionalResult() *EchoServiceEchoBidirectionalResult { + return &EchoServiceEchoBidirectionalResult{} +} + +func (p *EchoServiceEchoBidirectionalResult) InitDefault() { + *p = EchoServiceEchoBidirectionalResult{} +} + +var EchoServiceEchoBidirectionalResult_Success_DEFAULT *EchoResponse + +func (p *EchoServiceEchoBidirectionalResult) GetSuccess() (v *EchoResponse) { + if !p.IsSetSuccess() { + return EchoServiceEchoBidirectionalResult_Success_DEFAULT + } + return p.Success +} +func (p *EchoServiceEchoBidirectionalResult) SetSuccess(x interface{}) { + p.Success = x.(*EchoResponse) +} + +func (p *EchoServiceEchoBidirectionalResult) IsSetSuccess() bool { + return p.Success != nil +} + +func (p *EchoServiceEchoBidirectionalResult) String() string { + if p == nil { + return "" + } + return fmt.Sprintf("EchoServiceEchoBidirectionalResult(%+v)", *p) +} +func (p *EchoServiceEchoBidirectionalResult) GetResult() interface{} { + return p.Success +} + +type EchoServiceEchoClientArgs struct { + Req1 *EchoRequest `thrift:"req1,1" frugal:"1,default,EchoRequest" json:"req1"` +} + +func NewEchoServiceEchoClientArgs() *EchoServiceEchoClientArgs { + return &EchoServiceEchoClientArgs{} +} + +func (p *EchoServiceEchoClientArgs) InitDefault() { + *p = EchoServiceEchoClientArgs{} +} + +var EchoServiceEchoClientArgs_Req1_DEFAULT *EchoRequest + +func (p *EchoServiceEchoClientArgs) GetReq1() (v *EchoRequest) { + if !p.IsSetReq1() { + return EchoServiceEchoClientArgs_Req1_DEFAULT + } + return p.Req1 +} +func (p *EchoServiceEchoClientArgs) SetReq1(val *EchoRequest) { + p.Req1 = val +} + +func (p *EchoServiceEchoClientArgs) IsSetReq1() bool { + return p.Req1 != nil +} + +func (p *EchoServiceEchoClientArgs) String() string { + if p == nil { + return "" + } + return fmt.Sprintf("EchoServiceEchoClientArgs(%+v)", *p) +} +func (p *EchoServiceEchoClientArgs) GetFirstArgument() interface{} { + return p.Req1 +} + +type EchoServiceEchoClientResult struct { + Success *EchoResponse `thrift:"success,0,optional" frugal:"0,optional,EchoResponse" json:"success,omitempty"` +} + +func NewEchoServiceEchoClientResult() *EchoServiceEchoClientResult { + return &EchoServiceEchoClientResult{} +} + +func (p *EchoServiceEchoClientResult) InitDefault() { + *p = EchoServiceEchoClientResult{} +} + +var EchoServiceEchoClientResult_Success_DEFAULT *EchoResponse + +func (p *EchoServiceEchoClientResult) GetSuccess() (v *EchoResponse) { + if !p.IsSetSuccess() { + return EchoServiceEchoClientResult_Success_DEFAULT + } + return p.Success +} +func (p *EchoServiceEchoClientResult) SetSuccess(x interface{}) { + p.Success = x.(*EchoResponse) +} + +func (p *EchoServiceEchoClientResult) IsSetSuccess() bool { + return p.Success != nil +} + +func (p *EchoServiceEchoClientResult) String() string { + if p == nil { + return "" + } + return fmt.Sprintf("EchoServiceEchoClientResult(%+v)", *p) +} +func (p *EchoServiceEchoClientResult) GetResult() interface{} { + return p.Success +} + +type EchoServiceEchoServerArgs struct { + Req1 *EchoRequest `thrift:"req1,1" frugal:"1,default,EchoRequest" json:"req1"` +} + +func NewEchoServiceEchoServerArgs() *EchoServiceEchoServerArgs { + return &EchoServiceEchoServerArgs{} +} + +func (p *EchoServiceEchoServerArgs) InitDefault() { + *p = EchoServiceEchoServerArgs{} +} + +var EchoServiceEchoServerArgs_Req1_DEFAULT *EchoRequest + +func (p *EchoServiceEchoServerArgs) GetReq1() (v *EchoRequest) { + if !p.IsSetReq1() { + return EchoServiceEchoServerArgs_Req1_DEFAULT + } + return p.Req1 +} +func (p *EchoServiceEchoServerArgs) SetReq1(val *EchoRequest) { + p.Req1 = val +} + +func (p *EchoServiceEchoServerArgs) IsSetReq1() bool { + return p.Req1 != nil +} + +func (p *EchoServiceEchoServerArgs) String() string { + if p == nil { + return "" + } + return fmt.Sprintf("EchoServiceEchoServerArgs(%+v)", *p) +} +func (p *EchoServiceEchoServerArgs) GetFirstArgument() interface{} { + return p.Req1 +} + +type EchoServiceEchoServerResult struct { + Success *EchoResponse `thrift:"success,0,optional" frugal:"0,optional,EchoResponse" json:"success,omitempty"` +} + +func NewEchoServiceEchoServerResult() *EchoServiceEchoServerResult { + return &EchoServiceEchoServerResult{} +} + +func (p *EchoServiceEchoServerResult) InitDefault() { + *p = EchoServiceEchoServerResult{} +} + +var EchoServiceEchoServerResult_Success_DEFAULT *EchoResponse + +func (p *EchoServiceEchoServerResult) GetSuccess() (v *EchoResponse) { + if !p.IsSetSuccess() { + return EchoServiceEchoServerResult_Success_DEFAULT + } + return p.Success +} +func (p *EchoServiceEchoServerResult) SetSuccess(x interface{}) { + p.Success = x.(*EchoResponse) +} + +func (p *EchoServiceEchoServerResult) IsSetSuccess() bool { + return p.Success != nil +} + +func (p *EchoServiceEchoServerResult) String() string { + if p == nil { + return "" + } + return fmt.Sprintf("EchoServiceEchoServerResult(%+v)", *p) +} +func (p *EchoServiceEchoServerResult) GetResult() interface{} { + return p.Success +} + +type EchoServiceEchoUnaryArgs struct { + Req1 *EchoRequest `thrift:"req1,1" frugal:"1,default,EchoRequest" json:"req1"` +} + +func NewEchoServiceEchoUnaryArgs() *EchoServiceEchoUnaryArgs { + return &EchoServiceEchoUnaryArgs{} +} + +func (p *EchoServiceEchoUnaryArgs) InitDefault() { + *p = EchoServiceEchoUnaryArgs{} +} + +var EchoServiceEchoUnaryArgs_Req1_DEFAULT *EchoRequest + +func (p *EchoServiceEchoUnaryArgs) GetReq1() (v *EchoRequest) { + if !p.IsSetReq1() { + return EchoServiceEchoUnaryArgs_Req1_DEFAULT + } + return p.Req1 +} +func (p *EchoServiceEchoUnaryArgs) SetReq1(val *EchoRequest) { + p.Req1 = val +} + +func (p *EchoServiceEchoUnaryArgs) IsSetReq1() bool { + return p.Req1 != nil +} + +func (p *EchoServiceEchoUnaryArgs) String() string { + if p == nil { + return "" + } + return fmt.Sprintf("EchoServiceEchoUnaryArgs(%+v)", *p) +} +func (p *EchoServiceEchoUnaryArgs) GetFirstArgument() interface{} { + return p.Req1 +} + +type EchoServiceEchoUnaryResult struct { + Success *EchoResponse `thrift:"success,0,optional" frugal:"0,optional,EchoResponse" json:"success,omitempty"` +} + +func NewEchoServiceEchoUnaryResult() *EchoServiceEchoUnaryResult { + return &EchoServiceEchoUnaryResult{} +} + +func (p *EchoServiceEchoUnaryResult) InitDefault() { + *p = EchoServiceEchoUnaryResult{} +} + +var EchoServiceEchoUnaryResult_Success_DEFAULT *EchoResponse + +func (p *EchoServiceEchoUnaryResult) GetSuccess() (v *EchoResponse) { + if !p.IsSetSuccess() { + return EchoServiceEchoUnaryResult_Success_DEFAULT + } + return p.Success +} +func (p *EchoServiceEchoUnaryResult) SetSuccess(x interface{}) { + p.Success = x.(*EchoResponse) +} + +func (p *EchoServiceEchoUnaryResult) IsSetSuccess() bool { + return p.Success != nil +} + +func (p *EchoServiceEchoUnaryResult) String() string { + if p == nil { + return "" + } + return fmt.Sprintf("EchoServiceEchoUnaryResult(%+v)", *p) +} +func (p *EchoServiceEchoUnaryResult) GetResult() interface{} { + return p.Success +} + +type EchoServiceEchoPingPongArgs struct { + Req1 *EchoRequest `thrift:"req1,1" frugal:"1,default,EchoRequest" json:"req1"` + Req2 *EchoRequest `thrift:"req2,2" frugal:"2,default,EchoRequest" json:"req2"` +} + +func NewEchoServiceEchoPingPongArgs() *EchoServiceEchoPingPongArgs { + return &EchoServiceEchoPingPongArgs{} +} + +func (p *EchoServiceEchoPingPongArgs) InitDefault() { + *p = EchoServiceEchoPingPongArgs{} +} + +var EchoServiceEchoPingPongArgs_Req1_DEFAULT *EchoRequest + +func (p *EchoServiceEchoPingPongArgs) GetReq1() (v *EchoRequest) { + if !p.IsSetReq1() { + return EchoServiceEchoPingPongArgs_Req1_DEFAULT + } + return p.Req1 +} + +var EchoServiceEchoPingPongArgs_Req2_DEFAULT *EchoRequest + +func (p *EchoServiceEchoPingPongArgs) GetReq2() (v *EchoRequest) { + if !p.IsSetReq2() { + return EchoServiceEchoPingPongArgs_Req2_DEFAULT + } + return p.Req2 +} +func (p *EchoServiceEchoPingPongArgs) SetReq1(val *EchoRequest) { + p.Req1 = val +} +func (p *EchoServiceEchoPingPongArgs) SetReq2(val *EchoRequest) { + p.Req2 = val +} + +func (p *EchoServiceEchoPingPongArgs) IsSetReq1() bool { + return p.Req1 != nil +} + +func (p *EchoServiceEchoPingPongArgs) IsSetReq2() bool { + return p.Req2 != nil +} + +func (p *EchoServiceEchoPingPongArgs) String() string { + if p == nil { + return "" + } + return fmt.Sprintf("EchoServiceEchoPingPongArgs(%+v)", *p) +} +func (p *EchoServiceEchoPingPongArgs) GetFirstArgument() interface{} { + return p.Req1 +} + +type EchoServiceEchoPingPongResult struct { + Success *EchoResponse `thrift:"success,0,optional" frugal:"0,optional,EchoResponse" json:"success,omitempty"` + E *EchoException `thrift:"e,1,optional" frugal:"1,optional,EchoException" json:"e,omitempty"` +} + +func NewEchoServiceEchoPingPongResult() *EchoServiceEchoPingPongResult { + return &EchoServiceEchoPingPongResult{} +} + +func (p *EchoServiceEchoPingPongResult) InitDefault() { + *p = EchoServiceEchoPingPongResult{} +} + +var EchoServiceEchoPingPongResult_Success_DEFAULT *EchoResponse + +func (p *EchoServiceEchoPingPongResult) GetSuccess() (v *EchoResponse) { + if !p.IsSetSuccess() { + return EchoServiceEchoPingPongResult_Success_DEFAULT + } + return p.Success +} + +var EchoServiceEchoPingPongResult_E_DEFAULT *EchoException + +func (p *EchoServiceEchoPingPongResult) GetE() (v *EchoException) { + if !p.IsSetE() { + return EchoServiceEchoPingPongResult_E_DEFAULT + } + return p.E +} +func (p *EchoServiceEchoPingPongResult) SetSuccess(x interface{}) { + p.Success = x.(*EchoResponse) +} +func (p *EchoServiceEchoPingPongResult) SetE(val *EchoException) { + p.E = val +} + +func (p *EchoServiceEchoPingPongResult) IsSetSuccess() bool { + return p.Success != nil +} + +func (p *EchoServiceEchoPingPongResult) IsSetE() bool { + return p.E != nil +} + +func (p *EchoServiceEchoPingPongResult) String() string { + if p == nil { + return "" + } + return fmt.Sprintf("EchoServiceEchoPingPongResult(%+v)", *p) +} +func (p *EchoServiceEchoPingPongResult) GetResult() interface{} { + return p.Success +} + +type EchoServiceEchoOnewayArgs struct { + Req1 *EchoRequest `thrift:"req1,1" frugal:"1,default,EchoRequest" json:"req1"` +} + +func NewEchoServiceEchoOnewayArgs() *EchoServiceEchoOnewayArgs { + return &EchoServiceEchoOnewayArgs{} +} + +func (p *EchoServiceEchoOnewayArgs) InitDefault() { + *p = EchoServiceEchoOnewayArgs{} +} + +var EchoServiceEchoOnewayArgs_Req1_DEFAULT *EchoRequest + +func (p *EchoServiceEchoOnewayArgs) GetReq1() (v *EchoRequest) { + if !p.IsSetReq1() { + return EchoServiceEchoOnewayArgs_Req1_DEFAULT + } + return p.Req1 +} +func (p *EchoServiceEchoOnewayArgs) SetReq1(val *EchoRequest) { + p.Req1 = val +} + +func (p *EchoServiceEchoOnewayArgs) IsSetReq1() bool { + return p.Req1 != nil +} + +func (p *EchoServiceEchoOnewayArgs) String() string { + if p == nil { + return "" + } + return fmt.Sprintf("EchoServiceEchoOnewayArgs(%+v)", *p) +} +func (p *EchoServiceEchoOnewayArgs) GetFirstArgument() interface{} { + return p.Req1 +} + +type EchoServiceEchoOnewayResult struct { +} + +func NewEchoServiceEchoOnewayResult() *EchoServiceEchoOnewayResult { + return &EchoServiceEchoOnewayResult{} +} + +func (p *EchoServiceEchoOnewayResult) InitDefault() { + *p = EchoServiceEchoOnewayResult{} +} + +func (p *EchoServiceEchoOnewayResult) String() string { + if p == nil { + return "" + } + return fmt.Sprintf("EchoServiceEchoOnewayResult(%+v)", *p) +} +func (p *EchoServiceEchoOnewayResult) GetResult() interface{} { + return nil +} + +type EchoServicePingArgs struct { +} + +func NewEchoServicePingArgs() *EchoServicePingArgs { + return &EchoServicePingArgs{} +} + +func (p *EchoServicePingArgs) InitDefault() { + *p = EchoServicePingArgs{} +} + +func (p *EchoServicePingArgs) String() string { + if p == nil { + return "" + } + return fmt.Sprintf("EchoServicePingArgs(%+v)", *p) +} +func (p *EchoServicePingArgs) GetFirstArgument() interface{} { + return nil +} + +type EchoServicePingResult struct { +} + +func NewEchoServicePingResult() *EchoServicePingResult { + return &EchoServicePingResult{} +} + +func (p *EchoServicePingResult) InitDefault() { + *p = EchoServicePingResult{} +} + +func (p *EchoServicePingResult) String() string { + if p == nil { + return "" + } + return fmt.Sprintf("EchoServicePingResult(%+v)", *p) +} +func (p *EchoServicePingResult) GetResult() interface{} { + return nil +} diff --git a/thrift_streaming/kitex_gen_slim/echo/k-consts.go b/thrift_streaming/kitex_gen_slim/echo/k-consts.go new file mode 100644 index 0000000..cf25014 --- /dev/null +++ b/thrift_streaming/kitex_gen_slim/echo/k-consts.go @@ -0,0 +1,4 @@ +package echo + +// KitexUnusedProtection is used to prevent 'imported and not used' error. +var KitexUnusedProtection = struct{}{} diff --git a/thrift_streaming/kitexpb_handler.go b/thrift_streaming/kitexpb_handler.go new file mode 100644 index 0000000..d8d8881 --- /dev/null +++ b/thrift_streaming/kitexpb_handler.go @@ -0,0 +1,30 @@ +// Copyright 2023 CloudWeGo 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 thrift_streaming + +import ( + "context" + + "github.com/cloudwego/kitex-tests/thrift_streaming/kitex_gen/kitex_pb" +) + +type KitexPBServiceImpl struct{} + +func (k KitexPBServiceImpl) EchoPingPong(ctx context.Context, req *kitex_pb.Request) (resp *kitex_pb.Response, err error) { + resp = &kitex_pb.Response{ + Message: req.Message, + } + return +} diff --git a/thrift_streaming/kitexpb_test.go b/thrift_streaming/kitexpb_test.go new file mode 100644 index 0000000..0e7a96f --- /dev/null +++ b/thrift_streaming/kitexpb_test.go @@ -0,0 +1,46 @@ +// Copyright 2023 CloudWeGo 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 thrift_streaming + +import ( + "context" + "testing" + + "github.com/cloudwego/kitex/client" + + "github.com/cloudwego/kitex-tests/pkg/test" + "github.com/cloudwego/kitex-tests/thrift_streaming/kitex_gen/kitex_pb" + kitexpbservice "github.com/cloudwego/kitex-tests/thrift_streaming/kitex_gen/kitex_pb/pbservice" +) + +func TestKitexPBClient(t *testing.T) { + req := &kitex_pb.Request{ + Message: "hello", + } + + t.Run("kitex_pb client -> kitex_pb client", func(t *testing.T) { + cli := kitexpbservice.MustNewClient("test", client.WithHostPorts(pbAddr)) + resp, err := cli.EchoPingPong(context.Background(), req) + test.Assert(t, err == nil, err) + test.Assert(t, resp.Message == "hello") + }) + + t.Run("kitex_pb client -> kitex_pb server", func(t *testing.T) { + cli := kitexpbservice.MustNewClient("test", client.WithHostPorts(grpcAddr)) + resp, err := cli.EchoPingPong(context.Background(), req) + test.Assert(t, err == nil, err) + test.Assert(t, resp.Message == "hello") + }) +} diff --git a/thrift_streaming/main_test.go b/thrift_streaming/main_test.go new file mode 100644 index 0000000..8b3c0e4 --- /dev/null +++ b/thrift_streaming/main_test.go @@ -0,0 +1,141 @@ +// Copyright 2023 CloudWeGo 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 thrift_streaming + +import ( + "net" + "strconv" + "sync/atomic" + "testing" + "time" + + "github.com/cloudwego/kitex-tests/thrift_streaming/kitex_gen/echo" + "github.com/cloudwego/kitex-tests/thrift_streaming/kitex_gen/echo/echoservice" + "github.com/cloudwego/kitex-tests/thrift_streaming/kitex_gen/grpc_pb" + grpcpbservice "github.com/cloudwego/kitex-tests/thrift_streaming/kitex_gen/grpc_pb/pbservice" + "github.com/cloudwego/kitex-tests/thrift_streaming/kitex_gen/kitex_pb" + kitexpbservice "github.com/cloudwego/kitex-tests/thrift_streaming/kitex_gen/kitex_pb/pbservice" + cross_echo "github.com/cloudwego/kitex-tests/thrift_streaming/kitex_gen_cross/echo" + cross_echoservice "github.com/cloudwego/kitex-tests/thrift_streaming/kitex_gen_cross/echo/echoservice" + "github.com/cloudwego/kitex/pkg/klog" + "github.com/cloudwego/kitex/server" +) + +func WithServerAddr(hostPort string) server.Option { + addr, err := net.ResolveTCPAddr("tcp", hostPort) + if err != nil { + panic(err) + } + return server.WithServiceAddr(addr) +} + +func WaitServer(hostPort string) { + for begin := time.Now(); time.Since(begin) < time.Second; { + if _, err := net.Dial("tcp", hostPort); err == nil { + klog.Infof("server %s is up", hostPort) + return + } + time.Sleep(time.Millisecond * 10) + } +} + +func RunThriftServer(handler echo.EchoService, addr string, opts ...server.Option) server.Server { + opts = append(opts, WithServerAddr(addr)) + opts = append(opts, server.WithExitWaitTime(time.Millisecond*10)) + svr := echoservice.NewServer(handler, opts...) + go func() { + if err := svr.Run(); err != nil { + panic(err) + } + }() + WaitServer(addr) + return svr +} + +func RunThriftCrossServer(handler cross_echo.EchoService, addr string, opts ...server.Option) server.Server { + opts = append(opts, WithServerAddr(addr)) + opts = append(opts, server.WithExitWaitTime(time.Millisecond*10)) + svr := cross_echoservice.NewServer(handler, opts...) + go func() { + if err := svr.Run(); err != nil { + panic(err) + } + }() + WaitServer(addr) + return svr +} + +func RunGRPCPBServer(handler grpc_pb.PBService, addr string, opts ...server.Option) server.Server { + opts = append(opts, WithServerAddr(addr)) + opts = append(opts, server.WithExitWaitTime(time.Millisecond*10)) + svr := grpcpbservice.NewServer(handler, opts...) + go func() { + if err := svr.Run(); err != nil { + panic(err) + } + }() + WaitServer(addr) + return svr +} + +func RunKitexPBServer(handler kitex_pb.PBService, addr string, opts ...server.Option) server.Server { + opts = append(opts, WithServerAddr(addr)) + opts = append(opts, server.WithExitWaitTime(time.Millisecond*10)) + svr := kitexpbservice.NewServer(handler, opts...) + go func() { + if err := svr.Run(); err != nil { + panic(err) + } + }() + WaitServer(addr) + return svr +} + +var ( + initialPort = int32(9000) + thriftAddr = addrAllocator() + crossAddr = addrAllocator() + slimAddr = addrAllocator() + grpcAddr = addrAllocator() + pbAddr = addrAllocator() +) + +func addrAllocator() string { + addr := "127.0.0.1:" + strconv.Itoa(int(atomic.LoadInt32(&initialPort))) + atomic.AddInt32(&initialPort, 1) + return addr +} + +func TestMain(m *testing.M) { + var thriftSvr, thriftCrossSvr, slimServer, grpcServer, pbServer server.Server + go func() { thriftSvr = RunThriftServer(&EchoServiceImpl{}, thriftAddr) }() + go func() { thriftCrossSvr = RunThriftCrossServer(&CrossEchoServiceImpl{}, crossAddr) }() + go func() { grpcServer = RunGRPCPBServer(&GRPCPBServiceImpl{}, grpcAddr) }() + go func() { pbServer = RunKitexPBServer(&KitexPBServiceImpl{}, pbAddr) }() + go func() { slimServer = RunSlimThriftServer(&SlimEchoServiceImpl{}, slimAddr) }() + defer func() { + go thriftSvr.Stop() + go grpcServer.Stop() + go pbServer.Stop() + go slimServer.Stop() + go thriftCrossSvr.Stop() + }() + WaitServer(thriftAddr) + WaitServer(crossAddr) + WaitServer(grpcAddr) + WaitServer(pbAddr) + WaitServer(slimAddr) + m.Run() +} diff --git a/thrift_streaming/thrift_cross_handler.go b/thrift_streaming/thrift_cross_handler.go new file mode 100644 index 0000000..28d8f9b --- /dev/null +++ b/thrift_streaming/thrift_cross_handler.go @@ -0,0 +1,57 @@ +// Copyright 2023 CloudWeGo 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 thrift_streaming + +import ( + "context" + "errors" + + cross_echo "github.com/cloudwego/kitex-tests/thrift_streaming/kitex_gen_cross/echo" + "github.com/cloudwego/kitex/pkg/klog" +) + +type CrossEchoServiceImpl struct{} + +func (e *CrossEchoServiceImpl) EchoPingPong(ctx context.Context, req1 *cross_echo.EchoRequest, req2 *cross_echo.EchoRequest) (r *cross_echo.EchoResponse, err error) { + klog.Infof("CrossEchoServiceImpl.EchoPingPong: req1 = %v, req2 = %v", req1, req2) + if err = GetError(ctx); err != nil { + klog.Infof("EchoPingPong: context err = %v", err) + return + } + r = &cross_echo.EchoResponse{ + Message: req1.Message + "-" + req2.Message, + } + klog.Infof("EchoPingPong: resp = %v", r) + return r, nil +} + +func (e *CrossEchoServiceImpl) EchoOneway(ctx context.Context, req1 *cross_echo.EchoRequest) (err error) { + klog.Infof("CrossEchoServiceImpl.EchoOneway: req1 = %v", req1) + expected := GetValue(ctx, KeyMessage, "") + if req1.Message != expected { + klog.Infof("EchoOneway: invalid message, req1 = %v, expected = %v", req1, expected) + return errors.New("invalid message") + } + if err = GetError(ctx); err != nil { + klog.Infof("EchoOneway: context err = %v", err) + } + return +} + +func (e *CrossEchoServiceImpl) Ping(ctx context.Context) (err error) { + err = GetError(ctx) + klog.Infof("CrossEchoServiceImpl.Ping: context err = %v", err) + return +} diff --git a/thrift_streaming/thrift_cross_test.go b/thrift_streaming/thrift_cross_test.go new file mode 100644 index 0000000..e5caf57 --- /dev/null +++ b/thrift_streaming/thrift_cross_test.go @@ -0,0 +1,83 @@ +// Copyright 2023 CloudWeGo 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 thrift_streaming + +import ( + "context" + "testing" + + "github.com/bytedance/gopkg/cloud/metainfo" + "github.com/cloudwego/kitex-tests/pkg/test" + "github.com/cloudwego/kitex-tests/thrift_streaming/kitex_gen_cross/echo" + "github.com/cloudwego/kitex-tests/thrift_streaming/kitex_gen_cross/echo/echoservice" + "github.com/cloudwego/kitex/client" + "github.com/cloudwego/kitex/transport" +) + +func TestKitexCrossThriftEchoPingPong(t *testing.T) { + cli := echoservice.MustNewClient( + "service", + client.WithHostPorts(crossAddr), + client.WithTransportProtocol(transport.TTHeaderFramed)) + + t.Run("normal", func(t *testing.T) { + req1 := &echo.EchoRequest{Message: "hello"} + req2 := &echo.EchoRequest{Message: "world"} + resp, err := cli.EchoPingPong(context.Background(), req1, req2) + test.Assert(t, err == nil, err) + test.Assert(t, resp.Message == "hello-world", resp.Message) + }) + + t.Run("exception", func(t *testing.T) { + ctx := metainfo.WithValue(context.Background(), KeyError, "pingpong") + _, err := cli.EchoPingPong(ctx, &echo.EchoRequest{Message: "hello"}, &echo.EchoRequest{Message: "world"}) + test.Assert(t, err != nil, err) + }) +} + +func TestKitexCrossThriftEchoOneway(t *testing.T) { + cli := echoservice.MustNewClient( + "service", + client.WithHostPorts(crossAddr), + client.WithTransportProtocol(transport.TTHeaderFramed)) + + req := &echo.EchoRequest{Message: "oneway"} + + t.Run("normal", func(t *testing.T) { + ctx := metainfo.WithValue(context.Background(), KeyMessage, req.Message) + err := cli.EchoOneway(ctx, req) + test.Assert(t, err == nil, err) + }) + t.Run("normal", func(t *testing.T) { + err := cli.EchoOneway(context.Background(), req) + test.Assert(t, err != nil, err) + }) +} + +func TestKitexCrossThriftPing(t *testing.T) { + cli := echoservice.MustNewClient( + "service", + client.WithHostPorts(crossAddr), + client.WithTransportProtocol(transport.TTHeaderFramed)) + t.Run("normal", func(t *testing.T) { + err := cli.Ping(context.Background()) + test.Assert(t, err == nil, err) + }) + t.Run("exception", func(t *testing.T) { + ctx := metainfo.WithValue(context.Background(), KeyError, "ping") + err := cli.Ping(ctx) + test.Assert(t, err != nil, err) + }) +} diff --git a/thrift_streaming/thrift_handler.go b/thrift_streaming/thrift_handler.go new file mode 100644 index 0000000..ebb66d6 --- /dev/null +++ b/thrift_streaming/thrift_handler.go @@ -0,0 +1,138 @@ +// Copyright 2023 CloudWeGo 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 thrift_streaming + +import ( + "context" + "errors" + "strconv" + + "github.com/cloudwego/kitex/pkg/klog" + + "github.com/cloudwego/kitex-tests/thrift_streaming/kitex_gen/echo" +) + +type EchoServiceImpl struct{} + +func (e EchoServiceImpl) EchoBidirectional(stream echo.EchoService_EchoBidirectionalServer) (err error) { + klog.Infof("EchoBidirectional: start") + count := GetInt(stream.Context(), KeyCount, 0) + if count == 0 { + return errors.New("count not set in metadata") + } + var req *echo.EchoRequest + var resp *echo.EchoResponse + for i := 0; i < count; i++ { + req, err = stream.Recv() + if err != nil { + klog.Infof("EchoBidirectional: recv error = %v", err) + return + } + klog.Infof("EchoBidirectional: recv req = %v", req) + resp = &echo.EchoResponse{ + Message: req.Message, + } + if err = stream.Send(resp); err != nil { + klog.Infof("EchoBidirectional: send error = %v", err) + return + } + klog.Infof("EchoBidirectional: send resp = %v", resp) + } + return +} + +func (e EchoServiceImpl) EchoClient(stream echo.EchoService_EchoClientServer) (err error) { + klog.Infof("EchoClient: start") + count := GetInt(stream.Context(), KeyCount, 0) + var req *echo.EchoRequest + for i := 0; i < count; i++ { + req, err = stream.Recv() + if err != nil { + klog.Infof("EchoClient: recv error = %v", err) + return + } + klog.Infof("EchoClient: recv req = %v", req) + } + resp := &echo.EchoResponse{ + Message: strconv.Itoa(count), + } + if err = stream.SendAndClose(resp); err != nil { + klog.Infof("EchoClient: send&close error = %v", err) + return + } + klog.Infof("EchoClient: send&close resp = %v", resp) + return +} + +func (e EchoServiceImpl) EchoServer(req *echo.EchoRequest, stream echo.EchoService_EchoServerServer) (err error) { + klog.Infof("EchoServer: recv req = %v", req) + count := GetInt(stream.Context(), KeyCount, 0) + for i := 0; i < count; i++ { + resp := &echo.EchoResponse{ + Message: req.Message + "-" + strconv.Itoa(i), + } + if err = stream.Send(resp); err != nil { + klog.Infof("EchoServer: send error = %v", err) + return + } + klog.Infof("EchoServer: send resp = %v", resp) + } + return nil +} + +func (e EchoServiceImpl) EchoUnary(ctx context.Context, req1 *echo.EchoRequest) (r *echo.EchoResponse, err error) { + klog.Infof("EchoUnary: req1 = %v", req1) + if err = GetError(ctx); err != nil { + klog.Infof("EchoPingPong: context err = %v", err) + return + } + r = &echo.EchoResponse{ + Message: req1.Message, + } + klog.Infof("EchoUnary: resp = %v", r) + return r, nil +} + +func (e EchoServiceImpl) EchoPingPong(ctx context.Context, req1, req2 *echo.EchoRequest) (r *echo.EchoResponse, err error) { + klog.Infof("EchoPingPong: req1 = %v, req2 = %v", req1, req2) + if err = GetError(ctx); err != nil { + klog.Infof("EchoPingPong: context err = %v", err) + return + } + r = &echo.EchoResponse{ + Message: req1.Message + "-" + req2.Message, + } + klog.Infof("EchoPingPong: resp = %v", r) + return r, nil +} + +func (e EchoServiceImpl) EchoOneway(ctx context.Context, req1 *echo.EchoRequest) (err error) { + klog.Infof("EchoOneway: req1 = %v", req1) + expected := GetValue(ctx, KeyMessage, "") + if req1.Message != expected { + klog.Infof("EchoOneway: invalid message, req1 = %v, expected = %v", req1, expected) + return errors.New("invalid message") + } + if err = GetError(ctx); err != nil { + klog.Infof("EchoOneway: context err = %v", err) + } + return +} + +func (e EchoServiceImpl) Ping(ctx context.Context) (err error) { + err = GetError(ctx) + klog.Infof("Ping: context err = %v", err) + return +} diff --git a/thrift_streaming/thrift_old_client_test.go b/thrift_streaming/thrift_old_client_test.go new file mode 100644 index 0000000..2da3dc4 --- /dev/null +++ b/thrift_streaming/thrift_old_client_test.go @@ -0,0 +1,137 @@ +// Copyright 2023 CloudWeGo 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 thrift_streaming + +import ( + "context" + "strconv" + "strings" + "testing" + + "github.com/bytedance/gopkg/cloud/metainfo" + "github.com/cloudwego/kitex/client" + "github.com/cloudwego/kitex/transport" + + "github.com/cloudwego/kitex-tests/pkg/test" + "github.com/cloudwego/kitex-tests/thrift_streaming/kitex_gen_old/echo" + "github.com/cloudwego/kitex-tests/thrift_streaming/kitex_gen_old/echo/echoservice" +) + +func TestOldKitexThriftBidirectional(t *testing.T) { + cli := echoservice.MustNewClient( + "service", + client.WithHostPorts(thriftAddr)) + t.Run("normal", func(t *testing.T) { + n := 3 + ctx := metainfo.WithValue(context.Background(), KeyCount, strconv.Itoa(n)) + _, err := cli.EchoBidirectional(ctx, &echo.EchoRequest{Message: "bidirectional"}) + test.Assert(t, err != nil, err) + test.Assert(t, strings.Contains(err.Error(), "please call with Kitex StreamClient"), err) + }) +} + +func TestOldKitexThriftClient(t *testing.T) { + cli := echoservice.MustNewClient( + "service", + client.WithHostPorts(thriftAddr)) + t.Run("normal", func(t *testing.T) { + n := 3 + ctx := metainfo.WithValue(context.Background(), KeyCount, strconv.Itoa(n)) + _, err := cli.EchoClient(ctx, &echo.EchoRequest{Message: "client"}) + test.Assert(t, err != nil, err) + test.Assert(t, strings.Contains(err.Error(), "please call with Kitex StreamClient"), err) + }) +} + +func TestOldKitexThriftServer(t *testing.T) { + cli := echoservice.MustNewClient( + "service", + client.WithHostPorts(thriftAddr), + ) + t.Run("normal", func(t *testing.T) { + n := 3 + ctx := metainfo.WithValue(context.Background(), KeyCount, strconv.Itoa(n)) + _, err := cli.EchoServer(ctx, &echo.EchoRequest{Message: "server"}) + test.Assert(t, err != nil, err) + test.Assert(t, strings.Contains(err.Error(), "please call with Kitex StreamClient"), err) + }) +} + +func TestOldKitexThriftEchoUnary(t *testing.T) { + cli := echoservice.MustNewClient( + "service", + client.WithHostPorts(thriftAddr)) + t.Run("normal", func(t *testing.T) { + _, err := cli.EchoUnary(context.Background(), &echo.EchoRequest{Message: "unary"}) + test.Assert(t, err != nil, err) + test.Assert(t, strings.Contains(err.Error(), "please call with Kitex StreamClient"), err) + }) +} + +func TestOldKitexThriftEchoPingPong(t *testing.T) { + cli := echoservice.MustNewClient( + "service", + client.WithHostPorts(thriftAddr), + client.WithTransportProtocol(transport.TTHeaderFramed)) + + t.Run("normal", func(t *testing.T) { + req1 := &echo.EchoRequest{Message: "hello"} + req2 := &echo.EchoRequest{Message: "world"} + resp, err := cli.EchoPingPong(context.Background(), req1, req2) + test.Assert(t, err == nil, err) + test.Assert(t, resp.Message == "hello-world", resp.Message) + }) + + t.Run("exception", func(t *testing.T) { + ctx := metainfo.WithValue(context.Background(), KeyError, "pingpong") + _, err := cli.EchoPingPong(ctx, &echo.EchoRequest{Message: "hello"}, &echo.EchoRequest{Message: "world"}) + test.Assert(t, err != nil, err) + }) +} + +func TestOldKitexThriftEchoOneway(t *testing.T) { + cli := echoservice.MustNewClient( + "service", + client.WithHostPorts(thriftAddr), + client.WithTransportProtocol(transport.TTHeaderFramed)) + + req := &echo.EchoRequest{Message: "oneway"} + + t.Run("normal", func(t *testing.T) { + ctx := metainfo.WithValue(context.Background(), KeyMessage, req.Message) + err := cli.EchoOneway(ctx, req) + test.Assert(t, err == nil, err) + }) + t.Run("normal", func(t *testing.T) { + err := cli.EchoOneway(context.Background(), req) + test.Assert(t, err != nil, err) + }) +} + +func TestOldKitexThriftPing(t *testing.T) { + cli := echoservice.MustNewClient( + "service", + client.WithHostPorts(thriftAddr), + client.WithTransportProtocol(transport.TTHeaderFramed)) + t.Run("normal", func(t *testing.T) { + err := cli.Ping(context.Background()) + test.Assert(t, err == nil, err) + }) + t.Run("exception", func(t *testing.T) { + ctx := metainfo.WithValue(context.Background(), KeyError, "ping") + err := cli.Ping(ctx) + test.Assert(t, err != nil, err) + }) +} diff --git a/thrift_streaming/thrift_slim_amd64_test.go b/thrift_streaming/thrift_slim_amd64_test.go new file mode 100644 index 0000000..9f85a8f --- /dev/null +++ b/thrift_streaming/thrift_slim_amd64_test.go @@ -0,0 +1,580 @@ +//go:build amd64 && !windows && go1.16 && !go1.22 && !disablefrugal +// +build amd64,!windows,go1.16,!go1.22,!disablefrugal + +// Copyright 2023 CloudWeGo 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 thrift_streaming + +import ( + "context" + "errors" + "fmt" + "strconv" + "sync" + "testing" + "time" + + "github.com/bytedance/gopkg/cloud/metainfo" + "github.com/cloudwego/kitex/client" + "github.com/cloudwego/kitex/client/streamclient" + "github.com/cloudwego/kitex/pkg/endpoint" + "github.com/cloudwego/kitex/pkg/remote/codec/thrift" + "github.com/cloudwego/kitex/pkg/streaming" + "github.com/cloudwego/kitex/server" + "github.com/cloudwego/kitex/transport" + + "github.com/cloudwego/kitex-tests/pkg/test" + "github.com/cloudwego/kitex-tests/thrift_streaming/kitex_gen_slim/echo" + "github.com/cloudwego/kitex-tests/thrift_streaming/kitex_gen_slim/echo/echoservice" +) + +var svrCodecOpt = server.WithPayloadCodec(thrift.NewThriftCodecWithConfig(thrift.FrugalReadWrite)) + +func RunSlimThriftServer(handler echo.EchoService, addr string, opts ...server.Option) server.Server { + opts = append(opts, WithServerAddr(addr)) + opts = append(opts, server.WithExitWaitTime(time.Millisecond*10)) + opts = append(opts, server.WithPayloadCodec(thrift.NewThriftCodecWithConfig(thrift.FrugalReadWrite))) + svr := echoservice.NewServer(handler, opts...) + go func() { + if err := svr.Run(); err != nil { + panic(err) + } + }() + WaitServer(addr) + return svr +} + +func TestSlimKitexThriftBidirectional(t *testing.T) { + cli := echoservice.MustNewStreamClient( + "service", + streamclient.WithPayloadCodec(thrift.NewThriftCodecWithConfig(thrift.FrugalReadWrite)), + streamclient.WithHostPorts(slimAddr)) + t.Run("normal", func(t *testing.T) { + n := 3 + ctx := metainfo.WithValue(context.Background(), KeyCount, strconv.Itoa(n)) + stream, err := cli.EchoBidirectional(ctx) + test.Assert(t, err == nil, err) + wg := new(sync.WaitGroup) + wg.Add(2) + go func() { + defer wg.Done() + for i := 0; i < n; i++ { + req := &echo.EchoRequest{Message: "bidirectional-" + strconv.Itoa(i)} + err = stream.Send(req) + test.Assert(t, err == nil, err) + } + }() + go func() { + defer wg.Done() + for i := 0; i < n; i++ { + resp, err := stream.Recv() + test.Assert(t, err == nil, err) + test.Assert(t, resp.Message == "bidirectional-"+strconv.Itoa(i), resp.Message) + } + }() + wg.Wait() + }) +} + +func TestSlimKitexThriftClient(t *testing.T) { + cli := echoservice.MustNewStreamClient( + "service", + streamclient.WithPayloadCodec(thrift.NewThriftCodecWithConfig(thrift.FrugalReadWrite)), + streamclient.WithHostPorts(slimAddr)) + t.Run("normal", func(t *testing.T) { + n := 3 + ctx := metainfo.WithValue(context.Background(), KeyCount, strconv.Itoa(n)) + stream, err := cli.EchoClient(ctx) + test.Assert(t, err == nil, err) + for i := 0; i < n; i++ { + req := &echo.EchoRequest{Message: "client"} + err = stream.Send(req) + test.Assert(t, err == nil, err) + } + resp, err := stream.CloseAndRecv() + test.Assert(t, err == nil, err) + test.Assert(t, resp.Message == strconv.Itoa(n), resp.Message) + }) +} + +func TestSlimKitexThriftServer(t *testing.T) { + cli := echoservice.MustNewStreamClient( + "service", + streamclient.WithPayloadCodec(thrift.NewThriftCodecWithConfig(thrift.FrugalReadWrite)), + streamclient.WithHostPorts(slimAddr)) + + t.Run("normal", func(t *testing.T) { + n := 3 + req := &echo.EchoRequest{Message: "server"} + ctx := metainfo.WithValue(context.Background(), KeyCount, strconv.Itoa(n)) + stream, err := cli.EchoServer(ctx, req) + test.Assert(t, err == nil, err) + for i := 0; i < n; i++ { + resp, err := stream.Recv() + test.Assert(t, err == nil, err) + test.Assert(t, resp.Message == "server-"+strconv.Itoa(i), resp.Message) + } + }) +} + +func TestSlimKitexThriftEchoUnary(t *testing.T) { + cli := echoservice.MustNewStreamClient( + "service", + streamclient.WithPayloadCodec(thrift.NewThriftCodecWithConfig(thrift.FrugalReadWrite)), + streamclient.WithHostPorts(slimAddr)) + + t.Run("normal", func(t *testing.T) { + req := &echo.EchoRequest{Message: "unary"} + resp, err := cli.EchoUnary(context.Background(), req) + test.Assert(t, err == nil, err) + test.Assert(t, resp.Message == "unary", resp.Message) + }) + + t.Run("exception", func(t *testing.T) { + ctx := metainfo.WithValue(context.Background(), "error", "unary") + _, err := cli.EchoUnary(ctx, &echo.EchoRequest{Message: "unary"}) + test.Assert(t, err != nil, err) + }) +} + +func TestSlimKitexThriftEchoPingPong(t *testing.T) { + cli := echoservice.MustNewClient( + "service", + client.WithHostPorts(slimAddr), + client.WithPayloadCodec(thrift.NewThriftCodecWithConfig(thrift.FrugalReadWrite)), + client.WithTransportProtocol(transport.TTHeaderFramed)) + + t.Run("normal", func(t *testing.T) { + req1 := &echo.EchoRequest{Message: "hello"} + req2 := &echo.EchoRequest{Message: "world"} + resp, err := cli.EchoPingPong(context.Background(), req1, req2) + test.Assert(t, err == nil, err) + test.Assert(t, resp.Message == "hello-world", resp.Message) + }) + + t.Run("exception", func(t *testing.T) { + ctx := metainfo.WithValue(context.Background(), KeyError, "pingpong") + _, err := cli.EchoPingPong(ctx, &echo.EchoRequest{Message: "hello"}, &echo.EchoRequest{Message: "world"}) + test.Assert(t, err != nil, err) + }) +} + +func TestSlimKitexThriftEchoOneway(t *testing.T) { + cli := echoservice.MustNewClient( + "service", + client.WithPayloadCodec(thrift.NewThriftCodecWithConfig(thrift.FrugalReadWrite)), + client.WithHostPorts(slimAddr), + client.WithTransportProtocol(transport.TTHeaderFramed)) + + req := &echo.EchoRequest{Message: "oneway"} + + t.Run("normal", func(t *testing.T) { + ctx := metainfo.WithValue(context.Background(), KeyMessage, req.Message) + err := cli.EchoOneway(ctx, req) + test.Assert(t, err == nil, err) + }) + t.Run("normal", func(t *testing.T) { + err := cli.EchoOneway(context.Background(), req) + test.Assert(t, err != nil, err) + }) +} + +func TestSlimKitexThriftPing(t *testing.T) { + cli := echoservice.MustNewClient( + "service", + client.WithPayloadCodec(thrift.NewThriftCodecWithConfig(thrift.FrugalReadWrite)), + client.WithHostPorts(slimAddr), + client.WithTransportProtocol(transport.TTHeaderFramed)) + t.Run("normal", func(t *testing.T) { + err := cli.Ping(context.Background()) + test.Assert(t, err == nil, err) + }) + t.Run("exception", func(t *testing.T) { + ctx := metainfo.WithValue(context.Background(), KeyError, "ping") + err := cli.Ping(ctx) + test.Assert(t, err != nil, err) + }) +} + +func TestSlimKitexClientMiddleware(t *testing.T) { + cli := echoservice.MustNewClient( + "service", + client.WithPayloadCodec(thrift.NewThriftCodecWithConfig(thrift.FrugalReadWrite)), + client.WithHostPorts(slimAddr), + client.WithTransportProtocol(transport.TTHeaderFramed), + client.WithMiddleware(func(endpoint endpoint.Endpoint) endpoint.Endpoint { + return func(ctx context.Context, args, result interface{}) (err error) { + req := args.(*echo.EchoServiceEchoPingPongArgs).Req1 + test.Assert(t, req.Message == "request", req.Message) + result.(*echo.EchoServiceEchoPingPongResult).Success = &echo.EchoResponse{Message: "response"} + return nil + } + }), + ) + req := &echo.EchoRequest{Message: "request"} + resp, err := cli.EchoPingPong(context.Background(), req, &echo.EchoRequest{Message: ""}) + test.Assert(t, err == nil, err) + test.Assert(t, resp.Message == "response", resp.Message) +} + +func TestSlimKitexStreamClientMiddlewareUnary(t *testing.T) { + cli := echoservice.MustNewStreamClient( + "service", + streamclient.WithPayloadCodec(thrift.NewThriftCodecWithConfig(thrift.FrugalReadWrite)), + streamclient.WithHostPorts(slimAddr), + streamclient.WithMiddleware(func(endpoint endpoint.Endpoint) endpoint.Endpoint { + return func(ctx context.Context, args, result interface{}) (err error) { + req := args.(*echo.EchoServiceEchoUnaryArgs).Req1 + test.Assert(t, req.Message == "request", req.Message) + result.(*echo.EchoServiceEchoUnaryResult).Success = &echo.EchoResponse{Message: "response"} + return nil + } + }), + ) + req := &echo.EchoRequest{Message: "request"} + resp, err := cli.EchoUnary(context.Background(), req) + test.Assert(t, err == nil, err) + test.Assert(t, resp.Message == "response", resp.Message) +} + +func TestSlimKitexStreamClientMiddlewareBidirectional(t *testing.T) { + cli := echoservice.MustNewStreamClient( + "service", + streamclient.WithHostPorts(slimAddr), + streamclient.WithPayloadCodec(thrift.NewThriftCodecWithConfig(thrift.FrugalReadWrite)), + streamclient.WithSendMiddleware(func(next endpoint.SendEndpoint) endpoint.SendEndpoint { + return func(stream streaming.Stream, req interface{}) (err error) { + test.Assert(t, req.(*echo.EchoRequest).Message == "request") + return next(stream, req) + } + }), + streamclient.WithRecvMiddleware(func(next endpoint.RecvEndpoint) endpoint.RecvEndpoint { + return func(stream streaming.Stream, resp interface{}) (err error) { + err = next(stream, resp) + rsp := resp.(*echo.EchoResponse) + test.Assert(t, rsp.Message == "request") + rsp.Message = "response-modified-in-mw" + return err + } + }), + ) + + ctx := metainfo.WithValue(context.Background(), KeyCount, "1") + stream, err := cli.EchoBidirectional(ctx) + test.Assert(t, err == nil, err) + + err = stream.Send(&echo.EchoRequest{Message: "request"}) + test.Assert(t, err == nil, err) + + resp, err := stream.Recv() + test.Assert(t, err == nil, err) + test.Assert(t, resp.Message == "response-modified-in-mw", resp.Message) +} + +func TestSlimKitexStreamClientMiddlewareClient(t *testing.T) { + cli := echoservice.MustNewStreamClient( + "service", + streamclient.WithPayloadCodec(thrift.NewThriftCodecWithConfig(thrift.FrugalReadWrite)), + streamclient.WithHostPorts(slimAddr), + streamclient.WithSendMiddleware(func(next endpoint.SendEndpoint) endpoint.SendEndpoint { + return func(stream streaming.Stream, req interface{}) (err error) { + test.Assert(t, req.(*echo.EchoRequest).Message == "request") + return next(stream, req) + } + }), + streamclient.WithRecvMiddleware(func(next endpoint.RecvEndpoint) endpoint.RecvEndpoint { + return func(stream streaming.Stream, resp interface{}) (err error) { + err = next(stream, resp) + rsp := resp.(*echo.EchoResponse) + test.Assert(t, rsp.Message == "2") + rsp.Message = "response-modified-in-mw" + return err + } + }), + ) + ctx := metainfo.WithValue(context.Background(), KeyCount, "2") + stream, err := cli.EchoClient(ctx) + test.Assert(t, err == nil, err) + + err = stream.Send(&echo.EchoRequest{Message: "request"}) + test.Assert(t, err == nil, err) + + err = stream.Send(&echo.EchoRequest{Message: "request"}) + test.Assert(t, err == nil, err) + + resp, err := stream.CloseAndRecv() + test.Assert(t, err == nil, err) + test.Assert(t, resp.Message == "response-modified-in-mw", resp.Message) +} + +func TestSlimKitexStreamClientMiddlewareServer(t *testing.T) { + recvCount := 0 + cli := echoservice.MustNewStreamClient( + "service", + streamclient.WithPayloadCodec(thrift.NewThriftCodecWithConfig(thrift.FrugalReadWrite)), + streamclient.WithHostPorts(slimAddr), + streamclient.WithSendMiddleware(func(next endpoint.SendEndpoint) endpoint.SendEndpoint { + return func(stream streaming.Stream, req interface{}) (err error) { + test.Assert(t, req.(*echo.EchoRequest).Message == "request") + return next(stream, req) + } + }), + streamclient.WithRecvMiddleware(func(next endpoint.RecvEndpoint) endpoint.RecvEndpoint { + return func(stream streaming.Stream, resp interface{}) (err error) { + err = next(stream, resp) + rsp := resp.(*echo.EchoResponse) + test.Assert(t, rsp.Message == "request-"+strconv.Itoa(recvCount)) + recvCount += 1 + rsp.Message = "response-modified-in-mw" + return err + } + }), + ) + ctx := metainfo.WithValue(context.Background(), KeyCount, "2") + stream, err := cli.EchoServer(ctx, &echo.EchoRequest{Message: "request"}) + test.Assert(t, err == nil, err) + + resp, err := stream.Recv() + test.Assert(t, err == nil, err) + test.Assert(t, resp.Message == "response-modified-in-mw", resp.Message) + + resp, err = stream.Recv() + test.Assert(t, err == nil, err) + test.Assert(t, resp.Message == "response-modified-in-mw", resp.Message) +} + +func TestSlimKitexServerMiddleware(t *testing.T) { + addr := addrAllocator() + t.Run("pingpong", func(t *testing.T) { + svr := RunSlimThriftServer(&SlimEchoServiceImpl{}, addr, svrCodecOpt, + server.WithMiddleware(func(e endpoint.Endpoint) endpoint.Endpoint { + return func(ctx context.Context, args, result interface{}) (err error) { + realArgs := args.(*echo.EchoServiceEchoPingPongArgs) + req1, req2 := realArgs.Req1, realArgs.Req2 + test.Assert(t, req1.Message == "ping") + test.Assert(t, req2.Message == "pong") + err = e(ctx, args, result) + resp := result.(*echo.EchoServiceEchoPingPongResult) + test.Assert(t, resp.Success.Message == "ping-pong") + resp.Success.Message = "response" + return nil + } + })) + defer svr.Stop() + + cli := echoservice.MustNewClient( + "service", + client.WithPayloadCodec(thrift.NewThriftCodecWithConfig(thrift.FrugalReadWrite)), + client.WithHostPorts(addr), + client.WithTransportProtocol(transport.TTHeaderFramed), + ) + req1, req2 := &echo.EchoRequest{Message: "ping"}, &echo.EchoRequest{Message: "pong"} + resp, err := cli.EchoPingPong(context.Background(), req1, req2) + test.Assert(t, err == nil, err) + test.Assert(t, resp.Message == "response", resp.Message) + }) + + t.Run("unary", func(t *testing.T) { + svr := RunSlimThriftServer(&SlimEchoServiceImpl{}, addr, svrCodecOpt, + server.WithMiddleware(func(e endpoint.Endpoint) endpoint.Endpoint { + return func(ctx context.Context, args, result interface{}) (err error) { + realArgs, ok := args.(*echo.EchoServiceEchoUnaryArgs) + if !ok { + return fmt.Errorf("invalid args type: %T", args) + } + if realArgs.Req1.Message != "unary" { + return fmt.Errorf("invalid realArgs.Req1.Message: %v", realArgs.Req1.Message) + } + if err = e(ctx, args, result); err != nil { + return err + } + resp, ok := result.(*echo.EchoServiceEchoUnaryResult) + if !ok { + return fmt.Errorf("invalid result type: %T", result) + } + if resp.Success.Message != "unary" { + return fmt.Errorf("invalid resp.Success.Message: %v", resp.Success.Message) + } + resp.Success.Message = "response" + return nil + } + }), + server.WithRecvMiddleware(func(e endpoint.RecvEndpoint) endpoint.RecvEndpoint { + return func(stream streaming.Stream, resp interface{}) (err error) { + t.Errorf("recv middleware should not be called") + return errors.New("recv middleware should not be called") + } + }), + server.WithSendMiddleware(func(e endpoint.SendEndpoint) endpoint.SendEndpoint { + return func(stream streaming.Stream, req interface{}) (err error) { + t.Errorf("send middleware should not be called") + return errors.New("send middleware should not be called") + } + })) + defer svr.Stop() + + cli := echoservice.MustNewStreamClient("service", + streamclient.WithPayloadCodec(thrift.NewThriftCodecWithConfig(thrift.FrugalReadWrite)), + streamclient.WithHostPorts(addr)) + req := &echo.EchoRequest{Message: "unary"} + resp, err := cli.EchoUnary(context.Background(), req) + test.Assert(t, err == nil, err) + test.Assert(t, resp.Message == "response", resp.Message) + }) + + t.Run("bidirectional streaming", func(t *testing.T) { + svr := RunSlimThriftServer(&SlimEchoServiceImpl{}, addr, svrCodecOpt, + server.WithMiddleware(func(e endpoint.Endpoint) endpoint.Endpoint { + return func(ctx context.Context, args, result interface{}) (err error) { + _, ok := args.(*streaming.Args) + test.Assert(t, ok) + return e(ctx, args, result) + } + }), + server.WithRecvMiddleware(func(e endpoint.RecvEndpoint) endpoint.RecvEndpoint { + return func(stream streaming.Stream, req interface{}) (err error) { + err = e(stream, req) + realReq, ok := req.(*echo.EchoRequest) + test.Assert(t, ok) + test.Assert(t, realReq.Message == "request") + realReq.Message = "bidirectional" + return + } + }), + server.WithSendMiddleware(func(e endpoint.SendEndpoint) endpoint.SendEndpoint { + return func(stream streaming.Stream, resp interface{}) (err error) { + realResp, ok := resp.(*echo.EchoResponse) + test.Assert(t, ok) + test.Assert(t, realResp.Message == "bidirectional") + realResp.Message = "response" + return e(stream, realResp) + } + })) + defer svr.Stop() + + cli := echoservice.MustNewStreamClient("service", + streamclient.WithPayloadCodec(thrift.NewThriftCodecWithConfig(thrift.FrugalReadWrite)), + streamclient.WithHostPorts(addr)) + ctx := metainfo.WithValue(context.Background(), KeyCount, "1") + stream, err := cli.EchoBidirectional(ctx) + test.Assert(t, err == nil, err) + + req := &echo.EchoRequest{Message: "request"} + err = stream.Send(req) + test.Assert(t, err == nil, err) + + resp, err := stream.Recv() + test.Assert(t, err == nil, err) + test.Assert(t, resp.Message == "response", resp.Message) + }) + + t.Run("server streaming", func(t *testing.T) { + count := 0 + svr := RunSlimThriftServer(&SlimEchoServiceImpl{}, addr, svrCodecOpt, + server.WithMiddleware(func(e endpoint.Endpoint) endpoint.Endpoint { + return func(ctx context.Context, args, result interface{}) (err error) { + _, ok := args.(*streaming.Args) + test.Assert(t, ok) + return e(ctx, args, result) + } + }), + server.WithRecvMiddleware(func(e endpoint.RecvEndpoint) endpoint.RecvEndpoint { + return func(stream streaming.Stream, req interface{}) (err error) { + err = e(stream, req) + realReq, ok := req.(*echo.EchoRequest) + test.Assert(t, ok) + test.Assert(t, realReq.Message == "request") + realReq.Message = "server" + return + } + }), + server.WithSendMiddleware(func(e endpoint.SendEndpoint) endpoint.SendEndpoint { + return func(stream streaming.Stream, resp interface{}) (err error) { + realResp, ok := resp.(*echo.EchoResponse) + test.Assert(t, ok) + test.Assert(t, realResp.Message == "server-"+strconv.Itoa(count)) + realResp.Message = "response-" + strconv.Itoa(count) + count += 1 + return e(stream, realResp) + } + })) + defer svr.Stop() + + cli := echoservice.MustNewStreamClient("service", + streamclient.WithPayloadCodec(thrift.NewThriftCodecWithConfig(thrift.FrugalReadWrite)), + streamclient.WithHostPorts(addr)) + ctx := metainfo.WithValue(context.Background(), KeyCount, "2") + stream, err := cli.EchoServer(ctx, &echo.EchoRequest{Message: "request"}) + test.Assert(t, err == nil, err) + + resp, err := stream.Recv() + test.Assert(t, err == nil, err) + test.Assert(t, resp.Message == "response-0", resp.Message) + + resp, err = stream.Recv() + test.Assert(t, err == nil, err) + test.Assert(t, resp.Message == "response-1", resp.Message) + }) + + t.Run("client streaming", func(t *testing.T) { + count := 0 + svr := RunSlimThriftServer(&SlimEchoServiceImpl{}, addr, svrCodecOpt, + server.WithMiddleware(func(e endpoint.Endpoint) endpoint.Endpoint { + return func(ctx context.Context, args, result interface{}) (err error) { + _, ok := args.(*streaming.Args) + test.Assert(t, ok) + return e(ctx, args, result) + } + }), + server.WithRecvMiddleware(func(e endpoint.RecvEndpoint) endpoint.RecvEndpoint { + return func(stream streaming.Stream, req interface{}) (err error) { + err = e(stream, req) + realReq, ok := req.(*echo.EchoRequest) + test.Assert(t, ok) + test.Assert(t, realReq.Message == "request-"+strconv.Itoa(count), realReq.Message) + count += 1 + realReq.Message += "_recv_middleware" + return + } + }), + server.WithSendMiddleware(func(e endpoint.SendEndpoint) endpoint.SendEndpoint { + return func(stream streaming.Stream, resp interface{}) (err error) { + realResp, ok := resp.(*echo.EchoResponse) + test.Assert(t, ok) + test.Assert(t, realResp.Message == "2") + realResp.Message += "_send_middleware" + return e(stream, realResp) + } + })) + defer svr.Stop() + + cli := echoservice.MustNewStreamClient("service", + streamclient.WithPayloadCodec(thrift.NewThriftCodecWithConfig(thrift.FrugalReadWrite)), + streamclient.WithHostPorts(addr)) + ctx := metainfo.WithValue(context.Background(), KeyCount, "2") + stream, err := cli.EchoClient(ctx) + test.Assert(t, err == nil, err) + + err = stream.Send(&echo.EchoRequest{Message: "request-0"}) + test.Assert(t, err == nil, err) + + err = stream.Send(&echo.EchoRequest{Message: "request-1"}) + test.Assert(t, err == nil, err) + + resp, err := stream.CloseAndRecv() + test.Assert(t, err == nil, err) + test.Assert(t, resp.Message == "2_send_middleware", resp.Message) + }) +} diff --git a/thrift_streaming/thrift_slim_handler.go b/thrift_streaming/thrift_slim_handler.go new file mode 100644 index 0000000..0d56d4b --- /dev/null +++ b/thrift_streaming/thrift_slim_handler.go @@ -0,0 +1,135 @@ +// Copyright 2023 CloudWeGo 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 thrift_streaming + +import ( + "context" + "errors" + "strconv" + + "github.com/cloudwego/kitex/pkg/klog" + + "github.com/cloudwego/kitex-tests/thrift_streaming/kitex_gen_slim/echo" +) + +type SlimEchoServiceImpl struct{} + +func (e *SlimEchoServiceImpl) EchoBidirectional(stream echo.EchoService_EchoBidirectionalServer) (err error) { + klog.Infof("EchoBidirectional: start") + count := GetInt(stream.Context(), KeyCount, 0) + var req *echo.EchoRequest + var resp *echo.EchoResponse + for i := 0; i < count; i++ { + req, err = stream.Recv() + if err != nil { + klog.Infof("EchoBidirectional: recv error = %v", err) + return + } + klog.Infof("EchoBidirectional: recv req = %v", req) + resp = &echo.EchoResponse{ + Message: req.Message, + } + if err = stream.Send(resp); err != nil { + klog.Infof("EchoBidirectional: send error = %v", err) + return + } + klog.Infof("EchoBidirectional: send resp = %v", resp) + } + return +} + +func (e *SlimEchoServiceImpl) EchoClient(stream echo.EchoService_EchoClientServer) (err error) { + klog.Infof("EchoClient: start") + count := GetInt(stream.Context(), KeyCount, 0) + var req *echo.EchoRequest + for i := 0; i < count; i++ { + req, err = stream.Recv() + if err != nil { + klog.Infof("EchoClient: recv error = %v", err) + return + } + klog.Infof("EchoClient: recv req = %v", req) + } + resp := &echo.EchoResponse{ + Message: strconv.Itoa(count), + } + if err = stream.SendAndClose(resp); err != nil { + klog.Infof("EchoClient: send&close error = %v", err) + return + } + klog.Infof("EchoClient: send&close resp = %v", resp) + return +} + +func (e *SlimEchoServiceImpl) EchoServer(req *echo.EchoRequest, stream echo.EchoService_EchoServerServer) (err error) { + klog.Infof("EchoServer: recv req = %v", req) + count := GetInt(stream.Context(), KeyCount, 0) + for i := 0; i < count; i++ { + resp := &echo.EchoResponse{ + Message: req.Message + "-" + strconv.Itoa(i), + } + if err = stream.Send(resp); err != nil { + klog.Infof("EchoServer: send error = %v", err) + return + } + klog.Infof("EchoServer: send resp = %v", resp) + } + return nil +} + +func (e *SlimEchoServiceImpl) EchoUnary(ctx context.Context, req1 *echo.EchoRequest) (r *echo.EchoResponse, err error) { + klog.Infof("EchoUnary: req1 = %v", req1) + if err = GetError(ctx); err != nil { + klog.Infof("EchoPingPong: context err = %v", err) + return + } + r = &echo.EchoResponse{ + Message: req1.Message, + } + klog.Infof("EchoUnary: resp = %v", r) + return r, nil +} + +func (e *SlimEchoServiceImpl) EchoPingPong(ctx context.Context, req1, req2 *echo.EchoRequest) (r *echo.EchoResponse, err error) { + klog.Infof("EchoPingPong: req1 = %v, req2 = %v", req1, req2) + if err = GetError(ctx); err != nil { + klog.Infof("EchoPingPong: context err = %v", err) + return + } + r = &echo.EchoResponse{ + Message: req1.Message + "-" + req2.Message, + } + klog.Infof("EchoPingPong: resp = %v", r) + return r, nil +} + +func (e *SlimEchoServiceImpl) EchoOneway(ctx context.Context, req1 *echo.EchoRequest) (err error) { + klog.Infof("EchoOneway: req1 = %v", req1) + expected := GetValue(ctx, KeyMessage, "") + if req1.Message != expected { + klog.Infof("EchoOneway: invalid message, req1 = %v, expected = %v", req1, expected) + return errors.New("invalid message") + } + if err = GetError(ctx); err != nil { + klog.Infof("EchoOneway: context err = %v", err) + } + return +} + +func (e *SlimEchoServiceImpl) Ping(ctx context.Context) (err error) { + err = GetError(ctx) + klog.Infof("Ping: context err = %v", err) + return +} diff --git a/thrift_streaming/thrift_slim_others_test.go b/thrift_streaming/thrift_slim_others_test.go new file mode 100644 index 0000000..9fe18c6 --- /dev/null +++ b/thrift_streaming/thrift_slim_others_test.go @@ -0,0 +1,29 @@ +//go:build !amd64 && windows && !go1.16 && go1.22 && disablefrugal +// +build !amd64,windows,!go1.16,go1.22,disablefrugal + +// Copyright 2023 CloudWeGo 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 thrift_streaming + +import ( + "github.com/cloudwego/kitex/server" + + "github.com/cloudwego/kitex-tests/thrift_streaming/kitex_gen_slim/echo" +) + +func RunSlimThriftServer(handler echo.EchoService, addr string, opts ...server.Option) server.Server { + // frugal + slim not available, return an empty server + return server.NewServer() +} diff --git a/thrift_streaming/thrift_test.go b/thrift_streaming/thrift_test.go new file mode 100644 index 0000000..48b649b --- /dev/null +++ b/thrift_streaming/thrift_test.go @@ -0,0 +1,955 @@ +// Copyright 2023 CloudWeGo 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 thrift_streaming + +import ( + "context" + "errors" + "fmt" + "reflect" + "strconv" + "strings" + "sync" + "testing" + "time" + + "github.com/bytedance/gopkg/cloud/metainfo" + "github.com/cloudwego/kitex/client" + "github.com/cloudwego/kitex/client/streamclient" + "github.com/cloudwego/kitex/pkg/endpoint" + "github.com/cloudwego/kitex/pkg/klog" + "github.com/cloudwego/kitex/pkg/logid" + "github.com/cloudwego/kitex/pkg/remote/trans/nphttp2/metadata" + "github.com/cloudwego/kitex/pkg/streaming" + "github.com/cloudwego/kitex/server" + "github.com/cloudwego/kitex/transport" + + "github.com/cloudwego/kitex-tests/pkg/test" + "github.com/cloudwego/kitex-tests/thrift_streaming/kitex_gen/echo" + "github.com/cloudwego/kitex-tests/thrift_streaming/kitex_gen/echo/echoservice" +) + +func TestKitexThriftBidirectional(t *testing.T) { + cli := echoservice.MustNewStreamClient( + "service", + streamclient.WithHostPorts(thriftAddr)) + t.Run("normal", func(t *testing.T) { + n := 3 + ctx := metainfo.WithValue(context.Background(), KeyCount, strconv.Itoa(n)) + stream, err := cli.EchoBidirectional(ctx) + test.Assert(t, err == nil, err) + wg := new(sync.WaitGroup) + wg.Add(2) + go func() { + defer wg.Done() + for i := 0; i < n; i++ { + req := &echo.EchoRequest{Message: "bidirectional-" + strconv.Itoa(i)} + err = stream.Send(req) + test.Assert(t, err == nil, err) + } + }() + go func() { + defer wg.Done() + for i := 0; i < n; i++ { + resp, err := stream.Recv() + test.Assert(t, err == nil, err) + test.Assert(t, resp.Message == "bidirectional-"+strconv.Itoa(i), resp.Message) + } + }() + wg.Wait() + }) +} + +func TestKitexThriftClient(t *testing.T) { + cli := echoservice.MustNewStreamClient( + "service", + streamclient.WithHostPorts(thriftAddr)) + t.Run("normal", func(t *testing.T) { + n := 3 + ctx := metainfo.WithValue(context.Background(), KeyCount, strconv.Itoa(n)) + stream, err := cli.EchoClient(ctx) + test.Assert(t, err == nil, err) + for i := 0; i < n; i++ { + req := &echo.EchoRequest{Message: "client"} + err = stream.Send(req) + test.Assert(t, err == nil, err) + } + resp, err := stream.CloseAndRecv() + test.Assert(t, err == nil, err) + test.Assert(t, resp.Message == strconv.Itoa(n), resp.Message) + }) +} + +func TestKitexThriftServer(t *testing.T) { + cli := echoservice.MustNewStreamClient( + "service", + streamclient.WithHostPorts(thriftAddr), + ) + + t.Run("normal", func(t *testing.T) { + n := 3 + req := &echo.EchoRequest{Message: "server"} + ctx := metainfo.WithValue(context.Background(), KeyCount, strconv.Itoa(n)) + stream, err := cli.EchoServer(ctx, req) + test.Assert(t, err == nil, err) + for i := 0; i < n; i++ { + resp, err := stream.Recv() + test.Assert(t, err == nil, err) + test.Assert(t, resp.Message == "server-"+strconv.Itoa(i), resp.Message) + } + }) +} + +func TestKitexThriftEchoUnary(t *testing.T) { + cli := echoservice.MustNewStreamClient( + "service", + streamclient.WithHostPorts(thriftAddr)) + + t.Run("normal", func(t *testing.T) { + req := &echo.EchoRequest{Message: "unary"} + resp, err := cli.EchoUnary(context.Background(), req) + test.Assert(t, err == nil, err) + test.Assert(t, resp.Message == "unary", resp.Message) + }) + + t.Run("exception", func(t *testing.T) { + ctx := metainfo.WithValue(context.Background(), "error", "unary") + _, err := cli.EchoUnary(ctx, &echo.EchoRequest{Message: "unary"}) + test.Assert(t, err != nil, err) + }) +} + +func TestKitexThriftEchoPingPong(t *testing.T) { + cli := echoservice.MustNewClient( + "service", + client.WithHostPorts(thriftAddr), + client.WithTransportProtocol(transport.TTHeaderFramed)) + + t.Run("normal", func(t *testing.T) { + req1 := &echo.EchoRequest{Message: "hello"} + req2 := &echo.EchoRequest{Message: "world"} + resp, err := cli.EchoPingPong(context.Background(), req1, req2) + test.Assert(t, err == nil, err) + test.Assert(t, resp.Message == "hello-world", resp.Message) + }) + + t.Run("exception", func(t *testing.T) { + ctx := metainfo.WithValue(context.Background(), KeyError, "pingpong") + _, err := cli.EchoPingPong(ctx, &echo.EchoRequest{Message: "hello"}, &echo.EchoRequest{Message: "world"}) + test.Assert(t, err != nil, err) + }) +} + +func TestKitexThriftEchoOneway(t *testing.T) { + cli := echoservice.MustNewClient( + "service", + client.WithHostPorts(thriftAddr), + client.WithTransportProtocol(transport.TTHeaderFramed)) + + req := &echo.EchoRequest{Message: "oneway"} + + t.Run("normal", func(t *testing.T) { + ctx := metainfo.WithValue(context.Background(), KeyMessage, req.Message) + err := cli.EchoOneway(ctx, req) + test.Assert(t, err == nil, err) + }) + t.Run("normal", func(t *testing.T) { + err := cli.EchoOneway(context.Background(), req) + test.Assert(t, err != nil, err) + }) +} + +func TestKitexThriftPing(t *testing.T) { + cli := echoservice.MustNewClient( + "service", + client.WithHostPorts(thriftAddr), + client.WithTransportProtocol(transport.TTHeaderFramed)) + t.Run("normal", func(t *testing.T) { + err := cli.Ping(context.Background()) + test.Assert(t, err == nil, err) + }) + t.Run("exception", func(t *testing.T) { + ctx := metainfo.WithValue(context.Background(), KeyError, "ping") + err := cli.Ping(ctx) + test.Assert(t, err != nil, err) + }) +} + +func TestKitexClientMiddleware(t *testing.T) { + cli := echoservice.MustNewClient( + "service", + client.WithHostPorts(thriftAddr), + client.WithTransportProtocol(transport.TTHeaderFramed), + client.WithMiddleware(func(endpoint endpoint.Endpoint) endpoint.Endpoint { + return func(ctx context.Context, args, result interface{}) (err error) { + req := args.(*echo.EchoServiceEchoPingPongArgs).Req1 + test.Assert(t, req.Message == "request", req.Message) + result.(*echo.EchoServiceEchoPingPongResult).Success = &echo.EchoResponse{Message: "response"} + return nil + } + }), + ) + req := &echo.EchoRequest{Message: "request"} + resp, err := cli.EchoPingPong(context.Background(), req, &echo.EchoRequest{Message: ""}) + test.Assert(t, err == nil, err) + test.Assert(t, resp.Message == "response", resp.Message) +} + +func TestKitexStreamClientMiddlewareUnary(t *testing.T) { + cli := echoservice.MustNewStreamClient( + "service", + streamclient.WithHostPorts(thriftAddr), + streamclient.WithMiddleware(func(endpoint endpoint.Endpoint) endpoint.Endpoint { + return func(ctx context.Context, args, result interface{}) (err error) { + req := args.(*echo.EchoServiceEchoUnaryArgs).Req1 + test.Assert(t, req.Message == "request", req.Message) + result.(*echo.EchoServiceEchoUnaryResult).Success = &echo.EchoResponse{Message: "response"} + return nil + } + }), + ) + req := &echo.EchoRequest{Message: "request"} + resp, err := cli.EchoUnary(context.Background(), req) + test.Assert(t, err == nil, err) + test.Assert(t, resp.Message == "response", resp.Message) +} + +func TestKitexStreamClientMiddlewareBidirectional(t *testing.T) { + cli := echoservice.MustNewStreamClient( + "service", + streamclient.WithHostPorts(thriftAddr), + streamclient.WithSendMiddleware(func(next endpoint.SendEndpoint) endpoint.SendEndpoint { + return func(stream streaming.Stream, req interface{}) (err error) { + test.Assert(t, req.(*echo.EchoRequest).Message == "request") + return next(stream, req) + } + }), + streamclient.WithRecvMiddleware(func(next endpoint.RecvEndpoint) endpoint.RecvEndpoint { + return func(stream streaming.Stream, resp interface{}) (err error) { + err = next(stream, resp) + rsp := resp.(*echo.EchoResponse) + test.Assert(t, rsp.Message == "request") + rsp.Message = "response-modified-in-mw" + return err + } + }), + ) + + ctx := metainfo.WithValue(context.Background(), KeyCount, "1") + stream, err := cli.EchoBidirectional(ctx) + test.Assert(t, err == nil, err) + + err = stream.Send(&echo.EchoRequest{Message: "request"}) + test.Assert(t, err == nil, err) + + resp, err := stream.Recv() + test.Assert(t, err == nil, err) + test.Assert(t, resp.Message == "response-modified-in-mw", resp.Message) +} + +func TestKitexStreamClientMiddlewareClient(t *testing.T) { + cli := echoservice.MustNewStreamClient( + "service", + streamclient.WithHostPorts(thriftAddr), + streamclient.WithSendMiddleware(func(next endpoint.SendEndpoint) endpoint.SendEndpoint { + return func(stream streaming.Stream, req interface{}) (err error) { + test.Assert(t, req.(*echo.EchoRequest).Message == "request") + return next(stream, req) + } + }), + streamclient.WithRecvMiddleware(func(next endpoint.RecvEndpoint) endpoint.RecvEndpoint { + return func(stream streaming.Stream, resp interface{}) (err error) { + err = next(stream, resp) + rsp := resp.(*echo.EchoResponse) + test.Assert(t, rsp.Message == "2") + rsp.Message = "response-modified-in-mw" + return err + } + }), + ) + ctx := metainfo.WithValue(context.Background(), KeyCount, "2") + stream, err := cli.EchoClient(ctx) + test.Assert(t, err == nil, err) + + err = stream.Send(&echo.EchoRequest{Message: "request"}) + test.Assert(t, err == nil, err) + + err = stream.Send(&echo.EchoRequest{Message: "request"}) + test.Assert(t, err == nil, err) + + resp, err := stream.CloseAndRecv() + test.Assert(t, err == nil, err) + test.Assert(t, resp.Message == "response-modified-in-mw", resp.Message) +} + +func TestKitexStreamClientMiddlewareServer(t *testing.T) { + recvCount := 0 + cli := echoservice.MustNewStreamClient( + "service", + streamclient.WithHostPorts(thriftAddr), + streamclient.WithSendMiddleware(func(next endpoint.SendEndpoint) endpoint.SendEndpoint { + return func(stream streaming.Stream, req interface{}) (err error) { + test.Assert(t, req.(*echo.EchoRequest).Message == "request") + return next(stream, req) + } + }), + streamclient.WithRecvMiddleware(func(next endpoint.RecvEndpoint) endpoint.RecvEndpoint { + return func(stream streaming.Stream, resp interface{}) (err error) { + err = next(stream, resp) + rsp := resp.(*echo.EchoResponse) + test.Assert(t, rsp.Message == "request-"+strconv.Itoa(recvCount)) + recvCount += 1 + rsp.Message = "response-modified-in-mw" + return err + } + }), + ) + ctx := metainfo.WithValue(context.Background(), KeyCount, "2") + stream, err := cli.EchoServer(ctx, &echo.EchoRequest{Message: "request"}) + test.Assert(t, err == nil, err) + + resp, err := stream.Recv() + test.Assert(t, err == nil, err) + test.Assert(t, resp.Message == "response-modified-in-mw", resp.Message) + + resp, err = stream.Recv() + test.Assert(t, err == nil, err) + test.Assert(t, resp.Message == "response-modified-in-mw", resp.Message) +} + +func TestKitexServerMiddleware(t *testing.T) { + addr := addrAllocator() + t.Run("pingpong", func(t *testing.T) { + svr := RunThriftServer(&EchoServiceImpl{}, addr, + server.WithMiddleware(func(e endpoint.Endpoint) endpoint.Endpoint { + return func(ctx context.Context, args, result interface{}) (err error) { + realArgs := args.(*echo.EchoServiceEchoPingPongArgs) + req1, req2 := realArgs.Req1, realArgs.Req2 + test.Assert(t, req1.Message == "ping") + test.Assert(t, req2.Message == "pong") + err = e(ctx, args, result) + resp := result.(*echo.EchoServiceEchoPingPongResult) + test.Assert(t, resp.Success.Message == "ping-pong") + resp.Success.Message = "response" + return nil + } + })) + defer svr.Stop() + + cli := echoservice.MustNewClient( + "service", + client.WithHostPorts(addr), + client.WithTransportProtocol(transport.TTHeaderFramed), + ) + req1, req2 := &echo.EchoRequest{Message: "ping"}, &echo.EchoRequest{Message: "pong"} + resp, err := cli.EchoPingPong(context.Background(), req1, req2) + test.Assert(t, err == nil, err) + test.Assert(t, resp.Message == "response", resp.Message) + }) + + t.Run("unary", func(t *testing.T) { + svr := RunThriftServer(&EchoServiceImpl{}, addr, + server.WithMiddleware(func(e endpoint.Endpoint) endpoint.Endpoint { + return func(ctx context.Context, args, result interface{}) (err error) { + realArgs, ok := args.(*echo.EchoServiceEchoUnaryArgs) + if !ok { + return fmt.Errorf("invalid args type: not %T", args) + } + if realArgs.Req1.Message != "unary" { + return fmt.Errorf("invalid realArgs.Req1.Message: %v", realArgs.Req1.Message) + } + if err = e(ctx, args, result); err != nil { + return err + } + resp, ok := result.(*echo.EchoServiceEchoUnaryResult) + if !ok { + return fmt.Errorf("invalid result type: not %T", result) + } + if resp.Success.Message != "unary" { + return fmt.Errorf("invalid resp.Success.Message: %v", resp.Success.Message) + } + resp.Success.Message = "response" + return nil + } + }), + server.WithRecvMiddleware(func(e endpoint.RecvEndpoint) endpoint.RecvEndpoint { + return func(stream streaming.Stream, resp interface{}) (err error) { + t.Errorf("recv middleware should not be called") + return errors.New("recv middleware should not be called") + } + }), + server.WithSendMiddleware(func(e endpoint.SendEndpoint) endpoint.SendEndpoint { + return func(stream streaming.Stream, req interface{}) (err error) { + t.Errorf("send middleware should not be called") + return errors.New("send middleware should not be called") + } + })) + defer svr.Stop() + + cli := echoservice.MustNewStreamClient("service", streamclient.WithHostPorts(addr)) + req := &echo.EchoRequest{Message: "unary"} + resp, err := cli.EchoUnary(context.Background(), req) + test.Assert(t, err == nil, err) + test.Assert(t, resp.Message == "response", resp.Message) + }) + + t.Run("bidirectional streaming", func(t *testing.T) { + svr := RunThriftServer(&EchoServiceImpl{}, addr, + server.WithMiddleware(func(e endpoint.Endpoint) endpoint.Endpoint { + return func(ctx context.Context, args, result interface{}) (err error) { + _, ok := args.(*streaming.Args) + test.Assert(t, ok) + return e(ctx, args, result) + } + }), + server.WithRecvMiddleware(func(e endpoint.RecvEndpoint) endpoint.RecvEndpoint { + return func(stream streaming.Stream, req interface{}) (err error) { + if err = e(stream, req); err != nil { + return + } + realReq, ok := req.(*echo.EchoRequest) + test.Assert(t, ok) + test.Assert(t, realReq.Message == "request") + realReq.Message = "bidirectional" + return + } + }), + server.WithSendMiddleware(func(e endpoint.SendEndpoint) endpoint.SendEndpoint { + return func(stream streaming.Stream, resp interface{}) (err error) { + realResp, ok := resp.(*echo.EchoResponse) + test.Assert(t, ok) + test.Assert(t, realResp.Message == "bidirectional") + realResp.Message = "response" + return e(stream, realResp) + } + })) + defer svr.Stop() + + cli := echoservice.MustNewStreamClient("service", streamclient.WithHostPorts(addr)) + ctx := metainfo.WithValue(context.Background(), KeyCount, "1") + stream, err := cli.EchoBidirectional(ctx) + test.Assert(t, err == nil, err) + + req := &echo.EchoRequest{Message: "request"} + err = stream.Send(req) + test.Assert(t, err == nil, err) + + resp, err := stream.Recv() + test.Assert(t, err == nil, err) + test.Assert(t, resp.Message == "response", resp.Message) + }) + + t.Run("server streaming", func(t *testing.T) { + count := 0 + svr := RunThriftServer(&EchoServiceImpl{}, addr, + server.WithMiddleware(func(e endpoint.Endpoint) endpoint.Endpoint { + return func(ctx context.Context, args, result interface{}) (err error) { + _, ok := args.(*streaming.Args) + test.Assert(t, ok) + return e(ctx, args, result) + } + }), + server.WithRecvMiddleware(func(e endpoint.RecvEndpoint) endpoint.RecvEndpoint { + return func(stream streaming.Stream, req interface{}) (err error) { + err = e(stream, req) + realReq, ok := req.(*echo.EchoRequest) + test.Assert(t, ok) + test.Assert(t, realReq.Message == "request") + realReq.Message = "server" + return + } + }), + server.WithSendMiddleware(func(e endpoint.SendEndpoint) endpoint.SendEndpoint { + return func(stream streaming.Stream, resp interface{}) (err error) { + realResp, ok := resp.(*echo.EchoResponse) + test.Assert(t, ok) + test.Assert(t, realResp.Message == "server-"+strconv.Itoa(count)) + realResp.Message = "response-" + strconv.Itoa(count) + count += 1 + return e(stream, realResp) + } + })) + defer svr.Stop() + + cli := echoservice.MustNewStreamClient("service", streamclient.WithHostPorts(addr)) + ctx := metainfo.WithValue(context.Background(), KeyCount, "2") + stream, err := cli.EchoServer(ctx, &echo.EchoRequest{Message: "request"}) + test.Assert(t, err == nil, err) + + resp, err := stream.Recv() + test.Assert(t, err == nil, err) + test.Assert(t, resp.Message == "response-0", resp.Message) + + resp, err = stream.Recv() + test.Assert(t, err == nil, err) + test.Assert(t, resp.Message == "response-1", resp.Message) + }) + + t.Run("client streaming", func(t *testing.T) { + count := 0 + svr := RunThriftServer(&EchoServiceImpl{}, addr, + server.WithMiddleware(func(e endpoint.Endpoint) endpoint.Endpoint { + return func(ctx context.Context, args, result interface{}) (err error) { + _, ok := args.(*streaming.Args) + test.Assert(t, ok) + return e(ctx, args, result) + } + }), + server.WithRecvMiddleware(func(e endpoint.RecvEndpoint) endpoint.RecvEndpoint { + return func(stream streaming.Stream, req interface{}) (err error) { + err = e(stream, req) + realReq, ok := req.(*echo.EchoRequest) + test.Assert(t, ok) + test.Assert(t, realReq.Message == "request-"+strconv.Itoa(count), realReq.Message) + count += 1 + realReq.Message += "_recv_middleware" + return + } + }), + server.WithSendMiddleware(func(e endpoint.SendEndpoint) endpoint.SendEndpoint { + return func(stream streaming.Stream, resp interface{}) (err error) { + realResp, ok := resp.(*echo.EchoResponse) + test.Assert(t, ok) + test.Assert(t, realResp.Message == "2") + realResp.Message += "_send_middleware" + return e(stream, realResp) + } + })) + defer svr.Stop() + + cli := echoservice.MustNewStreamClient("service", streamclient.WithHostPorts(addr)) + ctx := metainfo.WithValue(context.Background(), KeyCount, "2") + stream, err := cli.EchoClient(ctx) + test.Assert(t, err == nil, err) + + err = stream.Send(&echo.EchoRequest{Message: "request-0"}) + test.Assert(t, err == nil, err) + + err = stream.Send(&echo.EchoRequest{Message: "request-1"}) + test.Assert(t, err == nil, err) + + resp, err := stream.CloseAndRecv() + test.Assert(t, err == nil, err) + test.Assert(t, resp.Message == "2_send_middleware", resp.Message) + }) +} + +func TestTimeoutRecvSend(t *testing.T) { + t.Run("client send timeout", func(t *testing.T) { + cli := echoservice.MustNewStreamClient("service", streamclient.WithHostPorts(thriftAddr), + streamclient.WithSendMiddleware(func(next endpoint.SendEndpoint) endpoint.SendEndpoint { + return func(stream streaming.Stream, message interface{}) (err error) { + time.Sleep(time.Millisecond * 100) + return next(stream, message) + } + }), + ) + ctx, cancel := context.WithCancel(context.Background()) + defer cancel() + ctx = metainfo.WithValue(ctx, KeyCount, "1") + ctx = AddKeyValueHTTP2(ctx, KeyServerRecvTimeoutMS, "100") + stream, err := cli.EchoBidirectional(ctx) + test.Assert(t, err == nil, err) + + err = streaming.CallWithTimeout(time.Millisecond*50, cancel, func() (err error) { + err = stream.Send(&echo.EchoRequest{Message: "request"}) + return + }) + test.Assertf(t, err != nil, "err = %v", err) + test.Assertf(t, strings.Contains(err.Error(), "timeout in business code"), "err = %v", err) + }) + + t.Run("client recv timeout", func(t *testing.T) { + cli := echoservice.MustNewStreamClient("service", streamclient.WithHostPorts(thriftAddr), + streamclient.WithRecvMiddleware(func(next endpoint.RecvEndpoint) endpoint.RecvEndpoint { + return func(stream streaming.Stream, message interface{}) (err error) { + time.Sleep(time.Millisecond * 100) + return next(stream, message) + } + }), + ) + ctx, cancel := context.WithCancel(context.Background()) + defer cancel() + ctx = metainfo.WithValue(ctx, KeyCount, "1") + ctx = AddKeyValueHTTP2(ctx, KeyServerSendTimeoutMS, "100") + stream, err := cli.EchoBidirectional(ctx) + test.Assert(t, err == nil, err) + + err = stream.Send(&echo.EchoRequest{Message: "request"}) + test.Assertf(t, err == nil, "err = %v", err) + + var resp *echo.EchoResponse + err = streaming.CallWithTimeout(time.Millisecond*50, cancel, func() (err error) { + resp, err = stream.Recv() + return + }) + test.Assertf(t, err != nil, "err = %v", err) + test.Assertf(t, strings.Contains(err.Error(), "timeout in business code"), "err = %v", err) + test.Assertf(t, resp == nil, "resp = %v", resp) + }) + + t.Run("client recv timeout with MetaHandler", func(t *testing.T) { + addr := addrAllocator() + svr := RunThriftServer(&thriftServerTimeoutImpl{ + Handler: func(stream echo.EchoService_EchoBidirectionalServer) (err error) { + time.Sleep(time.Millisecond * 100) + return nil + }, + }, addr) + defer svr.Stop() + + cli := echoservice.MustNewStreamClient("service", streamclient.WithHostPorts(addr), + WithClientContextCancel(), + ) + stream, err := cli.EchoBidirectional(context.Background()) + test.Assert(t, err == nil, err) + err = CallWithCtx(stream.Context(), time.Millisecond*50, func() (err error) { + _, err = stream.Recv() + klog.Infof("client recv: err = %v", err) + test.Assert(t, err != nil, err) + return err + }) + test.Assert(t, err != nil, err) + test.Assert(t, strings.Contains(err.Error(), "timeout in business code"), err.Error()) + }) + + t.Run("server recv timeout with MetaHandler", func(t *testing.T) { + addr := addrAllocator() + svr := RunThriftServer( + &thriftServerTimeoutImpl{ + Handler: func(stream echo.EchoService_EchoBidirectionalServer) (err error) { + err = CallWithCtx(stream.Context(), time.Millisecond*50, func() (err error) { + _, err = stream.Recv() + klog.Infof("server recv: err = %v", err) + test.Assert(t, err != nil, err) + return + }) + klog.Infof("server recv: err = %v", err) + return err + }, + }, + addr, + WithServerContextCancel(), + ) + defer svr.Stop() + + cli := echoservice.MustNewStreamClient("service", streamclient.WithHostPorts(addr)) + stream, err := cli.EchoBidirectional(context.Background()) + test.Assert(t, err == nil, err) + _, err = stream.Recv() + test.Assertf(t, err != nil, "err = %v", err) + }) +} + +type thriftServerTimeoutImpl struct { + echo.EchoService + Handler func(stream echo.EchoService_EchoBidirectionalServer) (err error) +} + +func (h *thriftServerTimeoutImpl) EchoBidirectional(stream echo.EchoService_EchoBidirectionalServer) (err error) { + return h.Handler(stream) +} + +func TestThriftStreamingMetaData(t *testing.T) { + t.Run("metainfo", func(t *testing.T) { + metainfoKeys := map[string]bool{ + "HELLO": true, + "HELLO_WORLD": true, + // lower case keys will be ignored + "Foo": false, + "Foo_Bar": false, + "hello": false, + "hello_world": false, + } + + metadataKeys := []string{ + "hello", "WORLD", "foo_bar", "BAR_FOO", + "HELLO", // case-insensitive, will be merged into "hello" + } + + headers := metadata.MD{ + "hello": []string{"3", "4"}, + "foo_bar": []string{"5", "6"}, + "bar-foo": []string{"7", "8"}, + "x1": []string{"9"}, + "x_1": []string{"10"}, + "1_x": []string{"11"}, + // capital letters not allowed, will cause error at client side + } + trailers := metadata.MD{ + "xxx": []string{"9"}, + "yyy_zzz": []string{"10"}, + "zzz-yyy": []string{"11"}, + "x1": []string{"12"}, + "x_1": []string{"13"}, + "1_x": []string{"14"}, + } + + addr := addrAllocator() + + svr := RunThriftServer( + &thriftServerTimeoutImpl{ + Handler: func(stream echo.EchoService_EchoBidirectionalServer) (err error) { + values := metainfo.GetAllValues(stream.Context()) + klog.Infof("metainfo.GetAllValues: v = %v", values) + for key, shouldExists := range metainfoKeys { + value, exists := values[key] + test.Assertf(t, exists == shouldExists, "key = %v, shouldExists = %v, exists = %v", + key, shouldExists, exists) + if shouldExists { + test.Assertf(t, value == "1", "key = %v, v = %v, exists = %v", key, value, exists) + } + } + + values = metainfo.GetAllPersistentValues(stream.Context()) + klog.Infof("metainfo.GetAllPersistentValues: v = %v", values) + for key, shouldExists := range metainfoKeys { + value, exists := metainfo.GetPersistentValue(stream.Context(), key) + test.Assertf(t, exists == shouldExists, "key = %v, shouldExists = %v, exists = %v", + key, shouldExists, exists) + if shouldExists { + test.Assertf(t, value == "1", "v = %v, exists = %v", value, exists) + } + } + + // TODO: client unable to receive backward values + metainfo.SendBackwardValue(stream.Context(), "backward", "1") + metainfo.SendBackwardValue(stream.Context(), "BACKWARD", "1") + + md, ok := metadata.FromIncomingContext(stream.Context()) + klog.Infof("metadata: md = %v, ok = %v", md, ok) + for _, key := range metadataKeys { + value := md.Get(key) + if strings.ToLower(key) == "hello" { // case-insensitive, same keys merged + test.Assert(t, len(value) == 4, "value = %v", value) + test.Assert(t, reflect.DeepEqual(value, []string{"1", "2", "1", "2"}), value) + } else { + test.Assert(t, len(value) == 2, "value = %v", value) + test.Assert(t, reflect.DeepEqual(value, []string{"1", "2"}), value) + } + } + + err = stream.SendHeader(headers) + test.Assert(t, err == nil, err) + + err = stream.Send(&echo.EchoResponse{Message: "ok"}) + test.Assert(t, err == nil, err) + + stream.SetTrailer(trailers) + return nil + }, + }, + addr, + ) + defer svr.Stop() + cli := echoservice.MustNewStreamClient("service", streamclient.WithHostPorts(addr)) + + ctx := metainfo.WithBackwardValues(context.Background()) + + for k := range metainfoKeys { + ctx = metainfo.WithValue(ctx, k, "1") + ctx = metainfo.WithPersistentValue(ctx, k, "1") + } + + for _, k := range metadataKeys { + ctx = metadata.AppendToOutgoingContext(ctx, k, "1", k, "2") + } + + stream, err := cli.EchoBidirectional(ctx) + test.Assert(t, err == nil, err) + + err = stream.Send(&echo.EchoRequest{Message: "hello"}) + test.Assert(t, err == nil, err) + + headerReceived, err := stream.Header() + test.Assertf(t, err == nil, "err = %v", err) + klog.Infof("headerReceived: %v", headerReceived) + for k, expected := range headers { + got := headerReceived[k] + test.Assertf(t, reflect.DeepEqual(got, expected), "key = %v, got = %v, expected = %v", k, got, expected) + } + + trailerReceived := stream.Trailer() + klog.Infof("trailerReceived: %v", trailerReceived) + for k, expected := range trailers { + got := trailerReceived[k] + test.Assertf(t, reflect.DeepEqual(got, expected), "key = %v, got = %v, expected = %v", k, got, expected) + } + + // TODO: not implemented? + klog.Infof("metainfo.BackwardValues: %v", metainfo.RecvAllBackwardValues(stream.Context())) + }) + + t.Run("header-failure", func(t *testing.T) { + addr := addrAllocator() + svr := RunThriftServer( + &thriftServerTimeoutImpl{ + Handler: func(stream echo.EchoService_EchoBidirectionalServer) (err error) { + _, err = stream.Recv() + test.Assert(t, err == nil, err) + + err = stream.SendHeader(metadata.MD{ + "HELLO": []string{"1"}, // upper case keys cause error at client side + }) + test.Assert(t, err == nil, err) + + return stream.Send(&echo.EchoResponse{Message: "ok"}) + }, + }, + addr, + ) + defer svr.Stop() + + cli := echoservice.MustNewStreamClient("service", streamclient.WithHostPorts(addr)) + ctx := metainfo.WithBackwardValues(context.Background()) + stream, err := cli.EchoBidirectional(ctx) + test.Assert(t, err == nil, err) + + err = stream.Send(&echo.EchoRequest{Message: "hello"}) + test.Assert(t, err == nil, err) + + receivedHeaders, err := stream.Header() + klog.Infof("receivedHeaders: %v, err = %v", receivedHeaders, err) + test.Assert(t, err != nil, err) + test.Assert(t, strings.Contains(err.Error(), `invalid header field name "HELLO"`), err) + }) + + t.Run("trailer-failure", func(t *testing.T) { + addr := addrAllocator() + svr := RunThriftServer( + &thriftServerTimeoutImpl{ + Handler: func(stream echo.EchoService_EchoBidirectionalServer) (err error) { + _, err = stream.Recv() + test.Assert(t, err == nil, err) + + err = stream.Send(&echo.EchoResponse{Message: "ok"}) + test.Assert(t, err == nil, err) + + stream.SetTrailer(metadata.MD{ + "HELLO": []string{"1"}, // upper case keys cause error at client side + }) + return nil + }, + }, + addr, + ) + defer svr.Stop() + + cli := echoservice.MustNewStreamClient("service", streamclient.WithHostPorts(addr)) + ctx := metainfo.WithBackwardValues(context.Background()) + stream, err := cli.EchoBidirectional(ctx) + test.Assert(t, err == nil, err) + + err = stream.Send(&echo.EchoRequest{Message: "hello"}) + test.Assert(t, err == nil, err) + + receivedTrailers := stream.Trailer() + klog.Infof("receivedTrailers: %v, err = %v", receivedTrailers, err) + test.Assertf(t, len(receivedTrailers) == 0, "receivedTrailers = %v", receivedTrailers) + }) +} + +func TestThriftStreamLogID(t *testing.T) { + defer logid.SetLogIDGenerator(logid.DefaultLogIDGenerator) + + expectedLogID := "" + checkLogID := func(ctx context.Context) (got string, match bool) { + got = logid.GetStreamLogID(ctx) + return got, got == expectedLogID + } + + addr := addrAllocator() + svr := RunThriftServer( + &thriftServerTimeoutImpl{ + Handler: func(stream echo.EchoService_EchoBidirectionalServer) (err error) { + if got, ok := checkLogID(stream.Context()); !ok { + return fmt.Errorf("EchoBidirectional got logID = %v", got) + } + if _, err = stream.Recv(); err != nil { + return err + } + return stream.Send(&echo.EchoResponse{Message: "ok"}) + }, + }, + addr, + server.WithExitWaitTime(time.Millisecond*10), + server.WithMiddleware(func(next endpoint.Endpoint) endpoint.Endpoint { + return func(ctx context.Context, req, resp interface{}) (err error) { + if got, ok := checkLogID(ctx); !ok { + return fmt.Errorf("svr mw got logID = %v", got) + } + return next(ctx, req, resp) + } + }), + server.WithRecvMiddleware(func(next endpoint.RecvEndpoint) endpoint.RecvEndpoint { + return func(stream streaming.Stream, message interface{}) (err error) { + if got, ok := checkLogID(stream.Context()); !ok { + return fmt.Errorf("svr recv mw got logID = %v", got) + } + return next(stream, message) + } + }), + server.WithSendMiddleware(func(next endpoint.SendEndpoint) endpoint.SendEndpoint { + return func(stream streaming.Stream, message interface{}) (err error) { + if got, ok := checkLogID(stream.Context()); !ok { + return fmt.Errorf("svr send mw got logID = %v", got) + } + return next(stream, message) + } + }), + ) + defer svr.Stop() + + cli := echoservice.MustNewStreamClient("service", streamclient.WithHostPorts(addr), + streamclient.WithMiddleware(func(next endpoint.Endpoint) endpoint.Endpoint { + return func(ctx context.Context, req, resp interface{}) (err error) { + // streamLogID is injected in user defined middleware, and is available for inner middlewares + ctx = logid.NewCtxWithStreamLogID(ctx, logid.GenerateStreamLogID(ctx)) + expectedLogID = logid.GetStreamLogID(ctx) + klog.Infof("expectedLogID = %v", expectedLogID) + test.Assertf(t, expectedLogID != "", "expectedLogID = %v", expectedLogID) + return next(ctx, req, resp) + } + }), + streamclient.WithRecvMiddleware(func(next endpoint.RecvEndpoint) endpoint.RecvEndpoint { + return func(stream streaming.Stream, resp interface{}) (err error) { + if got, ok := checkLogID(stream.Context()); !ok { + return fmt.Errorf("cli recv mw got logID = %v", got) + } + return next(stream, resp) + } + }), + streamclient.WithSendMiddleware(func(next endpoint.SendEndpoint) endpoint.SendEndpoint { + return func(stream streaming.Stream, req interface{}) (err error) { + if got, ok := checkLogID(stream.Context()); !ok { + return fmt.Errorf("cli send mw got logID = %v", got) + } + return next(stream, req) + } + }), + ) + stream, err := cli.EchoBidirectional(context.Background()) + test.Assert(t, err == nil, err) + + err = stream.Send(&echo.EchoRequest{Message: "hello"}) + test.Assert(t, err == nil, err) + + _, err = stream.Recv() + test.Assert(t, err == nil, err) + + if got, ok := checkLogID(stream.Context()); !ok { + t.Errorf("stream ctx got logID = %v", got) + } +} diff --git a/thrift_streaming/timeout.go b/thrift_streaming/timeout.go new file mode 100644 index 0000000..3a39a22 --- /dev/null +++ b/thrift_streaming/timeout.go @@ -0,0 +1,106 @@ +// Copyright 2023 CloudWeGo 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 thrift_streaming + +import ( + "context" + "time" + + "github.com/cloudwego/kitex/client" + "github.com/cloudwego/kitex/client/streamclient" + "github.com/cloudwego/kitex/pkg/endpoint" + "github.com/cloudwego/kitex/pkg/remote" + "github.com/cloudwego/kitex/pkg/streaming" + "github.com/cloudwego/kitex/server" +) + +// TODO: move to cloudwego/kitex? or cloudwego/kitex-contrib? + +type ctxCancelKey struct{} + +type contextCancelMetaHandler struct{} + +func (c contextCancelMetaHandler) WriteMeta(ctx context.Context, msg remote.Message) (context.Context, error) { + return ctx, nil +} + +func (c contextCancelMetaHandler) ReadMeta(ctx context.Context, msg remote.Message) (context.Context, error) { + return ctx, nil +} + +// OnConnectStream is called by client and will return a new context with a cancel function +func (c contextCancelMetaHandler) OnConnectStream(ctx context.Context) (context.Context, error) { + newCtx, cancel := context.WithCancel(ctx) + ctx = context.WithValue(newCtx, ctxCancelKey{}, cancel) + return ctx, nil +} + +// OnReadStream is called by server and will return a new context with a cancel function +func (c contextCancelMetaHandler) OnReadStream(ctx context.Context) (context.Context, error) { + newCtx, cancel := context.WithCancel(ctx) + ctx = context.WithValue(newCtx, ctxCancelKey{}, cancel) + return ctx, nil +} + +type withCancelServerSuite struct{} + +func (c *withCancelServerSuite) Options() []server.Option { + return []server.Option{ + server.WithMetaHandler(&contextCancelMetaHandler{}), + server.WithMiddleware(func(endpoint endpoint.Endpoint) endpoint.Endpoint { + return func(ctx context.Context, req, resp interface{}) (err error) { + cancel, ok := ctx.Value(ctxCancelKey{}).(context.CancelFunc) + if ok { + defer cancel() + } + err = endpoint(ctx, req, resp) + return + } + }), + } +} + +type withCancelClientSuite struct{} + +func (c *withCancelClientSuite) Options() []client.Option { + return []client.Option{ + client.WithMetaHandler(&contextCancelMetaHandler{}), + client.WithMiddleware(func(endpoint endpoint.Endpoint) endpoint.Endpoint { + return func(ctx context.Context, req, resp interface{}) (err error) { + cancel, ok := ctx.Value(ctxCancelKey{}).(context.CancelFunc) + if ok { + defer cancel() + } + err = endpoint(ctx, req, resp) + return + } + }), + } +} + +// WithServerContextCancel sets the context cancel function for server, and invoke it with middleware. +func WithServerContextCancel() server.Option { + return server.WithSuite(&withCancelServerSuite{}) +} + +// WithClientContextCancel sets the context cancel function for client, and invoke it with middleware. +func WithClientContextCancel() streamclient.Option { + return streamclient.ConvertOptionFrom(client.WithSuite(&withCancelClientSuite{})) +} + +func CallWithCtx(ctx context.Context, timeout time.Duration, f func() (err error)) error { + cancel, _ := ctx.Value(ctxCancelKey{}).(context.CancelFunc) + return streaming.CallWithTimeout(timeout, cancel, f) +} diff --git a/thrift_streaming/util.go b/thrift_streaming/util.go new file mode 100644 index 0000000..96f9178 --- /dev/null +++ b/thrift_streaming/util.go @@ -0,0 +1,83 @@ +// Copyright 2023 CloudWeGo 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 thrift_streaming + +import ( + "context" + "errors" + "strconv" + + "github.com/bytedance/gopkg/cloud/metainfo" + "github.com/cloudwego/kitex/pkg/remote/trans/nphttp2/metadata" +) + +const ( + KeyError = "ERROR" + KeyMessage = "MESSAGE" + KeyCount = "COUNT" + KeyServerRecvTimeoutMS = "RECV_TIMEOUT_MS" + KeyServerSendTimeoutMS = "SEND_TIMEOUT_MS" +) + +func GetError(ctx context.Context) error { + if err, exists := metainfo.GetValue(ctx, KeyError); exists { + return errors.New(err) + } + return nil +} + +func GetErrorHTTP2(ctx context.Context) error { + err := GetKeyHTTP2(ctx, KeyError, "") + if err != "" { + return errors.New(err) + } + return nil +} + +func GetIntHTTP2(ctx context.Context, key string, defaultValue int) int { + if i, err := strconv.Atoi(GetKeyHTTP2(ctx, key, "")); err == nil { + return i + } + return defaultValue +} + +func GetKeyHTTP2(ctx context.Context, key, defaultValue string) string { + md, ok := metadata.FromIncomingContext(ctx) + if !ok { + return defaultValue + } + if v := md.Get(key); len(v) > 0 { + return v[0] + } + return defaultValue +} + +func AddKeyValueHTTP2(ctx context.Context, key, value string) context.Context { + return metadata.AppendToOutgoingContext(ctx, key, value) +} + +func GetValue(ctx context.Context, key, defaultValue string) string { + if v, exists := metainfo.GetValue(ctx, key); exists { + return v + } + return defaultValue +} + +func GetInt(ctx context.Context, key string, defaultValue int) int { + if i, err := strconv.Atoi(GetValue(ctx, key, "")); err == nil { + return i + } + return defaultValue +} diff --git a/thriftrpc/retrycall/retrycall_test.go b/thriftrpc/retrycall/retrycall_test.go index d58f507..5b2a7e6 100644 --- a/thriftrpc/retrycall/retrycall_test.go +++ b/thriftrpc/retrycall/retrycall_test.go @@ -215,8 +215,14 @@ func TestNoRetry(t *testing.T) { ctx, stReq := thriftrpc.CreateSTRequest(context.Background()) // add a mark to avoid retry ctx = metainfo.WithPersistentValue(ctx, retry.TransitKey, strconv.Itoa(1)) + ctx = metainfo.WithValue(ctx, skipCounterSleepKey, "1") // do not sleep by global variable + for i := 0; i < 250; i++ { - stResp, err := cli.TestSTReq(ctx, stReq) + reqCtx := ctx + if i%10 == 0 { + reqCtx = metainfo.WithValue(ctx, sleepTimeMsKey, "100") + } + stResp, err := cli.TestSTReq(reqCtx, stReq) if i%10 == 0 { test.Assert(t, err != nil) test.Assert(t, strings.Contains(err.Error(), retryChainStopStr), err)