use super::{chunk_header::*, chunk_type::*, *};
use bytes::{Bytes, BytesMut};
use std::fmt;
#[derive(Default, Debug, Clone)]
pub(crate) struct ChunkUnknown {
pub(crate) typ: ChunkType,
pub(crate) flags: u8,
pub(crate) value: Bytes,
}
impl fmt::Display for ChunkUnknown {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}", self.header())
}
}
impl ChunkUnknown {
pub(crate) fn stops_processing(&self) -> bool {
self.typ.0 & 0x80 == 0
}
pub(crate) fn is_reported(&self) -> bool {
self.typ.0 & 0x40 != 0
}
}
impl Chunk for ChunkUnknown {
fn header(&self) -> ChunkHeader {
ChunkHeader {
typ: self.typ,
flags: self.flags,
value_length: self.value.len() as u16,
}
}
fn unmarshal(raw: &Bytes) -> Result<Self> {
let header = ChunkHeader::unmarshal(raw)?;
Ok(ChunkUnknown {
typ: header.typ,
flags: header.flags,
value: raw.slice(CHUNK_HEADER_SIZE..CHUNK_HEADER_SIZE + header.value_length()),
})
}
fn marshal_to(&self, buf: &mut BytesMut) -> Result<usize> {
self.header().marshal_to(buf)?;
buf.extend_from_slice(&self.value);
Ok(buf.len())
}
fn check(&self) -> Result<()> {
Ok(())
}
fn value_length(&self) -> usize {
self.value.len()
}
fn as_any(&self) -> &dyn Any {
self
}
}