#byte #bson #packet #networking #serde

tora

A lite, byte-based serialization and deserialization library

8 releases

0.1.8 Sep 3, 2024
0.1.7 Jul 18, 2024
0.1.5 Dec 14, 2023
0.1.2 Apr 7, 2023
0.1.1 Mar 23, 2023

#1276 in Encoding

Download history 5/week @ 2024-08-02 124/week @ 2024-08-30 16/week @ 2024-09-06 27/week @ 2024-09-13 16/week @ 2024-09-20 20/week @ 2024-09-27 6/week @ 2024-10-04

515 downloads per month

Custom license

19KB
444 lines

Tora

A lite, byte-based serialization and deserialization library


*A zero-serde solution*

Examples

Network data transfer

Host

use std::io;
use std::net::TcpListener;

use tora::write::ToraWrite;
use tora::WriteStruct;

#[derive(WriteStruct)]
struct Message {
    sender: String,
    content: String,
}

fn main() -> io::Result<()> {
    let listener = TcpListener::bind("127.0.0.1:12345")?;
    let (mut conn, _) = listener.accept()?;

    let message = Message {
        sender: "John".to_string(),
        content: "Hello, world!".to_string(),
    };
    conn.writes(&message)
}

Client

use std::io;
use std::net::TcpStream;

use tora::read::ToraRead;
use tora::ReadStruct;

#[derive(ReadStruct)]
struct Message {
    sender: String,
    content: String,
}

fn main() -> io::Result<()> {
    let mut stream = TcpStream::connect("127.0.0.1:12345")?;
    let Message { sender, content } = stream.reads()?;
    println!("{}: {}", sender, content);
    Ok(())
}

Dependencies

~235–680KB
~16K SLoC