All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.twitter.finagle.thrift.thriftscala.RequestHeader.scala Maven / Gradle / Ivy

There is a newer version: 24.2.0
Show newest version
/**
 * Generated by Scrooge
 *   version: 20.4.1
 *   rev: 74d6bed636c90dc4b67e342ecd80033bad43e94d
 *   built at: 20200425-214521
 */
package com.twitter.finagle.thrift.thriftscala

import com.twitter.io.Buf
import com.twitter.scrooge.{
  InvalidFieldsException,
  LazyTProtocol,
  StructBuilder,
  StructBuilderFactory,
  TFieldBlob,
  ThriftStruct,
  ThriftStructCodec3,
  ThriftStructField,
  ThriftStructFieldInfo,
  ThriftStructMetaData,
  ValidatingThriftStruct,
  ValidatingThriftStructCodec3
}
import org.apache.thrift.protocol._
import org.apache.thrift.transport.TMemoryBuffer
import scala.collection.immutable.{Map => immutable$Map}
import scala.collection.mutable.Builder
import scala.reflect.{ClassTag, classTag}

/**
 * The following are for finagle-thrift specific tracing headers &
 * negotiation.
 */
/**
 * RequestHeader defines headers for the request. These carry the span data, and
 * a flag indicating whether the request is to be debugged.
 */
object RequestHeader extends ValidatingThriftStructCodec3[RequestHeader] with StructBuilderFactory[RequestHeader] {
  val NoPassthroughFields: immutable$Map[Short, TFieldBlob] = immutable$Map.empty[Short, TFieldBlob]
  val Struct: TStruct = new TStruct("RequestHeader")
  val TraceIdField: TField = new TField("trace_id", TType.I64, 1)
  val TraceIdFieldManifest: Manifest[Long] = manifest[Long]
  val SpanIdField: TField = new TField("span_id", TType.I64, 2)
  val SpanIdFieldManifest: Manifest[Long] = manifest[Long]
  val ParentSpanIdField: TField = new TField("parent_span_id", TType.I64, 3)
  val ParentSpanIdFieldManifest: Manifest[Long] = manifest[Long]
  val SampledField: TField = new TField("sampled", TType.BOOL, 5)
  val SampledFieldManifest: Manifest[Boolean] = manifest[Boolean]
  val ClientIdField: TField = new TField("client_id", TType.STRUCT, 6)
  val ClientIdFieldManifest: Manifest[com.twitter.finagle.thrift.thriftscala.ClientId] = manifest[com.twitter.finagle.thrift.thriftscala.ClientId]
  val FlagsField: TField = new TField("flags", TType.I64, 7)
  val FlagsFieldManifest: Manifest[Long] = manifest[Long]
  val ContextsField: TField = new TField("contexts", TType.LIST, 8)
  val ContextsFieldManifest: Manifest[_root_.scala.collection.Seq[com.twitter.finagle.thrift.thriftscala.RequestContext]] = manifest[_root_.scala.collection.Seq[com.twitter.finagle.thrift.thriftscala.RequestContext]]
  val DestField: TField = new TField("dest", TType.STRING, 9)
  val DestFieldManifest: Manifest[String] = manifest[String]
  val DelegationsField: TField = new TField("delegations", TType.LIST, 10)
  val DelegationsFieldManifest: Manifest[_root_.scala.collection.Seq[com.twitter.finagle.thrift.thriftscala.Delegation]] = manifest[_root_.scala.collection.Seq[com.twitter.finagle.thrift.thriftscala.Delegation]]
  val TraceIdHighField: TField = new TField("trace_id_high", TType.I64, 11)
  val TraceIdHighFieldManifest: Manifest[Long] = manifest[Long]

  /**
   * Field information in declaration order.
   */
  lazy val fieldInfos: scala.List[ThriftStructFieldInfo] = scala.List[ThriftStructFieldInfo](
    new ThriftStructFieldInfo(
      TraceIdField,
      false,
      false,
      TraceIdFieldManifest,
      _root_.scala.None,
      _root_.scala.None,
      immutable$Map.empty[String, String],
      immutable$Map.empty[String, String],
      None
    ),
    new ThriftStructFieldInfo(
      SpanIdField,
      false,
      false,
      SpanIdFieldManifest,
      _root_.scala.None,
      _root_.scala.None,
      immutable$Map.empty[String, String],
      immutable$Map.empty[String, String],
      None
    ),
    new ThriftStructFieldInfo(
      ParentSpanIdField,
      true,
      false,
      ParentSpanIdFieldManifest,
      _root_.scala.None,
      _root_.scala.None,
      immutable$Map.empty[String, String],
      immutable$Map.empty[String, String],
      None
    ),
    new ThriftStructFieldInfo(
      SampledField,
      true,
      false,
      SampledFieldManifest,
      _root_.scala.None,
      _root_.scala.None,
      immutable$Map.empty[String, String],
      immutable$Map.empty[String, String],
      None
    ),
    new ThriftStructFieldInfo(
      ClientIdField,
      true,
      false,
      ClientIdFieldManifest,
      _root_.scala.None,
      _root_.scala.None,
      immutable$Map.empty[String, String],
      immutable$Map.empty[String, String],
      None
    ),
    new ThriftStructFieldInfo(
      FlagsField,
      true,
      false,
      FlagsFieldManifest,
      _root_.scala.None,
      _root_.scala.None,
      immutable$Map.empty[String, String],
      immutable$Map.empty[String, String],
      None
    ),
    new ThriftStructFieldInfo(
      ContextsField,
      false,
      false,
      ContextsFieldManifest,
      _root_.scala.None,
      _root_.scala.Some(manifest[com.twitter.finagle.thrift.thriftscala.RequestContext]),
      immutable$Map.empty[String, String],
      immutable$Map.empty[String, String],
      None
    ),
    new ThriftStructFieldInfo(
      DestField,
      true,
      false,
      DestFieldManifest,
      _root_.scala.None,
      _root_.scala.None,
      immutable$Map.empty[String, String],
      immutable$Map.empty[String, String],
      None
    ),
    new ThriftStructFieldInfo(
      DelegationsField,
      true,
      false,
      DelegationsFieldManifest,
      _root_.scala.None,
      _root_.scala.Some(manifest[com.twitter.finagle.thrift.thriftscala.Delegation]),
      immutable$Map.empty[String, String],
      immutable$Map.empty[String, String],
      None
    ),
    new ThriftStructFieldInfo(
      TraceIdHighField,
      true,
      false,
      TraceIdHighFieldManifest,
      _root_.scala.None,
      _root_.scala.None,
      immutable$Map.empty[String, String],
      immutable$Map.empty[String, String],
      None
    )
  )


  val structAnnotations: immutable$Map[String, String] =
    immutable$Map.empty[String, String]

  private val fieldTypes: IndexedSeq[ClassTag[_]] = IndexedSeq[ClassTag[_]](
    classTag[Long].asInstanceOf[ClassTag[_]],
    classTag[Long].asInstanceOf[ClassTag[_]],
    classTag[_root_.scala.Option[Long]].asInstanceOf[ClassTag[_]],
    classTag[_root_.scala.Option[Boolean]].asInstanceOf[ClassTag[_]],
    classTag[_root_.scala.Option[com.twitter.finagle.thrift.thriftscala.ClientId]].asInstanceOf[ClassTag[_]],
    classTag[_root_.scala.Option[Long]].asInstanceOf[ClassTag[_]],
    classTag[_root_.scala.collection.Seq[com.twitter.finagle.thrift.thriftscala.RequestContext]].asInstanceOf[ClassTag[_]],
    classTag[_root_.scala.Option[String]].asInstanceOf[ClassTag[_]],
    classTag[_root_.scala.Option[_root_.scala.collection.Seq[com.twitter.finagle.thrift.thriftscala.Delegation]]].asInstanceOf[ClassTag[_]],
    classTag[_root_.scala.Option[Long]].asInstanceOf[ClassTag[_]]
  )

  private[this] val structFields: Seq[ThriftStructField[RequestHeader]] = Seq[ThriftStructField[RequestHeader]](
    new ThriftStructField[RequestHeader](
      TraceIdField,
      _root_.scala.Some(TraceIdFieldManifest),
      classOf[RequestHeader]) {
        def getValue[R](struct: RequestHeader): R = struct.traceId.asInstanceOf[R]
    },
    new ThriftStructField[RequestHeader](
      SpanIdField,
      _root_.scala.Some(SpanIdFieldManifest),
      classOf[RequestHeader]) {
        def getValue[R](struct: RequestHeader): R = struct.spanId.asInstanceOf[R]
    },
    new ThriftStructField[RequestHeader](
      ParentSpanIdField,
      _root_.scala.Some(ParentSpanIdFieldManifest),
      classOf[RequestHeader]) {
        def getValue[R](struct: RequestHeader): R = struct.parentSpanId.asInstanceOf[R]
    },
    new ThriftStructField[RequestHeader](
      SampledField,
      _root_.scala.Some(SampledFieldManifest),
      classOf[RequestHeader]) {
        def getValue[R](struct: RequestHeader): R = struct.sampled.asInstanceOf[R]
    },
    new ThriftStructField[RequestHeader](
      ClientIdField,
      _root_.scala.Some(ClientIdFieldManifest),
      classOf[RequestHeader]) {
        def getValue[R](struct: RequestHeader): R = struct.clientId.asInstanceOf[R]
    },
    new ThriftStructField[RequestHeader](
      FlagsField,
      _root_.scala.Some(FlagsFieldManifest),
      classOf[RequestHeader]) {
        def getValue[R](struct: RequestHeader): R = struct.flags.asInstanceOf[R]
    },
    new ThriftStructField[RequestHeader](
      ContextsField,
      _root_.scala.Some(ContextsFieldManifest),
      classOf[RequestHeader]) {
        def getValue[R](struct: RequestHeader): R = struct.contexts.asInstanceOf[R]
    },
    new ThriftStructField[RequestHeader](
      DestField,
      _root_.scala.Some(DestFieldManifest),
      classOf[RequestHeader]) {
        def getValue[R](struct: RequestHeader): R = struct.dest.asInstanceOf[R]
    },
    new ThriftStructField[RequestHeader](
      DelegationsField,
      _root_.scala.Some(DelegationsFieldManifest),
      classOf[RequestHeader]) {
        def getValue[R](struct: RequestHeader): R = struct.delegations.asInstanceOf[R]
    },
    new ThriftStructField[RequestHeader](
      TraceIdHighField,
      _root_.scala.Some(TraceIdHighFieldManifest),
      classOf[RequestHeader]) {
        def getValue[R](struct: RequestHeader): R = struct.traceIdHigh.asInstanceOf[R]
    }
  )

  override lazy val metaData: ThriftStructMetaData[RequestHeader] =
    new ThriftStructMetaData(this, structFields, fieldInfos, Nil, structAnnotations)

  /**
   * Checks that all required fields are non-null.
   */
  def validate(_item: RequestHeader): Unit = {
  }

  /**
   * Checks that the struct is a valid as a new instance. If there are any missing required or
   * construction required fields, return a non-empty list.
   */
  def validateNewInstance(item: RequestHeader): scala.Seq[com.twitter.scrooge.validation.Issue] = {
    val buf = scala.collection.mutable.ListBuffer.empty[com.twitter.scrooge.validation.Issue]

    buf ++= validateField(item.traceId)
    buf ++= validateField(item.spanId)
    buf ++= validateField(item.parentSpanId)
    buf ++= validateField(item.sampled)
    buf ++= validateField(item.clientId)
    buf ++= validateField(item.flags)
    buf ++= validateField(item.contexts)
    buf ++= validateField(item.dest)
    buf ++= validateField(item.delegations)
    buf ++= validateField(item.traceIdHigh)
    buf.toList
  }

  def withoutPassthroughFields(original: RequestHeader): RequestHeader =
    new Immutable(
      traceId = original.traceId,
      spanId = original.spanId,
      parentSpanId = original.parentSpanId,
      sampled = original.sampled,
      clientId =
        {
          val field = original.clientId
          field.map { field =>
            com.twitter.finagle.thrift.thriftscala.ClientId.withoutPassthroughFields(field)
          }
        },
      flags = original.flags,
      contexts =
        {
          val field = original.contexts
          field.map { field =>
            com.twitter.finagle.thrift.thriftscala.RequestContext.withoutPassthroughFields(field)
          }
        },
      dest = original.dest,
      delegations =
        {
          val field = original.delegations
          field.map { field =>
            field.map { field =>
              com.twitter.finagle.thrift.thriftscala.Delegation.withoutPassthroughFields(field)
            }
          }
        },
      traceIdHigh = original.traceIdHigh
    )

  def newBuilder(): StructBuilder[RequestHeader] = new RequestHeaderStructBuilder(_root_.scala.None, fieldTypes)

  override def encode(_item: RequestHeader, _oproto: TProtocol): Unit = {
    _item.write(_oproto)
  }


  private[this] def lazyDecode(_iprot: LazyTProtocol): RequestHeader = {

    var traceId: Long = 0L
    var spanId: Long = 0L
    var parent_span_idOffset: Int = -1
    var sampledOffset: Int = -1
    var clientId: Option[com.twitter.finagle.thrift.thriftscala.ClientId] = None
    var flagsOffset: Int = -1
    var contexts: _root_.scala.collection.Seq[com.twitter.finagle.thrift.thriftscala.RequestContext] = _root_.scala.collection.immutable.Nil
    var destOffset: Int = -1
    var delegations: Option[_root_.scala.collection.Seq[com.twitter.finagle.thrift.thriftscala.Delegation]] = None
    var trace_id_highOffset: Int = -1

    var _passthroughFields: Builder[(Short, TFieldBlob), immutable$Map[Short, TFieldBlob]] = null
    var _done = false
    val _start_offset = _iprot.offset

    _iprot.readStructBegin()
    do {
      val _field = _iprot.readFieldBegin()
      val _fieldType = _field.`type`
      if (_fieldType == TType.STOP) {
        _done = true
      } else {
        _field.id match {
          case 1 =>
            if (_fieldType == TType.I64) {
              traceId = readTraceIdValue(_iprot)
            } else {
              _root_.com.twitter.scrooge.internal.ApplicationExceptions.throwWrongFieldTypeException(
                "Received wrong type for field 'traceId' (expected=%s, actual=%s).",
                TType.I64,
                _fieldType
              )
            }
          case 2 =>
            if (_fieldType == TType.I64) {
              spanId = readSpanIdValue(_iprot)
            } else {
              _root_.com.twitter.scrooge.internal.ApplicationExceptions.throwWrongFieldTypeException(
                "Received wrong type for field 'spanId' (expected=%s, actual=%s).",
                TType.I64,
                _fieldType
              )
            }
          case 3 =>
            if (_fieldType == TType.I64) {
              parent_span_idOffset = _iprot.offsetSkipI64()
            } else {
              _root_.com.twitter.scrooge.internal.ApplicationExceptions.throwWrongFieldTypeException(
                "Received wrong type for field 'parentSpanId' (expected=%s, actual=%s).",
                TType.I64,
                _fieldType
              )
            }
          case 5 =>
            if (_fieldType == TType.BOOL) {
              sampledOffset = _iprot.offsetSkipBool()
            } else {
              _root_.com.twitter.scrooge.internal.ApplicationExceptions.throwWrongFieldTypeException(
                "Received wrong type for field 'sampled' (expected=%s, actual=%s).",
                TType.BOOL,
                _fieldType
              )
            }
          case 6 =>
            if (_fieldType == TType.STRUCT) {
              clientId = Some(readClientIdValue(_iprot))
            } else {
              _root_.com.twitter.scrooge.internal.ApplicationExceptions.throwWrongFieldTypeException(
                "Received wrong type for field 'clientId' (expected=%s, actual=%s).",
                TType.STRUCT,
                _fieldType
              )
            }
          case 7 =>
            if (_fieldType == TType.I64) {
              flagsOffset = _iprot.offsetSkipI64()
            } else {
              _root_.com.twitter.scrooge.internal.ApplicationExceptions.throwWrongFieldTypeException(
                "Received wrong type for field 'flags' (expected=%s, actual=%s).",
                TType.I64,
                _fieldType
              )
            }
          case 8 =>
            if (_fieldType == TType.LIST) {
              contexts = readContextsValue(_iprot)
            } else {
              _root_.com.twitter.scrooge.internal.ApplicationExceptions.throwWrongFieldTypeException(
                "Received wrong type for field 'contexts' (expected=%s, actual=%s).",
                TType.LIST,
                _fieldType
              )
            }
          case 9 =>
            if (_fieldType == TType.STRING) {
              destOffset = _iprot.offsetSkipString()
            } else {
              _root_.com.twitter.scrooge.internal.ApplicationExceptions.throwWrongFieldTypeException(
                "Received wrong type for field 'dest' (expected=%s, actual=%s).",
                TType.STRING,
                _fieldType
              )
            }
          case 10 =>
            if (_fieldType == TType.LIST) {
              delegations = Some(readDelegationsValue(_iprot))
            } else {
              _root_.com.twitter.scrooge.internal.ApplicationExceptions.throwWrongFieldTypeException(
                "Received wrong type for field 'delegations' (expected=%s, actual=%s).",
                TType.LIST,
                _fieldType
              )
            }
          case 11 =>
            if (_fieldType == TType.I64) {
              trace_id_highOffset = _iprot.offsetSkipI64()
            } else {
              _root_.com.twitter.scrooge.internal.ApplicationExceptions.throwWrongFieldTypeException(
                "Received wrong type for field 'traceIdHigh' (expected=%s, actual=%s).",
                TType.I64,
                _fieldType
              )
            }
          case _ =>
            if (_passthroughFields eq null)
              _passthroughFields = immutable$Map.newBuilder[Short, TFieldBlob]
            _passthroughFields += _root_.scala.Tuple2(_field.id, TFieldBlob.read(_field, _iprot))
        }
        _iprot.readFieldEnd()
      }
    } while (!_done)
    _iprot.readStructEnd()

    new LazyImmutable(
      _iprot,
      _iprot.buffer,
      _start_offset,
      _iprot.offset,
      traceId,
      spanId,
      parent_span_idOffset,
      sampledOffset,
      clientId,
      flagsOffset,
      contexts,
      destOffset,
      delegations,
      trace_id_highOffset,
      if (_passthroughFields eq null)
        NoPassthroughFields
      else
        _passthroughFields.result()
    )
  }

  override def decode(_iprot: TProtocol): RequestHeader = {
    if (_iprot.isInstanceOf[LazyTProtocol]) {
      lazyDecode(_iprot.asInstanceOf[LazyTProtocol])
    } else {
      eagerDecode(_iprot)
    }
  }

  private[thriftscala] def eagerDecode(_iprot: TProtocol): RequestHeader = {
    var traceId: Long = 0L
    var spanId: Long = 0L
    var parentSpanId: _root_.scala.Option[Long] = _root_.scala.None
    var sampled: _root_.scala.Option[Boolean] = _root_.scala.None
    var clientId: _root_.scala.Option[com.twitter.finagle.thrift.thriftscala.ClientId] = _root_.scala.None
    var flags: _root_.scala.Option[Long] = _root_.scala.None
    var contexts: _root_.scala.collection.Seq[com.twitter.finagle.thrift.thriftscala.RequestContext] = _root_.scala.collection.immutable.Nil
    var dest: _root_.scala.Option[String] = _root_.scala.None
    var delegations: _root_.scala.Option[_root_.scala.collection.Seq[com.twitter.finagle.thrift.thriftscala.Delegation]] = _root_.scala.None
    var traceIdHigh: _root_.scala.Option[Long] = _root_.scala.None
    var _passthroughFields: Builder[(Short, TFieldBlob), immutable$Map[Short, TFieldBlob]] = null
    var _done = false

    _iprot.readStructBegin()
    do {
      val _field = _iprot.readFieldBegin()
      val _fieldType = _field.`type`
      if (_fieldType == TType.STOP) {
        _done = true
      } else {
        _field.id match {
          case 1 =>
            if (_fieldType == TType.I64) {
              traceId = readTraceIdValue(_iprot)
            } else {
              _root_.com.twitter.scrooge.internal.ApplicationExceptions.throwWrongFieldTypeException(
                "Received wrong type for field 'traceId' (expected=%s, actual=%s).",
                TType.I64,
                _fieldType
              )
            }
          case 2 =>
            if (_fieldType == TType.I64) {
              spanId = readSpanIdValue(_iprot)
            } else {
              _root_.com.twitter.scrooge.internal.ApplicationExceptions.throwWrongFieldTypeException(
                "Received wrong type for field 'spanId' (expected=%s, actual=%s).",
                TType.I64,
                _fieldType
              )
            }
          case 3 =>
            if (_fieldType == TType.I64) {
              parentSpanId = _root_.scala.Some(readParentSpanIdValue(_iprot))
            } else {
              _root_.com.twitter.scrooge.internal.ApplicationExceptions.throwWrongFieldTypeException(
                "Received wrong type for field 'parentSpanId' (expected=%s, actual=%s).",
                TType.I64,
                _fieldType
              )
            }
          case 5 =>
            if (_fieldType == TType.BOOL) {
              sampled = _root_.scala.Some(readSampledValue(_iprot))
            } else {
              _root_.com.twitter.scrooge.internal.ApplicationExceptions.throwWrongFieldTypeException(
                "Received wrong type for field 'sampled' (expected=%s, actual=%s).",
                TType.BOOL,
                _fieldType
              )
            }
          case 6 =>
            if (_fieldType == TType.STRUCT) {
              clientId = _root_.scala.Some(readClientIdValue(_iprot))
            } else {
              _root_.com.twitter.scrooge.internal.ApplicationExceptions.throwWrongFieldTypeException(
                "Received wrong type for field 'clientId' (expected=%s, actual=%s).",
                TType.STRUCT,
                _fieldType
              )
            }
          case 7 =>
            if (_fieldType == TType.I64) {
              flags = _root_.scala.Some(readFlagsValue(_iprot))
            } else {
              _root_.com.twitter.scrooge.internal.ApplicationExceptions.throwWrongFieldTypeException(
                "Received wrong type for field 'flags' (expected=%s, actual=%s).",
                TType.I64,
                _fieldType
              )
            }
          case 8 =>
            if (_fieldType == TType.LIST) {
              contexts = readContextsValue(_iprot)
            } else {
              _root_.com.twitter.scrooge.internal.ApplicationExceptions.throwWrongFieldTypeException(
                "Received wrong type for field 'contexts' (expected=%s, actual=%s).",
                TType.LIST,
                _fieldType
              )
            }
          case 9 =>
            if (_fieldType == TType.STRING) {
              dest = _root_.scala.Some(readDestValue(_iprot))
            } else {
              _root_.com.twitter.scrooge.internal.ApplicationExceptions.throwWrongFieldTypeException(
                "Received wrong type for field 'dest' (expected=%s, actual=%s).",
                TType.STRING,
                _fieldType
              )
            }
          case 10 =>
            if (_fieldType == TType.LIST) {
              delegations = _root_.scala.Some(readDelegationsValue(_iprot))
            } else {
              _root_.com.twitter.scrooge.internal.ApplicationExceptions.throwWrongFieldTypeException(
                "Received wrong type for field 'delegations' (expected=%s, actual=%s).",
                TType.LIST,
                _fieldType
              )
            }
          case 11 =>
            if (_fieldType == TType.I64) {
              traceIdHigh = _root_.scala.Some(readTraceIdHighValue(_iprot))
            } else {
              _root_.com.twitter.scrooge.internal.ApplicationExceptions.throwWrongFieldTypeException(
                "Received wrong type for field 'traceIdHigh' (expected=%s, actual=%s).",
                TType.I64,
                _fieldType
              )
            }
          case _ =>
            if (_passthroughFields eq null)
              _passthroughFields = immutable$Map.newBuilder[Short, TFieldBlob]
            _passthroughFields += _root_.scala.Tuple2(_field.id, TFieldBlob.read(_field, _iprot))
        }
        _iprot.readFieldEnd()
      }
    } while (!_done)
    _iprot.readStructEnd()

    new Immutable(
      traceId,
      spanId,
      parentSpanId,
      sampled,
      clientId,
      flags,
      contexts,
      dest,
      delegations,
      traceIdHigh,
      if (_passthroughFields eq null)
        NoPassthroughFields
      else
        _passthroughFields.result()
    )
  }

  def apply(
    traceId: Long,
    spanId: Long,
    parentSpanId: _root_.scala.Option[Long] = _root_.scala.None,
    sampled: _root_.scala.Option[Boolean] = _root_.scala.None,
    clientId: _root_.scala.Option[com.twitter.finagle.thrift.thriftscala.ClientId] = _root_.scala.None,
    flags: _root_.scala.Option[Long] = _root_.scala.None,
    contexts: _root_.scala.collection.Seq[com.twitter.finagle.thrift.thriftscala.RequestContext] = _root_.scala.collection.immutable.Nil,
    dest: _root_.scala.Option[String] = _root_.scala.None,
    delegations: _root_.scala.Option[_root_.scala.collection.Seq[com.twitter.finagle.thrift.thriftscala.Delegation]] = _root_.scala.None,
    traceIdHigh: _root_.scala.Option[Long] = _root_.scala.None
  ): RequestHeader =
    new Immutable(
      traceId,
      spanId,
      parentSpanId,
      sampled,
      clientId,
      flags,
      contexts,
      dest,
      delegations,
      traceIdHigh
    )

  def unapply(_item: RequestHeader): _root_.scala.Option[_root_.scala.Tuple10[Long, Long, Option[Long], Option[Boolean], Option[com.twitter.finagle.thrift.thriftscala.ClientId], Option[Long], _root_.scala.collection.Seq[com.twitter.finagle.thrift.thriftscala.RequestContext], Option[String], Option[_root_.scala.collection.Seq[com.twitter.finagle.thrift.thriftscala.Delegation]], Option[Long]]] = _root_.scala.Some(_item.toTuple)


  @inline private[thriftscala] def readTraceIdValue(_iprot: TProtocol): Long = {
    _iprot.readI64()
  }

  @inline private def writeTraceIdField(traceId_item: Long, _oprot: TProtocol): Unit = {
    _oprot.writeFieldBegin(TraceIdField)
    writeTraceIdValue(traceId_item, _oprot)
    _oprot.writeFieldEnd()
  }

  @inline private def writeTraceIdValue(traceId_item: Long, _oprot: TProtocol): Unit = {
    _oprot.writeI64(traceId_item)
  }

  @inline private[thriftscala] def readSpanIdValue(_iprot: TProtocol): Long = {
    _iprot.readI64()
  }

  @inline private def writeSpanIdField(spanId_item: Long, _oprot: TProtocol): Unit = {
    _oprot.writeFieldBegin(SpanIdField)
    writeSpanIdValue(spanId_item, _oprot)
    _oprot.writeFieldEnd()
  }

  @inline private def writeSpanIdValue(spanId_item: Long, _oprot: TProtocol): Unit = {
    _oprot.writeI64(spanId_item)
  }

  @inline private[thriftscala] def readParentSpanIdValue(_iprot: TProtocol): Long = {
    _iprot.readI64()
  }

  @inline private def writeParentSpanIdField(parentSpanId_item: Long, _oprot: TProtocol): Unit = {
    _oprot.writeFieldBegin(ParentSpanIdField)
    writeParentSpanIdValue(parentSpanId_item, _oprot)
    _oprot.writeFieldEnd()
  }

  @inline private def writeParentSpanIdValue(parentSpanId_item: Long, _oprot: TProtocol): Unit = {
    _oprot.writeI64(parentSpanId_item)
  }

  @inline private[thriftscala] def readSampledValue(_iprot: TProtocol): Boolean = {
    _iprot.readBool()
  }

  @inline private def writeSampledField(sampled_item: Boolean, _oprot: TProtocol): Unit = {
    _oprot.writeFieldBegin(SampledField)
    writeSampledValue(sampled_item, _oprot)
    _oprot.writeFieldEnd()
  }

  @inline private def writeSampledValue(sampled_item: Boolean, _oprot: TProtocol): Unit = {
    _oprot.writeBool(sampled_item)
  }

  @inline private[thriftscala] def readClientIdValue(_iprot: TProtocol): com.twitter.finagle.thrift.thriftscala.ClientId = {
    com.twitter.finagle.thrift.thriftscala.ClientId.decode(_iprot)
  }

  @inline private def writeClientIdField(clientId_item: com.twitter.finagle.thrift.thriftscala.ClientId, _oprot: TProtocol): Unit = {
    _oprot.writeFieldBegin(ClientIdField)
    writeClientIdValue(clientId_item, _oprot)
    _oprot.writeFieldEnd()
  }

  @inline private def writeClientIdValue(clientId_item: com.twitter.finagle.thrift.thriftscala.ClientId, _oprot: TProtocol): Unit = {
    clientId_item.write(_oprot)
  }

  @inline private[thriftscala] def readFlagsValue(_iprot: TProtocol): Long = {
    _iprot.readI64()
  }

  @inline private def writeFlagsField(flags_item: Long, _oprot: TProtocol): Unit = {
    _oprot.writeFieldBegin(FlagsField)
    writeFlagsValue(flags_item, _oprot)
    _oprot.writeFieldEnd()
  }

  @inline private def writeFlagsValue(flags_item: Long, _oprot: TProtocol): Unit = {
    _oprot.writeI64(flags_item)
  }

  @inline private[thriftscala] def readContextsValue(_iprot: TProtocol): _root_.scala.collection.Seq[com.twitter.finagle.thrift.thriftscala.RequestContext] = {
    val _list = _iprot.readListBegin()
    if (_list.size == 0) {
      _iprot.readListEnd()
      Nil
    } else {
      val _rv = new _root_.scala.collection.mutable.ArrayBuffer[com.twitter.finagle.thrift.thriftscala.RequestContext](_list.size)
      var _i = 0
      do {
        _rv += {
          com.twitter.finagle.thrift.thriftscala.RequestContext.decode(_iprot)
        }
        _i += 1
      } while (_i < _list.size)
      _iprot.readListEnd()
      _rv
    }
  }

  @inline private def writeContextsField(contexts_item: _root_.scala.collection.Seq[com.twitter.finagle.thrift.thriftscala.RequestContext], _oprot: TProtocol): Unit = {
    _oprot.writeFieldBegin(ContextsField)
    writeContextsValue(contexts_item, _oprot)
    _oprot.writeFieldEnd()
  }

  @inline private def writeContextsValue(contexts_item: _root_.scala.collection.Seq[com.twitter.finagle.thrift.thriftscala.RequestContext], _oprot: TProtocol): Unit = {
    _oprot.writeListBegin(new TList(TType.STRUCT, contexts_item.size))
    if (contexts_item.isInstanceOf[IndexedSeq[_]]) {
      var _i = 0
      val _size = contexts_item.size
      while (_i < _size) {
        val contexts_item_element = contexts_item(_i)
        contexts_item_element.write(_oprot)
        _i += 1
      }
    } else {
      contexts_item.foreach { contexts_item_element =>
        contexts_item_element.write(_oprot)
      }
    }
    _oprot.writeListEnd()
  }

  @inline private[thriftscala] def readDestValue(_iprot: TProtocol): String = {
    _iprot.readString()
  }

  @inline private def writeDestField(dest_item: String, _oprot: TProtocol): Unit = {
    _oprot.writeFieldBegin(DestField)
    writeDestValue(dest_item, _oprot)
    _oprot.writeFieldEnd()
  }

  @inline private def writeDestValue(dest_item: String, _oprot: TProtocol): Unit = {
    _oprot.writeString(dest_item)
  }

  @inline private[thriftscala] def readDelegationsValue(_iprot: TProtocol): _root_.scala.collection.Seq[com.twitter.finagle.thrift.thriftscala.Delegation] = {
    val _list = _iprot.readListBegin()
    if (_list.size == 0) {
      _iprot.readListEnd()
      Nil
    } else {
      val _rv = new _root_.scala.collection.mutable.ArrayBuffer[com.twitter.finagle.thrift.thriftscala.Delegation](_list.size)
      var _i = 0
      do {
        _rv += {
          com.twitter.finagle.thrift.thriftscala.Delegation.decode(_iprot)
        }
        _i += 1
      } while (_i < _list.size)
      _iprot.readListEnd()
      _rv
    }
  }

  @inline private def writeDelegationsField(delegations_item: _root_.scala.collection.Seq[com.twitter.finagle.thrift.thriftscala.Delegation], _oprot: TProtocol): Unit = {
    _oprot.writeFieldBegin(DelegationsField)
    writeDelegationsValue(delegations_item, _oprot)
    _oprot.writeFieldEnd()
  }

  @inline private def writeDelegationsValue(delegations_item: _root_.scala.collection.Seq[com.twitter.finagle.thrift.thriftscala.Delegation], _oprot: TProtocol): Unit = {
    _oprot.writeListBegin(new TList(TType.STRUCT, delegations_item.size))
    if (delegations_item.isInstanceOf[IndexedSeq[_]]) {
      var _i = 0
      val _size = delegations_item.size
      while (_i < _size) {
        val delegations_item_element = delegations_item(_i)
        delegations_item_element.write(_oprot)
        _i += 1
      }
    } else {
      delegations_item.foreach { delegations_item_element =>
        delegations_item_element.write(_oprot)
      }
    }
    _oprot.writeListEnd()
  }

  @inline private[thriftscala] def readTraceIdHighValue(_iprot: TProtocol): Long = {
    _iprot.readI64()
  }

  @inline private def writeTraceIdHighField(traceIdHigh_item: Long, _oprot: TProtocol): Unit = {
    _oprot.writeFieldBegin(TraceIdHighField)
    writeTraceIdHighValue(traceIdHigh_item, _oprot)
    _oprot.writeFieldEnd()
  }

  @inline private def writeTraceIdHighValue(traceIdHigh_item: Long, _oprot: TProtocol): Unit = {
    _oprot.writeI64(traceIdHigh_item)
  }


  object Immutable extends ThriftStructCodec3[RequestHeader] {
    override def encode(_item: RequestHeader, _oproto: TProtocol): Unit = { _item.write(_oproto) }
    override def decode(_iprot: TProtocol): RequestHeader = RequestHeader.decode(_iprot)
    override lazy val metaData: ThriftStructMetaData[RequestHeader] = RequestHeader.metaData
  }

  /**
   * The default read-only implementation of RequestHeader.  You typically should not need to
   * directly reference this class; instead, use the RequestHeader.apply method to construct
   * new instances.
   */
  class Immutable(
      val traceId: Long,
      val spanId: Long,
      val parentSpanId: _root_.scala.Option[Long],
      val sampled: _root_.scala.Option[Boolean],
      val clientId: _root_.scala.Option[com.twitter.finagle.thrift.thriftscala.ClientId],
      val flags: _root_.scala.Option[Long],
      val contexts: _root_.scala.collection.Seq[com.twitter.finagle.thrift.thriftscala.RequestContext],
      val dest: _root_.scala.Option[String],
      val delegations: _root_.scala.Option[_root_.scala.collection.Seq[com.twitter.finagle.thrift.thriftscala.Delegation]],
      val traceIdHigh: _root_.scala.Option[Long],
      override val _passthroughFields: immutable$Map[Short, TFieldBlob])
    extends RequestHeader {
    def this(
      traceId: Long,
      spanId: Long,
      parentSpanId: _root_.scala.Option[Long] = _root_.scala.None,
      sampled: _root_.scala.Option[Boolean] = _root_.scala.None,
      clientId: _root_.scala.Option[com.twitter.finagle.thrift.thriftscala.ClientId] = _root_.scala.None,
      flags: _root_.scala.Option[Long] = _root_.scala.None,
      contexts: _root_.scala.collection.Seq[com.twitter.finagle.thrift.thriftscala.RequestContext] = _root_.scala.collection.immutable.Nil,
      dest: _root_.scala.Option[String] = _root_.scala.None,
      delegations: _root_.scala.Option[_root_.scala.collection.Seq[com.twitter.finagle.thrift.thriftscala.Delegation]] = _root_.scala.None,
      traceIdHigh: _root_.scala.Option[Long] = _root_.scala.None
    ) = this(
      traceId,
      spanId,
      parentSpanId,
      sampled,
      clientId,
      flags,
      contexts,
      dest,
      delegations,
      traceIdHigh,
      immutable$Map.empty[Short, TFieldBlob]
    )
  }

  /**
   * This is another Immutable, this however keeps strings as lazy values that are lazily decoded from the backing
   * array byte on read.
   */
  private[this] class LazyImmutable(
      _proto: LazyTProtocol,
      _buf: Array[Byte],
      _start_offset: Int,
      _end_offset: Int,
      val traceId: Long,
      val spanId: Long,
      parent_span_idOffset: Int,
      sampledOffset: Int,
      val clientId: _root_.scala.Option[com.twitter.finagle.thrift.thriftscala.ClientId],
      flagsOffset: Int,
      val contexts: _root_.scala.collection.Seq[com.twitter.finagle.thrift.thriftscala.RequestContext],
      destOffset: Int,
      val delegations: _root_.scala.Option[_root_.scala.collection.Seq[com.twitter.finagle.thrift.thriftscala.Delegation]],
      trace_id_highOffset: Int,
      override val _passthroughFields: immutable$Map[Short, TFieldBlob])
    extends RequestHeader {

    override def write(_oprot: TProtocol): Unit = {
      if (_oprot.isInstanceOf[LazyTProtocol]) {
        _oprot.asInstanceOf[LazyTProtocol].writeRaw(_buf, _start_offset, _end_offset - _start_offset)
      } else {
        super.write(_oprot)
      }
    }

    lazy val parentSpanId: _root_.scala.Option[Long] =
      if (parent_span_idOffset == -1)
        None
      else {
        Some(_proto.decodeI64(_buf, parent_span_idOffset))
      }
    lazy val sampled: _root_.scala.Option[Boolean] =
      if (sampledOffset == -1)
        None
      else {
        Some(_proto.decodeBool(_buf, sampledOffset))
      }
    lazy val flags: _root_.scala.Option[Long] =
      if (flagsOffset == -1)
        None
      else {
        Some(_proto.decodeI64(_buf, flagsOffset))
      }
    lazy val dest: _root_.scala.Option[String] =
      if (destOffset == -1)
        None
      else {
        Some(_proto.decodeString(_buf, destOffset))
      }
    lazy val traceIdHigh: _root_.scala.Option[Long] =
      if (trace_id_highOffset == -1)
        None
      else {
        Some(_proto.decodeI64(_buf, trace_id_highOffset))
      }

    /**
     * Override the super hash code to make it a lazy val rather than def.
     *
     * Calculating the hash code can be expensive, caching it where possible
     * can provide significant performance wins. (Key in a hash map for instance)
     * Usually not safe since the normal constructor will accept a mutable map or
     * set as an arg
     * Here however we control how the class is generated from serialized data.
     * With the class private and the contract that we throw away our mutable references
     * having the hash code lazy here is safe.
     */
    override lazy val hashCode: Int = super.hashCode
  }

  /**
   * This Proxy trait allows you to extend the RequestHeader trait with additional state or
   * behavior and implement the read-only methods from RequestHeader using an underlying
   * instance.
   */
  trait Proxy extends RequestHeader {
    protected def _underlying_RequestHeader: RequestHeader
    override def traceId: Long = _underlying_RequestHeader.traceId
    override def spanId: Long = _underlying_RequestHeader.spanId
    override def parentSpanId: _root_.scala.Option[Long] = _underlying_RequestHeader.parentSpanId
    override def sampled: _root_.scala.Option[Boolean] = _underlying_RequestHeader.sampled
    override def clientId: _root_.scala.Option[com.twitter.finagle.thrift.thriftscala.ClientId] = _underlying_RequestHeader.clientId
    override def flags: _root_.scala.Option[Long] = _underlying_RequestHeader.flags
    override def contexts: _root_.scala.collection.Seq[com.twitter.finagle.thrift.thriftscala.RequestContext] = _underlying_RequestHeader.contexts
    override def dest: _root_.scala.Option[String] = _underlying_RequestHeader.dest
    override def delegations: _root_.scala.Option[_root_.scala.collection.Seq[com.twitter.finagle.thrift.thriftscala.Delegation]] = _underlying_RequestHeader.delegations
    override def traceIdHigh: _root_.scala.Option[Long] = _underlying_RequestHeader.traceIdHigh
    override def _passthroughFields: immutable$Map[Short, TFieldBlob] = _underlying_RequestHeader._passthroughFields
  }
}

/**
 * Prefer the companion object's [[com.twitter.finagle.thrift.thriftscala.RequestHeader.apply]]
 * for construction if you don't need to specify passthrough fields.
 */
trait RequestHeader
  extends ThriftStruct
  with _root_.scala.Product10[Long, Long, Option[Long], Option[Boolean], Option[com.twitter.finagle.thrift.thriftscala.ClientId], Option[Long], _root_.scala.collection.Seq[com.twitter.finagle.thrift.thriftscala.RequestContext], Option[String], Option[_root_.scala.collection.Seq[com.twitter.finagle.thrift.thriftscala.Delegation]], Option[Long]]
  with ValidatingThriftStruct[RequestHeader]
  with java.io.Serializable
{
  import RequestHeader._

  def traceId: Long
  def spanId: Long
  def parentSpanId: _root_.scala.Option[Long]
  def sampled: _root_.scala.Option[Boolean]
  def clientId: _root_.scala.Option[com.twitter.finagle.thrift.thriftscala.ClientId]
  def flags: _root_.scala.Option[Long]
  def contexts: _root_.scala.collection.Seq[com.twitter.finagle.thrift.thriftscala.RequestContext]
  def dest: _root_.scala.Option[String]
  def delegations: _root_.scala.Option[_root_.scala.collection.Seq[com.twitter.finagle.thrift.thriftscala.Delegation]]
  def traceIdHigh: _root_.scala.Option[Long]

  def _passthroughFields: immutable$Map[Short, TFieldBlob] = immutable$Map.empty

  def _1: Long = traceId
  def _2: Long = spanId
  def _3: _root_.scala.Option[Long] = parentSpanId
  def _4: _root_.scala.Option[Boolean] = sampled
  def _5: _root_.scala.Option[com.twitter.finagle.thrift.thriftscala.ClientId] = clientId
  def _6: _root_.scala.Option[Long] = flags
  def _7: _root_.scala.collection.Seq[com.twitter.finagle.thrift.thriftscala.RequestContext] = contexts
  def _8: _root_.scala.Option[String] = dest
  def _9: _root_.scala.Option[_root_.scala.collection.Seq[com.twitter.finagle.thrift.thriftscala.Delegation]] = delegations
  def _10: _root_.scala.Option[Long] = traceIdHigh

  def toTuple: _root_.scala.Tuple10[Long, Long, Option[Long], Option[Boolean], Option[com.twitter.finagle.thrift.thriftscala.ClientId], Option[Long], _root_.scala.collection.Seq[com.twitter.finagle.thrift.thriftscala.RequestContext], Option[String], Option[_root_.scala.collection.Seq[com.twitter.finagle.thrift.thriftscala.Delegation]], Option[Long]] =
    _root_.scala.Tuple10[Long, Long, Option[Long], Option[Boolean], Option[com.twitter.finagle.thrift.thriftscala.ClientId], Option[Long], _root_.scala.collection.Seq[com.twitter.finagle.thrift.thriftscala.RequestContext], Option[String], Option[_root_.scala.collection.Seq[com.twitter.finagle.thrift.thriftscala.Delegation]], Option[Long]](
      traceId,
      spanId,
      parentSpanId,
      sampled,
      clientId,
      flags,
      contexts,
      dest,
      delegations,
      traceIdHigh
    )


  /**
   * Gets a field value encoded as a binary blob using TCompactProtocol.  If the specified field
   * is present in the passthrough map, that value is returned.  Otherwise, if the specified field
   * is known and not optional and set to None, then the field is serialized and returned.
   */
  def getFieldBlob(_fieldId: Short): _root_.scala.Option[TFieldBlob] = {
    val passedthroughValue = _passthroughFields.get(_fieldId)
    if (passedthroughValue.isDefined) {
      passedthroughValue
    } else {
      val _buff = new TMemoryBuffer(32)
      val _oprot = new TCompactProtocol(_buff)

      val _fieldOpt: _root_.scala.Option[TField] = _fieldId match {
        case 1 =>
            writeTraceIdValue(traceId, _oprot)
            _root_.scala.Some(RequestHeader.TraceIdField)
        case 2 =>
            writeSpanIdValue(spanId, _oprot)
            _root_.scala.Some(RequestHeader.SpanIdField)
        case 3 =>
          if (parentSpanId.isDefined) {
            writeParentSpanIdValue(parentSpanId.get, _oprot)
            _root_.scala.Some(RequestHeader.ParentSpanIdField)
          } else {
            _root_.scala.None
          }
        case 5 =>
          if (sampled.isDefined) {
            writeSampledValue(sampled.get, _oprot)
            _root_.scala.Some(RequestHeader.SampledField)
          } else {
            _root_.scala.None
          }
        case 6 =>
          if (clientId.isDefined) {
            writeClientIdValue(clientId.get, _oprot)
            _root_.scala.Some(RequestHeader.ClientIdField)
          } else {
            _root_.scala.None
          }
        case 7 =>
          if (flags.isDefined) {
            writeFlagsValue(flags.get, _oprot)
            _root_.scala.Some(RequestHeader.FlagsField)
          } else {
            _root_.scala.None
          }
        case 8 =>
          if (contexts ne null) {
            writeContextsValue(contexts, _oprot)
            _root_.scala.Some(RequestHeader.ContextsField)
          } else {
            _root_.scala.None
          }
        case 9 =>
          if (dest.isDefined) {
            writeDestValue(dest.get, _oprot)
            _root_.scala.Some(RequestHeader.DestField)
          } else {
            _root_.scala.None
          }
        case 10 =>
          if (delegations.isDefined) {
            writeDelegationsValue(delegations.get, _oprot)
            _root_.scala.Some(RequestHeader.DelegationsField)
          } else {
            _root_.scala.None
          }
        case 11 =>
          if (traceIdHigh.isDefined) {
            writeTraceIdHighValue(traceIdHigh.get, _oprot)
            _root_.scala.Some(RequestHeader.TraceIdHighField)
          } else {
            _root_.scala.None
          }
        case _ => _root_.scala.None
      }
      if (_fieldOpt.isDefined) {
        _root_.scala.Some(TFieldBlob(_fieldOpt.get, Buf.ByteArray.Owned(_buff.getArray)))
      } else {
        _root_.scala.None
      }
    }
  }


  /**
   * Collects TCompactProtocol-encoded field values according to `getFieldBlob` into a map.
   */
  def getFieldBlobs(ids: TraversableOnce[Short]): immutable$Map[Short, TFieldBlob] =
    (ids.flatMap { id => getFieldBlob(id).map { fieldBlob => (id, fieldBlob) } }).toMap

  /**
   * Sets a field using a TCompactProtocol-encoded binary blob.  If the field is a known
   * field, the blob is decoded and the field is set to the decoded value.  If the field
   * is unknown and passthrough fields are enabled, then the blob will be stored in
   * _passthroughFields.
   */
  def setField(_blob: TFieldBlob): RequestHeader = {
    var traceId: Long = this.traceId
    var spanId: Long = this.spanId
    var parentSpanId: _root_.scala.Option[Long] = this.parentSpanId
    var sampled: _root_.scala.Option[Boolean] = this.sampled
    var clientId: _root_.scala.Option[com.twitter.finagle.thrift.thriftscala.ClientId] = this.clientId
    var flags: _root_.scala.Option[Long] = this.flags
    var contexts: _root_.scala.collection.Seq[com.twitter.finagle.thrift.thriftscala.RequestContext] = this.contexts
    var dest: _root_.scala.Option[String] = this.dest
    var delegations: _root_.scala.Option[_root_.scala.collection.Seq[com.twitter.finagle.thrift.thriftscala.Delegation]] = this.delegations
    var traceIdHigh: _root_.scala.Option[Long] = this.traceIdHigh
    var _passthroughFields = this._passthroughFields
    _blob.id match {
      case 1 =>
        traceId = readTraceIdValue(_blob.read)
      case 2 =>
        spanId = readSpanIdValue(_blob.read)
      case 3 =>
        parentSpanId = _root_.scala.Some(readParentSpanIdValue(_blob.read))
      case 5 =>
        sampled = _root_.scala.Some(readSampledValue(_blob.read))
      case 6 =>
        clientId = _root_.scala.Some(readClientIdValue(_blob.read))
      case 7 =>
        flags = _root_.scala.Some(readFlagsValue(_blob.read))
      case 8 =>
        contexts = readContextsValue(_blob.read)
      case 9 =>
        dest = _root_.scala.Some(readDestValue(_blob.read))
      case 10 =>
        delegations = _root_.scala.Some(readDelegationsValue(_blob.read))
      case 11 =>
        traceIdHigh = _root_.scala.Some(readTraceIdHighValue(_blob.read))
      case _ => _passthroughFields += _root_.scala.Tuple2(_blob.id, _blob)
    }
    new Immutable(
      traceId,
      spanId,
      parentSpanId,
      sampled,
      clientId,
      flags,
      contexts,
      dest,
      delegations,
      traceIdHigh,
      _passthroughFields
    )
  }

  /**
   * If the specified field is optional, it is set to None.  Otherwise, if the field is
   * known, it is reverted to its default value; if the field is unknown, it is removed
   * from the passthroughFields map, if present.
   */
  def unsetField(_fieldId: Short): RequestHeader = {
    var traceId: Long = this.traceId
    var spanId: Long = this.spanId
    var parentSpanId: _root_.scala.Option[Long] = this.parentSpanId
    var sampled: _root_.scala.Option[Boolean] = this.sampled
    var clientId: _root_.scala.Option[com.twitter.finagle.thrift.thriftscala.ClientId] = this.clientId
    var flags: _root_.scala.Option[Long] = this.flags
    var contexts: _root_.scala.collection.Seq[com.twitter.finagle.thrift.thriftscala.RequestContext] = this.contexts
    var dest: _root_.scala.Option[String] = this.dest
    var delegations: _root_.scala.Option[_root_.scala.collection.Seq[com.twitter.finagle.thrift.thriftscala.Delegation]] = this.delegations
    var traceIdHigh: _root_.scala.Option[Long] = this.traceIdHigh

    _fieldId match {
      case 1 =>
        traceId = 0L
      case 2 =>
        spanId = 0L
      case 3 =>
        parentSpanId = _root_.scala.None
      case 5 =>
        sampled = _root_.scala.None
      case 6 =>
        clientId = _root_.scala.None
      case 7 =>
        flags = _root_.scala.None
      case 8 =>
        contexts = _root_.scala.collection.immutable.Nil
      case 9 =>
        dest = _root_.scala.None
      case 10 =>
        delegations = _root_.scala.None
      case 11 =>
        traceIdHigh = _root_.scala.None
      case _ =>
    }
    new Immutable(
      traceId,
      spanId,
      parentSpanId,
      sampled,
      clientId,
      flags,
      contexts,
      dest,
      delegations,
      traceIdHigh,
      _passthroughFields - _fieldId
    )
  }

  /**
   * If the specified field is optional, it is set to None.  Otherwise, if the field is
   * known, it is reverted to its default value; if the field is unknown, it is removed
   * from the passthroughFields map, if present.
   */
  def unsetTraceId: RequestHeader = unsetField(1)

  def unsetSpanId: RequestHeader = unsetField(2)

  def unsetParentSpanId: RequestHeader = unsetField(3)

  def unsetSampled: RequestHeader = unsetField(5)

  def unsetClientId: RequestHeader = unsetField(6)

  def unsetFlags: RequestHeader = unsetField(7)

  def unsetContexts: RequestHeader = unsetField(8)

  def unsetDest: RequestHeader = unsetField(9)

  def unsetDelegations: RequestHeader = unsetField(10)

  def unsetTraceIdHigh: RequestHeader = unsetField(11)


  override def write(_oprot: TProtocol): Unit = {
    RequestHeader.validate(this)
    _oprot.writeStructBegin(Struct)
    writeTraceIdField(traceId, _oprot)
    writeSpanIdField(spanId, _oprot)
    if (parentSpanId.isDefined) writeParentSpanIdField(parentSpanId.get, _oprot)
    if (sampled.isDefined) writeSampledField(sampled.get, _oprot)
    if (clientId.isDefined) writeClientIdField(clientId.get, _oprot)
    if (flags.isDefined) writeFlagsField(flags.get, _oprot)
    if (contexts ne null) writeContextsField(contexts, _oprot)
    if (dest.isDefined) writeDestField(dest.get, _oprot)
    if (delegations.isDefined) writeDelegationsField(delegations.get, _oprot)
    if (traceIdHigh.isDefined) writeTraceIdHighField(traceIdHigh.get, _oprot)
    if (_passthroughFields.nonEmpty) {
      _passthroughFields.values.foreach { _.write(_oprot) }
    }
    _oprot.writeFieldStop()
    _oprot.writeStructEnd()
  }

  def copy(
    traceId: Long = this.traceId,
    spanId: Long = this.spanId,
    parentSpanId: _root_.scala.Option[Long] = this.parentSpanId,
    sampled: _root_.scala.Option[Boolean] = this.sampled,
    clientId: _root_.scala.Option[com.twitter.finagle.thrift.thriftscala.ClientId] = this.clientId,
    flags: _root_.scala.Option[Long] = this.flags,
    contexts: _root_.scala.collection.Seq[com.twitter.finagle.thrift.thriftscala.RequestContext] = this.contexts,
    dest: _root_.scala.Option[String] = this.dest,
    delegations: _root_.scala.Option[_root_.scala.collection.Seq[com.twitter.finagle.thrift.thriftscala.Delegation]] = this.delegations,
    traceIdHigh: _root_.scala.Option[Long] = this.traceIdHigh,
    _passthroughFields: immutable$Map[Short, TFieldBlob] = this._passthroughFields
  ): RequestHeader =
    new Immutable(
      traceId,
      spanId,
      parentSpanId,
      sampled,
      clientId,
      flags,
      contexts,
      dest,
      delegations,
      traceIdHigh,
      _passthroughFields
    )

  override def canEqual(other: Any): Boolean = other.isInstanceOf[RequestHeader]

  private[this] def _equals(other: RequestHeader): Boolean =
      this.productArity == other.productArity &&
      this.productIterator.sameElements(other.productIterator) &&
      this._passthroughFields == other._passthroughFields

  override def equals(other: Any): Boolean =
    canEqual(other) && _equals(other.asInstanceOf[RequestHeader])

  override def hashCode: Int = {
    _root_.scala.runtime.ScalaRunTime._hashCode(this)
  }

  override def toString: String = _root_.scala.runtime.ScalaRunTime._toString(this)

  override def productPrefix: String = "RequestHeader"

  def _codec: ValidatingThriftStructCodec3[RequestHeader] = RequestHeader

  def newBuilder(): StructBuilder[RequestHeader] = new RequestHeaderStructBuilder(_root_.scala.Some(this), fieldTypes)
}

