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

com.avsystem.commons.serialization.DefaultCaseObjectInput.scala Maven / Gradle / Ivy

The newest version!
package com.avsystem.commons
package serialization

import com.avsystem.commons.serialization.GenCodec.ReadFailure

final class DefaultCaseObjectInput(firstField: FieldInput, actualInput: ObjectInput, caseFieldName: String)
  extends ObjectInput {

  override def knownSize: Int = actualInput.knownSize

  private[this] var atFirstField = true

  def hasNext: Boolean = atFirstField || actualInput.hasNext
  def nextField(): FieldInput =
    if (atFirstField) {
      atFirstField = false
      firstField
    } else {
      val field = actualInput.nextField()
      if (field.fieldName == caseFieldName) {
        throw new ReadFailure(s"$caseFieldName field found too far into the object")
      }
      field
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy