commands: implement some more response parsers
This commit is contained in:
@@ -8,10 +8,8 @@ use crate::{
|
|||||||
|
|
||||||
pub struct FindAdd;
|
pub struct FindAdd;
|
||||||
|
|
||||||
pub struct FindAddResponse {}
|
|
||||||
|
|
||||||
impl Command for FindAdd {
|
impl Command for FindAdd {
|
||||||
type Response = FindAddResponse;
|
type Response = ();
|
||||||
const COMMAND: &'static str = "findadd";
|
const COMMAND: &'static str = "findadd";
|
||||||
|
|
||||||
fn parse_request(mut parts: std::str::SplitWhitespace<'_>) -> RequestParserResult<'_> {
|
fn parse_request(mut parts: std::str::SplitWhitespace<'_>) -> RequestParserResult<'_> {
|
||||||
@@ -56,6 +54,7 @@ impl Command for FindAdd {
|
|||||||
fn parse_response(
|
fn parse_response(
|
||||||
parts: ResponseAttributes<'_>,
|
parts: ResponseAttributes<'_>,
|
||||||
) -> Result<Self::Response, ResponseParserError> {
|
) -> Result<Self::Response, ResponseParserError> {
|
||||||
unimplemented!()
|
debug_assert!(parts.is_empty());
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,10 +8,8 @@ use crate::{
|
|||||||
|
|
||||||
pub struct SearchAdd;
|
pub struct SearchAdd;
|
||||||
|
|
||||||
pub struct SearchAddResponse {}
|
|
||||||
|
|
||||||
impl Command for SearchAdd {
|
impl Command for SearchAdd {
|
||||||
type Response = SearchAddResponse;
|
type Response = ();
|
||||||
const COMMAND: &'static str = "searchadd";
|
const COMMAND: &'static str = "searchadd";
|
||||||
|
|
||||||
fn parse_request(mut parts: std::str::SplitWhitespace<'_>) -> RequestParserResult<'_> {
|
fn parse_request(mut parts: std::str::SplitWhitespace<'_>) -> RequestParserResult<'_> {
|
||||||
@@ -56,6 +54,7 @@ impl Command for SearchAdd {
|
|||||||
fn parse_response(
|
fn parse_response(
|
||||||
parts: ResponseAttributes<'_>,
|
parts: ResponseAttributes<'_>,
|
||||||
) -> Result<Self::Response, ResponseParserError> {
|
) -> Result<Self::Response, ResponseParserError> {
|
||||||
unimplemented!()
|
debug_assert!(parts.is_empty());
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,10 +8,8 @@ use crate::{
|
|||||||
|
|
||||||
pub struct SearchAddPl;
|
pub struct SearchAddPl;
|
||||||
|
|
||||||
pub struct SearchAddPlResponse {}
|
|
||||||
|
|
||||||
impl Command for SearchAddPl {
|
impl Command for SearchAddPl {
|
||||||
type Response = SearchAddPlResponse;
|
type Response = ();
|
||||||
const COMMAND: &'static str = "searchaddpl";
|
const COMMAND: &'static str = "searchaddpl";
|
||||||
|
|
||||||
fn parse_request(mut parts: std::str::SplitWhitespace<'_>) -> RequestParserResult<'_> {
|
fn parse_request(mut parts: std::str::SplitWhitespace<'_>) -> RequestParserResult<'_> {
|
||||||
@@ -64,6 +62,7 @@ impl Command for SearchAddPl {
|
|||||||
fn parse_response(
|
fn parse_response(
|
||||||
parts: ResponseAttributes<'_>,
|
parts: ResponseAttributes<'_>,
|
||||||
) -> Result<Self::Response, ResponseParserError> {
|
) -> Result<Self::Response, ResponseParserError> {
|
||||||
unimplemented!()
|
debug_assert!(parts.is_empty());
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,11 +1,14 @@
|
|||||||
use crate::commands::{
|
use crate::commands::{
|
||||||
Command, Request, RequestParserResult, ResponseAttributes, ResponseParserError,
|
Command, GenericResponseValue, Request, RequestParserResult, ResponseAttributes,
|
||||||
|
ResponseParserError,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub struct Commands;
|
pub struct Commands;
|
||||||
|
|
||||||
|
pub type CommandsResponse = Vec<String>;
|
||||||
|
|
||||||
impl Command for Commands {
|
impl Command for Commands {
|
||||||
type Response = ();
|
type Response = CommandsResponse;
|
||||||
const COMMAND: &'static str = "commands";
|
const COMMAND: &'static str = "commands";
|
||||||
|
|
||||||
fn parse_request(mut parts: std::str::SplitWhitespace<'_>) -> RequestParserResult<'_> {
|
fn parse_request(mut parts: std::str::SplitWhitespace<'_>) -> RequestParserResult<'_> {
|
||||||
@@ -16,6 +19,22 @@ impl Command for Commands {
|
|||||||
fn parse_response(
|
fn parse_response(
|
||||||
parts: ResponseAttributes<'_>,
|
parts: ResponseAttributes<'_>,
|
||||||
) -> Result<Self::Response, ResponseParserError> {
|
) -> 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::{
|
use crate::commands::{
|
||||||
Command, Request, RequestParserResult, ResponseAttributes, ResponseParserError,
|
Command, GenericResponseValue, Request, RequestParserResult, ResponseAttributes,
|
||||||
|
ResponseParserError,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub struct NotCommands;
|
pub struct NotCommands;
|
||||||
|
|
||||||
|
pub type NotCommandsResponse = Vec<String>;
|
||||||
|
|
||||||
impl Command for NotCommands {
|
impl Command for NotCommands {
|
||||||
type Response = ();
|
type Response = NotCommandsResponse;
|
||||||
const COMMAND: &'static str = "not_commands";
|
const COMMAND: &'static str = "notcommands";
|
||||||
|
|
||||||
fn parse_request(mut parts: std::str::SplitWhitespace<'_>) -> RequestParserResult<'_> {
|
fn parse_request(mut parts: std::str::SplitWhitespace<'_>) -> RequestParserResult<'_> {
|
||||||
debug_assert!(parts.next().is_none());
|
debug_assert!(parts.next().is_none());
|
||||||
@@ -16,6 +19,22 @@ impl Command for NotCommands {
|
|||||||
fn parse_response(
|
fn parse_response(
|
||||||
parts: ResponseAttributes<'_>,
|
parts: ResponseAttributes<'_>,
|
||||||
) -> Result<Self::Response, ResponseParserError> {
|
) -> 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