-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add debug options for resources-processes
- Loading branch information
Showing
4 changed files
with
179 additions
and
14 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,59 @@ | ||
use anyhow::Result; | ||
use process_data::ProcessData; | ||
use ron::ser::PrettyConfig; | ||
use std::io::{Read, Write}; | ||
|
||
use clap::Parser; | ||
|
||
#[derive(Parser, Debug)] | ||
#[command(version, about)] | ||
struct Args { | ||
/// Output once and then exit | ||
#[arg(short, long, default_value_t = false)] | ||
once: bool, | ||
|
||
/// Use Rusty Object Notation (use this only for debugging this binary on its own, Resources won't be able to decode RON) | ||
#[arg(short, long, default_value_t = false)] | ||
ron: bool, | ||
} | ||
|
||
fn main() -> Result<()> { | ||
let args = Args::parse(); | ||
|
||
if args.once { | ||
output(args.ron)?; | ||
return Ok(()); | ||
} | ||
|
||
loop { | ||
let mut buffer = [0; 1]; | ||
|
||
std::io::stdin().read_exact(&mut buffer)?; | ||
|
||
let data = ProcessData::all_process_data()?; | ||
let encoded = rmp_serde::encode::to_vec(&*data)?; | ||
output(args.ron)?; | ||
} | ||
} | ||
|
||
fn output(ron: bool) -> Result<()> { | ||
let data = ProcessData::all_process_data()?; | ||
|
||
let len_byte_array = encoded.len().to_le_bytes(); | ||
let encoded = if ron { | ||
ron::ser::to_string_pretty(&data, PrettyConfig::default())? | ||
.as_bytes() | ||
.to_vec() | ||
} else { | ||
rmp_serde::to_vec(&data)? | ||
}; | ||
|
||
let stdout = std::io::stdout(); | ||
let mut handle = stdout.lock(); | ||
let len_byte_array = encoded.len().to_le_bytes(); | ||
|
||
handle.write_all(&len_byte_array)?; | ||
let stdout = std::io::stdout(); | ||
let mut handle = stdout.lock(); | ||
|
||
handle.write_all(&encoded)?; | ||
handle.write_all(&len_byte_array)?; | ||
|
||
handle.flush()?; | ||
} | ||
handle.write_all(&encoded)?; | ||
|
||
handle.flush()?; | ||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters