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

izumi.fundamentals.platform.serialization.IzSerializable.scala Maven / Gradle / Ivy

package izumi.fundamentals.platform.serialization

import izumi.fundamentals.platform.IzPlatformSyntax

import java.io.{ByteArrayOutputStream, ObjectOutputStream}
import java.nio.ByteBuffer
import scala.language.implicitConversions

final class SerializableExt(private val s: Serializable) extends AnyVal {
  def toByteBuffer: ByteBuffer = {
    val byteArrayOutputStream = new ByteArrayOutputStream()
    val objectOutputStream = new ObjectOutputStream(byteArrayOutputStream)
    objectOutputStream.writeObject(s)
    ByteBuffer.wrap(byteArrayOutputStream.toByteArray)
  }
}

trait IzSerializable extends IzPlatformSyntax {
  implicit def toRichSerializable(s: Serializable): SerializableExt = new SerializableExt(s)

}

object IzSerializable extends IzSerializable {}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy