Files
empidee/src/commands/playback_options/replay_gain_status.rs
h7x4 1944b5022d
Some checks failed
Build and test / test (push) Failing after 14s
Build and test / docs (push) Has been cancelled
Build and test / build (push) Has been cancelled
Build and test / check (push) Has been cancelled
common/types: move stuff from requests to types
2025-02-23 19:46:28 +01:00

41 lines
1.2 KiB
Rust

use std::{collections::HashMap, str::FromStr};
use serde::{Deserialize, Serialize};
use crate::{
commands::{
get_property, Command, Request, RequestParserResult, ResponseAttributes,
ResponseParserError,
}, common::ReplayGainModeMode,
};
pub struct ReplayGainStatus;
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct ReplayGainStatusResponse {
pub replay_gain_mode: ReplayGainModeMode,
}
impl Command for ReplayGainStatus {
type Response = ReplayGainStatusResponse;
const COMMAND: &'static str = "replay_gain_status";
fn parse_request(mut parts: std::str::SplitWhitespace<'_>) -> RequestParserResult<'_> {
debug_assert!(parts.next().is_none());
Ok((Request::ReplayGainStatus, ""))
}
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 {
replay_gain_mode: ReplayGainModeMode::from_str(replay_gain_mode).map_err(|_| {
ResponseParserError::InvalidProperty("replay_gain_mode", replay_gain_mode)
})?,
})
}
}