aboutsummaryrefslogtreecommitdiff
path: root/crates/whirl_server/src/cmd/set_parser.rs
diff options
context:
space:
mode:
authorFuwn <[email protected]>2021-05-20 17:05:59 +0000
committerFuwn <[email protected]>2021-05-20 17:05:59 +0000
commit9dbc613765de8ab7dfa8e1374cf6661dcfd56bc8 (patch)
tree8cfff6a23bb72db2660e68c63a8cf9d0539a061f /crates/whirl_server/src/cmd/set_parser.rs
parentfeat(readme): add sqlfluff as a dev dep (diff)
downloadarchived-whirl-9dbc613765de8ab7dfa8e1374cf6661dcfd56bc8.tar.xz
archived-whirl-9dbc613765de8ab7dfa8e1374cf6661dcfd56bc8.zip
refactor(global): move crates around, stricter module isolation
Diffstat (limited to 'crates/whirl_server/src/cmd/set_parser.rs')
-rw-r--r--crates/whirl_server/src/cmd/set_parser.rs39
1 files changed, 39 insertions, 0 deletions
diff --git a/crates/whirl_server/src/cmd/set_parser.rs b/crates/whirl_server/src/cmd/set_parser.rs
new file mode 100644
index 0000000..9d6a4b3
--- /dev/null
+++ b/crates/whirl_server/src/cmd/set_parser.rs
@@ -0,0 +1,39 @@
+// 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 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: command_length as i32,
+ obj_id: data[1] as i32,
+ id: data[2] as i32,
+ 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
+}