JceParser

Struct JceParser 

Source
pub struct JceParser<'de> { /* private fields */ }
Expand description

Manually construct jce format

§Example

use serde_jce::{JceParser, JceType};

let mut parser = JceParser::from_bytes(&[0x00, 0x12, 0x11, 0x12, 0x34]);
assert_eq!(parser.pick_head(), Ok((0, JceType::I8)));
assert_eq!(parser.i8(), Ok(0x12));
assert_eq!(parser.pick_head(), Ok((1, JceType::I16)));
assert_eq!(parser.i16(), Ok(0x1234));
assert_eq!(parser.done(), true);

§Error

When JceParser returns Error, remaining bytes will change due to incorrect parsing

This means, the parsing operation is not atomic

Implementations§

Source§

impl<'de> JceParser<'de>

Source

pub fn from_bytes(bytes: &'de [u8]) -> Self

Source

pub fn done(&self) -> bool

Source§

impl<'de> JceParser<'de>

Source

pub fn pick_tag(&self) -> Result<u8>

Source

pub fn pick_type(&self) -> Result<JceType>

Source

pub fn pick_head(&self) -> Result<(u8, JceType)>

Source§

impl<'de> JceParser<'de>

Source

pub fn i8(&mut self) -> Result<i8>

Source

pub fn i16(&mut self) -> Result<i16>

Source

pub fn i32(&mut self) -> Result<i32>

Source

pub fn i64(&mut self) -> Result<i64>

Source

pub fn f32(&mut self) -> Result<f32>

Source

pub fn f64(&mut self) -> Result<f64>

Source

pub fn str_small(&mut self) -> Result<&'de str>

Source

pub fn str_big(&mut self) -> Result<&'de str>

Source

pub fn str(&mut self) -> Result<&'de str>

Source

pub fn map<'a>(&'a mut self) -> Result<usize>

swallow headers & return the length of map

Source

pub fn list<'a>(&'a mut self) -> Result<usize>

swallow headers & return the length of list

Source

pub fn struct_begin<'a>(&mut self) -> Result<()>

Basically do nothing but swallow headers

Source

pub fn struct_end<'a>(&mut self) -> Result<()>

Basically do nothing but swallow headers

Source

pub fn zero(&mut self) -> Result<()>

Source

pub fn bytes(&mut self) -> Result<&'de [u8]>

Source

pub fn ignore(&mut self) -> Result<()>

Auto Trait Implementations§

§

impl<'de> Freeze for JceParser<'de>

§

impl<'de> RefUnwindSafe for JceParser<'de>

§

impl<'de> Send for JceParser<'de>

§

impl<'de> Sync for JceParser<'de>

§

impl<'de> Unpin for JceParser<'de>

§

impl<'de> UnwindSafe for JceParser<'de>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.