Change entry header. Expand api
This commit is contained in:
parent
2f23df1009
commit
cac34d95e0
6 changed files with 150 additions and 39 deletions
|
|
@ -45,6 +45,18 @@ pub fn encode_sequence<T: Encode>(ts: &[T]) -> Result<Vec<u8>, bincode::error::E
|
|||
Ok(result)
|
||||
}
|
||||
|
||||
pub fn encode_sequence_with_sizes<T: Encode>(ts: &[T]) -> Result<(Vec<u8>, Vec<usize>), bincode::error::EncodeError> {
|
||||
let mut result_bytes = vec![];
|
||||
let mut sizes = Vec::with_capacity(ts.len());
|
||||
for t in ts {
|
||||
let mut bytes = encode(&t)?;
|
||||
sizes.push(bytes.len());
|
||||
result_bytes.append(&mut bytes);
|
||||
|
||||
}
|
||||
Ok((result_bytes, sizes))
|
||||
}
|
||||
|
||||
pub fn decode_sequence<T: Decode>(len: usize, bytes: &[u8]) -> Result<Vec<T>, bincode::error::DecodeError> {
|
||||
let mut result: Vec<T> = Vec::with_capacity(len);
|
||||
let mut offset = 0;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue