use super::Tlv;
use crate::error::TlvError;
use crate::Result;
use alloc::vec::Vec;
#[derive(PartialEq, Debug, Clone)]
pub enum Value {
Constructed(Vec<Tlv>),
Primitive(Vec<u8>),
}
impl Value {
#[must_use]
pub fn is_constructed(&self) -> bool {
matches!(self, Self::Constructed(_))
}
#[must_use]
pub fn len_as_bytes(&self) -> usize {
match &self {
Self::Primitive(v) => v.len(),
Self::Constructed(tlv) => tlv.iter().fold(0, |sum, x| sum + x.len()),
}
}
pub fn push(&mut self, tlv: Tlv) -> Result<()> {
match self {
Self::Constructed(t) => {
t.push(tlv);
Ok(())
}
Self::Primitive(_) => Err(TlvError::Inconsistant),
}
}
}