ostrya_gvariant/lib.rs
1#![forbid(unsafe_code)]
2
3//! A byte-exact GVariant codec for the ostree on-disk format.
4//!
5//! A caller writes values as GVariant bytes in normal form and reads them
6//! back. The checksum of each ostree metadata object is the hash of these
7//! bytes, so each metadata checksum of ostrya depends on this crate. The
8//! typed codec reads fields in place with no allocation. The crate has no
9//! ostree knowledge.
10//!
11//! # Entry points
12//!
13//! - [`Type::parse`] reads a type signature.
14//! - [`to_bytes`] writes a [`Value`] as normal-form bytes.
15//! - [`from_bytes`] reads normal-form bytes as a [`Value`].
16//! - [`GvEncode`] writes a Rust type as normal-form bytes.
17//! - [`GvDecode`] reads a Rust type in place from normal-form bytes.
18//! - [`to_text`] writes the GVariant text form of a value.
19//! - [`from_text`] reads the GVariant text form.
20//! - [`DictBuilder`] builds an `a{sv}` dict.
21//!
22//! # Examples
23//!
24//! ```
25//! use ostrya_gvariant::{Type, Value, from_bytes, to_bytes};
26//!
27//! let ty = Type::parse("(su)")?;
28//! let value = Value::Tuple(vec![Value::from("ostree"), Value::from(7u32)]);
29//! let bytes = to_bytes(&ty, &value)?;
30//! // The string, one padding byte, the `u`, and the framing offset 7.
31//! assert_eq!(bytes, b"ostree\0\0\x07\0\0\0\x07");
32//! assert_eq!(from_bytes(&ty, &bytes)?, value);
33//! # Ok::<(), ostrya_gvariant::Error>(())
34//! ```
35
36mod codec;
37mod de;
38mod dict;
39mod error;
40mod print;
41mod ser;
42mod text;
43mod ty;
44mod value;
45
46pub use codec::{
47 ArrayIter, GvDecode, GvEncode, GvType, Slice, Variant, VariantBytes, encode_to_vec, write_array,
48};
49pub use de::{from_bytes, offset_size_for, tuple_field_from_bytes, validate};
50pub use dict::DictBuilder;
51pub use error::{Error, Result};
52pub use print::{to_text, to_text_unannotated};
53pub use ser::{choose_offset_size, to_bytes, write_offset};
54pub use text::{Span, TextError, from_text};
55pub use ty::{ElementType, MemberTypes, Type};
56pub use value::Value;