diff --git a/src/commands/music_database/findadd.rs b/src/commands/music_database/findadd.rs index 11586ef..3ef977d 100644 --- a/src/commands/music_database/findadd.rs +++ b/src/commands/music_database/findadd.rs @@ -8,10 +8,8 @@ use crate::{ pub struct FindAdd; -pub struct FindAddResponse {} - impl Command for FindAdd { - type Response = FindAddResponse; + type Response = (); const COMMAND: &'static str = "findadd"; fn parse_request(mut parts: std::str::SplitWhitespace<'_>) -> RequestParserResult<'_> { @@ -56,6 +54,7 @@ impl Command for FindAdd { fn parse_response( parts: ResponseAttributes<'_>, ) -> Result { - unimplemented!() + debug_assert!(parts.is_empty()); + Ok(()) } } diff --git a/src/commands/music_database/searchadd.rs b/src/commands/music_database/searchadd.rs index f82931d..983e45d 100644 --- a/src/commands/music_database/searchadd.rs +++ b/src/commands/music_database/searchadd.rs @@ -8,10 +8,8 @@ use crate::{ pub struct SearchAdd; -pub struct SearchAddResponse {} - impl Command for SearchAdd { - type Response = SearchAddResponse; + type Response = (); const COMMAND: &'static str = "searchadd"; fn parse_request(mut parts: std::str::SplitWhitespace<'_>) -> RequestParserResult<'_> { @@ -56,6 +54,7 @@ impl Command for SearchAdd { fn parse_response( parts: ResponseAttributes<'_>, ) -> Result { - unimplemented!() + debug_assert!(parts.is_empty()); + Ok(()) } } diff --git a/src/commands/music_database/searchaddpl.rs b/src/commands/music_database/searchaddpl.rs index 4ee59ed..44ecd04 100644 --- a/src/commands/music_database/searchaddpl.rs +++ b/src/commands/music_database/searchaddpl.rs @@ -8,10 +8,8 @@ use crate::{ pub struct SearchAddPl; -pub struct SearchAddPlResponse {} - impl Command for SearchAddPl { - type Response = SearchAddPlResponse; + type Response = (); const COMMAND: &'static str = "searchaddpl"; fn parse_request(mut parts: std::str::SplitWhitespace<'_>) -> RequestParserResult<'_> { @@ -64,6 +62,7 @@ impl Command for SearchAddPl { fn parse_response( parts: ResponseAttributes<'_>, ) -> Result { - unimplemented!() + debug_assert!(parts.is_empty()); + Ok(()) } } diff --git a/src/commands/reflection/commands.rs b/src/commands/reflection/commands.rs index 94d9eb8..395fa4b 100644 --- a/src/commands/reflection/commands.rs +++ b/src/commands/reflection/commands.rs @@ -1,11 +1,14 @@ use crate::commands::{ - Command, Request, RequestParserResult, ResponseAttributes, ResponseParserError, + Command, GenericResponseValue, Request, RequestParserResult, ResponseAttributes, + ResponseParserError, }; pub struct Commands; +pub type CommandsResponse = Vec; + impl Command for Commands { - type Response = (); + type Response = CommandsResponse; const COMMAND: &'static str = "commands"; fn parse_request(mut parts: std::str::SplitWhitespace<'_>) -> RequestParserResult<'_> { @@ -16,6 +19,22 @@ impl Command for Commands { fn parse_response( parts: ResponseAttributes<'_>, ) -> Result { - unimplemented!() + let parts: Vec<_> = parts.into(); + let mut result = Vec::new(); + for (key, value) in parts.into_iter() { + if key != "command" { + return Err(ResponseParserError::UnexpectedProperty(key)); + } + let value = match value { + GenericResponseValue::Text(value) => value, + GenericResponseValue::Binary(_) => { + return Err(ResponseParserError::UnexpectedPropertyType( + "handler", "Binary", + )) + } + }; + result.push(value.to_string()); + } + Ok(result) } } diff --git a/src/commands/reflection/not_commands.rs b/src/commands/reflection/not_commands.rs index af79fe9..482c318 100644 --- a/src/commands/reflection/not_commands.rs +++ b/src/commands/reflection/not_commands.rs @@ -1,12 +1,15 @@ use crate::commands::{ - Command, Request, RequestParserResult, ResponseAttributes, ResponseParserError, + Command, GenericResponseValue, Request, RequestParserResult, ResponseAttributes, + ResponseParserError, }; pub struct NotCommands; +pub type NotCommandsResponse = Vec; + impl Command for NotCommands { - type Response = (); - const COMMAND: &'static str = "not_commands"; + type Response = NotCommandsResponse; + const COMMAND: &'static str = "notcommands"; fn parse_request(mut parts: std::str::SplitWhitespace<'_>) -> RequestParserResult<'_> { debug_assert!(parts.next().is_none()); @@ -16,6 +19,22 @@ impl Command for NotCommands { fn parse_response( parts: ResponseAttributes<'_>, ) -> Result { - unimplemented!() + let parts: Vec<_> = parts.into(); + let mut result = Vec::new(); + for (key, value) in parts.into_iter() { + if key != "command" { + return Err(ResponseParserError::UnexpectedProperty(key)); + } + let value = match value { + GenericResponseValue::Text(value) => value, + GenericResponseValue::Binary(_) => { + return Err(ResponseParserError::UnexpectedPropertyType( + "handler", "Binary", + )) + } + }; + result.push(value.to_string()); + } + Ok(result) } }