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

51 lines
1.5 KiB
Rust

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