fn write_body<W: Write>(&self, msg: &Message, mut writer: W) -> Result<(), Error> {
        match msg {
            Message::Version {
                version,
                services,
                timestamp,
                address_recv,
                address_from,
                nonce,
                user_agent,
                start_height,
                relay,
            } => {
                writer.write_u32::<LittleEndian>(version.0)?;
                writer.write_u64::<LittleEndian>(services.bits())?;
                // # Security
                // DateTime<Utc>::timestamp has a smaller range than i64, so
                // serialization can not error.
                writer.write_i64::<LittleEndian>(timestamp.timestamp())?;

                address_recv.zcash_serialize(&mut writer)?;
                address_from.zcash_serialize(&mut writer)?;

                writer.write_u64::<LittleEndian>(nonce.0)?;
                user_agent.zcash_serialize(&mut writer)?;
                writer.write_u32::<LittleEndian>(start_height.0)?;
                writer.write_u8(*relay as u8)?;
            }
            Message::Verack => { /* Empty payload -- no-op */ }
            Message::Ping(nonce) => {
                writer.write_u64::<LittleEndian>(nonce.0)?;
            }
            Message::Pong(nonce) => {
                writer.write_u64::<LittleEndian>(nonce.0)?;
            }
            Message::Reject {
                message,
                ccode,
                reason,
                data,
            } => {
                message.zcash_serialize(&mut writer)?;
                writer.write_u8(*ccode as u8)?;
                reason.zcash_serialize(&mut writer)?;
                if let Some(data) = data {
                    writer.write_all(data)?;
                }
            }
            Message::Addr(addrs) => {
                assert!(
                    addrs.len() <= constants::MAX_ADDRS_IN_MESSAGE,
                    "unexpectedly large Addr message: greater than MAX_ADDRS_IN_MESSAGE addresses"
                );

                // Regardless of the way we received the address,
                // Zebra always sends `addr` messages
                let v1_addrs: Vec<AddrV1> = addrs.iter().map(|addr| AddrV1::from(*addr)).collect();
                v1_addrs.zcash_serialize(&mut writer)?
            }
            Message::GetAddr => { /* Empty payload -- no-op */ }
            Message::Block(block) => block.zcash_serialize(&mut writer)?,
            Message::GetBlocks { known_blocks, stop } => {
                writer.write_u32::<LittleEndian>(self.builder.version.0)?;
                known_blocks.zcash_serialize(&mut writer)?;
                stop.unwrap_or(block::Hash([0; 32]))
                    .zcash_serialize(&mut writer)?;
            }
            Message::GetHeaders { known_blocks, stop } => {
                writer.write_u32::<LittleEndian>(self.builder.version.0)?;
                known_blocks.zcash_serialize(&mut writer)?;
                stop.unwrap_or(block::Hash([0; 32]))
                    .zcash_serialize(&mut writer)?;
            }
            Message::Headers(headers) => headers.zcash_serialize(&mut writer)?,
            Message::Inv(hashes) => hashes.zcash_serialize(&mut writer)?,
            Message::GetData(hashes) => hashes.zcash_serialize(&mut writer)?,
            Message::NotFound(hashes) => hashes.zcash_serialize(&mut writer)?,
            Message::Tx(transaction) => transaction.transaction.zcash_serialize(&mut writer)?,
            Message::Mempool => { /* Empty payload -- no-op */ }
            Message::FilterLoad {
                filter,
                hash_functions_count,
                tweak,
                flags,
            } => {
                writer.write_all(&filter.0)?;
                writer.write_u32::<LittleEndian>(*hash_functions_count)?;
                writer.write_u32::<LittleEndian>(tweak.0)?;
                writer.write_u8(*flags)?;
            }
            Message::FilterAdd { data } => {
                writer.write_all(data)?;
            }
            Message::FilterClear => { /* Empty payload -- no-op */ }
        }
        Ok(())
    }
