Closed PopcornPaws closed 2 years ago
@volovyk-s would you please take a look?
@PopcornPaws awesome contribution! Have you tested it with borsh-rs
? Can we serialize it here and deserialize it in Rust and vise-versa?
@PopcornPaws awesome contribution! Have you tested it with
borsh-rs
? Can we serialize it here and deserialize it in Rust and vise-versa?
@volovyk-s Yep, I tested the (de)serialization of a BTreeMap<[u8; 32], Pubkey>
, a BTreeMap<String, Option<u32>
and a BTreeMap<u16, String>
type in Rust and it worked seamlessly in both ways.
Thank you @PopcornPaws !
@volovyk-s thank you!
It would be nice if Borsh-js would support
Map
types out of the box.For example, I would like to use a rust
BTreeMap
type on the contract side that can be serialized/deserialized on the client side in aMap
type. As far as I know,BTreeMap
s are serialized similarly to aVec
, namely there is 4 bytes reserved at the front to encode the length (size) in LE representation, then the keys and values are serialized in a sorted sequence, so, contrary to aHashMap
type, there's no danger of iterating over the key-value pairs randomly.What do you guys think?