Trait bin_proto::Protocol

source ·
pub trait Protocol: Sized {
    // Required methods
    fn read(
        read: &mut dyn BitRead,
        byte_order: ByteOrder,
        ctx: &mut dyn Any
    ) -> Result<Self, Error>;
    fn write(
        &self,
        write: &mut dyn BitWrite,
        byte_order: ByteOrder,
        ctx: &mut dyn Any
    ) -> Result<(), Error>;

    // Provided methods
    fn from_bytes(bytes: &[u8], byte_order: ByteOrder) -> Result<Self, Error> { ... }
    fn from_bytes_ctx(
        bytes: &[u8],
        byte_order: ByteOrder,
        ctx: &mut dyn Any
    ) -> Result<Self, Error> { ... }
    fn bytes(&self, byte_order: ByteOrder) -> Result<Vec<u8>, Error> { ... }
    fn bytes_ctx(
        &self,
        byte_order: ByteOrder,
        ctx: &mut dyn Any
    ) -> Result<Vec<u8>, Error> { ... }
}
Expand description

A trait for bit-level co/dec.

Required Methods§

source

fn read( read: &mut dyn BitRead, byte_order: ByteOrder, ctx: &mut dyn Any ) -> Result<Self, Error>

Reads self from a stream.

Blocks until a value is received.

source

fn write( &self, write: &mut dyn BitWrite, byte_order: ByteOrder, ctx: &mut dyn Any ) -> Result<(), Error>

Writes a value to a stream.

Provided Methods§

source

fn from_bytes(bytes: &[u8], byte_order: ByteOrder) -> Result<Self, Error>

Parses a new value from its raw byte representation without context.

source

fn from_bytes_ctx( bytes: &[u8], byte_order: ByteOrder, ctx: &mut dyn Any ) -> Result<Self, Error>

Parses a new value from its raw byte representation with additional context.

source

fn bytes(&self, byte_order: ByteOrder) -> Result<Vec<u8>, Error>

Gets the raw bytes of this type without context.

source

fn bytes_ctx( &self, byte_order: ByteOrder, ctx: &mut dyn Any ) -> Result<Vec<u8>, Error>

Gets the raw bytes of this type with provided context.

Object Safety§

This trait is not object safe.

Implementations on Foreign Types§

source§

impl Protocol for bool

source§

fn read( read: &mut dyn BitRead, _: ByteOrder, _: &mut dyn Any ) -> Result<Self, Error>

source§

fn write( &self, write: &mut dyn BitWrite, _: ByteOrder, _: &mut dyn Any ) -> Result<(), Error>

source§

impl Protocol for f32

source§

fn read( read: &mut dyn BitRead, byte_order: ByteOrder, _: &mut dyn Any ) -> Result<Self, Error>

source§

fn write( &self, write: &mut dyn BitWrite, byte_order: ByteOrder, _: &mut dyn Any ) -> Result<(), Error>

source§

impl Protocol for f64

source§

fn read( read: &mut dyn BitRead, byte_order: ByteOrder, _: &mut dyn Any ) -> Result<Self, Error>

source§

fn write( &self, write: &mut dyn BitWrite, byte_order: ByteOrder, _: &mut dyn Any ) -> Result<(), Error>

source§

impl Protocol for i8

source§

fn read( read: &mut dyn BitRead, _: ByteOrder, _: &mut dyn Any ) -> Result<Self, Error>

source§

fn write( &self, write: &mut dyn BitWrite, _: ByteOrder, _: &mut dyn Any ) -> Result<(), Error>

source§

impl Protocol for i16

source§

fn read( read: &mut dyn BitRead, byte_order: ByteOrder, _: &mut dyn Any ) -> Result<Self, Error>

source§

fn write( &self, write: &mut dyn BitWrite, byte_order: ByteOrder, _: &mut dyn Any ) -> Result<(), Error>

source§

impl Protocol for i32

source§

fn read( read: &mut dyn BitRead, byte_order: ByteOrder, _: &mut dyn Any ) -> Result<Self, Error>

source§

fn write( &self, write: &mut dyn BitWrite, byte_order: ByteOrder, _: &mut dyn Any ) -> Result<(), Error>

source§

impl Protocol for i64

source§

fn read( read: &mut dyn BitRead, byte_order: ByteOrder, _: &mut dyn Any ) -> Result<Self, Error>

source§

fn write( &self, write: &mut dyn BitWrite, byte_order: ByteOrder, _: &mut dyn Any ) -> Result<(), Error>

source§

impl Protocol for i128

source§

fn read( read: &mut dyn BitRead, byte_order: ByteOrder, _: &mut dyn Any ) -> Result<Self, Error>

source§

fn write( &self, write: &mut dyn BitWrite, byte_order: ByteOrder, _: &mut dyn Any ) -> Result<(), Error>

source§

impl Protocol for u8

source§

fn read( read: &mut dyn BitRead, _: ByteOrder, _: &mut dyn Any ) -> Result<Self, Error>

source§

fn write( &self, write: &mut dyn BitWrite, _: ByteOrder, _: &mut dyn Any ) -> Result<(), Error>

source§

impl Protocol for u16

source§

fn read( read: &mut dyn BitRead, byte_order: ByteOrder, _: &mut dyn Any ) -> Result<Self, Error>

source§

fn write( &self, write: &mut dyn BitWrite, byte_order: ByteOrder, _: &mut dyn Any ) -> Result<(), Error>

source§

impl Protocol for u32

source§

fn read( read: &mut dyn BitRead, byte_order: ByteOrder, _: &mut dyn Any ) -> Result<Self, Error>

source§

fn write( &self, write: &mut dyn BitWrite, byte_order: ByteOrder, _: &mut dyn Any ) -> Result<(), Error>

source§

impl Protocol for u64

source§

fn read( read: &mut dyn BitRead, byte_order: ByteOrder, _: &mut dyn Any ) -> Result<Self, Error>

source§

fn write( &self, write: &mut dyn BitWrite, byte_order: ByteOrder, _: &mut dyn Any ) -> Result<(), Error>

source§

impl Protocol for u128

source§

fn read( read: &mut dyn BitRead, byte_order: ByteOrder, _: &mut dyn Any ) -> Result<Self, Error>

source§

fn write( &self, write: &mut dyn BitWrite, byte_order: ByteOrder, _: &mut dyn Any ) -> Result<(), Error>

source§

impl Protocol for ()

source§

fn read( read: &mut dyn BitRead, byte_order: ByteOrder, ctx: &mut dyn Any ) -> Result<Self, Error>

source§

fn write( &self, write: &mut dyn BitWrite, byte_order: ByteOrder, ctx: &mut dyn Any ) -> Result<(), Error>

source§

impl Protocol for CString

source§

fn read( read: &mut dyn BitRead, byte_order: ByteOrder, ctx: &mut dyn Any ) -> Result<Self, Error>

source§

fn write( &self, write: &mut dyn BitWrite, byte_order: ByteOrder, ctx: &mut dyn Any ) -> Result<(), Error>

source§

impl Protocol for PhantomPinned

source§

fn read( _: &mut dyn BitRead, _: ByteOrder, _: &mut dyn Any ) -> Result<Self, Error>

source§

fn write( &self, _: &mut dyn BitWrite, _: ByteOrder, _: &mut dyn Any ) -> Result<(), Error>

source§

impl Protocol for Ipv4Addr

source§

fn read( read: &mut dyn BitRead, byte_order: ByteOrder, ctx: &mut dyn Any ) -> Result<Self, Error>

source§

fn write( &self, write: &mut dyn BitWrite, byte_order: ByteOrder, ctx: &mut dyn Any ) -> Result<(), Error>

source§

impl Protocol for Ipv6Addr

source§

fn read( read: &mut dyn BitRead, byte_order: ByteOrder, ctx: &mut dyn Any ) -> Result<Self, Error>

source§

fn write( &self, write: &mut dyn BitWrite, byte_order: ByteOrder, ctx: &mut dyn Any ) -> Result<(), Error>

source§

impl<A> Protocol for (A,)
where A: Protocol,

source§

fn read( read: &mut dyn BitRead, byte_order: ByteOrder, ctx: &mut dyn Any ) -> Result<Self, Error>

source§

fn write( &self, write: &mut dyn BitWrite, byte_order: ByteOrder, ctx: &mut dyn Any ) -> Result<(), Error>

source§

impl<A, B> Protocol for (A, B)
where A: Protocol, B: Protocol,

source§

fn read( read: &mut dyn BitRead, byte_order: ByteOrder, ctx: &mut dyn Any ) -> Result<Self, Error>

source§

fn write( &self, write: &mut dyn BitWrite, byte_order: ByteOrder, ctx: &mut dyn Any ) -> Result<(), Error>

source§

impl<A, B, C> Protocol for (A, B, C)
where A: Protocol, B: Protocol, C: Protocol,

source§

fn read( read: &mut dyn BitRead, byte_order: ByteOrder, ctx: &mut dyn Any ) -> Result<Self, Error>

source§

fn write( &self, write: &mut dyn BitWrite, byte_order: ByteOrder, ctx: &mut dyn Any ) -> Result<(), Error>

source§

impl<A, B, C, D> Protocol for (A, B, C, D)
where A: Protocol, B: Protocol, C: Protocol, D: Protocol,

source§

fn read( read: &mut dyn BitRead, byte_order: ByteOrder, ctx: &mut dyn Any ) -> Result<Self, Error>

source§

fn write( &self, write: &mut dyn BitWrite, byte_order: ByteOrder, ctx: &mut dyn Any ) -> Result<(), Error>

source§

impl<A, B, C, D, E> Protocol for (A, B, C, D, E)
where A: Protocol, B: Protocol, C: Protocol, D: Protocol, E: Protocol,

source§

fn read( read: &mut dyn BitRead, byte_order: ByteOrder, ctx: &mut dyn Any ) -> Result<Self, Error>

source§

fn write( &self, write: &mut dyn BitWrite, byte_order: ByteOrder, ctx: &mut dyn Any ) -> Result<(), Error>

source§

impl<A, B, C, D, E, F> Protocol for (A, B, C, D, E, F)
where A: Protocol, B: Protocol, C: Protocol, D: Protocol, E: Protocol, F: Protocol,

source§

fn read( read: &mut dyn BitRead, byte_order: ByteOrder, ctx: &mut dyn Any ) -> Result<Self, Error>

source§

fn write( &self, write: &mut dyn BitWrite, byte_order: ByteOrder, ctx: &mut dyn Any ) -> Result<(), Error>

source§

impl<A, B, C, D, E, F, G> Protocol for (A, B, C, D, E, F, G)
where A: Protocol, B: Protocol, C: Protocol, D: Protocol, E: Protocol, F: Protocol, G: Protocol,

source§

fn read( read: &mut dyn BitRead, byte_order: ByteOrder, ctx: &mut dyn Any ) -> Result<Self, Error>

source§

fn write( &self, write: &mut dyn BitWrite, byte_order: ByteOrder, ctx: &mut dyn Any ) -> Result<(), Error>

source§

impl<A, B, C, D, E, F, G, H> Protocol for (A, B, C, D, E, F, G, H)
where A: Protocol, B: Protocol, C: Protocol, D: Protocol, E: Protocol, F: Protocol, G: Protocol, H: Protocol,

source§

fn read( read: &mut dyn BitRead, byte_order: ByteOrder, ctx: &mut dyn Any ) -> Result<Self, Error>

source§

fn write( &self, write: &mut dyn BitWrite, byte_order: ByteOrder, ctx: &mut dyn Any ) -> Result<(), Error>

source§

impl<T> Protocol for PhantomData<T>

source§

fn read( _: &mut dyn BitRead, _: ByteOrder, _: &mut dyn Any ) -> Result<Self, Error>

source§

fn write( &self, _: &mut dyn BitWrite, _: ByteOrder, _: &mut dyn Any ) -> Result<(), Error>

source§

impl<T: Protocol + Debug, const N: usize> Protocol for [T; N]

source§

fn read( read: &mut dyn BitRead, byte_order: ByteOrder, ctx: &mut dyn Any ) -> Result<Self, Error>

source§

fn write( &self, write: &mut dyn BitWrite, byte_order: ByteOrder, ctx: &mut dyn Any ) -> Result<(), Error>

source§

impl<T: Protocol> Protocol for Option<T>

source§

fn read( read: &mut dyn BitRead, byte_order: ByteOrder, ctx: &mut dyn Any ) -> Result<Self, Error>

source§

fn write( &self, write: &mut dyn BitWrite, byte_order: ByteOrder, ctx: &mut dyn Any ) -> Result<(), Error>

source§

impl<T: Protocol> Protocol for Box<T>

source§

fn read( read: &mut dyn BitRead, byte_order: ByteOrder, ctx: &mut dyn Any ) -> Result<Self, Error>

source§

fn write( &self, write: &mut dyn BitWrite, byte_order: ByteOrder, ctx: &mut dyn Any ) -> Result<(), Error>

source§

impl<T: Protocol> Protocol for Rc<T>

source§

fn read( read: &mut dyn BitRead, byte_order: ByteOrder, ctx: &mut dyn Any ) -> Result<Self, Error>

source§

fn write( &self, write: &mut dyn BitWrite, byte_order: ByteOrder, ctx: &mut dyn Any ) -> Result<(), Error>

source§

impl<T: Protocol> Protocol for Arc<T>

source§

fn read( read: &mut dyn BitRead, byte_order: ByteOrder, ctx: &mut dyn Any ) -> Result<Self, Error>

source§

fn write( &self, write: &mut dyn BitWrite, byte_order: ByteOrder, ctx: &mut dyn Any ) -> Result<(), Error>

Implementors§