use ::std::error::Error;
fn default_ip() -> String {
"127.0.0.1".to_string()
}
fn default_port() -> u32 {
6448
}
#[derive(::serde::Serialize, ::serde::Deserialize)]
pub(crate) struct Args {
#[serde(default = "default_ip")]
pub address: String,
#[serde(default = "default_port")]
pub port: u32,
}
impl Default for Args {
fn default() -> Self {
Self {
address: "127.0.0.1".to_string(),
port: 6448
}
}
}
pub(super) fn parse_args(args: *const std::ffi::c_char) -> Result<Args, Box<dyn Error>> {
let args_str = unsafe{std::ffi::CString::from_raw(args as *mut _)};
if args_str.is_empty() {
Ok(Args::default())
} else {
log::info!("inputflow_qmp received args: {args_str:?}");
Ok(ron::from_str(args_str.to_str()?)?)
}
}