//! For the parity check against upstream (tools/parity/links.py): JSON lines in, //! `{"url", "tag", "backend"}`, JSON lines out, `{"ok": outbound}` or `{"error": message}`. use std::io::{BufRead, Write}; use ps_core::links::{LinkBackend, build_outbound}; use serde_json::{Value, json}; fn main() { let stdout = std::io::stdout(); let mut out = stdout.lock(); for line in std::io::stdin().lock().lines() { let line = line.expect("stdin"); let req: Value = serde_json::from_str(&line).expect("a JSON request"); let backend = if req["backend"] == "xray" { LinkBackend::Xray } else { LinkBackend::SingBox }; let result = match build_outbound(req["url"].as_str().unwrap(), req["tag"].as_str().unwrap(), backend) { Ok(ob) => json!({ "ok": ob }), Err(e) => json!({ "error": e.to_string() }), }; writeln!(out, "{result}").unwrap(); } }