#codec #binary #decoding #wire #framed #protocols

wire-framed

A library for encoding and decoding structures into a binary data format

15 releases (4 breaking)

0.5.0 Jul 3, 2023
0.4.2 Jun 18, 2023
0.4.0 May 30, 2023
0.3.0 May 30, 2023
0.1.8 May 17, 2023

#1867 in Encoding

Download history 2/week @ 2024-02-22 2/week @ 2024-02-29 33/week @ 2024-03-28 18/week @ 2024-04-04

51 downloads per month

Custom license

36KB
755 lines

wire-framed

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
}

Dependencies

~4–5.5MB
~93K SLoC