common/types: move stuff from requests to types
This commit is contained in:
@@ -3,8 +3,7 @@ use crate::{
|
|||||||
Command, Request, RequestParserError, RequestParserResult, ResponseAttributes,
|
Command, Request, RequestParserError, RequestParserResult, ResponseAttributes,
|
||||||
ResponseParserError,
|
ResponseParserError,
|
||||||
},
|
},
|
||||||
common::TimeWithFractions,
|
common::{SeekMode, TimeWithFractions},
|
||||||
request::SeekMode,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
pub struct SeekCur;
|
pub struct SeekCur;
|
||||||
|
|||||||
@@ -1,6 +1,11 @@
|
|||||||
|
use std::collections::HashMap;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
commands::{Command, Request, RequestParserResult, ResponseAttributes, ResponseParserError},
|
commands::{
|
||||||
request::VolumeValue,
|
get_and_parse_property, Command, Request, RequestParserResult, ResponseAttributes,
|
||||||
|
ResponseParserError,
|
||||||
|
},
|
||||||
|
common::VolumeValue,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub struct GetVol;
|
pub struct GetVol;
|
||||||
@@ -15,15 +20,11 @@ impl Command for GetVol {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn parse_response(
|
fn parse_response(
|
||||||
_parts: ResponseAttributes<'_>,
|
parts: ResponseAttributes<'_>,
|
||||||
) -> Result<Self::Response, ResponseParserError> {
|
) -> Result<Self::Response, ResponseParserError> {
|
||||||
unimplemented!()
|
let parts: HashMap<_, _> = parts.into();
|
||||||
// let volume = get_property!(parts, Volume, "volume");
|
assert_eq!(parts.len(), 1);
|
||||||
// let volume = match parts.get("volume") {
|
let volume = get_and_parse_property!(parts, "volume", Text);
|
||||||
// Some(GenericResponseValue::Volume(v)) => *v,
|
Ok(volume)
|
||||||
// _ => return Err(ResponseParserError::MissingField("volume")),
|
|
||||||
// };
|
|
||||||
|
|
||||||
// Ok(volume)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ use crate::{
|
|||||||
Command, Request, RequestParserError, RequestParserResult, ResponseAttributes,
|
Command, Request, RequestParserError, RequestParserResult, ResponseAttributes,
|
||||||
ResponseParserError,
|
ResponseParserError,
|
||||||
},
|
},
|
||||||
request::ReplayGainModeMode,
|
common::ReplayGainModeMode,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub struct ReplayGainMode;
|
pub struct ReplayGainMode;
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ use crate::{
|
|||||||
get_property, Command, Request, RequestParserResult, ResponseAttributes,
|
get_property, Command, Request, RequestParserResult, ResponseAttributes,
|
||||||
ResponseParserError,
|
ResponseParserError,
|
||||||
},
|
},
|
||||||
request::ReplayGainModeMode,
|
common::ReplayGainModeMode,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub struct ReplayGainStatus;
|
pub struct ReplayGainStatus;
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ use crate::{
|
|||||||
Command, Request, RequestParserError, RequestParserResult, ResponseAttributes,
|
Command, Request, RequestParserError, RequestParserResult, ResponseAttributes,
|
||||||
ResponseParserError,
|
ResponseParserError,
|
||||||
},
|
},
|
||||||
request::VolumeValue,
|
common::VolumeValue,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub struct SetVol;
|
pub struct SetVol;
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ use crate::{
|
|||||||
Command, Request, RequestParserError, RequestParserResult, ResponseAttributes,
|
Command, Request, RequestParserError, RequestParserResult, ResponseAttributes,
|
||||||
ResponseParserError,
|
ResponseParserError,
|
||||||
},
|
},
|
||||||
request::VolumeValue,
|
common::VolumeValue,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub struct Volume;
|
pub struct Volume;
|
||||||
|
|||||||
@@ -1,19 +1,29 @@
|
|||||||
mod absolute_relative_song_position;
|
mod absolute_relative_song_position;
|
||||||
mod audio;
|
mod audio;
|
||||||
mod bool_or_oneshot;
|
mod bool_or_oneshot;
|
||||||
|
mod group_type;
|
||||||
mod one_or_range;
|
mod one_or_range;
|
||||||
|
mod replay_gain_mode_mode;
|
||||||
|
mod save_mode;
|
||||||
|
mod seek_mode;
|
||||||
mod subsystem;
|
mod subsystem;
|
||||||
mod tag;
|
mod tag;
|
||||||
mod time_interval;
|
mod time_interval;
|
||||||
|
mod volume_value;
|
||||||
mod window_range;
|
mod window_range;
|
||||||
|
|
||||||
pub use absolute_relative_song_position::AbsouluteRelativeSongPosition;
|
pub use absolute_relative_song_position::AbsouluteRelativeSongPosition;
|
||||||
pub use audio::Audio;
|
pub use audio::Audio;
|
||||||
pub use bool_or_oneshot::BoolOrOneshot;
|
pub use bool_or_oneshot::BoolOrOneshot;
|
||||||
|
pub use group_type::GroupType;
|
||||||
pub use one_or_range::OneOrRange;
|
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 subsystem::SubSystem;
|
||||||
pub use tag::Tag;
|
pub use tag::Tag;
|
||||||
pub use time_interval::TimeInterval;
|
pub use time_interval::TimeInterval;
|
||||||
|
pub use volume_value::VolumeValue;
|
||||||
pub use window_range::WindowRange;
|
pub use window_range::WindowRange;
|
||||||
|
|
||||||
pub type SongPosition = u32;
|
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 serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
use crate::common::*;
|
use crate::common::*;
|
||||||
@@ -205,130 +203,6 @@ pub enum Request {
|
|||||||
SendMessage(ChannelName, String),
|
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 {
|
// pub enum RequestParserError {
|
||||||
// SyntaxError(u64, String),
|
// SyntaxError(u64, String),
|
||||||
// MissingCommandListEnd(u64),
|
// MissingCommandListEnd(u64),
|
||||||
|
|||||||
Reference in New Issue
Block a user