Skip to main content

BitEncode

Trait BitEncode 

Source
pub trait BitEncode {
    const LAYOUT: Layout = _;

    // Required method
    fn bit_encode<K: Sink>(&self, w: &mut K) -> Result<(), BitError>;

    // Provided method
    fn canonical_bit_encode<K: Sink>(&self, w: &mut K) -> Result<(), BitError> { ... }
}
Expand description

A message encoded to a bit stream — the dual of BitDecode.

Encoding has two forms: the required bit_encode is verbatim (exactly what’s stored), and canonical_bit_encode is canonical (reserved → spec value, calc → recomputed). The default canonical impl just calls bit_encode, so the two are identical unless a #[bin] message has a reserved or non-temp calc field — in which case the derive overrides it.

Provided Associated Constants§

Source

const LAYOUT: Layout = _

The message’s bit/byte order, used to size a fresh BitWriter when encoding to a Vec/writer. The derive sets it from the struct’s declared bit_order/bytes; a hand-written impl that only ever encodes into a caller-supplied Sink can leave the default.

Required Methods§

Source

fn bit_encode<K: Sink>(&self, w: &mut K) -> Result<(), BitError>

Encodes self verbatim into any Sink, advancing its cursor.

§Errors

Propagates the sink’s BitError.

Provided Methods§

Source

fn canonical_bit_encode<K: Sink>(&self, w: &mut K) -> Result<(), BitError>

Encodes self’s canonical form into any Sink: reserved fields as their spec value, calc fields recomputed. Defaults to bit_encode (verbatim == canonical) for messages with no reserved/calc field.

§Errors

Propagates the sink’s BitError.

Dyn Compatibility§

This trait is not dyn compatible.

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

Implementations on Foreign Types§

Source§

impl BitEncode for Ipv4Addr

Available on crate feature std only.
Source§

impl BitEncode for Ipv6Addr

Available on crate feature std only.
Source§

impl BitEncode for bool

Source§

impl BitEncode for u8

Source§

impl BitEncode for u16

Source§

impl BitEncode for u32

Source§

impl BitEncode for u64

Source§

impl BitEncode for u128

Implementors§

Source§

impl<T, const N: usize> BitEncode for UInt<T, N>
where UInt<T, N>: Bits,

Source§

impl<T: Bits> BitEncode for WireLen<T>