emp/lib.rs
1//! # EMP
2//!
3//! ## NOTICE: EMP 1.1.x is not compatable with data from EMP 1.0.x!
4//!
5//! EMP is a bytecode format which is able to pack JSON and NBT data into an
6//! even smaller file size, which is useful for storage of large amounts of
7//! data.
8//!
9//! ### Rust structure
10//!
11//! ```
12//! pub enum Value {
13//! Null,
14//! Object(std::collections::HashMap<std::string::String, Value>),
15//! Array(std::vec::Vec<Value>),
16//! String(std::string::String),
17//! Bit(bool),
18//! Boolean(bool),
19//! Int32(i32),
20//! Float(f32),
21//! Double(f64),
22//! Int64(i64),
23//! Int16(i16),
24//! Int8(i8),
25//! }
26//! ```
27//!
28//! ### Encoding
29//!
30//! Using `emp::encode::encode` you can pass in an `emp::value::Value` and get an `std::vec::Vec<u8>` back, this will encode the data in the `Value` into the bytes that you can then write to a file.
31//!
32//! ### Decoding
33//!
34//! Using `emp::decode::decode` you can pass in a `&[u8]` and get an `Result<emp::value::Value, emp::errors::DecodeError>` in return.
35//!
36//! `DecodeError` is an enum that is as so:
37//!
38//! ```
39//! pub enum DecodeError {
40//! UnexpectedByte(u8, u64),
41//! EOFError,
42//! UnmatchedKey(std::string::String),
43//! StringDecodeError(std::str::Utf8Error),
44//! }
45//! ```
46//!
47//! You can also use `emp::decode::decode_safe` and pass in the same data to decode the data in the same way but if there is an `Err` it instead returns `emp::value::Value::Null`.
48//!
49//! ### Parsing
50//!
51//! Using the `emp::value::parse::from_str` function you can pass in a `&str` to convert it into a `Result<emp::value::Value, emp::errors::ParseError>`. Alternatively you can use `emp::value::parse::from_str_safe` and pass in the same thing to get a `emp::value::Value`, if an error is encounted it returns a `emp::value::Value::Null` instead.
52//!
53//! `ParseError` is an enum that is as so:
54//!
55//! ```
56//! pub enum ParseError {
57//! EOFError,
58//! UnexpectedCharacterError(char),
59//! UnexpectedTokenError(std::string::String),
60//! InvalidKeyError(value::Value),
61//! InvalidNumberError(char),
62//! }
63//! ```
64//!
65//! ### JSON Compatability
66//!
67//! #### Conversion
68//!
69//! This crate is compatible with `serde_json`, by using `emp::value::json::from_json` you can convert a `serde_json::Value` to an `emp::value::Value`, vice versa for `emp::value::json::to_json`.
70//!
71//! #### Encoding
72//!
73//! Using `emp::encode::json::encode_json` you can encode a `serde_json::Value` directly into `emp` bytecode.
74//!
75//! #### Decoding
76//!
77//! Using `emp::decode::json::decode_json` you can decode `emp` bytecode directly into a `serde_json::Value`, this uses `decode_safe` rather than `decode`.
78//! You can also use `emp::decode::json::decode_json_unsafe` to get the error instead of a `serde_json::Value::Null`
79//!
80//! ### String representation
81//!
82//! Strings: Data in quotes
83//! Int32: Regular number
84//! Int16: Number with `s` appended at the end
85//! Int8: Number with `B` appended at the end
86//! Bit: 0 or 1 with `b` appended at the end
87//! Int64: Number with `l` appended at the end
88//! Boolean: `true` or `false`
89//! Null: `null`
90//! Array: Values separated by commas in square brackets
91//! Object: String then a colon then a Value, separated by commas in curly brackets
92//!
93
94pub mod constants;
95pub mod decode;
96pub mod encode;
97pub mod errors;
98pub mod value;