Skip to content

Commit

Permalink
chore(afrim-jni): internal minor refactor (#23)
Browse files Browse the repository at this point in the history
  • Loading branch information
pythonbrad authored Mar 31, 2024
1 parent c515b53 commit 288f85c
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions app/src/main/jni/afrim_jni/src/afrim_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ impl Afrim {

/// Process the keyboard event.
pub fn process_key(&mut self, key: &str, state: &str) -> Result<(bool, bool), String> {
let key_event = utils::parse_event(key, state)?;
let key_event = utils::deserialize_event(key, state)?;
let status = self.preprocessor.process(key_event);

Ok(status)
Expand All @@ -88,7 +88,8 @@ impl Afrim {
pub fn next_command(&mut self) -> String {
self.preprocessor
.pop_queue()
.map(utils::parse_command)
.as_ref()
.map(utils::serialize_command)
.unwrap_or("\"NOP\"".to_owned())
}

Expand Down Expand Up @@ -152,7 +153,7 @@ mod utils {
use std::str::FromStr;

/// Deserializes the KeyboardEvent.
pub fn parse_event(key: &str, state: &str) -> Result<KeyboardEvent, String> {
pub fn deserialize_event(key: &str, state: &str) -> Result<KeyboardEvent, String> {
let event = KeyboardEvent {
key: Key::from_str(key).map_err(|err| {
format!("[preprocessor] Unrecognized key `{key}`.\nCaused by:\n\t{err}.")
Expand All @@ -167,7 +168,7 @@ mod utils {
}

/// Converts an afrim command to speudo code.
pub fn parse_command(command: Command) -> String {
serde_json::to_string(&command).unwrap()
pub fn serialize_command(command: &Command) -> String {
serde_json::to_string(command).unwrap()
}
}

0 comments on commit 288f85c

Please sign in to comment.