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