github.com/uber-go/tally/v4@v4.1.17/m3/thrift/v2/m3.go (about)

     1  // Autogenerated by Thrift Compiler (0.9.3)
     2  // DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
     3  
     4  package v2
     5  
     6  import (
     7  	"bytes"
     8  	"fmt"
     9  	"github.com/uber-go/tally/v4/thirdparty/github.com/apache/thrift/lib/go/thrift"
    10  )
    11  
    12  // (needed to ensure safety because of naive import list construction.)
    13  var _ = thrift.ZERO
    14  var _ = fmt.Printf
    15  var _ = bytes.Equal
    16  
    17  type M3 interface {
    18  	// Parameters:
    19  	//  - Batch
    20  	EmitMetricBatchV2(batch MetricBatch) (err error)
    21  }
    22  
    23  type M3Client struct {
    24  	Transport       thrift.TTransport
    25  	ProtocolFactory thrift.TProtocolFactory
    26  	InputProtocol   thrift.TProtocol
    27  	OutputProtocol  thrift.TProtocol
    28  	SeqId           int32
    29  }
    30  
    31  func NewM3ClientFactory(t thrift.TTransport, f thrift.TProtocolFactory) *M3Client {
    32  	return &M3Client{Transport: t,
    33  		ProtocolFactory: f,
    34  		InputProtocol:   f.GetProtocol(t),
    35  		OutputProtocol:  f.GetProtocol(t),
    36  		SeqId:           0,
    37  	}
    38  }
    39  
    40  func NewM3ClientProtocol(t thrift.TTransport, iprot thrift.TProtocol, oprot thrift.TProtocol) *M3Client {
    41  	return &M3Client{Transport: t,
    42  		ProtocolFactory: nil,
    43  		InputProtocol:   iprot,
    44  		OutputProtocol:  oprot,
    45  		SeqId:           0,
    46  	}
    47  }
    48  
    49  // Parameters:
    50  //  - Batch
    51  func (p *M3Client) EmitMetricBatchV2(batch MetricBatch) (err error) {
    52  	if err = p.sendEmitMetricBatchV2(batch); err != nil {
    53  		return
    54  	}
    55  	return
    56  }
    57  
    58  func (p *M3Client) sendEmitMetricBatchV2(batch MetricBatch) (err error) {
    59  	oprot := p.OutputProtocol
    60  	if oprot == nil {
    61  		oprot = p.ProtocolFactory.GetProtocol(p.Transport)
    62  		p.OutputProtocol = oprot
    63  	}
    64  	p.SeqId++
    65  	if err = oprot.WriteMessageBegin("emitMetricBatchV2", thrift.ONEWAY, p.SeqId); err != nil {
    66  		return
    67  	}
    68  	args := M3EmitMetricBatchV2Args{
    69  		Batch: batch,
    70  	}
    71  	if err = args.Write(oprot); err != nil {
    72  		return
    73  	}
    74  	if err = oprot.WriteMessageEnd(); err != nil {
    75  		return
    76  	}
    77  	return oprot.Flush()
    78  }
    79  
    80  type M3Processor struct {
    81  	processorMap map[string]thrift.TProcessorFunction
    82  	handler      M3
    83  }
    84  
    85  func (p *M3Processor) AddToProcessorMap(key string, processor thrift.TProcessorFunction) {
    86  	p.processorMap[key] = processor
    87  }
    88  
    89  func (p *M3Processor) GetProcessorFunction(key string) (processor thrift.TProcessorFunction, ok bool) {
    90  	processor, ok = p.processorMap[key]
    91  	return processor, ok
    92  }
    93  
    94  func (p *M3Processor) ProcessorMap() map[string]thrift.TProcessorFunction {
    95  	return p.processorMap
    96  }
    97  
    98  func NewM3Processor(handler M3) *M3Processor {
    99  
   100  	self3 := &M3Processor{handler: handler, processorMap: make(map[string]thrift.TProcessorFunction)}
   101  	self3.processorMap["emitMetricBatchV2"] = &m3ProcessorEmitMetricBatchV2{handler: handler}
   102  	return self3
   103  }
   104  
   105  func (p *M3Processor) Process(iprot, oprot thrift.TProtocol) (success bool, err thrift.TException) {
   106  	name, _, seqId, err := iprot.ReadMessageBegin()
   107  	if err != nil {
   108  		return false, err
   109  	}
   110  	if processor, ok := p.GetProcessorFunction(name); ok {
   111  		return processor.Process(seqId, iprot, oprot)
   112  	}
   113  	iprot.Skip(thrift.STRUCT)
   114  	iprot.ReadMessageEnd()
   115  	x4 := thrift.NewTApplicationException(thrift.UNKNOWN_METHOD, "Unknown function "+name)
   116  	oprot.WriteMessageBegin(name, thrift.EXCEPTION, seqId)
   117  	x4.Write(oprot)
   118  	oprot.WriteMessageEnd()
   119  	oprot.Flush()
   120  	return false, x4
   121  
   122  }
   123  
   124  type m3ProcessorEmitMetricBatchV2 struct {
   125  	handler M3
   126  }
   127  
   128  func (p *m3ProcessorEmitMetricBatchV2) Process(seqId int32, iprot, oprot thrift.TProtocol) (success bool, err thrift.TException) {
   129  	args := M3EmitMetricBatchV2Args{}
   130  	if err = args.Read(iprot); err != nil {
   131  		iprot.ReadMessageEnd()
   132  		return false, err
   133  	}
   134  
   135  	iprot.ReadMessageEnd()
   136  	var err2 error
   137  	if err2 = p.handler.EmitMetricBatchV2(args.Batch); err2 != nil {
   138  		return true, err2
   139  	}
   140  	return true, nil
   141  }
   142  
   143  // HELPER FUNCTIONS AND STRUCTURES
   144  
   145  // Attributes:
   146  //  - Batch
   147  type M3EmitMetricBatchV2Args struct {
   148  	Batch MetricBatch `thrift:"batch,1" json:"batch"`
   149  }
   150  
   151  func NewM3EmitMetricBatchV2Args() *M3EmitMetricBatchV2Args {
   152  	return &M3EmitMetricBatchV2Args{}
   153  }
   154  
   155  var M3EmitMetricBatchV2Args_Batch_DEFAULT MetricBatch
   156  
   157  func (p *M3EmitMetricBatchV2Args) GetBatch() MetricBatch {
   158  	if !p.IsSetBatch() {
   159  		return M3EmitMetricBatchV2Args_Batch_DEFAULT
   160  	}
   161  	return p.Batch
   162  }
   163  func (p *M3EmitMetricBatchV2Args) IsSetBatch() bool {
   164  	return p.Batch.Metrics != nil || p.Batch.CommonTags != nil
   165  }
   166  
   167  func (p *M3EmitMetricBatchV2Args) Read(iprot thrift.TProtocol) error {
   168  	if _, err := iprot.ReadStructBegin(); err != nil {
   169  		return thrift.PrependError(fmt.Sprintf("%T read error: ", p), err)
   170  	}
   171  
   172  	for {
   173  		_, fieldTypeId, fieldId, err := iprot.ReadFieldBegin()
   174  		if err != nil {
   175  			return thrift.PrependError(fmt.Sprintf("%T field %d read error: ", p, fieldId), err)
   176  		}
   177  		if fieldTypeId == thrift.STOP {
   178  			break
   179  		}
   180  		switch fieldId {
   181  		case 1:
   182  			if err := p.readField1(iprot); err != nil {
   183  				return err
   184  			}
   185  		default:
   186  			if err := iprot.Skip(fieldTypeId); err != nil {
   187  				return err
   188  			}
   189  		}
   190  		if err := iprot.ReadFieldEnd(); err != nil {
   191  			return err
   192  		}
   193  	}
   194  	if err := iprot.ReadStructEnd(); err != nil {
   195  		return thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err)
   196  	}
   197  	return nil
   198  }
   199  
   200  func (p *M3EmitMetricBatchV2Args) readField1(iprot thrift.TProtocol) error {
   201  	p.Batch = MetricBatch{}
   202  	if err := p.Batch.Read(iprot); err != nil {
   203  		return thrift.PrependError(fmt.Sprintf("%T error reading struct: ", p.Batch), err)
   204  	}
   205  	return nil
   206  }
   207  
   208  func (p *M3EmitMetricBatchV2Args) Write(oprot thrift.TProtocol) error {
   209  	if err := oprot.WriteStructBegin("emitMetricBatchV2_args"); err != nil {
   210  		return thrift.PrependError(fmt.Sprintf("%T write struct begin error: ", p), err)
   211  	}
   212  	if err := p.writeField1(oprot); err != nil {
   213  		return err
   214  	}
   215  	if err := oprot.WriteFieldStop(); err != nil {
   216  		return thrift.PrependError("write field stop error: ", err)
   217  	}
   218  	if err := oprot.WriteStructEnd(); err != nil {
   219  		return thrift.PrependError("write struct stop error: ", err)
   220  	}
   221  	return nil
   222  }
   223  
   224  func (p *M3EmitMetricBatchV2Args) writeField1(oprot thrift.TProtocol) (err error) {
   225  	if err := oprot.WriteFieldBegin("batch", thrift.STRUCT, 1); err != nil {
   226  		return thrift.PrependError(fmt.Sprintf("%T write field begin error 1:batch: ", p), err)
   227  	}
   228  	if err := p.Batch.Write(oprot); err != nil {
   229  		return thrift.PrependError(fmt.Sprintf("%T error writing struct: ", p.Batch), err)
   230  	}
   231  	if err := oprot.WriteFieldEnd(); err != nil {
   232  		return thrift.PrependError(fmt.Sprintf("%T write field end error 1:batch: ", p), err)
   233  	}
   234  	return err
   235  }
   236  
   237  func (p *M3EmitMetricBatchV2Args) String() string {
   238  	if p == nil {
   239  		return "<nil>"
   240  	}
   241  	return fmt.Sprintf("M3EmitMetricBatchV2Args(%+v)", *p)
   242  }