8 type TClient interface {
9 Call(ctx context.Context, method string, args, result TStruct) error
12 type TStandardClient struct {
14 iprot, oprot TProtocol
17 // TStandardClient implements TClient, and uses the standard message format for Thrift.
18 // It is not safe for concurrent use.
19 func NewTStandardClient(inputProtocol, outputProtocol TProtocol) *TStandardClient {
20 return &TStandardClient{
22 oprot: outputProtocol,
26 func (p *TStandardClient) Send(ctx context.Context, oprot TProtocol, seqId int32, method string, args TStruct) error {
27 // Set headers from context object on THeaderProtocol
28 if headerProt, ok := oprot.(*THeaderProtocol); ok {
29 headerProt.ClearWriteHeaders()
30 for _, key := range GetWriteHeaderList(ctx) {
31 if value, ok := GetHeader(ctx, key); ok {
32 headerProt.SetWriteHeader(key, value)
37 if err := oprot.WriteMessageBegin(method, CALL, seqId); err != nil {
40 if err := args.Write(oprot); err != nil {
43 if err := oprot.WriteMessageEnd(); err != nil {
46 return oprot.Flush(ctx)
49 func (p *TStandardClient) Recv(iprot TProtocol, seqId int32, method string, result TStruct) error {
50 rMethod, rTypeId, rSeqId, err := iprot.ReadMessageBegin()
55 if method != rMethod {
56 return NewTApplicationException(WRONG_METHOD_NAME, fmt.Sprintf("%s: wrong method name", method))
57 } else if seqId != rSeqId {
58 return NewTApplicationException(BAD_SEQUENCE_ID, fmt.Sprintf("%s: out of order sequence response", method))
59 } else if rTypeId == EXCEPTION {
60 var exception tApplicationException
61 if err := exception.Read(iprot); err != nil {
65 if err := iprot.ReadMessageEnd(); err != nil {
70 } else if rTypeId != REPLY {
71 return NewTApplicationException(INVALID_MESSAGE_TYPE_EXCEPTION, fmt.Sprintf("%s: invalid message type", method))
74 if err := result.Read(iprot); err != nil {
78 return iprot.ReadMessageEnd()
81 func (p *TStandardClient) Call(ctx context.Context, method string, args, result TStruct) error {
85 if err := p.Send(ctx, p.oprot, seqId, method, args); err != nil {
94 return p.Recv(p.iprot, seqId, method, result)