This crate is a Rust library for using the Serde serialization framework with data in the VICI protocol format.
To make best use of this crate, let Serde's derive macros handle structs in your application.
toml
[dependencies]
serde = { version = "1.0", features = ["derive"] }
serde_vici = "0.1"
For example, serializing/deserializing the Encoding Example looks like the following:
```rust use serde::{Deserialize, Serialize};
struct RootSection { key1: String, section1: MainSection, }
struct MainSection {
sub_section: SubSection,
list1: Vec
struct SubSection { key2: String, }
fn main() -> Result<(), serdevici::Error> { // Define a struct as in the documentation for the VICI protocol. let data = RootSection { key1: "value1".tostring(), section1: MainSection { subsection: SubSection { key2: "value2".tostring(), }, list1: vec!["item1".tostring(), "item2".tostring()], }, };
// Serialize to a vector.
let msg = serde_vici::to_vec(&data)?;
assert_eq!(
msg,
vec![
// key1 = value1
3, 4, b'k', b'e', b'y', b'1', 0, 6, b'v', b'a', b'l', b'u', b'e', b'1',
// section1
1, 8, b's', b'e', b'c', b't', b'i', b'o', b'n', b'1',
// sub-section
1, 11, b's', b'u', b'b', b'-', b's', b'e', b'c', b't', b'i', b'o', b'n',
// key2 = value2
3, 4, b'k', b'e', b'y', b'2', 0, 6, b'v', b'a', b'l', b'u', b'e', b'2',
// sub-section end
2,
// list1
4, 5, b'l', b'i', b's', b't', b'1',
// item1
5, 0, 5, b'i', b't', b'e', b'm', b'1',
// item2
5, 0, 5, b'i', b't', b'e', b'm', b'2',
// list1 end
6,
// section1 end
2,
]
);
// Deserialize back to a Rust type.
let deserialized_data: RootSection = serde_vici::from_slice(&msg)?;
assert_eq!(data, deserialized_data);
Ok(())
} ```