pub fn from_msgpack<T: DeserializeOwned>(
value: impl AsRef<[u8]>,
) -> StdResult<T>
Expand description
Deserializes the given MessagePack bytes to a data structure.
Errors if the input is not valid MessagePack or cannot be deserialized to the given type.
ยงExamples
Encoding and decoding an enum using MessagePack.
use cosmwasm_schema::cw_serde;
use cosmwasm_std::{to_msgpack_binary, from_msgpack};
#[cw_serde]
enum MyPacket {
Cowsay {
text: String,
},
}
let packet = MyPacket::Cowsay { text: "hi".to_string() };
let encoded = to_msgpack_binary(&packet).unwrap();
let decoded: MyPacket = from_msgpack(&encoded).unwrap();
assert_eq!(decoded, packet);