1 Commits

Author SHA1 Message Date
e469a8eb3c WIP 2025-05-07 10:54:28 +02:00
16 changed files with 64 additions and 120 deletions

View File

@@ -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
Cargo.lock generated
View File

@@ -73,9 +73,9 @@ dependencies = [
[[package]]
name = "syn"
version = "2.0.104"
version = "2.0.101"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "17b6f705963418cdb9927482fa304bc562ece2fdd4f616084c50b7023b435a40"
checksum = "8ce2b7fc941b3a24138a0a7cf8e858bfc6a992e7978a068a5c760deb0ed43caf"
dependencies = [
"proc-macro2",
"quote",

View File

@@ -11,8 +11,8 @@ edition = "2024"
rust-version = "1.85.0"
[dependencies]
serde = { version = "1.0.219", features = ["derive"] }
serde = { version = "1.0.210", features = ["derive"] }
[dev-dependencies]
indoc = "2.0.6"
indoc = "2.0.5"
pretty_assertions = "1.4.1"

12
flake.lock generated
View File

@@ -2,11 +2,11 @@
"nodes": {
"nixpkgs": {
"locked": {
"lastModified": 1753939845,
"narHash": "sha256-K2ViRJfdVGE8tpJejs8Qpvvejks1+A4GQej/lBk5y7I=",
"lastModified": 1746461020,
"narHash": "sha256-7+pG1I9jvxNlmln4YgnlW4o+w0TZX24k688mibiFDUE=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "94def634a20494ee057c76998843c015909d6311",
"rev": "3730d8a308f94996a9ba7c7138ede69c1b9ac4ae",
"type": "github"
},
"original": {
@@ -29,11 +29,11 @@
]
},
"locked": {
"lastModified": 1754189623,
"narHash": "sha256-fstu5eb30UYwsxow0aQqkzxNxGn80UZjyehQVNVHuBk=",
"lastModified": 1746585402,
"narHash": "sha256-Pf+ufu6bYNA1+KQKHnGMNEfTwpD9ZIcAeLoE2yPWIP0=",
"owner": "oxalica",
"repo": "rust-overlay",
"rev": "c582ff7f0d8a7ea689ae836dfb1773f1814f472a",
"rev": "72dd969389583664f87aa348b3458f2813693617",
"type": "github"
},
"original": {

View File

@@ -36,7 +36,6 @@
default = pkgs.mkShell {
nativeBuildInputs = [
toolchain
pkgs.cargo-edit
];
RUST_SRC_PATH = "${toolchain}/lib/rustlib/src/rust/library";

View File

@@ -34,8 +34,12 @@ impl Command for ReadMessages {
let (ckey, cvalue) = channel_message_pair[0];
let (mkey, mvalue) = channel_message_pair[1];
debug_assert!(ckey == "channel");
debug_assert!(mkey == "message");
if ckey != "channel" {
return Err(ResponseParserError::UnexpectedProperty(ckey));
}
if mkey != "message" {
return Err(ResponseParserError::UnexpectedProperty(mkey));
}
let channel = expect_property_type!(Some(cvalue), "channel", Text).to_string();
let message = expect_property_type!(Some(mvalue), "message", Text).to_string();

View File

@@ -1,6 +1,6 @@
use crate::commands::{
Command, GenericResponseValue, Request, RequestParserResult, ResponseAttributes,
ResponseParserError,
Command, Request, RequestParserResult, ResponseAttributes, ResponseParserError,
expect_property_type,
};
pub struct TagTypes;
@@ -24,16 +24,7 @@ impl Command for TagTypes {
let mut tagtypes = Vec::with_capacity(parts.len());
for (key, value) in parts.into_iter() {
debug_assert_eq!(key, "tagtype");
let tagtype = match value {
GenericResponseValue::Text(name) => name.to_string(),
GenericResponseValue::Binary(_) => {
return Err(ResponseParserError::UnexpectedPropertyType(
"tagtype", "Binary",
));
}
};
let tagtype = expect_property_type!(Some(value), "tagtype", Text).to_string();
tagtypes.push(tagtype);
}

View File

@@ -2,7 +2,7 @@ use std::collections::HashMap;
use crate::commands::{
Command, GenericResponseValue, Request, RequestParserError, RequestParserResult,
ResponseAttributes, ResponseParserError,
ResponseAttributes, ResponseParserError, expect_property_type,
};
pub struct ReadComments;
@@ -30,10 +30,12 @@ impl Command for ReadComments {
let parts: HashMap<_, _> = parts.into();
let comments = parts
.iter()
.map(|(k, v)| match v {
GenericResponseValue::Text(s) => Ok((k.to_string(), s.to_string())),
GenericResponseValue::Binary(_) => Err(ResponseParserError::SyntaxError(1, k)),
.into_iter()
.map(|(k, v)| {
Ok((
k.to_string(),
expect_property_type!(Some(v), k, Text).to_string(),
))
})
.collect::<Result<HashMap<_, _>, ResponseParserError>>()?;

View File

@@ -40,8 +40,15 @@ impl Command for AddId {
) -> 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);
debug_assert!(key == "Id");
if key != "Id" {
return Err(ResponseParserError::UnexpectedProperty(key));
}
debug_assert!(iter.next().is_none());
Ok(AddIdResponse { id })
}
}

View File

@@ -1,6 +1,6 @@
use crate::commands::{
Command, GenericResponseValue, Request, RequestParserResult, ResponseAttributes,
ResponseParserError,
Command, Request, RequestParserResult, ResponseAttributes, ResponseParserError,
expect_property_type,
};
pub struct Commands;
@@ -25,14 +25,7 @@ impl Command for Commands {
if key != "command" {
return Err(ResponseParserError::UnexpectedProperty(key));
}
let value = match value {
GenericResponseValue::Text(value) => value,
GenericResponseValue::Binary(_) => {
return Err(ResponseParserError::UnexpectedPropertyType(
"handler", "Binary",
));
}
};
let value = expect_property_type!(Some(value), "command", Text);
result.push(value.to_string());
}
Ok(result)

View File

@@ -1,6 +1,6 @@
use crate::commands::{
Command, GenericResponseValue, Request, RequestParserResult, ResponseAttributes,
ResponseParserError,
Command, Request, RequestParserResult, ResponseAttributes, ResponseParserError,
expect_property_type,
};
pub struct NotCommands;
@@ -25,14 +25,7 @@ impl Command for NotCommands {
if key != "command" {
return Err(ResponseParserError::UnexpectedProperty(key));
}
let value = match value {
GenericResponseValue::Text(value) => value,
GenericResponseValue::Binary(_) => {
return Err(ResponseParserError::UnexpectedPropertyType(
"handler", "Binary",
));
}
};
let value = expect_property_type!(Some(value), "command", Text).to_string();
result.push(value.to_string());
}
Ok(result)

View File

@@ -1,6 +1,6 @@
use crate::commands::{
Command, GenericResponseValue, Request, RequestParserResult, ResponseAttributes,
ResponseParserError,
Command, Request, RequestParserResult, ResponseAttributes, ResponseParserError,
expect_property_type,
};
pub struct UrlHandlers;
@@ -25,14 +25,7 @@ impl Command for UrlHandlers {
if key != "handler" {
return Err(ResponseParserError::UnexpectedProperty(key));
}
let value = match value {
GenericResponseValue::Text(value) => value,
GenericResponseValue::Binary(_) => {
return Err(ResponseParserError::UnexpectedPropertyType(
"handler", "Binary",
));
}
};
let value = expect_property_type!(Some(value), "handler", Text);
url_handlers.push(value.to_string());
}
Ok(url_handlers)

View File

@@ -1,6 +1,6 @@
use crate::commands::{
Command, GenericResponseValue, Request, RequestParserError, RequestParserResult,
ResponseAttributes, ResponseParserError,
Command, Request, RequestParserError, RequestParserResult, ResponseAttributes,
ResponseParserError, expect_property_type,
};
pub struct StickerFind;
@@ -84,21 +84,8 @@ impl Command for StickerFind {
// TODO: debug assert that this is a valid sticker type
// debug_assert!(uri.0 == "");
let uri = match uri.1 {
GenericResponseValue::Text(s) => s.to_string(),
GenericResponseValue::Binary(_) => {
return Err(ResponseParserError::UnexpectedPropertyType(uri.0, "Binary"));
}
};
let sticker = match sticker.1 {
GenericResponseValue::Text(s) => s,
GenericResponseValue::Binary(_) => {
return Err(ResponseParserError::UnexpectedPropertyType(
"sticker", "Binary",
));
}
};
let uri = expect_property_type!(Some(uri.1), uri.0, Text).to_string();
let sticker = expect_property_type!(Some(sticker.1), sticker.0, Text);
// TODO: This assumes the first = is the only one.
// See: https://github.com/MusicPlayerDaemon/MPD/issues/2166

View File

@@ -1,8 +1,8 @@
use std::collections::HashMap;
use crate::commands::{
Command, GenericResponseValue, Request, RequestParserError, RequestParserResult,
ResponseAttributes, ResponseParserError,
Command, Request, RequestParserError, RequestParserResult, ResponseAttributes,
ResponseParserError, expect_property_type,
};
pub struct StickerList;
@@ -37,12 +37,7 @@ impl Command for StickerList {
let result = parts
.iter()
.map(|(_, v)| match v {
GenericResponseValue::Text(value) => Ok(value),
GenericResponseValue::Binary(_) => Err(
ResponseParserError::UnexpectedPropertyType("sticker", "Binary"),
),
})
.map(|(k, v)| Ok(expect_property_type!(Some(v), k, Text)))
.collect::<Result<Vec<_>, ResponseParserError>>()?;
result

View File

@@ -1,8 +1,8 @@
use std::collections::HashMap;
use crate::commands::{
Command, GenericResponseValue, Request, RequestParserResult, ResponseAttributes,
ResponseParserError,
Command, Request, RequestParserResult, ResponseAttributes, ResponseParserError,
expect_property_type,
};
pub struct StickerNamesTypes;
@@ -34,23 +34,8 @@ impl Command for StickerNamesTypes {
debug_assert!(name_key == "name");
debug_assert!(type_key == "type");
let name = match name_value {
GenericResponseValue::Text(s) => s.to_string(),
GenericResponseValue::Binary(_) => {
return Err(ResponseParserError::UnexpectedPropertyType(
"name", "Binary",
));
}
};
let sticker_type = match type_value {
GenericResponseValue::Text(s) => s.to_string(),
GenericResponseValue::Binary(_) => {
return Err(ResponseParserError::UnexpectedPropertyType(
"type", "Binary",
));
}
};
let name = expect_property_type!(Some(name_value), name_key, Text).to_string();
let sticker_type = expect_property_type!(Some(type_value), type_key, Text).to_string();
result
.entry(name)

View File

@@ -1,7 +1,7 @@
use crate::{
commands::{
Command, GenericResponseValue, Request, RequestParserError, RequestParserResult,
ResponseAttributes, ResponseParserError,
Command, Request, RequestParserError, RequestParserResult, ResponseAttributes,
ResponseParserError, expect_property_type,
},
common::PlaylistName,
};
@@ -37,17 +37,12 @@ impl Command for ListPlaylist {
parts: ResponseAttributes<'_>,
) -> Result<Self::Response, ResponseParserError> {
let parts: Vec<_> = parts.into();
debug_assert!(parts.iter().all(|(k, _)| *k == "file"));
parts
.into_iter()
.map(|(name, value)| {
debug_assert_eq!(name, "file");
match value {
GenericResponseValue::Text(value) => Ok(value.to_string()),
GenericResponseValue::Binary(_) => Err(
ResponseParserError::UnexpectedPropertyType("file", "Binary"),
),
}
})
.map(|(name, value)| Ok(expect_property_type!(Some(value), name, Text).to_string()))
.collect::<Result<Vec<_>, _>>()
}
}