DataFormat

Trait DataFormat 

Source
pub trait DataFormat: Sized {
    type Header: DataFormat + Clone;

    const LATEST_HEADER: Self::Header;

    // Required methods
    fn write_data<W: Write>(
        &self,
        writer: &mut W,
    ) -> Result<usize, DataWriteError>;
    fn read_data<R: Read>(
        reader: &mut R,
        header: &Self::Header,
    ) -> Result<Self, DataReadError>;

    // Provided methods
    fn write_header<W: Write>(
        &self,
        writer: &mut W,
    ) -> Result<usize, DataWriteError> { ... }
    fn read_header<R: Read>(
        reader: &mut R,
    ) -> Result<Self::Header, DataReadError> { ... }
    fn to_byte_vec(&self) -> Result<Vec<u8>, DataWriteError> { ... }
}
Expand description

DataFormat is a trait for serializing and deserializing binary data.

A header is read/written containing the versions of the desired data

Required Associated Constants§

Required Associated Types§

Required Methods§

Source

fn write_data<W: Write>(&self, writer: &mut W) -> Result<usize, DataWriteError>

Write the data to the writer

Source

fn read_data<R: Read>( reader: &mut R, header: &Self::Header, ) -> Result<Self, DataReadError>

Read the data from the reader

Provided Methods§

Source

fn write_header<W: Write>( &self, writer: &mut W, ) -> Result<usize, DataWriteError>

Source

fn read_header<R: Read>(reader: &mut R) -> Result<Self::Header, DataReadError>

Source

fn to_byte_vec(&self) -> Result<Vec<u8>, DataWriteError>

Convert the data to a byte vector

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.

Implementations on Foreign Types§

Source§

impl DataFormat for IpAddr

Source§

const LATEST_HEADER: Self::Header = ()

Source§

type Header = ()

Source§

fn write_data<W: Write>(&self, writer: &mut W) -> Result<usize, DataWriteError>

Source§

fn read_data<R: Read>( reader: &mut R, _header: &Self::Header, ) -> Result<Self, DataReadError>

Source§

impl DataFormat for SocketAddr

Source§

const LATEST_HEADER: Self::Header = ()

Source§

type Header = ()

Source§

fn write_data<W: Write>(&self, writer: &mut W) -> Result<usize, DataWriteError>

Source§

fn read_data<R: Read>( reader: &mut R, _header: &Self::Header, ) -> Result<Self, DataReadError>

Source§

impl DataFormat for Value

Source§

const LATEST_HEADER: Self::Header = ()

Source§

type Header = ()

Source§

fn write_data<W: Write>(&self, writer: &mut W) -> Result<usize, DataWriteError>

Source§

fn read_data<R: Read>( reader: &mut R, _header: &Self::Header, ) -> Result<Self, DataReadError>

Source§

impl DataFormat for RetentionSpan

Source§

const LATEST_HEADER: Self::Header = {transmute(0x01): <snops_checkpoint::RetentionSpan as format::DataFormat>::Header}

Source§

type Header = u8

Source§

fn write_data<W: Write>(&self, writer: &mut W) -> Result<usize, DataWriteError>

Source§

fn read_data<R: Read>( reader: &mut R, header: &Self::Header, ) -> Result<Self, DataReadError>

Source§

impl DataFormat for bool

Source§

const LATEST_HEADER: Self::Header = ()

Source§

type Header = ()

Source§

fn write_data<W: Write>(&self, writer: &mut W) -> Result<usize, DataWriteError>

Source§

fn read_data<R: Read>( reader: &mut R, _header: &Self::Header, ) -> Result<Self, DataReadError>

Source§

impl DataFormat for i8

Source§

const LATEST_HEADER: Self::Header = ()

Source§

type Header = ()

Source§

fn write_data<W: Write>(&self, writer: &mut W) -> Result<usize, DataWriteError>

Source§

fn read_data<R: Read>( reader: &mut R, _header: &Self::Header, ) -> Result<Self, DataReadError>

Source§

impl DataFormat for i16

Source§

const LATEST_HEADER: Self::Header = ()

Source§

type Header = ()

Source§

fn write_data<W: Write>(&self, writer: &mut W) -> Result<usize, DataWriteError>

Source§

fn read_data<R: Read>( reader: &mut R, _header: &Self::Header, ) -> Result<Self, DataReadError>

Source§

impl DataFormat for i32

Source§

const LATEST_HEADER: Self::Header = ()

Source§

type Header = ()

Source§

fn write_data<W: Write>(&self, writer: &mut W) -> Result<usize, DataWriteError>

Source§

fn read_data<R: Read>( reader: &mut R, _header: &Self::Header, ) -> Result<Self, DataReadError>

