On travaille sur la sérialisation XML.
This commit is contained in:
@@ -20,6 +20,7 @@ pub mod ip_utils;
|
||||
pub use ip_utils::guess_local_ip;
|
||||
pub mod process;
|
||||
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.
|
||||
///
|
||||
@@ -52,3 +53,24 @@ pub fn get_os_string() -> String {
|
||||
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