35 lines
991 B
Rust
35 lines
991 B
Rust
use std::collections::HashMap;
|
|
|
|
use crate::{
|
|
commands::{Command, Request, RequestParserResult, ResponseParserError},
|
|
common::VolumeValue,
|
|
request_tokenizer::RequestTokenizer,
|
|
response_tokenizer::{ResponseAttributes, get_and_parse_property},
|
|
};
|
|
|
|
pub struct GetVol;
|
|
|
|
impl Command for GetVol {
|
|
type Request = ();
|
|
type Response = VolumeValue;
|
|
const COMMAND: &'static str = "getvol";
|
|
|
|
fn serialize_request(&self, _request: Self::Request) -> String {
|
|
Self::COMMAND.to_string()
|
|
}
|
|
|
|
fn parse_request(mut parts: RequestTokenizer<'_>) -> RequestParserResult<'_> {
|
|
debug_assert!(parts.next().is_none());
|
|
Ok((Request::GetVol, ""))
|
|
}
|
|
|
|
fn parse_response(
|
|
parts: ResponseAttributes<'_>,
|
|
) -> Result<Self::Response, ResponseParserError<'_>> {
|
|
let parts: HashMap<_, _> = parts.into();
|
|
assert_eq!(parts.len(), 1);
|
|
let volume = get_and_parse_property!(parts, "volume", Text);
|
|
Ok(volume)
|
|
}
|
|
}
|