A fully self-descriptive format for [Müsli].
Descriptive encoding is fully upgrade stable:
#[musli(default)]
.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};
struct Version1 { name: String, }
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"), }); ```
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
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); ```
Each field is prefix typed with a single byte tag that describes exactly the type which is contained in the field.