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

scray.service.qservice.thrifscala.ScrayTException.scala Maven / Gradle / Ivy

There is a newer version: 1.1.2
Show newest version
/**
 * Generated by Scrooge
 *   version: 4.16.0
 *   rev: 0201cac9fdd6188248d42da91fd14c87744cc4a5
 *   built at: 20170421-124523
 */
package scray.service.qservice.thrifscala

import com.twitter.scrooge.{
  HasThriftStructCodec3,
  LazyTProtocol,
  TFieldBlob,
  ThriftException,
  ThriftStruct,
  ThriftStructCodec3,
  ThriftStructFieldInfo,
  ThriftStructMetaData,
  ThriftUtil
}
import org.apache.thrift.protocol._
import org.apache.thrift.transport.{TMemoryBuffer, TTransport}
import java.nio.ByteBuffer
import java.util.Arrays
import scala.collection.immutable.{Map => immutable$Map}
import scala.collection.mutable.Builder
import scala.collection.mutable.{
  ArrayBuffer => mutable$ArrayBuffer, Buffer => mutable$Buffer,
  HashMap => mutable$HashMap, HashSet => mutable$HashSet}
import scala.collection.{Map, Set}

/**
 * Scray-level exceptions
 */
object ScrayTException extends ThriftStructCodec3[ScrayTException] {
  private val NoPassthroughFields = immutable$Map.empty[Short, TFieldBlob]
  val Struct = new TStruct("ScrayTException")
  val WhatField = new TField("what", TType.I32, 1)
  val WhatFieldManifest = implicitly[Manifest[Int]]
  val WhyField = new TField("why", TType.STRING, 2)
  val WhyFieldManifest = implicitly[Manifest[String]]

  /**
   * Field information in declaration order.
   */
  lazy val fieldInfos: scala.List[ThriftStructFieldInfo] = scala.List[ThriftStructFieldInfo](
    new ThriftStructFieldInfo(
      WhatField,
      false,
      false,
      WhatFieldManifest,
      _root_.scala.None,
      _root_.scala.None,
      immutable$Map.empty[String, String],
      immutable$Map.empty[String, String],
      None
    ),
    new ThriftStructFieldInfo(
      WhyField,
      false,
      false,
      WhyFieldManifest,
      _root_.scala.None,
      _root_.scala.None,
      immutable$Map.empty[String, String],
      immutable$Map.empty[String, String],
      None
    )
  )

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

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

  def withoutPassthroughFields(original: ScrayTException): ScrayTException =
    new ScrayTException(
      what =
        {
          val field = original.what
          field
        },
      why =
        {
          val field = original.why
          field
        }
    )

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

  override def decode(_iprot: TProtocol): ScrayTException = {
    var what: Int = 0
    var why: String = null
    var _passthroughFields: Builder[(Short, TFieldBlob), immutable$Map[Short, TFieldBlob]] = null
    var _done = false

    _iprot.readStructBegin()
    while (!_done) {
      val _field = _iprot.readFieldBegin()
      if (_field.`type` == TType.STOP) {
        _done = true
      } else {
        _field.id match {
          case 1 =>
            _field.`type` match {
              case TType.I32 =>
                what = readWhatValue(_iprot)
              case _actualType =>
                val _expectedType = TType.I32
                throw new TProtocolException(
                  "Received wrong type for field 'what' (expected=%s, actual=%s).".format(
                    ttypeToString(_expectedType),
                    ttypeToString(_actualType)
                  )
                )
            }
          case 2 =>
            _field.`type` match {
              case TType.STRING =>
                why = readWhyValue(_iprot)
              case _actualType =>
                val _expectedType = TType.STRING
                throw new TProtocolException(
                  "Received wrong type for field 'why' (expected=%s, actual=%s).".format(
                    ttypeToString(_expectedType),
                    ttypeToString(_actualType)
                  )
                )
            }
          case _ =>
            if (_passthroughFields == null)
              _passthroughFields = immutable$Map.newBuilder[Short, TFieldBlob]
            _passthroughFields += (_field.id -> TFieldBlob.read(_field, _iprot))
        }
        _iprot.readFieldEnd()
      }
    }
    _iprot.readStructEnd()

    new ScrayTException(
      what,
      why,
      if (_passthroughFields == null)
        NoPassthroughFields
      else
        _passthroughFields.result()
    )
  }

  def apply(
    what: Int,
    why: String
  ): ScrayTException =
    new ScrayTException(
      what,
      why
    )

  def unapply(_item: ScrayTException): _root_.scala.Option[_root_.scala.Tuple2[Int, String]] = _root_.scala.Some(_item.toTuple)


  @inline private def readWhatValue(_iprot: TProtocol): Int = {
    _iprot.readI32()
  }

  @inline private def writeWhatField(what_item: Int, _oprot: TProtocol): Unit = {
    _oprot.writeFieldBegin(WhatField)
    writeWhatValue(what_item, _oprot)
    _oprot.writeFieldEnd()
  }

  @inline private def writeWhatValue(what_item: Int, _oprot: TProtocol): Unit = {
    _oprot.writeI32(what_item)
  }

  @inline private def readWhyValue(_iprot: TProtocol): String = {
    _iprot.readString()
  }

  @inline private def writeWhyField(why_item: String, _oprot: TProtocol): Unit = {
    _oprot.writeFieldBegin(WhyField)
    writeWhyValue(why_item, _oprot)
    _oprot.writeFieldEnd()
  }

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


}

class ScrayTException(
    val what: Int,
    val why: String,
    val _passthroughFields: immutable$Map[Short, TFieldBlob])
  extends ThriftException with com.twitter.finagle.SourcedException with ThriftStruct
  with _root_.scala.Product2[Int, String]
  with HasThriftStructCodec3[ScrayTException]
  with java.io.Serializable
{
  import ScrayTException._
  def this(
    what: Int,
    why: String
  ) = this(
    what,
    why,
    Map.empty
  )

  def _1 = what
  def _2 = why

  def toTuple: _root_.scala.Tuple2[Int, String] = {
    (
      what,
      why
    )
  }


  /**
   * 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] = {
    lazy val _buff = new TMemoryBuffer(32)
    lazy val _oprot = new TCompactProtocol(_buff)
    _passthroughFields.get(_fieldId) match {
      case blob: _root_.scala.Some[TFieldBlob] => blob
      case _root_.scala.None => {
        val _fieldOpt: _root_.scala.Option[TField] =
          _fieldId match {
            case 1 =>
              if (true) {
                writeWhatValue(what, _oprot)
                _root_.scala.Some(ScrayTException.WhatField)
              } else {
                _root_.scala.None
              }
            case 2 =>
              if (why ne null) {
                writeWhyValue(why, _oprot)
                _root_.scala.Some(ScrayTException.WhyField)
              } else {
                _root_.scala.None
              }
            case _ => _root_.scala.None
          }
        _fieldOpt match {
          case _root_.scala.Some(_field) =>
            val _data = Arrays.copyOfRange(_buff.getArray, 0, _buff.length)
            _root_.scala.Some(TFieldBlob(_field, _data))
          case _root_.scala.None =>
            _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 { id -> _ } }).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): ScrayTException = {
    var what: Int = this.what
    var why: String = this.why
    var _passthroughFields = this._passthroughFields
    _blob.id match {
      case 1 =>
        what = readWhatValue(_blob.read)
      case 2 =>
        why = readWhyValue(_blob.read)
      case _ => _passthroughFields += (_blob.id -> _blob)
    }
    new ScrayTException(
      what,
      why,
      _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): ScrayTException = {
    var what: Int = this.what
    var why: String = this.why

    _fieldId match {
      case 1 =>
        what = 0
      case 2 =>
        why = null
      case _ =>
    }
    new ScrayTException(
      what,
      why,
      _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 unsetWhat: ScrayTException = unsetField(1)

  def unsetWhy: ScrayTException = unsetField(2)


  override def write(_oprot: TProtocol): Unit = {
    ScrayTException.validate(this)
    _oprot.writeStructBegin(Struct)
    writeWhatField(what, _oprot)
    if (why ne null) writeWhyField(why, _oprot)
    if (_passthroughFields.nonEmpty) {
      _passthroughFields.values.foreach { _.write(_oprot) }
    }
    _oprot.writeFieldStop()
    _oprot.writeStructEnd()
  }

  def copy(
    what: Int = this.what,
    why: String = this.why,
    _passthroughFields: immutable$Map[Short, TFieldBlob] = this._passthroughFields
  ): ScrayTException =
    new ScrayTException(
      what,
      why,
      _passthroughFields
    )

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

  private def _equals(x: ScrayTException, y: ScrayTException): Boolean =
      x.productArity == y.productArity &&
      x.productIterator.sameElements(y.productIterator)

  override def equals(other: Any): Boolean =
    canEqual(other) &&
      _equals(this, other.asInstanceOf[ScrayTException]) &&
      _passthroughFields == other.asInstanceOf[ScrayTException]._passthroughFields

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

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

  override def getMessage: String = String.valueOf(why)

  override def productArity: Int = 2

  override def productElement(n: Int): Any = n match {
    case 0 => this.what
    case 1 => this.why
    case _ => throw new IndexOutOfBoundsException(n.toString)
  }

  override def productPrefix: String = "ScrayTException"

  def _codec: ThriftStructCodec3[ScrayTException] = ScrayTException
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy