Files
empidee/src/commands/music_database/listfiles.rs
T

46 lines
1.2 KiB
Rust

use crate::{
commands::{Command, Request, RequestParserError, RequestParserResult, ResponseParserError},
common::Uri,
request_tokenizer::RequestTokenizer,
response_tokenizer::ResponseAttributes,
};
pub struct ListFiles;
// TODO: fix this type
pub type ListFilesResponse = Vec<String>;
impl Command for ListFiles {
type Request = Option<Uri>;
type Response = ListFilesResponse;
const COMMAND: &'static str = "listfiles";
fn serialize_request(&self, request: Self::Request) -> String {
if let Some(uri) = request {
format!("{} {}", Self::COMMAND, uri)
} else {
Self::COMMAND.to_string()
}
}
fn parse_request(mut parts: RequestTokenizer<'_>) -> RequestParserResult<'_> {
let uri = parts
.next()
.map(|s| {
s.parse()
.map_err(|_| RequestParserError::SyntaxError(1, s.to_owned()))
})
.transpose()?;
debug_assert!(parts.next().is_none());
Ok((Request::ListFiles(uri), ""))
}
fn parse_response(
parts: ResponseAttributes<'_>,
) -> Result<Self::Response, ResponseParserError<'_>> {
unimplemented!()
}
}