{"id":14155565,"url":"https://github.com/only-cliches/NoProto","last_synced_at":"2025-08-06T01:31:56.937Z","repository":{"id":37179878,"uuid":"232455894","full_name":"only-cliches/NoProto","owner":"only-cliches","description":"Flexible, Fast \u0026 Compact Serialization with RPC","archived":false,"fork":false,"pushed_at":"2023-05-31T20:51:15.000Z","size":43972,"stargazers_count":374,"open_issues_count":9,"forks_count":14,"subscribers_count":10,"default_branch":"master","last_synced_at":"2024-12-01T18:11:36.237Z","etag":null,"topics":["apache-avro","avro","bson","data-buffers","databases","deserialization","flatbuffers","flexbuffers","json","messagepack","protocol-buffers","rpc","schemas","serialization","zero-copy"],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/only-cliches.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2020-01-08T02:01:14.000Z","updated_at":"2024-10-04T14:01:51.000Z","dependencies_parsed_at":"2024-01-16T22:32:10.897Z","dependency_job_id":null,"html_url":"https://github.com/only-cliches/NoProto","commit_stats":{"total_commits":217,"total_committers":9,"mean_commits":24.11111111111111,"dds":"0.47926267281105994","last_synced_commit":"827ebb9644806740bd481fb3930beeccf803224e"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/only-cliches%2FNoProto","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/only-cliches%2FNoProto/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/only-cliches%2FNoProto/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/only-cliches%2FNoProto/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/only-cliches","download_url":"https://codeload.github.com/only-cliches/NoProto/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":228821407,"owners_count":17977167,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["apache-avro","avro","bson","data-buffers","databases","deserialization","flatbuffers","flexbuffers","json","messagepack","protocol-buffers","rpc","schemas","serialization","zero-copy"],"created_at":"2024-08-17T08:03:56.432Z","updated_at":"2024-12-09T02:31:28.911Z","avatar_url":"https://github.com/only-cliches.png","language":"Rust","funding_links":[],"categories":["json"],"sub_categories":[],"readme":"## NoProto: Flexible, Fast \u0026 Compact Serialization with RPC\n\n\u003cimg src=\"https://github.com/only-cliches/NoProto/raw/master/logo_small.png\"/\u003e\n\n[Github](https://github.com/only-cliches/NoProto) | [Crates.io](https://crates.io/crates/no_proto) | [Documentation](https://docs.rs/no_proto)\n\n[![MIT license](https://img.shields.io/badge/License-MIT-blue.svg)](https://lbesson.mit-license.org/)\n[![crates.io](https://img.shields.io/crates/v/no_proto.svg)](https://crates.io/crates/no_proto)\n[![docs.rs](https://docs.rs/no_proto/badge.svg)](https://docs.rs/no_proto/latest/no_proto/)\n[![GitHub stars](https://img.shields.io/github/stars/only-cliches/NoProto.svg?style=social\u0026label=Star\u0026maxAge=2592000)](https://GitHub.com/only-cliches/NoProto/stargazers/)\n### Features  \n\n**Lightweight**\u003cbr/\u003e\n- Zero dependencies\n- `no_std` support, WASM ready\n- Most compact non compiling storage format\n\n**Stable**\u003cbr/\u003e\n- Safely accept untrusted buffers\n- Passes Miri compiler safety checks\n- Panic and unwrap free\n\n**Easy**\u003cbr/\u003e\n- Extensive Documentation \u0026 Testing\n- Full interop with JSON, Import and Export JSON values\n- [Thoroughly documented](https://docs.rs/no_proto/latest/no_proto/format/index.html) \u0026 simple data storage format\n\n**Fast**\u003cbr/\u003e\n- Zero copy deserialization\n- Most updates are append only\n- Deserialization is incrimental\n\n**Powerful**\u003cbr/\u003e\n- Native byte-wise sorting\n- Supports recursive data types\n- Supports most common native data types\n- Supports collections (list, map, struct \u0026 tuple)\n- Supports arbitrary nesting of collection types\n- Schemas support default values and non destructive updates\n- Transport agnostic [RPC Framework](https://docs.rs/no_proto/latest/no_proto/rpc/index.html).\n\n\n### Why ANOTHER Serialization Format?\n1. NoProto combines the **performance** of compiled formats with the **flexibilty** of dynamic formats:\n\n**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.\n\n**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.\n\nNoProto takes the performance advantages of compiled formats and implements them in a flexible format.\n\n2. NoProto is a **key-value database focused format**:\n\n**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*.\n\n**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.\n\n**UUID \u0026 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.\n\n**Fastest Updates** NoProto is the only format that supports *all mutations* without deserializng.  It can do the common database read -\u003e update -\u003e write operation between 50x - 300x faster than other dynamic formats. [Benchamrks](#benchmarks)\n\n\n### Comparison With Other Formats\n\n\u003cbr/\u003e\n\u003cdetails\u003e\n\u003csummary\u003e\u003cb\u003eCompared to Apache Avro\u003c/b\u003e\u003c/summary\u003e\n- Far more space efficient\u003cbr/\u003e\n- Significantly faster serialization \u0026 deserialization\u003cbr/\u003e\n- All values are optional (no void or null type)\u003cbr/\u003e\n- Supports more native types (like unsigned ints)\u003cbr/\u003e\n- Updates without deserializng/serializing\u003cbr/\u003e\n- Works with `no_std`.\u003cbr/\u003e\n- Safely handle untrusted data.\u003cbr/\u003e\n\u003c/details\u003e\n\u003cbr/\u003e\n\u003cdetails\u003e\n\u003csummary\u003e\u003cb\u003eCompared to Protocol Buffers\u003c/b\u003e\u003c/summary\u003e\n- Comparable serialization \u0026 deserialization performance\u003cbr/\u003e\n- Updating buffers is an order of magnitude faster\u003cbr/\u003e\n- Schemas are dynamic at runtime, no compilation step\u003cbr/\u003e\n- All values are optional\u003cbr/\u003e\n- Supports more types and better nested type support\u003cbr/\u003e\n- Byte-wise sorting is first class operation\u003cbr/\u003e\n- Updates without deserializng/serializing\u003cbr/\u003e\n- Safely handle untrusted data.\u003cbr/\u003e\n- All values are optional and can be inserted in any order.\u003cbr/\u003e\n\u003c/details\u003e\n\u003cbr/\u003e\n\u003cdetails\u003e\n\u003csummary\u003e\u003cb\u003eCompared to JSON / BSON\u003c/b\u003e\u003c/summary\u003e\n- Far more space efficient\u003cbr/\u003e\n- Significantly faster serialization \u0026 deserialization\u003cbr/\u003e\n- Deserializtion is zero copy\u003cbr/\u003e\n- Has schemas / type safe\u003cbr/\u003e\n- Supports byte-wise sorting\u003cbr/\u003e\n- Supports raw bytes \u0026 other native types\u003cbr/\u003e\n- Updates without deserializng/serializing\u003cbr/\u003e\n- Works with `no_std`.\u003cbr/\u003e\n- Safely handle untrusted data.\u003cbr/\u003e\n\u003c/details\u003e\n\u003cbr/\u003e\n\u003cdetails\u003e\n\u003csummary\u003e\u003cb\u003eCompared to Flatbuffers / Bincode\u003c/b\u003e\u003c/summary\u003e\n- Data types can change or be created at runtime\u003cbr/\u003e\n- Updating buffers is an order of magnitude faster\u003cbr/\u003e\n- Supports byte-wise sorting\u003cbr/\u003e\n- Updates without deserializng/serializing\u003cbr/\u003e\n- Works with `no_std`.\u003cbr/\u003e\n- Safely handle untrusted data.\u003cbr/\u003e\n- All values are optional and can be inserted in any order.\u003cbr/\u003e\n\u003c/details\u003e\n\u003cbr/\u003e\u003cbr/\u003e\n\n| Format           | Zero-Copy | Size Limit | Mutable | Schemas  | Byte-wise Sorting |\n|------------------|-----------|------------|---------|----------|-------------------|\n| **Runtime Libs** |           |            |         |          |                   | \n| *NoProto*        | ✓         | ~4GB       | ✓       | ✓        | ✓                 |\n| Apache Avro      | ✗         | 2^63 Bytes | ✗       | ✓        | ✓                 |\n| JSON             | ✗         | Unlimited  | ✓       | ✗        | ✗                 |\n| BSON             | ✗         | ~16MB      | ✓       | ✗        | ✗                 |\n| MessagePack      | ✗         | Unlimited  | ✓       | ✗        | ✗                 |\n| **Compiled Libs**|           |            |         |          |                   | \n| FlatBuffers      | ✓         | ~2GB       | ✗       | ✓        | ✗                 |\n| Bincode          | ✓         | ?          | ✓       | ✓        | ✗                 |\n| Protocol Buffers | ✗         | ~2GB       | ✗       | ✓        | ✗                 |\n| Cap'N Proto      | ✓         | 2^64 Bytes | ✗       | ✓        | ✗                 |\n| Veriform         | ✗         | ?          | ✗       | ✗        | ✗                 |\n\n\n# Quick Example\n```rust\nuse no_proto::error::NP_Error;\nuse no_proto::NP_Factory;\n\n// An ES6 like IDL is used to describe schema for the factory\n// Each factory represents a single schema\n// One factory can be used to serialize/deserialize any number of buffers\nlet user_factory = NP_Factory::new(r#\"\n    struct({ fields: {\n        name: string(),\n        age: u16({ default: 0 }),\n        tags: list({ of: string() })\n    }})\n\"#)?;\n\n\n// create a new empty buffer\nlet mut user_buffer = user_factory.new_buffer(None); // optional capacity\n\n// set the \"name\" field\nuser_buffer.set(\u0026[\"name\"], \"Billy Joel\")?;\n\n// read the \"name\" field\nlet name = user_buffer.get::\u003c\u0026str\u003e(\u0026[\"name\"])?;\nassert_eq!(name, Some(\"Billy Joel\"));\n\n// set a nested value, the first tag in the tag list\nuser_buffer.set(\u0026[\"tags\", \"0\"], \"first tag\")?;\n\n// read the first tag from the tag list\nlet tag = user_buffer.get::\u003c\u0026str\u003e(\u0026[\"tags\", \"0\"])?;\nassert_eq!(tag, Some(\"first tag\"));\n\n// close buffer and get internal bytes\nlet user_bytes: Vec\u003cu8\u003e = user_buffer.finish().bytes();\n\n// open the buffer again\nlet user_buffer = user_factory.open_buffer(user_bytes);\n\n// read the \"name\" field again\nlet name = user_buffer.get::\u003c\u0026str\u003e(\u0026[\"name\"])?;\nassert_eq!(name, Some(\"Billy Joel\"));\n\n// get the age field\nlet age = user_buffer.get::\u003cu16\u003e(\u0026[\"age\"])?;\n// returns default value from schema\nassert_eq!(age, Some(0u16));\n\n// close again\nlet user_bytes: Vec\u003cu8\u003e = user_buffer.finish().bytes();\n\n\n// we can now save user_bytes to disk, \n// send it over the network, or whatever else is needed with the data\n\n\n# Ok::\u003c(), NP_Error\u003e(()) \n```\n\n## Guided Learning / Next Steps:\n1. [`Schemas`](https://docs.rs/no_proto/latest/no_proto/schema/index.html) - Learn how to build \u0026 work with schemas.\n2. [`Factories`](https://docs.rs/no_proto/latest/no_proto/struct.NP_Factory.html) - Parsing schemas into something you can work with.\n3. [`Buffers`](https://docs.rs/no_proto/latest/no_proto/buffer/struct.NP_Buffer.html) - How to create, update \u0026 compact buffers/data.\n4. [`RPC Framework`](https://docs.rs/no_proto/latest/no_proto/rpc/index.html) - How to use the RPC Framework APIs.\n5. [`Data \u0026 Schema Format`](https://docs.rs/no_proto/latest/no_proto/format/index.html) - Learn how data is saved into the buffer and schemas.\n\n## Benchmarks\nWhile 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`. \n\nThe 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.\n\n**Legend**: Ops / Millisecond, higher is better\n\n| Format / Lib                                               | Encode  | Decode All | Decode 1 | Update 1 | Size (bytes) | Size (Zlib) |\n|------------------------------------------------------------|---------|------------|----------|----------|--------------|-------------|\n| **Runtime Libs**                                           |         |            |          |          |              |             |\n| *NoProto*                                                  |         |            |          |          |              |             |\n|        [no_proto](https://crates.io/crates/no_proto)       |    1393 |       1883 |    55556 |     9524 |          308 |         198 |\n| Apache Avro                                                |         |            |          |          |              |             |\n|         [avro-rs](https://crates.io/crates/avro-rs)        |     156 |         57 |       56 |       40 |          702 |         337 |\n| FlexBuffers                                                |         |            |          |          |              |             |\n|     [flexbuffers](https://crates.io/crates/flexbuffers)    |     444 |        962 |    24390 |      294 |          490 |         309 |\n| JSON                                                       |         |            |          |          |              |             |\n|            [json](https://crates.io/crates/json)           |     609 |        481 |      607 |      439 |          439 |         184 |\n|      [serde_json](https://crates.io/crates/serde_json)     |     938 |        646 |      644 |      403 |          446 |         198 |\n| BSON                                                       |         |            |          |          |              |             |\n|            [bson](https://crates.io/crates/bson)           |     129 |        116 |      123 |       90 |          414 |         216 |\n|         [rawbson](https://crates.io/crates/rawbson)        |     130 |       1117 |    17857 |       89 |          414 |         216 |\n| MessagePack                                                |         |            |          |          |              |             |\n|             [rmp](https://crates.io/crates/rmp)            |     661 |        623 |      832 |      202 |          311 |         193 |\n|  [messagepack-rs](https://crates.io/crates/messagepack-rs) |     152 |        266 |      284 |      138 |          296 |         187 |\n| **Compiled Libs**                                          |         |            |          |          |              |             |\n| Flatbuffers                                                |         |            |          |          |              |             |\n|     [flatbuffers](https://crates.io/crates/flatbuffers)    |    3165 |      16393 |   250000 |     2532 |          264 |         181 |\n| Bincode                                                    |         |            |          |          |              |             |\n|         [bincode](https://crates.io/crates/bincode)        |    6757 |       9259 |    10000 |     4115 |          163 |         129 |\n| Postcard                                                   |         |            |          |          |              |             |\n|        [postcard](https://crates.io/crates/postcard)       |    3067 |       7519 |     7937 |     2469 |          128 |         119 |\n| Protocol Buffers                                           |         |            |          |          |              |             |\n|        [protobuf](https://crates.io/crates/protobuf)       |     953 |       1305 |     1312 |      529 |          154 |         141 |\n|           [prost](https://crates.io/crates/prost)          |    1464 |       2020 |     2232 |     1040 |          154 |         142 |\n| Abomonation                                                |         |            |          |          |              |             |\n|     [abomonation](https://crates.io/crates/abomonation)    |    2342 |     125000 |   500000 |     2183 |          261 |         160 |\n| Rkyv                                                       |         |            |          |          |              |             |\n|            [rkyv](https://crates.io/crates/rkyv)           |    1605 |      37037 |   200000 |     1531 |          180 |         154 |\n\n- **Encode**: Transfer a collection of fields of test data into a serialized `Vec\u003cu8\u003e`.\n- **Decode All**: Deserialize the test object from the `Vec\u003cu8\u003e` into all fields.\n- **Decode 1**: Deserialize the test object from the `Vec\u003cu8\u003e` into one field.\n- **Update 1**: Deserialize, update a single field, then serialize back into `Vec\u003cu8\u003e`.\n\n**Runtime VS Compiled Libs**: Some formats require data types to be compiled into the application, which increases performance but means data types *cannot change at runtime*.  If data types need to mutate during runtime or can't be known before the application is compiled (like with databases), you must use a format that doesn't compile data types into the application, like JSON or NoProto.\n\nComplete benchmark source code is available [here](https://github.com/only-cliches/NoProto/tree/master/bench).  Suggestions for improving the quality of these benchmarks is appreciated.\n\n## NoProto Strengths\nIf your use case fits any of the points below, NoProto might be a good choice for your application.\n\n1. Flexible At Runtime\u003cbr/\u003e\nIf you need to work with data types that will change or be created at runtime, you normally have to pick something like JSON since highly optimized formats like Flatbuffers and Bincode depend on compiling the data types into your application (making everything fixed at runtime). When it comes to formats that can change/implement data types at runtime, NoProto is fastest format we're aware of (if you know if one that might be faster, let us know!).\n\n2. Safely Accept Untrusted Data\u003c/br\u003e\nThe worse case failure mode for NoProto buffers is junk data.  While other formats can cause denial of service attacks or allow unsafe memory access, there is no such failure case with NoProto.  There is no way to construct a NoProto buffer that would cause any detrement in performance to the host application or lead to unsafe memory access.  Also, there is no panic causing code in the library, meaning it will never crash your application.\n\n3. Extremely Fast Updates\u003cbr/\u003e\nIf you have a workflow in your application that is read -\u003e modify -\u003e write with buffers, NoProto will usually outperform every other format, including Bincode and Flatbuffers. This is because NoProto never actually deserializes, it doesn't need to.  This includes complicated mutations like pushing a value onto a nested list or replacing entire structs.\n\n4. All Fields Optional, Insert/Update In Any Order\u003cbr/\u003e\nMany formats require that all values be present to close the buffer, further they may require data to be inserted in a specific order to accomodate the encoding/decoding scheme.  With NoProto, all fields are optional and any update/insert can happen in any order.  \n\n5. Incremental Deserializing\u003cbr/\u003e\nYou only pay for the fields you read, no more. There is no deserializing step in NoProto, opening a buffer performs no operations. Once you start asking for fields, the library will navigate the buffer using the format rules to get just what you asked for and nothing else. If you have a workflow in your application where you read a buffer and only grab a few fields inside it, NoProto will outperform most other libraries.\n\n6. Bytewise Sorting\u003cbr/\u003e\nAlmost all of NoProto's data types are designed to serialize into bytewise sortable values, *including signed integers*.  When used with Tuples, making database keys with compound sorting is extremly easy.  When you combine that with first class support for `UUID`s and `ULID`s NoProto makes an excellent tool for parsing and creating primary keys for databases like RocksDB, LevelDB and TiKV. \n\n7. `no_std` Support\u003cbr/\u003e\nIf you need a serialization format with low memory usage that works in `no_std` environments, NoProto is one of the few good choices.\n\n8. Stable\u003cbr/\u003e\nNoProto will never cause a panic in your application.  It has *zero* panics or unwraps, meaning there is no code path that could lead to a panic.  Fallback behavior is to provide a sane default path or bubble an error up to the caller.\n\n9. CPU Independent\u003cbr/\u003e\nAll numbers and pointers in NoProto buffers are always stored in big endian, so you can safely create buffers on any CPU architecture and know that they will work with any other CPU architecture.\n\n\n### When to use Flatbuffers / Bincode / CapN Proto\nIf you can safely compile all your data types into your application, all the buffers/data is trusted, and you don't intend to mutate buffers after they're created, Bincode/Flatbuffers/CapNProto is a better choice for you.\n\n### When to use JSON / BSON / MessagePack\nIf your data changes so often that schemas don't really make sense or the format you use must be self describing, JSON/BSON/MessagePack is a better choice.   Although I'd argue that if you *can* make schemas work you should.  Once you can use a format with schemas you save a ton of space in the resulting buffers and performance far better.\n\n## Limitations\n- Structs and Tuples cannot have more than 255 items.\n- Lists and Maps cannot have more than 2^16 (~64k) items.\n- You cannot nest more than 255 levels deep.\n- Struct field names cannot be longer than 255 UTF8 bytes.\n- Enum/Option types are limited to 255 options and each option cannot be more than 255 UTF8 Bytes.\n- Map keys cannot be larger than 255 UTF8 bytes.\n- Buffers cannot be larger than 2^32 bytes or ~4GB.\n\n## Unsafe\nThis library makes use of `unsafe` to get better performance.  Generally speaking, it's not possible to have a high performance serialization library without `unsafe`.  It is only used where performance improvements are significant and additional checks are performed so that the worst case for any `unsafe` block is it leads to junk data in a buffer.\n\n----------------------\n\nMIT License\n\nCopyright (c) 2021 Scott Lott\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE. ","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fonly-cliches%2FNoProto","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fonly-cliches%2FNoProto","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fonly-cliches%2FNoProto/lists"}