Crates.io | tora |
lib.rs | tora |
version | 0.1.8 |
source | src |
created_at | 2023-03-23 04:19:15.401231 |
updated_at | 2024-09-03 20:05:35.418961 |
description | A lite, byte-based serialization and deserialization library. |
homepage | |
repository | https://github.com/imajindevon/tora |
max_upload_size | |
id | 817768 |
size | 18,532 |
A lite, byte-based serialization and deserialization library
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)
}
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(())
}