web3api_wasm_rs/msgpack/
write.rs

1use super::error::EncodeError;
2use crate::{BigInt, BigNumber, Context, JSON};
3use core::hash::Hash;
4use std::collections::BTreeMap;
5
6pub trait Write {
7    fn write_nil(&mut self) -> Result<(), EncodeError>;
8    fn write_bool(&mut self, value: &bool) -> Result<(), EncodeError>;
9    fn write_i8(&mut self, value: &i8) -> Result<(), EncodeError>;
10    fn write_i16(&mut self, value: &i16) -> Result<(), EncodeError>;
11    fn write_i32(&mut self, value: &i32) -> Result<(), EncodeError>;
12    fn write_u8(&mut self, value: &u8) -> Result<(), EncodeError>;
13    fn write_u16(&mut self, value: &u16) -> Result<(), EncodeError>;
14    fn write_u32(&mut self, value: &u32) -> Result<(), EncodeError>;
15    fn write_f32(&mut self, value: &f32) -> Result<(), EncodeError>;
16    fn write_f64(&mut self, value: &f64) -> Result<(), EncodeError>;
17    fn write_string_length(&mut self, length: &u32) -> Result<(), EncodeError>;
18    fn write_string(&mut self, value: &str) -> Result<(), EncodeError>;
19    fn write_bytes_length(&mut self, length: &u32) -> Result<(), EncodeError>;
20    fn write_bytes(&mut self, buf: &[u8]) -> Result<(), EncodeError>;
21    fn write_bigint(&mut self, value: &BigInt) -> Result<(), EncodeError>;
22    fn write_bignumber(&mut self, value: &BigNumber) -> Result<(), EncodeError>;
23    fn write_json(&mut self, value: &JSON::Value) -> Result<(), EncodeError>;
24    fn write_array_length(&mut self, length: &u32) -> Result<(), EncodeError>;
25    fn write_array<T: Clone>(
26        &mut self,
27        array: &[T],
28        item_writer: impl FnMut(&mut Self, &T) -> Result<(), EncodeError>,
29    ) -> Result<(), EncodeError>;
30    fn write_map_length(&mut self, length: &u32) -> Result<(), EncodeError>;
31    fn write_map<K, V: Clone>(
32        &mut self,
33        map: &BTreeMap<K, V>,
34        key_writer: impl FnMut(&mut Self, &K) -> Result<(), EncodeError>,
35        val_writer: impl FnMut(&mut Self, &V) -> Result<(), EncodeError>,
36    ) -> Result<(), EncodeError>
37    where
38        K: Clone + Eq + Hash + Ord;
39    fn write_ext_generic_map<K, V: Clone>(
40        &mut self,
41        map: &BTreeMap<K, V>,
42        key_writer: impl FnMut(&mut Self, &K) -> Result<(), EncodeError>,
43        val_writer: impl FnMut(&mut Self, &V) -> Result<(), EncodeError>,
44    ) -> Result<(), EncodeError>
45    where
46        K: Clone + Eq + Hash + Ord;
47
48    fn write_nullable_bool(&mut self, value: &Option<bool>) -> Result<(), EncodeError>;
49    fn write_nullable_i8(&mut self, value: &Option<i8>) -> Result<(), EncodeError>;
50    fn write_nullable_i16(&mut self, value: &Option<i16>) -> Result<(), EncodeError>;
51    fn write_nullable_i32(&mut self, value: &Option<i32>) -> Result<(), EncodeError>;
52    fn write_nullable_u8(&mut self, value: &Option<u8>) -> Result<(), EncodeError>;
53    fn write_nullable_u16(&mut self, value: &Option<u16>) -> Result<(), EncodeError>;
54    fn write_nullable_u32(&mut self, value: &Option<u32>) -> Result<(), EncodeError>;
55    fn write_nullable_f32(&mut self, value: &Option<f32>) -> Result<(), EncodeError>;
56    fn write_nullable_f64(&mut self, value: &Option<f64>) -> Result<(), EncodeError>;
57    fn write_nullable_string(&mut self, value: &Option<String>) -> Result<(), EncodeError>;
58    fn write_nullable_bytes(&mut self, value: &Option<Vec<u8>>) -> Result<(), EncodeError>;
59    fn write_nullable_bigint(&mut self, value: &Option<BigInt>) -> Result<(), EncodeError>;
60    fn write_nullable_bignumber(&mut self, value: &Option<BigNumber>) -> Result<(), EncodeError>;
61    fn write_nullable_json(&mut self, value: &Option<JSON::Value>) -> Result<(), EncodeError>;
62    fn write_nullable_array<T: Clone>(
63        &mut self,
64        opt_array: &Option<Vec<T>>,
65        item_writer: impl FnMut(&mut Self, &T) -> Result<(), EncodeError>,
66    ) -> Result<(), EncodeError>;
67    fn write_nullable_map<K, V: Clone>(
68        &mut self,
69        opt_map: &Option<BTreeMap<K, V>>,
70        key_writer: impl FnMut(&mut Self, &K) -> Result<(), EncodeError>,
71        val_writer: impl FnMut(&mut Self, &V) -> Result<(), EncodeError>,
72    ) -> Result<(), EncodeError>
73    where
74        K: Clone + Eq + Hash + Ord;
75    fn write_nullable_ext_generic_map<K, V: Clone>(
76        &mut self,
77        opt_map: &Option<BTreeMap<K, V>>,
78        key_writer: impl FnMut(&mut Self, &K) -> Result<(), EncodeError>,
79        val_writer: impl FnMut(&mut Self, &V) -> Result<(), EncodeError>,
80    ) -> Result<(), EncodeError>
81    where
82        K: Clone + Eq + Hash + Ord;
83
84    fn context(&mut self) -> &mut Context;
85}