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 /crates/whirl_server/src/cmd/structure.rs | |
| 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
Diffstat (limited to 'crates/whirl_server/src/cmd/structure.rs')
| -rw-r--r-- | crates/whirl_server/src/cmd/structure.rs | 33 |
1 files changed, 33 insertions, 0 deletions
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 { |