Created
July 27, 2009 16:59
-
-
Save jboner/156629 to your computer and use it in GitHub Desktop.
Example of Akka's binary Scala serialization protocol
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
case class User(val usernamePassword: Tuple2[String, String], | |
val email: String, | |
val age: Int) | |
extends Serializable.SBinary[User] { | |
def this() = this(null, null, 0) | |
import sbinary.DefaultProtocol._ | |
implicit object UserFormat extends Format[User] { | |
def reads(in : Input) = User( | |
read[Tuple2[String, String]](in), | |
read[String](in), | |
read[Int](in)) | |
def writes(out: Output, value: User) = { | |
write[Tuple2[String, String]](out, value.usernamePassword) | |
write[String](out, value.email) | |
write[Int](out, value.age) | |
} | |
} | |
def fromBytes(bytes: Array[Byte]) = fromByteArray[User](bytes) | |
def toBytes: Array[Byte] = toByteArray(this) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment