
ru.tinkoff.phobos.decoding.XmlDecoderIterable.scala Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of phobos-core_2.13 Show documentation
Show all versions of phobos-core_2.13 Show documentation
Fast xml data binding library
The newest version!
package ru.tinkoff.phobos.decoding
import javax.xml.stream.XMLStreamConstants
import ru.tinkoff.phobos.decoding.XmlDecoder.createStreamReader
trait XmlDecoderIterable[A] { xmlDecoder: XmlDecoder[A] =>
def decodeFromIterable(
iterable: IterableOnce[Array[Byte]],
charset: String = "UTF-8",
): Either[DecodingError, A] = {
val sr: XmlStreamReader = createStreamReader(charset)
val cursor = new Cursor(sr)
val a = iterable.iterator.foldLeft(elementdecoder) { (decoder: ElementDecoder[A], bytes: Array[Byte]) =>
sr.getInputFeeder.feedInput(bytes, 0, bytes.length)
do {
cursor.next()
} while (cursor.getEventType == XMLStreamConstants.DTD || cursor.getEventType == XMLStreamConstants.START_DOCUMENT)
if (decoder.result(cursor.history).isRight) {
decoder
} else {
decoder.decodeAsElement(cursor, localname, namespaceuri)
}
}
sr.getInputFeeder.endOfInput()
a.result(cursor.history)
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy