#serialization #xml #deserialize #serde #de #namespaces #structs

xml_serde

使用 Serde 的命名空间感知 XML (反)序列化器

11 个稳定版本

1.4.1 2022 年 9 月 1 日
1.4.0 2022 年 3 月 11 日
1.3.0 2022 年 2 月 23 日
1.1.3 2022 年 1 月 5 日
1.0.1 2021 年 10 月 19 日

#1022编码

Download history 48/week @ 2024-03-24 45/week @ 2024-03-31 74/week @ 2024-04-07 64/week @ 2024-04-14 41/week @ 2024-04-21 73/week @ 2024-04-28 21/week @ 2024-05-05 22/week @ 2024-05-12 23/week @ 2024-05-19 19/week @ 2024-05-26 75/week @ 2024-06-02 33/week @ 2024-06-09 30/week @ 2024-06-16 24/week @ 2024-06-23 3/week @ 2024-06-30 3/week @ 2024-07-07

62 每月下载量
3 crates 中使用

MIT 许可协议

71KB
1.5K SLoC

使用 Serde 的 Rust 命名空间感知 XML (反)序列化器

// XML elements can be specified with structs
#[derive(Debug, Serialize, Deserialize)]
pub struct BulkObservable {
    // Required attributes can easily be defined, with the format of {namespace}ns-prefix:element
    #[serde(rename = "{urn:ietf:params:xml:ns:iodef-2.0}iodef:BulkObservableList")]
    pub list: String,

    // Repeated and optional elements can be defined with Vec and Option
    #[serde(rename = "{urn:ietf:params:xml:ns:iodef-2.0}iodef:AdditionalData", default, skip_serializing_if="Vec::is_empty")]
    pub additional_data: Vec<ExtensionType>,
    #[serde(rename = "{urn:ietf:params:xml:ns:iodef-2.0}iodef:BulkObservableFormat", default, skip_serializing_if="Option::is_none")]
    pub format: Option<BulkObservableFormat>,

    // Element attributes can be specified with the $attr: prefix
    #[serde(rename = "$attr:type")]
    pub bulk_type: BulkObservableType,
    #[serde(rename = "$attr:ext-type", default, skip_serializing_if="Option::is_none")]
    pub bulk_ext_type: Option<String>,

    // Textual element content can be set with the special name $value
    #[serde(rename = "$value")]
    pub value: f64,
}

// Enumerated values can also be defined
#[derive(Debug, Serialize, Deserialize)]
pub enum ConfidenceRating {
    #[serde(rename = "low")]
    Low,
    #[serde(rename = "medium")]
    Medium,
    #[serde(rename = "high")]
    High,
    #[serde(rename = "numeric")]
    Numeric,
    #[serde(rename = "unknown")]
    Unknown
}

// As can enumerated objects
#[derive(Debug, Serialize, Deserialize)]
pub enum IndicatorExpressionInner {
    #[serde(rename = "{urn:ietf:params:xml:ns:iodef-2.0}IndicatorExpression")]
    IndicatorExpression(IndicatorExpression),
    #[serde(rename = "{urn:ietf:params:xml:ns:iodef-2.0}Observable")]
    Observable(Observable),
    #[serde(rename = "{urn:ietf:params:xml:ns:iodef-2.0}ObservableReference")]
    ObservableReference(ObservableReference),
    #[serde(rename = "{urn:ietf:params:xml:ns:iodef-2.0}IndicatorReference")]
    IndicatorReference(IndicatorReference),
    #[serde(rename = "{urn:ietf:params:xml:ns:iodef-2.0}AdditionalData")]
    AdditionalData(ExtensionType),
}

依赖关系

~4–13MB
~139K SLoC