Created
April 11, 2013 12:17
-
-
Save jcheype/5362926 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 KryoInjection2(val output: Output) extends Injection[AnyRef, Array[Byte]] { | |
| val input: Input = new Input() | |
| val kryo = KryoBijection.getKryo | |
| def register(clazz: Class[_]) { | |
| kryo.register(clazz) | |
| } | |
| def apply(obj: AnyRef): Array[Byte] = { | |
| output.clear() | |
| kryo.writeClassAndObject(output, obj) | |
| output.toBytes | |
| } | |
| def invert(b: Array[Byte]): Option[AnyRef] = { | |
| input.setBuffer(b) | |
| Option(allCatch.opt(kryo.readClassAndObject(input)).orNull) | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment