Files
empidee/src/commands/queue/plchangesposid.rs
h7x4 3342293bf2
Some checks failed
Build and test / build (push) Failing after 1m1s
Build and test / check (push) Failing after 1m25s
Build and test / test (push) Failing after 1m25s
Build and test / docs (push) Failing after 1m0s
commands: use new error variants for various commands
2025-12-08 15:54:37 +09:00

91 lines
2.6 KiB
Rust

use serde::{Deserialize, Serialize};
use crate::{
commands::{Command, CommandRequest, CommandResponse, RequestParserError, ResponseParserError},
request_tokenizer::RequestTokenizer,
response_tokenizer::ResponseAttributes,
types::{PlaylistVersion, SongId, SongPosition, WindowRange},
};
pub struct PlChangesPosId;
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct PlChangesPosIdRequest {
pub version: PlaylistVersion,
pub window: Option<WindowRange>,
}
impl CommandRequest for PlChangesPosIdRequest {
const COMMAND: &'static str = "plchangesposid";
const MIN_ARGS: u32 = 1;
const MAX_ARGS: Option<u32> = Some(2);
fn into_request_enum(self) -> crate::Request {
crate::Request::PlChangesPosId(self.version, self.window)
}
fn from_request_enum(request: crate::Request) -> Option<Self> {
match request {
crate::Request::PlChangesPosId(version, window) => {
Some(PlChangesPosIdRequest { version, window })
}
_ => None,
}
}
fn serialize(&self) -> String {
match self.window.as_ref() {
Some(window) => format!("{} {} {}\n", Self::COMMAND, self.version, window),
None => format!("{} {}\n", Self::COMMAND, self.version),
}
}
fn parse(mut parts: RequestTokenizer<'_>) -> Result<Self, RequestParserError> {
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()?;
Self::throw_if_too_many_arguments(parts)?;
Ok(PlChangesPosIdRequest { version, window })
}
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct PlChangesPosIdResponse(Vec<PlChangesPosIdResponseEntry>);
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct PlChangesPosIdResponseEntry {
// 'cpos'
pub position: SongPosition,
pub id: SongId,
}
impl CommandResponse for PlChangesPosIdResponse {
fn from_response_enum(response: crate::Response) -> Option<Self> {
todo!()
}
fn into_response_enum(self) -> crate::Response {
todo!()
}
fn parse(parts: ResponseAttributes<'_>) -> Result<Self, ResponseParserError> {
unimplemented!()
}
}
impl Command for PlChangesPosId {
type Request = PlChangesPosIdRequest;
type Response = PlChangesPosIdResponse;
}