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

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

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

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

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

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

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

            
70
8
        Ok(())
71
8
    }
72
}