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/ target: ${{ gitea.ref_name }}/coverage/
username: gitea-web username: gitea-web
ssh-key: ${{ secrets.WEB_SYNC_SSH_KEY }} ssh-key: ${{ secrets.WEB_SYNC_SSH_KEY }}
host: pages.pvv.ntnu.no host: bekkalokk.pvv.ntnu.no
known-hosts: "pages.pvv.ntnu.no ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIH2QjfFB+city1SYqltkVqWACfo1j37k+oQQfj13mtgg" known-hosts: "bekkalokk.pvv.ntnu.no ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIEI6VSaDrMG8+flg4/AeHlAFIen8RUzWh6URQKqFegSx"
docs: docs:
runs-on: ubuntu-latest runs-on: ubuntu-latest
@@ -107,6 +107,6 @@ jobs:
target: ${{ gitea.ref_name }}/docs/ target: ${{ gitea.ref_name }}/docs/
username: gitea-web username: gitea-web
ssh-key: ${{ secrets.WEB_SYNC_SSH_KEY }} ssh-key: ${{ secrets.WEB_SYNC_SSH_KEY }}
host: pages.pvv.ntnu.no host: bekkalokk.pvv.ntnu.no
known-hosts: "pages.pvv.ntnu.no ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIH2QjfFB+city1SYqltkVqWACfo1j37k+oQQfj13mtgg" known-hosts: "bekkalokk.pvv.ntnu.no ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIEI6VSaDrMG8+flg4/AeHlAFIen8RUzWh6URQKqFegSx"

4
Cargo.lock generated
View File

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

View File

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

12
flake.lock generated
View File

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

View File

@@ -36,7 +36,6 @@
default = pkgs.mkShell { default = pkgs.mkShell {
nativeBuildInputs = [ nativeBuildInputs = [
toolchain toolchain
pkgs.cargo-edit
]; ];
RUST_SRC_PATH = "${toolchain}/lib/rustlib/src/rust/library"; 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 (ckey, cvalue) = channel_message_pair[0];
let (mkey, mvalue) = channel_message_pair[1]; let (mkey, mvalue) = channel_message_pair[1];
debug_assert!(ckey == "channel"); if ckey != "channel" {
debug_assert!(mkey == "message"); 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 channel = expect_property_type!(Some(cvalue), "channel", Text).to_string();
let message = expect_property_type!(Some(mvalue), "message", Text).to_string(); let message = expect_property_type!(Some(mvalue), "message", Text).to_string();

View File

@@ -1,6 +1,6 @@
use crate::commands::{ use crate::commands::{
Command, GenericResponseValue, Request, RequestParserResult, ResponseAttributes, Command, Request, RequestParserResult, ResponseAttributes, ResponseParserError,
ResponseParserError, expect_property_type,
}; };
pub struct TagTypes; pub struct TagTypes;
@@ -24,16 +24,7 @@ impl Command for TagTypes {
let mut tagtypes = Vec::with_capacity(parts.len()); let mut tagtypes = Vec::with_capacity(parts.len());
for (key, value) in parts.into_iter() { for (key, value) in parts.into_iter() {
debug_assert_eq!(key, "tagtype"); 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); tagtypes.push(tagtype);
} }

View File

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

View File

@@ -40,8 +40,15 @@ impl Command for AddId {
) -> Result<Self::Response, ResponseParserError> { ) -> Result<Self::Response, ResponseParserError> {
let parts: Vec<_> = parts.into(); let parts: Vec<_> = parts.into();
let mut iter = parts.into_iter(); let mut iter = parts.into_iter();
let (key, id) = get_next_and_parse_property!(iter, Text); 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 }) Ok(AddIdResponse { id })
} }
} }

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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