/// Push up to an usize worth of bits
Push up to an usize worth of bits
Push up to an usize worth of bits
pub fn push_bits(&mut self, bits: usize, count: usize) {
        if count == 0 {
            return;
        }
        // ensure there are no stray bits
        let bits = bits & (usize::MAX >> (USIZE_BITS - count));
        let bit_offset = self.bit_len & 7;
        debug_assert!(count <= USIZE_BITS - bit_offset);
        let last_written_byte = if bit_offset > 0 {
            self.bytes.pop().unwrap_or(0)
        } else {
            0
        };
        let merged_byte_count = (count + bit_offset + 7) / 8;
        if E::is_le() {
            let merged = last_written_byte as usize | bits << bit_offset;
            self.bytes
                .extend_from_slice(&merged.to_le_bytes()[0..merged_byte_count]);
        } else {
            let merged = ((last_written_byte as usize) << (USIZE_BITS - 8))
                | (bits << (USIZE_BITS - bit_offset - count));
            self.bytes
                .extend_from_slice(&merged.to_be_bytes()[0..merged_byte_count]);
        }
        self.bit_len += count;
    }
pub fn push_bits ( & mut self , bits : usize , count : usize ) { if count == 0 { return ; } // ensure there are no stray bits let bits = bits & ( usize :: MAX >> ( USIZE_BITS - count ) ) ; let bit_offset = self . bit_len & 7 ; debug_assert ! ( count USIZE_BITS bit_offset ) ; let last_written_byte = if bit_offset > 0 { self . bytes . pop ( ) . unwrap_or ( 0 ) } else { 0 } ; let merged_byte_count = ( count + bit_offset + 7 ) / 8 ; if E :: is_le ( ) { let merged = last_written_byte as usize | bits << bit_offset ; self . bytes . extend_from_slice ( & merged . to_le_bytes ( ) [ 0 .. merged_byte_count ] ) ; } else { let merged = ( ( last_written_byte as usize ) << ( USIZE_BITS - 8 ) ) | ( bits << ( USIZE_BITS - bit_offset - count ) ) ; self . bytes . extend_from_slice ( & merged . to_be_bytes ( ) [ 0 .. merged_byte_count ] ) ; } self . bit_len += count ; }
Push up to an usize worth of bits
Push up to an usize worth of bits
&mut self
bits
usize
count
usize