commands: implement response parser for protocol

This commit is contained in:
2025-11-21 15:14:43 +09:00
parent 73ddb6d498
commit 10913fd48c

View File

@@ -1,12 +1,13 @@
use crate::{
Request,
commands::{Command, RequestParserResult, ResponseAttributes, ResponseParserError},
commands::{expect_property_type, Command, RequestParserResult, ResponseAttributes, ResponseParserError}, Request
};
pub struct Protocol;
pub type ProtocolResponse = Vec<String>;
impl Command for Protocol {
type Response = ();
type Response = ProtocolResponse;
const COMMAND: &'static str = "protocol";
fn parse_request(mut parts: std::str::SplitWhitespace<'_>) -> RequestParserResult<'_> {
@@ -17,6 +18,16 @@ impl Command for Protocol {
fn parse_response(
parts: ResponseAttributes<'_>,
) -> Result<Self::Response, ResponseParserError<'_>> {
unimplemented!()
for (k, _) in parts.0.iter().filter(|(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)
}
}