Files
empidee/src/commands/reflection/not_commands.rs
h7x4 02e292ffd7 response_tokenizer: rewrite
This commit contains a rewrite of the response tokenizer, which
introduces lazy parsing of the response, handling of binary data, some
tests, as well as just generally more robustness against errors.
2025-11-24 23:49:27 +09:00

40 lines
1.2 KiB
Rust

use crate::{
commands::{Command, Request, RequestParserResult, ResponseParserError},
request_tokenizer::RequestTokenizer,
response_tokenizer::{ResponseAttributes, expect_property_type},
};
pub struct NotCommands;
pub type NotCommandsResponse = Vec<String>;
impl Command for NotCommands {
type Request = ();
type Response = NotCommandsResponse;
const COMMAND: &'static str = "notcommands";
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::NotCommands, ""))
}
fn parse_response(
parts: ResponseAttributes<'_>,
) -> Result<Self::Response, ResponseParserError<'_>> {
let parts: Vec<_> = parts.into_vec()?;
let mut result = Vec::with_capacity(parts.len());
for (key, value) in parts.into_iter() {
if key != "command" {
return Err(ResponseParserError::UnexpectedProperty(key));
}
let value = expect_property_type!(Some(value), "command", Text);
result.push(value.to_string());
}
Ok(result)
}
}