1
+ use cosmwasm_std:: StdError ;
1
2
use storey:: encoding:: { Cover , DecodableWithImpl , EncodableWithImpl , Encoding } ;
2
3
3
4
/// An encoding that delegates to the [*MessagePack*] encoding provided by the [`cosmwasm_std`] crate.
@@ -13,15 +14,15 @@ use storey::encoding::{Cover, DecodableWithImpl, EncodableWithImpl, Encoding};
13
14
pub struct CwEncoding ;
14
15
15
16
impl Encoding for CwEncoding {
16
- type DecodeError = cosmwasm_std_new :: StdError ;
17
- type EncodeError = cosmwasm_std_new :: StdError ;
17
+ type DecodeError = StdError ;
18
+ type EncodeError = StdError ;
18
19
}
19
20
20
21
impl < T > EncodableWithImpl < CwEncoding > for Cover < & T >
21
22
where
22
23
T : serde:: Serialize ,
23
24
{
24
- fn encode_impl ( self ) -> Result < Vec < u8 > , cosmwasm_std_new :: StdError > {
25
+ fn encode_impl ( self ) -> Result < Vec < u8 > , StdError > {
25
26
cosmwasm_std_new:: to_msgpack_vec ( self . 0 )
26
27
}
27
28
}
@@ -30,7 +31,28 @@ impl<T> DecodableWithImpl<CwEncoding> for Cover<T>
30
31
where
31
32
T : serde:: de:: DeserializeOwned ,
32
33
{
33
- fn decode_impl ( data : & [ u8 ] ) -> Result < Self , cosmwasm_std_new :: StdError > {
34
+ fn decode_impl ( data : & [ u8 ] ) -> Result < Self , StdError > {
34
35
cosmwasm_std_new:: from_msgpack ( data) . map ( Cover )
35
36
}
36
37
}
38
+
39
+ // TODO: remove this module once the following PR is released on crates.io:
40
+ // https://github.com/CosmWasm/cosmwasm/pull/2118
41
+ mod cosmwasm_std_new {
42
+ use core:: any:: type_name;
43
+
44
+ use cosmwasm_std:: { StdError , StdResult } ;
45
+ use serde:: de:: DeserializeOwned ;
46
+ use serde:: Serialize ;
47
+
48
+ pub ( super ) fn from_msgpack < T : DeserializeOwned > ( value : impl AsRef < [ u8 ] > ) -> StdResult < T > {
49
+ rmp_serde:: from_read ( value. as_ref ( ) ) . map_err ( |e| StdError :: parse_err ( type_name :: < T > ( ) , e) )
50
+ }
51
+
52
+ pub ( super ) fn to_msgpack_vec < T > ( data : & T ) -> StdResult < Vec < u8 > >
53
+ where
54
+ T : Serialize + ?Sized ,
55
+ {
56
+ rmp_serde:: to_vec_named ( data) . map_err ( |e| StdError :: serialize_err ( type_name :: < T > ( ) , e) )
57
+ }
58
+ }
0 commit comments