pub fn encode_varint<T: Write>(varint: Varint, output: &mut T) -> IoResult<()> {
    let (size, number) = match varint {
        Varint::Unknown => (1, 0xFF),
        Varint::Value(too_big) if too_big > EIGHT_MAX => {
            return Err(IoError::new(ErrorKind::InvalidInput, WriteError::OutOfRange))
        },
        Varint::Value(value) => {
            let mut flag = SMALL_FLAG;
            let mut size = 1;
            // flag bit - 1 = UNKNOWN representation once OR'd with the flag;
            // if we're less than that, we can OR with the flag bit to get a valid Varint
            while value >= (flag - 1) {
                // right shift length bit by 1 to indicate adding a new byte;
                // left shift by 8 because there's a new byte at the end
                flag = flag << (8 - 1);
                size += 1;
            };
            (size, flag | value)
        }
    };

    let mut buffer = [0; 8];
    buffer.as_mut().put_uint(number, size);

    return output.write_all(&buffer[..size]);
}
/// Tries to write an EBML varint using minimal space
Tries to write an EBML varint using minimal space
Tries to write an EBML varint using minimal space
pub fn encode_varint<T: Write>(varint: Varint, output: &mut T) -> IoResult<()> {
    let (size, number) = match varint {
        Varint::Unknown => (1, 0xFF),
        Varint::Value(too_big) if too_big > EIGHT_MAX => {
            return Err(IoError::new(ErrorKind::InvalidInput, WriteError::OutOfRange))
        },
        Varint::Value(value) => {
            let mut flag = SMALL_FLAG;
            let mut size = 1;
            // flag bit - 1 = UNKNOWN representation once OR'd with the flag;
            // if we're less than that, we can OR with the flag bit to get a valid Varint
            while value >= (flag - 1) {
                // right shift length bit by 1 to indicate adding a new byte;
                // left shift by 8 because there's a new byte at the end
                flag = flag << (8 - 1);
                size += 1;
            };
            (size, flag | value)
        }
    };
    let mut buffer = [0; 8];
    buffer.as_mut().put_uint(number, size);
    return output.write_all(&buffer[..size]);
}
pub fn encode_varint < T : Write > ( varint : Varint , output : & mut T ) -> IoResult < ( ) > { let ( size , number ) = match varint { Varint :: Unknown => ( 1 , 0xFF ) , Varint :: Value ( too_big ) if too_big > EIGHT_MAX => { return Err ( IoError :: new ( ErrorKind :: InvalidInput , WriteError :: OutOfRange ) ) } , Varint :: Value ( value ) => { let mut flag = SMALL_FLAG ; let mut size = 1 ; // flag bit - 1 = UNKNOWN representation once OR'd with the flag; // if we're less than that, we can OR with the flag bit to get a valid Varint while value >= ( flag - 1 ) { // right shift length bit by 1 to indicate adding a new byte; // left shift by 8 because there's a new byte at the end flag = flag << ( 8 - 1 ) ; size += 1 ; } ; ( size , flag | value ) } } ; let mut buffer = [ 0 ; 8 ] ; buffer . as_mut ( ) . put_uint ( number , size ) ; return output . write_all ( & buffer [ .. size ] ) ; }
Tries to write an EBML varint using minimal space
Tries to write an EBML varint using minimal space
varint
Varint
output
&mut T
varint
Varint
output
&mut T