mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-10 23:17:27 +00:00
Compare commits
51 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
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
|
- "*" # new tag version, like `0.8.4` or else
|
||||||
branches:
|
branches:
|
||||||
- master
|
- master
|
||||||
|
- flatbuffers-64
|
||||||
pull_request:
|
pull_request:
|
||||||
branches:
|
branches:
|
||||||
- master
|
- master
|
||||||
@@ -29,7 +30,7 @@ jobs:
|
|||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v3
|
||||||
- name: cmake
|
- 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
|
- name: build
|
||||||
run: make -j
|
run: make -j
|
||||||
- name: test
|
- name: test
|
||||||
@@ -59,11 +60,11 @@ jobs:
|
|||||||
- name: Generate SLSA subjects - clang
|
- name: Generate SLSA subjects - clang
|
||||||
if: matrix.cxx == 'clang++-12' && startsWith(github.ref, 'refs/tags/')
|
if: matrix.cxx == 'clang++-12' && startsWith(github.ref, 'refs/tags/')
|
||||||
id: hash-clang
|
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
|
- name: Generate SLSA subjects - gcc
|
||||||
if: matrix.cxx == 'g++-10' && startsWith(github.ref, 'refs/tags/')
|
if: matrix.cxx == 'g++-10' && startsWith(github.ref, 'refs/tags/')
|
||||||
id: hash-gcc
|
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:
|
build-linux-no-file-tests:
|
||||||
name: Build Linux with -DFLATBUFFERS_NO_FILE_TESTS
|
name: Build Linux with -DFLATBUFFERS_NO_FILE_TESTS
|
||||||
@@ -165,7 +166,7 @@ jobs:
|
|||||||
if: startsWith(github.ref, 'refs/tags/')
|
if: startsWith(github.ref, 'refs/tags/')
|
||||||
id: hash
|
id: hash
|
||||||
shell: bash
|
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:
|
build-windows-2017:
|
||||||
name: Build Windows 2017
|
name: Build Windows 2017
|
||||||
@@ -266,7 +267,7 @@ jobs:
|
|||||||
- name: Generate SLSA subjects
|
- name: Generate SLSA subjects
|
||||||
if: startsWith(github.ref, 'refs/tags/')
|
if: startsWith(github.ref, 'refs/tags/')
|
||||||
id: hash
|
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:
|
build-mac-universal:
|
||||||
permissions:
|
permissions:
|
||||||
@@ -309,7 +310,7 @@ jobs:
|
|||||||
- name: Generate SLSA subjects
|
- name: Generate SLSA subjects
|
||||||
if: startsWith(github.ref, 'refs/tags/')
|
if: startsWith(github.ref, 'refs/tags/')
|
||||||
id: hash
|
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:
|
build-android:
|
||||||
name: Build Android (on Linux)
|
name: Build Android (on Linux)
|
||||||
@@ -560,7 +561,7 @@ jobs:
|
|||||||
echo "$MAC_DIGESTS" | base64 -d >> checksums.txt
|
echo "$MAC_DIGESTS" | base64 -d >> checksums.txt
|
||||||
echo "$MACINTEL_DIGESTS" | base64 -d >> checksums.txt
|
echo "$MACINTEL_DIGESTS" | base64 -d >> checksums.txt
|
||||||
echo "$WINDOWS_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:
|
provenance:
|
||||||
if: startsWith(github.ref, 'refs/tags/')
|
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
|
name: Mark stale issues and pull requests
|
||||||
permissions: read-all
|
permissions:
|
||||||
|
issues: write
|
||||||
|
pull-requests: write
|
||||||
|
|
||||||
on:
|
on:
|
||||||
|
# For manual tests.
|
||||||
|
workflow_dispatch:
|
||||||
schedule:
|
schedule:
|
||||||
- cron: "30 20 * * *"
|
- cron: "30 20 * * *"
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
stale:
|
stale:
|
||||||
@@ -11,14 +15,23 @@ jobs:
|
|||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/stale@v4.0.0
|
- uses: actions/stale@v7.0.0
|
||||||
with:
|
with:
|
||||||
repo-token: ${{ secrets.GITHUB_TOKEN }}
|
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.'
|
operations-per-run: 500
|
||||||
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
|
|
||||||
exempt-all-milestones: true
|
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")
|
load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_library")
|
||||||
|
|
||||||
licenses(["notice"])
|
licenses(["notice"])
|
||||||
@@ -6,6 +8,13 @@ package(
|
|||||||
default_visibility = ["//visibility:public"],
|
default_visibility = ["//visibility:public"],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
npm_link_all_packages(name = "node_modules")
|
||||||
|
|
||||||
|
npm_link_package(
|
||||||
|
name = "node_modules/flatbuffers",
|
||||||
|
src = "//ts:flatbuffers",
|
||||||
|
)
|
||||||
|
|
||||||
exports_files([
|
exports_files([
|
||||||
"LICENSE",
|
"LICENSE",
|
||||||
"tsconfig.json",
|
"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.
|
# Public flatc library to compile flatbuffer files at runtime.
|
||||||
cc_library(
|
cc_library(
|
||||||
name = "flatbuffers",
|
name = "flatbuffers",
|
||||||
@@ -47,6 +73,7 @@ filegroup(
|
|||||||
"include/flatbuffers/code_generators.h",
|
"include/flatbuffers/code_generators.h",
|
||||||
"include/flatbuffers/default_allocator.h",
|
"include/flatbuffers/default_allocator.h",
|
||||||
"include/flatbuffers/detached_buffer.h",
|
"include/flatbuffers/detached_buffer.h",
|
||||||
|
"include/flatbuffers/file_manager.h",
|
||||||
"include/flatbuffers/flatbuffer_builder.h",
|
"include/flatbuffers/flatbuffer_builder.h",
|
||||||
"include/flatbuffers/flatbuffers.h",
|
"include/flatbuffers/flatbuffers.h",
|
||||||
"include/flatbuffers/flex_flat_util.h",
|
"include/flatbuffers/flex_flat_util.h",
|
||||||
|
|||||||
43
CHANGELOG.md
43
CHANGELOG.md
@@ -4,6 +4,49 @@ 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
|
new features that should be highlighted. Minor fixes or improvements are not
|
||||||
necessarily listed.
|
necessarily listed.
|
||||||
|
|
||||||
|
## [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)
|
## [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).
|
* Refactoring of `flatc` generators to use an interface (#7797).
|
||||||
|
|||||||
@@ -59,6 +59,9 @@ function(build_flatbuffers flatbuffers_schemas
|
|||||||
if(FLATBUFFERS_FLATC_EXECUTABLE)
|
if(FLATBUFFERS_FLATC_EXECUTABLE)
|
||||||
set(FLATC_TARGET "")
|
set(FLATC_TARGET "")
|
||||||
set(FLATC ${FLATBUFFERS_FLATC_EXECUTABLE})
|
set(FLATC ${FLATBUFFERS_FLATC_EXECUTABLE})
|
||||||
|
elseif(TARGET flatbuffers::flatc)
|
||||||
|
set(FLATC_TARGET flatbuffers::flatc)
|
||||||
|
set(FLATC flatbuffers::flatc)
|
||||||
else()
|
else()
|
||||||
set(FLATC_TARGET flatc)
|
set(FLATC_TARGET flatc)
|
||||||
set(FLATC flatc)
|
set(FLATC flatc)
|
||||||
@@ -211,6 +214,9 @@ function(flatbuffers_generate_headers)
|
|||||||
if(FLATBUFFERS_FLATC_EXECUTABLE)
|
if(FLATBUFFERS_FLATC_EXECUTABLE)
|
||||||
set(FLATC_TARGET "")
|
set(FLATC_TARGET "")
|
||||||
set(FLATC ${FLATBUFFERS_FLATC_EXECUTABLE})
|
set(FLATC ${FLATBUFFERS_FLATC_EXECUTABLE})
|
||||||
|
elseif(TARGET flatbuffers::flatc)
|
||||||
|
set(FLATC_TARGET flatbuffers::flatc)
|
||||||
|
set(FLATC flatbuffers::flatc)
|
||||||
else()
|
else()
|
||||||
set(FLATC_TARGET flatc)
|
set(FLATC_TARGET flatc)
|
||||||
set(FLATC flatc)
|
set(FLATC flatc)
|
||||||
@@ -382,6 +388,9 @@ function(flatbuffers_generate_binary_files)
|
|||||||
if(FLATBUFFERS_FLATC_EXECUTABLE)
|
if(FLATBUFFERS_FLATC_EXECUTABLE)
|
||||||
set(FLATC_TARGET "")
|
set(FLATC_TARGET "")
|
||||||
set(FLATC ${FLATBUFFERS_FLATC_EXECUTABLE})
|
set(FLATC ${FLATBUFFERS_FLATC_EXECUTABLE})
|
||||||
|
elseif(TARGET flatbuffers::flatc)
|
||||||
|
set(FLATC_TARGET flatbuffers::flatc)
|
||||||
|
set(FLATC flatbuffers::flatc)
|
||||||
else()
|
else()
|
||||||
set(FLATC_TARGET flatc)
|
set(FLATC_TARGET flatc)
|
||||||
set(FLATC flatc)
|
set(FLATC flatc)
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ if (UNIX)
|
|||||||
|
|
||||||
set(CPACK_RPM_PACKAGE_VENDOR "Google, Inc.")
|
set(CPACK_RPM_PACKAGE_VENDOR "Google, Inc.")
|
||||||
set(CPACK_RPM_PACKAGE_LICENSE "Apache 2.0")
|
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)
|
set(CPACK_PACKAGE_DESCRIPTION_FILE ${CMAKE_SOURCE_DIR}/CMake/DESCRIPTION.txt)
|
||||||
|
|
||||||
# This may reduce rpm compatiblity with very old systems.
|
# This may reduce rpm compatiblity with very old systems.
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
set(VERSION_MAJOR 23)
|
set(VERSION_MAJOR 23)
|
||||||
set(VERSION_MINOR 3)
|
set(VERSION_MINOR 5)
|
||||||
set(VERSION_PATCH 3)
|
set(VERSION_PATCH 8)
|
||||||
set(VERSION_COMMIT 0)
|
set(VERSION_COMMIT 0)
|
||||||
|
|
||||||
if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/.git")
|
if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/.git")
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
include("${CMAKE_CURRENT_LIST_DIR}/FlatBuffersTargets.cmake" OPTIONAL)
|
include("${CMAKE_CURRENT_LIST_DIR}/FlatBuffersTargets.cmake" OPTIONAL)
|
||||||
include("${CMAKE_CURRENT_LIST_DIR}/FlatcTargets.cmake" OPTIONAL)
|
include("${CMAKE_CURRENT_LIST_DIR}/FlatcTargets.cmake" OPTIONAL)
|
||||||
include("${CMAKE_CURRENT_LIST_DIR}/FlatBuffersSharedTargets.cmake" OPTIONAL)
|
include("${CMAKE_CURRENT_LIST_DIR}/FlatBuffersSharedTargets.cmake" OPTIONAL)
|
||||||
|
include("${CMAKE_CURRENT_LIST_DIR}/BuildFlatBuffers.cmake" OPTIONAL)
|
||||||
198
CMakeLists.txt
198
CMakeLists.txt
@@ -21,7 +21,7 @@ option(FLATBUFFERS_BUILD_FLATC "Enable the build of the flatbuffers compiler"
|
|||||||
ON)
|
ON)
|
||||||
option(FLATBUFFERS_STATIC_FLATC "Build flatbuffers compiler with -static flag"
|
option(FLATBUFFERS_STATIC_FLATC "Build flatbuffers compiler with -static flag"
|
||||||
OFF)
|
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."
|
option(FLATBUFFERS_BUILD_BENCHMARKS "Enable the build of flatbenchmark."
|
||||||
OFF)
|
OFF)
|
||||||
option(FLATBUFFERS_BUILD_GRPCTEST "Enable the build of grpctest" 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/default_allocator.h
|
||||||
include/flatbuffers/detached_buffer.h
|
include/flatbuffers/detached_buffer.h
|
||||||
include/flatbuffers/code_generator.h
|
include/flatbuffers/code_generator.h
|
||||||
|
include/flatbuffers/file_manager.h
|
||||||
include/flatbuffers/flatbuffer_builder.h
|
include/flatbuffers/flatbuffer_builder.h
|
||||||
include/flatbuffers/flatbuffers.h
|
include/flatbuffers/flatbuffers.h
|
||||||
include/flatbuffers/flexbuffers.h
|
include/flatbuffers/flexbuffers.h
|
||||||
@@ -171,6 +172,9 @@ set(FlatBuffers_Compiler_SRCS
|
|||||||
src/idl_gen_grpc.cpp
|
src/idl_gen_grpc.cpp
|
||||||
src/idl_gen_json_schema.cpp
|
src/idl_gen_json_schema.cpp
|
||||||
src/idl_gen_swift.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/idl_namer.h
|
||||||
src/namer.h
|
src/namer.h
|
||||||
src/flatc.cpp
|
src/flatc.cpp
|
||||||
@@ -232,29 +236,6 @@ set(FlatBuffers_Tests_SRCS
|
|||||||
tests/alignment_test.cpp
|
tests/alignment_test.cpp
|
||||||
include/flatbuffers/code_generators.h
|
include/flatbuffers/code_generators.h
|
||||||
src/code_generators.cpp
|
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
|
set(FlatBuffers_Tests_CPP17_SRCS
|
||||||
@@ -262,32 +243,21 @@ set(FlatBuffers_Tests_CPP17_SRCS
|
|||||||
tests/test_assert.h
|
tests/test_assert.h
|
||||||
tests/test_assert.cpp
|
tests/test_assert.cpp
|
||||||
tests/cpp17/test_cpp17.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
|
set(FlatBuffers_Sample_Binary_SRCS
|
||||||
include/flatbuffers/flatbuffers.h
|
include/flatbuffers/flatbuffers.h
|
||||||
samples/sample_binary.cpp
|
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
|
set(FlatBuffers_Sample_Text_SRCS
|
||||||
${FlatBuffers_Library_SRCS}
|
${FlatBuffers_Library_SRCS}
|
||||||
samples/sample_text.cpp
|
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
|
set(FlatBuffers_Sample_BFBS_SRCS
|
||||||
${FlatBuffers_Library_SRCS}
|
${FlatBuffers_Library_SRCS}
|
||||||
samples/sample_bfbs.cpp
|
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
|
set(FlatBuffers_GRPCTest_SRCS
|
||||||
@@ -303,8 +273,6 @@ set(FlatBuffers_GRPCTest_SRCS
|
|||||||
tests/test_builder.cpp
|
tests/test_builder.cpp
|
||||||
grpc/tests/grpctest.cpp
|
grpc/tests/grpctest.cpp
|
||||||
grpc/tests/message_builder_test.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
|
# TODO(dbaileychess): Figure out how this would now work. I posted a question on
|
||||||
@@ -519,144 +487,65 @@ if(FLATBUFFERS_BUILD_SHAREDLIB)
|
|||||||
endif()
|
endif()
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
# Global list of generated files.
|
function(compile_schema SRC_FBS OPT OUT_GEN_FILE)
|
||||||
# Use the global property to be independent of PARENT_SCOPE.
|
|
||||||
set_property(GLOBAL PROPERTY FBS_GENERATED_OUTPUTS)
|
|
||||||
|
|
||||||
function(get_generated_output generated_files)
|
|
||||||
get_property(tmp GLOBAL PROPERTY FBS_GENERATED_OUTPUTS)
|
|
||||||
set(${generated_files} ${tmp} PARENT_SCOPE)
|
|
||||||
endfunction(get_generated_output)
|
|
||||||
|
|
||||||
function(register_generated_output file_name)
|
|
||||||
get_property(tmp GLOBAL PROPERTY FBS_GENERATED_OUTPUTS)
|
|
||||||
list(APPEND tmp ${file_name})
|
|
||||||
set_property(GLOBAL PROPERTY FBS_GENERATED_OUTPUTS ${tmp})
|
|
||||||
endfunction(register_generated_output)
|
|
||||||
|
|
||||||
function(compile_flatbuffers_schema_to_cpp_opt SRC_FBS OPT)
|
|
||||||
if(FLATBUFFERS_BUILD_LEGACY)
|
|
||||||
set(OPT ${OPT};--cpp-std c++0x)
|
|
||||||
else()
|
|
||||||
# --cpp-std is defined by flatc default settings.
|
|
||||||
endif()
|
|
||||||
message(STATUS "`${SRC_FBS}`: add generation of C++ code with '${OPT}'")
|
|
||||||
get_filename_component(SRC_FBS_DIR ${SRC_FBS} PATH)
|
get_filename_component(SRC_FBS_DIR ${SRC_FBS} PATH)
|
||||||
string(REGEX REPLACE "\\.fbs$" "_generated.h" GEN_HEADER ${SRC_FBS})
|
string(REGEX REPLACE "\\.fbs$" "_generated.h" GEN_HEADER ${SRC_FBS})
|
||||||
add_custom_command(
|
add_custom_command(TARGET flatc POST_BUILD
|
||||||
OUTPUT ${GEN_HEADER}
|
COMMAND "${FLATBUFFERS_FLATC_EXECUTABLE}"
|
||||||
COMMAND "${FLATBUFFERS_FLATC_EXECUTABLE}"
|
${OPT}
|
||||||
--cpp --gen-mutable --gen-object-api --reflect-names
|
-o "${SRC_FBS_DIR}"
|
||||||
--cpp-ptr-type flatbuffers::unique_ptr # Used to test with C++98 STLs
|
"${CMAKE_CURRENT_SOURCE_DIR}/${SRC_FBS}"
|
||||||
${OPT}
|
BYPRODUCTS ${GEN_HEADER}
|
||||||
-I "${CMAKE_CURRENT_SOURCE_DIR}/tests/include_test"
|
COMMENT "flatc generation: `${SRC_FBS}` -> `${GEN_HEADER}`"
|
||||||
-o "${SRC_FBS_DIR}"
|
)
|
||||||
"${CMAKE_CURRENT_SOURCE_DIR}/${SRC_FBS}"
|
set(${OUT_GEN_FILE} ${GEN_HEADER} PARENT_SCOPE)
|
||||||
DEPENDS flatc
|
|
||||||
COMMENT "Run generation: '${GEN_HEADER}'")
|
|
||||||
register_generated_output(${GEN_HEADER})
|
|
||||||
endfunction()
|
endfunction()
|
||||||
|
|
||||||
function(compile_flatbuffers_schema_to_cpp SRC_FBS)
|
function(compile_schema_for_test SRC_FBS OPT)
|
||||||
compile_flatbuffers_schema_to_cpp_opt(${SRC_FBS} "--no-includes;--gen-compare")
|
compile_schema("${SRC_FBS}" "${OPT}" GEN_FILE)
|
||||||
|
target_sources(flattests PRIVATE ${GEN_FILE})
|
||||||
endfunction()
|
endfunction()
|
||||||
|
|
||||||
function(compile_flatbuffers_schema_to_binary SRC_FBS)
|
function(compile_schema_for_samples SRC_FBS OPT)
|
||||||
message(STATUS "`${SRC_FBS}`: add generation of binary (.bfbs) schema")
|
compile_schema("${SRC_FBS}" "${OPT}" GEN_FILE)
|
||||||
get_filename_component(SRC_FBS_DIR ${SRC_FBS} PATH)
|
target_sources(flatsamplebinary PRIVATE ${GEN_FILE})
|
||||||
string(REGEX REPLACE "\\.fbs$" ".bfbs" GEN_BINARY_SCHEMA ${SRC_FBS})
|
target_sources(flatsampletext PRIVATE ${GEN_FILE})
|
||||||
# For details about flags see generate_code.py
|
target_sources(flatsamplebfbs PRIVATE ${GEN_FILE})
|
||||||
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})
|
|
||||||
endfunction()
|
endfunction()
|
||||||
|
|
||||||
if(FLATBUFFERS_BUILD_TESTS)
|
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)
|
include_directories(${CMAKE_CURRENT_BINARY_DIR}/tests)
|
||||||
add_executable(flattests ${FlatBuffers_Tests_SRCS})
|
add_executable(flattests ${FlatBuffers_Tests_SRCS})
|
||||||
target_link_libraries(flattests PRIVATE $<BUILD_INTERFACE:ProjectConfig>)
|
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}")
|
||||||
|
|
||||||
if(FLATBUFFERS_CODE_SANITIZE)
|
if(FLATBUFFERS_CODE_SANITIZE)
|
||||||
add_fsanitize_to_target(flattests ${FLATBUFFERS_CODE_SANITIZE})
|
add_fsanitize_to_target(flattests ${FLATBUFFERS_CODE_SANITIZE})
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
compile_flatbuffers_schema_to_cpp(samples/monster.fbs)
|
|
||||||
compile_flatbuffers_schema_to_binary(samples/monster.fbs)
|
|
||||||
include_directories(${CMAKE_CURRENT_BINARY_DIR}/samples)
|
include_directories(${CMAKE_CURRENT_BINARY_DIR}/samples)
|
||||||
|
|
||||||
add_executable(flatsamplebinary ${FlatBuffers_Sample_Binary_SRCS})
|
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})
|
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})
|
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>)
|
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)
|
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_executable(flattests_cpp17 ${FlatBuffers_Tests_CPP17_SRCS})
|
||||||
add_dependencies(flattests_cpp17 generated_code)
|
|
||||||
target_link_libraries(flattests_cpp17 PRIVATE $<BUILD_INTERFACE:ProjectConfig>)
|
target_link_libraries(flattests_cpp17 PRIVATE $<BUILD_INTERFACE:ProjectConfig>)
|
||||||
target_compile_features(flattests_cpp17 PRIVATE cxx_std_17) # requires cmake 3.8
|
target_compile_features(flattests_cpp17 PRIVATE cxx_std_17) # requires cmake 3.8
|
||||||
|
|
||||||
@@ -681,7 +570,6 @@ if(FLATBUFFERS_BUILD_GRPCTEST)
|
|||||||
find_package(protobuf CONFIG REQUIRED)
|
find_package(protobuf CONFIG REQUIRED)
|
||||||
find_package(gRPC CONFIG REQUIRED)
|
find_package(gRPC CONFIG REQUIRED)
|
||||||
add_executable(grpctest ${FlatBuffers_GRPCTest_SRCS})
|
add_executable(grpctest ${FlatBuffers_GRPCTest_SRCS})
|
||||||
add_dependencies(grpctest generated_code)
|
|
||||||
target_link_libraries(grpctext
|
target_link_libraries(grpctext
|
||||||
PRIVATE
|
PRIVATE
|
||||||
$<BUILD_INTERFACE:ProjectConfig>
|
$<BUILD_INTERFACE:ProjectConfig>
|
||||||
@@ -774,16 +662,6 @@ if(FLATBUFFERS_BUILD_TESTS)
|
|||||||
endif()
|
endif()
|
||||||
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)
|
include(CMake/BuildFlatBuffers.cmake)
|
||||||
|
|
||||||
if(UNIX)
|
if(UNIX)
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
Pod::Spec.new do |s|
|
Pod::Spec.new do |s|
|
||||||
s.name = 'FlatBuffers'
|
s.name = 'FlatBuffers'
|
||||||
s.version = '23.3.3'
|
s.version = '23.5.8'
|
||||||
s.summary = 'FlatBuffers: Memory Efficient Serialization Library'
|
s.summary = 'FlatBuffers: Memory Efficient Serialization Library'
|
||||||
|
|
||||||
s.description = "FlatBuffers is a cross platform serialization library architected for
|
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.**
|
**Go to our [landing page][] to browse our documentation.**
|
||||||
|
|
||||||
## Supported operating systems
|
## Supported operating systems
|
||||||
* Windows
|
- Windows
|
||||||
* macOS
|
- macOS
|
||||||
* Linux
|
- Linux
|
||||||
* Android
|
- Android
|
||||||
* And any others with a recent C++ compiler (C++ 11 and newer)
|
- And any others with a recent C++ compiler (C++ 11 and newer)
|
||||||
|
|
||||||
## Supported programming languages
|
## 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++ - [snapcraft.io](https://snapcraft.io/flatbuffers)
|
||||||
1. C# - [nuget.org](https://www.nuget.org/packages/Google.FlatBuffers)
|
1. C# - [nuget.org](https://www.nuget.org/packages/Google.FlatBuffers)
|
||||||
1. Dart - [pub.dev](https://pub.dev/packages/flat_buffers)
|
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. Java - [Maven](https://search.maven.org/artifact/com.google.flatbuffers/flatbuffers-java)
|
||||||
1. JavaScript - [NPM](https://www.npmjs.com/package/flatbuffers)
|
1. JavaScript - [NPM](https://www.npmjs.com/package/flatbuffers)
|
||||||
1. Kotlin
|
1. Kotlin
|
||||||
1. Lobster
|
1. Lobster
|
||||||
1. Lua
|
1. Lua
|
||||||
1. PHP
|
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. Rust - [crates.io](https://crates.io/crates/flatbuffers)
|
||||||
1. Swift - [swiftpackageindex](https://swiftpackageindex.com/google/flatbuffers)
|
1. Swift - [swiftpackageindex](https://swiftpackageindex.com/google/flatbuffers)
|
||||||
1. TypeScript - [NPM](https://www.npmjs.com/package/flatbuffers)
|
1. TypeScript - [NPM](https://www.npmjs.com/package/flatbuffers)
|
||||||
84
WORKSPACE
84
WORKSPACE
@@ -1,6 +1,6 @@
|
|||||||
workspace(name = "com_github_google_flatbuffers")
|
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(
|
http_archive(
|
||||||
name = "platforms",
|
name = "platforms",
|
||||||
@@ -76,30 +76,80 @@ load("@com_github_grpc_grpc//bazel:grpc_extra_deps.bzl", "grpc_extra_deps")
|
|||||||
grpc_extra_deps()
|
grpc_extra_deps()
|
||||||
|
|
||||||
# rules_go from https://github.com/bazelbuild/rules_go/releases/tag/v0.34.0
|
# rules_go from https://github.com/bazelbuild/rules_go/releases/tag/v0.34.0
|
||||||
|
|
||||||
http_archive(
|
http_archive(
|
||||||
name = "build_bazel_rules_nodejs",
|
name = "aspect_rules_js",
|
||||||
sha256 = "965ee2492a2b087cf9e0f2ca472aeaf1be2eb650e0cfbddf514b9a7d3ea4b02a",
|
sha256 = "124ed29fb0b3d0cba5b44f8f8e07897cf61b34e35e33b1f83d1a943dfd91b193",
|
||||||
urls = ["https://github.com/bazelbuild/rules_nodejs/releases/download/5.2.0/rules_nodejs-5.2.0.tar.gz"],
|
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",
|
name = "npm",
|
||||||
exports_directories_only = False,
|
npmrc = "//:.npmrc",
|
||||||
# Unfreeze to add/remove packages.
|
pnpm_lock = "//:pnpm-lock.yaml",
|
||||||
frozen_lockfile = False,
|
# Set this to True when the lock file needs to be updated, commit the
|
||||||
package_json = "//:package.json",
|
# changes, then set to False again.
|
||||||
symlink_node_modules = False,
|
update_pnpm_lock = False,
|
||||||
yarn_lock = "//:yarn.lock",
|
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
|
return if(o != 0) bb.getShort(o + bb_pos).toUShort() else 0u
|
||||||
}
|
}
|
||||||
companion object {
|
companion object {
|
||||||
fun validateVersion() = Constants.FLATBUFFERS_23_3_3()
|
fun validateVersion() = Constants.FLATBUFFERS_23_5_8()
|
||||||
fun getRootAsAnimal(_bb: ByteBuffer): Animal = getRootAsAnimal(_bb, Animal())
|
fun getRootAsAnimal(_bb: ByteBuffer): Animal = getRootAsAnimal(_bb, Animal())
|
||||||
fun getRootAsAnimal(_bb: ByteBuffer, obj: Animal): Animal {
|
fun getRootAsAnimal(_bb: ByteBuffer, obj: Animal): Animal {
|
||||||
_bb.order(ByteOrder.LITTLE_ENDIAN)
|
_bb.order(ByteOrder.LITTLE_ENDIAN)
|
||||||
|
|||||||
@@ -48,7 +48,10 @@ def flatbuffer_library_public(
|
|||||||
restricted_to = None,
|
restricted_to = None,
|
||||||
target_compatible_with = None,
|
target_compatible_with = None,
|
||||||
flatc_path = "@com_github_google_flatbuffers//:flatc",
|
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.
|
"""Generates code files for reading/writing the given flatbuffers in the requested language using the public compiler.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
@@ -73,6 +76,11 @@ def flatbuffer_library_public(
|
|||||||
to use.
|
to use.
|
||||||
flatc_path: Bazel target corresponding to the flatc compiler to use.
|
flatc_path: Bazel target corresponding to the flatc compiler to use.
|
||||||
output_to_bindir: Passed to genrule for output to bin directory.
|
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
|
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 = default_include_paths(flatc_path)
|
||||||
include_paths_cmd = ["-I %s" % (s) for s in include_paths]
|
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
|
# '$(@D)' when given a single source target will give the appropriate
|
||||||
# directory. Appending 'out_prefix' is only necessary when given a build
|
# directory. Appending 'out_prefix' is only necessary when given a build
|
||||||
# target with multiple sources.
|
# target with multiple sources.
|
||||||
@@ -92,7 +102,7 @@ def flatbuffer_library_public(
|
|||||||
genrule_cmd = " ".join([
|
genrule_cmd = " ".join([
|
||||||
"SRCS=($(SRCS));",
|
"SRCS=($(SRCS));",
|
||||||
"for f in $${SRCS[@]:0:%s}; do" % len(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(include_paths_cmd),
|
||||||
" ".join(flatc_args),
|
" ".join(flatc_args),
|
||||||
language_flag,
|
language_flag,
|
||||||
@@ -105,12 +115,13 @@ def flatbuffer_library_public(
|
|||||||
srcs = srcs + includes,
|
srcs = srcs + includes,
|
||||||
outs = outs,
|
outs = outs,
|
||||||
output_to_bindir = output_to_bindir,
|
output_to_bindir = output_to_bindir,
|
||||||
tools = [flatc_path],
|
tools = (tools or []) + [flatc_path],
|
||||||
cmd = genrule_cmd,
|
cmd = genrule_cmd,
|
||||||
compatible_with = compatible_with,
|
compatible_with = compatible_with,
|
||||||
target_compatible_with = target_compatible_with,
|
target_compatible_with = target_compatible_with,
|
||||||
restricted_to = restricted_to,
|
restricted_to = restricted_to,
|
||||||
message = "Generating flatbuffer files for %s:" % (name),
|
message = "Generating flatbuffer files for %s:" % (name),
|
||||||
|
**kwargs
|
||||||
)
|
)
|
||||||
if reflection_name:
|
if reflection_name:
|
||||||
reflection_genrule_cmd = " ".join([
|
reflection_genrule_cmd = " ".join([
|
||||||
@@ -154,6 +165,7 @@ def flatbuffer_cc_library(
|
|||||||
name,
|
name,
|
||||||
srcs,
|
srcs,
|
||||||
srcs_filegroup_name = "",
|
srcs_filegroup_name = "",
|
||||||
|
outs = [],
|
||||||
out_prefix = "",
|
out_prefix = "",
|
||||||
deps = [],
|
deps = [],
|
||||||
includes = [],
|
includes = [],
|
||||||
@@ -174,6 +186,7 @@ def flatbuffer_cc_library(
|
|||||||
srcs_filegroup_name: Name of the output filegroup that holds srcs. Pass this
|
srcs_filegroup_name: Name of the output filegroup that holds srcs. Pass this
|
||||||
filegroup into the `includes` parameter of any other
|
filegroup into the `includes` parameter of any other
|
||||||
flatbuffer_cc_library that depends on this one's schemas.
|
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
|
out_prefix: Prepend this path to the front of all generated files. Usually
|
||||||
is a directory name.
|
is a directory name.
|
||||||
deps: Optional, list of other flatbuffer_cc_library's to depend on. Cannot be specified
|
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(
|
flatbuffer_library_public(
|
||||||
name = srcs_lib,
|
name = srcs_lib,
|
||||||
srcs = srcs,
|
srcs = srcs,
|
||||||
outs = output_headers,
|
outs = outs + output_headers,
|
||||||
language_flag = "-c",
|
language_flag = "-c",
|
||||||
out_prefix = out_prefix,
|
out_prefix = out_prefix,
|
||||||
includes = includes,
|
includes = includes,
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ class FlatbuffersConan(ConanFile):
|
|||||||
options = {"shared": [True, False], "fPIC": [True, False]}
|
options = {"shared": [True, False], "fPIC": [True, False]}
|
||||||
default_options = {"shared": False, "fPIC": True}
|
default_options = {"shared": False, "fPIC": True}
|
||||||
generators = "cmake"
|
generators = "cmake"
|
||||||
exports = "LICENSE.txt"
|
exports = "LICENSE"
|
||||||
exports_sources = ["CMake/*", "include/*", "src/*", "grpc/*", "CMakeLists.txt", "conan/CMakeLists.txt"]
|
exports_sources = ["CMake/*", "include/*", "src/*", "grpc/*", "CMakeLists.txt", "conan/CMakeLists.txt"]
|
||||||
|
|
||||||
def source(self):
|
def source(self):
|
||||||
@@ -56,7 +56,7 @@ class FlatbuffersConan(ConanFile):
|
|||||||
"""
|
"""
|
||||||
cmake = self.configure_cmake()
|
cmake = self.configure_cmake()
|
||||||
cmake.install()
|
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="FindFlatBuffers.cmake", dst=os.path.join("lib", "cmake", "flatbuffers"), src="CMake")
|
||||||
self.copy(pattern="flathash*", dst="bin", src="bin")
|
self.copy(pattern="flathash*", dst="bin", src="bin")
|
||||||
self.copy(pattern="flatc*", dst="bin", src="bin")
|
self.copy(pattern="flatc*", dst="bin", src="bin")
|
||||||
|
|||||||
@@ -304,7 +304,7 @@ class Builder {
|
|||||||
assert(_inVTable);
|
assert(_inVTable);
|
||||||
// Prepare for writing the VTable.
|
// Prepare for writing the VTable.
|
||||||
_prepare(_sizeofInt32, 1);
|
_prepare(_sizeofInt32, 1);
|
||||||
var tableTail = _tail;
|
final tableTail = _tail;
|
||||||
// Prepare the size of the current table.
|
// Prepare the size of the current table.
|
||||||
final currentVTable = _currentVTable!;
|
final currentVTable = _currentVTable!;
|
||||||
currentVTable.tableSize = tableTail - _currentTableEndTail;
|
currentVTable.tableSize = tableTail - _currentTableEndTail;
|
||||||
@@ -514,7 +514,7 @@ class Builder {
|
|||||||
var tail = _tail;
|
var tail = _tail;
|
||||||
_setUint32AtTail(tail, values.length);
|
_setUint32AtTail(tail, values.length);
|
||||||
tail -= _sizeofUint32;
|
tail -= _sizeofUint32;
|
||||||
for (var value in values) {
|
for (final value in values) {
|
||||||
_setUint32AtTail(tail, tail - value);
|
_setUint32AtTail(tail, tail - value);
|
||||||
tail -= _sizeofUint32;
|
tail -= _sizeofUint32;
|
||||||
}
|
}
|
||||||
@@ -529,7 +529,7 @@ class Builder {
|
|||||||
var tail = _tail;
|
var tail = _tail;
|
||||||
_setUint32AtTail(tail, values.length);
|
_setUint32AtTail(tail, values.length);
|
||||||
tail -= _sizeofUint32;
|
tail -= _sizeofUint32;
|
||||||
for (var value in values) {
|
for (final value in values) {
|
||||||
_setFloat64AtTail(tail, value);
|
_setFloat64AtTail(tail, value);
|
||||||
tail -= _sizeofFloat64;
|
tail -= _sizeofFloat64;
|
||||||
}
|
}
|
||||||
@@ -544,7 +544,7 @@ class Builder {
|
|||||||
var tail = _tail;
|
var tail = _tail;
|
||||||
_setUint32AtTail(tail, values.length);
|
_setUint32AtTail(tail, values.length);
|
||||||
tail -= _sizeofUint32;
|
tail -= _sizeofUint32;
|
||||||
for (var value in values) {
|
for (final value in values) {
|
||||||
_setFloat32AtTail(tail, value);
|
_setFloat32AtTail(tail, value);
|
||||||
tail -= _sizeofFloat32;
|
tail -= _sizeofFloat32;
|
||||||
}
|
}
|
||||||
@@ -559,7 +559,7 @@ class Builder {
|
|||||||
var tail = _tail;
|
var tail = _tail;
|
||||||
_setUint32AtTail(tail, values.length);
|
_setUint32AtTail(tail, values.length);
|
||||||
tail -= _sizeofUint32;
|
tail -= _sizeofUint32;
|
||||||
for (var value in values) {
|
for (final value in values) {
|
||||||
_setInt64AtTail(tail, value);
|
_setInt64AtTail(tail, value);
|
||||||
tail -= _sizeofInt64;
|
tail -= _sizeofInt64;
|
||||||
}
|
}
|
||||||
@@ -574,7 +574,7 @@ class Builder {
|
|||||||
var tail = _tail;
|
var tail = _tail;
|
||||||
_setUint32AtTail(tail, values.length);
|
_setUint32AtTail(tail, values.length);
|
||||||
tail -= _sizeofUint32;
|
tail -= _sizeofUint32;
|
||||||
for (var value in values) {
|
for (final value in values) {
|
||||||
_setUint64AtTail(tail, value);
|
_setUint64AtTail(tail, value);
|
||||||
tail -= _sizeofUint64;
|
tail -= _sizeofUint64;
|
||||||
}
|
}
|
||||||
@@ -589,7 +589,7 @@ class Builder {
|
|||||||
var tail = _tail;
|
var tail = _tail;
|
||||||
_setUint32AtTail(tail, values.length);
|
_setUint32AtTail(tail, values.length);
|
||||||
tail -= _sizeofUint32;
|
tail -= _sizeofUint32;
|
||||||
for (var value in values) {
|
for (final value in values) {
|
||||||
_setInt32AtTail(tail, value);
|
_setInt32AtTail(tail, value);
|
||||||
tail -= _sizeofInt32;
|
tail -= _sizeofInt32;
|
||||||
}
|
}
|
||||||
@@ -604,7 +604,7 @@ class Builder {
|
|||||||
var tail = _tail;
|
var tail = _tail;
|
||||||
_setUint32AtTail(tail, values.length);
|
_setUint32AtTail(tail, values.length);
|
||||||
tail -= _sizeofUint32;
|
tail -= _sizeofUint32;
|
||||||
for (var value in values) {
|
for (final value in values) {
|
||||||
_setUint32AtTail(tail, value);
|
_setUint32AtTail(tail, value);
|
||||||
tail -= _sizeofUint32;
|
tail -= _sizeofUint32;
|
||||||
}
|
}
|
||||||
@@ -619,7 +619,7 @@ class Builder {
|
|||||||
var tail = _tail;
|
var tail = _tail;
|
||||||
_setUint32AtTail(tail, values.length);
|
_setUint32AtTail(tail, values.length);
|
||||||
tail -= _sizeofUint32;
|
tail -= _sizeofUint32;
|
||||||
for (var value in values) {
|
for (final value in values) {
|
||||||
_setInt16AtTail(tail, value);
|
_setInt16AtTail(tail, value);
|
||||||
tail -= _sizeofInt16;
|
tail -= _sizeofInt16;
|
||||||
}
|
}
|
||||||
@@ -634,7 +634,7 @@ class Builder {
|
|||||||
var tail = _tail;
|
var tail = _tail;
|
||||||
_setUint32AtTail(tail, values.length);
|
_setUint32AtTail(tail, values.length);
|
||||||
tail -= _sizeofUint32;
|
tail -= _sizeofUint32;
|
||||||
for (var value in values) {
|
for (final value in values) {
|
||||||
_setUint16AtTail(tail, value);
|
_setUint16AtTail(tail, value);
|
||||||
tail -= _sizeofUint16;
|
tail -= _sizeofUint16;
|
||||||
}
|
}
|
||||||
@@ -669,7 +669,7 @@ class Builder {
|
|||||||
var tail = _tail;
|
var tail = _tail;
|
||||||
_setUint32AtTail(tail, values.length);
|
_setUint32AtTail(tail, values.length);
|
||||||
tail -= _sizeofUint32;
|
tail -= _sizeofUint32;
|
||||||
for (var value in values) {
|
for (final value in values) {
|
||||||
_setUint8AtTail(tail, value);
|
_setUint8AtTail(tail, value);
|
||||||
tail -= _sizeofUint8;
|
tail -= _sizeofUint8;
|
||||||
}
|
}
|
||||||
@@ -777,17 +777,17 @@ class Builder {
|
|||||||
_maxAlign = size;
|
_maxAlign = size;
|
||||||
}
|
}
|
||||||
// Prepare amount of required space.
|
// Prepare amount of required space.
|
||||||
var dataSize = size * count + additionalBytes;
|
final dataSize = size * count + additionalBytes;
|
||||||
var alignDelta = (-(_tail + dataSize)) & (size - 1);
|
final alignDelta = (-(_tail + dataSize)) & (size - 1);
|
||||||
var bufSize = alignDelta + dataSize;
|
final bufSize = alignDelta + dataSize;
|
||||||
// Ensure that we have the required amount of space.
|
// Ensure that we have the required amount of space.
|
||||||
{
|
{
|
||||||
var oldCapacity = _buf.lengthInBytes;
|
final oldCapacity = _buf.lengthInBytes;
|
||||||
if (_tail + bufSize > oldCapacity) {
|
if (_tail + bufSize > oldCapacity) {
|
||||||
var desiredNewCapacity = (oldCapacity + bufSize) * 2;
|
final desiredNewCapacity = (oldCapacity + bufSize) * 2;
|
||||||
var deltaCapacity = desiredNewCapacity - oldCapacity;
|
var deltaCapacity = desiredNewCapacity - oldCapacity;
|
||||||
deltaCapacity += (-deltaCapacity) & (_maxAlign - 1);
|
deltaCapacity += (-deltaCapacity) & (_maxAlign - 1);
|
||||||
var newCapacity = oldCapacity + deltaCapacity;
|
final newCapacity = oldCapacity + deltaCapacity;
|
||||||
_buf = _allocator.resize(_buf, newCapacity, _tail, 0);
|
_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].
|
/// Read the value of the given [field] in the given [object].
|
||||||
@pragma('vm:prefer-inline')
|
@pragma('vm:prefer-inline')
|
||||||
T vTableGet(BufferContext object, int offset, int field, T defaultValue) {
|
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);
|
return fieldOffset == 0 ? defaultValue : read(object, offset + fieldOffset);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Read the value of the given [field] in the given [object].
|
/// Read the value of the given [field] in the given [object].
|
||||||
@pragma('vm:prefer-inline')
|
@pragma('vm:prefer-inline')
|
||||||
T? vTableGetNullable(BufferContext object, int offset, int field) {
|
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);
|
return fieldOffset == 0 ? null : read(object, offset + fieldOffset);
|
||||||
}
|
}
|
||||||
|
|
||||||
@pragma('vm:prefer-inline')
|
@pragma('vm:prefer-inline')
|
||||||
int _vTableFieldOffset(BufferContext object, int offset, int field) {
|
int _vTableFieldOffset(BufferContext object, int offset, int field) {
|
||||||
var vTableSOffset = object._getInt32(offset);
|
final vTableSOffset = object._getInt32(offset);
|
||||||
var vTableOffset = offset - vTableSOffset;
|
final vTableOffset = offset - vTableSOffset;
|
||||||
var vTableSize = object._getUint16(vTableOffset);
|
final vTableSize = object._getUint16(vTableOffset);
|
||||||
if (field >= vTableSize) return 0;
|
if (field >= vTableSize) return 0;
|
||||||
return object._getUint16(vTableOffset + field);
|
return object._getUint16(vTableOffset + field);
|
||||||
}
|
}
|
||||||
@@ -1057,9 +1057,9 @@ class StringReader extends Reader<String> {
|
|||||||
@override
|
@override
|
||||||
@pragma('vm:prefer-inline')
|
@pragma('vm:prefer-inline')
|
||||||
String read(BufferContext bc, int offset) {
|
String read(BufferContext bc, int offset) {
|
||||||
var strOffset = bc.derefObject(offset);
|
final strOffset = bc.derefObject(offset);
|
||||||
var length = bc._getUint32(strOffset);
|
final length = bc._getUint32(strOffset);
|
||||||
var bytes = bc._asUint8List(strOffset + _sizeofUint32, length);
|
final bytes = bc._asUint8List(strOffset + _sizeofUint32, length);
|
||||||
if (asciiOptimization && _isLatin(bytes)) {
|
if (asciiOptimization && _isLatin(bytes)) {
|
||||||
return String.fromCharCodes(bytes);
|
return String.fromCharCodes(bytes);
|
||||||
}
|
}
|
||||||
@@ -1068,7 +1068,7 @@ class StringReader extends Reader<String> {
|
|||||||
|
|
||||||
@pragma('vm:prefer-inline')
|
@pragma('vm:prefer-inline')
|
||||||
static bool _isLatin(Uint8List bytes) {
|
static bool _isLatin(Uint8List bytes) {
|
||||||
var length = bytes.length;
|
final length = bytes.length;
|
||||||
for (var i = 0; i < length; i++) {
|
for (var i = 0; i < length; i++) {
|
||||||
if (bytes[i] > 127) {
|
if (bytes[i] > 127) {
|
||||||
return false;
|
return false;
|
||||||
@@ -1104,7 +1104,7 @@ abstract class TableReader<T> extends Reader<T> {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
T read(BufferContext bc, int offset) {
|
T read(BufferContext bc, int offset) {
|
||||||
var objectOffset = bc.derefObject(offset);
|
final objectOffset = bc.derefObject(offset);
|
||||||
return createObject(bc, objectOffset);
|
return createObject(bc, objectOffset);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
name: flat_buffers
|
name: flat_buffers
|
||||||
version: 23.3.3
|
version: 23.5.8
|
||||||
description: FlatBuffers reading and writing library for Dart. Based on original work by Konstantin Scheglov and Paul Berry of the Dart SDK team.
|
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
|
homepage: https://github.com/google/flatbuffers
|
||||||
documentation: https://google.github.io/flatbuffers/index.html
|
documentation: https://google.github.io/flatbuffers/index.html
|
||||||
|
|||||||
@@ -59,6 +59,8 @@ struct Vec3 (force_align: 8) {
|
|||||||
test3:Test;
|
test3:Test;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Stats for monster
|
||||||
|
|
||||||
struct Ability {
|
struct Ability {
|
||||||
id:uint(key);
|
id:uint(key);
|
||||||
distance:uint;
|
distance:uint;
|
||||||
|
|||||||
@@ -142,6 +142,47 @@ To use it:
|
|||||||
`ByKey` only works if the vector has been sorted, it will
|
`ByKey` only works if the vector has been sorted, it will
|
||||||
likely not find elements if it hasn't been sorted.
|
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
|
## Text parsing
|
||||||
|
|
||||||
There currently is no support for parsing text (Schema's and JSON) directly
|
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.
|
performance-critical applications.
|
||||||
|
|
||||||
It is available as Open Source on [GitHub](http://github.com/google/flatbuffers)
|
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?
|
## Why use FlatBuffers?
|
||||||
|
|
||||||
|
|||||||
@@ -529,7 +529,7 @@ The first step is to import/include the library, generated files, etc.
|
|||||||
#[allow(dead_code, unused_imports)]
|
#[allow(dead_code, unused_imports)]
|
||||||
#[path = "./monster_generated.rs"]
|
#[path = "./monster_generated.rs"]
|
||||||
mod monster_generated;
|
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,
|
Color, Equipment,
|
||||||
Monster, MonsterArgs,
|
Monster, MonsterArgs,
|
||||||
Vec3,
|
Vec3,
|
||||||
@@ -652,7 +652,7 @@ which will grow automatically if needed:
|
|||||||
~~~{.rs}
|
~~~{.rs}
|
||||||
// Build up a serialized buffer algorithmically.
|
// Build up a serialized buffer algorithmically.
|
||||||
// Initialize it with a capacity of 1024 bytes.
|
// 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>
|
||||||
<div class="language-swift">
|
<div class="language-swift">
|
||||||
@@ -2309,7 +2309,7 @@ import './monster_my_game.sample_generated.dart' as myGame;
|
|||||||
#[allow(dead_code, unused_imports)]
|
#[allow(dead_code, unused_imports)]
|
||||||
#[path = "./monster_generated.rs"]
|
#[path = "./monster_generated.rs"]
|
||||||
mod monster_generated;
|
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,
|
Color, Equipment,
|
||||||
Monster, MonsterArgs,
|
Monster, MonsterArgs,
|
||||||
Vec3,
|
Vec3,
|
||||||
@@ -2465,7 +2465,7 @@ myGame.Monster monster = new myGame.Monster(data);
|
|||||||
let buf = /* the data you just read, in a &[u8] */
|
let buf = /* the data you just read, in a &[u8] */
|
||||||
|
|
||||||
// Get an accessor to the root object inside the buffer.
|
// 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>
|
||||||
<div class="language-swift">
|
<div class="language-swift">
|
||||||
|
|||||||
@@ -779,7 +779,8 @@ INPUT = "FlatBuffers.md" \
|
|||||||
"../../python/flatbuffers/builder.py" \
|
"../../python/flatbuffers/builder.py" \
|
||||||
"../../js/flatbuffers.js" \
|
"../../js/flatbuffers.js" \
|
||||||
"../../php/FlatbufferBuilder.php" \
|
"../../php/FlatbufferBuilder.php" \
|
||||||
"../../net/FlatBuffers/FlatBufferBuilder.cs" \
|
"../../net/FlatBuffers/FlatBufferBuilder.cs"
|
||||||
|
"../../net/FlatBuffers/FlatBufferVerify.cs" \
|
||||||
"../../include/flatbuffers/flatbuffers.h" \
|
"../../include/flatbuffers/flatbuffers.h" \
|
||||||
"../../go/builder.go" \
|
"../../go/builder.go" \
|
||||||
"../../rust/flatbuffers/src/builder.rs"
|
"../../rust/flatbuffers/src/builder.rs"
|
||||||
|
|||||||
@@ -12,8 +12,13 @@ type WarriorT struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (t *WarriorT) Pack(builder *flatbuffers.Builder) flatbuffers.UOffsetT {
|
func (t *WarriorT) Pack(builder *flatbuffers.Builder) flatbuffers.UOffsetT {
|
||||||
if t == nil { return 0 }
|
if t == nil {
|
||||||
nameOffset := builder.CreateString(t.Name)
|
return 0
|
||||||
|
}
|
||||||
|
nameOffset := flatbuffers.UOffsetT(0)
|
||||||
|
if t.Name != "" {
|
||||||
|
nameOffset = builder.CreateString(t.Name)
|
||||||
|
}
|
||||||
WarriorStart(builder)
|
WarriorStart(builder)
|
||||||
WarriorAddName(builder, nameOffset)
|
WarriorAddName(builder, nameOffset)
|
||||||
WarriorAddHp(builder, t.Hp)
|
WarriorAddHp(builder, t.Hp)
|
||||||
@@ -26,7 +31,9 @@ func (rcv *Warrior) UnPackTo(t *WarriorT) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (rcv *Warrior) UnPack() *WarriorT {
|
func (rcv *Warrior) UnPack() *WarriorT {
|
||||||
if rcv == nil { return nil }
|
if rcv == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
t := &WarriorT{}
|
t := &WarriorT{}
|
||||||
rcv.UnPackTo(t)
|
rcv.UnPackTo(t)
|
||||||
return t
|
return t
|
||||||
|
|||||||
@@ -13,7 +13,9 @@ type RequestT struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (t *RequestT) Pack(builder *flatbuffers.Builder) flatbuffers.UOffsetT {
|
func (t *RequestT) Pack(builder *flatbuffers.Builder) flatbuffers.UOffsetT {
|
||||||
if t == nil { return 0 }
|
if t == nil {
|
||||||
|
return 0
|
||||||
|
}
|
||||||
playerOffset := t.Player.Pack(builder)
|
playerOffset := t.Player.Pack(builder)
|
||||||
RequestStart(builder)
|
RequestStart(builder)
|
||||||
RequestAddPlayer(builder, playerOffset)
|
RequestAddPlayer(builder, playerOffset)
|
||||||
@@ -25,7 +27,9 @@ func (rcv *Request) UnPackTo(t *RequestT) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (rcv *Request) UnPack() *RequestT {
|
func (rcv *Request) UnPack() *RequestT {
|
||||||
if rcv == nil { return nil }
|
if rcv == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
t := &RequestT{}
|
t := &RequestT{}
|
||||||
rcv.UnPackTo(t)
|
rcv.UnPackTo(t)
|
||||||
return t
|
return t
|
||||||
|
|||||||
@@ -13,7 +13,9 @@ type ResponseT struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (t *ResponseT) Pack(builder *flatbuffers.Builder) flatbuffers.UOffsetT {
|
func (t *ResponseT) Pack(builder *flatbuffers.Builder) flatbuffers.UOffsetT {
|
||||||
if t == nil { return 0 }
|
if t == nil {
|
||||||
|
return 0
|
||||||
|
}
|
||||||
playerOffset := t.Player.Pack(builder)
|
playerOffset := t.Player.Pack(builder)
|
||||||
ResponseStart(builder)
|
ResponseStart(builder)
|
||||||
ResponseAddPlayer(builder, playerOffset)
|
ResponseAddPlayer(builder, playerOffset)
|
||||||
@@ -25,7 +27,9 @@ func (rcv *Response) UnPackTo(t *ResponseT) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (rcv *Response) UnPack() *ResponseT {
|
func (rcv *Response) UnPack() *ResponseT {
|
||||||
if rcv == nil { return nil }
|
if rcv == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
t := &ResponseT{}
|
t := &ResponseT{}
|
||||||
rcv.UnPackTo(t)
|
rcv.UnPackTo(t)
|
||||||
return 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 {
|
func GetIndirectOffset(buf []byte, offset UOffsetT) UOffsetT {
|
||||||
return offset + GetUOffsetT(buf[offset:])
|
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 == 3 &&
|
||||||
|
FLATBUFFERS_VERSION_REVISION == 3,
|
||||||
|
"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_8(); }
|
||||||
|
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_8(); }
|
||||||
|
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_8(); }
|
||||||
|
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_8(); }
|
||||||
|
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_8()
|
||||||
|
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_8()
|
||||||
|
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_8() }
|
||||||
|
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_8() }
|
||||||
|
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
|
return x
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func FinishHelloReplyBuffer(builder *flatbuffers.Builder, offset flatbuffers.UOffsetT) {
|
||||||
|
builder.Finish(offset)
|
||||||
|
}
|
||||||
|
|
||||||
func GetSizePrefixedRootAsHelloReply(buf []byte, offset flatbuffers.UOffsetT) *HelloReply {
|
func GetSizePrefixedRootAsHelloReply(buf []byte, offset flatbuffers.UOffsetT) *HelloReply {
|
||||||
n := flatbuffers.GetUOffsetT(buf[offset+flatbuffers.SizeUint32:])
|
n := flatbuffers.GetUOffsetT(buf[offset+flatbuffers.SizeUint32:])
|
||||||
x := &HelloReply{}
|
x := &HelloReply{}
|
||||||
@@ -24,6 +28,10 @@ func GetSizePrefixedRootAsHelloReply(buf []byte, offset flatbuffers.UOffsetT) *H
|
|||||||
return x
|
return x
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func FinishSizePrefixedHelloReplyBuffer(builder *flatbuffers.Builder, offset flatbuffers.UOffsetT) {
|
||||||
|
builder.FinishSizePrefixed(offset)
|
||||||
|
}
|
||||||
|
|
||||||
func (rcv *HelloReply) Init(buf []byte, i flatbuffers.UOffsetT) {
|
func (rcv *HelloReply) Init(buf []byte, i flatbuffers.UOffsetT) {
|
||||||
rcv._tab.Bytes = buf
|
rcv._tab.Bytes = buf
|
||||||
rcv._tab.Pos = i
|
rcv._tab.Pos = i
|
||||||
|
|||||||
@@ -17,6 +17,10 @@ func GetRootAsHelloRequest(buf []byte, offset flatbuffers.UOffsetT) *HelloReques
|
|||||||
return x
|
return x
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func FinishHelloRequestBuffer(builder *flatbuffers.Builder, offset flatbuffers.UOffsetT) {
|
||||||
|
builder.Finish(offset)
|
||||||
|
}
|
||||||
|
|
||||||
func GetSizePrefixedRootAsHelloRequest(buf []byte, offset flatbuffers.UOffsetT) *HelloRequest {
|
func GetSizePrefixedRootAsHelloRequest(buf []byte, offset flatbuffers.UOffsetT) *HelloRequest {
|
||||||
n := flatbuffers.GetUOffsetT(buf[offset+flatbuffers.SizeUint32:])
|
n := flatbuffers.GetUOffsetT(buf[offset+flatbuffers.SizeUint32:])
|
||||||
x := &HelloRequest{}
|
x := &HelloRequest{}
|
||||||
@@ -24,6 +28,10 @@ func GetSizePrefixedRootAsHelloRequest(buf []byte, offset flatbuffers.UOffsetT)
|
|||||||
return x
|
return x
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func FinishSizePrefixedHelloRequestBuffer(builder *flatbuffers.Builder, offset flatbuffers.UOffsetT) {
|
||||||
|
builder.FinishSizePrefixed(offset)
|
||||||
|
}
|
||||||
|
|
||||||
func (rcv *HelloRequest) Init(buf []byte, i flatbuffers.UOffsetT) {
|
func (rcv *HelloRequest) Init(buf []byte, i flatbuffers.UOffsetT) {
|
||||||
rcv._tab.Bytes = buf
|
rcv._tab.Bytes = buf
|
||||||
rcv._tab.Pos = i
|
rcv._tab.Pos = i
|
||||||
|
|||||||
@@ -31,12 +31,20 @@ class HelloReply(object):
|
|||||||
return self._tab.String(o + self._tab.Pos)
|
return self._tab.String(o + self._tab.Pos)
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def HelloReplyStart(builder): builder.StartObject(1)
|
def HelloReplyStart(builder):
|
||||||
|
builder.StartObject(1)
|
||||||
|
|
||||||
def Start(builder):
|
def Start(builder):
|
||||||
return HelloReplyStart(builder)
|
HelloReplyStart(builder)
|
||||||
def HelloReplyAddMessage(builder, message): builder.PrependUOffsetTRelativeSlot(0, flatbuffers.number_types.UOffsetTFlags.py_type(message), 0)
|
|
||||||
def AddMessage(builder, message):
|
def HelloReplyAddMessage(builder, message):
|
||||||
return HelloReplyAddMessage(builder, message)
|
builder.PrependUOffsetTRelativeSlot(0, flatbuffers.number_types.UOffsetTFlags.py_type(message), 0)
|
||||||
def HelloReplyEnd(builder): return builder.EndObject()
|
|
||||||
|
def AddMessage(builder: flatbuffers.Builder, message: int):
|
||||||
|
HelloReplyAddMessage(builder, message)
|
||||||
|
|
||||||
|
def HelloReplyEnd(builder):
|
||||||
|
return builder.EndObject()
|
||||||
|
|
||||||
def End(builder):
|
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 self._tab.String(o + self._tab.Pos)
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def HelloRequestStart(builder): builder.StartObject(1)
|
def HelloRequestStart(builder):
|
||||||
|
builder.StartObject(1)
|
||||||
|
|
||||||
def Start(builder):
|
def Start(builder):
|
||||||
return HelloRequestStart(builder)
|
HelloRequestStart(builder)
|
||||||
def HelloRequestAddName(builder, name): builder.PrependUOffsetTRelativeSlot(0, flatbuffers.number_types.UOffsetTFlags.py_type(name), 0)
|
|
||||||
def AddName(builder, name):
|
def HelloRequestAddName(builder, name):
|
||||||
return HelloRequestAddName(builder, name)
|
builder.PrependUOffsetTRelativeSlot(0, flatbuffers.number_types.UOffsetTFlags.py_type(name), 0)
|
||||||
def HelloRequestEnd(builder): return builder.EndObject()
|
|
||||||
|
def AddName(builder: flatbuffers.Builder, name: int):
|
||||||
|
HelloRequestAddName(builder, name)
|
||||||
|
|
||||||
|
def HelloRequestEnd(builder):
|
||||||
|
return builder.EndObject()
|
||||||
|
|
||||||
def End(builder):
|
def End(builder):
|
||||||
return HelloRequestEnd(builder)
|
return HelloRequestEnd(builder)
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import FlatBuffers
|
|||||||
|
|
||||||
public struct models_HelloReply: FlatBufferObject, Verifiable {
|
public struct models_HelloReply: FlatBufferObject, Verifiable {
|
||||||
|
|
||||||
static func validateVersion() { FlatBuffersVersion_23_3_3() }
|
static func validateVersion() { FlatBuffersVersion_23_5_8() }
|
||||||
public var __buffer: ByteBuffer! { return _accessor.bb }
|
public var __buffer: ByteBuffer! { return _accessor.bb }
|
||||||
private var _accessor: Table
|
private var _accessor: Table
|
||||||
|
|
||||||
@@ -53,7 +53,7 @@ extension models_HelloReply: Encodable {
|
|||||||
|
|
||||||
public struct models_HelloRequest: FlatBufferObject, Verifiable {
|
public struct models_HelloRequest: FlatBufferObject, Verifiable {
|
||||||
|
|
||||||
static func validateVersion() { FlatBuffersVersion_23_3_3() }
|
static func validateVersion() { FlatBuffersVersion_23_5_8() }
|
||||||
public var __buffer: ByteBuffer! { return _accessor.bb }
|
public var __buffer: ByteBuffer! { return _accessor.bb }
|
||||||
private var _accessor: Table
|
private var _accessor: Table
|
||||||
|
|
||||||
|
|||||||
@@ -4,6 +4,16 @@ package(
|
|||||||
default_visibility = ["//visibility:public"],
|
default_visibility = ["//visibility:public"],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
filegroup(
|
||||||
|
name = "distribution",
|
||||||
|
srcs = [
|
||||||
|
"BUILD.bazel",
|
||||||
|
] + glob([
|
||||||
|
"*.cc",
|
||||||
|
"*.h",
|
||||||
|
]),
|
||||||
|
)
|
||||||
|
|
||||||
filegroup(
|
filegroup(
|
||||||
name = "common_headers",
|
name = "common_headers",
|
||||||
srcs = [
|
srcs = [
|
||||||
|
|||||||
@@ -139,8 +139,8 @@
|
|||||||
#endif // !defined(FLATBUFFERS_LITTLEENDIAN)
|
#endif // !defined(FLATBUFFERS_LITTLEENDIAN)
|
||||||
|
|
||||||
#define FLATBUFFERS_VERSION_MAJOR 23
|
#define FLATBUFFERS_VERSION_MAJOR 23
|
||||||
#define FLATBUFFERS_VERSION_MINOR 3
|
#define FLATBUFFERS_VERSION_MINOR 5
|
||||||
#define FLATBUFFERS_VERSION_REVISION 3
|
#define FLATBUFFERS_VERSION_REVISION 8
|
||||||
#define FLATBUFFERS_STRING_EXPAND(X) #X
|
#define FLATBUFFERS_STRING_EXPAND(X) #X
|
||||||
#define FLATBUFFERS_STRING(X) FLATBUFFERS_STRING_EXPAND(X)
|
#define FLATBUFFERS_STRING(X) FLATBUFFERS_STRING_EXPAND(X)
|
||||||
namespace flatbuffers {
|
namespace flatbuffers {
|
||||||
@@ -233,12 +233,17 @@ namespace flatbuffers {
|
|||||||
}
|
}
|
||||||
#define FLATBUFFERS_HAS_STRING_VIEW 1
|
#define FLATBUFFERS_HAS_STRING_VIEW 1
|
||||||
// Check for absl::string_view
|
// Check for absl::string_view
|
||||||
#elif __has_include("absl/strings/string_view.h") && (__cplusplus >= 201411)
|
#elif __has_include("absl/strings/string_view.h") && \
|
||||||
#include "absl/strings/string_view.h"
|
__has_include("absl/base/config.h") && \
|
||||||
namespace flatbuffers {
|
(__cplusplus >= 201411)
|
||||||
typedef absl::string_view string_view;
|
#include "absl/base/config.h"
|
||||||
}
|
#if !defined(ABSL_USES_STD_STRING_VIEW)
|
||||||
#define FLATBUFFERS_HAS_STRING_VIEW 1
|
#include "absl/strings/string_view.h"
|
||||||
|
namespace flatbuffers {
|
||||||
|
typedef absl::string_view string_view;
|
||||||
|
}
|
||||||
|
#define FLATBUFFERS_HAS_STRING_VIEW 1
|
||||||
|
#endif
|
||||||
#endif
|
#endif
|
||||||
#endif // __has_include
|
#endif // __has_include
|
||||||
#endif // !FLATBUFFERS_HAS_STRING_VIEW
|
#endif // !FLATBUFFERS_HAS_STRING_VIEW
|
||||||
|
|||||||
@@ -36,6 +36,8 @@ class CodeGenerator {
|
|||||||
NOT_IMPLEMENTED = 3
|
NOT_IMPLEMENTED = 3
|
||||||
};
|
};
|
||||||
|
|
||||||
|
std::string status_detail;
|
||||||
|
|
||||||
// Generate code from the provided `parser`.
|
// Generate code from the provided `parser`.
|
||||||
//
|
//
|
||||||
// DEPRECATED: prefer using the other overload of GenerateCode for bfbs.
|
// 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_
|
||||||
@@ -40,8 +40,8 @@ namespace flatbuffers {
|
|||||||
// Converts a Field ID to a virtual table offset.
|
// Converts a Field ID to a virtual table offset.
|
||||||
inline voffset_t FieldIndexToOffset(voffset_t field_id) {
|
inline voffset_t FieldIndexToOffset(voffset_t field_id) {
|
||||||
// Should correspond to what EndTable() below builds up.
|
// Should correspond to what EndTable() below builds up.
|
||||||
const int fixed_fields = 2; // Vtable size and Object Size.
|
const voffset_t fixed_fields = 2 * sizeof(voffset_t); // Vtable size and Object Size.
|
||||||
return static_cast<voffset_t>((field_id + fixed_fields) * sizeof(voffset_t));
|
return fixed_fields + field_id * sizeof(voffset_t);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T, typename Alloc = std::allocator<T>>
|
template<typename T, typename Alloc = std::allocator<T>>
|
||||||
@@ -360,7 +360,7 @@ class FlatBufferBuilder {
|
|||||||
FLATBUFFERS_ASSERT(nested);
|
FLATBUFFERS_ASSERT(nested);
|
||||||
// Write the vtable offset, which is the start of any Table.
|
// Write the vtable offset, which is the start of any Table.
|
||||||
// We fill its value later.
|
// We fill its value later.
|
||||||
auto vtableoffsetloc = PushElement<soffset_t>(0);
|
const uoffset_t vtableoffsetloc = PushElement<soffset_t>(0);
|
||||||
// Write a vtable, which consists entirely of voffset_t elements.
|
// Write a vtable, which consists entirely of voffset_t elements.
|
||||||
// It starts with the number of offsets, followed by a type id, followed
|
// It starts with the number of offsets, followed by a type id, followed
|
||||||
// by the offsets themselves. In reverse:
|
// by the offsets themselves. In reverse:
|
||||||
@@ -400,7 +400,7 @@ class FlatBufferBuilder {
|
|||||||
auto vt2_size = ReadScalar<voffset_t>(vt2);
|
auto vt2_size = ReadScalar<voffset_t>(vt2);
|
||||||
if (vt1_size != vt2_size || 0 != memcmp(vt2, vt1, vt1_size)) continue;
|
if (vt1_size != vt2_size || 0 != memcmp(vt2, vt1, vt1_size)) continue;
|
||||||
vt_use = *vt_offset_ptr;
|
vt_use = *vt_offset_ptr;
|
||||||
buf_.pop(GetSize() - vtableoffsetloc);
|
buf_.pop(GetSize() - static_cast<size_t>(vtableoffsetloc));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -525,7 +525,7 @@ class FlatBufferBuilder {
|
|||||||
FLATBUFFERS_ASSERT(FLATBUFFERS_GENERAL_HEAP_ALLOC_OK);
|
FLATBUFFERS_ASSERT(FLATBUFFERS_GENERAL_HEAP_ALLOC_OK);
|
||||||
if (!string_pool)
|
if (!string_pool)
|
||||||
string_pool = new StringOffsetMap(StringOffsetCompare(buf_));
|
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
|
// Must first serialize the string, since the set is all offsets into
|
||||||
// buffer.
|
// buffer.
|
||||||
auto off = CreateString(str, len);
|
auto off = CreateString(str, len);
|
||||||
@@ -1184,7 +1184,8 @@ class FlatBufferBuilder {
|
|||||||
// Allocates space for a vector of structures.
|
// Allocates space for a vector of structures.
|
||||||
// Must be completed with EndVectorOfStructs().
|
// Must be completed with EndVectorOfStructs().
|
||||||
template<typename T> T *StartVectorOfStructs(size_t vector_size) {
|
template<typename T> T *StartVectorOfStructs(size_t vector_size) {
|
||||||
StartVector(vector_size * sizeof(T) / AlignOf<T>(), sizeof(T), AlignOf<T>());
|
StartVector(vector_size * sizeof(T) / AlignOf<T>(), sizeof(T),
|
||||||
|
AlignOf<T>());
|
||||||
return reinterpret_cast<T *>(buf_.make_space(vector_size * sizeof(T)));
|
return reinterpret_cast<T *>(buf_.make_space(vector_size * sizeof(T)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -56,6 +56,7 @@ struct FlatCOptions {
|
|||||||
bool schema_binary = false;
|
bool schema_binary = false;
|
||||||
bool grpc_enabled = false;
|
bool grpc_enabled = false;
|
||||||
bool requires_bfbs = false;
|
bool requires_bfbs = false;
|
||||||
|
bool file_names_only = false;
|
||||||
|
|
||||||
std::vector<std::shared_ptr<CodeGenerator>> generators;
|
std::vector<std::shared_ptr<CodeGenerator>> generators;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1424,12 +1424,10 @@ class Builder FLATBUFFERS_FINAL_CLASS {
|
|||||||
|
|
||||||
template<typename T> static Type GetScalarType() {
|
template<typename T> static Type GetScalarType() {
|
||||||
static_assert(flatbuffers::is_scalar<T>::value, "Unrelated types");
|
static_assert(flatbuffers::is_scalar<T>::value, "Unrelated types");
|
||||||
return flatbuffers::is_floating_point<T>::value
|
return flatbuffers::is_floating_point<T>::value ? FBT_FLOAT
|
||||||
? FBT_FLOAT
|
: flatbuffers::is_same<T, bool>::value
|
||||||
: flatbuffers::is_same<T, bool>::value
|
? FBT_BOOL
|
||||||
? FBT_BOOL
|
: (flatbuffers::is_unsigned<T>::value ? FBT_UINT : FBT_INT);
|
||||||
: (flatbuffers::is_unsigned<T>::value ? FBT_UINT
|
|
||||||
: FBT_INT);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|||||||
@@ -697,6 +697,8 @@ struct IDLOptions {
|
|||||||
bool no_leak_private_annotations;
|
bool no_leak_private_annotations;
|
||||||
bool require_json_eof;
|
bool require_json_eof;
|
||||||
bool keep_proto_id;
|
bool keep_proto_id;
|
||||||
|
bool python_no_type_prefix_suffix;
|
||||||
|
bool python_typing;
|
||||||
ProtoIdGapAction proto_id_gap_action;
|
ProtoIdGapAction proto_id_gap_action;
|
||||||
|
|
||||||
// Possible options for the more general generator below.
|
// Possible options for the more general generator below.
|
||||||
@@ -806,6 +808,8 @@ struct IDLOptions {
|
|||||||
no_leak_private_annotations(false),
|
no_leak_private_annotations(false),
|
||||||
require_json_eof(true),
|
require_json_eof(true),
|
||||||
keep_proto_id(false),
|
keep_proto_id(false),
|
||||||
|
python_no_type_prefix_suffix(false),
|
||||||
|
python_typing(false),
|
||||||
proto_id_gap_action(ProtoIdGapAction::WARNING),
|
proto_id_gap_action(ProtoIdGapAction::WARNING),
|
||||||
mini_reflect(IDLOptions::kNone),
|
mini_reflect(IDLOptions::kNone),
|
||||||
require_explicit_ids(false),
|
require_explicit_ids(false),
|
||||||
@@ -1196,13 +1200,14 @@ class Parser : public ParserState {
|
|||||||
// strict_json adds "quotes" around field names if true.
|
// strict_json adds "quotes" around field names if true.
|
||||||
// If the flatbuffer cannot be encoded in JSON (e.g., it contains non-UTF-8
|
// If the flatbuffer cannot be encoded in JSON (e.g., it contains non-UTF-8
|
||||||
// byte arrays in String values), returns false.
|
// byte arrays in String values), returns false.
|
||||||
extern bool GenerateTextFromTable(const Parser &parser, const void *table,
|
extern const char *GenerateTextFromTable(const Parser &parser, const void *table,
|
||||||
const std::string &tablename,
|
const std::string &tablename,
|
||||||
std::string *text);
|
std::string *text);
|
||||||
extern bool GenerateText(const Parser &parser, const void *flatbuffer,
|
extern const char *GenerateText(const Parser &parser, const void *flatbuffer,
|
||||||
std::string *text);
|
std::string *text);
|
||||||
extern bool GenerateTextFile(const Parser &parser, const std::string &path,
|
extern const char *GenerateTextFile(const Parser &parser,
|
||||||
const std::string &file_name);
|
const std::string &path,
|
||||||
|
const std::string &file_name);
|
||||||
|
|
||||||
// Generate Json schema to string
|
// Generate Json schema to string
|
||||||
// See idl_gen_json_schema.cpp.
|
// See idl_gen_json_schema.cpp.
|
||||||
@@ -1283,9 +1288,10 @@ extern bool GenerateSwift(const Parser &parser, const std::string &path,
|
|||||||
// Generate a schema file from the internal representation, useful after
|
// Generate a schema file from the internal representation, useful after
|
||||||
// parsing a .proto schema.
|
// parsing a .proto schema.
|
||||||
extern std::string GenerateFBS(const Parser &parser,
|
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,
|
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.
|
// Generate a make rule for the generated TypeScript code.
|
||||||
// See idl_gen_ts.cpp.
|
// See idl_gen_ts.cpp.
|
||||||
|
|||||||
@@ -408,7 +408,7 @@ inline std::string FlatBufferToString(const uint8_t *buffer,
|
|||||||
const TypeTable *type_table,
|
const TypeTable *type_table,
|
||||||
bool multi_line = false,
|
bool multi_line = false,
|
||||||
bool vector_delimited = true,
|
bool vector_delimited = true,
|
||||||
const std::string& indent = "") {
|
const std::string &indent = "") {
|
||||||
ToStringVisitor tostring_visitor(multi_line ? "\n" : " ", false, indent,
|
ToStringVisitor tostring_visitor(multi_line ? "\n" : " ", false, indent,
|
||||||
vector_delimited);
|
vector_delimited);
|
||||||
IterateFlatBuffer(buffer, type_table, &tostring_visitor);
|
IterateFlatBuffer(buffer, type_table, &tostring_visitor);
|
||||||
|
|||||||
@@ -9,8 +9,8 @@
|
|||||||
// Ensure the included flatbuffers.h is the same version as when this file was
|
// Ensure the included flatbuffers.h is the same version as when this file was
|
||||||
// generated, otherwise it may not be compatible.
|
// generated, otherwise it may not be compatible.
|
||||||
static_assert(FLATBUFFERS_VERSION_MAJOR == 23 &&
|
static_assert(FLATBUFFERS_VERSION_MAJOR == 23 &&
|
||||||
FLATBUFFERS_VERSION_MINOR == 3 &&
|
FLATBUFFERS_VERSION_MINOR == 5 &&
|
||||||
FLATBUFFERS_VERSION_REVISION == 3,
|
FLATBUFFERS_VERSION_REVISION == 8,
|
||||||
"Non-compatible flatbuffers version included");
|
"Non-compatible flatbuffers version included");
|
||||||
|
|
||||||
namespace reflection {
|
namespace reflection {
|
||||||
|
|||||||
@@ -52,8 +52,10 @@ class Registry {
|
|||||||
Parser parser;
|
Parser parser;
|
||||||
if (!LoadSchema(ident, &parser)) return false;
|
if (!LoadSchema(ident, &parser)) return false;
|
||||||
// Now we're ready to generate text.
|
// Now we're ready to generate text.
|
||||||
if (!GenerateText(parser, flatbuf, dest)) {
|
auto err = GenerateText(parser, flatbuf, dest);
|
||||||
lasterror_ = "unable to generate text for FlatBuffer binary";
|
if (err) {
|
||||||
|
lasterror_ = "unable to generate text for FlatBuffer binary: " +
|
||||||
|
std::string(err);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@@ -722,9 +722,10 @@ enum class Case {
|
|||||||
kSnake2 = 9,
|
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,
|
std::string ConvertCase(const std::string &input, Case output_case,
|
||||||
Case input_case = Case::kSnake);
|
Case input_case = Case::kSnake);
|
||||||
|
|
||||||
} // namespace flatbuffers
|
} // namespace flatbuffers
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<groupId>com.google.flatbuffers</groupId>
|
<groupId>com.google.flatbuffers</groupId>
|
||||||
<artifactId>flatbuffers-java</artifactId>
|
<artifactId>flatbuffers-java</artifactId>
|
||||||
<version>23.3.3</version>
|
<version>23.5.8</version>
|
||||||
<packaging>bundle</packaging>
|
<packaging>bundle</packaging>
|
||||||
<name>FlatBuffers Java API</name>
|
<name>FlatBuffers Java API</name>
|
||||||
<description>
|
<description>
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ public class Constants {
|
|||||||
Changes to the Java implementation need to be sure to change
|
Changes to the Java implementation need to be sure to change
|
||||||
the version here and in the code generator on every possible
|
the version here and in the code generator on every possible
|
||||||
incompatible change */
|
incompatible change */
|
||||||
public static void FLATBUFFERS_23_3_3() {}
|
public static void FLATBUFFERS_23_5_8() {}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// @endcond
|
/// @endcond
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ import java.nio.ByteOrder;
|
|||||||
|
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
public final class Enum extends Table {
|
public final class Enum extends Table {
|
||||||
public static void ValidateVersion() { Constants.FLATBUFFERS_23_3_3(); }
|
public static void ValidateVersion() { Constants.FLATBUFFERS_23_5_8(); }
|
||||||
public static Enum getRootAsEnum(ByteBuffer _bb) { return getRootAsEnum(_bb, new Enum()); }
|
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 static Enum getRootAsEnum(ByteBuffer _bb, Enum obj) { _bb.order(ByteOrder.LITTLE_ENDIAN); return (obj.__assign(_bb.getInt(_bb.position()) + _bb.position(), _bb)); }
|
||||||
public void __init(int _i, ByteBuffer _bb) { __reset(_i, _bb); }
|
public void __init(int _i, ByteBuffer _bb) { __reset(_i, _bb); }
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ import java.nio.ByteOrder;
|
|||||||
|
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
public final class EnumVal extends Table {
|
public final class EnumVal extends Table {
|
||||||
public static void ValidateVersion() { Constants.FLATBUFFERS_23_3_3(); }
|
public static void ValidateVersion() { Constants.FLATBUFFERS_23_5_8(); }
|
||||||
public static EnumVal getRootAsEnumVal(ByteBuffer _bb) { return getRootAsEnumVal(_bb, new EnumVal()); }
|
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 static EnumVal getRootAsEnumVal(ByteBuffer _bb, EnumVal obj) { _bb.order(ByteOrder.LITTLE_ENDIAN); return (obj.__assign(_bb.getInt(_bb.position()) + _bb.position(), _bb)); }
|
||||||
public void __init(int _i, ByteBuffer _bb) { __reset(_i, _bb); }
|
public void __init(int _i, ByteBuffer _bb) { __reset(_i, _bb); }
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ import java.nio.ByteOrder;
|
|||||||
|
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
public final class Field extends Table {
|
public final class Field extends Table {
|
||||||
public static void ValidateVersion() { Constants.FLATBUFFERS_23_3_3(); }
|
public static void ValidateVersion() { Constants.FLATBUFFERS_23_5_8(); }
|
||||||
public static Field getRootAsField(ByteBuffer _bb) { return getRootAsField(_bb, new Field()); }
|
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 static Field getRootAsField(ByteBuffer _bb, Field obj) { _bb.order(ByteOrder.LITTLE_ENDIAN); return (obj.__assign(_bb.getInt(_bb.position()) + _bb.position(), _bb)); }
|
||||||
public void __init(int _i, ByteBuffer _bb) { __reset(_i, _bb); }
|
public void __init(int _i, ByteBuffer _bb) { __reset(_i, _bb); }
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ import java.nio.ByteOrder;
|
|||||||
|
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
public final class KeyValue extends Table {
|
public final class KeyValue extends Table {
|
||||||
public static void ValidateVersion() { Constants.FLATBUFFERS_23_3_3(); }
|
public static void ValidateVersion() { Constants.FLATBUFFERS_23_5_8(); }
|
||||||
public static KeyValue getRootAsKeyValue(ByteBuffer _bb) { return getRootAsKeyValue(_bb, new KeyValue()); }
|
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 static KeyValue getRootAsKeyValue(ByteBuffer _bb, KeyValue obj) { _bb.order(ByteOrder.LITTLE_ENDIAN); return (obj.__assign(_bb.getInt(_bb.position()) + _bb.position(), _bb)); }
|
||||||
public void __init(int _i, ByteBuffer _bb) { __reset(_i, _bb); }
|
public void __init(int _i, ByteBuffer _bb) { __reset(_i, _bb); }
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ import java.nio.ByteOrder;
|
|||||||
|
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
public final class Object extends Table {
|
public final class Object extends Table {
|
||||||
public static void ValidateVersion() { Constants.FLATBUFFERS_23_3_3(); }
|
public static void ValidateVersion() { Constants.FLATBUFFERS_23_5_8(); }
|
||||||
public static Object getRootAsObject(ByteBuffer _bb) { return getRootAsObject(_bb, new Object()); }
|
public static Object getRootAsObject(ByteBuffer _bb) { return getRootAsObject(_bb, new Object()); }
|
||||||
public static Object getRootAsObject(ByteBuffer _bb, Object obj) { _bb.order(ByteOrder.LITTLE_ENDIAN); return (obj.__assign(_bb.getInt(_bb.position()) + _bb.position(), _bb)); }
|
public static Object getRootAsObject(ByteBuffer _bb, Object obj) { _bb.order(ByteOrder.LITTLE_ENDIAN); return (obj.__assign(_bb.getInt(_bb.position()) + _bb.position(), _bb)); }
|
||||||
public void __init(int _i, ByteBuffer _bb) { __reset(_i, _bb); }
|
public void __init(int _i, ByteBuffer _bb) { __reset(_i, _bb); }
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ import java.nio.ByteOrder;
|
|||||||
|
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
public final class RPCCall extends Table {
|
public final class RPCCall extends Table {
|
||||||
public static void ValidateVersion() { Constants.FLATBUFFERS_23_3_3(); }
|
public static void ValidateVersion() { Constants.FLATBUFFERS_23_5_8(); }
|
||||||
public static RPCCall getRootAsRPCCall(ByteBuffer _bb) { return getRootAsRPCCall(_bb, new RPCCall()); }
|
public static RPCCall getRootAsRPCCall(ByteBuffer _bb) { return getRootAsRPCCall(_bb, new RPCCall()); }
|
||||||
public static RPCCall getRootAsRPCCall(ByteBuffer _bb, RPCCall obj) { _bb.order(ByteOrder.LITTLE_ENDIAN); return (obj.__assign(_bb.getInt(_bb.position()) + _bb.position(), _bb)); }
|
public static RPCCall getRootAsRPCCall(ByteBuffer _bb, RPCCall obj) { _bb.order(ByteOrder.LITTLE_ENDIAN); return (obj.__assign(_bb.getInt(_bb.position()) + _bb.position(), _bb)); }
|
||||||
public void __init(int _i, ByteBuffer _bb) { __reset(_i, _bb); }
|
public void __init(int _i, ByteBuffer _bb) { __reset(_i, _bb); }
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ import java.nio.ByteOrder;
|
|||||||
|
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
public final class Schema extends Table {
|
public final class Schema extends Table {
|
||||||
public static void ValidateVersion() { Constants.FLATBUFFERS_23_3_3(); }
|
public static void ValidateVersion() { Constants.FLATBUFFERS_23_5_8(); }
|
||||||
public static Schema getRootAsSchema(ByteBuffer _bb) { return getRootAsSchema(_bb, new Schema()); }
|
public static Schema getRootAsSchema(ByteBuffer _bb) { return getRootAsSchema(_bb, new Schema()); }
|
||||||
public static Schema getRootAsSchema(ByteBuffer _bb, Schema obj) { _bb.order(ByteOrder.LITTLE_ENDIAN); return (obj.__assign(_bb.getInt(_bb.position()) + _bb.position(), _bb)); }
|
public static Schema getRootAsSchema(ByteBuffer _bb, Schema obj) { _bb.order(ByteOrder.LITTLE_ENDIAN); return (obj.__assign(_bb.getInt(_bb.position()) + _bb.position(), _bb)); }
|
||||||
public static boolean SchemaBufferHasIdentifier(ByteBuffer _bb) { return __has_identifier(_bb, "BFBS"); }
|
public static boolean SchemaBufferHasIdentifier(ByteBuffer _bb) { return __has_identifier(_bb, "BFBS"); }
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ import java.nio.ByteOrder;
|
|||||||
*/
|
*/
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
public final class SchemaFile extends Table {
|
public final class SchemaFile extends Table {
|
||||||
public static void ValidateVersion() { Constants.FLATBUFFERS_23_3_3(); }
|
public static void ValidateVersion() { Constants.FLATBUFFERS_23_5_8(); }
|
||||||
public static SchemaFile getRootAsSchemaFile(ByteBuffer _bb) { return getRootAsSchemaFile(_bb, new SchemaFile()); }
|
public static SchemaFile getRootAsSchemaFile(ByteBuffer _bb) { return getRootAsSchemaFile(_bb, new SchemaFile()); }
|
||||||
public static SchemaFile getRootAsSchemaFile(ByteBuffer _bb, SchemaFile obj) { _bb.order(ByteOrder.LITTLE_ENDIAN); return (obj.__assign(_bb.getInt(_bb.position()) + _bb.position(), _bb)); }
|
public static SchemaFile getRootAsSchemaFile(ByteBuffer _bb, SchemaFile obj) { _bb.order(ByteOrder.LITTLE_ENDIAN); return (obj.__assign(_bb.getInt(_bb.position()) + _bb.position(), _bb)); }
|
||||||
public void __init(int _i, ByteBuffer _bb) { __reset(_i, _bb); }
|
public void __init(int _i, ByteBuffer _bb) { __reset(_i, _bb); }
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ import java.nio.ByteOrder;
|
|||||||
|
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
public final class Service extends Table {
|
public final class Service extends Table {
|
||||||
public static void ValidateVersion() { Constants.FLATBUFFERS_23_3_3(); }
|
public static void ValidateVersion() { Constants.FLATBUFFERS_23_5_8(); }
|
||||||
public static Service getRootAsService(ByteBuffer _bb) { return getRootAsService(_bb, new Service()); }
|
public static Service getRootAsService(ByteBuffer _bb) { return getRootAsService(_bb, new Service()); }
|
||||||
public static Service getRootAsService(ByteBuffer _bb, Service obj) { _bb.order(ByteOrder.LITTLE_ENDIAN); return (obj.__assign(_bb.getInt(_bb.position()) + _bb.position(), _bb)); }
|
public static Service getRootAsService(ByteBuffer _bb, Service obj) { _bb.order(ByteOrder.LITTLE_ENDIAN); return (obj.__assign(_bb.getInt(_bb.position()) + _bb.position(), _bb)); }
|
||||||
public void __init(int _i, ByteBuffer _bb) { __reset(_i, _bb); }
|
public void __init(int _i, ByteBuffer _bb) { __reset(_i, _bb); }
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ import java.nio.ByteOrder;
|
|||||||
|
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
public final class Type extends Table {
|
public final class Type extends Table {
|
||||||
public static void ValidateVersion() { Constants.FLATBUFFERS_23_3_3(); }
|
public static void ValidateVersion() { Constants.FLATBUFFERS_23_5_8(); }
|
||||||
public static Type getRootAsType(ByteBuffer _bb) { return getRootAsType(_bb, new Type()); }
|
public static Type getRootAsType(ByteBuffer _bb) { return getRootAsType(_bb, new Type()); }
|
||||||
public static Type getRootAsType(ByteBuffer _bb, Type obj) { _bb.order(ByteOrder.LITTLE_ENDIAN); return (obj.__assign(_bb.getInt(_bb.position()) + _bb.position(), _bb)); }
|
public static Type getRootAsType(ByteBuffer _bb, Type obj) { _bb.order(ByteOrder.LITTLE_ENDIAN); return (obj.__assign(_bb.getInt(_bb.position()) + _bb.position(), _bb)); }
|
||||||
public void __init(int _i, ByteBuffer _bb) { __reset(_i, _bb); }
|
public void __init(int _i, ByteBuffer _bb) { __reset(_i, _bb); }
|
||||||
|
|||||||
@@ -438,7 +438,8 @@ namespace Google.FlatBuffers
|
|||||||
if (off > Offset)
|
if (off > Offset)
|
||||||
throw new ArgumentException();
|
throw new ArgumentException();
|
||||||
|
|
||||||
off = Offset - off + sizeof(int);
|
if (off != 0)
|
||||||
|
off = Offset - off + sizeof(int);
|
||||||
PutInt(off);
|
PutInt(off);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -32,6 +32,6 @@ namespace Google.FlatBuffers
|
|||||||
Changes to the C# implementation need to be sure to change
|
Changes to the C# implementation need to be sure to change
|
||||||
the version here and in the code generator on every possible
|
the version here and in the code generator on every possible
|
||||||
incompatible change */
|
incompatible change */
|
||||||
public static void FLATBUFFERS_23_3_3() {}
|
public static void FLATBUFFERS_23_5_8() {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
822
net/FlatBuffers/FlatBufferVerify.cs
Normal file
822
net/FlatBuffers/FlatBufferVerify.cs
Normal file
@@ -0,0 +1,822 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2014 Google Inc. All rights reserved.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
using System;
|
||||||
|
using System.Reflection;using System.Collections.Generic;
|
||||||
|
using System.IO;
|
||||||
|
|
||||||
|
namespace Google.FlatBuffers
|
||||||
|
{
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The Class of the Verifier Options
|
||||||
|
/// </summary>
|
||||||
|
public class Options
|
||||||
|
{
|
||||||
|
public const int DEFAULT_MAX_DEPTH = 64;
|
||||||
|
public const int DEFAULT_MAX_TABLES = 1000000;
|
||||||
|
|
||||||
|
private int max_depth = 0;
|
||||||
|
private int max_tables = 0;
|
||||||
|
private bool string_end_check = false;
|
||||||
|
private bool alignment_check = false;
|
||||||
|
|
||||||
|
public Options()
|
||||||
|
{
|
||||||
|
max_depth = DEFAULT_MAX_DEPTH;
|
||||||
|
max_tables = DEFAULT_MAX_TABLES;
|
||||||
|
string_end_check = true;
|
||||||
|
alignment_check = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Options(int maxDepth, int maxTables, bool stringEndCheck, bool alignmentCheck)
|
||||||
|
{
|
||||||
|
max_depth = maxDepth;
|
||||||
|
max_tables = maxTables;
|
||||||
|
string_end_check = stringEndCheck;
|
||||||
|
alignment_check = alignmentCheck;
|
||||||
|
}
|
||||||
|
/// <summary> Maximum depth of nested tables allowed in a valid flatbuffer. </summary>
|
||||||
|
public int maxDepth
|
||||||
|
{
|
||||||
|
get { return max_depth; }
|
||||||
|
set { max_depth = value; }
|
||||||
|
}
|
||||||
|
/// <summary> Maximum number of tables allowed in a valid flatbuffer. </summary>
|
||||||
|
public int maxTables
|
||||||
|
{
|
||||||
|
get { return max_tables; }
|
||||||
|
set { max_tables = value; }
|
||||||
|
}
|
||||||
|
/// <summary> Check that string contains its null terminator </summary>
|
||||||
|
public bool stringEndCheck
|
||||||
|
{
|
||||||
|
get { return string_end_check; }
|
||||||
|
set { string_end_check = value; }
|
||||||
|
}
|
||||||
|
/// <summary> Check alignment of elements </summary>
|
||||||
|
public bool alignmentCheck
|
||||||
|
{
|
||||||
|
get { return alignment_check; }
|
||||||
|
set { alignment_check = value; }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public struct checkElementStruct
|
||||||
|
{
|
||||||
|
public bool elementValid;
|
||||||
|
public uint elementOffset;
|
||||||
|
}
|
||||||
|
|
||||||
|
public delegate bool VerifyTableAction(Verifier verifier, uint tablePos);
|
||||||
|
public delegate bool VerifyUnionAction(Verifier verifier, byte typeId, uint tablePos);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The Main Class of the FlatBuffer Verifier
|
||||||
|
/// </summary>
|
||||||
|
public class Verifier
|
||||||
|
{
|
||||||
|
private ByteBuffer verifier_buffer = null;
|
||||||
|
private Options verifier_options = null;
|
||||||
|
private int depth_cnt = 0;
|
||||||
|
private int num_tables_cnt = 0;
|
||||||
|
|
||||||
|
public const int SIZE_BYTE = 1;
|
||||||
|
public const int SIZE_INT = 4;
|
||||||
|
public const int SIZE_U_OFFSET = 4;
|
||||||
|
public const int SIZE_S_OFFSET = 4;
|
||||||
|
public const int SIZE_V_OFFSET = 2;
|
||||||
|
public const int SIZE_PREFIX_LENGTH = FlatBufferConstants.SizePrefixLength; // default size = 4
|
||||||
|
public const int FLATBUFFERS_MAX_BUFFER_SIZE = System.Int32.MaxValue; // default size = 2147483647
|
||||||
|
public const int FILE_IDENTIFIER_LENGTH = FlatBufferConstants.FileIdentifierLength; // default size = 4
|
||||||
|
|
||||||
|
/// <summary> The Base Constructor of the Verifier object </summary>
|
||||||
|
public Verifier()
|
||||||
|
{
|
||||||
|
// Verifier buffer
|
||||||
|
verifier_buffer = null;
|
||||||
|
// Verifier settings
|
||||||
|
verifier_options = null;
|
||||||
|
// Depth counter
|
||||||
|
depth_cnt = 0;
|
||||||
|
// Tables counter
|
||||||
|
num_tables_cnt = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary> The Constructor of the Verifier object with input parameters: ByteBuffer and/or Options </summary>
|
||||||
|
/// <param name="buf"> Input flat byte buffer defined as ByteBuffer type</param>
|
||||||
|
/// <param name="options"> Options object with settings for the coniguration the Verifier </param>
|
||||||
|
public Verifier(ByteBuffer buf, Options options = null)
|
||||||
|
{
|
||||||
|
verifier_buffer = buf;
|
||||||
|
verifier_options = options ?? new Options();
|
||||||
|
depth_cnt = 0;
|
||||||
|
num_tables_cnt = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary> Bytes Buffer for Verify</summary>
|
||||||
|
public ByteBuffer Buf
|
||||||
|
{
|
||||||
|
get { return verifier_buffer; }
|
||||||
|
set { verifier_buffer = value; }
|
||||||
|
}
|
||||||
|
/// <summary> Options of the Verifier </summary>
|
||||||
|
public Options options
|
||||||
|
{
|
||||||
|
get { return verifier_options; }
|
||||||
|
set { verifier_options = value; }
|
||||||
|
}
|
||||||
|
/// <summary> Counter of tables depth in a tested flatbuffer </summary>
|
||||||
|
public int depth
|
||||||
|
{
|
||||||
|
get { return depth_cnt; }
|
||||||
|
set { depth_cnt = value; }
|
||||||
|
}
|
||||||
|
/// <summary> Counter of tables in a tested flatbuffer </summary>
|
||||||
|
public int numTables
|
||||||
|
{
|
||||||
|
get { return num_tables_cnt; }
|
||||||
|
set { num_tables_cnt = value; }
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary> Method set maximum tables depth of valid structure</summary>
|
||||||
|
/// <param name="value"> Specify Value of the maximum depth of the structure</param>
|
||||||
|
public Verifier SetMaxDepth(int value)
|
||||||
|
{
|
||||||
|
verifier_options.maxDepth = value;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
/// <summary> Specify maximum number of tables in structure </summary>
|
||||||
|
/// <param name="value"> Specify Value of the maximum number of the tables in the structure</param>
|
||||||
|
public Verifier SetMaxTables(int value)
|
||||||
|
{
|
||||||
|
verifier_options.maxTables = value;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
/// <summary> Enable/disable buffer content alignment check </summary>
|
||||||
|
/// <param name="value"> Value of the State for buffer content alignment check (Enable = true) </param>
|
||||||
|
public Verifier SetAlignmentCheck(bool value)
|
||||||
|
{
|
||||||
|
verifier_options.alignmentCheck = value;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
/// <summary> Enable/disable checking of string termination '0' character </summary>
|
||||||
|
/// <param name="value"> Value of the option for string termination '0' character check (Enable = true)</param>
|
||||||
|
public Verifier SetStringCheck(bool value)
|
||||||
|
{
|
||||||
|
verifier_options.stringEndCheck = value;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary> Check if there is identifier in buffer </summary>
|
||||||
|
/// <param name="buf"> Input flat byte buffer defined as ByteBuffer type </param>
|
||||||
|
/// <param name="startPos">Start position of data in the Byte Buffer</param>
|
||||||
|
/// <param name="identifier"> Identifier for the Byte Buffer</param>
|
||||||
|
/// <returns> Return True when the Byte Buffer Identifier is present</returns>
|
||||||
|
private bool BufferHasIdentifier(ByteBuffer buf, uint startPos, string identifier)
|
||||||
|
{
|
||||||
|
if (identifier.Length != FILE_IDENTIFIER_LENGTH)
|
||||||
|
{
|
||||||
|
throw new ArgumentException("FlatBuffers: file identifier must be length" + Convert.ToString(FILE_IDENTIFIER_LENGTH));
|
||||||
|
}
|
||||||
|
for (int i = 0; i < FILE_IDENTIFIER_LENGTH; i++)
|
||||||
|
{
|
||||||
|
if ((sbyte)identifier[i] != verifier_buffer.GetSbyte(Convert.ToInt32(SIZE_S_OFFSET + i + startPos)))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary> Get UOffsetT from buffer at given position - it must be verified before read </summary>
|
||||||
|
/// <param name="buf"> Input flat byte buffer defined as ByteBuffer type </param>
|
||||||
|
/// <param name="pos"> Position of data in the Byte Buffer</param>
|
||||||
|
/// <returns> Return the UOffset Value (Unsigned Integer type - 4 bytes) in pos </returns>
|
||||||
|
private uint ReadUOffsetT(ByteBuffer buf, uint pos)
|
||||||
|
{
|
||||||
|
return buf.GetUint(Convert.ToInt32(pos));
|
||||||
|
}
|
||||||
|
/// <summary> Get SOffsetT from buffer at given position - it must be verified before read </summary>
|
||||||
|
/// <param name="buf"> Input flat byte buffer defined as ByteBuffer type </param>
|
||||||
|
/// <param name="pos"> Position of data in the Byte Buffer</param>
|
||||||
|
/// <returns> Return the SOffset Value (Signed Integer type - 4 bytes) in pos </returns>
|
||||||
|
private int ReadSOffsetT(ByteBuffer buf, int pos)
|
||||||
|
{
|
||||||
|
return buf.GetInt(pos);
|
||||||
|
}
|
||||||
|
/// <summary> Get VOffsetT from buffer at given position - it must be verified before read </summary>
|
||||||
|
/// <param name="buf"> Input flat byte buffer defined as ByteBuffer type </param>
|
||||||
|
/// <param name="pos"> Position of data in the Byte Buffer</param>
|
||||||
|
/// <returns> Return the VOffset Value (Short type - 2 bytes) in pos </returns>
|
||||||
|
private short ReadVOffsetT(ByteBuffer buf, int pos)
|
||||||
|
{
|
||||||
|
return buf.GetShort(pos);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary> Get table data area relative offset from vtable. Result is relative to table start
|
||||||
|
/// Fields which are deprecated are ignored by checking against the vtable's length. </summary>
|
||||||
|
/// <param name="pos"> Position of data in the Byte Buffer </param>
|
||||||
|
/// <param name="vtableOffset"> offset of value in the Table</param>
|
||||||
|
/// <returns> Return the relative VOffset Value (Short type - 2 bytes) in calculated offset </returns>
|
||||||
|
private short GetVRelOffset(int pos, short vtableOffset)
|
||||||
|
{
|
||||||
|
short VOffset = 0;
|
||||||
|
// Used try/catch because pos typa as int 32bit
|
||||||
|
try
|
||||||
|
{
|
||||||
|
// First, get vtable offset
|
||||||
|
short vtable = Convert.ToInt16(pos - ReadSOffsetT(verifier_buffer, pos));
|
||||||
|
// Check that offset points to vtable area (is smaller than vtable size)
|
||||||
|
if (vtableOffset < ReadVOffsetT(verifier_buffer, vtable))
|
||||||
|
{
|
||||||
|
// Now, we can read offset value - TODO check this value against size of table data
|
||||||
|
VOffset = ReadVOffsetT(verifier_buffer, vtable + vtableOffset);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
VOffset = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
Console.WriteLine("Exception: {0}", e);
|
||||||
|
return VOffset;
|
||||||
|
}
|
||||||
|
return VOffset;
|
||||||
|
|
||||||
|
}
|
||||||
|
/// <summary> Get table data area absolute offset from vtable. Result is the absolute buffer offset.
|
||||||
|
/// The result value offset cannot be '0' (pointing to itself) so after validation this method returnes '0'
|
||||||
|
/// value as a marker for missing optional entry </summary>
|
||||||
|
/// <param name="tablePos"> Table Position value in the Byte Buffer </param>
|
||||||
|
/// <param name="vtableOffset"> offset value in the Table</param>
|
||||||
|
/// <returns> Return the absolute UOffset Value </returns>
|
||||||
|
private uint GetVOffset(uint tablePos, short vtableOffset)
|
||||||
|
{
|
||||||
|
uint UOffset = 0;
|
||||||
|
// First, get vtable relative offset
|
||||||
|
short relPos = GetVRelOffset(Convert.ToInt32(tablePos), vtableOffset);
|
||||||
|
if (relPos != 0)
|
||||||
|
{
|
||||||
|
// Calculate offset based on table postion
|
||||||
|
UOffset = Convert.ToUInt32(tablePos + relPos);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
UOffset = 0;
|
||||||
|
}
|
||||||
|
return UOffset;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary> Check flatbuffer complexity (tables depth, elements counter and so on) </summary>
|
||||||
|
/// <returns> If complexity is too high function returns false as verification error </returns>
|
||||||
|
private bool CheckComplexity()
|
||||||
|
{
|
||||||
|
return ((depth <= options.maxDepth) && (numTables <= options.maxTables));
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary> Check alignment of element. </summary>
|
||||||
|
/// <returns> Return True when alignment of the element is correct</returns>
|
||||||
|
private bool CheckAlignment(uint element, ulong align)
|
||||||
|
{
|
||||||
|
return (((element & (align - 1)) == 0) || (!options.alignmentCheck));
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary> Check if element is valid in buffer area. </summary>
|
||||||
|
/// <param name="pos"> Value defines the offset/position to element</param>
|
||||||
|
/// <param name="elementSize"> Size of element</param>
|
||||||
|
/// <returns> Return True when Element is correct </returns>
|
||||||
|
private bool CheckElement(uint pos, ulong elementSize)
|
||||||
|
{
|
||||||
|
return ((elementSize < Convert.ToUInt64(verifier_buffer.Length)) && (pos <= (Convert.ToUInt32(verifier_buffer.Length) - elementSize)));
|
||||||
|
}
|
||||||
|
/// <summary> Check if element is a valid scalar. </summary>
|
||||||
|
/// <param name="pos"> Value defines the offset to scalar</param>
|
||||||
|
/// <param name="elementSize"> Size of element</param>
|
||||||
|
/// <returns> Return True when Scalar Element is correct </returns>
|
||||||
|
private bool CheckScalar(uint pos, ulong elementSize)
|
||||||
|
{
|
||||||
|
return ((CheckAlignment(pos, elementSize)) && (CheckElement(pos, elementSize)));
|
||||||
|
}
|
||||||
|
/// <summary> Check offset. It is a scalar with size of UOffsetT. </summary>
|
||||||
|
private bool CheckOffset(uint offset)
|
||||||
|
{
|
||||||
|
return (CheckScalar(offset, SIZE_U_OFFSET));
|
||||||
|
}
|
||||||
|
|
||||||
|
private checkElementStruct CheckVectorOrString(uint pos, ulong elementSize)
|
||||||
|
{
|
||||||
|
var result = new checkElementStruct
|
||||||
|
{
|
||||||
|
elementValid = false,
|
||||||
|
elementOffset = 0
|
||||||
|
};
|
||||||
|
|
||||||
|
uint vectorPos = pos;
|
||||||
|
// Check we can read the vector/string size field (it is of uoffset size)
|
||||||
|
if (!CheckScalar(vectorPos, SIZE_U_OFFSET))
|
||||||
|
{
|
||||||
|
// result.elementValid = false; result.elementOffset = 0;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
// Check the whole array. If this is a string, the byte past the array
|
||||||
|
// must be 0.
|
||||||
|
uint size = ReadUOffsetT(verifier_buffer, vectorPos);
|
||||||
|
ulong max_elements = (FLATBUFFERS_MAX_BUFFER_SIZE / elementSize);
|
||||||
|
if (size >= max_elements)
|
||||||
|
{
|
||||||
|
// Protect against byte_size overflowing.
|
||||||
|
// result.elementValid = false; result.elementOffset = 0;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint bytes_size = SIZE_U_OFFSET + (Convert.ToUInt32(elementSize) * size);
|
||||||
|
uint buffer_end_pos = vectorPos + bytes_size;
|
||||||
|
result.elementValid = CheckElement(vectorPos, bytes_size);
|
||||||
|
result.elementOffset = buffer_end_pos;
|
||||||
|
return (result);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>Verify a string at given position.</summary>
|
||||||
|
private bool CheckString(uint pos)
|
||||||
|
{
|
||||||
|
var result = CheckVectorOrString(pos, SIZE_BYTE);
|
||||||
|
if (options.stringEndCheck)
|
||||||
|
{
|
||||||
|
result.elementValid = result.elementValid && CheckScalar(result.elementOffset, 1); // Must have terminator
|
||||||
|
result.elementValid = result.elementValid && (verifier_buffer.GetSbyte(Convert.ToInt32(result.elementOffset)) == 0); // Terminating byte must be 0.
|
||||||
|
}
|
||||||
|
return result.elementValid;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary> Verify the vector of elements of given size </summary>
|
||||||
|
private bool CheckVector(uint pos, ulong elementSize)
|
||||||
|
{
|
||||||
|
var result = CheckVectorOrString(pos, elementSize);
|
||||||
|
return result.elementValid;
|
||||||
|
}
|
||||||
|
/// <summary> Verify table content using structure dependent generated function </summary>
|
||||||
|
private bool CheckTable(uint tablePos, VerifyTableAction verifyAction)
|
||||||
|
{
|
||||||
|
return verifyAction(this, tablePos);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary> String check wrapper function to be used in vector of strings check </summary>
|
||||||
|
private bool CheckStringFunc(Verifier verifier, uint pos)
|
||||||
|
{
|
||||||
|
return verifier.CheckString(pos);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary> Check vector of objects. Use generated object verification function </summary>
|
||||||
|
private bool CheckVectorOfObjects(uint pos, VerifyTableAction verifyAction)
|
||||||
|
{
|
||||||
|
if (!CheckVector(pos, SIZE_U_OFFSET))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
uint size = ReadUOffsetT(verifier_buffer, pos);
|
||||||
|
// Vector data starts just after vector size/length
|
||||||
|
uint vecStart = pos + SIZE_U_OFFSET;
|
||||||
|
uint vecOff = 0;
|
||||||
|
// Iterate offsets and verify referenced objects
|
||||||
|
for (uint i = 0; i < size; i++)
|
||||||
|
{
|
||||||
|
vecOff = vecStart + (i * SIZE_U_OFFSET);
|
||||||
|
if (!CheckIndirectOffset(vecOff))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
uint objOffset = GetIndirectOffset(vecOff);
|
||||||
|
if (!verifyAction(this, objOffset))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary> Check if the offset referenced by offsetPos is the valid offset pointing to buffer</summary>
|
||||||
|
// offsetPos - offset to offset data
|
||||||
|
private bool CheckIndirectOffset(uint pos)
|
||||||
|
{
|
||||||
|
// Check the input offset is valid
|
||||||
|
if(!CheckScalar(pos, SIZE_U_OFFSET))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
// Get indirect offset
|
||||||
|
uint offset = ReadUOffsetT(verifier_buffer, pos);
|
||||||
|
// May not point to itself neither wrap around (buffers are max 2GB)
|
||||||
|
if ((offset == 0) || (offset >= FLATBUFFERS_MAX_BUFFER_SIZE))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
// Must be inside the buffer
|
||||||
|
return CheckElement(pos + offset, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary> Check flatbuffer content using generated object verification function </summary>
|
||||||
|
private bool CheckBufferFromStart(string identifier, uint startPos, VerifyTableAction verifyAction)
|
||||||
|
{
|
||||||
|
if ((identifier != null) &&
|
||||||
|
(identifier.Length == 0) &&
|
||||||
|
((verifier_buffer.Length < (SIZE_U_OFFSET + FILE_IDENTIFIER_LENGTH)) || (!BufferHasIdentifier(verifier_buffer, startPos, identifier))))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if(!CheckIndirectOffset(startPos))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
uint offset = GetIndirectOffset(startPos);
|
||||||
|
return CheckTable(offset, verifyAction); // && GetComputedSize()
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary> Get indirect offset. It is an offset referenced by offset Pos </summary>
|
||||||
|
private uint GetIndirectOffset(uint pos)
|
||||||
|
{
|
||||||
|
// Get indirect offset referenced by offsetPos
|
||||||
|
uint offset = pos + ReadUOffsetT(verifier_buffer, pos);
|
||||||
|
return offset;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary> Verify beginning of table </summary>
|
||||||
|
/// <param name="tablePos"> Position in the Table </param>
|
||||||
|
/// <returns> Return True when the verification of the beginning of the table is passed</returns>
|
||||||
|
// (this method is used internally by generated verification functions)
|
||||||
|
public bool VerifyTableStart(uint tablePos)
|
||||||
|
{
|
||||||
|
// Starting new table verification increases complexity of structure
|
||||||
|
depth_cnt++;
|
||||||
|
num_tables_cnt++;
|
||||||
|
|
||||||
|
if (!CheckScalar(tablePos, SIZE_S_OFFSET))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
uint vtable = (uint)(tablePos - ReadSOffsetT(verifier_buffer, Convert.ToInt32(tablePos)));
|
||||||
|
return ((CheckComplexity()) && (CheckScalar(vtable, SIZE_V_OFFSET)) && (CheckAlignment(Convert.ToUInt32(ReadVOffsetT(verifier_buffer, Convert.ToInt32(vtable))), SIZE_V_OFFSET)) && (CheckElement(vtable, Convert.ToUInt64(ReadVOffsetT(verifier_buffer, Convert.ToInt32(vtable))))));
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary> Verify end of table. In practice, this function does not check buffer but handles
|
||||||
|
/// verification statistics update </summary>
|
||||||
|
// (this method is used internally by generated verification functions)
|
||||||
|
public bool VerifyTableEnd(uint tablePos)
|
||||||
|
{
|
||||||
|
depth--;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary> Verifiy static/inlined data area field </summary>
|
||||||
|
/// <param name="tablePos"> Position in the Table</param>
|
||||||
|
/// <param name="offsetId"> Offset to the static/inlined data element </param>
|
||||||
|
/// <param name="elementSize"> Size of the element </param>
|
||||||
|
/// <param name="align"> Alignment bool value </param>
|
||||||
|
/// <param name="required"> Required Value when the offset == 0 </param>
|
||||||
|
/// <returns>Return True when the verification of the static/inlined data element is passed</returns>
|
||||||
|
// (this method is used internally by generated verification functions)
|
||||||
|
public bool VerifyField(uint tablePos, short offsetId, ulong elementSize, ulong align, bool required)
|
||||||
|
{
|
||||||
|
uint offset = GetVOffset(tablePos, offsetId);
|
||||||
|
if (offset != 0)
|
||||||
|
{
|
||||||
|
return ((CheckAlignment(offset, align)) && (CheckElement(offset, elementSize)));
|
||||||
|
}
|
||||||
|
return !required; // it is OK if field is not required
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary> Verify string </summary>
|
||||||
|
/// <param name="tablePos"> Position in the Table</param>
|
||||||
|
/// <param name="vOffset"> Offset to the String element </param>
|
||||||
|
/// <param name="required"> Required Value when the offset == 0 </param>
|
||||||
|
/// <returns>Return True when the verification of the String is passed</returns>
|
||||||
|
// (this method is used internally by generated verification functions)
|
||||||
|
public bool VerifyString(uint tablePos, short vOffset, bool required)
|
||||||
|
{
|
||||||
|
var offset = GetVOffset(tablePos, vOffset);
|
||||||
|
if (offset == 0)
|
||||||
|
{
|
||||||
|
return !required;
|
||||||
|
}
|
||||||
|
if (!CheckIndirectOffset(offset))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
var strOffset = GetIndirectOffset(offset);
|
||||||
|
return CheckString(strOffset);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary> Verify vector of fixed size structures and scalars </summary>
|
||||||
|
/// <param name="tablePos"> Position in the Table</param>
|
||||||
|
/// <param name="vOffset"> Offset to the Vector of Data </param>
|
||||||
|
/// <param name="elementSize"> Size of the element</param>
|
||||||
|
/// <param name="required"> Required Value when the offset == 0 </param>
|
||||||
|
/// <returns>Return True when the verification of the Vector of Data passed</returns>
|
||||||
|
// (this method is used internally by generated verification functions)
|
||||||
|
public bool VerifyVectorOfData(uint tablePos, short vOffset, ulong elementSize, bool required)
|
||||||
|
{
|
||||||
|
var offset = GetVOffset(tablePos, vOffset);
|
||||||
|
if (offset == 0)
|
||||||
|
{
|
||||||
|
return !required;
|
||||||
|
}
|
||||||
|
if (!CheckIndirectOffset(offset))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
var vecOffset = GetIndirectOffset(offset);
|
||||||
|
return CheckVector(vecOffset, elementSize);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary> Verify array of strings </summary>
|
||||||
|
/// <param name="tablePos"> Position in the Table</param>
|
||||||
|
/// <param name="offsetId"> Offset to the Vector of String </param>
|
||||||
|
/// <param name="required"> Required Value when the offset == 0 </param>
|
||||||
|
/// <returns>Return True when the verification of the Vector of String passed</returns>
|
||||||
|
// (this method is used internally by generated verification functions)
|
||||||
|
public bool VerifyVectorOfStrings(uint tablePos, short offsetId, bool required)
|
||||||
|
{
|
||||||
|
var offset = GetVOffset(tablePos, offsetId);
|
||||||
|
if (offset == 0)
|
||||||
|
{
|
||||||
|
return !required;
|
||||||
|
}
|
||||||
|
if (!CheckIndirectOffset(offset))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
var vecOffset = GetIndirectOffset(offset);
|
||||||
|
return CheckVectorOfObjects(vecOffset, CheckStringFunc);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary> Verify vector of tables (objects). Tables are verified using generated verifyObjFunc </summary>
|
||||||
|
/// <param name="tablePos"> Position in the Table</param>
|
||||||
|
/// <param name="offsetId"> Offset to the Vector of Table </param>
|
||||||
|
/// <param name="verifyAction"> Method used to the verification Table </param>
|
||||||
|
/// <param name="required"> Required Value when the offset == 0 </param>
|
||||||
|
/// <returns>Return True when the verification of the Vector of Table passed</returns>
|
||||||
|
// (this method is used internally by generated verification functions)
|
||||||
|
public bool VerifyVectorOfTables(uint tablePos, short offsetId, VerifyTableAction verifyAction, bool required)
|
||||||
|
{
|
||||||
|
var offset = GetVOffset(tablePos, offsetId);
|
||||||
|
if (offset == 0)
|
||||||
|
{
|
||||||
|
return !required;
|
||||||
|
}
|
||||||
|
if (!CheckIndirectOffset(offset))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
var vecOffset = GetIndirectOffset(offset);
|
||||||
|
return CheckVectorOfObjects(vecOffset, verifyAction);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary> Verify table object using generated verification function. </summary>
|
||||||
|
/// <param name="tablePos"> Position in the Table</param>
|
||||||
|
/// <param name="offsetId"> Offset to the Table </param>
|
||||||
|
/// <param name="verifyAction"> Method used to the verification Table </param>
|
||||||
|
/// <param name="required"> Required Value when the offset == 0 </param>
|
||||||
|
/// <returns>Return True when the verification of the Table passed</returns>
|
||||||
|
// (this method is used internally by generated verification functions)
|
||||||
|
public bool VerifyTable(uint tablePos, short offsetId, VerifyTableAction verifyAction, bool required)
|
||||||
|
{
|
||||||
|
var offset = GetVOffset(tablePos, offsetId);
|
||||||
|
if (offset == 0)
|
||||||
|
{
|
||||||
|
return !required;
|
||||||
|
}
|
||||||
|
if (!CheckIndirectOffset(offset))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
var tabOffset = GetIndirectOffset(offset);
|
||||||
|
return CheckTable(tabOffset, verifyAction);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary> Verify nested buffer object. When verifyObjFunc is provided, it is used to verify object structure. </summary>
|
||||||
|
/// <param name="tablePos"> Position in the Table </param>
|
||||||
|
/// <param name="offsetId"> Offset to the Table </param>
|
||||||
|
/// <param name="verifyAction"> Method used to the verification Table </param>
|
||||||
|
/// <param name="required"> Required Value when the offset == 0 </param>
|
||||||
|
// (this method is used internally by generated verification functions)
|
||||||
|
public bool VerifyNestedBuffer(uint tablePos, short offsetId, VerifyTableAction verifyAction, bool required)
|
||||||
|
{
|
||||||
|
var offset = GetVOffset(tablePos, offsetId);
|
||||||
|
if (offset == 0)
|
||||||
|
{
|
||||||
|
return !required;
|
||||||
|
}
|
||||||
|
uint vecOffset = GetIndirectOffset(offset);
|
||||||
|
if (!CheckVector(vecOffset, SIZE_BYTE))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (verifyAction != null)
|
||||||
|
{
|
||||||
|
var vecLength = ReadUOffsetT(verifier_buffer, vecOffset);
|
||||||
|
// Buffer begins after vector length
|
||||||
|
var vecStart = vecOffset + SIZE_U_OFFSET;
|
||||||
|
// Create and Copy nested buffer bytes from part of Verify Buffer
|
||||||
|
var nestedByteBuffer = new ByteBuffer(verifier_buffer.ToArray(Convert.ToInt32(vecStart), Convert.ToInt32(vecLength)));
|
||||||
|
var nestedVerifyier = new Verifier(nestedByteBuffer, options);
|
||||||
|
// There is no internal identifier - use empty one
|
||||||
|
if (!nestedVerifyier.CheckBufferFromStart("", 0, verifyAction))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary> Verifiy static/inlined data area at absolute offset </summary>
|
||||||
|
/// <param name="pos"> Position of static/inlined data area in the Byte Buffer</param>
|
||||||
|
/// <param name="elementSize"> Size of the union data</param>
|
||||||
|
/// <param name="align"> Alignment bool value </param>
|
||||||
|
/// <returns>Return True when the verification of the Union Data is passed</returns>
|
||||||
|
// (this method is used internally by generated verification functions)
|
||||||
|
public bool VerifyUnionData(uint pos, ulong elementSize, ulong align)
|
||||||
|
{
|
||||||
|
bool result = ((CheckAlignment(pos, align)) && (CheckElement(pos, elementSize)));
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary> Verify string referenced by absolute offset value </summary>
|
||||||
|
/// <param name="pos"> Position of Union String in the Byte Buffer</param>
|
||||||
|
/// <returns>Return True when the verification of the Union String is passed</returns>
|
||||||
|
// (this method is used internally by generated verification functions)
|
||||||
|
public bool VerifyUnionString(uint pos)
|
||||||
|
{
|
||||||
|
bool result = CheckString(pos);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary> Method verifies union object using generated verification function </summary>
|
||||||
|
/// <param name="tablePos"> Position in the Table</param>
|
||||||
|
/// <param name="typeIdVOffset"> Offset in the Table</param>
|
||||||
|
/// <param name="valueVOffset"> Offset to Element</param>
|
||||||
|
/// <param name="verifyAction"> Verification Method used for Union</param>
|
||||||
|
/// <param name="required"> Required Value when the offset == 0 </param>
|
||||||
|
// (this method is used internally by generated verification functions)
|
||||||
|
public bool VerifyUnion(uint tablePos, short typeIdVOffset, short valueVOffset, VerifyUnionAction verifyAction, bool required)
|
||||||
|
{
|
||||||
|
// Check the union type index
|
||||||
|
var offset = GetVOffset(tablePos, typeIdVOffset);
|
||||||
|
if (offset == 0)
|
||||||
|
{
|
||||||
|
return !required;
|
||||||
|
}
|
||||||
|
if (!((CheckAlignment(offset, SIZE_BYTE)) && (CheckElement(offset, SIZE_BYTE))))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
// Check union data
|
||||||
|
offset = GetVOffset(tablePos, valueVOffset);
|
||||||
|
// Take type id
|
||||||
|
var typeId = verifier_buffer.Get(Convert.ToInt32(offset));
|
||||||
|
if (offset == 0)
|
||||||
|
{
|
||||||
|
// When value data is not present, allow union verification function to deal with illegal offset
|
||||||
|
return verifyAction(this, typeId, Convert.ToUInt32(verifier_buffer.Length));
|
||||||
|
}
|
||||||
|
if (!CheckIndirectOffset(offset))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
// Take value offset and validate union structure
|
||||||
|
uint unionOffset = GetIndirectOffset(offset);
|
||||||
|
return verifyAction(this, typeId, unionOffset);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary> Verify vector of unions (objects). Unions are verified using generated verifyObjFunc </summary>
|
||||||
|
/// <param name="tablePos"> Position of the Table</param>
|
||||||
|
/// <param name="typeOffsetId"> Offset in the Table (Union type id)</param>
|
||||||
|
/// <param name="offsetId"> Offset to vector of Data Stucture offset</param>
|
||||||
|
/// <param name="verifyAction"> Verification Method used for Union</param>
|
||||||
|
/// <param name="required"> Required Value when the offset == 0 </param>
|
||||||
|
/// <returns>Return True when the verification of the Vector of Unions passed</returns>
|
||||||
|
// (this method is used internally by generated verification functions)
|
||||||
|
public bool VerifyVectorOfUnion(uint tablePos, short typeOffsetId, short offsetId, VerifyUnionAction verifyAction, bool required)
|
||||||
|
{
|
||||||
|
// type id offset must be valid
|
||||||
|
var offset = GetVOffset(tablePos, typeOffsetId);
|
||||||
|
if (offset == 0)
|
||||||
|
{
|
||||||
|
return !required;
|
||||||
|
}
|
||||||
|
if (!CheckIndirectOffset(offset))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
// Get type id table absolute offset
|
||||||
|
var typeIdVectorOffset = GetIndirectOffset(offset);
|
||||||
|
// values offset must be valid
|
||||||
|
offset = GetVOffset(tablePos, offsetId);
|
||||||
|
if (!CheckIndirectOffset(offset))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
var valueVectorOffset = GetIndirectOffset(offset);
|
||||||
|
// validate referenced vectors
|
||||||
|
if(!CheckVector(typeIdVectorOffset, SIZE_BYTE) ||
|
||||||
|
!CheckVector(valueVectorOffset, SIZE_U_OFFSET))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
// Both vectors should have the same length
|
||||||
|
var typeIdVectorLength = ReadUOffsetT(verifier_buffer, typeIdVectorOffset);
|
||||||
|
var valueVectorLength = ReadUOffsetT(verifier_buffer, valueVectorOffset);
|
||||||
|
if (typeIdVectorLength != valueVectorLength)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
// Verify each union from vectors
|
||||||
|
var typeIdStart = typeIdVectorOffset + SIZE_U_OFFSET;
|
||||||
|
var valueStart = valueVectorOffset + SIZE_U_OFFSET;
|
||||||
|
for (uint i = 0; i < typeIdVectorLength; i++)
|
||||||
|
{
|
||||||
|
// Get type id
|
||||||
|
byte typeId = verifier_buffer.Get(Convert.ToInt32(typeIdStart + i * SIZE_U_OFFSET));
|
||||||
|
// get offset to vector item
|
||||||
|
uint off = valueStart + i * SIZE_U_OFFSET;
|
||||||
|
// Check the vector item has a proper offset
|
||||||
|
if (!CheckIndirectOffset(off))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
uint valueOffset = GetIndirectOffset(off);
|
||||||
|
// Verify object
|
||||||
|
if (!verifyAction(this, typeId, valueOffset))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Method verifies flatbuffer data using generated Table verification function.
|
||||||
|
// The data buffer is already provided when creating [Verifier] object (see [NewVerifier])
|
||||||
|
//
|
||||||
|
// - identifier - the expected identifier of buffer data.
|
||||||
|
// When empty identifier is provided the identifier validation is skipped.
|
||||||
|
// - sizePrefixed - this flag should be true when buffer is prefixed with content size
|
||||||
|
// - verifyObjFunc - function to be used for verification. This function is generated by compiler and included in each table definition file with name "<Tablename>Verify"
|
||||||
|
//
|
||||||
|
// Example:
|
||||||
|
//
|
||||||
|
// /* Verify Monster table. Ignore buffer name and assume buffer does not contain data length prefix */
|
||||||
|
// isValid = verifier.verifyBuffer(bb, false, MonsterVerify)
|
||||||
|
//
|
||||||
|
// /* Verify Monster table. Buffer name is 'MONS' and contains data length prefix */
|
||||||
|
// isValid = verifier.verifyBuffer("MONS", true, MonsterVerify)
|
||||||
|
/// <summary> Method verifies flatbuffer data using generated Table verification function </summary>
|
||||||
|
///
|
||||||
|
/// <param name="identifier"> The expected identifier of buffer data</param>
|
||||||
|
/// <param name="sizePrefixed"> Flag should be true when buffer is prefixed with content size</param>
|
||||||
|
/// <param name="verifyAction"> Function to be used for verification. This function is generated by compiler and included in each table definition file</param>
|
||||||
|
/// <returns> Return True when verification of FlatBuffer passed</returns>
|
||||||
|
/// <example>
|
||||||
|
/// Example 1. Verify Monster table. Ignore buffer name and assume buffer does not contain data length prefix
|
||||||
|
/// <code> isValid = verifier.VerifyBuffer(bb, false, MonsterVerify)</code>
|
||||||
|
/// Example 2. Verify Monster table. Buffer name is 'MONS' and contains data length prefix
|
||||||
|
/// <code> isValid = verifier.VerifyBuffer("MONS", true, MonsterVerify)</code>
|
||||||
|
/// </example>
|
||||||
|
public bool VerifyBuffer(string identifier, bool sizePrefixed, VerifyTableAction verifyAction)
|
||||||
|
{
|
||||||
|
// Reset counters - starting verification from beginning
|
||||||
|
depth = 0;
|
||||||
|
numTables = 0;
|
||||||
|
|
||||||
|
var start = (uint)(verifier_buffer.Position);
|
||||||
|
if (sizePrefixed)
|
||||||
|
{
|
||||||
|
start = (uint)(verifier_buffer.Position) + SIZE_PREFIX_LENGTH;
|
||||||
|
if(!CheckScalar((uint)(verifier_buffer.Position), SIZE_PREFIX_LENGTH))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
uint size = ReadUOffsetT(verifier_buffer, (uint)(verifier_buffer.Position));
|
||||||
|
if (size != ((uint)(verifier_buffer.Length) - start))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return CheckBufferFromStart(identifier, start, verifyAction);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user