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

57 lines
1.6 KiB
Rust

use serde::{Deserialize, Serialize};
use crate::{
Request,
request_tokenizer::RequestTokenizer,
commands::{
Command, RequestParserError, RequestParserResult, ResponseAttributes, ResponseParserError,
},
common::{SongId, TimeInterval},
};
pub struct RangeId;
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct RangeIdRequest {
songid: SongId,
time_interval: TimeInterval,
}
impl Command for RangeId {
type Request = RangeIdRequest;
type Response = ();
const COMMAND: &'static str = "rangeid";
fn serialize_request(&self, request: Self::Request) -> String {
format!(
"{} {} {}",
Self::COMMAND,
request.songid,
request.time_interval
)
}
fn parse_request(mut parts: RequestTokenizer<'_>) -> RequestParserResult<'_> {
let songid = parts.next().ok_or(RequestParserError::UnexpectedEOF)?;
let songid = songid
.parse()
.map_err(|_| RequestParserError::SyntaxError(0, songid.to_string()))?;
let time_interval = parts.next().ok_or(RequestParserError::UnexpectedEOF)?;
let time_interval = time_interval
.parse()
.map_err(|_| RequestParserError::SyntaxError(0, time_interval.to_string()))?;
debug_assert!(parts.next().is_none());
Ok((Request::RangeId(songid, time_interval), ""))
}
fn parse_response(
parts: ResponseAttributes<'_>,
) -> Result<Self::Response, ResponseParserError<'_>> {
debug_assert!(parts.is_empty());
Ok(())
}
}