commands: use different datastructure for response attrs

This commit is contained in:
Oystein Kristoffer Tveit 2024-11-30 02:18:06 +01:00
parent 472be6c083
commit 84f061a79f
Signed by: oysteikt
GPG Key ID: 9F2F7D8250F35146
37 changed files with 157 additions and 179 deletions

View File

@ -38,11 +38,12 @@ pub trait Command {
// TODO: Replace the HashMap datastructure with something that allows keeping // TODO: Replace the HashMap datastructure with something that allows keeping
// duplicate keys and order of insertion // duplicate keys and order of insertion
fn parse_response<'a>( fn parse_response(
parts: HashMap<&'a str, GenericResponseValue<'a>>, parts: ResponseAttributes<'_>,
) -> Result<Self::Response, ResponseParserError<'a>>; ) -> Result<Self::Response, ResponseParserError<'_>>;
fn parse_raw_response(raw: &str) -> 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 parts = HashMap::new();
let mut lines = raw.lines(); let mut lines = raw.lines();
loop { loop {
@ -67,7 +68,7 @@ pub trait Command {
parts.insert(key, GenericResponseValue::Text(value)); 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> { pub enum GenericResponseValue<'a> {
Text(&'a str), Text(&'a str),
Binary(&'a [u8]), 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 { macro_rules! get_property {
($parts:expr, $name:literal, $variant:ident) => { ($parts:expr, $name:literal, $variant:ident) => {
match $parts.get($name) { match $parts.get($name) {
@ -112,7 +144,6 @@ macro_rules! get_property {
let actual_type = match value { let actual_type = match value {
GenericResponseValue::Text(_) => "Text", GenericResponseValue::Text(_) => "Text",
GenericResponseValue::Binary(_) => "Binary", GenericResponseValue::Binary(_) => "Binary",
GenericResponseValue::Many(_) => "Many",
}; };
return Err(ResponseParserError::UnexpectedPropertyType( return Err(ResponseParserError::UnexpectedPropertyType(
$name, $name,
@ -132,7 +163,6 @@ macro_rules! get_optional_property {
let actual_type = match value { let actual_type = match value {
GenericResponseValue::Text(_) => "Text", GenericResponseValue::Text(_) => "Text",
GenericResponseValue::Binary(_) => "Binary", GenericResponseValue::Binary(_) => "Binary",
GenericResponseValue::Many(_) => "Many",
}; };
return Err(ResponseParserError::UnexpectedPropertyType( return Err(ResponseParserError::UnexpectedPropertyType(
$name, $name,
@ -154,7 +184,6 @@ macro_rules! get_and_parse_property {
let actual_type = match value { let actual_type = match value {
GenericResponseValue::Text(_) => "Text", GenericResponseValue::Text(_) => "Text",
GenericResponseValue::Binary(_) => "Binary", GenericResponseValue::Binary(_) => "Binary",
GenericResponseValue::Many(_) => "Many",
}; };
return Err(ResponseParserError::UnexpectedPropertyType( return Err(ResponseParserError::UnexpectedPropertyType(
$name, $name,
@ -178,7 +207,6 @@ macro_rules! get_and_parse_optional_property {
let actual_type = match value { let actual_type = match value {
GenericResponseValue::Text(_) => "Text", GenericResponseValue::Text(_) => "Text",
GenericResponseValue::Binary(_) => "Binary", GenericResponseValue::Binary(_) => "Binary",
GenericResponseValue::Many(_) => "Many",
}; };
return Err(ResponseParserError::UnexpectedPropertyType( return Err(ResponseParserError::UnexpectedPropertyType(
$name, $name,

View File

@ -1,7 +1,5 @@
use std::collections::HashMap;
use crate::commands::{ use crate::commands::{
Command, GenericResponseValue, Request, RequestParserError, RequestParserResult, Command, Request, RequestParserError, RequestParserResult, ResponseAttributes,
ResponseParserError, ResponseParserError,
}; };
@ -19,9 +17,9 @@ impl Command for DisableOutput {
Ok((Request::DisableOutput(output_id.to_string()), "")) Ok((Request::DisableOutput(output_id.to_string()), ""))
} }
fn parse_response<'a>( fn parse_response(
parts: HashMap<&'a str, GenericResponseValue<'a>>, parts: ResponseAttributes<'_>,
) -> Result<Self::Response, ResponseParserError> { ) -> Result<Self::Response, ResponseParserError<'_>> {
debug_assert!(parts.is_empty()); debug_assert!(parts.is_empty());
Ok(()) Ok(())
} }

View File

@ -1,7 +1,5 @@
use std::collections::HashMap;
use crate::commands::{ use crate::commands::{
Command, GenericResponseValue, Request, RequestParserError, RequestParserResult, Command, Request, RequestParserError, RequestParserResult, ResponseAttributes,
ResponseParserError, ResponseParserError,
}; };
@ -19,8 +17,8 @@ impl Command for EnableOutput {
Ok((Request::EnableOutput(output_id.to_string()), "")) Ok((Request::EnableOutput(output_id.to_string()), ""))
} }
fn parse_response<'a>( fn parse_response(
parts: HashMap<&'a str, GenericResponseValue<'a>>, parts: ResponseAttributes<'_>,
) -> Result<Self::Response, ResponseParserError> { ) -> Result<Self::Response, ResponseParserError> {
debug_assert!(parts.is_empty()); debug_assert!(parts.is_empty());
Ok(()) Ok(())

View File

@ -1,7 +1,7 @@
use std::collections::HashMap; use std::collections::HashMap;
use crate::commands::{ use crate::commands::{
Command, GenericResponseValue, Request, RequestParserResult, ResponseParserError, Command, Request, RequestParserResult, ResponseAttributes, ResponseParserError,
}; };
pub struct Outputs; pub struct Outputs;
@ -26,8 +26,8 @@ impl Command for Outputs {
Ok((Request::Outputs, "")) Ok((Request::Outputs, ""))
} }
fn parse_response<'a>( fn parse_response(
parts: HashMap<&'a str, GenericResponseValue<'a>>, parts: ResponseAttributes<'_>,
) -> Result<Self::Response, ResponseParserError> { ) -> Result<Self::Response, ResponseParserError> {
todo!() todo!()
// debug_assert!(parts.is_empty()); // debug_assert!(parts.is_empty());

View File

@ -1,7 +1,5 @@
use std::collections::HashMap;
use crate::commands::{ use crate::commands::{
Command, GenericResponseValue, Request, RequestParserError, RequestParserResult, Command, Request, RequestParserError, RequestParserResult, ResponseAttributes,
ResponseParserError, ResponseParserError,
}; };
@ -28,8 +26,8 @@ impl Command for OutputSet {
)) ))
} }
fn parse_response<'a>( fn parse_response(
parts: HashMap<&'a str, GenericResponseValue<'a>>, parts: ResponseAttributes<'_>,
) -> Result<Self::Response, ResponseParserError> { ) -> Result<Self::Response, ResponseParserError> {
debug_assert!(parts.is_empty()); debug_assert!(parts.is_empty());
Ok(()) Ok(())

View File

@ -1,7 +1,5 @@
use std::collections::HashMap;
use crate::commands::{ use crate::commands::{
Command, GenericResponseValue, Request, RequestParserError, RequestParserResult, Command, Request, RequestParserError, RequestParserResult, ResponseAttributes,
ResponseParserError, ResponseParserError,
}; };
@ -19,8 +17,8 @@ impl Command for ToggleOutput {
Ok((Request::ToggleOutput(output_id.to_string()), "")) Ok((Request::ToggleOutput(output_id.to_string()), ""))
} }
fn parse_response<'a>( fn parse_response(
parts: HashMap<&'a str, GenericResponseValue<'a>>, parts: ResponseAttributes<'_>,
) -> Result<Self::Response, ResponseParserError> { ) -> Result<Self::Response, ResponseParserError> {
debug_assert!(parts.is_empty()); debug_assert!(parts.is_empty());
Ok(()) Ok(())

View File

@ -1,7 +1,5 @@
use std::collections::HashMap;
use crate::commands::{ use crate::commands::{
Command, GenericResponseValue, Request, RequestParserResult, ResponseParserError, Command, Request, RequestParserResult, ResponseAttributes, ResponseParserError,
}; };
pub struct Channels; pub struct Channels;
@ -21,8 +19,8 @@ impl Command for Channels {
Ok((Request::Channels, "")) Ok((Request::Channels, ""))
} }
fn parse_response<'a>( fn parse_response(
parts: HashMap<&'a str, GenericResponseValue<'a>>, parts: ResponseAttributes<'_>,
) -> Result<Self::Response, ResponseParserError> { ) -> Result<Self::Response, ResponseParserError> {
todo!() todo!()
// let channels = parts // let channels = parts

View File

@ -1,7 +1,5 @@
use std::collections::HashMap;
use crate::commands::{ use crate::commands::{
Command, GenericResponseValue, Request, RequestParserResult, ResponseParserError, Command, Request, RequestParserResult, ResponseAttributes, ResponseParserError,
}; };
pub struct ReadMessages; pub struct ReadMessages;
@ -21,8 +19,8 @@ impl Command for ReadMessages {
Ok((Request::ReadMessages, "")) Ok((Request::ReadMessages, ""))
} }
fn parse_response<'a>( fn parse_response(
parts: HashMap<&'a str, GenericResponseValue<'a>>, parts: ResponseAttributes<'_>,
) -> Result<Self::Response, ResponseParserError> { ) -> Result<Self::Response, ResponseParserError> {
todo!() todo!()
} }

View File

@ -1,7 +1,5 @@
use std::collections::HashMap;
use crate::commands::{ use crate::commands::{
Command, GenericResponseValue, Request, RequestParserError, RequestParserResult, Command, Request, RequestParserError, RequestParserResult, ResponseAttributes,
ResponseParserError, ResponseParserError,
}; };
@ -22,8 +20,8 @@ impl Command for SendMessage {
Ok((Request::SendMessage(channel.to_string(), message), "")) Ok((Request::SendMessage(channel.to_string(), message), ""))
} }
fn parse_response<'a>( fn parse_response(
parts: HashMap<&'a str, GenericResponseValue<'a>>, parts: ResponseAttributes<'_>,
) -> Result<Self::Response, ResponseParserError> { ) -> Result<Self::Response, ResponseParserError> {
debug_assert!(parts.is_empty()); debug_assert!(parts.is_empty());
Ok(()) Ok(())

View File

@ -1,7 +1,5 @@
use std::collections::HashMap;
use crate::commands::{ use crate::commands::{
Command, GenericResponseValue, Request, RequestParserError, RequestParserResult, Command, Request, RequestParserError, RequestParserResult, ResponseAttributes,
ResponseParserError, ResponseParserError,
}; };
@ -19,8 +17,8 @@ impl Command for Subscribe {
Ok((Request::Subscribe(channel_name.to_string()), "")) Ok((Request::Subscribe(channel_name.to_string()), ""))
} }
fn parse_response<'a>( fn parse_response(
parts: HashMap<&'a str, GenericResponseValue<'a>>, parts: ResponseAttributes<'_>,
) -> Result<Self::Response, ResponseParserError> { ) -> Result<Self::Response, ResponseParserError> {
debug_assert!(parts.is_empty()); debug_assert!(parts.is_empty());
Ok(()) Ok(())

View File

@ -1,7 +1,5 @@
use std::collections::HashMap;
use crate::commands::{ use crate::commands::{
Command, GenericResponseValue, Request, RequestParserError, RequestParserResult, Command, Request, RequestParserError, RequestParserResult, ResponseAttributes,
ResponseParserError, ResponseParserError,
}; };
@ -19,8 +17,8 @@ impl Command for Unsubscribe {
Ok((Request::Unsubscribe(channel_name.to_string()), "")) Ok((Request::Unsubscribe(channel_name.to_string()), ""))
} }
fn parse_response<'a>( fn parse_response(
parts: HashMap<&'a str, GenericResponseValue<'a>>, parts: ResponseAttributes<'_>,
) -> Result<Self::Response, ResponseParserError> { ) -> Result<Self::Response, ResponseParserError> {
debug_assert!(parts.is_empty()); debug_assert!(parts.is_empty());
Ok(()) Ok(())

View File

@ -1,7 +1,5 @@
use std::collections::HashMap;
use crate::commands::{ use crate::commands::{
Command, GenericResponseValue, Request, RequestParserResult, ResponseParserError, Command, Request, RequestParserResult, ResponseAttributes, ResponseParserError,
}; };
pub struct Next; pub struct Next;
@ -15,8 +13,8 @@ impl Command for Next {
Ok((Request::Next, "")) Ok((Request::Next, ""))
} }
fn parse_response<'a>( fn parse_response(
parts: HashMap<&'a str, GenericResponseValue<'a>>, parts: ResponseAttributes<'_>,
) -> Result<Self::Response, ResponseParserError> { ) -> Result<Self::Response, ResponseParserError> {
debug_assert!(parts.is_empty()); debug_assert!(parts.is_empty());
Ok(()) Ok(())

View File

@ -1,7 +1,5 @@
use std::collections::HashMap;
use crate::commands::{ use crate::commands::{
Command, GenericResponseValue, Request, RequestParserError, RequestParserResult, Command, Request, RequestParserError, RequestParserResult, ResponseAttributes,
ResponseParserError, ResponseParserError,
}; };
@ -20,8 +18,8 @@ impl Command for Pause {
} }
} }
fn parse_response<'a>( fn parse_response(
parts: HashMap<&'a str, GenericResponseValue<'a>>, parts: ResponseAttributes<'_>,
) -> Result<Self::Response, ResponseParserError> { ) -> Result<Self::Response, ResponseParserError> {
debug_assert!(parts.is_empty()); debug_assert!(parts.is_empty());
Ok(()) Ok(())

View File

@ -1,8 +1,6 @@
use std::collections::HashMap;
use crate::{ use crate::{
commands::{ commands::{
Command, GenericResponseValue, Request, RequestParserError, RequestParserResult, Command, Request, RequestParserError, RequestParserResult, ResponseAttributes,
ResponseParserError, ResponseParserError,
}, },
common::SongPosition, common::SongPosition,
@ -27,8 +25,8 @@ impl Command for Play {
Ok((Request::Play(songpos), "")) Ok((Request::Play(songpos), ""))
} }
fn parse_response<'a>( fn parse_response(
parts: HashMap<&'a str, GenericResponseValue<'a>>, parts: ResponseAttributes<'_>,
) -> Result<Self::Response, ResponseParserError> { ) -> Result<Self::Response, ResponseParserError> {
debug_assert!(parts.is_empty()); debug_assert!(parts.is_empty());
Ok(()) Ok(())

View File

@ -1,8 +1,6 @@
use std::collections::HashMap;
use crate::{ use crate::{
commands::{ commands::{
Command, GenericResponseValue, Request, RequestParserError, RequestParserResult, Command, Request, RequestParserError, RequestParserResult, ResponseAttributes,
ResponseParserError, ResponseParserError,
}, },
common::SongId, common::SongId,
@ -27,8 +25,8 @@ impl Command for PlayId {
Ok((Request::PlayId(songid), "")) Ok((Request::PlayId(songid), ""))
} }
fn parse_response<'a>( fn parse_response(
parts: HashMap<&'a str, GenericResponseValue<'a>>, parts: ResponseAttributes<'_>,
) -> Result<Self::Response, ResponseParserError> { ) -> Result<Self::Response, ResponseParserError> {
debug_assert!(parts.is_empty()); debug_assert!(parts.is_empty());
Ok(()) Ok(())

View File

@ -1,7 +1,5 @@
use std::collections::HashMap;
use crate::commands::{ use crate::commands::{
Command, GenericResponseValue, Request, RequestParserResult, ResponseParserError, Command, Request, RequestParserResult, ResponseAttributes, ResponseParserError,
}; };
pub struct Previous; pub struct Previous;
@ -15,8 +13,8 @@ impl Command for Previous {
Ok((Request::Previous, "")) Ok((Request::Previous, ""))
} }
fn parse_response<'a>( fn parse_response(
parts: HashMap<&'a str, GenericResponseValue<'a>>, parts: ResponseAttributes<'_>,
) -> Result<Self::Response, ResponseParserError> { ) -> Result<Self::Response, ResponseParserError> {
debug_assert!(parts.is_empty()); debug_assert!(parts.is_empty());
Ok(()) Ok(())

View File

@ -1,8 +1,6 @@
use std::collections::HashMap;
use crate::{ use crate::{
commands::{ commands::{
Command, GenericResponseValue, Request, RequestParserError, RequestParserResult, Command, Request, RequestParserError, RequestParserResult, ResponseAttributes,
ResponseParserError, ResponseParserError,
}, },
common::{SongPosition, TimeWithFractions}, common::{SongPosition, TimeWithFractions},
@ -32,8 +30,8 @@ impl Command for Seek {
Ok((Request::Seek(songpos, time), "")) Ok((Request::Seek(songpos, time), ""))
} }
fn parse_response<'a>( fn parse_response(
parts: HashMap<&'a str, GenericResponseValue<'a>>, parts: ResponseAttributes<'_>,
) -> Result<Self::Response, ResponseParserError> { ) -> Result<Self::Response, ResponseParserError> {
debug_assert!(parts.is_empty()); debug_assert!(parts.is_empty());
Ok(()) Ok(())

View File

@ -1,8 +1,6 @@
use std::collections::HashMap;
use crate::{ use crate::{
commands::{ commands::{
Command, GenericResponseValue, Request, RequestParserError, RequestParserResult, Command, Request, RequestParserError, RequestParserResult, ResponseAttributes,
ResponseParserError, ResponseParserError,
}, },
common::TimeWithFractions, common::TimeWithFractions,
@ -45,8 +43,8 @@ impl Command for SeekCur {
Ok((Request::SeekCur(mode, time), "")) Ok((Request::SeekCur(mode, time), ""))
} }
fn parse_response<'a>( fn parse_response(
parts: HashMap<&'a str, GenericResponseValue<'a>>, parts: ResponseAttributes<'_>,
) -> Result<Self::Response, ResponseParserError> { ) -> Result<Self::Response, ResponseParserError> {
debug_assert!(parts.is_empty()); debug_assert!(parts.is_empty());
Ok(()) Ok(())

View File

@ -1,8 +1,6 @@
use std::collections::HashMap;
use crate::{ use crate::{
commands::{ commands::{
Command, GenericResponseValue, Request, RequestParserError, RequestParserResult, Command, Request, RequestParserError, RequestParserResult, ResponseAttributes,
ResponseParserError, ResponseParserError,
}, },
common::{SongId, TimeWithFractions}, common::{SongId, TimeWithFractions},
@ -32,8 +30,8 @@ impl Command for SeekId {
Ok((Request::SeekId(songid, time), "")) Ok((Request::SeekId(songid, time), ""))
} }
fn parse_response<'a>( fn parse_response(
parts: HashMap<&'a str, GenericResponseValue<'a>>, parts: ResponseAttributes<'_>,
) -> Result<Self::Response, ResponseParserError> { ) -> Result<Self::Response, ResponseParserError> {
debug_assert!(parts.is_empty()); debug_assert!(parts.is_empty());
Ok(()) Ok(())

View File

@ -1,7 +1,5 @@
use std::collections::HashMap;
use crate::commands::{ use crate::commands::{
Command, GenericResponseValue, Request, RequestParserResult, ResponseParserError, Command, Request, RequestParserResult, ResponseAttributes, ResponseParserError,
}; };
pub struct Stop; pub struct Stop;
@ -15,8 +13,8 @@ impl Command for Stop {
Ok((Request::Stop, "")) Ok((Request::Stop, ""))
} }
fn parse_response<'a>( fn parse_response(
parts: HashMap<&'a str, GenericResponseValue<'a>>, parts: ResponseAttributes<'_>,
) -> Result<Self::Response, ResponseParserError> { ) -> Result<Self::Response, ResponseParserError> {
debug_assert!(parts.is_empty()); debug_assert!(parts.is_empty());
Ok(()) Ok(())

View File

@ -1,7 +1,7 @@
use std::{collections::HashMap, str::FromStr}; use std::str::FromStr;
use crate::commands::{ use crate::commands::{
Command, GenericResponseValue, Request, RequestParserError, RequestParserResult, Command, Request, RequestParserError, RequestParserResult, ResponseAttributes,
ResponseParserError, ResponseParserError,
}; };
@ -23,8 +23,8 @@ impl Command for Consume {
Ok((Request::Consume(state), "")) Ok((Request::Consume(state), ""))
} }
fn parse_response<'a>( fn parse_response(
parts: HashMap<&'a str, GenericResponseValue<'a>>, parts: ResponseAttributes<'_>,
) -> Result<Self::Response, ResponseParserError> { ) -> Result<Self::Response, ResponseParserError> {
debug_assert!(parts.is_empty()); debug_assert!(parts.is_empty());
Ok(()) Ok(())

View File

@ -1,8 +1,6 @@
use std::collections::HashMap;
use crate::{ use crate::{
commands::{ commands::{
Command, GenericResponseValue, Request, RequestParserError, RequestParserResult, Command, Request, RequestParserError, RequestParserResult, ResponseAttributes,
ResponseParserError, ResponseParserError,
}, },
common::Seconds, common::Seconds,
@ -27,8 +25,8 @@ impl Command for Crossfade {
Ok((Request::Crossfade(seconds), "")) Ok((Request::Crossfade(seconds), ""))
} }
fn parse_response<'a>( fn parse_response(
parts: HashMap<&'a str, GenericResponseValue<'a>>, parts: ResponseAttributes<'_>,
) -> Result<Self::Response, ResponseParserError> { ) -> Result<Self::Response, ResponseParserError> {
debug_assert!(parts.is_empty()); debug_assert!(parts.is_empty());
Ok(()) Ok(())

View File

@ -1,7 +1,5 @@
use std::collections::HashMap;
use crate::{ use crate::{
commands::{Command, GenericResponseValue, Request, RequestParserResult, ResponseParserError}, commands::{Command, Request, RequestParserResult, ResponseAttributes, ResponseParserError},
request::Volume, request::Volume,
}; };
@ -16,8 +14,8 @@ impl Command for GetVol {
Ok((Request::GetVol, "")) Ok((Request::GetVol, ""))
} }
fn parse_response<'a>( fn parse_response(
parts: HashMap<&'a str, GenericResponseValue<'a>>, parts: ResponseAttributes<'_>,
) -> Result<Self::Response, ResponseParserError> { ) -> Result<Self::Response, ResponseParserError> {
todo!() todo!()
// let volume = get_property!(parts, Volume, "volume"); // let volume = get_property!(parts, Volume, "volume");

View File

@ -1,7 +1,5 @@
use std::collections::HashMap;
use crate::commands::{ use crate::commands::{
Command, GenericResponseValue, Request, RequestParserError, RequestParserResult, Command, Request, RequestParserError, RequestParserResult, ResponseAttributes,
ResponseParserError, ResponseParserError,
}; };
@ -24,8 +22,8 @@ impl Command for MixRampDb {
Ok((Request::MixRampDb(db), "")) Ok((Request::MixRampDb(db), ""))
} }
fn parse_response<'a>( fn parse_response(
parts: HashMap<&'a str, GenericResponseValue<'a>>, parts: ResponseAttributes<'_>,
) -> Result<Self::Response, ResponseParserError> { ) -> Result<Self::Response, ResponseParserError> {
debug_assert!(parts.is_empty()); debug_assert!(parts.is_empty());
Ok(()) Ok(())

View File

@ -1,8 +1,6 @@
use std::collections::HashMap;
use crate::{ use crate::{
commands::{ commands::{
Command, GenericResponseValue, Request, RequestParserError, RequestParserResult, Command, Request, RequestParserError, RequestParserResult, ResponseAttributes,
ResponseParserError, ResponseParserError,
}, },
common::Seconds, common::Seconds,
@ -27,8 +25,8 @@ impl Command for MixRampDelay {
Ok((Request::MixRampDelay(seconds), "")) Ok((Request::MixRampDelay(seconds), ""))
} }
fn parse_response<'a>( fn parse_response(
parts: HashMap<&'a str, GenericResponseValue<'a>>, parts: ResponseAttributes<'_>,
) -> Result<Self::Response, ResponseParserError> { ) -> Result<Self::Response, ResponseParserError> {
debug_assert!(parts.is_empty()); debug_assert!(parts.is_empty());
Ok(()) Ok(())

View File

@ -1,7 +1,5 @@
use std::collections::HashMap;
use crate::commands::{ use crate::commands::{
Command, GenericResponseValue, Request, RequestParserError, RequestParserResult, Command, Request, RequestParserError, RequestParserResult, ResponseAttributes,
ResponseParserError, ResponseParserError,
}; };
@ -24,8 +22,8 @@ impl Command for Random {
Ok((Request::Random(state), "")) Ok((Request::Random(state), ""))
} }
fn parse_response<'a>( fn parse_response(
parts: HashMap<&'a str, GenericResponseValue<'a>>, parts: ResponseAttributes<'_>,
) -> Result<Self::Response, ResponseParserError> { ) -> Result<Self::Response, ResponseParserError> {
debug_assert!(parts.is_empty()); debug_assert!(parts.is_empty());
Ok(()) Ok(())

View File

@ -1,7 +1,5 @@
use std::collections::HashMap;
use crate::commands::{ use crate::commands::{
Command, GenericResponseValue, Request, RequestParserError, RequestParserResult, Command, Request, RequestParserError, RequestParserResult, ResponseAttributes,
ResponseParserError, ResponseParserError,
}; };
@ -24,8 +22,8 @@ impl Command for Repeat {
Ok((Request::Repeat(state), "")) Ok((Request::Repeat(state), ""))
} }
fn parse_response<'a>( fn parse_response(
parts: HashMap<&'a str, GenericResponseValue<'a>>, parts: ResponseAttributes<'_>,
) -> Result<Self::Response, ResponseParserError> { ) -> Result<Self::Response, ResponseParserError> {
debug_assert!(parts.is_empty()); debug_assert!(parts.is_empty());
Ok(()) Ok(())

View File

@ -1,8 +1,8 @@
use std::{collections::HashMap, str::FromStr}; use std::str::FromStr;
use crate::{ use crate::{
commands::{ commands::{
Command, GenericResponseValue, Request, RequestParserError, RequestParserResult, Command, Request, RequestParserError, RequestParserResult, ResponseAttributes,
ResponseParserError, ResponseParserError,
}, },
request::ReplayGainModeMode, request::ReplayGainModeMode,
@ -26,8 +26,8 @@ impl Command for ReplayGainMode {
Ok((Request::ReplayGainMode(mode), "")) Ok((Request::ReplayGainMode(mode), ""))
} }
fn parse_response<'a>( fn parse_response(
parts: HashMap<&'a str, GenericResponseValue<'a>>, parts: ResponseAttributes<'_>,
) -> Result<Self::Response, ResponseParserError> { ) -> Result<Self::Response, ResponseParserError> {
debug_assert!(parts.is_empty()); debug_assert!(parts.is_empty());
Ok(()) Ok(())

View File

@ -3,7 +3,7 @@ use std::{collections::HashMap, str::FromStr};
use crate::{ use crate::{
commands::{ commands::{
get_property, Command, GenericResponseValue, Request, RequestParserResult, get_property, Command, GenericResponseValue, Request, RequestParserResult,
ResponseParserError, ResponseAttributes, ResponseParserError,
}, },
request::ReplayGainModeMode, request::ReplayGainModeMode,
}; };
@ -23,9 +23,10 @@ impl Command for ReplayGainStatus {
Ok((Request::ReplayGainStatus, "")) Ok((Request::ReplayGainStatus, ""))
} }
fn parse_response<'a>( fn parse_response(
parts: HashMap<&'a str, GenericResponseValue<'a>>, parts: ResponseAttributes<'_>,
) -> Result<Self::Response, ResponseParserError> { ) -> Result<Self::Response, ResponseParserError> {
let parts: HashMap<_, _> = parts.into();
let replay_gain_mode = get_property!(parts, "replay_gain_mode", Text); let replay_gain_mode = get_property!(parts, "replay_gain_mode", Text);
Ok(ReplayGainStatusResponse { Ok(ReplayGainStatusResponse {

View File

@ -1,8 +1,8 @@
use std::{collections::HashMap, str::FromStr}; use std::str::FromStr;
use crate::{ use crate::{
commands::{ commands::{
Command, GenericResponseValue, Request, RequestParserError, RequestParserResult, Command, Request, RequestParserError, RequestParserResult, ResponseAttributes,
ResponseParserError, ResponseParserError,
}, },
request::Volume, request::Volume,
@ -27,8 +27,8 @@ impl Command for SetVol {
Ok((Request::SetVol(volume), "")) Ok((Request::SetVol(volume), ""))
} }
fn parse_response<'a>( fn parse_response(
parts: HashMap<&'a str, GenericResponseValue<'a>>, parts: ResponseAttributes<'_>,
) -> Result<Self::Response, ResponseParserError> { ) -> Result<Self::Response, ResponseParserError> {
debug_assert!(parts.is_empty()); debug_assert!(parts.is_empty());
Ok(()) Ok(())

View File

@ -1,7 +1,7 @@
use std::{collections::HashMap, str::FromStr}; use std::str::FromStr;
use crate::commands::{ use crate::commands::{
Command, GenericResponseValue, Request, RequestParserError, RequestParserResult, Command, Request, RequestParserError, RequestParserResult, ResponseAttributes,
ResponseParserError, ResponseParserError,
}; };
@ -23,8 +23,8 @@ impl Command for Single {
Ok((Request::Single(state), "")) Ok((Request::Single(state), ""))
} }
fn parse_response<'a>( fn parse_response(
parts: HashMap<&'a str, GenericResponseValue<'a>>, parts: ResponseAttributes<'_>,
) -> Result<Self::Response, ResponseParserError> { ) -> Result<Self::Response, ResponseParserError> {
debug_assert!(parts.is_empty()); debug_assert!(parts.is_empty());
Ok(()) Ok(())

View File

@ -1,7 +1,7 @@
use std::{collections::HashMap, str::FromStr}; use std::str::FromStr;
use crate::commands::{ use crate::commands::{
Command, GenericResponseValue, Request, RequestParserError, RequestParserResult, Command, Request, RequestParserError, RequestParserResult, ResponseAttributes,
ResponseParserError, ResponseParserError,
}; };
@ -23,8 +23,8 @@ impl Command for Volume {
Ok((Request::Volume(change), "")) Ok((Request::Volume(change), ""))
} }
fn parse_response<'a>( fn parse_response(
parts: HashMap<&'a str, GenericResponseValue<'a>>, parts: ResponseAttributes<'_>,
) -> Result<Self::Response, ResponseParserError> { ) -> Result<Self::Response, ResponseParserError> {
debug_assert!(parts.is_empty()); debug_assert!(parts.is_empty());
Ok(()) Ok(())

View File

@ -1,7 +1,5 @@
use std::collections::HashMap;
use crate::commands::{ use crate::commands::{
Command, GenericResponseValue, Request, RequestParserResult, ResponseParserError, Command, Request, RequestParserResult, ResponseAttributes, ResponseParserError,
}; };
pub struct ClearError; pub struct ClearError;
@ -16,8 +14,8 @@ impl Command for ClearError {
Ok((Request::ClearError, "")) Ok((Request::ClearError, ""))
} }
fn parse_response<'a>( fn parse_response(
parts: HashMap<&'a str, GenericResponseValue<'a>>, parts: ResponseAttributes<'_>,
) -> Result<Self::Response, ResponseParserError> { ) -> Result<Self::Response, ResponseParserError> {
debug_assert!(parts.is_empty()); debug_assert!(parts.is_empty());
Ok(()) Ok(())

View File

@ -1,7 +1,5 @@
use std::collections::HashMap;
use crate::commands::{ use crate::commands::{
Command, GenericResponseValue, Request, RequestParserResult, ResponseParserError, Command, Request, RequestParserResult, ResponseAttributes, ResponseParserError,
}; };
pub struct CurrentSong; pub struct CurrentSong;
@ -18,8 +16,8 @@ impl Command for CurrentSong {
Ok((Request::CurrentSong, "")) Ok((Request::CurrentSong, ""))
} }
fn parse_response<'a>( fn parse_response(
parts: HashMap<&'a str, GenericResponseValue<'a>>, parts: ResponseAttributes<'_>,
) -> Result<Self::Response, ResponseParserError> { ) -> Result<Self::Response, ResponseParserError> {
todo!() todo!()
} }

View File

@ -3,7 +3,7 @@ use std::str::{FromStr, SplitWhitespace};
use crate::common::SubSystem; use crate::common::SubSystem;
use crate::commands::{ use crate::commands::{
Command, GenericResponseValue, Request, RequestParserResult, ResponseParserError, Command, Request, RequestParserResult, ResponseAttributes, ResponseParserError,
}; };
pub struct Idle; pub struct Idle;
@ -24,8 +24,8 @@ impl Command for Idle {
}) })
} }
fn parse_response<'a>( fn parse_response(
parts: std::collections::HashMap<&'a str, GenericResponseValue<'a>>, parts: ResponseAttributes<'_>,
) -> Result<Self::Response, ResponseParserError> { ) -> Result<Self::Response, ResponseParserError> {
debug_assert!(parts.is_empty()); debug_assert!(parts.is_empty());
Ok(()) Ok(())

View File

@ -1,9 +1,7 @@
use std::collections::HashMap;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use crate::commands::{ use crate::commands::{
Command, GenericResponseValue, Request, RequestParserResult, ResponseParserError, Command, Request, RequestParserResult, ResponseAttributes, ResponseParserError,
}; };
pub struct Stats; pub struct Stats;
@ -29,8 +27,8 @@ impl Command for Stats {
Ok((Request::Stats, "")) Ok((Request::Stats, ""))
} }
fn parse_response<'a>( fn parse_response(
parts: HashMap<&'a str, GenericResponseValue<'a>>, parts: ResponseAttributes<'_>,
) -> Result<Self::Response, ResponseParserError> { ) -> Result<Self::Response, ResponseParserError> {
todo!() todo!()
} }

View File

@ -1,3 +1,4 @@
use std::collections::HashMap;
use std::str::FromStr; use std::str::FromStr;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
@ -6,7 +7,8 @@ use crate::common::{Audio, BoolOrOneshot, SongId, SongPosition};
use crate::commands::{ use crate::commands::{
get_and_parse_optional_property, get_and_parse_property, get_optional_property, get_property, 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)] #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
@ -59,9 +61,10 @@ pub struct StatusResponse {
} }
#[inline] #[inline]
fn parse_status_response<'a>( fn parse_status_response(
parts: std::collections::HashMap<&'a str, GenericResponseValue<'a>>, parts: ResponseAttributes<'_>,
) -> Result<StatusResponse, ResponseParserError> { ) -> Result<StatusResponse, ResponseParserError> {
let parts: HashMap<&str, GenericResponseValue> = parts.into();
let partition = get_property!(parts, "partition", Text).to_string(); let partition = get_property!(parts, "partition", Text).to_string();
let volume = match get_property!(parts, "volume", Text) { let volume = match get_property!(parts, "volume", Text) {
@ -163,8 +166,8 @@ impl Command for Status {
Ok((Request::Status, "")) Ok((Request::Status, ""))
} }
fn parse_response<'a>( fn parse_response(
parts: std::collections::HashMap<&'a str, GenericResponseValue<'a>>, parts: ResponseAttributes<'_>,
) -> Result<Self::Response, ResponseParserError> { ) -> Result<Self::Response, ResponseParserError> {
parse_status_response(parts) parse_status_response(parts)
} }