From a5845a609453d79902114a015d64bd078eee1543 Mon Sep 17 00:00:00 2001 From: Paul Flynn Date: Mon, 14 Oct 2024 20:44:13 -0400 Subject: [PATCH 01/15] Add GeoFenceContract in Rust and update .gitignore Implemented a GeoFenceContract to check coordinates within a 3D geofence using Rust and Ink smart contracts. Added Cargo.toml and lib.rs files with contract definitions, dependencies, and test cases. Updated .gitignore to ignore all .idea/ directories under contracts. --- .gitignore | 2 +- etc/contracts/geo_fence_contract/Cargo.toml | 24 +++++ etc/contracts/geo_fence_contract/lib.rs | 106 ++++++++++++++++++++ 3 files changed, 131 insertions(+), 1 deletion(-) create mode 100755 etc/contracts/geo_fence_contract/Cargo.toml create mode 100755 etc/contracts/geo_fence_contract/lib.rs diff --git a/.gitignore b/.gitignore index 835b388..0051f77 100644 --- a/.gitignore +++ b/.gitignore @@ -24,6 +24,6 @@ Cargo.lock /cache/ /etc/contracts/substrate-contracts-node /etc/contracts/ev/ -/etc/contracts/simple_abac/.idea/ +/etc/contracts/*/.idea/ /apple-app-site-association.json /dump.rdb diff --git a/etc/contracts/geo_fence_contract/Cargo.toml b/etc/contracts/geo_fence_contract/Cargo.toml new file mode 100755 index 0000000..0873c68 --- /dev/null +++ b/etc/contracts/geo_fence_contract/Cargo.toml @@ -0,0 +1,24 @@ +[package] +name = "geo_fence_contract" +version = "0.1.0" +authors = ["[your_name] <[your_email]>"] +edition = "2021" + +[dependencies] +ink = { version = "5.0.0", default-features = false } +parity-scale-codec = { version = "3.6.12", default-features = false } +scale-info = { version = "2.11.3", default-features = false } + +[dev-dependencies] +ink_e2e = { version = "5.0.0" } + +[lib] +path = "lib.rs" + +[features] +default = ["std"] +std = [ + "ink/std", +] +ink-as-dependency = [] +e2e-tests = [] diff --git a/etc/contracts/geo_fence_contract/lib.rs b/etc/contracts/geo_fence_contract/lib.rs new file mode 100755 index 0000000..7bdbafa --- /dev/null +++ b/etc/contracts/geo_fence_contract/lib.rs @@ -0,0 +1,106 @@ +#![cfg_attr(not(feature = "std"), no_std, no_main)] + +#[ink::contract] +mod geo_fence_contract { + use parity_scale_codec::{Decode, Encode}; + use scale_info::TypeInfo; + + #[derive(Debug, PartialEq, Eq, Clone, Copy, Decode, Encode, TypeInfo)] + pub struct Coordinate3D { + pub latitude: FixedPoint, + pub longitude: FixedPoint, + pub altitude: FixedPoint, + } + + #[derive(Debug, PartialEq, Eq, Clone, Copy, Decode, Encode, TypeInfo)] + pub struct Geofence3D { + pub min_latitude: FixedPoint, + pub max_latitude: FixedPoint, + pub min_longitude: FixedPoint, + pub max_longitude: FixedPoint, + pub min_altitude: FixedPoint, + pub max_altitude: FixedPoint, + } + + #[derive(Debug, PartialEq, Eq, Clone, Copy, Decode, Encode, TypeInfo)] + pub struct FixedPoint(pub i64); + + impl FixedPoint { + pub fn new(value: f64) -> Self { + FixedPoint((value * 1_000_000.0) as i64) // Scale f64 to fixed point representation + } + + pub fn to_f64(self) -> f64 { + self.0 as f64 / 1_000_000.0 + } + } + + #[ink(storage)] + pub struct GeoFenceContract { + value: bool, + } + + impl GeoFenceContract { + #[ink(constructor)] + pub fn new(init_value: bool) -> Self { + Self { value: init_value } + } + + #[ink(constructor)] + pub fn default() -> Self { + Self::new(Default::default()) + } + + #[ink(message)] + pub fn is_within_geofence( + &self, + geofence: Geofence3D, + latitude: FixedPoint, + longitude: FixedPoint, + altitude: FixedPoint, + ) -> bool { + latitude.0 >= geofence.min_latitude.0 && latitude.0 <= geofence.max_latitude.0 && + longitude.0 >= geofence.min_longitude.0 && longitude.0 <= geofence.max_longitude.0 && + altitude.0 >= geofence.min_altitude.0 && altitude.0 <= geofence.max_altitude.0 + } + } + + #[cfg(test)] + mod tests { + use super::*; + + #[ink::test] + fn test_within_geofence() { + let contract = GeoFenceContract::new(false); + let geofence = Geofence3D { + min_latitude: FixedPoint::new(-10.0), + max_latitude: FixedPoint::new(10.0), + min_longitude: FixedPoint::new(-20.0), + max_longitude: FixedPoint::new(20.0), + min_altitude: FixedPoint::new(0.0), + max_altitude: FixedPoint::new(100.0), + }; + assert!(contract.is_within_geofence(geofence, FixedPoint::new(0.0), FixedPoint::new(0.0), FixedPoint::new(50.0))); + assert!(!contract.is_within_geofence(geofence, FixedPoint::new(-15.0), FixedPoint::new(0.0), FixedPoint::new(50.0))); + assert!(!contract.is_within_geofence(geofence, FixedPoint::new(0.0), FixedPoint::new(-25.0), FixedPoint::new(50.0))); + assert!(!contract.is_within_geofence(geofence, FixedPoint::new(0.0), FixedPoint::new(0.0), FixedPoint::new(150.0))); + } + + #[ink::test] + fn test_within_20ft_cube() { + let contract = GeoFenceContract::new(false); + let geofence = Geofence3D { + min_latitude: FixedPoint::new(0.0), + max_latitude: FixedPoint::new(0.0061), // Approximately 20 feet in latitude + min_longitude: FixedPoint::new(0.0), + max_longitude: FixedPoint::new(0.0061), // Approximately 20 feet in longitude + min_altitude: FixedPoint::new(0.0), + max_altitude: FixedPoint::new(6.096), // 20 feet in altitude + }; + assert!(contract.is_within_geofence(geofence, FixedPoint::new(0.003), FixedPoint::new(0.003), FixedPoint::new(3.0))); // Inside the cube + assert!(!contract.is_within_geofence(geofence, FixedPoint::new(0.01), FixedPoint::new(0.003), FixedPoint::new(3.0))); // Outside latitude + assert!(!contract.is_within_geofence(geofence, FixedPoint::new(0.003), FixedPoint::new(0.01), FixedPoint::new(3.0))); // Outside longitude + assert!(!contract.is_within_geofence(geofence, FixedPoint::new(0.003), FixedPoint::new(0.003), FixedPoint::new(10.0))); // Outside altitude + } + } +} \ No newline at end of file From 0641d67c8351fb6b06e818c4f273e498ff08620f Mon Sep 17 00:00:00 2001 From: Paul Flynn Date: Mon, 14 Oct 2024 21:15:43 -0400 Subject: [PATCH 02/15] Refactor geofence contract storage Switched from fixed-point to integer latitude/longitude/altitude representation and integrated ink! Mapping for geofence storage and retrieval. Introduced `add_geofence` method and updated tests accordingly for better geofence management. --- etc/contracts/geo_fence_contract/Cargo.toml | 6 +- etc/contracts/geo_fence_contract/lib.rs | 134 ++++++++++---------- 2 files changed, 72 insertions(+), 68 deletions(-) diff --git a/etc/contracts/geo_fence_contract/Cargo.toml b/etc/contracts/geo_fence_contract/Cargo.toml index 0873c68..8064a64 100755 --- a/etc/contracts/geo_fence_contract/Cargo.toml +++ b/etc/contracts/geo_fence_contract/Cargo.toml @@ -6,8 +6,8 @@ edition = "2021" [dependencies] ink = { version = "5.0.0", default-features = false } -parity-scale-codec = { version = "3.6.12", default-features = false } -scale-info = { version = "2.11.3", default-features = false } +scale = { package = "parity-scale-codec", version = "3.6.12", default-features = false, features = ["derive"] } +scale-info = { version = "2.11.3", default-features = false, features = ["derive"], optional = true } [dev-dependencies] ink_e2e = { version = "5.0.0" } @@ -19,6 +19,8 @@ path = "lib.rs" default = ["std"] std = [ "ink/std", + "scale/std", + "scale-info/std", ] ink-as-dependency = [] e2e-tests = [] diff --git a/etc/contracts/geo_fence_contract/lib.rs b/etc/contracts/geo_fence_contract/lib.rs index 7bdbafa..9c6b2fc 100755 --- a/etc/contracts/geo_fence_contract/lib.rs +++ b/etc/contracts/geo_fence_contract/lib.rs @@ -2,66 +2,76 @@ #[ink::contract] mod geo_fence_contract { - use parity_scale_codec::{Decode, Encode}; - use scale_info::TypeInfo; + use ink::storage::Mapping; + use ink::storage::traits::StorageLayout; + use scale::{Decode, Encode}; - #[derive(Debug, PartialEq, Eq, Clone, Copy, Decode, Encode, TypeInfo)] + #[derive(Debug, PartialEq, Eq, Clone, Copy, Decode, Encode)] + #[cfg_attr(feature = "std", derive(scale_info::TypeInfo))] + #[derive(StorageLayout)] pub struct Coordinate3D { - pub latitude: FixedPoint, - pub longitude: FixedPoint, - pub altitude: FixedPoint, + pub latitude: i64, + pub longitude: i64, + pub altitude: i64, } - #[derive(Debug, PartialEq, Eq, Clone, Copy, Decode, Encode, TypeInfo)] + #[derive(Debug, PartialEq, Eq, Clone, Copy, Decode, Encode)] + #[cfg_attr(feature = "std", derive(scale_info::TypeInfo))] + #[derive(StorageLayout)] pub struct Geofence3D { - pub min_latitude: FixedPoint, - pub max_latitude: FixedPoint, - pub min_longitude: FixedPoint, - pub max_longitude: FixedPoint, - pub min_altitude: FixedPoint, - pub max_altitude: FixedPoint, - } - - #[derive(Debug, PartialEq, Eq, Clone, Copy, Decode, Encode, TypeInfo)] - pub struct FixedPoint(pub i64); - - impl FixedPoint { - pub fn new(value: f64) -> Self { - FixedPoint((value * 1_000_000.0) as i64) // Scale f64 to fixed point representation - } - - pub fn to_f64(self) -> f64 { - self.0 as f64 / 1_000_000.0 - } + pub min_latitude: i64, + pub max_latitude: i64, + pub min_longitude: i64, + pub max_longitude: i64, + pub min_altitude: i64, + pub max_altitude: i64, } #[ink(storage)] pub struct GeoFenceContract { - value: bool, + geofences: Mapping, + geofence_count: u32, } + impl Default for GeoFenceContract { + fn default() -> Self { + Self::new() + } + } + impl GeoFenceContract { #[ink(constructor)] - pub fn new(init_value: bool) -> Self { - Self { value: init_value } + pub fn new() -> Self { + Self { + geofences: Mapping::default(), + geofence_count: 0, + } } - #[ink(constructor)] - pub fn default() -> Self { - Self::new(Default::default()) + #[ink(message)] + pub fn add_geofence(&mut self, geofence: Geofence3D) -> u32 { + let id = self.geofence_count; + self.geofences.insert(id, &geofence); + self.geofence_count += 1; + id } #[ink(message)] pub fn is_within_geofence( &self, - geofence: Geofence3D, - latitude: FixedPoint, - longitude: FixedPoint, - altitude: FixedPoint, + geofence_id: u32, + coordinate: Coordinate3D, ) -> bool { - latitude.0 >= geofence.min_latitude.0 && latitude.0 <= geofence.max_latitude.0 && - longitude.0 >= geofence.min_longitude.0 && longitude.0 <= geofence.max_longitude.0 && - altitude.0 >= geofence.min_altitude.0 && altitude.0 <= geofence.max_altitude.0 + if let Some(geofence) = self.geofences.get(geofence_id) { + coordinate.latitude >= geofence.min_latitude + && coordinate.latitude <= geofence.max_latitude + && coordinate.longitude >= geofence.min_longitude + && coordinate.longitude <= geofence.max_longitude + && coordinate.altitude >= geofence.min_altitude + && coordinate.altitude <= geofence.max_altitude + } else { + false + } } } @@ -71,36 +81,28 @@ mod geo_fence_contract { #[ink::test] fn test_within_geofence() { - let contract = GeoFenceContract::new(false); + let mut contract = GeoFenceContract::new(); let geofence = Geofence3D { - min_latitude: FixedPoint::new(-10.0), - max_latitude: FixedPoint::new(10.0), - min_longitude: FixedPoint::new(-20.0), - max_longitude: FixedPoint::new(20.0), - min_altitude: FixedPoint::new(0.0), - max_altitude: FixedPoint::new(100.0), + min_latitude: -10_000_000, + max_latitude: 10_000_000, + min_longitude: -20_000_000, + max_longitude: 20_000_000, + min_altitude: 0, + max_altitude: 100_000_000, }; - assert!(contract.is_within_geofence(geofence, FixedPoint::new(0.0), FixedPoint::new(0.0), FixedPoint::new(50.0))); - assert!(!contract.is_within_geofence(geofence, FixedPoint::new(-15.0), FixedPoint::new(0.0), FixedPoint::new(50.0))); - assert!(!contract.is_within_geofence(geofence, FixedPoint::new(0.0), FixedPoint::new(-25.0), FixedPoint::new(50.0))); - assert!(!contract.is_within_geofence(geofence, FixedPoint::new(0.0), FixedPoint::new(0.0), FixedPoint::new(150.0))); - } + let geofence_id = contract.add_geofence(geofence); - #[ink::test] - fn test_within_20ft_cube() { - let contract = GeoFenceContract::new(false); - let geofence = Geofence3D { - min_latitude: FixedPoint::new(0.0), - max_latitude: FixedPoint::new(0.0061), // Approximately 20 feet in latitude - min_longitude: FixedPoint::new(0.0), - max_longitude: FixedPoint::new(0.0061), // Approximately 20 feet in longitude - min_altitude: FixedPoint::new(0.0), - max_altitude: FixedPoint::new(6.096), // 20 feet in altitude - }; - assert!(contract.is_within_geofence(geofence, FixedPoint::new(0.003), FixedPoint::new(0.003), FixedPoint::new(3.0))); // Inside the cube - assert!(!contract.is_within_geofence(geofence, FixedPoint::new(0.01), FixedPoint::new(0.003), FixedPoint::new(3.0))); // Outside latitude - assert!(!contract.is_within_geofence(geofence, FixedPoint::new(0.003), FixedPoint::new(0.01), FixedPoint::new(3.0))); // Outside longitude - assert!(!contract.is_within_geofence(geofence, FixedPoint::new(0.003), FixedPoint::new(0.003), FixedPoint::new(10.0))); // Outside altitude + assert!(contract.is_within_geofence(geofence_id, Coordinate3D { + latitude: 0, + longitude: 0, + altitude: 50_000_000, + })); + + assert!(!contract.is_within_geofence(geofence_id, Coordinate3D { + latitude: -15_000_000, + longitude: 0, + altitude: 50_000_000, + })); } } } \ No newline at end of file From fba5080d5cf05a76c83402926016fab5cd25318d Mon Sep 17 00:00:00 2001 From: Paul Flynn Date: Mon, 14 Oct 2024 21:39:22 -0400 Subject: [PATCH 03/15] Refactor GeoFenceContract to remove storage and mapping. Removed the geofence storage and mapping from GeoFenceContract, simplifying the contract structure. Updated the is_within_geofence function to take a Geofence3D parameter directly instead of using a mapping. Added a new test function to verify geofence checks within a 20-foot cube. --- etc/contracts/geo_fence_contract/Cargo.toml | 3 + etc/contracts/geo_fence_contract/lib.rs | 90 +++++++++++---------- 2 files changed, 52 insertions(+), 41 deletions(-) diff --git a/etc/contracts/geo_fence_contract/Cargo.toml b/etc/contracts/geo_fence_contract/Cargo.toml index 8064a64..f0641c1 100755 --- a/etc/contracts/geo_fence_contract/Cargo.toml +++ b/etc/contracts/geo_fence_contract/Cargo.toml @@ -24,3 +24,6 @@ std = [ ] ink-as-dependency = [] e2e-tests = [] +# do not add +#__ink_dylint_Constructor = [] +#__ink_dylint_Storage = [] diff --git a/etc/contracts/geo_fence_contract/lib.rs b/etc/contracts/geo_fence_contract/lib.rs index 9c6b2fc..7d3a084 100755 --- a/etc/contracts/geo_fence_contract/lib.rs +++ b/etc/contracts/geo_fence_contract/lib.rs @@ -2,13 +2,10 @@ #[ink::contract] mod geo_fence_contract { - use ink::storage::Mapping; - use ink::storage::traits::StorageLayout; use scale::{Decode, Encode}; #[derive(Debug, PartialEq, Eq, Clone, Copy, Decode, Encode)] #[cfg_attr(feature = "std", derive(scale_info::TypeInfo))] - #[derive(StorageLayout)] pub struct Coordinate3D { pub latitude: i64, pub longitude: i64, @@ -17,7 +14,6 @@ mod geo_fence_contract { #[derive(Debug, PartialEq, Eq, Clone, Copy, Decode, Encode)] #[cfg_attr(feature = "std", derive(scale_info::TypeInfo))] - #[derive(StorageLayout)] pub struct Geofence3D { pub min_latitude: i64, pub max_latitude: i64, @@ -28,50 +24,26 @@ mod geo_fence_contract { } #[ink(storage)] - pub struct GeoFenceContract { - geofences: Mapping, - geofence_count: u32, - } + pub struct GeoFenceContract {} - impl Default for GeoFenceContract { - fn default() -> Self { - Self::new() - } - } - impl GeoFenceContract { #[ink(constructor)] pub fn new() -> Self { - Self { - geofences: Mapping::default(), - geofence_count: 0, - } - } - - #[ink(message)] - pub fn add_geofence(&mut self, geofence: Geofence3D) -> u32 { - let id = self.geofence_count; - self.geofences.insert(id, &geofence); - self.geofence_count += 1; - id + Self {} } #[ink(message)] pub fn is_within_geofence( &self, - geofence_id: u32, + geofence: Geofence3D, coordinate: Coordinate3D, ) -> bool { - if let Some(geofence) = self.geofences.get(geofence_id) { - coordinate.latitude >= geofence.min_latitude - && coordinate.latitude <= geofence.max_latitude - && coordinate.longitude >= geofence.min_longitude - && coordinate.longitude <= geofence.max_longitude - && coordinate.altitude >= geofence.min_altitude - && coordinate.altitude <= geofence.max_altitude - } else { - false - } + coordinate.latitude >= geofence.min_latitude + && coordinate.latitude <= geofence.max_latitude + && coordinate.longitude >= geofence.min_longitude + && coordinate.longitude <= geofence.max_longitude + && coordinate.altitude >= geofence.min_altitude + && coordinate.altitude <= geofence.max_altitude } } @@ -81,7 +53,7 @@ mod geo_fence_contract { #[ink::test] fn test_within_geofence() { - let mut contract = GeoFenceContract::new(); + let contract = GeoFenceContract::new(); let geofence = Geofence3D { min_latitude: -10_000_000, max_latitude: 10_000_000, @@ -90,19 +62,55 @@ mod geo_fence_contract { min_altitude: 0, max_altitude: 100_000_000, }; - let geofence_id = contract.add_geofence(geofence); - assert!(contract.is_within_geofence(geofence_id, Coordinate3D { + assert!(contract.is_within_geofence(geofence, Coordinate3D { latitude: 0, longitude: 0, altitude: 50_000_000, })); - assert!(!contract.is_within_geofence(geofence_id, Coordinate3D { + assert!(!contract.is_within_geofence(geofence, Coordinate3D { latitude: -15_000_000, longitude: 0, altitude: 50_000_000, })); } + + #[ink::test] + fn test_within_20ft_cube() { + let contract = GeoFenceContract::new(); + let geofence = Geofence3D { + min_latitude: 0, + max_latitude: 610, // Approximately 20 feet in latitude (scaled by 10^5) + min_longitude: 0, + max_longitude: 610, // Approximately 20 feet in longitude (scaled by 10^5) + min_altitude: 0, + max_altitude: 610, // 20 feet in altitude (scaled by 10^2) + }; + + assert!(contract.is_within_geofence(geofence, Coordinate3D { + latitude: 300, + longitude: 300, + altitude: 300, + })); // Inside the cube + + assert!(!contract.is_within_geofence(geofence, Coordinate3D { + latitude: 1000, + longitude: 300, + altitude: 300, + })); // Outside latitude + + assert!(!contract.is_within_geofence(geofence, Coordinate3D { + latitude: 300, + longitude: 1000, + altitude: 300, + })); // Outside longitude + + assert!(!contract.is_within_geofence(geofence, Coordinate3D { + latitude: 300, + longitude: 300, + altitude: 1000, + })); // Outside altitude + } } } \ No newline at end of file From da4e1c1f2d5720624df981239ca0195c984259fb Mon Sep 17 00:00:00 2001 From: Paul Flynn Date: Mon, 14 Oct 2024 21:41:03 -0400 Subject: [PATCH 04/15] Merge remote-tracking branch 'origin/main' into feature/redis From c15dbe63b77cfebff98277423c9e806e2f615e1e Mon Sep 17 00:00:00 2001 From: Paul Flynn Date: Sat, 19 Oct 2024 21:46:29 -0400 Subject: [PATCH 05/15] Add geo-fencing contract support Added a new geo-fencing contract for enhanced policy enforcement. This includes integration of a `GeoFenceContract` to check if coordinates fall within defined geofences. Adjusted the handling of policy types to include embedded geofence data validation. --- Cargo.toml | 3 + etc/contracts/README.md | 12 ++ src/bin/contracts/geo_fence_contract.rs | 115 +++++++++++++++ src/bin/contracts/mod.rs | 1 + src/bin/main.rs | 187 +++++++++++++++++++----- src/lib.rs | 8 +- 6 files changed, 288 insertions(+), 38 deletions(-) create mode 100755 src/bin/contracts/geo_fence_contract.rs diff --git a/Cargo.toml b/Cargo.toml index e39e5b2..7df3f00 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -45,6 +45,9 @@ async-nats = "0.36.0" serde_json = "1.0.128" redis = { version = "0.27.2", features = ["tokio-comp"] } flatbuffers = "24.3.25" +scale = { package = "parity-scale-codec", version = "3.6.12", default-features = false, features = ["derive"] } +scale-info = { version = "2.11.3", default-features = false, features = ["derive"], optional = true } + [dev-dependencies] criterion = "0.5.1" diff --git a/etc/contracts/README.md b/etc/contracts/README.md index 407006f..6d1cb90 100644 --- a/etc/contracts/README.md +++ b/etc/contracts/README.md @@ -45,6 +45,18 @@ cargo contract build --features e2e-tests ### Deploy +#### Geofence + +```text +Code hash 0x63a3ec45fd3ab905924a38227917e278de277c9b80d6865190d18d0d64f560bb +Contract 5H6sLwXKBv3cdm5VVRxrvA8p5cux2Rrni5CQ4GRyYKo4b9B4 +``` + +```shell +cargo contract upload --url ws://127.0.0.1:9944 --suri //Alice geo_fence_contract/target/ink/geo_fence_contract.wasm +cargo contract instantiate --url ws://127.0.0.1:9944 --suri //Alice geo_fence_contract/target/ink/geo_fence_contract.wasm --execute +``` + ```shell cargo contract upload --url ws://127.0.0.1:9944 --suri //Alice simple_abac/target/ink/simple_abac.wasm cargo contract instantiate --url ws://127.0.0.1:9944 --suri //Alice simple_abac/target/ink/simple_abac.wasm --execute diff --git a/src/bin/contracts/geo_fence_contract.rs b/src/bin/contracts/geo_fence_contract.rs new file mode 100755 index 0000000..1c40d41 --- /dev/null +++ b/src/bin/contracts/geo_fence_contract.rs @@ -0,0 +1,115 @@ +#![allow(unexpected_cfgs)] +#[ink::contract] +pub mod geo_fence_contract { + use scale::{Decode, Encode}; + + #[derive(Debug, PartialEq, Eq, Clone, Copy, Decode, Encode)] + #[cfg_attr(feature = "std", derive(scale_info::TypeInfo))] + pub struct Coordinate3D { + pub latitude: i64, + pub longitude: i64, + pub altitude: i64, + } + + #[derive(Debug, PartialEq, Eq, Clone, Copy, Decode, Encode)] + #[cfg_attr(feature = "std", derive(scale_info::TypeInfo))] + pub struct Geofence3D { + pub min_latitude: i64, + pub max_latitude: i64, + pub min_longitude: i64, + pub max_longitude: i64, + pub min_altitude: i64, + pub max_altitude: i64, + } + + #[ink(storage)] + pub struct GeoFenceContract {} + + impl GeoFenceContract { + #[ink(constructor)] + pub fn new() -> Self { + Self {} + } + + #[ink(message)] + pub fn is_within_geofence( + &self, + geofence: Geofence3D, + coordinate: Coordinate3D, + ) -> bool { + coordinate.latitude >= geofence.min_latitude + && coordinate.latitude <= geofence.max_latitude + && coordinate.longitude >= geofence.min_longitude + && coordinate.longitude <= geofence.max_longitude + && coordinate.altitude >= geofence.min_altitude + && coordinate.altitude <= geofence.max_altitude + } + } + + #[cfg(test)] + mod tests { + use super::*; + + #[ink::test] + fn test_within_geofence() { + let contract = GeoFenceContract::new(); + let geofence = Geofence3D { + min_latitude: -10_000_000, + max_latitude: 10_000_000, + min_longitude: -20_000_000, + max_longitude: 20_000_000, + min_altitude: 0, + max_altitude: 100_000_000, + }; + + assert!(contract.is_within_geofence(geofence, Coordinate3D { + latitude: 0, + longitude: 0, + altitude: 50_000_000, + })); + + assert!(!contract.is_within_geofence(geofence, Coordinate3D { + latitude: -15_000_000, + longitude: 0, + altitude: 50_000_000, + })); + } + + #[ink::test] + fn test_within_20ft_cube() { + let contract = GeoFenceContract::new(); + let geofence = Geofence3D { + min_latitude: 0, + max_latitude: 610, // Approximately 20 feet in latitude (scaled by 10^5) + min_longitude: 0, + max_longitude: 610, // Approximately 20 feet in longitude (scaled by 10^5) + min_altitude: 0, + max_altitude: 610, // 20 feet in altitude (scaled by 10^2) + }; + + assert!(contract.is_within_geofence(geofence, Coordinate3D { + latitude: 300, + longitude: 300, + altitude: 300, + })); // Inside the cube + + assert!(!contract.is_within_geofence(geofence, Coordinate3D { + latitude: 1000, + longitude: 300, + altitude: 300, + })); // Outside latitude + + assert!(!contract.is_within_geofence(geofence, Coordinate3D { + latitude: 300, + longitude: 1000, + altitude: 300, + })); // Outside longitude + + assert!(!contract.is_within_geofence(geofence, Coordinate3D { + latitude: 300, + longitude: 300, + altitude: 1000, + })); // Outside altitude + } + } +} \ No newline at end of file diff --git a/src/bin/contracts/mod.rs b/src/bin/contracts/mod.rs index 7644d48..a1d09b9 100644 --- a/src/bin/contracts/mod.rs +++ b/src/bin/contracts/mod.rs @@ -1 +1,2 @@ pub mod contract_simple_abac; +pub mod geo_fence_contract; diff --git a/src/bin/main.rs b/src/bin/main.rs index ec91129..0f2758f 100644 --- a/src/bin/main.rs +++ b/src/bin/main.rs @@ -2,6 +2,7 @@ mod contracts; mod schemas; use crate::contracts::contract_simple_abac; +use crate::contracts::geo_fence_contract; use crate::schemas::event_generated::arkavo::{Event, EventData}; use aes_gcm::aead::generic_array::GenericArray; use aes_gcm::aead::KeyInit; @@ -15,7 +16,7 @@ use futures_util::{SinkExt, StreamExt}; use hkdf::Hkdf; use jsonwebtoken::{decode, DecodingKey, Validation}; use log::{error, info}; -use nanotdf::{BinaryParser, ProtocolEnum}; +use nanotdf::{BinaryParser, PolicyType, ProtocolEnum, ResourceLocator}; use native_tls::{Identity, Protocol, TlsAcceptor as NativeTlsAcceptor}; use once_cell::sync::OnceCell; use p256::ecdh::EphemeralSecret; @@ -267,6 +268,7 @@ async fn handle_websocket( server_state.settings.nats_subject.clone(), connection_state.clone(), )); + let mut public_id_nats_task: Option> = None; // Handle incoming WebSocket messages loop { tokio::select! { @@ -280,15 +282,28 @@ async fn handle_websocket( if msg.is_text() { // Handle JWT token let token = msg.into_text().unwrap(); - // println!("token: {}", token); + println!("token: {}", token); match verify_token(&token) { Ok(claims) => { println!("Valid JWT received. Claims: {:?}", claims); // store the claims { let mut claims_lock = connection_state.claims_lock.write().unwrap(); - *claims_lock = Some(claims); + *claims_lock = Some(claims.clone()); } + // Extract publicID from claims and subscribe to `profile.` + let public_id = claims.sub; + let subject = format!("profile.{}", public_id); + // Cancel any existing `publicID`-specific NATS task + if let Some(task) = public_id_nats_task.take() { + task.abort(); + } + // Set up new NATS subscription for `profile.` + public_id_nats_task = Some(tokio::spawn(handle_nats_subscription( + nats_connection.clone(), + subject, + connection_state.clone(), + ))); } Err(e) => { println!("Invalid JWT: {}", e); @@ -323,6 +338,9 @@ async fn handle_websocket( } // Cancel the NATS subscription when the WebSocket connection closes nats_task.abort(); + if let Some(task) = public_id_nats_task { + task.abort(); + } } async fn handle_connection( @@ -489,38 +507,138 @@ async fn handle_rewrap( } // TDF contract let policy = header.get_policy(); - let locator = policy.get_locator(); - let locator = match locator { - Some(locator) => locator, - None => { - info!("Missing TDF locator"); - return None; + let locator: Option<&ResourceLocator>; + let mut embedded_locator: Option = None; + let mut policy_body: Option<&[u8]> = None; + + match policy.policy_type { + PolicyType::Remote => { + locator = policy.get_locator().as_ref(); } - }; - if locator.protocol_enum == ProtocolEnum::SharedResource { - // println!("contract {}", locator.body.clone()); - if !locator.body.is_empty() { - let claims_result = match connection_state.claims_lock.read() { - Ok(read_lock) => match read_lock.clone() { - Some(value) => Ok(value.sub), - None => Err("Error: Clone cannot be performed"), - }, - Err(_) => Err("Error: Read lock cannot be obtained"), - }; - // execute contract - let contract = contract_simple_abac::simple_abac::SimpleAbac::new(); - if claims_result.is_ok() - && !contract.check_access(claims_result.unwrap(), locator.body.clone()) - { - // binary response - let mut response_data = Vec::new(); - response_data.push(MessageType::RewrappedKey as u8); - response_data.extend_from_slice(tdf_ephemeral_key_bytes); - // timing - let total_time = start_time.elapsed(); - log_timing(settings, "Time to deny", total_time); - // DENY - return Some(Message::Binary(response_data)); + PolicyType::Embedded => { + if let Some(body) = &policy.body { + let mut parser = BinaryParser::new(body); + if let Ok(parsed_locator) = parser.read_kas_field() { + embedded_locator = Some(parsed_locator); + policy_body = Some(&body[parser.position..]); + } + } + locator = embedded_locator.as_ref(); + } + } + if let Some(locator) = &locator { + if locator.protocol_enum == ProtocolEnum::SharedResource { + println!("contract {}", locator.body.clone()); + if !locator.body.is_empty() { + let claims_result = match connection_state.claims_lock.read() { + Ok(read_lock) => match read_lock.clone() { + Some(value) => Ok(value.sub), + None => Err("Error: Clone cannot be performed"), + }, + Err(_) => Err("Error: Read lock cannot be obtained"), + }; + // geo_fence_contract + if locator + .body + .contains("5H6sLwXKBv3cdm5VVRxrvA8p5cux2Rrni5CQ4GRyYKo4b9B4") + { + println!("contract geofence"); + let contract = geo_fence_contract::geo_fence_contract::GeoFenceContract::new(); + // Parse the geofence data from the policy body + if let Some(body) = policy_body { + if body.len() >= 24 { + // Ensure we have enough bytes for the geofence data + let geofence = geo_fence_contract::geo_fence_contract::Geofence3D { + min_latitude: i32::from_be_bytes([ + body[0], body[1], body[2], body[3], + ]) as i64, + max_latitude: i32::from_be_bytes([ + body[4], body[5], body[6], body[7], + ]) as i64, + min_longitude: i32::from_be_bytes([ + body[8], body[9], body[10], body[11], + ]) as i64, + max_longitude: i32::from_be_bytes([ + body[12], body[13], body[14], body[15], + ]) as i64, + min_altitude: i32::from_be_bytes([ + body[16], body[17], body[18], body[19], + ]) as i64, + max_altitude: i32::from_be_bytes([ + body[20], body[21], body[22], body[23], + ]) as i64, + }; + + // For this example, we'll use a fixed coordinate. In a real scenario, + // you might want to get this from the claims or another source. + let coordinate = geo_fence_contract::geo_fence_contract::Coordinate3D { + latitude: 374305000, + longitude: -1221015000, + altitude: 1000, + }; + + if claims_result.is_ok() + && !contract.is_within_geofence(geofence, coordinate) + { + // binary response for DENY + let mut response_data: Vec = Vec::new(); + response_data.push(MessageType::RewrappedKey as u8); + response_data.extend_from_slice(tdf_ephemeral_key_bytes); + // timing + let total_time = start_time.elapsed(); + log_timing(settings, "Time to deny", total_time); + // DENY + return Some(Message::Binary(response_data)); + } + } + } + // let geofence = geo_fence_contract::geo_fence_contract::Geofence3D { + // min_latitude: -10_000_000, + // max_latitude: 10_000_000, + // min_longitude: -20_000_000, + // max_longitude: 20_000_000, + // min_altitude: 0, + // max_altitude: 100_000_000, + // }; + // let coordinate = geo_fence_contract::geo_fence_contract::Coordinate3D { + // latitude: 0, + // longitude: 0, + // altitude: 50_000_000, + // }; + // if claims_result.is_ok() + // && !contract.is_within_geofence(geofence, coordinate) + // { + // // binary response + // let mut response_data: Vec = Vec::new(); + // response_data.push(MessageType::RewrappedKey as u8); + // response_data.extend_from_slice(tdf_ephemeral_key_bytes); + // // timing + // let total_time = start_time.elapsed(); + // log_timing(settings, "Time to deny", total_time); + // // DENY + // return Some(Message::Binary(response_data)); + // } + } + // simple_abac + else if locator + .body + .contains("5Cqk3ERPToSMuY8UoKJtcmo4fs1iVyQpq6ndzWzpzWezAF1W") + { + let contract = contract_simple_abac::simple_abac::SimpleAbac::new(); + if claims_result.is_ok() + && !contract.check_access(claims_result.unwrap(), locator.body.clone()) + { + // binary response + let mut response_data = Vec::new(); + response_data.push(MessageType::RewrappedKey as u8); + response_data.extend_from_slice(tdf_ephemeral_key_bytes); + // timing + let total_time = start_time.elapsed(); + log_timing(settings, "Time to deny", total_time); + // DENY + return Some(Message::Binary(response_data)); + } + } } } } @@ -750,6 +868,7 @@ async fn handle_event(server_state: &Arc, payload: &[u8]) -> Option return None; } }; + // if cache miss then route to device } } EventData::CacheEvent => { diff --git a/src/lib.rs b/src/lib.rs index 03f1dcb..7e1bd1b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -72,15 +72,15 @@ struct SymmetricAndPayloadConfig { } #[derive(Debug)] -enum PolicyType { +pub enum PolicyType { Remote, Embedded, } #[derive(Debug)] pub struct Policy { - policy_type: PolicyType, - body: Option>, + pub policy_type: PolicyType, + pub body: Option>, remote: Option, // TODO change to PolicyBindingConfig binding: Option>, @@ -134,7 +134,7 @@ struct Payload { pub struct BinaryParser<'a> { data: &'a [u8], - position: usize, + pub position: usize, } impl<'a> BinaryParser<'a> { From 45da2d1bf6332a00c066e726457d6fdecbd56fa9 Mon Sep 17 00:00:00 2001 From: Paul Flynn Date: Sun, 20 Oct 2024 19:17:42 -0400 Subject: [PATCH 06/15] Enhance event handling with NATS integration Updated the `handle_event` function to include NATS connection for routing events to NATS. Improved error handling and added `RouteEvent` support in event schema. Furthermore, cleaned up deprecated code formatting and streamlined field additions in FbsBuilder. --- Cargo.toml | 2 +- README.md | 6 +- src/bin/main.rs | 51 +- src/bin/schemas/event_generated.rs | 768 +++++++++++++++++------------ 4 files changed, 515 insertions(+), 312 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 7df3f00..034b900 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -47,7 +47,7 @@ redis = { version = "0.27.2", features = ["tokio-comp"] } flatbuffers = "24.3.25" scale = { package = "parity-scale-codec", version = "3.6.12", default-features = false, features = ["derive"] } scale-info = { version = "2.11.3", default-features = false, features = ["derive"], optional = true } - +bs58 = "0.5.1" [dev-dependencies] criterion = "0.5.1" diff --git a/README.md b/README.md index cd775ec..c33f591 100644 --- a/README.md +++ b/README.md @@ -123,9 +123,9 @@ redis-server #### Start backend - ```shell - cargo run - ``` +```shell +cargo run +``` The server will start and listen on the configured port. diff --git a/src/bin/main.rs b/src/bin/main.rs index 0f2758f..1ea9eb0 100644 --- a/src/bin/main.rs +++ b/src/bin/main.rs @@ -437,7 +437,7 @@ async fn handle_binary_message( ) .await } // internal - Some(MessageType::Event) => handle_event(server_state, payload).await, // embedded + Some(MessageType::Event) => handle_event(server_state, payload, nats_connection).await, // embedded None => { // println!("Unknown message type: {:?}", message_type); None @@ -822,7 +822,7 @@ async fn handle_nats_message( Ok(()) } -async fn handle_event(server_state: &Arc, payload: &[u8]) -> Option { +async fn handle_event(server_state: &Arc, payload: &[u8], nats_connection: Arc,) -> Option { let start_time = Instant::now(); let mut event_data: Option> = None; if let Ok(event) = root::(payload) { @@ -868,7 +868,7 @@ async fn handle_event(server_state: &Arc, payload: &[u8]) -> Option return None; } }; - // if cache miss then route to device + // TODO if cache miss then route to device } } EventData::CacheEvent => { @@ -923,11 +923,52 @@ async fn handle_event(server_state: &Arc, payload: &[u8]) -> Option event_data = Some(cache_event.target_payload().unwrap().bytes().to_vec()); } } + EventData::RouteEvent => { + if let Some(route_event) = event.data_as_route_event() { + if let Some(target_id) = route_event.target_id() { + println!("Route Event:"); + println!(" Target ID: {:?}", target_id); + let public_id = bs58::encode(target_id.bytes()).into_string(); + println!(" Public ID: {}", public_id); + let subject = format!("profile.{}", public_id); + println!(" subject: {}", subject); + // Create NATS message + // Create NATS message + let nats_message = match NATSMessage::new(payload) { + Ok(msg) => msg, + Err(e) => { + error!("Failed to create NATS message: {}", e); + return None; + } + }; + // Get NATS client + if let Some(nats_client) = nats_connection.get_client().await { + // Send the event to NATS + match nats_message.send_to_nats(&nats_client, subject).await { + Ok(_) => { + println!("Successfully sent route event to NATS"); + return None; + } + Err(e) => { + error!("Failed to send route event to NATS: {}", e); + return None; + } + } + } else { + error!("NATS client not available"); + return None; + } + } else { + error!("Target ID is missing."); + return None; + } + } + } EventData::NONE => { - println!("No event data"); + error!("No event data"); } _ => { - println!("Unknown event data type: {:?}", event.data_type()); + error!("Unknown event data type: {:?}", event.data_type()); } } } else { diff --git a/src/bin/schemas/event_generated.rs b/src/bin/schemas/event_generated.rs index 0f98049..6463cc3 100644 --- a/src/bin/schemas/event_generated.rs +++ b/src/bin/schemas/event_generated.rs @@ -9,20 +9,11 @@ pub mod arkavo { extern crate flatbuffers; use self::flatbuffers::Follow; - #[deprecated( - since = "2.0.0", - note = "Use associated constants instead. This will no longer be generated in 2021." - )] + #[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")] pub const ENUM_MIN_ACTION: i8 = 0; - #[deprecated( - since = "2.0.0", - note = "Use associated constants instead. This will no longer be generated in 2021." - )] + #[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")] pub const ENUM_MAX_ACTION: i8 = 8; - #[deprecated( - since = "2.0.0", - note = "Use associated constants instead. This will no longer be generated in 2021." - )] + #[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")] #[allow(non_camel_case_types)] pub const ENUM_VALUES_ACTION: [Action; 9] = [ Action::unused, @@ -120,11 +111,10 @@ pub mod arkavo { } } - impl flatbuffers::Verifiable for Action { + impl<'a> flatbuffers::Verifiable for Action { #[inline] fn run_verifier( - v: &mut flatbuffers::Verifier, - pos: usize, + v: &mut flatbuffers::Verifier, pos: usize ) -> Result<(), flatbuffers::InvalidFlatbuffer> { use self::flatbuffers::Verifiable; i8::run_verifier(v, pos) @@ -132,20 +122,11 @@ pub mod arkavo { } impl flatbuffers::SimpleToVerifyInSlice for Action {} - #[deprecated( - since = "2.0.0", - note = "Use associated constants instead. This will no longer be generated in 2021." - )] + #[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")] pub const ENUM_MIN_ACTION_STATUS: i8 = 0; - #[deprecated( - since = "2.0.0", - note = "Use associated constants instead. This will no longer be generated in 2021." - )] + #[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")] pub const ENUM_MAX_ACTION_STATUS: i8 = 4; - #[deprecated( - since = "2.0.0", - note = "Use associated constants instead. This will no longer be generated in 2021." - )] + #[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")] #[allow(non_camel_case_types)] pub const ENUM_VALUES_ACTION_STATUS: [ActionStatus; 5] = [ ActionStatus::unused, @@ -227,11 +208,10 @@ pub mod arkavo { } } - impl flatbuffers::Verifiable for ActionStatus { + impl<'a> flatbuffers::Verifiable for ActionStatus { #[inline] fn run_verifier( - v: &mut flatbuffers::Verifier, - pos: usize, + v: &mut flatbuffers::Verifier, pos: usize ) -> Result<(), flatbuffers::InvalidFlatbuffer> { use self::flatbuffers::Verifiable; i8::run_verifier(v, pos) @@ -239,25 +219,17 @@ pub mod arkavo { } impl flatbuffers::SimpleToVerifyInSlice for ActionStatus {} - #[deprecated( - since = "2.0.0", - note = "Use associated constants instead. This will no longer be generated in 2021." - )] + #[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")] pub const ENUM_MIN_ENTITY_TYPE: i8 = 0; - #[deprecated( - since = "2.0.0", - note = "Use associated constants instead. This will no longer be generated in 2021." - )] - pub const ENUM_MAX_ENTITY_TYPE: i8 = 2; - #[deprecated( - since = "2.0.0", - note = "Use associated constants instead. This will no longer be generated in 2021." - )] + #[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")] + pub const ENUM_MAX_ENTITY_TYPE: i8 = 3; + #[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")] #[allow(non_camel_case_types)] - pub const ENUM_VALUES_ENTITY_TYPE: [EntityType; 3] = [ + pub const ENUM_VALUES_ENTITY_TYPE: [EntityType; 4] = [ EntityType::unused, EntityType::stream_profile, EntityType::account_profile, + EntityType::server, ]; #[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Default)] @@ -268,17 +240,23 @@ pub mod arkavo { pub const unused: Self = Self(0); pub const stream_profile: Self = Self(1); pub const account_profile: Self = Self(2); + pub const server: Self = Self(3); pub const ENUM_MIN: i8 = 0; - pub const ENUM_MAX: i8 = 2; - pub const ENUM_VALUES: &'static [Self] = - &[Self::unused, Self::stream_profile, Self::account_profile]; + pub const ENUM_MAX: i8 = 3; + pub const ENUM_VALUES: &'static [Self] = &[ + Self::unused, + Self::stream_profile, + Self::account_profile, + Self::server, + ]; /// Returns the variant's name or "" if unknown. pub fn variant_name(self) -> Option<&'static str> { match self { Self::unused => Some("unused"), Self::stream_profile => Some("stream_profile"), Self::account_profile => Some("account_profile"), + Self::server => Some("server"), _ => None, } } @@ -323,11 +301,10 @@ pub mod arkavo { } } - impl flatbuffers::Verifiable for EntityType { + impl<'a> flatbuffers::Verifiable for EntityType { #[inline] fn run_verifier( - v: &mut flatbuffers::Verifier, - pos: usize, + v: &mut flatbuffers::Verifier, pos: usize ) -> Result<(), flatbuffers::InvalidFlatbuffer> { use self::flatbuffers::Verifiable; i8::run_verifier(v, pos) @@ -335,23 +312,107 @@ pub mod arkavo { } impl flatbuffers::SimpleToVerifyInSlice for EntityType {} - #[deprecated( - since = "2.0.0", - note = "Use associated constants instead. This will no longer be generated in 2021." - )] + #[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")] + pub const ENUM_MIN_ATTRIBUTE_TYPE: i8 = 0; + #[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")] + pub const ENUM_MAX_ATTRIBUTE_TYPE: i8 = 2; + #[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")] + #[allow(non_camel_case_types)] + pub const ENUM_VALUES_ATTRIBUTE_TYPE: [AttributeType; 3] = [ + AttributeType::unused, + AttributeType::time, + AttributeType::location, + ]; + + #[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Default)] + #[repr(transparent)] + pub struct AttributeType(pub i8); + #[allow(non_upper_case_globals)] + impl AttributeType { + pub const unused: Self = Self(0); + pub const time: Self = Self(1); + pub const location: Self = Self(2); + + pub const ENUM_MIN: i8 = 0; + pub const ENUM_MAX: i8 = 2; + pub const ENUM_VALUES: &'static [Self] = &[ + Self::unused, + Self::time, + Self::location, + ]; + /// Returns the variant's name or "" if unknown. + pub fn variant_name(self) -> Option<&'static str> { + match self { + Self::unused => Some("unused"), + Self::time => Some("time"), + Self::location => Some("location"), + _ => None, + } + } + } + impl core::fmt::Debug for AttributeType { + fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result { + if let Some(name) = self.variant_name() { + f.write_str(name) + } else { + f.write_fmt(format_args!("", self.0)) + } + } + } + impl<'a> flatbuffers::Follow<'a> for AttributeType { + type Inner = Self; + #[inline] + unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { + let b = flatbuffers::read_scalar_at::(buf, loc); + Self(b) + } + } + + impl flatbuffers::Push for AttributeType { + type Output = AttributeType; + #[inline] + unsafe fn push(&self, dst: &mut [u8], _written_len: usize) { + flatbuffers::emplace_scalar::(dst, self.0); + } + } + + impl flatbuffers::EndianScalar for AttributeType { + type Scalar = i8; + #[inline] + fn to_little_endian(self) -> i8 { + self.0.to_le() + } + #[inline] + #[allow(clippy::wrong_self_convention)] + fn from_little_endian(v: i8) -> Self { + let b = i8::from_le(v); + Self(b) + } + } + + impl<'a> flatbuffers::Verifiable for AttributeType { + #[inline] + fn run_verifier( + v: &mut flatbuffers::Verifier, pos: usize + ) -> Result<(), flatbuffers::InvalidFlatbuffer> { + use self::flatbuffers::Verifiable; + i8::run_verifier(v, pos) + } + } + + impl flatbuffers::SimpleToVerifyInSlice for AttributeType {} + #[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")] pub const ENUM_MIN_EVENT_DATA: u8 = 0; - #[deprecated( - since = "2.0.0", - note = "Use associated constants instead. This will no longer be generated in 2021." - )] - pub const ENUM_MAX_EVENT_DATA: u8 = 2; - #[deprecated( - since = "2.0.0", - note = "Use associated constants instead. This will no longer be generated in 2021." - )] + #[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")] + pub const ENUM_MAX_EVENT_DATA: u8 = 3; + #[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")] #[allow(non_camel_case_types)] - pub const ENUM_VALUES_EVENT_DATA: [EventData; 3] = - [EventData::NONE, EventData::UserEvent, EventData::CacheEvent]; + pub const ENUM_VALUES_EVENT_DATA: [EventData; 4] = [ + EventData::NONE, + EventData::UserEvent, + EventData::CacheEvent, + EventData::RouteEvent, + ]; #[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Default)] #[repr(transparent)] @@ -361,16 +422,23 @@ pub mod arkavo { pub const NONE: Self = Self(0); pub const UserEvent: Self = Self(1); pub const CacheEvent: Self = Self(2); + pub const RouteEvent: Self = Self(3); pub const ENUM_MIN: u8 = 0; - pub const ENUM_MAX: u8 = 2; - pub const ENUM_VALUES: &'static [Self] = &[Self::NONE, Self::UserEvent, Self::CacheEvent]; + pub const ENUM_MAX: u8 = 3; + pub const ENUM_VALUES: &'static [Self] = &[ + Self::NONE, + Self::UserEvent, + Self::CacheEvent, + Self::RouteEvent, + ]; /// Returns the variant's name or "" if unknown. pub fn variant_name(self) -> Option<&'static str> { match self { Self::NONE => Some("NONE"), Self::UserEvent => Some("UserEvent"), Self::CacheEvent => Some("CacheEvent"), + Self::RouteEvent => Some("RouteEvent"), _ => None, } } @@ -415,11 +483,10 @@ pub mod arkavo { } } - impl flatbuffers::Verifiable for EventData { + impl<'a> flatbuffers::Verifiable for EventData { #[inline] fn run_verifier( - v: &mut flatbuffers::Verifier, - pos: usize, + v: &mut flatbuffers::Verifier, pos: usize ) -> Result<(), flatbuffers::InvalidFlatbuffer> { use self::flatbuffers::Verifiable; u8::run_verifier(v, pos) @@ -440,9 +507,7 @@ pub mod arkavo { type Inner = UserEvent<'a>; #[inline] unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { - Self { - _tab: flatbuffers::Table::new(buf, loc), - } + Self { _tab: flatbuffers::Table::new(buf, loc) } } } @@ -451,102 +516,85 @@ pub mod arkavo { pub const VT_TARGET_TYPE: flatbuffers::VOffsetT = 6; pub const VT_SOURCE_ID: flatbuffers::VOffsetT = 8; pub const VT_TARGET_ID: flatbuffers::VOffsetT = 10; + pub const VT_ATTRIBUTE_TYPE: flatbuffers::VOffsetT = 12; + pub const VT_ENTITY_TYPE: flatbuffers::VOffsetT = 14; #[inline] pub unsafe fn init_from_table(table: flatbuffers::Table<'a>) -> Self { UserEvent { _tab: table } } #[allow(unused_mut)] - pub fn create< - 'bldr: 'args, - 'args: 'mut_bldr, - 'mut_bldr, - A: flatbuffers::Allocator + 'bldr, - >( + pub fn create<'bldr: 'args, 'args: 'mut_bldr, 'mut_bldr, A: flatbuffers::Allocator + 'bldr>( _fbb: &'mut_bldr mut flatbuffers::FlatBufferBuilder<'bldr, A>, - args: &'args UserEventArgs<'args>, + args: &'args UserEventArgs<'args> ) -> flatbuffers::WIPOffset> { let mut builder = UserEventBuilder::new(_fbb); - if let Some(x) = args.target_id { - builder.add_target_id(x); - } - if let Some(x) = args.source_id { - builder.add_source_id(x); - } + if let Some(x) = args.attribute_type { builder.add_attribute_type(x); } + if let Some(x) = args.target_id { builder.add_target_id(x); } + if let Some(x) = args.source_id { builder.add_source_id(x); } + builder.add_entity_type(args.entity_type); builder.add_target_type(args.target_type); builder.add_source_type(args.source_type); builder.finish() } + #[inline] pub fn source_type(&self) -> EntityType { // Safety: // Created from valid Table for this object // which contains a valid value in this slot - unsafe { - self._tab - .get::(UserEvent::VT_SOURCE_TYPE, Some(EntityType::unused)) - .unwrap() - } + unsafe { self._tab.get::(UserEvent::VT_SOURCE_TYPE, Some(EntityType::unused)).unwrap()} } #[inline] pub fn target_type(&self) -> EntityType { // Safety: // Created from valid Table for this object // which contains a valid value in this slot - unsafe { - self._tab - .get::(UserEvent::VT_TARGET_TYPE, Some(EntityType::unused)) - .unwrap() - } + unsafe { self._tab.get::(UserEvent::VT_TARGET_TYPE, Some(EntityType::unused)).unwrap()} } #[inline] pub fn source_id(&self) -> Option> { // Safety: // Created from valid Table for this object // which contains a valid value in this slot - unsafe { - self._tab - .get::>>( - UserEvent::VT_SOURCE_ID, - None, - ) - } + unsafe { self._tab.get::>>(UserEvent::VT_SOURCE_ID, None)} } #[inline] pub fn target_id(&self) -> Option> { // Safety: // Created from valid Table for this object // which contains a valid value in this slot - unsafe { - self._tab - .get::>>( - UserEvent::VT_TARGET_ID, - None, - ) - } + unsafe { self._tab.get::>>(UserEvent::VT_TARGET_ID, None)} + } + #[inline] + pub fn attribute_type(&self) -> Option> { + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { self._tab.get::>>(UserEvent::VT_ATTRIBUTE_TYPE, None)} + } + #[inline] + pub fn entity_type(&self) -> EntityType { + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { self._tab.get::(UserEvent::VT_ENTITY_TYPE, Some(EntityType::unused)).unwrap()} } } impl flatbuffers::Verifiable for UserEvent<'_> { #[inline] fn run_verifier( - v: &mut flatbuffers::Verifier, - pos: usize, + v: &mut flatbuffers::Verifier, pos: usize ) -> Result<(), flatbuffers::InvalidFlatbuffer> { v.visit_table(pos)? .visit_field::("source_type", Self::VT_SOURCE_TYPE, false)? .visit_field::("target_type", Self::VT_TARGET_TYPE, false)? - .visit_field::>>( - "source_id", - Self::VT_SOURCE_ID, - false, - )? - .visit_field::>>( - "target_id", - Self::VT_TARGET_ID, - false, - )? + .visit_field::>>("source_id", Self::VT_SOURCE_ID, false)? + .visit_field::>>("target_id", Self::VT_TARGET_ID, false)? + .visit_field::>>("attribute_type", Self::VT_ATTRIBUTE_TYPE, false)? + .visit_field::("entity_type", Self::VT_ENTITY_TYPE, false)? .finish(); Ok(()) } @@ -556,6 +604,8 @@ pub mod arkavo { pub target_type: EntityType, pub source_id: Option>>, pub target_id: Option>>, + pub attribute_type: Option>>, + pub entity_type: EntityType, } impl<'a> Default for UserEventArgs<'a> { #[inline] @@ -565,6 +615,8 @@ pub mod arkavo { target_type: EntityType::unused, source_id: None, target_id: None, + attribute_type: None, + entity_type: EntityType::unused, } } } @@ -576,40 +628,30 @@ pub mod arkavo { impl<'a: 'b, 'b, A: flatbuffers::Allocator + 'a> UserEventBuilder<'a, 'b, A> { #[inline] pub fn add_source_type(&mut self, source_type: EntityType) { - self.fbb_.push_slot::( - UserEvent::VT_SOURCE_TYPE, - source_type, - EntityType::unused, - ); + self.fbb_.push_slot::(UserEvent::VT_SOURCE_TYPE, source_type, EntityType::unused); } #[inline] pub fn add_target_type(&mut self, target_type: EntityType) { - self.fbb_.push_slot::( - UserEvent::VT_TARGET_TYPE, - target_type, - EntityType::unused, - ); + self.fbb_.push_slot::(UserEvent::VT_TARGET_TYPE, target_type, EntityType::unused); + } + #[inline] + pub fn add_source_id(&mut self, source_id: flatbuffers::WIPOffset>) { + self.fbb_.push_slot_always::>(UserEvent::VT_SOURCE_ID, source_id); + } + #[inline] + pub fn add_target_id(&mut self, target_id: flatbuffers::WIPOffset>) { + self.fbb_.push_slot_always::>(UserEvent::VT_TARGET_ID, target_id); } #[inline] - pub fn add_source_id( - &mut self, - source_id: flatbuffers::WIPOffset>, - ) { - self.fbb_ - .push_slot_always::>(UserEvent::VT_SOURCE_ID, source_id); + pub fn add_attribute_type(&mut self, attribute_type: flatbuffers::WIPOffset>) { + self.fbb_.push_slot_always::>(UserEvent::VT_ATTRIBUTE_TYPE, attribute_type); } #[inline] - pub fn add_target_id( - &mut self, - target_id: flatbuffers::WIPOffset>, - ) { - self.fbb_ - .push_slot_always::>(UserEvent::VT_TARGET_ID, target_id); + pub fn add_entity_type(&mut self, entity_type: EntityType) { + self.fbb_.push_slot::(UserEvent::VT_ENTITY_TYPE, entity_type, EntityType::unused); } #[inline] - pub fn new( - _fbb: &'b mut flatbuffers::FlatBufferBuilder<'a, A>, - ) -> UserEventBuilder<'a, 'b, A> { + pub fn new(_fbb: &'b mut flatbuffers::FlatBufferBuilder<'a, A>) -> UserEventBuilder<'a, 'b, A> { let start = _fbb.start_table(); UserEventBuilder { fbb_: _fbb, @@ -630,6 +672,8 @@ pub mod arkavo { ds.field("target_type", &self.target_type()); ds.field("source_id", &self.source_id()); ds.field("target_id", &self.target_id()); + ds.field("attribute_type", &self.attribute_type()); + ds.field("entity_type", &self.entity_type()); ds.finish() } } @@ -644,9 +688,7 @@ pub mod arkavo { type Inner = CacheEvent<'a>; #[inline] unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { - Self { - _tab: flatbuffers::Table::new(buf, loc), - } + Self { _tab: flatbuffers::Table::new(buf, loc) } } } @@ -661,90 +703,57 @@ pub mod arkavo { CacheEvent { _tab: table } } #[allow(unused_mut)] - pub fn create< - 'bldr: 'args, - 'args: 'mut_bldr, - 'mut_bldr, - A: flatbuffers::Allocator + 'bldr, - >( + pub fn create<'bldr: 'args, 'args: 'mut_bldr, 'mut_bldr, A: flatbuffers::Allocator + 'bldr>( _fbb: &'mut_bldr mut flatbuffers::FlatBufferBuilder<'bldr, A>, - args: &'args CacheEventArgs<'args>, + args: &'args CacheEventArgs<'args> ) -> flatbuffers::WIPOffset> { let mut builder = CacheEventBuilder::new(_fbb); builder.add_ttl(args.ttl); - if let Some(x) = args.target_payload { - builder.add_target_payload(x); - } - if let Some(x) = args.target_id { - builder.add_target_id(x); - } + if let Some(x) = args.target_payload { builder.add_target_payload(x); } + if let Some(x) = args.target_id { builder.add_target_id(x); } builder.add_one_time_access(args.one_time_access); builder.finish() } + #[inline] pub fn target_id(&self) -> Option> { // Safety: // Created from valid Table for this object // which contains a valid value in this slot - unsafe { - self._tab - .get::>>( - CacheEvent::VT_TARGET_ID, - None, - ) - } + unsafe { self._tab.get::>>(CacheEvent::VT_TARGET_ID, None)} } #[inline] pub fn target_payload(&self) -> Option> { // Safety: // Created from valid Table for this object // which contains a valid value in this slot - unsafe { - self._tab - .get::>>( - CacheEvent::VT_TARGET_PAYLOAD, - None, - ) - } + unsafe { self._tab.get::>>(CacheEvent::VT_TARGET_PAYLOAD, None)} } #[inline] pub fn ttl(&self) -> u32 { // Safety: // Created from valid Table for this object // which contains a valid value in this slot - unsafe { self._tab.get::(CacheEvent::VT_TTL, Some(0)).unwrap() } + unsafe { self._tab.get::(CacheEvent::VT_TTL, Some(0)).unwrap()} } #[inline] pub fn one_time_access(&self) -> bool { // Safety: // Created from valid Table for this object // which contains a valid value in this slot - unsafe { - self._tab - .get::(CacheEvent::VT_ONE_TIME_ACCESS, Some(false)) - .unwrap() - } + unsafe { self._tab.get::(CacheEvent::VT_ONE_TIME_ACCESS, Some(false)).unwrap()} } } impl flatbuffers::Verifiable for CacheEvent<'_> { #[inline] fn run_verifier( - v: &mut flatbuffers::Verifier, - pos: usize, + v: &mut flatbuffers::Verifier, pos: usize ) -> Result<(), flatbuffers::InvalidFlatbuffer> { v.visit_table(pos)? - .visit_field::>>( - "target_id", - Self::VT_TARGET_ID, - false, - )? - .visit_field::>>( - "target_payload", - Self::VT_TARGET_PAYLOAD, - false, - )? + .visit_field::>>("target_id", Self::VT_TARGET_ID, false)? + .visit_field::>>("target_payload", Self::VT_TARGET_PAYLOAD, false)? .visit_field::("ttl", Self::VT_TTL, false)? .visit_field::("one_time_access", Self::VT_ONE_TIME_ACCESS, false)? .finish(); @@ -775,22 +784,12 @@ pub mod arkavo { } impl<'a: 'b, 'b, A: flatbuffers::Allocator + 'a> CacheEventBuilder<'a, 'b, A> { #[inline] - pub fn add_target_id( - &mut self, - target_id: flatbuffers::WIPOffset>, - ) { - self.fbb_ - .push_slot_always::>(CacheEvent::VT_TARGET_ID, target_id); + pub fn add_target_id(&mut self, target_id: flatbuffers::WIPOffset>) { + self.fbb_.push_slot_always::>(CacheEvent::VT_TARGET_ID, target_id); } #[inline] - pub fn add_target_payload( - &mut self, - target_payload: flatbuffers::WIPOffset>, - ) { - self.fbb_.push_slot_always::>( - CacheEvent::VT_TARGET_PAYLOAD, - target_payload, - ); + pub fn add_target_payload(&mut self, target_payload: flatbuffers::WIPOffset>) { + self.fbb_.push_slot_always::>(CacheEvent::VT_TARGET_PAYLOAD, target_payload); } #[inline] pub fn add_ttl(&mut self, ttl: u32) { @@ -798,13 +797,10 @@ pub mod arkavo { } #[inline] pub fn add_one_time_access(&mut self, one_time_access: bool) { - self.fbb_ - .push_slot::(CacheEvent::VT_ONE_TIME_ACCESS, one_time_access, false); + self.fbb_.push_slot::(CacheEvent::VT_ONE_TIME_ACCESS, one_time_access, false); } #[inline] - pub fn new( - _fbb: &'b mut flatbuffers::FlatBufferBuilder<'a, A>, - ) -> CacheEventBuilder<'a, 'b, A> { + pub fn new(_fbb: &'b mut flatbuffers::FlatBufferBuilder<'a, A>) -> CacheEventBuilder<'a, 'b, A> { let start = _fbb.start_table(); CacheEventBuilder { fbb_: _fbb, @@ -828,6 +824,204 @@ pub mod arkavo { ds.finish() } } + pub enum RouteEventOffset {} + #[derive(Copy, Clone, PartialEq)] + + pub struct RouteEvent<'a> { + pub _tab: flatbuffers::Table<'a>, + } + + impl<'a> flatbuffers::Follow<'a> for RouteEvent<'a> { + type Inner = RouteEvent<'a>; + #[inline] + unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { + Self { _tab: flatbuffers::Table::new(buf, loc) } + } + } + + impl<'a> RouteEvent<'a> { + pub const VT_TARGET_TYPE: flatbuffers::VOffsetT = 4; + pub const VT_TARGET_ID: flatbuffers::VOffsetT = 6; + pub const VT_SOURCE_TYPE: flatbuffers::VOffsetT = 8; + pub const VT_SOURCE_ID: flatbuffers::VOffsetT = 10; + pub const VT_ATTRIBUTE_TYPE: flatbuffers::VOffsetT = 12; + pub const VT_ENTITY_TYPE: flatbuffers::VOffsetT = 14; + pub const VT_PAYLOAD: flatbuffers::VOffsetT = 16; + + #[inline] + pub unsafe fn init_from_table(table: flatbuffers::Table<'a>) -> Self { + RouteEvent { _tab: table } + } + #[allow(unused_mut)] + pub fn create<'bldr: 'args, 'args: 'mut_bldr, 'mut_bldr, A: flatbuffers::Allocator + 'bldr>( + _fbb: &'mut_bldr mut flatbuffers::FlatBufferBuilder<'bldr, A>, + args: &'args RouteEventArgs<'args> + ) -> flatbuffers::WIPOffset> { + let mut builder = RouteEventBuilder::new(_fbb); + if let Some(x) = args.payload { builder.add_payload(x); } + if let Some(x) = args.source_id { builder.add_source_id(x); } + if let Some(x) = args.target_id { builder.add_target_id(x); } + builder.add_entity_type(args.entity_type); + builder.add_attribute_type(args.attribute_type); + builder.add_source_type(args.source_type); + builder.add_target_type(args.target_type); + builder.finish() + } + + + #[inline] + pub fn target_type(&self) -> EntityType { + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { self._tab.get::(RouteEvent::VT_TARGET_TYPE, Some(EntityType::unused)).unwrap()} + } + #[inline] + pub fn target_id(&self) -> Option> { + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { self._tab.get::>>(RouteEvent::VT_TARGET_ID, None)} + } + #[inline] + pub fn source_type(&self) -> EntityType { + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { self._tab.get::(RouteEvent::VT_SOURCE_TYPE, Some(EntityType::unused)).unwrap()} + } + #[inline] + pub fn source_id(&self) -> Option> { + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { self._tab.get::>>(RouteEvent::VT_SOURCE_ID, None)} + } + #[inline] + pub fn attribute_type(&self) -> AttributeType { + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { self._tab.get::(RouteEvent::VT_ATTRIBUTE_TYPE, Some(AttributeType::unused)).unwrap()} + } + #[inline] + pub fn entity_type(&self) -> EntityType { + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { self._tab.get::(RouteEvent::VT_ENTITY_TYPE, Some(EntityType::unused)).unwrap()} + } + #[inline] + pub fn payload(&self) -> Option> { + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { self._tab.get::>>(RouteEvent::VT_PAYLOAD, None)} + } + } + + impl flatbuffers::Verifiable for RouteEvent<'_> { + #[inline] + fn run_verifier( + v: &mut flatbuffers::Verifier, pos: usize + ) -> Result<(), flatbuffers::InvalidFlatbuffer> { + v.visit_table(pos)? + .visit_field::("target_type", Self::VT_TARGET_TYPE, false)? + .visit_field::>>("target_id", Self::VT_TARGET_ID, false)? + .visit_field::("source_type", Self::VT_SOURCE_TYPE, false)? + .visit_field::>>("source_id", Self::VT_SOURCE_ID, false)? + .visit_field::("attribute_type", Self::VT_ATTRIBUTE_TYPE, false)? + .visit_field::("entity_type", Self::VT_ENTITY_TYPE, false)? + .visit_field::>>("payload", Self::VT_PAYLOAD, false)? + .finish(); + Ok(()) + } + } + pub struct RouteEventArgs<'a> { + pub target_type: EntityType, + pub target_id: Option>>, + pub source_type: EntityType, + pub source_id: Option>>, + pub attribute_type: AttributeType, + pub entity_type: EntityType, + pub payload: Option>>, + } + impl<'a> Default for RouteEventArgs<'a> { + #[inline] + fn default() -> Self { + RouteEventArgs { + target_type: EntityType::unused, + target_id: None, + source_type: EntityType::unused, + source_id: None, + attribute_type: AttributeType::unused, + entity_type: EntityType::unused, + payload: None, + } + } + } + + pub struct RouteEventBuilder<'a: 'b, 'b, A: flatbuffers::Allocator + 'a> { + fbb_: &'b mut flatbuffers::FlatBufferBuilder<'a, A>, + start_: flatbuffers::WIPOffset, + } + impl<'a: 'b, 'b, A: flatbuffers::Allocator + 'a> RouteEventBuilder<'a, 'b, A> { + #[inline] + pub fn add_target_type(&mut self, target_type: EntityType) { + self.fbb_.push_slot::(RouteEvent::VT_TARGET_TYPE, target_type, EntityType::unused); + } + #[inline] + pub fn add_target_id(&mut self, target_id: flatbuffers::WIPOffset>) { + self.fbb_.push_slot_always::>(RouteEvent::VT_TARGET_ID, target_id); + } + #[inline] + pub fn add_source_type(&mut self, source_type: EntityType) { + self.fbb_.push_slot::(RouteEvent::VT_SOURCE_TYPE, source_type, EntityType::unused); + } + #[inline] + pub fn add_source_id(&mut self, source_id: flatbuffers::WIPOffset>) { + self.fbb_.push_slot_always::>(RouteEvent::VT_SOURCE_ID, source_id); + } + #[inline] + pub fn add_attribute_type(&mut self, attribute_type: AttributeType) { + self.fbb_.push_slot::(RouteEvent::VT_ATTRIBUTE_TYPE, attribute_type, AttributeType::unused); + } + #[inline] + pub fn add_entity_type(&mut self, entity_type: EntityType) { + self.fbb_.push_slot::(RouteEvent::VT_ENTITY_TYPE, entity_type, EntityType::unused); + } + #[inline] + pub fn add_payload(&mut self, payload: flatbuffers::WIPOffset>) { + self.fbb_.push_slot_always::>(RouteEvent::VT_PAYLOAD, payload); + } + #[inline] + pub fn new(_fbb: &'b mut flatbuffers::FlatBufferBuilder<'a, A>) -> RouteEventBuilder<'a, 'b, A> { + let start = _fbb.start_table(); + RouteEventBuilder { + fbb_: _fbb, + start_: start, + } + } + #[inline] + pub fn finish(self) -> flatbuffers::WIPOffset> { + let o = self.fbb_.end_table(self.start_); + flatbuffers::WIPOffset::new(o.value()) + } + } + + impl core::fmt::Debug for RouteEvent<'_> { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + let mut ds = f.debug_struct("RouteEvent"); + ds.field("target_type", &self.target_type()); + ds.field("target_id", &self.target_id()); + ds.field("source_type", &self.source_type()); + ds.field("source_id", &self.source_id()); + ds.field("attribute_type", &self.attribute_type()); + ds.field("entity_type", &self.entity_type()); + ds.field("payload", &self.payload()); + ds.finish() + } + } pub enum EventOffset {} #[derive(Copy, Clone, PartialEq)] @@ -839,9 +1033,7 @@ pub mod arkavo { type Inner = Event<'a>; #[inline] unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { - Self { - _tab: flatbuffers::Table::new(buf, loc), - } + Self { _tab: flatbuffers::Table::new(buf, loc) } } } @@ -857,78 +1049,54 @@ pub mod arkavo { Event { _tab: table } } #[allow(unused_mut)] - pub fn create< - 'bldr: 'args, - 'args: 'mut_bldr, - 'mut_bldr, - A: flatbuffers::Allocator + 'bldr, - >( + pub fn create<'bldr: 'args, 'args: 'mut_bldr, 'mut_bldr, A: flatbuffers::Allocator + 'bldr>( _fbb: &'mut_bldr mut flatbuffers::FlatBufferBuilder<'bldr, A>, - args: &'args EventArgs, + args: &'args EventArgs ) -> flatbuffers::WIPOffset> { let mut builder = EventBuilder::new(_fbb); builder.add_timestamp(args.timestamp); - if let Some(x) = args.data { - builder.add_data(x); - } + if let Some(x) = args.data { builder.add_data(x); } builder.add_data_type(args.data_type); builder.add_status(args.status); builder.add_action(args.action); builder.finish() } + #[inline] pub fn action(&self) -> Action { // Safety: // Created from valid Table for this object // which contains a valid value in this slot - unsafe { - self._tab - .get::(Event::VT_ACTION, Some(Action::unused)) - .unwrap() - } + unsafe { self._tab.get::(Event::VT_ACTION, Some(Action::unused)).unwrap()} } #[inline] pub fn timestamp(&self) -> u64 { // Safety: // Created from valid Table for this object // which contains a valid value in this slot - unsafe { self._tab.get::(Event::VT_TIMESTAMP, Some(0)).unwrap() } + unsafe { self._tab.get::(Event::VT_TIMESTAMP, Some(0)).unwrap()} } #[inline] pub fn status(&self) -> ActionStatus { // Safety: // Created from valid Table for this object // which contains a valid value in this slot - unsafe { - self._tab - .get::(Event::VT_STATUS, Some(ActionStatus::unused)) - .unwrap() - } + unsafe { self._tab.get::(Event::VT_STATUS, Some(ActionStatus::unused)).unwrap()} } #[inline] pub fn data_type(&self) -> EventData { // Safety: // Created from valid Table for this object // which contains a valid value in this slot - unsafe { - self._tab - .get::(Event::VT_DATA_TYPE, Some(EventData::NONE)) - .unwrap() - } + unsafe { self._tab.get::(Event::VT_DATA_TYPE, Some(EventData::NONE)).unwrap()} } #[inline] pub fn data(&self) -> Option> { // Safety: // Created from valid Table for this object // which contains a valid value in this slot - unsafe { - self._tab - .get::>>( - Event::VT_DATA, - None, - ) - } + unsafe { self._tab.get::>>(Event::VT_DATA, None)} } #[inline] #[allow(non_snake_case)] @@ -959,38 +1127,41 @@ pub mod arkavo { None } } + + #[inline] + #[allow(non_snake_case)] + pub fn data_as_route_event(&self) -> Option> { + if self.data_type() == EventData::RouteEvent { + self.data().map(|t| { + // Safety: + // Created from a valid Table for this object + // Which contains a valid union in this slot + unsafe { RouteEvent::init_from_table(t) } + }) + } else { + None + } + } + } impl flatbuffers::Verifiable for Event<'_> { #[inline] fn run_verifier( - v: &mut flatbuffers::Verifier, - pos: usize, + v: &mut flatbuffers::Verifier, pos: usize ) -> Result<(), flatbuffers::InvalidFlatbuffer> { v.visit_table(pos)? .visit_field::("action", Self::VT_ACTION, false)? .visit_field::("timestamp", Self::VT_TIMESTAMP, false)? .visit_field::("status", Self::VT_STATUS, false)? - .visit_union::( - "data_type", - Self::VT_DATA_TYPE, - "data", - Self::VT_DATA, - false, - |key, v, pos| match key { - EventData::UserEvent => v - .verify_union_variant::>( - "EventData::UserEvent", - pos, - ), - EventData::CacheEvent => v - .verify_union_variant::>( - "EventData::CacheEvent", - pos, - ), + .visit_union::("data_type", Self::VT_DATA_TYPE, "data", Self::VT_DATA, false, |key, v, pos| { + match key { + EventData::UserEvent => v.verify_union_variant::>("EventData::UserEvent", pos), + EventData::CacheEvent => v.verify_union_variant::>("EventData::CacheEvent", pos), + EventData::RouteEvent => v.verify_union_variant::>("EventData::RouteEvent", pos), _ => Ok(()), - }, - )? + } + })? .finish(); Ok(()) } @@ -1002,7 +1173,7 @@ pub mod arkavo { pub data_type: EventData, pub data: Option>, } - impl Default for EventArgs { + impl<'a> Default for EventArgs { #[inline] fn default() -> Self { EventArgs { @@ -1022,28 +1193,23 @@ pub mod arkavo { impl<'a: 'b, 'b, A: flatbuffers::Allocator + 'a> EventBuilder<'a, 'b, A> { #[inline] pub fn add_action(&mut self, action: Action) { - self.fbb_ - .push_slot::(Event::VT_ACTION, action, Action::unused); + self.fbb_.push_slot::(Event::VT_ACTION, action, Action::unused); } #[inline] pub fn add_timestamp(&mut self, timestamp: u64) { - self.fbb_ - .push_slot::(Event::VT_TIMESTAMP, timestamp, 0); + self.fbb_.push_slot::(Event::VT_TIMESTAMP, timestamp, 0); } #[inline] pub fn add_status(&mut self, status: ActionStatus) { - self.fbb_ - .push_slot::(Event::VT_STATUS, status, ActionStatus::unused); + self.fbb_.push_slot::(Event::VT_STATUS, status, ActionStatus::unused); } #[inline] pub fn add_data_type(&mut self, data_type: EventData) { - self.fbb_ - .push_slot::(Event::VT_DATA_TYPE, data_type, EventData::NONE); + self.fbb_.push_slot::(Event::VT_DATA_TYPE, data_type, EventData::NONE); } #[inline] pub fn add_data(&mut self, data: flatbuffers::WIPOffset) { - self.fbb_ - .push_slot_always::>(Event::VT_DATA, data); + self.fbb_.push_slot_always::>(Event::VT_DATA, data); } #[inline] pub fn new(_fbb: &'b mut flatbuffers::FlatBufferBuilder<'a, A>) -> EventBuilder<'a, 'b, A> { @@ -1072,26 +1238,27 @@ pub mod arkavo { if let Some(x) = self.data_as_user_event() { ds.field("data", &x) } else { - ds.field( - "data", - &"InvalidFlatbuffer: Union discriminant does not match value.", - ) + ds.field("data", &"InvalidFlatbuffer: Union discriminant does not match value.") } - } + }, EventData::CacheEvent => { if let Some(x) = self.data_as_cache_event() { ds.field("data", &x) } else { - ds.field( - "data", - &"InvalidFlatbuffer: Union discriminant does not match value.", - ) + ds.field("data", &"InvalidFlatbuffer: Union discriminant does not match value.") } - } + }, + EventData::RouteEvent => { + if let Some(x) = self.data_as_route_event() { + ds.field("data", &x) + } else { + ds.field("data", &"InvalidFlatbuffer: Union discriminant does not match value.") + } + }, _ => { let x: Option<()> = None; ds.field("data", &x) - } + }, }; ds.finish() } @@ -1113,9 +1280,7 @@ pub mod arkavo { /// catch every error, or be maximally performant. For the /// previous, unchecked, behavior use /// `size_prefixed_root_as_event_unchecked`. - pub fn size_prefixed_root_as_event( - buf: &[u8], - ) -> Result { + pub fn size_prefixed_root_as_event(buf: &[u8]) -> Result { flatbuffers::size_prefixed_root::(buf) } #[inline] @@ -1161,16 +1326,13 @@ pub mod arkavo { #[inline] pub fn finish_event_buffer<'a, 'b, A: flatbuffers::Allocator + 'a>( fbb: &'b mut flatbuffers::FlatBufferBuilder<'a, A>, - root: flatbuffers::WIPOffset>, - ) { + root: flatbuffers::WIPOffset>) { fbb.finish(root, None); } #[inline] - pub fn finish_size_prefixed_event_buffer<'a, 'b, A: flatbuffers::Allocator + 'a>( - fbb: &'b mut flatbuffers::FlatBufferBuilder<'a, A>, - root: flatbuffers::WIPOffset>, - ) { + pub fn finish_size_prefixed_event_buffer<'a, 'b, A: flatbuffers::Allocator + 'a>(fbb: &'b mut flatbuffers::FlatBufferBuilder<'a, A>, root: flatbuffers::WIPOffset>) { fbb.finish_size_prefixed(root, None); } -} // pub mod Arkavo +} // pub mod Arkavo + From 6b524bb036e60bdbf76b4975edccf504f102c263 Mon Sep 17 00:00:00 2001 From: Paul Flynn Date: Sun, 20 Oct 2024 19:57:29 -0400 Subject: [PATCH 07/15] Rename `handle_nats_message` to `handle_nats_event` Refactor function and logs to use 'event' terminology instead of 'message'. Updated Cargo.toml to version 0.9.1 to reflect these changes. --- Cargo.toml | 2 +- src/bin/main.rs | 7 +++---- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 034b900..2ed1c77 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "arkavo-rs" -version = "0.9.0" +version = "0.9.1" edition = "2021" rust-version = "1.80.0" diff --git a/src/bin/main.rs b/src/bin/main.rs index 1ea9eb0..1472778 100644 --- a/src/bin/main.rs +++ b/src/bin/main.rs @@ -792,7 +792,7 @@ async fn handle_nats_subscription( Ok(mut subscription) => { info!("Subscribed to NATS subject: {}", subject); while let Some(msg) = subscription.next().await { - if let Err(e) = handle_nats_message(msg, connection_state.clone()).await { + if let Err(e) = handle_nats_event(msg, connection_state.clone()).await { error!("Error handling NATS message: {}", e); } } @@ -808,12 +808,12 @@ async fn handle_nats_subscription( tokio::time::sleep(NATS_RETRY_INTERVAL).await; } } -async fn handle_nats_message( +async fn handle_nats_event( msg: NatsMessage, connection_state: Arc, ) -> Result<(), Box> { let ws_message = Message::Binary( - vec![MessageType::Nats as u8] + vec![MessageType::Event as u8] .into_iter() .chain(msg.payload) .collect(), @@ -821,7 +821,6 @@ async fn handle_nats_message( connection_state.outgoing_tx.send(ws_message)?; Ok(()) } - async fn handle_event(server_state: &Arc, payload: &[u8], nats_connection: Arc,) -> Option { let start_time = Instant::now(); let mut event_data: Option> = None; From 30f2efb44f6359182bffb96f658ba757ac77901e Mon Sep 17 00:00:00 2001 From: Paul Flynn Date: Mon, 21 Oct 2024 22:09:13 -0400 Subject: [PATCH 08/15] Change geofence coordinates to floating-point Updated Geofence3D and Coordinate3D structs to use f64 instead of i64 for latitude, longitude, and altitude. This change improves precision for geofencing and simplifies coordinate calculations in the main code. Also adjusted test cases to align with the new floating-point coordinates. --- src/bin/contracts/geo_fence_contract.rs | 82 ++++++++++++------------- src/bin/main.rs | 36 ++++------- 2 files changed, 53 insertions(+), 65 deletions(-) diff --git a/src/bin/contracts/geo_fence_contract.rs b/src/bin/contracts/geo_fence_contract.rs index 1c40d41..65b555f 100755 --- a/src/bin/contracts/geo_fence_contract.rs +++ b/src/bin/contracts/geo_fence_contract.rs @@ -3,23 +3,23 @@ pub mod geo_fence_contract { use scale::{Decode, Encode}; - #[derive(Debug, PartialEq, Eq, Clone, Copy, Decode, Encode)] + #[derive(Debug, PartialEq, Clone, Copy, Decode, Encode)] #[cfg_attr(feature = "std", derive(scale_info::TypeInfo))] pub struct Coordinate3D { - pub latitude: i64, - pub longitude: i64, - pub altitude: i64, + pub latitude: f64, + pub longitude: f64, + pub altitude: f64, } - #[derive(Debug, PartialEq, Eq, Clone, Copy, Decode, Encode)] + #[derive(Debug, PartialEq, Clone, Copy, Decode, Encode)] #[cfg_attr(feature = "std", derive(scale_info::TypeInfo))] pub struct Geofence3D { - pub min_latitude: i64, - pub max_latitude: i64, - pub min_longitude: i64, - pub max_longitude: i64, - pub min_altitude: i64, - pub max_altitude: i64, + pub min_latitude: f64, + pub max_latitude: f64, + pub min_longitude: f64, + pub max_longitude: f64, + pub min_altitude: f64, + pub max_altitude: f64, } #[ink(storage)] @@ -54,24 +54,24 @@ pub mod geo_fence_contract { fn test_within_geofence() { let contract = GeoFenceContract::new(); let geofence = Geofence3D { - min_latitude: -10_000_000, - max_latitude: 10_000_000, - min_longitude: -20_000_000, - max_longitude: 20_000_000, - min_altitude: 0, - max_altitude: 100_000_000, + min_latitude: -10.0, + max_latitude: 10.0, + min_longitude: -20.0, + max_longitude: 20.0, + min_altitude: 0.0, + max_altitude: 100_000.0, }; assert!(contract.is_within_geofence(geofence, Coordinate3D { - latitude: 0, - longitude: 0, - altitude: 50_000_000, + latitude: 0.0, + longitude: 0.0, + altitude: 50_000.0, })); assert!(!contract.is_within_geofence(geofence, Coordinate3D { - latitude: -15_000_000, - longitude: 0, - altitude: 50_000_000, + latitude: -15.0, + longitude: 0.0, + altitude: 50_000.0, })); } @@ -79,36 +79,36 @@ pub mod geo_fence_contract { fn test_within_20ft_cube() { let contract = GeoFenceContract::new(); let geofence = Geofence3D { - min_latitude: 0, - max_latitude: 610, // Approximately 20 feet in latitude (scaled by 10^5) - min_longitude: 0, - max_longitude: 610, // Approximately 20 feet in longitude (scaled by 10^5) - min_altitude: 0, - max_altitude: 610, // 20 feet in altitude (scaled by 10^2) + min_latitude: 0.0, + max_latitude: 0.00061, // Approximately 20 feet in latitude + min_longitude: 0.0, + max_longitude: 0.00061, // Approximately 20 feet in longitude + min_altitude: 0.0, + max_altitude: 6.1, // 20 feet in altitude }; assert!(contract.is_within_geofence(geofence, Coordinate3D { - latitude: 300, - longitude: 300, - altitude: 300, + latitude: 0.0003, + longitude: 0.0003, + altitude: 3.0, })); // Inside the cube assert!(!contract.is_within_geofence(geofence, Coordinate3D { - latitude: 1000, - longitude: 300, - altitude: 300, + latitude: 0.001, + longitude: 0.0003, + altitude: 3.0, })); // Outside latitude assert!(!contract.is_within_geofence(geofence, Coordinate3D { - latitude: 300, - longitude: 1000, - altitude: 300, + latitude: 0.0003, + longitude: 0.001, + altitude: 3.0, })); // Outside longitude assert!(!contract.is_within_geofence(geofence, Coordinate3D { - latitude: 300, - longitude: 300, - altitude: 1000, + latitude: 0.0003, + longitude: 0.0003, + altitude: 10.0, })); // Outside altitude } } diff --git a/src/bin/main.rs b/src/bin/main.rs index 1472778..453abce 100644 --- a/src/bin/main.rs +++ b/src/bin/main.rs @@ -38,6 +38,7 @@ use tokio::net::TcpListener; use tokio::sync::{mpsc, Mutex}; use tokio_native_tls::TlsAcceptor; use tokio_tungstenite::tungstenite::Message; +use crate::contracts::geo_fence_contract::geo_fence_contract::Geofence3D; #[derive(Serialize, Deserialize, Debug)] struct PublicKeyMessage { @@ -548,33 +549,20 @@ async fn handle_rewrap( if let Some(body) = policy_body { if body.len() >= 24 { // Ensure we have enough bytes for the geofence data - let geofence = geo_fence_contract::geo_fence_contract::Geofence3D { - min_latitude: i32::from_be_bytes([ - body[0], body[1], body[2], body[3], - ]) as i64, - max_latitude: i32::from_be_bytes([ - body[4], body[5], body[6], body[7], - ]) as i64, - min_longitude: i32::from_be_bytes([ - body[8], body[9], body[10], body[11], - ]) as i64, - max_longitude: i32::from_be_bytes([ - body[12], body[13], body[14], body[15], - ]) as i64, - min_altitude: i32::from_be_bytes([ - body[16], body[17], body[18], body[19], - ]) as i64, - max_altitude: i32::from_be_bytes([ - body[20], body[21], body[22], body[23], - ]) as i64, + let geofence = Geofence3D { + min_latitude: 0.0, + max_latitude: 0.00061, // Approximately 20 feet in latitude + min_longitude: 0.0, + max_longitude: 0.00061, // Approximately 20 feet in longitude + min_altitude: 0.0, + max_altitude: 6.1, // 20 feet in altitude }; - // For this example, we'll use a fixed coordinate. In a real scenario, - // you might want to get this from the claims or another source. + // Get from rewrap request, second payload will be NanoTDF location let coordinate = geo_fence_contract::geo_fence_contract::Coordinate3D { - latitude: 374305000, - longitude: -1221015000, - altitude: 1000, + latitude: 0.0003, + longitude: 0.0003, + altitude: 3.0, }; if claims_result.is_ok() From 1c251cff182cf0a866acb723476f432cec211919 Mon Sep 17 00:00:00 2001 From: Paul Flynn Date: Wed, 23 Oct 2024 18:08:08 -0400 Subject: [PATCH 09/15] Add Timestamp Validator contract Introduce a new Timestamp Validator contract with basic functionality to validate timestamps. Updated the README to include deployment instructions for the new contract. --- etc/contracts/README.md | 12 +++ etc/contracts/timestamp_validator/Cargo.toml | 26 +++++++ etc/contracts/timestamp_validator/lib.rs | 79 ++++++++++++++++++++ 3 files changed, 117 insertions(+) create mode 100755 etc/contracts/timestamp_validator/Cargo.toml create mode 100755 etc/contracts/timestamp_validator/lib.rs diff --git a/etc/contracts/README.md b/etc/contracts/README.md index 6d1cb90..da49bd6 100644 --- a/etc/contracts/README.md +++ b/etc/contracts/README.md @@ -52,6 +52,18 @@ Code hash 0x63a3ec45fd3ab905924a38227917e278de277c9b80d6865190d18d0d64f560bb Contract 5H6sLwXKBv3cdm5VVRxrvA8p5cux2Rrni5CQ4GRyYKo4b9B4 ``` +#### Timestamp + +```text +Code hash 0xee2250ba4215f273e571ecdfc2a373ccc96de5f82c19fcdaca889218fac5ac39 +Contract 5D35jFeQboveKiaQSxyLKENGqrnjgUc7B4D23QbhJK4Yr7jT +``` + +```shell +cargo contract upload --url ws://127.0.0.1:9944 --suri //Alice timestamp_validator/target/ink/timestamp_validator.wasm +cargo contract instantiate --url ws://127.0.0.1:9944 --suri //Alice timestamp_validator/target/ink/timestamp_validator.wasm --execute +``` + ```shell cargo contract upload --url ws://127.0.0.1:9944 --suri //Alice geo_fence_contract/target/ink/geo_fence_contract.wasm cargo contract instantiate --url ws://127.0.0.1:9944 --suri //Alice geo_fence_contract/target/ink/geo_fence_contract.wasm --execute diff --git a/etc/contracts/timestamp_validator/Cargo.toml b/etc/contracts/timestamp_validator/Cargo.toml new file mode 100755 index 0000000..b17af60 --- /dev/null +++ b/etc/contracts/timestamp_validator/Cargo.toml @@ -0,0 +1,26 @@ +[package] +name = "timestamp_validator" +version = "0.1.0" +authors = ["[your_name] <[your_email]>"] +edition = "2021" + +[dependencies] +ink = { version = "5.0.0", default-features = false } +scale = { package = "parity-scale-codec", version = "3.6.12", default-features = false, features = ["derive"] } +scale-info = { version = "2.11.3", default-features = false, features = ["derive"], optional = true } + +[dev-dependencies] +ink_e2e = { version = "5.0.0" } + +[lib] +path = "lib.rs" + +[features] +default = ["std"] +std = [ + "ink/std", + "scale/std", + "scale-info/std", +] +ink-as-dependency = [] +e2e-tests = [] diff --git a/etc/contracts/timestamp_validator/lib.rs b/etc/contracts/timestamp_validator/lib.rs new file mode 100755 index 0000000..27b7ff5 --- /dev/null +++ b/etc/contracts/timestamp_validator/lib.rs @@ -0,0 +1,79 @@ +#![cfg_attr(not(feature = "std"), no_std, no_main)] +#![allow(unexpected_cfgs)] +#[ink::contract] +mod timestamp_validator { + use scale::{Decode, Encode}; + + #[ink(storage)] + pub struct TimestampValidator {} + + impl Default for TimestampValidator { + fn default() -> Self { + Self::new() + } + } + + impl TimestampValidator { + #[ink(constructor)] + pub fn new() -> Self { + Self {} + } + + #[ink(message)] + pub fn is_timestamp_valid(&self, timestamp: u64, start: u64, end: u64) -> bool { + // Check if timestamp is within range (inclusive) + timestamp >= start && timestamp <= end + } + + #[ink(message)] + pub fn validate_with_error(&self, timestamp: u64, start: u64, end: u64) -> Result<(), Error> { + if timestamp < start { + return Err(Error::TooEarly); + } + if timestamp > end { + return Err(Error::TooLate); + } + Ok(()) + } + } + + #[derive(Debug, PartialEq, Eq, Encode, Decode)] + #[cfg_attr(feature = "std", derive(scale_info::TypeInfo))] + pub enum Error { + TooEarly, + TooLate, + } +} + +#[cfg(test)] +mod tests { + use crate::timestamp_validator::{Error, TimestampValidator}; + + #[ink::test] + fn test_timestamp_validation() { + let validator = TimestampValidator::new(); + + // Test valid timestamp + assert!(validator.is_timestamp_valid(100, 50, 150)); + + // Test boundary conditions + assert!(validator.is_timestamp_valid(50, 50, 150)); // Start boundary + assert!(validator.is_timestamp_valid(150, 50, 150)); // End boundary + + // Test invalid timestamps + assert!(!validator.is_timestamp_valid(49, 50, 150)); // Before start + assert!(!validator.is_timestamp_valid(151, 50, 150)); // After end + } + + #[ink::test] + fn test_validate_with_error() { + let validator = TimestampValidator::new(); + + // Test valid timestamp + assert_eq!(validator.validate_with_error(100, 50, 150), Ok(())); + + // Test invalid timestamps + assert_eq!(validator.validate_with_error(49, 50, 150), Err(Error::TooEarly)); + assert_eq!(validator.validate_with_error(151, 50, 150), Err(Error::TooLate)); + } +} \ No newline at end of file From f9b7ad409618df7fb3a80fa2a87b6ceb85bfb49c Mon Sep 17 00:00:00 2001 From: Paul Flynn Date: Wed, 23 Oct 2024 22:12:25 -0400 Subject: [PATCH 10/15] Add content rating contract Introduce a new content rating contract to validate content based on age levels. This includes enum definitions for RatingLevel, AgeLevel, and Error, and implements validation logic and unit tests. --- etc/contracts/README.md | 12 ++ etc/contracts/content_rating/Cargo.toml | 26 +++ etc/contracts/content_rating/lib.rs | 218 ++++++++++++++++++++++++ 3 files changed, 256 insertions(+) create mode 100755 etc/contracts/content_rating/Cargo.toml create mode 100755 etc/contracts/content_rating/lib.rs diff --git a/etc/contracts/README.md b/etc/contracts/README.md index da49bd6..677537f 100644 --- a/etc/contracts/README.md +++ b/etc/contracts/README.md @@ -45,6 +45,13 @@ cargo contract build --features e2e-tests ### Deploy +#### Content Rating + +```text +Code hash 0xcee0206b80f939ec9da4c69a62284e22e0fa05c98e0c7341deeb3a7e835ef261 +Contract 5HKLo6CKbt1Z5dU4wZ3MiufeZzjM6JGwKUWUQ6a91fmuA6RB +``` + #### Geofence ```text @@ -59,6 +66,11 @@ Code hash 0xee2250ba4215f273e571ecdfc2a373ccc96de5f82c19fcdaca889218fac5ac39 Contract 5D35jFeQboveKiaQSxyLKENGqrnjgUc7B4D23QbhJK4Yr7jT ``` +```shell +cargo contract upload --url ws://127.0.0.1:9944 --suri //Alice content_rating/target/ink/content_rating.wasm +cargo contract instantiate --url ws://127.0.0.1:9944 --suri //Alice content_rating/target/ink/content_rating.wasm --execute +``` + ```shell cargo contract upload --url ws://127.0.0.1:9944 --suri //Alice timestamp_validator/target/ink/timestamp_validator.wasm cargo contract instantiate --url ws://127.0.0.1:9944 --suri //Alice timestamp_validator/target/ink/timestamp_validator.wasm --execute diff --git a/etc/contracts/content_rating/Cargo.toml b/etc/contracts/content_rating/Cargo.toml new file mode 100755 index 0000000..e20313e --- /dev/null +++ b/etc/contracts/content_rating/Cargo.toml @@ -0,0 +1,26 @@ +[package] +name = "content_rating" +version = "0.1.0" +authors = ["[your_name] <[your_email]>"] +edition = "2021" + +[dependencies] +ink = { version = "5.0.0", default-features = false } +scale = { package = "parity-scale-codec", version = "3.6.12", default-features = false, features = ["derive"] } +scale-info = { version = "2.11.3", default-features = false, features = ["derive"], optional = true } + +[dev-dependencies] +ink_e2e = { version = "5.0.0" } + +[lib] +path = "lib.rs" + +[features] +default = ["std"] +std = [ + "ink/std", + "scale/std", + "scale-info/std", +] +ink-as-dependency = [] +e2e-tests = [] diff --git a/etc/contracts/content_rating/lib.rs b/etc/contracts/content_rating/lib.rs new file mode 100755 index 0000000..d97026e --- /dev/null +++ b/etc/contracts/content_rating/lib.rs @@ -0,0 +1,218 @@ +#![cfg_attr(not(feature = "std"), no_std, no_main)] +#![allow(unexpected_cfgs)] +#[ink::contract] +mod content_rating { + #[derive(Debug, PartialEq, Eq, scale::Encode, scale::Decode)] + #[cfg_attr(feature = "std", derive(scale_info::TypeInfo))] + pub enum RatingLevel { + Unused = 0, + None = 1, + Mild = 2, + Moderate = 3, + Severe = 4, + } + + #[derive(Debug, PartialEq, Eq, scale::Encode, scale::Decode)] + #[cfg_attr(feature = "std", derive(scale_info::TypeInfo))] + pub struct Rating { + violent: RatingLevel, + sexual: RatingLevel, + profane: RatingLevel, + substance: RatingLevel, + hate: RatingLevel, + harm: RatingLevel, + mature: RatingLevel, + bully: RatingLevel, + } + + #[derive(Debug, PartialEq, Eq, scale::Encode, scale::Decode)] + #[cfg_attr(feature = "std", derive(scale_info::TypeInfo))] + pub enum AgeLevel { + Kids, // Under 13 + Teens, // 13 to 17 + Adults, // 18 and above + } + + #[derive(Debug, PartialEq, Eq, scale::Encode, scale::Decode)] + #[cfg_attr(feature = "std", derive(scale_info::TypeInfo))] + pub enum Error { + ViolentContentTooHigh, + SexualContentNotAllowed, + ProfaneContentNotAllowed, + SubstanceContentNotAllowed, + HateContentNotAllowed, + HarmContentNotAllowed, + MatureContentNotAllowed, + BullyingContentNotAllowed, + } + + #[ink(storage)] + pub struct ContentRating { + // Contract storage (empty for this case) + } + + impl ContentRating { + #[ink(constructor)] + pub fn new() -> Self { + Self {} + } + + #[ink(message)] + pub fn validate_content(&self, age_level: AgeLevel, rating: Rating) -> Result<(), Error> { + match age_level { + AgeLevel::Kids => self.validate_kids_content(&rating), + AgeLevel::Teens => self.validate_teens_content(&rating), + AgeLevel::Adults => Ok(()), // Everything is allowed for adults + } + } + + fn validate_kids_content(&self, rating: &Rating) -> Result<(), Error> { + // For kids, only mild violence is allowed, everything else must be none + if !matches!(rating.violent, RatingLevel::None | RatingLevel::Mild) { + return Err(Error::ViolentContentTooHigh); + } + if !matches!(rating.sexual, RatingLevel::None) { + return Err(Error::SexualContentNotAllowed); + } + if !matches!(rating.profane, RatingLevel::None) { + return Err(Error::ProfaneContentNotAllowed); + } + if !matches!(rating.substance, RatingLevel::None) { + return Err(Error::SubstanceContentNotAllowed); + } + if !matches!(rating.hate, RatingLevel::None) { + return Err(Error::HateContentNotAllowed); + } + if !matches!(rating.harm, RatingLevel::None) { + return Err(Error::HarmContentNotAllowed); + } + if !matches!(rating.mature, RatingLevel::None) { + return Err(Error::MatureContentNotAllowed); + } + if !matches!(rating.bully, RatingLevel::None) { + return Err(Error::BullyingContentNotAllowed); + } + Ok(()) + } + + fn validate_teens_content(&self, rating: &Rating) -> Result<(), Error> { + // For teens, certain content must be none, others can be up to mild + if matches!(rating.violent, RatingLevel::Moderate | RatingLevel::Severe) { + return Err(Error::ViolentContentTooHigh); + } + if matches!(rating.sexual, RatingLevel::Moderate | RatingLevel::Severe) { + return Err(Error::SexualContentNotAllowed); + } + if matches!(rating.profane, RatingLevel::Moderate | RatingLevel::Severe) { + return Err(Error::ProfaneContentNotAllowed); + } + // These must be none for teens + if !matches!(rating.substance, RatingLevel::None) { + return Err(Error::SubstanceContentNotAllowed); + } + if !matches!(rating.hate, RatingLevel::None) { + return Err(Error::HateContentNotAllowed); + } + if !matches!(rating.harm, RatingLevel::None) { + return Err(Error::HarmContentNotAllowed); + } + if matches!(rating.mature, RatingLevel::Moderate | RatingLevel::Severe) { + return Err(Error::MatureContentNotAllowed); + } + if !matches!(rating.bully, RatingLevel::None) { + return Err(Error::BullyingContentNotAllowed); + } + Ok(()) + } + + #[ink(message)] + pub fn check_content(&self, age_level: AgeLevel, rating: Rating) -> bool { + self.validate_content(age_level, rating).is_ok() + } + } + + #[cfg(test)] + mod tests { + use super::*; + + #[ink::test] + fn kids_content_validation_works() { + let contract = ContentRating::new(); + + // Valid kids content + let valid_kids_rating = Rating { + violent: RatingLevel::Mild, + sexual: RatingLevel::None, + profane: RatingLevel::None, + substance: RatingLevel::None, + hate: RatingLevel::None, + harm: RatingLevel::None, + mature: RatingLevel::None, + bully: RatingLevel::None, + }; + assert!(contract.check_content(AgeLevel::Kids, valid_kids_rating)); + + // Invalid kids content (too violent) + let invalid_kids_rating = Rating { + violent: RatingLevel::Moderate, + sexual: RatingLevel::None, + profane: RatingLevel::None, + substance: RatingLevel::None, + hate: RatingLevel::None, + harm: RatingLevel::None, + mature: RatingLevel::None, + bully: RatingLevel::None, + }; + assert!(!contract.check_content(AgeLevel::Kids, invalid_kids_rating)); + } + + #[ink::test] + fn teens_content_validation_works() { + let contract = ContentRating::new(); + + // Valid teens content + let valid_teens_rating = Rating { + violent: RatingLevel::Mild, + sexual: RatingLevel::Mild, + profane: RatingLevel::Mild, + substance: RatingLevel::None, + hate: RatingLevel::None, + harm: RatingLevel::None, + mature: RatingLevel::Mild, + bully: RatingLevel::None, + }; + assert!(contract.check_content(AgeLevel::Teens, valid_teens_rating)); + + // Invalid teens content (substance use) + let invalid_teens_rating = Rating { + violent: RatingLevel::Mild, + sexual: RatingLevel::Mild, + profane: RatingLevel::Mild, + substance: RatingLevel::Mild, + hate: RatingLevel::None, + harm: RatingLevel::None, + mature: RatingLevel::Mild, + bully: RatingLevel::None, + }; + assert!(!contract.check_content(AgeLevel::Teens, invalid_teens_rating)); + } + + #[ink::test] + fn adult_content_validation_works() { + let contract = ContentRating::new(); + + // All content levels are valid for adults + let adult_rating = Rating { + violent: RatingLevel::Severe, + sexual: RatingLevel::Severe, + profane: RatingLevel::Severe, + substance: RatingLevel::Severe, + hate: RatingLevel::Severe, + harm: RatingLevel::Severe, + mature: RatingLevel::Severe, + bully: RatingLevel::Severe, + }; + assert!(contract.check_content(AgeLevel::Adults, adult_rating)); + } + } +} From 8c8db9ee6926c2a6620fe67f47f1f261bd692d30 Mon Sep 17 00:00:00 2001 From: Paul Flynn Date: Wed, 23 Oct 2024 22:21:14 -0400 Subject: [PATCH 11/15] Add Clippy lint allowance and default implementation Added `#![allow(clippy::extra_unused_lifetimes)]` to suppress Clippy warnings in `event_generated.rs`. Implemented `Default` trait for `GeoFenceContract` in `geo_fence_contract.rs` to provide a default constructor. --- src/bin/contracts/geo_fence_contract.rs | 6 ++++++ src/bin/schemas/event_generated.rs | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/bin/contracts/geo_fence_contract.rs b/src/bin/contracts/geo_fence_contract.rs index 65b555f..55ea2f8 100755 --- a/src/bin/contracts/geo_fence_contract.rs +++ b/src/bin/contracts/geo_fence_contract.rs @@ -25,6 +25,12 @@ pub mod geo_fence_contract { #[ink(storage)] pub struct GeoFenceContract {} + impl Default for GeoFenceContract { + fn default() -> Self { + Self::new() + } + } + impl GeoFenceContract { #[ink(constructor)] pub fn new() -> Self { diff --git a/src/bin/schemas/event_generated.rs b/src/bin/schemas/event_generated.rs index 6463cc3..5a385af 100644 --- a/src/bin/schemas/event_generated.rs +++ b/src/bin/schemas/event_generated.rs @@ -1,5 +1,5 @@ // automatically generated by the FlatBuffers compiler, do not modify - +#![allow(clippy::extra_unused_lifetimes)] // @generated extern crate flatbuffers; From 7aee5c286638fa1d3a46fe7a9781ed7d1fc1cfe5 Mon Sep 17 00:00:00 2001 From: Paul Flynn Date: Wed, 23 Oct 2024 22:25:23 -0400 Subject: [PATCH 12/15] Refactor to improve code formatting Reorganized import statements in `main.rs` and improved code readability by reformatting lines for better alignment. Enhanced the clarity of deprecation warnings and structured method definitions more consistently across `event_generated.rs`. --- src/bin/contracts/geo_fence_contract.rs | 88 ++-- src/bin/main.rs | 10 +- src/bin/schemas/event_generated.rs | 585 ++++++++++++++++++------ 3 files changed, 510 insertions(+), 173 deletions(-) diff --git a/src/bin/contracts/geo_fence_contract.rs b/src/bin/contracts/geo_fence_contract.rs index 55ea2f8..ad2ccb0 100755 --- a/src/bin/contracts/geo_fence_contract.rs +++ b/src/bin/contracts/geo_fence_contract.rs @@ -30,7 +30,7 @@ pub mod geo_fence_contract { Self::new() } } - + impl GeoFenceContract { #[ink(constructor)] pub fn new() -> Self { @@ -38,11 +38,7 @@ pub mod geo_fence_contract { } #[ink(message)] - pub fn is_within_geofence( - &self, - geofence: Geofence3D, - coordinate: Coordinate3D, - ) -> bool { + pub fn is_within_geofence(&self, geofence: Geofence3D, coordinate: Coordinate3D) -> bool { coordinate.latitude >= geofence.min_latitude && coordinate.latitude <= geofence.max_latitude && coordinate.longitude >= geofence.min_longitude @@ -68,17 +64,23 @@ pub mod geo_fence_contract { max_altitude: 100_000.0, }; - assert!(contract.is_within_geofence(geofence, Coordinate3D { - latitude: 0.0, - longitude: 0.0, - altitude: 50_000.0, - })); + assert!(contract.is_within_geofence( + geofence, + Coordinate3D { + latitude: 0.0, + longitude: 0.0, + altitude: 50_000.0, + } + )); - assert!(!contract.is_within_geofence(geofence, Coordinate3D { - latitude: -15.0, - longitude: 0.0, - altitude: 50_000.0, - })); + assert!(!contract.is_within_geofence( + geofence, + Coordinate3D { + latitude: -15.0, + longitude: 0.0, + altitude: 50_000.0, + } + )); } #[ink::test] @@ -93,29 +95,41 @@ pub mod geo_fence_contract { max_altitude: 6.1, // 20 feet in altitude }; - assert!(contract.is_within_geofence(geofence, Coordinate3D { - latitude: 0.0003, - longitude: 0.0003, - altitude: 3.0, - })); // Inside the cube + assert!(contract.is_within_geofence( + geofence, + Coordinate3D { + latitude: 0.0003, + longitude: 0.0003, + altitude: 3.0, + } + )); // Inside the cube - assert!(!contract.is_within_geofence(geofence, Coordinate3D { - latitude: 0.001, - longitude: 0.0003, - altitude: 3.0, - })); // Outside latitude + assert!(!contract.is_within_geofence( + geofence, + Coordinate3D { + latitude: 0.001, + longitude: 0.0003, + altitude: 3.0, + } + )); // Outside latitude - assert!(!contract.is_within_geofence(geofence, Coordinate3D { - latitude: 0.0003, - longitude: 0.001, - altitude: 3.0, - })); // Outside longitude + assert!(!contract.is_within_geofence( + geofence, + Coordinate3D { + latitude: 0.0003, + longitude: 0.001, + altitude: 3.0, + } + )); // Outside longitude - assert!(!contract.is_within_geofence(geofence, Coordinate3D { - latitude: 0.0003, - longitude: 0.0003, - altitude: 10.0, - })); // Outside altitude + assert!(!contract.is_within_geofence( + geofence, + Coordinate3D { + latitude: 0.0003, + longitude: 0.0003, + altitude: 10.0, + } + )); // Outside altitude } } -} \ No newline at end of file +} diff --git a/src/bin/main.rs b/src/bin/main.rs index 453abce..631dcc7 100644 --- a/src/bin/main.rs +++ b/src/bin/main.rs @@ -3,6 +3,7 @@ mod schemas; use crate::contracts::contract_simple_abac; use crate::contracts::geo_fence_contract; +use crate::contracts::geo_fence_contract::geo_fence_contract::Geofence3D; use crate::schemas::event_generated::arkavo::{Event, EventData}; use aes_gcm::aead::generic_array::GenericArray; use aes_gcm::aead::KeyInit; @@ -38,7 +39,6 @@ use tokio::net::TcpListener; use tokio::sync::{mpsc, Mutex}; use tokio_native_tls::TlsAcceptor; use tokio_tungstenite::tungstenite::Message; -use crate::contracts::geo_fence_contract::geo_fence_contract::Geofence3D; #[derive(Serialize, Deserialize, Debug)] struct PublicKeyMessage { @@ -438,7 +438,7 @@ async fn handle_binary_message( ) .await } // internal - Some(MessageType::Event) => handle_event(server_state, payload, nats_connection).await, // embedded + Some(MessageType::Event) => handle_event(server_state, payload, nats_connection).await, // embedded None => { // println!("Unknown message type: {:?}", message_type); None @@ -809,7 +809,11 @@ async fn handle_nats_event( connection_state.outgoing_tx.send(ws_message)?; Ok(()) } -async fn handle_event(server_state: &Arc, payload: &[u8], nats_connection: Arc,) -> Option { +async fn handle_event( + server_state: &Arc, + payload: &[u8], + nats_connection: Arc, +) -> Option { let start_time = Instant::now(); let mut event_data: Option> = None; if let Ok(event) = root::(payload) { diff --git a/src/bin/schemas/event_generated.rs b/src/bin/schemas/event_generated.rs index 5a385af..91d4731 100644 --- a/src/bin/schemas/event_generated.rs +++ b/src/bin/schemas/event_generated.rs @@ -9,11 +9,20 @@ pub mod arkavo { extern crate flatbuffers; use self::flatbuffers::Follow; - #[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")] + #[deprecated( + since = "2.0.0", + note = "Use associated constants instead. This will no longer be generated in 2021." + )] pub const ENUM_MIN_ACTION: i8 = 0; - #[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")] + #[deprecated( + since = "2.0.0", + note = "Use associated constants instead. This will no longer be generated in 2021." + )] pub const ENUM_MAX_ACTION: i8 = 8; - #[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")] + #[deprecated( + since = "2.0.0", + note = "Use associated constants instead. This will no longer be generated in 2021." + )] #[allow(non_camel_case_types)] pub const ENUM_VALUES_ACTION: [Action; 9] = [ Action::unused, @@ -114,7 +123,8 @@ pub mod arkavo { impl<'a> flatbuffers::Verifiable for Action { #[inline] fn run_verifier( - v: &mut flatbuffers::Verifier, pos: usize + v: &mut flatbuffers::Verifier, + pos: usize, ) -> Result<(), flatbuffers::InvalidFlatbuffer> { use self::flatbuffers::Verifiable; i8::run_verifier(v, pos) @@ -122,11 +132,20 @@ pub mod arkavo { } impl flatbuffers::SimpleToVerifyInSlice for Action {} - #[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")] + #[deprecated( + since = "2.0.0", + note = "Use associated constants instead. This will no longer be generated in 2021." + )] pub const ENUM_MIN_ACTION_STATUS: i8 = 0; - #[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")] + #[deprecated( + since = "2.0.0", + note = "Use associated constants instead. This will no longer be generated in 2021." + )] pub const ENUM_MAX_ACTION_STATUS: i8 = 4; - #[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")] + #[deprecated( + since = "2.0.0", + note = "Use associated constants instead. This will no longer be generated in 2021." + )] #[allow(non_camel_case_types)] pub const ENUM_VALUES_ACTION_STATUS: [ActionStatus; 5] = [ ActionStatus::unused, @@ -211,7 +230,8 @@ pub mod arkavo { impl<'a> flatbuffers::Verifiable for ActionStatus { #[inline] fn run_verifier( - v: &mut flatbuffers::Verifier, pos: usize + v: &mut flatbuffers::Verifier, + pos: usize, ) -> Result<(), flatbuffers::InvalidFlatbuffer> { use self::flatbuffers::Verifiable; i8::run_verifier(v, pos) @@ -219,11 +239,20 @@ pub mod arkavo { } impl flatbuffers::SimpleToVerifyInSlice for ActionStatus {} - #[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")] + #[deprecated( + since = "2.0.0", + note = "Use associated constants instead. This will no longer be generated in 2021." + )] pub const ENUM_MIN_ENTITY_TYPE: i8 = 0; - #[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")] + #[deprecated( + since = "2.0.0", + note = "Use associated constants instead. This will no longer be generated in 2021." + )] pub const ENUM_MAX_ENTITY_TYPE: i8 = 3; - #[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")] + #[deprecated( + since = "2.0.0", + note = "Use associated constants instead. This will no longer be generated in 2021." + )] #[allow(non_camel_case_types)] pub const ENUM_VALUES_ENTITY_TYPE: [EntityType; 4] = [ EntityType::unused, @@ -304,7 +333,8 @@ pub mod arkavo { impl<'a> flatbuffers::Verifiable for EntityType { #[inline] fn run_verifier( - v: &mut flatbuffers::Verifier, pos: usize + v: &mut flatbuffers::Verifier, + pos: usize, ) -> Result<(), flatbuffers::InvalidFlatbuffer> { use self::flatbuffers::Verifiable; i8::run_verifier(v, pos) @@ -312,11 +342,20 @@ pub mod arkavo { } impl flatbuffers::SimpleToVerifyInSlice for EntityType {} - #[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")] + #[deprecated( + since = "2.0.0", + note = "Use associated constants instead. This will no longer be generated in 2021." + )] pub const ENUM_MIN_ATTRIBUTE_TYPE: i8 = 0; - #[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")] + #[deprecated( + since = "2.0.0", + note = "Use associated constants instead. This will no longer be generated in 2021." + )] pub const ENUM_MAX_ATTRIBUTE_TYPE: i8 = 2; - #[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")] + #[deprecated( + since = "2.0.0", + note = "Use associated constants instead. This will no longer be generated in 2021." + )] #[allow(non_camel_case_types)] pub const ENUM_VALUES_ATTRIBUTE_TYPE: [AttributeType; 3] = [ AttributeType::unused, @@ -335,11 +374,7 @@ pub mod arkavo { pub const ENUM_MIN: i8 = 0; pub const ENUM_MAX: i8 = 2; - pub const ENUM_VALUES: &'static [Self] = &[ - Self::unused, - Self::time, - Self::location, - ]; + pub const ENUM_VALUES: &'static [Self] = &[Self::unused, Self::time, Self::location]; /// Returns the variant's name or "" if unknown. pub fn variant_name(self) -> Option<&'static str> { match self { @@ -393,7 +428,8 @@ pub mod arkavo { impl<'a> flatbuffers::Verifiable for AttributeType { #[inline] fn run_verifier( - v: &mut flatbuffers::Verifier, pos: usize + v: &mut flatbuffers::Verifier, + pos: usize, ) -> Result<(), flatbuffers::InvalidFlatbuffer> { use self::flatbuffers::Verifiable; i8::run_verifier(v, pos) @@ -401,11 +437,20 @@ pub mod arkavo { } impl flatbuffers::SimpleToVerifyInSlice for AttributeType {} - #[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")] + #[deprecated( + since = "2.0.0", + note = "Use associated constants instead. This will no longer be generated in 2021." + )] pub const ENUM_MIN_EVENT_DATA: u8 = 0; - #[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")] + #[deprecated( + since = "2.0.0", + note = "Use associated constants instead. This will no longer be generated in 2021." + )] pub const ENUM_MAX_EVENT_DATA: u8 = 3; - #[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")] + #[deprecated( + since = "2.0.0", + note = "Use associated constants instead. This will no longer be generated in 2021." + )] #[allow(non_camel_case_types)] pub const ENUM_VALUES_EVENT_DATA: [EventData; 4] = [ EventData::NONE, @@ -486,7 +531,8 @@ pub mod arkavo { impl<'a> flatbuffers::Verifiable for EventData { #[inline] fn run_verifier( - v: &mut flatbuffers::Verifier, pos: usize + v: &mut flatbuffers::Verifier, + pos: usize, ) -> Result<(), flatbuffers::InvalidFlatbuffer> { use self::flatbuffers::Verifiable; u8::run_verifier(v, pos) @@ -507,7 +553,9 @@ pub mod arkavo { type Inner = UserEvent<'a>; #[inline] unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { - Self { _tab: flatbuffers::Table::new(buf, loc) } + Self { + _tab: flatbuffers::Table::new(buf, loc), + } } } @@ -524,69 +572,110 @@ pub mod arkavo { UserEvent { _tab: table } } #[allow(unused_mut)] - pub fn create<'bldr: 'args, 'args: 'mut_bldr, 'mut_bldr, A: flatbuffers::Allocator + 'bldr>( + pub fn create< + 'bldr: 'args, + 'args: 'mut_bldr, + 'mut_bldr, + A: flatbuffers::Allocator + 'bldr, + >( _fbb: &'mut_bldr mut flatbuffers::FlatBufferBuilder<'bldr, A>, - args: &'args UserEventArgs<'args> + args: &'args UserEventArgs<'args>, ) -> flatbuffers::WIPOffset> { let mut builder = UserEventBuilder::new(_fbb); - if let Some(x) = args.attribute_type { builder.add_attribute_type(x); } - if let Some(x) = args.target_id { builder.add_target_id(x); } - if let Some(x) = args.source_id { builder.add_source_id(x); } + if let Some(x) = args.attribute_type { + builder.add_attribute_type(x); + } + if let Some(x) = args.target_id { + builder.add_target_id(x); + } + if let Some(x) = args.source_id { + builder.add_source_id(x); + } builder.add_entity_type(args.entity_type); builder.add_target_type(args.target_type); builder.add_source_type(args.source_type); builder.finish() } - #[inline] pub fn source_type(&self) -> EntityType { // Safety: // Created from valid Table for this object // which contains a valid value in this slot - unsafe { self._tab.get::(UserEvent::VT_SOURCE_TYPE, Some(EntityType::unused)).unwrap()} + unsafe { + self._tab + .get::(UserEvent::VT_SOURCE_TYPE, Some(EntityType::unused)) + .unwrap() + } } #[inline] pub fn target_type(&self) -> EntityType { // Safety: // Created from valid Table for this object // which contains a valid value in this slot - unsafe { self._tab.get::(UserEvent::VT_TARGET_TYPE, Some(EntityType::unused)).unwrap()} + unsafe { + self._tab + .get::(UserEvent::VT_TARGET_TYPE, Some(EntityType::unused)) + .unwrap() + } } #[inline] pub fn source_id(&self) -> Option> { // Safety: // Created from valid Table for this object // which contains a valid value in this slot - unsafe { self._tab.get::>>(UserEvent::VT_SOURCE_ID, None)} + unsafe { + self._tab + .get::>>( + UserEvent::VT_SOURCE_ID, + None, + ) + } } #[inline] pub fn target_id(&self) -> Option> { // Safety: // Created from valid Table for this object // which contains a valid value in this slot - unsafe { self._tab.get::>>(UserEvent::VT_TARGET_ID, None)} + unsafe { + self._tab + .get::>>( + UserEvent::VT_TARGET_ID, + None, + ) + } } #[inline] pub fn attribute_type(&self) -> Option> { // Safety: // Created from valid Table for this object // which contains a valid value in this slot - unsafe { self._tab.get::>>(UserEvent::VT_ATTRIBUTE_TYPE, None)} + unsafe { + self._tab + .get::>>( + UserEvent::VT_ATTRIBUTE_TYPE, + None, + ) + } } #[inline] pub fn entity_type(&self) -> EntityType { // Safety: // Created from valid Table for this object // which contains a valid value in this slot - unsafe { self._tab.get::(UserEvent::VT_ENTITY_TYPE, Some(EntityType::unused)).unwrap()} + unsafe { + self._tab + .get::(UserEvent::VT_ENTITY_TYPE, Some(EntityType::unused)) + .unwrap() + } } } impl flatbuffers::Verifiable for UserEvent<'_> { #[inline] fn run_verifier( - v: &mut flatbuffers::Verifier, pos: usize + v: &mut flatbuffers::Verifier, + pos: usize, ) -> Result<(), flatbuffers::InvalidFlatbuffer> { v.visit_table(pos)? .visit_field::("source_type", Self::VT_SOURCE_TYPE, false)? @@ -628,30 +717,58 @@ pub mod arkavo { impl<'a: 'b, 'b, A: flatbuffers::Allocator + 'a> UserEventBuilder<'a, 'b, A> { #[inline] pub fn add_source_type(&mut self, source_type: EntityType) { - self.fbb_.push_slot::(UserEvent::VT_SOURCE_TYPE, source_type, EntityType::unused); + self.fbb_.push_slot::( + UserEvent::VT_SOURCE_TYPE, + source_type, + EntityType::unused, + ); } #[inline] pub fn add_target_type(&mut self, target_type: EntityType) { - self.fbb_.push_slot::(UserEvent::VT_TARGET_TYPE, target_type, EntityType::unused); + self.fbb_.push_slot::( + UserEvent::VT_TARGET_TYPE, + target_type, + EntityType::unused, + ); } #[inline] - pub fn add_source_id(&mut self, source_id: flatbuffers::WIPOffset>) { - self.fbb_.push_slot_always::>(UserEvent::VT_SOURCE_ID, source_id); + pub fn add_source_id( + &mut self, + source_id: flatbuffers::WIPOffset>, + ) { + self.fbb_ + .push_slot_always::>(UserEvent::VT_SOURCE_ID, source_id); } #[inline] - pub fn add_target_id(&mut self, target_id: flatbuffers::WIPOffset>) { - self.fbb_.push_slot_always::>(UserEvent::VT_TARGET_ID, target_id); + pub fn add_target_id( + &mut self, + target_id: flatbuffers::WIPOffset>, + ) { + self.fbb_ + .push_slot_always::>(UserEvent::VT_TARGET_ID, target_id); } #[inline] - pub fn add_attribute_type(&mut self, attribute_type: flatbuffers::WIPOffset>) { - self.fbb_.push_slot_always::>(UserEvent::VT_ATTRIBUTE_TYPE, attribute_type); + pub fn add_attribute_type( + &mut self, + attribute_type: flatbuffers::WIPOffset>, + ) { + self.fbb_.push_slot_always::>( + UserEvent::VT_ATTRIBUTE_TYPE, + attribute_type, + ); } #[inline] pub fn add_entity_type(&mut self, entity_type: EntityType) { - self.fbb_.push_slot::(UserEvent::VT_ENTITY_TYPE, entity_type, EntityType::unused); + self.fbb_.push_slot::( + UserEvent::VT_ENTITY_TYPE, + entity_type, + EntityType::unused, + ); } #[inline] - pub fn new(_fbb: &'b mut flatbuffers::FlatBufferBuilder<'a, A>) -> UserEventBuilder<'a, 'b, A> { + pub fn new( + _fbb: &'b mut flatbuffers::FlatBufferBuilder<'a, A>, + ) -> UserEventBuilder<'a, 'b, A> { let start = _fbb.start_table(); UserEventBuilder { fbb_: _fbb, @@ -688,7 +805,9 @@ pub mod arkavo { type Inner = CacheEvent<'a>; #[inline] unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { - Self { _tab: flatbuffers::Table::new(buf, loc) } + Self { + _tab: flatbuffers::Table::new(buf, loc), + } } } @@ -703,57 +822,90 @@ pub mod arkavo { CacheEvent { _tab: table } } #[allow(unused_mut)] - pub fn create<'bldr: 'args, 'args: 'mut_bldr, 'mut_bldr, A: flatbuffers::Allocator + 'bldr>( + pub fn create< + 'bldr: 'args, + 'args: 'mut_bldr, + 'mut_bldr, + A: flatbuffers::Allocator + 'bldr, + >( _fbb: &'mut_bldr mut flatbuffers::FlatBufferBuilder<'bldr, A>, - args: &'args CacheEventArgs<'args> + args: &'args CacheEventArgs<'args>, ) -> flatbuffers::WIPOffset> { let mut builder = CacheEventBuilder::new(_fbb); builder.add_ttl(args.ttl); - if let Some(x) = args.target_payload { builder.add_target_payload(x); } - if let Some(x) = args.target_id { builder.add_target_id(x); } + if let Some(x) = args.target_payload { + builder.add_target_payload(x); + } + if let Some(x) = args.target_id { + builder.add_target_id(x); + } builder.add_one_time_access(args.one_time_access); builder.finish() } - #[inline] pub fn target_id(&self) -> Option> { // Safety: // Created from valid Table for this object // which contains a valid value in this slot - unsafe { self._tab.get::>>(CacheEvent::VT_TARGET_ID, None)} + unsafe { + self._tab + .get::>>( + CacheEvent::VT_TARGET_ID, + None, + ) + } } #[inline] pub fn target_payload(&self) -> Option> { // Safety: // Created from valid Table for this object // which contains a valid value in this slot - unsafe { self._tab.get::>>(CacheEvent::VT_TARGET_PAYLOAD, None)} + unsafe { + self._tab + .get::>>( + CacheEvent::VT_TARGET_PAYLOAD, + None, + ) + } } #[inline] pub fn ttl(&self) -> u32 { // Safety: // Created from valid Table for this object // which contains a valid value in this slot - unsafe { self._tab.get::(CacheEvent::VT_TTL, Some(0)).unwrap()} + unsafe { self._tab.get::(CacheEvent::VT_TTL, Some(0)).unwrap() } } #[inline] pub fn one_time_access(&self) -> bool { // Safety: // Created from valid Table for this object // which contains a valid value in this slot - unsafe { self._tab.get::(CacheEvent::VT_ONE_TIME_ACCESS, Some(false)).unwrap()} + unsafe { + self._tab + .get::(CacheEvent::VT_ONE_TIME_ACCESS, Some(false)) + .unwrap() + } } } impl flatbuffers::Verifiable for CacheEvent<'_> { #[inline] fn run_verifier( - v: &mut flatbuffers::Verifier, pos: usize + v: &mut flatbuffers::Verifier, + pos: usize, ) -> Result<(), flatbuffers::InvalidFlatbuffer> { v.visit_table(pos)? - .visit_field::>>("target_id", Self::VT_TARGET_ID, false)? - .visit_field::>>("target_payload", Self::VT_TARGET_PAYLOAD, false)? + .visit_field::>>( + "target_id", + Self::VT_TARGET_ID, + false, + )? + .visit_field::>>( + "target_payload", + Self::VT_TARGET_PAYLOAD, + false, + )? .visit_field::("ttl", Self::VT_TTL, false)? .visit_field::("one_time_access", Self::VT_ONE_TIME_ACCESS, false)? .finish(); @@ -784,12 +936,22 @@ pub mod arkavo { } impl<'a: 'b, 'b, A: flatbuffers::Allocator + 'a> CacheEventBuilder<'a, 'b, A> { #[inline] - pub fn add_target_id(&mut self, target_id: flatbuffers::WIPOffset>) { - self.fbb_.push_slot_always::>(CacheEvent::VT_TARGET_ID, target_id); + pub fn add_target_id( + &mut self, + target_id: flatbuffers::WIPOffset>, + ) { + self.fbb_ + .push_slot_always::>(CacheEvent::VT_TARGET_ID, target_id); } #[inline] - pub fn add_target_payload(&mut self, target_payload: flatbuffers::WIPOffset>) { - self.fbb_.push_slot_always::>(CacheEvent::VT_TARGET_PAYLOAD, target_payload); + pub fn add_target_payload( + &mut self, + target_payload: flatbuffers::WIPOffset>, + ) { + self.fbb_.push_slot_always::>( + CacheEvent::VT_TARGET_PAYLOAD, + target_payload, + ); } #[inline] pub fn add_ttl(&mut self, ttl: u32) { @@ -797,10 +959,13 @@ pub mod arkavo { } #[inline] pub fn add_one_time_access(&mut self, one_time_access: bool) { - self.fbb_.push_slot::(CacheEvent::VT_ONE_TIME_ACCESS, one_time_access, false); + self.fbb_ + .push_slot::(CacheEvent::VT_ONE_TIME_ACCESS, one_time_access, false); } #[inline] - pub fn new(_fbb: &'b mut flatbuffers::FlatBufferBuilder<'a, A>) -> CacheEventBuilder<'a, 'b, A> { + pub fn new( + _fbb: &'b mut flatbuffers::FlatBufferBuilder<'a, A>, + ) -> CacheEventBuilder<'a, 'b, A> { let start = _fbb.start_table(); CacheEventBuilder { fbb_: _fbb, @@ -835,7 +1000,9 @@ pub mod arkavo { type Inner = RouteEvent<'a>; #[inline] unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { - Self { _tab: flatbuffers::Table::new(buf, loc) } + Self { + _tab: flatbuffers::Table::new(buf, loc), + } } } @@ -853,14 +1020,25 @@ pub mod arkavo { RouteEvent { _tab: table } } #[allow(unused_mut)] - pub fn create<'bldr: 'args, 'args: 'mut_bldr, 'mut_bldr, A: flatbuffers::Allocator + 'bldr>( + pub fn create< + 'bldr: 'args, + 'args: 'mut_bldr, + 'mut_bldr, + A: flatbuffers::Allocator + 'bldr, + >( _fbb: &'mut_bldr mut flatbuffers::FlatBufferBuilder<'bldr, A>, - args: &'args RouteEventArgs<'args> + args: &'args RouteEventArgs<'args>, ) -> flatbuffers::WIPOffset> { let mut builder = RouteEventBuilder::new(_fbb); - if let Some(x) = args.payload { builder.add_payload(x); } - if let Some(x) = args.source_id { builder.add_source_id(x); } - if let Some(x) = args.target_id { builder.add_target_id(x); } + if let Some(x) = args.payload { + builder.add_payload(x); + } + if let Some(x) = args.source_id { + builder.add_source_id(x); + } + if let Some(x) = args.target_id { + builder.add_target_id(x); + } builder.add_entity_type(args.entity_type); builder.add_attribute_type(args.attribute_type); builder.add_source_type(args.source_type); @@ -868,71 +1046,120 @@ pub mod arkavo { builder.finish() } - #[inline] pub fn target_type(&self) -> EntityType { // Safety: // Created from valid Table for this object // which contains a valid value in this slot - unsafe { self._tab.get::(RouteEvent::VT_TARGET_TYPE, Some(EntityType::unused)).unwrap()} + unsafe { + self._tab + .get::(RouteEvent::VT_TARGET_TYPE, Some(EntityType::unused)) + .unwrap() + } } #[inline] pub fn target_id(&self) -> Option> { // Safety: // Created from valid Table for this object // which contains a valid value in this slot - unsafe { self._tab.get::>>(RouteEvent::VT_TARGET_ID, None)} + unsafe { + self._tab + .get::>>( + RouteEvent::VT_TARGET_ID, + None, + ) + } } #[inline] pub fn source_type(&self) -> EntityType { // Safety: // Created from valid Table for this object // which contains a valid value in this slot - unsafe { self._tab.get::(RouteEvent::VT_SOURCE_TYPE, Some(EntityType::unused)).unwrap()} + unsafe { + self._tab + .get::(RouteEvent::VT_SOURCE_TYPE, Some(EntityType::unused)) + .unwrap() + } } #[inline] pub fn source_id(&self) -> Option> { // Safety: // Created from valid Table for this object // which contains a valid value in this slot - unsafe { self._tab.get::>>(RouteEvent::VT_SOURCE_ID, None)} + unsafe { + self._tab + .get::>>( + RouteEvent::VT_SOURCE_ID, + None, + ) + } } #[inline] pub fn attribute_type(&self) -> AttributeType { // Safety: // Created from valid Table for this object // which contains a valid value in this slot - unsafe { self._tab.get::(RouteEvent::VT_ATTRIBUTE_TYPE, Some(AttributeType::unused)).unwrap()} + unsafe { + self._tab + .get::( + RouteEvent::VT_ATTRIBUTE_TYPE, + Some(AttributeType::unused), + ) + .unwrap() + } } #[inline] pub fn entity_type(&self) -> EntityType { // Safety: // Created from valid Table for this object // which contains a valid value in this slot - unsafe { self._tab.get::(RouteEvent::VT_ENTITY_TYPE, Some(EntityType::unused)).unwrap()} + unsafe { + self._tab + .get::(RouteEvent::VT_ENTITY_TYPE, Some(EntityType::unused)) + .unwrap() + } } #[inline] pub fn payload(&self) -> Option> { // Safety: // Created from valid Table for this object // which contains a valid value in this slot - unsafe { self._tab.get::>>(RouteEvent::VT_PAYLOAD, None)} + unsafe { + self._tab + .get::>>( + RouteEvent::VT_PAYLOAD, + None, + ) + } } } impl flatbuffers::Verifiable for RouteEvent<'_> { #[inline] fn run_verifier( - v: &mut flatbuffers::Verifier, pos: usize + v: &mut flatbuffers::Verifier, + pos: usize, ) -> Result<(), flatbuffers::InvalidFlatbuffer> { v.visit_table(pos)? .visit_field::("target_type", Self::VT_TARGET_TYPE, false)? - .visit_field::>>("target_id", Self::VT_TARGET_ID, false)? + .visit_field::>>( + "target_id", + Self::VT_TARGET_ID, + false, + )? .visit_field::("source_type", Self::VT_SOURCE_TYPE, false)? - .visit_field::>>("source_id", Self::VT_SOURCE_ID, false)? + .visit_field::>>( + "source_id", + Self::VT_SOURCE_ID, + false, + )? .visit_field::("attribute_type", Self::VT_ATTRIBUTE_TYPE, false)? .visit_field::("entity_type", Self::VT_ENTITY_TYPE, false)? - .visit_field::>>("payload", Self::VT_PAYLOAD, false)? + .visit_field::>>( + "payload", + Self::VT_PAYLOAD, + false, + )? .finish(); Ok(()) } @@ -968,34 +1195,64 @@ pub mod arkavo { impl<'a: 'b, 'b, A: flatbuffers::Allocator + 'a> RouteEventBuilder<'a, 'b, A> { #[inline] pub fn add_target_type(&mut self, target_type: EntityType) { - self.fbb_.push_slot::(RouteEvent::VT_TARGET_TYPE, target_type, EntityType::unused); + self.fbb_.push_slot::( + RouteEvent::VT_TARGET_TYPE, + target_type, + EntityType::unused, + ); } #[inline] - pub fn add_target_id(&mut self, target_id: flatbuffers::WIPOffset>) { - self.fbb_.push_slot_always::>(RouteEvent::VT_TARGET_ID, target_id); + pub fn add_target_id( + &mut self, + target_id: flatbuffers::WIPOffset>, + ) { + self.fbb_ + .push_slot_always::>(RouteEvent::VT_TARGET_ID, target_id); } #[inline] pub fn add_source_type(&mut self, source_type: EntityType) { - self.fbb_.push_slot::(RouteEvent::VT_SOURCE_TYPE, source_type, EntityType::unused); + self.fbb_.push_slot::( + RouteEvent::VT_SOURCE_TYPE, + source_type, + EntityType::unused, + ); } #[inline] - pub fn add_source_id(&mut self, source_id: flatbuffers::WIPOffset>) { - self.fbb_.push_slot_always::>(RouteEvent::VT_SOURCE_ID, source_id); + pub fn add_source_id( + &mut self, + source_id: flatbuffers::WIPOffset>, + ) { + self.fbb_ + .push_slot_always::>(RouteEvent::VT_SOURCE_ID, source_id); } #[inline] pub fn add_attribute_type(&mut self, attribute_type: AttributeType) { - self.fbb_.push_slot::(RouteEvent::VT_ATTRIBUTE_TYPE, attribute_type, AttributeType::unused); + self.fbb_.push_slot::( + RouteEvent::VT_ATTRIBUTE_TYPE, + attribute_type, + AttributeType::unused, + ); } #[inline] pub fn add_entity_type(&mut self, entity_type: EntityType) { - self.fbb_.push_slot::(RouteEvent::VT_ENTITY_TYPE, entity_type, EntityType::unused); + self.fbb_.push_slot::( + RouteEvent::VT_ENTITY_TYPE, + entity_type, + EntityType::unused, + ); } #[inline] - pub fn add_payload(&mut self, payload: flatbuffers::WIPOffset>) { - self.fbb_.push_slot_always::>(RouteEvent::VT_PAYLOAD, payload); + pub fn add_payload( + &mut self, + payload: flatbuffers::WIPOffset>, + ) { + self.fbb_ + .push_slot_always::>(RouteEvent::VT_PAYLOAD, payload); } #[inline] - pub fn new(_fbb: &'b mut flatbuffers::FlatBufferBuilder<'a, A>) -> RouteEventBuilder<'a, 'b, A> { + pub fn new( + _fbb: &'b mut flatbuffers::FlatBufferBuilder<'a, A>, + ) -> RouteEventBuilder<'a, 'b, A> { let start = _fbb.start_table(); RouteEventBuilder { fbb_: _fbb, @@ -1033,7 +1290,9 @@ pub mod arkavo { type Inner = Event<'a>; #[inline] unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { - Self { _tab: flatbuffers::Table::new(buf, loc) } + Self { + _tab: flatbuffers::Table::new(buf, loc), + } } } @@ -1049,54 +1308,78 @@ pub mod arkavo { Event { _tab: table } } #[allow(unused_mut)] - pub fn create<'bldr: 'args, 'args: 'mut_bldr, 'mut_bldr, A: flatbuffers::Allocator + 'bldr>( + pub fn create< + 'bldr: 'args, + 'args: 'mut_bldr, + 'mut_bldr, + A: flatbuffers::Allocator + 'bldr, + >( _fbb: &'mut_bldr mut flatbuffers::FlatBufferBuilder<'bldr, A>, - args: &'args EventArgs + args: &'args EventArgs, ) -> flatbuffers::WIPOffset> { let mut builder = EventBuilder::new(_fbb); builder.add_timestamp(args.timestamp); - if let Some(x) = args.data { builder.add_data(x); } + if let Some(x) = args.data { + builder.add_data(x); + } builder.add_data_type(args.data_type); builder.add_status(args.status); builder.add_action(args.action); builder.finish() } - #[inline] pub fn action(&self) -> Action { // Safety: // Created from valid Table for this object // which contains a valid value in this slot - unsafe { self._tab.get::(Event::VT_ACTION, Some(Action::unused)).unwrap()} + unsafe { + self._tab + .get::(Event::VT_ACTION, Some(Action::unused)) + .unwrap() + } } #[inline] pub fn timestamp(&self) -> u64 { // Safety: // Created from valid Table for this object // which contains a valid value in this slot - unsafe { self._tab.get::(Event::VT_TIMESTAMP, Some(0)).unwrap()} + unsafe { self._tab.get::(Event::VT_TIMESTAMP, Some(0)).unwrap() } } #[inline] pub fn status(&self) -> ActionStatus { // Safety: // Created from valid Table for this object // which contains a valid value in this slot - unsafe { self._tab.get::(Event::VT_STATUS, Some(ActionStatus::unused)).unwrap()} + unsafe { + self._tab + .get::(Event::VT_STATUS, Some(ActionStatus::unused)) + .unwrap() + } } #[inline] pub fn data_type(&self) -> EventData { // Safety: // Created from valid Table for this object // which contains a valid value in this slot - unsafe { self._tab.get::(Event::VT_DATA_TYPE, Some(EventData::NONE)).unwrap()} + unsafe { + self._tab + .get::(Event::VT_DATA_TYPE, Some(EventData::NONE)) + .unwrap() + } } #[inline] pub fn data(&self) -> Option> { // Safety: // Created from valid Table for this object // which contains a valid value in this slot - unsafe { self._tab.get::>>(Event::VT_DATA, None)} + unsafe { + self._tab + .get::>>( + Event::VT_DATA, + None, + ) + } } #[inline] #[allow(non_snake_case)] @@ -1142,26 +1425,43 @@ pub mod arkavo { None } } - } impl flatbuffers::Verifiable for Event<'_> { #[inline] fn run_verifier( - v: &mut flatbuffers::Verifier, pos: usize + v: &mut flatbuffers::Verifier, + pos: usize, ) -> Result<(), flatbuffers::InvalidFlatbuffer> { v.visit_table(pos)? .visit_field::("action", Self::VT_ACTION, false)? .visit_field::("timestamp", Self::VT_TIMESTAMP, false)? .visit_field::("status", Self::VT_STATUS, false)? - .visit_union::("data_type", Self::VT_DATA_TYPE, "data", Self::VT_DATA, false, |key, v, pos| { - match key { - EventData::UserEvent => v.verify_union_variant::>("EventData::UserEvent", pos), - EventData::CacheEvent => v.verify_union_variant::>("EventData::CacheEvent", pos), - EventData::RouteEvent => v.verify_union_variant::>("EventData::RouteEvent", pos), + .visit_union::( + "data_type", + Self::VT_DATA_TYPE, + "data", + Self::VT_DATA, + false, + |key, v, pos| match key { + EventData::UserEvent => v + .verify_union_variant::>( + "EventData::UserEvent", + pos, + ), + EventData::CacheEvent => v + .verify_union_variant::>( + "EventData::CacheEvent", + pos, + ), + EventData::RouteEvent => v + .verify_union_variant::>( + "EventData::RouteEvent", + pos, + ), _ => Ok(()), - } - })? + }, + )? .finish(); Ok(()) } @@ -1193,23 +1493,28 @@ pub mod arkavo { impl<'a: 'b, 'b, A: flatbuffers::Allocator + 'a> EventBuilder<'a, 'b, A> { #[inline] pub fn add_action(&mut self, action: Action) { - self.fbb_.push_slot::(Event::VT_ACTION, action, Action::unused); + self.fbb_ + .push_slot::(Event::VT_ACTION, action, Action::unused); } #[inline] pub fn add_timestamp(&mut self, timestamp: u64) { - self.fbb_.push_slot::(Event::VT_TIMESTAMP, timestamp, 0); + self.fbb_ + .push_slot::(Event::VT_TIMESTAMP, timestamp, 0); } #[inline] pub fn add_status(&mut self, status: ActionStatus) { - self.fbb_.push_slot::(Event::VT_STATUS, status, ActionStatus::unused); + self.fbb_ + .push_slot::(Event::VT_STATUS, status, ActionStatus::unused); } #[inline] pub fn add_data_type(&mut self, data_type: EventData) { - self.fbb_.push_slot::(Event::VT_DATA_TYPE, data_type, EventData::NONE); + self.fbb_ + .push_slot::(Event::VT_DATA_TYPE, data_type, EventData::NONE); } #[inline] pub fn add_data(&mut self, data: flatbuffers::WIPOffset) { - self.fbb_.push_slot_always::>(Event::VT_DATA, data); + self.fbb_ + .push_slot_always::>(Event::VT_DATA, data); } #[inline] pub fn new(_fbb: &'b mut flatbuffers::FlatBufferBuilder<'a, A>) -> EventBuilder<'a, 'b, A> { @@ -1238,27 +1543,36 @@ pub mod arkavo { if let Some(x) = self.data_as_user_event() { ds.field("data", &x) } else { - ds.field("data", &"InvalidFlatbuffer: Union discriminant does not match value.") + ds.field( + "data", + &"InvalidFlatbuffer: Union discriminant does not match value.", + ) } - }, + } EventData::CacheEvent => { if let Some(x) = self.data_as_cache_event() { ds.field("data", &x) } else { - ds.field("data", &"InvalidFlatbuffer: Union discriminant does not match value.") + ds.field( + "data", + &"InvalidFlatbuffer: Union discriminant does not match value.", + ) } - }, + } EventData::RouteEvent => { if let Some(x) = self.data_as_route_event() { ds.field("data", &x) } else { - ds.field("data", &"InvalidFlatbuffer: Union discriminant does not match value.") + ds.field( + "data", + &"InvalidFlatbuffer: Union discriminant does not match value.", + ) } - }, + } _ => { let x: Option<()> = None; ds.field("data", &x) - }, + } }; ds.finish() } @@ -1280,7 +1594,9 @@ pub mod arkavo { /// catch every error, or be maximally performant. For the /// previous, unchecked, behavior use /// `size_prefixed_root_as_event_unchecked`. - pub fn size_prefixed_root_as_event(buf: &[u8]) -> Result { + pub fn size_prefixed_root_as_event( + buf: &[u8], + ) -> Result { flatbuffers::size_prefixed_root::(buf) } #[inline] @@ -1326,13 +1642,16 @@ pub mod arkavo { #[inline] pub fn finish_event_buffer<'a, 'b, A: flatbuffers::Allocator + 'a>( fbb: &'b mut flatbuffers::FlatBufferBuilder<'a, A>, - root: flatbuffers::WIPOffset>) { + root: flatbuffers::WIPOffset>, + ) { fbb.finish(root, None); } #[inline] - pub fn finish_size_prefixed_event_buffer<'a, 'b, A: flatbuffers::Allocator + 'a>(fbb: &'b mut flatbuffers::FlatBufferBuilder<'a, A>, root: flatbuffers::WIPOffset>) { + pub fn finish_size_prefixed_event_buffer<'a, 'b, A: flatbuffers::Allocator + 'a>( + fbb: &'b mut flatbuffers::FlatBufferBuilder<'a, A>, + root: flatbuffers::WIPOffset>, + ) { fbb.finish_size_prefixed(root, None); } -} // pub mod Arkavo - +} // pub mod Arkavo From 52f8f76ef5e732a04a09fc623da2d5e335feffa5 Mon Sep 17 00:00:00 2001 From: Paul Flynn Date: Wed, 23 Oct 2024 23:16:24 -0400 Subject: [PATCH 13/15] Add content rating contract and integration Introduce a new content rating contract with age and rating levels. Integrate content rating validation into the main module to enforce content policies based on predefined rating criteria. --- src/bin/contracts/content_rating.rs | 217 ++++++++++++++++++++++++++++ src/bin/contracts/mod.rs | 1 + src/bin/main.rs | 35 ++++- 3 files changed, 251 insertions(+), 2 deletions(-) create mode 100644 src/bin/contracts/content_rating.rs diff --git a/src/bin/contracts/content_rating.rs b/src/bin/contracts/content_rating.rs new file mode 100644 index 0000000..a90fe46 --- /dev/null +++ b/src/bin/contracts/content_rating.rs @@ -0,0 +1,217 @@ +#![allow(unexpected_cfgs)] +#[ink::contract] +pub mod content_rating { + #[derive(Debug, PartialEq, Eq, scale::Encode, scale::Decode)] + #[cfg_attr(feature = "std", derive(scale_info::TypeInfo))] + pub enum RatingLevel { + Unused = 0, + None = 1, + Mild = 2, + Moderate = 3, + Severe = 4, + } + + #[derive(Debug, PartialEq, Eq, scale::Encode, scale::Decode)] + #[cfg_attr(feature = "std", derive(scale_info::TypeInfo))] + pub struct Rating { + pub violent: RatingLevel, + pub sexual: RatingLevel, + pub profane: RatingLevel, + pub substance: RatingLevel, + pub hate: RatingLevel, + pub harm: RatingLevel, + pub mature: RatingLevel, + pub bully: RatingLevel, + } + + #[derive(Debug, PartialEq, Eq, scale::Encode, scale::Decode)] + #[cfg_attr(feature = "std", derive(scale_info::TypeInfo))] + pub enum AgeLevel { + Kids, // Under 13 + Teens, // 13 to 17 + Adults, // 18 and above + } + + #[derive(Debug, PartialEq, Eq, scale::Encode, scale::Decode)] + #[cfg_attr(feature = "std", derive(scale_info::TypeInfo))] + pub enum Error { + ViolentContentTooHigh, + SexualContentNotAllowed, + ProfaneContentNotAllowed, + SubstanceContentNotAllowed, + HateContentNotAllowed, + HarmContentNotAllowed, + MatureContentNotAllowed, + BullyingContentNotAllowed, + } + + #[ink(storage)] + pub struct ContentRating { + // Contract storage (empty for this case) + } + + impl ContentRating { + #[ink(constructor)] + pub fn new() -> Self { + Self {} + } + + #[ink(message)] + pub fn validate_content(&self, age_level: AgeLevel, rating: Rating) -> Result<(), Error> { + match age_level { + AgeLevel::Kids => self.validate_kids_content(&rating), + AgeLevel::Teens => self.validate_teens_content(&rating), + AgeLevel::Adults => Ok(()), // Everything is allowed for adults + } + } + + fn validate_kids_content(&self, rating: &Rating) -> Result<(), Error> { + // For kids, only mild violence is allowed, everything else must be none + if !matches!(rating.violent, RatingLevel::None | RatingLevel::Mild) { + return Err(Error::ViolentContentTooHigh); + } + if !matches!(rating.sexual, RatingLevel::None) { + return Err(Error::SexualContentNotAllowed); + } + if !matches!(rating.profane, RatingLevel::None) { + return Err(Error::ProfaneContentNotAllowed); + } + if !matches!(rating.substance, RatingLevel::None) { + return Err(Error::SubstanceContentNotAllowed); + } + if !matches!(rating.hate, RatingLevel::None) { + return Err(Error::HateContentNotAllowed); + } + if !matches!(rating.harm, RatingLevel::None) { + return Err(Error::HarmContentNotAllowed); + } + if !matches!(rating.mature, RatingLevel::None) { + return Err(Error::MatureContentNotAllowed); + } + if !matches!(rating.bully, RatingLevel::None) { + return Err(Error::BullyingContentNotAllowed); + } + Ok(()) + } + + fn validate_teens_content(&self, rating: &Rating) -> Result<(), Error> { + // For teens, certain content must be none, others can be up to mild + if matches!(rating.violent, RatingLevel::Moderate | RatingLevel::Severe) { + return Err(Error::ViolentContentTooHigh); + } + if matches!(rating.sexual, RatingLevel::Moderate | RatingLevel::Severe) { + return Err(Error::SexualContentNotAllowed); + } + if matches!(rating.profane, RatingLevel::Moderate | RatingLevel::Severe) { + return Err(Error::ProfaneContentNotAllowed); + } + // These must be none for teens + if !matches!(rating.substance, RatingLevel::None) { + return Err(Error::SubstanceContentNotAllowed); + } + if !matches!(rating.hate, RatingLevel::None) { + return Err(Error::HateContentNotAllowed); + } + if !matches!(rating.harm, RatingLevel::None) { + return Err(Error::HarmContentNotAllowed); + } + if matches!(rating.mature, RatingLevel::Moderate | RatingLevel::Severe) { + return Err(Error::MatureContentNotAllowed); + } + if !matches!(rating.bully, RatingLevel::None) { + return Err(Error::BullyingContentNotAllowed); + } + Ok(()) + } + + #[ink(message)] + pub fn check_content(&self, age_level: AgeLevel, rating: Rating) -> bool { + self.validate_content(age_level, rating).is_ok() + } + } + + #[cfg(test)] + mod tests { + use super::*; + + #[ink::test] + fn kids_content_validation_works() { + let contract = ContentRating::new(); + + // Valid kids content + let valid_kids_rating = Rating { + violent: RatingLevel::Mild, + sexual: RatingLevel::None, + profane: RatingLevel::None, + substance: RatingLevel::None, + hate: RatingLevel::None, + harm: RatingLevel::None, + mature: RatingLevel::None, + bully: RatingLevel::None, + }; + assert!(contract.check_content(AgeLevel::Kids, valid_kids_rating)); + + // Invalid kids content (too violent) + let invalid_kids_rating = Rating { + violent: RatingLevel::Moderate, + sexual: RatingLevel::None, + profane: RatingLevel::None, + substance: RatingLevel::None, + hate: RatingLevel::None, + harm: RatingLevel::None, + mature: RatingLevel::None, + bully: RatingLevel::None, + }; + assert!(!contract.check_content(AgeLevel::Kids, invalid_kids_rating)); + } + + #[ink::test] + fn teens_content_validation_works() { + let contract = ContentRating::new(); + + // Valid teens content + let valid_teens_rating = Rating { + violent: RatingLevel::Mild, + sexual: RatingLevel::Mild, + profane: RatingLevel::Mild, + substance: RatingLevel::None, + hate: RatingLevel::None, + harm: RatingLevel::None, + mature: RatingLevel::Mild, + bully: RatingLevel::None, + }; + assert!(contract.check_content(AgeLevel::Teens, valid_teens_rating)); + + // Invalid teens content (substance use) + let invalid_teens_rating = Rating { + violent: RatingLevel::Mild, + sexual: RatingLevel::Mild, + profane: RatingLevel::Mild, + substance: RatingLevel::Mild, + hate: RatingLevel::None, + harm: RatingLevel::None, + mature: RatingLevel::Mild, + bully: RatingLevel::None, + }; + assert!(!contract.check_content(AgeLevel::Teens, invalid_teens_rating)); + } + + #[ink::test] + fn adult_content_validation_works() { + let contract = ContentRating::new(); + + // All content levels are valid for adults + let adult_rating = Rating { + violent: RatingLevel::Severe, + sexual: RatingLevel::Severe, + profane: RatingLevel::Severe, + substance: RatingLevel::Severe, + hate: RatingLevel::Severe, + harm: RatingLevel::Severe, + mature: RatingLevel::Severe, + bully: RatingLevel::Severe, + }; + assert!(contract.check_content(AgeLevel::Adults, adult_rating)); + } + } +} diff --git a/src/bin/contracts/mod.rs b/src/bin/contracts/mod.rs index a1d09b9..22b537a 100644 --- a/src/bin/contracts/mod.rs +++ b/src/bin/contracts/mod.rs @@ -1,2 +1,3 @@ pub mod contract_simple_abac; pub mod geo_fence_contract; +pub mod content_rating; diff --git a/src/bin/main.rs b/src/bin/main.rs index 631dcc7..afc5d0b 100644 --- a/src/bin/main.rs +++ b/src/bin/main.rs @@ -1,9 +1,9 @@ mod contracts; mod schemas; -use crate::contracts::contract_simple_abac; -use crate::contracts::geo_fence_contract; +use crate::contracts::content_rating::content_rating::{AgeLevel, ContentRating, Rating, RatingLevel}; use crate::contracts::geo_fence_contract::geo_fence_contract::Geofence3D; +use crate::contracts::{contract_simple_abac, geo_fence_contract}; use crate::schemas::event_generated::arkavo::{Event, EventData}; use aes_gcm::aead::generic_array::GenericArray; use aes_gcm::aead::KeyInit; @@ -607,6 +607,37 @@ async fn handle_rewrap( // return Some(Message::Binary(response_data)); // } } + // content_rating + else if locator + .body + .contains("5HKLo6CKbt1Z5dU4wZ3MiufeZzjM6JGwKUWUQ6a91fmuA6RB") + { + println!("contract content rating"); + let contract = ContentRating::new(); + // Parse the content rating data from the policy body + if let Some(body) = policy_body { + if body.len() >= 8 { + let age_level = AgeLevel::Kids; + let rating = Rating { + violent: RatingLevel::Mild, + sexual: RatingLevel::None, + profane: RatingLevel::None, + substance: RatingLevel::None, + hate: RatingLevel::None, + harm: RatingLevel::None, + mature: RatingLevel::None, + bully: RatingLevel::None, + }; + if !contract.check_content(age_level, rating) { + println!("content rating DENY"); + return None; + } + } else { + println!("policy body DENY"); + return None; + } + } + } // simple_abac else if locator .body From 20008b25dc2f5028bc8191a8fdd3fa291a436444 Mon Sep 17 00:00:00 2001 From: Paul Flynn Date: Thu, 24 Oct 2024 20:18:41 -0400 Subject: [PATCH 14/15] Create metadata_generated.rs with enums and structs This file is automatically generated using the FlatBuffers compiler. It includes various enums like RatingLevel, FormatType, DataEncoding, and ArchiveType, as well as structs such as Rating and Purpose. --- README.md | 2 + src/bin/main.rs | 99 +- src/bin/schemas/entity_generated.rs | 2065 +++++++++++++++++++++++++ src/bin/schemas/metadata_generated.rs | 1571 +++++++++++++++++++ src/bin/schemas/mod.rs | 2 + src/lib.rs | 4 +- 6 files changed, 3703 insertions(+), 40 deletions(-) create mode 100644 src/bin/schemas/entity_generated.rs create mode 100644 src/bin/schemas/metadata_generated.rs diff --git a/README.md b/README.md index c33f591..a8f761a 100644 --- a/README.md +++ b/README.md @@ -25,6 +25,8 @@ brew install nats-server redis flatbuffers ```shell flatc --binary --rust idl/event.fbs +flatc --binary --rust idl/entity.fbs +flatc --binary --rust idl/metadata.fbs ``` ### Installation diff --git a/src/bin/main.rs b/src/bin/main.rs index afc5d0b..32a877a 100644 --- a/src/bin/main.rs +++ b/src/bin/main.rs @@ -39,6 +39,8 @@ use tokio::net::TcpListener; use tokio::sync::{mpsc, Mutex}; use tokio_native_tls::TlsAcceptor; use tokio_tungstenite::tungstenite::Message; +use crate::schemas::metadata_generated::arkavo; +use crate::schemas::metadata_generated::arkavo::{root_as_metadata, Metadata}; #[derive(Serialize, Deserialize, Debug)] struct PublicKeyMessage { @@ -508,23 +510,34 @@ async fn handle_rewrap( } // TDF contract let policy = header.get_policy(); - let locator: Option<&ResourceLocator>; - let mut embedded_locator: Option = None; - let mut policy_body: Option<&[u8]> = None; + // println!("policy: {:?}", policy); + let locator: Option; + let policy_body: Option<&[u8]> = None; + let mut metadata: Option = None; match policy.policy_type { PolicyType::Remote => { - locator = policy.get_locator().as_ref(); + locator = policy.get_locator().clone(); } PolicyType::Embedded => { + // println!("embedded policy"); if let Some(body) = &policy.body { - let mut parser = BinaryParser::new(body); - if let Ok(parsed_locator) = parser.read_kas_field() { - embedded_locator = Some(parsed_locator); - policy_body = Some(&body[parser.position..]); - } + metadata = match root_as_metadata(body) { + Ok(metadata) => Some(metadata), + Err(e) => { + eprintln!("Failed to parse metadata: {}", e); + return None; + } + }; + // TODO add contracts + // println!("metadata: {:#?}", metadata); } - locator = embedded_locator.as_ref(); + // add content rating contract + let rl = ResourceLocator{ + protocol_enum: ProtocolEnum::SharedResource, + body: "5HKLo6CKbt1Z5dU4wZ3MiufeZzjM6JGwKUWUQ6a91fmuA6RB".to_string(), + }; + locator = Some(rl); } } if let Some(locator) = &locator { @@ -615,35 +628,34 @@ async fn handle_rewrap( println!("contract content rating"); let contract = ContentRating::new(); // Parse the content rating data from the policy body - if let Some(body) = policy_body { - if body.len() >= 8 { - let age_level = AgeLevel::Kids; - let rating = Rating { - violent: RatingLevel::Mild, - sexual: RatingLevel::None, - profane: RatingLevel::None, - substance: RatingLevel::None, - hate: RatingLevel::None, - harm: RatingLevel::None, - mature: RatingLevel::None, - bully: RatingLevel::None, - }; - if !contract.check_content(age_level, rating) { - println!("content rating DENY"); - return None; - } - } else { - println!("policy body DENY"); - return None; - } + // get entitlements + let age_level = AgeLevel::Kids; + if metadata == None { + println!("metadata is null"); + return None; } - } - // simple_abac - else if locator - .body - .contains("5Cqk3ERPToSMuY8UoKJtcmo4fs1iVyQpq6ndzWzpzWezAF1W") - { - let contract = contract_simple_abac::simple_abac::SimpleAbac::new(); + let rating_data = metadata.unwrap().rating()?; + let rating = Rating { + violent: convert_rating_level(rating_data.violent()), + sexual: convert_rating_level(rating_data.sexual()), + profane: convert_rating_level(rating_data.profane()), + substance: convert_rating_level(rating_data.substance()), + hate: convert_rating_level(rating_data.hate()), + harm: convert_rating_level(rating_data.harm()), + mature: convert_rating_level(rating_data.mature()), + bully: convert_rating_level(rating_data.bully()), + }; + if !contract.check_content(age_level, rating) { + println!("content rating DENY"); + return None; + } + } + // simple_abac + else if locator + .body + .contains("5Cqk3ERPToSMuY8UoKJtcmo4fs1iVyQpq6ndzWzpzWezAF1W") + { + let contract = contract_simple_abac::simple_abac::SimpleAbac::new(); if claims_result.is_ok() && !contract.check_access(claims_result.unwrap(), locator.body.clone()) { @@ -1351,3 +1363,14 @@ mod tests { pub scalar: NonZeroScalar, } } + +fn convert_rating_level(level: arkavo::RatingLevel) -> RatingLevel { + match level.0 { + x if x == arkavo::RatingLevel::unused.0 => RatingLevel::Unused, + x if x == arkavo::RatingLevel::none.0 => RatingLevel::None, + x if x == arkavo::RatingLevel::mild.0 => RatingLevel::Mild, + x if x == arkavo::RatingLevel::moderate.0 => RatingLevel::Moderate, + x if x == arkavo::RatingLevel::severe.0 => RatingLevel::Severe, + _ => RatingLevel::Unused, // Default to Unused for any invalid values + } +} \ No newline at end of file diff --git a/src/bin/schemas/entity_generated.rs b/src/bin/schemas/entity_generated.rs new file mode 100644 index 0000000..213c08c --- /dev/null +++ b/src/bin/schemas/entity_generated.rs @@ -0,0 +1,2065 @@ +// automatically generated by the FlatBuffers compiler, do not modify +#![allow(clippy::extra_unused_lifetimes)] + +// @generated + +extern crate flatbuffers; + +#[allow(unused_imports, dead_code)] +pub mod arkavo { + + use core::mem; + use core::cmp::Ordering; + + extern crate flatbuffers; + use self::flatbuffers::{EndianScalar, Follow}; + +#[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")] +pub const ENUM_MIN_ACTIVITY_LEVEL: i8 = 0; +#[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")] +pub const ENUM_MAX_ACTIVITY_LEVEL: i8 = 3; +#[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")] +#[allow(non_camel_case_types)] +pub const ENUM_VALUES_ACTIVITY_LEVEL: [ActivityLevel; 4] = [ + ActivityLevel::unused, + ActivityLevel::low, + ActivityLevel::medium, + ActivityLevel::high, +]; + +#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Default)] +#[repr(transparent)] +pub struct ActivityLevel(pub i8); +#[allow(non_upper_case_globals)] +impl ActivityLevel { + pub const unused: Self = Self(0); + pub const low: Self = Self(1); + pub const medium: Self = Self(2); + pub const high: Self = Self(3); + + pub const ENUM_MIN: i8 = 0; + pub const ENUM_MAX: i8 = 3; + pub const ENUM_VALUES: &'static [Self] = &[ + Self::unused, + Self::low, + Self::medium, + Self::high, + ]; + /// Returns the variant's name or "" if unknown. + pub fn variant_name(self) -> Option<&'static str> { + match self { + Self::unused => Some("unused"), + Self::low => Some("low"), + Self::medium => Some("medium"), + Self::high => Some("high"), + _ => None, + } + } +} +impl core::fmt::Debug for ActivityLevel { + fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result { + if let Some(name) = self.variant_name() { + f.write_str(name) + } else { + f.write_fmt(format_args!("", self.0)) + } + } +} +impl<'a> flatbuffers::Follow<'a> for ActivityLevel { + type Inner = Self; + #[inline] + unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { + let b = flatbuffers::read_scalar_at::(buf, loc); + Self(b) + } +} + +impl flatbuffers::Push for ActivityLevel { + type Output = ActivityLevel; + #[inline] + unsafe fn push(&self, dst: &mut [u8], _written_len: usize) { + flatbuffers::emplace_scalar::(dst, self.0); + } +} + +impl flatbuffers::EndianScalar for ActivityLevel { + type Scalar = i8; + #[inline] + fn to_little_endian(self) -> i8 { + self.0.to_le() + } + #[inline] + #[allow(clippy::wrong_self_convention)] + fn from_little_endian(v: i8) -> Self { + let b = i8::from_le(v); + Self(b) + } +} + +impl<'a> flatbuffers::Verifiable for ActivityLevel { + #[inline] + fn run_verifier( + v: &mut flatbuffers::Verifier, pos: usize + ) -> Result<(), flatbuffers::InvalidFlatbuffer> { + use self::flatbuffers::Verifiable; + i8::run_verifier(v, pos) + } +} + +impl flatbuffers::SimpleToVerifyInSlice for ActivityLevel {} +#[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")] +pub const ENUM_MIN_MEDIA_TYPE: i8 = 0; +#[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")] +pub const ENUM_MAX_MEDIA_TYPE: i8 = 4; +#[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")] +#[allow(non_camel_case_types)] +pub const ENUM_VALUES_MEDIA_TYPE: [MediaType; 5] = [ + MediaType::unused, + MediaType::text, + MediaType::image, + MediaType::video, + MediaType::audio, +]; + +#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Default)] +#[repr(transparent)] +pub struct MediaType(pub i8); +#[allow(non_upper_case_globals)] +impl MediaType { + pub const unused: Self = Self(0); + pub const text: Self = Self(1); + pub const image: Self = Self(2); + pub const video: Self = Self(3); + pub const audio: Self = Self(4); + + pub const ENUM_MIN: i8 = 0; + pub const ENUM_MAX: i8 = 4; + pub const ENUM_VALUES: &'static [Self] = &[ + Self::unused, + Self::text, + Self::image, + Self::video, + Self::audio, + ]; + /// Returns the variant's name or "" if unknown. + pub fn variant_name(self) -> Option<&'static str> { + match self { + Self::unused => Some("unused"), + Self::text => Some("text"), + Self::image => Some("image"), + Self::video => Some("video"), + Self::audio => Some("audio"), + _ => None, + } + } +} +impl core::fmt::Debug for MediaType { + fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result { + if let Some(name) = self.variant_name() { + f.write_str(name) + } else { + f.write_fmt(format_args!("", self.0)) + } + } +} +impl<'a> flatbuffers::Follow<'a> for MediaType { + type Inner = Self; + #[inline] + unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { + let b = flatbuffers::read_scalar_at::(buf, loc); + Self(b) + } +} + +impl flatbuffers::Push for MediaType { + type Output = MediaType; + #[inline] + unsafe fn push(&self, dst: &mut [u8], _written_len: usize) { + flatbuffers::emplace_scalar::(dst, self.0); + } +} + +impl flatbuffers::EndianScalar for MediaType { + type Scalar = i8; + #[inline] + fn to_little_endian(self) -> i8 { + self.0.to_le() + } + #[inline] + #[allow(clippy::wrong_self_convention)] + fn from_little_endian(v: i8) -> Self { + let b = i8::from_le(v); + Self(b) + } +} + +impl<'a> flatbuffers::Verifiable for MediaType { + #[inline] + fn run_verifier( + v: &mut flatbuffers::Verifier, pos: usize + ) -> Result<(), flatbuffers::InvalidFlatbuffer> { + use self::flatbuffers::Verifiable; + i8::run_verifier(v, pos) + } +} + +impl flatbuffers::SimpleToVerifyInSlice for MediaType {} +#[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")] +pub const ENUM_MIN_LOCATION_LEVEL: i8 = 0; +#[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")] +pub const ENUM_MAX_LOCATION_LEVEL: i8 = 3; +#[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")] +#[allow(non_camel_case_types)] +pub const ENUM_VALUES_LOCATION_LEVEL: [LocationLevel; 4] = [ + LocationLevel::unused, + LocationLevel::wide, + LocationLevel::approximate, + LocationLevel::precise, +]; + +#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Default)] +#[repr(transparent)] +pub struct LocationLevel(pub i8); +#[allow(non_upper_case_globals)] +impl LocationLevel { + pub const unused: Self = Self(0); + pub const wide: Self = Self(1); + pub const approximate: Self = Self(2); + pub const precise: Self = Self(3); + + pub const ENUM_MIN: i8 = 0; + pub const ENUM_MAX: i8 = 3; + pub const ENUM_VALUES: &'static [Self] = &[ + Self::unused, + Self::wide, + Self::approximate, + Self::precise, + ]; + /// Returns the variant's name or "" if unknown. + pub fn variant_name(self) -> Option<&'static str> { + match self { + Self::unused => Some("unused"), + Self::wide => Some("wide"), + Self::approximate => Some("approximate"), + Self::precise => Some("precise"), + _ => None, + } + } +} +impl core::fmt::Debug for LocationLevel { + fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result { + if let Some(name) = self.variant_name() { + f.write_str(name) + } else { + f.write_fmt(format_args!("", self.0)) + } + } +} +impl<'a> flatbuffers::Follow<'a> for LocationLevel { + type Inner = Self; + #[inline] + unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { + let b = flatbuffers::read_scalar_at::(buf, loc); + Self(b) + } +} + +impl flatbuffers::Push for LocationLevel { + type Output = LocationLevel; + #[inline] + unsafe fn push(&self, dst: &mut [u8], _written_len: usize) { + flatbuffers::emplace_scalar::(dst, self.0); + } +} + +impl flatbuffers::EndianScalar for LocationLevel { + type Scalar = i8; + #[inline] + fn to_little_endian(self) -> i8 { + self.0.to_le() + } + #[inline] + #[allow(clippy::wrong_self_convention)] + fn from_little_endian(v: i8) -> Self { + let b = i8::from_le(v); + Self(b) + } +} + +impl<'a> flatbuffers::Verifiable for LocationLevel { + #[inline] + fn run_verifier( + v: &mut flatbuffers::Verifier, pos: usize + ) -> Result<(), flatbuffers::InvalidFlatbuffer> { + use self::flatbuffers::Verifiable; + i8::run_verifier(v, pos) + } +} + +impl flatbuffers::SimpleToVerifyInSlice for LocationLevel {} +#[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")] +pub const ENUM_MIN_IDENTITY_ASSURANCE_LEVEL: i8 = 0; +#[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")] +pub const ENUM_MAX_IDENTITY_ASSURANCE_LEVEL: i8 = 5; +#[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")] +#[allow(non_camel_case_types)] +pub const ENUM_VALUES_IDENTITY_ASSURANCE_LEVEL: [IdentityAssuranceLevel; 6] = [ + IdentityAssuranceLevel::unused, + IdentityAssuranceLevel::ial0, + IdentityAssuranceLevel::ial1, + IdentityAssuranceLevel::ial2, + IdentityAssuranceLevel::ial25, + IdentityAssuranceLevel::ial3, +]; + +#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Default)] +#[repr(transparent)] +pub struct IdentityAssuranceLevel(pub i8); +#[allow(non_upper_case_globals)] +impl IdentityAssuranceLevel { + pub const unused: Self = Self(0); + pub const ial0: Self = Self(1); + pub const ial1: Self = Self(2); + pub const ial2: Self = Self(3); + pub const ial25: Self = Self(4); + pub const ial3: Self = Self(5); + + pub const ENUM_MIN: i8 = 0; + pub const ENUM_MAX: i8 = 5; + pub const ENUM_VALUES: &'static [Self] = &[ + Self::unused, + Self::ial0, + Self::ial1, + Self::ial2, + Self::ial25, + Self::ial3, + ]; + /// Returns the variant's name or "" if unknown. + pub fn variant_name(self) -> Option<&'static str> { + match self { + Self::unused => Some("unused"), + Self::ial0 => Some("ial0"), + Self::ial1 => Some("ial1"), + Self::ial2 => Some("ial2"), + Self::ial25 => Some("ial25"), + Self::ial3 => Some("ial3"), + _ => None, + } + } +} +impl core::fmt::Debug for IdentityAssuranceLevel { + fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result { + if let Some(name) = self.variant_name() { + f.write_str(name) + } else { + f.write_fmt(format_args!("", self.0)) + } + } +} +impl<'a> flatbuffers::Follow<'a> for IdentityAssuranceLevel { + type Inner = Self; + #[inline] + unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { + let b = flatbuffers::read_scalar_at::(buf, loc); + Self(b) + } +} + +impl flatbuffers::Push for IdentityAssuranceLevel { + type Output = IdentityAssuranceLevel; + #[inline] + unsafe fn push(&self, dst: &mut [u8], _written_len: usize) { + flatbuffers::emplace_scalar::(dst, self.0); + } +} + +impl flatbuffers::EndianScalar for IdentityAssuranceLevel { + type Scalar = i8; + #[inline] + fn to_little_endian(self) -> i8 { + self.0.to_le() + } + #[inline] + #[allow(clippy::wrong_self_convention)] + fn from_little_endian(v: i8) -> Self { + let b = i8::from_le(v); + Self(b) + } +} + +impl<'a> flatbuffers::Verifiable for IdentityAssuranceLevel { + #[inline] + fn run_verifier( + v: &mut flatbuffers::Verifier, pos: usize + ) -> Result<(), flatbuffers::InvalidFlatbuffer> { + use self::flatbuffers::Verifiable; + i8::run_verifier(v, pos) + } +} + +impl flatbuffers::SimpleToVerifyInSlice for IdentityAssuranceLevel {} +#[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")] +pub const ENUM_MIN_ENCRYPTION_LEVEL: i8 = 0; +#[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")] +pub const ENUM_MAX_ENCRYPTION_LEVEL: i8 = 3; +#[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")] +#[allow(non_camel_case_types)] +pub const ENUM_VALUES_ENCRYPTION_LEVEL: [EncryptionLevel; 4] = [ + EncryptionLevel::unused, + EncryptionLevel::el0, + EncryptionLevel::el1, + EncryptionLevel::el2, +]; + +#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Default)] +#[repr(transparent)] +pub struct EncryptionLevel(pub i8); +#[allow(non_upper_case_globals)] +impl EncryptionLevel { + pub const unused: Self = Self(0); + pub const el0: Self = Self(1); + pub const el1: Self = Self(2); + pub const el2: Self = Self(3); + + pub const ENUM_MIN: i8 = 0; + pub const ENUM_MAX: i8 = 3; + pub const ENUM_VALUES: &'static [Self] = &[ + Self::unused, + Self::el0, + Self::el1, + Self::el2, + ]; + /// Returns the variant's name or "" if unknown. + pub fn variant_name(self) -> Option<&'static str> { + match self { + Self::unused => Some("unused"), + Self::el0 => Some("el0"), + Self::el1 => Some("el1"), + Self::el2 => Some("el2"), + _ => None, + } + } +} +impl core::fmt::Debug for EncryptionLevel { + fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result { + if let Some(name) = self.variant_name() { + f.write_str(name) + } else { + f.write_fmt(format_args!("", self.0)) + } + } +} +impl<'a> flatbuffers::Follow<'a> for EncryptionLevel { + type Inner = Self; + #[inline] + unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { + let b = flatbuffers::read_scalar_at::(buf, loc); + Self(b) + } +} + +impl flatbuffers::Push for EncryptionLevel { + type Output = EncryptionLevel; + #[inline] + unsafe fn push(&self, dst: &mut [u8], _written_len: usize) { + flatbuffers::emplace_scalar::(dst, self.0); + } +} + +impl flatbuffers::EndianScalar for EncryptionLevel { + type Scalar = i8; + #[inline] + fn to_little_endian(self) -> i8 { + self.0.to_le() + } + #[inline] + #[allow(clippy::wrong_self_convention)] + fn from_little_endian(v: i8) -> Self { + let b = i8::from_le(v); + Self(b) + } +} + +impl<'a> flatbuffers::Verifiable for EncryptionLevel { + #[inline] + fn run_verifier( + v: &mut flatbuffers::Verifier, pos: usize + ) -> Result<(), flatbuffers::InvalidFlatbuffer> { + use self::flatbuffers::Verifiable; + i8::run_verifier(v, pos) + } +} + +impl flatbuffers::SimpleToVerifyInSlice for EncryptionLevel {} +#[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")] +pub const ENUM_MIN_STREAM_LEVEL: i8 = 0; +#[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")] +pub const ENUM_MAX_STREAM_LEVEL: i8 = 3; +#[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")] +#[allow(non_camel_case_types)] +pub const ENUM_VALUES_STREAM_LEVEL: [StreamLevel; 4] = [ + StreamLevel::unused, + StreamLevel::sl0, + StreamLevel::sl1, + StreamLevel::sl2, +]; + +#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Default)] +#[repr(transparent)] +pub struct StreamLevel(pub i8); +#[allow(non_upper_case_globals)] +impl StreamLevel { + pub const unused: Self = Self(0); + pub const sl0: Self = Self(1); + pub const sl1: Self = Self(2); + pub const sl2: Self = Self(3); + + pub const ENUM_MIN: i8 = 0; + pub const ENUM_MAX: i8 = 3; + pub const ENUM_VALUES: &'static [Self] = &[ + Self::unused, + Self::sl0, + Self::sl1, + Self::sl2, + ]; + /// Returns the variant's name or "" if unknown. + pub fn variant_name(self) -> Option<&'static str> { + match self { + Self::unused => Some("unused"), + Self::sl0 => Some("sl0"), + Self::sl1 => Some("sl1"), + Self::sl2 => Some("sl2"), + _ => None, + } + } +} +impl core::fmt::Debug for StreamLevel { + fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result { + if let Some(name) = self.variant_name() { + f.write_str(name) + } else { + f.write_fmt(format_args!("", self.0)) + } + } +} +impl<'a> flatbuffers::Follow<'a> for StreamLevel { + type Inner = Self; + #[inline] + unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { + let b = flatbuffers::read_scalar_at::(buf, loc); + Self(b) + } +} + +impl flatbuffers::Push for StreamLevel { + type Output = StreamLevel; + #[inline] + unsafe fn push(&self, dst: &mut [u8], _written_len: usize) { + flatbuffers::emplace_scalar::(dst, self.0); + } +} + +impl flatbuffers::EndianScalar for StreamLevel { + type Scalar = i8; + #[inline] + fn to_little_endian(self) -> i8 { + self.0.to_le() + } + #[inline] + #[allow(clippy::wrong_self_convention)] + fn from_little_endian(v: i8) -> Self { + let b = i8::from_le(v); + Self(b) + } +} + +impl<'a> flatbuffers::Verifiable for StreamLevel { + #[inline] + fn run_verifier( + v: &mut flatbuffers::Verifier, pos: usize + ) -> Result<(), flatbuffers::InvalidFlatbuffer> { + use self::flatbuffers::Verifiable; + i8::run_verifier(v, pos) + } +} + +impl flatbuffers::SimpleToVerifyInSlice for StreamLevel {} +#[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")] +pub const ENUM_MIN_EXPERT_LEVEL: i8 = 0; +#[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")] +pub const ENUM_MAX_EXPERT_LEVEL: i8 = 4; +#[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")] +#[allow(non_camel_case_types)] +pub const ENUM_VALUES_EXPERT_LEVEL: [ExpertLevel; 5] = [ + ExpertLevel::unused, + ExpertLevel::novice, + ExpertLevel::intermediate, + ExpertLevel::expert, + ExpertLevel::master, +]; + +#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Default)] +#[repr(transparent)] +pub struct ExpertLevel(pub i8); +#[allow(non_upper_case_globals)] +impl ExpertLevel { + pub const unused: Self = Self(0); + pub const novice: Self = Self(1); + pub const intermediate: Self = Self(2); + pub const expert: Self = Self(3); + pub const master: Self = Self(4); + + pub const ENUM_MIN: i8 = 0; + pub const ENUM_MAX: i8 = 4; + pub const ENUM_VALUES: &'static [Self] = &[ + Self::unused, + Self::novice, + Self::intermediate, + Self::expert, + Self::master, + ]; + /// Returns the variant's name or "" if unknown. + pub fn variant_name(self) -> Option<&'static str> { + match self { + Self::unused => Some("unused"), + Self::novice => Some("novice"), + Self::intermediate => Some("intermediate"), + Self::expert => Some("expert"), + Self::master => Some("master"), + _ => None, + } + } +} +impl core::fmt::Debug for ExpertLevel { + fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result { + if let Some(name) = self.variant_name() { + f.write_str(name) + } else { + f.write_fmt(format_args!("", self.0)) + } + } +} +impl<'a> flatbuffers::Follow<'a> for ExpertLevel { + type Inner = Self; + #[inline] + unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { + let b = flatbuffers::read_scalar_at::(buf, loc); + Self(b) + } +} + +impl flatbuffers::Push for ExpertLevel { + type Output = ExpertLevel; + #[inline] + unsafe fn push(&self, dst: &mut [u8], _written_len: usize) { + flatbuffers::emplace_scalar::(dst, self.0); + } +} + +impl flatbuffers::EndianScalar for ExpertLevel { + type Scalar = i8; + #[inline] + fn to_little_endian(self) -> i8 { + self.0.to_le() + } + #[inline] + #[allow(clippy::wrong_self_convention)] + fn from_little_endian(v: i8) -> Self { + let b = i8::from_le(v); + Self(b) + } +} + +impl<'a> flatbuffers::Verifiable for ExpertLevel { + #[inline] + fn run_verifier( + v: &mut flatbuffers::Verifier, pos: usize + ) -> Result<(), flatbuffers::InvalidFlatbuffer> { + use self::flatbuffers::Verifiable; + i8::run_verifier(v, pos) + } +} + +impl flatbuffers::SimpleToVerifyInSlice for ExpertLevel {} +#[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")] +pub const ENUM_MIN_TRUST_LEVEL: i8 = 0; +#[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")] +pub const ENUM_MAX_TRUST_LEVEL: i8 = 5; +#[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")] +#[allow(non_camel_case_types)] +pub const ENUM_VALUES_TRUST_LEVEL: [TrustLevel; 6] = [ + TrustLevel::unused, + TrustLevel::untrusted, + TrustLevel::low, + TrustLevel::medium, + TrustLevel::high, + TrustLevel::verified, +]; + +#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Default)] +#[repr(transparent)] +pub struct TrustLevel(pub i8); +#[allow(non_upper_case_globals)] +impl TrustLevel { + pub const unused: Self = Self(0); + pub const untrusted: Self = Self(1); + pub const low: Self = Self(2); + pub const medium: Self = Self(3); + pub const high: Self = Self(4); + pub const verified: Self = Self(5); + + pub const ENUM_MIN: i8 = 0; + pub const ENUM_MAX: i8 = 5; + pub const ENUM_VALUES: &'static [Self] = &[ + Self::unused, + Self::untrusted, + Self::low, + Self::medium, + Self::high, + Self::verified, + ]; + /// Returns the variant's name or "" if unknown. + pub fn variant_name(self) -> Option<&'static str> { + match self { + Self::unused => Some("unused"), + Self::untrusted => Some("untrusted"), + Self::low => Some("low"), + Self::medium => Some("medium"), + Self::high => Some("high"), + Self::verified => Some("verified"), + _ => None, + } + } +} +impl core::fmt::Debug for TrustLevel { + fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result { + if let Some(name) = self.variant_name() { + f.write_str(name) + } else { + f.write_fmt(format_args!("", self.0)) + } + } +} +impl<'a> flatbuffers::Follow<'a> for TrustLevel { + type Inner = Self; + #[inline] + unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { + let b = flatbuffers::read_scalar_at::(buf, loc); + Self(b) + } +} + +impl flatbuffers::Push for TrustLevel { + type Output = TrustLevel; + #[inline] + unsafe fn push(&self, dst: &mut [u8], _written_len: usize) { + flatbuffers::emplace_scalar::(dst, self.0); + } +} + +impl flatbuffers::EndianScalar for TrustLevel { + type Scalar = i8; + #[inline] + fn to_little_endian(self) -> i8 { + self.0.to_le() + } + #[inline] + #[allow(clippy::wrong_self_convention)] + fn from_little_endian(v: i8) -> Self { + let b = i8::from_le(v); + Self(b) + } +} + +impl<'a> flatbuffers::Verifiable for TrustLevel { + #[inline] + fn run_verifier( + v: &mut flatbuffers::Verifier, pos: usize + ) -> Result<(), flatbuffers::InvalidFlatbuffer> { + use self::flatbuffers::Verifiable; + i8::run_verifier(v, pos) + } +} + +impl flatbuffers::SimpleToVerifyInSlice for TrustLevel {} +#[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")] +pub const ENUM_MIN_ENTITY: u8 = 0; +#[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")] +pub const ENUM_MAX_ENTITY: u8 = 3; +#[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")] +#[allow(non_camel_case_types)] +pub const ENUM_VALUES_ENTITY: [Entity; 4] = [ + Entity::NONE, + Entity::Account, + Entity::Stream, + Entity::Thought, +]; + +#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Default)] +#[repr(transparent)] +pub struct Entity(pub u8); +#[allow(non_upper_case_globals)] +impl Entity { + pub const NONE: Self = Self(0); + pub const Account: Self = Self(1); + pub const Stream: Self = Self(2); + pub const Thought: Self = Self(3); + + pub const ENUM_MIN: u8 = 0; + pub const ENUM_MAX: u8 = 3; + pub const ENUM_VALUES: &'static [Self] = &[ + Self::NONE, + Self::Account, + Self::Stream, + Self::Thought, + ]; + /// Returns the variant's name or "" if unknown. + pub fn variant_name(self) -> Option<&'static str> { + match self { + Self::NONE => Some("NONE"), + Self::Account => Some("Account"), + Self::Stream => Some("Stream"), + Self::Thought => Some("Thought"), + _ => None, + } + } +} +impl core::fmt::Debug for Entity { + fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result { + if let Some(name) = self.variant_name() { + f.write_str(name) + } else { + f.write_fmt(format_args!("", self.0)) + } + } +} +impl<'a> flatbuffers::Follow<'a> for Entity { + type Inner = Self; + #[inline] + unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { + let b = flatbuffers::read_scalar_at::(buf, loc); + Self(b) + } +} + +impl flatbuffers::Push for Entity { + type Output = Entity; + #[inline] + unsafe fn push(&self, dst: &mut [u8], _written_len: usize) { + flatbuffers::emplace_scalar::(dst, self.0); + } +} + +impl flatbuffers::EndianScalar for Entity { + type Scalar = u8; + #[inline] + fn to_little_endian(self) -> u8 { + self.0.to_le() + } + #[inline] + #[allow(clippy::wrong_self_convention)] + fn from_little_endian(v: u8) -> Self { + let b = u8::from_le(v); + Self(b) + } +} + +impl<'a> flatbuffers::Verifiable for Entity { + #[inline] + fn run_verifier( + v: &mut flatbuffers::Verifier, pos: usize + ) -> Result<(), flatbuffers::InvalidFlatbuffer> { + use self::flatbuffers::Verifiable; + u8::run_verifier(v, pos) + } +} + +impl flatbuffers::SimpleToVerifyInSlice for Entity {} +pub struct EntityUnionTableOffset {} + +pub enum PublicIdOffset {} +#[derive(Copy, Clone, PartialEq)] + +pub struct PublicId<'a> { + pub _tab: flatbuffers::Table<'a>, +} + +impl<'a> flatbuffers::Follow<'a> for PublicId<'a> { + type Inner = PublicId<'a>; + #[inline] + unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { + Self { _tab: flatbuffers::Table::new(buf, loc) } + } +} + +impl<'a> PublicId<'a> { + pub const VT_ID: flatbuffers::VOffsetT = 4; + + #[inline] + pub unsafe fn init_from_table(table: flatbuffers::Table<'a>) -> Self { + PublicId { _tab: table } + } + #[allow(unused_mut)] + pub fn create<'bldr: 'args, 'args: 'mut_bldr, 'mut_bldr, A: flatbuffers::Allocator + 'bldr>( + _fbb: &'mut_bldr mut flatbuffers::FlatBufferBuilder<'bldr, A>, + args: &'args PublicIdArgs<'args> + ) -> flatbuffers::WIPOffset> { + let mut builder = PublicIdBuilder::new(_fbb); + if let Some(x) = args.id { builder.add_id(x); } + builder.finish() + } + + + #[inline] + pub fn id(&self) -> Option> { + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { self._tab.get::>>(PublicId::VT_ID, None)} + } +} + +impl flatbuffers::Verifiable for PublicId<'_> { + #[inline] + fn run_verifier( + v: &mut flatbuffers::Verifier, pos: usize + ) -> Result<(), flatbuffers::InvalidFlatbuffer> { + use self::flatbuffers::Verifiable; + v.visit_table(pos)? + .visit_field::>>("id", Self::VT_ID, false)? + .finish(); + Ok(()) + } +} +pub struct PublicIdArgs<'a> { + pub id: Option>>, +} +impl<'a> Default for PublicIdArgs<'a> { + #[inline] + fn default() -> Self { + PublicIdArgs { + id: None, + } + } +} + +pub struct PublicIdBuilder<'a: 'b, 'b, A: flatbuffers::Allocator + 'a> { + fbb_: &'b mut flatbuffers::FlatBufferBuilder<'a, A>, + start_: flatbuffers::WIPOffset, +} +impl<'a: 'b, 'b, A: flatbuffers::Allocator + 'a> PublicIdBuilder<'a, 'b, A> { + #[inline] + pub fn add_id(&mut self, id: flatbuffers::WIPOffset>) { + self.fbb_.push_slot_always::>(PublicId::VT_ID, id); + } + #[inline] + pub fn new(_fbb: &'b mut flatbuffers::FlatBufferBuilder<'a, A>) -> PublicIdBuilder<'a, 'b, A> { + let start = _fbb.start_table(); + PublicIdBuilder { + fbb_: _fbb, + start_: start, + } + } + #[inline] + pub fn finish(self) -> flatbuffers::WIPOffset> { + let o = self.fbb_.end_table(self.start_); + flatbuffers::WIPOffset::new(o.value()) + } +} + +impl core::fmt::Debug for PublicId<'_> { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + let mut ds = f.debug_struct("PublicId"); + ds.field("id", &self.id()); + ds.finish() + } +} +pub enum AccountOffset {} +#[derive(Copy, Clone, PartialEq)] + +pub struct Account<'a> { + pub _tab: flatbuffers::Table<'a>, +} + +impl<'a> flatbuffers::Follow<'a> for Account<'a> { + type Inner = Account<'a>; + #[inline] + unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { + Self { _tab: flatbuffers::Table::new(buf, loc) } + } +} + +impl<'a> Account<'a> { + pub const VT_PUBLIC_ID: flatbuffers::VOffsetT = 4; + pub const VT_PROFILE: flatbuffers::VOffsetT = 6; + pub const VT_ACTIVITY: flatbuffers::VOffsetT = 8; + + #[inline] + pub unsafe fn init_from_table(table: flatbuffers::Table<'a>) -> Self { + Account { _tab: table } + } + #[allow(unused_mut)] + pub fn create<'bldr: 'args, 'args: 'mut_bldr, 'mut_bldr, A: flatbuffers::Allocator + 'bldr>( + _fbb: &'mut_bldr mut flatbuffers::FlatBufferBuilder<'bldr, A>, + args: &'args AccountArgs<'args> + ) -> flatbuffers::WIPOffset> { + let mut builder = AccountBuilder::new(_fbb); + if let Some(x) = args.activity { builder.add_activity(x); } + if let Some(x) = args.profile { builder.add_profile(x); } + if let Some(x) = args.public_id { builder.add_public_id(x); } + builder.finish() + } + + + #[inline] + pub fn public_id(&self) -> Option> { + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { self._tab.get::>(Account::VT_PUBLIC_ID, None)} + } + #[inline] + pub fn profile(&self) -> Option> { + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { self._tab.get::>(Account::VT_PROFILE, None)} + } + #[inline] + pub fn activity(&self) -> Option> { + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { self._tab.get::>(Account::VT_ACTIVITY, None)} + } +} + +impl flatbuffers::Verifiable for Account<'_> { + #[inline] + fn run_verifier( + v: &mut flatbuffers::Verifier, pos: usize + ) -> Result<(), flatbuffers::InvalidFlatbuffer> { + use self::flatbuffers::Verifiable; + v.visit_table(pos)? + .visit_field::>("public_id", Self::VT_PUBLIC_ID, false)? + .visit_field::>("profile", Self::VT_PROFILE, false)? + .visit_field::>("activity", Self::VT_ACTIVITY, false)? + .finish(); + Ok(()) + } +} +pub struct AccountArgs<'a> { + pub public_id: Option>>, + pub profile: Option>>, + pub activity: Option>>, +} +impl<'a> Default for AccountArgs<'a> { + #[inline] + fn default() -> Self { + AccountArgs { + public_id: None, + profile: None, + activity: None, + } + } +} + +pub struct AccountBuilder<'a: 'b, 'b, A: flatbuffers::Allocator + 'a> { + fbb_: &'b mut flatbuffers::FlatBufferBuilder<'a, A>, + start_: flatbuffers::WIPOffset, +} +impl<'a: 'b, 'b, A: flatbuffers::Allocator + 'a> AccountBuilder<'a, 'b, A> { + #[inline] + pub fn add_public_id(&mut self, public_id: flatbuffers::WIPOffset>) { + self.fbb_.push_slot_always::>(Account::VT_PUBLIC_ID, public_id); + } + #[inline] + pub fn add_profile(&mut self, profile: flatbuffers::WIPOffset>) { + self.fbb_.push_slot_always::>(Account::VT_PROFILE, profile); + } + #[inline] + pub fn add_activity(&mut self, activity: flatbuffers::WIPOffset>) { + self.fbb_.push_slot_always::>(Account::VT_ACTIVITY, activity); + } + #[inline] + pub fn new(_fbb: &'b mut flatbuffers::FlatBufferBuilder<'a, A>) -> AccountBuilder<'a, 'b, A> { + let start = _fbb.start_table(); + AccountBuilder { + fbb_: _fbb, + start_: start, + } + } + #[inline] + pub fn finish(self) -> flatbuffers::WIPOffset> { + let o = self.fbb_.end_table(self.start_); + flatbuffers::WIPOffset::new(o.value()) + } +} + +impl core::fmt::Debug for Account<'_> { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + let mut ds = f.debug_struct("Account"); + ds.field("public_id", &self.public_id()); + ds.field("profile", &self.profile()); + ds.field("activity", &self.activity()); + ds.finish() + } +} +pub enum StreamOffset {} +#[derive(Copy, Clone, PartialEq)] + +pub struct Stream<'a> { + pub _tab: flatbuffers::Table<'a>, +} + +impl<'a> flatbuffers::Follow<'a> for Stream<'a> { + type Inner = Stream<'a>; + #[inline] + unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { + Self { _tab: flatbuffers::Table::new(buf, loc) } + } +} + +impl<'a> Stream<'a> { + pub const VT_PUBLIC_ID: flatbuffers::VOffsetT = 4; + pub const VT_PROFILE: flatbuffers::VOffsetT = 6; + pub const VT_ACTIVITY: flatbuffers::VOffsetT = 8; + pub const VT_CREATOR_PUBLIC_ID: flatbuffers::VOffsetT = 10; + pub const VT_MEMBERS_PUBLIC_ID: flatbuffers::VOffsetT = 12; + pub const VT_STREAM_LEVEL: flatbuffers::VOffsetT = 14; + + #[inline] + pub unsafe fn init_from_table(table: flatbuffers::Table<'a>) -> Self { + Stream { _tab: table } + } + #[allow(unused_mut)] + pub fn create<'bldr: 'args, 'args: 'mut_bldr, 'mut_bldr, A: flatbuffers::Allocator + 'bldr>( + _fbb: &'mut_bldr mut flatbuffers::FlatBufferBuilder<'bldr, A>, + args: &'args StreamArgs<'args> + ) -> flatbuffers::WIPOffset> { + let mut builder = StreamBuilder::new(_fbb); + if let Some(x) = args.members_public_id { builder.add_members_public_id(x); } + if let Some(x) = args.creator_public_id { builder.add_creator_public_id(x); } + if let Some(x) = args.activity { builder.add_activity(x); } + if let Some(x) = args.profile { builder.add_profile(x); } + if let Some(x) = args.public_id { builder.add_public_id(x); } + builder.add_stream_level(args.stream_level); + builder.finish() + } + + + #[inline] + pub fn public_id(&self) -> Option> { + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { self._tab.get::>(Stream::VT_PUBLIC_ID, None)} + } + #[inline] + pub fn profile(&self) -> Option> { + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { self._tab.get::>(Stream::VT_PROFILE, None)} + } + #[inline] + pub fn activity(&self) -> Option> { + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { self._tab.get::>(Stream::VT_ACTIVITY, None)} + } + #[inline] + pub fn creator_public_id(&self) -> Option> { + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { self._tab.get::>(Stream::VT_CREATOR_PUBLIC_ID, None)} + } + #[inline] + pub fn members_public_id(&self) -> Option>>> { + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { self._tab.get::>>>(Stream::VT_MEMBERS_PUBLIC_ID, None)} + } + #[inline] + pub fn stream_level(&self) -> StreamLevel { + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { self._tab.get::(Stream::VT_STREAM_LEVEL, Some(StreamLevel::unused)).unwrap()} + } +} + +impl flatbuffers::Verifiable for Stream<'_> { + #[inline] + fn run_verifier( + v: &mut flatbuffers::Verifier, pos: usize + ) -> Result<(), flatbuffers::InvalidFlatbuffer> { + use self::flatbuffers::Verifiable; + v.visit_table(pos)? + .visit_field::>("public_id", Self::VT_PUBLIC_ID, false)? + .visit_field::>("profile", Self::VT_PROFILE, false)? + .visit_field::>("activity", Self::VT_ACTIVITY, false)? + .visit_field::>("creator_public_id", Self::VT_CREATOR_PUBLIC_ID, false)? + .visit_field::>>>("members_public_id", Self::VT_MEMBERS_PUBLIC_ID, false)? + .visit_field::("stream_level", Self::VT_STREAM_LEVEL, false)? + .finish(); + Ok(()) + } +} +pub struct StreamArgs<'a> { + pub public_id: Option>>, + pub profile: Option>>, + pub activity: Option>>, + pub creator_public_id: Option>>, + pub members_public_id: Option>>>>, + pub stream_level: StreamLevel, +} +impl<'a> Default for StreamArgs<'a> { + #[inline] + fn default() -> Self { + StreamArgs { + public_id: None, + profile: None, + activity: None, + creator_public_id: None, + members_public_id: None, + stream_level: StreamLevel::unused, + } + } +} + +pub struct StreamBuilder<'a: 'b, 'b, A: flatbuffers::Allocator + 'a> { + fbb_: &'b mut flatbuffers::FlatBufferBuilder<'a, A>, + start_: flatbuffers::WIPOffset, +} +impl<'a: 'b, 'b, A: flatbuffers::Allocator + 'a> StreamBuilder<'a, 'b, A> { + #[inline] + pub fn add_public_id(&mut self, public_id: flatbuffers::WIPOffset>) { + self.fbb_.push_slot_always::>(Stream::VT_PUBLIC_ID, public_id); + } + #[inline] + pub fn add_profile(&mut self, profile: flatbuffers::WIPOffset>) { + self.fbb_.push_slot_always::>(Stream::VT_PROFILE, profile); + } + #[inline] + pub fn add_activity(&mut self, activity: flatbuffers::WIPOffset>) { + self.fbb_.push_slot_always::>(Stream::VT_ACTIVITY, activity); + } + #[inline] + pub fn add_creator_public_id(&mut self, creator_public_id: flatbuffers::WIPOffset>) { + self.fbb_.push_slot_always::>(Stream::VT_CREATOR_PUBLIC_ID, creator_public_id); + } + #[inline] + pub fn add_members_public_id(&mut self, members_public_id: flatbuffers::WIPOffset>>>) { + self.fbb_.push_slot_always::>(Stream::VT_MEMBERS_PUBLIC_ID, members_public_id); + } + #[inline] + pub fn add_stream_level(&mut self, stream_level: StreamLevel) { + self.fbb_.push_slot::(Stream::VT_STREAM_LEVEL, stream_level, StreamLevel::unused); + } + #[inline] + pub fn new(_fbb: &'b mut flatbuffers::FlatBufferBuilder<'a, A>) -> StreamBuilder<'a, 'b, A> { + let start = _fbb.start_table(); + StreamBuilder { + fbb_: _fbb, + start_: start, + } + } + #[inline] + pub fn finish(self) -> flatbuffers::WIPOffset> { + let o = self.fbb_.end_table(self.start_); + flatbuffers::WIPOffset::new(o.value()) + } +} + +impl core::fmt::Debug for Stream<'_> { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + let mut ds = f.debug_struct("Stream"); + ds.field("public_id", &self.public_id()); + ds.field("profile", &self.profile()); + ds.field("activity", &self.activity()); + ds.field("creator_public_id", &self.creator_public_id()); + ds.field("members_public_id", &self.members_public_id()); + ds.field("stream_level", &self.stream_level()); + ds.finish() + } +} +pub enum ThoughtOffset {} +#[derive(Copy, Clone, PartialEq)] + +pub struct Thought<'a> { + pub _tab: flatbuffers::Table<'a>, +} + +impl<'a> flatbuffers::Follow<'a> for Thought<'a> { + type Inner = Thought<'a>; + #[inline] + unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { + Self { _tab: flatbuffers::Table::new(buf, loc) } + } +} + +impl<'a> Thought<'a> { + pub const VT_PUBLIC_ID: flatbuffers::VOffsetT = 4; + pub const VT_CREATOR_PUBLIC_ID: flatbuffers::VOffsetT = 6; + pub const VT_STREAM_PUBLIC_ID: flatbuffers::VOffsetT = 8; + pub const VT_CONTENT: flatbuffers::VOffsetT = 10; + pub const VT_MEDIA_TYPE: flatbuffers::VOffsetT = 12; + + #[inline] + pub unsafe fn init_from_table(table: flatbuffers::Table<'a>) -> Self { + Thought { _tab: table } + } + #[allow(unused_mut)] + pub fn create<'bldr: 'args, 'args: 'mut_bldr, 'mut_bldr, A: flatbuffers::Allocator + 'bldr>( + _fbb: &'mut_bldr mut flatbuffers::FlatBufferBuilder<'bldr, A>, + args: &'args ThoughtArgs<'args> + ) -> flatbuffers::WIPOffset> { + let mut builder = ThoughtBuilder::new(_fbb); + if let Some(x) = args.content { builder.add_content(x); } + if let Some(x) = args.stream_public_id { builder.add_stream_public_id(x); } + if let Some(x) = args.creator_public_id { builder.add_creator_public_id(x); } + if let Some(x) = args.public_id { builder.add_public_id(x); } + builder.add_media_type(args.media_type); + builder.finish() + } + + + #[inline] + pub fn public_id(&self) -> Option> { + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { self._tab.get::>(Thought::VT_PUBLIC_ID, None)} + } + #[inline] + pub fn creator_public_id(&self) -> Option> { + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { self._tab.get::>(Thought::VT_CREATOR_PUBLIC_ID, None)} + } + #[inline] + pub fn stream_public_id(&self) -> Option> { + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { self._tab.get::>(Thought::VT_STREAM_PUBLIC_ID, None)} + } + #[inline] + pub fn content(&self) -> Option> { + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { self._tab.get::>>(Thought::VT_CONTENT, None)} + } + #[inline] + pub fn media_type(&self) -> MediaType { + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { self._tab.get::(Thought::VT_MEDIA_TYPE, Some(MediaType::unused)).unwrap()} + } +} + +impl flatbuffers::Verifiable for Thought<'_> { + #[inline] + fn run_verifier( + v: &mut flatbuffers::Verifier, pos: usize + ) -> Result<(), flatbuffers::InvalidFlatbuffer> { + use self::flatbuffers::Verifiable; + v.visit_table(pos)? + .visit_field::>("public_id", Self::VT_PUBLIC_ID, false)? + .visit_field::>("creator_public_id", Self::VT_CREATOR_PUBLIC_ID, false)? + .visit_field::>("stream_public_id", Self::VT_STREAM_PUBLIC_ID, false)? + .visit_field::>>("content", Self::VT_CONTENT, false)? + .visit_field::("media_type", Self::VT_MEDIA_TYPE, false)? + .finish(); + Ok(()) + } +} +pub struct ThoughtArgs<'a> { + pub public_id: Option>>, + pub creator_public_id: Option>>, + pub stream_public_id: Option>>, + pub content: Option>>, + pub media_type: MediaType, +} +impl<'a> Default for ThoughtArgs<'a> { + #[inline] + fn default() -> Self { + ThoughtArgs { + public_id: None, + creator_public_id: None, + stream_public_id: None, + content: None, + media_type: MediaType::unused, + } + } +} + +pub struct ThoughtBuilder<'a: 'b, 'b, A: flatbuffers::Allocator + 'a> { + fbb_: &'b mut flatbuffers::FlatBufferBuilder<'a, A>, + start_: flatbuffers::WIPOffset, +} +impl<'a: 'b, 'b, A: flatbuffers::Allocator + 'a> ThoughtBuilder<'a, 'b, A> { + #[inline] + pub fn add_public_id(&mut self, public_id: flatbuffers::WIPOffset>) { + self.fbb_.push_slot_always::>(Thought::VT_PUBLIC_ID, public_id); + } + #[inline] + pub fn add_creator_public_id(&mut self, creator_public_id: flatbuffers::WIPOffset>) { + self.fbb_.push_slot_always::>(Thought::VT_CREATOR_PUBLIC_ID, creator_public_id); + } + #[inline] + pub fn add_stream_public_id(&mut self, stream_public_id: flatbuffers::WIPOffset>) { + self.fbb_.push_slot_always::>(Thought::VT_STREAM_PUBLIC_ID, stream_public_id); + } + #[inline] + pub fn add_content(&mut self, content: flatbuffers::WIPOffset>) { + self.fbb_.push_slot_always::>(Thought::VT_CONTENT, content); + } + #[inline] + pub fn add_media_type(&mut self, media_type: MediaType) { + self.fbb_.push_slot::(Thought::VT_MEDIA_TYPE, media_type, MediaType::unused); + } + #[inline] + pub fn new(_fbb: &'b mut flatbuffers::FlatBufferBuilder<'a, A>) -> ThoughtBuilder<'a, 'b, A> { + let start = _fbb.start_table(); + ThoughtBuilder { + fbb_: _fbb, + start_: start, + } + } + #[inline] + pub fn finish(self) -> flatbuffers::WIPOffset> { + let o = self.fbb_.end_table(self.start_); + flatbuffers::WIPOffset::new(o.value()) + } +} + +impl core::fmt::Debug for Thought<'_> { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + let mut ds = f.debug_struct("Thought"); + ds.field("public_id", &self.public_id()); + ds.field("creator_public_id", &self.creator_public_id()); + ds.field("stream_public_id", &self.stream_public_id()); + ds.field("content", &self.content()); + ds.field("media_type", &self.media_type()); + ds.finish() + } +} +pub enum ProfileOffset {} +#[derive(Copy, Clone, PartialEq)] + +pub struct Profile<'a> { + pub _tab: flatbuffers::Table<'a>, +} + +impl<'a> flatbuffers::Follow<'a> for Profile<'a> { + type Inner = Profile<'a>; + #[inline] + unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { + Self { _tab: flatbuffers::Table::new(buf, loc) } + } +} + +impl<'a> Profile<'a> { + pub const VT_NAME: flatbuffers::VOffsetT = 4; + pub const VT_BLURB: flatbuffers::VOffsetT = 6; + pub const VT_INTERESTS: flatbuffers::VOffsetT = 8; + pub const VT_LOCATION: flatbuffers::VOffsetT = 10; + pub const VT_LOCATION_LEVEL: flatbuffers::VOffsetT = 12; + pub const VT_IDENTITY_ASSURANCE_LEVEL: flatbuffers::VOffsetT = 14; + pub const VT_ENCRYPTION_LEVEL: flatbuffers::VOffsetT = 16; + + #[inline] + pub unsafe fn init_from_table(table: flatbuffers::Table<'a>) -> Self { + Profile { _tab: table } + } + #[allow(unused_mut)] + pub fn create<'bldr: 'args, 'args: 'mut_bldr, 'mut_bldr, A: flatbuffers::Allocator + 'bldr>( + _fbb: &'mut_bldr mut flatbuffers::FlatBufferBuilder<'bldr, A>, + args: &'args ProfileArgs<'args> + ) -> flatbuffers::WIPOffset> { + let mut builder = ProfileBuilder::new(_fbb); + if let Some(x) = args.location { builder.add_location(x); } + if let Some(x) = args.interests { builder.add_interests(x); } + if let Some(x) = args.blurb { builder.add_blurb(x); } + if let Some(x) = args.name { builder.add_name(x); } + builder.add_encryption_level(args.encryption_level); + builder.add_identity_assurance_level(args.identity_assurance_level); + builder.add_location_level(args.location_level); + builder.finish() + } + + + #[inline] + pub fn name(&self) -> Option<&'a str> { + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { self._tab.get::>(Profile::VT_NAME, None)} + } + #[inline] + pub fn blurb(&self) -> Option<&'a str> { + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { self._tab.get::>(Profile::VT_BLURB, None)} + } + #[inline] + pub fn interests(&self) -> Option<&'a str> { + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { self._tab.get::>(Profile::VT_INTERESTS, None)} + } + #[inline] + pub fn location(&self) -> Option<&'a str> { + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { self._tab.get::>(Profile::VT_LOCATION, None)} + } + #[inline] + pub fn location_level(&self) -> LocationLevel { + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { self._tab.get::(Profile::VT_LOCATION_LEVEL, Some(LocationLevel::unused)).unwrap()} + } + #[inline] + pub fn identity_assurance_level(&self) -> IdentityAssuranceLevel { + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { self._tab.get::(Profile::VT_IDENTITY_ASSURANCE_LEVEL, Some(IdentityAssuranceLevel::unused)).unwrap()} + } + #[inline] + pub fn encryption_level(&self) -> EncryptionLevel { + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { self._tab.get::(Profile::VT_ENCRYPTION_LEVEL, Some(EncryptionLevel::unused)).unwrap()} + } +} + +impl flatbuffers::Verifiable for Profile<'_> { + #[inline] + fn run_verifier( + v: &mut flatbuffers::Verifier, pos: usize + ) -> Result<(), flatbuffers::InvalidFlatbuffer> { + use self::flatbuffers::Verifiable; + v.visit_table(pos)? + .visit_field::>("name", Self::VT_NAME, false)? + .visit_field::>("blurb", Self::VT_BLURB, false)? + .visit_field::>("interests", Self::VT_INTERESTS, false)? + .visit_field::>("location", Self::VT_LOCATION, false)? + .visit_field::("location_level", Self::VT_LOCATION_LEVEL, false)? + .visit_field::("identity_assurance_level", Self::VT_IDENTITY_ASSURANCE_LEVEL, false)? + .visit_field::("encryption_level", Self::VT_ENCRYPTION_LEVEL, false)? + .finish(); + Ok(()) + } +} +pub struct ProfileArgs<'a> { + pub name: Option>, + pub blurb: Option>, + pub interests: Option>, + pub location: Option>, + pub location_level: LocationLevel, + pub identity_assurance_level: IdentityAssuranceLevel, + pub encryption_level: EncryptionLevel, +} +impl<'a> Default for ProfileArgs<'a> { + #[inline] + fn default() -> Self { + ProfileArgs { + name: None, + blurb: None, + interests: None, + location: None, + location_level: LocationLevel::unused, + identity_assurance_level: IdentityAssuranceLevel::unused, + encryption_level: EncryptionLevel::unused, + } + } +} + +pub struct ProfileBuilder<'a: 'b, 'b, A: flatbuffers::Allocator + 'a> { + fbb_: &'b mut flatbuffers::FlatBufferBuilder<'a, A>, + start_: flatbuffers::WIPOffset, +} +impl<'a: 'b, 'b, A: flatbuffers::Allocator + 'a> ProfileBuilder<'a, 'b, A> { + #[inline] + pub fn add_name(&mut self, name: flatbuffers::WIPOffset<&'b str>) { + self.fbb_.push_slot_always::>(Profile::VT_NAME, name); + } + #[inline] + pub fn add_blurb(&mut self, blurb: flatbuffers::WIPOffset<&'b str>) { + self.fbb_.push_slot_always::>(Profile::VT_BLURB, blurb); + } + #[inline] + pub fn add_interests(&mut self, interests: flatbuffers::WIPOffset<&'b str>) { + self.fbb_.push_slot_always::>(Profile::VT_INTERESTS, interests); + } + #[inline] + pub fn add_location(&mut self, location: flatbuffers::WIPOffset<&'b str>) { + self.fbb_.push_slot_always::>(Profile::VT_LOCATION, location); + } + #[inline] + pub fn add_location_level(&mut self, location_level: LocationLevel) { + self.fbb_.push_slot::(Profile::VT_LOCATION_LEVEL, location_level, LocationLevel::unused); + } + #[inline] + pub fn add_identity_assurance_level(&mut self, identity_assurance_level: IdentityAssuranceLevel) { + self.fbb_.push_slot::(Profile::VT_IDENTITY_ASSURANCE_LEVEL, identity_assurance_level, IdentityAssuranceLevel::unused); + } + #[inline] + pub fn add_encryption_level(&mut self, encryption_level: EncryptionLevel) { + self.fbb_.push_slot::(Profile::VT_ENCRYPTION_LEVEL, encryption_level, EncryptionLevel::unused); + } + #[inline] + pub fn new(_fbb: &'b mut flatbuffers::FlatBufferBuilder<'a, A>) -> ProfileBuilder<'a, 'b, A> { + let start = _fbb.start_table(); + ProfileBuilder { + fbb_: _fbb, + start_: start, + } + } + #[inline] + pub fn finish(self) -> flatbuffers::WIPOffset> { + let o = self.fbb_.end_table(self.start_); + flatbuffers::WIPOffset::new(o.value()) + } +} + +impl core::fmt::Debug for Profile<'_> { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + let mut ds = f.debug_struct("Profile"); + ds.field("name", &self.name()); + ds.field("blurb", &self.blurb()); + ds.field("interests", &self.interests()); + ds.field("location", &self.location()); + ds.field("location_level", &self.location_level()); + ds.field("identity_assurance_level", &self.identity_assurance_level()); + ds.field("encryption_level", &self.encryption_level()); + ds.finish() + } +} +pub enum ActivityOffset {} +#[derive(Copy, Clone, PartialEq)] + +pub struct Activity<'a> { + pub _tab: flatbuffers::Table<'a>, +} + +impl<'a> flatbuffers::Follow<'a> for Activity<'a> { + type Inner = Activity<'a>; + #[inline] + unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { + Self { _tab: flatbuffers::Table::new(buf, loc) } + } +} + +impl<'a> Activity<'a> { + pub const VT_DATE_CREATED: flatbuffers::VOffsetT = 4; + pub const VT_EXPERT_LEVEL: flatbuffers::VOffsetT = 6; + pub const VT_ACTIVITY_LEVEL: flatbuffers::VOffsetT = 8; + pub const VT_TRUST_LEVEL: flatbuffers::VOffsetT = 10; + + #[inline] + pub unsafe fn init_from_table(table: flatbuffers::Table<'a>) -> Self { + Activity { _tab: table } + } + #[allow(unused_mut)] + pub fn create<'bldr: 'args, 'args: 'mut_bldr, 'mut_bldr, A: flatbuffers::Allocator + 'bldr>( + _fbb: &'mut_bldr mut flatbuffers::FlatBufferBuilder<'bldr, A>, + args: &'args ActivityArgs + ) -> flatbuffers::WIPOffset> { + let mut builder = ActivityBuilder::new(_fbb); + builder.add_date_created(args.date_created); + builder.add_trust_level(args.trust_level); + builder.add_activity_level(args.activity_level); + builder.add_expert_level(args.expert_level); + builder.finish() + } + + + #[inline] + pub fn date_created(&self) -> i64 { + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { self._tab.get::(Activity::VT_DATE_CREATED, Some(0)).unwrap()} + } + #[inline] + pub fn expert_level(&self) -> ExpertLevel { + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { self._tab.get::(Activity::VT_EXPERT_LEVEL, Some(ExpertLevel::unused)).unwrap()} + } + #[inline] + pub fn activity_level(&self) -> ActivityLevel { + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { self._tab.get::(Activity::VT_ACTIVITY_LEVEL, Some(ActivityLevel::unused)).unwrap()} + } + #[inline] + pub fn trust_level(&self) -> TrustLevel { + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { self._tab.get::(Activity::VT_TRUST_LEVEL, Some(TrustLevel::unused)).unwrap()} + } +} + +impl flatbuffers::Verifiable for Activity<'_> { + #[inline] + fn run_verifier( + v: &mut flatbuffers::Verifier, pos: usize + ) -> Result<(), flatbuffers::InvalidFlatbuffer> { + use self::flatbuffers::Verifiable; + v.visit_table(pos)? + .visit_field::("date_created", Self::VT_DATE_CREATED, false)? + .visit_field::("expert_level", Self::VT_EXPERT_LEVEL, false)? + .visit_field::("activity_level", Self::VT_ACTIVITY_LEVEL, false)? + .visit_field::("trust_level", Self::VT_TRUST_LEVEL, false)? + .finish(); + Ok(()) + } +} +pub struct ActivityArgs { + pub date_created: i64, + pub expert_level: ExpertLevel, + pub activity_level: ActivityLevel, + pub trust_level: TrustLevel, +} +impl<'a> Default for ActivityArgs { + #[inline] + fn default() -> Self { + ActivityArgs { + date_created: 0, + expert_level: ExpertLevel::unused, + activity_level: ActivityLevel::unused, + trust_level: TrustLevel::unused, + } + } +} + +pub struct ActivityBuilder<'a: 'b, 'b, A: flatbuffers::Allocator + 'a> { + fbb_: &'b mut flatbuffers::FlatBufferBuilder<'a, A>, + start_: flatbuffers::WIPOffset, +} +impl<'a: 'b, 'b, A: flatbuffers::Allocator + 'a> ActivityBuilder<'a, 'b, A> { + #[inline] + pub fn add_date_created(&mut self, date_created: i64) { + self.fbb_.push_slot::(Activity::VT_DATE_CREATED, date_created, 0); + } + #[inline] + pub fn add_expert_level(&mut self, expert_level: ExpertLevel) { + self.fbb_.push_slot::(Activity::VT_EXPERT_LEVEL, expert_level, ExpertLevel::unused); + } + #[inline] + pub fn add_activity_level(&mut self, activity_level: ActivityLevel) { + self.fbb_.push_slot::(Activity::VT_ACTIVITY_LEVEL, activity_level, ActivityLevel::unused); + } + #[inline] + pub fn add_trust_level(&mut self, trust_level: TrustLevel) { + self.fbb_.push_slot::(Activity::VT_TRUST_LEVEL, trust_level, TrustLevel::unused); + } + #[inline] + pub fn new(_fbb: &'b mut flatbuffers::FlatBufferBuilder<'a, A>) -> ActivityBuilder<'a, 'b, A> { + let start = _fbb.start_table(); + ActivityBuilder { + fbb_: _fbb, + start_: start, + } + } + #[inline] + pub fn finish(self) -> flatbuffers::WIPOffset> { + let o = self.fbb_.end_table(self.start_); + flatbuffers::WIPOffset::new(o.value()) + } +} + +impl core::fmt::Debug for Activity<'_> { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + let mut ds = f.debug_struct("Activity"); + ds.field("date_created", &self.date_created()); + ds.field("expert_level", &self.expert_level()); + ds.field("activity_level", &self.activity_level()); + ds.field("trust_level", &self.trust_level()); + ds.finish() + } +} +pub enum EntityRootOffset {} +#[derive(Copy, Clone, PartialEq)] + +pub struct EntityRoot<'a> { + pub _tab: flatbuffers::Table<'a>, +} + +impl<'a> flatbuffers::Follow<'a> for EntityRoot<'a> { + type Inner = EntityRoot<'a>; + #[inline] + unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { + Self { _tab: flatbuffers::Table::new(buf, loc) } + } +} + +impl<'a> EntityRoot<'a> { + pub const VT_ENTITY_TYPE: flatbuffers::VOffsetT = 4; + pub const VT_ENTITY: flatbuffers::VOffsetT = 6; + + #[inline] + pub unsafe fn init_from_table(table: flatbuffers::Table<'a>) -> Self { + EntityRoot { _tab: table } + } + #[allow(unused_mut)] + pub fn create<'bldr: 'args, 'args: 'mut_bldr, 'mut_bldr, A: flatbuffers::Allocator + 'bldr>( + _fbb: &'mut_bldr mut flatbuffers::FlatBufferBuilder<'bldr, A>, + args: &'args EntityRootArgs + ) -> flatbuffers::WIPOffset> { + let mut builder = EntityRootBuilder::new(_fbb); + if let Some(x) = args.entity { builder.add_entity(x); } + builder.add_entity_type(args.entity_type); + builder.finish() + } + + + #[inline] + pub fn entity_type(&self) -> Entity { + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { self._tab.get::(EntityRoot::VT_ENTITY_TYPE, Some(Entity::NONE)).unwrap()} + } + #[inline] + pub fn entity(&self) -> Option> { + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { self._tab.get::>>(EntityRoot::VT_ENTITY, None)} + } + #[inline] + #[allow(non_snake_case)] + pub fn entity_as_account(&self) -> Option> { + if self.entity_type() == Entity::Account { + self.entity().map(|t| { + // Safety: + // Created from a valid Table for this object + // Which contains a valid union in this slot + unsafe { Account::init_from_table(t) } + }) + } else { + None + } + } + + #[inline] + #[allow(non_snake_case)] + pub fn entity_as_stream(&self) -> Option> { + if self.entity_type() == Entity::Stream { + self.entity().map(|t| { + // Safety: + // Created from a valid Table for this object + // Which contains a valid union in this slot + unsafe { Stream::init_from_table(t) } + }) + } else { + None + } + } + + #[inline] + #[allow(non_snake_case)] + pub fn entity_as_thought(&self) -> Option> { + if self.entity_type() == Entity::Thought { + self.entity().map(|t| { + // Safety: + // Created from a valid Table for this object + // Which contains a valid union in this slot + unsafe { Thought::init_from_table(t) } + }) + } else { + None + } + } + +} + +impl flatbuffers::Verifiable for EntityRoot<'_> { + #[inline] + fn run_verifier( + v: &mut flatbuffers::Verifier, pos: usize + ) -> Result<(), flatbuffers::InvalidFlatbuffer> { + use self::flatbuffers::Verifiable; + v.visit_table(pos)? + .visit_union::("entity_type", Self::VT_ENTITY_TYPE, "entity", Self::VT_ENTITY, false, |key, v, pos| { + match key { + Entity::Account => v.verify_union_variant::>("Entity::Account", pos), + Entity::Stream => v.verify_union_variant::>("Entity::Stream", pos), + Entity::Thought => v.verify_union_variant::>("Entity::Thought", pos), + _ => Ok(()), + } + })? + .finish(); + Ok(()) + } +} +pub struct EntityRootArgs { + pub entity_type: Entity, + pub entity: Option>, +} +impl<'a> Default for EntityRootArgs { + #[inline] + fn default() -> Self { + EntityRootArgs { + entity_type: Entity::NONE, + entity: None, + } + } +} + +pub struct EntityRootBuilder<'a: 'b, 'b, A: flatbuffers::Allocator + 'a> { + fbb_: &'b mut flatbuffers::FlatBufferBuilder<'a, A>, + start_: flatbuffers::WIPOffset, +} +impl<'a: 'b, 'b, A: flatbuffers::Allocator + 'a> EntityRootBuilder<'a, 'b, A> { + #[inline] + pub fn add_entity_type(&mut self, entity_type: Entity) { + self.fbb_.push_slot::(EntityRoot::VT_ENTITY_TYPE, entity_type, Entity::NONE); + } + #[inline] + pub fn add_entity(&mut self, entity: flatbuffers::WIPOffset) { + self.fbb_.push_slot_always::>(EntityRoot::VT_ENTITY, entity); + } + #[inline] + pub fn new(_fbb: &'b mut flatbuffers::FlatBufferBuilder<'a, A>) -> EntityRootBuilder<'a, 'b, A> { + let start = _fbb.start_table(); + EntityRootBuilder { + fbb_: _fbb, + start_: start, + } + } + #[inline] + pub fn finish(self) -> flatbuffers::WIPOffset> { + let o = self.fbb_.end_table(self.start_); + flatbuffers::WIPOffset::new(o.value()) + } +} + +impl core::fmt::Debug for EntityRoot<'_> { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + let mut ds = f.debug_struct("EntityRoot"); + ds.field("entity_type", &self.entity_type()); + match self.entity_type() { + Entity::Account => { + if let Some(x) = self.entity_as_account() { + ds.field("entity", &x) + } else { + ds.field("entity", &"InvalidFlatbuffer: Union discriminant does not match value.") + } + }, + Entity::Stream => { + if let Some(x) = self.entity_as_stream() { + ds.field("entity", &x) + } else { + ds.field("entity", &"InvalidFlatbuffer: Union discriminant does not match value.") + } + }, + Entity::Thought => { + if let Some(x) = self.entity_as_thought() { + ds.field("entity", &x) + } else { + ds.field("entity", &"InvalidFlatbuffer: Union discriminant does not match value.") + } + }, + _ => { + let x: Option<()> = None; + ds.field("entity", &x) + }, + }; + ds.finish() + } +} +#[inline] +/// Verifies that a buffer of bytes contains a `EntityRoot` +/// and returns it. +/// Note that verification is still experimental and may not +/// catch every error, or be maximally performant. For the +/// previous, unchecked, behavior use +/// `root_as_entity_root_unchecked`. +pub fn root_as_entity_root(buf: &[u8]) -> Result { + flatbuffers::root::(buf) +} +#[inline] +/// Verifies that a buffer of bytes contains a size prefixed +/// `EntityRoot` and returns it. +/// Note that verification is still experimental and may not +/// catch every error, or be maximally performant. For the +/// previous, unchecked, behavior use +/// `size_prefixed_root_as_entity_root_unchecked`. +pub fn size_prefixed_root_as_entity_root(buf: &[u8]) -> Result { + flatbuffers::size_prefixed_root::(buf) +} +#[inline] +/// Verifies, with the given options, that a buffer of bytes +/// contains a `EntityRoot` and returns it. +/// Note that verification is still experimental and may not +/// catch every error, or be maximally performant. For the +/// previous, unchecked, behavior use +/// `root_as_entity_root_unchecked`. +pub fn root_as_entity_root_with_opts<'b, 'o>( + opts: &'o flatbuffers::VerifierOptions, + buf: &'b [u8], +) -> Result, flatbuffers::InvalidFlatbuffer> { + flatbuffers::root_with_opts::>(opts, buf) +} +#[inline] +/// Verifies, with the given verifier options, that a buffer of +/// bytes contains a size prefixed `EntityRoot` and returns +/// it. Note that verification is still experimental and may not +/// catch every error, or be maximally performant. For the +/// previous, unchecked, behavior use +/// `root_as_entity_root_unchecked`. +pub fn size_prefixed_root_as_entity_root_with_opts<'b, 'o>( + opts: &'o flatbuffers::VerifierOptions, + buf: &'b [u8], +) -> Result, flatbuffers::InvalidFlatbuffer> { + flatbuffers::size_prefixed_root_with_opts::>(opts, buf) +} +#[inline] +/// Assumes, without verification, that a buffer of bytes contains a EntityRoot and returns it. +/// # Safety +/// Callers must trust the given bytes do indeed contain a valid `EntityRoot`. +pub unsafe fn root_as_entity_root_unchecked(buf: &[u8]) -> EntityRoot { + flatbuffers::root_unchecked::(buf) +} +#[inline] +/// Assumes, without verification, that a buffer of bytes contains a size prefixed EntityRoot and returns it. +/// # Safety +/// Callers must trust the given bytes do indeed contain a valid size prefixed `EntityRoot`. +pub unsafe fn size_prefixed_root_as_entity_root_unchecked(buf: &[u8]) -> EntityRoot { + flatbuffers::size_prefixed_root_unchecked::(buf) +} +#[inline] +pub fn finish_entity_root_buffer<'a, 'b, A: flatbuffers::Allocator + 'a>( + fbb: &'b mut flatbuffers::FlatBufferBuilder<'a, A>, + root: flatbuffers::WIPOffset>) { + fbb.finish(root, None); +} + +#[inline] +pub fn finish_size_prefixed_entity_root_buffer<'a, 'b, A: flatbuffers::Allocator + 'a>(fbb: &'b mut flatbuffers::FlatBufferBuilder<'a, A>, root: flatbuffers::WIPOffset>) { + fbb.finish_size_prefixed(root, None); +} +} // pub mod Arkavo + diff --git a/src/bin/schemas/metadata_generated.rs b/src/bin/schemas/metadata_generated.rs new file mode 100644 index 0000000..1309100 --- /dev/null +++ b/src/bin/schemas/metadata_generated.rs @@ -0,0 +1,1571 @@ +// automatically generated by the FlatBuffers compiler, do not modify +#![allow(clippy::extra_unused_lifetimes)] +// @generated + +extern crate flatbuffers; + +#[allow(unused_imports, dead_code)] +pub mod arkavo { + + use core::mem; + use core::cmp::Ordering; + use crate::schemas::entity_generated::arkavo::MediaType; + + extern crate flatbuffers; + use self::flatbuffers::{EndianScalar, Follow}; + +#[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")] +pub const ENUM_MIN_RATING_LEVEL: i8 = 0; +#[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")] +pub const ENUM_MAX_RATING_LEVEL: i8 = 4; +#[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")] +#[allow(non_camel_case_types)] +pub const ENUM_VALUES_RATING_LEVEL: [RatingLevel; 5] = [ + RatingLevel::unused, + RatingLevel::none, + RatingLevel::mild, + RatingLevel::moderate, + RatingLevel::severe, +]; + +#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Default)] +#[repr(transparent)] +pub struct RatingLevel(pub i8); +#[allow(non_upper_case_globals)] +impl RatingLevel { + pub const unused: Self = Self(0); + pub const none: Self = Self(1); + pub const mild: Self = Self(2); + pub const moderate: Self = Self(3); + pub const severe: Self = Self(4); + + pub const ENUM_MIN: i8 = 0; + pub const ENUM_MAX: i8 = 4; + pub const ENUM_VALUES: &'static [Self] = &[ + Self::unused, + Self::none, + Self::mild, + Self::moderate, + Self::severe, + ]; + /// Returns the variant's name or "" if unknown. + pub fn variant_name(self) -> Option<&'static str> { + match self { + Self::unused => Some("unused"), + Self::none => Some("none"), + Self::mild => Some("mild"), + Self::moderate => Some("moderate"), + Self::severe => Some("severe"), + _ => None, + } + } +} +impl core::fmt::Debug for RatingLevel { + fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result { + if let Some(name) = self.variant_name() { + f.write_str(name) + } else { + f.write_fmt(format_args!("", self.0)) + } + } +} +impl<'a> flatbuffers::Follow<'a> for RatingLevel { + type Inner = Self; + #[inline] + unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { + let b = flatbuffers::read_scalar_at::(buf, loc); + Self(b) + } +} + +impl flatbuffers::Push for RatingLevel { + type Output = RatingLevel; + #[inline] + unsafe fn push(&self, dst: &mut [u8], _written_len: usize) { + flatbuffers::emplace_scalar::(dst, self.0); + } +} + +impl flatbuffers::EndianScalar for RatingLevel { + type Scalar = i8; + #[inline] + fn to_little_endian(self) -> i8 { + self.0.to_le() + } + #[inline] + #[allow(clippy::wrong_self_convention)] + fn from_little_endian(v: i8) -> Self { + let b = i8::from_le(v); + Self(b) + } +} + +impl<'a> flatbuffers::Verifiable for RatingLevel { + #[inline] + fn run_verifier( + v: &mut flatbuffers::Verifier, pos: usize + ) -> Result<(), flatbuffers::InvalidFlatbuffer> { + use self::flatbuffers::Verifiable; + i8::run_verifier(v, pos) + } +} + +impl flatbuffers::SimpleToVerifyInSlice for RatingLevel {} +#[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")] +pub const ENUM_MIN_FORMAT_TYPE: i8 = 0; +#[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")] +pub const ENUM_MAX_FORMAT_TYPE: i8 = 30; +#[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")] +#[allow(non_camel_case_types)] +pub const ENUM_VALUES_FORMAT_TYPE: [FormatType; 10] = [ + FormatType::plain, + FormatType::html, + FormatType::csv, + FormatType::xml, + FormatType::json, + FormatType::jpeg, + FormatType::png, + FormatType::svg, + FormatType::gif, + FormatType::pdf, +]; + +#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Default)] +#[repr(transparent)] +pub struct FormatType(pub i8); +#[allow(non_upper_case_globals)] +impl FormatType { + pub const plain: Self = Self(0); + pub const html: Self = Self(1); + pub const csv: Self = Self(2); + pub const xml: Self = Self(3); + pub const json: Self = Self(4); + pub const jpeg: Self = Self(10); + pub const png: Self = Self(11); + pub const svg: Self = Self(12); + pub const gif: Self = Self(13); + pub const pdf: Self = Self(30); + + pub const ENUM_MIN: i8 = 0; + pub const ENUM_MAX: i8 = 30; + pub const ENUM_VALUES: &'static [Self] = &[ + Self::plain, + Self::html, + Self::csv, + Self::xml, + Self::json, + Self::jpeg, + Self::png, + Self::svg, + Self::gif, + Self::pdf, + ]; + /// Returns the variant's name or "" if unknown. + pub fn variant_name(self) -> Option<&'static str> { + match self { + Self::plain => Some("plain"), + Self::html => Some("html"), + Self::csv => Some("csv"), + Self::xml => Some("xml"), + Self::json => Some("json"), + Self::jpeg => Some("jpeg"), + Self::png => Some("png"), + Self::svg => Some("svg"), + Self::gif => Some("gif"), + Self::pdf => Some("pdf"), + _ => None, + } + } +} +impl core::fmt::Debug for FormatType { + fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result { + if let Some(name) = self.variant_name() { + f.write_str(name) + } else { + f.write_fmt(format_args!("", self.0)) + } + } +} +impl<'a> flatbuffers::Follow<'a> for FormatType { + type Inner = Self; + #[inline] + unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { + let b = flatbuffers::read_scalar_at::(buf, loc); + Self(b) + } +} + +impl flatbuffers::Push for FormatType { + type Output = FormatType; + #[inline] + unsafe fn push(&self, dst: &mut [u8], _written_len: usize) { + flatbuffers::emplace_scalar::(dst, self.0); + } +} + +impl flatbuffers::EndianScalar for FormatType { + type Scalar = i8; + #[inline] + fn to_little_endian(self) -> i8 { + self.0.to_le() + } + #[inline] + #[allow(clippy::wrong_self_convention)] + fn from_little_endian(v: i8) -> Self { + let b = i8::from_le(v); + Self(b) + } +} + +impl<'a> flatbuffers::Verifiable for FormatType { + #[inline] + fn run_verifier( + v: &mut flatbuffers::Verifier, pos: usize + ) -> Result<(), flatbuffers::InvalidFlatbuffer> { + use self::flatbuffers::Verifiable; + i8::run_verifier(v, pos) + } +} + +impl flatbuffers::SimpleToVerifyInSlice for FormatType {} +#[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")] +pub const ENUM_MIN_DATA_ENCODING: i8 = 0; +#[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")] +pub const ENUM_MAX_DATA_ENCODING: i8 = 5; +#[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")] +#[allow(non_camel_case_types)] +pub const ENUM_VALUES_DATA_ENCODING: [DataEncoding; 6] = [ + DataEncoding::binary, + DataEncoding::utf8, + DataEncoding::utf16, + DataEncoding::ascii, + DataEncoding::base64, + DataEncoding::quoted_printable, +]; + +#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Default)] +#[repr(transparent)] +pub struct DataEncoding(pub i8); +#[allow(non_upper_case_globals)] +impl DataEncoding { + pub const binary: Self = Self(0); + pub const utf8: Self = Self(1); + pub const utf16: Self = Self(2); + pub const ascii: Self = Self(3); + pub const base64: Self = Self(4); + pub const quoted_printable: Self = Self(5); + + pub const ENUM_MIN: i8 = 0; + pub const ENUM_MAX: i8 = 5; + pub const ENUM_VALUES: &'static [Self] = &[ + Self::binary, + Self::utf8, + Self::utf16, + Self::ascii, + Self::base64, + Self::quoted_printable, + ]; + /// Returns the variant's name or "" if unknown. + pub fn variant_name(self) -> Option<&'static str> { + match self { + Self::binary => Some("binary"), + Self::utf8 => Some("utf8"), + Self::utf16 => Some("utf16"), + Self::ascii => Some("ascii"), + Self::base64 => Some("base64"), + Self::quoted_printable => Some("quoted_printable"), + _ => None, + } + } +} +impl core::fmt::Debug for DataEncoding { + fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result { + if let Some(name) = self.variant_name() { + f.write_str(name) + } else { + f.write_fmt(format_args!("", self.0)) + } + } +} +impl<'a> flatbuffers::Follow<'a> for DataEncoding { + type Inner = Self; + #[inline] + unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { + let b = flatbuffers::read_scalar_at::(buf, loc); + Self(b) + } +} + +impl flatbuffers::Push for DataEncoding { + type Output = DataEncoding; + #[inline] + unsafe fn push(&self, dst: &mut [u8], _written_len: usize) { + flatbuffers::emplace_scalar::(dst, self.0); + } +} + +impl flatbuffers::EndianScalar for DataEncoding { + type Scalar = i8; + #[inline] + fn to_little_endian(self) -> i8 { + self.0.to_le() + } + #[inline] + #[allow(clippy::wrong_self_convention)] + fn from_little_endian(v: i8) -> Self { + let b = i8::from_le(v); + Self(b) + } +} + +impl<'a> flatbuffers::Verifiable for DataEncoding { + #[inline] + fn run_verifier( + v: &mut flatbuffers::Verifier, pos: usize + ) -> Result<(), flatbuffers::InvalidFlatbuffer> { + use self::flatbuffers::Verifiable; + i8::run_verifier(v, pos) + } +} + +impl flatbuffers::SimpleToVerifyInSlice for DataEncoding {} +#[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")] +pub const ENUM_MIN_ARCHIVE_TYPE: i8 = 0; +#[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")] +pub const ENUM_MAX_ARCHIVE_TYPE: i8 = 7; +#[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")] +#[allow(non_camel_case_types)] +pub const ENUM_VALUES_ARCHIVE_TYPE: [ArchiveType; 8] = [ + ArchiveType::none, + ArchiveType::zip, + ArchiveType::tar, + ArchiveType::gzip, + ArchiveType::bzip2, + ArchiveType::xz, + ArchiveType::zstd, + ArchiveType::lz4, +]; + +#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Default)] +#[repr(transparent)] +pub struct ArchiveType(pub i8); +#[allow(non_upper_case_globals)] +impl ArchiveType { + pub const none: Self = Self(0); + pub const zip: Self = Self(1); + pub const tar: Self = Self(2); + pub const gzip: Self = Self(3); + pub const bzip2: Self = Self(4); + pub const xz: Self = Self(5); + pub const zstd: Self = Self(6); + pub const lz4: Self = Self(7); + + pub const ENUM_MIN: i8 = 0; + pub const ENUM_MAX: i8 = 7; + pub const ENUM_VALUES: &'static [Self] = &[ + Self::none, + Self::zip, + Self::tar, + Self::gzip, + Self::bzip2, + Self::xz, + Self::zstd, + Self::lz4, + ]; + /// Returns the variant's name or "" if unknown. + pub fn variant_name(self) -> Option<&'static str> { + match self { + Self::none => Some("none"), + Self::zip => Some("zip"), + Self::tar => Some("tar"), + Self::gzip => Some("gzip"), + Self::bzip2 => Some("bzip2"), + Self::xz => Some("xz"), + Self::zstd => Some("zstd"), + Self::lz4 => Some("lz4"), + _ => None, + } + } +} +impl core::fmt::Debug for ArchiveType { + fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result { + if let Some(name) = self.variant_name() { + f.write_str(name) + } else { + f.write_fmt(format_args!("", self.0)) + } + } +} +impl<'a> flatbuffers::Follow<'a> for ArchiveType { + type Inner = Self; + #[inline] + unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { + let b = flatbuffers::read_scalar_at::(buf, loc); + Self(b) + } +} + +impl flatbuffers::Push for ArchiveType { + type Output = ArchiveType; + #[inline] + unsafe fn push(&self, dst: &mut [u8], _written_len: usize) { + flatbuffers::emplace_scalar::(dst, self.0); + } +} + +impl flatbuffers::EndianScalar for ArchiveType { + type Scalar = i8; + #[inline] + fn to_little_endian(self) -> i8 { + self.0.to_le() + } + #[inline] + #[allow(clippy::wrong_self_convention)] + fn from_little_endian(v: i8) -> Self { + let b = i8::from_le(v); + Self(b) + } +} + +impl<'a> flatbuffers::Verifiable for ArchiveType { + #[inline] + fn run_verifier( + v: &mut flatbuffers::Verifier, pos: usize + ) -> Result<(), flatbuffers::InvalidFlatbuffer> { + use self::flatbuffers::Verifiable; + i8::run_verifier(v, pos) + } +} + +impl flatbuffers::SimpleToVerifyInSlice for ArchiveType {} +pub enum RatingOffset {} +#[derive(Copy, Clone, PartialEq)] + +pub struct Rating<'a> { + pub _tab: flatbuffers::Table<'a>, +} + +impl<'a> flatbuffers::Follow<'a> for Rating<'a> { + type Inner = Rating<'a>; + #[inline] + unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { + Self { _tab: flatbuffers::Table::new(buf, loc) } + } +} + +impl<'a> Rating<'a> { + pub const VT_VIOLENT: flatbuffers::VOffsetT = 4; + pub const VT_SEXUAL: flatbuffers::VOffsetT = 6; + pub const VT_PROFANE: flatbuffers::VOffsetT = 8; + pub const VT_SUBSTANCE: flatbuffers::VOffsetT = 10; + pub const VT_HATE: flatbuffers::VOffsetT = 12; + pub const VT_HARM: flatbuffers::VOffsetT = 14; + pub const VT_MATURE: flatbuffers::VOffsetT = 16; + pub const VT_BULLY: flatbuffers::VOffsetT = 18; + + #[inline] + pub unsafe fn init_from_table(table: flatbuffers::Table<'a>) -> Self { + Rating { _tab: table } + } + #[allow(unused_mut)] + pub fn create<'bldr: 'args, 'args: 'mut_bldr, 'mut_bldr, A: flatbuffers::Allocator + 'bldr>( + _fbb: &'mut_bldr mut flatbuffers::FlatBufferBuilder<'bldr, A>, + args: &'args RatingArgs + ) -> flatbuffers::WIPOffset> { + let mut builder = RatingBuilder::new(_fbb); + builder.add_bully(args.bully); + builder.add_mature(args.mature); + builder.add_harm(args.harm); + builder.add_hate(args.hate); + builder.add_substance(args.substance); + builder.add_profane(args.profane); + builder.add_sexual(args.sexual); + builder.add_violent(args.violent); + builder.finish() + } + + + #[inline] + pub fn violent(&self) -> RatingLevel { + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { self._tab.get::(Rating::VT_VIOLENT, Some(RatingLevel::unused)).unwrap()} + } + #[inline] + pub fn sexual(&self) -> RatingLevel { + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { self._tab.get::(Rating::VT_SEXUAL, Some(RatingLevel::unused)).unwrap()} + } + #[inline] + pub fn profane(&self) -> RatingLevel { + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { self._tab.get::(Rating::VT_PROFANE, Some(RatingLevel::unused)).unwrap()} + } + #[inline] + pub fn substance(&self) -> RatingLevel { + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { self._tab.get::(Rating::VT_SUBSTANCE, Some(RatingLevel::unused)).unwrap()} + } + #[inline] + pub fn hate(&self) -> RatingLevel { + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { self._tab.get::(Rating::VT_HATE, Some(RatingLevel::unused)).unwrap()} + } + #[inline] + pub fn harm(&self) -> RatingLevel { + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { self._tab.get::(Rating::VT_HARM, Some(RatingLevel::unused)).unwrap()} + } + #[inline] + pub fn mature(&self) -> RatingLevel { + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { self._tab.get::(Rating::VT_MATURE, Some(RatingLevel::unused)).unwrap()} + } + #[inline] + pub fn bully(&self) -> RatingLevel { + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { self._tab.get::(Rating::VT_BULLY, Some(RatingLevel::unused)).unwrap()} + } +} + +impl flatbuffers::Verifiable for Rating<'_> { + #[inline] + fn run_verifier( + v: &mut flatbuffers::Verifier, pos: usize + ) -> Result<(), flatbuffers::InvalidFlatbuffer> { + use self::flatbuffers::Verifiable; + v.visit_table(pos)? + .visit_field::("violent", Self::VT_VIOLENT, false)? + .visit_field::("sexual", Self::VT_SEXUAL, false)? + .visit_field::("profane", Self::VT_PROFANE, false)? + .visit_field::("substance", Self::VT_SUBSTANCE, false)? + .visit_field::("hate", Self::VT_HATE, false)? + .visit_field::("harm", Self::VT_HARM, false)? + .visit_field::("mature", Self::VT_MATURE, false)? + .visit_field::("bully", Self::VT_BULLY, false)? + .finish(); + Ok(()) + } +} +pub struct RatingArgs { + pub violent: RatingLevel, + pub sexual: RatingLevel, + pub profane: RatingLevel, + pub substance: RatingLevel, + pub hate: RatingLevel, + pub harm: RatingLevel, + pub mature: RatingLevel, + pub bully: RatingLevel, +} +impl<'a> Default for RatingArgs { + #[inline] + fn default() -> Self { + RatingArgs { + violent: RatingLevel::unused, + sexual: RatingLevel::unused, + profane: RatingLevel::unused, + substance: RatingLevel::unused, + hate: RatingLevel::unused, + harm: RatingLevel::unused, + mature: RatingLevel::unused, + bully: RatingLevel::unused, + } + } +} + +pub struct RatingBuilder<'a: 'b, 'b, A: flatbuffers::Allocator + 'a> { + fbb_: &'b mut flatbuffers::FlatBufferBuilder<'a, A>, + start_: flatbuffers::WIPOffset, +} +impl<'a: 'b, 'b, A: flatbuffers::Allocator + 'a> RatingBuilder<'a, 'b, A> { + #[inline] + pub fn add_violent(&mut self, violent: RatingLevel) { + self.fbb_.push_slot::(Rating::VT_VIOLENT, violent, RatingLevel::unused); + } + #[inline] + pub fn add_sexual(&mut self, sexual: RatingLevel) { + self.fbb_.push_slot::(Rating::VT_SEXUAL, sexual, RatingLevel::unused); + } + #[inline] + pub fn add_profane(&mut self, profane: RatingLevel) { + self.fbb_.push_slot::(Rating::VT_PROFANE, profane, RatingLevel::unused); + } + #[inline] + pub fn add_substance(&mut self, substance: RatingLevel) { + self.fbb_.push_slot::(Rating::VT_SUBSTANCE, substance, RatingLevel::unused); + } + #[inline] + pub fn add_hate(&mut self, hate: RatingLevel) { + self.fbb_.push_slot::(Rating::VT_HATE, hate, RatingLevel::unused); + } + #[inline] + pub fn add_harm(&mut self, harm: RatingLevel) { + self.fbb_.push_slot::(Rating::VT_HARM, harm, RatingLevel::unused); + } + #[inline] + pub fn add_mature(&mut self, mature: RatingLevel) { + self.fbb_.push_slot::(Rating::VT_MATURE, mature, RatingLevel::unused); + } + #[inline] + pub fn add_bully(&mut self, bully: RatingLevel) { + self.fbb_.push_slot::(Rating::VT_BULLY, bully, RatingLevel::unused); + } + #[inline] + pub fn new(_fbb: &'b mut flatbuffers::FlatBufferBuilder<'a, A>) -> RatingBuilder<'a, 'b, A> { + let start = _fbb.start_table(); + RatingBuilder { + fbb_: _fbb, + start_: start, + } + } + #[inline] + pub fn finish(self) -> flatbuffers::WIPOffset> { + let o = self.fbb_.end_table(self.start_); + flatbuffers::WIPOffset::new(o.value()) + } +} + +impl core::fmt::Debug for Rating<'_> { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + let mut ds = f.debug_struct("Rating"); + ds.field("violent", &self.violent()); + ds.field("sexual", &self.sexual()); + ds.field("profane", &self.profane()); + ds.field("substance", &self.substance()); + ds.field("hate", &self.hate()); + ds.field("harm", &self.harm()); + ds.field("mature", &self.mature()); + ds.field("bully", &self.bully()); + ds.finish() + } +} +pub enum PurposeOffset {} +#[derive(Copy, Clone, PartialEq)] + +pub struct Purpose<'a> { + pub _tab: flatbuffers::Table<'a>, +} + +impl<'a> flatbuffers::Follow<'a> for Purpose<'a> { + type Inner = Purpose<'a>; + #[inline] + unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { + Self { _tab: flatbuffers::Table::new(buf, loc) } + } +} + +impl<'a> Purpose<'a> { + pub const VT_EDUCATIONAL: flatbuffers::VOffsetT = 4; + pub const VT_ENTERTAINMENT: flatbuffers::VOffsetT = 6; + pub const VT_NEWS: flatbuffers::VOffsetT = 8; + pub const VT_PROMOTIONAL: flatbuffers::VOffsetT = 10; + pub const VT_PERSONAL: flatbuffers::VOffsetT = 12; + pub const VT_OPINION: flatbuffers::VOffsetT = 14; + pub const VT_TRANSACTIONAL: flatbuffers::VOffsetT = 16; + pub const VT_HARMFUL: flatbuffers::VOffsetT = 18; + pub const VT_CONFIDENCE: flatbuffers::VOffsetT = 20; + + #[inline] + pub unsafe fn init_from_table(table: flatbuffers::Table<'a>) -> Self { + Purpose { _tab: table } + } + #[allow(unused_mut)] + pub fn create<'bldr: 'args, 'args: 'mut_bldr, 'mut_bldr, A: flatbuffers::Allocator + 'bldr>( + _fbb: &'mut_bldr mut flatbuffers::FlatBufferBuilder<'bldr, A>, + args: &'args PurposeArgs + ) -> flatbuffers::WIPOffset> { + let mut builder = PurposeBuilder::new(_fbb); + builder.add_confidence(args.confidence); + builder.add_harmful(args.harmful); + builder.add_transactional(args.transactional); + builder.add_opinion(args.opinion); + builder.add_personal(args.personal); + builder.add_promotional(args.promotional); + builder.add_news(args.news); + builder.add_entertainment(args.entertainment); + builder.add_educational(args.educational); + builder.finish() + } + + + #[inline] + pub fn educational(&self) -> f32 { + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { self._tab.get::(Purpose::VT_EDUCATIONAL, Some(0.0)).unwrap()} + } + #[inline] + pub fn entertainment(&self) -> f32 { + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { self._tab.get::(Purpose::VT_ENTERTAINMENT, Some(0.0)).unwrap()} + } + #[inline] + pub fn news(&self) -> f32 { + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { self._tab.get::(Purpose::VT_NEWS, Some(0.0)).unwrap()} + } + #[inline] + pub fn promotional(&self) -> f32 { + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { self._tab.get::(Purpose::VT_PROMOTIONAL, Some(0.0)).unwrap()} + } + #[inline] + pub fn personal(&self) -> f32 { + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { self._tab.get::(Purpose::VT_PERSONAL, Some(0.0)).unwrap()} + } + #[inline] + pub fn opinion(&self) -> f32 { + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { self._tab.get::(Purpose::VT_OPINION, Some(0.0)).unwrap()} + } + #[inline] + pub fn transactional(&self) -> f32 { + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { self._tab.get::(Purpose::VT_TRANSACTIONAL, Some(0.0)).unwrap()} + } + #[inline] + pub fn harmful(&self) -> f32 { + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { self._tab.get::(Purpose::VT_HARMFUL, Some(0.0)).unwrap()} + } + #[inline] + pub fn confidence(&self) -> f32 { + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { self._tab.get::(Purpose::VT_CONFIDENCE, Some(0.0)).unwrap()} + } +} + +impl flatbuffers::Verifiable for Purpose<'_> { + #[inline] + fn run_verifier( + v: &mut flatbuffers::Verifier, pos: usize + ) -> Result<(), flatbuffers::InvalidFlatbuffer> { + use self::flatbuffers::Verifiable; + v.visit_table(pos)? + .visit_field::("educational", Self::VT_EDUCATIONAL, false)? + .visit_field::("entertainment", Self::VT_ENTERTAINMENT, false)? + .visit_field::("news", Self::VT_NEWS, false)? + .visit_field::("promotional", Self::VT_PROMOTIONAL, false)? + .visit_field::("personal", Self::VT_PERSONAL, false)? + .visit_field::("opinion", Self::VT_OPINION, false)? + .visit_field::("transactional", Self::VT_TRANSACTIONAL, false)? + .visit_field::("harmful", Self::VT_HARMFUL, false)? + .visit_field::("confidence", Self::VT_CONFIDENCE, false)? + .finish(); + Ok(()) + } +} +pub struct PurposeArgs { + pub educational: f32, + pub entertainment: f32, + pub news: f32, + pub promotional: f32, + pub personal: f32, + pub opinion: f32, + pub transactional: f32, + pub harmful: f32, + pub confidence: f32, +} +impl<'a> Default for PurposeArgs { + #[inline] + fn default() -> Self { + PurposeArgs { + educational: 0.0, + entertainment: 0.0, + news: 0.0, + promotional: 0.0, + personal: 0.0, + opinion: 0.0, + transactional: 0.0, + harmful: 0.0, + confidence: 0.0, + } + } +} + +pub struct PurposeBuilder<'a: 'b, 'b, A: flatbuffers::Allocator + 'a> { + fbb_: &'b mut flatbuffers::FlatBufferBuilder<'a, A>, + start_: flatbuffers::WIPOffset, +} +impl<'a: 'b, 'b, A: flatbuffers::Allocator + 'a> PurposeBuilder<'a, 'b, A> { + #[inline] + pub fn add_educational(&mut self, educational: f32) { + self.fbb_.push_slot::(Purpose::VT_EDUCATIONAL, educational, 0.0); + } + #[inline] + pub fn add_entertainment(&mut self, entertainment: f32) { + self.fbb_.push_slot::(Purpose::VT_ENTERTAINMENT, entertainment, 0.0); + } + #[inline] + pub fn add_news(&mut self, news: f32) { + self.fbb_.push_slot::(Purpose::VT_NEWS, news, 0.0); + } + #[inline] + pub fn add_promotional(&mut self, promotional: f32) { + self.fbb_.push_slot::(Purpose::VT_PROMOTIONAL, promotional, 0.0); + } + #[inline] + pub fn add_personal(&mut self, personal: f32) { + self.fbb_.push_slot::(Purpose::VT_PERSONAL, personal, 0.0); + } + #[inline] + pub fn add_opinion(&mut self, opinion: f32) { + self.fbb_.push_slot::(Purpose::VT_OPINION, opinion, 0.0); + } + #[inline] + pub fn add_transactional(&mut self, transactional: f32) { + self.fbb_.push_slot::(Purpose::VT_TRANSACTIONAL, transactional, 0.0); + } + #[inline] + pub fn add_harmful(&mut self, harmful: f32) { + self.fbb_.push_slot::(Purpose::VT_HARMFUL, harmful, 0.0); + } + #[inline] + pub fn add_confidence(&mut self, confidence: f32) { + self.fbb_.push_slot::(Purpose::VT_CONFIDENCE, confidence, 0.0); + } + #[inline] + pub fn new(_fbb: &'b mut flatbuffers::FlatBufferBuilder<'a, A>) -> PurposeBuilder<'a, 'b, A> { + let start = _fbb.start_table(); + PurposeBuilder { + fbb_: _fbb, + start_: start, + } + } + #[inline] + pub fn finish(self) -> flatbuffers::WIPOffset> { + let o = self.fbb_.end_table(self.start_); + flatbuffers::WIPOffset::new(o.value()) + } +} + +impl core::fmt::Debug for Purpose<'_> { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + let mut ds = f.debug_struct("Purpose"); + ds.field("educational", &self.educational()); + ds.field("entertainment", &self.entertainment()); + ds.field("news", &self.news()); + ds.field("promotional", &self.promotional()); + ds.field("personal", &self.personal()); + ds.field("opinion", &self.opinion()); + ds.field("transactional", &self.transactional()); + ds.field("harmful", &self.harmful()); + ds.field("confidence", &self.confidence()); + ds.finish() + } +} +pub enum FormatInfoOffset {} +#[derive(Copy, Clone, PartialEq)] + +pub struct FormatInfo<'a> { + pub _tab: flatbuffers::Table<'a>, +} + +impl<'a> flatbuffers::Follow<'a> for FormatInfo<'a> { + type Inner = FormatInfo<'a>; + #[inline] + unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { + Self { _tab: flatbuffers::Table::new(buf, loc) } + } +} + +impl<'a> FormatInfo<'a> { + pub const VT_TYPE_: flatbuffers::VOffsetT = 4; + pub const VT_VERSION: flatbuffers::VOffsetT = 6; + pub const VT_PROFILE: flatbuffers::VOffsetT = 8; + + #[inline] + pub unsafe fn init_from_table(table: flatbuffers::Table<'a>) -> Self { + FormatInfo { _tab: table } + } + #[allow(unused_mut)] + pub fn create<'bldr: 'args, 'args: 'mut_bldr, 'mut_bldr, A: flatbuffers::Allocator + 'bldr>( + _fbb: &'mut_bldr mut flatbuffers::FlatBufferBuilder<'bldr, A>, + args: &'args FormatInfoArgs<'args> + ) -> flatbuffers::WIPOffset> { + let mut builder = FormatInfoBuilder::new(_fbb); + if let Some(x) = args.profile { builder.add_profile(x); } + if let Some(x) = args.version { builder.add_version(x); } + builder.add_type_(args.type_); + builder.finish() + } + + + #[inline] + pub fn type_(&self) -> FormatType { + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { self._tab.get::(FormatInfo::VT_TYPE_, Some(FormatType::plain)).unwrap()} + } + #[inline] + pub fn version(&self) -> Option<&'a str> { + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { self._tab.get::>(FormatInfo::VT_VERSION, None)} + } + #[inline] + pub fn profile(&self) -> Option<&'a str> { + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { self._tab.get::>(FormatInfo::VT_PROFILE, None)} + } +} + +impl flatbuffers::Verifiable for FormatInfo<'_> { + #[inline] + fn run_verifier( + v: &mut flatbuffers::Verifier, pos: usize + ) -> Result<(), flatbuffers::InvalidFlatbuffer> { + use self::flatbuffers::Verifiable; + v.visit_table(pos)? + .visit_field::("type_", Self::VT_TYPE_, false)? + .visit_field::>("version", Self::VT_VERSION, false)? + .visit_field::>("profile", Self::VT_PROFILE, false)? + .finish(); + Ok(()) + } +} +pub struct FormatInfoArgs<'a> { + pub type_: FormatType, + pub version: Option>, + pub profile: Option>, +} +impl<'a> Default for FormatInfoArgs<'a> { + #[inline] + fn default() -> Self { + FormatInfoArgs { + type_: FormatType::plain, + version: None, + profile: None, + } + } +} + +pub struct FormatInfoBuilder<'a: 'b, 'b, A: flatbuffers::Allocator + 'a> { + fbb_: &'b mut flatbuffers::FlatBufferBuilder<'a, A>, + start_: flatbuffers::WIPOffset, +} +impl<'a: 'b, 'b, A: flatbuffers::Allocator + 'a> FormatInfoBuilder<'a, 'b, A> { + #[inline] + pub fn add_type_(&mut self, type_: FormatType) { + self.fbb_.push_slot::(FormatInfo::VT_TYPE_, type_, FormatType::plain); + } + #[inline] + pub fn add_version(&mut self, version: flatbuffers::WIPOffset<&'b str>) { + self.fbb_.push_slot_always::>(FormatInfo::VT_VERSION, version); + } + #[inline] + pub fn add_profile(&mut self, profile: flatbuffers::WIPOffset<&'b str>) { + self.fbb_.push_slot_always::>(FormatInfo::VT_PROFILE, profile); + } + #[inline] + pub fn new(_fbb: &'b mut flatbuffers::FlatBufferBuilder<'a, A>) -> FormatInfoBuilder<'a, 'b, A> { + let start = _fbb.start_table(); + FormatInfoBuilder { + fbb_: _fbb, + start_: start, + } + } + #[inline] + pub fn finish(self) -> flatbuffers::WIPOffset> { + let o = self.fbb_.end_table(self.start_); + flatbuffers::WIPOffset::new(o.value()) + } +} + +impl core::fmt::Debug for FormatInfo<'_> { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + let mut ds = f.debug_struct("FormatInfo"); + ds.field("type_", &self.type_()); + ds.field("version", &self.version()); + ds.field("profile", &self.profile()); + ds.finish() + } +} +pub enum ArchiveInfoOffset {} +#[derive(Copy, Clone, PartialEq)] + +pub struct ArchiveInfo<'a> { + pub _tab: flatbuffers::Table<'a>, +} + +impl<'a> flatbuffers::Follow<'a> for ArchiveInfo<'a> { + type Inner = ArchiveInfo<'a>; + #[inline] + unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { + Self { _tab: flatbuffers::Table::new(buf, loc) } + } +} + +impl<'a> ArchiveInfo<'a> { + pub const VT_TYPE_: flatbuffers::VOffsetT = 4; + pub const VT_VERSION: flatbuffers::VOffsetT = 6; + pub const VT_PROFILE: flatbuffers::VOffsetT = 8; + + #[inline] + pub unsafe fn init_from_table(table: flatbuffers::Table<'a>) -> Self { + ArchiveInfo { _tab: table } + } + #[allow(unused_mut)] + pub fn create<'bldr: 'args, 'args: 'mut_bldr, 'mut_bldr, A: flatbuffers::Allocator + 'bldr>( + _fbb: &'mut_bldr mut flatbuffers::FlatBufferBuilder<'bldr, A>, + args: &'args ArchiveInfoArgs<'args> + ) -> flatbuffers::WIPOffset> { + let mut builder = ArchiveInfoBuilder::new(_fbb); + if let Some(x) = args.profile { builder.add_profile(x); } + if let Some(x) = args.version { builder.add_version(x); } + builder.add_type_(args.type_); + builder.finish() + } + + + #[inline] + pub fn type_(&self) -> ArchiveType { + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { self._tab.get::(ArchiveInfo::VT_TYPE_, Some(ArchiveType::none)).unwrap()} + } + #[inline] + pub fn version(&self) -> Option<&'a str> { + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { self._tab.get::>(ArchiveInfo::VT_VERSION, None)} + } + #[inline] + pub fn profile(&self) -> Option<&'a str> { + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { self._tab.get::>(ArchiveInfo::VT_PROFILE, None)} + } +} + +impl flatbuffers::Verifiable for ArchiveInfo<'_> { + #[inline] + fn run_verifier( + v: &mut flatbuffers::Verifier, pos: usize + ) -> Result<(), flatbuffers::InvalidFlatbuffer> { + use self::flatbuffers::Verifiable; + v.visit_table(pos)? + .visit_field::("type_", Self::VT_TYPE_, false)? + .visit_field::>("version", Self::VT_VERSION, false)? + .visit_field::>("profile", Self::VT_PROFILE, false)? + .finish(); + Ok(()) + } +} +pub struct ArchiveInfoArgs<'a> { + pub type_: ArchiveType, + pub version: Option>, + pub profile: Option>, +} +impl<'a> Default for ArchiveInfoArgs<'a> { + #[inline] + fn default() -> Self { + ArchiveInfoArgs { + type_: ArchiveType::none, + version: None, + profile: None, + } + } +} + +pub struct ArchiveInfoBuilder<'a: 'b, 'b, A: flatbuffers::Allocator + 'a> { + fbb_: &'b mut flatbuffers::FlatBufferBuilder<'a, A>, + start_: flatbuffers::WIPOffset, +} +impl<'a: 'b, 'b, A: flatbuffers::Allocator + 'a> ArchiveInfoBuilder<'a, 'b, A> { + #[inline] + pub fn add_type_(&mut self, type_: ArchiveType) { + self.fbb_.push_slot::(ArchiveInfo::VT_TYPE_, type_, ArchiveType::none); + } + #[inline] + pub fn add_version(&mut self, version: flatbuffers::WIPOffset<&'b str>) { + self.fbb_.push_slot_always::>(ArchiveInfo::VT_VERSION, version); + } + #[inline] + pub fn add_profile(&mut self, profile: flatbuffers::WIPOffset<&'b str>) { + self.fbb_.push_slot_always::>(ArchiveInfo::VT_PROFILE, profile); + } + #[inline] + pub fn new(_fbb: &'b mut flatbuffers::FlatBufferBuilder<'a, A>) -> ArchiveInfoBuilder<'a, 'b, A> { + let start = _fbb.start_table(); + ArchiveInfoBuilder { + fbb_: _fbb, + start_: start, + } + } + #[inline] + pub fn finish(self) -> flatbuffers::WIPOffset> { + let o = self.fbb_.end_table(self.start_); + flatbuffers::WIPOffset::new(o.value()) + } +} + +impl core::fmt::Debug for ArchiveInfo<'_> { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + let mut ds = f.debug_struct("ArchiveInfo"); + ds.field("type_", &self.type_()); + ds.field("version", &self.version()); + ds.field("profile", &self.profile()); + ds.finish() + } +} +pub enum ContentFormatOffset {} +#[derive(Copy, Clone, PartialEq)] + +pub struct ContentFormat<'a> { + pub _tab: flatbuffers::Table<'a>, +} + +impl<'a> flatbuffers::Follow<'a> for ContentFormat<'a> { + type Inner = ContentFormat<'a>; + #[inline] + unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { + Self { _tab: flatbuffers::Table::new(buf, loc) } + } +} + +impl<'a> ContentFormat<'a> { + pub const VT_MEDIA_TYPE: flatbuffers::VOffsetT = 4; + pub const VT_DATA_ENCODING: flatbuffers::VOffsetT = 6; + pub const VT_FORMAT: flatbuffers::VOffsetT = 8; + + #[inline] + pub unsafe fn init_from_table(table: flatbuffers::Table<'a>) -> Self { + ContentFormat { _tab: table } + } + #[allow(unused_mut)] + pub fn create<'bldr: 'args, 'args: 'mut_bldr, 'mut_bldr, A: flatbuffers::Allocator + 'bldr>( + _fbb: &'mut_bldr mut flatbuffers::FlatBufferBuilder<'bldr, A>, + args: &'args ContentFormatArgs<'args> + ) -> flatbuffers::WIPOffset> { + let mut builder = ContentFormatBuilder::new(_fbb); + if let Some(x) = args.format { builder.add_format(x); } + builder.add_data_encoding(args.data_encoding); + builder.add_media_type(args.media_type); + builder.finish() + } + + + #[inline] + pub fn media_type(&self) -> MediaType { + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { self._tab.get::(ContentFormat::VT_MEDIA_TYPE, Some(MediaType::unused)).unwrap()} + } + #[inline] + pub fn data_encoding(&self) -> DataEncoding { + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { self._tab.get::(ContentFormat::VT_DATA_ENCODING, Some(DataEncoding::binary)).unwrap()} + } + #[inline] + pub fn format(&self) -> Option> { + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { self._tab.get::>(ContentFormat::VT_FORMAT, None)} + } +} + +impl flatbuffers::Verifiable for ContentFormat<'_> { + #[inline] + fn run_verifier( + v: &mut flatbuffers::Verifier, pos: usize + ) -> Result<(), flatbuffers::InvalidFlatbuffer> { + use self::flatbuffers::Verifiable; + v.visit_table(pos)? + .visit_field::("media_type", Self::VT_MEDIA_TYPE, false)? + .visit_field::("data_encoding", Self::VT_DATA_ENCODING, false)? + .visit_field::>("format", Self::VT_FORMAT, false)? + .finish(); + Ok(()) + } +} +pub struct ContentFormatArgs<'a> { + pub media_type: MediaType, + pub data_encoding: DataEncoding, + pub format: Option>>, +} +impl<'a> Default for ContentFormatArgs<'a> { + #[inline] + fn default() -> Self { + ContentFormatArgs { + media_type: MediaType::unused, + data_encoding: DataEncoding::binary, + format: None, + } + } +} + +pub struct ContentFormatBuilder<'a: 'b, 'b, A: flatbuffers::Allocator + 'a> { + fbb_: &'b mut flatbuffers::FlatBufferBuilder<'a, A>, + start_: flatbuffers::WIPOffset, +} +impl<'a: 'b, 'b, A: flatbuffers::Allocator + 'a> ContentFormatBuilder<'a, 'b, A> { + #[inline] + pub fn add_media_type(&mut self, media_type: MediaType) { + self.fbb_.push_slot::(ContentFormat::VT_MEDIA_TYPE, media_type, MediaType::unused); + } + #[inline] + pub fn add_data_encoding(&mut self, data_encoding: DataEncoding) { + self.fbb_.push_slot::(ContentFormat::VT_DATA_ENCODING, data_encoding, DataEncoding::binary); + } + #[inline] + pub fn add_format(&mut self, format: flatbuffers::WIPOffset>) { + self.fbb_.push_slot_always::>(ContentFormat::VT_FORMAT, format); + } + #[inline] + pub fn new(_fbb: &'b mut flatbuffers::FlatBufferBuilder<'a, A>) -> ContentFormatBuilder<'a, 'b, A> { + let start = _fbb.start_table(); + ContentFormatBuilder { + fbb_: _fbb, + start_: start, + } + } + #[inline] + pub fn finish(self) -> flatbuffers::WIPOffset> { + let o = self.fbb_.end_table(self.start_); + flatbuffers::WIPOffset::new(o.value()) + } +} + +impl core::fmt::Debug for ContentFormat<'_> { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + let mut ds = f.debug_struct("ContentFormat"); + ds.field("media_type", &self.media_type()); + ds.field("data_encoding", &self.data_encoding()); + ds.field("format", &self.format()); + ds.finish() + } +} +pub enum MetadataOffset {} +#[derive(Copy, Clone, PartialEq)] + +pub struct Metadata<'a> { + pub _tab: flatbuffers::Table<'a>, +} + +impl<'a> flatbuffers::Follow<'a> for Metadata<'a> { + type Inner = Metadata<'a>; + #[inline] + unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { + Self { _tab: flatbuffers::Table::new(buf, loc) } + } +} + +impl<'a> Metadata<'a> { + pub const VT_CREATED: flatbuffers::VOffsetT = 4; + pub const VT_ID: flatbuffers::VOffsetT = 6; + pub const VT_RELATED: flatbuffers::VOffsetT = 8; + pub const VT_RATING: flatbuffers::VOffsetT = 10; + pub const VT_PURPOSE: flatbuffers::VOffsetT = 12; + pub const VT_TOPICS: flatbuffers::VOffsetT = 14; + pub const VT_ARCHIVE: flatbuffers::VOffsetT = 16; + pub const VT_CONTENT: flatbuffers::VOffsetT = 18; + + #[inline] + pub unsafe fn init_from_table(table: flatbuffers::Table<'a>) -> Self { + Metadata { _tab: table } + } + #[allow(unused_mut)] + pub fn create<'bldr: 'args, 'args: 'mut_bldr, 'mut_bldr, A: flatbuffers::Allocator + 'bldr>( + _fbb: &'mut_bldr mut flatbuffers::FlatBufferBuilder<'bldr, A>, + args: &'args MetadataArgs<'args> + ) -> flatbuffers::WIPOffset> { + let mut builder = MetadataBuilder::new(_fbb); + builder.add_created(args.created); + if let Some(x) = args.content { builder.add_content(x); } + if let Some(x) = args.archive { builder.add_archive(x); } + if let Some(x) = args.topics { builder.add_topics(x); } + if let Some(x) = args.purpose { builder.add_purpose(x); } + if let Some(x) = args.rating { builder.add_rating(x); } + if let Some(x) = args.related { builder.add_related(x); } + if let Some(x) = args.id { builder.add_id(x); } + builder.finish() + } + + + #[inline] + pub fn created(&self) -> i64 { + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { self._tab.get::(Metadata::VT_CREATED, Some(0)).unwrap()} + } + #[inline] + pub fn id(&self) -> Option> { + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { self._tab.get::>>(Metadata::VT_ID, None)} + } + #[inline] + pub fn related(&self) -> Option> { + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { self._tab.get::>>(Metadata::VT_RELATED, None)} + } + #[inline] + pub fn rating(&self) -> Option> { + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { self._tab.get::>(Metadata::VT_RATING, None)} + } + #[inline] + pub fn purpose(&self) -> Option> { + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { self._tab.get::>(Metadata::VT_PURPOSE, None)} + } + #[inline] + pub fn topics(&self) -> Option> { + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { self._tab.get::>>(Metadata::VT_TOPICS, None)} + } + #[inline] + pub fn archive(&self) -> Option> { + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { self._tab.get::>(Metadata::VT_ARCHIVE, None)} + } + #[inline] + pub fn content(&self) -> Option> { + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { self._tab.get::>(Metadata::VT_CONTENT, None)} + } +} + +impl flatbuffers::Verifiable for Metadata<'_> { + #[inline] + fn run_verifier( + v: &mut flatbuffers::Verifier, pos: usize + ) -> Result<(), flatbuffers::InvalidFlatbuffer> { + use self::flatbuffers::Verifiable; + v.visit_table(pos)? + .visit_field::("created", Self::VT_CREATED, false)? + .visit_field::>>("id", Self::VT_ID, false)? + .visit_field::>>("related", Self::VT_RELATED, false)? + .visit_field::>("rating", Self::VT_RATING, false)? + .visit_field::>("purpose", Self::VT_PURPOSE, false)? + .visit_field::>>("topics", Self::VT_TOPICS, false)? + .visit_field::>("archive", Self::VT_ARCHIVE, false)? + .visit_field::>("content", Self::VT_CONTENT, false)? + .finish(); + Ok(()) + } +} +pub struct MetadataArgs<'a> { + pub created: i64, + pub id: Option>>, + pub related: Option>>, + pub rating: Option>>, + pub purpose: Option>>, + pub topics: Option>>, + pub archive: Option>>, + pub content: Option>>, +} +impl<'a> Default for MetadataArgs<'a> { + #[inline] + fn default() -> Self { + MetadataArgs { + created: 0, + id: None, + related: None, + rating: None, + purpose: None, + topics: None, + archive: None, + content: None, + } + } +} + +pub struct MetadataBuilder<'a: 'b, 'b, A: flatbuffers::Allocator + 'a> { + fbb_: &'b mut flatbuffers::FlatBufferBuilder<'a, A>, + start_: flatbuffers::WIPOffset, +} +impl<'a: 'b, 'b, A: flatbuffers::Allocator + 'a> MetadataBuilder<'a, 'b, A> { + #[inline] + pub fn add_created(&mut self, created: i64) { + self.fbb_.push_slot::(Metadata::VT_CREATED, created, 0); + } + #[inline] + pub fn add_id(&mut self, id: flatbuffers::WIPOffset>) { + self.fbb_.push_slot_always::>(Metadata::VT_ID, id); + } + #[inline] + pub fn add_related(&mut self, related: flatbuffers::WIPOffset>) { + self.fbb_.push_slot_always::>(Metadata::VT_RELATED, related); + } + #[inline] + pub fn add_rating(&mut self, rating: flatbuffers::WIPOffset>) { + self.fbb_.push_slot_always::>(Metadata::VT_RATING, rating); + } + #[inline] + pub fn add_purpose(&mut self, purpose: flatbuffers::WIPOffset>) { + self.fbb_.push_slot_always::>(Metadata::VT_PURPOSE, purpose); + } + #[inline] + pub fn add_topics(&mut self, topics: flatbuffers::WIPOffset>) { + self.fbb_.push_slot_always::>(Metadata::VT_TOPICS, topics); + } + #[inline] + pub fn add_archive(&mut self, archive: flatbuffers::WIPOffset>) { + self.fbb_.push_slot_always::>(Metadata::VT_ARCHIVE, archive); + } + #[inline] + pub fn add_content(&mut self, content: flatbuffers::WIPOffset>) { + self.fbb_.push_slot_always::>(Metadata::VT_CONTENT, content); + } + #[inline] + pub fn new(_fbb: &'b mut flatbuffers::FlatBufferBuilder<'a, A>) -> MetadataBuilder<'a, 'b, A> { + let start = _fbb.start_table(); + MetadataBuilder { + fbb_: _fbb, + start_: start, + } + } + #[inline] + pub fn finish(self) -> flatbuffers::WIPOffset> { + let o = self.fbb_.end_table(self.start_); + flatbuffers::WIPOffset::new(o.value()) + } +} + +impl core::fmt::Debug for Metadata<'_> { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + let mut ds = f.debug_struct("Metadata"); + ds.field("created", &self.created()); + ds.field("id", &self.id()); + ds.field("related", &self.related()); + ds.field("rating", &self.rating()); + ds.field("purpose", &self.purpose()); + ds.field("topics", &self.topics()); + ds.field("archive", &self.archive()); + ds.field("content", &self.content()); + ds.finish() + } +} +#[inline] +/// Verifies that a buffer of bytes contains a `Metadata` +/// and returns it. +/// Note that verification is still experimental and may not +/// catch every error, or be maximally performant. For the +/// previous, unchecked, behavior use +/// `root_as_metadata_unchecked`. +pub fn root_as_metadata(buf: &[u8]) -> Result { + flatbuffers::root::(buf) +} +#[inline] +/// Verifies that a buffer of bytes contains a size prefixed +/// `Metadata` and returns it. +/// Note that verification is still experimental and may not +/// catch every error, or be maximally performant. For the +/// previous, unchecked, behavior use +/// `size_prefixed_root_as_metadata_unchecked`. +pub fn size_prefixed_root_as_metadata(buf: &[u8]) -> Result { + flatbuffers::size_prefixed_root::(buf) +} +#[inline] +/// Verifies, with the given options, that a buffer of bytes +/// contains a `Metadata` and returns it. +/// Note that verification is still experimental and may not +/// catch every error, or be maximally performant. For the +/// previous, unchecked, behavior use +/// `root_as_metadata_unchecked`. +pub fn root_as_metadata_with_opts<'b, 'o>( + opts: &'o flatbuffers::VerifierOptions, + buf: &'b [u8], +) -> Result, flatbuffers::InvalidFlatbuffer> { + flatbuffers::root_with_opts::>(opts, buf) +} +#[inline] +/// Verifies, with the given verifier options, that a buffer of +/// bytes contains a size prefixed `Metadata` and returns +/// it. Note that verification is still experimental and may not +/// catch every error, or be maximally performant. For the +/// previous, unchecked, behavior use +/// `root_as_metadata_unchecked`. +pub fn size_prefixed_root_as_metadata_with_opts<'b, 'o>( + opts: &'o flatbuffers::VerifierOptions, + buf: &'b [u8], +) -> Result, flatbuffers::InvalidFlatbuffer> { + flatbuffers::size_prefixed_root_with_opts::>(opts, buf) +} +#[inline] +/// Assumes, without verification, that a buffer of bytes contains a Metadata and returns it. +/// # Safety +/// Callers must trust the given bytes do indeed contain a valid `Metadata`. +pub unsafe fn root_as_metadata_unchecked(buf: &[u8]) -> Metadata { + flatbuffers::root_unchecked::(buf) +} +#[inline] +/// Assumes, without verification, that a buffer of bytes contains a size prefixed Metadata and returns it. +/// # Safety +/// Callers must trust the given bytes do indeed contain a valid size prefixed `Metadata`. +pub unsafe fn size_prefixed_root_as_metadata_unchecked(buf: &[u8]) -> Metadata { + flatbuffers::size_prefixed_root_unchecked::(buf) +} +#[inline] +pub fn finish_metadata_buffer<'a, 'b, A: flatbuffers::Allocator + 'a>( + fbb: &'b mut flatbuffers::FlatBufferBuilder<'a, A>, + root: flatbuffers::WIPOffset>) { + fbb.finish(root, None); +} + +#[inline] +pub fn finish_size_prefixed_metadata_buffer<'a, 'b, A: flatbuffers::Allocator + 'a>(fbb: &'b mut flatbuffers::FlatBufferBuilder<'a, A>, root: flatbuffers::WIPOffset>) { + fbb.finish_size_prefixed(root, None); +} +} // pub mod Arkavo + diff --git a/src/bin/schemas/mod.rs b/src/bin/schemas/mod.rs index b748312..55a9838 100644 --- a/src/bin/schemas/mod.rs +++ b/src/bin/schemas/mod.rs @@ -1 +1,3 @@ pub mod event_generated; +pub mod metadata_generated; +pub mod entity_generated; diff --git a/src/lib.rs b/src/lib.rs index 7e1bd1b..b4a11ac 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -18,13 +18,13 @@ struct NanoTDFHeader { ephemeral_key: Vec, } -#[derive(Serialize, Deserialize, Debug)] +#[derive(Serialize, Deserialize, Debug, Clone)] pub struct ResourceLocator { pub protocol_enum: ProtocolEnum, pub body: String, } -#[derive(Serialize, Deserialize, Debug, PartialEq)] +#[derive(Serialize, Deserialize, Debug, PartialEq, Clone)] pub enum ProtocolEnum { Http = 0x00, Https = 0x01, From 12efb4f530644962b4bc6dec89f7da527fd44a71 Mon Sep 17 00:00:00 2001 From: Paul Flynn Date: Thu, 24 Oct 2024 21:18:21 -0400 Subject: [PATCH 15/15] Add age field to Claims and verify age for content rating Introduce a new age field in the Claims struct to verify the age of users for content rating. This helps differentiate content access based on age criteria and ensures age-appropriate content delivery. --- src/bin/contracts/content_rating.rs | 7 +- src/bin/contracts/mod.rs | 2 +- src/bin/main.rs | 47 +- src/bin/schemas/entity_generated.rs | 4572 ++++++++++++++----------- src/bin/schemas/metadata_generated.rs | 3466 ++++++++++--------- src/bin/schemas/mod.rs | 2 +- 6 files changed, 4472 insertions(+), 3624 deletions(-) diff --git a/src/bin/contracts/content_rating.rs b/src/bin/contracts/content_rating.rs index a90fe46..595780e 100644 --- a/src/bin/contracts/content_rating.rs +++ b/src/bin/contracts/content_rating.rs @@ -27,9 +27,9 @@ pub mod content_rating { #[derive(Debug, PartialEq, Eq, scale::Encode, scale::Decode)] #[cfg_attr(feature = "std", derive(scale_info::TypeInfo))] pub enum AgeLevel { - Kids, // Under 13 - Teens, // 13 to 17 - Adults, // 18 and above + Kids, // Under 13 + Teens, // 13 to 17 + Adults, // 18 and above } #[derive(Debug, PartialEq, Eq, scale::Encode, scale::Decode)] @@ -46,6 +46,7 @@ pub mod content_rating { } #[ink(storage)] + #[derive(Default)] pub struct ContentRating { // Contract storage (empty for this case) } diff --git a/src/bin/contracts/mod.rs b/src/bin/contracts/mod.rs index 22b537a..460a9a4 100644 --- a/src/bin/contracts/mod.rs +++ b/src/bin/contracts/mod.rs @@ -1,3 +1,3 @@ +pub mod content_rating; pub mod contract_simple_abac; pub mod geo_fence_contract; -pub mod content_rating; diff --git a/src/bin/main.rs b/src/bin/main.rs index 32a877a..6eb1ffc 100644 --- a/src/bin/main.rs +++ b/src/bin/main.rs @@ -1,10 +1,14 @@ mod contracts; mod schemas; -use crate::contracts::content_rating::content_rating::{AgeLevel, ContentRating, Rating, RatingLevel}; +use crate::contracts::content_rating::content_rating::{ + AgeLevel, ContentRating, Rating, RatingLevel, +}; use crate::contracts::geo_fence_contract::geo_fence_contract::Geofence3D; use crate::contracts::{contract_simple_abac, geo_fence_contract}; use crate::schemas::event_generated::arkavo::{Event, EventData}; +use crate::schemas::metadata_generated::arkavo; +use crate::schemas::metadata_generated::arkavo::{root_as_metadata, Metadata}; use aes_gcm::aead::generic_array::GenericArray; use aes_gcm::aead::KeyInit; use aes_gcm::aead::{Aead, Key}; @@ -39,8 +43,6 @@ use tokio::net::TcpListener; use tokio::sync::{mpsc, Mutex}; use tokio_native_tls::TlsAcceptor; use tokio_tungstenite::tungstenite::Message; -use crate::schemas::metadata_generated::arkavo; -use crate::schemas::metadata_generated::arkavo::{root_as_metadata, Metadata}; #[derive(Serialize, Deserialize, Debug)] struct PublicKeyMessage { @@ -399,6 +401,7 @@ async fn handle_connection( #[derive(Debug, Serialize, Deserialize, Clone)] struct Claims { sub: String, + age: String, } fn verify_token(token: &str) -> Result { let mut validation = Validation::default(); @@ -513,7 +516,7 @@ async fn handle_rewrap( // println!("policy: {:?}", policy); let locator: Option; let policy_body: Option<&[u8]> = None; - let mut metadata: Option = None; + let mut metadata: Option = None; match policy.policy_type { PolicyType::Remote => { @@ -533,7 +536,7 @@ async fn handle_rewrap( // println!("metadata: {:#?}", metadata); } // add content rating contract - let rl = ResourceLocator{ + let rl = ResourceLocator { protocol_enum: ProtocolEnum::SharedResource, body: "5HKLo6CKbt1Z5dU4wZ3MiufeZzjM6JGwKUWUQ6a91fmuA6RB".to_string(), }; @@ -544,6 +547,7 @@ async fn handle_rewrap( if locator.protocol_enum == ProtocolEnum::SharedResource { println!("contract {}", locator.body.clone()); if !locator.body.is_empty() { + // "Verified 18+" let claims_result = match connection_state.claims_lock.read() { Ok(read_lock) => match read_lock.clone() { Some(value) => Ok(value.sub), @@ -551,6 +555,15 @@ async fn handle_rewrap( }, Err(_) => Err("Error: Read lock cannot be obtained"), }; + let verified_age_result = match connection_state + .claims_lock + .read() + .expect("Error: Read lock cannot be obtained") + .clone() + { + Some(claims) => Ok(claims.age == "Verified 18+"), + None => Err("Error: Claims data not available"), + }; // geo_fence_contract if locator .body @@ -629,8 +642,12 @@ async fn handle_rewrap( let contract = ContentRating::new(); // Parse the content rating data from the policy body // get entitlements - let age_level = AgeLevel::Kids; - if metadata == None { + let age_level = if verified_age_result.unwrap_or(false) { + AgeLevel::Adults + } else { + AgeLevel::Kids + }; + if metadata.is_none() { println!("metadata is null"); return None; } @@ -649,13 +666,13 @@ async fn handle_rewrap( println!("content rating DENY"); return None; } - } - // simple_abac - else if locator - .body - .contains("5Cqk3ERPToSMuY8UoKJtcmo4fs1iVyQpq6ndzWzpzWezAF1W") - { - let contract = contract_simple_abac::simple_abac::SimpleAbac::new(); + } + // simple_abac + else if locator + .body + .contains("5Cqk3ERPToSMuY8UoKJtcmo4fs1iVyQpq6ndzWzpzWezAF1W") + { + let contract = contract_simple_abac::simple_abac::SimpleAbac::new(); if claims_result.is_ok() && !contract.check_access(claims_result.unwrap(), locator.body.clone()) { @@ -1373,4 +1390,4 @@ fn convert_rating_level(level: arkavo::RatingLevel) -> RatingLevel { x if x == arkavo::RatingLevel::severe.0 => RatingLevel::Severe, _ => RatingLevel::Unused, // Default to Unused for any invalid values } -} \ No newline at end of file +} diff --git a/src/bin/schemas/entity_generated.rs b/src/bin/schemas/entity_generated.rs index 213c08c..857fd2c 100644 --- a/src/bin/schemas/entity_generated.rs +++ b/src/bin/schemas/entity_generated.rs @@ -8,2058 +8,2536 @@ extern crate flatbuffers; #[allow(unused_imports, dead_code)] pub mod arkavo { - use core::mem; - use core::cmp::Ordering; - - extern crate flatbuffers; - use self::flatbuffers::{EndianScalar, Follow}; - -#[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")] -pub const ENUM_MIN_ACTIVITY_LEVEL: i8 = 0; -#[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")] -pub const ENUM_MAX_ACTIVITY_LEVEL: i8 = 3; -#[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")] -#[allow(non_camel_case_types)] -pub const ENUM_VALUES_ACTIVITY_LEVEL: [ActivityLevel; 4] = [ - ActivityLevel::unused, - ActivityLevel::low, - ActivityLevel::medium, - ActivityLevel::high, -]; - -#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Default)] -#[repr(transparent)] -pub struct ActivityLevel(pub i8); -#[allow(non_upper_case_globals)] -impl ActivityLevel { - pub const unused: Self = Self(0); - pub const low: Self = Self(1); - pub const medium: Self = Self(2); - pub const high: Self = Self(3); - - pub const ENUM_MIN: i8 = 0; - pub const ENUM_MAX: i8 = 3; - pub const ENUM_VALUES: &'static [Self] = &[ - Self::unused, - Self::low, - Self::medium, - Self::high, - ]; - /// Returns the variant's name or "" if unknown. - pub fn variant_name(self) -> Option<&'static str> { - match self { - Self::unused => Some("unused"), - Self::low => Some("low"), - Self::medium => Some("medium"), - Self::high => Some("high"), - _ => None, - } - } -} -impl core::fmt::Debug for ActivityLevel { - fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result { - if let Some(name) = self.variant_name() { - f.write_str(name) - } else { - f.write_fmt(format_args!("", self.0)) - } - } -} -impl<'a> flatbuffers::Follow<'a> for ActivityLevel { - type Inner = Self; - #[inline] - unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { - let b = flatbuffers::read_scalar_at::(buf, loc); - Self(b) - } -} - -impl flatbuffers::Push for ActivityLevel { - type Output = ActivityLevel; - #[inline] - unsafe fn push(&self, dst: &mut [u8], _written_len: usize) { - flatbuffers::emplace_scalar::(dst, self.0); - } -} - -impl flatbuffers::EndianScalar for ActivityLevel { - type Scalar = i8; - #[inline] - fn to_little_endian(self) -> i8 { - self.0.to_le() - } - #[inline] - #[allow(clippy::wrong_self_convention)] - fn from_little_endian(v: i8) -> Self { - let b = i8::from_le(v); - Self(b) - } -} - -impl<'a> flatbuffers::Verifiable for ActivityLevel { - #[inline] - fn run_verifier( - v: &mut flatbuffers::Verifier, pos: usize - ) -> Result<(), flatbuffers::InvalidFlatbuffer> { - use self::flatbuffers::Verifiable; - i8::run_verifier(v, pos) - } -} - -impl flatbuffers::SimpleToVerifyInSlice for ActivityLevel {} -#[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")] -pub const ENUM_MIN_MEDIA_TYPE: i8 = 0; -#[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")] -pub const ENUM_MAX_MEDIA_TYPE: i8 = 4; -#[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")] -#[allow(non_camel_case_types)] -pub const ENUM_VALUES_MEDIA_TYPE: [MediaType; 5] = [ - MediaType::unused, - MediaType::text, - MediaType::image, - MediaType::video, - MediaType::audio, -]; - -#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Default)] -#[repr(transparent)] -pub struct MediaType(pub i8); -#[allow(non_upper_case_globals)] -impl MediaType { - pub const unused: Self = Self(0); - pub const text: Self = Self(1); - pub const image: Self = Self(2); - pub const video: Self = Self(3); - pub const audio: Self = Self(4); - - pub const ENUM_MIN: i8 = 0; - pub const ENUM_MAX: i8 = 4; - pub const ENUM_VALUES: &'static [Self] = &[ - Self::unused, - Self::text, - Self::image, - Self::video, - Self::audio, - ]; - /// Returns the variant's name or "" if unknown. - pub fn variant_name(self) -> Option<&'static str> { - match self { - Self::unused => Some("unused"), - Self::text => Some("text"), - Self::image => Some("image"), - Self::video => Some("video"), - Self::audio => Some("audio"), - _ => None, - } - } -} -impl core::fmt::Debug for MediaType { - fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result { - if let Some(name) = self.variant_name() { - f.write_str(name) - } else { - f.write_fmt(format_args!("", self.0)) - } - } -} -impl<'a> flatbuffers::Follow<'a> for MediaType { - type Inner = Self; - #[inline] - unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { - let b = flatbuffers::read_scalar_at::(buf, loc); - Self(b) - } -} - -impl flatbuffers::Push for MediaType { - type Output = MediaType; - #[inline] - unsafe fn push(&self, dst: &mut [u8], _written_len: usize) { - flatbuffers::emplace_scalar::(dst, self.0); - } -} - -impl flatbuffers::EndianScalar for MediaType { - type Scalar = i8; - #[inline] - fn to_little_endian(self) -> i8 { - self.0.to_le() - } - #[inline] - #[allow(clippy::wrong_self_convention)] - fn from_little_endian(v: i8) -> Self { - let b = i8::from_le(v); - Self(b) - } -} - -impl<'a> flatbuffers::Verifiable for MediaType { - #[inline] - fn run_verifier( - v: &mut flatbuffers::Verifier, pos: usize - ) -> Result<(), flatbuffers::InvalidFlatbuffer> { - use self::flatbuffers::Verifiable; - i8::run_verifier(v, pos) - } -} - -impl flatbuffers::SimpleToVerifyInSlice for MediaType {} -#[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")] -pub const ENUM_MIN_LOCATION_LEVEL: i8 = 0; -#[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")] -pub const ENUM_MAX_LOCATION_LEVEL: i8 = 3; -#[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")] -#[allow(non_camel_case_types)] -pub const ENUM_VALUES_LOCATION_LEVEL: [LocationLevel; 4] = [ - LocationLevel::unused, - LocationLevel::wide, - LocationLevel::approximate, - LocationLevel::precise, -]; - -#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Default)] -#[repr(transparent)] -pub struct LocationLevel(pub i8); -#[allow(non_upper_case_globals)] -impl LocationLevel { - pub const unused: Self = Self(0); - pub const wide: Self = Self(1); - pub const approximate: Self = Self(2); - pub const precise: Self = Self(3); - - pub const ENUM_MIN: i8 = 0; - pub const ENUM_MAX: i8 = 3; - pub const ENUM_VALUES: &'static [Self] = &[ - Self::unused, - Self::wide, - Self::approximate, - Self::precise, - ]; - /// Returns the variant's name or "" if unknown. - pub fn variant_name(self) -> Option<&'static str> { - match self { - Self::unused => Some("unused"), - Self::wide => Some("wide"), - Self::approximate => Some("approximate"), - Self::precise => Some("precise"), - _ => None, - } - } -} -impl core::fmt::Debug for LocationLevel { - fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result { - if let Some(name) = self.variant_name() { - f.write_str(name) - } else { - f.write_fmt(format_args!("", self.0)) - } - } -} -impl<'a> flatbuffers::Follow<'a> for LocationLevel { - type Inner = Self; - #[inline] - unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { - let b = flatbuffers::read_scalar_at::(buf, loc); - Self(b) - } -} - -impl flatbuffers::Push for LocationLevel { - type Output = LocationLevel; + use core::cmp::Ordering; + use core::mem; + + extern crate flatbuffers; + use self::flatbuffers::{EndianScalar, Follow}; + + #[deprecated( + since = "2.0.0", + note = "Use associated constants instead. This will no longer be generated in 2021." + )] + pub const ENUM_MIN_ACTIVITY_LEVEL: i8 = 0; + #[deprecated( + since = "2.0.0", + note = "Use associated constants instead. This will no longer be generated in 2021." + )] + pub const ENUM_MAX_ACTIVITY_LEVEL: i8 = 3; + #[deprecated( + since = "2.0.0", + note = "Use associated constants instead. This will no longer be generated in 2021." + )] + #[allow(non_camel_case_types)] + pub const ENUM_VALUES_ACTIVITY_LEVEL: [ActivityLevel; 4] = [ + ActivityLevel::unused, + ActivityLevel::low, + ActivityLevel::medium, + ActivityLevel::high, + ]; + + #[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Default)] + #[repr(transparent)] + pub struct ActivityLevel(pub i8); + #[allow(non_upper_case_globals)] + impl ActivityLevel { + pub const unused: Self = Self(0); + pub const low: Self = Self(1); + pub const medium: Self = Self(2); + pub const high: Self = Self(3); + + pub const ENUM_MIN: i8 = 0; + pub const ENUM_MAX: i8 = 3; + pub const ENUM_VALUES: &'static [Self] = + &[Self::unused, Self::low, Self::medium, Self::high]; + /// Returns the variant's name or "" if unknown. + pub fn variant_name(self) -> Option<&'static str> { + match self { + Self::unused => Some("unused"), + Self::low => Some("low"), + Self::medium => Some("medium"), + Self::high => Some("high"), + _ => None, + } + } + } + impl core::fmt::Debug for ActivityLevel { + fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result { + if let Some(name) = self.variant_name() { + f.write_str(name) + } else { + f.write_fmt(format_args!("", self.0)) + } + } + } + impl<'a> flatbuffers::Follow<'a> for ActivityLevel { + type Inner = Self; + #[inline] + unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { + let b = flatbuffers::read_scalar_at::(buf, loc); + Self(b) + } + } + + impl flatbuffers::Push for ActivityLevel { + type Output = ActivityLevel; + #[inline] + unsafe fn push(&self, dst: &mut [u8], _written_len: usize) { + flatbuffers::emplace_scalar::(dst, self.0); + } + } + + impl flatbuffers::EndianScalar for ActivityLevel { + type Scalar = i8; + #[inline] + fn to_little_endian(self) -> i8 { + self.0.to_le() + } + #[inline] + #[allow(clippy::wrong_self_convention)] + fn from_little_endian(v: i8) -> Self { + let b = i8::from_le(v); + Self(b) + } + } + + impl<'a> flatbuffers::Verifiable for ActivityLevel { + #[inline] + fn run_verifier( + v: &mut flatbuffers::Verifier, + pos: usize, + ) -> Result<(), flatbuffers::InvalidFlatbuffer> { + use self::flatbuffers::Verifiable; + i8::run_verifier(v, pos) + } + } + + impl flatbuffers::SimpleToVerifyInSlice for ActivityLevel {} + #[deprecated( + since = "2.0.0", + note = "Use associated constants instead. This will no longer be generated in 2021." + )] + pub const ENUM_MIN_MEDIA_TYPE: i8 = 0; + #[deprecated( + since = "2.0.0", + note = "Use associated constants instead. This will no longer be generated in 2021." + )] + pub const ENUM_MAX_MEDIA_TYPE: i8 = 4; + #[deprecated( + since = "2.0.0", + note = "Use associated constants instead. This will no longer be generated in 2021." + )] + #[allow(non_camel_case_types)] + pub const ENUM_VALUES_MEDIA_TYPE: [MediaType; 5] = [ + MediaType::unused, + MediaType::text, + MediaType::image, + MediaType::video, + MediaType::audio, + ]; + + #[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Default)] + #[repr(transparent)] + pub struct MediaType(pub i8); + #[allow(non_upper_case_globals)] + impl MediaType { + pub const unused: Self = Self(0); + pub const text: Self = Self(1); + pub const image: Self = Self(2); + pub const video: Self = Self(3); + pub const audio: Self = Self(4); + + pub const ENUM_MIN: i8 = 0; + pub const ENUM_MAX: i8 = 4; + pub const ENUM_VALUES: &'static [Self] = &[ + Self::unused, + Self::text, + Self::image, + Self::video, + Self::audio, + ]; + /// Returns the variant's name or "" if unknown. + pub fn variant_name(self) -> Option<&'static str> { + match self { + Self::unused => Some("unused"), + Self::text => Some("text"), + Self::image => Some("image"), + Self::video => Some("video"), + Self::audio => Some("audio"), + _ => None, + } + } + } + impl core::fmt::Debug for MediaType { + fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result { + if let Some(name) = self.variant_name() { + f.write_str(name) + } else { + f.write_fmt(format_args!("", self.0)) + } + } + } + impl<'a> flatbuffers::Follow<'a> for MediaType { + type Inner = Self; + #[inline] + unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { + let b = flatbuffers::read_scalar_at::(buf, loc); + Self(b) + } + } + + impl flatbuffers::Push for MediaType { + type Output = MediaType; + #[inline] + unsafe fn push(&self, dst: &mut [u8], _written_len: usize) { + flatbuffers::emplace_scalar::(dst, self.0); + } + } + + impl flatbuffers::EndianScalar for MediaType { + type Scalar = i8; + #[inline] + fn to_little_endian(self) -> i8 { + self.0.to_le() + } + #[inline] + #[allow(clippy::wrong_self_convention)] + fn from_little_endian(v: i8) -> Self { + let b = i8::from_le(v); + Self(b) + } + } + + impl<'a> flatbuffers::Verifiable for MediaType { + #[inline] + fn run_verifier( + v: &mut flatbuffers::Verifier, + pos: usize, + ) -> Result<(), flatbuffers::InvalidFlatbuffer> { + use self::flatbuffers::Verifiable; + i8::run_verifier(v, pos) + } + } + + impl flatbuffers::SimpleToVerifyInSlice for MediaType {} + #[deprecated( + since = "2.0.0", + note = "Use associated constants instead. This will no longer be generated in 2021." + )] + pub const ENUM_MIN_LOCATION_LEVEL: i8 = 0; + #[deprecated( + since = "2.0.0", + note = "Use associated constants instead. This will no longer be generated in 2021." + )] + pub const ENUM_MAX_LOCATION_LEVEL: i8 = 3; + #[deprecated( + since = "2.0.0", + note = "Use associated constants instead. This will no longer be generated in 2021." + )] + #[allow(non_camel_case_types)] + pub const ENUM_VALUES_LOCATION_LEVEL: [LocationLevel; 4] = [ + LocationLevel::unused, + LocationLevel::wide, + LocationLevel::approximate, + LocationLevel::precise, + ]; + + #[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Default)] + #[repr(transparent)] + pub struct LocationLevel(pub i8); + #[allow(non_upper_case_globals)] + impl LocationLevel { + pub const unused: Self = Self(0); + pub const wide: Self = Self(1); + pub const approximate: Self = Self(2); + pub const precise: Self = Self(3); + + pub const ENUM_MIN: i8 = 0; + pub const ENUM_MAX: i8 = 3; + pub const ENUM_VALUES: &'static [Self] = + &[Self::unused, Self::wide, Self::approximate, Self::precise]; + /// Returns the variant's name or "" if unknown. + pub fn variant_name(self) -> Option<&'static str> { + match self { + Self::unused => Some("unused"), + Self::wide => Some("wide"), + Self::approximate => Some("approximate"), + Self::precise => Some("precise"), + _ => None, + } + } + } + impl core::fmt::Debug for LocationLevel { + fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result { + if let Some(name) = self.variant_name() { + f.write_str(name) + } else { + f.write_fmt(format_args!("", self.0)) + } + } + } + impl<'a> flatbuffers::Follow<'a> for LocationLevel { + type Inner = Self; + #[inline] + unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { + let b = flatbuffers::read_scalar_at::(buf, loc); + Self(b) + } + } + + impl flatbuffers::Push for LocationLevel { + type Output = LocationLevel; + #[inline] + unsafe fn push(&self, dst: &mut [u8], _written_len: usize) { + flatbuffers::emplace_scalar::(dst, self.0); + } + } + + impl flatbuffers::EndianScalar for LocationLevel { + type Scalar = i8; + #[inline] + fn to_little_endian(self) -> i8 { + self.0.to_le() + } + #[inline] + #[allow(clippy::wrong_self_convention)] + fn from_little_endian(v: i8) -> Self { + let b = i8::from_le(v); + Self(b) + } + } + + impl<'a> flatbuffers::Verifiable for LocationLevel { + #[inline] + fn run_verifier( + v: &mut flatbuffers::Verifier, + pos: usize, + ) -> Result<(), flatbuffers::InvalidFlatbuffer> { + use self::flatbuffers::Verifiable; + i8::run_verifier(v, pos) + } + } + + impl flatbuffers::SimpleToVerifyInSlice for LocationLevel {} + #[deprecated( + since = "2.0.0", + note = "Use associated constants instead. This will no longer be generated in 2021." + )] + pub const ENUM_MIN_IDENTITY_ASSURANCE_LEVEL: i8 = 0; + #[deprecated( + since = "2.0.0", + note = "Use associated constants instead. This will no longer be generated in 2021." + )] + pub const ENUM_MAX_IDENTITY_ASSURANCE_LEVEL: i8 = 5; + #[deprecated( + since = "2.0.0", + note = "Use associated constants instead. This will no longer be generated in 2021." + )] + #[allow(non_camel_case_types)] + pub const ENUM_VALUES_IDENTITY_ASSURANCE_LEVEL: [IdentityAssuranceLevel; 6] = [ + IdentityAssuranceLevel::unused, + IdentityAssuranceLevel::ial0, + IdentityAssuranceLevel::ial1, + IdentityAssuranceLevel::ial2, + IdentityAssuranceLevel::ial25, + IdentityAssuranceLevel::ial3, + ]; + + #[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Default)] + #[repr(transparent)] + pub struct IdentityAssuranceLevel(pub i8); + #[allow(non_upper_case_globals)] + impl IdentityAssuranceLevel { + pub const unused: Self = Self(0); + pub const ial0: Self = Self(1); + pub const ial1: Self = Self(2); + pub const ial2: Self = Self(3); + pub const ial25: Self = Self(4); + pub const ial3: Self = Self(5); + + pub const ENUM_MIN: i8 = 0; + pub const ENUM_MAX: i8 = 5; + pub const ENUM_VALUES: &'static [Self] = &[ + Self::unused, + Self::ial0, + Self::ial1, + Self::ial2, + Self::ial25, + Self::ial3, + ]; + /// Returns the variant's name or "" if unknown. + pub fn variant_name(self) -> Option<&'static str> { + match self { + Self::unused => Some("unused"), + Self::ial0 => Some("ial0"), + Self::ial1 => Some("ial1"), + Self::ial2 => Some("ial2"), + Self::ial25 => Some("ial25"), + Self::ial3 => Some("ial3"), + _ => None, + } + } + } + impl core::fmt::Debug for IdentityAssuranceLevel { + fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result { + if let Some(name) = self.variant_name() { + f.write_str(name) + } else { + f.write_fmt(format_args!("", self.0)) + } + } + } + impl<'a> flatbuffers::Follow<'a> for IdentityAssuranceLevel { + type Inner = Self; + #[inline] + unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { + let b = flatbuffers::read_scalar_at::(buf, loc); + Self(b) + } + } + + impl flatbuffers::Push for IdentityAssuranceLevel { + type Output = IdentityAssuranceLevel; + #[inline] + unsafe fn push(&self, dst: &mut [u8], _written_len: usize) { + flatbuffers::emplace_scalar::(dst, self.0); + } + } + + impl flatbuffers::EndianScalar for IdentityAssuranceLevel { + type Scalar = i8; + #[inline] + fn to_little_endian(self) -> i8 { + self.0.to_le() + } + #[inline] + #[allow(clippy::wrong_self_convention)] + fn from_little_endian(v: i8) -> Self { + let b = i8::from_le(v); + Self(b) + } + } + + impl<'a> flatbuffers::Verifiable for IdentityAssuranceLevel { + #[inline] + fn run_verifier( + v: &mut flatbuffers::Verifier, + pos: usize, + ) -> Result<(), flatbuffers::InvalidFlatbuffer> { + use self::flatbuffers::Verifiable; + i8::run_verifier(v, pos) + } + } + + impl flatbuffers::SimpleToVerifyInSlice for IdentityAssuranceLevel {} + #[deprecated( + since = "2.0.0", + note = "Use associated constants instead. This will no longer be generated in 2021." + )] + pub const ENUM_MIN_ENCRYPTION_LEVEL: i8 = 0; + #[deprecated( + since = "2.0.0", + note = "Use associated constants instead. This will no longer be generated in 2021." + )] + pub const ENUM_MAX_ENCRYPTION_LEVEL: i8 = 3; + #[deprecated( + since = "2.0.0", + note = "Use associated constants instead. This will no longer be generated in 2021." + )] + #[allow(non_camel_case_types)] + pub const ENUM_VALUES_ENCRYPTION_LEVEL: [EncryptionLevel; 4] = [ + EncryptionLevel::unused, + EncryptionLevel::el0, + EncryptionLevel::el1, + EncryptionLevel::el2, + ]; + + #[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Default)] + #[repr(transparent)] + pub struct EncryptionLevel(pub i8); + #[allow(non_upper_case_globals)] + impl EncryptionLevel { + pub const unused: Self = Self(0); + pub const el0: Self = Self(1); + pub const el1: Self = Self(2); + pub const el2: Self = Self(3); + + pub const ENUM_MIN: i8 = 0; + pub const ENUM_MAX: i8 = 3; + pub const ENUM_VALUES: &'static [Self] = &[Self::unused, Self::el0, Self::el1, Self::el2]; + /// Returns the variant's name or "" if unknown. + pub fn variant_name(self) -> Option<&'static str> { + match self { + Self::unused => Some("unused"), + Self::el0 => Some("el0"), + Self::el1 => Some("el1"), + Self::el2 => Some("el2"), + _ => None, + } + } + } + impl core::fmt::Debug for EncryptionLevel { + fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result { + if let Some(name) = self.variant_name() { + f.write_str(name) + } else { + f.write_fmt(format_args!("", self.0)) + } + } + } + impl<'a> flatbuffers::Follow<'a> for EncryptionLevel { + type Inner = Self; + #[inline] + unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { + let b = flatbuffers::read_scalar_at::(buf, loc); + Self(b) + } + } + + impl flatbuffers::Push for EncryptionLevel { + type Output = EncryptionLevel; + #[inline] + unsafe fn push(&self, dst: &mut [u8], _written_len: usize) { + flatbuffers::emplace_scalar::(dst, self.0); + } + } + + impl flatbuffers::EndianScalar for EncryptionLevel { + type Scalar = i8; + #[inline] + fn to_little_endian(self) -> i8 { + self.0.to_le() + } + #[inline] + #[allow(clippy::wrong_self_convention)] + fn from_little_endian(v: i8) -> Self { + let b = i8::from_le(v); + Self(b) + } + } + + impl<'a> flatbuffers::Verifiable for EncryptionLevel { + #[inline] + fn run_verifier( + v: &mut flatbuffers::Verifier, + pos: usize, + ) -> Result<(), flatbuffers::InvalidFlatbuffer> { + use self::flatbuffers::Verifiable; + i8::run_verifier(v, pos) + } + } + + impl flatbuffers::SimpleToVerifyInSlice for EncryptionLevel {} + #[deprecated( + since = "2.0.0", + note = "Use associated constants instead. This will no longer be generated in 2021." + )] + pub const ENUM_MIN_STREAM_LEVEL: i8 = 0; + #[deprecated( + since = "2.0.0", + note = "Use associated constants instead. This will no longer be generated in 2021." + )] + pub const ENUM_MAX_STREAM_LEVEL: i8 = 3; + #[deprecated( + since = "2.0.0", + note = "Use associated constants instead. This will no longer be generated in 2021." + )] + #[allow(non_camel_case_types)] + pub const ENUM_VALUES_STREAM_LEVEL: [StreamLevel; 4] = [ + StreamLevel::unused, + StreamLevel::sl0, + StreamLevel::sl1, + StreamLevel::sl2, + ]; + + #[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Default)] + #[repr(transparent)] + pub struct StreamLevel(pub i8); + #[allow(non_upper_case_globals)] + impl StreamLevel { + pub const unused: Self = Self(0); + pub const sl0: Self = Self(1); + pub const sl1: Self = Self(2); + pub const sl2: Self = Self(3); + + pub const ENUM_MIN: i8 = 0; + pub const ENUM_MAX: i8 = 3; + pub const ENUM_VALUES: &'static [Self] = &[Self::unused, Self::sl0, Self::sl1, Self::sl2]; + /// Returns the variant's name or "" if unknown. + pub fn variant_name(self) -> Option<&'static str> { + match self { + Self::unused => Some("unused"), + Self::sl0 => Some("sl0"), + Self::sl1 => Some("sl1"), + Self::sl2 => Some("sl2"), + _ => None, + } + } + } + impl core::fmt::Debug for StreamLevel { + fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result { + if let Some(name) = self.variant_name() { + f.write_str(name) + } else { + f.write_fmt(format_args!("", self.0)) + } + } + } + impl<'a> flatbuffers::Follow<'a> for StreamLevel { + type Inner = Self; + #[inline] + unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { + let b = flatbuffers::read_scalar_at::(buf, loc); + Self(b) + } + } + + impl flatbuffers::Push for StreamLevel { + type Output = StreamLevel; + #[inline] + unsafe fn push(&self, dst: &mut [u8], _written_len: usize) { + flatbuffers::emplace_scalar::(dst, self.0); + } + } + + impl flatbuffers::EndianScalar for StreamLevel { + type Scalar = i8; + #[inline] + fn to_little_endian(self) -> i8 { + self.0.to_le() + } + #[inline] + #[allow(clippy::wrong_self_convention)] + fn from_little_endian(v: i8) -> Self { + let b = i8::from_le(v); + Self(b) + } + } + + impl<'a> flatbuffers::Verifiable for StreamLevel { + #[inline] + fn run_verifier( + v: &mut flatbuffers::Verifier, + pos: usize, + ) -> Result<(), flatbuffers::InvalidFlatbuffer> { + use self::flatbuffers::Verifiable; + i8::run_verifier(v, pos) + } + } + + impl flatbuffers::SimpleToVerifyInSlice for StreamLevel {} + #[deprecated( + since = "2.0.0", + note = "Use associated constants instead. This will no longer be generated in 2021." + )] + pub const ENUM_MIN_EXPERT_LEVEL: i8 = 0; + #[deprecated( + since = "2.0.0", + note = "Use associated constants instead. This will no longer be generated in 2021." + )] + pub const ENUM_MAX_EXPERT_LEVEL: i8 = 4; + #[deprecated( + since = "2.0.0", + note = "Use associated constants instead. This will no longer be generated in 2021." + )] + #[allow(non_camel_case_types)] + pub const ENUM_VALUES_EXPERT_LEVEL: [ExpertLevel; 5] = [ + ExpertLevel::unused, + ExpertLevel::novice, + ExpertLevel::intermediate, + ExpertLevel::expert, + ExpertLevel::master, + ]; + + #[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Default)] + #[repr(transparent)] + pub struct ExpertLevel(pub i8); + #[allow(non_upper_case_globals)] + impl ExpertLevel { + pub const unused: Self = Self(0); + pub const novice: Self = Self(1); + pub const intermediate: Self = Self(2); + pub const expert: Self = Self(3); + pub const master: Self = Self(4); + + pub const ENUM_MIN: i8 = 0; + pub const ENUM_MAX: i8 = 4; + pub const ENUM_VALUES: &'static [Self] = &[ + Self::unused, + Self::novice, + Self::intermediate, + Self::expert, + Self::master, + ]; + /// Returns the variant's name or "" if unknown. + pub fn variant_name(self) -> Option<&'static str> { + match self { + Self::unused => Some("unused"), + Self::novice => Some("novice"), + Self::intermediate => Some("intermediate"), + Self::expert => Some("expert"), + Self::master => Some("master"), + _ => None, + } + } + } + impl core::fmt::Debug for ExpertLevel { + fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result { + if let Some(name) = self.variant_name() { + f.write_str(name) + } else { + f.write_fmt(format_args!("", self.0)) + } + } + } + impl<'a> flatbuffers::Follow<'a> for ExpertLevel { + type Inner = Self; + #[inline] + unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { + let b = flatbuffers::read_scalar_at::(buf, loc); + Self(b) + } + } + + impl flatbuffers::Push for ExpertLevel { + type Output = ExpertLevel; + #[inline] + unsafe fn push(&self, dst: &mut [u8], _written_len: usize) { + flatbuffers::emplace_scalar::(dst, self.0); + } + } + + impl flatbuffers::EndianScalar for ExpertLevel { + type Scalar = i8; + #[inline] + fn to_little_endian(self) -> i8 { + self.0.to_le() + } + #[inline] + #[allow(clippy::wrong_self_convention)] + fn from_little_endian(v: i8) -> Self { + let b = i8::from_le(v); + Self(b) + } + } + + impl<'a> flatbuffers::Verifiable for ExpertLevel { + #[inline] + fn run_verifier( + v: &mut flatbuffers::Verifier, + pos: usize, + ) -> Result<(), flatbuffers::InvalidFlatbuffer> { + use self::flatbuffers::Verifiable; + i8::run_verifier(v, pos) + } + } + + impl flatbuffers::SimpleToVerifyInSlice for ExpertLevel {} + #[deprecated( + since = "2.0.0", + note = "Use associated constants instead. This will no longer be generated in 2021." + )] + pub const ENUM_MIN_TRUST_LEVEL: i8 = 0; + #[deprecated( + since = "2.0.0", + note = "Use associated constants instead. This will no longer be generated in 2021." + )] + pub const ENUM_MAX_TRUST_LEVEL: i8 = 5; + #[deprecated( + since = "2.0.0", + note = "Use associated constants instead. This will no longer be generated in 2021." + )] + #[allow(non_camel_case_types)] + pub const ENUM_VALUES_TRUST_LEVEL: [TrustLevel; 6] = [ + TrustLevel::unused, + TrustLevel::untrusted, + TrustLevel::low, + TrustLevel::medium, + TrustLevel::high, + TrustLevel::verified, + ]; + + #[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Default)] + #[repr(transparent)] + pub struct TrustLevel(pub i8); + #[allow(non_upper_case_globals)] + impl TrustLevel { + pub const unused: Self = Self(0); + pub const untrusted: Self = Self(1); + pub const low: Self = Self(2); + pub const medium: Self = Self(3); + pub const high: Self = Self(4); + pub const verified: Self = Self(5); + + pub const ENUM_MIN: i8 = 0; + pub const ENUM_MAX: i8 = 5; + pub const ENUM_VALUES: &'static [Self] = &[ + Self::unused, + Self::untrusted, + Self::low, + Self::medium, + Self::high, + Self::verified, + ]; + /// Returns the variant's name or "" if unknown. + pub fn variant_name(self) -> Option<&'static str> { + match self { + Self::unused => Some("unused"), + Self::untrusted => Some("untrusted"), + Self::low => Some("low"), + Self::medium => Some("medium"), + Self::high => Some("high"), + Self::verified => Some("verified"), + _ => None, + } + } + } + impl core::fmt::Debug for TrustLevel { + fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result { + if let Some(name) = self.variant_name() { + f.write_str(name) + } else { + f.write_fmt(format_args!("", self.0)) + } + } + } + impl<'a> flatbuffers::Follow<'a> for TrustLevel { + type Inner = Self; + #[inline] + unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { + let b = flatbuffers::read_scalar_at::(buf, loc); + Self(b) + } + } + + impl flatbuffers::Push for TrustLevel { + type Output = TrustLevel; + #[inline] + unsafe fn push(&self, dst: &mut [u8], _written_len: usize) { + flatbuffers::emplace_scalar::(dst, self.0); + } + } + + impl flatbuffers::EndianScalar for TrustLevel { + type Scalar = i8; + #[inline] + fn to_little_endian(self) -> i8 { + self.0.to_le() + } + #[inline] + #[allow(clippy::wrong_self_convention)] + fn from_little_endian(v: i8) -> Self { + let b = i8::from_le(v); + Self(b) + } + } + + impl<'a> flatbuffers::Verifiable for TrustLevel { + #[inline] + fn run_verifier( + v: &mut flatbuffers::Verifier, + pos: usize, + ) -> Result<(), flatbuffers::InvalidFlatbuffer> { + use self::flatbuffers::Verifiable; + i8::run_verifier(v, pos) + } + } + + impl flatbuffers::SimpleToVerifyInSlice for TrustLevel {} + #[deprecated( + since = "2.0.0", + note = "Use associated constants instead. This will no longer be generated in 2021." + )] + pub const ENUM_MIN_ENTITY: u8 = 0; + #[deprecated( + since = "2.0.0", + note = "Use associated constants instead. This will no longer be generated in 2021." + )] + pub const ENUM_MAX_ENTITY: u8 = 3; + #[deprecated( + since = "2.0.0", + note = "Use associated constants instead. This will no longer be generated in 2021." + )] + #[allow(non_camel_case_types)] + pub const ENUM_VALUES_ENTITY: [Entity; 4] = [ + Entity::NONE, + Entity::Account, + Entity::Stream, + Entity::Thought, + ]; + + #[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Default)] + #[repr(transparent)] + pub struct Entity(pub u8); + #[allow(non_upper_case_globals)] + impl Entity { + pub const NONE: Self = Self(0); + pub const Account: Self = Self(1); + pub const Stream: Self = Self(2); + pub const Thought: Self = Self(3); + + pub const ENUM_MIN: u8 = 0; + pub const ENUM_MAX: u8 = 3; + pub const ENUM_VALUES: &'static [Self] = + &[Self::NONE, Self::Account, Self::Stream, Self::Thought]; + /// Returns the variant's name or "" if unknown. + pub fn variant_name(self) -> Option<&'static str> { + match self { + Self::NONE => Some("NONE"), + Self::Account => Some("Account"), + Self::Stream => Some("Stream"), + Self::Thought => Some("Thought"), + _ => None, + } + } + } + impl core::fmt::Debug for Entity { + fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result { + if let Some(name) = self.variant_name() { + f.write_str(name) + } else { + f.write_fmt(format_args!("", self.0)) + } + } + } + impl<'a> flatbuffers::Follow<'a> for Entity { + type Inner = Self; + #[inline] + unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { + let b = flatbuffers::read_scalar_at::(buf, loc); + Self(b) + } + } + + impl flatbuffers::Push for Entity { + type Output = Entity; + #[inline] + unsafe fn push(&self, dst: &mut [u8], _written_len: usize) { + flatbuffers::emplace_scalar::(dst, self.0); + } + } + + impl flatbuffers::EndianScalar for Entity { + type Scalar = u8; + #[inline] + fn to_little_endian(self) -> u8 { + self.0.to_le() + } + #[inline] + #[allow(clippy::wrong_self_convention)] + fn from_little_endian(v: u8) -> Self { + let b = u8::from_le(v); + Self(b) + } + } + + impl<'a> flatbuffers::Verifiable for Entity { + #[inline] + fn run_verifier( + v: &mut flatbuffers::Verifier, + pos: usize, + ) -> Result<(), flatbuffers::InvalidFlatbuffer> { + use self::flatbuffers::Verifiable; + u8::run_verifier(v, pos) + } + } + + impl flatbuffers::SimpleToVerifyInSlice for Entity {} + pub struct EntityUnionTableOffset {} + + pub enum PublicIdOffset {} + #[derive(Copy, Clone, PartialEq)] + + pub struct PublicId<'a> { + pub _tab: flatbuffers::Table<'a>, + } + + impl<'a> flatbuffers::Follow<'a> for PublicId<'a> { + type Inner = PublicId<'a>; + #[inline] + unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { + Self { + _tab: flatbuffers::Table::new(buf, loc), + } + } + } + + impl<'a> PublicId<'a> { + pub const VT_ID: flatbuffers::VOffsetT = 4; + + #[inline] + pub unsafe fn init_from_table(table: flatbuffers::Table<'a>) -> Self { + PublicId { _tab: table } + } + #[allow(unused_mut)] + pub fn create< + 'bldr: 'args, + 'args: 'mut_bldr, + 'mut_bldr, + A: flatbuffers::Allocator + 'bldr, + >( + _fbb: &'mut_bldr mut flatbuffers::FlatBufferBuilder<'bldr, A>, + args: &'args PublicIdArgs<'args>, + ) -> flatbuffers::WIPOffset> { + let mut builder = PublicIdBuilder::new(_fbb); + if let Some(x) = args.id { + builder.add_id(x); + } + builder.finish() + } + + #[inline] + pub fn id(&self) -> Option> { + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { + self._tab + .get::>>( + PublicId::VT_ID, + None, + ) + } + } + } + + impl flatbuffers::Verifiable for PublicId<'_> { + #[inline] + fn run_verifier( + v: &mut flatbuffers::Verifier, + pos: usize, + ) -> Result<(), flatbuffers::InvalidFlatbuffer> { + use self::flatbuffers::Verifiable; + v.visit_table(pos)? + .visit_field::>>( + "id", + Self::VT_ID, + false, + )? + .finish(); + Ok(()) + } + } + pub struct PublicIdArgs<'a> { + pub id: Option>>, + } + impl<'a> Default for PublicIdArgs<'a> { + #[inline] + fn default() -> Self { + PublicIdArgs { id: None } + } + } + + pub struct PublicIdBuilder<'a: 'b, 'b, A: flatbuffers::Allocator + 'a> { + fbb_: &'b mut flatbuffers::FlatBufferBuilder<'a, A>, + start_: flatbuffers::WIPOffset, + } + impl<'a: 'b, 'b, A: flatbuffers::Allocator + 'a> PublicIdBuilder<'a, 'b, A> { + #[inline] + pub fn add_id(&mut self, id: flatbuffers::WIPOffset>) { + self.fbb_ + .push_slot_always::>(PublicId::VT_ID, id); + } + #[inline] + pub fn new( + _fbb: &'b mut flatbuffers::FlatBufferBuilder<'a, A>, + ) -> PublicIdBuilder<'a, 'b, A> { + let start = _fbb.start_table(); + PublicIdBuilder { + fbb_: _fbb, + start_: start, + } + } + #[inline] + pub fn finish(self) -> flatbuffers::WIPOffset> { + let o = self.fbb_.end_table(self.start_); + flatbuffers::WIPOffset::new(o.value()) + } + } + + impl core::fmt::Debug for PublicId<'_> { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + let mut ds = f.debug_struct("PublicId"); + ds.field("id", &self.id()); + ds.finish() + } + } + pub enum AccountOffset {} + #[derive(Copy, Clone, PartialEq)] + + pub struct Account<'a> { + pub _tab: flatbuffers::Table<'a>, + } + + impl<'a> flatbuffers::Follow<'a> for Account<'a> { + type Inner = Account<'a>; + #[inline] + unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { + Self { + _tab: flatbuffers::Table::new(buf, loc), + } + } + } + + impl<'a> Account<'a> { + pub const VT_PUBLIC_ID: flatbuffers::VOffsetT = 4; + pub const VT_PROFILE: flatbuffers::VOffsetT = 6; + pub const VT_ACTIVITY: flatbuffers::VOffsetT = 8; + + #[inline] + pub unsafe fn init_from_table(table: flatbuffers::Table<'a>) -> Self { + Account { _tab: table } + } + #[allow(unused_mut)] + pub fn create< + 'bldr: 'args, + 'args: 'mut_bldr, + 'mut_bldr, + A: flatbuffers::Allocator + 'bldr, + >( + _fbb: &'mut_bldr mut flatbuffers::FlatBufferBuilder<'bldr, A>, + args: &'args AccountArgs<'args>, + ) -> flatbuffers::WIPOffset> { + let mut builder = AccountBuilder::new(_fbb); + if let Some(x) = args.activity { + builder.add_activity(x); + } + if let Some(x) = args.profile { + builder.add_profile(x); + } + if let Some(x) = args.public_id { + builder.add_public_id(x); + } + builder.finish() + } + + #[inline] + pub fn public_id(&self) -> Option> { + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { + self._tab + .get::>(Account::VT_PUBLIC_ID, None) + } + } + #[inline] + pub fn profile(&self) -> Option> { + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { + self._tab + .get::>(Account::VT_PROFILE, None) + } + } + #[inline] + pub fn activity(&self) -> Option> { + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { + self._tab + .get::>(Account::VT_ACTIVITY, None) + } + } + } + + impl flatbuffers::Verifiable for Account<'_> { + #[inline] + fn run_verifier( + v: &mut flatbuffers::Verifier, + pos: usize, + ) -> Result<(), flatbuffers::InvalidFlatbuffer> { + use self::flatbuffers::Verifiable; + v.visit_table(pos)? + .visit_field::>( + "public_id", + Self::VT_PUBLIC_ID, + false, + )? + .visit_field::>( + "profile", + Self::VT_PROFILE, + false, + )? + .visit_field::>( + "activity", + Self::VT_ACTIVITY, + false, + )? + .finish(); + Ok(()) + } + } + pub struct AccountArgs<'a> { + pub public_id: Option>>, + pub profile: Option>>, + pub activity: Option>>, + } + impl<'a> Default for AccountArgs<'a> { + #[inline] + fn default() -> Self { + AccountArgs { + public_id: None, + profile: None, + activity: None, + } + } + } + + pub struct AccountBuilder<'a: 'b, 'b, A: flatbuffers::Allocator + 'a> { + fbb_: &'b mut flatbuffers::FlatBufferBuilder<'a, A>, + start_: flatbuffers::WIPOffset, + } + impl<'a: 'b, 'b, A: flatbuffers::Allocator + 'a> AccountBuilder<'a, 'b, A> { + #[inline] + pub fn add_public_id(&mut self, public_id: flatbuffers::WIPOffset>) { + self.fbb_ + .push_slot_always::>( + Account::VT_PUBLIC_ID, + public_id, + ); + } + #[inline] + pub fn add_profile(&mut self, profile: flatbuffers::WIPOffset>) { + self.fbb_ + .push_slot_always::>(Account::VT_PROFILE, profile); + } + #[inline] + pub fn add_activity(&mut self, activity: flatbuffers::WIPOffset>) { + self.fbb_ + .push_slot_always::>( + Account::VT_ACTIVITY, + activity, + ); + } + #[inline] + pub fn new( + _fbb: &'b mut flatbuffers::FlatBufferBuilder<'a, A>, + ) -> AccountBuilder<'a, 'b, A> { + let start = _fbb.start_table(); + AccountBuilder { + fbb_: _fbb, + start_: start, + } + } + #[inline] + pub fn finish(self) -> flatbuffers::WIPOffset> { + let o = self.fbb_.end_table(self.start_); + flatbuffers::WIPOffset::new(o.value()) + } + } + + impl core::fmt::Debug for Account<'_> { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + let mut ds = f.debug_struct("Account"); + ds.field("public_id", &self.public_id()); + ds.field("profile", &self.profile()); + ds.field("activity", &self.activity()); + ds.finish() + } + } + pub enum StreamOffset {} + #[derive(Copy, Clone, PartialEq)] + + pub struct Stream<'a> { + pub _tab: flatbuffers::Table<'a>, + } + + impl<'a> flatbuffers::Follow<'a> for Stream<'a> { + type Inner = Stream<'a>; + #[inline] + unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { + Self { + _tab: flatbuffers::Table::new(buf, loc), + } + } + } + + impl<'a> Stream<'a> { + pub const VT_PUBLIC_ID: flatbuffers::VOffsetT = 4; + pub const VT_PROFILE: flatbuffers::VOffsetT = 6; + pub const VT_ACTIVITY: flatbuffers::VOffsetT = 8; + pub const VT_CREATOR_PUBLIC_ID: flatbuffers::VOffsetT = 10; + pub const VT_MEMBERS_PUBLIC_ID: flatbuffers::VOffsetT = 12; + pub const VT_STREAM_LEVEL: flatbuffers::VOffsetT = 14; + + #[inline] + pub unsafe fn init_from_table(table: flatbuffers::Table<'a>) -> Self { + Stream { _tab: table } + } + #[allow(unused_mut)] + pub fn create< + 'bldr: 'args, + 'args: 'mut_bldr, + 'mut_bldr, + A: flatbuffers::Allocator + 'bldr, + >( + _fbb: &'mut_bldr mut flatbuffers::FlatBufferBuilder<'bldr, A>, + args: &'args StreamArgs<'args>, + ) -> flatbuffers::WIPOffset> { + let mut builder = StreamBuilder::new(_fbb); + if let Some(x) = args.members_public_id { + builder.add_members_public_id(x); + } + if let Some(x) = args.creator_public_id { + builder.add_creator_public_id(x); + } + if let Some(x) = args.activity { + builder.add_activity(x); + } + if let Some(x) = args.profile { + builder.add_profile(x); + } + if let Some(x) = args.public_id { + builder.add_public_id(x); + } + builder.add_stream_level(args.stream_level); + builder.finish() + } + + #[inline] + pub fn public_id(&self) -> Option> { + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { + self._tab + .get::>(Stream::VT_PUBLIC_ID, None) + } + } + #[inline] + pub fn profile(&self) -> Option> { + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { + self._tab + .get::>(Stream::VT_PROFILE, None) + } + } + #[inline] + pub fn activity(&self) -> Option> { + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { + self._tab + .get::>(Stream::VT_ACTIVITY, None) + } + } + #[inline] + pub fn creator_public_id(&self) -> Option> { + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { + self._tab.get::>( + Stream::VT_CREATOR_PUBLIC_ID, + None, + ) + } + } + #[inline] + pub fn members_public_id( + &self, + ) -> Option>>> { + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { + self._tab.get::>, + >>(Stream::VT_MEMBERS_PUBLIC_ID, None) + } + } + #[inline] + pub fn stream_level(&self) -> StreamLevel { + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { + self._tab + .get::(Stream::VT_STREAM_LEVEL, Some(StreamLevel::unused)) + .unwrap() + } + } + } + + impl flatbuffers::Verifiable for Stream<'_> { + #[inline] + fn run_verifier( + v: &mut flatbuffers::Verifier, + pos: usize, + ) -> Result<(), flatbuffers::InvalidFlatbuffer> { + use self::flatbuffers::Verifiable; + v.visit_table(pos)? + .visit_field::>( + "public_id", + Self::VT_PUBLIC_ID, + false, + )? + .visit_field::>( + "profile", + Self::VT_PROFILE, + false, + )? + .visit_field::>( + "activity", + Self::VT_ACTIVITY, + false, + )? + .visit_field::>( + "creator_public_id", + Self::VT_CREATOR_PUBLIC_ID, + false, + )? + .visit_field::>, + >>("members_public_id", Self::VT_MEMBERS_PUBLIC_ID, false)? + .visit_field::("stream_level", Self::VT_STREAM_LEVEL, false)? + .finish(); + Ok(()) + } + } + pub struct StreamArgs<'a> { + pub public_id: Option>>, + pub profile: Option>>, + pub activity: Option>>, + pub creator_public_id: Option>>, + pub members_public_id: Option< + flatbuffers::WIPOffset< + flatbuffers::Vector<'a, flatbuffers::ForwardsUOffset>>, + >, + >, + pub stream_level: StreamLevel, + } + impl<'a> Default for StreamArgs<'a> { + #[inline] + fn default() -> Self { + StreamArgs { + public_id: None, + profile: None, + activity: None, + creator_public_id: None, + members_public_id: None, + stream_level: StreamLevel::unused, + } + } + } + + pub struct StreamBuilder<'a: 'b, 'b, A: flatbuffers::Allocator + 'a> { + fbb_: &'b mut flatbuffers::FlatBufferBuilder<'a, A>, + start_: flatbuffers::WIPOffset, + } + impl<'a: 'b, 'b, A: flatbuffers::Allocator + 'a> StreamBuilder<'a, 'b, A> { + #[inline] + pub fn add_public_id(&mut self, public_id: flatbuffers::WIPOffset>) { + self.fbb_ + .push_slot_always::>( + Stream::VT_PUBLIC_ID, + public_id, + ); + } + #[inline] + pub fn add_profile(&mut self, profile: flatbuffers::WIPOffset>) { + self.fbb_ + .push_slot_always::>(Stream::VT_PROFILE, profile); + } + #[inline] + pub fn add_activity(&mut self, activity: flatbuffers::WIPOffset>) { + self.fbb_ + .push_slot_always::>( + Stream::VT_ACTIVITY, + activity, + ); + } + #[inline] + pub fn add_creator_public_id( + &mut self, + creator_public_id: flatbuffers::WIPOffset>, + ) { + self.fbb_ + .push_slot_always::>( + Stream::VT_CREATOR_PUBLIC_ID, + creator_public_id, + ); + } + #[inline] + pub fn add_members_public_id( + &mut self, + members_public_id: flatbuffers::WIPOffset< + flatbuffers::Vector<'b, flatbuffers::ForwardsUOffset>>, + >, + ) { + self.fbb_.push_slot_always::>( + Stream::VT_MEMBERS_PUBLIC_ID, + members_public_id, + ); + } + #[inline] + pub fn add_stream_level(&mut self, stream_level: StreamLevel) { + self.fbb_.push_slot::( + Stream::VT_STREAM_LEVEL, + stream_level, + StreamLevel::unused, + ); + } + #[inline] + pub fn new( + _fbb: &'b mut flatbuffers::FlatBufferBuilder<'a, A>, + ) -> StreamBuilder<'a, 'b, A> { + let start = _fbb.start_table(); + StreamBuilder { + fbb_: _fbb, + start_: start, + } + } + #[inline] + pub fn finish(self) -> flatbuffers::WIPOffset> { + let o = self.fbb_.end_table(self.start_); + flatbuffers::WIPOffset::new(o.value()) + } + } + + impl core::fmt::Debug for Stream<'_> { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + let mut ds = f.debug_struct("Stream"); + ds.field("public_id", &self.public_id()); + ds.field("profile", &self.profile()); + ds.field("activity", &self.activity()); + ds.field("creator_public_id", &self.creator_public_id()); + ds.field("members_public_id", &self.members_public_id()); + ds.field("stream_level", &self.stream_level()); + ds.finish() + } + } + pub enum ThoughtOffset {} + #[derive(Copy, Clone, PartialEq)] + + pub struct Thought<'a> { + pub _tab: flatbuffers::Table<'a>, + } + + impl<'a> flatbuffers::Follow<'a> for Thought<'a> { + type Inner = Thought<'a>; + #[inline] + unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { + Self { + _tab: flatbuffers::Table::new(buf, loc), + } + } + } + + impl<'a> Thought<'a> { + pub const VT_PUBLIC_ID: flatbuffers::VOffsetT = 4; + pub const VT_CREATOR_PUBLIC_ID: flatbuffers::VOffsetT = 6; + pub const VT_STREAM_PUBLIC_ID: flatbuffers::VOffsetT = 8; + pub const VT_CONTENT: flatbuffers::VOffsetT = 10; + pub const VT_MEDIA_TYPE: flatbuffers::VOffsetT = 12; + + #[inline] + pub unsafe fn init_from_table(table: flatbuffers::Table<'a>) -> Self { + Thought { _tab: table } + } + #[allow(unused_mut)] + pub fn create< + 'bldr: 'args, + 'args: 'mut_bldr, + 'mut_bldr, + A: flatbuffers::Allocator + 'bldr, + >( + _fbb: &'mut_bldr mut flatbuffers::FlatBufferBuilder<'bldr, A>, + args: &'args ThoughtArgs<'args>, + ) -> flatbuffers::WIPOffset> { + let mut builder = ThoughtBuilder::new(_fbb); + if let Some(x) = args.content { + builder.add_content(x); + } + if let Some(x) = args.stream_public_id { + builder.add_stream_public_id(x); + } + if let Some(x) = args.creator_public_id { + builder.add_creator_public_id(x); + } + if let Some(x) = args.public_id { + builder.add_public_id(x); + } + builder.add_media_type(args.media_type); + builder.finish() + } + + #[inline] + pub fn public_id(&self) -> Option> { + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { + self._tab + .get::>(Thought::VT_PUBLIC_ID, None) + } + } + #[inline] + pub fn creator_public_id(&self) -> Option> { + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { + self._tab.get::>( + Thought::VT_CREATOR_PUBLIC_ID, + None, + ) + } + } + #[inline] + pub fn stream_public_id(&self) -> Option> { + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { + self._tab.get::>( + Thought::VT_STREAM_PUBLIC_ID, + None, + ) + } + } + #[inline] + pub fn content(&self) -> Option> { + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { + self._tab + .get::>>( + Thought::VT_CONTENT, + None, + ) + } + } + #[inline] + pub fn media_type(&self) -> MediaType { + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { + self._tab + .get::(Thought::VT_MEDIA_TYPE, Some(MediaType::unused)) + .unwrap() + } + } + } + + impl flatbuffers::Verifiable for Thought<'_> { + #[inline] + fn run_verifier( + v: &mut flatbuffers::Verifier, + pos: usize, + ) -> Result<(), flatbuffers::InvalidFlatbuffer> { + use self::flatbuffers::Verifiable; + v.visit_table(pos)? + .visit_field::>( + "public_id", + Self::VT_PUBLIC_ID, + false, + )? + .visit_field::>( + "creator_public_id", + Self::VT_CREATOR_PUBLIC_ID, + false, + )? + .visit_field::>( + "stream_public_id", + Self::VT_STREAM_PUBLIC_ID, + false, + )? + .visit_field::>>( + "content", + Self::VT_CONTENT, + false, + )? + .visit_field::("media_type", Self::VT_MEDIA_TYPE, false)? + .finish(); + Ok(()) + } + } + pub struct ThoughtArgs<'a> { + pub public_id: Option>>, + pub creator_public_id: Option>>, + pub stream_public_id: Option>>, + pub content: Option>>, + pub media_type: MediaType, + } + impl<'a> Default for ThoughtArgs<'a> { + #[inline] + fn default() -> Self { + ThoughtArgs { + public_id: None, + creator_public_id: None, + stream_public_id: None, + content: None, + media_type: MediaType::unused, + } + } + } + + pub struct ThoughtBuilder<'a: 'b, 'b, A: flatbuffers::Allocator + 'a> { + fbb_: &'b mut flatbuffers::FlatBufferBuilder<'a, A>, + start_: flatbuffers::WIPOffset, + } + impl<'a: 'b, 'b, A: flatbuffers::Allocator + 'a> ThoughtBuilder<'a, 'b, A> { + #[inline] + pub fn add_public_id(&mut self, public_id: flatbuffers::WIPOffset>) { + self.fbb_ + .push_slot_always::>( + Thought::VT_PUBLIC_ID, + public_id, + ); + } + #[inline] + pub fn add_creator_public_id( + &mut self, + creator_public_id: flatbuffers::WIPOffset>, + ) { + self.fbb_ + .push_slot_always::>( + Thought::VT_CREATOR_PUBLIC_ID, + creator_public_id, + ); + } + #[inline] + pub fn add_stream_public_id( + &mut self, + stream_public_id: flatbuffers::WIPOffset>, + ) { + self.fbb_ + .push_slot_always::>( + Thought::VT_STREAM_PUBLIC_ID, + stream_public_id, + ); + } + #[inline] + pub fn add_content( + &mut self, + content: flatbuffers::WIPOffset>, + ) { + self.fbb_ + .push_slot_always::>(Thought::VT_CONTENT, content); + } + #[inline] + pub fn add_media_type(&mut self, media_type: MediaType) { + self.fbb_ + .push_slot::(Thought::VT_MEDIA_TYPE, media_type, MediaType::unused); + } + #[inline] + pub fn new( + _fbb: &'b mut flatbuffers::FlatBufferBuilder<'a, A>, + ) -> ThoughtBuilder<'a, 'b, A> { + let start = _fbb.start_table(); + ThoughtBuilder { + fbb_: _fbb, + start_: start, + } + } + #[inline] + pub fn finish(self) -> flatbuffers::WIPOffset> { + let o = self.fbb_.end_table(self.start_); + flatbuffers::WIPOffset::new(o.value()) + } + } + + impl core::fmt::Debug for Thought<'_> { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + let mut ds = f.debug_struct("Thought"); + ds.field("public_id", &self.public_id()); + ds.field("creator_public_id", &self.creator_public_id()); + ds.field("stream_public_id", &self.stream_public_id()); + ds.field("content", &self.content()); + ds.field("media_type", &self.media_type()); + ds.finish() + } + } + pub enum ProfileOffset {} + #[derive(Copy, Clone, PartialEq)] + + pub struct Profile<'a> { + pub _tab: flatbuffers::Table<'a>, + } + + impl<'a> flatbuffers::Follow<'a> for Profile<'a> { + type Inner = Profile<'a>; + #[inline] + unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { + Self { + _tab: flatbuffers::Table::new(buf, loc), + } + } + } + + impl<'a> Profile<'a> { + pub const VT_NAME: flatbuffers::VOffsetT = 4; + pub const VT_BLURB: flatbuffers::VOffsetT = 6; + pub const VT_INTERESTS: flatbuffers::VOffsetT = 8; + pub const VT_LOCATION: flatbuffers::VOffsetT = 10; + pub const VT_LOCATION_LEVEL: flatbuffers::VOffsetT = 12; + pub const VT_IDENTITY_ASSURANCE_LEVEL: flatbuffers::VOffsetT = 14; + pub const VT_ENCRYPTION_LEVEL: flatbuffers::VOffsetT = 16; + + #[inline] + pub unsafe fn init_from_table(table: flatbuffers::Table<'a>) -> Self { + Profile { _tab: table } + } + #[allow(unused_mut)] + pub fn create< + 'bldr: 'args, + 'args: 'mut_bldr, + 'mut_bldr, + A: flatbuffers::Allocator + 'bldr, + >( + _fbb: &'mut_bldr mut flatbuffers::FlatBufferBuilder<'bldr, A>, + args: &'args ProfileArgs<'args>, + ) -> flatbuffers::WIPOffset> { + let mut builder = ProfileBuilder::new(_fbb); + if let Some(x) = args.location { + builder.add_location(x); + } + if let Some(x) = args.interests { + builder.add_interests(x); + } + if let Some(x) = args.blurb { + builder.add_blurb(x); + } + if let Some(x) = args.name { + builder.add_name(x); + } + builder.add_encryption_level(args.encryption_level); + builder.add_identity_assurance_level(args.identity_assurance_level); + builder.add_location_level(args.location_level); + builder.finish() + } + + #[inline] + pub fn name(&self) -> Option<&'a str> { + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { + self._tab + .get::>(Profile::VT_NAME, None) + } + } + #[inline] + pub fn blurb(&self) -> Option<&'a str> { + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { + self._tab + .get::>(Profile::VT_BLURB, None) + } + } + #[inline] + pub fn interests(&self) -> Option<&'a str> { + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { + self._tab + .get::>(Profile::VT_INTERESTS, None) + } + } + #[inline] + pub fn location(&self) -> Option<&'a str> { + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { + self._tab + .get::>(Profile::VT_LOCATION, None) + } + } + #[inline] + pub fn location_level(&self) -> LocationLevel { + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { + self._tab + .get::(Profile::VT_LOCATION_LEVEL, Some(LocationLevel::unused)) + .unwrap() + } + } + #[inline] + pub fn identity_assurance_level(&self) -> IdentityAssuranceLevel { + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { + self._tab + .get::( + Profile::VT_IDENTITY_ASSURANCE_LEVEL, + Some(IdentityAssuranceLevel::unused), + ) + .unwrap() + } + } + #[inline] + pub fn encryption_level(&self) -> EncryptionLevel { + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { + self._tab + .get::( + Profile::VT_ENCRYPTION_LEVEL, + Some(EncryptionLevel::unused), + ) + .unwrap() + } + } + } + + impl flatbuffers::Verifiable for Profile<'_> { + #[inline] + fn run_verifier( + v: &mut flatbuffers::Verifier, + pos: usize, + ) -> Result<(), flatbuffers::InvalidFlatbuffer> { + use self::flatbuffers::Verifiable; + v.visit_table(pos)? + .visit_field::>("name", Self::VT_NAME, false)? + .visit_field::>("blurb", Self::VT_BLURB, false)? + .visit_field::>( + "interests", + Self::VT_INTERESTS, + false, + )? + .visit_field::>( + "location", + Self::VT_LOCATION, + false, + )? + .visit_field::("location_level", Self::VT_LOCATION_LEVEL, false)? + .visit_field::( + "identity_assurance_level", + Self::VT_IDENTITY_ASSURANCE_LEVEL, + false, + )? + .visit_field::( + "encryption_level", + Self::VT_ENCRYPTION_LEVEL, + false, + )? + .finish(); + Ok(()) + } + } + pub struct ProfileArgs<'a> { + pub name: Option>, + pub blurb: Option>, + pub interests: Option>, + pub location: Option>, + pub location_level: LocationLevel, + pub identity_assurance_level: IdentityAssuranceLevel, + pub encryption_level: EncryptionLevel, + } + impl<'a> Default for ProfileArgs<'a> { + #[inline] + fn default() -> Self { + ProfileArgs { + name: None, + blurb: None, + interests: None, + location: None, + location_level: LocationLevel::unused, + identity_assurance_level: IdentityAssuranceLevel::unused, + encryption_level: EncryptionLevel::unused, + } + } + } + + pub struct ProfileBuilder<'a: 'b, 'b, A: flatbuffers::Allocator + 'a> { + fbb_: &'b mut flatbuffers::FlatBufferBuilder<'a, A>, + start_: flatbuffers::WIPOffset, + } + impl<'a: 'b, 'b, A: flatbuffers::Allocator + 'a> ProfileBuilder<'a, 'b, A> { + #[inline] + pub fn add_name(&mut self, name: flatbuffers::WIPOffset<&'b str>) { + self.fbb_ + .push_slot_always::>(Profile::VT_NAME, name); + } + #[inline] + pub fn add_blurb(&mut self, blurb: flatbuffers::WIPOffset<&'b str>) { + self.fbb_ + .push_slot_always::>(Profile::VT_BLURB, blurb); + } + #[inline] + pub fn add_interests(&mut self, interests: flatbuffers::WIPOffset<&'b str>) { + self.fbb_ + .push_slot_always::>(Profile::VT_INTERESTS, interests); + } + #[inline] + pub fn add_location(&mut self, location: flatbuffers::WIPOffset<&'b str>) { + self.fbb_ + .push_slot_always::>(Profile::VT_LOCATION, location); + } + #[inline] + pub fn add_location_level(&mut self, location_level: LocationLevel) { + self.fbb_.push_slot::( + Profile::VT_LOCATION_LEVEL, + location_level, + LocationLevel::unused, + ); + } + #[inline] + pub fn add_identity_assurance_level( + &mut self, + identity_assurance_level: IdentityAssuranceLevel, + ) { + self.fbb_.push_slot::( + Profile::VT_IDENTITY_ASSURANCE_LEVEL, + identity_assurance_level, + IdentityAssuranceLevel::unused, + ); + } + #[inline] + pub fn add_encryption_level(&mut self, encryption_level: EncryptionLevel) { + self.fbb_.push_slot::( + Profile::VT_ENCRYPTION_LEVEL, + encryption_level, + EncryptionLevel::unused, + ); + } + #[inline] + pub fn new( + _fbb: &'b mut flatbuffers::FlatBufferBuilder<'a, A>, + ) -> ProfileBuilder<'a, 'b, A> { + let start = _fbb.start_table(); + ProfileBuilder { + fbb_: _fbb, + start_: start, + } + } + #[inline] + pub fn finish(self) -> flatbuffers::WIPOffset> { + let o = self.fbb_.end_table(self.start_); + flatbuffers::WIPOffset::new(o.value()) + } + } + + impl core::fmt::Debug for Profile<'_> { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + let mut ds = f.debug_struct("Profile"); + ds.field("name", &self.name()); + ds.field("blurb", &self.blurb()); + ds.field("interests", &self.interests()); + ds.field("location", &self.location()); + ds.field("location_level", &self.location_level()); + ds.field("identity_assurance_level", &self.identity_assurance_level()); + ds.field("encryption_level", &self.encryption_level()); + ds.finish() + } + } + pub enum ActivityOffset {} + #[derive(Copy, Clone, PartialEq)] + + pub struct Activity<'a> { + pub _tab: flatbuffers::Table<'a>, + } + + impl<'a> flatbuffers::Follow<'a> for Activity<'a> { + type Inner = Activity<'a>; + #[inline] + unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { + Self { + _tab: flatbuffers::Table::new(buf, loc), + } + } + } + + impl<'a> Activity<'a> { + pub const VT_DATE_CREATED: flatbuffers::VOffsetT = 4; + pub const VT_EXPERT_LEVEL: flatbuffers::VOffsetT = 6; + pub const VT_ACTIVITY_LEVEL: flatbuffers::VOffsetT = 8; + pub const VT_TRUST_LEVEL: flatbuffers::VOffsetT = 10; + + #[inline] + pub unsafe fn init_from_table(table: flatbuffers::Table<'a>) -> Self { + Activity { _tab: table } + } + #[allow(unused_mut)] + pub fn create< + 'bldr: 'args, + 'args: 'mut_bldr, + 'mut_bldr, + A: flatbuffers::Allocator + 'bldr, + >( + _fbb: &'mut_bldr mut flatbuffers::FlatBufferBuilder<'bldr, A>, + args: &'args ActivityArgs, + ) -> flatbuffers::WIPOffset> { + let mut builder = ActivityBuilder::new(_fbb); + builder.add_date_created(args.date_created); + builder.add_trust_level(args.trust_level); + builder.add_activity_level(args.activity_level); + builder.add_expert_level(args.expert_level); + builder.finish() + } + + #[inline] + pub fn date_created(&self) -> i64 { + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { + self._tab + .get::(Activity::VT_DATE_CREATED, Some(0)) + .unwrap() + } + } + #[inline] + pub fn expert_level(&self) -> ExpertLevel { + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { + self._tab + .get::(Activity::VT_EXPERT_LEVEL, Some(ExpertLevel::unused)) + .unwrap() + } + } + #[inline] + pub fn activity_level(&self) -> ActivityLevel { + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { + self._tab + .get::(Activity::VT_ACTIVITY_LEVEL, Some(ActivityLevel::unused)) + .unwrap() + } + } + #[inline] + pub fn trust_level(&self) -> TrustLevel { + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { + self._tab + .get::(Activity::VT_TRUST_LEVEL, Some(TrustLevel::unused)) + .unwrap() + } + } + } + + impl flatbuffers::Verifiable for Activity<'_> { + #[inline] + fn run_verifier( + v: &mut flatbuffers::Verifier, + pos: usize, + ) -> Result<(), flatbuffers::InvalidFlatbuffer> { + use self::flatbuffers::Verifiable; + v.visit_table(pos)? + .visit_field::("date_created", Self::VT_DATE_CREATED, false)? + .visit_field::("expert_level", Self::VT_EXPERT_LEVEL, false)? + .visit_field::("activity_level", Self::VT_ACTIVITY_LEVEL, false)? + .visit_field::("trust_level", Self::VT_TRUST_LEVEL, false)? + .finish(); + Ok(()) + } + } + pub struct ActivityArgs { + pub date_created: i64, + pub expert_level: ExpertLevel, + pub activity_level: ActivityLevel, + pub trust_level: TrustLevel, + } + impl<'a> Default for ActivityArgs { + #[inline] + fn default() -> Self { + ActivityArgs { + date_created: 0, + expert_level: ExpertLevel::unused, + activity_level: ActivityLevel::unused, + trust_level: TrustLevel::unused, + } + } + } + + pub struct ActivityBuilder<'a: 'b, 'b, A: flatbuffers::Allocator + 'a> { + fbb_: &'b mut flatbuffers::FlatBufferBuilder<'a, A>, + start_: flatbuffers::WIPOffset, + } + impl<'a: 'b, 'b, A: flatbuffers::Allocator + 'a> ActivityBuilder<'a, 'b, A> { + #[inline] + pub fn add_date_created(&mut self, date_created: i64) { + self.fbb_ + .push_slot::(Activity::VT_DATE_CREATED, date_created, 0); + } + #[inline] + pub fn add_expert_level(&mut self, expert_level: ExpertLevel) { + self.fbb_.push_slot::( + Activity::VT_EXPERT_LEVEL, + expert_level, + ExpertLevel::unused, + ); + } + #[inline] + pub fn add_activity_level(&mut self, activity_level: ActivityLevel) { + self.fbb_.push_slot::( + Activity::VT_ACTIVITY_LEVEL, + activity_level, + ActivityLevel::unused, + ); + } + #[inline] + pub fn add_trust_level(&mut self, trust_level: TrustLevel) { + self.fbb_.push_slot::( + Activity::VT_TRUST_LEVEL, + trust_level, + TrustLevel::unused, + ); + } + #[inline] + pub fn new( + _fbb: &'b mut flatbuffers::FlatBufferBuilder<'a, A>, + ) -> ActivityBuilder<'a, 'b, A> { + let start = _fbb.start_table(); + ActivityBuilder { + fbb_: _fbb, + start_: start, + } + } + #[inline] + pub fn finish(self) -> flatbuffers::WIPOffset> { + let o = self.fbb_.end_table(self.start_); + flatbuffers::WIPOffset::new(o.value()) + } + } + + impl core::fmt::Debug for Activity<'_> { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + let mut ds = f.debug_struct("Activity"); + ds.field("date_created", &self.date_created()); + ds.field("expert_level", &self.expert_level()); + ds.field("activity_level", &self.activity_level()); + ds.field("trust_level", &self.trust_level()); + ds.finish() + } + } + pub enum EntityRootOffset {} + #[derive(Copy, Clone, PartialEq)] + + pub struct EntityRoot<'a> { + pub _tab: flatbuffers::Table<'a>, + } + + impl<'a> flatbuffers::Follow<'a> for EntityRoot<'a> { + type Inner = EntityRoot<'a>; + #[inline] + unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { + Self { + _tab: flatbuffers::Table::new(buf, loc), + } + } + } + + impl<'a> EntityRoot<'a> { + pub const VT_ENTITY_TYPE: flatbuffers::VOffsetT = 4; + pub const VT_ENTITY: flatbuffers::VOffsetT = 6; + + #[inline] + pub unsafe fn init_from_table(table: flatbuffers::Table<'a>) -> Self { + EntityRoot { _tab: table } + } + #[allow(unused_mut)] + pub fn create< + 'bldr: 'args, + 'args: 'mut_bldr, + 'mut_bldr, + A: flatbuffers::Allocator + 'bldr, + >( + _fbb: &'mut_bldr mut flatbuffers::FlatBufferBuilder<'bldr, A>, + args: &'args EntityRootArgs, + ) -> flatbuffers::WIPOffset> { + let mut builder = EntityRootBuilder::new(_fbb); + if let Some(x) = args.entity { + builder.add_entity(x); + } + builder.add_entity_type(args.entity_type); + builder.finish() + } + + #[inline] + pub fn entity_type(&self) -> Entity { + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { + self._tab + .get::(EntityRoot::VT_ENTITY_TYPE, Some(Entity::NONE)) + .unwrap() + } + } + #[inline] + pub fn entity(&self) -> Option> { + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { + self._tab + .get::>>( + EntityRoot::VT_ENTITY, + None, + ) + } + } + #[inline] + #[allow(non_snake_case)] + pub fn entity_as_account(&self) -> Option> { + if self.entity_type() == Entity::Account { + self.entity().map(|t| { + // Safety: + // Created from a valid Table for this object + // Which contains a valid union in this slot + unsafe { Account::init_from_table(t) } + }) + } else { + None + } + } + + #[inline] + #[allow(non_snake_case)] + pub fn entity_as_stream(&self) -> Option> { + if self.entity_type() == Entity::Stream { + self.entity().map(|t| { + // Safety: + // Created from a valid Table for this object + // Which contains a valid union in this slot + unsafe { Stream::init_from_table(t) } + }) + } else { + None + } + } + + #[inline] + #[allow(non_snake_case)] + pub fn entity_as_thought(&self) -> Option> { + if self.entity_type() == Entity::Thought { + self.entity().map(|t| { + // Safety: + // Created from a valid Table for this object + // Which contains a valid union in this slot + unsafe { Thought::init_from_table(t) } + }) + } else { + None + } + } + } + + impl flatbuffers::Verifiable for EntityRoot<'_> { + #[inline] + fn run_verifier( + v: &mut flatbuffers::Verifier, + pos: usize, + ) -> Result<(), flatbuffers::InvalidFlatbuffer> { + use self::flatbuffers::Verifiable; + v.visit_table(pos)? + .visit_union::( + "entity_type", + Self::VT_ENTITY_TYPE, + "entity", + Self::VT_ENTITY, + false, + |key, v, pos| match key { + Entity::Account => v + .verify_union_variant::>( + "Entity::Account", + pos, + ), + Entity::Stream => v + .verify_union_variant::>( + "Entity::Stream", + pos, + ), + Entity::Thought => v + .verify_union_variant::>( + "Entity::Thought", + pos, + ), + _ => Ok(()), + }, + )? + .finish(); + Ok(()) + } + } + pub struct EntityRootArgs { + pub entity_type: Entity, + pub entity: Option>, + } + impl<'a> Default for EntityRootArgs { + #[inline] + fn default() -> Self { + EntityRootArgs { + entity_type: Entity::NONE, + entity: None, + } + } + } + + pub struct EntityRootBuilder<'a: 'b, 'b, A: flatbuffers::Allocator + 'a> { + fbb_: &'b mut flatbuffers::FlatBufferBuilder<'a, A>, + start_: flatbuffers::WIPOffset, + } + impl<'a: 'b, 'b, A: flatbuffers::Allocator + 'a> EntityRootBuilder<'a, 'b, A> { + #[inline] + pub fn add_entity_type(&mut self, entity_type: Entity) { + self.fbb_ + .push_slot::(EntityRoot::VT_ENTITY_TYPE, entity_type, Entity::NONE); + } + #[inline] + pub fn add_entity(&mut self, entity: flatbuffers::WIPOffset) { + self.fbb_ + .push_slot_always::>(EntityRoot::VT_ENTITY, entity); + } + #[inline] + pub fn new( + _fbb: &'b mut flatbuffers::FlatBufferBuilder<'a, A>, + ) -> EntityRootBuilder<'a, 'b, A> { + let start = _fbb.start_table(); + EntityRootBuilder { + fbb_: _fbb, + start_: start, + } + } + #[inline] + pub fn finish(self) -> flatbuffers::WIPOffset> { + let o = self.fbb_.end_table(self.start_); + flatbuffers::WIPOffset::new(o.value()) + } + } + + impl core::fmt::Debug for EntityRoot<'_> { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + let mut ds = f.debug_struct("EntityRoot"); + ds.field("entity_type", &self.entity_type()); + match self.entity_type() { + Entity::Account => { + if let Some(x) = self.entity_as_account() { + ds.field("entity", &x) + } else { + ds.field( + "entity", + &"InvalidFlatbuffer: Union discriminant does not match value.", + ) + } + } + Entity::Stream => { + if let Some(x) = self.entity_as_stream() { + ds.field("entity", &x) + } else { + ds.field( + "entity", + &"InvalidFlatbuffer: Union discriminant does not match value.", + ) + } + } + Entity::Thought => { + if let Some(x) = self.entity_as_thought() { + ds.field("entity", &x) + } else { + ds.field( + "entity", + &"InvalidFlatbuffer: Union discriminant does not match value.", + ) + } + } + _ => { + let x: Option<()> = None; + ds.field("entity", &x) + } + }; + ds.finish() + } + } #[inline] - unsafe fn push(&self, dst: &mut [u8], _written_len: usize) { - flatbuffers::emplace_scalar::(dst, self.0); - } -} - -impl flatbuffers::EndianScalar for LocationLevel { - type Scalar = i8; - #[inline] - fn to_little_endian(self) -> i8 { - self.0.to_le() - } - #[inline] - #[allow(clippy::wrong_self_convention)] - fn from_little_endian(v: i8) -> Self { - let b = i8::from_le(v); - Self(b) - } -} - -impl<'a> flatbuffers::Verifiable for LocationLevel { - #[inline] - fn run_verifier( - v: &mut flatbuffers::Verifier, pos: usize - ) -> Result<(), flatbuffers::InvalidFlatbuffer> { - use self::flatbuffers::Verifiable; - i8::run_verifier(v, pos) - } -} - -impl flatbuffers::SimpleToVerifyInSlice for LocationLevel {} -#[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")] -pub const ENUM_MIN_IDENTITY_ASSURANCE_LEVEL: i8 = 0; -#[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")] -pub const ENUM_MAX_IDENTITY_ASSURANCE_LEVEL: i8 = 5; -#[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")] -#[allow(non_camel_case_types)] -pub const ENUM_VALUES_IDENTITY_ASSURANCE_LEVEL: [IdentityAssuranceLevel; 6] = [ - IdentityAssuranceLevel::unused, - IdentityAssuranceLevel::ial0, - IdentityAssuranceLevel::ial1, - IdentityAssuranceLevel::ial2, - IdentityAssuranceLevel::ial25, - IdentityAssuranceLevel::ial3, -]; - -#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Default)] -#[repr(transparent)] -pub struct IdentityAssuranceLevel(pub i8); -#[allow(non_upper_case_globals)] -impl IdentityAssuranceLevel { - pub const unused: Self = Self(0); - pub const ial0: Self = Self(1); - pub const ial1: Self = Self(2); - pub const ial2: Self = Self(3); - pub const ial25: Self = Self(4); - pub const ial3: Self = Self(5); - - pub const ENUM_MIN: i8 = 0; - pub const ENUM_MAX: i8 = 5; - pub const ENUM_VALUES: &'static [Self] = &[ - Self::unused, - Self::ial0, - Self::ial1, - Self::ial2, - Self::ial25, - Self::ial3, - ]; - /// Returns the variant's name or "" if unknown. - pub fn variant_name(self) -> Option<&'static str> { - match self { - Self::unused => Some("unused"), - Self::ial0 => Some("ial0"), - Self::ial1 => Some("ial1"), - Self::ial2 => Some("ial2"), - Self::ial25 => Some("ial25"), - Self::ial3 => Some("ial3"), - _ => None, - } - } -} -impl core::fmt::Debug for IdentityAssuranceLevel { - fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result { - if let Some(name) = self.variant_name() { - f.write_str(name) - } else { - f.write_fmt(format_args!("", self.0)) - } - } -} -impl<'a> flatbuffers::Follow<'a> for IdentityAssuranceLevel { - type Inner = Self; - #[inline] - unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { - let b = flatbuffers::read_scalar_at::(buf, loc); - Self(b) - } -} - -impl flatbuffers::Push for IdentityAssuranceLevel { - type Output = IdentityAssuranceLevel; + /// Verifies that a buffer of bytes contains a `EntityRoot` + /// and returns it. + /// Note that verification is still experimental and may not + /// catch every error, or be maximally performant. For the + /// previous, unchecked, behavior use + /// `root_as_entity_root_unchecked`. + pub fn root_as_entity_root(buf: &[u8]) -> Result { + flatbuffers::root::(buf) + } #[inline] - unsafe fn push(&self, dst: &mut [u8], _written_len: usize) { - flatbuffers::emplace_scalar::(dst, self.0); - } -} - -impl flatbuffers::EndianScalar for IdentityAssuranceLevel { - type Scalar = i8; - #[inline] - fn to_little_endian(self) -> i8 { - self.0.to_le() - } - #[inline] - #[allow(clippy::wrong_self_convention)] - fn from_little_endian(v: i8) -> Self { - let b = i8::from_le(v); - Self(b) - } -} - -impl<'a> flatbuffers::Verifiable for IdentityAssuranceLevel { - #[inline] - fn run_verifier( - v: &mut flatbuffers::Verifier, pos: usize - ) -> Result<(), flatbuffers::InvalidFlatbuffer> { - use self::flatbuffers::Verifiable; - i8::run_verifier(v, pos) - } -} - -impl flatbuffers::SimpleToVerifyInSlice for IdentityAssuranceLevel {} -#[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")] -pub const ENUM_MIN_ENCRYPTION_LEVEL: i8 = 0; -#[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")] -pub const ENUM_MAX_ENCRYPTION_LEVEL: i8 = 3; -#[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")] -#[allow(non_camel_case_types)] -pub const ENUM_VALUES_ENCRYPTION_LEVEL: [EncryptionLevel; 4] = [ - EncryptionLevel::unused, - EncryptionLevel::el0, - EncryptionLevel::el1, - EncryptionLevel::el2, -]; - -#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Default)] -#[repr(transparent)] -pub struct EncryptionLevel(pub i8); -#[allow(non_upper_case_globals)] -impl EncryptionLevel { - pub const unused: Self = Self(0); - pub const el0: Self = Self(1); - pub const el1: Self = Self(2); - pub const el2: Self = Self(3); - - pub const ENUM_MIN: i8 = 0; - pub const ENUM_MAX: i8 = 3; - pub const ENUM_VALUES: &'static [Self] = &[ - Self::unused, - Self::el0, - Self::el1, - Self::el2, - ]; - /// Returns the variant's name or "" if unknown. - pub fn variant_name(self) -> Option<&'static str> { - match self { - Self::unused => Some("unused"), - Self::el0 => Some("el0"), - Self::el1 => Some("el1"), - Self::el2 => Some("el2"), - _ => None, - } - } -} -impl core::fmt::Debug for EncryptionLevel { - fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result { - if let Some(name) = self.variant_name() { - f.write_str(name) - } else { - f.write_fmt(format_args!("", self.0)) - } - } -} -impl<'a> flatbuffers::Follow<'a> for EncryptionLevel { - type Inner = Self; - #[inline] - unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { - let b = flatbuffers::read_scalar_at::(buf, loc); - Self(b) - } -} - -impl flatbuffers::Push for EncryptionLevel { - type Output = EncryptionLevel; + /// Verifies that a buffer of bytes contains a size prefixed + /// `EntityRoot` and returns it. + /// Note that verification is still experimental and may not + /// catch every error, or be maximally performant. For the + /// previous, unchecked, behavior use + /// `size_prefixed_root_as_entity_root_unchecked`. + pub fn size_prefixed_root_as_entity_root( + buf: &[u8], + ) -> Result { + flatbuffers::size_prefixed_root::(buf) + } #[inline] - unsafe fn push(&self, dst: &mut [u8], _written_len: usize) { - flatbuffers::emplace_scalar::(dst, self.0); - } -} - -impl flatbuffers::EndianScalar for EncryptionLevel { - type Scalar = i8; - #[inline] - fn to_little_endian(self) -> i8 { - self.0.to_le() - } - #[inline] - #[allow(clippy::wrong_self_convention)] - fn from_little_endian(v: i8) -> Self { - let b = i8::from_le(v); - Self(b) - } -} - -impl<'a> flatbuffers::Verifiable for EncryptionLevel { - #[inline] - fn run_verifier( - v: &mut flatbuffers::Verifier, pos: usize - ) -> Result<(), flatbuffers::InvalidFlatbuffer> { - use self::flatbuffers::Verifiable; - i8::run_verifier(v, pos) - } -} - -impl flatbuffers::SimpleToVerifyInSlice for EncryptionLevel {} -#[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")] -pub const ENUM_MIN_STREAM_LEVEL: i8 = 0; -#[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")] -pub const ENUM_MAX_STREAM_LEVEL: i8 = 3; -#[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")] -#[allow(non_camel_case_types)] -pub const ENUM_VALUES_STREAM_LEVEL: [StreamLevel; 4] = [ - StreamLevel::unused, - StreamLevel::sl0, - StreamLevel::sl1, - StreamLevel::sl2, -]; - -#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Default)] -#[repr(transparent)] -pub struct StreamLevel(pub i8); -#[allow(non_upper_case_globals)] -impl StreamLevel { - pub const unused: Self = Self(0); - pub const sl0: Self = Self(1); - pub const sl1: Self = Self(2); - pub const sl2: Self = Self(3); - - pub const ENUM_MIN: i8 = 0; - pub const ENUM_MAX: i8 = 3; - pub const ENUM_VALUES: &'static [Self] = &[ - Self::unused, - Self::sl0, - Self::sl1, - Self::sl2, - ]; - /// Returns the variant's name or "" if unknown. - pub fn variant_name(self) -> Option<&'static str> { - match self { - Self::unused => Some("unused"), - Self::sl0 => Some("sl0"), - Self::sl1 => Some("sl1"), - Self::sl2 => Some("sl2"), - _ => None, - } - } -} -impl core::fmt::Debug for StreamLevel { - fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result { - if let Some(name) = self.variant_name() { - f.write_str(name) - } else { - f.write_fmt(format_args!("", self.0)) - } - } -} -impl<'a> flatbuffers::Follow<'a> for StreamLevel { - type Inner = Self; - #[inline] - unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { - let b = flatbuffers::read_scalar_at::(buf, loc); - Self(b) - } -} - -impl flatbuffers::Push for StreamLevel { - type Output = StreamLevel; + /// Verifies, with the given options, that a buffer of bytes + /// contains a `EntityRoot` and returns it. + /// Note that verification is still experimental and may not + /// catch every error, or be maximally performant. For the + /// previous, unchecked, behavior use + /// `root_as_entity_root_unchecked`. + pub fn root_as_entity_root_with_opts<'b, 'o>( + opts: &'o flatbuffers::VerifierOptions, + buf: &'b [u8], + ) -> Result, flatbuffers::InvalidFlatbuffer> { + flatbuffers::root_with_opts::>(opts, buf) + } #[inline] - unsafe fn push(&self, dst: &mut [u8], _written_len: usize) { - flatbuffers::emplace_scalar::(dst, self.0); - } -} - -impl flatbuffers::EndianScalar for StreamLevel { - type Scalar = i8; - #[inline] - fn to_little_endian(self) -> i8 { - self.0.to_le() - } - #[inline] - #[allow(clippy::wrong_self_convention)] - fn from_little_endian(v: i8) -> Self { - let b = i8::from_le(v); - Self(b) - } -} - -impl<'a> flatbuffers::Verifiable for StreamLevel { - #[inline] - fn run_verifier( - v: &mut flatbuffers::Verifier, pos: usize - ) -> Result<(), flatbuffers::InvalidFlatbuffer> { - use self::flatbuffers::Verifiable; - i8::run_verifier(v, pos) - } -} - -impl flatbuffers::SimpleToVerifyInSlice for StreamLevel {} -#[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")] -pub const ENUM_MIN_EXPERT_LEVEL: i8 = 0; -#[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")] -pub const ENUM_MAX_EXPERT_LEVEL: i8 = 4; -#[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")] -#[allow(non_camel_case_types)] -pub const ENUM_VALUES_EXPERT_LEVEL: [ExpertLevel; 5] = [ - ExpertLevel::unused, - ExpertLevel::novice, - ExpertLevel::intermediate, - ExpertLevel::expert, - ExpertLevel::master, -]; - -#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Default)] -#[repr(transparent)] -pub struct ExpertLevel(pub i8); -#[allow(non_upper_case_globals)] -impl ExpertLevel { - pub const unused: Self = Self(0); - pub const novice: Self = Self(1); - pub const intermediate: Self = Self(2); - pub const expert: Self = Self(3); - pub const master: Self = Self(4); - - pub const ENUM_MIN: i8 = 0; - pub const ENUM_MAX: i8 = 4; - pub const ENUM_VALUES: &'static [Self] = &[ - Self::unused, - Self::novice, - Self::intermediate, - Self::expert, - Self::master, - ]; - /// Returns the variant's name or "" if unknown. - pub fn variant_name(self) -> Option<&'static str> { - match self { - Self::unused => Some("unused"), - Self::novice => Some("novice"), - Self::intermediate => Some("intermediate"), - Self::expert => Some("expert"), - Self::master => Some("master"), - _ => None, - } - } -} -impl core::fmt::Debug for ExpertLevel { - fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result { - if let Some(name) = self.variant_name() { - f.write_str(name) - } else { - f.write_fmt(format_args!("", self.0)) - } - } -} -impl<'a> flatbuffers::Follow<'a> for ExpertLevel { - type Inner = Self; - #[inline] - unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { - let b = flatbuffers::read_scalar_at::(buf, loc); - Self(b) - } -} - -impl flatbuffers::Push for ExpertLevel { - type Output = ExpertLevel; + /// Verifies, with the given verifier options, that a buffer of + /// bytes contains a size prefixed `EntityRoot` and returns + /// it. Note that verification is still experimental and may not + /// catch every error, or be maximally performant. For the + /// previous, unchecked, behavior use + /// `root_as_entity_root_unchecked`. + pub fn size_prefixed_root_as_entity_root_with_opts<'b, 'o>( + opts: &'o flatbuffers::VerifierOptions, + buf: &'b [u8], + ) -> Result, flatbuffers::InvalidFlatbuffer> { + flatbuffers::size_prefixed_root_with_opts::>(opts, buf) + } #[inline] - unsafe fn push(&self, dst: &mut [u8], _written_len: usize) { - flatbuffers::emplace_scalar::(dst, self.0); - } -} - -impl flatbuffers::EndianScalar for ExpertLevel { - type Scalar = i8; - #[inline] - fn to_little_endian(self) -> i8 { - self.0.to_le() - } - #[inline] - #[allow(clippy::wrong_self_convention)] - fn from_little_endian(v: i8) -> Self { - let b = i8::from_le(v); - Self(b) - } -} - -impl<'a> flatbuffers::Verifiable for ExpertLevel { - #[inline] - fn run_verifier( - v: &mut flatbuffers::Verifier, pos: usize - ) -> Result<(), flatbuffers::InvalidFlatbuffer> { - use self::flatbuffers::Verifiable; - i8::run_verifier(v, pos) - } -} - -impl flatbuffers::SimpleToVerifyInSlice for ExpertLevel {} -#[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")] -pub const ENUM_MIN_TRUST_LEVEL: i8 = 0; -#[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")] -pub const ENUM_MAX_TRUST_LEVEL: i8 = 5; -#[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")] -#[allow(non_camel_case_types)] -pub const ENUM_VALUES_TRUST_LEVEL: [TrustLevel; 6] = [ - TrustLevel::unused, - TrustLevel::untrusted, - TrustLevel::low, - TrustLevel::medium, - TrustLevel::high, - TrustLevel::verified, -]; - -#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Default)] -#[repr(transparent)] -pub struct TrustLevel(pub i8); -#[allow(non_upper_case_globals)] -impl TrustLevel { - pub const unused: Self = Self(0); - pub const untrusted: Self = Self(1); - pub const low: Self = Self(2); - pub const medium: Self = Self(3); - pub const high: Self = Self(4); - pub const verified: Self = Self(5); - - pub const ENUM_MIN: i8 = 0; - pub const ENUM_MAX: i8 = 5; - pub const ENUM_VALUES: &'static [Self] = &[ - Self::unused, - Self::untrusted, - Self::low, - Self::medium, - Self::high, - Self::verified, - ]; - /// Returns the variant's name or "" if unknown. - pub fn variant_name(self) -> Option<&'static str> { - match self { - Self::unused => Some("unused"), - Self::untrusted => Some("untrusted"), - Self::low => Some("low"), - Self::medium => Some("medium"), - Self::high => Some("high"), - Self::verified => Some("verified"), - _ => None, - } - } -} -impl core::fmt::Debug for TrustLevel { - fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result { - if let Some(name) = self.variant_name() { - f.write_str(name) - } else { - f.write_fmt(format_args!("", self.0)) - } - } -} -impl<'a> flatbuffers::Follow<'a> for TrustLevel { - type Inner = Self; - #[inline] - unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { - let b = flatbuffers::read_scalar_at::(buf, loc); - Self(b) - } -} - -impl flatbuffers::Push for TrustLevel { - type Output = TrustLevel; + /// Assumes, without verification, that a buffer of bytes contains a EntityRoot and returns it. + /// # Safety + /// Callers must trust the given bytes do indeed contain a valid `EntityRoot`. + pub unsafe fn root_as_entity_root_unchecked(buf: &[u8]) -> EntityRoot { + flatbuffers::root_unchecked::(buf) + } #[inline] - unsafe fn push(&self, dst: &mut [u8], _written_len: usize) { - flatbuffers::emplace_scalar::(dst, self.0); - } -} - -impl flatbuffers::EndianScalar for TrustLevel { - type Scalar = i8; - #[inline] - fn to_little_endian(self) -> i8 { - self.0.to_le() - } - #[inline] - #[allow(clippy::wrong_self_convention)] - fn from_little_endian(v: i8) -> Self { - let b = i8::from_le(v); - Self(b) - } -} - -impl<'a> flatbuffers::Verifiable for TrustLevel { - #[inline] - fn run_verifier( - v: &mut flatbuffers::Verifier, pos: usize - ) -> Result<(), flatbuffers::InvalidFlatbuffer> { - use self::flatbuffers::Verifiable; - i8::run_verifier(v, pos) - } -} - -impl flatbuffers::SimpleToVerifyInSlice for TrustLevel {} -#[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")] -pub const ENUM_MIN_ENTITY: u8 = 0; -#[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")] -pub const ENUM_MAX_ENTITY: u8 = 3; -#[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")] -#[allow(non_camel_case_types)] -pub const ENUM_VALUES_ENTITY: [Entity; 4] = [ - Entity::NONE, - Entity::Account, - Entity::Stream, - Entity::Thought, -]; - -#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Default)] -#[repr(transparent)] -pub struct Entity(pub u8); -#[allow(non_upper_case_globals)] -impl Entity { - pub const NONE: Self = Self(0); - pub const Account: Self = Self(1); - pub const Stream: Self = Self(2); - pub const Thought: Self = Self(3); - - pub const ENUM_MIN: u8 = 0; - pub const ENUM_MAX: u8 = 3; - pub const ENUM_VALUES: &'static [Self] = &[ - Self::NONE, - Self::Account, - Self::Stream, - Self::Thought, - ]; - /// Returns the variant's name or "" if unknown. - pub fn variant_name(self) -> Option<&'static str> { - match self { - Self::NONE => Some("NONE"), - Self::Account => Some("Account"), - Self::Stream => Some("Stream"), - Self::Thought => Some("Thought"), - _ => None, - } - } -} -impl core::fmt::Debug for Entity { - fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result { - if let Some(name) = self.variant_name() { - f.write_str(name) - } else { - f.write_fmt(format_args!("", self.0)) - } - } -} -impl<'a> flatbuffers::Follow<'a> for Entity { - type Inner = Self; - #[inline] - unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { - let b = flatbuffers::read_scalar_at::(buf, loc); - Self(b) - } -} - -impl flatbuffers::Push for Entity { - type Output = Entity; + /// Assumes, without verification, that a buffer of bytes contains a size prefixed EntityRoot and returns it. + /// # Safety + /// Callers must trust the given bytes do indeed contain a valid size prefixed `EntityRoot`. + pub unsafe fn size_prefixed_root_as_entity_root_unchecked(buf: &[u8]) -> EntityRoot { + flatbuffers::size_prefixed_root_unchecked::(buf) + } #[inline] - unsafe fn push(&self, dst: &mut [u8], _written_len: usize) { - flatbuffers::emplace_scalar::(dst, self.0); - } -} - -impl flatbuffers::EndianScalar for Entity { - type Scalar = u8; - #[inline] - fn to_little_endian(self) -> u8 { - self.0.to_le() - } - #[inline] - #[allow(clippy::wrong_self_convention)] - fn from_little_endian(v: u8) -> Self { - let b = u8::from_le(v); - Self(b) - } -} - -impl<'a> flatbuffers::Verifiable for Entity { - #[inline] - fn run_verifier( - v: &mut flatbuffers::Verifier, pos: usize - ) -> Result<(), flatbuffers::InvalidFlatbuffer> { - use self::flatbuffers::Verifiable; - u8::run_verifier(v, pos) - } -} - -impl flatbuffers::SimpleToVerifyInSlice for Entity {} -pub struct EntityUnionTableOffset {} - -pub enum PublicIdOffset {} -#[derive(Copy, Clone, PartialEq)] - -pub struct PublicId<'a> { - pub _tab: flatbuffers::Table<'a>, -} - -impl<'a> flatbuffers::Follow<'a> for PublicId<'a> { - type Inner = PublicId<'a>; - #[inline] - unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { - Self { _tab: flatbuffers::Table::new(buf, loc) } - } -} - -impl<'a> PublicId<'a> { - pub const VT_ID: flatbuffers::VOffsetT = 4; - - #[inline] - pub unsafe fn init_from_table(table: flatbuffers::Table<'a>) -> Self { - PublicId { _tab: table } - } - #[allow(unused_mut)] - pub fn create<'bldr: 'args, 'args: 'mut_bldr, 'mut_bldr, A: flatbuffers::Allocator + 'bldr>( - _fbb: &'mut_bldr mut flatbuffers::FlatBufferBuilder<'bldr, A>, - args: &'args PublicIdArgs<'args> - ) -> flatbuffers::WIPOffset> { - let mut builder = PublicIdBuilder::new(_fbb); - if let Some(x) = args.id { builder.add_id(x); } - builder.finish() - } - - - #[inline] - pub fn id(&self) -> Option> { - // Safety: - // Created from valid Table for this object - // which contains a valid value in this slot - unsafe { self._tab.get::>>(PublicId::VT_ID, None)} - } -} - -impl flatbuffers::Verifiable for PublicId<'_> { - #[inline] - fn run_verifier( - v: &mut flatbuffers::Verifier, pos: usize - ) -> Result<(), flatbuffers::InvalidFlatbuffer> { - use self::flatbuffers::Verifiable; - v.visit_table(pos)? - .visit_field::>>("id", Self::VT_ID, false)? - .finish(); - Ok(()) - } -} -pub struct PublicIdArgs<'a> { - pub id: Option>>, -} -impl<'a> Default for PublicIdArgs<'a> { - #[inline] - fn default() -> Self { - PublicIdArgs { - id: None, - } - } -} - -pub struct PublicIdBuilder<'a: 'b, 'b, A: flatbuffers::Allocator + 'a> { - fbb_: &'b mut flatbuffers::FlatBufferBuilder<'a, A>, - start_: flatbuffers::WIPOffset, -} -impl<'a: 'b, 'b, A: flatbuffers::Allocator + 'a> PublicIdBuilder<'a, 'b, A> { - #[inline] - pub fn add_id(&mut self, id: flatbuffers::WIPOffset>) { - self.fbb_.push_slot_always::>(PublicId::VT_ID, id); - } - #[inline] - pub fn new(_fbb: &'b mut flatbuffers::FlatBufferBuilder<'a, A>) -> PublicIdBuilder<'a, 'b, A> { - let start = _fbb.start_table(); - PublicIdBuilder { - fbb_: _fbb, - start_: start, - } - } - #[inline] - pub fn finish(self) -> flatbuffers::WIPOffset> { - let o = self.fbb_.end_table(self.start_); - flatbuffers::WIPOffset::new(o.value()) - } -} - -impl core::fmt::Debug for PublicId<'_> { - fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { - let mut ds = f.debug_struct("PublicId"); - ds.field("id", &self.id()); - ds.finish() - } -} -pub enum AccountOffset {} -#[derive(Copy, Clone, PartialEq)] - -pub struct Account<'a> { - pub _tab: flatbuffers::Table<'a>, -} - -impl<'a> flatbuffers::Follow<'a> for Account<'a> { - type Inner = Account<'a>; - #[inline] - unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { - Self { _tab: flatbuffers::Table::new(buf, loc) } - } -} - -impl<'a> Account<'a> { - pub const VT_PUBLIC_ID: flatbuffers::VOffsetT = 4; - pub const VT_PROFILE: flatbuffers::VOffsetT = 6; - pub const VT_ACTIVITY: flatbuffers::VOffsetT = 8; - - #[inline] - pub unsafe fn init_from_table(table: flatbuffers::Table<'a>) -> Self { - Account { _tab: table } - } - #[allow(unused_mut)] - pub fn create<'bldr: 'args, 'args: 'mut_bldr, 'mut_bldr, A: flatbuffers::Allocator + 'bldr>( - _fbb: &'mut_bldr mut flatbuffers::FlatBufferBuilder<'bldr, A>, - args: &'args AccountArgs<'args> - ) -> flatbuffers::WIPOffset> { - let mut builder = AccountBuilder::new(_fbb); - if let Some(x) = args.activity { builder.add_activity(x); } - if let Some(x) = args.profile { builder.add_profile(x); } - if let Some(x) = args.public_id { builder.add_public_id(x); } - builder.finish() - } - - - #[inline] - pub fn public_id(&self) -> Option> { - // Safety: - // Created from valid Table for this object - // which contains a valid value in this slot - unsafe { self._tab.get::>(Account::VT_PUBLIC_ID, None)} - } - #[inline] - pub fn profile(&self) -> Option> { - // Safety: - // Created from valid Table for this object - // which contains a valid value in this slot - unsafe { self._tab.get::>(Account::VT_PROFILE, None)} - } - #[inline] - pub fn activity(&self) -> Option> { - // Safety: - // Created from valid Table for this object - // which contains a valid value in this slot - unsafe { self._tab.get::>(Account::VT_ACTIVITY, None)} - } -} - -impl flatbuffers::Verifiable for Account<'_> { - #[inline] - fn run_verifier( - v: &mut flatbuffers::Verifier, pos: usize - ) -> Result<(), flatbuffers::InvalidFlatbuffer> { - use self::flatbuffers::Verifiable; - v.visit_table(pos)? - .visit_field::>("public_id", Self::VT_PUBLIC_ID, false)? - .visit_field::>("profile", Self::VT_PROFILE, false)? - .visit_field::>("activity", Self::VT_ACTIVITY, false)? - .finish(); - Ok(()) - } -} -pub struct AccountArgs<'a> { - pub public_id: Option>>, - pub profile: Option>>, - pub activity: Option>>, -} -impl<'a> Default for AccountArgs<'a> { - #[inline] - fn default() -> Self { - AccountArgs { - public_id: None, - profile: None, - activity: None, - } - } -} - -pub struct AccountBuilder<'a: 'b, 'b, A: flatbuffers::Allocator + 'a> { - fbb_: &'b mut flatbuffers::FlatBufferBuilder<'a, A>, - start_: flatbuffers::WIPOffset, -} -impl<'a: 'b, 'b, A: flatbuffers::Allocator + 'a> AccountBuilder<'a, 'b, A> { - #[inline] - pub fn add_public_id(&mut self, public_id: flatbuffers::WIPOffset>) { - self.fbb_.push_slot_always::>(Account::VT_PUBLIC_ID, public_id); - } - #[inline] - pub fn add_profile(&mut self, profile: flatbuffers::WIPOffset>) { - self.fbb_.push_slot_always::>(Account::VT_PROFILE, profile); - } - #[inline] - pub fn add_activity(&mut self, activity: flatbuffers::WIPOffset>) { - self.fbb_.push_slot_always::>(Account::VT_ACTIVITY, activity); - } - #[inline] - pub fn new(_fbb: &'b mut flatbuffers::FlatBufferBuilder<'a, A>) -> AccountBuilder<'a, 'b, A> { - let start = _fbb.start_table(); - AccountBuilder { - fbb_: _fbb, - start_: start, - } - } - #[inline] - pub fn finish(self) -> flatbuffers::WIPOffset> { - let o = self.fbb_.end_table(self.start_); - flatbuffers::WIPOffset::new(o.value()) - } -} - -impl core::fmt::Debug for Account<'_> { - fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { - let mut ds = f.debug_struct("Account"); - ds.field("public_id", &self.public_id()); - ds.field("profile", &self.profile()); - ds.field("activity", &self.activity()); - ds.finish() - } -} -pub enum StreamOffset {} -#[derive(Copy, Clone, PartialEq)] - -pub struct Stream<'a> { - pub _tab: flatbuffers::Table<'a>, -} - -impl<'a> flatbuffers::Follow<'a> for Stream<'a> { - type Inner = Stream<'a>; - #[inline] - unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { - Self { _tab: flatbuffers::Table::new(buf, loc) } - } -} - -impl<'a> Stream<'a> { - pub const VT_PUBLIC_ID: flatbuffers::VOffsetT = 4; - pub const VT_PROFILE: flatbuffers::VOffsetT = 6; - pub const VT_ACTIVITY: flatbuffers::VOffsetT = 8; - pub const VT_CREATOR_PUBLIC_ID: flatbuffers::VOffsetT = 10; - pub const VT_MEMBERS_PUBLIC_ID: flatbuffers::VOffsetT = 12; - pub const VT_STREAM_LEVEL: flatbuffers::VOffsetT = 14; - - #[inline] - pub unsafe fn init_from_table(table: flatbuffers::Table<'a>) -> Self { - Stream { _tab: table } - } - #[allow(unused_mut)] - pub fn create<'bldr: 'args, 'args: 'mut_bldr, 'mut_bldr, A: flatbuffers::Allocator + 'bldr>( - _fbb: &'mut_bldr mut flatbuffers::FlatBufferBuilder<'bldr, A>, - args: &'args StreamArgs<'args> - ) -> flatbuffers::WIPOffset> { - let mut builder = StreamBuilder::new(_fbb); - if let Some(x) = args.members_public_id { builder.add_members_public_id(x); } - if let Some(x) = args.creator_public_id { builder.add_creator_public_id(x); } - if let Some(x) = args.activity { builder.add_activity(x); } - if let Some(x) = args.profile { builder.add_profile(x); } - if let Some(x) = args.public_id { builder.add_public_id(x); } - builder.add_stream_level(args.stream_level); - builder.finish() - } - - - #[inline] - pub fn public_id(&self) -> Option> { - // Safety: - // Created from valid Table for this object - // which contains a valid value in this slot - unsafe { self._tab.get::>(Stream::VT_PUBLIC_ID, None)} - } - #[inline] - pub fn profile(&self) -> Option> { - // Safety: - // Created from valid Table for this object - // which contains a valid value in this slot - unsafe { self._tab.get::>(Stream::VT_PROFILE, None)} - } - #[inline] - pub fn activity(&self) -> Option> { - // Safety: - // Created from valid Table for this object - // which contains a valid value in this slot - unsafe { self._tab.get::>(Stream::VT_ACTIVITY, None)} - } - #[inline] - pub fn creator_public_id(&self) -> Option> { - // Safety: - // Created from valid Table for this object - // which contains a valid value in this slot - unsafe { self._tab.get::>(Stream::VT_CREATOR_PUBLIC_ID, None)} - } - #[inline] - pub fn members_public_id(&self) -> Option>>> { - // Safety: - // Created from valid Table for this object - // which contains a valid value in this slot - unsafe { self._tab.get::>>>(Stream::VT_MEMBERS_PUBLIC_ID, None)} - } - #[inline] - pub fn stream_level(&self) -> StreamLevel { - // Safety: - // Created from valid Table for this object - // which contains a valid value in this slot - unsafe { self._tab.get::(Stream::VT_STREAM_LEVEL, Some(StreamLevel::unused)).unwrap()} - } -} - -impl flatbuffers::Verifiable for Stream<'_> { - #[inline] - fn run_verifier( - v: &mut flatbuffers::Verifier, pos: usize - ) -> Result<(), flatbuffers::InvalidFlatbuffer> { - use self::flatbuffers::Verifiable; - v.visit_table(pos)? - .visit_field::>("public_id", Self::VT_PUBLIC_ID, false)? - .visit_field::>("profile", Self::VT_PROFILE, false)? - .visit_field::>("activity", Self::VT_ACTIVITY, false)? - .visit_field::>("creator_public_id", Self::VT_CREATOR_PUBLIC_ID, false)? - .visit_field::>>>("members_public_id", Self::VT_MEMBERS_PUBLIC_ID, false)? - .visit_field::("stream_level", Self::VT_STREAM_LEVEL, false)? - .finish(); - Ok(()) - } -} -pub struct StreamArgs<'a> { - pub public_id: Option>>, - pub profile: Option>>, - pub activity: Option>>, - pub creator_public_id: Option>>, - pub members_public_id: Option>>>>, - pub stream_level: StreamLevel, -} -impl<'a> Default for StreamArgs<'a> { - #[inline] - fn default() -> Self { - StreamArgs { - public_id: None, - profile: None, - activity: None, - creator_public_id: None, - members_public_id: None, - stream_level: StreamLevel::unused, - } - } -} - -pub struct StreamBuilder<'a: 'b, 'b, A: flatbuffers::Allocator + 'a> { - fbb_: &'b mut flatbuffers::FlatBufferBuilder<'a, A>, - start_: flatbuffers::WIPOffset, -} -impl<'a: 'b, 'b, A: flatbuffers::Allocator + 'a> StreamBuilder<'a, 'b, A> { - #[inline] - pub fn add_public_id(&mut self, public_id: flatbuffers::WIPOffset>) { - self.fbb_.push_slot_always::>(Stream::VT_PUBLIC_ID, public_id); - } - #[inline] - pub fn add_profile(&mut self, profile: flatbuffers::WIPOffset>) { - self.fbb_.push_slot_always::>(Stream::VT_PROFILE, profile); - } - #[inline] - pub fn add_activity(&mut self, activity: flatbuffers::WIPOffset>) { - self.fbb_.push_slot_always::>(Stream::VT_ACTIVITY, activity); - } - #[inline] - pub fn add_creator_public_id(&mut self, creator_public_id: flatbuffers::WIPOffset>) { - self.fbb_.push_slot_always::>(Stream::VT_CREATOR_PUBLIC_ID, creator_public_id); - } - #[inline] - pub fn add_members_public_id(&mut self, members_public_id: flatbuffers::WIPOffset>>>) { - self.fbb_.push_slot_always::>(Stream::VT_MEMBERS_PUBLIC_ID, members_public_id); - } - #[inline] - pub fn add_stream_level(&mut self, stream_level: StreamLevel) { - self.fbb_.push_slot::(Stream::VT_STREAM_LEVEL, stream_level, StreamLevel::unused); - } - #[inline] - pub fn new(_fbb: &'b mut flatbuffers::FlatBufferBuilder<'a, A>) -> StreamBuilder<'a, 'b, A> { - let start = _fbb.start_table(); - StreamBuilder { - fbb_: _fbb, - start_: start, - } - } - #[inline] - pub fn finish(self) -> flatbuffers::WIPOffset> { - let o = self.fbb_.end_table(self.start_); - flatbuffers::WIPOffset::new(o.value()) - } -} - -impl core::fmt::Debug for Stream<'_> { - fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { - let mut ds = f.debug_struct("Stream"); - ds.field("public_id", &self.public_id()); - ds.field("profile", &self.profile()); - ds.field("activity", &self.activity()); - ds.field("creator_public_id", &self.creator_public_id()); - ds.field("members_public_id", &self.members_public_id()); - ds.field("stream_level", &self.stream_level()); - ds.finish() - } -} -pub enum ThoughtOffset {} -#[derive(Copy, Clone, PartialEq)] - -pub struct Thought<'a> { - pub _tab: flatbuffers::Table<'a>, -} - -impl<'a> flatbuffers::Follow<'a> for Thought<'a> { - type Inner = Thought<'a>; - #[inline] - unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { - Self { _tab: flatbuffers::Table::new(buf, loc) } - } -} - -impl<'a> Thought<'a> { - pub const VT_PUBLIC_ID: flatbuffers::VOffsetT = 4; - pub const VT_CREATOR_PUBLIC_ID: flatbuffers::VOffsetT = 6; - pub const VT_STREAM_PUBLIC_ID: flatbuffers::VOffsetT = 8; - pub const VT_CONTENT: flatbuffers::VOffsetT = 10; - pub const VT_MEDIA_TYPE: flatbuffers::VOffsetT = 12; - - #[inline] - pub unsafe fn init_from_table(table: flatbuffers::Table<'a>) -> Self { - Thought { _tab: table } - } - #[allow(unused_mut)] - pub fn create<'bldr: 'args, 'args: 'mut_bldr, 'mut_bldr, A: flatbuffers::Allocator + 'bldr>( - _fbb: &'mut_bldr mut flatbuffers::FlatBufferBuilder<'bldr, A>, - args: &'args ThoughtArgs<'args> - ) -> flatbuffers::WIPOffset> { - let mut builder = ThoughtBuilder::new(_fbb); - if let Some(x) = args.content { builder.add_content(x); } - if let Some(x) = args.stream_public_id { builder.add_stream_public_id(x); } - if let Some(x) = args.creator_public_id { builder.add_creator_public_id(x); } - if let Some(x) = args.public_id { builder.add_public_id(x); } - builder.add_media_type(args.media_type); - builder.finish() - } - - - #[inline] - pub fn public_id(&self) -> Option> { - // Safety: - // Created from valid Table for this object - // which contains a valid value in this slot - unsafe { self._tab.get::>(Thought::VT_PUBLIC_ID, None)} - } - #[inline] - pub fn creator_public_id(&self) -> Option> { - // Safety: - // Created from valid Table for this object - // which contains a valid value in this slot - unsafe { self._tab.get::>(Thought::VT_CREATOR_PUBLIC_ID, None)} - } - #[inline] - pub fn stream_public_id(&self) -> Option> { - // Safety: - // Created from valid Table for this object - // which contains a valid value in this slot - unsafe { self._tab.get::>(Thought::VT_STREAM_PUBLIC_ID, None)} - } - #[inline] - pub fn content(&self) -> Option> { - // Safety: - // Created from valid Table for this object - // which contains a valid value in this slot - unsafe { self._tab.get::>>(Thought::VT_CONTENT, None)} - } - #[inline] - pub fn media_type(&self) -> MediaType { - // Safety: - // Created from valid Table for this object - // which contains a valid value in this slot - unsafe { self._tab.get::(Thought::VT_MEDIA_TYPE, Some(MediaType::unused)).unwrap()} - } -} - -impl flatbuffers::Verifiable for Thought<'_> { - #[inline] - fn run_verifier( - v: &mut flatbuffers::Verifier, pos: usize - ) -> Result<(), flatbuffers::InvalidFlatbuffer> { - use self::flatbuffers::Verifiable; - v.visit_table(pos)? - .visit_field::>("public_id", Self::VT_PUBLIC_ID, false)? - .visit_field::>("creator_public_id", Self::VT_CREATOR_PUBLIC_ID, false)? - .visit_field::>("stream_public_id", Self::VT_STREAM_PUBLIC_ID, false)? - .visit_field::>>("content", Self::VT_CONTENT, false)? - .visit_field::("media_type", Self::VT_MEDIA_TYPE, false)? - .finish(); - Ok(()) - } -} -pub struct ThoughtArgs<'a> { - pub public_id: Option>>, - pub creator_public_id: Option>>, - pub stream_public_id: Option>>, - pub content: Option>>, - pub media_type: MediaType, -} -impl<'a> Default for ThoughtArgs<'a> { - #[inline] - fn default() -> Self { - ThoughtArgs { - public_id: None, - creator_public_id: None, - stream_public_id: None, - content: None, - media_type: MediaType::unused, - } - } -} - -pub struct ThoughtBuilder<'a: 'b, 'b, A: flatbuffers::Allocator + 'a> { - fbb_: &'b mut flatbuffers::FlatBufferBuilder<'a, A>, - start_: flatbuffers::WIPOffset, -} -impl<'a: 'b, 'b, A: flatbuffers::Allocator + 'a> ThoughtBuilder<'a, 'b, A> { - #[inline] - pub fn add_public_id(&mut self, public_id: flatbuffers::WIPOffset>) { - self.fbb_.push_slot_always::>(Thought::VT_PUBLIC_ID, public_id); - } - #[inline] - pub fn add_creator_public_id(&mut self, creator_public_id: flatbuffers::WIPOffset>) { - self.fbb_.push_slot_always::>(Thought::VT_CREATOR_PUBLIC_ID, creator_public_id); - } - #[inline] - pub fn add_stream_public_id(&mut self, stream_public_id: flatbuffers::WIPOffset>) { - self.fbb_.push_slot_always::>(Thought::VT_STREAM_PUBLIC_ID, stream_public_id); - } - #[inline] - pub fn add_content(&mut self, content: flatbuffers::WIPOffset>) { - self.fbb_.push_slot_always::>(Thought::VT_CONTENT, content); - } - #[inline] - pub fn add_media_type(&mut self, media_type: MediaType) { - self.fbb_.push_slot::(Thought::VT_MEDIA_TYPE, media_type, MediaType::unused); - } - #[inline] - pub fn new(_fbb: &'b mut flatbuffers::FlatBufferBuilder<'a, A>) -> ThoughtBuilder<'a, 'b, A> { - let start = _fbb.start_table(); - ThoughtBuilder { - fbb_: _fbb, - start_: start, - } - } - #[inline] - pub fn finish(self) -> flatbuffers::WIPOffset> { - let o = self.fbb_.end_table(self.start_); - flatbuffers::WIPOffset::new(o.value()) - } -} - -impl core::fmt::Debug for Thought<'_> { - fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { - let mut ds = f.debug_struct("Thought"); - ds.field("public_id", &self.public_id()); - ds.field("creator_public_id", &self.creator_public_id()); - ds.field("stream_public_id", &self.stream_public_id()); - ds.field("content", &self.content()); - ds.field("media_type", &self.media_type()); - ds.finish() - } -} -pub enum ProfileOffset {} -#[derive(Copy, Clone, PartialEq)] - -pub struct Profile<'a> { - pub _tab: flatbuffers::Table<'a>, -} - -impl<'a> flatbuffers::Follow<'a> for Profile<'a> { - type Inner = Profile<'a>; - #[inline] - unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { - Self { _tab: flatbuffers::Table::new(buf, loc) } - } -} - -impl<'a> Profile<'a> { - pub const VT_NAME: flatbuffers::VOffsetT = 4; - pub const VT_BLURB: flatbuffers::VOffsetT = 6; - pub const VT_INTERESTS: flatbuffers::VOffsetT = 8; - pub const VT_LOCATION: flatbuffers::VOffsetT = 10; - pub const VT_LOCATION_LEVEL: flatbuffers::VOffsetT = 12; - pub const VT_IDENTITY_ASSURANCE_LEVEL: flatbuffers::VOffsetT = 14; - pub const VT_ENCRYPTION_LEVEL: flatbuffers::VOffsetT = 16; - - #[inline] - pub unsafe fn init_from_table(table: flatbuffers::Table<'a>) -> Self { - Profile { _tab: table } - } - #[allow(unused_mut)] - pub fn create<'bldr: 'args, 'args: 'mut_bldr, 'mut_bldr, A: flatbuffers::Allocator + 'bldr>( - _fbb: &'mut_bldr mut flatbuffers::FlatBufferBuilder<'bldr, A>, - args: &'args ProfileArgs<'args> - ) -> flatbuffers::WIPOffset> { - let mut builder = ProfileBuilder::new(_fbb); - if let Some(x) = args.location { builder.add_location(x); } - if let Some(x) = args.interests { builder.add_interests(x); } - if let Some(x) = args.blurb { builder.add_blurb(x); } - if let Some(x) = args.name { builder.add_name(x); } - builder.add_encryption_level(args.encryption_level); - builder.add_identity_assurance_level(args.identity_assurance_level); - builder.add_location_level(args.location_level); - builder.finish() - } - - - #[inline] - pub fn name(&self) -> Option<&'a str> { - // Safety: - // Created from valid Table for this object - // which contains a valid value in this slot - unsafe { self._tab.get::>(Profile::VT_NAME, None)} - } - #[inline] - pub fn blurb(&self) -> Option<&'a str> { - // Safety: - // Created from valid Table for this object - // which contains a valid value in this slot - unsafe { self._tab.get::>(Profile::VT_BLURB, None)} - } - #[inline] - pub fn interests(&self) -> Option<&'a str> { - // Safety: - // Created from valid Table for this object - // which contains a valid value in this slot - unsafe { self._tab.get::>(Profile::VT_INTERESTS, None)} - } - #[inline] - pub fn location(&self) -> Option<&'a str> { - // Safety: - // Created from valid Table for this object - // which contains a valid value in this slot - unsafe { self._tab.get::>(Profile::VT_LOCATION, None)} - } - #[inline] - pub fn location_level(&self) -> LocationLevel { - // Safety: - // Created from valid Table for this object - // which contains a valid value in this slot - unsafe { self._tab.get::(Profile::VT_LOCATION_LEVEL, Some(LocationLevel::unused)).unwrap()} - } - #[inline] - pub fn identity_assurance_level(&self) -> IdentityAssuranceLevel { - // Safety: - // Created from valid Table for this object - // which contains a valid value in this slot - unsafe { self._tab.get::(Profile::VT_IDENTITY_ASSURANCE_LEVEL, Some(IdentityAssuranceLevel::unused)).unwrap()} - } - #[inline] - pub fn encryption_level(&self) -> EncryptionLevel { - // Safety: - // Created from valid Table for this object - // which contains a valid value in this slot - unsafe { self._tab.get::(Profile::VT_ENCRYPTION_LEVEL, Some(EncryptionLevel::unused)).unwrap()} - } -} - -impl flatbuffers::Verifiable for Profile<'_> { - #[inline] - fn run_verifier( - v: &mut flatbuffers::Verifier, pos: usize - ) -> Result<(), flatbuffers::InvalidFlatbuffer> { - use self::flatbuffers::Verifiable; - v.visit_table(pos)? - .visit_field::>("name", Self::VT_NAME, false)? - .visit_field::>("blurb", Self::VT_BLURB, false)? - .visit_field::>("interests", Self::VT_INTERESTS, false)? - .visit_field::>("location", Self::VT_LOCATION, false)? - .visit_field::("location_level", Self::VT_LOCATION_LEVEL, false)? - .visit_field::("identity_assurance_level", Self::VT_IDENTITY_ASSURANCE_LEVEL, false)? - .visit_field::("encryption_level", Self::VT_ENCRYPTION_LEVEL, false)? - .finish(); - Ok(()) - } -} -pub struct ProfileArgs<'a> { - pub name: Option>, - pub blurb: Option>, - pub interests: Option>, - pub location: Option>, - pub location_level: LocationLevel, - pub identity_assurance_level: IdentityAssuranceLevel, - pub encryption_level: EncryptionLevel, -} -impl<'a> Default for ProfileArgs<'a> { - #[inline] - fn default() -> Self { - ProfileArgs { - name: None, - blurb: None, - interests: None, - location: None, - location_level: LocationLevel::unused, - identity_assurance_level: IdentityAssuranceLevel::unused, - encryption_level: EncryptionLevel::unused, - } - } -} - -pub struct ProfileBuilder<'a: 'b, 'b, A: flatbuffers::Allocator + 'a> { - fbb_: &'b mut flatbuffers::FlatBufferBuilder<'a, A>, - start_: flatbuffers::WIPOffset, -} -impl<'a: 'b, 'b, A: flatbuffers::Allocator + 'a> ProfileBuilder<'a, 'b, A> { - #[inline] - pub fn add_name(&mut self, name: flatbuffers::WIPOffset<&'b str>) { - self.fbb_.push_slot_always::>(Profile::VT_NAME, name); - } - #[inline] - pub fn add_blurb(&mut self, blurb: flatbuffers::WIPOffset<&'b str>) { - self.fbb_.push_slot_always::>(Profile::VT_BLURB, blurb); - } - #[inline] - pub fn add_interests(&mut self, interests: flatbuffers::WIPOffset<&'b str>) { - self.fbb_.push_slot_always::>(Profile::VT_INTERESTS, interests); - } - #[inline] - pub fn add_location(&mut self, location: flatbuffers::WIPOffset<&'b str>) { - self.fbb_.push_slot_always::>(Profile::VT_LOCATION, location); - } - #[inline] - pub fn add_location_level(&mut self, location_level: LocationLevel) { - self.fbb_.push_slot::(Profile::VT_LOCATION_LEVEL, location_level, LocationLevel::unused); - } - #[inline] - pub fn add_identity_assurance_level(&mut self, identity_assurance_level: IdentityAssuranceLevel) { - self.fbb_.push_slot::(Profile::VT_IDENTITY_ASSURANCE_LEVEL, identity_assurance_level, IdentityAssuranceLevel::unused); - } - #[inline] - pub fn add_encryption_level(&mut self, encryption_level: EncryptionLevel) { - self.fbb_.push_slot::(Profile::VT_ENCRYPTION_LEVEL, encryption_level, EncryptionLevel::unused); - } - #[inline] - pub fn new(_fbb: &'b mut flatbuffers::FlatBufferBuilder<'a, A>) -> ProfileBuilder<'a, 'b, A> { - let start = _fbb.start_table(); - ProfileBuilder { - fbb_: _fbb, - start_: start, - } - } - #[inline] - pub fn finish(self) -> flatbuffers::WIPOffset> { - let o = self.fbb_.end_table(self.start_); - flatbuffers::WIPOffset::new(o.value()) - } -} - -impl core::fmt::Debug for Profile<'_> { - fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { - let mut ds = f.debug_struct("Profile"); - ds.field("name", &self.name()); - ds.field("blurb", &self.blurb()); - ds.field("interests", &self.interests()); - ds.field("location", &self.location()); - ds.field("location_level", &self.location_level()); - ds.field("identity_assurance_level", &self.identity_assurance_level()); - ds.field("encryption_level", &self.encryption_level()); - ds.finish() - } -} -pub enum ActivityOffset {} -#[derive(Copy, Clone, PartialEq)] - -pub struct Activity<'a> { - pub _tab: flatbuffers::Table<'a>, -} - -impl<'a> flatbuffers::Follow<'a> for Activity<'a> { - type Inner = Activity<'a>; - #[inline] - unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { - Self { _tab: flatbuffers::Table::new(buf, loc) } - } -} - -impl<'a> Activity<'a> { - pub const VT_DATE_CREATED: flatbuffers::VOffsetT = 4; - pub const VT_EXPERT_LEVEL: flatbuffers::VOffsetT = 6; - pub const VT_ACTIVITY_LEVEL: flatbuffers::VOffsetT = 8; - pub const VT_TRUST_LEVEL: flatbuffers::VOffsetT = 10; - - #[inline] - pub unsafe fn init_from_table(table: flatbuffers::Table<'a>) -> Self { - Activity { _tab: table } - } - #[allow(unused_mut)] - pub fn create<'bldr: 'args, 'args: 'mut_bldr, 'mut_bldr, A: flatbuffers::Allocator + 'bldr>( - _fbb: &'mut_bldr mut flatbuffers::FlatBufferBuilder<'bldr, A>, - args: &'args ActivityArgs - ) -> flatbuffers::WIPOffset> { - let mut builder = ActivityBuilder::new(_fbb); - builder.add_date_created(args.date_created); - builder.add_trust_level(args.trust_level); - builder.add_activity_level(args.activity_level); - builder.add_expert_level(args.expert_level); - builder.finish() - } - - - #[inline] - pub fn date_created(&self) -> i64 { - // Safety: - // Created from valid Table for this object - // which contains a valid value in this slot - unsafe { self._tab.get::(Activity::VT_DATE_CREATED, Some(0)).unwrap()} - } - #[inline] - pub fn expert_level(&self) -> ExpertLevel { - // Safety: - // Created from valid Table for this object - // which contains a valid value in this slot - unsafe { self._tab.get::(Activity::VT_EXPERT_LEVEL, Some(ExpertLevel::unused)).unwrap()} - } - #[inline] - pub fn activity_level(&self) -> ActivityLevel { - // Safety: - // Created from valid Table for this object - // which contains a valid value in this slot - unsafe { self._tab.get::(Activity::VT_ACTIVITY_LEVEL, Some(ActivityLevel::unused)).unwrap()} - } - #[inline] - pub fn trust_level(&self) -> TrustLevel { - // Safety: - // Created from valid Table for this object - // which contains a valid value in this slot - unsafe { self._tab.get::(Activity::VT_TRUST_LEVEL, Some(TrustLevel::unused)).unwrap()} - } -} - -impl flatbuffers::Verifiable for Activity<'_> { - #[inline] - fn run_verifier( - v: &mut flatbuffers::Verifier, pos: usize - ) -> Result<(), flatbuffers::InvalidFlatbuffer> { - use self::flatbuffers::Verifiable; - v.visit_table(pos)? - .visit_field::("date_created", Self::VT_DATE_CREATED, false)? - .visit_field::("expert_level", Self::VT_EXPERT_LEVEL, false)? - .visit_field::("activity_level", Self::VT_ACTIVITY_LEVEL, false)? - .visit_field::("trust_level", Self::VT_TRUST_LEVEL, false)? - .finish(); - Ok(()) - } -} -pub struct ActivityArgs { - pub date_created: i64, - pub expert_level: ExpertLevel, - pub activity_level: ActivityLevel, - pub trust_level: TrustLevel, -} -impl<'a> Default for ActivityArgs { - #[inline] - fn default() -> Self { - ActivityArgs { - date_created: 0, - expert_level: ExpertLevel::unused, - activity_level: ActivityLevel::unused, - trust_level: TrustLevel::unused, - } - } -} - -pub struct ActivityBuilder<'a: 'b, 'b, A: flatbuffers::Allocator + 'a> { - fbb_: &'b mut flatbuffers::FlatBufferBuilder<'a, A>, - start_: flatbuffers::WIPOffset, -} -impl<'a: 'b, 'b, A: flatbuffers::Allocator + 'a> ActivityBuilder<'a, 'b, A> { - #[inline] - pub fn add_date_created(&mut self, date_created: i64) { - self.fbb_.push_slot::(Activity::VT_DATE_CREATED, date_created, 0); - } - #[inline] - pub fn add_expert_level(&mut self, expert_level: ExpertLevel) { - self.fbb_.push_slot::(Activity::VT_EXPERT_LEVEL, expert_level, ExpertLevel::unused); - } - #[inline] - pub fn add_activity_level(&mut self, activity_level: ActivityLevel) { - self.fbb_.push_slot::(Activity::VT_ACTIVITY_LEVEL, activity_level, ActivityLevel::unused); - } - #[inline] - pub fn add_trust_level(&mut self, trust_level: TrustLevel) { - self.fbb_.push_slot::(Activity::VT_TRUST_LEVEL, trust_level, TrustLevel::unused); - } - #[inline] - pub fn new(_fbb: &'b mut flatbuffers::FlatBufferBuilder<'a, A>) -> ActivityBuilder<'a, 'b, A> { - let start = _fbb.start_table(); - ActivityBuilder { - fbb_: _fbb, - start_: start, - } - } - #[inline] - pub fn finish(self) -> flatbuffers::WIPOffset> { - let o = self.fbb_.end_table(self.start_); - flatbuffers::WIPOffset::new(o.value()) - } -} - -impl core::fmt::Debug for Activity<'_> { - fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { - let mut ds = f.debug_struct("Activity"); - ds.field("date_created", &self.date_created()); - ds.field("expert_level", &self.expert_level()); - ds.field("activity_level", &self.activity_level()); - ds.field("trust_level", &self.trust_level()); - ds.finish() - } -} -pub enum EntityRootOffset {} -#[derive(Copy, Clone, PartialEq)] - -pub struct EntityRoot<'a> { - pub _tab: flatbuffers::Table<'a>, -} - -impl<'a> flatbuffers::Follow<'a> for EntityRoot<'a> { - type Inner = EntityRoot<'a>; - #[inline] - unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { - Self { _tab: flatbuffers::Table::new(buf, loc) } - } -} - -impl<'a> EntityRoot<'a> { - pub const VT_ENTITY_TYPE: flatbuffers::VOffsetT = 4; - pub const VT_ENTITY: flatbuffers::VOffsetT = 6; - - #[inline] - pub unsafe fn init_from_table(table: flatbuffers::Table<'a>) -> Self { - EntityRoot { _tab: table } - } - #[allow(unused_mut)] - pub fn create<'bldr: 'args, 'args: 'mut_bldr, 'mut_bldr, A: flatbuffers::Allocator + 'bldr>( - _fbb: &'mut_bldr mut flatbuffers::FlatBufferBuilder<'bldr, A>, - args: &'args EntityRootArgs - ) -> flatbuffers::WIPOffset> { - let mut builder = EntityRootBuilder::new(_fbb); - if let Some(x) = args.entity { builder.add_entity(x); } - builder.add_entity_type(args.entity_type); - builder.finish() - } - - - #[inline] - pub fn entity_type(&self) -> Entity { - // Safety: - // Created from valid Table for this object - // which contains a valid value in this slot - unsafe { self._tab.get::(EntityRoot::VT_ENTITY_TYPE, Some(Entity::NONE)).unwrap()} - } - #[inline] - pub fn entity(&self) -> Option> { - // Safety: - // Created from valid Table for this object - // which contains a valid value in this slot - unsafe { self._tab.get::>>(EntityRoot::VT_ENTITY, None)} - } - #[inline] - #[allow(non_snake_case)] - pub fn entity_as_account(&self) -> Option> { - if self.entity_type() == Entity::Account { - self.entity().map(|t| { - // Safety: - // Created from a valid Table for this object - // Which contains a valid union in this slot - unsafe { Account::init_from_table(t) } - }) - } else { - None - } - } - - #[inline] - #[allow(non_snake_case)] - pub fn entity_as_stream(&self) -> Option> { - if self.entity_type() == Entity::Stream { - self.entity().map(|t| { - // Safety: - // Created from a valid Table for this object - // Which contains a valid union in this slot - unsafe { Stream::init_from_table(t) } - }) - } else { - None - } - } - - #[inline] - #[allow(non_snake_case)] - pub fn entity_as_thought(&self) -> Option> { - if self.entity_type() == Entity::Thought { - self.entity().map(|t| { - // Safety: - // Created from a valid Table for this object - // Which contains a valid union in this slot - unsafe { Thought::init_from_table(t) } - }) - } else { - None - } - } - -} - -impl flatbuffers::Verifiable for EntityRoot<'_> { - #[inline] - fn run_verifier( - v: &mut flatbuffers::Verifier, pos: usize - ) -> Result<(), flatbuffers::InvalidFlatbuffer> { - use self::flatbuffers::Verifiable; - v.visit_table(pos)? - .visit_union::("entity_type", Self::VT_ENTITY_TYPE, "entity", Self::VT_ENTITY, false, |key, v, pos| { - match key { - Entity::Account => v.verify_union_variant::>("Entity::Account", pos), - Entity::Stream => v.verify_union_variant::>("Entity::Stream", pos), - Entity::Thought => v.verify_union_variant::>("Entity::Thought", pos), - _ => Ok(()), - } - })? - .finish(); - Ok(()) - } -} -pub struct EntityRootArgs { - pub entity_type: Entity, - pub entity: Option>, -} -impl<'a> Default for EntityRootArgs { - #[inline] - fn default() -> Self { - EntityRootArgs { - entity_type: Entity::NONE, - entity: None, - } - } -} - -pub struct EntityRootBuilder<'a: 'b, 'b, A: flatbuffers::Allocator + 'a> { - fbb_: &'b mut flatbuffers::FlatBufferBuilder<'a, A>, - start_: flatbuffers::WIPOffset, -} -impl<'a: 'b, 'b, A: flatbuffers::Allocator + 'a> EntityRootBuilder<'a, 'b, A> { - #[inline] - pub fn add_entity_type(&mut self, entity_type: Entity) { - self.fbb_.push_slot::(EntityRoot::VT_ENTITY_TYPE, entity_type, Entity::NONE); - } - #[inline] - pub fn add_entity(&mut self, entity: flatbuffers::WIPOffset) { - self.fbb_.push_slot_always::>(EntityRoot::VT_ENTITY, entity); - } - #[inline] - pub fn new(_fbb: &'b mut flatbuffers::FlatBufferBuilder<'a, A>) -> EntityRootBuilder<'a, 'b, A> { - let start = _fbb.start_table(); - EntityRootBuilder { - fbb_: _fbb, - start_: start, - } - } - #[inline] - pub fn finish(self) -> flatbuffers::WIPOffset> { - let o = self.fbb_.end_table(self.start_); - flatbuffers::WIPOffset::new(o.value()) - } -} - -impl core::fmt::Debug for EntityRoot<'_> { - fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { - let mut ds = f.debug_struct("EntityRoot"); - ds.field("entity_type", &self.entity_type()); - match self.entity_type() { - Entity::Account => { - if let Some(x) = self.entity_as_account() { - ds.field("entity", &x) - } else { - ds.field("entity", &"InvalidFlatbuffer: Union discriminant does not match value.") - } - }, - Entity::Stream => { - if let Some(x) = self.entity_as_stream() { - ds.field("entity", &x) - } else { - ds.field("entity", &"InvalidFlatbuffer: Union discriminant does not match value.") - } - }, - Entity::Thought => { - if let Some(x) = self.entity_as_thought() { - ds.field("entity", &x) - } else { - ds.field("entity", &"InvalidFlatbuffer: Union discriminant does not match value.") - } - }, - _ => { - let x: Option<()> = None; - ds.field("entity", &x) - }, - }; - ds.finish() - } -} -#[inline] -/// Verifies that a buffer of bytes contains a `EntityRoot` -/// and returns it. -/// Note that verification is still experimental and may not -/// catch every error, or be maximally performant. For the -/// previous, unchecked, behavior use -/// `root_as_entity_root_unchecked`. -pub fn root_as_entity_root(buf: &[u8]) -> Result { - flatbuffers::root::(buf) -} -#[inline] -/// Verifies that a buffer of bytes contains a size prefixed -/// `EntityRoot` and returns it. -/// Note that verification is still experimental and may not -/// catch every error, or be maximally performant. For the -/// previous, unchecked, behavior use -/// `size_prefixed_root_as_entity_root_unchecked`. -pub fn size_prefixed_root_as_entity_root(buf: &[u8]) -> Result { - flatbuffers::size_prefixed_root::(buf) -} -#[inline] -/// Verifies, with the given options, that a buffer of bytes -/// contains a `EntityRoot` and returns it. -/// Note that verification is still experimental and may not -/// catch every error, or be maximally performant. For the -/// previous, unchecked, behavior use -/// `root_as_entity_root_unchecked`. -pub fn root_as_entity_root_with_opts<'b, 'o>( - opts: &'o flatbuffers::VerifierOptions, - buf: &'b [u8], -) -> Result, flatbuffers::InvalidFlatbuffer> { - flatbuffers::root_with_opts::>(opts, buf) -} -#[inline] -/// Verifies, with the given verifier options, that a buffer of -/// bytes contains a size prefixed `EntityRoot` and returns -/// it. Note that verification is still experimental and may not -/// catch every error, or be maximally performant. For the -/// previous, unchecked, behavior use -/// `root_as_entity_root_unchecked`. -pub fn size_prefixed_root_as_entity_root_with_opts<'b, 'o>( - opts: &'o flatbuffers::VerifierOptions, - buf: &'b [u8], -) -> Result, flatbuffers::InvalidFlatbuffer> { - flatbuffers::size_prefixed_root_with_opts::>(opts, buf) -} -#[inline] -/// Assumes, without verification, that a buffer of bytes contains a EntityRoot and returns it. -/// # Safety -/// Callers must trust the given bytes do indeed contain a valid `EntityRoot`. -pub unsafe fn root_as_entity_root_unchecked(buf: &[u8]) -> EntityRoot { - flatbuffers::root_unchecked::(buf) -} -#[inline] -/// Assumes, without verification, that a buffer of bytes contains a size prefixed EntityRoot and returns it. -/// # Safety -/// Callers must trust the given bytes do indeed contain a valid size prefixed `EntityRoot`. -pub unsafe fn size_prefixed_root_as_entity_root_unchecked(buf: &[u8]) -> EntityRoot { - flatbuffers::size_prefixed_root_unchecked::(buf) -} -#[inline] -pub fn finish_entity_root_buffer<'a, 'b, A: flatbuffers::Allocator + 'a>( - fbb: &'b mut flatbuffers::FlatBufferBuilder<'a, A>, - root: flatbuffers::WIPOffset>) { - fbb.finish(root, None); -} - -#[inline] -pub fn finish_size_prefixed_entity_root_buffer<'a, 'b, A: flatbuffers::Allocator + 'a>(fbb: &'b mut flatbuffers::FlatBufferBuilder<'a, A>, root: flatbuffers::WIPOffset>) { - fbb.finish_size_prefixed(root, None); -} -} // pub mod Arkavo + pub fn finish_entity_root_buffer<'a, 'b, A: flatbuffers::Allocator + 'a>( + fbb: &'b mut flatbuffers::FlatBufferBuilder<'a, A>, + root: flatbuffers::WIPOffset>, + ) { + fbb.finish(root, None); + } + #[inline] + pub fn finish_size_prefixed_entity_root_buffer<'a, 'b, A: flatbuffers::Allocator + 'a>( + fbb: &'b mut flatbuffers::FlatBufferBuilder<'a, A>, + root: flatbuffers::WIPOffset>, + ) { + fbb.finish_size_prefixed(root, None); + } +} // pub mod Arkavo diff --git a/src/bin/schemas/metadata_generated.rs b/src/bin/schemas/metadata_generated.rs index 1309100..0c8b731 100644 --- a/src/bin/schemas/metadata_generated.rs +++ b/src/bin/schemas/metadata_generated.rs @@ -7,1565 +7,1917 @@ extern crate flatbuffers; #[allow(unused_imports, dead_code)] pub mod arkavo { - use core::mem; - use core::cmp::Ordering; - use crate::schemas::entity_generated::arkavo::MediaType; - - extern crate flatbuffers; - use self::flatbuffers::{EndianScalar, Follow}; - -#[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")] -pub const ENUM_MIN_RATING_LEVEL: i8 = 0; -#[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")] -pub const ENUM_MAX_RATING_LEVEL: i8 = 4; -#[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")] -#[allow(non_camel_case_types)] -pub const ENUM_VALUES_RATING_LEVEL: [RatingLevel; 5] = [ - RatingLevel::unused, - RatingLevel::none, - RatingLevel::mild, - RatingLevel::moderate, - RatingLevel::severe, -]; - -#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Default)] -#[repr(transparent)] -pub struct RatingLevel(pub i8); -#[allow(non_upper_case_globals)] -impl RatingLevel { - pub const unused: Self = Self(0); - pub const none: Self = Self(1); - pub const mild: Self = Self(2); - pub const moderate: Self = Self(3); - pub const severe: Self = Self(4); - - pub const ENUM_MIN: i8 = 0; - pub const ENUM_MAX: i8 = 4; - pub const ENUM_VALUES: &'static [Self] = &[ - Self::unused, - Self::none, - Self::mild, - Self::moderate, - Self::severe, - ]; - /// Returns the variant's name or "" if unknown. - pub fn variant_name(self) -> Option<&'static str> { - match self { - Self::unused => Some("unused"), - Self::none => Some("none"), - Self::mild => Some("mild"), - Self::moderate => Some("moderate"), - Self::severe => Some("severe"), - _ => None, - } - } -} -impl core::fmt::Debug for RatingLevel { - fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result { - if let Some(name) = self.variant_name() { - f.write_str(name) - } else { - f.write_fmt(format_args!("", self.0)) - } - } -} -impl<'a> flatbuffers::Follow<'a> for RatingLevel { - type Inner = Self; - #[inline] - unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { - let b = flatbuffers::read_scalar_at::(buf, loc); - Self(b) - } -} - -impl flatbuffers::Push for RatingLevel { - type Output = RatingLevel; + use crate::schemas::entity_generated::arkavo::MediaType; + use core::cmp::Ordering; + use core::mem; + + extern crate flatbuffers; + use self::flatbuffers::{EndianScalar, Follow}; + + #[deprecated( + since = "2.0.0", + note = "Use associated constants instead. This will no longer be generated in 2021." + )] + pub const ENUM_MIN_RATING_LEVEL: i8 = 0; + #[deprecated( + since = "2.0.0", + note = "Use associated constants instead. This will no longer be generated in 2021." + )] + pub const ENUM_MAX_RATING_LEVEL: i8 = 4; + #[deprecated( + since = "2.0.0", + note = "Use associated constants instead. This will no longer be generated in 2021." + )] + #[allow(non_camel_case_types)] + pub const ENUM_VALUES_RATING_LEVEL: [RatingLevel; 5] = [ + RatingLevel::unused, + RatingLevel::none, + RatingLevel::mild, + RatingLevel::moderate, + RatingLevel::severe, + ]; + + #[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Default)] + #[repr(transparent)] + pub struct RatingLevel(pub i8); + #[allow(non_upper_case_globals)] + impl RatingLevel { + pub const unused: Self = Self(0); + pub const none: Self = Self(1); + pub const mild: Self = Self(2); + pub const moderate: Self = Self(3); + pub const severe: Self = Self(4); + + pub const ENUM_MIN: i8 = 0; + pub const ENUM_MAX: i8 = 4; + pub const ENUM_VALUES: &'static [Self] = &[ + Self::unused, + Self::none, + Self::mild, + Self::moderate, + Self::severe, + ]; + /// Returns the variant's name or "" if unknown. + pub fn variant_name(self) -> Option<&'static str> { + match self { + Self::unused => Some("unused"), + Self::none => Some("none"), + Self::mild => Some("mild"), + Self::moderate => Some("moderate"), + Self::severe => Some("severe"), + _ => None, + } + } + } + impl core::fmt::Debug for RatingLevel { + fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result { + if let Some(name) = self.variant_name() { + f.write_str(name) + } else { + f.write_fmt(format_args!("", self.0)) + } + } + } + impl<'a> flatbuffers::Follow<'a> for RatingLevel { + type Inner = Self; + #[inline] + unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { + let b = flatbuffers::read_scalar_at::(buf, loc); + Self(b) + } + } + + impl flatbuffers::Push for RatingLevel { + type Output = RatingLevel; + #[inline] + unsafe fn push(&self, dst: &mut [u8], _written_len: usize) { + flatbuffers::emplace_scalar::(dst, self.0); + } + } + + impl flatbuffers::EndianScalar for RatingLevel { + type Scalar = i8; + #[inline] + fn to_little_endian(self) -> i8 { + self.0.to_le() + } + #[inline] + #[allow(clippy::wrong_self_convention)] + fn from_little_endian(v: i8) -> Self { + let b = i8::from_le(v); + Self(b) + } + } + + impl<'a> flatbuffers::Verifiable for RatingLevel { + #[inline] + fn run_verifier( + v: &mut flatbuffers::Verifier, + pos: usize, + ) -> Result<(), flatbuffers::InvalidFlatbuffer> { + use self::flatbuffers::Verifiable; + i8::run_verifier(v, pos) + } + } + + impl flatbuffers::SimpleToVerifyInSlice for RatingLevel {} + #[deprecated( + since = "2.0.0", + note = "Use associated constants instead. This will no longer be generated in 2021." + )] + pub const ENUM_MIN_FORMAT_TYPE: i8 = 0; + #[deprecated( + since = "2.0.0", + note = "Use associated constants instead. This will no longer be generated in 2021." + )] + pub const ENUM_MAX_FORMAT_TYPE: i8 = 30; + #[deprecated( + since = "2.0.0", + note = "Use associated constants instead. This will no longer be generated in 2021." + )] + #[allow(non_camel_case_types)] + pub const ENUM_VALUES_FORMAT_TYPE: [FormatType; 10] = [ + FormatType::plain, + FormatType::html, + FormatType::csv, + FormatType::xml, + FormatType::json, + FormatType::jpeg, + FormatType::png, + FormatType::svg, + FormatType::gif, + FormatType::pdf, + ]; + + #[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Default)] + #[repr(transparent)] + pub struct FormatType(pub i8); + #[allow(non_upper_case_globals)] + impl FormatType { + pub const plain: Self = Self(0); + pub const html: Self = Self(1); + pub const csv: Self = Self(2); + pub const xml: Self = Self(3); + pub const json: Self = Self(4); + pub const jpeg: Self = Self(10); + pub const png: Self = Self(11); + pub const svg: Self = Self(12); + pub const gif: Self = Self(13); + pub const pdf: Self = Self(30); + + pub const ENUM_MIN: i8 = 0; + pub const ENUM_MAX: i8 = 30; + pub const ENUM_VALUES: &'static [Self] = &[ + Self::plain, + Self::html, + Self::csv, + Self::xml, + Self::json, + Self::jpeg, + Self::png, + Self::svg, + Self::gif, + Self::pdf, + ]; + /// Returns the variant's name or "" if unknown. + pub fn variant_name(self) -> Option<&'static str> { + match self { + Self::plain => Some("plain"), + Self::html => Some("html"), + Self::csv => Some("csv"), + Self::xml => Some("xml"), + Self::json => Some("json"), + Self::jpeg => Some("jpeg"), + Self::png => Some("png"), + Self::svg => Some("svg"), + Self::gif => Some("gif"), + Self::pdf => Some("pdf"), + _ => None, + } + } + } + impl core::fmt::Debug for FormatType { + fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result { + if let Some(name) = self.variant_name() { + f.write_str(name) + } else { + f.write_fmt(format_args!("", self.0)) + } + } + } + impl<'a> flatbuffers::Follow<'a> for FormatType { + type Inner = Self; + #[inline] + unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { + let b = flatbuffers::read_scalar_at::(buf, loc); + Self(b) + } + } + + impl flatbuffers::Push for FormatType { + type Output = FormatType; + #[inline] + unsafe fn push(&self, dst: &mut [u8], _written_len: usize) { + flatbuffers::emplace_scalar::(dst, self.0); + } + } + + impl flatbuffers::EndianScalar for FormatType { + type Scalar = i8; + #[inline] + fn to_little_endian(self) -> i8 { + self.0.to_le() + } + #[inline] + #[allow(clippy::wrong_self_convention)] + fn from_little_endian(v: i8) -> Self { + let b = i8::from_le(v); + Self(b) + } + } + + impl<'a> flatbuffers::Verifiable for FormatType { + #[inline] + fn run_verifier( + v: &mut flatbuffers::Verifier, + pos: usize, + ) -> Result<(), flatbuffers::InvalidFlatbuffer> { + use self::flatbuffers::Verifiable; + i8::run_verifier(v, pos) + } + } + + impl flatbuffers::SimpleToVerifyInSlice for FormatType {} + #[deprecated( + since = "2.0.0", + note = "Use associated constants instead. This will no longer be generated in 2021." + )] + pub const ENUM_MIN_DATA_ENCODING: i8 = 0; + #[deprecated( + since = "2.0.0", + note = "Use associated constants instead. This will no longer be generated in 2021." + )] + pub const ENUM_MAX_DATA_ENCODING: i8 = 5; + #[deprecated( + since = "2.0.0", + note = "Use associated constants instead. This will no longer be generated in 2021." + )] + #[allow(non_camel_case_types)] + pub const ENUM_VALUES_DATA_ENCODING: [DataEncoding; 6] = [ + DataEncoding::binary, + DataEncoding::utf8, + DataEncoding::utf16, + DataEncoding::ascii, + DataEncoding::base64, + DataEncoding::quoted_printable, + ]; + + #[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Default)] + #[repr(transparent)] + pub struct DataEncoding(pub i8); + #[allow(non_upper_case_globals)] + impl DataEncoding { + pub const binary: Self = Self(0); + pub const utf8: Self = Self(1); + pub const utf16: Self = Self(2); + pub const ascii: Self = Self(3); + pub const base64: Self = Self(4); + pub const quoted_printable: Self = Self(5); + + pub const ENUM_MIN: i8 = 0; + pub const ENUM_MAX: i8 = 5; + pub const ENUM_VALUES: &'static [Self] = &[ + Self::binary, + Self::utf8, + Self::utf16, + Self::ascii, + Self::base64, + Self::quoted_printable, + ]; + /// Returns the variant's name or "" if unknown. + pub fn variant_name(self) -> Option<&'static str> { + match self { + Self::binary => Some("binary"), + Self::utf8 => Some("utf8"), + Self::utf16 => Some("utf16"), + Self::ascii => Some("ascii"), + Self::base64 => Some("base64"), + Self::quoted_printable => Some("quoted_printable"), + _ => None, + } + } + } + impl core::fmt::Debug for DataEncoding { + fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result { + if let Some(name) = self.variant_name() { + f.write_str(name) + } else { + f.write_fmt(format_args!("", self.0)) + } + } + } + impl<'a> flatbuffers::Follow<'a> for DataEncoding { + type Inner = Self; + #[inline] + unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { + let b = flatbuffers::read_scalar_at::(buf, loc); + Self(b) + } + } + + impl flatbuffers::Push for DataEncoding { + type Output = DataEncoding; + #[inline] + unsafe fn push(&self, dst: &mut [u8], _written_len: usize) { + flatbuffers::emplace_scalar::(dst, self.0); + } + } + + impl flatbuffers::EndianScalar for DataEncoding { + type Scalar = i8; + #[inline] + fn to_little_endian(self) -> i8 { + self.0.to_le() + } + #[inline] + #[allow(clippy::wrong_self_convention)] + fn from_little_endian(v: i8) -> Self { + let b = i8::from_le(v); + Self(b) + } + } + + impl<'a> flatbuffers::Verifiable for DataEncoding { + #[inline] + fn run_verifier( + v: &mut flatbuffers::Verifier, + pos: usize, + ) -> Result<(), flatbuffers::InvalidFlatbuffer> { + use self::flatbuffers::Verifiable; + i8::run_verifier(v, pos) + } + } + + impl flatbuffers::SimpleToVerifyInSlice for DataEncoding {} + #[deprecated( + since = "2.0.0", + note = "Use associated constants instead. This will no longer be generated in 2021." + )] + pub const ENUM_MIN_ARCHIVE_TYPE: i8 = 0; + #[deprecated( + since = "2.0.0", + note = "Use associated constants instead. This will no longer be generated in 2021." + )] + pub const ENUM_MAX_ARCHIVE_TYPE: i8 = 7; + #[deprecated( + since = "2.0.0", + note = "Use associated constants instead. This will no longer be generated in 2021." + )] + #[allow(non_camel_case_types)] + pub const ENUM_VALUES_ARCHIVE_TYPE: [ArchiveType; 8] = [ + ArchiveType::none, + ArchiveType::zip, + ArchiveType::tar, + ArchiveType::gzip, + ArchiveType::bzip2, + ArchiveType::xz, + ArchiveType::zstd, + ArchiveType::lz4, + ]; + + #[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Default)] + #[repr(transparent)] + pub struct ArchiveType(pub i8); + #[allow(non_upper_case_globals)] + impl ArchiveType { + pub const none: Self = Self(0); + pub const zip: Self = Self(1); + pub const tar: Self = Self(2); + pub const gzip: Self = Self(3); + pub const bzip2: Self = Self(4); + pub const xz: Self = Self(5); + pub const zstd: Self = Self(6); + pub const lz4: Self = Self(7); + + pub const ENUM_MIN: i8 = 0; + pub const ENUM_MAX: i8 = 7; + pub const ENUM_VALUES: &'static [Self] = &[ + Self::none, + Self::zip, + Self::tar, + Self::gzip, + Self::bzip2, + Self::xz, + Self::zstd, + Self::lz4, + ]; + /// Returns the variant's name or "" if unknown. + pub fn variant_name(self) -> Option<&'static str> { + match self { + Self::none => Some("none"), + Self::zip => Some("zip"), + Self::tar => Some("tar"), + Self::gzip => Some("gzip"), + Self::bzip2 => Some("bzip2"), + Self::xz => Some("xz"), + Self::zstd => Some("zstd"), + Self::lz4 => Some("lz4"), + _ => None, + } + } + } + impl core::fmt::Debug for ArchiveType { + fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result { + if let Some(name) = self.variant_name() { + f.write_str(name) + } else { + f.write_fmt(format_args!("", self.0)) + } + } + } + impl<'a> flatbuffers::Follow<'a> for ArchiveType { + type Inner = Self; + #[inline] + unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { + let b = flatbuffers::read_scalar_at::(buf, loc); + Self(b) + } + } + + impl flatbuffers::Push for ArchiveType { + type Output = ArchiveType; + #[inline] + unsafe fn push(&self, dst: &mut [u8], _written_len: usize) { + flatbuffers::emplace_scalar::(dst, self.0); + } + } + + impl flatbuffers::EndianScalar for ArchiveType { + type Scalar = i8; + #[inline] + fn to_little_endian(self) -> i8 { + self.0.to_le() + } + #[inline] + #[allow(clippy::wrong_self_convention)] + fn from_little_endian(v: i8) -> Self { + let b = i8::from_le(v); + Self(b) + } + } + + impl<'a> flatbuffers::Verifiable for ArchiveType { + #[inline] + fn run_verifier( + v: &mut flatbuffers::Verifier, + pos: usize, + ) -> Result<(), flatbuffers::InvalidFlatbuffer> { + use self::flatbuffers::Verifiable; + i8::run_verifier(v, pos) + } + } + + impl flatbuffers::SimpleToVerifyInSlice for ArchiveType {} + pub enum RatingOffset {} + #[derive(Copy, Clone, PartialEq)] + + pub struct Rating<'a> { + pub _tab: flatbuffers::Table<'a>, + } + + impl<'a> flatbuffers::Follow<'a> for Rating<'a> { + type Inner = Rating<'a>; + #[inline] + unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { + Self { + _tab: flatbuffers::Table::new(buf, loc), + } + } + } + + impl<'a> Rating<'a> { + pub const VT_VIOLENT: flatbuffers::VOffsetT = 4; + pub const VT_SEXUAL: flatbuffers::VOffsetT = 6; + pub const VT_PROFANE: flatbuffers::VOffsetT = 8; + pub const VT_SUBSTANCE: flatbuffers::VOffsetT = 10; + pub const VT_HATE: flatbuffers::VOffsetT = 12; + pub const VT_HARM: flatbuffers::VOffsetT = 14; + pub const VT_MATURE: flatbuffers::VOffsetT = 16; + pub const VT_BULLY: flatbuffers::VOffsetT = 18; + + #[inline] + pub unsafe fn init_from_table(table: flatbuffers::Table<'a>) -> Self { + Rating { _tab: table } + } + #[allow(unused_mut)] + pub fn create< + 'bldr: 'args, + 'args: 'mut_bldr, + 'mut_bldr, + A: flatbuffers::Allocator + 'bldr, + >( + _fbb: &'mut_bldr mut flatbuffers::FlatBufferBuilder<'bldr, A>, + args: &'args RatingArgs, + ) -> flatbuffers::WIPOffset> { + let mut builder = RatingBuilder::new(_fbb); + builder.add_bully(args.bully); + builder.add_mature(args.mature); + builder.add_harm(args.harm); + builder.add_hate(args.hate); + builder.add_substance(args.substance); + builder.add_profane(args.profane); + builder.add_sexual(args.sexual); + builder.add_violent(args.violent); + builder.finish() + } + + #[inline] + pub fn violent(&self) -> RatingLevel { + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { + self._tab + .get::(Rating::VT_VIOLENT, Some(RatingLevel::unused)) + .unwrap() + } + } + #[inline] + pub fn sexual(&self) -> RatingLevel { + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { + self._tab + .get::(Rating::VT_SEXUAL, Some(RatingLevel::unused)) + .unwrap() + } + } + #[inline] + pub fn profane(&self) -> RatingLevel { + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { + self._tab + .get::(Rating::VT_PROFANE, Some(RatingLevel::unused)) + .unwrap() + } + } + #[inline] + pub fn substance(&self) -> RatingLevel { + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { + self._tab + .get::(Rating::VT_SUBSTANCE, Some(RatingLevel::unused)) + .unwrap() + } + } + #[inline] + pub fn hate(&self) -> RatingLevel { + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { + self._tab + .get::(Rating::VT_HATE, Some(RatingLevel::unused)) + .unwrap() + } + } + #[inline] + pub fn harm(&self) -> RatingLevel { + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { + self._tab + .get::(Rating::VT_HARM, Some(RatingLevel::unused)) + .unwrap() + } + } + #[inline] + pub fn mature(&self) -> RatingLevel { + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { + self._tab + .get::(Rating::VT_MATURE, Some(RatingLevel::unused)) + .unwrap() + } + } + #[inline] + pub fn bully(&self) -> RatingLevel { + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { + self._tab + .get::(Rating::VT_BULLY, Some(RatingLevel::unused)) + .unwrap() + } + } + } + + impl flatbuffers::Verifiable for Rating<'_> { + #[inline] + fn run_verifier( + v: &mut flatbuffers::Verifier, + pos: usize, + ) -> Result<(), flatbuffers::InvalidFlatbuffer> { + use self::flatbuffers::Verifiable; + v.visit_table(pos)? + .visit_field::("violent", Self::VT_VIOLENT, false)? + .visit_field::("sexual", Self::VT_SEXUAL, false)? + .visit_field::("profane", Self::VT_PROFANE, false)? + .visit_field::("substance", Self::VT_SUBSTANCE, false)? + .visit_field::("hate", Self::VT_HATE, false)? + .visit_field::("harm", Self::VT_HARM, false)? + .visit_field::("mature", Self::VT_MATURE, false)? + .visit_field::("bully", Self::VT_BULLY, false)? + .finish(); + Ok(()) + } + } + pub struct RatingArgs { + pub violent: RatingLevel, + pub sexual: RatingLevel, + pub profane: RatingLevel, + pub substance: RatingLevel, + pub hate: RatingLevel, + pub harm: RatingLevel, + pub mature: RatingLevel, + pub bully: RatingLevel, + } + impl<'a> Default for RatingArgs { + #[inline] + fn default() -> Self { + RatingArgs { + violent: RatingLevel::unused, + sexual: RatingLevel::unused, + profane: RatingLevel::unused, + substance: RatingLevel::unused, + hate: RatingLevel::unused, + harm: RatingLevel::unused, + mature: RatingLevel::unused, + bully: RatingLevel::unused, + } + } + } + + pub struct RatingBuilder<'a: 'b, 'b, A: flatbuffers::Allocator + 'a> { + fbb_: &'b mut flatbuffers::FlatBufferBuilder<'a, A>, + start_: flatbuffers::WIPOffset, + } + impl<'a: 'b, 'b, A: flatbuffers::Allocator + 'a> RatingBuilder<'a, 'b, A> { + #[inline] + pub fn add_violent(&mut self, violent: RatingLevel) { + self.fbb_ + .push_slot::(Rating::VT_VIOLENT, violent, RatingLevel::unused); + } + #[inline] + pub fn add_sexual(&mut self, sexual: RatingLevel) { + self.fbb_ + .push_slot::(Rating::VT_SEXUAL, sexual, RatingLevel::unused); + } + #[inline] + pub fn add_profane(&mut self, profane: RatingLevel) { + self.fbb_ + .push_slot::(Rating::VT_PROFANE, profane, RatingLevel::unused); + } + #[inline] + pub fn add_substance(&mut self, substance: RatingLevel) { + self.fbb_.push_slot::( + Rating::VT_SUBSTANCE, + substance, + RatingLevel::unused, + ); + } + #[inline] + pub fn add_hate(&mut self, hate: RatingLevel) { + self.fbb_ + .push_slot::(Rating::VT_HATE, hate, RatingLevel::unused); + } + #[inline] + pub fn add_harm(&mut self, harm: RatingLevel) { + self.fbb_ + .push_slot::(Rating::VT_HARM, harm, RatingLevel::unused); + } + #[inline] + pub fn add_mature(&mut self, mature: RatingLevel) { + self.fbb_ + .push_slot::(Rating::VT_MATURE, mature, RatingLevel::unused); + } + #[inline] + pub fn add_bully(&mut self, bully: RatingLevel) { + self.fbb_ + .push_slot::(Rating::VT_BULLY, bully, RatingLevel::unused); + } + #[inline] + pub fn new( + _fbb: &'b mut flatbuffers::FlatBufferBuilder<'a, A>, + ) -> RatingBuilder<'a, 'b, A> { + let start = _fbb.start_table(); + RatingBuilder { + fbb_: _fbb, + start_: start, + } + } + #[inline] + pub fn finish(self) -> flatbuffers::WIPOffset> { + let o = self.fbb_.end_table(self.start_); + flatbuffers::WIPOffset::new(o.value()) + } + } + + impl core::fmt::Debug for Rating<'_> { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + let mut ds = f.debug_struct("Rating"); + ds.field("violent", &self.violent()); + ds.field("sexual", &self.sexual()); + ds.field("profane", &self.profane()); + ds.field("substance", &self.substance()); + ds.field("hate", &self.hate()); + ds.field("harm", &self.harm()); + ds.field("mature", &self.mature()); + ds.field("bully", &self.bully()); + ds.finish() + } + } + pub enum PurposeOffset {} + #[derive(Copy, Clone, PartialEq)] + + pub struct Purpose<'a> { + pub _tab: flatbuffers::Table<'a>, + } + + impl<'a> flatbuffers::Follow<'a> for Purpose<'a> { + type Inner = Purpose<'a>; + #[inline] + unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { + Self { + _tab: flatbuffers::Table::new(buf, loc), + } + } + } + + impl<'a> Purpose<'a> { + pub const VT_EDUCATIONAL: flatbuffers::VOffsetT = 4; + pub const VT_ENTERTAINMENT: flatbuffers::VOffsetT = 6; + pub const VT_NEWS: flatbuffers::VOffsetT = 8; + pub const VT_PROMOTIONAL: flatbuffers::VOffsetT = 10; + pub const VT_PERSONAL: flatbuffers::VOffsetT = 12; + pub const VT_OPINION: flatbuffers::VOffsetT = 14; + pub const VT_TRANSACTIONAL: flatbuffers::VOffsetT = 16; + pub const VT_HARMFUL: flatbuffers::VOffsetT = 18; + pub const VT_CONFIDENCE: flatbuffers::VOffsetT = 20; + + #[inline] + pub unsafe fn init_from_table(table: flatbuffers::Table<'a>) -> Self { + Purpose { _tab: table } + } + #[allow(unused_mut)] + pub fn create< + 'bldr: 'args, + 'args: 'mut_bldr, + 'mut_bldr, + A: flatbuffers::Allocator + 'bldr, + >( + _fbb: &'mut_bldr mut flatbuffers::FlatBufferBuilder<'bldr, A>, + args: &'args PurposeArgs, + ) -> flatbuffers::WIPOffset> { + let mut builder = PurposeBuilder::new(_fbb); + builder.add_confidence(args.confidence); + builder.add_harmful(args.harmful); + builder.add_transactional(args.transactional); + builder.add_opinion(args.opinion); + builder.add_personal(args.personal); + builder.add_promotional(args.promotional); + builder.add_news(args.news); + builder.add_entertainment(args.entertainment); + builder.add_educational(args.educational); + builder.finish() + } + + #[inline] + pub fn educational(&self) -> f32 { + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { + self._tab + .get::(Purpose::VT_EDUCATIONAL, Some(0.0)) + .unwrap() + } + } + #[inline] + pub fn entertainment(&self) -> f32 { + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { + self._tab + .get::(Purpose::VT_ENTERTAINMENT, Some(0.0)) + .unwrap() + } + } + #[inline] + pub fn news(&self) -> f32 { + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { self._tab.get::(Purpose::VT_NEWS, Some(0.0)).unwrap() } + } + #[inline] + pub fn promotional(&self) -> f32 { + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { + self._tab + .get::(Purpose::VT_PROMOTIONAL, Some(0.0)) + .unwrap() + } + } + #[inline] + pub fn personal(&self) -> f32 { + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { + self._tab + .get::(Purpose::VT_PERSONAL, Some(0.0)) + .unwrap() + } + } + #[inline] + pub fn opinion(&self) -> f32 { + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { + self._tab + .get::(Purpose::VT_OPINION, Some(0.0)) + .unwrap() + } + } + #[inline] + pub fn transactional(&self) -> f32 { + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { + self._tab + .get::(Purpose::VT_TRANSACTIONAL, Some(0.0)) + .unwrap() + } + } + #[inline] + pub fn harmful(&self) -> f32 { + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { + self._tab + .get::(Purpose::VT_HARMFUL, Some(0.0)) + .unwrap() + } + } + #[inline] + pub fn confidence(&self) -> f32 { + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { + self._tab + .get::(Purpose::VT_CONFIDENCE, Some(0.0)) + .unwrap() + } + } + } + + impl flatbuffers::Verifiable for Purpose<'_> { + #[inline] + fn run_verifier( + v: &mut flatbuffers::Verifier, + pos: usize, + ) -> Result<(), flatbuffers::InvalidFlatbuffer> { + use self::flatbuffers::Verifiable; + v.visit_table(pos)? + .visit_field::("educational", Self::VT_EDUCATIONAL, false)? + .visit_field::("entertainment", Self::VT_ENTERTAINMENT, false)? + .visit_field::("news", Self::VT_NEWS, false)? + .visit_field::("promotional", Self::VT_PROMOTIONAL, false)? + .visit_field::("personal", Self::VT_PERSONAL, false)? + .visit_field::("opinion", Self::VT_OPINION, false)? + .visit_field::("transactional", Self::VT_TRANSACTIONAL, false)? + .visit_field::("harmful", Self::VT_HARMFUL, false)? + .visit_field::("confidence", Self::VT_CONFIDENCE, false)? + .finish(); + Ok(()) + } + } + pub struct PurposeArgs { + pub educational: f32, + pub entertainment: f32, + pub news: f32, + pub promotional: f32, + pub personal: f32, + pub opinion: f32, + pub transactional: f32, + pub harmful: f32, + pub confidence: f32, + } + impl<'a> Default for PurposeArgs { + #[inline] + fn default() -> Self { + PurposeArgs { + educational: 0.0, + entertainment: 0.0, + news: 0.0, + promotional: 0.0, + personal: 0.0, + opinion: 0.0, + transactional: 0.0, + harmful: 0.0, + confidence: 0.0, + } + } + } + + pub struct PurposeBuilder<'a: 'b, 'b, A: flatbuffers::Allocator + 'a> { + fbb_: &'b mut flatbuffers::FlatBufferBuilder<'a, A>, + start_: flatbuffers::WIPOffset, + } + impl<'a: 'b, 'b, A: flatbuffers::Allocator + 'a> PurposeBuilder<'a, 'b, A> { + #[inline] + pub fn add_educational(&mut self, educational: f32) { + self.fbb_ + .push_slot::(Purpose::VT_EDUCATIONAL, educational, 0.0); + } + #[inline] + pub fn add_entertainment(&mut self, entertainment: f32) { + self.fbb_ + .push_slot::(Purpose::VT_ENTERTAINMENT, entertainment, 0.0); + } + #[inline] + pub fn add_news(&mut self, news: f32) { + self.fbb_.push_slot::(Purpose::VT_NEWS, news, 0.0); + } + #[inline] + pub fn add_promotional(&mut self, promotional: f32) { + self.fbb_ + .push_slot::(Purpose::VT_PROMOTIONAL, promotional, 0.0); + } + #[inline] + pub fn add_personal(&mut self, personal: f32) { + self.fbb_ + .push_slot::(Purpose::VT_PERSONAL, personal, 0.0); + } + #[inline] + pub fn add_opinion(&mut self, opinion: f32) { + self.fbb_ + .push_slot::(Purpose::VT_OPINION, opinion, 0.0); + } + #[inline] + pub fn add_transactional(&mut self, transactional: f32) { + self.fbb_ + .push_slot::(Purpose::VT_TRANSACTIONAL, transactional, 0.0); + } + #[inline] + pub fn add_harmful(&mut self, harmful: f32) { + self.fbb_ + .push_slot::(Purpose::VT_HARMFUL, harmful, 0.0); + } + #[inline] + pub fn add_confidence(&mut self, confidence: f32) { + self.fbb_ + .push_slot::(Purpose::VT_CONFIDENCE, confidence, 0.0); + } + #[inline] + pub fn new( + _fbb: &'b mut flatbuffers::FlatBufferBuilder<'a, A>, + ) -> PurposeBuilder<'a, 'b, A> { + let start = _fbb.start_table(); + PurposeBuilder { + fbb_: _fbb, + start_: start, + } + } + #[inline] + pub fn finish(self) -> flatbuffers::WIPOffset> { + let o = self.fbb_.end_table(self.start_); + flatbuffers::WIPOffset::new(o.value()) + } + } + + impl core::fmt::Debug for Purpose<'_> { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + let mut ds = f.debug_struct("Purpose"); + ds.field("educational", &self.educational()); + ds.field("entertainment", &self.entertainment()); + ds.field("news", &self.news()); + ds.field("promotional", &self.promotional()); + ds.field("personal", &self.personal()); + ds.field("opinion", &self.opinion()); + ds.field("transactional", &self.transactional()); + ds.field("harmful", &self.harmful()); + ds.field("confidence", &self.confidence()); + ds.finish() + } + } + pub enum FormatInfoOffset {} + #[derive(Copy, Clone, PartialEq)] + + pub struct FormatInfo<'a> { + pub _tab: flatbuffers::Table<'a>, + } + + impl<'a> flatbuffers::Follow<'a> for FormatInfo<'a> { + type Inner = FormatInfo<'a>; + #[inline] + unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { + Self { + _tab: flatbuffers::Table::new(buf, loc), + } + } + } + + impl<'a> FormatInfo<'a> { + pub const VT_TYPE_: flatbuffers::VOffsetT = 4; + pub const VT_VERSION: flatbuffers::VOffsetT = 6; + pub const VT_PROFILE: flatbuffers::VOffsetT = 8; + + #[inline] + pub unsafe fn init_from_table(table: flatbuffers::Table<'a>) -> Self { + FormatInfo { _tab: table } + } + #[allow(unused_mut)] + pub fn create< + 'bldr: 'args, + 'args: 'mut_bldr, + 'mut_bldr, + A: flatbuffers::Allocator + 'bldr, + >( + _fbb: &'mut_bldr mut flatbuffers::FlatBufferBuilder<'bldr, A>, + args: &'args FormatInfoArgs<'args>, + ) -> flatbuffers::WIPOffset> { + let mut builder = FormatInfoBuilder::new(_fbb); + if let Some(x) = args.profile { + builder.add_profile(x); + } + if let Some(x) = args.version { + builder.add_version(x); + } + builder.add_type_(args.type_); + builder.finish() + } + + #[inline] + pub fn type_(&self) -> FormatType { + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { + self._tab + .get::(FormatInfo::VT_TYPE_, Some(FormatType::plain)) + .unwrap() + } + } + #[inline] + pub fn version(&self) -> Option<&'a str> { + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { + self._tab + .get::>(FormatInfo::VT_VERSION, None) + } + } + #[inline] + pub fn profile(&self) -> Option<&'a str> { + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { + self._tab + .get::>(FormatInfo::VT_PROFILE, None) + } + } + } + + impl flatbuffers::Verifiable for FormatInfo<'_> { + #[inline] + fn run_verifier( + v: &mut flatbuffers::Verifier, + pos: usize, + ) -> Result<(), flatbuffers::InvalidFlatbuffer> { + use self::flatbuffers::Verifiable; + v.visit_table(pos)? + .visit_field::("type_", Self::VT_TYPE_, false)? + .visit_field::>( + "version", + Self::VT_VERSION, + false, + )? + .visit_field::>( + "profile", + Self::VT_PROFILE, + false, + )? + .finish(); + Ok(()) + } + } + pub struct FormatInfoArgs<'a> { + pub type_: FormatType, + pub version: Option>, + pub profile: Option>, + } + impl<'a> Default for FormatInfoArgs<'a> { + #[inline] + fn default() -> Self { + FormatInfoArgs { + type_: FormatType::plain, + version: None, + profile: None, + } + } + } + + pub struct FormatInfoBuilder<'a: 'b, 'b, A: flatbuffers::Allocator + 'a> { + fbb_: &'b mut flatbuffers::FlatBufferBuilder<'a, A>, + start_: flatbuffers::WIPOffset, + } + impl<'a: 'b, 'b, A: flatbuffers::Allocator + 'a> FormatInfoBuilder<'a, 'b, A> { + #[inline] + pub fn add_type_(&mut self, type_: FormatType) { + self.fbb_ + .push_slot::(FormatInfo::VT_TYPE_, type_, FormatType::plain); + } + #[inline] + pub fn add_version(&mut self, version: flatbuffers::WIPOffset<&'b str>) { + self.fbb_ + .push_slot_always::>(FormatInfo::VT_VERSION, version); + } + #[inline] + pub fn add_profile(&mut self, profile: flatbuffers::WIPOffset<&'b str>) { + self.fbb_ + .push_slot_always::>(FormatInfo::VT_PROFILE, profile); + } + #[inline] + pub fn new( + _fbb: &'b mut flatbuffers::FlatBufferBuilder<'a, A>, + ) -> FormatInfoBuilder<'a, 'b, A> { + let start = _fbb.start_table(); + FormatInfoBuilder { + fbb_: _fbb, + start_: start, + } + } + #[inline] + pub fn finish(self) -> flatbuffers::WIPOffset> { + let o = self.fbb_.end_table(self.start_); + flatbuffers::WIPOffset::new(o.value()) + } + } + + impl core::fmt::Debug for FormatInfo<'_> { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + let mut ds = f.debug_struct("FormatInfo"); + ds.field("type_", &self.type_()); + ds.field("version", &self.version()); + ds.field("profile", &self.profile()); + ds.finish() + } + } + pub enum ArchiveInfoOffset {} + #[derive(Copy, Clone, PartialEq)] + + pub struct ArchiveInfo<'a> { + pub _tab: flatbuffers::Table<'a>, + } + + impl<'a> flatbuffers::Follow<'a> for ArchiveInfo<'a> { + type Inner = ArchiveInfo<'a>; + #[inline] + unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { + Self { + _tab: flatbuffers::Table::new(buf, loc), + } + } + } + + impl<'a> ArchiveInfo<'a> { + pub const VT_TYPE_: flatbuffers::VOffsetT = 4; + pub const VT_VERSION: flatbuffers::VOffsetT = 6; + pub const VT_PROFILE: flatbuffers::VOffsetT = 8; + + #[inline] + pub unsafe fn init_from_table(table: flatbuffers::Table<'a>) -> Self { + ArchiveInfo { _tab: table } + } + #[allow(unused_mut)] + pub fn create< + 'bldr: 'args, + 'args: 'mut_bldr, + 'mut_bldr, + A: flatbuffers::Allocator + 'bldr, + >( + _fbb: &'mut_bldr mut flatbuffers::FlatBufferBuilder<'bldr, A>, + args: &'args ArchiveInfoArgs<'args>, + ) -> flatbuffers::WIPOffset> { + let mut builder = ArchiveInfoBuilder::new(_fbb); + if let Some(x) = args.profile { + builder.add_profile(x); + } + if let Some(x) = args.version { + builder.add_version(x); + } + builder.add_type_(args.type_); + builder.finish() + } + + #[inline] + pub fn type_(&self) -> ArchiveType { + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { + self._tab + .get::(ArchiveInfo::VT_TYPE_, Some(ArchiveType::none)) + .unwrap() + } + } + #[inline] + pub fn version(&self) -> Option<&'a str> { + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { + self._tab + .get::>(ArchiveInfo::VT_VERSION, None) + } + } + #[inline] + pub fn profile(&self) -> Option<&'a str> { + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { + self._tab + .get::>(ArchiveInfo::VT_PROFILE, None) + } + } + } + + impl flatbuffers::Verifiable for ArchiveInfo<'_> { + #[inline] + fn run_verifier( + v: &mut flatbuffers::Verifier, + pos: usize, + ) -> Result<(), flatbuffers::InvalidFlatbuffer> { + use self::flatbuffers::Verifiable; + v.visit_table(pos)? + .visit_field::("type_", Self::VT_TYPE_, false)? + .visit_field::>( + "version", + Self::VT_VERSION, + false, + )? + .visit_field::>( + "profile", + Self::VT_PROFILE, + false, + )? + .finish(); + Ok(()) + } + } + pub struct ArchiveInfoArgs<'a> { + pub type_: ArchiveType, + pub version: Option>, + pub profile: Option>, + } + impl<'a> Default for ArchiveInfoArgs<'a> { + #[inline] + fn default() -> Self { + ArchiveInfoArgs { + type_: ArchiveType::none, + version: None, + profile: None, + } + } + } + + pub struct ArchiveInfoBuilder<'a: 'b, 'b, A: flatbuffers::Allocator + 'a> { + fbb_: &'b mut flatbuffers::FlatBufferBuilder<'a, A>, + start_: flatbuffers::WIPOffset, + } + impl<'a: 'b, 'b, A: flatbuffers::Allocator + 'a> ArchiveInfoBuilder<'a, 'b, A> { + #[inline] + pub fn add_type_(&mut self, type_: ArchiveType) { + self.fbb_ + .push_slot::(ArchiveInfo::VT_TYPE_, type_, ArchiveType::none); + } + #[inline] + pub fn add_version(&mut self, version: flatbuffers::WIPOffset<&'b str>) { + self.fbb_ + .push_slot_always::>(ArchiveInfo::VT_VERSION, version); + } + #[inline] + pub fn add_profile(&mut self, profile: flatbuffers::WIPOffset<&'b str>) { + self.fbb_ + .push_slot_always::>(ArchiveInfo::VT_PROFILE, profile); + } + #[inline] + pub fn new( + _fbb: &'b mut flatbuffers::FlatBufferBuilder<'a, A>, + ) -> ArchiveInfoBuilder<'a, 'b, A> { + let start = _fbb.start_table(); + ArchiveInfoBuilder { + fbb_: _fbb, + start_: start, + } + } + #[inline] + pub fn finish(self) -> flatbuffers::WIPOffset> { + let o = self.fbb_.end_table(self.start_); + flatbuffers::WIPOffset::new(o.value()) + } + } + + impl core::fmt::Debug for ArchiveInfo<'_> { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + let mut ds = f.debug_struct("ArchiveInfo"); + ds.field("type_", &self.type_()); + ds.field("version", &self.version()); + ds.field("profile", &self.profile()); + ds.finish() + } + } + pub enum ContentFormatOffset {} + #[derive(Copy, Clone, PartialEq)] + + pub struct ContentFormat<'a> { + pub _tab: flatbuffers::Table<'a>, + } + + impl<'a> flatbuffers::Follow<'a> for ContentFormat<'a> { + type Inner = ContentFormat<'a>; + #[inline] + unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { + Self { + _tab: flatbuffers::Table::new(buf, loc), + } + } + } + + impl<'a> ContentFormat<'a> { + pub const VT_MEDIA_TYPE: flatbuffers::VOffsetT = 4; + pub const VT_DATA_ENCODING: flatbuffers::VOffsetT = 6; + pub const VT_FORMAT: flatbuffers::VOffsetT = 8; + + #[inline] + pub unsafe fn init_from_table(table: flatbuffers::Table<'a>) -> Self { + ContentFormat { _tab: table } + } + #[allow(unused_mut)] + pub fn create< + 'bldr: 'args, + 'args: 'mut_bldr, + 'mut_bldr, + A: flatbuffers::Allocator + 'bldr, + >( + _fbb: &'mut_bldr mut flatbuffers::FlatBufferBuilder<'bldr, A>, + args: &'args ContentFormatArgs<'args>, + ) -> flatbuffers::WIPOffset> { + let mut builder = ContentFormatBuilder::new(_fbb); + if let Some(x) = args.format { + builder.add_format(x); + } + builder.add_data_encoding(args.data_encoding); + builder.add_media_type(args.media_type); + builder.finish() + } + + #[inline] + pub fn media_type(&self) -> MediaType { + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { + self._tab + .get::(ContentFormat::VT_MEDIA_TYPE, Some(MediaType::unused)) + .unwrap() + } + } + #[inline] + pub fn data_encoding(&self) -> DataEncoding { + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { + self._tab + .get::( + ContentFormat::VT_DATA_ENCODING, + Some(DataEncoding::binary), + ) + .unwrap() + } + } + #[inline] + pub fn format(&self) -> Option> { + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { + self._tab + .get::>(ContentFormat::VT_FORMAT, None) + } + } + } + + impl flatbuffers::Verifiable for ContentFormat<'_> { + #[inline] + fn run_verifier( + v: &mut flatbuffers::Verifier, + pos: usize, + ) -> Result<(), flatbuffers::InvalidFlatbuffer> { + use self::flatbuffers::Verifiable; + v.visit_table(pos)? + .visit_field::("media_type", Self::VT_MEDIA_TYPE, false)? + .visit_field::("data_encoding", Self::VT_DATA_ENCODING, false)? + .visit_field::>( + "format", + Self::VT_FORMAT, + false, + )? + .finish(); + Ok(()) + } + } + pub struct ContentFormatArgs<'a> { + pub media_type: MediaType, + pub data_encoding: DataEncoding, + pub format: Option>>, + } + impl<'a> Default for ContentFormatArgs<'a> { + #[inline] + fn default() -> Self { + ContentFormatArgs { + media_type: MediaType::unused, + data_encoding: DataEncoding::binary, + format: None, + } + } + } + + pub struct ContentFormatBuilder<'a: 'b, 'b, A: flatbuffers::Allocator + 'a> { + fbb_: &'b mut flatbuffers::FlatBufferBuilder<'a, A>, + start_: flatbuffers::WIPOffset, + } + impl<'a: 'b, 'b, A: flatbuffers::Allocator + 'a> ContentFormatBuilder<'a, 'b, A> { + #[inline] + pub fn add_media_type(&mut self, media_type: MediaType) { + self.fbb_.push_slot::( + ContentFormat::VT_MEDIA_TYPE, + media_type, + MediaType::unused, + ); + } + #[inline] + pub fn add_data_encoding(&mut self, data_encoding: DataEncoding) { + self.fbb_.push_slot::( + ContentFormat::VT_DATA_ENCODING, + data_encoding, + DataEncoding::binary, + ); + } + #[inline] + pub fn add_format(&mut self, format: flatbuffers::WIPOffset>) { + self.fbb_ + .push_slot_always::>( + ContentFormat::VT_FORMAT, + format, + ); + } + #[inline] + pub fn new( + _fbb: &'b mut flatbuffers::FlatBufferBuilder<'a, A>, + ) -> ContentFormatBuilder<'a, 'b, A> { + let start = _fbb.start_table(); + ContentFormatBuilder { + fbb_: _fbb, + start_: start, + } + } + #[inline] + pub fn finish(self) -> flatbuffers::WIPOffset> { + let o = self.fbb_.end_table(self.start_); + flatbuffers::WIPOffset::new(o.value()) + } + } + + impl core::fmt::Debug for ContentFormat<'_> { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + let mut ds = f.debug_struct("ContentFormat"); + ds.field("media_type", &self.media_type()); + ds.field("data_encoding", &self.data_encoding()); + ds.field("format", &self.format()); + ds.finish() + } + } + pub enum MetadataOffset {} + #[derive(Copy, Clone, PartialEq)] + + pub struct Metadata<'a> { + pub _tab: flatbuffers::Table<'a>, + } + + impl<'a> flatbuffers::Follow<'a> for Metadata<'a> { + type Inner = Metadata<'a>; + #[inline] + unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { + Self { + _tab: flatbuffers::Table::new(buf, loc), + } + } + } + + impl<'a> Metadata<'a> { + pub const VT_CREATED: flatbuffers::VOffsetT = 4; + pub const VT_ID: flatbuffers::VOffsetT = 6; + pub const VT_RELATED: flatbuffers::VOffsetT = 8; + pub const VT_RATING: flatbuffers::VOffsetT = 10; + pub const VT_PURPOSE: flatbuffers::VOffsetT = 12; + pub const VT_TOPICS: flatbuffers::VOffsetT = 14; + pub const VT_ARCHIVE: flatbuffers::VOffsetT = 16; + pub const VT_CONTENT: flatbuffers::VOffsetT = 18; + + #[inline] + pub unsafe fn init_from_table(table: flatbuffers::Table<'a>) -> Self { + Metadata { _tab: table } + } + #[allow(unused_mut)] + pub fn create< + 'bldr: 'args, + 'args: 'mut_bldr, + 'mut_bldr, + A: flatbuffers::Allocator + 'bldr, + >( + _fbb: &'mut_bldr mut flatbuffers::FlatBufferBuilder<'bldr, A>, + args: &'args MetadataArgs<'args>, + ) -> flatbuffers::WIPOffset> { + let mut builder = MetadataBuilder::new(_fbb); + builder.add_created(args.created); + if let Some(x) = args.content { + builder.add_content(x); + } + if let Some(x) = args.archive { + builder.add_archive(x); + } + if let Some(x) = args.topics { + builder.add_topics(x); + } + if let Some(x) = args.purpose { + builder.add_purpose(x); + } + if let Some(x) = args.rating { + builder.add_rating(x); + } + if let Some(x) = args.related { + builder.add_related(x); + } + if let Some(x) = args.id { + builder.add_id(x); + } + builder.finish() + } + + #[inline] + pub fn created(&self) -> i64 { + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { self._tab.get::(Metadata::VT_CREATED, Some(0)).unwrap() } + } + #[inline] + pub fn id(&self) -> Option> { + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { + self._tab + .get::>>( + Metadata::VT_ID, + None, + ) + } + } + #[inline] + pub fn related(&self) -> Option> { + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { + self._tab + .get::>>( + Metadata::VT_RELATED, + None, + ) + } + } + #[inline] + pub fn rating(&self) -> Option> { + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { + self._tab + .get::>(Metadata::VT_RATING, None) + } + } + #[inline] + pub fn purpose(&self) -> Option> { + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { + self._tab + .get::>(Metadata::VT_PURPOSE, None) + } + } + #[inline] + pub fn topics(&self) -> Option> { + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { + self._tab + .get::>>( + Metadata::VT_TOPICS, + None, + ) + } + } + #[inline] + pub fn archive(&self) -> Option> { + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { + self._tab + .get::>(Metadata::VT_ARCHIVE, None) + } + } + #[inline] + pub fn content(&self) -> Option> { + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { + self._tab + .get::>(Metadata::VT_CONTENT, None) + } + } + } + + impl flatbuffers::Verifiable for Metadata<'_> { + #[inline] + fn run_verifier( + v: &mut flatbuffers::Verifier, + pos: usize, + ) -> Result<(), flatbuffers::InvalidFlatbuffer> { + use self::flatbuffers::Verifiable; + v.visit_table(pos)? + .visit_field::("created", Self::VT_CREATED, false)? + .visit_field::>>( + "id", + Self::VT_ID, + false, + )? + .visit_field::>>( + "related", + Self::VT_RELATED, + false, + )? + .visit_field::>( + "rating", + Self::VT_RATING, + false, + )? + .visit_field::>( + "purpose", + Self::VT_PURPOSE, + false, + )? + .visit_field::>>( + "topics", + Self::VT_TOPICS, + false, + )? + .visit_field::>( + "archive", + Self::VT_ARCHIVE, + false, + )? + .visit_field::>( + "content", + Self::VT_CONTENT, + false, + )? + .finish(); + Ok(()) + } + } + pub struct MetadataArgs<'a> { + pub created: i64, + pub id: Option>>, + pub related: Option>>, + pub rating: Option>>, + pub purpose: Option>>, + pub topics: Option>>, + pub archive: Option>>, + pub content: Option>>, + } + impl<'a> Default for MetadataArgs<'a> { + #[inline] + fn default() -> Self { + MetadataArgs { + created: 0, + id: None, + related: None, + rating: None, + purpose: None, + topics: None, + archive: None, + content: None, + } + } + } + + pub struct MetadataBuilder<'a: 'b, 'b, A: flatbuffers::Allocator + 'a> { + fbb_: &'b mut flatbuffers::FlatBufferBuilder<'a, A>, + start_: flatbuffers::WIPOffset, + } + impl<'a: 'b, 'b, A: flatbuffers::Allocator + 'a> MetadataBuilder<'a, 'b, A> { + #[inline] + pub fn add_created(&mut self, created: i64) { + self.fbb_.push_slot::(Metadata::VT_CREATED, created, 0); + } + #[inline] + pub fn add_id(&mut self, id: flatbuffers::WIPOffset>) { + self.fbb_ + .push_slot_always::>(Metadata::VT_ID, id); + } + #[inline] + pub fn add_related( + &mut self, + related: flatbuffers::WIPOffset>, + ) { + self.fbb_ + .push_slot_always::>(Metadata::VT_RELATED, related); + } + #[inline] + pub fn add_rating(&mut self, rating: flatbuffers::WIPOffset>) { + self.fbb_ + .push_slot_always::>(Metadata::VT_RATING, rating); + } + #[inline] + pub fn add_purpose(&mut self, purpose: flatbuffers::WIPOffset>) { + self.fbb_ + .push_slot_always::>(Metadata::VT_PURPOSE, purpose); + } + #[inline] + pub fn add_topics(&mut self, topics: flatbuffers::WIPOffset>) { + self.fbb_ + .push_slot_always::>(Metadata::VT_TOPICS, topics); + } + #[inline] + pub fn add_archive(&mut self, archive: flatbuffers::WIPOffset>) { + self.fbb_ + .push_slot_always::>( + Metadata::VT_ARCHIVE, + archive, + ); + } + #[inline] + pub fn add_content(&mut self, content: flatbuffers::WIPOffset>) { + self.fbb_ + .push_slot_always::>( + Metadata::VT_CONTENT, + content, + ); + } + #[inline] + pub fn new( + _fbb: &'b mut flatbuffers::FlatBufferBuilder<'a, A>, + ) -> MetadataBuilder<'a, 'b, A> { + let start = _fbb.start_table(); + MetadataBuilder { + fbb_: _fbb, + start_: start, + } + } + #[inline] + pub fn finish(self) -> flatbuffers::WIPOffset> { + let o = self.fbb_.end_table(self.start_); + flatbuffers::WIPOffset::new(o.value()) + } + } + + impl core::fmt::Debug for Metadata<'_> { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + let mut ds = f.debug_struct("Metadata"); + ds.field("created", &self.created()); + ds.field("id", &self.id()); + ds.field("related", &self.related()); + ds.field("rating", &self.rating()); + ds.field("purpose", &self.purpose()); + ds.field("topics", &self.topics()); + ds.field("archive", &self.archive()); + ds.field("content", &self.content()); + ds.finish() + } + } #[inline] - unsafe fn push(&self, dst: &mut [u8], _written_len: usize) { - flatbuffers::emplace_scalar::(dst, self.0); - } -} - -impl flatbuffers::EndianScalar for RatingLevel { - type Scalar = i8; - #[inline] - fn to_little_endian(self) -> i8 { - self.0.to_le() - } - #[inline] - #[allow(clippy::wrong_self_convention)] - fn from_little_endian(v: i8) -> Self { - let b = i8::from_le(v); - Self(b) - } -} - -impl<'a> flatbuffers::Verifiable for RatingLevel { - #[inline] - fn run_verifier( - v: &mut flatbuffers::Verifier, pos: usize - ) -> Result<(), flatbuffers::InvalidFlatbuffer> { - use self::flatbuffers::Verifiable; - i8::run_verifier(v, pos) - } -} - -impl flatbuffers::SimpleToVerifyInSlice for RatingLevel {} -#[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")] -pub const ENUM_MIN_FORMAT_TYPE: i8 = 0; -#[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")] -pub const ENUM_MAX_FORMAT_TYPE: i8 = 30; -#[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")] -#[allow(non_camel_case_types)] -pub const ENUM_VALUES_FORMAT_TYPE: [FormatType; 10] = [ - FormatType::plain, - FormatType::html, - FormatType::csv, - FormatType::xml, - FormatType::json, - FormatType::jpeg, - FormatType::png, - FormatType::svg, - FormatType::gif, - FormatType::pdf, -]; - -#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Default)] -#[repr(transparent)] -pub struct FormatType(pub i8); -#[allow(non_upper_case_globals)] -impl FormatType { - pub const plain: Self = Self(0); - pub const html: Self = Self(1); - pub const csv: Self = Self(2); - pub const xml: Self = Self(3); - pub const json: Self = Self(4); - pub const jpeg: Self = Self(10); - pub const png: Self = Self(11); - pub const svg: Self = Self(12); - pub const gif: Self = Self(13); - pub const pdf: Self = Self(30); - - pub const ENUM_MIN: i8 = 0; - pub const ENUM_MAX: i8 = 30; - pub const ENUM_VALUES: &'static [Self] = &[ - Self::plain, - Self::html, - Self::csv, - Self::xml, - Self::json, - Self::jpeg, - Self::png, - Self::svg, - Self::gif, - Self::pdf, - ]; - /// Returns the variant's name or "" if unknown. - pub fn variant_name(self) -> Option<&'static str> { - match self { - Self::plain => Some("plain"), - Self::html => Some("html"), - Self::csv => Some("csv"), - Self::xml => Some("xml"), - Self::json => Some("json"), - Self::jpeg => Some("jpeg"), - Self::png => Some("png"), - Self::svg => Some("svg"), - Self::gif => Some("gif"), - Self::pdf => Some("pdf"), - _ => None, - } - } -} -impl core::fmt::Debug for FormatType { - fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result { - if let Some(name) = self.variant_name() { - f.write_str(name) - } else { - f.write_fmt(format_args!("", self.0)) - } - } -} -impl<'a> flatbuffers::Follow<'a> for FormatType { - type Inner = Self; - #[inline] - unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { - let b = flatbuffers::read_scalar_at::(buf, loc); - Self(b) - } -} - -impl flatbuffers::Push for FormatType { - type Output = FormatType; + /// Verifies that a buffer of bytes contains a `Metadata` + /// and returns it. + /// Note that verification is still experimental and may not + /// catch every error, or be maximally performant. For the + /// previous, unchecked, behavior use + /// `root_as_metadata_unchecked`. + pub fn root_as_metadata(buf: &[u8]) -> Result { + flatbuffers::root::(buf) + } #[inline] - unsafe fn push(&self, dst: &mut [u8], _written_len: usize) { - flatbuffers::emplace_scalar::(dst, self.0); - } -} - -impl flatbuffers::EndianScalar for FormatType { - type Scalar = i8; - #[inline] - fn to_little_endian(self) -> i8 { - self.0.to_le() - } - #[inline] - #[allow(clippy::wrong_self_convention)] - fn from_little_endian(v: i8) -> Self { - let b = i8::from_le(v); - Self(b) - } -} - -impl<'a> flatbuffers::Verifiable for FormatType { - #[inline] - fn run_verifier( - v: &mut flatbuffers::Verifier, pos: usize - ) -> Result<(), flatbuffers::InvalidFlatbuffer> { - use self::flatbuffers::Verifiable; - i8::run_verifier(v, pos) - } -} - -impl flatbuffers::SimpleToVerifyInSlice for FormatType {} -#[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")] -pub const ENUM_MIN_DATA_ENCODING: i8 = 0; -#[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")] -pub const ENUM_MAX_DATA_ENCODING: i8 = 5; -#[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")] -#[allow(non_camel_case_types)] -pub const ENUM_VALUES_DATA_ENCODING: [DataEncoding; 6] = [ - DataEncoding::binary, - DataEncoding::utf8, - DataEncoding::utf16, - DataEncoding::ascii, - DataEncoding::base64, - DataEncoding::quoted_printable, -]; - -#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Default)] -#[repr(transparent)] -pub struct DataEncoding(pub i8); -#[allow(non_upper_case_globals)] -impl DataEncoding { - pub const binary: Self = Self(0); - pub const utf8: Self = Self(1); - pub const utf16: Self = Self(2); - pub const ascii: Self = Self(3); - pub const base64: Self = Self(4); - pub const quoted_printable: Self = Self(5); - - pub const ENUM_MIN: i8 = 0; - pub const ENUM_MAX: i8 = 5; - pub const ENUM_VALUES: &'static [Self] = &[ - Self::binary, - Self::utf8, - Self::utf16, - Self::ascii, - Self::base64, - Self::quoted_printable, - ]; - /// Returns the variant's name or "" if unknown. - pub fn variant_name(self) -> Option<&'static str> { - match self { - Self::binary => Some("binary"), - Self::utf8 => Some("utf8"), - Self::utf16 => Some("utf16"), - Self::ascii => Some("ascii"), - Self::base64 => Some("base64"), - Self::quoted_printable => Some("quoted_printable"), - _ => None, - } - } -} -impl core::fmt::Debug for DataEncoding { - fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result { - if let Some(name) = self.variant_name() { - f.write_str(name) - } else { - f.write_fmt(format_args!("", self.0)) - } - } -} -impl<'a> flatbuffers::Follow<'a> for DataEncoding { - type Inner = Self; - #[inline] - unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { - let b = flatbuffers::read_scalar_at::(buf, loc); - Self(b) - } -} - -impl flatbuffers::Push for DataEncoding { - type Output = DataEncoding; + /// Verifies that a buffer of bytes contains a size prefixed + /// `Metadata` and returns it. + /// Note that verification is still experimental and may not + /// catch every error, or be maximally performant. For the + /// previous, unchecked, behavior use + /// `size_prefixed_root_as_metadata_unchecked`. + pub fn size_prefixed_root_as_metadata( + buf: &[u8], + ) -> Result { + flatbuffers::size_prefixed_root::(buf) + } #[inline] - unsafe fn push(&self, dst: &mut [u8], _written_len: usize) { - flatbuffers::emplace_scalar::(dst, self.0); - } -} - -impl flatbuffers::EndianScalar for DataEncoding { - type Scalar = i8; - #[inline] - fn to_little_endian(self) -> i8 { - self.0.to_le() - } - #[inline] - #[allow(clippy::wrong_self_convention)] - fn from_little_endian(v: i8) -> Self { - let b = i8::from_le(v); - Self(b) - } -} - -impl<'a> flatbuffers::Verifiable for DataEncoding { - #[inline] - fn run_verifier( - v: &mut flatbuffers::Verifier, pos: usize - ) -> Result<(), flatbuffers::InvalidFlatbuffer> { - use self::flatbuffers::Verifiable; - i8::run_verifier(v, pos) - } -} - -impl flatbuffers::SimpleToVerifyInSlice for DataEncoding {} -#[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")] -pub const ENUM_MIN_ARCHIVE_TYPE: i8 = 0; -#[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")] -pub const ENUM_MAX_ARCHIVE_TYPE: i8 = 7; -#[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")] -#[allow(non_camel_case_types)] -pub const ENUM_VALUES_ARCHIVE_TYPE: [ArchiveType; 8] = [ - ArchiveType::none, - ArchiveType::zip, - ArchiveType::tar, - ArchiveType::gzip, - ArchiveType::bzip2, - ArchiveType::xz, - ArchiveType::zstd, - ArchiveType::lz4, -]; - -#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Default)] -#[repr(transparent)] -pub struct ArchiveType(pub i8); -#[allow(non_upper_case_globals)] -impl ArchiveType { - pub const none: Self = Self(0); - pub const zip: Self = Self(1); - pub const tar: Self = Self(2); - pub const gzip: Self = Self(3); - pub const bzip2: Self = Self(4); - pub const xz: Self = Self(5); - pub const zstd: Self = Self(6); - pub const lz4: Self = Self(7); - - pub const ENUM_MIN: i8 = 0; - pub const ENUM_MAX: i8 = 7; - pub const ENUM_VALUES: &'static [Self] = &[ - Self::none, - Self::zip, - Self::tar, - Self::gzip, - Self::bzip2, - Self::xz, - Self::zstd, - Self::lz4, - ]; - /// Returns the variant's name or "" if unknown. - pub fn variant_name(self) -> Option<&'static str> { - match self { - Self::none => Some("none"), - Self::zip => Some("zip"), - Self::tar => Some("tar"), - Self::gzip => Some("gzip"), - Self::bzip2 => Some("bzip2"), - Self::xz => Some("xz"), - Self::zstd => Some("zstd"), - Self::lz4 => Some("lz4"), - _ => None, - } - } -} -impl core::fmt::Debug for ArchiveType { - fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result { - if let Some(name) = self.variant_name() { - f.write_str(name) - } else { - f.write_fmt(format_args!("", self.0)) - } - } -} -impl<'a> flatbuffers::Follow<'a> for ArchiveType { - type Inner = Self; - #[inline] - unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { - let b = flatbuffers::read_scalar_at::(buf, loc); - Self(b) - } -} - -impl flatbuffers::Push for ArchiveType { - type Output = ArchiveType; + /// Verifies, with the given options, that a buffer of bytes + /// contains a `Metadata` and returns it. + /// Note that verification is still experimental and may not + /// catch every error, or be maximally performant. For the + /// previous, unchecked, behavior use + /// `root_as_metadata_unchecked`. + pub fn root_as_metadata_with_opts<'b, 'o>( + opts: &'o flatbuffers::VerifierOptions, + buf: &'b [u8], + ) -> Result, flatbuffers::InvalidFlatbuffer> { + flatbuffers::root_with_opts::>(opts, buf) + } #[inline] - unsafe fn push(&self, dst: &mut [u8], _written_len: usize) { - flatbuffers::emplace_scalar::(dst, self.0); - } -} - -impl flatbuffers::EndianScalar for ArchiveType { - type Scalar = i8; - #[inline] - fn to_little_endian(self) -> i8 { - self.0.to_le() - } - #[inline] - #[allow(clippy::wrong_self_convention)] - fn from_little_endian(v: i8) -> Self { - let b = i8::from_le(v); - Self(b) - } -} - -impl<'a> flatbuffers::Verifiable for ArchiveType { - #[inline] - fn run_verifier( - v: &mut flatbuffers::Verifier, pos: usize - ) -> Result<(), flatbuffers::InvalidFlatbuffer> { - use self::flatbuffers::Verifiable; - i8::run_verifier(v, pos) - } -} - -impl flatbuffers::SimpleToVerifyInSlice for ArchiveType {} -pub enum RatingOffset {} -#[derive(Copy, Clone, PartialEq)] - -pub struct Rating<'a> { - pub _tab: flatbuffers::Table<'a>, -} - -impl<'a> flatbuffers::Follow<'a> for Rating<'a> { - type Inner = Rating<'a>; - #[inline] - unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { - Self { _tab: flatbuffers::Table::new(buf, loc) } - } -} - -impl<'a> Rating<'a> { - pub const VT_VIOLENT: flatbuffers::VOffsetT = 4; - pub const VT_SEXUAL: flatbuffers::VOffsetT = 6; - pub const VT_PROFANE: flatbuffers::VOffsetT = 8; - pub const VT_SUBSTANCE: flatbuffers::VOffsetT = 10; - pub const VT_HATE: flatbuffers::VOffsetT = 12; - pub const VT_HARM: flatbuffers::VOffsetT = 14; - pub const VT_MATURE: flatbuffers::VOffsetT = 16; - pub const VT_BULLY: flatbuffers::VOffsetT = 18; - - #[inline] - pub unsafe fn init_from_table(table: flatbuffers::Table<'a>) -> Self { - Rating { _tab: table } - } - #[allow(unused_mut)] - pub fn create<'bldr: 'args, 'args: 'mut_bldr, 'mut_bldr, A: flatbuffers::Allocator + 'bldr>( - _fbb: &'mut_bldr mut flatbuffers::FlatBufferBuilder<'bldr, A>, - args: &'args RatingArgs - ) -> flatbuffers::WIPOffset> { - let mut builder = RatingBuilder::new(_fbb); - builder.add_bully(args.bully); - builder.add_mature(args.mature); - builder.add_harm(args.harm); - builder.add_hate(args.hate); - builder.add_substance(args.substance); - builder.add_profane(args.profane); - builder.add_sexual(args.sexual); - builder.add_violent(args.violent); - builder.finish() - } - - - #[inline] - pub fn violent(&self) -> RatingLevel { - // Safety: - // Created from valid Table for this object - // which contains a valid value in this slot - unsafe { self._tab.get::(Rating::VT_VIOLENT, Some(RatingLevel::unused)).unwrap()} - } - #[inline] - pub fn sexual(&self) -> RatingLevel { - // Safety: - // Created from valid Table for this object - // which contains a valid value in this slot - unsafe { self._tab.get::(Rating::VT_SEXUAL, Some(RatingLevel::unused)).unwrap()} - } - #[inline] - pub fn profane(&self) -> RatingLevel { - // Safety: - // Created from valid Table for this object - // which contains a valid value in this slot - unsafe { self._tab.get::(Rating::VT_PROFANE, Some(RatingLevel::unused)).unwrap()} - } - #[inline] - pub fn substance(&self) -> RatingLevel { - // Safety: - // Created from valid Table for this object - // which contains a valid value in this slot - unsafe { self._tab.get::(Rating::VT_SUBSTANCE, Some(RatingLevel::unused)).unwrap()} - } - #[inline] - pub fn hate(&self) -> RatingLevel { - // Safety: - // Created from valid Table for this object - // which contains a valid value in this slot - unsafe { self._tab.get::(Rating::VT_HATE, Some(RatingLevel::unused)).unwrap()} - } - #[inline] - pub fn harm(&self) -> RatingLevel { - // Safety: - // Created from valid Table for this object - // which contains a valid value in this slot - unsafe { self._tab.get::(Rating::VT_HARM, Some(RatingLevel::unused)).unwrap()} - } - #[inline] - pub fn mature(&self) -> RatingLevel { - // Safety: - // Created from valid Table for this object - // which contains a valid value in this slot - unsafe { self._tab.get::(Rating::VT_MATURE, Some(RatingLevel::unused)).unwrap()} - } - #[inline] - pub fn bully(&self) -> RatingLevel { - // Safety: - // Created from valid Table for this object - // which contains a valid value in this slot - unsafe { self._tab.get::(Rating::VT_BULLY, Some(RatingLevel::unused)).unwrap()} - } -} - -impl flatbuffers::Verifiable for Rating<'_> { - #[inline] - fn run_verifier( - v: &mut flatbuffers::Verifier, pos: usize - ) -> Result<(), flatbuffers::InvalidFlatbuffer> { - use self::flatbuffers::Verifiable; - v.visit_table(pos)? - .visit_field::("violent", Self::VT_VIOLENT, false)? - .visit_field::("sexual", Self::VT_SEXUAL, false)? - .visit_field::("profane", Self::VT_PROFANE, false)? - .visit_field::("substance", Self::VT_SUBSTANCE, false)? - .visit_field::("hate", Self::VT_HATE, false)? - .visit_field::("harm", Self::VT_HARM, false)? - .visit_field::("mature", Self::VT_MATURE, false)? - .visit_field::("bully", Self::VT_BULLY, false)? - .finish(); - Ok(()) - } -} -pub struct RatingArgs { - pub violent: RatingLevel, - pub sexual: RatingLevel, - pub profane: RatingLevel, - pub substance: RatingLevel, - pub hate: RatingLevel, - pub harm: RatingLevel, - pub mature: RatingLevel, - pub bully: RatingLevel, -} -impl<'a> Default for RatingArgs { - #[inline] - fn default() -> Self { - RatingArgs { - violent: RatingLevel::unused, - sexual: RatingLevel::unused, - profane: RatingLevel::unused, - substance: RatingLevel::unused, - hate: RatingLevel::unused, - harm: RatingLevel::unused, - mature: RatingLevel::unused, - bully: RatingLevel::unused, - } - } -} - -pub struct RatingBuilder<'a: 'b, 'b, A: flatbuffers::Allocator + 'a> { - fbb_: &'b mut flatbuffers::FlatBufferBuilder<'a, A>, - start_: flatbuffers::WIPOffset, -} -impl<'a: 'b, 'b, A: flatbuffers::Allocator + 'a> RatingBuilder<'a, 'b, A> { - #[inline] - pub fn add_violent(&mut self, violent: RatingLevel) { - self.fbb_.push_slot::(Rating::VT_VIOLENT, violent, RatingLevel::unused); - } - #[inline] - pub fn add_sexual(&mut self, sexual: RatingLevel) { - self.fbb_.push_slot::(Rating::VT_SEXUAL, sexual, RatingLevel::unused); - } - #[inline] - pub fn add_profane(&mut self, profane: RatingLevel) { - self.fbb_.push_slot::(Rating::VT_PROFANE, profane, RatingLevel::unused); - } - #[inline] - pub fn add_substance(&mut self, substance: RatingLevel) { - self.fbb_.push_slot::(Rating::VT_SUBSTANCE, substance, RatingLevel::unused); - } - #[inline] - pub fn add_hate(&mut self, hate: RatingLevel) { - self.fbb_.push_slot::(Rating::VT_HATE, hate, RatingLevel::unused); - } - #[inline] - pub fn add_harm(&mut self, harm: RatingLevel) { - self.fbb_.push_slot::(Rating::VT_HARM, harm, RatingLevel::unused); - } - #[inline] - pub fn add_mature(&mut self, mature: RatingLevel) { - self.fbb_.push_slot::(Rating::VT_MATURE, mature, RatingLevel::unused); - } - #[inline] - pub fn add_bully(&mut self, bully: RatingLevel) { - self.fbb_.push_slot::(Rating::VT_BULLY, bully, RatingLevel::unused); - } - #[inline] - pub fn new(_fbb: &'b mut flatbuffers::FlatBufferBuilder<'a, A>) -> RatingBuilder<'a, 'b, A> { - let start = _fbb.start_table(); - RatingBuilder { - fbb_: _fbb, - start_: start, - } - } - #[inline] - pub fn finish(self) -> flatbuffers::WIPOffset> { - let o = self.fbb_.end_table(self.start_); - flatbuffers::WIPOffset::new(o.value()) - } -} - -impl core::fmt::Debug for Rating<'_> { - fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { - let mut ds = f.debug_struct("Rating"); - ds.field("violent", &self.violent()); - ds.field("sexual", &self.sexual()); - ds.field("profane", &self.profane()); - ds.field("substance", &self.substance()); - ds.field("hate", &self.hate()); - ds.field("harm", &self.harm()); - ds.field("mature", &self.mature()); - ds.field("bully", &self.bully()); - ds.finish() - } -} -pub enum PurposeOffset {} -#[derive(Copy, Clone, PartialEq)] - -pub struct Purpose<'a> { - pub _tab: flatbuffers::Table<'a>, -} - -impl<'a> flatbuffers::Follow<'a> for Purpose<'a> { - type Inner = Purpose<'a>; - #[inline] - unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { - Self { _tab: flatbuffers::Table::new(buf, loc) } - } -} - -impl<'a> Purpose<'a> { - pub const VT_EDUCATIONAL: flatbuffers::VOffsetT = 4; - pub const VT_ENTERTAINMENT: flatbuffers::VOffsetT = 6; - pub const VT_NEWS: flatbuffers::VOffsetT = 8; - pub const VT_PROMOTIONAL: flatbuffers::VOffsetT = 10; - pub const VT_PERSONAL: flatbuffers::VOffsetT = 12; - pub const VT_OPINION: flatbuffers::VOffsetT = 14; - pub const VT_TRANSACTIONAL: flatbuffers::VOffsetT = 16; - pub const VT_HARMFUL: flatbuffers::VOffsetT = 18; - pub const VT_CONFIDENCE: flatbuffers::VOffsetT = 20; - - #[inline] - pub unsafe fn init_from_table(table: flatbuffers::Table<'a>) -> Self { - Purpose { _tab: table } - } - #[allow(unused_mut)] - pub fn create<'bldr: 'args, 'args: 'mut_bldr, 'mut_bldr, A: flatbuffers::Allocator + 'bldr>( - _fbb: &'mut_bldr mut flatbuffers::FlatBufferBuilder<'bldr, A>, - args: &'args PurposeArgs - ) -> flatbuffers::WIPOffset> { - let mut builder = PurposeBuilder::new(_fbb); - builder.add_confidence(args.confidence); - builder.add_harmful(args.harmful); - builder.add_transactional(args.transactional); - builder.add_opinion(args.opinion); - builder.add_personal(args.personal); - builder.add_promotional(args.promotional); - builder.add_news(args.news); - builder.add_entertainment(args.entertainment); - builder.add_educational(args.educational); - builder.finish() - } - - - #[inline] - pub fn educational(&self) -> f32 { - // Safety: - // Created from valid Table for this object - // which contains a valid value in this slot - unsafe { self._tab.get::(Purpose::VT_EDUCATIONAL, Some(0.0)).unwrap()} - } - #[inline] - pub fn entertainment(&self) -> f32 { - // Safety: - // Created from valid Table for this object - // which contains a valid value in this slot - unsafe { self._tab.get::(Purpose::VT_ENTERTAINMENT, Some(0.0)).unwrap()} - } - #[inline] - pub fn news(&self) -> f32 { - // Safety: - // Created from valid Table for this object - // which contains a valid value in this slot - unsafe { self._tab.get::(Purpose::VT_NEWS, Some(0.0)).unwrap()} - } - #[inline] - pub fn promotional(&self) -> f32 { - // Safety: - // Created from valid Table for this object - // which contains a valid value in this slot - unsafe { self._tab.get::(Purpose::VT_PROMOTIONAL, Some(0.0)).unwrap()} - } - #[inline] - pub fn personal(&self) -> f32 { - // Safety: - // Created from valid Table for this object - // which contains a valid value in this slot - unsafe { self._tab.get::(Purpose::VT_PERSONAL, Some(0.0)).unwrap()} - } - #[inline] - pub fn opinion(&self) -> f32 { - // Safety: - // Created from valid Table for this object - // which contains a valid value in this slot - unsafe { self._tab.get::(Purpose::VT_OPINION, Some(0.0)).unwrap()} - } - #[inline] - pub fn transactional(&self) -> f32 { - // Safety: - // Created from valid Table for this object - // which contains a valid value in this slot - unsafe { self._tab.get::(Purpose::VT_TRANSACTIONAL, Some(0.0)).unwrap()} - } - #[inline] - pub fn harmful(&self) -> f32 { - // Safety: - // Created from valid Table for this object - // which contains a valid value in this slot - unsafe { self._tab.get::(Purpose::VT_HARMFUL, Some(0.0)).unwrap()} - } - #[inline] - pub fn confidence(&self) -> f32 { - // Safety: - // Created from valid Table for this object - // which contains a valid value in this slot - unsafe { self._tab.get::(Purpose::VT_CONFIDENCE, Some(0.0)).unwrap()} - } -} - -impl flatbuffers::Verifiable for Purpose<'_> { - #[inline] - fn run_verifier( - v: &mut flatbuffers::Verifier, pos: usize - ) -> Result<(), flatbuffers::InvalidFlatbuffer> { - use self::flatbuffers::Verifiable; - v.visit_table(pos)? - .visit_field::("educational", Self::VT_EDUCATIONAL, false)? - .visit_field::("entertainment", Self::VT_ENTERTAINMENT, false)? - .visit_field::("news", Self::VT_NEWS, false)? - .visit_field::("promotional", Self::VT_PROMOTIONAL, false)? - .visit_field::("personal", Self::VT_PERSONAL, false)? - .visit_field::("opinion", Self::VT_OPINION, false)? - .visit_field::("transactional", Self::VT_TRANSACTIONAL, false)? - .visit_field::("harmful", Self::VT_HARMFUL, false)? - .visit_field::("confidence", Self::VT_CONFIDENCE, false)? - .finish(); - Ok(()) - } -} -pub struct PurposeArgs { - pub educational: f32, - pub entertainment: f32, - pub news: f32, - pub promotional: f32, - pub personal: f32, - pub opinion: f32, - pub transactional: f32, - pub harmful: f32, - pub confidence: f32, -} -impl<'a> Default for PurposeArgs { - #[inline] - fn default() -> Self { - PurposeArgs { - educational: 0.0, - entertainment: 0.0, - news: 0.0, - promotional: 0.0, - personal: 0.0, - opinion: 0.0, - transactional: 0.0, - harmful: 0.0, - confidence: 0.0, - } - } -} - -pub struct PurposeBuilder<'a: 'b, 'b, A: flatbuffers::Allocator + 'a> { - fbb_: &'b mut flatbuffers::FlatBufferBuilder<'a, A>, - start_: flatbuffers::WIPOffset, -} -impl<'a: 'b, 'b, A: flatbuffers::Allocator + 'a> PurposeBuilder<'a, 'b, A> { - #[inline] - pub fn add_educational(&mut self, educational: f32) { - self.fbb_.push_slot::(Purpose::VT_EDUCATIONAL, educational, 0.0); - } - #[inline] - pub fn add_entertainment(&mut self, entertainment: f32) { - self.fbb_.push_slot::(Purpose::VT_ENTERTAINMENT, entertainment, 0.0); - } - #[inline] - pub fn add_news(&mut self, news: f32) { - self.fbb_.push_slot::(Purpose::VT_NEWS, news, 0.0); - } - #[inline] - pub fn add_promotional(&mut self, promotional: f32) { - self.fbb_.push_slot::(Purpose::VT_PROMOTIONAL, promotional, 0.0); - } - #[inline] - pub fn add_personal(&mut self, personal: f32) { - self.fbb_.push_slot::(Purpose::VT_PERSONAL, personal, 0.0); - } - #[inline] - pub fn add_opinion(&mut self, opinion: f32) { - self.fbb_.push_slot::(Purpose::VT_OPINION, opinion, 0.0); - } - #[inline] - pub fn add_transactional(&mut self, transactional: f32) { - self.fbb_.push_slot::(Purpose::VT_TRANSACTIONAL, transactional, 0.0); - } - #[inline] - pub fn add_harmful(&mut self, harmful: f32) { - self.fbb_.push_slot::(Purpose::VT_HARMFUL, harmful, 0.0); - } - #[inline] - pub fn add_confidence(&mut self, confidence: f32) { - self.fbb_.push_slot::(Purpose::VT_CONFIDENCE, confidence, 0.0); - } - #[inline] - pub fn new(_fbb: &'b mut flatbuffers::FlatBufferBuilder<'a, A>) -> PurposeBuilder<'a, 'b, A> { - let start = _fbb.start_table(); - PurposeBuilder { - fbb_: _fbb, - start_: start, - } - } - #[inline] - pub fn finish(self) -> flatbuffers::WIPOffset> { - let o = self.fbb_.end_table(self.start_); - flatbuffers::WIPOffset::new(o.value()) - } -} - -impl core::fmt::Debug for Purpose<'_> { - fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { - let mut ds = f.debug_struct("Purpose"); - ds.field("educational", &self.educational()); - ds.field("entertainment", &self.entertainment()); - ds.field("news", &self.news()); - ds.field("promotional", &self.promotional()); - ds.field("personal", &self.personal()); - ds.field("opinion", &self.opinion()); - ds.field("transactional", &self.transactional()); - ds.field("harmful", &self.harmful()); - ds.field("confidence", &self.confidence()); - ds.finish() - } -} -pub enum FormatInfoOffset {} -#[derive(Copy, Clone, PartialEq)] - -pub struct FormatInfo<'a> { - pub _tab: flatbuffers::Table<'a>, -} - -impl<'a> flatbuffers::Follow<'a> for FormatInfo<'a> { - type Inner = FormatInfo<'a>; - #[inline] - unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { - Self { _tab: flatbuffers::Table::new(buf, loc) } - } -} - -impl<'a> FormatInfo<'a> { - pub const VT_TYPE_: flatbuffers::VOffsetT = 4; - pub const VT_VERSION: flatbuffers::VOffsetT = 6; - pub const VT_PROFILE: flatbuffers::VOffsetT = 8; - - #[inline] - pub unsafe fn init_from_table(table: flatbuffers::Table<'a>) -> Self { - FormatInfo { _tab: table } - } - #[allow(unused_mut)] - pub fn create<'bldr: 'args, 'args: 'mut_bldr, 'mut_bldr, A: flatbuffers::Allocator + 'bldr>( - _fbb: &'mut_bldr mut flatbuffers::FlatBufferBuilder<'bldr, A>, - args: &'args FormatInfoArgs<'args> - ) -> flatbuffers::WIPOffset> { - let mut builder = FormatInfoBuilder::new(_fbb); - if let Some(x) = args.profile { builder.add_profile(x); } - if let Some(x) = args.version { builder.add_version(x); } - builder.add_type_(args.type_); - builder.finish() - } - - - #[inline] - pub fn type_(&self) -> FormatType { - // Safety: - // Created from valid Table for this object - // which contains a valid value in this slot - unsafe { self._tab.get::(FormatInfo::VT_TYPE_, Some(FormatType::plain)).unwrap()} - } - #[inline] - pub fn version(&self) -> Option<&'a str> { - // Safety: - // Created from valid Table for this object - // which contains a valid value in this slot - unsafe { self._tab.get::>(FormatInfo::VT_VERSION, None)} - } - #[inline] - pub fn profile(&self) -> Option<&'a str> { - // Safety: - // Created from valid Table for this object - // which contains a valid value in this slot - unsafe { self._tab.get::>(FormatInfo::VT_PROFILE, None)} - } -} - -impl flatbuffers::Verifiable for FormatInfo<'_> { - #[inline] - fn run_verifier( - v: &mut flatbuffers::Verifier, pos: usize - ) -> Result<(), flatbuffers::InvalidFlatbuffer> { - use self::flatbuffers::Verifiable; - v.visit_table(pos)? - .visit_field::("type_", Self::VT_TYPE_, false)? - .visit_field::>("version", Self::VT_VERSION, false)? - .visit_field::>("profile", Self::VT_PROFILE, false)? - .finish(); - Ok(()) - } -} -pub struct FormatInfoArgs<'a> { - pub type_: FormatType, - pub version: Option>, - pub profile: Option>, -} -impl<'a> Default for FormatInfoArgs<'a> { - #[inline] - fn default() -> Self { - FormatInfoArgs { - type_: FormatType::plain, - version: None, - profile: None, - } - } -} - -pub struct FormatInfoBuilder<'a: 'b, 'b, A: flatbuffers::Allocator + 'a> { - fbb_: &'b mut flatbuffers::FlatBufferBuilder<'a, A>, - start_: flatbuffers::WIPOffset, -} -impl<'a: 'b, 'b, A: flatbuffers::Allocator + 'a> FormatInfoBuilder<'a, 'b, A> { - #[inline] - pub fn add_type_(&mut self, type_: FormatType) { - self.fbb_.push_slot::(FormatInfo::VT_TYPE_, type_, FormatType::plain); - } - #[inline] - pub fn add_version(&mut self, version: flatbuffers::WIPOffset<&'b str>) { - self.fbb_.push_slot_always::>(FormatInfo::VT_VERSION, version); - } - #[inline] - pub fn add_profile(&mut self, profile: flatbuffers::WIPOffset<&'b str>) { - self.fbb_.push_slot_always::>(FormatInfo::VT_PROFILE, profile); - } - #[inline] - pub fn new(_fbb: &'b mut flatbuffers::FlatBufferBuilder<'a, A>) -> FormatInfoBuilder<'a, 'b, A> { - let start = _fbb.start_table(); - FormatInfoBuilder { - fbb_: _fbb, - start_: start, - } - } - #[inline] - pub fn finish(self) -> flatbuffers::WIPOffset> { - let o = self.fbb_.end_table(self.start_); - flatbuffers::WIPOffset::new(o.value()) - } -} - -impl core::fmt::Debug for FormatInfo<'_> { - fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { - let mut ds = f.debug_struct("FormatInfo"); - ds.field("type_", &self.type_()); - ds.field("version", &self.version()); - ds.field("profile", &self.profile()); - ds.finish() - } -} -pub enum ArchiveInfoOffset {} -#[derive(Copy, Clone, PartialEq)] - -pub struct ArchiveInfo<'a> { - pub _tab: flatbuffers::Table<'a>, -} - -impl<'a> flatbuffers::Follow<'a> for ArchiveInfo<'a> { - type Inner = ArchiveInfo<'a>; - #[inline] - unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { - Self { _tab: flatbuffers::Table::new(buf, loc) } - } -} - -impl<'a> ArchiveInfo<'a> { - pub const VT_TYPE_: flatbuffers::VOffsetT = 4; - pub const VT_VERSION: flatbuffers::VOffsetT = 6; - pub const VT_PROFILE: flatbuffers::VOffsetT = 8; - - #[inline] - pub unsafe fn init_from_table(table: flatbuffers::Table<'a>) -> Self { - ArchiveInfo { _tab: table } - } - #[allow(unused_mut)] - pub fn create<'bldr: 'args, 'args: 'mut_bldr, 'mut_bldr, A: flatbuffers::Allocator + 'bldr>( - _fbb: &'mut_bldr mut flatbuffers::FlatBufferBuilder<'bldr, A>, - args: &'args ArchiveInfoArgs<'args> - ) -> flatbuffers::WIPOffset> { - let mut builder = ArchiveInfoBuilder::new(_fbb); - if let Some(x) = args.profile { builder.add_profile(x); } - if let Some(x) = args.version { builder.add_version(x); } - builder.add_type_(args.type_); - builder.finish() - } - - - #[inline] - pub fn type_(&self) -> ArchiveType { - // Safety: - // Created from valid Table for this object - // which contains a valid value in this slot - unsafe { self._tab.get::(ArchiveInfo::VT_TYPE_, Some(ArchiveType::none)).unwrap()} - } - #[inline] - pub fn version(&self) -> Option<&'a str> { - // Safety: - // Created from valid Table for this object - // which contains a valid value in this slot - unsafe { self._tab.get::>(ArchiveInfo::VT_VERSION, None)} - } - #[inline] - pub fn profile(&self) -> Option<&'a str> { - // Safety: - // Created from valid Table for this object - // which contains a valid value in this slot - unsafe { self._tab.get::>(ArchiveInfo::VT_PROFILE, None)} - } -} - -impl flatbuffers::Verifiable for ArchiveInfo<'_> { - #[inline] - fn run_verifier( - v: &mut flatbuffers::Verifier, pos: usize - ) -> Result<(), flatbuffers::InvalidFlatbuffer> { - use self::flatbuffers::Verifiable; - v.visit_table(pos)? - .visit_field::("type_", Self::VT_TYPE_, false)? - .visit_field::>("version", Self::VT_VERSION, false)? - .visit_field::>("profile", Self::VT_PROFILE, false)? - .finish(); - Ok(()) - } -} -pub struct ArchiveInfoArgs<'a> { - pub type_: ArchiveType, - pub version: Option>, - pub profile: Option>, -} -impl<'a> Default for ArchiveInfoArgs<'a> { - #[inline] - fn default() -> Self { - ArchiveInfoArgs { - type_: ArchiveType::none, - version: None, - profile: None, - } - } -} - -pub struct ArchiveInfoBuilder<'a: 'b, 'b, A: flatbuffers::Allocator + 'a> { - fbb_: &'b mut flatbuffers::FlatBufferBuilder<'a, A>, - start_: flatbuffers::WIPOffset, -} -impl<'a: 'b, 'b, A: flatbuffers::Allocator + 'a> ArchiveInfoBuilder<'a, 'b, A> { - #[inline] - pub fn add_type_(&mut self, type_: ArchiveType) { - self.fbb_.push_slot::(ArchiveInfo::VT_TYPE_, type_, ArchiveType::none); - } - #[inline] - pub fn add_version(&mut self, version: flatbuffers::WIPOffset<&'b str>) { - self.fbb_.push_slot_always::>(ArchiveInfo::VT_VERSION, version); - } - #[inline] - pub fn add_profile(&mut self, profile: flatbuffers::WIPOffset<&'b str>) { - self.fbb_.push_slot_always::>(ArchiveInfo::VT_PROFILE, profile); - } - #[inline] - pub fn new(_fbb: &'b mut flatbuffers::FlatBufferBuilder<'a, A>) -> ArchiveInfoBuilder<'a, 'b, A> { - let start = _fbb.start_table(); - ArchiveInfoBuilder { - fbb_: _fbb, - start_: start, - } - } - #[inline] - pub fn finish(self) -> flatbuffers::WIPOffset> { - let o = self.fbb_.end_table(self.start_); - flatbuffers::WIPOffset::new(o.value()) - } -} - -impl core::fmt::Debug for ArchiveInfo<'_> { - fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { - let mut ds = f.debug_struct("ArchiveInfo"); - ds.field("type_", &self.type_()); - ds.field("version", &self.version()); - ds.field("profile", &self.profile()); - ds.finish() - } -} -pub enum ContentFormatOffset {} -#[derive(Copy, Clone, PartialEq)] - -pub struct ContentFormat<'a> { - pub _tab: flatbuffers::Table<'a>, -} - -impl<'a> flatbuffers::Follow<'a> for ContentFormat<'a> { - type Inner = ContentFormat<'a>; - #[inline] - unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { - Self { _tab: flatbuffers::Table::new(buf, loc) } - } -} - -impl<'a> ContentFormat<'a> { - pub const VT_MEDIA_TYPE: flatbuffers::VOffsetT = 4; - pub const VT_DATA_ENCODING: flatbuffers::VOffsetT = 6; - pub const VT_FORMAT: flatbuffers::VOffsetT = 8; - - #[inline] - pub unsafe fn init_from_table(table: flatbuffers::Table<'a>) -> Self { - ContentFormat { _tab: table } - } - #[allow(unused_mut)] - pub fn create<'bldr: 'args, 'args: 'mut_bldr, 'mut_bldr, A: flatbuffers::Allocator + 'bldr>( - _fbb: &'mut_bldr mut flatbuffers::FlatBufferBuilder<'bldr, A>, - args: &'args ContentFormatArgs<'args> - ) -> flatbuffers::WIPOffset> { - let mut builder = ContentFormatBuilder::new(_fbb); - if let Some(x) = args.format { builder.add_format(x); } - builder.add_data_encoding(args.data_encoding); - builder.add_media_type(args.media_type); - builder.finish() - } - - - #[inline] - pub fn media_type(&self) -> MediaType { - // Safety: - // Created from valid Table for this object - // which contains a valid value in this slot - unsafe { self._tab.get::(ContentFormat::VT_MEDIA_TYPE, Some(MediaType::unused)).unwrap()} - } - #[inline] - pub fn data_encoding(&self) -> DataEncoding { - // Safety: - // Created from valid Table for this object - // which contains a valid value in this slot - unsafe { self._tab.get::(ContentFormat::VT_DATA_ENCODING, Some(DataEncoding::binary)).unwrap()} - } - #[inline] - pub fn format(&self) -> Option> { - // Safety: - // Created from valid Table for this object - // which contains a valid value in this slot - unsafe { self._tab.get::>(ContentFormat::VT_FORMAT, None)} - } -} - -impl flatbuffers::Verifiable for ContentFormat<'_> { - #[inline] - fn run_verifier( - v: &mut flatbuffers::Verifier, pos: usize - ) -> Result<(), flatbuffers::InvalidFlatbuffer> { - use self::flatbuffers::Verifiable; - v.visit_table(pos)? - .visit_field::("media_type", Self::VT_MEDIA_TYPE, false)? - .visit_field::("data_encoding", Self::VT_DATA_ENCODING, false)? - .visit_field::>("format", Self::VT_FORMAT, false)? - .finish(); - Ok(()) - } -} -pub struct ContentFormatArgs<'a> { - pub media_type: MediaType, - pub data_encoding: DataEncoding, - pub format: Option>>, -} -impl<'a> Default for ContentFormatArgs<'a> { - #[inline] - fn default() -> Self { - ContentFormatArgs { - media_type: MediaType::unused, - data_encoding: DataEncoding::binary, - format: None, - } - } -} - -pub struct ContentFormatBuilder<'a: 'b, 'b, A: flatbuffers::Allocator + 'a> { - fbb_: &'b mut flatbuffers::FlatBufferBuilder<'a, A>, - start_: flatbuffers::WIPOffset, -} -impl<'a: 'b, 'b, A: flatbuffers::Allocator + 'a> ContentFormatBuilder<'a, 'b, A> { - #[inline] - pub fn add_media_type(&mut self, media_type: MediaType) { - self.fbb_.push_slot::(ContentFormat::VT_MEDIA_TYPE, media_type, MediaType::unused); - } - #[inline] - pub fn add_data_encoding(&mut self, data_encoding: DataEncoding) { - self.fbb_.push_slot::(ContentFormat::VT_DATA_ENCODING, data_encoding, DataEncoding::binary); - } - #[inline] - pub fn add_format(&mut self, format: flatbuffers::WIPOffset>) { - self.fbb_.push_slot_always::>(ContentFormat::VT_FORMAT, format); - } - #[inline] - pub fn new(_fbb: &'b mut flatbuffers::FlatBufferBuilder<'a, A>) -> ContentFormatBuilder<'a, 'b, A> { - let start = _fbb.start_table(); - ContentFormatBuilder { - fbb_: _fbb, - start_: start, - } - } - #[inline] - pub fn finish(self) -> flatbuffers::WIPOffset> { - let o = self.fbb_.end_table(self.start_); - flatbuffers::WIPOffset::new(o.value()) - } -} - -impl core::fmt::Debug for ContentFormat<'_> { - fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { - let mut ds = f.debug_struct("ContentFormat"); - ds.field("media_type", &self.media_type()); - ds.field("data_encoding", &self.data_encoding()); - ds.field("format", &self.format()); - ds.finish() - } -} -pub enum MetadataOffset {} -#[derive(Copy, Clone, PartialEq)] - -pub struct Metadata<'a> { - pub _tab: flatbuffers::Table<'a>, -} - -impl<'a> flatbuffers::Follow<'a> for Metadata<'a> { - type Inner = Metadata<'a>; - #[inline] - unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { - Self { _tab: flatbuffers::Table::new(buf, loc) } - } -} - -impl<'a> Metadata<'a> { - pub const VT_CREATED: flatbuffers::VOffsetT = 4; - pub const VT_ID: flatbuffers::VOffsetT = 6; - pub const VT_RELATED: flatbuffers::VOffsetT = 8; - pub const VT_RATING: flatbuffers::VOffsetT = 10; - pub const VT_PURPOSE: flatbuffers::VOffsetT = 12; - pub const VT_TOPICS: flatbuffers::VOffsetT = 14; - pub const VT_ARCHIVE: flatbuffers::VOffsetT = 16; - pub const VT_CONTENT: flatbuffers::VOffsetT = 18; - - #[inline] - pub unsafe fn init_from_table(table: flatbuffers::Table<'a>) -> Self { - Metadata { _tab: table } - } - #[allow(unused_mut)] - pub fn create<'bldr: 'args, 'args: 'mut_bldr, 'mut_bldr, A: flatbuffers::Allocator + 'bldr>( - _fbb: &'mut_bldr mut flatbuffers::FlatBufferBuilder<'bldr, A>, - args: &'args MetadataArgs<'args> - ) -> flatbuffers::WIPOffset> { - let mut builder = MetadataBuilder::new(_fbb); - builder.add_created(args.created); - if let Some(x) = args.content { builder.add_content(x); } - if let Some(x) = args.archive { builder.add_archive(x); } - if let Some(x) = args.topics { builder.add_topics(x); } - if let Some(x) = args.purpose { builder.add_purpose(x); } - if let Some(x) = args.rating { builder.add_rating(x); } - if let Some(x) = args.related { builder.add_related(x); } - if let Some(x) = args.id { builder.add_id(x); } - builder.finish() - } - - - #[inline] - pub fn created(&self) -> i64 { - // Safety: - // Created from valid Table for this object - // which contains a valid value in this slot - unsafe { self._tab.get::(Metadata::VT_CREATED, Some(0)).unwrap()} - } - #[inline] - pub fn id(&self) -> Option> { - // Safety: - // Created from valid Table for this object - // which contains a valid value in this slot - unsafe { self._tab.get::>>(Metadata::VT_ID, None)} - } - #[inline] - pub fn related(&self) -> Option> { - // Safety: - // Created from valid Table for this object - // which contains a valid value in this slot - unsafe { self._tab.get::>>(Metadata::VT_RELATED, None)} - } - #[inline] - pub fn rating(&self) -> Option> { - // Safety: - // Created from valid Table for this object - // which contains a valid value in this slot - unsafe { self._tab.get::>(Metadata::VT_RATING, None)} - } - #[inline] - pub fn purpose(&self) -> Option> { - // Safety: - // Created from valid Table for this object - // which contains a valid value in this slot - unsafe { self._tab.get::>(Metadata::VT_PURPOSE, None)} - } - #[inline] - pub fn topics(&self) -> Option> { - // Safety: - // Created from valid Table for this object - // which contains a valid value in this slot - unsafe { self._tab.get::>>(Metadata::VT_TOPICS, None)} - } - #[inline] - pub fn archive(&self) -> Option> { - // Safety: - // Created from valid Table for this object - // which contains a valid value in this slot - unsafe { self._tab.get::>(Metadata::VT_ARCHIVE, None)} - } - #[inline] - pub fn content(&self) -> Option> { - // Safety: - // Created from valid Table for this object - // which contains a valid value in this slot - unsafe { self._tab.get::>(Metadata::VT_CONTENT, None)} - } -} - -impl flatbuffers::Verifiable for Metadata<'_> { - #[inline] - fn run_verifier( - v: &mut flatbuffers::Verifier, pos: usize - ) -> Result<(), flatbuffers::InvalidFlatbuffer> { - use self::flatbuffers::Verifiable; - v.visit_table(pos)? - .visit_field::("created", Self::VT_CREATED, false)? - .visit_field::>>("id", Self::VT_ID, false)? - .visit_field::>>("related", Self::VT_RELATED, false)? - .visit_field::>("rating", Self::VT_RATING, false)? - .visit_field::>("purpose", Self::VT_PURPOSE, false)? - .visit_field::>>("topics", Self::VT_TOPICS, false)? - .visit_field::>("archive", Self::VT_ARCHIVE, false)? - .visit_field::>("content", Self::VT_CONTENT, false)? - .finish(); - Ok(()) - } -} -pub struct MetadataArgs<'a> { - pub created: i64, - pub id: Option>>, - pub related: Option>>, - pub rating: Option>>, - pub purpose: Option>>, - pub topics: Option>>, - pub archive: Option>>, - pub content: Option>>, -} -impl<'a> Default for MetadataArgs<'a> { - #[inline] - fn default() -> Self { - MetadataArgs { - created: 0, - id: None, - related: None, - rating: None, - purpose: None, - topics: None, - archive: None, - content: None, - } - } -} - -pub struct MetadataBuilder<'a: 'b, 'b, A: flatbuffers::Allocator + 'a> { - fbb_: &'b mut flatbuffers::FlatBufferBuilder<'a, A>, - start_: flatbuffers::WIPOffset, -} -impl<'a: 'b, 'b, A: flatbuffers::Allocator + 'a> MetadataBuilder<'a, 'b, A> { - #[inline] - pub fn add_created(&mut self, created: i64) { - self.fbb_.push_slot::(Metadata::VT_CREATED, created, 0); - } - #[inline] - pub fn add_id(&mut self, id: flatbuffers::WIPOffset>) { - self.fbb_.push_slot_always::>(Metadata::VT_ID, id); - } - #[inline] - pub fn add_related(&mut self, related: flatbuffers::WIPOffset>) { - self.fbb_.push_slot_always::>(Metadata::VT_RELATED, related); - } - #[inline] - pub fn add_rating(&mut self, rating: flatbuffers::WIPOffset>) { - self.fbb_.push_slot_always::>(Metadata::VT_RATING, rating); - } - #[inline] - pub fn add_purpose(&mut self, purpose: flatbuffers::WIPOffset>) { - self.fbb_.push_slot_always::>(Metadata::VT_PURPOSE, purpose); - } - #[inline] - pub fn add_topics(&mut self, topics: flatbuffers::WIPOffset>) { - self.fbb_.push_slot_always::>(Metadata::VT_TOPICS, topics); - } - #[inline] - pub fn add_archive(&mut self, archive: flatbuffers::WIPOffset>) { - self.fbb_.push_slot_always::>(Metadata::VT_ARCHIVE, archive); - } - #[inline] - pub fn add_content(&mut self, content: flatbuffers::WIPOffset>) { - self.fbb_.push_slot_always::>(Metadata::VT_CONTENT, content); - } - #[inline] - pub fn new(_fbb: &'b mut flatbuffers::FlatBufferBuilder<'a, A>) -> MetadataBuilder<'a, 'b, A> { - let start = _fbb.start_table(); - MetadataBuilder { - fbb_: _fbb, - start_: start, - } - } - #[inline] - pub fn finish(self) -> flatbuffers::WIPOffset> { - let o = self.fbb_.end_table(self.start_); - flatbuffers::WIPOffset::new(o.value()) - } -} - -impl core::fmt::Debug for Metadata<'_> { - fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { - let mut ds = f.debug_struct("Metadata"); - ds.field("created", &self.created()); - ds.field("id", &self.id()); - ds.field("related", &self.related()); - ds.field("rating", &self.rating()); - ds.field("purpose", &self.purpose()); - ds.field("topics", &self.topics()); - ds.field("archive", &self.archive()); - ds.field("content", &self.content()); - ds.finish() - } -} -#[inline] -/// Verifies that a buffer of bytes contains a `Metadata` -/// and returns it. -/// Note that verification is still experimental and may not -/// catch every error, or be maximally performant. For the -/// previous, unchecked, behavior use -/// `root_as_metadata_unchecked`. -pub fn root_as_metadata(buf: &[u8]) -> Result { - flatbuffers::root::(buf) -} -#[inline] -/// Verifies that a buffer of bytes contains a size prefixed -/// `Metadata` and returns it. -/// Note that verification is still experimental and may not -/// catch every error, or be maximally performant. For the -/// previous, unchecked, behavior use -/// `size_prefixed_root_as_metadata_unchecked`. -pub fn size_prefixed_root_as_metadata(buf: &[u8]) -> Result { - flatbuffers::size_prefixed_root::(buf) -} -#[inline] -/// Verifies, with the given options, that a buffer of bytes -/// contains a `Metadata` and returns it. -/// Note that verification is still experimental and may not -/// catch every error, or be maximally performant. For the -/// previous, unchecked, behavior use -/// `root_as_metadata_unchecked`. -pub fn root_as_metadata_with_opts<'b, 'o>( - opts: &'o flatbuffers::VerifierOptions, - buf: &'b [u8], -) -> Result, flatbuffers::InvalidFlatbuffer> { - flatbuffers::root_with_opts::>(opts, buf) -} -#[inline] -/// Verifies, with the given verifier options, that a buffer of -/// bytes contains a size prefixed `Metadata` and returns -/// it. Note that verification is still experimental and may not -/// catch every error, or be maximally performant. For the -/// previous, unchecked, behavior use -/// `root_as_metadata_unchecked`. -pub fn size_prefixed_root_as_metadata_with_opts<'b, 'o>( - opts: &'o flatbuffers::VerifierOptions, - buf: &'b [u8], -) -> Result, flatbuffers::InvalidFlatbuffer> { - flatbuffers::size_prefixed_root_with_opts::>(opts, buf) -} -#[inline] -/// Assumes, without verification, that a buffer of bytes contains a Metadata and returns it. -/// # Safety -/// Callers must trust the given bytes do indeed contain a valid `Metadata`. -pub unsafe fn root_as_metadata_unchecked(buf: &[u8]) -> Metadata { - flatbuffers::root_unchecked::(buf) -} -#[inline] -/// Assumes, without verification, that a buffer of bytes contains a size prefixed Metadata and returns it. -/// # Safety -/// Callers must trust the given bytes do indeed contain a valid size prefixed `Metadata`. -pub unsafe fn size_prefixed_root_as_metadata_unchecked(buf: &[u8]) -> Metadata { - flatbuffers::size_prefixed_root_unchecked::(buf) -} -#[inline] -pub fn finish_metadata_buffer<'a, 'b, A: flatbuffers::Allocator + 'a>( - fbb: &'b mut flatbuffers::FlatBufferBuilder<'a, A>, - root: flatbuffers::WIPOffset>) { - fbb.finish(root, None); -} - -#[inline] -pub fn finish_size_prefixed_metadata_buffer<'a, 'b, A: flatbuffers::Allocator + 'a>(fbb: &'b mut flatbuffers::FlatBufferBuilder<'a, A>, root: flatbuffers::WIPOffset>) { - fbb.finish_size_prefixed(root, None); -} -} // pub mod Arkavo + /// Verifies, with the given verifier options, that a buffer of + /// bytes contains a size prefixed `Metadata` and returns + /// it. Note that verification is still experimental and may not + /// catch every error, or be maximally performant. For the + /// previous, unchecked, behavior use + /// `root_as_metadata_unchecked`. + pub fn size_prefixed_root_as_metadata_with_opts<'b, 'o>( + opts: &'o flatbuffers::VerifierOptions, + buf: &'b [u8], + ) -> Result, flatbuffers::InvalidFlatbuffer> { + flatbuffers::size_prefixed_root_with_opts::>(opts, buf) + } + #[inline] + /// Assumes, without verification, that a buffer of bytes contains a Metadata and returns it. + /// # Safety + /// Callers must trust the given bytes do indeed contain a valid `Metadata`. + pub unsafe fn root_as_metadata_unchecked(buf: &[u8]) -> Metadata { + flatbuffers::root_unchecked::(buf) + } + #[inline] + /// Assumes, without verification, that a buffer of bytes contains a size prefixed Metadata and returns it. + /// # Safety + /// Callers must trust the given bytes do indeed contain a valid size prefixed `Metadata`. + pub unsafe fn size_prefixed_root_as_metadata_unchecked(buf: &[u8]) -> Metadata { + flatbuffers::size_prefixed_root_unchecked::(buf) + } + #[inline] + pub fn finish_metadata_buffer<'a, 'b, A: flatbuffers::Allocator + 'a>( + fbb: &'b mut flatbuffers::FlatBufferBuilder<'a, A>, + root: flatbuffers::WIPOffset>, + ) { + fbb.finish(root, None); + } + #[inline] + pub fn finish_size_prefixed_metadata_buffer<'a, 'b, A: flatbuffers::Allocator + 'a>( + fbb: &'b mut flatbuffers::FlatBufferBuilder<'a, A>, + root: flatbuffers::WIPOffset>, + ) { + fbb.finish_size_prefixed(root, None); + } +} // pub mod Arkavo diff --git a/src/bin/schemas/mod.rs b/src/bin/schemas/mod.rs index 55a9838..fd81d7e 100644 --- a/src/bin/schemas/mod.rs +++ b/src/bin/schemas/mod.rs @@ -1,3 +1,3 @@ +pub mod entity_generated; pub mod event_generated; pub mod metadata_generated; -pub mod entity_generated;