[][src]Crate rustt

RusTT

TT is a format used to serialize/deserialize data efficiently and fast. TT can be used to transmit data between processes or over the network. TT is designed to not transmit any unneccecary data and keep data sizes small but still easily readable to the machine. The TT data is structured like a key-value format, where keys can be any integer, String or Byte sequence. A value can be that or a Sequence or a Map.

At the moment only TTv3 is supported, so all encoding/decoding will be done using that. When another version is supported the enum Version will be used to specify the (de)serialization version.

untyped TT Values

In cases where you cannot define a static structure, there are ttv3::Key and ttv3::Value. These enums define alll possible values for a key and value.

Since TT can have floats as keys, they will be represented by ttv3::serde::TtF32 or ttv3::serde::TtF64, wich is a wrapper around u32 and u64 to be able to use it in a ttv3::Value::Map. This is not how rust usualy works and should only be used within ttv3::Value

enum Key {
	String(String),
	Bytes(Vec<u8>),
	I8(i8),
	I16(i16),
	I32(i32),
	I64(i64),
	U8(u8),
	U16(u16),
	U32(u32),
	U64(u64),
	Bool(bool),
	F32(rustt::ttv3::TtF32),
	F64(rustt::ttv3::TtF64),
}
enum Value {
	String(String),
	Bytes(Vec<u8>),
	I8(i8),
	I16(i16),
	I32(i32),
	I64(i64),
	U8(u8),
	U16(u16),
	U32(u32),
	U64(u64),
	Bool(bool),
	F32(rustt::ttv3::TtF32),
	F64(rustt::ttv3::TtF64),
	Map(std::collections::HashMap<Key, Value>),
	Vec(Vec<Value>),
}

Parsing TT as strongly types data

Serde provides macro's for serializing and deserializing data structures. Rust TT is able to use these macros to do all the same things serde_json and the like can do too. For performance reasons it you should use serde_bytes for Vec<u8> and [u8]. If you do not do this other applications will read this as an array of bytes, and not as a Byte Sequence. the distinction being, in TT a byte sequence is encoded just like a string while a sequence of bytes is encoded like any other array.

Versions

TT comes in diverent versions. This crate only supports ttv3 as it is the most recent one. Any upcomming tt versions will be supported, this is the reason there is a diferent module for ttv3 specific code. ttv3::Key, ttv3::Value and ttv3::Error are all specific to ttv3 (except maybe ttv3::Error) so to keep this crate backwards comptible those are in a diferent submodule.

Modules

ttv3

TTv3 contains all the v3 specific things like Error, Key and Value

Enums

Version

Functions

from_bytes

Deserialize an instance of type T from a TT byte slice

from_reader

Deserialize an instance of type T from an IO stream of TT.

to_size

Get the size of T serialized into bytes. This shoul'd not be used publicly to pre-allocate for to_vec, this already reserves enough space using this function.

to_vec

Serialize T into a byte vector.