Implement some more commands

This commit is contained in:
2024-11-30 17:12:49 +01:00
parent 8461542735
commit 2ca3cd40bc
31 changed files with 926 additions and 10 deletions
+41
View File
@@ -0,0 +1,41 @@
use crate::{
commands::{
Command, RequestParserError, RequestParserResult, ResponseAttributes, ResponseParserError,
},
Request,
};
pub struct PrioId;
impl Command for PrioId {
type Response = ();
const COMMAND: &'static str = "prioid";
fn parse_request(mut parts: std::str::SplitWhitespace<'_>) -> RequestParserResult<'_> {
let prio = parts.next().ok_or(RequestParserError::UnexpectedEOF)?;
let prio = prio
.parse()
.map_err(|_| RequestParserError::SyntaxError(0, prio.to_string()))?;
let songids = parts.next().ok_or(RequestParserError::UnexpectedEOF)?;
// TODO: This is just a guess to satisfy compilation, double check it
let songids = songids
.split(',')
.map(|s| {
s.parse()
.map_err(|_| RequestParserError::SyntaxError(0, s.to_string()))
})
.collect::<Result<Vec<u32>, RequestParserError>>()?;
debug_assert!(parts.next().is_none());
Ok((Request::PrioId(prio, songids), ""))
}
fn parse_response(
parts: ResponseAttributes<'_>,
) -> Result<Self::Response, ResponseParserError> {
debug_assert!(parts.is_empty());
Ok(())
}
}