commands: deduplicate logic in macros, add more macros
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
use crate::{
|
||||
commands::{
|
||||
Command, GenericResponseValue, Request, RequestParserError, RequestParserResult,
|
||||
get_next_and_parse_property, Command, Request, RequestParserError, RequestParserResult,
|
||||
ResponseAttributes, ResponseParserError,
|
||||
},
|
||||
common::{SongId, SongPosition},
|
||||
@@ -39,17 +39,9 @@ impl Command for AddId {
|
||||
parts: ResponseAttributes<'_>,
|
||||
) -> Result<Self::Response, ResponseParserError> {
|
||||
let parts: Vec<_> = parts.into();
|
||||
let (key, value) = parts.first().ok_or(ResponseParserError::UnexpectedEOF)?;
|
||||
debug_assert!(key == &"Id");
|
||||
let value = match value {
|
||||
GenericResponseValue::Text(value) => value,
|
||||
GenericResponseValue::Binary(_) => {
|
||||
return Err(ResponseParserError::UnexpectedPropertyType("Id", "Binary"))
|
||||
}
|
||||
};
|
||||
let id = value
|
||||
.parse()
|
||||
.map_err(|_| ResponseParserError::InvalidProperty("Id", value.to_owned()))?;
|
||||
let mut iter = parts.into_iter();
|
||||
let (key, id) = get_next_and_parse_property!(iter, Text);
|
||||
debug_assert!(key == "Id");
|
||||
Ok(AddIdResponse { id })
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user