Crate wire_framed

Source
Expand description

wire-framed is a library for encoding and decoding frames using a custom binary protocol. It prioritizes ease-of-use.

It reolves around two traits FromFrame and IntoFrame. These traits can be manually implemented relatively easily using the utilities provided in the utils module or automatically using the Encoding and Decoding macros.

§Usage

use wire_framed::prelude::*;
 
#[derive(Debug, Encoding, Decoding, PartialEq, Eq)]
pub struct Foo {
    pub id: u32,
    pub name: String,
    pub description: String,
    pub created_at: u64,
}
 
 
fn send() -> Result<(), std::io::Error> {
    let foo = Foo {
        id: 1,
        name: "John".to_string(),
        description: "John is a legend".to_string(),
        created_at: 1234567890,
    };
 
    let frame = foo.into_frame();
    send_to_socket(frame)
}
 
 
fn recv() -> Result<(), std::io::Error> {
    let bytes = recv_from_socket();
    let foo = Foo::from_frame(bytes)?;

    // process foo
}
 

Re-exports§

pub use wire_framed_core;
pub use wire_framed_core::bytes;

Modules§

codec
prelude
utils

Structs§

Bytes
A cheaply cloneable and sliceable chunk of contiguous memory.
BytesMut
A unique reference to a contiguous slice of memory.
FrameCodec
Codec type for [Message] that implements tokio_util::codec::Decoder and tokio_util::codec::Encoder.

Traits§

Buf
Read bytes from a buffer.
BufMut
A trait for values that provide sequential write access to bytes.
FromFrame
Trait for converting a frame into `Self.
IntoFrame
Trait for converting a Self into a frame.

Type Aliases§

Framed
FramedRead
FramedWrite

Derive Macros§

Decoding
Implements the FromFrame traits for the type.
Encoding
Implements the IntoFrame traits for the type.