use super::RenderError;
use crate::identity::encode_bytes;
impl RenderError {
#[must_use]
pub fn canonical_bytes(&self) -> Vec<u8> {
let mut bytes = Vec::new();
self.encode_into(&mut bytes);
bytes
}
pub fn encode_into(&self, into: &mut Vec<u8>) {
into.push(self.slot());
let mut material = Vec::new();
self.material_into(&mut material);
encode_bytes(&material, into);
}
fn material_into(&self, into: &mut Vec<u8>) {
match self {
Self::NothingRendered => {}
Self::SeatUnplanned { role } => encode_bytes(role.as_bytes(), into),
Self::BytesUnbounded {
role,
bound,
observed,
} => {
encode_bytes(role.as_bytes(), into);
counted_into(*bound, into);
counted_into(*observed, into);
}
Self::UnitsUnbounded { bound, observed }
| Self::TokensUnbounded { bound, observed } => {
counted_into(*bound, into);
counted_into(*observed, into);
}
}
}
}
fn counted_into(value: usize, into: &mut Vec<u8>) {
into.extend_from_slice(&u64::try_from(value).unwrap_or(u64::MAX).to_be_bytes());
}