ridl-backend-rust 0.2.0

Compiles a RIDL IR package to Rust source, plus the generated interaction face.
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
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
---
source: crates/ridl-backend-rust/src/tests.rs
expression: rust_for(decls)
---
/// Vehicle speed over ground
///
/// Quantization (`step`) is not checked by `new`.
#[derive(Debug, Clone, Copy, PartialEq, PartialOrd)]
#[repr(transparent)]
pub struct Speed(f64);
impl Speed {
    /// Constructs the value, enforcing its typl constraints.
    pub fn new(
        value: f64,
    ) -> ::core::result::Result<Self, ::ridl_rt::payload::Violation> {
        Self::check(&value)?;
        ::core::result::Result::Ok(Self::new_unchecked(value))
    }
    /// Checks `value` against this type's typl constraints, without
    /// constructing it. `pub(crate)` rather than `pub`: a caller
    /// outside `new` is a function generated into this crate — since
    /// driftsys/ridl#467 that includes the codec of *another* package
    /// of the same build, which reaches this type through the module
    /// tree and so cannot see a private item here. The emitted crate
    /// is one crate per build, so `pub(crate)` reaches every such
    /// caller while adding nothing to the crate's public surface.
    /// Whether this becomes `pub` is Epic 10's call, still open.
    /// `new` is the composition of this and `new_unchecked`.
    pub(crate) fn check(
        value: &f64,
    ) -> ::core::result::Result<(), ::ridl_rt::payload::Violation> {
        let value = *value;
        if value < 0.0 {
            return ::core::result::Result::Err(::ridl_rt::payload::Violation {
                type_name: "Speed",
                rule: ::ridl_rt::payload::Rule::Range,
            });
        }
        if value > 250.0 {
            return ::core::result::Result::Err(::ridl_rt::payload::Violation {
                type_name: "Speed",
                rule: ::ridl_rt::payload::Rule::Range,
            });
        }
        ::core::result::Result::Ok(())
    }
    /// Constructs the value without checking its constraints.
    ///
    /// Safe: nothing here relies on the invariant for memory
    /// soundness. Use it only for a value already known to satisfy
    /// the contract.
    pub const fn new_unchecked(value: f64) -> Self {
        Self(value)
    }
    pub const fn get(self) -> f64 {
        self.0
    }
}
impl ::core::convert::TryFrom<f64> for Speed {
    type Error = ::ridl_rt::payload::Violation;
    fn try_from(value: f64) -> ::core::result::Result<Self, Self::Error> {
        Self::new(value)
    }
}
impl ::core::convert::From<Speed> for f64 {
    fn from(value: Speed) -> Self {
        value.0
    }
}
impl Default for Speed {
    fn default() -> Self {
        Speed::new_unchecked(0.0)
    }
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord)]
#[repr(transparent)]
pub struct Counter(i64);
impl Counter {
    /// Constructs the value. This type declares no constraint, so
    /// construction cannot fail.
    pub const fn new(value: i64) -> Self {
        Self(value)
    }
    pub const fn get(self) -> i64 {
        self.0
    }
}
impl ::core::convert::From<i64> for Counter {
    fn from(value: i64) -> Self {
        Self(value)
    }
}
impl ::core::convert::From<Counter> for i64 {
    fn from(value: Counter) -> Self {
        value.0
    }
}
impl Default for Counter {
    fn default() -> Self {
        Counter::new(0)
    }
}
#[derive(Debug, Clone, Copy, PartialEq)]
#[repr(C)]
pub struct SensorReading {
    pub value: Speed,
}
impl Default for SensorReading {
    fn default() -> Self {
        SensorReading {
            value: Speed::default(),
        }
    }
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[repr(C)]
pub struct SensorFault {
    pub code: Counter,
}
impl Default for SensorFault {
    fn default() -> Self {
        SensorFault {
            code: Counter::default(),
        }
    }
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub enum SensorResult {
    /// Successful reading
    Ok(SensorReading),
    Err(SensorFault),
}
impl Default for SensorResult {
    fn default() -> Self {
        SensorResult::Ok(SensorReading::default())
    }
}
/// An accessor over FlatBuffers bytes `Speed`'s `verify` accepted.
///
/// The buffer's root is the box table ADR-0019 decision 8
/// gives this declaration: one required `value` field. A
/// buffer carrying no slot for it is `MissingRequired`.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[allow(deprecated)]
pub struct SpeedFbView<'a> {
    pub(crate) buf: &'a [u8],
    pub(crate) table: usize,
}
#[allow(deprecated)]
impl<'a> SpeedFbView<'a> {
    /// The verified bytes this view reads.
    pub fn bytes(&self) -> &'a [u8] {
        self.buf
    }
    /// The value the box carries. `Speed` is one value, so this decodes it rather than borrowing it, which costs one read.
    pub fn value(&self) -> Speed {
        __ridl_fb_decode_speed(self.buf, self.table)
    }
}
/// Writes `Speed` as its box table and returns its position (ADR-0019 decision 8).
#[allow(deprecated)]
pub(crate) fn __ridl_fb_encode_speed(
    value: &Speed,
    builder: &mut ::ridl_rt::flatbuffers::Builder<'_>,
) -> ::core::result::Result<
    ::ridl_rt::flatbuffers::Pos,
    ::ridl_rt::payload::EncodeError,
