mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-02 12:05:50 +00:00
Compare commits
53 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
72b56fd081 | ||
|
|
63b7b25289 | ||
|
|
13fc75cb6b | ||
|
|
e6e38a8d17 | ||
|
|
d9f2cc2d62 | ||
|
|
197ae6cc7e | ||
|
|
489d9735e9 | ||
|
|
3308444147 | ||
|
|
ef5ae488dd | ||
|
|
08efe60954 | ||
|
|
01a7bc3c58 | ||
|
|
67084b9921 | ||
|
|
ed11b08fc9 | ||
|
|
c1e7aee489 | ||
|
|
75143f836b | ||
|
|
fb4f6fb894 | ||
|
|
19d8942943 | ||
|
|
dbce69c63b | ||
|
|
aeba096403 | ||
|
|
966aae2144 | ||
|
|
e7dc252b0e | ||
|
|
4172c3f0bd | ||
|
|
417821fdd7 | ||
|
|
c192ab423b | ||
|
|
a397dd7e8c | ||
|
|
6eae49a79a | ||
|
|
f6af2087ee | ||
|
|
ab716ee41d | ||
|
|
d6d83c3a92 | ||
|
|
aa6848fbf6 | ||
|
|
6c8a8d054d | ||
|
|
63495b935a | ||
|
|
56ecc1f548 | ||
|
|
3fda20d7c7 | ||
|
|
fa3fa91936 | ||
|
|
52f2596e15 | ||
|
|
0916f1c87e | ||
|
|
0888e7cb4d | ||
|
|
876a64aae1 | ||
|
|
2803983c70 | ||
|
|
88dd92de40 | ||
|
|
477b1b5d13 | ||
|
|
1cb1c4baee | ||
|
|
50cdf92e1e | ||
|
|
9a7fb4d68a | ||
|
|
3cb27fa241 | ||
|
|
d3d7e2ef99 | ||
|
|
d4d355d883 | ||
|
|
0fde16e426 | ||
|
|
32a6744286 | ||
|
|
42ee479c31 | ||
|
|
df007dfde8 | ||
|
|
d44ce00af1 |
1
.bazelignore
Normal file
1
.bazelignore
Normal file
@@ -0,0 +1 @@
|
||||
node_modules
|
||||
4
.bazelrc
Normal file
4
.bazelrc
Normal file
@@ -0,0 +1,4 @@
|
||||
# We cannot use "common" here because the "version" command doesn't support
|
||||
# --deleted_packages. We need to specify it for both build and query instead.
|
||||
build --deleted_packages=tests/ts/bazel_repository_test_dir
|
||||
query --deleted_packages=tests/ts/bazel_repository_test_dir
|
||||
15
.github/workflows/build.yml
vendored
15
.github/workflows/build.yml
vendored
@@ -9,6 +9,7 @@ on:
|
||||
- "*" # new tag version, like `0.8.4` or else
|
||||
branches:
|
||||
- master
|
||||
- flatbuffers-64
|
||||
pull_request:
|
||||
branches:
|
||||
- master
|
||||
@@ -29,7 +30,7 @@ jobs:
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- name: cmake
|
||||
run: CXX=${{ matrix.cxx }} cmake -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=Release -DFLATBUFFERS_STRICT_MODE=ON .
|
||||
run: CXX=${{ matrix.cxx }} cmake -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=Release -DFLATBUFFERS_STRICT_MODE=ON -DFLATBUFFERS_STATIC_FLATC=ON .
|
||||
- name: build
|
||||
run: make -j
|
||||
- name: test
|
||||
@@ -59,11 +60,11 @@ jobs:
|
||||
- name: Generate SLSA subjects - clang
|
||||
if: matrix.cxx == 'clang++-12' && startsWith(github.ref, 'refs/tags/')
|
||||
id: hash-clang
|
||||
run: echo "::set-output name=hashes::$(sha256sum Linux.flatc.binary.${{ matrix.cxx }}.zip | base64 -w0)"
|
||||
run: echo "hashes=$(sha256sum Linux.flatc.binary.${{ matrix.cxx }}.zip | base64 -w0)" >> $GITHUB_OUTPUT
|
||||
- name: Generate SLSA subjects - gcc
|
||||
if: matrix.cxx == 'g++-10' && startsWith(github.ref, 'refs/tags/')
|
||||
id: hash-gcc
|
||||
run: echo "::set-output name=hashes::$(sha256sum Linux.flatc.binary.${{ matrix.cxx }}.zip | base64 -w0)"
|
||||
run: echo "hashes=$(sha256sum Linux.flatc.binary.${{ matrix.cxx }}.zip | base64 -w0)" >> $GITHUB_OUTPUT
|
||||
|
||||
build-linux-no-file-tests:
|
||||
name: Build Linux with -DFLATBUFFERS_NO_FILE_TESTS
|
||||
@@ -165,7 +166,7 @@ jobs:
|
||||
if: startsWith(github.ref, 'refs/tags/')
|
||||
id: hash
|
||||
shell: bash
|
||||
run: echo "::set-output name=hashes::$(sha256sum Windows.flatc.binary.zip | base64 -w0)"
|
||||
run: echo "hashes=$(sha256sum Windows.flatc.binary.zip | base64 -w0)" >> $GITHUB_OUTPUT
|
||||
|
||||
build-windows-2017:
|
||||
name: Build Windows 2017
|
||||
@@ -266,7 +267,7 @@ jobs:
|
||||
- name: Generate SLSA subjects
|
||||
if: startsWith(github.ref, 'refs/tags/')
|
||||
id: hash
|
||||
run: echo "::set-output name=hashes::$(shasum -a 256 MacIntel.flatc.binary.zip | base64)"
|
||||
run: echo "hashes=$(shasum -a 256 MacIntel.flatc.binary.zip | base64)" >> $GITHUB_OUTPUT
|
||||
|
||||
build-mac-universal:
|
||||
permissions:
|
||||
@@ -309,7 +310,7 @@ jobs:
|
||||
- name: Generate SLSA subjects
|
||||
if: startsWith(github.ref, 'refs/tags/')
|
||||
id: hash
|
||||
run: echo "::set-output name=hashes::$(shasum -a 256 Mac.flatc.binary.zip | base64)"
|
||||
run: echo "hashes=$(shasum -a 256 Mac.flatc.binary.zip | base64)" >> $GITHUB_OUTPUT
|
||||
|
||||
build-android:
|
||||
name: Build Android (on Linux)
|
||||
@@ -560,7 +561,7 @@ jobs:
|
||||
echo "$MAC_DIGESTS" | base64 -d >> checksums.txt
|
||||
echo "$MACINTEL_DIGESTS" | base64 -d >> checksums.txt
|
||||
echo "$WINDOWS_DIGESTS" | base64 -d >> checksums.txt
|
||||
echo "::set-output name=digests::$(cat checksums.txt | base64 -w0)"
|
||||
echo "digests=$(cat checksums.txt | base64 -w0)" >> $GITHUB_OUTPUT
|
||||
|
||||
provenance:
|
||||
if: startsWith(github.ref, 'refs/tags/')
|
||||
|
||||
33
.github/workflows/stale.yml
vendored
33
.github/workflows/stale.yml
vendored
@@ -1,9 +1,13 @@
|
||||
name: Mark stale issues and pull requests
|
||||
permissions: read-all
|
||||
permissions:
|
||||
issues: write
|
||||
pull-requests: write
|
||||
|
||||
on:
|
||||
# For manual tests.
|
||||
workflow_dispatch:
|
||||
schedule:
|
||||
- cron: "30 20 * * *"
|
||||
- cron: "30 20 * * *"
|
||||
|
||||
jobs:
|
||||
stale:
|
||||
@@ -11,14 +15,23 @@ jobs:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- uses: actions/stale@v4.0.0
|
||||
- uses: actions/stale@v7.0.0
|
||||
with:
|
||||
repo-token: ${{ secrets.GITHUB_TOKEN }}
|
||||
stale-pr-message: 'This pull request is stale because it has been open 6 months with no activity. Please comment or this will be closed in 14 days.'
|
||||
stale-issue-message: 'This issue is stale because it has been open 6 months with no activity. Please comment or this will be closed in 14 days.'
|
||||
days-before-stale: 182 # 6 months
|
||||
days-before-close: 14
|
||||
operations-per-run: 1500
|
||||
exempt-issue-labels: not-stale
|
||||
exempt-pr-labels: not-stale
|
||||
operations-per-run: 500
|
||||
exempt-all-milestones: true
|
||||
remove-stale-when-updated: true
|
||||
|
||||
stale-issue-message: 'This issue is stale because it has been open 6 months with no activity. Please comment or label `not-stale`, or this will be closed in 14 days.'
|
||||
close-issue-message: 'This issue was automatically closed due to no activity for 6 months plus the 14 day notice period.'
|
||||
days-before-issue-stale: 182 # 6 months
|
||||
days-before-issue-close: 14 # 2 weeks
|
||||
exempt-issue-labels: not-stale
|
||||
|
||||
stale-pr-message: 'This pull request is stale because it has been open 3 weeks with no activity. Please comment or label `not-stale`, or this will be closed in 7 days.'
|
||||
close-pr-message: 'This pull request was automatically closed due to no activity for 3 weeks plus the 7 day notice period.'
|
||||
days-before-pr-stale: 21 # 3 weeks
|
||||
days-before-pr-close: 7 # 1 week
|
||||
exempt-pr-labels: not-stale
|
||||
exempt-draft-pr: false
|
||||
|
||||
|
||||
27
BUILD.bazel
27
BUILD.bazel
@@ -1,3 +1,5 @@
|
||||
load("@aspect_rules_js//npm:defs.bzl", "npm_link_package")
|
||||
load("@npm//:defs.bzl", "npm_link_all_packages")
|
||||
load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_library")
|
||||
|
||||
licenses(["notice"])
|
||||
@@ -6,6 +8,13 @@ package(
|
||||
default_visibility = ["//visibility:public"],
|
||||
)
|
||||
|
||||
npm_link_all_packages(name = "node_modules")
|
||||
|
||||
npm_link_package(
|
||||
name = "node_modules/flatbuffers",
|
||||
src = "//ts:flatbuffers",
|
||||
)
|
||||
|
||||
exports_files([
|
||||
"LICENSE",
|
||||
"tsconfig.json",
|
||||
@@ -25,6 +34,23 @@ config_setting(
|
||||
],
|
||||
)
|
||||
|
||||
filegroup(
|
||||
name = "distribution",
|
||||
srcs = [
|
||||
"BUILD.bazel",
|
||||
"WORKSPACE",
|
||||
"build_defs.bzl",
|
||||
"typescript.bzl",
|
||||
"//grpc/src/compiler:distribution",
|
||||
"//reflection:distribution",
|
||||
"//src:distribution",
|
||||
"//ts:distribution",
|
||||
] + glob([
|
||||
"include/flatbuffers/*.h",
|
||||
]),
|
||||
visibility = ["//visibility:public"],
|
||||
)
|
||||
|
||||
# Public flatc library to compile flatbuffer files at runtime.
|
||||
cc_library(
|
||||
name = "flatbuffers",
|
||||
@@ -47,6 +73,7 @@ filegroup(
|
||||
"include/flatbuffers/code_generators.h",
|
||||
"include/flatbuffers/default_allocator.h",
|
||||
"include/flatbuffers/detached_buffer.h",
|
||||
"include/flatbuffers/file_manager.h",
|
||||
"include/flatbuffers/flatbuffer_builder.h",
|
||||
"include/flatbuffers/flatbuffers.h",
|
||||
"include/flatbuffers/flex_flat_util.h",
|
||||
|
||||
47
CHANGELOG.md
47
CHANGELOG.md
@@ -4,6 +4,53 @@ 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.5.9 (May 9 2023)](https://github.com/google/flatbuffers/releases/tag/v23.5.9)
|
||||
|
||||
* 64-bit support for C++ (#7935)
|
||||
|
||||
## [23.5.8 (May 8 2023)](https://github.com/google/flatbuffers/releases/tag/v23.5.8)
|
||||
|
||||
* add key_field to compiled tests
|
||||
* Add golden language directory
|
||||
* Rework cmake flatc codegeneration (#7938)
|
||||
* remove defining generated files in test srcs
|
||||
* Add binary schema reflection (#7932)
|
||||
* Migrate from rules_nodejs to rules_js/rules_ts (take 2) (#7928)
|
||||
* `flat_buffers.dart`: mark const variable finals for internal Dart linters
|
||||
* fixed some windows warnings (#7929)
|
||||
* inject no long for FBS generation to remove logs in flattests (#7926)
|
||||
* Revert "Migrate from rules_nodejs to rules_js/rules_ts (#7923)" (#7927)
|
||||
* Migrate from rules_nodejs to rules_js/rules_ts (#7923)
|
||||
* Only generate @kotlin.ExperimentalUnsigned annotation on create*Vector methods having an unsigned array type parameter. (#7881)
|
||||
* additional check for absl::string_view availability (#7897)
|
||||
* Optionally generate Python type annotations (#7858)
|
||||
* Replace deprecated command with environment file (#7921)
|
||||
* drop glibc from runtime dependencies (#7906)
|
||||
* Make JSON supporting advanced union features (#7869)
|
||||
* Allow to use functions from `BuildFlatBuffers.cmake` from a flatbuffers installation installed with CMake. (#7912)
|
||||
* TS/JS: Use TypeError instead of Error when appropriate (#7910)
|
||||
* Go: make generated code more compliant to "go fmt" (#7907)
|
||||
* Support file_identifier in Go (#7904)
|
||||
* Optionally generate type prefixes and suffixes for python code (#7857)
|
||||
* Go: add test for FinishWithFileIdentifier (#7905)
|
||||
* Fix go_sample.sh (#7903)
|
||||
* [TS/JS] Upgrade dependencies (#7889)
|
||||
* Add a FileWriter interface (#7821)
|
||||
* TS/JS: Use minvalue from enum if not found (#7888)
|
||||
* [CS] Verifier (#7850)
|
||||
* README.md: PyPI case typo (#7880)
|
||||
* Update go documentation link to point to root module (#7879)
|
||||
* use Bool for flatbuffers bool instead of Byte (#7876)
|
||||
* fix using null string in vector (#7872)
|
||||
* Add `flatbuffers-64` branch to CI for pushes
|
||||
* made changes to the rust docs so they would compile. new_with_capacity is deprecated should use with_capacity, get_root_as_monster should be root_as_monster (#7871)
|
||||
* Adding comment for code clarification (#7856)
|
||||
* ToCamelCase() when kLowerCamel now converts first char to lower. (#7838)
|
||||
* Fix help output for --java-checkerframework (#7854)
|
||||
* Update filename to README.md and improve formatting (#7855)
|
||||
* Update stale.yml
|
||||
* Updated remaining usages of LICENSE.txt
|
||||
|
||||
## [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).
|
||||
|
||||
@@ -59,6 +59,9 @@ function(build_flatbuffers flatbuffers_schemas
|
||||
if(FLATBUFFERS_FLATC_EXECUTABLE)
|
||||
set(FLATC_TARGET "")
|
||||
set(FLATC ${FLATBUFFERS_FLATC_EXECUTABLE})
|
||||
elseif(TARGET flatbuffers::flatc)
|
||||
set(FLATC_TARGET flatbuffers::flatc)
|
||||
set(FLATC flatbuffers::flatc)
|
||||
else()
|
||||
set(FLATC_TARGET flatc)
|
||||
set(FLATC flatc)
|
||||
@@ -211,6 +214,9 @@ function(flatbuffers_generate_headers)
|
||||
if(FLATBUFFERS_FLATC_EXECUTABLE)
|
||||
set(FLATC_TARGET "")
|
||||
set(FLATC ${FLATBUFFERS_FLATC_EXECUTABLE})
|
||||
elseif(TARGET flatbuffers::flatc)
|
||||
set(FLATC_TARGET flatbuffers::flatc)
|
||||
set(FLATC flatbuffers::flatc)
|
||||
else()
|
||||
set(FLATC_TARGET flatc)
|
||||
set(FLATC flatc)
|
||||
@@ -382,6 +388,9 @@ function(flatbuffers_generate_binary_files)
|
||||
if(FLATBUFFERS_FLATC_EXECUTABLE)
|
||||
set(FLATC_TARGET "")
|
||||
set(FLATC ${FLATBUFFERS_FLATC_EXECUTABLE})
|
||||
elseif(TARGET flatbuffers::flatc)
|
||||
set(FLATC_TARGET flatbuffers::flatc)
|
||||
set(FLATC flatbuffers::flatc)
|
||||
else()
|
||||
set(FLATC_TARGET flatc)
|
||||
set(FLATC flatc)
|
||||
|
||||
@@ -22,7 +22,7 @@ if (UNIX)
|
||||
|
||||
set(CPACK_RPM_PACKAGE_VENDOR "Google, Inc.")
|
||||
set(CPACK_RPM_PACKAGE_LICENSE "Apache 2.0")
|
||||
set(CPACK_RESOURCE_FILE_LICENSE ${CMAKE_SOURCE_DIR}/LICENSE.txt)
|
||||
set(CPACK_RESOURCE_FILE_LICENSE ${CMAKE_SOURCE_DIR}/LICENSE)
|
||||
set(CPACK_PACKAGE_DESCRIPTION_FILE ${CMAKE_SOURCE_DIR}/CMake/DESCRIPTION.txt)
|
||||
|
||||
# This may reduce rpm compatiblity with very old systems.
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
set(VERSION_MAJOR 23)
|
||||
set(VERSION_MINOR 3)
|
||||
set(VERSION_PATCH 3)
|
||||
set(VERSION_MINOR 5)
|
||||
set(VERSION_PATCH 9)
|
||||
set(VERSION_COMMIT 0)
|
||||
|
||||
if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/.git")
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
include("${CMAKE_CURRENT_LIST_DIR}/FlatBuffersTargets.cmake" OPTIONAL)
|
||||
include("${CMAKE_CURRENT_LIST_DIR}/FlatcTargets.cmake" OPTIONAL)
|
||||
include("${CMAKE_CURRENT_LIST_DIR}/FlatBuffersSharedTargets.cmake" OPTIONAL)
|
||||
include("${CMAKE_CURRENT_LIST_DIR}/BuildFlatBuffers.cmake" OPTIONAL)
|
||||
203
CMakeLists.txt
203
CMakeLists.txt
@@ -21,7 +21,7 @@ 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_FLATHASH "Enable the build of flathash" OFF)
|
||||
option(FLATBUFFERS_BUILD_BENCHMARKS "Enable the build of flatbenchmark."
|
||||
OFF)
|
||||
option(FLATBUFFERS_BUILD_GRPCTEST "Enable the build of grpctest" OFF)
|
||||
@@ -127,6 +127,7 @@ set(FlatBuffers_Library_SRCS
|
||||
include/flatbuffers/default_allocator.h
|
||||
include/flatbuffers/detached_buffer.h
|
||||
include/flatbuffers/code_generator.h
|
||||
include/flatbuffers/file_manager.h
|
||||
include/flatbuffers/flatbuffer_builder.h
|
||||
include/flatbuffers/flatbuffers.h
|
||||
include/flatbuffers/flexbuffers.h
|
||||
@@ -171,6 +172,9 @@ set(FlatBuffers_Compiler_SRCS
|
||||
src/idl_gen_grpc.cpp
|
||||
src/idl_gen_json_schema.cpp
|
||||
src/idl_gen_swift.cpp
|
||||
src/file_name_saving_file_manager.cpp
|
||||
src/file_binary_writer.cpp
|
||||
src/file_writer.cpp
|
||||
src/idl_namer.h
|
||||
src/namer.h
|
||||
src/flatc.cpp
|
||||
@@ -230,31 +234,10 @@ set(FlatBuffers_Tests_SRCS
|
||||
tests/native_type_test_impl.cpp
|
||||
tests/alignment_test.h
|
||||
tests/alignment_test.cpp
|
||||
tests/64bit/offset64_test.h
|
||||
tests/64bit/offset64_test.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
|
||||
# file generate by running compiler on tests/native_inline_table_test.fbs
|
||||
${CMAKE_CURRENT_BINARY_DIR}/tests/native_inline_table_test_generated.h
|
||||
# file generate by running compiler on tests/alignment_test.fbs
|
||||
${CMAKE_CURRENT_BINARY_DIR}/tests/alignment_test_generated.h
|
||||
# file generate by running compiler on tests/key_field/key_field_sample.fbs
|
||||
${CMAKE_CURRENT_BINARY_DIR}/tests/key_field/key_field_sample_generated.h
|
||||
)
|
||||
|
||||
set(FlatBuffers_Tests_CPP17_SRCS
|
||||
@@ -262,32 +245,21 @@ set(FlatBuffers_Tests_CPP17_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
|
||||
@@ -303,8 +275,6 @@ set(FlatBuffers_GRPCTest_SRCS
|
||||
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
|
||||
)
|
||||
|
||||
# TODO(dbaileychess): Figure out how this would now work. I posted a question on
|
||||
@@ -519,144 +489,68 @@ if(FLATBUFFERS_BUILD_SHAREDLIB)
|
||||
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}'")
|
||||
function(compile_schema SRC_FBS OPT OUT_GEN_FILE)
|
||||
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})
|
||||
add_custom_command(TARGET flatc POST_BUILD
|
||||
COMMAND "${FLATBUFFERS_FLATC_EXECUTABLE}"
|
||||
${OPT}
|
||||
-o "${SRC_FBS_DIR}"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/${SRC_FBS}"
|
||||
BYPRODUCTS ${GEN_HEADER}
|
||||
COMMENT "flatc generation: `${SRC_FBS}` -> `${GEN_HEADER}`"
|
||||
)
|
||||
set(${OUT_GEN_FILE} ${GEN_HEADER} PARENT_SCOPE)
|
||||
endfunction()
|
||||
|
||||
function(compile_flatbuffers_schema_to_cpp SRC_FBS)
|
||||
compile_flatbuffers_schema_to_cpp_opt(${SRC_FBS} "--no-includes;--gen-compare")
|
||||
function(compile_schema_for_test SRC_FBS OPT)
|
||||
compile_schema("${SRC_FBS}" "${OPT}" GEN_FILE)
|
||||
target_sources(flattests PRIVATE ${GEN_FILE})
|
||||
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 "${CMAKE_CURRENT_SOURCE_DIR}/${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})
|
||||
function(compile_schema_for_samples SRC_FBS OPT)
|
||||
compile_schema("${SRC_FBS}" "${OPT}" GEN_FILE)
|
||||
target_sources(flatsamplebinary PRIVATE ${GEN_FILE})
|
||||
target_sources(flatsampletext PRIVATE ${GEN_FILE})
|
||||
target_sources(flatsamplebfbs PRIVATE ${GEN_FILE})
|
||||
endfunction()
|
||||
|
||||
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;")
|
||||
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")
|
||||
compile_flatbuffers_schema_to_cpp(tests/native_inline_table_test.fbs "--gen-compare")
|
||||
compile_flatbuffers_schema_to_cpp(tests/alignment_test.fbs "--gen-compare")
|
||||
compile_flatbuffers_schema_to_cpp(tests/key_field/key_field_sample.fbs)
|
||||
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})
|
||||
target_link_libraries(flattests PRIVATE $<BUILD_INTERFACE:ProjectConfig>)
|
||||
target_include_directories(flattests PUBLIC src)
|
||||
|
||||
add_dependencies(flattests generated_code)
|
||||
# The flattest target needs some generated files
|
||||
SET(FLATC_OPT --cpp --gen-mutable --gen-object-api --reflect-names)
|
||||
SET(FLATC_OPT_COMP ${FLATC_OPT};--gen-compare)
|
||||
|
||||
compile_schema_for_test(tests/alignment_test.fbs "${FLATC_OPT_COMP}")
|
||||
compile_schema_for_test(tests/native_inline_table_test.fbs "${FLATC_OPT_COMP}")
|
||||
compile_schema_for_test(tests/native_type_test.fbs "${FLATC_OPT}")
|
||||
compile_schema_for_test(tests/key_field/key_field_sample.fbs "${FLATC_OPT_COMP}")
|
||||
compile_schema_for_test(tests/64bit/test_64bit.fbs "${FLATC_OPT_COMP};--bfbs-gen-embed")
|
||||
compile_schema_for_test(tests/64bit/evolution/v1.fbs "${FLATC_OPT_COMP}")
|
||||
compile_schema_for_test(tests/64bit/evolution/v2.fbs "${FLATC_OPT_COMP}")
|
||||
|
||||
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})
|
||||
target_link_libraries(flatsamplebinary PRIVATE $<BUILD_INTERFACE:ProjectConfig>)
|
||||
add_dependencies(flatsamplebinary generated_code)
|
||||
|
||||
add_executable(flatsampletext ${FlatBuffers_Sample_Text_SRCS})
|
||||
target_link_libraries(flatsampletext PRIVATE $<BUILD_INTERFACE:ProjectConfig>)
|
||||
add_dependencies(flatsampletext generated_code)
|
||||
|
||||
add_executable(flatsamplebfbs ${FlatBuffers_Sample_BFBS_SRCS})
|
||||
|
||||
target_link_libraries(flatsamplebinary PRIVATE $<BUILD_INTERFACE:ProjectConfig>)
|
||||
target_link_libraries(flatsampletext PRIVATE $<BUILD_INTERFACE:ProjectConfig>)
|
||||
target_link_libraries(flatsamplebfbs PRIVATE $<BUILD_INTERFACE:ProjectConfig>)
|
||||
add_dependencies(flatsamplebfbs generated_code)
|
||||
|
||||
compile_schema_for_samples(samples/monster.fbs "${FLATC_OPT_COMP}")
|
||||
|
||||
if(FLATBUFFERS_BUILD_CPP17)
|
||||
# Don't generate header for flattests_cpp17 target.
|
||||
# This target uses "generated_cpp17/monster_test_generated.h"
|
||||
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) # requires cmake 3.8
|
||||
|
||||
@@ -681,7 +575,6 @@ if(FLATBUFFERS_BUILD_GRPCTEST)
|
||||
find_package(protobuf CONFIG REQUIRED)
|
||||
find_package(gRPC CONFIG REQUIRED)
|
||||
add_executable(grpctest ${FlatBuffers_GRPCTest_SRCS})
|
||||
add_dependencies(grpctest generated_code)
|
||||
target_link_libraries(grpctext
|
||||
PRIVATE
|
||||
$<BUILD_INTERFACE:ProjectConfig>
|
||||
@@ -774,16 +667,6 @@ if(FLATBUFFERS_BUILD_TESTS)
|
||||
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)
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
Pod::Spec.new do |s|
|
||||
s.name = 'FlatBuffers'
|
||||
s.version = '23.3.3'
|
||||
s.version = '23.5.9'
|
||||
s.summary = 'FlatBuffers: Memory Efficient Serialization Library'
|
||||
|
||||
s.description = "FlatBuffers is a cross platform serialization library architected for
|
||||
|
||||
@@ -17,11 +17,11 @@ maximum memory efficiency. It allows you to directly access serialized data with
|
||||
**Go to our [landing page][] to browse our documentation.**
|
||||
|
||||
## Supported operating systems
|
||||
* Windows
|
||||
* macOS
|
||||
* Linux
|
||||
* Android
|
||||
* And any others with a recent C++ compiler (C++ 11 and newer)
|
||||
- Windows
|
||||
- macOS
|
||||
- Linux
|
||||
- Android
|
||||
- And any others with a recent C++ compiler (C++ 11 and newer)
|
||||
|
||||
## Supported programming languages
|
||||
|
||||
@@ -31,14 +31,14 @@ Code generation and runtime libraries for many popular languages.
|
||||
1. C++ - [snapcraft.io](https://snapcraft.io/flatbuffers)
|
||||
1. C# - [nuget.org](https://www.nuget.org/packages/Google.FlatBuffers)
|
||||
1. Dart - [pub.dev](https://pub.dev/packages/flat_buffers)
|
||||
1. Go - [go.dev](https://pkg.go.dev/github.com/google/flatbuffers/go)
|
||||
1. Go - [go.dev](https://pkg.go.dev/github.com/google/flatbuffers)
|
||||
1. Java - [Maven](https://search.maven.org/artifact/com.google.flatbuffers/flatbuffers-java)
|
||||
1. JavaScript - [NPM](https://www.npmjs.com/package/flatbuffers)
|
||||
1. Kotlin
|
||||
1. Lobster
|
||||
1. Lua
|
||||
1. PHP
|
||||
1. Python - [PyPi](https://pypi.org/project/flatbuffers/)
|
||||
1. Python - [PyPI](https://pypi.org/project/flatbuffers/)
|
||||
1. Rust - [crates.io](https://crates.io/crates/flatbuffers)
|
||||
1. Swift - [swiftpackageindex](https://swiftpackageindex.com/google/flatbuffers)
|
||||
1. TypeScript - [NPM](https://www.npmjs.com/package/flatbuffers)
|
||||
84
WORKSPACE
84
WORKSPACE
@@ -1,6 +1,6 @@
|
||||
workspace(name = "com_github_google_flatbuffers")
|
||||
|
||||
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
|
||||
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive", "http_file")
|
||||
|
||||
http_archive(
|
||||
name = "platforms",
|
||||
@@ -76,30 +76,80 @@ load("@com_github_grpc_grpc//bazel:grpc_extra_deps.bzl", "grpc_extra_deps")
|
||||
grpc_extra_deps()
|
||||
|
||||
# rules_go from https://github.com/bazelbuild/rules_go/releases/tag/v0.34.0
|
||||
|
||||
http_archive(
|
||||
name = "build_bazel_rules_nodejs",
|
||||
sha256 = "965ee2492a2b087cf9e0f2ca472aeaf1be2eb650e0cfbddf514b9a7d3ea4b02a",
|
||||
urls = ["https://github.com/bazelbuild/rules_nodejs/releases/download/5.2.0/rules_nodejs-5.2.0.tar.gz"],
|
||||
name = "aspect_rules_js",
|
||||
sha256 = "124ed29fb0b3d0cba5b44f8f8e07897cf61b34e35e33b1f83d1a943dfd91b193",
|
||||
strip_prefix = "rules_js-1.24.0",
|
||||
url = "https://github.com/aspect-build/rules_js/releases/download/v1.24.0/rules_js-v1.24.0.tar.gz",
|
||||
)
|
||||
|
||||
load("@build_bazel_rules_nodejs//:repositories.bzl", "build_bazel_rules_nodejs_dependencies")
|
||||
load("@aspect_rules_js//js:repositories.bzl", "rules_js_dependencies")
|
||||
|
||||
build_bazel_rules_nodejs_dependencies()
|
||||
rules_js_dependencies()
|
||||
|
||||
load("@build_bazel_rules_nodejs//:index.bzl", "node_repositories", "yarn_install")
|
||||
load("@aspect_rules_js//npm:npm_import.bzl", "npm_translate_lock", "pnpm_repository")
|
||||
|
||||
node_repositories()
|
||||
pnpm_repository(name = "pnpm")
|
||||
|
||||
yarn_install(
|
||||
http_archive(
|
||||
name = "aspect_rules_ts",
|
||||
sha256 = "8eb25d1fdafc0836f5778d33fb8eaac37c64176481d67872b54b0a05de5be5c0",
|
||||
strip_prefix = "rules_ts-1.3.3",
|
||||
url = "https://github.com/aspect-build/rules_ts/releases/download/v1.3.3/rules_ts-v1.3.3.tar.gz",
|
||||
)
|
||||
|
||||
load("@aspect_rules_ts//ts:repositories.bzl", "rules_ts_dependencies")
|
||||
|
||||
rules_ts_dependencies(
|
||||
# Since rules_ts doesn't always have the newest integrity hashes, we
|
||||
# compute it manually here.
|
||||
# $ curl --silent https://registry.npmjs.org/typescript/5.0.4 | jq ._integrity
|
||||
ts_integrity = "sha512-cW9T5W9xY37cc+jfEnaUvX91foxtHkza3Nw3wkoF4sSlKn0MONdkdEndig/qPBWXNkmplh3NzayQzCiHM4/hqw==",
|
||||
ts_version_from = "//:package.json",
|
||||
)
|
||||
|
||||
load("@rules_nodejs//nodejs:repositories.bzl", "DEFAULT_NODE_VERSION", "nodejs_register_toolchains")
|
||||
|
||||
nodejs_register_toolchains(
|
||||
name = "nodejs",
|
||||
node_version = DEFAULT_NODE_VERSION,
|
||||
)
|
||||
|
||||
npm_translate_lock(
|
||||
name = "npm",
|
||||
exports_directories_only = False,
|
||||
# Unfreeze to add/remove packages.
|
||||
frozen_lockfile = False,
|
||||
package_json = "//:package.json",
|
||||
symlink_node_modules = False,
|
||||
yarn_lock = "//:yarn.lock",
|
||||
npmrc = "//:.npmrc",
|
||||
pnpm_lock = "//:pnpm-lock.yaml",
|
||||
# Set this to True when the lock file needs to be updated, commit the
|
||||
# changes, then set to False again.
|
||||
update_pnpm_lock = False,
|
||||
verify_node_modules_ignored = "//:.bazelignore",
|
||||
)
|
||||
|
||||
load("@build_bazel_rules_nodejs//toolchains/esbuild:esbuild_repositories.bzl", "esbuild_repositories")
|
||||
load("@npm//:repositories.bzl", "npm_repositories")
|
||||
|
||||
esbuild_repositories(npm_repository = "npm")
|
||||
npm_repositories()
|
||||
|
||||
http_archive(
|
||||
name = "aspect_rules_esbuild",
|
||||
sha256 = "2ea31bd97181a315e048be693ddc2815fddda0f3a12ca7b7cc6e91e80f31bac7",
|
||||
strip_prefix = "rules_esbuild-0.14.4",
|
||||
url = "https://github.com/aspect-build/rules_esbuild/releases/download/v0.14.4/rules_esbuild-v0.14.4.tar.gz",
|
||||
)
|
||||
|
||||
# Register a toolchain containing esbuild npm package and native bindings
|
||||
load("@aspect_rules_esbuild//esbuild:repositories.bzl", "LATEST_VERSION", "esbuild_register_toolchains")
|
||||
|
||||
esbuild_register_toolchains(
|
||||
name = "esbuild",
|
||||
esbuild_version = LATEST_VERSION,
|
||||
)
|
||||
|
||||
http_file(
|
||||
name = "bazel_linux_x86_64",
|
||||
downloaded_file_path = "bazel",
|
||||
sha256 = "e89747d63443e225b140d7d37ded952dacea73aaed896bca01ccd745827c6289",
|
||||
urls = [
|
||||
"https://github.com/bazelbuild/bazel/releases/download/6.1.2/bazel-6.1.2-linux-x86_64",
|
||||
],
|
||||
)
|
||||
|
||||
@@ -57,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_3_3()
|
||||
fun validateVersion() = Constants.FLATBUFFERS_23_5_9()
|
||||
fun getRootAsAnimal(_bb: ByteBuffer): Animal = getRootAsAnimal(_bb, Animal())
|
||||
fun getRootAsAnimal(_bb: ByteBuffer, obj: Animal): Animal {
|
||||
_bb.order(ByteOrder.LITTLE_ENDIAN)
|
||||
|
||||
@@ -48,7 +48,10 @@ def flatbuffer_library_public(
|
||||
restricted_to = None,
|
||||
target_compatible_with = None,
|
||||
flatc_path = "@com_github_google_flatbuffers//:flatc",
|
||||
output_to_bindir = False):
|
||||
output_to_bindir = False,
|
||||
tools = None,
|
||||
extra_env = None,
|
||||
**kwargs):
|
||||
"""Generates code files for reading/writing the given flatbuffers in the requested language using the public compiler.
|
||||
|
||||
Args:
|
||||
@@ -73,6 +76,11 @@ def flatbuffer_library_public(
|
||||
to use.
|
||||
flatc_path: Bazel target corresponding to the flatc compiler to use.
|
||||
output_to_bindir: Passed to genrule for output to bin directory.
|
||||
tools: Optional, passed to genrule for list of tools to make available
|
||||
during the action.
|
||||
extra_env: Optional, must be a string of "VAR1=VAL1 VAR2=VAL2". These get
|
||||
set as environment variables that "flatc_path" sees.
|
||||
**kwargs: Passed to the underlying genrule.
|
||||
|
||||
|
||||
This rule creates a filegroup(name) with all generated source files, and
|
||||
@@ -83,6 +91,8 @@ def flatbuffer_library_public(
|
||||
include_paths = default_include_paths(flatc_path)
|
||||
include_paths_cmd = ["-I %s" % (s) for s in include_paths]
|
||||
|
||||
extra_env = extra_env or ""
|
||||
|
||||
# '$(@D)' when given a single source target will give the appropriate
|
||||
# directory. Appending 'out_prefix' is only necessary when given a build
|
||||
# target with multiple sources.
|
||||
@@ -92,7 +102,7 @@ def flatbuffer_library_public(
|
||||
genrule_cmd = " ".join([
|
||||
"SRCS=($(SRCS));",
|
||||
"for f in $${SRCS[@]:0:%s}; do" % len(srcs),
|
||||
"OUTPUT_FILE=\"$(OUTS)\" $(location %s)" % (flatc_path),
|
||||
"OUTPUT_FILE=\"$(OUTS)\" %s $(location %s)" % (extra_env, flatc_path),
|
||||
" ".join(include_paths_cmd),
|
||||
" ".join(flatc_args),
|
||||
language_flag,
|
||||
@@ -105,12 +115,13 @@ def flatbuffer_library_public(
|
||||
srcs = srcs + includes,
|
||||
outs = outs,
|
||||
output_to_bindir = output_to_bindir,
|
||||
tools = [flatc_path],
|
||||
tools = (tools or []) + [flatc_path],
|
||||
cmd = genrule_cmd,
|
||||
compatible_with = compatible_with,
|
||||
target_compatible_with = target_compatible_with,
|
||||
restricted_to = restricted_to,
|
||||
message = "Generating flatbuffer files for %s:" % (name),
|
||||
**kwargs
|
||||
)
|
||||
if reflection_name:
|
||||
reflection_genrule_cmd = " ".join([
|
||||
@@ -154,6 +165,7 @@ def flatbuffer_cc_library(
|
||||
name,
|
||||
srcs,
|
||||
srcs_filegroup_name = "",
|
||||
outs = [],
|
||||
out_prefix = "",
|
||||
deps = [],
|
||||
includes = [],
|
||||
@@ -174,6 +186,7 @@ def flatbuffer_cc_library(
|
||||
srcs_filegroup_name: Name of the output filegroup that holds srcs. Pass this
|
||||
filegroup into the `includes` parameter of any other
|
||||
flatbuffer_cc_library that depends on this one's schemas.
|
||||
outs: Additional outputs expected to be generated by flatc.
|
||||
out_prefix: Prepend this path to the front of all generated files. Usually
|
||||
is a directory name.
|
||||
deps: Optional, list of other flatbuffer_cc_library's to depend on. Cannot be specified
|
||||
@@ -221,7 +234,7 @@ def flatbuffer_cc_library(
|
||||
flatbuffer_library_public(
|
||||
name = srcs_lib,
|
||||
srcs = srcs,
|
||||
outs = output_headers,
|
||||
outs = outs + output_headers,
|
||||
language_flag = "-c",
|
||||
out_prefix = out_prefix,
|
||||
includes = includes,
|
||||
|
||||
@@ -20,7 +20,7 @@ class FlatbuffersConan(ConanFile):
|
||||
options = {"shared": [True, False], "fPIC": [True, False]}
|
||||
default_options = {"shared": False, "fPIC": True}
|
||||
generators = "cmake"
|
||||
exports = "LICENSE.txt"
|
||||
exports = "LICENSE"
|
||||
exports_sources = ["CMake/*", "include/*", "src/*", "grpc/*", "CMakeLists.txt", "conan/CMakeLists.txt"]
|
||||
|
||||
def source(self):
|
||||
@@ -56,7 +56,7 @@ class FlatbuffersConan(ConanFile):
|
||||
"""
|
||||
cmake = self.configure_cmake()
|
||||
cmake.install()
|
||||
self.copy(pattern="LICENSE.txt", dst="licenses")
|
||||
self.copy(pattern="LICENSE", dst="licenses")
|
||||
self.copy(pattern="FindFlatBuffers.cmake", dst=os.path.join("lib", "cmake", "flatbuffers"), src="CMake")
|
||||
self.copy(pattern="flathash*", dst="bin", src="bin")
|
||||
self.copy(pattern="flatc*", dst="bin", src="bin")
|
||||
|
||||
@@ -304,7 +304,7 @@ class Builder {
|
||||
assert(_inVTable);
|
||||
// Prepare for writing the VTable.
|
||||
_prepare(_sizeofInt32, 1);
|
||||
var tableTail = _tail;
|
||||
final tableTail = _tail;
|
||||
// Prepare the size of the current table.
|
||||
final currentVTable = _currentVTable!;
|
||||
currentVTable.tableSize = tableTail - _currentTableEndTail;
|
||||
@@ -514,7 +514,7 @@ class Builder {
|
||||
var tail = _tail;
|
||||
_setUint32AtTail(tail, values.length);
|
||||
tail -= _sizeofUint32;
|
||||
for (var value in values) {
|
||||
for (final value in values) {
|
||||
_setUint32AtTail(tail, tail - value);
|
||||
tail -= _sizeofUint32;
|
||||
}
|
||||
@@ -529,7 +529,7 @@ class Builder {
|
||||
var tail = _tail;
|
||||
_setUint32AtTail(tail, values.length);
|
||||
tail -= _sizeofUint32;
|
||||
for (var value in values) {
|
||||
for (final value in values) {
|
||||
_setFloat64AtTail(tail, value);
|
||||
tail -= _sizeofFloat64;
|
||||
}
|
||||
@@ -544,7 +544,7 @@ class Builder {
|
||||
var tail = _tail;
|
||||
_setUint32AtTail(tail, values.length);
|
||||
tail -= _sizeofUint32;
|
||||
for (var value in values) {
|
||||
for (final value in values) {
|
||||
_setFloat32AtTail(tail, value);
|
||||
tail -= _sizeofFloat32;
|
||||
}
|
||||
@@ -559,7 +559,7 @@ class Builder {
|
||||
var tail = _tail;
|
||||
_setUint32AtTail(tail, values.length);
|
||||
tail -= _sizeofUint32;
|
||||
for (var value in values) {
|
||||
for (final value in values) {
|
||||
_setInt64AtTail(tail, value);
|
||||
tail -= _sizeofInt64;
|
||||
}
|
||||
@@ -574,7 +574,7 @@ class Builder {
|
||||
var tail = _tail;
|
||||
_setUint32AtTail(tail, values.length);
|
||||
tail -= _sizeofUint32;
|
||||
for (var value in values) {
|
||||
for (final value in values) {
|
||||
_setUint64AtTail(tail, value);
|
||||
tail -= _sizeofUint64;
|
||||
}
|
||||
@@ -589,7 +589,7 @@ class Builder {
|
||||
var tail = _tail;
|
||||
_setUint32AtTail(tail, values.length);
|
||||
tail -= _sizeofUint32;
|
||||
for (var value in values) {
|
||||
for (final value in values) {
|
||||
_setInt32AtTail(tail, value);
|
||||
tail -= _sizeofInt32;
|
||||
}
|
||||
@@ -604,7 +604,7 @@ class Builder {
|
||||
var tail = _tail;
|
||||
_setUint32AtTail(tail, values.length);
|
||||
tail -= _sizeofUint32;
|
||||
for (var value in values) {
|
||||
for (final value in values) {
|
||||
_setUint32AtTail(tail, value);
|
||||
tail -= _sizeofUint32;
|
||||
}
|
||||
@@ -619,7 +619,7 @@ class Builder {
|
||||
var tail = _tail;
|
||||
_setUint32AtTail(tail, values.length);
|
||||
tail -= _sizeofUint32;
|
||||
for (var value in values) {
|
||||
for (final value in values) {
|
||||
_setInt16AtTail(tail, value);
|
||||
tail -= _sizeofInt16;
|
||||
}
|
||||
@@ -634,7 +634,7 @@ class Builder {
|
||||
var tail = _tail;
|
||||
_setUint32AtTail(tail, values.length);
|
||||
tail -= _sizeofUint32;
|
||||
for (var value in values) {
|
||||
for (final value in values) {
|
||||
_setUint16AtTail(tail, value);
|
||||
tail -= _sizeofUint16;
|
||||
}
|
||||
@@ -669,7 +669,7 @@ class Builder {
|
||||
var tail = _tail;
|
||||
_setUint32AtTail(tail, values.length);
|
||||
tail -= _sizeofUint32;
|
||||
for (var value in values) {
|
||||
for (final value in values) {
|
||||
_setUint8AtTail(tail, value);
|
||||
tail -= _sizeofUint8;
|
||||
}
|
||||
@@ -777,17 +777,17 @@ class Builder {
|
||||
_maxAlign = size;
|
||||
}
|
||||
// Prepare amount of required space.
|
||||
var dataSize = size * count + additionalBytes;
|
||||
var alignDelta = (-(_tail + dataSize)) & (size - 1);
|
||||
var bufSize = alignDelta + dataSize;
|
||||
final dataSize = size * count + additionalBytes;
|
||||
final alignDelta = (-(_tail + dataSize)) & (size - 1);
|
||||
final bufSize = alignDelta + dataSize;
|
||||
// Ensure that we have the required amount of space.
|
||||
{
|
||||
var oldCapacity = _buf.lengthInBytes;
|
||||
final oldCapacity = _buf.lengthInBytes;
|
||||
if (_tail + bufSize > oldCapacity) {
|
||||
var desiredNewCapacity = (oldCapacity + bufSize) * 2;
|
||||
final desiredNewCapacity = (oldCapacity + bufSize) * 2;
|
||||
var deltaCapacity = desiredNewCapacity - oldCapacity;
|
||||
deltaCapacity += (-deltaCapacity) & (_maxAlign - 1);
|
||||
var newCapacity = oldCapacity + deltaCapacity;
|
||||
final newCapacity = oldCapacity + deltaCapacity;
|
||||
_buf = _allocator.resize(_buf, newCapacity, _tail, 0);
|
||||
}
|
||||
}
|
||||
@@ -1023,22 +1023,22 @@ abstract class Reader<T> {
|
||||
/// Read the value of the given [field] in the given [object].
|
||||
@pragma('vm:prefer-inline')
|
||||
T vTableGet(BufferContext object, int offset, int field, T defaultValue) {
|
||||
var fieldOffset = _vTableFieldOffset(object, offset, field);
|
||||
final fieldOffset = _vTableFieldOffset(object, offset, field);
|
||||
return fieldOffset == 0 ? defaultValue : read(object, offset + fieldOffset);
|
||||
}
|
||||
|
||||
/// Read the value of the given [field] in the given [object].
|
||||
@pragma('vm:prefer-inline')
|
||||
T? vTableGetNullable(BufferContext object, int offset, int field) {
|
||||
var fieldOffset = _vTableFieldOffset(object, offset, field);
|
||||
final fieldOffset = _vTableFieldOffset(object, offset, field);
|
||||
return fieldOffset == 0 ? null : read(object, offset + fieldOffset);
|
||||
}
|
||||
|
||||
@pragma('vm:prefer-inline')
|
||||
int _vTableFieldOffset(BufferContext object, int offset, int field) {
|
||||
var vTableSOffset = object._getInt32(offset);
|
||||
var vTableOffset = offset - vTableSOffset;
|
||||
var vTableSize = object._getUint16(vTableOffset);
|
||||
final vTableSOffset = object._getInt32(offset);
|
||||
final vTableOffset = offset - vTableSOffset;
|
||||
final vTableSize = object._getUint16(vTableOffset);
|
||||
if (field >= vTableSize) return 0;
|
||||
return object._getUint16(vTableOffset + field);
|
||||
}
|
||||
@@ -1057,9 +1057,9 @@ class StringReader extends Reader<String> {
|
||||
@override
|
||||
@pragma('vm:prefer-inline')
|
||||
String read(BufferContext bc, int offset) {
|
||||
var strOffset = bc.derefObject(offset);
|
||||
var length = bc._getUint32(strOffset);
|
||||
var bytes = bc._asUint8List(strOffset + _sizeofUint32, length);
|
||||
final strOffset = bc.derefObject(offset);
|
||||
final length = bc._getUint32(strOffset);
|
||||
final bytes = bc._asUint8List(strOffset + _sizeofUint32, length);
|
||||
if (asciiOptimization && _isLatin(bytes)) {
|
||||
return String.fromCharCodes(bytes);
|
||||
}
|
||||
@@ -1068,7 +1068,7 @@ class StringReader extends Reader<String> {
|
||||
|
||||
@pragma('vm:prefer-inline')
|
||||
static bool _isLatin(Uint8List bytes) {
|
||||
var length = bytes.length;
|
||||
final length = bytes.length;
|
||||
for (var i = 0; i < length; i++) {
|
||||
if (bytes[i] > 127) {
|
||||
return false;
|
||||
@@ -1104,7 +1104,7 @@ abstract class TableReader<T> extends Reader<T> {
|
||||
|
||||
@override
|
||||
T read(BufferContext bc, int offset) {
|
||||
var objectOffset = bc.derefObject(offset);
|
||||
final objectOffset = bc.derefObject(offset);
|
||||
return createObject(bc, objectOffset);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
name: flat_buffers
|
||||
version: 23.3.3
|
||||
version: 23.5.9
|
||||
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
|
||||
|
||||
@@ -59,6 +59,8 @@ struct Vec3 (force_align: 8) {
|
||||
test3:Test;
|
||||
}
|
||||
|
||||
// Stats for monster
|
||||
|
||||
struct Ability {
|
||||
id:uint(key);
|
||||
distance:uint;
|
||||
|
||||
@@ -142,6 +142,47 @@ To use it:
|
||||
`ByKey` only works if the vector has been sorted, it will
|
||||
likely not find elements if it hasn't been sorted.
|
||||
|
||||
## Buffer verification
|
||||
|
||||
As mentioned in [C++ Usage](@ref flatbuffers_guide_use_cpp) buffer
|
||||
accessor functions do not verify buffer offsets at run-time.
|
||||
If it is necessary, you can optionally use a buffer verifier before you
|
||||
access the data. This verifier will check all offsets, all sizes of
|
||||
fields, and null termination of strings to ensure that when a buffer
|
||||
is accessed, all reads will end up inside the buffer.
|
||||
|
||||
Each root type will have a verification function generated for it,
|
||||
e.g. `Monster.VerifyMonster`. This can be called as shown:
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cs}
|
||||
var ok = Monster.VerifyMonster(buf);
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
if `ok` is true, the buffer is safe to read.
|
||||
|
||||
For a more detailed control of verification `MonsterVerify.Verify`
|
||||
for `Monster` type can be used:
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cs}
|
||||
# Sequence of calls
|
||||
FlatBuffers.Verifier verifier = new FlatBuffers.Verifier(buf);
|
||||
var ok = verifier.VerifyBuffer("MONS", false, MonsterVerify.Verify);
|
||||
|
||||
# Or single line call
|
||||
var ok = new FlatBuffers.Verifier(bb).setStringCheck(true).\
|
||||
VerifyBuffer("MONS", false, MonsterVerify.Verify);
|
||||
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
if `ok` is true, the buffer is safe to read.
|
||||
|
||||
A second parameter of `verifyBuffer` specifies whether buffer content is
|
||||
size prefixed or not. In the example above, the buffer is assumed to not include
|
||||
size prefix (`false`).
|
||||
|
||||
Verifier supports options that can be set using appropriate fluent methods:
|
||||
* SetMaxDepth - limit the nesting depth. Default: 1000000
|
||||
* SetMaxTables - total amount of tables the verifier may encounter. Default: 64
|
||||
* SetAlignmentCheck - check content alignment. Default: True
|
||||
* SetStringCheck - check if strings contain termination '0' character. Default: true
|
||||
|
||||
|
||||
## Text parsing
|
||||
|
||||
There currently is no support for parsing text (Schema's and JSON) directly
|
||||
|
||||
@@ -9,7 +9,7 @@ It was originally created at Google for game development and other
|
||||
performance-critical applications.
|
||||
|
||||
It is available as Open Source on [GitHub](http://github.com/google/flatbuffers)
|
||||
under the Apache license, v2 (see LICENSE.txt).
|
||||
under the Apache license, v2 (see LICENSE).
|
||||
|
||||
## Why use FlatBuffers?
|
||||
|
||||
|
||||
@@ -529,7 +529,7 @@ The first step is to import/include the library, generated files, etc.
|
||||
#[allow(dead_code, unused_imports)]
|
||||
#[path = "./monster_generated.rs"]
|
||||
mod monster_generated;
|
||||
pub use monster_generated::my_game::sample::{get_root_as_monster,
|
||||
pub use monster_generated::my_game::sample::{root_as_monster,
|
||||
Color, Equipment,
|
||||
Monster, MonsterArgs,
|
||||
Vec3,
|
||||
@@ -652,7 +652,7 @@ which will grow automatically if needed:
|
||||
~~~{.rs}
|
||||
// Build up a serialized buffer algorithmically.
|
||||
// Initialize it with a capacity of 1024 bytes.
|
||||
let mut builder = flatbuffers::FlatBufferBuilder::new_with_capacity(1024);
|
||||
let mut builder = flatbuffers::FlatBufferBuilder::with_capacity(1024);
|
||||
~~~
|
||||
</div>
|
||||
<div class="language-swift">
|
||||
@@ -2309,7 +2309,7 @@ import './monster_my_game.sample_generated.dart' as myGame;
|
||||
#[allow(dead_code, unused_imports)]
|
||||
#[path = "./monster_generated.rs"]
|
||||
mod monster_generated;
|
||||
pub use monster_generated::my_game::sample::{get_root_as_monster,
|
||||
pub use monster_generated::my_game::sample::{root_as_monster,
|
||||
Color, Equipment,
|
||||
Monster, MonsterArgs,
|
||||
Vec3,
|
||||
@@ -2465,7 +2465,7 @@ myGame.Monster monster = new myGame.Monster(data);
|
||||
let buf = /* the data you just read, in a &[u8] */
|
||||
|
||||
// Get an accessor to the root object inside the buffer.
|
||||
let monster = get_root_as_monster(buf);
|
||||
let monster = root_as_monster(buf).unwrap();
|
||||
~~~
|
||||
</div>
|
||||
<div class="language-swift">
|
||||
|
||||
@@ -779,7 +779,8 @@ INPUT = "FlatBuffers.md" \
|
||||
"../../python/flatbuffers/builder.py" \
|
||||
"../../js/flatbuffers.js" \
|
||||
"../../php/FlatbufferBuilder.php" \
|
||||
"../../net/FlatBuffers/FlatBufferBuilder.cs" \
|
||||
"../../net/FlatBuffers/FlatBufferBuilder.cs"
|
||||
"../../net/FlatBuffers/FlatBufferVerify.cs" \
|
||||
"../../include/flatbuffers/flatbuffers.h" \
|
||||
"../../go/builder.go" \
|
||||
"../../rust/flatbuffers/src/builder.rs"
|
||||
|
||||
@@ -12,8 +12,13 @@ type WarriorT struct {
|
||||
}
|
||||
|
||||
func (t *WarriorT) Pack(builder *flatbuffers.Builder) flatbuffers.UOffsetT {
|
||||
if t == nil { return 0 }
|
||||
nameOffset := builder.CreateString(t.Name)
|
||||
if t == nil {
|
||||
return 0
|
||||
}
|
||||
nameOffset := flatbuffers.UOffsetT(0)
|
||||
if t.Name != "" {
|
||||
nameOffset = builder.CreateString(t.Name)
|
||||
}
|
||||
WarriorStart(builder)
|
||||
WarriorAddName(builder, nameOffset)
|
||||
WarriorAddHp(builder, t.Hp)
|
||||
@@ -26,7 +31,9 @@ func (rcv *Warrior) UnPackTo(t *WarriorT) {
|
||||
}
|
||||
|
||||
func (rcv *Warrior) UnPack() *WarriorT {
|
||||
if rcv == nil { return nil }
|
||||
if rcv == nil {
|
||||
return nil
|
||||
}
|
||||
t := &WarriorT{}
|
||||
rcv.UnPackTo(t)
|
||||
return t
|
||||
|
||||
@@ -13,7 +13,9 @@ type RequestT struct {
|
||||
}
|
||||
|
||||
func (t *RequestT) Pack(builder *flatbuffers.Builder) flatbuffers.UOffsetT {
|
||||
if t == nil { return 0 }
|
||||
if t == nil {
|
||||
return 0
|
||||
}
|
||||
playerOffset := t.Player.Pack(builder)
|
||||
RequestStart(builder)
|
||||
RequestAddPlayer(builder, playerOffset)
|
||||
@@ -25,7 +27,9 @@ func (rcv *Request) UnPackTo(t *RequestT) {
|
||||
}
|
||||
|
||||
func (rcv *Request) UnPack() *RequestT {
|
||||
if rcv == nil { return nil }
|
||||
if rcv == nil {
|
||||
return nil
|
||||
}
|
||||
t := &RequestT{}
|
||||
rcv.UnPackTo(t)
|
||||
return t
|
||||
|
||||
@@ -13,7 +13,9 @@ type ResponseT struct {
|
||||
}
|
||||
|
||||
func (t *ResponseT) Pack(builder *flatbuffers.Builder) flatbuffers.UOffsetT {
|
||||
if t == nil { return 0 }
|
||||
if t == nil {
|
||||
return 0
|
||||
}
|
||||
playerOffset := t.Player.Pack(builder)
|
||||
ResponseStart(builder)
|
||||
ResponseAddPlayer(builder, playerOffset)
|
||||
@@ -25,7 +27,9 @@ func (rcv *Response) UnPackTo(t *ResponseT) {
|
||||
}
|
||||
|
||||
func (rcv *Response) UnPack() *ResponseT {
|
||||
if rcv == nil { return nil }
|
||||
if rcv == nil {
|
||||
return nil
|
||||
}
|
||||
t := &ResponseT{}
|
||||
rcv.UnPackTo(t)
|
||||
return t
|
||||
|
||||
20
go/lib.go
20
go/lib.go
@@ -28,3 +28,23 @@ func GetSizePrefix(buf []byte, offset UOffsetT) uint32 {
|
||||
func GetIndirectOffset(buf []byte, offset UOffsetT) UOffsetT {
|
||||
return offset + GetUOffsetT(buf[offset:])
|
||||
}
|
||||
|
||||
// GetBufferIdentifier returns the file identifier as string
|
||||
func GetBufferIdentifier(buf []byte) string {
|
||||
return string(buf[SizeUOffsetT:][:fileIdentifierLength])
|
||||
}
|
||||
|
||||
// GetBufferIdentifier returns the file identifier as string for a size-prefixed buffer
|
||||
func GetSizePrefixedBufferIdentifier(buf []byte) string {
|
||||
return string(buf[SizeUOffsetT+sizePrefixLength:][:fileIdentifierLength])
|
||||
}
|
||||
|
||||
// BufferHasIdentifier checks if the identifier in a buffer has the expected value
|
||||
func BufferHasIdentifier(buf []byte, identifier string) bool {
|
||||
return GetBufferIdentifier(buf) == identifier
|
||||
}
|
||||
|
||||
// BufferHasIdentifier checks if the identifier in a buffer has the expected value for a size-prefixed buffer
|
||||
func SizePrefixedBufferHasIdentifier(buf []byte, identifier string) bool {
|
||||
return GetSizePrefixedBufferIdentifier(buf) == identifier
|
||||
}
|
||||
|
||||
26
goldens/README.md
Normal file
26
goldens/README.md
Normal file
@@ -0,0 +1,26 @@
|
||||
# Golden Generated Files
|
||||
|
||||
This directory is a repository for the generated files of `flatc`.
|
||||
|
||||
We check in the generated code so we can see, during a PR review, how the
|
||||
changes affect the generated output. Its also useful as a reference to point too
|
||||
as how things work across various languages.
|
||||
|
||||
These files are **NOT** intended to be depended on by any code, such as tests or
|
||||
or compiled examples.
|
||||
|
||||
## Languages Specifics
|
||||
|
||||
Each language should keep their generated code in their respective directories.
|
||||
However, the parent schemas can, and should, be shared so we have a consistent
|
||||
view of things across languages. These are kept in the `schema/` directory.
|
||||
|
||||
Some languages may not support every generation feature, so each language is
|
||||
required to specify the `flatc` arguments individually.
|
||||
|
||||
* Try to avoid includes and nested directories, preferring it as flat as
|
||||
possible.
|
||||
|
||||
## Updating
|
||||
|
||||
Just run the `generate_goldens.py` script and it should generate them all.
|
||||
157
goldens/cpp/basic_generated.h
Normal file
157
goldens/cpp/basic_generated.h
Normal file
@@ -0,0 +1,157 @@
|
||||
// automatically generated by the FlatBuffers compiler, do not modify
|
||||
|
||||
|
||||
#ifndef FLATBUFFERS_GENERATED_BASIC_H_
|
||||
#define FLATBUFFERS_GENERATED_BASIC_H_
|
||||
|
||||
#include "flatbuffers/flatbuffers.h"
|
||||
|
||||
// Ensure the included flatbuffers.h is the same version as when this file was
|
||||
// generated, otherwise it may not be compatible.
|
||||
static_assert(FLATBUFFERS_VERSION_MAJOR == 23 &&
|
||||
FLATBUFFERS_VERSION_MINOR == 5 &&
|
||||
FLATBUFFERS_VERSION_REVISION == 9,
|
||||
"Non-compatible flatbuffers version included");
|
||||
|
||||
struct Galaxy;
|
||||
struct GalaxyBuilder;
|
||||
|
||||
struct Universe;
|
||||
struct UniverseBuilder;
|
||||
|
||||
struct Galaxy FLATBUFFERS_FINAL_CLASS : private ::flatbuffers::Table {
|
||||
typedef GalaxyBuilder Builder;
|
||||
enum FlatBuffersVTableOffset FLATBUFFERS_VTABLE_UNDERLYING_TYPE {
|
||||
VT_NUM_STARS = 4
|
||||
};
|
||||
int64_t num_stars() const {
|
||||
return GetField<int64_t>(VT_NUM_STARS, 0);
|
||||
}
|
||||
bool Verify(::flatbuffers::Verifier &verifier) const {
|
||||
return VerifyTableStart(verifier) &&
|
||||
VerifyField<int64_t>(verifier, VT_NUM_STARS, 8) &&
|
||||
verifier.EndTable();
|
||||
}
|
||||
};
|
||||
|
||||
struct GalaxyBuilder {
|
||||
typedef Galaxy Table;
|
||||
::flatbuffers::FlatBufferBuilder &fbb_;
|
||||
::flatbuffers::uoffset_t start_;
|
||||
void add_num_stars(int64_t num_stars) {
|
||||
fbb_.AddElement<int64_t>(Galaxy::VT_NUM_STARS, num_stars, 0);
|
||||
}
|
||||
explicit GalaxyBuilder(::flatbuffers::FlatBufferBuilder &_fbb)
|
||||
: fbb_(_fbb) {
|
||||
start_ = fbb_.StartTable();
|
||||
}
|
||||
::flatbuffers::Offset<Galaxy> Finish() {
|
||||
const auto end = fbb_.EndTable(start_);
|
||||
auto o = ::flatbuffers::Offset<Galaxy>(end);
|
||||
return o;
|
||||
}
|
||||
};
|
||||
|
||||
inline ::flatbuffers::Offset<Galaxy> CreateGalaxy(
|
||||
::flatbuffers::FlatBufferBuilder &_fbb,
|
||||
int64_t num_stars = 0) {
|
||||
GalaxyBuilder builder_(_fbb);
|
||||
builder_.add_num_stars(num_stars);
|
||||
return builder_.Finish();
|
||||
}
|
||||
|
||||
struct Universe FLATBUFFERS_FINAL_CLASS : private ::flatbuffers::Table {
|
||||
typedef UniverseBuilder Builder;
|
||||
enum FlatBuffersVTableOffset FLATBUFFERS_VTABLE_UNDERLYING_TYPE {
|
||||
VT_AGE = 4,
|
||||
VT_GALAXIES = 6
|
||||
};
|
||||
double age() const {
|
||||
return GetField<double>(VT_AGE, 0.0);
|
||||
}
|
||||
const ::flatbuffers::Vector<::flatbuffers::Offset<Galaxy>> *galaxies() const {
|
||||
return GetPointer<const ::flatbuffers::Vector<::flatbuffers::Offset<Galaxy>> *>(VT_GALAXIES);
|
||||
}
|
||||
bool Verify(::flatbuffers::Verifier &verifier) const {
|
||||
return VerifyTableStart(verifier) &&
|
||||
VerifyField<double>(verifier, VT_AGE, 8) &&
|
||||
VerifyOffset(verifier, VT_GALAXIES) &&
|
||||
verifier.VerifyVector(galaxies()) &&
|
||||
verifier.VerifyVectorOfTables(galaxies()) &&
|
||||
verifier.EndTable();
|
||||
}
|
||||
};
|
||||
|
||||
struct UniverseBuilder {
|
||||
typedef Universe Table;
|
||||
::flatbuffers::FlatBufferBuilder &fbb_;
|
||||
::flatbuffers::uoffset_t start_;
|
||||
void add_age(double age) {
|
||||
fbb_.AddElement<double>(Universe::VT_AGE, age, 0.0);
|
||||
}
|
||||
void add_galaxies(::flatbuffers::Offset<::flatbuffers::Vector<::flatbuffers::Offset<Galaxy>>> galaxies) {
|
||||
fbb_.AddOffset(Universe::VT_GALAXIES, galaxies);
|
||||
}
|
||||
explicit UniverseBuilder(::flatbuffers::FlatBufferBuilder &_fbb)
|
||||
: fbb_(_fbb) {
|
||||
start_ = fbb_.StartTable();
|
||||
}
|
||||
::flatbuffers::Offset<Universe> Finish() {
|
||||
const auto end = fbb_.EndTable(start_);
|
||||
auto o = ::flatbuffers::Offset<Universe>(end);
|
||||
return o;
|
||||
}
|
||||
};
|
||||
|
||||
inline ::flatbuffers::Offset<Universe> CreateUniverse(
|
||||
::flatbuffers::FlatBufferBuilder &_fbb,
|
||||
double age = 0.0,
|
||||
::flatbuffers::Offset<::flatbuffers::Vector<::flatbuffers::Offset<Galaxy>>> galaxies = 0) {
|
||||
UniverseBuilder builder_(_fbb);
|
||||
builder_.add_age(age);
|
||||
builder_.add_galaxies(galaxies);
|
||||
return builder_.Finish();
|
||||
}
|
||||
|
||||
inline ::flatbuffers::Offset<Universe> CreateUniverseDirect(
|
||||
::flatbuffers::FlatBufferBuilder &_fbb,
|
||||
double age = 0.0,
|
||||
const std::vector<::flatbuffers::Offset<Galaxy>> *galaxies = nullptr) {
|
||||
auto galaxies__ = galaxies ? _fbb.CreateVector<::flatbuffers::Offset<Galaxy>>(*galaxies) : 0;
|
||||
return CreateUniverse(
|
||||
_fbb,
|
||||
age,
|
||||
galaxies__);
|
||||
}
|
||||
|
||||
inline const Universe *GetUniverse(const void *buf) {
|
||||
return ::flatbuffers::GetRoot<Universe>(buf);
|
||||
}
|
||||
|
||||
inline const Universe *GetSizePrefixedUniverse(const void *buf) {
|
||||
return ::flatbuffers::GetSizePrefixedRoot<Universe>(buf);
|
||||
}
|
||||
|
||||
inline bool VerifyUniverseBuffer(
|
||||
::flatbuffers::Verifier &verifier) {
|
||||
return verifier.VerifyBuffer<Universe>(nullptr);
|
||||
}
|
||||
|
||||
inline bool VerifySizePrefixedUniverseBuffer(
|
||||
::flatbuffers::Verifier &verifier) {
|
||||
return verifier.VerifySizePrefixedBuffer<Universe>(nullptr);
|
||||
}
|
||||
|
||||
inline void FinishUniverseBuffer(
|
||||
::flatbuffers::FlatBufferBuilder &fbb,
|
||||
::flatbuffers::Offset<Universe> root) {
|
||||
fbb.Finish(root);
|
||||
}
|
||||
|
||||
inline void FinishSizePrefixedUniverseBuffer(
|
||||
::flatbuffers::FlatBufferBuilder &fbb,
|
||||
::flatbuffers::Offset<Universe> root) {
|
||||
fbb.FinishSizePrefixed(root);
|
||||
}
|
||||
|
||||
#endif // FLATBUFFERS_GENERATED_BASIC_H_
|
||||
10
goldens/cpp/generate.py
Normal file
10
goldens/cpp/generate.py
Normal file
@@ -0,0 +1,10 @@
|
||||
from golden_utils import flatc_golden
|
||||
|
||||
|
||||
def flatc(options, schema):
|
||||
# Wrap the golden flatc generator with C++ specifics
|
||||
flatc_golden(options=["--cpp"] + options, schema=schema, prefix="cpp")
|
||||
|
||||
|
||||
def GenerateCpp():
|
||||
flatc([], "basic.fbs")
|
||||
45
goldens/csharp/Galaxy.cs
Normal file
45
goldens/csharp/Galaxy.cs
Normal file
@@ -0,0 +1,45 @@
|
||||
// <auto-generated>
|
||||
// automatically generated by the FlatBuffers compiler, do not modify
|
||||
// </auto-generated>
|
||||
|
||||
using global::System;
|
||||
using global::System.Collections.Generic;
|
||||
using global::Google.FlatBuffers;
|
||||
|
||||
public struct Galaxy : IFlatbufferObject
|
||||
{
|
||||
private Table __p;
|
||||
public ByteBuffer ByteBuffer { get { return __p.bb; } }
|
||||
public static void ValidateVersion() { FlatBufferConstants.FLATBUFFERS_23_5_9(); }
|
||||
public static Galaxy GetRootAsGalaxy(ByteBuffer _bb) { return GetRootAsGalaxy(_bb, new Galaxy()); }
|
||||
public static Galaxy GetRootAsGalaxy(ByteBuffer _bb, Galaxy obj) { return (obj.__assign(_bb.GetInt(_bb.Position) + _bb.Position, _bb)); }
|
||||
public void __init(int _i, ByteBuffer _bb) { __p = new Table(_i, _bb); }
|
||||
public Galaxy __assign(int _i, ByteBuffer _bb) { __init(_i, _bb); return this; }
|
||||
|
||||
public long NumStars { get { int o = __p.__offset(4); return o != 0 ? __p.bb.GetLong(o + __p.bb_pos) : (long)0; } }
|
||||
|
||||
public static Offset<Galaxy> CreateGalaxy(FlatBufferBuilder builder,
|
||||
long num_stars = 0) {
|
||||
builder.StartTable(1);
|
||||
Galaxy.AddNumStars(builder, num_stars);
|
||||
return Galaxy.EndGalaxy(builder);
|
||||
}
|
||||
|
||||
public static void StartGalaxy(FlatBufferBuilder builder) { builder.StartTable(1); }
|
||||
public static void AddNumStars(FlatBufferBuilder builder, long numStars) { builder.AddLong(0, numStars, 0); }
|
||||
public static Offset<Galaxy> EndGalaxy(FlatBufferBuilder builder) {
|
||||
int o = builder.EndTable();
|
||||
return new Offset<Galaxy>(o);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static public class GalaxyVerify
|
||||
{
|
||||
static public bool Verify(Google.FlatBuffers.Verifier verifier, uint tablePos)
|
||||
{
|
||||
return verifier.VerifyTableStart(tablePos)
|
||||
&& verifier.VerifyField(tablePos, 4 /*NumStars*/, 8 /*long*/, 8, false)
|
||||
&& verifier.VerifyTableEnd(tablePos);
|
||||
}
|
||||
}
|
||||
59
goldens/csharp/Universe.cs
Normal file
59
goldens/csharp/Universe.cs
Normal file
@@ -0,0 +1,59 @@
|
||||
// <auto-generated>
|
||||
// automatically generated by the FlatBuffers compiler, do not modify
|
||||
// </auto-generated>
|
||||
|
||||
using global::System;
|
||||
using global::System.Collections.Generic;
|
||||
using global::Google.FlatBuffers;
|
||||
|
||||
public struct Universe : IFlatbufferObject
|
||||
{
|
||||
private Table __p;
|
||||
public ByteBuffer ByteBuffer { get { return __p.bb; } }
|
||||
public static void ValidateVersion() { FlatBufferConstants.FLATBUFFERS_23_5_9(); }
|
||||
public static Universe GetRootAsUniverse(ByteBuffer _bb) { return GetRootAsUniverse(_bb, new Universe()); }
|
||||
public static Universe GetRootAsUniverse(ByteBuffer _bb, Universe obj) { return (obj.__assign(_bb.GetInt(_bb.Position) + _bb.Position, _bb)); }
|
||||
public static bool VerifyUniverse(ByteBuffer _bb) {Google.FlatBuffers.Verifier verifier = new Google.FlatBuffers.Verifier(_bb); return verifier.VerifyBuffer("", false, UniverseVerify.Verify); }
|
||||
public void __init(int _i, ByteBuffer _bb) { __p = new Table(_i, _bb); }
|
||||
public Universe __assign(int _i, ByteBuffer _bb) { __init(_i, _bb); return this; }
|
||||
|
||||
public double Age { get { int o = __p.__offset(4); return o != 0 ? __p.bb.GetDouble(o + __p.bb_pos) : (double)0.0; } }
|
||||
public Galaxy? Galaxies(int j) { int o = __p.__offset(6); return o != 0 ? (Galaxy?)(new Galaxy()).__assign(__p.__indirect(__p.__vector(o) + j * 4), __p.bb) : null; }
|
||||
public int GalaxiesLength { get { int o = __p.__offset(6); return o != 0 ? __p.__vector_len(o) : 0; } }
|
||||
|
||||
public static Offset<Universe> CreateUniverse(FlatBufferBuilder builder,
|
||||
double age = 0.0,
|
||||
VectorOffset galaxiesOffset = default(VectorOffset)) {
|
||||
builder.StartTable(2);
|
||||
Universe.AddAge(builder, age);
|
||||
Universe.AddGalaxies(builder, galaxiesOffset);
|
||||
return Universe.EndUniverse(builder);
|
||||
}
|
||||
|
||||
public static void StartUniverse(FlatBufferBuilder builder) { builder.StartTable(2); }
|
||||
public static void AddAge(FlatBufferBuilder builder, double age) { builder.AddDouble(0, age, 0.0); }
|
||||
public static void AddGalaxies(FlatBufferBuilder builder, VectorOffset galaxiesOffset) { builder.AddOffset(1, galaxiesOffset.Value, 0); }
|
||||
public static VectorOffset CreateGalaxiesVector(FlatBufferBuilder builder, Offset<Galaxy>[] data) { builder.StartVector(4, data.Length, 4); for (int i = data.Length - 1; i >= 0; i--) builder.AddOffset(data[i].Value); return builder.EndVector(); }
|
||||
public static VectorOffset CreateGalaxiesVectorBlock(FlatBufferBuilder builder, Offset<Galaxy>[] data) { builder.StartVector(4, data.Length, 4); builder.Add(data); return builder.EndVector(); }
|
||||
public static VectorOffset CreateGalaxiesVectorBlock(FlatBufferBuilder builder, ArraySegment<Offset<Galaxy>> data) { builder.StartVector(4, data.Count, 4); builder.Add(data); return builder.EndVector(); }
|
||||
public static VectorOffset CreateGalaxiesVectorBlock(FlatBufferBuilder builder, IntPtr dataPtr, int sizeInBytes) { builder.StartVector(1, sizeInBytes, 1); builder.Add<Offset<Galaxy>>(dataPtr, sizeInBytes); return builder.EndVector(); }
|
||||
public static void StartGalaxiesVector(FlatBufferBuilder builder, int numElems) { builder.StartVector(4, numElems, 4); }
|
||||
public static Offset<Universe> EndUniverse(FlatBufferBuilder builder) {
|
||||
int o = builder.EndTable();
|
||||
return new Offset<Universe>(o);
|
||||
}
|
||||
public static void FinishUniverseBuffer(FlatBufferBuilder builder, Offset<Universe> offset) { builder.Finish(offset.Value); }
|
||||
public static void FinishSizePrefixedUniverseBuffer(FlatBufferBuilder builder, Offset<Universe> offset) { builder.FinishSizePrefixed(offset.Value); }
|
||||
}
|
||||
|
||||
|
||||
static public class UniverseVerify
|
||||
{
|
||||
static public bool Verify(Google.FlatBuffers.Verifier verifier, uint tablePos)
|
||||
{
|
||||
return verifier.VerifyTableStart(tablePos)
|
||||
&& verifier.VerifyField(tablePos, 4 /*Age*/, 8 /*double*/, 8, false)
|
||||
&& verifier.VerifyVectorOfTables(tablePos, 6 /*Galaxies*/, GalaxyVerify.Verify, false)
|
||||
&& verifier.VerifyTableEnd(tablePos);
|
||||
}
|
||||
}
|
||||
10
goldens/csharp/generate.py
Normal file
10
goldens/csharp/generate.py
Normal file
@@ -0,0 +1,10 @@
|
||||
from golden_utils import flatc_golden
|
||||
|
||||
|
||||
def flatc(options, schema):
|
||||
# Wrap the golden flatc generator with C# specifics
|
||||
flatc_golden(options=["--csharp"] + options, schema=schema, prefix="csharp")
|
||||
|
||||
|
||||
def GenerateCSharp():
|
||||
flatc([], "basic.fbs")
|
||||
160
goldens/dart/basic_generated.dart
Normal file
160
goldens/dart/basic_generated.dart
Normal file
@@ -0,0 +1,160 @@
|
||||
// automatically generated by the FlatBuffers compiler, do not modify
|
||||
// ignore_for_file: unused_import, unused_field, unused_element, unused_local_variable
|
||||
|
||||
import 'dart:typed_data' show Uint8List;
|
||||
import 'package:flat_buffers/flat_buffers.dart' as fb;
|
||||
|
||||
|
||||
class Galaxy {
|
||||
Galaxy._(this._bc, this._bcOffset);
|
||||
factory Galaxy(List<int> bytes) {
|
||||
final rootRef = fb.BufferContext.fromBytes(bytes);
|
||||
return reader.read(rootRef, 0);
|
||||
}
|
||||
|
||||
static const fb.Reader<Galaxy> reader = _GalaxyReader();
|
||||
|
||||
final fb.BufferContext _bc;
|
||||
final int _bcOffset;
|
||||
|
||||
int get numStars => const fb.Int64Reader().vTableGet(_bc, _bcOffset, 4, 0);
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return 'Galaxy{numStars: ${numStars}}';
|
||||
}
|
||||
}
|
||||
|
||||
class _GalaxyReader extends fb.TableReader<Galaxy> {
|
||||
const _GalaxyReader();
|
||||
|
||||
@override
|
||||
Galaxy createObject(fb.BufferContext bc, int offset) =>
|
||||
Galaxy._(bc, offset);
|
||||
}
|
||||
|
||||
class GalaxyBuilder {
|
||||
GalaxyBuilder(this.fbBuilder);
|
||||
|
||||
final fb.Builder fbBuilder;
|
||||
|
||||
void begin() {
|
||||
fbBuilder.startTable(1);
|
||||
}
|
||||
|
||||
int addNumStars(int? numStars) {
|
||||
fbBuilder.addInt64(0, numStars);
|
||||
return fbBuilder.offset;
|
||||
}
|
||||
|
||||
int finish() {
|
||||
return fbBuilder.endTable();
|
||||
}
|
||||
}
|
||||
|
||||
class GalaxyObjectBuilder extends fb.ObjectBuilder {
|
||||
final int? _numStars;
|
||||
|
||||
GalaxyObjectBuilder({
|
||||
int? numStars,
|
||||
})
|
||||
: _numStars = numStars;
|
||||
|
||||
/// Finish building, and store into the [fbBuilder].
|
||||
@override
|
||||
int finish(fb.Builder fbBuilder) {
|
||||
fbBuilder.startTable(1);
|
||||
fbBuilder.addInt64(0, _numStars);
|
||||
return fbBuilder.endTable();
|
||||
}
|
||||
|
||||
/// Convenience method to serialize to byte list.
|
||||
@override
|
||||
Uint8List toBytes([String? fileIdentifier]) {
|
||||
final fbBuilder = fb.Builder(deduplicateTables: false);
|
||||
fbBuilder.finish(finish(fbBuilder), fileIdentifier);
|
||||
return fbBuilder.buffer;
|
||||
}
|
||||
}
|
||||
class Universe {
|
||||
Universe._(this._bc, this._bcOffset);
|
||||
factory Universe(List<int> bytes) {
|
||||
final rootRef = fb.BufferContext.fromBytes(bytes);
|
||||
return reader.read(rootRef, 0);
|
||||
}
|
||||
|
||||
static const fb.Reader<Universe> reader = _UniverseReader();
|
||||
|
||||
final fb.BufferContext _bc;
|
||||
final int _bcOffset;
|
||||
|
||||
double get age => const fb.Float64Reader().vTableGet(_bc, _bcOffset, 4, 0.0);
|
||||
List<Galaxy>? get galaxies => const fb.ListReader<Galaxy>(Galaxy.reader).vTableGetNullable(_bc, _bcOffset, 6);
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return 'Universe{age: ${age}, galaxies: ${galaxies}}';
|
||||
}
|
||||
}
|
||||
|
||||
class _UniverseReader extends fb.TableReader<Universe> {
|
||||
const _UniverseReader();
|
||||
|
||||
@override
|
||||
Universe createObject(fb.BufferContext bc, int offset) =>
|
||||
Universe._(bc, offset);
|
||||
}
|
||||
|
||||
class UniverseBuilder {
|
||||
UniverseBuilder(this.fbBuilder);
|
||||
|
||||
final fb.Builder fbBuilder;
|
||||
|
||||
void begin() {
|
||||
fbBuilder.startTable(2);
|
||||
}
|
||||
|
||||
int addAge(double? age) {
|
||||
fbBuilder.addFloat64(0, age);
|
||||
return fbBuilder.offset;
|
||||
}
|
||||
int addGalaxiesOffset(int? offset) {
|
||||
fbBuilder.addOffset(1, offset);
|
||||
return fbBuilder.offset;
|
||||
}
|
||||
|
||||
int finish() {
|
||||
return fbBuilder.endTable();
|
||||
}
|
||||
}
|
||||
|
||||
class UniverseObjectBuilder extends fb.ObjectBuilder {
|
||||
final double? _age;
|
||||
final List<GalaxyObjectBuilder>? _galaxies;
|
||||
|
||||
UniverseObjectBuilder({
|
||||
double? age,
|
||||
List<GalaxyObjectBuilder>? galaxies,
|
||||
})
|
||||
: _age = age,
|
||||
_galaxies = galaxies;
|
||||
|
||||
/// Finish building, and store into the [fbBuilder].
|
||||
@override
|
||||
int finish(fb.Builder fbBuilder) {
|
||||
final int? galaxiesOffset = _galaxies == null ? null
|
||||
: fbBuilder.writeList(_galaxies!.map((b) => b.getOrCreateOffset(fbBuilder)).toList());
|
||||
fbBuilder.startTable(2);
|
||||
fbBuilder.addFloat64(0, _age);
|
||||
fbBuilder.addOffset(1, galaxiesOffset);
|
||||
return fbBuilder.endTable();
|
||||
}
|
||||
|
||||
/// Convenience method to serialize to byte list.
|
||||
@override
|
||||
Uint8List toBytes([String? fileIdentifier]) {
|
||||
final fbBuilder = fb.Builder(deduplicateTables: false);
|
||||
fbBuilder.finish(finish(fbBuilder), fileIdentifier);
|
||||
return fbBuilder.buffer;
|
||||
}
|
||||
}
|
||||
10
goldens/dart/generate.py
Normal file
10
goldens/dart/generate.py
Normal file
@@ -0,0 +1,10 @@
|
||||
from golden_utils import flatc_golden
|
||||
|
||||
|
||||
def flatc(options, schema):
|
||||
# Wrap the golden flatc generator with Dart specifics
|
||||
flatc_golden(options=["--dart"] + options, schema=schema, prefix="dart")
|
||||
|
||||
|
||||
def GenerateDart():
|
||||
flatc([], "basic.fbs")
|
||||
33
goldens/generate_goldens.py
Executable file
33
goldens/generate_goldens.py
Executable file
@@ -0,0 +1,33 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
from cpp.generate import GenerateCpp
|
||||
from csharp.generate import GenerateCSharp
|
||||
from dart.generate import GenerateDart
|
||||
from go.generate import GenerateGo
|
||||
from java.generate import GenerateJava
|
||||
from kotlin.generate import GenerateKotlin
|
||||
from lobster.generate import GenerateLobster
|
||||
from lua.generate import GenerateLua
|
||||
from nim.generate import GenerateNim
|
||||
from php.generate import GeneratePhp
|
||||
from py.generate import GeneratePython
|
||||
from rust.generate import GenerateRust
|
||||
from swift.generate import GenerateSwift
|
||||
from ts.generate import GenerateTs
|
||||
|
||||
# Run each language generation logic
|
||||
GenerateCpp()
|
||||
GenerateCSharp()
|
||||
GenerateDart()
|
||||
GenerateGo()
|
||||
GenerateJava()
|
||||
GenerateKotlin()
|
||||
GenerateLobster()
|
||||
# TODO these doesn't respect the output prefix, fix and reenable
|
||||
# GenerateLua()
|
||||
# GenerateNim()
|
||||
GeneratePhp()
|
||||
GeneratePython()
|
||||
GenerateRust()
|
||||
GenerateSwift()
|
||||
GenerateTs()
|
||||
64
goldens/go/Galaxy.go
Normal file
64
goldens/go/Galaxy.go
Normal file
@@ -0,0 +1,64 @@
|
||||
// Code generated by the FlatBuffers compiler. DO NOT EDIT.
|
||||
|
||||
package Galaxy
|
||||
|
||||
import (
|
||||
flatbuffers "github.com/google/flatbuffers/go"
|
||||
)
|
||||
|
||||
type Galaxy struct {
|
||||
_tab flatbuffers.Table
|
||||
}
|
||||
|
||||
func GetRootAsGalaxy(buf []byte, offset flatbuffers.UOffsetT) *Galaxy {
|
||||
n := flatbuffers.GetUOffsetT(buf[offset:])
|
||||
x := &Galaxy{}
|
||||
x.Init(buf, n+offset)
|
||||
return x
|
||||
}
|
||||
|
||||
func FinishGalaxyBuffer(builder *flatbuffers.Builder, offset flatbuffers.UOffsetT) {
|
||||
builder.Finish(offset)
|
||||
}
|
||||
|
||||
func GetSizePrefixedRootAsGalaxy(buf []byte, offset flatbuffers.UOffsetT) *Galaxy {
|
||||
n := flatbuffers.GetUOffsetT(buf[offset+flatbuffers.SizeUint32:])
|
||||
x := &Galaxy{}
|
||||
x.Init(buf, n+offset+flatbuffers.SizeUint32)
|
||||
return x
|
||||
}
|
||||
|
||||
func FinishSizePrefixedGalaxyBuffer(builder *flatbuffers.Builder, offset flatbuffers.UOffsetT) {
|
||||
builder.FinishSizePrefixed(offset)
|
||||
}
|
||||
|
||||
func (rcv *Galaxy) Init(buf []byte, i flatbuffers.UOffsetT) {
|
||||
rcv._tab.Bytes = buf
|
||||
rcv._tab.Pos = i
|
||||
}
|
||||
|
||||
func (rcv *Galaxy) Table() flatbuffers.Table {
|
||||
return rcv._tab
|
||||
}
|
||||
|
||||
func (rcv *Galaxy) NumStars() int64 {
|
||||
o := flatbuffers.UOffsetT(rcv._tab.Offset(4))
|
||||
if o != 0 {
|
||||
return rcv._tab.GetInt64(o + rcv._tab.Pos)
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func (rcv *Galaxy) MutateNumStars(n int64) bool {
|
||||
return rcv._tab.MutateInt64Slot(4, n)
|
||||
}
|
||||
|
||||
func GalaxyStart(builder *flatbuffers.Builder) {
|
||||
builder.StartObject(1)
|
||||
}
|
||||
func GalaxyAddNumStars(builder *flatbuffers.Builder, numStars int64) {
|
||||
builder.PrependInt64Slot(0, numStars, 0)
|
||||
}
|
||||
func GalaxyEnd(builder *flatbuffers.Builder) flatbuffers.UOffsetT {
|
||||
return builder.EndObject()
|
||||
}
|
||||
90
goldens/go/Universe.go
Normal file
90
goldens/go/Universe.go
Normal file
@@ -0,0 +1,90 @@
|
||||
// Code generated by the FlatBuffers compiler. DO NOT EDIT.
|
||||
|
||||
package Universe
|
||||
|
||||
import (
|
||||
flatbuffers "github.com/google/flatbuffers/go"
|
||||
)
|
||||
|
||||
type Universe struct {
|
||||
_tab flatbuffers.Table
|
||||
}
|
||||
|
||||
func GetRootAsUniverse(buf []byte, offset flatbuffers.UOffsetT) *Universe {
|
||||
n := flatbuffers.GetUOffsetT(buf[offset:])
|
||||
x := &Universe{}
|
||||
x.Init(buf, n+offset)
|
||||
return x
|
||||
}
|
||||
|
||||
func FinishUniverseBuffer(builder *flatbuffers.Builder, offset flatbuffers.UOffsetT) {
|
||||
builder.Finish(offset)
|
||||
}
|
||||
|
||||
func GetSizePrefixedRootAsUniverse(buf []byte, offset flatbuffers.UOffsetT) *Universe {
|
||||
n := flatbuffers.GetUOffsetT(buf[offset+flatbuffers.SizeUint32:])
|
||||
x := &Universe{}
|
||||
x.Init(buf, n+offset+flatbuffers.SizeUint32)
|
||||
return x
|
||||
}
|
||||
|
||||
func FinishSizePrefixedUniverseBuffer(builder *flatbuffers.Builder, offset flatbuffers.UOffsetT) {
|
||||
builder.FinishSizePrefixed(offset)
|
||||
}
|
||||
|
||||
func (rcv *Universe) Init(buf []byte, i flatbuffers.UOffsetT) {
|
||||
rcv._tab.Bytes = buf
|
||||
rcv._tab.Pos = i
|
||||
}
|
||||
|
||||
func (rcv *Universe) Table() flatbuffers.Table {
|
||||
return rcv._tab
|
||||
}
|
||||
|
||||
func (rcv *Universe) Age() float64 {
|
||||
o := flatbuffers.UOffsetT(rcv._tab.Offset(4))
|
||||
if o != 0 {
|
||||
return rcv._tab.GetFloat64(o + rcv._tab.Pos)
|
||||
}
|
||||
return 0.0
|
||||
}
|
||||
|
||||
func (rcv *Universe) MutateAge(n float64) bool {
|
||||
return rcv._tab.MutateFloat64Slot(4, n)
|
||||
}
|
||||
|
||||
func (rcv *Universe) Galaxies(obj *Galaxy, j int) bool {
|
||||
o := flatbuffers.UOffsetT(rcv._tab.Offset(6))
|
||||
if o != 0 {
|
||||
x := rcv._tab.Vector(o)
|
||||
x += flatbuffers.UOffsetT(j) * 4
|
||||
x = rcv._tab.Indirect(x)
|
||||
obj.Init(rcv._tab.Bytes, x)
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (rcv *Universe) GalaxiesLength() int {
|
||||
o := flatbuffers.UOffsetT(rcv._tab.Offset(6))
|
||||
if o != 0 {
|
||||
return rcv._tab.VectorLen(o)
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func UniverseStart(builder *flatbuffers.Builder) {
|
||||
builder.StartObject(2)
|
||||
}
|
||||
func UniverseAddAge(builder *flatbuffers.Builder, age float64) {
|
||||
builder.PrependFloat64Slot(0, age, 0.0)
|
||||
}
|
||||
func UniverseAddGalaxies(builder *flatbuffers.Builder, galaxies flatbuffers.UOffsetT) {
|
||||
builder.PrependUOffsetTSlot(1, flatbuffers.UOffsetT(galaxies), 0)
|
||||
}
|
||||
func UniverseStartGalaxiesVector(builder *flatbuffers.Builder, numElems int) flatbuffers.UOffsetT {
|
||||
return builder.StartVector(4, numElems, 4)
|
||||
}
|
||||
func UniverseEnd(builder *flatbuffers.Builder) flatbuffers.UOffsetT {
|
||||
return builder.EndObject()
|
||||
}
|
||||
10
goldens/go/generate.py
Normal file
10
goldens/go/generate.py
Normal file
@@ -0,0 +1,10 @@
|
||||
from golden_utils import flatc_golden
|
||||
|
||||
|
||||
def flatc(options, schema):
|
||||
# Wrap the golden flatc generator with Go specifics
|
||||
flatc_golden(options=["--go"] + options, schema=schema, prefix="go")
|
||||
|
||||
|
||||
def GenerateGo():
|
||||
flatc([], "basic.fbs")
|
||||
30
goldens/golden_utils.py
Normal file
30
goldens/golden_utils.py
Normal file
@@ -0,0 +1,30 @@
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
# 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 schema
|
||||
schema_path = Path(script_path, "schema")
|
||||
|
||||
# Too add the util package in /scripts/util.py
|
||||
sys.path.append(str(root_path.absolute()))
|
||||
|
||||
from scripts.util import flatc
|
||||
|
||||
|
||||
def flatc_golden(options, schema, prefix):
|
||||
# wrap the generic flatc call with specifis for these goldens.
|
||||
flatc(
|
||||
options=options,
|
||||
# where the files are generated, typically the language (e.g. "cpp").
|
||||
prefix=prefix,
|
||||
# The schema are relative to the schema directory.
|
||||
schema=str(Path(schema_path, schema)),
|
||||
# Run flatc from this location.
|
||||
cwd=script_path,
|
||||
)
|
||||
51
goldens/java/Galaxy.java
Normal file
51
goldens/java/Galaxy.java
Normal file
@@ -0,0 +1,51 @@
|
||||
// automatically generated by the FlatBuffers compiler, do not modify
|
||||
|
||||
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 Galaxy extends Table {
|
||||
public static void ValidateVersion() { Constants.FLATBUFFERS_23_5_9(); }
|
||||
public static Galaxy getRootAsGalaxy(ByteBuffer _bb) { return getRootAsGalaxy(_bb, new Galaxy()); }
|
||||
public static Galaxy getRootAsGalaxy(ByteBuffer _bb, Galaxy 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 Galaxy __assign(int _i, ByteBuffer _bb) { __init(_i, _bb); return this; }
|
||||
|
||||
public long numStars() { int o = __offset(4); return o != 0 ? bb.getLong(o + bb_pos) : 0L; }
|
||||
|
||||
public static int createGalaxy(FlatBufferBuilder builder,
|
||||
long numStars) {
|
||||
builder.startTable(1);
|
||||
Galaxy.addNumStars(builder, numStars);
|
||||
return Galaxy.endGalaxy(builder);
|
||||
}
|
||||
|
||||
public static void startGalaxy(FlatBufferBuilder builder) { builder.startTable(1); }
|
||||
public static void addNumStars(FlatBufferBuilder builder, long numStars) { builder.addLong(0, numStars, 0L); }
|
||||
public static int endGalaxy(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 Galaxy get(int j) { return get(new Galaxy(), j); }
|
||||
public Galaxy get(Galaxy obj, int j) { return obj.__assign(__indirect(__element(j), bb), bb); }
|
||||
}
|
||||
}
|
||||
|
||||
63
goldens/java/Universe.java
Normal file
63
goldens/java/Universe.java
Normal file
@@ -0,0 +1,63 @@
|
||||
// automatically generated by the FlatBuffers compiler, do not modify
|
||||
|
||||
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 Universe extends Table {
|
||||
public static void ValidateVersion() { Constants.FLATBUFFERS_23_5_9(); }
|
||||
public static Universe getRootAsUniverse(ByteBuffer _bb) { return getRootAsUniverse(_bb, new Universe()); }
|
||||
public static Universe getRootAsUniverse(ByteBuffer _bb, Universe 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 Universe __assign(int _i, ByteBuffer _bb) { __init(_i, _bb); return this; }
|
||||
|
||||
public double age() { int o = __offset(4); return o != 0 ? bb.getDouble(o + bb_pos) : 0.0; }
|
||||
public Galaxy galaxies(int j) { return galaxies(new Galaxy(), j); }
|
||||
public Galaxy galaxies(Galaxy obj, int j) { int o = __offset(6); return o != 0 ? obj.__assign(__indirect(__vector(o) + j * 4), bb) : null; }
|
||||
public int galaxiesLength() { int o = __offset(6); return o != 0 ? __vector_len(o) : 0; }
|
||||
public Galaxy.Vector galaxiesVector() { return galaxiesVector(new Galaxy.Vector()); }
|
||||
public Galaxy.Vector galaxiesVector(Galaxy.Vector obj) { int o = __offset(6); return o != 0 ? obj.__assign(__vector(o), 4, bb) : null; }
|
||||
|
||||
public static int createUniverse(FlatBufferBuilder builder,
|
||||
double age,
|
||||
int galaxiesOffset) {
|
||||
builder.startTable(2);
|
||||
Universe.addAge(builder, age);
|
||||
Universe.addGalaxies(builder, galaxiesOffset);
|
||||
return Universe.endUniverse(builder);
|
||||
}
|
||||
|
||||
public static void startUniverse(FlatBufferBuilder builder) { builder.startTable(2); }
|
||||
public static void addAge(FlatBufferBuilder builder, double age) { builder.addDouble(0, age, 0.0); }
|
||||
public static void addGalaxies(FlatBufferBuilder builder, int galaxiesOffset) { builder.addOffset(1, galaxiesOffset, 0); }
|
||||
public static int createGalaxiesVector(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 startGalaxiesVector(FlatBufferBuilder builder, int numElems) { builder.startVector(4, numElems, 4); }
|
||||
public static int endUniverse(FlatBufferBuilder builder) {
|
||||
int o = builder.endTable();
|
||||
return o;
|
||||
}
|
||||
public static void finishUniverseBuffer(FlatBufferBuilder builder, int offset) { builder.finish(offset); }
|
||||
public static void finishSizePrefixedUniverseBuffer(FlatBufferBuilder builder, int offset) { builder.finishSizePrefixed(offset); }
|
||||
|
||||
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 Universe get(int j) { return get(new Universe(), j); }
|
||||
public Universe get(Universe obj, int j) { return obj.__assign(__indirect(__element(j), bb), bb); }
|
||||
}
|
||||
}
|
||||
|
||||
10
goldens/java/generate.py
Normal file
10
goldens/java/generate.py
Normal file
@@ -0,0 +1,10 @@
|
||||
from golden_utils import flatc_golden
|
||||
|
||||
|
||||
def flatc(options, schema):
|
||||
# Wrap the golden flatc generator with Java specifics
|
||||
flatc_golden(options=["--java"] + options, schema=schema, prefix="java")
|
||||
|
||||
|
||||
def GenerateJava():
|
||||
flatc([], "basic.fbs")
|
||||
53
goldens/kotlin/Galaxy.kt
Normal file
53
goldens/kotlin/Galaxy.kt
Normal file
@@ -0,0 +1,53 @@
|
||||
// automatically generated by the FlatBuffers compiler, do not modify
|
||||
|
||||
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
|
||||
|
||||
@Suppress("unused")
|
||||
class Galaxy : Table() {
|
||||
|
||||
fun __init(_i: Int, _bb: ByteBuffer) {
|
||||
__reset(_i, _bb)
|
||||
}
|
||||
fun __assign(_i: Int, _bb: ByteBuffer) : Galaxy {
|
||||
__init(_i, _bb)
|
||||
return this
|
||||
}
|
||||
val numStars : Long
|
||||
get() {
|
||||
val o = __offset(4)
|
||||
return if(o != 0) bb.getLong(o + bb_pos) else 0L
|
||||
}
|
||||
companion object {
|
||||
fun validateVersion() = Constants.FLATBUFFERS_23_5_9()
|
||||
fun getRootAsGalaxy(_bb: ByteBuffer): Galaxy = getRootAsGalaxy(_bb, Galaxy())
|
||||
fun getRootAsGalaxy(_bb: ByteBuffer, obj: Galaxy): Galaxy {
|
||||
_bb.order(ByteOrder.LITTLE_ENDIAN)
|
||||
return (obj.__assign(_bb.getInt(_bb.position()) + _bb.position(), _bb))
|
||||
}
|
||||
fun createGalaxy(builder: FlatBufferBuilder, numStars: Long) : Int {
|
||||
builder.startTable(1)
|
||||
addNumStars(builder, numStars)
|
||||
return endGalaxy(builder)
|
||||
}
|
||||
fun startGalaxy(builder: FlatBufferBuilder) = builder.startTable(1)
|
||||
fun addNumStars(builder: FlatBufferBuilder, numStars: Long) = builder.addLong(0, numStars, 0L)
|
||||
fun endGalaxy(builder: FlatBufferBuilder) : Int {
|
||||
val o = builder.endTable()
|
||||
return o
|
||||
}
|
||||
}
|
||||
}
|
||||
78
goldens/kotlin/Universe.kt
Normal file
78
goldens/kotlin/Universe.kt
Normal file
@@ -0,0 +1,78 @@
|
||||
// automatically generated by the FlatBuffers compiler, do not modify
|
||||
|
||||
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
|
||||
|
||||
@Suppress("unused")
|
||||
class Universe : Table() {
|
||||
|
||||
fun __init(_i: Int, _bb: ByteBuffer) {
|
||||
__reset(_i, _bb)
|
||||
}
|
||||
fun __assign(_i: Int, _bb: ByteBuffer) : Universe {
|
||||
__init(_i, _bb)
|
||||
return this
|
||||
}
|
||||
val age : Double
|
||||
get() {
|
||||
val o = __offset(4)
|
||||
return if(o != 0) bb.getDouble(o + bb_pos) else 0.0
|
||||
}
|
||||
fun galaxies(j: Int) : Galaxy? = galaxies(Galaxy(), j)
|
||||
fun galaxies(obj: Galaxy, j: Int) : Galaxy? {
|
||||
val o = __offset(6)
|
||||
return if (o != 0) {
|
||||
obj.__assign(__indirect(__vector(o) + j * 4), bb)
|
||||
} else {
|
||||
null
|
||||
}
|
||||
}
|
||||
val galaxiesLength : Int
|
||||
get() {
|
||||
val o = __offset(6); return if (o != 0) __vector_len(o) else 0
|
||||
}
|
||||
companion object {
|
||||
fun validateVersion() = Constants.FLATBUFFERS_23_5_9()
|
||||
fun getRootAsUniverse(_bb: ByteBuffer): Universe = getRootAsUniverse(_bb, Universe())
|
||||
fun getRootAsUniverse(_bb: ByteBuffer, obj: Universe): Universe {
|
||||
_bb.order(ByteOrder.LITTLE_ENDIAN)
|
||||
return (obj.__assign(_bb.getInt(_bb.position()) + _bb.position(), _bb))
|
||||
}
|
||||
fun createUniverse(builder: FlatBufferBuilder, age: Double, galaxiesOffset: Int) : Int {
|
||||
builder.startTable(2)
|
||||
addAge(builder, age)
|
||||
addGalaxies(builder, galaxiesOffset)
|
||||
return endUniverse(builder)
|
||||
}
|
||||
fun startUniverse(builder: FlatBufferBuilder) = builder.startTable(2)
|
||||
fun addAge(builder: FlatBufferBuilder, age: Double) = builder.addDouble(0, age, 0.0)
|
||||
fun addGalaxies(builder: FlatBufferBuilder, galaxies: Int) = builder.addOffset(1, galaxies, 0)
|
||||
fun createGalaxiesVector(builder: FlatBufferBuilder, data: IntArray) : Int {
|
||||
builder.startVector(4, data.size, 4)
|
||||
for (i in data.size - 1 downTo 0) {
|
||||
builder.addOffset(data[i])
|
||||
}
|
||||
return builder.endVector()
|
||||
}
|
||||
fun startGalaxiesVector(builder: FlatBufferBuilder, numElems: Int) = builder.startVector(4, numElems, 4)
|
||||
fun endUniverse(builder: FlatBufferBuilder) : Int {
|
||||
val o = builder.endTable()
|
||||
return o
|
||||
}
|
||||
fun finishUniverseBuffer(builder: FlatBufferBuilder, offset: Int) = builder.finish(offset)
|
||||
fun finishSizePrefixedUniverseBuffer(builder: FlatBufferBuilder, offset: Int) = builder.finishSizePrefixed(offset)
|
||||
}
|
||||
}
|
||||
10
goldens/kotlin/generate.py
Normal file
10
goldens/kotlin/generate.py
Normal file
@@ -0,0 +1,10 @@
|
||||
from golden_utils import flatc_golden
|
||||
|
||||
|
||||
def flatc(options, schema):
|
||||
# Wrap the golden flatc generator with Kotlin specifics
|
||||
flatc_golden(options=["--kotlin"] + options, schema=schema, prefix="kotlin")
|
||||
|
||||
|
||||
def GenerateKotlin():
|
||||
flatc([], "basic.fbs")
|
||||
55
goldens/lobster/basic_generated.lobster
Normal file
55
goldens/lobster/basic_generated.lobster
Normal file
@@ -0,0 +1,55 @@
|
||||
// automatically generated by the FlatBuffers compiler, do not modify
|
||||
import flatbuffers
|
||||
|
||||
class Galaxy
|
||||
|
||||
class Universe
|
||||
|
||||
class Galaxy : flatbuffers_handle
|
||||
def num_stars() -> int:
|
||||
return buf_.flatbuffers_field_int64(pos_, 4, 0)
|
||||
|
||||
def GetRootAsGalaxy(buf:string): return Galaxy { buf, buf.flatbuffers_indirect(0) }
|
||||
|
||||
struct GalaxyBuilder:
|
||||
b_:flatbuffers_builder
|
||||
def start():
|
||||
b_.StartObject(1)
|
||||
return this
|
||||
def add_num_stars(num_stars:int):
|
||||
b_.PrependInt64Slot(0, num_stars, 0)
|
||||
return this
|
||||
def end():
|
||||
return b_.EndObject()
|
||||
|
||||
class Universe : flatbuffers_handle
|
||||
def age() -> float:
|
||||
return buf_.flatbuffers_field_float64(pos_, 4, 0.0)
|
||||
def galaxies(i:int) -> Galaxy:
|
||||
return Galaxy { buf_, buf_.flatbuffers_indirect(buf_.flatbuffers_field_vector(pos_, 6) + i * 4) }
|
||||
def galaxies_length() -> int:
|
||||
return buf_.flatbuffers_field_vector_len(pos_, 6)
|
||||
|
||||
def GetRootAsUniverse(buf:string): return Universe { buf, buf.flatbuffers_indirect(0) }
|
||||
|
||||
struct UniverseBuilder:
|
||||
b_:flatbuffers_builder
|
||||
def start():
|
||||
b_.StartObject(2)
|
||||
return this
|
||||
def add_age(age:float):
|
||||
b_.PrependFloat64Slot(0, age, 0.0)
|
||||
return this
|
||||
def add_galaxies(galaxies:flatbuffers_offset):
|
||||
b_.PrependUOffsetTRelativeSlot(1, galaxies)
|
||||
return this
|
||||
def end():
|
||||
return b_.EndObject()
|
||||
|
||||
def UniverseStartGalaxiesVector(b_:flatbuffers_builder, n_:int):
|
||||
b_.StartVector(4, n_, 4)
|
||||
def UniverseCreateGalaxiesVector(b_:flatbuffers_builder, v_:[flatbuffers_offset]):
|
||||
b_.StartVector(4, v_.length, 4)
|
||||
reverse(v_) e_: b_.PrependUOffsetTRelative(e_)
|
||||
return b_.EndVector(v_.length)
|
||||
|
||||
10
goldens/lobster/generate.py
Normal file
10
goldens/lobster/generate.py
Normal file
@@ -0,0 +1,10 @@
|
||||
from golden_utils import flatc_golden
|
||||
|
||||
|
||||
def flatc(options, schema):
|
||||
# Wrap the golden flatc generator with Lobster specifics
|
||||
flatc_golden(options=["--lobster"] + options, schema=schema, prefix="lobster")
|
||||
|
||||
|
||||
def GenerateLobster():
|
||||
flatc([], "basic.fbs")
|
||||
10
goldens/lua/generate.py
Normal file
10
goldens/lua/generate.py
Normal file
@@ -0,0 +1,10 @@
|
||||
from golden_utils import flatc_golden
|
||||
|
||||
|
||||
def flatc(options, schema):
|
||||
# Wrap the golden flatc generator with Lua specifics
|
||||
flatc_golden(options=["--lua"] + options, schema=schema, prefix="lua")
|
||||
|
||||
|
||||
def GenerateLua():
|
||||
flatc([], "basic.fbs")
|
||||
10
goldens/nim/generate.py
Normal file
10
goldens/nim/generate.py
Normal file
@@ -0,0 +1,10 @@
|
||||
from golden_utils import flatc_golden
|
||||
|
||||
|
||||
def flatc(options, schema):
|
||||
# Wrap the golden flatc generator with Nim specifics
|
||||
flatc_golden(options=["--nim"] + options, schema=schema, prefix="nim")
|
||||
|
||||
|
||||
def GenerateNim():
|
||||
flatc([], "basic.fbs")
|
||||
82
goldens/php/Galaxy.php
Normal file
82
goldens/php/Galaxy.php
Normal file
@@ -0,0 +1,82 @@
|
||||
<?php
|
||||
// automatically generated by the FlatBuffers compiler, do not modify
|
||||
|
||||
use \Google\FlatBuffers\Struct;
|
||||
use \Google\FlatBuffers\Table;
|
||||
use \Google\FlatBuffers\ByteBuffer;
|
||||
use \Google\FlatBuffers\FlatBufferBuilder;
|
||||
|
||||
class Galaxy extends Table
|
||||
{
|
||||
/**
|
||||
* @param ByteBuffer $bb
|
||||
* @return Galaxy
|
||||
*/
|
||||
public static function getRootAsGalaxy(ByteBuffer $bb)
|
||||
{
|
||||
$obj = new Galaxy();
|
||||
return ($obj->init($bb->getInt($bb->getPosition()) + $bb->getPosition(), $bb));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $_i offset
|
||||
* @param ByteBuffer $_bb
|
||||
* @return Galaxy
|
||||
**/
|
||||
public function init($_i, ByteBuffer $_bb)
|
||||
{
|
||||
$this->bb_pos = $_i;
|
||||
$this->bb = $_bb;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return long
|
||||
*/
|
||||
public function getNumStars()
|
||||
{
|
||||
$o = $this->__offset(4);
|
||||
return $o != 0 ? $this->bb->getLong($o + $this->bb_pos) : 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param FlatBufferBuilder $builder
|
||||
* @return void
|
||||
*/
|
||||
public static function startGalaxy(FlatBufferBuilder $builder)
|
||||
{
|
||||
$builder->StartObject(1);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param FlatBufferBuilder $builder
|
||||
* @return Galaxy
|
||||
*/
|
||||
public static function createGalaxy(FlatBufferBuilder $builder, $num_stars)
|
||||
{
|
||||
$builder->startObject(1);
|
||||
self::addNumStars($builder, $num_stars);
|
||||
$o = $builder->endObject();
|
||||
return $o;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param FlatBufferBuilder $builder
|
||||
* @param long
|
||||
* @return void
|
||||
*/
|
||||
public static function addNumStars(FlatBufferBuilder $builder, $numStars)
|
||||
{
|
||||
$builder->addLongX(0, $numStars, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param FlatBufferBuilder $builder
|
||||
* @return int table offset
|
||||
*/
|
||||
public static function endGalaxy(FlatBufferBuilder $builder)
|
||||
{
|
||||
$o = $builder->endObject();
|
||||
return $o;
|
||||
}
|
||||
}
|
||||
141
goldens/php/Universe.php
Normal file
141
goldens/php/Universe.php
Normal file
@@ -0,0 +1,141 @@
|
||||
<?php
|
||||
// automatically generated by the FlatBuffers compiler, do not modify
|
||||
|
||||
use \Google\FlatBuffers\Struct;
|
||||
use \Google\FlatBuffers\Table;
|
||||
use \Google\FlatBuffers\ByteBuffer;
|
||||
use \Google\FlatBuffers\FlatBufferBuilder;
|
||||
|
||||
class Universe extends Table
|
||||
{
|
||||
/**
|
||||
* @param ByteBuffer $bb
|
||||
* @return Universe
|
||||
*/
|
||||
public static function getRootAsUniverse(ByteBuffer $bb)
|
||||
{
|
||||
$obj = new Universe();
|
||||
return ($obj->init($bb->getInt($bb->getPosition()) + $bb->getPosition(), $bb));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $_i offset
|
||||
* @param ByteBuffer $_bb
|
||||
* @return Universe
|
||||
**/
|
||||
public function init($_i, ByteBuffer $_bb)
|
||||
{
|
||||
$this->bb_pos = $_i;
|
||||
$this->bb = $_bb;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return double
|
||||
*/
|
||||
public function getAge()
|
||||
{
|
||||
$o = $this->__offset(4);
|
||||
return $o != 0 ? $this->bb->getDouble($o + $this->bb_pos) : 0.0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @returnVectorOffset
|
||||
*/
|
||||
public function getGalaxies($j)
|
||||
{
|
||||
$o = $this->__offset(6);
|
||||
$obj = new Galaxy();
|
||||
return $o != 0 ? $obj->init($this->__indirect($this->__vector($o) + $j * 4), $this->bb) : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getGalaxiesLength()
|
||||
{
|
||||
$o = $this->__offset(6);
|
||||
return $o != 0 ? $this->__vector_len($o) : 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param FlatBufferBuilder $builder
|
||||
* @return void
|
||||
*/
|
||||
public static function startUniverse(FlatBufferBuilder $builder)
|
||||
{
|
||||
$builder->StartObject(2);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param FlatBufferBuilder $builder
|
||||
* @return Universe
|
||||
*/
|
||||
public static function createUniverse(FlatBufferBuilder $builder, $age, $galaxies)
|
||||
{
|
||||
$builder->startObject(2);
|
||||
self::addAge($builder, $age);
|
||||
self::addGalaxies($builder, $galaxies);
|
||||
$o = $builder->endObject();
|
||||
return $o;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param FlatBufferBuilder $builder
|
||||
* @param double
|
||||
* @return void
|
||||
*/
|
||||
public static function addAge(FlatBufferBuilder $builder, $age)
|
||||
{
|
||||
$builder->addDoubleX(0, $age, 0.0);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param FlatBufferBuilder $builder
|
||||
* @param VectorOffset
|
||||
* @return void
|
||||
*/
|
||||
public static function addGalaxies(FlatBufferBuilder $builder, $galaxies)
|
||||
{
|
||||
$builder->addOffsetX(1, $galaxies, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param FlatBufferBuilder $builder
|
||||
* @param array offset array
|
||||
* @return int vector offset
|
||||
*/
|
||||
public static function createGalaxiesVector(FlatBufferBuilder $builder, array $data)
|
||||
{
|
||||
$builder->startVector(4, count($data), 4);
|
||||
for ($i = count($data) - 1; $i >= 0; $i--) {
|
||||
$builder->putOffset($data[$i]);
|
||||
}
|
||||
return $builder->endVector();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param FlatBufferBuilder $builder
|
||||
* @param int $numElems
|
||||
* @return void
|
||||
*/
|
||||
public static function startGalaxiesVector(FlatBufferBuilder $builder, $numElems)
|
||||
{
|
||||
$builder->startVector(4, $numElems, 4);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param FlatBufferBuilder $builder
|
||||
* @return int table offset
|
||||
*/
|
||||
public static function endUniverse(FlatBufferBuilder $builder)
|
||||
{
|
||||
$o = $builder->endObject();
|
||||
return $o;
|
||||
}
|
||||
|
||||
public static function finishUniverseBuffer(FlatBufferBuilder $builder, $offset)
|
||||
{
|
||||
$builder->finish($offset);
|
||||
}
|
||||
}
|
||||
10
goldens/php/generate.py
Normal file
10
goldens/php/generate.py
Normal file
@@ -0,0 +1,10 @@
|
||||
from golden_utils import flatc_golden
|
||||
|
||||
|
||||
def flatc(options, schema):
|
||||
# Wrap the golden flatc generator with PHP specifics
|
||||
flatc_golden(options=["--php"] + options, schema=schema, prefix="php")
|
||||
|
||||
|
||||
def GeneratePhp():
|
||||
flatc([], "basic.fbs")
|
||||
50
goldens/py/Galaxy.py
Normal file
50
goldens/py/Galaxy.py
Normal file
@@ -0,0 +1,50 @@
|
||||
# automatically generated by the FlatBuffers compiler, do not modify
|
||||
|
||||
# namespace:
|
||||
|
||||
import flatbuffers
|
||||
from flatbuffers.compat import import_numpy
|
||||
np = import_numpy()
|
||||
|
||||
class Galaxy(object):
|
||||
__slots__ = ['_tab']
|
||||
|
||||
@classmethod
|
||||
def GetRootAs(cls, buf, offset=0):
|
||||
n = flatbuffers.encode.Get(flatbuffers.packer.uoffset, buf, offset)
|
||||
x = Galaxy()
|
||||
x.Init(buf, n + offset)
|
||||
return x
|
||||
|
||||
@classmethod
|
||||
def GetRootAsGalaxy(cls, buf, offset=0):
|
||||
"""This method is deprecated. Please switch to GetRootAs."""
|
||||
return cls.GetRootAs(buf, offset)
|
||||
# Galaxy
|
||||
def Init(self, buf, pos):
|
||||
self._tab = flatbuffers.table.Table(buf, pos)
|
||||
|
||||
# Galaxy
|
||||
def NumStars(self):
|
||||
o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(4))
|
||||
if o != 0:
|
||||
return self._tab.Get(flatbuffers.number_types.Int64Flags, o + self._tab.Pos)
|
||||
return 0
|
||||
|
||||
def GalaxyStart(builder):
|
||||
builder.StartObject(1)
|
||||
|
||||
def Start(builder):
|
||||
GalaxyStart(builder)
|
||||
|
||||
def GalaxyAddNumStars(builder, numStars):
|
||||
builder.PrependInt64Slot(0, numStars, 0)
|
||||
|
||||
def AddNumStars(builder: flatbuffers.Builder, numStars: int):
|
||||
GalaxyAddNumStars(builder, numStars)
|
||||
|
||||
def GalaxyEnd(builder):
|
||||
return builder.EndObject()
|
||||
|
||||
def End(builder):
|
||||
return GalaxyEnd(builder)
|
||||
87
goldens/py/Universe.py
Normal file
87
goldens/py/Universe.py
Normal file
@@ -0,0 +1,87 @@
|
||||
# automatically generated by the FlatBuffers compiler, do not modify
|
||||
|
||||
# namespace:
|
||||
|
||||
import flatbuffers
|
||||
from flatbuffers.compat import import_numpy
|
||||
np = import_numpy()
|
||||
|
||||
class Universe(object):
|
||||
__slots__ = ['_tab']
|
||||
|
||||
@classmethod
|
||||
def GetRootAs(cls, buf, offset=0):
|
||||
n = flatbuffers.encode.Get(flatbuffers.packer.uoffset, buf, offset)
|
||||
x = Universe()
|
||||
x.Init(buf, n + offset)
|
||||
return x
|
||||
|
||||
@classmethod
|
||||
def GetRootAsUniverse(cls, buf, offset=0):
|
||||
"""This method is deprecated. Please switch to GetRootAs."""
|
||||
return cls.GetRootAs(buf, offset)
|
||||
# Universe
|
||||
def Init(self, buf, pos):
|
||||
self._tab = flatbuffers.table.Table(buf, pos)
|
||||
|
||||
# Universe
|
||||
def Age(self):
|
||||
o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(4))
|
||||
if o != 0:
|
||||
return self._tab.Get(flatbuffers.number_types.Float64Flags, o + self._tab.Pos)
|
||||
return 0.0
|
||||
|
||||
# Universe
|
||||
def Galaxies(self, j):
|
||||
o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(6))
|
||||
if o != 0:
|
||||
x = self._tab.Vector(o)
|
||||
x += flatbuffers.number_types.UOffsetTFlags.py_type(j) * 4
|
||||
x = self._tab.Indirect(x)
|
||||
from .Galaxy import Galaxy
|
||||
obj = Galaxy()
|
||||
obj.Init(self._tab.Bytes, x)
|
||||
return obj
|
||||
return None
|
||||
|
||||
# Universe
|
||||
def GalaxiesLength(self):
|
||||
o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(6))
|
||||
if o != 0:
|
||||
return self._tab.VectorLen(o)
|
||||
return 0
|
||||
|
||||
# Universe
|
||||
def GalaxiesIsNone(self):
|
||||
o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(6))
|
||||
return o == 0
|
||||
|
||||
def UniverseStart(builder):
|
||||
builder.StartObject(2)
|
||||
|
||||
def Start(builder):
|
||||
UniverseStart(builder)
|
||||
|
||||
def UniverseAddAge(builder, age):
|
||||
builder.PrependFloat64Slot(0, age, 0.0)
|
||||
|
||||
def AddAge(builder: flatbuffers.Builder, age: float):
|
||||
UniverseAddAge(builder, age)
|
||||
|
||||
def UniverseAddGalaxies(builder, galaxies):
|
||||
builder.PrependUOffsetTRelativeSlot(1, flatbuffers.number_types.UOffsetTFlags.py_type(galaxies), 0)
|
||||
|
||||
def AddGalaxies(builder: flatbuffers.Builder, galaxies: int):
|
||||
UniverseAddGalaxies(builder, galaxies)
|
||||
|
||||
def UniverseStartGalaxiesVector(builder, numElems):
|
||||
return builder.StartVector(4, numElems, 4)
|
||||
|
||||
def StartGalaxiesVector(builder, numElems: int) -> int:
|
||||
return UniverseStartGalaxiesVector(builder, numElems)
|
||||
|
||||
def UniverseEnd(builder):
|
||||
return builder.EndObject()
|
||||
|
||||
def End(builder):
|
||||
return UniverseEnd(builder)
|
||||
0
goldens/py/__init__.py
Normal file
0
goldens/py/__init__.py
Normal file
10
goldens/py/generate.py
Normal file
10
goldens/py/generate.py
Normal file
@@ -0,0 +1,10 @@
|
||||
from golden_utils import flatc_golden
|
||||
|
||||
|
||||
def flatc(options, schema):
|
||||
# Wrap the golden flatc generator with Python specifics
|
||||
flatc_golden(options=["--python"] + options, schema=schema, prefix="py")
|
||||
|
||||
|
||||
def GeneratePython():
|
||||
flatc([], "basic.fbs")
|
||||
293
goldens/rust/basic_generated.rs
Normal file
293
goldens/rust/basic_generated.rs
Normal file
@@ -0,0 +1,293 @@
|
||||
// automatically generated by the FlatBuffers compiler, do not modify
|
||||
|
||||
|
||||
// @generated
|
||||
|
||||
use core::mem;
|
||||
use core::cmp::Ordering;
|
||||
|
||||
extern crate flatbuffers;
|
||||
use self::flatbuffers::{EndianScalar, Follow};
|
||||
|
||||
pub enum GalaxyOffset {}
|
||||
#[derive(Copy, Clone, PartialEq)]
|
||||
|
||||
pub struct Galaxy<'a> {
|
||||
pub _tab: flatbuffers::Table<'a>,
|
||||
}
|
||||
|
||||
impl<'a> flatbuffers::Follow<'a> for Galaxy<'a> {
|
||||
type Inner = Galaxy<'a>;
|
||||
#[inline]
|
||||
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
Self { _tab: flatbuffers::Table::new(buf, loc) }
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> Galaxy<'a> {
|
||||
pub const VT_NUM_STARS: flatbuffers::VOffsetT = 4;
|
||||
|
||||
#[inline]
|
||||
pub unsafe fn init_from_table(table: flatbuffers::Table<'a>) -> Self {
|
||||
Galaxy { _tab: table }
|
||||
}
|
||||
#[allow(unused_mut)]
|
||||
pub fn create<'bldr: 'args, 'args: 'mut_bldr, 'mut_bldr>(
|
||||
_fbb: &'mut_bldr mut flatbuffers::FlatBufferBuilder<'bldr>,
|
||||
args: &'args GalaxyArgs
|
||||
) -> flatbuffers::WIPOffset<Galaxy<'bldr>> {
|
||||
let mut builder = GalaxyBuilder::new(_fbb);
|
||||
builder.add_num_stars(args.num_stars);
|
||||
builder.finish()
|
||||
}
|
||||
|
||||
|
||||
#[inline]
|
||||
pub fn num_stars(&self) -> i64 {
|
||||
// Safety:
|
||||
// Created from valid Table for this object
|
||||
// which contains a valid value in this slot
|
||||
unsafe { self._tab.get::<i64>(Galaxy::VT_NUM_STARS, Some(0)).unwrap()}
|
||||
}
|
||||
}
|
||||
|
||||
impl flatbuffers::Verifiable for Galaxy<'_> {
|
||||
#[inline]
|
||||
fn run_verifier(
|
||||
v: &mut flatbuffers::Verifier, pos: usize
|
||||
) -> Result<(), flatbuffers::InvalidFlatbuffer> {
|
||||
use self::flatbuffers::Verifiable;
|
||||
v.visit_table(pos)?
|
||||
.visit_field::<i64>("num_stars", Self::VT_NUM_STARS, false)?
|
||||
.finish();
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
pub struct GalaxyArgs {
|
||||
pub num_stars: i64,
|
||||
}
|
||||
impl<'a> Default for GalaxyArgs {
|
||||
#[inline]
|
||||
fn default() -> Self {
|
||||
GalaxyArgs {
|
||||
num_stars: 0,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub struct GalaxyBuilder<'a: 'b, 'b> {
|
||||
fbb_: &'b mut flatbuffers::FlatBufferBuilder<'a>,
|
||||
start_: flatbuffers::WIPOffset<flatbuffers::TableUnfinishedWIPOffset>,
|
||||
}
|
||||
impl<'a: 'b, 'b> GalaxyBuilder<'a, 'b> {
|
||||
#[inline]
|
||||
pub fn add_num_stars(&mut self, num_stars: i64) {
|
||||
self.fbb_.push_slot::<i64>(Galaxy::VT_NUM_STARS, num_stars, 0);
|
||||
}
|
||||
#[inline]
|
||||
pub fn new(_fbb: &'b mut flatbuffers::FlatBufferBuilder<'a>) -> GalaxyBuilder<'a, 'b> {
|
||||
let start = _fbb.start_table();
|
||||
GalaxyBuilder {
|
||||
fbb_: _fbb,
|
||||
start_: start,
|
||||
}
|
||||
}
|
||||
#[inline]
|
||||
pub fn finish(self) -> flatbuffers::WIPOffset<Galaxy<'a>> {
|
||||
let o = self.fbb_.end_table(self.start_);
|
||||
flatbuffers::WIPOffset::new(o.value())
|
||||
}
|
||||
}
|
||||
|
||||
impl core::fmt::Debug for Galaxy<'_> {
|
||||
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
|
||||
let mut ds = f.debug_struct("Galaxy");
|
||||
ds.field("num_stars", &self.num_stars());
|
||||
ds.finish()
|
||||
}
|
||||
}
|
||||
pub enum UniverseOffset {}
|
||||
#[derive(Copy, Clone, PartialEq)]
|
||||
|
||||
pub struct Universe<'a> {
|
||||
pub _tab: flatbuffers::Table<'a>,
|
||||
}
|
||||
|
||||
impl<'a> flatbuffers::Follow<'a> for Universe<'a> {
|
||||
type Inner = Universe<'a>;
|
||||
#[inline]
|
||||
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||
Self { _tab: flatbuffers::Table::new(buf, loc) }
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> Universe<'a> {
|
||||
pub const VT_AGE: flatbuffers::VOffsetT = 4;
|
||||
pub const VT_GALAXIES: flatbuffers::VOffsetT = 6;
|
||||
|
||||
#[inline]
|
||||
pub unsafe fn init_from_table(table: flatbuffers::Table<'a>) -> Self {
|
||||
Universe { _tab: table }
|
||||
}
|
||||
#[allow(unused_mut)]
|
||||
pub fn create<'bldr: 'args, 'args: 'mut_bldr, 'mut_bldr>(
|
||||
_fbb: &'mut_bldr mut flatbuffers::FlatBufferBuilder<'bldr>,
|
||||
args: &'args UniverseArgs<'args>
|
||||
) -> flatbuffers::WIPOffset<Universe<'bldr>> {
|
||||
let mut builder = UniverseBuilder::new(_fbb);
|
||||
builder.add_age(args.age);
|
||||
if let Some(x) = args.galaxies { builder.add_galaxies(x); }
|
||||
builder.finish()
|
||||
}
|
||||
|
||||
|
||||
#[inline]
|
||||
pub fn age(&self) -> f64 {
|
||||
// Safety:
|
||||
// Created from valid Table for this object
|
||||
// which contains a valid value in this slot
|
||||
unsafe { self._tab.get::<f64>(Universe::VT_AGE, Some(0.0)).unwrap()}
|
||||
}
|
||||
#[inline]
|
||||
pub fn galaxies(&self) -> Option<flatbuffers::Vector<'a, flatbuffers::ForwardsUOffset<Galaxy<'a>>>> {
|
||||
// Safety:
|
||||
// Created from valid Table for this object
|
||||
// which contains a valid value in this slot
|
||||
unsafe { self._tab.get::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<'a, flatbuffers::ForwardsUOffset<Galaxy>>>>(Universe::VT_GALAXIES, None)}
|
||||
}
|
||||
}
|
||||
|
||||
impl flatbuffers::Verifiable for Universe<'_> {
|
||||
#[inline]
|
||||
fn run_verifier(
|
||||
v: &mut flatbuffers::Verifier, pos: usize
|
||||
) -> Result<(), flatbuffers::InvalidFlatbuffer> {
|
||||
use self::flatbuffers::Verifiable;
|
||||
v.visit_table(pos)?
|
||||
.visit_field::<f64>("age", Self::VT_AGE, false)?
|
||||
.visit_field::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<'_, flatbuffers::ForwardsUOffset<Galaxy>>>>("galaxies", Self::VT_GALAXIES, false)?
|
||||
.finish();
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
pub struct UniverseArgs<'a> {
|
||||
pub age: f64,
|
||||
pub galaxies: Option<flatbuffers::WIPOffset<flatbuffers::Vector<'a, flatbuffers::ForwardsUOffset<Galaxy<'a>>>>>,
|
||||
}
|
||||
impl<'a> Default for UniverseArgs<'a> {
|
||||
#[inline]
|
||||
fn default() -> Self {
|
||||
UniverseArgs {
|
||||
age: 0.0,
|
||||
galaxies: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub struct UniverseBuilder<'a: 'b, 'b> {
|
||||
fbb_: &'b mut flatbuffers::FlatBufferBuilder<'a>,
|
||||
start_: flatbuffers::WIPOffset<flatbuffers::TableUnfinishedWIPOffset>,
|
||||
}
|
||||
impl<'a: 'b, 'b> UniverseBuilder<'a, 'b> {
|
||||
#[inline]
|
||||
pub fn add_age(&mut self, age: f64) {
|
||||
self.fbb_.push_slot::<f64>(Universe::VT_AGE, age, 0.0);
|
||||
}
|
||||
#[inline]
|
||||
pub fn add_galaxies(&mut self, galaxies: flatbuffers::WIPOffset<flatbuffers::Vector<'b , flatbuffers::ForwardsUOffset<Galaxy<'b >>>>) {
|
||||
self.fbb_.push_slot_always::<flatbuffers::WIPOffset<_>>(Universe::VT_GALAXIES, galaxies);
|
||||
}
|
||||
#[inline]
|
||||
pub fn new(_fbb: &'b mut flatbuffers::FlatBufferBuilder<'a>) -> UniverseBuilder<'a, 'b> {
|
||||
let start = _fbb.start_table();
|
||||
UniverseBuilder {
|
||||
fbb_: _fbb,
|
||||
start_: start,
|
||||
}
|
||||
}
|
||||
#[inline]
|
||||
pub fn finish(self) -> flatbuffers::WIPOffset<Universe<'a>> {
|
||||
let o = self.fbb_.end_table(self.start_);
|
||||
flatbuffers::WIPOffset::new(o.value())
|
||||
}
|
||||
}
|
||||
|
||||
impl core::fmt::Debug for Universe<'_> {
|
||||
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
|
||||
let mut ds = f.debug_struct("Universe");
|
||||
ds.field("age", &self.age());
|
||||
ds.field("galaxies", &self.galaxies());
|
||||
ds.finish()
|
||||
}
|
||||
}
|
||||
#[inline]
|
||||
/// Verifies that a buffer of bytes contains a `Universe`
|
||||
/// and returns it.
|
||||
/// Note that verification is still experimental and may not
|
||||
/// catch every error, or be maximally performant. For the
|
||||
/// previous, unchecked, behavior use
|
||||
/// `root_as_universe_unchecked`.
|
||||
pub fn root_as_universe(buf: &[u8]) -> Result<Universe, flatbuffers::InvalidFlatbuffer> {
|
||||
flatbuffers::root::<Universe>(buf)
|
||||
}
|
||||
#[inline]
|
||||
/// Verifies that a buffer of bytes contains a size prefixed
|
||||
/// `Universe` and returns it.
|
||||
/// Note that verification is still experimental and may not
|
||||
/// catch every error, or be maximally performant. For the
|
||||
/// previous, unchecked, behavior use
|
||||
/// `size_prefixed_root_as_universe_unchecked`.
|
||||
pub fn size_prefixed_root_as_universe(buf: &[u8]) -> Result<Universe, flatbuffers::InvalidFlatbuffer> {
|
||||
flatbuffers::size_prefixed_root::<Universe>(buf)
|
||||
}
|
||||
#[inline]
|
||||
/// Verifies, with the given options, that a buffer of bytes
|
||||
/// contains a `Universe` and returns it.
|
||||
/// Note that verification is still experimental and may not
|
||||
/// catch every error, or be maximally performant. For the
|
||||
/// previous, unchecked, behavior use
|
||||
/// `root_as_universe_unchecked`.
|
||||
pub fn root_as_universe_with_opts<'b, 'o>(
|
||||
opts: &'o flatbuffers::VerifierOptions,
|
||||
buf: &'b [u8],
|
||||
) -> Result<Universe<'b>, flatbuffers::InvalidFlatbuffer> {
|
||||
flatbuffers::root_with_opts::<Universe<'b>>(opts, buf)
|
||||
}
|
||||
#[inline]
|
||||
/// Verifies, with the given verifier options, that a buffer of
|
||||
/// bytes contains a size prefixed `Universe` and returns
|
||||
/// it. Note that verification is still experimental and may not
|
||||
/// catch every error, or be maximally performant. For the
|
||||
/// previous, unchecked, behavior use
|
||||
/// `root_as_universe_unchecked`.
|
||||
pub fn size_prefixed_root_as_universe_with_opts<'b, 'o>(
|
||||
opts: &'o flatbuffers::VerifierOptions,
|
||||
buf: &'b [u8],
|
||||
) -> Result<Universe<'b>, flatbuffers::InvalidFlatbuffer> {
|
||||
flatbuffers::size_prefixed_root_with_opts::<Universe<'b>>(opts, buf)
|
||||
}
|
||||
#[inline]
|
||||
/// Assumes, without verification, that a buffer of bytes contains a Universe and returns it.
|
||||
/// # Safety
|
||||
/// Callers must trust the given bytes do indeed contain a valid `Universe`.
|
||||
pub unsafe fn root_as_universe_unchecked(buf: &[u8]) -> Universe {
|
||||
flatbuffers::root_unchecked::<Universe>(buf)
|
||||
}
|
||||
#[inline]
|
||||
/// Assumes, without verification, that a buffer of bytes contains a size prefixed Universe and returns it.
|
||||
/// # Safety
|
||||
/// Callers must trust the given bytes do indeed contain a valid size prefixed `Universe`.
|
||||
pub unsafe fn size_prefixed_root_as_universe_unchecked(buf: &[u8]) -> Universe {
|
||||
flatbuffers::size_prefixed_root_unchecked::<Universe>(buf)
|
||||
}
|
||||
#[inline]
|
||||
pub fn finish_universe_buffer<'a, 'b>(
|
||||
fbb: &'b mut flatbuffers::FlatBufferBuilder<'a>,
|
||||
root: flatbuffers::WIPOffset<Universe<'a>>) {
|
||||
fbb.finish(root, None);
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn finish_size_prefixed_universe_buffer<'a, 'b>(fbb: &'b mut flatbuffers::FlatBufferBuilder<'a>, root: flatbuffers::WIPOffset<Universe<'a>>) {
|
||||
fbb.finish_size_prefixed(root, None);
|
||||
}
|
||||
10
goldens/rust/generate.py
Normal file
10
goldens/rust/generate.py
Normal file
@@ -0,0 +1,10 @@
|
||||
from golden_utils import flatc_golden
|
||||
|
||||
|
||||
def flatc(options, schema):
|
||||
# Wrap the golden flatc generator with Rust specifics
|
||||
flatc_golden(options=["--rust"] + options, schema=schema, prefix="rust")
|
||||
|
||||
|
||||
def GenerateRust():
|
||||
flatc([], "basic.fbs")
|
||||
13
goldens/schema/basic.fbs
Normal file
13
goldens/schema/basic.fbs
Normal file
@@ -0,0 +1,13 @@
|
||||
// This file should contain the basics of flatbuffers that all languages should
|
||||
// support.
|
||||
|
||||
table Galaxy {
|
||||
num_stars:long;
|
||||
}
|
||||
|
||||
table Universe {
|
||||
age:double;
|
||||
galaxies:[Galaxy];
|
||||
}
|
||||
|
||||
root_type Universe;
|
||||
84
goldens/swift/basic_generated.swift
Normal file
84
goldens/swift/basic_generated.swift
Normal file
@@ -0,0 +1,84 @@
|
||||
// automatically generated by the FlatBuffers compiler, do not modify
|
||||
// swiftlint:disable all
|
||||
// swiftformat:disable all
|
||||
|
||||
import FlatBuffers
|
||||
|
||||
public struct Galaxy: FlatBufferObject, Verifiable {
|
||||
|
||||
static func validateVersion() { FlatBuffersVersion_23_5_9() }
|
||||
public var __buffer: ByteBuffer! { return _accessor.bb }
|
||||
private var _accessor: Table
|
||||
|
||||
private init(_ t: Table) { _accessor = t }
|
||||
public init(_ bb: ByteBuffer, o: Int32) { _accessor = Table(bb: bb, position: o) }
|
||||
|
||||
private enum VTOFFSET: VOffset {
|
||||
case numStars = 4
|
||||
var v: Int32 { Int32(self.rawValue) }
|
||||
var p: VOffset { self.rawValue }
|
||||
}
|
||||
|
||||
public var numStars: Int64 { let o = _accessor.offset(VTOFFSET.numStars.v); return o == 0 ? 0 : _accessor.readBuffer(of: Int64.self, at: o) }
|
||||
public static func startGalaxy(_ fbb: inout FlatBufferBuilder) -> UOffset { fbb.startTable(with: 1) }
|
||||
public static func add(numStars: Int64, _ fbb: inout FlatBufferBuilder) { fbb.add(element: numStars, def: 0, at: VTOFFSET.numStars.p) }
|
||||
public static func endGalaxy(_ fbb: inout FlatBufferBuilder, start: UOffset) -> Offset { let end = Offset(offset: fbb.endTable(at: start)); return end }
|
||||
public static func createGalaxy(
|
||||
_ fbb: inout FlatBufferBuilder,
|
||||
numStars: Int64 = 0
|
||||
) -> Offset {
|
||||
let __start = Galaxy.startGalaxy(&fbb)
|
||||
Galaxy.add(numStars: numStars, &fbb)
|
||||
return Galaxy.endGalaxy(&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.numStars.p, fieldName: "numStars", required: false, type: Int64.self)
|
||||
_v.finish()
|
||||
}
|
||||
}
|
||||
|
||||
public struct Universe: FlatBufferObject, Verifiable {
|
||||
|
||||
static func validateVersion() { FlatBuffersVersion_23_5_9() }
|
||||
public var __buffer: ByteBuffer! { return _accessor.bb }
|
||||
private var _accessor: Table
|
||||
|
||||
private init(_ t: Table) { _accessor = t }
|
||||
public init(_ bb: ByteBuffer, o: Int32) { _accessor = Table(bb: bb, position: o) }
|
||||
|
||||
private enum VTOFFSET: VOffset {
|
||||
case age = 4
|
||||
case galaxies = 6
|
||||
var v: Int32 { Int32(self.rawValue) }
|
||||
var p: VOffset { self.rawValue }
|
||||
}
|
||||
|
||||
public var age: Double { let o = _accessor.offset(VTOFFSET.age.v); return o == 0 ? 0.0 : _accessor.readBuffer(of: Double.self, at: o) }
|
||||
public var hasGalaxies: Bool { let o = _accessor.offset(VTOFFSET.galaxies.v); return o == 0 ? false : true }
|
||||
public var galaxiesCount: Int32 { let o = _accessor.offset(VTOFFSET.galaxies.v); return o == 0 ? 0 : _accessor.vector(count: o) }
|
||||
public func galaxies(at index: Int32) -> Galaxy? { let o = _accessor.offset(VTOFFSET.galaxies.v); return o == 0 ? nil : Galaxy(_accessor.bb, o: _accessor.indirect(_accessor.vector(at: o) + index * 4)) }
|
||||
public static func startUniverse(_ fbb: inout FlatBufferBuilder) -> UOffset { fbb.startTable(with: 2) }
|
||||
public static func add(age: Double, _ fbb: inout FlatBufferBuilder) { fbb.add(element: age, def: 0.0, at: VTOFFSET.age.p) }
|
||||
public static func addVectorOf(galaxies: Offset, _ fbb: inout FlatBufferBuilder) { fbb.add(offset: galaxies, at: VTOFFSET.galaxies.p) }
|
||||
public static func endUniverse(_ fbb: inout FlatBufferBuilder, start: UOffset) -> Offset { let end = Offset(offset: fbb.endTable(at: start)); return end }
|
||||
public static func createUniverse(
|
||||
_ fbb: inout FlatBufferBuilder,
|
||||
age: Double = 0.0,
|
||||
galaxiesVectorOffset galaxies: Offset = Offset()
|
||||
) -> Offset {
|
||||
let __start = Universe.startUniverse(&fbb)
|
||||
Universe.add(age: age, &fbb)
|
||||
Universe.addVectorOf(galaxies: galaxies, &fbb)
|
||||
return Universe.endUniverse(&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.age.p, fieldName: "age", required: false, type: Double.self)
|
||||
try _v.visit(field: VTOFFSET.galaxies.p, fieldName: "galaxies", required: false, type: ForwardOffset<Vector<ForwardOffset<Galaxy>, Galaxy>>.self)
|
||||
_v.finish()
|
||||
}
|
||||
}
|
||||
|
||||
10
goldens/swift/generate.py
Normal file
10
goldens/swift/generate.py
Normal file
@@ -0,0 +1,10 @@
|
||||
from golden_utils import flatc_golden
|
||||
|
||||
|
||||
def flatc(options, schema):
|
||||
# Wrap the golden flatc generator with Swift specifics
|
||||
flatc_golden(options=["--swift"] + options, schema=schema, prefix="swift")
|
||||
|
||||
|
||||
def GenerateSwift():
|
||||
flatc([], "basic.fbs")
|
||||
4
goldens/ts/basic.ts
Normal file
4
goldens/ts/basic.ts
Normal file
@@ -0,0 +1,4 @@
|
||||
// automatically generated by the FlatBuffers compiler, do not modify
|
||||
|
||||
export { Galaxy } from './galaxy.js';
|
||||
export { Universe } from './universe.js';
|
||||
46
goldens/ts/galaxy.ts
Normal file
46
goldens/ts/galaxy.ts
Normal file
@@ -0,0 +1,46 @@
|
||||
// automatically generated by the FlatBuffers compiler, do not modify
|
||||
|
||||
import * as flatbuffers from 'flatbuffers';
|
||||
|
||||
export class Galaxy {
|
||||
bb: flatbuffers.ByteBuffer|null = null;
|
||||
bb_pos = 0;
|
||||
__init(i:number, bb:flatbuffers.ByteBuffer):Galaxy {
|
||||
this.bb_pos = i;
|
||||
this.bb = bb;
|
||||
return this;
|
||||
}
|
||||
|
||||
static getRootAsGalaxy(bb:flatbuffers.ByteBuffer, obj?:Galaxy):Galaxy {
|
||||
return (obj || new Galaxy()).__init(bb.readInt32(bb.position()) + bb.position(), bb);
|
||||
}
|
||||
|
||||
static getSizePrefixedRootAsGalaxy(bb:flatbuffers.ByteBuffer, obj?:Galaxy):Galaxy {
|
||||
bb.setPosition(bb.position() + flatbuffers.SIZE_PREFIX_LENGTH);
|
||||
return (obj || new Galaxy()).__init(bb.readInt32(bb.position()) + bb.position(), bb);
|
||||
}
|
||||
|
||||
numStars():bigint {
|
||||
const offset = this.bb!.__offset(this.bb_pos, 4);
|
||||
return offset ? this.bb!.readInt64(this.bb_pos + offset) : BigInt('0');
|
||||
}
|
||||
|
||||
static startGalaxy(builder:flatbuffers.Builder) {
|
||||
builder.startObject(1);
|
||||
}
|
||||
|
||||
static addNumStars(builder:flatbuffers.Builder, numStars:bigint) {
|
||||
builder.addFieldInt64(0, numStars, BigInt('0'));
|
||||
}
|
||||
|
||||
static endGalaxy(builder:flatbuffers.Builder):flatbuffers.Offset {
|
||||
const offset = builder.endObject();
|
||||
return offset;
|
||||
}
|
||||
|
||||
static createGalaxy(builder:flatbuffers.Builder, numStars:bigint):flatbuffers.Offset {
|
||||
Galaxy.startGalaxy(builder);
|
||||
Galaxy.addNumStars(builder, numStars);
|
||||
return Galaxy.endGalaxy(builder);
|
||||
}
|
||||
}
|
||||
10
goldens/ts/generate.py
Normal file
10
goldens/ts/generate.py
Normal file
@@ -0,0 +1,10 @@
|
||||
from golden_utils import flatc_golden
|
||||
|
||||
|
||||
def flatc(options, schema):
|
||||
# Wrap the golden flatc generator with Swift specifics
|
||||
flatc_golden(options=["--ts"] + options, schema=schema, prefix="ts")
|
||||
|
||||
|
||||
def GenerateTs():
|
||||
flatc([], "basic.fbs")
|
||||
84
goldens/ts/universe.ts
Normal file
84
goldens/ts/universe.ts
Normal file
@@ -0,0 +1,84 @@
|
||||
// automatically generated by the FlatBuffers compiler, do not modify
|
||||
|
||||
import * as flatbuffers from 'flatbuffers';
|
||||
|
||||
import { Galaxy } from './galaxy.js';
|
||||
|
||||
|
||||
export class Universe {
|
||||
bb: flatbuffers.ByteBuffer|null = null;
|
||||
bb_pos = 0;
|
||||
__init(i:number, bb:flatbuffers.ByteBuffer):Universe {
|
||||
this.bb_pos = i;
|
||||
this.bb = bb;
|
||||
return this;
|
||||
}
|
||||
|
||||
static getRootAsUniverse(bb:flatbuffers.ByteBuffer, obj?:Universe):Universe {
|
||||
return (obj || new Universe()).__init(bb.readInt32(bb.position()) + bb.position(), bb);
|
||||
}
|
||||
|
||||
static getSizePrefixedRootAsUniverse(bb:flatbuffers.ByteBuffer, obj?:Universe):Universe {
|
||||
bb.setPosition(bb.position() + flatbuffers.SIZE_PREFIX_LENGTH);
|
||||
return (obj || new Universe()).__init(bb.readInt32(bb.position()) + bb.position(), bb);
|
||||
}
|
||||
|
||||
age():number {
|
||||
const offset = this.bb!.__offset(this.bb_pos, 4);
|
||||
return offset ? this.bb!.readFloat64(this.bb_pos + offset) : 0.0;
|
||||
}
|
||||
|
||||
galaxies(index: number, obj?:Galaxy):Galaxy|null {
|
||||
const offset = this.bb!.__offset(this.bb_pos, 6);
|
||||
return offset ? (obj || new Galaxy()).__init(this.bb!.__indirect(this.bb!.__vector(this.bb_pos + offset) + index * 4), this.bb!) : null;
|
||||
}
|
||||
|
||||
galaxiesLength():number {
|
||||
const offset = this.bb!.__offset(this.bb_pos, 6);
|
||||
return offset ? this.bb!.__vector_len(this.bb_pos + offset) : 0;
|
||||
}
|
||||
|
||||
static startUniverse(builder:flatbuffers.Builder) {
|
||||
builder.startObject(2);
|
||||
}
|
||||
|
||||
static addAge(builder:flatbuffers.Builder, age:number) {
|
||||
builder.addFieldFloat64(0, age, 0.0);
|
||||
}
|
||||
|
||||
static addGalaxies(builder:flatbuffers.Builder, galaxiesOffset:flatbuffers.Offset) {
|
||||
builder.addFieldOffset(1, galaxiesOffset, 0);
|
||||
}
|
||||
|
||||
static createGalaxiesVector(builder:flatbuffers.Builder, data:flatbuffers.Offset[]):flatbuffers.Offset {
|
||||
builder.startVector(4, data.length, 4);
|
||||
for (let i = data.length - 1; i >= 0; i--) {
|
||||
builder.addOffset(data[i]!);
|
||||
}
|
||||
return builder.endVector();
|
||||
}
|
||||
|
||||
static startGalaxiesVector(builder:flatbuffers.Builder, numElems:number) {
|
||||
builder.startVector(4, numElems, 4);
|
||||
}
|
||||
|
||||
static endUniverse(builder:flatbuffers.Builder):flatbuffers.Offset {
|
||||
const offset = builder.endObject();
|
||||
return offset;
|
||||
}
|
||||
|
||||
static finishUniverseBuffer(builder:flatbuffers.Builder, offset:flatbuffers.Offset) {
|
||||
builder.finish(offset);
|
||||
}
|
||||
|
||||
static finishSizePrefixedUniverseBuffer(builder:flatbuffers.Builder, offset:flatbuffers.Offset) {
|
||||
builder.finish(offset, undefined, true);
|
||||
}
|
||||
|
||||
static createUniverse(builder:flatbuffers.Builder, age:number, galaxiesOffset:flatbuffers.Offset):flatbuffers.Offset {
|
||||
Universe.startUniverse(builder);
|
||||
Universe.addAge(builder, age);
|
||||
Universe.addGalaxies(builder, galaxiesOffset);
|
||||
return Universe.endUniverse(builder);
|
||||
}
|
||||
}
|
||||
@@ -17,6 +17,10 @@ func GetRootAsHelloReply(buf []byte, offset flatbuffers.UOffsetT) *HelloReply {
|
||||
return x
|
||||
}
|
||||
|
||||
func FinishHelloReplyBuffer(builder *flatbuffers.Builder, offset flatbuffers.UOffsetT) {
|
||||
builder.Finish(offset)
|
||||
}
|
||||
|
||||
func GetSizePrefixedRootAsHelloReply(buf []byte, offset flatbuffers.UOffsetT) *HelloReply {
|
||||
n := flatbuffers.GetUOffsetT(buf[offset+flatbuffers.SizeUint32:])
|
||||
x := &HelloReply{}
|
||||
@@ -24,6 +28,10 @@ func GetSizePrefixedRootAsHelloReply(buf []byte, offset flatbuffers.UOffsetT) *H
|
||||
return x
|
||||
}
|
||||
|
||||
func FinishSizePrefixedHelloReplyBuffer(builder *flatbuffers.Builder, offset flatbuffers.UOffsetT) {
|
||||
builder.FinishSizePrefixed(offset)
|
||||
}
|
||||
|
||||
func (rcv *HelloReply) Init(buf []byte, i flatbuffers.UOffsetT) {
|
||||
rcv._tab.Bytes = buf
|
||||
rcv._tab.Pos = i
|
||||
|
||||
@@ -17,6 +17,10 @@ func GetRootAsHelloRequest(buf []byte, offset flatbuffers.UOffsetT) *HelloReques
|
||||
return x
|
||||
}
|
||||
|
||||
func FinishHelloRequestBuffer(builder *flatbuffers.Builder, offset flatbuffers.UOffsetT) {
|
||||
builder.Finish(offset)
|
||||
}
|
||||
|
||||
func GetSizePrefixedRootAsHelloRequest(buf []byte, offset flatbuffers.UOffsetT) *HelloRequest {
|
||||
n := flatbuffers.GetUOffsetT(buf[offset+flatbuffers.SizeUint32:])
|
||||
x := &HelloRequest{}
|
||||
@@ -24,6 +28,10 @@ func GetSizePrefixedRootAsHelloRequest(buf []byte, offset flatbuffers.UOffsetT)
|
||||
return x
|
||||
}
|
||||
|
||||
func FinishSizePrefixedHelloRequestBuffer(builder *flatbuffers.Builder, offset flatbuffers.UOffsetT) {
|
||||
builder.FinishSizePrefixed(offset)
|
||||
}
|
||||
|
||||
func (rcv *HelloRequest) Init(buf []byte, i flatbuffers.UOffsetT) {
|
||||
rcv._tab.Bytes = buf
|
||||
rcv._tab.Pos = i
|
||||
|
||||
@@ -31,12 +31,20 @@ class HelloReply(object):
|
||||
return self._tab.String(o + self._tab.Pos)
|
||||
return None
|
||||
|
||||
def HelloReplyStart(builder): builder.StartObject(1)
|
||||
def HelloReplyStart(builder):
|
||||
builder.StartObject(1)
|
||||
|
||||
def Start(builder):
|
||||
return HelloReplyStart(builder)
|
||||
def HelloReplyAddMessage(builder, message): builder.PrependUOffsetTRelativeSlot(0, flatbuffers.number_types.UOffsetTFlags.py_type(message), 0)
|
||||
def AddMessage(builder, message):
|
||||
return HelloReplyAddMessage(builder, message)
|
||||
def HelloReplyEnd(builder): return builder.EndObject()
|
||||
HelloReplyStart(builder)
|
||||
|
||||
def HelloReplyAddMessage(builder, message):
|
||||
builder.PrependUOffsetTRelativeSlot(0, flatbuffers.number_types.UOffsetTFlags.py_type(message), 0)
|
||||
|
||||
def AddMessage(builder: flatbuffers.Builder, message: int):
|
||||
HelloReplyAddMessage(builder, message)
|
||||
|
||||
def HelloReplyEnd(builder):
|
||||
return builder.EndObject()
|
||||
|
||||
def End(builder):
|
||||
return HelloReplyEnd(builder)
|
||||
return HelloReplyEnd(builder)
|
||||
|
||||
@@ -31,12 +31,20 @@ class HelloRequest(object):
|
||||
return self._tab.String(o + self._tab.Pos)
|
||||
return None
|
||||
|
||||
def HelloRequestStart(builder): builder.StartObject(1)
|
||||
def HelloRequestStart(builder):
|
||||
builder.StartObject(1)
|
||||
|
||||
def Start(builder):
|
||||
return HelloRequestStart(builder)
|
||||
def HelloRequestAddName(builder, name): builder.PrependUOffsetTRelativeSlot(0, flatbuffers.number_types.UOffsetTFlags.py_type(name), 0)
|
||||
def AddName(builder, name):
|
||||
return HelloRequestAddName(builder, name)
|
||||
def HelloRequestEnd(builder): return builder.EndObject()
|
||||
HelloRequestStart(builder)
|
||||
|
||||
def HelloRequestAddName(builder, name):
|
||||
builder.PrependUOffsetTRelativeSlot(0, flatbuffers.number_types.UOffsetTFlags.py_type(name), 0)
|
||||
|
||||
def AddName(builder: flatbuffers.Builder, name: int):
|
||||
HelloRequestAddName(builder, name)
|
||||
|
||||
def HelloRequestEnd(builder):
|
||||
return builder.EndObject()
|
||||
|
||||
def End(builder):
|
||||
return HelloRequestEnd(builder)
|
||||
return HelloRequestEnd(builder)
|
||||
|
||||
@@ -6,7 +6,7 @@ import FlatBuffers
|
||||
|
||||
public struct models_HelloReply: FlatBufferObject, Verifiable {
|
||||
|
||||
static func validateVersion() { FlatBuffersVersion_23_3_3() }
|
||||
static func validateVersion() { FlatBuffersVersion_23_5_9() }
|
||||
public var __buffer: ByteBuffer! { return _accessor.bb }
|
||||
private var _accessor: Table
|
||||
|
||||
@@ -53,7 +53,7 @@ extension models_HelloReply: Encodable {
|
||||
|
||||
public struct models_HelloRequest: FlatBufferObject, Verifiable {
|
||||
|
||||
static func validateVersion() { FlatBuffersVersion_23_3_3() }
|
||||
static func validateVersion() { FlatBuffersVersion_23_5_9() }
|
||||
public var __buffer: ByteBuffer! { return _accessor.bb }
|
||||
private var _accessor: Table
|
||||
|
||||
|
||||
@@ -4,6 +4,16 @@ package(
|
||||
default_visibility = ["//visibility:public"],
|
||||
)
|
||||
|
||||
filegroup(
|
||||
name = "distribution",
|
||||
srcs = [
|
||||
"BUILD.bazel",
|
||||
] + glob([
|
||||
"*.cc",
|
||||
"*.h",
|
||||
]),
|
||||
)
|
||||
|
||||
filegroup(
|
||||
name = "common_headers",
|
||||
srcs = [
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
#ifndef FLATBUFFERS_ARRAY_H_
|
||||
#define FLATBUFFERS_ARRAY_H_
|
||||
|
||||
#include <cstdint>
|
||||
#include <memory>
|
||||
|
||||
#include "flatbuffers/base.h"
|
||||
@@ -37,7 +38,7 @@ template<typename T, uint16_t length> class Array {
|
||||
public:
|
||||
typedef uint16_t size_type;
|
||||
typedef typename IndirectHelper<IndirectHelperType>::return_type return_type;
|
||||
typedef VectorConstIterator<T, return_type> const_iterator;
|
||||
typedef VectorConstIterator<T, return_type, uoffset_t> const_iterator;
|
||||
typedef VectorReverseIterator<const_iterator> const_reverse_iterator;
|
||||
|
||||
// If T is a LE-scalar or a struct (!scalar_tag::value).
|
||||
@@ -158,11 +159,13 @@ template<typename T, uint16_t length> class Array {
|
||||
|
||||
// Specialization for Array[struct] with access using Offset<void> pointer.
|
||||
// This specialization used by idl_gen_text.cpp.
|
||||
template<typename T, uint16_t length> class Array<Offset<T>, length> {
|
||||
template<typename T, uint16_t length, template<typename> class OffsetT>
|
||||
class Array<OffsetT<T>, length> {
|
||||
static_assert(flatbuffers::is_same<T, void>::value, "unexpected type T");
|
||||
|
||||
public:
|
||||
typedef const void *return_type;
|
||||
typedef uint16_t size_type;
|
||||
|
||||
const uint8_t *Data() const { return data_; }
|
||||
|
||||
|
||||
@@ -43,6 +43,7 @@
|
||||
#include <vector>
|
||||
#include <set>
|
||||
#include <algorithm>
|
||||
#include <limits>
|
||||
#include <iterator>
|
||||
#include <memory>
|
||||
|
||||
@@ -139,8 +140,8 @@
|
||||
#endif // !defined(FLATBUFFERS_LITTLEENDIAN)
|
||||
|
||||
#define FLATBUFFERS_VERSION_MAJOR 23
|
||||
#define FLATBUFFERS_VERSION_MINOR 3
|
||||
#define FLATBUFFERS_VERSION_REVISION 3
|
||||
#define FLATBUFFERS_VERSION_MINOR 5
|
||||
#define FLATBUFFERS_VERSION_REVISION 9
|
||||
#define FLATBUFFERS_STRING_EXPAND(X) #X
|
||||
#define FLATBUFFERS_STRING(X) FLATBUFFERS_STRING_EXPAND(X)
|
||||
namespace flatbuffers {
|
||||
@@ -233,12 +234,17 @@ namespace flatbuffers {
|
||||
}
|
||||
#define FLATBUFFERS_HAS_STRING_VIEW 1
|
||||
// Check for absl::string_view
|
||||
#elif __has_include("absl/strings/string_view.h") && (__cplusplus >= 201411)
|
||||
#include "absl/strings/string_view.h"
|
||||
namespace flatbuffers {
|
||||
typedef absl::string_view string_view;
|
||||
}
|
||||
#define FLATBUFFERS_HAS_STRING_VIEW 1
|
||||
#elif __has_include("absl/strings/string_view.h") && \
|
||||
__has_include("absl/base/config.h") && \
|
||||
(__cplusplus >= 201411)
|
||||
#include "absl/base/config.h"
|
||||
#if !defined(ABSL_USES_STD_STRING_VIEW)
|
||||
#include "absl/strings/string_view.h"
|
||||
namespace flatbuffers {
|
||||
typedef absl::string_view string_view;
|
||||
}
|
||||
#define FLATBUFFERS_HAS_STRING_VIEW 1
|
||||
#endif
|
||||
#endif
|
||||
#endif // __has_include
|
||||
#endif // !FLATBUFFERS_HAS_STRING_VIEW
|
||||
@@ -318,9 +324,11 @@ namespace flatbuffers {
|
||||
// Also, using a consistent offset type maintains compatibility of serialized
|
||||
// offset values between 32bit and 64bit systems.
|
||||
typedef uint32_t uoffset_t;
|
||||
typedef uint64_t uoffset64_t;
|
||||
|
||||
// Signed offsets for references that can go in both directions.
|
||||
typedef int32_t soffset_t;
|
||||
typedef int64_t soffset64_t;
|
||||
|
||||
// Offset/index used in v-tables, can be changed to uint8_t in
|
||||
// format forks to save a bit of space if desired.
|
||||
@@ -329,7 +337,8 @@ typedef uint16_t voffset_t;
|
||||
typedef uintmax_t largest_scalar_t;
|
||||
|
||||
// In 32bits, this evaluates to 2GB - 1
|
||||
#define FLATBUFFERS_MAX_BUFFER_SIZE ((1ULL << (sizeof(::flatbuffers::soffset_t) * 8 - 1)) - 1)
|
||||
#define FLATBUFFERS_MAX_BUFFER_SIZE std::numeric_limits<::flatbuffers::soffset_t>::max()
|
||||
#define FLATBUFFERS_MAX_64_BUFFER_SIZE std::numeric_limits<::flatbuffers::soffset64_t>::max()
|
||||
|
||||
// The minimum size buffer that can be a valid flatbuffer.
|
||||
// Includes the offset to the root table (uoffset_t), the offset to the vtable
|
||||
|
||||
@@ -25,14 +25,33 @@ namespace flatbuffers {
|
||||
|
||||
// Wrapper for uoffset_t to allow safe template specialization.
|
||||
// Value is allowed to be 0 to indicate a null object (see e.g. AddOffset).
|
||||
template<typename T> struct Offset {
|
||||
uoffset_t o;
|
||||
template<typename T = void> struct Offset {
|
||||
// The type of offset to use.
|
||||
typedef uoffset_t offset_type;
|
||||
|
||||
offset_type o;
|
||||
Offset() : o(0) {}
|
||||
Offset(uoffset_t _o) : o(_o) {}
|
||||
Offset<void> Union() const { return Offset<void>(o); }
|
||||
Offset(const offset_type _o) : o(_o) {}
|
||||
Offset<> Union() const { return o; }
|
||||
bool IsNull() const { return !o; }
|
||||
};
|
||||
|
||||
// Wrapper for uoffset64_t Offsets.
|
||||
template<typename T = void> struct Offset64 {
|
||||
// The type of offset to use.
|
||||
typedef uoffset64_t offset_type;
|
||||
|
||||
offset_type o;
|
||||
Offset64() : o(0) {}
|
||||
Offset64(const offset_type offset) : o(offset) {}
|
||||
Offset64<> Union() const { return o; }
|
||||
bool IsNull() const { return !o; }
|
||||
};
|
||||
|
||||
// Litmus check for ensuring the Offsets are the expected size.
|
||||
static_assert(sizeof(Offset<>) == 4, "Offset has wrong size");
|
||||
static_assert(sizeof(Offset64<>) == 8, "Offset64 has wrong size");
|
||||
|
||||
inline void EndianCheck() {
|
||||
int endiantest = 1;
|
||||
// If this fails, see FLATBUFFERS_LITTLEENDIAN above.
|
||||
@@ -75,35 +94,59 @@ template<typename T> struct IndirectHelper {
|
||||
typedef T return_type;
|
||||
typedef T mutable_return_type;
|
||||
static const size_t element_stride = sizeof(T);
|
||||
static return_type Read(const uint8_t *p, uoffset_t i) {
|
||||
|
||||
static return_type Read(const uint8_t *p, const size_t i) {
|
||||
return EndianScalar((reinterpret_cast<const T *>(p))[i]);
|
||||
}
|
||||
static return_type Read(uint8_t *p, uoffset_t i) {
|
||||
return Read(const_cast<const uint8_t *>(p), i);
|
||||
static mutable_return_type Read(uint8_t *p, const size_t i) {
|
||||
return reinterpret_cast<mutable_return_type>(
|
||||
Read(const_cast<const uint8_t *>(p), i));
|
||||
}
|
||||
};
|
||||
template<typename T> struct IndirectHelper<Offset<T>> {
|
||||
|
||||
// For vector of Offsets.
|
||||
template<typename T, template<typename> class OffsetT>
|
||||
struct IndirectHelper<OffsetT<T>> {
|
||||
typedef const T *return_type;
|
||||
typedef T *mutable_return_type;
|
||||
static const size_t element_stride = sizeof(uoffset_t);
|
||||
static return_type Read(const uint8_t *p, uoffset_t i) {
|
||||
p += i * sizeof(uoffset_t);
|
||||
return reinterpret_cast<return_type>(p + ReadScalar<uoffset_t>(p));
|
||||
typedef typename OffsetT<T>::offset_type offset_type;
|
||||
static const offset_type element_stride = sizeof(offset_type);
|
||||
|
||||
static return_type Read(const uint8_t *const p, const offset_type i) {
|
||||
// Offsets are relative to themselves, so first update the pointer to
|
||||
// point to the offset location.
|
||||
const uint8_t *const offset_location = p + i * element_stride;
|
||||
|
||||
// Then read the scalar value of the offset (which may be 32 or 64-bits) and
|
||||
// then determine the relative location from the offset location.
|
||||
return reinterpret_cast<return_type>(
|
||||
offset_location + ReadScalar<offset_type>(offset_location));
|
||||
}
|
||||
static mutable_return_type Read(uint8_t *p, uoffset_t i) {
|
||||
p += i * sizeof(uoffset_t);
|
||||
return reinterpret_cast<mutable_return_type>(p + ReadScalar<uoffset_t>(p));
|
||||
static mutable_return_type Read(uint8_t *const p, const offset_type i) {
|
||||
// Offsets are relative to themselves, so first update the pointer to
|
||||
// point to the offset location.
|
||||
uint8_t *const offset_location = p + i * element_stride;
|
||||
|
||||
// Then read the scalar value of the offset (which may be 32 or 64-bits) and
|
||||
// then determine the relative location from the offset location.
|
||||
return reinterpret_cast<mutable_return_type>(
|
||||
offset_location + ReadScalar<offset_type>(offset_location));
|
||||
}
|
||||
};
|
||||
|
||||
// For vector of structs.
|
||||
template<typename T> struct IndirectHelper<const T *> {
|
||||
typedef const T *return_type;
|
||||
typedef T *mutable_return_type;
|
||||
static const size_t element_stride = sizeof(T);
|
||||
static return_type Read(const uint8_t *p, uoffset_t i) {
|
||||
return reinterpret_cast<return_type>(p + i * sizeof(T));
|
||||
|
||||
static return_type Read(const uint8_t *const p, const size_t i) {
|
||||
// Structs are stored inline, relative to the first struct pointer.
|
||||
return reinterpret_cast<return_type>(p + i * element_stride);
|
||||
}
|
||||
static mutable_return_type Read(uint8_t *p, uoffset_t i) {
|
||||
return reinterpret_cast<mutable_return_type>(p + i * sizeof(T));
|
||||
static mutable_return_type Read(uint8_t *const p, const size_t i) {
|
||||
// Structs are stored inline, relative to the first struct pointer.
|
||||
return reinterpret_cast<mutable_return_type>(p + i * element_stride);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -130,23 +173,25 @@ inline bool BufferHasIdentifier(const void *buf, const char *identifier,
|
||||
/// @cond FLATBUFFERS_INTERNAL
|
||||
// Helpers to get a typed pointer to the root object contained in the buffer.
|
||||
template<typename T> T *GetMutableRoot(void *buf) {
|
||||
if (!buf) return nullptr;
|
||||
EndianCheck();
|
||||
return reinterpret_cast<T *>(
|
||||
reinterpret_cast<uint8_t *>(buf) +
|
||||
EndianScalar(*reinterpret_cast<uoffset_t *>(buf)));
|
||||
}
|
||||
|
||||
template<typename T> T *GetMutableSizePrefixedRoot(void *buf) {
|
||||
return GetMutableRoot<T>(reinterpret_cast<uint8_t *>(buf) +
|
||||
sizeof(uoffset_t));
|
||||
template<typename T, typename SizeT = uoffset_t>
|
||||
T *GetMutableSizePrefixedRoot(void *buf) {
|
||||
return GetMutableRoot<T>(reinterpret_cast<uint8_t *>(buf) + sizeof(SizeT));
|
||||
}
|
||||
|
||||
template<typename T> const T *GetRoot(const void *buf) {
|
||||
return GetMutableRoot<T>(const_cast<void *>(buf));
|
||||
}
|
||||
|
||||
template<typename T> const T *GetSizePrefixedRoot(const void *buf) {
|
||||
return GetRoot<T>(reinterpret_cast<const uint8_t *>(buf) + sizeof(uoffset_t));
|
||||
template<typename T, typename SizeT = uoffset_t>
|
||||
const T *GetSizePrefixedRoot(const void *buf) {
|
||||
return GetRoot<T>(reinterpret_cast<const uint8_t *>(buf) + sizeof(SizeT));
|
||||
}
|
||||
|
||||
} // namespace flatbuffers
|
||||
|
||||
@@ -36,6 +36,8 @@ class CodeGenerator {
|
||||
NOT_IMPLEMENTED = 3
|
||||
};
|
||||
|
||||
std::string status_detail;
|
||||
|
||||
// Generate code from the provided `parser`.
|
||||
//
|
||||
// DEPRECATED: prefer using the other overload of GenerateCode for bfbs.
|
||||
|
||||
48
include/flatbuffers/file_manager.h
Normal file
48
include/flatbuffers/file_manager.h
Normal file
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
* 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_FILE_MANAGER_H_
|
||||
#define FLATBUFFERS_FILE_MANAGER_H_
|
||||
|
||||
#include <set>
|
||||
#include <string>
|
||||
|
||||
#include "flatbuffers/util.h"
|
||||
|
||||
namespace flatbuffers {
|
||||
|
||||
// A File interface to write data to file by default or
|
||||
// save only file names
|
||||
class FileManager {
|
||||
public:
|
||||
FileManager() = default;
|
||||
virtual ~FileManager() = default;
|
||||
|
||||
virtual bool SaveFile(const std::string &absolute_file_name,
|
||||
const std::string &content) = 0;
|
||||
|
||||
virtual bool LoadFile(const std::string &absolute_file_name,
|
||||
std::string *buf) = 0;
|
||||
|
||||
private:
|
||||
// Copying is not supported.
|
||||
FileManager(const FileManager &) = delete;
|
||||
FileManager &operator=(const FileManager &) = delete;
|
||||
};
|
||||
|
||||
} // namespace flatbuffers
|
||||
|
||||
#endif // FLATBUFFERS_FILE_MANAGER_H_
|
||||
@@ -18,12 +18,15 @@
|
||||
#define FLATBUFFERS_FLATBUFFER_BUILDER_H_
|
||||
|
||||
#include <algorithm>
|
||||
#include <cstdint>
|
||||
#include <functional>
|
||||
#include <initializer_list>
|
||||
#include <type_traits>
|
||||
|
||||
#include "flatbuffers/allocator.h"
|
||||
#include "flatbuffers/array.h"
|
||||
#include "flatbuffers/base.h"
|
||||
#include "flatbuffers/buffer.h"
|
||||
#include "flatbuffers/buffer_ref.h"
|
||||
#include "flatbuffers/default_allocator.h"
|
||||
#include "flatbuffers/detached_buffer.h"
|
||||
@@ -40,8 +43,9 @@ namespace flatbuffers {
|
||||
// Converts a Field ID to a virtual table offset.
|
||||
inline voffset_t FieldIndexToOffset(voffset_t field_id) {
|
||||
// Should correspond to what EndTable() below builds up.
|
||||
const int fixed_fields = 2; // Vtable size and Object Size.
|
||||
return static_cast<voffset_t>((field_id + fixed_fields) * sizeof(voffset_t));
|
||||
const voffset_t fixed_fields =
|
||||
2 * sizeof(voffset_t); // Vtable size and Object Size.
|
||||
return fixed_fields + field_id * sizeof(voffset_t);
|
||||
}
|
||||
|
||||
template<typename T, typename Alloc = std::allocator<T>>
|
||||
@@ -68,8 +72,13 @@ T *data(std::vector<T, Alloc> &v) {
|
||||
/// `PushElement`/`AddElement`/`EndTable`, or the builtin `CreateString`/
|
||||
/// `CreateVector` functions. Do this is depth-first order to build up a tree to
|
||||
/// the root. `Finish()` wraps up the buffer ready for transport.
|
||||
class FlatBufferBuilder {
|
||||
template<bool Is64Aware = false> class FlatBufferBuilderImpl {
|
||||
public:
|
||||
// This switches the size type of the builder, based on if its 64-bit aware
|
||||
// (uoffset64_t) or not (uoffset_t).
|
||||
typedef
|
||||
typename std::conditional<Is64Aware, uoffset64_t, uoffset_t>::type SizeT;
|
||||
|
||||
/// @brief Default constructor for FlatBufferBuilder.
|
||||
/// @param[in] initial_size The initial size of the buffer, in bytes. Defaults
|
||||
/// to `1024`.
|
||||
@@ -81,13 +90,16 @@ class FlatBufferBuilder {
|
||||
/// minimum alignment upon reallocation. Only needed if you intend to store
|
||||
/// types with custom alignment AND you wish to read the buffer in-place
|
||||
/// directly after creation.
|
||||
explicit FlatBufferBuilder(
|
||||
explicit FlatBufferBuilderImpl(
|
||||
size_t initial_size = 1024, Allocator *allocator = nullptr,
|
||||
bool own_allocator = false,
|
||||
size_t buffer_minalign = AlignOf<largest_scalar_t>())
|
||||
: buf_(initial_size, allocator, own_allocator, buffer_minalign),
|
||||
: buf_(initial_size, allocator, own_allocator, buffer_minalign,
|
||||
static_cast<SizeT>(Is64Aware ? FLATBUFFERS_MAX_64_BUFFER_SIZE
|
||||
: FLATBUFFERS_MAX_BUFFER_SIZE)),
|
||||
num_field_loc(0),
|
||||
max_voffset_(0),
|
||||
length_of_64_bit_region_(0),
|
||||
nested(false),
|
||||
finished(false),
|
||||
minalign_(1),
|
||||
@@ -98,10 +110,13 @@ class FlatBufferBuilder {
|
||||
}
|
||||
|
||||
/// @brief Move constructor for FlatBufferBuilder.
|
||||
FlatBufferBuilder(FlatBufferBuilder &&other) noexcept
|
||||
: buf_(1024, nullptr, false, AlignOf<largest_scalar_t>()),
|
||||
FlatBufferBuilderImpl(FlatBufferBuilderImpl &&other) noexcept
|
||||
: buf_(1024, nullptr, false, AlignOf<largest_scalar_t>(),
|
||||
static_cast<SizeT>(Is64Aware ? FLATBUFFERS_MAX_64_BUFFER_SIZE
|
||||
: FLATBUFFERS_MAX_BUFFER_SIZE)),
|
||||
num_field_loc(0),
|
||||
max_voffset_(0),
|
||||
length_of_64_bit_region_(0),
|
||||
nested(false),
|
||||
finished(false),
|
||||
minalign_(1),
|
||||
@@ -116,18 +131,19 @@ class FlatBufferBuilder {
|
||||
}
|
||||
|
||||
/// @brief Move assignment operator for FlatBufferBuilder.
|
||||
FlatBufferBuilder &operator=(FlatBufferBuilder &&other) noexcept {
|
||||
FlatBufferBuilderImpl &operator=(FlatBufferBuilderImpl &&other) noexcept {
|
||||
// Move construct a temporary and swap idiom
|
||||
FlatBufferBuilder temp(std::move(other));
|
||||
FlatBufferBuilderImpl temp(std::move(other));
|
||||
Swap(temp);
|
||||
return *this;
|
||||
}
|
||||
|
||||
void Swap(FlatBufferBuilder &other) {
|
||||
void Swap(FlatBufferBuilderImpl &other) {
|
||||
using std::swap;
|
||||
buf_.swap(other.buf_);
|
||||
swap(num_field_loc, other.num_field_loc);
|
||||
swap(max_voffset_, other.max_voffset_);
|
||||
swap(length_of_64_bit_region_, other.length_of_64_bit_region_);
|
||||
swap(nested, other.nested);
|
||||
swap(finished, other.finished);
|
||||
swap(minalign_, other.minalign_);
|
||||
@@ -136,7 +152,7 @@ class FlatBufferBuilder {
|
||||
swap(string_pool, other.string_pool);
|
||||
}
|
||||
|
||||
~FlatBufferBuilder() {
|
||||
~FlatBufferBuilderImpl() {
|
||||
if (string_pool) delete string_pool;
|
||||
}
|
||||
|
||||
@@ -153,12 +169,36 @@ class FlatBufferBuilder {
|
||||
nested = false;
|
||||
finished = false;
|
||||
minalign_ = 1;
|
||||
length_of_64_bit_region_ = 0;
|
||||
if (string_pool) string_pool->clear();
|
||||
}
|
||||
|
||||
/// @brief The current size of the serialized buffer, counting from the end.
|
||||
/// @return Returns an `SizeT` with the current size of the buffer.
|
||||
SizeT GetSize() const { return buf_.size(); }
|
||||
|
||||
/// @brief The current size of the serialized buffer relative to the end of
|
||||
/// the 32-bit region.
|
||||
/// @return Returns an `uoffset_t` with the current size of the buffer.
|
||||
uoffset_t GetSize() const { return buf_.size(); }
|
||||
template<bool is_64 = Is64Aware>
|
||||
// Only enable this method for the 64-bit builder, as only that builder is
|
||||
// concerned with the 32/64-bit boundary, and should be the one to bare any
|
||||
// run time costs.
|
||||
typename std::enable_if<is_64, uoffset_t>::type GetSizeRelative32BitRegion()
|
||||
const {
|
||||
//[32-bit region][64-bit region]
|
||||
// [XXXXXXXXXXXXXXXXXXX] GetSize()
|
||||
// [YYYYYYYYYYYYY] length_of_64_bit_region_
|
||||
// [ZZZZ] return size
|
||||
return static_cast<uoffset_t>(GetSize() - length_of_64_bit_region_);
|
||||
}
|
||||
|
||||
template<bool is_64 = Is64Aware>
|
||||
// Only enable this method for the 32-bit builder.
|
||||
typename std::enable_if<!is_64, uoffset_t>::type GetSizeRelative32BitRegion()
|
||||
const {
|
||||
return static_cast<uoffset_t>(GetSize());
|
||||
}
|
||||
|
||||
/// @brief Get the serialized buffer (after you call `Finish()`).
|
||||
/// @return Returns an `uint8_t` pointer to the FlatBuffer data inside the
|
||||
@@ -270,14 +310,16 @@ class FlatBufferBuilder {
|
||||
}
|
||||
|
||||
// Write a single aligned scalar to the buffer
|
||||
template<typename T> uoffset_t PushElement(T element) {
|
||||
template<typename T, typename ReturnT = uoffset_t>
|
||||
ReturnT PushElement(T element) {
|
||||
AssertScalarT<T>();
|
||||
Align(sizeof(T));
|
||||
buf_.push_small(EndianScalar(element));
|
||||
return GetSize();
|
||||
return CalculateOffset<ReturnT>();
|
||||
}
|
||||
|
||||
template<typename T> uoffset_t PushElement(Offset<T> off) {
|
||||
template<typename T, template<typename> class OffsetT = Offset>
|
||||
uoffset_t PushElement(OffsetT<T> off) {
|
||||
// Special case for offsets: see ReferTo below.
|
||||
return PushElement(ReferTo(off.o));
|
||||
}
|
||||
@@ -307,11 +349,16 @@ class FlatBufferBuilder {
|
||||
AddElement(field, ReferTo(off.o), static_cast<uoffset_t>(0));
|
||||
}
|
||||
|
||||
template<typename T> void AddOffset(voffset_t field, Offset64<T> off) {
|
||||
if (off.IsNull()) return; // Don't store.
|
||||
AddElement(field, ReferTo(off.o), static_cast<uoffset64_t>(0));
|
||||
}
|
||||
|
||||
template<typename T> void AddStruct(voffset_t field, const T *structptr) {
|
||||
if (!structptr) return; // Default, don't store.
|
||||
Align(AlignOf<T>());
|
||||
buf_.push_small(*structptr);
|
||||
TrackField(field, GetSize());
|
||||
TrackField(field, CalculateOffset<uoffset_t>());
|
||||
}
|
||||
|
||||
void AddStructOffset(voffset_t field, uoffset_t off) {
|
||||
@@ -322,12 +369,29 @@ class FlatBufferBuilder {
|
||||
// This function converts them to be relative to the current location
|
||||
// in the buffer (when stored here), pointing upwards.
|
||||
uoffset_t ReferTo(uoffset_t off) {
|
||||
// Align to ensure GetSize() below is correct.
|
||||
// Align to ensure GetSizeRelative32BitRegion() below is correct.
|
||||
Align(sizeof(uoffset_t));
|
||||
// Offset must refer to something already in buffer.
|
||||
const uoffset_t size = GetSize();
|
||||
// 32-bit offsets are relative to the tail of the 32-bit region of the
|
||||
// buffer. For most cases (without 64-bit entities) this is equivalent to
|
||||
// size of the whole buffer (e.g. GetSize())
|
||||
return ReferTo(off, GetSizeRelative32BitRegion());
|
||||
}
|
||||
|
||||
uoffset64_t ReferTo(uoffset64_t off) {
|
||||
// Align to ensure GetSize() below is correct.
|
||||
Align(sizeof(uoffset64_t));
|
||||
// 64-bit offsets are relative to tail of the whole buffer
|
||||
return ReferTo(off, GetSize());
|
||||
}
|
||||
|
||||
template<typename T, typename T2> T ReferTo(const T off, const T2 size) {
|
||||
FLATBUFFERS_ASSERT(off && off <= size);
|
||||
return size - off + static_cast<uoffset_t>(sizeof(uoffset_t));
|
||||
return size - off + static_cast<T>(sizeof(T));
|
||||
}
|
||||
|
||||
template<typename T> T ReferTo(const T off, const T size) {
|
||||
FLATBUFFERS_ASSERT(off && off <= size);
|
||||
return size - off + static_cast<T>(sizeof(T));
|
||||
}
|
||||
|
||||
void NotNested() {
|
||||
@@ -349,7 +413,7 @@ class FlatBufferBuilder {
|
||||
uoffset_t StartTable() {
|
||||
NotNested();
|
||||
nested = true;
|
||||
return GetSize();
|
||||
return GetSizeRelative32BitRegion();
|
||||
}
|
||||
|
||||
// This finishes one serialized object by generating the vtable if it's a
|
||||
@@ -360,7 +424,9 @@ class FlatBufferBuilder {
|
||||
FLATBUFFERS_ASSERT(nested);
|
||||
// Write the vtable offset, which is the start of any Table.
|
||||
// We fill its value later.
|
||||
auto vtableoffsetloc = PushElement<soffset_t>(0);
|
||||
// This is relative to the end of the 32-bit region.
|
||||
const uoffset_t vtable_offset_loc =
|
||||
static_cast<uoffset_t>(PushElement<soffset_t>(0));
|
||||
// Write a vtable, which consists entirely of voffset_t elements.
|
||||
// It starts with the number of offsets, followed by a type id, followed
|
||||
// by the offsets themselves. In reverse:
|
||||
@@ -370,7 +436,7 @@ class FlatBufferBuilder {
|
||||
(std::max)(static_cast<voffset_t>(max_voffset_ + sizeof(voffset_t)),
|
||||
FieldIndexToOffset(0));
|
||||
buf_.fill_big(max_voffset_);
|
||||
auto table_object_size = vtableoffsetloc - start;
|
||||
const uoffset_t table_object_size = vtable_offset_loc - start;
|
||||
// Vtable use 16bit offsets.
|
||||
FLATBUFFERS_ASSERT(table_object_size < 0x10000);
|
||||
WriteScalar<voffset_t>(buf_.data() + sizeof(voffset_t),
|
||||
@@ -380,7 +446,8 @@ class FlatBufferBuilder {
|
||||
for (auto it = buf_.scratch_end() - num_field_loc * sizeof(FieldLoc);
|
||||
it < buf_.scratch_end(); it += sizeof(FieldLoc)) {
|
||||
auto field_location = reinterpret_cast<FieldLoc *>(it);
|
||||
auto pos = static_cast<voffset_t>(vtableoffsetloc - field_location->off);
|
||||
const voffset_t pos =
|
||||
static_cast<voffset_t>(vtable_offset_loc - field_location->off);
|
||||
// If this asserts, it means you've set a field twice.
|
||||
FLATBUFFERS_ASSERT(
|
||||
!ReadScalar<voffset_t>(buf_.data() + field_location->id));
|
||||
@@ -389,7 +456,7 @@ class FlatBufferBuilder {
|
||||
ClearOffsets();
|
||||
auto vt1 = reinterpret_cast<voffset_t *>(buf_.data());
|
||||
auto vt1_size = ReadScalar<voffset_t>(vt1);
|
||||
auto vt_use = GetSize();
|
||||
auto vt_use = GetSizeRelative32BitRegion();
|
||||
// See if we already have generated a vtable with this exact same
|
||||
// layout before. If so, make it point to the old one, remove this one.
|
||||
if (dedup_vtables_) {
|
||||
@@ -400,23 +467,24 @@ class FlatBufferBuilder {
|
||||
auto vt2_size = ReadScalar<voffset_t>(vt2);
|
||||
if (vt1_size != vt2_size || 0 != memcmp(vt2, vt1, vt1_size)) continue;
|
||||
vt_use = *vt_offset_ptr;
|
||||
buf_.pop(GetSize() - vtableoffsetloc);
|
||||
buf_.pop(GetSizeRelative32BitRegion() - vtable_offset_loc);
|
||||
break;
|
||||
}
|
||||
}
|
||||
// If this is a new vtable, remember it.
|
||||
if (vt_use == GetSize()) { buf_.scratch_push_small(vt_use); }
|
||||
if (vt_use == GetSizeRelative32BitRegion()) {
|
||||
buf_.scratch_push_small(vt_use);
|
||||
}
|
||||
// Fill the vtable offset we created above.
|
||||
// The offset points from the beginning of the object to where the
|
||||
// vtable is stored.
|
||||
// The offset points from the beginning of the object to where the vtable is
|
||||
// stored.
|
||||
// Offsets default direction is downward in memory for future format
|
||||
// flexibility (storing all vtables at the start of the file).
|
||||
WriteScalar(buf_.data_at(vtableoffsetloc),
|
||||
WriteScalar(buf_.data_at(vtable_offset_loc + length_of_64_bit_region_),
|
||||
static_cast<soffset_t>(vt_use) -
|
||||
static_cast<soffset_t>(vtableoffsetloc));
|
||||
|
||||
static_cast<soffset_t>(vtable_offset_loc));
|
||||
nested = false;
|
||||
return vtableoffsetloc;
|
||||
return vtable_offset_loc;
|
||||
}
|
||||
|
||||
FLATBUFFERS_ATTRIBUTE([[deprecated("call the version above instead")]])
|
||||
@@ -426,14 +494,20 @@ class FlatBufferBuilder {
|
||||
|
||||
// This checks a required field has been set in a given table that has
|
||||
// just been constructed.
|
||||
template<typename T> void Required(Offset<T> table, voffset_t field);
|
||||
template<typename T> void Required(Offset<T> table, voffset_t field) {
|
||||
auto table_ptr = reinterpret_cast<const Table *>(buf_.data_at(table.o));
|
||||
bool ok = table_ptr->GetOptionalFieldOffset(field) != 0;
|
||||
// If this fails, the caller will show what field needs to be set.
|
||||
FLATBUFFERS_ASSERT(ok);
|
||||
(void)ok;
|
||||
}
|
||||
|
||||
uoffset_t StartStruct(size_t alignment) {
|
||||
Align(alignment);
|
||||
return GetSize();
|
||||
return GetSizeRelative32BitRegion();
|
||||
}
|
||||
|
||||
uoffset_t EndStruct() { return GetSize(); }
|
||||
uoffset_t EndStruct() { return GetSizeRelative32BitRegion(); }
|
||||
|
||||
void ClearOffsets() {
|
||||
buf_.scratch_pop(num_field_loc * sizeof(FieldLoc));
|
||||
@@ -442,15 +516,18 @@ class FlatBufferBuilder {
|
||||
}
|
||||
|
||||
// Aligns such that when "len" bytes are written, an object can be written
|
||||
// after it with "alignment" without padding.
|
||||
// after it (forward in the buffer) with "alignment" without padding.
|
||||
void PreAlign(size_t len, size_t alignment) {
|
||||
if (len == 0) return;
|
||||
TrackMinAlign(alignment);
|
||||
buf_.fill(PaddingBytes(GetSize() + len, alignment));
|
||||
}
|
||||
template<typename T> void PreAlign(size_t len) {
|
||||
AssertScalarT<T>();
|
||||
PreAlign(len, AlignOf<T>());
|
||||
|
||||
// Aligns such than when "len" bytes are written, an object of type `AlignT`
|
||||
// can be written after it (forward in the buffer) without padding.
|
||||
template<typename AlignT> void PreAlign(size_t len) {
|
||||
AssertScalarT<AlignT>();
|
||||
PreAlign(len, AlignOf<AlignT>());
|
||||
}
|
||||
/// @endcond
|
||||
|
||||
@@ -458,34 +535,35 @@ class FlatBufferBuilder {
|
||||
/// @param[in] str A const char pointer to the data to be stored as a string.
|
||||
/// @param[in] len The number of bytes that should be stored from `str`.
|
||||
/// @return Returns the offset in the buffer where the string starts.
|
||||
Offset<String> CreateString(const char *str, size_t len) {
|
||||
NotNested();
|
||||
PreAlign<uoffset_t>(len + 1); // Always 0-terminated.
|
||||
buf_.fill(1);
|
||||
PushBytes(reinterpret_cast<const uint8_t *>(str), len);
|
||||
PushElement(static_cast<uoffset_t>(len));
|
||||
return Offset<String>(GetSize());
|
||||
template<template<typename> class OffsetT = Offset>
|
||||
OffsetT<String> CreateString(const char *str, size_t len) {
|
||||
CreateStringImpl(str, len);
|
||||
return OffsetT<String>(
|
||||
CalculateOffset<typename OffsetT<String>::offset_type>());
|
||||
}
|
||||
|
||||
/// @brief Store a string in the buffer, which is null-terminated.
|
||||
/// @param[in] str A const char pointer to a C-string to add to the buffer.
|
||||
/// @return Returns the offset in the buffer where the string starts.
|
||||
Offset<String> CreateString(const char *str) {
|
||||
return CreateString(str, strlen(str));
|
||||
template<template<typename> class OffsetT = Offset>
|
||||
OffsetT<String> CreateString(const char *str) {
|
||||
return CreateString<OffsetT>(str, strlen(str));
|
||||
}
|
||||
|
||||
/// @brief Store a string in the buffer, which is null-terminated.
|
||||
/// @param[in] str A char pointer to a C-string to add to the buffer.
|
||||
/// @return Returns the offset in the buffer where the string starts.
|
||||
Offset<String> CreateString(char *str) {
|
||||
return CreateString(str, strlen(str));
|
||||
template<template<typename> class OffsetT = Offset>
|
||||
OffsetT<String> CreateString(char *str) {
|
||||
return CreateString<OffsetT>(str, strlen(str));
|
||||
}
|
||||
|
||||
/// @brief Store a string in the buffer, which can contain any binary data.
|
||||
/// @param[in] str A const reference to a std::string to store in the buffer.
|
||||
/// @return Returns the offset in the buffer where the string starts.
|
||||
Offset<String> CreateString(const std::string &str) {
|
||||
return CreateString(str.c_str(), str.length());
|
||||
template<template<typename> class OffsetT = Offset>
|
||||
OffsetT<String> CreateString(const std::string &str) {
|
||||
return CreateString<OffsetT>(str.c_str(), str.length());
|
||||
}
|
||||
|
||||
// clang-format off
|
||||
@@ -493,8 +571,9 @@ class FlatBufferBuilder {
|
||||
/// @brief Store a string in the buffer, which can contain any binary data.
|
||||
/// @param[in] str A const string_view to copy in to the buffer.
|
||||
/// @return Returns the offset in the buffer where the string starts.
|
||||
Offset<String> CreateString(flatbuffers::string_view str) {
|
||||
return CreateString(str.data(), str.size());
|
||||
template<template <typename> class OffsetT = Offset>
|
||||
OffsetT<String>CreateString(flatbuffers::string_view str) {
|
||||
return CreateString<OffsetT>(str.data(), str.size());
|
||||
}
|
||||
#endif // FLATBUFFERS_HAS_STRING_VIEW
|
||||
// clang-format on
|
||||
@@ -502,16 +581,21 @@ class FlatBufferBuilder {
|
||||
/// @brief Store a string in the buffer, which can contain any binary data.
|
||||
/// @param[in] str A const pointer to a `String` struct to add to the buffer.
|
||||
/// @return Returns the offset in the buffer where the string starts
|
||||
Offset<String> CreateString(const String *str) {
|
||||
return str ? CreateString(str->c_str(), str->size()) : 0;
|
||||
template<template<typename> class OffsetT = Offset>
|
||||
OffsetT<String> CreateString(const String *str) {
|
||||
return str ? CreateString<OffsetT>(str->c_str(), str->size()) : 0;
|
||||
}
|
||||
|
||||
/// @brief Store a string in the buffer, which can contain any binary data.
|
||||
/// @param[in] str A const reference to a std::string like type with support
|
||||
/// of T::c_str() and T::length() to store in the buffer.
|
||||
/// @return Returns the offset in the buffer where the string starts.
|
||||
template<typename T> Offset<String> CreateString(const T &str) {
|
||||
return CreateString(str.c_str(), str.length());
|
||||
template<template<typename> class OffsetT = Offset,
|
||||
// No need to explicitly declare the T type, let the compiler deduce
|
||||
// it.
|
||||
int &...ExplicitArgumentBarrier, typename T>
|
||||
OffsetT<String> CreateString(const T &str) {
|
||||
return CreateString<OffsetT>(str.c_str(), str.length());
|
||||
}
|
||||
|
||||
/// @brief Store a string in the buffer, which can contain any binary data.
|
||||
@@ -523,12 +607,14 @@ class FlatBufferBuilder {
|
||||
/// @return Returns the offset in the buffer where the string starts.
|
||||
Offset<String> CreateSharedString(const char *str, size_t len) {
|
||||
FLATBUFFERS_ASSERT(FLATBUFFERS_GENERAL_HEAP_ALLOC_OK);
|
||||
if (!string_pool)
|
||||
if (!string_pool) {
|
||||
string_pool = new StringOffsetMap(StringOffsetCompare(buf_));
|
||||
auto size_before_string = buf_.size();
|
||||
}
|
||||
|
||||
const size_t size_before_string = buf_.size();
|
||||
// Must first serialize the string, since the set is all offsets into
|
||||
// buffer.
|
||||
auto off = CreateString(str, len);
|
||||
const Offset<String> off = CreateString<Offset>(str, len);
|
||||
auto it = string_pool->find(off);
|
||||
// If it exists we reuse existing serialized data!
|
||||
if (it != string_pool->end()) {
|
||||
@@ -584,21 +670,27 @@ class FlatBufferBuilder {
|
||||
}
|
||||
|
||||
/// @cond FLATBUFFERS_INTERNAL
|
||||
uoffset_t EndVector(size_t len) {
|
||||
template<typename LenT = uoffset_t, typename ReturnT = uoffset_t>
|
||||
ReturnT EndVector(size_t len) {
|
||||
FLATBUFFERS_ASSERT(nested); // Hit if no corresponding StartVector.
|
||||
nested = false;
|
||||
return PushElement(static_cast<uoffset_t>(len));
|
||||
return PushElement<LenT, ReturnT>(static_cast<LenT>(len));
|
||||
}
|
||||
|
||||
template<template<typename> class OffsetT = Offset, typename LenT = uint32_t>
|
||||
void StartVector(size_t len, size_t elemsize, size_t alignment) {
|
||||
NotNested();
|
||||
nested = true;
|
||||
PreAlign<uoffset_t>(len * elemsize);
|
||||
// Align to the Length type of the vector (either 32-bit or 64-bit), so
|
||||
// that the length of the buffer can be added without padding.
|
||||
PreAlign<LenT>(len * elemsize);
|
||||
PreAlign(len * elemsize, alignment); // Just in case elemsize > uoffset_t.
|
||||
}
|
||||
|
||||
template<typename T> void StartVector(size_t len) {
|
||||
return StartVector(len, sizeof(T), AlignOf<T>());
|
||||
template<typename T, template<typename> class OffsetT = Offset,
|
||||
typename LenT = uint32_t>
|
||||
void StartVector(size_t len) {
|
||||
return StartVector<OffsetT, LenT>(len, sizeof(T), AlignOf<T>());
|
||||
}
|
||||
|
||||
// Call this right before StartVector/CreateVector if you want to force the
|
||||
@@ -623,31 +715,40 @@ class FlatBufferBuilder {
|
||||
|
||||
/// @brief Serialize an array into a FlatBuffer `vector`.
|
||||
/// @tparam T The data type of the array elements.
|
||||
/// @tparam OffsetT the type of offset to return
|
||||
/// @tparam VectorT the type of vector to cast to.
|
||||
/// @param[in] v A pointer to the array of type `T` to serialize into the
|
||||
/// buffer as a `vector`.
|
||||
/// @param[in] len The number of elements to serialize.
|
||||
/// @return Returns a typed `Offset` into the serialized data indicating
|
||||
/// @return Returns a typed `TOffset` into the serialized data indicating
|
||||
/// where the vector is stored.
|
||||
template<typename T> Offset<Vector<T>> CreateVector(const T *v, size_t len) {
|
||||
template<template<typename...> class OffsetT = Offset,
|
||||
template<typename...> class VectorT = Vector,
|
||||
int &...ExplicitArgumentBarrier, typename T>
|
||||
OffsetT<VectorT<T>> CreateVector(const T *v, size_t len) {
|
||||
// The type of the length field in the vector.
|
||||
typedef typename VectorT<T>::size_type LenT;
|
||||
typedef typename OffsetT<VectorT<T>>::offset_type offset_type;
|
||||
// If this assert hits, you're specifying a template argument that is
|
||||
// causing the wrong overload to be selected, remove it.
|
||||
AssertScalarT<T>();
|
||||
StartVector<T>(len);
|
||||
if (len == 0) { return Offset<Vector<T>>(EndVector(len)); }
|
||||
// clang-format off
|
||||
#if FLATBUFFERS_LITTLEENDIAN
|
||||
PushBytes(reinterpret_cast<const uint8_t *>(v), len * sizeof(T));
|
||||
#else
|
||||
if (sizeof(T) == 1) {
|
||||
PushBytes(reinterpret_cast<const uint8_t *>(v), len);
|
||||
} else {
|
||||
for (auto i = len; i > 0; ) {
|
||||
PushElement(v[--i]);
|
||||
StartVector<T, OffsetT, LenT>(len);
|
||||
if (len > 0) {
|
||||
// clang-format off
|
||||
#if FLATBUFFERS_LITTLEENDIAN
|
||||
PushBytes(reinterpret_cast<const uint8_t *>(v), len * sizeof(T));
|
||||
#else
|
||||
if (sizeof(T) == 1) {
|
||||
PushBytes(reinterpret_cast<const uint8_t *>(v), len);
|
||||
} else {
|
||||
for (auto i = len; i > 0; ) {
|
||||
PushElement(v[--i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
// clang-format on
|
||||
return Offset<Vector<T>>(EndVector(len));
|
||||
#endif
|
||||
// clang-format on
|
||||
}
|
||||
return OffsetT<VectorT<T>>(EndVector<LenT, offset_type>(len));
|
||||
}
|
||||
|
||||
/// @brief Serialize an array like object into a FlatBuffer `vector`.
|
||||
@@ -689,6 +790,12 @@ class FlatBufferBuilder {
|
||||
return CreateVector(data(v), v.size());
|
||||
}
|
||||
|
||||
template<template<typename...> class VectorT = Vector64,
|
||||
int &...ExplicitArgumentBarrier, typename T>
|
||||
Offset64<VectorT<T>> CreateVector64(const std::vector<T> &v) {
|
||||
return CreateVector<Offset64, VectorT>(data(v), v.size());
|
||||
}
|
||||
|
||||
// vector<bool> may be implemented using a bit-set, so we can't access it as
|
||||
// an array. Instead, read elements manually.
|
||||
// Background: https://isocpp.org/blog/2012/11/on-vectorbool
|
||||
@@ -785,47 +892,19 @@ class FlatBufferBuilder {
|
||||
/// @param[in] len The number of elements to serialize.
|
||||
/// @return Returns a typed `Offset` into the serialized data indicating
|
||||
/// where the vector is stored.
|
||||
template<typename T>
|
||||
Offset<Vector<const T *>> CreateVectorOfStructs(const T *v, size_t len) {
|
||||
StartVector(len * sizeof(T) / AlignOf<T>(), sizeof(T), AlignOf<T>());
|
||||
template<typename T, template<typename...> class OffsetT = Offset,
|
||||
template<typename...> class VectorT = Vector>
|
||||
OffsetT<VectorT<const T *>> CreateVectorOfStructs(const T *v, size_t len) {
|
||||
// The type of the length field in the vector.
|
||||
typedef typename VectorT<T>::size_type LenT;
|
||||
typedef typename OffsetT<VectorT<const T *>>::offset_type offset_type;
|
||||
|
||||
StartVector<OffsetT, LenT>(len * sizeof(T) / AlignOf<T>(), sizeof(T),
|
||||
AlignOf<T>());
|
||||
if (len > 0) {
|
||||
PushBytes(reinterpret_cast<const uint8_t *>(v), sizeof(T) * len);
|
||||
}
|
||||
return Offset<Vector<const T *>>(EndVector(len));
|
||||
}
|
||||
|
||||
/// @brief Serialize an array of native structs into a FlatBuffer `vector`.
|
||||
/// @tparam T The data type of the struct array elements.
|
||||
/// @tparam S The data type of the native struct array elements.
|
||||
/// @param[in] v A pointer to the array of type `S` to serialize into the
|
||||
/// buffer as a `vector`.
|
||||
/// @param[in] len The number of elements to serialize.
|
||||
/// @param[in] pack_func Pointer to a function to convert the native struct
|
||||
/// to the FlatBuffer struct.
|
||||
/// @return Returns a typed `Offset` into the serialized data indicating
|
||||
/// where the vector is stored.
|
||||
template<typename T, typename S>
|
||||
Offset<Vector<const T *>> CreateVectorOfNativeStructs(
|
||||
const S *v, size_t len, T (*const pack_func)(const S &)) {
|
||||
FLATBUFFERS_ASSERT(pack_func);
|
||||
auto structs = StartVectorOfStructs<T>(len);
|
||||
for (size_t i = 0; i < len; i++) { structs[i] = pack_func(v[i]); }
|
||||
return EndVectorOfStructs<T>(len);
|
||||
}
|
||||
|
||||
/// @brief Serialize an array of native structs into a FlatBuffer `vector`.
|
||||
/// @tparam T The data type of the struct array elements.
|
||||
/// @tparam S The data type of the native struct array elements.
|
||||
/// @param[in] v A pointer to the array of type `S` to serialize into the
|
||||
/// buffer as a `vector`.
|
||||
/// @param[in] len The number of elements to serialize.
|
||||
/// @return Returns a typed `Offset` into the serialized data indicating
|
||||
/// where the vector is stored.
|
||||
template<typename T, typename S>
|
||||
Offset<Vector<const T *>> CreateVectorOfNativeStructs(const S *v,
|
||||
size_t len) {
|
||||
extern T Pack(const S &);
|
||||
return CreateVectorOfNativeStructs(v, len, Pack);
|
||||
return OffsetT<VectorT<const T *>>(EndVector<LenT, offset_type>(len));
|
||||
}
|
||||
|
||||
/// @brief Serialize an array of structs into a FlatBuffer `vector`.
|
||||
@@ -873,10 +952,52 @@ class FlatBufferBuilder {
|
||||
/// serialize into the buffer as a `vector`.
|
||||
/// @return Returns a typed `Offset` into the serialized data indicating
|
||||
/// where the vector is stored.
|
||||
template<typename T, typename Alloc = std::allocator<T>>
|
||||
Offset<Vector<const T *>> CreateVectorOfStructs(
|
||||
template<typename T, template<typename...> class OffsetT = Offset,
|
||||
template<typename...> class VectorT = Vector,
|
||||
typename Alloc = std::allocator<T>>
|
||||
OffsetT<VectorT<const T *>> CreateVectorOfStructs(
|
||||
const std::vector<T, Alloc> &v) {
|
||||
return CreateVectorOfStructs(data(v), v.size());
|
||||
return CreateVectorOfStructs<T, OffsetT, VectorT>(data(v), v.size());
|
||||
}
|
||||
|
||||
template<template<typename...> class VectorT = Vector64, int &..., typename T>
|
||||
Offset64<VectorT<const T *>> CreateVectorOfStructs64(
|
||||
const std::vector<T> &v) {
|
||||
return CreateVectorOfStructs<T, Offset64, VectorT>(data(v), v.size());
|
||||
}
|
||||
|
||||
/// @brief Serialize an array of native structs into a FlatBuffer `vector`.
|
||||
/// @tparam T The data type of the struct array elements.
|
||||
/// @tparam S The data type of the native struct array elements.
|
||||
/// @param[in] v A pointer to the array of type `S` to serialize into the
|
||||
/// buffer as a `vector`.
|
||||
/// @param[in] len The number of elements to serialize.
|
||||
/// @param[in] pack_func Pointer to a function to convert the native struct
|
||||
/// to the FlatBuffer struct.
|
||||
/// @return Returns a typed `Offset` into the serialized data indicating
|
||||
/// where the vector is stored.
|
||||
template<typename T, typename S>
|
||||
Offset<Vector<const T *>> CreateVectorOfNativeStructs(
|
||||
const S *v, size_t len, T (*const pack_func)(const S &)) {
|
||||
FLATBUFFERS_ASSERT(pack_func);
|
||||
auto structs = StartVectorOfStructs<T>(len);
|
||||
for (size_t i = 0; i < len; i++) { structs[i] = pack_func(v[i]); }
|
||||
return EndVectorOfStructs<T>(len);
|
||||
}
|
||||
|
||||
/// @brief Serialize an array of native structs into a FlatBuffer `vector`.
|
||||
/// @tparam T The data type of the struct array elements.
|
||||
/// @tparam S The data type of the native struct array elements.
|
||||
/// @param[in] v A pointer to the array of type `S` to serialize into the
|
||||
/// buffer as a `vector`.
|
||||
/// @param[in] len The number of elements to serialize.
|
||||
/// @return Returns a typed `Offset` into the serialized data indicating
|
||||
/// where the vector is stored.
|
||||
template<typename T, typename S>
|
||||
Offset<Vector<const T *>> CreateVectorOfNativeStructs(const S *v,
|
||||
size_t len) {
|
||||
extern T Pack(const S &);
|
||||
return CreateVectorOfNativeStructs(v, len, Pack);
|
||||
}
|
||||
|
||||
/// @brief Serialize a `std::vector` of native structs into a FlatBuffer
|
||||
@@ -979,14 +1100,14 @@ class FlatBufferBuilder {
|
||||
|
||||
/// @cond FLATBUFFERS_INTERNAL
|
||||
template<typename T> struct TableKeyComparator {
|
||||
TableKeyComparator(vector_downward &buf) : buf_(buf) {}
|
||||
explicit TableKeyComparator(vector_downward<SizeT> &buf) : buf_(buf) {}
|
||||
TableKeyComparator(const TableKeyComparator &other) : buf_(other.buf_) {}
|
||||
bool operator()(const Offset<T> &a, const Offset<T> &b) const {
|
||||
auto table_a = reinterpret_cast<T *>(buf_.data_at(a.o));
|
||||
auto table_b = reinterpret_cast<T *>(buf_.data_at(b.o));
|
||||
return table_a->KeyCompareLessThan(table_b);
|
||||
}
|
||||
vector_downward &buf_;
|
||||
vector_downward<SizeT> &buf_;
|
||||
|
||||
private:
|
||||
FLATBUFFERS_DELETE_FUNC(
|
||||
@@ -1034,7 +1155,7 @@ class FlatBufferBuilder {
|
||||
NotNested();
|
||||
StartVector(len, elemsize, alignment);
|
||||
buf_.make_space(len * elemsize);
|
||||
auto vec_start = GetSize();
|
||||
const uoffset_t vec_start = GetSizeRelative32BitRegion();
|
||||
auto vec_end = EndVector(len);
|
||||
*buf = buf_.data_at(vec_start);
|
||||
return vec_end;
|
||||
@@ -1085,7 +1206,8 @@ class FlatBufferBuilder {
|
||||
NotNested();
|
||||
Align(AlignOf<T>());
|
||||
buf_.push_small(structobj);
|
||||
return Offset<const T *>(GetSize());
|
||||
return Offset<const T *>(
|
||||
CalculateOffset<typename Offset<const T *>::offset_type>());
|
||||
}
|
||||
|
||||
/// @brief Finish serializing a buffer by writing the root offset.
|
||||
@@ -1109,7 +1231,7 @@ class FlatBufferBuilder {
|
||||
Finish(root.o, file_identifier, true);
|
||||
}
|
||||
|
||||
void SwapBufAllocator(FlatBufferBuilder &other) {
|
||||
void SwapBufAllocator(FlatBufferBuilderImpl &other) {
|
||||
buf_.swap_allocator(other.buf_);
|
||||
}
|
||||
|
||||
@@ -1119,16 +1241,23 @@ class FlatBufferBuilder {
|
||||
|
||||
protected:
|
||||
// You shouldn't really be copying instances of this class.
|
||||
FlatBufferBuilder(const FlatBufferBuilder &);
|
||||
FlatBufferBuilder &operator=(const FlatBufferBuilder &);
|
||||
FlatBufferBuilderImpl(const FlatBufferBuilderImpl &);
|
||||
FlatBufferBuilderImpl &operator=(const FlatBufferBuilderImpl &);
|
||||
|
||||
void Finish(uoffset_t root, const char *file_identifier, bool size_prefix) {
|
||||
NotNested();
|
||||
buf_.clear_scratch();
|
||||
|
||||
const size_t prefix_size = size_prefix ? sizeof(SizeT) : 0;
|
||||
// Make sure we track the alignment of the size prefix.
|
||||
TrackMinAlign(prefix_size);
|
||||
|
||||
const size_t root_offset_size = sizeof(uoffset_t);
|
||||
const size_t file_id_size = file_identifier ? kFileIdentifierLength : 0;
|
||||
|
||||
// This will cause the whole buffer to be aligned.
|
||||
PreAlign((size_prefix ? sizeof(uoffset_t) : 0) + sizeof(uoffset_t) +
|
||||
(file_identifier ? kFileIdentifierLength : 0),
|
||||
minalign_);
|
||||
PreAlign(prefix_size + root_offset_size + file_id_size, minalign_);
|
||||
|
||||
if (file_identifier) {
|
||||
FLATBUFFERS_ASSERT(strlen(file_identifier) == kFileIdentifierLength);
|
||||
PushBytes(reinterpret_cast<const uint8_t *>(file_identifier),
|
||||
@@ -1144,7 +1273,7 @@ class FlatBufferBuilder {
|
||||
voffset_t id;
|
||||
};
|
||||
|
||||
vector_downward buf_;
|
||||
vector_downward<SizeT> buf_;
|
||||
|
||||
// Accumulating offsets of table members while it is being built.
|
||||
// We store these in the scratch pad of buf_, after the vtable offsets.
|
||||
@@ -1153,6 +1282,31 @@ class FlatBufferBuilder {
|
||||
// possible vtable.
|
||||
voffset_t max_voffset_;
|
||||
|
||||
// This is the length of the 64-bit region of the buffer. The buffer supports
|
||||
// 64-bit offsets by forcing serialization of those elements in the "tail"
|
||||
// region of the buffer (i.e. "64-bit region"). To properly keep track of
|
||||
// offsets that are referenced from the tail of the buffer to not overflow
|
||||
// their size (e.g. Offset is a uint32_t type), the boundary of the 32-/64-bit
|
||||
// regions must be tracked.
|
||||
//
|
||||
// [ Complete FlatBuffer ]
|
||||
// [32-bit region][64-bit region]
|
||||
// ^ ^
|
||||
// | Tail of the buffer.
|
||||
// |
|
||||
// Tail of the 32-bit region of the buffer.
|
||||
//
|
||||
// This keeps track of the size of the 64-bit region so that the tail of the
|
||||
// 32-bit region can be calculated as `GetSize() - length_of_64_bit_region_`.
|
||||
//
|
||||
// This will remain 0 if no 64-bit offset types are added to the buffer.
|
||||
size_t length_of_64_bit_region_;
|
||||
|
||||
// When true, 64-bit offsets can still be added to the builder. When false,
|
||||
// only 32-bit offsets can be added, and attempts to add a 64-bit offset will
|
||||
// raise an assertion. This is typically a compile-time error in ordering the
|
||||
// serialization of 64-bit offset fields not at the tail of the buffer.
|
||||
|
||||
// Ensure objects are not nested.
|
||||
bool nested;
|
||||
|
||||
@@ -1166,14 +1320,15 @@ class FlatBufferBuilder {
|
||||
bool dedup_vtables_;
|
||||
|
||||
struct StringOffsetCompare {
|
||||
StringOffsetCompare(const vector_downward &buf) : buf_(&buf) {}
|
||||
explicit StringOffsetCompare(const vector_downward<SizeT> &buf)
|
||||
: buf_(&buf) {}
|
||||
bool operator()(const Offset<String> &a, const Offset<String> &b) const {
|
||||
auto stra = reinterpret_cast<const String *>(buf_->data_at(a.o));
|
||||
auto strb = reinterpret_cast<const String *>(buf_->data_at(b.o));
|
||||
return StringLessThan(stra->data(), stra->size(), strb->data(),
|
||||
strb->size());
|
||||
}
|
||||
const vector_downward *buf_;
|
||||
const vector_downward<SizeT> *buf_;
|
||||
};
|
||||
|
||||
// For use with CreateSharedString. Instantiated on first use only.
|
||||
@@ -1181,22 +1336,122 @@ class FlatBufferBuilder {
|
||||
StringOffsetMap *string_pool;
|
||||
|
||||
private:
|
||||
void CanAddOffset64() {
|
||||
// If you hit this assertion, you are attempting to add a 64-bit offset to
|
||||
// a 32-bit only builder. This is because the builder has overloads that
|
||||
// differ only on the offset size returned: e.g.:
|
||||
//
|
||||
// FlatBufferBuilder builder;
|
||||
// Offset64<String> string_offset = builder.CreateString<Offset64>();
|
||||
//
|
||||
// Either use a 64-bit aware builder, or don't try to create an Offset64
|
||||
// return type.
|
||||
//
|
||||
// TODO(derekbailey): we can probably do more enable_if to avoid this
|
||||
// looking like its possible to the user.
|
||||
static_assert(Is64Aware, "cannot add 64-bit offset to a 32-bit builder");
|
||||
|
||||
// If you hit this assertion, you are attempting to add an 64-bit offset
|
||||
// item after already serializing a 32-bit item. All 64-bit offsets have to
|
||||
// added to the tail of the buffer before any 32-bit items can be added.
|
||||
// Otherwise some items might not be addressable due to the maximum range of
|
||||
// the 32-bit offset.
|
||||
FLATBUFFERS_ASSERT(GetSize() == length_of_64_bit_region_);
|
||||
}
|
||||
|
||||
/// @brief Store a string in the buffer, which can contain any binary data.
|
||||
/// @param[in] str A const char pointer to the data to be stored as a string.
|
||||
/// @param[in] len The number of bytes that should be stored from `str`.
|
||||
/// @return Returns the offset in the buffer where the string starts.
|
||||
void CreateStringImpl(const char *str, size_t len) {
|
||||
NotNested();
|
||||
PreAlign<uoffset_t>(len + 1); // Always 0-terminated.
|
||||
buf_.fill(1);
|
||||
PushBytes(reinterpret_cast<const uint8_t *>(str), len);
|
||||
PushElement(static_cast<uoffset_t>(len));
|
||||
}
|
||||
|
||||
// Allocates space for a vector of structures.
|
||||
// Must be completed with EndVectorOfStructs().
|
||||
template<typename T> T *StartVectorOfStructs(size_t vector_size) {
|
||||
StartVector(vector_size * sizeof(T) / AlignOf<T>(), sizeof(T), AlignOf<T>());
|
||||
template<typename T, template<typename> class OffsetT = Offset>
|
||||
T *StartVectorOfStructs(size_t vector_size) {
|
||||
StartVector<OffsetT>(vector_size * sizeof(T) / AlignOf<T>(), sizeof(T),
|
||||
AlignOf<T>());
|
||||
return reinterpret_cast<T *>(buf_.make_space(vector_size * sizeof(T)));
|
||||
}
|
||||
|
||||
// End the vector of structures in the flatbuffers.
|
||||
// Vector should have previously be started with StartVectorOfStructs().
|
||||
template<typename T, template<typename> class OffsetT = Offset>
|
||||
OffsetT<Vector<const T *>> EndVectorOfStructs(size_t vector_size) {
|
||||
return OffsetT<Vector<const T *>>(
|
||||
EndVector<typename Vector<const T *>::size_type,
|
||||
typename OffsetT<Vector<const T *>>::offset_type>(
|
||||
vector_size));
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
Offset<Vector<const T *>> EndVectorOfStructs(size_t vector_size) {
|
||||
return Offset<Vector<const T *>>(EndVector(vector_size));
|
||||
typename std::enable_if<std::is_same<T, uoffset_t>::value, T>::type
|
||||
CalculateOffset() {
|
||||
// Default to the end of the 32-bit region. This may or may not be the end
|
||||
// of the buffer, depending on if any 64-bit offsets have been added.
|
||||
return GetSizeRelative32BitRegion();
|
||||
}
|
||||
|
||||
// Specializations to handle the 64-bit CalculateOffset, which is relative to
|
||||
// end of the buffer.
|
||||
template<typename T>
|
||||
typename std::enable_if<std::is_same<T, uoffset64_t>::value, T>::type
|
||||
CalculateOffset() {
|
||||
// This should never be compiled in when not using a 64-bit builder.
|
||||
static_assert(Is64Aware, "invalid 64-bit offset in 32-bit builder");
|
||||
|
||||
// Store how big the 64-bit region of the buffer is, so we can determine
|
||||
// where the 32/64 bit boundary is.
|
||||
length_of_64_bit_region_ = GetSize();
|
||||
|
||||
return length_of_64_bit_region_;
|
||||
}
|
||||
};
|
||||
/// @}
|
||||
|
||||
// Hack to `FlatBufferBuilder` mean `FlatBufferBuilder<false>` or
|
||||
// `FlatBufferBuilder<>`, where the template < > syntax is required.
|
||||
typedef FlatBufferBuilderImpl<false> FlatBufferBuilder;
|
||||
typedef FlatBufferBuilderImpl<true> FlatBufferBuilder64;
|
||||
|
||||
// These are external due to GCC not allowing them in the class.
|
||||
// See: https://stackoverflow.com/q/8061456/868247
|
||||
template<>
|
||||
template<>
|
||||
inline Offset64<String> FlatBufferBuilder64::CreateString(const char *str,
|
||||
size_t len) {
|
||||
CanAddOffset64();
|
||||
CreateStringImpl(str, len);
|
||||
return Offset64<String>(
|
||||
CalculateOffset<typename Offset64<String>::offset_type>());
|
||||
}
|
||||
|
||||
// Used to distinguish from real Offsets.
|
||||
template<typename T = void> struct EmptyOffset {};
|
||||
|
||||
// TODO(derekbailey): it would be nice to combine these two methods.
|
||||
template<>
|
||||
template<>
|
||||
inline void FlatBufferBuilder64::StartVector<Offset64, uint32_t>(
|
||||
size_t len, size_t elemsize, size_t alignment) {
|
||||
CanAddOffset64();
|
||||
StartVector<EmptyOffset, uint32_t>(len, elemsize, alignment);
|
||||
}
|
||||
|
||||
template<>
|
||||
template<>
|
||||
inline void FlatBufferBuilder64::StartVector<Offset64, uint64_t>(
|
||||
size_t len, size_t elemsize, size_t alignment) {
|
||||
CanAddOffset64();
|
||||
StartVector<EmptyOffset, uint64_t>(len, elemsize, alignment);
|
||||
}
|
||||
|
||||
/// Helpers to get a typed pointer to objects that are currently being built.
|
||||
/// @warning Creating new objects will lead to reallocations and invalidates
|
||||
/// the pointer!
|
||||
@@ -1211,15 +1466,6 @@ const T *GetTemporaryPointer(FlatBufferBuilder &fbb, Offset<T> offset) {
|
||||
return GetMutableTemporaryPointer<T>(fbb, offset);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void FlatBufferBuilder::Required(Offset<T> table, voffset_t field) {
|
||||
auto table_ptr = reinterpret_cast<const Table *>(buf_.data_at(table.o));
|
||||
bool ok = table_ptr->GetOptionalFieldOffset(field) != 0;
|
||||
// If this fails, the caller will show what field needs to be set.
|
||||
FLATBUFFERS_ASSERT(ok);
|
||||
(void)ok;
|
||||
}
|
||||
|
||||
} // namespace flatbuffers
|
||||
|
||||
#endif // FLATBUFFERS_VECTOR_DOWNWARD_H_
|
||||
#endif // FLATBUFFERS_FLATBUFFER_BUILDER_H_
|
||||
|
||||
@@ -76,8 +76,9 @@ inline const uint8_t *GetBufferStartFromRootPointer(const void *root) {
|
||||
}
|
||||
|
||||
/// @brief This return the prefixed size of a FlatBuffer.
|
||||
inline uoffset_t GetPrefixedSize(const uint8_t *buf) {
|
||||
return ReadScalar<uoffset_t>(buf);
|
||||
template<typename SizeT = uoffset_t>
|
||||
inline SizeT GetPrefixedSize(const uint8_t *buf) {
|
||||
return ReadScalar<SizeT>(buf);
|
||||
}
|
||||
|
||||
// Base class for native objects (FlatBuffer data de-serialized into native
|
||||
|
||||
@@ -56,6 +56,7 @@ struct FlatCOptions {
|
||||
bool schema_binary = false;
|
||||
bool grpc_enabled = false;
|
||||
bool requires_bfbs = false;
|
||||
bool file_names_only = false;
|
||||
|
||||
std::vector<std::shared_ptr<CodeGenerator>> generators;
|
||||
};
|
||||
|
||||
@@ -1424,12 +1424,10 @@ class Builder FLATBUFFERS_FINAL_CLASS {
|
||||
|
||||
template<typename T> static Type GetScalarType() {
|
||||
static_assert(flatbuffers::is_scalar<T>::value, "Unrelated types");
|
||||
return flatbuffers::is_floating_point<T>::value
|
||||
? FBT_FLOAT
|
||||
: flatbuffers::is_same<T, bool>::value
|
||||
? FBT_BOOL
|
||||
: (flatbuffers::is_unsigned<T>::value ? FBT_UINT
|
||||
: FBT_INT);
|
||||
return flatbuffers::is_floating_point<T>::value ? FBT_FLOAT
|
||||
: flatbuffers::is_same<T, bool>::value
|
||||
? FBT_BOOL
|
||||
: (flatbuffers::is_unsigned<T>::value ? FBT_UINT : FBT_INT);
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
@@ -45,26 +45,27 @@ 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, 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 */
|
||||
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>, 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)
|
||||
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(VECTOR64, "", Offset64<void>, int, int, VectorOffset, int, unused, Int, Offset<UOffset>, 18) \
|
||||
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>, 17)
|
||||
TD(ARRAY, "", int, int, int, int, int, unused, Int, Offset<UOffset>, 17)
|
||||
// The fields are:
|
||||
// - enum
|
||||
// - FlatBuffers schema type.
|
||||
@@ -139,6 +140,8 @@ inline bool IsLong (BaseType t) { return t == BASE_TYPE_LONG ||
|
||||
inline bool IsBool (BaseType t) { return t == BASE_TYPE_BOOL; }
|
||||
inline bool IsOneByte(BaseType t) { return t >= BASE_TYPE_UTYPE &&
|
||||
t <= BASE_TYPE_UCHAR; }
|
||||
inline bool IsVector (BaseType t) { return t == BASE_TYPE_VECTOR ||
|
||||
t == BASE_TYPE_VECTOR64; }
|
||||
|
||||
inline bool IsUnsigned(BaseType t) {
|
||||
return (t == BASE_TYPE_UTYPE) || (t == BASE_TYPE_UCHAR) ||
|
||||
@@ -210,7 +213,8 @@ struct Type {
|
||||
bool Deserialize(const Parser &parser, const reflection::Type *type);
|
||||
|
||||
BaseType base_type;
|
||||
BaseType element; // only set if t == BASE_TYPE_VECTOR
|
||||
BaseType element; // only set if t == BASE_TYPE_VECTOR or
|
||||
// BASE_TYPE_VECTOR64
|
||||
StructDef *struct_def; // only set if t or element == BASE_TYPE_STRUCT
|
||||
EnumDef *enum_def; // set if t == BASE_TYPE_UNION / BASE_TYPE_UTYPE,
|
||||
// or for an integral type derived from an enum.
|
||||
@@ -326,6 +330,7 @@ struct FieldDef : public Definition {
|
||||
shared(false),
|
||||
native_inline(false),
|
||||
flexbuffer(false),
|
||||
offset64(false),
|
||||
presence(kDefault),
|
||||
nested_flatbuffer(nullptr),
|
||||
padding(0),
|
||||
@@ -352,6 +357,7 @@ struct FieldDef : public Definition {
|
||||
bool native_inline; // Field will be defined inline (instead of as a pointer)
|
||||
// for native tables if field is a struct.
|
||||
bool flexbuffer; // This field contains FlexBuffer data.
|
||||
bool offset64; // If the field uses 64-bit offsets.
|
||||
|
||||
enum Presence {
|
||||
// Field must always be present.
|
||||
@@ -528,9 +534,7 @@ inline bool IsUnionType(const Type &type) {
|
||||
return IsUnion(type) && IsInteger(type.base_type);
|
||||
}
|
||||
|
||||
inline bool IsVector(const Type &type) {
|
||||
return type.base_type == BASE_TYPE_VECTOR;
|
||||
}
|
||||
inline bool IsVector(const Type &type) { return IsVector(type.base_type); }
|
||||
|
||||
inline bool IsVectorOfStruct(const Type &type) {
|
||||
return IsVector(type) && IsStruct(type.VectorType());
|
||||
@@ -697,6 +701,8 @@ struct IDLOptions {
|
||||
bool no_leak_private_annotations;
|
||||
bool require_json_eof;
|
||||
bool keep_proto_id;
|
||||
bool python_no_type_prefix_suffix;
|
||||
bool python_typing;
|
||||
ProtoIdGapAction proto_id_gap_action;
|
||||
|
||||
// Possible options for the more general generator below.
|
||||
@@ -806,6 +812,8 @@ struct IDLOptions {
|
||||
no_leak_private_annotations(false),
|
||||
require_json_eof(true),
|
||||
keep_proto_id(false),
|
||||
python_no_type_prefix_suffix(false),
|
||||
python_typing(false),
|
||||
proto_id_gap_action(ProtoIdGapAction::WARNING),
|
||||
mini_reflect(IDLOptions::kNone),
|
||||
require_explicit_ids(false),
|
||||
@@ -948,6 +956,13 @@ class Parser : public ParserState {
|
||||
known_attributes_["native_default"] = true;
|
||||
known_attributes_["flexbuffer"] = true;
|
||||
known_attributes_["private"] = true;
|
||||
|
||||
// An attribute added to a field to indicate that is uses 64-bit addressing.
|
||||
known_attributes_["offset64"] = true;
|
||||
|
||||
// An attribute added to a vector field to indicate that it uses 64-bit
|
||||
// addressing and it has a 64-bit length.
|
||||
known_attributes_["vector64"] = true;
|
||||
}
|
||||
|
||||
// Copying is not allowed
|
||||
@@ -1058,7 +1073,7 @@ class Parser : public ParserState {
|
||||
FLATBUFFERS_CHECKED_ERROR ParseAnyValue(Value &val, FieldDef *field,
|
||||
size_t parent_fieldn,
|
||||
const StructDef *parent_struct_def,
|
||||
uoffset_t count,
|
||||
size_t count,
|
||||
bool inside_vector = false);
|
||||
template<typename F>
|
||||
FLATBUFFERS_CHECKED_ERROR ParseTableDelimiters(size_t &fieldn,
|
||||
@@ -1070,7 +1085,7 @@ class Parser : public ParserState {
|
||||
void SerializeStruct(FlatBufferBuilder &builder, const StructDef &struct_def,
|
||||
const Value &val);
|
||||
template<typename F>
|
||||
FLATBUFFERS_CHECKED_ERROR ParseVectorDelimiters(uoffset_t &count, F body);
|
||||
FLATBUFFERS_CHECKED_ERROR ParseVectorDelimiters(size_t &count, F body);
|
||||
FLATBUFFERS_CHECKED_ERROR ParseVector(const Type &type, uoffset_t *ovalue,
|
||||
FieldDef *field, size_t fieldn);
|
||||
FLATBUFFERS_CHECKED_ERROR ParseArray(Value &array);
|
||||
@@ -1135,6 +1150,7 @@ class Parser : public ParserState {
|
||||
bool SupportsAdvancedArrayFeatures() const;
|
||||
bool SupportsOptionalScalars() const;
|
||||
bool SupportsDefaultVectorsAndStrings() const;
|
||||
bool Supports64BitOffsets() const;
|
||||
Namespace *UniqueNamespace(Namespace *ns);
|
||||
|
||||
FLATBUFFERS_CHECKED_ERROR RecurseError();
|
||||
@@ -1196,13 +1212,14 @@ class Parser : public ParserState {
|
||||
// strict_json adds "quotes" around field names if true.
|
||||
// If the flatbuffer cannot be encoded in JSON (e.g., it contains non-UTF-8
|
||||
// byte arrays in String values), returns false.
|
||||
extern bool GenerateTextFromTable(const Parser &parser, const void *table,
|
||||
const std::string &tablename,
|
||||
std::string *text);
|
||||
extern bool GenerateText(const Parser &parser, const void *flatbuffer,
|
||||
std::string *text);
|
||||
extern bool GenerateTextFile(const Parser &parser, const std::string &path,
|
||||
const std::string &file_name);
|
||||
extern const char *GenerateTextFromTable(const Parser &parser, const void *table,
|
||||
const std::string &tablename,
|
||||
std::string *text);
|
||||
extern const char *GenerateText(const Parser &parser, const void *flatbuffer,
|
||||
std::string *text);
|
||||
extern const char *GenerateTextFile(const Parser &parser,
|
||||
const std::string &path,
|
||||
const std::string &file_name);
|
||||
|
||||
// Generate Json schema to string
|
||||
// See idl_gen_json_schema.cpp.
|
||||
@@ -1283,9 +1300,9 @@ extern bool GenerateSwift(const Parser &parser, const std::string &path,
|
||||
// Generate a schema file from the internal representation, useful after
|
||||
// parsing a .proto schema.
|
||||
extern std::string GenerateFBS(const Parser &parser,
|
||||
const std::string &file_name);
|
||||
const std::string &file_name, bool no_log);
|
||||
extern bool GenerateFBS(const Parser &parser, const std::string &path,
|
||||
const std::string &file_name);
|
||||
const std::string &file_name, bool no_log);
|
||||
|
||||
// Generate a make rule for the generated TypeScript code.
|
||||
// See idl_gen_ts.cpp.
|
||||
|
||||
@@ -408,7 +408,7 @@ inline std::string FlatBufferToString(const uint8_t *buffer,
|
||||
const TypeTable *type_table,
|
||||
bool multi_line = false,
|
||||
bool vector_delimited = true,
|
||||
const std::string& indent = "") {
|
||||
const std::string &indent = "") {
|
||||
ToStringVisitor tostring_visitor(multi_line ? "\n" : " ", false, indent,
|
||||
vector_delimited);
|
||||
IterateFlatBuffer(buffer, type_table, &tostring_visitor);
|
||||
|
||||
@@ -66,6 +66,7 @@ inline size_t GetTypeSize(reflection::BaseType base_type) {
|
||||
4, // Union
|
||||
0, // Array. Only used in structs. 0 was chosen to prevent out-of-bounds
|
||||
// errors.
|
||||
8, // Vector64
|
||||
|
||||
0 // MaxBaseType. This must be kept the last entry in this array.
|
||||
};
|
||||
|
||||
@@ -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 == 3 &&
|
||||
FLATBUFFERS_VERSION_REVISION == 3,
|
||||
FLATBUFFERS_VERSION_MINOR == 5 &&
|
||||
FLATBUFFERS_VERSION_REVISION == 9,
|
||||
"Non-compatible flatbuffers version included");
|
||||
|
||||
namespace reflection {
|
||||
@@ -64,10 +64,11 @@ enum BaseType {
|
||||
Obj = 15,
|
||||
Union = 16,
|
||||
Array = 17,
|
||||
MaxBaseType = 18
|
||||
Vector64 = 18,
|
||||
MaxBaseType = 19
|
||||
};
|
||||
|
||||
inline const BaseType (&EnumValuesBaseType())[19] {
|
||||
inline const BaseType (&EnumValuesBaseType())[20] {
|
||||
static const BaseType values[] = {
|
||||
None,
|
||||
UType,
|
||||
@@ -87,13 +88,14 @@ inline const BaseType (&EnumValuesBaseType())[19] {
|
||||
Obj,
|
||||
Union,
|
||||
Array,
|
||||
Vector64,
|
||||
MaxBaseType
|
||||
};
|
||||
return values;
|
||||
}
|
||||
|
||||
inline const char * const *EnumNamesBaseType() {
|
||||
static const char * const names[20] = {
|
||||
static const char * const names[21] = {
|
||||
"None",
|
||||
"UType",
|
||||
"Bool",
|
||||
@@ -112,6 +114,7 @@ inline const char * const *EnumNamesBaseType() {
|
||||
"Obj",
|
||||
"Union",
|
||||
"Array",
|
||||
"Vector64",
|
||||
"MaxBaseType",
|
||||
nullptr
|
||||
};
|
||||
@@ -601,7 +604,8 @@ struct Field FLATBUFFERS_FINAL_CLASS : private ::flatbuffers::Table {
|
||||
VT_ATTRIBUTES = 22,
|
||||
VT_DOCUMENTATION = 24,
|
||||
VT_OPTIONAL = 26,
|
||||
VT_PADDING = 28
|
||||
VT_PADDING = 28,
|
||||
VT_OFFSET64 = 30
|
||||
};
|
||||
const ::flatbuffers::String *name() const {
|
||||
return GetPointer<const ::flatbuffers::String *>(VT_NAME);
|
||||
@@ -649,6 +653,10 @@ struct Field FLATBUFFERS_FINAL_CLASS : private ::flatbuffers::Table {
|
||||
uint16_t padding() const {
|
||||
return GetField<uint16_t>(VT_PADDING, 0);
|
||||
}
|
||||
/// If the field uses 64-bit offsets.
|
||||
bool offset64() const {
|
||||
return GetField<uint8_t>(VT_OFFSET64, 0) != 0;
|
||||
}
|
||||
bool Verify(::flatbuffers::Verifier &verifier) const {
|
||||
return VerifyTableStart(verifier) &&
|
||||
VerifyOffsetRequired(verifier, VT_NAME) &&
|
||||
@@ -670,6 +678,7 @@ struct Field FLATBUFFERS_FINAL_CLASS : private ::flatbuffers::Table {
|
||||
verifier.VerifyVectorOfStrings(documentation()) &&
|
||||
VerifyField<uint8_t>(verifier, VT_OPTIONAL, 1) &&
|
||||
VerifyField<uint16_t>(verifier, VT_PADDING, 2) &&
|
||||
VerifyField<uint8_t>(verifier, VT_OFFSET64, 1) &&
|
||||
verifier.EndTable();
|
||||
}
|
||||
};
|
||||
@@ -717,6 +726,9 @@ struct FieldBuilder {
|
||||
void add_padding(uint16_t padding) {
|
||||
fbb_.AddElement<uint16_t>(Field::VT_PADDING, padding, 0);
|
||||
}
|
||||
void add_offset64(bool offset64) {
|
||||
fbb_.AddElement<uint8_t>(Field::VT_OFFSET64, static_cast<uint8_t>(offset64), 0);
|
||||
}
|
||||
explicit FieldBuilder(::flatbuffers::FlatBufferBuilder &_fbb)
|
||||
: fbb_(_fbb) {
|
||||
start_ = fbb_.StartTable();
|
||||
@@ -744,7 +756,8 @@ inline ::flatbuffers::Offset<Field> CreateField(
|
||||
::flatbuffers::Offset<::flatbuffers::Vector<::flatbuffers::Offset<reflection::KeyValue>>> attributes = 0,
|
||||
::flatbuffers::Offset<::flatbuffers::Vector<::flatbuffers::Offset<::flatbuffers::String>>> documentation = 0,
|
||||
bool optional = false,
|
||||
uint16_t padding = 0) {
|
||||
uint16_t padding = 0,
|
||||
bool offset64 = false) {
|
||||
FieldBuilder builder_(_fbb);
|
||||
builder_.add_default_real(default_real);
|
||||
builder_.add_default_integer(default_integer);
|
||||
@@ -755,6 +768,7 @@ inline ::flatbuffers::Offset<Field> CreateField(
|
||||
builder_.add_padding(padding);
|
||||
builder_.add_offset(offset);
|
||||
builder_.add_id(id);
|
||||
builder_.add_offset64(offset64);
|
||||
builder_.add_optional(optional);
|
||||
builder_.add_key(key);
|
||||
builder_.add_required(required);
|
||||
@@ -776,7 +790,8 @@ inline ::flatbuffers::Offset<Field> CreateFieldDirect(
|
||||
std::vector<::flatbuffers::Offset<reflection::KeyValue>> *attributes = nullptr,
|
||||
const std::vector<::flatbuffers::Offset<::flatbuffers::String>> *documentation = nullptr,
|
||||
bool optional = false,
|
||||
uint16_t padding = 0) {
|
||||
uint16_t padding = 0,
|
||||
bool offset64 = false) {
|
||||
auto name__ = name ? _fbb.CreateString(name) : 0;
|
||||
auto attributes__ = attributes ? _fbb.CreateVectorOfSortedTables<reflection::KeyValue>(attributes) : 0;
|
||||
auto documentation__ = documentation ? _fbb.CreateVector<::flatbuffers::Offset<::flatbuffers::String>>(*documentation) : 0;
|
||||
@@ -794,7 +809,8 @@ inline ::flatbuffers::Offset<Field> CreateFieldDirect(
|
||||
attributes__,
|
||||
documentation__,
|
||||
optional,
|
||||
padding);
|
||||
padding,
|
||||
offset64);
|
||||
}
|
||||
|
||||
struct Object FLATBUFFERS_FINAL_CLASS : private ::flatbuffers::Table {
|
||||
|
||||
@@ -52,8 +52,10 @@ class Registry {
|
||||
Parser parser;
|
||||
if (!LoadSchema(ident, &parser)) return false;
|
||||
// Now we're ready to generate text.
|
||||
if (!GenerateText(parser, flatbuf, dest)) {
|
||||
lasterror_ = "unable to generate text for FlatBuffer binary";
|
||||
auto err = GenerateText(parser, flatbuf, dest);
|
||||
if (err) {
|
||||
lasterror_ = "unable to generate text for FlatBuffer binary: " +
|
||||
std::string(err);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
|
||||
@@ -47,14 +47,24 @@ class Table {
|
||||
return field_offset ? ReadScalar<T>(data_ + field_offset) : defaultval;
|
||||
}
|
||||
|
||||
template<typename P> P GetPointer(voffset_t field) {
|
||||
template<typename P, typename OffsetSize = uoffset_t>
|
||||
P GetPointer(voffset_t field) {
|
||||
auto field_offset = GetOptionalFieldOffset(field);
|
||||
auto p = data_ + field_offset;
|
||||
return field_offset ? reinterpret_cast<P>(p + ReadScalar<uoffset_t>(p))
|
||||
return field_offset ? reinterpret_cast<P>(p + ReadScalar<OffsetSize>(p))
|
||||
: nullptr;
|
||||
}
|
||||
template<typename P> P GetPointer(voffset_t field) const {
|
||||
return const_cast<Table *>(this)->GetPointer<P>(field);
|
||||
template<typename P, typename OffsetSize = uoffset_t>
|
||||
P GetPointer(voffset_t field) const {
|
||||
return const_cast<Table *>(this)->GetPointer<P, OffsetSize>(field);
|
||||
}
|
||||
|
||||
template<typename P> P GetPointer64(voffset_t field) {
|
||||
return GetPointer<P, uoffset64_t>(field);
|
||||
}
|
||||
|
||||
template<typename P> P GetPointer64(voffset_t field) const {
|
||||
return GetPointer<P, uoffset64_t>(field);
|
||||
}
|
||||
|
||||
template<typename P> P GetStruct(voffset_t field) const {
|
||||
@@ -131,15 +141,25 @@ class Table {
|
||||
}
|
||||
|
||||
// Versions for offsets.
|
||||
template<typename OffsetT = uoffset_t>
|
||||
bool VerifyOffset(const Verifier &verifier, voffset_t field) const {
|
||||
auto field_offset = GetOptionalFieldOffset(field);
|
||||
return !field_offset || verifier.VerifyOffset(data_, field_offset);
|
||||
return !field_offset || verifier.VerifyOffset<OffsetT>(data_, field_offset);
|
||||
}
|
||||
|
||||
template<typename OffsetT = uoffset_t>
|
||||
bool VerifyOffsetRequired(const Verifier &verifier, voffset_t field) const {
|
||||
auto field_offset = GetOptionalFieldOffset(field);
|
||||
return verifier.Check(field_offset != 0) &&
|
||||
verifier.VerifyOffset(data_, field_offset);
|
||||
verifier.VerifyOffset<OffsetT>(data_, field_offset);
|
||||
}
|
||||
|
||||
bool VerifyOffset64(const Verifier &verifier, voffset_t field) const {
|
||||
return VerifyOffset<uoffset64_t>(verifier, field);
|
||||
}
|
||||
|
||||
bool VerifyOffset64Required(const Verifier &verifier, voffset_t field) const {
|
||||
return VerifyOffsetRequired<uoffset64_t>(verifier, field);
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
@@ -722,9 +722,10 @@ enum class Case {
|
||||
kSnake2 = 9,
|
||||
};
|
||||
|
||||
// Convert the `input` string of case `input_case` to the specified `output_case`.
|
||||
// Convert the `input` string of case `input_case` to the specified
|
||||
// `output_case`.
|
||||
std::string ConvertCase(const std::string &input, Case output_case,
|
||||
Case input_case = Case::kSnake);
|
||||
Case input_case = Case::kSnake);
|
||||
|
||||
} // namespace flatbuffers
|
||||
|
||||
|
||||
@@ -27,7 +27,8 @@ struct String;
|
||||
|
||||
// An STL compatible iterator implementation for Vector below, effectively
|
||||
// calling Get() for every element.
|
||||
template<typename T, typename IT, typename Data = uint8_t *>
|
||||
template<typename T, typename IT, typename Data = uint8_t *,
|
||||
typename SizeT = uoffset_t>
|
||||
struct VectorIterator {
|
||||
typedef std::random_access_iterator_tag iterator_category;
|
||||
typedef IT value_type;
|
||||
@@ -35,8 +36,9 @@ struct VectorIterator {
|
||||
typedef IT *pointer;
|
||||
typedef IT &reference;
|
||||
|
||||
VectorIterator(Data data, uoffset_t i)
|
||||
: data_(data + IndirectHelper<T>::element_stride * i) {}
|
||||
static const SizeT element_stride = IndirectHelper<T>::element_stride;
|
||||
|
||||
VectorIterator(Data data, SizeT i) : data_(data + element_stride * i) {}
|
||||
VectorIterator(const VectorIterator &other) : data_(other.data_) {}
|
||||
VectorIterator() : data_(nullptr) {}
|
||||
|
||||
@@ -63,7 +65,7 @@ struct VectorIterator {
|
||||
}
|
||||
|
||||
difference_type operator-(const VectorIterator &other) const {
|
||||
return (data_ - other.data_) / IndirectHelper<T>::element_stride;
|
||||
return (data_ - other.data_) / element_stride;
|
||||
}
|
||||
|
||||
// Note: return type is incompatible with the standard
|
||||
@@ -75,44 +77,42 @@ struct VectorIterator {
|
||||
IT operator->() const { return IndirectHelper<T>::Read(data_, 0); }
|
||||
|
||||
VectorIterator &operator++() {
|
||||
data_ += IndirectHelper<T>::element_stride;
|
||||
data_ += element_stride;
|
||||
return *this;
|
||||
}
|
||||
|
||||
VectorIterator operator++(int) {
|
||||
VectorIterator temp(data_, 0);
|
||||
data_ += IndirectHelper<T>::element_stride;
|
||||
data_ += element_stride;
|
||||
return temp;
|
||||
}
|
||||
|
||||
VectorIterator operator+(const uoffset_t &offset) const {
|
||||
return VectorIterator(data_ + offset * IndirectHelper<T>::element_stride,
|
||||
0);
|
||||
VectorIterator operator+(const SizeT &offset) const {
|
||||
return VectorIterator(data_ + offset * element_stride, 0);
|
||||
}
|
||||
|
||||
VectorIterator &operator+=(const uoffset_t &offset) {
|
||||
data_ += offset * IndirectHelper<T>::element_stride;
|
||||
VectorIterator &operator+=(const SizeT &offset) {
|
||||
data_ += offset * element_stride;
|
||||
return *this;
|
||||
}
|
||||
|
||||
VectorIterator &operator--() {
|
||||
data_ -= IndirectHelper<T>::element_stride;
|
||||
data_ -= element_stride;
|
||||
return *this;
|
||||
}
|
||||
|
||||
VectorIterator operator--(int) {
|
||||
VectorIterator temp(data_, 0);
|
||||
data_ -= IndirectHelper<T>::element_stride;
|
||||
data_ -= element_stride;
|
||||
return temp;
|
||||
}
|
||||
|
||||
VectorIterator operator-(const uoffset_t &offset) const {
|
||||
return VectorIterator(data_ - offset * IndirectHelper<T>::element_stride,
|
||||
0);
|
||||
VectorIterator operator-(const SizeT &offset) const {
|
||||
return VectorIterator(data_ - offset * element_stride, 0);
|
||||
}
|
||||
|
||||
VectorIterator &operator-=(const uoffset_t &offset) {
|
||||
data_ -= offset * IndirectHelper<T>::element_stride;
|
||||
VectorIterator &operator-=(const SizeT &offset) {
|
||||
data_ -= offset * element_stride;
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -120,8 +120,8 @@ struct VectorIterator {
|
||||
Data data_;
|
||||
};
|
||||
|
||||
template<typename T, typename IT>
|
||||
using VectorConstIterator = VectorIterator<T, IT, const uint8_t *>;
|
||||
template<typename T, typename IT, typename SizeT = uoffset_t>
|
||||
using VectorConstIterator = VectorIterator<T, IT, const uint8_t *, SizeT>;
|
||||
|
||||
template<typename Iterator>
|
||||
struct VectorReverseIterator : public std::reverse_iterator<Iterator> {
|
||||
@@ -145,11 +145,14 @@ struct VectorReverseIterator : public std::reverse_iterator<Iterator> {
|
||||
|
||||
// This is used as a helper type for accessing vectors.
|
||||
// Vector::data() assumes the vector elements start after the length field.
|
||||
template<typename T> class Vector {
|
||||
template<typename T, typename SizeT = uoffset_t> class Vector {
|
||||
public:
|
||||
typedef VectorIterator<T, typename IndirectHelper<T>::mutable_return_type>
|
||||
typedef VectorIterator<T,
|
||||
typename IndirectHelper<T>::mutable_return_type,
|
||||
uint8_t *, SizeT>
|
||||
iterator;
|
||||
typedef VectorConstIterator<T, typename IndirectHelper<T>::return_type>
|
||||
typedef VectorConstIterator<T, typename IndirectHelper<T>::return_type,
|
||||
SizeT>
|
||||
const_iterator;
|
||||
typedef VectorReverseIterator<iterator> reverse_iterator;
|
||||
typedef VectorReverseIterator<const_iterator> const_reverse_iterator;
|
||||
@@ -160,39 +163,41 @@ template<typename T> class Vector {
|
||||
static FLATBUFFERS_CONSTEXPR bool is_span_observable =
|
||||
scalar_tag::value && (FLATBUFFERS_LITTLEENDIAN || sizeof(T) == 1);
|
||||
|
||||
uoffset_t size() const { return EndianScalar(length_); }
|
||||
SizeT size() const { return EndianScalar(length_); }
|
||||
|
||||
// Deprecated: use size(). Here for backwards compatibility.
|
||||
FLATBUFFERS_ATTRIBUTE([[deprecated("use size() instead")]])
|
||||
uoffset_t Length() const { return size(); }
|
||||
SizeT Length() const { return size(); }
|
||||
|
||||
typedef SizeT size_type;
|
||||
typedef typename IndirectHelper<T>::return_type return_type;
|
||||
typedef typename IndirectHelper<T>::mutable_return_type mutable_return_type;
|
||||
typedef typename IndirectHelper<T>::mutable_return_type
|
||||
mutable_return_type;
|
||||
typedef return_type value_type;
|
||||
|
||||
return_type Get(uoffset_t i) const {
|
||||
return_type Get(SizeT i) const {
|
||||
FLATBUFFERS_ASSERT(i < size());
|
||||
return IndirectHelper<T>::Read(Data(), i);
|
||||
}
|
||||
|
||||
return_type operator[](uoffset_t i) const { return Get(i); }
|
||||
return_type operator[](SizeT i) const { return Get(i); }
|
||||
|
||||
// If this is a Vector of enums, T will be its storage type, not the enum
|
||||
// type. This function makes it convenient to retrieve value with enum
|
||||
// type E.
|
||||
template<typename E> E GetEnum(uoffset_t i) const {
|
||||
template<typename E> E GetEnum(SizeT i) const {
|
||||
return static_cast<E>(Get(i));
|
||||
}
|
||||
|
||||
// If this a vector of unions, this does the cast for you. There's no check
|
||||
// to make sure this is the right type!
|
||||
template<typename U> const U *GetAs(uoffset_t i) const {
|
||||
template<typename U> const U *GetAs(SizeT i) const {
|
||||
return reinterpret_cast<const U *>(Get(i));
|
||||
}
|
||||
|
||||
// If this a vector of unions, this does the cast for you. There's no check
|
||||
// to make sure this is actually a string!
|
||||
const String *GetAsString(uoffset_t i) const {
|
||||
const String *GetAsString(SizeT i) const {
|
||||
return reinterpret_cast<const String *>(Get(i));
|
||||
}
|
||||
|
||||
@@ -226,7 +231,7 @@ template<typename T> class Vector {
|
||||
|
||||
// Change elements if you have a non-const pointer to this object.
|
||||
// Scalars only. See reflection.h, and the documentation.
|
||||
void Mutate(uoffset_t i, const T &val) {
|
||||
void Mutate(SizeT i, const T &val) {
|
||||
FLATBUFFERS_ASSERT(i < size());
|
||||
WriteScalar(data() + i, val);
|
||||
}
|
||||
@@ -234,15 +239,15 @@ template<typename T> class Vector {
|
||||
// Change an element of a vector of tables (or strings).
|
||||
// "val" points to the new table/string, as you can obtain from
|
||||
// e.g. reflection::AddFlatBuffer().
|
||||
void MutateOffset(uoffset_t i, const uint8_t *val) {
|
||||
void MutateOffset(SizeT i, const uint8_t *val) {
|
||||
FLATBUFFERS_ASSERT(i < size());
|
||||
static_assert(sizeof(T) == sizeof(uoffset_t), "Unrelated types");
|
||||
static_assert(sizeof(T) == sizeof(SizeT), "Unrelated types");
|
||||
WriteScalar(data() + i,
|
||||
static_cast<uoffset_t>(val - (Data() + i * sizeof(uoffset_t))));
|
||||
static_cast<SizeT>(val - (Data() + i * sizeof(SizeT))));
|
||||
}
|
||||
|
||||
// Get a mutable pointer to tables/strings inside this vector.
|
||||
mutable_return_type GetMutableObject(uoffset_t i) const {
|
||||
mutable_return_type GetMutableObject(SizeT i) const {
|
||||
FLATBUFFERS_ASSERT(i < size());
|
||||
return const_cast<mutable_return_type>(IndirectHelper<T>::Read(Data(), i));
|
||||
}
|
||||
@@ -280,7 +285,7 @@ template<typename T> class Vector {
|
||||
// try to construct these manually.
|
||||
Vector();
|
||||
|
||||
uoffset_t length_;
|
||||
SizeT length_;
|
||||
|
||||
private:
|
||||
// This class is a pointer. Copying will therefore create an invalid object.
|
||||
@@ -299,6 +304,8 @@ template<typename T> class Vector {
|
||||
}
|
||||
};
|
||||
|
||||
template<typename T> using Vector64 = Vector<T, uoffset64_t>;
|
||||
|
||||
template<class U>
|
||||
FLATBUFFERS_CONSTEXPR_CPP11 flatbuffers::span<U> make_span(Vector<U> &vec)
|
||||
FLATBUFFERS_NOEXCEPT {
|
||||
|
||||
@@ -17,6 +17,8 @@
|
||||
#ifndef FLATBUFFERS_VECTOR_DOWNWARD_H_
|
||||
#define FLATBUFFERS_VECTOR_DOWNWARD_H_
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
#include "flatbuffers/base.h"
|
||||
@@ -31,13 +33,15 @@ namespace flatbuffers {
|
||||
// Since this vector leaves the lower part unused, we support a "scratch-pad"
|
||||
// that can be stored there for temporary data, to share the allocated space.
|
||||
// Essentially, this supports 2 std::vectors in a single buffer.
|
||||
class vector_downward {
|
||||
template<typename SizeT = uoffset_t> class vector_downward {
|
||||
public:
|
||||
explicit vector_downward(size_t initial_size, Allocator *allocator,
|
||||
bool own_allocator, size_t buffer_minalign)
|
||||
bool own_allocator, size_t buffer_minalign,
|
||||
const SizeT max_size = FLATBUFFERS_MAX_BUFFER_SIZE)
|
||||
: allocator_(allocator),
|
||||
own_allocator_(own_allocator),
|
||||
initial_size_(initial_size),
|
||||
max_size_(max_size),
|
||||
buffer_minalign_(buffer_minalign),
|
||||
reserved_(0),
|
||||
size_(0),
|
||||
@@ -50,6 +54,7 @@ class vector_downward {
|
||||
: allocator_(other.allocator_),
|
||||
own_allocator_(other.own_allocator_),
|
||||
initial_size_(other.initial_size_),
|
||||
max_size_(other.max_size_),
|
||||
buffer_minalign_(other.buffer_minalign_),
|
||||
reserved_(other.reserved_),
|
||||
size_(other.size_),
|
||||
@@ -111,7 +116,7 @@ class vector_downward {
|
||||
uint8_t *release_raw(size_t &allocated_bytes, size_t &offset) {
|
||||
auto *buf = buf_;
|
||||
allocated_bytes = reserved_;
|
||||
offset = static_cast<size_t>(cur_ - buf_);
|
||||
offset = vector_downward::offset();
|
||||
|
||||
// release_raw only relinquishes the buffer ownership.
|
||||
// Does not deallocate or reset the allocator. Destructor will do that.
|
||||
@@ -136,10 +141,10 @@ class vector_downward {
|
||||
|
||||
size_t ensure_space(size_t len) {
|
||||
FLATBUFFERS_ASSERT(cur_ >= scratch_ && scratch_ >= buf_);
|
||||
if (len > static_cast<size_t>(cur_ - scratch_)) { reallocate(len); }
|
||||
// Beyond this, signed offsets may not have enough range:
|
||||
// (FlatBuffers > 2GB not supported).
|
||||
FLATBUFFERS_ASSERT(size() < FLATBUFFERS_MAX_BUFFER_SIZE);
|
||||
// If the length is larger than the unused part of the buffer, we need to
|
||||
// grow.
|
||||
if (len > unused_buffer_size()) { reallocate(len); }
|
||||
FLATBUFFERS_ASSERT(size() < max_size_);
|
||||
return len;
|
||||
}
|
||||
|
||||
@@ -147,7 +152,7 @@ class vector_downward {
|
||||
if (len) {
|
||||
ensure_space(len);
|
||||
cur_ -= len;
|
||||
size_ += static_cast<uoffset_t>(len);
|
||||
size_ += static_cast<SizeT>(len);
|
||||
}
|
||||
return cur_;
|
||||
}
|
||||
@@ -155,11 +160,17 @@ class vector_downward {
|
||||
// Returns nullptr if using the DefaultAllocator.
|
||||
Allocator *get_custom_allocator() { return allocator_; }
|
||||
|
||||
inline uoffset_t size() const { return size_; }
|
||||
// The current offset into the buffer.
|
||||
size_t offset() const { return cur_ - buf_; }
|
||||
|
||||
uoffset_t scratch_size() const {
|
||||
return static_cast<uoffset_t>(scratch_ - buf_);
|
||||
}
|
||||
// The total size of the vector (both the buffer and scratch parts).
|
||||
inline SizeT size() const { return size_; }
|
||||
|
||||
// The size of the buffer part of the vector that is currently unused.
|
||||
SizeT unused_buffer_size() const { return static_cast<SizeT>(cur_ - scratch_); }
|
||||
|
||||
// The size of the scratch part of the vector.
|
||||
SizeT scratch_size() const { return static_cast<SizeT>(scratch_ - buf_); }
|
||||
|
||||
size_t capacity() const { return reserved_; }
|
||||
|
||||
@@ -211,7 +222,7 @@ class vector_downward {
|
||||
|
||||
void pop(size_t bytes_to_remove) {
|
||||
cur_ += bytes_to_remove;
|
||||
size_ -= static_cast<uoffset_t>(bytes_to_remove);
|
||||
size_ -= static_cast<SizeT>(bytes_to_remove);
|
||||
}
|
||||
|
||||
void scratch_pop(size_t bytes_to_remove) { scratch_ -= bytes_to_remove; }
|
||||
@@ -224,6 +235,7 @@ class vector_downward {
|
||||
swap(buffer_minalign_, other.buffer_minalign_);
|
||||
swap(reserved_, other.reserved_);
|
||||
swap(size_, other.size_);
|
||||
swap(max_size_, other.max_size_);
|
||||
swap(buf_, other.buf_);
|
||||
swap(cur_, other.cur_);
|
||||
swap(scratch_, other.scratch_);
|
||||
@@ -243,9 +255,12 @@ class vector_downward {
|
||||
Allocator *allocator_;
|
||||
bool own_allocator_;
|
||||
size_t initial_size_;
|
||||
|
||||
// The maximum size the vector can be.
|
||||
SizeT max_size_;
|
||||
size_t buffer_minalign_;
|
||||
size_t reserved_;
|
||||
uoffset_t size_;
|
||||
SizeT size_;
|
||||
uint8_t *buf_;
|
||||
uint8_t *cur_; // Points at location between empty (below) and used (above).
|
||||
uint8_t *scratch_; // Points to the end of the scratchpad in use.
|
||||
|
||||
@@ -34,12 +34,16 @@ class Verifier FLATBUFFERS_FINAL_CLASS {
|
||||
bool check_alignment = true;
|
||||
// If true, run verifier on nested flatbuffers
|
||||
bool check_nested_flatbuffers = true;
|
||||
// The maximum size of a buffer.
|
||||
size_t max_size = FLATBUFFERS_MAX_BUFFER_SIZE;
|
||||
// Use assertions to check for errors.
|
||||
bool assert = false;
|
||||
};
|
||||
|
||||
explicit Verifier(const uint8_t *const buf, const size_t buf_len,
|
||||
const Options &opts)
|
||||
: buf_(buf), size_(buf_len), opts_(opts) {
|
||||
FLATBUFFERS_ASSERT(size_ < FLATBUFFERS_MAX_BUFFER_SIZE);
|
||||
FLATBUFFERS_ASSERT(size_ < opts.max_size);
|
||||
}
|
||||
|
||||
// Deprecated API, please construct with Verifier::Options.
|
||||
@@ -58,7 +62,7 @@ class Verifier FLATBUFFERS_FINAL_CLASS {
|
||||
bool Check(const bool ok) const {
|
||||
// clang-format off
|
||||
#ifdef FLATBUFFERS_DEBUG_VERIFICATION_FAILURE
|
||||
FLATBUFFERS_ASSERT(ok);
|
||||
if (opts_.assert) { FLATBUFFERS_ASSERT(ok); }
|
||||
#endif
|
||||
#ifdef FLATBUFFERS_TRACK_VERIFIER_BUFFER_SIZE
|
||||
if (!ok)
|
||||
@@ -113,41 +117,43 @@ class Verifier FLATBUFFERS_FINAL_CLASS {
|
||||
}
|
||||
|
||||
// Verify a pointer (may be NULL) of any vector type.
|
||||
template<typename T> bool VerifyVector(const Vector<T> *const vec) const {
|
||||
return !vec || VerifyVectorOrString(reinterpret_cast<const uint8_t *>(vec),
|
||||
sizeof(T));
|
||||
template<int &..., typename T, typename LenT>
|
||||
bool VerifyVector(const Vector<T, LenT> *const vec) const {
|
||||
return !vec || VerifyVectorOrString<LenT>(
|
||||
reinterpret_cast<const uint8_t *>(vec), sizeof(T));
|
||||
}
|
||||
|
||||
// Verify a pointer (may be NULL) of a vector to struct.
|
||||
template<typename T>
|
||||
bool VerifyVector(const Vector<const T *> *const vec) const {
|
||||
return VerifyVector(reinterpret_cast<const Vector<T> *>(vec));
|
||||
template<int &..., typename T, typename LenT>
|
||||
bool VerifyVector(const Vector<const T *, LenT> *const vec) const {
|
||||
return VerifyVector(reinterpret_cast<const Vector<T, LenT> *>(vec));
|
||||
}
|
||||
|
||||
// Verify a pointer (may be NULL) to string.
|
||||
bool VerifyString(const String *const str) const {
|
||||
size_t end;
|
||||
return !str || (VerifyVectorOrString(reinterpret_cast<const uint8_t *>(str),
|
||||
1, &end) &&
|
||||
return !str || (VerifyVectorOrString<uoffset_t>(
|
||||
reinterpret_cast<const uint8_t *>(str), 1, &end) &&
|
||||
Verify(end, 1) && // Must have terminator
|
||||
Check(buf_[end] == '\0')); // Terminating byte must be 0.
|
||||
}
|
||||
|
||||
// Common code between vectors and strings.
|
||||
template<typename LenT = uoffset_t>
|
||||
bool VerifyVectorOrString(const uint8_t *const vec, const size_t elem_size,
|
||||
size_t *const end = nullptr) const {
|
||||
const auto veco = static_cast<size_t>(vec - buf_);
|
||||
const auto vec_offset = static_cast<size_t>(vec - buf_);
|
||||
// Check we can read the size field.
|
||||
if (!Verify<uoffset_t>(veco)) return false;
|
||||
if (!Verify<LenT>(vec_offset)) return false;
|
||||
// Check the whole array. If this is a string, the byte past the array must
|
||||
// be 0.
|
||||
const auto size = ReadScalar<uoffset_t>(vec);
|
||||
const auto max_elems = FLATBUFFERS_MAX_BUFFER_SIZE / elem_size;
|
||||
const LenT size = ReadScalar<LenT>(vec);
|
||||
const auto max_elems = opts_.max_size / elem_size;
|
||||
if (!Check(size < max_elems))
|
||||
return false; // Protect against byte_size overflowing.
|
||||
const auto byte_size = sizeof(size) + elem_size * size;
|
||||
if (end) *end = veco + byte_size;
|
||||
return Verify(veco, byte_size);
|
||||
const auto byte_size = sizeof(LenT) + elem_size * size;
|
||||
if (end) *end = vec_offset + byte_size;
|
||||
return Verify(vec_offset, byte_size);
|
||||
}
|
||||
|
||||
// Special case for string contents, after the above has been called.
|
||||
@@ -203,7 +209,7 @@ class Verifier FLATBUFFERS_FINAL_CLASS {
|
||||
}
|
||||
|
||||
// Call T::Verify, which must be in the generated code for this type.
|
||||
const auto o = VerifyOffset(start);
|
||||
const auto o = VerifyOffset<uoffset_t>(start);
|
||||
return Check(o != 0) &&
|
||||
reinterpret_cast<const T *>(buf_ + start + o)->Verify(*this)
|
||||
// clang-format off
|
||||
@@ -214,8 +220,8 @@ class Verifier FLATBUFFERS_FINAL_CLASS {
|
||||
// clang-format on
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
bool VerifyNestedFlatBuffer(const Vector<uint8_t> *const buf,
|
||||
template<typename T, int &..., typename SizeT>
|
||||
bool VerifyNestedFlatBuffer(const Vector<uint8_t, SizeT> *const buf,
|
||||
const char *const identifier) {
|
||||
// Caller opted out of this.
|
||||
if (!opts_.check_nested_flatbuffers) return true;
|
||||
@@ -226,7 +232,7 @@ class Verifier FLATBUFFERS_FINAL_CLASS {
|
||||
// If there is a nested buffer, it must be greater than the min size.
|
||||
if (!Check(buf->size() >= FLATBUFFERS_MIN_BUFFER_SIZE)) return false;
|
||||
|
||||
Verifier nested_verifier(buf->data(), buf->size());
|
||||
Verifier nested_verifier(buf->data(), buf->size(), opts_);
|
||||
return nested_verifier.VerifyBuffer<T>(identifier);
|
||||
}
|
||||
|
||||
@@ -237,29 +243,30 @@ class Verifier FLATBUFFERS_FINAL_CLASS {
|
||||
return VerifyBufferFromStart<T>(identifier, 0);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
template<typename T, typename SizeT = uoffset_t>
|
||||
bool VerifySizePrefixedBuffer(const char *const identifier) {
|
||||
return Verify<uoffset_t>(0U) &&
|
||||
Check(ReadScalar<uoffset_t>(buf_) == size_ - sizeof(uoffset_t)) &&
|
||||
VerifyBufferFromStart<T>(identifier, sizeof(uoffset_t));
|
||||
return Verify<SizeT>(0U) &&
|
||||
Check(ReadScalar<SizeT>(buf_) == size_ - sizeof(SizeT)) &&
|
||||
VerifyBufferFromStart<T>(identifier, sizeof(SizeT));
|
||||
}
|
||||
|
||||
uoffset_t VerifyOffset(const size_t start) const {
|
||||
if (!Verify<uoffset_t>(start)) return 0;
|
||||
const auto o = ReadScalar<uoffset_t>(buf_ + start);
|
||||
template<typename OffsetT = uoffset_t, typename SOffsetT = soffset_t>
|
||||
size_t VerifyOffset(const size_t start) const {
|
||||
if (!Verify<OffsetT>(start)) return 0;
|
||||
const auto o = ReadScalar<OffsetT>(buf_ + start);
|
||||
// May not point to itself.
|
||||
if (!Check(o != 0)) return 0;
|
||||
// Can't wrap around / buffers are max 2GB.
|
||||
if (!Check(static_cast<soffset_t>(o) >= 0)) return 0;
|
||||
// Can't wrap around larger than the max size.
|
||||
if (!Check(static_cast<SOffsetT>(o) >= 0)) return 0;
|
||||
// Must be inside the buffer to create a pointer from it (pointer outside
|
||||
// buffer is UB).
|
||||
if (!Verify(start + o, 1)) return 0;
|
||||
return o;
|
||||
}
|
||||
|
||||
uoffset_t VerifyOffset(const uint8_t *const base,
|
||||
const voffset_t start) const {
|
||||
return VerifyOffset(static_cast<size_t>(base - buf_) + start);
|
||||
template<typename OffsetT = uoffset_t>
|
||||
size_t VerifyOffset(const uint8_t *const base, const voffset_t start) const {
|
||||
return VerifyOffset<OffsetT>(static_cast<size_t>(base - buf_) + start);
|
||||
}
|
||||
|
||||
// Called at the start of a table to increase counters measuring data
|
||||
@@ -312,6 +319,12 @@ class Verifier FLATBUFFERS_FINAL_CLASS {
|
||||
std::vector<uint8_t> *flex_reuse_tracker_ = nullptr;
|
||||
};
|
||||
|
||||
// Specialization for 64-bit offsets.
|
||||
template<>
|
||||
inline size_t Verifier::VerifyOffset<uoffset64_t>(const size_t start) const {
|
||||
return VerifyOffset<uoffset64_t, soffset64_t>(start);
|
||||
}
|
||||
|
||||
} // namespace flatbuffers
|
||||
|
||||
#endif // FLATBUFFERS_VERIFIER_H_
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>com.google.flatbuffers</groupId>
|
||||
<artifactId>flatbuffers-java</artifactId>
|
||||
<version>23.3.3</version>
|
||||
<version>23.5.9</version>
|
||||
<packaging>bundle</packaging>
|
||||
<name>FlatBuffers Java API</name>
|
||||
<description>
|
||||
|
||||
@@ -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_3_3() {}
|
||||
public static void FLATBUFFERS_23_5_9() {}
|
||||
}
|
||||
|
||||
/// @endcond
|
||||
|
||||
@@ -23,9 +23,10 @@ public final class BaseType {
|
||||
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 byte Vector64 = 18;
|
||||
public static final byte MaxBaseType = 19;
|
||||
|
||||
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 final String[] names = { "None", "UType", "Bool", "Byte", "UByte", "Short", "UShort", "Int", "UInt", "Long", "ULong", "Float", "Double", "String", "Vector", "Obj", "Union", "Array", "Vector64", "MaxBaseType", };
|
||||
|
||||
public static String name(int e) { return names[e]; }
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ import java.nio.ByteOrder;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public final class Enum extends Table {
|
||||
public static void ValidateVersion() { Constants.FLATBUFFERS_23_3_3(); }
|
||||
public static void ValidateVersion() { Constants.FLATBUFFERS_23_5_9(); }
|
||||
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); }
|
||||
|
||||
@@ -21,7 +21,7 @@ import java.nio.ByteOrder;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public final class EnumVal extends Table {
|
||||
public static void ValidateVersion() { Constants.FLATBUFFERS_23_3_3(); }
|
||||
public static void ValidateVersion() { Constants.FLATBUFFERS_23_5_9(); }
|
||||
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); }
|
||||
|
||||
@@ -21,7 +21,7 @@ import java.nio.ByteOrder;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public final class Field extends Table {
|
||||
public static void ValidateVersion() { Constants.FLATBUFFERS_23_3_3(); }
|
||||
public static void ValidateVersion() { Constants.FLATBUFFERS_23_5_9(); }
|
||||
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); }
|
||||
@@ -55,6 +55,10 @@ public final class Field extends Table {
|
||||
* 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; }
|
||||
/**
|
||||
* If the field uses 64-bit offsets.
|
||||
*/
|
||||
public boolean offset64() { int o = __offset(30); return o != 0 ? 0!=bb.get(o + bb_pos) : false; }
|
||||
|
||||
public static int createField(FlatBufferBuilder builder,
|
||||
int nameOffset,
|
||||
@@ -69,8 +73,9 @@ public final class Field extends Table {
|
||||
int attributesOffset,
|
||||
int documentationOffset,
|
||||
boolean optional,
|
||||
int padding) {
|
||||
builder.startTable(13);
|
||||
int padding,
|
||||
boolean offset64) {
|
||||
builder.startTable(14);
|
||||
Field.addDefaultReal(builder, defaultReal);
|
||||
Field.addDefaultInteger(builder, defaultInteger);
|
||||
Field.addDocumentation(builder, documentationOffset);
|
||||
@@ -80,6 +85,7 @@ public final class Field extends Table {
|
||||
Field.addPadding(builder, padding);
|
||||
Field.addOffset(builder, offset);
|
||||
Field.addId(builder, id);
|
||||
Field.addOffset64(builder, offset64);
|
||||
Field.addOptional(builder, optional);
|
||||
Field.addKey(builder, key);
|
||||
Field.addRequired(builder, required);
|
||||
@@ -87,7 +93,7 @@ public final class Field extends Table {
|
||||
return Field.endField(builder);
|
||||
}
|
||||
|
||||
public static void startField(FlatBufferBuilder builder) { builder.startTable(13); }
|
||||
public static void startField(FlatBufferBuilder builder) { builder.startTable(14); }
|
||||
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); }
|
||||
@@ -105,6 +111,7 @@ public final class Field extends Table {
|
||||
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 void addOffset64(FlatBufferBuilder builder, boolean offset64) { builder.addBoolean(13, offset64, false); }
|
||||
public static int endField(FlatBufferBuilder builder) {
|
||||
int o = builder.endTable();
|
||||
builder.required(o, 4); // name
|
||||
|
||||
@@ -21,7 +21,7 @@ import java.nio.ByteOrder;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public final class KeyValue extends Table {
|
||||
public static void ValidateVersion() { Constants.FLATBUFFERS_23_3_3(); }
|
||||
public static void ValidateVersion() { Constants.FLATBUFFERS_23_5_9(); }
|
||||
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); }
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user