pub fn encode_map<'a, K, V>(
map: impl Iterator<Item = (&'a K, &'a V)>,
buf: &mut [u8],
) -> Result<usize, EncodeError>Expand description
Encodes a map of entries as varints and writes them to the buffer.
Returns the total number of bytes written to the buffer.
ยงExample
use varing::{Varint, decode_map, encoded_map_len, encode_map};
use std::collections::HashMap;
let values = (0..1024u64).map(|v| (v, v)).collect::<HashMap<_, _>>();
let encoded_len = encoded_map_len(values.iter());
let mut buf = vec![0; encoded_len];
let bytes_written = encode_map(values.iter(), &mut buf).unwrap();
assert_eq!(bytes_written, encoded_len);
let (readed, decoded) = decode_map::<_, _, HashMap<u64, u64>>(&buf).unwrap();
assert_eq!(decoded, values);
assert_eq!(readed, buf.len());