> {
    ::core::result::Result::Ok({
        let __box = [
            ::ridl_rt::flatbuffers::TableField {
                slot: 0u16,
                offset: 4u16,
                value: {
                    let __s = *value;
                    ::ridl_rt::flatbuffers::Field::F32(__s.get() as f32)
                },
            },
        ];
        builder.push_table(8usize, 4usize, 1u16, &__box)?
    })
}
#[allow(deprecated)]
pub(crate) fn __ridl_fb_verify_speed(
    buf: &[u8],
    table: usize,
) -> ::core::result::Result<(), ::ridl_rt::payload::VerifyError> {
    match ::ridl_rt::flatbuffers::field(buf, table, 0u16, 4usize)
        .map_err(::ridl_rt::payload::VerifyError::Structure)?
    {
        ::core::option::Option::Some(__p) => {
            let __raw = ::ridl_rt::flatbuffers::read_f32(buf, __p)
                .map_err(::ridl_rt::payload::VerifyError::Structure)?;
            Speed::check(&(f64::from(__raw)))
                .map_err(::ridl_rt::payload::VerifyError::Contract)?;
        }
        ::core::option::Option::None => {
            return ::core::result::Result::Err(
                ::ridl_rt::payload::VerifyError::Structure(
                    ::ridl_rt::payload::Malformed::MissingRequired,
                ),
            );
        }
    }
    ::core::result::Result::Ok(())
}
#[allow(deprecated)]
pub(crate) fn __ridl_fb_decode_speed(buf: &[u8], table: usize) -> Speed {
    {
        let __p = ::ridl_rt::flatbuffers::field(buf, table, 0u16, 4usize)
            .unwrap_or(::core::option::Option::None)
            .unwrap_or(0usize);
        Speed::new_unchecked(
            f64::from(::ridl_rt::flatbuffers::read_f32(buf, __p).unwrap_or(0.0f32)),
        )
    }
}
#[allow(deprecated)]
impl ::ridl_rt::payload::Payload<::ridl_rt::encoding::FlatBuffers> for Speed {
    /// The largest FlatBuffers buffer any legal `Speed` encodes to: 46 bytes.
    ///
    /// `ridl_ir::projection::flatbuffers::max_size` computed it,
    /// which is the one implementation of the bound (design note
    /// D-6): each table is charged its `soffset`, its inline
    /// fields, its vtable and one alignment event per slot; a
    /// string four bytes per declared character plus a
    /// terminator; a collection its declared maximum. It is a
    /// literal rather than an expression over the field types
    /// because that slack is not expressible in Rust's type
    /// system.
    const MAX_SIZE: usize = 46usize;
    type View<'a> = SpeedFbView<'a>;
    fn encode<'o>(
        &self,
        out: &'o mut [u8],
    ) -> ::core::result::Result<
        ::ridl_rt::payload::Encoded<'o, Self::View<'o>>,
        ::ridl_rt::payload::EncodeError,
    > {
        let mut builder = ::ridl_rt::flatbuffers::Builder::new(out);
        let __root = __ridl_fb_encode_speed(self, &mut builder)?;
        let bytes = builder.finish(__root, 8usize)?;
        let table = ::ridl_rt::flatbuffers::root(bytes).unwrap_or(0usize);
        ::core::result::Result::Ok(::ridl_rt::payload::Encoded {
            bytes,
            view: SpeedFbView { buf: bytes, table },
        })
    }
    fn verify(
        buf: &[u8],
    ) -> ::core::result::Result<Self::View<'_>, ::ridl_rt::payload::VerifyError> {
        if buf.len()
            > <Self as ::ridl_rt::payload::Payload<
                ::ridl_rt::encoding::FlatBuffers,
            >>::MAX_SIZE
        {
            return ::core::result::Result::Err(
                ::ridl_rt::payload::VerifyError::Structure(
                    ::ridl_rt::payload::Malformed::TooLarge,
                ),
            );
        }
        let table = ::ridl_rt::flatbuffers::root(buf)
            .map_err(::ridl_rt::payload::VerifyError::Structure)?;
        __ridl_fb_verify_speed(buf, table)?;
        ::core::result::Result::Ok(SpeedFbView { buf, table })
    }
    fn decode(
        r: ::ridl_rt::payload::Ref<'_, Self, ::ridl_rt::encoding::FlatBuffers>,
    ) -> Self {
        let __view = r.view();
        __ridl_fb_decode_speed(__view.buf, __view.table)
    }
}
/// An accessor over FlatBuffers bytes `Counter`'s `verify` accepted.
///
/// The buffer's root is the box table ADR-0019 decision 8
/// gives this declaration: one required `value` field. A
/// buffer carrying no slot for it is `MissingRequired`.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[allow(deprecated)]
pub struct CounterFbView<'a> {
    pub(crate) buf: &'a [u8],
    pub(crate) table: usize,
}
#[allow(deprecated)]
impl<'a> CounterFbView<'a> {
    /// The verified bytes this view reads.
    pub fn bytes(&self) -> &'a [u8] {
        self.buf
    }
    /// The value the box carries. `Counter` is one value, so this decodes it rather than borrowing it, which costs one read.
    pub fn value(&self) -> Counter {
        __ridl_fb_decode_counter(self.buf, self.table)
    }
}
/// Writes `Counter` as its box table and returns its position (ADR-0019 decision 8).
#[allow(deprecated)]
pub(crate) fn __ridl_fb_encode_counter(
    value: &Counter,
    builder: &mut ::ridl_rt::flatbuffers::Builder<'_>,
) -> ::core::result::Result<
    ::ridl_rt::flatbuffers::Pos,
    ::ridl_rt::payload::EncodeError,
> {
    ::core::result::Result::Ok({
        let __box = [
            ::ridl_rt::flatbuffers::TableField {
                slot: 0u16,
                offset: 4u16,
                value: {
                    let __s = *value;
                    ::ridl_rt::flatbuffers::Field::U16(__s.get() as u16)
                },
            },
        ];
        builder.push_table(6usize, 4usize, 1u16, &__box)?
    })
}
#[allow(deprecated)]
pub(crate) fn __ridl_fb_verify_counter(
    buf: &[u8],
    table: usize,
) -> ::core::result::Result<(), ::ridl_rt::payload::VerifyError> {
    match ::ridl_rt::flatbuffers::field(buf, table, 0u16, 2usize)
        .map_err(::ridl_rt::payload::VerifyError::Structure)?
    {
        ::core::option::Option::Some(__p) => {
            ::ridl_rt::flatbuffers::read_u16(buf, __p)
                .map_err(::ridl_rt::payload::VerifyError::Structure)?;
        }
        ::core::option::Option::None => {
            return ::core::result::Result::Err(
                ::ridl_rt::payload::VerifyError::Structure(
                    ::ridl_rt::payload::Malformed::MissingRequired,
                ),
            );
        }
    }
    ::core::result::Result::Ok(())
}
#[allow(deprecated)]
pub(crate) fn __ridl_fb_decode_counter(buf: &[u8], table: usize) -> Counter {
    {
        let __p = ::ridl_rt::flatbuffers::field(buf, table, 0u16, 2usize)
            .unwrap_or(::core::option::Option::None)
            .unwrap_or(0usize);
        Counter::new(
            i64::from(::ridl_rt::flatbuffers::read_u16(buf, __p).unwrap_or(0u16)),
        )
    }
}
#[allow(deprecated)]
impl ::ridl_rt::payload::Payload<::ridl_rt::encoding::FlatBuffers> for Counter {
    /// The largest FlatBuffers buffer any legal `Counter` encodes to: 44 bytes.
    ///
    /// `ridl_ir::projection::flatbuffers::max_size` computed it,
    /// which is the one implementation of the bound (design note
    /// D-6): each table is charged its `soffset`, its inline
    /// fields, its vtable and one alignment event per slot; a
    /// string four bytes per declared character plus a
    /// terminator; a collection its declared maximum. It is a
    /// literal rather than an expression over the field types
    /// because that slack is not expressible in Rust's type
    /// system.
    const MAX_SIZE: usize = 44usize;
    type View<'a> = CounterFbView<'a>;
    fn encode<'o>(
        &self,
        out: &'o mut [u8],
    ) -> ::core::result::Result<
        ::ridl_rt::payload::Encoded<'o, Self::View<'o>>,
        ::ridl_rt::payload::EncodeError,
    > {
        let mut builder = ::ridl_rt::flatbuffers::Builder::new(out);
        let __root = __ridl_fb_encode_counter(self, &mut builder)?;
        let bytes = builder.finish(__root, 8usize)?;
        let table = ::ridl_rt::flatbuffers::root(bytes).unwrap_or(0usize);
        ::core::result::Result::Ok(::ridl_rt::payload::Encoded {
            bytes,
            view: CounterFbView { buf: bytes, table },
        })
    }
    fn verify(
        buf: &[u8],
    ) -> ::core::result::Result<Self::View<'_>, ::ridl_rt::payload::VerifyError> {
        if buf.len()
            > <Self as ::ridl_rt::payload::Payload<
                ::ridl_rt::encoding::FlatBuffers,
            >>::MAX_SIZE
        {
            return ::core::result::Result::Err(
                ::ridl_rt::payload::VerifyError::Structure(
                    ::ridl_rt::payload::Malformed::TooLarge,
                ),
            );
        }
        let table = ::ridl_rt::flatbuffers::root(buf)
            .map_err(::ridl_rt::payload::VerifyError::Structure)?;
        __ridl_fb_verify_counter(buf, table)?;
        ::core::result::Result::Ok(CounterFbView { buf, table })
    }
    fn decode(
        r: ::ridl_rt::payload::Ref<'_, Self, ::ridl_rt::encoding::FlatBuffers>,
    ) -> Self {
        let __view = r.view();
        __ridl_fb_decode_counter(__view.buf, __view.table)
    }
}
/// A zero-copy accessor over FlatBuffers bytes `SensorReading`'s `verify` accepted.
///
/// A scalar, a string, a byte sequence and a nested table are
/// read in place and allocate nothing. A union and a collection
/// are decoded on access instead: a union's arms and a
/// collection's elements have no one view type to hand back.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[allow(deprecated)]
pub struct SensorReadingFbView<'a> {
    pub(crate) buf: &'a [u8],
    pub(crate) table: usize,
}
#[allow(deprecated)]
impl<'a> SensorReadingFbView<'a> {
    /// The verified bytes this view reads.
    pub fn bytes(&self) -> &'a [u8] {
        self.buf
    }
    /// Reads `SensorReading`'s `value` field in place.
    pub fn value(&self) -> Speed {
        let __p = ::ridl_rt::flatbuffers::field(self.buf, self.table, 0u16, 4usize)
            .unwrap_or(::core::option::Option::None)
            .unwrap_or(0usize);
        Speed::new_unchecked(
            f64::from(::ridl_rt::flatbuffers::read_f32(self.buf, __p).unwrap_or(0.0f32)),
        )
    }
}
/// Writes `SensorReading` as a FlatBuffers table and returns its position.
#[allow(deprecated)]
pub(crate) fn __ridl_fb_encode_sensor_reading(
    value: &SensorReading,
    builder: &mut ::ridl_rt::flatbuffers::Builder<'_>,
) -> ::core::result::Result<
    ::ridl_rt::flatbuffers::Pos,
    ::ridl_rt::payload::EncodeError,
