mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-13 00:04:29 +00:00
Compare commits
110 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 | ||
|
|
01834de25e | ||
|
|
6f9ea7c23c | ||
|
|
de9791e0a9 | ||
|
|
3e778aca4d | ||
|
|
01f4138618 | ||
|
|
b90cc35a10 | ||
|
|
79d6abb42e | ||
|
|
d1e4daa178 | ||
|
|
4a34cd70dc | ||
|
|
6a9cd4411f | ||
|
|
f7a75173f1 | ||
|
|
a56f9ec50e | ||
|
|
4c71f87619 | ||
|
|
6af83a7d05 | ||
|
|
535ead8d8c | ||
|
|
85aee1f5c3 | ||
|
|
f3a3f45159 | ||
|
|
02d7859f8b | ||
|
|
5785784c8a | ||
|
|
0fb5519585 | ||
|
|
f838017860 | ||
|
|
08ebd202e2 | ||
|
|
a6f4194489 | ||
|
|
7fb785fd89 | ||
|
|
ca71fdfb9a | ||
|
|
a105c26eca | ||
|
|
5b7a02d037 | ||
|
|
f5121615d9 | ||
|
|
34c821f4ad | ||
|
|
802a3a056a | ||
|
|
ee848a02e1 | ||
|
|
ef76b5ece4 | ||
|
|
1703662285 | ||
|
|
991b39edbe | ||
|
|
81799203f1 | ||
|
|
62e4d2e5b2 | ||
|
|
40758674b1 | ||
|
|
4e75867bd2 | ||
|
|
b17d59b18c | ||
|
|
b23493a7d2 | ||
|
|
b50b6be60a | ||
|
|
7bf83f5ea0 | ||
|
|
ca6381bcc8 | ||
|
|
3b8644d32c | ||
|
|
641fbe4658 | ||
|
|
5638a6a900 | ||
|
|
c2668fc0e2 | ||
|
|
b5802b57f2 | ||
|
|
06f2a3dce9 | ||
|
|
75af533e95 | ||
|
|
c95cf661af | ||
|
|
920f3827a0 | ||
|
|
81724e5b20 | ||
|
|
4d6a7aa8b7 | ||
|
|
e61b00359b | ||
|
|
74b5195089 | ||
|
|
07d9485146 | ||
|
|
82da3da3f6 | ||
|
|
a809a2d3f7 |
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
|
||||||
@@ -5,3 +5,4 @@ root = true
|
|||||||
indent_style = space
|
indent_style = space
|
||||||
indent_size = 2
|
indent_size = 2
|
||||||
insert_final_newline = true
|
insert_final_newline = true
|
||||||
|
trim_trailing_whitespace = true
|
||||||
|
|||||||
49
.github/workflows/build.yml
vendored
49
.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
|
||||||
@@ -38,8 +39,10 @@ jobs:
|
|||||||
run: |
|
run: |
|
||||||
chmod +x flatc
|
chmod +x flatc
|
||||||
./flatc --version
|
./flatc --version
|
||||||
- name: flatc tests
|
# - name: flatc tests
|
||||||
run: python3 tests/flatc/main.py
|
# run: |
|
||||||
|
# yarn global add esbuild
|
||||||
|
# python3 tests/flatc/main.py
|
||||||
- name: upload build artifacts
|
- name: upload build artifacts
|
||||||
uses: actions/upload-artifact@v1
|
uses: actions/upload-artifact@v1
|
||||||
with:
|
with:
|
||||||
@@ -57,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
|
||||||
@@ -143,8 +146,8 @@ jobs:
|
|||||||
run: msbuild.exe FlatBuffers.sln /p:Configuration=Release /p:Platform=x64
|
run: msbuild.exe FlatBuffers.sln /p:Configuration=Release /p:Platform=x64
|
||||||
- name: test
|
- name: test
|
||||||
run: Release\flattests.exe
|
run: Release\flattests.exe
|
||||||
- name: flatc tests
|
# - name: flatc tests
|
||||||
run: python3 tests/flatc/main.py --flatc Release\flatc.exe
|
# run: python3 tests/flatc/main.py --flatc Release\flatc.exe
|
||||||
- name: upload build artifacts
|
- name: upload build artifacts
|
||||||
uses: actions/upload-artifact@v1
|
uses: actions/upload-artifact@v1
|
||||||
with:
|
with:
|
||||||
@@ -163,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
|
||||||
@@ -245,8 +248,8 @@ jobs:
|
|||||||
run: |
|
run: |
|
||||||
chmod +x Release/flatc
|
chmod +x Release/flatc
|
||||||
Release/flatc --version
|
Release/flatc --version
|
||||||
- name: flatc tests
|
# - name: flatc tests
|
||||||
run: python3 tests/flatc/main.py --flatc Release/flatc
|
# run: python3 tests/flatc/main.py --flatc Release/flatc
|
||||||
- name: upload build artifacts
|
- name: upload build artifacts
|
||||||
uses: actions/upload-artifact@v1
|
uses: actions/upload-artifact@v1
|
||||||
with:
|
with:
|
||||||
@@ -264,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:
|
||||||
@@ -307,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)
|
||||||
@@ -343,6 +346,22 @@ jobs:
|
|||||||
- name: Generate gRPC
|
- name: Generate gRPC
|
||||||
run: scripts/check-grpc-generated-code.py
|
run: scripts/check-grpc-generated-code.py
|
||||||
|
|
||||||
|
build-generator-windows:
|
||||||
|
name: Check Generated Code on Windows
|
||||||
|
runs-on: windows-2019
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
- name: Add msbuild to PATH
|
||||||
|
uses: microsoft/setup-msbuild@v1.1
|
||||||
|
- name: cmake
|
||||||
|
run: cmake -G "Visual Studio 16 2019" -A x64 -DCMAKE_BUILD_TYPE=Release -DFLATBUFFERS_BUILD_CPP17=ON -DFLATBUFFERS_STRICT_MODE=ON .
|
||||||
|
- name: build
|
||||||
|
run: msbuild.exe FlatBuffers.sln /p:Configuration=Release /p:Platform=x64
|
||||||
|
- name: Generate
|
||||||
|
run: python3 scripts/check_generate_code.py --flatc Release\flatc.exe
|
||||||
|
- name: Generate gRPC
|
||||||
|
run: python3 scripts/check-grpc-generated-code.py --flatc Release\flatc.exe
|
||||||
|
|
||||||
build-benchmarks:
|
build-benchmarks:
|
||||||
name: Build Benchmarks (on Linux)
|
name: Build Benchmarks (on Linux)
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
@@ -485,7 +504,9 @@ jobs:
|
|||||||
run: yarn compile
|
run: yarn compile
|
||||||
- name: test
|
- name: test
|
||||||
working-directory: tests/ts
|
working-directory: tests/ts
|
||||||
run: python3 TypeScriptTest.py
|
run: |
|
||||||
|
yarn global add esbuild
|
||||||
|
python3 TypeScriptTest.py
|
||||||
|
|
||||||
build-dart:
|
build-dart:
|
||||||
name: Build Dart
|
name: Build Dart
|
||||||
@@ -540,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
|
||||||
|
|
||||||
|
|||||||
29
BUILD.bazel
29
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",
|
||||||
@@ -41,12 +67,13 @@ filegroup(
|
|||||||
"include/flatbuffers/allocator.h",
|
"include/flatbuffers/allocator.h",
|
||||||
"include/flatbuffers/array.h",
|
"include/flatbuffers/array.h",
|
||||||
"include/flatbuffers/base.h",
|
"include/flatbuffers/base.h",
|
||||||
"include/flatbuffers/bfbs_generator.h",
|
|
||||||
"include/flatbuffers/buffer.h",
|
"include/flatbuffers/buffer.h",
|
||||||
"include/flatbuffers/buffer_ref.h",
|
"include/flatbuffers/buffer_ref.h",
|
||||||
|
"include/flatbuffers/code_generator.h",
|
||||||
"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",
|
||||||
|
|||||||
58
CHANGELOG.md
58
CHANGELOG.md
@@ -4,6 +4,64 @@ 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)
|
||||||
|
|
||||||
|
* Refactoring of `flatc` generators to use an interface (#7797).
|
||||||
|
|
||||||
|
* Removed legacy cmake support and set min to 3.8 (#7801).
|
||||||
|
|
||||||
|
## [23.1.21 (Jan 21 2023)](https://github.com/google/flatbuffers/releases/tag/v23.1.20)
|
||||||
|
|
||||||
|
* Reworked entry points for Typescript/Javascript and compatibility for single
|
||||||
|
file build (#7510)
|
||||||
|
|
||||||
|
## [23.1.20 (Jan 20 2023)](https://github.com/google/flatbuffers/releases/tag/v23.1.20)
|
||||||
|
|
||||||
|
* Removed go.mod files after some versioning issues were being report (#7780).
|
||||||
|
|
||||||
## [23.1.4 (Jan 4 2023)](https://github.com/google/flatbuffers/releases/tag/v23.1.4)
|
## [23.1.4 (Jan 4 2023)](https://github.com/google/flatbuffers/releases/tag/v23.1.4)
|
||||||
|
|
||||||
* Major release! Just kidding, we are continuing the
|
* Major release! Just kidding, we are continuing the
|
||||||
|
|||||||
@@ -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)
|
||||||
@@ -157,6 +160,10 @@ endfunction()
|
|||||||
# other flagc flags using the FLAGS option to change the behavior of the flatc
|
# other flagc flags using the FLAGS option to change the behavior of the flatc
|
||||||
# tool.
|
# tool.
|
||||||
#
|
#
|
||||||
|
# When the target_link_libraries is done within a different directory than
|
||||||
|
# flatbuffers_generate_headers is called, then the target should also be dependent
|
||||||
|
# the custom generation target called GENERATE_<TARGET>.
|
||||||
|
#
|
||||||
# Arguments:
|
# Arguments:
|
||||||
# TARGET: The name of the target to generate.
|
# TARGET: The name of the target to generate.
|
||||||
# SCHEMAS: The list of schema files to generate code for.
|
# SCHEMAS: The list of schema files to generate code for.
|
||||||
@@ -182,6 +189,9 @@ endfunction()
|
|||||||
# target_link_libraries(MyExecutableTarget
|
# target_link_libraries(MyExecutableTarget
|
||||||
# PRIVATE my_generated_headers_target
|
# PRIVATE my_generated_headers_target
|
||||||
# )
|
# )
|
||||||
|
#
|
||||||
|
# Optional (only needed within different directory):
|
||||||
|
# add_dependencies(app GENERATE_my_generated_headers_target)
|
||||||
function(flatbuffers_generate_headers)
|
function(flatbuffers_generate_headers)
|
||||||
# Parse function arguments.
|
# Parse function arguments.
|
||||||
set(options)
|
set(options)
|
||||||
@@ -204,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)
|
||||||
@@ -226,6 +239,8 @@ function(flatbuffers_generate_headers)
|
|||||||
"--include-prefix" ${FLATBUFFERS_GENERATE_HEADERS_INCLUDE_PREFIX})
|
"--include-prefix" ${FLATBUFFERS_GENERATE_HEADERS_INCLUDE_PREFIX})
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
set(generated_custom_commands)
|
||||||
|
|
||||||
# Create rules to generate the code for each schema.
|
# Create rules to generate the code for each schema.
|
||||||
foreach(schema ${FLATBUFFERS_GENERATE_HEADERS_SCHEMAS})
|
foreach(schema ${FLATBUFFERS_GENERATE_HEADERS_SCHEMAS})
|
||||||
get_filename_component(filename ${schema} NAME_WE)
|
get_filename_component(filename ${schema} NAME_WE)
|
||||||
@@ -254,6 +269,7 @@ function(flatbuffers_generate_headers)
|
|||||||
COMMENT "Building ${schema} flatbuffers...")
|
COMMENT "Building ${schema} flatbuffers...")
|
||||||
list(APPEND all_generated_header_files ${generated_include})
|
list(APPEND all_generated_header_files ${generated_include})
|
||||||
list(APPEND all_generated_source_files ${generated_source_file})
|
list(APPEND all_generated_source_files ${generated_source_file})
|
||||||
|
list(APPEND generated_custom_commands "${generated_include}" "${generated_source_file}")
|
||||||
|
|
||||||
# Geneate the binary flatbuffers schemas if instructed to.
|
# Geneate the binary flatbuffers schemas if instructed to.
|
||||||
if (NOT ${FLATBUFFERS_GENERATE_HEADERS_BINARY_SCHEMAS_DIR} STREQUAL "")
|
if (NOT ${FLATBUFFERS_GENERATE_HEADERS_BINARY_SCHEMAS_DIR} STREQUAL "")
|
||||||
@@ -267,10 +283,17 @@ function(flatbuffers_generate_headers)
|
|||||||
${schema}
|
${schema}
|
||||||
DEPENDS ${FLATC_TARGET} ${schema}
|
DEPENDS ${FLATC_TARGET} ${schema}
|
||||||
WORKING_DIRECTORY "${working_dir}")
|
WORKING_DIRECTORY "${working_dir}")
|
||||||
|
list(APPEND generated_custom_commands "${binary_schema}")
|
||||||
list(APPEND all_generated_binary_files ${binary_schema})
|
list(APPEND all_generated_binary_files ${binary_schema})
|
||||||
endif()
|
endif()
|
||||||
endforeach()
|
endforeach()
|
||||||
|
|
||||||
|
# Create an additional target as add_custom_command scope is only within same directory (CMakeFile.txt)
|
||||||
|
set(generate_target GENERATE_${FLATBUFFERS_GENERATE_HEADERS_TARGET})
|
||||||
|
add_custom_target(${generate_target} ALL
|
||||||
|
DEPENDS ${generated_custom_commands}
|
||||||
|
COMMENT "Generating flatbuffer target ${FLATBUFFERS_GENERATE_HEADERS_TARGET}")
|
||||||
|
|
||||||
# Set up interface library
|
# Set up interface library
|
||||||
add_library(${FLATBUFFERS_GENERATE_HEADERS_TARGET} INTERFACE)
|
add_library(${FLATBUFFERS_GENERATE_HEADERS_TARGET} INTERFACE)
|
||||||
target_sources(
|
target_sources(
|
||||||
@@ -365,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)
|
||||||
|
|||||||
@@ -1,780 +0,0 @@
|
|||||||
# This was the legacy <root>/CMakeLists.txt that supported cmake version 2.8.12.
|
|
||||||
# It was originally copied on Jan 30 2022, and is conditionally included in the
|
|
||||||
# current <root>/CMakeLists.txt if the cmake version used is older than the new
|
|
||||||
# minimum version.
|
|
||||||
#
|
|
||||||
# Only add to this file to fix immediate issues or if a change cannot be made
|
|
||||||
# <root>/CMakeList.txt in a compatible way.
|
|
||||||
|
|
||||||
if (POLICY CMP0048)
|
|
||||||
cmake_policy(SET CMP0048 NEW)
|
|
||||||
if(CMAKE_VERSION VERSION_LESS 3.9)
|
|
||||||
project(FlatBuffers
|
|
||||||
VERSION 2.0.0
|
|
||||||
LANGUAGES CXX)
|
|
||||||
else()
|
|
||||||
project(FlatBuffers
|
|
||||||
DESCRIPTION "Flatbuffers serialization library"
|
|
||||||
VERSION 2.0.0
|
|
||||||
LANGUAGES CXX)
|
|
||||||
endif()
|
|
||||||
else()
|
|
||||||
project(FlatBuffers)
|
|
||||||
endif (POLICY CMP0048)
|
|
||||||
|
|
||||||
include(CMake/Version.cmake)
|
|
||||||
|
|
||||||
# generate compile_commands.json
|
|
||||||
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
|
||||||
|
|
||||||
# NOTE: Code coverage only works on Linux & OSX.
|
|
||||||
option(FLATBUFFERS_CODE_COVERAGE "Enable the code coverage build option." OFF)
|
|
||||||
option(FLATBUFFERS_BUILD_TESTS "Enable the build of tests and samples." ON)
|
|
||||||
option(FLATBUFFERS_INSTALL "Enable the installation of targets." ON)
|
|
||||||
option(FLATBUFFERS_BUILD_FLATLIB "Enable the build of the flatbuffers library"
|
|
||||||
ON)
|
|
||||||
option(FLATBUFFERS_BUILD_FLATC "Enable the build of the flatbuffers compiler"
|
|
||||||
ON)
|
|
||||||
option(FLATBUFFERS_STATIC_FLATC "Build flatbuffers compiler with -static flag"
|
|
||||||
OFF)
|
|
||||||
option(FLATBUFFERS_BUILD_FLATHASH "Enable the build of flathash" ON)
|
|
||||||
option(FLATBUFFERS_BUILD_BENCHMARKS "Enable the build of flatbenchmark. \"
|
|
||||||
Requires C++11."
|
|
||||||
OFF)
|
|
||||||
option(FLATBUFFERS_BUILD_GRPCTEST "Enable the build of grpctest" OFF)
|
|
||||||
option(FLATBUFFERS_BUILD_SHAREDLIB
|
|
||||||
"Enable the build of the flatbuffers shared library"
|
|
||||||
OFF)
|
|
||||||
option(FLATBUFFERS_LIBCXX_WITH_CLANG "Force libc++ when using Clang" ON)
|
|
||||||
# NOTE: Sanitizer check only works on Linux & OSX (gcc & llvm).
|
|
||||||
option(FLATBUFFERS_CODE_SANITIZE
|
|
||||||
"Add '-fsanitize' flags to 'flattests' and 'flatc' targets."
|
|
||||||
OFF)
|
|
||||||
option(FLATBUFFERS_PACKAGE_REDHAT
|
|
||||||
"Build an rpm using the 'package' target."
|
|
||||||
OFF)
|
|
||||||
option(FLATBUFFERS_PACKAGE_DEBIAN
|
|
||||||
"Build an deb using the 'package' target."
|
|
||||||
OFF)
|
|
||||||
option(FLATBUFFERS_BUILD_CPP17
|
|
||||||
"Enable the build of c++17 test target. \"
|
|
||||||
Requirements: Clang6, GCC7, MSVC2017 (_MSC_VER >= 1914) or higher."
|
|
||||||
OFF)
|
|
||||||
option(FLATBUFFERS_BUILD_LEGACY
|
|
||||||
"Run C++ code generator with '--cpp-std c++0x' switch."
|
|
||||||
OFF)
|
|
||||||
option(FLATBUFFERS_ENABLE_PCH
|
|
||||||
"Enable precompile headers support for 'flatbuffers' and 'flatc'. \"
|
|
||||||
Only work if CMake supports 'target_precompile_headers'. \"
|
|
||||||
This can speed up compilation time."
|
|
||||||
OFF)
|
|
||||||
option(FLATBUFFERS_SKIP_MONSTER_EXTRA
|
|
||||||
"Skip generating monster_extra.fbs that contains non-supported numerical\"
|
|
||||||
types." OFF)
|
|
||||||
option(FLATBUFFERS_OSX_BUILD_UNIVERSAL
|
|
||||||
"Enable the build for multiple architectures on OS X (arm64, x86_64)."
|
|
||||||
ON)
|
|
||||||
|
|
||||||
if(NOT FLATBUFFERS_BUILD_FLATC AND FLATBUFFERS_BUILD_TESTS)
|
|
||||||
message(WARNING
|
|
||||||
"Cannot build tests without building the compiler. Tests will be disabled.")
|
|
||||||
set(FLATBUFFERS_BUILD_TESTS OFF)
|
|
||||||
endif()
|
|
||||||
|
|
||||||
if(DEFINED FLATBUFFERS_MAX_PARSING_DEPTH)
|
|
||||||
# Override the default recursion depth limit.
|
|
||||||
add_definitions(-DFLATBUFFERS_MAX_PARSING_DEPTH=${FLATBUFFERS_MAX_PARSING_DEPTH})
|
|
||||||
message(STATUS "FLATBUFFERS_MAX_PARSING_DEPTH: ${FLATBUFFERS_MAX_PARSING_DEPTH}")
|
|
||||||
endif()
|
|
||||||
|
|
||||||
# Auto-detect locale-narrow 'strtod_l' and 'strtoull_l' functions.
|
|
||||||
if(NOT DEFINED FLATBUFFERS_LOCALE_INDEPENDENT)
|
|
||||||
include(CheckCXXSymbolExists)
|
|
||||||
|
|
||||||
set(FLATBUFFERS_LOCALE_INDEPENDENT 0)
|
|
||||||
if(MSVC)
|
|
||||||
check_cxx_symbol_exists(_strtof_l stdlib.h FLATBUFFERS_HAS_STRTOF_L)
|
|
||||||
check_cxx_symbol_exists(_strtoui64_l stdlib.h FLATBUFFERS_HAS_STRTOULL_L)
|
|
||||||
else()
|
|
||||||
check_cxx_symbol_exists(strtof_l stdlib.h FLATBUFFERS_HAS_STRTOF_L)
|
|
||||||
check_cxx_symbol_exists(strtoull_l stdlib.h FLATBUFFERS_HAS_STRTOULL_L)
|
|
||||||
endif()
|
|
||||||
if(FLATBUFFERS_HAS_STRTOF_L AND FLATBUFFERS_HAS_STRTOULL_L)
|
|
||||||
set(FLATBUFFERS_LOCALE_INDEPENDENT 1)
|
|
||||||
endif()
|
|
||||||
endif()
|
|
||||||
add_definitions(-DFLATBUFFERS_LOCALE_INDEPENDENT=$<BOOL:${FLATBUFFERS_LOCALE_INDEPENDENT}>)
|
|
||||||
|
|
||||||
set(FlatBuffers_Library_SRCS
|
|
||||||
include/flatbuffers/allocator.h
|
|
||||||
include/flatbuffers/array.h
|
|
||||||
include/flatbuffers/base.h
|
|
||||||
include/flatbuffers/bfbs_generator.h
|
|
||||||
include/flatbuffers/buffer.h
|
|
||||||
include/flatbuffers/buffer_ref.h
|
|
||||||
include/flatbuffers/default_allocator.h
|
|
||||||
include/flatbuffers/detached_buffer.h
|
|
||||||
include/flatbuffers/flatbuffer_builder.h
|
|
||||||
include/flatbuffers/flatbuffers.h
|
|
||||||
include/flatbuffers/flexbuffers.h
|
|
||||||
include/flatbuffers/hash.h
|
|
||||||
include/flatbuffers/idl.h
|
|
||||||
include/flatbuffers/minireflect.h
|
|
||||||
include/flatbuffers/reflection.h
|
|
||||||
include/flatbuffers/reflection_generated.h
|
|
||||||
include/flatbuffers/registry.h
|
|
||||||
include/flatbuffers/stl_emulation.h
|
|
||||||
include/flatbuffers/string.h
|
|
||||||
include/flatbuffers/struct.h
|
|
||||||
include/flatbuffers/table.h
|
|
||||||
include/flatbuffers/util.h
|
|
||||||
include/flatbuffers/vector.h
|
|
||||||
include/flatbuffers/vector_downward.h
|
|
||||||
include/flatbuffers/verifier.h
|
|
||||||
src/idl_parser.cpp
|
|
||||||
src/idl_gen_text.cpp
|
|
||||||
src/reflection.cpp
|
|
||||||
src/util.cpp
|
|
||||||
)
|
|
||||||
|
|
||||||
set(FlatBuffers_Compiler_SRCS
|
|
||||||
${FlatBuffers_Library_SRCS}
|
|
||||||
src/idl_gen_cpp.cpp
|
|
||||||
src/idl_gen_csharp.cpp
|
|
||||||
src/idl_gen_dart.cpp
|
|
||||||
src/idl_gen_kotlin.cpp
|
|
||||||
src/idl_gen_go.cpp
|
|
||||||
src/idl_gen_java.cpp
|
|
||||||
src/idl_gen_ts.cpp
|
|
||||||
src/idl_gen_php.cpp
|
|
||||||
src/idl_gen_python.cpp
|
|
||||||
src/idl_gen_lobster.cpp
|
|
||||||
src/idl_gen_lua.cpp
|
|
||||||
src/idl_gen_rust.cpp
|
|
||||||
src/idl_gen_fbs.cpp
|
|
||||||
src/idl_gen_grpc.cpp
|
|
||||||
src/idl_gen_json_schema.cpp
|
|
||||||
src/idl_gen_swift.cpp
|
|
||||||
src/flatc.cpp
|
|
||||||
src/flatc_main.cpp
|
|
||||||
src/bfbs_gen.h
|
|
||||||
src/bfbs_gen_lua.h
|
|
||||||
include/flatbuffers/code_generators.h
|
|
||||||
src/bfbs_gen_lua.cpp
|
|
||||||
src/code_generators.cpp
|
|
||||||
grpc/src/compiler/schema_interface.h
|
|
||||||
grpc/src/compiler/cpp_generator.h
|
|
||||||
grpc/src/compiler/cpp_generator.cc
|
|
||||||
grpc/src/compiler/go_generator.h
|
|
||||||
grpc/src/compiler/go_generator.cc
|
|
||||||
grpc/src/compiler/java_generator.h
|
|
||||||
grpc/src/compiler/java_generator.cc
|
|
||||||
grpc/src/compiler/python_generator.h
|
|
||||||
grpc/src/compiler/python_generator.cc
|
|
||||||
grpc/src/compiler/swift_generator.h
|
|
||||||
grpc/src/compiler/swift_generator.cc
|
|
||||||
grpc/src/compiler/ts_generator.h
|
|
||||||
grpc/src/compiler/ts_generator.cc
|
|
||||||
)
|
|
||||||
|
|
||||||
set(FlatHash_SRCS
|
|
||||||
include/flatbuffers/hash.h
|
|
||||||
src/flathash.cpp
|
|
||||||
)
|
|
||||||
|
|
||||||
set(FlatBuffers_Tests_SRCS
|
|
||||||
${FlatBuffers_Library_SRCS}
|
|
||||||
src/idl_gen_fbs.cpp
|
|
||||||
tests/test.cpp
|
|
||||||
tests/test_assert.h
|
|
||||||
tests/test_assert.cpp
|
|
||||||
tests/test_builder.h
|
|
||||||
tests/test_builder.cpp
|
|
||||||
tests/native_type_test_impl.h
|
|
||||||
tests/native_type_test_impl.cpp
|
|
||||||
include/flatbuffers/code_generators.h
|
|
||||||
src/code_generators.cpp
|
|
||||||
# file generate by running compiler on tests/monster_test.fbs
|
|
||||||
${CMAKE_CURRENT_BINARY_DIR}/tests/monster_test_generated.h
|
|
||||||
# file generate by running compiler on namespace_test/namespace_test1.fbs
|
|
||||||
${CMAKE_CURRENT_BINARY_DIR}/tests/namespace_test/namespace_test1_generated.h
|
|
||||||
${CMAKE_CURRENT_BINARY_DIR}/tests/namespace_test/namespace_test2_generated.h
|
|
||||||
# file generate by running compiler on union_vector/union_vector.fbs
|
|
||||||
${CMAKE_CURRENT_BINARY_DIR}/tests/union_vector/union_vector_generated.h
|
|
||||||
# file generate by running compiler on tests/arrays_test.fbs
|
|
||||||
${CMAKE_CURRENT_BINARY_DIR}/tests/arrays_test_generated.h
|
|
||||||
# file generate by running compiler on tests/native_type_test.fbs
|
|
||||||
${CMAKE_CURRENT_BINARY_DIR}/tests/native_type_test_generated.h
|
|
||||||
# file generate by running compiler on tests/monster_extra.fbs
|
|
||||||
${CMAKE_CURRENT_BINARY_DIR}/tests/monster_extra_generated.h
|
|
||||||
# file generate by running compiler on tests/monster_test.fbs
|
|
||||||
${CMAKE_CURRENT_BINARY_DIR}/tests/monster_test_bfbs_generated.h
|
|
||||||
# file generate by running compiler on tests/optional_scalars.fbs
|
|
||||||
${CMAKE_CURRENT_BINARY_DIR}/tests/optional_scalars_generated.h
|
|
||||||
)
|
|
||||||
|
|
||||||
set(FlatBuffers_Tests_CPP17_SRCS
|
|
||||||
${FlatBuffers_Library_SRCS}
|
|
||||||
tests/test_assert.h
|
|
||||||
tests/test_assert.cpp
|
|
||||||
tests/cpp17/test_cpp17.cpp
|
|
||||||
# file generate by running compiler on tests/monster_test.fbs
|
|
||||||
${CMAKE_CURRENT_BINARY_DIR}/tests/cpp17/generated_cpp17/monster_test_generated.h
|
|
||||||
${CMAKE_CURRENT_BINARY_DIR}/tests/monster_test_generated.h
|
|
||||||
${CMAKE_CURRENT_BINARY_DIR}/tests/cpp17/generated_cpp17/optional_scalars_generated.h
|
|
||||||
${CMAKE_CURRENT_BINARY_DIR}/tests/optional_scalars_generated.h
|
|
||||||
)
|
|
||||||
|
|
||||||
set(FlatBuffers_Sample_Binary_SRCS
|
|
||||||
include/flatbuffers/flatbuffers.h
|
|
||||||
samples/sample_binary.cpp
|
|
||||||
# file generated by running compiler on samples/monster.fbs
|
|
||||||
${CMAKE_CURRENT_BINARY_DIR}/samples/monster_generated.h
|
|
||||||
)
|
|
||||||
|
|
||||||
set(FlatBuffers_Sample_Text_SRCS
|
|
||||||
${FlatBuffers_Library_SRCS}
|
|
||||||
samples/sample_text.cpp
|
|
||||||
# file generated by running compiler on samples/monster.fbs
|
|
||||||
${CMAKE_CURRENT_BINARY_DIR}/samples/monster_generated.h
|
|
||||||
)
|
|
||||||
|
|
||||||
set(FlatBuffers_Sample_BFBS_SRCS
|
|
||||||
${FlatBuffers_Library_SRCS}
|
|
||||||
samples/sample_bfbs.cpp
|
|
||||||
# file generated by running compiler on samples/monster.fbs
|
|
||||||
${CMAKE_CURRENT_BINARY_DIR}/samples/monster_generated.h
|
|
||||||
)
|
|
||||||
|
|
||||||
set(FlatBuffers_GRPCTest_SRCS
|
|
||||||
include/flatbuffers/flatbuffers.h
|
|
||||||
include/flatbuffers/grpc.h
|
|
||||||
include/flatbuffers/util.h
|
|
||||||
src/util.cpp
|
|
||||||
tests/monster_test.grpc.fb.h
|
|
||||||
tests/test_assert.h
|
|
||||||
tests/test_builder.h
|
|
||||||
tests/monster_test.grpc.fb.cc
|
|
||||||
tests/test_assert.cpp
|
|
||||||
tests/test_builder.cpp
|
|
||||||
grpc/tests/grpctest.cpp
|
|
||||||
grpc/tests/message_builder_test.cpp
|
|
||||||
# file generate by running compiler on tests/monster_test.fbs
|
|
||||||
${CMAKE_CURRENT_BINARY_DIR}/tests/monster_test_generated.h
|
|
||||||
)
|
|
||||||
|
|
||||||
# source_group(Compiler FILES ${FlatBuffers_Compiler_SRCS})
|
|
||||||
# source_group(Tests FILES ${FlatBuffers_Tests_SRCS})
|
|
||||||
|
|
||||||
if(EXISTS "${CMAKE_TOOLCHAIN_FILE}")
|
|
||||||
# do not apply any global settings if the toolchain
|
|
||||||
# is being configured externally
|
|
||||||
message(STATUS "Using toolchain file: ${CMAKE_TOOLCHAIN_FILE}.")
|
|
||||||
elseif(CMAKE_COMPILER_IS_GNUCXX)
|
|
||||||
if(CYGWIN)
|
|
||||||
set(CMAKE_CXX_FLAGS
|
|
||||||
"${CMAKE_CXX_FLAGS} -std=gnu++11")
|
|
||||||
else(CYGWIN)
|
|
||||||
set(CMAKE_CXX_FLAGS
|
|
||||||
"${CMAKE_CXX_FLAGS} -std=c++0x")
|
|
||||||
endif(CYGWIN)
|
|
||||||
set(CMAKE_CXX_FLAGS
|
|
||||||
"${CMAKE_CXX_FLAGS} -Wall -pedantic -Werror -Wextra -Werror=shadow")
|
|
||||||
set(FLATBUFFERS_PRIVATE_CXX_FLAGS "-Wold-style-cast")
|
|
||||||
if (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 4.4)
|
|
||||||
if (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 7.0)
|
|
||||||
set(CMAKE_CXX_FLAGS
|
|
||||||
"${CMAKE_CXX_FLAGS} -faligned-new -Werror=implicit-fallthrough=2")
|
|
||||||
endif()
|
|
||||||
set(CMAKE_CXX_FLAGS
|
|
||||||
"${CMAKE_CXX_FLAGS} -Wunused-result -Werror=unused-result -Wunused-parameter -Werror=unused-parameter")
|
|
||||||
endif()
|
|
||||||
|
|
||||||
# Certain platforms such as ARM do not use signed chars by default
|
|
||||||
# which causes issues with certain bounds checks.
|
|
||||||
set(CMAKE_CXX_FLAGS
|
|
||||||
"${CMAKE_CXX_FLAGS} -fsigned-char")
|
|
||||||
|
|
||||||
# MSVC **MUST** come before the Clang check, as clang-cl is flagged by CMake as "MSVC", but it still textually
|
|
||||||
# matches as Clang in its Compiler Id :)
|
|
||||||
# Note: in CMake >= 3.14 we can check CMAKE_CXX_COMPILER_FRONTEND_VARIANT STREQUAL "GNU" or "MSVC" to differentiate...
|
|
||||||
elseif(MSVC)
|
|
||||||
# Visual Studio pedantic build settings
|
|
||||||
# warning C4512: assignment operator could not be generated
|
|
||||||
# warning C4316: object allocated on the heap may not be aligned
|
|
||||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W4 /WX /wd4512 /wd4316")
|
|
||||||
|
|
||||||
if(${CMAKE_CXX_COMPILER_ID} MATCHES "Clang")
|
|
||||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /D_CRT_SECURE_NO_WARNINGS")
|
|
||||||
endif()
|
|
||||||
|
|
||||||
elseif(${CMAKE_CXX_COMPILER_ID} MATCHES "Clang")
|
|
||||||
if(APPLE)
|
|
||||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
|
|
||||||
|
|
||||||
if(FLATBUFFERS_OSX_BUILD_UNIVERSAL)
|
|
||||||
set(CMAKE_OSX_ARCHITECTURES "arm64;x86_64")
|
|
||||||
endif()
|
|
||||||
else()
|
|
||||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x")
|
|
||||||
endif()
|
|
||||||
|
|
||||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -pedantic -Werror -Wextra -Wno-unused-parameter")
|
|
||||||
set(FLATBUFFERS_PRIVATE_CXX_FLAGS "-Wold-style-cast")
|
|
||||||
if(NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 3.8)
|
|
||||||
list(APPEND FLATBUFFERS_PRIVATE_CXX_FLAGS "-Wimplicit-fallthrough" "-Wextra-semi" "-Werror=unused-private-field") # enable warning
|
|
||||||
endif()
|
|
||||||
if(FLATBUFFERS_LIBCXX_WITH_CLANG)
|
|
||||||
if(NOT "${CMAKE_SYSTEM_NAME}" MATCHES "Linux")
|
|
||||||
set(CMAKE_CXX_FLAGS
|
|
||||||
"${CMAKE_CXX_FLAGS} -stdlib=libc++")
|
|
||||||
endif()
|
|
||||||
if(NOT ("${CMAKE_SYSTEM_NAME}" MATCHES "FreeBSD" OR
|
|
||||||
"${CMAKE_SYSTEM_NAME}" MATCHES "Linux"))
|
|
||||||
set(CMAKE_EXE_LINKER_FLAGS
|
|
||||||
"${CMAKE_EXE_LINKER_FLAGS} -lc++abi")
|
|
||||||
endif()
|
|
||||||
endif()
|
|
||||||
|
|
||||||
# Certain platforms such as ARM do not use signed chars by default
|
|
||||||
# which causes issues with certain bounds checks.
|
|
||||||
set(CMAKE_CXX_FLAGS
|
|
||||||
"${CMAKE_CXX_FLAGS} -fsigned-char")
|
|
||||||
|
|
||||||
endif()
|
|
||||||
|
|
||||||
# Append FLATBUFFERS_CXX_FLAGS to CMAKE_CXX_FLAGS.
|
|
||||||
if(DEFINED FLATBUFFERS_CXX_FLAGS AND NOT EXISTS "${CMAKE_TOOLCHAIN_FILE}")
|
|
||||||
message(STATUS "extend CXX_FLAGS with ${FLATBUFFERS_CXX_FLAGS}")
|
|
||||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${FLATBUFFERS_CXX_FLAGS}")
|
|
||||||
endif()
|
|
||||||
message(STATUS "CMAKE_CXX_FLAGS: ${CMAKE_CXX_FLAGS}")
|
|
||||||
|
|
||||||
if(FLATBUFFERS_CODE_COVERAGE)
|
|
||||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -fprofile-arcs -ftest-coverage")
|
|
||||||
set(CMAKE_EXE_LINKER_FLAGS
|
|
||||||
"${CMAKE_EXE_LINKER_FLAGS} -fprofile-arcs -ftest-coverage")
|
|
||||||
endif()
|
|
||||||
|
|
||||||
function(add_fsanitize_to_target _target _sanitizer)
|
|
||||||
if(WIN32)
|
|
||||||
target_compile_definitions(${_target} PRIVATE FLATBUFFERS_MEMORY_LEAK_TRACKING)
|
|
||||||
message(STATUS "Sanitizer MSVC::_CrtDumpMemoryLeaks added to ${_target}")
|
|
||||||
else()
|
|
||||||
# FLATBUFFERS_CODE_SANITIZE: boolean {ON,OFF,YES,NO} or string with list of sanitizer.
|
|
||||||
# List of sanitizer is string starts with '=': "=address,undefined,thread,memory".
|
|
||||||
if((${CMAKE_CXX_COMPILER_ID} MATCHES "Clang") OR
|
|
||||||
((${CMAKE_CXX_COMPILER_ID} MATCHES "GNU") AND NOT (CMAKE_CXX_COMPILER_VERSION VERSION_LESS "4.9"))
|
|
||||||
)
|
|
||||||
set(_sanitizer_flags "=address,undefined")
|
|
||||||
if(_sanitizer MATCHES "=.*")
|
|
||||||
# override default by user-defined sanitizer list
|
|
||||||
set(_sanitizer_flags ${_sanitizer})
|
|
||||||
endif()
|
|
||||||
target_compile_options(${_target} PRIVATE
|
|
||||||
-g -fsigned-char -fno-omit-frame-pointer
|
|
||||||
"-fsanitize${_sanitizer_flags}")
|
|
||||||
target_link_libraries(${_target} PRIVATE
|
|
||||||
"-fsanitize${_sanitizer_flags}")
|
|
||||||
set_property(TARGET ${_target} PROPERTY POSITION_INDEPENDENT_CODE ON)
|
|
||||||
message(STATUS "Sanitizer ${_sanitizer_flags} added to ${_target}")
|
|
||||||
endif()
|
|
||||||
endif()
|
|
||||||
endfunction()
|
|
||||||
|
|
||||||
function(add_pch_to_target _target _pch_header)
|
|
||||||
if(COMMAND target_precompile_headers)
|
|
||||||
target_precompile_headers(${_target} PRIVATE ${_pch_header})
|
|
||||||
if(NOT MSVC)
|
|
||||||
set_source_files_properties(src/util.cpp PROPERTIES SKIP_PRECOMPILE_HEADERS ON)
|
|
||||||
endif()
|
|
||||||
endif()
|
|
||||||
endfunction()
|
|
||||||
|
|
||||||
if(BIICODE)
|
|
||||||
include(biicode/cmake/biicode.cmake)
|
|
||||||
return()
|
|
||||||
endif()
|
|
||||||
|
|
||||||
include_directories(include)
|
|
||||||
include_directories(grpc)
|
|
||||||
|
|
||||||
if(FLATBUFFERS_BUILD_FLATLIB)
|
|
||||||
add_library(flatbuffers STATIC ${FlatBuffers_Library_SRCS})
|
|
||||||
# Attach header directory for when build via add_subdirectory().
|
|
||||||
target_include_directories(flatbuffers INTERFACE
|
|
||||||
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>)
|
|
||||||
target_compile_options(flatbuffers PRIVATE "${FLATBUFFERS_PRIVATE_CXX_FLAGS}")
|
|
||||||
if(FLATBUFFERS_ENABLE_PCH)
|
|
||||||
add_pch_to_target(flatbuffers include/flatbuffers/pch/pch.h)
|
|
||||||
endif()
|
|
||||||
endif()
|
|
||||||
|
|
||||||
if(FLATBUFFERS_BUILD_FLATC)
|
|
||||||
add_executable(flatc ${FlatBuffers_Compiler_SRCS})
|
|
||||||
if(FLATBUFFERS_ENABLE_PCH)
|
|
||||||
add_pch_to_target(flatc include/flatbuffers/pch/flatc_pch.h)
|
|
||||||
endif()
|
|
||||||
target_compile_options(flatc PRIVATE "${FLATBUFFERS_PRIVATE_CXX_FLAGS}")
|
|
||||||
if(FLATBUFFERS_CODE_SANITIZE AND NOT WIN32)
|
|
||||||
add_fsanitize_to_target(flatc ${FLATBUFFERS_CODE_SANITIZE})
|
|
||||||
endif()
|
|
||||||
if(NOT FLATBUFFERS_FLATC_EXECUTABLE)
|
|
||||||
set(FLATBUFFERS_FLATC_EXECUTABLE $<TARGET_FILE:flatc>)
|
|
||||||
endif()
|
|
||||||
if(MSVC)
|
|
||||||
# Make flatc.exe not depend on runtime dlls for easy distribution.
|
|
||||||
target_compile_options(flatc PUBLIC $<$<CONFIG:Release>:/MT>)
|
|
||||||
endif()
|
|
||||||
if(FLATBUFFERS_STATIC_FLATC AND NOT MSVC)
|
|
||||||
target_link_libraries(flatc PRIVATE -static)
|
|
||||||
endif()
|
|
||||||
endif()
|
|
||||||
|
|
||||||
if(FLATBUFFERS_BUILD_FLATHASH)
|
|
||||||
add_executable(flathash ${FlatHash_SRCS})
|
|
||||||
endif()
|
|
||||||
|
|
||||||
if(FLATBUFFERS_BUILD_SHAREDLIB)
|
|
||||||
add_library(flatbuffers_shared SHARED ${FlatBuffers_Library_SRCS})
|
|
||||||
|
|
||||||
# Shared object version: "major.minor.micro"
|
|
||||||
# - micro updated every release when there is no API/ABI changes
|
|
||||||
# - minor updated when there are additions in API/ABI
|
|
||||||
# - major (ABI number) updated when there are changes in ABI (or removals)
|
|
||||||
set(FlatBuffers_Library_SONAME_MAJOR ${VERSION_MAJOR})
|
|
||||||
set(FlatBuffers_Library_SONAME_FULL "${FlatBuffers_Library_SONAME_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}")
|
|
||||||
set_target_properties(flatbuffers_shared PROPERTIES OUTPUT_NAME flatbuffers
|
|
||||||
SOVERSION "${FlatBuffers_Library_SONAME_MAJOR}"
|
|
||||||
VERSION "${FlatBuffers_Library_SONAME_FULL}")
|
|
||||||
if(FLATBUFFERS_ENABLE_PCH)
|
|
||||||
add_pch_to_target(flatbuffers_shared include/flatbuffers/pch/pch.h)
|
|
||||||
endif()
|
|
||||||
endif()
|
|
||||||
|
|
||||||
# Global list of generated files.
|
|
||||||
# Use the global property to be independent of PARENT_SCOPE.
|
|
||||||
set_property(GLOBAL PROPERTY FBS_GENERATED_OUTPUTS)
|
|
||||||
|
|
||||||
function(get_generated_output generated_files)
|
|
||||||
get_property(tmp GLOBAL PROPERTY FBS_GENERATED_OUTPUTS)
|
|
||||||
set(${generated_files} ${tmp} PARENT_SCOPE)
|
|
||||||
endfunction(get_generated_output)
|
|
||||||
|
|
||||||
function(register_generated_output file_name)
|
|
||||||
get_property(tmp GLOBAL PROPERTY FBS_GENERATED_OUTPUTS)
|
|
||||||
list(APPEND tmp ${file_name})
|
|
||||||
set_property(GLOBAL PROPERTY FBS_GENERATED_OUTPUTS ${tmp})
|
|
||||||
endfunction(register_generated_output)
|
|
||||||
|
|
||||||
function(compile_flatbuffers_schema_to_cpp_opt SRC_FBS OPT)
|
|
||||||
if(FLATBUFFERS_BUILD_LEGACY)
|
|
||||||
set(OPT ${OPT};--cpp-std c++0x)
|
|
||||||
else()
|
|
||||||
# --cpp-std is defined by flatc default settings.
|
|
||||||
endif()
|
|
||||||
message(STATUS "`${SRC_FBS}`: add generation of C++ code with '${OPT}'")
|
|
||||||
get_filename_component(SRC_FBS_DIR ${SRC_FBS} PATH)
|
|
||||||
string(REGEX REPLACE "\\.fbs$" "_generated.h" GEN_HEADER ${SRC_FBS})
|
|
||||||
add_custom_command(
|
|
||||||
OUTPUT ${GEN_HEADER}
|
|
||||||
COMMAND "${FLATBUFFERS_FLATC_EXECUTABLE}"
|
|
||||||
--cpp --gen-mutable --gen-object-api --reflect-names
|
|
||||||
--cpp-ptr-type flatbuffers::unique_ptr # Used to test with C++98 STLs
|
|
||||||
${OPT}
|
|
||||||
-I "${CMAKE_CURRENT_SOURCE_DIR}/tests/include_test"
|
|
||||||
-o "${SRC_FBS_DIR}"
|
|
||||||
"${CMAKE_CURRENT_SOURCE_DIR}/${SRC_FBS}"
|
|
||||||
DEPENDS flatc
|
|
||||||
COMMENT "Run generation: '${GEN_HEADER}'")
|
|
||||||
register_generated_output(${GEN_HEADER})
|
|
||||||
endfunction()
|
|
||||||
|
|
||||||
function(compile_flatbuffers_schema_to_cpp SRC_FBS)
|
|
||||||
compile_flatbuffers_schema_to_cpp_opt(${SRC_FBS} "--no-includes;--gen-compare")
|
|
||||||
endfunction()
|
|
||||||
|
|
||||||
function(compile_flatbuffers_schema_to_binary SRC_FBS)
|
|
||||||
message(STATUS "`${SRC_FBS}`: add generation of binary (.bfbs) schema")
|
|
||||||
get_filename_component(SRC_FBS_DIR ${SRC_FBS} PATH)
|
|
||||||
string(REGEX REPLACE "\\.fbs$" ".bfbs" GEN_BINARY_SCHEMA ${SRC_FBS})
|
|
||||||
# For details about flags see generate_code.py
|
|
||||||
add_custom_command(
|
|
||||||
OUTPUT ${GEN_BINARY_SCHEMA}
|
|
||||||
COMMAND "${FLATBUFFERS_FLATC_EXECUTABLE}"
|
|
||||||
-b --schema --bfbs-comments --bfbs-builtins
|
|
||||||
--bfbs-filenames ${SRC_FBS_DIR}
|
|
||||||
-I "${CMAKE_CURRENT_SOURCE_DIR}/tests/include_test"
|
|
||||||
-o "${SRC_FBS_DIR}"
|
|
||||||
"${CMAKE_CURRENT_SOURCE_DIR}/${SRC_FBS}"
|
|
||||||
DEPENDS flatc
|
|
||||||
COMMENT "Run generation: '${GEN_BINARY_SCHEMA}'")
|
|
||||||
register_generated_output(${GEN_BINARY_SCHEMA})
|
|
||||||
endfunction()
|
|
||||||
|
|
||||||
function(compile_flatbuffers_schema_to_embedded_binary SRC_FBS OPT)
|
|
||||||
if(FLATBUFFERS_BUILD_LEGACY)
|
|
||||||
set(OPT ${OPT};--cpp-std c++0x)
|
|
||||||
else()
|
|
||||||
# --cpp-std is defined by flatc default settings.
|
|
||||||
endif()
|
|
||||||
message(STATUS "`${SRC_FBS}`: add generation of C++ embedded binary schema code with '${OPT}'")
|
|
||||||
get_filename_component(SRC_FBS_DIR ${SRC_FBS} PATH)
|
|
||||||
string(REGEX REPLACE "\\.fbs$" "_bfbs_generated.h" GEN_BFBS_HEADER ${SRC_FBS})
|
|
||||||
# For details about flags see generate_code.py
|
|
||||||
add_custom_command(
|
|
||||||
OUTPUT ${GEN_BFBS_HEADER}
|
|
||||||
COMMAND "${FLATBUFFERS_FLATC_EXECUTABLE}"
|
|
||||||
--cpp --gen-mutable --gen-object-api --reflect-names
|
|
||||||
--cpp-ptr-type flatbuffers::unique_ptr # Used to test with C++98 STLs
|
|
||||||
${OPT}
|
|
||||||
--bfbs-comments --bfbs-builtins --bfbs-gen-embed
|
|
||||||
--bfbs-filenames ${SRC_FBS_DIR}
|
|
||||||
-I "${CMAKE_CURRENT_SOURCE_DIR}/tests/include_test"
|
|
||||||
-o "${SRC_FBS_DIR}"
|
|
||||||
"${CMAKE_CURRENT_SOURCE_DIR}/${SRC_FBS}"
|
|
||||||
DEPENDS flatc
|
|
||||||
COMMENT "Run generation: '${GEN_BFBS_HEADER}'")
|
|
||||||
register_generated_output(${GEN_BFBS_HEADER})
|
|
||||||
endfunction()
|
|
||||||
|
|
||||||
# Look if we have python 3.5 installed so that we can run the generate code
|
|
||||||
# python script after flatc is built.
|
|
||||||
find_package(PythonInterp 3.5)
|
|
||||||
|
|
||||||
if(PYTHONINTERP_FOUND AND
|
|
||||||
# Skip doing this if the MSVC version is below VS 12.
|
|
||||||
# https://cmake.org/cmake/help/latest/variable/MSVC_VERSION.html
|
|
||||||
(NOT MSVC OR MSVC_VERSION GREATER 1800))
|
|
||||||
set(GENERATION_SCRIPT ${PYTHON_EXECUTABLE} scripts/generate_code.py)
|
|
||||||
if(FLATBUFFERS_BUILD_LEGACY)
|
|
||||||
# Need to set --cpp-std c++-0x options
|
|
||||||
set(GENERATION_SCRIPT ${GENERATION_SCRIPT} --cpp-0x)
|
|
||||||
endif()
|
|
||||||
if(FLATBUFFERS_SKIP_MONSTER_EXTRA)
|
|
||||||
set(GENERATION_SCRIPT ${GENERATION_SCRIPT} --skip-monster-extra)
|
|
||||||
endif()
|
|
||||||
add_custom_command(
|
|
||||||
TARGET flatc
|
|
||||||
POST_BUILD
|
|
||||||
COMMAND ${GENERATION_SCRIPT} --flatc "${FLATBUFFERS_FLATC_EXECUTABLE}"
|
|
||||||
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
|
|
||||||
COMMENT "Running ${GENERATION_SCRIPT}..."
|
|
||||||
VERBATIM)
|
|
||||||
else()
|
|
||||||
message("No Python3 interpreter found! Unable to generate files automatically.")
|
|
||||||
endif()
|
|
||||||
|
|
||||||
if(FLATBUFFERS_BUILD_TESTS)
|
|
||||||
file(COPY "${CMAKE_CURRENT_SOURCE_DIR}/tests" DESTINATION "${CMAKE_CURRENT_BINARY_DIR}")
|
|
||||||
file(COPY "${CMAKE_CURRENT_SOURCE_DIR}/samples" DESTINATION "${CMAKE_CURRENT_BINARY_DIR}")
|
|
||||||
|
|
||||||
# TODO Add (monster_test.fbs monsterdata_test.json)->monsterdata_test.mon
|
|
||||||
compile_flatbuffers_schema_to_cpp(tests/monster_test.fbs)
|
|
||||||
compile_flatbuffers_schema_to_binary(tests/monster_test.fbs)
|
|
||||||
compile_flatbuffers_schema_to_cpp_opt(tests/namespace_test/namespace_test1.fbs "--no-includes;--gen-compare;--gen-name-strings")
|
|
||||||
compile_flatbuffers_schema_to_cpp_opt(tests/namespace_test/namespace_test2.fbs "--no-includes;--gen-compare;--gen-name-strings")
|
|
||||||
compile_flatbuffers_schema_to_cpp_opt(tests/union_vector/union_vector.fbs "--no-includes;--gen-compare;--gen-name-strings")
|
|
||||||
compile_flatbuffers_schema_to_cpp(tests/optional_scalars.fbs)
|
|
||||||
compile_flatbuffers_schema_to_cpp_opt(tests/native_type_test.fbs "")
|
|
||||||
compile_flatbuffers_schema_to_cpp_opt(tests/arrays_test.fbs "--scoped-enums;--gen-compare")
|
|
||||||
compile_flatbuffers_schema_to_binary(tests/arrays_test.fbs)
|
|
||||||
compile_flatbuffers_schema_to_embedded_binary(tests/monster_test.fbs "--no-includes;--gen-compare")
|
|
||||||
if(NOT (MSVC AND (MSVC_VERSION LESS 1900)))
|
|
||||||
compile_flatbuffers_schema_to_cpp(tests/monster_extra.fbs) # Test floating-point NAN/INF.
|
|
||||||
endif()
|
|
||||||
include_directories(${CMAKE_CURRENT_BINARY_DIR}/tests)
|
|
||||||
add_executable(flattests ${FlatBuffers_Tests_SRCS})
|
|
||||||
add_dependencies(flattests generated_code)
|
|
||||||
set_property(TARGET flattests
|
|
||||||
PROPERTY COMPILE_DEFINITIONS FLATBUFFERS_TRACK_VERIFIER_BUFFER_SIZE
|
|
||||||
FLATBUFFERS_DEBUG_VERIFICATION_FAILURE=1)
|
|
||||||
if(FLATBUFFERS_CODE_SANITIZE)
|
|
||||||
add_fsanitize_to_target(flattests ${FLATBUFFERS_CODE_SANITIZE})
|
|
||||||
endif()
|
|
||||||
|
|
||||||
compile_flatbuffers_schema_to_cpp(samples/monster.fbs)
|
|
||||||
compile_flatbuffers_schema_to_binary(samples/monster.fbs)
|
|
||||||
include_directories(${CMAKE_CURRENT_BINARY_DIR}/samples)
|
|
||||||
add_executable(flatsamplebinary ${FlatBuffers_Sample_Binary_SRCS})
|
|
||||||
add_dependencies(flatsamplebinary generated_code)
|
|
||||||
add_executable(flatsampletext ${FlatBuffers_Sample_Text_SRCS})
|
|
||||||
add_dependencies(flatsampletext generated_code)
|
|
||||||
add_executable(flatsamplebfbs ${FlatBuffers_Sample_BFBS_SRCS})
|
|
||||||
add_dependencies(flatsamplebfbs generated_code)
|
|
||||||
|
|
||||||
if(FLATBUFFERS_BUILD_CPP17)
|
|
||||||
# Don't generate header for flattests_cpp17 target.
|
|
||||||
# This target uses "generated_cpp17/monster_test_generated.h"
|
|
||||||
# produced by direct call of generate_code.py script.
|
|
||||||
add_executable(flattests_cpp17 ${FlatBuffers_Tests_CPP17_SRCS})
|
|
||||||
add_dependencies(flattests_cpp17 generated_code)
|
|
||||||
target_compile_features(flattests_cpp17 PRIVATE cxx_std_17)
|
|
||||||
target_compile_definitions(flattests_cpp17 PRIVATE
|
|
||||||
FLATBUFFERS_TRACK_VERIFIER_BUFFER_SIZE
|
|
||||||
FLATBUFFERS_DEBUG_VERIFICATION_FAILURE=1
|
|
||||||
)
|
|
||||||
if(FLATBUFFERS_CODE_SANITIZE)
|
|
||||||
add_fsanitize_to_target(flattests_cpp17 ${FLATBUFFERS_CODE_SANITIZE})
|
|
||||||
endif()
|
|
||||||
endif(FLATBUFFERS_BUILD_CPP17)
|
|
||||||
endif()
|
|
||||||
|
|
||||||
if(FLATBUFFERS_BUILD_GRPCTEST)
|
|
||||||
if(CMAKE_COMPILER_IS_GNUCXX)
|
|
||||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unused-parameter -Wno-shadow")
|
|
||||||
endif()
|
|
||||||
if(NOT GRPC_INSTALL_PATH)
|
|
||||||
message(SEND_ERROR "GRPC_INSTALL_PATH variable is not defined. See grpc/README.md")
|
|
||||||
endif()
|
|
||||||
if(NOT PROTOBUF_DOWNLOAD_PATH)
|
|
||||||
message(SEND_ERROR "PROTOBUF_DOWNLOAD_PATH variable is not defined. See grpc/README.md")
|
|
||||||
endif()
|
|
||||||
INCLUDE_DIRECTORIES(${GRPC_INSTALL_PATH}/include)
|
|
||||||
INCLUDE_DIRECTORIES(${PROTOBUF_DOWNLOAD_PATH}/src)
|
|
||||||
find_package(Threads REQUIRED)
|
|
||||||
list(APPEND CMAKE_PREFIX_PATH ${GRPC_INSTALL_PATH})
|
|
||||||
find_package(absl CONFIG REQUIRED)
|
|
||||||
find_package(protobuf CONFIG REQUIRED)
|
|
||||||
find_package(gRPC CONFIG REQUIRED)
|
|
||||||
add_executable(grpctest ${FlatBuffers_GRPCTest_SRCS})
|
|
||||||
add_dependencies(grpctest generated_code)
|
|
||||||
target_link_libraries(grpctest PRIVATE gRPC::grpc++_unsecure gRPC::grpc_unsecure gRPC::gpr pthread dl)
|
|
||||||
if(FLATBUFFERS_CODE_SANITIZE AND NOT WIN32)
|
|
||||||
# GRPC test has problems with alignment and will fail under ASAN/UBSAN.
|
|
||||||
# add_fsanitize_to_target(grpctest ${FLATBUFFERS_CODE_SANITIZE})
|
|
||||||
endif()
|
|
||||||
endif()
|
|
||||||
|
|
||||||
|
|
||||||
if(FLATBUFFERS_INSTALL)
|
|
||||||
include(GNUInstallDirs)
|
|
||||||
|
|
||||||
install(DIRECTORY include/flatbuffers DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
|
|
||||||
|
|
||||||
set(FB_CMAKE_DIR "${CMAKE_INSTALL_LIBDIR}/cmake/flatbuffers")
|
|
||||||
|
|
||||||
configure_file(CMake/flatbuffers-config-version.cmake.in flatbuffers-config-version.cmake @ONLY)
|
|
||||||
install(
|
|
||||||
FILES "CMake/flatbuffers-config.cmake" "${CMAKE_CURRENT_BINARY_DIR}/flatbuffers-config-version.cmake"
|
|
||||||
DESTINATION ${FB_CMAKE_DIR}
|
|
||||||
)
|
|
||||||
|
|
||||||
if(FLATBUFFERS_BUILD_FLATLIB)
|
|
||||||
if(CMAKE_VERSION VERSION_LESS 3.0)
|
|
||||||
install(
|
|
||||||
TARGETS flatbuffers EXPORT FlatBuffersTargets
|
|
||||||
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
|
||||||
)
|
|
||||||
else()
|
|
||||||
install(
|
|
||||||
TARGETS flatbuffers EXPORT FlatBuffersTargets
|
|
||||||
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
|
||||||
INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
|
|
||||||
)
|
|
||||||
endif()
|
|
||||||
|
|
||||||
install(EXPORT FlatBuffersTargets
|
|
||||||
FILE FlatBuffersTargets.cmake
|
|
||||||
NAMESPACE flatbuffers::
|
|
||||||
DESTINATION ${FB_CMAKE_DIR}
|
|
||||||
)
|
|
||||||
endif()
|
|
||||||
|
|
||||||
if(FLATBUFFERS_BUILD_FLATC)
|
|
||||||
install(
|
|
||||||
TARGETS flatc EXPORT FlatcTargets
|
|
||||||
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
|
|
||||||
)
|
|
||||||
|
|
||||||
install(
|
|
||||||
EXPORT FlatcTargets
|
|
||||||
FILE FlatcTargets.cmake
|
|
||||||
NAMESPACE flatbuffers::
|
|
||||||
DESTINATION ${FB_CMAKE_DIR}
|
|
||||||
)
|
|
||||||
endif()
|
|
||||||
|
|
||||||
if(FLATBUFFERS_BUILD_SHAREDLIB)
|
|
||||||
if(CMAKE_VERSION VERSION_LESS 3.0)
|
|
||||||
install(
|
|
||||||
TARGETS flatbuffers_shared EXPORT FlatBuffersSharedTargets
|
|
||||||
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
|
||||||
RUNTIME DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
|
||||||
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
|
||||||
)
|
|
||||||
else()
|
|
||||||
install(
|
|
||||||
TARGETS flatbuffers_shared EXPORT FlatBuffersSharedTargets
|
|
||||||
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
|
||||||
RUNTIME DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
|
||||||
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
|
||||||
INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
|
|
||||||
)
|
|
||||||
endif()
|
|
||||||
|
|
||||||
install(
|
|
||||||
EXPORT FlatBuffersSharedTargets
|
|
||||||
FILE FlatBuffersSharedTargets.cmake
|
|
||||||
NAMESPACE flatbuffers::
|
|
||||||
DESTINATION ${FB_CMAKE_DIR}
|
|
||||||
)
|
|
||||||
endif()
|
|
||||||
|
|
||||||
if(FLATBUFFERS_BUILD_SHAREDLIB OR FLATBUFFERS_BUILD_FLATLIB)
|
|
||||||
configure_file(CMake/flatbuffers.pc.in flatbuffers.pc @ONLY)
|
|
||||||
install(
|
|
||||||
FILES "${CMAKE_CURRENT_BINARY_DIR}/flatbuffers.pc"
|
|
||||||
DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig
|
|
||||||
)
|
|
||||||
endif()
|
|
||||||
endif()
|
|
||||||
|
|
||||||
if(FLATBUFFERS_BUILD_TESTS)
|
|
||||||
enable_testing()
|
|
||||||
|
|
||||||
add_test(NAME flattests COMMAND flattests)
|
|
||||||
if(FLATBUFFERS_BUILD_CPP17)
|
|
||||||
add_test(NAME flattests_cpp17 COMMAND flattests_cpp17)
|
|
||||||
endif()
|
|
||||||
if(FLATBUFFERS_BUILD_GRPCTEST)
|
|
||||||
add_test(NAME grpctest COMMAND grpctest)
|
|
||||||
endif()
|
|
||||||
endif()
|
|
||||||
|
|
||||||
# This target is sync-barrier.
|
|
||||||
# Other generate-dependent targets can depend on 'generated_code' only.
|
|
||||||
get_generated_output(fbs_generated)
|
|
||||||
if(fbs_generated)
|
|
||||||
# message(STATUS "Add generated_code target with files:${fbs_generated}")
|
|
||||||
add_custom_target(generated_code
|
|
||||||
DEPENDS ${fbs_generated}
|
|
||||||
COMMENT "All generated files were updated.")
|
|
||||||
endif()
|
|
||||||
|
|
||||||
include(CMake/BuildFlatBuffers.cmake)
|
|
||||||
|
|
||||||
if(UNIX)
|
|
||||||
# Use of CPack only supported on Linux systems.
|
|
||||||
if(FLATBUFFERS_PACKAGE_DEBIAN)
|
|
||||||
include(CMake/PackageDebian.cmake)
|
|
||||||
include(CPack)
|
|
||||||
endif()
|
|
||||||
if (FLATBUFFERS_PACKAGE_REDHAT)
|
|
||||||
include(CMake/PackageRedhat.cmake)
|
|
||||||
include(CPack)
|
|
||||||
endif()
|
|
||||||
endif()
|
|
||||||
|
|
||||||
# Include for running Google Benchmarks.
|
|
||||||
if(FLATBUFFERS_BUILD_BENCHMARKS AND CMAKE_VERSION VERSION_GREATER 3.13)
|
|
||||||
add_subdirectory(benchmarks)
|
|
||||||
endif()
|
|
||||||
|
|
||||||
# Add FlatBuffers::FlatBuffers interface, needed for FetchContent_Declare
|
|
||||||
add_library(FlatBuffers INTERFACE)
|
|
||||||
add_library(FlatBuffers::FlatBuffers ALIAS FlatBuffers)
|
|
||||||
target_include_directories(
|
|
||||||
FlatBuffers
|
|
||||||
INTERFACE $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
|
|
||||||
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/include>)
|
|
||||||
@@ -17,23 +17,9 @@ if (UNIX)
|
|||||||
SET(CPACK_PACKAGE_VERSION "${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}-${VERSION_COMMIT}")
|
SET(CPACK_PACKAGE_VERSION "${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}-${VERSION_COMMIT}")
|
||||||
SET(CPACK_DEBIAN_PACKAGE_VERSION "${CPACK_PACKAGE_VERSION}")
|
SET(CPACK_DEBIAN_PACKAGE_VERSION "${CPACK_PACKAGE_VERSION}")
|
||||||
|
|
||||||
# Derive architecture
|
|
||||||
IF(NOT CPACK_DEBIAN_PACKAGE_ARCHITECTURE)
|
|
||||||
FIND_PROGRAM(DPKG_CMD dpkg)
|
|
||||||
IF(NOT DPKG_CMD)
|
|
||||||
MESSAGE(STATUS "Can not find dpkg in your path, default to i386.")
|
|
||||||
SET(CPACK_DEBIAN_PACKAGE_ARCHITECTURE i386)
|
|
||||||
ENDIF(NOT DPKG_CMD)
|
|
||||||
EXECUTE_PROCESS(COMMAND "${DPKG_CMD}" --print-architecture
|
|
||||||
OUTPUT_VARIABLE CPACK_DEBIAN_PACKAGE_ARCHITECTURE
|
|
||||||
OUTPUT_STRIP_TRAILING_WHITESPACE
|
|
||||||
)
|
|
||||||
ENDIF(NOT CPACK_DEBIAN_PACKAGE_ARCHITECTURE)
|
|
||||||
|
|
||||||
# Package name
|
# Package name
|
||||||
SET(CPACK_DEBIAN_PACKAGE_NAME "flatbuffers")
|
SET(CPACK_DEBIAN_PACKAGE_NAME "flatbuffers")
|
||||||
SET(CPACK_RESOURCE_FILE_LICENSE ${CMAKE_SOURCE_DIR}/LICENSE.txt)
|
SET(CPACK_RESOURCE_FILE_LICENSE ${CMAKE_SOURCE_DIR}/LICENSE)
|
||||||
SET(CPACK_PACKAGE_FILE_NAME
|
set(CPACK_DEBIAN_FILE_NAME "DEB-DEFAULT")
|
||||||
"${CPACK_DEBIAN_PACKAGE_NAME}_${CPACK_DEBIAN_PACKAGE_VERSION}_${CPACK_DEBIAN_PACKAGE_ARCHITECTURE}")
|
|
||||||
|
|
||||||
endif(UNIX)
|
endif(UNIX)
|
||||||
|
|||||||
@@ -15,14 +15,14 @@ if (UNIX)
|
|||||||
|
|
||||||
set(CPACK_RPM_PACKAGE_NAME "flatbuffers")
|
set(CPACK_RPM_PACKAGE_NAME "flatbuffers")
|
||||||
|
|
||||||
# Assume this is not a cross complation build.
|
# Assume this is not a cross compilation build.
|
||||||
if(NOT CPACK_RPM_PACKAGE_ARCHITECTURE)
|
if(NOT CPACK_RPM_PACKAGE_ARCHITECTURE)
|
||||||
set(CPACK_RPM_PACKAGE_ARCHITECTURE "${CMAKE_SYSTEM_PROCESSOR}")
|
set(CPACK_RPM_PACKAGE_ARCHITECTURE "${CMAKE_SYSTEM_PROCESSOR}")
|
||||||
endif(NOT CPACK_RPM_PACKAGE_ARCHITECTURE)
|
endif(NOT CPACK_RPM_PACKAGE_ARCHITECTURE)
|
||||||
|
|
||||||
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 1)
|
set(VERSION_MINOR 5)
|
||||||
set(VERSION_PATCH 4)
|
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)
|
||||||
263
CMakeLists.txt
263
CMakeLists.txt
@@ -1,32 +1,12 @@
|
|||||||
# This is the legacy minimum version flatbuffers supported for a while.
|
# This is the legacy minimum version flatbuffers supported for a while.
|
||||||
cmake_minimum_required(VERSION 2.8.12...3.22.1)
|
cmake_minimum_required(VERSION 3.8...3.25.2)
|
||||||
|
|
||||||
# CMake version 3.16 is the 'de-facto' minimum version for flatbuffers. If the
|
|
||||||
# current cmake is older than this, warn the user and include the legacy file to
|
|
||||||
# provide some level of support.
|
|
||||||
if(CMAKE_VERSION VERSION_LESS 3.16)
|
|
||||||
message(WARNING "Using cmake version ${CMAKE_VERSION} which is older than "
|
|
||||||
"our target version of 3.16. This will use the legacy CMakeLists.txt that "
|
|
||||||
"supports version 2.8.12 and higher, but not actively maintained. Consider "
|
|
||||||
"upgrading cmake to a newer version, as this may become a fatal error in the "
|
|
||||||
"future.")
|
|
||||||
# Use the legacy version of CMakeLists.txt
|
|
||||||
include(CMake/CMakeLists_legacy.cmake.in)
|
|
||||||
return()
|
|
||||||
endif()
|
|
||||||
|
|
||||||
# Attempt to read the current version of flatbuffers by looking at the latest tag.
|
# Attempt to read the current version of flatbuffers by looking at the latest tag.
|
||||||
include(CMake/Version.cmake)
|
include(CMake/Version.cmake)
|
||||||
|
|
||||||
if (POLICY CMP0048)
|
project(FlatBuffers
|
||||||
cmake_policy(SET CMP0048 NEW)
|
|
||||||
project(FlatBuffers
|
|
||||||
DESCRIPTION "Flatbuffers serialization library"
|
|
||||||
VERSION ${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}
|
VERSION ${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}
|
||||||
LANGUAGES CXX)
|
LANGUAGES CXX)
|
||||||
else()
|
|
||||||
project(FlatBuffers)
|
|
||||||
endif (POLICY CMP0048)
|
|
||||||
|
|
||||||
# generate compile_commands.json
|
# generate compile_commands.json
|
||||||
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
||||||
@@ -41,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)
|
||||||
@@ -87,6 +67,12 @@ if(MSVC OR CMAKE_CXX_COMPILER_FRONTEND_VARIANT STREQUAL "MSVC")
|
|||||||
set(MSVC_LIKE ON)
|
set(MSVC_LIKE ON)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
|
||||||
|
set(IS_CLANG ON)
|
||||||
|
else()
|
||||||
|
set(IS_CLANG OFF)
|
||||||
|
endif()
|
||||||
|
|
||||||
if(DEFINED FLATBUFFERS_COMPILATION_TIMINGS)
|
if(DEFINED FLATBUFFERS_COMPILATION_TIMINGS)
|
||||||
message("Recording Compilation Timings to ${FLATBUFFERS_COMPILATION_TIMINGS}")
|
message("Recording Compilation Timings to ${FLATBUFFERS_COMPILATION_TIMINGS}")
|
||||||
file(REMOVE ${FLATBUFFERS_COMPILATION_TIMINGS})
|
file(REMOVE ${FLATBUFFERS_COMPILATION_TIMINGS})
|
||||||
@@ -136,11 +122,12 @@ set(FlatBuffers_Library_SRCS
|
|||||||
include/flatbuffers/allocator.h
|
include/flatbuffers/allocator.h
|
||||||
include/flatbuffers/array.h
|
include/flatbuffers/array.h
|
||||||
include/flatbuffers/base.h
|
include/flatbuffers/base.h
|
||||||
include/flatbuffers/bfbs_generator.h
|
|
||||||
include/flatbuffers/buffer.h
|
include/flatbuffers/buffer.h
|
||||||
include/flatbuffers/buffer_ref.h
|
include/flatbuffers/buffer_ref.h
|
||||||
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/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
|
||||||
@@ -167,6 +154,8 @@ set(FlatBuffers_Library_SRCS
|
|||||||
|
|
||||||
set(FlatBuffers_Compiler_SRCS
|
set(FlatBuffers_Compiler_SRCS
|
||||||
${FlatBuffers_Library_SRCS}
|
${FlatBuffers_Library_SRCS}
|
||||||
|
src/idl_gen_binary.cpp
|
||||||
|
src/idl_gen_text.cpp
|
||||||
src/idl_gen_cpp.cpp
|
src/idl_gen_cpp.cpp
|
||||||
src/idl_gen_csharp.cpp
|
src/idl_gen_csharp.cpp
|
||||||
src/idl_gen_dart.cpp
|
src/idl_gen_dart.cpp
|
||||||
@@ -183,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
|
||||||
@@ -244,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
|
||||||
@@ -274,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
|
||||||
@@ -315,14 +273,12 @@ 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
|
||||||
# https://stackoverflow.com/questions/71772330/override-target-compile-options-via-cmake-command-line.
|
# https://stackoverflow.com/questions/71772330/override-target-compile-options-via-cmake-command-line.
|
||||||
# Append FLATBUFFERS_CXX_FLAGS to CMAKE_CXX_FLAGS.
|
# Append FLATBUFFERS_CXX_FLAGS to CMAKE_CXX_FLAGS.
|
||||||
if(DEFINED FLATBUFFERS_CXX_FLAGS AND NOT EXISTS "${CMAKE_TOOLCHAIN_FILE}")
|
if(DEFINED FLATBUFFERS_CXX_FLAGS)
|
||||||
message(STATUS "extend CXX_FLAGS with ${FLATBUFFERS_CXX_FLAGS}")
|
message(STATUS "extend CXX_FLAGS with ${FLATBUFFERS_CXX_FLAGS}")
|
||||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${FLATBUFFERS_CXX_FLAGS}")
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${FLATBUFFERS_CXX_FLAGS}")
|
||||||
endif()
|
endif()
|
||||||
@@ -335,9 +291,7 @@ function(add_fsanitize_to_target _target _sanitizer)
|
|||||||
else()
|
else()
|
||||||
# FLATBUFFERS_CODE_SANITIZE: boolean {ON,OFF,YES,NO} or string with list of sanitizer.
|
# FLATBUFFERS_CODE_SANITIZE: boolean {ON,OFF,YES,NO} or string with list of sanitizer.
|
||||||
# List of sanitizer is string starts with '=': "=address,undefined,thread,memory".
|
# List of sanitizer is string starts with '=': "=address,undefined,thread,memory".
|
||||||
if((${CMAKE_CXX_COMPILER_ID} MATCHES "Clang") OR
|
if(IS_CLANG OR (CMAKE_COMPILER_IS_GNUCXX AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 4.9))
|
||||||
((${CMAKE_CXX_COMPILER_ID} MATCHES "GNU") AND NOT (CMAKE_CXX_COMPILER_VERSION VERSION_LESS "4.9"))
|
|
||||||
)
|
|
||||||
set(_sanitizer_flags "=address,undefined")
|
set(_sanitizer_flags "=address,undefined")
|
||||||
if(_sanitizer MATCHES "=.*")
|
if(_sanitizer MATCHES "=.*")
|
||||||
# override default by user-defined sanitizer list
|
# override default by user-defined sanitizer list
|
||||||
@@ -348,13 +302,14 @@ function(add_fsanitize_to_target _target _sanitizer)
|
|||||||
"-fsanitize${_sanitizer_flags}")
|
"-fsanitize${_sanitizer_flags}")
|
||||||
target_link_libraries(${_target} PRIVATE
|
target_link_libraries(${_target} PRIVATE
|
||||||
"-fsanitize${_sanitizer_flags}")
|
"-fsanitize${_sanitizer_flags}")
|
||||||
set_property(TARGET ${_target} PROPERTY POSITION_INDEPENDENT_CODE ON)
|
set_target_properties(${_target} PROPERTIES POSITION_INDEPENDENT_CODE ON)
|
||||||
message(STATUS "Sanitizer ${_sanitizer_flags} added to ${_target}")
|
message(STATUS "Sanitizer ${_sanitizer_flags} added to ${_target}")
|
||||||
endif()
|
endif()
|
||||||
endif()
|
endif()
|
||||||
endfunction()
|
endfunction()
|
||||||
|
|
||||||
function(add_pch_to_target _target _pch_header)
|
function(add_pch_to_target _target _pch_header)
|
||||||
|
# the command is available since cmake 3.16
|
||||||
if(COMMAND target_precompile_headers)
|
if(COMMAND target_precompile_headers)
|
||||||
target_precompile_headers(${_target} PRIVATE ${_pch_header})
|
target_precompile_headers(${_target} PRIVATE ${_pch_header})
|
||||||
if(NOT MSVC)
|
if(NOT MSVC)
|
||||||
@@ -398,11 +353,6 @@ if(MSVC_LIKE)
|
|||||||
>
|
>
|
||||||
)
|
)
|
||||||
else()
|
else()
|
||||||
if("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
|
|
||||||
set(IS_CLANG ON)
|
|
||||||
else()
|
|
||||||
set(IS_CLANG OFF)
|
|
||||||
endif()
|
|
||||||
target_compile_options(ProjectConfig
|
target_compile_options(ProjectConfig
|
||||||
INTERFACE
|
INTERFACE
|
||||||
-Wall
|
-Wall
|
||||||
@@ -499,7 +449,7 @@ if(FLATBUFFERS_BUILD_FLATC)
|
|||||||
|
|
||||||
target_link_libraries(flatc PRIVATE $<BUILD_INTERFACE:ProjectConfig>)
|
target_link_libraries(flatc PRIVATE $<BUILD_INTERFACE:ProjectConfig>)
|
||||||
target_compile_options(flatc
|
target_compile_options(flatc
|
||||||
PUBLIC
|
PRIVATE
|
||||||
$<$<AND:$<BOOL:${MSVC_LIKE}>,$<CONFIG:Release>>:
|
$<$<AND:$<BOOL:${MSVC_LIKE}>,$<CONFIG:Release>>:
|
||||||
/MT
|
/MT
|
||||||
>
|
>
|
||||||
@@ -524,160 +474,80 @@ endif()
|
|||||||
if(FLATBUFFERS_BUILD_SHAREDLIB)
|
if(FLATBUFFERS_BUILD_SHAREDLIB)
|
||||||
add_library(flatbuffers_shared SHARED ${FlatBuffers_Library_SRCS})
|
add_library(flatbuffers_shared SHARED ${FlatBuffers_Library_SRCS})
|
||||||
target_link_libraries(flatbuffers_shared PRIVATE $<BUILD_INTERFACE:ProjectConfig>)
|
target_link_libraries(flatbuffers_shared PRIVATE $<BUILD_INTERFACE:ProjectConfig>)
|
||||||
# Shared object version: "major.minor.micro"
|
# FlatBuffers use calendar-based versioning and do not provide any ABI
|
||||||
# - micro updated every release when there is no API/ABI changes
|
# stability guarantees. Therefore, always use the full version as SOVERSION
|
||||||
# - minor updated when there are additions in API/ABI
|
# in order to avoid breaking reverse dependencies on upgrades.
|
||||||
# - major (ABI number) updated when there are changes in ABI (or removals)
|
set(FlatBuffers_Library_SONAME_FULL "${PROJECT_VERSION}")
|
||||||
set(FlatBuffers_Library_SONAME_MAJOR ${VERSION_MAJOR})
|
set_target_properties(flatbuffers_shared PROPERTIES
|
||||||
set(FlatBuffers_Library_SONAME_FULL "${FlatBuffers_Library_SONAME_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}")
|
OUTPUT_NAME flatbuffers
|
||||||
set_target_properties(flatbuffers_shared PROPERTIES OUTPUT_NAME flatbuffers
|
SOVERSION "${FlatBuffers_Library_SONAME_FULL}"
|
||||||
SOVERSION "${FlatBuffers_Library_SONAME_MAJOR}"
|
|
||||||
VERSION "${FlatBuffers_Library_SONAME_FULL}")
|
VERSION "${FlatBuffers_Library_SONAME_FULL}")
|
||||||
if(FLATBUFFERS_ENABLE_PCH)
|
if(FLATBUFFERS_ENABLE_PCH)
|
||||||
add_pch_to_target(flatbuffers_shared include/flatbuffers/pch/pch.h)
|
add_pch_to_target(flatbuffers_shared include/flatbuffers/pch/pch.h)
|
||||||
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)
|
target_compile_features(flattests_cpp17 PRIVATE cxx_std_17) # requires cmake 3.8
|
||||||
|
|
||||||
if(FLATBUFFERS_CODE_SANITIZE)
|
if(FLATBUFFERS_CODE_SANITIZE)
|
||||||
add_fsanitize_to_target(flattests_cpp17 ${FLATBUFFERS_CODE_SANITIZE})
|
add_fsanitize_to_target(flattests_cpp17 ${FLATBUFFERS_CODE_SANITIZE})
|
||||||
@@ -700,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>
|
||||||
@@ -793,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.1.4'
|
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
|
||||||
|
|||||||
@@ -32,6 +32,6 @@ let package = Package(
|
|||||||
.target(
|
.target(
|
||||||
name: "FlatBuffers",
|
name: "FlatBuffers",
|
||||||
dependencies: [],
|
dependencies: [],
|
||||||
path: "swift/Sources")
|
path: "swift/Sources"),
|
||||||
])
|
])
|
||||||
|
|
||||||
|
|||||||
@@ -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,19 +31,23 @@ 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)
|
||||||
1. Nim
|
1. Nim
|
||||||
|
|
||||||
|
## Versioning
|
||||||
|
|
||||||
|
FlatBuffers does not follow traditional Semver versioning (see [rationale](https://github.com/google/flatbuffers/wiki/Versioning)) but rather uses a format of the date of the release.
|
||||||
|
|
||||||
## Contribution
|
## Contribution
|
||||||
|
|
||||||
* [FlatBuffers Issues Tracker][] to submit an issue.
|
* [FlatBuffers Issues Tracker][] to submit an issue.
|
||||||
@@ -73,4 +77,4 @@ Please see our [Security Policy](SECURITY.md) for reporting vulnerabilities.
|
|||||||
[FlatBuffers Issues Tracker]: http://github.com/google/flatbuffers/issues
|
[FlatBuffers Issues Tracker]: http://github.com/google/flatbuffers/issues
|
||||||
[stackoverflow.com]: http://stackoverflow.com/search?q=flatbuffers
|
[stackoverflow.com]: http://stackoverflow.com/search?q=flatbuffers
|
||||||
[landing page]: https://google.github.io/flatbuffers
|
[landing page]: https://google.github.io/flatbuffers
|
||||||
[LICENSE]: https://github.com/google/flatbuffers/blob/master/LICENSE.txt
|
[LICENSE]: https://github.com/google/flatbuffers/blob/master/LICENSE
|
||||||
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,26 +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 = True,
|
# 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("@npm//:repositories.bzl", "npm_repositories")
|
||||||
|
|
||||||
|
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",
|
||||||
|
],
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -1,20 +1,22 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<!-- Copyright (c) 2014 Google, Inc.
|
|
||||||
|
|
||||||
This software is provided 'as-is', without any express or implied
|
|
||||||
warranty. In no event will the authors be held liable for any damages
|
|
||||||
arising from the use of this software.
|
|
||||||
Permission is granted to anyone to use this software for any purpose,
|
|
||||||
including commercial applications, and to alter it and redistribute it
|
|
||||||
freely, subject to the following restrictions:
|
|
||||||
1. The origin of this software must not be misrepresented; you must not
|
|
||||||
claim that you wrote the original software. If you use this software
|
|
||||||
in a product, an acknowledgment in the product documentation would be
|
|
||||||
appreciated but is not required.
|
|
||||||
2. Altered source versions must be plainly marked as such, and must not be
|
|
||||||
misrepresented as being the original software.
|
|
||||||
3. This notice may not be removed or altered from any source distribution.
|
|
||||||
-->
|
|
||||||
<projectDescription>
|
<projectDescription>
|
||||||
<name>FlatBufferTest</name>
|
<name>FlatBufferTest</name>
|
||||||
|
<comment></comment>
|
||||||
|
<projects>
|
||||||
|
</projects>
|
||||||
|
<buildSpec>
|
||||||
|
</buildSpec>
|
||||||
|
<natures>
|
||||||
|
</natures>
|
||||||
|
<filteredResources>
|
||||||
|
<filter>
|
||||||
|
<id>1677235311958</id>
|
||||||
|
<name></name>
|
||||||
|
<type>30</type>
|
||||||
|
<matcher>
|
||||||
|
<id>org.eclipse.core.resources.regexFilterMatcher</id>
|
||||||
|
<arguments>node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__</arguments>
|
||||||
|
</matcher>
|
||||||
|
</filter>
|
||||||
|
</filteredResources>
|
||||||
</projectDescription>
|
</projectDescription>
|
||||||
|
|||||||
@@ -1,15 +1,13 @@
|
|||||||
apply plugin: 'com.android.application'
|
apply plugin: 'com.android.application'
|
||||||
apply plugin: 'kotlin-android'
|
apply plugin: 'kotlin-android'
|
||||||
apply plugin: 'kotlin-android-extensions'
|
|
||||||
|
|
||||||
android {
|
android {
|
||||||
compileSdkVersion 30
|
compileSdk 33
|
||||||
buildToolsVersion "30.0.2"
|
|
||||||
|
|
||||||
defaultConfig {
|
defaultConfig {
|
||||||
applicationId "com.flatbuffers.app"
|
applicationId "com.flatbuffers.app"
|
||||||
minSdkVersion 26
|
minSdkVersion 26
|
||||||
targetSdkVersion 30
|
targetSdkVersion 33
|
||||||
versionCode 1
|
versionCode 1
|
||||||
versionName "1.0"
|
versionName "1.0"
|
||||||
|
|
||||||
@@ -113,13 +111,13 @@ android {
|
|||||||
dependsOn(generateFbsCpp)
|
dependsOn(generateFbsCpp)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
namespace 'com.flatbuffers.app'
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation fileTree(dir: "libs", include: ["*.jar"])
|
implementation fileTree(dir: "libs", include: ["*.jar"])
|
||||||
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
|
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
|
||||||
implementation 'androidx.core:core-ktx:1.3.2'
|
implementation 'androidx.appcompat:appcompat:1.6.1'
|
||||||
implementation 'androidx.appcompat:appcompat:1.2.0'
|
|
||||||
|
|
||||||
// If you using java runtime you can add its dependency as the example below
|
// If you using java runtime you can add its dependency as the example below
|
||||||
// implementation 'com.google.flatbuffers:flatbuffers-java:$latest_version'
|
// implementation 'com.google.flatbuffers:flatbuffers-java:$latest_version'
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
package="com.flatbuffers.app">
|
|
||||||
|
|
||||||
<application
|
<application
|
||||||
android:allowBackup="true"
|
android:allowBackup="true"
|
||||||
@@ -9,7 +8,8 @@
|
|||||||
android:roundIcon="@mipmap/ic_launcher_round"
|
android:roundIcon="@mipmap/ic_launcher_round"
|
||||||
android:supportsRtl="true"
|
android:supportsRtl="true"
|
||||||
android:theme="@style/AppTheme">
|
android:theme="@style/AppTheme">
|
||||||
<activity android:name=".MainActivity">
|
<activity android:name=".MainActivity"
|
||||||
|
android:exported="true">
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
<action android:name="android.intent.action.MAIN" />
|
<action android:name="android.intent.action.MAIN" />
|
||||||
|
|
||||||
|
|||||||
@@ -18,7 +18,6 @@ set(FlatBuffers_Library_SRCS
|
|||||||
${FLATBUFFERS_SRC}/include/flatbuffers/allocator.h
|
${FLATBUFFERS_SRC}/include/flatbuffers/allocator.h
|
||||||
${FLATBUFFERS_SRC}/include/flatbuffers/array.h
|
${FLATBUFFERS_SRC}/include/flatbuffers/array.h
|
||||||
${FLATBUFFERS_SRC}/include/flatbuffers/base.h
|
${FLATBUFFERS_SRC}/include/flatbuffers/base.h
|
||||||
${FLATBUFFERS_SRC}/include/flatbuffers/bfbs_generator.h
|
|
||||||
${FLATBUFFERS_SRC}/include/flatbuffers/buffer.h
|
${FLATBUFFERS_SRC}/include/flatbuffers/buffer.h
|
||||||
${FLATBUFFERS_SRC}/include/flatbuffers/buffer_ref.h
|
${FLATBUFFERS_SRC}/include/flatbuffers/buffer_ref.h
|
||||||
${FLATBUFFERS_SRC}/include/flatbuffers/default_allocator.h
|
${FLATBUFFERS_SRC}/include/flatbuffers/default_allocator.h
|
||||||
|
|||||||
@@ -8,9 +8,9 @@
|
|||||||
|
|
||||||
// Ensure the included flatbuffers.h is the same version as when this file was
|
// 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 == 2 &&
|
static_assert(FLATBUFFERS_VERSION_MAJOR == 23 &&
|
||||||
FLATBUFFERS_VERSION_MINOR == 0 &&
|
FLATBUFFERS_VERSION_MINOR == 1 &&
|
||||||
FLATBUFFERS_VERSION_REVISION == 8,
|
FLATBUFFERS_VERSION_REVISION == 21,
|
||||||
"Non-compatible flatbuffers version included");
|
"Non-compatible flatbuffers version included");
|
||||||
|
|
||||||
namespace com {
|
namespace com {
|
||||||
@@ -20,23 +20,23 @@ namespace app {
|
|||||||
struct Animal;
|
struct Animal;
|
||||||
struct AnimalBuilder;
|
struct AnimalBuilder;
|
||||||
|
|
||||||
struct Animal FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table {
|
struct Animal FLATBUFFERS_FINAL_CLASS : private ::flatbuffers::Table {
|
||||||
typedef AnimalBuilder Builder;
|
typedef AnimalBuilder Builder;
|
||||||
enum FlatBuffersVTableOffset FLATBUFFERS_VTABLE_UNDERLYING_TYPE {
|
enum FlatBuffersVTableOffset FLATBUFFERS_VTABLE_UNDERLYING_TYPE {
|
||||||
VT_NAME = 4,
|
VT_NAME = 4,
|
||||||
VT_SOUND = 6,
|
VT_SOUND = 6,
|
||||||
VT_WEIGHT = 8
|
VT_WEIGHT = 8
|
||||||
};
|
};
|
||||||
const flatbuffers::String *name() const {
|
const ::flatbuffers::String *name() const {
|
||||||
return GetPointer<const flatbuffers::String *>(VT_NAME);
|
return GetPointer<const ::flatbuffers::String *>(VT_NAME);
|
||||||
}
|
}
|
||||||
const flatbuffers::String *sound() const {
|
const ::flatbuffers::String *sound() const {
|
||||||
return GetPointer<const flatbuffers::String *>(VT_SOUND);
|
return GetPointer<const ::flatbuffers::String *>(VT_SOUND);
|
||||||
}
|
}
|
||||||
uint16_t weight() const {
|
uint16_t weight() const {
|
||||||
return GetField<uint16_t>(VT_WEIGHT, 0);
|
return GetField<uint16_t>(VT_WEIGHT, 0);
|
||||||
}
|
}
|
||||||
bool Verify(flatbuffers::Verifier &verifier) const {
|
bool Verify(::flatbuffers::Verifier &verifier) const {
|
||||||
return VerifyTableStart(verifier) &&
|
return VerifyTableStart(verifier) &&
|
||||||
VerifyOffset(verifier, VT_NAME) &&
|
VerifyOffset(verifier, VT_NAME) &&
|
||||||
verifier.VerifyString(name()) &&
|
verifier.VerifyString(name()) &&
|
||||||
@@ -49,32 +49,32 @@ struct Animal FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table {
|
|||||||
|
|
||||||
struct AnimalBuilder {
|
struct AnimalBuilder {
|
||||||
typedef Animal Table;
|
typedef Animal Table;
|
||||||
flatbuffers::FlatBufferBuilder &fbb_;
|
::flatbuffers::FlatBufferBuilder &fbb_;
|
||||||
flatbuffers::uoffset_t start_;
|
::flatbuffers::uoffset_t start_;
|
||||||
void add_name(flatbuffers::Offset<flatbuffers::String> name) {
|
void add_name(::flatbuffers::Offset<::flatbuffers::String> name) {
|
||||||
fbb_.AddOffset(Animal::VT_NAME, name);
|
fbb_.AddOffset(Animal::VT_NAME, name);
|
||||||
}
|
}
|
||||||
void add_sound(flatbuffers::Offset<flatbuffers::String> sound) {
|
void add_sound(::flatbuffers::Offset<::flatbuffers::String> sound) {
|
||||||
fbb_.AddOffset(Animal::VT_SOUND, sound);
|
fbb_.AddOffset(Animal::VT_SOUND, sound);
|
||||||
}
|
}
|
||||||
void add_weight(uint16_t weight) {
|
void add_weight(uint16_t weight) {
|
||||||
fbb_.AddElement<uint16_t>(Animal::VT_WEIGHT, weight, 0);
|
fbb_.AddElement<uint16_t>(Animal::VT_WEIGHT, weight, 0);
|
||||||
}
|
}
|
||||||
explicit AnimalBuilder(flatbuffers::FlatBufferBuilder &_fbb)
|
explicit AnimalBuilder(::flatbuffers::FlatBufferBuilder &_fbb)
|
||||||
: fbb_(_fbb) {
|
: fbb_(_fbb) {
|
||||||
start_ = fbb_.StartTable();
|
start_ = fbb_.StartTable();
|
||||||
}
|
}
|
||||||
flatbuffers::Offset<Animal> Finish() {
|
::flatbuffers::Offset<Animal> Finish() {
|
||||||
const auto end = fbb_.EndTable(start_);
|
const auto end = fbb_.EndTable(start_);
|
||||||
auto o = flatbuffers::Offset<Animal>(end);
|
auto o = ::flatbuffers::Offset<Animal>(end);
|
||||||
return o;
|
return o;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
inline flatbuffers::Offset<Animal> CreateAnimal(
|
inline ::flatbuffers::Offset<Animal> CreateAnimal(
|
||||||
flatbuffers::FlatBufferBuilder &_fbb,
|
::flatbuffers::FlatBufferBuilder &_fbb,
|
||||||
flatbuffers::Offset<flatbuffers::String> name = 0,
|
::flatbuffers::Offset<::flatbuffers::String> name = 0,
|
||||||
flatbuffers::Offset<flatbuffers::String> sound = 0,
|
::flatbuffers::Offset<::flatbuffers::String> sound = 0,
|
||||||
uint16_t weight = 0) {
|
uint16_t weight = 0) {
|
||||||
AnimalBuilder builder_(_fbb);
|
AnimalBuilder builder_(_fbb);
|
||||||
builder_.add_sound(sound);
|
builder_.add_sound(sound);
|
||||||
@@ -83,8 +83,8 @@ inline flatbuffers::Offset<Animal> CreateAnimal(
|
|||||||
return builder_.Finish();
|
return builder_.Finish();
|
||||||
}
|
}
|
||||||
|
|
||||||
inline flatbuffers::Offset<Animal> CreateAnimalDirect(
|
inline ::flatbuffers::Offset<Animal> CreateAnimalDirect(
|
||||||
flatbuffers::FlatBufferBuilder &_fbb,
|
::flatbuffers::FlatBufferBuilder &_fbb,
|
||||||
const char *name = nullptr,
|
const char *name = nullptr,
|
||||||
const char *sound = nullptr,
|
const char *sound = nullptr,
|
||||||
uint16_t weight = 0) {
|
uint16_t weight = 0) {
|
||||||
@@ -98,32 +98,32 @@ inline flatbuffers::Offset<Animal> CreateAnimalDirect(
|
|||||||
}
|
}
|
||||||
|
|
||||||
inline const com::fbs::app::Animal *GetAnimal(const void *buf) {
|
inline const com::fbs::app::Animal *GetAnimal(const void *buf) {
|
||||||
return flatbuffers::GetRoot<com::fbs::app::Animal>(buf);
|
return ::flatbuffers::GetRoot<com::fbs::app::Animal>(buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline const com::fbs::app::Animal *GetSizePrefixedAnimal(const void *buf) {
|
inline const com::fbs::app::Animal *GetSizePrefixedAnimal(const void *buf) {
|
||||||
return flatbuffers::GetSizePrefixedRoot<com::fbs::app::Animal>(buf);
|
return ::flatbuffers::GetSizePrefixedRoot<com::fbs::app::Animal>(buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool VerifyAnimalBuffer(
|
inline bool VerifyAnimalBuffer(
|
||||||
flatbuffers::Verifier &verifier) {
|
::flatbuffers::Verifier &verifier) {
|
||||||
return verifier.VerifyBuffer<com::fbs::app::Animal>(nullptr);
|
return verifier.VerifyBuffer<com::fbs::app::Animal>(nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool VerifySizePrefixedAnimalBuffer(
|
inline bool VerifySizePrefixedAnimalBuffer(
|
||||||
flatbuffers::Verifier &verifier) {
|
::flatbuffers::Verifier &verifier) {
|
||||||
return verifier.VerifySizePrefixedBuffer<com::fbs::app::Animal>(nullptr);
|
return verifier.VerifySizePrefixedBuffer<com::fbs::app::Animal>(nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void FinishAnimalBuffer(
|
inline void FinishAnimalBuffer(
|
||||||
flatbuffers::FlatBufferBuilder &fbb,
|
::flatbuffers::FlatBufferBuilder &fbb,
|
||||||
flatbuffers::Offset<com::fbs::app::Animal> root) {
|
::flatbuffers::Offset<com::fbs::app::Animal> root) {
|
||||||
fbb.Finish(root);
|
fbb.Finish(root);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void FinishSizePrefixedAnimalBuffer(
|
inline void FinishSizePrefixedAnimalBuffer(
|
||||||
flatbuffers::FlatBufferBuilder &fbb,
|
::flatbuffers::FlatBufferBuilder &fbb,
|
||||||
flatbuffers::Offset<com::fbs::app::Animal> root) {
|
::flatbuffers::Offset<com::fbs::app::Animal> root) {
|
||||||
fbb.FinishSizePrefixed(root);
|
fbb.FinishSizePrefixed(root);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,11 +2,24 @@
|
|||||||
|
|
||||||
package com.fbs.app
|
package com.fbs.app
|
||||||
|
|
||||||
import java.nio.*
|
import com.google.flatbuffers.BaseVector
|
||||||
|
import com.google.flatbuffers.BooleanVector
|
||||||
|
import com.google.flatbuffers.ByteVector
|
||||||
|
import com.google.flatbuffers.Constants
|
||||||
|
import com.google.flatbuffers.DoubleVector
|
||||||
|
import com.google.flatbuffers.FlatBufferBuilder
|
||||||
|
import com.google.flatbuffers.FloatVector
|
||||||
|
import com.google.flatbuffers.LongVector
|
||||||
|
import com.google.flatbuffers.StringVector
|
||||||
|
import com.google.flatbuffers.Struct
|
||||||
|
import com.google.flatbuffers.Table
|
||||||
|
import com.google.flatbuffers.UnionVector
|
||||||
|
import java.nio.ByteBuffer
|
||||||
|
import java.nio.ByteOrder
|
||||||
import kotlin.math.sign
|
import kotlin.math.sign
|
||||||
import com.google.flatbuffers.*
|
|
||||||
|
|
||||||
@Suppress("unused")
|
@Suppress("unused")
|
||||||
|
@kotlin.ExperimentalUnsignedTypes
|
||||||
class Animal : Table() {
|
class Animal : Table() {
|
||||||
|
|
||||||
fun __init(_i: Int, _bb: ByteBuffer) {
|
fun __init(_i: Int, _bb: ByteBuffer) {
|
||||||
@@ -19,14 +32,22 @@ class Animal : Table() {
|
|||||||
val name : String?
|
val name : String?
|
||||||
get() {
|
get() {
|
||||||
val o = __offset(4)
|
val o = __offset(4)
|
||||||
return if (o != 0) __string(o + bb_pos) else null
|
return if (o != 0) {
|
||||||
|
__string(o + bb_pos)
|
||||||
|
} else {
|
||||||
|
null
|
||||||
|
}
|
||||||
}
|
}
|
||||||
val nameAsByteBuffer : ByteBuffer get() = __vector_as_bytebuffer(4, 1)
|
val nameAsByteBuffer : ByteBuffer get() = __vector_as_bytebuffer(4, 1)
|
||||||
fun nameInByteBuffer(_bb: ByteBuffer) : ByteBuffer = __vector_in_bytebuffer(_bb, 4, 1)
|
fun nameInByteBuffer(_bb: ByteBuffer) : ByteBuffer = __vector_in_bytebuffer(_bb, 4, 1)
|
||||||
val sound : String?
|
val sound : String?
|
||||||
get() {
|
get() {
|
||||||
val o = __offset(6)
|
val o = __offset(6)
|
||||||
return if (o != 0) __string(o + bb_pos) else null
|
return if (o != 0) {
|
||||||
|
__string(o + bb_pos)
|
||||||
|
} else {
|
||||||
|
null
|
||||||
|
}
|
||||||
}
|
}
|
||||||
val soundAsByteBuffer : ByteBuffer get() = __vector_as_bytebuffer(6, 1)
|
val soundAsByteBuffer : ByteBuffer get() = __vector_as_bytebuffer(6, 1)
|
||||||
fun soundInByteBuffer(_bb: ByteBuffer) : ByteBuffer = __vector_in_bytebuffer(_bb, 6, 1)
|
fun soundInByteBuffer(_bb: ByteBuffer) : ByteBuffer = __vector_in_bytebuffer(_bb, 6, 1)
|
||||||
@@ -36,7 +57,7 @@ class Animal : Table() {
|
|||||||
return if(o != 0) bb.getShort(o + bb_pos).toUShort() else 0u
|
return if(o != 0) bb.getShort(o + bb_pos).toUShort() else 0u
|
||||||
}
|
}
|
||||||
companion object {
|
companion object {
|
||||||
fun validateVersion() = Constants.FLATBUFFERS_23_1_4()
|
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)
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
// Top-level build file where you can add configuration options common to all sub-projects/modules.
|
// Top-level build file where you can add configuration options common to all sub-projects/modules.
|
||||||
buildscript {
|
buildscript {
|
||||||
ext.kotlin_version = "1.4.10"
|
ext.kotlin_version = "1.7.21"
|
||||||
repositories {
|
repositories {
|
||||||
google()
|
google()
|
||||||
jcenter()
|
mavenCentral()
|
||||||
}
|
}
|
||||||
dependencies {
|
dependencies {
|
||||||
classpath 'com.android.tools.build:gradle:4.1.0'
|
classpath 'com.android.tools.build:gradle:7.4.1'
|
||||||
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
|
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
|
||||||
|
|
||||||
// NOTE: Do not place your application dependencies here; they belong
|
// NOTE: Do not place your application dependencies here; they belong
|
||||||
@@ -17,7 +17,7 @@ buildscript {
|
|||||||
allprojects {
|
allprojects {
|
||||||
repositories {
|
repositories {
|
||||||
google()
|
google()
|
||||||
jcenter()
|
mavenCentral()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
distributionBase=GRADLE_USER_HOME
|
distributionBase=GRADLE_USER_HOME
|
||||||
distributionPath=wrapper/dists
|
distributionPath=wrapper/dists
|
||||||
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4.2-bin.zip
|
distributionUrl=https\://services.gradle.org/distributions/gradle-8.0.1-bin.zip
|
||||||
zipStoreBase=GRADLE_USER_HOME
|
zipStoreBase=GRADLE_USER_HOME
|
||||||
zipStorePath=wrapper/dists
|
zipStorePath=wrapper/dists
|
||||||
|
|||||||
@@ -1,8 +1,9 @@
|
|||||||
# Setup for running Google Benchmarks (https://github.com/google/benchmark) on
|
# Setup for running Google Benchmarks (https://github.com/google/benchmark) on
|
||||||
# flatbuffers. This requires both that benchmark library and its depenency gtest
|
# flatbuffers. This requires both that benchmark library and its dependency gtest
|
||||||
# to build. Instead of including them here or doing a submodule, this uses
|
# to build. Instead of including them here or doing a submodule, this uses
|
||||||
# FetchContent (https://cmake.org/cmake/help/latest/module/FetchContent.html) to
|
# FetchContent (https://cmake.org/cmake/help/latest/module/FetchContent.html) to
|
||||||
# grab the dependencies at config time. This requires CMake 3.14 or higher.
|
# grab the dependencies at config time. This requires CMake 3.14 or higher.
|
||||||
|
|
||||||
cmake_minimum_required(VERSION 3.14)
|
cmake_minimum_required(VERSION 3.14)
|
||||||
include(FetchContent)
|
include(FetchContent)
|
||||||
|
|
||||||
@@ -27,7 +28,7 @@ FetchContent_MakeAvailable(
|
|||||||
googlebenchmark
|
googlebenchmark
|
||||||
)
|
)
|
||||||
|
|
||||||
set(CPP_BENCH_DIR cpp)
|
set(CPP_BENCH_DIR ${CMAKE_CURRENT_SOURCE_DIR}/cpp)
|
||||||
set(CPP_FB_BENCH_DIR ${CPP_BENCH_DIR}/flatbuffers)
|
set(CPP_FB_BENCH_DIR ${CPP_BENCH_DIR}/flatbuffers)
|
||||||
set(CPP_RAW_BENCH_DIR ${CPP_BENCH_DIR}/raw)
|
set(CPP_RAW_BENCH_DIR ${CPP_BENCH_DIR}/raw)
|
||||||
set(CPP_BENCH_FBS ${CPP_FB_BENCH_DIR}/bench.fbs)
|
set(CPP_BENCH_FBS ${CPP_FB_BENCH_DIR}/bench.fbs)
|
||||||
@@ -62,8 +63,8 @@ add_custom_command(
|
|||||||
add_executable(flatbenchmark ${FlatBenchmark_SRCS})
|
add_executable(flatbenchmark ${FlatBenchmark_SRCS})
|
||||||
|
|
||||||
# Benchmark requires C++11
|
# Benchmark requires C++11
|
||||||
target_compile_features(flatbenchmark PUBLIC
|
target_compile_features(flatbenchmark PRIVATE
|
||||||
cxx_std_11
|
cxx_std_11 # requires cmake 3.8
|
||||||
)
|
)
|
||||||
|
|
||||||
target_compile_options(flatbenchmark
|
target_compile_options(flatbenchmark
|
||||||
@@ -81,7 +82,7 @@ set_target_properties(flatbenchmark
|
|||||||
# The includes of the benchmark files are fully qualified from flatbuffers root.
|
# The includes of the benchmark files are fully qualified from flatbuffers root.
|
||||||
target_include_directories(flatbenchmark PUBLIC ${CMAKE_SOURCE_DIR})
|
target_include_directories(flatbenchmark PUBLIC ${CMAKE_SOURCE_DIR})
|
||||||
|
|
||||||
target_link_libraries(flatbenchmark
|
target_link_libraries(flatbenchmark PRIVATE
|
||||||
benchmark::benchmark_main # _main to use their entry point
|
benchmark::benchmark_main # _main to use their entry point
|
||||||
gtest # Link to gtest so we can also assert in the benchmarks
|
gtest # Link to gtest so we can also assert in the benchmarks
|
||||||
)
|
)
|
||||||
@@ -7,7 +7,7 @@ Rules for building C++ flatbuffers with Bazel.
|
|||||||
|
|
||||||
load("@rules_cc//cc:defs.bzl", "cc_library")
|
load("@rules_cc//cc:defs.bzl", "cc_library")
|
||||||
|
|
||||||
flatc_path = "@com_github_google_flatbuffers//:flatc"
|
TRUE_FLATC_PATH = "@com_github_google_flatbuffers//:flatc"
|
||||||
|
|
||||||
DEFAULT_INCLUDE_PATHS = [
|
DEFAULT_INCLUDE_PATHS = [
|
||||||
"./",
|
"./",
|
||||||
@@ -16,6 +16,14 @@ DEFAULT_INCLUDE_PATHS = [
|
|||||||
"$(execpath @com_github_google_flatbuffers//:flatc).runfiles/com_github_google_flatbuffers",
|
"$(execpath @com_github_google_flatbuffers//:flatc).runfiles/com_github_google_flatbuffers",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
def default_include_paths(flatc_path):
|
||||||
|
return [
|
||||||
|
"./",
|
||||||
|
"$(GENDIR)",
|
||||||
|
"$(BINDIR)",
|
||||||
|
"$(execpath %s).runfiles/com_github_google_flatbuffers" % (flatc_path),
|
||||||
|
]
|
||||||
|
|
||||||
DEFAULT_FLATC_ARGS = [
|
DEFAULT_FLATC_ARGS = [
|
||||||
"--gen-object-api",
|
"--gen-object-api",
|
||||||
"--gen-compare",
|
"--gen-compare",
|
||||||
@@ -32,14 +40,18 @@ def flatbuffer_library_public(
|
|||||||
language_flag,
|
language_flag,
|
||||||
out_prefix = "",
|
out_prefix = "",
|
||||||
includes = [],
|
includes = [],
|
||||||
include_paths = DEFAULT_INCLUDE_PATHS,
|
include_paths = None,
|
||||||
flatc_args = DEFAULT_FLATC_ARGS,
|
flatc_args = DEFAULT_FLATC_ARGS,
|
||||||
reflection_name = "",
|
reflection_name = "",
|
||||||
reflection_visibility = None,
|
reflection_visibility = None,
|
||||||
compatible_with = None,
|
compatible_with = None,
|
||||||
restricted_to = None,
|
restricted_to = None,
|
||||||
target_compatible_with = None,
|
target_compatible_with = None,
|
||||||
output_to_bindir = False):
|
flatc_path = "@com_github_google_flatbuffers//:flatc",
|
||||||
|
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:
|
||||||
@@ -62,15 +74,25 @@ def flatbuffer_library_public(
|
|||||||
for, instead of default-supported environments.
|
for, instead of default-supported environments.
|
||||||
target_compatible_with: Optional, The list of target platform constraints
|
target_compatible_with: Optional, The list of target platform constraints
|
||||||
to use.
|
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
|
||||||
optionally a Fileset([reflection_name]) with all generated reflection
|
optionally a Fileset([reflection_name]) with all generated reflection
|
||||||
binaries.
|
binaries.
|
||||||
"""
|
"""
|
||||||
|
if include_paths == None:
|
||||||
|
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.
|
||||||
@@ -80,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),
|
||||||
"$(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,
|
||||||
@@ -93,18 +115,19 @@ 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([
|
||||||
"SRCS=($(SRCS));",
|
"SRCS=($(SRCS));",
|
||||||
"for f in $${SRCS[@]:0:%s}; do" % len(srcs),
|
"for f in $${SRCS[@]:0:%s}; do" % len(srcs),
|
||||||
"$(location %s)" % (flatc_path),
|
"$(location %s)" % (TRUE_FLATC_PATH),
|
||||||
"-b --schema",
|
"-b --schema",
|
||||||
" ".join(flatc_args),
|
" ".join(flatc_args),
|
||||||
" ".join(include_paths_cmd),
|
" ".join(include_paths_cmd),
|
||||||
@@ -122,7 +145,7 @@ def flatbuffer_library_public(
|
|||||||
srcs = srcs + includes,
|
srcs = srcs + includes,
|
||||||
outs = reflection_outs,
|
outs = reflection_outs,
|
||||||
output_to_bindir = output_to_bindir,
|
output_to_bindir = output_to_bindir,
|
||||||
tools = [flatc_path],
|
tools = [TRUE_FLATC_PATH],
|
||||||
compatible_with = compatible_with,
|
compatible_with = compatible_with,
|
||||||
restricted_to = restricted_to,
|
restricted_to = restricted_to,
|
||||||
target_compatible_with = target_compatible_with,
|
target_compatible_with = target_compatible_with,
|
||||||
@@ -142,10 +165,11 @@ def flatbuffer_cc_library(
|
|||||||
name,
|
name,
|
||||||
srcs,
|
srcs,
|
||||||
srcs_filegroup_name = "",
|
srcs_filegroup_name = "",
|
||||||
|
outs = [],
|
||||||
out_prefix = "",
|
out_prefix = "",
|
||||||
deps = [],
|
deps = [],
|
||||||
includes = [],
|
includes = [],
|
||||||
include_paths = DEFAULT_INCLUDE_PATHS,
|
include_paths = None,
|
||||||
cc_include_paths = [],
|
cc_include_paths = [],
|
||||||
flatc_args = DEFAULT_FLATC_ARGS,
|
flatc_args = DEFAULT_FLATC_ARGS,
|
||||||
visibility = None,
|
visibility = None,
|
||||||
@@ -162,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
|
||||||
@@ -209,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.1.4
|
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;
|
||||||
|
|||||||
@@ -91,6 +91,9 @@ Additional options:
|
|||||||
- `--scoped-enums` : Use C++11 style scoped and strongly typed enums in
|
- `--scoped-enums` : Use C++11 style scoped and strongly typed enums in
|
||||||
generated C++. This also implies `--no-prefix`.
|
generated C++. This also implies `--no-prefix`.
|
||||||
|
|
||||||
|
- `--no-emit-min-max-enum-values` : Disable generation of MIN and MAX
|
||||||
|
enumerated values for scoped enums and prefixed enums.
|
||||||
|
|
||||||
- `--gen-includes` : (deprecated), this is the default behavior.
|
- `--gen-includes` : (deprecated), this is the default behavior.
|
||||||
If the original behavior is required (no include
|
If the original behavior is required (no include
|
||||||
statements) use `--no-includes.`
|
statements) use `--no-includes.`
|
||||||
|
|||||||
@@ -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?
|
||||||
|
|
||||||
|
|||||||
@@ -72,7 +72,10 @@ Now you can access values like this:
|
|||||||
In some cases it's necessary to modify values in an existing FlatBuffer in place (without creating a copy). For this reason, scalar fields of a Flatbuffer table or struct can be mutated.
|
In some cases it's necessary to modify values in an existing FlatBuffer in place (without creating a copy). For this reason, scalar fields of a Flatbuffer table or struct can be mutated.
|
||||||
|
|
||||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.swift}
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.swift}
|
||||||
let monster = Monster.getRootAsMonster(bb: ByteBuffer(data: data))
|
var byteBuffer = ByteBuffer(bytes: data)
|
||||||
|
// Get an accessor to the root object inside the buffer.
|
||||||
|
let monster: Monster = try! getCheckedRoot(byteBuffer: &byteBuffer)
|
||||||
|
// let monster: Monster = getRoot(byteBuffer: &byteBuffer)
|
||||||
|
|
||||||
if !monster.mutate(hp: 10) {
|
if !monster.mutate(hp: 10) {
|
||||||
fatalError("couldn't mutate")
|
fatalError("couldn't mutate")
|
||||||
|
|||||||
@@ -321,9 +321,8 @@ Please be aware of the difference between `flatc` and `flatcc` tools.
|
|||||||
<div class="language-javascript">
|
<div class="language-javascript">
|
||||||
~~~{.sh}
|
~~~{.sh}
|
||||||
cd flatbuffers/samples
|
cd flatbuffers/samples
|
||||||
./../flatc --ts monster.fbs
|
./../flatc --ts-flat-files --ts monster.fbs
|
||||||
# customize your TS -> JS transpilation
|
# produces ts/js modules and js bundle monster_generated.js
|
||||||
tsc monster_generated.ts
|
|
||||||
~~~
|
~~~
|
||||||
</div>
|
</div>
|
||||||
<div class="language-typescript">
|
<div class="language-typescript">
|
||||||
@@ -530,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,
|
||||||
@@ -653,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">
|
||||||
@@ -2241,7 +2240,7 @@ before:
|
|||||||
~~~{.ts}
|
~~~{.ts}
|
||||||
// note: import flatbuffers with your desired import method
|
// note: import flatbuffers with your desired import method
|
||||||
|
|
||||||
// note: the `./monster_generated.ts` file was previously generated by `flatc` above using the `monster.fbs` schema
|
// note: the `./monster_generated.js` file was previously generated by `flatc` above using the `monster.fbs` schema
|
||||||
import { MyGame } from './monster_generated';
|
import { MyGame } from './monster_generated';
|
||||||
~~~
|
~~~
|
||||||
</div>
|
</div>
|
||||||
@@ -2310,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,
|
||||||
@@ -2466,16 +2465,16 @@ 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">
|
||||||
~~~{.swift}
|
~~~{.swift}
|
||||||
// create a ByteBuffer(:) from an [UInt8] or Data()
|
// create a ByteBuffer(:) from an [UInt8] or Data()
|
||||||
let buf = // Get your data
|
var buf = // Get your data
|
||||||
|
|
||||||
// Get an accessor to the root object inside the buffer.
|
// Get an accessor to the root object inside the buffer.
|
||||||
let monster = Monster.getRootAsMonster(bb: ByteBuffer(bytes: buf))
|
let monster: Monster = try! getCheckedRoot(byteBuffer: &byteBuffer)
|
||||||
|
// let monster: Monster = getRoot(byteBuffer: &byteBuffer)
|
||||||
~~~
|
~~~
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
@@ -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,12 +6,10 @@ import FlatBuffers
|
|||||||
|
|
||||||
public struct models_HelloReply: FlatBufferObject, Verifiable {
|
public struct models_HelloReply: FlatBufferObject, Verifiable {
|
||||||
|
|
||||||
static func validateVersion() { FlatBuffersVersion_23_1_4() }
|
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
|
||||||
|
|
||||||
public static func getRootAsHelloReply(bb: ByteBuffer) -> models_HelloReply { return models_HelloReply(Table(bb: bb, position: Int32(bb.read(def: UOffset.self, position: bb.reader)) + Int32(bb.reader))) }
|
|
||||||
|
|
||||||
private init(_ t: Table) { _accessor = t }
|
private init(_ t: Table) { _accessor = t }
|
||||||
public init(_ bb: ByteBuffer, o: Int32) { _accessor = Table(bb: bb, position: o) }
|
public init(_ bb: ByteBuffer, o: Int32) { _accessor = Table(bb: bb, position: o) }
|
||||||
|
|
||||||
@@ -55,12 +53,10 @@ extension models_HelloReply: Encodable {
|
|||||||
|
|
||||||
public struct models_HelloRequest: FlatBufferObject, Verifiable {
|
public struct models_HelloRequest: FlatBufferObject, Verifiable {
|
||||||
|
|
||||||
static func validateVersion() { FlatBuffersVersion_23_1_4() }
|
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
|
||||||
|
|
||||||
public static func getRootAsHelloRequest(bb: ByteBuffer) -> models_HelloRequest { return models_HelloRequest(Table(bb: bb, position: Int32(bb.read(def: UOffset.self, position: bb.reader)) + Int32(bb.reader))) }
|
|
||||||
|
|
||||||
private init(_ t: Table) { _accessor = t }
|
private init(_ t: Table) { _accessor = t }
|
||||||
public init(_ bb: ByteBuffer, o: Int32) { _accessor = Table(bb: bb, position: o) }
|
public init(_ bb: ByteBuffer, o: Int32) { _accessor = Table(bb: bb, position: o) }
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2021 Google Inc. All rights reserved.
|
* Copyright 2023 Google Inc. All rights reserved.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2021 Google Inc. All rights reserved.
|
* Copyright 2023 Google Inc. All rights reserved.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|||||||
@@ -1,2 +1,3 @@
|
|||||||
export { HelloReply } from './models/hello-reply';
|
// automatically generated by the FlatBuffers compiler, do not modify
|
||||||
export { HelloRequest } from './models/hello-request';
|
|
||||||
|
export * as models from './models.js';
|
||||||
|
|||||||
4
grpc/examples/ts/greeter/src/models.ts
Normal file
4
grpc/examples/ts/greeter/src/models.ts
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
// automatically generated by the FlatBuffers compiler, do not modify
|
||||||
|
|
||||||
|
export { HelloReply } from './models/hello-reply.js';
|
||||||
|
export { HelloRequest } from './models/hello-request.js';
|
||||||
@@ -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 = [
|
||||||
|
|||||||
@@ -17,6 +17,8 @@
|
|||||||
#ifndef FLATBUFFERS_ARRAY_H_
|
#ifndef FLATBUFFERS_ARRAY_H_
|
||||||
#define FLATBUFFERS_ARRAY_H_
|
#define FLATBUFFERS_ARRAY_H_
|
||||||
|
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
#include "flatbuffers/base.h"
|
#include "flatbuffers/base.h"
|
||||||
#include "flatbuffers/stl_emulation.h"
|
#include "flatbuffers/stl_emulation.h"
|
||||||
#include "flatbuffers/vector.h"
|
#include "flatbuffers/vector.h"
|
||||||
@@ -238,6 +240,14 @@ const Array<E, length> &CastToArrayOfEnum(const T (&arr)[length]) {
|
|||||||
return *reinterpret_cast<const Array<E, length> *>(arr);
|
return *reinterpret_cast<const Array<E, length> *>(arr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<typename T, uint16_t length>
|
||||||
|
bool operator==(const Array<T, length> &lhs,
|
||||||
|
const Array<T, length> &rhs) noexcept {
|
||||||
|
return std::addressof(lhs) == std::addressof(rhs) ||
|
||||||
|
(lhs.size() == rhs.size() &&
|
||||||
|
std::memcmp(lhs.Data(), rhs.Data(), rhs.size() * sizeof(T)) == 0);
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace flatbuffers
|
} // namespace flatbuffers
|
||||||
|
|
||||||
#endif // FLATBUFFERS_ARRAY_H_
|
#endif // FLATBUFFERS_ARRAY_H_
|
||||||
|
|||||||
@@ -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 1
|
#define FLATBUFFERS_VERSION_MINOR 5
|
||||||
#define FLATBUFFERS_VERSION_REVISION 4
|
#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")
|
#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
|
||||||
|
|||||||
82
include/flatbuffers/code_generator.h
Normal file
82
include/flatbuffers/code_generator.h
Normal file
@@ -0,0 +1,82 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2023 Google Inc. All rights reserved.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef FLATBUFFERS_CODE_GENERATOR_H_
|
||||||
|
#define FLATBUFFERS_CODE_GENERATOR_H_
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
#include "flatbuffers/idl.h"
|
||||||
|
|
||||||
|
namespace flatbuffers {
|
||||||
|
|
||||||
|
// A code generator interface for producing converting flatbuffer schema into
|
||||||
|
// code.
|
||||||
|
class CodeGenerator {
|
||||||
|
public:
|
||||||
|
virtual ~CodeGenerator() = default;
|
||||||
|
|
||||||
|
enum Status {
|
||||||
|
OK = 0,
|
||||||
|
ERROR = 1,
|
||||||
|
FAILED_VERIFICATION = 2,
|
||||||
|
NOT_IMPLEMENTED = 3
|
||||||
|
};
|
||||||
|
|
||||||
|
std::string status_detail;
|
||||||
|
|
||||||
|
// Generate code from the provided `parser`.
|
||||||
|
//
|
||||||
|
// DEPRECATED: prefer using the other overload of GenerateCode for bfbs.
|
||||||
|
virtual Status GenerateCode(const Parser &parser, const std::string &path,
|
||||||
|
const std::string &filename) = 0;
|
||||||
|
|
||||||
|
// Generate code from the provided `buffer` of given `length`. The buffer is a
|
||||||
|
// serialized reflection.fbs.
|
||||||
|
virtual Status GenerateCode(const uint8_t *buffer, int64_t length) = 0;
|
||||||
|
|
||||||
|
virtual Status GenerateMakeRule(const Parser &parser, const std::string &path,
|
||||||
|
const std::string &filename,
|
||||||
|
std::string &output) = 0;
|
||||||
|
|
||||||
|
virtual Status GenerateGrpcCode(const Parser &parser, const std::string &path,
|
||||||
|
const std::string &filename) = 0;
|
||||||
|
|
||||||
|
virtual Status GenerateRootFile(const Parser &parser,
|
||||||
|
const std::string &path) = 0;
|
||||||
|
|
||||||
|
virtual bool IsSchemaOnly() const = 0;
|
||||||
|
|
||||||
|
virtual bool SupportsBfbsGeneration() const = 0;
|
||||||
|
|
||||||
|
virtual bool SupportsRootFileGeneration() const = 0;
|
||||||
|
|
||||||
|
virtual IDLOptions::Language Language() const = 0;
|
||||||
|
|
||||||
|
virtual std::string LanguageName() const = 0;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
CodeGenerator() = default;
|
||||||
|
|
||||||
|
private:
|
||||||
|
// Copying is not supported.
|
||||||
|
CodeGenerator(const CodeGenerator &) = delete;
|
||||||
|
CodeGenerator &operator=(const CodeGenerator &) = delete;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace flatbuffers
|
||||||
|
|
||||||
|
#endif // FLATBUFFERS_CODE_GENERATOR_H_
|
||||||
@@ -45,7 +45,7 @@ class DetachedBuffer {
|
|||||||
cur_(cur),
|
cur_(cur),
|
||||||
size_(sz) {}
|
size_(sz) {}
|
||||||
|
|
||||||
DetachedBuffer(DetachedBuffer &&other)
|
DetachedBuffer(DetachedBuffer &&other) noexcept
|
||||||
: allocator_(other.allocator_),
|
: allocator_(other.allocator_),
|
||||||
own_allocator_(other.own_allocator_),
|
own_allocator_(other.own_allocator_),
|
||||||
buf_(other.buf_),
|
buf_(other.buf_),
|
||||||
@@ -55,7 +55,7 @@ class DetachedBuffer {
|
|||||||
other.reset();
|
other.reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
DetachedBuffer &operator=(DetachedBuffer &&other) {
|
DetachedBuffer &operator=(DetachedBuffer &&other) noexcept {
|
||||||
if (this == &other) return *this;
|
if (this == &other) return *this;
|
||||||
|
|
||||||
destroy();
|
destroy();
|
||||||
|
|||||||
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>>
|
||||||
@@ -98,7 +98,7 @@ class FlatBufferBuilder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// @brief Move constructor for FlatBufferBuilder.
|
/// @brief Move constructor for FlatBufferBuilder.
|
||||||
FlatBufferBuilder(FlatBufferBuilder &&other)
|
FlatBufferBuilder(FlatBufferBuilder &&other) noexcept
|
||||||
: buf_(1024, nullptr, false, AlignOf<largest_scalar_t>()),
|
: buf_(1024, nullptr, false, AlignOf<largest_scalar_t>()),
|
||||||
num_field_loc(0),
|
num_field_loc(0),
|
||||||
max_voffset_(0),
|
max_voffset_(0),
|
||||||
@@ -116,7 +116,7 @@ class FlatBufferBuilder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// @brief Move assignment operator for FlatBufferBuilder.
|
/// @brief Move assignment operator for FlatBufferBuilder.
|
||||||
FlatBufferBuilder &operator=(FlatBufferBuilder &&other) {
|
FlatBufferBuilder &operator=(FlatBufferBuilder &&other) noexcept {
|
||||||
// Move construct a temporary and swap idiom
|
// Move construct a temporary and swap idiom
|
||||||
FlatBufferBuilder temp(std::move(other));
|
FlatBufferBuilder temp(std::move(other));
|
||||||
Swap(temp);
|
Swap(temp);
|
||||||
@@ -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)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user