Source§

impl DataFormat for i64

Source§

const LATEST_HEADER: Self::Header = ()

Source§

type Header = ()

Source§

fn write_data<W: Write>(&self, writer: &mut W) -> Result<usize, DataWriteError>

Source§

fn read_data<R: Read>( reader: &mut R, _header: &Self::Header, ) -> Result<Self, DataReadError>

Source§

impl DataFormat for i128

Source§

const LATEST_HEADER: Self::Header = ()

Source§

type Header = ()

Source§

fn write_data<W: Write>(&self, writer: &mut W) -> Result<usize, DataWriteError>

Source§

fn read_data<R: Read>( reader: &mut R, _header: &Self::Header, ) -> Result<Self, DataReadError>

Source§

impl DataFormat for u8

Source§

const LATEST_HEADER: Self::Header = ()

Source§

type Header = ()

Source§

fn write_data<W: Write>(&self, writer: &mut W) -> Result<usize, DataWriteError>

Source§

fn read_data<R: Read>( reader: &mut R, _header: &Self::Header, ) -> Result<Self, DataReadError>

Source§

impl DataFormat for u16

Source§

const LATEST_HEADER: Self::Header = ()

Source§

type Header = ()

Source§

fn write_data<W: Write>(&self, writer: &mut W) -> Result<usize, DataWriteError>

Source§

fn read_data<R: Read>( reader: &mut R, _header: &Self::Header, ) -> Result<Self, DataReadError>

Source§

impl DataFormat for u32

Source§

const LATEST_HEADER: Self::Header = ()

Source§

type Header = ()

Source§

fn write_data<W: Write>(&self, writer: &mut W) -> Result<usize, DataWriteError>

Source§

fn read_data<R: Read>( reader: &mut R, _header: &Self::Header, ) -> Result<Self, DataReadError>

Source§

impl DataFormat for u64

Source§

const LATEST_HEADER: Self::Header = ()

Source§

type Header = ()

Source§

fn write_data<W: Write>(&self, writer: &mut W) -> Result<usize, DataWriteError>

Source§

fn read_data<R: Read>( reader: &mut R, _header: &Self::Header, ) -> Result<Self, DataReadError>

Source§

impl DataFormat for u128

Source§

const LATEST_HEADER: Self::Header = ()

Source§

type Header = ()

Source§

fn write_data<W: Write>(&self, writer: &mut W) -> Result<usize, DataWriteError>

Source§

fn read_data<R: Read>( reader: &mut R, _header: &Self::Header, ) -> Result<Self, DataReadError>

Source§

impl DataFormat for ()

Source§

const LATEST_HEADER: Self::Header = ()

Source§

type Header = ()

Source§

fn write_header<W: Write>( &self, _writer: &mut W, ) -> Result<usize, DataWriteError>

Source§

fn read_header<R: Read>(_reader: &mut R) -> Result<Self::Header, DataReadError>

Source§

fn write_data<W: Write>(&self, _writer: &mut W) -> Result<usize, DataWriteError>

Source§

fn read_data<R: Read>( _reader: &mut R, _header: &Self::Header, ) -> Result<Self, DataReadError>

Source§

impl DataFormat for usize

Source§

const LATEST_HEADER: Self::Header = ()

Source§

type Header = ()

Source§

fn write_data<W: Write>(&self, writer: &mut W) -> Result<usize, DataWriteError>

Source§

fn read_data<R: Read>( reader: &mut R, header: &Self::Header, ) -> Result<Self, DataReadError>

Source§

impl DataFormat for String

Source§

const LATEST_HEADER: Self::Header = ()

Source§

type Header = ()

Source§

fn write_data<W: Write>(&self, writer: &mut W) -> Result<usize, DataWriteError>

Source§

fn read_data<R: Read>( reader: &mut R, _header: &Self::Header, ) -> Result<Self, DataReadError>

Source§

impl DataFormat for Ipv4Addr

Source§

const LATEST_HEADER: Self::Header = ()

Source§

type Header = ()

Source§

fn write_data<W: Write>(&self, writer: &mut W) -> Result<usize, DataWriteError>

Source§

fn read_data<R: Read>( reader: &mut R, _header: &Self::Header, ) -> Result<Self, DataReadError>

Source§

impl DataFormat for Ipv6Addr

Source§

const LATEST_HEADER: Self::Header = ()

Source§

type Header = ()

Source§

fn write_data<W: Write>(&self, writer: &mut W) -> Result<usize, DataWriteError>

Source§

fn read_data<R: Read>( reader: &mut R, _header: &Self::Header, ) -> Result<Self, DataReadError>

Source§

impl DataFormat for SocketAddrV4

Source§

const LATEST_HEADER: Self::Header = ()

Source§

type Header = ()

Source§

fn write_data<W: Write>(&self, writer: &mut W) -> Result<usize, DataWriteError>

Source§

fn read_data<R: Read>( reader: &mut R, header: &Self::Header, ) -> Result<Self, DataReadError>

Source§

impl DataFormat for SocketAddrV6

Source§

const LATEST_HEADER: Self::Header = ()

Source§

type Header = ()

Source§

fn write_data<W: Write>(&self, writer: &mut W) -> Result<usize, DataWriteError>

Source§

fn read_data<R: Read>( reader: &mut R, header: &Self::Header, ) -> Result<Self, DataReadError>

Source§

impl DataFormat for DateTime<Utc>

Source§

const LATEST_HEADER: Self::Header = ()

Source§

type Header = ()

Source§

fn write_data<W: Write>(&self, writer: &mut W) -> Result<usize, DataWriteError>

Source§

fn read_data<R: Read>( reader: &mut R, _header: &Self::Header, ) -> Result<Self, DataReadError>

Source§

impl DataFormat for Spur

Source§

const LATEST_HEADER: Self::Header = ()

Source§

type Header = ()

Source§

fn write_data<W: Write>(&self, writer: &mut W) -> Result<usize, DataWriteError>

Source§

fn read_data<R: Read>( reader: &mut R, _header: &Self::Header, ) -> Result<Self, DataReadError>

Source§

impl DataFormat for RetentionPolicy

Source§

impl DataFormat for NonZeroU8

Source§

const LATEST_HEADER: Self::Header = ()

Source§

type Header = ()

Source§

fn write_data<W: Write>(&self, writer: &mut W) -> Result<usize, DataWriteError>

Source§

fn read_data<R: Read>( reader: &mut R, _header: &Self::Header, ) -> Result<Self, DataReadError>

Source§

impl<A: DataFormat, B: DataFormat> DataFormat for (A, B)

Source§

const LATEST_HEADER: Self::Header

Source§

type Header = (<A as DataFormat>::Header, <B as DataFormat>::Header)

Source§

fn write_header<W: Write>( &self, writer: &mut W, ) -> Result<usize, DataWriteError>

Source§

fn read_header<R: Read>(reader: &mut R) -> Result<Self::Header, DataReadError>

Source§

fn write_data<W: Write>(&self, writer: &mut W) -> Result<usize, DataWriteError>

Source§

fn read_data<R: Read>( reader: &mut R, header: &Self::Header, ) -> Result<Self, DataReadError>

Source§

impl<A: DataFormat, B: DataFormat, C: DataFormat> DataFormat for (A, B, C)

Source§

const LATEST_HEADER: Self::Header

Source§

type Header = (<A as DataFormat>::Header, <B as DataFormat>::Header, <C as DataFormat>::Header)

Source§

fn write_header<W: Write>( &self, writer: &mut W, ) -> Result<usize, DataWriteError>

Source§

fn read_header<R: Read>(reader: &mut R) -> Result<Self::Header, DataReadError>

Source§

fn write_data<W: Write>(&self, writer: &mut W) -> Result<usize, DataWriteError>

Source§

fn read_data<R: Read>( reader: &mut R, header: &Self::Header, ) -> Result<Self, DataReadError>

Source§

impl<K, V> DataFormat for HashMap<K, V>
where K: DataFormat + Eq + Hash, V: DataFormat,

Source§

const LATEST_HEADER: Self::Header

Source§

type Header = (<K as DataFormat>::Header, <V as DataFormat>::Header)

Source§

fn write_data<W: Write>(&self, writer: &mut W) -> Result<usize, DataWriteError>

Source§

fn read_data<R: Read>( reader: &mut R, (key_header, value_header): &Self::Header, ) -> Result<Self, DataReadError>

Source§

impl<K, V> DataFormat for IndexMap<K, V>
where K: DataFormat + Eq + Hash, V: DataFormat,

Source§

const LATEST_HEADER: Self::Header

Source§

type Header = (<K as DataFormat>::Header, <V as DataFormat>::Header)

Source§

fn write_data<W: Write>(&self, writer: &mut W) -> Result<usize, DataWriteError>

Source§

fn read_data<R: Read>( reader: &mut R, (key_header, value_header): &Self::Header, ) -> Result<Self, DataReadError>

Source§

impl<T> DataFormat for HashSet<T>
where T: DataFormat + Eq + Hash,

Source§

const LATEST_HEADER: Self::Header = T::LATEST_HEADER

Source§

type Header = <T as DataFormat>::Header

Source§

fn write_data<W: Write>(&self, writer: &mut W) -> Result<usize, DataWriteError>