> {
    let mut __fields = [::ridl_rt::flatbuffers::TableField {
        slot: 0u16,
        offset: 4u16,
        value: ::ridl_rt::flatbuffers::Field::Bool(false),
    }; 1usize];
    let mut __n = 0usize;
    __fields[__n] = ::ridl_rt::flatbuffers::TableField {
        slot: 0u16,
        offset: 4u16,
        value: {
            let __s = value.value;
            ::ridl_rt::flatbuffers::Field::F32(__s.get() as f32)
        },
    };
    __n += 1;
    builder.push_table(8usize, 4usize, 1u16, &__fields[..__n])
}
/// Checks the FlatBuffers table at `table` against `SensorReading`'s shape.
///
/// A total walk of the type's own shape: the structure in full,
/// an enum and an enum-set discriminant, a collection's declared
/// element count, and every **named** scalar's own declared
/// range, length and pattern, checked over a borrow (`check`,
/// beside `new` on the type itself) against its declared range,
/// length and pattern.
///
/// This does not make every value `decode` builds satisfy every
/// typl constraint. Three gaps:
///
/// - a `step` constraint is checked nowhere — not by `new`, by
///   `check`, or here (driftsys/ridl#469);
/// - the pattern check is behind the `validate-pattern` feature,
///   so a value violating a `match` pattern passes when that
///   feature is off;
/// - an anonymous inline constraint (a field's own `[..]` or
///   `match` written at the field, not through a named scalar)
///   is not checked here at all (driftsys/ridl#469).
#[allow(deprecated)]
pub(crate) fn __ridl_fb_verify_sensor_reading(
    buf: &[u8],
    table: usize,
) -> ::core::result::Result<(), ::ridl_rt::payload::VerifyError> {
    match ::ridl_rt::flatbuffers::field(buf, table, 0u16, 4usize)
        .map_err(::ridl_rt::payload::VerifyError::Structure)?
    {
        ::core::option::Option::Some(__p) => {
            let __raw = ::ridl_rt::flatbuffers::read_f32(buf, __p)
                .map_err(::ridl_rt::payload::VerifyError::Structure)?;
            Speed::check(&(f64::from(__raw)))
                .map_err(::ridl_rt::payload::VerifyError::Contract)?;
        }
        ::core::option::Option::None => {
            return ::core::result::Result::Err(
                ::ridl_rt::payload::VerifyError::Structure(
                    ::ridl_rt::payload::Malformed::MissingRequired,
                ),
            );
        }
    }
    ::core::result::Result::Ok(())
}
/// Builds `SensorReading` from the FlatBuffers table at `table`.
///
/// It cannot fail. A read that could is discharged with the
/// neutral value of its own type — zero, the empty string or
/// collection, the first declared enum variant — and `verify` is
/// what makes those branches unreachable. A named scalar is
/// built with its unchecked constructor (`new_unchecked`) over a
/// value `verify` has already range-checked (`check`), so this
/// never re-checks and never fails.
#[allow(deprecated)]
pub(crate) fn __ridl_fb_decode_sensor_reading(
    buf: &[u8],
    table: usize,
) -> SensorReading {
    SensorReading {
        value: {
            let __p = ::ridl_rt::flatbuffers::field(buf, table, 0u16, 4usize)
                .unwrap_or(::core::option::Option::None)
                .unwrap_or(0usize);
            Speed::new_unchecked(
                f64::from(::ridl_rt::flatbuffers::read_f32(buf, __p).unwrap_or(0.0f32)),
            )
        },
    }
}
#[allow(deprecated)]
impl ::ridl_rt::payload::Payload<::ridl_rt::encoding::FlatBuffers> for SensorReading {
    /// The largest FlatBuffers buffer any legal `SensorReading` encodes to: 46 bytes.
    ///
    /// `ridl_ir::projection::flatbuffers::max_size` computed it,
    /// which is the one implementation of the bound (design note
    /// D-6): each table is charged its `soffset`, its inline
    /// fields, its vtable and one alignment event per slot; a
    /// string four bytes per declared character plus a
    /// terminator; a collection its declared maximum. It is a
    /// literal rather than an expression over the field types
    /// because that slack is not expressible in Rust's type
    /// system.
    const MAX_SIZE: usize = 46usize;
    type View<'a> = SensorReadingFbView<'a>;
    fn encode<'o>(
        &self,
        out: &'o mut [u8],
    ) -> ::core::result::Result<
        ::ridl_rt::payload::Encoded<'o, Self::View<'o>>,
        ::ridl_rt::payload::EncodeError,
    > {
        let mut builder = ::ridl_rt::flatbuffers::Builder::new(out);
        let __root = __ridl_fb_encode_sensor_reading(self, &mut builder)?;
        let bytes = builder.finish(__root, 8usize)?;
        let table = ::ridl_rt::flatbuffers::root(bytes).unwrap_or(0usize);
        ::core::result::Result::Ok(::ridl_rt::payload::Encoded {
            bytes,
            view: SensorReadingFbView {
                buf: bytes,
                table,
            },
        })
    }
    fn verify(
        buf: &[u8],
    ) -> ::core::result::Result<Self::View<'_>, ::ridl_rt::payload::VerifyError> {
        if buf.len()
            > <Self as ::ridl_rt::payload::Payload<
                ::ridl_rt::encoding::FlatBuffers,
            >>::MAX_SIZE
        {
            return ::core::result::Result::Err(
                ::ridl_rt::payload::VerifyError::Structure(
                    ::ridl_rt::payload::Malformed::TooLarge,
                ),
            );
        }
        let table = ::ridl_rt::flatbuffers::root(buf)
            .map_err(::ridl_rt::payload::VerifyError::Structure)?;
        __ridl_fb_verify_sensor_reading(buf, table)?;
        ::core::result::Result::Ok(SensorReadingFbView { buf, table })
    }
    fn decode(
        r: ::ridl_rt::payload::Ref<'_, Self, ::ridl_rt::encoding::FlatBuffers>,
    ) -> Self {
        let __view = r.view();
        __ridl_fb_decode_sensor_reading(__view.buf, __view.table)
    }
}
/// A zero-copy accessor over FlatBuffers bytes `SensorFault`'s `verify` accepted.
///
/// A scalar, a string, a byte sequence and a nested table are
/// read in place and allocate nothing. A union and a collection
/// are decoded on access instead: a union's arms and a
/// collection's elements have no one view type to hand back.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[allow(deprecated)]
pub struct SensorFaultFbView<'a> {
    pub(crate) buf: &'a [u8],
    pub(crate) table: usize,
}
#[allow(deprecated)]
impl<'a> SensorFaultFbView<'a> {
    /// The verified bytes this view reads.
    pub fn bytes(&self) -> &'a [u8] {
        self.buf
    }
    /// Reads `SensorFault`'s `code` field in place.
    pub fn code(&self) -> Counter {
        let __p = ::ridl_rt::flatbuffers::field(self.buf, self.table, 0u16, 2usize)
            .unwrap_or(::core::option::Option::None)
            .unwrap_or(0usize);
        Counter::new(
            i64::from(::ridl_rt::flatbuffers::read_u16(self.buf, __p).unwrap_or(0u16)),
        )
    }
}
/// Writes `SensorFault` as a FlatBuffers table and returns its position.
#[allow(deprecated)]
pub(crate) fn __ridl_fb_encode_sensor_fault(
    value: &SensorFault,
    builder: &mut ::ridl_rt::flatbuffers::Builder<'_>,
) -> ::core::result::Result<
    ::ridl_rt::flatbuffers::Pos,
    ::ridl_rt::payload::EncodeError,
