1
use crate::error::AetoliaResult;
2
use crate::serialize::WriteModel;
3
use std::io::Write;
4

            
5
impl WriteModel for crate::model::object::ICalObject {
6
40
    fn write_model<W: Write>(&self, writer: &mut W) -> AetoliaResult<()> {
7
40
        writer.write_all(b"BEGIN:VCALENDAR")?;
8
48
        for property in &self.properties {
9
8
            writer.write_all(b"\r\n")?;
10
8
            property.write_model(writer)?;
11
        }
12
92
        for component in &self.components {
13
52
            writer.write_all(b"\r\n")?;
14
52
            component.write_model(writer)?;
15
        }
16
40
        writer.write_all(b"\r\nEND:VCALENDAR\r\n")?;
17

            
18
40
        Ok(())
19
40
    }
20
}
21

            
22
impl WriteModel for crate::model::property::CalendarProperty {
23
8
    fn write_model<W: Write>(&self, writer: &mut W) -> AetoliaResult<()> {
24
        use crate::model::property::CalendarProperty;
25

            
26
8
        match self {
27
2
            CalendarProperty::ProductId(property) => {
28
2
                writer.write_all(b"PRODID")?;
29
2
                property.params.as_slice().write_model(writer)?;
30
2
                writer.write_all(b":")?;
31
2
                writer.write_all(property.value.as_bytes())?;
32
            }
33
2
            CalendarProperty::Version(property) => {
34
2
                writer.write_all(b"VERSION")?;
35
2
                property.params.as_slice().write_model(writer)?;
36
2
                writer.write_all(b":")?;
37

            
38
2
                if let Some(min_version) = &property.min_version {
39
                    write!(writer, "{};", min_version)?;
40
2
                }
41

            
42
2
                writer.write_all(property.max_version.as_bytes())?;
43
            }
44
2
            CalendarProperty::CalendarScale(property) => {
45
2
                writer.write_all(b"CALSCALE")?;
46
2
                property.params.as_slice().write_model(writer)?;
47
2
                writer.write_all(b":")?;
48
2
                writer.write_all(property.value.as_bytes())?;
49
            }
50
2
            CalendarProperty::Method(property) => {
51
2
                writer.write_all(b"METHOD")?;
52
2
                property.params.as_slice().write_model(writer)?;
53
2
                writer.write_all(b":")?;
54
2
                writer.write_all(property.value.as_bytes())?;
55
            }
56
            CalendarProperty::XProperty(property) => {
57
                writer.write_all(b"X-")?;
58
                writer.write_all(property.name.as_bytes())?;
59
                property.params.as_slice().write_model(writer)?;
60
                writer.write_all(b":")?;
61
                writer.write_all(property.value.as_bytes())?;
62
            }
63
            CalendarProperty::IanaProperty(property) => {
64
                writer.write_all(property.name.as_bytes())?;
65
                property.params.as_slice().write_model(writer)?;
66
                writer.write_all(b":")?;
67
                writer.write_all(property.value.as_bytes())?;
68
            }
69
        }
70

            
71
8
        Ok(())
72
8
    }
73
}