Currently Circe (with the latest shapeless snapshot) doesn't support the sereilization and eserialization of Twitter's scrooge generated scala classes as those classes are not sealed nor case classes.
/**
* Generated by Scrooge
* version: 3.14.1
* rev: a996c1128a032845c508102d62e65fc0aa7a5f41
* built at: 20140501-114733
*/
package demo
import com.twitter.scrooge.{
TFieldBlob, ThriftException, ThriftStruct, ThriftStructCodec3, ThriftStructFieldInfo, 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}
object StringOpt extends ThriftStructCodec3[StringOpt] {
private val NoPassthroughFields = immutable$Map.empty[Short, TFieldBlob]
val Struct = new TStruct("StringOpt")
val StrField = new TField("str", TType.STRING, 1)
val StrFieldManifest = implicitly[Manifest[String]]
/**
* Field information in declaration order.
*/
lazy val fieldInfos: scala.List[ThriftStructFieldInfo] = scala.List[ThriftStructFieldInfo](
new ThriftStructFieldInfo(
StrField,
true,
StrFieldManifest,
None,
None,
immutable$Map(
),
immutable$Map(
)
)
)
lazy val structAnnotations: immutable$Map[String, String] =
immutable$Map[String, String](
)
/**
* Checks that all required fields are non-null.
*/
def validate(_item: StringOpt) {
}
override def encode(_item: StringOpt, _oproto: TProtocol) {
_item.write(_oproto)
}
override def decode(_iprot: TProtocol): StringOpt = {
var str: Option[String] = None
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.STRING => {
str = Some(readStrValue(_iprot))
}
case _actualType =>
val _expectedType = TType.STRING
throw new TProtocolException(
"Received wrong type for field 'str' (expected=%s, actual=%s).".format(
ttypeToHuman(_expectedType),
ttypeToHuman(_actualType)
)
)
}
case _ =>
if (_passthroughFields == null)
_passthroughFields = immutable$Map.newBuilder[Short, TFieldBlob]
_passthroughFields += (_field.id -> TFieldBlob.read(_field, _iprot))
}
_iprot.readFieldEnd()
}
}
_iprot.readStructEnd()
new Immutable(
str,
if (_passthroughFields == null)
NoPassthroughFields
else
_passthroughFields.result()
)
}
def apply(
str: Option[String] = None
): StringOpt =
new Immutable(
str
)
def unapply(_item: StringOpt): Option[Option[String]] = Some(_item.str)
private def readStrValue(_iprot: TProtocol): String = {
_iprot.readString()
}
private def writeStrField(str_item: String, _oprot: TProtocol) {
_oprot.writeFieldBegin(StrField)
writeStrValue(str_item, _oprot)
_oprot.writeFieldEnd()
}
private def writeStrValue(str_item: String, _oprot: TProtocol) {
_oprot.writeString(str_item)
}
private def ttypeToHuman(byte: Byte) = {
// from https://github.com/apache/thrift/blob/master/lib/java/src/org/apache/thrift/protocol/TType.java
byte match {
case TType.STOP => "STOP"
case TType.VOID => "VOID"
case TType.BOOL => "BOOL"
case TType.BYTE => "BYTE"
case TType.DOUBLE => "DOUBLE"
case TType.I16 => "I16"
case TType.I32 => "I32"
case TType.I64 => "I64"
case TType.STRING => "STRING"
case TType.STRUCT => "STRUCT"
case TType.MAP => "MAP"
case TType.SET => "SET"
case TType.LIST => "LIST"
case TType.ENUM => "ENUM"
case _ => "UNKNOWN"
}
}
object Immutable extends ThriftStructCodec3[StringOpt] {
override def encode(_item: StringOpt, _oproto: TProtocol) { _item.write(_oproto) }
override def decode(_iprot: TProtocol): StringOpt = StringOpt.decode(_iprot)
}
/**
* The default read-only implementation of StringOpt. You typically should not need to
* directly reference this class; instead, use the StringOpt.apply method to construct
* new instances.
*/
class Immutable(
val str: Option[String],
override val _passthroughFields: immutable$Map[Short, TFieldBlob]
) extends StringOpt {
def this(
str: Option[String] = None
) = this(
str,
Map.empty
)
}
/**
* This Proxy trait allows you to extend the StringOpt trait with additional state or
* behavior and implement the read-only methods from StringOpt using an underlying
* instance.
*/
trait Proxy extends StringOpt {
protected def _underlying_StringOpt: StringOpt
override def str: Option[String] = _underlying_StringOpt.str
override def _passthroughFields = _underlying_StringOpt._passthroughFields
}
}
trait StringOpt
extends ThriftStruct
with scala.Product1[Option[String]]
with java.io.Serializable
{
import StringOpt._
def str: Option[String]
def _passthroughFields: immutable$Map[Short, TFieldBlob] = immutable$Map.empty
def _1 = str
/**
* Gets a field value encoded as a binary blob using TCompactProtocol. If the specified field
* is present in the passthrough map, that value is returend. 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): Option[TFieldBlob] = {
lazy val _buff = new TMemoryBuffer(32)
lazy val _oprot = new TCompactProtocol(_buff)
_passthroughFields.get(_fieldId) orElse {
val _fieldOpt: Option[TField] =
_fieldId match {
case 1 =>
if (str.isDefined) {
writeStrValue(str.get, _oprot)
Some(StringOpt.StrField)
} else {
None
}
case _ => None
}
_fieldOpt match {
case Some(_field) =>
val _data = Arrays.copyOfRange(_buff.getArray, 0, _buff.length)
Some(TFieldBlob(_field, _data))
case None =>
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): StringOpt = {
var str: Option[String] = this.str
var _passthroughFields = this._passthroughFields
_blob.id match {
case 1 =>
str = Some(readStrValue(_blob.read))
case _ => _passthroughFields += (_blob.id -> _blob)
}
new Immutable(
str,
_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 subtracked
* from the passthroughFields map, if present.
*/
def unsetField(_fieldId: Short): StringOpt = {
var str: Option[String] = this.str
_fieldId match {
case 1 =>
str = None
case _ =>
}
new Immutable(
str,
_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 subtracked
* from the passthroughFields map, if present.
*/
def unsetStr: StringOpt = unsetField(1)
override def write(_oprot: TProtocol) {
StringOpt.validate(this)
_oprot.writeStructBegin(Struct)
if (str.isDefined) writeStrField(str.get, _oprot)
_passthroughFields.values foreach { _.write(_oprot) }
_oprot.writeFieldStop()
_oprot.writeStructEnd()
}
def copy(
str: Option[String] = this.str,
_passthroughFields: immutable$Map[Short, TFieldBlob] = this._passthroughFields
): StringOpt =
new Immutable(
str,
_passthroughFields
)
override def canEqual(other: Any): Boolean = other.isInstanceOf[StringOpt]
override def equals(other: Any): Boolean =
_root_.scala.runtime.ScalaRunTime._equals(this, other) &&
_passthroughFields == other.asInstanceOf[StringOpt]._passthroughFields
override def hashCode: Int = _root_.scala.runtime.ScalaRunTime._hashCode(this)
override def toString: String = _root_.scala.runtime.ScalaRunTime._toString(this)
override def productArity: Int = 1
override def productElement(n: Int): Any = n match {
case 0 => this.str
case _ => throw new IndexOutOfBoundsException(n.toString)
}
override def productPrefix: String = "StringOpt"
}
/**
* Generated by Scrooge
* version: 3.14.1
* rev: a996c1128a032845c508102d62e65fc0aa7a5f41
* built at: 20140501-114733
*/
package demo
import com.twitter.scrooge.{
TFieldBlob, ThriftException, ThriftStruct, ThriftStructCodec3, ThriftStructFieldInfo, 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}
object IntOpt extends ThriftStructCodec3[IntOpt] {
private val NoPassthroughFields = immutable$Map.empty[Short, TFieldBlob]
val Struct = new TStruct("IntOpt")
val IntField = new TField("int", TType.I32, 1)
val IntFieldManifest = implicitly[Manifest[Int]]
/**
* Field information in declaration order.
*/
lazy val fieldInfos: scala.List[ThriftStructFieldInfo] = scala.List[ThriftStructFieldInfo](
new ThriftStructFieldInfo(
IntField,
true,
IntFieldManifest,
None,
None,
immutable$Map(
),
immutable$Map(
)
)
)
lazy val structAnnotations: immutable$Map[String, String] =
immutable$Map[String, String](
)
/**
* Checks that all required fields are non-null.
*/
def validate(_item: IntOpt) {
}
override def encode(_item: IntOpt, _oproto: TProtocol) {
_item.write(_oproto)
}
override def decode(_iprot: TProtocol): IntOpt = {
var int: Option[Int] = None
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 => {
int = Some(readIntValue(_iprot))
}
case _actualType =>
val _expectedType = TType.I32
throw new TProtocolException(
"Received wrong type for field 'int' (expected=%s, actual=%s).".format(
ttypeToHuman(_expectedType),
ttypeToHuman(_actualType)
)
)
}
case _ =>
if (_passthroughFields == null)
_passthroughFields = immutable$Map.newBuilder[Short, TFieldBlob]
_passthroughFields += (_field.id -> TFieldBlob.read(_field, _iprot))
}
_iprot.readFieldEnd()
}
}
_iprot.readStructEnd()
new Immutable(
int,
if (_passthroughFields == null)
NoPassthroughFields
else
_passthroughFields.result()
)
}
def apply(
int: Option[Int] = None
): IntOpt =
new Immutable(
int
)
def unapply(_item: IntOpt): Option[Option[Int]] = Some(_item.int)
private def readIntValue(_iprot: TProtocol): Int = {
_iprot.readI32()
}
private def writeIntField(int_item: Int, _oprot: TProtocol) {
_oprot.writeFieldBegin(IntField)
writeIntValue(int_item, _oprot)
_oprot.writeFieldEnd()
}
private def writeIntValue(int_item: Int, _oprot: TProtocol) {
_oprot.writeI32(int_item)
}
private def ttypeToHuman(byte: Byte) = {
// from https://github.com/apache/thrift/blob/master/lib/java/src/org/apache/thrift/protocol/TType.java
byte match {
case TType.STOP => "STOP"
case TType.VOID => "VOID"
case TType.BOOL => "BOOL"
case TType.BYTE => "BYTE"
case TType.DOUBLE => "DOUBLE"
case TType.I16 => "I16"
case TType.I32 => "I32"
case TType.I64 => "I64"
case TType.STRING => "STRING"
case TType.STRUCT => "STRUCT"
case TType.MAP => "MAP"
case TType.SET => "SET"
case TType.LIST => "LIST"
case TType.ENUM => "ENUM"
case _ => "UNKNOWN"
}
}
object Immutable extends ThriftStructCodec3[IntOpt] {
override def encode(_item: IntOpt, _oproto: TProtocol) { _item.write(_oproto) }
override def decode(_iprot: TProtocol): IntOpt = IntOpt.decode(_iprot)
}
/**
* The default read-only implementation of IntOpt. You typically should not need to
* directly reference this class; instead, use the IntOpt.apply method to construct
* new instances.
*/
class Immutable(
val int: Option[Int],
override val _passthroughFields: immutable$Map[Short, TFieldBlob]
) extends IntOpt {
def this(
int: Option[Int] = None
) = this(
int,
Map.empty
)
}
/**
* This Proxy trait allows you to extend the IntOpt trait with additional state or
* behavior and implement the read-only methods from IntOpt using an underlying
* instance.
*/
trait Proxy extends IntOpt {
protected def _underlying_IntOpt: IntOpt
override def int: Option[Int] = _underlying_IntOpt.int
override def _passthroughFields = _underlying_IntOpt._passthroughFields
}
}
trait IntOpt
extends ThriftStruct
with scala.Product1[Option[Int]]
with java.io.Serializable
{
import IntOpt._
def int: Option[Int]
def _passthroughFields: immutable$Map[Short, TFieldBlob] = immutable$Map.empty
def _1 = int
/**
* Gets a field value encoded as a binary blob using TCompactProtocol. If the specified field
* is present in the passthrough map, that value is returend. 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): Option[TFieldBlob] = {
lazy val _buff = new TMemoryBuffer(32)
lazy val _oprot = new TCompactProtocol(_buff)
_passthroughFields.get(_fieldId) orElse {
val _fieldOpt: Option[TField] =
_fieldId match {
case 1 =>
if (int.isDefined) {
writeIntValue(int.get, _oprot)
Some(IntOpt.IntField)
} else {
None
}
case _ => None
}
_fieldOpt match {
case Some(_field) =>
val _data = Arrays.copyOfRange(_buff.getArray, 0, _buff.length)
Some(TFieldBlob(_field, _data))
case None =>
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): IntOpt = {
var int: Option[Int] = this.int
var _passthroughFields = this._passthroughFields
_blob.id match {
case 1 =>
int = Some(readIntValue(_blob.read))
case _ => _passthroughFields += (_blob.id -> _blob)
}
new Immutable(
int,
_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 subtracked
* from the passthroughFields map, if present.
*/
def unsetField(_fieldId: Short): IntOpt = {
var int: Option[Int] = this.int
_fieldId match {
case 1 =>
int = None
case _ =>
}
new Immutable(
int,
_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 subtracked
* from the passthroughFields map, if present.
*/
def unsetInt: IntOpt = unsetField(1)
override def write(_oprot: TProtocol) {
IntOpt.validate(this)
_oprot.writeStructBegin(Struct)
if (int.isDefined) writeIntField(int.get, _oprot)
_passthroughFields.values foreach { _.write(_oprot) }
_oprot.writeFieldStop()
_oprot.writeStructEnd()
}
def copy(
int: Option[Int] = this.int,
_passthroughFields: immutable$Map[Short, TFieldBlob] = this._passthroughFields
): IntOpt =
new Immutable(
int,
_passthroughFields
)
override def canEqual(other: Any): Boolean = other.isInstanceOf[IntOpt]
override def equals(other: Any): Boolean =
_root_.scala.runtime.ScalaRunTime._equals(this, other) &&
_passthroughFields == other.asInstanceOf[IntOpt]._passthroughFields
override def hashCode: Int = _root_.scala.runtime.ScalaRunTime._hashCode(this)
override def toString: String = _root_.scala.runtime.ScalaRunTime._toString(this)
override def productArity: Int = 1
override def productElement(n: Int): Any = n match {
case 0 => this.int
case _ => throw new IndexOutOfBoundsException(n.toString)
}
override def productPrefix: String = "IntOpt"
}
* Generated by Scrooge
* version: 3.14.1
* rev: a996c1128a032845c508102d62e65fc0aa7a5f41
* built at: 20140501-114733
*/
package demo
import com.twitter.scrooge.{ThriftStruct, ThriftStructCodec3, TFieldBlob}
import org.apache.thrift.protocol._
import java.nio.ByteBuffer
import java.util.Arrays
import scala.collection.mutable.{
ArrayBuffer => mutable$ArrayBuffer, Buffer => mutable$Buffer,
HashMap => mutable$HashMap, HashSet => mutable$HashSet}
import scala.collection.{Map, Set}
@javax.annotation.Generated(value = Array("com.twitter.scrooge.Compiler"))
sealed trait Opt extends ThriftStruct
private object OptDecoder {
def apply(_iprot: TProtocol, newUnknown: TFieldBlob => Opt): Opt = {
var _result: Opt = null
_iprot.readStructBegin()
val _field = _iprot.readFieldBegin()
_field.id match {
case 1 => { /* strOpt */
_field.`type` match {
case TType.STRUCT => {
_result = Opt.StrOpt({
demo.StringOpt.decode(_iprot)
})
}
case _ => TProtocolUtil.skip(_iprot, _field.`type`)
}
}
case 2 => { /* intOpt */
_field.`type` match {
case TType.STRUCT => {
_result = Opt.IntOpt({
demo.IntOpt.decode(_iprot)
})
}
case _ => TProtocolUtil.skip(_iprot, _field.`type`)
}
}
case _ =>
if (_field.`type` != TType.STOP) {
_result = newUnknown(TFieldBlob.read(_field, _iprot))
} else {
TProtocolUtil.skip(_iprot, _field.`type`)
}
}
if (_field.`type` != TType.STOP) {
_iprot.readFieldEnd()
var _done = false
var _moreThanOne = false
while (!_done) {
val _field = _iprot.readFieldBegin()
if (_field.`type` == TType.STOP)
_done = true
else {
_moreThanOne = true
TProtocolUtil.skip(_iprot, _field.`type`)
_iprot.readFieldEnd()
}
}
if (_moreThanOne) {
_iprot.readStructEnd()
throw new TProtocolException("Cannot read a TUnion with more than one set value!")
}
}
_iprot.readStructEnd()
if (_result == null)
throw new TProtocolException("Cannot read a TUnion with no set value!")
_result
}
}
object OptAliases {
type StrOptAlias = demo.StringOpt
type IntOptAlias = demo.IntOpt
}
@javax.annotation.Generated(value = Array("com.twitter.scrooge.Compiler"))
object Opt extends ThriftStructCodec3[Opt] {
val Union = new TStruct("Opt")
val StrOptField = new TField("strOpt", TType.STRUCT, 1)
val IntOptField = new TField("intOpt", TType.STRUCT, 2)
override def encode(_item: Opt, _oprot: TProtocol) { _item.write(_oprot) }
override def decode(_iprot: TProtocol): Opt = OptDecoder(_iprot, UnknownUnionField(_))
def apply(_iprot: TProtocol): Opt = decode(_iprot)
import OptAliases._
case class StrOpt(strOpt: StrOptAlias) extends Opt {
override def write(_oprot: TProtocol) {
if (strOpt == null)
throw new TProtocolException("Cannot write a TUnion with no set value!")
_oprot.writeStructBegin(Union)
if (strOpt ne null) {
val strOpt_item = strOpt
_oprot.writeFieldBegin(StrOptField)
strOpt_item.write(_oprot)
_oprot.writeFieldEnd()
}
_oprot.writeFieldStop()
_oprot.writeStructEnd()
}
}
case class IntOpt(intOpt: IntOptAlias) extends Opt {
override def write(_oprot: TProtocol) {
if (intOpt == null)
throw new TProtocolException("Cannot write a TUnion with no set value!")
_oprot.writeStructBegin(Union)
if (intOpt ne null) {
val intOpt_item = intOpt
_oprot.writeFieldBegin(IntOptField)
intOpt_item.write(_oprot)
_oprot.writeFieldEnd()
}
_oprot.writeFieldStop()
_oprot.writeStructEnd()
}
}
case class UnknownUnionField private[Opt](private val field: TFieldBlob) extends Opt {
override def write(_oprot: TProtocol) {
_oprot.writeStructBegin(Union)
field.write(_oprot)
_oprot.writeFieldStop()
_oprot.writeStructEnd()
}
}
}
/**
* Generated by Scrooge
* version: 3.14.1
* rev: a996c1128a032845c508102d62e65fc0aa7a5f41
* built at: 20140501-114733
*/
package demo
import com.twitter.scrooge.{
TFieldBlob, ThriftException, ThriftStruct, ThriftStructCodec3, ThriftStructFieldInfo, 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}
object Foo extends ThriftStructCodec3[Foo] {
private val NoPassthroughFields = immutable$Map.empty[Short, TFieldBlob]
val Struct = new TStruct("Foo")
val ListField = new TField("list", TType.LIST, 1)
val ListFieldManifest = implicitly[Manifest[Seq[String]]]
val StateMapField = new TField("stateMap", TType.MAP, 2)
val StateMapFieldManifest = implicitly[Manifest[Map[State, String]]]
val OptMapField = new TField("optMap", TType.MAP, 3)
val OptMapFieldManifest = implicitly[Manifest[Map[Int, Opt]]]
/**
* Field information in declaration order.
*/
lazy val fieldInfos: scala.List[ThriftStructFieldInfo] = scala.List[ThriftStructFieldInfo](
new ThriftStructFieldInfo(
ListField,
false,
ListFieldManifest,
None,
Some(implicitly[Manifest[String]]),
immutable$Map(
),
immutable$Map(
)
),
new ThriftStructFieldInfo(
StateMapField,
false,
StateMapFieldManifest,
Some(implicitly[Manifest[State]]),
Some(implicitly[Manifest[String]]),
immutable$Map(
),
immutable$Map(
)
),
new ThriftStructFieldInfo(
OptMapField,
false,
OptMapFieldManifest,
Some(implicitly[Manifest[Int]]),
Some(implicitly[Manifest[Opt]]),
immutable$Map(
),
immutable$Map(
)
)
)
lazy val structAnnotations: immutable$Map[String, String] =
immutable$Map[String, String](
)
/**
* Checks that all required fields are non-null.
*/
def validate(_item: Foo) {
}
override def encode(_item: Foo, _oproto: TProtocol) {
_item.write(_oproto)
}
override def decode(_iprot: TProtocol): Foo = {
var list: Seq[String] = Seq[String]()
var stateMap: Map[State, String] = Map[State, String]()
var optMap: Map[Int, Opt] = Map[Int, Opt]()
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.LIST => {
list = readListValue(_iprot)
}
case _actualType =>
val _expectedType = TType.LIST
throw new TProtocolException(
"Received wrong type for field 'list' (expected=%s, actual=%s).".format(
ttypeToHuman(_expectedType),
ttypeToHuman(_actualType)
)
)
}
case 2 =>
_field.`type` match {
case TType.MAP => {
stateMap = readStateMapValue(_iprot)
}
case _actualType =>
val _expectedType = TType.MAP
throw new TProtocolException(
"Received wrong type for field 'stateMap' (expected=%s, actual=%s).".format(
ttypeToHuman(_expectedType),
ttypeToHuman(_actualType)
)
)
}
case 3 =>
_field.`type` match {
case TType.MAP => {
optMap = readOptMapValue(_iprot)
}
case _actualType =>
val _expectedType = TType.MAP
throw new TProtocolException(
"Received wrong type for field 'optMap' (expected=%s, actual=%s).".format(
ttypeToHuman(_expectedType),
ttypeToHuman(_actualType)
)
)
}
case _ =>
if (_passthroughFields == null)
_passthroughFields = immutable$Map.newBuilder[Short, TFieldBlob]
_passthroughFields += (_field.id -> TFieldBlob.read(_field, _iprot))
}
_iprot.readFieldEnd()
}
}
_iprot.readStructEnd()
new Immutable(
list,
stateMap,
optMap,
if (_passthroughFields == null)
NoPassthroughFields
else
_passthroughFields.result()
)
}
def apply(
list: Seq[String] = Seq[String](),
stateMap: Map[State, String] = Map[State, String](),
optMap: Map[Int, Opt] = Map[Int, Opt]()
): Foo =
new Immutable(
list,
stateMap,
optMap
)
def unapply(_item: Foo): Option[scala.Product3[Seq[String], Map[State, String], Map[Int, Opt]]] = Some(_item)
private def readListValue(_iprot: TProtocol): Seq[String] = {
val _list = _iprot.readListBegin()
if (_list.size == 0) {
_iprot.readListEnd()
Nil
} else {
val _rv = new mutable$ArrayBuffer[String](_list.size)
var _i = 0
while (_i < _list.size) {
_rv += {
_iprot.readString()
}
_i += 1
}
_iprot.readListEnd()
_rv
}
}
private def writeListField(list_item: Seq[String], _oprot: TProtocol) {
_oprot.writeFieldBegin(ListField)
writeListValue(list_item, _oprot)
_oprot.writeFieldEnd()
}
private def writeListValue(list_item: Seq[String], _oprot: TProtocol) {
_oprot.writeListBegin(new TList(TType.STRING, list_item.size))
list_item.foreach { list_item_element =>
_oprot.writeString(list_item_element)
}
_oprot.writeListEnd()
}
private def readStateMapValue(_iprot: TProtocol): Map[State, String] = {
val _map = _iprot.readMapBegin()
if (_map.size == 0) {
_iprot.readMapEnd()
Map.empty[State, String]
} else {
val _rv = new mutable$HashMap[State, String]
var _i = 0
while (_i < _map.size) {
val _key = {
State(_iprot.readI32())
}
val _value = {
_iprot.readString()
}
_rv(_key) = _value
_i += 1
}
_iprot.readMapEnd()
_rv
}
}
private def writeStateMapField(stateMap_item: Map[State, String], _oprot: TProtocol) {
_oprot.writeFieldBegin(StateMapField)
writeStateMapValue(stateMap_item, _oprot)
_oprot.writeFieldEnd()
}
private def writeStateMapValue(stateMap_item: Map[State, String], _oprot: TProtocol) {
_oprot.writeMapBegin(new TMap(TType.I32, TType.STRING, stateMap_item.size))
stateMap_item.foreach { _pair =>
val stateMap_item_key = _pair._1
val stateMap_item_value = _pair._2
_oprot.writeI32(stateMap_item_key.value)
_oprot.writeString(stateMap_item_value)
}
_oprot.writeMapEnd()
}
private def readOptMapValue(_iprot: TProtocol): Map[Int, Opt] = {
val _map = _iprot.readMapBegin()
if (_map.size == 0) {
_iprot.readMapEnd()
Map.empty[Int, Opt]
} else {
val _rv = new mutable$HashMap[Int, Opt]
var _i = 0
while (_i < _map.size) {
val _key = {
_iprot.readI32()
}
val _value = {
Opt.decode(_iprot)
}
_rv(_key) = _value
_i += 1
}
_iprot.readMapEnd()
_rv
}
}
private def writeOptMapField(optMap_item: Map[Int, Opt], _oprot: TProtocol) {
_oprot.writeFieldBegin(OptMapField)
writeOptMapValue(optMap_item, _oprot)
_oprot.writeFieldEnd()
}
private def writeOptMapValue(optMap_item: Map[Int, Opt], _oprot: TProtocol) {
_oprot.writeMapBegin(new TMap(TType.I32, TType.STRUCT, optMap_item.size))
optMap_item.foreach { _pair =>
val optMap_item_key = _pair._1
val optMap_item_value = _pair._2
_oprot.writeI32(optMap_item_key)
optMap_item_value.write(_oprot)
}
_oprot.writeMapEnd()
}
private def ttypeToHuman(byte: Byte) = {
// from https://github.com/apache/thrift/blob/master/lib/java/src/org/apache/thrift/protocol/TType.java
byte match {
case TType.STOP => "STOP"
case TType.VOID => "VOID"
case TType.BOOL => "BOOL"
case TType.BYTE => "BYTE"
case TType.DOUBLE => "DOUBLE"
case TType.I16 => "I16"
case TType.I32 => "I32"
case TType.I64 => "I64"
case TType.STRING => "STRING"
case TType.STRUCT => "STRUCT"
case TType.MAP => "MAP"
case TType.SET => "SET"
case TType.LIST => "LIST"
case TType.ENUM => "ENUM"
case _ => "UNKNOWN"
}
}
object Immutable extends ThriftStructCodec3[Foo] {
override def encode(_item: Foo, _oproto: TProtocol) { _item.write(_oproto) }
override def decode(_iprot: TProtocol): Foo = Foo.decode(_iprot)
}
/**
* The default read-only implementation of Foo. You typically should not need to
* directly reference this class; instead, use the Foo.apply method to construct
* new instances.
*/
class Immutable(
val list: Seq[String],
val stateMap: Map[State, String],
val optMap: Map[Int, Opt],
override val _passthroughFields: immutable$Map[Short, TFieldBlob]
) extends Foo {
def this(
list: Seq[String] = Seq[String](),
stateMap: Map[State, String] = Map[State, String](),
optMap: Map[Int, Opt] = Map[Int, Opt]()
) = this(
list,
stateMap,
optMap,
Map.empty
)
}
/**
* This Proxy trait allows you to extend the Foo trait with additional state or
* behavior and implement the read-only methods from Foo using an underlying
* instance.
*/
trait Proxy extends Foo {
protected def _underlying_Foo: Foo
override def list: Seq[String] = _underlying_Foo.list
override def stateMap: Map[State, String] = _underlying_Foo.stateMap
override def optMap: Map[Int, Opt] = _underlying_Foo.optMap
override def _passthroughFields = _underlying_Foo._passthroughFields
}
}
trait Foo
extends ThriftStruct
with scala.Product3[Seq[String], Map[State, String], Map[Int, Opt]]
with java.io.Serializable
{
import Foo._
def list: Seq[String]
def stateMap: Map[State, String]
def optMap: Map[Int, Opt]
def _passthroughFields: immutable$Map[Short, TFieldBlob] = immutable$Map.empty
def _1 = list
def _2 = stateMap
def _3 = optMap
/**
* Gets a field value encoded as a binary blob using TCompactProtocol. If the specified field
* is present in the passthrough map, that value is returend. 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): Option[TFieldBlob] = {
lazy val _buff = new TMemoryBuffer(32)
lazy val _oprot = new TCompactProtocol(_buff)
_passthroughFields.get(_fieldId) orElse {
val _fieldOpt: Option[TField] =
_fieldId match {
case 1 =>
if (list ne null) {
writeListValue(list, _oprot)
Some(Foo.ListField)
} else {
None
}
case 2 =>
if (stateMap ne null) {
writeStateMapValue(stateMap, _oprot)
Some(Foo.StateMapField)
} else {
None
}
case 3 =>
if (optMap ne null) {
writeOptMapValue(optMap, _oprot)
Some(Foo.OptMapField)
} else {
None
}
case _ => None
}
_fieldOpt match {
case Some(_field) =>
val _data = Arrays.copyOfRange(_buff.getArray, 0, _buff.length)
Some(TFieldBlob(_field, _data))
case None =>
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): Foo = {
var list: Seq[String] = this.list
var stateMap: Map[State, String] = this.stateMap
var optMap: Map[Int, Opt] = this.optMap
var _passthroughFields = this._passthroughFields
_blob.id match {
case 1 =>
list = readListValue(_blob.read)
case 2 =>
stateMap = readStateMapValue(_blob.read)
case 3 =>
optMap = readOptMapValue(_blob.read)
case _ => _passthroughFields += (_blob.id -> _blob)
}
new Immutable(
list,
stateMap,
optMap,
_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 subtracked
* from the passthroughFields map, if present.
*/
def unsetField(_fieldId: Short): Foo = {
var list: Seq[String] = this.list
var stateMap: Map[State, String] = this.stateMap
var optMap: Map[Int, Opt] = this.optMap
_fieldId match {
case 1 =>
list = Seq[String]()
case 2 =>
stateMap = Map[State, String]()
case 3 =>
optMap = Map[Int, Opt]()
case _ =>
}
new Immutable(
list,
stateMap,
optMap,
_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 subtracked
* from the passthroughFields map, if present.
*/
def unsetList: Foo = unsetField(1)
def unsetStateMap: Foo = unsetField(2)
def unsetOptMap: Foo = unsetField(3)
override def write(_oprot: TProtocol) {
Foo.validate(this)
_oprot.writeStructBegin(Struct)
if (list ne null) writeListField(list, _oprot)
if (stateMap ne null) writeStateMapField(stateMap, _oprot)
if (optMap ne null) writeOptMapField(optMap, _oprot)
_passthroughFields.values foreach { _.write(_oprot) }
_oprot.writeFieldStop()
_oprot.writeStructEnd()
}
def copy(
list: Seq[String] = this.list,
stateMap: Map[State, String] = this.stateMap,
optMap: Map[Int, Opt] = this.optMap,
_passthroughFields: immutable$Map[Short, TFieldBlob] = this._passthroughFields
): Foo =
new Immutable(
list,
stateMap,
optMap,
_passthroughFields
)
override def canEqual(other: Any): Boolean = other.isInstanceOf[Foo]
override def equals(other: Any): Boolean =
_root_.scala.runtime.ScalaRunTime._equals(this, other) &&
_passthroughFields == other.asInstanceOf[Foo]._passthroughFields
override def hashCode: Int = _root_.scala.runtime.ScalaRunTime._hashCode(this)
override def toString: String = _root_.scala.runtime.ScalaRunTime._toString(this)
override def productArity: Int = 3
override def productElement(n: Int): Any = n match {
case 0 => this.list
case 1 => this.stateMap
case 2 => this.optMap
case _ => throw new IndexOutOfBoundsException(n.toString)
}
override def productPrefix: String = "Foo"
}