[−][src]Struct jomini::BinaryDeserializerBuilder
Build a tweaked binary deserializer
use jomini::{BinaryDeserializer, BinaryTape, FailedResolveStrategy}; use serde::Deserialize; use std::collections::HashMap; #[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")); let mut deserializer = BinaryDeserializer::builder(); deserializer.on_failed_resolve(FailedResolveStrategy::Error); let tape = BinaryTape::from_slice(&data[..])?; 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
impl BinaryDeserializerBuilder
[src]
pub fn new() -> Self
[src]
Create a new builder instance
pub fn on_failed_resolve(
&mut self,
strategy: FailedResolveStrategy
) -> &mut Self
[src]
&mut self,
strategy: FailedResolveStrategy
) -> &mut Self
Set the behavior when a unknown token is encountered
pub fn from_tape<'a, 'b, 'c, 'res: 'a, RES, T>(
&'b self,
tape: &'c BinaryTape<'a>,
resolver: &'res RES
) -> Result<T, Error> where
T: Deserialize<'a>,
RES: TokenResolver,
[src]
&'b self,
tape: &'c BinaryTape<'a>,
resolver: &'res RES
) -> Result<T, Error> where
T: Deserialize<'a>,
RES: TokenResolver,
Deserialize the given binary tape
pub fn from_slice<'a, 'b, 'res: 'a, RES, T>(
&'b self,
data: &'a [u8],
resolver: &'res RES
) -> Result<T, Error> where
T: Deserialize<'a>,
RES: TokenResolver,
[src]
&'b self,
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
Trait Implementations
impl Debug for BinaryDeserializerBuilder
[src]
impl Default for BinaryDeserializerBuilder
[src]
Auto Trait Implementations
impl RefUnwindSafe for BinaryDeserializerBuilder
impl Send for BinaryDeserializerBuilder
impl Sync for BinaryDeserializerBuilder
impl Unpin for BinaryDeserializerBuilder
impl UnwindSafe for BinaryDeserializerBuilder
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,