Github | Crates.io | Documentation
NoProto allows you to store, read & mutate structured data with near zero overhead. It's like JSON but faster, type safe and allows native types. It's like Cap'N Proto/Flatbuffers except buffers and schemas are dynamic at runtime instead of requiring compilation.
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 - Mutate (add/delete/update) existing/imported buffers
Compared to JSON - Has schemas / type safe - Faster serialization & deserialization - Supports raw bytes & other native types
Compared to BSON - Faster serialization & deserialization - Has schemas / type safe - Supports much larger documents (4GB vs 16MB) - Better collection support & more supported types
Compared to Serde - Objects & schemas are dynamic at runtime - Faster serialization & deserialization
```rust use noproto::error::NPError; use noproto::NPFactory; use noproto::collection::table::NPTable; use noproto::pointer::NPPtr;
// 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
// userbuffer contains a deserialized Vec
// open the buffer to read or update values
let root: NP_Ptr<NP_Table> = buffer.root()?; // <- type cast the root
// the root of our schema is a collection type (NPTable), // so we have to collapse the root pointer into the collection type. let mut table: NPTable = root.into()?.unwrap();
// Select a column and type cast it. Selected columns can be mutated or read from.
let mut user_name = table.select::
// set value of name column username.set("some name".toowned())?;
// select age column and set it's value
let mut age = table.select::
// open the new buffer, user_buffer
, we just created
// userbuffer2 contains the deserialized Vec
let root: NP_Ptr
// get the table root again let mut table = root.into()?.unwrap();
// read the name column
let mut username = table.select::
// password value will be None since we haven't set it.
let mut password = table.select::
// read age value
let mut age = table.select::
// done with the buffer Ok(()) })?;
// we can now save userbuffer2 to disk, // send it over the network, or whatever else is needed with the data ```
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.