Skip to main content

WireDecode

Trait WireDecode 

Source
pub trait WireDecode: Sized {
    // Required method
    fn decode_wire(cursor: &mut WireCursor<'_>) -> Result<Self, WireError>;

    // Provided methods
    fn decode_wire_with_collection_limits(
        cursor: &mut WireCursor<'_>,
        _limits: CollectionLimits,
    ) -> Result<Self, WireError> { ... }
    fn decode_wire_with_limits(
        cursor: &mut WireCursor<'_>,
        collections: CollectionLimits,
        _max_records: Option<usize>,
    ) -> Result<Self, WireError> { ... }
    fn from_wire_bytes_with_collection_limits(
        bytes: &[u8],
        limits: CollectionLimits,
    ) -> Result<Self, WireError> { ... }
    fn from_wire_bytes(bytes: &[u8]) -> Result<Self, WireError> { ... }
}
Expand description

Decode one payload from a shared cursor using its public read methods. Self::from_wire_bytes additionally rejects trailing bytes.

use safemesh_crdt::{WireCursor, WireDecode, WireEncode, WireError};
#[derive(Debug, PartialEq)]
struct Reading(u64);
impl WireEncode for Reading {
    fn encode_wire(&self, out: &mut Vec<u8>) -> Result<(), WireError> {
        out.extend_from_slice(&self.0.to_le_bytes());
        Ok(())
    }
}
impl WireDecode for Reading {
    fn decode_wire(cursor: &mut WireCursor<'_>) -> Result<Self, WireError> {
        Ok(Self(cursor.read_u64()?))
    }
}
let reading = Reading(42);
assert_eq!(Reading::from_wire_bytes(&reading.to_wire_bytes()?)?, reading);

Required Methods§

Source

fn decode_wire(cursor: &mut WireCursor<'_>) -> Result<Self, WireError>

Provided Methods§

Source

fn decode_wire_with_collection_limits( cursor: &mut WireCursor<'_>, _limits: CollectionLimits, ) -> Result<Self, WireError>

Decode a nested payload with a collection budget. Other payload types retain their ordinary decoder unless they implement this method.

Source

fn decode_wire_with_limits( cursor: &mut WireCursor<'_>, collections: CollectionLimits, _max_records: Option<usize>, ) -> Result<Self, WireError>

Decode a payload nested in an EventLog with its record budget.

Source

fn from_wire_bytes_with_collection_limits( bytes: &[u8], limits: CollectionLimits, ) -> Result<Self, WireError>

Decode a complete wire value with an explicit collection ceiling.

Source

fn from_wire_bytes(bytes: &[u8]) -> Result<Self, WireError>

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§