Skip to main content

MessageRef

Trait MessageRef 

Source
pub trait MessageRef<'a>: Sized {
    const NAME: &'static str;
    const SEGMENTS: &'static [SegmentDef<'static>];
    const COVERED: &'static [CoverDef<'static>] = _;

    // Required methods
    fn decode(bytes: &'a [u8]) -> Result<(Self, usize), ParseError>;
    fn encode_into<B>(&self, out: &mut B) -> Result<(), Overflow>
       where B: Buffer;

    // Provided methods
    fn encode(&self) -> Vec<u8> ⓘ { ... }
    fn audit() -> MessageRecords<'static> { ... }
}
Expand description

A variable-length type whose fields borrow the bytes it decodes from.

#[derive(Message)] implements it, instead of Message, on a struct with a lifetime: &'a [u8] and &'a [u8; N] fields are views of the input, so decode needs no allocator. It has no parameters, and no other message can hold it, since Message decodes from bytes it does not keep.

Required Associated Constants§

Source

const NAME: &'static str

The type’s name, as printed in the audit.

Source

const SEGMENTS: &'static [SegmentDef<'static>]

The segment table, in wire order.

Provided Associated Constants§

Source

const COVERED: &'static [CoverDef<'static>] = _

The bytes each #[checksum] field covers, in wire order.

Required Methods§

Source

fn decode(bytes: &'a [u8]) -> Result<(Self, usize), ParseError>

Decode from the start of bytes, borrowing from them. Returns the value and the bytes consumed.

§Errors

As Message::decode_with.

Source

fn encode_into<B>(&self, out: &mut B) -> Result<(), Overflow>
where B: Buffer,

Append the wire bytes to out.

§Errors

Overflow, leaving the bytes already written in place.

Provided Methods§

Source

fn encode(&self) -> Vec<u8> ⓘ

Available on crate feature alloc only.

encode_into into a new vector.

Source

fn audit() -> MessageRecords<'static>

The audit records for this message.

Dyn Compatibility§

This trait is not dyn compatible.

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

Implementors§