private Message parseMessage(ChannelBuffer buffer, int length) { for (int commandLength = 4; commandLength <= length; commandLength++) { String command = buffer.toString(buffer.readerIndex(), commandLength, Charset.forName("US-ASCII")); Log.df("command: {0}", command); MessageType type = MessageType.getByCommand(command); if (type != null) { buffer.readerIndex(buffer.readerIndex() + commandLength); return new Message(type, type.parse(buffer)); } } Log.d("null message"); return null; }