Crates.io | send-it |
lib.rs | send-it |
version | 0.2.2 |
source | src |
created_at | 2023-12-04 02:15:25.93676 |
updated_at | 2024-01-31 05:01:45.973932 |
description | A tool for sending large amounts of data over a stream or network. |
homepage | |
repository | https://github.com/Sk3pz/send-it |
max_upload_size | |
id | 1057189 |
size | 30,123 |
A rust crate for sending multiple segments of information together over a stream using variable length encoding.
* this does not compress or encrypt the data. It turns the data into a stream of bytes and adds length information about each segment
use send_it::writer::VarWriter;
use send_it::reader::VarReader;
// Create a new VarWriter
let mut writer = VarWriter::new();
// Add some sample data
writer.add_string("Hello, ");
writer.add_string("World!");
// Use any Write implementor as your stream (i.e. TcpStream)
let mut stream: Vec<u8> = Vec::new();
// encode the data and send it over the stream
writer.send(&mut stream).expect("Failed to send data");
// turn the vector into a slice as Vec does not implement Read
let mut fake_stream = stream.as_slice();
// create a new VarReader to read from the stream we wrote to
let mut reader = VarReader::new(&mut fake_stream);
// read the data from the stream
let data = reader.read_data().unwrap();
assert_eq!(data[0].to_string(), "Hello, ");
assert_eq!(data[1].to_string(), "World!");
Adds the VarWriter struct, which is used to write data to a stream using variable-length encoding
Adds the VarReader struct, which is used to read data from a stream using variable-length encoding
Changes the encoding to use big-endian instead of little-endian
A struct used to write data to a stream using variable-length encoding
feature: 'writing' (enabled by default)
use send_it::writer::VarWriter;
// Create a new VarWriter
let mut writer = VarWriter::new();
// Add some sample data
writer.add_string("Hello, ");
writer.add_string("World!");
// Use any Write implementor as your stream (i.e. TcpStream)
let mut stream: Vec<u8> = Vec::new();
// encode the data and send it over the stream
writer.send(&mut stream).expect("Failed to send data");
A struct used to read data from a stream using variable-length encoding
feature: 'reading' (enabled by default)
use send_it::reader::VarReader;
// Create a sample stream, this is the output from the above VarWriter example
let stream: Vec<u8> = vec![21, 7, 0, 0, 0, 72, 101, 108, 108, 111, 44, 32, 6, 0, 0, 0, 87, 111, 114, 108, 100, 33];
// turn the vector into a slice as Vec does not implement Read
let mut fake_stream = stream.as_slice();
// create a new VarReader
let mut reader = VarReader::new(&mut fake_stream);
// read the data from the stream
let data = reader.read_data().unwrap();
assert_eq!(data[0].to_string(), "Hello, ");
assert_eq!(data[1].to_string(), "World!");
A struct used to represent a segment of data
use send_it::Segment;
let mut segment = Segment::new();
segment.append(Segment::from("Hello, "));
segment.append(Segment::from("World!"));
assert_eq!(segment.to_string(), "Hello, World!");