pub fn read<R: Read>(r: &mut R) -> io::Result<Self> {
        // this buffer contains the overall length and the amino prefix (for the registered types)
        let mut buf = vec![0; MAX_MSG_LEN];
        let bytes_read = r.read(&mut buf)?;
        if bytes_read < 4 {
            return Err(Error::new(
                ErrorKind::InvalidData,
                "Did not read enough bytes to continue.",
            ));
        }

        let buff: &mut Cursor<Vec<u8>> = &mut buf.into_buf();
        let len = decode_varint(buff).unwrap();
        if len > MAX_MSG_LEN as u64 {
            return Err(Error::new(ErrorKind::InvalidData, "RPC message too large."));
        }
        let mut amino_pre = vec![0; 4];
        buff.read_exact(&mut amino_pre)?;
        buff.set_position(0);
        let total_len = encoded_len_varint(len).checked_add(len as usize).unwrap();
        let rem = buff.get_ref()[..total_len].to_vec();
        match amino_pre {
            ref pp if *pp == *PP_PREFIX => Ok(Request::PoisonPill(PoisonPillMsg {})),
            ref vt if *vt == *VOTE_PREFIX => Ok(Request::SignVote(SignVoteRequest::decode(&rem)?)),
            ref pr if *pr == *PROPOSAL_PREFIX => {
                Ok(Request::SignProposal(SignProposalRequest::decode(&rem)?))
            }
            ref pubk if *pubk == *PUBKEY_PREFIX => {
                Ok(Request::ShowPublicKey(PubKeyMsg::decode(&rem)?))
            }
            ref ping if *ping == *PING_PREFIX => Ok(Request::ReplyPing(PingRequest::decode(&rem)?)),
            _ => Err(Error::new(
                ErrorKind::InvalidData,
                "Received unknown RPC message.",
            )),
        }
    }
/// Read a request from the given readable
Read a request from the given readable
Read a request from the given readable
pub fn read<R: Read>(r: &mut R) -> io::Result<Self> {
        // this buffer contains the overall length and the amino prefix (for the registered types)
        let mut buf = vec![0; MAX_MSG_LEN];
        let bytes_read = r.read(&mut buf)?;
        if bytes_read < 4 {
            return Err(Error::new(
                ErrorKind::InvalidData,
                "Did not read enough bytes to continue.",
            ));
        }
        let buff: &mut Cursor<Vec<u8>> = &mut buf.into_buf();
        let len = decode_varint(buff).unwrap();
        if len > MAX_MSG_LEN as u64 {
            return Err(Error::new(ErrorKind::InvalidData, "RPC message too large."));
        }
        let mut amino_pre = vec![0; 4];
        buff.read_exact(&mut amino_pre)?;
        buff.set_position(0);
        let total_len = encoded_len_varint(len).checked_add(len as usize).unwrap();
        let rem = buff.get_ref()[..total_len].to_vec();
        match amino_pre {
            ref pp if *pp == *PP_PREFIX => Ok(Request::PoisonPill(PoisonPillMsg {})),
            ref vt if *vt == *VOTE_PREFIX => Ok(Request::SignVote(SignVoteRequest::decode(&rem)?)),
            ref pr if *pr == *PROPOSAL_PREFIX => {
                Ok(Request::SignProposal(SignProposalRequest::decode(&rem)?))
            }
            ref pubk if *pubk == *PUBKEY_PREFIX => {
                Ok(Request::ShowPublicKey(PubKeyMsg::decode(&rem)?))
            }
            ref ping if *ping == *PING_PREFIX => Ok(Request::ReplyPing(PingRequest::decode(&rem)?)),
            _ => Err(Error::new(
                ErrorKind::InvalidData,
                "Received unknown RPC message.",
            )),
        }
    }
pub fn read < R : Read > ( r : & mut R ) -> io :: Result < Self > { // this buffer contains the overall length and the amino prefix (for the registered types) let mut buf = vec ! [ 0 MAX_MSG_LEN ] ; let bytes_read = r . read ( & mut buf ) ? ; if bytes_read < 4 { return Err ( Error :: new ( ErrorKind :: InvalidData , " " , ) ) ; } let buff : & mut Cursor < Vec < u8 > > = & mut buf . into_buf ( ) ; let len = decode_varint ( buff ) . unwrap ( ) ; if len > MAX_MSG_LEN as u64 { return Err ( Error :: new ( ErrorKind :: InvalidData , " " ) ) ; } let mut amino_pre = vec ! [ 0 4 ] ; buff . read_exact ( & mut amino_pre ) ? ; buff . set_position ( 0 ) ; let total_len = encoded_len_varint ( len ) . checked_add ( len as usize ) . unwrap ( ) ; let rem = buff . get_ref ( ) [ .. total_len ] . to_vec ( ) ; match amino_pre { ref pp if * pp == * PP_PREFIX => Ok ( Request :: PoisonPill ( PoisonPillMsg { } ) ) , ref vt if * vt == * VOTE_PREFIX => Ok ( Request :: SignVote ( SignVoteRequest :: decode ( & rem ) ? ) ) , ref pr if * pr == * PROPOSAL_PREFIX => { Ok ( Request :: SignProposal ( SignProposalRequest :: decode ( & rem ) ? ) ) } ref pubk if * pubk == * PUBKEY_PREFIX => { Ok ( Request :: ShowPublicKey ( PubKeyMsg :: decode ( & rem ) ? ) ) } ref ping if * ping == * PING_PREFIX => Ok ( Request :: ReplyPing ( PingRequest :: decode ( & rem ) ? ) ) , _ => Err ( Error :: new ( ErrorKind :: InvalidData , " " , ) ) , } }
Read a request from the given readable
Read a request from the given readable
r
&mut R
r
&mut R