Skip to content

Instantly share code, notes, and snippets.

@jcheype
Created April 11, 2013 12:17
Show Gist options
  • Select an option

  • Save jcheype/5362926 to your computer and use it in GitHub Desktop.

Select an option

Save jcheype/5362926 to your computer and use it in GitHub Desktop.
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