common/types: move stuff from requests to types
This commit is contained in:
@@ -3,8 +3,7 @@ use crate::{
|
||||
Command, Request, RequestParserError, RequestParserResult, ResponseAttributes,
|
||||
ResponseParserError,
|
||||
},
|
||||
common::TimeWithFractions,
|
||||
request::SeekMode,
|
||||
common::{SeekMode, TimeWithFractions},
|
||||
};
|
||||
|
||||
pub struct SeekCur;
|
||||
|
||||
@@ -1,6 +1,11 @@
|
||||
use std::collections::HashMap;
|
||||
|
||||
use crate::{
|
||||
commands::{Command, Request, RequestParserResult, ResponseAttributes, ResponseParserError},
|
||||
request::VolumeValue,
|
||||
commands::{
|
||||
get_and_parse_property, Command, Request, RequestParserResult, ResponseAttributes,
|
||||
ResponseParserError,
|
||||
},
|
||||
common::VolumeValue,
|
||||
};
|
||||
|
||||
pub struct GetVol;
|
||||
@@ -15,15 +20,11 @@ impl Command for GetVol {
|
||||
}
|
||||
|
||||
fn parse_response(
|
||||
_parts: ResponseAttributes<'_>,
|
||||
parts: ResponseAttributes<'_>,
|
||||
) -> Result<Self::Response, ResponseParserError> {
|
||||
unimplemented!()
|
||||
// let volume = get_property!(parts, Volume, "volume");
|
||||
// let volume = match parts.get("volume") {
|
||||
// Some(GenericResponseValue::Volume(v)) => *v,
|
||||
// _ => return Err(ResponseParserError::MissingField("volume")),
|
||||
// };
|
||||
|
||||
// Ok(volume)
|
||||
let parts: HashMap<_, _> = parts.into();
|
||||
assert_eq!(parts.len(), 1);
|
||||
let volume = get_and_parse_property!(parts, "volume", Text);
|
||||
Ok(volume)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ use crate::{
|
||||
Command, Request, RequestParserError, RequestParserResult, ResponseAttributes,
|
||||
ResponseParserError,
|
||||
},
|
||||
request::ReplayGainModeMode,
|
||||
common::ReplayGainModeMode,
|
||||
};
|
||||
|
||||
pub struct ReplayGainMode;
|
||||
|
||||
@@ -7,7 +7,7 @@ use crate::{
|
||||
get_property, Command, Request, RequestParserResult, ResponseAttributes,
|
||||
ResponseParserError,
|
||||
},
|
||||
request::ReplayGainModeMode,
|
||||
common::ReplayGainModeMode,
|
||||
};
|
||||
|
||||
pub struct ReplayGainStatus;
|
||||
|
||||
@@ -5,7 +5,7 @@ use crate::{
|
||||
Command, Request, RequestParserError, RequestParserResult, ResponseAttributes,
|
||||
ResponseParserError,
|
||||
},
|
||||
request::VolumeValue,
|
||||
common::VolumeValue,
|
||||
};
|
||||
|
||||
pub struct SetVol;
|
||||
|
||||
@@ -5,7 +5,7 @@ use crate::{
|
||||
Command, Request, RequestParserError, RequestParserResult, ResponseAttributes,
|
||||
ResponseParserError,
|
||||
},
|
||||
request::VolumeValue,
|
||||
common::VolumeValue,
|
||||
};
|
||||
|
||||
pub struct Volume;
|
||||
|
||||
@@ -1,19 +1,29 @@
|
||||
mod absolute_relative_song_position;
|
||||
mod audio;
|
||||
mod bool_or_oneshot;
|
||||
mod group_type;
|
||||
mod one_or_range;
|
||||
mod replay_gain_mode_mode;
|
||||
mod save_mode;
|
||||
mod seek_mode;
|
||||
mod subsystem;
|
||||
mod tag;
|
||||
mod time_interval;
|
||||
mod volume_value;
|
||||
mod window_range;
|
||||
|
||||
pub use absolute_relative_song_position::AbsouluteRelativeSongPosition;
|
||||
pub use audio::Audio;
|
||||
pub use bool_or_oneshot::BoolOrOneshot;
|
||||
pub use group_type::GroupType;
|
||||
pub use one_or_range::OneOrRange;
|
||||
pub use replay_gain_mode_mode::ReplayGainModeMode;
|
||||
pub use save_mode::SaveMode;
|
||||
pub use seek_mode::SeekMode;
|
||||
pub use subsystem::SubSystem;
|
||||
pub use tag::Tag;
|
||||
pub use time_interval::TimeInterval;
|
||||
pub use volume_value::VolumeValue;
|
||||
pub use window_range::WindowRange;
|
||||
|
||||
pub type SongPosition = u32;
|
||||
|
||||
43
src/common/types/group_type.rs
Normal file
43
src/common/types/group_type.rs
Normal file
@@ -0,0 +1,43 @@
|
||||
use std::str::FromStr;
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
// TODO: fill out
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
||||
pub enum GroupType {
|
||||
Artist,
|
||||
Album,
|
||||
AlbumArtist,
|
||||
Date,
|
||||
Genre,
|
||||
Track,
|
||||
Composer,
|
||||
Performer,
|
||||
Conductor,
|
||||
Comment,
|
||||
Disc,
|
||||
Filename,
|
||||
Any,
|
||||
}
|
||||
|
||||
impl FromStr for GroupType {
|
||||
type Err = ();
|
||||
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
||||
match s {
|
||||
"artist" => Ok(Self::Artist),
|
||||
"album" => Ok(Self::Album),
|
||||
"albumartist" => Ok(Self::AlbumArtist),
|
||||
"date" => Ok(Self::Date),
|
||||
"genre" => Ok(Self::Genre),
|
||||
"track" => Ok(Self::Track),
|
||||
"composer" => Ok(Self::Composer),
|
||||
"performer" => Ok(Self::Performer),
|
||||
"conductor" => Ok(Self::Conductor),
|
||||
"comment" => Ok(Self::Comment),
|
||||
"disc" => Ok(Self::Disc),
|
||||
"filename" => Ok(Self::Filename),
|
||||
"any" => Ok(Self::Any),
|
||||
_ => Err(()),
|
||||
}
|
||||
}
|
||||
}
|
||||
23
src/common/types/replay_gain_mode_mode.rs
Normal file
23
src/common/types/replay_gain_mode_mode.rs
Normal file
@@ -0,0 +1,23 @@
|
||||
use std::str::FromStr;
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
||||
pub enum ReplayGainModeMode {
|
||||
Off,
|
||||
Track,
|
||||
Album,
|
||||
Auto,
|
||||
}
|
||||
impl FromStr for ReplayGainModeMode {
|
||||
type Err = ();
|
||||
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
||||
match s {
|
||||
"off" => Ok(Self::Off),
|
||||
"track" => Ok(Self::Track),
|
||||
"album" => Ok(Self::Album),
|
||||
"auto" => Ok(Self::Auto),
|
||||
_ => Err(()),
|
||||
}
|
||||
}
|
||||
}
|
||||
21
src/common/types/save_mode.rs
Normal file
21
src/common/types/save_mode.rs
Normal file
@@ -0,0 +1,21 @@
|
||||
use std::str::FromStr;
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
||||
pub enum SaveMode {
|
||||
Create,
|
||||
Append,
|
||||
Replace,
|
||||
}
|
||||
impl FromStr for SaveMode {
|
||||
type Err = ();
|
||||
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
||||
match s {
|
||||
"create" => Ok(Self::Create),
|
||||
"append" => Ok(Self::Append),
|
||||
"replace" => Ok(Self::Replace),
|
||||
_ => Err(()),
|
||||
}
|
||||
}
|
||||
}
|
||||
8
src/common/types/seek_mode.rs
Normal file
8
src/common/types/seek_mode.rs
Normal file
@@ -0,0 +1,8 @@
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
||||
pub enum SeekMode {
|
||||
Relative,
|
||||
RelativeReverse,
|
||||
Absolute,
|
||||
}
|
||||
26
src/common/types/volume_value.rs
Normal file
26
src/common/types/volume_value.rs
Normal file
@@ -0,0 +1,26 @@
|
||||
use std::str::FromStr;
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
||||
pub struct VolumeValue(u32);
|
||||
impl VolumeValue {
|
||||
pub fn new(volume: u32) -> Result<Self, ()> {
|
||||
match volume {
|
||||
0..=100 => Ok(Self(volume)),
|
||||
_ => Err(()),
|
||||
}
|
||||
}
|
||||
}
|
||||
impl From<VolumeValue> for u32 {
|
||||
fn from(val: VolumeValue) -> Self {
|
||||
val.0
|
||||
}
|
||||
}
|
||||
impl FromStr for VolumeValue {
|
||||
type Err = ();
|
||||
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
||||
let volume = s.parse().map_err(|_| ())?;
|
||||
VolumeValue::new(volume)
|
||||
}
|
||||
}
|
||||
126
src/request.rs
126
src/request.rs
@@ -1,5 +1,3 @@
|
||||
use std::str::FromStr;
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::common::*;
|
||||
@@ -205,130 +203,6 @@ pub enum Request {
|
||||
SendMessage(ChannelName, String),
|
||||
}
|
||||
|
||||
// impl From<Request> for Vec<u8> {
|
||||
// fn from(val: Request) -> Self {
|
||||
// todo!()
|
||||
// }
|
||||
// }
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
||||
pub enum SaveMode {
|
||||
Create,
|
||||
Append,
|
||||
Replace,
|
||||
}
|
||||
impl FromStr for SaveMode {
|
||||
type Err = ();
|
||||
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
||||
match s {
|
||||
"create" => Ok(Self::Create),
|
||||
"append" => Ok(Self::Append),
|
||||
"replace" => Ok(Self::Replace),
|
||||
_ => Err(()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
||||
pub enum SeekMode {
|
||||
Relative,
|
||||
RelativeReverse,
|
||||
Absolute,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
||||
pub enum ReplayGainModeMode {
|
||||
Off,
|
||||
Track,
|
||||
Album,
|
||||
Auto,
|
||||
}
|
||||
impl FromStr for ReplayGainModeMode {
|
||||
type Err = ();
|
||||
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
||||
match s {
|
||||
"off" => Ok(Self::Off),
|
||||
"track" => Ok(Self::Track),
|
||||
"album" => Ok(Self::Album),
|
||||
"auto" => Ok(Self::Auto),
|
||||
_ => Err(()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
||||
pub struct VolumeValue(u32);
|
||||
impl VolumeValue {
|
||||
pub fn new(volume: u32) -> Result<Self, ()> {
|
||||
match volume {
|
||||
0..=100 => Ok(Self(volume)),
|
||||
_ => Err(()),
|
||||
}
|
||||
}
|
||||
}
|
||||
impl From<VolumeValue> for u32 {
|
||||
fn from(val: VolumeValue) -> Self {
|
||||
val.0
|
||||
}
|
||||
}
|
||||
impl FromStr for VolumeValue {
|
||||
type Err = ();
|
||||
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
||||
let volume = s.parse().map_err(|_| ())?;
|
||||
VolumeValue::new(volume)
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: fill out
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
||||
pub enum GroupType {
|
||||
Artist,
|
||||
Album,
|
||||
AlbumArtist,
|
||||
Date,
|
||||
Genre,
|
||||
Track,
|
||||
Composer,
|
||||
Performer,
|
||||
Conductor,
|
||||
Comment,
|
||||
Disc,
|
||||
Filename,
|
||||
Any,
|
||||
}
|
||||
|
||||
impl FromStr for GroupType {
|
||||
type Err = ();
|
||||
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
||||
match s {
|
||||
"artist" => Ok(Self::Artist),
|
||||
"album" => Ok(Self::Album),
|
||||
"albumartist" => Ok(Self::AlbumArtist),
|
||||
"date" => Ok(Self::Date),
|
||||
"genre" => Ok(Self::Genre),
|
||||
"track" => Ok(Self::Track),
|
||||
"composer" => Ok(Self::Composer),
|
||||
"performer" => Ok(Self::Performer),
|
||||
"conductor" => Ok(Self::Conductor),
|
||||
"comment" => Ok(Self::Comment),
|
||||
"disc" => Ok(Self::Disc),
|
||||
"filename" => Ok(Self::Filename),
|
||||
"any" => Ok(Self::Any),
|
||||
_ => Err(()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// trait RequestCommand {
|
||||
// // The command name used within the protocol
|
||||
// const COMMAND: &'static str;
|
||||
|
||||
// // A function to parse the remaining parts of the command, split by whitespace
|
||||
// fn parse(parts: SplitWhitespace<'_>) -> RequestParserResponse<'_>;
|
||||
// }
|
||||
|
||||
// type RequestParserResponse<'a> = Result<(Request, &'a str), RequestParserError>;
|
||||
|
||||
// pub enum RequestParserError {
|
||||
// SyntaxError(u64, String),
|
||||
// MissingCommandListEnd(u64),
|
||||
|
||||
Reference in New Issue
Block a user