Richard Searle's Blog

Thoughts about software

Archive for February, 2013

Akka IO using byte[]

Posted by eggsearle on February 2, 2013

Used the code from and to send data serialized using ProtoBufs

These examples are all string based, primarily to make the code easy to test with curl.

The string representation of the length can be replaced with its 4 byte binary representation.
The payload is still a byte[], derived from a String for convenience


case s: String => handle.foreach {
h =>
val bb = ByteBuffer.allocate(4)
h write ByteString(bb)
h write ByteString(s.getBytes("US-ASCII"))



def readMessage: IO.Iteratee[String] =
for {
lengthBytes <- take(4)
len = lengthBytes.asByteBuffer.getInt()
bytes <- take(len)
} yield {



Posted in Uncategorized | 6 Comments »