com.twitter.finagle.zipkin.thriftscala.LogEntry.scala Maven / Gradle / Ivy
/**
* Generated by Scrooge
* version: 4.10.0
* rev: 93b5383f7afff1301467b8941baf6ab35959a15c
* built at: 20160907-143258
*/
package com.twitter.finagle.zipkin.thriftscala
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}
object LogEntry extends ThriftStructCodec3[LogEntry] {
private val NoPassthroughFields = immutable$Map.empty[Short, TFieldBlob]
val Struct = new TStruct("LogEntry")
val CategoryField = new TField("category", TType.STRING, 1)
val CategoryFieldManifest = implicitly[Manifest[String]]
val MessageField = new TField("message", TType.STRING, 2)
val MessageFieldManifest = implicitly[Manifest[String]]
/**
* Field information in declaration order.
*/
lazy val fieldInfos: scala.List[ThriftStructFieldInfo] = scala.List[ThriftStructFieldInfo](
new ThriftStructFieldInfo(
CategoryField,
false,
false,
CategoryFieldManifest,
_root_.scala.None,
_root_.scala.None,
immutable$Map.empty[String, String],
immutable$Map.empty[String, String],
None
),
new ThriftStructFieldInfo(
MessageField,
false,
false,
MessageFieldManifest,
_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: LogEntry): Unit = {
}
def withoutPassthroughFields(original: LogEntry): LogEntry =
new Immutable(
category =
{
val field = original.category
field
},
message =
{
val field = original.message
field
}
)
override def encode(_item: LogEntry, _oproto: TProtocol): Unit = {
_item.write(_oproto)
}
private[this] def lazyDecode(_iprot: LazyTProtocol): LogEntry = {
var categoryOffset: Int = -1
var messageOffset: Int = -1
var _passthroughFields: Builder[(Short, TFieldBlob), immutable$Map[Short, TFieldBlob]] = null
var _done = false
val _start_offset = _iprot.offset
_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 =>
categoryOffset = _iprot.offsetSkipString
case _actualType =>
val _expectedType = TType.STRING
throw new TProtocolException(
"Received wrong type for field 'category' (expected=%s, actual=%s).".format(
ttypeToString(_expectedType),
ttypeToString(_actualType)
)
)
}
case 2 =>
_field.`type` match {
case TType.STRING =>
messageOffset = _iprot.offsetSkipString
case _actualType =>
val _expectedType = TType.STRING
throw new TProtocolException(
"Received wrong type for field 'message' (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 LazyImmutable(
_iprot,
_iprot.buffer,
_start_offset,
_iprot.offset,
categoryOffset,
messageOffset,
if (_passthroughFields == null)
NoPassthroughFields
else
_passthroughFields.result()
)
}
override def decode(_iprot: TProtocol): LogEntry =
_iprot match {
case i: LazyTProtocol => lazyDecode(i)
case i => eagerDecode(i)
}
private[this] def eagerDecode(_iprot: TProtocol): LogEntry = {
var category: String = null
var message: 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.STRING =>
category = readCategoryValue(_iprot)
case _actualType =>
val _expectedType = TType.STRING
throw new TProtocolException(
"Received wrong type for field 'category' (expected=%s, actual=%s).".format(
ttypeToString(_expectedType),
ttypeToString(_actualType)
)
)
}
case 2 =>
_field.`type` match {
case TType.STRING =>
message = readMessageValue(_iprot)
case _actualType =>
val _expectedType = TType.STRING
throw new TProtocolException(
"Received wrong type for field 'message' (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 Immutable(
category,
message,
if (_passthroughFields == null)
NoPassthroughFields
else
_passthroughFields.result()
)
}
def apply(
category: String,
message: String
): LogEntry =
new Immutable(
category,
message
)
def unapply(_item: LogEntry): _root_.scala.Option[scala.Product2[String, String]] = _root_.scala.Some(_item)
@inline private def readCategoryValue(_iprot: TProtocol): String = {
_iprot.readString()
}
@inline private def writeCategoryField(category_item: String, _oprot: TProtocol): Unit = {
_oprot.writeFieldBegin(CategoryField)
writeCategoryValue(category_item, _oprot)
_oprot.writeFieldEnd()
}
@inline private def writeCategoryValue(category_item: String, _oprot: TProtocol): Unit = {
_oprot.writeString(category_item)
}
@inline private def readMessageValue(_iprot: TProtocol): String = {
_iprot.readString()
}
@inline private def writeMessageField(message_item: String, _oprot: TProtocol): Unit = {
_oprot.writeFieldBegin(MessageField)
writeMessageValue(message_item, _oprot)
_oprot.writeFieldEnd()
}
@inline private def writeMessageValue(message_item: String, _oprot: TProtocol): Unit = {
_oprot.writeString(message_item)
}
object Immutable extends ThriftStructCodec3[LogEntry] {
override def encode(_item: LogEntry, _oproto: TProtocol): Unit = { _item.write(_oproto) }
override def decode(_iprot: TProtocol): LogEntry = LogEntry.decode(_iprot)
override lazy val metaData: ThriftStructMetaData[LogEntry] = LogEntry.metaData
}
/**
* The default read-only implementation of LogEntry. You typically should not need to
* directly reference this class; instead, use the LogEntry.apply method to construct
* new instances.
*/
class Immutable(
val category: String,
val message: String,
override val _passthroughFields: immutable$Map[Short, TFieldBlob])
extends LogEntry {
def this(
category: String,
message: String
) = this(
category,
message,
Map.empty
)
}
/**
* 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,
categoryOffset: Int,
messageOffset: Int,
override val _passthroughFields: immutable$Map[Short, TFieldBlob])
extends LogEntry {
override def write(_oprot: TProtocol): Unit = {
_oprot match {
case i: LazyTProtocol => i.writeRaw(_buf, _start_offset, _end_offset - _start_offset)
case _ => super.write(_oprot)
}
}
lazy val category: String =
if (categoryOffset == -1)
null
else {
_proto.decodeString(_buf, categoryOffset)
}
lazy val message: String =
if (messageOffset == -1)
null
else {
_proto.decodeString(_buf, messageOffset)
}
/**
* 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 = super.hashCode
}
/**
* This Proxy trait allows you to extend the LogEntry trait with additional state or
* behavior and implement the read-only methods from LogEntry using an underlying
* instance.
*/
trait Proxy extends LogEntry {
protected def _underlying_LogEntry: LogEntry
override def category: String = _underlying_LogEntry.category
override def message: String = _underlying_LogEntry.message
override def _passthroughFields = _underlying_LogEntry._passthroughFields
}
}
trait LogEntry
extends ThriftStruct
with scala.Product2[String, String]
with HasThriftStructCodec3[LogEntry]
with java.io.Serializable
{
import LogEntry._
def category: String
def message: String
def _passthroughFields: immutable$Map[Short, TFieldBlob] = immutable$Map.empty
def _1 = category
def _2 = message
/**
* 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 (category ne null) {
writeCategoryValue(category, _oprot)
_root_.scala.Some(LogEntry.CategoryField)
} else {
_root_.scala.None
}
case 2 =>
if (message ne null) {
writeMessageValue(message, _oprot)
_root_.scala.Some(LogEntry.MessageField)
} 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): LogEntry = {
var category: String = this.category
var message: String = this.message
var _passthroughFields = this._passthroughFields
_blob.id match {
case 1 =>
category = readCategoryValue(_blob.read)
case 2 =>
message = readMessageValue(_blob.read)
case _ => _passthroughFields += (_blob.id -> _blob)
}
new Immutable(
category,
message,
_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): LogEntry = {
var category: String = this.category
var message: String = this.message
_fieldId match {
case 1 =>
category = null
case 2 =>
message = null
case _ =>
}
new Immutable(
category,
message,
_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 unsetCategory: LogEntry = unsetField(1)
def unsetMessage: LogEntry = unsetField(2)
override def write(_oprot: TProtocol): Unit = {
LogEntry.validate(this)
_oprot.writeStructBegin(Struct)
if (category ne null) writeCategoryField(category, _oprot)
if (message ne null) writeMessageField(message, _oprot)
if (_passthroughFields.nonEmpty) {
_passthroughFields.values.foreach { _.write(_oprot) }
}
_oprot.writeFieldStop()
_oprot.writeStructEnd()
}
def copy(
category: String = this.category,
message: String = this.message,
_passthroughFields: immutable$Map[Short, TFieldBlob] = this._passthroughFields
): LogEntry =
new Immutable(
category,
message,
_passthroughFields
)
override def canEqual(other: Any): Boolean = other.isInstanceOf[LogEntry]
override def equals(other: Any): Boolean =
canEqual(other) &&
_root_.scala.runtime.ScalaRunTime._equals(this, other) &&
_passthroughFields == other.asInstanceOf[LogEntry]._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 = 2
override def productElement(n: Int): Any = n match {
case 0 => this.category
case 1 => this.message
case _ => throw new IndexOutOfBoundsException(n.toString)
}
override def productPrefix: String = "LogEntry"
def _codec: ThriftStructCodec3[LogEntry] = LogEntry
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy