Bump flatbuffers to v24.3.25 version (#6968)
This commit is contained in:
committed by
GitHub
parent
7436835244
commit
825132eec7
+1
-1
@@ -17,7 +17,7 @@
|
||||
// To run, use the `csharp_sample.sh` script.
|
||||
|
||||
using System;
|
||||
using FlatBuffers;
|
||||
using Google.FlatBuffers;
|
||||
using MyGame.Sample;
|
||||
|
||||
class SampleBinary
|
||||
|
||||
@@ -95,6 +95,12 @@ class SampleBinary {
|
||||
assert monster.weapons(i).damage() == expectedWeaponDamages[i];
|
||||
}
|
||||
|
||||
Weapon.Vector weaponsVector = monster.weaponsVector();
|
||||
for (int i = 0; i < weaponsVector.length(); i++) {
|
||||
assert weaponsVector.get(i).name().equals(expectedWeaponNames[i]);
|
||||
assert weaponsVector.get(i).damage() == expectedWeaponDamages[i];
|
||||
}
|
||||
|
||||
// Get and test the `equipped` FlatBuffer `union`.
|
||||
assert monster.equippedType() == Equipment.Weapon;
|
||||
Weapon equipped = (Weapon)monster.equipped(new Weapon());
|
||||
|
||||
+3
-2
@@ -24,6 +24,7 @@ import MyGame.Sample.Weapon
|
||||
|
||||
import com.google.flatbuffers.FlatBufferBuilder
|
||||
|
||||
@kotlin.ExperimentalUnsignedTypes
|
||||
class SampleBinary {
|
||||
|
||||
companion object {
|
||||
@@ -45,7 +46,7 @@ class SampleBinary {
|
||||
|
||||
// Serialize the FlatBuffer data.
|
||||
val name = builder.createString("Orc")
|
||||
val treasure = byteArrayOf(0, 1, 2, 3, 4, 5, 6, 7, 8, 9)
|
||||
val treasure = byteArrayOf(0, 1, 2, 3, 4, 5, 6, 7, 8, 9).asUByteArray()
|
||||
val inv = Monster.createInventoryVector(builder, treasure)
|
||||
val weapons = Monster.createWeaponsVector(builder, weaps)
|
||||
val pos = Vec3.createVec3(builder, 1.0f, 2.0f, 3.0f)
|
||||
@@ -85,7 +86,7 @@ class SampleBinary {
|
||||
|
||||
// Get and test the `inventory` FlatBuffer `vector`.
|
||||
for (i in 0 until monster.inventoryLength) {
|
||||
assert(monster.inventory(i) == i.toByte().toInt())
|
||||
assert(monster.inventory(i) == i.toUByte())
|
||||
}
|
||||
|
||||
// Get and test the `weapons` FlatBuffer `vector` of `table`s.
|
||||
|
||||
@@ -1,45 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- Copyright (c) 2015 Google, Inc.
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
arising from the use of this software.
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it
|
||||
freely, subject to the following restrictions:
|
||||
1. The origin of this software must not be misrepresented; you must not
|
||||
claim that you wrote the original software. If you use this software
|
||||
in a product, an acknowledgment in the product documentation would be
|
||||
appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be
|
||||
misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
-->
|
||||
<!-- BEGIN_INCLUDE(manifest) -->
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="com.samples.FlatBufferSample">
|
||||
|
||||
<uses-feature android:glEsVersion="0x00020000"></uses-feature>
|
||||
|
||||
<!-- This .apk has no Java code itself, so set hasCode to false. -->
|
||||
<application android:label="@string/app_name"
|
||||
android:hasCode="false"
|
||||
android:allowBackup="false">
|
||||
<!-- Our activity is the built-in NativeActivity framework class.
|
||||
This will take care of integrating with our NDK code. -->
|
||||
<activity android:name="android.app.NativeActivity"
|
||||
android:label="@string/app_name"
|
||||
android:configChanges="orientation|keyboardHidden"
|
||||
android:screenOrientation="landscape">
|
||||
<!-- Tell NativeActivity the name of or .so -->
|
||||
<meta-data android:name="android.app.lib_name"
|
||||
android:value="FlatBufferSample" />
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
</application>
|
||||
|
||||
</manifest>
|
||||
<!-- END_INCLUDE(manifest) -->
|
||||
@@ -1,108 +0,0 @@
|
||||
// Copyright (c) 2017 Google, Inc.
|
||||
//
|
||||
// This software is provided 'as-is', without any express or implied
|
||||
// warranty. In no event will the authors be held liable for any damages
|
||||
// arising from the use of this software.
|
||||
// Permission is granted to anyone to use this software for any purpose,
|
||||
// including commercial applications, and to alter it and redistribute it
|
||||
// freely, subject to the following restrictions:
|
||||
// 1. The origin of this software must not be misrepresented; you must not
|
||||
// claim that you wrote the original software. If you use this software
|
||||
// in a product, an acknowledgment in the product documentation would be
|
||||
// appreciated but is not required.
|
||||
// 2. Altered source versions must be plainly marked as such, and must not be
|
||||
// misrepresented as being the original software.
|
||||
// 3. This notice may not be removed or altered from any source distribution.
|
||||
|
||||
buildscript {
|
||||
repositories {
|
||||
jcenter()
|
||||
}
|
||||
dependencies {
|
||||
classpath 'com.android.tools.build:gradle:2.3.0'
|
||||
}
|
||||
}
|
||||
|
||||
allprojects {
|
||||
repositories {
|
||||
jcenter()
|
||||
}
|
||||
}
|
||||
|
||||
apply plugin: 'com.android.application'
|
||||
|
||||
android {
|
||||
compileSdkVersion 25
|
||||
buildToolsVersion '25.0.2'
|
||||
|
||||
sourceSets {
|
||||
main {
|
||||
manifest.srcFile 'AndroidManifest.xml'
|
||||
res.srcDirs = ['res']
|
||||
}
|
||||
}
|
||||
|
||||
externalNativeBuild {
|
||||
ndkBuild {
|
||||
path "jni/Android.mk"
|
||||
}
|
||||
}
|
||||
|
||||
defaultConfig {
|
||||
applicationId 'com.samples.FlatBufferSample'
|
||||
// This is the platform API where NativeActivity was introduced.
|
||||
minSdkVersion 9
|
||||
targetSdkVersion 25
|
||||
versionCode 1
|
||||
versionName "1.0"
|
||||
|
||||
buildTypes {
|
||||
release {
|
||||
minifyEnabled false
|
||||
}
|
||||
}
|
||||
|
||||
externalNativeBuild {
|
||||
ndkBuild {
|
||||
targets "FlatBufferSample"
|
||||
arguments "-j" + Runtime.getRuntime().availableProcessors()
|
||||
abiFilters "armeabi-v7a", "arm64-v8a", "x86", "x86_64"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
lintOptions {
|
||||
abortOnError false
|
||||
}
|
||||
|
||||
// Build with each STL variant.
|
||||
productFlavors {
|
||||
stlport {
|
||||
applicationIdSuffix ".stlport"
|
||||
versionNameSuffix "-stlport"
|
||||
externalNativeBuild {
|
||||
ndkBuild {
|
||||
arguments "APP_STL=stlport_static"
|
||||
}
|
||||
}
|
||||
}
|
||||
gnustl {
|
||||
applicationIdSuffix ".gnustl"
|
||||
versionNameSuffix "-gnustl"
|
||||
externalNativeBuild {
|
||||
ndkBuild {
|
||||
arguments "APP_STL=gnustl_static"
|
||||
}
|
||||
}
|
||||
}
|
||||
libcpp {
|
||||
applicationIdSuffix ".libcpp"
|
||||
versionNameSuffix "-libcpp"
|
||||
externalNativeBuild {
|
||||
ndkBuild {
|
||||
arguments "APP_STL=c++_static"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
-6
@@ -1,6 +0,0 @@
|
||||
#Mon Jun 19 11:54:59 PDT 2017
|
||||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-4.0-all.zip
|
||||
-172
@@ -1,172 +0,0 @@
|
||||
#!/usr/bin/env sh
|
||||
|
||||
##############################################################################
|
||||
##
|
||||
## Gradle start up script for UN*X
|
||||
##
|
||||
##############################################################################
|
||||
|
||||
# Attempt to set APP_HOME
|
||||
# Resolve links: $0 may be a link
|
||||
PRG="$0"
|
||||
# Need this for relative symlinks.
|
||||
while [ -h "$PRG" ] ; do
|
||||
ls=`ls -ld "$PRG"`
|
||||
link=`expr "$ls" : '.*-> \(.*\)$'`
|
||||
if expr "$link" : '/.*' > /dev/null; then
|
||||
PRG="$link"
|
||||
else
|
||||
PRG=`dirname "$PRG"`"/$link"
|
||||
fi
|
||||
done
|
||||
SAVED="`pwd`"
|
||||
cd "`dirname \"$PRG\"`/" >/dev/null
|
||||
APP_HOME="`pwd -P`"
|
||||
cd "$SAVED" >/dev/null
|
||||
|
||||
APP_NAME="Gradle"
|
||||
APP_BASE_NAME=`basename "$0"`
|
||||
|
||||
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||
DEFAULT_JVM_OPTS=""
|
||||
|
||||
# Use the maximum available, or set MAX_FD != -1 to use that value.
|
||||
MAX_FD="maximum"
|
||||
|
||||
warn () {
|
||||
echo "$*"
|
||||
}
|
||||
|
||||
die () {
|
||||
echo
|
||||
echo "$*"
|
||||
echo
|
||||
exit 1
|
||||
}
|
||||
|
||||
# OS specific support (must be 'true' or 'false').
|
||||
cygwin=false
|
||||
msys=false
|
||||
darwin=false
|
||||
nonstop=false
|
||||
case "`uname`" in
|
||||
CYGWIN* )
|
||||
cygwin=true
|
||||
;;
|
||||
Darwin* )
|
||||
darwin=true
|
||||
;;
|
||||
MINGW* )
|
||||
msys=true
|
||||
;;
|
||||
NONSTOP* )
|
||||
nonstop=true
|
||||
;;
|
||||
esac
|
||||
|
||||
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
|
||||
|
||||
# Determine the Java command to use to start the JVM.
|
||||
if [ -n "$JAVA_HOME" ] ; then
|
||||
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
|
||||
# IBM's JDK on AIX uses strange locations for the executables
|
||||
JAVACMD="$JAVA_HOME/jre/sh/java"
|
||||
else
|
||||
JAVACMD="$JAVA_HOME/bin/java"
|
||||
fi
|
||||
if [ ! -x "$JAVACMD" ] ; then
|
||||
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
|
||||
|
||||
Please set the JAVA_HOME variable in your environment to match the
|
||||
location of your Java installation."
|
||||
fi
|
||||
else
|
||||
JAVACMD="java"
|
||||
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
||||
|
||||
Please set the JAVA_HOME variable in your environment to match the
|
||||
location of your Java installation."
|
||||
fi
|
||||
|
||||
# Increase the maximum file descriptors if we can.
|
||||
if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
|
||||
MAX_FD_LIMIT=`ulimit -H -n`
|
||||
if [ $? -eq 0 ] ; then
|
||||
if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
|
||||
MAX_FD="$MAX_FD_LIMIT"
|
||||
fi
|
||||
ulimit -n $MAX_FD
|
||||
if [ $? -ne 0 ] ; then
|
||||
warn "Could not set maximum file descriptor limit: $MAX_FD"
|
||||
fi
|
||||
else
|
||||
warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
|
||||
fi
|
||||
fi
|
||||
|
||||
# For Darwin, add options to specify how the application appears in the dock
|
||||
if $darwin; then
|
||||
GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
|
||||
fi
|
||||
|
||||
# For Cygwin, switch paths to Windows format before running java
|
||||
if $cygwin ; then
|
||||
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
|
||||
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
|
||||
JAVACMD=`cygpath --unix "$JAVACMD"`
|
||||
|
||||
# We build the pattern for arguments to be converted via cygpath
|
||||
ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
|
||||
SEP=""
|
||||
for dir in $ROOTDIRSRAW ; do
|
||||
ROOTDIRS="$ROOTDIRS$SEP$dir"
|
||||
SEP="|"
|
||||
done
|
||||
OURCYGPATTERN="(^($ROOTDIRS))"
|
||||
# Add a user-defined pattern to the cygpath arguments
|
||||
if [ "$GRADLE_CYGPATTERN" != "" ] ; then
|
||||
OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
|
||||
fi
|
||||
# Now convert the arguments - kludge to limit ourselves to /bin/sh
|
||||
i=0
|
||||
for arg in "$@" ; do
|
||||
CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
|
||||
CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
|
||||
|
||||
if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
|
||||
eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
|
||||
else
|
||||
eval `echo args$i`="\"$arg\""
|
||||
fi
|
||||
i=$((i+1))
|
||||
done
|
||||
case $i in
|
||||
(0) set -- ;;
|
||||
(1) set -- "$args0" ;;
|
||||
(2) set -- "$args0" "$args1" ;;
|
||||
(3) set -- "$args0" "$args1" "$args2" ;;
|
||||
(4) set -- "$args0" "$args1" "$args2" "$args3" ;;
|
||||
(5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
|
||||
(6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
|
||||
(7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
|
||||
(8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
|
||||
(9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
|
||||
esac
|
||||
fi
|
||||
|
||||
# Escape application args
|
||||
save () {
|
||||
for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
|
||||
echo " "
|
||||
}
|
||||
APP_ARGS=$(save "$@")
|
||||
|
||||
# Collect all arguments for the java command, following the shell quoting and substitution rules
|
||||
eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
|
||||
|
||||
# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
|
||||
if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
|
||||
cd "$(dirname "$0")"
|
||||
fi
|
||||
|
||||
exec "$JAVACMD" "$@"
|
||||
@@ -1,84 +0,0 @@
|
||||
@if "%DEBUG%" == "" @echo off
|
||||
@rem ##########################################################################
|
||||
@rem
|
||||
@rem Gradle startup script for Windows
|
||||
@rem
|
||||
@rem ##########################################################################
|
||||
|
||||
@rem Set local scope for the variables with windows NT shell
|
||||
if "%OS%"=="Windows_NT" setlocal
|
||||
|
||||
set DIRNAME=%~dp0
|
||||
if "%DIRNAME%" == "" set DIRNAME=.
|
||||
set APP_BASE_NAME=%~n0
|
||||
set APP_HOME=%DIRNAME%
|
||||
|
||||
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||
set DEFAULT_JVM_OPTS=
|
||||
|
||||
@rem Find java.exe
|
||||
if defined JAVA_HOME goto findJavaFromJavaHome
|
||||
|
||||
set JAVA_EXE=java.exe
|
||||
%JAVA_EXE% -version >NUL 2>&1
|
||||
if "%ERRORLEVEL%" == "0" goto init
|
||||
|
||||
echo.
|
||||
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
||||
echo.
|
||||
echo Please set the JAVA_HOME variable in your environment to match the
|
||||
echo location of your Java installation.
|
||||
|
||||
goto fail
|
||||
|
||||
:findJavaFromJavaHome
|
||||
set JAVA_HOME=%JAVA_HOME:"=%
|
||||
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
|
||||
|
||||
if exist "%JAVA_EXE%" goto init
|
||||
|
||||
echo.
|
||||
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
|
||||
echo.
|
||||
echo Please set the JAVA_HOME variable in your environment to match the
|
||||
echo location of your Java installation.
|
||||
|
||||
goto fail
|
||||
|
||||
:init
|
||||
@rem Get command-line arguments, handling Windows variants
|
||||
|
||||
if not "%OS%" == "Windows_NT" goto win9xME_args
|
||||
|
||||
:win9xME_args
|
||||
@rem Slurp the command line arguments.
|
||||
set CMD_LINE_ARGS=
|
||||
set _SKIP=2
|
||||
|
||||
:win9xME_args_slurp
|
||||
if "x%~1" == "x" goto execute
|
||||
|
||||
set CMD_LINE_ARGS=%*
|
||||
|
||||
:execute
|
||||
@rem Setup the command line
|
||||
|
||||
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
|
||||
|
||||
@rem Execute Gradle
|
||||
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
|
||||
|
||||
:end
|
||||
@rem End local scope for the variables with windows NT shell
|
||||
if "%ERRORLEVEL%"=="0" goto mainEnd
|
||||
|
||||
:fail
|
||||
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
|
||||
rem the _cmd.exe /c_ return code!
|
||||
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
|
||||
exit /b 1
|
||||
|
||||
:mainEnd
|
||||
if "%OS%"=="Windows_NT" endlocal
|
||||
|
||||
:omega
|
||||
@@ -1,56 +0,0 @@
|
||||
# Copyright (c) 2013 Google, Inc.
|
||||
#
|
||||
# This software is provided 'as-is', without any express or implied
|
||||
# warranty. In no event will the authors be held liable for any damages
|
||||
# arising from the use of this software.
|
||||
# Permission is granted to anyone to use this software for any purpose,
|
||||
# including commercial applications, and to alter it and redistribute it
|
||||
# freely, subject to the following restrictions:
|
||||
# 1. The origin of this software must not be misrepresented; you must not
|
||||
# claim that you wrote the original software. If you use this software
|
||||
# in a product, an acknowledgment in the product documentation would be
|
||||
# appreciated but is not required.
|
||||
# 2. Altered source versions must be plainly marked as such, and must not be
|
||||
# misrepresented as being the original software.
|
||||
# 3. This notice may not be removed or altered from any source distribution.
|
||||
|
||||
LOCAL_PATH := $(call my-dir)
|
||||
FLATBUFFERS_ROOT_DIR := $(LOCAL_PATH)/../../..
|
||||
|
||||
# FlatBuffers test
|
||||
include $(CLEAR_VARS)
|
||||
|
||||
# Include the FlatBuffer utility function to generate header files from schemas.
|
||||
include $(FLATBUFFERS_ROOT_DIR)/android/jni/include.mk
|
||||
|
||||
LOCAL_MODULE := FlatBufferSample
|
||||
|
||||
# Set up some useful variables to identify schema and output directories and
|
||||
# schema files.
|
||||
ANDROID_SAMPLE_GENERATED_OUTPUT_DIR := $(LOCAL_PATH)/gen/include
|
||||
ANDROID_SAMPLE_SCHEMA_DIR := $(LOCAL_PATH)/schemas
|
||||
ANDROID_SAMPLE_SCHEMA_FILES := $(ANDROID_SAMPLE_SCHEMA_DIR)/animal.fbs
|
||||
|
||||
LOCAL_C_INCLUDES := $(ANDROID_SAMPLE_GENERATED_OUTPUT_DIR)
|
||||
|
||||
$(info $(LOCAL_C_INCLUDES))
|
||||
|
||||
LOCAL_SRC_FILES := main.cpp
|
||||
|
||||
LOCAL_CPPFLAGS := -std=c++11 -fexceptions -Wall -Wno-literal-suffix
|
||||
LOCAL_LDLIBS := -llog -landroid -latomic
|
||||
LOCAL_ARM_MODE := arm
|
||||
LOCAL_STATIC_LIBRARIES := android_native_app_glue flatbuffers
|
||||
|
||||
ifeq (,$(ANDROID_SAMPLE_RUN_ONCE))
|
||||
ANDROID_SAMPLE_RUN_ONCE := 1
|
||||
$(call flatbuffers_header_build_rules,$(ANDROID_SAMPLE_SCHEMA_FILES),$(ANDROID_SAMPLE_SCHEMA_DIR),$(ANDROID_SAMPLE_GENERATED_OUTPUT_DIR),,$(LOCAL_SRC_FILES))
|
||||
endif
|
||||
|
||||
include $(BUILD_SHARED_LIBRARY)
|
||||
|
||||
# Path to Flatbuffers root directory.
|
||||
$(call import-add-path,$(FLATBUFFERS_ROOT_DIR)/..)
|
||||
|
||||
$(call import-module,flatbuffers/android/jni)
|
||||
$(call import-module,android/native_app_glue)
|
||||
@@ -1,20 +0,0 @@
|
||||
# Copyright (c) 2014 Google, Inc.
|
||||
#
|
||||
# This software is provided 'as-is', without any express or implied
|
||||
# warranty. In no event will the authors be held liable for any damages
|
||||
# arising from the use of this software.
|
||||
# Permission is granted to anyone to use this software for any purpose,
|
||||
# including commercial applications, and to alter it and redistribute it
|
||||
# freely, subject to the following restrictions:
|
||||
# 1. The origin of this software must not be misrepresented; you must not
|
||||
# claim that you wrote the original software. If you use this software
|
||||
# in a product, an acknowledgment in the product documentation would be
|
||||
# appreciated but is not required.
|
||||
# 2. Altered source versions must be plainly marked as such, and must not be
|
||||
# misrepresented as being the original software.
|
||||
# 3. This notice may not be removed or altered from any source distribution.
|
||||
APP_PLATFORM := android-9
|
||||
APP_PROJECT_PATH := $(call my-dir)/..
|
||||
APP_STL ?= stlport_static
|
||||
APP_ABI := armeabi-v7a
|
||||
APP_CPPFLAGS += -std=c++11
|
||||
@@ -1,43 +0,0 @@
|
||||
// Copyright 2015 Google Inc. All rights reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include <android/log.h>
|
||||
|
||||
#include "android_native_app_glue.h"
|
||||
#include "animal_generated.h" // Includes "flatbuffers/flatbuffers.h".
|
||||
|
||||
void android_main(android_app *app) {
|
||||
app_dummy();
|
||||
|
||||
flatbuffers::FlatBufferBuilder builder;
|
||||
auto name = builder.CreateString("Dog");
|
||||
auto sound = builder.CreateString("Bark");
|
||||
auto animal_buffer = sample::CreateAnimal(builder, name, sound);
|
||||
builder.Finish(animal_buffer);
|
||||
|
||||
// We now have a FlatBuffer that can be stored on disk or sent over a network.
|
||||
|
||||
// ...Code to store on disk or send over a network goes here...
|
||||
|
||||
// Instead, we're going to access it immediately, as if we just recieved this.
|
||||
|
||||
auto animal = sample::GetAnimal(builder.GetBufferPointer());
|
||||
|
||||
assert(animal->name()->str() == "Dog");
|
||||
assert(animal->sound()->str() == "Bark");
|
||||
(void)animal; // To silence "Unused Variable" warnings.
|
||||
|
||||
__android_log_print(ANDROID_LOG_INFO, "FlatBufferSample",
|
||||
"FlatBuffer successfully created and verified.");
|
||||
}
|
||||
@@ -1,22 +0,0 @@
|
||||
// Copyright 2015 Google Inc. All rights reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
namespace sample;
|
||||
|
||||
table Animal {
|
||||
name:string;
|
||||
sound:string;
|
||||
}
|
||||
|
||||
root_type Animal;
|
||||
@@ -1,20 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- Copyright (c) 2015 Google, Inc.
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
arising from the use of this software.
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it
|
||||
freely, subject to the following restrictions:
|
||||
1. The origin of this software must not be misrepresented; you must not
|
||||
claim that you wrote the original software. If you use this software
|
||||
in a product, an acknowledgment in the product documentation would be
|
||||
appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be
|
||||
misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
-->
|
||||
<resources>
|
||||
<string name="app_name">FlatBufferSample</string>
|
||||
</resources>
|
||||
@@ -1,35 +0,0 @@
|
||||
#!/bin/bash
|
||||
#
|
||||
# Copyright 2015 Google Inc. All rights reserved.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
# Note: This script requires the Android NDK and Android SDK to be installed.
|
||||
# It also requires an Android device to be connected for installing and
|
||||
# running the applicaton.
|
||||
|
||||
sampledir=$(readlink -fn `dirname $0`)
|
||||
currentdir=$(readlink -fn `pwd`)
|
||||
|
||||
if [[ "$sampledir" != "$currentdir" ]]; then
|
||||
echo Error: This script must be run from inside the $sampledir directory.
|
||||
echo You executed it from the $currentdir directory.
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Execute `build_apk.sh` to build and run the android app.
|
||||
cd android
|
||||
./gradlew build
|
||||
|
||||
|
||||
|
||||
+8
-11
@@ -1,4 +1,5 @@
|
||||
#!/bin/bash
|
||||
set -euo
|
||||
#
|
||||
# Copyright 2018 Dan Field. All rights reserved.
|
||||
#
|
||||
@@ -27,14 +28,12 @@ if [[ "$sampledir" != "$currentdir" ]]; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
cd ../dart/example
|
||||
|
||||
# Run `flatc`. Note: This requires you to compile using `cmake` from the
|
||||
# root `/flatbuffers` directory.
|
||||
if [ -e ../../flatc ]; then
|
||||
../../flatc --dart ../../samples/monster.fbs
|
||||
elif [ -e ../../Debug/flatc ]; then
|
||||
../../Debug/flatc --dart ../../samples/monster.fbs
|
||||
if [ -e ../flatc ]; then
|
||||
../flatc --dart -o ../dart/example/ monster.fbs
|
||||
elif [ -e ../Debug/flatc ]; then
|
||||
../Debug/flatc --dart -o ../dart/example/ monster.fbs
|
||||
else
|
||||
echo 'flatc' could not be found. Make sure to build FlatBuffers from the \
|
||||
$rootdir directory.
|
||||
@@ -44,9 +43,7 @@ fi
|
||||
echo Running the Dart sample.
|
||||
|
||||
# Execute the sample.
|
||||
dart example.dart
|
||||
dart ../dart/example/example.dart
|
||||
|
||||
# Cleanup temporary files.
|
||||
git checkout monster_my_game.sample_generated.dart
|
||||
|
||||
cd ../../samples
|
||||
# Copy the source schema so it is distributed when published to pub.dev
|
||||
cp monster.fbs ../dart/example/
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
module github.com/google/flatbuffers/samples
|
||||
|
||||
go 1.20
|
||||
|
||||
replace github.com/google/flatbuffers/go => ./go_gen
|
||||
|
||||
require github.com/google/flatbuffers/go v0.0.0-00010101000000-000000000000
|
||||
+7
-12
@@ -41,23 +41,18 @@ fi
|
||||
|
||||
echo Compiling and running the Go sample.
|
||||
|
||||
# Go requires a particular layout of files in order to link the necessary
|
||||
# packages. Copy these files to the respective directores to compile the
|
||||
# sample.
|
||||
mkdir -p ${sampledir}/go_gen/src/MyGame/Sample
|
||||
mkdir -p ${sampledir}/go_gen/src/github.com/google/flatbuffers/go
|
||||
cp MyGame/Sample/*.go ${sampledir}/go_gen/src/MyGame/Sample/
|
||||
cp ${sampledir}/../go/* ${sampledir}/go_gen/src/github.com/google/flatbuffers/go
|
||||
|
||||
# Export the `GOPATH`, so that `go` will know which directories to search for
|
||||
# the libraries.
|
||||
export GOPATH=${sampledir}/go_gen/
|
||||
# Workaround for https://github.com/google/flatbuffers/issues/7780:
|
||||
# go mod replace requires a go.mod file in the target directory,
|
||||
# but there currently isn't one in the ../go directory.
|
||||
# So we copy the ../go directory to go_gen and manually create go_gen/go.mod
|
||||
mkdir -p ${sampledir}/go_gen
|
||||
cp ${sampledir}/../go/* ${sampledir}/go_gen
|
||||
( cd ${sampledir}/go_gen && go mod init github.com/google/flatbuffers/go )
|
||||
|
||||
# Compile and execute the sample.
|
||||
go build -o go_sample sample_binary.go
|
||||
./go_sample
|
||||
|
||||
# Clean up the temporary files.
|
||||
rm -rf MyGame/
|
||||
rm -rf ${sampledir}/go_gen/
|
||||
rm go_sample
|
||||
|
||||
+1
-1
@@ -56,5 +56,5 @@ echo Running test
|
||||
kotlin -cp ${sampledir}/kotlin/kotlin_sample.jar SampleBinary
|
||||
|
||||
# Cleanup temporary files.
|
||||
# rm -rf MyGame/
|
||||
rm -rf MyGame/
|
||||
# rm -rf ${sampledir}/kotlin
|
||||
|
||||
BIN
Binary file not shown.
+305
-259
@@ -6,15 +6,24 @@
|
||||
|
||||
#include "flatbuffers/flatbuffers.h"
|
||||
|
||||
// Ensure the included flatbuffers.h is the same version as when this file was
|
||||
// generated, otherwise it may not be compatible.
|
||||
static_assert(FLATBUFFERS_VERSION_MAJOR == 24 &&
|
||||
FLATBUFFERS_VERSION_MINOR == 3 &&
|
||||
FLATBUFFERS_VERSION_REVISION == 25,
|
||||
"Non-compatible flatbuffers version included");
|
||||
|
||||
namespace MyGame {
|
||||
namespace Sample {
|
||||
|
||||
struct Vec3;
|
||||
|
||||
struct Monster;
|
||||
struct MonsterBuilder;
|
||||
struct MonsterT;
|
||||
|
||||
struct Weapon;
|
||||
struct WeaponBuilder;
|
||||
struct WeaponT;
|
||||
|
||||
bool operator==(const Vec3 &lhs, const Vec3 &rhs);
|
||||
@@ -24,13 +33,13 @@ bool operator!=(const MonsterT &lhs, const MonsterT &rhs);
|
||||
bool operator==(const WeaponT &lhs, const WeaponT &rhs);
|
||||
bool operator!=(const WeaponT &lhs, const WeaponT &rhs);
|
||||
|
||||
inline const flatbuffers::TypeTable *Vec3TypeTable();
|
||||
inline const ::flatbuffers::TypeTable *Vec3TypeTable();
|
||||
|
||||
inline const flatbuffers::TypeTable *MonsterTypeTable();
|
||||
inline const ::flatbuffers::TypeTable *MonsterTypeTable();
|
||||
|
||||
inline const flatbuffers::TypeTable *WeaponTypeTable();
|
||||
inline const ::flatbuffers::TypeTable *WeaponTypeTable();
|
||||
|
||||
enum Color {
|
||||
enum Color : int8_t {
|
||||
Color_Red = 0,
|
||||
Color_Green = 1,
|
||||
Color_Blue = 2,
|
||||
@@ -58,12 +67,12 @@ inline const char * const *EnumNamesColor() {
|
||||
}
|
||||
|
||||
inline const char *EnumNameColor(Color e) {
|
||||
if (e < Color_Red || e > Color_Blue) return "";
|
||||
if (::flatbuffers::IsOutRange(e, Color_Red, Color_Blue)) return "";
|
||||
const size_t index = static_cast<size_t>(e);
|
||||
return EnumNamesColor()[index];
|
||||
}
|
||||
|
||||
enum Equipment {
|
||||
enum Equipment : uint8_t {
|
||||
Equipment_NONE = 0,
|
||||
Equipment_Weapon = 1,
|
||||
Equipment_MIN = Equipment_NONE,
|
||||
@@ -88,7 +97,7 @@ inline const char * const *EnumNamesEquipment() {
|
||||
}
|
||||
|
||||
inline const char *EnumNameEquipment(Equipment e) {
|
||||
if (e < Equipment_NONE || e > Equipment_Weapon) return "";
|
||||
if (::flatbuffers::IsOutRange(e, Equipment_NONE, Equipment_Weapon)) return "";
|
||||
const size_t index = static_cast<size_t>(e);
|
||||
return EnumNamesEquipment()[index];
|
||||
}
|
||||
@@ -101,6 +110,14 @@ template<> struct EquipmentTraits<MyGame::Sample::Weapon> {
|
||||
static const Equipment enum_value = Equipment_Weapon;
|
||||
};
|
||||
|
||||
template<typename T> struct EquipmentUnionTraits {
|
||||
static const Equipment enum_value = Equipment_NONE;
|
||||
};
|
||||
|
||||
template<> struct EquipmentUnionTraits<MyGame::Sample::WeaponT> {
|
||||
static const Equipment enum_value = Equipment_Weapon;
|
||||
};
|
||||
|
||||
struct EquipmentUnion {
|
||||
Equipment type;
|
||||
void *value;
|
||||
@@ -109,8 +126,8 @@ struct EquipmentUnion {
|
||||
EquipmentUnion(EquipmentUnion&& u) FLATBUFFERS_NOEXCEPT :
|
||||
type(Equipment_NONE), value(nullptr)
|
||||
{ std::swap(type, u.type); std::swap(value, u.value); }
|
||||
EquipmentUnion(const EquipmentUnion &) FLATBUFFERS_NOEXCEPT;
|
||||
EquipmentUnion &operator=(const EquipmentUnion &u) FLATBUFFERS_NOEXCEPT
|
||||
EquipmentUnion(const EquipmentUnion &);
|
||||
EquipmentUnion &operator=(const EquipmentUnion &u)
|
||||
{ EquipmentUnion t(u); std::swap(type, t.type); std::swap(value, t.value); return *this; }
|
||||
EquipmentUnion &operator=(EquipmentUnion &&u) FLATBUFFERS_NOEXCEPT
|
||||
{ std::swap(type, u.type); std::swap(value, u.value); return *this; }
|
||||
@@ -118,20 +135,18 @@ struct EquipmentUnion {
|
||||
|
||||
void Reset();
|
||||
|
||||
#ifndef FLATBUFFERS_CPP98_STL
|
||||
template <typename T>
|
||||
void Set(T&& val) {
|
||||
using RT = typename std::remove_reference<T>::type;
|
||||
typedef typename std::remove_reference<T>::type RT;
|
||||
Reset();
|
||||
type = EquipmentTraits<typename RT::TableType>::enum_value;
|
||||
type = EquipmentUnionTraits<RT>::enum_value;
|
||||
if (type != Equipment_NONE) {
|
||||
value = new RT(std::forward<T>(val));
|
||||
}
|
||||
}
|
||||
#endif // FLATBUFFERS_CPP98_STL
|
||||
|
||||
static void *UnPack(const void *obj, Equipment type, const flatbuffers::resolver_function_t *resolver);
|
||||
flatbuffers::Offset<void> Pack(flatbuffers::FlatBufferBuilder &_fbb, const flatbuffers::rehasher_function_t *_rehasher = nullptr) const;
|
||||
static void *UnPack(const void *obj, Equipment type, const ::flatbuffers::resolver_function_t *resolver);
|
||||
::flatbuffers::Offset<void> Pack(::flatbuffers::FlatBufferBuilder &_fbb, const ::flatbuffers::rehasher_function_t *_rehasher = nullptr) const;
|
||||
|
||||
MyGame::Sample::WeaponT *AsWeapon() {
|
||||
return type == Equipment_Weapon ?
|
||||
@@ -164,8 +179,8 @@ inline bool operator!=(const EquipmentUnion &lhs, const EquipmentUnion &rhs) {
|
||||
return !(lhs == rhs);
|
||||
}
|
||||
|
||||
bool VerifyEquipment(flatbuffers::Verifier &verifier, const void *obj, Equipment type);
|
||||
bool VerifyEquipmentVector(flatbuffers::Verifier &verifier, const flatbuffers::Vector<flatbuffers::Offset<void>> *values, const flatbuffers::Vector<uint8_t> *types);
|
||||
bool VerifyEquipment(::flatbuffers::Verifier &verifier, const void *obj, Equipment type);
|
||||
bool VerifyEquipmentVector(::flatbuffers::Verifier &verifier, const ::flatbuffers::Vector<::flatbuffers::Offset<void>> *values, const ::flatbuffers::Vector<uint8_t> *types);
|
||||
|
||||
FLATBUFFERS_MANUALLY_ALIGNED_STRUCT(4) Vec3 FLATBUFFERS_FINAL_CLASS {
|
||||
private:
|
||||
@@ -174,34 +189,36 @@ FLATBUFFERS_MANUALLY_ALIGNED_STRUCT(4) Vec3 FLATBUFFERS_FINAL_CLASS {
|
||||
float z_;
|
||||
|
||||
public:
|
||||
static const flatbuffers::TypeTable *MiniReflectTypeTable() {
|
||||
static const ::flatbuffers::TypeTable *MiniReflectTypeTable() {
|
||||
return Vec3TypeTable();
|
||||
}
|
||||
Vec3() {
|
||||
memset(static_cast<void *>(this), 0, sizeof(Vec3));
|
||||
Vec3()
|
||||
: x_(0),
|
||||
y_(0),
|
||||
z_(0) {
|
||||
}
|
||||
Vec3(float _x, float _y, float _z)
|
||||
: x_(flatbuffers::EndianScalar(_x)),
|
||||
y_(flatbuffers::EndianScalar(_y)),
|
||||
z_(flatbuffers::EndianScalar(_z)) {
|
||||
: x_(::flatbuffers::EndianScalar(_x)),
|
||||
y_(::flatbuffers::EndianScalar(_y)),
|
||||
z_(::flatbuffers::EndianScalar(_z)) {
|
||||
}
|
||||
float x() const {
|
||||
return flatbuffers::EndianScalar(x_);
|
||||
return ::flatbuffers::EndianScalar(x_);
|
||||
}
|
||||
void mutate_x(float _x) {
|
||||
flatbuffers::WriteScalar(&x_, _x);
|
||||
::flatbuffers::WriteScalar(&x_, _x);
|
||||
}
|
||||
float y() const {
|
||||
return flatbuffers::EndianScalar(y_);
|
||||
return ::flatbuffers::EndianScalar(y_);
|
||||
}
|
||||
void mutate_y(float _y) {
|
||||
flatbuffers::WriteScalar(&y_, _y);
|
||||
::flatbuffers::WriteScalar(&y_, _y);
|
||||
}
|
||||
float z() const {
|
||||
return flatbuffers::EndianScalar(z_);
|
||||
return ::flatbuffers::EndianScalar(z_);
|
||||
}
|
||||
void mutate_z(float _z) {
|
||||
flatbuffers::WriteScalar(&z_, _z);
|
||||
::flatbuffers::WriteScalar(&z_, _z);
|
||||
}
|
||||
};
|
||||
FLATBUFFERS_STRUCT_END(Vec3, 12);
|
||||
@@ -218,45 +235,27 @@ inline bool operator!=(const Vec3 &lhs, const Vec3 &rhs) {
|
||||
}
|
||||
|
||||
|
||||
struct MonsterT : public flatbuffers::NativeTable {
|
||||
struct MonsterT : public ::flatbuffers::NativeTable {
|
||||
typedef Monster TableType;
|
||||
flatbuffers::unique_ptr<MyGame::Sample::Vec3> pos;
|
||||
int16_t mana;
|
||||
int16_t hp;
|
||||
std::string name;
|
||||
std::vector<uint8_t> inventory;
|
||||
MyGame::Sample::Color color;
|
||||
std::vector<flatbuffers::unique_ptr<MyGame::Sample::WeaponT>> weapons;
|
||||
EquipmentUnion equipped;
|
||||
std::vector<MyGame::Sample::Vec3> path;
|
||||
MonsterT()
|
||||
: mana(150),
|
||||
hp(100),
|
||||
color(MyGame::Sample::Color_Blue) {
|
||||
}
|
||||
std::unique_ptr<MyGame::Sample::Vec3> pos{};
|
||||
int16_t mana = 150;
|
||||
int16_t hp = 100;
|
||||
std::string name{};
|
||||
std::vector<uint8_t> inventory{};
|
||||
MyGame::Sample::Color color = MyGame::Sample::Color_Blue;
|
||||
std::vector<std::unique_ptr<MyGame::Sample::WeaponT>> weapons{};
|
||||
MyGame::Sample::EquipmentUnion equipped{};
|
||||
std::vector<MyGame::Sample::Vec3> path{};
|
||||
MonsterT() = default;
|
||||
MonsterT(const MonsterT &o);
|
||||
MonsterT(MonsterT&&) FLATBUFFERS_NOEXCEPT = default;
|
||||
MonsterT &operator=(MonsterT o) FLATBUFFERS_NOEXCEPT;
|
||||
};
|
||||
|
||||
inline bool operator==(const MonsterT &lhs, const MonsterT &rhs) {
|
||||
return
|
||||
(lhs.pos == rhs.pos) &&
|
||||
(lhs.mana == rhs.mana) &&
|
||||
(lhs.hp == rhs.hp) &&
|
||||
(lhs.name == rhs.name) &&
|
||||
(lhs.inventory == rhs.inventory) &&
|
||||
(lhs.color == rhs.color) &&
|
||||
(lhs.weapons == rhs.weapons) &&
|
||||
(lhs.equipped == rhs.equipped) &&
|
||||
(lhs.path == rhs.path);
|
||||
}
|
||||
|
||||
inline bool operator!=(const MonsterT &lhs, const MonsterT &rhs) {
|
||||
return !(lhs == rhs);
|
||||
}
|
||||
|
||||
|
||||
struct Monster FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table {
|
||||
struct Monster FLATBUFFERS_FINAL_CLASS : private ::flatbuffers::Table {
|
||||
typedef MonsterT NativeTableType;
|
||||
static const flatbuffers::TypeTable *MiniReflectTypeTable() {
|
||||
typedef MonsterBuilder Builder;
|
||||
static const ::flatbuffers::TypeTable *MiniReflectTypeTable() {
|
||||
return MonsterTypeTable();
|
||||
}
|
||||
enum FlatBuffersVTableOffset FLATBUFFERS_VTABLE_UNDERLYING_TYPE {
|
||||
@@ -280,45 +279,42 @@ struct Monster FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table {
|
||||
int16_t mana() const {
|
||||
return GetField<int16_t>(VT_MANA, 150);
|
||||
}
|
||||
bool mutate_mana(int16_t _mana) {
|
||||
bool mutate_mana(int16_t _mana = 150) {
|
||||
return SetField<int16_t>(VT_MANA, _mana, 150);
|
||||
}
|
||||
int16_t hp() const {
|
||||
return GetField<int16_t>(VT_HP, 100);
|
||||
}
|
||||
bool mutate_hp(int16_t _hp) {
|
||||
bool mutate_hp(int16_t _hp = 100) {
|
||||
return SetField<int16_t>(VT_HP, _hp, 100);
|
||||
}
|
||||
const flatbuffers::String *name() const {
|
||||
return GetPointer<const flatbuffers::String *>(VT_NAME);
|
||||
const ::flatbuffers::String *name() const {
|
||||
return GetPointer<const ::flatbuffers::String *>(VT_NAME);
|
||||
}
|
||||
flatbuffers::String *mutable_name() {
|
||||
return GetPointer<flatbuffers::String *>(VT_NAME);
|
||||
::flatbuffers::String *mutable_name() {
|
||||
return GetPointer<::flatbuffers::String *>(VT_NAME);
|
||||
}
|
||||
const flatbuffers::Vector<uint8_t> *inventory() const {
|
||||
return GetPointer<const flatbuffers::Vector<uint8_t> *>(VT_INVENTORY);
|
||||
const ::flatbuffers::Vector<uint8_t> *inventory() const {
|
||||
return GetPointer<const ::flatbuffers::Vector<uint8_t> *>(VT_INVENTORY);
|
||||
}
|
||||
flatbuffers::Vector<uint8_t> *mutable_inventory() {
|
||||
return GetPointer<flatbuffers::Vector<uint8_t> *>(VT_INVENTORY);
|
||||
::flatbuffers::Vector<uint8_t> *mutable_inventory() {
|
||||
return GetPointer<::flatbuffers::Vector<uint8_t> *>(VT_INVENTORY);
|
||||
}
|
||||
MyGame::Sample::Color color() const {
|
||||
return static_cast<MyGame::Sample::Color>(GetField<int8_t>(VT_COLOR, 2));
|
||||
}
|
||||
bool mutate_color(MyGame::Sample::Color _color) {
|
||||
bool mutate_color(MyGame::Sample::Color _color = static_cast<MyGame::Sample::Color>(2)) {
|
||||
return SetField<int8_t>(VT_COLOR, static_cast<int8_t>(_color), 2);
|
||||
}
|
||||
const flatbuffers::Vector<flatbuffers::Offset<MyGame::Sample::Weapon>> *weapons() const {
|
||||
return GetPointer<const flatbuffers::Vector<flatbuffers::Offset<MyGame::Sample::Weapon>> *>(VT_WEAPONS);
|
||||
const ::flatbuffers::Vector<::flatbuffers::Offset<MyGame::Sample::Weapon>> *weapons() const {
|
||||
return GetPointer<const ::flatbuffers::Vector<::flatbuffers::Offset<MyGame::Sample::Weapon>> *>(VT_WEAPONS);
|
||||
}
|
||||
flatbuffers::Vector<flatbuffers::Offset<MyGame::Sample::Weapon>> *mutable_weapons() {
|
||||
return GetPointer<flatbuffers::Vector<flatbuffers::Offset<MyGame::Sample::Weapon>> *>(VT_WEAPONS);
|
||||
::flatbuffers::Vector<::flatbuffers::Offset<MyGame::Sample::Weapon>> *mutable_weapons() {
|
||||
return GetPointer<::flatbuffers::Vector<::flatbuffers::Offset<MyGame::Sample::Weapon>> *>(VT_WEAPONS);
|
||||
}
|
||||
MyGame::Sample::Equipment equipped_type() const {
|
||||
return static_cast<MyGame::Sample::Equipment>(GetField<uint8_t>(VT_EQUIPPED_TYPE, 0));
|
||||
}
|
||||
bool mutate_equipped_type(MyGame::Sample::Equipment _equipped_type) {
|
||||
return SetField<uint8_t>(VT_EQUIPPED_TYPE, static_cast<uint8_t>(_equipped_type), 0);
|
||||
}
|
||||
const void *equipped() const {
|
||||
return GetPointer<const void *>(VT_EQUIPPED);
|
||||
}
|
||||
@@ -329,35 +325,35 @@ struct Monster FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table {
|
||||
void *mutable_equipped() {
|
||||
return GetPointer<void *>(VT_EQUIPPED);
|
||||
}
|
||||
const flatbuffers::Vector<const MyGame::Sample::Vec3 *> *path() const {
|
||||
return GetPointer<const flatbuffers::Vector<const MyGame::Sample::Vec3 *> *>(VT_PATH);
|
||||
const ::flatbuffers::Vector<const MyGame::Sample::Vec3 *> *path() const {
|
||||
return GetPointer<const ::flatbuffers::Vector<const MyGame::Sample::Vec3 *> *>(VT_PATH);
|
||||
}
|
||||
flatbuffers::Vector<const MyGame::Sample::Vec3 *> *mutable_path() {
|
||||
return GetPointer<flatbuffers::Vector<const MyGame::Sample::Vec3 *> *>(VT_PATH);
|
||||
::flatbuffers::Vector<const MyGame::Sample::Vec3 *> *mutable_path() {
|
||||
return GetPointer<::flatbuffers::Vector<const MyGame::Sample::Vec3 *> *>(VT_PATH);
|
||||
}
|
||||
bool Verify(flatbuffers::Verifier &verifier) const {
|
||||
bool Verify(::flatbuffers::Verifier &verifier) const {
|
||||
return VerifyTableStart(verifier) &&
|
||||
VerifyField<MyGame::Sample::Vec3>(verifier, VT_POS) &&
|
||||
VerifyField<int16_t>(verifier, VT_MANA) &&
|
||||
VerifyField<int16_t>(verifier, VT_HP) &&
|
||||
VerifyField<MyGame::Sample::Vec3>(verifier, VT_POS, 4) &&
|
||||
VerifyField<int16_t>(verifier, VT_MANA, 2) &&
|
||||
VerifyField<int16_t>(verifier, VT_HP, 2) &&
|
||||
VerifyOffset(verifier, VT_NAME) &&
|
||||
verifier.VerifyString(name()) &&
|
||||
VerifyOffset(verifier, VT_INVENTORY) &&
|
||||
verifier.VerifyVector(inventory()) &&
|
||||
VerifyField<int8_t>(verifier, VT_COLOR) &&
|
||||
VerifyField<int8_t>(verifier, VT_COLOR, 1) &&
|
||||
VerifyOffset(verifier, VT_WEAPONS) &&
|
||||
verifier.VerifyVector(weapons()) &&
|
||||
verifier.VerifyVectorOfTables(weapons()) &&
|
||||
VerifyField<uint8_t>(verifier, VT_EQUIPPED_TYPE) &&
|
||||
VerifyField<uint8_t>(verifier, VT_EQUIPPED_TYPE, 1) &&
|
||||
VerifyOffset(verifier, VT_EQUIPPED) &&
|
||||
VerifyEquipment(verifier, equipped(), equipped_type()) &&
|
||||
VerifyOffset(verifier, VT_PATH) &&
|
||||
verifier.VerifyVector(path()) &&
|
||||
verifier.EndTable();
|
||||
}
|
||||
MonsterT *UnPack(const flatbuffers::resolver_function_t *_resolver = nullptr) const;
|
||||
void UnPackTo(MonsterT *_o, const flatbuffers::resolver_function_t *_resolver = nullptr) const;
|
||||
static flatbuffers::Offset<Monster> Pack(flatbuffers::FlatBufferBuilder &_fbb, const MonsterT* _o, const flatbuffers::rehasher_function_t *_rehasher = nullptr);
|
||||
MonsterT *UnPack(const ::flatbuffers::resolver_function_t *_resolver = nullptr) const;
|
||||
void UnPackTo(MonsterT *_o, const ::flatbuffers::resolver_function_t *_resolver = nullptr) const;
|
||||
static ::flatbuffers::Offset<Monster> Pack(::flatbuffers::FlatBufferBuilder &_fbb, const MonsterT* _o, const ::flatbuffers::rehasher_function_t *_rehasher = nullptr);
|
||||
};
|
||||
|
||||
template<> inline const MyGame::Sample::Weapon *Monster::equipped_as<MyGame::Sample::Weapon>() const {
|
||||
@@ -365,8 +361,9 @@ template<> inline const MyGame::Sample::Weapon *Monster::equipped_as<MyGame::Sam
|
||||
}
|
||||
|
||||
struct MonsterBuilder {
|
||||
flatbuffers::FlatBufferBuilder &fbb_;
|
||||
flatbuffers::uoffset_t start_;
|
||||
typedef Monster Table;
|
||||
::flatbuffers::FlatBufferBuilder &fbb_;
|
||||
::flatbuffers::uoffset_t start_;
|
||||
void add_pos(const MyGame::Sample::Vec3 *pos) {
|
||||
fbb_.AddStruct(Monster::VT_POS, pos);
|
||||
}
|
||||
@@ -376,51 +373,50 @@ struct MonsterBuilder {
|
||||
void add_hp(int16_t hp) {
|
||||
fbb_.AddElement<int16_t>(Monster::VT_HP, hp, 100);
|
||||
}
|
||||
void add_name(flatbuffers::Offset<flatbuffers::String> name) {
|
||||
void add_name(::flatbuffers::Offset<::flatbuffers::String> name) {
|
||||
fbb_.AddOffset(Monster::VT_NAME, name);
|
||||
}
|
||||
void add_inventory(flatbuffers::Offset<flatbuffers::Vector<uint8_t>> inventory) {
|
||||
void add_inventory(::flatbuffers::Offset<::flatbuffers::Vector<uint8_t>> inventory) {
|
||||
fbb_.AddOffset(Monster::VT_INVENTORY, inventory);
|
||||
}
|
||||
void add_color(MyGame::Sample::Color color) {
|
||||
fbb_.AddElement<int8_t>(Monster::VT_COLOR, static_cast<int8_t>(color), 2);
|
||||
}
|
||||
void add_weapons(flatbuffers::Offset<flatbuffers::Vector<flatbuffers::Offset<MyGame::Sample::Weapon>>> weapons) {
|
||||
void add_weapons(::flatbuffers::Offset<::flatbuffers::Vector<::flatbuffers::Offset<MyGame::Sample::Weapon>>> weapons) {
|
||||
fbb_.AddOffset(Monster::VT_WEAPONS, weapons);
|
||||
}
|
||||
void add_equipped_type(MyGame::Sample::Equipment equipped_type) {
|
||||
fbb_.AddElement<uint8_t>(Monster::VT_EQUIPPED_TYPE, static_cast<uint8_t>(equipped_type), 0);
|
||||
}
|
||||
void add_equipped(flatbuffers::Offset<void> equipped) {
|
||||
void add_equipped(::flatbuffers::Offset<void> equipped) {
|
||||
fbb_.AddOffset(Monster::VT_EQUIPPED, equipped);
|
||||
}
|
||||
void add_path(flatbuffers::Offset<flatbuffers::Vector<const MyGame::Sample::Vec3 *>> path) {
|
||||
void add_path(::flatbuffers::Offset<::flatbuffers::Vector<const MyGame::Sample::Vec3 *>> path) {
|
||||
fbb_.AddOffset(Monster::VT_PATH, path);
|
||||
}
|
||||
explicit MonsterBuilder(flatbuffers::FlatBufferBuilder &_fbb)
|
||||
explicit MonsterBuilder(::flatbuffers::FlatBufferBuilder &_fbb)
|
||||
: fbb_(_fbb) {
|
||||
start_ = fbb_.StartTable();
|
||||
}
|
||||
MonsterBuilder &operator=(const MonsterBuilder &);
|
||||
flatbuffers::Offset<Monster> Finish() {
|
||||
::flatbuffers::Offset<Monster> Finish() {
|
||||
const auto end = fbb_.EndTable(start_);
|
||||
auto o = flatbuffers::Offset<Monster>(end);
|
||||
auto o = ::flatbuffers::Offset<Monster>(end);
|
||||
return o;
|
||||
}
|
||||
};
|
||||
|
||||
inline flatbuffers::Offset<Monster> CreateMonster(
|
||||
flatbuffers::FlatBufferBuilder &_fbb,
|
||||
const MyGame::Sample::Vec3 *pos = 0,
|
||||
inline ::flatbuffers::Offset<Monster> CreateMonster(
|
||||
::flatbuffers::FlatBufferBuilder &_fbb,
|
||||
const MyGame::Sample::Vec3 *pos = nullptr,
|
||||
int16_t mana = 150,
|
||||
int16_t hp = 100,
|
||||
flatbuffers::Offset<flatbuffers::String> name = 0,
|
||||
flatbuffers::Offset<flatbuffers::Vector<uint8_t>> inventory = 0,
|
||||
::flatbuffers::Offset<::flatbuffers::String> name = 0,
|
||||
::flatbuffers::Offset<::flatbuffers::Vector<uint8_t>> inventory = 0,
|
||||
MyGame::Sample::Color color = MyGame::Sample::Color_Blue,
|
||||
flatbuffers::Offset<flatbuffers::Vector<flatbuffers::Offset<MyGame::Sample::Weapon>>> weapons = 0,
|
||||
::flatbuffers::Offset<::flatbuffers::Vector<::flatbuffers::Offset<MyGame::Sample::Weapon>>> weapons = 0,
|
||||
MyGame::Sample::Equipment equipped_type = MyGame::Sample::Equipment_NONE,
|
||||
flatbuffers::Offset<void> equipped = 0,
|
||||
flatbuffers::Offset<flatbuffers::Vector<const MyGame::Sample::Vec3 *>> path = 0) {
|
||||
::flatbuffers::Offset<void> equipped = 0,
|
||||
::flatbuffers::Offset<::flatbuffers::Vector<const MyGame::Sample::Vec3 *>> path = 0) {
|
||||
MonsterBuilder builder_(_fbb);
|
||||
builder_.add_path(path);
|
||||
builder_.add_equipped(equipped);
|
||||
@@ -435,21 +431,21 @@ inline flatbuffers::Offset<Monster> CreateMonster(
|
||||
return builder_.Finish();
|
||||
}
|
||||
|
||||
inline flatbuffers::Offset<Monster> CreateMonsterDirect(
|
||||
flatbuffers::FlatBufferBuilder &_fbb,
|
||||
const MyGame::Sample::Vec3 *pos = 0,
|
||||
inline ::flatbuffers::Offset<Monster> CreateMonsterDirect(
|
||||
::flatbuffers::FlatBufferBuilder &_fbb,
|
||||
const MyGame::Sample::Vec3 *pos = nullptr,
|
||||
int16_t mana = 150,
|
||||
int16_t hp = 100,
|
||||
const char *name = nullptr,
|
||||
const std::vector<uint8_t> *inventory = nullptr,
|
||||
MyGame::Sample::Color color = MyGame::Sample::Color_Blue,
|
||||
const std::vector<flatbuffers::Offset<MyGame::Sample::Weapon>> *weapons = nullptr,
|
||||
const std::vector<::flatbuffers::Offset<MyGame::Sample::Weapon>> *weapons = nullptr,
|
||||
MyGame::Sample::Equipment equipped_type = MyGame::Sample::Equipment_NONE,
|
||||
flatbuffers::Offset<void> equipped = 0,
|
||||
::flatbuffers::Offset<void> equipped = 0,
|
||||
const std::vector<MyGame::Sample::Vec3> *path = nullptr) {
|
||||
auto name__ = name ? _fbb.CreateString(name) : 0;
|
||||
auto inventory__ = inventory ? _fbb.CreateVector<uint8_t>(*inventory) : 0;
|
||||
auto weapons__ = weapons ? _fbb.CreateVector<flatbuffers::Offset<MyGame::Sample::Weapon>>(*weapons) : 0;
|
||||
auto weapons__ = weapons ? _fbb.CreateVector<::flatbuffers::Offset<MyGame::Sample::Weapon>>(*weapons) : 0;
|
||||
auto path__ = path ? _fbb.CreateVectorOfStructs<MyGame::Sample::Vec3>(*path) : 0;
|
||||
return MyGame::Sample::CreateMonster(
|
||||
_fbb,
|
||||
@@ -465,85 +461,72 @@ inline flatbuffers::Offset<Monster> CreateMonsterDirect(
|
||||
path__);
|
||||
}
|
||||
|
||||
flatbuffers::Offset<Monster> CreateMonster(flatbuffers::FlatBufferBuilder &_fbb, const MonsterT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr);
|
||||
::flatbuffers::Offset<Monster> CreateMonster(::flatbuffers::FlatBufferBuilder &_fbb, const MonsterT *_o, const ::flatbuffers::rehasher_function_t *_rehasher = nullptr);
|
||||
|
||||
struct WeaponT : public flatbuffers::NativeTable {
|
||||
struct WeaponT : public ::flatbuffers::NativeTable {
|
||||
typedef Weapon TableType;
|
||||
std::string name;
|
||||
int16_t damage;
|
||||
WeaponT()
|
||||
: damage(0) {
|
||||
}
|
||||
std::string name{};
|
||||
int16_t damage = 0;
|
||||
};
|
||||
|
||||
inline bool operator==(const WeaponT &lhs, const WeaponT &rhs) {
|
||||
return
|
||||
(lhs.name == rhs.name) &&
|
||||
(lhs.damage == rhs.damage);
|
||||
}
|
||||
|
||||
inline bool operator!=(const WeaponT &lhs, const WeaponT &rhs) {
|
||||
return !(lhs == rhs);
|
||||
}
|
||||
|
||||
|
||||
struct Weapon FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table {
|
||||
struct Weapon FLATBUFFERS_FINAL_CLASS : private ::flatbuffers::Table {
|
||||
typedef WeaponT NativeTableType;
|
||||
static const flatbuffers::TypeTable *MiniReflectTypeTable() {
|
||||
typedef WeaponBuilder Builder;
|
||||
static const ::flatbuffers::TypeTable *MiniReflectTypeTable() {
|
||||
return WeaponTypeTable();
|
||||
}
|
||||
enum FlatBuffersVTableOffset FLATBUFFERS_VTABLE_UNDERLYING_TYPE {
|
||||
VT_NAME = 4,
|
||||
VT_DAMAGE = 6
|
||||
};
|
||||
const flatbuffers::String *name() const {
|
||||
return GetPointer<const flatbuffers::String *>(VT_NAME);
|
||||
const ::flatbuffers::String *name() const {
|
||||
return GetPointer<const ::flatbuffers::String *>(VT_NAME);
|
||||
}
|
||||
flatbuffers::String *mutable_name() {
|
||||
return GetPointer<flatbuffers::String *>(VT_NAME);
|
||||
::flatbuffers::String *mutable_name() {
|
||||
return GetPointer<::flatbuffers::String *>(VT_NAME);
|
||||
}
|
||||
int16_t damage() const {
|
||||
return GetField<int16_t>(VT_DAMAGE, 0);
|
||||
}
|
||||
bool mutate_damage(int16_t _damage) {
|
||||
bool mutate_damage(int16_t _damage = 0) {
|
||||
return SetField<int16_t>(VT_DAMAGE, _damage, 0);
|
||||
}
|
||||
bool Verify(flatbuffers::Verifier &verifier) const {
|
||||
bool Verify(::flatbuffers::Verifier &verifier) const {
|
||||
return VerifyTableStart(verifier) &&
|
||||
VerifyOffset(verifier, VT_NAME) &&
|
||||
verifier.VerifyString(name()) &&
|
||||
VerifyField<int16_t>(verifier, VT_DAMAGE) &&
|
||||
VerifyField<int16_t>(verifier, VT_DAMAGE, 2) &&
|
||||
verifier.EndTable();
|
||||
}
|
||||
WeaponT *UnPack(const flatbuffers::resolver_function_t *_resolver = nullptr) const;
|
||||
void UnPackTo(WeaponT *_o, const flatbuffers::resolver_function_t *_resolver = nullptr) const;
|
||||
static flatbuffers::Offset<Weapon> Pack(flatbuffers::FlatBufferBuilder &_fbb, const WeaponT* _o, const flatbuffers::rehasher_function_t *_rehasher = nullptr);
|
||||
WeaponT *UnPack(const ::flatbuffers::resolver_function_t *_resolver = nullptr) const;
|
||||
void UnPackTo(WeaponT *_o, const ::flatbuffers::resolver_function_t *_resolver = nullptr) const;
|
||||
static ::flatbuffers::Offset<Weapon> Pack(::flatbuffers::FlatBufferBuilder &_fbb, const WeaponT* _o, const ::flatbuffers::rehasher_function_t *_rehasher = nullptr);
|
||||
};
|
||||
|
||||
struct WeaponBuilder {
|
||||
flatbuffers::FlatBufferBuilder &fbb_;
|
||||
flatbuffers::uoffset_t start_;
|
||||
void add_name(flatbuffers::Offset<flatbuffers::String> name) {
|
||||
typedef Weapon Table;
|
||||
::flatbuffers::FlatBufferBuilder &fbb_;
|
||||
::flatbuffers::uoffset_t start_;
|
||||
void add_name(::flatbuffers::Offset<::flatbuffers::String> name) {
|
||||
fbb_.AddOffset(Weapon::VT_NAME, name);
|
||||
}
|
||||
void add_damage(int16_t damage) {
|
||||
fbb_.AddElement<int16_t>(Weapon::VT_DAMAGE, damage, 0);
|
||||
}
|
||||
explicit WeaponBuilder(flatbuffers::FlatBufferBuilder &_fbb)
|
||||
explicit WeaponBuilder(::flatbuffers::FlatBufferBuilder &_fbb)
|
||||
: fbb_(_fbb) {
|
||||
start_ = fbb_.StartTable();
|
||||
}
|
||||
WeaponBuilder &operator=(const WeaponBuilder &);
|
||||
flatbuffers::Offset<Weapon> Finish() {
|
||||
::flatbuffers::Offset<Weapon> Finish() {
|
||||
const auto end = fbb_.EndTable(start_);
|
||||
auto o = flatbuffers::Offset<Weapon>(end);
|
||||
auto o = ::flatbuffers::Offset<Weapon>(end);
|
||||
return o;
|
||||
}
|
||||
};
|
||||
|
||||
inline flatbuffers::Offset<Weapon> CreateWeapon(
|
||||
flatbuffers::FlatBufferBuilder &_fbb,
|
||||
flatbuffers::Offset<flatbuffers::String> name = 0,
|
||||
inline ::flatbuffers::Offset<Weapon> CreateWeapon(
|
||||
::flatbuffers::FlatBufferBuilder &_fbb,
|
||||
::flatbuffers::Offset<::flatbuffers::String> name = 0,
|
||||
int16_t damage = 0) {
|
||||
WeaponBuilder builder_(_fbb);
|
||||
builder_.add_name(name);
|
||||
@@ -551,8 +534,8 @@ inline flatbuffers::Offset<Weapon> CreateWeapon(
|
||||
return builder_.Finish();
|
||||
}
|
||||
|
||||
inline flatbuffers::Offset<Weapon> CreateWeaponDirect(
|
||||
flatbuffers::FlatBufferBuilder &_fbb,
|
||||
inline ::flatbuffers::Offset<Weapon> CreateWeaponDirect(
|
||||
::flatbuffers::FlatBufferBuilder &_fbb,
|
||||
const char *name = nullptr,
|
||||
int16_t damage = 0) {
|
||||
auto name__ = name ? _fbb.CreateString(name) : 0;
|
||||
@@ -562,44 +545,89 @@ inline flatbuffers::Offset<Weapon> CreateWeaponDirect(
|
||||
damage);
|
||||
}
|
||||
|
||||
flatbuffers::Offset<Weapon> CreateWeapon(flatbuffers::FlatBufferBuilder &_fbb, const WeaponT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr);
|
||||
::flatbuffers::Offset<Weapon> CreateWeapon(::flatbuffers::FlatBufferBuilder &_fbb, const WeaponT *_o, const ::flatbuffers::rehasher_function_t *_rehasher = nullptr);
|
||||
|
||||
inline MonsterT *Monster::UnPack(const flatbuffers::resolver_function_t *_resolver) const {
|
||||
auto _o = new MonsterT();
|
||||
UnPackTo(_o, _resolver);
|
||||
return _o;
|
||||
|
||||
inline bool operator==(const MonsterT &lhs, const MonsterT &rhs) {
|
||||
return
|
||||
((lhs.pos == rhs.pos) || (lhs.pos && rhs.pos && *lhs.pos == *rhs.pos)) &&
|
||||
(lhs.mana == rhs.mana) &&
|
||||
(lhs.hp == rhs.hp) &&
|
||||
(lhs.name == rhs.name) &&
|
||||
(lhs.inventory == rhs.inventory) &&
|
||||
(lhs.color == rhs.color) &&
|
||||
(lhs.weapons.size() == rhs.weapons.size() && std::equal(lhs.weapons.cbegin(), lhs.weapons.cend(), rhs.weapons.cbegin(), [](std::unique_ptr<MyGame::Sample::WeaponT> const &a, std::unique_ptr<MyGame::Sample::WeaponT> const &b) { return (a == b) || (a && b && *a == *b); })) &&
|
||||
(lhs.equipped == rhs.equipped) &&
|
||||
(lhs.path == rhs.path);
|
||||
}
|
||||
|
||||
inline void Monster::UnPackTo(MonsterT *_o, const flatbuffers::resolver_function_t *_resolver) const {
|
||||
inline bool operator!=(const MonsterT &lhs, const MonsterT &rhs) {
|
||||
return !(lhs == rhs);
|
||||
}
|
||||
|
||||
|
||||
inline MonsterT::MonsterT(const MonsterT &o)
|
||||
: pos((o.pos) ? new MyGame::Sample::Vec3(*o.pos) : nullptr),
|
||||
mana(o.mana),
|
||||
hp(o.hp),
|
||||
name(o.name),
|
||||
inventory(o.inventory),
|
||||
color(o.color),
|
||||
equipped(o.equipped),
|
||||
path(o.path) {
|
||||
weapons.reserve(o.weapons.size());
|
||||
for (const auto &weapons_ : o.weapons) { weapons.emplace_back((weapons_) ? new MyGame::Sample::WeaponT(*weapons_) : nullptr); }
|
||||
}
|
||||
|
||||
inline MonsterT &MonsterT::operator=(MonsterT o) FLATBUFFERS_NOEXCEPT {
|
||||
std::swap(pos, o.pos);
|
||||
std::swap(mana, o.mana);
|
||||
std::swap(hp, o.hp);
|
||||
std::swap(name, o.name);
|
||||
std::swap(inventory, o.inventory);
|
||||
std::swap(color, o.color);
|
||||
std::swap(weapons, o.weapons);
|
||||
std::swap(equipped, o.equipped);
|
||||
std::swap(path, o.path);
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline MonsterT *Monster::UnPack(const ::flatbuffers::resolver_function_t *_resolver) const {
|
||||
auto _o = std::unique_ptr<MonsterT>(new MonsterT());
|
||||
UnPackTo(_o.get(), _resolver);
|
||||
return _o.release();
|
||||
}
|
||||
|
||||
inline void Monster::UnPackTo(MonsterT *_o, const ::flatbuffers::resolver_function_t *_resolver) const {
|
||||
(void)_o;
|
||||
(void)_resolver;
|
||||
{ auto _e = pos(); if (_e) _o->pos = flatbuffers::unique_ptr<MyGame::Sample::Vec3>(new MyGame::Sample::Vec3(*_e)); };
|
||||
{ auto _e = mana(); _o->mana = _e; };
|
||||
{ auto _e = hp(); _o->hp = _e; };
|
||||
{ auto _e = name(); if (_e) _o->name = _e->str(); };
|
||||
{ auto _e = inventory(); if (_e) { _o->inventory.resize(_e->size()); for (flatbuffers::uoffset_t _i = 0; _i < _e->size(); _i++) { _o->inventory[_i] = _e->Get(_i); } } };
|
||||
{ auto _e = color(); _o->color = _e; };
|
||||
{ auto _e = weapons(); if (_e) { _o->weapons.resize(_e->size()); for (flatbuffers::uoffset_t _i = 0; _i < _e->size(); _i++) { _o->weapons[_i] = flatbuffers::unique_ptr<MyGame::Sample::WeaponT>(_e->Get(_i)->UnPack(_resolver)); } } };
|
||||
{ auto _e = equipped_type(); _o->equipped.type = _e; };
|
||||
{ auto _e = equipped(); if (_e) _o->equipped.value = EquipmentUnion::UnPack(_e, equipped_type(), _resolver); };
|
||||
{ auto _e = path(); if (_e) { _o->path.resize(_e->size()); for (flatbuffers::uoffset_t _i = 0; _i < _e->size(); _i++) { _o->path[_i] = *_e->Get(_i); } } };
|
||||
{ auto _e = pos(); if (_e) _o->pos = std::unique_ptr<MyGame::Sample::Vec3>(new MyGame::Sample::Vec3(*_e)); }
|
||||
{ auto _e = mana(); _o->mana = _e; }
|
||||
{ auto _e = hp(); _o->hp = _e; }
|
||||
{ auto _e = name(); if (_e) _o->name = _e->str(); }
|
||||
{ auto _e = inventory(); if (_e) { _o->inventory.resize(_e->size()); std::copy(_e->begin(), _e->end(), _o->inventory.begin()); } }
|
||||
{ auto _e = color(); _o->color = _e; }
|
||||
{ auto _e = weapons(); if (_e) { _o->weapons.resize(_e->size()); for (::flatbuffers::uoffset_t _i = 0; _i < _e->size(); _i++) { if(_o->weapons[_i]) { _e->Get(_i)->UnPackTo(_o->weapons[_i].get(), _resolver); } else { _o->weapons[_i] = std::unique_ptr<MyGame::Sample::WeaponT>(_e->Get(_i)->UnPack(_resolver)); }; } } else { _o->weapons.resize(0); } }
|
||||
{ auto _e = equipped_type(); _o->equipped.type = _e; }
|
||||
{ auto _e = equipped(); if (_e) _o->equipped.value = MyGame::Sample::EquipmentUnion::UnPack(_e, equipped_type(), _resolver); }
|
||||
{ auto _e = path(); if (_e) { _o->path.resize(_e->size()); for (::flatbuffers::uoffset_t _i = 0; _i < _e->size(); _i++) { _o->path[_i] = *_e->Get(_i); } } else { _o->path.resize(0); } }
|
||||
}
|
||||
|
||||
inline flatbuffers::Offset<Monster> Monster::Pack(flatbuffers::FlatBufferBuilder &_fbb, const MonsterT* _o, const flatbuffers::rehasher_function_t *_rehasher) {
|
||||
inline ::flatbuffers::Offset<Monster> Monster::Pack(::flatbuffers::FlatBufferBuilder &_fbb, const MonsterT* _o, const ::flatbuffers::rehasher_function_t *_rehasher) {
|
||||
return CreateMonster(_fbb, _o, _rehasher);
|
||||
}
|
||||
|
||||
inline flatbuffers::Offset<Monster> CreateMonster(flatbuffers::FlatBufferBuilder &_fbb, const MonsterT *_o, const flatbuffers::rehasher_function_t *_rehasher) {
|
||||
inline ::flatbuffers::Offset<Monster> CreateMonster(::flatbuffers::FlatBufferBuilder &_fbb, const MonsterT *_o, const ::flatbuffers::rehasher_function_t *_rehasher) {
|
||||
(void)_rehasher;
|
||||
(void)_o;
|
||||
struct _VectorArgs { flatbuffers::FlatBufferBuilder *__fbb; const MonsterT* __o; const flatbuffers::rehasher_function_t *__rehasher; } _va = { &_fbb, _o, _rehasher}; (void)_va;
|
||||
auto _pos = _o->pos ? _o->pos.get() : 0;
|
||||
struct _VectorArgs { ::flatbuffers::FlatBufferBuilder *__fbb; const MonsterT* __o; const ::flatbuffers::rehasher_function_t *__rehasher; } _va = { &_fbb, _o, _rehasher}; (void)_va;
|
||||
auto _pos = _o->pos ? _o->pos.get() : nullptr;
|
||||
auto _mana = _o->mana;
|
||||
auto _hp = _o->hp;
|
||||
auto _name = _o->name.empty() ? 0 : _fbb.CreateString(_o->name);
|
||||
auto _inventory = _o->inventory.size() ? _fbb.CreateVector(_o->inventory) : 0;
|
||||
auto _color = _o->color;
|
||||
auto _weapons = _o->weapons.size() ? _fbb.CreateVector<flatbuffers::Offset<MyGame::Sample::Weapon>> (_o->weapons.size(), [](size_t i, _VectorArgs *__va) { return CreateWeapon(*__va->__fbb, __va->__o->weapons[i].get(), __va->__rehasher); }, &_va ) : 0;
|
||||
auto _weapons = _o->weapons.size() ? _fbb.CreateVector<::flatbuffers::Offset<MyGame::Sample::Weapon>> (_o->weapons.size(), [](size_t i, _VectorArgs *__va) { return CreateWeapon(*__va->__fbb, __va->__o->weapons[i].get(), __va->__rehasher); }, &_va ) : 0;
|
||||
auto _equipped_type = _o->equipped.type;
|
||||
auto _equipped = _o->equipped.Pack(_fbb);
|
||||
auto _path = _o->path.size() ? _fbb.CreateVectorOfStructs(_o->path) : 0;
|
||||
@@ -617,27 +645,39 @@ inline flatbuffers::Offset<Monster> CreateMonster(flatbuffers::FlatBufferBuilder
|
||||
_path);
|
||||
}
|
||||
|
||||
inline WeaponT *Weapon::UnPack(const flatbuffers::resolver_function_t *_resolver) const {
|
||||
auto _o = new WeaponT();
|
||||
UnPackTo(_o, _resolver);
|
||||
return _o;
|
||||
|
||||
inline bool operator==(const WeaponT &lhs, const WeaponT &rhs) {
|
||||
return
|
||||
(lhs.name == rhs.name) &&
|
||||
(lhs.damage == rhs.damage);
|
||||
}
|
||||
|
||||
inline void Weapon::UnPackTo(WeaponT *_o, const flatbuffers::resolver_function_t *_resolver) const {
|
||||
inline bool operator!=(const WeaponT &lhs, const WeaponT &rhs) {
|
||||
return !(lhs == rhs);
|
||||
}
|
||||
|
||||
|
||||
inline WeaponT *Weapon::UnPack(const ::flatbuffers::resolver_function_t *_resolver) const {
|
||||
auto _o = std::unique_ptr<WeaponT>(new WeaponT());
|
||||
UnPackTo(_o.get(), _resolver);
|
||||
return _o.release();
|
||||
}
|
||||
|
||||
inline void Weapon::UnPackTo(WeaponT *_o, const ::flatbuffers::resolver_function_t *_resolver) const {
|
||||
(void)_o;
|
||||
(void)_resolver;
|
||||
{ auto _e = name(); if (_e) _o->name = _e->str(); };
|
||||
{ auto _e = damage(); _o->damage = _e; };
|
||||
{ auto _e = name(); if (_e) _o->name = _e->str(); }
|
||||
{ auto _e = damage(); _o->damage = _e; }
|
||||
}
|
||||
|
||||
inline flatbuffers::Offset<Weapon> Weapon::Pack(flatbuffers::FlatBufferBuilder &_fbb, const WeaponT* _o, const flatbuffers::rehasher_function_t *_rehasher) {
|
||||
inline ::flatbuffers::Offset<Weapon> Weapon::Pack(::flatbuffers::FlatBufferBuilder &_fbb, const WeaponT* _o, const ::flatbuffers::rehasher_function_t *_rehasher) {
|
||||
return CreateWeapon(_fbb, _o, _rehasher);
|
||||
}
|
||||
|
||||
inline flatbuffers::Offset<Weapon> CreateWeapon(flatbuffers::FlatBufferBuilder &_fbb, const WeaponT *_o, const flatbuffers::rehasher_function_t *_rehasher) {
|
||||
inline ::flatbuffers::Offset<Weapon> CreateWeapon(::flatbuffers::FlatBufferBuilder &_fbb, const WeaponT *_o, const ::flatbuffers::rehasher_function_t *_rehasher) {
|
||||
(void)_rehasher;
|
||||
(void)_o;
|
||||
struct _VectorArgs { flatbuffers::FlatBufferBuilder *__fbb; const WeaponT* __o; const flatbuffers::rehasher_function_t *__rehasher; } _va = { &_fbb, _o, _rehasher}; (void)_va;
|
||||
struct _VectorArgs { ::flatbuffers::FlatBufferBuilder *__fbb; const WeaponT* __o; const ::flatbuffers::rehasher_function_t *__rehasher; } _va = { &_fbb, _o, _rehasher}; (void)_va;
|
||||
auto _name = _o->name.empty() ? 0 : _fbb.CreateString(_o->name);
|
||||
auto _damage = _o->damage;
|
||||
return MyGame::Sample::CreateWeapon(
|
||||
@@ -646,7 +686,7 @@ inline flatbuffers::Offset<Weapon> CreateWeapon(flatbuffers::FlatBufferBuilder &
|
||||
_damage);
|
||||
}
|
||||
|
||||
inline bool VerifyEquipment(flatbuffers::Verifier &verifier, const void *obj, Equipment type) {
|
||||
inline bool VerifyEquipment(::flatbuffers::Verifier &verifier, const void *obj, Equipment type) {
|
||||
switch (type) {
|
||||
case Equipment_NONE: {
|
||||
return true;
|
||||
@@ -655,14 +695,14 @@ inline bool VerifyEquipment(flatbuffers::Verifier &verifier, const void *obj, Eq
|
||||
auto ptr = reinterpret_cast<const MyGame::Sample::Weapon *>(obj);
|
||||
return verifier.VerifyTable(ptr);
|
||||
}
|
||||
default: return false;
|
||||
default: return true;
|
||||
}
|
||||
}
|
||||
|
||||
inline bool VerifyEquipmentVector(flatbuffers::Verifier &verifier, const flatbuffers::Vector<flatbuffers::Offset<void>> *values, const flatbuffers::Vector<uint8_t> *types) {
|
||||
inline bool VerifyEquipmentVector(::flatbuffers::Verifier &verifier, const ::flatbuffers::Vector<::flatbuffers::Offset<void>> *values, const ::flatbuffers::Vector<uint8_t> *types) {
|
||||
if (!values || !types) return !values && !types;
|
||||
if (values->size() != types->size()) return false;
|
||||
for (flatbuffers::uoffset_t i = 0; i < values->size(); ++i) {
|
||||
for (::flatbuffers::uoffset_t i = 0; i < values->size(); ++i) {
|
||||
if (!VerifyEquipment(
|
||||
verifier, values->Get(i), types->GetEnum<Equipment>(i))) {
|
||||
return false;
|
||||
@@ -671,7 +711,8 @@ inline bool VerifyEquipmentVector(flatbuffers::Verifier &verifier, const flatbuf
|
||||
return true;
|
||||
}
|
||||
|
||||
inline void *EquipmentUnion::UnPack(const void *obj, Equipment type, const flatbuffers::resolver_function_t *resolver) {
|
||||
inline void *EquipmentUnion::UnPack(const void *obj, Equipment type, const ::flatbuffers::resolver_function_t *resolver) {
|
||||
(void)resolver;
|
||||
switch (type) {
|
||||
case Equipment_Weapon: {
|
||||
auto ptr = reinterpret_cast<const MyGame::Sample::Weapon *>(obj);
|
||||
@@ -681,7 +722,8 @@ inline void *EquipmentUnion::UnPack(const void *obj, Equipment type, const flatb
|
||||
}
|
||||
}
|
||||
|
||||
inline flatbuffers::Offset<void> EquipmentUnion::Pack(flatbuffers::FlatBufferBuilder &_fbb, const flatbuffers::rehasher_function_t *_rehasher) const {
|
||||
inline ::flatbuffers::Offset<void> EquipmentUnion::Pack(::flatbuffers::FlatBufferBuilder &_fbb, const ::flatbuffers::rehasher_function_t *_rehasher) const {
|
||||
(void)_rehasher;
|
||||
switch (type) {
|
||||
case Equipment_Weapon: {
|
||||
auto ptr = reinterpret_cast<const MyGame::Sample::WeaponT *>(value);
|
||||
@@ -691,7 +733,7 @@ inline flatbuffers::Offset<void> EquipmentUnion::Pack(flatbuffers::FlatBufferBui
|
||||
}
|
||||
}
|
||||
|
||||
inline EquipmentUnion::EquipmentUnion(const EquipmentUnion &u) FLATBUFFERS_NOEXCEPT : type(u.type), value(nullptr) {
|
||||
inline EquipmentUnion::EquipmentUnion(const EquipmentUnion &u) : type(u.type), value(nullptr) {
|
||||
switch (type) {
|
||||
case Equipment_Weapon: {
|
||||
value = new MyGame::Sample::WeaponT(*reinterpret_cast<MyGame::Sample::WeaponT *>(u.value));
|
||||
@@ -715,13 +757,13 @@ inline void EquipmentUnion::Reset() {
|
||||
type = Equipment_NONE;
|
||||
}
|
||||
|
||||
inline const flatbuffers::TypeTable *ColorTypeTable() {
|
||||
static const flatbuffers::TypeCode type_codes[] = {
|
||||
{ flatbuffers::ET_CHAR, 0, 0 },
|
||||
{ flatbuffers::ET_CHAR, 0, 0 },
|
||||
{ flatbuffers::ET_CHAR, 0, 0 }
|
||||
inline const ::flatbuffers::TypeTable *ColorTypeTable() {
|
||||
static const ::flatbuffers::TypeCode type_codes[] = {
|
||||
{ ::flatbuffers::ET_CHAR, 0, 0 },
|
||||
{ ::flatbuffers::ET_CHAR, 0, 0 },
|
||||
{ ::flatbuffers::ET_CHAR, 0, 0 }
|
||||
};
|
||||
static const flatbuffers::TypeFunction type_refs[] = {
|
||||
static const ::flatbuffers::TypeFunction type_refs[] = {
|
||||
MyGame::Sample::ColorTypeTable
|
||||
};
|
||||
static const char * const names[] = {
|
||||
@@ -729,35 +771,35 @@ inline const flatbuffers::TypeTable *ColorTypeTable() {
|
||||
"Green",
|
||||
"Blue"
|
||||
};
|
||||
static const flatbuffers::TypeTable tt = {
|
||||
flatbuffers::ST_ENUM, 3, type_codes, type_refs, nullptr, names
|
||||
static const ::flatbuffers::TypeTable tt = {
|
||||
::flatbuffers::ST_ENUM, 3, type_codes, type_refs, nullptr, nullptr, names
|
||||
};
|
||||
return &tt;
|
||||
}
|
||||
|
||||
inline const flatbuffers::TypeTable *EquipmentTypeTable() {
|
||||
static const flatbuffers::TypeCode type_codes[] = {
|
||||
{ flatbuffers::ET_SEQUENCE, 0, -1 },
|
||||
{ flatbuffers::ET_SEQUENCE, 0, 0 }
|
||||
inline const ::flatbuffers::TypeTable *EquipmentTypeTable() {
|
||||
static const ::flatbuffers::TypeCode type_codes[] = {
|
||||
{ ::flatbuffers::ET_SEQUENCE, 0, -1 },
|
||||
{ ::flatbuffers::ET_SEQUENCE, 0, 0 }
|
||||
};
|
||||
static const flatbuffers::TypeFunction type_refs[] = {
|
||||
static const ::flatbuffers::TypeFunction type_refs[] = {
|
||||
MyGame::Sample::WeaponTypeTable
|
||||
};
|
||||
static const char * const names[] = {
|
||||
"NONE",
|
||||
"Weapon"
|
||||
};
|
||||
static const flatbuffers::TypeTable tt = {
|
||||
flatbuffers::ST_UNION, 2, type_codes, type_refs, nullptr, names
|
||||
static const ::flatbuffers::TypeTable tt = {
|
||||
::flatbuffers::ST_UNION, 2, type_codes, type_refs, nullptr, nullptr, names
|
||||
};
|
||||
return &tt;
|
||||
}
|
||||
|
||||
inline const flatbuffers::TypeTable *Vec3TypeTable() {
|
||||
static const flatbuffers::TypeCode type_codes[] = {
|
||||
{ flatbuffers::ET_FLOAT, 0, -1 },
|
||||
{ flatbuffers::ET_FLOAT, 0, -1 },
|
||||
{ flatbuffers::ET_FLOAT, 0, -1 }
|
||||
inline const ::flatbuffers::TypeTable *Vec3TypeTable() {
|
||||
static const ::flatbuffers::TypeCode type_codes[] = {
|
||||
{ ::flatbuffers::ET_FLOAT, 0, -1 },
|
||||
{ ::flatbuffers::ET_FLOAT, 0, -1 },
|
||||
{ ::flatbuffers::ET_FLOAT, 0, -1 }
|
||||
};
|
||||
static const int64_t values[] = { 0, 4, 8, 12 };
|
||||
static const char * const names[] = {
|
||||
@@ -765,27 +807,27 @@ inline const flatbuffers::TypeTable *Vec3TypeTable() {
|
||||
"y",
|
||||
"z"
|
||||
};
|
||||
static const flatbuffers::TypeTable tt = {
|
||||
flatbuffers::ST_STRUCT, 3, type_codes, nullptr, values, names
|
||||
static const ::flatbuffers::TypeTable tt = {
|
||||
::flatbuffers::ST_STRUCT, 3, type_codes, nullptr, nullptr, values, names
|
||||
};
|
||||
return &tt;
|
||||
}
|
||||
|
||||
inline const flatbuffers::TypeTable *MonsterTypeTable() {
|
||||
static const flatbuffers::TypeCode type_codes[] = {
|
||||
{ flatbuffers::ET_SEQUENCE, 0, 0 },
|
||||
{ flatbuffers::ET_SHORT, 0, -1 },
|
||||
{ flatbuffers::ET_SHORT, 0, -1 },
|
||||
{ flatbuffers::ET_STRING, 0, -1 },
|
||||
{ flatbuffers::ET_BOOL, 0, -1 },
|
||||
{ flatbuffers::ET_UCHAR, 1, -1 },
|
||||
{ flatbuffers::ET_CHAR, 0, 1 },
|
||||
{ flatbuffers::ET_SEQUENCE, 1, 2 },
|
||||
{ flatbuffers::ET_UTYPE, 0, 3 },
|
||||
{ flatbuffers::ET_SEQUENCE, 0, 3 },
|
||||
{ flatbuffers::ET_SEQUENCE, 1, 0 }
|
||||
inline const ::flatbuffers::TypeTable *MonsterTypeTable() {
|
||||
static const ::flatbuffers::TypeCode type_codes[] = {
|
||||
{ ::flatbuffers::ET_SEQUENCE, 0, 0 },
|
||||
{ ::flatbuffers::ET_SHORT, 0, -1 },
|
||||
{ ::flatbuffers::ET_SHORT, 0, -1 },
|
||||
{ ::flatbuffers::ET_STRING, 0, -1 },
|
||||
{ ::flatbuffers::ET_BOOL, 0, -1 },
|
||||
{ ::flatbuffers::ET_UCHAR, 1, -1 },
|
||||
{ ::flatbuffers::ET_CHAR, 0, 1 },
|
||||
{ ::flatbuffers::ET_SEQUENCE, 1, 2 },
|
||||
{ ::flatbuffers::ET_UTYPE, 0, 3 },
|
||||
{ ::flatbuffers::ET_SEQUENCE, 0, 3 },
|
||||
{ ::flatbuffers::ET_SEQUENCE, 1, 0 }
|
||||
};
|
||||
static const flatbuffers::TypeFunction type_refs[] = {
|
||||
static const ::flatbuffers::TypeFunction type_refs[] = {
|
||||
MyGame::Sample::Vec3TypeTable,
|
||||
MyGame::Sample::ColorTypeTable,
|
||||
MyGame::Sample::WeaponTypeTable,
|
||||
@@ -804,71 +846,75 @@ inline const flatbuffers::TypeTable *MonsterTypeTable() {
|
||||
"equipped",
|
||||
"path"
|
||||
};
|
||||
static const flatbuffers::TypeTable tt = {
|
||||
flatbuffers::ST_TABLE, 11, type_codes, type_refs, nullptr, names
|
||||
static const ::flatbuffers::TypeTable tt = {
|
||||
::flatbuffers::ST_TABLE, 11, type_codes, type_refs, nullptr, nullptr, names
|
||||
};
|
||||
return &tt;
|
||||
}
|
||||
|
||||
inline const flatbuffers::TypeTable *WeaponTypeTable() {
|
||||
static const flatbuffers::TypeCode type_codes[] = {
|
||||
{ flatbuffers::ET_STRING, 0, -1 },
|
||||
{ flatbuffers::ET_SHORT, 0, -1 }
|
||||
inline const ::flatbuffers::TypeTable *WeaponTypeTable() {
|
||||
static const ::flatbuffers::TypeCode type_codes[] = {
|
||||
{ ::flatbuffers::ET_STRING, 0, -1 },
|
||||
{ ::flatbuffers::ET_SHORT, 0, -1 }
|
||||
};
|
||||
static const char * const names[] = {
|
||||
"name",
|
||||
"damage"
|
||||
};
|
||||
static const flatbuffers::TypeTable tt = {
|
||||
flatbuffers::ST_TABLE, 2, type_codes, nullptr, nullptr, names
|
||||
static const ::flatbuffers::TypeTable tt = {
|
||||
::flatbuffers::ST_TABLE, 2, type_codes, nullptr, nullptr, nullptr, names
|
||||
};
|
||||
return &tt;
|
||||
}
|
||||
|
||||
inline const MyGame::Sample::Monster *GetMonster(const void *buf) {
|
||||
return flatbuffers::GetRoot<MyGame::Sample::Monster>(buf);
|
||||
return ::flatbuffers::GetRoot<MyGame::Sample::Monster>(buf);
|
||||
}
|
||||
|
||||
inline const MyGame::Sample::Monster *GetSizePrefixedMonster(const void *buf) {
|
||||
return flatbuffers::GetSizePrefixedRoot<MyGame::Sample::Monster>(buf);
|
||||
return ::flatbuffers::GetSizePrefixedRoot<MyGame::Sample::Monster>(buf);
|
||||
}
|
||||
|
||||
inline Monster *GetMutableMonster(void *buf) {
|
||||
return flatbuffers::GetMutableRoot<Monster>(buf);
|
||||
return ::flatbuffers::GetMutableRoot<Monster>(buf);
|
||||
}
|
||||
|
||||
inline MyGame::Sample::Monster *GetMutableSizePrefixedMonster(void *buf) {
|
||||
return ::flatbuffers::GetMutableSizePrefixedRoot<MyGame::Sample::Monster>(buf);
|
||||
}
|
||||
|
||||
inline bool VerifyMonsterBuffer(
|
||||
flatbuffers::Verifier &verifier) {
|
||||
::flatbuffers::Verifier &verifier) {
|
||||
return verifier.VerifyBuffer<MyGame::Sample::Monster>(nullptr);
|
||||
}
|
||||
|
||||
inline bool VerifySizePrefixedMonsterBuffer(
|
||||
flatbuffers::Verifier &verifier) {
|
||||
::flatbuffers::Verifier &verifier) {
|
||||
return verifier.VerifySizePrefixedBuffer<MyGame::Sample::Monster>(nullptr);
|
||||
}
|
||||
|
||||
inline void FinishMonsterBuffer(
|
||||
flatbuffers::FlatBufferBuilder &fbb,
|
||||
flatbuffers::Offset<MyGame::Sample::Monster> root) {
|
||||
::flatbuffers::FlatBufferBuilder &fbb,
|
||||
::flatbuffers::Offset<MyGame::Sample::Monster> root) {
|
||||
fbb.Finish(root);
|
||||
}
|
||||
|
||||
inline void FinishSizePrefixedMonsterBuffer(
|
||||
flatbuffers::FlatBufferBuilder &fbb,
|
||||
flatbuffers::Offset<MyGame::Sample::Monster> root) {
|
||||
::flatbuffers::FlatBufferBuilder &fbb,
|
||||
::flatbuffers::Offset<MyGame::Sample::Monster> root) {
|
||||
fbb.FinishSizePrefixed(root);
|
||||
}
|
||||
|
||||
inline flatbuffers::unique_ptr<MyGame::Sample::MonsterT> UnPackMonster(
|
||||
inline std::unique_ptr<MyGame::Sample::MonsterT> UnPackMonster(
|
||||
const void *buf,
|
||||
const flatbuffers::resolver_function_t *res = nullptr) {
|
||||
return flatbuffers::unique_ptr<MyGame::Sample::MonsterT>(GetMonster(buf)->UnPack(res));
|
||||
const ::flatbuffers::resolver_function_t *res = nullptr) {
|
||||
return std::unique_ptr<MyGame::Sample::MonsterT>(GetMonster(buf)->UnPack(res));
|
||||
}
|
||||
|
||||
inline flatbuffers::unique_ptr<MyGame::Sample::MonsterT> UnPackSizePrefixedMonster(
|
||||
inline std::unique_ptr<MyGame::Sample::MonsterT> UnPackSizePrefixedMonster(
|
||||
const void *buf,
|
||||
const flatbuffers::resolver_function_t *res = nullptr) {
|
||||
return flatbuffers::unique_ptr<MyGame::Sample::MonsterT>(GetSizePrefixedMonster(buf)->UnPack(res));
|
||||
const ::flatbuffers::resolver_function_t *res = nullptr) {
|
||||
return std::unique_ptr<MyGame::Sample::MonsterT>(GetSizePrefixedMonster(buf)->UnPack(res));
|
||||
}
|
||||
|
||||
} // namespace Sample
|
||||
|
||||
+54
-54
@@ -1,7 +1,7 @@
|
||||
// automatically generated by the FlatBuffers compiler, do not modify
|
||||
import flatbuffers
|
||||
|
||||
namespace MyGame_Sample
|
||||
namespace MyGame.Sample
|
||||
|
||||
enum Color:
|
||||
Color_Red = 0
|
||||
@@ -18,58 +18,58 @@ class Monster
|
||||
|
||||
class Weapon
|
||||
|
||||
class Vec3 : flatbuffers_handle
|
||||
def x():
|
||||
class Vec3 : flatbuffers.handle
|
||||
def x() -> float:
|
||||
return buf_.read_float32_le(pos_ + 0)
|
||||
def y():
|
||||
def y() -> float:
|
||||
return buf_.read_float32_le(pos_ + 4)
|
||||
def z():
|
||||
def z() -> float:
|
||||
return buf_.read_float32_le(pos_ + 8)
|
||||
|
||||
def CreateVec3(b_:flatbuffers_builder, x:float, y:float, z:float):
|
||||
def CreateVec3(b_:flatbuffers.builder, x:float, y:float, z:float):
|
||||
b_.Prep(4, 12)
|
||||
b_.PrependFloat32(z)
|
||||
b_.PrependFloat32(y)
|
||||
b_.PrependFloat32(x)
|
||||
return b_.Offset()
|
||||
|
||||
class Monster : flatbuffers_handle
|
||||
def pos():
|
||||
let o = buf_.flatbuffers_field_struct(pos_, 4)
|
||||
return if o: MyGame_Sample_Vec3 { buf_, o } else: nil
|
||||
def mana():
|
||||
return buf_.flatbuffers_field_int16(pos_, 6, 150)
|
||||
def hp():
|
||||
return buf_.flatbuffers_field_int16(pos_, 8, 100)
|
||||
def name():
|
||||
return buf_.flatbuffers_field_string(pos_, 10)
|
||||
def inventory(i:int):
|
||||
return buf_.read_int8_le(buf_.flatbuffers_field_vector(pos_, 14) + i * 1)
|
||||
def inventory_length():
|
||||
return buf_.flatbuffers_field_vector_len(pos_, 14)
|
||||
def color():
|
||||
return Color(buf_.flatbuffers_field_int8(pos_, 16, 2))
|
||||
def weapons(i:int):
|
||||
return MyGame_Sample_Weapon { buf_, buf_.flatbuffers_indirect(buf_.flatbuffers_field_vector(pos_, 18) + i * 4) }
|
||||
def weapons_length():
|
||||
return buf_.flatbuffers_field_vector_len(pos_, 18)
|
||||
def equipped_type():
|
||||
return Equipment(buf_.flatbuffers_field_int8(pos_, 20, 0))
|
||||
class Monster : flatbuffers.handle
|
||||
def pos() -> MyGame.Sample.Vec3?:
|
||||
let o = flatbuffers.field_struct(buf_, pos_, 4)
|
||||
return if o: MyGame.Sample.Vec3 { buf_, o } else: nil
|
||||
def mana() -> int:
|
||||
return flatbuffers.field_int16(buf_, pos_, 6, 150)
|
||||
def hp() -> int:
|
||||
return flatbuffers.field_int16(buf_, pos_, 8, 100)
|
||||
def name() -> string:
|
||||
return flatbuffers.field_string(buf_, pos_, 10)
|
||||
def inventory(i:int) -> int:
|
||||
return read_uint8_le(buf_, buf_.flatbuffers.field_vector(pos_, 14) + i * 1)
|
||||
def inventory_length() -> int:
|
||||
return flatbuffers.field_vector_len(buf_, pos_, 14)
|
||||
def color() -> Color:
|
||||
return Color(flatbuffers.field_int8(buf_, pos_, 16, 2))
|
||||
def weapons(i:int) -> MyGame.Sample.Weapon:
|
||||
return MyGame.Sample.Weapon { buf_, flatbuffers.indirect(buf_, flatbuffers.field_vector(buf_, pos_, 18) + i * 4) }
|
||||
def weapons_length() -> int:
|
||||
return flatbuffers.field_vector_len(buf_, pos_, 18)
|
||||
def equipped_type() -> Equipment:
|
||||
return Equipment(flatbuffers.field_uint8(buf_, pos_, 20, 0))
|
||||
def equipped_as_Weapon():
|
||||
return MyGame_Sample_Weapon { buf_, buf_.flatbuffers_field_table(pos_, 22) }
|
||||
def path(i:int):
|
||||
return MyGame_Sample_Vec3 { buf_, buf_.flatbuffers_field_vector(pos_, 24) + i * 12 }
|
||||
def path_length():
|
||||
return buf_.flatbuffers_field_vector_len(pos_, 24)
|
||||
return MyGame.Sample.Weapon { buf_, flatbuffers.field_table(buf_, pos_, 22) }
|
||||
def path(i:int) -> MyGame.Sample.Vec3:
|
||||
return MyGame.Sample.Vec3 { buf_, flatbuffers.field_vector(buf_, pos_, 24) + i * 12 }
|
||||
def path_length() -> int:
|
||||
return flatbuffers.field_vector_len(buf_, pos_, 24)
|
||||
|
||||
def GetRootAsMonster(buf:string): return Monster { buf, buf.flatbuffers_indirect(0) }
|
||||
def GetRootAsMonster(buf:string): return Monster { buf, flatbuffers.indirect(buf, 0) }
|
||||
|
||||
struct MonsterBuilder:
|
||||
b_:flatbuffers_builder
|
||||
b_:flatbuffers.builder
|
||||
def start():
|
||||
b_.StartObject(11)
|
||||
return this
|
||||
def add_pos(pos:flatbuffers_offset):
|
||||
def add_pos(pos:flatbuffers.offset):
|
||||
b_.PrependStructSlot(0, pos)
|
||||
return this
|
||||
def add_mana(mana:int):
|
||||
@@ -78,61 +78,61 @@ struct MonsterBuilder:
|
||||
def add_hp(hp:int):
|
||||
b_.PrependInt16Slot(2, hp, 100)
|
||||
return this
|
||||
def add_name(name:flatbuffers_offset):
|
||||
def add_name(name:flatbuffers.offset):
|
||||
b_.PrependUOffsetTRelativeSlot(3, name)
|
||||
return this
|
||||
def add_inventory(inventory:flatbuffers_offset):
|
||||
def add_inventory(inventory:flatbuffers.offset):
|
||||
b_.PrependUOffsetTRelativeSlot(5, inventory)
|
||||
return this
|
||||
def add_color(color:Color):
|
||||
b_.PrependInt8Slot(6, color, 2)
|
||||
return this
|
||||
def add_weapons(weapons:flatbuffers_offset):
|
||||
def add_weapons(weapons:flatbuffers.offset):
|
||||
b_.PrependUOffsetTRelativeSlot(7, weapons)
|
||||
return this
|
||||
def add_equipped_type(equipped_type:Equipment):
|
||||
b_.PrependUint8Slot(8, equipped_type, 0)
|
||||
return this
|
||||
def add_equipped(equipped:flatbuffers_offset):
|
||||
def add_equipped(equipped:flatbuffers.offset):
|
||||
b_.PrependUOffsetTRelativeSlot(9, equipped)
|
||||
return this
|
||||
def add_path(path:flatbuffers_offset):
|
||||
def add_path(path:flatbuffers.offset):
|
||||
b_.PrependUOffsetTRelativeSlot(10, path)
|
||||
return this
|
||||
def end():
|
||||
return b_.EndObject()
|
||||
|
||||
def MonsterStartInventoryVector(b_:flatbuffers_builder, n_:int):
|
||||
def MonsterStartInventoryVector(b_:flatbuffers.builder, n_:int):
|
||||
b_.StartVector(1, n_, 1)
|
||||
def MonsterCreateInventoryVector(b_:flatbuffers_builder, v_:[int]):
|
||||
def MonsterCreateInventoryVector(b_:flatbuffers.builder, v_:[int]):
|
||||
b_.StartVector(1, v_.length, 1)
|
||||
reverse(v_) e_: b_.PrependUint8(e_)
|
||||
return b_.EndVector(v_.length)
|
||||
|
||||
def MonsterStartWeaponsVector(b_:flatbuffers_builder, n_:int):
|
||||
def MonsterStartWeaponsVector(b_:flatbuffers.builder, n_:int):
|
||||
b_.StartVector(4, n_, 4)
|
||||
def MonsterCreateWeaponsVector(b_:flatbuffers_builder, v_:[flatbuffers_offset]):
|
||||
def MonsterCreateWeaponsVector(b_:flatbuffers.builder, v_:[flatbuffers.offset]):
|
||||
b_.StartVector(4, v_.length, 4)
|
||||
reverse(v_) e_: b_.PrependUOffsetTRelative(e_)
|
||||
return b_.EndVector(v_.length)
|
||||
|
||||
def MonsterStartPathVector(b_:flatbuffers_builder, n_:int):
|
||||
def MonsterStartPathVector(b_:flatbuffers.builder, n_:int):
|
||||
b_.StartVector(12, n_, 4)
|
||||
|
||||
class Weapon : flatbuffers_handle
|
||||
def name():
|
||||
return buf_.flatbuffers_field_string(pos_, 4)
|
||||
def damage():
|
||||
return buf_.flatbuffers_field_int16(pos_, 6, 0)
|
||||
class Weapon : flatbuffers.handle
|
||||
def name() -> string:
|
||||
return flatbuffers.field_string(buf_, pos_, 4)
|
||||
def damage() -> int:
|
||||
return flatbuffers.field_int16(buf_, pos_, 6, 0)
|
||||
|
||||
def GetRootAsWeapon(buf:string): return Weapon { buf, buf.flatbuffers_indirect(0) }
|
||||
def GetRootAsWeapon(buf:string): return Weapon { buf, flatbuffers.indirect(buf, 0) }
|
||||
|
||||
struct WeaponBuilder:
|
||||
b_:flatbuffers_builder
|
||||
b_:flatbuffers.builder
|
||||
def start():
|
||||
b_.StartObject(2)
|
||||
return this
|
||||
def add_name(name:flatbuffers_offset):
|
||||
def add_name(name:flatbuffers.offset):
|
||||
b_.PrependUOffsetTRelativeSlot(0, name)
|
||||
return this
|
||||
def add_damage(damage:int):
|
||||
|
||||
@@ -1,507 +0,0 @@
|
||||
// automatically generated by the FlatBuffers compiler, do not modify
|
||||
|
||||
|
||||
pub mod my_game {
|
||||
#![allow(dead_code)]
|
||||
#![allow(unused_imports)]
|
||||
|
||||
use std::mem;
|
||||
use std::marker::PhantomData;
|
||||
use std::cmp::Ordering;
|
||||
|
||||
extern crate flatbuffers;
|
||||
use self::flatbuffers::EndianScalar;
|
||||
pub mod sample {
|
||||
#![allow(dead_code)]
|
||||
#![allow(unused_imports)]
|
||||
|
||||
use std::mem;
|
||||
use std::marker::PhantomData;
|
||||
use std::cmp::Ordering;
|
||||
|
||||
extern crate flatbuffers;
|
||||
use self::flatbuffers::EndianScalar;
|
||||
|
||||
#[allow(non_camel_case_types)]
|
||||
#[repr(i8)]
|
||||
#[derive(Clone, Copy, PartialEq, Debug)]
|
||||
pub enum Color {
|
||||
Red = 0,
|
||||
Green = 1,
|
||||
Blue = 2
|
||||
}
|
||||
|
||||
const ENUM_MIN_COLOR: i8 = 0;
|
||||
const ENUM_MAX_COLOR: i8 = 2;
|
||||
|
||||
impl<'a> flatbuffers::Follow<'a> for Color {
|
||||
type Inner = Self;
|
||||
#[inline]
|
||||
fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
flatbuffers::read_scalar_at::<Self>(buf, loc)
|
||||
}
|
||||
}
|
||||
|
||||
impl flatbuffers::EndianScalar for Color {
|
||||
#[inline]
|
||||
fn to_little_endian(self) -> Self {
|
||||
let n = i8::to_le(self as i8);
|
||||
let p = &n as *const i8 as *const Color;
|
||||
unsafe { *p }
|
||||
}
|
||||
#[inline]
|
||||
fn from_little_endian(self) -> Self {
|
||||
let n = i8::from_le(self as i8);
|
||||
let p = &n as *const i8 as *const Color;
|
||||
unsafe { *p }
|
||||
}
|
||||
}
|
||||
|
||||
impl flatbuffers::Push for Color {
|
||||
type Output = Color;
|
||||
#[inline]
|
||||
fn push(&self, dst: &mut [u8], _rest: &[u8]) {
|
||||
flatbuffers::emplace_scalar::<Color>(dst, *self);
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(non_camel_case_types)]
|
||||
const ENUM_VALUES_COLOR:[Color; 3] = [
|
||||
Color::Red,
|
||||
Color::Green,
|
||||
Color::Blue
|
||||
];
|
||||
|
||||
#[allow(non_camel_case_types)]
|
||||
const ENUM_NAMES_COLOR:[&'static str; 3] = [
|
||||
"Red",
|
||||
"Green",
|
||||
"Blue"
|
||||
];
|
||||
|
||||
pub fn enum_name_color(e: Color) -> &'static str {
|
||||
let index: usize = e as usize;
|
||||
ENUM_NAMES_COLOR[index]
|
||||
}
|
||||
|
||||
#[allow(non_camel_case_types)]
|
||||
#[repr(u8)]
|
||||
#[derive(Clone, Copy, PartialEq, Debug)]
|
||||
pub enum Equipment {
|
||||
NONE = 0,
|
||||
Weapon = 1
|
||||
}
|
||||
|
||||
const ENUM_MIN_EQUIPMENT: u8 = 0;
|
||||
const ENUM_MAX_EQUIPMENT: u8 = 1;
|
||||
|
||||
impl<'a> flatbuffers::Follow<'a> for Equipment {
|
||||
type Inner = Self;
|
||||
#[inline]
|
||||
fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
flatbuffers::read_scalar_at::<Self>(buf, loc)
|
||||
}
|
||||
}
|
||||
|
||||
impl flatbuffers::EndianScalar for Equipment {
|
||||
#[inline]
|
||||
fn to_little_endian(self) -> Self {
|
||||
let n = u8::to_le(self as u8);
|
||||
let p = &n as *const u8 as *const Equipment;
|
||||
unsafe { *p }
|
||||
}
|
||||
#[inline]
|
||||
fn from_little_endian(self) -> Self {
|
||||
let n = u8::from_le(self as u8);
|
||||
let p = &n as *const u8 as *const Equipment;
|
||||
unsafe { *p }
|
||||
}
|
||||
}
|
||||
|
||||
impl flatbuffers::Push for Equipment {
|
||||
type Output = Equipment;
|
||||
#[inline]
|
||||
fn push(&self, dst: &mut [u8], _rest: &[u8]) {
|
||||
flatbuffers::emplace_scalar::<Equipment>(dst, *self);
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(non_camel_case_types)]
|
||||
const ENUM_VALUES_EQUIPMENT:[Equipment; 2] = [
|
||||
Equipment::NONE,
|
||||
Equipment::Weapon
|
||||
];
|
||||
|
||||
#[allow(non_camel_case_types)]
|
||||
const ENUM_NAMES_EQUIPMENT:[&'static str; 2] = [
|
||||
"NONE",
|
||||
"Weapon"
|
||||
];
|
||||
|
||||
pub fn enum_name_equipment(e: Equipment) -> &'static str {
|
||||
let index: usize = e as usize;
|
||||
ENUM_NAMES_EQUIPMENT[index]
|
||||
}
|
||||
|
||||
pub struct EquipmentUnionTableOffset {}
|
||||
// struct Vec3, aligned to 4
|
||||
#[repr(C, align(4))]
|
||||
#[derive(Clone, Copy, Debug, PartialEq)]
|
||||
pub struct Vec3 {
|
||||
x_: f32,
|
||||
y_: f32,
|
||||
z_: f32,
|
||||
} // pub struct Vec3
|
||||
impl flatbuffers::SafeSliceAccess for Vec3 {}
|
||||
impl<'a> flatbuffers::Follow<'a> for Vec3 {
|
||||
type Inner = &'a Vec3;
|
||||
#[inline]
|
||||
fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
<&'a Vec3>::follow(buf, loc)
|
||||
//flatbuffers::follow_cast_ref::<Vec3>(buf, loc)
|
||||
}
|
||||
}
|
||||
impl<'a> flatbuffers::Follow<'a> for &'a Vec3 {
|
||||
type Inner = &'a Vec3;
|
||||
#[inline]
|
||||
fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
flatbuffers::follow_cast_ref::<Vec3>(buf, loc)
|
||||
}
|
||||
}
|
||||
impl<'b> flatbuffers::Push for Vec3 {
|
||||
type Output = Vec3;
|
||||
#[inline]
|
||||
fn push(&self, dst: &mut [u8], _rest: &[u8]) {
|
||||
let src = unsafe {
|
||||
::std::slice::from_raw_parts(self as *const Vec3 as *const u8, Self::size())
|
||||
};
|
||||
dst.copy_from_slice(src);
|
||||
}
|
||||
}
|
||||
impl<'b> flatbuffers::Push for &'b Vec3 {
|
||||
type Output = Vec3;
|
||||
|
||||
#[inline]
|
||||
fn push(&self, dst: &mut [u8], _rest: &[u8]) {
|
||||
let src = unsafe {
|
||||
::std::slice::from_raw_parts(*self as *const Vec3 as *const u8, Self::size())
|
||||
};
|
||||
dst.copy_from_slice(src);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
impl Vec3 {
|
||||
pub fn new<'a>(_x: f32, _y: f32, _z: f32) -> Self {
|
||||
Vec3 {
|
||||
x_: _x.to_little_endian(),
|
||||
y_: _y.to_little_endian(),
|
||||
z_: _z.to_little_endian(),
|
||||
|
||||
}
|
||||
}
|
||||
pub fn x<'a>(&'a self) -> f32 {
|
||||
self.x_.from_little_endian()
|
||||
}
|
||||
pub fn y<'a>(&'a self) -> f32 {
|
||||
self.y_.from_little_endian()
|
||||
}
|
||||
pub fn z<'a>(&'a self) -> f32 {
|
||||
self.z_.from_little_endian()
|
||||
}
|
||||
}
|
||||
|
||||
pub enum MonsterOffset {}
|
||||
#[derive(Copy, Clone, Debug, PartialEq)]
|
||||
|
||||
pub struct Monster<'a> {
|
||||
pub _tab: flatbuffers::Table<'a>,
|
||||
}
|
||||
|
||||
impl<'a> flatbuffers::Follow<'a> for Monster<'a> {
|
||||
type Inner = Monster<'a>;
|
||||
#[inline]
|
||||
fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
Self {
|
||||
_tab: flatbuffers::Table { buf: buf, loc: loc },
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> Monster<'a> {
|
||||
#[inline]
|
||||
pub fn init_from_table(table: flatbuffers::Table<'a>) -> Self {
|
||||
Monster {
|
||||
_tab: table,
|
||||
}
|
||||
}
|
||||
#[allow(unused_mut)]
|
||||
pub fn create<'bldr: 'args, 'args: 'mut_bldr, 'mut_bldr>(
|
||||
_fbb: &'mut_bldr mut flatbuffers::FlatBufferBuilder<'bldr>,
|
||||
args: &'args MonsterArgs<'args>) -> flatbuffers::WIPOffset<Monster<'bldr>> {
|
||||
let mut builder = MonsterBuilder::new(_fbb);
|
||||
if let Some(x) = args.equipped { builder.add_equipped(x); }
|
||||
if let Some(x) = args.weapons { builder.add_weapons(x); }
|
||||
if let Some(x) = args.inventory { builder.add_inventory(x); }
|
||||
if let Some(x) = args.name { builder.add_name(x); }
|
||||
if let Some(x) = args.pos { builder.add_pos(x); }
|
||||
builder.add_hp(args.hp);
|
||||
builder.add_mana(args.mana);
|
||||
builder.add_equipped_type(args.equipped_type);
|
||||
builder.add_color(args.color);
|
||||
builder.finish()
|
||||
}
|
||||
|
||||
pub const VT_POS: flatbuffers::VOffsetT = 4;
|
||||
pub const VT_MANA: flatbuffers::VOffsetT = 6;
|
||||
pub const VT_HP: flatbuffers::VOffsetT = 8;
|
||||
pub const VT_NAME: flatbuffers::VOffsetT = 10;
|
||||
pub const VT_INVENTORY: flatbuffers::VOffsetT = 14;
|
||||
pub const VT_COLOR: flatbuffers::VOffsetT = 16;
|
||||
pub const VT_WEAPONS: flatbuffers::VOffsetT = 18;
|
||||
pub const VT_EQUIPPED_TYPE: flatbuffers::VOffsetT = 20;
|
||||
pub const VT_EQUIPPED: flatbuffers::VOffsetT = 22;
|
||||
|
||||
#[inline]
|
||||
pub fn pos(&'a self) -> Option<&'a Vec3> {
|
||||
self._tab.get::<Vec3>(Monster::VT_POS, None)
|
||||
}
|
||||
#[inline]
|
||||
pub fn mana(&'a self) -> i16 {
|
||||
self._tab.get::<i16>(Monster::VT_MANA, Some(150)).unwrap()
|
||||
}
|
||||
#[inline]
|
||||
pub fn hp(&'a self) -> i16 {
|
||||
self._tab.get::<i16>(Monster::VT_HP, Some(100)).unwrap()
|
||||
}
|
||||
#[inline]
|
||||
pub fn name(&'a self) -> Option<&'a str> {
|
||||
self._tab.get::<flatbuffers::ForwardsUOffset<&str>>(Monster::VT_NAME, None)
|
||||
}
|
||||
#[inline]
|
||||
pub fn inventory(&'a self) -> Option<&'a [u8]> {
|
||||
self._tab.get::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<'a, u8>>>(Monster::VT_INVENTORY, None).map(|v| v.safe_slice())
|
||||
}
|
||||
#[inline]
|
||||
pub fn color(&'a self) -> Color {
|
||||
self._tab.get::<Color>(Monster::VT_COLOR, Some(Color::Blue)).unwrap()
|
||||
}
|
||||
#[inline]
|
||||
pub fn weapons(&'a self) -> Option<flatbuffers::Vector<flatbuffers::ForwardsUOffset<Weapon<'a>>>> {
|
||||
self._tab.get::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<flatbuffers::ForwardsUOffset<Weapon<'a>>>>>(Monster::VT_WEAPONS, None)
|
||||
}
|
||||
#[inline]
|
||||
pub fn equipped_type(&'a self) -> Equipment {
|
||||
self._tab.get::<Equipment>(Monster::VT_EQUIPPED_TYPE, Some(Equipment::NONE)).unwrap()
|
||||
}
|
||||
#[inline]
|
||||
pub fn equipped(&'a self) -> Option<flatbuffers::Table<'a>> {
|
||||
self._tab.get::<flatbuffers::ForwardsUOffset<flatbuffers::Table<'a>>>(Monster::VT_EQUIPPED, None)
|
||||
}
|
||||
#[inline]
|
||||
#[allow(non_snake_case)]
|
||||
pub fn equipped_as_weapon(&'a self) -> Option<Weapon> {
|
||||
if self.equipped_type() == Equipment::Weapon {
|
||||
self.equipped().map(|u| Weapon::init_from_table(u))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
pub struct MonsterArgs<'a> {
|
||||
pub pos: Option<&'a Vec3>,
|
||||
pub mana: i16,
|
||||
pub hp: i16,
|
||||
pub name: Option<flatbuffers::WIPOffset<&'a str>>,
|
||||
pub inventory: Option<flatbuffers::WIPOffset<flatbuffers::Vector<'a , u8>>>,
|
||||
pub color: Color,
|
||||
pub weapons: Option<flatbuffers::WIPOffset<flatbuffers::Vector<'a , flatbuffers::ForwardsUOffset<Weapon<'a >>>>>,
|
||||
pub equipped_type: Equipment,
|
||||
pub equipped: Option<flatbuffers::WIPOffset<flatbuffers::UnionWIPOffset>>,
|
||||
}
|
||||
impl<'a> Default for MonsterArgs<'a> {
|
||||
#[inline]
|
||||
fn default() -> Self {
|
||||
MonsterArgs {
|
||||
pos: None,
|
||||
mana: 150,
|
||||
hp: 100,
|
||||
name: None,
|
||||
inventory: None,
|
||||
color: Color::Blue,
|
||||
weapons: None,
|
||||
equipped_type: Equipment::NONE,
|
||||
equipped: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
pub struct MonsterBuilder<'a: 'b, 'b> {
|
||||
fbb_: &'b mut flatbuffers::FlatBufferBuilder<'a>,
|
||||
start_: flatbuffers::WIPOffset<flatbuffers::TableUnfinishedWIPOffset>,
|
||||
}
|
||||
impl<'a: 'b, 'b> MonsterBuilder<'a, 'b> {
|
||||
#[inline]
|
||||
pub fn add_pos(&mut self, pos: &'b Vec3) {
|
||||
self.fbb_.push_slot_always::<&Vec3>(Monster::VT_POS, pos);
|
||||
}
|
||||
#[inline]
|
||||
pub fn add_mana(&mut self, mana: i16) {
|
||||
self.fbb_.push_slot::<i16>(Monster::VT_MANA, mana, 150);
|
||||
}
|
||||
#[inline]
|
||||
pub fn add_hp(&mut self, hp: i16) {
|
||||
self.fbb_.push_slot::<i16>(Monster::VT_HP, hp, 100);
|
||||
}
|
||||
#[inline]
|
||||
pub fn add_name(&mut self, name: flatbuffers::WIPOffset<&'b str>) {
|
||||
self.fbb_.push_slot_always::<flatbuffers::WIPOffset<_>>(Monster::VT_NAME, name);
|
||||
}
|
||||
#[inline]
|
||||
pub fn add_inventory(&mut self, inventory: flatbuffers::WIPOffset<flatbuffers::Vector<'b , u8>>) {
|
||||
self.fbb_.push_slot_always::<flatbuffers::WIPOffset<_>>(Monster::VT_INVENTORY, inventory);
|
||||
}
|
||||
#[inline]
|
||||
pub fn add_color(&mut self, color: Color) {
|
||||
self.fbb_.push_slot::<Color>(Monster::VT_COLOR, color, Color::Blue);
|
||||
}
|
||||
#[inline]
|
||||
pub fn add_weapons(&mut self, weapons: flatbuffers::WIPOffset<flatbuffers::Vector<'b , flatbuffers::ForwardsUOffset<Weapon<'b >>>>) {
|
||||
self.fbb_.push_slot_always::<flatbuffers::WIPOffset<_>>(Monster::VT_WEAPONS, weapons);
|
||||
}
|
||||
#[inline]
|
||||
pub fn add_equipped_type(&mut self, equipped_type: Equipment) {
|
||||
self.fbb_.push_slot::<Equipment>(Monster::VT_EQUIPPED_TYPE, equipped_type, Equipment::NONE);
|
||||
}
|
||||
#[inline]
|
||||
pub fn add_equipped(&mut self, equipped: flatbuffers::WIPOffset<flatbuffers::UnionWIPOffset>) {
|
||||
self.fbb_.push_slot_always::<flatbuffers::WIPOffset<_>>(Monster::VT_EQUIPPED, equipped);
|
||||
}
|
||||
#[inline]
|
||||
pub fn new(_fbb: &'b mut flatbuffers::FlatBufferBuilder<'a>) -> MonsterBuilder<'a, 'b> {
|
||||
let start = _fbb.start_table();
|
||||
MonsterBuilder {
|
||||
fbb_: _fbb,
|
||||
start_: start,
|
||||
}
|
||||
}
|
||||
#[inline]
|
||||
pub fn finish(self) -> flatbuffers::WIPOffset<Monster<'a>> {
|
||||
let o = self.fbb_.end_table(self.start_);
|
||||
flatbuffers::WIPOffset::new(o.value())
|
||||
}
|
||||
}
|
||||
|
||||
pub enum WeaponOffset {}
|
||||
#[derive(Copy, Clone, Debug, PartialEq)]
|
||||
|
||||
pub struct Weapon<'a> {
|
||||
pub _tab: flatbuffers::Table<'a>,
|
||||
}
|
||||
|
||||
impl<'a> flatbuffers::Follow<'a> for Weapon<'a> {
|
||||
type Inner = Weapon<'a>;
|
||||
#[inline]
|
||||
fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
Self {
|
||||
_tab: flatbuffers::Table { buf: buf, loc: loc },
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> Weapon<'a> {
|
||||
#[inline]
|
||||
pub fn init_from_table(table: flatbuffers::Table<'a>) -> Self {
|
||||
Weapon {
|
||||
_tab: table,
|
||||
}
|
||||
}
|
||||
#[allow(unused_mut)]
|
||||
pub fn create<'bldr: 'args, 'args: 'mut_bldr, 'mut_bldr>(
|
||||
_fbb: &'mut_bldr mut flatbuffers::FlatBufferBuilder<'bldr>,
|
||||
args: &'args WeaponArgs<'args>) -> flatbuffers::WIPOffset<Weapon<'bldr>> {
|
||||
let mut builder = WeaponBuilder::new(_fbb);
|
||||
if let Some(x) = args.name { builder.add_name(x); }
|
||||
builder.add_damage(args.damage);
|
||||
builder.finish()
|
||||
}
|
||||
|
||||
pub const VT_NAME: flatbuffers::VOffsetT = 4;
|
||||
pub const VT_DAMAGE: flatbuffers::VOffsetT = 6;
|
||||
|
||||
#[inline]
|
||||
pub fn name(&'a self) -> Option<&'a str> {
|
||||
self._tab.get::<flatbuffers::ForwardsUOffset<&str>>(Weapon::VT_NAME, None)
|
||||
}
|
||||
#[inline]
|
||||
pub fn damage(&'a self) -> i16 {
|
||||
self._tab.get::<i16>(Weapon::VT_DAMAGE, Some(0)).unwrap()
|
||||
}
|
||||
}
|
||||
|
||||
pub struct WeaponArgs<'a> {
|
||||
pub name: Option<flatbuffers::WIPOffset<&'a str>>,
|
||||
pub damage: i16,
|
||||
}
|
||||
impl<'a> Default for WeaponArgs<'a> {
|
||||
#[inline]
|
||||
fn default() -> Self {
|
||||
WeaponArgs {
|
||||
name: None,
|
||||
damage: 0,
|
||||
}
|
||||
}
|
||||
}
|
||||
pub struct WeaponBuilder<'a: 'b, 'b> {
|
||||
fbb_: &'b mut flatbuffers::FlatBufferBuilder<'a>,
|
||||
start_: flatbuffers::WIPOffset<flatbuffers::TableUnfinishedWIPOffset>,
|
||||
}
|
||||
impl<'a: 'b, 'b> WeaponBuilder<'a, 'b> {
|
||||
#[inline]
|
||||
pub fn add_name(&mut self, name: flatbuffers::WIPOffset<&'b str>) {
|
||||
self.fbb_.push_slot_always::<flatbuffers::WIPOffset<_>>(Weapon::VT_NAME, name);
|
||||
}
|
||||
#[inline]
|
||||
pub fn add_damage(&mut self, damage: i16) {
|
||||
self.fbb_.push_slot::<i16>(Weapon::VT_DAMAGE, damage, 0);
|
||||
}
|
||||
#[inline]
|
||||
pub fn new(_fbb: &'b mut flatbuffers::FlatBufferBuilder<'a>) -> WeaponBuilder<'a, 'b> {
|
||||
let start = _fbb.start_table();
|
||||
WeaponBuilder {
|
||||
fbb_: _fbb,
|
||||
start_: start,
|
||||
}
|
||||
}
|
||||
#[inline]
|
||||
pub fn finish(self) -> flatbuffers::WIPOffset<Weapon<'a>> {
|
||||
let o = self.fbb_.end_table(self.start_);
|
||||
flatbuffers::WIPOffset::new(o.value())
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn get_root_as_monster<'a>(buf: &'a [u8]) -> Monster<'a> {
|
||||
flatbuffers::get_root::<Monster<'a>>(buf)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn get_size_prefixed_root_as_monster<'a>(buf: &'a [u8]) -> Monster<'a> {
|
||||
flatbuffers::get_size_prefixed_root::<Monster<'a>>(buf)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn finish_monster_buffer<'a, 'b>(
|
||||
fbb: &'b mut flatbuffers::FlatBufferBuilder<'a>,
|
||||
root: flatbuffers::WIPOffset<Monster<'a>>) {
|
||||
fbb.finish(root, None);
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn finish_size_prefixed_monster_buffer<'a, 'b>(fbb: &'b mut flatbuffers::FlatBufferBuilder<'a>, root: flatbuffers::WIPOffset<Monster<'a>>) {
|
||||
fbb.finish_size_prefixed(root, None);
|
||||
}
|
||||
} // pub mod Sample
|
||||
} // pub mod MyGame
|
||||
|
||||
@@ -0,0 +1,243 @@
|
||||
// automatically generated by the FlatBuffers compiler, do not modify
|
||||
// swiftlint:disable all
|
||||
// swiftformat:disable all
|
||||
|
||||
import FlatBuffers
|
||||
|
||||
public enum MyGame_Sample_Color: Int8, Enum, Verifiable {
|
||||
public typealias T = Int8
|
||||
public static var byteSize: Int { return MemoryLayout<Int8>.size }
|
||||
public var value: Int8 { return self.rawValue }
|
||||
case red = 0
|
||||
case green = 1
|
||||
case blue = 2
|
||||
|
||||
public static var max: MyGame_Sample_Color { return .blue }
|
||||
public static var min: MyGame_Sample_Color { return .red }
|
||||
}
|
||||
|
||||
|
||||
public enum MyGame_Sample_Equipment: UInt8, UnionEnum {
|
||||
public typealias T = UInt8
|
||||
|
||||
public init?(value: T) {
|
||||
self.init(rawValue: value)
|
||||
}
|
||||
|
||||
public static var byteSize: Int { return MemoryLayout<UInt8>.size }
|
||||
public var value: UInt8 { return self.rawValue }
|
||||
case none_ = 0
|
||||
case weapon = 1
|
||||
|
||||
public static var max: MyGame_Sample_Equipment { return .weapon }
|
||||
public static var min: MyGame_Sample_Equipment { return .none_ }
|
||||
}
|
||||
|
||||
|
||||
public struct MyGame_Sample_Vec3: NativeStruct, Verifiable, FlatbuffersInitializable {
|
||||
|
||||
static func validateVersion() { FlatBuffersVersion_24_3_25() }
|
||||
|
||||
private var _x: Float32
|
||||
private var _y: Float32
|
||||
private var _z: Float32
|
||||
|
||||
public init(_ bb: ByteBuffer, o: Int32) {
|
||||
let _accessor = Struct(bb: bb, position: o)
|
||||
_x = _accessor.readBuffer(of: Float32.self, at: 0)
|
||||
_y = _accessor.readBuffer(of: Float32.self, at: 4)
|
||||
_z = _accessor.readBuffer(of: Float32.self, at: 8)
|
||||
}
|
||||
|
||||
public init(x: Float32, y: Float32, z: Float32) {
|
||||
_x = x
|
||||
_y = y
|
||||
_z = z
|
||||
}
|
||||
|
||||
public init() {
|
||||
_x = 0.0
|
||||
_y = 0.0
|
||||
_z = 0.0
|
||||
}
|
||||
|
||||
public var x: Float32 { _x }
|
||||
public var y: Float32 { _y }
|
||||
public var z: Float32 { _z }
|
||||
|
||||
public static func verify<T>(_ verifier: inout Verifier, at position: Int, of type: T.Type) throws where T: Verifiable {
|
||||
try verifier.inBuffer(position: position, of: MyGame_Sample_Vec3.self)
|
||||
}
|
||||
}
|
||||
|
||||
public struct MyGame_Sample_Vec3_Mutable: FlatBufferObject {
|
||||
|
||||
static func validateVersion() { FlatBuffersVersion_24_3_25() }
|
||||
public var __buffer: ByteBuffer! { return _accessor.bb }
|
||||
private var _accessor: Struct
|
||||
|
||||
public init(_ bb: ByteBuffer, o: Int32) { _accessor = Struct(bb: bb, position: o) }
|
||||
|
||||
public var x: Float32 { return _accessor.readBuffer(of: Float32.self, at: 0) }
|
||||
@discardableResult public func mutate(x: Float32) -> Bool { return _accessor.mutate(x, index: 0) }
|
||||
public var y: Float32 { return _accessor.readBuffer(of: Float32.self, at: 4) }
|
||||
@discardableResult public func mutate(y: Float32) -> Bool { return _accessor.mutate(y, index: 4) }
|
||||
public var z: Float32 { return _accessor.readBuffer(of: Float32.self, at: 8) }
|
||||
@discardableResult public func mutate(z: Float32) -> Bool { return _accessor.mutate(z, index: 8) }
|
||||
}
|
||||
|
||||
public struct MyGame_Sample_Monster: FlatBufferObject, Verifiable {
|
||||
|
||||
static func validateVersion() { FlatBuffersVersion_24_3_25() }
|
||||
public var __buffer: ByteBuffer! { return _accessor.bb }
|
||||
private var _accessor: Table
|
||||
|
||||
private init(_ t: Table) { _accessor = t }
|
||||
public init(_ bb: ByteBuffer, o: Int32) { _accessor = Table(bb: bb, position: o) }
|
||||
|
||||
private enum VTOFFSET: VOffset {
|
||||
case pos = 4
|
||||
case mana = 6
|
||||
case hp = 8
|
||||
case name = 10
|
||||
case inventory = 14
|
||||
case color = 16
|
||||
case weapons = 18
|
||||
case equippedType = 20
|
||||
case equipped = 22
|
||||
case path = 24
|
||||
var v: Int32 { Int32(self.rawValue) }
|
||||
var p: VOffset { self.rawValue }
|
||||
}
|
||||
|
||||
public var pos: MyGame_Sample_Vec3? { let o = _accessor.offset(VTOFFSET.pos.v); return o == 0 ? nil : _accessor.readBuffer(of: MyGame_Sample_Vec3.self, at: o) }
|
||||
public var mutablePos: MyGame_Sample_Vec3_Mutable? { let o = _accessor.offset(VTOFFSET.pos.v); return o == 0 ? nil : MyGame_Sample_Vec3_Mutable(_accessor.bb, o: o + _accessor.postion) }
|
||||
public var mana: Int16 { let o = _accessor.offset(VTOFFSET.mana.v); return o == 0 ? 150 : _accessor.readBuffer(of: Int16.self, at: o) }
|
||||
@discardableResult public func mutate(mana: Int16) -> Bool {let o = _accessor.offset(VTOFFSET.mana.v); return _accessor.mutate(mana, index: o) }
|
||||
public var hp: Int16 { let o = _accessor.offset(VTOFFSET.hp.v); return o == 0 ? 100 : _accessor.readBuffer(of: Int16.self, at: o) }
|
||||
@discardableResult public func mutate(hp: Int16) -> Bool {let o = _accessor.offset(VTOFFSET.hp.v); return _accessor.mutate(hp, index: o) }
|
||||
public var name: String? { let o = _accessor.offset(VTOFFSET.name.v); return o == 0 ? nil : _accessor.string(at: o) }
|
||||
public var nameSegmentArray: [UInt8]? { return _accessor.getVector(at: VTOFFSET.name.v) }
|
||||
public var hasInventory: Bool { let o = _accessor.offset(VTOFFSET.inventory.v); return o == 0 ? false : true }
|
||||
public var inventoryCount: Int32 { let o = _accessor.offset(VTOFFSET.inventory.v); return o == 0 ? 0 : _accessor.vector(count: o) }
|
||||
public func inventory(at index: Int32) -> UInt8 { let o = _accessor.offset(VTOFFSET.inventory.v); return o == 0 ? 0 : _accessor.directRead(of: UInt8.self, offset: _accessor.vector(at: o) + index * 1) }
|
||||
public var inventory: [UInt8] { return _accessor.getVector(at: VTOFFSET.inventory.v) ?? [] }
|
||||
public func mutate(inventory: UInt8, at index: Int32) -> Bool { let o = _accessor.offset(VTOFFSET.inventory.v); return _accessor.directMutate(inventory, index: _accessor.vector(at: o) + index * 1) }
|
||||
public var color: MyGame_Sample_Color { let o = _accessor.offset(VTOFFSET.color.v); return o == 0 ? .blue : MyGame_Sample_Color(rawValue: _accessor.readBuffer(of: Int8.self, at: o)) ?? .blue }
|
||||
@discardableResult public func mutate(color: MyGame_Sample_Color) -> Bool {let o = _accessor.offset(VTOFFSET.color.v); return _accessor.mutate(color.rawValue, index: o) }
|
||||
public var hasWeapons: Bool { let o = _accessor.offset(VTOFFSET.weapons.v); return o == 0 ? false : true }
|
||||
public var weaponsCount: Int32 { let o = _accessor.offset(VTOFFSET.weapons.v); return o == 0 ? 0 : _accessor.vector(count: o) }
|
||||
public func weapons(at index: Int32) -> MyGame_Sample_Weapon? { let o = _accessor.offset(VTOFFSET.weapons.v); return o == 0 ? nil : MyGame_Sample_Weapon(_accessor.bb, o: _accessor.indirect(_accessor.vector(at: o) + index * 4)) }
|
||||
public var equippedType: MyGame_Sample_Equipment { let o = _accessor.offset(VTOFFSET.equippedType.v); return o == 0 ? .none_ : MyGame_Sample_Equipment(rawValue: _accessor.readBuffer(of: UInt8.self, at: o)) ?? .none_ }
|
||||
public func equipped<T: FlatbuffersInitializable>(type: T.Type) -> T? { let o = _accessor.offset(VTOFFSET.equipped.v); return o == 0 ? nil : _accessor.union(o) }
|
||||
public var hasPath: Bool { let o = _accessor.offset(VTOFFSET.path.v); return o == 0 ? false : true }
|
||||
public var pathCount: Int32 { let o = _accessor.offset(VTOFFSET.path.v); return o == 0 ? 0 : _accessor.vector(count: o) }
|
||||
public func path(at index: Int32) -> MyGame_Sample_Vec3? { let o = _accessor.offset(VTOFFSET.path.v); return o == 0 ? nil : _accessor.directRead(of: MyGame_Sample_Vec3.self, offset: _accessor.vector(at: o) + index * 12) }
|
||||
public func mutablePath(at index: Int32) -> MyGame_Sample_Vec3_Mutable? { let o = _accessor.offset(VTOFFSET.path.v); return o == 0 ? nil : MyGame_Sample_Vec3_Mutable(_accessor.bb, o: _accessor.vector(at: o) + index * 12) }
|
||||
public static func startMonster(_ fbb: inout FlatBufferBuilder) -> UOffset { fbb.startTable(with: 11) }
|
||||
public static func add(pos: MyGame_Sample_Vec3?, _ fbb: inout FlatBufferBuilder) { guard let pos = pos else { return }; fbb.create(struct: pos, position: VTOFFSET.pos.p) }
|
||||
public static func add(mana: Int16, _ fbb: inout FlatBufferBuilder) { fbb.add(element: mana, def: 150, at: VTOFFSET.mana.p) }
|
||||
public static func add(hp: Int16, _ fbb: inout FlatBufferBuilder) { fbb.add(element: hp, def: 100, at: VTOFFSET.hp.p) }
|
||||
public static func add(name: Offset, _ fbb: inout FlatBufferBuilder) { fbb.add(offset: name, at: VTOFFSET.name.p) }
|
||||
public static func addVectorOf(inventory: Offset, _ fbb: inout FlatBufferBuilder) { fbb.add(offset: inventory, at: VTOFFSET.inventory.p) }
|
||||
public static func add(color: MyGame_Sample_Color, _ fbb: inout FlatBufferBuilder) { fbb.add(element: color.rawValue, def: 2, at: VTOFFSET.color.p) }
|
||||
public static func addVectorOf(weapons: Offset, _ fbb: inout FlatBufferBuilder) { fbb.add(offset: weapons, at: VTOFFSET.weapons.p) }
|
||||
public static func add(equippedType: MyGame_Sample_Equipment, _ fbb: inout FlatBufferBuilder) { fbb.add(element: equippedType.rawValue, def: 0, at: VTOFFSET.equippedType.p) }
|
||||
public static func add(equipped: Offset, _ fbb: inout FlatBufferBuilder) { fbb.add(offset: equipped, at: VTOFFSET.equipped.p) }
|
||||
public static func addVectorOf(path: Offset, _ fbb: inout FlatBufferBuilder) { fbb.add(offset: path, at: VTOFFSET.path.p) }
|
||||
public static func startVectorOfPath(_ size: Int, in builder: inout FlatBufferBuilder) {
|
||||
builder.startVector(size * MemoryLayout<MyGame_Sample_Vec3>.size, elementSize: MemoryLayout<MyGame_Sample_Vec3>.alignment)
|
||||
}
|
||||
public static func endMonster(_ fbb: inout FlatBufferBuilder, start: UOffset) -> Offset { let end = Offset(offset: fbb.endTable(at: start)); return end }
|
||||
public static func createMonster(
|
||||
_ fbb: inout FlatBufferBuilder,
|
||||
pos: MyGame_Sample_Vec3? = nil,
|
||||
mana: Int16 = 150,
|
||||
hp: Int16 = 100,
|
||||
nameOffset name: Offset = Offset(),
|
||||
inventoryVectorOffset inventory: Offset = Offset(),
|
||||
color: MyGame_Sample_Color = .blue,
|
||||
weaponsVectorOffset weapons: Offset = Offset(),
|
||||
equippedType: MyGame_Sample_Equipment = .none_,
|
||||
equippedOffset equipped: Offset = Offset(),
|
||||
pathVectorOffset path: Offset = Offset()
|
||||
) -> Offset {
|
||||
let __start = MyGame_Sample_Monster.startMonster(&fbb)
|
||||
MyGame_Sample_Monster.add(pos: pos, &fbb)
|
||||
MyGame_Sample_Monster.add(mana: mana, &fbb)
|
||||
MyGame_Sample_Monster.add(hp: hp, &fbb)
|
||||
MyGame_Sample_Monster.add(name: name, &fbb)
|
||||
MyGame_Sample_Monster.addVectorOf(inventory: inventory, &fbb)
|
||||
MyGame_Sample_Monster.add(color: color, &fbb)
|
||||
MyGame_Sample_Monster.addVectorOf(weapons: weapons, &fbb)
|
||||
MyGame_Sample_Monster.add(equippedType: equippedType, &fbb)
|
||||
MyGame_Sample_Monster.add(equipped: equipped, &fbb)
|
||||
MyGame_Sample_Monster.addVectorOf(path: path, &fbb)
|
||||
return MyGame_Sample_Monster.endMonster(&fbb, start: __start)
|
||||
}
|
||||
|
||||
public static func verify<T>(_ verifier: inout Verifier, at position: Int, of type: T.Type) throws where T: Verifiable {
|
||||
var _v = try verifier.visitTable(at: position)
|
||||
try _v.visit(field: VTOFFSET.pos.p, fieldName: "pos", required: false, type: MyGame_Sample_Vec3.self)
|
||||
try _v.visit(field: VTOFFSET.mana.p, fieldName: "mana", required: false, type: Int16.self)
|
||||
try _v.visit(field: VTOFFSET.hp.p, fieldName: "hp", required: false, type: Int16.self)
|
||||
try _v.visit(field: VTOFFSET.name.p, fieldName: "name", required: false, type: ForwardOffset<String>.self)
|
||||
try _v.visit(field: VTOFFSET.inventory.p, fieldName: "inventory", required: false, type: ForwardOffset<Vector<UInt8, UInt8>>.self)
|
||||
try _v.visit(field: VTOFFSET.color.p, fieldName: "color", required: false, type: MyGame_Sample_Color.self)
|
||||
try _v.visit(field: VTOFFSET.weapons.p, fieldName: "weapons", required: false, type: ForwardOffset<Vector<ForwardOffset<MyGame_Sample_Weapon>, MyGame_Sample_Weapon>>.self)
|
||||
try _v.visit(unionKey: VTOFFSET.equippedType.p, unionField: VTOFFSET.equipped.p, unionKeyName: "equippedType", fieldName: "equipped", required: false, completion: { (verifier, key: MyGame_Sample_Equipment, pos) in
|
||||
switch key {
|
||||
case .none_:
|
||||
break // NOTE - SWIFT doesnt support none
|
||||
case .weapon:
|
||||
try ForwardOffset<MyGame_Sample_Weapon>.verify(&verifier, at: pos, of: MyGame_Sample_Weapon.self)
|
||||
}
|
||||
})
|
||||
try _v.visit(field: VTOFFSET.path.p, fieldName: "path", required: false, type: ForwardOffset<Vector<MyGame_Sample_Vec3, MyGame_Sample_Vec3>>.self)
|
||||
_v.finish()
|
||||
}
|
||||
}
|
||||
|
||||
public struct MyGame_Sample_Weapon: FlatBufferObject, Verifiable {
|
||||
|
||||
static func validateVersion() { FlatBuffersVersion_24_3_25() }
|
||||
public var __buffer: ByteBuffer! { return _accessor.bb }
|
||||
private var _accessor: Table
|
||||
|
||||
private init(_ t: Table) { _accessor = t }
|
||||
public init(_ bb: ByteBuffer, o: Int32) { _accessor = Table(bb: bb, position: o) }
|
||||
|
||||
private enum VTOFFSET: VOffset {
|
||||
case name = 4
|
||||
case damage = 6
|
||||
var v: Int32 { Int32(self.rawValue) }
|
||||
var p: VOffset { self.rawValue }
|
||||
}
|
||||
|
||||
public var name: String? { let o = _accessor.offset(VTOFFSET.name.v); return o == 0 ? nil : _accessor.string(at: o) }
|
||||
public var nameSegmentArray: [UInt8]? { return _accessor.getVector(at: VTOFFSET.name.v) }
|
||||
public var damage: Int16 { let o = _accessor.offset(VTOFFSET.damage.v); return o == 0 ? 0 : _accessor.readBuffer(of: Int16.self, at: o) }
|
||||
@discardableResult public func mutate(damage: Int16) -> Bool {let o = _accessor.offset(VTOFFSET.damage.v); return _accessor.mutate(damage, index: o) }
|
||||
public static func startWeapon(_ fbb: inout FlatBufferBuilder) -> UOffset { fbb.startTable(with: 2) }
|
||||
public static func add(name: Offset, _ fbb: inout FlatBufferBuilder) { fbb.add(offset: name, at: VTOFFSET.name.p) }
|
||||
public static func add(damage: Int16, _ fbb: inout FlatBufferBuilder) { fbb.add(element: damage, def: 0, at: VTOFFSET.damage.p) }
|
||||
public static func endWeapon(_ fbb: inout FlatBufferBuilder, start: UOffset) -> Offset { let end = Offset(offset: fbb.endTable(at: start)); return end }
|
||||
public static func createWeapon(
|
||||
_ fbb: inout FlatBufferBuilder,
|
||||
nameOffset name: Offset = Offset(),
|
||||
damage: Int16 = 0
|
||||
) -> Offset {
|
||||
let __start = MyGame_Sample_Weapon.startWeapon(&fbb)
|
||||
MyGame_Sample_Weapon.add(name: name, &fbb)
|
||||
MyGame_Sample_Weapon.add(damage: damage, &fbb)
|
||||
return MyGame_Sample_Weapon.endWeapon(&fbb, start: __start)
|
||||
}
|
||||
|
||||
public static func verify<T>(_ verifier: inout Verifier, at position: Int, of type: T.Type) throws where T: Verifiable {
|
||||
var _v = try verifier.visitTable(at: position)
|
||||
try _v.visit(field: VTOFFSET.name.p, fieldName: "name", required: false, type: ForwardOffset<String>.self)
|
||||
try _v.visit(field: VTOFFSET.damage.p, fieldName: "damage", required: false, type: Int16.self)
|
||||
_v.finish()
|
||||
}
|
||||
}
|
||||
|
||||
+15
-15
@@ -1,24 +1,24 @@
|
||||
{
|
||||
pos: {
|
||||
x: 1.0,
|
||||
y: 2.0,
|
||||
z: 3.0
|
||||
"pos": {
|
||||
"x": 1.0,
|
||||
"y": 2.0,
|
||||
"z": 3.0
|
||||
},
|
||||
hp: 300,
|
||||
name: "Orc",
|
||||
weapons: [
|
||||
"hp": 300,
|
||||
"name": "Orc",
|
||||
"weapons": [
|
||||
{
|
||||
name: "axe",
|
||||
damage: 100
|
||||
"name": "axe",
|
||||
"damage": 100
|
||||
},
|
||||
{
|
||||
name: "bow",
|
||||
damage: 90
|
||||
"name": "bow",
|
||||
"damage": 90
|
||||
}
|
||||
],
|
||||
equipped_type: "Weapon",
|
||||
equipped: {
|
||||
name: "bow",
|
||||
damage: 90
|
||||
"equipped_type": "Weapon",
|
||||
"equipped": {
|
||||
"name": "bow",
|
||||
"damage": 90
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
// Automatically generated by the Flatbuffers compiler. Do not modify.
|
||||
// @generated
|
||||
pub mod my_game {
|
||||
use super::*;
|
||||
pub mod sample {
|
||||
use super::*;
|
||||
mod color_generated;
|
||||
pub use self::color_generated::*;
|
||||
mod equipment_generated;
|
||||
pub use self::equipment_generated::*;
|
||||
mod vec_3_generated;
|
||||
pub use self::vec_3_generated::*;
|
||||
mod monster_generated;
|
||||
pub use self::monster_generated::*;
|
||||
mod weapon_generated;
|
||||
pub use self::weapon_generated::*;
|
||||
} // sample
|
||||
} // my_game
|
||||
+100
@@ -0,0 +1,100 @@
|
||||
// automatically generated by the FlatBuffers compiler, do not modify
|
||||
// @generated
|
||||
extern crate alloc;
|
||||
extern crate flatbuffers;
|
||||
use alloc::boxed::Box;
|
||||
use alloc::string::{String, ToString};
|
||||
use alloc::vec::Vec;
|
||||
use core::mem;
|
||||
use core::cmp::Ordering;
|
||||
use self::flatbuffers::{EndianScalar, Follow};
|
||||
use super::*;
|
||||
#[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")]
|
||||
pub const ENUM_MIN_COLOR: i8 = 0;
|
||||
#[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")]
|
||||
pub const ENUM_MAX_COLOR: 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_COLOR: [Color; 3] = [
|
||||
Color::Red,
|
||||
Color::Green,
|
||||
Color::Blue,
|
||||
];
|
||||
|
||||
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Default)]
|
||||
#[repr(transparent)]
|
||||
pub struct Color(pub i8);
|
||||
#[allow(non_upper_case_globals)]
|
||||
impl Color {
|
||||
pub const Red: Self = Self(0);
|
||||
pub const Green: Self = Self(1);
|
||||
pub const Blue: Self = Self(2);
|
||||
|
||||
pub const ENUM_MIN: i8 = 0;
|
||||
pub const ENUM_MAX: i8 = 2;
|
||||
pub const ENUM_VALUES: &'static [Self] = &[
|
||||
Self::Red,
|
||||
Self::Green,
|
||||
Self::Blue,
|
||||
];
|
||||
/// Returns the variant's name or "" if unknown.
|
||||
pub fn variant_name(self) -> Option<&'static str> {
|
||||
match self {
|
||||
Self::Red => Some("Red"),
|
||||
Self::Green => Some("Green"),
|
||||
Self::Blue => Some("Blue"),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
}
|
||||
impl core::fmt::Debug for Color {
|
||||
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 Color {
|
||||
type Inner = Self;
|
||||
#[inline]
|
||||
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
let b = flatbuffers::read_scalar_at::<i8>(buf, loc);
|
||||
Self(b)
|
||||
}
|
||||
}
|
||||
|
||||
impl flatbuffers::Push for Color {
|
||||
type Output = Color;
|
||||
#[inline]
|
||||
unsafe fn push(&self, dst: &mut [u8], _written_len: usize) {
|
||||
flatbuffers::emplace_scalar::<i8>(dst, self.0);
|
||||
}
|
||||
}
|
||||
|
||||
impl flatbuffers::EndianScalar for Color {
|
||||
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 Color {
|
||||
#[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 Color {}
|
||||
+145
@@ -0,0 +1,145 @@
|
||||
// automatically generated by the FlatBuffers compiler, do not modify
|
||||
// @generated
|
||||
extern crate alloc;
|
||||
extern crate flatbuffers;
|
||||
use alloc::boxed::Box;
|
||||
use alloc::string::{String, ToString};
|
||||
use alloc::vec::Vec;
|
||||
use core::mem;
|
||||
use core::cmp::Ordering;
|
||||
use self::flatbuffers::{EndianScalar, Follow};
|
||||
use super::*;
|
||||
#[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")]
|
||||
pub const ENUM_MIN_EQUIPMENT: u8 = 0;
|
||||
#[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")]
|
||||
pub const ENUM_MAX_EQUIPMENT: u8 = 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_EQUIPMENT: [Equipment; 2] = [
|
||||
Equipment::NONE,
|
||||
Equipment::Weapon,
|
||||
];
|
||||
|
||||
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Default)]
|
||||
#[repr(transparent)]
|
||||
pub struct Equipment(pub u8);
|
||||
#[allow(non_upper_case_globals)]
|
||||
impl Equipment {
|
||||
pub const NONE: Self = Self(0);
|
||||
pub const Weapon: Self = Self(1);
|
||||
|
||||
pub const ENUM_MIN: u8 = 0;
|
||||
pub const ENUM_MAX: u8 = 1;
|
||||
pub const ENUM_VALUES: &'static [Self] = &[
|
||||
Self::NONE,
|
||||
Self::Weapon,
|
||||
];
|
||||
/// Returns the variant's name or "" if unknown.
|
||||
pub fn variant_name(self) -> Option<&'static str> {
|
||||
match self {
|
||||
Self::NONE => Some("NONE"),
|
||||
Self::Weapon => Some("Weapon"),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
}
|
||||
impl core::fmt::Debug for Equipment {
|
||||
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 Equipment {
|
||||
type Inner = Self;
|
||||
#[inline]
|
||||
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
let b = flatbuffers::read_scalar_at::<u8>(buf, loc);
|
||||
Self(b)
|
||||
}
|
||||
}
|
||||
|
||||
impl flatbuffers::Push for Equipment {
|
||||
type Output = Equipment;
|
||||
#[inline]
|
||||
unsafe fn push(&self, dst: &mut [u8], _written_len: usize) {
|
||||
flatbuffers::emplace_scalar::<u8>(dst, self.0);
|
||||
}
|
||||
}
|
||||
|
||||
impl flatbuffers::EndianScalar for Equipment {
|
||||
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 Equipment {
|
||||
#[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 Equipment {}
|
||||
pub struct EquipmentUnionTableOffset {}
|
||||
|
||||
#[allow(clippy::upper_case_acronyms)]
|
||||
#[non_exhaustive]
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub enum EquipmentT {
|
||||
NONE,
|
||||
Weapon(Box<WeaponT>),
|
||||
}
|
||||
impl Default for EquipmentT {
|
||||
fn default() -> Self {
|
||||
Self::NONE
|
||||
}
|
||||
}
|
||||
impl EquipmentT {
|
||||
pub fn equipment_type(&self) -> Equipment {
|
||||
match self {
|
||||
Self::NONE => Equipment::NONE,
|
||||
Self::Weapon(_) => Equipment::Weapon,
|
||||
}
|
||||
}
|
||||
pub fn pack<'b, A: flatbuffers::Allocator + 'b>(&self, fbb: &mut flatbuffers::FlatBufferBuilder<'b, A>) -> Option<flatbuffers::WIPOffset<flatbuffers::UnionWIPOffset>> {
|
||||
match self {
|
||||
Self::NONE => None,
|
||||
Self::Weapon(v) => Some(v.pack(fbb).as_union_value()),
|
||||
}
|
||||
}
|
||||
/// If the union variant matches, return the owned WeaponT, setting the union to NONE.
|
||||
pub fn take_weapon(&mut self) -> Option<Box<WeaponT>> {
|
||||
if let Self::Weapon(_) = self {
|
||||
let v = core::mem::replace(self, Self::NONE);
|
||||
if let Self::Weapon(w) = v {
|
||||
Some(w)
|
||||
} else {
|
||||
unreachable!()
|
||||
}
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
/// If the union variant matches, return a reference to the WeaponT.
|
||||
pub fn as_weapon(&self) -> Option<&WeaponT> {
|
||||
if let Self::Weapon(v) = self { Some(v.as_ref()) } else { None }
|
||||
}
|
||||
/// If the union variant matches, return a mutable reference to the WeaponT.
|
||||
pub fn as_weapon_mut(&mut self) -> Option<&mut WeaponT> {
|
||||
if let Self::Weapon(v) = self { Some(v.as_mut()) } else { None }
|
||||
}
|
||||
}
|
||||
+473
@@ -0,0 +1,473 @@
|
||||
// automatically generated by the FlatBuffers compiler, do not modify
|
||||
// @generated
|
||||
extern crate alloc;
|
||||
extern crate flatbuffers;
|
||||
use alloc::boxed::Box;
|
||||
use alloc::string::{String, ToString};
|
||||
use alloc::vec::Vec;
|
||||
use core::mem;
|
||||
use core::cmp::Ordering;
|
||||
use self::flatbuffers::{EndianScalar, Follow};
|
||||
use super::*;
|
||||
pub enum MonsterOffset {}
|
||||
#[derive(Copy, Clone, PartialEq)]
|
||||
|
||||
pub struct Monster<'a> {
|
||||
pub _tab: flatbuffers::Table<'a>,
|
||||
}
|
||||
|
||||
impl<'a> flatbuffers::Follow<'a> for Monster<'a> {
|
||||
type Inner = Monster<'a>;
|
||||
#[inline]
|
||||
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
Self { _tab: flatbuffers::Table::new(buf, loc) }
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> Monster<'a> {
|
||||
pub const VT_POS: flatbuffers::VOffsetT = 4;
|
||||
pub const VT_MANA: flatbuffers::VOffsetT = 6;
|
||||
pub const VT_HP: flatbuffers::VOffsetT = 8;
|
||||
pub const VT_NAME: flatbuffers::VOffsetT = 10;
|
||||
pub const VT_INVENTORY: flatbuffers::VOffsetT = 14;
|
||||
pub const VT_COLOR: flatbuffers::VOffsetT = 16;
|
||||
pub const VT_WEAPONS: flatbuffers::VOffsetT = 18;
|
||||
pub const VT_EQUIPPED_TYPE: flatbuffers::VOffsetT = 20;
|
||||
pub const VT_EQUIPPED: flatbuffers::VOffsetT = 22;
|
||||
pub const VT_PATH: flatbuffers::VOffsetT = 24;
|
||||
|
||||
pub const fn get_fully_qualified_name() -> &'static str {
|
||||
"MyGame.Sample.Monster"
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub unsafe fn init_from_table(table: flatbuffers::Table<'a>) -> Self {
|
||||
Monster { _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 MonsterArgs<'args>
|
||||
) -> flatbuffers::WIPOffset<Monster<'bldr>> {
|
||||
let mut builder = MonsterBuilder::new(_fbb);
|
||||
if let Some(x) = args.path { builder.add_path(x); }
|
||||
if let Some(x) = args.equipped { builder.add_equipped(x); }
|
||||
if let Some(x) = args.weapons { builder.add_weapons(x); }
|
||||
if let Some(x) = args.inventory { builder.add_inventory(x); }
|
||||
if let Some(x) = args.name { builder.add_name(x); }
|
||||
if let Some(x) = args.pos { builder.add_pos(x); }
|
||||
builder.add_hp(args.hp);
|
||||
builder.add_mana(args.mana);
|
||||
builder.add_equipped_type(args.equipped_type);
|
||||
builder.add_color(args.color);
|
||||
builder.finish()
|
||||
}
|
||||
|
||||
pub fn unpack(&self) -> MonsterT {
|
||||
let pos = self.pos().map(|x| {
|
||||
x.unpack()
|
||||
});
|
||||
let mana = self.mana();
|
||||
let hp = self.hp();
|
||||
let name = self.name().map(|x| {
|
||||
x.to_string()
|
||||
});
|
||||
let inventory = self.inventory().map(|x| {
|
||||
x.into_iter().collect()
|
||||
});
|
||||
let color = self.color();
|
||||
let weapons = self.weapons().map(|x| {
|
||||
x.iter().map(|t| t.unpack()).collect()
|
||||
});
|
||||
let equipped = match self.equipped_type() {
|
||||
Equipment::NONE => EquipmentT::NONE,
|
||||
Equipment::Weapon => EquipmentT::Weapon(Box::new(
|
||||
self.equipped_as_weapon()
|
||||
.expect("Invalid union table, expected `Equipment::Weapon`.")
|
||||
.unpack()
|
||||
)),
|
||||
_ => EquipmentT::NONE,
|
||||
};
|
||||
let path = self.path().map(|x| {
|
||||
x.iter().map(|t| t.unpack()).collect()
|
||||
});
|
||||
MonsterT {
|
||||
pos,
|
||||
mana,
|
||||
hp,
|
||||
name,
|
||||
inventory,
|
||||
color,
|
||||
weapons,
|
||||
equipped,
|
||||
path,
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn pos(&self) -> Option<&'a Vec3> {
|
||||
// Safety:
|
||||
// Created from valid Table for this object
|
||||
// which contains a valid value in this slot
|
||||
unsafe { self._tab.get::<Vec3>(Monster::VT_POS, None)}
|
||||
}
|
||||
#[inline]
|
||||
pub fn mana(&self) -> i16 {
|
||||
// Safety:
|
||||
// Created from valid Table for this object
|
||||
// which contains a valid value in this slot
|
||||
unsafe { self._tab.get::<i16>(Monster::VT_MANA, Some(150)).unwrap()}
|
||||
}
|
||||
#[inline]
|
||||
pub fn hp(&self) -> i16 {
|
||||
// Safety:
|
||||
// Created from valid Table for this object
|
||||
// which contains a valid value in this slot
|
||||
unsafe { self._tab.get::<i16>(Monster::VT_HP, Some(100)).unwrap()}
|
||||
}
|
||||
#[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::<flatbuffers::ForwardsUOffset<&str>>(Monster::VT_NAME, None)}
|
||||
}
|
||||
#[inline]
|
||||
pub fn inventory(&self) -> Option<flatbuffers::Vector<'a, u8>> {
|
||||
// Safety:
|
||||
// Created from valid Table for this object
|
||||
// which contains a valid value in this slot
|
||||
unsafe { self._tab.get::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<'a, u8>>>(Monster::VT_INVENTORY, None)}
|
||||
}
|
||||
#[inline]
|
||||
pub fn color(&self) -> Color {
|
||||
// Safety:
|
||||
// Created from valid Table for this object
|
||||
// which contains a valid value in this slot
|
||||
unsafe { self._tab.get::<Color>(Monster::VT_COLOR, Some(Color::Blue)).unwrap()}
|
||||
}
|
||||
#[inline]
|
||||
pub fn weapons(&self) -> Option<flatbuffers::Vector<'a, flatbuffers::ForwardsUOffset<Weapon<'a>>>> {
|
||||
// Safety:
|
||||
// Created from valid Table for this object
|
||||
// which contains a valid value in this slot
|
||||
unsafe { self._tab.get::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<'a, flatbuffers::ForwardsUOffset<Weapon>>>>(Monster::VT_WEAPONS, None)}
|
||||
}
|
||||
#[inline]
|
||||
pub fn equipped_type(&self) -> Equipment {
|
||||
// Safety:
|
||||
// Created from valid Table for this object
|
||||
// which contains a valid value in this slot
|
||||
unsafe { self._tab.get::<Equipment>(Monster::VT_EQUIPPED_TYPE, Some(Equipment::NONE)).unwrap()}
|
||||
}
|
||||
#[inline]
|
||||
pub fn equipped(&self) -> Option<flatbuffers::Table<'a>> {
|
||||
// Safety:
|
||||
// Created from valid Table for this object
|
||||
// which contains a valid value in this slot
|
||||
unsafe { self._tab.get::<flatbuffers::ForwardsUOffset<flatbuffers::Table<'a>>>(Monster::VT_EQUIPPED, None)}
|
||||
}
|
||||
#[inline]
|
||||
pub fn path(&self) -> Option<flatbuffers::Vector<'a, Vec3>> {
|
||||
// Safety:
|
||||
// Created from valid Table for this object
|
||||
// which contains a valid value in this slot
|
||||
unsafe { self._tab.get::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<'a, Vec3>>>(Monster::VT_PATH, None)}
|
||||
}
|
||||
#[inline]
|
||||
#[allow(non_snake_case)]
|
||||
pub fn equipped_as_weapon(&self) -> Option<Weapon<'a>> {
|
||||
if self.equipped_type() == Equipment::Weapon {
|
||||
self.equipped().map(|t| {
|
||||
// Safety:
|
||||
// Created from a valid Table for this object
|
||||
// Which contains a valid union in this slot
|
||||
unsafe { Weapon::init_from_table(t) }
|
||||
})
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
impl flatbuffers::Verifiable for Monster<'_> {
|
||||
#[inline]
|
||||
fn run_verifier(
|
||||
v: &mut flatbuffers::Verifier, pos: usize
|
||||
) -> Result<(), flatbuffers::InvalidFlatbuffer> {
|
||||
use self::flatbuffers::Verifiable;
|
||||
v.visit_table(pos)?
|
||||
.visit_field::<Vec3>("pos", Self::VT_POS, false)?
|
||||
.visit_field::<i16>("mana", Self::VT_MANA, false)?
|
||||
.visit_field::<i16>("hp", Self::VT_HP, false)?
|
||||
.visit_field::<flatbuffers::ForwardsUOffset<&str>>("name", Self::VT_NAME, false)?
|
||||
.visit_field::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<'_, u8>>>("inventory", Self::VT_INVENTORY, false)?
|
||||
.visit_field::<Color>("color", Self::VT_COLOR, false)?
|
||||
.visit_field::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<'_, flatbuffers::ForwardsUOffset<Weapon>>>>("weapons", Self::VT_WEAPONS, false)?
|
||||
.visit_union::<Equipment, _>("equipped_type", Self::VT_EQUIPPED_TYPE, "equipped", Self::VT_EQUIPPED, false, |key, v, pos| {
|
||||
match key {
|
||||
Equipment::Weapon => v.verify_union_variant::<flatbuffers::ForwardsUOffset<Weapon>>("Equipment::Weapon", pos),
|
||||
_ => Ok(()),
|
||||
}
|
||||
})?
|
||||
.visit_field::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<'_, Vec3>>>("path", Self::VT_PATH, false)?
|
||||
.finish();
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
pub struct MonsterArgs<'a> {
|
||||
pub pos: Option<&'a Vec3>,
|
||||
pub mana: i16,
|
||||
pub hp: i16,
|
||||
pub name: Option<flatbuffers::WIPOffset<&'a str>>,
|
||||
pub inventory: Option<flatbuffers::WIPOffset<flatbuffers::Vector<'a, u8>>>,
|
||||
pub color: Color,
|
||||
pub weapons: Option<flatbuffers::WIPOffset<flatbuffers::Vector<'a, flatbuffers::ForwardsUOffset<Weapon<'a>>>>>,
|
||||
pub equipped_type: Equipment,
|
||||
pub equipped: Option<flatbuffers::WIPOffset<flatbuffers::UnionWIPOffset>>,
|
||||
pub path: Option<flatbuffers::WIPOffset<flatbuffers::Vector<'a, Vec3>>>,
|
||||
}
|
||||
impl<'a> Default for MonsterArgs<'a> {
|
||||
#[inline]
|
||||
fn default() -> Self {
|
||||
MonsterArgs {
|
||||
pos: None,
|
||||
mana: 150,
|
||||
hp: 100,
|
||||
name: None,
|
||||
inventory: None,
|
||||
color: Color::Blue,
|
||||
weapons: None,
|
||||
equipped_type: Equipment::NONE,
|
||||
equipped: None,
|
||||
path: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub struct MonsterBuilder<'a: 'b, 'b, A: flatbuffers::Allocator + 'a> {
|
||||
fbb_: &'b mut flatbuffers::FlatBufferBuilder<'a, A>,
|
||||
start_: flatbuffers::WIPOffset<flatbuffers::TableUnfinishedWIPOffset>,
|
||||
}
|
||||
impl<'a: 'b, 'b, A: flatbuffers::Allocator + 'a> MonsterBuilder<'a, 'b, A> {
|
||||
#[inline]
|
||||
pub fn add_pos(&mut self, pos: &Vec3) {
|
||||
self.fbb_.push_slot_always::<&Vec3>(Monster::VT_POS, pos);
|
||||
}
|
||||
#[inline]
|
||||
pub fn add_mana(&mut self, mana: i16) {
|
||||
self.fbb_.push_slot::<i16>(Monster::VT_MANA, mana, 150);
|
||||
}
|
||||
#[inline]
|
||||
pub fn add_hp(&mut self, hp: i16) {
|
||||
self.fbb_.push_slot::<i16>(Monster::VT_HP, hp, 100);
|
||||
}
|
||||
#[inline]
|
||||
pub fn add_name(&mut self, name: flatbuffers::WIPOffset<&'b str>) {
|
||||
self.fbb_.push_slot_always::<flatbuffers::WIPOffset<_>>(Monster::VT_NAME, name);
|
||||
}
|
||||
#[inline]
|
||||
pub fn add_inventory(&mut self, inventory: flatbuffers::WIPOffset<flatbuffers::Vector<'b , u8>>) {
|
||||
self.fbb_.push_slot_always::<flatbuffers::WIPOffset<_>>(Monster::VT_INVENTORY, inventory);
|
||||
}
|
||||
#[inline]
|
||||
pub fn add_color(&mut self, color: Color) {
|
||||
self.fbb_.push_slot::<Color>(Monster::VT_COLOR, color, Color::Blue);
|
||||
}
|
||||
#[inline]
|
||||
pub fn add_weapons(&mut self, weapons: flatbuffers::WIPOffset<flatbuffers::Vector<'b , flatbuffers::ForwardsUOffset<Weapon<'b >>>>) {
|
||||
self.fbb_.push_slot_always::<flatbuffers::WIPOffset<_>>(Monster::VT_WEAPONS, weapons);
|
||||
}
|
||||
#[inline]
|
||||
pub fn add_equipped_type(&mut self, equipped_type: Equipment) {
|
||||
self.fbb_.push_slot::<Equipment>(Monster::VT_EQUIPPED_TYPE, equipped_type, Equipment::NONE);
|
||||
}
|
||||
#[inline]
|
||||
pub fn add_equipped(&mut self, equipped: flatbuffers::WIPOffset<flatbuffers::UnionWIPOffset>) {
|
||||
self.fbb_.push_slot_always::<flatbuffers::WIPOffset<_>>(Monster::VT_EQUIPPED, equipped);
|
||||
}
|
||||
#[inline]
|
||||
pub fn add_path(&mut self, path: flatbuffers::WIPOffset<flatbuffers::Vector<'b , Vec3>>) {
|
||||
self.fbb_.push_slot_always::<flatbuffers::WIPOffset<_>>(Monster::VT_PATH, path);
|
||||
}
|
||||
#[inline]
|
||||
pub fn new(_fbb: &'b mut flatbuffers::FlatBufferBuilder<'a, A>) -> MonsterBuilder<'a, 'b, A> {
|
||||
let start = _fbb.start_table();
|
||||
MonsterBuilder {
|
||||
fbb_: _fbb,
|
||||
start_: start,
|
||||
}
|
||||
}
|
||||
#[inline]
|
||||
pub fn finish(self) -> flatbuffers::WIPOffset<Monster<'a>> {
|
||||
let o = self.fbb_.end_table(self.start_);
|
||||
flatbuffers::WIPOffset::new(o.value())
|
||||
}
|
||||
}
|
||||
|
||||
impl core::fmt::Debug for Monster<'_> {
|
||||
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
|
||||
let mut ds = f.debug_struct("Monster");
|
||||
ds.field("pos", &self.pos());
|
||||
ds.field("mana", &self.mana());
|
||||
ds.field("hp", &self.hp());
|
||||
ds.field("name", &self.name());
|
||||
ds.field("inventory", &self.inventory());
|
||||
ds.field("color", &self.color());
|
||||
ds.field("weapons", &self.weapons());
|
||||
ds.field("equipped_type", &self.equipped_type());
|
||||
match self.equipped_type() {
|
||||
Equipment::Weapon => {
|
||||
if let Some(x) = self.equipped_as_weapon() {
|
||||
ds.field("equipped", &x)
|
||||
} else {
|
||||
ds.field("equipped", &"InvalidFlatbuffer: Union discriminant does not match value.")
|
||||
}
|
||||
},
|
||||
_ => {
|
||||
let x: Option<()> = None;
|
||||
ds.field("equipped", &x)
|
||||
},
|
||||
};
|
||||
ds.field("path", &self.path());
|
||||
ds.finish()
|
||||
}
|
||||
}
|
||||
#[non_exhaustive]
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub struct MonsterT {
|
||||
pub pos: Option<Vec3T>,
|
||||
pub mana: i16,
|
||||
pub hp: i16,
|
||||
pub name: Option<String>,
|
||||
pub inventory: Option<Vec<u8>>,
|
||||
pub color: Color,
|
||||
pub weapons: Option<Vec<WeaponT>>,
|
||||
pub equipped: EquipmentT,
|
||||
pub path: Option<Vec<Vec3T>>,
|
||||
}
|
||||
impl Default for MonsterT {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
pos: None,
|
||||
mana: 150,
|
||||
hp: 100,
|
||||
name: None,
|
||||
inventory: None,
|
||||
color: Color::Blue,
|
||||
weapons: None,
|
||||
equipped: EquipmentT::NONE,
|
||||
path: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
impl MonsterT {
|
||||
pub fn pack<'b, A: flatbuffers::Allocator + 'b>(
|
||||
&self,
|
||||
_fbb: &mut flatbuffers::FlatBufferBuilder<'b, A>
|
||||
) -> flatbuffers::WIPOffset<Monster<'b>> {
|
||||
let pos_tmp = self.pos.as_ref().map(|x| x.pack());
|
||||
let pos = pos_tmp.as_ref();
|
||||
let mana = self.mana;
|
||||
let hp = self.hp;
|
||||
let name = self.name.as_ref().map(|x|{
|
||||
_fbb.create_string(x)
|
||||
});
|
||||
let inventory = self.inventory.as_ref().map(|x|{
|
||||
_fbb.create_vector(x)
|
||||
});
|
||||
let color = self.color;
|
||||
let weapons = self.weapons.as_ref().map(|x|{
|
||||
let w: Vec<_> = x.iter().map(|t| t.pack(_fbb)).collect();_fbb.create_vector(&w)
|
||||
});
|
||||
let equipped_type = self.equipped.equipment_type();
|
||||
let equipped = self.equipped.pack(_fbb);
|
||||
let path = self.path.as_ref().map(|x|{
|
||||
let w: Vec<_> = x.iter().map(|t| t.pack()).collect();_fbb.create_vector(&w)
|
||||
});
|
||||
Monster::create(_fbb, &MonsterArgs{
|
||||
pos,
|
||||
mana,
|
||||
hp,
|
||||
name,
|
||||
inventory,
|
||||
color,
|
||||
weapons,
|
||||
equipped_type,
|
||||
equipped,
|
||||
path,
|
||||
})
|
||||
}
|
||||
}
|
||||
#[inline]
|
||||
/// Verifies that a buffer of bytes contains a `Monster`
|
||||
/// 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_monster_unchecked`.
|
||||
pub fn root_as_monster(buf: &[u8]) -> Result<Monster, flatbuffers::InvalidFlatbuffer> {
|
||||
flatbuffers::root::<Monster>(buf)
|
||||
}
|
||||
#[inline]
|
||||
/// Verifies that a buffer of bytes contains a size prefixed
|
||||
/// `Monster` 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_monster_unchecked`.
|
||||
pub fn size_prefixed_root_as_monster(buf: &[u8]) -> Result<Monster, flatbuffers::InvalidFlatbuffer> {
|
||||
flatbuffers::size_prefixed_root::<Monster>(buf)
|
||||
}
|
||||
#[inline]
|
||||
/// Verifies, with the given options, that a buffer of bytes
|
||||
/// contains a `Monster` 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_monster_unchecked`.
|
||||
pub fn root_as_monster_with_opts<'b, 'o>(
|
||||
opts: &'o flatbuffers::VerifierOptions,
|
||||
buf: &'b [u8],
|
||||
) -> Result<Monster<'b>, flatbuffers::InvalidFlatbuffer> {
|
||||
flatbuffers::root_with_opts::<Monster<'b>>(opts, buf)
|
||||
}
|
||||
#[inline]
|
||||
/// Verifies, with the given verifier options, that a buffer of
|
||||
/// bytes contains a size prefixed `Monster` 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_monster_unchecked`.
|
||||
pub fn size_prefixed_root_as_monster_with_opts<'b, 'o>(
|
||||
opts: &'o flatbuffers::VerifierOptions,
|
||||
buf: &'b [u8],
|
||||
) -> Result<Monster<'b>, flatbuffers::InvalidFlatbuffer> {
|
||||
flatbuffers::size_prefixed_root_with_opts::<Monster<'b>>(opts, buf)
|
||||
}
|
||||
#[inline]
|
||||
/// Assumes, without verification, that a buffer of bytes contains a Monster and returns it.
|
||||
/// # Safety
|
||||
/// Callers must trust the given bytes do indeed contain a valid `Monster`.
|
||||
pub unsafe fn root_as_monster_unchecked(buf: &[u8]) -> Monster {
|
||||
flatbuffers::root_unchecked::<Monster>(buf)
|
||||
}
|
||||
#[inline]
|
||||
/// Assumes, without verification, that a buffer of bytes contains a size prefixed Monster and returns it.
|
||||
/// # Safety
|
||||
/// Callers must trust the given bytes do indeed contain a valid size prefixed `Monster`.
|
||||
pub unsafe fn size_prefixed_root_as_monster_unchecked(buf: &[u8]) -> Monster {
|
||||
flatbuffers::size_prefixed_root_unchecked::<Monster>(buf)
|
||||
}
|
||||
#[inline]
|
||||
pub fn finish_monster_buffer<'a, 'b, A: flatbuffers::Allocator + 'a>(
|
||||
fbb: &'b mut flatbuffers::FlatBufferBuilder<'a, A>,
|
||||
root: flatbuffers::WIPOffset<Monster<'a>>) {
|
||||
fbb.finish(root, None);
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn finish_size_prefixed_monster_buffer<'a, 'b, A: flatbuffers::Allocator + 'a>(fbb: &'b mut flatbuffers::FlatBufferBuilder<'a, A>, root: flatbuffers::WIPOffset<Monster<'a>>) {
|
||||
fbb.finish_size_prefixed(root, None);
|
||||
}
|
||||
+194
@@ -0,0 +1,194 @@
|
||||
// automatically generated by the FlatBuffers compiler, do not modify
|
||||
// @generated
|
||||
extern crate alloc;
|
||||
extern crate flatbuffers;
|
||||
use alloc::boxed::Box;
|
||||
use alloc::string::{String, ToString};
|
||||
use alloc::vec::Vec;
|
||||
use core::mem;
|
||||
use core::cmp::Ordering;
|
||||
use self::flatbuffers::{EndianScalar, Follow};
|
||||
use super::*;
|
||||
// struct Vec3, aligned to 4
|
||||
#[repr(transparent)]
|
||||
#[derive(Clone, Copy, PartialEq)]
|
||||
pub struct Vec3(pub [u8; 12]);
|
||||
impl Default for Vec3 {
|
||||
fn default() -> Self {
|
||||
Self([0; 12])
|
||||
}
|
||||
}
|
||||
impl core::fmt::Debug for Vec3 {
|
||||
fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
|
||||
f.debug_struct("Vec3")
|
||||
.field("x", &self.x())
|
||||
.field("y", &self.y())
|
||||
.field("z", &self.z())
|
||||
.finish()
|
||||
}
|
||||
}
|
||||
|
||||
impl flatbuffers::SimpleToVerifyInSlice for Vec3 {}
|
||||
impl<'a> flatbuffers::Follow<'a> for Vec3 {
|
||||
type Inner = &'a Vec3;
|
||||
#[inline]
|
||||
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
<&'a Vec3>::follow(buf, loc)
|
||||
}
|
||||
}
|
||||
impl<'a> flatbuffers::Follow<'a> for &'a Vec3 {
|
||||
type Inner = &'a Vec3;
|
||||
#[inline]
|
||||
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
flatbuffers::follow_cast_ref::<Vec3>(buf, loc)
|
||||
}
|
||||
}
|
||||
impl<'b> flatbuffers::Push for Vec3 {
|
||||
type Output = Vec3;
|
||||
#[inline]
|
||||
unsafe fn push(&self, dst: &mut [u8], _written_len: usize) {
|
||||
let src = ::core::slice::from_raw_parts(self as *const Vec3 as *const u8, Self::size());
|
||||
dst.copy_from_slice(src);
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> flatbuffers::Verifiable for Vec3 {
|
||||
#[inline]
|
||||
fn run_verifier(
|
||||
v: &mut flatbuffers::Verifier, pos: usize
|
||||
) -> Result<(), flatbuffers::InvalidFlatbuffer> {
|
||||
use self::flatbuffers::Verifiable;
|
||||
v.in_buffer::<Self>(pos)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> Vec3 {
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub fn new(
|
||||
x: f32,
|
||||
y: f32,
|
||||
z: f32,
|
||||
) -> Self {
|
||||
let mut s = Self([0; 12]);
|
||||
s.set_x(x);
|
||||
s.set_y(y);
|
||||
s.set_z(z);
|
||||
s
|
||||
}
|
||||
|
||||
pub const fn get_fully_qualified_name() -> &'static str {
|
||||
"MyGame.Sample.Vec3"
|
||||
}
|
||||
|
||||
pub fn x(&self) -> f32 {
|
||||
let mut mem = core::mem::MaybeUninit::<<f32 as EndianScalar>::Scalar>::uninit();
|
||||
// Safety:
|
||||
// Created from a valid Table for this object
|
||||
// Which contains a valid value in this slot
|
||||
EndianScalar::from_little_endian(unsafe {
|
||||
core::ptr::copy_nonoverlapping(
|
||||
self.0[0..].as_ptr(),
|
||||
mem.as_mut_ptr() as *mut u8,
|
||||
core::mem::size_of::<<f32 as EndianScalar>::Scalar>(),
|
||||
);
|
||||
mem.assume_init()
|
||||
})
|
||||
}
|
||||
|
||||
pub fn set_x(&mut self, x: f32) {
|
||||
let x_le = x.to_little_endian();
|
||||
// Safety:
|
||||
// Created from a valid Table for this object
|
||||
// Which contains a valid value in this slot
|
||||
unsafe {
|
||||
core::ptr::copy_nonoverlapping(
|
||||
&x_le as *const _ as *const u8,
|
||||
self.0[0..].as_mut_ptr(),
|
||||
core::mem::size_of::<<f32 as EndianScalar>::Scalar>(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn y(&self) -> f32 {
|
||||
let mut mem = core::mem::MaybeUninit::<<f32 as EndianScalar>::Scalar>::uninit();
|
||||
// Safety:
|
||||
// Created from a valid Table for this object
|
||||
// Which contains a valid value in this slot
|
||||
EndianScalar::from_little_endian(unsafe {
|
||||
core::ptr::copy_nonoverlapping(
|
||||
self.0[4..].as_ptr(),
|
||||
mem.as_mut_ptr() as *mut u8,
|
||||
core::mem::size_of::<<f32 as EndianScalar>::Scalar>(),
|
||||
);
|
||||
mem.assume_init()
|
||||
})
|
||||
}
|
||||
|
||||
pub fn set_y(&mut self, x: f32) {
|
||||
let x_le = x.to_little_endian();
|
||||
// Safety:
|
||||
// Created from a valid Table for this object
|
||||
// Which contains a valid value in this slot
|
||||
unsafe {
|
||||
core::ptr::copy_nonoverlapping(
|
||||
&x_le as *const _ as *const u8,
|
||||
self.0[4..].as_mut_ptr(),
|
||||
core::mem::size_of::<<f32 as EndianScalar>::Scalar>(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn z(&self) -> f32 {
|
||||
let mut mem = core::mem::MaybeUninit::<<f32 as EndianScalar>::Scalar>::uninit();
|
||||
// Safety:
|
||||
// Created from a valid Table for this object
|
||||
// Which contains a valid value in this slot
|
||||
EndianScalar::from_little_endian(unsafe {
|
||||
core::ptr::copy_nonoverlapping(
|
||||
self.0[8..].as_ptr(),
|
||||
mem.as_mut_ptr() as *mut u8,
|
||||
core::mem::size_of::<<f32 as EndianScalar>::Scalar>(),
|
||||
);
|
||||
mem.assume_init()
|
||||
})
|
||||
}
|
||||
|
||||
pub fn set_z(&mut self, x: f32) {
|
||||
let x_le = x.to_little_endian();
|
||||
// Safety:
|
||||
// Created from a valid Table for this object
|
||||
// Which contains a valid value in this slot
|
||||
unsafe {
|
||||
core::ptr::copy_nonoverlapping(
|
||||
&x_le as *const _ as *const u8,
|
||||
self.0[8..].as_mut_ptr(),
|
||||
core::mem::size_of::<<f32 as EndianScalar>::Scalar>(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn unpack(&self) -> Vec3T {
|
||||
Vec3T {
|
||||
x: self.x(),
|
||||
y: self.y(),
|
||||
z: self.z(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Default)]
|
||||
pub struct Vec3T {
|
||||
pub x: f32,
|
||||
pub y: f32,
|
||||
pub z: f32,
|
||||
}
|
||||
impl Vec3T {
|
||||
pub fn pack(&self) -> Vec3 {
|
||||
Vec3::new(
|
||||
self.x,
|
||||
self.y,
|
||||
self.z,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
+168
@@ -0,0 +1,168 @@
|
||||
// automatically generated by the FlatBuffers compiler, do not modify
|
||||
// @generated
|
||||
extern crate alloc;
|
||||
extern crate flatbuffers;
|
||||
use alloc::boxed::Box;
|
||||
use alloc::string::{String, ToString};
|
||||
use alloc::vec::Vec;
|
||||
use core::mem;
|
||||
use core::cmp::Ordering;
|
||||
use self::flatbuffers::{EndianScalar, Follow};
|
||||
use super::*;
|
||||
pub enum WeaponOffset {}
|
||||
#[derive(Copy, Clone, PartialEq)]
|
||||
|
||||
pub struct Weapon<'a> {
|
||||
pub _tab: flatbuffers::Table<'a>,
|
||||
}
|
||||
|
||||
impl<'a> flatbuffers::Follow<'a> for Weapon<'a> {
|
||||
type Inner = Weapon<'a>;
|
||||
#[inline]
|
||||
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
Self { _tab: flatbuffers::Table::new(buf, loc) }
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> Weapon<'a> {
|
||||
pub const VT_NAME: flatbuffers::VOffsetT = 4;
|
||||
pub const VT_DAMAGE: flatbuffers::VOffsetT = 6;
|
||||
|
||||
pub const fn get_fully_qualified_name() -> &'static str {
|
||||
"MyGame.Sample.Weapon"
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub unsafe fn init_from_table(table: flatbuffers::Table<'a>) -> Self {
|
||||
Weapon { _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 WeaponArgs<'args>
|
||||
) -> flatbuffers::WIPOffset<Weapon<'bldr>> {
|
||||
let mut builder = WeaponBuilder::new(_fbb);
|
||||
if let Some(x) = args.name { builder.add_name(x); }
|
||||
builder.add_damage(args.damage);
|
||||
builder.finish()
|
||||
}
|
||||
|
||||
pub fn unpack(&self) -> WeaponT {
|
||||
let name = self.name().map(|x| {
|
||||
x.to_string()
|
||||
});
|
||||
let damage = self.damage();
|
||||
WeaponT {
|
||||
name,
|
||||
damage,
|
||||
}
|
||||
}
|
||||
|
||||
#[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::<flatbuffers::ForwardsUOffset<&str>>(Weapon::VT_NAME, None)}
|
||||
}
|
||||
#[inline]
|
||||
pub fn damage(&self) -> i16 {
|
||||
// Safety:
|
||||
// Created from valid Table for this object
|
||||
// which contains a valid value in this slot
|
||||
unsafe { self._tab.get::<i16>(Weapon::VT_DAMAGE, Some(0)).unwrap()}
|
||||
}
|
||||
}
|
||||
|
||||
impl flatbuffers::Verifiable for Weapon<'_> {
|
||||
#[inline]
|
||||
fn run_verifier(
|
||||
v: &mut flatbuffers::Verifier, pos: usize
|
||||
) -> Result<(), flatbuffers::InvalidFlatbuffer> {
|
||||
use self::flatbuffers::Verifiable;
|
||||
v.visit_table(pos)?
|
||||
.visit_field::<flatbuffers::ForwardsUOffset<&str>>("name", Self::VT_NAME, false)?
|
||||
.visit_field::<i16>("damage", Self::VT_DAMAGE, false)?
|
||||
.finish();
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
pub struct WeaponArgs<'a> {
|
||||
pub name: Option<flatbuffers::WIPOffset<&'a str>>,
|
||||
pub damage: i16,
|
||||
}
|
||||
impl<'a> Default for WeaponArgs<'a> {
|
||||
#[inline]
|
||||
fn default() -> Self {
|
||||
WeaponArgs {
|
||||
name: None,
|
||||
damage: 0,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub struct WeaponBuilder<'a: 'b, 'b, A: flatbuffers::Allocator + 'a> {
|
||||
fbb_: &'b mut flatbuffers::FlatBufferBuilder<'a, A>,
|
||||
start_: flatbuffers::WIPOffset<flatbuffers::TableUnfinishedWIPOffset>,
|
||||
}
|
||||
impl<'a: 'b, 'b, A: flatbuffers::Allocator + 'a> WeaponBuilder<'a, 'b, A> {
|
||||
#[inline]
|
||||
pub fn add_name(&mut self, name: flatbuffers::WIPOffset<&'b str>) {
|
||||
self.fbb_.push_slot_always::<flatbuffers::WIPOffset<_>>(Weapon::VT_NAME, name);
|
||||
}
|
||||
#[inline]
|
||||
pub fn add_damage(&mut self, damage: i16) {
|
||||
self.fbb_.push_slot::<i16>(Weapon::VT_DAMAGE, damage, 0);
|
||||
}
|
||||
#[inline]
|
||||
pub fn new(_fbb: &'b mut flatbuffers::FlatBufferBuilder<'a, A>) -> WeaponBuilder<'a, 'b, A> {
|
||||
let start = _fbb.start_table();
|
||||
WeaponBuilder {
|
||||
fbb_: _fbb,
|
||||
start_: start,
|
||||
}
|
||||
}
|
||||
#[inline]
|
||||
pub fn finish(self) -> flatbuffers::WIPOffset<Weapon<'a>> {
|
||||
let o = self.fbb_.end_table(self.start_);
|
||||
flatbuffers::WIPOffset::new(o.value())
|
||||
}
|
||||
}
|
||||
|
||||
impl core::fmt::Debug for Weapon<'_> {
|
||||
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
|
||||
let mut ds = f.debug_struct("Weapon");
|
||||
ds.field("name", &self.name());
|
||||
ds.field("damage", &self.damage());
|
||||
ds.finish()
|
||||
}
|
||||
}
|
||||
#[non_exhaustive]
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub struct WeaponT {
|
||||
pub name: Option<String>,
|
||||
pub damage: i16,
|
||||
}
|
||||
impl Default for WeaponT {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
name: None,
|
||||
damage: 0,
|
||||
}
|
||||
}
|
||||
}
|
||||
impl WeaponT {
|
||||
pub fn pack<'b, A: flatbuffers::Allocator + 'b>(
|
||||
&self,
|
||||
_fbb: &mut flatbuffers::FlatBufferBuilder<'b, A>
|
||||
) -> flatbuffers::WIPOffset<Weapon<'b>> {
|
||||
let name = self.name.as_ref().map(|x|{
|
||||
_fbb.create_string(x)
|
||||
});
|
||||
let damage = self.damage;
|
||||
Weapon::create(_fbb, &WeaponArgs{
|
||||
name,
|
||||
damage,
|
||||
})
|
||||
}
|
||||
}
|
||||
+7
-7
@@ -16,9 +16,7 @@
|
||||
|
||||
#include "flatbuffers/idl.h"
|
||||
#include "flatbuffers/util.h"
|
||||
|
||||
#include "monster_test_generated.h"
|
||||
#include "monster_generated.h" // Already includes "flatbuffers/flatbuffers.h".
|
||||
#include "monster_generated.h" // Already includes "flatbuffers/flatbuffers.h".
|
||||
|
||||
using namespace MyGame::Sample;
|
||||
|
||||
@@ -31,7 +29,8 @@ int main(int /*argc*/, const char * /*argv*/[]) {
|
||||
std::string bfbs_file;
|
||||
bool ok =
|
||||
flatbuffers::LoadFile("tests/monster_test.fbs", false, &schema_file) &&
|
||||
flatbuffers::LoadFile("tests/monsterdata_test.golden", false, &json_file) &&
|
||||
flatbuffers::LoadFile("tests/monsterdata_test.golden", false,
|
||||
&json_file) &&
|
||||
flatbuffers::LoadFile("tests/monster_test.bfbs", true, &bfbs_file);
|
||||
if (!ok) {
|
||||
printf("couldn't load files!\n");
|
||||
@@ -47,7 +46,8 @@ int main(int /*argc*/, const char * /*argv*/[]) {
|
||||
|
||||
// inizialize parser by deserializing bfbs schema
|
||||
flatbuffers::Parser parser2;
|
||||
ok = parser2.Deserialize((uint8_t *)bfbs_file.c_str(), bfbs_file.length());
|
||||
ok = parser2.Deserialize(reinterpret_cast<const uint8_t *>(bfbs_file.c_str()),
|
||||
bfbs_file.length());
|
||||
assert(ok);
|
||||
|
||||
// parse json in parser from fbs and bfbs
|
||||
@@ -59,13 +59,13 @@ int main(int /*argc*/, const char * /*argv*/[]) {
|
||||
// to ensure it is correct, we now generate text back from the binary,
|
||||
// and compare the two:
|
||||
std::string jsongen1;
|
||||
if (!GenerateText(parser1, parser1.builder_.GetBufferPointer(), &jsongen1)) {
|
||||
if (GenText(parser1, parser1.builder_.GetBufferPointer(), &jsongen1)) {
|
||||
printf("Couldn't serialize parsed data to JSON!\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
std::string jsongen2;
|
||||
if (!GenerateText(parser2, parser2.builder_.GetBufferPointer(), &jsongen2)) {
|
||||
if (GenText(parser2, parser2.builder_.GetBufferPointer(), &jsongen2)) {
|
||||
printf("Couldn't serialize parsed data to JSON!\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
+1
-1
@@ -20,7 +20,7 @@ using namespace MyGame::Sample;
|
||||
|
||||
// Example how to use FlatBuffers to create and read binary buffers.
|
||||
|
||||
int main(int /*argc*/, const char * /*argv*/ []) {
|
||||
int main(int /*argc*/, const char * /*argv*/[]) {
|
||||
// Build up a serialized buffer algorithmically:
|
||||
flatbuffers::FlatBufferBuilder builder;
|
||||
|
||||
|
||||
+1
-1
@@ -19,7 +19,7 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
sample "MyGame/Sample"
|
||||
sample "github.com/google/flatbuffers/samples/MyGame/Sample"
|
||||
"fmt"
|
||||
flatbuffers "github.com/google/flatbuffers/go"
|
||||
"strconv"
|
||||
|
||||
+1
-1
@@ -54,7 +54,7 @@ let orc = MyGame_Sample_MonsterBuilder { b }
|
||||
.end()
|
||||
|
||||
// Finish the buffer!
|
||||
b.Finish(orc)
|
||||
b.Finish(orc, "MONS")
|
||||
|
||||
// We now have a FlatBuffer that we could store on disk or send over a network.
|
||||
|
||||
|
||||
+8
-8
@@ -55,13 +55,13 @@ def main():
|
||||
# Note: Since we prepend the bytes, this loop iterates in reverse order.
|
||||
for i in reversed(range(0, 10)):
|
||||
builder.PrependByte(i)
|
||||
inv = builder.EndVector(10)
|
||||
inv = builder.EndVector()
|
||||
|
||||
MyGame.Sample.Monster.MonsterStartWeaponsVector(builder, 2)
|
||||
# Note: Since we prepend the data, prepend the weapons in reverse order.
|
||||
builder.PrependUOffsetTRelative(axe)
|
||||
builder.PrependUOffsetTRelative(sword)
|
||||
weapons = builder.EndVector(2)
|
||||
weapons = builder.EndVector()
|
||||
|
||||
pos = MyGame.Sample.Vec3.CreateVec3(builder, 1.0, 2.0, 3.0)
|
||||
|
||||
@@ -99,20 +99,20 @@ def main():
|
||||
# Note: We did not set the `Mana` field explicitly, so we get a default value.
|
||||
assert monster.Mana() == 150
|
||||
assert monster.Hp() == 300
|
||||
assert monster.Name() == 'Orc'
|
||||
assert monster.Name() == b'Orc'
|
||||
assert monster.Color() == MyGame.Sample.Color.Color().Red
|
||||
assert monster.Pos().X() == 1.0
|
||||
assert monster.Pos().Y() == 2.0
|
||||
assert monster.Pos().Z() == 3.0
|
||||
|
||||
# Get and test the `inventory` FlatBuffer `vector`.
|
||||
for i in xrange(monster.InventoryLength()):
|
||||
for i in range(monster.InventoryLength()):
|
||||
assert monster.Inventory(i) == i
|
||||
|
||||
# Get and test the `weapons` FlatBuffer `vector` of `table`s.
|
||||
expected_weapon_names = ['Sword', 'Axe']
|
||||
expected_weapon_names = [b'Sword', b'Axe']
|
||||
expected_weapon_damages = [3, 5]
|
||||
for i in xrange(monster.WeaponsLength()):
|
||||
for i in range(monster.WeaponsLength()):
|
||||
assert monster.Weapons(i).Name() == expected_weapon_names[i]
|
||||
assert monster.Weapons(i).Damage() == expected_weapon_damages[i]
|
||||
|
||||
@@ -128,10 +128,10 @@ def main():
|
||||
union_weapon = MyGame.Sample.Weapon.Weapon()
|
||||
union_weapon.Init(monster.Equipped().Bytes, monster.Equipped().Pos)
|
||||
|
||||
assert union_weapon.Name() == "Axe"
|
||||
assert union_weapon.Name() == b"Axe"
|
||||
assert union_weapon.Damage() == 5
|
||||
|
||||
print 'The FlatBuffer was successfully created and verified!'
|
||||
print('The FlatBuffer was successfully created and verified!')
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
||||
+16
-12
@@ -18,21 +18,21 @@
|
||||
extern crate flatbuffers;
|
||||
|
||||
// import the generated code
|
||||
#[path = "./monster_generated.rs"]
|
||||
mod monster_generated;
|
||||
pub use monster_generated::my_game::sample::{get_root_as_monster,
|
||||
Color, Equipment,
|
||||
#[allow(dead_code, unused_imports)]
|
||||
#[allow(clippy::all)]
|
||||
mod rust_generated;
|
||||
pub use rust_generated::my_game::sample::{Color, Equipment,
|
||||
Monster, MonsterArgs,
|
||||
Vec3,
|
||||
Weapon, WeaponArgs};
|
||||
|
||||
|
||||
// Example how to use FlatBuffers to create and read binary buffers.
|
||||
|
||||
#[allow(clippy::float_cmp)]
|
||||
fn main() {
|
||||
// Build up a serialized buffer algorithmically.
|
||||
// Initialize it with a capacity of 1024 bytes.
|
||||
let mut builder = flatbuffers::FlatBufferBuilder::new_with_capacity(1024);
|
||||
let mut builder = flatbuffers::FlatBufferBuilder::with_capacity(1024);
|
||||
|
||||
// Serialize some weapons for the Monster: A 'sword' and an 'axe'.
|
||||
let weapon_one_name = builder.create_string("Sword");
|
||||
@@ -71,7 +71,7 @@ fn main() {
|
||||
// Create the monster using the `Monster::create` helper function. This
|
||||
// function accepts a `MonsterArgs` struct, which supplies all of the data
|
||||
// needed to build a `Monster`. To supply empty/default fields, just use the
|
||||
// Rust built-in `Default::default()` function, as demononstrated below.
|
||||
// Rust built-in `Default::default()` function, as demonstrated below.
|
||||
let orc = Monster::create(&mut builder, &MonsterArgs{
|
||||
pos: Some(&Vec3::new(1.0f32, 2.0f32, 3.0f32)),
|
||||
mana: 150,
|
||||
@@ -98,7 +98,7 @@ fn main() {
|
||||
let buf = builder.finished_data(); // Of type `&[u8]`
|
||||
|
||||
// Get access to the root:
|
||||
let monster = get_root_as_monster(buf);
|
||||
let monster = flatbuffers::root::<Monster>(buf).unwrap();
|
||||
|
||||
// Get and test some scalar types from the FlatBuffer.
|
||||
let hp = monster.hp();
|
||||
@@ -122,10 +122,7 @@ fn main() {
|
||||
// Get an element from the `inventory` FlatBuffer's `vector`.
|
||||
assert!(monster.inventory().is_some());
|
||||
let inv = monster.inventory().unwrap();
|
||||
|
||||
// Note that this vector is returned as a slice, because direct access for
|
||||
// this type, a u8 vector, is safe on all platforms:
|
||||
let third_item = inv[2];
|
||||
let third_item = inv.get(2);
|
||||
assert_eq!(third_item, 2);
|
||||
|
||||
// Get and test the `weapons` FlatBuffers's `vector`.
|
||||
@@ -152,4 +149,11 @@ fn main() {
|
||||
//assert_eq!(monster.path().unwrap()[1].x(), 4.0);
|
||||
|
||||
println!("The FlatBuffer was successfully created and accessed!");
|
||||
dbg!(monster);
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
#[test]
|
||||
fn test_main() {
|
||||
main()
|
||||
}
|
||||
|
||||
@@ -0,0 +1,83 @@
|
||||
/*
|
||||
* Copyright 2023 Google Inc. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import FlatBuffers
|
||||
|
||||
typealias Monster = MyGame_Sample_Monster
|
||||
typealias Weapon = MyGame_Sample_Weapon
|
||||
typealias Color = MyGame_Sample_Color
|
||||
typealias Vec3 = MyGame_Sample_Vec3
|
||||
|
||||
func main() {
|
||||
let expectedDMG: [Int16] = [3, 5]
|
||||
let expectedNames = ["Sword", "Axe"]
|
||||
|
||||
var builder = FlatBufferBuilder(initialSize: 1024)
|
||||
let weapon1Name = builder.create(string: expectedNames[0])
|
||||
let weapon2Name = builder.create(string: expectedNames[1])
|
||||
|
||||
let weapon1Start = Weapon.startWeapon(&builder)
|
||||
Weapon.add(name: weapon1Name, &builder)
|
||||
Weapon.add(damage: expectedDMG[0], &builder)
|
||||
let sword = Weapon.endWeapon(&builder, start: weapon1Start)
|
||||
let weapon2Start = Weapon.startWeapon(&builder)
|
||||
Weapon.add(name: weapon2Name, &builder)
|
||||
Weapon.add(damage: expectedDMG[1], &builder)
|
||||
let axe = Weapon.endWeapon(&builder, start: weapon2Start)
|
||||
|
||||
let name = builder.create(string: "Orc")
|
||||
let inventory: [Byte] = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
|
||||
let inventoryOffset = builder.createVector(inventory)
|
||||
|
||||
let weaponsOffset = builder.createVector(ofOffsets: [sword, axe])
|
||||
|
||||
let orc = Monster.createMonster(
|
||||
&builder,
|
||||
pos: MyGame_Sample_Vec3(x: 1, y: 2, z: 3),
|
||||
hp: 300,
|
||||
nameOffset: name,
|
||||
inventoryVectorOffset: inventoryOffset,
|
||||
color: .red,
|
||||
weaponsVectorOffset: weaponsOffset,
|
||||
equippedType: .weapon,
|
||||
equippedOffset: axe)
|
||||
builder.finish(offset: orc)
|
||||
|
||||
var buf = ByteBuffer(bytes: builder.sizedByteArray)
|
||||
let monster: Monster = try! getCheckedRoot(byteBuffer: &buffer)
|
||||
|
||||
assert(monster.mana == 150)
|
||||
assert(monster.hp == 300)
|
||||
assert(monster.name == "Orc")
|
||||
assert(monster.color == MyGame.Sample.Color.red)
|
||||
assert(monster.pos != nil)
|
||||
assert(monster.mutablePos != nil)
|
||||
for i in 0..<monster.inventoryCount {
|
||||
assert(i == monster.inventory(at: i))
|
||||
}
|
||||
|
||||
for i in 0..<monster.weaponsCount {
|
||||
let weap = monster.weapons(at: i)
|
||||
let index = Int(i)
|
||||
assert(weap?.damage == expectedDMG[index])
|
||||
assert(weap?.name == expectedNames[index])
|
||||
}
|
||||
assert(monster.equippedType == .weapon)
|
||||
let equipped = monster.equipped(type: Weapon.self)
|
||||
assert(equipped?.name == "Axe")
|
||||
assert(equipped?.damage == 5)
|
||||
print("Monster Object is Verified")
|
||||
}
|
||||
@@ -0,0 +1,166 @@
|
||||
// Copyright 2019 Google LLC
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
extern crate flexbuffers;
|
||||
|
||||
use flexbuffers::{BitWidth, Builder, Reader, ReaderError};
|
||||
|
||||
// In this Example we're creating a monster that corresponds to the following JSON:
|
||||
// {
|
||||
// "coins": [5, 10, 25, 25, 25, 100],
|
||||
// "color": [255, 0, 0, 255],
|
||||
// "enraged": true,
|
||||
// "hp": 80,
|
||||
// "mana": 200,
|
||||
// "position": [0, 0, 0],
|
||||
// "velocity": [1, 0, 0],
|
||||
// "weapons": [
|
||||
// "fist",
|
||||
// {"damage": 15, "name": "great axe"},
|
||||
// {"damage": 5, "name": "hammer"}]
|
||||
// }
|
||||
#[allow(clippy::float_cmp)]
|
||||
fn main() {
|
||||
// Create a new Flexbuffer builder.
|
||||
let mut builder = Builder::default();
|
||||
|
||||
// The root of the builder can be a singleton, map or vector.
|
||||
// Our monster will be represented with a map.
|
||||
let mut monster = builder.start_map();
|
||||
|
||||
// Use `push` to add elements to a vector or map. Note that it up to the programmer to ensure
|
||||
// duplicate keys are avoided and the key has no null bytes.
|
||||
monster.push("hp", 80);
|
||||
monster.push("mana", 200);
|
||||
monster.push("enraged", true);
|
||||
|
||||
// Let's give our monster some weapons. Use `start_vector` to store a vector.
|
||||
let mut weapons = monster.start_vector("weapons");
|
||||
|
||||
// The first weapon is a fist which has no damage so we'll store it as a string.
|
||||
// Strings in Flexbuffers are utf8 encoded and are distinct from map Keys which are c strings.
|
||||
weapons.push("fist");
|
||||
|
||||
// The monster also has an axe. We'll store it as a map to make it more interesting.
|
||||
let mut axe = weapons.start_map();
|
||||
axe.push("name", "great axe");
|
||||
axe.push("damage", 15);
|
||||
// We're done adding to the axe.
|
||||
axe.end_map();
|
||||
|
||||
// The monster also has a hammer.
|
||||
{
|
||||
let mut hammer = weapons.start_map();
|
||||
hammer.push("name", "hammer");
|
||||
hammer.push("damage", 5);
|
||||
// Instead of calling `hammer.end_map()`, we can just drop the `hammer` for the same effect.
|
||||
// Vectors and maps are completed and serialized when their builders are dropped.
|
||||
}
|
||||
|
||||
// We're done adding weapons.
|
||||
weapons.end_vector();
|
||||
|
||||
// Give the monster some money. Flexbuffers has typed vectors which are smaller than
|
||||
// heterogenous vectors. Elements of typed vectors can be pushed one at a time, as above, or
|
||||
// they can be passed as a slice. This will be stored as a `FlexBufferType::VectorInt`.
|
||||
monster.push("coins", &[5, 10, 25, 25, 25, 100]);
|
||||
|
||||
// Flexbuffer has special types for fixed-length-typed-vectors (if the length is 3 or 4 and the
|
||||
// type is int, uint, or float). They're even more compact than typed vectors.
|
||||
// The monster's position and Velocity will be stored as `FlexbufferType::VectorFloat3`.
|
||||
monster.push("position", &[0.0; 3]);
|
||||
monster.push("velocity", &[1.0, 0.0, 0.0]);
|
||||
|
||||
// Give the monster bright red skin. In rust, numbers are assumed integers until proven
|
||||
// otherwise. We annotate u8 to tell flexbuffers to store it as a FlexbufferType::VectorUInt4.
|
||||
monster.push("color", &[255, 0, 0, 255u8]);
|
||||
|
||||
// End the map at the root of the builder. This finishes the Flexbuffer.
|
||||
monster.end_map();
|
||||
|
||||
// Now the buffer is free to be reused. Let's see the final buffer.
|
||||
let data = builder.view();
|
||||
println!("The monster was serialized in {:?} bytes.", data.len());
|
||||
|
||||
// Let's read and verify the data.
|
||||
let root = Reader::get_root(data).unwrap();
|
||||
println!("The monster: {}", root);
|
||||
|
||||
let read_monster = root.as_map();
|
||||
|
||||
// What attributes does this monster have?
|
||||
let attrs: Vec<_> = read_monster.iter_keys().collect();
|
||||
assert_eq!(
|
||||
attrs,
|
||||
vec!["coins", "color", "enraged", "hp", "mana", "position", "velocity", "weapons"]
|
||||
);
|
||||
|
||||
// index into a vector or map with the `idx` method.
|
||||
let read_hp = read_monster.idx("hp");
|
||||
let read_mana = read_monster.idx("mana");
|
||||
// If `idx` fails it will return a Null flexbuffer Reader
|
||||
|
||||
// Use `as_T` to cast the data to your desired type.
|
||||
assert_eq!(read_hp.as_u8(), 80);
|
||||
assert_eq!(read_hp.as_f32(), 80.0);
|
||||
// If it fails it will return T::default().
|
||||
assert_eq!(read_hp.as_str(), ""); // Its not a string.
|
||||
assert_eq!(read_mana.as_i8(), 0); // 200 is not representable in i8.
|
||||
assert!(read_mana.as_vector().is_empty()); // Its not a vector.
|
||||
assert_eq!(read_monster.idx("foo").as_i32(), 0); // `foo` is not a monster attribute.
|
||||
|
||||
// To examine how your data is stored, check the flexbuffer type and bitwidth.
|
||||
assert!(read_hp.flexbuffer_type().is_int());
|
||||
assert!(read_mana.flexbuffer_type().is_int());
|
||||
// Note that mana=200 is bigger than the maximum i8 so everything in the top layer of the
|
||||
// monster map is stored in 16 bits.
|
||||
assert_eq!(read_hp.bitwidth(), BitWidth::W16);
|
||||
assert_eq!(read_monster.idx("mana").bitwidth(), BitWidth::W16);
|
||||
|
||||
// Use get_T functions if you want to ensure the flexbuffer type matches what you expect.
|
||||
assert_eq!(read_hp.get_i64(), Ok(80));
|
||||
assert!(read_hp.get_u64().is_err());
|
||||
assert!(read_hp.get_vector().is_err());
|
||||
|
||||
// Analogously, the `index` method is the safe version of `idx`.
|
||||
assert!(read_monster.index("hp").is_ok());
|
||||
assert_eq!(
|
||||
read_monster.index("foo").unwrap_err(),
|
||||
ReaderError::KeyNotFound
|
||||
);
|
||||
|
||||
// Maps can also be indexed by usize. They're stored by key so `coins` are the first element.
|
||||
let monster_coins = read_monster.idx(0);
|
||||
// Maps and Vectors can be iterated over.
|
||||
assert!(monster_coins
|
||||
.as_vector()
|
||||
.iter()
|
||||
.map(|r| r.as_u8())
|
||||
.eq(vec![5, 10, 25, 25, 25, 100].into_iter()));
|
||||
|
||||
// Build the answer to life the universe and everything. Reusing a builder resets it. The
|
||||
// reused internals won't need to reallocate leading to a potential 2x speedup.
|
||||
builder.build_singleton(42);
|
||||
|
||||
// The monster is now no more.
|
||||
assert_eq!(builder.view().len(), 3); // Bytes.
|
||||
|
||||
let the_answer = Reader::get_root(builder.view()).unwrap();
|
||||
assert_eq!(the_answer.as_i32(), 42);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_main() {
|
||||
main()
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
// Copyright 2019 Google LLC
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
extern crate flexbuffers;
|
||||
extern crate serde;
|
||||
#[macro_use]
|
||||
extern crate serde_derive;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Debug, PartialEq, Serialize, Deserialize)]
|
||||
enum Weapon {
|
||||
Fist,
|
||||
Equipment { name: String, damage: i32 },
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq, Serialize, Deserialize)]
|
||||
struct Color(u8, u8, u8, u8);
|
||||
|
||||
#[derive(Debug, PartialEq, Serialize, Deserialize)]
|
||||
struct Monster {
|
||||
hp: u32,
|
||||
mana: i32,
|
||||
enraged: bool,
|
||||
weapons: Vec<Weapon>,
|
||||
color: Color,
|
||||
position: [f64; 3],
|
||||
velocity: [f64; 3],
|
||||
coins: Vec<u32>,
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let monster = Monster {
|
||||
hp: 80,
|
||||
mana: 200,
|
||||
enraged: true,
|
||||
color: Color(255, 255, 255, 255),
|
||||
position: [0.0; 3],
|
||||
velocity: [1.0, 0.0, 0.0],
|
||||
weapons: vec![
|
||||
Weapon::Fist,
|
||||
Weapon::Equipment {
|
||||
name: "great axe".to_string(),
|
||||
damage: 15,
|
||||
},
|
||||
Weapon::Equipment {
|
||||
name: "hammer".to_string(),
|
||||
damage: 5,
|
||||
},
|
||||
],
|
||||
coins: vec![5, 10, 25, 25, 25, 100],
|
||||
};
|
||||
let mut s = flexbuffers::FlexbufferSerializer::new();
|
||||
monster.serialize(&mut s).unwrap();
|
||||
|
||||
let r = flexbuffers::Reader::get_root(s.view()).unwrap();
|
||||
|
||||
// Serialization is similar to JSON. Field names are stored in the buffer but are reused
|
||||
// between all maps and structs.
|
||||
println!("Monster stored in {:?} bytes.", s.view().len());
|
||||
println!("{}", r);
|
||||
|
||||
let monster2 = Monster::deserialize(r).unwrap();
|
||||
|
||||
assert_eq!(monster, monster2);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_main() {
|
||||
main()
|
||||
}
|
||||
+2
-3
@@ -16,14 +16,13 @@
|
||||
|
||||
#include "flatbuffers/idl.h"
|
||||
#include "flatbuffers/util.h"
|
||||
|
||||
#include "monster_generated.h" // Already includes "flatbuffers/flatbuffers.h".
|
||||
|
||||
using namespace MyGame::Sample;
|
||||
|
||||
// This is an example of parsing text straight into a buffer and then
|
||||
// generating flatbuffer (JSON) text from the buffer.
|
||||
int main(int /*argc*/, const char * /*argv*/ []) {
|
||||
int main(int /*argc*/, const char * /*argv*/[]) {
|
||||
// load FlatBuffer schema (.fbs) and JSON from disk
|
||||
std::string schemafile;
|
||||
std::string jsonfile;
|
||||
@@ -46,7 +45,7 @@ int main(int /*argc*/, const char * /*argv*/ []) {
|
||||
// to ensure it is correct, we now generate text back from the binary,
|
||||
// and compare the two:
|
||||
std::string jsongen;
|
||||
if (!GenerateText(parser, parser.builder_.GetBufferPointer(), &jsongen)) {
|
||||
if (GenText(parser, parser.builder_.GetBufferPointer(), &jsongen)) {
|
||||
printf("Couldn't serialize parsed data to JSON!\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
-106
@@ -1,106 +0,0 @@
|
||||
/*
|
||||
* Copyright 2015 Google Inc. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
// To run, use the `javascript_sample.sh` script.
|
||||
|
||||
var assert = require('assert');
|
||||
var flatbuffers = require('../js/flatbuffers').flatbuffers;
|
||||
var MyGame = require('./monster_generated').MyGame;
|
||||
|
||||
// Example how to use FlatBuffers to create and read binary buffers.
|
||||
function main() {
|
||||
var builder = new flatbuffers.Builder(0);
|
||||
|
||||
// Create some weapons for our Monster ('Sword' and 'Axe').
|
||||
var weaponOne = builder.createString('Sword');
|
||||
var weaponTwo = builder.createString('Axe');
|
||||
|
||||
MyGame.Sample.Weapon.startWeapon(builder);
|
||||
MyGame.Sample.Weapon.addName(builder, weaponOne);
|
||||
MyGame.Sample.Weapon.addDamage(builder, 3);
|
||||
var sword = MyGame.Sample.Weapon.endWeapon(builder);
|
||||
|
||||
MyGame.Sample.Weapon.startWeapon(builder);
|
||||
MyGame.Sample.Weapon.addName(builder, weaponTwo);
|
||||
MyGame.Sample.Weapon.addDamage(builder, 5);
|
||||
var axe = MyGame.Sample.Weapon.endWeapon(builder);
|
||||
|
||||
// Serialize the FlatBuffer data.
|
||||
var name = builder.createString('Orc');
|
||||
|
||||
var treasure = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
|
||||
var inv = MyGame.Sample.Monster.createInventoryVector(builder, treasure);
|
||||
|
||||
var weaps = [sword, axe];
|
||||
var weapons = MyGame.Sample.Monster.createWeaponsVector(builder, weaps);
|
||||
|
||||
var pos = MyGame.Sample.Vec3.createVec3(builder, 1.0, 2.0, 3.0);
|
||||
|
||||
MyGame.Sample.Monster.startMonster(builder);
|
||||
MyGame.Sample.Monster.addPos(builder, pos);
|
||||
MyGame.Sample.Monster.addHp(builder, 300);
|
||||
MyGame.Sample.Monster.addColor(builder, MyGame.Sample.Color.Red)
|
||||
MyGame.Sample.Monster.addName(builder, name);
|
||||
MyGame.Sample.Monster.addInventory(builder, inv);
|
||||
MyGame.Sample.Monster.addWeapons(builder, weapons);
|
||||
MyGame.Sample.Monster.addEquippedType(builder, MyGame.Sample.Equipment.Weapon);
|
||||
MyGame.Sample.Monster.addEquipped(builder, weaps[1]);
|
||||
var orc = MyGame.Sample.Monster.endMonster(builder);
|
||||
|
||||
builder.finish(orc); // You may also call 'MyGame.Example.Monster.finishMonsterBuffer(builder, orc);'.
|
||||
|
||||
// We now have a FlatBuffer that can be stored on disk or sent over a network.
|
||||
|
||||
// ...Code to store to disk or send over a network goes here...
|
||||
|
||||
// Instead, we are going to access it right away, as if we just received it.
|
||||
|
||||
var buf = builder.dataBuffer();
|
||||
|
||||
// Get access to the root:
|
||||
var monster = MyGame.Sample.Monster.getRootAsMonster(buf);
|
||||
|
||||
// Note: We did not set the `mana` field explicitly, so we get back the default value.
|
||||
assert.equal(monster.mana(), 150);
|
||||
assert.equal(monster.hp(), 300);
|
||||
assert.equal(monster.name(), 'Orc');
|
||||
assert.equal(monster.color(), MyGame.Sample.Color.Red);
|
||||
assert.equal(monster.pos().x(), 1.0);
|
||||
assert.equal(monster.pos().y(), 2.0);
|
||||
assert.equal(monster.pos().z(), 3.0);
|
||||
|
||||
// Get and test the `inventory` FlatBuffer `vector`.
|
||||
for (var i = 0; i < monster.inventoryLength(); i++) {
|
||||
assert.equal(monster.inventory(i), i);
|
||||
}
|
||||
|
||||
// Get and test the `weapons` FlatBuffer `vector` of `table`s.
|
||||
var expectedWeaponNames = ['Sword', 'Axe'];
|
||||
var expectedWeaponDamages = [3, 5];
|
||||
for (var i = 0; i < monster.weaponsLength(); i++) {
|
||||
assert.equal(monster.weapons(i).name(), expectedWeaponNames[i]);
|
||||
assert.equal(monster.weapons(i).damage(), expectedWeaponDamages[i]);
|
||||
}
|
||||
|
||||
// Get and test the `equipped` FlatBuffer `union`.
|
||||
assert.equal(monster.equippedType(), MyGame.Sample.Equipment.Weapon);
|
||||
assert.equal(monster.equipped(new MyGame.Sample.Weapon()).name(), 'Axe');
|
||||
assert.equal(monster.equipped(new MyGame.Sample.Weapon()).damage(), 5);
|
||||
|
||||
console.log('The FlatBuffer was successfully created and verified!');
|
||||
}
|
||||
|
||||
main();
|
||||
Reference in New Issue
Block a user