1
0
Fork 0

Add conversion functions on SysExMessage trait

This commit is contained in:
Robbert van der Helm 2023-01-31 18:57:49 +01:00
parent d9cf78e72a
commit 611dc452ec

View file

@ -7,10 +7,29 @@ pub trait SysExMessage: Debug + Clone + PartialEq + Send + Sync {
/// The maximum SysEx message size, in bytes. /// The maximum SysEx message size, in bytes.
const MAX_BUFFER_SIZE: usize; const MAX_BUFFER_SIZE: usize;
// TODO: Conversion functions /// Read a SysEx message from `buffer` and convert it to this message type if supported.
/// `buffer`'s length matches the received message. It is not padded to `MAX_BUFFER_SIZE` bytes.
fn from_buffer(buffer: &[u8]) -> Option<Self>;
/// Serialize this message object as a SysEx message in `buffer`, returning the message's length
/// in bytes.
///
/// `buffer` is a `[u8; Self::MAX_BUFFER_SIZE]`, but Rust currently doesn't allow using
/// associated constants in method types:
///
/// <https://github.com/rust-lang/rust/issues/60551>
fn to_buffer(self, buffer: &mut [u8]) -> usize;
} }
/// A default implementation plugins that don't need SysEx support can use. /// A default implementation plugins that don't need SysEx support can use.
impl SysExMessage for () { impl SysExMessage for () {
const MAX_BUFFER_SIZE: usize = 0; const MAX_BUFFER_SIZE: usize = 0;
fn from_buffer(_buffer: &[u8]) -> Option<Self> {
None
}
fn to_buffer(self, _buffer: &mut [u8]) -> usize {
0
}
} }