musli-wire
Fully upgrade stable format for Müsli suitable for network communication.
Wire encoding is fully upgrade stable:
- ✔ Can tolerate missing fields if they are annotated with
#[musli(default)]
. - ✔ Can skip over unknown fields.
This means that it's suitable as a wire format, since the data model can evolve independently among clients. Once some clients are upgraded they will start sending unknown fields which non-upgraded clients will be forced to skip over for the duration of the upgrade.
use ;
let version2 = to_vec?;
let version1: Version1 = decode?;
assert_eq!;
Configuring
To configure the behavior of the wire format you can use the Encoding
type:
use ;
use ;
use Encoding;
const OPTIONS: Options = new.with_integer.build;
const CONFIG: = new.with_options;
let mut out = Vec new;
let expected = Struct ;
CONFIG.encode?;
let actual = CONFIG.decode?;
assert_eq!;
Implementation details
Each field is prefix typed with a single byte tag that allows a receiver to figure out exactly how much should be skipped over.
Packed items are prefix-length encoded, and have a limited size. Its exact length is defined by MAX_INLINE_LEN and can be modified with Encoding::with_max_pack.