
com.avsystem.commons.serialization.OptionalFieldValueCodec.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
import com.avsystem.commons.meta.OptionLike
final class OptionalFieldValueCodec[O, V](optionLike: OptionLike.Aux[O, V], valueCodec: GenCodec[V]) extends GenCodec[O] {
def read(input: Input): O =
if (optionLike.ignoreNulls && input.readNull()) optionLike.none
else optionLike.some(valueCodec.read(input))
def write(output: Output, value: O): Unit =
optionLike.fold(value, output.writeNull())(valueCodec.write(output, _))
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy