messagepack-async

Crates.iomessagepack-async
lib.rsmessagepack-async
version0.2.3
created_at2024-12-16 05:38:12.125175+00
updated_at2024-12-23 08:55:22.734367+00
descriptionA simple functional library for read/writing messagepack with tokio.
homepage
repository
max_upload_size
id1484643
size57,714
Madeline Baggins (MadelineBaggins)

documentation

README

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.

[dependencies]
# Stdlib
messagepack-async = { version = "0.2.3", features = [ "sync" ] }
# Tokio
messagepack-async = { version = "0.2.3", features = [ "tokio" ] }

The Traits

This crate provides four traits; sync::ReadFrom, sync::WriteTo, tokio::ReadFrom, and tokio::WriteTo. These provide methods to read and write Values 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 messagepack_async::{Value, Int, sync::{ReadFrom, WriteTo}};
let mut data = vec![];
let value = Value::Int(Int::U64(0));
value.write_to(&mut data).unwrap();
let mut cursor = data.as_slice();
let read_value = Value::read_from(&mut cursor).unwrap();
assert_eq!(value, read_value);

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.

Commit count: 0

cargo fmt