public static void serializeTo ( AbstractMessage message , RawDataBuffer out ) { // Do we have a cached version of the raw message ? RawDataBuffer rawMsg = message . getRawMessage ( ) ; if ( rawMsg != null ) { out . writeInt ( rawMsg . size ( ) ) ; rawMsg . writeTo ( out ) ; } else { // Serialize the message out . writeInt ( 0 ) ; // Write a dummy size int startPos = out . size ( ) ; out . writeByte ( message . getType ( ) ) ; message . serializeTo ( out ) ; int endPos = out . size ( ) ; out . writeInt ( endPos - startPos , startPos - 4 ) ; // Update the actual size } }
Serialize a message to the given output stream