SkillAgentSearch skills...

NoProto

Flexible, Fast & Compact Serialization with RPC

Install / Use

/learn @only-cliches/NoProto

README

NoProto: Flexible, Fast & Compact Serialization with RPC

<img src="https://github.com/only-cliches/NoProto/raw/master/logo_small.png"/>

Github | Crates.io | Documentation

MIT license crates.io docs.rs GitHub stars

Features

Lightweight<br/>

  • Zero dependencies
  • no_std support, WASM ready
  • Most compact non compiling storage format

Stable<br/>

  • Safely accept untrusted buffers
  • Passes Miri compiler safety checks
  • Panic and unwrap free

Easy<br/>

  • Extensive Documentation & Testing
  • Full interop with JSON, Import and Export JSON values
  • Thoroughly documented & simple data storage format

Fast<br/>

  • Zero copy deserialization
  • Most updates are append only
  • Deserialization is incrimental

Powerful<br/>

  • Native byte-wise sorting
  • Supports recursive data types
  • Supports most common native data types
  • Supports collections (list, map, struct & tuple)
  • Supports arbitrary nesting of collection types
  • Schemas support default values and non destructive updates
  • Transport agnostic RPC Framework.

Why ANOTHER Serialization Format?

  1. NoProto combines the performance of compiled formats with the flexibilty of dynamic formats:

Compiled formats like Flatbuffers, CapN Proto and bincode have amazing performance and extremely compact buffers, but you MUST compile the data types into your application. This means if the schema of the data changes the application must be recompiled to accomodate the new schema.

Dynamic formats like JSON, MessagePack and BSON give flexibilty to store any data with any schema at runtime but the buffers are fat and performance is somewhere between horrible and hopefully acceptable.

NoProto takes the performance advantages of compiled formats and implements them in a flexible format.

  1. NoProto is a key-value database focused format:

Byte Wise Sorting Ever try to store a signed integer as a sortable key in a database? NoProto can do that. Almost every data type is stored in the buffer as byte-wise sortable, meaning buffers can be compared at the byte level for sorting without deserializing.

Primary Key Management Compound sortable keys are extremely easy to generate, maintain and update with NoProto. You don't need a custom sort function in your key-value store, you just need this library.

UUID & ULID Support NoProto is one of the few formats that come with first class suport for these popular primary key data types. It can easily encode, decode and generate these data types.

Fastest Updates NoProto is the only format that supports all mutations without deserializng. It can do the common database read -> update -> write operation between 50x - 300x faster than other dynamic formats. Benchamrks

Comparison With Other Formats

<br/> <details> <summary><b>Compared to Apache Avro</b></summary> - Far more space efficient<br/> - Significantly faster serialization & deserialization<br/> - All values are optional (no void or null type)<br/> - Supports more native types (like unsigned ints)<br/> - Updates without deserializng/serializing<br/> - Works with `no_std`.<br/> - Safely handle untrusted data.<br/> </details> <br/> <details> <summary><b>Compared to Protocol Buffers</b></summary> - Comparable serialization & deserialization performance<br/> - Updating buffers is an order of magnitude faster<br/> - Schemas are dynamic at runtime, no compilation step<br/> - All values are optional<br/> - Supports more types and better nested type support<br/> - Byte-wise sorting is first class operation<br/> - Updates without deserializng/serializing<br/> - Safely handle untrusted data.<br/> - All values are optional and can be inserted in any order.<br/> </details> <br/> <details> <summary><b>Compared to JSON / BSON</b></summary> - Far more space efficient<br/> - Significantly faster serialization & deserialization<br/> - Deserializtion is zero copy<br/> - Has schemas / type safe<br/> - Supports byte-wise sorting<br/> - Supports raw bytes & other native types<br/> - Updates without deserializng/serializing<br/> - Works with `no_std`.<br/> - Safely handle untrusted data.<br/> </details> <br/> <details> <summary><b>Compared to Flatbuffers / Bincode</b></summary> - Data types can change or be created at runtime<br/> - Updating buffers is an order of magnitude faster<br/> - Supports byte-wise sorting<br/> - Updates without deserializng/serializing<br/> - Works with `no_std`.<br/> - Safely handle untrusted data.<br/> - All values are optional and can be inserted in any order.<br/> </details> <br/><br/>

