[][src]Struct kiwi_schema::Schema

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

defs: Vec<Def>def_name_to_index: HashMap<String, usize>

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.

Implementations

impl Schema[src]

pub fn new(defs: Vec<Def>) -> Schema[src]

pub fn decode(bytes: &[u8]) -> Result<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

pub fn encode(&self) -> Vec<u8>[src]

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

pub fn def(&self, name: &str) -> Option<&Def>[src]

Returns the Def with the provided name if one exists.

pub fn skip_with_options(
    &self,
    bb: &mut ByteBuffer,
    type_id: i32,
    options: &SchemaOptions
) -> Result<(), ()>
[src]

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.

pub fn skip(&self, bb: &mut ByteBuffer, type_id: i32) -> Result<(), ()>[src]

pub fn skip_field_with_options(
    &self,
    bb: &mut ByteBuffer,
    field: &Field,
    options: &SchemaOptions
) -> Result<(), ()>
[src]

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.

pub fn skip_field(&self, bb: &mut ByteBuffer, field: &Field) -> Result<(), ()>[src]

Trait Implementations

impl Debug for Schema[src]

impl PartialEq<Schema> for Schema[src]

impl StructuralPartialEq for Schema[src]

Auto Trait Implementations

impl RefUnwindSafe for Schema

impl Send for Schema

impl Sync for Schema

impl Unpin for Schema

impl UnwindSafe for Schema

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.