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
515 downloads per month
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