| Format | Zero-Copy | Size Limit | Mutable | Schemas | Byte-wise Sorting | |------------------|-----------|------------|---------|----------|-------------------| | Runtime Libs | | | | | | | NoProto | ✓ | ~4GB | ✓ | ✓ | ✓ | | Apache Avro | ✗ | 2^63 Bytes | ✗ | ✓ | ✓ | | JSON | ✗ | Unlimited | ✓ | ✗ | ✗ | | BSON | ✗ | ~16MB | ✓ | ✗ | ✗ | | MessagePack | ✗ | Unlimited | ✓ | ✗ | ✗ | | Compiled Libs| | | | | | | FlatBuffers | ✓ | ~2GB | ✗ | ✓ | ✗ | | Bincode | ✓ | ? | ✓ | ✓ | ✗ | | Protocol Buffers | ✗ | ~2GB | ✗ | ✓ | ✗ | | Cap'N Proto | ✓ | 2^64 Bytes | ✗ | ✓ | ✗ | | Veriform | ✗ | ? | ✗ | ✗ | ✗ |

Quick Example

use no_proto::error::NP_Error;
use no_proto::NP_Factory;

// An ES6 like IDL 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 user_factory = NP_Factory::new(r#"
    struct({ fields: {
        name: string(),
        age: u16({ default: 0 }),
        tags: list({ of: string() })
    }})
"#)?;


// create a new empty buffer
let mut user_buffer = user_factory.new_buffer(None); // optional capacity

// set the "name" field
user_buffer.set(&["name"], "Billy Joel")?;

// read the "name" field
let name = user_buffer.get::<&str>(&["name"])?;
assert_eq!(name, Some("Billy Joel"));

// set a nested value, the first tag in the tag list
user_buffer.set(&["tags", "0"], "first tag")?;

// read the first tag from the tag list
let tag = user_buffer.get::<&str>(&["tags", "0"])?;
assert_eq!(tag, Some("first tag"));

// close buffer and get internal bytes
let user_bytes: Vec<u8> = user_buffer.finish().bytes();

// open the buffer again
let user_buffer = user_factory.open_buffer(user_bytes);

// read the "name" field again
let name = user_buffer.get::<&str>(&["name"])?;
assert_eq!(name, Some("Billy Joel"));

// get the age field
let age = user_buffer.get::<u16>(&["age"])?;
// returns default value from schema
assert_eq!(age, Some(0u16));

// close again
let user_bytes: Vec<u8> = user_buffer.finish().bytes();


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


# Ok::<(), NP_Error>(()) 

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/data.
  4. RPC Framework - How to use the RPC Framework APIs.
  5. Data & Schema Format - Learn how data is saved into the buffer and schemas.

Benchmarks

While it's difficult to properly benchmark libraries like these in a fair way, I've made an attempt in the graph below. These benchmarks are available in the bench folder and you can easily run them yourself with cargo run --release.

The format and data used in the benchmarks were taken from the flatbuffers benchmarks github repo. You should always benchmark/test your own use case for each library before making any choices on what to use.

Legend: Ops / Millisecond, higher is better

| Format / Lib | Encode | Decode All | Decode 1 | Update 1 | Size (bytes) | Size (Zlib) | |------------------------------------------------------------|---------|------------|----------|----------|--------------|-------------| | Runtime Libs | | | | | | | | NoProto | | | | | | | | no_proto | 1393 | 1883 | 55556 | 9524 | 308 | 198 | | Apache Avro |

Related Skills

View on GitHub
GitHub Stars380
CategoryData
Updated17h ago
Forks13

Languages

Rust

Security Score

100/100

Audited on Mar 25, 2026

No findings