58 lines
1.6 KiB
Rust
58 lines
1.6 KiB
Rust
use serde::{Deserialize, Serialize};
|
|
|
|
use crate::{
|
|
commands::{Command, CommandRequest, RequestParserError, empty_command_response},
|
|
request_tokenizer::RequestTokenizer,
|
|
types::{Priority, WindowRange},
|
|
};
|
|
|
|
pub struct Prio;
|
|
|
|
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
|
|
pub struct PrioRequest {
|
|
pub prio: Priority,
|
|
pub window: WindowRange,
|
|
}
|
|
|
|
impl CommandRequest<'_> for PrioRequest {
|
|
const COMMAND: &'static str = "prio";
|
|
|
|
fn into_request_enum(self) -> crate::Request {
|
|
crate::Request::Prio(self.prio, self.window)
|
|
}
|
|
|
|
fn from_request_enum(request: crate::Request) -> Option<Self> {
|
|
match request {
|
|
crate::Request::Prio(prio, window) => Some(PrioRequest { prio, window }),
|
|
_ => None,
|
|
}
|
|
}
|
|
|
|
fn serialize(&self) -> String {
|
|
format!("{} {} {}", Self::COMMAND, self.prio, self.window)
|
|
}
|
|
|
|
fn parse(mut parts: RequestTokenizer<'_>) -> Result<Self, RequestParserError> {
|
|
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(PrioRequest { prio, window })
|
|
}
|
|
}
|
|
|
|
empty_command_response!(Prio);
|
|
|
|
impl Command<'_, '_> for Prio {
|
|
type Request = PrioRequest;
|
|
type Response = PrioResponse;
|
|
}
|