Skip to content

Commit

Permalink
Switches to new internal methods
Browse files Browse the repository at this point in the history
  • Loading branch information
nvollmar authored and danischroeter committed Aug 14, 2023
1 parent 7d26858 commit c28de94
Showing 1 changed file with 11 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,22 @@ import org.apache.pekko.serialization.{ByteBufferSerializer, Serializer}

import java.nio.ByteBuffer

class PekkoKryoSerializer(val system: ExtendedActorSystem) extends Serializer with ByteBufferSerializer {
private val kryoSerializer = new KryoSerializer(system.settings.config, system.dynamicAccess.classLoader) {
override protected[kryo] def configKey: String = "pekko-kryo-serialization"
override protected[kryo] val useManifest: Boolean = system.settings.config.getBoolean(s"$configKey.use-manifests")
override protected[kryo] def prepareKryoInitializer(initializer: scala.DefaultKryoInitializer): Unit = initializer match {
case init: DefaultKryoInitializer => init.system_=(system)
case _ => // nothing to do
}
class PekkoKryoSerializer(val system: ExtendedActorSystem) extends KryoSerializer(system.settings.config, system.dynamicAccess.classLoader) with Serializer with ByteBufferSerializer {
override protected def configKey: String = "pekko-kryo-serialization"
override protected[kryo] val useManifest: Boolean = system.settings.config.getBoolean(s"$configKey.use-manifests")
override protected[kryo] def prepareKryoInitializer(initializer: scala.DefaultKryoInitializer): Unit = initializer match {
case init: DefaultKryoInitializer => init.system_=(system)
case _ => // nothing to do
}

// Serializer API
override def identifier: Int = 123454323
override def includeManifest: Boolean = kryoSerializer.useManifest
override def includeManifest: Boolean = useManifest

override def toBinary(obj: Any): Array[Byte] = kryoSerializer.toBinary(obj)
override def fromBinary(bytes: Array[Byte], clazz: Option[Class[?]]): AnyRef = kryoSerializer.fromBinary(bytes, clazz)
def toBinary(obj: AnyRef): Array[Byte] = toBinaryInternal(obj)
def fromBinary(bytes: Array[Byte], clazz: Option[Class[?]]): AnyRef = fromBinaryInternal(bytes, clazz)

// ByteBufferSerializer API
override def toBinary(obj: Any, buf: ByteBuffer): Unit = kryoSerializer.toBinary(obj, buf)
override def fromBinary(buf: ByteBuffer, manifest: String): AnyRef = kryoSerializer.fromBinary(buf, Some(manifest))
def toBinary(obj: AnyRef, buf: ByteBuffer): Unit = toBinaryInternal(obj.asInstanceOf[Any], buf)
def fromBinary(buf: ByteBuffer, manifest: String): AnyRef = fromBinaryInternal(buf, Some(manifest))
}

0 comments on commit c28de94

Please sign in to comment.