#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

#1174 in Encoding

Download history 211/week @ 2024-07-18 39/week @ 2024-07-25 6/week @ 2024-08-01 114/week @ 2024-08-29 26/week @ 2024-09-05 24/week @ 2024-09-12 17/week @ 2024-09-19 17/week @ 2024-09-26 11/week @ 2024-10-03

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

~240–690KB
~16K SLoC