aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/commands.rs30
-rw-r--r--src/util.rs2
2 files changed, 16 insertions, 16 deletions
diff --git a/src/commands.rs b/src/commands.rs
index e8e332b..3a7d16a 100644
--- a/src/commands.rs
+++ b/src/commands.rs
@@ -23,21 +23,6 @@ trait Command {
type Response: Serialize;
fn execute(data: Self::Request) -> Result<Self::Response, CommandStatus>;
-
- fn execute_raw(data: &[u8], buf: &mut [u8]) -> CommandStatus {
- // TODO: better error if (de-)serialization fails
- if let Ok((request, _)) = ssmarshal::deserialize::<Self::Request>(data) {
- match Self::execute(request) {
- Ok(response) => match ssmarshal::serialize(buf, &response) {
- Ok(_) => CommandStatus::Ok,
- Err(_) => CommandStatus::NotSupported,
- },
- Err(status) => status,
- }
- } else {
- CommandStatus::NotSupported
- }
- }
}
#[derive(Debug, Default, Serialize)]
@@ -95,3 +80,18 @@ impl Command for ReadSlotNameCommand {
}
}
}
+
+fn execute<C: Command>(data: &[u8], buf: &mut [u8]) -> CommandStatus {
+ // TODO: better error if (de-)serialization fails
+ if let Ok((request, _)) = ssmarshal::deserialize::<C::Request>(data) {
+ match C::execute(request) {
+ Ok(response) => match ssmarshal::serialize(buf, &response) {
+ Ok(_) => CommandStatus::Ok,
+ Err(_) => CommandStatus::NotSupported,
+ },
+ Err(status) => status,
+ }
+ } else {
+ CommandStatus::NotSupported
+ }
+}
diff --git a/src/util.rs b/src/util.rs
index 9325e9e..c83d3f3 100644
--- a/src/util.rs
+++ b/src/util.rs
@@ -24,7 +24,7 @@ macro_rules! enum_cmd {
pub fn execute(&self, data: &[u8], buf: &mut [u8]) -> CommandStatus {
match *self {
$(
- $name::$var => $cmd::execute_raw(data, buf),
+ $name::$var => crate::commands::execute::<$cmd>(data, buf),
)*
}
}