#
# Autogenerated by Thrift
#
# DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
#

from thrift.Thrift import *

from thrift.transport import TTransport
from thrift.protocol import TBinaryProtocol
try:
  from thrift.protocol import fastbinary
except:
  fastbinary = None


class EventType:
  CLIENT_SEND = 1
  CLIENT_RECV = 2
  SERVER_SEND = 3
  SERVER_RECV = 4
  CUSTOM = 5

  _VALUES_TO_NAMES = {
    1: "CLIENT_SEND",
    2: "CLIENT_RECV",
    3: "SERVER_SEND",
    4: "SERVER_RECV",
    5: "CUSTOM",
  }

  _NAMES_TO_VALUES = {
    "CLIENT_SEND": 1,
    "CLIENT_RECV": 2,
    "SERVER_SEND": 3,
    "SERVER_RECV": 4,
    "CUSTOM": 5,
  }

class ResultCode:
  OK = 0
  TRY_LATER = 1

  _VALUES_TO_NAMES = {
    0: "OK",
    1: "TRY_LATER",
  }

  _NAMES_TO_VALUES = {
    "OK": 0,
    "TRY_LATER": 1,
  }


class Event:
  """
  Attributes:
   - timestamp
   - event_type
   - value
  """

  thrift_spec = (
    None, # 0
    (1, TType.I64, 'timestamp', None, None, ), # 1
    (2, TType.I32, 'event_type', None, None, ), # 2
    (3, TType.STRING, 'value', None, None, ), # 3
  )

  def __init__(self, timestamp=None, event_type=None, value=None,):
    self.timestamp = timestamp
    self.event_type = event_type
    self.value = value

  def read(self, iprot):
    if iprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and isinstance(iprot.trans, TTransport.CReadableTransport) and self.thrift_spec is not None and fastbinary is not None:
      fastbinary.decode_binary(self, iprot.trans, (self.__class__, self.thrift_spec))
      return
    iprot.readStructBegin()
    while True:
      (fname, ftype, fid) = iprot.readFieldBegin()
      if ftype == TType.STOP:
        break
      if fid == 1:
        if ftype == TType.I64:
          self.timestamp = iprot.readI64();
        else:
          iprot.skip(ftype)
      elif fid == 2:
        if ftype == TType.I32:
          self.event_type = iprot.readI32();
        else:
          iprot.skip(ftype)
      elif fid == 3:
        if ftype == TType.STRING:
          self.value = iprot.readString();
        else:
          iprot.skip(ftype)
      else:
        iprot.skip(ftype)
      iprot.readFieldEnd()
    iprot.readStructEnd()

  def write(self, oprot):
    if oprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and self.thrift_spec is not None and fastbinary is not None:
      oprot.trans.write(fastbinary.encode_binary(self, (self.__class__, self.thrift_spec)))
      return
    oprot.writeStructBegin('Event')
    if self.timestamp != None:
      oprot.writeFieldBegin('timestamp', TType.I64, 1)
      oprot.writeI64(self.timestamp)
      oprot.writeFieldEnd()
    if self.event_type != None:
      oprot.writeFieldBegin('event_type', TType.I32, 2)
      oprot.writeI32(self.event_type)
      oprot.writeFieldEnd()
    if self.value != None:
      oprot.writeFieldBegin('value', TType.STRING, 3)
      oprot.writeString(self.value)
      oprot.writeFieldEnd()
    oprot.writeFieldStop()
    oprot.writeStructEnd()

  def __repr__(self):
    L = ['%s=%r' % (key, value)
      for key, value in self.__dict__.iteritems()]
    return '%s(%s)' % (self.__class__.__name__, ', '.join(L))

  def __eq__(self, other):
    return isinstance(other, self.__class__) and self.__dict__ == other.__dict__

  def __ne__(self, other):
    return not (self == other)

class Span:
  """
  Attributes:
   - trace_id
   - name
   - id
   - parent_id
   - client_host
   - server_host
   - events
   - annotations
   - counters
  """

  thrift_spec = (
    None, # 0
    (1, TType.I64, 'trace_id', None, None, ), # 1
    (2, TType.STRING, 'name', None, None, ), # 2
    (3, TType.I64, 'id', None, None, ), # 3
    (4, TType.I64, 'parent_id', None, None, ), # 4
    (5, TType.STRING, 'client_host', None, None, ), # 5
    (6, TType.STRING, 'server_host', None, None, ), # 6
    (7, TType.LIST, 'events', (TType.STRUCT,(Event, Event.thrift_spec)), None, ), # 7
    (8, TType.MAP, 'annotations', (TType.STRING,None,TType.STRING,None), None, ), # 8
    (9, TType.MAP, 'counters', (TType.STRING,None,TType.I64,None), None, ), # 9
  )

  def __init__(self, trace_id=None, name=None, id=None, parent_id=None, client_host=None, server_host=None, events=None, annotations=None, counters=None,):
    self.trace_id = trace_id
    self.name = name
    self.id = id
    self.parent_id = parent_id
    self.client_host = client_host
    self.server_host = server_host
    self.events = events
    self.annotations = annotations
    self.counters = counters

  def read(self, iprot):
    if iprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and isinstance(iprot.trans, TTransport.CReadableTransport) and self.thrift_spec is not None and fastbinary is not None:
      fastbinary.decode_binary(self, iprot.trans, (self.__class__, self.thrift_spec))
      return
    iprot.readStructBegin()
    while True:
      (fname, ftype, fid) = iprot.readFieldBegin()
      if ftype == TType.STOP:
        break
      if fid == 1:
        if ftype == TType.I64:
          self.trace_id = iprot.readI64();
        else:
          iprot.skip(ftype)
      elif fid == 2:
        if ftype == TType.STRING:
          self.name = iprot.readString();
        else:
          iprot.skip(ftype)
      elif fid == 3:
        if ftype == TType.I64:
          self.id = iprot.readI64();
        else:
          iprot.skip(ftype)
      elif fid == 4:
        if ftype == TType.I64:
          self.parent_id = iprot.readI64();
        else:
          iprot.skip(ftype)
      elif fid == 5:
        if ftype == TType.STRING:
          self.client_host = iprot.readString();
        else:
          iprot.skip(ftype)
      elif fid == 6:
        if ftype == TType.STRING:
          self.server_host = iprot.readString();
        else:
          iprot.skip(ftype)
      elif fid == 7:
        if ftype == TType.LIST:
          self.events = []
          (_etype3, _size0) = iprot.readListBegin()
          for _i4 in xrange(_size0):
            _elem5 = Event()
            _elem5.read(iprot)
            self.events.append(_elem5)
          iprot.readListEnd()
        else:
          iprot.skip(ftype)
      elif fid == 8:
        if ftype == TType.MAP:
          self.annotations = {}
          (_ktype7, _vtype8, _size6 ) = iprot.readMapBegin()
          for _i10 in xrange(_size6):
            _key11 = iprot.readString();
            _val12 = iprot.readString();
            self.annotations[_key11] = _val12
          iprot.readMapEnd()
        else:
          iprot.skip(ftype)
      elif fid == 9:
        if ftype == TType.MAP:
          self.counters = {}
          (_ktype14, _vtype15, _size13 ) = iprot.readMapBegin()
          for _i17 in xrange(_size13):
            _key18 = iprot.readString();
            _val19 = iprot.readI64();
            self.counters[_key18] = _val19
          iprot.readMapEnd()
        else:
          iprot.skip(ftype)
      else:
        iprot.skip(ftype)
      iprot.readFieldEnd()
    iprot.readStructEnd()

  def write(self, oprot):
    if oprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and self.thrift_spec is not None and fastbinary is not None:
      oprot.trans.write(fastbinary.encode_binary(self, (self.__class__, self.thrift_spec)))
      return
    oprot.writeStructBegin('Span')
    if self.trace_id != None:
      oprot.writeFieldBegin('trace_id', TType.I64, 1)
      oprot.writeI64(self.trace_id)
      oprot.writeFieldEnd()
    if self.name != None:
      oprot.writeFieldBegin('name', TType.STRING, 2)
      oprot.writeString(self.name)
      oprot.writeFieldEnd()
    if self.id != None:
      oprot.writeFieldBegin('id', TType.I64, 3)
      oprot.writeI64(self.id)
      oprot.writeFieldEnd()
    if self.parent_id != None:
      oprot.writeFieldBegin('parent_id', TType.I64, 4)
      oprot.writeI64(self.parent_id)
      oprot.writeFieldEnd()
    if self.client_host != None:
      oprot.writeFieldBegin('client_host', TType.STRING, 5)
      oprot.writeString(self.client_host)
      oprot.writeFieldEnd()
    if self.server_host != None:
      oprot.writeFieldBegin('server_host', TType.STRING, 6)
      oprot.writeString(self.server_host)
      oprot.writeFieldEnd()
    if self.events != None:
      oprot.writeFieldBegin('events', TType.LIST, 7)
      oprot.writeListBegin(TType.STRUCT, len(self.events))
      for iter20 in self.events:
        iter20.write(oprot)
      oprot.writeListEnd()
      oprot.writeFieldEnd()
    if self.annotations != None:
      oprot.writeFieldBegin('annotations', TType.MAP, 8)
      oprot.writeMapBegin(TType.STRING, TType.STRING, len(self.annotations))
      for kiter21,viter22 in self.annotations.items():
        oprot.writeString(kiter21)
        oprot.writeString(viter22)
      oprot.writeMapEnd()
      oprot.writeFieldEnd()
    if self.counters != None:
      oprot.writeFieldBegin('counters', TType.MAP, 9)
      oprot.writeMapBegin(TType.STRING, TType.I64, len(self.counters))
      for kiter23,viter24 in self.counters.items():
        oprot.writeString(kiter23)
        oprot.writeI64(viter24)
      oprot.writeMapEnd()
      oprot.writeFieldEnd()
    oprot.writeFieldStop()
    oprot.writeStructEnd()

  def __repr__(self):
    L = ['%s=%r' % (key, value)
      for key, value in self.__dict__.iteritems()]
    return '%s(%s)' % (self.__class__.__name__, ', '.join(L))

  def __eq__(self, other):
    return isinstance(other, self.__class__) and self.__dict__ == other.__dict__

  def __ne__(self, other):
    return not (self == other)

