Compare commits
2 Commits
main
...
db-selecti
| Author | SHA1 | Date | |
|---|---|---|---|
|
f674b0b0b1
|
|||
|
493995c1f2
|
@@ -83,8 +83,8 @@ jobs:
|
||||
target: ${{ gitea.ref_name }}/coverage/
|
||||
username: gitea-web
|
||||
ssh-key: ${{ secrets.WEB_SYNC_SSH_KEY }}
|
||||
host: pages.pvv.ntnu.no
|
||||
known-hosts: "pages.pvv.ntnu.no ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIH2QjfFB+city1SYqltkVqWACfo1j37k+oQQfj13mtgg"
|
||||
host: bekkalokk.pvv.ntnu.no
|
||||
known-hosts: "bekkalokk.pvv.ntnu.no ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIEI6VSaDrMG8+flg4/AeHlAFIen8RUzWh6URQKqFegSx"
|
||||
|
||||
docs:
|
||||
runs-on: ubuntu-latest
|
||||
@@ -107,6 +107,6 @@ jobs:
|
||||
target: ${{ gitea.ref_name }}/docs/
|
||||
username: gitea-web
|
||||
ssh-key: ${{ secrets.WEB_SYNC_SSH_KEY }}
|
||||
host: pages.pvv.ntnu.no
|
||||
known-hosts: "pages.pvv.ntnu.no ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIH2QjfFB+city1SYqltkVqWACfo1j37k+oQQfj13mtgg"
|
||||
host: bekkalokk.pvv.ntnu.no
|
||||
known-hosts: "bekkalokk.pvv.ntnu.no ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIEI6VSaDrMG8+flg4/AeHlAFIen8RUzWh6URQKqFegSx"
|
||||
|
||||
|
||||
4
.gitignore
vendored
4
.gitignore
vendored
@@ -1,5 +1,3 @@
|
||||
/target
|
||||
result
|
||||
result-*
|
||||
|
||||
Cargo.lock
|
||||
result-*
|
||||
95
Cargo.lock
generated
Normal file
95
Cargo.lock
generated
Normal file
@@ -0,0 +1,95 @@
|
||||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
version = 3
|
||||
|
||||
[[package]]
|
||||
name = "diff"
|
||||
version = "0.1.13"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "56254986775e3233ffa9c4d7d3faaf6d36a2c09d30b20687e9f88bc8bafc16c8"
|
||||
|
||||
[[package]]
|
||||
name = "empidee"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"indoc",
|
||||
"pretty_assertions",
|
||||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "indoc"
|
||||
version = "2.0.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b248f5224d1d606005e02c97f5aa4e88eeb230488bcc03bc9ca4d7991399f2b5"
|
||||
|
||||
[[package]]
|
||||
name = "pretty_assertions"
|
||||
version = "1.4.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3ae130e2f271fbc2ac3a40fb1d07180839cdbbe443c7a27e1e3c13c5cac0116d"
|
||||
dependencies = [
|
||||
"diff",
|
||||
"yansi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "proc-macro2"
|
||||
version = "1.0.88"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7c3a7fc5db1e57d5a779a352c8cdb57b29aa4c40cc69c3a68a7fedc815fbf2f9"
|
||||
dependencies = [
|
||||
"unicode-ident",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "quote"
|
||||
version = "1.0.37"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b5b9d34b8991d19d98081b46eacdd8eb58c6f2b201139f7c5f643cc155a633af"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde"
|
||||
version = "1.0.210"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c8e3592472072e6e22e0a54d5904d9febf8508f65fb8552499a1abc7d1078c3a"
|
||||
dependencies = [
|
||||
"serde_derive",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde_derive"
|
||||
version = "1.0.210"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "243902eda00fad750862fc144cea25caca5e20d615af0a81bee94ca738f1df1f"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "syn"
|
||||
version = "2.0.82"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "83540f837a8afc019423a8edb95b52a8effe46957ee402287f4292fae35be021"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"unicode-ident",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "unicode-ident"
|
||||
version = "1.0.13"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e91b56cd4cadaeb79bbf1a5645f6b4f8dc5bde8834ad5894a8db35fda9efa1fe"
|
||||
|
||||
[[package]]
|
||||
name = "yansi"
|
||||
version = "1.0.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "cfe53a6657fd280eaa890a3bc59152892ffa3e30101319d168b781ed6529b049"
|
||||
13
Cargo.toml
13
Cargo.toml
@@ -7,17 +7,12 @@ authors = [
|
||||
description = "A rust implementation of the mpd protocol, both client and serverside"
|
||||
repository = "https://git.pvv.ntnu.no/Grzegorz/empidee"
|
||||
documentation = "https://pages.pvv.ntnu.no/Grzegorz/empidee/main/docs/empidee/"
|
||||
edition = "2024"
|
||||
rust-version = "1.85.0"
|
||||
edition = "2021"
|
||||
rust-version = "1.83.0"
|
||||
|
||||
[dependencies]
|
||||
chrono = { version = "0.4.42", features = ["serde"] }
|
||||
lalrpop-util = { version = "0.22.2", features = ["lexer"] }
|
||||
serde = { version = "1.0.228", features = ["derive"] }
|
||||
serde = { version = "1.0.210", features = ["derive"] }
|
||||
|
||||
[dev-dependencies]
|
||||
indoc = "2.0.7"
|
||||
indoc = "2.0.5"
|
||||
pretty_assertions = "1.4.1"
|
||||
|
||||
[build-dependencies]
|
||||
lalrpop = "0.22.2"
|
||||
|
||||
8
build.rs
8
build.rs
@@ -1,8 +0,0 @@
|
||||
fn main() {
|
||||
lalrpop::process_root().unwrap();
|
||||
// let debug_mode = std::env::var("PROFILE").unwrap() == "debug";
|
||||
// lalrpop::Configuration::new()
|
||||
// .emit_comments(debug_mode)
|
||||
// .process()
|
||||
// .unwrap();
|
||||
}
|
||||
12
flake.lock
generated
12
flake.lock
generated
@@ -2,11 +2,11 @@
|
||||
"nodes": {
|
||||
"nixpkgs": {
|
||||
"locked": {
|
||||
"lastModified": 1763421233,
|
||||
"narHash": "sha256-Stk9ZYRkGrnnpyJ4eqt9eQtdFWRRIvMxpNRf4sIegnw=",
|
||||
"lastModified": 1739866667,
|
||||
"narHash": "sha256-EO1ygNKZlsAC9avfcwHkKGMsmipUk1Uc0TbrEZpkn64=",
|
||||
"owner": "NixOS",
|
||||
"repo": "nixpkgs",
|
||||
"rev": "89c2b2330e733d6cdb5eae7b899326930c2c0648",
|
||||
"rev": "73cf49b8ad837ade2de76f87eb53fc85ed5d4680",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
@@ -29,11 +29,11 @@
|
||||
]
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1763692705,
|
||||
"narHash": "sha256-tCKCyMYU0Vy+ph/xswlNsYXXjnFVweWBV+ew/5FS9tA=",
|
||||
"lastModified": 1740277845,
|
||||
"narHash": "sha256-NNU0CdiaSbAeZ8tpDG4aFi9qtcdlItRvk8Xns9oBrVU=",
|
||||
"owner": "oxalica",
|
||||
"repo": "rust-overlay",
|
||||
"rev": "6fbf5d328dce1828d887b8ee7d44a785196a34e7",
|
||||
"rev": "f933070c29f9c1c5457447a51903f27f76ebb519",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
|
||||
@@ -36,7 +36,6 @@
|
||||
default = pkgs.mkShell {
|
||||
nativeBuildInputs = [
|
||||
toolchain
|
||||
pkgs.cargo-edit
|
||||
];
|
||||
|
||||
RUST_SRC_PATH = "${toolchain}/lib/rustlib/src/rust/library";
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
style_edition = "2024"
|
||||
507
src/commands.rs
507
src/commands.rs
@@ -1,4 +1,9 @@
|
||||
use crate::{Request, request_tokenizer::RequestTokenizer, response_tokenizer::ResponseAttributes};
|
||||
use std::{
|
||||
collections::{HashMap, HashSet},
|
||||
str::SplitWhitespace,
|
||||
};
|
||||
|
||||
use crate::Request;
|
||||
|
||||
mod audio_output_devices;
|
||||
mod client_to_client;
|
||||
@@ -28,69 +33,40 @@ pub use reflection::*;
|
||||
pub use stickers::*;
|
||||
pub use stored_playlists::*;
|
||||
|
||||
/// A trait modelling the request/response pair of a single MPD command.
|
||||
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
|
||||
// The command name used within the protocol
|
||||
const COMMAND: &'static str;
|
||||
|
||||
/// Serialize the request into a string.
|
||||
/// This should optimally produce an input that can be parsed by [`parse_request`]
|
||||
fn serialize_request(&self, request: Self::Request) -> String;
|
||||
// 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.
|
||||
|
||||
/// Serialize the request into a bytestring.
|
||||
fn serialize_request_to_bytes(&self, request: Self::Request) -> Vec<u8> {
|
||||
self.serialize_request(request).into_bytes()
|
||||
}
|
||||
// A function to parse the remaining parts of the command, split by whitespace
|
||||
fn parse_request(parts: SplitWhitespace<'_>) -> RequestParserResult<'_>;
|
||||
|
||||
// fn serialize_response(&self) -> String;
|
||||
// fn serialize_response_to_bytes(&self) -> Vec<u8> {
|
||||
// self.serialize_response().into_bytes()
|
||||
// }
|
||||
|
||||
/// Parse the request from its tokenized parts.
|
||||
///
|
||||
/// Note that this assumes only the parts after the command name are passed in, e.g.
|
||||
///
|
||||
/// ```ignore
|
||||
/// arg1 "arg2 arg3"
|
||||
/// ```
|
||||
fn parse_request(parts: RequestTokenizer<'_>) -> RequestParserResult<'_>;
|
||||
|
||||
/// Parse the raw request string into a request and the remaining unparsed string.
|
||||
/// This assumes the raw string starts with the command name, e.g.
|
||||
///
|
||||
/// ```ignore
|
||||
/// command_name arg1 "arg2 arg3"
|
||||
/// ```
|
||||
fn parse_raw_request(raw: &str) -> RequestParserResult<'_> {
|
||||
let (line, rest) = raw
|
||||
.split_once('\n')
|
||||
.ok_or(RequestParserError::UnexpectedEOF)?;
|
||||
let mut tokenized = RequestTokenizer::new(line);
|
||||
let mut parts = line.split_whitespace();
|
||||
|
||||
let command_name = tokenized
|
||||
let command_name = parts
|
||||
.next()
|
||||
.ok_or(RequestParserError::SyntaxError(0, line.to_string()))?
|
||||
.trim();
|
||||
|
||||
debug_assert!(command_name == Self::COMMAND);
|
||||
|
||||
Self::parse_request(tokenized).map(|(req, _)| (req, rest))
|
||||
Self::parse_request(parts).map(|(req, _)| (req, rest))
|
||||
}
|
||||
|
||||
/// Parse the response from its tokenized parts.
|
||||
/// See also [`parse_raw_response`].
|
||||
fn parse_response(parts: ResponseAttributes<'_>) -> ResponseParserResult<'_, Self::Response>;
|
||||
fn parse_response(
|
||||
parts: ResponseAttributes<'_>,
|
||||
) -> Result<Self::Response, ResponseParserError<'_>>;
|
||||
|
||||
/// Parse the raw response string into a response.
|
||||
fn parse_raw_response(raw: &str) -> ResponseParserResult<'_, Self::Response> {
|
||||
Self::parse_response(ResponseAttributes::new(raw))
|
||||
fn parse_raw_response(raw: &str) -> Result<Self::Response, ResponseParserError<'_>> {
|
||||
Self::parse_response(ResponseAttributes::new(raw)?)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -106,8 +82,6 @@ pub enum RequestParserError {
|
||||
MissingNewline,
|
||||
}
|
||||
|
||||
pub type ResponseParserResult<'a, T> = Result<T, ResponseParserError<'a>>;
|
||||
|
||||
// TODO: should these be renamed to fit the mpd docs?
|
||||
// "Attribute" instead of "Property"?
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
@@ -122,9 +96,6 @@ pub enum ResponseParserError<'a> {
|
||||
/// A property was found in the response that was not expected.
|
||||
UnexpectedProperty(&'a str),
|
||||
|
||||
/// A property was found multiple times in the response, but was only expected once.
|
||||
DuplicateProperty(&'a str),
|
||||
|
||||
/// The property value is parsable, but the value is invalid or nonsensical.
|
||||
InvalidProperty(&'a str, &'a str),
|
||||
|
||||
@@ -136,151 +107,297 @@ pub enum ResponseParserError<'a> {
|
||||
// MissingNewline,
|
||||
}
|
||||
|
||||
pub type GenericResponseResult<'a> = Result<GenericResponse<'a>, &'a str>;
|
||||
|
||||
pub type GenericResponse<'a> = HashMap<&'a str, GenericResponseValue<'a>>;
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
||||
pub enum GenericResponseValue<'a> {
|
||||
Text(&'a str),
|
||||
Binary(&'a [u8]),
|
||||
// Many(Vec<GenericResponseValue<'a>>),
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub struct ResponseAttributes<'a>(Vec<(&'a str, GenericResponseValue<'a>)>);
|
||||
|
||||
impl<'a> ResponseAttributes<'a> {
|
||||
pub fn new(raw: &'a str) -> Result<Self, ResponseParserError<'a>> {
|
||||
let mut parts = Vec::new();
|
||||
let mut lines = raw.lines();
|
||||
loop {
|
||||
let line = lines.next().ok_or(ResponseParserError::UnexpectedEOF)?;
|
||||
if line.is_empty() {
|
||||
println!("Warning: empty line in response");
|
||||
continue;
|
||||
}
|
||||
|
||||
if line == "OK" {
|
||||
break;
|
||||
}
|
||||
|
||||
let mut keyval = line.splitn(2, ": ");
|
||||
let key = keyval
|
||||
.next()
|
||||
.ok_or(ResponseParserError::SyntaxError(0, line))?;
|
||||
|
||||
// TODO: handle binary data, also verify binarylimit
|
||||
let value = keyval
|
||||
.next()
|
||||
.ok_or(ResponseParserError::SyntaxError(0, line))?;
|
||||
|
||||
parts.push((key, GenericResponseValue::Text(value)));
|
||||
}
|
||||
|
||||
Ok(parts.into())
|
||||
}
|
||||
|
||||
// pub fn get<'a>(&self, key: &str) -> Option<&GenericResponseValue<'a>> {
|
||||
// self.0.iter().find_map(|(k, v)| if k == &key { Some(v) } else { None })
|
||||
// }
|
||||
}
|
||||
|
||||
impl ResponseAttributes<'_> {
|
||||
pub fn is_empty(&self) -> bool {
|
||||
self.0.is_empty()
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> From<HashMap<&'a str, GenericResponseValue<'a>>> for ResponseAttributes<'a> {
|
||||
fn from(map: HashMap<&'a str, GenericResponseValue<'a>>) -> Self {
|
||||
Self(map.into_iter().collect())
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> From<ResponseAttributes<'a>> for HashMap<&'a str, GenericResponseValue<'a>> {
|
||||
fn from(val: ResponseAttributes<'a>) -> Self {
|
||||
debug_assert!({
|
||||
let mut uniq = HashSet::new();
|
||||
val.0.iter().all(move |x| uniq.insert(*x))
|
||||
});
|
||||
|
||||
val.0.into_iter().collect()
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> From<ResponseAttributes<'a>> for Vec<(&'a str, GenericResponseValue<'a>)> {
|
||||
fn from(val: ResponseAttributes<'a>) -> Self {
|
||||
val.0
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> From<Vec<(&'a str, GenericResponseValue<'a>)>> for ResponseAttributes<'a> {
|
||||
fn from(val: Vec<(&'a str, GenericResponseValue<'a>)>) -> Self {
|
||||
Self(val)
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: There should probably be a helper that lets you extract and verify one, two or maybe
|
||||
// three properties without having to allocate a hashmap to get a nice API. We can retrieve
|
||||
// the properties by name with a loop on the inner vec.
|
||||
|
||||
/*******************/
|
||||
/* Parsing Helpers */
|
||||
/*******************/
|
||||
|
||||
pub const COMMAND_NAMES: &[&str] = &[
|
||||
// Audio output devices
|
||||
DisableOutput::COMMAND,
|
||||
EnableOutput::COMMAND,
|
||||
Outputs::COMMAND,
|
||||
OutputSet::COMMAND,
|
||||
ToggleOutput::COMMAND,
|
||||
// Client to client
|
||||
Channels::COMMAND,
|
||||
ReadMessages::COMMAND,
|
||||
SendMessage::COMMAND,
|
||||
Subscribe::COMMAND,
|
||||
Unsubscribe::COMMAND,
|
||||
// Connection settings
|
||||
BinaryLimit::COMMAND,
|
||||
Close::COMMAND,
|
||||
Kill::COMMAND,
|
||||
Password::COMMAND,
|
||||
Ping::COMMAND,
|
||||
Protocol::COMMAND,
|
||||
ProtocolAll::COMMAND,
|
||||
ProtocolAvailable::COMMAND,
|
||||
ProtocolClear::COMMAND,
|
||||
ProtocolDisable::COMMAND,
|
||||
ProtocolEnable::COMMAND,
|
||||
TagTypes::COMMAND,
|
||||
TagTypesAll::COMMAND,
|
||||
TagTypesAvailable::COMMAND,
|
||||
TagTypesClear::COMMAND,
|
||||
TagTypesDisable::COMMAND,
|
||||
TagTypesEnable::COMMAND,
|
||||
TagTypesReset::COMMAND,
|
||||
// Controlling playback
|
||||
Next::COMMAND,
|
||||
Pause::COMMAND,
|
||||
Play::COMMAND,
|
||||
PlayId::COMMAND,
|
||||
Previous::COMMAND,
|
||||
Seek::COMMAND,
|
||||
SeekCur::COMMAND,
|
||||
SeekId::COMMAND,
|
||||
Stop::COMMAND,
|
||||
// Mounts and neighbors
|
||||
ListMounts::COMMAND,
|
||||
ListNeighbors::COMMAND,
|
||||
Mount::COMMAND,
|
||||
Unmount::COMMAND,
|
||||
// Music database
|
||||
AlbumArt::COMMAND,
|
||||
Count::COMMAND,
|
||||
Find::COMMAND,
|
||||
FindAdd::COMMAND,
|
||||
GetFingerprint::COMMAND,
|
||||
List::COMMAND,
|
||||
ListAll::COMMAND,
|
||||
ListAllInfo::COMMAND,
|
||||
ListFiles::COMMAND,
|
||||
LsInfo::COMMAND,
|
||||
ReadComments::COMMAND,
|
||||
ReadPicture::COMMAND,
|
||||
Rescan::COMMAND,
|
||||
Search::COMMAND,
|
||||
SearchAdd::COMMAND,
|
||||
SearchAddPl::COMMAND,
|
||||
SearchCount::COMMAND,
|
||||
Update::COMMAND,
|
||||
// Partition commands
|
||||
DelPartition::COMMAND,
|
||||
ListPartitions::COMMAND,
|
||||
MoveOutput::COMMAND,
|
||||
NewPartition::COMMAND,
|
||||
Partition::COMMAND,
|
||||
// Playback options
|
||||
Consume::COMMAND,
|
||||
Crossfade::COMMAND,
|
||||
GetVol::COMMAND,
|
||||
MixRampDb::COMMAND,
|
||||
MixRampDelay::COMMAND,
|
||||
Random::COMMAND,
|
||||
Repeat::COMMAND,
|
||||
ReplayGainMode::COMMAND,
|
||||
ReplayGainStatus::COMMAND,
|
||||
SetVol::COMMAND,
|
||||
Single::COMMAND,
|
||||
Volume::COMMAND,
|
||||
// Querying mpd status
|
||||
ClearError::COMMAND,
|
||||
CurrentSong::COMMAND,
|
||||
Idle::COMMAND,
|
||||
Stats::COMMAND,
|
||||
Status::COMMAND,
|
||||
// Queue
|
||||
Add::COMMAND,
|
||||
AddId::COMMAND,
|
||||
AddTagId::COMMAND,
|
||||
Clear::COMMAND,
|
||||
ClearTagId::COMMAND,
|
||||
Delete::COMMAND,
|
||||
DeleteId::COMMAND,
|
||||
Move::COMMAND,
|
||||
MoveId::COMMAND,
|
||||
Playlist::COMMAND,
|
||||
PlaylistFind::COMMAND,
|
||||
PlaylistId::COMMAND,
|
||||
PlaylistInfo::COMMAND,
|
||||
PlaylistSearch::COMMAND,
|
||||
PlChanges::COMMAND,
|
||||
PlChangesPosId::COMMAND,
|
||||
Prio::COMMAND,
|
||||
PrioId::COMMAND,
|
||||
RangeId::COMMAND,
|
||||
Shuffle::COMMAND,
|
||||
Swap::COMMAND,
|
||||
SwapId::COMMAND,
|
||||
// Reflection
|
||||
Commands::COMMAND,
|
||||
Config::COMMAND,
|
||||
Decoders::COMMAND,
|
||||
NotCommands::COMMAND,
|
||||
UrlHandlers::COMMAND,
|
||||
// Stickers
|
||||
StickerDec::COMMAND,
|
||||
StickerDelete::COMMAND,
|
||||
StickerFind::COMMAND,
|
||||
StickerGet::COMMAND,
|
||||
StickerInc::COMMAND,
|
||||
StickerList::COMMAND,
|
||||
StickerSet::COMMAND,
|
||||
StickerNames::COMMAND,
|
||||
StickerNamesTypes::COMMAND,
|
||||
StickerTypes::COMMAND,
|
||||
// Stored playlists
|
||||
ListPlaylist::COMMAND,
|
||||
ListPlaylistInfo::COMMAND,
|
||||
ListPlaylists::COMMAND,
|
||||
Load::COMMAND,
|
||||
PlaylistAdd::COMMAND,
|
||||
PlaylistClear::COMMAND,
|
||||
PlaylistDelete::COMMAND,
|
||||
PlaylistLength::COMMAND,
|
||||
PlaylistMove::COMMAND,
|
||||
Rename::COMMAND,
|
||||
Rm::COMMAND,
|
||||
Save::COMMAND,
|
||||
SearchPlaylist::COMMAND,
|
||||
];
|
||||
macro_rules! _expect_property_type {
|
||||
($property:expr, $name:expr, $variant:ident) => {
|
||||
match $property {
|
||||
Some(crate::commands::GenericResponseValue::$variant(value)) => Some(value),
|
||||
Some(value) => {
|
||||
let actual_type = match value {
|
||||
crate::commands::GenericResponseValue::Text(_) => "Text",
|
||||
crate::commands::GenericResponseValue::Binary(_) => "Binary",
|
||||
};
|
||||
return Err(
|
||||
crate::commands::ResponseParserError::UnexpectedPropertyType(
|
||||
$name,
|
||||
actual_type,
|
||||
),
|
||||
);
|
||||
}
|
||||
None => None,
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
macro_rules! _parse_optional_property_type {
|
||||
($name:expr, $property:expr) => {
|
||||
$property
|
||||
.map(|value| {
|
||||
value.parse().map_err(|_| {
|
||||
crate::commands::ResponseParserError::InvalidProperty($name, value)
|
||||
})
|
||||
})
|
||||
.transpose()?
|
||||
};
|
||||
}
|
||||
|
||||
macro_rules! _unwrap_optional_property_type {
|
||||
($name:expr, $property:expr) => {
|
||||
match $property {
|
||||
Some(value) => value,
|
||||
None => return Err(crate::commands::ResponseParserError::MissingProperty($name)),
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
macro_rules! expect_optional_property_type {
|
||||
($property:expr, $name:expr, $variant:ident) => {
|
||||
crate::commands::_expect_property_type!($property, $name, $variant)
|
||||
};
|
||||
}
|
||||
|
||||
macro_rules! expect_property_type {
|
||||
($property:expr, $name:expr, $variant:ident) => {{
|
||||
let prop = crate::commands::_expect_property_type!($property, $name, $variant);
|
||||
crate::commands::_unwrap_optional_property_type!($name, prop)
|
||||
}};
|
||||
}
|
||||
|
||||
macro_rules! get_optional_property {
|
||||
($parts:expr, $name:literal, $variant:ident) => {
|
||||
crate::commands::_expect_property_type!({ $parts.get($name).map(|v| *v) }, $name, $variant)
|
||||
};
|
||||
}
|
||||
|
||||
macro_rules! get_property {
|
||||
($parts:expr, $name:literal, $variant:ident) => {{
|
||||
let prop = crate::commands::_expect_property_type!(
|
||||
{ $parts.get($name).map(|v| *v) },
|
||||
$name,
|
||||
$variant
|
||||
);
|
||||
crate::commands::_unwrap_optional_property_type!($name, prop)
|
||||
}};
|
||||
}
|
||||
|
||||
macro_rules! get_and_parse_optional_property {
|
||||
($parts:ident, $name:literal, $variant:ident) => {{
|
||||
let prop = crate::commands::_expect_property_type!(
|
||||
{ $parts.get($name).map(|v| *v) },
|
||||
$name,
|
||||
$variant
|
||||
);
|
||||
crate::commands::_parse_optional_property_type!($name, prop)
|
||||
}};
|
||||
}
|
||||
|
||||
macro_rules! get_and_parse_property {
|
||||
($parts:ident, $name:literal, $variant:ident) => {{
|
||||
let prop = crate::commands::_expect_property_type!(
|
||||
{ $parts.get($name).map(|v| *v) },
|
||||
$name,
|
||||
$variant
|
||||
);
|
||||
let prop = crate::commands::_parse_optional_property_type!($name, prop);
|
||||
crate::commands::_unwrap_optional_property_type!($name, prop)
|
||||
}};
|
||||
}
|
||||
|
||||
macro_rules! get_next_optional_property {
|
||||
($parts:ident, $variant:ident) => {
|
||||
match $parts.next() {
|
||||
Some((name, value)) => {
|
||||
crate::commands::_expect_property_type!({ Some(value) }, name, $variant)
|
||||
.map(|value| (name, value))
|
||||
}
|
||||
None => None,
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
macro_rules! get_next_property {
|
||||
($parts:ident, $variant:ident) => {
|
||||
match $parts.next() {
|
||||
Some((name, value)) => (
|
||||
name,
|
||||
crate::commands::_expect_property_type!({ Some(value) }, name, $variant).unwrap(),
|
||||
),
|
||||
None => return Err(crate::commands::ResponseParserError::UnexpectedEOF),
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
macro_rules! get_next_and_parse_optional_property {
|
||||
($parts:ident, $variant:ident) => {
|
||||
match $parts.next() {
|
||||
Some((name, value)) => {
|
||||
let prop = crate::commands::_expect_property_type!({ Some(value) }, name, $variant);
|
||||
prop.map(|value| {
|
||||
(
|
||||
name,
|
||||
crate::commands::_parse_optional_property_type!(name, value),
|
||||
)
|
||||
})
|
||||
}
|
||||
None => None,
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
macro_rules! get_next_and_parse_property {
|
||||
($parts:ident, $variant:ident) => {
|
||||
match $parts.next() {
|
||||
Some((name, value)) => {
|
||||
let prop = crate::commands::_expect_property_type!({ Some(value) }, name, $variant);
|
||||
let prop = crate::commands::_parse_optional_property_type!(name, prop);
|
||||
(
|
||||
name,
|
||||
crate::commands::_unwrap_optional_property_type!(name, prop),
|
||||
)
|
||||
}
|
||||
None => return Err(crate::commands::ResponseParserError::UnexpectedEOF),
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
pub(crate) use _expect_property_type;
|
||||
pub(crate) use _parse_optional_property_type;
|
||||
pub(crate) use _unwrap_optional_property_type;
|
||||
pub(crate) use expect_property_type;
|
||||
// pub(crate) use expect_optional_property_type;
|
||||
pub(crate) use get_and_parse_optional_property;
|
||||
pub(crate) use get_and_parse_property;
|
||||
// pub(crate) use get_next_and_parse_optional_property;
|
||||
pub(crate) use get_next_and_parse_property;
|
||||
// pub(crate) use get_next_optional_property;
|
||||
pub(crate) use get_next_property;
|
||||
pub(crate) use get_optional_property;
|
||||
pub(crate) use get_property;
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
#[cfg(debug_assertions)]
|
||||
fn test_valid_hashmap_uniqueness_assert() {
|
||||
let valid_maplike_attrs: ResponseAttributes = vec![
|
||||
("a", GenericResponseValue::Text("1")),
|
||||
("A", GenericResponseValue::Text("2")),
|
||||
("A ", GenericResponseValue::Text("3")),
|
||||
("b", GenericResponseValue::Text("4")),
|
||||
]
|
||||
.into();
|
||||
|
||||
let map: HashMap<_, _> = valid_maplike_attrs.into();
|
||||
assert_eq!(map.len(), 4);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(debug_assertions)]
|
||||
#[should_panic]
|
||||
fn test_invalid_hashmap_uniqueness_assert() {
|
||||
let invalid_maplike_attrs: ResponseAttributes = vec![
|
||||
("a", GenericResponseValue::Text("1")),
|
||||
("b", GenericResponseValue::Text("2")),
|
||||
("c", GenericResponseValue::Text("3")),
|
||||
("a", GenericResponseValue::Text("4")),
|
||||
]
|
||||
.into();
|
||||
|
||||
let map: HashMap<_, _> = invalid_maplike_attrs.into();
|
||||
assert_eq!(map.len(), 4);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,32 +1,20 @@
|
||||
use crate::{
|
||||
commands::{Command, Request, RequestParserError, RequestParserResult, ResponseParserError},
|
||||
common::AudioOutputId,
|
||||
request_tokenizer::RequestTokenizer,
|
||||
response_tokenizer::ResponseAttributes,
|
||||
use crate::commands::{
|
||||
Command, Request, RequestParserError, RequestParserResult, ResponseAttributes,
|
||||
ResponseParserError,
|
||||
};
|
||||
|
||||
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: RequestTokenizer<'_>) -> RequestParserResult<'_> {
|
||||
fn parse_request(mut parts: std::str::SplitWhitespace<'_>) -> RequestParserResult<'_> {
|
||||
let output_id = parts.next().ok_or(RequestParserError::UnexpectedEOF)?;
|
||||
let output_id = output_id
|
||||
.parse()
|
||||
.map_err(|_| RequestParserError::SyntaxError(0, output_id.to_owned()))?;
|
||||
|
||||
debug_assert!(parts.next().is_none());
|
||||
|
||||
Ok((Request::DisableOutput(output_id), ""))
|
||||
Ok((Request::DisableOutput(output_id.to_string()), ""))
|
||||
}
|
||||
|
||||
fn parse_response(
|
||||
|
||||
@@ -1,37 +1,25 @@
|
||||
use crate::{
|
||||
commands::{Command, Request, RequestParserError, RequestParserResult, ResponseParserError},
|
||||
common::AudioOutputId,
|
||||
request_tokenizer::RequestTokenizer,
|
||||
response_tokenizer::ResponseAttributes,
|
||||
use crate::commands::{
|
||||
Command, Request, RequestParserError, RequestParserResult, ResponseAttributes,
|
||||
ResponseParserError,
|
||||
};
|
||||
|
||||
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: RequestTokenizer<'_>) -> RequestParserResult<'_> {
|
||||
fn parse_request(mut parts: std::str::SplitWhitespace<'_>) -> RequestParserResult<'_> {
|
||||
let output_id = parts.next().ok_or(RequestParserError::UnexpectedEOF)?;
|
||||
let output_id = output_id
|
||||
.parse()
|
||||
.map_err(|_| RequestParserError::SyntaxError(0, output_id.to_owned()))?;
|
||||
|
||||
debug_assert!(parts.next().is_none());
|
||||
|
||||
Ok((Request::EnableOutput(output_id), ""))
|
||||
Ok((Request::EnableOutput(output_id.to_string()), ""))
|
||||
}
|
||||
|
||||
fn parse_response(
|
||||
parts: ResponseAttributes<'_>,
|
||||
) -> Result<Self::Response, ResponseParserError<'_>> {
|
||||
) -> Result<Self::Response, ResponseParserError> {
|
||||
debug_assert!(parts.is_empty());
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -2,18 +2,15 @@ use std::collections::HashMap;
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::{
|
||||
commands::{Command, Request, RequestParserResult, ResponseParserError},
|
||||
common::AudioOutputId,
|
||||
request_tokenizer::RequestTokenizer,
|
||||
response_tokenizer::{ResponseAttributes, expect_property_type},
|
||||
use crate::commands::{
|
||||
Command, Request, RequestParserResult, ResponseAttributes, ResponseParserError,
|
||||
};
|
||||
|
||||
pub struct Outputs;
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||
pub struct Output {
|
||||
pub id: AudioOutputId,
|
||||
pub id: u64,
|
||||
pub name: String,
|
||||
pub plugin: String,
|
||||
pub enabled: bool,
|
||||
@@ -23,147 +20,17 @@ 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: RequestTokenizer<'_>) -> RequestParserResult<'_> {
|
||||
fn parse_request(mut parts: std::str::SplitWhitespace<'_>) -> RequestParserResult<'_> {
|
||||
debug_assert!(parts.next().is_none());
|
||||
Ok((Request::Outputs, ""))
|
||||
}
|
||||
|
||||
fn parse_response(
|
||||
parts: ResponseAttributes<'_>,
|
||||
) -> Result<Self::Response, ResponseParserError<'_>> {
|
||||
let mut outputs = Vec::new();
|
||||
|
||||
let mut id: Option<AudioOutputId> = None;
|
||||
let mut name: Option<String> = None;
|
||||
let mut plugin: Option<String> = None;
|
||||
let mut enabled: Option<bool> = None;
|
||||
let mut attributes: HashMap<String, String> = HashMap::new();
|
||||
|
||||
for (k, v) in parts.into_vec()?.into_iter() {
|
||||
match k {
|
||||
"outputid" => {
|
||||
// Reset and store the previous output if all fields are present
|
||||
if let (Some(id), Some(name), Some(plugin), Some(enabled)) =
|
||||
(id.take(), name.take(), plugin.take(), enabled.take())
|
||||
{
|
||||
outputs.push(Output {
|
||||
id,
|
||||
name,
|
||||
plugin,
|
||||
enabled,
|
||||
attribute: attributes,
|
||||
});
|
||||
}
|
||||
attributes = HashMap::new();
|
||||
let id_s = expect_property_type!(Some(v), k, Text);
|
||||
id = Some(
|
||||
id_s.parse()
|
||||
.map_err(|_| ResponseParserError::SyntaxError(0, id_s))?,
|
||||
);
|
||||
}
|
||||
"outputname" => {
|
||||
name = Some(expect_property_type!(Some(v), k, Text).to_string());
|
||||
}
|
||||
"plugin" => {
|
||||
plugin = Some(expect_property_type!(Some(v), k, Text).to_string());
|
||||
}
|
||||
"outputenabled" => {
|
||||
let val_s = expect_property_type!(Some(v), k, Text);
|
||||
let val: u64 = val_s
|
||||
.parse::<u64>()
|
||||
.map_err(|_| ResponseParserError::SyntaxError(0, val_s))?;
|
||||
enabled = Some(val != 0);
|
||||
}
|
||||
"attribute" => {
|
||||
let value = expect_property_type!(Some(v), k, Text);
|
||||
let mut parts = value.splitn(2, '=');
|
||||
let attr_key = parts
|
||||
.next()
|
||||
.ok_or(ResponseParserError::SyntaxError(0, value))?
|
||||
.to_string();
|
||||
let attr_value = parts
|
||||
.next()
|
||||
.ok_or(ResponseParserError::SyntaxError(0, value))?
|
||||
.to_string();
|
||||
attributes.insert(attr_key, attr_value);
|
||||
}
|
||||
_ => {
|
||||
return Err(ResponseParserError::UnexpectedProperty(k));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Store the last output if all fields are present
|
||||
if let (Some(id), Some(name), Some(plugin), Some(enabled)) =
|
||||
(id.take(), name.take(), plugin.take(), enabled.take())
|
||||
{
|
||||
outputs.push(Output {
|
||||
id,
|
||||
name,
|
||||
plugin,
|
||||
enabled,
|
||||
attribute: attributes,
|
||||
});
|
||||
}
|
||||
|
||||
Ok(outputs)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use indoc::indoc;
|
||||
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn test_parse_response() {
|
||||
let input = indoc! {"
|
||||
outputid: 0
|
||||
outputname: PipeWire Sound Server
|
||||
plugin: pipewire
|
||||
outputenabled: 1
|
||||
outputid: 1
|
||||
outputname: Visualizer feed
|
||||
plugin: fifo
|
||||
outputenabled: 1
|
||||
attribute: fifo_path=/tmp/empidee-visualizer.fifo
|
||||
OK
|
||||
"};
|
||||
let result = Outputs::parse_raw_response(input);
|
||||
assert_eq!(
|
||||
result,
|
||||
Ok(vec![
|
||||
Output {
|
||||
id: 0,
|
||||
name: "PipeWire Sound Server".to_string(),
|
||||
plugin: "pipewire".to_string(),
|
||||
enabled: true,
|
||||
attribute: HashMap::new(),
|
||||
},
|
||||
Output {
|
||||
id: 1,
|
||||
name: "Visualizer feed".to_string(),
|
||||
plugin: "fifo".to_string(),
|
||||
enabled: true,
|
||||
attribute: {
|
||||
let mut map = HashMap::new();
|
||||
map.insert(
|
||||
"fifo_path".to_string(),
|
||||
"/tmp/empidee-visualizer.fifo".to_string(),
|
||||
);
|
||||
map
|
||||
},
|
||||
},
|
||||
])
|
||||
);
|
||||
_parts: ResponseAttributes<'_>,
|
||||
) -> Result<Self::Response, ResponseParserError> {
|
||||
unimplemented!()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,41 +1,16 @@
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::{
|
||||
commands::{Command, Request, RequestParserError, RequestParserResult, ResponseParserError},
|
||||
common::AudioOutputId,
|
||||
request_tokenizer::RequestTokenizer,
|
||||
response_tokenizer::ResponseAttributes,
|
||||
use crate::commands::{
|
||||
Command, Request, RequestParserError, RequestParserResult, ResponseAttributes,
|
||||
ResponseParserError,
|
||||
};
|
||||
|
||||
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: RequestTokenizer<'_>) -> RequestParserResult<'_> {
|
||||
fn parse_request(mut parts: std::str::SplitWhitespace<'_>) -> RequestParserResult<'_> {
|
||||
let output_id = parts.next().ok_or(RequestParserError::UnexpectedEOF)?;
|
||||
let output_id = output_id
|
||||
.parse()
|
||||
.map_err(|_| RequestParserError::SyntaxError(0, output_id.to_owned()))?;
|
||||
let attribute_name = parts.next().ok_or(RequestParserError::UnexpectedEOF)?;
|
||||
let attribute_value = parts.next().ok_or(RequestParserError::UnexpectedEOF)?;
|
||||
|
||||
@@ -43,7 +18,7 @@ impl Command for OutputSet {
|
||||
|
||||
Ok((
|
||||
Request::OutputSet(
|
||||
output_id,
|
||||
output_id.to_string(),
|
||||
attribute_name.to_string(),
|
||||
attribute_value.to_string(),
|
||||
),
|
||||
@@ -53,7 +28,7 @@ impl Command for OutputSet {
|
||||
|
||||
fn parse_response(
|
||||
parts: ResponseAttributes<'_>,
|
||||
) -> Result<Self::Response, ResponseParserError<'_>> {
|
||||
) -> Result<Self::Response, ResponseParserError> {
|
||||
debug_assert!(parts.is_empty());
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -1,37 +1,25 @@
|
||||
use crate::{
|
||||
commands::{Command, Request, RequestParserError, RequestParserResult, ResponseParserError},
|
||||
common::AudioOutputId,
|
||||
request_tokenizer::RequestTokenizer,
|
||||
response_tokenizer::ResponseAttributes,
|
||||
use crate::commands::{
|
||||
Command, Request, RequestParserError, RequestParserResult, ResponseAttributes,
|
||||
ResponseParserError,
|
||||
};
|
||||
|
||||
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: RequestTokenizer<'_>) -> RequestParserResult<'_> {
|
||||
fn parse_request(mut parts: std::str::SplitWhitespace<'_>) -> RequestParserResult<'_> {
|
||||
let output_id = parts.next().ok_or(RequestParserError::UnexpectedEOF)?;
|
||||
let output_id = output_id
|
||||
.parse()
|
||||
.map_err(|_| RequestParserError::SyntaxError(0, output_id.to_owned()))?;
|
||||
|
||||
debug_assert!(parts.next().is_none());
|
||||
|
||||
Ok((Request::ToggleOutput(output_id), ""))
|
||||
Ok((Request::ToggleOutput(output_id.to_string()), ""))
|
||||
}
|
||||
|
||||
fn parse_response(
|
||||
parts: ResponseAttributes<'_>,
|
||||
) -> Result<Self::Response, ResponseParserError<'_>> {
|
||||
) -> Result<Self::Response, ResponseParserError> {
|
||||
debug_assert!(parts.is_empty());
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -1,29 +1,22 @@
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::{
|
||||
commands::{Command, Request, RequestParserResult, ResponseParserError},
|
||||
common::ChannelName,
|
||||
request_tokenizer::RequestTokenizer,
|
||||
response_tokenizer::{ResponseAttributes, expect_property_type},
|
||||
use crate::commands::{
|
||||
expect_property_type, Command, Request, RequestParserResult, ResponseAttributes,
|
||||
ResponseParserError,
|
||||
};
|
||||
|
||||
pub struct Channels;
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||
pub struct ChannelsResponse {
|
||||
pub channels: Vec<ChannelName>,
|
||||
pub channels: Vec<String>,
|
||||
}
|
||||
|
||||
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: RequestTokenizer<'_>) -> RequestParserResult<'_> {
|
||||
fn parse_request(mut parts: std::str::SplitWhitespace<'_>) -> RequestParserResult<'_> {
|
||||
debug_assert!(parts.next().is_none());
|
||||
|
||||
Ok((Request::Channels, ""))
|
||||
@@ -31,16 +24,13 @@ impl Command for Channels {
|
||||
|
||||
fn parse_response(
|
||||
parts: ResponseAttributes<'_>,
|
||||
) -> Result<Self::Response, ResponseParserError<'_>> {
|
||||
let parts: Vec<_> = parts.into_vec()?;
|
||||
) -> Result<Self::Response, ResponseParserError> {
|
||||
let parts: Vec<_> = parts.into();
|
||||
let mut channel_names = Vec::with_capacity(parts.len());
|
||||
for (key, value) in parts {
|
||||
debug_assert!(key == "channels");
|
||||
let channel_name = expect_property_type!(Some(value), "channels", Text);
|
||||
let channel_name = channel_name
|
||||
.parse()
|
||||
.map_err(|_| ResponseParserError::SyntaxError(0, channel_name))?;
|
||||
channel_names.push(channel_name);
|
||||
channel_names.push(channel_name.to_string());
|
||||
}
|
||||
|
||||
Ok(ChannelsResponse {
|
||||
@@ -67,11 +57,7 @@ mod tests {
|
||||
assert_eq!(
|
||||
response,
|
||||
ChannelsResponse {
|
||||
channels: vec![
|
||||
"foo".parse().unwrap(),
|
||||
"bar".parse().unwrap(),
|
||||
"baz".parse().unwrap(),
|
||||
]
|
||||
channels: vec!["foo".to_string(), "bar".to_string(), "baz".to_string()]
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,32 +1,22 @@
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::{
|
||||
commands::{Command, Request, RequestParserResult, ResponseParserError},
|
||||
common::ChannelName,
|
||||
request_tokenizer::RequestTokenizer,
|
||||
response_tokenizer::{ResponseAttributes, expect_property_type},
|
||||
use crate::commands::{
|
||||
expect_property_type, Command, Request, RequestParserResult, ResponseAttributes,
|
||||
ResponseParserError,
|
||||
};
|
||||
|
||||
pub struct ReadMessages;
|
||||
|
||||
pub type ReadMessagesResponse = Vec<ReadMessagesResponseEntry>;
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||
pub struct ReadMessagesResponseEntry {
|
||||
channel: ChannelName,
|
||||
message: String,
|
||||
pub struct ReadMessagesResponse {
|
||||
pub messages: Vec<(String, 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: RequestTokenizer<'_>) -> RequestParserResult<'_> {
|
||||
fn parse_request(mut parts: std::str::SplitWhitespace<'_>) -> RequestParserResult<'_> {
|
||||
debug_assert!(parts.next().is_none());
|
||||
|
||||
Ok((Request::ReadMessages, ""))
|
||||
@@ -34,8 +24,8 @@ impl Command for ReadMessages {
|
||||
|
||||
fn parse_response(
|
||||
parts: ResponseAttributes<'_>,
|
||||
) -> Result<Self::Response, ResponseParserError<'_>> {
|
||||
let parts: Vec<_> = parts.into_vec()?;
|
||||
) -> Result<Self::Response, ResponseParserError> {
|
||||
let parts: Vec<_> = parts.into();
|
||||
debug_assert!(parts.len() % 2 == 0);
|
||||
|
||||
let mut messages = Vec::with_capacity(parts.len() / 2);
|
||||
@@ -47,17 +37,13 @@ impl Command for ReadMessages {
|
||||
debug_assert!(ckey == "channel");
|
||||
debug_assert!(mkey == "message");
|
||||
|
||||
let channel = expect_property_type!(Some(cvalue), "channel", Text);
|
||||
let channel = channel
|
||||
.parse()
|
||||
.map_err(|_| ResponseParserError::SyntaxError(0, channel))?;
|
||||
|
||||
let channel = expect_property_type!(Some(cvalue), "channel", Text).to_string();
|
||||
let message = expect_property_type!(Some(mvalue), "message", Text).to_string();
|
||||
|
||||
messages.push(ReadMessagesResponseEntry { channel, message });
|
||||
messages.push((channel, message));
|
||||
}
|
||||
|
||||
Ok(messages)
|
||||
Ok(ReadMessagesResponse { messages })
|
||||
}
|
||||
}
|
||||
|
||||
@@ -79,16 +65,12 @@ mod tests {
|
||||
let result = ReadMessages::parse_raw_response(input);
|
||||
assert_eq!(
|
||||
result,
|
||||
Ok(vec![
|
||||
ReadMessagesResponseEntry {
|
||||
channel: "channel1".parse().unwrap(),
|
||||
message: "message1".to_string(),
|
||||
},
|
||||
ReadMessagesResponseEntry {
|
||||
channel: "channel2".parse().unwrap(),
|
||||
message: "message2".to_string(),
|
||||
},
|
||||
])
|
||||
Ok(ReadMessagesResponse {
|
||||
messages: vec![
|
||||
("channel1".to_string(), "message1".to_string()),
|
||||
("channel2".to_string(), "message2".to_string()),
|
||||
]
|
||||
})
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,46 +1,28 @@
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::{
|
||||
commands::{Command, Request, RequestParserError, RequestParserResult, ResponseParserError},
|
||||
common::ChannelName,
|
||||
request_tokenizer::RequestTokenizer,
|
||||
response_tokenizer::ResponseAttributes,
|
||||
use crate::commands::{
|
||||
Command, Request, RequestParserError, RequestParserResult, ResponseAttributes,
|
||||
ResponseParserError,
|
||||
};
|
||||
|
||||
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: RequestTokenizer<'_>) -> RequestParserResult<'_> {
|
||||
fn parse_request(mut parts: std::str::SplitWhitespace<'_>) -> RequestParserResult<'_> {
|
||||
let channel = parts.next().ok_or(RequestParserError::UnexpectedEOF)?;
|
||||
let channel = channel
|
||||
.parse()
|
||||
.map_err(|_| RequestParserError::SyntaxError(0, channel.to_owned()))?;
|
||||
|
||||
// TODO: SplitWhitespace::remainder() is unstable, use when stable
|
||||
let message = parts.collect::<Vec<_>>().join(" ");
|
||||
|
||||
debug_assert!(!message.is_empty());
|
||||
|
||||
Ok((Request::SendMessage(channel, message), ""))
|
||||
Ok((Request::SendMessage(channel.to_string(), message), ""))
|
||||
}
|
||||
|
||||
fn parse_response(
|
||||
parts: ResponseAttributes<'_>,
|
||||
) -> Result<Self::Response, ResponseParserError<'_>> {
|
||||
) -> Result<Self::Response, ResponseParserError> {
|
||||
debug_assert!(parts.is_empty());
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -1,35 +1,25 @@
|
||||
use crate::{
|
||||
commands::{Command, Request, RequestParserError, RequestParserResult, ResponseParserError},
|
||||
common::ChannelName,
|
||||
request_tokenizer::RequestTokenizer,
|
||||
response_tokenizer::ResponseAttributes,
|
||||
use crate::commands::{
|
||||
Command, Request, RequestParserError, RequestParserResult, ResponseAttributes,
|
||||
ResponseParserError,
|
||||
};
|
||||
|
||||
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: RequestTokenizer<'_>) -> RequestParserResult<'_> {
|
||||
fn parse_request(mut parts: std::str::SplitWhitespace<'_>) -> RequestParserResult<'_> {
|
||||
let channel_name = parts.next().ok_or(RequestParserError::UnexpectedEOF)?;
|
||||
let channel_name = channel_name
|
||||
.parse()
|
||||
.map_err(|_| RequestParserError::SyntaxError(0, channel_name.to_owned()))?;
|
||||
|
||||
debug_assert!(parts.next().is_none());
|
||||
|
||||
Ok((Request::Subscribe(channel_name), ""))
|
||||
Ok((Request::Subscribe(channel_name.to_string()), ""))
|
||||
}
|
||||
|
||||
fn parse_response(
|
||||
parts: ResponseAttributes<'_>,
|
||||
) -> Result<Self::Response, ResponseParserError<'_>> {
|
||||
) -> Result<Self::Response, ResponseParserError> {
|
||||
debug_assert!(parts.is_empty());
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -1,35 +1,25 @@
|
||||
use crate::{
|
||||
commands::{Command, Request, RequestParserError, RequestParserResult, ResponseParserError},
|
||||
common::ChannelName,
|
||||
request_tokenizer::RequestTokenizer,
|
||||
response_tokenizer::ResponseAttributes,
|
||||
use crate::commands::{
|
||||
Command, Request, RequestParserError, RequestParserResult, ResponseAttributes,
|
||||
ResponseParserError,
|
||||
};
|
||||
|
||||
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: RequestTokenizer<'_>) -> RequestParserResult<'_> {
|
||||
fn parse_request(mut parts: std::str::SplitWhitespace<'_>) -> RequestParserResult<'_> {
|
||||
let channel_name = parts.next().ok_or(RequestParserError::UnexpectedEOF)?;
|
||||
let channel_name = channel_name
|
||||
.parse()
|
||||
.map_err(|_| RequestParserError::SyntaxError(0, channel_name.to_owned()))?;
|
||||
|
||||
debug_assert!(parts.next().is_none());
|
||||
|
||||
Ok((Request::Unsubscribe(channel_name), ""))
|
||||
Ok((Request::Unsubscribe(channel_name.to_string()), ""))
|
||||
}
|
||||
|
||||
fn parse_response(
|
||||
parts: ResponseAttributes<'_>,
|
||||
) -> Result<Self::Response, ResponseParserError<'_>> {
|
||||
) -> Result<Self::Response, ResponseParserError> {
|
||||
debug_assert!(parts.is_empty());
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -1,21 +1,15 @@
|
||||
use crate::{
|
||||
commands::{Command, Request, RequestParserError, RequestParserResult, ResponseParserError},
|
||||
request_tokenizer::RequestTokenizer,
|
||||
response_tokenizer::ResponseAttributes,
|
||||
use crate::commands::{
|
||||
Command, Request, RequestParserError, RequestParserResult, ResponseAttributes,
|
||||
ResponseParserError,
|
||||
};
|
||||
|
||||
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: RequestTokenizer<'_>) -> RequestParserResult<'_> {
|
||||
fn parse_request(mut parts: std::str::SplitWhitespace<'_>) -> RequestParserResult<'_> {
|
||||
let limit = parts.next().ok_or(RequestParserError::UnexpectedEOF)?;
|
||||
let limit = limit
|
||||
.parse()
|
||||
@@ -26,7 +20,7 @@ impl Command for BinaryLimit {
|
||||
|
||||
fn parse_response(
|
||||
parts: ResponseAttributes<'_>,
|
||||
) -> Result<Self::Response, ResponseParserError<'_>> {
|
||||
) -> Result<Self::Response, ResponseParserError> {
|
||||
debug_assert!(parts.is_empty());
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -1,28 +1,21 @@
|
||||
use crate::{
|
||||
commands::{Command, Request, RequestParserResult, ResponseParserError},
|
||||
request_tokenizer::RequestTokenizer,
|
||||
response_tokenizer::ResponseAttributes,
|
||||
use crate::commands::{
|
||||
Command, Request, RequestParserResult, ResponseAttributes, ResponseParserError,
|
||||
};
|
||||
|
||||
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: RequestTokenizer<'_>) -> RequestParserResult<'_> {
|
||||
fn parse_request(mut parts: std::str::SplitWhitespace<'_>) -> RequestParserResult<'_> {
|
||||
debug_assert!(parts.next().is_none());
|
||||
Ok((Request::Close, ""))
|
||||
}
|
||||
|
||||
fn parse_response(
|
||||
parts: ResponseAttributes<'_>,
|
||||
) -> Result<Self::Response, ResponseParserError<'_>> {
|
||||
) -> Result<Self::Response, ResponseParserError> {
|
||||
debug_assert!(parts.is_empty());
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -1,28 +1,21 @@
|
||||
use crate::{
|
||||
commands::{Command, Request, RequestParserResult, ResponseParserError},
|
||||
request_tokenizer::RequestTokenizer,
|
||||
response_tokenizer::ResponseAttributes,
|
||||
use crate::commands::{
|
||||
Command, Request, RequestParserResult, ResponseAttributes, ResponseParserError,
|
||||
};
|
||||
|
||||
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: RequestTokenizer<'_>) -> RequestParserResult<'_> {
|
||||
fn parse_request(mut parts: std::str::SplitWhitespace<'_>) -> RequestParserResult<'_> {
|
||||
debug_assert!(parts.next().is_none());
|
||||
Ok((Request::Kill, ""))
|
||||
}
|
||||
|
||||
fn parse_response(
|
||||
parts: ResponseAttributes<'_>,
|
||||
) -> Result<Self::Response, ResponseParserError<'_>> {
|
||||
) -> Result<Self::Response, ResponseParserError> {
|
||||
debug_assert!(parts.is_empty());
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -1,21 +1,15 @@
|
||||
use crate::{
|
||||
commands::{Command, Request, RequestParserError, RequestParserResult, ResponseParserError},
|
||||
request_tokenizer::RequestTokenizer,
|
||||
response_tokenizer::ResponseAttributes,
|
||||
use crate::commands::{
|
||||
Command, Request, RequestParserError, RequestParserResult, ResponseAttributes,
|
||||
ResponseParserError,
|
||||
};
|
||||
|
||||
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: RequestTokenizer<'_>) -> RequestParserResult<'_> {
|
||||
fn parse_request(mut parts: std::str::SplitWhitespace<'_>) -> RequestParserResult<'_> {
|
||||
let password = parts
|
||||
.next()
|
||||
.ok_or(RequestParserError::UnexpectedEOF)?
|
||||
@@ -26,7 +20,7 @@ impl Command for Password {
|
||||
|
||||
fn parse_response(
|
||||
parts: ResponseAttributes<'_>,
|
||||
) -> Result<Self::Response, ResponseParserError<'_>> {
|
||||
) -> Result<Self::Response, ResponseParserError> {
|
||||
debug_assert!(parts.is_empty());
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -1,28 +1,21 @@
|
||||
use crate::{
|
||||
commands::{Command, Request, RequestParserResult, ResponseParserError},
|
||||
request_tokenizer::RequestTokenizer,
|
||||
response_tokenizer::ResponseAttributes,
|
||||
use crate::commands::{
|
||||
Command, Request, RequestParserResult, ResponseAttributes, ResponseParserError,
|
||||
};
|
||||
|
||||
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: RequestTokenizer<'_>) -> RequestParserResult<'_> {
|
||||
fn parse_request(mut parts: std::str::SplitWhitespace<'_>) -> RequestParserResult<'_> {
|
||||
debug_assert!(parts.next().is_none());
|
||||
Ok((Request::Ping, ""))
|
||||
}
|
||||
|
||||
fn parse_response(
|
||||
parts: ResponseAttributes<'_>,
|
||||
) -> Result<Self::Response, ResponseParserError<'_>> {
|
||||
) -> Result<Self::Response, ResponseParserError> {
|
||||
debug_assert!(parts.is_empty());
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -1,41 +1,22 @@
|
||||
use crate::{
|
||||
commands::{Command, RequestParserResult, ResponseAttributes, ResponseParserError},
|
||||
Request,
|
||||
commands::{Command, RequestParserResult, ResponseParserError},
|
||||
request_tokenizer::RequestTokenizer,
|
||||
response_tokenizer::{ResponseAttributes, expect_property_type},
|
||||
};
|
||||
|
||||
pub struct Protocol;
|
||||
|
||||
pub type ProtocolResponse = Vec<String>;
|
||||
|
||||
impl Command for Protocol {
|
||||
type Request = ();
|
||||
type Response = ProtocolResponse;
|
||||
type Response = ();
|
||||
const COMMAND: &'static str = "protocol";
|
||||
|
||||
fn serialize_request(&self, _request: Self::Request) -> String {
|
||||
Self::COMMAND.to_string()
|
||||
}
|
||||
|
||||
fn parse_request(mut parts: RequestTokenizer<'_>) -> RequestParserResult<'_> {
|
||||
fn parse_request(mut parts: std::str::SplitWhitespace<'_>) -> RequestParserResult<'_> {
|
||||
debug_assert!(parts.next().is_none());
|
||||
Ok((Request::Protocol, ""))
|
||||
}
|
||||
|
||||
fn parse_response(
|
||||
parts: ResponseAttributes<'_>,
|
||||
) -> Result<Self::Response, ResponseParserError<'_>> {
|
||||
let parts_: Vec<_> = parts.into_vec()?;
|
||||
if let Some((k, _)) = parts_.iter().find(|(k, _)| *k != "feature") {
|
||||
return Err(ResponseParserError::UnexpectedProperty(k));
|
||||
}
|
||||
|
||||
let list = parts_
|
||||
.into_iter()
|
||||
.map(|(k, v)| Ok(expect_property_type!(Some(v), k, Text).to_string()))
|
||||
.collect::<Result<Vec<_>, ResponseParserError>>()?;
|
||||
|
||||
Ok(list)
|
||||
) -> Result<Self::Response, ResponseParserError> {
|
||||
unimplemented!()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,29 +1,22 @@
|
||||
use crate::{
|
||||
commands::{Command, RequestParserResult, ResponseAttributes, ResponseParserError},
|
||||
Request,
|
||||
commands::{Command, RequestParserResult, ResponseParserError},
|
||||
request_tokenizer::RequestTokenizer,
|
||||
response_tokenizer::ResponseAttributes,
|
||||
};
|
||||
|
||||
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: RequestTokenizer<'_>) -> RequestParserResult<'_> {
|
||||
fn parse_request(mut parts: std::str::SplitWhitespace<'_>) -> RequestParserResult<'_> {
|
||||
debug_assert!(parts.next().is_none());
|
||||
Ok((Request::ProtocolAll, ""))
|
||||
}
|
||||
|
||||
fn parse_response(
|
||||
parts: ResponseAttributes<'_>,
|
||||
) -> Result<Self::Response, ResponseParserError<'_>> {
|
||||
) -> Result<Self::Response, ResponseParserError> {
|
||||
debug_assert!(parts.is_empty());
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -1,41 +1,22 @@
|
||||
use crate::{
|
||||
commands::{Command, RequestParserResult, ResponseAttributes, ResponseParserError},
|
||||
Request,
|
||||
commands::{Command, RequestParserResult, ResponseParserError},
|
||||
request_tokenizer::RequestTokenizer,
|
||||
response_tokenizer::{ResponseAttributes, expect_property_type},
|
||||
};
|
||||
|
||||
pub struct ProtocolAvailable;
|
||||
|
||||
pub type ProtocolAvailableResponse = Vec<String>;
|
||||
|
||||
impl Command for ProtocolAvailable {
|
||||
type Request = ();
|
||||
type Response = ProtocolAvailableResponse;
|
||||
type Response = ();
|
||||
const COMMAND: &'static str = "protocol available";
|
||||
|
||||
fn serialize_request(&self, _request: Self::Request) -> String {
|
||||
Self::COMMAND.to_string()
|
||||
}
|
||||
|
||||
fn parse_request(mut parts: RequestTokenizer<'_>) -> RequestParserResult<'_> {
|
||||
fn parse_request(mut parts: std::str::SplitWhitespace<'_>) -> RequestParserResult<'_> {
|
||||
debug_assert!(parts.next().is_none());
|
||||
Ok((Request::ProtocolAvailable, ""))
|
||||
}
|
||||
|
||||
fn parse_response(
|
||||
parts: ResponseAttributes<'_>,
|
||||
) -> Result<Self::Response, ResponseParserError<'_>> {
|
||||
let parts_: Vec<_> = parts.into_vec()?;
|
||||
if let Some((k, _)) = parts_.iter().find(|(k, _)| *k != "feature") {
|
||||
return Err(ResponseParserError::UnexpectedProperty(k));
|
||||
}
|
||||
|
||||
let list = parts_
|
||||
.into_iter()
|
||||
.map(|(k, v)| Ok(expect_property_type!(Some(v), k, Text).to_string()))
|
||||
.collect::<Result<Vec<_>, ResponseParserError>>()?;
|
||||
|
||||
Ok(list)
|
||||
) -> Result<Self::Response, ResponseParserError> {
|
||||
unimplemented!()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,29 +1,22 @@
|
||||
use crate::{
|
||||
commands::{Command, RequestParserResult, ResponseAttributes, ResponseParserError},
|
||||
Request,
|
||||
commands::{Command, RequestParserResult, ResponseParserError},
|
||||
request_tokenizer::RequestTokenizer,
|
||||
response_tokenizer::ResponseAttributes,
|
||||
};
|
||||
|
||||
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: RequestTokenizer<'_>) -> RequestParserResult<'_> {
|
||||
fn parse_request(mut parts: std::str::SplitWhitespace<'_>) -> RequestParserResult<'_> {
|
||||
debug_assert!(parts.next().is_none());
|
||||
Ok((Request::ProtocolClear, ""))
|
||||
}
|
||||
|
||||
fn parse_response(
|
||||
parts: ResponseAttributes<'_>,
|
||||
) -> Result<Self::Response, ResponseParserError<'_>> {
|
||||
) -> Result<Self::Response, ResponseParserError> {
|
||||
debug_assert!(parts.is_empty());
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -1,38 +1,34 @@
|
||||
use crate::{
|
||||
commands::{
|
||||
Command, RequestParserError, RequestParserResult, ResponseAttributes, ResponseParserError,
|
||||
},
|
||||
Request,
|
||||
commands::{Command, RequestParserError, RequestParserResult, ResponseParserError},
|
||||
common::Feature,
|
||||
request_tokenizer::RequestTokenizer,
|
||||
response_tokenizer::ResponseAttributes,
|
||||
};
|
||||
|
||||
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: RequestTokenizer<'_>) -> RequestParserResult<'_> {
|
||||
fn parse_request(parts: std::str::SplitWhitespace<'_>) -> RequestParserResult<'_> {
|
||||
let mut parts = parts.peekable();
|
||||
if parts.peek().is_none() {
|
||||
return Err(RequestParserError::UnexpectedEOF);
|
||||
}
|
||||
|
||||
let features = parts.map(|s| s.to_string()).collect::<Vec<String>>();
|
||||
// TODO: verify that the features are split by whitespace
|
||||
let mut features = Vec::new();
|
||||
for feature in parts {
|
||||
features.push(feature.to_string());
|
||||
}
|
||||
|
||||
Ok((Request::ProtocolDisable(features), ""))
|
||||
}
|
||||
|
||||
fn parse_response(
|
||||
parts: ResponseAttributes<'_>,
|
||||
) -> Result<Self::Response, ResponseParserError<'_>> {
|
||||
) -> Result<Self::Response, ResponseParserError> {
|
||||
debug_assert!(parts.is_empty());
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -1,38 +1,34 @@
|
||||
use crate::{
|
||||
commands::{
|
||||
Command, RequestParserError, RequestParserResult, ResponseAttributes, ResponseParserError,
|
||||
},
|
||||
Request,
|
||||
commands::{Command, RequestParserError, RequestParserResult, ResponseParserError},
|
||||
common::Feature,
|
||||
request_tokenizer::RequestTokenizer,
|
||||
response_tokenizer::ResponseAttributes,
|
||||
};
|
||||
|
||||
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: RequestTokenizer<'_>) -> RequestParserResult<'_> {
|
||||
fn parse_request(parts: std::str::SplitWhitespace<'_>) -> RequestParserResult<'_> {
|
||||
let mut parts = parts.peekable();
|
||||
if parts.peek().is_none() {
|
||||
return Err(RequestParserError::UnexpectedEOF);
|
||||
}
|
||||
|
||||
let features = parts.map(|s| s.to_string()).collect::<Vec<String>>();
|
||||
// TODO: verify that the features are split by whitespace
|
||||
let mut features = Vec::new();
|
||||
for feature in parts {
|
||||
features.push(feature.to_string());
|
||||
}
|
||||
|
||||
Ok((Request::ProtocolEnable(features), ""))
|
||||
}
|
||||
|
||||
fn parse_response(
|
||||
parts: ResponseAttributes<'_>,
|
||||
) -> Result<Self::Response, ResponseParserError<'_>> {
|
||||
) -> Result<Self::Response, ResponseParserError> {
|
||||
debug_assert!(parts.is_empty());
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
use crate::{
|
||||
commands::{Command, Request, RequestParserResult, ResponseParserError},
|
||||
request_tokenizer::RequestTokenizer,
|
||||
response_tokenizer::{ResponseAttributes, expect_property_type},
|
||||
use crate::commands::{
|
||||
Command, GenericResponseValue, Request, RequestParserResult, ResponseAttributes,
|
||||
ResponseParserError,
|
||||
};
|
||||
|
||||
pub struct TagTypes;
|
||||
@@ -9,31 +8,31 @@ 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: RequestTokenizer<'_>) -> RequestParserResult<'_> {
|
||||
fn parse_request(mut parts: std::str::SplitWhitespace<'_>) -> RequestParserResult<'_> {
|
||||
debug_assert!(parts.next().is_none());
|
||||
Ok((Request::TagTypes, ""))
|
||||
}
|
||||
|
||||
fn parse_response(
|
||||
parts: ResponseAttributes<'_>,
|
||||
) -> Result<Self::Response, ResponseParserError<'_>> {
|
||||
let parts: Vec<_> = parts.into_vec()?;
|
||||
) -> Result<Self::Response, ResponseParserError> {
|
||||
let parts: Vec<_> = parts.into();
|
||||
|
||||
let mut tagtypes = Vec::with_capacity(parts.len());
|
||||
for (key, value) in parts.into_iter() {
|
||||
if key != "tagtype" {
|
||||
return Err(ResponseParserError::UnexpectedProperty(key));
|
||||
}
|
||||
debug_assert_eq!(key, "tagtype");
|
||||
|
||||
let tagtype = expect_property_type!(Some(value), "tagtype", Text).to_string();
|
||||
let tagtype = match value {
|
||||
GenericResponseValue::Text(name) => name.to_string(),
|
||||
GenericResponseValue::Binary(_) => {
|
||||
return Err(ResponseParserError::UnexpectedPropertyType(
|
||||
"tagtype", "Binary",
|
||||
))
|
||||
}
|
||||
};
|
||||
|
||||
tagtypes.push(tagtype);
|
||||
}
|
||||
|
||||
@@ -1,29 +1,22 @@
|
||||
use crate::{
|
||||
commands::{Command, RequestParserResult, ResponseAttributes, ResponseParserError},
|
||||
Request,
|
||||
commands::{Command, RequestParserResult, ResponseParserError},
|
||||
request_tokenizer::RequestTokenizer,
|
||||
response_tokenizer::ResponseAttributes,
|
||||
};
|
||||
|
||||
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: RequestTokenizer<'_>) -> RequestParserResult<'_> {
|
||||
fn parse_request(mut parts: std::str::SplitWhitespace<'_>) -> RequestParserResult<'_> {
|
||||
debug_assert!(parts.next().is_none());
|
||||
Ok((Request::TagTypesAll, ""))
|
||||
}
|
||||
|
||||
fn parse_response(
|
||||
parts: ResponseAttributes<'_>,
|
||||
) -> Result<Self::Response, ResponseParserError<'_>> {
|
||||
) -> Result<Self::Response, ResponseParserError> {
|
||||
debug_assert!(parts.is_empty());
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -1,44 +1,22 @@
|
||||
use crate::{
|
||||
commands::{Command, RequestParserResult, ResponseAttributes, ResponseParserError},
|
||||
Request,
|
||||
commands::{Command, RequestParserResult, ResponseParserError},
|
||||
request_tokenizer::RequestTokenizer,
|
||||
response_tokenizer::{ResponseAttributes, expect_property_type},
|
||||
};
|
||||
|
||||
pub struct TagTypesAvailable;
|
||||
|
||||
pub type TagTypesAvailableResponse = Vec<String>;
|
||||
|
||||
impl Command for TagTypesAvailable {
|
||||
type Request = ();
|
||||
type Response = TagTypesAvailableResponse;
|
||||
type Response = ();
|
||||
const COMMAND: &'static str = "tagtypes available";
|
||||
|
||||
fn serialize_request(&self, _request: Self::Request) -> String {
|
||||
Self::COMMAND.to_string()
|
||||
}
|
||||
|
||||
fn parse_request(mut parts: RequestTokenizer<'_>) -> RequestParserResult<'_> {
|
||||
fn parse_request(mut parts: std::str::SplitWhitespace<'_>) -> RequestParserResult<'_> {
|
||||
debug_assert!(parts.next().is_none());
|
||||
Ok((Request::TagTypesAvailable, ""))
|
||||
}
|
||||
|
||||
fn parse_response(
|
||||
parts: ResponseAttributes<'_>,
|
||||
) -> Result<Self::Response, ResponseParserError<'_>> {
|
||||
let parts: Vec<_> = parts.into_vec()?;
|
||||
|
||||
let mut tagtypes = Vec::with_capacity(parts.len());
|
||||
for (key, value) in parts.into_iter() {
|
||||
if key != "tagtype" {
|
||||
return Err(ResponseParserError::UnexpectedProperty(key));
|
||||
}
|
||||
|
||||
let tagtype = expect_property_type!(Some(value), "tagtype", Text).to_string();
|
||||
|
||||
tagtypes.push(tagtype);
|
||||
}
|
||||
|
||||
Ok(tagtypes)
|
||||
) -> Result<Self::Response, ResponseParserError> {
|
||||
unimplemented!()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,29 +1,22 @@
|
||||
use crate::{
|
||||
commands::{Command, RequestParserResult, ResponseAttributes, ResponseParserError},
|
||||
Request,
|
||||
commands::{Command, RequestParserResult, ResponseParserError},
|
||||
request_tokenizer::RequestTokenizer,
|
||||
response_tokenizer::ResponseAttributes,
|
||||
};
|
||||
|
||||
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: RequestTokenizer<'_>) -> RequestParserResult<'_> {
|
||||
fn parse_request(mut parts: std::str::SplitWhitespace<'_>) -> RequestParserResult<'_> {
|
||||
debug_assert!(parts.next().is_none());
|
||||
Ok((Request::TagTypesClear, ""))
|
||||
}
|
||||
|
||||
fn parse_response(
|
||||
parts: ResponseAttributes<'_>,
|
||||
) -> Result<Self::Response, ResponseParserError<'_>> {
|
||||
) -> Result<Self::Response, ResponseParserError> {
|
||||
debug_assert!(parts.is_empty());
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -1,38 +1,34 @@
|
||||
use crate::{
|
||||
commands::{
|
||||
Command, RequestParserError, RequestParserResult, ResponseAttributes, ResponseParserError,
|
||||
},
|
||||
Request,
|
||||
commands::{Command, RequestParserError, RequestParserResult, ResponseParserError},
|
||||
common::TagName,
|
||||
request_tokenizer::RequestTokenizer,
|
||||
response_tokenizer::ResponseAttributes,
|
||||
};
|
||||
|
||||
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: RequestTokenizer<'_>) -> RequestParserResult<'_> {
|
||||
fn parse_request(parts: std::str::SplitWhitespace<'_>) -> RequestParserResult<'_> {
|
||||
let mut parts = parts.peekable();
|
||||
if parts.peek().is_none() {
|
||||
return Err(RequestParserError::UnexpectedEOF);
|
||||
}
|
||||
|
||||
let tag_types = parts.map(|s| s.to_string()).collect::<Vec<String>>();
|
||||
// TODO: verify that the tag types are split by whitespace
|
||||
let mut tag_types = Vec::new();
|
||||
for tag_type in parts {
|
||||
tag_types.push(tag_type.to_string());
|
||||
}
|
||||
|
||||
Ok((Request::TagTypesDisable(tag_types), ""))
|
||||
}
|
||||
|
||||
fn parse_response(
|
||||
parts: ResponseAttributes<'_>,
|
||||
) -> Result<Self::Response, ResponseParserError<'_>> {
|
||||
) -> Result<Self::Response, ResponseParserError> {
|
||||
debug_assert!(parts.is_empty());
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -1,38 +1,34 @@
|
||||
use crate::{
|
||||
commands::{
|
||||
Command, RequestParserError, RequestParserResult, ResponseAttributes, ResponseParserError,
|
||||
},
|
||||
Request,
|
||||
commands::{Command, RequestParserError, RequestParserResult, ResponseParserError},
|
||||
common::TagName,
|
||||
request_tokenizer::RequestTokenizer,
|
||||
response_tokenizer::ResponseAttributes,
|
||||
};
|
||||
|
||||
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: RequestTokenizer<'_>) -> RequestParserResult<'_> {
|
||||
fn parse_request(parts: std::str::SplitWhitespace<'_>) -> RequestParserResult<'_> {
|
||||
let mut parts = parts.peekable();
|
||||
if parts.peek().is_none() {
|
||||
return Err(RequestParserError::UnexpectedEOF);
|
||||
}
|
||||
|
||||
let tag_types = parts.map(|s| s.to_string()).collect::<Vec<String>>();
|
||||
// TODO: verify that the tag types are split by whitespace
|
||||
let mut tag_types = Vec::new();
|
||||
for tag_type in parts {
|
||||
tag_types.push(tag_type.to_string());
|
||||
}
|
||||
|
||||
Ok((Request::TagTypesEnable(tag_types), ""))
|
||||
}
|
||||
|
||||
fn parse_response(
|
||||
parts: ResponseAttributes<'_>,
|
||||
) -> Result<Self::Response, ResponseParserError<'_>> {
|
||||
) -> Result<Self::Response, ResponseParserError> {
|
||||
debug_assert!(parts.is_empty());
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -1,39 +1,34 @@
|
||||
use crate::{
|
||||
commands::{
|
||||
Command, RequestParserError, RequestParserResult, ResponseAttributes, ResponseParserError,
|
||||
},
|
||||
Request,
|
||||
commands::{Command, RequestParserError, RequestParserResult, ResponseParserError},
|
||||
common::TagName,
|
||||
request_tokenizer::RequestTokenizer,
|
||||
response_tokenizer::ResponseAttributes,
|
||||
};
|
||||
|
||||
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: RequestTokenizer<'_>) -> RequestParserResult<'_> {
|
||||
fn parse_request(parts: std::str::SplitWhitespace<'_>) -> RequestParserResult<'_> {
|
||||
let mut parts = parts.peekable();
|
||||
if parts.peek().is_none() {
|
||||
return Err(RequestParserError::UnexpectedEOF);
|
||||
}
|
||||
|
||||
// TODO: verify that the tag types are split by whitespace
|
||||
let tag_types = parts.map(|s| s.to_string()).collect::<Vec<String>>();
|
||||
let mut tag_types = Vec::new();
|
||||
for tag_type in parts {
|
||||
tag_types.push(tag_type.to_string());
|
||||
}
|
||||
|
||||
Ok((Request::TagTypesReset(tag_types), ""))
|
||||
}
|
||||
|
||||
fn parse_response(
|
||||
parts: ResponseAttributes<'_>,
|
||||
) -> Result<Self::Response, ResponseParserError<'_>> {
|
||||
) -> Result<Self::Response, ResponseParserError> {
|
||||
debug_assert!(parts.is_empty());
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -1,28 +1,21 @@
|
||||
use crate::{
|
||||
commands::{Command, Request, RequestParserResult, ResponseParserError},
|
||||
request_tokenizer::RequestTokenizer,
|
||||
response_tokenizer::ResponseAttributes,
|
||||
use crate::commands::{
|
||||
Command, Request, RequestParserResult, ResponseAttributes, ResponseParserError,
|
||||
};
|
||||
|
||||
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: RequestTokenizer<'_>) -> RequestParserResult<'_> {
|
||||
fn parse_request(mut parts: std::str::SplitWhitespace<'_>) -> RequestParserResult<'_> {
|
||||
debug_assert!(parts.next().is_none());
|
||||
Ok((Request::Next, ""))
|
||||
}
|
||||
|
||||
fn parse_response(
|
||||
parts: ResponseAttributes<'_>,
|
||||
) -> Result<Self::Response, ResponseParserError<'_>> {
|
||||
) -> Result<Self::Response, ResponseParserError> {
|
||||
debug_assert!(parts.is_empty());
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -1,25 +1,15 @@
|
||||
use crate::{
|
||||
commands::{Command, Request, RequestParserError, RequestParserResult, ResponseParserError},
|
||||
request_tokenizer::RequestTokenizer,
|
||||
response_tokenizer::ResponseAttributes,
|
||||
use crate::commands::{
|
||||
Command, Request, RequestParserError, RequestParserResult, ResponseAttributes,
|
||||
ResponseParserError,
|
||||
};
|
||||
|
||||
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: RequestTokenizer<'_>) -> RequestParserResult<'_> {
|
||||
fn parse_request(mut parts: std::str::SplitWhitespace<'_>) -> RequestParserResult<'_> {
|
||||
let result = match parts.next() {
|
||||
Some("0") => Ok((Request::Pause(Some(false)), "")),
|
||||
Some("1") => Ok((Request::Pause(Some(true)), "")),
|
||||
@@ -34,7 +24,7 @@ impl Command for Pause {
|
||||
|
||||
fn parse_response(
|
||||
parts: ResponseAttributes<'_>,
|
||||
) -> Result<Self::Response, ResponseParserError<'_>> {
|
||||
) -> Result<Self::Response, ResponseParserError> {
|
||||
debug_assert!(parts.is_empty());
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -1,22 +1,18 @@
|
||||
use crate::{
|
||||
commands::{Command, Request, RequestParserError, RequestParserResult, ResponseParserError},
|
||||
commands::{
|
||||
Command, Request, RequestParserError, RequestParserResult, ResponseAttributes,
|
||||
ResponseParserError,
|
||||
},
|
||||
common::SongPosition,
|
||||
request_tokenizer::RequestTokenizer,
|
||||
response_tokenizer::ResponseAttributes,
|
||||
};
|
||||
|
||||
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: RequestTokenizer<'_>) -> RequestParserResult<'_> {
|
||||
fn parse_request(mut parts: std::str::SplitWhitespace<'_>) -> RequestParserResult<'_> {
|
||||
let songpos = match parts.next() {
|
||||
Some(s) => s
|
||||
.parse::<SongPosition>()
|
||||
@@ -31,7 +27,7 @@ impl Command for Play {
|
||||
|
||||
fn parse_response(
|
||||
parts: ResponseAttributes<'_>,
|
||||
) -> Result<Self::Response, ResponseParserError<'_>> {
|
||||
) -> Result<Self::Response, ResponseParserError> {
|
||||
debug_assert!(parts.is_empty());
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -1,22 +1,18 @@
|
||||
use crate::{
|
||||
commands::{Command, Request, RequestParserError, RequestParserResult, ResponseParserError},
|
||||
commands::{
|
||||
Command, Request, RequestParserError, RequestParserResult, ResponseAttributes,
|
||||
ResponseParserError,
|
||||
},
|
||||
common::SongId,
|
||||
request_tokenizer::RequestTokenizer,
|
||||
response_tokenizer::ResponseAttributes,
|
||||
};
|
||||
|
||||
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: RequestTokenizer<'_>) -> RequestParserResult<'_> {
|
||||
fn parse_request(mut parts: std::str::SplitWhitespace<'_>) -> RequestParserResult<'_> {
|
||||
let songid = match parts.next() {
|
||||
Some(s) => s
|
||||
.parse::<SongId>()
|
||||
@@ -31,7 +27,7 @@ impl Command for PlayId {
|
||||
|
||||
fn parse_response(
|
||||
parts: ResponseAttributes<'_>,
|
||||
) -> Result<Self::Response, ResponseParserError<'_>> {
|
||||
) -> Result<Self::Response, ResponseParserError> {
|
||||
debug_assert!(parts.is_empty());
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -1,28 +1,21 @@
|
||||
use crate::{
|
||||
commands::{Command, Request, RequestParserResult, ResponseParserError},
|
||||
request_tokenizer::RequestTokenizer,
|
||||
response_tokenizer::ResponseAttributes,
|
||||
use crate::commands::{
|
||||
Command, Request, RequestParserResult, ResponseAttributes, ResponseParserError,
|
||||
};
|
||||
|
||||
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: RequestTokenizer<'_>) -> RequestParserResult<'_> {
|
||||
fn parse_request(mut parts: std::str::SplitWhitespace<'_>) -> RequestParserResult<'_> {
|
||||
debug_assert!(parts.next().is_none());
|
||||
Ok((Request::Previous, ""))
|
||||
}
|
||||
|
||||
fn parse_response(
|
||||
parts: ResponseAttributes<'_>,
|
||||
) -> Result<Self::Response, ResponseParserError<'_>> {
|
||||
) -> Result<Self::Response, ResponseParserError> {
|
||||
debug_assert!(parts.is_empty());
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -1,30 +1,18 @@
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::{
|
||||
commands::{Command, Request, RequestParserError, RequestParserResult, ResponseParserError},
|
||||
commands::{
|
||||
Command, Request, RequestParserError, RequestParserResult, ResponseAttributes,
|
||||
ResponseParserError,
|
||||
},
|
||||
common::{SongPosition, TimeWithFractions},
|
||||
request_tokenizer::RequestTokenizer,
|
||||
response_tokenizer::ResponseAttributes,
|
||||
};
|
||||
|
||||
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: RequestTokenizer<'_>) -> RequestParserResult<'_> {
|
||||
fn parse_request(mut parts: std::str::SplitWhitespace<'_>) -> RequestParserResult<'_> {
|
||||
let songpos = match parts.next() {
|
||||
Some(s) => s
|
||||
.parse::<SongPosition>()
|
||||
@@ -46,7 +34,7 @@ impl Command for Seek {
|
||||
|
||||
fn parse_response(
|
||||
parts: ResponseAttributes<'_>,
|
||||
) -> Result<Self::Response, ResponseParserError<'_>> {
|
||||
) -> Result<Self::Response, ResponseParserError> {
|
||||
debug_assert!(parts.is_empty());
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -1,39 +1,18 @@
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::{
|
||||
commands::{
|
||||
Command, Request, RequestParserError, RequestParserResult, ResponseAttributes,
|
||||
ResponseParserError,
|
||||
},
|
||||
common::{SeekMode, TimeWithFractions},
|
||||
request_tokenizer::RequestTokenizer,
|
||||
};
|
||||
|
||||
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: RequestTokenizer<'_>) -> RequestParserResult<'_> {
|
||||
fn parse_request(mut parts: std::str::SplitWhitespace<'_>) -> RequestParserResult<'_> {
|
||||
let time_raw = match parts.next() {
|
||||
Some(t) => t,
|
||||
None => return Err(RequestParserError::UnexpectedEOF),
|
||||
@@ -67,7 +46,7 @@ impl Command for SeekCur {
|
||||
|
||||
fn parse_response(
|
||||
parts: ResponseAttributes<'_>,
|
||||
) -> Result<Self::Response, ResponseParserError<'_>> {
|
||||
) -> Result<Self::Response, ResponseParserError> {
|
||||
debug_assert!(parts.is_empty());
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -1,30 +1,18 @@
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::{
|
||||
commands::{Command, Request, RequestParserError, RequestParserResult, ResponseParserError},
|
||||
commands::{
|
||||
Command, Request, RequestParserError, RequestParserResult, ResponseAttributes,
|
||||
ResponseParserError,
|
||||
},
|
||||
common::{SongId, TimeWithFractions},
|
||||
request_tokenizer::RequestTokenizer,
|
||||
response_tokenizer::ResponseAttributes,
|
||||
};
|
||||
|
||||
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: RequestTokenizer<'_>) -> RequestParserResult<'_> {
|
||||
fn parse_request(mut parts: std::str::SplitWhitespace<'_>) -> RequestParserResult<'_> {
|
||||
let songid = match parts.next() {
|
||||
Some(s) => s
|
||||
.parse::<SongId>()
|
||||
@@ -46,7 +34,7 @@ impl Command for SeekId {
|
||||
|
||||
fn parse_response(
|
||||
parts: ResponseAttributes<'_>,
|
||||
) -> Result<Self::Response, ResponseParserError<'_>> {
|
||||
) -> Result<Self::Response, ResponseParserError> {
|
||||
debug_assert!(parts.is_empty());
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -1,28 +1,21 @@
|
||||
use crate::{
|
||||
commands::{Command, Request, RequestParserResult, ResponseParserError},
|
||||
request_tokenizer::RequestTokenizer,
|
||||
response_tokenizer::ResponseAttributes,
|
||||
use crate::commands::{
|
||||
Command, Request, RequestParserResult, ResponseAttributes, ResponseParserError,
|
||||
};
|
||||
|
||||
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: RequestTokenizer<'_>) -> RequestParserResult<'_> {
|
||||
fn parse_request(mut parts: std::str::SplitWhitespace<'_>) -> RequestParserResult<'_> {
|
||||
debug_assert!(parts.next().is_none());
|
||||
Ok((Request::Stop, ""))
|
||||
}
|
||||
|
||||
fn parse_response(
|
||||
parts: ResponseAttributes<'_>,
|
||||
) -> Result<Self::Response, ResponseParserError<'_>> {
|
||||
) -> Result<Self::Response, ResponseParserError> {
|
||||
debug_assert!(parts.is_empty());
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -1,56 +1,22 @@
|
||||
use crate::{
|
||||
commands::{Command, RequestParserResult, ResponseAttributes, ResponseParserError},
|
||||
Request,
|
||||
commands::{Command, RequestParserResult, ResponseParserError},
|
||||
request_tokenizer::RequestTokenizer,
|
||||
response_tokenizer::{ResponseAttributes, expect_property_type},
|
||||
};
|
||||
|
||||
pub struct ListMounts;
|
||||
|
||||
impl Command for ListMounts {
|
||||
type Request = ();
|
||||
type Response = Vec<String>;
|
||||
type Response = Vec<(String, String)>;
|
||||
const COMMAND: &'static str = "listmounts";
|
||||
|
||||
fn serialize_request(&self, _request: Self::Request) -> String {
|
||||
Self::COMMAND.to_string()
|
||||
}
|
||||
|
||||
fn parse_request(mut parts: RequestTokenizer<'_>) -> RequestParserResult<'_> {
|
||||
fn parse_request(mut parts: std::str::SplitWhitespace<'_>) -> RequestParserResult<'_> {
|
||||
debug_assert!(parts.next().is_none());
|
||||
Ok((Request::ListMounts, ""))
|
||||
}
|
||||
|
||||
fn parse_response(
|
||||
parts: ResponseAttributes<'_>,
|
||||
) -> Result<Self::Response, ResponseParserError<'_>> {
|
||||
let parts: Vec<_> = parts.into_vec()?;
|
||||
let mut result = Vec::with_capacity(parts.len());
|
||||
for (key, value) in parts.into_iter() {
|
||||
if key != "mount" {
|
||||
return Err(ResponseParserError::UnexpectedProperty(key));
|
||||
}
|
||||
let value = expect_property_type!(Some(value), "mount", Text).to_string();
|
||||
result.push(value);
|
||||
}
|
||||
Ok(result)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use indoc::indoc;
|
||||
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn test_parse_response() {
|
||||
let input = indoc! {"
|
||||
mount:
|
||||
mount: /mnt/music
|
||||
OK
|
||||
"};
|
||||
let result = ListMounts::parse_raw_response(input);
|
||||
assert_eq!(result, Ok(vec!["".to_string(), "/mnt/music".to_string(),]));
|
||||
) -> Result<Self::Response, ResponseParserError> {
|
||||
unimplemented!()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,51 +1,22 @@
|
||||
use std::collections::HashMap;
|
||||
|
||||
use crate::{
|
||||
commands::{Command, RequestParserResult, ResponseAttributes, ResponseParserError},
|
||||
Request,
|
||||
commands::{Command, RequestParserResult, ResponseParserError},
|
||||
request_tokenizer::RequestTokenizer,
|
||||
response_tokenizer::{ResponseAttributes, expect_property_type},
|
||||
};
|
||||
|
||||
pub struct ListNeighbors;
|
||||
|
||||
pub type ListNeighborsResponse = HashMap<String, String>;
|
||||
|
||||
impl Command for ListNeighbors {
|
||||
type Request = ();
|
||||
type Response = ListNeighborsResponse;
|
||||
type Response = Vec<(String, String)>;
|
||||
const COMMAND: &'static str = "listneighbors";
|
||||
|
||||
fn serialize_request(&self, _request: Self::Request) -> String {
|
||||
Self::COMMAND.to_string()
|
||||
}
|
||||
|
||||
fn parse_request(mut parts: RequestTokenizer<'_>) -> RequestParserResult<'_> {
|
||||
fn parse_request(mut parts: std::str::SplitWhitespace<'_>) -> RequestParserResult<'_> {
|
||||
debug_assert!(parts.next().is_none());
|
||||
Ok((Request::ListNeighbors, ""))
|
||||
}
|
||||
|
||||
fn parse_response(
|
||||
parts: ResponseAttributes<'_>,
|
||||
) -> Result<Self::Response, ResponseParserError<'_>> {
|
||||
let parts: Vec<_> = parts.into_vec()?;
|
||||
debug_assert!(parts.len() % 2 == 0);
|
||||
|
||||
let mut result = HashMap::with_capacity(parts.len() / 2);
|
||||
|
||||
for channel_message_pair in parts.chunks_exact(2) {
|
||||
let (neigh_key, neigh_value) = channel_message_pair[0];
|
||||
let (name_key, name_value) = channel_message_pair[1];
|
||||
|
||||
debug_assert!(neigh_key == "neighbor");
|
||||
debug_assert!(name_key == "name");
|
||||
|
||||
let neighbor = expect_property_type!(Some(neigh_value), "neighbor", Text).to_string();
|
||||
let name = expect_property_type!(Some(name_value), "name", Text).to_string();
|
||||
|
||||
result.insert(neighbor, name);
|
||||
}
|
||||
|
||||
Ok(result)
|
||||
) -> Result<Self::Response, ResponseParserError> {
|
||||
unimplemented!()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,34 +1,21 @@
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::{
|
||||
commands::{
|
||||
Command, RequestParserError, RequestParserResult, ResponseAttributes, ResponseParserError,
|
||||
},
|
||||
Request,
|
||||
commands::{Command, RequestParserError, RequestParserResult, ResponseParserError},
|
||||
request_tokenizer::RequestTokenizer,
|
||||
response_tokenizer::ResponseAttributes,
|
||||
};
|
||||
|
||||
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: RequestTokenizer<'_>) -> RequestParserResult<'_> {
|
||||
let path = parts.next().ok_or(RequestParserError::UnexpectedEOF)?;
|
||||
let path = path
|
||||
.parse()
|
||||
.map_err(|_| RequestParserError::SyntaxError(0, path.to_string()))?;
|
||||
fn parse_request(mut parts: std::str::SplitWhitespace<'_>) -> RequestParserResult<'_> {
|
||||
let path = parts
|
||||
.next()
|
||||
.ok_or(RequestParserError::UnexpectedEOF)?
|
||||
.to_string();
|
||||
|
||||
let uri = parts
|
||||
.next()
|
||||
@@ -42,7 +29,7 @@ impl Command for Mount {
|
||||
|
||||
fn parse_response(
|
||||
parts: ResponseAttributes<'_>,
|
||||
) -> Result<Self::Response, ResponseParserError<'_>> {
|
||||
) -> Result<Self::Response, ResponseParserError> {
|
||||
debug_assert!(parts.is_empty());
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -1,28 +1,21 @@
|
||||
use crate::{
|
||||
commands::{
|
||||
Command, RequestParserError, RequestParserResult, ResponseAttributes, ResponseParserError,
|
||||
},
|
||||
Request,
|
||||
commands::{Command, RequestParserError, RequestParserResult, ResponseParserError},
|
||||
request_tokenizer::RequestTokenizer,
|
||||
response_tokenizer::ResponseAttributes,
|
||||
};
|
||||
|
||||
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: RequestTokenizer<'_>) -> RequestParserResult<'_> {
|
||||
let path = parts.next().ok_or(RequestParserError::UnexpectedEOF)?;
|
||||
let path = path
|
||||
.parse()
|
||||
.map_err(|_| RequestParserError::SyntaxError(0, path.to_string()))?;
|
||||
fn parse_request(mut parts: std::str::SplitWhitespace<'_>) -> RequestParserResult<'_> {
|
||||
let path = parts
|
||||
.next()
|
||||
.ok_or(RequestParserError::UnexpectedEOF)?
|
||||
.to_string();
|
||||
|
||||
debug_assert!(parts.next().is_none());
|
||||
|
||||
@@ -31,7 +24,7 @@ impl Command for Unmount {
|
||||
|
||||
fn parse_response(
|
||||
parts: ResponseAttributes<'_>,
|
||||
) -> Result<Self::Response, ResponseParserError<'_>> {
|
||||
) -> Result<Self::Response, ResponseParserError> {
|
||||
debug_assert!(parts.is_empty());
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -1,38 +1,25 @@
|
||||
use std::collections::HashMap;
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::{
|
||||
commands::{Command, Request, RequestParserError, RequestParserResult, ResponseParserError},
|
||||
common::{Offset, Uri},
|
||||
request_tokenizer::RequestTokenizer,
|
||||
response_tokenizer::{ResponseAttributes, get_and_parse_property, get_property},
|
||||
commands::{
|
||||
get_and_parse_property, get_property, Command, Request, RequestParserError,
|
||||
RequestParserResult, ResponseAttributes, ResponseParserError,
|
||||
},
|
||||
common::Offset,
|
||||
};
|
||||
|
||||
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,
|
||||
pub binary: Vec<u8>,
|
||||
}
|
||||
|
||||
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: RequestTokenizer<'_>) -> RequestParserResult<'_> {
|
||||
fn parse_request(mut parts: std::str::SplitWhitespace<'_>) -> RequestParserResult<'_> {
|
||||
let uri = match parts.next() {
|
||||
Some(s) => s,
|
||||
None => return Err(RequestParserError::UnexpectedEOF),
|
||||
@@ -52,8 +39,8 @@ impl Command for AlbumArt {
|
||||
|
||||
fn parse_response(
|
||||
parts: ResponseAttributes<'_>,
|
||||
) -> Result<Self::Response, ResponseParserError<'_>> {
|
||||
let parts: HashMap<_, _> = parts.into_map()?;
|
||||
) -> Result<Self::Response, ResponseParserError> {
|
||||
let parts: HashMap<_, _> = parts.into();
|
||||
|
||||
let size = get_and_parse_property!(parts, "size", Text);
|
||||
|
||||
|
||||
@@ -1,49 +1,26 @@
|
||||
use std::collections::HashMap;
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::{
|
||||
commands::{Command, Request, RequestParserError, RequestParserResult, ResponseParserError},
|
||||
common::GroupType,
|
||||
filter::Filter,
|
||||
request_tokenizer::RequestTokenizer,
|
||||
response_tokenizer::{ResponseAttributes, get_and_parse_property},
|
||||
commands::{
|
||||
get_and_parse_property, Command, Request, RequestParserError, RequestParserResult,
|
||||
ResponseAttributes, ResponseParserError,
|
||||
},
|
||||
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,
|
||||
pub playtime: u64,
|
||||
}
|
||||
|
||||
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: RequestTokenizer<'_>) -> RequestParserResult<'_> {
|
||||
let filter = match parts.next() {
|
||||
Some(f) => {
|
||||
Filter::parse(f).map_err(|_| RequestParserError::SyntaxError(1, f.to_owned()))?
|
||||
}
|
||||
None => return Err(RequestParserError::UnexpectedEOF),
|
||||
};
|
||||
fn parse_request(mut parts: std::str::SplitWhitespace<'_>) -> RequestParserResult<'_> {
|
||||
let filter = parse_filter(&mut parts)?;
|
||||
|
||||
let group = if let Some("group") = parts.next() {
|
||||
let group = parts.next().ok_or(RequestParserError::UnexpectedEOF)?;
|
||||
@@ -64,8 +41,8 @@ impl Command for Count {
|
||||
|
||||
fn parse_response(
|
||||
parts: ResponseAttributes<'_>,
|
||||
) -> Result<Self::Response, ResponseParserError<'_>> {
|
||||
let parts: HashMap<_, _> = parts.into_map()?;
|
||||
) -> Result<Self::Response, ResponseParserError> {
|
||||
let parts: HashMap<_, _> = parts.into();
|
||||
|
||||
let songs = get_and_parse_property!(parts, "songs", Text);
|
||||
let playtime = get_and_parse_property!(parts, "playtime", Text);
|
||||
|
||||
@@ -1,56 +1,30 @@
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::{
|
||||
commands::{Command, Request, RequestParserError, RequestParserResult, ResponseParserError},
|
||||
common::{Sort, WindowRange},
|
||||
filter::Filter,
|
||||
request_tokenizer::RequestTokenizer,
|
||||
response_tokenizer::ResponseAttributes,
|
||||
commands::{
|
||||
Command, Request, RequestParserError, RequestParserResult, ResponseAttributes,
|
||||
ResponseParserError,
|
||||
},
|
||||
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: RequestTokenizer<'_>) -> RequestParserResult<'_> {
|
||||
let filter = match parts.next() {
|
||||
Some(f) => {
|
||||
Filter::parse(f).map_err(|_| RequestParserError::SyntaxError(1, f.to_owned()))?
|
||||
}
|
||||
None => return Err(RequestParserError::UnexpectedEOF),
|
||||
};
|
||||
fn parse_request(mut parts: std::str::SplitWhitespace<'_>) -> RequestParserResult<'_> {
|
||||
let filter = parse_filter(&mut parts)?;
|
||||
|
||||
let mut sort_or_window = parts.next();
|
||||
let mut sort = None;
|
||||
if let Some("sort") = sort_or_window {
|
||||
let s = parts.next().ok_or(RequestParserError::UnexpectedEOF)?;
|
||||
sort = Some(
|
||||
s.parse()
|
||||
.map_err(|_| RequestParserError::SyntaxError(0, s.to_string()))?,
|
||||
parts
|
||||
.next()
|
||||
.ok_or(RequestParserError::UnexpectedEOF)?
|
||||
.to_string(),
|
||||
);
|
||||
sort_or_window = parts.next();
|
||||
}
|
||||
@@ -71,7 +45,8 @@ impl Command for Find {
|
||||
|
||||
fn parse_response(
|
||||
parts: ResponseAttributes<'_>,
|
||||
) -> Result<Self::Response, ResponseParserError<'_>> {
|
||||
) -> Result<Self::Response, ResponseParserError> {
|
||||
// db_selection_print
|
||||
unimplemented!()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,57 +1,28 @@
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::{
|
||||
commands::{Command, Request, RequestParserError, RequestParserResult, ResponseParserError},
|
||||
common::{SongPosition, Sort, WindowRange},
|
||||
filter::Filter,
|
||||
request_tokenizer::RequestTokenizer,
|
||||
response_tokenizer::ResponseAttributes,
|
||||
commands::{
|
||||
Command, Request, RequestParserError, RequestParserResult, ResponseAttributes,
|
||||
ResponseParserError,
|
||||
},
|
||||
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: RequestTokenizer<'_>) -> RequestParserResult<'_> {
|
||||
let filter = match parts.next() {
|
||||
Some(f) => {
|
||||
Filter::parse(f).map_err(|_| RequestParserError::SyntaxError(1, f.to_owned()))?
|
||||
}
|
||||
None => return Err(RequestParserError::UnexpectedEOF),
|
||||
};
|
||||
fn parse_request(mut parts: std::str::SplitWhitespace<'_>) -> RequestParserResult<'_> {
|
||||
let filter = parse_filter(&mut parts)?;
|
||||
|
||||
let mut sort_or_window_or_position = parts.next();
|
||||
let mut sort = None;
|
||||
if let Some("sort") = sort_or_window_or_position {
|
||||
let s = parts.next().ok_or(RequestParserError::UnexpectedEOF)?;
|
||||
sort = Some(
|
||||
s.parse()
|
||||
.map_err(|_| RequestParserError::SyntaxError(0, s.to_string()))?,
|
||||
parts
|
||||
.next()
|
||||
.ok_or(RequestParserError::UnexpectedEOF)?
|
||||
.to_string(),
|
||||
);
|
||||
sort_or_window_or_position = parts.next();
|
||||
}
|
||||
@@ -82,7 +53,7 @@ impl Command for FindAdd {
|
||||
|
||||
fn parse_response(
|
||||
parts: ResponseAttributes<'_>,
|
||||
) -> Result<Self::Response, ResponseParserError<'_>> {
|
||||
) -> Result<Self::Response, ResponseParserError> {
|
||||
debug_assert!(parts.is_empty());
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -1,31 +1,21 @@
|
||||
use std::collections::HashMap;
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::{
|
||||
commands::{Command, Request, RequestParserError, RequestParserResult, ResponseParserError},
|
||||
common::Uri,
|
||||
request_tokenizer::RequestTokenizer,
|
||||
response_tokenizer::{ResponseAttributes, get_and_parse_property},
|
||||
use crate::commands::{
|
||||
get_and_parse_property, Command, Request, RequestParserError, RequestParserResult,
|
||||
ResponseAttributes, ResponseParserError,
|
||||
};
|
||||
|
||||
pub struct GetFingerprint;
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||
pub struct GetFingerprintResponse {
|
||||
pub chromaprint: String,
|
||||
}
|
||||
|
||||
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: RequestTokenizer<'_>) -> RequestParserResult<'_> {
|
||||
fn parse_request(mut parts: std::str::SplitWhitespace<'_>) -> RequestParserResult<'_> {
|
||||
let uri = parts.next().ok_or(RequestParserError::UnexpectedEOF)?;
|
||||
let uri = uri
|
||||
.parse()
|
||||
@@ -38,8 +28,8 @@ impl Command for GetFingerprint {
|
||||
|
||||
fn parse_response(
|
||||
parts: ResponseAttributes<'_>,
|
||||
) -> Result<Self::Response, ResponseParserError<'_>> {
|
||||
let parts: HashMap<_, _> = parts.into_map()?;
|
||||
) -> Result<Self::Response, ResponseParserError> {
|
||||
let parts: HashMap<_, _> = parts.into();
|
||||
|
||||
let chromaprint = get_and_parse_property!(parts, "chromaprint", Text);
|
||||
|
||||
|
||||
@@ -1,102 +1,54 @@
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::{
|
||||
commands::{Command, Request, RequestParserError, RequestParserResult, ResponseParserError},
|
||||
common::{GroupType, TagName, WindowRange},
|
||||
filter::Filter,
|
||||
request_tokenizer::RequestTokenizer,
|
||||
response_tokenizer::{ResponseAttributes, expect_property_type},
|
||||
commands::{
|
||||
expect_property_type, Command, Request, RequestParserError, RequestParserResult,
|
||||
ResponseAttributes, ResponseParserError,
|
||||
},
|
||||
filter::parse_filter,
|
||||
};
|
||||
|
||||
pub struct List;
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||
pub struct ListRequest {
|
||||
tagname: TagName,
|
||||
filter: Option<Filter>,
|
||||
groups: Vec<GroupType>,
|
||||
window: Option<WindowRange>,
|
||||
}
|
||||
|
||||
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 = match &request.filter {
|
||||
Some(f) => format!("{} {} {}", Self::COMMAND, request.tagname, f),
|
||||
None => format!("{} {}", Self::COMMAND, request.tagname),
|
||||
};
|
||||
for group in request.groups {
|
||||
cmd.push_str(&format!(" group {}", group));
|
||||
}
|
||||
if let Some(window) = request.window {
|
||||
cmd.push_str(&format!(" window {}", window));
|
||||
}
|
||||
cmd
|
||||
}
|
||||
|
||||
fn parse_request(mut parts: RequestTokenizer<'_>) -> RequestParserResult<'_> {
|
||||
let tagname = parts.next().ok_or(RequestParserError::UnexpectedEOF)?;
|
||||
let tagname = tagname
|
||||
fn parse_request(mut parts: std::str::SplitWhitespace<'_>) -> RequestParserResult<'_> {
|
||||
let tagtype = parts.next().ok_or(RequestParserError::UnexpectedEOF)?;
|
||||
let tagtype = tagtype
|
||||
.parse()
|
||||
.map_err(|_| RequestParserError::SyntaxError(1, tagname.to_owned()))?;
|
||||
.map_err(|_| RequestParserError::SyntaxError(1, tagtype.to_owned()))?;
|
||||
|
||||
let mut filter = None;
|
||||
let mut groups = Vec::new();
|
||||
let mut window = None;
|
||||
// TODO: This should be optional
|
||||
let filter = parse_filter(&mut parts)?;
|
||||
|
||||
let mut next = parts.next();
|
||||
|
||||
if let Some(f) = next
|
||||
&& f != "group"
|
||||
&& f != "window"
|
||||
{
|
||||
let parsed_filter =
|
||||
Filter::parse(f).map_err(|_| RequestParserError::SyntaxError(1, f.to_owned()))?;
|
||||
filter = Some(parsed_filter);
|
||||
next = parts.next();
|
||||
}
|
||||
|
||||
while let Some(g) = next
|
||||
&& g == "group"
|
||||
{
|
||||
let group = if let Some("group") = parts.next() {
|
||||
let group = parts.next().ok_or(RequestParserError::UnexpectedEOF)?;
|
||||
let parsed_group = group
|
||||
.parse()
|
||||
.map_err(|_| RequestParserError::SyntaxError(1, group.to_owned()))?;
|
||||
groups.push(parsed_group);
|
||||
next = parts.next();
|
||||
}
|
||||
|
||||
if let Some(w) = next
|
||||
&& w == "window"
|
||||
{
|
||||
let window_str = parts.next().ok_or(RequestParserError::UnexpectedEOF)?;
|
||||
let parsed_window = window_str
|
||||
.parse()
|
||||
.map_err(|_| RequestParserError::SyntaxError(1, window_str.to_owned()))?;
|
||||
window = Some(parsed_window);
|
||||
}
|
||||
Some(
|
||||
group
|
||||
.parse()
|
||||
.map_err(|_| RequestParserError::SyntaxError(1, group.to_owned()))?,
|
||||
)
|
||||
} else {
|
||||
None
|
||||
};
|
||||
|
||||
debug_assert!(parts.next().is_none());
|
||||
|
||||
Ok((Request::List(tagname, filter, groups, window), ""))
|
||||
Ok((Request::List(tagtype, filter, group), ""))
|
||||
}
|
||||
|
||||
fn parse_response(
|
||||
parts: ResponseAttributes<'_>,
|
||||
) -> Result<Self::Response, ResponseParserError<'_>> {
|
||||
let parts_: Vec<_> = parts.into_vec()?;
|
||||
) -> Result<Self::Response, ResponseParserError> {
|
||||
debug_assert!({
|
||||
let key = parts_.first().map(|(k, _)| k);
|
||||
parts_.iter().all(|(k, _)| k == key.unwrap())
|
||||
let key = parts.0.first().map(|(k, _)| k);
|
||||
parts.0.iter().all(|(k, _)| k == key.unwrap())
|
||||
});
|
||||
|
||||
let list = parts_
|
||||
let list = parts
|
||||
.0
|
||||
.into_iter()
|
||||
.map(|(k, v)| Ok(expect_property_type!(Some(v), k, Text).to_string()))
|
||||
.collect::<Result<Vec<_>, ResponseParserError>>()?;
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
use crate::{
|
||||
commands::{Command, Request, RequestParserError, RequestParserResult, ResponseParserError},
|
||||
common::Uri,
|
||||
request_tokenizer::RequestTokenizer,
|
||||
response_tokenizer::ResponseAttributes,
|
||||
use crate::commands::{
|
||||
Command, Request, RequestParserError, RequestParserResult, ResponseAttributes,
|
||||
ResponseParserError,
|
||||
};
|
||||
|
||||
pub struct ListAll;
|
||||
@@ -11,19 +9,10 @@ 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: RequestTokenizer<'_>) -> RequestParserResult<'_> {
|
||||
fn parse_request(mut parts: std::str::SplitWhitespace<'_>) -> RequestParserResult<'_> {
|
||||
let uri = parts
|
||||
.next()
|
||||
.map(|s| {
|
||||
@@ -39,7 +28,7 @@ impl Command for ListAll {
|
||||
|
||||
fn parse_response(
|
||||
parts: ResponseAttributes<'_>,
|
||||
) -> Result<Self::Response, ResponseParserError<'_>> {
|
||||
) -> Result<Self::Response, ResponseParserError> {
|
||||
unimplemented!()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,30 +1,18 @@
|
||||
use crate::{
|
||||
commands::{Command, Request, RequestParserError, RequestParserResult, ResponseParserError},
|
||||
common::Uri,
|
||||
request_tokenizer::RequestTokenizer,
|
||||
response_tokenizer::ResponseAttributes,
|
||||
use crate::commands::{
|
||||
Command, Request, RequestParserError, RequestParserResult, ResponseAttributes,
|
||||
ResponseParserError,
|
||||
};
|
||||
use crate::common::DbSelectionPrintResponse;
|
||||
|
||||
pub struct ListAllInfo;
|
||||
|
||||
// TODO: This is supposed to be a tree-like structure, with directories containing files and playlists
|
||||
// in addition to the metadata of each entry
|
||||
pub type ListAllInfoResponse = Vec<String>;
|
||||
pub type ListAllInfoResponse = Vec<DbSelectionPrintResponse>;
|
||||
|
||||
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: RequestTokenizer<'_>) -> RequestParserResult<'_> {
|
||||
fn parse_request(mut parts: std::str::SplitWhitespace<'_>) -> RequestParserResult<'_> {
|
||||
let uri = parts
|
||||
.next()
|
||||
.map(|s| {
|
||||
@@ -40,7 +28,7 @@ impl Command for ListAllInfo {
|
||||
|
||||
fn parse_response(
|
||||
parts: ResponseAttributes<'_>,
|
||||
) -> Result<Self::Response, ResponseParserError<'_>> {
|
||||
unimplemented!()
|
||||
) -> Result<Self::Response, ResponseParserError> {
|
||||
DbSelectionPrintResponse::parse(parts)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
use crate::{
|
||||
commands::{Command, Request, RequestParserError, RequestParserResult, ResponseParserError},
|
||||
common::Uri,
|
||||
request_tokenizer::RequestTokenizer,
|
||||
response_tokenizer::ResponseAttributes,
|
||||
use crate::commands::{
|
||||
Command, Request, RequestParserError, RequestParserResult, ResponseAttributes,
|
||||
ResponseParserError,
|
||||
};
|
||||
|
||||
pub struct ListFiles;
|
||||
@@ -11,19 +9,10 @@ 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: RequestTokenizer<'_>) -> RequestParserResult<'_> {
|
||||
fn parse_request(mut parts: std::str::SplitWhitespace<'_>) -> RequestParserResult<'_> {
|
||||
let uri = parts
|
||||
.next()
|
||||
.map(|s| {
|
||||
@@ -39,7 +28,8 @@ impl Command for ListFiles {
|
||||
|
||||
fn parse_response(
|
||||
parts: ResponseAttributes<'_>,
|
||||
) -> Result<Self::Response, ResponseParserError<'_>> {
|
||||
) -> Result<Self::Response, ResponseParserError> {
|
||||
// db_selection_print
|
||||
unimplemented!()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,35 +1,18 @@
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::{
|
||||
commands::{Command, Request, RequestParserError, RequestParserResult, ResponseParserError},
|
||||
common::Uri,
|
||||
request_tokenizer::RequestTokenizer,
|
||||
response_tokenizer::{ResponseAttributes, expect_property_type},
|
||||
use crate::commands::{
|
||||
Command, Request, RequestParserError, RequestParserResult, ResponseAttributes,
|
||||
ResponseParserError,
|
||||
};
|
||||
|
||||
pub struct LsInfo;
|
||||
|
||||
pub type LsInfoResponse = Vec<LsInfoResponseEntry>;
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||
pub struct LsInfoResponseEntry {
|
||||
playlist: String,
|
||||
last_modified: Option<String>,
|
||||
}
|
||||
// TODO: fix this type
|
||||
pub type LsInfoResponse = Vec<String>;
|
||||
|
||||
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: RequestTokenizer<'_>) -> RequestParserResult<'_> {
|
||||
fn parse_request(mut parts: std::str::SplitWhitespace<'_>) -> RequestParserResult<'_> {
|
||||
let uri = parts
|
||||
.next()
|
||||
.map(|s| {
|
||||
@@ -45,31 +28,8 @@ impl Command for LsInfo {
|
||||
|
||||
fn parse_response(
|
||||
parts: ResponseAttributes<'_>,
|
||||
) -> Result<Self::Response, ResponseParserError<'_>> {
|
||||
let parts: Vec<_> = parts.into_vec()?;
|
||||
let mut playlists = Vec::new();
|
||||
|
||||
for (key, value) in parts {
|
||||
match key {
|
||||
"playlist" => {
|
||||
playlists.push(LsInfoResponseEntry {
|
||||
playlist: expect_property_type!(Some(value), "playlist", Text).to_string(),
|
||||
last_modified: None,
|
||||
});
|
||||
}
|
||||
"Last-Modified" => {
|
||||
if let Some(last) = playlists.last_mut() {
|
||||
last.last_modified = Some(
|
||||
expect_property_type!(Some(value), "Last-Modified", Text).to_string(),
|
||||
);
|
||||
} else {
|
||||
return Err(ResponseParserError::UnexpectedProperty("Last-Modified"));
|
||||
}
|
||||
}
|
||||
_ => return Err(ResponseParserError::UnexpectedProperty(key)),
|
||||
}
|
||||
}
|
||||
|
||||
Ok(playlists)
|
||||
) -> Result<Self::Response, ResponseParserError> {
|
||||
// db_selection_print
|
||||
unimplemented!()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,10 +1,8 @@
|
||||
use std::collections::HashMap;
|
||||
|
||||
use crate::{
|
||||
commands::{Command, Request, RequestParserError, RequestParserResult, ResponseParserError},
|
||||
common::Uri,
|
||||
request_tokenizer::RequestTokenizer,
|
||||
response_tokenizer::{GenericResponseValue, ResponseAttributes},
|
||||
use crate::commands::{
|
||||
Command, GenericResponseValue, Request, RequestParserError, RequestParserResult,
|
||||
ResponseAttributes, ResponseParserError,
|
||||
};
|
||||
|
||||
pub struct ReadComments;
|
||||
@@ -12,15 +10,10 @@ 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: RequestTokenizer<'_>) -> RequestParserResult<'_> {
|
||||
fn parse_request(mut parts: std::str::SplitWhitespace<'_>) -> RequestParserResult<'_> {
|
||||
let uri = parts.next().ok_or(RequestParserError::UnexpectedEOF)?;
|
||||
let uri = uri
|
||||
.parse()
|
||||
@@ -33,8 +26,8 @@ impl Command for ReadComments {
|
||||
|
||||
fn parse_response(
|
||||
parts: ResponseAttributes<'_>,
|
||||
) -> Result<Self::Response, ResponseParserError<'_>> {
|
||||
let parts: HashMap<_, _> = parts.into_map()?;
|
||||
) -> Result<Self::Response, ResponseParserError> {
|
||||
let parts: HashMap<_, _> = parts.into();
|
||||
|
||||
let comments = parts
|
||||
.iter()
|
||||
|
||||
@@ -1,25 +1,15 @@
|
||||
use std::collections::HashMap;
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::{
|
||||
commands::{Command, Request, RequestParserError, RequestParserResult, ResponseParserError},
|
||||
common::{Offset, Uri},
|
||||
request_tokenizer::RequestTokenizer,
|
||||
response_tokenizer::{
|
||||
ResponseAttributes, get_and_parse_property, get_optional_property, get_property,
|
||||
commands::{
|
||||
get_and_parse_property, get_optional_property, get_property, Command, Request,
|
||||
RequestParserError, RequestParserResult, ResponseAttributes, ResponseParserError,
|
||||
},
|
||||
common::Offset,
|
||||
};
|
||||
|
||||
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,
|
||||
pub binary: Vec<u8>,
|
||||
@@ -27,15 +17,10 @@ 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: RequestTokenizer<'_>) -> RequestParserResult<'_> {
|
||||
fn parse_request(mut parts: std::str::SplitWhitespace<'_>) -> RequestParserResult<'_> {
|
||||
let uri = match parts.next() {
|
||||
Some(s) => s,
|
||||
None => return Err(RequestParserError::UnexpectedEOF),
|
||||
@@ -55,8 +40,8 @@ impl Command for ReadPicture {
|
||||
|
||||
fn parse_response(
|
||||
parts: ResponseAttributes<'_>,
|
||||
) -> Result<Self::Response, ResponseParserError<'_>> {
|
||||
let parts: HashMap<_, _> = parts.into_map()?;
|
||||
) -> Result<Self::Response, ResponseParserError> {
|
||||
let parts: HashMap<_, _> = parts.into();
|
||||
|
||||
if parts.is_empty() {
|
||||
return Ok(None);
|
||||
|
||||
@@ -1,34 +1,21 @@
|
||||
use std::collections::HashMap;
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::{
|
||||
commands::{Command, Request, RequestParserResult, ResponseParserError},
|
||||
common::Uri,
|
||||
request_tokenizer::RequestTokenizer,
|
||||
response_tokenizer::{ResponseAttributes, get_and_parse_property},
|
||||
use crate::commands::{
|
||||
get_and_parse_property, Command, Request, RequestParserResult, ResponseAttributes,
|
||||
ResponseParserError,
|
||||
};
|
||||
|
||||
pub struct Rescan;
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||
pub struct RescanResponse {
|
||||
pub updating_db: usize,
|
||||
}
|
||||
|
||||
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: RequestTokenizer<'_>) -> RequestParserResult<'_> {
|
||||
fn parse_request(mut parts: std::str::SplitWhitespace<'_>) -> RequestParserResult<'_> {
|
||||
let uri = parts.next().map(|s| s.to_string());
|
||||
|
||||
debug_assert!(parts.next().is_none());
|
||||
@@ -38,8 +25,8 @@ impl Command for Rescan {
|
||||
|
||||
fn parse_response(
|
||||
parts: ResponseAttributes<'_>,
|
||||
) -> Result<Self::Response, ResponseParserError<'_>> {
|
||||
let parts: HashMap<_, _> = parts.into_map()?;
|
||||
) -> Result<Self::Response, ResponseParserError> {
|
||||
let parts: HashMap<_, _> = parts.into();
|
||||
|
||||
let updating_db = get_and_parse_property!(parts, "updating_db", Text);
|
||||
|
||||
|
||||
@@ -1,56 +1,30 @@
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::{
|
||||
commands::{Command, Request, RequestParserError, RequestParserResult, ResponseParserError},
|
||||
common::{Sort, WindowRange},
|
||||
filter::Filter,
|
||||
request_tokenizer::RequestTokenizer,
|
||||
response_tokenizer::ResponseAttributes,
|
||||
commands::{
|
||||
Command, Request, RequestParserError, RequestParserResult, ResponseAttributes,
|
||||
ResponseParserError,
|
||||
},
|
||||
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: RequestTokenizer<'_>) -> RequestParserResult<'_> {
|
||||
let filter = match parts.next() {
|
||||
Some(f) => {
|
||||
Filter::parse(f).map_err(|_| RequestParserError::SyntaxError(1, f.to_owned()))?
|
||||
}
|
||||
None => return Err(RequestParserError::UnexpectedEOF),
|
||||
};
|
||||
fn parse_request(mut parts: std::str::SplitWhitespace<'_>) -> RequestParserResult<'_> {
|
||||
let filter = parse_filter(&mut parts)?;
|
||||
|
||||
let mut sort_or_window = parts.next();
|
||||
let mut sort = None;
|
||||
if let Some("sort") = sort_or_window {
|
||||
let s = parts.next().ok_or(RequestParserError::UnexpectedEOF)?;
|
||||
sort = Some(
|
||||
s.parse()
|
||||
.map_err(|_| RequestParserError::SyntaxError(0, s.to_string()))?,
|
||||
parts
|
||||
.next()
|
||||
.ok_or(RequestParserError::UnexpectedEOF)?
|
||||
.to_string(),
|
||||
);
|
||||
sort_or_window = parts.next();
|
||||
}
|
||||
@@ -71,7 +45,8 @@ impl Command for Search {
|
||||
|
||||
fn parse_response(
|
||||
parts: ResponseAttributes<'_>,
|
||||
) -> Result<Self::Response, ResponseParserError<'_>> {
|
||||
) -> Result<Self::Response, ResponseParserError> {
|
||||
// db_selection_print
|
||||
unimplemented!()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,59 +1,28 @@
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::{
|
||||
commands::{
|
||||
Command, Request, RequestParserError, RequestParserResult, ResponseAttributes,
|
||||
ResponseParserError,
|
||||
},
|
||||
common::{SongPosition, Sort, WindowRange},
|
||||
filter::Filter,
|
||||
request_tokenizer::RequestTokenizer,
|
||||
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: RequestTokenizer<'_>) -> RequestParserResult<'_> {
|
||||
let filter = match parts.next() {
|
||||
Some(f) => {
|
||||
Filter::parse(f).map_err(|_| RequestParserError::SyntaxError(1, f.to_owned()))?
|
||||
}
|
||||
None => return Err(RequestParserError::UnexpectedEOF),
|
||||
};
|
||||
fn parse_request(mut parts: std::str::SplitWhitespace<'_>) -> RequestParserResult<'_> {
|
||||
let filter = parse_filter(&mut parts)?;
|
||||
|
||||
let mut sort_or_window_or_position = parts.next();
|
||||
let mut sort = None;
|
||||
if let Some("sort") = sort_or_window_or_position {
|
||||
let s = parts.next().ok_or(RequestParserError::UnexpectedEOF)?;
|
||||
sort = Some(
|
||||
s.parse()
|
||||
.map_err(|_| RequestParserError::SyntaxError(0, s.to_string()))?,
|
||||
parts
|
||||
.next()
|
||||
.ok_or(RequestParserError::UnexpectedEOF)?
|
||||
.to_string(),
|
||||
);
|
||||
sort_or_window_or_position = parts.next();
|
||||
}
|
||||
@@ -84,7 +53,7 @@ impl Command for SearchAdd {
|
||||
|
||||
fn parse_response(
|
||||
parts: ResponseAttributes<'_>,
|
||||
) -> Result<Self::Response, ResponseParserError<'_>> {
|
||||
) -> Result<Self::Response, ResponseParserError> {
|
||||
debug_assert!(parts.is_empty());
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -1,70 +1,33 @@
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::{
|
||||
commands::{
|
||||
Command, Request, RequestParserError, RequestParserResult, ResponseAttributes,
|
||||
ResponseParserError,
|
||||
},
|
||||
common::{PlaylistName, SongPosition, Sort, WindowRange},
|
||||
filter::Filter,
|
||||
request_tokenizer::RequestTokenizer,
|
||||
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: RequestTokenizer<'_>) -> RequestParserResult<'_> {
|
||||
fn parse_request(mut parts: std::str::SplitWhitespace<'_>) -> RequestParserResult<'_> {
|
||||
let playlist_name = parts
|
||||
.next()
|
||||
.ok_or(RequestParserError::UnexpectedEOF)?
|
||||
.to_string();
|
||||
|
||||
let filter = match parts.next() {
|
||||
Some(f) => {
|
||||
Filter::parse(f).map_err(|_| RequestParserError::SyntaxError(1, f.to_owned()))?
|
||||
}
|
||||
None => return Err(RequestParserError::UnexpectedEOF),
|
||||
};
|
||||
let filter = parse_filter(&mut parts)?;
|
||||
|
||||
let mut sort_or_window_or_position = parts.next();
|
||||
let mut sort = None;
|
||||
if let Some("sort") = sort_or_window_or_position {
|
||||
let s = parts.next().ok_or(RequestParserError::UnexpectedEOF)?;
|
||||
sort = Some(
|
||||
s.parse()
|
||||
.map_err(|_| RequestParserError::SyntaxError(0, s.to_string()))?,
|
||||
parts
|
||||
.next()
|
||||
.ok_or(RequestParserError::UnexpectedEOF)?
|
||||
.to_string(),
|
||||
);
|
||||
sort_or_window_or_position = parts.next();
|
||||
}
|
||||
@@ -98,7 +61,7 @@ impl Command for SearchAddPl {
|
||||
|
||||
fn parse_response(
|
||||
parts: ResponseAttributes<'_>,
|
||||
) -> Result<Self::Response, ResponseParserError<'_>> {
|
||||
) -> Result<Self::Response, ResponseParserError> {
|
||||
debug_assert!(parts.is_empty());
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -1,49 +1,26 @@
|
||||
use std::collections::HashMap;
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::{
|
||||
commands::{Command, Request, RequestParserError, RequestParserResult, ResponseParserError},
|
||||
common::GroupType,
|
||||
filter::Filter,
|
||||
request_tokenizer::RequestTokenizer,
|
||||
response_tokenizer::{ResponseAttributes, get_and_parse_property},
|
||||
commands::{
|
||||
get_and_parse_property, Command, Request, RequestParserError, RequestParserResult,
|
||||
ResponseAttributes, ResponseParserError,
|
||||
},
|
||||
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,
|
||||
pub playtime: u64,
|
||||
}
|
||||
|
||||
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: RequestTokenizer<'_>) -> RequestParserResult<'_> {
|
||||
let filter = match parts.next() {
|
||||
Some(f) => {
|
||||
Filter::parse(f).map_err(|_| RequestParserError::SyntaxError(1, f.to_owned()))?
|
||||
}
|
||||
None => return Err(RequestParserError::UnexpectedEOF),
|
||||
};
|
||||
fn parse_request(mut parts: std::str::SplitWhitespace<'_>) -> RequestParserResult<'_> {
|
||||
let filter = parse_filter(&mut parts)?;
|
||||
|
||||
let group = if let Some("group") = parts.next() {
|
||||
let group = parts.next().ok_or(RequestParserError::UnexpectedEOF)?;
|
||||
@@ -63,8 +40,8 @@ impl Command for SearchCount {
|
||||
|
||||
fn parse_response(
|
||||
parts: ResponseAttributes<'_>,
|
||||
) -> Result<Self::Response, ResponseParserError<'_>> {
|
||||
let parts: HashMap<_, _> = parts.into_map()?;
|
||||
) -> Result<Self::Response, ResponseParserError> {
|
||||
let parts: HashMap<_, _> = parts.into();
|
||||
|
||||
let songs = get_and_parse_property!(parts, "songs", Text);
|
||||
let playtime = get_and_parse_property!(parts, "playtime", Text);
|
||||
|
||||
@@ -1,34 +1,21 @@
|
||||
use std::collections::HashMap;
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::{
|
||||
commands::{Command, Request, RequestParserResult, ResponseParserError},
|
||||
common::Uri,
|
||||
request_tokenizer::RequestTokenizer,
|
||||
response_tokenizer::{ResponseAttributes, get_and_parse_property},
|
||||
use crate::commands::{
|
||||
get_and_parse_property, Command, Request, RequestParserResult, ResponseAttributes,
|
||||
ResponseParserError,
|
||||
};
|
||||
|
||||
pub struct Update;
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||
pub struct UpdateResponse {
|
||||
updating_db: usize,
|
||||
}
|
||||
|
||||
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: RequestTokenizer<'_>) -> RequestParserResult<'_> {
|
||||
fn parse_request(mut parts: std::str::SplitWhitespace<'_>) -> RequestParserResult<'_> {
|
||||
let uri = parts.next().map(|s| s.to_string());
|
||||
|
||||
debug_assert!(parts.next().is_none());
|
||||
@@ -38,8 +25,8 @@ impl Command for Update {
|
||||
|
||||
fn parse_response(
|
||||
parts: ResponseAttributes<'_>,
|
||||
) -> Result<Self::Response, ResponseParserError<'_>> {
|
||||
let parts: HashMap<_, _> = parts.into_map()?;
|
||||
) -> Result<Self::Response, ResponseParserError> {
|
||||
let parts: HashMap<_, _> = parts.into();
|
||||
|
||||
let updating_db = get_and_parse_property!(parts, "updating_db", Text);
|
||||
|
||||
|
||||
@@ -1,22 +1,15 @@
|
||||
use crate::{
|
||||
commands::{Command, Request, RequestParserError, RequestParserResult, ResponseParserError},
|
||||
common::PartitionName,
|
||||
request_tokenizer::RequestTokenizer,
|
||||
response_tokenizer::ResponseAttributes,
|
||||
use crate::commands::{
|
||||
Command, Request, RequestParserError, RequestParserResult, ResponseAttributes,
|
||||
ResponseParserError,
|
||||
};
|
||||
|
||||
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: RequestTokenizer<'_>) -> RequestParserResult<'_> {
|
||||
fn parse_request(mut parts: std::str::SplitWhitespace<'_>) -> RequestParserResult<'_> {
|
||||
let partition = parts
|
||||
.next()
|
||||
.ok_or(RequestParserError::UnexpectedEOF)?
|
||||
@@ -29,7 +22,7 @@ impl Command for DelPartition {
|
||||
|
||||
fn parse_response(
|
||||
parts: ResponseAttributes<'_>,
|
||||
) -> Result<Self::Response, ResponseParserError<'_>> {
|
||||
) -> Result<Self::Response, ResponseParserError> {
|
||||
debug_assert!(parts.is_empty());
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -1,38 +1,29 @@
|
||||
use crate::{
|
||||
commands::{Command, Request, RequestParserResult, ResponseParserError},
|
||||
common::PartitionName,
|
||||
request_tokenizer::RequestTokenizer,
|
||||
response_tokenizer::{ResponseAttributes, expect_property_type},
|
||||
use crate::commands::{
|
||||
expect_property_type, Command, Request, RequestParserResult, ResponseAttributes,
|
||||
ResponseParserError,
|
||||
};
|
||||
|
||||
pub struct ListPartitions;
|
||||
|
||||
pub type ListPartitionsResponse = Vec<PartitionName>;
|
||||
pub type ListPartitionsResponse = Vec<String>;
|
||||
|
||||
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: RequestTokenizer<'_>) -> RequestParserResult<'_> {
|
||||
fn parse_request(mut parts: std::str::SplitWhitespace<'_>) -> RequestParserResult<'_> {
|
||||
debug_assert!(parts.next().is_none());
|
||||
Ok((Request::ListPartitions, ""))
|
||||
}
|
||||
|
||||
fn parse_response(
|
||||
parts: ResponseAttributes<'_>,
|
||||
) -> Result<Self::Response, ResponseParserError<'_>> {
|
||||
let parts: Vec<_> = parts.into_vec()?;
|
||||
) -> Result<Self::Response, ResponseParserError> {
|
||||
let parts: Vec<_> = parts.into();
|
||||
|
||||
let mut partitions = Vec::with_capacity(parts.len());
|
||||
for (key, value) in parts.into_iter() {
|
||||
if key != "partition" {
|
||||
return Err(ResponseParserError::UnexpectedProperty(key));
|
||||
}
|
||||
debug_assert_eq!(key, "partition");
|
||||
let partition = expect_property_type!(Some(value), "partition", Text).to_string();
|
||||
partitions.push(partition);
|
||||
}
|
||||
|
||||
@@ -1,21 +1,15 @@
|
||||
use crate::{
|
||||
commands::{Command, Request, RequestParserError, RequestParserResult, ResponseParserError},
|
||||
request_tokenizer::RequestTokenizer,
|
||||
response_tokenizer::ResponseAttributes,
|
||||
use crate::commands::{
|
||||
Command, Request, RequestParserError, RequestParserResult, ResponseAttributes,
|
||||
ResponseParserError,
|
||||
};
|
||||
|
||||
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: RequestTokenizer<'_>) -> RequestParserResult<'_> {
|
||||
fn parse_request(mut parts: std::str::SplitWhitespace<'_>) -> RequestParserResult<'_> {
|
||||
let output_name = parts
|
||||
.next()
|
||||
.ok_or(RequestParserError::UnexpectedEOF)?
|
||||
@@ -28,7 +22,7 @@ impl Command for MoveOutput {
|
||||
|
||||
fn parse_response(
|
||||
parts: ResponseAttributes<'_>,
|
||||
) -> Result<Self::Response, ResponseParserError<'_>> {
|
||||
) -> Result<Self::Response, ResponseParserError> {
|
||||
debug_assert!(parts.is_empty());
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -1,22 +1,15 @@
|
||||
use crate::{
|
||||
commands::{Command, Request, RequestParserError, RequestParserResult, ResponseParserError},
|
||||
common::PartitionName,
|
||||
request_tokenizer::RequestTokenizer,
|
||||
response_tokenizer::ResponseAttributes,
|
||||
use crate::commands::{
|
||||
Command, Request, RequestParserError, RequestParserResult, ResponseAttributes,
|
||||
ResponseParserError,
|
||||
};
|
||||
|
||||
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: RequestTokenizer<'_>) -> RequestParserResult<'_> {
|
||||
fn parse_request(mut parts: std::str::SplitWhitespace<'_>) -> RequestParserResult<'_> {
|
||||
let partition = parts
|
||||
.next()
|
||||
.ok_or(RequestParserError::UnexpectedEOF)?
|
||||
@@ -29,7 +22,7 @@ impl Command for NewPartition {
|
||||
|
||||
fn parse_response(
|
||||
parts: ResponseAttributes<'_>,
|
||||
) -> Result<Self::Response, ResponseParserError<'_>> {
|
||||
) -> Result<Self::Response, ResponseParserError> {
|
||||
debug_assert!(parts.is_empty());
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -1,22 +1,15 @@
|
||||
use crate::{
|
||||
commands::{Command, Request, RequestParserError, RequestParserResult, ResponseParserError},
|
||||
common::PartitionName,
|
||||
request_tokenizer::RequestTokenizer,
|
||||
response_tokenizer::ResponseAttributes,
|
||||
use crate::commands::{
|
||||
Command, Request, RequestParserError, RequestParserResult, ResponseAttributes,
|
||||
ResponseParserError,
|
||||
};
|
||||
|
||||
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: RequestTokenizer<'_>) -> RequestParserResult<'_> {
|
||||
fn parse_request(mut parts: std::str::SplitWhitespace<'_>) -> RequestParserResult<'_> {
|
||||
let partition = parts
|
||||
.next()
|
||||
.ok_or(RequestParserError::UnexpectedEOF)?
|
||||
@@ -29,7 +22,7 @@ impl Command for Partition {
|
||||
|
||||
fn parse_response(
|
||||
parts: ResponseAttributes<'_>,
|
||||
) -> Result<Self::Response, ResponseParserError<'_>> {
|
||||
) -> Result<Self::Response, ResponseParserError> {
|
||||
debug_assert!(parts.is_empty());
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -1,24 +1,17 @@
|
||||
use std::str::FromStr;
|
||||
|
||||
use crate::{
|
||||
commands::{Command, Request, RequestParserError, RequestParserResult, ResponseParserError},
|
||||
common::BoolOrOneshot,
|
||||
request_tokenizer::RequestTokenizer,
|
||||
response_tokenizer::ResponseAttributes,
|
||||
use crate::commands::{
|
||||
Command, Request, RequestParserError, RequestParserResult, ResponseAttributes,
|
||||
ResponseParserError,
|
||||
};
|
||||
|
||||
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: RequestTokenizer<'_>) -> RequestParserResult<'_> {
|
||||
fn parse_request(mut parts: std::str::SplitWhitespace<'_>) -> RequestParserResult<'_> {
|
||||
let state = match parts.next() {
|
||||
Some(s) => crate::common::BoolOrOneshot::from_str(s)
|
||||
.map_err(|_| RequestParserError::SyntaxError(0, s.to_owned()))?,
|
||||
@@ -32,7 +25,7 @@ impl Command for Consume {
|
||||
|
||||
fn parse_response(
|
||||
parts: ResponseAttributes<'_>,
|
||||
) -> Result<Self::Response, ResponseParserError<'_>> {
|
||||
) -> Result<Self::Response, ResponseParserError> {
|
||||
debug_assert!(parts.is_empty());
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -1,22 +1,18 @@
|
||||
use crate::{
|
||||
commands::{Command, Request, RequestParserError, RequestParserResult, ResponseParserError},
|
||||
commands::{
|
||||
Command, Request, RequestParserError, RequestParserResult, ResponseAttributes,
|
||||
ResponseParserError,
|
||||
},
|
||||
common::Seconds,
|
||||
request_tokenizer::RequestTokenizer,
|
||||
response_tokenizer::ResponseAttributes,
|
||||
};
|
||||
|
||||
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: RequestTokenizer<'_>) -> RequestParserResult<'_> {
|
||||
fn parse_request(mut parts: std::str::SplitWhitespace<'_>) -> RequestParserResult<'_> {
|
||||
let seconds = match parts.next() {
|
||||
Some(s) => s
|
||||
.parse::<Seconds>()
|
||||
@@ -31,7 +27,7 @@ impl Command for Crossfade {
|
||||
|
||||
fn parse_response(
|
||||
parts: ResponseAttributes<'_>,
|
||||
) -> Result<Self::Response, ResponseParserError<'_>> {
|
||||
) -> Result<Self::Response, ResponseParserError> {
|
||||
debug_assert!(parts.is_empty());
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -1,32 +1,28 @@
|
||||
use std::collections::HashMap;
|
||||
|
||||
use crate::{
|
||||
commands::{Command, Request, RequestParserResult, ResponseParserError},
|
||||
commands::{
|
||||
get_and_parse_property, Command, Request, RequestParserResult, ResponseAttributes,
|
||||
ResponseParserError,
|
||||
},
|
||||
common::VolumeValue,
|
||||
request_tokenizer::RequestTokenizer,
|
||||
response_tokenizer::{ResponseAttributes, get_and_parse_property},
|
||||
};
|
||||
|
||||
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: RequestTokenizer<'_>) -> RequestParserResult<'_> {
|
||||
fn parse_request(mut parts: std::str::SplitWhitespace<'_>) -> RequestParserResult<'_> {
|
||||
debug_assert!(parts.next().is_none());
|
||||
Ok((Request::GetVol, ""))
|
||||
}
|
||||
|
||||
fn parse_response(
|
||||
parts: ResponseAttributes<'_>,
|
||||
) -> Result<Self::Response, ResponseParserError<'_>> {
|
||||
let parts: HashMap<_, _> = parts.into_map()?;
|
||||
) -> Result<Self::Response, ResponseParserError> {
|
||||
let parts: HashMap<_, _> = parts.into();
|
||||
assert_eq!(parts.len(), 1);
|
||||
let volume = get_and_parse_property!(parts, "volume", Text);
|
||||
Ok(volume)
|
||||
|
||||
@@ -1,21 +1,15 @@
|
||||
use crate::{
|
||||
commands::{Command, Request, RequestParserError, RequestParserResult, ResponseParserError},
|
||||
request_tokenizer::RequestTokenizer,
|
||||
response_tokenizer::ResponseAttributes,
|
||||
use crate::commands::{
|
||||
Command, Request, RequestParserError, RequestParserResult, ResponseAttributes,
|
||||
ResponseParserError,
|
||||
};
|
||||
|
||||
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: RequestTokenizer<'_>) -> RequestParserResult<'_> {
|
||||
fn parse_request(mut parts: std::str::SplitWhitespace<'_>) -> RequestParserResult<'_> {
|
||||
let db = match parts.next() {
|
||||
Some(s) => s
|
||||
.parse::<f32>()
|
||||
@@ -30,7 +24,7 @@ impl Command for MixRampDb {
|
||||
|
||||
fn parse_response(
|
||||
parts: ResponseAttributes<'_>,
|
||||
) -> Result<Self::Response, ResponseParserError<'_>> {
|
||||
) -> Result<Self::Response, ResponseParserError> {
|
||||
debug_assert!(parts.is_empty());
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -1,22 +1,18 @@
|
||||
use crate::{
|
||||
commands::{Command, Request, RequestParserError, RequestParserResult, ResponseParserError},
|
||||
commands::{
|
||||
Command, Request, RequestParserError, RequestParserResult, ResponseAttributes,
|
||||
ResponseParserError,
|
||||
},
|
||||
common::Seconds,
|
||||
request_tokenizer::RequestTokenizer,
|
||||
response_tokenizer::ResponseAttributes,
|
||||
};
|
||||
|
||||
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: RequestTokenizer<'_>) -> RequestParserResult<'_> {
|
||||
fn parse_request(mut parts: std::str::SplitWhitespace<'_>) -> RequestParserResult<'_> {
|
||||
let seconds = match parts.next() {
|
||||
Some(s) => s
|
||||
.parse::<Seconds>()
|
||||
@@ -31,7 +27,7 @@ impl Command for MixRampDelay {
|
||||
|
||||
fn parse_response(
|
||||
parts: ResponseAttributes<'_>,
|
||||
) -> Result<Self::Response, ResponseParserError<'_>> {
|
||||
) -> Result<Self::Response, ResponseParserError> {
|
||||
debug_assert!(parts.is_empty());
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -1,22 +1,15 @@
|
||||
use crate::{
|
||||
commands::{Command, Request, RequestParserError, RequestParserResult, ResponseParserError},
|
||||
request_tokenizer::RequestTokenizer,
|
||||
response_tokenizer::ResponseAttributes,
|
||||
use crate::commands::{
|
||||
Command, Request, RequestParserError, RequestParserResult, ResponseAttributes,
|
||||
ResponseParserError,
|
||||
};
|
||||
|
||||
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: RequestTokenizer<'_>) -> RequestParserResult<'_> {
|
||||
fn parse_request(mut parts: std::str::SplitWhitespace<'_>) -> RequestParserResult<'_> {
|
||||
let state = match parts.next() {
|
||||
Some("0") => false,
|
||||
Some("1") => true,
|
||||
@@ -31,7 +24,7 @@ impl Command for Random {
|
||||
|
||||
fn parse_response(
|
||||
parts: ResponseAttributes<'_>,
|
||||
) -> Result<Self::Response, ResponseParserError<'_>> {
|
||||
) -> Result<Self::Response, ResponseParserError> {
|
||||
debug_assert!(parts.is_empty());
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -1,22 +1,15 @@
|
||||
use crate::{
|
||||
commands::{Command, Request, RequestParserError, RequestParserResult, ResponseParserError},
|
||||
request_tokenizer::RequestTokenizer,
|
||||
response_tokenizer::ResponseAttributes,
|
||||
use crate::commands::{
|
||||
Command, Request, RequestParserError, RequestParserResult, ResponseAttributes,
|
||||
ResponseParserError,
|
||||
};
|
||||
|
||||
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: RequestTokenizer<'_>) -> RequestParserResult<'_> {
|
||||
fn parse_request(mut parts: std::str::SplitWhitespace<'_>) -> RequestParserResult<'_> {
|
||||
let state = match parts.next() {
|
||||
Some("0") => false,
|
||||
Some("1") => true,
|
||||
@@ -31,7 +24,7 @@ impl Command for Repeat {
|
||||
|
||||
fn parse_response(
|
||||
parts: ResponseAttributes<'_>,
|
||||
) -> Result<Self::Response, ResponseParserError<'_>> {
|
||||
) -> Result<Self::Response, ResponseParserError> {
|
||||
debug_assert!(parts.is_empty());
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -1,24 +1,20 @@
|
||||
use std::str::FromStr;
|
||||
|
||||
use crate::{
|
||||
commands::{Command, Request, RequestParserError, RequestParserResult, ResponseParserError},
|
||||
commands::{
|
||||
Command, Request, RequestParserError, RequestParserResult, ResponseAttributes,
|
||||
ResponseParserError,
|
||||
},
|
||||
common::ReplayGainModeMode,
|
||||
request_tokenizer::RequestTokenizer,
|
||||
response_tokenizer::ResponseAttributes,
|
||||
};
|
||||
|
||||
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: RequestTokenizer<'_>) -> RequestParserResult<'_> {
|
||||
fn parse_request(mut parts: std::str::SplitWhitespace<'_>) -> RequestParserResult<'_> {
|
||||
let mode = match parts.next() {
|
||||
Some(s) => ReplayGainModeMode::from_str(s)
|
||||
.map_err(|_| RequestParserError::SyntaxError(0, s.to_owned()))?,
|
||||
@@ -32,7 +28,7 @@ impl Command for ReplayGainMode {
|
||||
|
||||
fn parse_response(
|
||||
parts: ResponseAttributes<'_>,
|
||||
) -> Result<Self::Response, ResponseParserError<'_>> {
|
||||
) -> Result<Self::Response, ResponseParserError> {
|
||||
debug_assert!(parts.is_empty());
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -3,10 +3,11 @@ use std::{collections::HashMap, str::FromStr};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::{
|
||||
commands::{Command, Request, RequestParserResult, ResponseParserError},
|
||||
commands::{
|
||||
get_property, Command, Request, RequestParserResult, ResponseAttributes,
|
||||
ResponseParserError,
|
||||
},
|
||||
common::ReplayGainModeMode,
|
||||
request_tokenizer::RequestTokenizer,
|
||||
response_tokenizer::{ResponseAttributes, get_property},
|
||||
};
|
||||
|
||||
pub struct ReplayGainStatus;
|
||||
@@ -17,23 +18,18 @@ 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: RequestTokenizer<'_>) -> RequestParserResult<'_> {
|
||||
fn parse_request(mut parts: std::str::SplitWhitespace<'_>) -> RequestParserResult<'_> {
|
||||
debug_assert!(parts.next().is_none());
|
||||
Ok((Request::ReplayGainStatus, ""))
|
||||
}
|
||||
|
||||
fn parse_response(
|
||||
parts: ResponseAttributes<'_>,
|
||||
) -> Result<Self::Response, ResponseParserError<'_>> {
|
||||
let parts: HashMap<_, _> = parts.into_map()?;
|
||||
) -> Result<Self::Response, ResponseParserError> {
|
||||
let parts: HashMap<_, _> = parts.into();
|
||||
let replay_gain_mode = get_property!(parts, "replay_gain_mode", Text);
|
||||
|
||||
Ok(ReplayGainStatusResponse {
|
||||
|
||||
@@ -1,24 +1,20 @@
|
||||
use std::str::FromStr;
|
||||
|
||||
use crate::{
|
||||
commands::{Command, Request, RequestParserError, RequestParserResult, ResponseParserError},
|
||||
commands::{
|
||||
Command, Request, RequestParserError, RequestParserResult, ResponseAttributes,
|
||||
ResponseParserError,
|
||||
},
|
||||
common::VolumeValue,
|
||||
request_tokenizer::RequestTokenizer,
|
||||
response_tokenizer::ResponseAttributes,
|
||||
};
|
||||
|
||||
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: RequestTokenizer<'_>) -> RequestParserResult<'_> {
|
||||
fn parse_request(mut parts: std::str::SplitWhitespace<'_>) -> RequestParserResult<'_> {
|
||||
let volume = match parts.next() {
|
||||
Some(s) => VolumeValue::from_str(s)
|
||||
.map_err(|_| RequestParserError::SyntaxError(0, s.to_owned()))?,
|
||||
@@ -32,7 +28,7 @@ impl Command for SetVol {
|
||||
|
||||
fn parse_response(
|
||||
parts: ResponseAttributes<'_>,
|
||||
) -> Result<Self::Response, ResponseParserError<'_>> {
|
||||
) -> Result<Self::Response, ResponseParserError> {
|
||||
debug_assert!(parts.is_empty());
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -1,24 +1,17 @@
|
||||
use std::str::FromStr;
|
||||
|
||||
use crate::{
|
||||
commands::{Command, Request, RequestParserError, RequestParserResult, ResponseParserError},
|
||||
common::BoolOrOneshot,
|
||||
request_tokenizer::RequestTokenizer,
|
||||
response_tokenizer::ResponseAttributes,
|
||||
use crate::commands::{
|
||||
Command, Request, RequestParserError, RequestParserResult, ResponseAttributes,
|
||||
ResponseParserError,
|
||||
};
|
||||
|
||||
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: RequestTokenizer<'_>) -> RequestParserResult<'_> {
|
||||
fn parse_request(mut parts: std::str::SplitWhitespace<'_>) -> RequestParserResult<'_> {
|
||||
let state = match parts.next() {
|
||||
Some(s) => crate::common::BoolOrOneshot::from_str(s)
|
||||
.map_err(|_| RequestParserError::SyntaxError(0, s.to_owned()))?,
|
||||
@@ -32,7 +25,7 @@ impl Command for Single {
|
||||
|
||||
fn parse_response(
|
||||
parts: ResponseAttributes<'_>,
|
||||
) -> Result<Self::Response, ResponseParserError<'_>> {
|
||||
) -> Result<Self::Response, ResponseParserError> {
|
||||
debug_assert!(parts.is_empty());
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -1,24 +1,20 @@
|
||||
use std::str::FromStr;
|
||||
|
||||
use crate::{
|
||||
commands::{Command, Request, RequestParserError, RequestParserResult, ResponseParserError},
|
||||
commands::{
|
||||
Command, Request, RequestParserError, RequestParserResult, ResponseAttributes,
|
||||
ResponseParserError,
|
||||
},
|
||||
common::VolumeValue,
|
||||
request_tokenizer::RequestTokenizer,
|
||||
response_tokenizer::ResponseAttributes,
|
||||
};
|
||||
|
||||
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: RequestTokenizer<'_>) -> RequestParserResult<'_> {
|
||||
fn parse_request(mut parts: std::str::SplitWhitespace<'_>) -> RequestParserResult<'_> {
|
||||
let change = match parts.next() {
|
||||
Some(s) => VolumeValue::from_str(s)
|
||||
.map_err(|_| RequestParserError::SyntaxError(0, s.to_owned()))?,
|
||||
@@ -32,7 +28,7 @@ impl Command for Volume {
|
||||
|
||||
fn parse_response(
|
||||
parts: ResponseAttributes<'_>,
|
||||
) -> Result<Self::Response, ResponseParserError<'_>> {
|
||||
) -> Result<Self::Response, ResponseParserError> {
|
||||
debug_assert!(parts.is_empty());
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -1,22 +1,15 @@
|
||||
use crate::{
|
||||
commands::{Command, Request, RequestParserResult, ResponseParserError},
|
||||
request_tokenizer::RequestTokenizer,
|
||||
response_tokenizer::ResponseAttributes,
|
||||
use crate::commands::{
|
||||
Command, Request, RequestParserResult, ResponseAttributes, ResponseParserError,
|
||||
};
|
||||
|
||||
/// Clears the current error message in status (this is also accomplished by any command that starts playback)
|
||||
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: RequestTokenizer<'_>) -> RequestParserResult<'_> {
|
||||
fn parse_request(mut parts: std::str::SplitWhitespace<'_>) -> RequestParserResult<'_> {
|
||||
debug_assert!(parts.next().is_none());
|
||||
|
||||
Ok((Request::ClearError, ""))
|
||||
@@ -24,7 +17,7 @@ impl Command for ClearError {
|
||||
|
||||
fn parse_response(
|
||||
parts: ResponseAttributes<'_>,
|
||||
) -> Result<Self::Response, ResponseParserError<'_>> {
|
||||
) -> Result<Self::Response, ResponseParserError> {
|
||||
debug_assert!(parts.is_empty());
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::{
|
||||
commands::{Command, Request, RequestParserResult, ResponseParserError},
|
||||
request_tokenizer::RequestTokenizer,
|
||||
response_tokenizer::ResponseAttributes,
|
||||
use crate::commands::{
|
||||
Command, Request, RequestParserResult, ResponseAttributes, ResponseParserError,
|
||||
};
|
||||
|
||||
/// Displays the song info of the current song (same song that is identified in status)
|
||||
@@ -13,15 +11,10 @@ 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: RequestTokenizer<'_>) -> RequestParserResult<'_> {
|
||||
fn parse_request(mut parts: std::str::SplitWhitespace<'_>) -> RequestParserResult<'_> {
|
||||
debug_assert!(parts.next().is_none());
|
||||
|
||||
Ok((Request::CurrentSong, ""))
|
||||
@@ -29,7 +22,7 @@ impl Command for CurrentSong {
|
||||
|
||||
fn parse_response(
|
||||
_parts: ResponseAttributes<'_>,
|
||||
) -> Result<Self::Response, ResponseParserError<'_>> {
|
||||
) -> Result<Self::Response, ResponseParserError> {
|
||||
unimplemented!()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,36 +1,18 @@
|
||||
use std::str::FromStr;
|
||||
use std::str::{FromStr, SplitWhitespace};
|
||||
|
||||
use crate::{
|
||||
commands::{Command, Request, RequestParserResult, ResponseParserError},
|
||||
common::SubSystem,
|
||||
request_tokenizer::RequestTokenizer,
|
||||
response_tokenizer::ResponseAttributes,
|
||||
use crate::common::SubSystem;
|
||||
|
||||
use crate::commands::{
|
||||
Command, Request, RequestParserResult, ResponseAttributes, ResponseParserError,
|
||||
};
|
||||
|
||||
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: RequestTokenizer<'_>) -> RequestParserResult<'_> {
|
||||
fn parse_request(mut parts: SplitWhitespace<'_>) -> RequestParserResult<'_> {
|
||||
let result = parts
|
||||
.next()
|
||||
.map_or(Ok((Request::Idle(None), "")), |subsystems| {
|
||||
@@ -48,7 +30,7 @@ impl Command for Idle {
|
||||
|
||||
fn parse_response(
|
||||
parts: ResponseAttributes<'_>,
|
||||
) -> Result<Self::Response, ResponseParserError<'_>> {
|
||||
) -> Result<Self::Response, ResponseParserError> {
|
||||
debug_assert!(parts.is_empty());
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -2,12 +2,9 @@ use std::collections::HashMap;
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::{
|
||||
commands::{Command, Request, RequestParserResult, ResponseParserError},
|
||||
request_tokenizer::RequestTokenizer,
|
||||
response_tokenizer::{
|
||||
ResponseAttributes, get_and_parse_optional_property, get_and_parse_property,
|
||||
},
|
||||
use crate::commands::{
|
||||
get_and_parse_optional_property, get_and_parse_property, Command, Request, RequestParserResult,
|
||||
ResponseAttributes, ResponseParserError,
|
||||
};
|
||||
|
||||
pub struct Stats;
|
||||
@@ -24,15 +21,10 @@ 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: RequestTokenizer<'_>) -> RequestParserResult<'_> {
|
||||
fn parse_request(mut parts: std::str::SplitWhitespace<'_>) -> RequestParserResult<'_> {
|
||||
debug_assert!(parts.next().is_none());
|
||||
|
||||
Ok((Request::Stats, ""))
|
||||
@@ -40,8 +32,8 @@ impl Command for Stats {
|
||||
|
||||
fn parse_response(
|
||||
parts: ResponseAttributes<'_>,
|
||||
) -> Result<Self::Response, ResponseParserError<'_>> {
|
||||
let parts: HashMap<_, _> = parts.into_map()?;
|
||||
) -> Result<Self::Response, ResponseParserError> {
|
||||
let parts: HashMap<_, _> = parts.into();
|
||||
|
||||
let uptime = get_and_parse_property!(parts, "uptime", Text);
|
||||
let playtime = get_and_parse_property!(parts, "playtime", Text);
|
||||
|
||||
@@ -3,14 +3,12 @@ use std::str::FromStr;
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::{
|
||||
commands::{Command, Request, RequestParserResult, ResponseParserError},
|
||||
common::{Audio, BoolOrOneshot, SongId, SongPosition},
|
||||
request_tokenizer::RequestTokenizer,
|
||||
response_tokenizer::{
|
||||
GenericResponseValue, ResponseAttributes, get_and_parse_optional_property,
|
||||
get_and_parse_property, get_optional_property, get_property,
|
||||
},
|
||||
use crate::common::{Audio, BoolOrOneshot, SongId, SongPosition};
|
||||
|
||||
use crate::commands::{
|
||||
get_and_parse_optional_property, get_and_parse_property, get_optional_property, get_property,
|
||||
Command, GenericResponseValue, Request, RequestParserResult, ResponseAttributes,
|
||||
ResponseParserError,
|
||||
};
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||
@@ -65,8 +63,8 @@ pub struct StatusResponse {
|
||||
#[inline]
|
||||
fn parse_status_response(
|
||||
parts: ResponseAttributes<'_>,
|
||||
) -> Result<StatusResponse, ResponseParserError<'_>> {
|
||||
let parts: HashMap<_, _> = parts.into_map()?;
|
||||
) -> Result<StatusResponse, ResponseParserError> {
|
||||
let parts: HashMap<&str, GenericResponseValue> = parts.into();
|
||||
let partition = get_property!(parts, "partition", Text).to_string();
|
||||
|
||||
let volume = match get_property!(parts, "volume", Text) {
|
||||
@@ -161,15 +159,10 @@ 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: RequestTokenizer<'_>) -> RequestParserResult<'_> {
|
||||
fn parse_request(mut parts: std::str::SplitWhitespace<'_>) -> RequestParserResult<'_> {
|
||||
debug_assert!(parts.next().is_none());
|
||||
|
||||
Ok((Request::Status, ""))
|
||||
@@ -177,7 +170,7 @@ impl Command for Status {
|
||||
|
||||
fn parse_response(
|
||||
parts: ResponseAttributes<'_>,
|
||||
) -> Result<Self::Response, ResponseParserError<'_>> {
|
||||
) -> Result<Self::Response, ResponseParserError> {
|
||||
parse_status_response(parts)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,39 +1,18 @@
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::{
|
||||
commands::{Command, Request, RequestParserError, RequestParserResult, ResponseParserError},
|
||||
common::{SongPosition, Uri},
|
||||
request_tokenizer::RequestTokenizer,
|
||||
response_tokenizer::ResponseAttributes,
|
||||
commands::{
|
||||
Command, Request, RequestParserError, RequestParserResult, ResponseAttributes,
|
||||
ResponseParserError,
|
||||
},
|
||||
common::SongPosition,
|
||||
};
|
||||
|
||||
pub struct Add;
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||
pub struct AddRequest {
|
||||
uri: Uri,
|
||||
position: Option<SongPosition>,
|
||||
}
|
||||
|
||||
impl AddRequest {
|
||||
pub fn new(uri: Uri, position: Option<SongPosition>) -> Self {
|
||||
Self { uri, position }
|
||||
}
|
||||
}
|
||||
|
||||
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: RequestTokenizer<'_>) -> RequestParserResult<'_> {
|
||||
fn parse_request(mut parts: std::str::SplitWhitespace<'_>) -> RequestParserResult<'_> {
|
||||
let uri = match parts.next() {
|
||||
Some(s) => s,
|
||||
None => return Err(RequestParserError::UnexpectedEOF),
|
||||
@@ -54,7 +33,7 @@ impl Command for Add {
|
||||
|
||||
fn parse_response(
|
||||
parts: ResponseAttributes<'_>,
|
||||
) -> Result<Self::Response, ResponseParserError<'_>> {
|
||||
) -> Result<Self::Response, ResponseParserError> {
|
||||
debug_assert!(parts.is_empty());
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -1,38 +1,22 @@
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::{
|
||||
commands::{Command, Request, RequestParserError, RequestParserResult, ResponseParserError},
|
||||
common::{SongId, SongPosition, Uri},
|
||||
request_tokenizer::RequestTokenizer,
|
||||
response_tokenizer::{ResponseAttributes, get_next_and_parse_property},
|
||||
commands::{
|
||||
get_next_and_parse_property, Command, Request, RequestParserError, RequestParserResult,
|
||||
ResponseAttributes, ResponseParserError,
|
||||
},
|
||||
common::{SongId, SongPosition},
|
||||
};
|
||||
|
||||
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: RequestTokenizer<'_>) -> RequestParserResult<'_> {
|
||||
fn parse_request(mut parts: std::str::SplitWhitespace<'_>) -> RequestParserResult<'_> {
|
||||
let uri = match parts.next() {
|
||||
Some(s) => s,
|
||||
None => return Err(RequestParserError::UnexpectedEOF),
|
||||
@@ -53,13 +37,11 @@ impl Command for AddId {
|
||||
|
||||
fn parse_response(
|
||||
parts: ResponseAttributes<'_>,
|
||||
) -> Result<Self::Response, ResponseParserError<'_>> {
|
||||
) -> Result<Self::Response, ResponseParserError> {
|
||||
let parts: Vec<_> = parts.into();
|
||||
let mut iter = parts.into_iter();
|
||||
let (key, id) = get_next_and_parse_property!(iter, Text);
|
||||
if key != "Id" {
|
||||
return Err(ResponseParserError::UnexpectedProperty(key));
|
||||
}
|
||||
debug_assert!(key == "Id");
|
||||
Ok(AddIdResponse { id })
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,39 +1,17 @@
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::{
|
||||
Request,
|
||||
commands::{
|
||||
Command, RequestParserError, RequestParserResult, ResponseAttributes, ResponseParserError,
|
||||
},
|
||||
common::{SongId, TagName, TagValue},
|
||||
request_tokenizer::RequestTokenizer,
|
||||
Request,
|
||||
};
|
||||
|
||||
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: RequestTokenizer<'_>) -> RequestParserResult<'_> {
|
||||
fn parse_request(mut parts: std::str::SplitWhitespace<'_>) -> RequestParserResult<'_> {
|
||||
let songid = parts.next().ok_or(RequestParserError::UnexpectedEOF)?;
|
||||
let songid = songid
|
||||
.parse()
|
||||
@@ -56,7 +34,7 @@ impl Command for AddTagId {
|
||||
|
||||
fn parse_response(
|
||||
parts: ResponseAttributes<'_>,
|
||||
) -> Result<Self::Response, ResponseParserError<'_>> {
|
||||
) -> Result<Self::Response, ResponseParserError> {
|
||||
debug_assert!(parts.is_empty());
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -1,28 +1,21 @@
|
||||
use crate::{
|
||||
commands::{Command, Request, RequestParserResult, ResponseParserError},
|
||||
request_tokenizer::RequestTokenizer,
|
||||
response_tokenizer::ResponseAttributes,
|
||||
use crate::commands::{
|
||||
Command, Request, RequestParserResult, ResponseAttributes, ResponseParserError,
|
||||
};
|
||||
|
||||
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: RequestTokenizer<'_>) -> RequestParserResult<'_> {
|
||||
fn parse_request(mut parts: std::str::SplitWhitespace<'_>) -> RequestParserResult<'_> {
|
||||
debug_assert!(parts.next().is_none());
|
||||
Ok((Request::Clear, ""))
|
||||
}
|
||||
|
||||
fn parse_response(
|
||||
parts: ResponseAttributes<'_>,
|
||||
) -> Result<Self::Response, ResponseParserError<'_>> {
|
||||
) -> Result<Self::Response, ResponseParserError> {
|
||||
debug_assert!(parts.is_empty());
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -1,31 +1,17 @@
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::{
|
||||
commands::{
|
||||
Command, RequestParserError, RequestParserResult, ResponseAttributes, ResponseParserError,
|
||||
},
|
||||
Request,
|
||||
commands::{Command, RequestParserError, RequestParserResult, ResponseParserError},
|
||||
common::{SongId, TagName},
|
||||
request_tokenizer::RequestTokenizer,
|
||||
response_tokenizer::ResponseAttributes,
|
||||
};
|
||||
|
||||
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: RequestTokenizer<'_>) -> RequestParserResult<'_> {
|
||||
fn parse_request(mut parts: std::str::SplitWhitespace<'_>) -> RequestParserResult<'_> {
|
||||
let songid = parts.next().ok_or(RequestParserError::UnexpectedEOF)?;
|
||||
let songid = songid
|
||||
.parse()
|
||||
@@ -43,7 +29,7 @@ impl Command for ClearTagId {
|
||||
|
||||
fn parse_response(
|
||||
parts: ResponseAttributes<'_>,
|
||||
) -> Result<Self::Response, ResponseParserError<'_>> {
|
||||
) -> Result<Self::Response, ResponseParserError> {
|
||||
debug_assert!(parts.is_empty());
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -1,25 +1,20 @@
|
||||
use std::str::FromStr;
|
||||
|
||||
use crate::{
|
||||
Request,
|
||||
commands::{Command, RequestParserError, RequestParserResult, ResponseParserError},
|
||||
commands::{
|
||||
Command, RequestParserError, RequestParserResult, ResponseAttributes, ResponseParserError,
|
||||
},
|
||||
common::OneOrRange,
|
||||
request_tokenizer::RequestTokenizer,
|
||||
response_tokenizer::ResponseAttributes,
|
||||
Request,
|
||||
};
|
||||
|
||||
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: RequestTokenizer<'_>) -> RequestParserResult<'_> {
|
||||
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)
|
||||
.map_err(|_| RequestParserError::SyntaxError(0, pos_or_range.to_string()))?;
|
||||
@@ -31,7 +26,7 @@ impl Command for Delete {
|
||||
|
||||
fn parse_response(
|
||||
parts: ResponseAttributes<'_>,
|
||||
) -> Result<Self::Response, ResponseParserError<'_>> {
|
||||
) -> Result<Self::Response, ResponseParserError> {
|
||||
debug_assert!(parts.is_empty());
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -1,23 +1,17 @@
|
||||
use crate::{
|
||||
commands::{
|
||||
Command, RequestParserError, RequestParserResult, ResponseAttributes, ResponseParserError,
|
||||
},
|
||||
Request,
|
||||
commands::{Command, RequestParserError, RequestParserResult, ResponseParserError},
|
||||
common::SongId,
|
||||
request_tokenizer::RequestTokenizer,
|
||||
response_tokenizer::ResponseAttributes,
|
||||
};
|
||||
|
||||
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: RequestTokenizer<'_>) -> RequestParserResult<'_> {
|
||||
fn parse_request(mut parts: std::str::SplitWhitespace<'_>) -> RequestParserResult<'_> {
|
||||
let id = parts.next().ok_or(RequestParserError::UnexpectedEOF)?;
|
||||
let id = id
|
||||
.parse()
|
||||
@@ -30,7 +24,7 @@ impl Command for DeleteId {
|
||||
|
||||
fn parse_response(
|
||||
parts: ResponseAttributes<'_>,
|
||||
) -> Result<Self::Response, ResponseParserError<'_>> {
|
||||
) -> Result<Self::Response, ResponseParserError> {
|
||||
debug_assert!(parts.is_empty());
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -1,32 +1,17 @@
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::{
|
||||
Request,
|
||||
commands::{
|
||||
Command, RequestParserError, RequestParserResult, ResponseAttributes, ResponseParserError,
|
||||
},
|
||||
common::{AbsouluteRelativeSongPosition, OneOrRange},
|
||||
request_tokenizer::RequestTokenizer,
|
||||
Request,
|
||||
};
|
||||
|
||||
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: RequestTokenizer<'_>) -> RequestParserResult<'_> {
|
||||
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
|
||||
.parse()
|
||||
@@ -44,7 +29,7 @@ impl Command for Move {
|
||||
|
||||
fn parse_response(
|
||||
parts: ResponseAttributes<'_>,
|
||||
) -> Result<Self::Response, ResponseParserError<'_>> {
|
||||
) -> Result<Self::Response, ResponseParserError> {
|
||||
debug_assert!(parts.is_empty());
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -1,32 +1,17 @@
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::{
|
||||
Request,
|
||||
commands::{
|
||||
Command, RequestParserError, RequestParserResult, ResponseAttributes, ResponseParserError,
|
||||
},
|
||||
common::{AbsouluteRelativeSongPosition, SongId},
|
||||
request_tokenizer::RequestTokenizer,
|
||||
Request,
|
||||
};
|
||||
|
||||
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: RequestTokenizer<'_>) -> RequestParserResult<'_> {
|
||||
fn parse_request(mut parts: std::str::SplitWhitespace<'_>) -> RequestParserResult<'_> {
|
||||
let id = parts.next().ok_or(RequestParserError::UnexpectedEOF)?;
|
||||
let id = id
|
||||
.parse()
|
||||
@@ -44,7 +29,7 @@ impl Command for MoveId {
|
||||
|
||||
fn parse_response(
|
||||
parts: ResponseAttributes<'_>,
|
||||
) -> Result<Self::Response, ResponseParserError<'_>> {
|
||||
) -> Result<Self::Response, ResponseParserError> {
|
||||
debug_assert!(parts.is_empty());
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -1,29 +1,22 @@
|
||||
use crate::{
|
||||
commands::{Command, RequestParserResult, ResponseAttributes, ResponseParserError},
|
||||
Request,
|
||||
commands::{Command, RequestParserResult, ResponseParserError},
|
||||
request_tokenizer::RequestTokenizer,
|
||||
response_tokenizer::ResponseAttributes,
|
||||
};
|
||||
|
||||
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: RequestTokenizer<'_>) -> RequestParserResult<'_> {
|
||||
fn parse_request(mut parts: std::str::SplitWhitespace<'_>) -> RequestParserResult<'_> {
|
||||
debug_assert!(parts.next().is_none());
|
||||
Ok((Request::Playlist, ""))
|
||||
}
|
||||
|
||||
fn parse_response(
|
||||
_parts: ResponseAttributes<'_>,
|
||||
) -> Result<Self::Response, ResponseParserError<'_>> {
|
||||
) -> Result<Self::Response, ResponseParserError> {
|
||||
unimplemented!()
|
||||
}
|
||||
}
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user