Skip to content

Instantly share code, notes, and snippets.

@stefanobaghino
Created May 12, 2017 14:29
Show Gist options
  • Save stefanobaghino/5c5b01bdd273f64f181303f768ab008a to your computer and use it in GitHub Desktop.
Save stefanobaghino/5c5b01bdd273f64f181303f768ab008a to your computer and use it in GitHub Desktop.
scalameter PrimitivePickler for generic use cases
case class Point(x: Double, y: Double)
final class PointPickler extends PrimitivePickler[Point] {
override protected def bits: Int = java.lang.Double.SIZE * 2
override protected def unwrap(from: ByteBuffer): Point = Point(from.getDouble, from.getDouble)
override def pickle(x: Point): Array[Byte] = byteBuffer.putDouble(x.x).putDouble(x.y).array()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment