// Autogenerated by Thrift Compiler (0.9.3)
// DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING

package v2

import (
	"bytes"
	"fmt"
	"github.com/uber-go/tally/v4/thirdparty/github.com/apache/thrift/lib/go/thrift"
)

// (needed to ensure safety because of naive import list construction.)
var _ = thrift.ZERO
var _ = fmt.Printf
var _ = bytes.Equal

var GoUnusedProtection__ int

type MetricType int64

const (
	MetricType_INVALID MetricType = 0
	MetricType_COUNTER MetricType = 1
	MetricType_GAUGE   MetricType = 2
	MetricType_TIMER   MetricType = 3
)

func (p MetricType) String() string {
	switch p {
	case MetricType_INVALID:
		return "INVALID"
	case MetricType_COUNTER:
		return "COUNTER"
	case MetricType_GAUGE:
		return "GAUGE"
	case MetricType_TIMER:
		return "TIMER"
	}
	return "<UNSET>"
}

func MetricTypeFromString(s string) (MetricType, error) {
	switch s {
	case "INVALID":
		return MetricType_INVALID, nil
	case "COUNTER":
		return MetricType_COUNTER, nil
	case "GAUGE":
		return MetricType_GAUGE, nil
	case "TIMER":
		return MetricType_TIMER, nil
	}
	return MetricType(0), fmt.Errorf("not a valid MetricType string")
}

func MetricTypePtr(v MetricType) *MetricType { return &v }

func (p MetricType) MarshalText() ([]byte, error) {
	return []byte(p.String()), nil
}

func (p *MetricType) UnmarshalText(text []byte) error {
	q, err := MetricTypeFromString(string(text))
	if err != nil {
		return err
	}
	*p = q
	return nil
}

// Attributes:
//  - MetricType
//  - Count
//  - Gauge
//  - Timer
type MetricValue struct {
	MetricType MetricType `thrift:"metricType,1,required" json:"metricType"`
	Count      int64      `thrift:"count,2,required" json:"count"`
	Gauge      float64    `thrift:"gauge,3,required" json:"gauge"`
	Timer      int64      `thrift:"timer,4,required" json:"timer"`
}

func NewMetricValue() *MetricValue {
	return &MetricValue{}
}

func (p *MetricValue) GetMetricType() MetricType {
	return p.MetricType
}

func (p *MetricValue) GetCount() int64 {
	return p.Count
}

func (p *MetricValue) GetGauge() float64 {
	return p.Gauge
}

func (p *MetricValue) GetTimer() int64 {
	return p.Timer
}
func (p *MetricValue) Read(iprot thrift.TProtocol) error {
	if _, err := iprot.ReadStructBegin(); err != nil {
		return thrift.PrependError(fmt.Sprintf("%T read error: ", p), err)
	}

	var issetMetricType bool = false
	var issetCount bool = false
	var issetGauge bool = false
	var issetTimer bool = false

	for {
		_, fieldTypeId, fieldId, err := iprot.ReadFieldBegin()
		if err != nil {
			return thrift.PrependError(fmt.Sprintf("%T field %d read error: ", p, fieldId), err)
		}
		if fieldTypeId == thrift.STOP {
			break
		}
		switch fieldId {
		case 1:
			if err := p.readField1(iprot); err != nil {
				return err
			}
			issetMetricType = true
		case 2:
			if err := p.readField2(iprot); err != nil {
				return err
			}
			issetCount = true
		case 3:
			if err := p.readField3(iprot); err != nil {
				return err
			}
			issetGauge = true
		case 4:
			if err := p.readField4(iprot); err != nil {
				return err
			}
			issetTimer = true
		default:
			if err := iprot.Skip(fieldTypeId); err != nil {
				return err
			}
		}
		if err := iprot.ReadFieldEnd(); err != nil {
			return err
		}
	}
	if err := iprot.ReadStructEnd(); err != nil {
		return thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err)
	}
	if !issetMetricType {
		return thrift.NewTProtocolExceptionWithType(thrift.INVALID_DATA, fmt.Errorf("Required field MetricType is not set"))
	}
	if !issetCount {
		return thrift.NewTProtocolExceptionWithType(thrift.INVALID_DATA, fmt.Errorf("Required field Count is not set"))
	}
	if !issetGauge {
		return thrift.NewTProtocolExceptionWithType(thrift.INVALID_DATA, fmt.Errorf("Required field Gauge is not set"))
	}
	if !issetTimer {
		return thrift.NewTProtocolExceptionWithType(thrift.INVALID_DATA, fmt.Errorf("Required field Timer is not set"))
	}
	return nil
}

