/// Interpret a page-sized byte slice as node.
Interpret a page-sized byte slice as node.
Interpret a page - sized byte slice as node .
pub fn from_bytes<Size: PageSize>(bytes: &'a [u8]) -> Node<'a> {
        assert_eq!(bytes.len(), Size::SIZE);
        // TODO: Assert alignment of byte array.
        // TODO: Check that these are within range. Should return Result then.
        let header = &bytes[Size::header_offset()..];
        let level = header[0];
        let num_datoms = header[1] as usize;
        // The datom array is stored at the start of the page.
        let num_datom_bytes = 32 * num_datoms;
        let datoms: &[Datom] = unsafe {
            transmute_slice(&bytes[0..num_datom_bytes])
        };
        // The array with child page ids starts at an offset dependent on the
        // size of the node.
        let num_children_bytes = 8 * (num_datoms + 1);
        let child_off = Size::children_offset();
        let children: &[PageId] = unsafe {
            transmute_slice(&bytes[child_off..child_off + num_children_bytes])
        };
        assert_eq!(
            datoms.len() + 1,
            children.len(),
            "Node must have one more child than datoms.",
        );
        Node {
            level: level,
            datoms: datoms,
            children: children,
        }
    }
pub fn from_bytes < Size : PageSize > ( bytes : & ' a [ u8 ] ) -> Node < ' a > { assert_eq ! ( bytes len ( ) Size SIZE ) ; // TODO: Assert alignment of byte array. // TODO: Check that these are within range. Should return Result then. let header = & bytes [ Size :: header_offset ( ) .. ] ; let level = header [ 0 ] ; let num_datoms = header [ 1 ] as usize ; // The datom array is stored at the start of the page. let num_datom_bytes = 32 * num_datoms ; let datoms : & [ Datom ] = unsafe { transmute_slice ( & bytes [ 0 .. num_datom_bytes ] ) } ; // The array with child page ids starts at an offset dependent on the // size of the node. let num_children_bytes = 8 * ( num_datoms + 1 ) ; let child_off = Size :: children_offset ( ) ; let children : & [ PageId ] = unsafe { transmute_slice ( & bytes [ child_off .. child_off + num_children_bytes ] ) } ; assert_eq ! ( datoms len ( ) 1 children len ( ) " " ) ; Node { level : level , datoms : datoms , children : children , } }
Interpret a page-sized byte slice as node.
Interpret a page - sized byte slice as node .
bytes
&'a [u8]