Lines
0 %
Functions
use std::collections::HashMap;
use crate::{
commands::{
get_and_parse_property, get_property, Command, Request, RequestParserError,
RequestParserResult, ResponseAttributes, ResponseParserError,
},
common::Offset,
};
pub struct AlbumArt;
pub struct AlbumArtResponse {
pub size: usize,
pub binary: Vec<u8>,
}
impl Command for AlbumArt {
type Response = AlbumArtResponse;
const COMMAND: &'static str = "albumart";
fn parse_request(mut parts: std::str::SplitWhitespace<'_>) -> RequestParserResult<'_> {
let uri = match parts.next() {
Some(s) => s,
None => return Err(RequestParserError::UnexpectedEOF),
let offset = match parts.next() {
Some(s) => s
.parse::<Offset>()
.map_err(|_| RequestParserError::SyntaxError(1, s.to_owned()))?,
debug_assert!(parts.next().is_none());
Ok((Request::AlbumArt(uri.to_string(), offset), ""))
fn parse_response(
parts: ResponseAttributes<'_>,
) -> Result<Self::Response, ResponseParserError> {
let parts: HashMap<_, _> = parts.into();
let size = get_and_parse_property!(parts, "size", Text);
let binary = get_property!(parts, "binary", Binary).into();
Ok(AlbumArtResponse { size, binary })