Crate graven

Crate graven 

Source
Expand description

Runtime for Graven, a zero-copy binary serialization format.

Messages are read in place: accessors read fields straight from the buffer, and strings and byte slices borrow from it. The wire format is specified in docs/spec/graven-format-v1.md (format v1, frozen) and pinned by the conformance vectors in testvectors/v1/.

Most code does not use this crate directly: the gravenc compiler turns a .graven schema into typed readers, verified views and writers built on top of it. This crate provides:

  • Builder and the writers (TableW, FixedW, list writers): build a message into a pooled buffer (BufPool, SimplePool);
  • TableRef and the list readers: checked, lazy reads, where every access validates what it touches and returns an Error instead of misbehaving;
  • VerifyCtx: the depth and budget limits of a full verify (spec §7), which generated code runs once before handing out a verified view;
  • envelope: the optional envelope for disk and network (magic, version, schema id, CRC32C), including iteration over concatenated envelopes;
  • validate: the results of the validation rules a schema declares (range, len, finite, known, check(name));
  • rt: support items called by generated code.

The crate is no_std (with alloc) when the default std feature is disabled.

use bytes::BytesMut;
use graven::envelope::{decode, encode, schema_id};

let id = schema_id("bank.Transaction");
let mut out = BytesMut::new();
encode(id, b"payload bytes", &mut out)?;
let env = decode(&out)?;
assert_eq!((env.schema_id, env.payload), (id, &b"payload bytes"[..]));

Re-exports§

pub use read::Bit;
pub use read::Frames;
pub use read::ScalarList;
pub use read::StrList;
pub use read::TableList;
pub use read::TableRef;
pub use read::frames;
pub use pool::SimplePool;
pub use pool::BufPool;
pub use write::Builder;
pub use write::FixedListW;
pub use write::FixedW;
pub use write::ScalarListW;
pub use write::StreamListW;
pub use write::TableListW;
pub use write::TableW;
pub use verify::VerifyCtx;
pub use validate::Invalid;
pub use validate::Rule;
pub use validate::ValidateError;

Modules§

envelope
The optional envelope that wraps a raw Graven message for disk or network.
pool
Buffer pools.
read
Zero-copy reading.
rt
Support for code generated by the Graven compiler (and the hand-written code in graven-schemas that freezes its pattern). Items marked #[doc(hidden)] are called only by generated code; the rest (ListR, VListR, VStrList, ListW, StreamW) appear in generated signatures.
validate
Results of the validation rules declared in a schema (range, len, finite, known, check(name)).
verify
Whole-message verification limits.
write
Forward-only writing into pooled BytesMut.

Structs§

Bytes
A cheaply cloneable and sliceable chunk of contiguous memory.

Enums§

Error
Every failure mode of reading or writing a Graven buffer.

Traits§

Le
Fixed-size little-endian value. read_le/write_le require a slice of exactly SIZE bytes.

Functions§

crc32c
CRC32C of data. Hardware-accelerated with std, software otherwise.