Skip to main content

vcard/tree/value/
binary.rs

1//! # Binary value codec (vCard 2.1 / 3.0)
2//!
3//! [`VcardCodec`] for a 2.1 / 3.0 `PHOTO` / `LOGO` / `SOUND` / `KEY` value:
4//! inline base64 kept verbatim. A URI reference is reached via `VALUE=uri`,
5//! which the spec resolves to [`VcardUri`](crate::value::uri::VcardUri), not
6//! here.
7
8use crate::{
9    tree::{
10        codec::{VcardCodec, encode::scalar_node, mode::VcardEscaper},
11        value::node::VcardValueNode,
12    },
13    value::binary::VcardBinary,
14};
15
16impl<'v> VcardCodec<'v> for VcardBinary<'v> {
17    fn decode(node: &'v VcardValueNode<'_>) -> Self {
18        VcardBinary::Base64(node.decode_scalar_at(0))
19    }
20
21    fn encode(&self, escaper: VcardEscaper) -> VcardValueNode<'static> {
22        let raw = match self {
23            VcardBinary::Uri(value) | VcardBinary::Base64(value) => value.as_ref(),
24        };
25
26        scalar_node(raw, escaper)
27    }
28}