class LogEntry:
  """
  Attributes:
   - category
   - message
  """

  thrift_spec = (
    None, # 0
    (1, TType.STRING, 'category', None, None, ), # 1
    (2, TType.STRING, 'message', None, None, ), # 2
  )

  def __init__(self, category=None, message=None,):
    self.category = category
    self.message = message

  def read(self, iprot):
    if iprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and isinstance(iprot.trans, TTransport.CReadableTransport) and self.thrift_spec is not None and fastbinary is not None:
      fastbinary.decode_binary(self, iprot.trans, (self.__class__, self.thrift_spec))
      return
    iprot.readStructBegin()
    while True:
      (fname, ftype, fid) = iprot.readFieldBegin()
      if ftype == TType.STOP:
        break
      if fid == 1:
        if ftype == TType.STRING:
          self.category = iprot.readString();
        else:
          iprot.skip(ftype)
      elif fid == 2:
        if ftype == TType.STRING:
          self.message = iprot.readString();
        else:
          iprot.skip(ftype)
      else:
        iprot.skip(ftype)
      iprot.readFieldEnd()
    iprot.readStructEnd()

  def write(self, oprot):
    if oprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and self.thrift_spec is not None and fastbinary is not None:
      oprot.trans.write(fastbinary.encode_binary(self, (self.__class__, self.thrift_spec)))
      return
    oprot.writeStructBegin('LogEntry')
    if self.category != None:
      oprot.writeFieldBegin('category', TType.STRING, 1)
      oprot.writeString(self.category)
      oprot.writeFieldEnd()
    if self.message != None:
      oprot.writeFieldBegin('message', TType.STRING, 2)
      oprot.writeString(self.message)
      oprot.writeFieldEnd()
    oprot.writeFieldStop()
    oprot.writeStructEnd()

  def __repr__(self):
    L = ['%s=%r' % (key, value)
      for key, value in self.__dict__.iteritems()]
    return '%s(%s)' % (self.__class__.__name__, ', '.join(L))

  def __eq__(self, other):
    return isinstance(other, self.__class__) and self.__dict__ == other.__dict__

  def __ne__(self, other):
    return not (self == other)
