1use crate::common::{Encoding, Format};
2use crate::read::{Error, Reader, Result};
3
4#[derive(Debug, Clone, Copy)]
5pub(crate) struct ListsHeader {
6 encoding: Encoding,
7 #[allow(dead_code)]
8 offset_entry_count: u32,
9}
10
11impl Default for ListsHeader {
12 fn default() -> Self {
13 ListsHeader {
14 encoding: Encoding {
15 format: Format::Dwarf32,
16 version: 5,
17 address_size: 0,
18 },
19 offset_entry_count: 0,
20 }
21 }
22}
23
24impl ListsHeader {
25 /// Return the serialized size of the table header.
26 #[allow(dead_code)]
27 #[inline]
28 fn size(self) -> u8 {
29 // initial_length + version + address_size + segment_selector_size + offset_entry_count
30 ListsHeader::size_for_encoding(self.encoding)
31 }
32
33 /// Return the serialized size of the table header.
34 #[inline]
35 pub(crate) fn size_for_encoding(encoding: Encoding) -> u8 {
36 // initial_length + version + address_size + segment_selector_size + offset_entry_count
37 encoding.format.initial_length_size() + 2 + 1 + 1 + 4
38 }
39}
40
41// TODO: add an iterator over headers in the appropriate sections section
42#[allow(dead_code)]
43fn parse_header<R: Reader>(input: &mut R) -> Result<ListsHeader> {
44 let (length, format) = input.read_initial_length()?;
45 input.truncate(length)?;
46
47 let version = input.read_u16()?;
48 if version != 5 {
49 return Err(Error::UnknownVersion(u64::from(version)));
50 }
51
52 let address_size = input.read_u8()?;
53 let segment_selector_size = input.read_u8()?;
54 if segment_selector_size != 0 {
55 return Err(Error::UnsupportedSegmentSize);
56 }
57 let offset_entry_count = input.read_u32()?;
58
59 let encoding = Encoding {
60 format,
61 version,
62 address_size,
63 };
64 Ok(ListsHeader {
65 encoding,
66 offset_entry_count,
67 })
68}
69