private[thriftscala] class RequestHeaderStructBuilder(instance: _root_.scala.Option[RequestHeader], fieldTypes: IndexedSeq[ClassTag[_]])
    extends StructBuilder[RequestHeader](fieldTypes) {

  def build(): RequestHeader = {
    val _fieldArray = fieldArray // shadow variable
    if (instance.isDefined) {
      val instanceValue = instance.get
      RequestHeader(
        if (_fieldArray(0) == null) instanceValue.traceId else _fieldArray(0).asInstanceOf[Long],
        if (_fieldArray(1) == null) instanceValue.spanId else _fieldArray(1).asInstanceOf[Long],
        if (_fieldArray(2) == null) instanceValue.parentSpanId else _fieldArray(2).asInstanceOf[_root_.scala.Option[Long]],
        if (_fieldArray(3) == null) instanceValue.sampled else _fieldArray(3).asInstanceOf[_root_.scala.Option[Boolean]],
        if (_fieldArray(4) == null) instanceValue.clientId else _fieldArray(4).asInstanceOf[_root_.scala.Option[com.twitter.finagle.thrift.thriftscala.ClientId]],
        if (_fieldArray(5) == null) instanceValue.flags else _fieldArray(5).asInstanceOf[_root_.scala.Option[Long]],
        if (_fieldArray(6) == null) instanceValue.contexts else _fieldArray(6).asInstanceOf[_root_.scala.collection.Seq[com.twitter.finagle.thrift.thriftscala.RequestContext]],
        if (_fieldArray(7) == null) instanceValue.dest else _fieldArray(7).asInstanceOf[_root_.scala.Option[String]],
        if (_fieldArray(8) == null) instanceValue.delegations else _fieldArray(8).asInstanceOf[_root_.scala.Option[_root_.scala.collection.Seq[com.twitter.finagle.thrift.thriftscala.Delegation]]],
        if (_fieldArray(9) == null) instanceValue.traceIdHigh else _fieldArray(9).asInstanceOf[_root_.scala.Option[Long]]
      )
    } else {
      if (genericArrayOps(_fieldArray).contains(null)) throw new InvalidFieldsException(structBuildError("RequestHeader"))
      RequestHeader(
        _fieldArray(0).asInstanceOf[Long],
        _fieldArray(1).asInstanceOf[Long],
        _fieldArray(2).asInstanceOf[_root_.scala.Option[Long]],
        _fieldArray(3).asInstanceOf[_root_.scala.Option[Boolean]],
        _fieldArray(4).asInstanceOf[_root_.scala.Option[com.twitter.finagle.thrift.thriftscala.ClientId]],
        _fieldArray(5).asInstanceOf[_root_.scala.Option[Long]],
        _fieldArray(6).asInstanceOf[_root_.scala.collection.Seq[com.twitter.finagle.thrift.thriftscala.RequestContext]],
        _fieldArray(7).asInstanceOf[_root_.scala.Option[String]],
        _fieldArray(8).asInstanceOf[_root_.scala.Option[_root_.scala.collection.Seq[com.twitter.finagle.thrift.thriftscala.Delegation]]],
        _fieldArray(9).asInstanceOf[_root_.scala.Option[Long]]
      )
    }
  }
}





© 2015 - 2024 Weber Informatics LLC | Privacy Policy