use rmp_serde; use serde::{Serialize, Deserialize}; use std::io::{Write, Read, Cursor}; pub use serde::bytes::ByteBuf as Bytes; pub use rmp_serde::decode::Error as DecodeError; pub use rmp_serde::encode::Error as EncodeError; #[inline] pub fn encode(t: &T) -> Result, EncodeError> { let mut data = Vec::new(); { let mut writer = rmp_serde::Serializer::new(&mut data); try!(t.serialize(&mut writer)); } Ok(data) } #[inline] pub fn encode_to_stream(t: &T, w: &mut Write) -> Result<(), EncodeError> { let mut writer = rmp_serde::Serializer::new(w); t.serialize(&mut writer) } #[inline] pub fn decode(data: &[u8]) -> Result { let data = Cursor::new(data); let mut reader = rmp_serde::Deserializer::new(data); T::deserialize(&mut reader) } #[inline] pub fn decode_from_stream(r: &mut Read) -> Result { let mut reader = rmp_serde::Deserializer::new(r); T::deserialize(&mut reader) }