High Performance Serialization Library

FlatBuffers/CapNProto with Flexible Runtime Schemas

Github | Crates.io | Documentation

TODO:

Features

NoProto allows you to store, read & mutate structured data with near zero overhead. It's like Cap'N Proto/Flatbuffers except buffers and schemas are dynamic at runtime instead of requiring compilation. It's like JSON but faster, type safe and allows native types.

Bytewise sorting comes in the box and is a first class operation. The result is two NoProto buffers can be compared at the byte level without deserializing and a correct ordering between the buffer's internal values will be the result. This is extremely useful for storing ordered keys in databases.

NoProto moves the cost of deserialization to the access methods instead of deserializing the entire object ahead of time. This makes it a perfect use case for things like database storage or file storage of structured data.

Compared to FlatBuffers / Cap'N Proto - Schemas are dynamic at runtime, no compilation step - Supports more types and better nested type support - Bytewise sorting is first class operation - Mutate (add/delete/update) existing/imported buffers

Compared to JSON - Has schemas / type safe - Supports bytewise sorting - Faster serialization & deserialization - Supports raw bytes & other native types

Compared to BSON - Faster serialization & deserialization - Has schemas / type safe - Bytewise sorting is first class operation - Supports much larger documents (4GB vs 16MB) - Better collection support & more supported types

Compared to Serde - Supports bytewise sorting - Objects & schemas are dynamic at runtime - Faster serialization & deserialization

| Format | Free De/Serialization | Size Limit | Mutatable | Schemas | Language Agnostic | Runtime Dynamic | Bytewise Sorting | |------------------|-----------------------|------------|-----------|---------|-------------------|-----------------|------------------| | NoProto | ✓ | ~4GB | ✓ | ✓ | ✓ | ✓ | ✓ | | JSON | 𐄂 | Unlimited | ✓ | 𐄂 | ✓ | ✓ | 𐄂 | | BSON | 𐄂 | ~16KB | ✓ | 𐄂 | ✓ | ✓ | 𐄂 | | MessagePack | 𐄂 | Unlimited | ✓ | 𐄂 | ✓ | ✓ | 𐄂 | | FlatBuffers | ✓ | ~2GB | 𐄂 | ✓ | ✓ | 𐄂 | 𐄂 | | Protocol Buffers | 𐄂 | ~2GB | 𐄂 | ✓ | ✓ | 𐄂 | 𐄂 | | Cap'N Proto | ✓ | 2^64 Bytes | 𐄂 | ✓ | ✓ | 𐄂 | 𐄂 | | Serde | 𐄂 | ? | ✓ | ✓ | 𐄂 | 𐄂 | 𐄂 |

Limitations

Quick Example

```rust use noproto::error::NPError; use noproto::NPFactory; use noproto::NP; use noproto::collection::table::NPTable; use noproto::pointer::NP_Ptr;

// JSON is used to describe schema for the factory // Each factory represents a single schema // One factory can be used to serialize/deserialize any number of buffers let userfactory = NPFactory::new(r#"{ "type": "table", "columns": [ ["name", {"type": "string"}], ["pass", {"type": "string"}], ["age", {"type": "uint16"}] ] }"#)?;

// creating a new buffer from the user_factory schema // user_buffer contains a serialized Vec containing our data

let uservec: Vec = userfactory.open(NP::new, |mut buffer| {

// set "name" column to "some name"
buffer.deep_set("name", "some name".to_owned())?;

// set "age" column to 75
buffer.deep_set("age", 75u16)?;

// done with the buffer Ok(buffer) })?;

// open the new buffer, user_vec, we just created // uservec2 contains the serialized Vec let uservec2: Vec = userfactory.open(NP::buffer(uservec), |mut buffer| {

// read the name column let mut username = buffer.deepget::("name")?; asserteq!(username, Some(Box::new(String::from("some name"))));

// password value will be None since we haven't set it. let mut password = buffer.deepget::("pass")?; asserteq!(password, None);

// read age value
let mut age = buffer.deepget::("age")?; asserteq!(age, Some(Box::new(75)));

// done with the buffer Ok(buffer) })?;

// we can now save uservec2 to disk, // send it over the network, or whatever else is needed with the data ```

Guided Learning / Next Steps:

  1. Schemas - Learn how to build & work with schemas.
  2. Factories - Parsing schemas into something you can work with.
  3. Buffers - How to create, update & compact buffers.
  4. Pointers - How to add, remove and edit values in a buffer.

MIT License

Copyright (c) 2020 Scott Lott

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.