43 lines
1.2 KiB
Rust
43 lines
1.2 KiB
Rust
use crate::{
|
|
Request,
|
|
request_tokenizer::RequestTokenizer,
|
|
commands::{
|
|
Command, RequestParserResult, ResponseAttributes, ResponseParserError, expect_property_type,
|
|
},
|
|
};
|
|
|
|
pub struct Protocol;
|
|
|
|
pub type ProtocolResponse = Vec<String>;
|
|
|
|
impl Command for Protocol {
|
|
type Request = ();
|
|
type Response = ProtocolResponse;
|
|
const COMMAND: &'static str = "protocol";
|
|
|
|
fn serialize_request(&self, _request: Self::Request) -> String {
|
|
Self::COMMAND.to_string()
|
|
}
|
|
|
|
fn parse_request(mut parts: RequestTokenizer<'_>) -> RequestParserResult<'_> {
|
|
debug_assert!(parts.next().is_none());
|
|
Ok((Request::Protocol, ""))
|
|
}
|
|
|
|
fn parse_response(
|
|
parts: ResponseAttributes<'_>,
|
|
) -> Result<Self::Response, ResponseParserError<'_>> {
|
|
if let Some((k, _)) = parts.0.iter().find(|(k, _)| *k != "feature") {
|
|
return Err(ResponseParserError::UnexpectedProperty(k));
|
|
}
|
|
|
|
let list = parts
|
|
.0
|
|
.into_iter()
|
|
.map(|(k, v)| Ok(expect_property_type!(Some(v), k, Text).to_string()))
|
|
.collect::<Result<Vec<_>, ResponseParserError>>()?;
|
|
|
|
Ok(list)
|
|
}
|
|
}
|