diff --git a/encoding/thrift/envelope.go b/encoding/thrift/envelope.go index 5bf36273b7..4d4c26ae01 100644 --- a/encoding/thrift/envelope.go +++ b/encoding/thrift/envelope.go @@ -25,6 +25,7 @@ import ( "io" "go.uber.org/thriftrw/protocol" + "go.uber.org/thriftrw/protocol/stream" "go.uber.org/thriftrw/wire" ) @@ -55,3 +56,45 @@ func (ev disableEnvelopingProtocol) DecodeEnveloped(r io.ReaderAt) (wire.Envelop Value: value, }, err } + +type disableEnvelopingNoWireProtocol struct { + stream.Protocol + + Type wire.EnvelopeType +} + +func (evsp disableEnvelopingNoWireProtocol) Reader(r io.Reader) stream.Reader { + return disableEnvelopingReader{ + Reader: evsp.Protocol.Reader(r), + Type: evsp.Type, + } +} + +func (evsp disableEnvelopingNoWireProtocol) Writer(w io.Writer) stream.Writer { + return disableEnvelopingWriter{ + Writer: evsp.Protocol.Writer(w), + } +} + +type disableEnvelopingReader struct { + stream.Reader + + Type wire.EnvelopeType +} + +func (evr disableEnvelopingReader) ReadEnvelopeBegin() (stream.EnvelopeHeader, error) { + return stream.EnvelopeHeader{ + Name: "", + Type: evr.Type, + SeqID: 1, + }, nil +} + +func (evr disableEnvelopingReader) ReadEnvelopeEnd() error { return nil } + +type disableEnvelopingWriter struct { + stream.Writer +} + +func (evw disableEnvelopingWriter) WriteEnvelopeBegin(stream.EnvelopeHeader) error { return nil } +func (evw disableEnvelopingWriter) WriteEnvelopeEnd() error { return nil } diff --git a/encoding/thrift/inject.go b/encoding/thrift/inject.go index 5bc16fcb64..158d84b01b 100644 --- a/encoding/thrift/inject.go +++ b/encoding/thrift/inject.go @@ -45,6 +45,8 @@ func ClientBuilderOptions(_ transport.ClientConfig, f reflect.StructField) []Cli opts = append(opts, Multiplexed) case "enveloped": opts = append(opts, Enveloped) + case "nowire": + opts = append(opts, NoWire(true)) default: // Ignore unknown options } diff --git a/encoding/thrift/internal/observabilitytest/test/testserviceclient/client.go b/encoding/thrift/internal/observabilitytest/test/testserviceclient/client.go index 12dfd3c0c9..c3827840ae 100644 --- a/encoding/thrift/internal/observabilitytest/test/testserviceclient/client.go +++ b/encoding/thrift/internal/observabilitytest/test/testserviceclient/client.go @@ -51,6 +51,10 @@ func New(c transport.ClientConfig, opts ...thrift.ClientOption) Interface { Service: "TestService", ClientConfig: c, }, opts...), + nwc: thrift.NewNoWire(thrift.Config{ + Service: "TestService", + ClientConfig: c, + }, opts...), } } @@ -63,7 +67,8 @@ func init() { } type client struct { - c thrift.Client + c thrift.Client + nwc thrift.NoWireClient } func (c client) Call( @@ -72,17 +77,24 @@ func (c client) Call( opts ...yarpc.CallOption, ) (success string, err error) { + var result test.TestService_Call_Result args := test.TestService_Call_Helper.Args(_Key) - var body wire.Value - body, err = c.c.Call(ctx, args, opts...) - if err != nil { - return - } + if c.nwc != nil && c.nwc.Enabled() { + err = c.nwc.Call(ctx, args, &result, opts...) + if err != nil { + return + } + } else { + var body wire.Value + body, err = c.c.Call(ctx, args, opts...) + if err != nil { + return + } - var result test.TestService_Call_Result - if err = result.FromWire(body); err != nil { - return + if err = result.FromWire(body); err != nil { + return + } } success, err = test.TestService_Call_Helper.UnwrapResponse(&result) diff --git a/encoding/thrift/multiplex.go b/encoding/thrift/multiplex.go index 11ae0efa19..c343fd89da 100644 --- a/encoding/thrift/multiplex.go +++ b/encoding/thrift/multiplex.go @@ -25,6 +25,7 @@ import ( "strings" "go.uber.org/thriftrw/protocol" + "go.uber.org/thriftrw/protocol/stream" "go.uber.org/thriftrw/wire" ) @@ -48,3 +49,46 @@ func (m multiplexedOutboundProtocol) DecodeEnveloped(r io.ReaderAt) (wire.Envelo e.Name = strings.TrimPrefix(e.Name, m.Service+":") return e, err } + +type multiplexedOutboundNoWireProtocol struct { + stream.Protocol + + Service string +} + +func (m multiplexedOutboundNoWireProtocol) Writer(w io.Writer) stream.Writer { + return multiplexedWriter{ + Writer: m.Protocol.Writer(w), + Service: m.Service, + } +} + +func (m multiplexedOutboundNoWireProtocol) Reader(r io.Reader) stream.Reader { + return multiplexedReader{ + Reader: m.Protocol.Reader(r), + Service: m.Service, + } +} + +type multiplexedWriter struct { + stream.Writer + + Service string +} + +func (w multiplexedWriter) WriteEnvelopeBegin(eh stream.EnvelopeHeader) error { + eh.Name = w.Service + ":" + eh.Name + return w.Writer.WriteEnvelopeBegin(eh) +} + +type multiplexedReader struct { + stream.Reader + + Service string +} + +func (r multiplexedReader) ReadEnvelopeBegin() (stream.EnvelopeHeader, error) { + eh, err := r.Reader.ReadEnvelopeBegin() + eh.Name = strings.TrimPrefix(eh.Name, r.Service+":") + return eh, err +} diff --git a/encoding/thrift/outbound_nowire.go b/encoding/thrift/outbound_nowire.go new file mode 100644 index 0000000000..8c54614960 --- /dev/null +++ b/encoding/thrift/outbound_nowire.go @@ -0,0 +1,248 @@ +// Copyright (c) 2021 Uber Technologies, Inc. +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +package thrift + +import ( + "bytes" + "context" + + "go.uber.org/thriftrw/protocol" + "go.uber.org/thriftrw/protocol/stream" + "go.uber.org/thriftrw/wire" + "go.uber.org/yarpc" + encodingapi "go.uber.org/yarpc/api/encoding" + "go.uber.org/yarpc/api/transport" + "go.uber.org/yarpc/encoding/thrift/internal" + "go.uber.org/yarpc/pkg/encoding" + "go.uber.org/yarpc/pkg/errors" + "go.uber.org/yarpc/pkg/procedure" +) + +// NoWireClient is a generic Thrift client for encoding/decoding using +// ThriftRW's "streaming" mechanisms. +// It speaks in raw Thrift payloads. +// +// Users should use the client generated by the code generator rather than +// using this directly. +type NoWireClient interface { + // Call the given Thrift method. + Call(ctx context.Context, reqBody stream.Enveloper, resBody stream.BodyReader, opts ...yarpc.CallOption) error + CallOneway(ctx context.Context, reqBody stream.Enveloper, opts ...yarpc.CallOption) (transport.Ack, error) + + // Enabled returns whether or not this client is enabled through a + // ClientOption. + Enabled() bool +} + +// NewNoWire creates a new Thrift client. +func NewNoWire(c Config, opts ...ClientOption) NoWireClient { + // Code generated for Thrift client instantiation will probably be something + // like this: + // + // func New(cc transport.ClientConfig, opts ...ClientOption) *MyServiceClient { + // c := thrift.NewNoWire(thrift.Config{ + // Service: "MyService", + // ClientConfig: cc, + // Protocol: binary.Default, + // }, opts...) + // return &MyServiceClient{client: c} + // } + // + // So Config is really the internal config as far as consumers of the + // generated client are concerned. + + var cc clientConfig + for _, opt := range opts { + opt.applyClientOption(&cc) + } + + p := protocol.BinaryStreamer + if cc.Protocol != nil { + if val, ok := cc.Protocol.(stream.Protocol); ok { + p = val + } + } + + svc := c.Service + if cc.ServiceName != "" { + svc = cc.ServiceName + } + + if cc.Multiplexed { + p = multiplexedOutboundNoWireProtocol{ + Protocol: p, + Service: svc, + } + } + + return noWireThriftClient{ + p: p, + cc: c.ClientConfig, + thriftService: svc, + Enveloping: cc.Enveloping, + NoWire: cc.NoWire, + } +} + +type noWireThriftClient struct { + cc transport.ClientConfig + p stream.Protocol + + // name of the Thrift service + thriftService string + Enveloping bool + NoWire bool +} + +func (c noWireThriftClient) Call(ctx context.Context, reqBody stream.Enveloper, resBody stream.BodyReader, opts ...yarpc.CallOption) error { + // Code generated for Thrift client calls will probably be something like + // this: + // + // func (c *MyServiceClient) someMethod(ctx context.Context, arg1 Arg1Type, arg2 arg2Type, opts ...yarpc.CallOption) (returnValue, error) { + // var result myservice.SomeMethodResult + // args := myservice.SomeMethodHelper.Args(arg1, arg2) + // err := c.client.Call(ctx, args, result, opts...) + // + // success, err := myservice.SomeMethodHelper.UnwrapResponse(&result) + // return success, err + // } + + out := c.cc.GetUnaryOutbound() + + treq, proto, err := c.writeTransportRequest(reqBody) + if err != nil { + return err + } + + call := encodingapi.NewOutboundCall(encoding.FromOptions(opts)...) + ctx, err = call.WriteToRequest(ctx, treq) + if err != nil { + return err + } + + tres, err := out.Call(ctx, treq) + if err != nil { + return err + } + defer tres.Body.Close() + + if _, err = call.ReadFromResponse(ctx, tres); err != nil { + return err + } + + sr := proto.Reader(tres.Body) + defer sr.Close() + + env, err := sr.ReadEnvelopeBegin() + if err != nil { + return errors.ResponseBodyDecodeError(treq, err) + } + + switch env.Type { + case wire.Reply: + if err := resBody.Decode(sr); err != nil { + return err + } + return sr.ReadEnvelopeEnd() + case wire.Exception: + var exc internal.TApplicationException + if err = exc.Decode(sr); err != nil { + return errors.ResponseBodyDecodeError(treq, err) + } + return thriftException{ + Service: treq.Service, + Procedure: treq.Procedure, + Reason: &exc, + } + default: + return errors.ResponseBodyDecodeError( + treq, errUnexpectedEnvelopeType(env.Type)) + } +} + +func (c noWireThriftClient) CallOneway(ctx context.Context, reqBody stream.Enveloper, opts ...yarpc.CallOption) (transport.Ack, error) { + out := c.cc.GetOnewayOutbound() + + treq, _, err := c.writeTransportRequest(reqBody) + if err != nil { + return nil, err + } + + call := encodingapi.NewOutboundCall(encoding.FromOptions(opts)...) + ctx, err = call.WriteToRequest(ctx, treq) + if err != nil { + return nil, err + } + + return out.CallOneway(ctx, treq) +} + +func (c noWireThriftClient) Enabled() bool { + return c.NoWire +} + +func (c noWireThriftClient) writeTransportRequest(reqBody stream.Enveloper) (*transport.Request, stream.Protocol, error) { + proto := c.p + if !c.Enveloping { + proto = disableEnvelopingNoWireProtocol{ + Protocol: proto, + Type: wire.Reply, // we only decode replies with this instance + } + } + + treq := transport.Request{ + Caller: c.cc.Caller(), + Service: c.cc.Service(), + Encoding: Encoding, + Procedure: procedure.ToName(c.thriftService, reqBody.MethodName()), + } + + envType := reqBody.EnvelopeType() + if envType != wire.Call && envType != wire.OneWay { + return nil, nil, errors.RequestBodyEncodeError( + &treq, errUnexpectedEnvelopeType(envType), + ) + } + + var buffer bytes.Buffer + sw := proto.Writer(&buffer) + defer sw.Close() + + if err := sw.WriteEnvelopeBegin(stream.EnvelopeHeader{ + Name: reqBody.MethodName(), + Type: envType, + SeqID: 1, // don't care + }); err != nil { + return nil, nil, errors.RequestBodyEncodeError(&treq, err) + } + + if err := reqBody.Encode(sw); err != nil { + return nil, nil, errors.RequestBodyEncodeError(&treq, err) + } + + if err := sw.WriteEnvelopeEnd(); err != nil { + return nil, nil, errors.RequestBodyEncodeError(&treq, err) + } + + treq.Body = &buffer + treq.BodySize = buffer.Len() + return &treq, proto, nil +} diff --git a/encoding/thrift/stream_outbound.go b/encoding/thrift/stream_outbound.go deleted file mode 100644 index 023e8313f0..0000000000 --- a/encoding/thrift/stream_outbound.go +++ /dev/null @@ -1,231 +0,0 @@ -package thrift - -import ( - "bytes" - "context" - "io" - - envelope "go.uber.org/thriftrw/envelope/stream" - "go.uber.org/thriftrw/protocol/binary" - "go.uber.org/thriftrw/protocol/stream" - "go.uber.org/thriftrw/wire" - "go.uber.org/yarpc" - encodingapi "go.uber.org/yarpc/api/encoding" - "go.uber.org/yarpc/api/transport" - "go.uber.org/yarpc/encoding/thrift/internal" - "go.uber.org/yarpc/pkg/encoding" - "go.uber.org/yarpc/pkg/errors" - "go.uber.org/yarpc/pkg/procedure" -) - -// StreamClient is a generic Thrift client for stream encoding/decoding. -// It speaks in raw Thrift payloads. -// -// Users should use the client generated by the code generator rather than -// using this directly. -type StreamClient interface { - // Call the given Thrift method. - Call(ctx context.Context, reqBody envelope.Enveloper, opts ...yarpc.CallOption) (stream.Reader, error) - CallOneway(ctx context.Context, reqBody envelope.Enveloper, opts ...yarpc.CallOption) (transport.Ack, error) -} - -// NewStreamClient creates a new Thrift client. -func NewStreamClient(c Config, opts ...ClientOption) StreamClient { - // Code generated for Thrift client instantiation will probably be something - // like this: - // - // func New(cc transport.ClientConfig, opts ...ClientOption) *MyServiceClient { - // c := thrift.NewStreamClient(thrift.Config{ - // Service: "MyService", - // ClientConfig: cc, - // Protocol: binary.Default, - // }, opts...) - // return &MyServiceClient{client: c} - // } - // - // So Config is really the internal config as far as consumers of the - // generated client are concerned. - - var cc clientConfig - for _, opt := range opts { - opt.applyClientOption(&cc) - } - - p := stream.Protocol(binary.Default) - if cc.Protocol != nil { - val, ok := cc.Protocol.(stream.Protocol) - if !ok { - panic("yarpc.NewStreamClient expects a Protocol of type stream.Protocol") - } - p = val - } - - svc := c.Service - if cc.ServiceName != "" { - svc = cc.ServiceName - } - - return streamThriftClient{ - p: p, - cc: c.ClientConfig, - thriftService: svc, - Enveloping: cc.Enveloping, - Multiplexed: cc.Multiplexed, - } -} - -type streamThriftClient struct { - cc transport.ClientConfig - p stream.Protocol - - // name of the Thrift service - thriftService string - Enveloping bool - Multiplexed bool -} - -func (c streamThriftClient) Call(ctx context.Context, reqBody envelope.Enveloper, opts ...yarpc.CallOption) (stream.Reader, error) { - // Code generated for Thrift client calls will probably be something like - // this: - // - // func (c *MyServiceClient) someMethod(ctx context.Context, arg1 Arg1Type, arg2 arg2Type, opts ...yarpc.CallOption) (returnValue, error) { - // args := myservice.SomeMethodHelper.Args(arg1, arg2) - // resBody, err := c.client.Call(ctx, args, opts...) - // var result myservice.SomeMethodResult - // if err = result.Decode(resBody); err != nil { - // return nil, err - // } - // success, err := myservice.SomeMethodHelper.UnwrapResponse(&result) - // return success, err - // } - - out := c.cc.GetUnaryOutbound() - - treq, proto, err := c.buildTransportRequest(reqBody) - if err != nil { - return nil, err - } - - call := encodingapi.NewOutboundCall(encoding.FromOptions(opts)...) - ctx, err = call.WriteToRequest(ctx, treq) - if err != nil { - return nil, err - } - - tres, err := out.Call(ctx, treq) - if err != nil { - return nil, err - } - defer tres.Body.Close() - - if _, err = call.ReadFromResponse(ctx, tres); err != nil { - return nil, err - } - - var r io.Reader - // optimization for avoiding additional buffer copy as tchannel outbound - // already decodes the body into io.Reader compatible type - // thrift deserializer reads sets, maps, and lists lazily which makes - // buffer pool unusable as response handling is out of scope of this method - if body, ok := tres.Body.(io.Reader); ok { - r = body - } else { - buf := bytes.NewBuffer(make([]byte, 0, _defaultBufferSize)) - if _, err = buf.ReadFrom(tres.Body); err != nil { - return nil, err - } - r = bytes.NewReader(buf.Bytes()) - } - - sr := proto.Reader(r) - - env, err := sr.ReadEnvelopeBegin() - if err != nil { - return nil, errors.ResponseBodyDecodeError(treq, err) - } - - switch env.Type { - case wire.Reply: - return sr, nil - case wire.Exception: - defer sr.Close() - var exc internal.TApplicationException - if err = exc.Decode(sr); err != nil { - return nil, errors.ResponseBodyDecodeError(treq, err) - } - return nil, thriftException{ - Service: treq.Service, - Procedure: treq.Procedure, - Reason: &exc, - } - default: - sr.Close() - return nil, errors.ResponseBodyDecodeError( - treq, errUnexpectedEnvelopeType(env.Type)) - } - -} - -func (c streamThriftClient) CallOneway(ctx context.Context, reqBody envelope.Enveloper, opts ...yarpc.CallOption) (transport.Ack, error) { - out := c.cc.GetOnewayOutbound() - - treq, _, err := c.buildTransportRequest(reqBody) - if err != nil { - return nil, err - } - - call := encodingapi.NewOutboundCall(encoding.FromOptions(opts)...) - ctx, err = call.WriteToRequest(ctx, treq) - if err != nil { - return nil, err - } - - return out.CallOneway(ctx, treq) -} - -func (c streamThriftClient) buildTransportRequest(reqBody envelope.Enveloper) (*transport.Request, stream.Protocol, error) { - proto := c.p - treq := transport.Request{ - Caller: c.cc.Caller(), - Service: c.cc.Service(), - Encoding: Encoding, - Procedure: procedure.ToName(c.thriftService, reqBody.MethodName()), - } - - envType := reqBody.EnvelopeType() - if envType != wire.Call && envType != wire.OneWay { - return nil, nil, errors.RequestBodyEncodeError( - &treq, errUnexpectedEnvelopeType(envType), - ) - } - - var buffer bytes.Buffer - sw := proto.Writer(&buffer) - defer sw.Close() - - if c.Enveloping { - if err := sw.WriteEnvelopeBegin(stream.EnvelopeHeader{ - Name: reqBody.MethodName(), - Type: reqBody.EnvelopeType(), - SeqID: 1, // don't care - }); err != nil { - return nil, nil, errors.RequestBodyEncodeError(&treq, err) - } - - if err := reqBody.Encode(sw); err != nil { - return nil, nil, errors.RequestBodyEncodeError(&treq, err) - } - - if err := sw.WriteEnvelopeEnd(); err != nil { - return nil, nil, errors.RequestBodyEncodeError(&treq, err) - } - } else { - if err := reqBody.Encode(sw); err != nil { - return nil, nil, errors.RequestBodyEncodeError(&treq, err) - } - } - - treq.Body = &buffer - treq.BodySize = buffer.Len() - return &treq, proto, nil -} diff --git a/encoding/thrift/thriftrw-plugin-yarpc/client.go b/encoding/thrift/thriftrw-plugin-yarpc/client.go index c717ee74a4..31552ceab1 100644 --- a/encoding/thrift/thriftrw-plugin-yarpc/client.go +++ b/encoding/thrift/thriftrw-plugin-yarpc/client.go @@ -70,6 +70,10 @@ func New(c <$transport>.ClientConfig, opts ...<$thrift>.ClientOption) Interface Service: "<.Name>", ClientConfig: c, }, opts...), + nwc: <$thrift>.NewNoWire(<$thrift>.Config{ + Service: "<.Name>", + ClientConfig: c, + }, opts...), Interface: .New( c, @@ -95,6 +99,7 @@ type client struct { .Interface c <$thrift>.Client + nwc <$thrift>.NoWireClient } <$service := .> @@ -114,18 +119,25 @@ func (c client) <.Name>( } ) (success , err error) { <$wire := import "go.uber.org/thriftrw/wire"> + var result <$prefix>Result args := <$prefix>Helper.Args(_<.Name>, ) ctx = .WithoutHeaders(ctx) - var body <$wire>.Value - body, err = c.c.Call(ctx, args, opts...) - if err != nil { - return - } - - var result <$prefix>Result - if err = result.FromWire(body); err != nil { - return + if c.nwc != nil && c.nwc.Enabled() { + err = c.nwc.Call(ctx, args, &result, opts...) + if err != nil { + return + } + } else { + var body <$wire>.Value + body, err = c.c.Call(ctx, args, opts...) + if err != nil { + return + } + + if err = result.FromWire(body); err != nil { + return + } } success, err = <$prefix>Helper.UnwrapResponse(&result) diff --git a/encoding/thrift/thriftrw-plugin-yarpc/internal/tests/atomic/readonlystoreclient/client.go b/encoding/thrift/thriftrw-plugin-yarpc/internal/tests/atomic/readonlystoreclient/client.go index 81cd4ab24b..427d3c8663 100644 --- a/encoding/thrift/thriftrw-plugin-yarpc/internal/tests/atomic/readonlystoreclient/client.go +++ b/encoding/thrift/thriftrw-plugin-yarpc/internal/tests/atomic/readonlystoreclient/client.go @@ -34,6 +34,10 @@ func New(c transport.ClientConfig, opts ...thrift.ClientOption) Interface { Service: "ReadOnlyStore", ClientConfig: c, }, opts...), + nwc: thrift.NewNoWire(thrift.Config{ + Service: "ReadOnlyStore", + ClientConfig: c, + }, opts...), Interface: baseserviceclient.New( c, @@ -56,7 +60,8 @@ func init() { type client struct { baseserviceclient.Interface - c thrift.Client + c thrift.Client + nwc thrift.NoWireClient } func (c client) Integer( @@ -65,17 +70,24 @@ func (c client) Integer( opts ...yarpc.CallOption, ) (success int64, err error) { + var result atomic.ReadOnlyStore_Integer_Result args := atomic.ReadOnlyStore_Integer_Helper.Args(_Key) - var body wire.Value - body, err = c.c.Call(ctx, args, opts...) - if err != nil { - return - } + if c.nwc != nil && c.nwc.Enabled() { + err = c.nwc.Call(ctx, args, &result, opts...) + if err != nil { + return + } + } else { + var body wire.Value + body, err = c.c.Call(ctx, args, opts...) + if err != nil { + return + } - var result atomic.ReadOnlyStore_Integer_Result - if err = result.FromWire(body); err != nil { - return + if err = result.FromWire(body); err != nil { + return + } } success, err = atomic.ReadOnlyStore_Integer_Helper.UnwrapResponse(&result) diff --git a/encoding/thrift/thriftrw-plugin-yarpc/internal/tests/atomic/storeclient/client.go b/encoding/thrift/thriftrw-plugin-yarpc/internal/tests/atomic/storeclient/client.go index 0c2244532e..998fc5b648 100644 --- a/encoding/thrift/thriftrw-plugin-yarpc/internal/tests/atomic/storeclient/client.go +++ b/encoding/thrift/thriftrw-plugin-yarpc/internal/tests/atomic/storeclient/client.go @@ -47,6 +47,10 @@ func New(c transport.ClientConfig, opts ...thrift.ClientOption) Interface { Service: "Store", ClientConfig: c, }, opts...), + nwc: thrift.NewNoWire(thrift.Config{ + Service: "Store", + ClientConfig: c, + }, opts...), Interface: readonlystoreclient.New( c, @@ -69,7 +73,8 @@ func init() { type client struct { readonlystoreclient.Interface - c thrift.Client + c thrift.Client + nwc thrift.NoWireClient } func (c client) CompareAndSwap( @@ -78,17 +83,24 @@ func (c client) CompareAndSwap( opts ...yarpc.CallOption, ) (err error) { + var result atomic.Store_CompareAndSwap_Result args := atomic.Store_CompareAndSwap_Helper.Args(_Request) - var body wire.Value - body, err = c.c.Call(ctx, args, opts...) - if err != nil { - return - } - - var result atomic.Store_CompareAndSwap_Result - if err = result.FromWire(body); err != nil { - return + if c.nwc != nil && c.nwc.Enabled() { + err = c.nwc.Call(ctx, args, &result, opts...) + if err != nil { + return + } + } else { + var body wire.Value + body, err = c.c.Call(ctx, args, opts...) + if err != nil { + return + } + + if err = result.FromWire(body); err != nil { + return + } } err = atomic.Store_CompareAndSwap_Helper.UnwrapResponse(&result) @@ -111,17 +123,24 @@ func (c client) Increment( opts ...yarpc.CallOption, ) (err error) { + var result atomic.Store_Increment_Result args := atomic.Store_Increment_Helper.Args(_Key, _Value) - var body wire.Value - body, err = c.c.Call(ctx, args, opts...) - if err != nil { - return - } - - var result atomic.Store_Increment_Result - if err = result.FromWire(body); err != nil { - return + if c.nwc != nil && c.nwc.Enabled() { + err = c.nwc.Call(ctx, args, &result, opts...) + if err != nil { + return + } + } else { + var body wire.Value + body, err = c.c.Call(ctx, args, opts...) + if err != nil { + return + } + + if err = result.FromWire(body); err != nil { + return + } } err = atomic.Store_Increment_Helper.UnwrapResponse(&result) diff --git a/encoding/thrift/thriftrw-plugin-yarpc/internal/tests/common/baseserviceclient/client.go b/encoding/thrift/thriftrw-plugin-yarpc/internal/tests/common/baseserviceclient/client.go index 2555339532..5a32d65047 100644 --- a/encoding/thrift/thriftrw-plugin-yarpc/internal/tests/common/baseserviceclient/client.go +++ b/encoding/thrift/thriftrw-plugin-yarpc/internal/tests/common/baseserviceclient/client.go @@ -30,6 +30,10 @@ func New(c transport.ClientConfig, opts ...thrift.ClientOption) Interface { Service: "BaseService", ClientConfig: c, }, opts...), + nwc: thrift.NewNoWire(thrift.Config{ + Service: "BaseService", + ClientConfig: c, + }, opts...), } } @@ -42,7 +46,8 @@ func init() { } type client struct { - c thrift.Client + c thrift.Client + nwc thrift.NoWireClient } func (c client) Healthy( @@ -50,17 +55,24 @@ func (c client) Healthy( opts ...yarpc.CallOption, ) (success bool, err error) { + var result common.BaseService_Healthy_Result args := common.BaseService_Healthy_Helper.Args() - var body wire.Value - body, err = c.c.Call(ctx, args, opts...) - if err != nil { - return - } + if c.nwc != nil && c.nwc.Enabled() { + err = c.nwc.Call(ctx, args, &result, opts...) + if err != nil { + return + } + } else { + var body wire.Value + body, err = c.c.Call(ctx, args, opts...) + if err != nil { + return + } - var result common.BaseService_Healthy_Result - if err = result.FromWire(body); err != nil { - return + if err = result.FromWire(body); err != nil { + return + } } success, err = common.BaseService_Healthy_Helper.UnwrapResponse(&result) diff --git a/encoding/thrift/thriftrw-plugin-yarpc/internal/tests/common/emptyserviceclient/client.go b/encoding/thrift/thriftrw-plugin-yarpc/internal/tests/common/emptyserviceclient/client.go index b073ae466e..26efc11dd0 100644 --- a/encoding/thrift/thriftrw-plugin-yarpc/internal/tests/common/emptyserviceclient/client.go +++ b/encoding/thrift/thriftrw-plugin-yarpc/internal/tests/common/emptyserviceclient/client.go @@ -23,6 +23,10 @@ func New(c transport.ClientConfig, opts ...thrift.ClientOption) Interface { Service: "EmptyService", ClientConfig: c, }, opts...), + nwc: thrift.NewNoWire(thrift.Config{ + Service: "EmptyService", + ClientConfig: c, + }, opts...), } } @@ -35,5 +39,6 @@ func init() { } type client struct { - c thrift.Client + c thrift.Client + nwc thrift.NoWireClient } diff --git a/encoding/thrift/thriftrw-plugin-yarpc/internal/tests/common/extendemptyclient/client.go b/encoding/thrift/thriftrw-plugin-yarpc/internal/tests/common/extendemptyclient/client.go index 580b1d72a3..1f1b2c9e9e 100644 --- a/encoding/thrift/thriftrw-plugin-yarpc/internal/tests/common/extendemptyclient/client.go +++ b/encoding/thrift/thriftrw-plugin-yarpc/internal/tests/common/extendemptyclient/client.go @@ -33,6 +33,10 @@ func New(c transport.ClientConfig, opts ...thrift.ClientOption) Interface { Service: "ExtendEmpty", ClientConfig: c, }, opts...), + nwc: thrift.NewNoWire(thrift.Config{ + Service: "ExtendEmpty", + ClientConfig: c, + }, opts...), Interface: emptyserviceclient.New( c, @@ -55,7 +59,8 @@ func init() { type client struct { emptyserviceclient.Interface - c thrift.Client + c thrift.Client + nwc thrift.NoWireClient } func (c client) Hello( @@ -63,17 +68,24 @@ func (c client) Hello( opts ...yarpc.CallOption, ) (err error) { + var result common.ExtendEmpty_Hello_Result args := common.ExtendEmpty_Hello_Helper.Args() - var body wire.Value - body, err = c.c.Call(ctx, args, opts...) - if err != nil { - return - } + if c.nwc != nil && c.nwc.Enabled() { + err = c.nwc.Call(ctx, args, &result, opts...) + if err != nil { + return + } + } else { + var body wire.Value + body, err = c.c.Call(ctx, args, opts...) + if err != nil { + return + } - var result common.ExtendEmpty_Hello_Result - if err = result.FromWire(body); err != nil { - return + if err = result.FromWire(body); err != nil { + return + } } err = common.ExtendEmpty_Hello_Helper.UnwrapResponse(&result) diff --git a/encoding/thrift/thriftrw-plugin-yarpc/internal/tests/common/extendonlyclient/client.go b/encoding/thrift/thriftrw-plugin-yarpc/internal/tests/common/extendonlyclient/client.go index ace17c45ba..463bea0c4b 100644 --- a/encoding/thrift/thriftrw-plugin-yarpc/internal/tests/common/extendonlyclient/client.go +++ b/encoding/thrift/thriftrw-plugin-yarpc/internal/tests/common/extendonlyclient/client.go @@ -25,6 +25,10 @@ func New(c transport.ClientConfig, opts ...thrift.ClientOption) Interface { Service: "ExtendOnly", ClientConfig: c, }, opts...), + nwc: thrift.NewNoWire(thrift.Config{ + Service: "ExtendOnly", + ClientConfig: c, + }, opts...), Interface: baseserviceclient.New( c, @@ -47,5 +51,6 @@ func init() { type client struct { baseserviceclient.Interface - c thrift.Client + c thrift.Client + nwc thrift.NoWireClient } diff --git a/encoding/thrift/thriftrw-plugin-yarpc/internal/tests/extends/barclient/client.go b/encoding/thrift/thriftrw-plugin-yarpc/internal/tests/extends/barclient/client.go index 46bb775f2b..f7c8ac5ba8 100644 --- a/encoding/thrift/thriftrw-plugin-yarpc/internal/tests/extends/barclient/client.go +++ b/encoding/thrift/thriftrw-plugin-yarpc/internal/tests/extends/barclient/client.go @@ -25,6 +25,10 @@ func New(c transport.ClientConfig, opts ...thrift.ClientOption) Interface { Service: "Bar", ClientConfig: c, }, opts...), + nwc: thrift.NewNoWire(thrift.Config{ + Service: "Bar", + ClientConfig: c, + }, opts...), Interface: fooclient.New( c, @@ -47,5 +51,6 @@ func init() { type client struct { fooclient.Interface - c thrift.Client + c thrift.Client + nwc thrift.NoWireClient } diff --git a/encoding/thrift/thriftrw-plugin-yarpc/internal/tests/extends/fooclient/client.go b/encoding/thrift/thriftrw-plugin-yarpc/internal/tests/extends/fooclient/client.go index bb1f674fcf..5acfa1ec26 100644 --- a/encoding/thrift/thriftrw-plugin-yarpc/internal/tests/extends/fooclient/client.go +++ b/encoding/thrift/thriftrw-plugin-yarpc/internal/tests/extends/fooclient/client.go @@ -25,6 +25,10 @@ func New(c transport.ClientConfig, opts ...thrift.ClientOption) Interface { Service: "Foo", ClientConfig: c, }, opts...), + nwc: thrift.NewNoWire(thrift.Config{ + Service: "Foo", + ClientConfig: c, + }, opts...), Interface: nameclient.New( c, @@ -47,5 +51,6 @@ func init() { type client struct { nameclient.Interface - c thrift.Client + c thrift.Client + nwc thrift.NoWireClient } diff --git a/encoding/thrift/thriftrw-plugin-yarpc/internal/tests/extends/nameclient/client.go b/encoding/thrift/thriftrw-plugin-yarpc/internal/tests/extends/nameclient/client.go index 96775aca2e..2a8dc0f47b 100644 --- a/encoding/thrift/thriftrw-plugin-yarpc/internal/tests/extends/nameclient/client.go +++ b/encoding/thrift/thriftrw-plugin-yarpc/internal/tests/extends/nameclient/client.go @@ -30,6 +30,10 @@ func New(c transport.ClientConfig, opts ...thrift.ClientOption) Interface { Service: "Name", ClientConfig: c, }, opts...), + nwc: thrift.NewNoWire(thrift.Config{ + Service: "Name", + ClientConfig: c, + }, opts...), } } @@ -42,7 +46,8 @@ func init() { } type client struct { - c thrift.Client + c thrift.Client + nwc thrift.NoWireClient } func (c client) Name( @@ -50,17 +55,24 @@ func (c client) Name( opts ...yarpc.CallOption, ) (success string, err error) { + var result extends.Name_Name_Result args := extends.Name_Name_Helper.Args() - var body wire.Value - body, err = c.c.Call(ctx, args, opts...) - if err != nil { - return - } + if c.nwc != nil && c.nwc.Enabled() { + err = c.nwc.Call(ctx, args, &result, opts...) + if err != nil { + return + } + } else { + var body wire.Value + body, err = c.c.Call(ctx, args, opts...) + if err != nil { + return + } - var result extends.Name_Name_Result - if err = result.FromWire(body); err != nil { - return + if err = result.FromWire(body); err != nil { + return + } } success, err = extends.Name_Name_Helper.UnwrapResponse(&result) diff --git a/encoding/thrift/thriftrw-plugin-yarpc/internal/tests/weather/weatherclient/client.go b/encoding/thrift/thriftrw-plugin-yarpc/internal/tests/weather/weatherclient/client.go index 28c16a244b..1d6097f01a 100644 --- a/encoding/thrift/thriftrw-plugin-yarpc/internal/tests/weather/weatherclient/client.go +++ b/encoding/thrift/thriftrw-plugin-yarpc/internal/tests/weather/weatherclient/client.go @@ -31,6 +31,10 @@ func New(c transport.ClientConfig, opts ...thrift.ClientOption) Interface { Service: "Weather", ClientConfig: c, }, opts...), + nwc: thrift.NewNoWire(thrift.Config{ + Service: "Weather", + ClientConfig: c, + }, opts...), } } @@ -43,7 +47,8 @@ func init() { } type client struct { - c thrift.Client + c thrift.Client + nwc thrift.NoWireClient } func (c client) Check( @@ -51,18 +56,25 @@ func (c client) Check( opts ...yarpc.CallOption, ) (success string, err error) { + var result weather.Weather_Check_Result args := weather.Weather_Check_Helper.Args() ctx = tchannel.WithoutHeaders(ctx) - var body wire.Value - body, err = c.c.Call(ctx, args, opts...) - if err != nil { - return - } + if c.nwc != nil && c.nwc.Enabled() { + err = c.nwc.Call(ctx, args, &result, opts...) + if err != nil { + return + } + } else { + var body wire.Value + body, err = c.c.Call(ctx, args, opts...) + if err != nil { + return + } - var result weather.Weather_Check_Result - if err = result.FromWire(body); err != nil { - return + if err = result.FromWire(body); err != nil { + return + } } success, err = weather.Weather_Check_Helper.UnwrapResponse(&result) diff --git a/encoding/thrift/thriftrw-plugin-yarpc/roundtrip_test.go b/encoding/thrift/thriftrw-plugin-yarpc/roundtrip_test.go index a75f49dc5e..5f2db35b75 100644 --- a/encoding/thrift/thriftrw-plugin-yarpc/roundtrip_test.go +++ b/encoding/thrift/thriftrw-plugin-yarpc/roundtrip_test.go @@ -55,34 +55,42 @@ import ( ) func TestRoundTrip(t *testing.T) { - tests := []struct{ enveloped, multiplexed, nowire bool }{ - {true, true, true}, - {true, true, false}, + tests := []struct{ enveloped, multiplexed, nowireServer, nowireClient bool }{ + {true, true, true, true}, + {true, true, true, false}, + {true, true, false, true}, + {true, true, false, false}, // Skipping for now until flaky test fixed. // Uncomment this when fixed. // https://github.com/yarpc/yarpc-go/issues/1171 - //{true, false, true}, - //{true, false, false}, - {false, true, true}, - {false, true, false}, - {false, false, true}, - {false, false, false}, + //{true, false, true, true}, + //{true, false, true, false}, + //{true, false, false, true}, + //{true, false, false, false}, + {false, true, true, true}, + {false, true, true, false}, + {false, true, false, true}, + {false, true, false, false}, + {false, false, true, true}, + {false, false, true, false}, + {false, false, false, true}, + {false, false, false, false}, } for _, tt := range tests { - name := fmt.Sprintf("enveloped(%v)/multiplexed(%v)/nowire(%v)", tt.enveloped, tt.multiplexed, tt.nowire) - t.Run(name, func(t *testing.T) { testRoundTrip(t, tt.enveloped, tt.multiplexed, tt.nowire) }) + name := fmt.Sprintf("enveloped(%v)/multiplexed(%v)/nowireServer(%v)/nowireClient(%v)", tt.enveloped, tt.multiplexed, tt.nowireServer, tt.nowireClient) + t.Run(name, func(t *testing.T) { testRoundTrip(t, tt.enveloped, tt.multiplexed, tt.nowireServer, tt.nowireClient) }) } } -func testRoundTrip(t *testing.T, enveloped, multiplexed, nowire bool) { +func testRoundTrip(t *testing.T, enveloped, multiplexed, nowireServer, nowireClient bool) { t.Helper() var serverOpts []thrift.RegisterOption if enveloped { serverOpts = append(serverOpts, thrift.Enveloped) } - serverOpts = append(serverOpts, thrift.NoWire(nowire)) + serverOpts = append(serverOpts, thrift.NoWire(nowireServer)) var clientOpts []string if enveloped { @@ -91,6 +99,9 @@ func testRoundTrip(t *testing.T, enveloped, multiplexed, nowire bool) { if multiplexed { clientOpts = append(clientOpts, "multiplexed") } + if nowireClient { + clientOpts = append(clientOpts, "nowire") + } var thriftTag string if len(clientOpts) > 0 { diff --git a/internal/crossdock/thrift/echo/echoclient/client.go b/internal/crossdock/thrift/echo/echoclient/client.go index 97bcdecced..ffc7deb703 100644 --- a/internal/crossdock/thrift/echo/echoclient/client.go +++ b/internal/crossdock/thrift/echo/echoclient/client.go @@ -51,6 +51,10 @@ func New(c transport.ClientConfig, opts ...thrift.ClientOption) Interface { Service: "Echo", ClientConfig: c, }, opts...), + nwc: thrift.NewNoWire(thrift.Config{ + Service: "Echo", + ClientConfig: c, + }, opts...), } } @@ -63,7 +67,8 @@ func init() { } type client struct { - c thrift.Client + c thrift.Client + nwc thrift.NoWireClient } func (c client) Echo( @@ -72,17 +77,24 @@ func (c client) Echo( opts ...yarpc.CallOption, ) (success *echo.Pong, err error) { + var result echo.Echo_Echo_Result args := echo.Echo_Echo_Helper.Args(_Ping) - var body wire.Value - body, err = c.c.Call(ctx, args, opts...) - if err != nil { - return - } + if c.nwc != nil && c.nwc.Enabled() { + err = c.nwc.Call(ctx, args, &result, opts...) + if err != nil { + return + } + } else { + var body wire.Value + body, err = c.c.Call(ctx, args, opts...) + if err != nil { + return + } - var result echo.Echo_Echo_Result - if err = result.FromWire(body); err != nil { - return + if err = result.FromWire(body); err != nil { + return + } } success, err = echo.Echo_Echo_Helper.UnwrapResponse(&result) diff --git a/internal/crossdock/thrift/gauntlet/secondserviceclient/client.go b/internal/crossdock/thrift/gauntlet/secondserviceclient/client.go index ffce0158ee..71862b8610 100644 --- a/internal/crossdock/thrift/gauntlet/secondserviceclient/client.go +++ b/internal/crossdock/thrift/gauntlet/secondserviceclient/client.go @@ -56,6 +56,10 @@ func New(c transport.ClientConfig, opts ...thrift.ClientOption) Interface { Service: "SecondService", ClientConfig: c, }, opts...), + nwc: thrift.NewNoWire(thrift.Config{ + Service: "SecondService", + ClientConfig: c, + }, opts...), } } @@ -68,7 +72,8 @@ func init() { } type client struct { - c thrift.Client + c thrift.Client + nwc thrift.NoWireClient } func (c client) BlahBlah( @@ -76,17 +81,24 @@ func (c client) BlahBlah( opts ...yarpc.CallOption, ) (err error) { + var result gauntlet.SecondService_BlahBlah_Result args := gauntlet.SecondService_BlahBlah_Helper.Args() - var body wire.Value - body, err = c.c.Call(ctx, args, opts...) - if err != nil { - return - } - - var result gauntlet.SecondService_BlahBlah_Result - if err = result.FromWire(body); err != nil { - return + if c.nwc != nil && c.nwc.Enabled() { + err = c.nwc.Call(ctx, args, &result, opts...) + if err != nil { + return + } + } else { + var body wire.Value + body, err = c.c.Call(ctx, args, opts...) + if err != nil { + return + } + + if err = result.FromWire(body); err != nil { + return + } } err = gauntlet.SecondService_BlahBlah_Helper.UnwrapResponse(&result) @@ -99,17 +111,24 @@ func (c client) SecondtestString( opts ...yarpc.CallOption, ) (success string, err error) { + var result gauntlet.SecondService_SecondtestString_Result args := gauntlet.SecondService_SecondtestString_Helper.Args(_Thing) - var body wire.Value - body, err = c.c.Call(ctx, args, opts...) - if err != nil { - return - } - - var result gauntlet.SecondService_SecondtestString_Result - if err = result.FromWire(body); err != nil { - return + if c.nwc != nil && c.nwc.Enabled() { + err = c.nwc.Call(ctx, args, &result, opts...) + if err != nil { + return + } + } else { + var body wire.Value + body, err = c.c.Call(ctx, args, opts...) + if err != nil { + return + } + + if err = result.FromWire(body); err != nil { + return + } } success, err = gauntlet.SecondService_SecondtestString_Helper.UnwrapResponse(&result) diff --git a/internal/crossdock/thrift/gauntlet/thrifttestclient/client.go b/internal/crossdock/thrift/gauntlet/thrifttestclient/client.go index 07ad923e78..94f7ac1b2f 100644 --- a/internal/crossdock/thrift/gauntlet/thrifttestclient/client.go +++ b/internal/crossdock/thrift/gauntlet/thrifttestclient/client.go @@ -176,6 +176,10 @@ func New(c transport.ClientConfig, opts ...thrift.ClientOption) Interface { Service: "ThriftTest", ClientConfig: c, }, opts...), + nwc: thrift.NewNoWire(thrift.Config{ + Service: "ThriftTest", + ClientConfig: c, + }, opts...), } } @@ -188,7 +192,8 @@ func init() { } type client struct { - c thrift.Client + c thrift.Client + nwc thrift.NoWireClient } func (c client) TestBinary( @@ -197,17 +202,24 @@ func (c client) TestBinary( opts ...yarpc.CallOption, ) (success []byte, err error) { + var result gauntlet.ThriftTest_TestBinary_Result args := gauntlet.ThriftTest_TestBinary_Helper.Args(_Thing) - var body wire.Value - body, err = c.c.Call(ctx, args, opts...) - if err != nil { - return - } + if c.nwc != nil && c.nwc.Enabled() { + err = c.nwc.Call(ctx, args, &result, opts...) + if err != nil { + return + } + } else { + var body wire.Value + body, err = c.c.Call(ctx, args, opts...) + if err != nil { + return + } - var result gauntlet.ThriftTest_TestBinary_Result - if err = result.FromWire(body); err != nil { - return + if err = result.FromWire(body); err != nil { + return + } } success, err = gauntlet.ThriftTest_TestBinary_Helper.UnwrapResponse(&result) @@ -220,17 +232,24 @@ func (c client) TestByte( opts ...yarpc.CallOption, ) (success int8, err error) { + var result gauntlet.ThriftTest_TestByte_Result args := gauntlet.ThriftTest_TestByte_Helper.Args(_Thing) - var body wire.Value - body, err = c.c.Call(ctx, args, opts...) - if err != nil { - return - } + if c.nwc != nil && c.nwc.Enabled() { + err = c.nwc.Call(ctx, args, &result, opts...) + if err != nil { + return + } + } else { + var body wire.Value + body, err = c.c.Call(ctx, args, opts...) + if err != nil { + return + } - var result gauntlet.ThriftTest_TestByte_Result - if err = result.FromWire(body); err != nil { - return + if err = result.FromWire(body); err != nil { + return + } } success, err = gauntlet.ThriftTest_TestByte_Helper.UnwrapResponse(&result) @@ -243,17 +262,24 @@ func (c client) TestDouble( opts ...yarpc.CallOption, ) (success float64, err error) { + var result gauntlet.ThriftTest_TestDouble_Result args := gauntlet.ThriftTest_TestDouble_Helper.Args(_Thing) - var body wire.Value - body, err = c.c.Call(ctx, args, opts...) - if err != nil { - return - } + if c.nwc != nil && c.nwc.Enabled() { + err = c.nwc.Call(ctx, args, &result, opts...) + if err != nil { + return + } + } else { + var body wire.Value + body, err = c.c.Call(ctx, args, opts...) + if err != nil { + return + } - var result gauntlet.ThriftTest_TestDouble_Result - if err = result.FromWire(body); err != nil { - return + if err = result.FromWire(body); err != nil { + return + } } success, err = gauntlet.ThriftTest_TestDouble_Helper.UnwrapResponse(&result) @@ -266,17 +292,24 @@ func (c client) TestEnum( opts ...yarpc.CallOption, ) (success gauntlet.Numberz, err error) { + var result gauntlet.ThriftTest_TestEnum_Result args := gauntlet.ThriftTest_TestEnum_Helper.Args(_Thing) - var body wire.Value - body, err = c.c.Call(ctx, args, opts...) - if err != nil { - return - } + if c.nwc != nil && c.nwc.Enabled() { + err = c.nwc.Call(ctx, args, &result, opts...) + if err != nil { + return + } + } else { + var body wire.Value + body, err = c.c.Call(ctx, args, opts...) + if err != nil { + return + } - var result gauntlet.ThriftTest_TestEnum_Result - if err = result.FromWire(body); err != nil { - return + if err = result.FromWire(body); err != nil { + return + } } success, err = gauntlet.ThriftTest_TestEnum_Helper.UnwrapResponse(&result) @@ -289,17 +322,24 @@ func (c client) TestException( opts ...yarpc.CallOption, ) (err error) { + var result gauntlet.ThriftTest_TestException_Result args := gauntlet.ThriftTest_TestException_Helper.Args(_Arg) - var body wire.Value - body, err = c.c.Call(ctx, args, opts...) - if err != nil { - return - } + if c.nwc != nil && c.nwc.Enabled() { + err = c.nwc.Call(ctx, args, &result, opts...) + if err != nil { + return + } + } else { + var body wire.Value + body, err = c.c.Call(ctx, args, opts...) + if err != nil { + return + } - var result gauntlet.ThriftTest_TestException_Result - if err = result.FromWire(body); err != nil { - return + if err = result.FromWire(body); err != nil { + return + } } err = gauntlet.ThriftTest_TestException_Helper.UnwrapResponse(&result) @@ -312,17 +352,24 @@ func (c client) TestI32( opts ...yarpc.CallOption, ) (success int32, err error) { + var result gauntlet.ThriftTest_TestI32_Result args := gauntlet.ThriftTest_TestI32_Helper.Args(_Thing) - var body wire.Value - body, err = c.c.Call(ctx, args, opts...) - if err != nil { - return - } + if c.nwc != nil && c.nwc.Enabled() { + err = c.nwc.Call(ctx, args, &result, opts...) + if err != nil { + return + } + } else { + var body wire.Value + body, err = c.c.Call(ctx, args, opts...) + if err != nil { + return + } - var result gauntlet.ThriftTest_TestI32_Result - if err = result.FromWire(body); err != nil { - return + if err = result.FromWire(body); err != nil { + return + } } success, err = gauntlet.ThriftTest_TestI32_Helper.UnwrapResponse(&result) @@ -335,17 +382,24 @@ func (c client) TestI64( opts ...yarpc.CallOption, ) (success int64, err error) { + var result gauntlet.ThriftTest_TestI64_Result args := gauntlet.ThriftTest_TestI64_Helper.Args(_Thing) - var body wire.Value - body, err = c.c.Call(ctx, args, opts...) - if err != nil { - return - } + if c.nwc != nil && c.nwc.Enabled() { + err = c.nwc.Call(ctx, args, &result, opts...) + if err != nil { + return + } + } else { + var body wire.Value + body, err = c.c.Call(ctx, args, opts...) + if err != nil { + return + } - var result gauntlet.ThriftTest_TestI64_Result - if err = result.FromWire(body); err != nil { - return + if err = result.FromWire(body); err != nil { + return + } } success, err = gauntlet.ThriftTest_TestI64_Helper.UnwrapResponse(&result) @@ -358,17 +412,24 @@ func (c client) TestInsanity( opts ...yarpc.CallOption, ) (success map[gauntlet.UserId]map[gauntlet.Numberz]*gauntlet.Insanity, err error) { + var result gauntlet.ThriftTest_TestInsanity_Result args := gauntlet.ThriftTest_TestInsanity_Helper.Args(_Argument) - var body wire.Value - body, err = c.c.Call(ctx, args, opts...) - if err != nil { - return - } + if c.nwc != nil && c.nwc.Enabled() { + err = c.nwc.Call(ctx, args, &result, opts...) + if err != nil { + return + } + } else { + var body wire.Value + body, err = c.c.Call(ctx, args, opts...) + if err != nil { + return + } - var result gauntlet.ThriftTest_TestInsanity_Result - if err = result.FromWire(body); err != nil { - return + if err = result.FromWire(body); err != nil { + return + } } success, err = gauntlet.ThriftTest_TestInsanity_Helper.UnwrapResponse(&result) @@ -381,17 +442,24 @@ func (c client) TestList( opts ...yarpc.CallOption, ) (success []int32, err error) { + var result gauntlet.ThriftTest_TestList_Result args := gauntlet.ThriftTest_TestList_Helper.Args(_Thing) - var body wire.Value - body, err = c.c.Call(ctx, args, opts...) - if err != nil { - return - } + if c.nwc != nil && c.nwc.Enabled() { + err = c.nwc.Call(ctx, args, &result, opts...) + if err != nil { + return + } + } else { + var body wire.Value + body, err = c.c.Call(ctx, args, opts...) + if err != nil { + return + } - var result gauntlet.ThriftTest_TestList_Result - if err = result.FromWire(body); err != nil { - return + if err = result.FromWire(body); err != nil { + return + } } success, err = gauntlet.ThriftTest_TestList_Helper.UnwrapResponse(&result) @@ -404,17 +472,24 @@ func (c client) TestMap( opts ...yarpc.CallOption, ) (success map[int32]int32, err error) { + var result gauntlet.ThriftTest_TestMap_Result args := gauntlet.ThriftTest_TestMap_Helper.Args(_Thing) - var body wire.Value - body, err = c.c.Call(ctx, args, opts...) - if err != nil { - return - } + if c.nwc != nil && c.nwc.Enabled() { + err = c.nwc.Call(ctx, args, &result, opts...) + if err != nil { + return + } + } else { + var body wire.Value + body, err = c.c.Call(ctx, args, opts...) + if err != nil { + return + } - var result gauntlet.ThriftTest_TestMap_Result - if err = result.FromWire(body); err != nil { - return + if err = result.FromWire(body); err != nil { + return + } } success, err = gauntlet.ThriftTest_TestMap_Helper.UnwrapResponse(&result) @@ -427,17 +502,24 @@ func (c client) TestMapMap( opts ...yarpc.CallOption, ) (success map[int32]map[int32]int32, err error) { + var result gauntlet.ThriftTest_TestMapMap_Result args := gauntlet.ThriftTest_TestMapMap_Helper.Args(_Hello) - var body wire.Value - body, err = c.c.Call(ctx, args, opts...) - if err != nil { - return - } + if c.nwc != nil && c.nwc.Enabled() { + err = c.nwc.Call(ctx, args, &result, opts...) + if err != nil { + return + } + } else { + var body wire.Value + body, err = c.c.Call(ctx, args, opts...) + if err != nil { + return + } - var result gauntlet.ThriftTest_TestMapMap_Result - if err = result.FromWire(body); err != nil { - return + if err = result.FromWire(body); err != nil { + return + } } success, err = gauntlet.ThriftTest_TestMapMap_Helper.UnwrapResponse(&result) @@ -455,17 +537,24 @@ func (c client) TestMulti( opts ...yarpc.CallOption, ) (success *gauntlet.Xtruct, err error) { + var result gauntlet.ThriftTest_TestMulti_Result args := gauntlet.ThriftTest_TestMulti_Helper.Args(_Arg0, _Arg1, _Arg2, _Arg3, _Arg4, _Arg5) - var body wire.Value - body, err = c.c.Call(ctx, args, opts...) - if err != nil { - return - } + if c.nwc != nil && c.nwc.Enabled() { + err = c.nwc.Call(ctx, args, &result, opts...) + if err != nil { + return + } + } else { + var body wire.Value + body, err = c.c.Call(ctx, args, opts...) + if err != nil { + return + } - var result gauntlet.ThriftTest_TestMulti_Result - if err = result.FromWire(body); err != nil { - return + if err = result.FromWire(body); err != nil { + return + } } success, err = gauntlet.ThriftTest_TestMulti_Helper.UnwrapResponse(&result) @@ -479,17 +568,24 @@ func (c client) TestMultiException( opts ...yarpc.CallOption, ) (success *gauntlet.Xtruct, err error) { + var result gauntlet.ThriftTest_TestMultiException_Result args := gauntlet.ThriftTest_TestMultiException_Helper.Args(_Arg0, _Arg1) - var body wire.Value - body, err = c.c.Call(ctx, args, opts...) - if err != nil { - return - } + if c.nwc != nil && c.nwc.Enabled() { + err = c.nwc.Call(ctx, args, &result, opts...) + if err != nil { + return + } + } else { + var body wire.Value + body, err = c.c.Call(ctx, args, opts...) + if err != nil { + return + } - var result gauntlet.ThriftTest_TestMultiException_Result - if err = result.FromWire(body); err != nil { - return + if err = result.FromWire(body); err != nil { + return + } } success, err = gauntlet.ThriftTest_TestMultiException_Helper.UnwrapResponse(&result) @@ -502,17 +598,24 @@ func (c client) TestNest( opts ...yarpc.CallOption, ) (success *gauntlet.Xtruct2, err error) { + var result gauntlet.ThriftTest_TestNest_Result args := gauntlet.ThriftTest_TestNest_Helper.Args(_Thing) - var body wire.Value - body, err = c.c.Call(ctx, args, opts...) - if err != nil { - return - } + if c.nwc != nil && c.nwc.Enabled() { + err = c.nwc.Call(ctx, args, &result, opts...) + if err != nil { + return + } + } else { + var body wire.Value + body, err = c.c.Call(ctx, args, opts...) + if err != nil { + return + } - var result gauntlet.ThriftTest_TestNest_Result - if err = result.FromWire(body); err != nil { - return + if err = result.FromWire(body); err != nil { + return + } } success, err = gauntlet.ThriftTest_TestNest_Helper.UnwrapResponse(&result) @@ -534,17 +637,24 @@ func (c client) TestSet( opts ...yarpc.CallOption, ) (success map[int32]struct{}, err error) { + var result gauntlet.ThriftTest_TestSet_Result args := gauntlet.ThriftTest_TestSet_Helper.Args(_Thing) - var body wire.Value - body, err = c.c.Call(ctx, args, opts...) - if err != nil { - return - } + if c.nwc != nil && c.nwc.Enabled() { + err = c.nwc.Call(ctx, args, &result, opts...) + if err != nil { + return + } + } else { + var body wire.Value + body, err = c.c.Call(ctx, args, opts...) + if err != nil { + return + } - var result gauntlet.ThriftTest_TestSet_Result - if err = result.FromWire(body); err != nil { - return + if err = result.FromWire(body); err != nil { + return + } } success, err = gauntlet.ThriftTest_TestSet_Helper.UnwrapResponse(&result) @@ -557,17 +667,24 @@ func (c client) TestString( opts ...yarpc.CallOption, ) (success string, err error) { + var result gauntlet.ThriftTest_TestString_Result args := gauntlet.ThriftTest_TestString_Helper.Args(_Thing) - var body wire.Value - body, err = c.c.Call(ctx, args, opts...) - if err != nil { - return - } + if c.nwc != nil && c.nwc.Enabled() { + err = c.nwc.Call(ctx, args, &result, opts...) + if err != nil { + return + } + } else { + var body wire.Value + body, err = c.c.Call(ctx, args, opts...) + if err != nil { + return + } - var result gauntlet.ThriftTest_TestString_Result - if err = result.FromWire(body); err != nil { - return + if err = result.FromWire(body); err != nil { + return + } } success, err = gauntlet.ThriftTest_TestString_Helper.UnwrapResponse(&result) @@ -580,17 +697,24 @@ func (c client) TestStringMap( opts ...yarpc.CallOption, ) (success map[string]string, err error) { + var result gauntlet.ThriftTest_TestStringMap_Result args := gauntlet.ThriftTest_TestStringMap_Helper.Args(_Thing) - var body wire.Value - body, err = c.c.Call(ctx, args, opts...) - if err != nil { - return - } + if c.nwc != nil && c.nwc.Enabled() { + err = c.nwc.Call(ctx, args, &result, opts...) + if err != nil { + return + } + } else { + var body wire.Value + body, err = c.c.Call(ctx, args, opts...) + if err != nil { + return + } - var result gauntlet.ThriftTest_TestStringMap_Result - if err = result.FromWire(body); err != nil { - return + if err = result.FromWire(body); err != nil { + return + } } success, err = gauntlet.ThriftTest_TestStringMap_Helper.UnwrapResponse(&result) @@ -603,17 +727,24 @@ func (c client) TestStruct( opts ...yarpc.CallOption, ) (success *gauntlet.Xtruct, err error) { + var result gauntlet.ThriftTest_TestStruct_Result args := gauntlet.ThriftTest_TestStruct_Helper.Args(_Thing) - var body wire.Value - body, err = c.c.Call(ctx, args, opts...) - if err != nil { - return - } + if c.nwc != nil && c.nwc.Enabled() { + err = c.nwc.Call(ctx, args, &result, opts...) + if err != nil { + return + } + } else { + var body wire.Value + body, err = c.c.Call(ctx, args, opts...) + if err != nil { + return + } - var result gauntlet.ThriftTest_TestStruct_Result - if err = result.FromWire(body); err != nil { - return + if err = result.FromWire(body); err != nil { + return + } } success, err = gauntlet.ThriftTest_TestStruct_Helper.UnwrapResponse(&result) @@ -626,17 +757,24 @@ func (c client) TestTypedef( opts ...yarpc.CallOption, ) (success gauntlet.UserId, err error) { + var result gauntlet.ThriftTest_TestTypedef_Result args := gauntlet.ThriftTest_TestTypedef_Helper.Args(_Thing) - var body wire.Value - body, err = c.c.Call(ctx, args, opts...) - if err != nil { - return - } + if c.nwc != nil && c.nwc.Enabled() { + err = c.nwc.Call(ctx, args, &result, opts...) + if err != nil { + return + } + } else { + var body wire.Value + body, err = c.c.Call(ctx, args, opts...) + if err != nil { + return + } - var result gauntlet.ThriftTest_TestTypedef_Result - if err = result.FromWire(body); err != nil { - return + if err = result.FromWire(body); err != nil { + return + } } success, err = gauntlet.ThriftTest_TestTypedef_Helper.UnwrapResponse(&result) @@ -648,17 +786,24 @@ func (c client) TestVoid( opts ...yarpc.CallOption, ) (err error) { + var result gauntlet.ThriftTest_TestVoid_Result args := gauntlet.ThriftTest_TestVoid_Helper.Args() - var body wire.Value - body, err = c.c.Call(ctx, args, opts...) - if err != nil { - return - } - - var result gauntlet.ThriftTest_TestVoid_Result - if err = result.FromWire(body); err != nil { - return + if c.nwc != nil && c.nwc.Enabled() { + err = c.nwc.Call(ctx, args, &result, opts...) + if err != nil { + return + } + } else { + var body wire.Value + body, err = c.c.Call(ctx, args, opts...) + if err != nil { + return + } + + if err = result.FromWire(body); err != nil { + return + } } err = gauntlet.ThriftTest_TestVoid_Helper.UnwrapResponse(&result) diff --git a/internal/crossdock/thrift/oneway/onewayclient/client.go b/internal/crossdock/thrift/oneway/onewayclient/client.go index 4f9cf4b13b..835e5cb563 100644 --- a/internal/crossdock/thrift/oneway/onewayclient/client.go +++ b/internal/crossdock/thrift/oneway/onewayclient/client.go @@ -50,6 +50,10 @@ func New(c transport.ClientConfig, opts ...thrift.ClientOption) Interface { Service: "Oneway", ClientConfig: c, }, opts...), + nwc: thrift.NewNoWire(thrift.Config{ + Service: "Oneway", + ClientConfig: c, + }, opts...), } } @@ -62,7 +66,8 @@ func init() { } type client struct { - c thrift.Client + c thrift.Client + nwc thrift.NoWireClient } func (c client) Echo( diff --git a/internal/examples/thrift-hello/hello/echo/helloclient/client.go b/internal/examples/thrift-hello/hello/echo/helloclient/client.go index d35c9b8a8c..0819436881 100644 --- a/internal/examples/thrift-hello/hello/echo/helloclient/client.go +++ b/internal/examples/thrift-hello/hello/echo/helloclient/client.go @@ -51,6 +51,10 @@ func New(c transport.ClientConfig, opts ...thrift.ClientOption) Interface { Service: "Hello", ClientConfig: c, }, opts...), + nwc: thrift.NewNoWire(thrift.Config{ + Service: "Hello", + ClientConfig: c, + }, opts...), } } @@ -63,7 +67,8 @@ func init() { } type client struct { - c thrift.Client + c thrift.Client + nwc thrift.NoWireClient } func (c client) Echo( @@ -72,17 +77,24 @@ func (c client) Echo( opts ...yarpc.CallOption, ) (success *echo.EchoResponse, err error) { + var result echo.Hello_Echo_Result args := echo.Hello_Echo_Helper.Args(_Echo) - var body wire.Value - body, err = c.c.Call(ctx, args, opts...) - if err != nil { - return - } + if c.nwc != nil && c.nwc.Enabled() { + err = c.nwc.Call(ctx, args, &result, opts...) + if err != nil { + return + } + } else { + var body wire.Value + body, err = c.c.Call(ctx, args, opts...) + if err != nil { + return + } - var result echo.Hello_Echo_Result - if err = result.FromWire(body); err != nil { - return + if err = result.FromWire(body); err != nil { + return + } } success, err = echo.Hello_Echo_Helper.UnwrapResponse(&result) diff --git a/internal/examples/thrift-keyvalue/keyvalue/kv/keyvalueclient/client.go b/internal/examples/thrift-keyvalue/keyvalue/kv/keyvalueclient/client.go index e18c0f2c9b..b29a9f5c0b 100644 --- a/internal/examples/thrift-keyvalue/keyvalue/kv/keyvalueclient/client.go +++ b/internal/examples/thrift-keyvalue/keyvalue/kv/keyvalueclient/client.go @@ -58,6 +58,10 @@ func New(c transport.ClientConfig, opts ...thrift.ClientOption) Interface { Service: "KeyValue", ClientConfig: c, }, opts...), + nwc: thrift.NewNoWire(thrift.Config{ + Service: "KeyValue", + ClientConfig: c, + }, opts...), } } @@ -70,7 +74,8 @@ func init() { } type client struct { - c thrift.Client + c thrift.Client + nwc thrift.NoWireClient } func (c client) GetValue( @@ -79,17 +84,24 @@ func (c client) GetValue( opts ...yarpc.CallOption, ) (success string, err error) { + var result kv.KeyValue_GetValue_Result args := kv.KeyValue_GetValue_Helper.Args(_Key) - var body wire.Value - body, err = c.c.Call(ctx, args, opts...) - if err != nil { - return - } - - var result kv.KeyValue_GetValue_Result - if err = result.FromWire(body); err != nil { - return + if c.nwc != nil && c.nwc.Enabled() { + err = c.nwc.Call(ctx, args, &result, opts...) + if err != nil { + return + } + } else { + var body wire.Value + body, err = c.c.Call(ctx, args, opts...) + if err != nil { + return + } + + if err = result.FromWire(body); err != nil { + return + } } success, err = kv.KeyValue_GetValue_Helper.UnwrapResponse(&result) @@ -103,17 +115,24 @@ func (c client) SetValue( opts ...yarpc.CallOption, ) (err error) { + var result kv.KeyValue_SetValue_Result args := kv.KeyValue_SetValue_Helper.Args(_Key, _Value) - var body wire.Value - body, err = c.c.Call(ctx, args, opts...) - if err != nil { - return - } - - var result kv.KeyValue_SetValue_Result - if err = result.FromWire(body); err != nil { - return + if c.nwc != nil && c.nwc.Enabled() { + err = c.nwc.Call(ctx, args, &result, opts...) + if err != nil { + return + } + } else { + var body wire.Value + body, err = c.c.Call(ctx, args, opts...) + if err != nil { + return + } + + if err = result.FromWire(body); err != nil { + return + } } err = kv.KeyValue_SetValue_Helper.UnwrapResponse(&result) diff --git a/internal/examples/thrift-oneway/sink/helloclient/client.go b/internal/examples/thrift-oneway/sink/helloclient/client.go index 34511ac13a..940e623ee4 100644 --- a/internal/examples/thrift-oneway/sink/helloclient/client.go +++ b/internal/examples/thrift-oneway/sink/helloclient/client.go @@ -50,6 +50,10 @@ func New(c transport.ClientConfig, opts ...thrift.ClientOption) Interface { Service: "Hello", ClientConfig: c, }, opts...), + nwc: thrift.NewNoWire(thrift.Config{ + Service: "Hello", + ClientConfig: c, + }, opts...), } } @@ -62,7 +66,8 @@ func init() { } type client struct { - c thrift.Client + c thrift.Client + nwc thrift.NoWireClient } func (c client) Sink(