pub fn put<T: BufMut>(&self, buf: &mut T) {
        fn aggr_type<T: BufMut>(buf: &mut T, tag: u8, len: &Option<usize>) {
            buf.put_u8(tag);
            if let Some(len) = len {
                let mut nbuf = itoa::Buffer::new();
                buf.put_slice(nbuf.format(*len).as_bytes());
                buf.put_slice(CRLF);
            } else {
                buf.put_u8(STREAM_START);
                buf.put_slice(CRLF);
            }
        }
        let mut nbuf = itoa::Buffer::new();
        match self {
            Array(len) => aggr_type(buf, ARRAY, len),
            Blob(msg) => {
                buf.put_u8(BLOB);
                if let Some(msg) = msg {
                    buf.put_slice(nbuf.format(msg.len()).as_bytes());
                    buf.put_slice(CRLF);
                    buf.put_slice(msg);
                    buf.put_slice(CRLF);
                } else {
                    buf.put_u8(STREAM_START);
                    buf.put_slice(CRLF);
                }
            }
            BlobStream(msg) => {
                buf.put_u8(BLOB_STREAM);
                buf.put_slice(nbuf.format(msg.len()).as_bytes());
                buf.put_slice(CRLF);
                if !msg.is_empty() {
                    buf.put_slice(msg);
                    buf.put_slice(CRLF);
                }
            }
            Simple(msg) => {
                debug_assert!(
                    msg.iter().all(|&b| b != b'\r' && b != b'\n'),
                    "RESP Simple String can't have \\r or \\n character"
                );
                buf.put_u8(SIMPLE);
                buf.put_slice(msg);
                buf.put_slice(CRLF);
            }
            SimpleError(msg) => {
                debug_assert!(
                    msg.iter().all(|&b| b != b'\r' && b != b'\n'),
                    "RESP Simple Error can't have \\r or \\n character"
                );
                buf.put_u8(ERROR);
                buf.put_slice(msg);
                buf.put_slice(CRLF);
            }
            Number(num) => {
                buf.put_u8(NUMBER);
                buf.put_slice(nbuf.format(*num).as_bytes());
                buf.put_slice(CRLF);
            }
            Null => {
                buf.put_u8(NULL);
                buf.put_slice(CRLF);
            }
            Double(num) => {
                let mut fbuf = ryu::Buffer::new();
                buf.put_u8(DOUBLE);
                buf.put_slice(fbuf.format(num.get()).as_bytes());
                buf.put_slice(CRLF);
            }
            Boolean(b) => {
                buf.put_u8(BOOLEAN);
                if *b {
                    buf.put_slice(BOOL_TRUE);
                } else {
                    buf.put_slice(BOOL_FALSE);
                }
                buf.put_slice(CRLF);
            }
            BlobError(msg) => {
                buf.put_u8(BLOB_ERROR);
                buf.put_slice(nbuf.format(msg.len()).as_bytes());
                buf.put_slice(CRLF);
                buf.put_slice(msg);
                buf.put_slice(CRLF);
            }
            Verbatim(msg) => {
                buf.put_u8(VERBATIM);
                buf.put_slice(nbuf.format(msg.len()).as_bytes());
                buf.put_slice(CRLF);
                buf.put_slice(msg);
                buf.put_slice(CRLF);
            }
            Map(len) => aggr_type(buf, MAP, len),
            Set(len) => aggr_type(buf, SET, len),
            Attribute(len) => {
                buf.put_u8(ATTRIBUTE);
                buf.put_slice(nbuf.format(*len).as_bytes());
                buf.put_slice(CRLF);
            }
            Push(len) => {
                buf.put_u8(PUSH);
                buf.put_slice(nbuf.format(*len).as_bytes());
                buf.put_slice(CRLF);
            }
            BigNumber(digits) => {
                debug_assert!(
                    digits
                        .iter()
                        .all(|b| b == &b'-' || (b'0'..=b'9').contains(b)),
                    "RESP Big Number can only have digits and a sign"
                );
                buf.put_u8(BIG_NUMBER);
                buf.put_slice(digits);
                buf.put_slice(CRLF);
            }
            StreamEnd => {
                buf.put_u8(STREAM_END);
                buf.put_slice(CRLF);
            }
        }
    }
