1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#![feature(alloc, heap_api)]

extern crate alloc;

pub mod reader;

pub use reader::{BitReader,BigEndian,LittleEndian};

mod util {
    use std;
    // Allocates a byte buffer with word alignment
    pub unsafe fn allocate_buffer(size: usize) -> *mut u8 {
        use alloc::heap::allocate;
        debug_assert!(size % word_bytes() == 0);
        allocate(size, std::mem::align_of::<usize>())
    }

    pub unsafe fn deallocate_buffer(buf: *mut u8, size: usize) {
        use alloc::heap::deallocate;
        deallocate(buf, size, std::mem::align_of::<usize>());
    }

    #[inline(always)]
    pub fn word_bytes() -> usize {
        std::mem::size_of::<usize>()
    }
    #[inline(always)]
    pub fn word_bits() -> usize {
        std::mem::size_of::<usize>() * 8
    }
}