
com.avsystem.commons.serialization.PeekingObjectInput.scala Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of commons-core_2.13 Show documentation
Show all versions of commons-core_2.13 Show documentation
AVSystem commons library for Scala
package com.avsystem.commons
package serialization
/**
* Wrapper over [[ObjectInput]] that lets you peek next field name without advancing the input.
*/
final class PeekingObjectInput(original: ObjectInput) extends ObjectInput {
private[this] var peekedField: FieldInput = _
override def knownSize: Int = original.knownSize
def peekNextFieldName: Opt[String] = peekedField match {
case null if original.hasNext =>
peekedField = original.nextField()
peekedField.fieldName.opt
case null => Opt.Empty
case fi => fi.fieldName.opt
}
def nextField(): FieldInput =
peekedField match {
case null => original.nextField()
case fi =>
peekedField = null
fi
}
def hasNext: Boolean =
peekedField != null || original.hasNext
override def peekField(name: String): Opt[FieldInput] =
original.peekField(name)
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy