Skip to main content

SequenceCodec

Trait SequenceCodec 

Source
pub trait SequenceCodec: Sized {
    const TYPE_TAG: [u8; 16];
    const LOSSY: bool;
    const IS_IDENTITY: bool = false;

    // Required methods
    fn encode_into(
        sequence: &[u8],
        output: &mut Vec<u8>,
    ) -> Result<(), DryIceError>;
    fn decode_into(
        encoded: &[u8],
        original_len: usize,
        output: &mut Vec<u8>,
    ) -> Result<(), DryIceError>;

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

A sequence encoding strategy for dryice blocks.

Implementors define how raw ASCII nucleotide sequences are encoded for on-disk storage and decoded back. The crate provides RawAsciiCodec and TwoBitExactCodec as built-in implementations, but users can implement this trait for custom encodings.

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. When true, the decoder can skip decoding and return slices directly into the block’s payload buffer.

Required Methods§

Source

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

Encode a raw ASCII nucleotide sequence, appending the encoded bytes directly into the provided output buffer.

§Errors

Returns an error if the sequence contains bytes that are invalid for this encoding.

Source

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

Decode an encoded buffer, appending the decoded ASCII bytes directly into the provided output buffer.

original_len is the number of bases in the original sequence, needed because some encodings pad or compress.

§Errors

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

Provided Methods§

Source

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

Encode a sequence, returning a new allocated buffer.

This is a convenience wrapper around encode_into.

§Errors

Returns an error if the sequence contains bytes that are invalid for this encoding.

Source

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

Decode an encoded buffer, returning a new allocated buffer.

This is a convenience wrapper around decode_into.

§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§