datex2 0.3.0

Unofficial DATEX II implementation in Rust: read, stream and write road traffic and travel information (v3 XML and JSON, including the Mobilithek AFIR profile) as typed data.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
// @generated by `cargo xtask codegen` from the DATEX II 3.7 schemas. Do not edit.
//! Types of the DATEX II namespace `http://datex2.eu/schema/3/locationExtension`.
//!
//! Names follow the standard; see <https://docs.datex2.eu/> for what each one means.

#[allow(unused_imports)]
use super::{common as com, common_extension as comx, location_referencing as loc, situation as sit, road_traffic_data as roa, vms, parking as prk, energy_infrastructure as egi, afir_energy_infrastructure as aegi, facilities as fac, afir_facilities as afac, traffic_regulation as tro, controlled_zone as cz, traffic_management_plan as tmp, rerouting_management_enhanced as rer, urban_extensions as ubx, fault_and_status as fst, message_container as con, exchange_information as ex, information_management as inf, cis_information as cis};
#[allow(unused_imports)]
use crate::out::{Out, Pattern, Rules};
#[allow(unused_imports)]
use crate::json::{JsonReader, JsonWriter};
#[allow(unused_imports)]
use crate::{ErrorKind, WarningKind};
#[allow(unused_imports)]
use crate::xml::{Enumeration, Xml};
#[allow(unused_imports)]
use crate::{Date, DateTime, Decimal, Error, Extension, MultilingualString, Time};

/// XML enumeration `locx:AddressLineTypeEnum`.
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum AddressLineTypeEnum {
    /// `apartment`
    Apartment,
    /// `building`
    Building,
    /// `poBox`
    PoBox,
    /// `unit`
    Unit,
    /// `region`
    Region,
    /// `town`
    Town,
    /// `districtTerritory`
    DistrictTerritory,
    /// `floor`
    Floor,
    /// `street`
    Street,
    /// `houseNumber`
    HouseNumber,
    /// `generalTextLine`
    GeneralTextLine,
    /// A value outside the standard list.
    Extended(String),
}

impl AddressLineTypeEnum {
    /// The value as written in a document.
    pub fn as_str(&self) -> &str {
        match self {
            Self::Apartment => "apartment",
            Self::Building => "building",
            Self::PoBox => "poBox",
            Self::Unit => "unit",
            Self::Region => "region",
            Self::Town => "town",
            Self::DistrictTerritory => "districtTerritory",
            Self::Floor => "floor",
            Self::Street => "street",
            Self::HouseNumber => "houseNumber",
            Self::GeneralTextLine => "generalTextLine",
            Self::Extended(v) => v,
        }
    }
}

impl Enumeration for AddressLineTypeEnum {
    fn from_literal(literal: &str) -> Option<Self> {
        match literal {
            "apartment" => Some(Self::Apartment),
            "building" => Some(Self::Building),
            "poBox" => Some(Self::PoBox),
            "unit" => Some(Self::Unit),
            "region" => Some(Self::Region),
            "town" => Some(Self::Town),
            "districtTerritory" => Some(Self::DistrictTerritory),
            "floor" => Some(Self::Floor),
            "street" => Some(Self::Street),
            "houseNumber" => Some(Self::HouseNumber),
            "generalTextLine" => Some(Self::GeneralTextLine),
            _ => None,
        }
    }

    fn extended(value: String) -> Self {
        Self::Extended(value)
    }
}

impl AddressLineTypeEnum {
    /// The literal to write and, for a value outside the standard list, that value.
    #[allow(unreachable_patterns)]
    pub(crate) fn literal(&self) -> (&str, Option<&str>) {
        match self {
            Self::Extended(v) => ("_extended", Some(v)),
            other => (other.as_str(), None),
        }
    }
}

/// XML enumeration `locx:HouseNumberSideEnum`.
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum HouseNumberSideEnum {
    /// `odd`
    Odd,
    /// `even`
    Even,
    /// A value outside the standard list.
    Extended(String),
}

impl HouseNumberSideEnum {
    /// The value as written in a document.
    pub fn as_str(&self) -> &str {
        match self {
            Self::Odd => "odd",
            Self::Even => "even",
            Self::Extended(v) => v,
        }
    }
}

impl Enumeration for HouseNumberSideEnum {
    fn from_literal(literal: &str) -> Option<Self> {
        match literal {
            "odd" => Some(Self::Odd),
            "even" => Some(Self::Even),
            _ => None,
        }
    }

    fn extended(value: String) -> Self {
        Self::Extended(value)
    }
}

impl HouseNumberSideEnum {
    /// The literal to write and, for a value outside the standard list, that value.
    #[allow(unreachable_patterns)]
    pub(crate) fn literal(&self) -> (&str, Option<&str>) {
        match self {
            Self::Extended(v) => ("_extended", Some(v)),
            other => (other.as_str(), None),
        }
    }
}

/// XML simple type `locx:NamedAreaCode`.
pub type NamedAreaCode = String;

/// XML type `locx:Address`.
#[derive(Debug, Clone, Default, PartialEq)]
pub struct Address {
    /// XML element `locx:postcode`.
    pub postcode: Option<String>,
    /// XML element `locx:city`.
    pub city: Option<MultilingualString>,
    /// XML element `locx:countryCode`.
    pub country_code: Option<com::CountryCode>,
    /// XML element `locx:addressLine`.
    pub address_line: Vec<AddressLine>,
    /// XML element `locx:_addressExtension`.
    pub address_extension: Option<Box<Extension>>,
}

impl Address {
    const FIELDS: &'static [u32] = &[0xd0a9d, 0xd0743, 0xd0777, 0xd06bd, 0xd041e];

    pub(crate) fn read(r: &mut Xml<'_>) -> Result<Self, Error> {
        r.expect_type(0xd0016);
        r.attrs_done();
        let mut e0 = None;
        let mut e1 = None;
        let mut e2 = None;
        let mut e3 = Vec::new();
        let mut e4 = None;
        while let Some(mut key) = r.next_child()? {
            loop {
                match key {
                    0xd0a9d => { let v = r.string()?; r.set(&mut e0, v, 2717); }
                    0xd0743 => { let v = r.multilingual()?; r.set(&mut e1, v, 1859); }
                    0xd0777 => { let v = r.string()?; r.set(&mut e2, v, 1911); }
                    0xd06bd => { let v = Some(AddressLine::read(r)?); e3.extend(v); }
                    0xd041e => { let v = r.raw()?; r.set(&mut e4, v.map(Box::new), 1054); }
                    _ => match r.fallback(key, Self::FIELDS) {
                        Some(k) => { key = k; continue; }
                        None => r.skip_unknown(key)?,
                    },
                }
                break;
            }
        }
        let v = Self {
            postcode: e0,
            city: e1,
            country_code: e2,
            address_line: e3,
            address_extension: e4,
        };
        r.close();
        Ok(v)
    }
}

impl Address {
    pub(crate) fn write(&self, w: &mut Out<'_>, tag: &'static str, kind: &'static str, fixed: &'static str) -> Result<(), Error> {
        w.begin(tag)?;
        w.constant_attrs(kind)?;
        w.constant_attrs(fixed)?;
        if let Some(v) = &self.postcode { w.max_len("postcode", "String", v, 1024)?; w.leaf("locx:postcode", v)?; }
        if let Some(v) = &self.city { w.multilingual("locx:city", v)?; }
        if let Some(v) = &self.country_code { w.max_len("countryCode", "CountryCode", v, 2)?; w.leaf("locx:countryCode", v)?; }
        for v in &self.address_line { v.write(w, "locx:addressLine", "", "")?; }
        if let Some(v) = &self.address_extension { w.extension("locx:_addressExtension", v)?; }
        w.end(tag)
    }
}

impl Address {
    pub(crate) fn read_json(r: &mut JsonReader<'_>) -> Result<Option<Self>, Error> {
        if !r.begin_object()? {
            return Ok(None);
        }
        Self::read_json_members(r, None).map(Some)
    }

