diff --git a/encoding/thrift/envelope.go b/encoding/thrift/envelope.go index 4d4c26ae01..62d1942a33 100644 --- a/encoding/thrift/envelope.go +++ b/encoding/thrift/envelope.go @@ -64,7 +64,7 @@ type disableEnvelopingNoWireProtocol struct { } func (evsp disableEnvelopingNoWireProtocol) Reader(r io.Reader) stream.Reader { - return disableEnvelopingReader{ + return disableEnvelopingNoWireReader{ Reader: evsp.Protocol.Reader(r), Type: evsp.Type, } @@ -76,13 +76,13 @@ func (evsp disableEnvelopingNoWireProtocol) Writer(w io.Writer) stream.Writer { } } -type disableEnvelopingReader struct { +type disableEnvelopingNoWireReader struct { stream.Reader Type wire.EnvelopeType } -func (evr disableEnvelopingReader) ReadEnvelopeBegin() (stream.EnvelopeHeader, error) { +func (evr disableEnvelopingNoWireReader) ReadEnvelopeBegin() (stream.EnvelopeHeader, error) { return stream.EnvelopeHeader{ Name: "", Type: evr.Type, @@ -90,7 +90,7 @@ func (evr disableEnvelopingReader) ReadEnvelopeBegin() (stream.EnvelopeHeader, e }, nil } -func (evr disableEnvelopingReader) ReadEnvelopeEnd() error { return nil } +func (evr disableEnvelopingNoWireReader) ReadEnvelopeEnd() error { return nil } type disableEnvelopingWriter struct { stream.Writer diff --git a/encoding/thrift/multiplex.go b/encoding/thrift/multiplex.go index c343fd89da..57ea32b59a 100644 --- a/encoding/thrift/multiplex.go +++ b/encoding/thrift/multiplex.go @@ -57,37 +57,37 @@ type multiplexedOutboundNoWireProtocol struct { } func (m multiplexedOutboundNoWireProtocol) Writer(w io.Writer) stream.Writer { - return multiplexedWriter{ + return multiplexedNoWireWriter{ Writer: m.Protocol.Writer(w), Service: m.Service, } } func (m multiplexedOutboundNoWireProtocol) Reader(r io.Reader) stream.Reader { - return multiplexedReader{ + return multiplexedNoWireReader{ Reader: m.Protocol.Reader(r), Service: m.Service, } } -type multiplexedWriter struct { +type multiplexedNoWireWriter struct { stream.Writer Service string } -func (w multiplexedWriter) WriteEnvelopeBegin(eh stream.EnvelopeHeader) error { +func (w multiplexedNoWireWriter) WriteEnvelopeBegin(eh stream.EnvelopeHeader) error { eh.Name = w.Service + ":" + eh.Name return w.Writer.WriteEnvelopeBegin(eh) } -type multiplexedReader struct { +type multiplexedNoWireReader struct { stream.Reader Service string } -func (r multiplexedReader) ReadEnvelopeBegin() (stream.EnvelopeHeader, error) { +func (r multiplexedNoWireReader) 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 index 8c54614960..acd5db8504 100644 --- a/encoding/thrift/outbound_nowire.go +++ b/encoding/thrift/outbound_nowire.go @@ -37,7 +37,9 @@ import ( ) // NoWireClient is a generic Thrift client for encoding/decoding using -// ThriftRW's "streaming" mechanisms. +// ThriftRW's "streaming" mechanisms. The body of the request is expected to be +// written out of through a `reqBody` (its `Encode`), while the response is +// expected to be read out through `resBody` (its `Decode`). // It speaks in raw Thrift payloads. // // Users should use the client generated by the code generator rather than @@ -127,7 +129,7 @@ func (c noWireThriftClient) Call(ctx context.Context, reqBody stream.Enveloper, out := c.cc.GetUnaryOutbound() - treq, proto, err := c.writeTransportRequest(reqBody) + treq, proto, err := c.buildTransportRequest(reqBody) if err != nil { return err } @@ -144,19 +146,19 @@ func (c noWireThriftClient) Call(ctx context.Context, reqBody stream.Enveloper, } defer tres.Body.Close() - if _, err = call.ReadFromResponse(ctx, tres); err != nil { + if _, err := call.ReadFromResponse(ctx, tres); err != nil { return err } sr := proto.Reader(tres.Body) defer sr.Close() - env, err := sr.ReadEnvelopeBegin() + envelope, err := sr.ReadEnvelopeBegin() if err != nil { return errors.ResponseBodyDecodeError(treq, err) } - switch env.Type { + switch envelope.Type { case wire.Reply: if err := resBody.Decode(sr); err != nil { return err @@ -164,7 +166,7 @@ func (c noWireThriftClient) Call(ctx context.Context, reqBody stream.Enveloper, return sr.ReadEnvelopeEnd() case wire.Exception: var exc internal.TApplicationException - if err = exc.Decode(sr); err != nil { + if err := exc.Decode(sr); err != nil { return errors.ResponseBodyDecodeError(treq, err) } return thriftException{ @@ -174,14 +176,14 @@ func (c noWireThriftClient) Call(ctx context.Context, reqBody stream.Enveloper, } default: return errors.ResponseBodyDecodeError( - treq, errUnexpectedEnvelopeType(env.Type)) + treq, errUnexpectedEnvelopeType(envelope.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) + treq, _, err := c.buildTransportRequest(reqBody) if err != nil { return nil, err } @@ -199,7 +201,7 @@ func (c noWireThriftClient) Enabled() bool { return c.NoWire } -func (c noWireThriftClient) writeTransportRequest(reqBody stream.Enveloper) (*transport.Request, stream.Protocol, error) { +func (c noWireThriftClient) buildTransportRequest(reqBody stream.Enveloper) (*transport.Request, stream.Protocol, error) { proto := c.p if !c.Enveloping { proto = disableEnvelopingNoWireProtocol{ diff --git a/encoding/thrift/register.go b/encoding/thrift/register.go index 69f475e88d..8c4423109f 100644 --- a/encoding/thrift/register.go +++ b/encoding/thrift/register.go @@ -49,12 +49,6 @@ type UnaryHandler func(context.Context, wire.Value) (Response, error) // OnewayHandler is a convenience type alias for functions that act as OnewayHandlers. type OnewayHandler func(context.Context, wire.Value) error -// UnaryStreamHandler is a convenience type alias for functions that act as StreamHandlers. -type UnaryStreamHandler func(context.Context, stream.Reader, stream.Writer) (Response, error) - -// OnewayStreamHandler is a convenience type alias for functions that act as OnewayStreamHandlers. -type OnewayStreamHandler func(context.Context, stream.Reader) error - // HandlerSpec represents the handler behind a Thrift service method. type HandlerSpec struct { Type transport.Type