Skip to main content

zerodds_web/
representation.rs

1// SPDX-License-Identifier: Apache-2.0
2// Copyright 2026 ZeroDDS Contributors
3
4//! XML Object-Representation Tags — Spec §8.3.4 Tab 6.
5
6/// Spec §8.3.5 — Content-Type fuer alle WebDDS-REST-Bodies.
7pub const CONTENT_TYPE_DDS_WEB_XML: &str = "application/zerodds-web+xml";
8
9/// Spec §8.3.4 Tab 6 — Object-Representation-Kategorien.
10#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
11pub enum RepresentationKind {
12    /// Single object (e.g., `<application>`).
13    Object,
14    /// List of objects (e.g., `<application_list>`).
15    List,
16}
17
18/// Wire-Element-Name fuer ein Object/List Tab 6 (Spec §8.3.4).
19#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
20pub enum ContentType {
21    /// `qos_library` / `qos_library_list`.
22    QosLibrary,
23    /// `qos_profile` / `qos_profile_list`.
24    QosProfile,
25    /// `application` / `application_list`.
26    Application,
27    /// `domain_participant` / `domain_participant_list`.
28    DomainParticipant,
29    /// `types` (XML-Type-Definition aus DDS-XTYPES).
30    Types,
31    /// `waitset` / `waitset_list`.
32    Waitset,
33    /// `topic` / `topic_list`.
34    Topic,
35    /// `publisher` / `publisher_list`.
36    Publisher,
37    /// `subscriber` / `subscriber_list`.
38    Subscriber,
39    /// `data_writer` / `data_writer_list`.
40    DataWriter,
41    /// `data_reader` / `data_reader_list`.
42    DataReader,
43    /// `read_sample_seq` (DataReader::read).
44    ReadSampleSeq,
45    /// `write_sample_seq` (DataWriter::write).
46    WriteSampleSeq,
47}
48
49/// Liefert das XML-Element-Name aus Spec §8.3.4 Tab 6.
50#[must_use]
51pub const fn element_name(kind: ContentType, repr: RepresentationKind) -> &'static str {
52    use RepresentationKind::*;
53    match (kind, repr) {
54        (ContentType::QosLibrary, Object) => "qos_library",
55        (ContentType::QosLibrary, List) => "qos_library_list",
56        (ContentType::QosProfile, Object) => "qos_profile",
57        (ContentType::QosProfile, List) => "qos_profile_list",
58        (ContentType::Application, Object) => "application",
59        (ContentType::Application, List) => "application_list",
60        (ContentType::DomainParticipant, Object) => "domain_participant",
61        (ContentType::DomainParticipant, List) => "domain_participant_list",
62        (ContentType::Types, _) => "types",
63        (ContentType::Waitset, Object) => "waitset",
64        (ContentType::Waitset, List) => "waitset_list",
65        (ContentType::Topic, Object) => "topic",
66        (ContentType::Topic, List) => "topic_list",
67        (ContentType::Publisher, Object) => "publisher",
68        (ContentType::Publisher, List) => "publisher_list",
69        (ContentType::Subscriber, Object) => "subscriber",
70        (ContentType::Subscriber, List) => "subscriber_list",
71        (ContentType::DataWriter, Object) => "data_writer",
72        (ContentType::DataWriter, List) => "data_writer_list",
73        (ContentType::DataReader, Object) => "data_reader",
74        (ContentType::DataReader, List) => "data_reader_list",
75        (ContentType::ReadSampleSeq, _) => "read_sample_seq",
76        (ContentType::WriteSampleSeq, _) => "write_sample_seq",
77    }
78}
79
80#[cfg(test)]
81mod tests {
82    use super::*;
83
84    #[test]
85    fn content_type_constant() {
86        // Spec §8.3.5 Tab 7+8.
87        assert_eq!(CONTENT_TYPE_DDS_WEB_XML, "application/zerodds-web+xml");
88    }
89
90    #[test]
91    fn element_names_match_spec_tab_6() {
92        use ContentType as C;
93        use RepresentationKind::{List, Object};
94        // Spec §8.3.4 Tab 6 — Object + List Names.
95        assert_eq!(element_name(C::QosLibrary, Object), "qos_library");
96        assert_eq!(element_name(C::QosLibrary, List), "qos_library_list");
97        assert_eq!(element_name(C::QosProfile, Object), "qos_profile");
98        assert_eq!(element_name(C::QosProfile, List), "qos_profile_list");
99        assert_eq!(element_name(C::Application, Object), "application");
100        assert_eq!(element_name(C::Application, List), "application_list");
101        assert_eq!(
102            element_name(C::DomainParticipant, Object),
103            "domain_participant"
104        );
105        assert_eq!(
106            element_name(C::DomainParticipant, List),
107            "domain_participant_list"
108        );
109        assert_eq!(element_name(C::Waitset, Object), "waitset");
110        assert_eq!(element_name(C::Topic, Object), "topic");
111        assert_eq!(element_name(C::Publisher, Object), "publisher");
112        assert_eq!(element_name(C::Subscriber, Object), "subscriber");
113        assert_eq!(element_name(C::DataWriter, Object), "data_writer");
114        assert_eq!(element_name(C::DataReader, Object), "data_reader");
115        assert_eq!(element_name(C::ReadSampleSeq, Object), "read_sample_seq");
116        assert_eq!(element_name(C::WriteSampleSeq, Object), "write_sample_seq");
117    }
118
119    #[test]
120    fn types_representation_uses_dds_xtypes_root() {
121        // Spec — types-XML wird via DDS-XTYPES Root-Element representiert.
122        assert_eq!(
123            element_name(ContentType::Types, RepresentationKind::Object),
124            "types"
125        );
126        assert_eq!(
127            element_name(ContentType::Types, RepresentationKind::List),
128            "types"
129        );
130    }
131}