    /// Reads the members of an object that is already open; `pending` is a member key read
    /// already.
    pub(crate) fn read_json_members(r: &mut JsonReader<'_>, mut pending: Option<u32>) -> Result<Self, Error> {
        let mut seen = [false; 5];
        let mut f0 = None;
        let mut f1 = None;
        let mut f2 = None;
        let mut f3 = Vec::new();
        let mut f4 = None;
        loop {
            let key = match pending.take() {
                Some(key) => key,
                None => match r.next_key()? {
                    Some(key) => key,
                    None => break,
                },
            };
            match key {
                1615 => if r.first(&mut seen[0])? { f0 = r.string()?; },
                337 => if r.first(&mut seen[1])? { f1 = r.multilingual()?; },
                469 => if r.first(&mut seen[2])? { f2 = r.string()?; },
                65 => if r.first(&mut seen[3])? { let mut l = r.list()?; while r.item(&mut l)? { if let Some(v) = AddressLine::read_json(r)? { f3.push(v); } } },
                1242 => if r.first(&mut seen[4])? { f4 = r.raw_object()?.map(Box::new); },
                _ => r.skip_unknown()?,
            }
        }
        Ok(Self {
            postcode: f0,
            city: f1,
            country_code: f2,
            address_line: f3,
            address_extension: f4,
        })
    }

    pub(crate) fn write_json(&self, w: &mut JsonWriter<'_>, target_class: Option<&'static str>) -> Result<(), Error> {
        w.begin_object(473)?;
        if let Some(class) = target_class {
            w.target_class(class)?;
        }
        if let Some(v) = &self.postcode {
            w.key(1615)?;
            w.max_len("postcode", "String", v, 1024)?; w.string(v)?;
        }
        if let Some(v) = &self.city {
            w.key(337)?;
            w.multilingual(v)?;
        }
        if let Some(v) = &self.country_code {
            w.key(469)?;
            w.max_len("countryCode", "CountryCode", v, 2)?; w.string(v)?;
        }
        if !self.address_line.is_empty() {
            w.key(65)?;
            w.begin_array()?;
            for v in &self.address_line {
                w.item()?;
                v.write_json(w, None)?;
            }
            w.end_array()?;
        }
        if let Some(v) = &self.address_extension {
            w.key(1242)?;
            w.extension(v)?;
        }
        w.end_object()
    }
}

/// XML type `locx:AddressLine`.
#[derive(Debug, Clone, Default, PartialEq)]
pub struct AddressLine {
    /// XML attribute `order`.
    pub order: Option<com::NonNegativeInteger>,
    /// XML element `locx:type`.
    pub r#type: Option<AddressLineTypeEnum>,
    /// XML element `locx:text`.
    pub text: Option<MultilingualString>,
    /// XML element `locx:_addressLineExtension`.
    pub address_line_extension: Option<Box<Extension>>,
}

impl AddressLine {
    const FIELDS: &'static [u32] = &[0xd0c5d, 0xd0c0b, 0xd041f];

    pub(crate) fn read(r: &mut Xml<'_>) -> Result<Self, Error> {
        r.expect_type(0xd0017);
        let a0 = r.req_attr_value::<u64>(2590)?;
        r.attrs_done();
        let mut e0 = None;
        let mut e1 = None;
        let mut e2 = None;
        while let Some(mut key) = r.next_child()? {
            loop {
                match key {
                    0xd0c5d => { let v = r.enumeration::<AddressLineTypeEnum>()?; r.set(&mut e0, v, 3165); }
                    0xd0c0b => { let v = r.multilingual()?; r.set(&mut e1, v, 3083); }
                    0xd041f => { let v = r.raw()?; r.set(&mut e2, v.map(Box::new), 1055); }
                    _ => match r.fallback(key, Self::FIELDS) {
                        Some(k) => { key = k; continue; }
                        None => r.skip_unknown(key)?,
                    },
                }
                break;
            }
        }
        r.required(&e0, 3165);
        r.required(&e1, 3083);
        let v = Self {
            order: a0,
            r#type: e0,
            text: e1,
            address_line_extension: e2,
        };
        r.close();
        Ok(v)
    }
}

impl AddressLine {
    pub(crate) fn write(&self, w: &mut Out<'_>, tag: &'static str, kind: &'static str, fixed: &'static str) -> Result<(), Error> {
        w.begin(tag)?;
        w.constant_attrs(kind)?;
        w.constant_attrs(fixed)?;
        match &self.order {
            Some(v) => { w.attr_value("order", v)?; }
            None => return Err(w.missing_attr("order")),
        }
        match &self.r#type {
            Some(v) => { w.enumeration("locx:type", v.literal())?; }
            None => return Err(w.missing("locx:type")),
        }
        match &self.text {
            Some(v) => { w.multilingual("locx:text", v)?; }
            None => return Err(w.missing("locx:text")),
        }
        if let Some(v) = &self.address_line_extension { w.extension("locx:_addressLineExtension", v)?; }
        w.end(tag)
    }
}

impl AddressLine {
    pub(crate) fn read_json(r: &mut JsonReader<'_>) -> Result<Option<Self>, Error> {
        if !r.begin_object()? {
            return Ok(None);
        }
        Self::read_json_members(r, None).map(Some)
    }

    /// Reads the members of an object that is already open; `pending` is a member key read
    /// already.
    pub(crate) fn read_json_members(r: &mut JsonReader<'_>, mut pending: Option<u32>) -> Result<Self, Error> {
        let mut seen = [false; 4];
        let mut f0 = None;
        let mut f1 = None;
        let mut f2 = None;
        let mut f3 = None;
        loop {
            let key = match pending.take() {
                Some(key) => key,
                None => match r.next_key()? {
                    Some(key) => key,
                    None => break,
                },
            };
            match key {
                1489 => if r.first(&mut seen[0])? { f0 = r.number::<u64>()?; },
                2495 => if r.first(&mut seen[1])? { f1 = r.enumeration::<AddressLineTypeEnum>()?; },
                2246 => if r.first(&mut seen[2])? { f2 = r.multilingual()?; },
                1243 => if r.first(&mut seen[3])? { f3 = r.raw_object()?.map(Box::new); },
                _ => r.skip_unknown()?,
            }
        }
        r.required(&f0, 1489);
        r.required(&f1, 2495);
        r.required(&f2, 2246);
        Ok(Self {
            order: f0,
            r#type: f1,
            text: f2,
            address_line_extension: f3,
        })
    }

    pub(crate) fn write_json(&self, w: &mut JsonWriter<'_>, target_class: Option<&'static str>) -> Result<(), Error> {
        w.begin_object(474)?;
        if let Some(class) = target_class {
            w.target_class(class)?;
        }
        match &self.order {
            Some(v) => {
                w.key(1489)?;
                w.integer(*v)?;
            }
            None => w.absent(1489, w.missing_attr("order"))?,
        }
        match &self.r#type {
            Some(v) => {
                w.key(2495)?;
                w.enumeration(475, v.literal())?;
            }
            None => w.absent(2495, w.missing("type"))?,
        }
        match &self.text {
            Some(v) => {
                w.key(2246)?;
                w.multilingual(v)?;
            }
            None => w.absent(2246, w.missing("text"))?,
        }
        if let Some(v) = &self.address_line_extension {
            w.key(1243)?;
            w.extension(v)?;
        }
        w.end_object()
    }
}

/// XML type `locx:FacilityLocation`.
#[derive(Debug, Clone, Default, PartialEq)]
pub struct FacilityLocation {
    /// XML element `locx:timeZone`.
    pub time_zone: Option<fac::TimeZone>,
    /// XML element `locx:address`.
    pub address: Option<Box<Address>>,
}

impl FacilityLocation {
    const FIELDS: &'static [u32] = &[0xd0c1c, 0xd06bc];

    pub(crate) fn read(r: &mut Xml<'_>) -> Result<Self, Error> {
        r.expect_type(0xd00b2);
        r.attrs_done();
        let mut e0 = None;
        let mut e1 = None;
        while let Some(mut key) = r.next_child()? {
            loop {
                match key {
                    0xd0c1c => { let v = r.string()?; r.set(&mut e0, v, 3100); }
                    0xd06bc => { let v = Some(Address::read(r)?); r.set(&mut e1, v.map(Box::new), 1724); }
                    _ => match r.fallback(key, Self::FIELDS) {
                        Some(k) => { key = k; continue; }
                        None => r.skip_unknown(key)?,
                    },
                }
                break;
            }
        }
        let v = Self {
            time_zone: e0,
            address: e1,
        };
        r.close();
        Ok(v)
    }
}

impl FacilityLocation {
    pub(crate) fn write(&self, w: &mut Out<'_>, tag: &'static str, kind: &'static str, fixed: &'static str) -> Result<(), Error> {
        w.begin(tag)?;
        w.constant_attrs(kind)?;
        w.constant_attrs(fixed)?;
        if let Some(v) = &self.time_zone { w.max_len("timeZone", "TimeZone", v, 1024)?; w.pattern("timeZone", "TimeZone", v, Pattern::TimeZone)?; w.leaf("locx:timeZone", v)?; }
        if let Some(v) = &self.address { v.write(w, "locx:address", "", "")?; }
        w.end(tag)
    }
}

impl FacilityLocation {
    pub(crate) fn read_json(r: &mut JsonReader<'_>) -> Result<Option<Self>, Error> {
        if !r.begin_object()? {
            return Ok(None);
        }
        Self::read_json_members(r, None).map(Some)
    }

    /// Reads the members of an object that is already open; `pending` is a member key read
    /// already.
    pub(crate) fn read_json_members(r: &mut JsonReader<'_>, mut pending: Option<u32>) -> Result<Self, Error> {
        let mut seen = [false; 2];
        let mut f0 = None;
        let mut f1 = None;
        loop {
            let key = match pending.take() {
                Some(key) => key,
                None => match r.next_key()? {
                    Some(key) => key,
                    None => break,
                },
            };
            match key {
                2263 => if r.first(&mut seen[0])? { f0 = r.string()?; },
                64 => if r.first(&mut seen[1])? { f1 = Address::read_json(r)?.map(Box::new); },
                _ => r.skip_unknown()?,
            }
        }
        Ok(Self {
            time_zone: f0,
            address: f1,
        })
    }

    pub(crate) fn write_json(&self, w: &mut JsonWriter<'_>, target_class: Option<&'static str>) -> Result<(), Error> {
        w.begin_object(476)?;
        if let Some(class) = target_class {
            w.target_class(class)?;
        }
        if let Some(v) = &self.time_zone {
            w.key(2263)?;
            w.max_len("timeZone", "TimeZone", v, 1024)?; w.pattern("timeZone", "TimeZone", v, Pattern::TimeZone)?; w.string(v)?;
        }
        if let Some(v) = &self.address {
            w.key(64)?;
            v.write_json(w, None)?;
        }
        w.end_object()
    }
}

/// XML type `locx:NamedAreaExtended`.
#[derive(Debug, Clone, Default, PartialEq)]
pub struct NamedAreaExtended {
    /// XML element `locx:namedAreaCode`.
    pub named_area_code: Option<NamedAreaCode>,
}

impl NamedAreaExtended {
    const FIELDS: &'static [u32] = &[0xd098e];

    pub(crate) fn read(r: &mut Xml<'_>) -> Result<Self, Error> {
        r.expect_type(0xd011d);
        r.attrs_done();
        let mut e0 = None;
        while let Some(mut key) = r.next_child()? {
            loop {
                match key {
                    0xd098e => { let v = r.string()?; r.set(&mut e0, v, 2446); }
                    _ => match r.fallback(key, Self::FIELDS) {
                        Some(k) => { key = k; continue; }
                        None => r.skip_unknown(key)?,
                    },
                }
                break;
            }
        }
        r.required(&e0, 2446);
        let v = Self {
            named_area_code: e0,
        };
        r.close();
        Ok(v)
    }
}

impl NamedAreaExtended {
    pub(crate) fn write(&self, w: &mut Out<'_>, tag: &'static str, kind: &'static str, fixed: &'static str) -> Result<(), Error> {
        w.begin(tag)?;
        w.constant_attrs(kind)?;
        w.constant_attrs(fixed)?;
        match &self.named_area_code {
            Some(v) => { w.max_len("namedAreaCode", "NamedAreaCode", v, 8)?; w.leaf("locx:namedAreaCode", v)?; }
            None => return Err(w.missing("locx:namedAreaCode")),
        }
        w.end(tag)
    }
}

impl NamedAreaExtended {
    pub(crate) fn read_json(r: &mut JsonReader<'_>) -> Result<Option<Self>, Error> {
        if !r.begin_object()? {
            return Ok(None);
        }
        Self::read_json_members(r, None).map(Some)
    }

    /// Reads the members of an object that is already open; `pending` is a member key read
    /// already.
    pub(crate) fn read_json_members(r: &mut JsonReader<'_>, mut pending: Option<u32>) -> Result<Self, Error> {
        let mut seen = [false; 1];
        let mut f0 = None;
        loop {
            let key = match pending.take() {
                Some(key) => key,
                None => match r.next_key()? {
                    Some(key) => key,
                    None => break,
                },
            };
            match key {
                1348 => if r.first(&mut seen[0])? { f0 = r.string()?; },
                _ => r.skip_unknown()?,
            }
        }
        r.required(&f0, 1348);
        Ok(Self {
            named_area_code: f0,
        })
    }

    pub(crate) fn write_json(&self, w: &mut JsonWriter<'_>, target_class: Option<&'static str>) -> Result<(), Error> {
        w.begin_object(478)?;
        if let Some(class) = target_class {
            w.target_class(class)?;
        }
        match &self.named_area_code {
            Some(v) => {
                w.key(1348)?;
                w.max_len("namedAreaCode", "NamedAreaCode", v, 8)?; w.string(v)?;
            }
            None => w.absent(1348, w.missing("namedAreaCode"))?,
        }
        w.end_object()
    }
}

/// XML type `locx:SupplementaryPositionalDescriptionExtended`.
#[derive(Debug, Clone, Default, PartialEq)]
pub struct SupplementaryPositionalDescriptionExtended {
    /// XML element `locx:houseNumberSide`.
    pub house_number_side: Option<HouseNumberSideEnum>,
}

impl SupplementaryPositionalDescriptionExtended {
    const FIELDS: &'static [u32] = &[0xd08a3];

    pub(crate) fn read(r: &mut Xml<'_>) -> Result<Self, Error> {
        r.expect_type(0xd0214);
        r.attrs_done();
        let mut e0 = None;
        while let Some(mut key) = r.next_child()? {
            loop {
                match key {
                    0xd08a3 => { let v = r.enumeration::<HouseNumberSideEnum>()?; r.set(&mut e0, v, 2211); }
                    _ => match r.fallback(key, Self::FIELDS) {
                        Some(k) => { key = k; continue; }
                        None => r.skip_unknown(key)?,
                    },
                }
                break;
            }
        }
        let v = Self {
            house_number_side: e0,
        };
        r.close();
        Ok(v)
    }
}

impl SupplementaryPositionalDescriptionExtended {
    pub(crate) fn write(&self, w: &mut Out<'_>, tag: &'static str, kind: &'static str, fixed: &'static str) -> Result<(), Error> {
        w.begin(tag)?;
        w.constant_attrs(kind)?;
        w.constant_attrs(fixed)?;
        if let Some(v) = &self.house_number_side { w.enumeration("locx:houseNumberSide", v.literal())?; }
        w.end(tag)
    }
}

impl SupplementaryPositionalDescriptionExtended {
    pub(crate) fn read_json(r: &mut JsonReader<'_>) -> Result<Option<Self>, Error> {
        if !r.begin_object()? {
            return Ok(None);
        }
        Self::read_json_members(r, None).map(Some)
    }

    /// Reads the members of an object that is already open; `pending` is a member key read
    /// already.
    pub(crate) fn read_json_members(r: &mut JsonReader<'_>, mut pending: Option<u32>) -> Result<Self, Error> {
        let mut seen = [false; 1];
        let mut f0 = None;
        loop {
            let key = match pending.take() {
                Some(key) => key,
                None => match r.next_key()? {
                    Some(key) => key,
                    None => break,
                },
            };
            match key {
                956 => if r.first(&mut seen[0])? { f0 = r.enumeration::<HouseNumberSideEnum>()?; },
                _ => r.skip_unknown()?,
            }
        }
        Ok(Self {
            house_number_side: f0,
        })
    }

    pub(crate) fn write_json(&self, w: &mut JsonWriter<'_>, target_class: Option<&'static str>) -> Result<(), Error> {
        w.begin_object(479)?;
        if let Some(class) = target_class {
            w.target_class(class)?;
        }
        if let Some(v) = &self.house_number_side {
            w.key(956)?;
            w.enumeration(477, v.literal())?;
        }
        w.end_object()
    }
}