Skip to content

Rafferty97/talk-serde-dyn-schema

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

About

This is a small demo produced to support the talk "Dynamic schemas with serde" at Rust Sydney April 2024.

It demonstrates how to leverage serde and serde_json to handle the serialization and deserialization of JSON documents into a compact binary format (in this project called "flatbin", because naming things is hard).

The binary format is novel in two aspects:

  • It is not self-describing, and relies on a schema type (Ty) to encode and decode documents. This is for maximum compactness, e.g. object keys do not need to be encoded. This is not unlike other encoding schemes like messagepack or protobuf.
  • It is possible to separate out the bytes representing the discrete elements of an array of fields of an object without knowing their types. So, for example, it is possible to skip over the first three elements of an array and extract the fourth one without knowing what kinds of values that array holds.

The unit tests in src/tests.rs and benchmarks in benches/serde.rs show how to use the library code to encode and decode documents given a runtime schema.

The code in src/slow shows how to encode/decode documents using an intermediate serde_json::Value object to represent arbitrary JSON, and is a very simple but relatively slower method.

The code in src/fast shows how to go directly from JSON text to encoded bytes and back again without this intermediate value, by implementing serde traits such as Serialize, DeserializeSeed and Visitor.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages