pub fn write_content_length(n: usize, bytes: &mut BytesMut) {
    bytes.put_slice(b"\r\ncontent-length: ");

    if n < 10 {
        bytes.put_u8(DIGITS_START + (n as u8));
    } else if n < 100 {
        let n = n as u8;

        let d10 = n / 10;
        let d1 = n % 10;

        bytes.put_u8(DIGITS_START + d10);
        bytes.put_u8(DIGITS_START + d1);
    } else if n < 1000 {
        let n = n as u16;

        let d100 = (n / 100) as u8;
        let d10 = ((n / 10) % 10) as u8;
        let d1 = (n % 10) as u8;

        bytes.put_u8(DIGITS_START + d100);
        bytes.put_u8(DIGITS_START + d10);
        bytes.put_u8(DIGITS_START + d1);
    } else if n < 10_000 {
        let n = n as u16;

        let d1000 = (n / 1000) as u8;
        let d100 = ((n / 100) % 10) as u8;
        let d10 = ((n / 10) % 10) as u8;
        let d1 = (n % 10) as u8;

        bytes.put_u8(DIGITS_START + d1000);
        bytes.put_u8(DIGITS_START + d100);
        bytes.put_u8(DIGITS_START + d10);
        bytes.put_u8(DIGITS_START + d1);
    } else if n < 100_000 {
        let n = n as u32;

        let d10000 = (n / 10000) as u8;
        let d1000 = ((n / 1000) % 10) as u8;
        let d100 = ((n / 100) % 10) as u8;
        let d10 = ((n / 10) % 10) as u8;
        let d1 = (n % 10) as u8;

        bytes.put_u8(DIGITS_START + d10000);
        bytes.put_u8(DIGITS_START + d1000);
        bytes.put_u8(DIGITS_START + d100);
        bytes.put_u8(DIGITS_START + d10);
        bytes.put_u8(DIGITS_START + d1);
    } else if n < 1_000_000 {
        let n = n as u32;

        let d100000 = (n / 100_000) as u8;
        let d10000 = ((n / 10000) % 10) as u8;
        let d1000 = ((n / 1000) % 10) as u8;
        let d100 = ((n / 100) % 10) as u8;
        let d10 = ((n / 10) % 10) as u8;
        let d1 = (n % 10) as u8;

        bytes.put_u8(DIGITS_START + d100000);
        bytes.put_u8(DIGITS_START + d10000);
        bytes.put_u8(DIGITS_START + d1000);
        bytes.put_u8(DIGITS_START + d100);
        bytes.put_u8(DIGITS_START + d10);
        bytes.put_u8(DIGITS_START + d1);
    } else {
        write_usize(n, bytes);
    }

    bytes.put_slice(b"\r\n");
}
/// NOTE: bytes object has to contain enough space
bytes object has to contain enough space
bytes object has to contain enough space
pub fn write_content_length(n: usize, bytes: &mut BytesMut) {
    bytes.put_slice(b"\r\ncontent-length: ");
    if n < 10 {
        bytes.put_u8(DIGITS_START + (n as u8));
    } else if n < 100 {
        let n = n as u8;
        let d10 = n / 10;
        let d1 = n % 10;
        bytes.put_u8(DIGITS_START + d10);
        bytes.put_u8(DIGITS_START + d1);
    } else if n < 1000 {
        let n = n as u16;
        let d100 = (n / 100) as u8;
        let d10 = ((n / 10) % 10) as u8;
        let d1 = (n % 10) as u8;
        bytes.put_u8(DIGITS_START + d100);
        bytes.put_u8(DIGITS_START + d10);
        bytes.put_u8(DIGITS_START + d1);
    } else if n < 10_000 {
        let n = n as u16;
        let d1000 = (n / 1000) as u8;
        let d100 = ((n / 100) % 10) as u8;
        let d10 = ((n / 10) % 10) as u8;
        let d1 = (n % 10) as u8;
        bytes.put_u8(DIGITS_START + d1000);
        bytes.put_u8(DIGITS_START + d100);
        bytes.put_u8(DIGITS_START + d10);
        bytes.put_u8(DIGITS_START + d1);
    } else if n < 100_000 {
        let n = n as u32;
        let d10000 = (n / 10000) as u8;
        let d1000 = ((n / 1000) % 10) as u8;
        let d100 = ((n / 100) % 10) as u8;
        let d10 = ((n / 10) % 10) as u8;
        let d1 = (n % 10) as u8;
        bytes.put_u8(DIGITS_START + d10000);
        bytes.put_u8(DIGITS_START + d1000);
        bytes.put_u8(DIGITS_START + d100);
        bytes.put_u8(DIGITS_START + d10);
        bytes.put_u8(DIGITS_START + d1);
    } else if n < 1_000_000 {
        let n = n as u32;
        let d100000 = (n / 100_000) as u8;
        let d10000 = ((n / 10000) % 10) as u8;
        let d1000 = ((n / 1000) % 10) as u8;
        let d100 = ((n / 100) % 10) as u8;
        let d10 = ((n / 10) % 10) as u8;
        let d1 = (n % 10) as u8;
        bytes.put_u8(DIGITS_START + d100000);
        bytes.put_u8(DIGITS_START + d10000);
        bytes.put_u8(DIGITS_START + d1000);
        bytes.put_u8(DIGITS_START + d100);
        bytes.put_u8(DIGITS_START + d10);
        bytes.put_u8(DIGITS_START + d1);
    } else {
        write_usize(n, bytes);
    }
    bytes.put_slice(b"\r\n");
}
pub fn write_content_length ( n : usize , bytes : & mut BytesMut ) { bytes . put_slice ( b" \r \n " ) ; if n < 10 { bytes . put_u8 ( DIGITS_START + ( n as u8 ) ) ; } else if n < 100 { let n = n as u8 ; let d10 = n / 10 ; let d1 = n % 10 ; bytes . put_u8 ( DIGITS_START + d10 ) ; bytes . put_u8 ( DIGITS_START + d1 ) ; } else if n < 1000 { let n = n as u16 ; let d100 = ( n / 100 ) as u8 ; let d10 = ( ( n / 10 ) % 10 ) as u8 ; let d1 = ( n % 10 ) as u8 ; bytes . put_u8 ( DIGITS_START + d100 ) ; bytes . put_u8 ( DIGITS_START + d10 ) ; bytes . put_u8 ( DIGITS_START + d1 ) ; } else if n < 10_000 { let n = n as u16 ; let d1000 = ( n / 1000 ) as u8 ; let d100 = ( ( n / 100 ) % 10 ) as u8 ; let d10 = ( ( n / 10 ) % 10 ) as u8 ; let d1 = ( n % 10 ) as u8 ; bytes . put_u8 ( DIGITS_START + d1000 ) ; bytes . put_u8 ( DIGITS_START + d100 ) ; bytes . put_u8 ( DIGITS_START + d10 ) ; bytes . put_u8 ( DIGITS_START + d1 ) ; } else if n < 100_000 { let n = n as u32 ; let d10000 = ( n / 10000 ) as u8 ; let d1000 = ( ( n / 1000 ) % 10 ) as u8 ; let d100 = ( ( n / 100 ) % 10 ) as u8 ; let d10 = ( ( n / 10 ) % 10 ) as u8 ; let d1 = ( n % 10 ) as u8 ; bytes . put_u8 ( DIGITS_START + d10000 ) ; bytes . put_u8 ( DIGITS_START + d1000 ) ; bytes . put_u8 ( DIGITS_START + d100 ) ; bytes . put_u8 ( DIGITS_START + d10 ) ; bytes . put_u8 ( DIGITS_START + d1 ) ; } else if n < 1_000_000 { let n = n as u32 ; let d100000 = ( n / 100_000 ) as u8 ; let d10000 = ( ( n / 10000 ) % 10 ) as u8 ; let d1000 = ( ( n / 1000 ) % 10 ) as u8 ; let d100 = ( ( n / 100 ) % 10 ) as u8 ; let d10 = ( ( n / 10 ) % 10 ) as u8 ; let d1 = ( n % 10 ) as u8 ; bytes . put_u8 ( DIGITS_START + d100000 ) ; bytes . put_u8 ( DIGITS_START + d10000 ) ; bytes . put_u8 ( DIGITS_START + d1000 ) ; bytes . put_u8 ( DIGITS_START + d100 ) ; bytes . put_u8 ( DIGITS_START + d10 ) ; bytes . put_u8 ( DIGITS_START + d1 ) ; } else { write_usize ( n , bytes ) ; } bytes . put_slice ( b" \r \n " ) ; }
NOTE: bytes object has to contain enough space
NOTE : bytes object has to contain enough space
n
usize
bytes
&mut BytesMut
n
usize
bytes
&mut BytesMut