pub struct Decoder<I: Iterator> { /* private fields */ }
Expand description
JSON decoder over char
iterators.
Implementations§
Source§impl<I: Iterator<Item = char>> Decoder<I>
impl<I: Iterator<Item = char>> Decoder<I>
pub fn new(c: Config, i: I) -> Decoder<I>
pub fn into_iter(self) -> I
pub fn iter_mut(&mut self) -> &mut I
Sourcepub fn from_json<T: FromJson>(&mut self) -> DecodeResult<T>
pub fn from_json<T: FromJson>(&mut self) -> DecodeResult<T>
Generic conversion from JSON to an instance of FromJson
.
Sourcepub fn decode(&mut self) -> DecodeResult<Json>
pub fn decode(&mut self) -> DecodeResult<Json>
Decode into Json
AST value.
Sourcepub fn skip(&mut self) -> DecodeResult<()>
pub fn skip(&mut self) -> DecodeResult<()>
Decode as generic Json but ignore the result.
Semantically this method is equivalent to Decoder::decode
but potentially more efficient as it tries to avoid allocating
intermediate values.
pub fn u8(&mut self) -> DecodeResult<u8>
pub fn u16(&mut self) -> DecodeResult<u16>
pub fn u32(&mut self) -> DecodeResult<u32>
pub fn u64(&mut self) -> DecodeResult<u64>
pub fn u128(&mut self) -> DecodeResult<u128>
pub fn usize(&mut self) -> DecodeResult<usize>
pub fn i8(&mut self) -> DecodeResult<i8>
pub fn i16(&mut self) -> DecodeResult<i16>
pub fn i32(&mut self) -> DecodeResult<i32>
pub fn i64(&mut self) -> DecodeResult<i64>
pub fn i128(&mut self) -> DecodeResult<i128>
pub fn isize(&mut self) -> DecodeResult<isize>
pub fn null(&mut self) -> DecodeResult<()>
pub fn bool(&mut self) -> DecodeResult<bool>
pub fn string(&mut self) -> DecodeResult<String>
Sourcepub fn str(
&mut self,
b: &mut Utf8Buffer<'_>,
overflow_err: bool,
) -> DecodeResult<()>
pub fn str( &mut self, b: &mut Utf8Buffer<'_>, overflow_err: bool, ) -> DecodeResult<()>
Decode a JSON string into the given Utf8Buffer
.
If the actual string does not fit into the provided buffer
and overflow_err
is true
, DecodeError::BufferOverflow
is returned immediately. If overflow_err
is false we
continue decoding the string, but the buffer will only
contain as much as fits into it.
Sourcepub fn optional<A, F>(&mut self, f: F) -> DecodeResult<Option<A>>
pub fn optional<A, F>(&mut self, f: F) -> DecodeResult<Option<A>>
Decode null
(which is mapped to None
) or some other
JSON value (mapped to Some
).
Sourcepub fn has_more(&mut self) -> DecodeResult<bool>
pub fn has_more(&mut self) -> DecodeResult<bool>
When parsing JSON arrays and objects this needs to be called in between to check if the array / object end has been reached. E.g.
use json_codec_wasm::{Decoder, DecodeResult};
fn foo<I: Iterator<Item=char>>(d: &mut Decoder<I>) -> DecodeResult<Vec<u8>> {
d.array()?;
let mut v = Vec::new();
while d.has_more()? {
v.push(d.u8()?)
}
Ok(v)
}
Sourcepub fn array(&mut self) -> DecodeResult<()>
pub fn array(&mut self) -> DecodeResult<()>
Begin parsing a JSON array.
Before each element is parsed, Decoder::has_more
needs to be queried.
Sourcepub fn array_iter<A: FromJson>(&mut self) -> DecodeResult<ArrayIter<'_, A, I>>
pub fn array_iter<A: FromJson>(&mut self) -> DecodeResult<ArrayIter<'_, A, I>>
Create a JSON array iterator to decode a homogenous array.
use json_codec_wasm::Decoder;
let mut d = Decoder::default("[1,2,3,4]".chars());
let mut v: Vec<u8> = Vec::new();
for i in d.array_iter().unwrap() {
v.push(i.unwrap())
}
Sourcepub fn object(&mut self) -> DecodeResult<()>
pub fn object(&mut self) -> DecodeResult<()>
Begin parsing a JSON object.
Before each key is parsed, Decoder::has_more
needs to be queried.
Sourcepub fn key(&mut self) -> DecodeResult<String>
pub fn key(&mut self) -> DecodeResult<String>
Decode a JSON object key.
Sourcepub fn key_str(
&mut self,
b: &mut Utf8Buffer<'_>,
overflow_err: bool,
) -> DecodeResult<()>
pub fn key_str( &mut self, b: &mut Utf8Buffer<'_>, overflow_err: bool, ) -> DecodeResult<()>
Decode a JSON object key into the given buffer.