Source§

fn read_data<R: Read>( reader: &mut R, header: &Self::Header, ) -> Result<Self, DataReadError>

Source§

impl<T> DataFormat for IndexSet<T>
where T: DataFormat + Eq + Hash,

Source§

const LATEST_HEADER: Self::Header = T::LATEST_HEADER

Source§

type Header = <T as DataFormat>::Header

Source§

fn write_data<W: Write>(&self, writer: &mut W) -> Result<usize, DataWriteError>

Source§

fn read_data<R: Read>( reader: &mut R, header: &Self::Header, ) -> Result<Self, DataReadError>

Source§

impl<T: DataFormat + Default + Copy, const N: usize> DataFormat for [T; N]

Source§

const LATEST_HEADER: Self::Header = T::LATEST_HEADER

Source§

type Header = <T as DataFormat>::Header

Source§

fn write_data<W: Write>(&self, writer: &mut W) -> Result<usize, DataWriteError>

Source§

fn read_data<R: Read>( reader: &mut R, header: &Self::Header, ) -> Result<Self, DataReadError>

Source§

impl<T: DataFormat> DataFormat for Option<T>

Source§

const LATEST_HEADER: Self::Header = T::LATEST_HEADER

Source§

type Header = <T as DataFormat>::Header

Source§

fn write_data<W: Write>(&self, writer: &mut W) -> Result<usize, DataWriteError>

Source§

fn read_data<R: Read>( reader: &mut R, header: &Self::Header, ) -> Result<Self, DataReadError>

Source§

impl<T: DataFormat> DataFormat for Box<T>

Source§

const LATEST_HEADER: Self::Header = T::LATEST_HEADER

Source§

type Header = <T as DataFormat>::Header

Source§

fn write_data<W: Write>(&self, writer: &mut W) -> Result<usize, DataWriteError>

Source§

fn read_data<R: Read>( reader: &mut R, header: &Self::Header, ) -> Result<Self, DataReadError>

Source§

impl<T: DataFormat> DataFormat for Vec<T>

Source§

const LATEST_HEADER: Self::Header = T::LATEST_HEADER

Source§

type Header = <T as DataFormat>::Header

Source§

fn write_data<W: Write>(&self, writer: &mut W) -> Result<usize, DataWriteError>

Source§

fn read_data<R: Read>( reader: &mut R, header: &Self::Header, ) -> Result<Self, DataReadError>

Implementors§

Source§

impl DataFormat for KeySource

Source§

const LATEST_HEADER: Self::Header = {transmute(0x01): <key_source::KeySource as format::DataFormat>::Header}

Source§

type Header = u8

Source§

impl DataFormat for NodeTargets

Source§

const LATEST_HEADER: Self::Header = NodeTarget::LATEST_HEADER

Source§

type Header = <NodeTarget as DataFormat>::Header

Source§

impl DataFormat for AgentPeer

Source§

const LATEST_HEADER: Self::Header = {transmute(0x01): <state::node_state::AgentPeer as format::DataFormat>::Header}

Source§

type Header = u8

Source§

impl DataFormat for DocHeightRequest

Source§

impl DataFormat for HeightRequest

Source§

impl DataFormat for KeyState

Source§

const LATEST_HEADER: Self::Header = {transmute(0x01): <state::node_state::KeyState as format::DataFormat>::Header}

Source§

type Header = u8

Source§

impl DataFormat for NetworkId

Source§

const LATEST_HEADER: Self::Header = {transmute(0x01): <state::network::NetworkId as format::DataFormat>::Header}

Source§

type Header = u8

Source§

impl DataFormat for NodeType

Source§

const LATEST_HEADER: Self::Header = {transmute(0x01): <state::node_type::NodeType as format::DataFormat>::Header}

Source§

type Header = u8

Source§

impl DataFormat for BinaryEntry

Source§

const LATEST_HEADER: Self::Header = {transmute(0x01): <binaries::BinaryEntry as format::DataFormat>::Header}

Source§

type Header = u8

Source§

impl DataFormat for NodeTarget

Source§

impl DataFormat for InternedId

Source§

impl DataFormat for NodeKey

Source§

impl DataFormat for NodeState

Source§

impl DataFormat for NodeStateFormatHeader

Source§

const LATEST_HEADER: Self::Header = {transmute(0x01): <state::node_state::NodeStateFormatHeader as format::DataFormat>::Header}

Source§

type Header = u8

Source§

impl DataFormat for PortConfig

Source§

const LATEST_HEADER: Self::Header = {transmute(0x01): <state::port_config::PortConfig as format::DataFormat>::Header}

Source§

type Header = u8

Source§

impl DataFormat for PackedUint