func (p *MetricValue) readField1(iprot thrift.TProtocol) error {
	if v, err := iprot.ReadI32(); err != nil {
		return thrift.PrependError("error reading field 1: ", err)
	} else {
		temp := MetricType(v)
		p.MetricType = temp
	}
	return nil
}

func (p *MetricValue) readField2(iprot thrift.TProtocol) error {
	if v, err := iprot.ReadI64(); err != nil {
		return thrift.PrependError("error reading field 2: ", err)
	} else {
		p.Count = v
	}
	return nil
}

func (p *MetricValue) readField3(iprot thrift.TProtocol) error {
	if v, err := iprot.ReadDouble(); err != nil {
		return thrift.PrependError("error reading field 3: ", err)
	} else {
		p.Gauge = v
	}
	return nil
}

func (p *MetricValue) readField4(iprot thrift.TProtocol) error {
	if v, err := iprot.ReadI64(); err != nil {
		return thrift.PrependError("error reading field 4: ", err)
	} else {
		p.Timer = v
	}
	return nil
}

func (p *MetricValue) Write(oprot thrift.TProtocol) error {
	if err := oprot.WriteStructBegin("MetricValue"); err != nil {
		return thrift.PrependError(fmt.Sprintf("%T write struct begin error: ", p), err)
	}
	if err := p.writeField1(oprot); err != nil {
		return err
	}
	if err := p.writeField2(oprot); err != nil {
		return err
	}
	if err := p.writeField3(oprot); err != nil {
		return err
	}
	if err := p.writeField4(oprot); err != nil {
		return err
	}
	if err := oprot.WriteFieldStop(); err != nil {
		return thrift.PrependError("write field stop error: ", err)
	}
	if err := oprot.WriteStructEnd(); err != nil {
		return thrift.PrependError("write struct stop error: ", err)
	}
	return nil
}

func (p *MetricValue) writeField1(oprot thrift.TProtocol) (err error) {
	if err := oprot.WriteFieldBegin("metricType", thrift.I32, 1); err != nil {
		return thrift.PrependError(fmt.Sprintf("%T write field begin error 1:metricType: ", p), err)
	}
	if err := oprot.WriteI32(int32(p.MetricType)); err != nil {
		return thrift.PrependError(fmt.Sprintf("%T.metricType (1) field write error: ", p), err)
	}
	if err := oprot.WriteFieldEnd(); err != nil {
		return thrift.PrependError(fmt.Sprintf("%T write field end error 1:metricType: ", p), err)
	}
	return err
}

func (p *MetricValue) writeField2(oprot thrift.TProtocol) (err error) {
	if err := oprot.WriteFieldBegin("count", thrift.I64, 2); err != nil {
		return thrift.PrependError(fmt.Sprintf("%T write field begin error 2:count: ", p), err)
	}
	if err := oprot.WriteI64(int64(p.Count)); err != nil {
		return thrift.PrependError(fmt.Sprintf("%T.count (2) field write error: ", p), err)
	}
	if err := oprot.WriteFieldEnd(); err != nil {
		return thrift.PrependError(fmt.Sprintf("%T write field end error 2:count: ", p), err)
	}
	return err
}

func (p *MetricValue) writeField3(oprot thrift.TProtocol) (err error) {
	if err := oprot.WriteFieldBegin("gauge", thrift.DOUBLE, 3); err != nil {
		return thrift.PrependError(fmt.Sprintf("%T write field begin error 3:gauge: ", p), err)
	}
	if err := oprot.WriteDouble(float64(p.Gauge)); err != nil {
		return thrift.PrependError(fmt.Sprintf("%T.gauge (3) field write error: ", p), err)
	}
	if err := oprot.WriteFieldEnd(); err != nil {
		return thrift.PrependError(fmt.Sprintf("%T write field end error 3:gauge: ", p), err)
	}
	return err
}

func (p *MetricValue) writeField4(oprot thrift.TProtocol) (err error) {
	if err := oprot.WriteFieldBegin("timer", thrift.I64, 4); err != nil {
		return thrift.PrependError(fmt.Sprintf("%T write field begin error 4:timer: ", p), err)
	}
	if err := oprot.WriteI64(int64(p.Timer)); err != nil {
		return thrift.PrependError(fmt.Sprintf("%T.timer (4) field write error: ", p), err)
	}
	if err := oprot.WriteFieldEnd(); err != nil {
		return thrift.PrependError(fmt.Sprintf("%T write field end error 4:timer: ", p), err)
	}
	return err
}

func (p *MetricValue) String() string {
	if p == nil {
		return "<nil>"
	}
	return fmt.Sprintf("MetricValue(%+v)", *p)
}

// Attributes:
//  - Name
//  - Value
type MetricTag struct {
	Name  string `thrift:"name,1,required" json:"name"`
	Value string `thrift:"value,2,required" json:"value"`
}

func NewMetricTag() *MetricTag {
	return &MetricTag{}
}

func (p *MetricTag) GetName() string {
	return p.Name
}

func (p *MetricTag) GetValue() string {
	return p.Value
}
func (p *MetricTag) Read(iprot thrift.TProtocol) error {
	if _, err := iprot.ReadStructBegin(); err != nil {
		return thrift.PrependError(fmt.Sprintf("%T read error: ", p), err)
	}

	var issetName bool = false
	var issetValue bool = false

	for {
		_, fieldTypeId, fieldId, err := iprot.ReadFieldBegin()
		if err != nil {
			return thrift.PrependError(fmt.Sprintf("%T field %d read error: ", p, fieldId), err)
		}
		if fieldTypeId == thrift.STOP {
			break
		}
		switch fieldId {
		case 1:
			if err := p.readField1(iprot); err != nil {
				return err
			}
			issetName = true
		case 2:
			if err := p.readField2(iprot); err != nil {
				return err
			}
			issetValue = true
		default:
			if err := iprot.Skip(fieldTypeId); err != nil {
				return err
			}
		}
		if err := iprot.ReadFieldEnd(); err != nil {
			return err
		}
	}
	if err := iprot.ReadStructEnd(); err != nil {
		return thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err)
	}
	if !issetName {
		return thrift.NewTProtocolExceptionWithType(thrift.INVALID_DATA, fmt.Errorf("Required field Name is not set"))
	}
	if !issetValue {
		return thrift.NewTProtocolExceptionWithType(thrift.INVALID_DATA, fmt.Errorf("Required field Value is not set"))
	}
	return nil
}

func (p *MetricTag) readField1(iprot thrift.TProtocol) error {
	if v, err := iprot.ReadString(); err != nil {
		return thrift.PrependError("error reading field 1: ", err)
	} else {
		p.Name = v
	}
	return nil
}

func (p *MetricTag) readField2(iprot thrift.TProtocol) error {
	if v, err := iprot.ReadString(); err != nil {
		return thrift.PrependError("error reading field 2: ", err)
	} else {
		p.Value = v
	}
	return nil
}

func (p *MetricTag) Write(oprot thrift.TProtocol) error {
	if err := oprot.WriteStructBegin("MetricTag"); err != nil {
		return thrift.PrependError(fmt.Sprintf("%T write struct begin error: ", p), err)
	}
	if err := p.writeField1(oprot); err != nil {
		return err
	}
	if err := p.writeField2(oprot); err != nil {
		return err
	}
	if err := oprot.WriteFieldStop(); err != nil {
		return thrift.PrependError("write field stop error: ", err)
	}
	if err := oprot.WriteStructEnd(); err != nil {
		return thrift.PrependError("write struct stop error: ", err)
	}
	return nil
}

func (p *MetricTag) writeField1(oprot thrift.TProtocol) (err error) {
	if err := oprot.WriteFieldBegin("name", thrift.STRING, 1); err != nil {
		return thrift.PrependError(fmt.Sprintf("%T write field begin error 1:name: ", p), err)
	}
	if err := oprot.WriteString(string(p.Name)); err != nil {
		return thrift.PrependError(fmt.Sprintf("%T.name (1) field write error: ", p), err)
	}
	if err := oprot.WriteFieldEnd(); err != nil {
		return thrift.PrependError(fmt.Sprintf("%T write field end error 1:name: ", p), err)
	}
	return err
}

func (p *MetricTag) writeField2(oprot thrift.TProtocol) (err error) {
	if err := oprot.WriteFieldBegin("value", thrift.STRING, 2); err != nil {
		return thrift.PrependError(fmt.Sprintf("%T write field begin error 2:value: ", p), err)
	}
	if err := oprot.WriteString(string(p.Value)); err != nil {
		return thrift.PrependError(fmt.Sprintf("%T.value (2) field write error: ", p), err)
	}
	if err := oprot.WriteFieldEnd(); err != nil {
		return thrift.PrependError(fmt.Sprintf("%T write field end error 2:value: ", p), err)
	}
	return err
}

func (p *MetricTag) String() string {
	if p == nil {
		return "<nil>"
	}
	return fmt.Sprintf("MetricTag(%+v)", *p)
}

// Attributes:
//  - Name
//  - Value
//  - Timestamp
//  - Tags
type Metric struct {
	Name      string      `thrift:"name,1,required" json:"name"`
	Value     MetricValue `thrift:"value,2,required" json:"value"`
	Timestamp int64       `thrift:"timestamp,3,required" json:"timestamp"`
	Tags      []MetricTag `thrift:"tags,4" json:"tags,omitempty"`
}

func NewMetric() *Metric {
	return &Metric{}
}

func (p *Metric) GetName() string {
	return p.Name
}

var Metric_Value_DEFAULT MetricValue

func (p *Metric) GetValue() MetricValue {
	if !p.IsSetValue() {
		return Metric_Value_DEFAULT
	}
	return p.Value
}

func (p *Metric) GetTimestamp() int64 {
	return p.Timestamp
}

var Metric_Tags_DEFAULT []MetricTag

func (p *Metric) GetTags() []MetricTag {
	return p.Tags
}
func (p *Metric) IsSetValue() bool {
	return p.Value.GetMetricType() != MetricType_INVALID || p.Value.Count != 0 || p.Value.Gauge != 0 || p.Value.Timer != 0
}

func (p *Metric) IsSetTags() bool {
	return p.Tags != nil
}

func (p *Metric) Read(iprot thrift.TProtocol) error {
	if _, err := iprot.ReadStructBegin(); err != nil {
		return thrift.PrependError(fmt.Sprintf("%T read error: ", p), err)
	}

	var issetName bool = false
	var issetValue bool = false
	var issetTimestamp bool = false

	for {
		_, fieldTypeId, fieldId, err := iprot.ReadFieldBegin()
		if err != nil {
			return thrift.PrependError(fmt.Sprintf("%T field %d read error: ", p, fieldId), err)
		}
		if fieldTypeId == thrift.STOP {
			break
		}
		switch fieldId {
		case 1:
			if err := p.readField1(iprot); err != nil {
				return err
			}
			issetName = true
		case 2:
			if err := p.readField2(iprot); err != nil {
				return err
			}
			issetValue = true
		case 3:
			if err := p.readField3(iprot); err != nil {
				return err
			}
			issetTimestamp = true
		case 4:
			if err := p.readField4(iprot); err != nil {
				return err
			}
		default:
			if err := iprot.Skip(fieldTypeId); err != nil {
				return err
			}
		}
		if err := iprot.ReadFieldEnd(); err != nil {
			return err
		}
	}
	if err := iprot.ReadStructEnd(); err != nil {
		return thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err)
	}
	if !issetName {
		return thrift.NewTProtocolExceptionWithType(thrift.INVALID_DATA, fmt.Errorf("Required field Name is not set"))
	}
	if !issetValue {
		return thrift.NewTProtocolExceptionWithType(thrift.INVALID_DATA, fmt.Errorf("Required field Value is not set"))
	}
	if !issetTimestamp {
		return thrift.NewTProtocolExceptionWithType(thrift.INVALID_DATA, fmt.Errorf("Required field Timestamp is not set"))
	}
	return nil
}

func (p *Metric) readField1(iprot thrift.TProtocol) error {
	if v, err := iprot.ReadString(); err != nil {
		return thrift.PrependError("error reading field 1: ", err)
	} else {
		p.Name = v
	}
	return nil
}

func (p *Metric) readField2(iprot thrift.TProtocol) error {
	p.Value = MetricValue{}
	if err := p.Value.Read(iprot); err != nil {
		return thrift.PrependError(fmt.Sprintf("%T error reading struct: ", p.Value), err)
	}
	return nil
}

func (p *Metric) readField3(iprot thrift.TProtocol) error {
	if v, err := iprot.ReadI64(); err != nil {
		return thrift.PrependError("error reading field 3: ", err)
	} else {
		p.Timestamp = v
	}
	return nil
}

func (p *Metric) readField4(iprot thrift.TProtocol) error {
	_, size, err := iprot.ReadListBegin()
	if err != nil {
		return thrift.PrependError("error reading list begin: ", err)
	}
	tSlice := make([]MetricTag, 0, size)
	p.Tags = tSlice
	for i := 0; i < size; i++ {
		_elem0 := MetricTag{}
		if err := _elem0.Read(iprot); err != nil {
			return thrift.PrependError(fmt.Sprintf("%T error reading struct: ", _elem0), err)
		}
		p.Tags = append(p.Tags, _elem0)
	}
	if err := iprot.ReadListEnd(); err != nil {
		return thrift.PrependError("error reading list end: ", err)
	}
	return nil
}

func (p *Metric) Write(oprot thrift.TProtocol) error {
	if err := oprot.WriteStructBegin("Metric"); err != nil {
		return thrift.PrependError(fmt.Sprintf("%T write struct begin error: ", p), err)
	}
	if err := p.writeField1(oprot); err != nil {
		return err
	}
	if err := p.writeField2(oprot); err != nil {
		return err
	}
	if err := p.writeField3(oprot); err != nil {
		return err
	}
	if err := p.writeField4(oprot); err != nil {
		return err
	}
	if err := oprot.WriteFieldStop(); err != nil {
		return thrift.PrependError("write field stop error: ", err)
	}
	if err := oprot.WriteStructEnd(); err != nil {
		return thrift.PrependError("write struct stop error: ", err)
	}
	return nil
}

func (p *Metric) writeField1(oprot thrift.TProtocol) (err error) {
	if err := oprot.WriteFieldBegin("name", thrift.STRING, 1); err != nil {
		return thrift.PrependError(fmt.Sprintf("%T write field begin error 1:name: ", p), err)
	}
	if err := oprot.WriteString(string(p.Name)); err != nil {
		return thrift.PrependError(fmt.Sprintf("%T.name (1) field write error: ", p), err)
	}
	if err := oprot.WriteFieldEnd(); err != nil {
		return thrift.PrependError(fmt.Sprintf("%T write field end error 1:name: ", p), err)
	}
	return err
}

func (p *Metric) writeField2(oprot thrift.TProtocol) (err error) {
	if err := oprot.WriteFieldBegin("value", thrift.STRUCT, 2); err != nil {
		return thrift.PrependError(fmt.Sprintf("%T write field begin error 2:value: ", p), err)
	}
	if err := p.Value.Write(oprot); err != nil {
		return thrift.PrependError(fmt.Sprintf("%T error writing struct: ", p.Value), err)
	}
	if err := oprot.WriteFieldEnd(); err != nil {
		return thrift.PrependError(fmt.Sprintf("%T write field end error 2:value: ", p), err)
	}
	return err
}

func (p *Metric) writeField3(oprot thrift.TProtocol) (err error) {
	if err := oprot.WriteFieldBegin("timestamp", thrift.I64, 3); err != nil {
		return thrift.PrependError(fmt.Sprintf("%T write field begin error 3:timestamp: ", p), err)
	}
	if err := oprot.WriteI64(int64(p.Timestamp)); err != nil {
		return thrift.PrependError(fmt.Sprintf("%T.timestamp (3) field write error: ", p), err)
	}
	if err := oprot.WriteFieldEnd(); err != nil {
		return thrift.PrependError(fmt.Sprintf("%T write field end error 3:timestamp: ", p), err)
	}
	return err
}

func (p *Metric) writeField4(oprot thrift.TProtocol) (err error) {
	if p.IsSetTags() {
		if err := oprot.WriteFieldBegin("tags", thrift.LIST, 4); err != nil {
			return thrift.PrependError(fmt.Sprintf("%T write field begin error 4:tags: ", p), err)
		}
		if err := oprot.WriteListBegin(thrift.STRUCT, len(p.Tags)); err != nil {
			return thrift.PrependError("error writing list begin: ", err)
		}
		for _, v := range p.Tags {
			if err := v.Write(oprot); err != nil {
				return thrift.PrependError(fmt.Sprintf("%T error writing struct: ", v), err)
			}
		}
		if err := oprot.WriteListEnd(); err != nil {
			return thrift.PrependError("error writing list end: ", err)
		}
		if err := oprot.WriteFieldEnd(); err != nil {
			return thrift.PrependError(fmt.Sprintf("%T write field end error 4:tags: ", p), err)
		}
	}
	return err
}

func (p *Metric) String() string {
	if p == nil {
		return "<nil>"
	}
	return fmt.Sprintf("Metric(%+v)", *p)
}

// Attributes:
//  - Metrics
//  - CommonTags
type MetricBatch struct {
	Metrics    []Metric    `thrift:"metrics,1,required" json:"metrics"`
	CommonTags []MetricTag `thrift:"commonTags,2" json:"commonTags,omitempty"`
}

func NewMetricBatch() *MetricBatch {
	return &MetricBatch{}
}

func (p *MetricBatch) GetMetrics() []Metric {
	return p.Metrics
}

var MetricBatch_CommonTags_DEFAULT []MetricTag

func (p *MetricBatch) GetCommonTags() []MetricTag {
	return p.CommonTags
}
func (p *MetricBatch) IsSetCommonTags() bool {
	return p.CommonTags != nil
}

func (p *MetricBatch) Read(iprot thrift.TProtocol) error {
	if _, err := iprot.ReadStructBegin(); err != nil {
		return thrift.PrependError(fmt.Sprintf("%T read error: ", p), err)
	}

	var issetMetrics bool = false

	for {
		_, fieldTypeId, fieldId, err := iprot.ReadFieldBegin()
		if err != nil {
			return thrift.PrependError(fmt.Sprintf("%T field %d read error: ", p, fieldId), err)
		}
		if fieldTypeId == thrift.STOP {
			break
		}
		switch fieldId {
		case 1:
			if err := p.readField1(iprot); err != nil {
				return err
			}
			issetMetrics = true
		case 2:
			if err := p.readField2(iprot); err != nil {
				return err
			}
		default:
			if err := iprot.Skip(fieldTypeId); err != nil {
				return err
			}
		}
		if err := iprot.ReadFieldEnd(); err != nil {
			return err
		}
	}
	if err := iprot.ReadStructEnd(); err != nil {
		return thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err)
	}
	if !issetMetrics {
		return thrift.NewTProtocolExceptionWithType(thrift.INVALID_DATA, fmt.Errorf("Required field Metrics is not set"))
	}
	return nil
}

func (p *MetricBatch) readField1(iprot thrift.TProtocol) error {
	_, size, err := iprot.ReadListBegin()
	if err != nil {
		return thrift.PrependError("error reading list begin: ", err)
	}
	tSlice := make([]Metric, 0, size)
	p.Metrics = tSlice
	for i := 0; i < size; i++ {
		_elem1 := Metric{}
		if err := _elem1.Read(iprot); err != nil {
			return thrift.PrependError(fmt.Sprintf("%T error reading struct: ", _elem1), err)
		}
		p.Metrics = append(p.Metrics, _elem1)
	}
	if err := iprot.ReadListEnd(); err != nil {
		return thrift.PrependError("error reading list end: ", err)
	}
	return nil
}

func (p *MetricBatch) readField2(iprot thrift.TProtocol) error {
	_, size, err := iprot.ReadListBegin()
	if err != nil {
		return thrift.PrependError("error reading list begin: ", err)
	}
	tSlice := make([]MetricTag, 0, size)
	p.CommonTags = tSlice
	for i := 0; i < size; i++ {
		_elem2 := MetricTag{}
		if err := _elem2.Read(iprot); err != nil {
			return thrift.PrependError(fmt.Sprintf("%T error reading struct: ", _elem2), err)
		}
		p.CommonTags = append(p.CommonTags, _elem2)
	}
	if err := iprot.ReadListEnd(); err != nil {
		return thrift.PrependError("error reading list end: ", err)
	}
	return nil
}

func (p *MetricBatch) Write(oprot thrift.TProtocol) error {
	if err := oprot.WriteStructBegin("MetricBatch"); err != nil {
		return thrift.PrependError(fmt.Sprintf("%T write struct begin error: ", p), err)
	}
	if err := p.writeField1(oprot); err != nil {
		return err
	}
	if err := p.writeField2(oprot); err != nil {
		return err
	}
	if err := oprot.WriteFieldStop(); err != nil {
		return thrift.PrependError("write field stop error: ", err)
	}
	if err := oprot.WriteStructEnd(); err != nil {
		return thrift.PrependError("write struct stop error: ", err)
	}
	return nil
}

func (p *MetricBatch) writeField1(oprot thrift.TProtocol) (err error) {
	if err := oprot.WriteFieldBegin("metrics", thrift.LIST, 1); err != nil {
		return thrift.PrependError(fmt.Sprintf("%T write field begin error 1:metrics: ", p), err)
	}
	if err := oprot.WriteListBegin(thrift.STRUCT, len(p.Metrics)); err != nil {
		return thrift.PrependError("error writing list begin: ", err)
	}
	for _, v := range p.Metrics {
		if err := v.Write(oprot); err != nil {
			return thrift.PrependError(fmt.Sprintf("%T error writing struct: ", v), err)
		}
	}
	if err := oprot.WriteListEnd(); err != nil {
		return thrift.PrependError("error writing list end: ", err)
	}
	if err := oprot.WriteFieldEnd(); err != nil {
		return thrift.PrependError(fmt.Sprintf("%T write field end error 1:metrics: ", p), err)
	}
	return err
}

func (p *MetricBatch) writeField2(oprot thrift.TProtocol) (err error) {
	if p.IsSetCommonTags() {
		if err := oprot.WriteFieldBegin("commonTags", thrift.LIST, 2); err != nil {
			return thrift.PrependError(fmt.Sprintf("%T write field begin error 2:commonTags: ", p), err)
		}
		if err := oprot.WriteListBegin(thrift.STRUCT, len(p.CommonTags)); err != nil {
			return thrift.PrependError("error writing list begin: ", err)
		}
		for _, v := range p.CommonTags {
			if err := v.Write(oprot); err != nil {
				return thrift.PrependError(fmt.Sprintf("%T error writing struct: ", v), err)
			}
		}
		if err := oprot.WriteListEnd(); err != nil {
			return thrift.PrependError("error writing list end: ", err)
		}
		if err := oprot.WriteFieldEnd(); err != nil {
			return thrift.PrependError(fmt.Sprintf("%T write field end error 2:commonTags: ", p), err)
		}
	}
	return err
}

func (p *MetricBatch) String() string {
	if p == nil {
		return "<nil>"
	}
	return fmt.Sprintf("MetricBatch(%+v)", *p)
}
