use crate::{
BytesRef, DecodeValue, EncodeValue, FixedTag, Header, Length, Reader, Result, Tag, Writer,
};
#[cfg(feature = "alloc")]
use alloc::boxed::Box;
pub trait Sequence<'a>: DecodeValue<'a> + EncodeValue {}
impl<'a, S> FixedTag for S
where
S: Sequence<'a>,
{
const TAG: Tag = Tag::Sequence;
}
#[cfg(feature = "alloc")]
impl<'a, T> Sequence<'a> for Box<T> where T: Sequence<'a> {}
pub struct SequenceRef<'a> {
body: BytesRef<'a>,
}
impl<'a> DecodeValue<'a> for SequenceRef<'a> {
fn decode_value<R: Reader<'a>>(reader: &mut R, header: Header) -> Result<Self> {
Ok(Self {
body: BytesRef::decode_value(reader, header)?,
})
}
}
impl EncodeValue for SequenceRef<'_> {
fn value_len(&self) -> Result<Length> {
Ok(self.body.len())
}
fn encode_value(&self, writer: &mut impl Writer) -> Result<()> {
self.body.encode_value(writer)
}
}
impl<'a> Sequence<'a> for SequenceRef<'a> {}