@@ -27,13 +27,16 @@ impl Block {
|
||||
}
|
||||
|
||||
pub fn decode(data: &[u8]) -> Self {
|
||||
// get number of elements in the block
|
||||
let entry_offsets_len = (&data[data.len() - SIZEOF_U16..]).get_u16() as usize;
|
||||
let data_end = data.len() - SIZEOF_U16 - entry_offsets_len * SIZEOF_U16;
|
||||
let offsets_raw = &data[data_end..data.len() - SIZEOF_U16];
|
||||
// get offset array
|
||||
let offsets = offsets_raw
|
||||
.chunks(SIZEOF_U16)
|
||||
.map(|mut x| x.get_u16())
|
||||
.collect();
|
||||
// retrieve data
|
||||
let data = data[0..data_end].to_vec();
|
||||
Self { data, offsets }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user