On travaille sur la sérialisation XML.
This commit is contained in:
1
Cargo.lock
generated
1
Cargo.lock
generated
@@ -3433,6 +3433,7 @@ dependencies = [
|
|||||||
"get_if_addrs",
|
"get_if_addrs",
|
||||||
"netstat2",
|
"netstat2",
|
||||||
"os_info",
|
"os_info",
|
||||||
|
"quick-xml 0.38.4",
|
||||||
"sysinfo",
|
"sysinfo",
|
||||||
"users",
|
"users",
|
||||||
]
|
]
|
||||||
|
|||||||
@@ -9,3 +9,5 @@ os_info = "3.8"
|
|||||||
netstat2 = "0.11"
|
netstat2 = "0.11"
|
||||||
sysinfo = "0.30"
|
sysinfo = "0.30"
|
||||||
users = "0.11"
|
users = "0.11"
|
||||||
|
quick-xml = "0.38.3"
|
||||||
|
xmltree = "0.10"
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ pub mod ip_utils;
|
|||||||
pub use ip_utils::guess_local_ip;
|
pub use ip_utils::guess_local_ip;
|
||||||
pub mod process;
|
pub mod process;
|
||||||
pub use process::{ProcessPortInfo, TransportProtocol, find_process_using_port};
|
pub use process::{ProcessPortInfo, TransportProtocol, find_process_using_port};
|
||||||
|
use xmltree::{Element, EmitterConfig};
|
||||||
|
|
||||||
/// Retourne une chaîne décrivant le système d'exploitation et sa version.
|
/// Retourne une chaîne décrivant le système d'exploitation et sa version.
|
||||||
///
|
///
|
||||||
@@ -52,3 +53,24 @@ pub fn get_os_string() -> String {
|
|||||||
format!("{}/Unknown", os_type)
|
format!("{}/Unknown", os_type)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Trait générique pour obtenir un élément XML (xmltree::Element).
|
||||||
|
///
|
||||||
|
/// Aligné sur la signature utilisée dans pmoupnp (UpnpObject::to_xml_element),
|
||||||
|
/// afin de pouvoir factoriser la sérialisation XML entre crates.
|
||||||
|
pub trait ToXmlElement {
|
||||||
|
/// Convertit l'objet en élément XML.
|
||||||
|
fn to_xml_element(&self) -> Element;
|
||||||
|
|
||||||
|
/// Sérialise en chaîne XML formatée.
|
||||||
|
fn to_xml(&self) -> String {
|
||||||
|
let elem = self.to_xml_element();
|
||||||
|
let config = EmitterConfig::new()
|
||||||
|
.perform_indent(true)
|
||||||
|
.indent_string(" ");
|
||||||
|
let mut buf = Vec::new();
|
||||||
|
elem.write_with_config(&mut buf, config)
|
||||||
|
.expect("Failed to write XML");
|
||||||
|
String::from_utf8(buf).expect("Invalid UTF-8")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user