Files
empidee/src/commands/queue/plchanges.rs

56 lines
1.6 KiB
Rust

use serde::{Deserialize, Serialize};
use crate::{
Request,
commands::{Command, RequestParserError, RequestParserResult, ResponseParserError},
common::{PlaylistVersion, WindowRange},
request_tokenizer::RequestTokenizer,
response_tokenizer::ResponseAttributes,
};
pub struct PlChanges;
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct PlChangesRequest {
pub version: PlaylistVersion,
pub window: Option<WindowRange>,
}
impl Command for PlChanges {
type Request = PlChangesRequest;
type Response = ();
const COMMAND: &'static str = "plchanges";
fn serialize_request(&self, request: Self::Request) -> String {
match request.window {
Some(window) => format!("{} {} {}", Self::COMMAND, request.version, window),
None => format!("{} {}", Self::COMMAND, request.version),
}
}
fn parse_request(mut parts: RequestTokenizer<'_>) -> RequestParserResult<'_> {
let version = parts.next().ok_or(RequestParserError::UnexpectedEOF)?;
let version = version
.parse()
.map_err(|_| RequestParserError::SyntaxError(0, version.to_string()))?;
let window = parts
.next()
.map(|w| {
w.parse()
.map_err(|_| RequestParserError::SyntaxError(0, w.to_string()))
})
.transpose()?;
debug_assert!(parts.next().is_none());
Ok((Request::PlChanges(version, window), ""))
}
fn parse_response(
parts: ResponseAttributes<'_>,
) -> Result<Self::Response, ResponseParserError<'_>> {
unimplemented!()
}
}