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
use xmlserde_derives::XmlDeserialize;

use crate::r#type::Type;

#[derive(Clone, Debug, XmlDeserialize)]
#[xmlserde(root = b"array")]
#[xmlserde(deny_unknown_fields)]
pub struct Array {
    #[xmlserde(name = b"name", ty = "attr")]
    name: Option<String>,
    #[xmlserde(name = b"zero-terminated", ty = "attr")]
    zero_terminated: Option<bool>,
    #[xmlserde(name = b"fixed-size", ty = "attr")]
    fixed_size: Option<u16>,
    #[xmlserde(name = b"introspectable", ty = "attr")]
    introspectable: Option<bool>,
    #[xmlserde(name = b"length", ty = "attr")]
    length: Option<u32>,
    #[xmlserde(name = b"c:type", ty = "attr")]
    c_type: Option<String>,
    #[xmlserde(name = b"type", ty = "child")]
    type_: Type, // TODO: does this really has to be AnyType?
}

impl Array {
    pub fn name(&self) -> Option<&str> {
        self.name.as_deref()
    }

    pub fn zero_terminated(&self) -> Option<bool> {
        self.zero_terminated
    }

    pub fn fixed_size(&self) -> Option<u16> {
        self.fixed_size
    }

    pub fn is_introspectable(&self) -> bool {
        self.introspectable.unwrap_or(true)
    }

    pub fn length(&self) -> Option<u32> {
        self.length
    }

    pub fn c_type(&self) -> Option<&str> {
        self.c_type.as_deref()
    }

    pub fn ty(&self) -> &Type {
        &self.type_
    }
}