
zeroformatter.ZeroFormatter.scala Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of zero-formatter_2.12 Show documentation
Show all versions of zero-formatter_2.12 Show documentation
Implementation of ZeroFormatter in Scala
The newest version!
package zeroformatter
object ZeroFormatter {
def serialize[T](value: T)(implicit F: Formatter[T]): Array[Byte] = {
val encoder = ArrayEncoder(new Array[Byte](F.length.getOrElse(0)))
val byteSize = F.serialize(encoder, 0, value)
val result = encoder.toByteArray
if(result.length != byteSize) BinaryUtil.resize(result, byteSize)
else result
}
def deserialize[T](bytes: Array[Byte])(implicit F: Formatter[T]): T =
F.deserialize(ArrayDecoder(bytes, 0))
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy