Lines
0 %
Functions
use std::collections::HashMap;
use serde::{Deserialize, Serialize};
use crate::{
commands::{CommandResponse, ResponseParserError, single_item_command_request},
response_tokenizer::{GenericResponseValue, ResponseAttributes},
types::Uri,
};
single_item_command_request!(ReadComments, "readcomments", Uri);
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct ReadCommentsResponse(HashMap<String, String>);
impl ReadCommentsResponse {
pub fn new(comments: HashMap<String, String>) -> Self {
ReadCommentsResponse(comments)
}
impl CommandResponse for ReadCommentsResponse {
type Request = ReadCommentsRequest;
fn parse(parts: ResponseAttributes<'_>) -> Result<Self, ResponseParserError> {
let parts: HashMap<_, _> = parts.into_map()?;
let comments = parts
.iter()
.map(|(k, v)| match v {
GenericResponseValue::Text(s) => Ok((k.to_string(), s.to_string())),
GenericResponseValue::Binary(_) => {
Err(ResponseParserError::SyntaxError(1, k.to_string()))
})
.collect::<Result<HashMap<_, _>, ResponseParserError>>()?;
Ok(ReadCommentsResponse(comments))
fn serialize(&self) -> Vec<u8> {
unimplemented!("response serialization is not yet implemented for ReadCommentsResponse")