Created
February 25, 2020 12:02
-
-
Save skvithalani/3e446aa08e212ed5c44b6a470c1c2878 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 _ => | |
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 | |
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