Created
September 30, 2016 20:30
-
-
Save t3hnar/560e1926376c0df6a354ebe978c07573 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
package com.evolutiongaming.serialization | |
import java.nio.charset.Charset | |
import akka.serialization.SerializerWithStringManifest | |
import scala.util.control.NoStackTrace | |
class BrokenSerializer extends SerializerWithStringManifest { | |
import BrokenSerializer._ | |
def identifier = 64574685 | |
def manifest(x: AnyRef) = x match { | |
case x: FailTo => x.getClass.getName | |
case _ => sys error s"Unexpected $x" | |
} | |
def toBinary(x: AnyRef) = x match { | |
case x: FailTo.Serialize => throw new FailToSerializeException | |
case x: FailTo.Deserialize => x.value getBytes Utf8 | |
case _ => sys error s"Unexpected $x" | |
} | |
def fromBinary(bytes: Array[Byte], manifest: String) = manifest match { | |
case FailTo.Deserialize.Manifest => throw new FailToDeserializeException | |
case FailTo.Serialize.Manifest => new String(bytes, Utf8) | |
case _ => sys error s"Unexpected $manifest" | |
} | |
} | |
object BrokenSerializer { | |
lazy val Utf8: Charset = Charset.forName("UTF-8") | |
lazy val MsgManifest = classOf[FailTo].toString | |
sealed trait FailTo | |
object FailTo { | |
case class Serialize(value: String) extends FailTo | |
object Serialize { | |
lazy val Manifest: String = classOf[Serialize].getName | |
} | |
case class Deserialize(value: String) extends FailTo | |
object Deserialize { | |
lazy val Manifest: String = classOf[Deserialize].getName | |
} | |
} | |
} | |
class FailToSerializeException extends RuntimeException with NoStackTrace | |
class FailToDeserializeException extends RuntimeException with NoStackTrace |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment