pub fn write_varint<W: Write>(val: &i32, writer: &mut W) -> Result<()> {
    /* Define some helpful values for dealing with varints */
    let msb: u8 = 0b10000000;
    let mask: u32 = !(msb as u32);

    /* Make the value unsigned to avoid weird signed behavior when bit-shifting */
    let mut val = *val as u32;

    let mut vec: Vec<u8> = Vec::new();
    for _ in 0..5 {
        /* Get the last 7 bits and cast to an u8.
         * Also right-shift the value to advance further. */
        let mut tmp = (val & mask) as u8;
        val >>= 7;

        /* If there's still something to write, set the most significant bit and continue */
        if val != 0 {
            tmp |= msb;
            vec.push(tmp);
        } else {
            vec.push(tmp);
            break;
        }
    }

    Ok(writer.write_all(&vec)?)
}
/// Write a single i32 to the Writer, as a varint
Write a single i32 to the Writer, as a varint
Write a single i32 to the Writer as a varint
pub fn write_varint<W: Write>(val: &i32, writer: &mut W) -> Result<()> {
    /* Define some helpful values for dealing with varints */
    let msb: u8 = 0b10000000;
    let mask: u32 = !(msb as u32);
    /* Make the value unsigned to avoid weird signed behavior when bit-shifting */
    let mut val = *val as u32;
    let mut vec: Vec<u8> = Vec::new();
    for _ in 0..5 {
        /* Get the last 7 bits and cast to an u8.
         * Also right-shift the value to advance further. */
        let mut tmp = (val & mask) as u8;
        val >>= 7;
        /* If there's still something to write, set the most significant bit and continue */
        if val != 0 {
            tmp |= msb;
            vec.push(tmp);
        } else {
            vec.push(tmp);
            break;
        }
    }
    Ok(writer.write_all(&vec)?)
}
pub fn write_varint < W : Write > ( val : & i32 , writer : & mut W ) -> Result < ( ) > { /* Define some helpful values for dealing with varints */ let msb : u8 = 0b10000000 ; let mask : u32 = ! ( msb as u32 ) ; /* Make the value unsigned to avoid weird signed behavior when bit-shifting */ let mut val = * val as u32 ; let mut vec : Vec < u8 > = Vec :: new ( ) ; for _ in 0 .. 5 { /* Get the last 7 bits and cast to an u8.
         * Also right-shift the value to advance further. */ let mut tmp = ( val & mask ) as u8 ; val >>= 7 ; /* If there's still something to write, set the most significant bit and continue */ if val != 0 { tmp |= msb ; vec . push ( tmp ) ; } else { vec . push ( tmp ) ; break ; } } Ok ( writer . write_all ( & vec ) ? ) }
Write a single i32 to the Writer, as a varint
Write a single i32 to the Writer as a varint
val
&i32
writer
&mut W
val
&i32
writer
&mut W