> {
    let mut __fields = [::ridl_rt::flatbuffers::TableField {
        slot: 0u16,
        offset: 4u16,
        value: ::ridl_rt::flatbuffers::Field::Bool(false),
    }; 1usize];
    let mut __n = 0usize;
    __fields[__n] = ::ridl_rt::flatbuffers::TableField {
        slot: 0u16,
        offset: 4u16,
        value: {
            let __s = value.code;
            ::ridl_rt::flatbuffers::Field::U16(__s.get() as u16)
        },
    };
    __n += 1;
    builder.push_table(6usize, 4usize, 1u16, &__fields[..__n])
}
/// Checks the FlatBuffers table at `table` against `SensorFault`'s shape.
///
/// A total walk of the type's own shape: the structure in full,
/// an enum and an enum-set discriminant, a collection's declared
/// element count, and every **named** scalar's own declared
/// range, length and pattern, checked over a borrow (`check`,
/// beside `new` on the type itself) against its declared range,
/// length and pattern.
///
/// This does not make every value `decode` builds satisfy every
/// typl constraint. Three gaps:
///
/// - a `step` constraint is checked nowhere — not by `new`, by
///   `check`, or here (driftsys/ridl#469);
/// - the pattern check is behind the `validate-pattern` feature,
///   so a value violating a `match` pattern passes when that
///   feature is off;
/// - an anonymous inline constraint (a field's own `[..]` or
///   `match` written at the field, not through a named scalar)
///   is not checked here at all (driftsys/ridl#469).
#[allow(deprecated)]
pub(crate) fn __ridl_fb_verify_sensor_fault(
    buf: &[u8],
    table: usize,
) -> ::core::result::Result<(), ::ridl_rt::payload::VerifyError> {
    match ::ridl_rt::flatbuffers::field(buf, table, 0u16, 2usize)
        .map_err(::ridl_rt::payload::VerifyError::Structure)?
    {
        ::core::option::Option::Some(__p) => {
            ::ridl_rt::flatbuffers::read_u16(buf, __p)
                .map_err(::ridl_rt::payload::VerifyError::Structure)?;
        }
        ::core::option::Option::None => {
            return ::core::result::Result::Err(
                ::ridl_rt::payload::VerifyError::Structure(
                    ::ridl_rt::payload::Malformed::MissingRequired,
                ),
            );
        }
    }
    ::core::result::Result::Ok(())
}
/// Builds `SensorFault` from the FlatBuffers table at `table`.
///
/// It cannot fail. A read that could is discharged with the
/// neutral value of its own type — zero, the empty string or
/// collection, the first declared enum variant — and `verify` is
/// what makes those branches unreachable. A named scalar is
/// built with its unchecked constructor (`new_unchecked`) over a
/// value `verify` has already range-checked (`check`), so this
/// never re-checks and never fails.
#[allow(deprecated)]
pub(crate) fn __ridl_fb_decode_sensor_fault(buf: &[u8], table: usize) -> SensorFault {
    SensorFault {
        code: {
            let __p = ::ridl_rt::flatbuffers::field(buf, table, 0u16, 2usize)
                .unwrap_or(::core::option::Option::None)
                .unwrap_or(0usize);
            Counter::new(
                i64::from(::ridl_rt::flatbuffers::read_u16(buf, __p).unwrap_or(0u16)),
            )
        },
    }
}
#[allow(deprecated)]
impl ::ridl_rt::payload::Payload<::ridl_rt::encoding::FlatBuffers> for SensorFault {
    /// The largest FlatBuffers buffer any legal `SensorFault` encodes to: 44 bytes.
    ///
    /// `ridl_ir::projection::flatbuffers::max_size` computed it,
    /// which is the one implementation of the bound (design note
    /// D-6): each table is charged its `soffset`, its inline
    /// fields, its vtable and one alignment event per slot; a
    /// string four bytes per declared character plus a
    /// terminator; a collection its declared maximum. It is a
    /// literal rather than an expression over the field types
    /// because that slack is not expressible in Rust's type
    /// system.
    const MAX_SIZE: usize = 44usize;
    type View<'a> = SensorFaultFbView<'a>;
    fn encode<'o>(
        &self,
        out: &'o mut [u8],
    ) -> ::core::result::Result<
        ::ridl_rt::payload::Encoded<'o, Self::View<'o>>,
        ::ridl_rt::payload::EncodeError,
    > {
        let mut builder = ::ridl_rt::flatbuffers::Builder::new(out);
        let __root = __ridl_fb_encode_sensor_fault(self, &mut builder)?;
        let bytes = builder.finish(__root, 8usize)?;
        let table = ::ridl_rt::flatbuffers::root(bytes).unwrap_or(0usize);
        ::core::result::Result::Ok(::ridl_rt::payload::Encoded {
            bytes,
            view: SensorFaultFbView {
                buf: bytes,
                table,
            },
        })
    }
    fn verify(
        buf: &[u8],
    ) -> ::core::result::Result<Self::View<'_>, ::ridl_rt::payload::VerifyError> {
        if buf.len()
            > <Self as ::ridl_rt::payload::Payload<
                ::ridl_rt::encoding::FlatBuffers,
            >>::MAX_SIZE
        {
            return ::core::result::Result::Err(
                ::ridl_rt::payload::VerifyError::Structure(
                    ::ridl_rt::payload::Malformed::TooLarge,
                ),
            );
        }
        let table = ::ridl_rt::flatbuffers::root(buf)
            .map_err(::ridl_rt::payload::VerifyError::Structure)?;
        __ridl_fb_verify_sensor_fault(buf, table)?;
        ::core::result::Result::Ok(SensorFaultFbView { buf, table })
    }
    fn decode(
        r: ::ridl_rt::payload::Ref<'_, Self, ::ridl_rt::encoding::FlatBuffers>,
    ) -> Self {
        let __view = r.view();
        __ridl_fb_decode_sensor_fault(__view.buf, __view.table)
    }
}
/// A zero-copy accessor over FlatBuffers bytes `SensorResult`'s `verify` accepted.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[allow(deprecated)]
pub struct SensorResultFbView<'a> {
    pub(crate) buf: &'a [u8],
    pub(crate) table: usize,
}
#[allow(deprecated)]
impl<'a> SensorResultFbView<'a> {
    /// The verified bytes this view reads.
    pub fn bytes(&self) -> &'a [u8] {
        self.buf
    }
    /// The value the buffer carries. A union's arms have no one view type, so this decodes `SensorResult` rather than borrowing it.
    pub fn value(&self) -> SensorResult {
        __ridl_fb_decode_sensor_result(self.buf, self.table)
    }
}
#[allow(deprecated)]
pub(crate) fn __ridl_fb_encode_sensor_result(
    value: &SensorResult,
    builder: &mut ::ridl_rt::flatbuffers::Builder<'_>,
) -> ::core::result::Result<
    ::ridl_rt::flatbuffers::Pos,
    ::ridl_rt::payload::EncodeError,
