I've been playing with the new I/O features in Akka 2.2 which are really neat when it comes to receiving packets (presented as Akka ByteString) over UDP.
The RTP protocol, although not very complicated, requires a fair amount of bit-level manipulation to extract useful information from the UDP packets. If you are familiar with bit-level operations, it is not difficult to write code to parse packets, however, that code is a bit difficult to read. When you get into RTCP or H264 byte streams, things get a lot more complicated, so I am looking for ways to keep the code easy to process.
I've been experimenting with a little utility class for bit-level manipulation, based on Akka ByteStrings.
Here is what it looks like:
The stuff works quite well, but compared to a hand-written parser, it is a bit slower (just under twice as slow). I have not done Scala Macros before, but I have the feeling that this is the kind of computation which could be moved to compile-time in a macro. Basically turning the bit-shifting code into a set of instructions which can be optimised at compile time. Ideally, something like Erlang's bit pattern matching, although I don't know if it is possible in Scala.
I will try that next.