Send-it
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
Example
use VarWriter;
use VarReader;
// Create a new VarWriter
let mut writer = new;
// Add some sample data
writer.add_string;
writer.add_string;
// Use any Write implementor as your stream (i.e. TcpStream)
let mut stream: = Vec new;
// encode the data and send it over the stream
writer.send.expect;
// 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 = new;
// read the data from the stream
let data = reader.read_data.unwrap;
assert_eq!;
assert_eq!;
Features
writing (enabled by default)
Adds the VarWriter struct, which is used to write data to a stream using variable-length encoding
reading (enabled by default)
Adds the VarReader struct, which is used to read data from a stream using variable-length encoding
big-endian (disabled by default)
Changes the encoding to use big-endian instead of little-endian
Usage
VarWriter
A struct used to write data to a stream using variable-length encoding
feature: 'writing' (enabled by default)
use VarWriter;
// Create a new VarWriter
let mut writer = new;
// Add some sample data
writer.add_string;
writer.add_string;
// Use any Write implementor as your stream (i.e. TcpStream)
let mut stream: = Vec new;
// encode the data and send it over the stream
writer.send.expect;
VarReader
A struct used to read data from a stream using variable-length encoding
feature: 'reading' (enabled by default)
use VarReader;
// Create a sample stream, this is the output from the above VarWriter example
let stream: = vec!;
// 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 = new;
// read the data from the stream
let data = reader.read_data.unwrap;
assert_eq!;
assert_eq!;
Segment
A struct used to represent a segment of data
use Segment;
let mut segment = new;
segment.append;
segment.append;
assert_eq!;