INNER CODE UNIT · Rust

fmt

Barre/ZeroFS · zerofs/nbd-proto/src/lib.rs:198

    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        write!(f, "NBD codec error: {self:?}")
    }
}

impl std::error::Error for CodecError {}

/// Big-endian fixed-width codec. Callers may encode into stack or reusable buffers.
pub trait WireCodec: Sized {
    const WIRE_SIZE: usize;
    fn decode(input: &[u8]) -> Result<Self, CodecError>;
    fn encode(&self, output: &mut [u8]) -> Result<usize, CodecError>;
    fn to_bytes(&self) -> Result<Vec<u8>, CodecError> {
        let mut output = vec![0; Self::WIRE_SIZE];
        self.encode(&mut output)?;
        Ok(output)
    }
}

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…