Skip to main content

MessageCodec

Trait MessageCodec 

Source
pub trait MessageCodec: Default + 'static {
    type Unpacked;

    const PAYLOAD_BITS: u32;
    const CRC_BITS: u32;

    // Required methods
    fn pack(&self, fields: &MessageFields) -> Option<Vec<u8>>;
    fn unpack(
        &self,
        payload: &[u8],
        ctx: &DecodeContext,
    ) -> Option<Self::Unpacked>;
}
Expand description

Human-facing message payload codec (callsigns, grids, reports, free text).

Operates on the FEC-decoded information bits (PAYLOAD_BITS wide, NOT including any CRC protecting them — callers handle the CRC layer).

Unlike FecCodec, this trait is an acceptable place for dyn when the caller juggles heterogeneous protocols at runtime (FFI, CLI dump tools): message unpacking is a cold path relative to DSP/FEC inner loops.

Required Associated Constants§

Source

const PAYLOAD_BITS: u32

Number of information bits consumed by pack / produced by unpack.

Source

const CRC_BITS: u32

CRC width guarding the payload during transmission (0 if the FEC itself provides all error detection, as with JT65 Reed–Solomon).

Required Associated Types§

Source

type Unpacked

Decoded high-level representation returned by unpack.

Required Methods§

Source

fn pack(&self, fields: &MessageFields) -> Option<Vec<u8>>

Encode high-level fields to a bit vector of length PAYLOAD_BITS. Returns None on encoding failure (invalid callsign format, overflow…).

Source

fn unpack(&self, payload: &[u8], ctx: &DecodeContext) -> Option<Self::Unpacked>

Decode a PAYLOAD_BITS-long bit vector to the protocol-specific unpacked representation. ctx carries side information such as the callsign-hash table.

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§