MessagePack-Async
messagepack-async
is a simple, functional library for reading and writing
MessagePack with std::io::{Read, Write}
and tokio::io::{AsyncRead, AsyncWrite}
.
No features are enabled by default so you will either need to enable at least one of
sync
or tokio
depending on what you're planning on reading/writing to.
[]
# Stdlib
= { = "0.2", = [ "sync" ] }
# Tokio
= { = "0.2", = [ "tokio" ] }
The Traits
This crate provides four traits; [sync::ReadFrom
], [sync::WriteTo
],
[tokio::ReadFrom
], and [tokio::WriteTo
]. These provide methods to read and
write [Value
]s to sources and sinks that implement the read/write traits from
the stdlib or tokio.
Note that write_to
will write exactly the value you supply. That means
if you write a Int::U64(0)
to a sink, it won't write the value as a U8 even
though it could be represented as such.
use ;
let mut data = vec!;
let value = Int;
value.write_to.unwrap;
let mut cursor = data.as_slice;
let read_value = read_from.unwrap;
assert_eq!;
The implementation of [std::cmp::PartialEq
] is derived so differentiates between
different variants of [Int
].
If you need to minimise the size in bytes of the values you write, create your
values with the [Value::int
], [Value::signed_int
], and
[Value::unsigned_int
] constructors for [Value
].