minimal_object_notation

Crates.iominimal_object_notation
lib.rsminimal_object_notation
version0.1.0
sourcesrc
created_at2020-09-25 08:29:32.145209
updated_at2020-09-25 08:29:32.145209
descriptionMinimal encoding.
homepage
repositoryhttps://github.com/36den/minimal_object_notation
max_upload_size
id292762
size26,119
(36den)

documentation

README

Minimal Object Notation

A Rust crate for reading and writing minimimal object notation.

Introduction

What is 'Minimal Object Notation'? It is a format that comes from simply attaching a name tag and a length tag to some information. For example: greeting|13~Hello, world!.

Example creating miniONs

    use minimal_object_notation::*;

    let mut minion = MiniON::new("greeting".to_string());

    minion.set_content("Hello, world!".to_string());

    let minion = minion.to_string();

Will result in a String containing greeting|13~Hello, world!.

Example parsing miniONs

    use minimal_object_notation::*;

    let data = b"greeting|13~Hello, world!container|23~first|3~ONEsecond|3~TWO";

    let mut incr: usize = 0;

    // Parse a single object that starts at the position `incr`...

    match MiniON::parse_one(data, &mut incr) {
        Ok(minion) => {
            assert_eq!("greeting",minion.name);

            match minion.content {
                Some(content) => {
                    assert_eq!("Hello, world!",content);
                },
                None => {
                    panic!("Expected content!");
                }
            }
        },
        Err(e) => {
            panic!("{}",e.to_string());
        }
    }

    // ... OR parse all (sucessive) miniON objects.

    match MiniON::parse_all(data) {
        Ok(minions) => {
            assert_eq!(minions.len(),2);

            assert_eq!("container",minions[1].name);
        },
        Err(e) => {
            panic!("{}",e.to_string());
        }
    }
Commit count: 11

cargo fmt