Switch to common crate for serialization

This commit is contained in:
armaniferrante 2020-09-23 01:42:14 -07:00
parent f5d85449ed
commit e9e185a6b0
No known key found for this signature in database
GPG Key ID: 58BEF301E91F7828
1 changed files with 4 additions and 7 deletions

View File

@ -684,15 +684,12 @@ fn enum_to_methods(
pub struct _DefaultCoder;
impl _DefaultCoder {
pub fn to_bytes(i: #instruction_mod_ident::#instruction_enum_ident) -> Vec<u8> {
bincode::serialize(&(0u8, i))
serum_common::pack::to_bytes(&i)
.expect("instruction must be serializable")
}
pub fn from_bytes(data: &[u8]) -> Result<Vec<u8>, ()> {
match data.split_first() {
None => Err(()),
Some((&0u8, rest)) => bincode::deserialize(rest).map_err(|_| ()),
Some((_, _rest)) => Err(()),
}
pub fn from_bytes(data: &[u8]) -> Result<#instruction_mod_ident::#instruction_enum_ident, ()> {
serum_common::pack::from_bytes(data)
.map_err(|_| ())
}
}
}