pub struct LowLevelJsonReader { /* private fields */ }
Expand description

A low-level JSON parser acting on a provided buffer.

Does not allocate except a stack to check if array and object opening and closing are properly nested. This stack size might be limited using the method with_max_stack_size.

use json_event_parser::{LowLevelJsonReader, JsonEvent, LowLevelJsonReaderResult};

let mut reader = LowLevelJsonReader::new();
assert!(matches!(
    reader.read_next_event(b"{\"foo".as_slice(), false),
    LowLevelJsonReaderResult { consumed_bytes: 1, event: Some(Ok(JsonEvent::StartObject))}
));
assert!(matches!(
    reader.read_next_event(b"\"foo".as_slice(), false),
    LowLevelJsonReaderResult { consumed_bytes: 0, event: None }
));
assert!(matches!(
    reader.read_next_event(b"\"foo\": 1}".as_slice(), false),
    LowLevelJsonReaderResult { consumed_bytes: 5, event: Some(Ok(JsonEvent::ObjectKey(Cow::Borrowed("foo")))) }
));
assert!(matches!(
    reader.read_next_event(b": 1}".as_slice(), false),
    LowLevelJsonReaderResult { consumed_bytes: 3, event: Some(Ok(JsonEvent::Number(Cow::Borrowed("1")))) }
));
assert!(matches!(
    reader.read_next_event(b"}".as_slice(), false),
    LowLevelJsonReaderResult { consumed_bytes: 1, event: Some(Ok(JsonEvent::EndObject)) }
));
assert!(matches!(
    reader.read_next_event(b"".as_slice(), true),
    LowLevelJsonReaderResult { consumed_bytes: 0, event: Some(Ok(JsonEvent::Eof)) }
));

Implementations§

source§

impl LowLevelJsonReader

source

pub const fn new() -> Self

source

pub fn with_max_stack_size(self, size: usize) -> Self

Maximal allowed number of nested object and array openings. Infinite by default.

source

pub fn read_next_event<'a>( &mut self, input_buffer: &'a [u8], is_ending: bool ) -> LowLevelJsonReaderResult<'a>

Reads a new event from the data in input_buffer.

is_ending must be set to true if all the JSON data have been already consumed or are in input_buffer.

Auto Trait Implementations§

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>,

§

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>,

§

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.