Skip to main content

NameCodec

Trait NameCodec 

Source
pub trait NameCodec: Sized {
    type Decoded;

    const TYPE_TAG: [u8; 16];
    const LOSSY: bool;
    const IS_IDENTITY: bool = false;

    // Required methods
    fn encode_into(name: &[u8], output: &mut Vec<u8>) -> Result<(), DryIceError>;
    fn decode(
        encoded: &[u8],
        original_len: usize,
    ) -> Result<Self::Decoded, DryIceError>;
    fn as_bytes(decoded: &Self::Decoded) -> &[u8] ;

    // Provided methods
    fn encode(name: &[u8]) -> Result<Vec<u8>, DryIceError> { ... }
    fn decode_to_bytes_into(
        encoded: &[u8],
        original_len: usize,
        output: &mut Vec<u8>,
    ) -> Result<(), DryIceError> { ... }
}
Expand description

A name encoding strategy for dryice blocks.

Unlike SequenceCodec and QualityCodec, the name codec has an associated Decoded type that can carry richer parsed structure than raw bytes. This reflects the fact that sequencing record names are structured text with meaningful subfields.

Required Associated Constants§

Source

const TYPE_TAG: [u8; 16]

Stable type tag written into block headers.

Source

const LOSSY: bool

Whether this encoding is lossy.

Provided Associated Constants§

Source

const IS_IDENTITY: bool = false

Whether the encoded form is identical to the raw input bytes.

Required Associated Types§

Source

type Decoded

The decoded representation of a name.

Required Methods§

Source

fn encode_into(name: &[u8], output: &mut Vec<u8>) -> Result<(), DryIceError>

Encode raw name bytes, appending the encoded bytes directly into the provided output buffer.

§Errors

Returns an error if the name data is invalid for this encoding.

Source

fn decode( encoded: &[u8], original_len: usize, ) -> Result<Self::Decoded, DryIceError>

Decode an encoded buffer into the codec’s decoded representation.

original_len is the number of bytes in the original name.

§Errors

Returns an error if the encoded data is corrupt or inconsistent.

Source

fn as_bytes(decoded: &Self::Decoded) -> &[u8]

View the decoded name as raw bytes for use in SeqRecordLike.

Provided Methods§

Source

fn encode(name: &[u8]) -> Result<Vec<u8>, DryIceError>

Encode name bytes, returning a new allocated buffer.

§Errors

Returns an error if the name data is invalid for this encoding.

Source

fn decode_to_bytes_into( encoded: &[u8], original_len: usize, output: &mut Vec<u8>, ) -> Result<(), DryIceError>

Decode an encoded buffer directly to raw bytes, appending into the provided output buffer.

This is used internally by the block decoder to populate the name buffer without requiring knowledge of the Decoded type. The default implementation decodes and then copies via as_bytes.

§Errors

Returns an error if the encoded data is corrupt or inconsistent.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§