pub fn to_msgpack_binary<T>(data: &T) -> StdResult<Binary>
Expand description
Serializes the given data structure as MessagePack bytes.
ยง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);