/// Write a token to the buffer.
Write a token to the buffer.
Write a token to the buffer .
pub fn put<T: BufMut>(&self, buf: &mut T) {
        fn aggr_type<T: BufMut>(buf: &mut T, tag: u8, len: &Option<usize>) {
            buf.put_u8(tag);
            if let Some(len) = len {
                let mut nbuf = itoa::Buffer::new();
                buf.put_slice(nbuf.format(*len).as_bytes());
                buf.put_slice(CRLF);
            } else {
                buf.put_u8(STREAM_START);
                buf.put_slice(CRLF);
            }
        }
        let mut nbuf = itoa::Buffer::new();
        match self {
            Array(len) => aggr_type(buf, ARRAY, len),
            Blob(msg) => {
                buf.put_u8(BLOB);
                if let Some(msg) = msg {
                    buf.put_slice(nbuf.format(msg.len()).as_bytes());
                    buf.put_slice(CRLF);
                    buf.put_slice(msg);
                    buf.put_slice(CRLF);
                } else {
                    buf.put_u8(STREAM_START);
                    buf.put_slice(CRLF);
                }
            }
            BlobStream(msg) => {
                buf.put_u8(BLOB_STREAM);
                buf.put_slice(nbuf.format(msg.len()).as_bytes());
                buf.put_slice(CRLF);
                if !msg.is_empty() {
                    buf.put_slice(msg);
                    buf.put_slice(CRLF);
                }
            }
            Simple(msg) => {
                debug_assert!(
                    msg.iter().all(|&b| b != b'\r' && b != b'\n'),
                    "RESP Simple String can't have \\r or \\n character"
                );
                buf.put_u8(SIMPLE);
                buf.put_slice(msg);
                buf.put_slice(CRLF);
            }
            SimpleError(msg) => {
                debug_assert!(
                    msg.iter().all(|&b| b != b'\r' && b != b'\n'),
                    "RESP Simple Error can't have \\r or \\n character"
                );
                buf.put_u8(ERROR);
                buf.put_slice(msg);
                buf.put_slice(CRLF);
            }
            Number(num) => {
                buf.put_u8(NUMBER);
                buf.put_slice(nbuf.format(*num).as_bytes());
                buf.put_slice(CRLF);
            }
            Null => {
                buf.put_u8(NULL);
                buf.put_slice(CRLF);
            }
            Double(num) => {
                let mut fbuf = ryu::Buffer::new();
                buf.put_u8(DOUBLE);
                buf.put_slice(fbuf.format(num.get()).as_bytes());
                buf.put_slice(CRLF);
            }
            Boolean(b) => {
                buf.put_u8(BOOLEAN);
                if *b {
                    buf.put_slice(BOOL_TRUE);
                } else {
                    buf.put_slice(BOOL_FALSE);
                }
                buf.put_slice(CRLF);
            }
            BlobError(msg) => {
                buf.put_u8(BLOB_ERROR);
                buf.put_slice(nbuf.format(msg.len()).as_bytes());
                buf.put_slice(CRLF);
                buf.put_slice(msg);
                buf.put_slice(CRLF);
            }
            Verbatim(msg) => {
                buf.put_u8(VERBATIM);
                buf.put_slice(nbuf.format(msg.len()).as_bytes());
                buf.put_slice(CRLF);
                buf.put_slice(msg);
                buf.put_slice(CRLF);
            }
            Map(len) => aggr_type(buf, MAP, len),
            Set(len) => aggr_type(buf, SET, len),
            Attribute(len) => {
                buf.put_u8(ATTRIBUTE);
                buf.put_slice(nbuf.format(*len).as_bytes());
                buf.put_slice(CRLF);
            }
            Push(len) => {
                buf.put_u8(PUSH);
                buf.put_slice(nbuf.format(*len).as_bytes());
                buf.put_slice(CRLF);
            }
            BigNumber(digits) => {
                debug_assert!(
                    digits
                        .iter()
                        .all(|b| b == &b'-' || (b'0'..=b'9').contains(b)),
                    "RESP Big Number can only have digits and a sign"
                );
                buf.put_u8(BIG_NUMBER);
                buf.put_slice(digits);
                buf.put_slice(CRLF);
            }
            StreamEnd => {
                buf.put_u8(STREAM_END);
                buf.put_slice(CRLF);
            }
        }
    }
pub fn put < T : BufMut > ( & self , buf : & mut T ) { fn aggr_type < T : BufMut > ( buf : & mut T , tag : u8 , len : & Option < usize > ) { buf . put_u8 ( tag ) ; if let Some ( len ) = len { let mut nbuf = itoa :: Buffer :: new ( ) ; buf . put_slice ( nbuf . format ( * len ) . as_bytes ( ) ) ; buf . put_slice ( CRLF ) ; } else { buf . put_u8 ( STREAM_START ) ; buf . put_slice ( CRLF ) ; } } let mut nbuf = itoa :: Buffer :: new ( ) ; match self { Array ( len ) => aggr_type ( buf , ARRAY , len ) , Blob ( msg ) => { buf . put_u8 ( BLOB ) ; if let Some ( msg ) = msg { buf . put_slice ( nbuf . format ( msg . len ( ) ) . as_bytes ( ) ) ; buf . put_slice ( CRLF ) ; buf . put_slice ( msg ) ; buf . put_slice ( CRLF ) ; } else { buf . put_u8 ( STREAM_START ) ; buf . put_slice ( CRLF ) ; } } BlobStream ( msg ) => { buf . put_u8 ( BLOB_STREAM ) ; buf . put_slice ( nbuf . format ( msg . len ( ) ) . as_bytes ( ) ) ; buf . put_slice ( CRLF ) ; if ! msg . is_empty ( ) { buf . put_slice ( msg ) ; buf . put_slice ( CRLF ) ; } } Simple ( msg ) => { debug_assert ! ( msg iter ( ) all ( b b b'\r' b b'\n' ) " \\ \\ " ) ; buf . put_u8 ( SIMPLE ) ; buf . put_slice ( msg ) ; buf . put_slice ( CRLF ) ; } SimpleError ( msg ) => { debug_assert ! ( msg iter ( ) all ( b b b'\r' b b'\n' ) " \\ \\ " ) ; buf . put_u8 ( ERROR ) ; buf . put_slice ( msg ) ; buf . put_slice ( CRLF ) ; } Number ( num ) => { buf . put_u8 ( NUMBER ) ; buf . put_slice ( nbuf . format ( * num ) . as_bytes ( ) ) ; buf . put_slice ( CRLF ) ; } Null => { buf . put_u8 ( NULL ) ; buf . put_slice ( CRLF ) ; } Double ( num ) => { let mut fbuf = ryu :: Buffer :: new ( ) ; buf . put_u8 ( DOUBLE ) ; buf . put_slice ( fbuf . format ( num . get ( ) ) . as_bytes ( ) ) ; buf . put_slice ( CRLF ) ; } Boolean ( b ) => { buf . put_u8 ( BOOLEAN ) ; if * b { buf . put_slice ( BOOL_TRUE ) ; } else { buf . put_slice ( BOOL_FALSE ) ; } buf . put_slice ( CRLF ) ; } BlobError ( msg ) => { buf . put_u8 ( BLOB_ERROR ) ; buf . put_slice ( nbuf . format ( msg . len ( ) ) . as_bytes ( ) ) ; buf . put_slice ( CRLF ) ; buf . put_slice ( msg ) ; buf . put_slice ( CRLF ) ; } Verbatim ( msg ) => { buf . put_u8 ( VERBATIM ) ; buf . put_slice ( nbuf . format ( msg . len ( ) ) . as_bytes ( ) ) ; buf . put_slice ( CRLF ) ; buf . put_slice ( msg ) ; buf . put_slice ( CRLF ) ; } Map ( len ) => aggr_type ( buf , MAP , len ) , Set ( len ) => aggr_type ( buf , SET , len ) , Attribute ( len ) => { buf . put_u8 ( ATTRIBUTE ) ; buf . put_slice ( nbuf . format ( * len ) . as_bytes ( ) ) ; buf . put_slice ( CRLF ) ; } Push ( len ) => { buf . put_u8 ( PUSH ) ; buf . put_slice ( nbuf . format ( * len ) . as_bytes ( ) ) ; buf . put_slice ( CRLF ) ; } BigNumber ( digits ) => { debug_assert ! ( digits iter ( ) all ( b b b'-' ( b'0' b'9' ) contains ( b ) ) " " ) ; buf . put_u8 ( BIG_NUMBER ) ; buf . put_slice ( digits ) ; buf . put_slice ( CRLF ) ; } StreamEnd => { buf . put_u8 ( STREAM_END ) ; buf . put_slice ( CRLF ) ; } } }
Write a token to the buffer.
Write a token to the buffer .
&self
buf
&mut T