---
source: crates/ridl-backend-rust/src/tests.rs
expression: rust_source
---
/// 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)
}
}
/// Coolant / ambient temperature
///
/// Quantization (`step`) is not checked by `new`.
#[derive(Debug, Clone, Copy, PartialEq, PartialOrd)]
#[repr(transparent)]
pub struct Temperature(f64);
impl Temperature {
/// 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 < -40.0 {
return ::core::result::Result::Err(::ridl_rt::payload::Violation {
type_name: "Temperature",
rule: ::ridl_rt::payload::Rule::Range,
});
}
if value > 125.0 {
return ::core::result::Result::Err(::ridl_rt::payload::Violation {
type_name: "Temperature",
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 Temperature {
type Error = ::ridl_rt::payload::Violation;
fn try_from(value: f64) -> ::core::result::Result<Self, Self::Error> {
Self::new(value)
}
}
impl ::core::convert::From<Temperature> for f64 {
fn from(value: Temperature) -> Self {
value.0
}
}
impl Default for Temperature {
fn default() -> Self {
Temperature::new_unchecked(0.0)
}
}
/// Engine crankshaft speed
///
/// Quantization (`step`) is not checked by `new`.
#[derive(Debug, Clone, Copy, PartialEq, PartialOrd)]
#[repr(transparent)]
pub struct RPM(f64);
impl RPM {
/// 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: "RPM",
rule: ::ridl_rt::payload::Rule::Range,
});
}
if value > 8000.0 {
return ::core::result::Result::Err(::ridl_rt::payload::Violation {
type_name: "RPM",
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 RPM {
type Error = ::ridl_rt::payload::Violation;
fn try_from(value: f64) -> ::core::result::Result<Self, Self::Error> {
Self::new(value)
}
}
impl ::core::convert::From<RPM> for f64 {
fn from(value: RPM) -> Self {
value.0
}
}
impl Default for RPM {
fn default() -> Self {
RPM::new_unchecked(0.0)
}
}
/// Normalised ratio
///
/// Quantization (`step`) is not checked by `new`.
#[derive(Debug, Clone, Copy, PartialEq, PartialOrd)]
#[repr(transparent)]
pub struct Ratio(f64);
impl Ratio {
/// 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: "Ratio",
rule: ::ridl_rt::payload::Rule::Range,
});
}
if value > 100.0 {
return ::core::result::Result::Err(::ridl_rt::payload::Violation {
type_name: "Ratio",
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 Ratio {
type Error = ::ridl_rt::payload::Violation;
fn try_from(value: f64) -> ::core::result::Result<Self, Self::Error> {
Self::new(value)
}
}
impl ::core::convert::From<Ratio> for f64 {
fn from(value: Ratio) -> Self {
value.0
}
}
impl Default for Ratio {
fn default() -> Self {
Ratio::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)
}
}
/// Quantization (`step`) is not checked by `new`.
#[derive(Debug, Clone, Copy, PartialEq, PartialOrd)]
#[repr(transparent)]
pub struct Gain(f64);
impl Gain {
/// 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: "Gain",
rule: ::ridl_rt::payload::Rule::Range,
});
}
if value > 1.0 {
return ::core::result::Result::Err(::ridl_rt::payload::Violation {
type_name: "Gain",
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 Gain {
type Error = ::ridl_rt::payload::Violation;
fn try_from(value: f64) -> ::core::result::Result<Self, Self::Error> {
Self::new(value)
}
}
impl ::core::convert::From<Gain> for f64 {
fn from(value: Gain) -> Self {
value.0
}
}
impl Default for Gain {
fn default() -> Self {
Gain::new_unchecked(0.0)
}
}
pub const MAX_SPEED: Speed = Speed::new_unchecked(250.0);
pub const SPEED_LIMIT_EU: Speed = Speed::new_unchecked(130.0);
pub const IDLE_RPM: RPM = RPM::new_unchecked(800.0);
pub const MAX_GEAR: i64 = 6;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[repr(i64)]
pub enum GearPosition {
PARK = 0,
DRIVE = 1,
REVERSE = 2,
NEUTRAL = 3,
}
impl ::core::convert::TryFrom<i64> for GearPosition {
type Error = ::ridl_rt::payload::Violation;
fn try_from(value: i64) -> ::core::result::Result<Self, Self::Error> {
match value {
0 => ::core::result::Result::Ok(Self::PARK),
1 => ::core::result::Result::Ok(Self::DRIVE),
2 => ::core::result::Result::Ok(Self::REVERSE),
3 => ::core::result::Result::Ok(Self::NEUTRAL),
_ => {
::core::result::Result::Err(::ridl_rt::payload::Violation {
type_name: "GearPosition",
rule: ::ridl_rt::payload::Rule::Variant,
})
}
}
}
}
impl ::core::convert::From<GearPosition> for i64 {
fn from(value: GearPosition) -> Self {
value as i64
}
}
impl Default for GearPosition {
fn default() -> Self {
GearPosition::PARK
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[repr(i64)]
pub enum Warning {
LOW_FUEL = 0,
CHECK_ENGINE = 1,
DOOR_OPEN = 2,
SEATBELT = 3,
}
impl ::core::convert::TryFrom<i64> for Warning {
type Error = ::ridl_rt::payload::Violation;
fn try_from(value: i64) -> ::core::result::Result<Self, Self::Error> {
match value {
0 => ::core::result::Result::Ok(Self::LOW_FUEL),
1 => ::core::result::Result::Ok(Self::CHECK_ENGINE),
2 => ::core::result::Result::Ok(Self::DOOR_OPEN),
3 => ::core::result::Result::Ok(Self::SEATBELT),
_ => {
::core::result::Result::Err(::ridl_rt::payload::Violation {
type_name: "Warning",
rule: ::ridl_rt::payload::Rule::Variant,
})
}
}
}
}
impl ::core::convert::From<Warning> for i64 {
fn from(value: Warning) -> Self {
value as i64
}
}
impl Default for Warning {
fn default() -> Self {
Warning::LOW_FUEL
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[repr(transparent)]
pub struct WarningFlags(i64);
impl WarningFlags {
pub const LOW_FUEL: WarningFlags = WarningFlags(1 << 0);
pub const CHECK_ENGINE: WarningFlags = WarningFlags(1 << 1);
pub const DOOR_OPEN: WarningFlags = WarningFlags(1 << 2);
pub const SEATBELT: WarningFlags = WarningFlags(1 << 3);
/// The union of every declared bit. `TryFrom` refuses a value
/// that carries any other bit.
pub const DECLARED_MASK: i64 = 15;
pub const fn get(self) -> i64 {
self.0
}
}
impl ::core::convert::TryFrom<i64> for WarningFlags {
type Error = ::ridl_rt::payload::Violation;
fn try_from(value: i64) -> ::core::result::Result<Self, Self::Error> {
if value & !Self::DECLARED_MASK != 0 {
return ::core::result::Result::Err(::ridl_rt::payload::Violation {
type_name: "WarningFlags",
rule: ::ridl_rt::payload::Rule::Variant,
});
}
::core::result::Result::Ok(Self(value))
}
}
impl ::core::convert::From<WarningFlags> for i64 {
fn from(value: WarningFlags) -> Self {
value.0
}
}
impl Default for WarningFlags {
fn default() -> Self {
WarningFlags(0)
}
}
#[derive(Debug, Clone, Copy, PartialEq)]
#[repr(C)]
pub struct SpeedLimitPayload {
pub limit: Speed,
pub actual: Speed,
}
impl Default for SpeedLimitPayload {
fn default() -> Self {
SpeedLimitPayload {
limit: Speed::default(),
actual: Speed::default(),
}
}
}
#[derive(Debug, Clone, PartialEq)]
pub struct DriverProfile {
pub name: crate::ridl::std::Name,
pub speed: Speed,
pub r#override: Option<Speed>,
pub gears: i64,
}
#[derive(Debug, Clone, PartialEq)]
pub struct SensorBounds {
pub range: SensorBoundsRange,
pub readings: [Speed; 8],
pub labels: Vec<crate::ridl::std::Label>,
pub meta: Vec<(crate::ridl::std::Label, crate::ridl::std::Name)>,
}
#[derive(Debug, Clone, PartialEq)]
pub enum SensorResult {
Ok(SensorReading),
Err(SensorFault),
}
impl Default for SensorResult {
fn default() -> Self {
SensorResult::Ok(SensorReading::default())
}
}
#[derive(Debug, Clone, PartialEq)]
#[repr(C)]
pub struct SensorReading {
pub value: Speed,
pub timestamp: crate::ridl::std::Timestamp,
}
impl Default for SensorReading {
fn default() -> Self {
SensorReading {
value: Speed::default(),
timestamp: crate::ridl::std::Timestamp::default(),
}
}
}
#[derive(Debug, Clone, PartialEq)]
pub struct SensorFault {
pub code: Counter,
pub message: crate::ridl::std::Message,
}
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub(crate) struct RawWheelFrame {
pub ticks: Counter,
pub frame: Vec<u8>,
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct SensorBoundsRange {
pub min: Speed,
pub max: Speed,
}
impl Default for SensorBoundsRange {
fn default() -> Self {
SensorBoundsRange {
min: Speed::default(),
max: Speed::default(),
}
}
}
/// `DriverProfile` carries no `Payload<FlatBuffers>` implementation.
///
/// The member `name` reaches a reference this backend does not resolve — a reference into another package, which this call was handed no package to resolve, a same-package cycle, or a stream.
/// A reference into another package of the same build resolves
/// when the caller hands the codec that build, which
/// `ridl build --emit rust` does and a bare `generate` does not;
/// a resolved one is named by a path through the emitted module
/// tree. The causes above are the ones this call could meet.
/// A type that reaches itself, and a stream, which has no single
/// value to size, are never resolvable by any caller.
///
/// This is a silent omission in the sense ADR-0016 decision 6 and
/// ADR-0017 decision 4 rule out, and it is deliberate for now.
#[allow(dead_code)]
const __RIDL_FB_NO_CODEC_DRIVER_PROFILE: () = ();
/// `SensorBounds` carries no `Payload<FlatBuffers>` implementation.
///
/// The members `labels`, `meta` reach a reference this backend does not resolve — a reference into another package, which this call was handed no package to resolve, a same-package cycle, or a stream.
/// A reference into another package of the same build resolves
/// when the caller hands the codec that build, which
/// `ridl build --emit rust` does and a bare `generate` does not;
/// a resolved one is named by a path through the emitted module
/// tree. The causes above are the ones this call could meet.
/// A type that reaches itself, and a stream, which has no single
/// value to size, are never resolvable by any caller.
///
/// This is a silent omission in the sense ADR-0016 decision 6 and
/// ADR-0017 decision 4 rule out, and it is deliberate for now.
#[allow(dead_code)]
const __RIDL_FB_NO_CODEC_SENSOR_BOUNDS: () = ();
/// `SensorResult` carries no `Payload<FlatBuffers>` implementation.
///
/// The members `ok`, `err` reach a reference this backend does not resolve — a reference into another package, which this call was handed no package to resolve, a same-package cycle, or a stream.
/// A reference into another package of the same build resolves
/// when the caller hands the codec that build, which
/// `ridl build --emit rust` does and a bare `generate` does not;
/// a resolved one is named by a path through the emitted module
/// tree. The causes above are the ones this call could meet.
/// A type that reaches itself, and a stream, which has no single
/// value to size, are never resolvable by any caller.
///
/// This is a silent omission in the sense ADR-0016 decision 6 and
/// ADR-0017 decision 4 rule out, and it is deliberate for now.
#[allow(dead_code)]
const __RIDL_FB_NO_CODEC_SENSOR_RESULT: () = ();
/// `SensorReading` carries no `Payload<FlatBuffers>` implementation.
///
/// The member `timestamp` reaches a reference this backend does not resolve — a reference into another package, which this call was handed no package to resolve, a same-package cycle, or a stream.
/// A reference into another package of the same build resolves
/// when the caller hands the codec that build, which
/// `ridl build --emit rust` does and a bare `generate` does not;
/// a resolved one is named by a path through the emitted module
/// tree. The causes above are the ones this call could meet.
/// A type that reaches itself, and a stream, which has no single
/// value to size, are never resolvable by any caller.
///
/// This is a silent omission in the sense ADR-0016 decision 6 and
/// ADR-0017 decision 4 rule out, and it is deliberate for now.
#[allow(dead_code)]
const __RIDL_FB_NO_CODEC_SENSOR_READING: () = ();
/// `SensorFault` carries no `Payload<FlatBuffers>` implementation.
///
/// The member `message` reaches a reference this backend does not resolve — a reference into another package, which this call was handed no package to resolve, a same-package cycle, or a stream.
/// A reference into another package of the same build resolves
/// when the caller hands the codec that build, which
/// `ridl build --emit rust` does and a bare `generate` does not;
/// a resolved one is named by a path through the emitted module
/// tree. The causes above are the ones this call could meet.
/// A type that reaches itself, and a stream, which has no single
/// value to size, are never resolvable by any caller.
///
/// This is a silent omission in the sense ADR-0016 decision 6 and
/// ADR-0017 decision 4 rule out, and it is deliberate for now.
#[allow(dead_code)]
const __RIDL_FB_NO_CODEC_SENSOR_FAULT: () = ();
/// 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 `Temperature`'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 TemperatureFbView<'a> {
pub(crate) buf: &'a [u8],
pub(crate) table: usize,
}
#[allow(deprecated)]
impl<'a> TemperatureFbView<'a> {
/// The verified bytes this view reads.
pub fn bytes(&self) -> &'a [u8] {
self.buf
}
/// The value the box carries. `Temperature` is one value, so this decodes it rather than borrowing it, which costs one read.
pub fn value(&self) -> Temperature {
__ridl_fb_decode_temperature(self.buf, self.table)
}
}
/// Writes `Temperature` as its box table and returns its position (ADR-0019 decision 8).
#[allow(deprecated)]
pub(crate) fn __ridl_fb_encode_temperature(
value: &Temperature,
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_temperature(
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)?;
Temperature::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_temperature(buf: &[u8], table: usize) -> Temperature {
{
let __p = ::ridl_rt::flatbuffers::field(buf, table, 0u16, 4usize)
.unwrap_or(::core::option::Option::None)
.unwrap_or(0usize);
Temperature::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 Temperature {
/// The largest FlatBuffers buffer any legal `Temperature` 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> = TemperatureFbView<'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_temperature(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: TemperatureFbView {
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_temperature(buf, table)?;
::core::result::Result::Ok(TemperatureFbView { buf, table })
}
fn decode(
r: ::ridl_rt::payload::Ref<'_, Self, ::ridl_rt::encoding::FlatBuffers>,
) -> Self {
let __view = r.view();
__ridl_fb_decode_temperature(__view.buf, __view.table)
}
}
/// An accessor over FlatBuffers bytes `RPM`'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 RPMFbView<'a> {
pub(crate) buf: &'a [u8],
pub(crate) table: usize,
}
#[allow(deprecated)]
impl<'a> RPMFbView<'a> {
/// The verified bytes this view reads.
pub fn bytes(&self) -> &'a [u8] {
self.buf
}
/// The value the box carries. `RPM` is one value, so this decodes it rather than borrowing it, which costs one read.
pub fn value(&self) -> RPM {
__ridl_fb_decode_rpm(self.buf, self.table)
}
}
/// Writes `RPM` as its box table and returns its position (ADR-0019 decision 8).
#[allow(deprecated)]
pub(crate) fn __ridl_fb_encode_rpm(
value: &RPM,
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_rpm(
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)?;
RPM::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_rpm(buf: &[u8], table: usize) -> RPM {
{
let __p = ::ridl_rt::flatbuffers::field(buf, table, 0u16, 4usize)
.unwrap_or(::core::option::Option::None)
.unwrap_or(0usize);
RPM::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 RPM {
/// The largest FlatBuffers buffer any legal `RPM` 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> = RPMFbView<'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_rpm(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: RPMFbView { 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_rpm(buf, table)?;
::core::result::Result::Ok(RPMFbView { buf, table })
}
fn decode(
r: ::ridl_rt::payload::Ref<'_, Self, ::ridl_rt::encoding::FlatBuffers>,
) -> Self {
let __view = r.view();
__ridl_fb_decode_rpm(__view.buf, __view.table)
}
}
/// An accessor over FlatBuffers bytes `Ratio`'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 RatioFbView<'a> {
pub(crate) buf: &'a [u8],
pub(crate) table: usize,
}
#[allow(deprecated)]
impl<'a> RatioFbView<'a> {
/// The verified bytes this view reads.
pub fn bytes(&self) -> &'a [u8] {
self.buf
}
/// The value the box carries. `Ratio` is one value, so this decodes it rather than borrowing it, which costs one read.
pub fn value(&self) -> Ratio {
__ridl_fb_decode_ratio(self.buf, self.table)
}
}
/// Writes `Ratio` as its box table and returns its position (ADR-0019 decision 8).
#[allow(deprecated)]
pub(crate) fn __ridl_fb_encode_ratio(
value: &Ratio,
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_ratio(
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)?;
Ratio::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_ratio(buf: &[u8], table: usize) -> Ratio {
{
let __p = ::ridl_rt::flatbuffers::field(buf, table, 0u16, 4usize)
.unwrap_or(::core::option::Option::None)
.unwrap_or(0usize);
Ratio::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 Ratio {
/// The largest FlatBuffers buffer any legal `Ratio` 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> = RatioFbView<'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_ratio(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: RatioFbView { 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_ratio(buf, table)?;
::core::result::Result::Ok(RatioFbView { buf, table })
}
fn decode(
r: ::ridl_rt::payload::Ref<'_, Self, ::ridl_rt::encoding::FlatBuffers>,
) -> Self {
let __view = r.view();
__ridl_fb_decode_ratio(__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)
}
}
/// An accessor over FlatBuffers bytes `Gain`'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 GainFbView<'a> {
pub(crate) buf: &'a [u8],
pub(crate) table: usize,
}
#[allow(deprecated)]
impl<'a> GainFbView<'a> {
/// The verified bytes this view reads.
pub fn bytes(&self) -> &'a [u8] {
self.buf
}
/// The value the box carries. `Gain` is one value, so this decodes it rather than borrowing it, which costs one read.
pub fn value(&self) -> Gain {
__ridl_fb_decode_gain(self.buf, self.table)
}
}
/// Writes `Gain` as its box table and returns its position (ADR-0019 decision 8).
#[allow(deprecated)]
pub(crate) fn __ridl_fb_encode_gain(
value: &Gain,
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_gain(
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)?;
Gain::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_gain(buf: &[u8], table: usize) -> Gain {
{
let __p = ::ridl_rt::flatbuffers::field(buf, table, 0u16, 4usize)
.unwrap_or(::core::option::Option::None)
.unwrap_or(0usize);
Gain::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 Gain {
/// The largest FlatBuffers buffer any legal `Gain` 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> = GainFbView<'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_gain(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: GainFbView { 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_gain(buf, table)?;
::core::result::Result::Ok(GainFbView { buf, table })
}
fn decode(
r: ::ridl_rt::payload::Ref<'_, Self, ::ridl_rt::encoding::FlatBuffers>,
) -> Self {
let __view = r.view();
__ridl_fb_decode_gain(__view.buf, __view.table)
}
}
/// An accessor over FlatBuffers bytes `GearPosition`'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 GearPositionFbView<'a> {
pub(crate) buf: &'a [u8],
pub(crate) table: usize,
}
#[allow(deprecated)]
impl<'a> GearPositionFbView<'a> {
/// The verified bytes this view reads.
pub fn bytes(&self) -> &'a [u8] {
self.buf
}
/// The value the box carries. `GearPosition` is one value, so this decodes it rather than borrowing it, which costs one read.
pub fn value(&self) -> GearPosition {
__ridl_fb_decode_gear_position(self.buf, self.table)
}
}
/// Writes `GearPosition` as its box table and returns its position (ADR-0019 decision 8).
#[allow(deprecated)]
pub(crate) fn __ridl_fb_encode_gear_position(
value: &GearPosition,
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: 8u16,
value: {
let __s = *value;
::ridl_rt::flatbuffers::Field::I64(i64::from(__s))
},
},
];
builder.push_table(16usize, 8usize, 1u16, &__box)?
})
}
#[allow(deprecated)]
pub(crate) fn __ridl_fb_verify_gear_position(
buf: &[u8],
table: usize,
) -> ::core::result::Result<(), ::ridl_rt::payload::VerifyError> {
match ::ridl_rt::flatbuffers::field(buf, table, 0u16, 8usize)
.map_err(::ridl_rt::payload::VerifyError::Structure)?
{
::core::option::Option::Some(__p) => {
let __raw = ::ridl_rt::flatbuffers::read_i64(buf, __p)
.map_err(::ridl_rt::payload::VerifyError::Structure)?;
<GearPosition as ::core::convert::TryFrom<i64>>::try_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_gear_position(buf: &[u8], table: usize) -> GearPosition {
{
let __p = ::ridl_rt::flatbuffers::field(buf, table, 0u16, 8usize)
.unwrap_or(::core::option::Option::None)
.unwrap_or(0usize);
<GearPosition as ::core::convert::TryFrom<
i64,
>>::try_from(::ridl_rt::flatbuffers::read_i64(buf, __p).unwrap_or(0i64))
.unwrap_or(GearPosition::PARK)
}
}
#[allow(deprecated)]
impl ::ridl_rt::payload::Payload<::ridl_rt::encoding::FlatBuffers> for GearPosition {
/// The largest FlatBuffers buffer any legal `GearPosition` encodes to: 50 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 = 50usize;
type View<'a> = GearPositionFbView<'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_gear_position(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: GearPositionFbView {
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_gear_position(buf, table)?;
::core::result::Result::Ok(GearPositionFbView { buf, table })
}
fn decode(
r: ::ridl_rt::payload::Ref<'_, Self, ::ridl_rt::encoding::FlatBuffers>,
) -> Self {
let __view = r.view();
__ridl_fb_decode_gear_position(__view.buf, __view.table)
}
}
/// An accessor over FlatBuffers bytes `Warning`'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 WarningFbView<'a> {
pub(crate) buf: &'a [u8],
pub(crate) table: usize,
}
#[allow(deprecated)]
impl<'a> WarningFbView<'a> {
/// The verified bytes this view reads.
pub fn bytes(&self) -> &'a [u8] {
self.buf
}
/// The value the box carries. `Warning` is one value, so this decodes it rather than borrowing it, which costs one read.
pub fn value(&self) -> Warning {
__ridl_fb_decode_warning(self.buf, self.table)
}
}
/// Writes `Warning` as its box table and returns its position (ADR-0019 decision 8).
#[allow(deprecated)]
pub(crate) fn __ridl_fb_encode_warning(
value: &Warning,
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: 8u16,
value: {
let __s = *value;
::ridl_rt::flatbuffers::Field::I64(i64::from(__s))
},
},
];
builder.push_table(16usize, 8usize, 1u16, &__box)?
})
}
#[allow(deprecated)]
pub(crate) fn __ridl_fb_verify_warning(
buf: &[u8],
table: usize,
) -> ::core::result::Result<(), ::ridl_rt::payload::VerifyError> {
match ::ridl_rt::flatbuffers::field(buf, table, 0u16, 8usize)
.map_err(::ridl_rt::payload::VerifyError::Structure)?
{
::core::option::Option::Some(__p) => {
let __raw = ::ridl_rt::flatbuffers::read_i64(buf, __p)
.map_err(::ridl_rt::payload::VerifyError::Structure)?;
<Warning as ::core::convert::TryFrom<i64>>::try_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_warning(buf: &[u8], table: usize) -> Warning {
{
let __p = ::ridl_rt::flatbuffers::field(buf, table, 0u16, 8usize)
.unwrap_or(::core::option::Option::None)
.unwrap_or(0usize);
<Warning as ::core::convert::TryFrom<
i64,
>>::try_from(::ridl_rt::flatbuffers::read_i64(buf, __p).unwrap_or(0i64))
.unwrap_or(Warning::LOW_FUEL)
}
}
#[allow(deprecated)]
impl ::ridl_rt::payload::Payload<::ridl_rt::encoding::FlatBuffers> for Warning {
/// The largest FlatBuffers buffer any legal `Warning` encodes to: 50 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 = 50usize;
type View<'a> = WarningFbView<'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_warning(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: WarningFbView { 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_warning(buf, table)?;
::core::result::Result::Ok(WarningFbView { buf, table })
}
fn decode(
r: ::ridl_rt::payload::Ref<'_, Self, ::ridl_rt::encoding::FlatBuffers>,
) -> Self {
let __view = r.view();
__ridl_fb_decode_warning(__view.buf, __view.table)
}
}
/// An accessor over FlatBuffers bytes `WarningFlags`'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 WarningFlagsFbView<'a> {
pub(crate) buf: &'a [u8],
pub(crate) table: usize,
}
#[allow(deprecated)]
impl<'a> WarningFlagsFbView<'a> {
/// The verified bytes this view reads.
pub fn bytes(&self) -> &'a [u8] {
self.buf
}
/// The value the box carries. `WarningFlags` is one value, so this decodes it rather than borrowing it, which costs one read.
pub fn value(&self) -> WarningFlags {
__ridl_fb_decode_warning_flags(self.buf, self.table)
}
}
/// Writes `WarningFlags` as its box table and returns its position (ADR-0019 decision 8).
#[allow(deprecated)]
pub(crate) fn __ridl_fb_encode_warning_flags(
value: &WarningFlags,
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::U8(i64::from(__s) as u8)
},
},
];
builder.push_table(5usize, 4usize, 1u16, &__box)?
})
}
#[allow(deprecated)]
pub(crate) fn __ridl_fb_verify_warning_flags(
buf: &[u8],
table: usize,
) -> ::core::result::Result<(), ::ridl_rt::payload::VerifyError> {
match ::ridl_rt::flatbuffers::field(buf, table, 0u16, 1usize)
.map_err(::ridl_rt::payload::VerifyError::Structure)?
{
::core::option::Option::Some(__p) => {
let __raw = ::ridl_rt::flatbuffers::read_u8(buf, __p)
.map_err(::ridl_rt::payload::VerifyError::Structure)?;
<WarningFlags as ::core::convert::TryFrom<i64>>::try_from(i64::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_warning_flags(buf: &[u8], table: usize) -> WarningFlags {
{
let __p = ::ridl_rt::flatbuffers::field(buf, table, 0u16, 1usize)
.unwrap_or(::core::option::Option::None)
.unwrap_or(0usize);
<WarningFlags as ::core::convert::TryFrom<
i64,
>>::try_from(i64::from(::ridl_rt::flatbuffers::read_u8(buf, __p).unwrap_or(0u8)))
.unwrap_or(WarningFlags(0i64))
}
}
#[allow(deprecated)]
impl ::ridl_rt::payload::Payload<::ridl_rt::encoding::FlatBuffers> for WarningFlags {
/// The largest FlatBuffers buffer any legal `WarningFlags` encodes to: 43 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 = 43usize;
type View<'a> = WarningFlagsFbView<'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_warning_flags(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: WarningFlagsFbView {
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_warning_flags(buf, table)?;
::core::result::Result::Ok(WarningFlagsFbView { buf, table })
}
fn decode(
r: ::ridl_rt::payload::Ref<'_, Self, ::ridl_rt::encoding::FlatBuffers>,
) -> Self {
let __view = r.view();
__ridl_fb_decode_warning_flags(__view.buf, __view.table)
}
}
/// A zero-copy accessor over FlatBuffers bytes `SpeedLimitPayload`'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 SpeedLimitPayloadFbView<'a> {
pub(crate) buf: &'a [u8],
pub(crate) table: usize,
}
#[allow(deprecated)]
impl<'a> SpeedLimitPayloadFbView<'a> {
/// The verified bytes this view reads.
pub fn bytes(&self) -> &'a [u8] {
self.buf
}
/// Reads `SpeedLimitPayload`'s `limit` field in place.
pub fn limit(&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)),
)
}
/// Reads `SpeedLimitPayload`'s `actual` field in place.
pub fn actual(&self) -> Speed {
let __p = ::ridl_rt::flatbuffers::field(self.buf, self.table, 1u16, 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 `SpeedLimitPayload` as a FlatBuffers table and returns its position.
#[allow(deprecated)]
pub(crate) fn __ridl_fb_encode_speed_limit_payload(
value: &SpeedLimitPayload,
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),
}; 2usize];
let mut __n = 0usize;
__fields[__n] = ::ridl_rt::flatbuffers::TableField {
slot: 0u16,
offset: 4u16,
value: {
let __s = value.limit;
::ridl_rt::flatbuffers::Field::F32(__s.get() as f32)
},
};
__n += 1;
__fields[__n] = ::ridl_rt::flatbuffers::TableField {
slot: 1u16,
offset: 8u16,
value: {
let __s = value.actual;
::ridl_rt::flatbuffers::Field::F32(__s.get() as f32)
},
};
__n += 1;
builder.push_table(12usize, 4usize, 2u16, &__fields[..__n])
}
/// Checks the FlatBuffers table at `table` against `SpeedLimitPayload`'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_speed_limit_payload(
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,
),
);
}
}
match ::ridl_rt::flatbuffers::field(buf, table, 1u16, 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 `SpeedLimitPayload` 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_speed_limit_payload(
buf: &[u8],
table: usize,
) -> SpeedLimitPayload {
SpeedLimitPayload {
limit: {
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)),
)
},
actual: {
let __p = ::ridl_rt::flatbuffers::field(buf, table, 1u16, 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 SpeedLimitPayload {
/// The largest FlatBuffers buffer any legal `SpeedLimitPayload` encodes to: 59 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 = 59usize;
type View<'a> = SpeedLimitPayloadFbView<'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_limit_payload(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: SpeedLimitPayloadFbView {
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_limit_payload(buf, table)?;
::core::result::Result::Ok(SpeedLimitPayloadFbView {
buf,
table,
})
}
fn decode(
r: ::ridl_rt::payload::Ref<'_, Self, ::ridl_rt::encoding::FlatBuffers>,
) -> Self {
let __view = r.view();
__ridl_fb_decode_speed_limit_payload(__view.buf, __view.table)
}
}
/// A zero-copy accessor over FlatBuffers bytes `RawWheelFrame`'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(crate) struct RawWheelFrameFbView<'a> {
pub(crate) buf: &'a [u8],
pub(crate) table: usize,
}
#[allow(deprecated)]
impl<'a> RawWheelFrameFbView<'a> {
/// The verified bytes this view reads.
pub(crate) fn bytes(&self) -> &'a [u8] {
self.buf
}
/// Reads `RawWheelFrame`'s `ticks` field in place.
pub(crate) fn ticks(&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)),
)
}
/// Reads `RawWheelFrame`'s `frame` field in place.
pub(crate) fn frame(&self) -> &'a [u8] {
let __p = ::ridl_rt::flatbuffers::field(self.buf, self.table, 1u16, 4usize)
.unwrap_or(::core::option::Option::None)
.unwrap_or(0usize);
{
let __v = ::ridl_rt::flatbuffers::vector(self.buf, __p, 1usize)
.unwrap_or(::ridl_rt::flatbuffers::Vector {
len: 0,
first: 0,
});
self.buf.get(__v.first..__v.first + __v.len).unwrap_or(&[])
}
}
}
/// Writes `RawWheelFrame` as a FlatBuffers table and returns its position.
#[allow(deprecated)]
pub(crate) fn __ridl_fb_encode_raw_wheel_frame(
value: &RawWheelFrame,
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),
}; 2usize];
let mut __n = 0usize;
__fields[__n] = ::ridl_rt::flatbuffers::TableField {
slot: 0u16,
offset: 4u16,
value: {
let __s = value.ticks;
::ridl_rt::flatbuffers::Field::U16(__s.get() as u16)
},
};
__n += 1;
__fields[__n] = ::ridl_rt::flatbuffers::TableField {
slot: 1u16,
offset: 8u16,
value: ::ridl_rt::flatbuffers::Field::Offset(
builder.push_vector(&value.frame.as_slice(), 1usize)?,
),
};
__n += 1;
builder.push_table(12usize, 4usize, 2u16, &__fields[..__n])
}
/// Checks the FlatBuffers table at `table` against `RawWheelFrame`'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_raw_wheel_frame(
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,
),
);
}
}
match ::ridl_rt::flatbuffers::field(buf, table, 1u16, 4usize)
.map_err(::ridl_rt::payload::VerifyError::Structure)?
{
::core::option::Option::Some(__p) => {
::ridl_rt::flatbuffers::vector(buf, __p, 1usize)
.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 `RawWheelFrame` 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_raw_wheel_frame(
buf: &[u8],
table: usize,
) -> RawWheelFrame {
RawWheelFrame {
ticks: {
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)),
)
},
frame: {
let __p = ::ridl_rt::flatbuffers::field(buf, table, 1u16, 4usize)
.unwrap_or(::core::option::Option::None)
.unwrap_or(0usize);
{
let __v = ::ridl_rt::flatbuffers::vector(buf, __p, 1usize)
.unwrap_or(::ridl_rt::flatbuffers::Vector {
len: 0,
first: 0,
});
buf.get(__v.first..__v.first + __v.len).unwrap_or(&[]).to_vec()
}
},
}
}
#[allow(deprecated)]
impl ::ridl_rt::payload::Payload<::ridl_rt::encoding::FlatBuffers> for RawWheelFrame {
/// The largest FlatBuffers buffer any legal `RawWheelFrame` encodes to: 76 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 = 76usize;
type View<'a> = RawWheelFrameFbView<'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_raw_wheel_frame(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: RawWheelFrameFbView {
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_raw_wheel_frame(buf, table)?;
::core::result::Result::Ok(RawWheelFrameFbView { buf, table })
}
fn decode(
r: ::ridl_rt::payload::Ref<'_, Self, ::ridl_rt::encoding::FlatBuffers>,
) -> Self {
let __view = r.view();
__ridl_fb_decode_raw_wheel_frame(__view.buf, __view.table)
}
}