xmachines-codec-msgpack 1.0.0

MessagePack events and snapshots for xmachines-rs machines (an xmachines-codec codec)
Documentation

xmachines-codec-msgpack

MessagePack for xmachines-rs machines, an xmachines-codec codec named msgpack: events as MessagePack (application/msgpack, application/x-msgpack, application/vnd.msgpack), and snapshot records of format byte 2 followed by the snapshot as MessagePack, maps with string keys, so any MessagePack reader can decode them.

When to use it

Use it for snapshots that are smaller and faster to write than JSON (a small order actor's snapshot is 484 bytes and about 1.1 µs to write in the compact form) and still self-describing, so it needs no schema and reads back every snapshot JSON can hold: in the Kafka service, "codec": "msgpack" with its msgpack feature. Register it in a host's Codecs wherever events or snapshots should be MessagePack.

Snapshots are written by a dedicated writer, byte-identical to rmp_serde's named encoding, because snapshots are written once per changed actor and rmp_serde's general writer cost several times the encoding; data of unknown length goes through rmp_serde. Records are read with rmp_serde.

Example

use serde_json::json;
use xmachines_codec::Codecs;

let mut codecs = Codecs::new();
codecs.register(xmachines_codec_msgpack::codec()).unwrap();
let msgpack = codecs.get("msgpack").unwrap();
let mut record = Vec::new();
msgpack.snapshots().unwrap().encode((&json!({ "root": "m" })).into(), &mut record).unwrap();
assert_eq!(record[0], xmachines_codec_msgpack::FORMAT);
assert_eq!(codecs.decode_snapshot(&record).unwrap(), json!({ "root": "m" }));

Pins

rmp-serde 1.3 for reading.

Related crates

License

MIT