From 54fc371f056f950389ecfae777b782e3570c43f0 Mon Sep 17 00:00:00 2001 From: Charles Date: Fri, 21 Mar 2025 20:49:49 -0700 Subject: [PATCH] add: half baked --- engine/Cargo.lock | 48 + engine/Cargo.toml | 8 + engine/Makefile | 3 + engine/schema/beacon.fbs | 53 ++ engine/schema/errors.fbs | 6 + engine/src/beacon/mod.rs | 82 ++ engine/src/gen/beacon_generated.rs | 1372 ++++++++++++++++++++++++++++ engine/src/gen/errors_generated.rs | 116 +++ engine/src/gen/mod.rs | 7 + engine/src/lib.rs | 3 + engine/src/main.rs | 3 + engine/src/player/mod.rs | 1 + engine/src/player/server/mod.rs | 0 13 files changed, 1702 insertions(+) create mode 100644 engine/Cargo.lock create mode 100644 engine/Cargo.toml create mode 100644 engine/Makefile create mode 100644 engine/schema/beacon.fbs create mode 100644 engine/schema/errors.fbs create mode 100644 engine/src/beacon/mod.rs create mode 100644 engine/src/gen/beacon_generated.rs create mode 100644 engine/src/gen/errors_generated.rs create mode 100644 engine/src/gen/mod.rs create mode 100644 engine/src/lib.rs create mode 100644 engine/src/main.rs create mode 100644 engine/src/player/mod.rs create mode 100644 engine/src/player/server/mod.rs diff --git a/engine/Cargo.lock b/engine/Cargo.lock new file mode 100644 index 0000000..2641523 --- /dev/null +++ b/engine/Cargo.lock @@ -0,0 +1,48 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "bitflags" +version = "2.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c8214115b7bf84099f1309324e63141d4c5d7cc26862f97a0a857dbefe165bd" + +[[package]] +name = "engine" +version = "0.1.0" +dependencies = [ + "flatbuffers", + "log", +] + +[[package]] +name = "flatbuffers" +version = "25.2.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1045398c1bfd89168b5fd3f1fc11f6e70b34f6f66300c87d44d3de849463abf1" +dependencies = [ + "bitflags", + "rustc_version", +] + +[[package]] +name = "log" +version = "0.4.26" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "30bde2b3dc3671ae49d8e2e9f044c7c005836e7a023ee57cffa25ab82764bb9e" + +[[package]] +name = "rustc_version" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cfcb3a22ef46e85b45de6ee7e79d063319ebb6594faafcf1c225ea92ab6e9b92" +dependencies = [ + "semver", +] + +[[package]] +name = "semver" +version = "1.0.26" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "56e6fa9c48d24d85fb3de5ad847117517440f6beceb7798af16b4a87d616b8d0" diff --git a/engine/Cargo.toml b/engine/Cargo.toml new file mode 100644 index 0000000..28d5d4d --- /dev/null +++ b/engine/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "engine" +version = "0.1.0" +edition = "2021" + +[dependencies] +flatbuffers = "25.2.10" +log = "0.4.26" diff --git a/engine/Makefile b/engine/Makefile new file mode 100644 index 0000000..8d2651e --- /dev/null +++ b/engine/Makefile @@ -0,0 +1,3 @@ +all: + flatc --rust -o src/gen/ schema/*.fbs + cargo build diff --git a/engine/schema/beacon.fbs b/engine/schema/beacon.fbs new file mode 100644 index 0000000..aff9e9f --- /dev/null +++ b/engine/schema/beacon.fbs @@ -0,0 +1,53 @@ +namespace mmo.beacon; + +enum Verb:byte { + Join = 0, + Leave, + List +} + +union Request { + JoinRequest, + LeaveRequest, + ListRequest +} + +table Call { + request:Request; +} + +table JoinRequest { + uid:string (required); + contact:string (required); + clock:long; +} + +table LeaveRequest { + uid:string (required); +} + +table ListRequest {} + +union Response { + JoinResponse, + LeaveResponse, + ListResponse +} + +table CallResp { + response:Response; +} + +table JoinResponse {} + +table LeaveResponse {} + +table ListResponse { + entities:[Entity]; +} + +table Entity { + uid:string (required); + // vector clock representing the state of this thing + clock:long; +} \ No newline at end of file diff --git a/engine/schema/errors.fbs b/engine/schema/errors.fbs new file mode 100644 index 0000000..3226648 --- /dev/null +++ b/engine/schema/errors.fbs @@ -0,0 +1,6 @@ +namespace mmo.util; + +enum Error:short { + BadRequest = 0, + NotFound, +} \ No newline at end of file diff --git a/engine/src/beacon/mod.rs b/engine/src/beacon/mod.rs new file mode 100644 index 0000000..d29f80e --- /dev/null +++ b/engine/src/beacon/mod.rs @@ -0,0 +1,82 @@ +use std::collections::HashMap; + +use flatbuffers::FlatBufferBuilder; +use log::info; + +use crate::gen::mmo::{ + beacon::{Call, CallResp, CallRespArgs, Request, Response}, + util::Error, +}; + +#[derive(Default)] +pub struct Server { + remotes: HashMap, +} + +impl Server { + pub fn new() -> Self { + Self::default() + } + pub fn handle<'a>( + &mut self, + call: Call<'a>, + response: &'a mut FlatBufferBuilder<'a>, + ) -> Result<(), Error> { + match call.request_type() { + Request::JoinRequest => { + let req = call.request_as_join_request().ok_or(Error::BadRequest)?; + self.remotes.insert(req.uid().into(), req.contact().into()); + let resp = CallResp::create( + response, + &CallRespArgs { + ..Default::default() + }, + ); + response.finish(resp, None); + Ok(()) + } + Request::LeaveRequest => { + let req = call.request_as_leave_request().ok_or(Error::BadRequest)?; + self.remotes.remove(req.uid()); + let resp = CallResp::create( + response, + &CallRespArgs { + ..Default::default() + }, + ); + response.finish(resp, None); + Ok(()) + } + Request::ListRequest => { + let resp = CallResp::create( + response, + &CallRespArgs { + ..Default::default() + }, + ); + response.finish(resp, None); + Ok(()) + } + _ => Err(Error::BadRequest), + } + } + /*pub fn handle_old<'a>(&mut self, action: Action<'a>) -> Result<(), Error> { + match action.verb() { + Verb::Join => { + self.remotes.insert( + action.uid().ok_or(Error::BadRequest)?.into(), + action.contact().ok_or(Error::BadRequest)?.into(), + ); + Ok(()) + } + Verb::Leave => { + self.remotes.remove(action.uid().ok_or(Error::NotFound)?); + Ok(()) + } + unknown => { + info!("Unknown verb: {:#?}", unknown); + Err(Error::BadRequest) + } + } + }*/ +} diff --git a/engine/src/gen/beacon_generated.rs b/engine/src/gen/beacon_generated.rs new file mode 100644 index 0000000..927eee4 --- /dev/null +++ b/engine/src/gen/beacon_generated.rs @@ -0,0 +1,1372 @@ +// automatically generated by the FlatBuffers compiler, do not modify + + +// @generated + +use core::mem; +use core::cmp::Ordering; + +extern crate flatbuffers; +use self::flatbuffers::{EndianScalar, Follow}; + +#[allow(unused_imports, dead_code)] +pub mod mmo { + + use core::mem; + use core::cmp::Ordering; + + extern crate flatbuffers; + use self::flatbuffers::{EndianScalar, Follow}; +#[allow(unused_imports, dead_code)] +pub mod beacon { + + 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_VERB: i8 = 0; +#[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")] +pub const ENUM_MAX_VERB: 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_VERB: [Verb; 3] = [ + Verb::Join, + Verb::Leave, + Verb::List, +]; + +#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Default)] +#[repr(transparent)] +pub struct Verb(pub i8); +#[allow(non_upper_case_globals)] +impl Verb { + pub const Join: Self = Self(0); + pub const Leave: Self = Self(1); + pub const List: Self = Self(2); + + pub const ENUM_MIN: i8 = 0; + pub const ENUM_MAX: i8 = 2; + pub const ENUM_VALUES: &'static [Self] = &[ + Self::Join, + Self::Leave, + Self::List, + ]; + /// Returns the variant's name or "" if unknown. + pub fn variant_name(self) -> Option<&'static str> { + match self { + Self::Join => Some("Join"), + Self::Leave => Some("Leave"), + Self::List => Some("List"), + _ => None, + } + } +} +impl core::fmt::Debug for Verb { + 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 Verb { + 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 Verb { + type Output = Verb; + #[inline] + unsafe fn push(&self, dst: &mut [u8], _written_len: usize) { + flatbuffers::emplace_scalar::(dst, self.0); + } +} + +impl flatbuffers::EndianScalar for Verb { + 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 Verb { + #[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 Verb {} +#[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")] +pub const ENUM_MIN_REQUEST: u8 = 0; +#[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")] +pub const ENUM_MAX_REQUEST: 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_REQUEST: [Request; 4] = [ + Request::NONE, + Request::JoinRequest, + Request::LeaveRequest, + Request::ListRequest, +]; + +#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Default)] +#[repr(transparent)] +pub struct Request(pub u8); +#[allow(non_upper_case_globals)] +impl Request { + pub const NONE: Self = Self(0); + pub const JoinRequest: Self = Self(1); + pub const LeaveRequest: Self = Self(2); + pub const ListRequest: Self = Self(3); + + pub const ENUM_MIN: u8 = 0; + pub const ENUM_MAX: u8 = 3; + pub const ENUM_VALUES: &'static [Self] = &[ + Self::NONE, + Self::JoinRequest, + Self::LeaveRequest, + Self::ListRequest, + ]; + /// Returns the variant's name or "" if unknown. + pub fn variant_name(self) -> Option<&'static str> { + match self { + Self::NONE => Some("NONE"), + Self::JoinRequest => Some("JoinRequest"), + Self::LeaveRequest => Some("LeaveRequest"), + Self::ListRequest => Some("ListRequest"), + _ => None, + } + } +} +impl core::fmt::Debug for Request { + 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 Request { + 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 Request { + type Output = Request; + #[inline] + unsafe fn push(&self, dst: &mut [u8], _written_len: usize) { + flatbuffers::emplace_scalar::(dst, self.0); + } +} + +impl flatbuffers::EndianScalar for Request { + 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 Request { + #[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 Request {} +pub struct RequestUnionTableOffset {} + +#[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")] +pub const ENUM_MIN_RESPONSE: u8 = 0; +#[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")] +pub const ENUM_MAX_RESPONSE: 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_RESPONSE: [Response; 4] = [ + Response::NONE, + Response::JoinResponse, + Response::LeaveResponse, + Response::ListResponse, +]; + +#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Default)] +#[repr(transparent)] +pub struct Response(pub u8); +#[allow(non_upper_case_globals)] +impl Response { + pub const NONE: Self = Self(0); + pub const JoinResponse: Self = Self(1); + pub const LeaveResponse: Self = Self(2); + pub const ListResponse: Self = Self(3); + + pub const ENUM_MIN: u8 = 0; + pub const ENUM_MAX: u8 = 3; + pub const ENUM_VALUES: &'static [Self] = &[ + Self::NONE, + Self::JoinResponse, + Self::LeaveResponse, + Self::ListResponse, + ]; + /// Returns the variant's name or "" if unknown. + pub fn variant_name(self) -> Option<&'static str> { + match self { + Self::NONE => Some("NONE"), + Self::JoinResponse => Some("JoinResponse"), + Self::LeaveResponse => Some("LeaveResponse"), + Self::ListResponse => Some("ListResponse"), + _ => None, + } + } +} +impl core::fmt::Debug for Response { + 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 Response { + 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 Response { + type Output = Response; + #[inline] + unsafe fn push(&self, dst: &mut [u8], _written_len: usize) { + flatbuffers::emplace_scalar::(dst, self.0); + } +} + +impl flatbuffers::EndianScalar for Response { + 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 Response { + #[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 Response {} +pub struct ResponseUnionTableOffset {} + +pub enum CallOffset {} +#[derive(Copy, Clone, PartialEq)] + +pub struct Call<'a> { + pub _tab: flatbuffers::Table<'a>, +} + +impl<'a> flatbuffers::Follow<'a> for Call<'a> { + type Inner = Call<'a>; + #[inline] + unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { + Self { _tab: flatbuffers::Table::new(buf, loc) } + } +} + +impl<'a> Call<'a> { + pub const VT_REQUEST_TYPE: flatbuffers::VOffsetT = 4; + pub const VT_REQUEST: flatbuffers::VOffsetT = 6; + + #[inline] + pub unsafe fn init_from_table(table: flatbuffers::Table<'a>) -> Self { + Call { _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 CallArgs + ) -> flatbuffers::WIPOffset> { + let mut builder = CallBuilder::new(_fbb); + if let Some(x) = args.request { builder.add_request(x); } + builder.add_request_type(args.request_type); + builder.finish() + } + + + #[inline] + pub fn request_type(&self) -> Request { + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { self._tab.get::(Call::VT_REQUEST_TYPE, Some(Request::NONE)).unwrap()} + } + #[inline] + pub fn request(&self) -> Option> { + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { self._tab.get::>>(Call::VT_REQUEST, None)} + } + #[inline] + #[allow(non_snake_case)] + pub fn request_as_join_request(&self) -> Option> { + if self.request_type() == Request::JoinRequest { + self.request().map(|t| { + // Safety: + // Created from a valid Table for this object + // Which contains a valid union in this slot + unsafe { JoinRequest::init_from_table(t) } + }) + } else { + None + } + } + + #[inline] + #[allow(non_snake_case)] + pub fn request_as_leave_request(&self) -> Option> { + if self.request_type() == Request::LeaveRequest { + self.request().map(|t| { + // Safety: + // Created from a valid Table for this object + // Which contains a valid union in this slot + unsafe { LeaveRequest::init_from_table(t) } + }) + } else { + None + } + } + + #[inline] + #[allow(non_snake_case)] + pub fn request_as_list_request(&self) -> Option> { + if self.request_type() == Request::ListRequest { + self.request().map(|t| { + // Safety: + // Created from a valid Table for this object + // Which contains a valid union in this slot + unsafe { ListRequest::init_from_table(t) } + }) + } else { + None + } + } + +} + +impl flatbuffers::Verifiable for Call<'_> { + #[inline] + fn run_verifier( + v: &mut flatbuffers::Verifier, pos: usize + ) -> Result<(), flatbuffers::InvalidFlatbuffer> { + use self::flatbuffers::Verifiable; + v.visit_table(pos)? + .visit_union::("request_type", Self::VT_REQUEST_TYPE, "request", Self::VT_REQUEST, false, |key, v, pos| { + match key { + Request::JoinRequest => v.verify_union_variant::>("Request::JoinRequest", pos), + Request::LeaveRequest => v.verify_union_variant::>("Request::LeaveRequest", pos), + Request::ListRequest => v.verify_union_variant::>("Request::ListRequest", pos), + _ => Ok(()), + } + })? + .finish(); + Ok(()) + } +} +pub struct CallArgs { + pub request_type: Request, + pub request: Option>, +} +impl<'a> Default for CallArgs { + #[inline] + fn default() -> Self { + CallArgs { + request_type: Request::NONE, + request: None, + } + } +} + +pub struct CallBuilder<'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> CallBuilder<'a, 'b, A> { + #[inline] + pub fn add_request_type(&mut self, request_type: Request) { + self.fbb_.push_slot::(Call::VT_REQUEST_TYPE, request_type, Request::NONE); + } + #[inline] + pub fn add_request(&mut self, request: flatbuffers::WIPOffset) { + self.fbb_.push_slot_always::>(Call::VT_REQUEST, request); + } + #[inline] + pub fn new(_fbb: &'b mut flatbuffers::FlatBufferBuilder<'a, A>) -> CallBuilder<'a, 'b, A> { + let start = _fbb.start_table(); + CallBuilder { + 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 Call<'_> { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + let mut ds = f.debug_struct("Call"); + ds.field("request_type", &self.request_type()); + match self.request_type() { + Request::JoinRequest => { + if let Some(x) = self.request_as_join_request() { + ds.field("request", &x) + } else { + ds.field("request", &"InvalidFlatbuffer: Union discriminant does not match value.") + } + }, + Request::LeaveRequest => { + if let Some(x) = self.request_as_leave_request() { + ds.field("request", &x) + } else { + ds.field("request", &"InvalidFlatbuffer: Union discriminant does not match value.") + } + }, + Request::ListRequest => { + if let Some(x) = self.request_as_list_request() { + ds.field("request", &x) + } else { + ds.field("request", &"InvalidFlatbuffer: Union discriminant does not match value.") + } + }, + _ => { + let x: Option<()> = None; + ds.field("request", &x) + }, + }; + ds.finish() + } +} +pub enum JoinRequestOffset {} +#[derive(Copy, Clone, PartialEq)] + +pub struct JoinRequest<'a> { + pub _tab: flatbuffers::Table<'a>, +} + +impl<'a> flatbuffers::Follow<'a> for JoinRequest<'a> { + type Inner = JoinRequest<'a>; + #[inline] + unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { + Self { _tab: flatbuffers::Table::new(buf, loc) } + } +} + +impl<'a> JoinRequest<'a> { + pub const VT_UID: flatbuffers::VOffsetT = 4; + pub const VT_CONTACT: flatbuffers::VOffsetT = 6; + pub const VT_CLOCK: flatbuffers::VOffsetT = 8; + + #[inline] + pub unsafe fn init_from_table(table: flatbuffers::Table<'a>) -> Self { + JoinRequest { _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 JoinRequestArgs<'args> + ) -> flatbuffers::WIPOffset> { + let mut builder = JoinRequestBuilder::new(_fbb); + builder.add_clock(args.clock); + if let Some(x) = args.contact { builder.add_contact(x); } + if let Some(x) = args.uid { builder.add_uid(x); } + builder.finish() + } + + + #[inline] + pub fn uid(&self) -> &'a str { + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { self._tab.get::>(JoinRequest::VT_UID, None).unwrap()} + } + #[inline] + pub fn contact(&self) -> &'a str { + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { self._tab.get::>(JoinRequest::VT_CONTACT, None).unwrap()} + } + #[inline] + pub fn clock(&self) -> i64 { + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { self._tab.get::(JoinRequest::VT_CLOCK, Some(0)).unwrap()} + } +} + +impl flatbuffers::Verifiable for JoinRequest<'_> { + #[inline] + fn run_verifier( + v: &mut flatbuffers::Verifier, pos: usize + ) -> Result<(), flatbuffers::InvalidFlatbuffer> { + use self::flatbuffers::Verifiable; + v.visit_table(pos)? + .visit_field::>("uid", Self::VT_UID, true)? + .visit_field::>("contact", Self::VT_CONTACT, true)? + .visit_field::("clock", Self::VT_CLOCK, false)? + .finish(); + Ok(()) + } +} +pub struct JoinRequestArgs<'a> { + pub uid: Option>, + pub contact: Option>, + pub clock: i64, +} +impl<'a> Default for JoinRequestArgs<'a> { + #[inline] + fn default() -> Self { + JoinRequestArgs { + uid: None, // required field + contact: None, // required field + clock: 0, + } + } +} + +pub struct JoinRequestBuilder<'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> JoinRequestBuilder<'a, 'b, A> { + #[inline] + pub fn add_uid(&mut self, uid: flatbuffers::WIPOffset<&'b str>) { + self.fbb_.push_slot_always::>(JoinRequest::VT_UID, uid); + } + #[inline] + pub fn add_contact(&mut self, contact: flatbuffers::WIPOffset<&'b str>) { + self.fbb_.push_slot_always::>(JoinRequest::VT_CONTACT, contact); + } + #[inline] + pub fn add_clock(&mut self, clock: i64) { + self.fbb_.push_slot::(JoinRequest::VT_CLOCK, clock, 0); + } + #[inline] + pub fn new(_fbb: &'b mut flatbuffers::FlatBufferBuilder<'a, A>) -> JoinRequestBuilder<'a, 'b, A> { + let start = _fbb.start_table(); + JoinRequestBuilder { + fbb_: _fbb, + start_: start, + } + } + #[inline] + pub fn finish(self) -> flatbuffers::WIPOffset> { + let o = self.fbb_.end_table(self.start_); + self.fbb_.required(o, JoinRequest::VT_UID,"uid"); + self.fbb_.required(o, JoinRequest::VT_CONTACT,"contact"); + flatbuffers::WIPOffset::new(o.value()) + } +} + +impl core::fmt::Debug for JoinRequest<'_> { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + let mut ds = f.debug_struct("JoinRequest"); + ds.field("uid", &self.uid()); + ds.field("contact", &self.contact()); + ds.field("clock", &self.clock()); + ds.finish() + } +} +pub enum LeaveRequestOffset {} +#[derive(Copy, Clone, PartialEq)] + +pub struct LeaveRequest<'a> { + pub _tab: flatbuffers::Table<'a>, +} + +impl<'a> flatbuffers::Follow<'a> for LeaveRequest<'a> { + type Inner = LeaveRequest<'a>; + #[inline] + unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { + Self { _tab: flatbuffers::Table::new(buf, loc) } + } +} + +impl<'a> LeaveRequest<'a> { + pub const VT_UID: flatbuffers::VOffsetT = 4; + + #[inline] + pub unsafe fn init_from_table(table: flatbuffers::Table<'a>) -> Self { + LeaveRequest { _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 LeaveRequestArgs<'args> + ) -> flatbuffers::WIPOffset> { + let mut builder = LeaveRequestBuilder::new(_fbb); + if let Some(x) = args.uid { builder.add_uid(x); } + builder.finish() + } + + + #[inline] + pub fn uid(&self) -> &'a str { + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { self._tab.get::>(LeaveRequest::VT_UID, None).unwrap()} + } +} + +impl flatbuffers::Verifiable for LeaveRequest<'_> { + #[inline] + fn run_verifier( + v: &mut flatbuffers::Verifier, pos: usize + ) -> Result<(), flatbuffers::InvalidFlatbuffer> { + use self::flatbuffers::Verifiable; + v.visit_table(pos)? + .visit_field::>("uid", Self::VT_UID, true)? + .finish(); + Ok(()) + } +} +pub struct LeaveRequestArgs<'a> { + pub uid: Option>, +} +impl<'a> Default for LeaveRequestArgs<'a> { + #[inline] + fn default() -> Self { + LeaveRequestArgs { + uid: None, // required field + } + } +} + +pub struct LeaveRequestBuilder<'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> LeaveRequestBuilder<'a, 'b, A> { + #[inline] + pub fn add_uid(&mut self, uid: flatbuffers::WIPOffset<&'b str>) { + self.fbb_.push_slot_always::>(LeaveRequest::VT_UID, uid); + } + #[inline] + pub fn new(_fbb: &'b mut flatbuffers::FlatBufferBuilder<'a, A>) -> LeaveRequestBuilder<'a, 'b, A> { + let start = _fbb.start_table(); + LeaveRequestBuilder { + fbb_: _fbb, + start_: start, + } + } + #[inline] + pub fn finish(self) -> flatbuffers::WIPOffset> { + let o = self.fbb_.end_table(self.start_); + self.fbb_.required(o, LeaveRequest::VT_UID,"uid"); + flatbuffers::WIPOffset::new(o.value()) + } +} + +impl core::fmt::Debug for LeaveRequest<'_> { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + let mut ds = f.debug_struct("LeaveRequest"); + ds.field("uid", &self.uid()); + ds.finish() + } +} +pub enum ListRequestOffset {} +#[derive(Copy, Clone, PartialEq)] + +pub struct ListRequest<'a> { + pub _tab: flatbuffers::Table<'a>, +} + +impl<'a> flatbuffers::Follow<'a> for ListRequest<'a> { + type Inner = ListRequest<'a>; + #[inline] + unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { + Self { _tab: flatbuffers::Table::new(buf, loc) } + } +} + +impl<'a> ListRequest<'a> { + + #[inline] + pub unsafe fn init_from_table(table: flatbuffers::Table<'a>) -> Self { + ListRequest { _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 ListRequestArgs + ) -> flatbuffers::WIPOffset> { + let mut builder = ListRequestBuilder::new(_fbb); + builder.finish() + } + +} + +impl flatbuffers::Verifiable for ListRequest<'_> { + #[inline] + fn run_verifier( + v: &mut flatbuffers::Verifier, pos: usize + ) -> Result<(), flatbuffers::InvalidFlatbuffer> { + use self::flatbuffers::Verifiable; + v.visit_table(pos)? + .finish(); + Ok(()) + } +} +pub struct ListRequestArgs { +} +impl<'a> Default for ListRequestArgs { + #[inline] + fn default() -> Self { + ListRequestArgs { + } + } +} + +pub struct ListRequestBuilder<'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> ListRequestBuilder<'a, 'b, A> { + #[inline] + pub fn new(_fbb: &'b mut flatbuffers::FlatBufferBuilder<'a, A>) -> ListRequestBuilder<'a, 'b, A> { + let start = _fbb.start_table(); + ListRequestBuilder { + 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 ListRequest<'_> { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + let mut ds = f.debug_struct("ListRequest"); + ds.finish() + } +} +pub enum CallRespOffset {} +#[derive(Copy, Clone, PartialEq)] + +pub struct CallResp<'a> { + pub _tab: flatbuffers::Table<'a>, +} + +impl<'a> flatbuffers::Follow<'a> for CallResp<'a> { + type Inner = CallResp<'a>; + #[inline] + unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { + Self { _tab: flatbuffers::Table::new(buf, loc) } + } +} + +impl<'a> CallResp<'a> { + pub const VT_RESPONSE_TYPE: flatbuffers::VOffsetT = 4; + pub const VT_RESPONSE: flatbuffers::VOffsetT = 6; + + #[inline] + pub unsafe fn init_from_table(table: flatbuffers::Table<'a>) -> Self { + CallResp { _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 CallRespArgs + ) -> flatbuffers::WIPOffset> { + let mut builder = CallRespBuilder::new(_fbb); + if let Some(x) = args.response { builder.add_response(x); } + builder.add_response_type(args.response_type); + builder.finish() + } + + + #[inline] + pub fn response_type(&self) -> Response { + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { self._tab.get::(CallResp::VT_RESPONSE_TYPE, Some(Response::NONE)).unwrap()} + } + #[inline] + pub fn response(&self) -> Option> { + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { self._tab.get::>>(CallResp::VT_RESPONSE, None)} + } + #[inline] + #[allow(non_snake_case)] + pub fn response_as_join_response(&self) -> Option> { + if self.response_type() == Response::JoinResponse { + self.response().map(|t| { + // Safety: + // Created from a valid Table for this object + // Which contains a valid union in this slot + unsafe { JoinResponse::init_from_table(t) } + }) + } else { + None + } + } + + #[inline] + #[allow(non_snake_case)] + pub fn response_as_leave_response(&self) -> Option> { + if self.response_type() == Response::LeaveResponse { + self.response().map(|t| { + // Safety: + // Created from a valid Table for this object + // Which contains a valid union in this slot + unsafe { LeaveResponse::init_from_table(t) } + }) + } else { + None + } + } + + #[inline] + #[allow(non_snake_case)] + pub fn response_as_list_response(&self) -> Option> { + if self.response_type() == Response::ListResponse { + self.response().map(|t| { + // Safety: + // Created from a valid Table for this object + // Which contains a valid union in this slot + unsafe { ListResponse::init_from_table(t) } + }) + } else { + None + } + } + +} + +impl flatbuffers::Verifiable for CallResp<'_> { + #[inline] + fn run_verifier( + v: &mut flatbuffers::Verifier, pos: usize + ) -> Result<(), flatbuffers::InvalidFlatbuffer> { + use self::flatbuffers::Verifiable; + v.visit_table(pos)? + .visit_union::("response_type", Self::VT_RESPONSE_TYPE, "response", Self::VT_RESPONSE, false, |key, v, pos| { + match key { + Response::JoinResponse => v.verify_union_variant::>("Response::JoinResponse", pos), + Response::LeaveResponse => v.verify_union_variant::>("Response::LeaveResponse", pos), + Response::ListResponse => v.verify_union_variant::>("Response::ListResponse", pos), + _ => Ok(()), + } + })? + .finish(); + Ok(()) + } +} +pub struct CallRespArgs { + pub response_type: Response, + pub response: Option>, +} +impl<'a> Default for CallRespArgs { + #[inline] + fn default() -> Self { + CallRespArgs { + response_type: Response::NONE, + response: None, + } + } +} + +pub struct CallRespBuilder<'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> CallRespBuilder<'a, 'b, A> { + #[inline] + pub fn add_response_type(&mut self, response_type: Response) { + self.fbb_.push_slot::(CallResp::VT_RESPONSE_TYPE, response_type, Response::NONE); + } + #[inline] + pub fn add_response(&mut self, response: flatbuffers::WIPOffset) { + self.fbb_.push_slot_always::>(CallResp::VT_RESPONSE, response); + } + #[inline] + pub fn new(_fbb: &'b mut flatbuffers::FlatBufferBuilder<'a, A>) -> CallRespBuilder<'a, 'b, A> { + let start = _fbb.start_table(); + CallRespBuilder { + 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 CallResp<'_> { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + let mut ds = f.debug_struct("CallResp"); + ds.field("response_type", &self.response_type()); + match self.response_type() { + Response::JoinResponse => { + if let Some(x) = self.response_as_join_response() { + ds.field("response", &x) + } else { + ds.field("response", &"InvalidFlatbuffer: Union discriminant does not match value.") + } + }, + Response::LeaveResponse => { + if let Some(x) = self.response_as_leave_response() { + ds.field("response", &x) + } else { + ds.field("response", &"InvalidFlatbuffer: Union discriminant does not match value.") + } + }, + Response::ListResponse => { + if let Some(x) = self.response_as_list_response() { + ds.field("response", &x) + } else { + ds.field("response", &"InvalidFlatbuffer: Union discriminant does not match value.") + } + }, + _ => { + let x: Option<()> = None; + ds.field("response", &x) + }, + }; + ds.finish() + } +} +pub enum JoinResponseOffset {} +#[derive(Copy, Clone, PartialEq)] + +pub struct JoinResponse<'a> { + pub _tab: flatbuffers::Table<'a>, +} + +impl<'a> flatbuffers::Follow<'a> for JoinResponse<'a> { + type Inner = JoinResponse<'a>; + #[inline] + unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { + Self { _tab: flatbuffers::Table::new(buf, loc) } + } +} + +impl<'a> JoinResponse<'a> { + + #[inline] + pub unsafe fn init_from_table(table: flatbuffers::Table<'a>) -> Self { + JoinResponse { _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 JoinResponseArgs + ) -> flatbuffers::WIPOffset> { + let mut builder = JoinResponseBuilder::new(_fbb); + builder.finish() + } + +} + +impl flatbuffers::Verifiable for JoinResponse<'_> { + #[inline] + fn run_verifier( + v: &mut flatbuffers::Verifier, pos: usize + ) -> Result<(), flatbuffers::InvalidFlatbuffer> { + use self::flatbuffers::Verifiable; + v.visit_table(pos)? + .finish(); + Ok(()) + } +} +pub struct JoinResponseArgs { +} +impl<'a> Default for JoinResponseArgs { + #[inline] + fn default() -> Self { + JoinResponseArgs { + } + } +} + +pub struct JoinResponseBuilder<'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> JoinResponseBuilder<'a, 'b, A> { + #[inline] + pub fn new(_fbb: &'b mut flatbuffers::FlatBufferBuilder<'a, A>) -> JoinResponseBuilder<'a, 'b, A> { + let start = _fbb.start_table(); + JoinResponseBuilder { + 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 JoinResponse<'_> { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + let mut ds = f.debug_struct("JoinResponse"); + ds.finish() + } +} +pub enum LeaveResponseOffset {} +#[derive(Copy, Clone, PartialEq)] + +pub struct LeaveResponse<'a> { + pub _tab: flatbuffers::Table<'a>, +} + +impl<'a> flatbuffers::Follow<'a> for LeaveResponse<'a> { + type Inner = LeaveResponse<'a>; + #[inline] + unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { + Self { _tab: flatbuffers::Table::new(buf, loc) } + } +} + +impl<'a> LeaveResponse<'a> { + + #[inline] + pub unsafe fn init_from_table(table: flatbuffers::Table<'a>) -> Self { + LeaveResponse { _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 LeaveResponseArgs + ) -> flatbuffers::WIPOffset> { + let mut builder = LeaveResponseBuilder::new(_fbb); + builder.finish() + } + +} + +impl flatbuffers::Verifiable for LeaveResponse<'_> { + #[inline] + fn run_verifier( + v: &mut flatbuffers::Verifier, pos: usize + ) -> Result<(), flatbuffers::InvalidFlatbuffer> { + use self::flatbuffers::Verifiable; + v.visit_table(pos)? + .finish(); + Ok(()) + } +} +pub struct LeaveResponseArgs { +} +impl<'a> Default for LeaveResponseArgs { + #[inline] + fn default() -> Self { + LeaveResponseArgs { + } + } +} + +pub struct LeaveResponseBuilder<'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> LeaveResponseBuilder<'a, 'b, A> { + #[inline] + pub fn new(_fbb: &'b mut flatbuffers::FlatBufferBuilder<'a, A>) -> LeaveResponseBuilder<'a, 'b, A> { + let start = _fbb.start_table(); + LeaveResponseBuilder { + 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 LeaveResponse<'_> { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + let mut ds = f.debug_struct("LeaveResponse"); + ds.finish() + } +} +pub enum ListResponseOffset {} +#[derive(Copy, Clone, PartialEq)] + +pub struct ListResponse<'a> { + pub _tab: flatbuffers::Table<'a>, +} + +impl<'a> flatbuffers::Follow<'a> for ListResponse<'a> { + type Inner = ListResponse<'a>; + #[inline] + unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { + Self { _tab: flatbuffers::Table::new(buf, loc) } + } +} + +impl<'a> ListResponse<'a> { + pub const VT_ENTITIES: flatbuffers::VOffsetT = 4; + + #[inline] + pub unsafe fn init_from_table(table: flatbuffers::Table<'a>) -> Self { + ListResponse { _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 ListResponseArgs<'args> + ) -> flatbuffers::WIPOffset> { + let mut builder = ListResponseBuilder::new(_fbb); + if let Some(x) = args.entities { builder.add_entities(x); } + builder.finish() + } + + + #[inline] + pub fn entities(&self) -> Option>>> { + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { self._tab.get::>>>(ListResponse::VT_ENTITIES, None)} + } +} + +impl flatbuffers::Verifiable for ListResponse<'_> { + #[inline] + fn run_verifier( + v: &mut flatbuffers::Verifier, pos: usize + ) -> Result<(), flatbuffers::InvalidFlatbuffer> { + use self::flatbuffers::Verifiable; + v.visit_table(pos)? + .visit_field::>>>("entities", Self::VT_ENTITIES, false)? + .finish(); + Ok(()) + } +} +pub struct ListResponseArgs<'a> { + pub entities: Option>>>>, +} +impl<'a> Default for ListResponseArgs<'a> { + #[inline] + fn default() -> Self { + ListResponseArgs { + entities: None, + } + } +} + +pub struct ListResponseBuilder<'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> ListResponseBuilder<'a, 'b, A> { + #[inline] + pub fn add_entities(&mut self, entities: flatbuffers::WIPOffset>>>) { + self.fbb_.push_slot_always::>(ListResponse::VT_ENTITIES, entities); + } + #[inline] + pub fn new(_fbb: &'b mut flatbuffers::FlatBufferBuilder<'a, A>) -> ListResponseBuilder<'a, 'b, A> { + let start = _fbb.start_table(); + ListResponseBuilder { + 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 ListResponse<'_> { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + let mut ds = f.debug_struct("ListResponse"); + ds.field("entities", &self.entities()); + ds.finish() + } +} +pub enum EntityOffset {} +#[derive(Copy, Clone, PartialEq)] + +pub struct Entity<'a> { + pub _tab: flatbuffers::Table<'a>, +} + +impl<'a> flatbuffers::Follow<'a> for Entity<'a> { + type Inner = Entity<'a>; + #[inline] + unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner { + Self { _tab: flatbuffers::Table::new(buf, loc) } + } +} + +impl<'a> Entity<'a> { + pub const VT_UID: flatbuffers::VOffsetT = 4; + pub const VT_CLOCK: flatbuffers::VOffsetT = 6; + + #[inline] + pub unsafe fn init_from_table(table: flatbuffers::Table<'a>) -> Self { + Entity { _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 EntityArgs<'args> + ) -> flatbuffers::WIPOffset> { + let mut builder = EntityBuilder::new(_fbb); + builder.add_clock(args.clock); + if let Some(x) = args.uid { builder.add_uid(x); } + builder.finish() + } + + + #[inline] + pub fn uid(&self) -> &'a str { + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { self._tab.get::>(Entity::VT_UID, None).unwrap()} + } + #[inline] + pub fn clock(&self) -> i64 { + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { self._tab.get::(Entity::VT_CLOCK, Some(0)).unwrap()} + } +} + +impl flatbuffers::Verifiable for Entity<'_> { + #[inline] + fn run_verifier( + v: &mut flatbuffers::Verifier, pos: usize + ) -> Result<(), flatbuffers::InvalidFlatbuffer> { + use self::flatbuffers::Verifiable; + v.visit_table(pos)? + .visit_field::>("uid", Self::VT_UID, true)? + .visit_field::("clock", Self::VT_CLOCK, false)? + .finish(); + Ok(()) + } +} +pub struct EntityArgs<'a> { + pub uid: Option>, + pub clock: i64, +} +impl<'a> Default for EntityArgs<'a> { + #[inline] + fn default() -> Self { + EntityArgs { + uid: None, // required field + clock: 0, + } + } +} + +pub struct EntityBuilder<'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> EntityBuilder<'a, 'b, A> { + #[inline] + pub fn add_uid(&mut self, uid: flatbuffers::WIPOffset<&'b str>) { + self.fbb_.push_slot_always::>(Entity::VT_UID, uid); + } + #[inline] + pub fn add_clock(&mut self, clock: i64) { + self.fbb_.push_slot::(Entity::VT_CLOCK, clock, 0); + } + #[inline] + pub fn new(_fbb: &'b mut flatbuffers::FlatBufferBuilder<'a, A>) -> EntityBuilder<'a, 'b, A> { + let start = _fbb.start_table(); + EntityBuilder { + fbb_: _fbb, + start_: start, + } + } + #[inline] + pub fn finish(self) -> flatbuffers::WIPOffset> { + let o = self.fbb_.end_table(self.start_); + self.fbb_.required(o, Entity::VT_UID,"uid"); + flatbuffers::WIPOffset::new(o.value()) + } +} + +impl core::fmt::Debug for Entity<'_> { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + let mut ds = f.debug_struct("Entity"); + ds.field("uid", &self.uid()); + ds.field("clock", &self.clock()); + ds.finish() + } +} +} // pub mod beacon +} // pub mod mmo + diff --git a/engine/src/gen/errors_generated.rs b/engine/src/gen/errors_generated.rs new file mode 100644 index 0000000..7f8fbd0 --- /dev/null +++ b/engine/src/gen/errors_generated.rs @@ -0,0 +1,116 @@ +// automatically generated by the FlatBuffers compiler, do not modify + + +// @generated + +use core::mem; +use core::cmp::Ordering; + +extern crate flatbuffers; +use self::flatbuffers::{EndianScalar, Follow}; + +#[allow(unused_imports, dead_code)] +pub mod mmo { + + use core::mem; + use core::cmp::Ordering; + + extern crate flatbuffers; + use self::flatbuffers::{EndianScalar, Follow}; +#[allow(unused_imports, dead_code)] +pub mod util { + + 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_ERROR: i16 = 0; +#[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")] +pub const ENUM_MAX_ERROR: i16 = 1; +#[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_ERROR: [Error; 2] = [ + Error::BadRequest, + Error::NotFound, +]; + +#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Default)] +#[repr(transparent)] +pub struct Error(pub i16); +#[allow(non_upper_case_globals)] +impl Error { + pub const BadRequest: Self = Self(0); + pub const NotFound: Self = Self(1); + + pub const ENUM_MIN: i16 = 0; + pub const ENUM_MAX: i16 = 1; + pub const ENUM_VALUES: &'static [Self] = &[ + Self::BadRequest, + Self::NotFound, + ]; + /// Returns the variant's name or "" if unknown. + pub fn variant_name(self) -> Option<&'static str> { + match self { + Self::BadRequest => Some("BadRequest"), + Self::NotFound => Some("NotFound"), + _ => None, + } + } +} +impl core::fmt::Debug for Error { + 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 Error { + 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 Error { + type Output = Error; + #[inline] + unsafe fn push(&self, dst: &mut [u8], _written_len: usize) { + flatbuffers::emplace_scalar::(dst, self.0); + } +} + +impl flatbuffers::EndianScalar for Error { + type Scalar = i16; + #[inline] + fn to_little_endian(self) -> i16 { + self.0.to_le() + } + #[inline] + #[allow(clippy::wrong_self_convention)] + fn from_little_endian(v: i16) -> Self { + let b = i16::from_le(v); + Self(b) + } +} + +impl<'a> flatbuffers::Verifiable for Error { + #[inline] + fn run_verifier( + v: &mut flatbuffers::Verifier, pos: usize + ) -> Result<(), flatbuffers::InvalidFlatbuffer> { + use self::flatbuffers::Verifiable; + i16::run_verifier(v, pos) + } +} + +impl flatbuffers::SimpleToVerifyInSlice for Error {} +} // pub mod util +} // pub mod mmo + diff --git a/engine/src/gen/mod.rs b/engine/src/gen/mod.rs new file mode 100644 index 0000000..53b177e --- /dev/null +++ b/engine/src/gen/mod.rs @@ -0,0 +1,7 @@ +#![allow(dead_code, unused_imports)] +mod beacon_generated; +mod errors_generated; +pub mod mmo { + pub use super::beacon_generated::mmo::*; + pub use super::errors_generated::mmo::*; +} \ No newline at end of file diff --git a/engine/src/lib.rs b/engine/src/lib.rs new file mode 100644 index 0000000..a2a4f13 --- /dev/null +++ b/engine/src/lib.rs @@ -0,0 +1,3 @@ +pub mod beacon; +pub mod player; +mod gen; \ No newline at end of file diff --git a/engine/src/main.rs b/engine/src/main.rs new file mode 100644 index 0000000..e7a11a9 --- /dev/null +++ b/engine/src/main.rs @@ -0,0 +1,3 @@ +fn main() { + println!("Hello, world!"); +} diff --git a/engine/src/player/mod.rs b/engine/src/player/mod.rs new file mode 100644 index 0000000..9310323 --- /dev/null +++ b/engine/src/player/mod.rs @@ -0,0 +1 @@ +mod server; \ No newline at end of file diff --git a/engine/src/player/server/mod.rs b/engine/src/player/server/mod.rs new file mode 100644 index 0000000..e69de29