librsv 0.1.0

A simple crate for encoding/decoding the RSV file format (Rows of String Values).
Documentation

RSV (Rows of String Values) is a very simple binary format for encoding tabular data. It is similar to CSV, but even simpler due to the avoidance of escape characters. This is achieved by encoding strings as UTF-8, and using bytes that can never appear in valid UTF-8 strings as delimiters.

The full specification can be found at: https://github.com/Stenway/RSV-Specification

Basic usage

There are three convenience methods for encoding and decoding RSV documents in one go:

  • encode_rsv - Encodes an RSV document from a structure such as Vec<Vec<Option<String>>>.
  • decode_rsv- Decodes an RSV document into a Vec<Vec<Option<String>>>.
  • decode_rsv_borrowed- Decodes an RSV document into a Vec<Vec<Option<&str>>>.
use librsv::{encode_rsv, decode_rsv};

let data = vec![
vec![Some("Hello".into()), Some("world".into())],
vec![Some("asdf".into()), None, Some("".into())],
];

let encoded = encode_rsv(&data);
let decoded = decode_rsv(&encoded).unwrap();

assert_eq!(data, decoded);

Advanced usage

For more control, there exists the RsvWriter and RsvReader structs which allow for more control over how the data is encoded or decoded respectively:

use librsv::{RsvReader, RsvWriter};

/// Write an RSV document
let mut writer = RsvWriter::new();
writer.start_row();
writer.push_str("Hello");
writer.push_null();
let buffer = writer.finish();

/// Read an RSV document and prints its contents to the screen
let mut reader = RsvReader::new(&buffer);
for row in reader.rows() {
let row = row.unwrap();
for value in row.values() {
match value.unwrap() {
Some(str) => print!("\"{str}\", "),
None => print!("null, ")
}
println!();
}
}