WIP: serialize requests
This commit is contained in:
@@ -34,10 +34,25 @@ pub use stickers::*;
|
||||
pub use stored_playlists::*;
|
||||
|
||||
pub trait Command {
|
||||
// // The request sent from the client to the server
|
||||
type Request;
|
||||
|
||||
// The response sent from the server to the client
|
||||
type Response;
|
||||
|
||||
// The command name used within the protocol
|
||||
const COMMAND: &'static str;
|
||||
|
||||
fn serialize_request(&self, request: Self::Request) -> String;
|
||||
fn serialize_request_to_bytes(&self, request: Self::Request) -> Vec<u8> {
|
||||
self.serialize_request(request).into_bytes()
|
||||
}
|
||||
|
||||
// fn serialize_response(&self) -> String;
|
||||
// fn serialize_response_to_bytes(&self) -> Vec<u8> {
|
||||
// self.serialize_response().into_bytes()
|
||||
// }
|
||||
|
||||
// TODO: `parse_request` should be using a more custom splitter, that can handle
|
||||
// quoted strings and escape characters. This is what mpd uses to provide arguments
|
||||
// with spaces and whatnot.
|
||||
|
||||
@@ -1,14 +1,24 @@
|
||||
use crate::commands::{
|
||||
Command, Request, RequestParserError, RequestParserResult, ResponseAttributes,
|
||||
ResponseParserError,
|
||||
use crate::{
|
||||
commands::{
|
||||
Command, Request, RequestParserError, RequestParserResult, ResponseAttributes,
|
||||
ResponseParserError,
|
||||
},
|
||||
common::AudioOutputId,
|
||||
};
|
||||
|
||||
pub struct DisableOutput;
|
||||
|
||||
pub type DisableOutputRequest = AudioOutputId;
|
||||
|
||||
impl Command for DisableOutput {
|
||||
type Request = DisableOutputRequest;
|
||||
type Response = ();
|
||||
const COMMAND: &'static str = "disableoutput";
|
||||
|
||||
fn serialize_request(&self, request: Self::Request) -> String {
|
||||
format!("{} {}", Self::COMMAND, request)
|
||||
}
|
||||
|
||||
fn parse_request(mut parts: std::str::SplitWhitespace<'_>) -> RequestParserResult<'_> {
|
||||
let output_id = parts.next().ok_or(RequestParserError::UnexpectedEOF)?;
|
||||
|
||||
|
||||
@@ -1,14 +1,24 @@
|
||||
use crate::commands::{
|
||||
Command, Request, RequestParserError, RequestParserResult, ResponseAttributes,
|
||||
ResponseParserError,
|
||||
use crate::{
|
||||
commands::{
|
||||
Command, Request, RequestParserError, RequestParserResult, ResponseAttributes,
|
||||
ResponseParserError,
|
||||
},
|
||||
common::AudioOutputId,
|
||||
};
|
||||
|
||||
pub struct EnableOutput;
|
||||
|
||||
pub type EnableOutputRequest = AudioOutputId;
|
||||
|
||||
impl Command for EnableOutput {
|
||||
type Request = EnableOutputRequest;
|
||||
type Response = ();
|
||||
const COMMAND: &'static str = "enableoutput";
|
||||
|
||||
fn serialize_request(&self, request: Self::Request) -> String {
|
||||
format!("{} {}", Self::COMMAND, request)
|
||||
}
|
||||
|
||||
fn parse_request(mut parts: std::str::SplitWhitespace<'_>) -> RequestParserResult<'_> {
|
||||
let output_id = parts.next().ok_or(RequestParserError::UnexpectedEOF)?;
|
||||
|
||||
|
||||
@@ -21,9 +21,14 @@ pub struct Output {
|
||||
pub type OutputsResponse = Vec<Output>;
|
||||
|
||||
impl Command for Outputs {
|
||||
type Request = ();
|
||||
type Response = OutputsResponse;
|
||||
const COMMAND: &'static str = "outputs";
|
||||
|
||||
fn serialize_request(&self, _: Self::Request) -> String {
|
||||
Self::COMMAND.to_string()
|
||||
}
|
||||
|
||||
fn parse_request(mut parts: std::str::SplitWhitespace<'_>) -> RequestParserResult<'_> {
|
||||
debug_assert!(parts.next().is_none());
|
||||
Ok((Request::Outputs, ""))
|
||||
|
||||
@@ -1,14 +1,37 @@
|
||||
use crate::commands::{
|
||||
Command, Request, RequestParserError, RequestParserResult, ResponseAttributes,
|
||||
ResponseParserError,
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::{
|
||||
commands::{
|
||||
Command, Request, RequestParserError, RequestParserResult, ResponseAttributes,
|
||||
ResponseParserError,
|
||||
},
|
||||
common::AudioOutputId,
|
||||
};
|
||||
|
||||
pub struct OutputSet;
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||
pub struct OutputSetRequest {
|
||||
pub output_id: AudioOutputId,
|
||||
pub attribute_name: String,
|
||||
pub attribute_value: String,
|
||||
}
|
||||
|
||||
impl Command for OutputSet {
|
||||
type Request = OutputSetRequest;
|
||||
type Response = ();
|
||||
const COMMAND: &'static str = "outputset";
|
||||
|
||||
fn serialize_request(&self, request: Self::Request) -> String {
|
||||
format!(
|
||||
"{} {} {} {}",
|
||||
Self::COMMAND,
|
||||
request.output_id,
|
||||
request.attribute_name,
|
||||
request.attribute_value
|
||||
)
|
||||
}
|
||||
|
||||
fn parse_request(mut parts: std::str::SplitWhitespace<'_>) -> RequestParserResult<'_> {
|
||||
let output_id = parts.next().ok_or(RequestParserError::UnexpectedEOF)?;
|
||||
let attribute_name = parts.next().ok_or(RequestParserError::UnexpectedEOF)?;
|
||||
|
||||
@@ -1,14 +1,24 @@
|
||||
use crate::commands::{
|
||||
Command, Request, RequestParserError, RequestParserResult, ResponseAttributes,
|
||||
ResponseParserError,
|
||||
use crate::{
|
||||
commands::{
|
||||
Command, Request, RequestParserError, RequestParserResult, ResponseAttributes,
|
||||
ResponseParserError,
|
||||
},
|
||||
common::AudioOutputId,
|
||||
};
|
||||
|
||||
pub struct ToggleOutput;
|
||||
|
||||
pub type ToggleOutputRequest = AudioOutputId;
|
||||
|
||||
impl Command for ToggleOutput {
|
||||
type Request = ToggleOutputRequest;
|
||||
type Response = ();
|
||||
const COMMAND: &'static str = "toggleoutput";
|
||||
|
||||
fn serialize_request(&self, request: Self::Request) -> String {
|
||||
format!("{} {}", Self::COMMAND, request)
|
||||
}
|
||||
|
||||
fn parse_request(mut parts: std::str::SplitWhitespace<'_>) -> RequestParserResult<'_> {
|
||||
let output_id = parts.next().ok_or(RequestParserError::UnexpectedEOF)?;
|
||||
|
||||
|
||||
@@ -1,21 +1,29 @@
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::commands::{
|
||||
Command, Request, RequestParserResult, ResponseAttributes, ResponseParserError,
|
||||
expect_property_type,
|
||||
use crate::{
|
||||
commands::{
|
||||
Command, Request, RequestParserResult, ResponseAttributes, ResponseParserError,
|
||||
expect_property_type,
|
||||
},
|
||||
common::ChannelName,
|
||||
};
|
||||
|
||||
pub struct Channels;
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||
pub struct ChannelsResponse {
|
||||
pub channels: Vec<String>,
|
||||
pub channels: Vec<ChannelName>,
|
||||
}
|
||||
|
||||
impl Command for Channels {
|
||||
type Request = ();
|
||||
type Response = ChannelsResponse;
|
||||
const COMMAND: &'static str = "channels";
|
||||
|
||||
fn serialize_request(&self, _: Self::Request) -> String {
|
||||
Self::COMMAND.to_string()
|
||||
}
|
||||
|
||||
fn parse_request(mut parts: std::str::SplitWhitespace<'_>) -> RequestParserResult<'_> {
|
||||
debug_assert!(parts.next().is_none());
|
||||
|
||||
|
||||
@@ -1,8 +1,11 @@
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::commands::{
|
||||
Command, Request, RequestParserResult, ResponseAttributes, ResponseParserError,
|
||||
expect_property_type,
|
||||
use crate::{
|
||||
commands::{
|
||||
Command, Request, RequestParserResult, ResponseAttributes, ResponseParserError,
|
||||
expect_property_type,
|
||||
},
|
||||
common::ChannelName,
|
||||
};
|
||||
|
||||
pub struct ReadMessages;
|
||||
@@ -11,14 +14,19 @@ pub type ReadMessagesResponse = Vec<ReadMessagesResponseEntry>;
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||
pub struct ReadMessagesResponseEntry {
|
||||
channel: String,
|
||||
channel: ChannelName,
|
||||
message: String,
|
||||
}
|
||||
|
||||
impl Command for ReadMessages {
|
||||
type Request = ();
|
||||
type Response = ReadMessagesResponse;
|
||||
const COMMAND: &'static str = "readmessages";
|
||||
|
||||
fn serialize_request(&self, _: Self::Request) -> String {
|
||||
Self::COMMAND.to_string()
|
||||
}
|
||||
|
||||
fn parse_request(mut parts: std::str::SplitWhitespace<'_>) -> RequestParserResult<'_> {
|
||||
debug_assert!(parts.next().is_none());
|
||||
|
||||
|
||||
@@ -1,14 +1,30 @@
|
||||
use crate::commands::{
|
||||
Command, Request, RequestParserError, RequestParserResult, ResponseAttributes,
|
||||
ResponseParserError,
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::{
|
||||
commands::{
|
||||
Command, Request, RequestParserError, RequestParserResult, ResponseAttributes,
|
||||
ResponseParserError,
|
||||
},
|
||||
common::ChannelName,
|
||||
};
|
||||
|
||||
pub struct SendMessage;
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||
pub struct SendMessageRequest {
|
||||
pub channel: ChannelName,
|
||||
pub message: String,
|
||||
}
|
||||
|
||||
impl Command for SendMessage {
|
||||
type Request = SendMessageRequest;
|
||||
type Response = ();
|
||||
const COMMAND: &'static str = "sendmessage";
|
||||
|
||||
fn serialize_request(&self, request: Self::Request) -> String {
|
||||
format!("{} {} {}", Self::COMMAND, request.channel, request.message)
|
||||
}
|
||||
|
||||
fn parse_request(mut parts: std::str::SplitWhitespace<'_>) -> RequestParserResult<'_> {
|
||||
let channel = parts.next().ok_or(RequestParserError::UnexpectedEOF)?;
|
||||
|
||||
|
||||
@@ -1,14 +1,22 @@
|
||||
use crate::commands::{
|
||||
Command, Request, RequestParserError, RequestParserResult, ResponseAttributes,
|
||||
ResponseParserError,
|
||||
use crate::{
|
||||
commands::{
|
||||
Command, Request, RequestParserError, RequestParserResult, ResponseAttributes,
|
||||
ResponseParserError,
|
||||
},
|
||||
common::ChannelName,
|
||||
};
|
||||
|
||||
pub struct Subscribe;
|
||||
|
||||
impl Command for Subscribe {
|
||||
type Request = ChannelName;
|
||||
type Response = ();
|
||||
const COMMAND: &'static str = "subscribe";
|
||||
|
||||
fn serialize_request(&self, request: Self::Request) -> String {
|
||||
format!("{} {}", Self::COMMAND, request)
|
||||
}
|
||||
|
||||
fn parse_request(mut parts: std::str::SplitWhitespace<'_>) -> RequestParserResult<'_> {
|
||||
let channel_name = parts.next().ok_or(RequestParserError::UnexpectedEOF)?;
|
||||
|
||||
|
||||
@@ -1,14 +1,22 @@
|
||||
use crate::commands::{
|
||||
Command, Request, RequestParserError, RequestParserResult, ResponseAttributes,
|
||||
ResponseParserError,
|
||||
use crate::{
|
||||
commands::{
|
||||
Command, Request, RequestParserError, RequestParserResult, ResponseAttributes,
|
||||
ResponseParserError,
|
||||
},
|
||||
common::ChannelName,
|
||||
};
|
||||
|
||||
pub struct Unsubscribe;
|
||||
|
||||
impl Command for Unsubscribe {
|
||||
type Request = ChannelName;
|
||||
type Response = ();
|
||||
const COMMAND: &'static str = "unsubscribe";
|
||||
|
||||
fn serialize_request(&self, request: Self::Request) -> String {
|
||||
format!("{} {}", Self::COMMAND, request)
|
||||
}
|
||||
|
||||
fn parse_request(mut parts: std::str::SplitWhitespace<'_>) -> RequestParserResult<'_> {
|
||||
let channel_name = parts.next().ok_or(RequestParserError::UnexpectedEOF)?;
|
||||
|
||||
|
||||
@@ -6,9 +6,14 @@ use crate::commands::{
|
||||
pub struct BinaryLimit;
|
||||
|
||||
impl Command for BinaryLimit {
|
||||
type Request = u64;
|
||||
type Response = ();
|
||||
const COMMAND: &'static str = "binarylimit";
|
||||
|
||||
fn serialize_request(&self, request: Self::Request) -> String {
|
||||
format!("{} {}", Self::COMMAND, request)
|
||||
}
|
||||
|
||||
fn parse_request(mut parts: std::str::SplitWhitespace<'_>) -> RequestParserResult<'_> {
|
||||
let limit = parts.next().ok_or(RequestParserError::UnexpectedEOF)?;
|
||||
let limit = limit
|
||||
|
||||
@@ -5,9 +5,14 @@ use crate::commands::{
|
||||
pub struct Close;
|
||||
|
||||
impl Command for Close {
|
||||
type Request = ();
|
||||
type Response = ();
|
||||
const COMMAND: &'static str = "close";
|
||||
|
||||
fn serialize_request(&self, _request: Self::Request) -> String {
|
||||
Self::COMMAND.to_string()
|
||||
}
|
||||
|
||||
fn parse_request(mut parts: std::str::SplitWhitespace<'_>) -> RequestParserResult<'_> {
|
||||
debug_assert!(parts.next().is_none());
|
||||
Ok((Request::Close, ""))
|
||||
|
||||
@@ -5,9 +5,14 @@ use crate::commands::{
|
||||
pub struct Kill;
|
||||
|
||||
impl Command for Kill {
|
||||
type Request = ();
|
||||
type Response = ();
|
||||
const COMMAND: &'static str = "kill";
|
||||
|
||||
fn serialize_request(&self, _request: Self::Request) -> String {
|
||||
Self::COMMAND.to_string()
|
||||
}
|
||||
|
||||
fn parse_request(mut parts: std::str::SplitWhitespace<'_>) -> RequestParserResult<'_> {
|
||||
debug_assert!(parts.next().is_none());
|
||||
Ok((Request::Kill, ""))
|
||||
|
||||
@@ -6,9 +6,14 @@ use crate::commands::{
|
||||
pub struct Password;
|
||||
|
||||
impl Command for Password {
|
||||
type Request = String;
|
||||
type Response = ();
|
||||
const COMMAND: &'static str = "password";
|
||||
|
||||
fn serialize_request(&self, request: Self::Request) -> String {
|
||||
format!("{} {}", Self::COMMAND, request)
|
||||
}
|
||||
|
||||
fn parse_request(mut parts: std::str::SplitWhitespace<'_>) -> RequestParserResult<'_> {
|
||||
let password = parts
|
||||
.next()
|
||||
|
||||
@@ -5,9 +5,14 @@ use crate::commands::{
|
||||
pub struct Ping;
|
||||
|
||||
impl Command for Ping {
|
||||
type Request = ();
|
||||
type Response = ();
|
||||
const COMMAND: &'static str = "ping";
|
||||
|
||||
fn serialize_request(&self, _request: Self::Request) -> String {
|
||||
Self::COMMAND.to_string()
|
||||
}
|
||||
|
||||
fn parse_request(mut parts: std::str::SplitWhitespace<'_>) -> RequestParserResult<'_> {
|
||||
debug_assert!(parts.next().is_none());
|
||||
Ok((Request::Ping, ""))
|
||||
|
||||
@@ -10,9 +10,14 @@ pub struct Protocol;
|
||||
pub type ProtocolResponse = Vec<String>;
|
||||
|
||||
impl Command for Protocol {
|
||||
type Request = ();
|
||||
type Response = ProtocolResponse;
|
||||
const COMMAND: &'static str = "protocol";
|
||||
|
||||
fn serialize_request(&self, _request: Self::Request) -> String {
|
||||
Self::COMMAND.to_string()
|
||||
}
|
||||
|
||||
fn parse_request(mut parts: std::str::SplitWhitespace<'_>) -> RequestParserResult<'_> {
|
||||
debug_assert!(parts.next().is_none());
|
||||
Ok((Request::Protocol, ""))
|
||||
|
||||
@@ -6,9 +6,14 @@ use crate::{
|
||||
pub struct ProtocolAll;
|
||||
|
||||
impl Command for ProtocolAll {
|
||||
type Request = ();
|
||||
type Response = ();
|
||||
const COMMAND: &'static str = "protocol all";
|
||||
|
||||
fn serialize_request(&self, _request: Self::Request) -> String {
|
||||
Self::COMMAND.to_string()
|
||||
}
|
||||
|
||||
fn parse_request(mut parts: std::str::SplitWhitespace<'_>) -> RequestParserResult<'_> {
|
||||
debug_assert!(parts.next().is_none());
|
||||
Ok((Request::ProtocolAll, ""))
|
||||
|
||||
@@ -10,9 +10,14 @@ pub struct ProtocolAvailable;
|
||||
pub type ProtocolAvailableResponse = Vec<String>;
|
||||
|
||||
impl Command for ProtocolAvailable {
|
||||
type Request = ();
|
||||
type Response = ProtocolAvailableResponse;
|
||||
const COMMAND: &'static str = "protocol available";
|
||||
|
||||
fn serialize_request(&self, _request: Self::Request) -> String {
|
||||
Self::COMMAND.to_string()
|
||||
}
|
||||
|
||||
fn parse_request(mut parts: std::str::SplitWhitespace<'_>) -> RequestParserResult<'_> {
|
||||
debug_assert!(parts.next().is_none());
|
||||
Ok((Request::ProtocolAvailable, ""))
|
||||
|
||||
@@ -6,9 +6,14 @@ use crate::{
|
||||
pub struct ProtocolClear;
|
||||
|
||||
impl Command for ProtocolClear {
|
||||
type Request = ();
|
||||
type Response = ();
|
||||
const COMMAND: &'static str = "protocol clear";
|
||||
|
||||
fn serialize_request(&self, _request: Self::Request) -> String {
|
||||
Self::COMMAND.to_string()
|
||||
}
|
||||
|
||||
fn parse_request(mut parts: std::str::SplitWhitespace<'_>) -> RequestParserResult<'_> {
|
||||
debug_assert!(parts.next().is_none());
|
||||
Ok((Request::ProtocolClear, ""))
|
||||
|
||||
@@ -3,14 +3,22 @@ use crate::{
|
||||
commands::{
|
||||
Command, RequestParserError, RequestParserResult, ResponseAttributes, ResponseParserError,
|
||||
},
|
||||
common::Feature,
|
||||
};
|
||||
|
||||
pub struct ProtocolDisable;
|
||||
|
||||
pub type ProtocolDisableRequest = Vec<Feature>;
|
||||
|
||||
impl Command for ProtocolDisable {
|
||||
type Request = ProtocolDisableRequest;
|
||||
type Response = ();
|
||||
const COMMAND: &'static str = "protocol disable";
|
||||
|
||||
fn serialize_request(&self, request: Self::Request) -> String {
|
||||
format!("{} {}", Self::COMMAND, request.join(" "))
|
||||
}
|
||||
|
||||
fn parse_request(parts: std::str::SplitWhitespace<'_>) -> RequestParserResult<'_> {
|
||||
let mut parts = parts.peekable();
|
||||
if parts.peek().is_none() {
|
||||
|
||||
@@ -3,14 +3,22 @@ use crate::{
|
||||
commands::{
|
||||
Command, RequestParserError, RequestParserResult, ResponseAttributes, ResponseParserError,
|
||||
},
|
||||
common::Feature,
|
||||
};
|
||||
|
||||
pub struct ProtocolEnable;
|
||||
|
||||
pub type ProtocolEnableRequest = Vec<Feature>;
|
||||
|
||||
impl Command for ProtocolEnable {
|
||||
type Request = ProtocolEnableRequest;
|
||||
type Response = ();
|
||||
const COMMAND: &'static str = "protocol enable";
|
||||
|
||||
fn serialize_request(&self, request: Self::Request) -> String {
|
||||
format!("{} {}", Self::COMMAND, request.join(" "))
|
||||
}
|
||||
|
||||
fn parse_request(parts: std::str::SplitWhitespace<'_>) -> RequestParserResult<'_> {
|
||||
let mut parts = parts.peekable();
|
||||
if parts.peek().is_none() {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
use crate::commands::{
|
||||
Command, Request, RequestParserResult, ResponseAttributes,
|
||||
ResponseParserError, expect_property_type,
|
||||
Command, Request, RequestParserResult, ResponseAttributes, ResponseParserError,
|
||||
expect_property_type,
|
||||
};
|
||||
|
||||
pub struct TagTypes;
|
||||
@@ -8,9 +8,14 @@ pub struct TagTypes;
|
||||
pub type TagTypesResponse = Vec<String>;
|
||||
|
||||
impl Command for TagTypes {
|
||||
type Request = ();
|
||||
type Response = TagTypesResponse;
|
||||
const COMMAND: &'static str = "tagtypes";
|
||||
|
||||
fn serialize_request(&self, _request: Self::Request) -> String {
|
||||
Self::COMMAND.to_string()
|
||||
}
|
||||
|
||||
fn parse_request(mut parts: std::str::SplitWhitespace<'_>) -> RequestParserResult<'_> {
|
||||
debug_assert!(parts.next().is_none());
|
||||
Ok((Request::TagTypes, ""))
|
||||
|
||||
@@ -6,9 +6,14 @@ use crate::{
|
||||
pub struct TagTypesAll;
|
||||
|
||||
impl Command for TagTypesAll {
|
||||
type Request = ();
|
||||
type Response = ();
|
||||
const COMMAND: &'static str = "tagtypes all";
|
||||
|
||||
fn serialize_request(&self, _request: Self::Request) -> String {
|
||||
Self::COMMAND.to_string()
|
||||
}
|
||||
|
||||
fn parse_request(mut parts: std::str::SplitWhitespace<'_>) -> RequestParserResult<'_> {
|
||||
debug_assert!(parts.next().is_none());
|
||||
Ok((Request::TagTypesAll, ""))
|
||||
|
||||
@@ -10,9 +10,14 @@ pub struct TagTypesAvailable;
|
||||
pub type TagTypesAvailableResponse = Vec<String>;
|
||||
|
||||
impl Command for TagTypesAvailable {
|
||||
type Request = ();
|
||||
type Response = TagTypesAvailableResponse;
|
||||
const COMMAND: &'static str = "tagtypes available";
|
||||
|
||||
fn serialize_request(&self, _request: Self::Request) -> String {
|
||||
Self::COMMAND.to_string()
|
||||
}
|
||||
|
||||
fn parse_request(mut parts: std::str::SplitWhitespace<'_>) -> RequestParserResult<'_> {
|
||||
debug_assert!(parts.next().is_none());
|
||||
Ok((Request::TagTypesAvailable, ""))
|
||||
|
||||
@@ -6,9 +6,14 @@ use crate::{
|
||||
pub struct TagTypesClear;
|
||||
|
||||
impl Command for TagTypesClear {
|
||||
type Request = ();
|
||||
type Response = ();
|
||||
const COMMAND: &'static str = "tagtypes clear";
|
||||
|
||||
fn serialize_request(&self, _request: Self::Request) -> String {
|
||||
Self::COMMAND.to_string()
|
||||
}
|
||||
|
||||
fn parse_request(mut parts: std::str::SplitWhitespace<'_>) -> RequestParserResult<'_> {
|
||||
debug_assert!(parts.next().is_none());
|
||||
Ok((Request::TagTypesClear, ""))
|
||||
|
||||
@@ -3,14 +3,22 @@ use crate::{
|
||||
commands::{
|
||||
Command, RequestParserError, RequestParserResult, ResponseAttributes, ResponseParserError,
|
||||
},
|
||||
common::TagName,
|
||||
};
|
||||
|
||||
pub struct TagTypesDisable;
|
||||
|
||||
pub type TagTypesDisableRequest = Vec<TagName>;
|
||||
|
||||
impl Command for TagTypesDisable {
|
||||
type Request = TagTypesDisableRequest;
|
||||
type Response = ();
|
||||
const COMMAND: &'static str = "tagtypes disable";
|
||||
|
||||
fn serialize_request(&self, request: Self::Request) -> String {
|
||||
format!("{} {}", Self::COMMAND, request.join(" "))
|
||||
}
|
||||
|
||||
fn parse_request(parts: std::str::SplitWhitespace<'_>) -> RequestParserResult<'_> {
|
||||
let mut parts = parts.peekable();
|
||||
if parts.peek().is_none() {
|
||||
|
||||
@@ -3,14 +3,22 @@ use crate::{
|
||||
commands::{
|
||||
Command, RequestParserError, RequestParserResult, ResponseAttributes, ResponseParserError,
|
||||
},
|
||||
common::TagName,
|
||||
};
|
||||
|
||||
pub struct TagTypesEnable;
|
||||
|
||||
pub type TagTypesEnableRequest = Vec<TagName>;
|
||||
|
||||
impl Command for TagTypesEnable {
|
||||
type Request = TagTypesEnableRequest;
|
||||
type Response = ();
|
||||
const COMMAND: &'static str = "tagtypes enable";
|
||||
|
||||
fn serialize_request(&self, request: Self::Request) -> String {
|
||||
format!("{} {}", Self::COMMAND, request.join(" "))
|
||||
}
|
||||
|
||||
fn parse_request(parts: std::str::SplitWhitespace<'_>) -> RequestParserResult<'_> {
|
||||
let mut parts = parts.peekable();
|
||||
if parts.peek().is_none() {
|
||||
|
||||
@@ -3,14 +3,22 @@ use crate::{
|
||||
commands::{
|
||||
Command, RequestParserError, RequestParserResult, ResponseAttributes, ResponseParserError,
|
||||
},
|
||||
common::TagName,
|
||||
};
|
||||
|
||||
pub struct TagTypesReset;
|
||||
|
||||
pub type TagTypesResetRequest = Vec<TagName>;
|
||||
|
||||
impl Command for TagTypesReset {
|
||||
type Request = TagTypesResetRequest;
|
||||
type Response = ();
|
||||
const COMMAND: &'static str = "tagtypes reset";
|
||||
|
||||
fn serialize_request(&self, request: Self::Request) -> String {
|
||||
format!("{} {}", Self::COMMAND, request.join(" "))
|
||||
}
|
||||
|
||||
fn parse_request(parts: std::str::SplitWhitespace<'_>) -> RequestParserResult<'_> {
|
||||
let mut parts = parts.peekable();
|
||||
if parts.peek().is_none() {
|
||||
|
||||
@@ -5,9 +5,14 @@ use crate::commands::{
|
||||
pub struct Next;
|
||||
|
||||
impl Command for Next {
|
||||
type Request = ();
|
||||
type Response = ();
|
||||
const COMMAND: &'static str = "next";
|
||||
|
||||
fn serialize_request(&self, _request: Self::Request) -> String {
|
||||
Self::COMMAND.to_string()
|
||||
}
|
||||
|
||||
fn parse_request(mut parts: std::str::SplitWhitespace<'_>) -> RequestParserResult<'_> {
|
||||
debug_assert!(parts.next().is_none());
|
||||
Ok((Request::Next, ""))
|
||||
|
||||
@@ -6,9 +6,18 @@ use crate::commands::{
|
||||
pub struct Pause;
|
||||
|
||||
impl Command for Pause {
|
||||
type Request = Option<bool>;
|
||||
type Response = ();
|
||||
const COMMAND: &'static str = "pause";
|
||||
|
||||
fn serialize_request(&self, request: Self::Request) -> String {
|
||||
match request {
|
||||
Some(true) => format!("{} 1", Self::COMMAND),
|
||||
Some(false) => format!("{} 0", Self::COMMAND),
|
||||
None => Self::COMMAND.to_string(),
|
||||
}
|
||||
}
|
||||
|
||||
fn parse_request(mut parts: std::str::SplitWhitespace<'_>) -> RequestParserResult<'_> {
|
||||
let result = match parts.next() {
|
||||
Some("0") => Ok((Request::Pause(Some(false)), "")),
|
||||
|
||||
@@ -9,9 +9,14 @@ use crate::{
|
||||
pub struct Play;
|
||||
|
||||
impl Command for Play {
|
||||
type Request = SongPosition;
|
||||
type Response = ();
|
||||
const COMMAND: &'static str = "play";
|
||||
|
||||
fn serialize_request(&self, request: Self::Request) -> String {
|
||||
format!("{} {}", Self::COMMAND, request)
|
||||
}
|
||||
|
||||
fn parse_request(mut parts: std::str::SplitWhitespace<'_>) -> RequestParserResult<'_> {
|
||||
let songpos = match parts.next() {
|
||||
Some(s) => s
|
||||
|
||||
@@ -9,9 +9,14 @@ use crate::{
|
||||
pub struct PlayId;
|
||||
|
||||
impl Command for PlayId {
|
||||
type Request = SongId;
|
||||
type Response = ();
|
||||
const COMMAND: &'static str = "playid";
|
||||
|
||||
fn serialize_request(&self, request: Self::Request) -> String {
|
||||
format!("{} {}", Self::COMMAND, request)
|
||||
}
|
||||
|
||||
fn parse_request(mut parts: std::str::SplitWhitespace<'_>) -> RequestParserResult<'_> {
|
||||
let songid = match parts.next() {
|
||||
Some(s) => s
|
||||
|
||||
@@ -5,9 +5,14 @@ use crate::commands::{
|
||||
pub struct Previous;
|
||||
|
||||
impl Command for Previous {
|
||||
type Request = ();
|
||||
type Response = ();
|
||||
const COMMAND: &'static str = "previous";
|
||||
|
||||
fn serialize_request(&self, _request: Self::Request) -> String {
|
||||
Self::COMMAND.to_string()
|
||||
}
|
||||
|
||||
fn parse_request(mut parts: std::str::SplitWhitespace<'_>) -> RequestParserResult<'_> {
|
||||
debug_assert!(parts.next().is_none());
|
||||
Ok((Request::Previous, ""))
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::{
|
||||
commands::{
|
||||
Command, Request, RequestParserError, RequestParserResult, ResponseAttributes,
|
||||
@@ -8,10 +10,21 @@ use crate::{
|
||||
|
||||
pub struct Seek;
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||
pub struct SeekRequest {
|
||||
pub songpos: SongPosition,
|
||||
pub time: TimeWithFractions,
|
||||
}
|
||||
|
||||
impl Command for Seek {
|
||||
type Request = SeekRequest;
|
||||
type Response = ();
|
||||
const COMMAND: &'static str = "seek";
|
||||
|
||||
fn serialize_request(&self, request: Self::Request) -> String {
|
||||
format!("{} {} {}", Self::COMMAND, request.songpos, request.time)
|
||||
}
|
||||
|
||||
fn parse_request(mut parts: std::str::SplitWhitespace<'_>) -> RequestParserResult<'_> {
|
||||
let songpos = match parts.next() {
|
||||
Some(s) => s
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::{
|
||||
commands::{
|
||||
Command, Request, RequestParserError, RequestParserResult, ResponseAttributes,
|
||||
@@ -8,10 +10,28 @@ use crate::{
|
||||
|
||||
pub struct SeekCur;
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||
pub struct SeekCurRequest {
|
||||
pub mode: SeekMode,
|
||||
pub time: TimeWithFractions,
|
||||
}
|
||||
|
||||
impl Command for SeekCur {
|
||||
type Request = SeekCurRequest;
|
||||
type Response = ();
|
||||
const COMMAND: &'static str = "seekcur";
|
||||
|
||||
fn serialize_request(&self, request: Self::Request) -> String {
|
||||
let time_str = match request.mode {
|
||||
SeekMode::Absolute => format!("{}", request.time),
|
||||
SeekMode::Relative if request.time >= 0.0 => format!("+{}", request.time),
|
||||
SeekMode::Relative => format!("-{}", -request.time),
|
||||
SeekMode::RelativeReverse => unimplemented!(), // TODO: should this happen?
|
||||
};
|
||||
|
||||
format!("{} {}", Self::COMMAND, time_str)
|
||||
}
|
||||
|
||||
fn parse_request(mut parts: std::str::SplitWhitespace<'_>) -> RequestParserResult<'_> {
|
||||
let time_raw = match parts.next() {
|
||||
Some(t) => t,
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::{
|
||||
commands::{
|
||||
Command, Request, RequestParserError, RequestParserResult, ResponseAttributes,
|
||||
@@ -8,10 +10,21 @@ use crate::{
|
||||
|
||||
pub struct SeekId;
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||
pub struct SeekIdRequest {
|
||||
pub songid: SongId,
|
||||
pub time: TimeWithFractions,
|
||||
}
|
||||
|
||||
impl Command for SeekId {
|
||||
type Request = SeekIdRequest;
|
||||
type Response = ();
|
||||
const COMMAND: &'static str = "seekid";
|
||||
|
||||
fn serialize_request(&self, request: Self::Request) -> String {
|
||||
format!("{} {} {}", Self::COMMAND, request.songid, request.time)
|
||||
}
|
||||
|
||||
fn parse_request(mut parts: std::str::SplitWhitespace<'_>) -> RequestParserResult<'_> {
|
||||
let songid = match parts.next() {
|
||||
Some(s) => s
|
||||
|
||||
@@ -5,9 +5,14 @@ use crate::commands::{
|
||||
pub struct Stop;
|
||||
|
||||
impl Command for Stop {
|
||||
type Request = ();
|
||||
type Response = ();
|
||||
const COMMAND: &'static str = "stop";
|
||||
|
||||
fn serialize_request(&self, _request: Self::Request) -> String {
|
||||
Self::COMMAND.to_string()
|
||||
}
|
||||
|
||||
fn parse_request(mut parts: std::str::SplitWhitespace<'_>) -> RequestParserResult<'_> {
|
||||
debug_assert!(parts.next().is_none());
|
||||
Ok((Request::Stop, ""))
|
||||
|
||||
@@ -8,9 +8,14 @@ use crate::{
|
||||
pub struct ListMounts;
|
||||
|
||||
impl Command for ListMounts {
|
||||
type Request = ();
|
||||
type Response = Vec<String>;
|
||||
const COMMAND: &'static str = "listmounts";
|
||||
|
||||
fn serialize_request(&self, _request: Self::Request) -> String {
|
||||
Self::COMMAND.to_string()
|
||||
}
|
||||
|
||||
fn parse_request(mut parts: std::str::SplitWhitespace<'_>) -> RequestParserResult<'_> {
|
||||
debug_assert!(parts.next().is_none());
|
||||
Ok((Request::ListMounts, ""))
|
||||
|
||||
@@ -12,9 +12,14 @@ pub struct ListNeighbors;
|
||||
pub type ListNeighborsResponse = HashMap<String, String>;
|
||||
|
||||
impl Command for ListNeighbors {
|
||||
type Request = ();
|
||||
type Response = ListNeighborsResponse;
|
||||
const COMMAND: &'static str = "listneighbors";
|
||||
|
||||
fn serialize_request(&self, _request: Self::Request) -> String {
|
||||
Self::COMMAND.to_string()
|
||||
}
|
||||
|
||||
fn parse_request(mut parts: std::str::SplitWhitespace<'_>) -> RequestParserResult<'_> {
|
||||
debug_assert!(parts.next().is_none());
|
||||
Ok((Request::ListNeighbors, ""))
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::{
|
||||
Request,
|
||||
commands::{
|
||||
@@ -7,10 +9,21 @@ use crate::{
|
||||
|
||||
pub struct Mount;
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||
pub struct MountRequest {
|
||||
pub path: String,
|
||||
pub uri: String,
|
||||
}
|
||||
|
||||
impl Command for Mount {
|
||||
type Request = MountRequest;
|
||||
type Response = ();
|
||||
const COMMAND: &'static str = "mount";
|
||||
|
||||
fn serialize_request(&self, request: Self::Request) -> String {
|
||||
format!("{} {} {}", Self::COMMAND, request.path, request.uri)
|
||||
}
|
||||
|
||||
fn parse_request(mut parts: std::str::SplitWhitespace<'_>) -> RequestParserResult<'_> {
|
||||
let path = parts
|
||||
.next()
|
||||
|
||||
@@ -7,10 +7,17 @@ use crate::{
|
||||
|
||||
pub struct Unmount;
|
||||
|
||||
pub type UnmountRequest = String;
|
||||
|
||||
impl Command for Unmount {
|
||||
type Request = UnmountRequest;
|
||||
type Response = ();
|
||||
const COMMAND: &'static str = "unmount";
|
||||
|
||||
fn serialize_request(&self, request: Self::Request) -> String {
|
||||
format!("{} {}", Self::COMMAND, request)
|
||||
}
|
||||
|
||||
fn parse_request(mut parts: std::str::SplitWhitespace<'_>) -> RequestParserResult<'_> {
|
||||
let path = parts
|
||||
.next()
|
||||
|
||||
@@ -7,11 +7,17 @@ use crate::{
|
||||
Command, Request, RequestParserError, RequestParserResult, ResponseAttributes,
|
||||
ResponseParserError, get_and_parse_property, get_property,
|
||||
},
|
||||
common::Offset,
|
||||
common::{Offset, Uri},
|
||||
};
|
||||
|
||||
pub struct AlbumArt;
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||
pub struct AlbumArtRequest {
|
||||
uri: Uri,
|
||||
offset: Offset,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||
pub struct AlbumArtResponse {
|
||||
pub size: usize,
|
||||
@@ -19,9 +25,14 @@ pub struct AlbumArtResponse {
|
||||
}
|
||||
|
||||
impl Command for AlbumArt {
|
||||
type Request = AlbumArtRequest;
|
||||
type Response = AlbumArtResponse;
|
||||
const COMMAND: &'static str = "albumart";
|
||||
|
||||
fn serialize_request(&self, request: Self::Request) -> String {
|
||||
format!("{} {} {}", Self::COMMAND, request.uri, request.offset)
|
||||
}
|
||||
|
||||
fn parse_request(mut parts: std::str::SplitWhitespace<'_>) -> RequestParserResult<'_> {
|
||||
let uri = match parts.next() {
|
||||
Some(s) => s,
|
||||
|
||||
@@ -7,11 +7,18 @@ use crate::{
|
||||
Command, Request, RequestParserError, RequestParserResult, ResponseAttributes,
|
||||
ResponseParserError, get_and_parse_property,
|
||||
},
|
||||
filter::parse_filter,
|
||||
common::GroupType,
|
||||
filter::{Filter, parse_filter},
|
||||
};
|
||||
|
||||
pub struct Count;
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||
pub struct CountRequest {
|
||||
filter: Filter,
|
||||
group: Option<GroupType>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||
pub struct CountResponse {
|
||||
pub songs: usize,
|
||||
@@ -19,9 +26,18 @@ pub struct CountResponse {
|
||||
}
|
||||
|
||||
impl Command for Count {
|
||||
type Request = CountRequest;
|
||||
type Response = CountResponse;
|
||||
const COMMAND: &'static str = "count";
|
||||
|
||||
fn serialize_request(&self, request: Self::Request) -> String {
|
||||
let mut cmd = format!("{} {}", Self::COMMAND, request.filter);
|
||||
if let Some(group) = request.group {
|
||||
cmd.push_str(&format!(" group {}", group));
|
||||
}
|
||||
cmd
|
||||
}
|
||||
|
||||
fn parse_request(mut parts: std::str::SplitWhitespace<'_>) -> RequestParserResult<'_> {
|
||||
let filter = parse_filter(&mut parts)?;
|
||||
|
||||
|
||||
@@ -5,18 +5,38 @@ use crate::{
|
||||
Command, Request, RequestParserError, RequestParserResult, ResponseAttributes,
|
||||
ResponseParserError,
|
||||
},
|
||||
filter::parse_filter,
|
||||
common::{Sort, WindowRange},
|
||||
filter::{Filter, parse_filter},
|
||||
};
|
||||
|
||||
pub struct Find;
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||
pub struct FindRequest {
|
||||
filter: Filter,
|
||||
sort: Option<Sort>,
|
||||
window: Option<WindowRange>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||
pub struct FindResponse {}
|
||||
|
||||
impl Command for Find {
|
||||
type Request = FindRequest;
|
||||
type Response = FindResponse;
|
||||
const COMMAND: &'static str = "find";
|
||||
|
||||
fn serialize_request(&self, request: Self::Request) -> String {
|
||||
let mut cmd = format!("{} {}", Self::COMMAND, request.filter);
|
||||
if let Some(sort) = request.sort {
|
||||
cmd.push_str(&format!(" sort {}", sort));
|
||||
}
|
||||
if let Some(window) = request.window {
|
||||
cmd.push_str(&format!(" window {}", window));
|
||||
}
|
||||
cmd
|
||||
}
|
||||
|
||||
fn parse_request(mut parts: std::str::SplitWhitespace<'_>) -> RequestParserResult<'_> {
|
||||
let filter = parse_filter(&mut parts)?;
|
||||
|
||||
|
||||
@@ -1,17 +1,43 @@
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::{
|
||||
commands::{
|
||||
Command, Request, RequestParserError, RequestParserResult, ResponseAttributes,
|
||||
ResponseParserError,
|
||||
},
|
||||
filter::parse_filter,
|
||||
common::{SongPosition, Sort, WindowRange},
|
||||
filter::{Filter, parse_filter},
|
||||
};
|
||||
|
||||
pub struct FindAdd;
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||
pub struct FindAddRequest {
|
||||
filter: Filter,
|
||||
sort: Option<Sort>,
|
||||
window: Option<WindowRange>,
|
||||
position: Option<SongPosition>,
|
||||
}
|
||||
|
||||
impl Command for FindAdd {
|
||||
type Request = FindAddRequest;
|
||||
type Response = ();
|
||||
const COMMAND: &'static str = "findadd";
|
||||
|
||||
fn serialize_request(&self, request: Self::Request) -> String {
|
||||
let mut cmd = format!("{} {}", Self::COMMAND, request.filter);
|
||||
if let Some(sort) = request.sort {
|
||||
cmd.push_str(&format!(" sort {}", sort));
|
||||
}
|
||||
if let Some(window) = request.window {
|
||||
cmd.push_str(&format!(" window {}", window));
|
||||
}
|
||||
if let Some(position) = request.position {
|
||||
cmd.push_str(&format!(" position {}", position));
|
||||
}
|
||||
cmd
|
||||
}
|
||||
|
||||
fn parse_request(mut parts: std::str::SplitWhitespace<'_>) -> RequestParserResult<'_> {
|
||||
let filter = parse_filter(&mut parts)?;
|
||||
|
||||
|
||||
@@ -2,9 +2,12 @@ use std::collections::HashMap;
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::commands::{
|
||||
Command, Request, RequestParserError, RequestParserResult, ResponseAttributes,
|
||||
ResponseParserError, get_and_parse_property,
|
||||
use crate::{
|
||||
commands::{
|
||||
Command, Request, RequestParserError, RequestParserResult, ResponseAttributes,
|
||||
ResponseParserError, get_and_parse_property,
|
||||
},
|
||||
common::Uri,
|
||||
};
|
||||
|
||||
pub struct GetFingerprint;
|
||||
@@ -15,9 +18,14 @@ pub struct GetFingerprintResponse {
|
||||
}
|
||||
|
||||
impl Command for GetFingerprint {
|
||||
type Request = Uri;
|
||||
type Response = GetFingerprintResponse;
|
||||
const COMMAND: &'static str = "getfingerprint";
|
||||
|
||||
fn serialize_request(&self, request: Self::Request) -> String {
|
||||
format!("{} {}", Self::COMMAND, request)
|
||||
}
|
||||
|
||||
fn parse_request(mut parts: std::str::SplitWhitespace<'_>) -> RequestParserResult<'_> {
|
||||
let uri = parts.next().ok_or(RequestParserError::UnexpectedEOF)?;
|
||||
let uri = uri
|
||||
|
||||
@@ -1,24 +1,43 @@
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::{
|
||||
commands::{
|
||||
Command, Request, RequestParserError, RequestParserResult, ResponseAttributes,
|
||||
ResponseParserError, expect_property_type,
|
||||
},
|
||||
filter::parse_filter,
|
||||
common::{GroupType, TagName},
|
||||
filter::{Filter, parse_filter},
|
||||
};
|
||||
|
||||
pub struct List;
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||
pub struct ListRequest {
|
||||
tagname: TagName,
|
||||
filter: Filter,
|
||||
group: Option<GroupType>,
|
||||
}
|
||||
|
||||
pub type ListResponse = Vec<String>;
|
||||
|
||||
impl Command for List {
|
||||
type Request = ListRequest;
|
||||
type Response = ListResponse;
|
||||
const COMMAND: &'static str = "list";
|
||||
|
||||
fn serialize_request(&self, request: Self::Request) -> String {
|
||||
let mut cmd = format!("{} {} {}", Self::COMMAND, request.tagname, request.filter);
|
||||
if let Some(group) = request.group {
|
||||
cmd.push_str(&format!(" group {}", group));
|
||||
}
|
||||
cmd
|
||||
}
|
||||
|
||||
fn parse_request(mut parts: std::str::SplitWhitespace<'_>) -> RequestParserResult<'_> {
|
||||
let tagtype = parts.next().ok_or(RequestParserError::UnexpectedEOF)?;
|
||||
let tagtype = tagtype
|
||||
let tagname = parts.next().ok_or(RequestParserError::UnexpectedEOF)?;
|
||||
let tagname = tagname
|
||||
.parse()
|
||||
.map_err(|_| RequestParserError::SyntaxError(1, tagtype.to_owned()))?;
|
||||
.map_err(|_| RequestParserError::SyntaxError(1, tagname.to_owned()))?;
|
||||
|
||||
// TODO: This should be optional
|
||||
let filter = parse_filter(&mut parts)?;
|
||||
@@ -36,7 +55,7 @@ impl Command for List {
|
||||
|
||||
debug_assert!(parts.next().is_none());
|
||||
|
||||
Ok((Request::List(tagtype, filter, group), ""))
|
||||
Ok((Request::List(tagname, filter, group), ""))
|
||||
}
|
||||
|
||||
fn parse_response(
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
use crate::commands::{
|
||||
Command, Request, RequestParserError, RequestParserResult, ResponseAttributes,
|
||||
ResponseParserError,
|
||||
use crate::{
|
||||
commands::{
|
||||
Command, Request, RequestParserError, RequestParserResult, ResponseAttributes,
|
||||
ResponseParserError,
|
||||
},
|
||||
common::Uri,
|
||||
};
|
||||
|
||||
pub struct ListAll;
|
||||
@@ -9,9 +12,18 @@ pub struct ListAll;
|
||||
pub type ListAllResponse = Vec<String>;
|
||||
|
||||
impl Command for ListAll {
|
||||
type Request = Option<Uri>;
|
||||
type Response = ListAllResponse;
|
||||
const COMMAND: &'static str = "listall";
|
||||
|
||||
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: std::str::SplitWhitespace<'_>) -> RequestParserResult<'_> {
|
||||
let uri = parts
|
||||
.next()
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
use crate::commands::{
|
||||
Command, Request, RequestParserError, RequestParserResult, ResponseAttributes,
|
||||
ResponseParserError,
|
||||
use crate::{
|
||||
commands::{
|
||||
Command, Request, RequestParserError, RequestParserResult, ResponseAttributes,
|
||||
ResponseParserError,
|
||||
},
|
||||
common::Uri,
|
||||
};
|
||||
|
||||
pub struct ListAllInfo;
|
||||
@@ -10,9 +13,18 @@ pub struct ListAllInfo;
|
||||
pub type ListAllInfoResponse = Vec<String>;
|
||||
|
||||
impl Command for ListAllInfo {
|
||||
type Request = Option<Uri>;
|
||||
type Response = ListAllInfoResponse;
|
||||
const COMMAND: &'static str = "listallinfo";
|
||||
|
||||
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: std::str::SplitWhitespace<'_>) -> RequestParserResult<'_> {
|
||||
let uri = parts
|
||||
.next()
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
use crate::commands::{
|
||||
Command, Request, RequestParserError, RequestParserResult, ResponseAttributes,
|
||||
ResponseParserError,
|
||||
use crate::{
|
||||
commands::{
|
||||
Command, Request, RequestParserError, RequestParserResult, ResponseAttributes,
|
||||
ResponseParserError,
|
||||
},
|
||||
common::Uri,
|
||||
};
|
||||
|
||||
pub struct ListFiles;
|
||||
@@ -9,9 +12,18 @@ pub struct ListFiles;
|
||||
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: std::str::SplitWhitespace<'_>) -> RequestParserResult<'_> {
|
||||
let uri = parts
|
||||
.next()
|
||||
|
||||
@@ -1,8 +1,11 @@
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::commands::{
|
||||
Command, Request, RequestParserError, RequestParserResult, ResponseAttributes,
|
||||
ResponseParserError, expect_property_type,
|
||||
use crate::{
|
||||
commands::{
|
||||
Command, Request, RequestParserError, RequestParserResult, ResponseAttributes,
|
||||
ResponseParserError, expect_property_type,
|
||||
},
|
||||
common::Uri,
|
||||
};
|
||||
|
||||
pub struct LsInfo;
|
||||
@@ -16,9 +19,17 @@ pub struct LsInfoResponseEntry {
|
||||
}
|
||||
|
||||
impl Command for LsInfo {
|
||||
type Request = Option<Uri>;
|
||||
type Response = LsInfoResponse;
|
||||
const COMMAND: &'static str = "lsinfo";
|
||||
|
||||
fn serialize_request(&self, request: Self::Request) -> String {
|
||||
match request {
|
||||
Some(uri) => format!("{} {}", Self::COMMAND, uri),
|
||||
None => Self::COMMAND.to_string(),
|
||||
}
|
||||
}
|
||||
|
||||
fn parse_request(mut parts: std::str::SplitWhitespace<'_>) -> RequestParserResult<'_> {
|
||||
let uri = parts
|
||||
.next()
|
||||
|
||||
@@ -1,8 +1,11 @@
|
||||
use std::collections::HashMap;
|
||||
|
||||
use crate::commands::{
|
||||
Command, GenericResponseValue, Request, RequestParserError, RequestParserResult,
|
||||
ResponseAttributes, ResponseParserError,
|
||||
use crate::{
|
||||
commands::{
|
||||
Command, GenericResponseValue, Request, RequestParserError, RequestParserResult,
|
||||
ResponseAttributes, ResponseParserError,
|
||||
},
|
||||
common::Uri,
|
||||
};
|
||||
|
||||
pub struct ReadComments;
|
||||
@@ -10,9 +13,14 @@ pub struct ReadComments;
|
||||
pub type ReadCommentsResponse = HashMap<String, String>;
|
||||
|
||||
impl Command for ReadComments {
|
||||
type Request = Uri;
|
||||
type Response = ReadCommentsResponse;
|
||||
const COMMAND: &'static str = "readcomments";
|
||||
|
||||
fn serialize_request(&self, request: Self::Request) -> String {
|
||||
format!("{} {}", Self::COMMAND, request)
|
||||
}
|
||||
|
||||
fn parse_request(mut parts: std::str::SplitWhitespace<'_>) -> RequestParserResult<'_> {
|
||||
let uri = parts.next().ok_or(RequestParserError::UnexpectedEOF)?;
|
||||
let uri = uri
|
||||
|
||||
@@ -7,11 +7,17 @@ use crate::{
|
||||
Command, Request, RequestParserError, RequestParserResult, ResponseAttributes,
|
||||
ResponseParserError, get_and_parse_property, get_optional_property, get_property,
|
||||
},
|
||||
common::Offset,
|
||||
common::{Offset, Uri},
|
||||
};
|
||||
|
||||
pub struct ReadPicture;
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||
pub struct ReadPictureRequest {
|
||||
pub uri: Uri,
|
||||
pub offset: Offset,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||
pub struct ReadPictureResponse {
|
||||
pub size: usize,
|
||||
@@ -20,9 +26,14 @@ pub struct ReadPictureResponse {
|
||||
}
|
||||
|
||||
impl Command for ReadPicture {
|
||||
type Request = ReadPictureRequest;
|
||||
type Response = Option<ReadPictureResponse>;
|
||||
const COMMAND: &'static str = "readpicture";
|
||||
|
||||
fn serialize_request(&self, request: Self::Request) -> String {
|
||||
format!("{} {} {}", Self::COMMAND, request.uri, request.offset)
|
||||
}
|
||||
|
||||
fn parse_request(mut parts: std::str::SplitWhitespace<'_>) -> RequestParserResult<'_> {
|
||||
let uri = match parts.next() {
|
||||
Some(s) => s,
|
||||
|
||||
@@ -2,9 +2,12 @@ use std::collections::HashMap;
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::commands::{
|
||||
Command, Request, RequestParserResult, ResponseAttributes, ResponseParserError,
|
||||
get_and_parse_property,
|
||||
use crate::{
|
||||
commands::{
|
||||
Command, Request, RequestParserResult, ResponseAttributes, ResponseParserError,
|
||||
get_and_parse_property,
|
||||
},
|
||||
common::Uri,
|
||||
};
|
||||
|
||||
pub struct Rescan;
|
||||
@@ -15,9 +18,17 @@ pub struct RescanResponse {
|
||||
}
|
||||
|
||||
impl Command for Rescan {
|
||||
type Request = Option<Uri>;
|
||||
type Response = RescanResponse;
|
||||
const COMMAND: &'static str = "rescan";
|
||||
|
||||
fn serialize_request(&self, request: Self::Request) -> String {
|
||||
match request {
|
||||
Some(uri) => format!("{} {}", Self::COMMAND, uri),
|
||||
None => Self::COMMAND.to_string(),
|
||||
}
|
||||
}
|
||||
|
||||
fn parse_request(mut parts: std::str::SplitWhitespace<'_>) -> RequestParserResult<'_> {
|
||||
let uri = parts.next().map(|s| s.to_string());
|
||||
|
||||
|
||||
@@ -5,18 +5,38 @@ use crate::{
|
||||
Command, Request, RequestParserError, RequestParserResult, ResponseAttributes,
|
||||
ResponseParserError,
|
||||
},
|
||||
filter::parse_filter,
|
||||
common::{Sort, WindowRange},
|
||||
filter::{Filter, parse_filter},
|
||||
};
|
||||
|
||||
pub struct Search;
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||
pub struct SearchRequest {
|
||||
filter: Filter,
|
||||
sort: Option<Sort>,
|
||||
window: Option<WindowRange>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||
pub struct SearchResponse {}
|
||||
|
||||
impl Command for Search {
|
||||
type Request = SearchRequest;
|
||||
type Response = SearchResponse;
|
||||
const COMMAND: &'static str = "search";
|
||||
|
||||
fn serialize_request(&self, request: Self::Request) -> String {
|
||||
let mut cmd = format!("{} {}", Self::COMMAND, request.filter);
|
||||
if let Some(sort) = request.sort {
|
||||
cmd.push_str(&format!(" sort {}", sort));
|
||||
}
|
||||
if let Some(window) = request.window {
|
||||
cmd.push_str(&format!(" window {}", window));
|
||||
}
|
||||
cmd
|
||||
}
|
||||
|
||||
fn parse_request(mut parts: std::str::SplitWhitespace<'_>) -> RequestParserResult<'_> {
|
||||
let filter = parse_filter(&mut parts)?;
|
||||
|
||||
|
||||
@@ -1,17 +1,43 @@
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::{
|
||||
commands::{
|
||||
Command, Request, RequestParserError, RequestParserResult, ResponseAttributes,
|
||||
ResponseParserError,
|
||||
},
|
||||
filter::parse_filter,
|
||||
common::{SongPosition, Sort, WindowRange},
|
||||
filter::{Filter, parse_filter},
|
||||
};
|
||||
|
||||
pub struct SearchAdd;
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||
pub struct SearchAddRequest {
|
||||
filter: Filter,
|
||||
sort: Option<Sort>,
|
||||
window: Option<WindowRange>,
|
||||
position: Option<SongPosition>,
|
||||
}
|
||||
|
||||
impl Command for SearchAdd {
|
||||
type Request = SearchAddRequest;
|
||||
type Response = ();
|
||||
const COMMAND: &'static str = "searchadd";
|
||||
|
||||
fn serialize_request(&self, request: Self::Request) -> String {
|
||||
let mut cmd = format!("{} {}", Self::COMMAND, request.filter);
|
||||
if let Some(sort) = request.sort {
|
||||
cmd.push_str(&format!(" sort {}", sort));
|
||||
}
|
||||
if let Some(window) = request.window {
|
||||
cmd.push_str(&format!(" window {}", window));
|
||||
}
|
||||
if let Some(position) = request.position {
|
||||
cmd.push_str(&format!(" position {}", position));
|
||||
}
|
||||
cmd
|
||||
}
|
||||
|
||||
fn parse_request(mut parts: std::str::SplitWhitespace<'_>) -> RequestParserResult<'_> {
|
||||
let filter = parse_filter(&mut parts)?;
|
||||
|
||||
|
||||
@@ -1,17 +1,49 @@
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::{
|
||||
commands::{
|
||||
Command, Request, RequestParserError, RequestParserResult, ResponseAttributes,
|
||||
ResponseParserError,
|
||||
},
|
||||
filter::parse_filter,
|
||||
common::{PlaylistName, SongPosition, Sort, WindowRange},
|
||||
filter::{Filter, parse_filter},
|
||||
};
|
||||
|
||||
pub struct SearchAddPl;
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||
pub struct SearchAddPlRequest {
|
||||
playlist_name: PlaylistName,
|
||||
filter: Filter,
|
||||
sort: Option<Sort>,
|
||||
window: Option<WindowRange>,
|
||||
position: Option<SongPosition>,
|
||||
}
|
||||
|
||||
impl Command for SearchAddPl {
|
||||
type Request = SearchAddPlRequest;
|
||||
type Response = ();
|
||||
const COMMAND: &'static str = "searchaddpl";
|
||||
|
||||
fn serialize_request(&self, request: Self::Request) -> String {
|
||||
let mut cmd = format!(
|
||||
"{} {} {}",
|
||||
Self::COMMAND,
|
||||
request.playlist_name,
|
||||
request.filter
|
||||
);
|
||||
if let Some(sort) = request.sort {
|
||||
cmd.push_str(&format!(" sort {}", sort));
|
||||
}
|
||||
if let Some(window) = request.window {
|
||||
cmd.push_str(&format!(" window {}", window));
|
||||
}
|
||||
if let Some(position) = request.position {
|
||||
cmd.push_str(&format!(" position {}", position));
|
||||
}
|
||||
cmd
|
||||
}
|
||||
|
||||
fn parse_request(mut parts: std::str::SplitWhitespace<'_>) -> RequestParserResult<'_> {
|
||||
let playlist_name = parts
|
||||
.next()
|
||||
|
||||
@@ -7,11 +7,18 @@ use crate::{
|
||||
Command, Request, RequestParserError, RequestParserResult, ResponseAttributes,
|
||||
ResponseParserError, get_and_parse_property,
|
||||
},
|
||||
filter::parse_filter,
|
||||
common::GroupType,
|
||||
filter::{Filter, parse_filter},
|
||||
};
|
||||
|
||||
pub struct SearchCount;
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||
pub struct SearchCountRequest {
|
||||
filter: Filter,
|
||||
group: Option<GroupType>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||
pub struct SearchCountResponse {
|
||||
pub songs: usize,
|
||||
@@ -19,9 +26,18 @@ pub struct SearchCountResponse {
|
||||
}
|
||||
|
||||
impl Command for SearchCount {
|
||||
type Request = SearchCountRequest;
|
||||
type Response = SearchCountResponse;
|
||||
const COMMAND: &'static str = "searchcount";
|
||||
|
||||
fn serialize_request(&self, request: Self::Request) -> String {
|
||||
let mut cmd = format!("{} {}", Self::COMMAND, request.filter);
|
||||
if let Some(group) = request.group {
|
||||
cmd.push_str(&format!(" group {}", group));
|
||||
}
|
||||
cmd
|
||||
}
|
||||
|
||||
fn parse_request(mut parts: std::str::SplitWhitespace<'_>) -> RequestParserResult<'_> {
|
||||
let filter = parse_filter(&mut parts)?;
|
||||
|
||||
|
||||
@@ -2,9 +2,12 @@ use std::collections::HashMap;
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::commands::{
|
||||
Command, Request, RequestParserResult, ResponseAttributes, ResponseParserError,
|
||||
get_and_parse_property,
|
||||
use crate::{
|
||||
commands::{
|
||||
Command, Request, RequestParserResult, ResponseAttributes, ResponseParserError,
|
||||
get_and_parse_property,
|
||||
},
|
||||
common::Uri,
|
||||
};
|
||||
|
||||
pub struct Update;
|
||||
@@ -15,9 +18,17 @@ pub struct UpdateResponse {
|
||||
}
|
||||
|
||||
impl Command for Update {
|
||||
type Request = Option<Uri>;
|
||||
type Response = UpdateResponse;
|
||||
const COMMAND: &'static str = "update";
|
||||
|
||||
fn serialize_request(&self, request: Self::Request) -> String {
|
||||
match request {
|
||||
Some(uri) => format!("{} {}", Self::COMMAND, uri),
|
||||
None => Self::COMMAND.to_string(),
|
||||
}
|
||||
}
|
||||
|
||||
fn parse_request(mut parts: std::str::SplitWhitespace<'_>) -> RequestParserResult<'_> {
|
||||
let uri = parts.next().map(|s| s.to_string());
|
||||
|
||||
|
||||
@@ -1,14 +1,22 @@
|
||||
use crate::commands::{
|
||||
Command, Request, RequestParserError, RequestParserResult, ResponseAttributes,
|
||||
ResponseParserError,
|
||||
use crate::{
|
||||
commands::{
|
||||
Command, Request, RequestParserError, RequestParserResult, ResponseAttributes,
|
||||
ResponseParserError,
|
||||
},
|
||||
common::PartitionName,
|
||||
};
|
||||
|
||||
pub struct DelPartition;
|
||||
|
||||
impl Command for DelPartition {
|
||||
type Request = PartitionName;
|
||||
type Response = ();
|
||||
const COMMAND: &'static str = "delpartition";
|
||||
|
||||
fn serialize_request(&self, request: Self::Request) -> String {
|
||||
format!("{} {}", Self::COMMAND, request)
|
||||
}
|
||||
|
||||
fn parse_request(mut parts: std::str::SplitWhitespace<'_>) -> RequestParserResult<'_> {
|
||||
let partition = parts
|
||||
.next()
|
||||
|
||||
@@ -1,16 +1,24 @@
|
||||
use crate::commands::{
|
||||
Command, Request, RequestParserResult, ResponseAttributes, ResponseParserError,
|
||||
expect_property_type,
|
||||
use crate::{
|
||||
commands::{
|
||||
Command, Request, RequestParserResult, ResponseAttributes, ResponseParserError,
|
||||
expect_property_type,
|
||||
},
|
||||
common::PartitionName,
|
||||
};
|
||||
|
||||
pub struct ListPartitions;
|
||||
|
||||
pub type ListPartitionsResponse = Vec<String>;
|
||||
pub type ListPartitionsResponse = Vec<PartitionName>;
|
||||
|
||||
impl Command for ListPartitions {
|
||||
type Request = ();
|
||||
type Response = ListPartitionsResponse;
|
||||
const COMMAND: &'static str = "listpartitions";
|
||||
|
||||
fn serialize_request(&self, _request: Self::Request) -> String {
|
||||
Self::COMMAND.to_string()
|
||||
}
|
||||
|
||||
fn parse_request(mut parts: std::str::SplitWhitespace<'_>) -> RequestParserResult<'_> {
|
||||
debug_assert!(parts.next().is_none());
|
||||
Ok((Request::ListPartitions, ""))
|
||||
|
||||
@@ -6,9 +6,14 @@ use crate::commands::{
|
||||
pub struct MoveOutput;
|
||||
|
||||
impl Command for MoveOutput {
|
||||
type Request = String;
|
||||
type Response = ();
|
||||
const COMMAND: &'static str = "moveoutput";
|
||||
|
||||
fn serialize_request(&self, request: Self::Request) -> String {
|
||||
format!("{} {}", Self::COMMAND, request)
|
||||
}
|
||||
|
||||
fn parse_request(mut parts: std::str::SplitWhitespace<'_>) -> RequestParserResult<'_> {
|
||||
let output_name = parts
|
||||
.next()
|
||||
|
||||
@@ -1,14 +1,22 @@
|
||||
use crate::commands::{
|
||||
Command, Request, RequestParserError, RequestParserResult, ResponseAttributes,
|
||||
ResponseParserError,
|
||||
use crate::{
|
||||
commands::{
|
||||
Command, Request, RequestParserError, RequestParserResult, ResponseAttributes,
|
||||
ResponseParserError,
|
||||
},
|
||||
common::PartitionName,
|
||||
};
|
||||
|
||||
pub struct NewPartition;
|
||||
|
||||
impl Command for NewPartition {
|
||||
type Request = PartitionName;
|
||||
type Response = ();
|
||||
const COMMAND: &'static str = "newpartition";
|
||||
|
||||
fn serialize_request(&self, request: Self::Request) -> String {
|
||||
format!("{} {}", Self::COMMAND, request)
|
||||
}
|
||||
|
||||
fn parse_request(mut parts: std::str::SplitWhitespace<'_>) -> RequestParserResult<'_> {
|
||||
let partition = parts
|
||||
.next()
|
||||
|
||||
@@ -1,14 +1,22 @@
|
||||
use crate::commands::{
|
||||
Command, Request, RequestParserError, RequestParserResult, ResponseAttributes,
|
||||
ResponseParserError,
|
||||
use crate::{
|
||||
commands::{
|
||||
Command, Request, RequestParserError, RequestParserResult, ResponseAttributes,
|
||||
ResponseParserError,
|
||||
},
|
||||
common::PartitionName,
|
||||
};
|
||||
|
||||
pub struct Partition;
|
||||
|
||||
impl Command for Partition {
|
||||
type Request = PartitionName;
|
||||
type Response = ();
|
||||
const COMMAND: &'static str = "partition";
|
||||
|
||||
fn serialize_request(&self, request: Self::Request) -> String {
|
||||
format!("{} {}", Self::COMMAND, request)
|
||||
}
|
||||
|
||||
fn parse_request(mut parts: std::str::SplitWhitespace<'_>) -> RequestParserResult<'_> {
|
||||
let partition = parts
|
||||
.next()
|
||||
|
||||
@@ -1,16 +1,24 @@
|
||||
use std::str::FromStr;
|
||||
|
||||
use crate::commands::{
|
||||
Command, Request, RequestParserError, RequestParserResult, ResponseAttributes,
|
||||
ResponseParserError,
|
||||
use crate::{
|
||||
commands::{
|
||||
Command, Request, RequestParserError, RequestParserResult, ResponseAttributes,
|
||||
ResponseParserError,
|
||||
},
|
||||
common::BoolOrOneshot,
|
||||
};
|
||||
|
||||
pub struct Consume;
|
||||
|
||||
impl Command for Consume {
|
||||
type Request = BoolOrOneshot;
|
||||
type Response = ();
|
||||
const COMMAND: &'static str = "consume";
|
||||
|
||||
fn serialize_request(&self, request: Self::Request) -> String {
|
||||
format!("{} {}", Self::COMMAND, request)
|
||||
}
|
||||
|
||||
fn parse_request(mut parts: std::str::SplitWhitespace<'_>) -> RequestParserResult<'_> {
|
||||
let state = match parts.next() {
|
||||
Some(s) => crate::common::BoolOrOneshot::from_str(s)
|
||||
|
||||
@@ -9,9 +9,14 @@ use crate::{
|
||||
pub struct Crossfade;
|
||||
|
||||
impl Command for Crossfade {
|
||||
type Request = Seconds;
|
||||
type Response = ();
|
||||
const COMMAND: &'static str = "crossfade";
|
||||
|
||||
fn serialize_request(&self, request: Self::Request) -> String {
|
||||
format!("{} {}", Self::COMMAND, request)
|
||||
}
|
||||
|
||||
fn parse_request(mut parts: std::str::SplitWhitespace<'_>) -> RequestParserResult<'_> {
|
||||
let seconds = match parts.next() {
|
||||
Some(s) => s
|
||||
|
||||
@@ -11,9 +11,14 @@ use crate::{
|
||||
pub struct GetVol;
|
||||
|
||||
impl Command for GetVol {
|
||||
type Request = ();
|
||||
type Response = VolumeValue;
|
||||
const COMMAND: &'static str = "getvol";
|
||||
|
||||
fn serialize_request(&self, _request: Self::Request) -> String {
|
||||
Self::COMMAND.to_string()
|
||||
}
|
||||
|
||||
fn parse_request(mut parts: std::str::SplitWhitespace<'_>) -> RequestParserResult<'_> {
|
||||
debug_assert!(parts.next().is_none());
|
||||
Ok((Request::GetVol, ""))
|
||||
|
||||
@@ -6,9 +6,14 @@ use crate::commands::{
|
||||
pub struct MixRampDb;
|
||||
|
||||
impl Command for MixRampDb {
|
||||
type Request = f32;
|
||||
type Response = ();
|
||||
const COMMAND: &'static str = "mixrampdb";
|
||||
|
||||
fn serialize_request(&self, request: Self::Request) -> String {
|
||||
format!("{} {}", Self::COMMAND, request)
|
||||
}
|
||||
|
||||
fn parse_request(mut parts: std::str::SplitWhitespace<'_>) -> RequestParserResult<'_> {
|
||||
let db = match parts.next() {
|
||||
Some(s) => s
|
||||
|
||||
@@ -9,9 +9,14 @@ use crate::{
|
||||
pub struct MixRampDelay;
|
||||
|
||||
impl Command for MixRampDelay {
|
||||
type Request = Seconds;
|
||||
type Response = ();
|
||||
const COMMAND: &'static str = "mixrampdelay";
|
||||
|
||||
fn serialize_request(&self, request: Self::Request) -> String {
|
||||
format!("{} {}", Self::COMMAND, request)
|
||||
}
|
||||
|
||||
fn parse_request(mut parts: std::str::SplitWhitespace<'_>) -> RequestParserResult<'_> {
|
||||
let seconds = match parts.next() {
|
||||
Some(s) => s
|
||||
|
||||
@@ -6,9 +6,15 @@ use crate::commands::{
|
||||
pub struct Random;
|
||||
|
||||
impl Command for Random {
|
||||
type Request = bool;
|
||||
type Response = ();
|
||||
const COMMAND: &'static str = "random";
|
||||
|
||||
fn serialize_request(&self, request: Self::Request) -> String {
|
||||
let state = if request { "1" } else { "0" };
|
||||
format!("{} {}", Self::COMMAND, state)
|
||||
}
|
||||
|
||||
fn parse_request(mut parts: std::str::SplitWhitespace<'_>) -> RequestParserResult<'_> {
|
||||
let state = match parts.next() {
|
||||
Some("0") => false,
|
||||
|
||||
@@ -6,9 +6,15 @@ use crate::commands::{
|
||||
pub struct Repeat;
|
||||
|
||||
impl Command for Repeat {
|
||||
type Request = bool;
|
||||
type Response = ();
|
||||
const COMMAND: &'static str = "repeat";
|
||||
|
||||
fn serialize_request(&self, request: Self::Request) -> String {
|
||||
let state = if request { "1" } else { "0" };
|
||||
format!("{} {}", Self::COMMAND, state)
|
||||
}
|
||||
|
||||
fn parse_request(mut parts: std::str::SplitWhitespace<'_>) -> RequestParserResult<'_> {
|
||||
let state = match parts.next() {
|
||||
Some("0") => false,
|
||||
|
||||
@@ -11,9 +11,14 @@ use crate::{
|
||||
pub struct ReplayGainMode;
|
||||
|
||||
impl Command for ReplayGainMode {
|
||||
type Request = ReplayGainModeMode;
|
||||
type Response = ();
|
||||
const COMMAND: &'static str = "replay_gain_mode";
|
||||
|
||||
fn serialize_request(&self, request: Self::Request) -> String {
|
||||
format!("{} {}", Self::COMMAND, request)
|
||||
}
|
||||
|
||||
fn parse_request(mut parts: std::str::SplitWhitespace<'_>) -> RequestParserResult<'_> {
|
||||
let mode = match parts.next() {
|
||||
Some(s) => ReplayGainModeMode::from_str(s)
|
||||
|
||||
@@ -18,9 +18,14 @@ pub struct ReplayGainStatusResponse {
|
||||
}
|
||||
|
||||
impl Command for ReplayGainStatus {
|
||||
type Request = ();
|
||||
type Response = ReplayGainStatusResponse;
|
||||
const COMMAND: &'static str = "replay_gain_status";
|
||||
|
||||
fn serialize_request(&self, _: Self::Request) -> String {
|
||||
Self::COMMAND.to_string()
|
||||
}
|
||||
|
||||
fn parse_request(mut parts: std::str::SplitWhitespace<'_>) -> RequestParserResult<'_> {
|
||||
debug_assert!(parts.next().is_none());
|
||||
Ok((Request::ReplayGainStatus, ""))
|
||||
|
||||
@@ -11,9 +11,14 @@ use crate::{
|
||||
pub struct SetVol;
|
||||
|
||||
impl Command for SetVol {
|
||||
type Request = VolumeValue;
|
||||
type Response = ();
|
||||
const COMMAND: &'static str = "setvol";
|
||||
|
||||
fn serialize_request(&self, request: Self::Request) -> String {
|
||||
format!("{} {}", Self::COMMAND, request)
|
||||
}
|
||||
|
||||
fn parse_request(mut parts: std::str::SplitWhitespace<'_>) -> RequestParserResult<'_> {
|
||||
let volume = match parts.next() {
|
||||
Some(s) => VolumeValue::from_str(s)
|
||||
|
||||
@@ -1,16 +1,24 @@
|
||||
use std::str::FromStr;
|
||||
|
||||
use crate::commands::{
|
||||
Command, Request, RequestParserError, RequestParserResult, ResponseAttributes,
|
||||
ResponseParserError,
|
||||
use crate::{
|
||||
commands::{
|
||||
Command, Request, RequestParserError, RequestParserResult, ResponseAttributes,
|
||||
ResponseParserError,
|
||||
},
|
||||
common::BoolOrOneshot,
|
||||
};
|
||||
|
||||
pub struct Single;
|
||||
|
||||
impl Command for Single {
|
||||
type Request = BoolOrOneshot;
|
||||
type Response = ();
|
||||
const COMMAND: &'static str = "single";
|
||||
|
||||
fn serialize_request(&self, request: Self::Request) -> String {
|
||||
format!("{} {}", Self::COMMAND, request)
|
||||
}
|
||||
|
||||
fn parse_request(mut parts: std::str::SplitWhitespace<'_>) -> RequestParserResult<'_> {
|
||||
let state = match parts.next() {
|
||||
Some(s) => crate::common::BoolOrOneshot::from_str(s)
|
||||
|
||||
@@ -11,9 +11,14 @@ use crate::{
|
||||
pub struct Volume;
|
||||
|
||||
impl Command for Volume {
|
||||
type Request = VolumeValue;
|
||||
type Response = ();
|
||||
const COMMAND: &'static str = "volume";
|
||||
|
||||
fn serialize_request(&self, request: Self::Request) -> String {
|
||||
format!("{} {}", Self::COMMAND, request)
|
||||
}
|
||||
|
||||
fn parse_request(mut parts: std::str::SplitWhitespace<'_>) -> RequestParserResult<'_> {
|
||||
let change = match parts.next() {
|
||||
Some(s) => VolumeValue::from_str(s)
|
||||
|
||||
@@ -6,9 +6,14 @@ use crate::commands::{
|
||||
pub struct ClearError;
|
||||
|
||||
impl Command for ClearError {
|
||||
type Request = ();
|
||||
type Response = ();
|
||||
const COMMAND: &'static str = "clearerror";
|
||||
|
||||
fn serialize_request(&self, _request: Self::Request) -> String {
|
||||
Self::COMMAND.to_string()
|
||||
}
|
||||
|
||||
fn parse_request(mut parts: std::str::SplitWhitespace<'_>) -> RequestParserResult<'_> {
|
||||
debug_assert!(parts.next().is_none());
|
||||
|
||||
|
||||
@@ -11,9 +11,14 @@ pub struct CurrentSong;
|
||||
pub struct CurrentSongResponse {}
|
||||
|
||||
impl Command for CurrentSong {
|
||||
type Request = ();
|
||||
type Response = CurrentSongResponse;
|
||||
const COMMAND: &'static str = "currentsong";
|
||||
|
||||
fn serialize_request(&self, _request: Self::Request) -> String {
|
||||
Self::COMMAND.to_string()
|
||||
}
|
||||
|
||||
fn parse_request(mut parts: std::str::SplitWhitespace<'_>) -> RequestParserResult<'_> {
|
||||
debug_assert!(parts.next().is_none());
|
||||
|
||||
|
||||
@@ -8,10 +8,27 @@ use crate::commands::{
|
||||
|
||||
pub struct Idle;
|
||||
|
||||
pub type IdleRequest = Option<Vec<SubSystem>>;
|
||||
|
||||
impl Command for Idle {
|
||||
type Request = IdleRequest;
|
||||
type Response = ();
|
||||
const COMMAND: &'static str = "idle";
|
||||
|
||||
fn serialize_request(&self, request: Self::Request) -> String {
|
||||
match request {
|
||||
Some(subsystems) => {
|
||||
let subsystems_str = subsystems
|
||||
.iter()
|
||||
.map(|subsystem| subsystem.to_string())
|
||||
.collect::<Vec<_>>()
|
||||
.join(",");
|
||||
format!("{} {}", Self::COMMAND, subsystems_str)
|
||||
}
|
||||
None => Self::COMMAND.to_string(),
|
||||
}
|
||||
}
|
||||
|
||||
fn parse_request(mut parts: SplitWhitespace<'_>) -> RequestParserResult<'_> {
|
||||
let result = parts
|
||||
.next()
|
||||
|
||||
@@ -21,9 +21,14 @@ pub struct StatsResponse {
|
||||
}
|
||||
|
||||
impl Command for Stats {
|
||||
type Request = ();
|
||||
type Response = StatsResponse;
|
||||
const COMMAND: &'static str = "stats";
|
||||
|
||||
fn serialize_request(&self, _: Self::Request) -> String {
|
||||
Self::COMMAND.to_string()
|
||||
}
|
||||
|
||||
fn parse_request(mut parts: std::str::SplitWhitespace<'_>) -> RequestParserResult<'_> {
|
||||
debug_assert!(parts.next().is_none());
|
||||
|
||||
|
||||
@@ -159,9 +159,14 @@ fn parse_status_response(
|
||||
pub struct Status;
|
||||
|
||||
impl Command for Status {
|
||||
type Request = ();
|
||||
type Response = StatusResponse;
|
||||
const COMMAND: &'static str = "status";
|
||||
|
||||
fn serialize_request(&self, _request: Self::Request) -> String {
|
||||
Self::COMMAND.to_string()
|
||||
}
|
||||
|
||||
fn parse_request(mut parts: std::str::SplitWhitespace<'_>) -> RequestParserResult<'_> {
|
||||
debug_assert!(parts.next().is_none());
|
||||
|
||||
|
||||
@@ -1,17 +1,33 @@
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::{
|
||||
commands::{
|
||||
Command, Request, RequestParserError, RequestParserResult, ResponseAttributes,
|
||||
ResponseParserError,
|
||||
},
|
||||
common::SongPosition,
|
||||
common::{SongPosition, Uri},
|
||||
};
|
||||
|
||||
pub struct Add;
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||
pub struct AddRequest {
|
||||
uri: Uri,
|
||||
position: Option<SongPosition>,
|
||||
}
|
||||
|
||||
impl Command for Add {
|
||||
type Request = AddRequest;
|
||||
type Response = ();
|
||||
const COMMAND: &'static str = "add";
|
||||
|
||||
fn serialize_request(&self, request: Self::Request) -> String {
|
||||
match request.position {
|
||||
Some(position) => format!("{} {} {}", Self::COMMAND, request.uri, position),
|
||||
None => format!("{} {}", Self::COMMAND, request.uri),
|
||||
}
|
||||
}
|
||||
|
||||
fn parse_request(mut parts: std::str::SplitWhitespace<'_>) -> RequestParserResult<'_> {
|
||||
let uri = match parts.next() {
|
||||
Some(s) => s,
|
||||
|
||||
@@ -5,20 +5,34 @@ use crate::{
|
||||
Command, Request, RequestParserError, RequestParserResult, ResponseAttributes,
|
||||
ResponseParserError, get_next_and_parse_property,
|
||||
},
|
||||
common::{SongId, SongPosition},
|
||||
common::{SongId, SongPosition, Uri},
|
||||
};
|
||||
|
||||
pub struct AddId;
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||
pub struct AddIdRequest {
|
||||
pub uri: Uri,
|
||||
pub position: Option<SongPosition>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||
pub struct AddIdResponse {
|
||||
pub id: SongId,
|
||||
}
|
||||
|
||||
impl Command for AddId {
|
||||
type Request = AddIdRequest;
|
||||
type Response = AddIdResponse;
|
||||
const COMMAND: &'static str = "addid";
|
||||
|
||||
fn serialize_request(&self, request: Self::Request) -> String {
|
||||
match request.position {
|
||||
Some(pos) => format!("{} {} {}", Self::COMMAND, request.uri, pos),
|
||||
None => format!("{} {}", Self::COMMAND, request.uri),
|
||||
}
|
||||
}
|
||||
|
||||
fn parse_request(mut parts: std::str::SplitWhitespace<'_>) -> RequestParserResult<'_> {
|
||||
let uri = match parts.next() {
|
||||
Some(s) => s,
|
||||
|
||||
@@ -1,16 +1,37 @@
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::{
|
||||
Request,
|
||||
commands::{
|
||||
Command, RequestParserError, RequestParserResult, ResponseAttributes, ResponseParserError,
|
||||
},
|
||||
common::{SongId, TagName, TagValue},
|
||||
};
|
||||
|
||||
pub struct AddTagId;
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||
pub struct AddTagIdRequest {
|
||||
pub songid: SongId,
|
||||
pub tag_name: TagName,
|
||||
pub tag_value: TagValue,
|
||||
}
|
||||
|
||||
impl Command for AddTagId {
|
||||
type Request = AddTagIdRequest;
|
||||
type Response = ();
|
||||
const COMMAND: &'static str = "addtagid";
|
||||
|
||||
fn serialize_request(&self, request: Self::Request) -> String {
|
||||
format!(
|
||||
"{} {} {} {}",
|
||||
Self::COMMAND,
|
||||
request.songid,
|
||||
request.tag_name,
|
||||
request.tag_value
|
||||
)
|
||||
}
|
||||
|
||||
fn parse_request(mut parts: std::str::SplitWhitespace<'_>) -> RequestParserResult<'_> {
|
||||
let songid = parts.next().ok_or(RequestParserError::UnexpectedEOF)?;
|
||||
let songid = songid
|
||||
|
||||
@@ -5,9 +5,14 @@ use crate::commands::{
|
||||
pub struct Clear;
|
||||
|
||||
impl Command for Clear {
|
||||
type Request = ();
|
||||
type Response = ();
|
||||
const COMMAND: &'static str = "clear";
|
||||
|
||||
fn serialize_request(&self, _request: Self::Request) -> String {
|
||||
Self::COMMAND.to_string()
|
||||
}
|
||||
|
||||
fn parse_request(mut parts: std::str::SplitWhitespace<'_>) -> RequestParserResult<'_> {
|
||||
debug_assert!(parts.next().is_none());
|
||||
Ok((Request::Clear, ""))
|
||||
|
||||
@@ -1,16 +1,30 @@
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::{
|
||||
Request,
|
||||
commands::{
|
||||
Command, RequestParserError, RequestParserResult, ResponseAttributes, ResponseParserError,
|
||||
},
|
||||
common::{SongId, TagName},
|
||||
};
|
||||
|
||||
pub struct ClearTagId;
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||
pub struct ClearTagIdRequest {
|
||||
pub songid: SongId,
|
||||
pub tag_name: TagName,
|
||||
}
|
||||
|
||||
impl Command for ClearTagId {
|
||||
type Request = ClearTagIdRequest;
|
||||
type Response = ();
|
||||
const COMMAND: &'static str = "cleartagid";
|
||||
|
||||
fn serialize_request(&self, request: Self::Request) -> String {
|
||||
format!("{} {} {}", Self::COMMAND, request.songid, request.tag_name)
|
||||
}
|
||||
|
||||
fn parse_request(mut parts: std::str::SplitWhitespace<'_>) -> RequestParserResult<'_> {
|
||||
let songid = parts.next().ok_or(RequestParserError::UnexpectedEOF)?;
|
||||
let songid = songid
|
||||
|
||||
@@ -11,9 +11,14 @@ use crate::{
|
||||
pub struct Delete;
|
||||
|
||||
impl Command for Delete {
|
||||
type Request = OneOrRange;
|
||||
type Response = ();
|
||||
const COMMAND: &'static str = "delete";
|
||||
|
||||
fn serialize_request(&self, request: Self::Request) -> String {
|
||||
format!("{} {}", Self::COMMAND, request)
|
||||
}
|
||||
|
||||
fn parse_request(mut parts: std::str::SplitWhitespace<'_>) -> RequestParserResult<'_> {
|
||||
let pos_or_range = parts.next().ok_or(RequestParserError::UnexpectedEOF)?;
|
||||
let one_or_range = OneOrRange::from_str(pos_or_range)
|
||||
|
||||
@@ -3,14 +3,20 @@ use crate::{
|
||||
commands::{
|
||||
Command, RequestParserError, RequestParserResult, ResponseAttributes, ResponseParserError,
|
||||
},
|
||||
common::SongId,
|
||||
};
|
||||
|
||||
pub struct DeleteId;
|
||||
|
||||
impl Command for DeleteId {
|
||||
type Request = SongId;
|
||||
type Response = ();
|
||||
const COMMAND: &'static str = "deleteid";
|
||||
|
||||
fn serialize_request(&self, request: Self::Request) -> String {
|
||||
format!("{} {}", Self::COMMAND, request)
|
||||
}
|
||||
|
||||
fn parse_request(mut parts: std::str::SplitWhitespace<'_>) -> RequestParserResult<'_> {
|
||||
let id = parts.next().ok_or(RequestParserError::UnexpectedEOF)?;
|
||||
let id = id
|
||||
|
||||
@@ -1,16 +1,30 @@
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::{
|
||||
Request,
|
||||
commands::{
|
||||
Command, RequestParserError, RequestParserResult, ResponseAttributes, ResponseParserError,
|
||||
},
|
||||
common::{AbsouluteRelativeSongPosition, OneOrRange},
|
||||
};
|
||||
|
||||
pub struct Move;
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||
pub struct MoveRequest {
|
||||
pub from_or_range: OneOrRange,
|
||||
pub to: AbsouluteRelativeSongPosition,
|
||||
}
|
||||
|
||||
impl Command for Move {
|
||||
type Request = MoveRequest;
|
||||
type Response = ();
|
||||
const COMMAND: &'static str = "move";
|
||||
|
||||
fn serialize_request(&self, request: Self::Request) -> String {
|
||||
format!("{} {} {}", Self::COMMAND, request.from_or_range, request.to)
|
||||
}
|
||||
|
||||
fn parse_request(mut parts: std::str::SplitWhitespace<'_>) -> RequestParserResult<'_> {
|
||||
let from_or_range = parts.next().ok_or(RequestParserError::UnexpectedEOF)?;
|
||||
let from_or_range = from_or_range
|
||||
|
||||
@@ -1,16 +1,30 @@
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::{
|
||||
Request,
|
||||
commands::{
|
||||
Command, RequestParserError, RequestParserResult, ResponseAttributes, ResponseParserError,
|
||||
},
|
||||
common::{AbsouluteRelativeSongPosition, SongId},
|
||||
};
|
||||
|
||||
pub struct MoveId;
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||
pub struct MoveIdRequest {
|
||||
pub id: SongId,
|
||||
pub to: AbsouluteRelativeSongPosition,
|
||||
}
|
||||
|
||||
impl Command for MoveId {
|
||||
type Request = MoveIdRequest;
|
||||
type Response = ();
|
||||
const COMMAND: &'static str = "moveid";
|
||||
|
||||
fn serialize_request(&self, request: Self::Request) -> String {
|
||||
format!("{} {} {}", Self::COMMAND, request.id, request.to)
|
||||
}
|
||||
|
||||
fn parse_request(mut parts: std::str::SplitWhitespace<'_>) -> RequestParserResult<'_> {
|
||||
let id = parts.next().ok_or(RequestParserError::UnexpectedEOF)?;
|
||||
let id = id
|
||||
|
||||
@@ -6,9 +6,14 @@ use crate::{
|
||||
pub struct Playlist;
|
||||
|
||||
impl Command for Playlist {
|
||||
type Request = ();
|
||||
type Response = ();
|
||||
const COMMAND: &'static str = "playlist";
|
||||
|
||||
fn serialize_request(&self, _request: Self::Request) -> String {
|
||||
Self::COMMAND.to_string()
|
||||
}
|
||||
|
||||
fn parse_request(mut parts: std::str::SplitWhitespace<'_>) -> RequestParserResult<'_> {
|
||||
debug_assert!(parts.next().is_none());
|
||||
Ok((Request::Playlist, ""))
|
||||
|
||||
@@ -1,17 +1,39 @@
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::{
|
||||
Request,
|
||||
commands::{
|
||||
Command, RequestParserError, RequestParserResult, ResponseAttributes, ResponseParserError,
|
||||
},
|
||||
filter::parse_filter,
|
||||
common::{Sort, WindowRange},
|
||||
filter::{Filter, parse_filter},
|
||||
};
|
||||
|
||||
pub struct PlaylistFind;
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||
pub struct PlaylistFindRequest {
|
||||
filter: Filter,
|
||||
sort: Option<Sort>,
|
||||
window: Option<WindowRange>,
|
||||
}
|
||||
|
||||
impl Command for PlaylistFind {
|
||||
type Request = PlaylistFindRequest;
|
||||
type Response = ();
|
||||
const COMMAND: &'static str = "playlistfind";
|
||||
|
||||
fn serialize_request(&self, request: Self::Request) -> String {
|
||||
let mut cmd = format!("{} {}", Self::COMMAND, request.filter);
|
||||
if let Some(sort) = request.sort {
|
||||
cmd.push_str(&format!(" sort {}", sort));
|
||||
}
|
||||
if let Some(window) = request.window {
|
||||
cmd.push_str(&format!(" window {}", window));
|
||||
}
|
||||
cmd
|
||||
}
|
||||
|
||||
fn parse_request(mut parts: std::str::SplitWhitespace<'_>) -> RequestParserResult<'_> {
|
||||
let filter = parse_filter(&mut parts)?;
|
||||
|
||||
|
||||
@@ -3,14 +3,20 @@ use crate::{
|
||||
commands::{
|
||||
Command, RequestParserError, RequestParserResult, ResponseAttributes, ResponseParserError,
|
||||
},
|
||||
common::SongId,
|
||||
};
|
||||
|
||||
pub struct PlaylistId;
|
||||
|
||||
impl Command for PlaylistId {
|
||||
type Request = SongId;
|
||||
type Response = ();
|
||||
const COMMAND: &'static str = "playlistid";
|
||||
|
||||
fn serialize_request(&self, request: Self::Request) -> String {
|
||||
format!("{} {}", Self::COMMAND, request)
|
||||
}
|
||||
|
||||
fn parse_request(mut parts: std::str::SplitWhitespace<'_>) -> RequestParserResult<'_> {
|
||||
let id = parts.next().ok_or(RequestParserError::UnexpectedEOF)?;
|
||||
let id = id
|
||||
|
||||
@@ -3,14 +3,23 @@ use crate::{
|
||||
commands::{
|
||||
Command, RequestParserError, RequestParserResult, ResponseAttributes, ResponseParserError,
|
||||
},
|
||||
common::OneOrRange,
|
||||
};
|
||||
|
||||
pub struct PlaylistInfo;
|
||||
|
||||
impl Command for PlaylistInfo {
|
||||
type Request = Option<OneOrRange>;
|
||||
type Response = ();
|
||||
const COMMAND: &'static str = "playlistinfo";
|
||||
|
||||
fn serialize_request(&self, request: Self::Request) -> String {
|
||||
match request {
|
||||
Some(one_or_range) => format!("{} {}", Self::COMMAND, one_or_range),
|
||||
None => Self::COMMAND.to_string(),
|
||||
}
|
||||
}
|
||||
|
||||
fn parse_request(mut parts: std::str::SplitWhitespace<'_>) -> RequestParserResult<'_> {
|
||||
let one_or_range = parts
|
||||
.next()
|
||||
|
||||
@@ -1,17 +1,39 @@
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::{
|
||||
Request,
|
||||
commands::{
|
||||
Command, RequestParserError, RequestParserResult, ResponseAttributes, ResponseParserError,
|
||||
},
|
||||
filter::parse_filter,
|
||||
common::{Sort, WindowRange},
|
||||
filter::{Filter, parse_filter},
|
||||
};
|
||||
|
||||
pub struct PlaylistSearch;
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||
pub struct PlaylistSearchRequest {
|
||||
filter: Filter,
|
||||
sort: Option<Sort>,
|
||||
window: Option<WindowRange>,
|
||||
}
|
||||
|
||||
impl Command for PlaylistSearch {
|
||||
type Request = PlaylistSearchRequest;
|
||||
type Response = ();
|
||||
const COMMAND: &'static str = "playlistsearch";
|
||||
|
||||
fn serialize_request(&self, request: Self::Request) -> String {
|
||||
let mut cmd = format!("{} {}", Self::COMMAND, request.filter);
|
||||
if let Some(sort) = request.sort {
|
||||
cmd.push_str(&format!(" sort {}", sort));
|
||||
}
|
||||
if let Some(window) = request.window {
|
||||
cmd.push_str(&format!(" window {}", window));
|
||||
}
|
||||
cmd
|
||||
}
|
||||
|
||||
fn parse_request(mut parts: std::str::SplitWhitespace<'_>) -> RequestParserResult<'_> {
|
||||
let filter = parse_filter(&mut parts)?;
|
||||
|
||||
|
||||
@@ -1,16 +1,33 @@
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::{
|
||||
Request,
|
||||
commands::{
|
||||
Command, RequestParserError, RequestParserResult, ResponseAttributes, ResponseParserError,
|
||||
},
|
||||
common::{Version, WindowRange},
|
||||
};
|
||||
|
||||
pub struct PlChanges;
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||
pub struct PlChangesRequest {
|
||||
pub version: Version,
|
||||
pub window: Option<WindowRange>,
|
||||
}
|
||||
|
||||
impl Command for PlChanges {
|
||||
type Request = PlChangesRequest;
|
||||
type Response = ();
|
||||
const COMMAND: &'static str = "plchanges";
|
||||
|
||||
fn serialize_request(&self, request: Self::Request) -> String {
|
||||
match request.window {
|
||||
Some(window) => format!("{} {} {}", Self::COMMAND, request.version, window),
|
||||
None => format!("{} {}", Self::COMMAND, request.version),
|
||||
}
|
||||
}
|
||||
|
||||
fn parse_request(mut parts: std::str::SplitWhitespace<'_>) -> RequestParserResult<'_> {
|
||||
let version = parts.next().ok_or(RequestParserError::UnexpectedEOF)?;
|
||||
let version = version
|
||||
|
||||
@@ -1,16 +1,33 @@
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::{
|
||||
Request,
|
||||
commands::{
|
||||
Command, RequestParserError, RequestParserResult, ResponseAttributes, ResponseParserError,
|
||||
},
|
||||
common::{Version, WindowRange},
|
||||
};
|
||||
|
||||
pub struct PlChangesPosId;
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||
pub struct PlChangesPosIdRequest {
|
||||
pub version: Version,
|
||||
pub window: Option<WindowRange>,
|
||||
}
|
||||
|
||||
impl Command for PlChangesPosId {
|
||||
type Request = PlChangesPosIdRequest;
|
||||
type Response = ();
|
||||
const COMMAND: &'static str = "plchangesposid";
|
||||
|
||||
fn serialize_request(&self, request: Self::Request) -> String {
|
||||
match request.window {
|
||||
Some(window) => format!("{} {} {}", Self::COMMAND, request.version, window),
|
||||
None => format!("{} {}", Self::COMMAND, request.version),
|
||||
}
|
||||
}
|
||||
|
||||
fn parse_request(mut parts: std::str::SplitWhitespace<'_>) -> RequestParserResult<'_> {
|
||||
let version = parts.next().ok_or(RequestParserError::UnexpectedEOF)?;
|
||||
let version = version
|
||||
|
||||
@@ -1,16 +1,30 @@
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::{
|
||||
Request,
|
||||
commands::{
|
||||
Command, RequestParserError, RequestParserResult, ResponseAttributes, ResponseParserError,
|
||||
},
|
||||
common::{Priority, WindowRange},
|
||||
};
|
||||
|
||||
pub struct Prio;
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||
pub struct PrioRequest {
|
||||
pub prio: Priority,
|
||||
pub window: WindowRange,
|
||||
}
|
||||
|
||||
impl Command for Prio {
|
||||
type Request = PrioRequest;
|
||||
type Response = ();
|
||||
const COMMAND: &'static str = "prio";
|
||||
|
||||
fn serialize_request(&self, request: Self::Request) -> String {
|
||||
format!("{} {} {}", Self::COMMAND, request.prio, request.window)
|
||||
}
|
||||
|
||||
fn parse_request(mut parts: std::str::SplitWhitespace<'_>) -> RequestParserResult<'_> {
|
||||
let prio = parts.next().ok_or(RequestParserError::UnexpectedEOF)?;
|
||||
let prio = prio
|
||||
|
||||
@@ -1,16 +1,36 @@
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::{
|
||||
Request,
|
||||
commands::{
|
||||
Command, RequestParserError, RequestParserResult, ResponseAttributes, ResponseParserError,
|
||||
},
|
||||
common::{Priority, SongId},
|
||||
};
|
||||
|
||||
pub struct PrioId;
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||
pub struct PrioIdRequest {
|
||||
pub prio: Priority,
|
||||
pub songids: Vec<SongId>,
|
||||
}
|
||||
|
||||
impl Command for PrioId {
|
||||
type Request = PrioIdRequest;
|
||||
type Response = ();
|
||||
const COMMAND: &'static str = "prioid";
|
||||
|
||||
fn serialize_request(&self, request: Self::Request) -> String {
|
||||
let songids = request
|
||||
.songids
|
||||
.iter()
|
||||
.map(|id| id.to_string())
|
||||
.collect::<Vec<String>>()
|
||||
.join(",");
|
||||
format!("{} {} {}", Self::COMMAND, request.prio, songids)
|
||||
}
|
||||
|
||||
fn parse_request(mut parts: std::str::SplitWhitespace<'_>) -> RequestParserResult<'_> {
|
||||
let prio = parts.next().ok_or(RequestParserError::UnexpectedEOF)?;
|
||||
let prio = prio
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user