musli-descriptive

github crates.io docs.rs build status

A fully self-descriptive format for [Müsli].

Descriptive encoding is fully upgrade stable:

Furthermore, it can be fully converted back and from to the [Value] type.

This means that it's suitable as a wire and general interchange 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.

```rust use musli::{Encode, Decode};

[derive(Debug, PartialEq, Encode, Decode)]

struct Version1 { name: String, }

[derive(Debug, PartialEq, Encode, Decode)]

struct Version2 { name: String, #[musli(default)] age: Option, }

let version2 = muslidescriptive::tobuffer(&Version2 { name: String::from("Aristotle"), age: Some(62), })?;

let version1: Version1 = muslidescriptive::decode(version2.asslice())?;

assert_eq!(version1, Version1 { name: String::from("Aristotle"), }); ```

Configuring

To configure the behavior of the wire format you can use the [Encoding] type:

```rust use musli_descriptive::Encoding; use musli::{Encode, Decode}; use musli::mode::DefaultMode;

const CONFIG: Encoding = Encoding::new() .withmaxpack::<128>();

[derive(Debug, PartialEq, Encode, Decode)]

struct Struct<'a> { name: &'a str, age: u32, }

let mut out = Vec::new();

let expected = Struct { name: "Aristotle", age: 61, };

CONFIG.encode(&mut out, &expected)?; let actual = CONFIG.decode(&out[..])?;

assert_eq!(expected, actual); ```

Implementation details

Each field is prefix typed with a single byte tag that describes exactly the type which is contained in the field.

License: MIT/Apache-2.0