web3api_wasm_rs/msgpack/
read.rs

1use super::error::DecodeError;
2use crate::{BigInt, BigNumber, Context, JSON};
3use core::hash::Hash;
4use std::collections::BTreeMap;
5
6pub trait Read {
7    fn read_bool(&mut self) -> Result<bool, DecodeError>;
8    fn read_i8(&mut self) -> Result<i8, DecodeError>;
9    fn read_i16(&mut self) -> Result<i16, DecodeError>;
10    fn read_i32(&mut self) -> Result<i32, DecodeError>;
11    fn read_u8(&mut self) -> Result<u8, DecodeError>;
12    fn read_u16(&mut self) -> Result<u16, DecodeError>;
13    fn read_u32(&mut self) -> Result<u32, DecodeError>;
14    fn read_f32(&mut self) -> Result<f32, DecodeError>;
15    fn read_f64(&mut self) -> Result<f64, DecodeError>;
16    fn read_string_length(&mut self) -> Result<u32, DecodeError>;
17    fn read_string(&mut self) -> Result<String, DecodeError>;
18    fn read_bytes_length(&mut self) -> Result<u32, DecodeError>;
19    fn read_bytes(&mut self) -> Result<Vec<u8>, DecodeError>;
20    fn read_bigint(&mut self) -> Result<BigInt, DecodeError>;
21    fn read_bignumber(&mut self) -> Result<BigNumber, DecodeError>;
22    fn read_json(&mut self) -> Result<JSON::Value, DecodeError>;
23    fn read_array_length(&mut self) -> Result<u32, DecodeError>;
24    fn read_array<T>(
25        &mut self,
26        item_reader: impl FnMut(&mut Self) -> Result<T, DecodeError>,
27    ) -> Result<Vec<T>, DecodeError>;
28    fn read_map_length(&mut self) -> Result<u32, DecodeError>;
29    fn read_map<K, V>(
30        &mut self,
31        key_reader: impl FnMut(&mut Self) -> Result<K, DecodeError>,
32        val_reader: impl FnMut(&mut Self) -> Result<V, DecodeError>,
33    ) -> Result<BTreeMap<K, V>, DecodeError>
34    where
35        K: Eq + Hash + Ord;
36    fn read_ext_generic_map<K, V>(
37        &mut self,
38        key_reader: impl FnMut(&mut Self) -> Result<K, DecodeError>,
39        val_reader: impl FnMut(&mut Self) -> Result<V, DecodeError>,
40    ) -> Result<BTreeMap<K, V>, DecodeError>
41    where
42        K: Eq + Hash + Ord;
43
44    fn read_nullable_bool(&mut self) -> Result<Option<bool>, DecodeError>;
45    fn read_nullable_i8(&mut self) -> Result<Option<i8>, DecodeError>;
46    fn read_nullable_i16(&mut self) -> Result<Option<i16>, DecodeError>;
47    fn read_nullable_i32(&mut self) -> Result<Option<i32>, DecodeError>;
48    fn read_nullable_u8(&mut self) -> Result<Option<u8>, DecodeError>;
49    fn read_nullable_u16(&mut self) -> Result<Option<u16>, DecodeError>;
50    fn read_nullable_u32(&mut self) -> Result<Option<u32>, DecodeError>;
51    fn read_nullable_f32(&mut self) -> Result<Option<f32>, DecodeError>;
52    fn read_nullable_f64(&mut self) -> Result<Option<f64>, DecodeError>;
53    fn read_nullable_string(&mut self) -> Result<Option<String>, DecodeError>;
54    fn read_nullable_bytes(&mut self) -> Result<Option<Vec<u8>>, DecodeError>;
55    fn read_nullable_bigint(&mut self) -> Result<Option<BigInt>, DecodeError>;
56    fn read_nullable_bignumber(&mut self) -> Result<Option<BigNumber>, DecodeError>;
57    fn read_nullable_json(&mut self) -> Result<Option<JSON::Value>, DecodeError>;
58    fn read_nullable_array<T>(
59        &mut self,
60        item_reader: impl FnMut(&mut Self) -> Result<T, DecodeError>,
61    ) -> Result<Option<Vec<T>>, DecodeError>;
62    fn read_nullable_map<K, V>(
63        &mut self,
64        key_reader: impl FnMut(&mut Self) -> Result<K, DecodeError>,
65        val_reader: impl FnMut(&mut Self) -> Result<V, DecodeError>,
66    ) -> Result<Option<BTreeMap<K, V>>, DecodeError>
67    where
68        K: Eq + Hash + Ord;
69    fn read_nullable_ext_generic_map<K, V>(
70        &mut self,
71        key_reader: impl FnMut(&mut Self) -> Result<K, DecodeError>,
72        val_reader: impl FnMut(&mut Self) -> Result<V, DecodeError>,
73    ) -> Result<Option<BTreeMap<K, V>>, DecodeError>
74    where
75        K: Eq + Hash + Ord;
76
77    fn is_next_nil(&mut self) -> Result<bool, DecodeError>;
78    fn is_next_string(&mut self) -> Result<bool, DecodeError>;
79
80    fn context(&mut self) -> &mut Context;
81}