-
Notifications
You must be signed in to change notification settings - Fork 28
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
added serde feature for MidiMessage #30
base: master
Are you sure you want to change the base?
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
MidiMessage
is useful.I have implemented
deserialize
andserialize
for just that enum and its contents but if you were interested in this PR I could expand to impl more types.