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

    // Provided method
    fn verify_info(info: &[u8]) -> bool { ... }
}
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.

Provided Methods§

Source

fn verify_info(info: &[u8]) -> bool

Verify the integrity of post-FEC info bits. The FEC layer invokes this when a candidate codeword satisfies parity: returning true accepts the codeword; returning false causes the FEC to keep iterating.

Default: accept unconditionally — appropriate for codecs whose message format carries no inline integrity field (the FEC layer has already enforced parity convergence by the time this is called).

CRC-bearing codecs override this. For example, crate::msg::Wsjt77Message verifies the CRC-14 stored in info bits 77..91. The associated-function (no &self) shape keeps the verifier compatible with the function-pointer field on FecOpts::verify_info.

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§