#messagepack #extension #dynamic #focused #pure #msg-pack

msgpack_simple

Simplified, easy to use, pure Rust MessagePack implementation focused on handling dynamic data structures

3 stable releases

1.0.2 Aug 29, 2020
1.0.0 Jan 31, 2019

#617 in Data structures

Download history 8318/week @ 2023-12-01 7134/week @ 2023-12-08 11854/week @ 2023-12-15 4319/week @ 2023-12-22 3267/week @ 2023-12-29 4460/week @ 2024-01-05 2563/week @ 2024-01-12 8627/week @ 2024-01-19 3462/week @ 2024-01-26 5465/week @ 2024-02-02 9763/week @ 2024-02-09 1902/week @ 2024-02-16 6903/week @ 2024-02-23 3561/week @ 2024-03-01 5929/week @ 2024-03-08 7716/week @ 2024-03-15

24,644 downloads per month
Used in gibberish

MIT license

55KB
778 lines

Simplified, easy to use, pure Rust MessagePack implementation focused on handling dynamic data structures.

Documentation

Example usage:

use msgpack_simple::{MsgPack, MapElement, Extension};

let message = MsgPack::Map(vec![
    MapElement {
        key: MsgPack::String(String::from("hello")),
        value: MsgPack::Int(42)
    },
    MapElement {
        key: MsgPack::String(String::from("world")),
        value: MsgPack::Array(vec![
            MsgPack::Boolean(true),
            MsgPack::Nil,
            MsgPack::Binary(vec![0x42, 0xff]),
            MsgPack::Extension(Extension {
                type_id: 2,
                value: vec![0x32, 0x4a, 0x67, 0x11]
            })
        ])
    }
]);

let encoded = message.encode(); // encoded is a Vec<u8>
let decoded = MsgPack::parse(&encoded).unwrap();

println!("{}", decoded);
assert_eq!(message, decoded);
assert!(message.is_map());

let mut map = message.as_map().unwrap(); // map is a Vec<MapElement>
let second_element = map.remove(1);

assert!(second_element.key.is_string());
assert_eq!(second_element.key.as_string().unwrap(), "world".to_string());

assert!(second_element.value.is_array());

let mut array = second_element.value.as_array().unwrap(); // array is a Vec<MsgPack>
let nil = array.remove(1);

assert!(nil.is_nil());

This library abstracts MessagePack data into a single MsgPack enum which can correspond to any encodable data type and handle nested data structures dynamically. It's not as performant as static solutions, for that, mneumann's rust-msgpack and 3Hren's RMP crates are recommended, but it is able to parse messages without full prior knowledge of their structure.

For more details, check out the documentation.

Contributing, license, and other stuff

As always, pull requests, bug reports, suggestions, and other kinds of improvements are welcome. Just be respectful towards each other, and maybe run or create tests as appropriate.

msgpack_simple is available under the MIT license.

Dependencies

~145KB