2 releases
0.1.1 | Sep 27, 2024 |
---|---|
0.1.0 | Jun 27, 2024 |
#10 in #message-pack
191 downloads per month
510KB
12K
SLoC
MessagePack support for Swim serialization.
Provides a MessagesPack backend for the Swim serialization system. This consists of two parts:
- A function
read_from_msg_pack
that will attempt to deserialize any type that implementsswimos_form::read::StructuralReadable
from a buffer containing MessagePack data. - The type
MsgPackInterpreter
that implementsswimos_form::write::StructuralWriter
allowing any type that implementsswimos_form::write::StructuralWritable
to be serialized as MessagePack.
Examples
use bytes::{BufMut, BytesMut};
use swimos_form::write::StructuralWritable;
use swimos_msgpack::{read_from_msg_pack, MsgPackInterpreter};
let mut buffer = BytesMut::with_capacity(128);
let data = vec!["first".to_owned(), "second".to_owned(), "third".to_owned()];
let mut writer = (&mut buffer).writer();
let interpreter = MsgPackInterpreter::new(&mut writer);
assert!(data.write_with(interpreter).is_ok());
let mut bytes = buffer.split().freeze();
let restored = read_from_msg_pack::<Vec<String>, _>(&mut bytes);
assert_eq!(restored, Ok(data));
Dependencies
~8–15MB
~179K SLoC