Skip to content

Commit 01656c2

Browse files
committed
fix: inline msgpack encoding functions
1 parent 8e0e4a8 commit 01656c2

File tree

2 files changed

+27
-8
lines changed

2 files changed

+27
-8
lines changed

packages/cw-storey/Cargo.toml

+1-4
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,7 @@ license = { workspace = true }
1212

1313
[dependencies]
1414
cosmwasm-std = "2"
15+
rmp-serde = "1.1"
1516
serde = "1"
1617

17-
# TODO: temporary, remove after this is released:
18-
# https://github.com/CosmWasm/cosmwasm/pull/2118
19-
cosmwasm-std-new = { git = "https://github.com/CosmWasm/cosmwasm.git", rev = "553bdd6fc5cc9c74bebcba99a89c0c4334b8824d", package = "cosmwasm-std" }
20-
2118
storey = { workspace = true }

packages/cw-storey/src/encoding.rs

+26-4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use cosmwasm_std::StdError;
12
use storey::encoding::{Cover, DecodableWithImpl, EncodableWithImpl, Encoding};
23

34
/// 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};
1314
pub struct CwEncoding;
1415

1516
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;
1819
}
1920

2021
impl<T> EncodableWithImpl<CwEncoding> for Cover<&T>
2122
where
2223
T: serde::Serialize,
2324
{
24-
fn encode_impl(self) -> Result<Vec<u8>, cosmwasm_std_new::StdError> {
25+
fn encode_impl(self) -> Result<Vec<u8>, StdError> {
2526
cosmwasm_std_new::to_msgpack_vec(self.0)
2627
}
2728
}
@@ -30,7 +31,28 @@ impl<T> DecodableWithImpl<CwEncoding> for Cover<T>
3031
where
3132
T: serde::de::DeserializeOwned,
3233
{
33-
fn decode_impl(data: &[u8]) -> Result<Self, cosmwasm_std_new::StdError> {
34+
fn decode_impl(data: &[u8]) -> Result<Self, StdError> {
3435
cosmwasm_std_new::from_msgpack(data).map(Cover)
3536
}
3637
}
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

Comments
 (0)