forked from BigfootDev/flatbuffers
Compare commits
44 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
76ddae006f | ||
|
|
cfe157ec56 | ||
|
|
413115858c | ||
|
|
88046190ee | ||
|
|
72aa85a759 | ||
|
|
bfceebb7fb | ||
|
|
bc44fad352 | ||
|
|
4fca4dc60c | ||
|
|
036032373b | ||
|
|
89dfb43f3b | ||
|
|
c49aff4b6f | ||
|
|
56e60223c3 | ||
|
|
89b1f5aa1b | ||
|
|
b901598233 | ||
|
|
8cdc6a2885 | ||
|
|
a67e35aff9 | ||
|
|
f124e41ae6 | ||
|
|
4c954181cd | ||
|
|
7f7547737e | ||
|
|
a79d61ea85 | ||
|
|
d465b39c3e | ||
|
|
c5a609dc20 | ||
|
|
5634dc3d0d | ||
|
|
37e37b8cad | ||
|
|
8fd4534fbe | ||
|
|
d5427da52f | ||
|
|
06c5c7ed0b | ||
|
|
b190ce11b0 | ||
|
|
bf5d23230a | ||
|
|
ce382d6dd3 | ||
|
|
41d9add7ef | ||
|
|
6a87427540 | ||
|
|
694add668b | ||
|
|
7edf8c9084 | ||
|
|
b86387442e | ||
|
|
e2eb5ee670 | ||
|
|
994502b6dd | ||
|
|
fa41e83679 | ||
|
|
799cc8f7b9 | ||
|
|
b7eb441470 | ||
|
|
8d01c5859c | ||
|
|
237e8b71fe | ||
|
|
eeb8fd60d5 | ||
|
|
fef2ffc4d0 |
6
.github/labeler.yml
vendored
6
.github/labeler.yml
vendored
@@ -15,9 +15,7 @@ c#:
|
||||
swift:
|
||||
- '**/*.swift'
|
||||
- swift/**/*
|
||||
- tests/FlatBuffers.GRPC.Swift/**/*
|
||||
- tests/FlatBuffers.Benchmarks.swift/**/*
|
||||
- tests/FlatBuffers.Test.Swift/**/*
|
||||
- tests/swift/**
|
||||
- src/idl_gen_swift.cpp
|
||||
|
||||
javascript:
|
||||
@@ -86,9 +84,7 @@ documentation:
|
||||
|
||||
CI:
|
||||
- '.github/**/*'
|
||||
- '.travis/**/*'
|
||||
- '.bazelci/**/*'
|
||||
- .travis.yml
|
||||
|
||||
grpc:
|
||||
- grpc/**/*
|
||||
|
||||
67
.github/workflows/build.yml
vendored
67
.github/workflows/build.yml
vendored
@@ -63,6 +63,59 @@ jobs:
|
||||
id: hash-gcc
|
||||
run: echo "::set-output name=hashes::$(sha256sum Linux.flatc.binary.${{ matrix.cxx }}.zip | base64 -w0)"
|
||||
|
||||
build-linux-cpp-std:
|
||||
name: Build Linux C++
|
||||
runs-on: ubuntu-latest
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
std: [11, 14, 17, 20, 23]
|
||||
cxx: [g++-10, clang++-12]
|
||||
exclude:
|
||||
# GCC 10.3.0 doesn't support std 23
|
||||
- cxx: g++-10
|
||||
std: 23
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- name: cmake
|
||||
run: >
|
||||
CXX=${{ matrix.cxx }} cmake -G "Unix Makefiles"
|
||||
-DCMAKE_BUILD_TYPE=Release -DFLATBUFFERS_STRICT_MODE=ON
|
||||
-DFLATBUFFERS_CPP_STD=${{ matrix.std }}
|
||||
-DFLATBUFFERS_BUILD_CPP17=${{ matrix.std >= 17 && 'On' || 'Off'}}
|
||||
- name: build
|
||||
run: make -j
|
||||
- name: test
|
||||
run: ./flattests
|
||||
- name: test C++17
|
||||
if: matrix.std >= 17
|
||||
run: ./flattests_cpp17
|
||||
|
||||
build-windows-cpp-std:
|
||||
name: Build Windows C++
|
||||
runs-on: windows-2019
|
||||
strategy:
|
||||
matrix:
|
||||
std: [11, 14, 17, 20, 23]
|
||||
fail-fast: false
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- 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_STRICT_MODE=ON
|
||||
-DFLATBUFFERS_CPP_STD=${{ matrix.std }}
|
||||
-DFLATBUFFERS_BUILD_CPP17=${{ matrix.std >= 17 && 'On' || 'Off'}}
|
||||
- name: build
|
||||
run: msbuild.exe FlatBuffers.sln /p:Configuration=Release /p:Platform=x64
|
||||
- name: test
|
||||
run: Release\flattests.exe
|
||||
- name: test C++17
|
||||
if: matrix.std >= 17
|
||||
run: Release\flattests_cpp17.exe
|
||||
|
||||
build-windows:
|
||||
permissions:
|
||||
contents: write
|
||||
@@ -305,8 +358,8 @@ jobs:
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- name: test
|
||||
working-directory: tests
|
||||
run: bash JavaTest.sh
|
||||
working-directory: java
|
||||
run: mvn test
|
||||
|
||||
build-kotlin-macos:
|
||||
name: Build Kotlin MacOS
|
||||
@@ -377,7 +430,7 @@ jobs:
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- name: test
|
||||
working-directory: tests/FlatBuffers.Test.Swift
|
||||
working-directory: tests/swift/tests
|
||||
run: sh SwiftTest.sh
|
||||
|
||||
build-swift-wasm:
|
||||
@@ -390,7 +443,7 @@ jobs:
|
||||
- name: Setup Wasmer
|
||||
uses: wasmerio/setup-wasmer@v1
|
||||
- name: Test
|
||||
working-directory: tests/FlatBuffers.Test.Swift.Wasm
|
||||
working-directory: tests/swift/Wasm.tests
|
||||
run: carton test
|
||||
|
||||
build-ts:
|
||||
@@ -401,10 +454,12 @@ jobs:
|
||||
- name: flatc
|
||||
# FIXME: make test script not rely on flatc
|
||||
run: cmake -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=Release -DFLATBUFFERS_BUILD_TESTS=OFF -DFLATBUFFERS_INSTALL=OFF -DFLATBUFFERS_BUILD_FLATLIB=OFF -DFLATBUFFERS_BUILD_FLATHASH=OFF . && make -j
|
||||
- name: deps
|
||||
run: yarn
|
||||
- name: compile
|
||||
run: npm run compile
|
||||
run: yarn compile
|
||||
- name: test
|
||||
working-directory: tests
|
||||
working-directory: tests/ts
|
||||
run: python3 TypeScriptTest.py
|
||||
|
||||
build-dart:
|
||||
|
||||
2
.github/workflows/scorecards.yml
vendored
2
.github/workflows/scorecards.yml
vendored
@@ -27,7 +27,7 @@ jobs:
|
||||
persist-credentials: false
|
||||
|
||||
- name: "Run analysis"
|
||||
uses: ossf/scorecard-action@c1aec4ac820532bab364f02a81873c555a0ba3a1 # v1.0.4
|
||||
uses: ossf/scorecard-action@ce330fde6b1a5c9c75b417e7efc510b822a35564 # v1.1.2
|
||||
with:
|
||||
results_file: results.sarif
|
||||
results_format: sarif
|
||||
|
||||
5
.gitignore
vendored
5
.gitignore
vendored
@@ -78,7 +78,7 @@ tests/php/
|
||||
CMakeLists.txt.user
|
||||
CMakeScripts/**
|
||||
CTestTestfile.cmake
|
||||
FlatBuffersConfigVersion.cmake
|
||||
flatbuffers-config-version.cmake
|
||||
FlatBuffers.cbp
|
||||
build/Xcode/FlatBuffers.xcodeproj/project.xcworkspace/**
|
||||
build/Xcode/FlatBuffers.xcodeproj/xcuserdata/**
|
||||
@@ -88,6 +88,7 @@ java/*.iml
|
||||
.idea
|
||||
*.iml
|
||||
target
|
||||
java/target
|
||||
**/*.pyc
|
||||
build/VS2010/FlatBuffers.sdf
|
||||
build/VS2010/FlatBuffers.opensdf
|
||||
@@ -148,4 +149,4 @@ flatbuffers.pc
|
||||
**/html/**
|
||||
**/latex/**
|
||||
# https://cmake.org/cmake/help/latest/module/FetchContent.html#variable:FETCHCONTENT_BASE_DIR
|
||||
_deps/
|
||||
_deps/
|
||||
|
||||
215
.travis.yml
215
.travis.yml
@@ -1,215 +0,0 @@
|
||||
env:
|
||||
global:
|
||||
# Set at the root level as this is ignored when set under matrix.env.
|
||||
- GCC_VERSION="4.9"
|
||||
# Fail on first error if UBSAN or ASAN enabled for a target
|
||||
- UBSAN_OPTIONS=halt_on_error=1
|
||||
- ASAN_OPTIONS=halt_on_error=1
|
||||
# Travis machines have 2 cores
|
||||
- JOBS=2
|
||||
- MAKEFLAGS="-j 2"
|
||||
|
||||
conan-linux: &conan-linux
|
||||
os: linux
|
||||
dist: xenial
|
||||
language: python
|
||||
python: "3.7"
|
||||
services:
|
||||
- docker
|
||||
install:
|
||||
- ./conan/travis/install.sh
|
||||
script:
|
||||
- ./conan/travis/build.sh
|
||||
if: tag IS present
|
||||
|
||||
conan-linux-master: &conan-linux-master
|
||||
os: linux
|
||||
dist: xenial
|
||||
language: python
|
||||
python: "3.7"
|
||||
services:
|
||||
- docker
|
||||
install:
|
||||
- 'if [ "$TRAVIS_PULL_REQUEST" = "false" ]; then bash ./conan/travis/install.sh; fi'
|
||||
script:
|
||||
- 'if [ "$TRAVIS_PULL_REQUEST" = "false" ]; then bash ./conan/travis/build.sh; fi'
|
||||
branches:
|
||||
only:
|
||||
- master
|
||||
|
||||
conan-osx: &conan-osx
|
||||
os: osx
|
||||
language: generic
|
||||
install:
|
||||
- ./conan/travis/install.sh
|
||||
script:
|
||||
- ./conan/travis/build.sh
|
||||
if: tag IS present
|
||||
|
||||
matrix:
|
||||
include:
|
||||
#- language: python
|
||||
# python: "2.7"
|
||||
# install:
|
||||
# - "pip install wheel twine"
|
||||
# script:
|
||||
# - "cd python/"
|
||||
# - 'VERSION="$TRAVIS_TAG" python setup.py sdist bdist_wheel'
|
||||
# - "cd ../"
|
||||
# deploy:
|
||||
# # Checkpointed release builds.
|
||||
# - provider: script
|
||||
# script: .travis/deploy-python.sh
|
||||
# skip_cleanup: true
|
||||
# on:
|
||||
# tags: true
|
||||
# # all_branches must be set with tags: true. See below post:
|
||||
# # https://stackoverflow.com/a/27775257/1076585
|
||||
# all_branches: true
|
||||
# # Produce a new build for the cutting edge when master changes.
|
||||
# - provider: script
|
||||
# script: .travis/deploy-python.sh
|
||||
# skip_cleanup: true
|
||||
# on:
|
||||
# branch: master
|
||||
- language: cpp
|
||||
os:
|
||||
- linux
|
||||
|
||||
addons:
|
||||
apt:
|
||||
packages:
|
||||
- docker-ce
|
||||
script:
|
||||
- bash .travis/build-and-run-docker-test-containers.sh
|
||||
|
||||
- language: cpp
|
||||
os:
|
||||
- linux
|
||||
|
||||
compiler:
|
||||
- gcc
|
||||
|
||||
env:
|
||||
matrix:
|
||||
- BUILD_TYPE=Debug
|
||||
- BUILD_TYPE=Release
|
||||
|
||||
before_install:
|
||||
- if [ "$TRAVIS_OS_NAME" == "linux" ]; then sudo add-apt-repository -y ppa:ubuntu-toolchain-r/test; fi
|
||||
- if [ "$TRAVIS_OS_NAME" == "linux" ]; then sudo apt-get update -qq; fi
|
||||
- if [ "$TRAVIS_OS_NAME" == "linux" ]; then sudo apt-get install -qq g++-$GCC_VERSION; fi
|
||||
- if [ "$TRAVIS_OS_NAME" == "linux" ]; then sudo apt-get install -qq gcc-$GCC_VERSION; fi
|
||||
- if [ "$TRAVIS_OS_NAME" == "linux" ]; then sudo ln -s -v -f $(which g++-$GCC_VERSION) /usr/bin/g++; fi
|
||||
- if [ "$TRAVIS_OS_NAME" == "linux" ]; then sudo ln -s -v -f $(which gcc-$GCC_VERSION) /usr/bin/gcc; fi
|
||||
|
||||
script:
|
||||
- pip install cmake
|
||||
- bash .travis/check-sources.sh
|
||||
- bash grpc/build_grpc.sh
|
||||
- cmake .
|
||||
-DCMAKE_BUILD_TYPE=$BUILD_TYPE
|
||||
-DFLATBUFFERS_BUILD_GRPCTEST=ON
|
||||
-DGRPC_INSTALL_PATH=$TRAVIS_BUILD_DIR/google/grpc/install
|
||||
-DPROTOBUF_DOWNLOAD_PATH=$TRAVIS_BUILD_DIR/google/grpc/third_party/protobuf
|
||||
-DFLATBUFFERS_CODE_SANITIZE=ON
|
||||
- cmake --build . --target all --clean-first -- -j${JOBS}
|
||||
- LD_LIBRARY_PATH=$TRAVIS_BUILD_DIR/google/grpc/install/lib ctest --extra-verbose --output-on-failure
|
||||
|
||||
- language: cpp
|
||||
os: osx
|
||||
osx_image: xcode9.3
|
||||
env:
|
||||
matrix:
|
||||
- BUILD_TYPE=Debug
|
||||
- BUILD_TYPE=Release
|
||||
|
||||
script:
|
||||
- pip install --user cmake
|
||||
- mkdir ~/cmake_path
|
||||
- ln -s $(find ~/Library/Python -name cmake -type f | head -n 1) ~/cmake_path/cmake
|
||||
- ln -s $(find ~/Library/Python -name ctest -type f | head -n 1) ~/cmake_path/ctest
|
||||
- export PATH=~/cmake_path:${PATH}
|
||||
- bash grpc/build_grpc.sh
|
||||
- cmake .
|
||||
-DCMAKE_BUILD_TYPE=$BUILD_TYPE
|
||||
-DFLATBUFFERS_BUILD_GRPCTEST=ON
|
||||
-DGRPC_INSTALL_PATH=$TRAVIS_BUILD_DIR/google/grpc/install
|
||||
-DPROTOBUF_DOWNLOAD_PATH=$TRAVIS_BUILD_DIR/google/grpc/third_party/protobuf
|
||||
-DFLATBUFFERS_CODE_SANITIZE=ON
|
||||
- cmake --build . -- -j${JOBS}
|
||||
- DYLD_LIBRARY_PATH=$TRAVIS_BUILD_DIR/google/grpc/install/lib ctest --extra-verbose --output-on-failure
|
||||
|
||||
- <<: *conan-linux-master
|
||||
env: CONAN_GCC_VERSIONS=8 CONAN_DOCKER_IMAGE=conanio/gcc8
|
||||
- <<: *conan-linux
|
||||
env: CONAN_GCC_VERSIONS=4.9 CONAN_DOCKER_IMAGE=conanio/gcc49
|
||||
- <<: *conan-linux
|
||||
env: CONAN_GCC_VERSIONS=5 CONAN_DOCKER_IMAGE=conanio/gcc5
|
||||
- <<: *conan-linux
|
||||
env: CONAN_GCC_VERSIONS=6 CONAN_DOCKER_IMAGE=conanio/gcc6
|
||||
- <<: *conan-linux
|
||||
env: CONAN_GCC_VERSIONS=7 CONAN_DOCKER_IMAGE=conanio/gcc7
|
||||
- <<: *conan-linux
|
||||
env: CONAN_GCC_VERSIONS=8 CONAN_DOCKER_IMAGE=conanio/gcc8
|
||||
- <<: *conan-linux
|
||||
env: CONAN_GCC_VERSIONS=9 CONAN_DOCKER_IMAGE=conanio/gcc9
|
||||
- <<: *conan-linux
|
||||
env: CONAN_CLANG_VERSIONS=3.9 CONAN_DOCKER_IMAGE=conanio/clang39
|
||||
- <<: *conan-linux
|
||||
env: CONAN_CLANG_VERSIONS=4.0 CONAN_DOCKER_IMAGE=conanio/clang40
|
||||
- <<: *conan-linux
|
||||
env: CONAN_CLANG_VERSIONS=5.0 CONAN_DOCKER_IMAGE=conanio/clang50
|
||||
- <<: *conan-linux
|
||||
env: CONAN_CLANG_VERSIONS=6.0 CONAN_DOCKER_IMAGE=conanio/clang60
|
||||
- <<: *conan-linux
|
||||
env: CONAN_CLANG_VERSIONS=7.0 CONAN_DOCKER_IMAGE=conanio/clang7
|
||||
- <<: *conan-linux
|
||||
env: CONAN_CLANG_VERSIONS=8 CONAN_DOCKER_IMAGE=conanio/clang8
|
||||
- <<: *conan-osx
|
||||
osx_image: xcode7.3
|
||||
env: CONAN_APPLE_CLANG_VERSIONS=7.3
|
||||
- <<: *conan-osx
|
||||
osx_image: xcode8.3
|
||||
env: CONAN_APPLE_CLANG_VERSIONS=8.1
|
||||
- <<: *conan-osx
|
||||
osx_image: xcode9
|
||||
env: CONAN_APPLE_CLANG_VERSIONS=9.0
|
||||
- <<: *conan-osx
|
||||
osx_image: xcode9.4
|
||||
env: CONAN_APPLE_CLANG_VERSIONS=9.1
|
||||
- <<: *conan-osx
|
||||
osx_image: xcode10.2
|
||||
env: CONAN_APPLE_CLANG_VERSIONS=10.0
|
||||
|
||||
- language: android
|
||||
sudo: true
|
||||
dist: trusty
|
||||
android:
|
||||
components:
|
||||
- tools
|
||||
- platform-tools
|
||||
- extra-android-m2repository
|
||||
licenses:
|
||||
- 'android-sdk-preview-license-52d11cd2'
|
||||
- 'android-sdk-license-.+'
|
||||
- 'google-gdk-license-.+'
|
||||
compiler:
|
||||
- gcc
|
||||
before_install:
|
||||
- echo y | sdkmanager "platforms;android-30"
|
||||
- echo y | sdkmanager "build-tools;30.0.2"
|
||||
- echo y | sdkmanager "ndk-bundle"
|
||||
- echo y | sdkmanager "cmake;3.6.4111459"
|
||||
script:
|
||||
- cmake -DFLATBUFFERS_BUILD_TESTS=OFF -DFLATBUFFERS_BUILD_FLATLIB=OFF -DFLATBUFFERS_BUILD_FLATHASH=OFF .; make; export PATH="$PATH:${PWD}"
|
||||
- cd android; ./gradlew clean build
|
||||
|
||||
- language: generic
|
||||
if: type IN (pull_request)
|
||||
os: linux
|
||||
install:
|
||||
- bash .travis/format_install.sh
|
||||
|
||||
script:
|
||||
- bash .travis/format_check.sh
|
||||
52
CHANGELOG.md
52
CHANGELOG.md
@@ -4,19 +4,55 @@ All major or breaking changes will be documented in this file, as well as any
|
||||
new features that should be highlighted. Minor fixes or improvements are not
|
||||
necessarily listed.
|
||||
|
||||
## 22.9.24 (Sept 24 2022)
|
||||
|
||||
* 20 Major releases in a row? Nope, we switched to a new
|
||||
[versioning scheme](https://github.com/google/flatbuffers/wiki/Versioning)
|
||||
that is based on date.
|
||||
|
||||
* Python supports fixed size arrays now (#7529).
|
||||
|
||||
* Behavior change in how C++ object API uses `UnPackTo`. The original intent of
|
||||
this was to reduce allocations by reusing an existing object to pack data
|
||||
into. At some point, this logic started to merge the states of the two objects
|
||||
instead of clearing the state of the packee. This change goes back to the
|
||||
original intention, the packed object is cleared when getting data packed into
|
||||
it (#7527).
|
||||
|
||||
* Fixed a bug in C++ alignment that was using `sizeof()` instead of the intended
|
||||
`AlignOf()` for structs (#7520).
|
||||
|
||||
* C# has an
|
||||
[offical Nuget package](https://www.nuget.org/packages/Google.FlatBuffers) now
|
||||
(#7496).
|
||||
|
||||
## 2.0.8 (Aug 29 2022)
|
||||
|
||||
* Fix for `--keep-prefix` the was generating the wrong include statements for
|
||||
C++ (#7469). The bug was introduced in 2.0.7.
|
||||
|
||||
* Added the `Verifier::Options` option struct to allow specifying runtime
|
||||
configuration settings for the verifier (#7489). This allows to skip verifying
|
||||
nested flatbuffers, a on-by-default change that was introduced in 2.0.7. This
|
||||
deprecates the existing `Verifier` constructor, which may be removed in a
|
||||
future version.
|
||||
|
||||
* Refactor of `tests/test.cpp` that lead to ~10% speedup in compilation of the
|
||||
entire project (#7487).
|
||||
|
||||
## 2.0.7 (Aug 22 2022)
|
||||
|
||||
* This is the first version with an explicit change log, so all the previous
|
||||
features will not be listed.
|
||||
features will not be listed.
|
||||
|
||||
* Verifier now checks that buffers are at least the minimum size required to be
|
||||
a flatbuffers (12 bytes). This includes nested flatbuffers, which previously
|
||||
could be declared valid at size 0.
|
||||
a flatbuffers (12 bytes). This includes nested flatbuffers, which previously
|
||||
could be declared valid at size 0.
|
||||
|
||||
* Annotated binaries. Given a flatbuffer binary and a schema (or binary schema)
|
||||
one can generate an annotated flatbuffer (.afb) to describe each byte in the
|
||||
binary with schema metadata and value.
|
||||
one can generate an annotated flatbuffer (.afb) to describe each byte in the
|
||||
binary with schema metadata and value.
|
||||
|
||||
* First binary schema generator (Lua) to generate Lua code via a .bfbs file.
|
||||
This is mostly an implementation detail of flatc internals, but will be slowly
|
||||
applied to the other language generators.
|
||||
* First binary schema generator (Lua) to generate Lua code via a .bfbs file.
|
||||
This is mostly an implementation detail of flatc internals, but will be slowly
|
||||
applied to the other language generators.
|
||||
@@ -654,9 +654,9 @@ if(FLATBUFFERS_INSTALL)
|
||||
|
||||
set(FB_CMAKE_DIR "${CMAKE_INSTALL_LIBDIR}/cmake/flatbuffers")
|
||||
|
||||
configure_file(CMake/FlatBuffersConfigVersion.cmake.in FlatBuffersConfigVersion.cmake @ONLY)
|
||||
configure_file(CMake/flatbuffers-config-version.cmake.in flatbuffers-config-version.cmake @ONLY)
|
||||
install(
|
||||
FILES "CMake/FlatBuffersConfig.cmake" "${CMAKE_CURRENT_BINARY_DIR}/FlatBuffersConfigVersion.cmake"
|
||||
FILES "CMake/flatbuffers-config.cmake" "${CMAKE_CURRENT_BINARY_DIR}/flatbuffers-config-version.cmake"
|
||||
DESTINATION ${FB_CMAKE_DIR}
|
||||
)
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
set(VERSION_MAJOR 2)
|
||||
set(VERSION_MINOR 0)
|
||||
set(VERSION_PATCH 7)
|
||||
set(VERSION_MAJOR 22)
|
||||
set(VERSION_MINOR 9)
|
||||
set(VERSION_PATCH 24)
|
||||
set(VERSION_COMMIT 0)
|
||||
|
||||
find_program(GIT git)
|
||||
@@ -14,10 +14,19 @@ if(GIT AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/.git")
|
||||
)
|
||||
|
||||
if(GIT_DESCRIBE_RESULT EQUAL 0)
|
||||
string(REGEX REPLACE "^v([0-9]+)\\..*" "\\1" VERSION_MAJOR "${GIT_DESCRIBE_DIRTY}")
|
||||
string(REGEX REPLACE "^v[0-9]+\\.([0-9]+).*" "\\1" VERSION_MINOR "${GIT_DESCRIBE_DIRTY}")
|
||||
string(REGEX REPLACE "^v[0-9]+\\.[0-9]+\\.([0-9]+).*" "\\1" VERSION_PATCH "${GIT_DESCRIBE_DIRTY}")
|
||||
string(REGEX REPLACE "^v[0-9]+\\.[0-9]+\\.[0-9]+\\-([0-9]+).*" "\\1" VERSION_COMMIT "${GIT_DESCRIBE_DIRTY}")
|
||||
# Test if the most recent Git tag matches the pattern "v<major>.<minor>.<patch>*"
|
||||
if(GIT_DESCRIBE_DIRTY MATCHES "^v[0-9]+\\.[0-9]+\\.[0-9]+.*")
|
||||
string(REGEX REPLACE "^v([0-9]+)\\..*" "\\1" VERSION_MAJOR "${GIT_DESCRIBE_DIRTY}")
|
||||
string(REGEX REPLACE "^v[0-9]+\\.([0-9]+).*" "\\1" VERSION_MINOR "${GIT_DESCRIBE_DIRTY}")
|
||||
string(REGEX REPLACE "^v[0-9]+\\.[0-9]+\\.([0-9]+).*" "\\1" VERSION_PATCH "${GIT_DESCRIBE_DIRTY}")
|
||||
string(REGEX REPLACE "^v[0-9]+\\.[0-9]+\\.[0-9]+\\-([0-9]+).*" "\\1" VERSION_COMMIT "${GIT_DESCRIBE_DIRTY}")
|
||||
# If the tag points to the commit, then only the tag is shown in "git describe"
|
||||
if(VERSION_COMMIT STREQUAL GIT_DESCRIBE_DIRTY)
|
||||
set(VERSION_COMMIT 0)
|
||||
endif()
|
||||
else()
|
||||
message(WARNING "\"${GIT_DESCRIBE_DIRTY}\" does not match pattern v<major>.<minor>.<patch>-<commit>")
|
||||
endif()
|
||||
else()
|
||||
message(WARNING "git describe failed with exit code: ${GIT_DESCRIBE_RESULT}")
|
||||
endif()
|
||||
|
||||
@@ -78,11 +78,23 @@ option(FLATBUFFERS_STRICT_MODE
|
||||
"Build flatbuffers with all warnings as errors (-Werror or /WX)."
|
||||
OFF)
|
||||
|
||||
if(NOT DEFINED FLATBUFFERS_CPP_STD)
|
||||
set(FLATBUFFERS_CPP_STD 11)
|
||||
endif()
|
||||
|
||||
set(MSVC_LIKE OFF)
|
||||
if(MSVC OR CMAKE_CXX_COMPILER_FRONTEND_VARIANT STREQUAL "MSVC")
|
||||
set(MSVC_LIKE ON)
|
||||
endif()
|
||||
|
||||
if(DEFINED FLATBUFFERS_COMPILATION_TIMINGS)
|
||||
message("Recording Compilation Timings to ${FLATBUFFERS_COMPILATION_TIMINGS}")
|
||||
file(REMOVE ${FLATBUFFERS_COMPILATION_TIMINGS})
|
||||
set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE "time -f 'Wall: %E User: %U Sys: %S | %C' -q -a -o ${FLATBUFFERS_COMPILATION_TIMINGS}")
|
||||
set_property(GLOBAL PROPERTY RULE_LAUNCH_CUSTOM "time -f 'Wall: %E User: %U Sys: %S | %C' -q -a -o ${FLATBUFFERS_COMPILATION_TIMINGS}")
|
||||
set_property(GLOBAL PROPERTY RULE_LAUNCH_LINK "time -f 'Wall: %E User: %U Sys: %S | %C' -q -a -o ${FLATBUFFERS_COMPILATION_TIMINGS}")
|
||||
endif()
|
||||
|
||||
if(NOT FLATBUFFERS_BUILD_FLATC AND FLATBUFFERS_BUILD_TESTS)
|
||||
message(WARNING
|
||||
"Cannot build tests without building the compiler. Tests will be disabled.")
|
||||
@@ -201,13 +213,25 @@ set(FlatHash_SRCS
|
||||
set(FlatBuffers_Tests_SRCS
|
||||
${FlatBuffers_Library_SRCS}
|
||||
src/idl_gen_fbs.cpp
|
||||
tests/evolution_test.cpp
|
||||
tests/flexbuffers_test.cpp
|
||||
tests/fuzz_test.cpp
|
||||
tests/json_test.cpp
|
||||
tests/monster_test.cpp
|
||||
tests/optional_scalars_test.cpp
|
||||
tests/parser_test.cpp
|
||||
tests/proto_test.cpp
|
||||
tests/reflection_test.cpp
|
||||
tests/test.cpp
|
||||
tests/test_assert.h
|
||||
tests/test_assert.cpp
|
||||
tests/test_builder.h
|
||||
tests/test_builder.cpp
|
||||
tests/util_test.cpp
|
||||
tests/native_type_test_impl.h
|
||||
tests/native_type_test_impl.cpp
|
||||
tests/alignment_test.h
|
||||
tests/alignment_test.cpp
|
||||
include/flatbuffers/code_generators.h
|
||||
src/code_generators.cpp
|
||||
# file generate by running compiler on tests/monster_test.fbs
|
||||
@@ -227,6 +251,10 @@ set(FlatBuffers_Tests_SRCS
|
||||
${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
|
||||
)
|
||||
|
||||
set(FlatBuffers_Tests_CPP17_SRCS
|
||||
@@ -334,7 +362,7 @@ include_directories(grpc)
|
||||
add_library(ProjectConfig INTERFACE)
|
||||
target_compile_features(ProjectConfig
|
||||
INTERFACE
|
||||
cxx_std_11
|
||||
cxx_std_${FLATBUFFERS_CPP_STD}
|
||||
)
|
||||
|
||||
# Force the standard to be met.
|
||||
@@ -358,26 +386,35 @@ if(MSVC_LIKE)
|
||||
>
|
||||
)
|
||||
else()
|
||||
if("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
|
||||
set(IS_CLANG ON)
|
||||
else()
|
||||
set(IS_CLANG OFF)
|
||||
endif()
|
||||
target_compile_options(ProjectConfig
|
||||
INTERFACE
|
||||
-Wall
|
||||
-Wno-unknown-warning-option
|
||||
$<$<BOOL:${FLATBUFFERS_STRICT_MODE}>:
|
||||
-Werror # Treat all compiler warnings as errors
|
||||
|
||||
# False positive string overflow
|
||||
# https://github.com/google/flatbuffers/issues/7366
|
||||
-Wno-error=stringop-overflow
|
||||
-fno-rtti # Disable runtime type information
|
||||
|
||||
$<$<CXX_COMPILER_ID:GNU>:
|
||||
# False positive string overflow
|
||||
# https://github.com/google/flatbuffers/issues/7366
|
||||
-Wno-error=stringop-overflow
|
||||
>
|
||||
>
|
||||
-pedantic
|
||||
-Wextra
|
||||
-Wno-unused-parameter
|
||||
-Wold-style-cast
|
||||
-Wimplicit-fallthrough
|
||||
-fsigned-char
|
||||
-Wnon-virtual-dtor
|
||||
|
||||
$<$<CXX_COMPILER_ID:CLANG>:
|
||||
# This isn't working for some reason: $<$<CXX_COMPILER_ID:CLANG>:
|
||||
$<$<BOOL:${IS_CLANG}>:
|
||||
-Wno-unknown-warning-option
|
||||
-Wmissing-declarations
|
||||
-Wzero-as-null-pointer-constant
|
||||
$<$<VERSION_GREATER:$<CXX_COMPILER_VERSION>,3.8>:
|
||||
@@ -589,6 +626,8 @@ if(FLATBUFFERS_BUILD_TESTS)
|
||||
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")
|
||||
if(NOT (MSVC AND (MSVC_VERSION LESS 1900)))
|
||||
compile_flatbuffers_schema_to_cpp(tests/monster_extra.fbs) # Test floating-point NAN/INF.
|
||||
endif()
|
||||
@@ -665,9 +704,12 @@ if(FLATBUFFERS_INSTALL)
|
||||
|
||||
set(FB_CMAKE_DIR "${CMAKE_INSTALL_LIBDIR}/cmake/flatbuffers")
|
||||
|
||||
configure_file(CMake/FlatBuffersConfigVersion.cmake.in FlatBuffersConfigVersion.cmake @ONLY)
|
||||
configure_file(CMake/flatbuffers-config-version.cmake.in flatbuffers-config-version.cmake @ONLY)
|
||||
install(
|
||||
FILES "CMake/FlatBuffersConfig.cmake" "${CMAKE_CURRENT_BINARY_DIR}/FlatBuffersConfigVersion.cmake"
|
||||
FILES
|
||||
"CMake/flatbuffers-config.cmake"
|
||||
"CMake/BuildFlatBuffers.cmake"
|
||||
"${CMAKE_CURRENT_BINARY_DIR}/flatbuffers-config-version.cmake"
|
||||
DESTINATION ${FB_CMAKE_DIR}
|
||||
)
|
||||
|
||||
|
||||
@@ -56,10 +56,13 @@ http_archive(
|
||||
)
|
||||
|
||||
##### GRPC
|
||||
_GRPC_VERSION = "1.48.0" # https://github.com/grpc/grpc/releases/tag/v1.48.0
|
||||
_GRPC_VERSION = "1.49.0" # https://github.com/grpc/grpc/releases/tag/v1.48.0
|
||||
|
||||
http_archive(
|
||||
name = "com_github_grpc_grpc",
|
||||
patch_args = ["-p1"],
|
||||
patches = ["//grpc:build_grpc_with_cxx14.patch"],
|
||||
sha256 = "15715e1847cc9e42014f02c727dbcb48e39dbdb90f79ad3d66fe4361709ff935",
|
||||
strip_prefix = "grpc-" + _GRPC_VERSION,
|
||||
urls = ["https://github.com/grpc/grpc/archive/refs/tags/v" + _GRPC_VERSION + ".tar.gz"],
|
||||
)
|
||||
|
||||
@@ -6,7 +6,8 @@
|
||||
<uses-feature android:glEsVersion="0x00020000"></uses-feature>
|
||||
|
||||
<!-- This .apk has no Java code itself, so set hasCode to false. -->
|
||||
<application android:label="@string/app_name"
|
||||
<application android:name="android.support.multidex.MultiDexApplication"
|
||||
android:label="@string/app_name"
|
||||
android:hasCode="false"
|
||||
android:allowBackup="false">
|
||||
<!-- Our activity is the built-in NativeActivity framework class.
|
||||
|
||||
@@ -8,7 +8,7 @@ android {
|
||||
|
||||
defaultConfig {
|
||||
applicationId "com.flatbuffers.app"
|
||||
minSdkVersion 16
|
||||
minSdkVersion 26
|
||||
targetSdkVersion 30
|
||||
versionCode 1
|
||||
versionName "1.0"
|
||||
@@ -18,6 +18,14 @@ android {
|
||||
targetCompatibility JavaVersion.VERSION_1_8
|
||||
}
|
||||
|
||||
sourceSets {
|
||||
main {
|
||||
java {
|
||||
srcDir '../../java/src/main/java/'
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ndk {
|
||||
abiFilters 'arm64-v8a', 'armeabi-v7a'
|
||||
}
|
||||
@@ -105,30 +113,6 @@ android {
|
||||
dependsOn(generateFbsCpp)
|
||||
}
|
||||
}
|
||||
|
||||
// flavorDimensions "stl-variant"
|
||||
// productFlavors {
|
||||
// gnustl {
|
||||
// dimension "stl-variant"
|
||||
// applicationIdSuffix ".gnustl"
|
||||
// versionNameSuffix "-gnustl"
|
||||
// externalNativeBuild {
|
||||
// ndkBuild {
|
||||
// arguments "APP_STL=gnustl_static"
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// libcpp {
|
||||
// dimension "stl-variant"
|
||||
// applicationIdSuffix ".libcpp"
|
||||
// versionNameSuffix "-libcpp"
|
||||
// externalNativeBuild {
|
||||
// ndkBuild {
|
||||
// arguments "APP_STL=c++_static"
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
||||
dependencies {
|
||||
@@ -136,6 +120,8 @@ dependencies {
|
||||
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
|
||||
implementation 'androidx.core:core-ktx:1.3.2'
|
||||
implementation 'androidx.appcompat:appcompat:1.2.0'
|
||||
implementation 'com.google.flatbuffers:flatbuffers-java:2.0.0'
|
||||
|
||||
// If you using java runtime you can add its dependency as the example below
|
||||
// implementation 'com.google.flatbuffers:flatbuffers-java:$latest_version'
|
||||
|
||||
}
|
||||
|
||||
@@ -6,6 +6,13 @@
|
||||
|
||||
#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 == 2 &&
|
||||
FLATBUFFERS_VERSION_MINOR == 0 &&
|
||||
FLATBUFFERS_VERSION_REVISION == 8,
|
||||
"Non-compatible flatbuffers version included");
|
||||
|
||||
namespace com {
|
||||
namespace fbs {
|
||||
namespace app {
|
||||
|
||||
@@ -36,7 +36,7 @@ class Animal : Table() {
|
||||
return if(o != 0) bb.getShort(o + bb_pos).toUShort() else 0u
|
||||
}
|
||||
companion object {
|
||||
fun validateVersion() = Constants.FLATBUFFERS_2_0_0()
|
||||
fun validateVersion() = Constants.FLATBUFFERS_22_9_24()
|
||||
fun getRootAsAnimal(_bb: ByteBuffer): Animal = getRootAsAnimal(_bb, Animal())
|
||||
fun getRootAsAnimal(_bb: ByteBuffer, obj: Animal): Animal {
|
||||
_bb.order(ByteOrder.LITTLE_ENDIAN)
|
||||
|
||||
@@ -1,8 +0,0 @@
|
||||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
import os
|
||||
|
||||
if os.getenv("APPVEYOR_REPO_TAG") != "true":
|
||||
print("Skip build step. It's not TAG")
|
||||
else:
|
||||
os.system("python conan/build.py")
|
||||
@@ -1,8 +0,0 @@
|
||||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
import os
|
||||
|
||||
if os.getenv("APPVEYOR_REPO_TAG") != "true":
|
||||
print("Skip step. It's not TAG")
|
||||
else:
|
||||
os.system("pip install conan conan-package-tools")
|
||||
@@ -21,14 +21,6 @@ def get_branch():
|
||||
|
||||
def get_version():
|
||||
version = get_branch()
|
||||
if os.getenv("TRAVIS", False):
|
||||
version = os.getenv("TRAVIS_BRANCH")
|
||||
|
||||
if os.getenv("APPVEYOR", False):
|
||||
version = os.getenv("APPVEYOR_REPO_BRANCH")
|
||||
if os.getenv("APPVEYOR_REPO_TAG") == "true":
|
||||
version = os.getenv("APPVEYOR_REPO_TAG_NAME")
|
||||
|
||||
match = re.search(r"v(\d+\.\d+\.\d+.*)", version)
|
||||
if match:
|
||||
return match.group(1)
|
||||
|
||||
@@ -1,14 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
set -e
|
||||
set -x
|
||||
|
||||
if [[ "$(uname -s)" == 'Darwin' ]]; then
|
||||
if which pyenv > /dev/null; then
|
||||
eval "$(pyenv init -)"
|
||||
fi
|
||||
pyenv activate conan
|
||||
fi
|
||||
|
||||
conan user
|
||||
python conan/build.py
|
||||
@@ -1,22 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
set -e
|
||||
set -x
|
||||
|
||||
if [[ "$(uname -s)" == 'Darwin' ]]; then
|
||||
brew update || brew update
|
||||
brew outdated pyenv || brew upgrade pyenv
|
||||
brew install pyenv-virtualenv
|
||||
brew install cmake || true
|
||||
|
||||
if which pyenv > /dev/null; then
|
||||
eval "$(pyenv init -)"
|
||||
fi
|
||||
|
||||
pyenv install 2.7.10
|
||||
pyenv virtualenv 2.7.10 conan
|
||||
pyenv rehash
|
||||
pyenv activate conan
|
||||
fi
|
||||
|
||||
pip install -U conan_package_tools conan
|
||||
@@ -17,7 +17,7 @@ class Builder {
|
||||
final Map<double, _StackValue> _indirectDoubleCache = {};
|
||||
|
||||
/// Instantiate the builder if you intent to gradually build up the buffer by calling
|
||||
/// add... methods and calling [finish] to receive the the resulting byte array.
|
||||
/// add... methods and calling [finish] to receive the resulting byte array.
|
||||
///
|
||||
/// The default size of internal buffer is set to 2048. Provide a different value in order to avoid buffer copies.
|
||||
Builder({int size = 2048}) : _buffer = ByteData(size);
|
||||
|
||||
@@ -199,7 +199,7 @@ class Reference {
|
||||
return _MapValueIterator(this);
|
||||
}
|
||||
|
||||
/// Returns the length of the the underlying FlexBuffer value.
|
||||
/// Returns the length of the underlying FlexBuffer value.
|
||||
/// If the underlying value is [null] the length is 0.
|
||||
/// If the underlying value is a number, or a bool, the length is 1.
|
||||
/// If the underlying value is a vector, or map, the length reflects number of elements / element pairs.
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
name: flat_buffers
|
||||
version: 2.0.5
|
||||
version: 22.9.24
|
||||
description: FlatBuffers reading and writing library for Dart. Based on original work by Konstantin Scheglov and Paul Berry of the Dart SDK team.
|
||||
homepage: https://github.com/google/flatbuffers
|
||||
documentation: https://google.github.io/flatbuffers/index.html
|
||||
|
||||
@@ -22,10 +22,10 @@ GitHub page](https://github.com/google/flatbuffers/tree/master/swift).
|
||||
|
||||
## Testing the FlatBuffers Swift library
|
||||
|
||||
The code to test the Swift library can be found at `flatbuffers/Flatbuffers.Test.Swift`.
|
||||
The test code itself is located in [Flatbuffers.Test.Swift](https://github.com/google/flatbuffers/blob/master/tests/FlatBuffers.Test.Swift).
|
||||
The code to test the Swift library can be found at `flatbuffers/tests/swift/tests`.
|
||||
The test code itself is located in [flatbuffers/tests/swift/tests](https://github.com/google/flatbuffers/blob/master/tests/swift/tests).
|
||||
|
||||
To run the tests, use the [SwiftTest.sh](https://github.com/google/flatbuffers/blob/master/tests/FlatBuffers.Test.Swift/SwiftTest.sh) shell script.
|
||||
To run the tests, use the [SwiftTest.sh](https://github.com/google/flatbuffers/blob/master/tests/swift/tests/SwiftTest.sh) shell script.
|
||||
|
||||
*Note: The shell script requires [Swift](https://swift.org) to
|
||||
be installed.*
|
||||
|
||||
10
grpc/build_grpc_with_cxx14.patch
Normal file
10
grpc/build_grpc_with_cxx14.patch
Normal file
@@ -0,0 +1,10 @@
|
||||
diff --git a/bazel/copts.bzl b/bazel/copts.bzl
|
||||
index 10be944f25..879518b92f 100644
|
||||
--- a/bazel/copts.bzl
|
||||
+++ b/bazel/copts.bzl
|
||||
@@ -59,4 +59,4 @@ GRPC_LLVM_WARNING_FLAGS = [
|
||||
GRPC_DEFAULT_COPTS = select({
|
||||
"//:use_strict_warning": GRPC_LLVM_WARNING_FLAGS + ["-DUSE_STRICT_WARNING=1"],
|
||||
"//conditions:default": [],
|
||||
-})
|
||||
+}) + ["-std=c++14"]
|
||||
@@ -6,7 +6,7 @@ import FlatBuffers
|
||||
|
||||
public struct models_HelloReply: FlatBufferObject, Verifiable {
|
||||
|
||||
static func validateVersion() { FlatBuffersVersion_2_0_0() }
|
||||
static func validateVersion() { FlatBuffersVersion_22_9_24() }
|
||||
public var __buffer: ByteBuffer! { return _accessor.bb }
|
||||
private var _accessor: Table
|
||||
|
||||
@@ -55,7 +55,7 @@ extension models_HelloReply: Encodable {
|
||||
|
||||
public struct models_HelloRequest: FlatBufferObject, Verifiable {
|
||||
|
||||
static func validateVersion() { FlatBuffersVersion_2_0_0() }
|
||||
static func validateVersion() { FlatBuffersVersion_22_9_24() }
|
||||
public var __buffer: ByteBuffer! { return _accessor.bb }
|
||||
private var _accessor: Table
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// automatically generated by the FlatBuffers compiler, do not modify
|
||||
|
||||
export { HelloReply } from './models/hello-reply';
|
||||
export { HelloRequest } from './models/hello-request';
|
||||
export { HelloReply } from './models/hello-reply.js';
|
||||
export { HelloRequest } from './models/hello-request.js';
|
||||
|
||||
@@ -138,9 +138,9 @@
|
||||
#endif
|
||||
#endif // !defined(FLATBUFFERS_LITTLEENDIAN)
|
||||
|
||||
#define FLATBUFFERS_VERSION_MAJOR 2
|
||||
#define FLATBUFFERS_VERSION_MINOR 0
|
||||
#define FLATBUFFERS_VERSION_REVISION 7
|
||||
#define FLATBUFFERS_VERSION_MAJOR 22
|
||||
#define FLATBUFFERS_VERSION_MINOR 9
|
||||
#define FLATBUFFERS_VERSION_REVISION 24
|
||||
#define FLATBUFFERS_STRING_EXPAND(X) #X
|
||||
#define FLATBUFFERS_STRING(X) FLATBUFFERS_STRING_EXPAND(X)
|
||||
namespace flatbuffers {
|
||||
@@ -273,14 +273,14 @@ namespace flatbuffers {
|
||||
#endif // !FLATBUFFERS_LOCALE_INDEPENDENT
|
||||
|
||||
// Suppress Undefined Behavior Sanitizer (recoverable only). Usage:
|
||||
// - __supress_ubsan__("undefined")
|
||||
// - __supress_ubsan__("signed-integer-overflow")
|
||||
// - __suppress_ubsan__("undefined")
|
||||
// - __suppress_ubsan__("signed-integer-overflow")
|
||||
#if defined(__clang__) && (__clang_major__ > 3 || (__clang_major__ == 3 && __clang_minor__ >=7))
|
||||
#define __supress_ubsan__(type) __attribute__((no_sanitize(type)))
|
||||
#define __suppress_ubsan__(type) __attribute__((no_sanitize(type)))
|
||||
#elif defined(__GNUC__) && (__GNUC__ * 100 + __GNUC_MINOR__ >= 409)
|
||||
#define __supress_ubsan__(type) __attribute__((no_sanitize_undefined))
|
||||
#define __suppress_ubsan__(type) __attribute__((no_sanitize_undefined))
|
||||
#else
|
||||
#define __supress_ubsan__(type)
|
||||
#define __suppress_ubsan__(type)
|
||||
#endif
|
||||
|
||||
// This is constexpr function used for checking compile-time constants.
|
||||
@@ -413,7 +413,7 @@ template<typename T> T EndianScalar(T t) {
|
||||
|
||||
template<typename T>
|
||||
// UBSAN: C++ aliasing type rules, see std::bit_cast<> for details.
|
||||
__supress_ubsan__("alignment")
|
||||
__suppress_ubsan__("alignment")
|
||||
T ReadScalar(const void *p) {
|
||||
return EndianScalar(*reinterpret_cast<const T *>(p));
|
||||
}
|
||||
@@ -427,13 +427,13 @@ T ReadScalar(const void *p) {
|
||||
|
||||
template<typename T>
|
||||
// UBSAN: C++ aliasing type rules, see std::bit_cast<> for details.
|
||||
__supress_ubsan__("alignment")
|
||||
__suppress_ubsan__("alignment")
|
||||
void WriteScalar(void *p, T t) {
|
||||
*reinterpret_cast<T *>(p) = EndianScalar(t);
|
||||
}
|
||||
|
||||
template<typename T> struct Offset;
|
||||
template<typename T> __supress_ubsan__("alignment") void WriteScalar(void *p, Offset<T> t) {
|
||||
template<typename T> __suppress_ubsan__("alignment") void WriteScalar(void *p, Offset<T> t) {
|
||||
*reinterpret_cast<uoffset_t *>(p) = EndianScalar(t.o);
|
||||
}
|
||||
|
||||
@@ -444,7 +444,7 @@ template<typename T> __supress_ubsan__("alignment") void WriteScalar(void *p, Of
|
||||
// Computes how many bytes you'd have to pad to be able to write an
|
||||
// "scalar_size" scalar if the buffer had grown to "buf_size" (downwards in
|
||||
// memory).
|
||||
__supress_ubsan__("unsigned-integer-overflow")
|
||||
__suppress_ubsan__("unsigned-integer-overflow")
|
||||
inline size_t PaddingBytes(size_t buf_size, size_t scalar_size) {
|
||||
return ((~buf_size) + 1) & (scalar_size - 1);
|
||||
}
|
||||
|
||||
@@ -95,7 +95,7 @@ template<typename T> struct IndirectHelper<const T *> {
|
||||
}
|
||||
};
|
||||
|
||||
/// @brief Get a pointer to the the file_identifier section of the buffer.
|
||||
/// @brief Get a pointer to the file_identifier section of the buffer.
|
||||
/// @return Returns a const char pointer to the start of the file_identifier
|
||||
/// characters in the buffer. The returned char * has length
|
||||
/// 'flatbuffers::FlatBufferBuilder::kFileIdentifierLength'.
|
||||
|
||||
@@ -358,7 +358,7 @@ class FlatBufferBuilder {
|
||||
// If you get this assert, a corresponding StartTable wasn't called.
|
||||
FLATBUFFERS_ASSERT(nested);
|
||||
// Write the vtable offset, which is the start of any Table.
|
||||
// We fill it's value later.
|
||||
// We fill its value later.
|
||||
auto vtableoffsetloc = PushElement<soffset_t>(0);
|
||||
// Write a vtable, which consists entirely of voffset_t elements.
|
||||
// It starts with the number of offsets, followed by a type id, followed
|
||||
@@ -449,7 +449,7 @@ class FlatBufferBuilder {
|
||||
}
|
||||
template<typename T> void PreAlign(size_t len) {
|
||||
AssertScalarT<T>();
|
||||
PreAlign(len, sizeof(T));
|
||||
PreAlign(len, AlignOf<T>());
|
||||
}
|
||||
/// @endcond
|
||||
|
||||
@@ -579,7 +579,7 @@ class FlatBufferBuilder {
|
||||
/// @param[in] str A const pointer to a `String` struct to add to the buffer.
|
||||
/// @return Returns the offset in the buffer where the string starts
|
||||
Offset<String> CreateSharedString(const String *str) {
|
||||
return CreateSharedString(str->c_str(), str->size());
|
||||
return str ? CreateSharedString(str->c_str(), str->size()) : 0;
|
||||
}
|
||||
|
||||
/// @cond FLATBUFFERS_INTERNAL
|
||||
@@ -589,11 +589,15 @@ class FlatBufferBuilder {
|
||||
return PushElement(static_cast<uoffset_t>(len));
|
||||
}
|
||||
|
||||
void StartVector(size_t len, size_t elemsize) {
|
||||
void StartVector(size_t len, size_t elemsize, size_t alignment) {
|
||||
NotNested();
|
||||
nested = true;
|
||||
PreAlign<uoffset_t>(len * elemsize);
|
||||
PreAlign(len * elemsize, elemsize); // Just in case elemsize > uoffset_t.
|
||||
PreAlign(len * elemsize, alignment); // Just in case elemsize > uoffset_t.
|
||||
}
|
||||
|
||||
template<typename T> void StartVector(size_t len) {
|
||||
return StartVector(len, sizeof(T), AlignOf<T>());
|
||||
}
|
||||
|
||||
// Call this right before StartVector/CreateVector if you want to force the
|
||||
@@ -627,7 +631,7 @@ class FlatBufferBuilder {
|
||||
// If this assert hits, you're specifying a template argument that is
|
||||
// causing the wrong overload to be selected, remove it.
|
||||
AssertScalarT<T>();
|
||||
StartVector(len, sizeof(T));
|
||||
StartVector<T>(len);
|
||||
if (len == 0) { return Offset<Vector<T>>(EndVector(len)); }
|
||||
// clang-format off
|
||||
#if FLATBUFFERS_LITTLEENDIAN
|
||||
@@ -668,7 +672,7 @@ class FlatBufferBuilder {
|
||||
|
||||
template<typename T>
|
||||
Offset<Vector<Offset<T>>> CreateVector(const Offset<T> *v, size_t len) {
|
||||
StartVector(len, sizeof(Offset<T>));
|
||||
StartVector<Offset<T>>(len);
|
||||
for (auto i = len; i > 0;) { PushElement(v[--i]); }
|
||||
return Offset<Vector<Offset<T>>>(EndVector(len));
|
||||
}
|
||||
@@ -688,7 +692,7 @@ class FlatBufferBuilder {
|
||||
// an array. Instead, read elements manually.
|
||||
// Background: https://isocpp.org/blog/2012/11/on-vectorbool
|
||||
Offset<Vector<uint8_t>> CreateVector(const std::vector<bool> &v) {
|
||||
StartVector(v.size(), sizeof(uint8_t));
|
||||
StartVector<uint8_t>(v.size());
|
||||
for (auto i = v.size(); i > 0;) {
|
||||
PushElement(static_cast<uint8_t>(v[--i]));
|
||||
}
|
||||
@@ -747,7 +751,7 @@ class FlatBufferBuilder {
|
||||
|
||||
/// @brief Serialize a collection of Strings into a FlatBuffer `vector`.
|
||||
/// This is a convenience function for a common case.
|
||||
/// @param begin The begining iterator of the collection
|
||||
/// @param begin The beginning iterator of the collection
|
||||
/// @param end The ending iterator of the collection
|
||||
/// @return Returns a typed `Offset` into the serialized data indicating
|
||||
/// where the vector is stored.
|
||||
@@ -757,12 +761,12 @@ class FlatBufferBuilder {
|
||||
auto scratch_buffer_usage = size * sizeof(Offset<String>);
|
||||
// If there is not enough space to store the offsets, there definitely won't
|
||||
// be enough space to store all the strings. So ensuring space for the
|
||||
// scratch region is OK, for it it fails, it would have failed later.
|
||||
// scratch region is OK, for if it fails, it would have failed later.
|
||||
buf_.ensure_space(scratch_buffer_usage);
|
||||
for (auto it = begin; it != end; ++it) {
|
||||
buf_.scratch_push_small(CreateString(*it));
|
||||
}
|
||||
StartVector(size, sizeof(Offset<String>));
|
||||
StartVector<Offset<String>>(size);
|
||||
for (auto i = 1; i <= size; i++) {
|
||||
// Note we re-evaluate the buf location each iteration to account for any
|
||||
// underlying buffer resizing that may occur.
|
||||
@@ -782,7 +786,7 @@ class FlatBufferBuilder {
|
||||
/// where the vector is stored.
|
||||
template<typename T>
|
||||
Offset<Vector<const T *>> CreateVectorOfStructs(const T *v, size_t len) {
|
||||
StartVector(len * sizeof(T) / AlignOf<T>(), AlignOf<T>());
|
||||
StartVector(len * sizeof(T) / AlignOf<T>(), sizeof(T), AlignOf<T>());
|
||||
if (len > 0) {
|
||||
PushBytes(reinterpret_cast<const uint8_t *>(v), sizeof(T) * len);
|
||||
}
|
||||
@@ -1025,9 +1029,9 @@ class FlatBufferBuilder {
|
||||
/// written to at a later time to serialize the data into a `vector`
|
||||
/// in the buffer.
|
||||
uoffset_t CreateUninitializedVector(size_t len, size_t elemsize,
|
||||
uint8_t **buf) {
|
||||
size_t alignment, uint8_t **buf) {
|
||||
NotNested();
|
||||
StartVector(len, elemsize);
|
||||
StartVector(len, elemsize, alignment);
|
||||
buf_.make_space(len * elemsize);
|
||||
auto vec_start = GetSize();
|
||||
auto vec_end = EndVector(len);
|
||||
@@ -1035,6 +1039,12 @@ class FlatBufferBuilder {
|
||||
return vec_end;
|
||||
}
|
||||
|
||||
FLATBUFFERS_ATTRIBUTE([[deprecated("call the version above instead")]])
|
||||
uoffset_t CreateUninitializedVector(size_t len, size_t elemsize,
|
||||
uint8_t **buf) {
|
||||
return CreateUninitializedVector(len, elemsize, elemsize, buf);
|
||||
}
|
||||
|
||||
/// @brief Specialized version of `CreateVector` for non-copying use cases.
|
||||
/// Write the data any time later to the returned buffer pointer `buf`.
|
||||
/// @tparam T The data type of the data that will be stored in the buffer
|
||||
@@ -1046,14 +1056,14 @@ class FlatBufferBuilder {
|
||||
template<typename T>
|
||||
Offset<Vector<T>> CreateUninitializedVector(size_t len, T **buf) {
|
||||
AssertScalarT<T>();
|
||||
return CreateUninitializedVector(len, sizeof(T),
|
||||
return CreateUninitializedVector(len, sizeof(T), AlignOf<T>(),
|
||||
reinterpret_cast<uint8_t **>(buf));
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
Offset<Vector<const T *>> CreateUninitializedVectorOfStructs(size_t len,
|
||||
T **buf) {
|
||||
return CreateUninitializedVector(len, sizeof(T),
|
||||
return CreateUninitializedVector(len, sizeof(T), AlignOf<T>(),
|
||||
reinterpret_cast<uint8_t **>(buf));
|
||||
}
|
||||
|
||||
@@ -1064,7 +1074,7 @@ class FlatBufferBuilder {
|
||||
Offset<Vector<T>> CreateVectorScalarCast(const U *v, size_t len) {
|
||||
AssertScalarT<T>();
|
||||
AssertScalarT<U>();
|
||||
StartVector(len, sizeof(T));
|
||||
StartVector<T>(len);
|
||||
for (auto i = len; i > 0;) { PushElement(static_cast<T>(v[--i])); }
|
||||
return Offset<Vector<T>>(EndVector(len));
|
||||
}
|
||||
@@ -1173,7 +1183,7 @@ class FlatBufferBuilder {
|
||||
// Allocates space for a vector of structures.
|
||||
// Must be completed with EndVectorOfStructs().
|
||||
template<typename T> T *StartVectorOfStructs(size_t vector_size) {
|
||||
StartVector(vector_size * sizeof(T) / AlignOf<T>(), AlignOf<T>());
|
||||
StartVector(vector_size * sizeof(T) / AlignOf<T>(), sizeof(T), AlignOf<T>());
|
||||
return reinterpret_cast<T *>(buf_.make_space(vector_size * sizeof(T)));
|
||||
}
|
||||
|
||||
|
||||
@@ -1871,7 +1871,7 @@ class Verifier FLATBUFFERS_FINAL_CLASS {
|
||||
std::vector<uint8_t> *reuse_tracker_;
|
||||
};
|
||||
|
||||
// Utility function that contructs the Verifier for you, see above for
|
||||
// Utility function that constructs the Verifier for you, see above for
|
||||
// parameters.
|
||||
inline bool VerifyBuffer(const uint8_t *buf, size_t buf_len,
|
||||
std::vector<uint8_t> *reuse_tracker = nullptr) {
|
||||
|
||||
@@ -464,6 +464,10 @@ inline bool IsStruct(const Type &type) {
|
||||
return type.base_type == BASE_TYPE_STRUCT && type.struct_def->fixed;
|
||||
}
|
||||
|
||||
inline bool IsTable(const Type &type) {
|
||||
return type.base_type == BASE_TYPE_STRUCT && !type.struct_def->fixed;
|
||||
}
|
||||
|
||||
inline bool IsUnion(const Type &type) {
|
||||
return type.enum_def != nullptr && type.enum_def->is_union;
|
||||
}
|
||||
@@ -476,6 +480,14 @@ inline bool IsVector(const Type &type) {
|
||||
return type.base_type == BASE_TYPE_VECTOR;
|
||||
}
|
||||
|
||||
inline bool IsVectorOfStruct(const Type& type) {
|
||||
return IsVector(type) && IsStruct(type.VectorType());
|
||||
}
|
||||
|
||||
inline bool IsVectorOfTable(const Type& type) {
|
||||
return IsVector(type) && IsTable(type.VectorType());
|
||||
}
|
||||
|
||||
inline bool IsArray(const Type &type) {
|
||||
return type.base_type == BASE_TYPE_ARRAY;
|
||||
}
|
||||
@@ -537,6 +549,24 @@ struct ServiceDef : public Definition {
|
||||
SymbolTable<RPCCall> calls;
|
||||
};
|
||||
|
||||
struct IncludedFile {
|
||||
// The name of the schema file being included, as defined in the .fbs file.
|
||||
// This includes the prefix (e.g., include "foo/bar/baz.fbs" would mean this
|
||||
// value is "foo/bar/baz.fbs").
|
||||
std::string schema_name;
|
||||
|
||||
// The filename of where the included file was found, after searching the
|
||||
// relative paths plus any other paths included with `flatc -I ...`. Note,
|
||||
// while this is sometimes the same as schema_name, it is not always, since it
|
||||
// can be defined relative to where flatc was invoked.
|
||||
std::string filename;
|
||||
};
|
||||
|
||||
// Since IncludedFile is contained within a std::set, need to provide ordering.
|
||||
inline bool operator<(const IncludedFile &a, const IncludedFile &b) {
|
||||
return a.filename < b.filename;
|
||||
}
|
||||
|
||||
// Container of options that may apply to any of the source/text generators.
|
||||
struct IDLOptions {
|
||||
// field case style options for C++
|
||||
@@ -914,7 +944,7 @@ class Parser : public ParserState {
|
||||
// Get the set of included files that are directly referenced by the file
|
||||
// being parsed. This does not include files that are transitively included by
|
||||
// others includes.
|
||||
std::vector<std::string> GetIncludedFiles() const;
|
||||
std::vector<IncludedFile> GetIncludedFiles() const;
|
||||
|
||||
private:
|
||||
class ParseDepthGuard;
|
||||
@@ -1043,7 +1073,7 @@ class Parser : public ParserState {
|
||||
std::string file_extension_;
|
||||
|
||||
std::map<uint64_t, std::string> included_files_;
|
||||
std::map<std::string, std::set<std::string>> files_included_per_file_;
|
||||
std::map<std::string, std::set<IncludedFile>> files_included_per_file_;
|
||||
std::vector<std::string> native_included_files_;
|
||||
|
||||
std::map<std::string, bool> known_attributes_;
|
||||
|
||||
@@ -8,9 +8,9 @@
|
||||
|
||||
// Ensure the included flatbuffers.h is the same version as when this file was
|
||||
// generated, otherwise it may not be compatible.
|
||||
static_assert(FLATBUFFERS_VERSION_MAJOR == 2 &&
|
||||
FLATBUFFERS_VERSION_MINOR == 0 &&
|
||||
FLATBUFFERS_VERSION_REVISION == 7,
|
||||
static_assert(FLATBUFFERS_VERSION_MAJOR == 22 &&
|
||||
FLATBUFFERS_VERSION_MINOR == 9 &&
|
||||
FLATBUFFERS_VERSION_REVISION == 24,
|
||||
"Non-compatible flatbuffers version included");
|
||||
|
||||
namespace reflection {
|
||||
|
||||
@@ -46,6 +46,7 @@
|
||||
#include <span>
|
||||
#elif defined(__cpp_lib_span) && defined(__has_include)
|
||||
#if __has_include(<span>)
|
||||
#include <array>
|
||||
#include <span>
|
||||
#define FLATBUFFERS_USE_STD_SPAN
|
||||
#endif
|
||||
@@ -292,7 +293,7 @@ namespace internal {
|
||||
// > to a pointer to an array of To.
|
||||
// This helper is used for checking of 'From -> const From'.
|
||||
template<class To, std::size_t Extent, class From, std::size_t N>
|
||||
struct is_span_convertable {
|
||||
struct is_span_convertible {
|
||||
using type =
|
||||
typename std::conditional<std::is_convertible<From (*)[], To (*)[]>::value
|
||||
&& (Extent == dynamic_extent || N == Extent),
|
||||
@@ -414,7 +415,7 @@ class span FLATBUFFERS_FINAL_CLASS {
|
||||
// extent == 0 || extent == flatbuffers::dynamic_extent.
|
||||
// A dummy template argument N is need dependency for SFINAE.
|
||||
template<std::size_t N = 0,
|
||||
typename internal::is_span_convertable<element_type, Extent, element_type, (N - N)>::type = 0>
|
||||
typename internal::is_span_convertible<element_type, Extent, element_type, (N - N)>::type = 0>
|
||||
FLATBUFFERS_CONSTEXPR_CPP11 span() FLATBUFFERS_NOEXCEPT : data_(nullptr),
|
||||
count_(0) {
|
||||
static_assert(extent == 0 || extent == dynamic_extent, "invalid span");
|
||||
@@ -427,12 +428,12 @@ class span FLATBUFFERS_FINAL_CLASS {
|
||||
// std::remove_pointer_t<decltype(std::data(arr))>(*)[]
|
||||
// is convertible to element_type (*)[].
|
||||
template<std::size_t N,
|
||||
typename internal::is_span_convertable<element_type, Extent, element_type, N>::type = 0>
|
||||
typename internal::is_span_convertible<element_type, Extent, element_type, N>::type = 0>
|
||||
FLATBUFFERS_CONSTEXPR_CPP11 span(element_type (&arr)[N]) FLATBUFFERS_NOEXCEPT
|
||||
: data_(arr), count_(N) {}
|
||||
|
||||
template<class U, std::size_t N,
|
||||
typename internal::is_span_convertable<element_type, Extent, U, N>::type = 0>
|
||||
typename internal::is_span_convertible<element_type, Extent, U, N>::type = 0>
|
||||
FLATBUFFERS_CONSTEXPR_CPP11 span(std::array<U, N> &arr) FLATBUFFERS_NOEXCEPT
|
||||
: data_(arr.data()), count_(N) {}
|
||||
|
||||
@@ -442,7 +443,7 @@ class span FLATBUFFERS_FINAL_CLASS {
|
||||
// : data_(arr.data()), count_(N) {}
|
||||
|
||||
template<class U, std::size_t N,
|
||||
typename internal::is_span_convertable<element_type, Extent, U, N>::type = 0>
|
||||
typename internal::is_span_convertible<element_type, Extent, U, N>::type = 0>
|
||||
FLATBUFFERS_CONSTEXPR_CPP11 span(const std::array<U, N> &arr) FLATBUFFERS_NOEXCEPT
|
||||
: data_(arr.data()), count_(N) {}
|
||||
|
||||
@@ -452,7 +453,7 @@ class span FLATBUFFERS_FINAL_CLASS {
|
||||
// if extent == std::dynamic_extent || N == extent is true and U (*)[]
|
||||
// is convertible to element_type (*)[].
|
||||
template<class U, std::size_t N,
|
||||
typename internal::is_span_convertable<element_type, Extent, U, N>::type = 0>
|
||||
typename internal::is_span_convertible<element_type, Extent, U, N>::type = 0>
|
||||
FLATBUFFERS_CONSTEXPR_CPP11 span(const flatbuffers::span<U, N> &s) FLATBUFFERS_NOEXCEPT
|
||||
: span(s.data(), s.size()) {
|
||||
}
|
||||
|
||||
@@ -255,7 +255,7 @@ inline void strtoval_impl(double *val, const char *str, char **endptr) {
|
||||
}
|
||||
|
||||
// UBSAN: double to float is safe if numeric_limits<float>::is_iec559 is true.
|
||||
__supress_ubsan__("float-cast-overflow")
|
||||
__suppress_ubsan__("float-cast-overflow")
|
||||
inline void strtoval_impl(float *val, const char *str, char **endptr) {
|
||||
*val = __strtof_impl(str, endptr);
|
||||
}
|
||||
@@ -685,9 +685,6 @@ bool SetGlobalTestLocale(const char *locale_name,
|
||||
bool ReadEnvironmentVariable(const char *var_name,
|
||||
std::string *_value = nullptr);
|
||||
|
||||
// MSVC specific: Send all assert reports to STDOUT to prevent CI hangs.
|
||||
void SetupDefaultCRTReportMode();
|
||||
|
||||
enum class Case {
|
||||
kUnknown = 0,
|
||||
// TheQuickBrownFox
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
namespace flatbuffers {
|
||||
|
||||
// This is a minimal replication of std::vector<uint8_t> functionality,
|
||||
// except growing from higher to lower addresses. i.e push_back() inserts data
|
||||
// except growing from higher to lower addresses. i.e. push_back() inserts data
|
||||
// in the lowest address in the vector.
|
||||
// Since this vector leaves the lower part unused, we support a "scratch-pad"
|
||||
// that can be stored there for temporary data, to share the allocated space.
|
||||
|
||||
@@ -25,22 +25,35 @@ namespace flatbuffers {
|
||||
// Helper class to verify the integrity of a FlatBuffer
|
||||
class Verifier FLATBUFFERS_FINAL_CLASS {
|
||||
public:
|
||||
Verifier(const uint8_t *const buf, const size_t buf_len,
|
||||
const uoffset_t _max_depth = 64,
|
||||
const uoffset_t _max_tables = 1000000,
|
||||
const bool _check_alignment = true)
|
||||
: buf_(buf),
|
||||
size_(buf_len),
|
||||
max_depth_(_max_depth),
|
||||
max_tables_(_max_tables),
|
||||
check_alignment_(_check_alignment),
|
||||
upper_bound_(0),
|
||||
depth_(0),
|
||||
num_tables_(0),
|
||||
flex_reuse_tracker_(nullptr) {
|
||||
struct Options {
|
||||
// The maximum nesting of tables and vectors before we call it invalid.
|
||||
uoffset_t max_depth = 64;
|
||||
// The maximum number of tables we will verify before we call it invalid.
|
||||
uoffset_t max_tables = 1000000;
|
||||
// If true, verify all data is aligned.
|
||||
bool check_alignment = true;
|
||||
// If true, run verifier on nested flatbuffers
|
||||
bool check_nested_flatbuffers = true;
|
||||
};
|
||||
|
||||
explicit Verifier(const uint8_t *const buf, const size_t buf_len,
|
||||
const Options &opts)
|
||||
: buf_(buf), size_(buf_len), opts_(opts) {
|
||||
FLATBUFFERS_ASSERT(size_ < FLATBUFFERS_MAX_BUFFER_SIZE);
|
||||
}
|
||||
|
||||
// Deprecated API, please construct with Verifier::Options.
|
||||
Verifier(const uint8_t *const buf, const size_t buf_len,
|
||||
const uoffset_t max_depth = 64, const uoffset_t max_tables = 1000000,
|
||||
const bool check_alignment = true)
|
||||
: Verifier(buf, buf_len, [&] {
|
||||
Options opts;
|
||||
opts.max_depth = max_depth;
|
||||
opts.max_tables = max_tables;
|
||||
opts.check_alignment = check_alignment;
|
||||
return opts;
|
||||
}()) {}
|
||||
|
||||
// Central location where any verification failures register.
|
||||
bool Check(const bool ok) const {
|
||||
// clang-format off
|
||||
@@ -68,7 +81,7 @@ class Verifier FLATBUFFERS_FINAL_CLASS {
|
||||
}
|
||||
|
||||
bool VerifyAlignment(const size_t elem, const size_t align) const {
|
||||
return Check((elem & (align - 1)) == 0 || !check_alignment_);
|
||||
return Check((elem & (align - 1)) == 0 || !opts_.check_alignment);
|
||||
}
|
||||
|
||||
// Verify a range indicated by sizeof(T).
|
||||
@@ -126,8 +139,8 @@ class Verifier FLATBUFFERS_FINAL_CLASS {
|
||||
const auto veco = static_cast<size_t>(vec - buf_);
|
||||
// Check we can read the size field.
|
||||
if (!Verify<uoffset_t>(veco)) return false;
|
||||
// Check the whole array. If this is a string, the byte past the array
|
||||
// must be 0.
|
||||
// Check the whole array. If this is a string, the byte past the array must
|
||||
// be 0.
|
||||
const auto size = ReadScalar<uoffset_t>(vec);
|
||||
const auto max_elems = FLATBUFFERS_MAX_BUFFER_SIZE / elem_size;
|
||||
if (!Check(size < max_elems))
|
||||
@@ -158,7 +171,7 @@ class Verifier FLATBUFFERS_FINAL_CLASS {
|
||||
return true;
|
||||
}
|
||||
|
||||
__supress_ubsan__("unsigned-integer-overflow") bool VerifyTableStart(
|
||||
__suppress_ubsan__("unsigned-integer-overflow") bool VerifyTableStart(
|
||||
const uint8_t *const table) {
|
||||
// Check the vtable offset.
|
||||
const auto tableo = static_cast<size_t>(table - buf_);
|
||||
@@ -204,11 +217,14 @@ class Verifier FLATBUFFERS_FINAL_CLASS {
|
||||
template<typename T>
|
||||
bool VerifyNestedFlatBuffer(const Vector<uint8_t> *const buf,
|
||||
const char *const identifier) {
|
||||
// Caller opted out of this.
|
||||
if (!opts_.check_nested_flatbuffers) return true;
|
||||
|
||||
// An empty buffer is OK as it indicates not present.
|
||||
if (!buf) return true;
|
||||
|
||||
// If there is a nested buffer, it must be greater than the min size.
|
||||
if(!Check(buf->size() >= FLATBUFFERS_MIN_BUFFER_SIZE)) return false;
|
||||
if (!Check(buf->size() >= FLATBUFFERS_MIN_BUFFER_SIZE)) return false;
|
||||
|
||||
Verifier nested_verifier(buf->data(), buf->size());
|
||||
return nested_verifier.VerifyBuffer<T>(identifier);
|
||||
@@ -247,13 +263,12 @@ class Verifier FLATBUFFERS_FINAL_CLASS {
|
||||
}
|
||||
|
||||
// Called at the start of a table to increase counters measuring data
|
||||
// structure depth and amount, and possibly bails out with false if
|
||||
// limits set by the constructor have been hit. Needs to be balanced
|
||||
// with EndTable().
|
||||
// structure depth and amount, and possibly bails out with false if limits set
|
||||
// by the constructor have been hit. Needs to be balanced with EndTable().
|
||||
bool VerifyComplexity() {
|
||||
depth_++;
|
||||
num_tables_++;
|
||||
return Check(depth_ <= max_depth_ && num_tables_ <= max_tables_);
|
||||
return Check(depth_ <= opts_.max_depth && num_tables_ <= opts_.max_tables);
|
||||
}
|
||||
|
||||
// Called at the end of a table to pop the depth count.
|
||||
@@ -288,15 +303,13 @@ class Verifier FLATBUFFERS_FINAL_CLASS {
|
||||
private:
|
||||
const uint8_t *buf_;
|
||||
const size_t size_;
|
||||
const uoffset_t max_depth_;
|
||||
const uoffset_t max_tables_;
|
||||
const bool check_alignment_;
|
||||
const Options opts_;
|
||||
|
||||
mutable size_t upper_bound_;
|
||||
mutable size_t upper_bound_ = 0;
|
||||
|
||||
uoffset_t depth_;
|
||||
uoffset_t num_tables_;
|
||||
std::vector<uint8_t> *flex_reuse_tracker_;
|
||||
uoffset_t depth_ = 0;
|
||||
uoffset_t num_tables_ = 0;
|
||||
std::vector<uint8_t> *flex_reuse_tracker_ = nullptr;
|
||||
};
|
||||
|
||||
} // namespace flatbuffers
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>com.google.flatbuffers</groupId>
|
||||
<artifactId>flatbuffers-java</artifactId>
|
||||
<version>2.0.3</version>
|
||||
<version>22.9.24</version>
|
||||
<packaging>bundle</packaging>
|
||||
<name>FlatBuffers Java API</name>
|
||||
<description>
|
||||
@@ -13,6 +13,10 @@
|
||||
<developer>
|
||||
<name>Wouter van Oortmerssen</name>
|
||||
</developer>
|
||||
<developer>
|
||||
<name>Derek Bailey</name>
|
||||
<email>dbaileychess@gmail.com</email>
|
||||
</developer>
|
||||
</developers>
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
@@ -33,6 +37,18 @@
|
||||
<tag>HEAD</tag>
|
||||
</scm>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>4.13.1</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.google.truth</groupId>
|
||||
<artifactId>truth</artifactId>
|
||||
<version>1.1.3</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<distributionManagement>
|
||||
<snapshotRepository>
|
||||
@@ -41,7 +57,21 @@
|
||||
</snapshotRepository>
|
||||
</distributionManagement>
|
||||
<build>
|
||||
<sourceDirectory>java</sourceDirectory>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<configuration>
|
||||
<release>8</release>
|
||||
<testExcludes>
|
||||
<testExclude>**/LongEnum.java</testExclude>
|
||||
<testExclude>MyGame/Example/MonsterStorageGrpc.java</testExclude>
|
||||
<testExclude>MyGame/Example/StructOfStructs**</testExclude>
|
||||
<testExclude>MyGame/OtherNameSpace/TableBT.java</testExclude>
|
||||
</testExcludes>
|
||||
</configuration>
|
||||
<version>3.8.1</version>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
<profiles>
|
||||
<profile>
|
||||
@@ -51,13 +81,6 @@
|
||||
</activation>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<configuration>
|
||||
<release>8</release>
|
||||
</configuration>
|
||||
<version>3.8.1</version>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<configuration>
|
||||
@@ -46,7 +46,7 @@ public class Constants {
|
||||
Changes to the Java implementation need to be sure to change
|
||||
the version here and in the code generator on every possible
|
||||
incompatible change */
|
||||
public static void FLATBUFFERS_2_0_0() {}
|
||||
public static void FLATBUFFERS_22_9_24() {}
|
||||
}
|
||||
|
||||
/// @endcond
|
||||
@@ -173,6 +173,21 @@ public class FlexBuffersBuilder {
|
||||
return bb;
|
||||
}
|
||||
|
||||
/**
|
||||
* Insert a null value into the buffer
|
||||
*/
|
||||
public void putNull() {
|
||||
putNull(null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Insert a null value into the buffer
|
||||
* @param key key used to store element in map
|
||||
*/
|
||||
public void putNull(String key) {
|
||||
stack.add(Value.nullValue(putKey(key)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Insert a single boolean into the buffer
|
||||
* @param val true or false
|
||||
@@ -451,7 +466,7 @@ public class FlexBuffersBuilder {
|
||||
/**
|
||||
* Finishes a vector, but writing the information in the buffer
|
||||
* @param key key used to store element in map
|
||||
* @param start reference for begining of the vector. Returned by {@link startVector()}
|
||||
* @param start reference for beginning of the vector. Returned by {@link startVector()}
|
||||
* @param typed boolean indicating whether vector is typed
|
||||
* @param fixed boolean indicating whether vector is fixed
|
||||
* @return Reference to the vector
|
||||
@@ -502,7 +517,9 @@ public class FlexBuffersBuilder {
|
||||
* @return Value representing the created vector
|
||||
*/
|
||||
private Value createVector(int key, int start, int length, boolean typed, boolean fixed, Value keys) {
|
||||
assert (!fixed || typed); // typed=false, fixed=true combination is not supported.
|
||||
if (fixed & !typed)
|
||||
throw new UnsupportedOperationException("Untyped fixed vector is not supported");
|
||||
|
||||
// Figure out smallest bit width we can store this vector with.
|
||||
int bitWidth = Math.max(WIDTH_8, widthUInBits(length));
|
||||
int prefixElems = 1;
|
||||
@@ -602,7 +619,7 @@ public class FlexBuffersBuilder {
|
||||
/**
|
||||
* Finishes a map, but writing the information in the buffer
|
||||
* @param key key used to store element in map
|
||||
* @param start reference for begining of the map. Returned by {@link startMap()}
|
||||
* @param start reference for beginning of the map. Returned by {@link startMap()}
|
||||
* @return Reference to the map
|
||||
*/
|
||||
public int endMap(String key, int start) {
|
||||
@@ -673,6 +690,10 @@ public class FlexBuffersBuilder {
|
||||
this.iValue = Long.MIN_VALUE;
|
||||
}
|
||||
|
||||
static Value nullValue(int key) {
|
||||
return new Value(key, FBT_NULL, WIDTH_8, 0);
|
||||
}
|
||||
|
||||
static Value bool(int key, boolean b) {
|
||||
return new Value(key, FBT_BOOL, WIDTH_8, b ? 1 : 0);
|
||||
}
|
||||
1
java/src/test/java/DictionaryLookup
Symbolic link
1
java/src/test/java/DictionaryLookup
Symbolic link
@@ -0,0 +1 @@
|
||||
../../../../tests/DictionaryLookup
|
||||
File diff suppressed because it is too large
Load Diff
1
java/src/test/java/MyGame
Symbolic link
1
java/src/test/java/MyGame
Symbolic link
@@ -0,0 +1 @@
|
||||
../../../../tests/MyGame
|
||||
1
java/src/test/java/NamespaceA
Symbolic link
1
java/src/test/java/NamespaceA
Symbolic link
@@ -0,0 +1 @@
|
||||
../../../../tests/namespace_test/NamespaceA
|
||||
1
java/src/test/java/NamespaceC
Symbolic link
1
java/src/test/java/NamespaceC
Symbolic link
@@ -0,0 +1 @@
|
||||
../../../../tests/namespace_test/NamespaceC
|
||||
1
java/src/test/java/optional_scalars
Symbolic link
1
java/src/test/java/optional_scalars
Symbolic link
@@ -0,0 +1 @@
|
||||
../../../../tests/optional_scalars
|
||||
1
java/src/test/java/union_vector
Symbolic link
1
java/src/test/java/union_vector
Symbolic link
@@ -0,0 +1 @@
|
||||
../../../../tests/union_vector
|
||||
BIN
java/src/test/resources/monsterdata_test.mon
Normal file
BIN
java/src/test/resources/monsterdata_test.mon
Normal file
Binary file not shown.
@@ -1 +1 @@
|
||||
../../../../java/
|
||||
../../../../java/src/main/java
|
||||
@@ -51,7 +51,7 @@ using System.Buffers.Binary;
|
||||
#warning ENABLE_SPAN_T requires UNSAFE_BYTEBUFFER to also be defined
|
||||
#endif
|
||||
|
||||
namespace FlatBuffers
|
||||
namespace Google.FlatBuffers
|
||||
{
|
||||
public abstract class ByteBufferAllocator
|
||||
{
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
|
||||
using System;
|
||||
|
||||
namespace FlatBuffers
|
||||
namespace Google.FlatBuffers
|
||||
{
|
||||
/// <summary>
|
||||
/// Class that collects utility functions around `ByteBuffer`.
|
||||
|
||||
@@ -23,7 +23,7 @@ using System.Text;
|
||||
/// @addtogroup flatbuffers_csharp_api
|
||||
/// @{
|
||||
|
||||
namespace FlatBuffers
|
||||
namespace Google.FlatBuffers
|
||||
{
|
||||
/// <summary>
|
||||
/// Responsible for building up and accessing a FlatBuffer formatted byte
|
||||
|
||||
@@ -19,7 +19,7 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace FlatBuffers
|
||||
namespace Google.FlatBuffers
|
||||
{
|
||||
public static class FlatBufferConstants
|
||||
{
|
||||
@@ -32,6 +32,6 @@ namespace FlatBuffers
|
||||
Changes to the C# implementation need to be sure to change
|
||||
the version here and in the code generator on every possible
|
||||
incompatible change */
|
||||
public static void FLATBUFFERS_2_0_0() {}
|
||||
public static void FLATBUFFERS_22_9_24() {}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,23 +0,0 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk" ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFrameworks>netstandard2.1;netstandard2.0;net46</TargetFrameworks>
|
||||
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition="'$(UNSAFE_BYTEBUFFER)' == 'true'">
|
||||
<DefineConstants>$(DefineConstants);UNSAFE_BYTEBUFFER</DefineConstants>
|
||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(BYTEBUFFER_NO_BOUNDS_CHECK)' == 'true'">
|
||||
<DefineConstants>$(DefineConstants);BYTEBUFFER_NO_BOUNDS_CHECK</DefineConstants>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(ENABLE_SPAN_T)' == 'true'">
|
||||
<DefineConstants>$(DefineConstants);ENABLE_SPAN_T</DefineConstants>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup Condition="('$(ENABLE_SPAN_T)' == 'true') And (('$(TargetFramework)' == 'netstandard2.0') Or ('$(TargetFramework)' == 'net46'))">
|
||||
<PackageReference Include="System.Memory" Version="4.5.4" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
46
net/FlatBuffers/Google.FlatBuffers.csproj
Normal file
46
net/FlatBuffers/Google.FlatBuffers.csproj
Normal file
@@ -0,0 +1,46 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk" ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFrameworks>netstandard2.1;netstandard2.0;net46</TargetFrameworks>
|
||||
<Description>A cross-platform memory efficient serialization library</Description>
|
||||
<PackageVersion>22.9.24</PackageVersion>
|
||||
<Authors>Google LLC</Authors>
|
||||
<PackageProjectUrl>https://github.com/google/flatbuffers</PackageProjectUrl>
|
||||
<RepositoryUrl>https://github.com/google/flatbuffers</RepositoryUrl>
|
||||
<PublishRepositoryUrl>true</PublishRepositoryUrl>
|
||||
<PackageLicenseFile>LICENSE.txt</PackageLicenseFile>
|
||||
<PackageIcon>flatbuffers.png</PackageIcon>
|
||||
<PackageTags>Google;FlatBuffers;Serialization;Buffer;Binary;zero copy</PackageTags>
|
||||
<Copyright>Copyright 2022 Google LLC</Copyright>
|
||||
<IncludeSymbols>true</IncludeSymbols>
|
||||
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
|
||||
<SignAssembly>true</SignAssembly>
|
||||
<AssemblyOriginatorKeyFile>flatbuffers.snk</AssemblyOriginatorKeyFile>
|
||||
<DelaySign>false</DelaySign>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition="'$(UNSAFE_BYTEBUFFER)' == 'true'">
|
||||
<DefineConstants>$(DefineConstants);UNSAFE_BYTEBUFFER</DefineConstants>
|
||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(BYTEBUFFER_NO_BOUNDS_CHECK)' == 'true'">
|
||||
<DefineConstants>$(DefineConstants);BYTEBUFFER_NO_BOUNDS_CHECK</DefineConstants>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(ENABLE_SPAN_T)' == 'true'">
|
||||
<DefineConstants>$(DefineConstants);ENABLE_SPAN_T</DefineConstants>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup Condition="('$(ENABLE_SPAN_T)' == 'true') And (('$(TargetFramework)' == 'netstandard2.0') Or ('$(TargetFramework)' == 'net46'))">
|
||||
<PackageReference Include="System.Memory" Version="4.5.4" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1" PrivateAssets="All" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Include="..\..\LICENSE.txt" Pack="true" PackagePath="" />
|
||||
<None Include="flatbuffers.png" Pack="true" PackagePath="" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
namespace FlatBuffers
|
||||
namespace Google.FlatBuffers
|
||||
{
|
||||
/// <summary>
|
||||
/// This is the base for both structs and tables.
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
namespace FlatBuffers
|
||||
namespace Google.FlatBuffers
|
||||
{
|
||||
/// <summary>
|
||||
/// Offset class for typesafe assignments.
|
||||
|
||||
@@ -1,52 +0,0 @@
|
||||
/*
|
||||
* Copyright 2014 Google Inc. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
// General Information about an assembly is controlled through the following
|
||||
// set of attributes. Change these attribute values to modify the information
|
||||
// associated with an assembly.
|
||||
[assembly: AssemblyTitle("FlatBuffers")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("")]
|
||||
[assembly: AssemblyProduct("FlatBuffers")]
|
||||
[assembly: AssemblyCopyright("Copyright (c) 2015 Google Inc")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
|
||||
// Setting ComVisible to false makes the types in this assembly not visible
|
||||
// to COM components. If you need to access a type in this assembly from
|
||||
// COM, set the ComVisible attribute to true on that type.
|
||||
[assembly: ComVisible(false)]
|
||||
|
||||
// The following GUID is for the ID of the typelib if this project is exposed to COM
|
||||
[assembly: Guid("91c32e64-ef20-47df-9c9f-cec9207bc6df")]
|
||||
|
||||
// Version information for an assembly consists of the following four values:
|
||||
//
|
||||
// Major Version
|
||||
// Minor Version
|
||||
// Build Number
|
||||
// Revision
|
||||
//
|
||||
// You can specify all the values or you can default the Build and Revision Numbers
|
||||
// by using the '*' as shown below:
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion("1.0.0.0")]
|
||||
[assembly: AssemblyFileVersion("1.0.0.0")]
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
namespace FlatBuffers
|
||||
namespace Google.FlatBuffers
|
||||
{
|
||||
/// <summary>
|
||||
/// All structs in the generated code derive from this class, and add their own accessors.
|
||||
|
||||
@@ -18,7 +18,7 @@ using System;
|
||||
using System.Text;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace FlatBuffers
|
||||
namespace Google.FlatBuffers
|
||||
{
|
||||
/// <summary>
|
||||
/// All tables in the generated code derive from this struct, and add their own accessors.
|
||||
|
||||
BIN
net/FlatBuffers/flatbuffers.png
Normal file
BIN
net/FlatBuffers/flatbuffers.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 5.0 KiB |
BIN
net/FlatBuffers/flatbuffers.snk
Normal file
BIN
net/FlatBuffers/flatbuffers.snk
Normal file
Binary file not shown.
19
package.json
19
package.json
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "flatbuffers",
|
||||
"version": "2.0.6",
|
||||
"version": "22.9.24",
|
||||
"description": "Memory Efficient Serialization Library",
|
||||
"files": [
|
||||
"js/**/*.js",
|
||||
@@ -16,8 +16,8 @@
|
||||
"test": "tests"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "npm run compile && cd tests && python3 ./TypeScriptTest.py",
|
||||
"compile": "tsc && tsc -p tsconfig.mjs.json",
|
||||
"test": "npm run compile && cd tests/ts && python3 ./TypeScriptTest.py",
|
||||
"compile": "tsc && tsc -p tsconfig.mjs.json && rollup -c",
|
||||
"prepublishOnly": "npm install --only=dev && npm run compile"
|
||||
},
|
||||
"repository": {
|
||||
@@ -35,11 +35,12 @@
|
||||
"homepage": "https://google.github.io/flatbuffers/",
|
||||
"dependencies": {},
|
||||
"devDependencies": {
|
||||
"@bazel/typescript": "^5.2.0",
|
||||
"@types/node": "17.0.21",
|
||||
"@typescript-eslint/eslint-plugin": "^4.12.0",
|
||||
"@typescript-eslint/parser": "^4.12.0",
|
||||
"eslint": "^7.17.0",
|
||||
"typescript": "^4.5.5"
|
||||
"@bazel/typescript": "5.2.0",
|
||||
"@types/node": "18.7.16",
|
||||
"@typescript-eslint/eslint-plugin": "^5.36.2",
|
||||
"@typescript-eslint/parser": "^5.36.2",
|
||||
"eslint": "^8.23.1",
|
||||
"rollup": "^2.79.0",
|
||||
"typescript": "^4.8.3"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,4 +14,4 @@
|
||||
|
||||
# Placeholder, to be updated during the release process
|
||||
# by the setup.py
|
||||
__version__ = u"latest"
|
||||
__version__ = u"22.9.24"
|
||||
|
||||
@@ -113,6 +113,15 @@ class Table(object):
|
||||
numpy_dtype = N.to_numpy_type(flags)
|
||||
return encode.GetVectorAsNumpy(numpy_dtype, self.Bytes, length, offset)
|
||||
|
||||
def GetArrayAsNumpy(self, flags, off, length):
|
||||
"""
|
||||
GetArrayAsNumpy returns the array with fixed width that starts at `Vector(offset)`
|
||||
with length `length` as a numpy array with the type specified by `flags`. The
|
||||
array is a `view` into Bytes so modifying the returned will modify Bytes in place.
|
||||
"""
|
||||
numpy_dtype = N.to_numpy_type(flags)
|
||||
return encode.GetVectorAsNumpy(numpy_dtype, self.Bytes, length, off)
|
||||
|
||||
def GetVOffsetTSlot(self, slot, d):
|
||||
"""
|
||||
GetVOffsetTSlot retrieves the VOffsetT that the given vtable location
|
||||
@@ -125,5 +134,5 @@ class Table(object):
|
||||
|
||||
off = self.Offset(slot)
|
||||
if off == 0:
|
||||
return d
|
||||
return d
|
||||
return off
|
||||
|
||||
45
readme.md
45
readme.md
@@ -20,33 +20,46 @@ maximum memory efficiency. It allows you to directly access serialized data with
|
||||
* MacOS X
|
||||
* Linux
|
||||
* Android
|
||||
* And any others with a recent C++ compiler.
|
||||
* And any others with a recent C++ compiler (C++ 11 and newer)
|
||||
|
||||
## Supported programming languages
|
||||
* C++
|
||||
* C#
|
||||
* C
|
||||
* Dart
|
||||
* Go
|
||||
* Java
|
||||
* JavaScript
|
||||
* Lobster
|
||||
* Lua
|
||||
* PHP
|
||||
* Python
|
||||
* Rust
|
||||
* Swift
|
||||
* TypeScript
|
||||
|
||||
Code generation and runtime libraries for many popular languages.
|
||||
|
||||
1. C
|
||||
1. C++ - [snapcraft.io](https://snapcraft.io/flatbuffers)
|
||||
1. C# - [nuget.org](https://www.nuget.org/packages/Google.FlatBuffers)
|
||||
1. Dart - [pub.dev](https://pub.dev/packages/flat_buffers)
|
||||
1. Go - [go.dev](https://pkg.go.dev/github.com/google/flatbuffers/go)
|
||||
1. Java - [Maven](https://search.maven.org/artifact/com.google.flatbuffers/flatbuffers-java)
|
||||
1. JavaScript - [NPM](https://www.npmjs.com/package/flatbuffers)
|
||||
1. Kotlin
|
||||
1. Lobster
|
||||
1. Lua
|
||||
1. PHP
|
||||
1. Python - [PyPi](https://pypi.org/project/flatbuffers/)
|
||||
1. Rust - [crates.io](https://crates.io/crates/flatbuffers)
|
||||
1. Swift
|
||||
1. TypeScript - [NPM](https://www.npmjs.com/package/flatbuffers)
|
||||
|
||||
*and more in progress...*
|
||||
|
||||
1. [Nim](https://github.com/google/flatbuffers/pull/7362)
|
||||
|
||||
## Contribution
|
||||
* [FlatBuffers Google Group][] to discuss FlatBuffers with other developers and users.
|
||||
|
||||
* [FlatBuffers Issues Tracker][] to submit an issue.
|
||||
* [stackoverflow.com][] with [`flatbuffers` tag][] for any questions regarding FlatBuffers.
|
||||
|
||||
*To contribute to this project,* see [CONTRIBUTING][].
|
||||
|
||||
## Community
|
||||
|
||||
* [FlatBuffers Google Group][] to discuss FlatBuffers with other developers and users.
|
||||
* [Discord Server](https:///discord.gg/6qgKs3R)
|
||||
* [Gitter](https://gitter.im/google/flatbuffers)
|
||||
|
||||
|
||||
## Security
|
||||
|
||||
Please see our [Security Policy](SECURITY.md) for reporting vulnerabilities.
|
||||
|
||||
8
rollup.config.js
Normal file
8
rollup.config.js
Normal file
@@ -0,0 +1,8 @@
|
||||
export default {
|
||||
input: 'mjs/index.js',
|
||||
output: {
|
||||
file: 'flatbuffers.js',
|
||||
format: 'iife',
|
||||
name: 'flatbuffers'
|
||||
}
|
||||
}
|
||||
@@ -8,9 +8,9 @@
|
||||
|
||||
// Ensure the included flatbuffers.h is the same version as when this file was
|
||||
// generated, otherwise it may not be compatible.
|
||||
static_assert(FLATBUFFERS_VERSION_MAJOR == 2 &&
|
||||
FLATBUFFERS_VERSION_MINOR == 0 &&
|
||||
FLATBUFFERS_VERSION_REVISION == 7,
|
||||
static_assert(FLATBUFFERS_VERSION_MAJOR == 22 &&
|
||||
FLATBUFFERS_VERSION_MINOR == 9 &&
|
||||
FLATBUFFERS_VERSION_REVISION == 24,
|
||||
"Non-compatible flatbuffers version included");
|
||||
|
||||
namespace MyGame {
|
||||
@@ -607,10 +607,10 @@ inline void Monster::UnPackTo(MonsterT *_o, const flatbuffers::resolver_function
|
||||
{ auto _e = name(); if (_e) _o->name = _e->str(); }
|
||||
{ auto _e = inventory(); if (_e) { _o->inventory.resize(_e->size()); std::copy(_e->begin(), _e->end(), _o->inventory.begin()); } }
|
||||
{ auto _e = color(); _o->color = _e; }
|
||||
{ auto _e = weapons(); if (_e) { _o->weapons.resize(_e->size()); for (flatbuffers::uoffset_t _i = 0; _i < _e->size(); _i++) { _o->weapons[_i] = flatbuffers::unique_ptr<MyGame::Sample::WeaponT>(_e->Get(_i)->UnPack(_resolver)); } } }
|
||||
{ auto _e = weapons(); if (_e) { _o->weapons.resize(_e->size()); for (flatbuffers::uoffset_t _i = 0; _i < _e->size(); _i++) { if(_o->weapons[_i]) { _e->Get(_i)->UnPackTo(_o->weapons[_i].get(), _resolver); } else { _o->weapons[_i] = flatbuffers::unique_ptr<MyGame::Sample::WeaponT>(_e->Get(_i)->UnPack(_resolver)); }; } } else { _o->weapons.resize(0); } }
|
||||
{ auto _e = equipped_type(); _o->equipped.type = _e; }
|
||||
{ auto _e = equipped(); if (_e) _o->equipped.value = MyGame::Sample::EquipmentUnion::UnPack(_e, equipped_type(), _resolver); }
|
||||
{ auto _e = path(); if (_e) { _o->path.resize(_e->size()); for (flatbuffers::uoffset_t _i = 0; _i < _e->size(); _i++) { _o->path[_i] = *_e->Get(_i); } } }
|
||||
{ auto _e = path(); if (_e) { _o->path.resize(_e->size()); for (flatbuffers::uoffset_t _i = 0; _i < _e->size(); _i++) { _o->path[_i] = *_e->Get(_i); } } else { _o->path.resize(0); } }
|
||||
}
|
||||
|
||||
inline flatbuffers::Offset<Monster> Monster::Pack(flatbuffers::FlatBufferBuilder &_fbb, const MonsterT* _o, const flatbuffers::rehasher_function_t *_rehasher) {
|
||||
|
||||
@@ -31,7 +31,7 @@ public enum MyGame_Sample_Equipment: UInt8, Enum {
|
||||
|
||||
public struct MyGame_Sample_Vec3: NativeStruct {
|
||||
|
||||
static func validateVersion() { FlatBuffersVersion_2_0_0() }
|
||||
static func validateVersion() { FlatBuffersVersion_22_9_24() }
|
||||
|
||||
private var _x: Float32
|
||||
private var _y: Float32
|
||||
@@ -56,7 +56,7 @@ public struct MyGame_Sample_Vec3: NativeStruct {
|
||||
|
||||
public struct MyGame_Sample_Vec3_Mutable: FlatBufferObject {
|
||||
|
||||
static func validateVersion() { FlatBuffersVersion_2_0_0() }
|
||||
static func validateVersion() { FlatBuffersVersion_22_9_24() }
|
||||
public var __buffer: ByteBuffer! { return _accessor.bb }
|
||||
private var _accessor: Struct
|
||||
|
||||
@@ -72,7 +72,7 @@ public struct MyGame_Sample_Vec3_Mutable: FlatBufferObject {
|
||||
|
||||
public struct MyGame_Sample_Monster: FlatBufferObject {
|
||||
|
||||
static func validateVersion() { FlatBuffersVersion_2_0_0() }
|
||||
static func validateVersion() { FlatBuffersVersion_22_9_24() }
|
||||
public var __buffer: ByteBuffer! { return _accessor.bb }
|
||||
private var _accessor: Table
|
||||
|
||||
@@ -162,7 +162,7 @@ public struct MyGame_Sample_Monster: FlatBufferObject {
|
||||
|
||||
public struct MyGame_Sample_Weapon: FlatBufferObject {
|
||||
|
||||
static func validateVersion() { FlatBuffersVersion_2_0_0() }
|
||||
static func validateVersion() { FlatBuffersVersion_22_9_24() }
|
||||
public var __buffer: ByteBuffer! { return _accessor.bb }
|
||||
private var _accessor: Table
|
||||
|
||||
|
||||
@@ -64,7 +64,7 @@ assert flatc_path.exists(), "Cannot find the flatc compiler " + str(flatc_path)
|
||||
|
||||
# Specify the other paths that will be referenced
|
||||
tests_path = Path(root_path, "tests")
|
||||
swift_code_gen = Path(root_path, "tests/FlatBuffers.Test.Swift/CodeGenerationTests")
|
||||
swift_code_gen = Path(root_path, "tests/swift/tests/CodeGenerationTests")
|
||||
samples_path = Path(root_path, "samples")
|
||||
reflection_path = Path(root_path, "reflection")
|
||||
|
||||
@@ -165,7 +165,6 @@ flatc(
|
||||
NO_INCL_OPTS
|
||||
+ CPP_OPTS
|
||||
+ CS_OPTS
|
||||
+ TS_OPTS
|
||||
+ [
|
||||
"--binary",
|
||||
"--java",
|
||||
@@ -180,6 +179,15 @@ flatc(
|
||||
data="monsterdata_test.json",
|
||||
)
|
||||
|
||||
flatc(
|
||||
NO_INCL_OPTS
|
||||
+ TS_OPTS,
|
||||
schema="monster_test.fbs",
|
||||
prefix="ts",
|
||||
include="include_test",
|
||||
data="monsterdata_test.json",
|
||||
)
|
||||
|
||||
flatc(
|
||||
["--lua", "--bfbs-filenames", str(tests_path)],
|
||||
schema="monster_test.fbs",
|
||||
@@ -226,7 +234,7 @@ flatc(
|
||||
# For Rust we currently generate two independent schemas, with namespace_test2
|
||||
# duplicating the types in namespace_test1
|
||||
flatc(
|
||||
RUST_OPTS,
|
||||
RUST_OPTS + CS_OPTS,
|
||||
prefix="namespace_test",
|
||||
schema=[
|
||||
"namespace_test/namespace_test1.fbs",
|
||||
@@ -235,14 +243,21 @@ flatc(
|
||||
)
|
||||
|
||||
flatc(
|
||||
BASE_OPTS + CPP_OPTS + CS_OPTS + TS_OPTS + JAVA_OPTS + KOTLIN_OPTS + PHP_OPTS,
|
||||
BASE_OPTS + CPP_OPTS + CS_OPTS + JAVA_OPTS + KOTLIN_OPTS + PHP_OPTS,
|
||||
prefix="union_vector",
|
||||
schema="union_vector/union_vector.fbs",
|
||||
)
|
||||
|
||||
flatc(
|
||||
BASE_OPTS + TS_OPTS,
|
||||
prefix="ts/union_vector",
|
||||
schema="union_vector/union_vector.fbs",
|
||||
)
|
||||
|
||||
flatc(
|
||||
BASE_OPTS + TS_OPTS + ["--gen-name-strings", "--gen-mutable"],
|
||||
include="include_test",
|
||||
prefix="ts",
|
||||
schema="monster_test.fbs",
|
||||
)
|
||||
|
||||
@@ -257,13 +272,14 @@ flatc(
|
||||
flatc(
|
||||
BASE_OPTS + TS_OPTS + ["-b"],
|
||||
include="include_test",
|
||||
prefix="ts",
|
||||
schema="monster_test.fbs",
|
||||
data="unicode_test.json",
|
||||
)
|
||||
|
||||
flatc(
|
||||
BASE_OPTS + TS_OPTS + ["--gen-name-strings"],
|
||||
prefix="union_vector",
|
||||
prefix="ts/union_vector",
|
||||
schema="union_vector/union_vector.fbs",
|
||||
)
|
||||
|
||||
@@ -357,7 +373,8 @@ flatc(
|
||||
|
||||
# Optional Scalars
|
||||
optional_scalars_schema = "optional_scalars.fbs"
|
||||
flatc(["--java", "--kotlin", "--lobster", "--ts"], schema=optional_scalars_schema)
|
||||
flatc(["--java", "--kotlin", "--lobster"], schema=optional_scalars_schema)
|
||||
flatc(TS_OPTS, schema=optional_scalars_schema, prefix="ts")
|
||||
|
||||
flatc(["--csharp", "--python", "--gen-object-api"], schema=optional_scalars_schema)
|
||||
|
||||
@@ -395,7 +412,7 @@ dictionary_lookup_schema = "dictionary_lookup.fbs"
|
||||
flatc(["--java", "--kotlin"], schema=dictionary_lookup_schema)
|
||||
|
||||
# Swift Tests
|
||||
swift_prefix = "FlatBuffers.Test.Swift/Tests/FlatBuffers.Test.SwiftTests"
|
||||
swift_prefix = "swift/tests/Tests/FlatBuffers.Test.SwiftTests"
|
||||
flatc(
|
||||
SWIFT_OPTS + BASE_OPTS + ["--grpc"],
|
||||
schema="monster_test.fbs",
|
||||
|
||||
@@ -52,9 +52,6 @@ void LogCompilerError(const std::string &err) {
|
||||
} // namespace flatbuffers
|
||||
|
||||
int main(int argc, const char *argv[]) {
|
||||
// Prevent Appveyor-CI hangs.
|
||||
flatbuffers::SetupDefaultCRTReportMode();
|
||||
|
||||
const std::string flatbuffers_version(flatbuffers::FLATBUFFERS_VERSION());
|
||||
|
||||
std::unique_ptr<flatbuffers::BfbsGenerator> bfbs_gen_lua =
|
||||
|
||||
@@ -26,10 +26,6 @@
|
||||
#include "flatbuffers/idl.h"
|
||||
#include "flatbuffers/util.h"
|
||||
|
||||
#ifndef FLATBUFFERS_CPP_OBJECT_UNPACKTO
|
||||
#define FLATBUFFERS_CPP_OBJECT_UNPACKTO 0
|
||||
#endif
|
||||
|
||||
namespace flatbuffers {
|
||||
|
||||
// Make numerical literal with type-suffix.
|
||||
@@ -74,6 +70,19 @@ static std::string GenIncludeGuard(const std::string &file_name,
|
||||
return guard;
|
||||
}
|
||||
|
||||
static bool IsVectorOfPointers(const FieldDef &field) {
|
||||
const auto &type = field.value.type;
|
||||
const auto &vector_type = type.VectorType();
|
||||
return type.base_type == BASE_TYPE_VECTOR &&
|
||||
vector_type.base_type == BASE_TYPE_STRUCT &&
|
||||
!vector_type.struct_def->fixed && !field.native_inline;
|
||||
}
|
||||
|
||||
static bool IsPointer(const FieldDef &field) {
|
||||
return field.value.type.base_type == BASE_TYPE_STRUCT &&
|
||||
!IsStruct(field.value.type);
|
||||
}
|
||||
|
||||
namespace cpp {
|
||||
|
||||
enum CppStandard { CPP_STD_X0 = 0, CPP_STD_11, CPP_STD_17 };
|
||||
@@ -233,37 +242,24 @@ class CppGenerator : public BaseGenerator {
|
||||
}
|
||||
|
||||
// Get the directly included file of the file being parsed.
|
||||
std::vector<std::string> included_files(parser_.GetIncludedFiles());
|
||||
std::vector<IncludedFile> included_files(parser_.GetIncludedFiles());
|
||||
|
||||
// We are safe to sort them alphabetically, since there shouldn't be any
|
||||
// interdependence between them.
|
||||
std::stable_sort(included_files.begin(), included_files.end());
|
||||
|
||||
// The absolute path of the file being parsed.
|
||||
const std::string parsed_path =
|
||||
flatbuffers::StripFileName(AbsolutePath(parser_.file_being_parsed_));
|
||||
for (const IncludedFile &included_file : included_files) {
|
||||
// Get the name of the included file as defined by the schema, and strip
|
||||
// the .fbs extension.
|
||||
const std::string name_without_ext =
|
||||
flatbuffers::StripExtension(included_file.schema_name);
|
||||
|
||||
for (const std::string &included_file : included_files) {
|
||||
// The base name of the file, without path or extensions.
|
||||
std::string basename =
|
||||
flatbuffers::StripPath(flatbuffers::StripExtension(included_file));
|
||||
|
||||
// If we are keeping the prefix
|
||||
if (opts_.keep_prefix) {
|
||||
// The absolute path of the included file.
|
||||
const std::string included_path =
|
||||
flatbuffers::StripFileName(AbsolutePath(included_file));
|
||||
|
||||
// The relative path of the parsed file to the included file.
|
||||
const std::string relative_path =
|
||||
RelativeToRootPath(parsed_path, included_path).substr(2);
|
||||
|
||||
// Only consider cases where the included path is a subdirectory of the
|
||||
// parsed path.
|
||||
if (strncmp("..", relative_path.c_str(), 2) != 0) {
|
||||
basename = relative_path + kPathSeparator + basename;
|
||||
}
|
||||
}
|
||||
// If we are told to keep the prefix of the included schema, leave it
|
||||
// unchanged, otherwise strip the leading path off so just the "basename"
|
||||
// of the include is retained.
|
||||
const std::string basename =
|
||||
opts_.keep_prefix ? name_without_ext
|
||||
: flatbuffers::StripPath(name_without_ext);
|
||||
|
||||
code_ += "#include \"" +
|
||||
GeneratedFileName(opts_.include_prefix, basename, opts_) + "\"";
|
||||
@@ -898,7 +894,9 @@ class CppGenerator : public BaseGenerator {
|
||||
}
|
||||
} else {
|
||||
const auto nn = WrapNativeNameInNameSpace(*type.struct_def, opts_);
|
||||
return forcopy ? nn : GenTypeNativePtr(nn, &field, false);
|
||||
return (forcopy || field.native_inline)
|
||||
? nn
|
||||
: GenTypeNativePtr(nn, &field, false);
|
||||
}
|
||||
}
|
||||
case BASE_TYPE_UNION: {
|
||||
@@ -1884,9 +1882,8 @@ class CppGenerator : public BaseGenerator {
|
||||
if (vec_type.base_type == BASE_TYPE_UTYPE) continue;
|
||||
const auto cpp_type = field.attributes.Lookup("cpp_type");
|
||||
const auto cpp_ptr_type = field.attributes.Lookup("cpp_ptr_type");
|
||||
const bool is_ptr =
|
||||
(vec_type.base_type == BASE_TYPE_STRUCT && !IsStruct(vec_type)) ||
|
||||
(cpp_type && cpp_ptr_type->constant != "naked");
|
||||
const bool is_ptr = IsVectorOfPointers(field) ||
|
||||
(cpp_type && cpp_ptr_type->constant != "naked");
|
||||
if (is_ptr) { return true; }
|
||||
}
|
||||
}
|
||||
@@ -2010,9 +2007,8 @@ class CppGenerator : public BaseGenerator {
|
||||
? cpp_type->constant
|
||||
: GenTypeNative(vec_type, /*invector*/ true,
|
||||
field, /*forcopy*/ true);
|
||||
const bool is_ptr =
|
||||
(vec_type.base_type == BASE_TYPE_STRUCT && !IsStruct(vec_type)) ||
|
||||
(cpp_type && cpp_ptr_type->constant != "naked");
|
||||
const bool is_ptr = IsVectorOfPointers(field) ||
|
||||
(cpp_type && cpp_ptr_type->constant != "naked");
|
||||
CodeWriter cw(" ");
|
||||
cw.SetValue("FIELD", Name(field));
|
||||
cw.SetValue("TYPE", type_name);
|
||||
@@ -2091,9 +2087,7 @@ class CppGenerator : public BaseGenerator {
|
||||
// If the field is a vector of tables, the table need to be compared
|
||||
// by value, instead of by the default unique_ptr == operator which
|
||||
// compares by address.
|
||||
if (field.value.type.base_type == BASE_TYPE_VECTOR &&
|
||||
field.value.type.element == BASE_TYPE_STRUCT &&
|
||||
!field.value.type.struct_def->fixed) {
|
||||
if (IsVectorOfPointers(field)) {
|
||||
const auto type =
|
||||
GenTypeNative(field.value.type.VectorType(), true, field);
|
||||
const auto equal_length =
|
||||
@@ -2992,7 +2986,8 @@ class CppGenerator : public BaseGenerator {
|
||||
return ptype + "(new " + name + "(*" + val + "))";
|
||||
}
|
||||
} else {
|
||||
const auto ptype = GenTypeNativePtr(
|
||||
std::string ptype = afield.native_inline ? "*" : "";
|
||||
ptype += GenTypeNativePtr(
|
||||
WrapNativeNameInNameSpace(*type.struct_def, opts_), &afield,
|
||||
true);
|
||||
return ptype + "(" + val + "->UnPack(_resolver))";
|
||||
@@ -3020,7 +3015,8 @@ class CppGenerator : public BaseGenerator {
|
||||
if (field.value.type.element == BASE_TYPE_UTYPE) {
|
||||
name = StripUnionType(Name(field));
|
||||
}
|
||||
code += "{ _o->" + name + ".resize(_e->size()); ";
|
||||
const std::string vector_field = "_o->" + name;
|
||||
code += "{ " + vector_field + ".resize(_e->size()); ";
|
||||
if (!field.value.type.enum_def && !IsBool(field.value.type.element) &&
|
||||
IsOneByte(field.value.type.element)) {
|
||||
// For vectors of bytes, std::copy is used to improve performance.
|
||||
@@ -3060,7 +3056,7 @@ class CppGenerator : public BaseGenerator {
|
||||
// (*resolver)(&_o->field, (hash_value_t)(_e));
|
||||
// else
|
||||
// _o->field = nullptr;
|
||||
code += "//vector resolver, " + PtrType(&field) + "\n";
|
||||
code += "/*vector resolver, " + PtrType(&field) + "*/ ";
|
||||
code += "if (_resolver) ";
|
||||
code += "(*_resolver)";
|
||||
code += "(reinterpret_cast<void **>(&_o->" + name + "[_i]" +
|
||||
@@ -3077,27 +3073,19 @@ class CppGenerator : public BaseGenerator {
|
||||
code += "/* else do nothing */";
|
||||
}
|
||||
} else {
|
||||
// clang-format off
|
||||
#if FLATBUFFERS_CPP_OBJECT_UNPACKTO
|
||||
const bool is_pointer =
|
||||
field.value.type.VectorType().base_type == BASE_TYPE_STRUCT &&
|
||||
!IsStruct(field.value.type.VectorType());
|
||||
const bool is_pointer = IsVectorOfPointers(field);
|
||||
if (is_pointer) {
|
||||
code += "if(_o->" + name + "[_i]" + ") { ";
|
||||
code += indexing + "->UnPackTo(_o->" + name +
|
||||
"[_i].get(), _resolver);";
|
||||
code += " } else { ";
|
||||
}
|
||||
#endif
|
||||
code += "_o->" + name + "[_i]" + access + " = ";
|
||||
code += GenUnpackVal(field.value.type.VectorType(), indexing, true,
|
||||
field);
|
||||
#if FLATBUFFERS_CPP_OBJECT_UNPACKTO
|
||||
if (is_pointer) { code += "; }"; }
|
||||
#endif
|
||||
// clang-format on
|
||||
}
|
||||
code += "; } }";
|
||||
code += "; } } else { " + vector_field + ".resize(0); }";
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -3125,7 +3113,7 @@ class CppGenerator : public BaseGenerator {
|
||||
// (*resolver)(&_o->field, (hash_value_t)(_e));
|
||||
// else
|
||||
// _o->field = nullptr;
|
||||
code += "//scalar resolver, " + PtrType(&field) + " \n";
|
||||
code += "/*scalar resolver, " + PtrType(&field) + "*/ ";
|
||||
code += "if (_resolver) ";
|
||||
code += "(*_resolver)";
|
||||
code += "(reinterpret_cast<void **>(&_o->" + Name(field) + "), ";
|
||||
@@ -3142,23 +3130,21 @@ class CppGenerator : public BaseGenerator {
|
||||
} else {
|
||||
// Generate code for assigning the value, of the form:
|
||||
// _o->field = value;
|
||||
// clang-format off
|
||||
#if FLATBUFFERS_CPP_OBJECT_UNPACKTO
|
||||
const bool is_pointer =
|
||||
field.value.type.base_type == BASE_TYPE_STRUCT &&
|
||||
!IsStruct(field.value.type);
|
||||
const bool is_pointer = IsPointer(field);
|
||||
|
||||
const std::string out_field = "_o->" + Name(field);
|
||||
|
||||
if (is_pointer) {
|
||||
code += "{ if(_o->" + Name(field) + ") { ";
|
||||
code += "_e->UnPackTo(_o->" + Name(field) + ".get(), _resolver);";
|
||||
code += "{ if(" + out_field + ") { ";
|
||||
code += "_e->UnPackTo(" + out_field + ".get(), _resolver);";
|
||||
code += " } else { ";
|
||||
}
|
||||
#endif
|
||||
code += "_o->" + Name(field) + " = ";
|
||||
code += out_field + " = ";
|
||||
code += GenUnpackVal(field.value.type, "_e", false, field) + ";";
|
||||
#if FLATBUFFERS_CPP_OBJECT_UNPACKTO
|
||||
if (is_pointer) { code += " } }"; }
|
||||
#endif
|
||||
// clang-format on
|
||||
if (is_pointer) {
|
||||
code += " } } else if (" + out_field + ") { " + out_field +
|
||||
".reset(); }";
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -3264,9 +3250,13 @@ class CppGenerator : public BaseGenerator {
|
||||
code += "(" + value + ".size(), ";
|
||||
code += "[](size_t i, _VectorArgs *__va) { ";
|
||||
code += "return Create" + vector_type.struct_def->name;
|
||||
code += "(*__va->__fbb, __va->_" + value + "[i]" +
|
||||
GenPtrGet(field) + ", ";
|
||||
code += "__va->__rehasher); }, &_va )";
|
||||
code += "(*__va->__fbb, ";
|
||||
if (field.native_inline) {
|
||||
code += "&(__va->_" + value + "[i])";
|
||||
} else {
|
||||
code += "__va->_" + value + "[i]" + GenPtrGet(field);
|
||||
}
|
||||
code += ", __va->__rehasher); }, &_va )";
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -3355,8 +3345,9 @@ class CppGenerator : public BaseGenerator {
|
||||
// _o->field ? CreateT(_fbb, _o->field.get(), _rehasher);
|
||||
const auto type = field.value.type.struct_def->name;
|
||||
code += value + " ? Create" + type;
|
||||
code += "(_fbb, " + value + GenPtrGet(field) + ", _rehasher)";
|
||||
code += " : 0";
|
||||
code += "(_fbb, " + value;
|
||||
if (!field.native_inline) code += GenPtrGet(field);
|
||||
code += ", _rehasher) : 0";
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -226,7 +226,7 @@ class CSharpGenerator : public BaseGenerator {
|
||||
if (needs_includes) {
|
||||
code += "using global::System;\n";
|
||||
code += "using global::System.Collections.Generic;\n";
|
||||
code += "using global::FlatBuffers;\n\n";
|
||||
code += "using global::Google.FlatBuffers;\n\n";
|
||||
}
|
||||
code += classcode;
|
||||
if (!namespace_name.empty()) { code += "\n}\n"; }
|
||||
@@ -651,11 +651,11 @@ class CSharpGenerator : public BaseGenerator {
|
||||
code += " public ByteBuffer ByteBuffer { get { return __p.bb; } }\n";
|
||||
|
||||
if (!struct_def.fixed) {
|
||||
// Generate verson check method.
|
||||
// Generate version check method.
|
||||
// Force compile time error if not using the same version runtime.
|
||||
code += " public static void ValidateVersion() {";
|
||||
code += " FlatBufferConstants.";
|
||||
code += "FLATBUFFERS_2_0_0(); ";
|
||||
code += "FLATBUFFERS_22_9_24(); ";
|
||||
code += "}\n";
|
||||
|
||||
// Generate a special accessor for the table that when used as the root
|
||||
@@ -1307,9 +1307,9 @@ class CSharpGenerator : public BaseGenerator {
|
||||
code += "Offset<" + struct_def.name + ">";
|
||||
code += "[] offsets) {\n";
|
||||
code += " Array.Sort(offsets,\n";
|
||||
code += " (Offset<" + struct_def.name +
|
||||
"> o1, Offset<" + struct_def.name + "> o2) =>\n";
|
||||
code += " "+ GenKeyGetter(struct_def, key_field);
|
||||
code += " (Offset<" + struct_def.name + "> o1, Offset<" +
|
||||
struct_def.name + "> o2) =>\n";
|
||||
code += " " + GenKeyGetter(struct_def, key_field);
|
||||
code += ");\n";
|
||||
code += " return builder.CreateVectorOfTables(offsets);\n }\n";
|
||||
|
||||
@@ -1463,8 +1463,10 @@ class CSharpGenerator : public BaseGenerator {
|
||||
}
|
||||
code += "\n";
|
||||
// Pack()
|
||||
code += " public static int Pack(FlatBuffers.FlatBufferBuilder builder, " +
|
||||
union_name + " _o) {\n";
|
||||
code +=
|
||||
" public static int Pack(Google.FlatBuffers.FlatBufferBuilder "
|
||||
"builder, " +
|
||||
union_name + " _o) {\n";
|
||||
code += " switch (_o.Type) {\n";
|
||||
for (auto it = enum_def.Vals().begin(); it != enum_def.Vals().end(); ++it) {
|
||||
auto &ev = **it;
|
||||
|
||||
@@ -661,11 +661,11 @@ class JavaGenerator : public BaseGenerator {
|
||||
code += " {\n";
|
||||
|
||||
if (!struct_def.fixed) {
|
||||
// Generate verson check method.
|
||||
// Generate version check method.
|
||||
// Force compile time error if not using the same version runtime.
|
||||
code += " public static void ValidateVersion() {";
|
||||
code += " Constants.";
|
||||
code += "FLATBUFFERS_2_0_0(); ";
|
||||
code += "FLATBUFFERS_22_9_24(); ";
|
||||
code += "}\n";
|
||||
|
||||
// Generate a special accessor for the table that when used as the root
|
||||
@@ -1658,11 +1658,15 @@ class JavaGenerator : public BaseGenerator {
|
||||
field.value.type.struct_def == nullptr
|
||||
? "builder.add" + GenMethod(field.value.type.VectorType()) +
|
||||
"(" + variable + "[_j]);"
|
||||
: type_name + ".pack(builder, " + variable + "[_j]);";
|
||||
: "_unused_offset = " + type_name + ".pack(builder, " +
|
||||
variable + "[_j]);";
|
||||
code += " int _" + field_name + " = 0;\n";
|
||||
code += " " + element_type_name + "[] " + variable + " = _o." +
|
||||
get_field + "();\n";
|
||||
code += " if (" + variable + " != null) {\n";
|
||||
if (field.value.type.struct_def != nullptr) {
|
||||
code += " int _unused_offset = 0;\n";
|
||||
}
|
||||
code += " " + namer_.Method("start", field) +
|
||||
"Vector(builder, " + variable + ".length);\n";
|
||||
code += " for (int _j = " + variable +
|
||||
|
||||
@@ -500,12 +500,12 @@ class KotlinGenerator : public BaseGenerator {
|
||||
if (!struct_def.fixed) {
|
||||
FieldDef *key_field = nullptr;
|
||||
|
||||
// Generate verson check method.
|
||||
// Generate version check method.
|
||||
// Force compile time error if not using the same version
|
||||
// runtime.
|
||||
GenerateFunOneLine(
|
||||
writer, "validateVersion", "", "",
|
||||
[&]() { writer += "Constants.FLATBUFFERS_2_0_0()"; },
|
||||
[&]() { writer += "Constants.FLATBUFFERS_22_9_24()"; },
|
||||
options.gen_jvmstatic);
|
||||
|
||||
GenerateGetRootAsAccessors(namer_.Type(struct_def), writer, options);
|
||||
|
||||
@@ -83,11 +83,11 @@ class PythonGenerator : public BaseGenerator {
|
||||
|
||||
// Most field accessors need to retrieve and test the field offset first,
|
||||
// this is the prefix code for that.
|
||||
std::string OffsetPrefix(const FieldDef &field) const {
|
||||
std::string OffsetPrefix(const FieldDef &field, bool new_line = true) const {
|
||||
return "\n" + Indent + Indent +
|
||||
"o = flatbuffers.number_types.UOffsetTFlags.py_type" +
|
||||
"(self._tab.Offset(" + NumToString(field.value.offset) + "))\n" +
|
||||
Indent + Indent + "if o != 0:\n";
|
||||
Indent + Indent + "if o != 0:" + (new_line ? "\n" : "");
|
||||
}
|
||||
|
||||
// Begin a class declaration.
|
||||
@@ -164,9 +164,14 @@ class PythonGenerator : public BaseGenerator {
|
||||
|
||||
GenReceiver(struct_def, code_ptr);
|
||||
code += namer_.Method(field) + "Length(self";
|
||||
code += "):" + OffsetPrefix(field);
|
||||
code += Indent + Indent + Indent + "return self._tab.VectorLen(o)\n";
|
||||
code += Indent + Indent + "return 0\n\n";
|
||||
code += "):";
|
||||
if(!IsArray(field.value.type)){
|
||||
code += OffsetPrefix(field,false);
|
||||
code += GenIndents(3) + "return self._tab.VectorLen(o)";
|
||||
code += GenIndents(2) + "return 0\n\n";
|
||||
}else{
|
||||
code += GenIndents(2) + "return "+NumToString(field.value.type.fixed_length)+"\n\n";
|
||||
}
|
||||
}
|
||||
|
||||
// Determines whether a vector is none or not.
|
||||
@@ -177,10 +182,15 @@ class PythonGenerator : public BaseGenerator {
|
||||
GenReceiver(struct_def, code_ptr);
|
||||
code += namer_.Method(field) + "IsNone(self";
|
||||
code += "):";
|
||||
code += GenIndents(2) +
|
||||
"o = flatbuffers.number_types.UOffsetTFlags.py_type" +
|
||||
"(self._tab.Offset(" + NumToString(field.value.offset) + "))";
|
||||
code += GenIndents(2) + "return o == 0";
|
||||
if(!IsArray(field.value.type)){
|
||||
code += GenIndents(2) +
|
||||
"o = flatbuffers.number_types.UOffsetTFlags.py_type" +
|
||||
"(self._tab.Offset(" + NumToString(field.value.offset) + "))";
|
||||
code += GenIndents(2) + "return o == 0";
|
||||
} else {
|
||||
//assume that we always have an array as memory is preassigned
|
||||
code += GenIndents(2) + "return False";
|
||||
}
|
||||
code += "\n\n";
|
||||
}
|
||||
|
||||
@@ -244,21 +254,42 @@ class PythonGenerator : public BaseGenerator {
|
||||
const auto vec_type = field.value.type.VectorType();
|
||||
GenReceiver(struct_def, code_ptr);
|
||||
code += namer_.Method(field);
|
||||
if (IsStruct(vec_type)) {
|
||||
code += "(self, obj, i):\n";
|
||||
code += Indent + Indent + "obj.Init(self._tab.Bytes, self._tab.Pos + ";
|
||||
code += NumToString(field.value.offset) + " + i * ";
|
||||
code += NumToString(InlineSize(vec_type));
|
||||
code += ")\n" + Indent + Indent + "return obj\n\n";
|
||||
} else {
|
||||
auto getter = GenGetter(vec_type);
|
||||
code += "(self): return [" + getter;
|
||||
code += "self._tab.Pos + flatbuffers.number_types.UOffsetTFlags.py_type(";
|
||||
code += NumToString(field.value.offset) + " + i * ";
|
||||
code += NumToString(InlineSize(vec_type));
|
||||
code += ")) for i in range(";
|
||||
code += NumToString(field.value.type.fixed_length) + ")]\n";
|
||||
code += "(self, i: int):";
|
||||
if (parser_.opts.include_dependence_headers) {
|
||||
code += GenIndents(2);
|
||||
code += "from " + GenPackageReference(field.value.type) + " import " +
|
||||
TypeName(field);
|
||||
}
|
||||
code += GenIndents(2) + "obj = " + TypeName(field) + "()";
|
||||
code += GenIndents(2) + "obj.Init(self._tab.Bytes, self._tab.Pos + ";
|
||||
code += NumToString(field.value.offset) + " + i * ";
|
||||
code += NumToString(InlineSize(vec_type));
|
||||
code += ")" + GenIndents(2) + "return obj\n\n";
|
||||
}
|
||||
|
||||
// Get the value of a vector's non-struct member. Uses a named return
|
||||
// argument to conveniently set the zero value for the result.
|
||||
void GetArrayOfNonStruct(const StructDef &struct_def, const FieldDef &field,
|
||||
std::string *code_ptr) const {
|
||||
auto &code = *code_ptr;
|
||||
GenReceiver(struct_def, code_ptr);
|
||||
code += namer_.Method(field);
|
||||
code += "(self, j = None):";
|
||||
code += GenIndents(2) + "if j is None:";
|
||||
code += GenIndents(3) + "return [" + GenGetter(field.value.type);
|
||||
code += "self._tab.Pos + flatbuffers.number_types.UOffsetTFlags.py_type(";
|
||||
code += NumToString(field.value.offset) + " + i * ";
|
||||
code += NumToString(InlineSize(field.value.type.VectorType()));
|
||||
code += ")) for i in range(";
|
||||
code += "self."+namer_.Method(field)+"Length()" + ")]";
|
||||
code += GenIndents(2) +"elif j >= 0 and j < self."+namer_.Method(field)+"Length():";
|
||||
code += GenIndents(3) + "return " + GenGetter(field.value.type);
|
||||
code += "self._tab.Pos + flatbuffers.number_types.UOffsetTFlags.py_type(";
|
||||
code += NumToString(field.value.offset) + " + j * ";
|
||||
code += NumToString(InlineSize(field.value.type.VectorType()));
|
||||
code += "))";
|
||||
code += GenIndents(2) + "else:";
|
||||
code += GenIndents(3) + "return None\n\n";
|
||||
}
|
||||
|
||||
// Get a struct by initializing an existing struct.
|
||||
@@ -403,18 +434,25 @@ class PythonGenerator : public BaseGenerator {
|
||||
|
||||
GenReceiver(struct_def, code_ptr);
|
||||
code += namer_.Method(field) + "AsNumpy(self):";
|
||||
code += OffsetPrefix(field);
|
||||
if(!IsArray(field.value.type)){
|
||||
code += OffsetPrefix(field, false);
|
||||
|
||||
code += Indent + Indent + Indent;
|
||||
code += "return ";
|
||||
code += "self._tab.GetVectorAsNumpy(flatbuffers.number_types.";
|
||||
code += namer_.Method(GenTypeGet(field.value.type));
|
||||
code += "Flags, o)\n";
|
||||
code += GenIndents(3);
|
||||
code += "return ";
|
||||
code += "self._tab.GetVectorAsNumpy(flatbuffers.number_types.";
|
||||
code += namer_.Method(GenTypeGet(field.value.type));
|
||||
code += "Flags, o)";
|
||||
|
||||
if (IsString(vectortype)) {
|
||||
code += Indent + Indent + "return \"\"\n";
|
||||
} else {
|
||||
code += Indent + Indent + "return 0\n";
|
||||
if (IsString(vectortype)) {
|
||||
code += GenIndents(2) + "return \"\"\n";
|
||||
} else {
|
||||
code += GenIndents(2) + "return 0\n";
|
||||
}
|
||||
}else{
|
||||
code += GenIndents(2) + "return ";
|
||||
code += "self._tab.GetArrayAsNumpy(flatbuffers.number_types.";
|
||||
code += namer_.Method(GenTypeGet(field.value.type.VectorType()));
|
||||
code += "Flags, self._tab.Pos + "+NumToString(field.value.offset)+", "+NumToString("self."+namer_.Method(field)+"Length()")+")\n";
|
||||
}
|
||||
code += "\n";
|
||||
}
|
||||
@@ -714,8 +752,6 @@ class PythonGenerator : public BaseGenerator {
|
||||
} else {
|
||||
GetScalarFieldOfTable(struct_def, field, code_ptr);
|
||||
}
|
||||
} else if (IsArray(field.value.type)) {
|
||||
GetArrayOfStruct(struct_def, field, code_ptr);
|
||||
} else {
|
||||
switch (field.value.type.base_type) {
|
||||
case BASE_TYPE_STRUCT:
|
||||
@@ -739,6 +775,17 @@ class PythonGenerator : public BaseGenerator {
|
||||
}
|
||||
break;
|
||||
}
|
||||
case BASE_TYPE_ARRAY: {
|
||||
auto vectortype = field.value.type.VectorType();
|
||||
if (vectortype.base_type == BASE_TYPE_STRUCT) {
|
||||
GetArrayOfStruct(struct_def, field, code_ptr);
|
||||
} else {
|
||||
GetArrayOfNonStruct(struct_def, field, code_ptr);
|
||||
GetVectorOfNonStructAsNumpy(struct_def, field, code_ptr);
|
||||
GetVectorAsNestedFlatbuffer(struct_def, field, code_ptr);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case BASE_TYPE_UNION: GetUnionField(struct_def, field, code_ptr); break;
|
||||
default: FLATBUFFERS_ASSERT(0);
|
||||
}
|
||||
@@ -1061,8 +1108,9 @@ class PythonGenerator : public BaseGenerator {
|
||||
|
||||
code += GenIndents(1) + "@classmethod";
|
||||
code += GenIndents(1) + "def InitFromBuf(cls, buf, pos):";
|
||||
code += GenIndents(2) + "n = flatbuffers.encode.Get(flatbuffers.packer.uoffset, buf, 0)";
|
||||
code += GenIndents(2) + struct_var + " = " + struct_type + "()";
|
||||
code += GenIndents(2) + struct_var + ".Init(buf, pos)";
|
||||
code += GenIndents(2) + struct_var + ".Init(buf, pos+n)";
|
||||
code += GenIndents(2) + "return cls.InitFromObj(" + struct_var + ")";
|
||||
code += "\n";
|
||||
}
|
||||
@@ -1143,12 +1191,41 @@ class PythonGenerator : public BaseGenerator {
|
||||
auto field_type = TypeName(field);
|
||||
auto one_instance = field_type + "_";
|
||||
one_instance[0] = CharToLower(one_instance[0]);
|
||||
|
||||
if (parser_.opts.include_dependence_headers) {
|
||||
auto package_reference = GenPackageReference(field.value.type);
|
||||
field_type = package_reference + "." + TypeName(field);
|
||||
}
|
||||
code += GenIndents(4) + "if " + struct_var + "." + field_method +
|
||||
"(i) is None:";
|
||||
code += GenIndents(5) + "self." + field_field + ".append(None)";
|
||||
code += GenIndents(4) + "else:";
|
||||
code += GenIndents(5) + one_instance + " = " + field_type +
|
||||
"T.InitFromObj(" + struct_var + "." + field_method + "(i))";
|
||||
code +=
|
||||
GenIndents(5) + "self." + field_field + ".append(" + one_instance + ")";
|
||||
}
|
||||
|
||||
void GenUnpackForTableVector(const StructDef &struct_def,
|
||||
const FieldDef &field,
|
||||
std::string *code_ptr) const {
|
||||
auto &code = *code_ptr;
|
||||
const auto field_field = namer_.Field(field);
|
||||
const auto field_method = namer_.Method(field);
|
||||
const auto struct_var = namer_.Variable(struct_def);
|
||||
|
||||
code += GenIndents(2) + "if not " + struct_var + "." + field_method +
|
||||
"IsNone():";
|
||||
code += GenIndents(3) + "self." + field_field + " = []";
|
||||
code += GenIndents(3) + "for i in range(" + struct_var + "." +
|
||||
field_method + "Length()):";
|
||||
|
||||
auto field_type = TypeName(field);
|
||||
auto one_instance = field_type + "_";
|
||||
one_instance[0] = CharToLower(one_instance[0]);
|
||||
if (parser_.opts.include_dependence_headers) {
|
||||
auto package_reference = GenPackageReference(field.value.type);
|
||||
field_type = package_reference + "." + TypeName(field);
|
||||
}
|
||||
code += GenIndents(4) + "if " + struct_var + "." + field_method +
|
||||
"(i) is None:";
|
||||
code += GenIndents(5) + "self." + field_field + ".append(None)";
|
||||
@@ -1233,6 +1310,7 @@ class PythonGenerator : public BaseGenerator {
|
||||
GenUnPackForUnion(struct_def, field, &code);
|
||||
break;
|
||||
}
|
||||
case BASE_TYPE_ARRAY:
|
||||
case BASE_TYPE_VECTOR: {
|
||||
auto vectortype = field.value.type.VectorType();
|
||||
if (vectortype.base_type == BASE_TYPE_STRUCT) {
|
||||
@@ -1242,10 +1320,6 @@ class PythonGenerator : public BaseGenerator {
|
||||
}
|
||||
break;
|
||||
}
|
||||
case BASE_TYPE_ARRAY: {
|
||||
GenUnPackForScalarVector(struct_def, field, &code);
|
||||
break;
|
||||
}
|
||||
default: GenUnPackForScalar(struct_def, field, &code);
|
||||
}
|
||||
}
|
||||
@@ -1482,6 +1556,7 @@ class PythonGenerator : public BaseGenerator {
|
||||
GenPackForUnionField(struct_def, field, &code_prefix, &code);
|
||||
break;
|
||||
}
|
||||
case BASE_TYPE_ARRAY:
|
||||
case BASE_TYPE_VECTOR: {
|
||||
auto vectortype = field.value.type.VectorType();
|
||||
if (vectortype.base_type == BASE_TYPE_STRUCT) {
|
||||
@@ -1491,10 +1566,6 @@ class PythonGenerator : public BaseGenerator {
|
||||
}
|
||||
break;
|
||||
}
|
||||
case BASE_TYPE_ARRAY: {
|
||||
GenPackForScalarVectorField(struct_def, field, &code_prefix, &code);
|
||||
break;
|
||||
}
|
||||
case BASE_TYPE_STRING: {
|
||||
code_prefix +=
|
||||
GenIndents(2) + "if self." + field_field + " is not None:";
|
||||
@@ -1666,7 +1737,9 @@ class PythonGenerator : public BaseGenerator {
|
||||
std::string GenTypePointer(const Type &type) const {
|
||||
switch (type.base_type) {
|
||||
case BASE_TYPE_STRING: return "string";
|
||||
case BASE_TYPE_VECTOR: return GenTypeGet(type.VectorType());
|
||||
case BASE_TYPE_VECTOR:
|
||||
// fall through
|
||||
case BASE_TYPE_ARRAY: return GenTypeGet(type.VectorType());
|
||||
case BASE_TYPE_STRUCT: return type.struct_def->name;
|
||||
case BASE_TYPE_UNION:
|
||||
// fall through
|
||||
|
||||
@@ -1198,7 +1198,8 @@ class SwiftGenerator : public BaseGenerator {
|
||||
|
||||
void GenEnum(const EnumDef &enum_def) {
|
||||
if (enum_def.generated) return;
|
||||
const auto is_private_access = enum_def.attributes.Lookup("private");
|
||||
const bool is_private_access = parser_.opts.swift_implementation_only ||
|
||||
enum_def.attributes.Lookup("private") != nullptr;
|
||||
code_.SetValue("ENUM_TYPE",
|
||||
enum_def.is_union ? "UnionEnum" : "Enum, Verifiable");
|
||||
code_.SetValue("ACCESS_TYPE", is_private_access ? "internal" : "public");
|
||||
@@ -1873,7 +1874,7 @@ class SwiftGenerator : public BaseGenerator {
|
||||
}
|
||||
|
||||
std::string ValidateFunc() {
|
||||
return "static func validateVersion() { FlatBuffersVersion_2_0_0() }";
|
||||
return "static func validateVersion() { FlatBuffersVersion_22_9_24() }";
|
||||
}
|
||||
|
||||
std::string GenType(const Type &type,
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user