forked from BigfootDev/flatbuffers
Compare commits
59 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
01834de25e | ||
|
|
6f9ea7c23c | ||
|
|
de9791e0a9 | ||
|
|
3e778aca4d | ||
|
|
01f4138618 | ||
|
|
b90cc35a10 | ||
|
|
79d6abb42e | ||
|
|
d1e4daa178 | ||
|
|
4a34cd70dc | ||
|
|
6a9cd4411f | ||
|
|
f7a75173f1 | ||
|
|
a56f9ec50e | ||
|
|
4c71f87619 | ||
|
|
6af83a7d05 | ||
|
|
535ead8d8c | ||
|
|
85aee1f5c3 | ||
|
|
f3a3f45159 | ||
|
|
02d7859f8b | ||
|
|
5785784c8a | ||
|
|
0fb5519585 | ||
|
|
f838017860 | ||
|
|
08ebd202e2 | ||
|
|
a6f4194489 | ||
|
|
7fb785fd89 | ||
|
|
ca71fdfb9a | ||
|
|
a105c26eca | ||
|
|
5b7a02d037 | ||
|
|
f5121615d9 | ||
|
|
34c821f4ad | ||
|
|
802a3a056a | ||
|
|
ee848a02e1 | ||
|
|
ef76b5ece4 | ||
|
|
1703662285 | ||
|
|
991b39edbe | ||
|
|
81799203f1 | ||
|
|
62e4d2e5b2 | ||
|
|
40758674b1 | ||
|
|
4e75867bd2 | ||
|
|
b17d59b18c | ||
|
|
b23493a7d2 | ||
|
|
b50b6be60a | ||
|
|
7bf83f5ea0 | ||
|
|
ca6381bcc8 | ||
|
|
3b8644d32c | ||
|
|
641fbe4658 | ||
|
|
5638a6a900 | ||
|
|
c2668fc0e2 | ||
|
|
b5802b57f2 | ||
|
|
06f2a3dce9 | ||
|
|
75af533e95 | ||
|
|
c95cf661af | ||
|
|
920f3827a0 | ||
|
|
81724e5b20 | ||
|
|
4d6a7aa8b7 | ||
|
|
e61b00359b | ||
|
|
74b5195089 | ||
|
|
07d9485146 | ||
|
|
82da3da3f6 | ||
|
|
a809a2d3f7 |
@@ -5,3 +5,4 @@ root = true
|
||||
indent_style = space
|
||||
indent_size = 2
|
||||
insert_final_newline = true
|
||||
trim_trailing_whitespace = true
|
||||
|
||||
34
.github/workflows/build.yml
vendored
34
.github/workflows/build.yml
vendored
@@ -38,8 +38,10 @@ jobs:
|
||||
run: |
|
||||
chmod +x flatc
|
||||
./flatc --version
|
||||
- name: flatc tests
|
||||
run: python3 tests/flatc/main.py
|
||||
# - name: flatc tests
|
||||
# run: |
|
||||
# yarn global add esbuild
|
||||
# python3 tests/flatc/main.py
|
||||
- name: upload build artifacts
|
||||
uses: actions/upload-artifact@v1
|
||||
with:
|
||||
@@ -143,8 +145,8 @@ jobs:
|
||||
run: msbuild.exe FlatBuffers.sln /p:Configuration=Release /p:Platform=x64
|
||||
- name: test
|
||||
run: Release\flattests.exe
|
||||
- name: flatc tests
|
||||
run: python3 tests/flatc/main.py --flatc Release\flatc.exe
|
||||
# - name: flatc tests
|
||||
# run: python3 tests/flatc/main.py --flatc Release\flatc.exe
|
||||
- name: upload build artifacts
|
||||
uses: actions/upload-artifact@v1
|
||||
with:
|
||||
@@ -245,8 +247,8 @@ jobs:
|
||||
run: |
|
||||
chmod +x Release/flatc
|
||||
Release/flatc --version
|
||||
- name: flatc tests
|
||||
run: python3 tests/flatc/main.py --flatc Release/flatc
|
||||
# - name: flatc tests
|
||||
# run: python3 tests/flatc/main.py --flatc Release/flatc
|
||||
- name: upload build artifacts
|
||||
uses: actions/upload-artifact@v1
|
||||
with:
|
||||
@@ -343,6 +345,22 @@ jobs:
|
||||
- name: Generate gRPC
|
||||
run: scripts/check-grpc-generated-code.py
|
||||
|
||||
build-generator-windows:
|
||||
name: Check Generated Code on Windows
|
||||
runs-on: windows-2019
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- name: Add msbuild to PATH
|
||||
uses: microsoft/setup-msbuild@v1.1
|
||||
- name: cmake
|
||||
run: cmake -G "Visual Studio 16 2019" -A x64 -DCMAKE_BUILD_TYPE=Release -DFLATBUFFERS_BUILD_CPP17=ON -DFLATBUFFERS_STRICT_MODE=ON .
|
||||
- name: build
|
||||
run: msbuild.exe FlatBuffers.sln /p:Configuration=Release /p:Platform=x64
|
||||
- name: Generate
|
||||
run: python3 scripts/check_generate_code.py --flatc Release\flatc.exe
|
||||
- name: Generate gRPC
|
||||
run: python3 scripts/check-grpc-generated-code.py --flatc Release\flatc.exe
|
||||
|
||||
build-benchmarks:
|
||||
name: Build Benchmarks (on Linux)
|
||||
runs-on: ubuntu-latest
|
||||
@@ -485,7 +503,9 @@ jobs:
|
||||
run: yarn compile
|
||||
- name: test
|
||||
working-directory: tests/ts
|
||||
run: python3 TypeScriptTest.py
|
||||
run: |
|
||||
yarn global add esbuild
|
||||
python3 TypeScriptTest.py
|
||||
|
||||
build-dart:
|
||||
name: Build Dart
|
||||
|
||||
@@ -41,9 +41,9 @@ filegroup(
|
||||
"include/flatbuffers/allocator.h",
|
||||
"include/flatbuffers/array.h",
|
||||
"include/flatbuffers/base.h",
|
||||
"include/flatbuffers/bfbs_generator.h",
|
||||
"include/flatbuffers/buffer.h",
|
||||
"include/flatbuffers/buffer_ref.h",
|
||||
"include/flatbuffers/code_generator.h",
|
||||
"include/flatbuffers/code_generators.h",
|
||||
"include/flatbuffers/default_allocator.h",
|
||||
"include/flatbuffers/detached_buffer.h",
|
||||
|
||||
15
CHANGELOG.md
15
CHANGELOG.md
@@ -4,6 +4,21 @@ All major or breaking changes will be documented in this file, as well as any
|
||||
new features that should be highlighted. Minor fixes or improvements are not
|
||||
necessarily listed.
|
||||
|
||||
## [23.3.3 (Mar 3 2023)](https://github.com/google/flatbuffers/releases/tag/v23.3.3)
|
||||
|
||||
* Refactoring of `flatc` generators to use an interface (#7797).
|
||||
|
||||
* Removed legacy cmake support and set min to 3.8 (#7801).
|
||||
|
||||
## [23.1.21 (Jan 21 2023)](https://github.com/google/flatbuffers/releases/tag/v23.1.20)
|
||||
|
||||
* Reworked entry points for Typescript/Javascript and compatibility for single
|
||||
file build (#7510)
|
||||
|
||||
## [23.1.20 (Jan 20 2023)](https://github.com/google/flatbuffers/releases/tag/v23.1.20)
|
||||
|
||||
* Removed go.mod files after some versioning issues were being report (#7780).
|
||||
|
||||
## [23.1.4 (Jan 4 2023)](https://github.com/google/flatbuffers/releases/tag/v23.1.4)
|
||||
|
||||
* Major release! Just kidding, we are continuing the
|
||||
|
||||
@@ -157,6 +157,10 @@ endfunction()
|
||||
# other flagc flags using the FLAGS option to change the behavior of the flatc
|
||||
# tool.
|
||||
#
|
||||
# When the target_link_libraries is done within a different directory than
|
||||
# flatbuffers_generate_headers is called, then the target should also be dependent
|
||||
# the custom generation target called GENERATE_<TARGET>.
|
||||
#
|
||||
# Arguments:
|
||||
# TARGET: The name of the target to generate.
|
||||
# SCHEMAS: The list of schema files to generate code for.
|
||||
@@ -182,6 +186,9 @@ endfunction()
|
||||
# target_link_libraries(MyExecutableTarget
|
||||
# PRIVATE my_generated_headers_target
|
||||
# )
|
||||
#
|
||||
# Optional (only needed within different directory):
|
||||
# add_dependencies(app GENERATE_my_generated_headers_target)
|
||||
function(flatbuffers_generate_headers)
|
||||
# Parse function arguments.
|
||||
set(options)
|
||||
@@ -226,6 +233,8 @@ function(flatbuffers_generate_headers)
|
||||
"--include-prefix" ${FLATBUFFERS_GENERATE_HEADERS_INCLUDE_PREFIX})
|
||||
endif()
|
||||
|
||||
set(generated_custom_commands)
|
||||
|
||||
# Create rules to generate the code for each schema.
|
||||
foreach(schema ${FLATBUFFERS_GENERATE_HEADERS_SCHEMAS})
|
||||
get_filename_component(filename ${schema} NAME_WE)
|
||||
@@ -254,6 +263,7 @@ function(flatbuffers_generate_headers)
|
||||
COMMENT "Building ${schema} flatbuffers...")
|
||||
list(APPEND all_generated_header_files ${generated_include})
|
||||
list(APPEND all_generated_source_files ${generated_source_file})
|
||||
list(APPEND generated_custom_commands "${generated_include}" "${generated_source_file}")
|
||||
|
||||
# Geneate the binary flatbuffers schemas if instructed to.
|
||||
if (NOT ${FLATBUFFERS_GENERATE_HEADERS_BINARY_SCHEMAS_DIR} STREQUAL "")
|
||||
@@ -267,10 +277,17 @@ function(flatbuffers_generate_headers)
|
||||
${schema}
|
||||
DEPENDS ${FLATC_TARGET} ${schema}
|
||||
WORKING_DIRECTORY "${working_dir}")
|
||||
list(APPEND generated_custom_commands "${binary_schema}")
|
||||
list(APPEND all_generated_binary_files ${binary_schema})
|
||||
endif()
|
||||
endforeach()
|
||||
|
||||
# Create an additional target as add_custom_command scope is only within same directory (CMakeFile.txt)
|
||||
set(generate_target GENERATE_${FLATBUFFERS_GENERATE_HEADERS_TARGET})
|
||||
add_custom_target(${generate_target} ALL
|
||||
DEPENDS ${generated_custom_commands}
|
||||
COMMENT "Generating flatbuffer target ${FLATBUFFERS_GENERATE_HEADERS_TARGET}")
|
||||
|
||||
# Set up interface library
|
||||
add_library(${FLATBUFFERS_GENERATE_HEADERS_TARGET} INTERFACE)
|
||||
target_sources(
|
||||
|
||||
@@ -1,780 +0,0 @@
|
||||
# This was the legacy <root>/CMakeLists.txt that supported cmake version 2.8.12.
|
||||
# It was originally copied on Jan 30 2022, and is conditionally included in the
|
||||
# current <root>/CMakeLists.txt if the cmake version used is older than the new
|
||||
# minimum version.
|
||||
#
|
||||
# Only add to this file to fix immediate issues or if a change cannot be made
|
||||
# <root>/CMakeList.txt in a compatible way.
|
||||
|
||||
if (POLICY CMP0048)
|
||||
cmake_policy(SET CMP0048 NEW)
|
||||
if(CMAKE_VERSION VERSION_LESS 3.9)
|
||||
project(FlatBuffers
|
||||
VERSION 2.0.0
|
||||
LANGUAGES CXX)
|
||||
else()
|
||||
project(FlatBuffers
|
||||
DESCRIPTION "Flatbuffers serialization library"
|
||||
VERSION 2.0.0
|
||||
LANGUAGES CXX)
|
||||
endif()
|
||||
else()
|
||||
project(FlatBuffers)
|
||||
endif (POLICY CMP0048)
|
||||
|
||||
include(CMake/Version.cmake)
|
||||
|
||||
# generate compile_commands.json
|
||||
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
||||
|
||||
# NOTE: Code coverage only works on Linux & OSX.
|
||||
option(FLATBUFFERS_CODE_COVERAGE "Enable the code coverage build option." OFF)
|
||||
option(FLATBUFFERS_BUILD_TESTS "Enable the build of tests and samples." ON)
|
||||
option(FLATBUFFERS_INSTALL "Enable the installation of targets." ON)
|
||||
option(FLATBUFFERS_BUILD_FLATLIB "Enable the build of the flatbuffers library"
|
||||
ON)
|
||||
option(FLATBUFFERS_BUILD_FLATC "Enable the build of the flatbuffers compiler"
|
||||
ON)
|
||||
option(FLATBUFFERS_STATIC_FLATC "Build flatbuffers compiler with -static flag"
|
||||
OFF)
|
||||
option(FLATBUFFERS_BUILD_FLATHASH "Enable the build of flathash" ON)
|
||||
option(FLATBUFFERS_BUILD_BENCHMARKS "Enable the build of flatbenchmark. \"
|
||||
Requires C++11."
|
||||
OFF)
|
||||
option(FLATBUFFERS_BUILD_GRPCTEST "Enable the build of grpctest" OFF)
|
||||
option(FLATBUFFERS_BUILD_SHAREDLIB
|
||||
"Enable the build of the flatbuffers shared library"
|
||||
OFF)
|
||||
option(FLATBUFFERS_LIBCXX_WITH_CLANG "Force libc++ when using Clang" ON)
|
||||
# NOTE: Sanitizer check only works on Linux & OSX (gcc & llvm).
|
||||
option(FLATBUFFERS_CODE_SANITIZE
|
||||
"Add '-fsanitize' flags to 'flattests' and 'flatc' targets."
|
||||
OFF)
|
||||
option(FLATBUFFERS_PACKAGE_REDHAT
|
||||
"Build an rpm using the 'package' target."
|
||||
OFF)
|
||||
option(FLATBUFFERS_PACKAGE_DEBIAN
|
||||
"Build an deb using the 'package' target."
|
||||
OFF)
|
||||
option(FLATBUFFERS_BUILD_CPP17
|
||||
"Enable the build of c++17 test target. \"
|
||||
Requirements: Clang6, GCC7, MSVC2017 (_MSC_VER >= 1914) or higher."
|
||||
OFF)
|
||||
option(FLATBUFFERS_BUILD_LEGACY
|
||||
"Run C++ code generator with '--cpp-std c++0x' switch."
|
||||
OFF)
|
||||
option(FLATBUFFERS_ENABLE_PCH
|
||||
"Enable precompile headers support for 'flatbuffers' and 'flatc'. \"
|
||||
Only work if CMake supports 'target_precompile_headers'. \"
|
||||
This can speed up compilation time."
|
||||
OFF)
|
||||
option(FLATBUFFERS_SKIP_MONSTER_EXTRA
|
||||
"Skip generating monster_extra.fbs that contains non-supported numerical\"
|
||||
types." OFF)
|
||||
option(FLATBUFFERS_OSX_BUILD_UNIVERSAL
|
||||
"Enable the build for multiple architectures on OS X (arm64, x86_64)."
|
||||
ON)
|
||||
|
||||
if(NOT FLATBUFFERS_BUILD_FLATC AND FLATBUFFERS_BUILD_TESTS)
|
||||
message(WARNING
|
||||
"Cannot build tests without building the compiler. Tests will be disabled.")
|
||||
set(FLATBUFFERS_BUILD_TESTS OFF)
|
||||
endif()
|
||||
|
||||
if(DEFINED FLATBUFFERS_MAX_PARSING_DEPTH)
|
||||
# Override the default recursion depth limit.
|
||||
add_definitions(-DFLATBUFFERS_MAX_PARSING_DEPTH=${FLATBUFFERS_MAX_PARSING_DEPTH})
|
||||
message(STATUS "FLATBUFFERS_MAX_PARSING_DEPTH: ${FLATBUFFERS_MAX_PARSING_DEPTH}")
|
||||
endif()
|
||||
|
||||
# Auto-detect locale-narrow 'strtod_l' and 'strtoull_l' functions.
|
||||
if(NOT DEFINED FLATBUFFERS_LOCALE_INDEPENDENT)
|
||||
include(CheckCXXSymbolExists)
|
||||
|
||||
set(FLATBUFFERS_LOCALE_INDEPENDENT 0)
|
||||
if(MSVC)
|
||||
check_cxx_symbol_exists(_strtof_l stdlib.h FLATBUFFERS_HAS_STRTOF_L)
|
||||
check_cxx_symbol_exists(_strtoui64_l stdlib.h FLATBUFFERS_HAS_STRTOULL_L)
|
||||
else()
|
||||
check_cxx_symbol_exists(strtof_l stdlib.h FLATBUFFERS_HAS_STRTOF_L)
|
||||
check_cxx_symbol_exists(strtoull_l stdlib.h FLATBUFFERS_HAS_STRTOULL_L)
|
||||
endif()
|
||||
if(FLATBUFFERS_HAS_STRTOF_L AND FLATBUFFERS_HAS_STRTOULL_L)
|
||||
set(FLATBUFFERS_LOCALE_INDEPENDENT 1)
|
||||
endif()
|
||||
endif()
|
||||
add_definitions(-DFLATBUFFERS_LOCALE_INDEPENDENT=$<BOOL:${FLATBUFFERS_LOCALE_INDEPENDENT}>)
|
||||
|
||||
set(FlatBuffers_Library_SRCS
|
||||
include/flatbuffers/allocator.h
|
||||
include/flatbuffers/array.h
|
||||
include/flatbuffers/base.h
|
||||
include/flatbuffers/bfbs_generator.h
|
||||
include/flatbuffers/buffer.h
|
||||
include/flatbuffers/buffer_ref.h
|
||||
include/flatbuffers/default_allocator.h
|
||||
include/flatbuffers/detached_buffer.h
|
||||
include/flatbuffers/flatbuffer_builder.h
|
||||
include/flatbuffers/flatbuffers.h
|
||||
include/flatbuffers/flexbuffers.h
|
||||
include/flatbuffers/hash.h
|
||||
include/flatbuffers/idl.h
|
||||
include/flatbuffers/minireflect.h
|
||||
include/flatbuffers/reflection.h
|
||||
include/flatbuffers/reflection_generated.h
|
||||
include/flatbuffers/registry.h
|
||||
include/flatbuffers/stl_emulation.h
|
||||
include/flatbuffers/string.h
|
||||
include/flatbuffers/struct.h
|
||||
include/flatbuffers/table.h
|
||||
include/flatbuffers/util.h
|
||||
include/flatbuffers/vector.h
|
||||
include/flatbuffers/vector_downward.h
|
||||
include/flatbuffers/verifier.h
|
||||
src/idl_parser.cpp
|
||||
src/idl_gen_text.cpp
|
||||
src/reflection.cpp
|
||||
src/util.cpp
|
||||
)
|
||||
|
||||
set(FlatBuffers_Compiler_SRCS
|
||||
${FlatBuffers_Library_SRCS}
|
||||
src/idl_gen_cpp.cpp
|
||||
src/idl_gen_csharp.cpp
|
||||
src/idl_gen_dart.cpp
|
||||
src/idl_gen_kotlin.cpp
|
||||
src/idl_gen_go.cpp
|
||||
src/idl_gen_java.cpp
|
||||
src/idl_gen_ts.cpp
|
||||
src/idl_gen_php.cpp
|
||||
src/idl_gen_python.cpp
|
||||
src/idl_gen_lobster.cpp
|
||||
src/idl_gen_lua.cpp
|
||||
src/idl_gen_rust.cpp
|
||||
src/idl_gen_fbs.cpp
|
||||
src/idl_gen_grpc.cpp
|
||||
src/idl_gen_json_schema.cpp
|
||||
src/idl_gen_swift.cpp
|
||||
src/flatc.cpp
|
||||
src/flatc_main.cpp
|
||||
src/bfbs_gen.h
|
||||
src/bfbs_gen_lua.h
|
||||
include/flatbuffers/code_generators.h
|
||||
src/bfbs_gen_lua.cpp
|
||||
src/code_generators.cpp
|
||||
grpc/src/compiler/schema_interface.h
|
||||
grpc/src/compiler/cpp_generator.h
|
||||
grpc/src/compiler/cpp_generator.cc
|
||||
grpc/src/compiler/go_generator.h
|
||||
grpc/src/compiler/go_generator.cc
|
||||
grpc/src/compiler/java_generator.h
|
||||
grpc/src/compiler/java_generator.cc
|
||||
grpc/src/compiler/python_generator.h
|
||||
grpc/src/compiler/python_generator.cc
|
||||
grpc/src/compiler/swift_generator.h
|
||||
grpc/src/compiler/swift_generator.cc
|
||||
grpc/src/compiler/ts_generator.h
|
||||
grpc/src/compiler/ts_generator.cc
|
||||
)
|
||||
|
||||
set(FlatHash_SRCS
|
||||
include/flatbuffers/hash.h
|
||||
src/flathash.cpp
|
||||
)
|
||||
|
||||
set(FlatBuffers_Tests_SRCS
|
||||
${FlatBuffers_Library_SRCS}
|
||||
src/idl_gen_fbs.cpp
|
||||
tests/test.cpp
|
||||
tests/test_assert.h
|
||||
tests/test_assert.cpp
|
||||
tests/test_builder.h
|
||||
tests/test_builder.cpp
|
||||
tests/native_type_test_impl.h
|
||||
tests/native_type_test_impl.cpp
|
||||
include/flatbuffers/code_generators.h
|
||||
src/code_generators.cpp
|
||||
# file generate by running compiler on tests/monster_test.fbs
|
||||
${CMAKE_CURRENT_BINARY_DIR}/tests/monster_test_generated.h
|
||||
# file generate by running compiler on namespace_test/namespace_test1.fbs
|
||||
${CMAKE_CURRENT_BINARY_DIR}/tests/namespace_test/namespace_test1_generated.h
|
||||
${CMAKE_CURRENT_BINARY_DIR}/tests/namespace_test/namespace_test2_generated.h
|
||||
# file generate by running compiler on union_vector/union_vector.fbs
|
||||
${CMAKE_CURRENT_BINARY_DIR}/tests/union_vector/union_vector_generated.h
|
||||
# file generate by running compiler on tests/arrays_test.fbs
|
||||
${CMAKE_CURRENT_BINARY_DIR}/tests/arrays_test_generated.h
|
||||
# file generate by running compiler on tests/native_type_test.fbs
|
||||
${CMAKE_CURRENT_BINARY_DIR}/tests/native_type_test_generated.h
|
||||
# file generate by running compiler on tests/monster_extra.fbs
|
||||
${CMAKE_CURRENT_BINARY_DIR}/tests/monster_extra_generated.h
|
||||
# file generate by running compiler on tests/monster_test.fbs
|
||||
${CMAKE_CURRENT_BINARY_DIR}/tests/monster_test_bfbs_generated.h
|
||||
# file generate by running compiler on tests/optional_scalars.fbs
|
||||
${CMAKE_CURRENT_BINARY_DIR}/tests/optional_scalars_generated.h
|
||||
)
|
||||
|
||||
set(FlatBuffers_Tests_CPP17_SRCS
|
||||
${FlatBuffers_Library_SRCS}
|
||||
tests/test_assert.h
|
||||
tests/test_assert.cpp
|
||||
tests/cpp17/test_cpp17.cpp
|
||||
# file generate by running compiler on tests/monster_test.fbs
|
||||
${CMAKE_CURRENT_BINARY_DIR}/tests/cpp17/generated_cpp17/monster_test_generated.h
|
||||
${CMAKE_CURRENT_BINARY_DIR}/tests/monster_test_generated.h
|
||||
${CMAKE_CURRENT_BINARY_DIR}/tests/cpp17/generated_cpp17/optional_scalars_generated.h
|
||||
${CMAKE_CURRENT_BINARY_DIR}/tests/optional_scalars_generated.h
|
||||
)
|
||||
|
||||
set(FlatBuffers_Sample_Binary_SRCS
|
||||
include/flatbuffers/flatbuffers.h
|
||||
samples/sample_binary.cpp
|
||||
# file generated by running compiler on samples/monster.fbs
|
||||
${CMAKE_CURRENT_BINARY_DIR}/samples/monster_generated.h
|
||||
)
|
||||
|
||||
set(FlatBuffers_Sample_Text_SRCS
|
||||
${FlatBuffers_Library_SRCS}
|
||||
samples/sample_text.cpp
|
||||
# file generated by running compiler on samples/monster.fbs
|
||||
${CMAKE_CURRENT_BINARY_DIR}/samples/monster_generated.h
|
||||
)
|
||||
|
||||
set(FlatBuffers_Sample_BFBS_SRCS
|
||||
${FlatBuffers_Library_SRCS}
|
||||
samples/sample_bfbs.cpp
|
||||
# file generated by running compiler on samples/monster.fbs
|
||||
${CMAKE_CURRENT_BINARY_DIR}/samples/monster_generated.h
|
||||
)
|
||||
|
||||
set(FlatBuffers_GRPCTest_SRCS
|
||||
include/flatbuffers/flatbuffers.h
|
||||
include/flatbuffers/grpc.h
|
||||
include/flatbuffers/util.h
|
||||
src/util.cpp
|
||||
tests/monster_test.grpc.fb.h
|
||||
tests/test_assert.h
|
||||
tests/test_builder.h
|
||||
tests/monster_test.grpc.fb.cc
|
||||
tests/test_assert.cpp
|
||||
tests/test_builder.cpp
|
||||
grpc/tests/grpctest.cpp
|
||||
grpc/tests/message_builder_test.cpp
|
||||
# file generate by running compiler on tests/monster_test.fbs
|
||||
${CMAKE_CURRENT_BINARY_DIR}/tests/monster_test_generated.h
|
||||
)
|
||||
|
||||
# source_group(Compiler FILES ${FlatBuffers_Compiler_SRCS})
|
||||
# source_group(Tests FILES ${FlatBuffers_Tests_SRCS})
|
||||
|
||||
if(EXISTS "${CMAKE_TOOLCHAIN_FILE}")
|
||||
# do not apply any global settings if the toolchain
|
||||
# is being configured externally
|
||||
message(STATUS "Using toolchain file: ${CMAKE_TOOLCHAIN_FILE}.")
|
||||
elseif(CMAKE_COMPILER_IS_GNUCXX)
|
||||
if(CYGWIN)
|
||||
set(CMAKE_CXX_FLAGS
|
||||
"${CMAKE_CXX_FLAGS} -std=gnu++11")
|
||||
else(CYGWIN)
|
||||
set(CMAKE_CXX_FLAGS
|
||||
"${CMAKE_CXX_FLAGS} -std=c++0x")
|
||||
endif(CYGWIN)
|
||||
set(CMAKE_CXX_FLAGS
|
||||
"${CMAKE_CXX_FLAGS} -Wall -pedantic -Werror -Wextra -Werror=shadow")
|
||||
set(FLATBUFFERS_PRIVATE_CXX_FLAGS "-Wold-style-cast")
|
||||
if (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 4.4)
|
||||
if (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 7.0)
|
||||
set(CMAKE_CXX_FLAGS
|
||||
"${CMAKE_CXX_FLAGS} -faligned-new -Werror=implicit-fallthrough=2")
|
||||
endif()
|
||||
set(CMAKE_CXX_FLAGS
|
||||
"${CMAKE_CXX_FLAGS} -Wunused-result -Werror=unused-result -Wunused-parameter -Werror=unused-parameter")
|
||||
endif()
|
||||
|
||||
# Certain platforms such as ARM do not use signed chars by default
|
||||
# which causes issues with certain bounds checks.
|
||||
set(CMAKE_CXX_FLAGS
|
||||
"${CMAKE_CXX_FLAGS} -fsigned-char")
|
||||
|
||||
# MSVC **MUST** come before the Clang check, as clang-cl is flagged by CMake as "MSVC", but it still textually
|
||||
# matches as Clang in its Compiler Id :)
|
||||
# Note: in CMake >= 3.14 we can check CMAKE_CXX_COMPILER_FRONTEND_VARIANT STREQUAL "GNU" or "MSVC" to differentiate...
|
||||
elseif(MSVC)
|
||||
# Visual Studio pedantic build settings
|
||||
# warning C4512: assignment operator could not be generated
|
||||
# warning C4316: object allocated on the heap may not be aligned
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W4 /WX /wd4512 /wd4316")
|
||||
|
||||
if(${CMAKE_CXX_COMPILER_ID} MATCHES "Clang")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /D_CRT_SECURE_NO_WARNINGS")
|
||||
endif()
|
||||
|
||||
elseif(${CMAKE_CXX_COMPILER_ID} MATCHES "Clang")
|
||||
if(APPLE)
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
|
||||
|
||||
if(FLATBUFFERS_OSX_BUILD_UNIVERSAL)
|
||||
set(CMAKE_OSX_ARCHITECTURES "arm64;x86_64")
|
||||
endif()
|
||||
else()
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x")
|
||||
endif()
|
||||
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -pedantic -Werror -Wextra -Wno-unused-parameter")
|
||||
set(FLATBUFFERS_PRIVATE_CXX_FLAGS "-Wold-style-cast")
|
||||
if(NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 3.8)
|
||||
list(APPEND FLATBUFFERS_PRIVATE_CXX_FLAGS "-Wimplicit-fallthrough" "-Wextra-semi" "-Werror=unused-private-field") # enable warning
|
||||
endif()
|
||||
if(FLATBUFFERS_LIBCXX_WITH_CLANG)
|
||||
if(NOT "${CMAKE_SYSTEM_NAME}" MATCHES "Linux")
|
||||
set(CMAKE_CXX_FLAGS
|
||||
"${CMAKE_CXX_FLAGS} -stdlib=libc++")
|
||||
endif()
|
||||
if(NOT ("${CMAKE_SYSTEM_NAME}" MATCHES "FreeBSD" OR
|
||||
"${CMAKE_SYSTEM_NAME}" MATCHES "Linux"))
|
||||
set(CMAKE_EXE_LINKER_FLAGS
|
||||
"${CMAKE_EXE_LINKER_FLAGS} -lc++abi")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
# Certain platforms such as ARM do not use signed chars by default
|
||||
# which causes issues with certain bounds checks.
|
||||
set(CMAKE_CXX_FLAGS
|
||||
"${CMAKE_CXX_FLAGS} -fsigned-char")
|
||||
|
||||
endif()
|
||||
|
||||
# Append FLATBUFFERS_CXX_FLAGS to CMAKE_CXX_FLAGS.
|
||||
if(DEFINED FLATBUFFERS_CXX_FLAGS AND NOT EXISTS "${CMAKE_TOOLCHAIN_FILE}")
|
||||
message(STATUS "extend CXX_FLAGS with ${FLATBUFFERS_CXX_FLAGS}")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${FLATBUFFERS_CXX_FLAGS}")
|
||||
endif()
|
||||
message(STATUS "CMAKE_CXX_FLAGS: ${CMAKE_CXX_FLAGS}")
|
||||
|
||||
if(FLATBUFFERS_CODE_COVERAGE)
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -fprofile-arcs -ftest-coverage")
|
||||
set(CMAKE_EXE_LINKER_FLAGS
|
||||
"${CMAKE_EXE_LINKER_FLAGS} -fprofile-arcs -ftest-coverage")
|
||||
endif()
|
||||
|
||||
function(add_fsanitize_to_target _target _sanitizer)
|
||||
if(WIN32)
|
||||
target_compile_definitions(${_target} PRIVATE FLATBUFFERS_MEMORY_LEAK_TRACKING)
|
||||
message(STATUS "Sanitizer MSVC::_CrtDumpMemoryLeaks added to ${_target}")
|
||||
else()
|
||||
# FLATBUFFERS_CODE_SANITIZE: boolean {ON,OFF,YES,NO} or string with list of sanitizer.
|
||||
# List of sanitizer is string starts with '=': "=address,undefined,thread,memory".
|
||||
if((${CMAKE_CXX_COMPILER_ID} MATCHES "Clang") OR
|
||||
((${CMAKE_CXX_COMPILER_ID} MATCHES "GNU") AND NOT (CMAKE_CXX_COMPILER_VERSION VERSION_LESS "4.9"))
|
||||
)
|
||||
set(_sanitizer_flags "=address,undefined")
|
||||
if(_sanitizer MATCHES "=.*")
|
||||
# override default by user-defined sanitizer list
|
||||
set(_sanitizer_flags ${_sanitizer})
|
||||
endif()
|
||||
target_compile_options(${_target} PRIVATE
|
||||
-g -fsigned-char -fno-omit-frame-pointer
|
||||
"-fsanitize${_sanitizer_flags}")
|
||||
target_link_libraries(${_target} PRIVATE
|
||||
"-fsanitize${_sanitizer_flags}")
|
||||
set_property(TARGET ${_target} PROPERTY POSITION_INDEPENDENT_CODE ON)
|
||||
message(STATUS "Sanitizer ${_sanitizer_flags} added to ${_target}")
|
||||
endif()
|
||||
endif()
|
||||
endfunction()
|
||||
|
||||
function(add_pch_to_target _target _pch_header)
|
||||
if(COMMAND target_precompile_headers)
|
||||
target_precompile_headers(${_target} PRIVATE ${_pch_header})
|
||||
if(NOT MSVC)
|
||||
set_source_files_properties(src/util.cpp PROPERTIES SKIP_PRECOMPILE_HEADERS ON)
|
||||
endif()
|
||||
endif()
|
||||
endfunction()
|
||||
|
||||
if(BIICODE)
|
||||
include(biicode/cmake/biicode.cmake)
|
||||
return()
|
||||
endif()
|
||||
|
||||
include_directories(include)
|
||||
include_directories(grpc)
|
||||
|
||||
if(FLATBUFFERS_BUILD_FLATLIB)
|
||||
add_library(flatbuffers STATIC ${FlatBuffers_Library_SRCS})
|
||||
# Attach header directory for when build via add_subdirectory().
|
||||
target_include_directories(flatbuffers INTERFACE
|
||||
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>)
|
||||
target_compile_options(flatbuffers PRIVATE "${FLATBUFFERS_PRIVATE_CXX_FLAGS}")
|
||||
if(FLATBUFFERS_ENABLE_PCH)
|
||||
add_pch_to_target(flatbuffers include/flatbuffers/pch/pch.h)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if(FLATBUFFERS_BUILD_FLATC)
|
||||
add_executable(flatc ${FlatBuffers_Compiler_SRCS})
|
||||
if(FLATBUFFERS_ENABLE_PCH)
|
||||
add_pch_to_target(flatc include/flatbuffers/pch/flatc_pch.h)
|
||||
endif()
|
||||
target_compile_options(flatc PRIVATE "${FLATBUFFERS_PRIVATE_CXX_FLAGS}")
|
||||
if(FLATBUFFERS_CODE_SANITIZE AND NOT WIN32)
|
||||
add_fsanitize_to_target(flatc ${FLATBUFFERS_CODE_SANITIZE})
|
||||
endif()
|
||||
if(NOT FLATBUFFERS_FLATC_EXECUTABLE)
|
||||
set(FLATBUFFERS_FLATC_EXECUTABLE $<TARGET_FILE:flatc>)
|
||||
endif()
|
||||
if(MSVC)
|
||||
# Make flatc.exe not depend on runtime dlls for easy distribution.
|
||||
target_compile_options(flatc PUBLIC $<$<CONFIG:Release>:/MT>)
|
||||
endif()
|
||||
if(FLATBUFFERS_STATIC_FLATC AND NOT MSVC)
|
||||
target_link_libraries(flatc PRIVATE -static)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if(FLATBUFFERS_BUILD_FLATHASH)
|
||||
add_executable(flathash ${FlatHash_SRCS})
|
||||
endif()
|
||||
|
||||
if(FLATBUFFERS_BUILD_SHAREDLIB)
|
||||
add_library(flatbuffers_shared SHARED ${FlatBuffers_Library_SRCS})
|
||||
|
||||
# Shared object version: "major.minor.micro"
|
||||
# - micro updated every release when there is no API/ABI changes
|
||||
# - minor updated when there are additions in API/ABI
|
||||
# - major (ABI number) updated when there are changes in ABI (or removals)
|
||||
set(FlatBuffers_Library_SONAME_MAJOR ${VERSION_MAJOR})
|
||||
set(FlatBuffers_Library_SONAME_FULL "${FlatBuffers_Library_SONAME_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}")
|
||||
set_target_properties(flatbuffers_shared PROPERTIES OUTPUT_NAME flatbuffers
|
||||
SOVERSION "${FlatBuffers_Library_SONAME_MAJOR}"
|
||||
VERSION "${FlatBuffers_Library_SONAME_FULL}")
|
||||
if(FLATBUFFERS_ENABLE_PCH)
|
||||
add_pch_to_target(flatbuffers_shared include/flatbuffers/pch/pch.h)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
# Global list of generated files.
|
||||
# Use the global property to be independent of PARENT_SCOPE.
|
||||
set_property(GLOBAL PROPERTY FBS_GENERATED_OUTPUTS)
|
||||
|
||||
function(get_generated_output generated_files)
|
||||
get_property(tmp GLOBAL PROPERTY FBS_GENERATED_OUTPUTS)
|
||||
set(${generated_files} ${tmp} PARENT_SCOPE)
|
||||
endfunction(get_generated_output)
|
||||
|
||||
function(register_generated_output file_name)
|
||||
get_property(tmp GLOBAL PROPERTY FBS_GENERATED_OUTPUTS)
|
||||
list(APPEND tmp ${file_name})
|
||||
set_property(GLOBAL PROPERTY FBS_GENERATED_OUTPUTS ${tmp})
|
||||
endfunction(register_generated_output)
|
||||
|
||||
function(compile_flatbuffers_schema_to_cpp_opt SRC_FBS OPT)
|
||||
if(FLATBUFFERS_BUILD_LEGACY)
|
||||
set(OPT ${OPT};--cpp-std c++0x)
|
||||
else()
|
||||
# --cpp-std is defined by flatc default settings.
|
||||
endif()
|
||||
message(STATUS "`${SRC_FBS}`: add generation of C++ code with '${OPT}'")
|
||||
get_filename_component(SRC_FBS_DIR ${SRC_FBS} PATH)
|
||||
string(REGEX REPLACE "\\.fbs$" "_generated.h" GEN_HEADER ${SRC_FBS})
|
||||
add_custom_command(
|
||||
OUTPUT ${GEN_HEADER}
|
||||
COMMAND "${FLATBUFFERS_FLATC_EXECUTABLE}"
|
||||
--cpp --gen-mutable --gen-object-api --reflect-names
|
||||
--cpp-ptr-type flatbuffers::unique_ptr # Used to test with C++98 STLs
|
||||
${OPT}
|
||||
-I "${CMAKE_CURRENT_SOURCE_DIR}/tests/include_test"
|
||||
-o "${SRC_FBS_DIR}"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/${SRC_FBS}"
|
||||
DEPENDS flatc
|
||||
COMMENT "Run generation: '${GEN_HEADER}'")
|
||||
register_generated_output(${GEN_HEADER})
|
||||
endfunction()
|
||||
|
||||
function(compile_flatbuffers_schema_to_cpp SRC_FBS)
|
||||
compile_flatbuffers_schema_to_cpp_opt(${SRC_FBS} "--no-includes;--gen-compare")
|
||||
endfunction()
|
||||
|
||||
function(compile_flatbuffers_schema_to_binary SRC_FBS)
|
||||
message(STATUS "`${SRC_FBS}`: add generation of binary (.bfbs) schema")
|
||||
get_filename_component(SRC_FBS_DIR ${SRC_FBS} PATH)
|
||||
string(REGEX REPLACE "\\.fbs$" ".bfbs" GEN_BINARY_SCHEMA ${SRC_FBS})
|
||||
# For details about flags see generate_code.py
|
||||
add_custom_command(
|
||||
OUTPUT ${GEN_BINARY_SCHEMA}
|
||||
COMMAND "${FLATBUFFERS_FLATC_EXECUTABLE}"
|
||||
-b --schema --bfbs-comments --bfbs-builtins
|
||||
--bfbs-filenames ${SRC_FBS_DIR}
|
||||
-I "${CMAKE_CURRENT_SOURCE_DIR}/tests/include_test"
|
||||
-o "${SRC_FBS_DIR}"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/${SRC_FBS}"
|
||||
DEPENDS flatc
|
||||
COMMENT "Run generation: '${GEN_BINARY_SCHEMA}'")
|
||||
register_generated_output(${GEN_BINARY_SCHEMA})
|
||||
endfunction()
|
||||
|
||||
function(compile_flatbuffers_schema_to_embedded_binary SRC_FBS OPT)
|
||||
if(FLATBUFFERS_BUILD_LEGACY)
|
||||
set(OPT ${OPT};--cpp-std c++0x)
|
||||
else()
|
||||
# --cpp-std is defined by flatc default settings.
|
||||
endif()
|
||||
message(STATUS "`${SRC_FBS}`: add generation of C++ embedded binary schema code with '${OPT}'")
|
||||
get_filename_component(SRC_FBS_DIR ${SRC_FBS} PATH)
|
||||
string(REGEX REPLACE "\\.fbs$" "_bfbs_generated.h" GEN_BFBS_HEADER ${SRC_FBS})
|
||||
# For details about flags see generate_code.py
|
||||
add_custom_command(
|
||||
OUTPUT ${GEN_BFBS_HEADER}
|
||||
COMMAND "${FLATBUFFERS_FLATC_EXECUTABLE}"
|
||||
--cpp --gen-mutable --gen-object-api --reflect-names
|
||||
--cpp-ptr-type flatbuffers::unique_ptr # Used to test with C++98 STLs
|
||||
${OPT}
|
||||
--bfbs-comments --bfbs-builtins --bfbs-gen-embed
|
||||
--bfbs-filenames ${SRC_FBS_DIR}
|
||||
-I "${CMAKE_CURRENT_SOURCE_DIR}/tests/include_test"
|
||||
-o "${SRC_FBS_DIR}"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/${SRC_FBS}"
|
||||
DEPENDS flatc
|
||||
COMMENT "Run generation: '${GEN_BFBS_HEADER}'")
|
||||
register_generated_output(${GEN_BFBS_HEADER})
|
||||
endfunction()
|
||||
|
||||
# Look if we have python 3.5 installed so that we can run the generate code
|
||||
# python script after flatc is built.
|
||||
find_package(PythonInterp 3.5)
|
||||
|
||||
if(PYTHONINTERP_FOUND AND
|
||||
# Skip doing this if the MSVC version is below VS 12.
|
||||
# https://cmake.org/cmake/help/latest/variable/MSVC_VERSION.html
|
||||
(NOT MSVC OR MSVC_VERSION GREATER 1800))
|
||||
set(GENERATION_SCRIPT ${PYTHON_EXECUTABLE} scripts/generate_code.py)
|
||||
if(FLATBUFFERS_BUILD_LEGACY)
|
||||
# Need to set --cpp-std c++-0x options
|
||||
set(GENERATION_SCRIPT ${GENERATION_SCRIPT} --cpp-0x)
|
||||
endif()
|
||||
if(FLATBUFFERS_SKIP_MONSTER_EXTRA)
|
||||
set(GENERATION_SCRIPT ${GENERATION_SCRIPT} --skip-monster-extra)
|
||||
endif()
|
||||
add_custom_command(
|
||||
TARGET flatc
|
||||
POST_BUILD
|
||||
COMMAND ${GENERATION_SCRIPT} --flatc "${FLATBUFFERS_FLATC_EXECUTABLE}"
|
||||
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
|
||||
COMMENT "Running ${GENERATION_SCRIPT}..."
|
||||
VERBATIM)
|
||||
else()
|
||||
message("No Python3 interpreter found! Unable to generate files automatically.")
|
||||
endif()
|
||||
|
||||
if(FLATBUFFERS_BUILD_TESTS)
|
||||
file(COPY "${CMAKE_CURRENT_SOURCE_DIR}/tests" DESTINATION "${CMAKE_CURRENT_BINARY_DIR}")
|
||||
file(COPY "${CMAKE_CURRENT_SOURCE_DIR}/samples" DESTINATION "${CMAKE_CURRENT_BINARY_DIR}")
|
||||
|
||||
# TODO Add (monster_test.fbs monsterdata_test.json)->monsterdata_test.mon
|
||||
compile_flatbuffers_schema_to_cpp(tests/monster_test.fbs)
|
||||
compile_flatbuffers_schema_to_binary(tests/monster_test.fbs)
|
||||
compile_flatbuffers_schema_to_cpp_opt(tests/namespace_test/namespace_test1.fbs "--no-includes;--gen-compare;--gen-name-strings")
|
||||
compile_flatbuffers_schema_to_cpp_opt(tests/namespace_test/namespace_test2.fbs "--no-includes;--gen-compare;--gen-name-strings")
|
||||
compile_flatbuffers_schema_to_cpp_opt(tests/union_vector/union_vector.fbs "--no-includes;--gen-compare;--gen-name-strings")
|
||||
compile_flatbuffers_schema_to_cpp(tests/optional_scalars.fbs)
|
||||
compile_flatbuffers_schema_to_cpp_opt(tests/native_type_test.fbs "")
|
||||
compile_flatbuffers_schema_to_cpp_opt(tests/arrays_test.fbs "--scoped-enums;--gen-compare")
|
||||
compile_flatbuffers_schema_to_binary(tests/arrays_test.fbs)
|
||||
compile_flatbuffers_schema_to_embedded_binary(tests/monster_test.fbs "--no-includes;--gen-compare")
|
||||
if(NOT (MSVC AND (MSVC_VERSION LESS 1900)))
|
||||
compile_flatbuffers_schema_to_cpp(tests/monster_extra.fbs) # Test floating-point NAN/INF.
|
||||
endif()
|
||||
include_directories(${CMAKE_CURRENT_BINARY_DIR}/tests)
|
||||
add_executable(flattests ${FlatBuffers_Tests_SRCS})
|
||||
add_dependencies(flattests generated_code)
|
||||
set_property(TARGET flattests
|
||||
PROPERTY COMPILE_DEFINITIONS FLATBUFFERS_TRACK_VERIFIER_BUFFER_SIZE
|
||||
FLATBUFFERS_DEBUG_VERIFICATION_FAILURE=1)
|
||||
if(FLATBUFFERS_CODE_SANITIZE)
|
||||
add_fsanitize_to_target(flattests ${FLATBUFFERS_CODE_SANITIZE})
|
||||
endif()
|
||||
|
||||
compile_flatbuffers_schema_to_cpp(samples/monster.fbs)
|
||||
compile_flatbuffers_schema_to_binary(samples/monster.fbs)
|
||||
include_directories(${CMAKE_CURRENT_BINARY_DIR}/samples)
|
||||
add_executable(flatsamplebinary ${FlatBuffers_Sample_Binary_SRCS})
|
||||
add_dependencies(flatsamplebinary generated_code)
|
||||
add_executable(flatsampletext ${FlatBuffers_Sample_Text_SRCS})
|
||||
add_dependencies(flatsampletext generated_code)
|
||||
add_executable(flatsamplebfbs ${FlatBuffers_Sample_BFBS_SRCS})
|
||||
add_dependencies(flatsamplebfbs generated_code)
|
||||
|
||||
if(FLATBUFFERS_BUILD_CPP17)
|
||||
# Don't generate header for flattests_cpp17 target.
|
||||
# This target uses "generated_cpp17/monster_test_generated.h"
|
||||
# produced by direct call of generate_code.py script.
|
||||
add_executable(flattests_cpp17 ${FlatBuffers_Tests_CPP17_SRCS})
|
||||
add_dependencies(flattests_cpp17 generated_code)
|
||||
target_compile_features(flattests_cpp17 PRIVATE cxx_std_17)
|
||||
target_compile_definitions(flattests_cpp17 PRIVATE
|
||||
FLATBUFFERS_TRACK_VERIFIER_BUFFER_SIZE
|
||||
FLATBUFFERS_DEBUG_VERIFICATION_FAILURE=1
|
||||
)
|
||||
if(FLATBUFFERS_CODE_SANITIZE)
|
||||
add_fsanitize_to_target(flattests_cpp17 ${FLATBUFFERS_CODE_SANITIZE})
|
||||
endif()
|
||||
endif(FLATBUFFERS_BUILD_CPP17)
|
||||
endif()
|
||||
|
||||
if(FLATBUFFERS_BUILD_GRPCTEST)
|
||||
if(CMAKE_COMPILER_IS_GNUCXX)
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unused-parameter -Wno-shadow")
|
||||
endif()
|
||||
if(NOT GRPC_INSTALL_PATH)
|
||||
message(SEND_ERROR "GRPC_INSTALL_PATH variable is not defined. See grpc/README.md")
|
||||
endif()
|
||||
if(NOT PROTOBUF_DOWNLOAD_PATH)
|
||||
message(SEND_ERROR "PROTOBUF_DOWNLOAD_PATH variable is not defined. See grpc/README.md")
|
||||
endif()
|
||||
INCLUDE_DIRECTORIES(${GRPC_INSTALL_PATH}/include)
|
||||
INCLUDE_DIRECTORIES(${PROTOBUF_DOWNLOAD_PATH}/src)
|
||||
find_package(Threads REQUIRED)
|
||||
list(APPEND CMAKE_PREFIX_PATH ${GRPC_INSTALL_PATH})
|
||||
find_package(absl CONFIG REQUIRED)
|
||||
find_package(protobuf CONFIG REQUIRED)
|
||||
find_package(gRPC CONFIG REQUIRED)
|
||||
add_executable(grpctest ${FlatBuffers_GRPCTest_SRCS})
|
||||
add_dependencies(grpctest generated_code)
|
||||
target_link_libraries(grpctest PRIVATE gRPC::grpc++_unsecure gRPC::grpc_unsecure gRPC::gpr pthread dl)
|
||||
if(FLATBUFFERS_CODE_SANITIZE AND NOT WIN32)
|
||||
# GRPC test has problems with alignment and will fail under ASAN/UBSAN.
|
||||
# add_fsanitize_to_target(grpctest ${FLATBUFFERS_CODE_SANITIZE})
|
||||
endif()
|
||||
endif()
|
||||
|
||||
|
||||
if(FLATBUFFERS_INSTALL)
|
||||
include(GNUInstallDirs)
|
||||
|
||||
install(DIRECTORY include/flatbuffers DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
|
||||
|
||||
set(FB_CMAKE_DIR "${CMAKE_INSTALL_LIBDIR}/cmake/flatbuffers")
|
||||
|
||||
configure_file(CMake/flatbuffers-config-version.cmake.in flatbuffers-config-version.cmake @ONLY)
|
||||
install(
|
||||
FILES "CMake/flatbuffers-config.cmake" "${CMAKE_CURRENT_BINARY_DIR}/flatbuffers-config-version.cmake"
|
||||
DESTINATION ${FB_CMAKE_DIR}
|
||||
)
|
||||
|
||||
if(FLATBUFFERS_BUILD_FLATLIB)
|
||||
if(CMAKE_VERSION VERSION_LESS 3.0)
|
||||
install(
|
||||
TARGETS flatbuffers EXPORT FlatBuffersTargets
|
||||
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
||||
)
|
||||
else()
|
||||
install(
|
||||
TARGETS flatbuffers EXPORT FlatBuffersTargets
|
||||
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
||||
INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
|
||||
)
|
||||
endif()
|
||||
|
||||
install(EXPORT FlatBuffersTargets
|
||||
FILE FlatBuffersTargets.cmake
|
||||
NAMESPACE flatbuffers::
|
||||
DESTINATION ${FB_CMAKE_DIR}
|
||||
)
|
||||
endif()
|
||||
|
||||
if(FLATBUFFERS_BUILD_FLATC)
|
||||
install(
|
||||
TARGETS flatc EXPORT FlatcTargets
|
||||
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
|
||||
)
|
||||
|
||||
install(
|
||||
EXPORT FlatcTargets
|
||||
FILE FlatcTargets.cmake
|
||||
NAMESPACE flatbuffers::
|
||||
DESTINATION ${FB_CMAKE_DIR}
|
||||
)
|
||||
endif()
|
||||
|
||||
if(FLATBUFFERS_BUILD_SHAREDLIB)
|
||||
if(CMAKE_VERSION VERSION_LESS 3.0)
|
||||
install(
|
||||
TARGETS flatbuffers_shared EXPORT FlatBuffersSharedTargets
|
||||
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
||||
RUNTIME DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
||||
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
||||
)
|
||||
else()
|
||||
install(
|
||||
TARGETS flatbuffers_shared EXPORT FlatBuffersSharedTargets
|
||||
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
||||
RUNTIME DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
||||
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
||||
INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
|
||||
)
|
||||
endif()
|
||||
|
||||
install(
|
||||
EXPORT FlatBuffersSharedTargets
|
||||
FILE FlatBuffersSharedTargets.cmake
|
||||
NAMESPACE flatbuffers::
|
||||
DESTINATION ${FB_CMAKE_DIR}
|
||||
)
|
||||
endif()
|
||||
|
||||
if(FLATBUFFERS_BUILD_SHAREDLIB OR FLATBUFFERS_BUILD_FLATLIB)
|
||||
configure_file(CMake/flatbuffers.pc.in flatbuffers.pc @ONLY)
|
||||
install(
|
||||
FILES "${CMAKE_CURRENT_BINARY_DIR}/flatbuffers.pc"
|
||||
DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig
|
||||
)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if(FLATBUFFERS_BUILD_TESTS)
|
||||
enable_testing()
|
||||
|
||||
add_test(NAME flattests COMMAND flattests)
|
||||
if(FLATBUFFERS_BUILD_CPP17)
|
||||
add_test(NAME flattests_cpp17 COMMAND flattests_cpp17)
|
||||
endif()
|
||||
if(FLATBUFFERS_BUILD_GRPCTEST)
|
||||
add_test(NAME grpctest COMMAND grpctest)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
# This target is sync-barrier.
|
||||
# Other generate-dependent targets can depend on 'generated_code' only.
|
||||
get_generated_output(fbs_generated)
|
||||
if(fbs_generated)
|
||||
# message(STATUS "Add generated_code target with files:${fbs_generated}")
|
||||
add_custom_target(generated_code
|
||||
DEPENDS ${fbs_generated}
|
||||
COMMENT "All generated files were updated.")
|
||||
endif()
|
||||
|
||||
include(CMake/BuildFlatBuffers.cmake)
|
||||
|
||||
if(UNIX)
|
||||
# Use of CPack only supported on Linux systems.
|
||||
if(FLATBUFFERS_PACKAGE_DEBIAN)
|
||||
include(CMake/PackageDebian.cmake)
|
||||
include(CPack)
|
||||
endif()
|
||||
if (FLATBUFFERS_PACKAGE_REDHAT)
|
||||
include(CMake/PackageRedhat.cmake)
|
||||
include(CPack)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
# Include for running Google Benchmarks.
|
||||
if(FLATBUFFERS_BUILD_BENCHMARKS AND CMAKE_VERSION VERSION_GREATER 3.13)
|
||||
add_subdirectory(benchmarks)
|
||||
endif()
|
||||
|
||||
# Add FlatBuffers::FlatBuffers interface, needed for FetchContent_Declare
|
||||
add_library(FlatBuffers INTERFACE)
|
||||
add_library(FlatBuffers::FlatBuffers ALIAS FlatBuffers)
|
||||
target_include_directories(
|
||||
FlatBuffers
|
||||
INTERFACE $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
|
||||
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/include>)
|
||||
@@ -17,23 +17,9 @@ if (UNIX)
|
||||
SET(CPACK_PACKAGE_VERSION "${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}-${VERSION_COMMIT}")
|
||||
SET(CPACK_DEBIAN_PACKAGE_VERSION "${CPACK_PACKAGE_VERSION}")
|
||||
|
||||
# Derive architecture
|
||||
IF(NOT CPACK_DEBIAN_PACKAGE_ARCHITECTURE)
|
||||
FIND_PROGRAM(DPKG_CMD dpkg)
|
||||
IF(NOT DPKG_CMD)
|
||||
MESSAGE(STATUS "Can not find dpkg in your path, default to i386.")
|
||||
SET(CPACK_DEBIAN_PACKAGE_ARCHITECTURE i386)
|
||||
ENDIF(NOT DPKG_CMD)
|
||||
EXECUTE_PROCESS(COMMAND "${DPKG_CMD}" --print-architecture
|
||||
OUTPUT_VARIABLE CPACK_DEBIAN_PACKAGE_ARCHITECTURE
|
||||
OUTPUT_STRIP_TRAILING_WHITESPACE
|
||||
)
|
||||
ENDIF(NOT CPACK_DEBIAN_PACKAGE_ARCHITECTURE)
|
||||
|
||||
# Package name
|
||||
SET(CPACK_DEBIAN_PACKAGE_NAME "flatbuffers")
|
||||
SET(CPACK_RESOURCE_FILE_LICENSE ${CMAKE_SOURCE_DIR}/LICENSE.txt)
|
||||
SET(CPACK_PACKAGE_FILE_NAME
|
||||
"${CPACK_DEBIAN_PACKAGE_NAME}_${CPACK_DEBIAN_PACKAGE_VERSION}_${CPACK_DEBIAN_PACKAGE_ARCHITECTURE}")
|
||||
SET(CPACK_RESOURCE_FILE_LICENSE ${CMAKE_SOURCE_DIR}/LICENSE)
|
||||
set(CPACK_DEBIAN_FILE_NAME "DEB-DEFAULT")
|
||||
|
||||
endif(UNIX)
|
||||
|
||||
@@ -15,7 +15,7 @@ if (UNIX)
|
||||
|
||||
set(CPACK_RPM_PACKAGE_NAME "flatbuffers")
|
||||
|
||||
# Assume this is not a cross complation build.
|
||||
# Assume this is not a cross compilation build.
|
||||
if(NOT CPACK_RPM_PACKAGE_ARCHITECTURE)
|
||||
set(CPACK_RPM_PACKAGE_ARCHITECTURE "${CMAKE_SYSTEM_PROCESSOR}")
|
||||
endif(NOT CPACK_RPM_PACKAGE_ARCHITECTURE)
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
set(VERSION_MAJOR 23)
|
||||
set(VERSION_MINOR 1)
|
||||
set(VERSION_PATCH 4)
|
||||
set(VERSION_MINOR 3)
|
||||
set(VERSION_PATCH 3)
|
||||
set(VERSION_COMMIT 0)
|
||||
|
||||
if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/.git")
|
||||
|
||||
@@ -1,32 +1,12 @@
|
||||
# This is the legacy minimum version flatbuffers supported for a while.
|
||||
cmake_minimum_required(VERSION 2.8.12...3.22.1)
|
||||
|
||||
# CMake version 3.16 is the 'de-facto' minimum version for flatbuffers. If the
|
||||
# current cmake is older than this, warn the user and include the legacy file to
|
||||
# provide some level of support.
|
||||
if(CMAKE_VERSION VERSION_LESS 3.16)
|
||||
message(WARNING "Using cmake version ${CMAKE_VERSION} which is older than "
|
||||
"our target version of 3.16. This will use the legacy CMakeLists.txt that "
|
||||
"supports version 2.8.12 and higher, but not actively maintained. Consider "
|
||||
"upgrading cmake to a newer version, as this may become a fatal error in the "
|
||||
"future.")
|
||||
# Use the legacy version of CMakeLists.txt
|
||||
include(CMake/CMakeLists_legacy.cmake.in)
|
||||
return()
|
||||
endif()
|
||||
cmake_minimum_required(VERSION 3.8...3.25.2)
|
||||
|
||||
# Attempt to read the current version of flatbuffers by looking at the latest tag.
|
||||
include(CMake/Version.cmake)
|
||||
|
||||
if (POLICY CMP0048)
|
||||
cmake_policy(SET CMP0048 NEW)
|
||||
project(FlatBuffers
|
||||
DESCRIPTION "Flatbuffers serialization library"
|
||||
project(FlatBuffers
|
||||
VERSION ${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}
|
||||
LANGUAGES CXX)
|
||||
else()
|
||||
project(FlatBuffers)
|
||||
endif (POLICY CMP0048)
|
||||
|
||||
# generate compile_commands.json
|
||||
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
||||
@@ -87,6 +67,12 @@ if(MSVC OR CMAKE_CXX_COMPILER_FRONTEND_VARIANT STREQUAL "MSVC")
|
||||
set(MSVC_LIKE ON)
|
||||
endif()
|
||||
|
||||
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
|
||||
set(IS_CLANG ON)
|
||||
else()
|
||||
set(IS_CLANG OFF)
|
||||
endif()
|
||||
|
||||
if(DEFINED FLATBUFFERS_COMPILATION_TIMINGS)
|
||||
message("Recording Compilation Timings to ${FLATBUFFERS_COMPILATION_TIMINGS}")
|
||||
file(REMOVE ${FLATBUFFERS_COMPILATION_TIMINGS})
|
||||
@@ -136,11 +122,11 @@ set(FlatBuffers_Library_SRCS
|
||||
include/flatbuffers/allocator.h
|
||||
include/flatbuffers/array.h
|
||||
include/flatbuffers/base.h
|
||||
include/flatbuffers/bfbs_generator.h
|
||||
include/flatbuffers/buffer.h
|
||||
include/flatbuffers/buffer_ref.h
|
||||
include/flatbuffers/default_allocator.h
|
||||
include/flatbuffers/detached_buffer.h
|
||||
include/flatbuffers/code_generator.h
|
||||
include/flatbuffers/flatbuffer_builder.h
|
||||
include/flatbuffers/flatbuffers.h
|
||||
include/flatbuffers/flexbuffers.h
|
||||
@@ -167,6 +153,8 @@ set(FlatBuffers_Library_SRCS
|
||||
|
||||
set(FlatBuffers_Compiler_SRCS
|
||||
${FlatBuffers_Library_SRCS}
|
||||
src/idl_gen_binary.cpp
|
||||
src/idl_gen_text.cpp
|
||||
src/idl_gen_cpp.cpp
|
||||
src/idl_gen_csharp.cpp
|
||||
src/idl_gen_dart.cpp
|
||||
@@ -322,7 +310,7 @@ set(FlatBuffers_GRPCTest_SRCS
|
||||
# TODO(dbaileychess): Figure out how this would now work. I posted a question on
|
||||
# https://stackoverflow.com/questions/71772330/override-target-compile-options-via-cmake-command-line.
|
||||
# Append FLATBUFFERS_CXX_FLAGS to CMAKE_CXX_FLAGS.
|
||||
if(DEFINED FLATBUFFERS_CXX_FLAGS AND NOT EXISTS "${CMAKE_TOOLCHAIN_FILE}")
|
||||
if(DEFINED FLATBUFFERS_CXX_FLAGS)
|
||||
message(STATUS "extend CXX_FLAGS with ${FLATBUFFERS_CXX_FLAGS}")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${FLATBUFFERS_CXX_FLAGS}")
|
||||
endif()
|
||||
@@ -335,9 +323,7 @@ function(add_fsanitize_to_target _target _sanitizer)
|
||||
else()
|
||||
# FLATBUFFERS_CODE_SANITIZE: boolean {ON,OFF,YES,NO} or string with list of sanitizer.
|
||||
# List of sanitizer is string starts with '=': "=address,undefined,thread,memory".
|
||||
if((${CMAKE_CXX_COMPILER_ID} MATCHES "Clang") OR
|
||||
((${CMAKE_CXX_COMPILER_ID} MATCHES "GNU") AND NOT (CMAKE_CXX_COMPILER_VERSION VERSION_LESS "4.9"))
|
||||
)
|
||||
if(IS_CLANG OR (CMAKE_COMPILER_IS_GNUCXX AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 4.9))
|
||||
set(_sanitizer_flags "=address,undefined")
|
||||
if(_sanitizer MATCHES "=.*")
|
||||
# override default by user-defined sanitizer list
|
||||
@@ -348,13 +334,14 @@ function(add_fsanitize_to_target _target _sanitizer)
|
||||
"-fsanitize${_sanitizer_flags}")
|
||||
target_link_libraries(${_target} PRIVATE
|
||||
"-fsanitize${_sanitizer_flags}")
|
||||
set_property(TARGET ${_target} PROPERTY POSITION_INDEPENDENT_CODE ON)
|
||||
set_target_properties(${_target} PROPERTIES POSITION_INDEPENDENT_CODE ON)
|
||||
message(STATUS "Sanitizer ${_sanitizer_flags} added to ${_target}")
|
||||
endif()
|
||||
endif()
|
||||
endfunction()
|
||||
|
||||
function(add_pch_to_target _target _pch_header)
|
||||
# the command is available since cmake 3.16
|
||||
if(COMMAND target_precompile_headers)
|
||||
target_precompile_headers(${_target} PRIVATE ${_pch_header})
|
||||
if(NOT MSVC)
|
||||
@@ -398,11 +385,6 @@ if(MSVC_LIKE)
|
||||
>
|
||||
)
|
||||
else()
|
||||
if("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
|
||||
set(IS_CLANG ON)
|
||||
else()
|
||||
set(IS_CLANG OFF)
|
||||
endif()
|
||||
target_compile_options(ProjectConfig
|
||||
INTERFACE
|
||||
-Wall
|
||||
@@ -499,7 +481,7 @@ if(FLATBUFFERS_BUILD_FLATC)
|
||||
|
||||
target_link_libraries(flatc PRIVATE $<BUILD_INTERFACE:ProjectConfig>)
|
||||
target_compile_options(flatc
|
||||
PUBLIC
|
||||
PRIVATE
|
||||
$<$<AND:$<BOOL:${MSVC_LIKE}>,$<CONFIG:Release>>:
|
||||
/MT
|
||||
>
|
||||
@@ -524,14 +506,13 @@ endif()
|
||||
if(FLATBUFFERS_BUILD_SHAREDLIB)
|
||||
add_library(flatbuffers_shared SHARED ${FlatBuffers_Library_SRCS})
|
||||
target_link_libraries(flatbuffers_shared PRIVATE $<BUILD_INTERFACE:ProjectConfig>)
|
||||
# Shared object version: "major.minor.micro"
|
||||
# - micro updated every release when there is no API/ABI changes
|
||||
# - minor updated when there are additions in API/ABI
|
||||
# - major (ABI number) updated when there are changes in ABI (or removals)
|
||||
set(FlatBuffers_Library_SONAME_MAJOR ${VERSION_MAJOR})
|
||||
set(FlatBuffers_Library_SONAME_FULL "${FlatBuffers_Library_SONAME_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}")
|
||||
set_target_properties(flatbuffers_shared PROPERTIES OUTPUT_NAME flatbuffers
|
||||
SOVERSION "${FlatBuffers_Library_SONAME_MAJOR}"
|
||||
# FlatBuffers use calendar-based versioning and do not provide any ABI
|
||||
# stability guarantees. Therefore, always use the full version as SOVERSION
|
||||
# in order to avoid breaking reverse dependencies on upgrades.
|
||||
set(FlatBuffers_Library_SONAME_FULL "${PROJECT_VERSION}")
|
||||
set_target_properties(flatbuffers_shared PROPERTIES
|
||||
OUTPUT_NAME flatbuffers
|
||||
SOVERSION "${FlatBuffers_Library_SONAME_FULL}"
|
||||
VERSION "${FlatBuffers_Library_SONAME_FULL}")
|
||||
if(FLATBUFFERS_ENABLE_PCH)
|
||||
add_pch_to_target(flatbuffers_shared include/flatbuffers/pch/pch.h)
|
||||
@@ -677,7 +658,7 @@ if(FLATBUFFERS_BUILD_TESTS)
|
||||
add_executable(flattests_cpp17 ${FlatBuffers_Tests_CPP17_SRCS})
|
||||
add_dependencies(flattests_cpp17 generated_code)
|
||||
target_link_libraries(flattests_cpp17 PRIVATE $<BUILD_INTERFACE:ProjectConfig>)
|
||||
target_compile_features(flattests_cpp17 PRIVATE cxx_std_17)
|
||||
target_compile_features(flattests_cpp17 PRIVATE cxx_std_17) # requires cmake 3.8
|
||||
|
||||
if(FLATBUFFERS_CODE_SANITIZE)
|
||||
add_fsanitize_to_target(flattests_cpp17 ${FLATBUFFERS_CODE_SANITIZE})
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
Pod::Spec.new do |s|
|
||||
s.name = 'FlatBuffers'
|
||||
s.version = '23.1.4'
|
||||
s.version = '23.3.3'
|
||||
s.summary = 'FlatBuffers: Memory Efficient Serialization Library'
|
||||
|
||||
s.description = "FlatBuffers is a cross platform serialization library architected for
|
||||
|
||||
@@ -32,6 +32,6 @@ let package = Package(
|
||||
.target(
|
||||
name: "FlatBuffers",
|
||||
dependencies: [],
|
||||
path: "swift/Sources")
|
||||
path: "swift/Sources"),
|
||||
])
|
||||
|
||||
|
||||
@@ -94,8 +94,12 @@ yarn_install(
|
||||
name = "npm",
|
||||
exports_directories_only = False,
|
||||
# Unfreeze to add/remove packages.
|
||||
frozen_lockfile = True,
|
||||
frozen_lockfile = False,
|
||||
package_json = "//:package.json",
|
||||
symlink_node_modules = False,
|
||||
yarn_lock = "//:yarn.lock",
|
||||
)
|
||||
|
||||
load("@build_bazel_rules_nodejs//toolchains/esbuild:esbuild_repositories.bzl", "esbuild_repositories")
|
||||
|
||||
esbuild_repositories(npm_repository = "npm")
|
||||
|
||||
@@ -1,20 +1,22 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!-- 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.
|
||||
-->
|
||||
<projectDescription>
|
||||
<name>FlatBufferTest</name>
|
||||
<name>FlatBufferTest</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
</natures>
|
||||
<filteredResources>
|
||||
<filter>
|
||||
<id>1677235311958</id>
|
||||
<name></name>
|
||||
<type>30</type>
|
||||
<matcher>
|
||||
<id>org.eclipse.core.resources.regexFilterMatcher</id>
|
||||
<arguments>node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__</arguments>
|
||||
</matcher>
|
||||
</filter>
|
||||
</filteredResources>
|
||||
</projectDescription>
|
||||
|
||||
@@ -1,15 +1,13 @@
|
||||
apply plugin: 'com.android.application'
|
||||
apply plugin: 'kotlin-android'
|
||||
apply plugin: 'kotlin-android-extensions'
|
||||
|
||||
android {
|
||||
compileSdkVersion 30
|
||||
buildToolsVersion "30.0.2"
|
||||
compileSdk 33
|
||||
|
||||
defaultConfig {
|
||||
applicationId "com.flatbuffers.app"
|
||||
minSdkVersion 26
|
||||
targetSdkVersion 30
|
||||
targetSdkVersion 33
|
||||
versionCode 1
|
||||
versionName "1.0"
|
||||
|
||||
@@ -113,13 +111,13 @@ android {
|
||||
dependsOn(generateFbsCpp)
|
||||
}
|
||||
}
|
||||
namespace 'com.flatbuffers.app'
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation fileTree(dir: "libs", include: ["*.jar"])
|
||||
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
|
||||
implementation 'androidx.core:core-ktx:1.3.2'
|
||||
implementation 'androidx.appcompat:appcompat:1.2.0'
|
||||
implementation 'androidx.appcompat:appcompat:1.6.1'
|
||||
|
||||
// If you using java runtime you can add its dependency as the example below
|
||||
// implementation 'com.google.flatbuffers:flatbuffers-java:$latest_version'
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="com.flatbuffers.app">
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
|
||||
<application
|
||||
android:allowBackup="true"
|
||||
@@ -9,7 +8,8 @@
|
||||
android:roundIcon="@mipmap/ic_launcher_round"
|
||||
android:supportsRtl="true"
|
||||
android:theme="@style/AppTheme">
|
||||
<activity android:name=".MainActivity">
|
||||
<activity android:name=".MainActivity"
|
||||
android:exported="true">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
|
||||
|
||||
@@ -18,7 +18,6 @@ set(FlatBuffers_Library_SRCS
|
||||
${FLATBUFFERS_SRC}/include/flatbuffers/allocator.h
|
||||
${FLATBUFFERS_SRC}/include/flatbuffers/array.h
|
||||
${FLATBUFFERS_SRC}/include/flatbuffers/base.h
|
||||
${FLATBUFFERS_SRC}/include/flatbuffers/bfbs_generator.h
|
||||
${FLATBUFFERS_SRC}/include/flatbuffers/buffer.h
|
||||
${FLATBUFFERS_SRC}/include/flatbuffers/buffer_ref.h
|
||||
${FLATBUFFERS_SRC}/include/flatbuffers/default_allocator.h
|
||||
|
||||
@@ -8,9 +8,9 @@
|
||||
|
||||
// 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 == 2 &&
|
||||
FLATBUFFERS_VERSION_MINOR == 0 &&
|
||||
FLATBUFFERS_VERSION_REVISION == 8,
|
||||
static_assert(FLATBUFFERS_VERSION_MAJOR == 23 &&
|
||||
FLATBUFFERS_VERSION_MINOR == 1 &&
|
||||
FLATBUFFERS_VERSION_REVISION == 21,
|
||||
"Non-compatible flatbuffers version included");
|
||||
|
||||
namespace com {
|
||||
@@ -20,23 +20,23 @@ namespace app {
|
||||
struct Animal;
|
||||
struct AnimalBuilder;
|
||||
|
||||
struct Animal FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table {
|
||||
struct Animal FLATBUFFERS_FINAL_CLASS : private ::flatbuffers::Table {
|
||||
typedef AnimalBuilder Builder;
|
||||
enum FlatBuffersVTableOffset FLATBUFFERS_VTABLE_UNDERLYING_TYPE {
|
||||
VT_NAME = 4,
|
||||
VT_SOUND = 6,
|
||||
VT_WEIGHT = 8
|
||||
};
|
||||
const flatbuffers::String *name() const {
|
||||
return GetPointer<const flatbuffers::String *>(VT_NAME);
|
||||
const ::flatbuffers::String *name() const {
|
||||
return GetPointer<const ::flatbuffers::String *>(VT_NAME);
|
||||
}
|
||||
const flatbuffers::String *sound() const {
|
||||
return GetPointer<const flatbuffers::String *>(VT_SOUND);
|
||||
const ::flatbuffers::String *sound() const {
|
||||
return GetPointer<const ::flatbuffers::String *>(VT_SOUND);
|
||||
}
|
||||
uint16_t weight() const {
|
||||
return GetField<uint16_t>(VT_WEIGHT, 0);
|
||||
}
|
||||
bool Verify(flatbuffers::Verifier &verifier) const {
|
||||
bool Verify(::flatbuffers::Verifier &verifier) const {
|
||||
return VerifyTableStart(verifier) &&
|
||||
VerifyOffset(verifier, VT_NAME) &&
|
||||
verifier.VerifyString(name()) &&
|
||||
@@ -49,32 +49,32 @@ struct Animal FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table {
|
||||
|
||||
struct AnimalBuilder {
|
||||
typedef Animal Table;
|
||||
flatbuffers::FlatBufferBuilder &fbb_;
|
||||
flatbuffers::uoffset_t start_;
|
||||
void add_name(flatbuffers::Offset<flatbuffers::String> name) {
|
||||
::flatbuffers::FlatBufferBuilder &fbb_;
|
||||
::flatbuffers::uoffset_t start_;
|
||||
void add_name(::flatbuffers::Offset<::flatbuffers::String> name) {
|
||||
fbb_.AddOffset(Animal::VT_NAME, name);
|
||||
}
|
||||
void add_sound(flatbuffers::Offset<flatbuffers::String> sound) {
|
||||
void add_sound(::flatbuffers::Offset<::flatbuffers::String> sound) {
|
||||
fbb_.AddOffset(Animal::VT_SOUND, sound);
|
||||
}
|
||||
void add_weight(uint16_t weight) {
|
||||
fbb_.AddElement<uint16_t>(Animal::VT_WEIGHT, weight, 0);
|
||||
}
|
||||
explicit AnimalBuilder(flatbuffers::FlatBufferBuilder &_fbb)
|
||||
explicit AnimalBuilder(::flatbuffers::FlatBufferBuilder &_fbb)
|
||||
: fbb_(_fbb) {
|
||||
start_ = fbb_.StartTable();
|
||||
}
|
||||
flatbuffers::Offset<Animal> Finish() {
|
||||
::flatbuffers::Offset<Animal> Finish() {
|
||||
const auto end = fbb_.EndTable(start_);
|
||||
auto o = flatbuffers::Offset<Animal>(end);
|
||||
auto o = ::flatbuffers::Offset<Animal>(end);
|
||||
return o;
|
||||
}
|
||||
};
|
||||
|
||||
inline flatbuffers::Offset<Animal> CreateAnimal(
|
||||
flatbuffers::FlatBufferBuilder &_fbb,
|
||||
flatbuffers::Offset<flatbuffers::String> name = 0,
|
||||
flatbuffers::Offset<flatbuffers::String> sound = 0,
|
||||
inline ::flatbuffers::Offset<Animal> CreateAnimal(
|
||||
::flatbuffers::FlatBufferBuilder &_fbb,
|
||||
::flatbuffers::Offset<::flatbuffers::String> name = 0,
|
||||
::flatbuffers::Offset<::flatbuffers::String> sound = 0,
|
||||
uint16_t weight = 0) {
|
||||
AnimalBuilder builder_(_fbb);
|
||||
builder_.add_sound(sound);
|
||||
@@ -83,8 +83,8 @@ inline flatbuffers::Offset<Animal> CreateAnimal(
|
||||
return builder_.Finish();
|
||||
}
|
||||
|
||||
inline flatbuffers::Offset<Animal> CreateAnimalDirect(
|
||||
flatbuffers::FlatBufferBuilder &_fbb,
|
||||
inline ::flatbuffers::Offset<Animal> CreateAnimalDirect(
|
||||
::flatbuffers::FlatBufferBuilder &_fbb,
|
||||
const char *name = nullptr,
|
||||
const char *sound = nullptr,
|
||||
uint16_t weight = 0) {
|
||||
@@ -98,32 +98,32 @@ inline flatbuffers::Offset<Animal> CreateAnimalDirect(
|
||||
}
|
||||
|
||||
inline const com::fbs::app::Animal *GetAnimal(const void *buf) {
|
||||
return flatbuffers::GetRoot<com::fbs::app::Animal>(buf);
|
||||
return ::flatbuffers::GetRoot<com::fbs::app::Animal>(buf);
|
||||
}
|
||||
|
||||
inline const com::fbs::app::Animal *GetSizePrefixedAnimal(const void *buf) {
|
||||
return flatbuffers::GetSizePrefixedRoot<com::fbs::app::Animal>(buf);
|
||||
return ::flatbuffers::GetSizePrefixedRoot<com::fbs::app::Animal>(buf);
|
||||
}
|
||||
|
||||
inline bool VerifyAnimalBuffer(
|
||||
flatbuffers::Verifier &verifier) {
|
||||
::flatbuffers::Verifier &verifier) {
|
||||
return verifier.VerifyBuffer<com::fbs::app::Animal>(nullptr);
|
||||
}
|
||||
|
||||
inline bool VerifySizePrefixedAnimalBuffer(
|
||||
flatbuffers::Verifier &verifier) {
|
||||
::flatbuffers::Verifier &verifier) {
|
||||
return verifier.VerifySizePrefixedBuffer<com::fbs::app::Animal>(nullptr);
|
||||
}
|
||||
|
||||
inline void FinishAnimalBuffer(
|
||||
flatbuffers::FlatBufferBuilder &fbb,
|
||||
flatbuffers::Offset<com::fbs::app::Animal> root) {
|
||||
::flatbuffers::FlatBufferBuilder &fbb,
|
||||
::flatbuffers::Offset<com::fbs::app::Animal> root) {
|
||||
fbb.Finish(root);
|
||||
}
|
||||
|
||||
inline void FinishSizePrefixedAnimalBuffer(
|
||||
flatbuffers::FlatBufferBuilder &fbb,
|
||||
flatbuffers::Offset<com::fbs::app::Animal> root) {
|
||||
::flatbuffers::FlatBufferBuilder &fbb,
|
||||
::flatbuffers::Offset<com::fbs::app::Animal> root) {
|
||||
fbb.FinishSizePrefixed(root);
|
||||
}
|
||||
|
||||
|
||||
@@ -2,11 +2,24 @@
|
||||
|
||||
package com.fbs.app
|
||||
|
||||
import java.nio.*
|
||||
import com.google.flatbuffers.BaseVector
|
||||
import com.google.flatbuffers.BooleanVector
|
||||
import com.google.flatbuffers.ByteVector
|
||||
import com.google.flatbuffers.Constants
|
||||
import com.google.flatbuffers.DoubleVector
|
||||
import com.google.flatbuffers.FlatBufferBuilder
|
||||
import com.google.flatbuffers.FloatVector
|
||||
import com.google.flatbuffers.LongVector
|
||||
import com.google.flatbuffers.StringVector
|
||||
import com.google.flatbuffers.Struct
|
||||
import com.google.flatbuffers.Table
|
||||
import com.google.flatbuffers.UnionVector
|
||||
import java.nio.ByteBuffer
|
||||
import java.nio.ByteOrder
|
||||
import kotlin.math.sign
|
||||
import com.google.flatbuffers.*
|
||||
|
||||
@Suppress("unused")
|
||||
@kotlin.ExperimentalUnsignedTypes
|
||||
class Animal : Table() {
|
||||
|
||||
fun __init(_i: Int, _bb: ByteBuffer) {
|
||||
@@ -19,14 +32,22 @@ class Animal : Table() {
|
||||
val name : String?
|
||||
get() {
|
||||
val o = __offset(4)
|
||||
return if (o != 0) __string(o + bb_pos) else null
|
||||
return if (o != 0) {
|
||||
__string(o + bb_pos)
|
||||
} else {
|
||||
null
|
||||
}
|
||||
}
|
||||
val nameAsByteBuffer : ByteBuffer get() = __vector_as_bytebuffer(4, 1)
|
||||
fun nameInByteBuffer(_bb: ByteBuffer) : ByteBuffer = __vector_in_bytebuffer(_bb, 4, 1)
|
||||
val sound : String?
|
||||
get() {
|
||||
val o = __offset(6)
|
||||
return if (o != 0) __string(o + bb_pos) else null
|
||||
return if (o != 0) {
|
||||
__string(o + bb_pos)
|
||||
} else {
|
||||
null
|
||||
}
|
||||
}
|
||||
val soundAsByteBuffer : ByteBuffer get() = __vector_as_bytebuffer(6, 1)
|
||||
fun soundInByteBuffer(_bb: ByteBuffer) : ByteBuffer = __vector_in_bytebuffer(_bb, 6, 1)
|
||||
@@ -36,7 +57,7 @@ class Animal : Table() {
|
||||
return if(o != 0) bb.getShort(o + bb_pos).toUShort() else 0u
|
||||
}
|
||||
companion object {
|
||||
fun validateVersion() = Constants.FLATBUFFERS_23_1_4()
|
||||
fun validateVersion() = Constants.FLATBUFFERS_23_3_3()
|
||||
fun getRootAsAnimal(_bb: ByteBuffer): Animal = getRootAsAnimal(_bb, Animal())
|
||||
fun getRootAsAnimal(_bb: ByteBuffer, obj: Animal): Animal {
|
||||
_bb.order(ByteOrder.LITTLE_ENDIAN)
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
// Top-level build file where you can add configuration options common to all sub-projects/modules.
|
||||
buildscript {
|
||||
ext.kotlin_version = "1.4.10"
|
||||
ext.kotlin_version = "1.7.21"
|
||||
repositories {
|
||||
google()
|
||||
jcenter()
|
||||
mavenCentral()
|
||||
}
|
||||
dependencies {
|
||||
classpath 'com.android.tools.build:gradle:4.1.0'
|
||||
classpath 'com.android.tools.build:gradle:7.4.1'
|
||||
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
|
||||
|
||||
// NOTE: Do not place your application dependencies here; they belong
|
||||
@@ -17,7 +17,7 @@ buildscript {
|
||||
allprojects {
|
||||
repositories {
|
||||
google()
|
||||
jcenter()
|
||||
mavenCentral()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4.2-bin.zip
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.0.1-bin.zip
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
# Setup for running Google Benchmarks (https://github.com/google/benchmark) on
|
||||
# flatbuffers. This requires both that benchmark library and its depenency gtest
|
||||
# flatbuffers. This requires both that benchmark library and its dependency gtest
|
||||
# to build. Instead of including them here or doing a submodule, this uses
|
||||
# FetchContent (https://cmake.org/cmake/help/latest/module/FetchContent.html) to
|
||||
# grab the dependencies at config time. This requires CMake 3.14 or higher.
|
||||
|
||||
cmake_minimum_required(VERSION 3.14)
|
||||
include(FetchContent)
|
||||
|
||||
@@ -27,7 +28,7 @@ FetchContent_MakeAvailable(
|
||||
googlebenchmark
|
||||
)
|
||||
|
||||
set(CPP_BENCH_DIR cpp)
|
||||
set(CPP_BENCH_DIR ${CMAKE_CURRENT_SOURCE_DIR}/cpp)
|
||||
set(CPP_FB_BENCH_DIR ${CPP_BENCH_DIR}/flatbuffers)
|
||||
set(CPP_RAW_BENCH_DIR ${CPP_BENCH_DIR}/raw)
|
||||
set(CPP_BENCH_FBS ${CPP_FB_BENCH_DIR}/bench.fbs)
|
||||
@@ -62,8 +63,8 @@ add_custom_command(
|
||||
add_executable(flatbenchmark ${FlatBenchmark_SRCS})
|
||||
|
||||
# Benchmark requires C++11
|
||||
target_compile_features(flatbenchmark PUBLIC
|
||||
cxx_std_11
|
||||
target_compile_features(flatbenchmark PRIVATE
|
||||
cxx_std_11 # requires cmake 3.8
|
||||
)
|
||||
|
||||
target_compile_options(flatbenchmark
|
||||
@@ -81,7 +82,7 @@ set_target_properties(flatbenchmark
|
||||
# The includes of the benchmark files are fully qualified from flatbuffers root.
|
||||
target_include_directories(flatbenchmark PUBLIC ${CMAKE_SOURCE_DIR})
|
||||
|
||||
target_link_libraries(flatbenchmark
|
||||
target_link_libraries(flatbenchmark PRIVATE
|
||||
benchmark::benchmark_main # _main to use their entry point
|
||||
gtest # Link to gtest so we can also assert in the benchmarks
|
||||
)
|
||||
@@ -7,7 +7,7 @@ Rules for building C++ flatbuffers with Bazel.
|
||||
|
||||
load("@rules_cc//cc:defs.bzl", "cc_library")
|
||||
|
||||
flatc_path = "@com_github_google_flatbuffers//:flatc"
|
||||
TRUE_FLATC_PATH = "@com_github_google_flatbuffers//:flatc"
|
||||
|
||||
DEFAULT_INCLUDE_PATHS = [
|
||||
"./",
|
||||
@@ -16,6 +16,14 @@ DEFAULT_INCLUDE_PATHS = [
|
||||
"$(execpath @com_github_google_flatbuffers//:flatc).runfiles/com_github_google_flatbuffers",
|
||||
]
|
||||
|
||||
def default_include_paths(flatc_path):
|
||||
return [
|
||||
"./",
|
||||
"$(GENDIR)",
|
||||
"$(BINDIR)",
|
||||
"$(execpath %s).runfiles/com_github_google_flatbuffers" % (flatc_path),
|
||||
]
|
||||
|
||||
DEFAULT_FLATC_ARGS = [
|
||||
"--gen-object-api",
|
||||
"--gen-compare",
|
||||
@@ -32,13 +40,14 @@ def flatbuffer_library_public(
|
||||
language_flag,
|
||||
out_prefix = "",
|
||||
includes = [],
|
||||
include_paths = DEFAULT_INCLUDE_PATHS,
|
||||
include_paths = None,
|
||||
flatc_args = DEFAULT_FLATC_ARGS,
|
||||
reflection_name = "",
|
||||
reflection_visibility = None,
|
||||
compatible_with = None,
|
||||
restricted_to = None,
|
||||
target_compatible_with = None,
|
||||
flatc_path = "@com_github_google_flatbuffers//:flatc",
|
||||
output_to_bindir = False):
|
||||
"""Generates code files for reading/writing the given flatbuffers in the requested language using the public compiler.
|
||||
|
||||
@@ -62,6 +71,7 @@ def flatbuffer_library_public(
|
||||
for, instead of default-supported environments.
|
||||
target_compatible_with: Optional, The list of target platform constraints
|
||||
to use.
|
||||
flatc_path: Bazel target corresponding to the flatc compiler to use.
|
||||
output_to_bindir: Passed to genrule for output to bin directory.
|
||||
|
||||
|
||||
@@ -69,6 +79,8 @@ def flatbuffer_library_public(
|
||||
optionally a Fileset([reflection_name]) with all generated reflection
|
||||
binaries.
|
||||
"""
|
||||
if include_paths == None:
|
||||
include_paths = default_include_paths(flatc_path)
|
||||
include_paths_cmd = ["-I %s" % (s) for s in include_paths]
|
||||
|
||||
# '$(@D)' when given a single source target will give the appropriate
|
||||
@@ -80,7 +92,7 @@ def flatbuffer_library_public(
|
||||
genrule_cmd = " ".join([
|
||||
"SRCS=($(SRCS));",
|
||||
"for f in $${SRCS[@]:0:%s}; do" % len(srcs),
|
||||
"$(location %s)" % (flatc_path),
|
||||
"OUTPUT_FILE=\"$(OUTS)\" $(location %s)" % (flatc_path),
|
||||
" ".join(include_paths_cmd),
|
||||
" ".join(flatc_args),
|
||||
language_flag,
|
||||
@@ -104,7 +116,7 @@ def flatbuffer_library_public(
|
||||
reflection_genrule_cmd = " ".join([
|
||||
"SRCS=($(SRCS));",
|
||||
"for f in $${SRCS[@]:0:%s}; do" % len(srcs),
|
||||
"$(location %s)" % (flatc_path),
|
||||
"$(location %s)" % (TRUE_FLATC_PATH),
|
||||
"-b --schema",
|
||||
" ".join(flatc_args),
|
||||
" ".join(include_paths_cmd),
|
||||
@@ -122,7 +134,7 @@ def flatbuffer_library_public(
|
||||
srcs = srcs + includes,
|
||||
outs = reflection_outs,
|
||||
output_to_bindir = output_to_bindir,
|
||||
tools = [flatc_path],
|
||||
tools = [TRUE_FLATC_PATH],
|
||||
compatible_with = compatible_with,
|
||||
restricted_to = restricted_to,
|
||||
target_compatible_with = target_compatible_with,
|
||||
@@ -145,7 +157,7 @@ def flatbuffer_cc_library(
|
||||
out_prefix = "",
|
||||
deps = [],
|
||||
includes = [],
|
||||
include_paths = DEFAULT_INCLUDE_PATHS,
|
||||
include_paths = None,
|
||||
cc_include_paths = [],
|
||||
flatc_args = DEFAULT_FLATC_ARGS,
|
||||
visibility = None,
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
name: flat_buffers
|
||||
version: 23.1.4
|
||||
version: 23.3.3
|
||||
description: FlatBuffers reading and writing library for Dart. Based on original work by Konstantin Scheglov and Paul Berry of the Dart SDK team.
|
||||
homepage: https://github.com/google/flatbuffers
|
||||
documentation: https://google.github.io/flatbuffers/index.html
|
||||
|
||||
@@ -90,7 +90,10 @@ Additional options:
|
||||
|
||||
- `--scoped-enums` : Use C++11 style scoped and strongly typed enums in
|
||||
generated C++. This also implies `--no-prefix`.
|
||||
|
||||
|
||||
- `--no-emit-min-max-enum-values` : Disable generation of MIN and MAX
|
||||
enumerated values for scoped enums and prefixed enums.
|
||||
|
||||
- `--gen-includes` : (deprecated), this is the default behavior.
|
||||
If the original behavior is required (no include
|
||||
statements) use `--no-includes.`
|
||||
|
||||
@@ -72,7 +72,10 @@ Now you can access values like this:
|
||||
In some cases it's necessary to modify values in an existing FlatBuffer in place (without creating a copy). For this reason, scalar fields of a Flatbuffer table or struct can be mutated.
|
||||
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.swift}
|
||||
let monster = Monster.getRootAsMonster(bb: ByteBuffer(data: data))
|
||||
var byteBuffer = ByteBuffer(bytes: data)
|
||||
// Get an accessor to the root object inside the buffer.
|
||||
let monster: Monster = try! getCheckedRoot(byteBuffer: &byteBuffer)
|
||||
// let monster: Monster = getRoot(byteBuffer: &byteBuffer)
|
||||
|
||||
if !monster.mutate(hp: 10) {
|
||||
fatalError("couldn't mutate")
|
||||
|
||||
@@ -321,9 +321,8 @@ Please be aware of the difference between `flatc` and `flatcc` tools.
|
||||
<div class="language-javascript">
|
||||
~~~{.sh}
|
||||
cd flatbuffers/samples
|
||||
./../flatc --ts monster.fbs
|
||||
# customize your TS -> JS transpilation
|
||||
tsc monster_generated.ts
|
||||
./../flatc --ts-flat-files --ts monster.fbs
|
||||
# produces ts/js modules and js bundle monster_generated.js
|
||||
~~~
|
||||
</div>
|
||||
<div class="language-typescript">
|
||||
@@ -2241,7 +2240,7 @@ before:
|
||||
~~~{.ts}
|
||||
// note: import flatbuffers with your desired import method
|
||||
|
||||
// note: the `./monster_generated.ts` file was previously generated by `flatc` above using the `monster.fbs` schema
|
||||
// note: the `./monster_generated.js` file was previously generated by `flatc` above using the `monster.fbs` schema
|
||||
import { MyGame } from './monster_generated';
|
||||
~~~
|
||||
</div>
|
||||
@@ -2472,10 +2471,10 @@ myGame.Monster monster = new myGame.Monster(data);
|
||||
<div class="language-swift">
|
||||
~~~{.swift}
|
||||
// create a ByteBuffer(:) from an [UInt8] or Data()
|
||||
let buf = // Get your data
|
||||
|
||||
var buf = // Get your data
|
||||
// Get an accessor to the root object inside the buffer.
|
||||
let monster = Monster.getRootAsMonster(bb: ByteBuffer(bytes: buf))
|
||||
let monster: Monster = try! getCheckedRoot(byteBuffer: &byteBuffer)
|
||||
// let monster: Monster = getRoot(byteBuffer: &byteBuffer)
|
||||
~~~
|
||||
</div>
|
||||
|
||||
|
||||
@@ -6,12 +6,10 @@ import FlatBuffers
|
||||
|
||||
public struct models_HelloReply: FlatBufferObject, Verifiable {
|
||||
|
||||
static func validateVersion() { FlatBuffersVersion_23_1_4() }
|
||||
static func validateVersion() { FlatBuffersVersion_23_3_3() }
|
||||
public var __buffer: ByteBuffer! { return _accessor.bb }
|
||||
private var _accessor: Table
|
||||
|
||||
public static func getRootAsHelloReply(bb: ByteBuffer) -> models_HelloReply { return models_HelloReply(Table(bb: bb, position: Int32(bb.read(def: UOffset.self, position: bb.reader)) + Int32(bb.reader))) }
|
||||
|
||||
private init(_ t: Table) { _accessor = t }
|
||||
public init(_ bb: ByteBuffer, o: Int32) { _accessor = Table(bb: bb, position: o) }
|
||||
|
||||
@@ -55,12 +53,10 @@ extension models_HelloReply: Encodable {
|
||||
|
||||
public struct models_HelloRequest: FlatBufferObject, Verifiable {
|
||||
|
||||
static func validateVersion() { FlatBuffersVersion_23_1_4() }
|
||||
static func validateVersion() { FlatBuffersVersion_23_3_3() }
|
||||
public var __buffer: ByteBuffer! { return _accessor.bb }
|
||||
private var _accessor: Table
|
||||
|
||||
public static func getRootAsHelloRequest(bb: ByteBuffer) -> models_HelloRequest { return models_HelloRequest(Table(bb: bb, position: Int32(bb.read(def: UOffset.self, position: bb.reader)) + Int32(bb.reader))) }
|
||||
|
||||
private init(_ t: Table) { _accessor = t }
|
||||
public init(_ bb: ByteBuffer, o: Int32) { _accessor = Table(bb: bb, position: o) }
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2021 Google Inc. All rights reserved.
|
||||
* 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.
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2021 Google Inc. All rights reserved.
|
||||
* 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.
|
||||
|
||||
@@ -1,2 +1,3 @@
|
||||
export { HelloReply } from './models/hello-reply';
|
||||
export { HelloRequest } from './models/hello-request';
|
||||
// automatically generated by the FlatBuffers compiler, do not modify
|
||||
|
||||
export * as models from './models.js';
|
||||
|
||||
4
grpc/examples/ts/greeter/src/models.ts
Normal file
4
grpc/examples/ts/greeter/src/models.ts
Normal file
@@ -0,0 +1,4 @@
|
||||
// automatically generated by the FlatBuffers compiler, do not modify
|
||||
|
||||
export { HelloReply } from './models/hello-reply.js';
|
||||
export { HelloRequest } from './models/hello-request.js';
|
||||
@@ -17,6 +17,8 @@
|
||||
#ifndef FLATBUFFERS_ARRAY_H_
|
||||
#define FLATBUFFERS_ARRAY_H_
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include "flatbuffers/base.h"
|
||||
#include "flatbuffers/stl_emulation.h"
|
||||
#include "flatbuffers/vector.h"
|
||||
@@ -238,6 +240,14 @@ const Array<E, length> &CastToArrayOfEnum(const T (&arr)[length]) {
|
||||
return *reinterpret_cast<const Array<E, length> *>(arr);
|
||||
}
|
||||
|
||||
template<typename T, uint16_t length>
|
||||
bool operator==(const Array<T, length> &lhs,
|
||||
const Array<T, length> &rhs) noexcept {
|
||||
return std::addressof(lhs) == std::addressof(rhs) ||
|
||||
(lhs.size() == rhs.size() &&
|
||||
std::memcmp(lhs.Data(), rhs.Data(), rhs.size() * sizeof(T)) == 0);
|
||||
}
|
||||
|
||||
} // namespace flatbuffers
|
||||
|
||||
#endif // FLATBUFFERS_ARRAY_H_
|
||||
|
||||
@@ -139,8 +139,8 @@
|
||||
#endif // !defined(FLATBUFFERS_LITTLEENDIAN)
|
||||
|
||||
#define FLATBUFFERS_VERSION_MAJOR 23
|
||||
#define FLATBUFFERS_VERSION_MINOR 1
|
||||
#define FLATBUFFERS_VERSION_REVISION 4
|
||||
#define FLATBUFFERS_VERSION_MINOR 3
|
||||
#define FLATBUFFERS_VERSION_REVISION 3
|
||||
#define FLATBUFFERS_STRING_EXPAND(X) #X
|
||||
#define FLATBUFFERS_STRING(X) FLATBUFFERS_STRING_EXPAND(X)
|
||||
namespace flatbuffers {
|
||||
@@ -233,7 +233,7 @@ namespace flatbuffers {
|
||||
}
|
||||
#define FLATBUFFERS_HAS_STRING_VIEW 1
|
||||
// Check for absl::string_view
|
||||
#elif __has_include("absl/strings/string_view.h")
|
||||
#elif __has_include("absl/strings/string_view.h") && (__cplusplus >= 201411)
|
||||
#include "absl/strings/string_view.h"
|
||||
namespace flatbuffers {
|
||||
typedef absl::string_view string_view;
|
||||
|
||||
80
include/flatbuffers/code_generator.h
Normal file
80
include/flatbuffers/code_generator.h
Normal file
@@ -0,0 +1,80 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef FLATBUFFERS_CODE_GENERATOR_H_
|
||||
#define FLATBUFFERS_CODE_GENERATOR_H_
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "flatbuffers/idl.h"
|
||||
|
||||
namespace flatbuffers {
|
||||
|
||||
// A code generator interface for producing converting flatbuffer schema into
|
||||
// code.
|
||||
class CodeGenerator {
|
||||
public:
|
||||
virtual ~CodeGenerator() = default;
|
||||
|
||||
enum Status {
|
||||
OK = 0,
|
||||
ERROR = 1,
|
||||
FAILED_VERIFICATION = 2,
|
||||
NOT_IMPLEMENTED = 3
|
||||
};
|
||||
|
||||
// Generate code from the provided `parser`.
|
||||
//
|
||||
// DEPRECATED: prefer using the other overload of GenerateCode for bfbs.
|
||||
virtual Status GenerateCode(const Parser &parser, const std::string &path,
|
||||
const std::string &filename) = 0;
|
||||
|
||||
// Generate code from the provided `buffer` of given `length`. The buffer is a
|
||||
// serialized reflection.fbs.
|
||||
virtual Status GenerateCode(const uint8_t *buffer, int64_t length) = 0;
|
||||
|
||||
virtual Status GenerateMakeRule(const Parser &parser, const std::string &path,
|
||||
const std::string &filename,
|
||||
std::string &output) = 0;
|
||||
|
||||
virtual Status GenerateGrpcCode(const Parser &parser, const std::string &path,
|
||||
const std::string &filename) = 0;
|
||||
|
||||
virtual Status GenerateRootFile(const Parser &parser,
|
||||
const std::string &path) = 0;
|
||||
|
||||
virtual bool IsSchemaOnly() const = 0;
|
||||
|
||||
virtual bool SupportsBfbsGeneration() const = 0;
|
||||
|
||||
virtual bool SupportsRootFileGeneration() const = 0;
|
||||
|
||||
virtual IDLOptions::Language Language() const = 0;
|
||||
|
||||
virtual std::string LanguageName() const = 0;
|
||||
|
||||
protected:
|
||||
CodeGenerator() = default;
|
||||
|
||||
private:
|
||||
// Copying is not supported.
|
||||
CodeGenerator(const CodeGenerator &) = delete;
|
||||
CodeGenerator &operator=(const CodeGenerator &) = delete;
|
||||
};
|
||||
|
||||
} // namespace flatbuffers
|
||||
|
||||
#endif // FLATBUFFERS_CODE_GENERATOR_H_
|
||||
@@ -45,7 +45,7 @@ class DetachedBuffer {
|
||||
cur_(cur),
|
||||
size_(sz) {}
|
||||
|
||||
DetachedBuffer(DetachedBuffer &&other)
|
||||
DetachedBuffer(DetachedBuffer &&other) noexcept
|
||||
: allocator_(other.allocator_),
|
||||
own_allocator_(other.own_allocator_),
|
||||
buf_(other.buf_),
|
||||
@@ -55,7 +55,7 @@ class DetachedBuffer {
|
||||
other.reset();
|
||||
}
|
||||
|
||||
DetachedBuffer &operator=(DetachedBuffer &&other) {
|
||||
DetachedBuffer &operator=(DetachedBuffer &&other) noexcept {
|
||||
if (this == &other) return *this;
|
||||
|
||||
destroy();
|
||||
|
||||
@@ -98,7 +98,7 @@ class FlatBufferBuilder {
|
||||
}
|
||||
|
||||
/// @brief Move constructor for FlatBufferBuilder.
|
||||
FlatBufferBuilder(FlatBufferBuilder &&other)
|
||||
FlatBufferBuilder(FlatBufferBuilder &&other) noexcept
|
||||
: buf_(1024, nullptr, false, AlignOf<largest_scalar_t>()),
|
||||
num_field_loc(0),
|
||||
max_voffset_(0),
|
||||
@@ -116,7 +116,7 @@ class FlatBufferBuilder {
|
||||
}
|
||||
|
||||
/// @brief Move assignment operator for FlatBufferBuilder.
|
||||
FlatBufferBuilder &operator=(FlatBufferBuilder &&other) {
|
||||
FlatBufferBuilder &operator=(FlatBufferBuilder &&other) noexcept {
|
||||
// Move construct a temporary and swap idiom
|
||||
FlatBufferBuilder temp(std::move(other));
|
||||
Swap(temp);
|
||||
|
||||
@@ -19,9 +19,11 @@
|
||||
|
||||
#include <functional>
|
||||
#include <limits>
|
||||
#include <list>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
#include "flatbuffers/bfbs_generator.h"
|
||||
#include "flatbuffers/code_generator.h"
|
||||
#include "flatbuffers/flatbuffers.h"
|
||||
#include "flatbuffers/idl.h"
|
||||
#include "flatbuffers/util.h"
|
||||
@@ -31,6 +33,33 @@ namespace flatbuffers {
|
||||
extern void LogCompilerWarn(const std::string &warn);
|
||||
extern void LogCompilerError(const std::string &err);
|
||||
|
||||
struct FlatCOptions {
|
||||
IDLOptions opts;
|
||||
|
||||
std::string program_name;
|
||||
|
||||
std::string output_path;
|
||||
|
||||
std::vector<std::string> filenames;
|
||||
|
||||
std::list<std::string> include_directories_storage;
|
||||
std::vector<const char *> include_directories;
|
||||
std::vector<const char *> conform_include_directories;
|
||||
std::vector<bool> generator_enabled;
|
||||
size_t binary_files_from = std::numeric_limits<size_t>::max();
|
||||
std::string conform_to_schema;
|
||||
std::string annotate_schema;
|
||||
bool annotate_include_vector_contents = true;
|
||||
bool any_generator = false;
|
||||
bool print_make_rules = false;
|
||||
bool raw_binary = false;
|
||||
bool schema_binary = false;
|
||||
bool grpc_enabled = false;
|
||||
bool requires_bfbs = false;
|
||||
|
||||
std::vector<std::shared_ptr<CodeGenerator>> generators;
|
||||
};
|
||||
|
||||
struct FlatCOption {
|
||||
std::string short_opt;
|
||||
std::string long_opt;
|
||||
@@ -40,29 +69,6 @@ struct FlatCOption {
|
||||
|
||||
class FlatCompiler {
|
||||
public:
|
||||
// Output generator for the various programming languages and formats we
|
||||
// support.
|
||||
struct Generator {
|
||||
typedef bool (*GenerateFn)(const flatbuffers::Parser &parser,
|
||||
const std::string &path,
|
||||
const std::string &file_name);
|
||||
typedef std::string (*MakeRuleFn)(const flatbuffers::Parser &parser,
|
||||
const std::string &path,
|
||||
const std::string &file_name);
|
||||
typedef bool (*ParsingCompletedFn)(const flatbuffers::Parser &parser,
|
||||
const std::string &output_path);
|
||||
|
||||
GenerateFn generate;
|
||||
const char *lang_name;
|
||||
bool schema_only;
|
||||
GenerateFn generateGRPC;
|
||||
flatbuffers::IDLOptions::Language lang;
|
||||
FlatCOption option;
|
||||
MakeRuleFn make_rule;
|
||||
BfbsGenerator *bfbs_generator;
|
||||
ParsingCompletedFn parsing_completed;
|
||||
};
|
||||
|
||||
typedef void (*WarnFn)(const FlatCompiler *flatc, const std::string &warn,
|
||||
bool show_exe_name);
|
||||
|
||||
@@ -71,29 +77,29 @@ class FlatCompiler {
|
||||
|
||||
// Parameters required to initialize the FlatCompiler.
|
||||
struct InitParams {
|
||||
InitParams()
|
||||
: generators(nullptr),
|
||||
num_generators(0),
|
||||
warn_fn(nullptr),
|
||||
error_fn(nullptr) {}
|
||||
InitParams() : warn_fn(nullptr), error_fn(nullptr) {}
|
||||
|
||||
const Generator *generators;
|
||||
size_t num_generators;
|
||||
WarnFn warn_fn;
|
||||
ErrorFn error_fn;
|
||||
};
|
||||
|
||||
explicit FlatCompiler(const InitParams ¶ms) : params_(params) {}
|
||||
|
||||
int Compile(int argc, const char **argv);
|
||||
bool RegisterCodeGenerator(const FlatCOption &option,
|
||||
std::shared_ptr<CodeGenerator> code_generator);
|
||||
|
||||
std::string GetShortUsageString(const char *program_name) const;
|
||||
std::string GetUsageString(const char *program_name) const;
|
||||
int Compile(const FlatCOptions &options);
|
||||
|
||||
std::string GetShortUsageString(const std::string &program_name) const;
|
||||
std::string GetUsageString(const std::string &program_name) const;
|
||||
|
||||
// Parse the FlatC options from command line arguments.
|
||||
FlatCOptions ParseFromCommandLineArguments(int argc, const char **argv);
|
||||
|
||||
private:
|
||||
void ParseFile(flatbuffers::Parser &parser, const std::string &filename,
|
||||
const std::string &contents,
|
||||
std::vector<const char *> &include_directories) const;
|
||||
const std::vector<const char *> &include_directories) const;
|
||||
|
||||
void LoadBinarySchema(Parser &parser, const std::string &filename,
|
||||
const std::string &contents);
|
||||
@@ -105,8 +111,16 @@ class FlatCompiler {
|
||||
|
||||
void AnnotateBinaries(const uint8_t *binary_schema,
|
||||
uint64_t binary_schema_size,
|
||||
const std::string & schema_filename,
|
||||
const std::vector<std::string> &binary_files);
|
||||
const FlatCOptions &options);
|
||||
|
||||
void ValidateOptions(const FlatCOptions &options);
|
||||
|
||||
Parser GetConformParser(const FlatCOptions &options);
|
||||
|
||||
std::unique_ptr<Parser> GenerateCode(const FlatCOptions &options,
|
||||
Parser &conform_parser);
|
||||
|
||||
std::map<std::string, std::shared_ptr<CodeGenerator>> code_generators_;
|
||||
|
||||
InitParams params_;
|
||||
};
|
||||
|
||||
@@ -1845,7 +1845,7 @@ class Verifier FLATBUFFERS_FINAL_CLASS {
|
||||
uint8_t len = 0;
|
||||
auto vtype = ToFixedTypedVectorElementType(r.type_, &len);
|
||||
if (!VerifyType(vtype)) return false;
|
||||
return VerifyFromPointer(p, r.byte_width_ * len);
|
||||
return VerifyFromPointer(p, static_cast<size_t>(r.byte_width_) * len);
|
||||
}
|
||||
default: return false;
|
||||
}
|
||||
|
||||
@@ -45,26 +45,26 @@ namespace flatbuffers {
|
||||
// of type tokens.
|
||||
// clang-format off
|
||||
#define FLATBUFFERS_GEN_TYPES_SCALAR(TD) \
|
||||
TD(NONE, "", uint8_t, byte, byte, byte, uint8, u8, UByte, UInt8) \
|
||||
TD(UTYPE, "", uint8_t, byte, byte, byte, uint8, u8, UByte, UInt8) /* begin scalar/int */ \
|
||||
TD(BOOL, "bool", uint8_t, boolean,bool, bool, bool, bool, Boolean, Bool) \
|
||||
TD(CHAR, "byte", int8_t, byte, int8, sbyte, int8, i8, Byte, Int8) \
|
||||
TD(UCHAR, "ubyte", uint8_t, byte, byte, byte, uint8, u8, UByte, UInt8) \
|
||||
TD(SHORT, "short", int16_t, short, int16, short, int16, i16, Short, Int16) \
|
||||
TD(USHORT, "ushort", uint16_t, short, uint16, ushort, uint16, u16, UShort, UInt16) \
|
||||
TD(INT, "int", int32_t, int, int32, int, int32, i32, Int, Int32) \
|
||||
TD(UINT, "uint", uint32_t, int, uint32, uint, uint32, u32, UInt, UInt32) \
|
||||
TD(LONG, "long", int64_t, long, int64, long, int64, i64, Long, Int64) \
|
||||
TD(ULONG, "ulong", uint64_t, long, uint64, ulong, uint64, u64, ULong, UInt64) /* end int */ \
|
||||
TD(FLOAT, "float", float, float, float32, float, float32, f32, Float, Float32) /* begin float */ \
|
||||
TD(DOUBLE, "double", double, double, float64, double, float64, f64, Double, Double) /* end float/scalar */
|
||||
TD(NONE, "", uint8_t, byte, byte, byte, uint8, u8, UByte, UInt8, 0) \
|
||||
TD(UTYPE, "", uint8_t, byte, byte, byte, uint8, u8, UByte, UInt8, 1) /* begin scalar/int */ \
|
||||
TD(BOOL, "bool", uint8_t, boolean,bool, bool, bool, bool, Boolean, Bool, 2) \
|
||||
TD(CHAR, "byte", int8_t, byte, int8, sbyte, int8, i8, Byte, Int8, 3) \
|
||||
TD(UCHAR, "ubyte", uint8_t, byte, byte, byte, uint8, u8, UByte, UInt8, 4) \
|
||||
TD(SHORT, "short", int16_t, short, int16, short, int16, i16, Short, Int16, 5) \
|
||||
TD(USHORT, "ushort", uint16_t, short, uint16, ushort, uint16, u16, UShort, UInt16, 6) \
|
||||
TD(INT, "int", int32_t, int, int32, int, int32, i32, Int, Int32, 7) \
|
||||
TD(UINT, "uint", uint32_t, int, uint32, uint, uint32, u32, UInt, UInt32, 8) \
|
||||
TD(LONG, "long", int64_t, long, int64, long, int64, i64, Long, Int64, 9) \
|
||||
TD(ULONG, "ulong", uint64_t, long, uint64, ulong, uint64, u64, ULong, UInt64, 10) /* end int */ \
|
||||
TD(FLOAT, "float", float, float, float32, float, float32, f32, Float, Float32, 11) /* begin float */ \
|
||||
TD(DOUBLE, "double", double, double, float64, double, float64, f64, Double, Double, 12) /* end float/scalar */
|
||||
#define FLATBUFFERS_GEN_TYPES_POINTER(TD) \
|
||||
TD(STRING, "string", Offset<void>, int, int, StringOffset, int, unused, Int, Offset<String>) \
|
||||
TD(VECTOR, "", Offset<void>, int, int, VectorOffset, int, unused, Int, Offset<UOffset>) \
|
||||
TD(STRUCT, "", Offset<void>, int, int, int, int, unused, Int, Offset<UOffset>) \
|
||||
TD(UNION, "", Offset<void>, int, int, int, int, unused, Int, Offset<UOffset>)
|
||||
TD(STRING, "string", Offset<void>, int, int, StringOffset, int, unused, Int, Offset<String>, 13) \
|
||||
TD(VECTOR, "", Offset<void>, int, int, VectorOffset, int, unused, Int, Offset<UOffset>, 14) \
|
||||
TD(STRUCT, "", Offset<void>, int, int, int, int, unused, Int, Offset<UOffset>, 15) \
|
||||
TD(UNION, "", Offset<void>, int, int, int, int, unused, Int, Offset<UOffset>, 16)
|
||||
#define FLATBUFFERS_GEN_TYPE_ARRAY(TD) \
|
||||
TD(ARRAY, "", int, int, int, int, int, unused, Int, Offset<UOffset>)
|
||||
TD(ARRAY, "", int, int, int, int, int, unused, Int, Offset<UOffset>, 17)
|
||||
// The fields are:
|
||||
// - enum
|
||||
// - FlatBuffers schema type.
|
||||
@@ -75,13 +75,15 @@ namespace flatbuffers {
|
||||
// - Python type.
|
||||
// - Kotlin type.
|
||||
// - Rust type.
|
||||
// - Swift type.
|
||||
// - enum value (matches the reflected values)
|
||||
|
||||
// using these macros, we can now write code dealing with types just once, e.g.
|
||||
|
||||
/*
|
||||
switch (type) {
|
||||
#define FLATBUFFERS_TD(ENUM, IDLTYPE, CTYPE, JTYPE, GTYPE, NTYPE, PTYPE, \
|
||||
RTYPE, KTYPE) \
|
||||
RTYPE, KTYPE, STYPE, ...) \
|
||||
case BASE_TYPE_ ## ENUM: \
|
||||
// do something specific to CTYPE here
|
||||
FLATBUFFERS_GEN_TYPES(FLATBUFFERS_TD)
|
||||
@@ -113,8 +115,9 @@ switch (type) {
|
||||
__extension__ // Stop GCC complaining about trailing comma with -Wpendantic.
|
||||
#endif
|
||||
enum BaseType {
|
||||
#define FLATBUFFERS_TD(ENUM, ...) \
|
||||
BASE_TYPE_ ## ENUM,
|
||||
#define FLATBUFFERS_TD(ENUM, IDLTYPE, \
|
||||
CTYPE, JTYPE, GTYPE, NTYPE, PTYPE, RTYPE, KTYPE, STYPE, ENUM_VALUE) \
|
||||
BASE_TYPE_ ## ENUM = ENUM_VALUE,
|
||||
FLATBUFFERS_GEN_TYPES(FLATBUFFERS_TD)
|
||||
#undef FLATBUFFERS_TD
|
||||
};
|
||||
@@ -143,13 +146,41 @@ inline bool IsUnsigned(BaseType t) {
|
||||
(t == BASE_TYPE_ULONG);
|
||||
}
|
||||
|
||||
inline size_t SizeOf(const BaseType t) {
|
||||
switch (t) {
|
||||
#define FLATBUFFERS_TD(ENUM, IDLTYPE, CTYPE, ...) \
|
||||
case BASE_TYPE_##ENUM: return sizeof(CTYPE);
|
||||
FLATBUFFERS_GEN_TYPES(FLATBUFFERS_TD)
|
||||
#undef FLATBUFFERS_TD
|
||||
default: FLATBUFFERS_ASSERT(0);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
inline const char* TypeName(const BaseType t) {
|
||||
switch (t) {
|
||||
#define FLATBUFFERS_TD(ENUM, IDLTYPE, ...) \
|
||||
case BASE_TYPE_##ENUM: return IDLTYPE;
|
||||
FLATBUFFERS_GEN_TYPES(FLATBUFFERS_TD)
|
||||
#undef FLATBUFFERS_TD
|
||||
default: FLATBUFFERS_ASSERT(0);
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
inline const char* StringOf(const BaseType t) {
|
||||
switch (t) {
|
||||
#define FLATBUFFERS_TD(ENUM, IDLTYPE, CTYPE, ...) \
|
||||
case BASE_TYPE_##ENUM: return #CTYPE;
|
||||
FLATBUFFERS_GEN_TYPES(FLATBUFFERS_TD)
|
||||
#undef FLATBUFFERS_TD
|
||||
default: FLATBUFFERS_ASSERT(0);
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
// clang-format on
|
||||
|
||||
extern const char *const kTypeNames[];
|
||||
extern const char kTypeSizes[];
|
||||
|
||||
inline size_t SizeOf(BaseType t) { return kTypeSizes[t]; }
|
||||
|
||||
struct StructDef;
|
||||
struct EnumDef;
|
||||
class Parser;
|
||||
@@ -297,7 +328,8 @@ struct FieldDef : public Definition {
|
||||
flexbuffer(false),
|
||||
presence(kDefault),
|
||||
nested_flatbuffer(nullptr),
|
||||
padding(0) {}
|
||||
padding(0),
|
||||
sibling_union_field(nullptr) {}
|
||||
|
||||
Offset<reflection::Field> Serialize(FlatBufferBuilder *builder, uint16_t id,
|
||||
const Parser &parser) const;
|
||||
@@ -342,6 +374,12 @@ struct FieldDef : public Definition {
|
||||
|
||||
StructDef *nested_flatbuffer; // This field contains nested FlatBuffer data.
|
||||
size_t padding; // Bytes to always pad after this field.
|
||||
|
||||
// sibling_union_field is always set to nullptr. The only exception is
|
||||
// when FieldDef is a union field or an union type field. Therefore,
|
||||
// sibling_union_field on a union field points to the union type field
|
||||
// and vice-versa.
|
||||
FieldDef *sibling_union_field;
|
||||
};
|
||||
|
||||
struct StructDef : public Definition {
|
||||
@@ -374,6 +412,7 @@ struct StructDef : public Definition {
|
||||
size_t bytesize; // Size if fixed.
|
||||
|
||||
flatbuffers::unique_ptr<std::string> original_location;
|
||||
std::vector<voffset_t> reserved_ids;
|
||||
};
|
||||
|
||||
struct EnumDef;
|
||||
@@ -587,7 +626,7 @@ inline bool operator<(const IncludedFile &a, const IncludedFile &b) {
|
||||
struct IDLOptions {
|
||||
// field case style options for C++
|
||||
enum CaseStyle { CaseStyle_Unchanged = 0, CaseStyle_Upper, CaseStyle_Lower };
|
||||
|
||||
enum class ProtoIdGapAction { NO_OP, WARNING, ERROR };
|
||||
bool gen_jvmstatic;
|
||||
// Use flexbuffers instead for binary and text generation
|
||||
bool use_flexbuffers;
|
||||
@@ -598,6 +637,7 @@ struct IDLOptions {
|
||||
bool output_enum_identifiers;
|
||||
bool prefixed_enums;
|
||||
bool scoped_enums;
|
||||
bool emit_min_max_enum_values;
|
||||
bool swift_implementation_only;
|
||||
bool include_dependence_headers;
|
||||
bool mutable_buffer;
|
||||
@@ -615,6 +655,7 @@ struct IDLOptions {
|
||||
CaseStyle cpp_object_api_field_case_style;
|
||||
bool cpp_direct_copy;
|
||||
bool gen_nullable;
|
||||
std::string java_package_prefix;
|
||||
bool java_checkerframework;
|
||||
bool gen_generated;
|
||||
bool gen_json_coders;
|
||||
@@ -650,9 +691,13 @@ struct IDLOptions {
|
||||
bool json_nested_flatbuffers;
|
||||
bool json_nested_flexbuffers;
|
||||
bool json_nested_legacy_flatbuffers;
|
||||
bool ts_flat_file;
|
||||
bool ts_flat_files;
|
||||
bool ts_entry_points;
|
||||
bool ts_no_import_ext;
|
||||
bool no_leak_private_annotations;
|
||||
bool require_json_eof;
|
||||
bool keep_proto_id;
|
||||
ProtoIdGapAction proto_id_gap_action;
|
||||
|
||||
// Possible options for the more general generator below.
|
||||
enum Language {
|
||||
@@ -673,6 +718,7 @@ struct IDLOptions {
|
||||
kKotlin = 1 << 15,
|
||||
kSwift = 1 << 16,
|
||||
kNim = 1 << 17,
|
||||
kProto = 1 << 18,
|
||||
kMAX
|
||||
};
|
||||
|
||||
@@ -711,6 +757,7 @@ struct IDLOptions {
|
||||
output_enum_identifiers(true),
|
||||
prefixed_enums(true),
|
||||
scoped_enums(false),
|
||||
emit_min_max_enum_values(true),
|
||||
swift_implementation_only(false),
|
||||
include_dependence_headers(true),
|
||||
mutable_buffer(false),
|
||||
@@ -753,9 +800,13 @@ struct IDLOptions {
|
||||
json_nested_flatbuffers(true),
|
||||
json_nested_flexbuffers(true),
|
||||
json_nested_legacy_flatbuffers(false),
|
||||
ts_flat_file(false),
|
||||
ts_flat_files(false),
|
||||
ts_entry_points(false),
|
||||
ts_no_import_ext(false),
|
||||
no_leak_private_annotations(false),
|
||||
require_json_eof(true),
|
||||
keep_proto_id(false),
|
||||
proto_id_gap_action(ProtoIdGapAction::WARNING),
|
||||
mini_reflect(IDLOptions::kNone),
|
||||
require_explicit_ids(false),
|
||||
rust_serialize(false),
|
||||
@@ -792,7 +843,7 @@ struct ParserState {
|
||||
FLATBUFFERS_ASSERT(cursor_ && line_start_ && cursor_ >= line_start_);
|
||||
return static_cast<int64_t>(cursor_ - line_start_);
|
||||
}
|
||||
|
||||
|
||||
const char *prev_cursor_;
|
||||
const char *cursor_;
|
||||
const char *line_start_;
|
||||
@@ -899,6 +950,13 @@ class Parser : public ParserState {
|
||||
known_attributes_["private"] = true;
|
||||
}
|
||||
|
||||
// Copying is not allowed
|
||||
Parser(const Parser &) = delete;
|
||||
Parser &operator=(const Parser &) = delete;
|
||||
|
||||
Parser(Parser &&) = default;
|
||||
Parser &operator=(Parser &&) = default;
|
||||
|
||||
~Parser() {
|
||||
for (auto it = namespaces_.begin(); it != namespaces_.end(); ++it) {
|
||||
delete *it;
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -41,15 +41,18 @@
|
||||
#include <optional>
|
||||
#endif
|
||||
|
||||
// The __cpp_lib_span is the predefined feature macro.
|
||||
#if defined(FLATBUFFERS_USE_STD_SPAN)
|
||||
#include <span>
|
||||
#elif defined(__cpp_lib_span) && defined(__has_include)
|
||||
#if __has_include(<span>)
|
||||
#include <array>
|
||||
#include <span>
|
||||
#define FLATBUFFERS_USE_STD_SPAN
|
||||
#ifndef FLATBUFFERS_USE_STD_SPAN
|
||||
// Testing __cpp_lib_span requires including either <version> or <span>,
|
||||
// both of which were added in C++20.
|
||||
// See: https://en.cppreference.com/w/cpp/utility/feature_test
|
||||
#if defined(__cplusplus) && __cplusplus >= 202002L
|
||||
#define FLATBUFFERS_USE_STD_SPAN 1
|
||||
#endif
|
||||
#endif // FLATBUFFERS_USE_STD_SPAN
|
||||
|
||||
#if defined(FLATBUFFERS_USE_STD_SPAN)
|
||||
#include <array>
|
||||
#include <span>
|
||||
#else
|
||||
// Disable non-trivial ctors if FLATBUFFERS_SPAN_MINIMAL defined.
|
||||
#if !defined(FLATBUFFERS_TEMPLATES_ALIASES)
|
||||
|
||||
@@ -31,6 +31,7 @@
|
||||
# include <stdio.h>
|
||||
#endif // FLATBUFFERS_PREFER_PRINTF
|
||||
|
||||
#include <cmath>
|
||||
#include <limits>
|
||||
#include <string>
|
||||
|
||||
@@ -313,6 +314,7 @@ inline bool StringToFloatImpl(T *val, const char *const str) {
|
||||
strtoval_impl(val, str, const_cast<char **>(&end));
|
||||
auto done = (end != str) && (*end == '\0');
|
||||
if (!done) *val = 0; // erase partial result
|
||||
if (done && std::isnan(*val)) { *val = std::numeric_limits<T>::quiet_NaN(); }
|
||||
return done;
|
||||
}
|
||||
|
||||
|
||||
@@ -45,7 +45,7 @@ class vector_downward {
|
||||
cur_(nullptr),
|
||||
scratch_(nullptr) {}
|
||||
|
||||
vector_downward(vector_downward &&other)
|
||||
vector_downward(vector_downward &&other) noexcept
|
||||
// clang-format on
|
||||
: allocator_(other.allocator_),
|
||||
own_allocator_(other.own_allocator_),
|
||||
@@ -66,7 +66,7 @@ class vector_downward {
|
||||
other.scratch_ = nullptr;
|
||||
}
|
||||
|
||||
vector_downward &operator=(vector_downward &&other) {
|
||||
vector_downward &operator=(vector_downward &&other) noexcept {
|
||||
// Move construct a temporary and swap idiom
|
||||
vector_downward temp(std::move(other));
|
||||
swap(temp);
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>com.google.flatbuffers</groupId>
|
||||
<artifactId>flatbuffers-java</artifactId>
|
||||
<version>23.1.4</version>
|
||||
<version>23.3.3</version>
|
||||
<packaging>bundle</packaging>
|
||||
<name>FlatBuffers Java API</name>
|
||||
<description>
|
||||
@@ -25,7 +25,7 @@
|
||||
<licenses>
|
||||
<license>
|
||||
<name>Apache License V2.0</name>
|
||||
<url>https://raw.githubusercontent.com/google/flatbuffers/master/LICENSE.txt</url>
|
||||
<url>https://raw.githubusercontent.com/google/flatbuffers/master/LICENSE</url>
|
||||
<distribution>repo</distribution>
|
||||
</license>
|
||||
</licenses>
|
||||
|
||||
@@ -46,7 +46,7 @@ public class Constants {
|
||||
Changes to the Java implementation need to be sure to change
|
||||
the version here and in the code generator on every possible
|
||||
incompatible change */
|
||||
public static void FLATBUFFERS_23_1_4() {}
|
||||
public static void FLATBUFFERS_23_3_3() {}
|
||||
}
|
||||
|
||||
/// @endcond
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
// automatically generated by the FlatBuffers compiler, do not modify
|
||||
|
||||
package com.google.flatbuffers.reflection;
|
||||
|
||||
/**
|
||||
* New schema language features that are not supported by old code generators.
|
||||
*/
|
||||
@SuppressWarnings("unused")
|
||||
public final class AdvancedFeatures {
|
||||
private AdvancedFeatures() { }
|
||||
public static final long AdvancedArrayFeatures = 1L;
|
||||
public static final long AdvancedUnionFeatures = 2L;
|
||||
public static final long OptionalScalars = 4L;
|
||||
public static final long DefaultVectorsAndStrings = 8L;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
// automatically generated by the FlatBuffers compiler, do not modify
|
||||
|
||||
package com.google.flatbuffers.reflection;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public final class BaseType {
|
||||
private BaseType() { }
|
||||
public static final byte None = 0;
|
||||
public static final byte UType = 1;
|
||||
public static final byte Bool = 2;
|
||||
public static final byte Byte = 3;
|
||||
public static final byte UByte = 4;
|
||||
public static final byte Short = 5;
|
||||
public static final byte UShort = 6;
|
||||
public static final byte Int = 7;
|
||||
public static final byte UInt = 8;
|
||||
public static final byte Long = 9;
|
||||
public static final byte ULong = 10;
|
||||
public static final byte Float = 11;
|
||||
public static final byte Double = 12;
|
||||
public static final byte String = 13;
|
||||
public static final byte Vector = 14;
|
||||
public static final byte Obj = 15;
|
||||
public static final byte Union = 16;
|
||||
public static final byte Array = 17;
|
||||
public static final byte MaxBaseType = 18;
|
||||
|
||||
public static final String[] names = { "None", "UType", "Bool", "Byte", "UByte", "Short", "UShort", "Int", "UInt", "Long", "ULong", "Float", "Double", "String", "Vector", "Obj", "Union", "Array", "MaxBaseType", };
|
||||
|
||||
public static String name(int e) { return names[e]; }
|
||||
}
|
||||
|
||||
135
java/src/main/java/com/google/flatbuffers/reflection/Enum.java
Normal file
135
java/src/main/java/com/google/flatbuffers/reflection/Enum.java
Normal file
@@ -0,0 +1,135 @@
|
||||
// automatically generated by the FlatBuffers compiler, do not modify
|
||||
|
||||
package com.google.flatbuffers.reflection;
|
||||
|
||||
import com.google.flatbuffers.BaseVector;
|
||||
import com.google.flatbuffers.BooleanVector;
|
||||
import com.google.flatbuffers.ByteVector;
|
||||
import com.google.flatbuffers.Constants;
|
||||
import com.google.flatbuffers.DoubleVector;
|
||||
import com.google.flatbuffers.FlatBufferBuilder;
|
||||
import com.google.flatbuffers.FloatVector;
|
||||
import com.google.flatbuffers.IntVector;
|
||||
import com.google.flatbuffers.LongVector;
|
||||
import com.google.flatbuffers.ShortVector;
|
||||
import com.google.flatbuffers.StringVector;
|
||||
import com.google.flatbuffers.Struct;
|
||||
import com.google.flatbuffers.Table;
|
||||
import com.google.flatbuffers.UnionVector;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.ByteOrder;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public final class Enum extends Table {
|
||||
public static void ValidateVersion() { Constants.FLATBUFFERS_23_3_3(); }
|
||||
public static Enum getRootAsEnum(ByteBuffer _bb) { return getRootAsEnum(_bb, new Enum()); }
|
||||
public static Enum getRootAsEnum(ByteBuffer _bb, Enum obj) { _bb.order(ByteOrder.LITTLE_ENDIAN); return (obj.__assign(_bb.getInt(_bb.position()) + _bb.position(), _bb)); }
|
||||
public void __init(int _i, ByteBuffer _bb) { __reset(_i, _bb); }
|
||||
public Enum __assign(int _i, ByteBuffer _bb) { __init(_i, _bb); return this; }
|
||||
|
||||
public String name() { int o = __offset(4); return o != 0 ? __string(o + bb_pos) : null; }
|
||||
public ByteBuffer nameAsByteBuffer() { return __vector_as_bytebuffer(4, 1); }
|
||||
public ByteBuffer nameInByteBuffer(ByteBuffer _bb) { return __vector_in_bytebuffer(_bb, 4, 1); }
|
||||
public com.google.flatbuffers.reflection.EnumVal values(int j) { return values(new com.google.flatbuffers.reflection.EnumVal(), j); }
|
||||
public com.google.flatbuffers.reflection.EnumVal values(com.google.flatbuffers.reflection.EnumVal obj, int j) { int o = __offset(6); return o != 0 ? obj.__assign(__indirect(__vector(o) + j * 4), bb) : null; }
|
||||
public int valuesLength() { int o = __offset(6); return o != 0 ? __vector_len(o) : 0; }
|
||||
public com.google.flatbuffers.reflection.EnumVal valuesByKey(long key) { int o = __offset(6); return o != 0 ? com.google.flatbuffers.reflection.EnumVal.__lookup_by_key(null, __vector(o), key, bb) : null; }
|
||||
public com.google.flatbuffers.reflection.EnumVal valuesByKey(com.google.flatbuffers.reflection.EnumVal obj, long key) { int o = __offset(6); return o != 0 ? com.google.flatbuffers.reflection.EnumVal.__lookup_by_key(obj, __vector(o), key, bb) : null; }
|
||||
public com.google.flatbuffers.reflection.EnumVal.Vector valuesVector() { return valuesVector(new com.google.flatbuffers.reflection.EnumVal.Vector()); }
|
||||
public com.google.flatbuffers.reflection.EnumVal.Vector valuesVector(com.google.flatbuffers.reflection.EnumVal.Vector obj) { int o = __offset(6); return o != 0 ? obj.__assign(__vector(o), 4, bb) : null; }
|
||||
public boolean isUnion() { int o = __offset(8); return o != 0 ? 0!=bb.get(o + bb_pos) : false; }
|
||||
public com.google.flatbuffers.reflection.Type underlyingType() { return underlyingType(new com.google.flatbuffers.reflection.Type()); }
|
||||
public com.google.flatbuffers.reflection.Type underlyingType(com.google.flatbuffers.reflection.Type obj) { int o = __offset(10); return o != 0 ? obj.__assign(__indirect(o + bb_pos), bb) : null; }
|
||||
public com.google.flatbuffers.reflection.KeyValue attributes(int j) { return attributes(new com.google.flatbuffers.reflection.KeyValue(), j); }
|
||||
public com.google.flatbuffers.reflection.KeyValue attributes(com.google.flatbuffers.reflection.KeyValue obj, int j) { int o = __offset(12); return o != 0 ? obj.__assign(__indirect(__vector(o) + j * 4), bb) : null; }
|
||||
public int attributesLength() { int o = __offset(12); return o != 0 ? __vector_len(o) : 0; }
|
||||
public com.google.flatbuffers.reflection.KeyValue attributesByKey(String key) { int o = __offset(12); return o != 0 ? com.google.flatbuffers.reflection.KeyValue.__lookup_by_key(null, __vector(o), key, bb) : null; }
|
||||
public com.google.flatbuffers.reflection.KeyValue attributesByKey(com.google.flatbuffers.reflection.KeyValue obj, String key) { int o = __offset(12); return o != 0 ? com.google.flatbuffers.reflection.KeyValue.__lookup_by_key(obj, __vector(o), key, bb) : null; }
|
||||
public com.google.flatbuffers.reflection.KeyValue.Vector attributesVector() { return attributesVector(new com.google.flatbuffers.reflection.KeyValue.Vector()); }
|
||||
public com.google.flatbuffers.reflection.KeyValue.Vector attributesVector(com.google.flatbuffers.reflection.KeyValue.Vector obj) { int o = __offset(12); return o != 0 ? obj.__assign(__vector(o), 4, bb) : null; }
|
||||
public String documentation(int j) { int o = __offset(14); return o != 0 ? __string(__vector(o) + j * 4) : null; }
|
||||
public int documentationLength() { int o = __offset(14); return o != 0 ? __vector_len(o) : 0; }
|
||||
public StringVector documentationVector() { return documentationVector(new StringVector()); }
|
||||
public StringVector documentationVector(StringVector obj) { int o = __offset(14); return o != 0 ? obj.__assign(__vector(o), 4, bb) : null; }
|
||||
/**
|
||||
* File that this Enum is declared in.
|
||||
*/
|
||||
public String declarationFile() { int o = __offset(16); return o != 0 ? __string(o + bb_pos) : null; }
|
||||
public ByteBuffer declarationFileAsByteBuffer() { return __vector_as_bytebuffer(16, 1); }
|
||||
public ByteBuffer declarationFileInByteBuffer(ByteBuffer _bb) { return __vector_in_bytebuffer(_bb, 16, 1); }
|
||||
|
||||
public static int createEnum(FlatBufferBuilder builder,
|
||||
int nameOffset,
|
||||
int valuesOffset,
|
||||
boolean isUnion,
|
||||
int underlyingTypeOffset,
|
||||
int attributesOffset,
|
||||
int documentationOffset,
|
||||
int declarationFileOffset) {
|
||||
builder.startTable(7);
|
||||
Enum.addDeclarationFile(builder, declarationFileOffset);
|
||||
Enum.addDocumentation(builder, documentationOffset);
|
||||
Enum.addAttributes(builder, attributesOffset);
|
||||
Enum.addUnderlyingType(builder, underlyingTypeOffset);
|
||||
Enum.addValues(builder, valuesOffset);
|
||||
Enum.addName(builder, nameOffset);
|
||||
Enum.addIsUnion(builder, isUnion);
|
||||
return Enum.endEnum(builder);
|
||||
}
|
||||
|
||||
public static void startEnum(FlatBufferBuilder builder) { builder.startTable(7); }
|
||||
public static void addName(FlatBufferBuilder builder, int nameOffset) { builder.addOffset(nameOffset); builder.slot(0); }
|
||||
public static void addValues(FlatBufferBuilder builder, int valuesOffset) { builder.addOffset(1, valuesOffset, 0); }
|
||||
public static int createValuesVector(FlatBufferBuilder builder, int[] data) { builder.startVector(4, data.length, 4); for (int i = data.length - 1; i >= 0; i--) builder.addOffset(data[i]); return builder.endVector(); }
|
||||
public static void startValuesVector(FlatBufferBuilder builder, int numElems) { builder.startVector(4, numElems, 4); }
|
||||
public static void addIsUnion(FlatBufferBuilder builder, boolean isUnion) { builder.addBoolean(2, isUnion, false); }
|
||||
public static void addUnderlyingType(FlatBufferBuilder builder, int underlyingTypeOffset) { builder.addOffset(3, underlyingTypeOffset, 0); }
|
||||
public static void addAttributes(FlatBufferBuilder builder, int attributesOffset) { builder.addOffset(4, attributesOffset, 0); }
|
||||
public static int createAttributesVector(FlatBufferBuilder builder, int[] data) { builder.startVector(4, data.length, 4); for (int i = data.length - 1; i >= 0; i--) builder.addOffset(data[i]); return builder.endVector(); }
|
||||
public static void startAttributesVector(FlatBufferBuilder builder, int numElems) { builder.startVector(4, numElems, 4); }
|
||||
public static void addDocumentation(FlatBufferBuilder builder, int documentationOffset) { builder.addOffset(5, documentationOffset, 0); }
|
||||
public static int createDocumentationVector(FlatBufferBuilder builder, int[] data) { builder.startVector(4, data.length, 4); for (int i = data.length - 1; i >= 0; i--) builder.addOffset(data[i]); return builder.endVector(); }
|
||||
public static void startDocumentationVector(FlatBufferBuilder builder, int numElems) { builder.startVector(4, numElems, 4); }
|
||||
public static void addDeclarationFile(FlatBufferBuilder builder, int declarationFileOffset) { builder.addOffset(6, declarationFileOffset, 0); }
|
||||
public static int endEnum(FlatBufferBuilder builder) {
|
||||
int o = builder.endTable();
|
||||
builder.required(o, 4); // name
|
||||
builder.required(o, 6); // values
|
||||
builder.required(o, 10); // underlying_type
|
||||
return o;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int keysCompare(Integer o1, Integer o2, ByteBuffer _bb) { return compareStrings(__offset(4, o1, _bb), __offset(4, o2, _bb), _bb); }
|
||||
|
||||
public static Enum __lookup_by_key(Enum obj, int vectorLocation, String key, ByteBuffer bb) {
|
||||
byte[] byteKey = key.getBytes(java.nio.charset.StandardCharsets.UTF_8);
|
||||
int span = bb.getInt(vectorLocation - 4);
|
||||
int start = 0;
|
||||
while (span != 0) {
|
||||
int middle = span / 2;
|
||||
int tableOffset = __indirect(vectorLocation + 4 * (start + middle), bb);
|
||||
int comp = compareStrings(__offset(4, bb.capacity() - tableOffset, bb), byteKey, bb);
|
||||
if (comp > 0) {
|
||||
span = middle;
|
||||
} else if (comp < 0) {
|
||||
middle++;
|
||||
start += middle;
|
||||
span -= middle;
|
||||
} else {
|
||||
return (obj == null ? new Enum() : obj).__assign(tableOffset, bb);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static final class Vector extends BaseVector {
|
||||
public Vector __assign(int _vector, int _element_size, ByteBuffer _bb) { __reset(_vector, _element_size, _bb); return this; }
|
||||
|
||||
public Enum get(int j) { return get(new Enum(), j); }
|
||||
public Enum get(Enum obj, int j) { return obj.__assign(__indirect(__element(j), bb), bb); }
|
||||
public Enum getByKey(String key) { return __lookup_by_key(null, __vector(), key, bb); }
|
||||
public Enum getByKey(Enum obj, String key) { return __lookup_by_key(obj, __vector(), key, bb); }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,116 @@
|
||||
// automatically generated by the FlatBuffers compiler, do not modify
|
||||
|
||||
package com.google.flatbuffers.reflection;
|
||||
|
||||
import com.google.flatbuffers.BaseVector;
|
||||
import com.google.flatbuffers.BooleanVector;
|
||||
import com.google.flatbuffers.ByteVector;
|
||||
import com.google.flatbuffers.Constants;
|
||||
import com.google.flatbuffers.DoubleVector;
|
||||
import com.google.flatbuffers.FlatBufferBuilder;
|
||||
import com.google.flatbuffers.FloatVector;
|
||||
import com.google.flatbuffers.IntVector;
|
||||
import com.google.flatbuffers.LongVector;
|
||||
import com.google.flatbuffers.ShortVector;
|
||||
import com.google.flatbuffers.StringVector;
|
||||
import com.google.flatbuffers.Struct;
|
||||
import com.google.flatbuffers.Table;
|
||||
import com.google.flatbuffers.UnionVector;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.ByteOrder;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public final class EnumVal extends Table {
|
||||
public static void ValidateVersion() { Constants.FLATBUFFERS_23_3_3(); }
|
||||
public static EnumVal getRootAsEnumVal(ByteBuffer _bb) { return getRootAsEnumVal(_bb, new EnumVal()); }
|
||||
public static EnumVal getRootAsEnumVal(ByteBuffer _bb, EnumVal obj) { _bb.order(ByteOrder.LITTLE_ENDIAN); return (obj.__assign(_bb.getInt(_bb.position()) + _bb.position(), _bb)); }
|
||||
public void __init(int _i, ByteBuffer _bb) { __reset(_i, _bb); }
|
||||
public EnumVal __assign(int _i, ByteBuffer _bb) { __init(_i, _bb); return this; }
|
||||
|
||||
public String name() { int o = __offset(4); return o != 0 ? __string(o + bb_pos) : null; }
|
||||
public ByteBuffer nameAsByteBuffer() { return __vector_as_bytebuffer(4, 1); }
|
||||
public ByteBuffer nameInByteBuffer(ByteBuffer _bb) { return __vector_in_bytebuffer(_bb, 4, 1); }
|
||||
public long value() { int o = __offset(6); return o != 0 ? bb.getLong(o + bb_pos) : 0L; }
|
||||
public com.google.flatbuffers.reflection.Type unionType() { return unionType(new com.google.flatbuffers.reflection.Type()); }
|
||||
public com.google.flatbuffers.reflection.Type unionType(com.google.flatbuffers.reflection.Type obj) { int o = __offset(10); return o != 0 ? obj.__assign(__indirect(o + bb_pos), bb) : null; }
|
||||
public String documentation(int j) { int o = __offset(12); return o != 0 ? __string(__vector(o) + j * 4) : null; }
|
||||
public int documentationLength() { int o = __offset(12); return o != 0 ? __vector_len(o) : 0; }
|
||||
public StringVector documentationVector() { return documentationVector(new StringVector()); }
|
||||
public StringVector documentationVector(StringVector obj) { int o = __offset(12); return o != 0 ? obj.__assign(__vector(o), 4, bb) : null; }
|
||||
public com.google.flatbuffers.reflection.KeyValue attributes(int j) { return attributes(new com.google.flatbuffers.reflection.KeyValue(), j); }
|
||||
public com.google.flatbuffers.reflection.KeyValue attributes(com.google.flatbuffers.reflection.KeyValue obj, int j) { int o = __offset(14); return o != 0 ? obj.__assign(__indirect(__vector(o) + j * 4), bb) : null; }
|
||||
public int attributesLength() { int o = __offset(14); return o != 0 ? __vector_len(o) : 0; }
|
||||
public com.google.flatbuffers.reflection.KeyValue attributesByKey(String key) { int o = __offset(14); return o != 0 ? com.google.flatbuffers.reflection.KeyValue.__lookup_by_key(null, __vector(o), key, bb) : null; }
|
||||
public com.google.flatbuffers.reflection.KeyValue attributesByKey(com.google.flatbuffers.reflection.KeyValue obj, String key) { int o = __offset(14); return o != 0 ? com.google.flatbuffers.reflection.KeyValue.__lookup_by_key(obj, __vector(o), key, bb) : null; }
|
||||
public com.google.flatbuffers.reflection.KeyValue.Vector attributesVector() { return attributesVector(new com.google.flatbuffers.reflection.KeyValue.Vector()); }
|
||||
public com.google.flatbuffers.reflection.KeyValue.Vector attributesVector(com.google.flatbuffers.reflection.KeyValue.Vector obj) { int o = __offset(14); return o != 0 ? obj.__assign(__vector(o), 4, bb) : null; }
|
||||
|
||||
public static int createEnumVal(FlatBufferBuilder builder,
|
||||
int nameOffset,
|
||||
long value,
|
||||
int unionTypeOffset,
|
||||
int documentationOffset,
|
||||
int attributesOffset) {
|
||||
builder.startTable(6);
|
||||
EnumVal.addValue(builder, value);
|
||||
EnumVal.addAttributes(builder, attributesOffset);
|
||||
EnumVal.addDocumentation(builder, documentationOffset);
|
||||
EnumVal.addUnionType(builder, unionTypeOffset);
|
||||
EnumVal.addName(builder, nameOffset);
|
||||
return EnumVal.endEnumVal(builder);
|
||||
}
|
||||
|
||||
public static void startEnumVal(FlatBufferBuilder builder) { builder.startTable(6); }
|
||||
public static void addName(FlatBufferBuilder builder, int nameOffset) { builder.addOffset(0, nameOffset, 0); }
|
||||
public static void addValue(FlatBufferBuilder builder, long value) { builder.addLong(value); builder.slot(1); }
|
||||
public static void addUnionType(FlatBufferBuilder builder, int unionTypeOffset) { builder.addOffset(3, unionTypeOffset, 0); }
|
||||
public static void addDocumentation(FlatBufferBuilder builder, int documentationOffset) { builder.addOffset(4, documentationOffset, 0); }
|
||||
public static int createDocumentationVector(FlatBufferBuilder builder, int[] data) { builder.startVector(4, data.length, 4); for (int i = data.length - 1; i >= 0; i--) builder.addOffset(data[i]); return builder.endVector(); }
|
||||
public static void startDocumentationVector(FlatBufferBuilder builder, int numElems) { builder.startVector(4, numElems, 4); }
|
||||
public static void addAttributes(FlatBufferBuilder builder, int attributesOffset) { builder.addOffset(5, attributesOffset, 0); }
|
||||
public static int createAttributesVector(FlatBufferBuilder builder, int[] data) { builder.startVector(4, data.length, 4); for (int i = data.length - 1; i >= 0; i--) builder.addOffset(data[i]); return builder.endVector(); }
|
||||
public static void startAttributesVector(FlatBufferBuilder builder, int numElems) { builder.startVector(4, numElems, 4); }
|
||||
public static int endEnumVal(FlatBufferBuilder builder) {
|
||||
int o = builder.endTable();
|
||||
builder.required(o, 4); // name
|
||||
return o;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int keysCompare(Integer o1, Integer o2, ByteBuffer _bb) {
|
||||
long val_1 = _bb.getLong(__offset(6, o1, _bb));
|
||||
long val_2 = _bb.getLong(__offset(6, o2, _bb));
|
||||
return val_1 > val_2 ? 1 : val_1 < val_2 ? -1 : 0;
|
||||
}
|
||||
|
||||
public static EnumVal __lookup_by_key(EnumVal obj, int vectorLocation, long key, ByteBuffer bb) {
|
||||
int span = bb.getInt(vectorLocation - 4);
|
||||
int start = 0;
|
||||
while (span != 0) {
|
||||
int middle = span / 2;
|
||||
int tableOffset = __indirect(vectorLocation + 4 * (start + middle), bb);
|
||||
long val = bb.getLong(__offset(6, bb.capacity() - tableOffset, bb));
|
||||
int comp = val > key ? 1 : val < key ? -1 : 0;
|
||||
if (comp > 0) {
|
||||
span = middle;
|
||||
} else if (comp < 0) {
|
||||
middle++;
|
||||
start += middle;
|
||||
span -= middle;
|
||||
} else {
|
||||
return (obj == null ? new EnumVal() : obj).__assign(tableOffset, bb);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static final class Vector extends BaseVector {
|
||||
public Vector __assign(int _vector, int _element_size, ByteBuffer _bb) { __reset(_vector, _element_size, _bb); return this; }
|
||||
|
||||
public EnumVal get(int j) { return get(new EnumVal(), j); }
|
||||
public EnumVal get(EnumVal obj, int j) { return obj.__assign(__indirect(__element(j), bb), bb); }
|
||||
public EnumVal getByKey(long key) { return __lookup_by_key(null, __vector(), key, bb); }
|
||||
public EnumVal getByKey(EnumVal obj, long key) { return __lookup_by_key(obj, __vector(), key, bb); }
|
||||
}
|
||||
}
|
||||
|
||||
148
java/src/main/java/com/google/flatbuffers/reflection/Field.java
Normal file
148
java/src/main/java/com/google/flatbuffers/reflection/Field.java
Normal file
@@ -0,0 +1,148 @@
|
||||
// automatically generated by the FlatBuffers compiler, do not modify
|
||||
|
||||
package com.google.flatbuffers.reflection;
|
||||
|
||||
import com.google.flatbuffers.BaseVector;
|
||||
import com.google.flatbuffers.BooleanVector;
|
||||
import com.google.flatbuffers.ByteVector;
|
||||
import com.google.flatbuffers.Constants;
|
||||
import com.google.flatbuffers.DoubleVector;
|
||||
import com.google.flatbuffers.FlatBufferBuilder;
|
||||
import com.google.flatbuffers.FloatVector;
|
||||
import com.google.flatbuffers.IntVector;
|
||||
import com.google.flatbuffers.LongVector;
|
||||
import com.google.flatbuffers.ShortVector;
|
||||
import com.google.flatbuffers.StringVector;
|
||||
import com.google.flatbuffers.Struct;
|
||||
import com.google.flatbuffers.Table;
|
||||
import com.google.flatbuffers.UnionVector;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.ByteOrder;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public final class Field extends Table {
|
||||
public static void ValidateVersion() { Constants.FLATBUFFERS_23_3_3(); }
|
||||
public static Field getRootAsField(ByteBuffer _bb) { return getRootAsField(_bb, new Field()); }
|
||||
public static Field getRootAsField(ByteBuffer _bb, Field obj) { _bb.order(ByteOrder.LITTLE_ENDIAN); return (obj.__assign(_bb.getInt(_bb.position()) + _bb.position(), _bb)); }
|
||||
public void __init(int _i, ByteBuffer _bb) { __reset(_i, _bb); }
|
||||
public Field __assign(int _i, ByteBuffer _bb) { __init(_i, _bb); return this; }
|
||||
|
||||
public String name() { int o = __offset(4); return o != 0 ? __string(o + bb_pos) : null; }
|
||||
public ByteBuffer nameAsByteBuffer() { return __vector_as_bytebuffer(4, 1); }
|
||||
public ByteBuffer nameInByteBuffer(ByteBuffer _bb) { return __vector_in_bytebuffer(_bb, 4, 1); }
|
||||
public com.google.flatbuffers.reflection.Type type() { return type(new com.google.flatbuffers.reflection.Type()); }
|
||||
public com.google.flatbuffers.reflection.Type type(com.google.flatbuffers.reflection.Type obj) { int o = __offset(6); return o != 0 ? obj.__assign(__indirect(o + bb_pos), bb) : null; }
|
||||
public int id() { int o = __offset(8); return o != 0 ? bb.getShort(o + bb_pos) & 0xFFFF : 0; }
|
||||
public int offset() { int o = __offset(10); return o != 0 ? bb.getShort(o + bb_pos) & 0xFFFF : 0; }
|
||||
public long defaultInteger() { int o = __offset(12); return o != 0 ? bb.getLong(o + bb_pos) : 0L; }
|
||||
public double defaultReal() { int o = __offset(14); return o != 0 ? bb.getDouble(o + bb_pos) : 0.0; }
|
||||
public boolean deprecated() { int o = __offset(16); return o != 0 ? 0!=bb.get(o + bb_pos) : false; }
|
||||
public boolean required() { int o = __offset(18); return o != 0 ? 0!=bb.get(o + bb_pos) : false; }
|
||||
public boolean key() { int o = __offset(20); return o != 0 ? 0!=bb.get(o + bb_pos) : false; }
|
||||
public com.google.flatbuffers.reflection.KeyValue attributes(int j) { return attributes(new com.google.flatbuffers.reflection.KeyValue(), j); }
|
||||
public com.google.flatbuffers.reflection.KeyValue attributes(com.google.flatbuffers.reflection.KeyValue obj, int j) { int o = __offset(22); return o != 0 ? obj.__assign(__indirect(__vector(o) + j * 4), bb) : null; }
|
||||
public int attributesLength() { int o = __offset(22); return o != 0 ? __vector_len(o) : 0; }
|
||||
public com.google.flatbuffers.reflection.KeyValue attributesByKey(String key) { int o = __offset(22); return o != 0 ? com.google.flatbuffers.reflection.KeyValue.__lookup_by_key(null, __vector(o), key, bb) : null; }
|
||||
public com.google.flatbuffers.reflection.KeyValue attributesByKey(com.google.flatbuffers.reflection.KeyValue obj, String key) { int o = __offset(22); return o != 0 ? com.google.flatbuffers.reflection.KeyValue.__lookup_by_key(obj, __vector(o), key, bb) : null; }
|
||||
public com.google.flatbuffers.reflection.KeyValue.Vector attributesVector() { return attributesVector(new com.google.flatbuffers.reflection.KeyValue.Vector()); }
|
||||
public com.google.flatbuffers.reflection.KeyValue.Vector attributesVector(com.google.flatbuffers.reflection.KeyValue.Vector obj) { int o = __offset(22); return o != 0 ? obj.__assign(__vector(o), 4, bb) : null; }
|
||||
public String documentation(int j) { int o = __offset(24); return o != 0 ? __string(__vector(o) + j * 4) : null; }
|
||||
public int documentationLength() { int o = __offset(24); return o != 0 ? __vector_len(o) : 0; }
|
||||
public StringVector documentationVector() { return documentationVector(new StringVector()); }
|
||||
public StringVector documentationVector(StringVector obj) { int o = __offset(24); return o != 0 ? obj.__assign(__vector(o), 4, bb) : null; }
|
||||
public boolean optional() { int o = __offset(26); return o != 0 ? 0!=bb.get(o + bb_pos) : false; }
|
||||
/**
|
||||
* Number of padding octets to always add after this field. Structs only.
|
||||
*/
|
||||
public int padding() { int o = __offset(28); return o != 0 ? bb.getShort(o + bb_pos) & 0xFFFF : 0; }
|
||||
|
||||
public static int createField(FlatBufferBuilder builder,
|
||||
int nameOffset,
|
||||
int typeOffset,
|
||||
int id,
|
||||
int offset,
|
||||
long defaultInteger,
|
||||
double defaultReal,
|
||||
boolean deprecated,
|
||||
boolean required,
|
||||
boolean key,
|
||||
int attributesOffset,
|
||||
int documentationOffset,
|
||||
boolean optional,
|
||||
int padding) {
|
||||
builder.startTable(13);
|
||||
Field.addDefaultReal(builder, defaultReal);
|
||||
Field.addDefaultInteger(builder, defaultInteger);
|
||||
Field.addDocumentation(builder, documentationOffset);
|
||||
Field.addAttributes(builder, attributesOffset);
|
||||
Field.addType(builder, typeOffset);
|
||||
Field.addName(builder, nameOffset);
|
||||
Field.addPadding(builder, padding);
|
||||
Field.addOffset(builder, offset);
|
||||
Field.addId(builder, id);
|
||||
Field.addOptional(builder, optional);
|
||||
Field.addKey(builder, key);
|
||||
Field.addRequired(builder, required);
|
||||
Field.addDeprecated(builder, deprecated);
|
||||
return Field.endField(builder);
|
||||
}
|
||||
|
||||
public static void startField(FlatBufferBuilder builder) { builder.startTable(13); }
|
||||
public static void addName(FlatBufferBuilder builder, int nameOffset) { builder.addOffset(nameOffset); builder.slot(0); }
|
||||
public static void addType(FlatBufferBuilder builder, int typeOffset) { builder.addOffset(1, typeOffset, 0); }
|
||||
public static void addId(FlatBufferBuilder builder, int id) { builder.addShort(2, (short) id, (short) 0); }
|
||||
public static void addOffset(FlatBufferBuilder builder, int offset) { builder.addShort(3, (short) offset, (short) 0); }
|
||||
public static void addDefaultInteger(FlatBufferBuilder builder, long defaultInteger) { builder.addLong(4, defaultInteger, 0L); }
|
||||
public static void addDefaultReal(FlatBufferBuilder builder, double defaultReal) { builder.addDouble(5, defaultReal, 0.0); }
|
||||
public static void addDeprecated(FlatBufferBuilder builder, boolean deprecated) { builder.addBoolean(6, deprecated, false); }
|
||||
public static void addRequired(FlatBufferBuilder builder, boolean required) { builder.addBoolean(7, required, false); }
|
||||
public static void addKey(FlatBufferBuilder builder, boolean key) { builder.addBoolean(8, key, false); }
|
||||
public static void addAttributes(FlatBufferBuilder builder, int attributesOffset) { builder.addOffset(9, attributesOffset, 0); }
|
||||
public static int createAttributesVector(FlatBufferBuilder builder, int[] data) { builder.startVector(4, data.length, 4); for (int i = data.length - 1; i >= 0; i--) builder.addOffset(data[i]); return builder.endVector(); }
|
||||
public static void startAttributesVector(FlatBufferBuilder builder, int numElems) { builder.startVector(4, numElems, 4); }
|
||||
public static void addDocumentation(FlatBufferBuilder builder, int documentationOffset) { builder.addOffset(10, documentationOffset, 0); }
|
||||
public static int createDocumentationVector(FlatBufferBuilder builder, int[] data) { builder.startVector(4, data.length, 4); for (int i = data.length - 1; i >= 0; i--) builder.addOffset(data[i]); return builder.endVector(); }
|
||||
public static void startDocumentationVector(FlatBufferBuilder builder, int numElems) { builder.startVector(4, numElems, 4); }
|
||||
public static void addOptional(FlatBufferBuilder builder, boolean optional) { builder.addBoolean(11, optional, false); }
|
||||
public static void addPadding(FlatBufferBuilder builder, int padding) { builder.addShort(12, (short) padding, (short) 0); }
|
||||
public static int endField(FlatBufferBuilder builder) {
|
||||
int o = builder.endTable();
|
||||
builder.required(o, 4); // name
|
||||
builder.required(o, 6); // type
|
||||
return o;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int keysCompare(Integer o1, Integer o2, ByteBuffer _bb) { return compareStrings(__offset(4, o1, _bb), __offset(4, o2, _bb), _bb); }
|
||||
|
||||
public static Field __lookup_by_key(Field obj, int vectorLocation, String key, ByteBuffer bb) {
|
||||
byte[] byteKey = key.getBytes(java.nio.charset.StandardCharsets.UTF_8);
|
||||
int span = bb.getInt(vectorLocation - 4);
|
||||
int start = 0;
|
||||
while (span != 0) {
|
||||
int middle = span / 2;
|
||||
int tableOffset = __indirect(vectorLocation + 4 * (start + middle), bb);
|
||||
int comp = compareStrings(__offset(4, bb.capacity() - tableOffset, bb), byteKey, bb);
|
||||
if (comp > 0) {
|
||||
span = middle;
|
||||
} else if (comp < 0) {
|
||||
middle++;
|
||||
start += middle;
|
||||
span -= middle;
|
||||
} else {
|
||||
return (obj == null ? new Field() : obj).__assign(tableOffset, bb);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static final class Vector extends BaseVector {
|
||||
public Vector __assign(int _vector, int _element_size, ByteBuffer _bb) { __reset(_vector, _element_size, _bb); return this; }
|
||||
|
||||
public Field get(int j) { return get(new Field(), j); }
|
||||
public Field get(Field obj, int j) { return obj.__assign(__indirect(__element(j), bb), bb); }
|
||||
public Field getByKey(String key) { return __lookup_by_key(null, __vector(), key, bb); }
|
||||
public Field getByKey(Field obj, String key) { return __lookup_by_key(obj, __vector(), key, bb); }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,88 @@
|
||||
// automatically generated by the FlatBuffers compiler, do not modify
|
||||
|
||||
package com.google.flatbuffers.reflection;
|
||||
|
||||
import com.google.flatbuffers.BaseVector;
|
||||
import com.google.flatbuffers.BooleanVector;
|
||||
import com.google.flatbuffers.ByteVector;
|
||||
import com.google.flatbuffers.Constants;
|
||||
import com.google.flatbuffers.DoubleVector;
|
||||
import com.google.flatbuffers.FlatBufferBuilder;
|
||||
import com.google.flatbuffers.FloatVector;
|
||||
import com.google.flatbuffers.IntVector;
|
||||
import com.google.flatbuffers.LongVector;
|
||||
import com.google.flatbuffers.ShortVector;
|
||||
import com.google.flatbuffers.StringVector;
|
||||
import com.google.flatbuffers.Struct;
|
||||
import com.google.flatbuffers.Table;
|
||||
import com.google.flatbuffers.UnionVector;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.ByteOrder;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public final class KeyValue extends Table {
|
||||
public static void ValidateVersion() { Constants.FLATBUFFERS_23_3_3(); }
|
||||
public static KeyValue getRootAsKeyValue(ByteBuffer _bb) { return getRootAsKeyValue(_bb, new KeyValue()); }
|
||||
public static KeyValue getRootAsKeyValue(ByteBuffer _bb, KeyValue obj) { _bb.order(ByteOrder.LITTLE_ENDIAN); return (obj.__assign(_bb.getInt(_bb.position()) + _bb.position(), _bb)); }
|
||||
public void __init(int _i, ByteBuffer _bb) { __reset(_i, _bb); }
|
||||
public KeyValue __assign(int _i, ByteBuffer _bb) { __init(_i, _bb); return this; }
|
||||
|
||||
public String key() { int o = __offset(4); return o != 0 ? __string(o + bb_pos) : null; }
|
||||
public ByteBuffer keyAsByteBuffer() { return __vector_as_bytebuffer(4, 1); }
|
||||
public ByteBuffer keyInByteBuffer(ByteBuffer _bb) { return __vector_in_bytebuffer(_bb, 4, 1); }
|
||||
public String value() { int o = __offset(6); return o != 0 ? __string(o + bb_pos) : null; }
|
||||
public ByteBuffer valueAsByteBuffer() { return __vector_as_bytebuffer(6, 1); }
|
||||
public ByteBuffer valueInByteBuffer(ByteBuffer _bb) { return __vector_in_bytebuffer(_bb, 6, 1); }
|
||||
|
||||
public static int createKeyValue(FlatBufferBuilder builder,
|
||||
int keyOffset,
|
||||
int valueOffset) {
|
||||
builder.startTable(2);
|
||||
KeyValue.addValue(builder, valueOffset);
|
||||
KeyValue.addKey(builder, keyOffset);
|
||||
return KeyValue.endKeyValue(builder);
|
||||
}
|
||||
|
||||
public static void startKeyValue(FlatBufferBuilder builder) { builder.startTable(2); }
|
||||
public static void addKey(FlatBufferBuilder builder, int keyOffset) { builder.addOffset(keyOffset); builder.slot(0); }
|
||||
public static void addValue(FlatBufferBuilder builder, int valueOffset) { builder.addOffset(1, valueOffset, 0); }
|
||||
public static int endKeyValue(FlatBufferBuilder builder) {
|
||||
int o = builder.endTable();
|
||||
builder.required(o, 4); // key
|
||||
return o;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int keysCompare(Integer o1, Integer o2, ByteBuffer _bb) { return compareStrings(__offset(4, o1, _bb), __offset(4, o2, _bb), _bb); }
|
||||
|
||||
public static KeyValue __lookup_by_key(KeyValue obj, int vectorLocation, String key, ByteBuffer bb) {
|
||||
byte[] byteKey = key.getBytes(java.nio.charset.StandardCharsets.UTF_8);
|
||||
int span = bb.getInt(vectorLocation - 4);
|
||||
int start = 0;
|
||||
while (span != 0) {
|
||||
int middle = span / 2;
|
||||
int tableOffset = __indirect(vectorLocation + 4 * (start + middle), bb);
|
||||
int comp = compareStrings(__offset(4, bb.capacity() - tableOffset, bb), byteKey, bb);
|
||||
if (comp > 0) {
|
||||
span = middle;
|
||||
} else if (comp < 0) {
|
||||
middle++;
|
||||
start += middle;
|
||||
span -= middle;
|
||||
} else {
|
||||
return (obj == null ? new KeyValue() : obj).__assign(tableOffset, bb);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static final class Vector extends BaseVector {
|
||||
public Vector __assign(int _vector, int _element_size, ByteBuffer _bb) { __reset(_vector, _element_size, _bb); return this; }
|
||||
|
||||
public KeyValue get(int j) { return get(new KeyValue(), j); }
|
||||
public KeyValue get(KeyValue obj, int j) { return obj.__assign(__indirect(__element(j), bb), bb); }
|
||||
public KeyValue getByKey(String key) { return __lookup_by_key(null, __vector(), key, bb); }
|
||||
public KeyValue getByKey(KeyValue obj, String key) { return __lookup_by_key(obj, __vector(), key, bb); }
|
||||
}
|
||||
}
|
||||
|
||||
137
java/src/main/java/com/google/flatbuffers/reflection/Object.java
Normal file
137
java/src/main/java/com/google/flatbuffers/reflection/Object.java
Normal file
@@ -0,0 +1,137 @@
|
||||
// automatically generated by the FlatBuffers compiler, do not modify
|
||||
|
||||
package com.google.flatbuffers.reflection;
|
||||
|
||||
import com.google.flatbuffers.BaseVector;
|
||||
import com.google.flatbuffers.BooleanVector;
|
||||
import com.google.flatbuffers.ByteVector;
|
||||
import com.google.flatbuffers.Constants;
|
||||
import com.google.flatbuffers.DoubleVector;
|
||||
import com.google.flatbuffers.FlatBufferBuilder;
|
||||
import com.google.flatbuffers.FloatVector;
|
||||
import com.google.flatbuffers.IntVector;
|
||||
import com.google.flatbuffers.LongVector;
|
||||
import com.google.flatbuffers.ShortVector;
|
||||
import com.google.flatbuffers.StringVector;
|
||||
import com.google.flatbuffers.Struct;
|
||||
import com.google.flatbuffers.Table;
|
||||
import com.google.flatbuffers.UnionVector;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.ByteOrder;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public final class Object extends Table {
|
||||
public static void ValidateVersion() { Constants.FLATBUFFERS_23_3_3(); }
|
||||
public static Object getRootAsObject(ByteBuffer _bb) { return getRootAsObject(_bb, new Object()); }
|
||||
public static Object getRootAsObject(ByteBuffer _bb, Object obj) { _bb.order(ByteOrder.LITTLE_ENDIAN); return (obj.__assign(_bb.getInt(_bb.position()) + _bb.position(), _bb)); }
|
||||
public void __init(int _i, ByteBuffer _bb) { __reset(_i, _bb); }
|
||||
public Object __assign(int _i, ByteBuffer _bb) { __init(_i, _bb); return this; }
|
||||
|
||||
public String name() { int o = __offset(4); return o != 0 ? __string(o + bb_pos) : null; }
|
||||
public ByteBuffer nameAsByteBuffer() { return __vector_as_bytebuffer(4, 1); }
|
||||
public ByteBuffer nameInByteBuffer(ByteBuffer _bb) { return __vector_in_bytebuffer(_bb, 4, 1); }
|
||||
public com.google.flatbuffers.reflection.Field fields(int j) { return fields(new com.google.flatbuffers.reflection.Field(), j); }
|
||||
public com.google.flatbuffers.reflection.Field fields(com.google.flatbuffers.reflection.Field obj, int j) { int o = __offset(6); return o != 0 ? obj.__assign(__indirect(__vector(o) + j * 4), bb) : null; }
|
||||
public int fieldsLength() { int o = __offset(6); return o != 0 ? __vector_len(o) : 0; }
|
||||
public com.google.flatbuffers.reflection.Field fieldsByKey(String key) { int o = __offset(6); return o != 0 ? com.google.flatbuffers.reflection.Field.__lookup_by_key(null, __vector(o), key, bb) : null; }
|
||||
public com.google.flatbuffers.reflection.Field fieldsByKey(com.google.flatbuffers.reflection.Field obj, String key) { int o = __offset(6); return o != 0 ? com.google.flatbuffers.reflection.Field.__lookup_by_key(obj, __vector(o), key, bb) : null; }
|
||||
public com.google.flatbuffers.reflection.Field.Vector fieldsVector() { return fieldsVector(new com.google.flatbuffers.reflection.Field.Vector()); }
|
||||
public com.google.flatbuffers.reflection.Field.Vector fieldsVector(com.google.flatbuffers.reflection.Field.Vector obj) { int o = __offset(6); return o != 0 ? obj.__assign(__vector(o), 4, bb) : null; }
|
||||
public boolean isStruct() { int o = __offset(8); return o != 0 ? 0!=bb.get(o + bb_pos) : false; }
|
||||
public int minalign() { int o = __offset(10); return o != 0 ? bb.getInt(o + bb_pos) : 0; }
|
||||
public int bytesize() { int o = __offset(12); return o != 0 ? bb.getInt(o + bb_pos) : 0; }
|
||||
public com.google.flatbuffers.reflection.KeyValue attributes(int j) { return attributes(new com.google.flatbuffers.reflection.KeyValue(), j); }
|
||||
public com.google.flatbuffers.reflection.KeyValue attributes(com.google.flatbuffers.reflection.KeyValue obj, int j) { int o = __offset(14); return o != 0 ? obj.__assign(__indirect(__vector(o) + j * 4), bb) : null; }
|
||||
public int attributesLength() { int o = __offset(14); return o != 0 ? __vector_len(o) : 0; }
|
||||
public com.google.flatbuffers.reflection.KeyValue attributesByKey(String key) { int o = __offset(14); return o != 0 ? com.google.flatbuffers.reflection.KeyValue.__lookup_by_key(null, __vector(o), key, bb) : null; }
|
||||
public com.google.flatbuffers.reflection.KeyValue attributesByKey(com.google.flatbuffers.reflection.KeyValue obj, String key) { int o = __offset(14); return o != 0 ? com.google.flatbuffers.reflection.KeyValue.__lookup_by_key(obj, __vector(o), key, bb) : null; }
|
||||
public com.google.flatbuffers.reflection.KeyValue.Vector attributesVector() { return attributesVector(new com.google.flatbuffers.reflection.KeyValue.Vector()); }
|
||||
public com.google.flatbuffers.reflection.KeyValue.Vector attributesVector(com.google.flatbuffers.reflection.KeyValue.Vector obj) { int o = __offset(14); return o != 0 ? obj.__assign(__vector(o), 4, bb) : null; }
|
||||
public String documentation(int j) { int o = __offset(16); return o != 0 ? __string(__vector(o) + j * 4) : null; }
|
||||
public int documentationLength() { int o = __offset(16); return o != 0 ? __vector_len(o) : 0; }
|
||||
public StringVector documentationVector() { return documentationVector(new StringVector()); }
|
||||
public StringVector documentationVector(StringVector obj) { int o = __offset(16); return o != 0 ? obj.__assign(__vector(o), 4, bb) : null; }
|
||||
/**
|
||||
* File that this Object is declared in.
|
||||
*/
|
||||
public String declarationFile() { int o = __offset(18); return o != 0 ? __string(o + bb_pos) : null; }
|
||||
public ByteBuffer declarationFileAsByteBuffer() { return __vector_as_bytebuffer(18, 1); }
|
||||
public ByteBuffer declarationFileInByteBuffer(ByteBuffer _bb) { return __vector_in_bytebuffer(_bb, 18, 1); }
|
||||
|
||||
public static int createObject(FlatBufferBuilder builder,
|
||||
int nameOffset,
|
||||
int fieldsOffset,
|
||||
boolean isStruct,
|
||||
int minalign,
|
||||
int bytesize,
|
||||
int attributesOffset,
|
||||
int documentationOffset,
|
||||
int declarationFileOffset) {
|
||||
builder.startTable(8);
|
||||
Object.addDeclarationFile(builder, declarationFileOffset);
|
||||
Object.addDocumentation(builder, documentationOffset);
|
||||
Object.addAttributes(builder, attributesOffset);
|
||||
Object.addBytesize(builder, bytesize);
|
||||
Object.addMinalign(builder, minalign);
|
||||
Object.addFields(builder, fieldsOffset);
|
||||
Object.addName(builder, nameOffset);
|
||||
Object.addIsStruct(builder, isStruct);
|
||||
return Object.endObject(builder);
|
||||
}
|
||||
|
||||
public static void startObject(FlatBufferBuilder builder) { builder.startTable(8); }
|
||||
public static void addName(FlatBufferBuilder builder, int nameOffset) { builder.addOffset(nameOffset); builder.slot(0); }
|
||||
public static void addFields(FlatBufferBuilder builder, int fieldsOffset) { builder.addOffset(1, fieldsOffset, 0); }
|
||||
public static int createFieldsVector(FlatBufferBuilder builder, int[] data) { builder.startVector(4, data.length, 4); for (int i = data.length - 1; i >= 0; i--) builder.addOffset(data[i]); return builder.endVector(); }
|
||||
public static void startFieldsVector(FlatBufferBuilder builder, int numElems) { builder.startVector(4, numElems, 4); }
|
||||
public static void addIsStruct(FlatBufferBuilder builder, boolean isStruct) { builder.addBoolean(2, isStruct, false); }
|
||||
public static void addMinalign(FlatBufferBuilder builder, int minalign) { builder.addInt(3, minalign, 0); }
|
||||
public static void addBytesize(FlatBufferBuilder builder, int bytesize) { builder.addInt(4, bytesize, 0); }
|
||||
public static void addAttributes(FlatBufferBuilder builder, int attributesOffset) { builder.addOffset(5, attributesOffset, 0); }
|
||||
public static int createAttributesVector(FlatBufferBuilder builder, int[] data) { builder.startVector(4, data.length, 4); for (int i = data.length - 1; i >= 0; i--) builder.addOffset(data[i]); return builder.endVector(); }
|
||||
public static void startAttributesVector(FlatBufferBuilder builder, int numElems) { builder.startVector(4, numElems, 4); }
|
||||
public static void addDocumentation(FlatBufferBuilder builder, int documentationOffset) { builder.addOffset(6, documentationOffset, 0); }
|
||||
public static int createDocumentationVector(FlatBufferBuilder builder, int[] data) { builder.startVector(4, data.length, 4); for (int i = data.length - 1; i >= 0; i--) builder.addOffset(data[i]); return builder.endVector(); }
|
||||
public static void startDocumentationVector(FlatBufferBuilder builder, int numElems) { builder.startVector(4, numElems, 4); }
|
||||
public static void addDeclarationFile(FlatBufferBuilder builder, int declarationFileOffset) { builder.addOffset(7, declarationFileOffset, 0); }
|
||||
public static int endObject(FlatBufferBuilder builder) {
|
||||
int o = builder.endTable();
|
||||
builder.required(o, 4); // name
|
||||
builder.required(o, 6); // fields
|
||||
return o;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int keysCompare(Integer o1, Integer o2, ByteBuffer _bb) { return compareStrings(__offset(4, o1, _bb), __offset(4, o2, _bb), _bb); }
|
||||
|
||||
public static Object __lookup_by_key(Object obj, int vectorLocation, String key, ByteBuffer bb) {
|
||||
byte[] byteKey = key.getBytes(java.nio.charset.StandardCharsets.UTF_8);
|
||||
int span = bb.getInt(vectorLocation - 4);
|
||||
int start = 0;
|
||||
while (span != 0) {
|
||||
int middle = span / 2;
|
||||
int tableOffset = __indirect(vectorLocation + 4 * (start + middle), bb);
|
||||
int comp = compareStrings(__offset(4, bb.capacity() - tableOffset, bb), byteKey, bb);
|
||||
if (comp > 0) {
|
||||
span = middle;
|
||||
} else if (comp < 0) {
|
||||
middle++;
|
||||
start += middle;
|
||||
span -= middle;
|
||||
} else {
|
||||
return (obj == null ? new Object() : obj).__assign(tableOffset, bb);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static final class Vector extends BaseVector {
|
||||
public Vector __assign(int _vector, int _element_size, ByteBuffer _bb) { __reset(_vector, _element_size, _bb); return this; }
|
||||
|
||||
public Object get(int j) { return get(new Object(), j); }
|
||||
public Object get(Object obj, int j) { return obj.__assign(__indirect(__element(j), bb), bb); }
|
||||
public Object getByKey(String key) { return __lookup_by_key(null, __vector(), key, bb); }
|
||||
public Object getByKey(Object obj, String key) { return __lookup_by_key(obj, __vector(), key, bb); }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,115 @@
|
||||
// automatically generated by the FlatBuffers compiler, do not modify
|
||||
|
||||
package com.google.flatbuffers.reflection;
|
||||
|
||||
import com.google.flatbuffers.BaseVector;
|
||||
import com.google.flatbuffers.BooleanVector;
|
||||
import com.google.flatbuffers.ByteVector;
|
||||
import com.google.flatbuffers.Constants;
|
||||
import com.google.flatbuffers.DoubleVector;
|
||||
import com.google.flatbuffers.FlatBufferBuilder;
|
||||
import com.google.flatbuffers.FloatVector;
|
||||
import com.google.flatbuffers.IntVector;
|
||||
import com.google.flatbuffers.LongVector;
|
||||
import com.google.flatbuffers.ShortVector;
|
||||
import com.google.flatbuffers.StringVector;
|
||||
import com.google.flatbuffers.Struct;
|
||||
import com.google.flatbuffers.Table;
|
||||
import com.google.flatbuffers.UnionVector;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.ByteOrder;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public final class RPCCall extends Table {
|
||||
public static void ValidateVersion() { Constants.FLATBUFFERS_23_3_3(); }
|
||||
public static RPCCall getRootAsRPCCall(ByteBuffer _bb) { return getRootAsRPCCall(_bb, new RPCCall()); }
|
||||
public static RPCCall getRootAsRPCCall(ByteBuffer _bb, RPCCall obj) { _bb.order(ByteOrder.LITTLE_ENDIAN); return (obj.__assign(_bb.getInt(_bb.position()) + _bb.position(), _bb)); }
|
||||
public void __init(int _i, ByteBuffer _bb) { __reset(_i, _bb); }
|
||||
public RPCCall __assign(int _i, ByteBuffer _bb) { __init(_i, _bb); return this; }
|
||||
|
||||
public String name() { int o = __offset(4); return o != 0 ? __string(o + bb_pos) : null; }
|
||||
public ByteBuffer nameAsByteBuffer() { return __vector_as_bytebuffer(4, 1); }
|
||||
public ByteBuffer nameInByteBuffer(ByteBuffer _bb) { return __vector_in_bytebuffer(_bb, 4, 1); }
|
||||
public com.google.flatbuffers.reflection.Object request() { return request(new com.google.flatbuffers.reflection.Object()); }
|
||||
public com.google.flatbuffers.reflection.Object request(com.google.flatbuffers.reflection.Object obj) { int o = __offset(6); return o != 0 ? obj.__assign(__indirect(o + bb_pos), bb) : null; }
|
||||
public com.google.flatbuffers.reflection.Object response() { return response(new com.google.flatbuffers.reflection.Object()); }
|
||||
public com.google.flatbuffers.reflection.Object response(com.google.flatbuffers.reflection.Object obj) { int o = __offset(8); return o != 0 ? obj.__assign(__indirect(o + bb_pos), bb) : null; }
|
||||
public com.google.flatbuffers.reflection.KeyValue attributes(int j) { return attributes(new com.google.flatbuffers.reflection.KeyValue(), j); }
|
||||
public com.google.flatbuffers.reflection.KeyValue attributes(com.google.flatbuffers.reflection.KeyValue obj, int j) { int o = __offset(10); return o != 0 ? obj.__assign(__indirect(__vector(o) + j * 4), bb) : null; }
|
||||
public int attributesLength() { int o = __offset(10); return o != 0 ? __vector_len(o) : 0; }
|
||||
public com.google.flatbuffers.reflection.KeyValue attributesByKey(String key) { int o = __offset(10); return o != 0 ? com.google.flatbuffers.reflection.KeyValue.__lookup_by_key(null, __vector(o), key, bb) : null; }
|
||||
public com.google.flatbuffers.reflection.KeyValue attributesByKey(com.google.flatbuffers.reflection.KeyValue obj, String key) { int o = __offset(10); return o != 0 ? com.google.flatbuffers.reflection.KeyValue.__lookup_by_key(obj, __vector(o), key, bb) : null; }
|
||||
public com.google.flatbuffers.reflection.KeyValue.Vector attributesVector() { return attributesVector(new com.google.flatbuffers.reflection.KeyValue.Vector()); }
|
||||
public com.google.flatbuffers.reflection.KeyValue.Vector attributesVector(com.google.flatbuffers.reflection.KeyValue.Vector obj) { int o = __offset(10); return o != 0 ? obj.__assign(__vector(o), 4, bb) : null; }
|
||||
public String documentation(int j) { int o = __offset(12); return o != 0 ? __string(__vector(o) + j * 4) : null; }
|
||||
public int documentationLength() { int o = __offset(12); return o != 0 ? __vector_len(o) : 0; }
|
||||
public StringVector documentationVector() { return documentationVector(new StringVector()); }
|
||||
public StringVector documentationVector(StringVector obj) { int o = __offset(12); return o != 0 ? obj.__assign(__vector(o), 4, bb) : null; }
|
||||
|
||||
public static int createRPCCall(FlatBufferBuilder builder,
|
||||
int nameOffset,
|
||||
int requestOffset,
|
||||
int responseOffset,
|
||||
int attributesOffset,
|
||||
int documentationOffset) {
|
||||
builder.startTable(5);
|
||||
RPCCall.addDocumentation(builder, documentationOffset);
|
||||
RPCCall.addAttributes(builder, attributesOffset);
|
||||
RPCCall.addResponse(builder, responseOffset);
|
||||
RPCCall.addRequest(builder, requestOffset);
|
||||
RPCCall.addName(builder, nameOffset);
|
||||
return RPCCall.endRPCCall(builder);
|
||||
}
|
||||
|
||||
public static void startRPCCall(FlatBufferBuilder builder) { builder.startTable(5); }
|
||||
public static void addName(FlatBufferBuilder builder, int nameOffset) { builder.addOffset(nameOffset); builder.slot(0); }
|
||||
public static void addRequest(FlatBufferBuilder builder, int requestOffset) { builder.addOffset(1, requestOffset, 0); }
|
||||
public static void addResponse(FlatBufferBuilder builder, int responseOffset) { builder.addOffset(2, responseOffset, 0); }
|
||||
public static void addAttributes(FlatBufferBuilder builder, int attributesOffset) { builder.addOffset(3, attributesOffset, 0); }
|
||||
public static int createAttributesVector(FlatBufferBuilder builder, int[] data) { builder.startVector(4, data.length, 4); for (int i = data.length - 1; i >= 0; i--) builder.addOffset(data[i]); return builder.endVector(); }
|
||||
public static void startAttributesVector(FlatBufferBuilder builder, int numElems) { builder.startVector(4, numElems, 4); }
|
||||
public static void addDocumentation(FlatBufferBuilder builder, int documentationOffset) { builder.addOffset(4, documentationOffset, 0); }
|
||||
public static int createDocumentationVector(FlatBufferBuilder builder, int[] data) { builder.startVector(4, data.length, 4); for (int i = data.length - 1; i >= 0; i--) builder.addOffset(data[i]); return builder.endVector(); }
|
||||
public static void startDocumentationVector(FlatBufferBuilder builder, int numElems) { builder.startVector(4, numElems, 4); }
|
||||
public static int endRPCCall(FlatBufferBuilder builder) {
|
||||
int o = builder.endTable();
|
||||
builder.required(o, 4); // name
|
||||
builder.required(o, 6); // request
|
||||
builder.required(o, 8); // response
|
||||
return o;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int keysCompare(Integer o1, Integer o2, ByteBuffer _bb) { return compareStrings(__offset(4, o1, _bb), __offset(4, o2, _bb), _bb); }
|
||||
|
||||
public static RPCCall __lookup_by_key(RPCCall obj, int vectorLocation, String key, ByteBuffer bb) {
|
||||
byte[] byteKey = key.getBytes(java.nio.charset.StandardCharsets.UTF_8);
|
||||
int span = bb.getInt(vectorLocation - 4);
|
||||
int start = 0;
|
||||
while (span != 0) {
|
||||
int middle = span / 2;
|
||||
int tableOffset = __indirect(vectorLocation + 4 * (start + middle), bb);
|
||||
int comp = compareStrings(__offset(4, bb.capacity() - tableOffset, bb), byteKey, bb);
|
||||
if (comp > 0) {
|
||||
span = middle;
|
||||
} else if (comp < 0) {
|
||||
middle++;
|
||||
start += middle;
|
||||
span -= middle;
|
||||
} else {
|
||||
return (obj == null ? new RPCCall() : obj).__assign(tableOffset, bb);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static final class Vector extends BaseVector {
|
||||
public Vector __assign(int _vector, int _element_size, ByteBuffer _bb) { __reset(_vector, _element_size, _bb); return this; }
|
||||
|
||||
public RPCCall get(int j) { return get(new RPCCall(), j); }
|
||||
public RPCCall get(RPCCall obj, int j) { return obj.__assign(__indirect(__element(j), bb), bb); }
|
||||
public RPCCall getByKey(String key) { return __lookup_by_key(null, __vector(), key, bb); }
|
||||
public RPCCall getByKey(RPCCall obj, String key) { return __lookup_by_key(obj, __vector(), key, bb); }
|
||||
}
|
||||
}
|
||||
|
||||
127
java/src/main/java/com/google/flatbuffers/reflection/Schema.java
Normal file
127
java/src/main/java/com/google/flatbuffers/reflection/Schema.java
Normal file
@@ -0,0 +1,127 @@
|
||||
// automatically generated by the FlatBuffers compiler, do not modify
|
||||
|
||||
package com.google.flatbuffers.reflection;
|
||||
|
||||
import com.google.flatbuffers.BaseVector;
|
||||
import com.google.flatbuffers.BooleanVector;
|
||||
import com.google.flatbuffers.ByteVector;
|
||||
import com.google.flatbuffers.Constants;
|
||||
import com.google.flatbuffers.DoubleVector;
|
||||
import com.google.flatbuffers.FlatBufferBuilder;
|
||||
import com.google.flatbuffers.FloatVector;
|
||||
import com.google.flatbuffers.IntVector;
|
||||
import com.google.flatbuffers.LongVector;
|
||||
import com.google.flatbuffers.ShortVector;
|
||||
import com.google.flatbuffers.StringVector;
|
||||
import com.google.flatbuffers.Struct;
|
||||
import com.google.flatbuffers.Table;
|
||||
import com.google.flatbuffers.UnionVector;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.ByteOrder;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public final class Schema extends Table {
|
||||
public static void ValidateVersion() { Constants.FLATBUFFERS_23_3_3(); }
|
||||
public static Schema getRootAsSchema(ByteBuffer _bb) { return getRootAsSchema(_bb, new Schema()); }
|
||||
public static Schema getRootAsSchema(ByteBuffer _bb, Schema obj) { _bb.order(ByteOrder.LITTLE_ENDIAN); return (obj.__assign(_bb.getInt(_bb.position()) + _bb.position(), _bb)); }
|
||||
public static boolean SchemaBufferHasIdentifier(ByteBuffer _bb) { return __has_identifier(_bb, "BFBS"); }
|
||||
public void __init(int _i, ByteBuffer _bb) { __reset(_i, _bb); }
|
||||
public Schema __assign(int _i, ByteBuffer _bb) { __init(_i, _bb); return this; }
|
||||
|
||||
public com.google.flatbuffers.reflection.Object objects(int j) { return objects(new com.google.flatbuffers.reflection.Object(), j); }
|
||||
public com.google.flatbuffers.reflection.Object objects(com.google.flatbuffers.reflection.Object obj, int j) { int o = __offset(4); return o != 0 ? obj.__assign(__indirect(__vector(o) + j * 4), bb) : null; }
|
||||
public int objectsLength() { int o = __offset(4); return o != 0 ? __vector_len(o) : 0; }
|
||||
public com.google.flatbuffers.reflection.Object objectsByKey(String key) { int o = __offset(4); return o != 0 ? com.google.flatbuffers.reflection.Object.__lookup_by_key(null, __vector(o), key, bb) : null; }
|
||||
public com.google.flatbuffers.reflection.Object objectsByKey(com.google.flatbuffers.reflection.Object obj, String key) { int o = __offset(4); return o != 0 ? com.google.flatbuffers.reflection.Object.__lookup_by_key(obj, __vector(o), key, bb) : null; }
|
||||
public com.google.flatbuffers.reflection.Object.Vector objectsVector() { return objectsVector(new com.google.flatbuffers.reflection.Object.Vector()); }
|
||||
public com.google.flatbuffers.reflection.Object.Vector objectsVector(com.google.flatbuffers.reflection.Object.Vector obj) { int o = __offset(4); return o != 0 ? obj.__assign(__vector(o), 4, bb) : null; }
|
||||
public com.google.flatbuffers.reflection.Enum enums(int j) { return enums(new com.google.flatbuffers.reflection.Enum(), j); }
|
||||
public com.google.flatbuffers.reflection.Enum enums(com.google.flatbuffers.reflection.Enum obj, int j) { int o = __offset(6); return o != 0 ? obj.__assign(__indirect(__vector(o) + j * 4), bb) : null; }
|
||||
public int enumsLength() { int o = __offset(6); return o != 0 ? __vector_len(o) : 0; }
|
||||
public com.google.flatbuffers.reflection.Enum enumsByKey(String key) { int o = __offset(6); return o != 0 ? com.google.flatbuffers.reflection.Enum.__lookup_by_key(null, __vector(o), key, bb) : null; }
|
||||
public com.google.flatbuffers.reflection.Enum enumsByKey(com.google.flatbuffers.reflection.Enum obj, String key) { int o = __offset(6); return o != 0 ? com.google.flatbuffers.reflection.Enum.__lookup_by_key(obj, __vector(o), key, bb) : null; }
|
||||
public com.google.flatbuffers.reflection.Enum.Vector enumsVector() { return enumsVector(new com.google.flatbuffers.reflection.Enum.Vector()); }
|
||||
public com.google.flatbuffers.reflection.Enum.Vector enumsVector(com.google.flatbuffers.reflection.Enum.Vector obj) { int o = __offset(6); return o != 0 ? obj.__assign(__vector(o), 4, bb) : null; }
|
||||
public String fileIdent() { int o = __offset(8); return o != 0 ? __string(o + bb_pos) : null; }
|
||||
public ByteBuffer fileIdentAsByteBuffer() { return __vector_as_bytebuffer(8, 1); }
|
||||
public ByteBuffer fileIdentInByteBuffer(ByteBuffer _bb) { return __vector_in_bytebuffer(_bb, 8, 1); }
|
||||
public String fileExt() { int o = __offset(10); return o != 0 ? __string(o + bb_pos) : null; }
|
||||
public ByteBuffer fileExtAsByteBuffer() { return __vector_as_bytebuffer(10, 1); }
|
||||
public ByteBuffer fileExtInByteBuffer(ByteBuffer _bb) { return __vector_in_bytebuffer(_bb, 10, 1); }
|
||||
public com.google.flatbuffers.reflection.Object rootTable() { return rootTable(new com.google.flatbuffers.reflection.Object()); }
|
||||
public com.google.flatbuffers.reflection.Object rootTable(com.google.flatbuffers.reflection.Object obj) { int o = __offset(12); return o != 0 ? obj.__assign(__indirect(o + bb_pos), bb) : null; }
|
||||
public com.google.flatbuffers.reflection.Service services(int j) { return services(new com.google.flatbuffers.reflection.Service(), j); }
|
||||
public com.google.flatbuffers.reflection.Service services(com.google.flatbuffers.reflection.Service obj, int j) { int o = __offset(14); return o != 0 ? obj.__assign(__indirect(__vector(o) + j * 4), bb) : null; }
|
||||
public int servicesLength() { int o = __offset(14); return o != 0 ? __vector_len(o) : 0; }
|
||||
public com.google.flatbuffers.reflection.Service servicesByKey(String key) { int o = __offset(14); return o != 0 ? com.google.flatbuffers.reflection.Service.__lookup_by_key(null, __vector(o), key, bb) : null; }
|
||||
public com.google.flatbuffers.reflection.Service servicesByKey(com.google.flatbuffers.reflection.Service obj, String key) { int o = __offset(14); return o != 0 ? com.google.flatbuffers.reflection.Service.__lookup_by_key(obj, __vector(o), key, bb) : null; }
|
||||
public com.google.flatbuffers.reflection.Service.Vector servicesVector() { return servicesVector(new com.google.flatbuffers.reflection.Service.Vector()); }
|
||||
public com.google.flatbuffers.reflection.Service.Vector servicesVector(com.google.flatbuffers.reflection.Service.Vector obj) { int o = __offset(14); return o != 0 ? obj.__assign(__vector(o), 4, bb) : null; }
|
||||
public long advancedFeatures() { int o = __offset(16); return o != 0 ? bb.getLong(o + bb_pos) : 0L; }
|
||||
/**
|
||||
* All the files used in this compilation. Files are relative to where
|
||||
* flatc was invoked.
|
||||
*/
|
||||
public com.google.flatbuffers.reflection.SchemaFile fbsFiles(int j) { return fbsFiles(new com.google.flatbuffers.reflection.SchemaFile(), j); }
|
||||
public com.google.flatbuffers.reflection.SchemaFile fbsFiles(com.google.flatbuffers.reflection.SchemaFile obj, int j) { int o = __offset(18); return o != 0 ? obj.__assign(__indirect(__vector(o) + j * 4), bb) : null; }
|
||||
public int fbsFilesLength() { int o = __offset(18); return o != 0 ? __vector_len(o) : 0; }
|
||||
public com.google.flatbuffers.reflection.SchemaFile fbsFilesByKey(String key) { int o = __offset(18); return o != 0 ? com.google.flatbuffers.reflection.SchemaFile.__lookup_by_key(null, __vector(o), key, bb) : null; }
|
||||
public com.google.flatbuffers.reflection.SchemaFile fbsFilesByKey(com.google.flatbuffers.reflection.SchemaFile obj, String key) { int o = __offset(18); return o != 0 ? com.google.flatbuffers.reflection.SchemaFile.__lookup_by_key(obj, __vector(o), key, bb) : null; }
|
||||
public com.google.flatbuffers.reflection.SchemaFile.Vector fbsFilesVector() { return fbsFilesVector(new com.google.flatbuffers.reflection.SchemaFile.Vector()); }
|
||||
public com.google.flatbuffers.reflection.SchemaFile.Vector fbsFilesVector(com.google.flatbuffers.reflection.SchemaFile.Vector obj) { int o = __offset(18); return o != 0 ? obj.__assign(__vector(o), 4, bb) : null; }
|
||||
|
||||
public static int createSchema(FlatBufferBuilder builder,
|
||||
int objectsOffset,
|
||||
int enumsOffset,
|
||||
int fileIdentOffset,
|
||||
int fileExtOffset,
|
||||
int rootTableOffset,
|
||||
int servicesOffset,
|
||||
long advancedFeatures,
|
||||
int fbsFilesOffset) {
|
||||
builder.startTable(8);
|
||||
Schema.addAdvancedFeatures(builder, advancedFeatures);
|
||||
Schema.addFbsFiles(builder, fbsFilesOffset);
|
||||
Schema.addServices(builder, servicesOffset);
|
||||
Schema.addRootTable(builder, rootTableOffset);
|
||||
Schema.addFileExt(builder, fileExtOffset);
|
||||
Schema.addFileIdent(builder, fileIdentOffset);
|
||||
Schema.addEnums(builder, enumsOffset);
|
||||
Schema.addObjects(builder, objectsOffset);
|
||||
return Schema.endSchema(builder);
|
||||
}
|
||||
|
||||
public static void startSchema(FlatBufferBuilder builder) { builder.startTable(8); }
|
||||
public static void addObjects(FlatBufferBuilder builder, int objectsOffset) { builder.addOffset(0, objectsOffset, 0); }
|
||||
public static int createObjectsVector(FlatBufferBuilder builder, int[] data) { builder.startVector(4, data.length, 4); for (int i = data.length - 1; i >= 0; i--) builder.addOffset(data[i]); return builder.endVector(); }
|
||||
public static void startObjectsVector(FlatBufferBuilder builder, int numElems) { builder.startVector(4, numElems, 4); }
|
||||
public static void addEnums(FlatBufferBuilder builder, int enumsOffset) { builder.addOffset(1, enumsOffset, 0); }
|
||||
public static int createEnumsVector(FlatBufferBuilder builder, int[] data) { builder.startVector(4, data.length, 4); for (int i = data.length - 1; i >= 0; i--) builder.addOffset(data[i]); return builder.endVector(); }
|
||||
public static void startEnumsVector(FlatBufferBuilder builder, int numElems) { builder.startVector(4, numElems, 4); }
|
||||
public static void addFileIdent(FlatBufferBuilder builder, int fileIdentOffset) { builder.addOffset(2, fileIdentOffset, 0); }
|
||||
public static void addFileExt(FlatBufferBuilder builder, int fileExtOffset) { builder.addOffset(3, fileExtOffset, 0); }
|
||||
public static void addRootTable(FlatBufferBuilder builder, int rootTableOffset) { builder.addOffset(4, rootTableOffset, 0); }
|
||||
public static void addServices(FlatBufferBuilder builder, int servicesOffset) { builder.addOffset(5, servicesOffset, 0); }
|
||||
public static int createServicesVector(FlatBufferBuilder builder, int[] data) { builder.startVector(4, data.length, 4); for (int i = data.length - 1; i >= 0; i--) builder.addOffset(data[i]); return builder.endVector(); }
|
||||
public static void startServicesVector(FlatBufferBuilder builder, int numElems) { builder.startVector(4, numElems, 4); }
|
||||
public static void addAdvancedFeatures(FlatBufferBuilder builder, long advancedFeatures) { builder.addLong(6, advancedFeatures, 0L); }
|
||||
public static void addFbsFiles(FlatBufferBuilder builder, int fbsFilesOffset) { builder.addOffset(7, fbsFilesOffset, 0); }
|
||||
public static int createFbsFilesVector(FlatBufferBuilder builder, int[] data) { builder.startVector(4, data.length, 4); for (int i = data.length - 1; i >= 0; i--) builder.addOffset(data[i]); return builder.endVector(); }
|
||||
public static void startFbsFilesVector(FlatBufferBuilder builder, int numElems) { builder.startVector(4, numElems, 4); }
|
||||
public static int endSchema(FlatBufferBuilder builder) {
|
||||
int o = builder.endTable();
|
||||
builder.required(o, 4); // objects
|
||||
builder.required(o, 6); // enums
|
||||
return o;
|
||||
}
|
||||
public static void finishSchemaBuffer(FlatBufferBuilder builder, int offset) { builder.finish(offset, "BFBS"); }
|
||||
public static void finishSizePrefixedSchemaBuffer(FlatBufferBuilder builder, int offset) { builder.finishSizePrefixed(offset, "BFBS"); }
|
||||
|
||||
public static final class Vector extends BaseVector {
|
||||
public Vector __assign(int _vector, int _element_size, ByteBuffer _bb) { __reset(_vector, _element_size, _bb); return this; }
|
||||
|
||||
public Schema get(int j) { return get(new Schema(), j); }
|
||||
public Schema get(Schema obj, int j) { return obj.__assign(__indirect(__element(j), bb), bb); }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,102 @@
|
||||
// automatically generated by the FlatBuffers compiler, do not modify
|
||||
|
||||
package com.google.flatbuffers.reflection;
|
||||
|
||||
import com.google.flatbuffers.BaseVector;
|
||||
import com.google.flatbuffers.BooleanVector;
|
||||
import com.google.flatbuffers.ByteVector;
|
||||
import com.google.flatbuffers.Constants;
|
||||
import com.google.flatbuffers.DoubleVector;
|
||||
import com.google.flatbuffers.FlatBufferBuilder;
|
||||
import com.google.flatbuffers.FloatVector;
|
||||
import com.google.flatbuffers.IntVector;
|
||||
import com.google.flatbuffers.LongVector;
|
||||
import com.google.flatbuffers.ShortVector;
|
||||
import com.google.flatbuffers.StringVector;
|
||||
import com.google.flatbuffers.Struct;
|
||||
import com.google.flatbuffers.Table;
|
||||
import com.google.flatbuffers.UnionVector;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.ByteOrder;
|
||||
|
||||
/**
|
||||
* File specific information.
|
||||
* Symbols declared within a file may be recovered by iterating over all
|
||||
* symbols and examining the `declaration_file` field.
|
||||
*/
|
||||
@SuppressWarnings("unused")
|
||||
public final class SchemaFile extends Table {
|
||||
public static void ValidateVersion() { Constants.FLATBUFFERS_23_3_3(); }
|
||||
public static SchemaFile getRootAsSchemaFile(ByteBuffer _bb) { return getRootAsSchemaFile(_bb, new SchemaFile()); }
|
||||
public static SchemaFile getRootAsSchemaFile(ByteBuffer _bb, SchemaFile obj) { _bb.order(ByteOrder.LITTLE_ENDIAN); return (obj.__assign(_bb.getInt(_bb.position()) + _bb.position(), _bb)); }
|
||||
public void __init(int _i, ByteBuffer _bb) { __reset(_i, _bb); }
|
||||
public SchemaFile __assign(int _i, ByteBuffer _bb) { __init(_i, _bb); return this; }
|
||||
|
||||
/**
|
||||
* Filename, relative to project root.
|
||||
*/
|
||||
public String filename() { int o = __offset(4); return o != 0 ? __string(o + bb_pos) : null; }
|
||||
public ByteBuffer filenameAsByteBuffer() { return __vector_as_bytebuffer(4, 1); }
|
||||
public ByteBuffer filenameInByteBuffer(ByteBuffer _bb) { return __vector_in_bytebuffer(_bb, 4, 1); }
|
||||
/**
|
||||
* Names of included files, relative to project root.
|
||||
*/
|
||||
public String includedFilenames(int j) { int o = __offset(6); return o != 0 ? __string(__vector(o) + j * 4) : null; }
|
||||
public int includedFilenamesLength() { int o = __offset(6); return o != 0 ? __vector_len(o) : 0; }
|
||||
public StringVector includedFilenamesVector() { return includedFilenamesVector(new StringVector()); }
|
||||
public StringVector includedFilenamesVector(StringVector obj) { int o = __offset(6); return o != 0 ? obj.__assign(__vector(o), 4, bb) : null; }
|
||||
|
||||
public static int createSchemaFile(FlatBufferBuilder builder,
|
||||
int filenameOffset,
|
||||
int includedFilenamesOffset) {
|
||||
builder.startTable(2);
|
||||
SchemaFile.addIncludedFilenames(builder, includedFilenamesOffset);
|
||||
SchemaFile.addFilename(builder, filenameOffset);
|
||||
return SchemaFile.endSchemaFile(builder);
|
||||
}
|
||||
|
||||
public static void startSchemaFile(FlatBufferBuilder builder) { builder.startTable(2); }
|
||||
public static void addFilename(FlatBufferBuilder builder, int filenameOffset) { builder.addOffset(filenameOffset); builder.slot(0); }
|
||||
public static void addIncludedFilenames(FlatBufferBuilder builder, int includedFilenamesOffset) { builder.addOffset(1, includedFilenamesOffset, 0); }
|
||||
public static int createIncludedFilenamesVector(FlatBufferBuilder builder, int[] data) { builder.startVector(4, data.length, 4); for (int i = data.length - 1; i >= 0; i--) builder.addOffset(data[i]); return builder.endVector(); }
|
||||
public static void startIncludedFilenamesVector(FlatBufferBuilder builder, int numElems) { builder.startVector(4, numElems, 4); }
|
||||
public static int endSchemaFile(FlatBufferBuilder builder) {
|
||||
int o = builder.endTable();
|
||||
builder.required(o, 4); // filename
|
||||
return o;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int keysCompare(Integer o1, Integer o2, ByteBuffer _bb) { return compareStrings(__offset(4, o1, _bb), __offset(4, o2, _bb), _bb); }
|
||||
|
||||
public static SchemaFile __lookup_by_key(SchemaFile obj, int vectorLocation, String key, ByteBuffer bb) {
|
||||
byte[] byteKey = key.getBytes(java.nio.charset.StandardCharsets.UTF_8);
|
||||
int span = bb.getInt(vectorLocation - 4);
|
||||
int start = 0;
|
||||
while (span != 0) {
|
||||
int middle = span / 2;
|
||||
int tableOffset = __indirect(vectorLocation + 4 * (start + middle), bb);
|
||||
int comp = compareStrings(__offset(4, bb.capacity() - tableOffset, bb), byteKey, bb);
|
||||
if (comp > 0) {
|
||||
span = middle;
|
||||
} else if (comp < 0) {
|
||||
middle++;
|
||||
start += middle;
|
||||
span -= middle;
|
||||
} else {
|
||||
return (obj == null ? new SchemaFile() : obj).__assign(tableOffset, bb);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static final class Vector extends BaseVector {
|
||||
public Vector __assign(int _vector, int _element_size, ByteBuffer _bb) { __reset(_vector, _element_size, _bb); return this; }
|
||||
|
||||
public SchemaFile get(int j) { return get(new SchemaFile(), j); }
|
||||
public SchemaFile get(SchemaFile obj, int j) { return obj.__assign(__indirect(__element(j), bb), bb); }
|
||||
public SchemaFile getByKey(String key) { return __lookup_by_key(null, __vector(), key, bb); }
|
||||
public SchemaFile getByKey(SchemaFile obj, String key) { return __lookup_by_key(obj, __vector(), key, bb); }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,124 @@
|
||||
// automatically generated by the FlatBuffers compiler, do not modify
|
||||
|
||||
package com.google.flatbuffers.reflection;
|
||||
|
||||
import com.google.flatbuffers.BaseVector;
|
||||
import com.google.flatbuffers.BooleanVector;
|
||||
import com.google.flatbuffers.ByteVector;
|
||||
import com.google.flatbuffers.Constants;
|
||||
import com.google.flatbuffers.DoubleVector;
|
||||
import com.google.flatbuffers.FlatBufferBuilder;
|
||||
import com.google.flatbuffers.FloatVector;
|
||||
import com.google.flatbuffers.IntVector;
|
||||
import com.google.flatbuffers.LongVector;
|
||||
import com.google.flatbuffers.ShortVector;
|
||||
import com.google.flatbuffers.StringVector;
|
||||
import com.google.flatbuffers.Struct;
|
||||
import com.google.flatbuffers.Table;
|
||||
import com.google.flatbuffers.UnionVector;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.ByteOrder;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public final class Service extends Table {
|
||||
public static void ValidateVersion() { Constants.FLATBUFFERS_23_3_3(); }
|
||||
public static Service getRootAsService(ByteBuffer _bb) { return getRootAsService(_bb, new Service()); }
|
||||
public static Service getRootAsService(ByteBuffer _bb, Service obj) { _bb.order(ByteOrder.LITTLE_ENDIAN); return (obj.__assign(_bb.getInt(_bb.position()) + _bb.position(), _bb)); }
|
||||
public void __init(int _i, ByteBuffer _bb) { __reset(_i, _bb); }
|
||||
public Service __assign(int _i, ByteBuffer _bb) { __init(_i, _bb); return this; }
|
||||
|
||||
public String name() { int o = __offset(4); return o != 0 ? __string(o + bb_pos) : null; }
|
||||
public ByteBuffer nameAsByteBuffer() { return __vector_as_bytebuffer(4, 1); }
|
||||
public ByteBuffer nameInByteBuffer(ByteBuffer _bb) { return __vector_in_bytebuffer(_bb, 4, 1); }
|
||||
public com.google.flatbuffers.reflection.RPCCall calls(int j) { return calls(new com.google.flatbuffers.reflection.RPCCall(), j); }
|
||||
public com.google.flatbuffers.reflection.RPCCall calls(com.google.flatbuffers.reflection.RPCCall obj, int j) { int o = __offset(6); return o != 0 ? obj.__assign(__indirect(__vector(o) + j * 4), bb) : null; }
|
||||
public int callsLength() { int o = __offset(6); return o != 0 ? __vector_len(o) : 0; }
|
||||
public com.google.flatbuffers.reflection.RPCCall callsByKey(String key) { int o = __offset(6); return o != 0 ? com.google.flatbuffers.reflection.RPCCall.__lookup_by_key(null, __vector(o), key, bb) : null; }
|
||||
public com.google.flatbuffers.reflection.RPCCall callsByKey(com.google.flatbuffers.reflection.RPCCall obj, String key) { int o = __offset(6); return o != 0 ? com.google.flatbuffers.reflection.RPCCall.__lookup_by_key(obj, __vector(o), key, bb) : null; }
|
||||
public com.google.flatbuffers.reflection.RPCCall.Vector callsVector() { return callsVector(new com.google.flatbuffers.reflection.RPCCall.Vector()); }
|
||||
public com.google.flatbuffers.reflection.RPCCall.Vector callsVector(com.google.flatbuffers.reflection.RPCCall.Vector obj) { int o = __offset(6); return o != 0 ? obj.__assign(__vector(o), 4, bb) : null; }
|
||||
public com.google.flatbuffers.reflection.KeyValue attributes(int j) { return attributes(new com.google.flatbuffers.reflection.KeyValue(), j); }
|
||||
public com.google.flatbuffers.reflection.KeyValue attributes(com.google.flatbuffers.reflection.KeyValue obj, int j) { int o = __offset(8); return o != 0 ? obj.__assign(__indirect(__vector(o) + j * 4), bb) : null; }
|
||||
public int attributesLength() { int o = __offset(8); return o != 0 ? __vector_len(o) : 0; }
|
||||
public com.google.flatbuffers.reflection.KeyValue attributesByKey(String key) { int o = __offset(8); return o != 0 ? com.google.flatbuffers.reflection.KeyValue.__lookup_by_key(null, __vector(o), key, bb) : null; }
|
||||
public com.google.flatbuffers.reflection.KeyValue attributesByKey(com.google.flatbuffers.reflection.KeyValue obj, String key) { int o = __offset(8); return o != 0 ? com.google.flatbuffers.reflection.KeyValue.__lookup_by_key(obj, __vector(o), key, bb) : null; }
|
||||
public com.google.flatbuffers.reflection.KeyValue.Vector attributesVector() { return attributesVector(new com.google.flatbuffers.reflection.KeyValue.Vector()); }
|
||||
public com.google.flatbuffers.reflection.KeyValue.Vector attributesVector(com.google.flatbuffers.reflection.KeyValue.Vector obj) { int o = __offset(8); return o != 0 ? obj.__assign(__vector(o), 4, bb) : null; }
|
||||
public String documentation(int j) { int o = __offset(10); return o != 0 ? __string(__vector(o) + j * 4) : null; }
|
||||
public int documentationLength() { int o = __offset(10); return o != 0 ? __vector_len(o) : 0; }
|
||||
public StringVector documentationVector() { return documentationVector(new StringVector()); }
|
||||
public StringVector documentationVector(StringVector obj) { int o = __offset(10); return o != 0 ? obj.__assign(__vector(o), 4, bb) : null; }
|
||||
/**
|
||||
* File that this Service is declared in.
|
||||
*/
|
||||
public String declarationFile() { int o = __offset(12); return o != 0 ? __string(o + bb_pos) : null; }
|
||||
public ByteBuffer declarationFileAsByteBuffer() { return __vector_as_bytebuffer(12, 1); }
|
||||
public ByteBuffer declarationFileInByteBuffer(ByteBuffer _bb) { return __vector_in_bytebuffer(_bb, 12, 1); }
|
||||
|
||||
public static int createService(FlatBufferBuilder builder,
|
||||
int nameOffset,
|
||||
int callsOffset,
|
||||
int attributesOffset,
|
||||
int documentationOffset,
|
||||
int declarationFileOffset) {
|
||||
builder.startTable(5);
|
||||
Service.addDeclarationFile(builder, declarationFileOffset);
|
||||
Service.addDocumentation(builder, documentationOffset);
|
||||
Service.addAttributes(builder, attributesOffset);
|
||||
Service.addCalls(builder, callsOffset);
|
||||
Service.addName(builder, nameOffset);
|
||||
return Service.endService(builder);
|
||||
}
|
||||
|
||||
public static void startService(FlatBufferBuilder builder) { builder.startTable(5); }
|
||||
public static void addName(FlatBufferBuilder builder, int nameOffset) { builder.addOffset(nameOffset); builder.slot(0); }
|
||||
public static void addCalls(FlatBufferBuilder builder, int callsOffset) { builder.addOffset(1, callsOffset, 0); }
|
||||
public static int createCallsVector(FlatBufferBuilder builder, int[] data) { builder.startVector(4, data.length, 4); for (int i = data.length - 1; i >= 0; i--) builder.addOffset(data[i]); return builder.endVector(); }
|
||||
public static void startCallsVector(FlatBufferBuilder builder, int numElems) { builder.startVector(4, numElems, 4); }
|
||||
public static void addAttributes(FlatBufferBuilder builder, int attributesOffset) { builder.addOffset(2, attributesOffset, 0); }
|
||||
public static int createAttributesVector(FlatBufferBuilder builder, int[] data) { builder.startVector(4, data.length, 4); for (int i = data.length - 1; i >= 0; i--) builder.addOffset(data[i]); return builder.endVector(); }
|
||||
public static void startAttributesVector(FlatBufferBuilder builder, int numElems) { builder.startVector(4, numElems, 4); }
|
||||
public static void addDocumentation(FlatBufferBuilder builder, int documentationOffset) { builder.addOffset(3, documentationOffset, 0); }
|
||||
public static int createDocumentationVector(FlatBufferBuilder builder, int[] data) { builder.startVector(4, data.length, 4); for (int i = data.length - 1; i >= 0; i--) builder.addOffset(data[i]); return builder.endVector(); }
|
||||
public static void startDocumentationVector(FlatBufferBuilder builder, int numElems) { builder.startVector(4, numElems, 4); }
|
||||
public static void addDeclarationFile(FlatBufferBuilder builder, int declarationFileOffset) { builder.addOffset(4, declarationFileOffset, 0); }
|
||||
public static int endService(FlatBufferBuilder builder) {
|
||||
int o = builder.endTable();
|
||||
builder.required(o, 4); // name
|
||||
return o;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int keysCompare(Integer o1, Integer o2, ByteBuffer _bb) { return compareStrings(__offset(4, o1, _bb), __offset(4, o2, _bb), _bb); }
|
||||
|
||||
public static Service __lookup_by_key(Service obj, int vectorLocation, String key, ByteBuffer bb) {
|
||||
byte[] byteKey = key.getBytes(java.nio.charset.StandardCharsets.UTF_8);
|
||||
int span = bb.getInt(vectorLocation - 4);
|
||||
int start = 0;
|
||||
while (span != 0) {
|
||||
int middle = span / 2;
|
||||
int tableOffset = __indirect(vectorLocation + 4 * (start + middle), bb);
|
||||
int comp = compareStrings(__offset(4, bb.capacity() - tableOffset, bb), byteKey, bb);
|
||||
if (comp > 0) {
|
||||
span = middle;
|
||||
} else if (comp < 0) {
|
||||
middle++;
|
||||
start += middle;
|
||||
span -= middle;
|
||||
} else {
|
||||
return (obj == null ? new Service() : obj).__assign(tableOffset, bb);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static final class Vector extends BaseVector {
|
||||
public Vector __assign(int _vector, int _element_size, ByteBuffer _bb) { __reset(_vector, _element_size, _bb); return this; }
|
||||
|
||||
public Service get(int j) { return get(new Service(), j); }
|
||||
public Service get(Service obj, int j) { return obj.__assign(__indirect(__element(j), bb), bb); }
|
||||
public Service getByKey(String key) { return __lookup_by_key(null, __vector(), key, bb); }
|
||||
public Service getByKey(Service obj, String key) { return __lookup_by_key(obj, __vector(), key, bb); }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,79 @@
|
||||
// automatically generated by the FlatBuffers compiler, do not modify
|
||||
|
||||
package com.google.flatbuffers.reflection;
|
||||
|
||||
import com.google.flatbuffers.BaseVector;
|
||||
import com.google.flatbuffers.BooleanVector;
|
||||
import com.google.flatbuffers.ByteVector;
|
||||
import com.google.flatbuffers.Constants;
|
||||
import com.google.flatbuffers.DoubleVector;
|
||||
import com.google.flatbuffers.FlatBufferBuilder;
|
||||
import com.google.flatbuffers.FloatVector;
|
||||
import com.google.flatbuffers.IntVector;
|
||||
import com.google.flatbuffers.LongVector;
|
||||
import com.google.flatbuffers.ShortVector;
|
||||
import com.google.flatbuffers.StringVector;
|
||||
import com.google.flatbuffers.Struct;
|
||||
import com.google.flatbuffers.Table;
|
||||
import com.google.flatbuffers.UnionVector;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.ByteOrder;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public final class Type extends Table {
|
||||
public static void ValidateVersion() { Constants.FLATBUFFERS_23_3_3(); }
|
||||
public static Type getRootAsType(ByteBuffer _bb) { return getRootAsType(_bb, new Type()); }
|
||||
public static Type getRootAsType(ByteBuffer _bb, Type obj) { _bb.order(ByteOrder.LITTLE_ENDIAN); return (obj.__assign(_bb.getInt(_bb.position()) + _bb.position(), _bb)); }
|
||||
public void __init(int _i, ByteBuffer _bb) { __reset(_i, _bb); }
|
||||
public Type __assign(int _i, ByteBuffer _bb) { __init(_i, _bb); return this; }
|
||||
|
||||
public byte baseType() { int o = __offset(4); return o != 0 ? bb.get(o + bb_pos) : 0; }
|
||||
public byte element() { int o = __offset(6); return o != 0 ? bb.get(o + bb_pos) : 0; }
|
||||
public int index() { int o = __offset(8); return o != 0 ? bb.getInt(o + bb_pos) : -1; }
|
||||
public int fixedLength() { int o = __offset(10); return o != 0 ? bb.getShort(o + bb_pos) & 0xFFFF : 0; }
|
||||
/**
|
||||
* The size (octets) of the `base_type` field.
|
||||
*/
|
||||
public long baseSize() { int o = __offset(12); return o != 0 ? (long)bb.getInt(o + bb_pos) & 0xFFFFFFFFL : 4L; }
|
||||
/**
|
||||
* The size (octets) of the `element` field, if present.
|
||||
*/
|
||||
public long elementSize() { int o = __offset(14); return o != 0 ? (long)bb.getInt(o + bb_pos) & 0xFFFFFFFFL : 0L; }
|
||||
|
||||
public static int createType(FlatBufferBuilder builder,
|
||||
byte baseType,
|
||||
byte element,
|
||||
int index,
|
||||
int fixedLength,
|
||||
long baseSize,
|
||||
long elementSize) {
|
||||
builder.startTable(6);
|
||||
Type.addElementSize(builder, elementSize);
|
||||
Type.addBaseSize(builder, baseSize);
|
||||
Type.addIndex(builder, index);
|
||||
Type.addFixedLength(builder, fixedLength);
|
||||
Type.addElement(builder, element);
|
||||
Type.addBaseType(builder, baseType);
|
||||
return Type.endType(builder);
|
||||
}
|
||||
|
||||
public static void startType(FlatBufferBuilder builder) { builder.startTable(6); }
|
||||
public static void addBaseType(FlatBufferBuilder builder, byte baseType) { builder.addByte(0, baseType, 0); }
|
||||
public static void addElement(FlatBufferBuilder builder, byte element) { builder.addByte(1, element, 0); }
|
||||
public static void addIndex(FlatBufferBuilder builder, int index) { builder.addInt(2, index, -1); }
|
||||
public static void addFixedLength(FlatBufferBuilder builder, int fixedLength) { builder.addShort(3, (short) fixedLength, (short) 0); }
|
||||
public static void addBaseSize(FlatBufferBuilder builder, long baseSize) { builder.addInt(4, (int) baseSize, (int) 4L); }
|
||||
public static void addElementSize(FlatBufferBuilder builder, long elementSize) { builder.addInt(5, (int) elementSize, (int) 0L); }
|
||||
public static int endType(FlatBufferBuilder builder) {
|
||||
int o = builder.endTable();
|
||||
return o;
|
||||
}
|
||||
|
||||
public static final class Vector extends BaseVector {
|
||||
public Vector __assign(int _vector, int _element_size, ByteBuffer _bb) { __reset(_vector, _element_size, _bb); return this; }
|
||||
|
||||
public Type get(int j) { return get(new Type(), j); }
|
||||
public Type get(Type obj, int j) { return obj.__assign(__indirect(__element(j), bb), bb); }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,18 +2,11 @@ import org.jetbrains.kotlin.ir.backend.js.compile
|
||||
|
||||
plugins {
|
||||
kotlin("multiplatform")
|
||||
id("org.jetbrains.kotlin.plugin.allopen") version "1.4.20"
|
||||
id("org.jetbrains.kotlinx.benchmark") version "0.4.2"
|
||||
id("io.morethan.jmhreport") version "0.9.0"
|
||||
id("org.jetbrains.kotlinx.benchmark")
|
||||
id("io.morethan.jmhreport")
|
||||
id("de.undercouch.download")
|
||||
}
|
||||
|
||||
// allOpen plugin is needed for the benchmark annotations.
|
||||
// for more information, see https://github.com/Kotlin/kotlinx-benchmark#gradle-plugin
|
||||
allOpen {
|
||||
annotation("org.openjdk.jmh.annotations.State")
|
||||
}
|
||||
|
||||
group = "com.google.flatbuffers.jmh"
|
||||
version = "2.0.0-SNAPSHOT"
|
||||
|
||||
@@ -34,7 +27,7 @@ benchmark {
|
||||
iterationTime = 300
|
||||
iterationTimeUnit = "ms"
|
||||
// uncomment for benchmarking JSON op only
|
||||
// include(".*JsonBenchmark.*")
|
||||
include(".*JsonBenchmark.*")
|
||||
}
|
||||
}
|
||||
targets {
|
||||
@@ -43,9 +36,7 @@ benchmark {
|
||||
}
|
||||
|
||||
kotlin {
|
||||
jvm {
|
||||
withJava()
|
||||
}
|
||||
jvm()
|
||||
|
||||
sourceSets {
|
||||
|
||||
@@ -58,7 +49,7 @@ kotlin {
|
||||
implementation(kotlin("stdlib-common"))
|
||||
implementation(project(":flatbuffers-kotlin"))
|
||||
implementation(libs.kotlinx.benchmark.runtime)
|
||||
|
||||
implementation("com.google.flatbuffers:flatbuffers-java:2.0.3")
|
||||
// json serializers
|
||||
implementation(libs.moshi.kotlin)
|
||||
implementation(libs.gson)
|
||||
|
||||
@@ -14,7 +14,6 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.google.flatbuffers.kotlin.benchmark
|
||||
|
||||
import com.google.flatbuffers.ArrayReadWriteBuf
|
||||
import com.google.flatbuffers.FlexBuffers
|
||||
import com.google.flatbuffers.FlexBuffersBuilder.BUILDER_FLAG_SHARE_ALL
|
||||
@@ -35,7 +34,7 @@ import java.util.concurrent.TimeUnit
|
||||
@BenchmarkMode(Mode.AverageTime)
|
||||
@OutputTimeUnit(TimeUnit.NANOSECONDS)
|
||||
@Measurement(iterations = 20, time = 1, timeUnit = TimeUnit.NANOSECONDS)
|
||||
class FlexBuffersBenchmark {
|
||||
open class FlexBuffersBenchmark {
|
||||
|
||||
var initialCapacity = 1024
|
||||
var value: Double = 0.0
|
||||
@@ -49,7 +48,7 @@ class FlexBuffersBenchmark {
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
fun mapKotlin(blackhole: Blackhole) {
|
||||
open fun mapKotlin(blackhole: Blackhole) {
|
||||
val kBuilder = FlexBuffersBuilder(initialCapacity, FlexBuffersBuilder.SHARE_KEYS_AND_STRINGS)
|
||||
kBuilder.putMap {
|
||||
this["hello"] = "world"
|
||||
@@ -72,7 +71,7 @@ class FlexBuffersBenchmark {
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
fun mapJava(blackhole: Blackhole) {
|
||||
open fun mapJava(blackhole: Blackhole) {
|
||||
val jBuilder = com.google.flatbuffers.FlexBuffersBuilder(ArrayReadWriteBuf(initialCapacity), BUILDER_FLAG_SHARE_ALL)
|
||||
val startMap = jBuilder.startMap()
|
||||
jBuilder.putString("hello", "world")
|
||||
@@ -102,7 +101,7 @@ class FlexBuffersBenchmark {
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
fun intArrayKotlin(blackhole: Blackhole) {
|
||||
open fun intArrayKotlin(blackhole: Blackhole) {
|
||||
val kBuilder = FlexBuffersBuilder(initialCapacity, FlexBuffersBuilder.SHARE_KEYS_AND_STRINGS)
|
||||
kBuilder.put(bigIntArray)
|
||||
val root = getRoot(kBuilder.finish())
|
||||
@@ -110,7 +109,7 @@ class FlexBuffersBenchmark {
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
fun intArrayJava(blackhole: Blackhole) {
|
||||
open fun intArrayJava(blackhole: Blackhole) {
|
||||
val jBuilder = com.google.flatbuffers.FlexBuffersBuilder(ArrayReadWriteBuf(initialCapacity), BUILDER_FLAG_SHARE_ALL)
|
||||
val v = jBuilder.startVector()
|
||||
bigIntArray.forEach { jBuilder.putInt(it) }
|
||||
@@ -126,7 +125,7 @@ class FlexBuffersBenchmark {
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
fun stringArrayKotlin(blackhole: Blackhole) {
|
||||
open fun stringArrayKotlin(blackhole: Blackhole) {
|
||||
val kBuilder = FlexBuffersBuilder(initialCapacity, FlexBuffersBuilder.SHARE_KEYS_AND_STRINGS)
|
||||
kBuilder.putVector { stringValue.forEach { kBuilder.put(it) } }
|
||||
kBuilder.finish()
|
||||
@@ -136,7 +135,7 @@ class FlexBuffersBenchmark {
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
fun stringArrayJava(blackhole: Blackhole) {
|
||||
open fun stringArrayJava(blackhole: Blackhole) {
|
||||
val jBuilder = com.google.flatbuffers.FlexBuffersBuilder(ArrayReadWriteBuf(initialCapacity), BUILDER_FLAG_SHARE_ALL)
|
||||
val v = jBuilder.startVector()
|
||||
stringValue.forEach { jBuilder.putString(it) }
|
||||
@@ -148,7 +147,7 @@ class FlexBuffersBenchmark {
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
fun stringMapKotlin(blackhole: Blackhole) {
|
||||
open fun stringMapKotlin(blackhole: Blackhole) {
|
||||
val kBuilder = FlexBuffersBuilder(initialCapacity, FlexBuffersBuilder.SHARE_KEYS_AND_STRINGS)
|
||||
val pos = kBuilder.startMap()
|
||||
for (i in stringKey.indices) {
|
||||
@@ -165,7 +164,7 @@ class FlexBuffersBenchmark {
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
fun stringMapBytIndexKotlin(blackhole: Blackhole) {
|
||||
open fun stringMapBytIndexKotlin(blackhole: Blackhole) {
|
||||
val kBuilder = FlexBuffersBuilder(initialCapacity, FlexBuffersBuilder.SHARE_KEYS_AND_STRINGS)
|
||||
val pos = kBuilder.startMap()
|
||||
for (i in stringKey.indices) {
|
||||
@@ -180,7 +179,7 @@ class FlexBuffersBenchmark {
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
fun stringMapJava(blackhole: Blackhole) {
|
||||
open fun stringMapJava(blackhole: Blackhole) {
|
||||
val jBuilder = com.google.flatbuffers.FlexBuffersBuilder(ArrayReadWriteBuf(initialCapacity), BUILDER_FLAG_SHARE_ALL)
|
||||
val v = jBuilder.startMap()
|
||||
for (i in stringKey.indices) {
|
||||
|
||||
@@ -41,7 +41,7 @@ import java.util.concurrent.TimeUnit
|
||||
@BenchmarkMode(Mode.AverageTime)
|
||||
@OutputTimeUnit(TimeUnit.MICROSECONDS)
|
||||
@Measurement(iterations = 100, time = 1, timeUnit = TimeUnit.MICROSECONDS)
|
||||
class JsonBenchmark {
|
||||
open class JsonBenchmark {
|
||||
|
||||
final val moshi = Moshi.Builder()
|
||||
.addLast(KotlinJsonAdapterFactory())
|
||||
@@ -76,46 +76,46 @@ class JsonBenchmark {
|
||||
|
||||
// TWITTER
|
||||
@Benchmark
|
||||
fun readTwitterFlexBuffers(hole: Blackhole? = null) = hole?.consume(readFlexBuffers(twitterData))
|
||||
open fun readTwitterFlexBuffers(hole: Blackhole? = null) = hole?.consume(readFlexBuffers(twitterData))
|
||||
@Benchmark
|
||||
fun readTwitterMoshi(hole: Blackhole?) = hole?.consume(readMoshi(twitterData))
|
||||
open fun readTwitterMoshi(hole: Blackhole?) = hole?.consume(readMoshi(twitterData))
|
||||
@Benchmark
|
||||
fun readTwitterGson(hole: Blackhole?) = hole?.consume(readGson(twitterData))
|
||||
open fun readTwitterGson(hole: Blackhole?) = hole?.consume(readGson(twitterData))
|
||||
|
||||
@Benchmark
|
||||
fun roundTripTwitterFlexBuffers(hole: Blackhole? = null) = hole?.consume(readFlexBuffers(twitterData).toJson())
|
||||
open fun roundTripTwitterFlexBuffers(hole: Blackhole? = null) = hole?.consume(readFlexBuffers(twitterData).toJson())
|
||||
@Benchmark
|
||||
fun roundTripTwitterMoshi(hole: Blackhole?) = hole?.consume(moshiAdapter.toJson(readMoshi(twitterData)))
|
||||
open fun roundTripTwitterMoshi(hole: Blackhole?) = hole?.consume(moshiAdapter.toJson(readMoshi(twitterData)))
|
||||
@Benchmark
|
||||
fun roundTripTwitterGson(hole: Blackhole?) = hole?.consume(gson.toJson(readGson(twitterData)))
|
||||
open fun roundTripTwitterGson(hole: Blackhole?) = hole?.consume(gson.toJson(readGson(twitterData)))
|
||||
|
||||
// CITM
|
||||
@Benchmark
|
||||
fun readCITMFlexBuffers(hole: Blackhole? = null) = hole?.consume(readFlexBuffers(citmData))
|
||||
open fun readCITMFlexBuffers(hole: Blackhole? = null) = hole?.consume(readFlexBuffers(citmData))
|
||||
@Benchmark
|
||||
fun readCITMMoshi(hole: Blackhole?) = hole?.consume(moshiAdapter.toJson(readMoshi(citmData)))
|
||||
open fun readCITMMoshi(hole: Blackhole?) = hole?.consume(moshiAdapter.toJson(readMoshi(citmData)))
|
||||
@Benchmark
|
||||
fun readCITMGson(hole: Blackhole?) = hole?.consume(gson.toJson(readGson(citmData)))
|
||||
open fun readCITMGson(hole: Blackhole?) = hole?.consume(gson.toJson(readGson(citmData)))
|
||||
|
||||
@Benchmark
|
||||
fun roundTripCITMFlexBuffers(hole: Blackhole? = null) = hole?.consume(readFlexBuffers(citmData).toJson())
|
||||
open fun roundTripCITMFlexBuffers(hole: Blackhole? = null) = hole?.consume(readFlexBuffers(citmData).toJson())
|
||||
@Benchmark
|
||||
fun roundTripCITMMoshi(hole: Blackhole?) = hole?.consume(moshiAdapter.toJson(readMoshi(citmData)))
|
||||
open fun roundTripCITMMoshi(hole: Blackhole?) = hole?.consume(moshiAdapter.toJson(readMoshi(citmData)))
|
||||
@Benchmark
|
||||
fun roundTripCITMGson(hole: Blackhole?) = hole?.consume(gson.toJson(readGson(citmData)))
|
||||
open fun roundTripCITMGson(hole: Blackhole?) = hole?.consume(gson.toJson(readGson(citmData)))
|
||||
|
||||
@Benchmark
|
||||
fun writeCITMFlexBuffers(hole: Blackhole? = null) = hole?.consume(fbCitmRef.toJson())
|
||||
open fun writeCITMFlexBuffers(hole: Blackhole? = null) = hole?.consume(fbCitmRef.toJson())
|
||||
@Benchmark
|
||||
fun writeCITMMoshi(hole: Blackhole?) = hole?.consume(moshiAdapter.toJson(moshiCitmRef))
|
||||
open fun writeCITMMoshi(hole: Blackhole?) = hole?.consume(moshiAdapter.toJson(moshiCitmRef))
|
||||
@Benchmark
|
||||
fun writeCITMGson(hole: Blackhole?) = hole?.consume(gson.toJson(gsonCitmRef))
|
||||
open fun writeCITMGson(hole: Blackhole?) = hole?.consume(gson.toJson(gsonCitmRef))
|
||||
|
||||
// CANADA
|
||||
@Benchmark
|
||||
fun readCanadaFlexBuffers(hole: Blackhole? = null) = hole?.consume(readFlexBuffers(canadaData))
|
||||
open fun readCanadaFlexBuffers(hole: Blackhole? = null) = hole?.consume(readFlexBuffers(canadaData))
|
||||
@Benchmark
|
||||
fun readCanadaMoshi(hole: Blackhole?) = hole?.consume(readMoshi(canadaData))
|
||||
open fun readCanadaMoshi(hole: Blackhole?) = hole?.consume(readMoshi(canadaData))
|
||||
@Benchmark
|
||||
fun readCanadaGson(hole: Blackhole?) = hole?.consume(readGson(canadaData))
|
||||
open fun readCanadaGson(hole: Blackhole?) = hole?.consume(readGson(canadaData))
|
||||
}
|
||||
|
||||
@@ -1,7 +1,3 @@
|
||||
plugins {
|
||||
id("com.diffplug.spotless") version "6.3.0"
|
||||
}
|
||||
|
||||
group = "com.google.flatbuffers"
|
||||
version = "2.0.0-SNAPSHOT"
|
||||
|
||||
@@ -12,7 +8,10 @@ buildscript {
|
||||
mavenCentral()
|
||||
}
|
||||
dependencies {
|
||||
classpath(libs.bundles.plugins)
|
||||
classpath(libs.plugin.kotlin.gradle)
|
||||
classpath(libs.plugin.kotlinx.benchmark)
|
||||
classpath(libs.plugin.jmhreport)
|
||||
classpath(libs.plugin.download)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,21 +21,3 @@ allprojects {
|
||||
mavenCentral()
|
||||
}
|
||||
}
|
||||
|
||||
// plugin used to enforce code style
|
||||
spotless {
|
||||
val klintConfig = mapOf("indent_size" to "2", "continuation_indent_size" to "2")
|
||||
kotlin {
|
||||
target("**/*.kt")
|
||||
ktlint("0.40.0").userData(klintConfig)
|
||||
trimTrailingWhitespace()
|
||||
indentWithSpaces()
|
||||
endWithNewline()
|
||||
licenseHeaderFile("$rootDir/spotless/spotless.kt").updateYearWithLatest(false)
|
||||
targetExclude("**/spotless.kt", "**/build/**")
|
||||
}
|
||||
kotlinGradle {
|
||||
target("*.gradle.kts")
|
||||
ktlint().userData(klintConfig)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,20 +1,19 @@
|
||||
[versions]
|
||||
plugin-kotlin = "1.6.10"
|
||||
kotlin = "1.7.21"
|
||||
plugin-gver = "0.42.0"
|
||||
kotlinx-benchmark-runtime = "0.4.2"
|
||||
kotlinx-benchmark = "0.4.6"
|
||||
junit = "4.12"
|
||||
gson = "2.8.5"
|
||||
moshi-kotlin = "1.11.0"
|
||||
|
||||
[libraries]
|
||||
kotlin-compiler = { module = "org.jetbrains.kotlin:kotlin-compiler", version.ref = "kotlin" }
|
||||
moshi-kotlin = { module = "com.squareup.moshi:moshi-kotlin", version.ref = "moshi-kotlin" }
|
||||
gson = { module = "com.google.code.gson:gson", version.ref = "gson" }
|
||||
kotlinx-benchmark-runtime = { module = "org.jetbrains.kotlinx:kotlinx-benchmark-runtime", version.ref = "kotlinx-benchmark-runtime" }
|
||||
plugin-kotlin = { module = "org.jetbrains.kotlin:kotlin-gradle-plugin", version.ref = "plugin-kotlin" }
|
||||
plugin-kotlin-serialization = { module = "org.jetbrains.kotlin:kotlin-serialization", version.ref = "plugin-kotlin" }
|
||||
kotlinx-benchmark-runtime = { module = "org.jetbrains.kotlinx:kotlinx-benchmark-runtime", version.ref = "kotlinx-benchmark" }
|
||||
plugin-gver = { module = "com.github.ben-manes:gradle-versions-plugin", version.ref = "plugin-gver" }
|
||||
|
||||
plugin-kotlin-gradle = { module = "org.jetbrains.kotlin:kotlin-gradle-plugin", version.ref = "kotlin" }
|
||||
plugin-kotlinx-benchmark = { module="org.jetbrains.kotlinx:kotlinx-benchmark-plugin", version.ref="kotlinx-benchmark"}
|
||||
plugin-jmhreport = { module = "gradle.plugin.io.morethan.jmhreport:gradle-jmh-report", version="0.9.0" }
|
||||
plugin-download = { module = "de.undercouch:gradle-download-task", version = "5.3.0"}
|
||||
junit = { module="junit:junit", version.ref="junit"}
|
||||
|
||||
[bundles]
|
||||
plugins = ["plugin-kotlin", "plugin-kotlin-serialization", "plugin-gver"]
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4.2-bin.zip
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.0.1-bin.zip
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
||||
|
||||
@@ -32,6 +32,6 @@ namespace Google.FlatBuffers
|
||||
Changes to the C# implementation need to be sure to change
|
||||
the version here and in the code generator on every possible
|
||||
incompatible change */
|
||||
public static void FLATBUFFERS_23_1_4() {}
|
||||
public static void FLATBUFFERS_23_3_3() {}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<PropertyGroup>
|
||||
<TargetFrameworks>netstandard2.1;netstandard2.0;net46</TargetFrameworks>
|
||||
<Description>A cross-platform memory efficient serialization library</Description>
|
||||
<PackageVersion>23.1.4</PackageVersion>
|
||||
<PackageVersion>23.3.3</PackageVersion>
|
||||
<Authors>Google LLC</Authors>
|
||||
<PackageProjectUrl>https://github.com/google/flatbuffers</PackageProjectUrl>
|
||||
<RepositoryUrl>https://github.com/google/flatbuffers</RepositoryUrl>
|
||||
|
||||
16
package.json
16
package.json
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "flatbuffers",
|
||||
"version": "23.1.4",
|
||||
"version": "23.3.3",
|
||||
"description": "Memory Efficient Serialization Library",
|
||||
"files": [
|
||||
"js/**/*.js",
|
||||
@@ -9,8 +9,8 @@
|
||||
"mjs/**/*.d.ts",
|
||||
"ts/**/*.ts"
|
||||
],
|
||||
"main": "js/index.js",
|
||||
"module": "mjs/index.js",
|
||||
"main": "js/flatbuffers.js",
|
||||
"module": "mjs/flatbuffers.js",
|
||||
"directories": {
|
||||
"doc": "docs",
|
||||
"test": "tests"
|
||||
@@ -18,7 +18,7 @@
|
||||
"scripts": {
|
||||
"test": "npm run compile && cd tests/ts && python3 ./TypeScriptTest.py",
|
||||
"lint": "eslint ts",
|
||||
"compile": "tsc && tsc -p tsconfig.mjs.json && rollup -c",
|
||||
"compile": "tsc && tsc -p tsconfig.mjs.json && esbuild js/flatbuffers.js --minify --global-name=flatbuffers --bundle --outfile=js/flatbuffers.min.js",
|
||||
"prepublishOnly": "npm install --only=dev && npm run compile"
|
||||
},
|
||||
"repository": {
|
||||
@@ -38,10 +38,10 @@
|
||||
"devDependencies": {
|
||||
"@bazel/typescript": "5.2.0",
|
||||
"@types/node": "18.7.16",
|
||||
"@typescript-eslint/eslint-plugin": "^5.36.2",
|
||||
"@typescript-eslint/parser": "^5.36.2",
|
||||
"eslint": "^8.23.1",
|
||||
"rollup": "^2.79.0",
|
||||
"@typescript-eslint/eslint-plugin": "^5.46.0",
|
||||
"@typescript-eslint/parser": "^5.46.0",
|
||||
"esbuild": "^0.16.4",
|
||||
"eslint": "^8.29.0",
|
||||
"typescript": "^4.8.3"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,4 +14,4 @@
|
||||
|
||||
# Placeholder, to be updated during the release process
|
||||
# by the setup.py
|
||||
__version__ = u"23.1.4"
|
||||
__version__ = u"23.3.3"
|
||||
|
||||
@@ -75,7 +75,7 @@ class BitWidth(enum.IntEnum):
|
||||
@staticmethod
|
||||
def F(value):
|
||||
"""Returns the `BitWidth` to encode floating point value."""
|
||||
if struct.unpack('f', struct.pack('f', value))[0] == value:
|
||||
if struct.unpack('<f', struct.pack('<f', value))[0] == value:
|
||||
return BitWidth.W32
|
||||
return BitWidth.W64
|
||||
|
||||
@@ -95,20 +95,20 @@ F = {4: 'f', 8: 'd'} # Floating point formats
|
||||
|
||||
|
||||
def _Unpack(fmt, buf):
|
||||
return struct.unpack(fmt[len(buf)], buf)[0]
|
||||
return struct.unpack('<%s' % fmt[len(buf)], buf)[0]
|
||||
|
||||
|
||||
def _UnpackVector(fmt, buf, length):
|
||||
byte_width = len(buf) // length
|
||||
return struct.unpack('%d%s' % (length, fmt[byte_width]), buf)
|
||||
return struct.unpack('<%d%s' % (length, fmt[byte_width]), buf)
|
||||
|
||||
|
||||
def _Pack(fmt, value, byte_width):
|
||||
return struct.pack(fmt[byte_width], value)
|
||||
return struct.pack('<%s' % fmt[byte_width], value)
|
||||
|
||||
|
||||
def _PackVector(fmt, values, byte_width):
|
||||
return struct.pack('%d%s' % (len(values), fmt[byte_width]), *values)
|
||||
return struct.pack('<%d%s' % (len(values), fmt[byte_width]), *values)
|
||||
|
||||
|
||||
def _Mutate(fmt, buf, value, byte_width, value_bit_width):
|
||||
|
||||
@@ -16,7 +16,7 @@ from setuptools import setup
|
||||
|
||||
setup(
|
||||
name='flatbuffers',
|
||||
version='23.1.4',
|
||||
version='23.3.3',
|
||||
license='Apache 2.0',
|
||||
license_files='../LICENSE.txt',
|
||||
author='Derek Bailey',
|
||||
|
||||
@@ -44,6 +44,10 @@ Code generation and runtime libraries for many popular languages.
|
||||
1. TypeScript - [NPM](https://www.npmjs.com/package/flatbuffers)
|
||||
1. Nim
|
||||
|
||||
## Versioning
|
||||
|
||||
FlatBuffers does not follow traditional Semver versioning (see [rationale](https://github.com/google/flatbuffers/wiki/Versioning)) but rather uses a format of the date of the release.
|
||||
|
||||
## Contribution
|
||||
|
||||
* [FlatBuffers Issues Tracker][] to submit an issue.
|
||||
@@ -73,4 +77,4 @@ Please see our [Security Policy](SECURITY.md) for reporting vulnerabilities.
|
||||
[FlatBuffers Issues Tracker]: http://github.com/google/flatbuffers/issues
|
||||
[stackoverflow.com]: http://stackoverflow.com/search?q=flatbuffers
|
||||
[landing page]: https://google.github.io/flatbuffers
|
||||
[LICENSE]: https://github.com/google/flatbuffers/blob/master/LICENSE.txt
|
||||
[LICENSE]: https://github.com/google/flatbuffers/blob/master/LICENSE
|
||||
|
||||
@@ -11,6 +11,5 @@ flatbuffer_ts_library(
|
||||
name = "reflection_ts_fbs",
|
||||
package_name = "flatbuffers_reflection",
|
||||
srcs = [":reflection.fbs"],
|
||||
include_reflection = False,
|
||||
visibility = ["//visibility:public"],
|
||||
)
|
||||
|
||||
@@ -1,8 +0,0 @@
|
||||
export default {
|
||||
input: 'mjs/index.js',
|
||||
output: {
|
||||
file: 'flatbuffers.js',
|
||||
format: 'iife',
|
||||
name: 'flatbuffers'
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "flatbuffers"
|
||||
version = "23.1.4"
|
||||
version = "23.3.3"
|
||||
edition = "2018"
|
||||
authors = ["Robert Winslow <hello@rwinslow.com>", "FlatBuffers Maintainers"]
|
||||
license = "Apache-2.0"
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -9,8 +9,8 @@
|
||||
// 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 == 23 &&
|
||||
FLATBUFFERS_VERSION_MINOR == 1 &&
|
||||
FLATBUFFERS_VERSION_REVISION == 4,
|
||||
FLATBUFFERS_VERSION_MINOR == 3 &&
|
||||
FLATBUFFERS_VERSION_REVISION == 3,
|
||||
"Non-compatible flatbuffers version included");
|
||||
|
||||
namespace MyGame {
|
||||
@@ -33,11 +33,11 @@ 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 : int8_t {
|
||||
Color_Red = 0,
|
||||
@@ -67,7 +67,7 @@ inline const char * const *EnumNamesColor() {
|
||||
}
|
||||
|
||||
inline const char *EnumNameColor(Color e) {
|
||||
if (flatbuffers::IsOutRange(e, Color_Red, Color_Blue)) return "";
|
||||
if (::flatbuffers::IsOutRange(e, Color_Red, Color_Blue)) return "";
|
||||
const size_t index = static_cast<size_t>(e);
|
||||
return EnumNamesColor()[index];
|
||||
}
|
||||
@@ -97,7 +97,7 @@ inline const char * const *EnumNamesEquipment() {
|
||||
}
|
||||
|
||||
inline const char *EnumNameEquipment(Equipment e) {
|
||||
if (flatbuffers::IsOutRange(e, Equipment_NONE, Equipment_Weapon)) return "";
|
||||
if (::flatbuffers::IsOutRange(e, Equipment_NONE, Equipment_Weapon)) return "";
|
||||
const size_t index = static_cast<size_t>(e);
|
||||
return EnumNamesEquipment()[index];
|
||||
}
|
||||
@@ -145,8 +145,8 @@ struct EquipmentUnion {
|
||||
}
|
||||
}
|
||||
|
||||
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 ?
|
||||
@@ -179,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:
|
||||
@@ -189,7 +189,7 @@ 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()
|
||||
@@ -198,27 +198,27 @@ FLATBUFFERS_MANUALLY_ALIGNED_STRUCT(4) Vec3 FLATBUFFERS_FINAL_CLASS {
|
||||
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);
|
||||
@@ -235,7 +235,7 @@ 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 = 150;
|
||||
@@ -252,10 +252,10 @@ struct MonsterT : public flatbuffers::NativeTable {
|
||||
MonsterT &operator=(MonsterT o) FLATBUFFERS_NOEXCEPT;
|
||||
};
|
||||
|
||||
struct Monster FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table {
|
||||
struct Monster FLATBUFFERS_FINAL_CLASS : private ::flatbuffers::Table {
|
||||
typedef MonsterT NativeTableType;
|
||||
typedef MonsterBuilder Builder;
|
||||
static const flatbuffers::TypeTable *MiniReflectTypeTable() {
|
||||
static const ::flatbuffers::TypeTable *MiniReflectTypeTable() {
|
||||
return MonsterTypeTable();
|
||||
}
|
||||
enum FlatBuffersVTableOffset FLATBUFFERS_VTABLE_UNDERLYING_TYPE {
|
||||
@@ -288,17 +288,17 @@ struct Monster FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table {
|
||||
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));
|
||||
@@ -306,11 +306,11 @@ struct Monster FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table {
|
||||
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));
|
||||
@@ -325,13 +325,13 @@ 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, 4) &&
|
||||
VerifyField<int16_t>(verifier, VT_MANA, 2) &&
|
||||
@@ -351,9 +351,9 @@ struct Monster FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table {
|
||||
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 {
|
||||
@@ -362,8 +362,8 @@ template<> inline const MyGame::Sample::Weapon *Monster::equipped_as<MyGame::Sam
|
||||
|
||||
struct MonsterBuilder {
|
||||
typedef Monster Table;
|
||||
flatbuffers::FlatBufferBuilder &fbb_;
|
||||
flatbuffers::uoffset_t start_;
|
||||
::flatbuffers::FlatBufferBuilder &fbb_;
|
||||
::flatbuffers::uoffset_t start_;
|
||||
void add_pos(const MyGame::Sample::Vec3 *pos) {
|
||||
fbb_.AddStruct(Monster::VT_POS, pos);
|
||||
}
|
||||
@@ -373,50 +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();
|
||||
}
|
||||
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,
|
||||
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);
|
||||
@@ -431,21 +431,21 @@ inline flatbuffers::Offset<Monster> CreateMonster(
|
||||
return builder_.Finish();
|
||||
}
|
||||
|
||||
inline flatbuffers::Offset<Monster> CreateMonsterDirect(
|
||||
flatbuffers::FlatBufferBuilder &_fbb,
|
||||
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,
|
||||
@@ -461,29 +461,29 @@ 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 = 0;
|
||||
};
|
||||
|
||||
struct Weapon FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table {
|
||||
struct Weapon FLATBUFFERS_FINAL_CLASS : private ::flatbuffers::Table {
|
||||
typedef WeaponT NativeTableType;
|
||||
typedef WeaponBuilder Builder;
|
||||
static const flatbuffers::TypeTable *MiniReflectTypeTable() {
|
||||
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);
|
||||
@@ -491,42 +491,42 @@ struct Weapon FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table {
|
||||
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, 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 {
|
||||
typedef Weapon Table;
|
||||
flatbuffers::FlatBufferBuilder &fbb_;
|
||||
flatbuffers::uoffset_t start_;
|
||||
void add_name(flatbuffers::Offset<flatbuffers::String> name) {
|
||||
::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();
|
||||
}
|
||||
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);
|
||||
@@ -534,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;
|
||||
@@ -545,7 +545,7 @@ 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 bool operator==(const MonsterT &lhs, const MonsterT &rhs) {
|
||||
@@ -592,13 +592,13 @@ inline MonsterT &MonsterT::operator=(MonsterT o) FLATBUFFERS_NOEXCEPT {
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline MonsterT *Monster::UnPack(const flatbuffers::resolver_function_t *_resolver) const {
|
||||
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 {
|
||||
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)); }
|
||||
@@ -607,27 +607,27 @@ inline void Monster::UnPackTo(MonsterT *_o, const flatbuffers::resolver_function
|
||||
{ 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] = flatbuffers::unique_ptr<MyGame::Sample::WeaponT>(_e->Get(_i)->UnPack(_resolver)); }; } } else { _o->weapons.resize(0); } }
|
||||
{ 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] = flatbuffers::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); } }
|
||||
{ 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;
|
||||
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;
|
||||
@@ -657,27 +657,27 @@ inline bool operator!=(const WeaponT &lhs, const WeaponT &rhs) {
|
||||
}
|
||||
|
||||
|
||||
inline WeaponT *Weapon::UnPack(const flatbuffers::resolver_function_t *_resolver) const {
|
||||
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 {
|
||||
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; }
|
||||
}
|
||||
|
||||
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(
|
||||
@@ -686,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;
|
||||
@@ -699,10 +699,10 @@ inline bool VerifyEquipment(flatbuffers::Verifier &verifier, const void *obj, Eq
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
@@ -711,7 +711,7 @@ 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: {
|
||||
@@ -722,7 +722,7 @@ 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: {
|
||||
@@ -757,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[] = {
|
||||
@@ -771,35 +771,35 @@ inline const flatbuffers::TypeTable *ColorTypeTable() {
|
||||
"Green",
|
||||
"Blue"
|
||||
};
|
||||
static const flatbuffers::TypeTable tt = {
|
||||
flatbuffers::ST_ENUM, 3, type_codes, type_refs, nullptr, 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, 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[] = {
|
||||
@@ -807,27 +807,27 @@ inline const flatbuffers::TypeTable *Vec3TypeTable() {
|
||||
"y",
|
||||
"z"
|
||||
};
|
||||
static const flatbuffers::TypeTable tt = {
|
||||
flatbuffers::ST_STRUCT, 3, type_codes, nullptr, 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,
|
||||
@@ -846,74 +846,74 @@ inline const flatbuffers::TypeTable *MonsterTypeTable() {
|
||||
"equipped",
|
||||
"path"
|
||||
};
|
||||
static const flatbuffers::TypeTable tt = {
|
||||
flatbuffers::ST_TABLE, 11, type_codes, type_refs, nullptr, 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, 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);
|
||||
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(
|
||||
const void *buf,
|
||||
const flatbuffers::resolver_function_t *res = nullptr) {
|
||||
const ::flatbuffers::resolver_function_t *res = nullptr) {
|
||||
return flatbuffers::unique_ptr<MyGame::Sample::MonsterT>(GetMonster(buf)->UnPack(res));
|
||||
}
|
||||
|
||||
inline flatbuffers::unique_ptr<MyGame::Sample::MonsterT> UnPackSizePrefixedMonster(
|
||||
const void *buf,
|
||||
const flatbuffers::resolver_function_t *res = nullptr) {
|
||||
const ::flatbuffers::resolver_function_t *res = nullptr) {
|
||||
return flatbuffers::unique_ptr<MyGame::Sample::MonsterT>(GetSizePrefixedMonster(buf)->UnPack(res));
|
||||
}
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
import FlatBuffers
|
||||
|
||||
public enum MyGame_Sample_Color: Int8, Enum {
|
||||
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 }
|
||||
@@ -12,31 +12,43 @@ public enum MyGame_Sample_Color: Int8, Enum {
|
||||
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, Enum {
|
||||
|
||||
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 {
|
||||
|
||||
static func validateVersion() { FlatBuffersVersion_23_1_4() }
|
||||
public struct MyGame_Sample_Vec3: NativeStruct, Verifiable, FlatbuffersInitializable {
|
||||
|
||||
static func validateVersion() { FlatBuffersVersion_23_3_3() }
|
||||
|
||||
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
|
||||
@@ -52,11 +64,15 @@ public struct MyGame_Sample_Vec3: NativeStruct {
|
||||
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_23_1_4() }
|
||||
static func validateVersion() { FlatBuffersVersion_23_3_3() }
|
||||
public var __buffer: ByteBuffer! { return _accessor.bb }
|
||||
private var _accessor: Struct
|
||||
|
||||
@@ -70,14 +86,12 @@ public struct MyGame_Sample_Vec3_Mutable: FlatBufferObject {
|
||||
@discardableResult public func mutate(z: Float32) -> Bool { return _accessor.mutate(z, index: 8) }
|
||||
}
|
||||
|
||||
public struct MyGame_Sample_Monster: FlatBufferObject {
|
||||
public struct MyGame_Sample_Monster: FlatBufferObject, Verifiable {
|
||||
|
||||
static func validateVersion() { FlatBuffersVersion_23_1_4() }
|
||||
static func validateVersion() { FlatBuffersVersion_23_3_3() }
|
||||
public var __buffer: ByteBuffer! { return _accessor.bb }
|
||||
private var _accessor: Table
|
||||
|
||||
public static func getRootAsMonster(bb: ByteBuffer) -> MyGame_Sample_Monster { return MyGame_Sample_Monster(Table(bb: bb, position: Int32(bb.read(def: UOffset.self, position: bb.reader)) + Int32(bb.reader))) }
|
||||
|
||||
private init(_ t: Table) { _accessor = t }
|
||||
public init(_ bb: ByteBuffer, o: Int32) { _accessor = Table(bb: bb, position: o) }
|
||||
|
||||
@@ -104,16 +118,19 @@ public struct MyGame_Sample_Monster: FlatBufferObject {
|
||||
@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) }
|
||||
@@ -158,16 +175,35 @@ public struct MyGame_Sample_Monster: FlatBufferObject {
|
||||
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 {
|
||||
public struct MyGame_Sample_Weapon: FlatBufferObject, Verifiable {
|
||||
|
||||
static func validateVersion() { FlatBuffersVersion_23_1_4() }
|
||||
static func validateVersion() { FlatBuffersVersion_23_3_3() }
|
||||
public var __buffer: ByteBuffer! { return _accessor.bb }
|
||||
private var _accessor: Table
|
||||
|
||||
public static func getRootAsWeapon(bb: ByteBuffer) -> MyGame_Sample_Weapon { return MyGame_Sample_Weapon(Table(bb: bb, position: Int32(bb.read(def: UOffset.self, position: bb.reader)) + Int32(bb.reader))) }
|
||||
|
||||
private init(_ t: Table) { _accessor = t }
|
||||
public init(_ bb: ByteBuffer, o: Int32) { _accessor = Table(bb: bb, position: o) }
|
||||
|
||||
@@ -196,5 +232,12 @@ public struct MyGame_Sample_Weapon: FlatBufferObject {
|
||||
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()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2021 Google Inc. All rights reserved.
|
||||
* 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.
|
||||
@@ -56,8 +56,8 @@ func main() {
|
||||
equippedOffset: axe)
|
||||
builder.finish(offset: orc)
|
||||
|
||||
let buf = builder.sizedByteArray
|
||||
let monster = Monster.getRootAsMonster(bb: ByteBuffer(bytes: buf))
|
||||
var buf = ByteBuffer(bytes: builder.sizedByteArray)
|
||||
let monster: Monster = try! getCheckedRoot(byteBuffer: &buffer)
|
||||
|
||||
assert(monster.mana == 150)
|
||||
assert(monster.hp == 300)
|
||||
|
||||
@@ -29,7 +29,7 @@ root_path = script_path.parent.absolute()
|
||||
print("Generating GRPC code...")
|
||||
generate_grpc_examples.GenerateGRPCExamples()
|
||||
|
||||
result = subprocess.run(["git", "diff", "--quiet"], cwd=root_path)
|
||||
result = subprocess.run(["git", "diff", "--quiet", "--ignore-cr-at-eol"], cwd=root_path)
|
||||
|
||||
if result.returncode != 0:
|
||||
print(
|
||||
|
||||
@@ -26,7 +26,7 @@ script_path = Path(__file__).parent.resolve()
|
||||
# Get the root path as an absolute path, so all derived paths are absolute.
|
||||
root_path = script_path.parent.absolute()
|
||||
|
||||
result = subprocess.run(["git", "diff", "--quiet"], cwd=root_path)
|
||||
result = subprocess.run(["git", "diff", "--quiet", "--ignore-cr-at-eol"], cwd=root_path)
|
||||
|
||||
if result.returncode != 0:
|
||||
print(
|
||||
@@ -46,7 +46,7 @@ if platform.system() == "Windows":
|
||||
gen_cmd = ["py"] + gen_cmd
|
||||
subprocess.run(gen_cmd, cwd=root_path)
|
||||
|
||||
result = subprocess.run(["git", "diff", "--quiet"], cwd=root_path)
|
||||
result = subprocess.run(["git", "diff", "--quiet", "--ignore-cr-at-eol"], cwd=root_path)
|
||||
|
||||
if result.returncode != 0:
|
||||
print(
|
||||
|
||||
@@ -14,73 +14,20 @@
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
import argparse
|
||||
import filecmp
|
||||
import glob
|
||||
import platform
|
||||
import shutil
|
||||
import subprocess
|
||||
import generate_grpc_examples
|
||||
from pathlib import Path
|
||||
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument(
|
||||
"--flatc",
|
||||
help="path of the Flat C compiler relative to the root directory",
|
||||
)
|
||||
parser.add_argument("--cpp-0x", action="store_true", help="use --cpp-std c++ox")
|
||||
parser.add_argument(
|
||||
"--skip-monster-extra",
|
||||
action="store_true",
|
||||
help="skip generating tests involving monster_extra.fbs",
|
||||
)
|
||||
parser.add_argument(
|
||||
"--skip-gen-reflection",
|
||||
action="store_true",
|
||||
help="skip generating the reflection.fbs files",
|
||||
)
|
||||
args = parser.parse_args()
|
||||
|
||||
# Get the path where this script is located so we can invoke the script from
|
||||
# any directory and have the paths work correctly.
|
||||
script_path = Path(__file__).parent.resolve()
|
||||
|
||||
# Get the root path as an absolute path, so all derived paths are absolute.
|
||||
root_path = script_path.parent.absolute()
|
||||
|
||||
# Get the location of the flatc executable, reading from the first command line
|
||||
# argument or defaulting to default names.
|
||||
flatc_exe = Path(
|
||||
("flatc" if not platform.system() == "Windows" else "flatc.exe")
|
||||
if not args.flatc
|
||||
else args.flatc
|
||||
)
|
||||
|
||||
# Find and assert flatc compiler is present.
|
||||
if root_path in flatc_exe.parents:
|
||||
flatc_exe = flatc_exe.relative_to(root_path)
|
||||
flatc_path = Path(root_path, flatc_exe)
|
||||
assert flatc_path.exists(), "Cannot find the flatc compiler " + str(flatc_path)
|
||||
from util import flatc, root_path, tests_path, args, flatc_path
|
||||
|
||||
# Specify the other paths that will be referenced
|
||||
tests_path = Path(root_path, "tests")
|
||||
swift_code_gen = Path(root_path, "tests/swift/tests/CodeGenerationTests")
|
||||
ts_code_gen = Path(root_path, "tests/ts")
|
||||
samples_path = Path(root_path, "samples")
|
||||
reflection_path = Path(root_path, "reflection")
|
||||
|
||||
# Execute the flatc compiler with the specified parameters
|
||||
def flatc(options, schema, prefix=None, include=None, data=None, cwd=tests_path):
|
||||
cmd = [str(flatc_path)] + options
|
||||
if prefix:
|
||||
cmd += ["-o"] + [prefix]
|
||||
if include:
|
||||
cmd += ["-I"] + [include]
|
||||
cmd += [schema] if isinstance(schema, str) else schema
|
||||
if data:
|
||||
cmd += [data] if isinstance(data, str) else data
|
||||
result = subprocess.run(cmd, cwd=str(cwd), check=True)
|
||||
|
||||
|
||||
# Generate the code for flatbuffers reflection schema
|
||||
def flatc_reflection(options, location, target):
|
||||
full_options = ["--no-prefix"] + options
|
||||
@@ -150,7 +97,7 @@ SWIFT_OPTS_CODE_GEN = [
|
||||
"--swift",
|
||||
"--gen-json-emit",
|
||||
"--bfbs-filenames",
|
||||
swift_code_gen
|
||||
str(swift_code_gen)
|
||||
]
|
||||
JAVA_OPTS = ["--java"]
|
||||
KOTLIN_OPTS = ["--kotlin"]
|
||||
@@ -158,6 +105,7 @@ PHP_OPTS = ["--php"]
|
||||
DART_OPTS = ["--dart"]
|
||||
PYTHON_OPTS = ["--python"]
|
||||
BINARY_OPTS = ["-b", "--schema", "--bfbs-comments", "--bfbs-builtins"]
|
||||
PROTO_OPTS = ["--proto"]
|
||||
|
||||
# Basic Usage
|
||||
|
||||
@@ -196,10 +144,10 @@ flatc(
|
||||
flatc(
|
||||
NO_INCL_OPTS
|
||||
+ TS_OPTS,
|
||||
schema="monster_test.fbs",
|
||||
prefix="ts",
|
||||
include="include_test",
|
||||
data="monsterdata_test.json",
|
||||
cwd=ts_code_gen,
|
||||
schema="../monster_test.fbs",
|
||||
include="../include_test",
|
||||
data="../monsterdata_test.json",
|
||||
)
|
||||
|
||||
flatc(
|
||||
@@ -245,6 +193,11 @@ flatc(
|
||||
data="monsterdata_test.json",
|
||||
)
|
||||
|
||||
flatc(
|
||||
PROTO_OPTS,
|
||||
schema="prototest/test.proto",
|
||||
)
|
||||
|
||||
# For Rust we currently generate two independent schemas, with namespace_test2
|
||||
# duplicating the types in namespace_test1
|
||||
flatc(
|
||||
@@ -264,37 +217,31 @@ flatc(
|
||||
|
||||
flatc(
|
||||
BASE_OPTS + TS_OPTS,
|
||||
prefix="ts/union_vector",
|
||||
schema="union_vector/union_vector.fbs",
|
||||
cwd=ts_code_gen,
|
||||
prefix="union_vector",
|
||||
schema="../union_vector/union_vector.fbs",
|
||||
)
|
||||
|
||||
flatc(
|
||||
BASE_OPTS + TS_OPTS + ["--gen-name-strings", "--gen-mutable"],
|
||||
include="include_test",
|
||||
prefix="ts",
|
||||
schema="monster_test.fbs",
|
||||
)
|
||||
|
||||
# Generate the complete flat file TS of monster.
|
||||
flatc(
|
||||
["--ts", "--gen-all", "--ts-flat-files"],
|
||||
include="include_test",
|
||||
schema="monster_test.fbs",
|
||||
prefix="ts/ts-flat-files"
|
||||
cwd=ts_code_gen,
|
||||
include="../include_test",
|
||||
schema="../monster_test.fbs",
|
||||
)
|
||||
|
||||
flatc(
|
||||
BASE_OPTS + TS_OPTS + ["-b"],
|
||||
include="include_test",
|
||||
prefix="ts",
|
||||
schema="monster_test.fbs",
|
||||
data="unicode_test.json",
|
||||
cwd=ts_code_gen,
|
||||
include="../include_test",
|
||||
schema="../monster_test.fbs",
|
||||
data="../unicode_test.json",
|
||||
)
|
||||
|
||||
flatc(
|
||||
BASE_OPTS + TS_OPTS + ["--gen-name-strings"],
|
||||
prefix="ts/union_vector",
|
||||
schema="union_vector/union_vector.fbs",
|
||||
cwd=ts_code_gen,
|
||||
prefix="union_vector",
|
||||
schema="../union_vector/union_vector.fbs",
|
||||
)
|
||||
|
||||
flatc(
|
||||
@@ -394,7 +341,7 @@ flatc(
|
||||
# Optional Scalars
|
||||
optional_scalars_schema = "optional_scalars.fbs"
|
||||
flatc(["--java", "--kotlin", "--lobster"], schema=optional_scalars_schema)
|
||||
flatc(TS_OPTS, schema=optional_scalars_schema, prefix="ts")
|
||||
flatc(TS_OPTS, cwd=ts_code_gen, schema="../optional_scalars.fbs")
|
||||
|
||||
flatc(["--csharp", "--python", "--gen-object-api"], schema=optional_scalars_schema)
|
||||
|
||||
@@ -407,6 +354,13 @@ type_field_collsion_schema = "type_field_collsion.fbs"
|
||||
|
||||
flatc(["--csharp", "--gen-object-api"], schema=type_field_collsion_schema)
|
||||
|
||||
# Union / value collision
|
||||
flatc(
|
||||
CS_OPTS + ["--gen-object-api", "--gen-onefile"],
|
||||
prefix="union_value_collsion",
|
||||
schema="union_value_collision.fbs"
|
||||
)
|
||||
|
||||
# Generate string/vector default code for tests
|
||||
flatc(RUST_OPTS, prefix="more_defaults", schema="more_defaults.fbs")
|
||||
|
||||
@@ -470,6 +424,15 @@ flatc(
|
||||
cwd=swift_code_gen
|
||||
)
|
||||
|
||||
# Swift Wasm Tests
|
||||
swift_Wasm_prefix = "swift/Wasm.tests/Tests/FlatBuffers.Test.Swift.WasmTests"
|
||||
flatc(
|
||||
SWIFT_OPTS + BASE_OPTS,
|
||||
schema="monster_test.fbs",
|
||||
include="include_test",
|
||||
prefix=swift_Wasm_prefix,
|
||||
)
|
||||
|
||||
# Nim Tests
|
||||
NIM_OPTS = BASE_OPTS + ["--nim"]
|
||||
flatc(NIM_OPTS, schema="monster_test.fbs", include="include_test")
|
||||
@@ -544,6 +507,12 @@ if not args.skip_gen_reflection:
|
||||
# Python Reflection
|
||||
flatc_reflection(["-p"], "python/flatbuffers", "reflection")
|
||||
|
||||
# Java Reflection
|
||||
flatc_reflection(
|
||||
["-j", "--java-package-prefix", "com.google.flatbuffers"],
|
||||
"java/src/main/java", "com/google/flatbuffers/reflection"
|
||||
)
|
||||
|
||||
# Annotation
|
||||
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@ from pathlib import Path
|
||||
|
||||
grpc_examples_path = Path(root_path, "grpc/examples")
|
||||
|
||||
greeter_schema = Path(grpc_examples_path, "greeter.fbs")
|
||||
greeter_schema = str(Path(grpc_examples_path, "greeter.fbs"))
|
||||
|
||||
COMMON_ARGS = [
|
||||
"--grpc",
|
||||
|
||||
@@ -12,20 +12,44 @@
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
import argparse
|
||||
import platform
|
||||
import subprocess
|
||||
from pathlib import Path
|
||||
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument(
|
||||
"--flatc",
|
||||
help="path of the Flat C compiler relative to the root directory",
|
||||
)
|
||||
parser.add_argument("--cpp-0x", action="store_true", help="use --cpp-std c++ox")
|
||||
parser.add_argument(
|
||||
"--skip-monster-extra",
|
||||
action="store_true",
|
||||
help="skip generating tests involving monster_extra.fbs",
|
||||
)
|
||||
parser.add_argument(
|
||||
"--skip-gen-reflection",
|
||||
action="store_true",
|
||||
help="skip generating the reflection.fbs files",
|
||||
)
|
||||
args = parser.parse_args()
|
||||
|
||||
# Get the path where this script is located so we can invoke the script from
|
||||
# any directory and have the paths work correctly.
|
||||
script_path = Path(__file__).parent.resolve()
|
||||
|
||||
# Get the root path as an absolute path, so all derived paths are absolute.
|
||||
root_path = script_path.parent.absolute()
|
||||
tests_path = Path(root_path, "tests")
|
||||
|
||||
# Get the location of the flatc executable, reading from the first command line
|
||||
# argument or defaulting to default names.
|
||||
flatc_exe = Path("flatc" if not platform.system() == "Windows" else "flatc.exe")
|
||||
flatc_exe = Path(
|
||||
("flatc" if not platform.system() == "Windows" else "flatc.exe")
|
||||
if not args.flatc
|
||||
else args.flatc
|
||||
)
|
||||
|
||||
# Find and assert flatc compiler is present.
|
||||
if root_path in flatc_exe.parents:
|
||||
@@ -34,18 +58,13 @@ flatc_path = Path(root_path, flatc_exe)
|
||||
assert flatc_path.exists(), "Cannot find the flatc compiler " + str(flatc_path)
|
||||
|
||||
# Execute the flatc compiler with the specified parameters
|
||||
def flatc(options, schema, prefix=None, include=None, data=None, cwd=root_path):
|
||||
def flatc(options, schema, prefix=None, include=None, data=None, cwd=tests_path):
|
||||
cmd = [str(flatc_path)] + options
|
||||
if prefix:
|
||||
cmd += ["-o"] + [prefix]
|
||||
if include:
|
||||
cmd += ["-I"] + [include]
|
||||
if isinstance(schema, Path):
|
||||
cmd += [str(schema)]
|
||||
elif isinstance(schema, str):
|
||||
cmd += [schema]
|
||||
else:
|
||||
cmd += schema
|
||||
cmd += [schema] if isinstance(schema, str) else schema
|
||||
if data:
|
||||
cmd += [data] if isinstance(data, str) else data
|
||||
return subprocess.check_call(cmd, cwd=str(cwd))
|
||||
result = subprocess.run(cmd, cwd=str(cwd), check=True)
|
||||
|
||||
@@ -11,7 +11,9 @@ cc_library(
|
||||
srcs = [
|
||||
"code_generators.cpp",
|
||||
"idl_gen_fbs.cpp",
|
||||
"idl_gen_fbs.h",
|
||||
"idl_gen_text.cpp",
|
||||
"idl_gen_text.h",
|
||||
"idl_parser.cpp",
|
||||
"reflection.cpp",
|
||||
"util.cpp",
|
||||
@@ -68,22 +70,39 @@ cc_library(
|
||||
"bfbs_gen_nim.h",
|
||||
"bfbs_namer.h",
|
||||
"flatc_main.cpp",
|
||||
"idl_gen_binary.cpp",
|
||||
"idl_gen_binary.h",
|
||||
"idl_gen_cpp.cpp",
|
||||
"idl_gen_cpp.h",
|
||||
"idl_gen_csharp.cpp",
|
||||
"idl_gen_csharp.h",
|
||||
"idl_gen_dart.cpp",
|
||||
"idl_gen_dart.h",
|
||||
"idl_gen_go.cpp",
|
||||
"idl_gen_go.h",
|
||||
"idl_gen_grpc.cpp",
|
||||
"idl_gen_java.cpp",
|
||||
"idl_gen_java.h",
|
||||
"idl_gen_json_schema.cpp",
|
||||
"idl_gen_json_schema.h",
|
||||
"idl_gen_kotlin.cpp",
|
||||
"idl_gen_kotlin.h",
|
||||
"idl_gen_lobster.cpp",
|
||||
"idl_gen_lobster.h",
|
||||
"idl_gen_lua.cpp",
|
||||
"idl_gen_lua.h",
|
||||
"idl_gen_php.cpp",
|
||||
"idl_gen_php.h",
|
||||
"idl_gen_python.cpp",
|
||||
"idl_gen_python.h",
|
||||
"idl_gen_rust.cpp",
|
||||
"idl_gen_rust.h",
|
||||
"idl_gen_swift.cpp",
|
||||
"idl_gen_swift.h",
|
||||
"idl_gen_text.cpp",
|
||||
"idl_gen_text.h",
|
||||
"idl_gen_ts.cpp",
|
||||
"idl_gen_ts.h",
|
||||
"idl_namer.h",
|
||||
"namer.h",
|
||||
"util.cpp",
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
#include "annotated_binary_text_gen.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <fstream>
|
||||
#include <ostream>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
|
||||
@@ -21,6 +23,8 @@ struct OutputConfig {
|
||||
size_t offset_max_char = 4;
|
||||
|
||||
char delimiter = '|';
|
||||
|
||||
bool include_vector_contents = true;
|
||||
};
|
||||
|
||||
static std::string ToString(const BinarySectionType type) {
|
||||
@@ -83,7 +87,7 @@ static std::string ToValueString(const BinaryRegion ®ion,
|
||||
if (region.array_length) {
|
||||
if (region.type == BinaryRegionType::Uint8 ||
|
||||
region.type == BinaryRegionType::Unknown) {
|
||||
// Interpet each value as a ASCII to aid debugging
|
||||
// Interpret each value as a ASCII to aid debugging
|
||||
for (uint64_t i = 0; i < region.array_length; ++i) {
|
||||
const uint8_t c = *(binary + region.offset + i);
|
||||
s += isprint(c) ? static_cast<char>(c & 0x7F) : '.';
|
||||
@@ -131,7 +135,7 @@ static std::string ToValueString(const BinaryRegion ®ion,
|
||||
// value.
|
||||
// TODO(dbaileychess): It might be nicer to put this in the comment field.
|
||||
if (IsOffset(region.type)) {
|
||||
s += " Loc: +0x";
|
||||
s += " Loc: 0x";
|
||||
s += ToHex(region.points_to_offset, output_config.offset_max_char);
|
||||
}
|
||||
return s;
|
||||
@@ -257,84 +261,74 @@ static std::string GenerateComment(const BinaryRegionComment &comment,
|
||||
return s;
|
||||
}
|
||||
|
||||
static std::string GenerateDocumentation(const BinaryRegion ®ion,
|
||||
const BinarySection §ion,
|
||||
const uint8_t *binary,
|
||||
DocContinuation &continuation,
|
||||
const OutputConfig &output_config) {
|
||||
std::string s;
|
||||
|
||||
static void GenerateDocumentation(std::ostream &os, const BinaryRegion ®ion,
|
||||
const BinarySection §ion,
|
||||
const uint8_t *binary,
|
||||
DocContinuation &continuation,
|
||||
const OutputConfig &output_config) {
|
||||
// Check if there is a doc continuation that should be prioritized.
|
||||
if (continuation.value_start_column) {
|
||||
s += std::string(continuation.value_start_column - 2, ' ');
|
||||
s += output_config.delimiter;
|
||||
s += " ";
|
||||
os << std::string(continuation.value_start_column - 2, ' ');
|
||||
os << output_config.delimiter << " ";
|
||||
|
||||
s += continuation.value.substr(0, output_config.max_bytes_per_line);
|
||||
os << continuation.value.substr(0, output_config.max_bytes_per_line);
|
||||
continuation.value = continuation.value.substr(
|
||||
std::min(output_config.max_bytes_per_line, continuation.value.size()));
|
||||
return s;
|
||||
return;
|
||||
}
|
||||
|
||||
size_t size_of = 0;
|
||||
{
|
||||
std::stringstream ss;
|
||||
ss << std::setw(output_config.largest_type_string) << std::left;
|
||||
ss << std::setw(static_cast<int>(output_config.largest_type_string))
|
||||
<< std::left;
|
||||
ss << GenerateTypeString(region);
|
||||
s += ss.str();
|
||||
os << ss.str();
|
||||
size_of = ss.str().size();
|
||||
}
|
||||
s += " ";
|
||||
s += output_config.delimiter;
|
||||
s += " ";
|
||||
os << " " << output_config.delimiter << " ";
|
||||
if (region.array_length) {
|
||||
// Record where the value is first being outputted.
|
||||
continuation.value_start_column = s.size();
|
||||
continuation.value_start_column = 3 + size_of;
|
||||
|
||||
// Get the full-length value, which we will chunk below.
|
||||
const std::string value = ToValueString(region, binary, output_config);
|
||||
|
||||
std::stringstream ss;
|
||||
ss << std::setw(output_config.largest_value_string) << std::left;
|
||||
ss << std::setw(static_cast<int>(output_config.largest_value_string))
|
||||
<< std::left;
|
||||
ss << value.substr(0, output_config.max_bytes_per_line);
|
||||
s += ss.str();
|
||||
os << ss.str();
|
||||
|
||||
continuation.value =
|
||||
value.substr(std::min(output_config.max_bytes_per_line, value.size()));
|
||||
} else {
|
||||
std::stringstream ss;
|
||||
ss << std::setw(output_config.largest_value_string) << std::left;
|
||||
ss << std::setw(static_cast<int>(output_config.largest_value_string))
|
||||
<< std::left;
|
||||
ss << ToValueString(region, binary, output_config);
|
||||
s += ss.str();
|
||||
os << ss.str();
|
||||
}
|
||||
|
||||
s += " ";
|
||||
s += output_config.delimiter;
|
||||
s += " ";
|
||||
s += GenerateComment(region.comment, section);
|
||||
|
||||
return s;
|
||||
os << " " << output_config.delimiter << " ";
|
||||
os << GenerateComment(region.comment, section);
|
||||
}
|
||||
|
||||
static std::string GenerateRegion(const BinaryRegion ®ion,
|
||||
const BinarySection §ion,
|
||||
const uint8_t *binary,
|
||||
const OutputConfig &output_config) {
|
||||
std::string s;
|
||||
static void GenerateRegion(std::ostream &os, const BinaryRegion ®ion,
|
||||
const BinarySection §ion, const uint8_t *binary,
|
||||
const OutputConfig &output_config) {
|
||||
bool doc_generated = false;
|
||||
DocContinuation doc_continuation;
|
||||
for (uint64_t i = 0; i < region.length; ++i) {
|
||||
if ((i % output_config.max_bytes_per_line) == 0) {
|
||||
// Start a new line of output
|
||||
s += '\n';
|
||||
s += " ";
|
||||
s += "+0x";
|
||||
s += ToHex(region.offset + i, output_config.offset_max_char);
|
||||
s += " ";
|
||||
s += output_config.delimiter;
|
||||
os << std::endl;
|
||||
os << " +0x" << ToHex(region.offset + i, output_config.offset_max_char);
|
||||
os << " " << output_config.delimiter;
|
||||
}
|
||||
|
||||
// Add each byte
|
||||
s += " ";
|
||||
s += ToHex(binary[region.offset + i]);
|
||||
os << " " << ToHex(binary[region.offset + i]);
|
||||
|
||||
// Check for end of line or end of region conditions.
|
||||
if (((i + 1) % output_config.max_bytes_per_line == 0) ||
|
||||
@@ -344,17 +338,16 @@ static std::string GenerateRegion(const BinaryRegion ®ion,
|
||||
// zero those out to align everything globally.
|
||||
for (uint64_t j = i + 1; (j % output_config.max_bytes_per_line) != 0;
|
||||
++j) {
|
||||
s += " ";
|
||||
os << " ";
|
||||
}
|
||||
}
|
||||
s += " ";
|
||||
s += output_config.delimiter;
|
||||
os << " " << output_config.delimiter;
|
||||
// This is the end of the first line or its the last byte of the region,
|
||||
// generate the end-of-line documentation.
|
||||
if (!doc_generated) {
|
||||
s += " ";
|
||||
s += GenerateDocumentation(region, section, binary, doc_continuation,
|
||||
output_config);
|
||||
os << " ";
|
||||
GenerateDocumentation(os, region, section, binary, doc_continuation,
|
||||
output_config);
|
||||
|
||||
// If we have a value in the doc continuation, that means the doc is
|
||||
// being printed on multiple lines.
|
||||
@@ -362,22 +355,41 @@ static std::string GenerateRegion(const BinaryRegion ®ion,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
static std::string GenerateSection(const BinarySection §ion,
|
||||
const uint8_t *binary,
|
||||
const OutputConfig &output_config) {
|
||||
std::string s;
|
||||
s += "\n";
|
||||
s += ToString(section.type);
|
||||
if (!section.name.empty()) { s += " (" + section.name + ")"; }
|
||||
s += ":";
|
||||
for (const BinaryRegion ®ion : section.regions) {
|
||||
s += GenerateRegion(region, section, binary, output_config);
|
||||
static void GenerateSection(std::ostream &os, const BinarySection §ion,
|
||||
const uint8_t *binary,
|
||||
const OutputConfig &output_config) {
|
||||
os << std::endl;
|
||||
os << ToString(section.type);
|
||||
if (!section.name.empty()) { os << " (" + section.name + ")"; }
|
||||
os << ":";
|
||||
|
||||
// As a space saving measure, skip generating every vector element, just put
|
||||
// the first and last elements in the output. Skip the whole thing if there
|
||||
// are only three or fewer elements, as it doesn't save space.
|
||||
if (section.type == BinarySectionType::Vector &&
|
||||
!output_config.include_vector_contents && section.regions.size() > 4) {
|
||||
// Generate the length region which should be first.
|
||||
GenerateRegion(os, section.regions[0], section, binary, output_config);
|
||||
|
||||
// Generate the first element.
|
||||
GenerateRegion(os, section.regions[1], section, binary, output_config);
|
||||
|
||||
// Indicate that we omitted elements.
|
||||
os << std::endl
|
||||
<< " <" << section.regions.size() - 3 << " regions omitted>";
|
||||
|
||||
// Generate the last element.
|
||||
GenerateRegion(os, section.regions.back(), section, binary, output_config);
|
||||
os << std::endl;
|
||||
return;
|
||||
}
|
||||
return s;
|
||||
|
||||
for (const BinaryRegion ®ion : section.regions) {
|
||||
GenerateRegion(os, region, section, binary, output_config);
|
||||
}
|
||||
os << std::endl;
|
||||
}
|
||||
} // namespace
|
||||
|
||||
@@ -385,6 +397,7 @@ bool AnnotatedBinaryTextGenerator::Generate(
|
||||
const std::string &filename, const std::string &schema_filename) {
|
||||
OutputConfig output_config;
|
||||
output_config.max_bytes_per_line = options_.max_bytes_per_line;
|
||||
output_config.include_vector_contents = options_.include_vector_contents;
|
||||
|
||||
// Given the length of the binary, we can calculate the maximum number of
|
||||
// characters to display in the offset hex: (i.e. 2 would lead to 0XFF being
|
||||
@@ -414,19 +427,6 @@ bool AnnotatedBinaryTextGenerator::Generate(
|
||||
}
|
||||
}
|
||||
|
||||
// Generate each of the binary sections
|
||||
std::string s;
|
||||
|
||||
s += "// Annotated Flatbuffer Binary\n";
|
||||
s += "//\n";
|
||||
s += "// Schema file: " + schema_filename + "\n";
|
||||
s += "// Binary file: " + filename + "\n";
|
||||
|
||||
for (const auto §ion : annotations_) {
|
||||
s += GenerateSection(section.second, binary_, output_config);
|
||||
s += "\n";
|
||||
}
|
||||
|
||||
// Modify the output filename.
|
||||
std::string output_filename = StripExtension(filename);
|
||||
output_filename += options_.output_postfix;
|
||||
@@ -434,7 +434,20 @@ bool AnnotatedBinaryTextGenerator::Generate(
|
||||
"." + (options_.output_extension.empty() ? GetExtension(filename)
|
||||
: options_.output_extension);
|
||||
|
||||
return SaveFile(output_filename.c_str(), s, false);
|
||||
std::ofstream ofs(output_filename.c_str());
|
||||
|
||||
ofs << "// Annotated Flatbuffer Binary" << std::endl;
|
||||
ofs << "//" << std::endl;
|
||||
ofs << "// Schema file: " << schema_filename << std::endl;
|
||||
ofs << "// Binary file: " << filename << std::endl;
|
||||
|
||||
// Generate each of the binary sections
|
||||
for (const auto §ion : annotations_) {
|
||||
GenerateSection(ofs, section.second, binary_, output_config);
|
||||
}
|
||||
|
||||
ofs.close();
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace flatbuffers
|
||||
|
||||
@@ -41,6 +41,9 @@ class AnnotatedBinaryTextGenerator {
|
||||
//
|
||||
// Example: binary1.bin -> binary1.afb
|
||||
std::string output_extension = "afb";
|
||||
|
||||
// Controls.
|
||||
bool include_vector_contents = true;
|
||||
};
|
||||
|
||||
explicit AnnotatedBinaryTextGenerator(
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
#include "flatbuffers/bfbs_generator.h"
|
||||
#include "flatbuffers/code_generator.h"
|
||||
#include "flatbuffers/reflection_generated.h"
|
||||
|
||||
namespace flatbuffers {
|
||||
@@ -96,20 +96,19 @@ static bool IsVector(const reflection::BaseType base_type) {
|
||||
|
||||
// A concrete base Flatbuffer Generator that specific language generators can
|
||||
// derive from.
|
||||
class BaseBfbsGenerator : public BfbsGenerator {
|
||||
class BaseBfbsGenerator : public CodeGenerator {
|
||||
public:
|
||||
virtual ~BaseBfbsGenerator() {}
|
||||
BaseBfbsGenerator() : schema_(nullptr) {}
|
||||
|
||||
virtual GeneratorStatus GenerateFromSchema(
|
||||
virtual Status GenerateFromSchema(
|
||||
const reflection::Schema *schema) = 0;
|
||||
|
||||
//
|
||||
virtual uint64_t SupportedAdvancedFeatures() const = 0;
|
||||
|
||||
// Override of the Generator::generate method that does the initial
|
||||
// Override of the Generator::GenerateCode method that does the initial
|
||||
// deserialization and verification steps.
|
||||
GeneratorStatus Generate(const uint8_t *buffer,
|
||||
Status GenerateCode(const uint8_t *buffer,
|
||||
int64_t length) FLATBUFFERS_OVERRIDE {
|
||||
flatbuffers::Verifier verifier(buffer, static_cast<size_t>(length));
|
||||
if (!reflection::VerifySchemaBuffer(verifier)) {
|
||||
@@ -125,7 +124,7 @@ class BaseBfbsGenerator : public BfbsGenerator {
|
||||
return FAILED_VERIFICATION;
|
||||
}
|
||||
|
||||
GeneratorStatus status = GenerateFromSchema(schema_);
|
||||
Status status = GenerateFromSchema(schema_);
|
||||
schema_ = nullptr;
|
||||
return status;
|
||||
}
|
||||
|
||||
@@ -26,7 +26,6 @@
|
||||
// Ensure no includes to flatc internals. bfbs_gen.h and generator.h are OK.
|
||||
#include "bfbs_gen.h"
|
||||
#include "bfbs_namer.h"
|
||||
#include "flatbuffers/bfbs_generator.h"
|
||||
|
||||
// The intermediate representation schema.
|
||||
#include "flatbuffers/reflection.h"
|
||||
@@ -79,15 +78,57 @@ class LuaBfbsGenerator : public BaseBfbsGenerator {
|
||||
flatc_version_(flatc_version),
|
||||
namer_(LuaDefaultConfig(), LuaKeywords()) {}
|
||||
|
||||
GeneratorStatus GenerateFromSchema(const r::Schema *schema)
|
||||
FLATBUFFERS_OVERRIDE {
|
||||
if (!GenerateEnums(schema->enums())) { return FAILED; }
|
||||
Status GenerateFromSchema(const r::Schema *schema) FLATBUFFERS_OVERRIDE {
|
||||
if (!GenerateEnums(schema->enums())) { return ERROR; }
|
||||
if (!GenerateObjects(schema->objects(), schema->root_table())) {
|
||||
return FAILED;
|
||||
return ERROR;
|
||||
}
|
||||
return OK;
|
||||
}
|
||||
|
||||
using BaseBfbsGenerator::GenerateCode;
|
||||
|
||||
Status GenerateCode(const Parser &parser, const std::string &path,
|
||||
const std::string &filename) FLATBUFFERS_OVERRIDE {
|
||||
if (!GenerateLua(parser, path, filename)) { return ERROR; }
|
||||
return OK;
|
||||
}
|
||||
|
||||
Status GenerateMakeRule(const Parser &parser, const std::string &path,
|
||||
const std::string &filename,
|
||||
std::string &output) override {
|
||||
(void)parser;
|
||||
(void)path;
|
||||
(void)filename;
|
||||
(void)output;
|
||||
return Status::NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
Status GenerateGrpcCode(const Parser &parser, const std::string &path,
|
||||
const std::string &filename) override {
|
||||
(void)parser;
|
||||
(void)path;
|
||||
(void)filename;
|
||||
return Status::NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
Status GenerateRootFile(const Parser &parser,
|
||||
const std::string &path) override {
|
||||
(void)parser;
|
||||
(void)path;
|
||||
return Status::NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
bool IsSchemaOnly() const override { return true; }
|
||||
|
||||
bool SupportsBfbsGeneration() const override { return true; }
|
||||
|
||||
bool SupportsRootFileGeneration() const override { return false; }
|
||||
|
||||
IDLOptions::Language Language() const override { return IDLOptions::kLua; }
|
||||
|
||||
std::string LanguageName() const override { return "Lua"; }
|
||||
|
||||
uint64_t SupportedAdvancedFeatures() const FLATBUFFERS_OVERRIDE {
|
||||
return 0xF;
|
||||
}
|
||||
@@ -625,7 +666,7 @@ class LuaBfbsGenerator : public BaseBfbsGenerator {
|
||||
};
|
||||
} // namespace
|
||||
|
||||
std::unique_ptr<BfbsGenerator> NewLuaBfbsGenerator(
|
||||
std::unique_ptr<CodeGenerator> NewLuaBfbsGenerator(
|
||||
const std::string &flatc_version) {
|
||||
return std::unique_ptr<LuaBfbsGenerator>(new LuaBfbsGenerator(flatc_version));
|
||||
}
|
||||
|
||||
@@ -20,12 +20,12 @@
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
#include "flatbuffers/bfbs_generator.h"
|
||||
#include "flatbuffers/code_generator.h"
|
||||
|
||||
namespace flatbuffers {
|
||||
|
||||
// Constructs a new Lua Code generator.
|
||||
std::unique_ptr<BfbsGenerator> NewLuaBfbsGenerator(
|
||||
std::unique_ptr<CodeGenerator> NewLuaBfbsGenerator(
|
||||
const std::string &flatc_version);
|
||||
|
||||
} // namespace flatbuffers
|
||||
|
||||
@@ -26,7 +26,6 @@
|
||||
// Ensure no includes to flatc internals. bfbs_gen.h and generator.h are OK.
|
||||
#include "bfbs_gen.h"
|
||||
#include "bfbs_namer.h"
|
||||
#include "flatbuffers/bfbs_generator.h"
|
||||
|
||||
// The intermediate representation schema.
|
||||
#include "flatbuffers/reflection.h"
|
||||
@@ -96,8 +95,7 @@ class NimBfbsGenerator : public BaseBfbsGenerator {
|
||||
flatc_version_(flatc_version),
|
||||
namer_(NimDefaultConfig(), NimKeywords()) {}
|
||||
|
||||
GeneratorStatus GenerateFromSchema(const r::Schema *schema)
|
||||
FLATBUFFERS_OVERRIDE {
|
||||
Status GenerateFromSchema(const r::Schema *schema) FLATBUFFERS_OVERRIDE {
|
||||
ForAllEnums(schema->enums(), [&](const r::Enum *enum_def) {
|
||||
StartCodeBlock(enum_def);
|
||||
GenerateEnum(enum_def);
|
||||
@@ -109,6 +107,51 @@ class NimBfbsGenerator : public BaseBfbsGenerator {
|
||||
return OK;
|
||||
}
|
||||
|
||||
using BaseBfbsGenerator::GenerateCode;
|
||||
|
||||
Status GenerateCode(const Parser &parser, const std::string &path,
|
||||
const std::string &filename) override {
|
||||
(void)parser;
|
||||
(void)path;
|
||||
(void)filename;
|
||||
return NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
Status GenerateMakeRule(const Parser &parser, const std::string &path,
|
||||
const std::string &filename,
|
||||
std::string &output) override {
|
||||
(void)parser;
|
||||
(void)path;
|
||||
(void)filename;
|
||||
(void)output;
|
||||
return NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
Status GenerateGrpcCode(const Parser &parser, const std::string &path,
|
||||
const std::string &filename) override {
|
||||
(void)parser;
|
||||
(void)path;
|
||||
(void)filename;
|
||||
return NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
Status GenerateRootFile(const Parser &parser,
|
||||
const std::string &path) override {
|
||||
(void)parser;
|
||||
(void)path;
|
||||
return NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
bool IsSchemaOnly() const override { return true; }
|
||||
|
||||
bool SupportsBfbsGeneration() const override { return true; }
|
||||
|
||||
bool SupportsRootFileGeneration() const override { return false; }
|
||||
|
||||
IDLOptions::Language Language() const override { return IDLOptions::kNim; }
|
||||
|
||||
std::string LanguageName() const override { return "Nim"; }
|
||||
|
||||
uint64_t SupportedAdvancedFeatures() const FLATBUFFERS_OVERRIDE {
|
||||
return r::AdvancedArrayFeatures | r::AdvancedUnionFeatures |
|
||||
r::OptionalScalars | r::DefaultVectorsAndStrings;
|
||||
@@ -472,9 +515,11 @@ class NimBfbsGenerator : public BaseBfbsGenerator {
|
||||
if (IsFloatingPoint(base_type)) {
|
||||
if (field->default_real() != field->default_real()) {
|
||||
return "NaN";
|
||||
} else if (field->default_real() == std::numeric_limits<double>::infinity()) {
|
||||
} else if (field->default_real() ==
|
||||
std::numeric_limits<double>::infinity()) {
|
||||
return "Inf";
|
||||
} else if (field->default_real() == -std::numeric_limits<double>::infinity()) {
|
||||
} else if (field->default_real() ==
|
||||
-std::numeric_limits<double>::infinity()) {
|
||||
return "-Inf";
|
||||
}
|
||||
return NumToString(field->default_real());
|
||||
@@ -639,7 +684,7 @@ class NimBfbsGenerator : public BaseBfbsGenerator {
|
||||
};
|
||||
} // namespace
|
||||
|
||||
std::unique_ptr<BfbsGenerator> NewNimBfbsGenerator(
|
||||
std::unique_ptr<CodeGenerator> NewNimBfbsGenerator(
|
||||
const std::string &flatc_version) {
|
||||
return std::unique_ptr<NimBfbsGenerator>(new NimBfbsGenerator(flatc_version));
|
||||
}
|
||||
|
||||
@@ -20,12 +20,12 @@
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
#include "flatbuffers/bfbs_generator.h"
|
||||
#include "flatbuffers/code_generator.h"
|
||||
|
||||
namespace flatbuffers {
|
||||
|
||||
// Constructs a new Nim Code generator.
|
||||
std::unique_ptr<BfbsGenerator> NewNimBfbsGenerator(
|
||||
std::unique_ptr<CodeGenerator> NewNimBfbsGenerator(
|
||||
const std::string &flatc_version);
|
||||
|
||||
} // namespace flatbuffers
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
#include <vector>
|
||||
|
||||
#include "flatbuffers/reflection.h"
|
||||
#include "flatbuffers/util.h"
|
||||
#include "flatbuffers/verifier.h"
|
||||
|
||||
namespace flatbuffers {
|
||||
@@ -195,14 +196,22 @@ uint64_t BinaryAnnotator::BuildHeader(const uint64_t header_offset) {
|
||||
return root_table_offset.value();
|
||||
}
|
||||
|
||||
void BinaryAnnotator::BuildVTable(const uint64_t vtable_offset,
|
||||
const reflection::Object *const table,
|
||||
const uint64_t offset_of_referring_table) {
|
||||
// First see if we have used this vtable before, if so skip building it again.
|
||||
auto it = vtables_.find(vtable_offset);
|
||||
if (it != vtables_.end()) { return; }
|
||||
BinaryAnnotator::VTable *BinaryAnnotator::GetOrBuildVTable(
|
||||
const uint64_t vtable_offset, const reflection::Object *const table,
|
||||
const uint64_t offset_of_referring_table) {
|
||||
// Get a list of vtables (if any) already defined at this offset.
|
||||
std::list<VTable> &vtables = vtables_[vtable_offset];
|
||||
|
||||
if (ContainsSection(vtable_offset)) { return; }
|
||||
// See if this vtable for the table type has been generated before.
|
||||
for (VTable &vtable : vtables) {
|
||||
if (vtable.referring_table == table) { return &vtable; }
|
||||
}
|
||||
|
||||
// If we are trying to make a new vtable and it is already encompassed by
|
||||
// another binary section, something is corrupted.
|
||||
if (vtables.empty() && ContainsSection(vtable_offset)) { return nullptr; }
|
||||
|
||||
const std::string referring_table_name = table->name()->str();
|
||||
|
||||
BinaryRegionComment vtable_size_comment;
|
||||
vtable_size_comment.type = BinaryRegionCommentType::VTableSize;
|
||||
@@ -216,11 +225,11 @@ void BinaryAnnotator::BuildVTable(const uint64_t vtable_offset,
|
||||
|
||||
AddSection(vtable_offset,
|
||||
MakeSingleRegionBinarySection(
|
||||
table->name()->str(), BinarySectionType::VTable,
|
||||
referring_table_name, BinarySectionType::VTable,
|
||||
MakeBinaryRegion(vtable_offset, remaining,
|
||||
BinaryRegionType::Unknown, remaining, 0,
|
||||
vtable_size_comment)));
|
||||
return;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// Vtables start with the size of the vtable
|
||||
@@ -231,23 +240,23 @@ void BinaryAnnotator::BuildVTable(const uint64_t vtable_offset,
|
||||
// The vtable_size points to off the end of the binary.
|
||||
AddSection(vtable_offset,
|
||||
MakeSingleRegionBinarySection(
|
||||
table->name()->str(), BinarySectionType::VTable,
|
||||
referring_table_name, BinarySectionType::VTable,
|
||||
MakeBinaryRegion(vtable_offset, sizeof(uint16_t),
|
||||
BinaryRegionType::Uint16, 0, 0,
|
||||
vtable_size_comment)));
|
||||
|
||||
return;
|
||||
return nullptr;
|
||||
} else if (vtable_size < 2 * sizeof(uint16_t)) {
|
||||
SetError(vtable_size_comment, BinaryRegionStatus::ERROR_LENGTH_TOO_SHORT,
|
||||
"4");
|
||||
// The size includes itself and the table size which are both uint16_t.
|
||||
AddSection(vtable_offset,
|
||||
MakeSingleRegionBinarySection(
|
||||
table->name()->str(), BinarySectionType::VTable,
|
||||
referring_table_name, BinarySectionType::VTable,
|
||||
MakeBinaryRegion(vtable_offset, sizeof(uint16_t),
|
||||
BinaryRegionType::Uint16, 0, 0,
|
||||
vtable_size_comment)));
|
||||
return;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
std::vector<BinaryRegion> regions;
|
||||
@@ -271,11 +280,11 @@ void BinaryAnnotator::BuildVTable(const uint64_t vtable_offset,
|
||||
"2");
|
||||
|
||||
AddSection(offset, MakeSingleRegionBinarySection(
|
||||
table->name()->str(), BinarySectionType::VTable,
|
||||
referring_table_name, BinarySectionType::VTable,
|
||||
MakeBinaryRegion(
|
||||
offset, remaining, BinaryRegionType::Unknown,
|
||||
remaining, 0, ref_table_len_comment)));
|
||||
return;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// Then they have the size of the table they reference.
|
||||
@@ -394,7 +403,7 @@ void BinaryAnnotator::BuildVTable(const uint64_t vtable_offset,
|
||||
(vtable_size - sizeof(uint16_t) - sizeof(uint16_t)) / sizeof(uint16_t);
|
||||
|
||||
// Prevent a bad binary from declaring a really large vtable_size, that we can
|
||||
// not indpendently verify.
|
||||
// not independently verify.
|
||||
expectant_vtable_fields = std::min(
|
||||
static_cast<uint16_t>(fields_processed * 3), expectant_vtable_fields);
|
||||
|
||||
@@ -426,15 +435,26 @@ void BinaryAnnotator::BuildVTable(const uint64_t vtable_offset,
|
||||
field_comment));
|
||||
}
|
||||
|
||||
sections_[vtable_offset] = MakeBinarySection(
|
||||
table->name()->str(), BinarySectionType::VTable, std::move(regions));
|
||||
// If we have never added this vtable before record the Binary section.
|
||||
if (vtables.empty()) {
|
||||
sections_[vtable_offset] = MakeBinarySection(
|
||||
referring_table_name, BinarySectionType::VTable, std::move(regions));
|
||||
} else {
|
||||
// Add the current table name to the name of the section.
|
||||
sections_[vtable_offset].name += ", " + referring_table_name;
|
||||
}
|
||||
|
||||
VTable vtable;
|
||||
vtable.referring_table = table;
|
||||
vtable.fields = std::move(fields);
|
||||
vtable.table_size = table_size;
|
||||
vtable.vtable_size = vtable_size;
|
||||
|
||||
vtables_[vtable_offset] = vtable;
|
||||
// Add this vtable to the collection of vtables at this offset.
|
||||
vtables.push_back(std::move(vtable));
|
||||
|
||||
// Return the vtable we just added.
|
||||
return &vtables.back();
|
||||
}
|
||||
|
||||
void BinaryAnnotator::BuildTable(const uint64_t table_offset,
|
||||
@@ -490,19 +510,17 @@ void BinaryAnnotator::BuildTable(const uint64_t table_offset,
|
||||
|
||||
// Parse the vtable first so we know what the rest of the fields in the table
|
||||
// are.
|
||||
BuildVTable(vtable_offset, table, table_offset);
|
||||
const VTable *const vtable =
|
||||
GetOrBuildVTable(vtable_offset, table, table_offset);
|
||||
|
||||
auto vtable_entry = vtables_.find(vtable_offset);
|
||||
if (vtable_entry == vtables_.end()) {
|
||||
if (vtable == nullptr) {
|
||||
// There is no valid vtable for this table, so we cannot process the rest of
|
||||
// the table entries.
|
||||
return;
|
||||
}
|
||||
|
||||
const VTable &vtable = vtable_entry->second;
|
||||
|
||||
// This is the size and length of this table.
|
||||
const uint16_t table_size = vtable.table_size;
|
||||
const uint16_t table_size = vtable->table_size;
|
||||
uint64_t table_end_offset = table_offset + table_size;
|
||||
|
||||
if (!IsValidOffset(table_end_offset - 1)) {
|
||||
@@ -515,7 +533,7 @@ void BinaryAnnotator::BuildTable(const uint64_t table_offset,
|
||||
// not by their IDs. So copy them over to another vector that we can sort on
|
||||
// the offset_from_table property.
|
||||
std::vector<VTable::Entry> fields;
|
||||
for (const auto &vtable_field : vtable.fields) {
|
||||
for (const auto &vtable_field : vtable->fields) {
|
||||
fields.push_back(vtable_field.second);
|
||||
}
|
||||
|
||||
@@ -679,7 +697,8 @@ void BinaryAnnotator::BuildTable(const uint64_t table_offset,
|
||||
|
||||
if (next_object->is_struct()) {
|
||||
// Structs are stored inline.
|
||||
BuildStruct(field_offset, regions, next_object);
|
||||
BuildStruct(field_offset, regions, field->name()->c_str(),
|
||||
next_object);
|
||||
} else {
|
||||
offset_field_comment.default_value = "(table)";
|
||||
|
||||
@@ -705,7 +724,8 @@ void BinaryAnnotator::BuildTable(const uint64_t table_offset,
|
||||
regions.push_back(MakeBinaryRegion(
|
||||
field_offset, sizeof(uint32_t), BinaryRegionType::UOffset, 0,
|
||||
offset_of_next_item, offset_field_comment));
|
||||
BuildVector(offset_of_next_item, table, field, table_offset, vtable);
|
||||
BuildVector(offset_of_next_item, table, field, table_offset,
|
||||
vtable->fields);
|
||||
} break;
|
||||
|
||||
case reflection::BaseType::Union: {
|
||||
@@ -714,8 +734,8 @@ void BinaryAnnotator::BuildTable(const uint64_t table_offset,
|
||||
// The union type field is always one less than the union itself.
|
||||
const uint16_t union_type_id = field->id() - 1;
|
||||
|
||||
auto vtable_field = vtable.fields.find(union_type_id);
|
||||
if (vtable_field == vtable.fields.end()) {
|
||||
auto vtable_field = vtable->fields.find(union_type_id);
|
||||
if (vtable_field == vtable->fields.end()) {
|
||||
// TODO(dbaileychess): need to capture this error condition.
|
||||
break;
|
||||
}
|
||||
@@ -780,6 +800,7 @@ void BinaryAnnotator::BuildTable(const uint64_t table_offset,
|
||||
|
||||
uint64_t BinaryAnnotator::BuildStruct(const uint64_t struct_offset,
|
||||
std::vector<BinaryRegion> ®ions,
|
||||
const std::string referring_field_name,
|
||||
const reflection::Object *const object) {
|
||||
if (!object->is_struct()) { return struct_offset; }
|
||||
uint64_t offset = struct_offset;
|
||||
@@ -794,9 +815,8 @@ uint64_t BinaryAnnotator::BuildStruct(const uint64_t struct_offset,
|
||||
|
||||
BinaryRegionComment comment;
|
||||
comment.type = BinaryRegionCommentType::StructField;
|
||||
comment.name =
|
||||
std::string(object->name()->c_str()) + "." + field->name()->c_str();
|
||||
comment.default_value = "(" +
|
||||
comment.name = referring_field_name + "." + field->name()->str();
|
||||
comment.default_value = "of '" + object->name()->str() + "' (" +
|
||||
std::string(reflection::EnumNameBaseType(
|
||||
field->type()->base_type())) +
|
||||
")";
|
||||
@@ -821,6 +841,7 @@ uint64_t BinaryAnnotator::BuildStruct(const uint64_t struct_offset,
|
||||
} else if (field->type()->base_type() == reflection::BaseType::Obj) {
|
||||
// Structs are stored inline, even when nested.
|
||||
offset = BuildStruct(offset, regions,
|
||||
referring_field_name + "." + field->name()->str(),
|
||||
schema_->objects()->Get(field->type()->index()));
|
||||
} else if (field->type()->base_type() == reflection::BaseType::Array) {
|
||||
const bool is_scalar = IsScalar(field->type()->element());
|
||||
@@ -833,11 +854,11 @@ uint64_t BinaryAnnotator::BuildStruct(const uint64_t struct_offset,
|
||||
if (is_scalar) {
|
||||
BinaryRegionComment array_comment;
|
||||
array_comment.type = BinaryRegionCommentType::ArrayField;
|
||||
array_comment.name = std::string(object->name()->c_str()) + "." +
|
||||
field->name()->c_str();
|
||||
array_comment.name =
|
||||
referring_field_name + "." + field->name()->str();
|
||||
array_comment.index = i;
|
||||
array_comment.default_value =
|
||||
"(" +
|
||||
"of '" + object->name()->str() + "' (" +
|
||||
std::string(
|
||||
reflection::EnumNameBaseType(field->type()->element())) +
|
||||
")";
|
||||
@@ -869,8 +890,10 @@ uint64_t BinaryAnnotator::BuildStruct(const uint64_t struct_offset,
|
||||
// TODO(dbaileychess): This works, but the comments on the fields lose
|
||||
// some context. Need to figure a way how to plumb the nested arrays
|
||||
// comments together that isn't too confusing.
|
||||
offset = BuildStruct(offset, regions,
|
||||
schema_->objects()->Get(field->type()->index()));
|
||||
offset =
|
||||
BuildStruct(offset, regions,
|
||||
referring_field_name + "." + field->name()->str(),
|
||||
schema_->objects()->Get(field->type()->index()));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -954,11 +977,10 @@ void BinaryAnnotator::BuildString(const uint64_t string_offset,
|
||||
BinarySectionType::String, std::move(regions)));
|
||||
}
|
||||
|
||||
void BinaryAnnotator::BuildVector(const uint64_t vector_offset,
|
||||
const reflection::Object *const table,
|
||||
const reflection::Field *const field,
|
||||
const uint64_t parent_table_offset,
|
||||
const VTable &vtable) {
|
||||
void BinaryAnnotator::BuildVector(
|
||||
const uint64_t vector_offset, const reflection::Object *const table,
|
||||
const reflection::Field *const field, const uint64_t parent_table_offset,
|
||||
const std::map<uint16_t, VTable::Entry> vtable_fields) {
|
||||
if (ContainsSection(vector_offset)) { return; }
|
||||
|
||||
BinaryRegionComment vector_length_comment;
|
||||
@@ -1006,7 +1028,7 @@ void BinaryAnnotator::BuildVector(const uint64_t vector_offset,
|
||||
regions.push_back(MakeBinaryRegion(vector_offset, sizeof(uint32_t),
|
||||
BinaryRegionType::Uint32, 0, 0,
|
||||
vector_length_comment));
|
||||
|
||||
// Consume the vector length offset.
|
||||
uint64_t offset = vector_offset + sizeof(uint32_t);
|
||||
|
||||
switch (field->type()->element()) {
|
||||
@@ -1018,7 +1040,8 @@ void BinaryAnnotator::BuildVector(const uint64_t vector_offset,
|
||||
// Vector of structs
|
||||
for (size_t i = 0; i < vector_length.value(); ++i) {
|
||||
// Structs are inline to the vector.
|
||||
const uint64_t next_offset = BuildStruct(offset, regions, object);
|
||||
const uint64_t next_offset =
|
||||
BuildStruct(offset, regions, "[" + NumToString(i) + "]", object);
|
||||
if (next_offset == offset) { break; }
|
||||
offset = next_offset;
|
||||
}
|
||||
@@ -1073,6 +1096,7 @@ void BinaryAnnotator::BuildVector(const uint64_t vector_offset,
|
||||
offset, sizeof(uint32_t), BinaryRegionType::UOffset, 0,
|
||||
table_offset, vector_object_comment));
|
||||
|
||||
// Consume the offset to the table.
|
||||
offset += sizeof(uint32_t);
|
||||
|
||||
BuildTable(table_offset, BinarySectionType::Table, object);
|
||||
@@ -1129,8 +1153,8 @@ void BinaryAnnotator::BuildVector(const uint64_t vector_offset,
|
||||
// location.
|
||||
const uint16_t union_type_vector_id = field->id() - 1;
|
||||
|
||||
auto vtable_entry = vtable.fields.find(union_type_vector_id);
|
||||
if (vtable_entry == vtable.fields.end()) {
|
||||
auto vtable_entry = vtable_fields.find(union_type_vector_id);
|
||||
if (vtable_entry == vtable_fields.end()) {
|
||||
// TODO(dbaileychess): need to capture this error condition.
|
||||
break;
|
||||
}
|
||||
@@ -1301,7 +1325,7 @@ std::string BinaryAnnotator::BuildUnion(const uint64_t union_offset,
|
||||
// Union of vectors point to a new Binary section
|
||||
std::vector<BinaryRegion> regions;
|
||||
|
||||
BuildStruct(union_offset, regions, object);
|
||||
BuildStruct(union_offset, regions, field->name()->c_str(), object);
|
||||
|
||||
AddSection(
|
||||
union_offset,
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
#ifndef FLATBUFFERS_BINARY_ANNOTATOR_H_
|
||||
#define FLATBUFFERS_BINARY_ANNOTATOR_H_
|
||||
|
||||
#include <list>
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
@@ -52,14 +53,14 @@ enum class BinaryRegionType {
|
||||
template<typename T>
|
||||
static inline std::string ToHex(T i, size_t width = sizeof(T)) {
|
||||
std::stringstream stream;
|
||||
stream << std::hex << std::uppercase << std::setfill('0') << std::setw(width)
|
||||
<< i;
|
||||
stream << std::hex << std::uppercase << std::setfill('0')
|
||||
<< std::setw(static_cast<int>(width)) << i;
|
||||
return stream.str();
|
||||
}
|
||||
|
||||
// Specialized version for uint8_t that don't work well with std::hex.
|
||||
static inline std::string ToHex(uint8_t i) {
|
||||
return ToHex(static_cast<int>(i), 2);
|
||||
return ToHex<int>(static_cast<int>(i), 2);
|
||||
}
|
||||
|
||||
enum class BinaryRegionStatus {
|
||||
@@ -257,6 +258,8 @@ class BinaryAnnotator {
|
||||
uint16_t offset_from_table = 0;
|
||||
};
|
||||
|
||||
const reflection::Object *referring_table;
|
||||
|
||||
// Field ID -> {field def, offset from table}
|
||||
std::map<uint16_t, Entry> fields;
|
||||
|
||||
@@ -266,13 +269,18 @@ class BinaryAnnotator {
|
||||
|
||||
uint64_t BuildHeader(uint64_t offset);
|
||||
|
||||
void BuildVTable(uint64_t offset, const reflection::Object *table,
|
||||
uint64_t offset_of_referring_table);
|
||||
// VTables can be shared across instances or even across objects. This
|
||||
// attempts to get an existing vtable given the offset and table type,
|
||||
// otherwise it will built the vtable, memorize it, and return the built
|
||||
// VTable. Returns nullptr if building the VTable fails.
|
||||
VTable *GetOrBuildVTable(uint64_t offset, const reflection::Object *table,
|
||||
uint64_t offset_of_referring_table);
|
||||
|
||||
void BuildTable(uint64_t offset, const BinarySectionType type,
|
||||
const reflection::Object *table);
|
||||
|
||||
uint64_t BuildStruct(uint64_t offset, std::vector<BinaryRegion> ®ions,
|
||||
const std::string referring_field_name,
|
||||
const reflection::Object *structure);
|
||||
|
||||
void BuildString(uint64_t offset, const reflection::Object *table,
|
||||
@@ -280,7 +288,7 @@ class BinaryAnnotator {
|
||||
|
||||
void BuildVector(uint64_t offset, const reflection::Object *table,
|
||||
const reflection::Field *field, uint64_t parent_table_offset,
|
||||
const VTable &vtable);
|
||||
const std::map<uint16_t, VTable::Entry> vtable_fields);
|
||||
|
||||
std::string BuildUnion(uint64_t offset, uint8_t realized_type,
|
||||
const reflection::Field *field);
|
||||
@@ -381,7 +389,7 @@ class BinaryAnnotator {
|
||||
const uint64_t binary_length_;
|
||||
|
||||
// Map of binary offset to vtables, to dedupe vtables.
|
||||
std::map<uint64_t, VTable> vtables_;
|
||||
std::map<uint64_t, std::list<VTable>> vtables_;
|
||||
|
||||
// The annotated binary sections, index by their absolute offset.
|
||||
std::map<uint64_t, BinarySection> sections_;
|
||||
|
||||
524
src/flatc.cpp
524
src/flatc.cpp
@@ -19,10 +19,13 @@
|
||||
#include <algorithm>
|
||||
#include <limits>
|
||||
#include <list>
|
||||
#include <memory>
|
||||
#include <sstream>
|
||||
|
||||
#include "annotated_binary_text_gen.h"
|
||||
#include "binary_annotator.h"
|
||||
#include "flatbuffers/code_generator.h"
|
||||
#include "flatbuffers/idl.h"
|
||||
#include "flatbuffers/util.h"
|
||||
|
||||
namespace flatbuffers {
|
||||
@@ -32,17 +35,19 @@ static const char *FLATC_VERSION() { return FLATBUFFERS_VERSION(); }
|
||||
void FlatCompiler::ParseFile(
|
||||
flatbuffers::Parser &parser, const std::string &filename,
|
||||
const std::string &contents,
|
||||
std::vector<const char *> &include_directories) const {
|
||||
const std::vector<const char *> &include_directories) const {
|
||||
auto local_include_directory = flatbuffers::StripFileName(filename);
|
||||
include_directories.push_back(local_include_directory.c_str());
|
||||
include_directories.push_back(nullptr);
|
||||
if (!parser.Parse(contents.c_str(), &include_directories[0],
|
||||
filename.c_str())) {
|
||||
|
||||
std::vector<const char *> inc_directories;
|
||||
inc_directories.insert(inc_directories.end(), include_directories.begin(),
|
||||
include_directories.end());
|
||||
inc_directories.push_back(local_include_directory.c_str());
|
||||
inc_directories.push_back(nullptr);
|
||||
|
||||
if (!parser.Parse(contents.c_str(), &inc_directories[0], filename.c_str())) {
|
||||
Error(parser.error_, false, false);
|
||||
}
|
||||
if (!parser.error_.empty()) { Warn(parser.error_, false); }
|
||||
include_directories.pop_back();
|
||||
include_directories.pop_back();
|
||||
}
|
||||
|
||||
void FlatCompiler::LoadBinarySchema(flatbuffers::Parser &parser,
|
||||
@@ -63,7 +68,7 @@ void FlatCompiler::Error(const std::string &err, bool usage,
|
||||
params_.error_fn(this, err, usage, show_exe_name);
|
||||
}
|
||||
|
||||
const static FlatCOption options[] = {
|
||||
const static FlatCOption flatc_options[] = {
|
||||
{ "o", "", "PATH", "Prefix PATH to all generated files." },
|
||||
{ "I", "", "PATH", "Search for includes in the specified path." },
|
||||
{ "M", "", "", "Print make rules for generated files." },
|
||||
@@ -88,6 +93,9 @@ const static FlatCOption options[] = {
|
||||
{ "", "scoped-enums", "",
|
||||
"Use C++11 style scoped and strongly typed enums. Also implies "
|
||||
"--no-prefix." },
|
||||
{ "", "no-emit-min-max-enum-values", "",
|
||||
"Disable generation of MIN and MAX enumerated values for scoped enums "
|
||||
"and prefixed enums." },
|
||||
{ "", "swift-implementation-only", "",
|
||||
"Adds a @_implementationOnly to swift imports" },
|
||||
{ "", "gen-includes", "",
|
||||
@@ -107,6 +115,8 @@ const static FlatCOption options[] = {
|
||||
{ "", "gen-compare", "", "Generate operator== for object-based API types." },
|
||||
{ "", "gen-nullable", "",
|
||||
"Add Clang _Nullable for C++ pointer. or @Nullable for Java" },
|
||||
{ "", "java-package-prefix", "",
|
||||
"Add a prefix to the generated package name for Java." },
|
||||
{ "", "java-checkerframe", "", "Add @Pure for Java." },
|
||||
{ "", "gen-generated", "", "Add @Generated annotation for Java." },
|
||||
{ "", "gen-jvmstatic", "",
|
||||
@@ -158,10 +168,18 @@ const static FlatCOption options[] = {
|
||||
"Allow binaries without file_identifier to be read. This may crash flatc "
|
||||
"given a mismatched schema." },
|
||||
{ "", "size-prefixed", "", "Input binaries are size prefixed buffers." },
|
||||
{ "", "proto", "", "Input is a .proto, translate to .fbs." },
|
||||
{ "", "proto-namespace-suffix", "SUFFIX",
|
||||
"Add this namespace to any flatbuffers generated from protobufs." },
|
||||
{ "", "oneof-union", "", "Translate .proto oneofs to flatbuffer unions." },
|
||||
{ "", "keep-proto-id", "", "Keep protobuf field ids in generated fbs file." },
|
||||
{ "", "proto-id-gap", "",
|
||||
"Action that should be taken when a gap between protobuf ids found. "
|
||||
"Supported values: * "
|
||||
"'nop' - do not care about gap * 'warn' - A warning message will be shown "
|
||||
"about the gap in protobuf ids"
|
||||
"(default) "
|
||||
"* 'error' - An error message will be shown and the fbs generation will be "
|
||||
"interrupted." },
|
||||
{ "", "grpc", "", "Generate GRPC interfaces for the specified languages." },
|
||||
{ "", "schema", "", "Serialize schemas instead of JSON (use with -b)." },
|
||||
{ "", "bfbs-filenames", "PATH",
|
||||
@@ -222,7 +240,11 @@ const static FlatCOption options[] = {
|
||||
"Allow a nested_flatbuffer field to be parsed as a vector of bytes "
|
||||
"in JSON, which is unsafe unless checked by a verifier afterwards." },
|
||||
{ "", "ts-flat-files", "",
|
||||
"Only generated one typescript file per .fbs file." },
|
||||
"Generate a single typescript file per .fbs file. Implies "
|
||||
"ts_entry_points." },
|
||||
{ "", "ts-entry-points", "",
|
||||
"Generate entry point typescript per namespace. Implies gen-all." },
|
||||
{ "", "annotate-sparse-vectors", "", "Don't annotate every vector element." },
|
||||
{ "", "annotate", "SCHEMA",
|
||||
"Annotate the provided BINARY_FILE with the specified SCHEMA file." },
|
||||
{ "", "no-leak-private-annotation", "",
|
||||
@@ -230,6 +252,9 @@ const static FlatCOption options[] = {
|
||||
"Currently this is required to generate private types in Rust" },
|
||||
};
|
||||
|
||||
auto cmp = [](FlatCOption a, FlatCOption b) { return a.long_opt < b.long_opt; };
|
||||
static std::set<FlatCOption, decltype(cmp)> language_options(cmp);
|
||||
|
||||
static void AppendTextWrappedString(std::stringstream &ss, std::string &text,
|
||||
size_t max_col, size_t start_col) {
|
||||
size_t max_line_length = max_col - start_col;
|
||||
@@ -297,18 +322,21 @@ static void AppendShortOption(std::stringstream &ss,
|
||||
if (!option.long_opt.empty()) { ss << "--" << option.long_opt; }
|
||||
}
|
||||
|
||||
std::string FlatCompiler::GetShortUsageString(const char *program_name) const {
|
||||
std::string FlatCompiler::GetShortUsageString(
|
||||
const std::string &program_name) const {
|
||||
std::stringstream ss;
|
||||
ss << "Usage: " << program_name << " [";
|
||||
for (size_t i = 0; i < params_.num_generators; ++i) {
|
||||
const Generator &g = params_.generators[i];
|
||||
AppendShortOption(ss, g.option);
|
||||
ss << ", ";
|
||||
}
|
||||
for (const FlatCOption &option : options) {
|
||||
|
||||
for (const FlatCOption &option : language_options) {
|
||||
AppendShortOption(ss, option);
|
||||
ss << ", ";
|
||||
}
|
||||
|
||||
for (const FlatCOption &option : flatc_options) {
|
||||
AppendShortOption(ss, option);
|
||||
ss << ", ";
|
||||
}
|
||||
|
||||
ss.seekp(-2, ss.cur);
|
||||
ss << "]... FILE... [-- BINARY_FILE...]";
|
||||
std::string help = ss.str();
|
||||
@@ -317,17 +345,18 @@ std::string FlatCompiler::GetShortUsageString(const char *program_name) const {
|
||||
return ss_textwrap.str();
|
||||
}
|
||||
|
||||
std::string FlatCompiler::GetUsageString(const char *program_name) const {
|
||||
std::string FlatCompiler::GetUsageString(
|
||||
const std::string &program_name) const {
|
||||
std::stringstream ss;
|
||||
ss << "Usage: " << program_name
|
||||
<< " [OPTION]... FILE... [-- BINARY_FILE...]\n";
|
||||
for (size_t i = 0; i < params_.num_generators; ++i) {
|
||||
const Generator &g = params_.generators[i];
|
||||
AppendOption(ss, g.option, 80, 25);
|
||||
}
|
||||
|
||||
for (const FlatCOption &option : language_options) {
|
||||
AppendOption(ss, option, 80, 25);
|
||||
}
|
||||
ss << "\n";
|
||||
for (const FlatCOption &option : options) {
|
||||
|
||||
for (const FlatCOption &option : flatc_options) {
|
||||
AppendOption(ss, option, 80, 25);
|
||||
}
|
||||
ss << "\n";
|
||||
@@ -338,17 +367,18 @@ std::string FlatCompiler::GetUsageString(const char *program_name) const {
|
||||
"after the -- must be binary flatbuffer format files. Output files are "
|
||||
"named using the base file name of the input, and written to the current "
|
||||
"directory or the path given by -o. example: " +
|
||||
std::string(program_name) + " -c -b schema1.fbs schema2.fbs data.json";
|
||||
program_name + " -c -b schema1.fbs schema2.fbs data.json";
|
||||
AppendTextWrappedString(ss, files_description, 80, 0);
|
||||
ss << "\n";
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
void FlatCompiler::AnnotateBinaries(
|
||||
const uint8_t *binary_schema, const uint64_t binary_schema_size,
|
||||
const std::string &schema_filename,
|
||||
const std::vector<std::string> &binary_files) {
|
||||
for (const std::string &filename : binary_files) {
|
||||
void FlatCompiler::AnnotateBinaries(const uint8_t *binary_schema,
|
||||
const uint64_t binary_schema_size,
|
||||
const FlatCOptions &options) {
|
||||
const std::string &schema_filename = options.annotate_schema;
|
||||
|
||||
for (const std::string &filename : options.filenames) {
|
||||
std::string binary_contents;
|
||||
if (!flatbuffers::LoadFile(filename.c_str(), true, &binary_contents)) {
|
||||
Warn("unable to load binary file: " + filename);
|
||||
@@ -364,60 +394,46 @@ void FlatCompiler::AnnotateBinaries(
|
||||
|
||||
auto annotations = binary_annotator.Annotate();
|
||||
|
||||
flatbuffers::AnnotatedBinaryTextGenerator::Options text_gen_opts;
|
||||
text_gen_opts.include_vector_contents =
|
||||
options.annotate_include_vector_contents;
|
||||
|
||||
// TODO(dbaileychess): Right now we just support a single text-based
|
||||
// output of the annotated binary schema, which we generate here. We
|
||||
// could output the raw annotations instead and have third-party tools
|
||||
// use them to generate their own output.
|
||||
flatbuffers::AnnotatedBinaryTextGenerator text_generator(
|
||||
flatbuffers::AnnotatedBinaryTextGenerator::Options{}, annotations,
|
||||
binary, binary_size);
|
||||
text_gen_opts, annotations, binary, binary_size);
|
||||
|
||||
text_generator.Generate(filename, schema_filename);
|
||||
}
|
||||
}
|
||||
|
||||
int FlatCompiler::Compile(int argc, const char **argv) {
|
||||
if (params_.generators == nullptr || params_.num_generators == 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
FlatCOptions FlatCompiler::ParseFromCommandLineArguments(int argc,
|
||||
const char **argv) {
|
||||
if (argc <= 1) { Error("Need to provide at least one argument."); }
|
||||
|
||||
flatbuffers::IDLOptions opts;
|
||||
std::string output_path;
|
||||
FlatCOptions options;
|
||||
|
||||
bool any_generator = false;
|
||||
bool print_make_rules = false;
|
||||
bool raw_binary = false;
|
||||
bool schema_binary = false;
|
||||
bool grpc_enabled = false;
|
||||
bool requires_bfbs = false;
|
||||
std::vector<std::string> filenames;
|
||||
std::list<std::string> include_directories_storage;
|
||||
std::vector<const char *> include_directories;
|
||||
std::vector<const char *> conform_include_directories;
|
||||
std::vector<bool> generator_enabled(params_.num_generators, false);
|
||||
size_t binary_files_from = std::numeric_limits<size_t>::max();
|
||||
std::string conform_to_schema;
|
||||
std::string annotate_schema;
|
||||
options.program_name = std::string(argv[0]);
|
||||
|
||||
const char *program_name = argv[0];
|
||||
IDLOptions &opts = options.opts;
|
||||
|
||||
for (int argi = 1; argi < argc; argi++) {
|
||||
std::string arg = argv[argi];
|
||||
if (arg[0] == '-') {
|
||||
if (filenames.size() && arg[1] != '-')
|
||||
if (options.filenames.size() && arg[1] != '-')
|
||||
Error("invalid option location: " + arg, true);
|
||||
if (arg == "-o") {
|
||||
if (++argi >= argc) Error("missing path following: " + arg, true);
|
||||
output_path = flatbuffers::ConCatPathFileName(
|
||||
options.output_path = flatbuffers::ConCatPathFileName(
|
||||
flatbuffers::PosixPath(argv[argi]), "");
|
||||
} else if (arg == "-I") {
|
||||
if (++argi >= argc) Error("missing path following: " + arg, true);
|
||||
include_directories_storage.push_back(
|
||||
options.include_directories_storage.push_back(
|
||||
flatbuffers::PosixPath(argv[argi]));
|
||||
include_directories.push_back(
|
||||
include_directories_storage.back().c_str());
|
||||
options.include_directories.push_back(
|
||||
options.include_directories_storage.back().c_str());
|
||||
} else if (arg == "--bfbs-filenames") {
|
||||
if (++argi > argc) Error("missing path following: " + arg, true);
|
||||
opts.project_root = argv[argi];
|
||||
@@ -425,13 +441,13 @@ int FlatCompiler::Compile(int argc, const char **argv) {
|
||||
Error(arg + " is not a directory: " + opts.project_root);
|
||||
} else if (arg == "--conform") {
|
||||
if (++argi >= argc) Error("missing path following: " + arg, true);
|
||||
conform_to_schema = flatbuffers::PosixPath(argv[argi]);
|
||||
options.conform_to_schema = flatbuffers::PosixPath(argv[argi]);
|
||||
} else if (arg == "--conform-includes") {
|
||||
if (++argi >= argc) Error("missing path following: " + arg, true);
|
||||
include_directories_storage.push_back(
|
||||
options.include_directories_storage.push_back(
|
||||
flatbuffers::PosixPath(argv[argi]));
|
||||
conform_include_directories.push_back(
|
||||
include_directories_storage.back().c_str());
|
||||
options.conform_include_directories.push_back(
|
||||
options.include_directories_storage.back().c_str());
|
||||
} else if (arg == "--include-prefix") {
|
||||
if (++argi >= argc) Error("missing path following: " + arg, true);
|
||||
opts.include_prefix = flatbuffers::ConCatPathFileName(
|
||||
@@ -464,6 +480,8 @@ int FlatCompiler::Compile(int argc, const char **argv) {
|
||||
} else if (arg == "--scoped-enums") {
|
||||
opts.prefixed_enums = false;
|
||||
opts.scoped_enums = true;
|
||||
} else if (arg == "--no-emit-min-max-enum-values") {
|
||||
opts.emit_min_max_enum_values = false;
|
||||
} else if (arg == "--no-union-value-namespacing") {
|
||||
opts.union_value_namespacing = false;
|
||||
} else if (arg == "--gen-mutable") {
|
||||
@@ -500,6 +518,9 @@ int FlatCompiler::Compile(int argc, const char **argv) {
|
||||
Error("unknown case style: " + std::string(argv[argi]), true);
|
||||
} else if (arg == "--gen-nullable") {
|
||||
opts.gen_nullable = true;
|
||||
} else if (arg == "--java-package-prefix") {
|
||||
if (++argi >= argc) Error("missing prefix following: " + arg, true);
|
||||
opts.java_package_prefix = argv[argi];
|
||||
} else if (arg == "--java-checkerframework") {
|
||||
opts.java_checkerframework = true;
|
||||
} else if (arg == "--gen-generated") {
|
||||
@@ -526,30 +547,40 @@ int FlatCompiler::Compile(int argc, const char **argv) {
|
||||
opts.one_file = true;
|
||||
opts.include_dependence_headers = false;
|
||||
} else if (arg == "--raw-binary") {
|
||||
raw_binary = true;
|
||||
options.raw_binary = true;
|
||||
} else if (arg == "--size-prefixed") {
|
||||
opts.size_prefixed = true;
|
||||
} else if (arg == "--") { // Separator between text and binary inputs.
|
||||
binary_files_from = filenames.size();
|
||||
} else if (arg == "--proto") {
|
||||
opts.proto_mode = true;
|
||||
options.binary_files_from = options.filenames.size();
|
||||
} else if (arg == "--proto-namespace-suffix") {
|
||||
if (++argi >= argc) Error("missing namespace suffix" + arg, true);
|
||||
opts.proto_namespace_suffix = argv[argi];
|
||||
} else if (arg == "--oneof-union") {
|
||||
opts.proto_oneof_union = true;
|
||||
} else if (arg == "--keep-proto-id") {
|
||||
opts.keep_proto_id = true;
|
||||
} else if (arg == "--proto-id-gap") {
|
||||
if (++argi >= argc) Error("missing case style following: " + arg, true);
|
||||
if (!strcmp(argv[argi], "nop"))
|
||||
opts.proto_id_gap_action = IDLOptions::ProtoIdGapAction::NO_OP;
|
||||
else if (!strcmp(argv[argi], "warn"))
|
||||
opts.proto_id_gap_action = IDLOptions::ProtoIdGapAction::WARNING;
|
||||
else if (!strcmp(argv[argi], "error"))
|
||||
opts.proto_id_gap_action = IDLOptions::ProtoIdGapAction::ERROR;
|
||||
else
|
||||
Error("unknown case style: " + std::string(argv[argi]), true);
|
||||
} else if (arg == "--schema") {
|
||||
schema_binary = true;
|
||||
options.schema_binary = true;
|
||||
} else if (arg == "-M") {
|
||||
print_make_rules = true;
|
||||
options.print_make_rules = true;
|
||||
} else if (arg == "--version") {
|
||||
printf("flatc version %s\n", FLATC_VERSION());
|
||||
exit(0);
|
||||
} else if (arg == "--help" || arg == "-h") {
|
||||
printf("%s\n", GetUsageString(program_name).c_str());
|
||||
printf("%s\n", GetUsageString(options.program_name).c_str());
|
||||
exit(0);
|
||||
} else if (arg == "--grpc") {
|
||||
grpc_enabled = true;
|
||||
options.grpc_enabled = true;
|
||||
} else if (arg == "--bfbs-comments") {
|
||||
opts.binary_schema_comments = true;
|
||||
} else if (arg == "--bfbs-builtins") {
|
||||
@@ -607,42 +638,61 @@ int FlatCompiler::Compile(int argc, const char **argv) {
|
||||
} else if (arg == "--json-nested-bytes") {
|
||||
opts.json_nested_legacy_flatbuffers = true;
|
||||
} else if (arg == "--ts-flat-files") {
|
||||
opts.ts_flat_file = true;
|
||||
opts.ts_flat_files = true;
|
||||
opts.ts_entry_points = true;
|
||||
opts.generate_all = true;
|
||||
} else if (arg == "--ts-entry-points") {
|
||||
opts.ts_entry_points = true;
|
||||
opts.generate_all = true;
|
||||
} else if (arg == "--ts-no-import-ext") {
|
||||
opts.ts_no_import_ext = true;
|
||||
} else if (arg == "--no-leak-private-annotation") {
|
||||
opts.no_leak_private_annotations = true;
|
||||
} else if (arg == "--annotate-sparse-vectors") {
|
||||
options.annotate_include_vector_contents = false;
|
||||
} else if (arg == "--annotate") {
|
||||
if (++argi >= argc) Error("missing path following: " + arg, true);
|
||||
annotate_schema = flatbuffers::PosixPath(argv[argi]);
|
||||
options.annotate_schema = flatbuffers::PosixPath(argv[argi]);
|
||||
} else {
|
||||
for (size_t i = 0; i < params_.num_generators; ++i) {
|
||||
if (arg == "--" + params_.generators[i].option.long_opt ||
|
||||
arg == "-" + params_.generators[i].option.short_opt) {
|
||||
generator_enabled[i] = true;
|
||||
any_generator = true;
|
||||
opts.lang_to_generate |= params_.generators[i].lang;
|
||||
if (params_.generators[i].bfbs_generator) {
|
||||
opts.binary_schema_comments = true;
|
||||
requires_bfbs = true;
|
||||
}
|
||||
goto found;
|
||||
}
|
||||
}
|
||||
Error("unknown commandline argument: " + arg, true);
|
||||
if (arg == "--proto") { opts.proto_mode = true; }
|
||||
|
||||
found:;
|
||||
auto code_generator_it = code_generators_.find(arg);
|
||||
if (code_generator_it == code_generators_.end()) {
|
||||
Error("unknown commandline argument: " + arg, true);
|
||||
return options;
|
||||
}
|
||||
|
||||
std::shared_ptr<CodeGenerator> code_generator =
|
||||
code_generator_it->second;
|
||||
|
||||
// TODO(derekbailey): remove in favor of just checking if
|
||||
// generators.empty().
|
||||
options.any_generator = true;
|
||||
opts.lang_to_generate |= code_generator->Language();
|
||||
|
||||
auto is_binary_schema = code_generator->SupportsBfbsGeneration();
|
||||
opts.binary_schema_comments = is_binary_schema;
|
||||
options.requires_bfbs = is_binary_schema;
|
||||
options.generators.push_back(std::move(code_generator));
|
||||
}
|
||||
} else {
|
||||
filenames.push_back(flatbuffers::PosixPath(argv[argi]));
|
||||
options.filenames.push_back(flatbuffers::PosixPath(argv[argi]));
|
||||
}
|
||||
}
|
||||
|
||||
if (!filenames.size()) Error("missing input files", false, true);
|
||||
return options;
|
||||
}
|
||||
|
||||
void FlatCompiler::ValidateOptions(const FlatCOptions &options) {
|
||||
const IDLOptions &opts = options.opts;
|
||||
|
||||
if (!options.filenames.size()) Error("missing input files", false, true);
|
||||
|
||||
if (opts.proto_mode) {
|
||||
if (any_generator)
|
||||
if (options.any_generator)
|
||||
Error("cannot generate code directly from .proto files", true);
|
||||
} else if (!any_generator && conform_to_schema.empty() &&
|
||||
annotate_schema.empty()) {
|
||||
} else if (!options.any_generator && options.conform_to_schema.empty() &&
|
||||
options.annotate_schema.empty()) {
|
||||
Error("no options: specify at least one generator.", true);
|
||||
}
|
||||
|
||||
@@ -651,80 +701,45 @@ int FlatCompiler::Compile(int argc, const char **argv) {
|
||||
"--cs-gen-json-serializer requires --gen-object-api to be set as "
|
||||
"well.");
|
||||
}
|
||||
}
|
||||
|
||||
flatbuffers::Parser FlatCompiler::GetConformParser(
|
||||
const FlatCOptions &options) {
|
||||
flatbuffers::Parser conform_parser;
|
||||
if (!conform_to_schema.empty()) {
|
||||
if (!options.conform_to_schema.empty()) {
|
||||
std::string contents;
|
||||
if (!flatbuffers::LoadFile(conform_to_schema.c_str(), true, &contents))
|
||||
Error("unable to load schema: " + conform_to_schema);
|
||||
if (!flatbuffers::LoadFile(options.conform_to_schema.c_str(), true,
|
||||
&contents)) {
|
||||
Error("unable to load schema: " + options.conform_to_schema);
|
||||
}
|
||||
|
||||
if (flatbuffers::GetExtension(conform_to_schema) ==
|
||||
if (flatbuffers::GetExtension(options.conform_to_schema) ==
|
||||
reflection::SchemaExtension()) {
|
||||
LoadBinarySchema(conform_parser, conform_to_schema, contents);
|
||||
LoadBinarySchema(conform_parser, options.conform_to_schema, contents);
|
||||
} else {
|
||||
ParseFile(conform_parser, conform_to_schema, contents,
|
||||
conform_include_directories);
|
||||
ParseFile(conform_parser, options.conform_to_schema, contents,
|
||||
options.conform_include_directories);
|
||||
}
|
||||
}
|
||||
return conform_parser;
|
||||
}
|
||||
|
||||
if (!annotate_schema.empty()) {
|
||||
const std::string ext = flatbuffers::GetExtension(annotate_schema);
|
||||
if (!(ext == reflection::SchemaExtension() || ext == "fbs")) {
|
||||
Error("Expected a `.bfbs` or `.fbs` schema, got: " + annotate_schema);
|
||||
}
|
||||
std::unique_ptr<Parser> FlatCompiler::GenerateCode(const FlatCOptions &options,
|
||||
Parser &conform_parser) {
|
||||
std::unique_ptr<Parser> parser =
|
||||
std::unique_ptr<Parser>(new Parser(options.opts));
|
||||
|
||||
const bool is_binary_schema = ext == reflection::SchemaExtension();
|
||||
for (auto file_it = options.filenames.begin();
|
||||
file_it != options.filenames.end(); ++file_it) {
|
||||
IDLOptions opts = options.opts;
|
||||
|
||||
std::string schema_contents;
|
||||
if (!flatbuffers::LoadFile(annotate_schema.c_str(),
|
||||
/*binary=*/is_binary_schema, &schema_contents)) {
|
||||
Error("unable to load schema: " + annotate_schema);
|
||||
}
|
||||
|
||||
const uint8_t *binary_schema = nullptr;
|
||||
uint64_t binary_schema_size = 0;
|
||||
|
||||
IDLOptions binary_opts;
|
||||
binary_opts.lang_to_generate |= flatbuffers::IDLOptions::kBinary;
|
||||
flatbuffers::Parser parser(binary_opts);
|
||||
|
||||
if (is_binary_schema) {
|
||||
binary_schema =
|
||||
reinterpret_cast<const uint8_t *>(schema_contents.c_str());
|
||||
binary_schema_size = schema_contents.size();
|
||||
} else {
|
||||
// If we need to generate the .bfbs file from the provided schema file
|
||||
// (.fbs)
|
||||
ParseFile(parser, annotate_schema, schema_contents, include_directories);
|
||||
parser.Serialize();
|
||||
|
||||
binary_schema = parser.builder_.GetBufferPointer();
|
||||
binary_schema_size = parser.builder_.GetSize();
|
||||
}
|
||||
|
||||
if (binary_schema == nullptr || !binary_schema_size) {
|
||||
Error("could not parse a value binary schema from: " + annotate_schema);
|
||||
}
|
||||
|
||||
// Annotate the provided files with the binary_schema.
|
||||
AnnotateBinaries(binary_schema, binary_schema_size, annotate_schema,
|
||||
filenames);
|
||||
|
||||
// We don't support doing anything else after annotating a binary.
|
||||
return 0;
|
||||
}
|
||||
|
||||
std::unique_ptr<flatbuffers::Parser> parser(new flatbuffers::Parser(opts));
|
||||
|
||||
for (auto file_it = filenames.begin(); file_it != filenames.end();
|
||||
++file_it) {
|
||||
auto &filename = *file_it;
|
||||
std::string contents;
|
||||
if (!flatbuffers::LoadFile(filename.c_str(), true, &contents))
|
||||
Error("unable to load file: " + filename);
|
||||
|
||||
bool is_binary =
|
||||
static_cast<size_t>(file_it - filenames.begin()) >= binary_files_from;
|
||||
bool is_binary = static_cast<size_t>(file_it - options.filenames.begin()) >=
|
||||
options.binary_files_from;
|
||||
auto ext = flatbuffers::GetExtension(filename);
|
||||
const bool is_schema = ext == "fbs" || ext == "proto";
|
||||
if (is_schema && opts.project_root.empty()) {
|
||||
@@ -736,7 +751,7 @@ int FlatCompiler::Compile(int argc, const char **argv) {
|
||||
parser->builder_.PushFlatBuffer(
|
||||
reinterpret_cast<const uint8_t *>(contents.c_str()),
|
||||
contents.length());
|
||||
if (!raw_binary) {
|
||||
if (!options.raw_binary) {
|
||||
// Generally reading binaries that do not correspond to the schema
|
||||
// will crash, and sadly there's no way around that when the binary
|
||||
// does not contain a file identifier.
|
||||
@@ -766,12 +781,12 @@ int FlatCompiler::Compile(int argc, const char **argv) {
|
||||
// If we're processing multiple schemas, make sure to start each
|
||||
// one from scratch. If it depends on previous schemas it must do
|
||||
// so explicitly using an include.
|
||||
parser.reset(new flatbuffers::Parser(opts));
|
||||
parser.reset(new Parser(opts));
|
||||
}
|
||||
// Try to parse the file contents (binary schema/flexbuffer/textual
|
||||
// schema)
|
||||
if (is_binary_schema) {
|
||||
LoadBinarySchema(*parser.get(), filename, contents);
|
||||
LoadBinarySchema(*parser, filename, contents);
|
||||
} else if (opts.use_flexbuffers) {
|
||||
if (opts.lang_to_generate == IDLOptions::kJson) {
|
||||
auto data = reinterpret_cast<const uint8_t *>(contents.c_str());
|
||||
@@ -782,10 +797,10 @@ int FlatCompiler::Compile(int argc, const char **argv) {
|
||||
parser->flex_root_ = flexbuffers::GetRoot(data, size);
|
||||
} else {
|
||||
parser->flex_builder_.Clear();
|
||||
ParseFile(*parser.get(), filename, contents, include_directories);
|
||||
ParseFile(*parser, filename, contents, options.include_directories);
|
||||
}
|
||||
} else {
|
||||
ParseFile(*parser.get(), filename, contents, include_directories);
|
||||
ParseFile(*parser, filename, contents, options.include_directories);
|
||||
if (!is_schema && !parser->builder_.GetSize()) {
|
||||
// If a file doesn't end in .fbs, it must be json/binary. Ensure we
|
||||
// didn't just parse a schema with a different extension.
|
||||
@@ -794,14 +809,15 @@ int FlatCompiler::Compile(int argc, const char **argv) {
|
||||
true);
|
||||
}
|
||||
}
|
||||
if ((is_schema || is_binary_schema) && !conform_to_schema.empty()) {
|
||||
if ((is_schema || is_binary_schema) &&
|
||||
!options.conform_to_schema.empty()) {
|
||||
auto err = parser->ConformTo(conform_parser);
|
||||
if (!err.empty()) Error("schemas don\'t conform: " + err, false);
|
||||
}
|
||||
if (schema_binary || opts.binary_schema_gen_embed) {
|
||||
if (options.schema_binary || opts.binary_schema_gen_embed) {
|
||||
parser->Serialize();
|
||||
}
|
||||
if (schema_binary) {
|
||||
if (options.schema_binary) {
|
||||
parser->file_extension_ = reflection::SchemaExtension();
|
||||
}
|
||||
}
|
||||
@@ -812,59 +828,58 @@ int FlatCompiler::Compile(int argc, const char **argv) {
|
||||
// the serialized buffer and length.
|
||||
const uint8_t *bfbs_buffer = nullptr;
|
||||
int64_t bfbs_length = 0;
|
||||
if (requires_bfbs) {
|
||||
if (options.requires_bfbs) {
|
||||
parser->Serialize();
|
||||
bfbs_buffer = parser->builder_.GetBufferPointer();
|
||||
bfbs_length = parser->builder_.GetSize();
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < params_.num_generators; ++i) {
|
||||
if (generator_enabled[i]) {
|
||||
if (!print_make_rules) {
|
||||
flatbuffers::EnsureDirExists(output_path);
|
||||
for (const std::shared_ptr<CodeGenerator> &code_generator :
|
||||
options.generators) {
|
||||
if (options.print_make_rules) {
|
||||
std::string make_rule;
|
||||
const CodeGenerator::Status status = code_generator->GenerateMakeRule(
|
||||
*parser, options.output_path, filename, make_rule);
|
||||
if (status == CodeGenerator::Status::OK && !make_rule.empty()) {
|
||||
printf("%s\n",
|
||||
flatbuffers::WordWrap(make_rule, 80, " ", " \\").c_str());
|
||||
} else {
|
||||
Error("Cannot generate make rule for " +
|
||||
code_generator->LanguageName());
|
||||
}
|
||||
} else {
|
||||
flatbuffers::EnsureDirExists(options.output_path);
|
||||
|
||||
// Prefer bfbs generators if present.
|
||||
if (params_.generators[i].bfbs_generator) {
|
||||
const GeneratorStatus status =
|
||||
params_.generators[i].bfbs_generator->Generate(bfbs_buffer,
|
||||
bfbs_length);
|
||||
if (status != OK) {
|
||||
Error(std::string("Unable to generate ") +
|
||||
params_.generators[i].lang_name + " for " + filebase +
|
||||
" using bfbs generator.");
|
||||
}
|
||||
} else {
|
||||
if ((!params_.generators[i].schema_only ||
|
||||
(is_schema || is_binary_schema)) &&
|
||||
!params_.generators[i].generate(*parser.get(), output_path,
|
||||
filebase)) {
|
||||
Error(std::string("Unable to generate ") +
|
||||
params_.generators[i].lang_name + " for " + filebase);
|
||||
}
|
||||
// Prefer bfbs generators if present.
|
||||
if (code_generator->SupportsBfbsGeneration()) {
|
||||
const CodeGenerator::Status status =
|
||||
code_generator->GenerateCode(bfbs_buffer, bfbs_length);
|
||||
if (status != CodeGenerator::Status::OK) {
|
||||
Error("Unable to generate " + code_generator->LanguageName() +
|
||||
" for " + filebase + " using bfbs generator.");
|
||||
}
|
||||
} else {
|
||||
if (params_.generators[i].make_rule == nullptr) {
|
||||
Error(std::string("Cannot generate make rule for ") +
|
||||
params_.generators[i].lang_name);
|
||||
} else {
|
||||
std::string make_rule = params_.generators[i].make_rule(
|
||||
*parser.get(), output_path, filename);
|
||||
if (!make_rule.empty())
|
||||
printf("%s\n",
|
||||
flatbuffers::WordWrap(make_rule, 80, " ", " \\").c_str());
|
||||
if ((!code_generator->IsSchemaOnly() ||
|
||||
(is_schema || is_binary_schema)) &&
|
||||
code_generator->GenerateCode(*parser, options.output_path,
|
||||
filebase) !=
|
||||
CodeGenerator::Status::OK) {
|
||||
Error("Unable to generate " + code_generator->LanguageName() +
|
||||
" for " + filebase);
|
||||
}
|
||||
}
|
||||
if (grpc_enabled) {
|
||||
if (params_.generators[i].generateGRPC != nullptr) {
|
||||
if (!params_.generators[i].generateGRPC(*parser.get(), output_path,
|
||||
filebase)) {
|
||||
Error(std::string("Unable to generate GRPC interface for ") +
|
||||
params_.generators[i].lang_name);
|
||||
}
|
||||
} else {
|
||||
Warn(std::string("GRPC interface generator not implemented for ") +
|
||||
params_.generators[i].lang_name);
|
||||
}
|
||||
}
|
||||
|
||||
if (options.grpc_enabled) {
|
||||
const CodeGenerator::Status status = code_generator->GenerateGrpcCode(
|
||||
*parser, options.output_path, filebase);
|
||||
|
||||
if (status == CodeGenerator::Status::NOT_IMPLEMENTED) {
|
||||
Warn("GRPC interface generator not implemented for " +
|
||||
code_generator->LanguageName());
|
||||
} else if (status == CodeGenerator::Status::ERROR) {
|
||||
Error("Unable to generate GRPC interface for " +
|
||||
code_generator->LanguageName());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -876,26 +891,111 @@ int FlatCompiler::Compile(int argc, const char **argv) {
|
||||
Error("root type must be a table");
|
||||
}
|
||||
|
||||
if (opts.proto_mode) GenerateFBS(*parser.get(), output_path, filebase);
|
||||
|
||||
// We do not want to generate code for the definitions in this file
|
||||
// in any files coming up next.
|
||||
parser->MarkGenerated();
|
||||
}
|
||||
|
||||
// Once all the files have been parsed, run any generators Parsing Completed
|
||||
// function for final generation.
|
||||
for (size_t i = 0; i < params_.num_generators; ++i) {
|
||||
if (generator_enabled[i] &&
|
||||
params_.generators[i].parsing_completed != nullptr) {
|
||||
if (!params_.generators[i].parsing_completed(*parser, output_path)) {
|
||||
Error("failed running parsing completed for " +
|
||||
std::string(params_.generators[i].lang_name));
|
||||
}
|
||||
return parser;
|
||||
}
|
||||
|
||||
int FlatCompiler::Compile(const FlatCOptions &options) {
|
||||
// TODO(derekbailey): change to std::optional<Parser>
|
||||
Parser conform_parser = GetConformParser(options);
|
||||
|
||||
// TODO(derekbailey): split to own method.
|
||||
if (!options.annotate_schema.empty()) {
|
||||
const std::string ext = flatbuffers::GetExtension(options.annotate_schema);
|
||||
if (!(ext == reflection::SchemaExtension() || ext == "fbs")) {
|
||||
Error("Expected a `.bfbs` or `.fbs` schema, got: " +
|
||||
options.annotate_schema);
|
||||
}
|
||||
|
||||
const bool is_binary_schema = ext == reflection::SchemaExtension();
|
||||
|
||||
std::string schema_contents;
|
||||
if (!flatbuffers::LoadFile(options.annotate_schema.c_str(),
|
||||
/*binary=*/is_binary_schema, &schema_contents)) {
|
||||
Error("unable to load schema: " + options.annotate_schema);
|
||||
}
|
||||
|
||||
const uint8_t *binary_schema = nullptr;
|
||||
uint64_t binary_schema_size = 0;
|
||||
|
||||
IDLOptions binary_opts;
|
||||
binary_opts.lang_to_generate |= flatbuffers::IDLOptions::kBinary;
|
||||
Parser parser(binary_opts);
|
||||
|
||||
if (is_binary_schema) {
|
||||
binary_schema =
|
||||
reinterpret_cast<const uint8_t *>(schema_contents.c_str());
|
||||
binary_schema_size = schema_contents.size();
|
||||
} else {
|
||||
// If we need to generate the .bfbs file from the provided schema file
|
||||
// (.fbs)
|
||||
ParseFile(parser, options.annotate_schema, schema_contents,
|
||||
options.include_directories);
|
||||
parser.Serialize();
|
||||
|
||||
binary_schema = parser.builder_.GetBufferPointer();
|
||||
binary_schema_size = parser.builder_.GetSize();
|
||||
}
|
||||
|
||||
if (binary_schema == nullptr || !binary_schema_size) {
|
||||
Error("could not parse a value binary schema from: " +
|
||||
options.annotate_schema);
|
||||
}
|
||||
|
||||
// Annotate the provided files with the binary_schema.
|
||||
AnnotateBinaries(binary_schema, binary_schema_size, options);
|
||||
|
||||
// We don't support doing anything else after annotating a binary.
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (options.generators.empty()) {
|
||||
Error("No generator registered");
|
||||
return -1;
|
||||
}
|
||||
|
||||
std::unique_ptr<Parser> parser = GenerateCode(options, conform_parser);
|
||||
|
||||
for (const auto &code_generator : options.generators) {
|
||||
if (code_generator->SupportsRootFileGeneration()) {
|
||||
code_generator->GenerateRootFile(*parser, options.output_path);
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool FlatCompiler::RegisterCodeGenerator(
|
||||
const FlatCOption &option, std::shared_ptr<CodeGenerator> code_generator) {
|
||||
if (!option.short_opt.empty() &&
|
||||
code_generators_.find("-" + option.short_opt) != code_generators_.end()) {
|
||||
Error("multiple generators registered under: -" + option.short_opt, false,
|
||||
false);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!option.short_opt.empty()) {
|
||||
code_generators_["-" + option.short_opt] = code_generator;
|
||||
}
|
||||
|
||||
if (!option.long_opt.empty() &&
|
||||
code_generators_.find("--" + option.long_opt) != code_generators_.end()) {
|
||||
Error("multiple generators registered under: --" + option.long_opt, false,
|
||||
false);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!option.long_opt.empty()) {
|
||||
code_generators_["--" + option.long_opt] = code_generator;
|
||||
}
|
||||
|
||||
language_options.insert(option);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace flatbuffers
|
||||
|
||||
@@ -20,8 +20,25 @@
|
||||
#include "bfbs_gen_lua.h"
|
||||
#include "bfbs_gen_nim.h"
|
||||
#include "flatbuffers/base.h"
|
||||
#include "flatbuffers/code_generator.h"
|
||||
#include "flatbuffers/flatc.h"
|
||||
#include "flatbuffers/util.h"
|
||||
#include "idl_gen_binary.h"
|
||||
#include "idl_gen_cpp.h"
|
||||
#include "idl_gen_csharp.h"
|
||||
#include "idl_gen_dart.h"
|
||||
#include "idl_gen_fbs.h"
|
||||
#include "idl_gen_go.h"
|
||||
#include "idl_gen_java.h"
|
||||
#include "idl_gen_json_schema.h"
|
||||
#include "idl_gen_kotlin.h"
|
||||
#include "idl_gen_lobster.h"
|
||||
#include "idl_gen_php.h"
|
||||
#include "idl_gen_python.h"
|
||||
#include "idl_gen_rust.h"
|
||||
#include "idl_gen_swift.h"
|
||||
#include "idl_gen_text.h"
|
||||
#include "idl_gen_ts.h"
|
||||
|
||||
static const char *g_program_name = nullptr;
|
||||
|
||||
@@ -55,108 +72,108 @@ void LogCompilerError(const std::string &err) {
|
||||
int main(int argc, const char *argv[]) {
|
||||
const std::string flatbuffers_version(flatbuffers::FLATBUFFERS_VERSION());
|
||||
|
||||
std::unique_ptr<flatbuffers::BfbsGenerator> bfbs_gen_lua =
|
||||
flatbuffers::NewLuaBfbsGenerator(flatbuffers_version);
|
||||
std::unique_ptr<flatbuffers::BfbsGenerator> bfbs_gen_nim =
|
||||
flatbuffers::NewNimBfbsGenerator(flatbuffers_version);
|
||||
|
||||
g_program_name = argv[0];
|
||||
|
||||
const flatbuffers::FlatCompiler::Generator generators[] = {
|
||||
{ flatbuffers::GenerateBinary, "binary", false, nullptr,
|
||||
flatbuffers::IDLOptions::kBinary,
|
||||
flatbuffers::FlatCOption{
|
||||
"b", "binary", "",
|
||||
"Generate wire format binaries for any data definitions" },
|
||||
flatbuffers::BinaryMakeRule, nullptr, nullptr },
|
||||
{ flatbuffers::GenerateTextFile, "text", false, nullptr,
|
||||
flatbuffers::IDLOptions::kJson,
|
||||
flatbuffers::FlatCOption{
|
||||
"t", "json", "", "Generate text output for any data definitions" },
|
||||
|
||||
flatbuffers::TextMakeRule, nullptr, nullptr },
|
||||
{ flatbuffers::GenerateCPP, "C++", true, flatbuffers::GenerateCppGRPC,
|
||||
flatbuffers::IDLOptions::kCpp,
|
||||
flatbuffers::FlatCOption{ "c", "cpp", "",
|
||||
"Generate C++ headers for tables/structs" },
|
||||
flatbuffers::CPPMakeRule, nullptr, nullptr },
|
||||
{ flatbuffers::GenerateGo, "Go", true, flatbuffers::GenerateGoGRPC,
|
||||
flatbuffers::IDLOptions::kGo,
|
||||
flatbuffers::FlatCOption{ "g", "go", "",
|
||||
"Generate Go files for tables/structs" },
|
||||
nullptr, nullptr, nullptr },
|
||||
{ flatbuffers::GenerateJava, "Java", true, flatbuffers::GenerateJavaGRPC,
|
||||
flatbuffers::IDLOptions::kJava,
|
||||
flatbuffers::FlatCOption{ "j", "java", "",
|
||||
"Generate Java classes for tables/structs" },
|
||||
flatbuffers::JavaMakeRule, nullptr, nullptr },
|
||||
{ flatbuffers::GenerateDart, "Dart", true, nullptr,
|
||||
flatbuffers::IDLOptions::kDart,
|
||||
flatbuffers::FlatCOption{ "d", "dart", "",
|
||||
"Generate Dart classes for tables/structs" },
|
||||
flatbuffers::DartMakeRule, nullptr, nullptr },
|
||||
{ flatbuffers::GenerateTS, "TypeScript", true, flatbuffers::GenerateTSGRPC,
|
||||
flatbuffers::IDLOptions::kTs,
|
||||
flatbuffers::FlatCOption{ "T", "ts", "",
|
||||
"Generate TypeScript code for tables/structs" },
|
||||
flatbuffers::TSMakeRule, nullptr, nullptr },
|
||||
{ flatbuffers::GenerateCSharp, "C#", true, nullptr,
|
||||
flatbuffers::IDLOptions::kCSharp,
|
||||
flatbuffers::FlatCOption{ "n", "csharp", "",
|
||||
"Generate C# classes for tables/structs" },
|
||||
flatbuffers::CSharpMakeRule, nullptr, nullptr },
|
||||
{ flatbuffers::GeneratePython, "Python", true,
|
||||
flatbuffers::GeneratePythonGRPC, flatbuffers::IDLOptions::kPython,
|
||||
flatbuffers::FlatCOption{ "p", "python", "",
|
||||
"Generate Python files for tables/structs" },
|
||||
nullptr, nullptr, nullptr },
|
||||
{ flatbuffers::GenerateLobster, "Lobster", true, nullptr,
|
||||
flatbuffers::IDLOptions::kLobster,
|
||||
flatbuffers::FlatCOption{ "", "lobster", "",
|
||||
"Generate Lobster files for tables/structs" },
|
||||
nullptr, nullptr, nullptr },
|
||||
{ flatbuffers::GenerateLua, "Lua", true, nullptr,
|
||||
flatbuffers::IDLOptions::kLua,
|
||||
flatbuffers::FlatCOption{ "l", "lua", "",
|
||||
"Generate Lua files for tables/structs" },
|
||||
nullptr, bfbs_gen_lua.get(), nullptr },
|
||||
{ flatbuffers::GenerateRust, "Rust", true, nullptr,
|
||||
flatbuffers::IDLOptions::kRust,
|
||||
flatbuffers::FlatCOption{ "r", "rust", "",
|
||||
"Generate Rust files for tables/structs" },
|
||||
flatbuffers::RustMakeRule, nullptr,
|
||||
flatbuffers::GenerateRustModuleRootFile },
|
||||
{ flatbuffers::GeneratePhp, "PHP", true, nullptr,
|
||||
flatbuffers::IDLOptions::kPhp,
|
||||
flatbuffers::FlatCOption{ "", "php", "",
|
||||
"Generate PHP files for tables/structs" },
|
||||
nullptr, nullptr, nullptr },
|
||||
{ flatbuffers::GenerateKotlin, "Kotlin", true, nullptr,
|
||||
flatbuffers::IDLOptions::kKotlin,
|
||||
flatbuffers::FlatCOption{ "", "kotlin", "",
|
||||
"Generate Kotlin classes for tables/structs" },
|
||||
nullptr, nullptr, nullptr },
|
||||
{ flatbuffers::GenerateJsonSchema, "JsonSchema", true, nullptr,
|
||||
flatbuffers::IDLOptions::kJsonSchema,
|
||||
flatbuffers::FlatCOption{ "", "jsonschema", "", "Generate Json schema" },
|
||||
nullptr, nullptr, nullptr },
|
||||
{ flatbuffers::GenerateSwift, "swift", true, flatbuffers::GenerateSwiftGRPC,
|
||||
flatbuffers::IDLOptions::kSwift,
|
||||
flatbuffers::FlatCOption{ "", "swift", "",
|
||||
"Generate Swift files for tables/structs" },
|
||||
nullptr, nullptr, nullptr },
|
||||
{ nullptr, "Nim", true, nullptr, flatbuffers::IDLOptions::kNim,
|
||||
flatbuffers::FlatCOption{ "", "nim", "",
|
||||
"Generate Nim files for tables/structs" },
|
||||
nullptr, bfbs_gen_nim.get(), nullptr },
|
||||
};
|
||||
|
||||
flatbuffers::FlatCompiler::InitParams params;
|
||||
params.generators = generators;
|
||||
params.num_generators = sizeof(generators) / sizeof(generators[0]);
|
||||
params.warn_fn = Warn;
|
||||
params.error_fn = Error;
|
||||
|
||||
flatbuffers::FlatCompiler flatc(params);
|
||||
return flatc.Compile(argc, argv);
|
||||
|
||||
flatc.RegisterCodeGenerator(
|
||||
flatbuffers::FlatCOption{
|
||||
"b", "binary", "",
|
||||
"Generate wire format binaries for any data definitions" },
|
||||
flatbuffers::NewBinaryCodeGenerator());
|
||||
|
||||
flatc.RegisterCodeGenerator(
|
||||
flatbuffers::FlatCOption{ "c", "cpp", "",
|
||||
"Generate C++ headers for tables/structs" },
|
||||
flatbuffers::NewCppCodeGenerator());
|
||||
|
||||
flatc.RegisterCodeGenerator(
|
||||
flatbuffers::FlatCOption{ "n", "csharp", "",
|
||||
"Generate C# classes for tables/structs" },
|
||||
flatbuffers::NewCSharpCodeGenerator());
|
||||
|
||||
flatc.RegisterCodeGenerator(
|
||||
flatbuffers::FlatCOption{ "d", "dart", "",
|
||||
"Generate Dart classes for tables/structs" },
|
||||
flatbuffers::NewDartCodeGenerator());
|
||||
|
||||
flatc.RegisterCodeGenerator(
|
||||
flatbuffers::FlatCOption{ "", "proto", "",
|
||||
"Input is a .proto, translate to .fbs" },
|
||||
flatbuffers::NewFBSCodeGenerator());
|
||||
|
||||
flatc.RegisterCodeGenerator(
|
||||
flatbuffers::FlatCOption{ "g", "go", "",
|
||||
"Generate Go files for tables/structs" },
|
||||
flatbuffers::NewGoCodeGenerator());
|
||||
|
||||
flatc.RegisterCodeGenerator(
|
||||
flatbuffers::FlatCOption{ "j", "java", "",
|
||||
"Generate Java classes for tables/structs" },
|
||||
flatbuffers::NewJavaCodeGenerator());
|
||||
|
||||
flatc.RegisterCodeGenerator(
|
||||
flatbuffers::FlatCOption{ "", "jsonschema", "", "Generate Json schema" },
|
||||
flatbuffers::NewJsonSchemaCodeGenerator());
|
||||
|
||||
flatc.RegisterCodeGenerator(
|
||||
flatbuffers::FlatCOption{ "", "kotlin", "",
|
||||
"Generate Kotlin classes for tables/structs" },
|
||||
flatbuffers::NewKotlinCodeGenerator());
|
||||
|
||||
flatc.RegisterCodeGenerator(
|
||||
flatbuffers::FlatCOption{ "", "lobster", "",
|
||||
"Generate Lobster files for tables/structs" },
|
||||
flatbuffers::NewLobsterCodeGenerator());
|
||||
|
||||
flatc.RegisterCodeGenerator(
|
||||
flatbuffers::FlatCOption{ "l", "lua", "",
|
||||
"Generate Lua files for tables/structs" },
|
||||
flatbuffers::NewLuaBfbsGenerator(flatbuffers_version));
|
||||
|
||||
flatc.RegisterCodeGenerator(
|
||||
flatbuffers::FlatCOption{ "", "nim", "",
|
||||
"Generate Nim files for tables/structs" },
|
||||
flatbuffers::NewNimBfbsGenerator(flatbuffers_version));
|
||||
|
||||
flatc.RegisterCodeGenerator(
|
||||
flatbuffers::FlatCOption{ "p", "python", "",
|
||||
"Generate Python files for tables/structs" },
|
||||
flatbuffers::NewPythonCodeGenerator());
|
||||
|
||||
flatc.RegisterCodeGenerator(
|
||||
flatbuffers::FlatCOption{ "", "php", "",
|
||||
"Generate PHP files for tables/structs" },
|
||||
flatbuffers::NewPhpCodeGenerator());
|
||||
|
||||
flatc.RegisterCodeGenerator(
|
||||
flatbuffers::FlatCOption{ "r", "rust", "",
|
||||
"Generate Rust files for tables/structs" },
|
||||
flatbuffers::NewRustCodeGenerator());
|
||||
|
||||
flatc.RegisterCodeGenerator(
|
||||
flatbuffers::FlatCOption{
|
||||
"t", "json", "", "Generate text output for any data definitions" },
|
||||
flatbuffers::NewTextCodeGenerator());
|
||||
|
||||
flatc.RegisterCodeGenerator(
|
||||
flatbuffers::FlatCOption{ "", "swift", "",
|
||||
"Generate Swift files for tables/structs" },
|
||||
flatbuffers::NewSwiftCodeGenerator());
|
||||
|
||||
flatc.RegisterCodeGenerator(
|
||||
flatbuffers::FlatCOption{ "T", "ts", "",
|
||||
"Generate TypeScript code for tables/structs" },
|
||||
flatbuffers::NewTsCodeGenerator());
|
||||
|
||||
// Create the FlatC options by parsing the command line arguments.
|
||||
const flatbuffers::FlatCOptions &options =
|
||||
flatc.ParseFromCommandLineArguments(argc, argv);
|
||||
|
||||
// Compile with the extracted FlatC options.
|
||||
return flatc.Compile(options);
|
||||
}
|
||||
|
||||
92
src/idl_gen_binary.cpp
Normal file
92
src/idl_gen_binary.cpp
Normal file
@@ -0,0 +1,92 @@
|
||||
/*
|
||||
* Copyright 2014 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.
|
||||
*/
|
||||
|
||||
// independent from idl_parser, since this code is not needed for most clients
|
||||
|
||||
#include "idl_gen_binary.h"
|
||||
|
||||
#include <limits>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <unordered_set>
|
||||
|
||||
#include "flatbuffers/base.h"
|
||||
#include "flatbuffers/code_generators.h"
|
||||
#include "flatbuffers/flatbuffers.h"
|
||||
#include "flatbuffers/flatc.h"
|
||||
#include "flatbuffers/idl.h"
|
||||
#include "flatbuffers/util.h"
|
||||
|
||||
namespace flatbuffers {
|
||||
|
||||
namespace {
|
||||
|
||||
class BinaryCodeGenerator : public CodeGenerator {
|
||||
public:
|
||||
Status GenerateCode(const Parser &parser, const std::string &path,
|
||||
const std::string &filename) override {
|
||||
if (!GenerateBinary(parser, path, filename)) { return Status::ERROR; }
|
||||
return Status::OK;
|
||||
}
|
||||
|
||||
// Generate code from the provided `buffer` of given `length`. The buffer is a
|
||||
// serialized reflection.fbs.
|
||||
Status GenerateCode(const uint8_t *buffer, int64_t length) override {
|
||||
(void)buffer;
|
||||
(void)length;
|
||||
return Status::NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
Status GenerateMakeRule(const Parser &parser, const std::string &path,
|
||||
const std::string &filename,
|
||||
std::string &output) override {
|
||||
output = BinaryMakeRule(parser, path, filename);
|
||||
return Status::OK;
|
||||
}
|
||||
|
||||
Status GenerateGrpcCode(const Parser &parser, const std::string &path,
|
||||
const std::string &filename) override {
|
||||
(void)parser;
|
||||
(void)path;
|
||||
(void)filename;
|
||||
return Status::NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
Status GenerateRootFile(const Parser &parser,
|
||||
const std::string &path) override {
|
||||
(void)parser;
|
||||
(void)path;
|
||||
return Status::NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
bool IsSchemaOnly() const override { return false; }
|
||||
|
||||
bool SupportsBfbsGeneration() const override { return false; }
|
||||
|
||||
bool SupportsRootFileGeneration() const override { return false; }
|
||||
|
||||
IDLOptions::Language Language() const override { return IDLOptions::kBinary; }
|
||||
|
||||
std::string LanguageName() const override { return "binary"; }
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
std::unique_ptr<CodeGenerator> NewBinaryCodeGenerator() {
|
||||
return std::unique_ptr<BinaryCodeGenerator>(new BinaryCodeGenerator());
|
||||
}
|
||||
|
||||
} // namespace flatbuffers
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2021 Google Inc. All rights reserved.
|
||||
* 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.
|
||||
@@ -14,30 +14,19 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef FLATBUFFERS_BFBS_GENERATOR_H_
|
||||
#define FLATBUFFERS_BFBS_GENERATOR_H_
|
||||
#ifndef FLATBUFFERS_IDL_GEN_BINARY_H_
|
||||
#define FLATBUFFERS_IDL_GEN_BINARY_H_
|
||||
|
||||
#include <cstdint>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
#include "flatbuffers/code_generator.h"
|
||||
|
||||
namespace flatbuffers {
|
||||
|
||||
enum GeneratorStatus {
|
||||
OK,
|
||||
FAILED,
|
||||
FAILED_VERIFICATION,
|
||||
};
|
||||
|
||||
// A Flatbuffer Code Generator that receives a binary serialized reflection.fbs
|
||||
// and generates code from it.
|
||||
class BfbsGenerator {
|
||||
public:
|
||||
virtual ~BfbsGenerator() {}
|
||||
|
||||
// Generate code from the provided `buffer` of given `length`. The buffer is
|
||||
// a serialized reflection.fbs.
|
||||
virtual GeneratorStatus Generate(const uint8_t *buffer, int64_t length) = 0;
|
||||
};
|
||||
// Constructs a new Binary code generator.
|
||||
std::unique_ptr<CodeGenerator> NewBinaryCodeGenerator();
|
||||
|
||||
} // namespace flatbuffers
|
||||
|
||||
#endif // FLATBUFFERS_BFBS_GENERATOR_H_
|
||||
#endif // FLATBUFFERS_IDL_GEN_BINARY_H_
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user