Add conversion functions on SysExMessage trait
This commit is contained in:
parent
d9cf78e72a
commit
611dc452ec
1 changed files with 20 additions and 1 deletions
|
@ -7,10 +7,29 @@ pub trait SysExMessage: Debug + Clone + PartialEq + Send + Sync {
|
|||
/// The maximum SysEx message size, in bytes.
|
||||
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.
|
||||
impl SysExMessage for () {
|
||||
const MAX_BUFFER_SIZE: usize = 0;
|
||||
|
||||
fn from_buffer(_buffer: &[u8]) -> Option<Self> {
|
||||
None
|
||||
}
|
||||
|
||||
fn to_buffer(self, _buffer: &mut [u8]) -> usize {
|
||||
0
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue