use crate::leb128::{self, max_leb128_len};
-use crate::serialize::{self, Encoder as _};
+use crate::serialize::{self, Decoder as _, Encoder as _};
use std::convert::TryInto;
use std::fs::File;
use std::io::{self, Write};
pub fn advance(&mut self, bytes: usize) {
self.position += bytes;
}
-
- #[inline]
- pub fn read_raw_bytes(&mut self, bytes: usize) -> &'a [u8] {
- let start = self.position;
- self.position += bytes;
- &self.data[start..self.position]
- }
}
macro_rules! read_leb128 {
}
#[inline]
- fn read_str(&mut self) -> &str {
+ fn read_str(&mut self) -> &'a str {
let len = self.read_usize();
let sentinel = self.data[self.position + len];
assert!(sentinel == STR_SENTINEL);
}
#[inline]
- fn read_raw_bytes_into(&mut self, s: &mut [u8]) {
+ fn read_raw_bytes(&mut self, bytes: usize) -> &'a [u8] {
let start = self.position;
- self.position += s.len();
- s.copy_from_slice(&self.data[start..self.position]);
+ self.position += bytes;
+ &self.data[start..self.position]
}
}
fn decode(decoder: &mut Decoder<'a>) -> IntEncodedWithFixedSize {
let _start_pos = decoder.position();
let bytes = decoder.read_raw_bytes(IntEncodedWithFixedSize::ENCODED_SIZE);
+ let value = u64::from_le_bytes(bytes.try_into().unwrap());
let _end_pos = decoder.position();
debug_assert_eq!((_end_pos - _start_pos), IntEncodedWithFixedSize::ENCODED_SIZE);
- let value = u64::from_le_bytes(bytes.try_into().unwrap());
IntEncodedWithFixedSize(value)
}
}