Struct jomini::BinaryDeserializer [−][src]
pub struct BinaryDeserializer;
Expand description
A structure to deserialize binary data into Rust values.
By default, if a token is unable to be resolved then it will be ignored by the default.
Construct a custom instance through the builder
method to tweak this behavior.
The example below demonstrates multiple ways to deserialize data
use jomini::{BinaryDeserializer, BinaryTape}; use serde::Deserialize; use std::collections::HashMap; #[derive(Debug, Clone, Deserialize, PartialEq)] pub struct StructA { #[serde(flatten)] b: StructB, #[serde(flatten)] c: StructC, } #[derive(Debug, Clone, Deserialize, PartialEq)] pub struct StructB { field1: String, } #[derive(Debug, Clone, Deserialize, PartialEq)] pub struct StructC { field2: String, } let data = [ 0x82, 0x2d, 0x01, 0x00, 0x0f, 0x00, 0x03, 0x00, 0x45, 0x4e, 0x47, 0x83, 0x2d, 0x01, 0x00, 0x0f, 0x00, 0x03, 0x00, 0x45, 0x4e, 0x48, ]; let mut map = HashMap::new(); map.insert(0x2d82, String::from("field1")); map.insert(0x2d83, String::from("field2")); // the data can be parsed and deserialized in one step let a: StructA = BinaryDeserializer::eu4_builder().from_slice(&data[..], &map)?; assert_eq!(a, StructA { b: StructB { field1: "ENG".to_string() }, c: StructC { field2: "ENH".to_string() }, }); // or split into two steps, whatever is appropriate. let tape = BinaryTape::from_eu4(&data[..])?; let deserializer = BinaryDeserializer::eu4_builder(); let b: StructB = deserializer.from_tape(&tape, &map)?; let c: StructC = deserializer.from_tape(&tape, &map)?; assert_eq!(b, StructB { field1: "ENG".to_string() }); assert_eq!(c, StructC { field2: "ENH".to_string() });
Implementations
Create a builder to custom binary deserialization
Create a builder to custom binary deserialization
A customized builder for a certain flavor of binary data
pub fn from_eu4<'a, 'res: 'a, RES, T>(
data: &'a [u8],
resolver: &'res RES
) -> Result<T, Error> where
T: Deserialize<'a>,
RES: TokenResolver,
pub fn from_eu4<'a, 'res: 'a, RES, T>(
data: &'a [u8],
resolver: &'res RES
) -> Result<T, Error> where
T: Deserialize<'a>,
RES: TokenResolver,
Convenience method for parsing and deserializing binary data in a single step
pub fn from_ck3<'a, 'b, 'res: 'a, RES, T>(
data: &'a [u8],
resolver: &'res RES
) -> Result<T, Error> where
T: Deserialize<'a>,
RES: TokenResolver,
pub fn from_ck3<'a, 'b, 'res: 'a, RES, T>(
data: &'a [u8],
resolver: &'res RES
) -> Result<T, Error> where
T: Deserialize<'a>,
RES: TokenResolver,
Convenience method for parsing and deserializing binary data in a single step
Auto Trait Implementations
impl RefUnwindSafe for BinaryDeserializer
impl Send for BinaryDeserializer
impl Sync for BinaryDeserializer
impl Unpin for BinaryDeserializer
impl UnwindSafe for BinaryDeserializer