Struct kiwi_schema::Schema [−][src]
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.
Methods
impl Schema
[src]
impl Schema
pub fn new(defs: Vec<Def>) -> Schema
[src]
pub fn new(defs: Vec<Def>) -> Schema
pub fn decode(bytes: &[u8]) -> Result<Schema, ()>
[src]
pub fn decode(bytes: &[u8]) -> Result<Schema, ()>
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]
pub fn encode(&self) -> Vec<u8>
The opposite of decode. Turns this schema back into a binary file.
pub fn def(&self, name: &str) -> Option<&Def>
[src]
pub fn def(&self, name: &str) -> Option<&Def>
Returns the Def with the provided name if one exists.
pub fn skip(&self, bb: &mut ByteBuffer, type_id: i32) -> Result<(), ()>
[src]
pub fn skip(&self, bb: &mut ByteBuffer, type_id: i32) -> Result<(), ()>
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_field(&self, bb: &mut ByteBuffer, field: &Field) -> Result<(), ()>
[src]
pub fn skip_field(&self, bb: &mut ByteBuffer, field: &Field) -> Result<(), ()>
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]
impl Debug for Schema
fn fmt(&self, f: &mut Formatter) -> Result
[src]
fn fmt(&self, f: &mut Formatter) -> Result
Formats the value using the given formatter. Read more
impl PartialEq for Schema
[src]
impl PartialEq for Schema