commands: implement some more response parsers
This commit is contained in:
@@ -8,10 +8,8 @@ use crate::{
|
||||
|
||||
pub struct FindAdd;
|
||||
|
||||
pub struct FindAddResponse {}
|
||||
|
||||
impl Command for FindAdd {
|
||||
type Response = FindAddResponse;
|
||||
type Response = ();
|
||||
const COMMAND: &'static str = "findadd";
|
||||
|
||||
fn parse_request(mut parts: std::str::SplitWhitespace<'_>) -> RequestParserResult<'_> {
|
||||
@@ -56,6 +54,7 @@ impl Command for FindAdd {
|
||||
fn parse_response(
|
||||
parts: ResponseAttributes<'_>,
|
||||
) -> Result<Self::Response, ResponseParserError> {
|
||||
unimplemented!()
|
||||
debug_assert!(parts.is_empty());
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,10 +8,8 @@ use crate::{
|
||||
|
||||
pub struct SearchAdd;
|
||||
|
||||
pub struct SearchAddResponse {}
|
||||
|
||||
impl Command for SearchAdd {
|
||||
type Response = SearchAddResponse;
|
||||
type Response = ();
|
||||
const COMMAND: &'static str = "searchadd";
|
||||
|
||||
fn parse_request(mut parts: std::str::SplitWhitespace<'_>) -> RequestParserResult<'_> {
|
||||
@@ -56,6 +54,7 @@ impl Command for SearchAdd {
|
||||
fn parse_response(
|
||||
parts: ResponseAttributes<'_>,
|
||||
) -> Result<Self::Response, ResponseParserError> {
|
||||
unimplemented!()
|
||||
debug_assert!(parts.is_empty());
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,10 +8,8 @@ use crate::{
|
||||
|
||||
pub struct SearchAddPl;
|
||||
|
||||
pub struct SearchAddPlResponse {}
|
||||
|
||||
impl Command for SearchAddPl {
|
||||
type Response = SearchAddPlResponse;
|
||||
type Response = ();
|
||||
const COMMAND: &'static str = "searchaddpl";
|
||||
|
||||
fn parse_request(mut parts: std::str::SplitWhitespace<'_>) -> RequestParserResult<'_> {
|
||||
@@ -64,6 +62,7 @@ impl Command for SearchAddPl {
|
||||
fn parse_response(
|
||||
parts: ResponseAttributes<'_>,
|
||||
) -> Result<Self::Response, ResponseParserError> {
|
||||
unimplemented!()
|
||||
debug_assert!(parts.is_empty());
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,14 @@
|
||||
use crate::commands::{
|
||||
Command, Request, RequestParserResult, ResponseAttributes, ResponseParserError,
|
||||
Command, GenericResponseValue, Request, RequestParserResult, ResponseAttributes,
|
||||
ResponseParserError,
|
||||
};
|
||||
|
||||
pub struct Commands;
|
||||
|
||||
pub type CommandsResponse = Vec<String>;
|
||||
|
||||
impl Command for Commands {
|
||||
type Response = ();
|
||||
type Response = CommandsResponse;
|
||||
const COMMAND: &'static str = "commands";
|
||||
|
||||
fn parse_request(mut parts: std::str::SplitWhitespace<'_>) -> RequestParserResult<'_> {
|
||||
@@ -16,6 +19,22 @@ impl Command for Commands {
|
||||
fn parse_response(
|
||||
parts: ResponseAttributes<'_>,
|
||||
) -> Result<Self::Response, ResponseParserError> {
|
||||
unimplemented!()
|
||||
let parts: Vec<_> = parts.into();
|
||||
let mut result = Vec::new();
|
||||
for (key, value) in parts.into_iter() {
|
||||
if key != "command" {
|
||||
return Err(ResponseParserError::UnexpectedProperty(key));
|
||||
}
|
||||
let value = match value {
|
||||
GenericResponseValue::Text(value) => value,
|
||||
GenericResponseValue::Binary(_) => {
|
||||
return Err(ResponseParserError::UnexpectedPropertyType(
|
||||
"handler", "Binary",
|
||||
))
|
||||
}
|
||||
};
|
||||
result.push(value.to_string());
|
||||
}
|
||||
Ok(result)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,12 +1,15 @@
|
||||
use crate::commands::{
|
||||
Command, Request, RequestParserResult, ResponseAttributes, ResponseParserError,
|
||||
Command, GenericResponseValue, Request, RequestParserResult, ResponseAttributes,
|
||||
ResponseParserError,
|
||||
};
|
||||
|
||||
pub struct NotCommands;
|
||||
|
||||
pub type NotCommandsResponse = Vec<String>;
|
||||
|
||||
impl Command for NotCommands {
|
||||
type Response = ();
|
||||
const COMMAND: &'static str = "not_commands";
|
||||
type Response = NotCommandsResponse;
|
||||
const COMMAND: &'static str = "notcommands";
|
||||
|
||||
fn parse_request(mut parts: std::str::SplitWhitespace<'_>) -> RequestParserResult<'_> {
|
||||
debug_assert!(parts.next().is_none());
|
||||
@@ -16,6 +19,22 @@ impl Command for NotCommands {
|
||||
fn parse_response(
|
||||
parts: ResponseAttributes<'_>,
|
||||
) -> Result<Self::Response, ResponseParserError> {
|
||||
unimplemented!()
|
||||
let parts: Vec<_> = parts.into();
|
||||
let mut result = Vec::new();
|
||||
for (key, value) in parts.into_iter() {
|
||||
if key != "command" {
|
||||
return Err(ResponseParserError::UnexpectedProperty(key));
|
||||
}
|
||||
let value = match value {
|
||||
GenericResponseValue::Text(value) => value,
|
||||
GenericResponseValue::Binary(_) => {
|
||||
return Err(ResponseParserError::UnexpectedPropertyType(
|
||||
"handler", "Binary",
|
||||
))
|
||||
}
|
||||
};
|
||||
result.push(value.to_string());
|
||||
}
|
||||
Ok(result)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user