Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/**
* 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}
/**
* Serializes an individual delegation.
*/
object Delegation extends ValidatingThriftStructCodec3[Delegation] with StructBuilderFactory[Delegation] {
val NoPassthroughFields: immutable$Map[Short, TFieldBlob] = immutable$Map.empty[Short, TFieldBlob]
val Struct: TStruct = new TStruct("Delegation")
val SrcField: TField = new TField("src", TType.STRING, 1)
val SrcFieldManifest: Manifest[String] = manifest[String]
val DstField: TField = new TField("dst", TType.STRING, 2)
val DstFieldManifest: Manifest[String] = manifest[String]
/**
* Field information in declaration order.
*/
lazy val fieldInfos: scala.List[ThriftStructFieldInfo] = scala.List[ThriftStructFieldInfo](
new ThriftStructFieldInfo(
SrcField,
false,
false,
SrcFieldManifest,
_root_.scala.None,
_root_.scala.None,
immutable$Map.empty[String, String],
immutable$Map.empty[String, String],
None
),
new ThriftStructFieldInfo(
DstField,
false,
false,
DstFieldManifest,
_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[String].asInstanceOf[ClassTag[_]],
classTag[String].asInstanceOf[ClassTag[_]]
)
private[this] val structFields: Seq[ThriftStructField[Delegation]] = Seq[ThriftStructField[Delegation]](
new ThriftStructField[Delegation](
SrcField,
_root_.scala.Some(SrcFieldManifest),
classOf[Delegation]) {
def getValue[R](struct: Delegation): R = struct.src.asInstanceOf[R]
},
new ThriftStructField[Delegation](
DstField,
_root_.scala.Some(DstFieldManifest),
classOf[Delegation]) {
def getValue[R](struct: Delegation): R = struct.dst.asInstanceOf[R]
}
)
override lazy val metaData: ThriftStructMetaData[Delegation] =
new ThriftStructMetaData(this, structFields, fieldInfos, Nil, structAnnotations)
/**
* Checks that all required fields are non-null.
*/
def validate(_item: Delegation): 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: Delegation): scala.Seq[com.twitter.scrooge.validation.Issue] = {
val buf = scala.collection.mutable.ListBuffer.empty[com.twitter.scrooge.validation.Issue]
buf ++= validateField(item.src)
buf ++= validateField(item.dst)
buf.toList
}
def withoutPassthroughFields(original: Delegation): Delegation =
new Immutable(
src = original.src,
dst = original.dst
)
def newBuilder(): StructBuilder[Delegation] = new DelegationStructBuilder(_root_.scala.None, fieldTypes)
override def encode(_item: Delegation, _oproto: TProtocol): Unit = {
_item.write(_oproto)
}
private[this] def lazyDecode(_iprot: LazyTProtocol): Delegation = {
var srcOffset: Int = -1
var dstOffset: 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.STRING) {
srcOffset = _iprot.offsetSkipString()
} else {
_root_.com.twitter.scrooge.internal.ApplicationExceptions.throwWrongFieldTypeException(
"Received wrong type for field 'src' (expected=%s, actual=%s).",
TType.STRING,
_fieldType
)
}
case 2 =>
if (_fieldType == TType.STRING) {
dstOffset = _iprot.offsetSkipString()
} else {
_root_.com.twitter.scrooge.internal.ApplicationExceptions.throwWrongFieldTypeException(
"Received wrong type for field 'dst' (expected=%s, actual=%s).",
TType.STRING,
_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,
srcOffset,
dstOffset,
if (_passthroughFields eq null)
NoPassthroughFields
else
_passthroughFields.result()
)
}
override def decode(_iprot: TProtocol): Delegation = {
if (_iprot.isInstanceOf[LazyTProtocol]) {
lazyDecode(_iprot.asInstanceOf[LazyTProtocol])
} else {
eagerDecode(_iprot)
}
}
private[thriftscala] def eagerDecode(_iprot: TProtocol): Delegation = {
var src: String = null
var dst: String = null
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.STRING) {
src = readSrcValue(_iprot)
} else {
_root_.com.twitter.scrooge.internal.ApplicationExceptions.throwWrongFieldTypeException(
"Received wrong type for field 'src' (expected=%s, actual=%s).",
TType.STRING,
_fieldType
)
}
case 2 =>
if (_fieldType == TType.STRING) {
dst = readDstValue(_iprot)
} else {
_root_.com.twitter.scrooge.internal.ApplicationExceptions.throwWrongFieldTypeException(
"Received wrong type for field 'dst' (expected=%s, actual=%s).",
TType.STRING,
_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(
src,
dst,
if (_passthroughFields eq null)
NoPassthroughFields
else
_passthroughFields.result()
)
}
def apply(
src: String,
dst: String
): Delegation =
new Immutable(
src,
dst
)
def unapply(_item: Delegation): _root_.scala.Option[_root_.scala.Tuple2[String, String]] = _root_.scala.Some(_item.toTuple)
@inline private[thriftscala] def readSrcValue(_iprot: TProtocol): String = {
_iprot.readString()
}
@inline private def writeSrcField(src_item: String, _oprot: TProtocol): Unit = {
_oprot.writeFieldBegin(SrcField)
writeSrcValue(src_item, _oprot)
_oprot.writeFieldEnd()
}
@inline private def writeSrcValue(src_item: String, _oprot: TProtocol): Unit = {
_oprot.writeString(src_item)
}
@inline private[thriftscala] def readDstValue(_iprot: TProtocol): String = {
_iprot.readString()
}
@inline private def writeDstField(dst_item: String, _oprot: TProtocol): Unit = {
_oprot.writeFieldBegin(DstField)
writeDstValue(dst_item, _oprot)
_oprot.writeFieldEnd()
}
@inline private def writeDstValue(dst_item: String, _oprot: TProtocol): Unit = {
_oprot.writeString(dst_item)
}
object Immutable extends ThriftStructCodec3[Delegation] {
override def encode(_item: Delegation, _oproto: TProtocol): Unit = { _item.write(_oproto) }
override def decode(_iprot: TProtocol): Delegation = Delegation.decode(_iprot)
override lazy val metaData: ThriftStructMetaData[Delegation] = Delegation.metaData
}
/**
* The default read-only implementation of Delegation. You typically should not need to
* directly reference this class; instead, use the Delegation.apply method to construct
* new instances.
*/
class Immutable(
val src: String,
val dst: String,
override val _passthroughFields: immutable$Map[Short, TFieldBlob])
extends Delegation {
def this(
src: String,
dst: String
) = this(
src,
dst,
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,
srcOffset: Int,
dstOffset: Int,
override val _passthroughFields: immutable$Map[Short, TFieldBlob])
extends Delegation {
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 src: String =
if (srcOffset == -1)
null
else {
_proto.decodeString(_buf, srcOffset)
}
lazy val dst: String =
if (dstOffset == -1)
null
else {
_proto.decodeString(_buf, dstOffset)
}
/**
* 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 Delegation trait with additional state or
* behavior and implement the read-only methods from Delegation using an underlying
* instance.
*/
trait Proxy extends Delegation {
protected def _underlying_Delegation: Delegation
override def src: String = _underlying_Delegation.src
override def dst: String = _underlying_Delegation.dst
override def _passthroughFields: immutable$Map[Short, TFieldBlob] = _underlying_Delegation._passthroughFields
}
}
/**
* Prefer the companion object's [[com.twitter.finagle.thrift.thriftscala.Delegation.apply]]
* for construction if you don't need to specify passthrough fields.
*/
trait Delegation
extends ThriftStruct
with _root_.scala.Product2[String, String]
with ValidatingThriftStruct[Delegation]
with java.io.Serializable
{
import Delegation._
def src: String
def dst: String
def _passthroughFields: immutable$Map[Short, TFieldBlob] = immutable$Map.empty
def _1: String = src
def _2: String = dst
def toTuple: _root_.scala.Tuple2[String, String] =
_root_.scala.Tuple2[String, String](
src,
dst
)
/**
* 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 =>
if (src ne null) {
writeSrcValue(src, _oprot)
_root_.scala.Some(Delegation.SrcField)
} else {
_root_.scala.None
}
case 2 =>
if (dst ne null) {
writeDstValue(dst, _oprot)
_root_.scala.Some(Delegation.DstField)
} 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): Delegation = {
var src: String = this.src
var dst: String = this.dst
var _passthroughFields = this._passthroughFields
_blob.id match {
case 1 =>
src = readSrcValue(_blob.read)
case 2 =>
dst = readDstValue(_blob.read)
case _ => _passthroughFields += _root_.scala.Tuple2(_blob.id, _blob)
}
new Immutable(
src,
dst,
_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): Delegation = {
var src: String = this.src
var dst: String = this.dst
_fieldId match {
case 1 =>
src = null
case 2 =>
dst = null
case _ =>
}
new Immutable(
src,
dst,
_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 unsetSrc: Delegation = unsetField(1)
def unsetDst: Delegation = unsetField(2)
override def write(_oprot: TProtocol): Unit = {
Delegation.validate(this)
_oprot.writeStructBegin(Struct)
if (src ne null) writeSrcField(src, _oprot)
if (dst ne null) writeDstField(dst, _oprot)
if (_passthroughFields.nonEmpty) {
_passthroughFields.values.foreach { _.write(_oprot) }
}
_oprot.writeFieldStop()
_oprot.writeStructEnd()
}
def copy(
src: String = this.src,
dst: String = this.dst,
_passthroughFields: immutable$Map[Short, TFieldBlob] = this._passthroughFields
): Delegation =
new Immutable(
src,
dst,
_passthroughFields
)
override def canEqual(other: Any): Boolean = other.isInstanceOf[Delegation]
private[this] def _equals(other: Delegation): 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[Delegation])
override def hashCode: Int = {
_root_.scala.runtime.ScalaRunTime._hashCode(this)
}
override def toString: String = _root_.scala.runtime.ScalaRunTime._toString(this)
override def productPrefix: String = "Delegation"
def _codec: ValidatingThriftStructCodec3[Delegation] = Delegation
def newBuilder(): StructBuilder[Delegation] = new DelegationStructBuilder(_root_.scala.Some(this), fieldTypes)
}
private[thriftscala] class DelegationStructBuilder(instance: _root_.scala.Option[Delegation], fieldTypes: IndexedSeq[ClassTag[_]])
extends StructBuilder[Delegation](fieldTypes) {
def build(): Delegation = {
val _fieldArray = fieldArray // shadow variable
if (instance.isDefined) {
val instanceValue = instance.get
Delegation(
if (_fieldArray(0) == null) instanceValue.src else _fieldArray(0).asInstanceOf[String],
if (_fieldArray(1) == null) instanceValue.dst else _fieldArray(1).asInstanceOf[String]
)
} else {
if (genericArrayOps(_fieldArray).contains(null)) throw new InvalidFieldsException(structBuildError("Delegation"))
Delegation(
_fieldArray(0).asInstanceOf[String],
_fieldArray(1).asInstanceOf[String]
)
}
}
}