tora

Crates.iotora
lib.rstora
version0.1.8
sourcesrc
created_at2023-03-23 04:19:15.401231
updated_at2024-09-03 20:05:35.418961
descriptionA lite, byte-based serialization and deserialization library.
homepage
repositoryhttps://github.com/imajindevon/tora
max_upload_size
id817768
size18,532
Imajin (ImajinDevon)

documentation

README

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(())
}
Commit count: 10

cargo fmt