added serde feature for MidiMessage#30
Conversation
|
I like it. It would be nice to implement the Additionally, we are not using any As an aside, implementing |
|
Hello, I've implemented Deserializing |
|
I impl #[cfg(feature = "serde")]
impl<'de: 'a, 'a> serde::Deserialize<'de> for SystemCommon<'a>{
fn deserialize<D>(deserializer: D) -> StdResult<Self, D::Error>
where
D: serde::Deserializer<'de>,
{
#[derive(Debug, serde::Deserialize)]
enum Internal<'a> {
SysEx(&'a [u8]),
MidiTimeCodeQuarterFrame(MtcQuarterFrameMessage, u4),
SongPosition(u14),
SongSelect(u7),
TuneRequest,
Undefined(u8, &'a [u8])
}
let internal = Internal::deserialize(deserializer)?;
match internal {
Internal::SysEx(data) => Ok(SystemCommon::SysEx(u7::slice_from_int(data))),
Internal::MidiTimeCodeQuarterFrame(msg, data) => Ok(SystemCommon::MidiTimeCodeQuarterFrame(msg, data)),
Internal::SongPosition(pos) => Ok(SystemCommon::SongPosition(pos)),
Internal::SongSelect(song) => Ok(SystemCommon::SongSelect(song)),
Internal::TuneRequest => Ok(SystemCommon::TuneRequest),
Internal::Undefined(status, data) => Ok(SystemCommon::Undefined(status, u7::slice_from_int(data))),
}
}
} #[test]
fn test_deserialize_system_common() {
let sys_ex = serde_json::from_str(r#"{"Common":{"SysEx":[1, 2, 3, 4, 5, 6]}}"#).unwrap();
assert_eq!(LiveEvent::Common(crate::live::SystemCommon::SysEx(crate::num::u7::slice_from_int(&[1, 2, 3, 4, 5, 6]))), sys_ex);
} |
For a project I am working on serde support for the
MidiMessageis useful.I have implemented
deserializeandserializefor just that enum and its contents but if you were interested in this PR I could expand to impl more types.