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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
use crate::iterator::VintArrayIterator;
use crate::*;
#[derive(Debug, Clone, Default)]
pub struct VIntArray {
pub data: Vec<u8>,
}
impl VIntArray {
#[inline]
pub fn from_vals(vals: &[u32]) -> VIntArray {
let mut arr = VIntArray::default();
arr.encode_vals(vals);
arr
}
#[inline]
pub fn encode_vals(&mut self, vals: &[u32]) {
for val in vals {
encode_varint_into(&mut self.data, *val);
}
}
#[inline]
pub fn serialize(&self) -> Vec<u8> {
let mut serialized = Vec::with_capacity(self.data.len() + 4);
encode_varint_into(&mut serialized, self.data.len() as u32);
serialized.extend_from_slice(&self.data);
serialized
}
#[inline]
pub fn encode(&mut self, val: u32) {
encode_varint_into(&mut self.data, val);
}
pub fn iter(&self) -> VintArrayIterator {
VintArrayIterator::new(&self.data)
}
}