/// Write the body of the message into the given writer. This allows writing
/// the message body prior to writing the header, so that the header can
/// contain a checksum of the message body.
Write the body of the message into the given writer. This allows writing
the message body prior to writing the header, so that the header can
contain a checksum of the message body.
Write the body of the message into the given writer . This allows writing the message body prior to writing the header so that the header can contain a checksum of the message body .
fn write_body<W: Write>(&self, msg: &Message, mut writer: W) -> Result<(), Error> {
        match msg {
            Message::Version {
                version,
                services,
                timestamp,
                address_recv,
                address_from,
                nonce,
                user_agent,
                start_height,
                relay,
            } => {
                writer.write_u32::<LittleEndian>(version.0)?;
                writer.write_u64::<LittleEndian>(services.bits())?;
                // # Security
                // DateTime<Utc>::timestamp has a smaller range than i64, so
                // serialization can not error.
                writer.write_i64::<LittleEndian>(timestamp.timestamp())?;
                address_recv.zcash_serialize(&mut writer)?;
                address_from.zcash_serialize(&mut writer)?;
                writer.write_u64::<LittleEndian>(nonce.0)?;
                user_agent.zcash_serialize(&mut writer)?;
                writer.write_u32::<LittleEndian>(start_height.0)?;
                writer.write_u8(*relay as u8)?;
            }
            Message::Verack => { /* Empty payload -- no-op */ }
            Message::Ping(nonce) => {
                writer.write_u64::<LittleEndian>(nonce.0)?;
            }
            Message::Pong(nonce) => {
                writer.write_u64::<LittleEndian>(nonce.0)?;
            }
            Message::Reject {
                message,
                ccode,
                reason,
                data,
            } => {
                message.zcash_serialize(&mut writer)?;
                writer.write_u8(*ccode as u8)?;
                reason.zcash_serialize(&mut writer)?;
                if let Some(data) = data {
                    writer.write_all(data)?;
                }
            }
            Message::Addr(addrs) => {
                assert!(
                    addrs.len() <= constants::MAX_ADDRS_IN_MESSAGE,
                    "unexpectedly large Addr message: greater than MAX_ADDRS_IN_MESSAGE addresses"
                );
                // Regardless of the way we received the address,
                // Zebra always sends `addr` messages
                let v1_addrs: Vec<AddrV1> = addrs.iter().map(|addr| AddrV1::from(*addr)).collect();
                v1_addrs.zcash_serialize(&mut writer)?
            }
            Message::GetAddr => { /* Empty payload -- no-op */ }
            Message::Block(block) => block.zcash_serialize(&mut writer)?,
            Message::GetBlocks { known_blocks, stop } => {
                writer.write_u32::<LittleEndian>(self.builder.version.0)?;
                known_blocks.zcash_serialize(&mut writer)?;
                stop.unwrap_or(block::Hash([0; 32]))
                    .zcash_serialize(&mut writer)?;
            }
            Message::GetHeaders { known_blocks, stop } => {
                writer.write_u32::<LittleEndian>(self.builder.version.0)?;
                known_blocks.zcash_serialize(&mut writer)?;
                stop.unwrap_or(block::Hash([0; 32]))
                    .zcash_serialize(&mut writer)?;
            }
            Message::Headers(headers) => headers.zcash_serialize(&mut writer)?,
            Message::Inv(hashes) => hashes.zcash_serialize(&mut writer)?,
            Message::GetData(hashes) => hashes.zcash_serialize(&mut writer)?,
            Message::NotFound(hashes) => hashes.zcash_serialize(&mut writer)?,
            Message::Tx(transaction) => transaction.transaction.zcash_serialize(&mut writer)?,
            Message::Mempool => { /* Empty payload -- no-op */ }
            Message::FilterLoad {
                filter,
                hash_functions_count,
                tweak,
                flags,
            } => {
                writer.write_all(&filter.0)?;
                writer.write_u32::<LittleEndian>(*hash_functions_count)?;
                writer.write_u32::<LittleEndian>(tweak.0)?;
                writer.write_u8(*flags)?;
            }
            Message::FilterAdd { data } => {
                writer.write_all(data)?;
            }
            Message::FilterClear => { /* Empty payload -- no-op */ }
        }
        Ok(())
    }
fn write_body < W : Write > ( & self , msg : & Message , mut writer : W ) -> Result < ( ) , Error > { match msg { Message :: Version { version , services , timestamp , address_recv , address_from , nonce , user_agent , start_height , relay , } => { writer . write_u32 :: < LittleEndian > ( version . 0 ) ? ; writer . write_u64 :: < LittleEndian > ( services . bits ( ) ) ? ; // # Security // DateTime<Utc>::timestamp has a smaller range than i64, so // serialization can not error. writer . write_i64 :: < LittleEndian > ( timestamp . timestamp ( ) ) ? ; address_recv . zcash_serialize ( & mut writer ) ? ; address_from . zcash_serialize ( & mut writer ) ? ; writer . write_u64 :: < LittleEndian > ( nonce . 0 ) ? ; user_agent . zcash_serialize ( & mut writer ) ? ; writer . write_u32 :: < LittleEndian > ( start_height . 0 ) ? ; writer . write_u8 ( * relay as u8 ) ? ; } Message :: Verack => { /* Empty payload -- no-op */ } Message :: Ping ( nonce ) => { writer . write_u64 :: < LittleEndian > ( nonce . 0 ) ? ; } Message :: Pong ( nonce ) => { writer . write_u64 :: < LittleEndian > ( nonce . 0 ) ? ; } Message :: Reject { message , ccode , reason , data , } => { message . zcash_serialize ( & mut writer ) ? ; writer . write_u8 ( * ccode as u8 ) ? ; reason . zcash_serialize ( & mut writer ) ? ; if let Some ( data ) = data { writer . write_all ( data ) ? ; } } Message :: Addr ( addrs ) => { assert ! ( addrs len ( ) constants MAX_ADDRS_IN_MESSAGE " " ) ; // Regardless of the way we received the address, // Zebra always sends `addr` messages let v1_addrs : Vec < AddrV1 > = addrs . iter ( ) . map ( | addr | AddrV1 :: from ( * addr ) ) . collect ( ) ; v1_addrs . zcash_serialize ( & mut writer ) ? } Message :: GetAddr => { /* Empty payload -- no-op */ } Message :: Block ( block ) => block . zcash_serialize ( & mut writer ) ? , Message :: GetBlocks { known_blocks , stop } => { writer . write_u32 :: < LittleEndian > ( self . builder . version . 0 ) ? ; known_blocks . zcash_serialize ( & mut writer ) ? ; stop . unwrap_or ( block :: Hash ( [ 0 ; 32 ] ) ) . zcash_serialize ( & mut writer ) ? ; } Message :: GetHeaders { known_blocks , stop } => { writer . write_u32 :: < LittleEndian > ( self . builder . version . 0 ) ? ; known_blocks . zcash_serialize ( & mut writer ) ? ; stop . unwrap_or ( block :: Hash ( [ 0 ; 32 ] ) ) . zcash_serialize ( & mut writer ) ? ; } Message :: Headers ( headers ) => headers . zcash_serialize ( & mut writer ) ? , Message :: Inv ( hashes ) => hashes . zcash_serialize ( & mut writer ) ? , Message :: GetData ( hashes ) => hashes . zcash_serialize ( & mut writer ) ? , Message :: NotFound ( hashes ) => hashes . zcash_serialize ( & mut writer ) ? , Message :: Tx ( transaction ) => transaction . transaction . zcash_serialize ( & mut writer ) ? , Message :: Mempool => { /* Empty payload -- no-op */ } Message :: FilterLoad { filter , hash_functions_count , tweak , flags , } => { writer . write_all ( & filter . 0 ) ? ; writer . write_u32 :: < LittleEndian > ( * hash_functions_count ) ? ; writer . write_u32 :: < LittleEndian > ( tweak . 0 ) ? ; writer . write_u8 ( * flags ) ? ; } Message :: FilterAdd { data } => { writer . write_all ( data ) ? ; } Message :: FilterClear => { /* Empty payload -- no-op */ } } Ok ( ( ) ) }
Write the body of the message into the given writer.
Write the body of the message into the given writer .
&self
msg
&Message
writer
W