fn from_net<T: Read>(reader: &mut T) -> Result<Self, Error> {
        const HEADER_WIDTH: usize = PROTOCOL_VERSION_SIZE + FRAME_SIZE_SIZE;
        let mut header_buffer: [u8; HEADER_WIDTH] = [0; HEADER_WIDTH];
        match reader.read_exact(&mut header_buffer) {
            Ok(_) => (),
            Err(e) => {
                error!("End of stream while reading header");
                return Err(e);
            }
        }

        let protocol_version = read_protocol_version(&header_buffer)?;
        let frame_size = read_frame_size(&header_buffer)?;
        let payload_buffer_size = frame_size as usize - HEADER_WIDTH;

        trace!("NetFrame payload size: {}", payload_buffer_size);
        let mut payload_buffer = vec![0; payload_buffer_size];
        reader.read_exact(&mut payload_buffer)?;

        let frame_type = read_frame_type(&payload_buffer)?;
        let payload = payload_buffer.into_iter().skip(FRAME_TYPE_SIZE).collect();
        Ok(NetFrame {
            protocol_version,
            frame_size,
            frame_type,
            payload,
        })
    }
/// Read NetFrame from a network stream
/// Note: from_net does two read operation per frame, this might be
/// inefficient on direct fd since it will trigger syscalls on unbuffered readers.
Read NetFrame from a network stream
Note: from_net does two read operation per frame, this might be
inefficient on direct fd since it will trigger syscalls on unbuffered readers.
Read NetFrame from a network stream Note : from_net does two read operation per frame this might be inefficient on direct fd since it will trigger syscalls on unbuffered readers .
fn from_net<T: Read>(reader: &mut T) -> Result<Self, Error> {
        const HEADER_WIDTH: usize = PROTOCOL_VERSION_SIZE + FRAME_SIZE_SIZE;
        let mut header_buffer: [u8; HEADER_WIDTH] = [0; HEADER_WIDTH];
        match reader.read_exact(&mut header_buffer) {
            Ok(_) => (),
            Err(e) => {
                error!("End of stream while reading header");
                return Err(e);
            }
        }
        let protocol_version = read_protocol_version(&header_buffer)?;
        let frame_size = read_frame_size(&header_buffer)?;
        let payload_buffer_size = frame_size as usize - HEADER_WIDTH;
        trace!("NetFrame payload size: {}", payload_buffer_size);
        let mut payload_buffer = vec![0; payload_buffer_size];
        reader.read_exact(&mut payload_buffer)?;
        let frame_type = read_frame_type(&payload_buffer)?;
        let payload = payload_buffer.into_iter().skip(FRAME_TYPE_SIZE).collect();
        Ok(NetFrame {
            protocol_version,
            frame_size,
            frame_type,
            payload,
        })
    }
fn from_net < T : Read > ( reader : & mut T ) -> Result < Self , Error > { const HEADER_WIDTH : usize = PROTOCOL_VERSION_SIZE + FRAME_SIZE_SIZE ; let mut header_buffer : [ u8 ; HEADER_WIDTH ] = [ 0 ; HEADER_WIDTH ] ; match reader . read_exact ( & mut header_buffer ) { Ok ( _ ) => ( ) , Err ( e ) => { error ! ( " " ) ; return Err ( e ) ; } } let protocol_version = read_protocol_version ( & header_buffer ) ? ; let frame_size = read_frame_size ( & header_buffer ) ? ; let payload_buffer_size = frame_size as usize - HEADER_WIDTH ; trace ! ( " " payload_buffer_size ) ; let mut payload_buffer = vec ! [ 0 payload_buffer_size ] ; reader . read_exact ( & mut payload_buffer ) ? ; let frame_type = read_frame_type ( & payload_buffer ) ? ; let payload = payload_buffer . into_iter ( ) . skip ( FRAME_TYPE_SIZE ) . collect ( ) ; Ok ( NetFrame { protocol_version , frame_size , frame_type , payload , } ) }
Read NetFrame from a network stream
Note: from_net does two read operation per frame, this might be
inefficient on direct fd since it will trigger syscalls on unbuffered readers.
Read NetFrame from a network stream Note : from_net does two read operation per frame this might be inefficient on direct fd since it will trigger syscalls on unbuffered readers .
reader
&mut T