add: half baked
This commit is contained in:
Generated
+48
@@ -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"
|
||||
@@ -0,0 +1,8 @@
|
||||
[package]
|
||||
name = "engine"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
flatbuffers = "25.2.10"
|
||||
log = "0.4.26"
|
||||
@@ -0,0 +1,3 @@
|
||||
all:
|
||||
flatc --rust -o src/gen/ schema/*.fbs
|
||||
cargo build
|
||||
@@ -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;
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
namespace mmo.util;
|
||||
|
||||
enum Error:short {
|
||||
BadRequest = 0,
|
||||
NotFound,
|
||||
}
|
||||
@@ -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<String, String>,
|
||||
}
|
||||
|
||||
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)
|
||||
}
|
||||
}
|
||||
}*/
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -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!("<UNKNOWN {:?}>", 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::<i16>(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::<i16>(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
|
||||
|
||||
@@ -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::*;
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
pub mod beacon;
|
||||
pub mod player;
|
||||
mod gen;
|
||||
@@ -0,0 +1,3 @@
|
||||
fn main() {
|
||||
println!("Hello, world!");
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
mod server;
|
||||
Reference in New Issue
Block a user