Skip to main content

Codec

Trait Codec 

Source
pub trait Codec: Sync {
    // Required methods
    fn id(&self) -> &'static str;
    fn encode(
        &self,
        src: &[u8],
        frame: Frame,
        out: &mut dyn Write,
    ) -> Result<u64>;
    fn decode(
        &self,
        data: &[u8],
        frame: Frame,
        out: &mut dyn Write,
    ) -> Result<u64>;

    // Provided method
    fn describe(&self) -> String { ... }
}
Expand description

A lossless image codec operating on raw sample bytes.

Implementations must be exactly reversible. This is asserted end-to-end on every archive rather than trusted.

Required Methods§

Source

fn id(&self) -> &'static str

Short stable identifier recorded in the archive manifest, so a future version knows which backend produced a payload.

Source

fn encode(&self, src: &[u8], frame: Frame, out: &mut dyn Write) -> Result<u64>

Encode src (raw samples in the file’s byte order), writing the compressed representation to out. Returns bytes written.

Source

fn decode(&self, data: &[u8], frame: Frame, out: &mut dyn Write) -> Result<u64>

Decode data, writing raw samples in the file’s byte order to out. Returns bytes written.

Provided Methods§

Source

fn describe(&self) -> String

Human description of the exact encoder and settings, for the archive’s record.

Reported by the linked library rather than assumed from the crate version: what matters to someone holding the archive in ten years is which encoder actually produced those bytes, and a hardcoded string can drift from reality without anyone noticing.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§