public ByteBuffer toByteBuffer ( ) { // Allow room for encoded message, plus the type byte ByteBuf buf = Unpooled . buffer ( encodedLength ( ) + 1 ) ; buf . writeByte ( type ( ) . id ) ; encode ( buf ) ; assert buf . writableBytes ( ) == 0 : "Writable bytes remain: " + buf . writableBytes ( ) ; return buf . nioBuffer ( ) ; }
Serializes the type byte followed by the message itself .