Last active
February 25, 2020 11:56
-
-
Save skvithalani/e1deba416104202984db4355e5f46be6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class BorerAkkaSerializer() extends Serializer with Codecs { | |
override def identifier: Int = 19923 | |
override def includeManifest: Boolean = true | |
override def toBinary(o: AnyRef): Array[Byte] = o match { | |
case x: Zoo => Cbor.encode(x).toByteArray | |
case x: Park => Cbor.encode(x).toByteArray | |
case x: Theatre => Cbor.encode(x).toByteArray | |
case _ => | |
throw new RuntimeException(s"does not support encoding of $o") | |
} | |
override def fromBinary(bytes: Array[Byte], manifest: Option[Class[_]]): AnyRef = { | |
if (classOf[Zoo].isAssignableFrom(manifest.get)) | |
Cbor.decode(bytes).to[Zoo].value | |
else if (classOf[Park].isAssignableFrom(manifest.get)) | |
Cbor.decode(bytes).to[Park].value | |
else if (classOf[Theatre].isAssignableFrom(manifest.get)) | |
Cbor.decode(bytes).to[Theatre].value | |
else | |
throw new RuntimeException(s"does not support decoding of ${manifest.get}") | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment