Files
empidee/src/commands/queue/plchangesposid.rs
h7x4 afa690366f
All checks were successful
Build and test / check (push) Successful in 1m2s
Build and test / build (push) Successful in 1m9s
Build and test / docs (push) Successful in 1m25s
Build and test / test (push) Successful in 1m38s
commands: use new error variants for a few more commands
2025-12-08 17:40:07 +09:00

99 lines
3.0 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(Self::missing_arguments_error(0))?;
let version = version
.parse()
.map_err(|_| RequestParserError::SubtypeParserError {
argument_index: 0,
expected_type: "PlaylistVersion".to_string(),
raw_input: version.to_string(),
})?;
let window = parts
.next()
.map(|w| {
w.parse()
.map_err(|_| RequestParserError::SubtypeParserError {
argument_index: 1,
expected_type: "WindowRange".to_string(),
raw_input: 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;
}