sode
I’ve created a simple binary serialization crate called “sode” for Kadent. This guarantees that the output binary won’t change even if the struct is modified so I thought it would be better than serde or that sort of serialization library.
impl Encode for Note {
fn encode(&self, e: &mut Encoder) -> Result<(), EncodeError> {
e.field(0, &self.start)?;
e.field(1, &self.duration)?;
e.field(2, &self.pitch)?;
e.field(3, &self.velocity)?;
Ok(())
}
}
impl Decode for Note {
fn decode(d: &mut ValueDecoder) -> Result<Self, DecodeError> {
let d = d.to_field_decoder()?;
Ok(Note::new(
d.field(0)?.ok_or(DecodeError::InvalidData)?,
d.field(1)?.ok_or(DecodeError::InvalidData)?,
d.field(2)?.ok_or(DecodeError::InvalidData)?,
d.field(3)?.ok_or(DecodeError::InvalidData)?,
))
}
}
Comments 0
No comments yet. Be the first!
Sign in to join the conversation.