> {
    let (__d, __v) = match value {
        SensorResult::Ok(__a) => (1u8, __ridl_fb_encode_sensor_reading(__a, builder)?),
        SensorResult::Err(__a) => (2u8, __ridl_fb_encode_sensor_fault(__a, builder)?),
    };
    let __fields = [
        ::ridl_rt::flatbuffers::TableField {
            slot: 0u16,
            offset: 4u16,
            value: ::ridl_rt::flatbuffers::Field::U8(__d),
        },
        ::ridl_rt::flatbuffers::TableField {
            slot: 1u16,
            offset: 8u16,
            value: ::ridl_rt::flatbuffers::Field::Offset(__v),
        },
    ];
    builder.push_table(12usize, 4usize, 2u16, &__fields)
}
#[allow(deprecated)]
pub(crate) fn __ridl_fb_verify_sensor_result(
    buf: &[u8],
    table: usize,
) -> ::core::result::Result<(), ::ridl_rt::payload::VerifyError> {
    let __dp = ::ridl_rt::flatbuffers::field(buf, table, 0u16, 1usize)
        .map_err(::ridl_rt::payload::VerifyError::Structure)?;
    let __vp = ::ridl_rt::flatbuffers::field(buf, table, 1u16, 4usize)
        .map_err(::ridl_rt::payload::VerifyError::Structure)?;
    let (__d, __value) = match (__dp, __vp) {
        (::core::option::Option::Some(__d), ::core::option::Option::Some(__value)) => {
            (
                ::ridl_rt::flatbuffers::read_u8(buf, __d)
                    .map_err(::ridl_rt::payload::VerifyError::Structure)?,
                __value,
            )
        }
        _ => {
            return ::core::result::Result::Err(
                ::ridl_rt::payload::VerifyError::Structure(
                    ::ridl_rt::payload::Malformed::Union,
                ),
            );
        }
    };
    match __d {
        1u8 => {
            let __t = ::ridl_rt::flatbuffers::follow(buf, __value)
                .map_err(::ridl_rt::payload::VerifyError::Structure)?;
            __ridl_fb_verify_sensor_reading(buf, __t)?;
        }
        2u8 => {
            let __t = ::ridl_rt::flatbuffers::follow(buf, __value)
                .map_err(::ridl_rt::payload::VerifyError::Structure)?;
            __ridl_fb_verify_sensor_fault(buf, __t)?;
        }
        _ => {
            return ::core::result::Result::Err(
                ::ridl_rt::payload::VerifyError::Structure(
                    ::ridl_rt::payload::Malformed::Union,
                ),
            );
        }
    }
    ::core::result::Result::Ok(())
}
#[allow(deprecated)]
pub(crate) fn __ridl_fb_decode_sensor_result(buf: &[u8], table: usize) -> SensorResult {
    let __d = ::ridl_rt::flatbuffers::field(buf, table, 0u16, 1usize)
        .unwrap_or(::core::option::Option::None)
        .map(|__p| ::ridl_rt::flatbuffers::read_u8(buf, __p).unwrap_or(0u8))
        .unwrap_or(0u8);
    let __value = ::ridl_rt::flatbuffers::field(buf, table, 1u16, 4usize)
        .unwrap_or(::core::option::Option::None)
        .unwrap_or(0usize);
    match __d {
        1u8 => {
            SensorResult::Ok(
                __ridl_fb_decode_sensor_reading(
                    buf,
                    ::ridl_rt::flatbuffers::follow(buf, __value).unwrap_or(0usize),
                ),
            )
        }
        2u8 => {
            SensorResult::Err(
                __ridl_fb_decode_sensor_fault(
                    buf,
                    ::ridl_rt::flatbuffers::follow(buf, __value).unwrap_or(0usize),
                ),
            )
        }
        _ => {
            SensorResult::Ok(
                __ridl_fb_decode_sensor_reading(
                    buf,
                    ::ridl_rt::flatbuffers::follow(buf, __value).unwrap_or(0usize),
                ),
            )
        }
    }
}
#[allow(deprecated)]
impl ::ridl_rt::payload::Payload<::ridl_rt::encoding::FlatBuffers> for SensorResult {
    /// The largest FlatBuffers buffer any legal `SensorResult` encodes to: 91 bytes.
    ///
    /// `ridl_ir::projection::flatbuffers::max_size` computed it,
    /// which is the one implementation of the bound (design note
    /// D-6): each table is charged its `soffset`, its inline
    /// fields, its vtable and one alignment event per slot; a
    /// string four bytes per declared character plus a
    /// terminator; a collection its declared maximum. It is a
    /// literal rather than an expression over the field types
    /// because that slack is not expressible in Rust's type
    /// system.
    const MAX_SIZE: usize = 91usize;
    type View<'a> = SensorResultFbView<'a>;
    fn encode<'o>(
        &self,
        out: &'o mut [u8],
    ) -> ::core::result::Result<
        ::ridl_rt::payload::Encoded<'o, Self::View<'o>>,
        ::ridl_rt::payload::EncodeError,
    > {
        let mut builder = ::ridl_rt::flatbuffers::Builder::new(out);
        let __root = __ridl_fb_encode_sensor_result(self, &mut builder)?;
        let bytes = builder.finish(__root, 8usize)?;
        let table = ::ridl_rt::flatbuffers::root(bytes).unwrap_or(0usize);
        ::core::result::Result::Ok(::ridl_rt::payload::Encoded {
            bytes,
            view: SensorResultFbView {
                buf: bytes,
                table,
            },
        })
    }
    fn verify(
        buf: &[u8],
    ) -> ::core::result::Result<Self::View<'_>, ::ridl_rt::payload::VerifyError> {
        if buf.len()
            > <Self as ::ridl_rt::payload::Payload<
                ::ridl_rt::encoding::FlatBuffers,
            >>::MAX_SIZE
        {
            return ::core::result::Result::Err(
                ::ridl_rt::payload::VerifyError::Structure(
                    ::ridl_rt::payload::Malformed::TooLarge,
                ),
            );
        }
        let table = ::ridl_rt::flatbuffers::root(buf)
            .map_err(::ridl_rt::payload::VerifyError::Structure)?;
        __ridl_fb_verify_sensor_result(buf, table)?;
        ::core::result::Result::Ok(SensorResultFbView { buf, table })
    }
    fn decode(
        r: ::ridl_rt::payload::Ref<'_, Self, ::ridl_rt::encoding::FlatBuffers>,
    ) -> Self {
        let __view = r.view();
        __ridl_fb_decode_sensor_result(__view.buf, __view.table)
    }
}