Skip to content

Instantly share code, notes, and snippets.

@attribyte
Last active January 2, 2016 00:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save attribyte/0a0ee82334a6178400ea to your computer and use it in GitHub Desktop.
Save attribyte/0a0ee82334a6178400ea to your computer and use it in GitHub Desktop.
trait KinjaMessage extends java.io.Serializable {
def toByteArray: Array[Byte]
}
trait NameValueMessage extends KinjaMessage {
def toNameValuePairs: TraversableOnce[(String, Any)]
override def toByteArray: Array[Byte] = {
val nvBuilder = NameValueSeq.newBuilder()
toNameValuePairs.foreach(nv => {
add(nv, nvBuilder)
})
nvBuilder.build().toByteArray
}
}
trait KinjaMessageMaterializer {
def fromByteArray(bytes: Array[Byte]): KinjaMessage
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment