Skip to main content

ical/tree/value/
binary.rs

1//! # Binary value codec (RFC 5545 3.3.1)
2//!
3//! [`Codec`] for an `ATTACH` / `IMAGE` value: inline
4//! base64 kept verbatim. A URI reference is reached via `VALUE=uri`, which the
5//! spec resolves to [`IcalUri`](crate::value::uri::IcalUri), not here.
6
7use crate::{
8    tree::{
9        codec::{Codec, encode::scalar_node, mode::Escaper},
10        value::IcalValueNode,
11    },
12    value::binary::IcalBinary,
13};
14
15impl<'v> Codec<'v> for IcalBinary<'v> {
16    fn decode(node: &'v IcalValueNode<'_>) -> Self {
17        IcalBinary::Base64(node.decode_scalar_at(0))
18    }
19
20    fn encode(&self, escaper: Escaper) -> IcalValueNode<'static> {
21        let raw = match self {
22            IcalBinary::Uri(value) | IcalBinary::Base64(value) => value.as_ref(),
23        };
24
25        scalar_node(raw, escaper)
26    }
27}