commands: use different datastructure for response attrs
This commit is contained in:
parent
472be6c083
commit
84f061a79f
@ -38,11 +38,12 @@ pub trait Command {
|
||||
|
||||
// TODO: Replace the HashMap datastructure with something that allows keeping
|
||||
// duplicate keys and order of insertion
|
||||
fn parse_response<'a>(
|
||||
parts: HashMap<&'a str, GenericResponseValue<'a>>,
|
||||
) -> Result<Self::Response, ResponseParserError<'a>>;
|
||||
fn parse_response(
|
||||
parts: ResponseAttributes<'_>,
|
||||
) -> Result<Self::Response, ResponseParserError<'_>>;
|
||||
|
||||
fn parse_raw_response(raw: &str) -> Result<Self::Response, ResponseParserError<'_>> {
|
||||
// TODO: Fix the implementation to use ResponseAttributes natively
|
||||
let mut parts = HashMap::new();
|
||||
let mut lines = raw.lines();
|
||||
loop {
|
||||
@ -67,7 +68,7 @@ pub trait Command {
|
||||
parts.insert(key, GenericResponseValue::Text(value));
|
||||
}
|
||||
|
||||
Self::parse_response(parts)
|
||||
Self::parse_response(parts.into())
|
||||
}
|
||||
}
|
||||
|
||||
@ -101,9 +102,40 @@ pub type GenericResponse<'a> = HashMap<&'a str, GenericResponseValue<'a>>;
|
||||
pub enum GenericResponseValue<'a> {
|
||||
Text(&'a str),
|
||||
Binary(&'a [u8]),
|
||||
Many(Vec<GenericResponseValue<'a>>),
|
||||
// Many(Vec<GenericResponseValue<'a>>),
|
||||
}
|
||||
|
||||
pub struct ResponseAttributes<'a>(Vec<(&'a str, GenericResponseValue<'a>)>);
|
||||
|
||||
// impl ResponseAttributes<'_> {
|
||||
// pub fn
|
||||
// pub fn get<'a>(&self, key: &str) -> Option<&GenericResponseValue<'a>> {
|
||||
// self.0.iter().find_map(|(k, v)| if k == &key { Some(v) } else { None })
|
||||
// }
|
||||
// }
|
||||
|
||||
impl ResponseAttributes<'_> {
|
||||
pub fn is_empty(&self) -> bool {
|
||||
self.0.is_empty()
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> From<HashMap<&'a str, GenericResponseValue<'a>>> for ResponseAttributes<'a> {
|
||||
fn from(map: HashMap<&'a str, GenericResponseValue<'a>>) -> Self {
|
||||
Self(map.into_iter().collect())
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> From<ResponseAttributes<'a>> for HashMap<&'a str, GenericResponseValue<'a>> {
|
||||
fn from(val: ResponseAttributes<'a>) -> Self {
|
||||
val.0.into_iter().collect()
|
||||
}
|
||||
}
|
||||
|
||||
/*******************/
|
||||
/* Parsing Helpers */
|
||||
/*******************/
|
||||
|
||||
macro_rules! get_property {
|
||||
($parts:expr, $name:literal, $variant:ident) => {
|
||||
match $parts.get($name) {
|
||||
@ -112,7 +144,6 @@ macro_rules! get_property {
|
||||
let actual_type = match value {
|
||||
GenericResponseValue::Text(_) => "Text",
|
||||
GenericResponseValue::Binary(_) => "Binary",
|
||||
GenericResponseValue::Many(_) => "Many",
|
||||
};
|
||||
return Err(ResponseParserError::UnexpectedPropertyType(
|
||||
$name,
|
||||
@ -132,7 +163,6 @@ macro_rules! get_optional_property {
|
||||
let actual_type = match value {
|
||||
GenericResponseValue::Text(_) => "Text",
|
||||
GenericResponseValue::Binary(_) => "Binary",
|
||||
GenericResponseValue::Many(_) => "Many",
|
||||
};
|
||||
return Err(ResponseParserError::UnexpectedPropertyType(
|
||||
$name,
|
||||
@ -154,7 +184,6 @@ macro_rules! get_and_parse_property {
|
||||
let actual_type = match value {
|
||||
GenericResponseValue::Text(_) => "Text",
|
||||
GenericResponseValue::Binary(_) => "Binary",
|
||||
GenericResponseValue::Many(_) => "Many",
|
||||
};
|
||||
return Err(ResponseParserError::UnexpectedPropertyType(
|
||||
$name,
|
||||
@ -178,7 +207,6 @@ macro_rules! get_and_parse_optional_property {
|
||||
let actual_type = match value {
|
||||
GenericResponseValue::Text(_) => "Text",
|
||||
GenericResponseValue::Binary(_) => "Binary",
|
||||
GenericResponseValue::Many(_) => "Many",
|
||||
};
|
||||
return Err(ResponseParserError::UnexpectedPropertyType(
|
||||
$name,
|
||||
|
@ -1,7 +1,5 @@
|
||||
use std::collections::HashMap;
|
||||
|
||||
use crate::commands::{
|
||||
Command, GenericResponseValue, Request, RequestParserError, RequestParserResult,
|
||||
Command, Request, RequestParserError, RequestParserResult, ResponseAttributes,
|
||||
ResponseParserError,
|
||||
};
|
||||
|
||||
@ -19,9 +17,9 @@ impl Command for DisableOutput {
|
||||
Ok((Request::DisableOutput(output_id.to_string()), ""))
|
||||
}
|
||||
|
||||
fn parse_response<'a>(
|
||||
parts: HashMap<&'a str, GenericResponseValue<'a>>,
|
||||
) -> Result<Self::Response, ResponseParserError> {
|
||||
fn parse_response(
|
||||
parts: ResponseAttributes<'_>,
|
||||
) -> Result<Self::Response, ResponseParserError<'_>> {
|
||||
debug_assert!(parts.is_empty());
|
||||
Ok(())
|
||||
}
|
||||
|
@ -1,7 +1,5 @@
|
||||
use std::collections::HashMap;
|
||||
|
||||
use crate::commands::{
|
||||
Command, GenericResponseValue, Request, RequestParserError, RequestParserResult,
|
||||
Command, Request, RequestParserError, RequestParserResult, ResponseAttributes,
|
||||
ResponseParserError,
|
||||
};
|
||||
|
||||
@ -19,8 +17,8 @@ impl Command for EnableOutput {
|
||||
Ok((Request::EnableOutput(output_id.to_string()), ""))
|
||||
}
|
||||
|
||||
fn parse_response<'a>(
|
||||
parts: HashMap<&'a str, GenericResponseValue<'a>>,
|
||||
fn parse_response(
|
||||
parts: ResponseAttributes<'_>,
|
||||
) -> Result<Self::Response, ResponseParserError> {
|
||||
debug_assert!(parts.is_empty());
|
||||
Ok(())
|
||||
|
@ -1,7 +1,7 @@
|
||||
use std::collections::HashMap;
|
||||
|
||||
use crate::commands::{
|
||||
Command, GenericResponseValue, Request, RequestParserResult, ResponseParserError,
|
||||
Command, Request, RequestParserResult, ResponseAttributes, ResponseParserError,
|
||||
};
|
||||
|
||||
pub struct Outputs;
|
||||
@ -26,8 +26,8 @@ impl Command for Outputs {
|
||||
Ok((Request::Outputs, ""))
|
||||
}
|
||||
|
||||
fn parse_response<'a>(
|
||||
parts: HashMap<&'a str, GenericResponseValue<'a>>,
|
||||
fn parse_response(
|
||||
parts: ResponseAttributes<'_>,
|
||||
) -> Result<Self::Response, ResponseParserError> {
|
||||
todo!()
|
||||
// debug_assert!(parts.is_empty());
|
||||
|
@ -1,7 +1,5 @@
|
||||
use std::collections::HashMap;
|
||||
|
||||
use crate::commands::{
|
||||
Command, GenericResponseValue, Request, RequestParserError, RequestParserResult,
|
||||
Command, Request, RequestParserError, RequestParserResult, ResponseAttributes,
|
||||
ResponseParserError,
|
||||
};
|
||||
|
||||
@ -28,8 +26,8 @@ impl Command for OutputSet {
|
||||
))
|
||||
}
|
||||
|
||||
fn parse_response<'a>(
|
||||
parts: HashMap<&'a str, GenericResponseValue<'a>>,
|
||||
fn parse_response(
|
||||
parts: ResponseAttributes<'_>,
|
||||
) -> Result<Self::Response, ResponseParserError> {
|
||||
debug_assert!(parts.is_empty());
|
||||
Ok(())
|
||||
|
@ -1,7 +1,5 @@
|
||||
use std::collections::HashMap;
|
||||
|
||||
use crate::commands::{
|
||||
Command, GenericResponseValue, Request, RequestParserError, RequestParserResult,
|
||||
Command, Request, RequestParserError, RequestParserResult, ResponseAttributes,
|
||||
ResponseParserError,
|
||||
};
|
||||
|
||||
@ -19,8 +17,8 @@ impl Command for ToggleOutput {
|
||||
Ok((Request::ToggleOutput(output_id.to_string()), ""))
|
||||
}
|
||||
|
||||
fn parse_response<'a>(
|
||||
parts: HashMap<&'a str, GenericResponseValue<'a>>,
|
||||
fn parse_response(
|
||||
parts: ResponseAttributes<'_>,
|
||||
) -> Result<Self::Response, ResponseParserError> {
|
||||
debug_assert!(parts.is_empty());
|
||||
Ok(())
|
||||
|
@ -1,7 +1,5 @@
|
||||
use std::collections::HashMap;
|
||||
|
||||
use crate::commands::{
|
||||
Command, GenericResponseValue, Request, RequestParserResult, ResponseParserError,
|
||||
Command, Request, RequestParserResult, ResponseAttributes, ResponseParserError,
|
||||
};
|
||||
|
||||
pub struct Channels;
|
||||
@ -21,8 +19,8 @@ impl Command for Channels {
|
||||
Ok((Request::Channels, ""))
|
||||
}
|
||||
|
||||
fn parse_response<'a>(
|
||||
parts: HashMap<&'a str, GenericResponseValue<'a>>,
|
||||
fn parse_response(
|
||||
parts: ResponseAttributes<'_>,
|
||||
) -> Result<Self::Response, ResponseParserError> {
|
||||
todo!()
|
||||
// let channels = parts
|
||||
|
@ -1,7 +1,5 @@
|
||||
use std::collections::HashMap;
|
||||
|
||||
use crate::commands::{
|
||||
Command, GenericResponseValue, Request, RequestParserResult, ResponseParserError,
|
||||
Command, Request, RequestParserResult, ResponseAttributes, ResponseParserError,
|
||||
};
|
||||
|
||||
pub struct ReadMessages;
|
||||
@ -21,8 +19,8 @@ impl Command for ReadMessages {
|
||||
Ok((Request::ReadMessages, ""))
|
||||
}
|
||||
|
||||
fn parse_response<'a>(
|
||||
parts: HashMap<&'a str, GenericResponseValue<'a>>,
|
||||
fn parse_response(
|
||||
parts: ResponseAttributes<'_>,
|
||||
) -> Result<Self::Response, ResponseParserError> {
|
||||
todo!()
|
||||
}
|
||||
|
@ -1,7 +1,5 @@
|
||||
use std::collections::HashMap;
|
||||
|
||||
use crate::commands::{
|
||||
Command, GenericResponseValue, Request, RequestParserError, RequestParserResult,
|
||||
Command, Request, RequestParserError, RequestParserResult, ResponseAttributes,
|
||||
ResponseParserError,
|
||||
};
|
||||
|
||||
@ -22,8 +20,8 @@ impl Command for SendMessage {
|
||||
Ok((Request::SendMessage(channel.to_string(), message), ""))
|
||||
}
|
||||
|
||||
fn parse_response<'a>(
|
||||
parts: HashMap<&'a str, GenericResponseValue<'a>>,
|
||||
fn parse_response(
|
||||
parts: ResponseAttributes<'_>,
|
||||
) -> Result<Self::Response, ResponseParserError> {
|
||||
debug_assert!(parts.is_empty());
|
||||
Ok(())
|
||||
|
@ -1,7 +1,5 @@
|
||||
use std::collections::HashMap;
|
||||
|
||||
use crate::commands::{
|
||||
Command, GenericResponseValue, Request, RequestParserError, RequestParserResult,
|
||||
Command, Request, RequestParserError, RequestParserResult, ResponseAttributes,
|
||||
ResponseParserError,
|
||||
};
|
||||
|
||||
@ -19,8 +17,8 @@ impl Command for Subscribe {
|
||||
Ok((Request::Subscribe(channel_name.to_string()), ""))
|
||||
}
|
||||
|
||||
fn parse_response<'a>(
|
||||
parts: HashMap<&'a str, GenericResponseValue<'a>>,
|
||||
fn parse_response(
|
||||
parts: ResponseAttributes<'_>,
|
||||
) -> Result<Self::Response, ResponseParserError> {
|
||||
debug_assert!(parts.is_empty());
|
||||
Ok(())
|
||||
|
@ -1,7 +1,5 @@
|
||||
use std::collections::HashMap;
|
||||
|
||||
use crate::commands::{
|
||||
Command, GenericResponseValue, Request, RequestParserError, RequestParserResult,
|
||||
Command, Request, RequestParserError, RequestParserResult, ResponseAttributes,
|
||||
ResponseParserError,
|
||||
};
|
||||
|
||||
@ -19,8 +17,8 @@ impl Command for Unsubscribe {
|
||||
Ok((Request::Unsubscribe(channel_name.to_string()), ""))
|
||||
}
|
||||
|
||||
fn parse_response<'a>(
|
||||
parts: HashMap<&'a str, GenericResponseValue<'a>>,
|
||||
fn parse_response(
|
||||
parts: ResponseAttributes<'_>,
|
||||
) -> Result<Self::Response, ResponseParserError> {
|
||||
debug_assert!(parts.is_empty());
|
||||
Ok(())
|
||||
|
@ -1,7 +1,5 @@
|
||||
use std::collections::HashMap;
|
||||
|
||||
use crate::commands::{
|
||||
Command, GenericResponseValue, Request, RequestParserResult, ResponseParserError,
|
||||
Command, Request, RequestParserResult, ResponseAttributes, ResponseParserError,
|
||||
};
|
||||
|
||||
pub struct Next;
|
||||
@ -15,8 +13,8 @@ impl Command for Next {
|
||||
Ok((Request::Next, ""))
|
||||
}
|
||||
|
||||
fn parse_response<'a>(
|
||||
parts: HashMap<&'a str, GenericResponseValue<'a>>,
|
||||
fn parse_response(
|
||||
parts: ResponseAttributes<'_>,
|
||||
) -> Result<Self::Response, ResponseParserError> {
|
||||
debug_assert!(parts.is_empty());
|
||||
Ok(())
|
||||
|
@ -1,7 +1,5 @@
|
||||
use std::collections::HashMap;
|
||||
|
||||
use crate::commands::{
|
||||
Command, GenericResponseValue, Request, RequestParserError, RequestParserResult,
|
||||
Command, Request, RequestParserError, RequestParserResult, ResponseAttributes,
|
||||
ResponseParserError,
|
||||
};
|
||||
|
||||
@ -20,8 +18,8 @@ impl Command for Pause {
|
||||
}
|
||||
}
|
||||
|
||||
fn parse_response<'a>(
|
||||
parts: HashMap<&'a str, GenericResponseValue<'a>>,
|
||||
fn parse_response(
|
||||
parts: ResponseAttributes<'_>,
|
||||
) -> Result<Self::Response, ResponseParserError> {
|
||||
debug_assert!(parts.is_empty());
|
||||
Ok(())
|
||||
|
@ -1,8 +1,6 @@
|
||||
use std::collections::HashMap;
|
||||
|
||||
use crate::{
|
||||
commands::{
|
||||
Command, GenericResponseValue, Request, RequestParserError, RequestParserResult,
|
||||
Command, Request, RequestParserError, RequestParserResult, ResponseAttributes,
|
||||
ResponseParserError,
|
||||
},
|
||||
common::SongPosition,
|
||||
@ -27,8 +25,8 @@ impl Command for Play {
|
||||
Ok((Request::Play(songpos), ""))
|
||||
}
|
||||
|
||||
fn parse_response<'a>(
|
||||
parts: HashMap<&'a str, GenericResponseValue<'a>>,
|
||||
fn parse_response(
|
||||
parts: ResponseAttributes<'_>,
|
||||
) -> Result<Self::Response, ResponseParserError> {
|
||||
debug_assert!(parts.is_empty());
|
||||
Ok(())
|
||||
|
@ -1,8 +1,6 @@
|
||||
use std::collections::HashMap;
|
||||
|
||||
use crate::{
|
||||
commands::{
|
||||
Command, GenericResponseValue, Request, RequestParserError, RequestParserResult,
|
||||
Command, Request, RequestParserError, RequestParserResult, ResponseAttributes,
|
||||
ResponseParserError,
|
||||
},
|
||||
common::SongId,
|
||||
@ -27,8 +25,8 @@ impl Command for PlayId {
|
||||
Ok((Request::PlayId(songid), ""))
|
||||
}
|
||||
|
||||
fn parse_response<'a>(
|
||||
parts: HashMap<&'a str, GenericResponseValue<'a>>,
|
||||
fn parse_response(
|
||||
parts: ResponseAttributes<'_>,
|
||||
) -> Result<Self::Response, ResponseParserError> {
|
||||
debug_assert!(parts.is_empty());
|
||||
Ok(())
|
||||
|
@ -1,7 +1,5 @@
|
||||
use std::collections::HashMap;
|
||||
|
||||
use crate::commands::{
|
||||
Command, GenericResponseValue, Request, RequestParserResult, ResponseParserError,
|
||||
Command, Request, RequestParserResult, ResponseAttributes, ResponseParserError,
|
||||
};
|
||||
|
||||
pub struct Previous;
|
||||
@ -15,8 +13,8 @@ impl Command for Previous {
|
||||
Ok((Request::Previous, ""))
|
||||
}
|
||||
|
||||
fn parse_response<'a>(
|
||||
parts: HashMap<&'a str, GenericResponseValue<'a>>,
|
||||
fn parse_response(
|
||||
parts: ResponseAttributes<'_>,
|
||||
) -> Result<Self::Response, ResponseParserError> {
|
||||
debug_assert!(parts.is_empty());
|
||||
Ok(())
|
||||
|
@ -1,8 +1,6 @@
|
||||
use std::collections::HashMap;
|
||||
|
||||
use crate::{
|
||||
commands::{
|
||||
Command, GenericResponseValue, Request, RequestParserError, RequestParserResult,
|
||||
Command, Request, RequestParserError, RequestParserResult, ResponseAttributes,
|
||||
ResponseParserError,
|
||||
},
|
||||
common::{SongPosition, TimeWithFractions},
|
||||
@ -32,8 +30,8 @@ impl Command for Seek {
|
||||
Ok((Request::Seek(songpos, time), ""))
|
||||
}
|
||||
|
||||
fn parse_response<'a>(
|
||||
parts: HashMap<&'a str, GenericResponseValue<'a>>,
|
||||
fn parse_response(
|
||||
parts: ResponseAttributes<'_>,
|
||||
) -> Result<Self::Response, ResponseParserError> {
|
||||
debug_assert!(parts.is_empty());
|
||||
Ok(())
|
||||
|
@ -1,8 +1,6 @@
|
||||
use std::collections::HashMap;
|
||||
|
||||
use crate::{
|
||||
commands::{
|
||||
Command, GenericResponseValue, Request, RequestParserError, RequestParserResult,
|
||||
Command, Request, RequestParserError, RequestParserResult, ResponseAttributes,
|
||||
ResponseParserError,
|
||||
},
|
||||
common::TimeWithFractions,
|
||||
@ -45,8 +43,8 @@ impl Command for SeekCur {
|
||||
Ok((Request::SeekCur(mode, time), ""))
|
||||
}
|
||||
|
||||
fn parse_response<'a>(
|
||||
parts: HashMap<&'a str, GenericResponseValue<'a>>,
|
||||
fn parse_response(
|
||||
parts: ResponseAttributes<'_>,
|
||||
) -> Result<Self::Response, ResponseParserError> {
|
||||
debug_assert!(parts.is_empty());
|
||||
Ok(())
|
||||
|
@ -1,8 +1,6 @@
|
||||
use std::collections::HashMap;
|
||||
|
||||
use crate::{
|
||||
commands::{
|
||||
Command, GenericResponseValue, Request, RequestParserError, RequestParserResult,
|
||||
Command, Request, RequestParserError, RequestParserResult, ResponseAttributes,
|
||||
ResponseParserError,
|
||||
},
|
||||
common::{SongId, TimeWithFractions},
|
||||
@ -32,8 +30,8 @@ impl Command for SeekId {
|
||||
Ok((Request::SeekId(songid, time), ""))
|
||||
}
|
||||
|
||||
fn parse_response<'a>(
|
||||
parts: HashMap<&'a str, GenericResponseValue<'a>>,
|
||||
fn parse_response(
|
||||
parts: ResponseAttributes<'_>,
|
||||
) -> Result<Self::Response, ResponseParserError> {
|
||||
debug_assert!(parts.is_empty());
|
||||
Ok(())
|
||||
|
@ -1,7 +1,5 @@
|
||||
use std::collections::HashMap;
|
||||
|
||||
use crate::commands::{
|
||||
Command, GenericResponseValue, Request, RequestParserResult, ResponseParserError,
|
||||
Command, Request, RequestParserResult, ResponseAttributes, ResponseParserError,
|
||||
};
|
||||
|
||||
pub struct Stop;
|
||||
@ -15,8 +13,8 @@ impl Command for Stop {
|
||||
Ok((Request::Stop, ""))
|
||||
}
|
||||
|
||||
fn parse_response<'a>(
|
||||
parts: HashMap<&'a str, GenericResponseValue<'a>>,
|
||||
fn parse_response(
|
||||
parts: ResponseAttributes<'_>,
|
||||
) -> Result<Self::Response, ResponseParserError> {
|
||||
debug_assert!(parts.is_empty());
|
||||
Ok(())
|
||||
|
@ -1,7 +1,7 @@
|
||||
use std::{collections::HashMap, str::FromStr};
|
||||
use std::str::FromStr;
|
||||
|
||||
use crate::commands::{
|
||||
Command, GenericResponseValue, Request, RequestParserError, RequestParserResult,
|
||||
Command, Request, RequestParserError, RequestParserResult, ResponseAttributes,
|
||||
ResponseParserError,
|
||||
};
|
||||
|
||||
@ -23,8 +23,8 @@ impl Command for Consume {
|
||||
Ok((Request::Consume(state), ""))
|
||||
}
|
||||
|
||||
fn parse_response<'a>(
|
||||
parts: HashMap<&'a str, GenericResponseValue<'a>>,
|
||||
fn parse_response(
|
||||
parts: ResponseAttributes<'_>,
|
||||
) -> Result<Self::Response, ResponseParserError> {
|
||||
debug_assert!(parts.is_empty());
|
||||
Ok(())
|
||||
|
@ -1,8 +1,6 @@
|
||||
use std::collections::HashMap;
|
||||
|
||||
use crate::{
|
||||
commands::{
|
||||
Command, GenericResponseValue, Request, RequestParserError, RequestParserResult,
|
||||
Command, Request, RequestParserError, RequestParserResult, ResponseAttributes,
|
||||
ResponseParserError,
|
||||
},
|
||||
common::Seconds,
|
||||
@ -27,8 +25,8 @@ impl Command for Crossfade {
|
||||
Ok((Request::Crossfade(seconds), ""))
|
||||
}
|
||||
|
||||
fn parse_response<'a>(
|
||||
parts: HashMap<&'a str, GenericResponseValue<'a>>,
|
||||
fn parse_response(
|
||||
parts: ResponseAttributes<'_>,
|
||||
) -> Result<Self::Response, ResponseParserError> {
|
||||
debug_assert!(parts.is_empty());
|
||||
Ok(())
|
||||
|
@ -1,7 +1,5 @@
|
||||
use std::collections::HashMap;
|
||||
|
||||
use crate::{
|
||||
commands::{Command, GenericResponseValue, Request, RequestParserResult, ResponseParserError},
|
||||
commands::{Command, Request, RequestParserResult, ResponseAttributes, ResponseParserError},
|
||||
request::Volume,
|
||||
};
|
||||
|
||||
@ -16,8 +14,8 @@ impl Command for GetVol {
|
||||
Ok((Request::GetVol, ""))
|
||||
}
|
||||
|
||||
fn parse_response<'a>(
|
||||
parts: HashMap<&'a str, GenericResponseValue<'a>>,
|
||||
fn parse_response(
|
||||
parts: ResponseAttributes<'_>,
|
||||
) -> Result<Self::Response, ResponseParserError> {
|
||||
todo!()
|
||||
// let volume = get_property!(parts, Volume, "volume");
|
||||
|
@ -1,7 +1,5 @@
|
||||
use std::collections::HashMap;
|
||||
|
||||
use crate::commands::{
|
||||
Command, GenericResponseValue, Request, RequestParserError, RequestParserResult,
|
||||
Command, Request, RequestParserError, RequestParserResult, ResponseAttributes,
|
||||
ResponseParserError,
|
||||
};
|
||||
|
||||
@ -24,8 +22,8 @@ impl Command for MixRampDb {
|
||||
Ok((Request::MixRampDb(db), ""))
|
||||
}
|
||||
|
||||
fn parse_response<'a>(
|
||||
parts: HashMap<&'a str, GenericResponseValue<'a>>,
|
||||
fn parse_response(
|
||||
parts: ResponseAttributes<'_>,
|
||||
) -> Result<Self::Response, ResponseParserError> {
|
||||
debug_assert!(parts.is_empty());
|
||||
Ok(())
|
||||
|
@ -1,8 +1,6 @@
|
||||
use std::collections::HashMap;
|
||||
|
||||
use crate::{
|
||||
commands::{
|
||||
Command, GenericResponseValue, Request, RequestParserError, RequestParserResult,
|
||||
Command, Request, RequestParserError, RequestParserResult, ResponseAttributes,
|
||||
ResponseParserError,
|
||||
},
|
||||
common::Seconds,
|
||||
@ -27,8 +25,8 @@ impl Command for MixRampDelay {
|
||||
Ok((Request::MixRampDelay(seconds), ""))
|
||||
}
|
||||
|
||||
fn parse_response<'a>(
|
||||
parts: HashMap<&'a str, GenericResponseValue<'a>>,
|
||||
fn parse_response(
|
||||
parts: ResponseAttributes<'_>,
|
||||
) -> Result<Self::Response, ResponseParserError> {
|
||||
debug_assert!(parts.is_empty());
|
||||
Ok(())
|
||||
|
@ -1,7 +1,5 @@
|
||||
use std::collections::HashMap;
|
||||
|
||||
use crate::commands::{
|
||||
Command, GenericResponseValue, Request, RequestParserError, RequestParserResult,
|
||||
Command, Request, RequestParserError, RequestParserResult, ResponseAttributes,
|
||||
ResponseParserError,
|
||||
};
|
||||
|
||||
@ -24,8 +22,8 @@ impl Command for Random {
|
||||
Ok((Request::Random(state), ""))
|
||||
}
|
||||
|
||||
fn parse_response<'a>(
|
||||
parts: HashMap<&'a str, GenericResponseValue<'a>>,
|
||||
fn parse_response(
|
||||
parts: ResponseAttributes<'_>,
|
||||
) -> Result<Self::Response, ResponseParserError> {
|
||||
debug_assert!(parts.is_empty());
|
||||
Ok(())
|
||||
|
@ -1,7 +1,5 @@
|
||||
use std::collections::HashMap;
|
||||
|
||||
use crate::commands::{
|
||||
Command, GenericResponseValue, Request, RequestParserError, RequestParserResult,
|
||||
Command, Request, RequestParserError, RequestParserResult, ResponseAttributes,
|
||||
ResponseParserError,
|
||||
};
|
||||
|
||||
@ -24,8 +22,8 @@ impl Command for Repeat {
|
||||
Ok((Request::Repeat(state), ""))
|
||||
}
|
||||
|
||||
fn parse_response<'a>(
|
||||
parts: HashMap<&'a str, GenericResponseValue<'a>>,
|
||||
fn parse_response(
|
||||
parts: ResponseAttributes<'_>,
|
||||
) -> Result<Self::Response, ResponseParserError> {
|
||||
debug_assert!(parts.is_empty());
|
||||
Ok(())
|
||||
|
@ -1,8 +1,8 @@
|
||||
use std::{collections::HashMap, str::FromStr};
|
||||
use std::str::FromStr;
|
||||
|
||||
use crate::{
|
||||
commands::{
|
||||
Command, GenericResponseValue, Request, RequestParserError, RequestParserResult,
|
||||
Command, Request, RequestParserError, RequestParserResult, ResponseAttributes,
|
||||
ResponseParserError,
|
||||
},
|
||||
request::ReplayGainModeMode,
|
||||
@ -26,8 +26,8 @@ impl Command for ReplayGainMode {
|
||||
Ok((Request::ReplayGainMode(mode), ""))
|
||||
}
|
||||
|
||||
fn parse_response<'a>(
|
||||
parts: HashMap<&'a str, GenericResponseValue<'a>>,
|
||||
fn parse_response(
|
||||
parts: ResponseAttributes<'_>,
|
||||
) -> Result<Self::Response, ResponseParserError> {
|
||||
debug_assert!(parts.is_empty());
|
||||
Ok(())
|
||||
|
@ -3,7 +3,7 @@ use std::{collections::HashMap, str::FromStr};
|
||||
use crate::{
|
||||
commands::{
|
||||
get_property, Command, GenericResponseValue, Request, RequestParserResult,
|
||||
ResponseParserError,
|
||||
ResponseAttributes, ResponseParserError,
|
||||
},
|
||||
request::ReplayGainModeMode,
|
||||
};
|
||||
@ -23,9 +23,10 @@ impl Command for ReplayGainStatus {
|
||||
Ok((Request::ReplayGainStatus, ""))
|
||||
}
|
||||
|
||||
fn parse_response<'a>(
|
||||
parts: HashMap<&'a str, GenericResponseValue<'a>>,
|
||||
fn parse_response(
|
||||
parts: ResponseAttributes<'_>,
|
||||
) -> Result<Self::Response, ResponseParserError> {
|
||||
let parts: HashMap<_, _> = parts.into();
|
||||
let replay_gain_mode = get_property!(parts, "replay_gain_mode", Text);
|
||||
|
||||
Ok(ReplayGainStatusResponse {
|
||||
|
@ -1,8 +1,8 @@
|
||||
use std::{collections::HashMap, str::FromStr};
|
||||
use std::str::FromStr;
|
||||
|
||||
use crate::{
|
||||
commands::{
|
||||
Command, GenericResponseValue, Request, RequestParserError, RequestParserResult,
|
||||
Command, Request, RequestParserError, RequestParserResult, ResponseAttributes,
|
||||
ResponseParserError,
|
||||
},
|
||||
request::Volume,
|
||||
@ -27,8 +27,8 @@ impl Command for SetVol {
|
||||
Ok((Request::SetVol(volume), ""))
|
||||
}
|
||||
|
||||
fn parse_response<'a>(
|
||||
parts: HashMap<&'a str, GenericResponseValue<'a>>,
|
||||
fn parse_response(
|
||||
parts: ResponseAttributes<'_>,
|
||||
) -> Result<Self::Response, ResponseParserError> {
|
||||
debug_assert!(parts.is_empty());
|
||||
Ok(())
|
||||
|
@ -1,7 +1,7 @@
|
||||
use std::{collections::HashMap, str::FromStr};
|
||||
use std::str::FromStr;
|
||||
|
||||
use crate::commands::{
|
||||
Command, GenericResponseValue, Request, RequestParserError, RequestParserResult,
|
||||
Command, Request, RequestParserError, RequestParserResult, ResponseAttributes,
|
||||
ResponseParserError,
|
||||
};
|
||||
|
||||
@ -23,8 +23,8 @@ impl Command for Single {
|
||||
Ok((Request::Single(state), ""))
|
||||
}
|
||||
|
||||
fn parse_response<'a>(
|
||||
parts: HashMap<&'a str, GenericResponseValue<'a>>,
|
||||
fn parse_response(
|
||||
parts: ResponseAttributes<'_>,
|
||||
) -> Result<Self::Response, ResponseParserError> {
|
||||
debug_assert!(parts.is_empty());
|
||||
Ok(())
|
||||
|
@ -1,7 +1,7 @@
|
||||
use std::{collections::HashMap, str::FromStr};
|
||||
use std::str::FromStr;
|
||||
|
||||
use crate::commands::{
|
||||
Command, GenericResponseValue, Request, RequestParserError, RequestParserResult,
|
||||
Command, Request, RequestParserError, RequestParserResult, ResponseAttributes,
|
||||
ResponseParserError,
|
||||
};
|
||||
|
||||
@ -23,8 +23,8 @@ impl Command for Volume {
|
||||
Ok((Request::Volume(change), ""))
|
||||
}
|
||||
|
||||
fn parse_response<'a>(
|
||||
parts: HashMap<&'a str, GenericResponseValue<'a>>,
|
||||
fn parse_response(
|
||||
parts: ResponseAttributes<'_>,
|
||||
) -> Result<Self::Response, ResponseParserError> {
|
||||
debug_assert!(parts.is_empty());
|
||||
Ok(())
|
||||
|
@ -1,7 +1,5 @@
|
||||
use std::collections::HashMap;
|
||||
|
||||
use crate::commands::{
|
||||
Command, GenericResponseValue, Request, RequestParserResult, ResponseParserError,
|
||||
Command, Request, RequestParserResult, ResponseAttributes, ResponseParserError,
|
||||
};
|
||||
|
||||
pub struct ClearError;
|
||||
@ -16,8 +14,8 @@ impl Command for ClearError {
|
||||
Ok((Request::ClearError, ""))
|
||||
}
|
||||
|
||||
fn parse_response<'a>(
|
||||
parts: HashMap<&'a str, GenericResponseValue<'a>>,
|
||||
fn parse_response(
|
||||
parts: ResponseAttributes<'_>,
|
||||
) -> Result<Self::Response, ResponseParserError> {
|
||||
debug_assert!(parts.is_empty());
|
||||
Ok(())
|
||||
|
@ -1,7 +1,5 @@
|
||||
use std::collections::HashMap;
|
||||
|
||||
use crate::commands::{
|
||||
Command, GenericResponseValue, Request, RequestParserResult, ResponseParserError,
|
||||
Command, Request, RequestParserResult, ResponseAttributes, ResponseParserError,
|
||||
};
|
||||
|
||||
pub struct CurrentSong;
|
||||
@ -18,8 +16,8 @@ impl Command for CurrentSong {
|
||||
Ok((Request::CurrentSong, ""))
|
||||
}
|
||||
|
||||
fn parse_response<'a>(
|
||||
parts: HashMap<&'a str, GenericResponseValue<'a>>,
|
||||
fn parse_response(
|
||||
parts: ResponseAttributes<'_>,
|
||||
) -> Result<Self::Response, ResponseParserError> {
|
||||
todo!()
|
||||
}
|
||||
|
@ -3,7 +3,7 @@ use std::str::{FromStr, SplitWhitespace};
|
||||
use crate::common::SubSystem;
|
||||
|
||||
use crate::commands::{
|
||||
Command, GenericResponseValue, Request, RequestParserResult, ResponseParserError,
|
||||
Command, Request, RequestParserResult, ResponseAttributes, ResponseParserError,
|
||||
};
|
||||
|
||||
pub struct Idle;
|
||||
@ -24,8 +24,8 @@ impl Command for Idle {
|
||||
})
|
||||
}
|
||||
|
||||
fn parse_response<'a>(
|
||||
parts: std::collections::HashMap<&'a str, GenericResponseValue<'a>>,
|
||||
fn parse_response(
|
||||
parts: ResponseAttributes<'_>,
|
||||
) -> Result<Self::Response, ResponseParserError> {
|
||||
debug_assert!(parts.is_empty());
|
||||
Ok(())
|
||||
|
@ -1,9 +1,7 @@
|
||||
use std::collections::HashMap;
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::commands::{
|
||||
Command, GenericResponseValue, Request, RequestParserResult, ResponseParserError,
|
||||
Command, Request, RequestParserResult, ResponseAttributes, ResponseParserError,
|
||||
};
|
||||
|
||||
pub struct Stats;
|
||||
@ -29,8 +27,8 @@ impl Command for Stats {
|
||||
Ok((Request::Stats, ""))
|
||||
}
|
||||
|
||||
fn parse_response<'a>(
|
||||
parts: HashMap<&'a str, GenericResponseValue<'a>>,
|
||||
fn parse_response(
|
||||
parts: ResponseAttributes<'_>,
|
||||
) -> Result<Self::Response, ResponseParserError> {
|
||||
todo!()
|
||||
}
|
||||
|
@ -1,3 +1,4 @@
|
||||
use std::collections::HashMap;
|
||||
use std::str::FromStr;
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
@ -6,7 +7,8 @@ use crate::common::{Audio, BoolOrOneshot, SongId, SongPosition};
|
||||
|
||||
use crate::commands::{
|
||||
get_and_parse_optional_property, get_and_parse_property, get_optional_property, get_property,
|
||||
Command, GenericResponseValue, Request, RequestParserResult, ResponseParserError,
|
||||
Command, GenericResponseValue, Request, RequestParserResult, ResponseAttributes,
|
||||
ResponseParserError,
|
||||
};
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||
@ -59,9 +61,10 @@ pub struct StatusResponse {
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn parse_status_response<'a>(
|
||||
parts: std::collections::HashMap<&'a str, GenericResponseValue<'a>>,
|
||||
fn parse_status_response(
|
||||
parts: ResponseAttributes<'_>,
|
||||
) -> Result<StatusResponse, ResponseParserError> {
|
||||
let parts: HashMap<&str, GenericResponseValue> = parts.into();
|
||||
let partition = get_property!(parts, "partition", Text).to_string();
|
||||
|
||||
let volume = match get_property!(parts, "volume", Text) {
|
||||
@ -163,8 +166,8 @@ impl Command for Status {
|
||||
Ok((Request::Status, ""))
|
||||
}
|
||||
|
||||
fn parse_response<'a>(
|
||||
parts: std::collections::HashMap<&'a str, GenericResponseValue<'a>>,
|
||||
fn parse_response(
|
||||
parts: ResponseAttributes<'_>,
|
||||
) -> Result<Self::Response, ResponseParserError> {
|
||||
parse_status_response(parts)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user