Lines
0 %
Functions
use std::collections::HashMap;
use serde::{Deserialize, Serialize};
use crate::{
commands::{CommandResponse, ResponseParserError, empty_command_request},
response_tokenizer::{
ResponseAttributes, get_and_parse_optional_property, get_and_parse_property,
},
};
empty_command_request!(Stats, "stats");
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct StatsResponse {
pub uptime: u64,
pub playtime: u64,
pub artists: Option<u64>,
pub albums: Option<u64>,
pub songs: Option<u64>,
pub db_playtime: Option<u64>,
pub db_update: Option<u64>,
}
impl StatsResponse {
pub fn new(
uptime: u64,
playtime: u64,
artists: Option<u64>,
albums: Option<u64>,
songs: Option<u64>,
db_playtime: Option<u64>,
db_update: Option<u64>,
) -> Self {
Self {
uptime,
playtime,
artists,
albums,
songs,
db_playtime,
db_update,
impl CommandResponse for StatsResponse {
type Request = StatsRequest;
fn parse(parts: ResponseAttributes<'_>) -> Result<Self, ResponseParserError> {
let parts: HashMap<_, _> = parts.into_map()?;
let uptime = get_and_parse_property!(parts, "uptime", Text);
let playtime = get_and_parse_property!(parts, "playtime", Text);
let artists = get_and_parse_optional_property!(parts, "artists", Text);
let albums = get_and_parse_optional_property!(parts, "albums", Text);
let songs = get_and_parse_optional_property!(parts, "songs", Text);
let db_playtime = get_and_parse_optional_property!(parts, "db_playtime", Text);
let db_update = get_and_parse_optional_property!(parts, "db_update", Text);
Ok(StatsResponse {
})
fn serialize(&self) -> Vec<u8> {
unimplemented!("response serialization is not yet implemented for StatsResponse")