State machine based codec for Netty