59 lines
1.6 KiB
Rust
59 lines
1.6 KiB
Rust
use crate::{
|
|
commands::{Command, CommandRequest, RequestParserError, empty_command_response},
|
|
request_tokenizer::RequestTokenizer,
|
|
types::Feature,
|
|
};
|
|
|
|
pub struct ProtocolDisable;
|
|
|
|
pub struct ProtocolDisableRequest(Vec<Feature>);
|
|
|
|
impl CommandRequest for ProtocolDisableRequest {
|
|
const COMMAND: &'static str = "protocol disable";
|
|
|
|
fn into_request_enum(self) -> crate::Request {
|
|
crate::Request::ProtocolDisable(self.0)
|
|
}
|
|
|
|
fn from_request_enum(request: crate::Request) -> Option<Self> {
|
|
match request {
|
|
crate::Request::ProtocolDisable(features) => Some(ProtocolDisableRequest(features)),
|
|
_ => None,
|
|
}
|
|
}
|
|
|
|
fn serialize(&self) -> String {
|
|
let features = self
|
|
.0
|
|
.iter()
|
|
.map(|f| f.to_string())
|
|
.collect::<Vec<String>>()
|
|
.join(" ");
|
|
format!("{} {}", Self::COMMAND, features)
|
|
}
|
|
|
|
fn parse(parts: RequestTokenizer<'_>) -> Result<Self, RequestParserError> {
|
|
let mut parts = parts.peekable();
|
|
if parts.peek().is_none() {
|
|
return Err(RequestParserError::UnexpectedEOF);
|
|
}
|
|
|
|
let mut features = Vec::new();
|
|
for part in parts {
|
|
let feature = part
|
|
.parse()
|
|
.map_err(|_| RequestParserError::SyntaxError(1, part.to_owned()))?;
|
|
features.push(feature);
|
|
}
|
|
|
|
Ok(ProtocolDisableRequest(features))
|
|
}
|
|
}
|
|
|
|
empty_command_response!(ProtocolDisable);
|
|
|
|
impl Command for ProtocolDisable {
|
|
type Request = ProtocolDisableRequest;
|
|
type Response = ProtocolDisableResponse;
|
|
}
|