//! Custom serialization formats for EQL types.

/// MessagePack Base85 encoding/decoding for a required `EncryptedRecord`.
///
/// Used with `#[serde(with = "formats::mp_base85")]` on non-optional ciphertext
/// fields. The v2.3 schema requires `c` on every encrypted payload (root scalar
/// and STE vector elements), so this module models the field as non-optional.
pub(super) mod mp_base85 {
    use super::super::*;
    use serde::Deserialize;

    /// Serializes an `EncryptedRecord` to MessagePack Base85 format.
    pub fn serialize<S>(ciphertext: &EncryptedRecord, serializer: S) -> Result<S::Ok, S::Error>
    where
        S: serde::Serializer,
    {
        let s = ciphertext
            .to_mp_base85()
            .map_err(serde::ser::Error::custom)?;
        serializer.serialize_str(&s)
    }

    /// Deserializes an `EncryptedRecord` from MessagePack Base85 format.
    pub fn deserialize<'de, D>(deserializer: D) -> Result<EncryptedRecord, D::Error>
    where
        D: serde::Deserializer<'de>,
    {
        let s = String::deserialize(deserializer)?;
        EncryptedRecord::from_mp_base85(&s).map_err(serde::de::Error::custom)
    }
}
