Struct kiwi_schema::Schema[][src]

pub struct Schema {
    pub defs: Vec<Def>,
    pub def_name_to_index: HashMap<String, usize>,
}

Holds the contents of a Kiwi schema.

Each schema consists of a list of definitions, each of which has a list of fields. It can either be constructed in memory or decoded from a file in the binary Kiwi schema format.

Example usage:

// This is the encoding of the Kiwi schema "message ABC { int[] xyz = 1; }"
let schema_bytes = [1, 65, 66, 67, 0, 2, 1, 120, 121, 122, 0, 5, 1, 1];
let schema = kiwi_schema::Schema::decode(&schema_bytes).unwrap();

let def = schema.def("ABC").unwrap();
assert_eq!(def.kind, kiwi_schema::DefKind::Message);

let field = def.field("xyz").unwrap();
assert_eq!(field.type_id, kiwi_schema::TYPE_INT);
assert_eq!(field.is_array, true);
assert_eq!(field.value, 1);

Fields

Maps the name member of each Def in the defs array to its index in that array. This is helpful when decoding and encoding a field to be able to quickly get to the field metadata.

Methods

impl Schema
[src]

Parses a Kiwi schema encoded in the binary format and returns the parsed schema if successful. A textual schema can be compiled into a binary schema using the command-line tools:

kiwic --schema example.kiwi --binary example.bkiwi

The opposite of decode. Turns this schema back into a binary file.

Returns the Def with the provided name if one exists.

Advances the current index of the provided ByteBuffer by the size of a field with the provided type information. The Kiwi format doesn't support seeking around to arbitrary points (it must be read from start to end) so this method is helpful when you need to to skip past unimportant fields.

Advances the current index of the provided ByteBuffer by the size of the provided field. This is used by skip but may also be useful by itself.

Trait Implementations

impl Debug for Schema
[src]

Formats the value using the given formatter. Read more

impl PartialEq for Schema
[src]

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

Auto Trait Implementations

impl Send for Schema

impl Sync for Schema