More fixes, begin implementing query_utils.ts

This commit is contained in:
G2-Games 2023-09-24 18:26:38 -05:00
parent 919a468a76
commit e39e95d555
3 changed files with 43 additions and 1 deletions

View file

@ -38,7 +38,8 @@ fn main() {
for i in 0..player_controller.track_count().unwrap() {
println!(
"Track {i: >2}: {: >21} | {}",
"Track {: >2}: {: >21} | {}",
i + 1,
player_controller.track_title(i as u16, false).unwrap(),
player_controller.track_title(i as u16, true).unwrap()
);

View file

@ -1,3 +1,4 @@
pub mod base;
pub mod interface;
pub mod utils;
pub mod query_utils;

40
src/netmd/query_utils.rs Normal file
View file

@ -0,0 +1,40 @@
use std::collections::hash_map::HashMap;
use std::error::Error;
use once_cell::sync::Lazy;
// prettier-ignore
const FORMAT_TYPE_LEN_DICT: Lazy<HashMap<char, i32>> = Lazy::new(|| {
HashMap::from([
('b', 1), // byte
('w', 2), // word
('d', 4), // doubleword
('q', 8), // quadword
])
});
/*
%b, w, d, q - explained above (can have endiannes overriden by '>' and '<' operators, f. ex. %>d %<q)
%s - Uint8Array preceded by 2 bytes of length
%x - Uint8Array preceded by 2 bytes of length
%z - Uint8Array preceded by 1 byte of length
%* - raw Uint8Array
%B - BCD-encoded 1-byte number
%W - BCD-encoded 2-byte number
*/
const DEBUG: bool = false;
/// Formats a query using a standard input to send to the player
pub fn format_query(format: String, args: Vec<i32>) -> Result<Vec<u8>, Box<dyn Error>> {
if DEBUG {
println!("SENT>>> F: {}", format);
}
let mut result: Vec<u8> = Vec::new();
for character in format.into_bytes().into_iter() {
println!("{}", character);
}
Ok(Vec::new())
}