MessagePacker - a Rust of the msgpack protocol
The protocol specification can be found here.
This crate targets simplicity and performance. No dependencies are used, just the standard Rust library.
We have two main structures available:
- Message - Owned parsed values
- MessageRef - Message parsed by reference and bound to the lifetime of the readers source
Example
use *;
use ;
let mut cursor = new;
let key = String;
let value = Integer;
let entry = new;
let message = Map;
// Write the message to the cursor
message.pack.expect;
cursor.rewind.expect;
// Read the message from the cursor
let restored = unpack.expect;
let value = restored
.as_map
.expect
.first
.expect
.val
.as_integer
.expect
.as_i64
.expect;
assert_eq!;
Example (by ref)
use *;
use ;
let mut cursor = new;
let key = String;
let value = Integer;
let entry = new;
let message = Map;
// Write the message to the cursor
message.pack.expect;
cursor.rewind.expect;
// The consumer need to guarantee himself the cursor source will live long enough to satify the
// lifetime of the message reference.
//
// If this is guaranteed, then the function is safe.
let restored = unsafe ;
// The lifetime of `MessageRef` is not bound to the `Read` implementation because the source
// might outlive it - as in this example
let _buffer = cursor.into_inner;
// `MessageRef` behaves the same as `Message`, but the runtime cost is cheaper because it will
// avoid a couple of unnecessary copies
let value = restored
.as_map
.expect
.first
.expect
.val
.as_integer
.expect
.as_i64
.expect;
assert_eq!;