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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
use crate::{BinaryReader, Result};
use ::core::ops::Range;
#[derive(Clone)]
pub struct CustomSectionReader<'a> {
pub(crate) name: &'a str,
pub(crate) data_offset: usize,
pub(crate) data: &'a [u8],
pub(crate) range: Range<usize>,
}
impl<'a> CustomSectionReader<'a> {
pub fn new(data: &'a [u8], offset: usize) -> Result<CustomSectionReader<'a>> {
let mut reader = BinaryReader::new_with_offset(data, offset);
let name = reader.read_string()?;
let data_offset = reader.original_position();
let data = reader.remaining_buffer();
let range = reader.range();
Ok(CustomSectionReader {
name,
data_offset,
data,
range,
})
}
pub fn name(&self) -> &'a str {
self.name
}
pub fn data_offset(&self) -> usize {
self.data_offset
}
pub fn data(&self) -> &'a [u8] {
self.data
}
pub fn range(&self) -> Range<usize> {
self.range.clone()
}
}
impl<'a> ::core::fmt::Debug for CustomSectionReader<'a> {
fn fmt(&self, f: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result {
f.debug_struct("CustomSectionReader")
.field("name", &self.name)
.field("data_offset", &self.data_offset)
.field("data", &"...")
.field("range", &self.range)
.finish()
}
}