fn send_json_data<T: Write, U: Debug>(
    args: &Option<Vec<String>>,
    mut stream: T,
    global_vars: &GlobalVars,
    runtime_vars: &RuntimeVars,
    first_time: bool,
    addr: U,
) -> AppResult<Option<ChildData>> {
    // create a dedicated JSON structure
    let mut json = match args {
        Some(args) => {
            if first_time {
                json!({
                    "args": &args,
                    "global": global_vars,
                    "vars": runtime_vars
                })
            } else {
                json!({
                    //"args": &args,
                    "vars": runtime_vars
                })
            }
        }
        None => {
            if first_time {
                json!({
                    "global": global_vars,
                    "vars": runtime_vars
                })
            } else {
                json!({ "vars": runtime_vars })
            }
        }
    }
    .to_string();

    // 64KB a payload is more than enough
    json.truncate(u16::MAX as usize);
    let json_raw = json.as_bytes();

    // send data length first in network order, and then send payload
    let size = u16::try_from(json_raw.len())
        .unwrap_or_else(|_| panic!("unexpected conversion error at {}-{}", file!(), line!()));

    stream.write(&size.to_be_bytes()).map_err(|e| {
        context!(
            e,
            "error writing payload size: {} to address: {:?}",
            size,
            addr
        )
    })?;
    stream
        .write(&json.as_bytes())
        .map_err(|e| context!(e, "error writing JSON data to Domain socket: {:?}", addr))?;

    Ok(None)
}
// send data through Tcp or Unix stream
send data through Tcp or Unix stream
send data through Tcp or Unix stream
fn send_json_data<T: Write, U: Debug>(
    args: &Option<Vec<String>>,
    mut stream: T,
    global_vars: &GlobalVars,
    runtime_vars: &RuntimeVars,
    first_time: bool,
    addr: U,
) -> AppResult<Option<ChildData>> {
    // create a dedicated JSON structure
    let mut json = match args {
        Some(args) => {
            if first_time {
                json!({
                    "args": &args,
                    "global": global_vars,
                    "vars": runtime_vars
                })
            } else {
                json!({
                    //"args": &args,
                    "vars": runtime_vars
                })
            }
        }
        None => {
            if first_time {
                json!({
                    "global": global_vars,
                    "vars": runtime_vars
                })
            } else {
                json!({ "vars": runtime_vars })
            }
        }
    }
    .to_string();
    // 64KB a payload is more than enough
    json.truncate(u16::MAX as usize);
    let json_raw = json.as_bytes();
    // send data length first in network order, and then send payload
    let size = u16::try_from(json_raw.len())
        .unwrap_or_else(|_| panic!("unexpected conversion error at {}-{}", file!(), line!()));
    stream.write(&size.to_be_bytes()).map_err(|e| {
        context!(
            e,
            "error writing payload size: {} to address: {:?}",
            size,
            addr
        )
    })?;
    stream
        .write(&json.as_bytes())
        .map_err(|e| context!(e, "error writing JSON data to Domain socket: {:?}", addr))?;
    Ok(None)
}
fn send_json_data < T : Write , U : Debug > ( args : & Option < Vec < String > > , mut stream : T , global_vars : & GlobalVars , runtime_vars : & RuntimeVars , first_time : bool , addr : U , ) -> AppResult < Option < ChildData > > { // create a dedicated JSON structure let mut json = match args { Some ( args ) => { if first_time { json ! ( { " " args " " global_vars " " runtime_vars } ) } else { json ! ( { //"args": &args, " " runtime_vars } ) } } None => { if first_time { json ! ( { " " global_vars " " runtime_vars } ) } else { json ! ( { " " runtime_vars } ) } } } . to_string ( ) ; // 64KB a payload is more than enough json . truncate ( u16 :: MAX as usize ) ; let json_raw = json . as_bytes ( ) ; // send data length first in network order, and then send payload let size = u16 :: try_from ( json_raw . len ( ) ) . unwrap_or_else ( | _ | panic ! ( " " file ( ) line ( ) ) ) ; stream . write ( & size . to_be_bytes ( ) ) . map_err ( | e | { context ! ( e " " size addr ) } ) ? ; stream . write ( & json . as_bytes ( ) ) . map_err ( | e | context ! ( e " " addr ) ) ? ; Ok ( None ) }
send data through Tcp or Unix stream
send data through Tcp or Unix stream
args
&Option<Vec<String>>
stream
T
global_vars
&GlobalVars
runtime_vars
&RuntimeVars
first_time
bool
addr
U
args
&Option<Vec<String>>
stream
T
global_vars
&GlobalVars
runtime_vars
&RuntimeVars
first_time
bool
addr
U