use super::{OwnerFact, OwnerIdentity, Profile};
pub fn encode_length(length: usize, into: &mut Vec<u8>) {
into.extend_from_slice(&u64::try_from(length).unwrap_or(u64::MAX).to_be_bytes());
}
pub fn encode_bytes(material: &[u8], into: &mut Vec<u8>) {
encode_length(material.len(), into);
into.extend_from_slice(material);
}
impl Profile {
pub fn encode_into(self, into: &mut Vec<u8>) {
encode_bytes(self.stem().as_bytes(), into);
encode_bytes(self.name().as_bytes(), into);
into.extend_from_slice(&self.version().position().to_be_bytes());
}
}
impl OwnerFact {
#[must_use]
pub fn citation_bytes(&self) -> Vec<u8> {
let mut bytes = Vec::new();
encode_bytes(self.home.as_bytes(), &mut bytes);
encode_bytes(self.name.as_bytes(), &mut bytes);
bytes
}
}
impl OwnerIdentity {
#[must_use]
pub fn citation_bytes(&self) -> Vec<u8> {
let mut bytes = Vec::new();
encode_bytes(self.subject.as_bytes(), &mut bytes);
encode_bytes(&self.bytes, &mut bytes);
bytes
}
}