Expand description
A byte-exact GVariant codec for the ostree on-disk format.
A caller writes values as GVariant bytes in normal form and reads them back. The checksum of each ostree metadata object is the hash of these bytes, so each metadata checksum of ostrya depends on this crate. The typed codec reads fields in place with no allocation. The crate has no ostree knowledge.
§Entry points
Type::parsereads a type signature.to_byteswrites aValueas normal-form bytes.from_bytesreads normal-form bytes as aValue.GvEncodewrites a Rust type as normal-form bytes.GvDecodereads a Rust type in place from normal-form bytes.to_textwrites the GVariant text form of a value.from_textreads the GVariant text form.DictBuilderbuilds ana{sv}dict.
§Examples
use ostrya_gvariant::{Type, Value, from_bytes, to_bytes};
let ty = Type::parse("(su)")?;
let value = Value::Tuple(vec![Value::from("ostree"), Value::from(7u32)]);
let bytes = to_bytes(&ty, &value)?;
// The string, one padding byte, the `u`, and the framing offset 7.
assert_eq!(bytes, b"ostree\0\0\x07\0\0\0\x07");
assert_eq!(from_bytes(&ty, &bytes)?, value);Structs§
- Array
Iter - A lazy iterator over the elements of a serialized array.
- Dict
Builder - A builder for an
a{sv}dict value. - Element
Type - A type in a container type: the element of a maybe or of an array, or the key or the value of a dict entry.
- Member
Types - The member types of a tuple type, in order.
- Slice
- An array to encode from a Rust slice of encodable elements.
- Span
- A half-open byte range of the input text that a
TextErrornames. - Text
Error - The error for a GVariant text form that
from_textrefuses. - Variant
- A decoded variant that holds the type and the value of its child.
- Variant
Bytes - A variant read in place, as borrowed child bytes and signature.
Enums§
Traits§
- GvDecode
- A type that reads itself from normal-form GVariant bytes.
- GvEncode
- A type that writes itself as normal-form GVariant bytes.
- GvType
- The type-level facts of a type that encodes as GVariant.
Functions§
- choose_
offset_ size - Returns the size in bytes of each framing offset of a container.
- encode_
to_ vec - Encodes a top-level value into a new byte vector.
- from_
bytes - Deserializes normal-form GVariant bytes of type
tyinto aValue. - from_
text - Reads one GVariant text form and returns the type it states and the value.
- offset_
size_ for - Returns the framing-offset size for a container of
lenserialized bytes. - to_
bytes - Serializes
valueas typetyin GVariant normal form. - to_text
- Renders
valueof typetyin the GVariant text form. - to_
text_ unannotated - Renders
valueof typetyin the GVariant text form with no annotations. - tuple_
field_ from_ bytes - Deserializes one member of a serialized tuple into a
Value. - validate
- Checks that
datais normal-form GVariant bytes of typety. - write_
array - Appends
narray elements with normal-form framing toout. - write_
offset - Appends one framing offset of width
z.
Type Aliases§
- Result
- The result type of the codec.