diff --git a/third-party/thrift/src/thrift/lib/go/thrift/alias.go b/third-party/thrift/src/thrift/lib/go/thrift/alias.go index 991e9b4603ee3..8366b558d1bf1 100644 --- a/third-party/thrift/src/thrift/lib/go/thrift/alias.go +++ b/third-party/thrift/src/thrift/lib/go/thrift/alias.go @@ -40,16 +40,14 @@ type Exception = types.Exception type WritableStruct = types.WritableStruct +type ReadableStruct = types.ReadableStruct + type Encoder = types.Encoder type ApplicationException = types.ApplicationException type Type = types.Type -type IRequest = types.IRequest - -type IResponse = types.IResponse - type FormatID = types.ProtocolID type Format = types.Format diff --git a/third-party/thrift/src/thrift/lib/go/thrift/clientconn.go b/third-party/thrift/src/thrift/lib/go/thrift/clientconn.go index 6f716778ad847..a874d8e448004 100644 --- a/third-party/thrift/src/thrift/lib/go/thrift/clientconn.go +++ b/third-party/thrift/src/thrift/lib/go/thrift/clientconn.go @@ -42,7 +42,7 @@ func (cc *ClientConn) Close() error { } // SendMsg sends a request to a given thrift endpoint -func (cc *ClientConn) SendMsg(ctx context.Context, method string, req types.IRequest, msgType types.MessageType) error { +func (cc *ClientConn) SendMsg(ctx context.Context, method string, req types.WritableStruct, msgType types.MessageType) error { cc.seqID++ if err := types.SetRequestHeaders(ctx, cc.proto); err != nil { @@ -65,7 +65,7 @@ func (cc *ClientConn) SendMsg(ctx context.Context, method string, req types.IReq } // RecvMsg receives the response from a call to a thrift endpoint -func (cc *ClientConn) RecvMsg(ctx context.Context, method string, res types.IResponse) error { +func (cc *ClientConn) RecvMsg(ctx context.Context, method string, res types.ReadableStruct) error { recvMethod, mTypeID, seqID, err := cc.proto.ReadMessageBegin() if err != nil { diff --git a/third-party/thrift/src/thrift/lib/go/thrift/clientconn_test.go b/third-party/thrift/src/thrift/lib/go/thrift/clientconn_test.go index 3e9dd41d034e9..ead1ef80d2471 100644 --- a/third-party/thrift/src/thrift/lib/go/thrift/clientconn_test.go +++ b/third-party/thrift/src/thrift/lib/go/thrift/clientconn_test.go @@ -33,12 +33,12 @@ var errFakeProtoWriteMessageEnd = errors.New("error writing message end from Fak var errFakeProtoFlush = errors.New("error flushing FakeProto") type fakeResponse struct { - types.IResponse + types.ReadableStruct shouldReturnError bool } type fakeRequest struct { - types.IRequest + types.WritableStruct shouldReturnError bool } @@ -100,7 +100,7 @@ func (f *fakeResponse) Read(proto types.Decoder) error { func TestSendMsgError(t *testing.T) { testCases := []struct { proto types.Protocol - request types.IRequest + request types.WritableStruct expected error }{ // Bad WriteMessageBegin @@ -143,7 +143,7 @@ func TestSendMsgError(t *testing.T) { func TestRecvMsgError(t *testing.T) { testCases := []struct { proto types.Protocol - response types.IResponse + response types.ReadableStruct expected error }{ // Error reading message begin diff --git a/third-party/thrift/src/thrift/lib/go/thrift/types/format.go b/third-party/thrift/src/thrift/lib/go/thrift/types/format.go index 8f71aed1d68d1..7f79f04d00290 100644 --- a/third-party/thrift/src/thrift/lib/go/thrift/types/format.go +++ b/third-party/thrift/src/thrift/lib/go/thrift/types/format.go @@ -119,16 +119,6 @@ type Encoder interface { Flush() (err error) } -// IRequest represents a request to be sent to a thrift endpoint -type IRequest interface { - Write(p Encoder) error -} - -// IResponse represents a response received from a thrift call -type IResponse interface { - Read(p Decoder) error -} - // The maximum recursive depth the skip() function will traverse const DEFAULT_RECURSION_DEPTH = 64 diff --git a/third-party/thrift/src/thrift/lib/go/thrift/types/request_channel.go b/third-party/thrift/src/thrift/lib/go/thrift/types/request_channel.go index dafa26f34393f..0e340a43b293f 100644 --- a/third-party/thrift/src/thrift/lib/go/thrift/types/request_channel.go +++ b/third-party/thrift/src/thrift/lib/go/thrift/types/request_channel.go @@ -28,6 +28,6 @@ import "context" type RequestChannel interface { ClientInterface - Call(ctx context.Context, method string, request IRequest, response IResponse) error - Oneway(ctx context.Context, method string, request IRequest) error + Call(ctx context.Context, method string, request WritableStruct, response ReadableStruct) error + Oneway(ctx context.Context, method string, request WritableStruct) error } diff --git a/third-party/thrift/src/thrift/lib/go/thrift/types/serial_channel.go b/third-party/thrift/src/thrift/lib/go/thrift/types/serial_channel.go index a93203847a456..6633c9edfd6f9 100644 --- a/third-party/thrift/src/thrift/lib/go/thrift/types/serial_channel.go +++ b/third-party/thrift/src/thrift/lib/go/thrift/types/serial_channel.go @@ -38,7 +38,7 @@ func NewSerialChannel(protocol Protocol) *SerialChannel { } } -func (c *SerialChannel) sendMsg(ctx context.Context, method string, request IRequest, msgType MessageType) (int32, error) { +func (c *SerialChannel) sendMsg(ctx context.Context, method string, request WritableStruct, msgType MessageType) (int32, error) { c.seqID++ seqID := c.seqID @@ -61,7 +61,7 @@ func (c *SerialChannel) sendMsg(ctx context.Context, method string, request IReq return seqID, c.protocol.Flush() } -func (c *SerialChannel) recvMsg(method string, seqID int32, response IResponse) error { +func (c *SerialChannel) recvMsg(method string, seqID int32, response ReadableStruct) error { // TODO: Implement per-call cancellation for a SerialChannel recvMethod, mTypeID, msgSeqID, err := c.protocol.ReadMessageBegin() @@ -111,7 +111,7 @@ func (c *SerialChannel) Close() error { // Call will call the given method with the given thrift struct, and read the response // into the given response struct. It only allows one outstanding request at once, but is thread-safe. -func (c *SerialChannel) Call(ctx context.Context, method string, request IRequest, response IResponse) error { +func (c *SerialChannel) Call(ctx context.Context, method string, request WritableStruct, response ReadableStruct) error { c.lock.Lock() defer c.lock.Unlock() @@ -130,7 +130,7 @@ func (c *SerialChannel) Call(ctx context.Context, method string, request IReques // Oneway will call the given method with the given thrift struct. It returns immediately when the request is sent. // It only allows one outstanding request at once, but is thread-safe. -func (c *SerialChannel) Oneway(ctx context.Context, method string, request IRequest) error { +func (c *SerialChannel) Oneway(ctx context.Context, method string, request WritableStruct) error { c.lock.Lock() defer c.lock.Unlock() diff --git a/third-party/thrift/src/thrift/lib/go/thrift/types/serializer.go b/third-party/thrift/src/thrift/lib/go/thrift/types/serializer.go index 1ca81375b81e9..66d8dc144f9ba 100644 --- a/third-party/thrift/src/thrift/lib/go/thrift/types/serializer.go +++ b/third-party/thrift/src/thrift/lib/go/thrift/types/serializer.go @@ -16,9 +16,20 @@ package types -// WritableStruct is an interface used to encapsulate a message that can be written to a protocol +// WritableStruct is an interface used to encapsulate a message that can be written to an Encoder type WritableStruct interface { - Write(p Encoder) error + Write(Encoder) error +} + +// ReadableStruct is an interface used to encapsulate a message that can be read from a Decoder +type ReadableStruct interface { + Read(Decoder) error +} + +// Struct is the interface used to encapsulate a message that can be read and written to/from Encoder/Decoder +type Struct interface { + WritableStruct + ReadableStruct } // WritableException is an interface used to encapsulate an exception that can be written to a protocol @@ -32,9 +43,3 @@ type WritableResult interface { WritableStruct Exception() WritableException } - -// Struct is the interface used to encapsulate a message that can be read and written to a protocol -type Struct interface { - Write(p Encoder) error - Read(p Decoder) error -}