diff options
| author | Fuwn <[email protected]> | 2021-06-06 00:15:13 +0000 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2021-06-06 00:15:13 +0000 |
| commit | e1af06de6407c2341163cfda173c7d2ac0ba36d4 (patch) | |
| tree | a15e817dff79c3018f3ba8e57fbc960b738d7f25 | |
| parent | refactor(whirl_server::net): move orphan functions to methods within property... (diff) | |
| download | whirl-e1af06de6407c2341163cfda173c7d2ac0ba36d4.tar.xz whirl-e1af06de6407c2341163cfda173c7d2ac0ba36d4.zip | |
refactor(whirl_server): orphan function to command method
| -rw-r--r-- | crates/whirl_server/src/cmd/mod.rs | 1 | ||||
| -rw-r--r-- | crates/whirl_server/src/cmd/set_parser.rs | 39 | ||||
| -rw-r--r-- | crates/whirl_server/src/cmd/structure.rs | 33 |
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 { |