aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFuwn <[email protected]>2021-06-06 00:15:13 -0700
committerFuwn <[email protected]>2021-06-06 00:15:13 -0700
commit5dbddb7c56735a8318e9bb87be9016259d64fd98 (patch)
treec44684383e634077b6346357f384322e6602615f
parentrefactor(whirl_server::net): move orphan functions to methods within property... (diff)
downloadwhirl-5dbddb7c56735a8318e9bb87be9016259d64fd98.tar.xz
whirl-5dbddb7c56735a8318e9bb87be9016259d64fd98.zip
refactor(whirl_server): orphan function to command method
-rw-r--r--crates/whirl_server/src/cmd/mod.rs1
-rw-r--r--crates/whirl_server/src/cmd/set_parser.rs39
-rw-r--r--crates/whirl_server/src/cmd/structure.rs33
3 files changed, 33 insertions, 40 deletions
diff --git a/crates/whirl_server/src/cmd/mod.rs b/crates/whirl_server/src/cmd/mod.rs
index ef91de7..e8f69cb 100644
--- a/crates/whirl_server/src/cmd/mod.rs
+++ b/crates/whirl_server/src/cmd/mod.rs
@@ -5,5 +5,4 @@ pub mod commands;
pub mod constants;
pub mod extendable;
-mod set_parser;
mod structure;
diff --git a/crates/whirl_server/src/cmd/set_parser.rs b/crates/whirl_server/src/cmd/set_parser.rs
deleted file mode 100644
index 5aa5b21..0000000
--- a/crates/whirl_server/src/cmd/set_parser.rs
+++ /dev/null
@@ -1,39 +0,0 @@
-// Copyleft (ɔ) 2021-2021 The Whirlsplash Collective
-// SPDX-License-Identifier: GPL-3.0-only
-
-use crate::cmd::structure::Command;
-
-/// Iterate over a command set in the from of bytes (Vec<u8>) and return a list
-/// of human-readable commands.
-fn _parse_command_set(mut data: Vec<u8>) -> Vec<Command> {
- let mut command_set = vec![];
-
- // Iterate over all commands
- loop {
- // Check if any commands are present
- if data.len() <= 2 {
- break;
- }
- if data[0] == 0 {
- break;
- }
-
- let command_length = data[0];
- let mut command = Command {
- length: i32::from(command_length),
- obj_id: i32::from(data[1]),
- id: i32::from(data[2]),
- body: vec![],
- };
- if command.length > 3 {
- command.body = data[3..].to_owned();
- }
- command_set.push(command);
-
- // Remove current command from the command set
- data = data[command_length as usize..].to_vec();
- }
-
- // Return the human-readable command set
- command_set
-}
diff --git a/crates/whirl_server/src/cmd/structure.rs b/crates/whirl_server/src/cmd/structure.rs
index a9f6ceb..b615599 100644
--- a/crates/whirl_server/src/cmd/structure.rs
+++ b/crates/whirl_server/src/cmd/structure.rs
@@ -9,6 +9,39 @@ pub struct Command {
}
impl Command {
pub fn _new() -> Self { Self::default() }
+
+ pub fn _from_byte(mut data: Vec<u8>) -> Vec<Self> {
+ let mut command_set = vec![];
+
+ // Iterate over all commands
+ loop {
+ // Check if any commands are present
+ if data.len() <= 2 {
+ break;
+ }
+ if data[0] == 0 {
+ break;
+ }
+
+ let command_length = data[0];
+ let mut command = Self {
+ length: i32::from(command_length),
+ obj_id: i32::from(data[1]),
+ id: i32::from(data[2]),
+ body: vec![],
+ };
+ if command.length > 3 {
+ command.body = data[3..].to_owned();
+ }
+ command_set.push(command);
+
+ // Remove current command from the command set
+ data = data[command_length as usize..].to_vec();
+ }
+
+ // Return the human-readable command set
+ command_set
+ }
}
impl Default for Command {
fn default() -> Self {