Switch to common crate for serialization
This commit is contained in:
parent
f5d85449ed
commit
e9e185a6b0
|
@ -684,15 +684,12 @@ fn enum_to_methods(
|
||||||
pub struct _DefaultCoder;
|
pub struct _DefaultCoder;
|
||||||
impl _DefaultCoder {
|
impl _DefaultCoder {
|
||||||
pub fn to_bytes(i: #instruction_mod_ident::#instruction_enum_ident) -> Vec<u8> {
|
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")
|
.expect("instruction must be serializable")
|
||||||
}
|
}
|
||||||
pub fn from_bytes(data: &[u8]) -> Result<Vec<u8>, ()> {
|
pub fn from_bytes(data: &[u8]) -> Result<#instruction_mod_ident::#instruction_enum_ident, ()> {
|
||||||
match data.split_first() {
|
serum_common::pack::from_bytes(data)
|
||||||
None => Err(()),
|
.map_err(|_| ())
|
||||||
Some((&0u8, rest)) => bincode::deserialize(rest).map_err(|_| ()),
|
|
||||||
Some((_, _rest)) => Err(()),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue