rusty_axml/chunks/
res_value.rs

1#![allow(dead_code)]
2
3use crate::{
4    chunks::data_value_type::DataValueType,
5    errors::AxmlError
6};
7
8use std::io:: Cursor;
9use byteorder::{
10    LittleEndian,
11    ReadBytesExt
12};
13
14/// Representation of a value in a resource, supplying type information.
15pub struct ResValue {
16    /// Number of bytes in this structure
17    pub size: u16,
18
19    /// Always set to 0
20    pub res0: u8,
21
22    /// The type of data
23    pub data_type: DataValueType,
24
25    /// The actual data
26    pub data: u32,
27}
28
29impl ResValue {
30    /// Parse from a cursor of bytes
31    pub fn from_buff(axml_buff: &mut Cursor<Vec<u8>>) -> Result<Self, AxmlError> {
32        let size = axml_buff.read_u16::<LittleEndian>()?;
33        let res0 = axml_buff.read_u8()?;
34
35        if res0 != 0 {
36            panic!("res0 is not 0");
37        }
38
39        let data_type = DataValueType::from_val(axml_buff.read_u8()?);
40        let data = axml_buff.read_u32::<LittleEndian>()?;
41
42        Ok(ResValue {
43            size,
44            res0,
45            data_type,
46            data
47        })
48    }
49}