@ Override public void writeTo ( DataOutput out ) throws IOException { byte leading = 0 ; if ( dest != null ) leading = Util . setFlag ( leading , DEST_SET ) ; if ( sender != null ) leading = Util . setFlag ( leading , SRC_SET ) ; if ( buf != null ) leading = Util . setFlag ( leading , BUF_SET ) ; // 1. write the leading byte first out . write ( leading ) ; // 2. the flags (e.g. OOB, LOW_PRIO), skip the transient flags out . writeShort ( flags ) ; // 3. dest_addr if ( dest != null ) Util . writeAddress ( dest , out ) ; // 4. src_addr if ( sender != null ) Util . writeAddress ( sender , out ) ; // 5. headers Header [ ] hdrs = this . headers ; int size = Headers . size ( hdrs ) ; out . writeShort ( size ) ; if ( size > 0 ) { for ( Header hdr : hdrs ) { if ( hdr == null ) break ; out . writeShort ( hdr . getProtId ( ) ) ; writeHeader ( hdr , out ) ; } } // 6. buf if ( buf != null ) { out . writeInt ( length ) ; out . write ( buf , offset , length ) ; } }
Writes the message to the output stream