Skip to main content

xml_disassembler/
types.rs

1//! Type definitions for XML element representation.
2//!
3//! Uses serde_json::Value for flexible representation matching the TypeScript structure:
4//! - Object with keys: element names, @attr for attributes, #text for text content, ?xml for declaration
5//! - Values: string, nested object, or array of objects/strings
6
7use serde_json::Value as JsonValue;
8
9/// XmlElement is a flexible representation of XML - equivalent to TypeScript's XmlElement type.
10/// Uses serde_json::Value for compatibility with quickxml_to_serde output.
11pub type XmlElement = JsonValue;
12
13/// Parameters for parsing an element during disassembly.
14#[derive(Debug, Clone)]
15pub struct XmlElementParams<'a> {
16    pub element: XmlElement,
17    pub disassembled_path: &'a str,
18    pub unique_id_elements: Option<&'a str>,
19    pub root_element_name: &'a str,
20    pub root_attributes: XmlElement,
21    pub key: &'a str,
22    pub leaf_content: XmlElement,
23    pub leaf_count: usize,
24    pub has_nested_elements: bool,
25    pub format: &'a str,
26    pub xml_declaration: Option<XmlElement>,
27    pub strategy: &'a str,
28}
29
30/// Options for building a single disassembled file.
31#[derive(Debug, Clone)]
32pub struct BuildDisassembledFileOptions<'a> {
33    pub content: XmlElement,
34    pub disassembled_path: &'a str,
35    pub output_file_name: Option<&'a str>,
36    pub subdirectory: Option<&'a str>,
37    pub wrap_key: Option<&'a str>,
38    pub is_grouped_array: bool,
39    pub root_element_name: &'a str,
40    pub root_attributes: XmlElement,
41    pub format: &'a str,
42    pub xml_declaration: Option<XmlElement>,
43    pub unique_id_elements: Option<&'a str>,
44}
45
46/// Result from unified element parsing.
47#[derive(Debug, Clone, Default)]
48pub struct UnifiedParseResult {
49    pub leaf_content: XmlElement,
50    pub leaf_count: usize,
51    pub has_nested_elements: bool,
52    pub nested_groups: Option<XmlElementArrayMap>,
53}
54
55/// Map of tag name to array of elements.
56pub type XmlElementArrayMap = std::collections::HashMap<String, Vec<XmlElement>>;
57
58/// Options for building disassembled files from a source file.
59#[derive(Debug, Clone)]
60pub struct BuildDisassembledFilesOptions<'a> {
61    pub file_path: &'a str,
62    pub disassembled_path: &'a str,
63    pub base_name: &'a str,
64    pub post_purge: bool,
65    pub format: &'a str,
66    pub unique_id_elements: Option<&'a str>,
67    pub strategy: &'a str,
68}
69
70/// Parameters for writing leaf content.
71#[derive(Debug, Clone)]
72pub struct LeafWriteParams<'a> {
73    pub leaf_count: usize,
74    pub leaf_content: XmlElement,
75    pub strategy: &'a str,
76    pub key_order: Vec<String>,
77    pub options: LeafWriteOptions<'a>,
78}
79
80#[derive(Debug, Clone)]
81pub struct LeafWriteOptions<'a> {
82    pub disassembled_path: &'a str,
83    pub output_file_name: &'a str,
84    pub root_element_name: &'a str,
85    pub root_attributes: XmlElement,
86    pub xml_declaration: Option<XmlElement>,
87    pub format: &'a str,
88}