forked from BigfootDev/flatbuffers
Compare commits
83 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d1867fb4cf | ||
|
|
129ef422e8 | ||
|
|
e5fc3b16d8 | ||
|
|
c0d16995a4 | ||
|
|
70c8292c29 | ||
|
|
d47cd10d77 | ||
|
|
66bd3d7400 | ||
|
|
0cc1edb3ad | ||
|
|
57375a9e1c | ||
|
|
0346535221 | ||
|
|
7d62dcc422 | ||
|
|
b3cd878dfe | ||
|
|
09486a9f97 | ||
|
|
dd79eed495 | ||
|
|
0e1305c8e2 | ||
|
|
88549130e1 | ||
|
|
6dfc59dfcc | ||
|
|
5ba80c24e0 | ||
|
|
da55ac3a27 | ||
|
|
c6f9e010bb | ||
|
|
94ff188a3e | ||
|
|
5a937f1ba1 | ||
|
|
e1c3690a2a | ||
|
|
b08abbbbf6 | ||
|
|
7d6d99c6be | ||
|
|
d3055a97e7 | ||
|
|
0dc5a75dc0 | ||
|
|
f175e60998 | ||
|
|
a632c3c004 | ||
|
|
11789e41b6 | ||
|
|
a9c0845504 | ||
|
|
526c92546f | ||
|
|
eb80ead90b | ||
|
|
386b6353ed | ||
|
|
d09696bbe6 | ||
|
|
a228e8c9b8 | ||
|
|
91a3172519 | ||
|
|
e0d4562782 | ||
|
|
49677b0b70 | ||
|
|
8e34ad5db7 | ||
|
|
eb64390080 | ||
|
|
46577d0d2f | ||
|
|
32029ac699 | ||
|
|
4354945727 | ||
|
|
755573bcda | ||
|
|
205285c35c | ||
|
|
f4e23bf91e | ||
|
|
1fdb5d263a | ||
|
|
c4211538bd | ||
|
|
bcb9ef1876 | ||
|
|
c5441dc199 | ||
|
|
7f417e3397 | ||
|
|
3c35a143ea | ||
|
|
56e2bc30b0 | ||
|
|
eb40a54672 | ||
|
|
15f16f149e | ||
|
|
053d39adaf | ||
|
|
6f71b76e6f | ||
|
|
4b7d8e0df9 | ||
|
|
0def91105f | ||
|
|
8176a204fc | ||
|
|
e8b2492cf1 | ||
|
|
5d4386b1bc | ||
|
|
a6a3989dd4 | ||
|
|
696f47f1f7 | ||
|
|
a3dfcf3326 | ||
|
|
d3e8cb60a1 | ||
|
|
0343396e49 | ||
|
|
f625ff3330 | ||
|
|
362dd663f8 | ||
|
|
5a8a395756 | ||
|
|
afafd206a3 | ||
|
|
48da238920 | ||
|
|
8836ddab41 | ||
|
|
23922e7eba | ||
|
|
f8fe811d5c | ||
|
|
0cc525b722 | ||
|
|
28861d1d7d | ||
|
|
204473cdb5 | ||
|
|
85088a196d | ||
|
|
6e214c3a49 | ||
|
|
96294e9f84 | ||
|
|
b7856f8e27 |
@@ -1,5 +1,6 @@
|
||||
---
|
||||
buildifier: latest
|
||||
bazel: 6.4.0
|
||||
platforms:
|
||||
ubuntu1804:
|
||||
environment:
|
||||
|
||||
1
.github/labeler.yml
vendored
1
.github/labeler.yml
vendored
@@ -48,6 +48,7 @@ java:
|
||||
kotlin:
|
||||
- '**/*.kt'
|
||||
- src/idl_gen_kotlin.cpp
|
||||
- src/idl_gen_kotlin_kmp.cpp
|
||||
|
||||
lua:
|
||||
- '**/*.lua'
|
||||
|
||||
150
.github/workflows/build.yml
vendored
150
.github/workflows/build.yml
vendored
@@ -9,7 +9,6 @@ on:
|
||||
- "*" # new tag version, like `0.8.4` or else
|
||||
branches:
|
||||
- master
|
||||
- flatbuffers-64
|
||||
pull_request:
|
||||
branches:
|
||||
- master
|
||||
@@ -22,10 +21,10 @@ jobs:
|
||||
digests-gcc: ${{ steps.hash-gcc.outputs.hashes }}
|
||||
digests-clang: ${{ steps.hash-clang.outputs.hashes }}
|
||||
name: Build Linux
|
||||
runs-on: ubuntu-latest
|
||||
runs-on: ubuntu-22.04-64core
|
||||
strategy:
|
||||
matrix:
|
||||
cxx: [g++-10, clang++-12]
|
||||
cxx: [g++-13, clang++-15]
|
||||
fail-fast: false
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
@@ -39,10 +38,6 @@ jobs:
|
||||
run: |
|
||||
chmod +x flatc
|
||||
./flatc --version
|
||||
# - name: flatc tests
|
||||
# run: |
|
||||
# yarn global add esbuild
|
||||
# python3 tests/flatc/main.py
|
||||
- name: upload build artifacts
|
||||
uses: actions/upload-artifact@v1
|
||||
with:
|
||||
@@ -58,27 +53,29 @@ jobs:
|
||||
with:
|
||||
files: Linux.flatc.binary.${{ matrix.cxx }}.zip
|
||||
- name: Generate SLSA subjects - clang
|
||||
if: matrix.cxx == 'clang++-12' && startsWith(github.ref, 'refs/tags/')
|
||||
if: matrix.cxx == 'clang++-15' && startsWith(github.ref, 'refs/tags/')
|
||||
id: hash-clang
|
||||
run: echo "hashes=$(sha256sum Linux.flatc.binary.${{ matrix.cxx }}.zip | base64 -w0)" >> $GITHUB_OUTPUT
|
||||
- name: Generate SLSA subjects - gcc
|
||||
if: matrix.cxx == 'g++-10' && startsWith(github.ref, 'refs/tags/')
|
||||
if: matrix.cxx == 'g++-13' && startsWith(github.ref, 'refs/tags/')
|
||||
id: hash-gcc
|
||||
run: echo "hashes=$(sha256sum Linux.flatc.binary.${{ matrix.cxx }}.zip | base64 -w0)" >> $GITHUB_OUTPUT
|
||||
|
||||
build-linux-no-file-tests:
|
||||
|
||||
build-linux-no-file-tests:
|
||||
name: Build Linux with -DFLATBUFFERS_NO_FILE_TESTS
|
||||
runs-on: ubuntu-latest
|
||||
runs-on: ubuntu-22.04-64core
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- name: cmake
|
||||
run: CXX=clang++-12 cmake -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=Release -DFLATBUFFERS_STRICT_MODE=ON -DFLATBUFFERS_CXX_FLAGS="-DFLATBUFFERS_NO_FILE_TESTS" .
|
||||
run: CXX=clang++-15 cmake -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=Release -DFLATBUFFERS_STRICT_MODE=ON -DFLATBUFFERS_CXX_FLAGS="-DFLATBUFFERS_NO_FILE_TESTS" .
|
||||
- name: build
|
||||
run: make -j
|
||||
- name: test
|
||||
run: ./flattests
|
||||
|
||||
build-linux-out-of-source:
|
||||
build-linux-out-of-source:
|
||||
name: Build Linux with out-of-source build location
|
||||
runs-on: ubuntu-latest
|
||||
runs-on: ubuntu-22.04-64core
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- name: make build directory
|
||||
@@ -86,7 +83,7 @@ jobs:
|
||||
- name: cmake
|
||||
working-directory: build
|
||||
run: >
|
||||
CXX=clang++-12 cmake .. -G "Unix Makefiles" -DFLATBUFFERS_STRICT_MODE=ON
|
||||
CXX=clang++-15 cmake .. -G "Unix Makefiles" -DFLATBUFFERS_STRICT_MODE=ON
|
||||
-DFLATBUFFERS_BUILD_CPP17=ON -DFLATBUFFERS_CPP_STD=17
|
||||
- name: build
|
||||
working-directory: build
|
||||
@@ -100,22 +97,23 @@ jobs:
|
||||
|
||||
build-linux-cpp-std:
|
||||
name: Build Linux C++
|
||||
runs-on: ubuntu-latest
|
||||
runs-on: ubuntu-22.04-64core
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
std: [11, 14, 17, 20, 23]
|
||||
cxx: [g++-10, clang++-12]
|
||||
cxx: [g++-13, clang++-15]
|
||||
exclude:
|
||||
# GCC 10.3.0 doesn't support std 23
|
||||
- cxx: g++-10
|
||||
# Clang++15 10.3.0 stdlibc++ doesn't fully support std 23
|
||||
- cxx: clang++-15
|
||||
std: 23
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- name: cmake
|
||||
run: >
|
||||
CXX=${{ matrix.cxx }} cmake -G "Unix Makefiles"
|
||||
-DCMAKE_BUILD_TYPE=Release -DFLATBUFFERS_STRICT_MODE=ON
|
||||
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
|
||||
@@ -126,7 +124,7 @@ jobs:
|
||||
if: matrix.std >= 17
|
||||
run: ./flattests_cpp17
|
||||
|
||||
build-windows-cpp-std:
|
||||
build-cpp-std:
|
||||
name: Build Windows C++
|
||||
runs-on: windows-2019
|
||||
strategy:
|
||||
@@ -139,8 +137,8 @@ jobs:
|
||||
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
|
||||
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
|
||||
@@ -156,7 +154,7 @@ jobs:
|
||||
contents: write
|
||||
outputs:
|
||||
digests: ${{ steps.hash.outputs.hashes }}
|
||||
name: Build Windows 2019
|
||||
name: Build Windows 2019
|
||||
runs-on: windows-2019
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
@@ -168,8 +166,6 @@ jobs:
|
||||
run: msbuild.exe FlatBuffers.sln /p:Configuration=Release /p:Platform=x64
|
||||
- name: test
|
||||
run: Release\flattests.exe
|
||||
# - name: flatc tests
|
||||
# run: python3 tests/flatc/main.py --flatc Release\flatc.exe
|
||||
- name: upload build artifacts
|
||||
uses: actions/upload-artifact@v1
|
||||
with:
|
||||
@@ -190,42 +186,14 @@ jobs:
|
||||
shell: bash
|
||||
run: echo "hashes=$(sha256sum Windows.flatc.binary.zip | base64 -w0)" >> $GITHUB_OUTPUT
|
||||
|
||||
build-windows-2017:
|
||||
name: Build Windows 2017
|
||||
runs-on: windows-2019
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- name: Add msbuild to PATH
|
||||
uses: microsoft/setup-msbuild@v1.1
|
||||
- name: cmake
|
||||
run: cmake -G "Visual Studio 16 2019" -A x64 -DCMAKE_BUILD_TYPE=Release -DFLATBUFFERS_STRICT_MODE=ON .
|
||||
- name: build tool version 15 (VS 2017)
|
||||
run: msbuild.exe FlatBuffers.sln /p:Configuration=Release /p:Platform=x64 /p:VisualStudioVersion=15.0
|
||||
- name: test
|
||||
run: Release\flattests.exe
|
||||
|
||||
build-windows-2015:
|
||||
name: Build Windows 2015
|
||||
runs-on: windows-2019
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- name: Add msbuild to PATH
|
||||
uses: microsoft/setup-msbuild@v1.1
|
||||
- name: cmake
|
||||
run: cmake -G "Visual Studio 14 2015" -A x64 -DCMAKE_BUILD_TYPE=Release -DFLATBUFFERS_STRICT_MODE=ON .
|
||||
- name: build tool version 14 (VS 2015)
|
||||
run: msbuild.exe FlatBuffers.sln /p:Configuration=Release /p:Platform=x64 /p:VisualStudioVersion=14.0
|
||||
- name: test
|
||||
run: Release\flattests.exe
|
||||
|
||||
build-dotnet-windows:
|
||||
name: Build .NET Windows
|
||||
runs-on: windows-2019
|
||||
runs-on: windows-2022-64core
|
||||
strategy:
|
||||
matrix:
|
||||
configuration: [
|
||||
'',
|
||||
'-p:UnsafeByteBuffer=true',
|
||||
'-p:UnsafeByteBuffer=true',
|
||||
# Fails two tests currently.
|
||||
#'-p:EnableSpanT=true,UnsafeByteBuffer=true'
|
||||
]
|
||||
@@ -233,18 +201,18 @@ jobs:
|
||||
- uses: actions/checkout@v3
|
||||
- name: Setup .NET Core SDK
|
||||
uses: actions/setup-dotnet@v3
|
||||
with:
|
||||
dotnet-version: '3.1.x'
|
||||
with:
|
||||
dotnet-version: '8.0.x'
|
||||
- name: Build
|
||||
run: |
|
||||
cd tests\FlatBuffers.Test
|
||||
dotnet new sln --force --name FlatBuffers.Core.Test
|
||||
dotnet sln FlatBuffers.Core.Test.sln add FlatBuffers.Core.Test.csproj
|
||||
dotnet build -c Release ${{matrix.configuration}} -o out FlatBuffers.Core.Test.sln
|
||||
dotnet new sln --force --name FlatBuffers.Test
|
||||
dotnet sln FlatBuffers.Test.sln add FlatBuffers.Test.csproj
|
||||
dotnet build -c Release ${{matrix.configuration}} -o out FlatBuffers.Test.sln
|
||||
- name: Run
|
||||
run: |
|
||||
cd tests\FlatBuffers.Test
|
||||
out\FlatBuffers.Core.Test.exe
|
||||
out\FlatBuffers.Test.exe
|
||||
|
||||
build-mac-intel:
|
||||
permissions:
|
||||
@@ -270,8 +238,6 @@ jobs:
|
||||
run: |
|
||||
chmod +x Release/flatc
|
||||
Release/flatc --version
|
||||
# - name: flatc tests
|
||||
# run: python3 tests/flatc/main.py --flatc Release/flatc
|
||||
- name: upload build artifacts
|
||||
uses: actions/upload-artifact@v1
|
||||
with:
|
||||
@@ -336,7 +302,7 @@ jobs:
|
||||
|
||||
build-android:
|
||||
name: Build Android (on Linux)
|
||||
runs-on: ubuntu-latest
|
||||
runs-on: ubuntu-22.04-64core
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- name: set up Java
|
||||
@@ -355,10 +321,10 @@ jobs:
|
||||
|
||||
build-generator:
|
||||
name: Check Generated Code
|
||||
runs-on: ubuntu-latest
|
||||
runs-on: ubuntu-22.04-64core
|
||||
strategy:
|
||||
matrix:
|
||||
cxx: [g++-10, clang++-12]
|
||||
cxx: [g++-13, clang++-15]
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- name: cmake
|
||||
@@ -386,10 +352,10 @@ jobs:
|
||||
|
||||
build-benchmarks:
|
||||
name: Build Benchmarks (on Linux)
|
||||
runs-on: ubuntu-latest
|
||||
runs-on: ubuntu-22.04-64core
|
||||
strategy:
|
||||
matrix:
|
||||
cxx: [g++-10]
|
||||
cxx: [g++-13]
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- name: cmake
|
||||
@@ -404,7 +370,7 @@ jobs:
|
||||
|
||||
build-java:
|
||||
name: Build Java
|
||||
runs-on: ubuntu-latest
|
||||
runs-on: ubuntu-22.04-64core
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- name: test
|
||||
@@ -422,13 +388,18 @@ jobs:
|
||||
with:
|
||||
distribution: 'temurin'
|
||||
java-version: '11'
|
||||
- name: Build flatc
|
||||
run: |
|
||||
cmake -DFLATBUFFERS_BUILD_TESTS=OFF -DFLATBUFFERS_BUILD_FLATLIB=OFF -DFLATBUFFERS_BUILD_FLATHASH=OFF .
|
||||
make -j
|
||||
echo "${PWD}" >> $GITHUB_PATH
|
||||
- name: Build
|
||||
working-directory: kotlin
|
||||
run: ./gradlew clean iosX64Test macosX64Test
|
||||
run: ./gradlew clean iosSimulatorArm64Test macosX64Test macosArm64Test
|
||||
|
||||
build-kotlin-linux:
|
||||
name: Build Kotlin Linux
|
||||
runs-on: ubuntu-latest
|
||||
runs-on: ubuntu-22.04-64core
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v3
|
||||
@@ -437,6 +408,11 @@ jobs:
|
||||
distribution: 'temurin'
|
||||
java-version: '11'
|
||||
- uses: gradle/wrapper-validation-action@v1.0.5
|
||||
- name: Build flatc
|
||||
run: |
|
||||
cmake -DFLATBUFFERS_BUILD_TESTS=OFF -DFLATBUFFERS_BUILD_FLATLIB=OFF -DFLATBUFFERS_BUILD_FLATHASH=OFF .
|
||||
make -j
|
||||
echo "${PWD}" >> $GITHUB_PATH
|
||||
- name: Build
|
||||
working-directory: kotlin
|
||||
# we are using docker's version of gradle
|
||||
@@ -446,16 +422,16 @@ jobs:
|
||||
|
||||
build-rust-linux:
|
||||
name: Build Rust Linux
|
||||
runs-on: ubuntu-latest
|
||||
runs-on: ubuntu-22.04-64core
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- name: test
|
||||
working-directory: tests
|
||||
run: bash RustTest.sh
|
||||
|
||||
|
||||
build-rust-windows:
|
||||
name: Build Rust Windows
|
||||
runs-on: windows-2019
|
||||
runs-on: windows-2022-64core
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- name: test
|
||||
@@ -464,7 +440,7 @@ jobs:
|
||||
|
||||
build-python:
|
||||
name: Build Python
|
||||
runs-on: ubuntu-latest
|
||||
runs-on: ubuntu-22.04-64core
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- name: flatc
|
||||
@@ -476,7 +452,7 @@ jobs:
|
||||
|
||||
build-go:
|
||||
name: Build Go
|
||||
runs-on: ubuntu-latest
|
||||
runs-on: ubuntu-22.04-64core
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- name: flatc
|
||||
@@ -488,7 +464,7 @@ jobs:
|
||||
|
||||
build-php:
|
||||
name: Build PHP
|
||||
runs-on: ubuntu-latest
|
||||
runs-on: ubuntu-22.04-64core
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- name: flatc
|
||||
@@ -502,7 +478,7 @@ jobs:
|
||||
|
||||
build-swift:
|
||||
name: Build Swift
|
||||
runs-on: ubuntu-latest
|
||||
runs-on: ubuntu-22.04-64core
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- name: test
|
||||
@@ -513,7 +489,7 @@ jobs:
|
||||
|
||||
build-swift-wasm:
|
||||
name: Build Swift Wasm
|
||||
runs-on: ubuntu-latest
|
||||
runs-on: ubuntu-22.04-64core
|
||||
container:
|
||||
image: ghcr.io/swiftwasm/carton:0.15.3
|
||||
steps:
|
||||
@@ -526,7 +502,7 @@ jobs:
|
||||
|
||||
build-ts:
|
||||
name: Build TS
|
||||
runs-on: ubuntu-latest
|
||||
runs-on: ubuntu-22.04-64core
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- name: flatc
|
||||
@@ -544,7 +520,7 @@ jobs:
|
||||
|
||||
build-dart:
|
||||
name: Build Dart
|
||||
runs-on: ubuntu-latest
|
||||
runs-on: ubuntu-22.04-64core
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- uses: dart-lang/setup-dart@v1
|
||||
@@ -559,7 +535,7 @@ jobs:
|
||||
|
||||
build-nim:
|
||||
name: Build Nim
|
||||
runs-on: ubuntu-latest
|
||||
runs-on: ubuntu-22.04-64core
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- name: flatc
|
||||
@@ -568,7 +544,7 @@ jobs:
|
||||
- uses: jiro4989/setup-nim-action@v1
|
||||
- name: install library
|
||||
working-directory: nim
|
||||
run: nimble -y develop
|
||||
run: nimble -y develop && nimble install
|
||||
- name: test
|
||||
working-directory: tests/nim
|
||||
run: python3 testnim.py
|
||||
@@ -578,7 +554,7 @@ jobs:
|
||||
needs: [build-linux, build-windows, build-mac-intel, build-mac-universal]
|
||||
outputs:
|
||||
digests: ${{ steps.hash.outputs.digests }}
|
||||
runs-on: ubuntu-latest
|
||||
runs-on: ubuntu-22.04-64core
|
||||
steps:
|
||||
- name: Merge results
|
||||
id: hash
|
||||
|
||||
4
.github/workflows/label.yml
vendored
4
.github/workflows/label.yml
vendored
@@ -19,6 +19,6 @@ jobs:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- uses: actions/labeler@main
|
||||
- uses: actions/labeler@ee18d5d34efd9b4f7dafdb0e363cb688eb438044 # 4.1.0
|
||||
with:
|
||||
repo-token: "${{ secrets.GITHUB_TOKEN }}"
|
||||
repo-token: "${{ secrets.GITHUB_TOKEN }}"
|
||||
|
||||
35
.github/workflows/release.yml
vendored
35
.github/workflows/release.yml
vendored
@@ -10,18 +10,18 @@ on:
|
||||
jobs:
|
||||
publish-npm:
|
||||
name: Publish NPM
|
||||
runs-on: ubuntu-latest
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- uses: actions/setup-node@v3
|
||||
with:
|
||||
node-version: '16.x'
|
||||
node-version: '20.x'
|
||||
registry-url: 'https://registry.npmjs.org'
|
||||
|
||||
|
||||
- run: npm publish
|
||||
env:
|
||||
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
|
||||
|
||||
|
||||
publish-pypi:
|
||||
name: Publish PyPi
|
||||
runs-on: ubuntu-latest
|
||||
@@ -33,16 +33,16 @@ jobs:
|
||||
- uses: actions/setup-python@v4
|
||||
with:
|
||||
python-version: '3.10'
|
||||
|
||||
|
||||
- name: Install Dependencies
|
||||
run: |
|
||||
python3 -m pip install --upgrade pip
|
||||
python3 -m pip install setuptools wheel twine
|
||||
|
||||
|
||||
- name: Build
|
||||
run: |
|
||||
python3 setup.py sdist bdist_wheel
|
||||
|
||||
|
||||
- name: Upload to PyPi
|
||||
run: |
|
||||
python3 -m twine upload dist/*
|
||||
@@ -60,20 +60,19 @@ jobs:
|
||||
- uses: actions/checkout@v3
|
||||
- uses: actions/setup-dotnet@v3
|
||||
with:
|
||||
dotnet-version: '6.0.x'
|
||||
|
||||
dotnet-version: '8.0.x'
|
||||
- name: Build
|
||||
run: |
|
||||
dotnet build Google.FlatBuffers.csproj -c Release
|
||||
|
||||
|
||||
- name: Pack
|
||||
run: |
|
||||
dotnet pack Google.FlatBuffers.csproj -c Release
|
||||
|
||||
|
||||
- name: Upload to NuGet
|
||||
run: |
|
||||
dotnet nuget push .\bin\Release\Google.FlatBuffers.*.nupkg -k ${{ secrets.NUGET_API_KEY }} -s https://api.nuget.org/v3/index.json
|
||||
|
||||
dotnet nuget push .\bin\Release\Google.FlatBuffers.*.nupkg -k ${{ secrets.NUGET_API_KEY }} -s https://api.nuget.org/v3/index.json
|
||||
|
||||
publish-maven:
|
||||
name: Publish Maven
|
||||
runs-on: ubuntu-latest
|
||||
@@ -82,7 +81,7 @@ jobs:
|
||||
working-directory: ./java
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
|
||||
|
||||
- name: Set up Maven Central Repository
|
||||
uses: actions/setup-java@v3
|
||||
with:
|
||||
@@ -94,13 +93,13 @@ jobs:
|
||||
server-password: OSSRH_PASSWORD
|
||||
gpg-private-key: ${{ secrets.MAVEN_GPG_PRIVATE_KEY }}
|
||||
gpg-passphrase: MAVEN_GPG_PASSPHRASE # this needs to be an env var
|
||||
|
||||
|
||||
- name: Publish Maven
|
||||
run: mvn --batch-mode clean deploy
|
||||
env:
|
||||
OSSRH_USERNAME: ${{ secrets.OSSRH_USERNAME }}
|
||||
OSSRH_PASSWORD: ${{ secrets.OSSRH_TOKEN }}
|
||||
MAVEN_GPG_PASSPHRASE: ${{ secrets.MAVEN_GPG_PASSPHRASE }}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
8
.github/workflows/stale.yml
vendored
8
.github/workflows/stale.yml
vendored
@@ -28,10 +28,10 @@ jobs:
|
||||
days-before-issue-close: 14 # 2 weeks
|
||||
exempt-issue-labels: not-stale
|
||||
|
||||
stale-pr-message: 'This pull request is stale because it has been open 3 weeks with no activity. Please comment or label `not-stale`, or this will be closed in 7 days.'
|
||||
close-pr-message: 'This pull request was automatically closed due to no activity for 3 weeks plus the 7 day notice period.'
|
||||
days-before-pr-stale: 21 # 3 weeks
|
||||
days-before-pr-close: 7 # 1 week
|
||||
stale-pr-message: 'This pull request is stale because it has been open 6 months with no activity. Please comment or label `not-stale`, or this will be closed in 14 days.'
|
||||
close-pr-message: 'This pull request was automatically closed due to no activity for 6 months plus the 14 day notice period.'
|
||||
days-before-pr-stale: 182 # 6 months
|
||||
days-before-pr-close: 14 # 2 week
|
||||
exempt-pr-labels: not-stale
|
||||
exempt-draft-pr: false
|
||||
|
||||
|
||||
2
.gitignore
vendored
2
.gitignore
vendored
@@ -151,3 +151,5 @@ flatbuffers.pc
|
||||
# https://cmake.org/cmake/help/latest/module/FetchContent.html#variable:FETCHCONTENT_BASE_DIR
|
||||
cmake-build-debug/
|
||||
_deps/
|
||||
**/.gradle/**
|
||||
kotlin/**/generated
|
||||
|
||||
@@ -4,6 +4,10 @@ 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.
|
||||
|
||||
## [24.3.6] (March 24 2024)(https://github.com/google/flatbuffers/releases/tag/v24.3.6)
|
||||
|
||||
* Fix typescript object API to allow 0 values for null-default scalars (#7864)
|
||||
|
||||
## [23.5.26 (May 26 2023)](https://github.com/google/flatbuffers/releases/tag/v23.5.26)
|
||||
|
||||
* Mostly bug fixing for 64-bit support
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
set(VERSION_MAJOR 23)
|
||||
set(VERSION_MINOR 5)
|
||||
set(VERSION_PATCH 26)
|
||||
set(VERSION_MAJOR 24)
|
||||
set(VERSION_MINOR 3)
|
||||
set(VERSION_PATCH 6)
|
||||
set(VERSION_COMMIT 0)
|
||||
|
||||
if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/.git")
|
||||
@@ -29,7 +29,7 @@ if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/.git")
|
||||
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}")
|
||||
message(WARNING "git describe failed with exit code: ${GIT_DESCRIBE_RESULT}\nMake sure you cloned with tags or run 'git fetch --tags'.")
|
||||
endif()
|
||||
else()
|
||||
message(WARNING "git is not found")
|
||||
|
||||
@@ -160,6 +160,7 @@ set(FlatBuffers_Compiler_SRCS
|
||||
src/idl_gen_csharp.cpp
|
||||
src/idl_gen_dart.cpp
|
||||
src/idl_gen_kotlin.cpp
|
||||
src/idl_gen_kotlin_kmp.cpp
|
||||
src/idl_gen_go.cpp
|
||||
src/idl_gen_java.cpp
|
||||
src/idl_gen_ts.cpp
|
||||
@@ -496,7 +497,7 @@ function(compile_schema SRC_FBS OPT OUT_GEN_FILE)
|
||||
${OPT}
|
||||
-o "${SRC_FBS_DIR}"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/${SRC_FBS}"
|
||||
DEPENDS flatc
|
||||
DEPENDS flatc ${SRC_FBS}
|
||||
COMMENT "flatc generation: `${SRC_FBS}` -> `${GEN_HEADER}`"
|
||||
)
|
||||
set(${OUT_GEN_FILE} ${GEN_HEADER} PARENT_SCOPE)
|
||||
@@ -531,16 +532,17 @@ if(FLATBUFFERS_BUILD_TESTS)
|
||||
# The flattest target needs some generated files
|
||||
SET(FLATC_OPT --cpp --gen-mutable --gen-object-api --reflect-names)
|
||||
SET(FLATC_OPT_COMP ${FLATC_OPT};--gen-compare)
|
||||
SET(FLATC_OPT_SCOPED_ENUMS ${FLATC_OPT_COMP};--scoped-enums)
|
||||
|
||||
compile_schema_for_test(tests/alignment_test.fbs "${FLATC_OPT_COMP}")
|
||||
compile_schema_for_test(tests/arrays_test.fbs "${FLATC_OPT_COMP};--scoped-enums")
|
||||
compile_schema_for_test(tests/arrays_test.fbs "${FLATC_OPT_SCOPED_ENUMS}")
|
||||
compile_schema_for_test(tests/native_inline_table_test.fbs "${FLATC_OPT_COMP}")
|
||||
compile_schema_for_test(tests/native_type_test.fbs "${FLATC_OPT}")
|
||||
compile_schema_for_test(tests/key_field/key_field_sample.fbs "${FLATC_OPT_COMP}")
|
||||
compile_schema_for_test(tests/64bit/test_64bit.fbs "${FLATC_OPT_COMP};--bfbs-gen-embed")
|
||||
compile_schema_for_test(tests/64bit/evolution/v1.fbs "${FLATC_OPT_COMP}")
|
||||
compile_schema_for_test(tests/64bit/evolution/v2.fbs "${FLATC_OPT_COMP}")
|
||||
compile_schema_for_test(tests/union_underlying_type_test.fbs "${FLATC_OPT_COMP}")
|
||||
compile_schema_for_test(tests/union_underlying_type_test.fbs "${FLATC_OPT_SCOPED_ENUMS}")
|
||||
|
||||
if(FLATBUFFERS_CODE_SANITIZE)
|
||||
add_fsanitize_to_target(flattests ${FLATBUFFERS_CODE_SANITIZE})
|
||||
@@ -554,7 +556,11 @@ if(FLATBUFFERS_BUILD_TESTS)
|
||||
|
||||
# Add a library so there is a single target that the generated samples can
|
||||
# link too.
|
||||
add_library(flatsample INTERFACE)
|
||||
if(MSVC OR ${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.20.0")
|
||||
add_library(flatsample INTERFACE)
|
||||
else()
|
||||
add_library(flatsample STATIC)
|
||||
endif()
|
||||
|
||||
# Since flatsample has no sources, we have to explicitly set the linker lang.
|
||||
set_target_properties(flatsample PROPERTIES LINKER_LANGUAGE CXX)
|
||||
@@ -592,7 +598,7 @@ if(FLATBUFFERS_BUILD_GRPCTEST)
|
||||
find_package(protobuf CONFIG REQUIRED)
|
||||
find_package(gRPC CONFIG REQUIRED)
|
||||
add_executable(grpctest ${FlatBuffers_GRPCTest_SRCS})
|
||||
target_link_libraries(grpctext
|
||||
target_link_libraries(grpctest
|
||||
PRIVATE
|
||||
$<BUILD_INTERFACE:ProjectConfig>
|
||||
gRPC::grpc++_unsecure
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
Pod::Spec.new do |s|
|
||||
s.name = 'FlatBuffers'
|
||||
s.version = '23.5.26'
|
||||
s.version = '24.3.6'
|
||||
s.summary = 'FlatBuffers: Memory Efficient Serialization Library'
|
||||
|
||||
s.description = "FlatBuffers is a cross platform serialization library architected for
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// swift-tools-version:5.2
|
||||
// swift-tools-version:5.6
|
||||
/*
|
||||
* Copyright 2020 Google Inc. All rights reserved.
|
||||
*
|
||||
@@ -32,6 +32,5 @@ let package = Package(
|
||||
.target(
|
||||
name: "FlatBuffers",
|
||||
dependencies: [],
|
||||
path: "swift/Sources",
|
||||
exclude: ["Documentation.docc/Resources/code/swift"]),
|
||||
path: "swift/Sources"),
|
||||
])
|
||||
|
||||
@@ -98,10 +98,7 @@ FlatBuffers does not follow traditional SemVer versioning (see [rationale](https
|
||||
|
||||
## 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
|
||||
|
||||
|
||||
55
WORKSPACE
55
WORKSPACE
@@ -4,13 +4,26 @@ load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive", "http_file"
|
||||
|
||||
http_archive(
|
||||
name = "platforms",
|
||||
sha256 = "379113459b0feaf6bfbb584a91874c065078aa673222846ac765f86661c27407",
|
||||
sha256 = "3a561c99e7bdbe9173aa653fd579fe849f1d8d67395780ab4770b1f381431d51",
|
||||
urls = [
|
||||
"https://mirror.bazel.build/github.com/bazelbuild/platforms/releases/download/0.0.5/platforms-0.0.5.tar.gz",
|
||||
"https://github.com/bazelbuild/platforms/releases/download/0.0.5/platforms-0.0.5.tar.gz",
|
||||
"https://mirror.bazel.build/github.com/bazelbuild/platforms/releases/download/0.0.7/platforms-0.0.7.tar.gz",
|
||||
"https://github.com/bazelbuild/platforms/releases/download/0.0.7/platforms-0.0.7.tar.gz",
|
||||
],
|
||||
)
|
||||
|
||||
http_archive(
|
||||
name = "build_bazel_rules_apple",
|
||||
sha256 = "34c41bfb59cdaea29ac2df5a2fa79e5add609c71bb303b2ebb10985f93fa20e7",
|
||||
url = "https://github.com/bazelbuild/rules_apple/releases/download/3.1.1/rules_apple.3.1.1.tar.gz",
|
||||
)
|
||||
|
||||
load(
|
||||
"@build_bazel_rules_apple//apple:repositories.bzl",
|
||||
"apple_rules_dependencies",
|
||||
)
|
||||
|
||||
apple_rules_dependencies()
|
||||
|
||||
http_archive(
|
||||
name = "build_bazel_rules_swift",
|
||||
sha256 = "a2fd565e527f83fb3f9eb07eb9737240e668c9242d3bc318712efa54a7deda97",
|
||||
@@ -33,10 +46,10 @@ swift_rules_extra_dependencies()
|
||||
|
||||
http_archive(
|
||||
name = "io_bazel_rules_go",
|
||||
sha256 = "ae013bf35bd23234d1dea46b079f1e05ba74ac0321423830119d3e787ec73483",
|
||||
sha256 = "278b7ff5a826f3dc10f04feaf0b70d48b68748ccd512d7f98bf442077f043fe3",
|
||||
urls = [
|
||||
"https://mirror.bazel.build/github.com/bazelbuild/rules_go/releases/download/v0.36.0/rules_go-v0.36.0.zip",
|
||||
"https://github.com/bazelbuild/rules_go/releases/download/v0.36.0/rules_go-v0.36.0.zip",
|
||||
"https://mirror.bazel.build/github.com/bazelbuild/rules_go/releases/download/v0.41.0/rules_go-v0.41.0.zip",
|
||||
"https://github.com/bazelbuild/rules_go/releases/download/v0.41.0/rules_go-v0.41.0.zip",
|
||||
],
|
||||
)
|
||||
|
||||
@@ -79,9 +92,9 @@ grpc_extra_deps()
|
||||
|
||||
http_archive(
|
||||
name = "aspect_rules_js",
|
||||
sha256 = "124ed29fb0b3d0cba5b44f8f8e07897cf61b34e35e33b1f83d1a943dfd91b193",
|
||||
strip_prefix = "rules_js-1.24.0",
|
||||
url = "https://github.com/aspect-build/rules_js/releases/download/v1.24.0/rules_js-v1.24.0.tar.gz",
|
||||
sha256 = "76a04ef2120ee00231d85d1ff012ede23963733339ad8db81f590791a031f643",
|
||||
strip_prefix = "rules_js-1.34.1",
|
||||
url = "https://github.com/aspect-build/rules_js/releases/download/v1.34.1/rules_js-v1.34.1.tar.gz",
|
||||
)
|
||||
|
||||
load("@aspect_rules_js//js:repositories.bzl", "rules_js_dependencies")
|
||||
@@ -94,9 +107,9 @@ pnpm_repository(name = "pnpm")
|
||||
|
||||
http_archive(
|
||||
name = "aspect_rules_ts",
|
||||
sha256 = "8eb25d1fdafc0836f5778d33fb8eaac37c64176481d67872b54b0a05de5be5c0",
|
||||
strip_prefix = "rules_ts-1.3.3",
|
||||
url = "https://github.com/aspect-build/rules_ts/releases/download/v1.3.3/rules_ts-v1.3.3.tar.gz",
|
||||
sha256 = "4c3f34fff9f96ffc9c26635d8235a32a23a6797324486c7d23c1dfa477e8b451",
|
||||
strip_prefix = "rules_ts-1.4.5",
|
||||
url = "https://github.com/aspect-build/rules_ts/releases/download/v1.4.5/rules_ts-v1.4.5.tar.gz",
|
||||
)
|
||||
|
||||
load("@aspect_rules_ts//ts:repositories.bzl", "rules_ts_dependencies")
|
||||
@@ -104,8 +117,8 @@ load("@aspect_rules_ts//ts:repositories.bzl", "rules_ts_dependencies")
|
||||
rules_ts_dependencies(
|
||||
# Since rules_ts doesn't always have the newest integrity hashes, we
|
||||
# compute it manually here.
|
||||
# $ curl --silent https://registry.npmjs.org/typescript/5.0.4 | jq ._integrity
|
||||
ts_integrity = "sha512-cW9T5W9xY37cc+jfEnaUvX91foxtHkza3Nw3wkoF4sSlKn0MONdkdEndig/qPBWXNkmplh3NzayQzCiHM4/hqw==",
|
||||
# $ curl --silent https://registry.npmjs.org/typescript/5.3.3 | jq ._integrity
|
||||
ts_integrity = "sha512-pXWcraxM0uxAS+tN0AG/BF2TyqmHO014Z070UsJ+pFvYuRSq8KH8DmWpnbXe0pEPDHXZV3FcAbJkijJ5oNEnWw==",
|
||||
ts_version_from = "//:package.json",
|
||||
)
|
||||
|
||||
@@ -132,25 +145,25 @@ npm_repositories()
|
||||
|
||||
http_archive(
|
||||
name = "aspect_rules_esbuild",
|
||||
sha256 = "2ea31bd97181a315e048be693ddc2815fddda0f3a12ca7b7cc6e91e80f31bac7",
|
||||
strip_prefix = "rules_esbuild-0.14.4",
|
||||
url = "https://github.com/aspect-build/rules_esbuild/releases/download/v0.14.4/rules_esbuild-v0.14.4.tar.gz",
|
||||
sha256 = "098e38e5ee868c14a6484ba263b79e57d48afacfc361ba30137c757a9c4716d6",
|
||||
strip_prefix = "rules_esbuild-0.15.0",
|
||||
url = "https://github.com/aspect-build/rules_esbuild/releases/download/v0.15.0/rules_esbuild-v0.15.0.tar.gz",
|
||||
)
|
||||
|
||||
# Register a toolchain containing esbuild npm package and native bindings
|
||||
load("@aspect_rules_esbuild//esbuild:repositories.bzl", "LATEST_VERSION", "esbuild_register_toolchains")
|
||||
load("@aspect_rules_esbuild//esbuild:repositories.bzl", "LATEST_ESBUILD_VERSION", "esbuild_register_toolchains")
|
||||
|
||||
esbuild_register_toolchains(
|
||||
name = "esbuild",
|
||||
esbuild_version = LATEST_VERSION,
|
||||
esbuild_version = LATEST_ESBUILD_VERSION,
|
||||
)
|
||||
|
||||
http_file(
|
||||
name = "bazel_linux_x86_64",
|
||||
downloaded_file_path = "bazel",
|
||||
executable = True,
|
||||
sha256 = "e89747d63443e225b140d7d37ded952dacea73aaed896bca01ccd745827c6289",
|
||||
sha256 = "e78fc3394deae5408d6f49a15c7b1e615901969ecf6e50d55ef899996b0b8458",
|
||||
urls = [
|
||||
"https://github.com/bazelbuild/bazel/releases/download/6.1.2/bazel-6.1.2-linux-x86_64",
|
||||
"https://github.com/bazelbuild/bazel/releases/download/6.3.2/bazel-6.3.2-linux-x86_64",
|
||||
],
|
||||
)
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
</natures>
|
||||
<filteredResources>
|
||||
<filter>
|
||||
<id>1677235311958</id>
|
||||
<id>1672434305228</id>
|
||||
<name></name>
|
||||
<type>30</type>
|
||||
<matcher>
|
||||
|
||||
@@ -57,7 +57,7 @@ class Animal : Table() {
|
||||
return if(o != 0) bb.getShort(o + bb_pos).toUShort() else 0u
|
||||
}
|
||||
companion object {
|
||||
fun validateVersion() = Constants.FLATBUFFERS_23_5_26()
|
||||
fun validateVersion() = Constants.FLATBUFFERS_24_3_6()
|
||||
fun getRootAsAnimal(_bb: ByteBuffer): Animal = getRootAsAnimal(_bb, Animal())
|
||||
fun getRootAsAnimal(_bb: ByteBuffer, obj: Animal): Animal {
|
||||
_bb.order(ByteOrder.LITTLE_ENDIAN)
|
||||
|
||||
@@ -0,0 +1,181 @@
|
||||
/*
|
||||
* Copyright 2023 Google Inc. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import Benchmark
|
||||
import CoreFoundation
|
||||
import FlatBuffers
|
||||
|
||||
@usableFromInline
|
||||
struct AA: NativeStruct {
|
||||
public init(a: Double, b: Double) {
|
||||
self.a = a
|
||||
self.b = b
|
||||
}
|
||||
var a: Double
|
||||
var b: Double
|
||||
}
|
||||
|
||||
let benchmarks = {
|
||||
let ints: [Int] = Array(repeating: 42, count: 100)
|
||||
let bytes: [UInt8] = Array(repeating: 42, count: 100)
|
||||
let str10 = (0...9).map { _ -> String in "x" }.joined()
|
||||
let str100 = (0...99).map { _ -> String in "x" }.joined()
|
||||
let array: [AA] = [
|
||||
AA(a: 2.4, b: 2.4),
|
||||
AA(a: 2.4, b: 2.4),
|
||||
AA(a: 2.4, b: 2.4),
|
||||
AA(a: 2.4, b: 2.4),
|
||||
AA(a: 2.4, b: 2.4),
|
||||
]
|
||||
|
||||
let metrics: [BenchmarkMetric] = [
|
||||
.cpuTotal,
|
||||
.wallClock,
|
||||
.mallocCountTotal,
|
||||
.releaseCount,
|
||||
.peakMemoryResident,
|
||||
]
|
||||
let maxIterations = 1_000_000
|
||||
let maxDuration: Duration = .seconds(3)
|
||||
let singleConfiguration: Benchmark.Configuration = .init(
|
||||
metrics: metrics,
|
||||
warmupIterations: 1,
|
||||
scalingFactor: .one,
|
||||
maxDuration: maxDuration,
|
||||
maxIterations: maxIterations)
|
||||
let kiloConfiguration: Benchmark.Configuration = .init(
|
||||
metrics: metrics,
|
||||
warmupIterations: 1,
|
||||
scalingFactor: .kilo,
|
||||
maxDuration: maxDuration,
|
||||
maxIterations: maxIterations)
|
||||
let megaConfiguration: Benchmark.Configuration = .init(
|
||||
metrics: metrics,
|
||||
warmupIterations: 1,
|
||||
scalingFactor: .mega,
|
||||
maxDuration: maxDuration,
|
||||
maxIterations: maxIterations)
|
||||
|
||||
Benchmark.defaultConfiguration = megaConfiguration
|
||||
|
||||
Benchmark("Allocating 1GB", configuration: singleConfiguration) { benchmark in
|
||||
for _ in benchmark.scaledIterations {
|
||||
blackHole(FlatBufferBuilder(initialSize: 1_024_000_000))
|
||||
}
|
||||
}
|
||||
|
||||
Benchmark("Clearing 1GB", configuration: singleConfiguration) { benchmark in
|
||||
var fb = FlatBufferBuilder(initialSize: 1_024_000_000)
|
||||
benchmark.startMeasurement()
|
||||
for _ in benchmark.scaledIterations {
|
||||
blackHole(fb.clear())
|
||||
}
|
||||
}
|
||||
|
||||
Benchmark("Strings 10") { benchmark in
|
||||
var fb = FlatBufferBuilder(initialSize: 1<<20)
|
||||
benchmark.startMeasurement()
|
||||
for _ in benchmark.scaledIterations {
|
||||
blackHole(fb.create(string: str10))
|
||||
}
|
||||
}
|
||||
|
||||
Benchmark("Strings 100") { benchmark in
|
||||
var fb = FlatBufferBuilder(initialSize: 1<<20)
|
||||
benchmark.startMeasurement()
|
||||
for _ in benchmark.scaledIterations {
|
||||
blackHole(fb.create(string: str100))
|
||||
}
|
||||
}
|
||||
|
||||
Benchmark("Vector 1 Bytes") { benchmark in
|
||||
var fb = FlatBufferBuilder(initialSize: 1<<20)
|
||||
benchmark.startMeasurement()
|
||||
for _ in benchmark.scaledIterations {
|
||||
blackHole(fb.createVector(bytes: bytes))
|
||||
}
|
||||
}
|
||||
|
||||
Benchmark("Vector 1 Ints") { benchmark in
|
||||
var fb = FlatBufferBuilder(initialSize: 1<<20)
|
||||
benchmark.startMeasurement()
|
||||
for _ in benchmark.scaledIterations {
|
||||
blackHole(fb.createVector(ints))
|
||||
}
|
||||
}
|
||||
|
||||
Benchmark("Vector 100 Ints") { benchmark in
|
||||
var fb = FlatBufferBuilder(initialSize: 1<<20)
|
||||
benchmark.startMeasurement()
|
||||
for i in benchmark.scaledIterations {
|
||||
blackHole(fb.createVector(ints))
|
||||
}
|
||||
}
|
||||
|
||||
Benchmark("Vector 100 Bytes") { benchmark in
|
||||
var fb = FlatBufferBuilder(initialSize: 1<<20)
|
||||
benchmark.startMeasurement()
|
||||
for i in benchmark.scaledIterations {
|
||||
blackHole(fb.createVector(bytes))
|
||||
}
|
||||
}
|
||||
|
||||
Benchmark("Vector 100 ContiguousBytes") { benchmark in
|
||||
var fb = FlatBufferBuilder(initialSize: 1<<20)
|
||||
benchmark.startMeasurement()
|
||||
for i in benchmark.scaledIterations {
|
||||
blackHole(fb.createVector(bytes: bytes))
|
||||
}
|
||||
}
|
||||
|
||||
Benchmark(
|
||||
"FlatBufferBuilder Add",
|
||||
configuration: kiloConfiguration)
|
||||
{ benchmark in
|
||||
var fb = FlatBufferBuilder(initialSize: 1024 * 1024 * 32)
|
||||
benchmark.startMeasurement()
|
||||
for _ in benchmark.scaledIterations {
|
||||
let off = fb.create(string: "T")
|
||||
let s = fb.startTable(with: 4)
|
||||
fb.add(element: 3.2, def: 0, at: 2)
|
||||
fb.add(element: 4.2, def: 0, at: 4)
|
||||
fb.add(element: 5.2, def: 0, at: 6)
|
||||
fb.add(offset: off, at: 8)
|
||||
blackHole(fb.endTable(at: s))
|
||||
}
|
||||
}
|
||||
|
||||
Benchmark("Structs") { benchmark in
|
||||
let rawSize = ((16 * 5) * benchmark.scaledIterations.count) / 1024
|
||||
var fb = FlatBufferBuilder(initialSize: Int32(rawSize * 1600))
|
||||
var offsets: [Offset] = []
|
||||
|
||||
benchmark.startMeasurement()
|
||||
for _ in benchmark.scaledIterations {
|
||||
let vector = fb.createVector(
|
||||
ofStructs: array)
|
||||
let start = fb.startTable(with: 1)
|
||||
fb.add(offset: vector, at: 4)
|
||||
offsets.append(Offset(offset: fb.endTable(at: start)))
|
||||
}
|
||||
|
||||
let vector = fb.createVector(ofOffsets: offsets)
|
||||
let start = fb.startTable(with: 1)
|
||||
fb.add(offset: vector, at: 4)
|
||||
let root = Offset(offset: fb.endTable(at: start))
|
||||
fb.finish(offset: root)
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
// swift-tools-version:5.1
|
||||
// swift-tools-version:5.8
|
||||
/*
|
||||
* Copyright 2020 Google Inc. All rights reserved.
|
||||
*
|
||||
@@ -20,15 +20,23 @@ import PackageDescription
|
||||
let package = Package(
|
||||
name: "benchmarks",
|
||||
platforms: [
|
||||
.macOS(.v10_14),
|
||||
.macOS(.v13),
|
||||
],
|
||||
dependencies: [
|
||||
.package(path: "../../.."),
|
||||
.package(url: "https://github.com/google/swift-benchmark", from: "0.1.0"),
|
||||
.package(path: "../.."),
|
||||
.package(
|
||||
url: "https://github.com/ordo-one/package-benchmark",
|
||||
from: "1.12.0"),
|
||||
],
|
||||
targets: [
|
||||
.target(
|
||||
name: "benchmarks",
|
||||
dependencies: ["FlatBuffers",
|
||||
.product(name: "Benchmark", package: "swift-benchmark")]),
|
||||
.executableTarget(
|
||||
name: "FlatbuffersBenchmarks",
|
||||
dependencies: [
|
||||
.product(name: "FlatBuffers", package: "flatbuffers"),
|
||||
.product(name: "Benchmark", package: "package-benchmark"),
|
||||
],
|
||||
path: "Benchmarks/FlatbuffersBenchmarks",
|
||||
plugins: [
|
||||
.plugin(name: "BenchmarkPlugin", package: "package-benchmark"),
|
||||
]),
|
||||
])
|
||||
9
benchmarks/swift/README.md
Normal file
9
benchmarks/swift/README.md
Normal file
@@ -0,0 +1,9 @@
|
||||
# Benchmarks
|
||||
|
||||
To open the benchmarks in xcode use:
|
||||
|
||||
`open --env BENCHMARK_DISABLE_JEMALLOC=true Package.swift`
|
||||
|
||||
or running them directly within terminal using:
|
||||
|
||||
`swift package benchmark`
|
||||
@@ -87,6 +87,7 @@ def flatbuffer_library_public(
|
||||
optionally a Fileset([reflection_name]) with all generated reflection
|
||||
binaries.
|
||||
"""
|
||||
reflection_include_paths = include_paths
|
||||
if include_paths == None:
|
||||
include_paths = default_include_paths(flatc_path)
|
||||
include_paths_cmd = ["-I %s" % (s) for s in include_paths]
|
||||
@@ -124,13 +125,16 @@ def flatbuffer_library_public(
|
||||
**kwargs
|
||||
)
|
||||
if reflection_name:
|
||||
if reflection_include_paths == None:
|
||||
reflection_include_paths = default_include_paths(TRUE_FLATC_PATH)
|
||||
reflection_include_paths_cmd = ["-I %s" % (s) for s in reflection_include_paths]
|
||||
reflection_genrule_cmd = " ".join([
|
||||
"SRCS=($(SRCS));",
|
||||
"for f in $${SRCS[@]:0:%s}; do" % len(srcs),
|
||||
"$(location %s)" % (TRUE_FLATC_PATH),
|
||||
"-b --schema",
|
||||
" ".join(flatc_args),
|
||||
" ".join(include_paths_cmd),
|
||||
" ".join(reflection_include_paths_cmd),
|
||||
language_flag,
|
||||
output_directory,
|
||||
"$$f;",
|
||||
|
||||
@@ -1,3 +1,17 @@
|
||||
# Changelog
|
||||
|
||||
## 23.5.26
|
||||
|
||||
- omit type annotationes for local variables (#7067, #7069, #7070)
|
||||
- remove BSD 3-clause license (#7073)
|
||||
- correctly parse lists of enums (#7157)
|
||||
- align naming conventions for generated code (#7187)
|
||||
- add `putBool` to fix errors when serializing structs with booleans (#7359)
|
||||
- fix handling of +/-inf defaults in codegen (#7588)
|
||||
- fix import issues in generated code (#7621)
|
||||
- Fix incorrect storage of floats as ints in some cases (#7703)
|
||||
- add final modifiers to the library implementation (#7943)
|
||||
|
||||
## 2.0.5
|
||||
|
||||
- switch to null safety (#6696)
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
This package is used to read and write [FlatBuffers](https://google.github.io/flatbuffers/).
|
||||
|
||||
Most consumers will want to use the [`flatc` - FlatBuffer compiler](https://github.com/google/flatbuffers) binary for your platform.
|
||||
You can find it in the `generator/{Platform}` directory of the [released package archive](https://pub.dev/packages/flat_buffers/versions/2.0.5.tar.gz).
|
||||
You can download the flatc version matching your dart package version from [GitHub releases](https://github.com/google/flatbuffers/releases).
|
||||
|
||||
The FlatBuffer compiler `flatc` reads a FlatBuffers IDL schema and generates Dart code.
|
||||
The generated classes can be used to read or write binary data/files that are interoperable with
|
||||
@@ -13,11 +13,3 @@ examples folder.
|
||||
For more details and documentation, head over to the official site and read the
|
||||
[Tutorial](https://google.github.io/flatbuffers/flatbuffers_guide_tutorial.html) and how to
|
||||
[use FlatBuffers in Dart](https://google.github.io/flatbuffers/flatbuffers_guide_use_dart.html).
|
||||
|
||||
## Dart 2.0 notes
|
||||
Version 2.0.5 ships with it's own custom build of `flatc` because this is an extraordinary release to catch-up
|
||||
with FlatBuffers for other platforms. This generator can only generate dart code (to avoid generating code for other platforms which isn't released yet).
|
||||
On the other hand, the generated code still produces standard binary FlatBuffers compatible with other languages.
|
||||
In other words: only `flatc --dart ...` works with this generator, but your app will be able to produce and read standard binary (`Uint8List`) FlatBuffers that are fully compotible with other languages supporting FlatBuffers (e.g. Java, C++, ...).
|
||||
|
||||
In the future a common `flatc` binary for all platforms would be shipped through GitHub release page instead.
|
||||
|
||||
@@ -1,15 +1,14 @@
|
||||
name: flat_buffers
|
||||
version: 23.5.26
|
||||
version: 24.3.6
|
||||
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
|
||||
|
||||
environment:
|
||||
sdk: '>=2.12.0 <3.0.0'
|
||||
sdk: '>=2.12.0 <4.0.0'
|
||||
|
||||
dev_dependencies:
|
||||
test: ^1.17.7
|
||||
test_reflective_loader: ^0.2.0
|
||||
path: ^1.8.0
|
||||
lints: ^1.0.1
|
||||
|
||||
|
||||
@@ -11,7 +11,6 @@ import './monster_test_my_game.example_generated.dart' as example;
|
||||
import './monster_test_my_game.example2_generated.dart' as example2;
|
||||
import './list_of_enums_generated.dart' as example3;
|
||||
import './bool_structs_generated.dart' as example4;
|
||||
import './keyword_test_keyword_test_generated.dart' as keyword_test;
|
||||
|
||||
main() {
|
||||
defineReflectiveSuite(() {
|
||||
@@ -62,92 +61,91 @@ class CheckOtherLangaugesData {
|
||||
|
||||
// this will fail if accessing any field fails.
|
||||
expect(
|
||||
mon.toString(),
|
||||
'Monster{'
|
||||
'pos: Vec3{x: 1.0, y: 2.0, z: 3.0, test1: 3.0, test2: Color{value: 2}, test3: Test{a: 5, b: 6}}, '
|
||||
'mana: 150, hp: 80, name: MyMonster, inventory: [0, 1, 2, 3, 4], '
|
||||
'color: Color{value: 8}, testType: AnyTypeId{value: 1}, '
|
||||
'test: Monster{pos: null, mana: 150, hp: 100, name: Fred, '
|
||||
'inventory: null, color: Color{value: 8}, testType: null, '
|
||||
'test: null, test4: null, testarrayofstring: null, '
|
||||
'testarrayoftables: null, enemy: null, testnestedflatbuffer: null, '
|
||||
'testempty: null, testbool: false, testhashs32Fnv1: 0, '
|
||||
'testhashu32Fnv1: 0, testhashs64Fnv1: 0, testhashu64Fnv1: 0, '
|
||||
'testhashs32Fnv1a: 0, testhashu32Fnv1a: 0, testhashs64Fnv1a: 0, '
|
||||
'testhashu64Fnv1a: 0, testarrayofbools: null, testf: 3.14159, '
|
||||
'testf2: 3.0, testf3: 0.0, testarrayofstring2: null, '
|
||||
'testarrayofsortedstruct: null, flex: null, test5: null, '
|
||||
'vectorOfLongs: null, vectorOfDoubles: null, parentNamespaceTest: null, '
|
||||
'vectorOfReferrables: null, singleWeakReference: 0, '
|
||||
'vectorOfWeakReferences: null, vectorOfStrongReferrables: null, '
|
||||
'coOwningReference: 0, vectorOfCoOwningReferences: null, '
|
||||
'nonOwningReference: 0, vectorOfNonOwningReferences: null, '
|
||||
'anyUniqueType: null, anyUnique: null, anyAmbiguousType: null, '
|
||||
'anyAmbiguous: null, vectorOfEnums: null, signedEnum: Race{value: -1}, '
|
||||
'testrequirednestedflatbuffer: null, scalarKeySortedTables: null, '
|
||||
'nativeInline: null, '
|
||||
'longEnumNonEnumDefault: LongEnum{value: 0}, '
|
||||
'longEnumNormalDefault: LongEnum{value: 2}, nanDefault: NaN, '
|
||||
'infDefault: Infinity, positiveInfDefault: Infinity, infinityDefault: '
|
||||
'Infinity, positiveInfinityDefault: Infinity, negativeInfDefault: '
|
||||
'-Infinity, negativeInfinityDefault: -Infinity, doubleInfDefault: Infinity}, '
|
||||
'test4: [Test{a: 10, b: 20}, Test{a: 30, b: 40}], '
|
||||
'testarrayofstring: [test1, test2], testarrayoftables: null, '
|
||||
'enemy: Monster{pos: null, mana: 150, hp: 100, name: Fred, '
|
||||
'inventory: null, color: Color{value: 8}, testType: null, '
|
||||
'test: null, test4: null, testarrayofstring: null, '
|
||||
'testarrayoftables: null, enemy: null, testnestedflatbuffer: null, '
|
||||
'testempty: null, testbool: false, testhashs32Fnv1: 0, '
|
||||
'testhashu32Fnv1: 0, testhashs64Fnv1: 0, testhashu64Fnv1: 0, '
|
||||
'testhashs32Fnv1a: 0, testhashu32Fnv1a: 0, testhashs64Fnv1a: 0, '
|
||||
'testhashu64Fnv1a: 0, testarrayofbools: null, testf: 3.14159, '
|
||||
'testf2: 3.0, testf3: 0.0, testarrayofstring2: null, '
|
||||
'testarrayofsortedstruct: null, flex: null, test5: null, '
|
||||
'vectorOfLongs: null, vectorOfDoubles: null, parentNamespaceTest: null, '
|
||||
'vectorOfReferrables: null, singleWeakReference: 0, '
|
||||
'vectorOfWeakReferences: null, vectorOfStrongReferrables: null, '
|
||||
'coOwningReference: 0, vectorOfCoOwningReferences: null, '
|
||||
'nonOwningReference: 0, vectorOfNonOwningReferences: null, '
|
||||
'anyUniqueType: null, anyUnique: null, anyAmbiguousType: null, '
|
||||
'anyAmbiguous: null, vectorOfEnums: null, signedEnum: Race{value: -1}, '
|
||||
'testrequirednestedflatbuffer: null, scalarKeySortedTables: null, '
|
||||
'nativeInline: null, '
|
||||
'longEnumNonEnumDefault: LongEnum{value: 0}, '
|
||||
'longEnumNormalDefault: LongEnum{value: 2}, nanDefault: NaN, '
|
||||
'infDefault: Infinity, positiveInfDefault: Infinity, infinityDefault: '
|
||||
'Infinity, positiveInfinityDefault: Infinity, negativeInfDefault: '
|
||||
'-Infinity, negativeInfinityDefault: -Infinity, doubleInfDefault: Infinity}, '
|
||||
'testnestedflatbuffer: null, testempty: null, testbool: true, '
|
||||
'testhashs32Fnv1: -579221183, testhashu32Fnv1: 3715746113, '
|
||||
'testhashs64Fnv1: 7930699090847568257, '
|
||||
'testhashu64Fnv1: 7930699090847568257, '
|
||||
'testhashs32Fnv1a: -1904106383, testhashu32Fnv1a: 2390860913, '
|
||||
'testhashs64Fnv1a: 4898026182817603057, '
|
||||
'testhashu64Fnv1a: 4898026182817603057, '
|
||||
'testarrayofbools: [true, false, true], testf: 3.14159, testf2: 3.0, '
|
||||
'testf3: 0.0, testarrayofstring2: null, testarrayofsortedstruct: ['
|
||||
'Ability{id: 0, distance: 45}, Ability{id: 1, distance: 21}, '
|
||||
'Ability{id: 5, distance: 12}], '
|
||||
'flex: null, test5: [Test{a: 10, b: 20}, Test{a: 30, b: 40}], '
|
||||
'vectorOfLongs: [1, 100, 10000, 1000000, 100000000], '
|
||||
'vectorOfDoubles: [-1.7976931348623157e+308, 0.0, 1.7976931348623157e+308], '
|
||||
'parentNamespaceTest: null, vectorOfReferrables: null, '
|
||||
'singleWeakReference: 0, vectorOfWeakReferences: null, '
|
||||
'vectorOfStrongReferrables: null, coOwningReference: 0, '
|
||||
'vectorOfCoOwningReferences: null, nonOwningReference: 0, '
|
||||
'vectorOfNonOwningReferences: null, '
|
||||
'anyUniqueType: null, anyUnique: null, '
|
||||
'anyAmbiguousType: null, '
|
||||
'anyAmbiguous: null, vectorOfEnums: null, signedEnum: Race{value: -1}, '
|
||||
'testrequirednestedflatbuffer: null, scalarKeySortedTables: [Stat{id: '
|
||||
'miss, val: 0, count: 0}, Stat{id: hit, val: 10, count: 1}], '
|
||||
'nativeInline: Test{a: 1, b: 2}, '
|
||||
'longEnumNonEnumDefault: LongEnum{value: 0}, '
|
||||
'longEnumNormalDefault: LongEnum{value: 2}, nanDefault: NaN, '
|
||||
'infDefault: Infinity, positiveInfDefault: Infinity, infinityDefault: '
|
||||
'Infinity, positiveInfinityDefault: Infinity, negativeInfDefault: '
|
||||
'-Infinity, negativeInfinityDefault: -Infinity, doubleInfDefault: Infinity}'
|
||||
);
|
||||
mon.toString(),
|
||||
'Monster{'
|
||||
'pos: Vec3{x: 1.0, y: 2.0, z: 3.0, test1: 3.0, test2: Color{value: 2}, test3: Test{a: 5, b: 6}}, '
|
||||
'mana: 150, hp: 80, name: MyMonster, inventory: [0, 1, 2, 3, 4], '
|
||||
'color: Color{value: 8}, testType: AnyTypeId{value: 1}, '
|
||||
'test: Monster{pos: null, mana: 150, hp: 100, name: Fred, '
|
||||
'inventory: null, color: Color{value: 8}, testType: null, '
|
||||
'test: null, test4: null, testarrayofstring: null, '
|
||||
'testarrayoftables: null, enemy: null, testnestedflatbuffer: null, '
|
||||
'testempty: null, testbool: false, testhashs32Fnv1: 0, '
|
||||
'testhashu32Fnv1: 0, testhashs64Fnv1: 0, testhashu64Fnv1: 0, '
|
||||
'testhashs32Fnv1a: 0, testhashu32Fnv1a: 0, testhashs64Fnv1a: 0, '
|
||||
'testhashu64Fnv1a: 0, testarrayofbools: null, testf: 3.14159, '
|
||||
'testf2: 3.0, testf3: 0.0, testarrayofstring2: null, '
|
||||
'testarrayofsortedstruct: null, flex: null, test5: null, '
|
||||
'vectorOfLongs: null, vectorOfDoubles: null, parentNamespaceTest: null, '
|
||||
'vectorOfReferrables: null, singleWeakReference: 0, '
|
||||
'vectorOfWeakReferences: null, vectorOfStrongReferrables: null, '
|
||||
'coOwningReference: 0, vectorOfCoOwningReferences: null, '
|
||||
'nonOwningReference: 0, vectorOfNonOwningReferences: null, '
|
||||
'anyUniqueType: null, anyUnique: null, anyAmbiguousType: null, '
|
||||
'anyAmbiguous: null, vectorOfEnums: null, signedEnum: Race{value: -1}, '
|
||||
'testrequirednestedflatbuffer: null, scalarKeySortedTables: null, '
|
||||
'nativeInline: null, '
|
||||
'longEnumNonEnumDefault: LongEnum{value: 0}, '
|
||||
'longEnumNormalDefault: LongEnum{value: 2}, nanDefault: NaN, '
|
||||
'infDefault: Infinity, positiveInfDefault: Infinity, infinityDefault: '
|
||||
'Infinity, positiveInfinityDefault: Infinity, negativeInfDefault: '
|
||||
'-Infinity, negativeInfinityDefault: -Infinity, doubleInfDefault: Infinity}, '
|
||||
'test4: [Test{a: 10, b: 20}, Test{a: 30, b: 40}], '
|
||||
'testarrayofstring: [test1, test2], testarrayoftables: null, '
|
||||
'enemy: Monster{pos: null, mana: 150, hp: 100, name: Fred, '
|
||||
'inventory: null, color: Color{value: 8}, testType: null, '
|
||||
'test: null, test4: null, testarrayofstring: null, '
|
||||
'testarrayoftables: null, enemy: null, testnestedflatbuffer: null, '
|
||||
'testempty: null, testbool: false, testhashs32Fnv1: 0, '
|
||||
'testhashu32Fnv1: 0, testhashs64Fnv1: 0, testhashu64Fnv1: 0, '
|
||||
'testhashs32Fnv1a: 0, testhashu32Fnv1a: 0, testhashs64Fnv1a: 0, '
|
||||
'testhashu64Fnv1a: 0, testarrayofbools: null, testf: 3.14159, '
|
||||
'testf2: 3.0, testf3: 0.0, testarrayofstring2: null, '
|
||||
'testarrayofsortedstruct: null, flex: null, test5: null, '
|
||||
'vectorOfLongs: null, vectorOfDoubles: null, parentNamespaceTest: null, '
|
||||
'vectorOfReferrables: null, singleWeakReference: 0, '
|
||||
'vectorOfWeakReferences: null, vectorOfStrongReferrables: null, '
|
||||
'coOwningReference: 0, vectorOfCoOwningReferences: null, '
|
||||
'nonOwningReference: 0, vectorOfNonOwningReferences: null, '
|
||||
'anyUniqueType: null, anyUnique: null, anyAmbiguousType: null, '
|
||||
'anyAmbiguous: null, vectorOfEnums: null, signedEnum: Race{value: -1}, '
|
||||
'testrequirednestedflatbuffer: null, scalarKeySortedTables: null, '
|
||||
'nativeInline: null, '
|
||||
'longEnumNonEnumDefault: LongEnum{value: 0}, '
|
||||
'longEnumNormalDefault: LongEnum{value: 2}, nanDefault: NaN, '
|
||||
'infDefault: Infinity, positiveInfDefault: Infinity, infinityDefault: '
|
||||
'Infinity, positiveInfinityDefault: Infinity, negativeInfDefault: '
|
||||
'-Infinity, negativeInfinityDefault: -Infinity, doubleInfDefault: Infinity}, '
|
||||
'testnestedflatbuffer: null, testempty: null, testbool: true, '
|
||||
'testhashs32Fnv1: -579221183, testhashu32Fnv1: 3715746113, '
|
||||
'testhashs64Fnv1: 7930699090847568257, '
|
||||
'testhashu64Fnv1: 7930699090847568257, '
|
||||
'testhashs32Fnv1a: -1904106383, testhashu32Fnv1a: 2390860913, '
|
||||
'testhashs64Fnv1a: 4898026182817603057, '
|
||||
'testhashu64Fnv1a: 4898026182817603057, '
|
||||
'testarrayofbools: [true, false, true], testf: 3.14159, testf2: 3.0, '
|
||||
'testf3: 0.0, testarrayofstring2: null, testarrayofsortedstruct: ['
|
||||
'Ability{id: 0, distance: 45}, Ability{id: 1, distance: 21}, '
|
||||
'Ability{id: 5, distance: 12}], '
|
||||
'flex: null, test5: [Test{a: 10, b: 20}, Test{a: 30, b: 40}], '
|
||||
'vectorOfLongs: [1, 100, 10000, 1000000, 100000000], '
|
||||
'vectorOfDoubles: [-1.7976931348623157e+308, 0.0, 1.7976931348623157e+308], '
|
||||
'parentNamespaceTest: null, vectorOfReferrables: null, '
|
||||
'singleWeakReference: 0, vectorOfWeakReferences: null, '
|
||||
'vectorOfStrongReferrables: null, coOwningReference: 0, '
|
||||
'vectorOfCoOwningReferences: null, nonOwningReference: 0, '
|
||||
'vectorOfNonOwningReferences: null, '
|
||||
'anyUniqueType: null, anyUnique: null, '
|
||||
'anyAmbiguousType: null, '
|
||||
'anyAmbiguous: null, vectorOfEnums: null, signedEnum: Race{value: -1}, '
|
||||
'testrequirednestedflatbuffer: null, scalarKeySortedTables: [Stat{id: '
|
||||
'miss, val: 0, count: 0}, Stat{id: hit, val: 10, count: 1}], '
|
||||
'nativeInline: Test{a: 1, b: 2}, '
|
||||
'longEnumNonEnumDefault: LongEnum{value: 0}, '
|
||||
'longEnumNormalDefault: LongEnum{value: 2}, nanDefault: NaN, '
|
||||
'infDefault: Infinity, positiveInfDefault: Infinity, infinityDefault: '
|
||||
'Infinity, positiveInfinityDefault: Infinity, negativeInfDefault: '
|
||||
'-Infinity, negativeInfinityDefault: -Infinity, doubleInfDefault: Infinity}');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -769,7 +767,6 @@ class BuilderTest {
|
||||
class ObjectAPITest {
|
||||
void test_tableStat() {
|
||||
final object1 = example.StatT(count: 3, id: "foo", val: 4);
|
||||
expect(object1 is Packable, isTrue);
|
||||
final fbb = Builder();
|
||||
fbb.finish(object1.pack(fbb));
|
||||
final object2 = example.Stat(fbb.buffer).unpack();
|
||||
|
||||
@@ -59,8 +59,6 @@ struct Vec3 (force_align: 8) {
|
||||
test3:Test;
|
||||
}
|
||||
|
||||
// Stats for monster
|
||||
|
||||
struct Ability {
|
||||
id:uint(key);
|
||||
distance:uint;
|
||||
|
||||
@@ -23,31 +23,35 @@ For any schema input files, one or more generators can be specified:
|
||||
|
||||
- `--java`, `-j` : Generate Java code.
|
||||
|
||||
- `--kotlin`, `-k` : Generate Kotlin code.
|
||||
- `--kotlin` , `--kotlin-kmp` : Generate Kotlin code.
|
||||
|
||||
- `--csharp`, `-n` : Generate C# code.
|
||||
|
||||
- `--go`, `-g` : Generate Go code.
|
||||
|
||||
- `--python`, `-p`: Generate Python code.
|
||||
- `--python`, `-p` : Generate Python code.
|
||||
|
||||
- `--js`, `-s`: Generate JavaScript code.
|
||||
- `--js`, `-s` : Generate JavaScript code.
|
||||
|
||||
- `--ts`: Generate TypeScript code.
|
||||
- `--ts`, `-T` : Generate TypeScript code.
|
||||
|
||||
- `--php`: Generate PHP code.
|
||||
- `--php` : Generate PHP code.
|
||||
|
||||
- `--grpc`: Generate RPC stub code for GRPC.
|
||||
- `--grpc` : Generate RPC stub code for GRPC.
|
||||
|
||||
- `--dart`: Generate Dart code.
|
||||
- `--dart`, `-d` : Generate Dart code.
|
||||
|
||||
- `--lua`: Generate Lua code.
|
||||
- `--lua`, `-l` : Generate Lua code.
|
||||
|
||||
- `--lobster`: Generate Lobster code.
|
||||
- `--lobster` : Generate Lobster code.
|
||||
|
||||
- `--rust`, `-r` : Generate Rust code.
|
||||
|
||||
- `--swift`: Generate Swift code.
|
||||
- `--swift` : Generate Swift code.
|
||||
|
||||
- `--nim` : Generate Nim code.
|
||||
|
||||
|
||||
|
||||
For any data input files:
|
||||
|
||||
@@ -58,6 +62,8 @@ For any data input files:
|
||||
- `--json`, `-t` : If data is contained in this file, generate a
|
||||
`filename.json` representing the data in the flatbuffer.
|
||||
|
||||
- `--jsonschema` : Generate Json schema
|
||||
|
||||
Additional options:
|
||||
|
||||
- `-o PATH` : Output all generated files to PATH (either absolute, or
|
||||
@@ -115,7 +121,7 @@ Additional options:
|
||||
|
||||
- `--gen-compare` : Generate operator== for object-based API types.
|
||||
|
||||
- `--gen-nullable` : Add Clang _Nullable for C++ pointer. or @Nullable for Java.
|
||||
- `--gen-nullable` : Add Clang \_Nullable for C++ pointer. or @Nullable for Java.
|
||||
|
||||
- `--gen-generated` : Add @Generated annotation for Java.
|
||||
|
||||
@@ -189,7 +195,7 @@ Additional options:
|
||||
`--conform PATH`.
|
||||
|
||||
- `--filename-suffix SUFFIX` : The suffix appended to the generated
|
||||
file names. Default is '_generated'.
|
||||
file names. Default is '\_generated'.
|
||||
|
||||
- `--filename-ext EXTENSION` : The extension appended to the generated
|
||||
file names. Default is language-specific (e.g. "h" for C++). This
|
||||
@@ -227,5 +233,10 @@ Additional options:
|
||||
vector of bytes in JSON, which is unsafe unless checked by a verifier
|
||||
afterwards.
|
||||
|
||||
- `--python-no-type-prefix-suffix` : Skip emission of Python functions that are prefixed
|
||||
with typenames
|
||||
|
||||
- `--python-typing` : Generate Python type annotations
|
||||
|
||||
NOTE: short-form options for generators are deprecated, use the long form
|
||||
whenever possible.
|
||||
|
||||
@@ -24,17 +24,14 @@ FlatBuffers).
|
||||
## Building the FlatBuffers C# library
|
||||
|
||||
The `FlatBuffers.csproj` project contains multitargeting for .NET Standard 2.1,
|
||||
.NET Standard 2.0, and .NET Framework 4.6 (Unity 2017). Support for .NET
|
||||
Framework 3.5 (Unity 5) is provided by the `FlatBuffers.net35.csproj` project.
|
||||
In most cases (including Unity 2018 and newer), .NET Standard 2.0 is
|
||||
recommended.
|
||||
.NET 6 and .NET 8.
|
||||
|
||||
You can build for a specific framework target when using the cross-platform
|
||||
[.NET Core SDK](https://dotnet.microsoft.com/download) by adding the `-f`
|
||||
command line option:
|
||||
|
||||
~~~{.sh}
|
||||
dotnet build -f netstandard2.0 "FlatBuffers.csproj"
|
||||
dotnet build -f netstandard2.1 "FlatBuffers.csproj"
|
||||
~~~
|
||||
|
||||
The `FlatBuffers.csproj` project also provides support for defining various
|
||||
@@ -142,10 +139,10 @@ To use it:
|
||||
`ByKey` only works if the vector has been sorted, it will
|
||||
likely not find elements if it hasn't been sorted.
|
||||
|
||||
## Buffer verification
|
||||
## Buffer verification
|
||||
|
||||
As mentioned in [C++ Usage](@ref flatbuffers_guide_use_cpp) buffer
|
||||
accessor functions do not verify buffer offsets at run-time.
|
||||
accessor functions do not verify buffer offsets at run-time.
|
||||
If it is necessary, you can optionally use a buffer verifier before you
|
||||
access the data. This verifier will check all offsets, all sizes of
|
||||
fields, and null termination of strings to ensure that when a buffer
|
||||
@@ -158,17 +155,17 @@ e.g. `Monster.VerifyMonster`. This can be called as shown:
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
if `ok` is true, the buffer is safe to read.
|
||||
|
||||
For a more detailed control of verification `MonsterVerify.Verify`
|
||||
for `Monster` type can be used:
|
||||
For a more detailed control of verification `MonsterVerify.Verify`
|
||||
for `Monster` type can be used:
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cs}
|
||||
# Sequence of calls
|
||||
FlatBuffers.Verifier verifier = new FlatBuffers.Verifier(buf);
|
||||
var ok = verifier.VerifyBuffer("MONS", false, MonsterVerify.Verify);
|
||||
|
||||
# Or single line call
|
||||
|
||||
# Or single line call
|
||||
var ok = new FlatBuffers.Verifier(bb).setStringCheck(true).\
|
||||
VerifyBuffer("MONS", false, MonsterVerify.Verify);
|
||||
|
||||
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
if `ok` is true, the buffer is safe to read.
|
||||
|
||||
@@ -181,7 +178,7 @@ Verifier supports options that can be set using appropriate fluent methods:
|
||||
* SetMaxTables - total amount of tables the verifier may encounter. Default: 64
|
||||
* SetAlignmentCheck - check content alignment. Default: True
|
||||
* SetStringCheck - check if strings contain termination '0' character. Default: true
|
||||
|
||||
|
||||
|
||||
## Text parsing
|
||||
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
// automatically generated by the FlatBuffers compiler, do not modify
|
||||
|
||||
|
||||
#ifndef FLATBUFFERS_GENERATED_BASIC_H_
|
||||
#define FLATBUFFERS_GENERATED_BASIC_H_
|
||||
#ifndef FLATBUFFERS_GENERATED_BASIC_FLATBUFFERS_GOLDENS_H_
|
||||
#define FLATBUFFERS_GENERATED_BASIC_FLATBUFFERS_GOLDENS_H_
|
||||
|
||||
#include "flatbuffers/flatbuffers.h"
|
||||
|
||||
@@ -10,9 +10,12 @@
|
||||
// generated, otherwise it may not be compatible.
|
||||
static_assert(FLATBUFFERS_VERSION_MAJOR == 23 &&
|
||||
FLATBUFFERS_VERSION_MINOR == 5 &&
|
||||
FLATBUFFERS_VERSION_REVISION == 9,
|
||||
FLATBUFFERS_VERSION_REVISION == 26,
|
||||
"Non-compatible flatbuffers version included");
|
||||
|
||||
namespace flatbuffers {
|
||||
namespace goldens {
|
||||
|
||||
struct Galaxy;
|
||||
struct GalaxyBuilder;
|
||||
|
||||
@@ -69,8 +72,8 @@ struct Universe FLATBUFFERS_FINAL_CLASS : private ::flatbuffers::Table {
|
||||
double age() const {
|
||||
return GetField<double>(VT_AGE, 0.0);
|
||||
}
|
||||
const ::flatbuffers::Vector<::flatbuffers::Offset<Galaxy>> *galaxies() const {
|
||||
return GetPointer<const ::flatbuffers::Vector<::flatbuffers::Offset<Galaxy>> *>(VT_GALAXIES);
|
||||
const ::flatbuffers::Vector<::flatbuffers::Offset<flatbuffers::goldens::Galaxy>> *galaxies() const {
|
||||
return GetPointer<const ::flatbuffers::Vector<::flatbuffers::Offset<flatbuffers::goldens::Galaxy>> *>(VT_GALAXIES);
|
||||
}
|
||||
bool Verify(::flatbuffers::Verifier &verifier) const {
|
||||
return VerifyTableStart(verifier) &&
|
||||
@@ -89,7 +92,7 @@ struct UniverseBuilder {
|
||||
void add_age(double age) {
|
||||
fbb_.AddElement<double>(Universe::VT_AGE, age, 0.0);
|
||||
}
|
||||
void add_galaxies(::flatbuffers::Offset<::flatbuffers::Vector<::flatbuffers::Offset<Galaxy>>> galaxies) {
|
||||
void add_galaxies(::flatbuffers::Offset<::flatbuffers::Vector<::flatbuffers::Offset<flatbuffers::goldens::Galaxy>>> galaxies) {
|
||||
fbb_.AddOffset(Universe::VT_GALAXIES, galaxies);
|
||||
}
|
||||
explicit UniverseBuilder(::flatbuffers::FlatBufferBuilder &_fbb)
|
||||
@@ -106,7 +109,7 @@ struct UniverseBuilder {
|
||||
inline ::flatbuffers::Offset<Universe> CreateUniverse(
|
||||
::flatbuffers::FlatBufferBuilder &_fbb,
|
||||
double age = 0.0,
|
||||
::flatbuffers::Offset<::flatbuffers::Vector<::flatbuffers::Offset<Galaxy>>> galaxies = 0) {
|
||||
::flatbuffers::Offset<::flatbuffers::Vector<::flatbuffers::Offset<flatbuffers::goldens::Galaxy>>> galaxies = 0) {
|
||||
UniverseBuilder builder_(_fbb);
|
||||
builder_.add_age(age);
|
||||
builder_.add_galaxies(galaxies);
|
||||
@@ -116,42 +119,45 @@ inline ::flatbuffers::Offset<Universe> CreateUniverse(
|
||||
inline ::flatbuffers::Offset<Universe> CreateUniverseDirect(
|
||||
::flatbuffers::FlatBufferBuilder &_fbb,
|
||||
double age = 0.0,
|
||||
const std::vector<::flatbuffers::Offset<Galaxy>> *galaxies = nullptr) {
|
||||
auto galaxies__ = galaxies ? _fbb.CreateVector<::flatbuffers::Offset<Galaxy>>(*galaxies) : 0;
|
||||
return CreateUniverse(
|
||||
const std::vector<::flatbuffers::Offset<flatbuffers::goldens::Galaxy>> *galaxies = nullptr) {
|
||||
auto galaxies__ = galaxies ? _fbb.CreateVector<::flatbuffers::Offset<flatbuffers::goldens::Galaxy>>(*galaxies) : 0;
|
||||
return flatbuffers::goldens::CreateUniverse(
|
||||
_fbb,
|
||||
age,
|
||||
galaxies__);
|
||||
}
|
||||
|
||||
inline const Universe *GetUniverse(const void *buf) {
|
||||
return ::flatbuffers::GetRoot<Universe>(buf);
|
||||
inline const flatbuffers::goldens::Universe *GetUniverse(const void *buf) {
|
||||
return ::flatbuffers::GetRoot<flatbuffers::goldens::Universe>(buf);
|
||||
}
|
||||
|
||||
inline const Universe *GetSizePrefixedUniverse(const void *buf) {
|
||||
return ::flatbuffers::GetSizePrefixedRoot<Universe>(buf);
|
||||
inline const flatbuffers::goldens::Universe *GetSizePrefixedUniverse(const void *buf) {
|
||||
return ::flatbuffers::GetSizePrefixedRoot<flatbuffers::goldens::Universe>(buf);
|
||||
}
|
||||
|
||||
inline bool VerifyUniverseBuffer(
|
||||
::flatbuffers::Verifier &verifier) {
|
||||
return verifier.VerifyBuffer<Universe>(nullptr);
|
||||
return verifier.VerifyBuffer<flatbuffers::goldens::Universe>(nullptr);
|
||||
}
|
||||
|
||||
inline bool VerifySizePrefixedUniverseBuffer(
|
||||
::flatbuffers::Verifier &verifier) {
|
||||
return verifier.VerifySizePrefixedBuffer<Universe>(nullptr);
|
||||
return verifier.VerifySizePrefixedBuffer<flatbuffers::goldens::Universe>(nullptr);
|
||||
}
|
||||
|
||||
inline void FinishUniverseBuffer(
|
||||
::flatbuffers::FlatBufferBuilder &fbb,
|
||||
::flatbuffers::Offset<Universe> root) {
|
||||
::flatbuffers::Offset<flatbuffers::goldens::Universe> root) {
|
||||
fbb.Finish(root);
|
||||
}
|
||||
|
||||
inline void FinishSizePrefixedUniverseBuffer(
|
||||
::flatbuffers::FlatBufferBuilder &fbb,
|
||||
::flatbuffers::Offset<Universe> root) {
|
||||
::flatbuffers::Offset<flatbuffers::goldens::Universe> root) {
|
||||
fbb.FinishSizePrefixed(root);
|
||||
}
|
||||
|
||||
#endif // FLATBUFFERS_GENERATED_BASIC_H_
|
||||
} // namespace goldens
|
||||
} // namespace flatbuffers
|
||||
|
||||
#endif // FLATBUFFERS_GENERATED_BASIC_FLATBUFFERS_GOLDENS_H_
|
||||
|
||||
@@ -2,6 +2,9 @@
|
||||
// automatically generated by the FlatBuffers compiler, do not modify
|
||||
// </auto-generated>
|
||||
|
||||
namespace flatbuffers.goldens
|
||||
{
|
||||
|
||||
using global::System;
|
||||
using global::System.Collections.Generic;
|
||||
using global::Google.FlatBuffers;
|
||||
@@ -10,7 +13,7 @@ public struct Galaxy : IFlatbufferObject
|
||||
{
|
||||
private Table __p;
|
||||
public ByteBuffer ByteBuffer { get { return __p.bb; } }
|
||||
public static void ValidateVersion() { FlatBufferConstants.FLATBUFFERS_23_5_26(); }
|
||||
public static void ValidateVersion() { FlatBufferConstants.FLATBUFFERS_24_3_6(); }
|
||||
public static Galaxy GetRootAsGalaxy(ByteBuffer _bb) { return GetRootAsGalaxy(_bb, new Galaxy()); }
|
||||
public static Galaxy GetRootAsGalaxy(ByteBuffer _bb, Galaxy obj) { return (obj.__assign(_bb.GetInt(_bb.Position) + _bb.Position, _bb)); }
|
||||
public void __init(int _i, ByteBuffer _bb) { __p = new Table(_i, _bb); }
|
||||
@@ -18,7 +21,7 @@ public struct Galaxy : IFlatbufferObject
|
||||
|
||||
public long NumStars { get { int o = __p.__offset(4); return o != 0 ? __p.bb.GetLong(o + __p.bb_pos) : (long)0; } }
|
||||
|
||||
public static Offset<Galaxy> CreateGalaxy(FlatBufferBuilder builder,
|
||||
public static Offset<flatbuffers.goldens.Galaxy> CreateGalaxy(FlatBufferBuilder builder,
|
||||
long num_stars = 0) {
|
||||
builder.StartTable(1);
|
||||
Galaxy.AddNumStars(builder, num_stars);
|
||||
@@ -27,9 +30,9 @@ public struct Galaxy : IFlatbufferObject
|
||||
|
||||
public static void StartGalaxy(FlatBufferBuilder builder) { builder.StartTable(1); }
|
||||
public static void AddNumStars(FlatBufferBuilder builder, long numStars) { builder.AddLong(0, numStars, 0); }
|
||||
public static Offset<Galaxy> EndGalaxy(FlatBufferBuilder builder) {
|
||||
public static Offset<flatbuffers.goldens.Galaxy> EndGalaxy(FlatBufferBuilder builder) {
|
||||
int o = builder.EndTable();
|
||||
return new Offset<Galaxy>(o);
|
||||
return new Offset<flatbuffers.goldens.Galaxy>(o);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -43,3 +46,5 @@ static public class GalaxyVerify
|
||||
&& verifier.VerifyTableEnd(tablePos);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -2,6 +2,9 @@
|
||||
// automatically generated by the FlatBuffers compiler, do not modify
|
||||
// </auto-generated>
|
||||
|
||||
namespace flatbuffers.goldens
|
||||
{
|
||||
|
||||
using global::System;
|
||||
using global::System.Collections.Generic;
|
||||
using global::Google.FlatBuffers;
|
||||
@@ -10,7 +13,7 @@ public struct Universe : IFlatbufferObject
|
||||
{
|
||||
private Table __p;
|
||||
public ByteBuffer ByteBuffer { get { return __p.bb; } }
|
||||
public static void ValidateVersion() { FlatBufferConstants.FLATBUFFERS_23_5_26(); }
|
||||
public static void ValidateVersion() { FlatBufferConstants.FLATBUFFERS_24_3_6(); }
|
||||
public static Universe GetRootAsUniverse(ByteBuffer _bb) { return GetRootAsUniverse(_bb, new Universe()); }
|
||||
public static Universe GetRootAsUniverse(ByteBuffer _bb, Universe obj) { return (obj.__assign(_bb.GetInt(_bb.Position) + _bb.Position, _bb)); }
|
||||
public static bool VerifyUniverse(ByteBuffer _bb) {Google.FlatBuffers.Verifier verifier = new Google.FlatBuffers.Verifier(_bb); return verifier.VerifyBuffer("", false, UniverseVerify.Verify); }
|
||||
@@ -18,10 +21,10 @@ public struct Universe : IFlatbufferObject
|
||||
public Universe __assign(int _i, ByteBuffer _bb) { __init(_i, _bb); return this; }
|
||||
|
||||
public double Age { get { int o = __p.__offset(4); return o != 0 ? __p.bb.GetDouble(o + __p.bb_pos) : (double)0.0; } }
|
||||
public Galaxy? Galaxies(int j) { int o = __p.__offset(6); return o != 0 ? (Galaxy?)(new Galaxy()).__assign(__p.__indirect(__p.__vector(o) + j * 4), __p.bb) : null; }
|
||||
public flatbuffers.goldens.Galaxy? Galaxies(int j) { int o = __p.__offset(6); return o != 0 ? (flatbuffers.goldens.Galaxy?)(new flatbuffers.goldens.Galaxy()).__assign(__p.__indirect(__p.__vector(o) + j * 4), __p.bb) : null; }
|
||||
public int GalaxiesLength { get { int o = __p.__offset(6); return o != 0 ? __p.__vector_len(o) : 0; } }
|
||||
|
||||
public static Offset<Universe> CreateUniverse(FlatBufferBuilder builder,
|
||||
public static Offset<flatbuffers.goldens.Universe> CreateUniverse(FlatBufferBuilder builder,
|
||||
double age = 0.0,
|
||||
VectorOffset galaxiesOffset = default(VectorOffset)) {
|
||||
builder.StartTable(2);
|
||||
@@ -33,17 +36,17 @@ public struct Universe : IFlatbufferObject
|
||||
public static void StartUniverse(FlatBufferBuilder builder) { builder.StartTable(2); }
|
||||
public static void AddAge(FlatBufferBuilder builder, double age) { builder.AddDouble(0, age, 0.0); }
|
||||
public static void AddGalaxies(FlatBufferBuilder builder, VectorOffset galaxiesOffset) { builder.AddOffset(1, galaxiesOffset.Value, 0); }
|
||||
public static VectorOffset CreateGalaxiesVector(FlatBufferBuilder builder, Offset<Galaxy>[] data) { builder.StartVector(4, data.Length, 4); for (int i = data.Length - 1; i >= 0; i--) builder.AddOffset(data[i].Value); return builder.EndVector(); }
|
||||
public static VectorOffset CreateGalaxiesVectorBlock(FlatBufferBuilder builder, Offset<Galaxy>[] data) { builder.StartVector(4, data.Length, 4); builder.Add(data); return builder.EndVector(); }
|
||||
public static VectorOffset CreateGalaxiesVectorBlock(FlatBufferBuilder builder, ArraySegment<Offset<Galaxy>> data) { builder.StartVector(4, data.Count, 4); builder.Add(data); return builder.EndVector(); }
|
||||
public static VectorOffset CreateGalaxiesVectorBlock(FlatBufferBuilder builder, IntPtr dataPtr, int sizeInBytes) { builder.StartVector(1, sizeInBytes, 1); builder.Add<Offset<Galaxy>>(dataPtr, sizeInBytes); return builder.EndVector(); }
|
||||
public static VectorOffset CreateGalaxiesVector(FlatBufferBuilder builder, Offset<flatbuffers.goldens.Galaxy>[] data) { builder.StartVector(4, data.Length, 4); for (int i = data.Length - 1; i >= 0; i--) builder.AddOffset(data[i].Value); return builder.EndVector(); }
|
||||
public static VectorOffset CreateGalaxiesVectorBlock(FlatBufferBuilder builder, Offset<flatbuffers.goldens.Galaxy>[] data) { builder.StartVector(4, data.Length, 4); builder.Add(data); return builder.EndVector(); }
|
||||
public static VectorOffset CreateGalaxiesVectorBlock(FlatBufferBuilder builder, ArraySegment<Offset<flatbuffers.goldens.Galaxy>> data) { builder.StartVector(4, data.Count, 4); builder.Add(data); return builder.EndVector(); }
|
||||
public static VectorOffset CreateGalaxiesVectorBlock(FlatBufferBuilder builder, IntPtr dataPtr, int sizeInBytes) { builder.StartVector(1, sizeInBytes, 1); builder.Add<Offset<flatbuffers.goldens.Galaxy>>(dataPtr, sizeInBytes); return builder.EndVector(); }
|
||||
public static void StartGalaxiesVector(FlatBufferBuilder builder, int numElems) { builder.StartVector(4, numElems, 4); }
|
||||
public static Offset<Universe> EndUniverse(FlatBufferBuilder builder) {
|
||||
public static Offset<flatbuffers.goldens.Universe> EndUniverse(FlatBufferBuilder builder) {
|
||||
int o = builder.EndTable();
|
||||
return new Offset<Universe>(o);
|
||||
return new Offset<flatbuffers.goldens.Universe>(o);
|
||||
}
|
||||
public static void FinishUniverseBuffer(FlatBufferBuilder builder, Offset<Universe> offset) { builder.Finish(offset.Value); }
|
||||
public static void FinishSizePrefixedUniverseBuffer(FlatBufferBuilder builder, Offset<Universe> offset) { builder.FinishSizePrefixed(offset.Value); }
|
||||
public static void FinishUniverseBuffer(FlatBufferBuilder builder, Offset<flatbuffers.goldens.Universe> offset) { builder.Finish(offset.Value); }
|
||||
public static void FinishSizePrefixedUniverseBuffer(FlatBufferBuilder builder, Offset<flatbuffers.goldens.Universe> offset) { builder.FinishSizePrefixed(offset.Value); }
|
||||
}
|
||||
|
||||
|
||||
@@ -53,7 +56,9 @@ static public class UniverseVerify
|
||||
{
|
||||
return verifier.VerifyTableStart(tablePos)
|
||||
&& verifier.VerifyField(tablePos, 4 /*Age*/, 8 /*double*/, 8, false)
|
||||
&& verifier.VerifyVectorOfTables(tablePos, 6 /*Galaxies*/, GalaxyVerify.Verify, false)
|
||||
&& verifier.VerifyVectorOfTables(tablePos, 6 /*Galaxies*/, flatbuffers.goldens.GalaxyVerify.Verify, false)
|
||||
&& verifier.VerifyTableEnd(tablePos);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,6 +1,8 @@
|
||||
// automatically generated by the FlatBuffers compiler, do not modify
|
||||
// ignore_for_file: unused_import, unused_field, unused_element, unused_local_variable
|
||||
|
||||
library flatbuffers.goldens;
|
||||
|
||||
import 'dart:typed_data' show Uint8List;
|
||||
import 'package:flat_buffers/flat_buffers.dart' as fb;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
// Code generated by the FlatBuffers compiler. DO NOT EDIT.
|
||||
|
||||
package Galaxy
|
||||
package goldens
|
||||
|
||||
import (
|
||||
flatbuffers "github.com/google/flatbuffers/go"
|
||||
@@ -1,6 +1,6 @@
|
||||
// Code generated by the FlatBuffers compiler. DO NOT EDIT.
|
||||
|
||||
package Universe
|
||||
package goldens
|
||||
|
||||
import (
|
||||
flatbuffers "github.com/google/flatbuffers/go"
|
||||
@@ -1,5 +1,7 @@
|
||||
// automatically generated by the FlatBuffers compiler, do not modify
|
||||
|
||||
package flatbuffers.goldens;
|
||||
|
||||
import com.google.flatbuffers.BaseVector;
|
||||
import com.google.flatbuffers.BooleanVector;
|
||||
import com.google.flatbuffers.ByteVector;
|
||||
@@ -19,7 +21,7 @@ import java.nio.ByteOrder;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public final class Galaxy extends Table {
|
||||
public static void ValidateVersion() { Constants.FLATBUFFERS_23_5_26(); }
|
||||
public static void ValidateVersion() { Constants.FLATBUFFERS_24_3_6(); }
|
||||
public static Galaxy getRootAsGalaxy(ByteBuffer _bb) { return getRootAsGalaxy(_bb, new Galaxy()); }
|
||||
public static Galaxy getRootAsGalaxy(ByteBuffer _bb, Galaxy obj) { _bb.order(ByteOrder.LITTLE_ENDIAN); return (obj.__assign(_bb.getInt(_bb.position()) + _bb.position(), _bb)); }
|
||||
public void __init(int _i, ByteBuffer _bb) { __reset(_i, _bb); }
|
||||
@@ -1,5 +1,7 @@
|
||||
// automatically generated by the FlatBuffers compiler, do not modify
|
||||
|
||||
package flatbuffers.goldens;
|
||||
|
||||
import com.google.flatbuffers.BaseVector;
|
||||
import com.google.flatbuffers.BooleanVector;
|
||||
import com.google.flatbuffers.ByteVector;
|
||||
@@ -19,18 +21,18 @@ import java.nio.ByteOrder;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public final class Universe extends Table {
|
||||
public static void ValidateVersion() { Constants.FLATBUFFERS_23_5_26(); }
|
||||
public static void ValidateVersion() { Constants.FLATBUFFERS_24_3_6(); }
|
||||
public static Universe getRootAsUniverse(ByteBuffer _bb) { return getRootAsUniverse(_bb, new Universe()); }
|
||||
public static Universe getRootAsUniverse(ByteBuffer _bb, Universe obj) { _bb.order(ByteOrder.LITTLE_ENDIAN); return (obj.__assign(_bb.getInt(_bb.position()) + _bb.position(), _bb)); }
|
||||
public void __init(int _i, ByteBuffer _bb) { __reset(_i, _bb); }
|
||||
public Universe __assign(int _i, ByteBuffer _bb) { __init(_i, _bb); return this; }
|
||||
|
||||
public double age() { int o = __offset(4); return o != 0 ? bb.getDouble(o + bb_pos) : 0.0; }
|
||||
public Galaxy galaxies(int j) { return galaxies(new Galaxy(), j); }
|
||||
public Galaxy galaxies(Galaxy obj, int j) { int o = __offset(6); return o != 0 ? obj.__assign(__indirect(__vector(o) + j * 4), bb) : null; }
|
||||
public flatbuffers.goldens.Galaxy galaxies(int j) { return galaxies(new flatbuffers.goldens.Galaxy(), j); }
|
||||
public flatbuffers.goldens.Galaxy galaxies(flatbuffers.goldens.Galaxy obj, int j) { int o = __offset(6); return o != 0 ? obj.__assign(__indirect(__vector(o) + j * 4), bb) : null; }
|
||||
public int galaxiesLength() { int o = __offset(6); return o != 0 ? __vector_len(o) : 0; }
|
||||
public Galaxy.Vector galaxiesVector() { return galaxiesVector(new Galaxy.Vector()); }
|
||||
public Galaxy.Vector galaxiesVector(Galaxy.Vector obj) { int o = __offset(6); return o != 0 ? obj.__assign(__vector(o), 4, bb) : null; }
|
||||
public flatbuffers.goldens.Galaxy.Vector galaxiesVector() { return galaxiesVector(new flatbuffers.goldens.Galaxy.Vector()); }
|
||||
public flatbuffers.goldens.Galaxy.Vector galaxiesVector(flatbuffers.goldens.Galaxy.Vector obj) { int o = __offset(6); return o != 0 ? obj.__assign(__vector(o), 4, bb) : null; }
|
||||
|
||||
public static int createUniverse(FlatBufferBuilder builder,
|
||||
double age,
|
||||
@@ -1,5 +1,7 @@
|
||||
// automatically generated by the FlatBuffers compiler, do not modify
|
||||
|
||||
package flatbuffers.goldens
|
||||
|
||||
import com.google.flatbuffers.BaseVector
|
||||
import com.google.flatbuffers.BooleanVector
|
||||
import com.google.flatbuffers.ByteVector
|
||||
@@ -32,7 +34,7 @@ class Galaxy : Table() {
|
||||
return if(o != 0) bb.getLong(o + bb_pos) else 0L
|
||||
}
|
||||
companion object {
|
||||
fun validateVersion() = Constants.FLATBUFFERS_23_5_26()
|
||||
fun validateVersion() = Constants.FLATBUFFERS_24_3_6()
|
||||
fun getRootAsGalaxy(_bb: ByteBuffer): Galaxy = getRootAsGalaxy(_bb, Galaxy())
|
||||
fun getRootAsGalaxy(_bb: ByteBuffer, obj: Galaxy): Galaxy {
|
||||
_bb.order(ByteOrder.LITTLE_ENDIAN)
|
||||
@@ -1,5 +1,7 @@
|
||||
// automatically generated by the FlatBuffers compiler, do not modify
|
||||
|
||||
package flatbuffers.goldens
|
||||
|
||||
import com.google.flatbuffers.BaseVector
|
||||
import com.google.flatbuffers.BooleanVector
|
||||
import com.google.flatbuffers.ByteVector
|
||||
@@ -31,8 +33,8 @@ class Universe : Table() {
|
||||
val o = __offset(4)
|
||||
return if(o != 0) bb.getDouble(o + bb_pos) else 0.0
|
||||
}
|
||||
fun galaxies(j: Int) : Galaxy? = galaxies(Galaxy(), j)
|
||||
fun galaxies(obj: Galaxy, j: Int) : Galaxy? {
|
||||
fun galaxies(j: Int) : flatbuffers.goldens.Galaxy? = galaxies(flatbuffers.goldens.Galaxy(), j)
|
||||
fun galaxies(obj: flatbuffers.goldens.Galaxy, j: Int) : flatbuffers.goldens.Galaxy? {
|
||||
val o = __offset(6)
|
||||
return if (o != 0) {
|
||||
obj.__assign(__indirect(__vector(o) + j * 4), bb)
|
||||
@@ -45,7 +47,7 @@ class Universe : Table() {
|
||||
val o = __offset(6); return if (o != 0) __vector_len(o) else 0
|
||||
}
|
||||
companion object {
|
||||
fun validateVersion() = Constants.FLATBUFFERS_23_5_26()
|
||||
fun validateVersion() = Constants.FLATBUFFERS_24_3_6()
|
||||
fun getRootAsUniverse(_bb: ByteBuffer): Universe = getRootAsUniverse(_bb, Universe())
|
||||
fun getRootAsUniverse(_bb: ByteBuffer, obj: Universe): Universe {
|
||||
_bb.order(ByteOrder.LITTLE_ENDIAN)
|
||||
@@ -1,18 +1,20 @@
|
||||
// automatically generated by the FlatBuffers compiler, do not modify
|
||||
import flatbuffers
|
||||
|
||||
namespace flatbuffers.goldens
|
||||
|
||||
class Galaxy
|
||||
|
||||
class Universe
|
||||
|
||||
class Galaxy : flatbuffers_handle
|
||||
class Galaxy : flatbuffers.handle
|
||||
def num_stars() -> int:
|
||||
return buf_.flatbuffers_field_int64(pos_, 4, 0)
|
||||
return flatbuffers.field_int64(buf_, pos_, 4, 0)
|
||||
|
||||
def GetRootAsGalaxy(buf:string): return Galaxy { buf, buf.flatbuffers_indirect(0) }
|
||||
def GetRootAsGalaxy(buf:string): return Galaxy { buf, flatbuffers.indirect(buf, 0) }
|
||||
|
||||
struct GalaxyBuilder:
|
||||
b_:flatbuffers_builder
|
||||
b_:flatbuffers.builder
|
||||
def start():
|
||||
b_.StartObject(1)
|
||||
return this
|
||||
@@ -22,33 +24,33 @@ struct GalaxyBuilder:
|
||||
def end():
|
||||
return b_.EndObject()
|
||||
|
||||
class Universe : flatbuffers_handle
|
||||
class Universe : flatbuffers.handle
|
||||
def age() -> float:
|
||||
return buf_.flatbuffers_field_float64(pos_, 4, 0.0)
|
||||
def galaxies(i:int) -> Galaxy:
|
||||
return Galaxy { buf_, buf_.flatbuffers_indirect(buf_.flatbuffers_field_vector(pos_, 6) + i * 4) }
|
||||
return flatbuffers.field_float64(buf_, pos_, 4, 0.0)
|
||||
def galaxies(i:int) -> flatbuffers.goldens.Galaxy:
|
||||
return flatbuffers.goldens.Galaxy { buf_, flatbuffers.indirect(buf_, flatbuffers.field_vector(buf_, pos_, 6) + i * 4) }
|
||||
def galaxies_length() -> int:
|
||||
return buf_.flatbuffers_field_vector_len(pos_, 6)
|
||||
return flatbuffers.field_vector_len(buf_, pos_, 6)
|
||||
|
||||
def GetRootAsUniverse(buf:string): return Universe { buf, buf.flatbuffers_indirect(0) }
|
||||
def GetRootAsUniverse(buf:string): return Universe { buf, flatbuffers.indirect(buf, 0) }
|
||||
|
||||
struct UniverseBuilder:
|
||||
b_:flatbuffers_builder
|
||||
b_:flatbuffers.builder
|
||||
def start():
|
||||
b_.StartObject(2)
|
||||
return this
|
||||
def add_age(age:float):
|
||||
b_.PrependFloat64Slot(0, age, 0.0)
|
||||
return this
|
||||
def add_galaxies(galaxies:flatbuffers_offset):
|
||||
def add_galaxies(galaxies:flatbuffers.offset):
|
||||
b_.PrependUOffsetTRelativeSlot(1, galaxies)
|
||||
return this
|
||||
def end():
|
||||
return b_.EndObject()
|
||||
|
||||
def UniverseStartGalaxiesVector(b_:flatbuffers_builder, n_:int):
|
||||
def UniverseStartGalaxiesVector(b_:flatbuffers.builder, n_:int):
|
||||
b_.StartVector(4, n_, 4)
|
||||
def UniverseCreateGalaxiesVector(b_:flatbuffers_builder, v_:[flatbuffers_offset]):
|
||||
def UniverseCreateGalaxiesVector(b_:flatbuffers.builder, v_:[flatbuffers.offset]):
|
||||
b_.StartVector(4, v_.length, 4)
|
||||
reverse(v_) e_: b_.PrependUOffsetTRelative(e_)
|
||||
return b_.EndVector(v_.length)
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
Automatically generated by the FlatBuffers compiler, do not modify.
|
||||
Or modify. I'm a message, not a cop.
|
||||
|
||||
flatc version: 23.5.9
|
||||
flatc version: 23.5.26
|
||||
|
||||
Declared by : //basic.fbs
|
||||
Rooting type : Universe (//basic.fbs)
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
Automatically generated by the FlatBuffers compiler, do not modify.
|
||||
Or modify. I'm a message, not a cop.
|
||||
|
||||
flatc version: 23.5.9
|
||||
flatc version: 23.5.26
|
||||
|
||||
Declared by : //basic.fbs
|
||||
Rooting type : Universe (//basic.fbs)
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
Automatically generated by the FlatBuffers compiler, do not modify.
|
||||
Or modify. I'm a message, not a cop.
|
||||
|
||||
flatc version: 23.5.9
|
||||
flatc version: 23.5.26
|
||||
|
||||
Declared by : //basic.fbs
|
||||
Rooting type : Universe (//basic.fbs)
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
Automatically generated by the FlatBuffers compiler, do not modify.
|
||||
Or modify. I'm a message, not a cop.
|
||||
|
||||
flatc version: 23.5.9
|
||||
flatc version: 23.5.26
|
||||
|
||||
Declared by : //basic.fbs
|
||||
Rooting type : Universe (//basic.fbs)
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
<?php
|
||||
// automatically generated by the FlatBuffers compiler, do not modify
|
||||
|
||||
namespace flatbuffers\goldens;
|
||||
|
||||
use \Google\FlatBuffers\Struct;
|
||||
use \Google\FlatBuffers\Table;
|
||||
use \Google\FlatBuffers\ByteBuffer;
|
||||
@@ -1,6 +1,8 @@
|
||||
<?php
|
||||
// automatically generated by the FlatBuffers compiler, do not modify
|
||||
|
||||
namespace flatbuffers\goldens;
|
||||
|
||||
use \Google\FlatBuffers\Struct;
|
||||
use \Google\FlatBuffers\Table;
|
||||
use \Google\FlatBuffers\ByteBuffer;
|
||||
0
goldens/py/flatbuffers/__init__.py
Normal file
0
goldens/py/flatbuffers/__init__.py
Normal file
@@ -1,6 +1,6 @@
|
||||
# automatically generated by the FlatBuffers compiler, do not modify
|
||||
|
||||
# namespace:
|
||||
# namespace: goldens
|
||||
|
||||
import flatbuffers
|
||||
from flatbuffers.compat import import_numpy
|
||||
@@ -40,7 +40,7 @@ def Start(builder):
|
||||
def GalaxyAddNumStars(builder, numStars):
|
||||
builder.PrependInt64Slot(0, numStars, 0)
|
||||
|
||||
def AddNumStars(builder: flatbuffers.Builder, numStars: int):
|
||||
def AddNumStars(builder, numStars):
|
||||
GalaxyAddNumStars(builder, numStars)
|
||||
|
||||
def GalaxyEnd(builder):
|
||||
@@ -1,6 +1,6 @@
|
||||
# automatically generated by the FlatBuffers compiler, do not modify
|
||||
|
||||
# namespace:
|
||||
# namespace: goldens
|
||||
|
||||
import flatbuffers
|
||||
from flatbuffers.compat import import_numpy
|
||||
@@ -38,7 +38,7 @@ class Universe(object):
|
||||
x = self._tab.Vector(o)
|
||||
x += flatbuffers.number_types.UOffsetTFlags.py_type(j) * 4
|
||||
x = self._tab.Indirect(x)
|
||||
from .Galaxy import Galaxy
|
||||
from flatbuffers.goldens.Galaxy import Galaxy
|
||||
obj = Galaxy()
|
||||
obj.Init(self._tab.Bytes, x)
|
||||
return obj
|
||||
@@ -65,13 +65,13 @@ def Start(builder):
|
||||
def UniverseAddAge(builder, age):
|
||||
builder.PrependFloat64Slot(0, age, 0.0)
|
||||
|
||||
def AddAge(builder: flatbuffers.Builder, age: float):
|
||||
def AddAge(builder, age):
|
||||
UniverseAddAge(builder, age)
|
||||
|
||||
def UniverseAddGalaxies(builder, galaxies):
|
||||
builder.PrependUOffsetTRelativeSlot(1, flatbuffers.number_types.UOffsetTFlags.py_type(galaxies), 0)
|
||||
|
||||
def AddGalaxies(builder: flatbuffers.Builder, galaxies: int):
|
||||
def AddGalaxies(builder, galaxies):
|
||||
UniverseAddGalaxies(builder, galaxies)
|
||||
|
||||
def UniverseStartGalaxiesVector(builder, numElems):
|
||||
0
goldens/py/flatbuffers/goldens/__init__.py
Normal file
0
goldens/py/flatbuffers/goldens/__init__.py
Normal file
@@ -9,6 +9,23 @@ use core::cmp::Ordering;
|
||||
extern crate flatbuffers;
|
||||
use self::flatbuffers::{EndianScalar, Follow};
|
||||
|
||||
#[allow(unused_imports, dead_code)]
|
||||
pub mod flatbuffers {
|
||||
|
||||
use core::mem;
|
||||
use core::cmp::Ordering;
|
||||
|
||||
extern crate flatbuffers;
|
||||
use self::flatbuffers::{EndianScalar, Follow};
|
||||
#[allow(unused_imports, dead_code)]
|
||||
pub mod goldens {
|
||||
|
||||
use core::mem;
|
||||
use core::cmp::Ordering;
|
||||
|
||||
extern crate flatbuffers;
|
||||
use self::flatbuffers::{EndianScalar, Follow};
|
||||
|
||||
pub enum GalaxyOffset {}
|
||||
#[derive(Copy, Clone, PartialEq)]
|
||||
|
||||
@@ -32,8 +49,8 @@ impl<'a> Galaxy<'a> {
|
||||
Galaxy { _tab: table }
|
||||
}
|
||||
#[allow(unused_mut)]
|
||||
pub fn create<'bldr: 'args, 'args: 'mut_bldr, 'mut_bldr>(
|
||||
_fbb: &'mut_bldr mut flatbuffers::FlatBufferBuilder<'bldr>,
|
||||
pub fn create<'bldr: 'args, 'args: 'mut_bldr, 'mut_bldr, A: flatbuffers::Allocator + 'bldr>(
|
||||
_fbb: &'mut_bldr mut flatbuffers::FlatBufferBuilder<'bldr, A>,
|
||||
args: &'args GalaxyArgs
|
||||
) -> flatbuffers::WIPOffset<Galaxy<'bldr>> {
|
||||
let mut builder = GalaxyBuilder::new(_fbb);
|
||||
@@ -75,17 +92,17 @@ impl<'a> Default for GalaxyArgs {
|
||||
}
|
||||
}
|
||||
|
||||
pub struct GalaxyBuilder<'a: 'b, 'b> {
|
||||
fbb_: &'b mut flatbuffers::FlatBufferBuilder<'a>,
|
||||
pub struct GalaxyBuilder<'a: 'b, 'b, A: flatbuffers::Allocator + 'a> {
|
||||
fbb_: &'b mut flatbuffers::FlatBufferBuilder<'a, A>,
|
||||
start_: flatbuffers::WIPOffset<flatbuffers::TableUnfinishedWIPOffset>,
|
||||
}
|
||||
impl<'a: 'b, 'b> GalaxyBuilder<'a, 'b> {
|
||||
impl<'a: 'b, 'b, A: flatbuffers::Allocator + 'a> GalaxyBuilder<'a, 'b, A> {
|
||||
#[inline]
|
||||
pub fn add_num_stars(&mut self, num_stars: i64) {
|
||||
self.fbb_.push_slot::<i64>(Galaxy::VT_NUM_STARS, num_stars, 0);
|
||||
}
|
||||
#[inline]
|
||||
pub fn new(_fbb: &'b mut flatbuffers::FlatBufferBuilder<'a>) -> GalaxyBuilder<'a, 'b> {
|
||||
pub fn new(_fbb: &'b mut flatbuffers::FlatBufferBuilder<'a, A>) -> GalaxyBuilder<'a, 'b, A> {
|
||||
let start = _fbb.start_table();
|
||||
GalaxyBuilder {
|
||||
fbb_: _fbb,
|
||||
@@ -130,8 +147,8 @@ impl<'a> Universe<'a> {
|
||||
Universe { _tab: table }
|
||||
}
|
||||
#[allow(unused_mut)]
|
||||
pub fn create<'bldr: 'args, 'args: 'mut_bldr, 'mut_bldr>(
|
||||
_fbb: &'mut_bldr mut flatbuffers::FlatBufferBuilder<'bldr>,
|
||||
pub fn create<'bldr: 'args, 'args: 'mut_bldr, 'mut_bldr, A: flatbuffers::Allocator + 'bldr>(
|
||||
_fbb: &'mut_bldr mut flatbuffers::FlatBufferBuilder<'bldr, A>,
|
||||
args: &'args UniverseArgs<'args>
|
||||
) -> flatbuffers::WIPOffset<Universe<'bldr>> {
|
||||
let mut builder = UniverseBuilder::new(_fbb);
|
||||
@@ -184,11 +201,11 @@ impl<'a> Default for UniverseArgs<'a> {
|
||||
}
|
||||
}
|
||||
|
||||
pub struct UniverseBuilder<'a: 'b, 'b> {
|
||||
fbb_: &'b mut flatbuffers::FlatBufferBuilder<'a>,
|
||||
pub struct UniverseBuilder<'a: 'b, 'b, A: flatbuffers::Allocator + 'a> {
|
||||
fbb_: &'b mut flatbuffers::FlatBufferBuilder<'a, A>,
|
||||
start_: flatbuffers::WIPOffset<flatbuffers::TableUnfinishedWIPOffset>,
|
||||
}
|
||||
impl<'a: 'b, 'b> UniverseBuilder<'a, 'b> {
|
||||
impl<'a: 'b, 'b, A: flatbuffers::Allocator + 'a> UniverseBuilder<'a, 'b, A> {
|
||||
#[inline]
|
||||
pub fn add_age(&mut self, age: f64) {
|
||||
self.fbb_.push_slot::<f64>(Universe::VT_AGE, age, 0.0);
|
||||
@@ -198,7 +215,7 @@ impl<'a: 'b, 'b> UniverseBuilder<'a, 'b> {
|
||||
self.fbb_.push_slot_always::<flatbuffers::WIPOffset<_>>(Universe::VT_GALAXIES, galaxies);
|
||||
}
|
||||
#[inline]
|
||||
pub fn new(_fbb: &'b mut flatbuffers::FlatBufferBuilder<'a>) -> UniverseBuilder<'a, 'b> {
|
||||
pub fn new(_fbb: &'b mut flatbuffers::FlatBufferBuilder<'a, A>) -> UniverseBuilder<'a, 'b, A> {
|
||||
let start = _fbb.start_table();
|
||||
UniverseBuilder {
|
||||
fbb_: _fbb,
|
||||
@@ -281,13 +298,16 @@ pub unsafe fn size_prefixed_root_as_universe_unchecked(buf: &[u8]) -> Universe {
|
||||
flatbuffers::size_prefixed_root_unchecked::<Universe>(buf)
|
||||
}
|
||||
#[inline]
|
||||
pub fn finish_universe_buffer<'a, 'b>(
|
||||
fbb: &'b mut flatbuffers::FlatBufferBuilder<'a>,
|
||||
pub fn finish_universe_buffer<'a, 'b, A: flatbuffers::Allocator + 'a>(
|
||||
fbb: &'b mut flatbuffers::FlatBufferBuilder<'a, A>,
|
||||
root: flatbuffers::WIPOffset<Universe<'a>>) {
|
||||
fbb.finish(root, None);
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn finish_size_prefixed_universe_buffer<'a, 'b>(fbb: &'b mut flatbuffers::FlatBufferBuilder<'a>, root: flatbuffers::WIPOffset<Universe<'a>>) {
|
||||
pub fn finish_size_prefixed_universe_buffer<'a, 'b, A: flatbuffers::Allocator + 'a>(fbb: &'b mut flatbuffers::FlatBufferBuilder<'a, A>, root: flatbuffers::WIPOffset<Universe<'a>>) {
|
||||
fbb.finish_size_prefixed(root, None);
|
||||
}
|
||||
} // pub mod goldens
|
||||
} // pub mod flatbuffers
|
||||
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
// This file should contain the basics of flatbuffers that all languages should
|
||||
// support.
|
||||
|
||||
namespace flatbuffers.goldens;
|
||||
|
||||
table Galaxy {
|
||||
num_stars:long;
|
||||
}
|
||||
|
||||
@@ -4,9 +4,9 @@
|
||||
|
||||
import FlatBuffers
|
||||
|
||||
public struct Galaxy: FlatBufferObject, Verifiable {
|
||||
public struct flatbuffers_goldens_Galaxy: FlatBufferObject, Verifiable {
|
||||
|
||||
static func validateVersion() { FlatBuffersVersion_23_5_26() }
|
||||
static func validateVersion() { FlatBuffersVersion_24_3_6() }
|
||||
public var __buffer: ByteBuffer! { return _accessor.bb }
|
||||
private var _accessor: Table
|
||||
|
||||
@@ -27,9 +27,9 @@ public struct Galaxy: FlatBufferObject, Verifiable {
|
||||
_ fbb: inout FlatBufferBuilder,
|
||||
numStars: Int64 = 0
|
||||
) -> Offset {
|
||||
let __start = Galaxy.startGalaxy(&fbb)
|
||||
Galaxy.add(numStars: numStars, &fbb)
|
||||
return Galaxy.endGalaxy(&fbb, start: __start)
|
||||
let __start = flatbuffers_goldens_Galaxy.startGalaxy(&fbb)
|
||||
flatbuffers_goldens_Galaxy.add(numStars: numStars, &fbb)
|
||||
return flatbuffers_goldens_Galaxy.endGalaxy(&fbb, start: __start)
|
||||
}
|
||||
|
||||
public static func verify<T>(_ verifier: inout Verifier, at position: Int, of type: T.Type) throws where T: Verifiable {
|
||||
@@ -39,9 +39,9 @@ public struct Galaxy: FlatBufferObject, Verifiable {
|
||||
}
|
||||
}
|
||||
|
||||
public struct Universe: FlatBufferObject, Verifiable {
|
||||
public struct flatbuffers_goldens_Universe: FlatBufferObject, Verifiable {
|
||||
|
||||
static func validateVersion() { FlatBuffersVersion_23_5_26() }
|
||||
static func validateVersion() { FlatBuffersVersion_24_3_6() }
|
||||
public var __buffer: ByteBuffer! { return _accessor.bb }
|
||||
private var _accessor: Table
|
||||
|
||||
@@ -58,7 +58,7 @@ public struct Universe: FlatBufferObject, Verifiable {
|
||||
public var age: Double { let o = _accessor.offset(VTOFFSET.age.v); return o == 0 ? 0.0 : _accessor.readBuffer(of: Double.self, at: o) }
|
||||
public var hasGalaxies: Bool { let o = _accessor.offset(VTOFFSET.galaxies.v); return o == 0 ? false : true }
|
||||
public var galaxiesCount: Int32 { let o = _accessor.offset(VTOFFSET.galaxies.v); return o == 0 ? 0 : _accessor.vector(count: o) }
|
||||
public func galaxies(at index: Int32) -> Galaxy? { let o = _accessor.offset(VTOFFSET.galaxies.v); return o == 0 ? nil : Galaxy(_accessor.bb, o: _accessor.indirect(_accessor.vector(at: o) + index * 4)) }
|
||||
public func galaxies(at index: Int32) -> flatbuffers_goldens_Galaxy? { let o = _accessor.offset(VTOFFSET.galaxies.v); return o == 0 ? nil : flatbuffers_goldens_Galaxy(_accessor.bb, o: _accessor.indirect(_accessor.vector(at: o) + index * 4)) }
|
||||
public static func startUniverse(_ fbb: inout FlatBufferBuilder) -> UOffset { fbb.startTable(with: 2) }
|
||||
public static func add(age: Double, _ fbb: inout FlatBufferBuilder) { fbb.add(element: age, def: 0.0, at: VTOFFSET.age.p) }
|
||||
public static func addVectorOf(galaxies: Offset, _ fbb: inout FlatBufferBuilder) { fbb.add(offset: galaxies, at: VTOFFSET.galaxies.p) }
|
||||
@@ -68,16 +68,16 @@ public struct Universe: FlatBufferObject, Verifiable {
|
||||
age: Double = 0.0,
|
||||
galaxiesVectorOffset galaxies: Offset = Offset()
|
||||
) -> Offset {
|
||||
let __start = Universe.startUniverse(&fbb)
|
||||
Universe.add(age: age, &fbb)
|
||||
Universe.addVectorOf(galaxies: galaxies, &fbb)
|
||||
return Universe.endUniverse(&fbb, start: __start)
|
||||
let __start = flatbuffers_goldens_Universe.startUniverse(&fbb)
|
||||
flatbuffers_goldens_Universe.add(age: age, &fbb)
|
||||
flatbuffers_goldens_Universe.addVectorOf(galaxies: galaxies, &fbb)
|
||||
return flatbuffers_goldens_Universe.endUniverse(&fbb, start: __start)
|
||||
}
|
||||
|
||||
public static func verify<T>(_ verifier: inout Verifier, at position: Int, of type: T.Type) throws where T: Verifiable {
|
||||
var _v = try verifier.visitTable(at: position)
|
||||
try _v.visit(field: VTOFFSET.age.p, fieldName: "age", required: false, type: Double.self)
|
||||
try _v.visit(field: VTOFFSET.galaxies.p, fieldName: "galaxies", required: false, type: ForwardOffset<Vector<ForwardOffset<Galaxy>, Galaxy>>.self)
|
||||
try _v.visit(field: VTOFFSET.galaxies.p, fieldName: "galaxies", required: false, type: ForwardOffset<Vector<ForwardOffset<flatbuffers_goldens_Galaxy>, flatbuffers_goldens_Galaxy>>.self)
|
||||
_v.finish()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
// automatically generated by the FlatBuffers compiler, do not modify
|
||||
|
||||
/* eslint-disable @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any, @typescript-eslint/no-non-null-assertion */
|
||||
|
||||
export { Galaxy } from './galaxy.js';
|
||||
export { Universe } from './universe.js';
|
||||
|
||||
6
goldens/ts/flatbuffers/goldens.ts
Normal file
6
goldens/ts/flatbuffers/goldens.ts
Normal file
@@ -0,0 +1,6 @@
|
||||
// automatically generated by the FlatBuffers compiler, do not modify
|
||||
|
||||
/* eslint-disable @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any, @typescript-eslint/no-non-null-assertion */
|
||||
|
||||
export { Galaxy } from './goldens/galaxy.js';
|
||||
export { Universe } from './goldens/universe.js';
|
||||
@@ -1,5 +1,7 @@
|
||||
// automatically generated by the FlatBuffers compiler, do not modify
|
||||
|
||||
/* eslint-disable @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any, @typescript-eslint/no-non-null-assertion */
|
||||
|
||||
import * as flatbuffers from 'flatbuffers';
|
||||
|
||||
export class Galaxy {
|
||||
@@ -1,8 +1,10 @@
|
||||
// automatically generated by the FlatBuffers compiler, do not modify
|
||||
|
||||
/* eslint-disable @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any, @typescript-eslint/no-non-null-assertion */
|
||||
|
||||
import * as flatbuffers from 'flatbuffers';
|
||||
|
||||
import { Galaxy } from './galaxy.js';
|
||||
import { Galaxy } from '../../flatbuffers/goldens/galaxy.js';
|
||||
|
||||
|
||||
export class Universe {
|
||||
@@ -5,7 +5,7 @@ go 1.15
|
||||
replace github.com/google/flatbuffers/grpc/examples/go/greeter/models v0.0.0 => ../models
|
||||
|
||||
require (
|
||||
github.com/google/flatbuffers v1.12.0
|
||||
github.com/google/flatbuffers v2.0.8+incompatible
|
||||
github.com/google/flatbuffers/grpc/examples/go/greeter/models v0.0.0
|
||||
google.golang.org/grpc v1.35.0
|
||||
google.golang.org/grpc v1.56.3
|
||||
)
|
||||
|
||||
@@ -3,6 +3,6 @@ module github.com/google/flatbuffers/grpc/examples/go/greeter/models
|
||||
go 1.15
|
||||
|
||||
require (
|
||||
github.com/google/flatbuffers v1.12.0
|
||||
google.golang.org/grpc v1.35.0
|
||||
github.com/google/flatbuffers v2.0.8+incompatible
|
||||
google.golang.org/grpc v1.56.3
|
||||
)
|
||||
|
||||
@@ -5,7 +5,7 @@ go 1.15
|
||||
replace github.com/google/flatbuffers/grpc/examples/go/greeter/models v0.0.0 => ../models
|
||||
|
||||
require (
|
||||
github.com/google/flatbuffers v1.12.0
|
||||
github.com/google/flatbuffers v2.0.8+incompatible
|
||||
github.com/google/flatbuffers/grpc/examples/go/greeter/models v0.0.0
|
||||
google.golang.org/grpc v1.39.0-dev
|
||||
google.golang.org/grpc v1.56.3
|
||||
)
|
||||
|
||||
@@ -6,7 +6,7 @@ import FlatBuffers
|
||||
|
||||
public struct models_HelloReply: FlatBufferObject, Verifiable {
|
||||
|
||||
static func validateVersion() { FlatBuffersVersion_23_5_26() }
|
||||
static func validateVersion() { FlatBuffersVersion_24_3_6() }
|
||||
public var __buffer: ByteBuffer! { return _accessor.bb }
|
||||
private var _accessor: Table
|
||||
|
||||
@@ -53,7 +53,7 @@ extension models_HelloReply: Encodable {
|
||||
|
||||
public struct models_HelloRequest: FlatBufferObject, Verifiable {
|
||||
|
||||
static func validateVersion() { FlatBuffersVersion_23_5_26() }
|
||||
static func validateVersion() { FlatBuffersVersion_24_3_6() }
|
||||
public var __buffer: ByteBuffer! { return _accessor.bb }
|
||||
private var _accessor: Table
|
||||
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
// automatically generated by the FlatBuffers compiler, do not modify
|
||||
|
||||
/* eslint-disable @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any, @typescript-eslint/no-non-null-assertion */
|
||||
|
||||
export * as models from './models.js';
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
// automatically generated by the FlatBuffers compiler, do not modify
|
||||
|
||||
/* eslint-disable @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any, @typescript-eslint/no-non-null-assertion */
|
||||
|
||||
export { HelloReply } from './models/hello-reply.js';
|
||||
export { HelloRequest } from './models/hello-request.js';
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
// automatically generated by the FlatBuffers compiler, do not modify
|
||||
|
||||
/* eslint-disable @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any, @typescript-eslint/no-non-null-assertion */
|
||||
|
||||
import * as flatbuffers from 'flatbuffers';
|
||||
|
||||
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
// automatically generated by the FlatBuffers compiler, do not modify
|
||||
|
||||
/* eslint-disable @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any, @typescript-eslint/no-non-null-assertion */
|
||||
|
||||
import * as flatbuffers from 'flatbuffers';
|
||||
|
||||
|
||||
|
||||
@@ -139,9 +139,9 @@
|
||||
#endif
|
||||
#endif // !defined(FLATBUFFERS_LITTLEENDIAN)
|
||||
|
||||
#define FLATBUFFERS_VERSION_MAJOR 23
|
||||
#define FLATBUFFERS_VERSION_MINOR 5
|
||||
#define FLATBUFFERS_VERSION_REVISION 26
|
||||
#define FLATBUFFERS_VERSION_MAJOR 24
|
||||
#define FLATBUFFERS_VERSION_MINOR 3
|
||||
#define FLATBUFFERS_VERSION_REVISION 6
|
||||
#define FLATBUFFERS_STRING_EXPAND(X) #X
|
||||
#define FLATBUFFERS_STRING(X) FLATBUFFERS_STRING_EXPAND(X)
|
||||
namespace flatbuffers {
|
||||
@@ -155,7 +155,7 @@ namespace flatbuffers {
|
||||
#define FLATBUFFERS_FINAL_CLASS final
|
||||
#define FLATBUFFERS_OVERRIDE override
|
||||
#define FLATBUFFERS_EXPLICIT_CPP11 explicit
|
||||
#define FLATBUFFERS_VTABLE_UNDERLYING_TYPE : flatbuffers::voffset_t
|
||||
#define FLATBUFFERS_VTABLE_UNDERLYING_TYPE : ::flatbuffers::voffset_t
|
||||
#else
|
||||
#define FLATBUFFERS_FINAL_CLASS
|
||||
#define FLATBUFFERS_OVERRIDE
|
||||
@@ -289,10 +289,12 @@ namespace flatbuffers {
|
||||
#define FLATBUFFERS_SUPPRESS_UBSAN(type)
|
||||
#endif
|
||||
|
||||
// This is constexpr function used for checking compile-time constants.
|
||||
// Avoid `#pragma warning(disable: 4127) // C4127: expression is constant`.
|
||||
template<typename T> FLATBUFFERS_CONSTEXPR inline bool IsConstTrue(T t) {
|
||||
return !!t;
|
||||
namespace flatbuffers {
|
||||
// This is constexpr function used for checking compile-time constants.
|
||||
// Avoid `#pragma warning(disable: 4127) // C4127: expression is constant`.
|
||||
template<typename T> FLATBUFFERS_CONSTEXPR inline bool IsConstTrue(T t) {
|
||||
return !!t;
|
||||
}
|
||||
}
|
||||
|
||||
// Enable C++ attribute [[]] if std:c++17 or higher.
|
||||
@@ -361,7 +363,6 @@ inline bool VerifyAlignmentRequirements(size_t align, size_t min_align = 1) {
|
||||
}
|
||||
|
||||
#if defined(_MSC_VER)
|
||||
#pragma warning(disable: 4351) // C4351: new behavior: elements of array ... will be default initialized
|
||||
#pragma warning(push)
|
||||
#pragma warning(disable: 4127) // C4127: conditional expression is constant
|
||||
#endif
|
||||
|
||||
@@ -45,8 +45,9 @@ inline voffset_t FieldIndexToOffset(voffset_t field_id) {
|
||||
// Should correspond to what EndTable() below builds up.
|
||||
const voffset_t fixed_fields =
|
||||
2 * sizeof(voffset_t); // Vtable size and Object Size.
|
||||
return fixed_fields + field_id * sizeof(voffset_t);
|
||||
}
|
||||
size_t offset = fixed_fields + field_id * sizeof(voffset_t);
|
||||
FLATBUFFERS_ASSERT(offset < std::numeric_limits<voffset_t>::max());
|
||||
return static_cast<voffset_t>(offset);}
|
||||
|
||||
template<typename T, typename Alloc = std::allocator<T>>
|
||||
const T *data(const std::vector<T, Alloc> &v) {
|
||||
@@ -220,21 +221,13 @@ template<bool Is64Aware = false> class FlatBufferBuilderImpl {
|
||||
/// @return Returns a `uint8_t` pointer to the unfinished buffer.
|
||||
uint8_t *GetCurrentBufferPointer() const { return buf_.data(); }
|
||||
|
||||
/// @brief Get the released pointer to the serialized buffer.
|
||||
/// @warning Do NOT attempt to use this FlatBufferBuilder afterwards!
|
||||
/// @return A `FlatBuffer` that owns the buffer and its allocator and
|
||||
/// behaves similar to a `unique_ptr` with a deleter.
|
||||
FLATBUFFERS_ATTRIBUTE([[deprecated("use Release() instead")]])
|
||||
DetachedBuffer ReleaseBufferPointer() {
|
||||
Finished();
|
||||
return buf_.release();
|
||||
}
|
||||
|
||||
/// @brief Get the released DetachedBuffer.
|
||||
/// @return A `DetachedBuffer` that owns the buffer and its allocator.
|
||||
DetachedBuffer Release() {
|
||||
Finished();
|
||||
return buf_.release();
|
||||
DetachedBuffer buffer = buf_.release();
|
||||
Clear();
|
||||
return buffer;
|
||||
}
|
||||
|
||||
/// @brief Get the released pointer to the serialized buffer.
|
||||
@@ -245,10 +238,12 @@ template<bool Is64Aware = false> class FlatBufferBuilderImpl {
|
||||
/// @return A raw pointer to the start of the memory block containing
|
||||
/// the serialized `FlatBuffer`.
|
||||
/// @remark If the allocator is owned, it gets deleted when the destructor is
|
||||
/// called..
|
||||
/// called.
|
||||
uint8_t *ReleaseRaw(size_t &size, size_t &offset) {
|
||||
Finished();
|
||||
return buf_.release_raw(size, offset);
|
||||
uint8_t* raw = buf_.release_raw(size, offset);
|
||||
Clear();
|
||||
return raw;
|
||||
}
|
||||
|
||||
/// @brief get the minimum alignment this buffer needs to be accessed
|
||||
@@ -566,7 +561,7 @@ template<bool Is64Aware = false> class FlatBufferBuilderImpl {
|
||||
return CreateString<OffsetT>(str.c_str(), str.length());
|
||||
}
|
||||
|
||||
// clang-format off
|
||||
// clang-format off
|
||||
#ifdef FLATBUFFERS_HAS_STRING_VIEW
|
||||
/// @brief Store a string in the buffer, which can contain any binary data.
|
||||
/// @param[in] str A const string_view to copy in to the buffer.
|
||||
@@ -588,14 +583,14 @@ template<bool Is64Aware = false> class FlatBufferBuilderImpl {
|
||||
|
||||
/// @brief Store a string in the buffer, which can contain any binary data.
|
||||
/// @param[in] str A const reference to a std::string like type with support
|
||||
/// of T::c_str() and T::length() to store in the buffer.
|
||||
/// of T::data() and T::length() to store in the buffer.
|
||||
/// @return Returns the offset in the buffer where the string starts.
|
||||
template<template<typename> class OffsetT = Offset,
|
||||
// No need to explicitly declare the T type, let the compiler deduce
|
||||
// it.
|
||||
int &...ExplicitArgumentBarrier, typename T>
|
||||
OffsetT<String> CreateString(const T &str) {
|
||||
return CreateString<OffsetT>(str.c_str(), str.length());
|
||||
return CreateString<OffsetT>(str.data(), str.length());
|
||||
}
|
||||
|
||||
/// @brief Store a string in the buffer, which can contain any binary data.
|
||||
@@ -698,12 +693,27 @@ template<bool Is64Aware = false> class FlatBufferBuilderImpl {
|
||||
// normally dictate.
|
||||
// This is useful when storing a nested_flatbuffer in a vector of bytes,
|
||||
// or when storing SIMD floats, etc.
|
||||
void ForceVectorAlignment(size_t len, size_t elemsize, size_t alignment) {
|
||||
void ForceVectorAlignment(const size_t len, const size_t elemsize,
|
||||
const size_t alignment) {
|
||||
if (len == 0) return;
|
||||
FLATBUFFERS_ASSERT(VerifyAlignmentRequirements(alignment));
|
||||
PreAlign(len * elemsize, alignment);
|
||||
}
|
||||
|
||||
template<bool is_64 = Is64Aware>
|
||||
typename std::enable_if<is_64, void>::type ForceVectorAlignment64(
|
||||
const size_t len, const size_t elemsize, const size_t alignment) {
|
||||
// If you hit this assertion, you are trying to force alignment on a
|
||||
// vector with offset64 after serializing a 32-bit offset.
|
||||
FLATBUFFERS_ASSERT(GetSize() == length_of_64_bit_region_);
|
||||
|
||||
// Call through.
|
||||
ForceVectorAlignment(len, elemsize, alignment);
|
||||
|
||||
// Update the 64 bit region.
|
||||
length_of_64_bit_region_ = GetSize();
|
||||
}
|
||||
|
||||
// Similar to ForceVectorAlignment but for String fields.
|
||||
void ForceStringAlignment(size_t len, size_t alignment) {
|
||||
if (len == 0) return;
|
||||
@@ -733,7 +743,7 @@ template<bool Is64Aware = false> class FlatBufferBuilderImpl {
|
||||
AssertScalarT<T>();
|
||||
StartVector<T, OffsetT, LenT>(len);
|
||||
if (len > 0) {
|
||||
// clang-format off
|
||||
// clang-format off
|
||||
#if FLATBUFFERS_LITTLEENDIAN
|
||||
PushBytes(reinterpret_cast<const uint8_t *>(v), len * sizeof(T));
|
||||
#else
|
||||
@@ -864,7 +874,9 @@ template<bool Is64Aware = false> class FlatBufferBuilderImpl {
|
||||
/// where the vector is stored.
|
||||
template<class It>
|
||||
Offset<Vector<Offset<String>>> CreateVectorOfStrings(It begin, It end) {
|
||||
auto size = std::distance(begin, end);
|
||||
auto distance = std::distance(begin, end);
|
||||
FLATBUFFERS_ASSERT(distance >= 0);
|
||||
auto size = static_cast<size_t>(distance);
|
||||
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
|
||||
@@ -874,7 +886,7 @@ template<bool Is64Aware = false> class FlatBufferBuilderImpl {
|
||||
buf_.scratch_push_small(CreateString(*it));
|
||||
}
|
||||
StartVector<Offset<String>>(size);
|
||||
for (auto i = 1; i <= size; i++) {
|
||||
for (size_t i = 1; i <= size; i++) {
|
||||
// Note we re-evaluate the buf location each iteration to account for any
|
||||
// underlying buffer resizing that may occur.
|
||||
PushElement(*reinterpret_cast<Offset<String> *>(
|
||||
@@ -898,8 +910,7 @@ template<bool Is64Aware = false> class FlatBufferBuilderImpl {
|
||||
typedef typename VectorT<T>::size_type LenT;
|
||||
typedef typename OffsetT<VectorT<const T *>>::offset_type offset_type;
|
||||
|
||||
StartVector<OffsetT, LenT>(len * sizeof(T) / AlignOf<T>(), sizeof(T),
|
||||
AlignOf<T>());
|
||||
StartVector<OffsetT, LenT>(len, sizeof(T), AlignOf<T>());
|
||||
if (len > 0) {
|
||||
PushBytes(reinterpret_cast<const uint8_t *>(v), sizeof(T) * len);
|
||||
}
|
||||
@@ -1244,6 +1255,9 @@ template<bool Is64Aware = false> class FlatBufferBuilderImpl {
|
||||
FlatBufferBuilderImpl &operator=(const FlatBufferBuilderImpl &);
|
||||
|
||||
void Finish(uoffset_t root, const char *file_identifier, bool size_prefix) {
|
||||
// A buffer can only be finished once. To reuse a builder use `clear()`.
|
||||
FLATBUFFERS_ASSERT(!finished);
|
||||
|
||||
NotNested();
|
||||
buf_.clear_scratch();
|
||||
|
||||
@@ -1369,8 +1383,7 @@ template<bool Is64Aware = false> class FlatBufferBuilderImpl {
|
||||
// Must be completed with EndVectorOfStructs().
|
||||
template<typename T, template<typename> class OffsetT = Offset>
|
||||
T *StartVectorOfStructs(size_t vector_size) {
|
||||
StartVector<OffsetT>(vector_size * sizeof(T) / AlignOf<T>(), sizeof(T),
|
||||
AlignOf<T>());
|
||||
StartVector<OffsetT>(vector_size, sizeof(T), AlignOf<T>());
|
||||
return reinterpret_cast<T *>(buf_.make_space(vector_size * sizeof(T)));
|
||||
}
|
||||
|
||||
@@ -1456,7 +1469,7 @@ T *GetMutableTemporaryPointer(FlatBufferBuilder &fbb, Offset<T> offset) {
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
const T *GetTemporaryPointer(FlatBufferBuilder &fbb, Offset<T> offset) {
|
||||
const T *GetTemporaryPointer(const FlatBufferBuilder &fbb, Offset<T> offset) {
|
||||
return GetMutableTemporaryPointer<T>(fbb, offset);
|
||||
}
|
||||
|
||||
|
||||
@@ -248,31 +248,31 @@ inline const char *flatbuffers_version_string() {
|
||||
|
||||
// clang-format off
|
||||
#define FLATBUFFERS_DEFINE_BITMASK_OPERATORS(E, T)\
|
||||
inline E operator | (E lhs, E rhs){\
|
||||
inline FLATBUFFERS_CONSTEXPR_CPP11 E operator | (E lhs, E rhs){\
|
||||
return E(T(lhs) | T(rhs));\
|
||||
}\
|
||||
inline E operator & (E lhs, E rhs){\
|
||||
inline FLATBUFFERS_CONSTEXPR_CPP11 E operator & (E lhs, E rhs){\
|
||||
return E(T(lhs) & T(rhs));\
|
||||
}\
|
||||
inline E operator ^ (E lhs, E rhs){\
|
||||
inline FLATBUFFERS_CONSTEXPR_CPP11 E operator ^ (E lhs, E rhs){\
|
||||
return E(T(lhs) ^ T(rhs));\
|
||||
}\
|
||||
inline E operator ~ (E lhs){\
|
||||
inline FLATBUFFERS_CONSTEXPR_CPP11 E operator ~ (E lhs){\
|
||||
return E(~T(lhs));\
|
||||
}\
|
||||
inline E operator |= (E &lhs, E rhs){\
|
||||
inline FLATBUFFERS_CONSTEXPR_CPP11 E operator |= (E &lhs, E rhs){\
|
||||
lhs = lhs | rhs;\
|
||||
return lhs;\
|
||||
}\
|
||||
inline E operator &= (E &lhs, E rhs){\
|
||||
inline FLATBUFFERS_CONSTEXPR_CPP11 E operator &= (E &lhs, E rhs){\
|
||||
lhs = lhs & rhs;\
|
||||
return lhs;\
|
||||
}\
|
||||
inline E operator ^= (E &lhs, E rhs){\
|
||||
inline FLATBUFFERS_CONSTEXPR_CPP11 E operator ^= (E &lhs, E rhs){\
|
||||
lhs = lhs ^ rhs;\
|
||||
return lhs;\
|
||||
}\
|
||||
inline bool operator !(E rhs) \
|
||||
inline FLATBUFFERS_CONSTEXPR_CPP11 bool operator !(E rhs) \
|
||||
{\
|
||||
return !bool(T(rhs)); \
|
||||
}
|
||||
|
||||
@@ -360,16 +360,40 @@ class Map : public Vector {
|
||||
bool IsTheEmptyMap() const { return data_ == EmptyMap().data_; }
|
||||
};
|
||||
|
||||
inline void IndentString(std::string &s, int indent,
|
||||
const char *indent_string) {
|
||||
for (int i = 0; i < indent; i++) s += indent_string;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void AppendToString(std::string &s, T &&v, bool keys_quoted, bool indented,
|
||||
int cur_indent, const char *indent_string) {
|
||||
s += "[";
|
||||
s += indented ? "\n" : " ";
|
||||
for (size_t i = 0; i < v.size(); i++) {
|
||||
if (i) {
|
||||
s += ",";
|
||||
s += indented ? "\n" : " ";
|
||||
}
|
||||
if (indented) IndentString(s, cur_indent, indent_string);
|
||||
v[i].ToString(true, keys_quoted, s, indented, cur_indent,
|
||||
indent_string);
|
||||
}
|
||||
if (indented) {
|
||||
s += "\n";
|
||||
IndentString(s, cur_indent - 1, indent_string);
|
||||
} else {
|
||||
s += " ";
|
||||
}
|
||||
s += "]";
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void AppendToString(std::string &s, T &&v, bool keys_quoted) {
|
||||
s += "[ ";
|
||||
for (size_t i = 0; i < v.size(); i++) {
|
||||
if (i) s += ", ";
|
||||
v[i].ToString(true, keys_quoted, s);
|
||||
}
|
||||
s += " ]";
|
||||
AppendToString(s, v, keys_quoted);
|
||||
}
|
||||
|
||||
|
||||
class Reference {
|
||||
public:
|
||||
Reference()
|
||||
@@ -542,8 +566,13 @@ class Reference {
|
||||
// Convert any type to a JSON-like string. strings_quoted determines if
|
||||
// string values at the top level receive "" quotes (inside other values
|
||||
// they always do). keys_quoted determines if keys are quoted, at any level.
|
||||
// TODO(wvo): add further options to have indentation/newlines.
|
||||
void ToString(bool strings_quoted, bool keys_quoted, std::string &s) const {
|
||||
ToString(strings_quoted, keys_quoted, s, false, 0, "");
|
||||
}
|
||||
|
||||
// This version additionally allow you to specify if you want indentation.
|
||||
void ToString(bool strings_quoted, bool keys_quoted, std::string &s,
|
||||
bool indented, int cur_indent, const char *indent_string) const {
|
||||
if (type_ == FBT_STRING) {
|
||||
String str(Indirect(), byte_width_);
|
||||
if (strings_quoted) {
|
||||
@@ -569,7 +598,8 @@ class Reference {
|
||||
} else if (IsBool()) {
|
||||
s += AsBool() ? "true" : "false";
|
||||
} else if (IsMap()) {
|
||||
s += "{ ";
|
||||
s += "{";
|
||||
s += indented ? "\n" : " ";
|
||||
auto m = AsMap();
|
||||
auto keys = m.Keys();
|
||||
auto vals = m.Values();
|
||||
@@ -590,18 +620,28 @@ class Reference {
|
||||
}
|
||||
}
|
||||
}
|
||||
if (indented) IndentString(s, cur_indent + 1, indent_string);
|
||||
keys[i].ToString(true, kq, s);
|
||||
s += ": ";
|
||||
vals[i].ToString(true, keys_quoted, s);
|
||||
if (i < keys.size() - 1) s += ", ";
|
||||
vals[i].ToString(true, keys_quoted, s, indented, cur_indent + 1, indent_string);
|
||||
if (i < keys.size() - 1) {
|
||||
s += ",";
|
||||
if (!indented) s += " ";
|
||||
}
|
||||
if (indented) s += "\n";
|
||||
}
|
||||
s += " }";
|
||||
if (!indented) s += " ";
|
||||
if (indented) IndentString(s, cur_indent, indent_string);
|
||||
s += "}";
|
||||
} else if (IsVector()) {
|
||||
AppendToString<Vector>(s, AsVector(), keys_quoted);
|
||||
AppendToString<Vector>(s, AsVector(), keys_quoted, indented,
|
||||
cur_indent + 1, indent_string);
|
||||
} else if (IsTypedVector()) {
|
||||
AppendToString<TypedVector>(s, AsTypedVector(), keys_quoted);
|
||||
AppendToString<TypedVector>(s, AsTypedVector(), keys_quoted, indented,
|
||||
cur_indent + 1, indent_string);
|
||||
} else if (IsFixedTypedVector()) {
|
||||
AppendToString<FixedTypedVector>(s, AsFixedTypedVector(), keys_quoted);
|
||||
AppendToString<FixedTypedVector>(s, AsFixedTypedVector(), keys_quoted,
|
||||
indented, cur_indent + 1, indent_string);
|
||||
} else if (IsBlob()) {
|
||||
auto blob = AsBlob();
|
||||
flatbuffers::EscapeString(reinterpret_cast<const char *>(blob.data()),
|
||||
@@ -1128,10 +1168,7 @@ class Builder FLATBUFFERS_FINAL_CLASS {
|
||||
|
||||
size_t EndMap(size_t start) {
|
||||
// We should have interleaved keys and values on the stack.
|
||||
// Make sure it is an even number:
|
||||
auto len = stack_.size() - start;
|
||||
FLATBUFFERS_ASSERT(!(len & 1));
|
||||
len /= 2;
|
||||
auto len = MapElementCount(start);
|
||||
// Make sure keys are all strings:
|
||||
for (auto key = start; key < stack_.size(); key += 2) {
|
||||
FLATBUFFERS_ASSERT(stack_[key].type_ == FBT_KEY);
|
||||
@@ -1289,6 +1326,14 @@ class Builder FLATBUFFERS_FINAL_CLASS {
|
||||
EndMap(start);
|
||||
}
|
||||
|
||||
size_t MapElementCount(size_t start) {
|
||||
// Make sure it is an even number:
|
||||
auto len = stack_.size() - start;
|
||||
FLATBUFFERS_ASSERT(!(len & 1));
|
||||
len /= 2;
|
||||
return len;
|
||||
}
|
||||
|
||||
// If you wish to share a value explicitly (a value not shared automatically
|
||||
// through one of the BUILDER_FLAG_SHARE_* flags) you can do so with these
|
||||
// functions. Or if you wish to turn those flags off for performance reasons
|
||||
@@ -1307,6 +1352,12 @@ class Builder FLATBUFFERS_FINAL_CLASS {
|
||||
ReuseValue(v);
|
||||
}
|
||||
|
||||
// Undo the last element serialized. Call once for a value and once for a
|
||||
// key.
|
||||
void Undo() {
|
||||
stack_.pop_back();
|
||||
}
|
||||
|
||||
// Overloaded Add that tries to call the correct function above.
|
||||
void Add(int8_t i) { Int(i); }
|
||||
void Add(int16_t i) { Int(i); }
|
||||
@@ -1669,7 +1720,7 @@ class Verifier FLATBUFFERS_FINAL_CLASS {
|
||||
max_vectors_(buf_len),
|
||||
check_alignment_(_check_alignment),
|
||||
reuse_tracker_(reuse_tracker) {
|
||||
FLATBUFFERS_ASSERT(size_ < FLATBUFFERS_MAX_BUFFER_SIZE);
|
||||
FLATBUFFERS_ASSERT(static_cast<int32_t>(size_) < FLATBUFFERS_MAX_BUFFER_SIZE);
|
||||
if (reuse_tracker_) {
|
||||
reuse_tracker_->clear();
|
||||
reuse_tracker_->resize(size_, PackedType(BIT_WIDTH_8, FBT_NULL));
|
||||
|
||||
@@ -342,7 +342,10 @@ struct FieldDef : public Definition {
|
||||
bool Deserialize(Parser &parser, const reflection::Field *field);
|
||||
|
||||
bool IsScalarOptional() const {
|
||||
return IsScalar(value.type.base_type) && IsOptional();
|
||||
return IsScalar() && IsOptional();
|
||||
}
|
||||
bool IsScalar() const {
|
||||
return ::flatbuffers::IsScalar(value.type.base_type);
|
||||
}
|
||||
bool IsOptional() const { return presence == kOptional; }
|
||||
bool IsRequired() const { return presence == kRequired; }
|
||||
@@ -673,6 +676,7 @@ struct IDLOptions {
|
||||
bool binary_schema_comments;
|
||||
bool binary_schema_builtins;
|
||||
bool binary_schema_gen_embed;
|
||||
bool binary_schema_absolute_paths;
|
||||
std::string go_import;
|
||||
std::string go_namespace;
|
||||
std::string go_module_name;
|
||||
@@ -703,6 +707,7 @@ struct IDLOptions {
|
||||
bool keep_proto_id;
|
||||
bool python_no_type_prefix_suffix;
|
||||
bool python_typing;
|
||||
bool ts_omit_entrypoint;
|
||||
ProtoIdGapAction proto_id_gap_action;
|
||||
|
||||
// Possible options for the more general generator below.
|
||||
@@ -725,6 +730,7 @@ struct IDLOptions {
|
||||
kSwift = 1 << 16,
|
||||
kNim = 1 << 17,
|
||||
kProto = 1 << 18,
|
||||
kKotlinKmp = 1 << 19,
|
||||
kMAX
|
||||
};
|
||||
|
||||
@@ -791,6 +797,7 @@ struct IDLOptions {
|
||||
binary_schema_comments(false),
|
||||
binary_schema_builtins(false),
|
||||
binary_schema_gen_embed(false),
|
||||
binary_schema_absolute_paths(false),
|
||||
protobuf_ascii_alike(false),
|
||||
size_prefixed(false),
|
||||
force_defaults(false),
|
||||
@@ -814,6 +821,7 @@ struct IDLOptions {
|
||||
keep_proto_id(false),
|
||||
python_no_type_prefix_suffix(false),
|
||||
python_typing(false),
|
||||
ts_omit_entrypoint(false),
|
||||
proto_id_gap_action(ProtoIdGapAction::WARNING),
|
||||
mini_reflect(IDLOptions::kNone),
|
||||
require_explicit_ids(false),
|
||||
@@ -1214,6 +1222,16 @@ class Parser : public ParserState {
|
||||
// These functions return nullptr on success, or an error string,
|
||||
// which may happen if the flatbuffer cannot be encoded in JSON (e.g.,
|
||||
// it contains non-UTF-8 byte arrays in String values).
|
||||
extern bool GenerateTextFromTable(const Parser &parser,
|
||||
const void *table,
|
||||
const std::string &tablename,
|
||||
std::string *text);
|
||||
extern const char *GenerateText(const Parser &parser, const void *flatbuffer,
|
||||
std::string *text);
|
||||
extern const char *GenerateTextFile(const Parser &parser,
|
||||
const std::string &path,
|
||||
const std::string &file_name);
|
||||
|
||||
extern const char *GenTextFromTable(const Parser &parser, const void *table,
|
||||
const std::string &tablename,
|
||||
std::string *text);
|
||||
|
||||
@@ -408,8 +408,9 @@ inline std::string FlatBufferToString(const uint8_t *buffer,
|
||||
const TypeTable *type_table,
|
||||
bool multi_line = false,
|
||||
bool vector_delimited = true,
|
||||
const std::string &indent = "") {
|
||||
ToStringVisitor tostring_visitor(multi_line ? "\n" : " ", false, indent,
|
||||
const std::string &indent = "",
|
||||
bool quotes = false) {
|
||||
ToStringVisitor tostring_visitor(multi_line ? "\n" : " ", quotes, indent,
|
||||
vector_delimited);
|
||||
IterateFlatBuffer(buffer, type_table, &tostring_visitor);
|
||||
return tostring_visitor.s;
|
||||
|
||||
@@ -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 == 23 &&
|
||||
FLATBUFFERS_VERSION_MINOR == 5 &&
|
||||
FLATBUFFERS_VERSION_REVISION == 26,
|
||||
static_assert(FLATBUFFERS_VERSION_MAJOR == 24 &&
|
||||
FLATBUFFERS_VERSION_MINOR == 3 &&
|
||||
FLATBUFFERS_VERSION_REVISION == 6,
|
||||
"Non-compatible flatbuffers version included");
|
||||
|
||||
namespace reflection {
|
||||
|
||||
@@ -45,7 +45,8 @@
|
||||
// Testing __cpp_lib_span requires including either <version> or <span>,
|
||||
// both of which were added in C++20.
|
||||
// See: https://en.cppreference.com/w/cpp/utility/feature_test
|
||||
#if defined(__cplusplus) && __cplusplus >= 202002L
|
||||
#if defined(__cplusplus) && __cplusplus >= 202002L \
|
||||
|| (defined(_MSVC_LANG) && _MSVC_LANG >= 202002L)
|
||||
#define FLATBUFFERS_USE_STD_SPAN 1
|
||||
#endif
|
||||
#endif // FLATBUFFERS_USE_STD_SPAN
|
||||
|
||||
@@ -31,6 +31,11 @@ struct String : public Vector<char> {
|
||||
flatbuffers::string_view string_view() const {
|
||||
return flatbuffers::string_view(c_str(), size());
|
||||
}
|
||||
|
||||
/* implicit */
|
||||
operator flatbuffers::string_view() const {
|
||||
return flatbuffers::string_view(c_str(), size());
|
||||
}
|
||||
#endif // FLATBUFFERS_HAS_STRING_VIEW
|
||||
// clang-format on
|
||||
|
||||
|
||||
@@ -479,6 +479,11 @@ std::string PosixPath(const std::string &path);
|
||||
// creating dirs for any parts of the path that don't exist yet.
|
||||
void EnsureDirExists(const std::string &filepath);
|
||||
|
||||
// Obtains the relative or absolute path.
|
||||
std::string FilePath(const std::string &project,
|
||||
const std::string &filePath,
|
||||
bool absolute);
|
||||
|
||||
// Obtains the absolute path from any other path.
|
||||
// Returns the input path if the absolute path couldn't be resolved.
|
||||
std::string AbsolutePath(const std::string &filepath);
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>com.google.flatbuffers</groupId>
|
||||
<artifactId>flatbuffers-java</artifactId>
|
||||
<version>23.5.26</version>
|
||||
<version>24.3.6</version>
|
||||
<packaging>bundle</packaging>
|
||||
<name>FlatBuffers Java API</name>
|
||||
<description>
|
||||
|
||||
@@ -46,7 +46,7 @@ public class Constants {
|
||||
Changes to the Java implementation need to be sure to change
|
||||
the version here and in the code generator on every possible
|
||||
incompatible change */
|
||||
public static void FLATBUFFERS_23_5_26() {}
|
||||
public static void FLATBUFFERS_24_3_6() {}
|
||||
}
|
||||
|
||||
/// @endcond
|
||||
|
||||
@@ -42,8 +42,15 @@ public class Utf8Old extends Utf8 {
|
||||
}
|
||||
}
|
||||
|
||||
// ThreadLocal.withInitial() is not used to make the following code compatible with Android API
|
||||
// level 23.
|
||||
private static final ThreadLocal<Cache> CACHE =
|
||||
ThreadLocal.withInitial(() -> new Cache());
|
||||
new ThreadLocal<Cache>() {
|
||||
@Override
|
||||
protected Cache initialValue() {
|
||||
return new Cache();
|
||||
}
|
||||
};
|
||||
|
||||
// Play some games so that the old encoder doesn't pay twice for computing
|
||||
// the length of the encoded string.
|
||||
|
||||
@@ -21,7 +21,7 @@ import java.nio.ByteOrder;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public final class Enum extends Table {
|
||||
public static void ValidateVersion() { Constants.FLATBUFFERS_23_5_26(); }
|
||||
public static void ValidateVersion() { Constants.FLATBUFFERS_24_3_6(); }
|
||||
public static Enum getRootAsEnum(ByteBuffer _bb) { return getRootAsEnum(_bb, new Enum()); }
|
||||
public static Enum getRootAsEnum(ByteBuffer _bb, Enum obj) { _bb.order(ByteOrder.LITTLE_ENDIAN); return (obj.__assign(_bb.getInt(_bb.position()) + _bb.position(), _bb)); }
|
||||
public void __init(int _i, ByteBuffer _bb) { __reset(_i, _bb); }
|
||||
|
||||
@@ -21,7 +21,7 @@ import java.nio.ByteOrder;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public final class EnumVal extends Table {
|
||||
public static void ValidateVersion() { Constants.FLATBUFFERS_23_5_26(); }
|
||||
public static void ValidateVersion() { Constants.FLATBUFFERS_24_3_6(); }
|
||||
public static EnumVal getRootAsEnumVal(ByteBuffer _bb) { return getRootAsEnumVal(_bb, new EnumVal()); }
|
||||
public static EnumVal getRootAsEnumVal(ByteBuffer _bb, EnumVal obj) { _bb.order(ByteOrder.LITTLE_ENDIAN); return (obj.__assign(_bb.getInt(_bb.position()) + _bb.position(), _bb)); }
|
||||
public void __init(int _i, ByteBuffer _bb) { __reset(_i, _bb); }
|
||||
|
||||
@@ -21,7 +21,7 @@ import java.nio.ByteOrder;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public final class Field extends Table {
|
||||
public static void ValidateVersion() { Constants.FLATBUFFERS_23_5_26(); }
|
||||
public static void ValidateVersion() { Constants.FLATBUFFERS_24_3_6(); }
|
||||
public static Field getRootAsField(ByteBuffer _bb) { return getRootAsField(_bb, new Field()); }
|
||||
public static Field getRootAsField(ByteBuffer _bb, Field obj) { _bb.order(ByteOrder.LITTLE_ENDIAN); return (obj.__assign(_bb.getInt(_bb.position()) + _bb.position(), _bb)); }
|
||||
public void __init(int _i, ByteBuffer _bb) { __reset(_i, _bb); }
|
||||
|
||||
@@ -21,7 +21,7 @@ import java.nio.ByteOrder;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public final class KeyValue extends Table {
|
||||
public static void ValidateVersion() { Constants.FLATBUFFERS_23_5_26(); }
|
||||
public static void ValidateVersion() { Constants.FLATBUFFERS_24_3_6(); }
|
||||
public static KeyValue getRootAsKeyValue(ByteBuffer _bb) { return getRootAsKeyValue(_bb, new KeyValue()); }
|
||||
public static KeyValue getRootAsKeyValue(ByteBuffer _bb, KeyValue obj) { _bb.order(ByteOrder.LITTLE_ENDIAN); return (obj.__assign(_bb.getInt(_bb.position()) + _bb.position(), _bb)); }
|
||||
public void __init(int _i, ByteBuffer _bb) { __reset(_i, _bb); }
|
||||
|
||||
@@ -21,7 +21,7 @@ import java.nio.ByteOrder;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public final class Object extends Table {
|
||||
public static void ValidateVersion() { Constants.FLATBUFFERS_23_5_26(); }
|
||||
public static void ValidateVersion() { Constants.FLATBUFFERS_24_3_6(); }
|
||||
public static Object getRootAsObject(ByteBuffer _bb) { return getRootAsObject(_bb, new Object()); }
|
||||
public static Object getRootAsObject(ByteBuffer _bb, Object obj) { _bb.order(ByteOrder.LITTLE_ENDIAN); return (obj.__assign(_bb.getInt(_bb.position()) + _bb.position(), _bb)); }
|
||||
public void __init(int _i, ByteBuffer _bb) { __reset(_i, _bb); }
|
||||
|
||||
@@ -21,7 +21,7 @@ import java.nio.ByteOrder;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public final class RPCCall extends Table {
|
||||
public static void ValidateVersion() { Constants.FLATBUFFERS_23_5_26(); }
|
||||
public static void ValidateVersion() { Constants.FLATBUFFERS_24_3_6(); }
|
||||
public static RPCCall getRootAsRPCCall(ByteBuffer _bb) { return getRootAsRPCCall(_bb, new RPCCall()); }
|
||||
public static RPCCall getRootAsRPCCall(ByteBuffer _bb, RPCCall obj) { _bb.order(ByteOrder.LITTLE_ENDIAN); return (obj.__assign(_bb.getInt(_bb.position()) + _bb.position(), _bb)); }
|
||||
public void __init(int _i, ByteBuffer _bb) { __reset(_i, _bb); }
|
||||
|
||||
@@ -21,7 +21,7 @@ import java.nio.ByteOrder;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public final class Schema extends Table {
|
||||
public static void ValidateVersion() { Constants.FLATBUFFERS_23_5_26(); }
|
||||
public static void ValidateVersion() { Constants.FLATBUFFERS_24_3_6(); }
|
||||
public static Schema getRootAsSchema(ByteBuffer _bb) { return getRootAsSchema(_bb, new Schema()); }
|
||||
public static Schema getRootAsSchema(ByteBuffer _bb, Schema obj) { _bb.order(ByteOrder.LITTLE_ENDIAN); return (obj.__assign(_bb.getInt(_bb.position()) + _bb.position(), _bb)); }
|
||||
public static boolean SchemaBufferHasIdentifier(ByteBuffer _bb) { return __has_identifier(_bb, "BFBS"); }
|
||||
|
||||
@@ -26,7 +26,7 @@ import java.nio.ByteOrder;
|
||||
*/
|
||||
@SuppressWarnings("unused")
|
||||
public final class SchemaFile extends Table {
|
||||
public static void ValidateVersion() { Constants.FLATBUFFERS_23_5_26(); }
|
||||
public static void ValidateVersion() { Constants.FLATBUFFERS_24_3_6(); }
|
||||
public static SchemaFile getRootAsSchemaFile(ByteBuffer _bb) { return getRootAsSchemaFile(_bb, new SchemaFile()); }
|
||||
public static SchemaFile getRootAsSchemaFile(ByteBuffer _bb, SchemaFile obj) { _bb.order(ByteOrder.LITTLE_ENDIAN); return (obj.__assign(_bb.getInt(_bb.position()) + _bb.position(), _bb)); }
|
||||
public void __init(int _i, ByteBuffer _bb) { __reset(_i, _bb); }
|
||||
|
||||
@@ -21,7 +21,7 @@ import java.nio.ByteOrder;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public final class Service extends Table {
|
||||
public static void ValidateVersion() { Constants.FLATBUFFERS_23_5_26(); }
|
||||
public static void ValidateVersion() { Constants.FLATBUFFERS_24_3_6(); }
|
||||
public static Service getRootAsService(ByteBuffer _bb) { return getRootAsService(_bb, new Service()); }
|
||||
public static Service getRootAsService(ByteBuffer _bb, Service obj) { _bb.order(ByteOrder.LITTLE_ENDIAN); return (obj.__assign(_bb.getInt(_bb.position()) + _bb.position(), _bb)); }
|
||||
public void __init(int _i, ByteBuffer _bb) { __reset(_i, _bb); }
|
||||
|
||||
@@ -21,7 +21,7 @@ import java.nio.ByteOrder;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public final class Type extends Table {
|
||||
public static void ValidateVersion() { Constants.FLATBUFFERS_23_5_26(); }
|
||||
public static void ValidateVersion() { Constants.FLATBUFFERS_24_3_6(); }
|
||||
public static Type getRootAsType(ByteBuffer _bb) { return getRootAsType(_bb, new Type()); }
|
||||
public static Type getRootAsType(ByteBuffer _bb, Type obj) { _bb.order(ByteOrder.LITTLE_ENDIAN); return (obj.__assign(_bb.getInt(_bb.position()) + _bb.position(), _bb)); }
|
||||
public void __init(int _i, ByteBuffer _bb) { __reset(_i, _bb); }
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import org.jetbrains.kotlin.ir.backend.js.compile
|
||||
import groovy.xml.XmlParser
|
||||
|
||||
plugins {
|
||||
kotlin("multiplatform")
|
||||
@@ -10,6 +10,18 @@ plugins {
|
||||
group = "com.google.flatbuffers.jmh"
|
||||
version = "2.0.0-SNAPSHOT"
|
||||
|
||||
// Reads latest version from Java's runtime pom.xml,
|
||||
// so we can use it for benchmarking against Kotlin's
|
||||
// runtime
|
||||
fun readJavaFlatBufferVersion(): String {
|
||||
val pom = XmlParser().parse(File("../java/pom.xml"))
|
||||
val versionTag = pom.children().find {
|
||||
val node = it as groovy.util.Node
|
||||
node.name().toString().contains("version")
|
||||
} as groovy.util.Node
|
||||
return versionTag.value().toString()
|
||||
}
|
||||
|
||||
// This plugin generates a static html page with the aggregation
|
||||
// of all benchmarks ran. very useful visualization tool.
|
||||
jmhReport {
|
||||
@@ -27,7 +39,7 @@ benchmark {
|
||||
iterationTime = 300
|
||||
iterationTimeUnit = "ms"
|
||||
// uncomment for benchmarking JSON op only
|
||||
include(".*JsonBenchmark.*")
|
||||
include(".*FlatbufferBenchmark.*")
|
||||
}
|
||||
}
|
||||
targets {
|
||||
@@ -36,24 +48,34 @@ benchmark {
|
||||
}
|
||||
|
||||
kotlin {
|
||||
jvm()
|
||||
jvm {
|
||||
compilations {
|
||||
val main by getting { }
|
||||
// custom benchmark compilation
|
||||
val benchmarks by compilations.creating {
|
||||
defaultSourceSet {
|
||||
dependencies {
|
||||
// Compile against the main compilation's compile classpath and outputs:
|
||||
implementation(main.compileDependencyFiles + main.output.classesDirs)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
sourceSets {
|
||||
|
||||
all {
|
||||
languageSettings.enableLanguageFeature("InlineClasses")
|
||||
}
|
||||
|
||||
val jvmMain by getting {
|
||||
dependencies {
|
||||
implementation(kotlin("stdlib-common"))
|
||||
implementation(project(":flatbuffers-kotlin"))
|
||||
implementation(libs.kotlinx.benchmark.runtime)
|
||||
implementation("com.google.flatbuffers:flatbuffers-java:2.0.3")
|
||||
implementation("com.google.flatbuffers:flatbuffers-java:${readJavaFlatBufferVersion()}")
|
||||
// json serializers
|
||||
implementation(libs.moshi.kotlin)
|
||||
implementation(libs.gson)
|
||||
}
|
||||
kotlin.srcDir("src/jvmMain/generated/kotlin/")
|
||||
kotlin.srcDir("src/jvmMain/generated/java/")
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -67,3 +89,64 @@ tasks.register<de.undercouch.gradle.tasks.download.Download>("downloadMultipleFi
|
||||
dest(File("${project.projectDir.absolutePath}/src/jvmMain/resources"))
|
||||
overwrite(false)
|
||||
}
|
||||
|
||||
abstract class GenerateFBTestClasses : DefaultTask() {
|
||||
@get:InputFiles
|
||||
abstract val inputFiles: ConfigurableFileCollection
|
||||
|
||||
@get:Input
|
||||
abstract val includeFolder: Property<String>
|
||||
|
||||
@get:Input
|
||||
abstract val outputFolder: Property<String>
|
||||
|
||||
@get:Input
|
||||
abstract val variants: ListProperty<String>
|
||||
|
||||
@Inject
|
||||
protected open fun getExecActionFactory(): org.gradle.process.internal.ExecActionFactory? {
|
||||
throw UnsupportedOperationException()
|
||||
}
|
||||
|
||||
init {
|
||||
includeFolder.set("")
|
||||
}
|
||||
|
||||
@TaskAction
|
||||
fun compile() {
|
||||
val execAction = getExecActionFactory()!!.newExecAction()
|
||||
val sources = inputFiles.asPath.split(":")
|
||||
val langs = variants.get().map { "--$it" }
|
||||
val args = mutableListOf("flatc","-o", outputFolder.get(), *langs.toTypedArray())
|
||||
if (includeFolder.get().isNotEmpty()) {
|
||||
args.add("-I")
|
||||
args.add(includeFolder.get())
|
||||
}
|
||||
args.addAll(sources)
|
||||
println(args)
|
||||
execAction.commandLine = args
|
||||
print(execAction.execute())
|
||||
}
|
||||
}
|
||||
|
||||
// Use the default greeting
|
||||
tasks.register<GenerateFBTestClasses>("generateFBTestClassesKt") {
|
||||
inputFiles.setFrom("$projectDir/monster_test_kotlin.fbs")
|
||||
includeFolder.set("$rootDir/../tests/include_test")
|
||||
outputFolder.set("${projectDir}/src/jvmMain/generated/kotlin/")
|
||||
variants.addAll("kotlin-kmp")
|
||||
}
|
||||
|
||||
tasks.register<GenerateFBTestClasses>("generateFBTestClassesJava") {
|
||||
inputFiles.setFrom("$projectDir/monster_test_java.fbs")
|
||||
includeFolder.set("$rootDir/../tests/include_test")
|
||||
outputFolder.set("${projectDir}/src/jvmMain/generated/java/")
|
||||
variants.addAll("kotlin")
|
||||
}
|
||||
|
||||
project.tasks.forEach {
|
||||
if (it.name.contains("compileKotlin")) {
|
||||
it.dependsOn("generateFBTestClassesKt")
|
||||
it.dependsOn("generateFBTestClassesJava")
|
||||
}
|
||||
}
|
||||
|
||||
37
kotlin/benchmark/monster_test_java.fbs
Normal file
37
kotlin/benchmark/monster_test_java.fbs
Normal file
@@ -0,0 +1,37 @@
|
||||
// Example IDL file for our monster's schema.
|
||||
|
||||
namespace jmonster;
|
||||
|
||||
enum JColor:byte { Red = 0, Green, Blue = 2 }
|
||||
|
||||
union JEquipment { JWeapon } // Optionally add more tables.
|
||||
|
||||
struct JVec3 {
|
||||
x:float;
|
||||
y:float;
|
||||
z:float;
|
||||
}
|
||||
|
||||
table JMonster {
|
||||
pos:JVec3;
|
||||
mana:short = 150;
|
||||
hp:short = 100;
|
||||
name:string;
|
||||
friendly:bool = false (deprecated);
|
||||
inventory:[ubyte];
|
||||
color:JColor = Blue;
|
||||
weapons:[JWeapon];
|
||||
equipped:JEquipment;
|
||||
path:[JVec3];
|
||||
}
|
||||
|
||||
table JWeapon {
|
||||
name:string;
|
||||
damage:short;
|
||||
}
|
||||
|
||||
table JAllMonsters {
|
||||
monsters: [JMonster];
|
||||
}
|
||||
|
||||
root_type JAllMonsters;
|
||||
37
kotlin/benchmark/monster_test_kotlin.fbs
Normal file
37
kotlin/benchmark/monster_test_kotlin.fbs
Normal file
@@ -0,0 +1,37 @@
|
||||
// Example IDL file for our monster's schema.
|
||||
|
||||
namespace monster;
|
||||
|
||||
enum Color:byte { Red = 0, Green, Blue = 2 }
|
||||
|
||||
union Equipment { Weapon } // Optionally add more tables.
|
||||
|
||||
struct Vec3 {
|
||||
x:float;
|
||||
y:float;
|
||||
z:float;
|
||||
}
|
||||
|
||||
table Monster {
|
||||
pos:Vec3;
|
||||
mana:short = 150;
|
||||
hp:short = 100;
|
||||
name:string;
|
||||
friendly:bool = false (deprecated);
|
||||
inventory:[ubyte];
|
||||
color:Color = Blue;
|
||||
weapons:[Weapon];
|
||||
equipped:Equipment;
|
||||
path:[Vec3];
|
||||
}
|
||||
|
||||
table Weapon {
|
||||
name:string;
|
||||
damage:short;
|
||||
}
|
||||
|
||||
table AllMonsters {
|
||||
monsters: [Monster];
|
||||
}
|
||||
|
||||
root_type AllMonsters;
|
||||
@@ -1 +0,0 @@
|
||||
../../../../java/src/main/java
|
||||
@@ -0,0 +1,129 @@
|
||||
@file:OptIn(ExperimentalUnsignedTypes::class)
|
||||
|
||||
package com.google.flatbuffers.kotlin.benchmark
|
||||
|
||||
|
||||
import com.google.flatbuffers.kotlin.FlatBufferBuilder
|
||||
import jmonster.JAllMonsters
|
||||
import jmonster.JColor
|
||||
import jmonster.JMonster
|
||||
import jmonster.JVec3
|
||||
import monster.AllMonsters
|
||||
import monster.AllMonsters.Companion.createAllMonsters
|
||||
import monster.AllMonsters.Companion.createMonstersVector
|
||||
import monster.Monster
|
||||
import monster.Monster.Companion.createInventoryVector
|
||||
import monster.MonsterOffsetArray
|
||||
import monster.Vec3
|
||||
import org.openjdk.jmh.annotations.*
|
||||
import org.openjdk.jmh.infra.Blackhole
|
||||
import java.util.concurrent.TimeUnit
|
||||
|
||||
@State(Scope.Benchmark)
|
||||
@BenchmarkMode(Mode.AverageTime)
|
||||
@OutputTimeUnit(TimeUnit.NANOSECONDS)
|
||||
@Measurement(iterations = 20, time = 1, timeUnit = TimeUnit.NANOSECONDS)
|
||||
open class FlatbufferBenchmark {
|
||||
|
||||
val repetition = 1000000
|
||||
val fbKotlin = FlatBufferBuilder(1024 * repetition)
|
||||
val fbDeserializationKotlin = FlatBufferBuilder(1024 * repetition)
|
||||
val fbJava = com.google.flatbuffers.FlatBufferBuilder(1024 * repetition)
|
||||
val fbDeserializationJava = com.google.flatbuffers.FlatBufferBuilder(1024 * repetition)
|
||||
|
||||
init {
|
||||
populateMosterKotlin(fbDeserializationKotlin)
|
||||
populateMosterJava(fbDeserializationJava)
|
||||
}
|
||||
@OptIn(ExperimentalUnsignedTypes::class)
|
||||
private fun populateMosterKotlin(fb: FlatBufferBuilder) {
|
||||
fb.clear()
|
||||
val monsterName = fb.createString("MonsterName");
|
||||
val items = ubyteArrayOf(0u, 1u, 2u, 3u, 4u)
|
||||
val inv = createInventoryVector(fb, items)
|
||||
val monsterOffsets: MonsterOffsetArray = MonsterOffsetArray(repetition) {
|
||||
Monster.startMonster(fb)
|
||||
Monster.addName(fb, monsterName)
|
||||
Monster.addPos(fb, Vec3.createVec3(fb, 1.0f, 2.0f, 3.0f))
|
||||
Monster.addHp(fb, 80)
|
||||
Monster.addMana(fb, 150)
|
||||
Monster.addInventory(fb, inv)
|
||||
Monster.addColor(fb, monster.Color.Red)
|
||||
Monster.endMonster(fb)
|
||||
}
|
||||
val monsters = createMonstersVector(fb, monsterOffsets)
|
||||
val allMonsters = createAllMonsters(fb, monsters)
|
||||
fb.finish(allMonsters)
|
||||
}
|
||||
|
||||
@OptIn(ExperimentalUnsignedTypes::class)
|
||||
private fun populateMosterJava(fb: com.google.flatbuffers.FlatBufferBuilder){
|
||||
fb.clear()
|
||||
val monsterName = fb.createString("MonsterName");
|
||||
val inv = JMonster.createInventoryVector(fb, ubyteArrayOf(0u, 1u, 2u, 3u, 4u))
|
||||
val monsters = JAllMonsters.createMonstersVector(fb, IntArray(repetition) {
|
||||
JMonster.startJMonster(fb)
|
||||
JMonster.addName(fb, monsterName)
|
||||
JMonster.addPos(fb, JVec3.createJVec3(fb, 1.0f, 2.0f, 3.0f))
|
||||
JMonster.addHp(fb, 80)
|
||||
JMonster.addMana(fb, 150)
|
||||
JMonster.addInventory(fb, inv)
|
||||
JMonster.addColor(fb, JColor.Red)
|
||||
JMonster.endJMonster(fb)
|
||||
})
|
||||
val allMonsters = JAllMonsters.createJAllMonsters(fb, monsters)
|
||||
fb.finish(allMonsters)
|
||||
}
|
||||
@Benchmark
|
||||
fun monstersSerializationKotlin() {
|
||||
populateMosterKotlin(fbKotlin)
|
||||
}
|
||||
|
||||
@OptIn(ExperimentalUnsignedTypes::class)
|
||||
@Benchmark
|
||||
fun monstersDeserializationKotlin(hole: Blackhole) {
|
||||
val monstersRef = AllMonsters.asRoot(fbDeserializationKotlin.dataBuffer())
|
||||
|
||||
for (i in 0 until monstersRef.monstersLength) {
|
||||
val monster = monstersRef.monsters(i)!!
|
||||
val pos = monster.pos!!
|
||||
hole.consume(monster.name)
|
||||
hole.consume(pos.x)
|
||||
hole.consume(pos.y)
|
||||
hole.consume(pos.z)
|
||||
hole.consume(monster.hp)
|
||||
hole.consume(monster.mana)
|
||||
hole.consume(monster.color)
|
||||
hole.consume(monster.inventory(0).toByte())
|
||||
hole.consume(monster.inventory(1))
|
||||
hole.consume(monster.inventory(2))
|
||||
hole.consume(monster.inventory(3))
|
||||
}
|
||||
}
|
||||
@Benchmark
|
||||
fun monstersSerializationJava() {
|
||||
populateMosterJava(fbJava)
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
fun monstersDeserializationJava(hole: Blackhole) {
|
||||
val monstersRef = JAllMonsters.getRootAsJAllMonsters(fbDeserializationJava.dataBuffer())
|
||||
|
||||
for (i in 0 until monstersRef.monstersLength) {
|
||||
val monster = monstersRef.monsters(i)!!
|
||||
val pos = monster.pos!!
|
||||
hole.consume(monster.name)
|
||||
hole.consume(pos.x)
|
||||
hole.consume(pos.y)
|
||||
hole.consume(pos.z)
|
||||
hole.consume(monster.hp)
|
||||
hole.consume(monster.mana)
|
||||
hole.consume(monster.color)
|
||||
hole.consume(monster.inventory(0))
|
||||
hole.consume(monster.inventory(1))
|
||||
hole.consume(monster.inventory(2))
|
||||
hole.consume(monster.inventory(3))
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -13,6 +13,8 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
@file:OptIn(ExperimentalUnsignedTypes::class)
|
||||
|
||||
package com.google.flatbuffers.kotlin.benchmark
|
||||
import com.google.flatbuffers.ArrayReadWriteBuf
|
||||
import com.google.flatbuffers.FlexBuffers
|
||||
|
||||
@@ -53,9 +53,10 @@ open class JsonBenchmark {
|
||||
|
||||
val fbParser = JSONParser()
|
||||
|
||||
final val twitterData = this.javaClass.classLoader.getResourceAsStream("twitter.json")!!.readBytes()
|
||||
final val canadaData = this.javaClass.classLoader.getResourceAsStream("canada.json")!!.readBytes()
|
||||
final val citmData = this.javaClass.classLoader.getResourceAsStream("citm_catalog.json")!!.readBytes()
|
||||
final val classLoader = this.javaClass.classLoader
|
||||
final val twitterData = classLoader.getResourceAsStream("twitter.json")!!.readBytes()
|
||||
final val canadaData = classLoader.getResourceAsStream("canada.json")!!.readBytes()
|
||||
final val citmData = classLoader.getResourceAsStream("citm_catalog.json")!!.readBytes()
|
||||
|
||||
val fbCitmRef = JSONParser().parse(ArrayReadBuffer(citmData))
|
||||
val moshiCitmRef = moshi.adapter(Map::class.java).fromJson(citmData.decodeToString())
|
||||
|
||||
@@ -35,14 +35,14 @@ import kotlin.random.Random
|
||||
@BenchmarkMode(Mode.AverageTime)
|
||||
@OutputTimeUnit(TimeUnit.MICROSECONDS)
|
||||
@Measurement(iterations = 100, time = 1, timeUnit = TimeUnit.MICROSECONDS)
|
||||
class UTF8Benchmark {
|
||||
open class UTF8Benchmark {
|
||||
|
||||
private final val sampleSize = 5000
|
||||
private final val stringSize = 25
|
||||
final var sampleSmallUtf8 = (0..sampleSize).map { populateUTF8(stringSize) }.toList()
|
||||
final var sampleSmallUtf8Decoded = sampleSmallUtf8.map { it.encodeToByteArray() }.toList()
|
||||
final var sampleSmallAscii = (0..sampleSize).map { populateAscii(stringSize) }.toList()
|
||||
final var sampleSmallAsciiDecoded = sampleSmallAscii.map { it.encodeToByteArray() }.toList()
|
||||
private val sampleSize = 5000
|
||||
private val stringSize = 25
|
||||
private var sampleSmallUtf8 = (0..sampleSize).map { populateUTF8(stringSize) }.toList()
|
||||
private var sampleSmallUtf8Decoded = sampleSmallUtf8.map { it.encodeToByteArray() }.toList()
|
||||
private var sampleSmallAscii = (0..sampleSize).map { populateAscii(stringSize) }.toList()
|
||||
private var sampleSmallAsciiDecoded = sampleSmallAscii.map { it.encodeToByteArray() }.toList()
|
||||
|
||||
@Setup
|
||||
fun setUp() {
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
group = "com.google.flatbuffers"
|
||||
version = "2.0.0-SNAPSHOT"
|
||||
import org.gradle.internal.impldep.org.testng.ITestResult.STARTED
|
||||
import org.jetbrains.kotlin.gradle.dsl.KotlinCommonOptions
|
||||
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
|
||||
import java.nio.charset.StandardCharsets
|
||||
|
||||
buildscript {
|
||||
repositories {
|
||||
@@ -21,3 +23,22 @@ allprojects {
|
||||
mavenCentral()
|
||||
}
|
||||
}
|
||||
|
||||
tasks.withType<org.jetbrains.kotlin.gradle.dsl.KotlinCompile<KotlinCommonOptions>>().configureEach {
|
||||
kotlinOptions {
|
||||
freeCompilerArgs += "-progressive" // https://kotlinlang.org/docs/whatsnew13.html#progressive-mode
|
||||
}
|
||||
}
|
||||
|
||||
tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinJvmCompile>().configureEach {
|
||||
kotlinOptions {
|
||||
jvmTarget = JavaVersion.VERSION_1_8.toString()
|
||||
freeCompilerArgs += "-Xjvm-default=all"
|
||||
}
|
||||
}
|
||||
|
||||
tasks.withType<JavaCompile> {
|
||||
options.encoding = StandardCharsets.UTF_8.toString()
|
||||
sourceCompatibility = JavaVersion.VERSION_1_8.toString()
|
||||
targetCompatibility = JavaVersion.VERSION_1_8.toString()
|
||||
}
|
||||
|
||||
@@ -1,29 +1,37 @@
|
||||
import org.gradle.internal.impldep.org.fusesource.jansi.AnsiRenderer.test
|
||||
import org.jetbrains.kotlin.gradle.plugin.mpp.apple.XCFramework
|
||||
import org.jetbrains.kotlin.cli.common.toBooleanLenient
|
||||
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget
|
||||
import org.jetbrains.kotlin.gradle.plugin.mpp.NativeBuildType
|
||||
import org.jetbrains.kotlin.gradle.plugin.mpp.apple.XCFrameworkConfig
|
||||
|
||||
plugins {
|
||||
kotlin("multiplatform")
|
||||
}
|
||||
|
||||
|
||||
val libName = "Flatbuffers"
|
||||
group = "com.google.flatbuffers.kotlin"
|
||||
version = "2.0.0-SNAPSHOT"
|
||||
|
||||
kotlin {
|
||||
explicitApi()
|
||||
jvm()
|
||||
js {
|
||||
js(IR) {
|
||||
browser {
|
||||
testTask {
|
||||
useKarma {
|
||||
useChromeHeadless()
|
||||
}
|
||||
testTask {
|
||||
enabled = false
|
||||
}
|
||||
}
|
||||
binaries.executable()
|
||||
}
|
||||
macosX64()
|
||||
iosArm32()
|
||||
macosArm64()
|
||||
iosArm64()
|
||||
iosX64()
|
||||
iosSimulatorArm64()
|
||||
|
||||
sourceSets {
|
||||
|
||||
val commonMain by getting {
|
||||
dependencies {
|
||||
implementation(kotlin("stdlib-common"))
|
||||
@@ -34,47 +42,33 @@ kotlin {
|
||||
dependencies {
|
||||
implementation(kotlin("test"))
|
||||
}
|
||||
|
||||
kotlin.srcDir("src/commonTest/generated/kotlin/")
|
||||
}
|
||||
val jvmTest by getting {
|
||||
dependencies {
|
||||
implementation(kotlin("test-junit"))
|
||||
implementation("com.google.flatbuffers:flatbuffers-java:2.0.3")
|
||||
}
|
||||
}
|
||||
val jvmMain by getting {
|
||||
kotlin.srcDir("java")
|
||||
}
|
||||
|
||||
val jsMain by getting {
|
||||
dependsOn(commonMain)
|
||||
}
|
||||
val jsTest by getting {
|
||||
dependsOn(commonTest)
|
||||
dependencies {
|
||||
implementation(kotlin("test-js"))
|
||||
}
|
||||
}
|
||||
val macosX64Main by getting
|
||||
val macosArm64Main by getting
|
||||
val iosArm64Main by getting
|
||||
val iosSimulatorArm64Main by getting
|
||||
|
||||
val nativeMain by creating {
|
||||
dependsOn(commonMain)
|
||||
}
|
||||
val nativeTest by creating {
|
||||
// this sourceSet will hold common cold for all iOS targets
|
||||
dependsOn(commonMain)
|
||||
}
|
||||
val macosX64Main by getting {
|
||||
dependsOn(nativeMain)
|
||||
}
|
||||
|
||||
val iosArm32Main by getting {
|
||||
dependsOn(nativeMain)
|
||||
}
|
||||
val iosArm64Main by getting {
|
||||
dependsOn(nativeMain)
|
||||
}
|
||||
val iosX64Main by getting {
|
||||
dependsOn(nativeMain)
|
||||
macosArm64Main.dependsOn(this)
|
||||
macosX64Main.dependsOn(this)
|
||||
iosArm64Main.dependsOn(this)
|
||||
iosSimulatorArm64Main.dependsOn(this)
|
||||
}
|
||||
|
||||
all {
|
||||
languageSettings.enableLanguageFeature("InlineClasses")
|
||||
languageSettings.optIn("kotlin.ExperimentalUnsignedTypes")
|
||||
}
|
||||
}
|
||||
@@ -83,4 +77,66 @@ kotlin {
|
||||
// Fixes JS issue: https://youtrack.jetbrains.com/issue/KT-49109
|
||||
rootProject.plugins.withType<org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootPlugin> {
|
||||
rootProject.the<org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootExtension>().nodeVersion = "16.0.0"
|
||||
|
||||
}
|
||||
|
||||
// Use the default greeting
|
||||
tasks.register<GenerateFBTestClasses>("generateFBTestClassesKt") {
|
||||
inputFiles.setFrom("$rootDir/../tests/monster_test.fbs",
|
||||
"$rootDir/../tests/dictionary_lookup.fbs",
|
||||
// @todo Seems like nesting code generation is broken for all generators.
|
||||
// disabling test for now.
|
||||
// "$rootDir/../tests/namespace_test/namespace_test1.fbs",
|
||||
// "$rootDir/../tests/namespace_test/namespace_test2.fbs",
|
||||
"$rootDir/../tests/union_vector/union_vector.fbs",
|
||||
"$rootDir/../tests/optional_scalars.fbs")
|
||||
includeFolder.set("$rootDir/../tests/include_test")
|
||||
outputFolder.set("${projectDir}/src/commonTest/generated/kotlin/")
|
||||
variant.set("kotlin-kmp")
|
||||
}
|
||||
|
||||
|
||||
project.tasks.forEach {
|
||||
if (it.name.contains("compileKotlin"))
|
||||
it.dependsOn("generateFBTestClassesKt")
|
||||
}
|
||||
|
||||
fun String.intProperty() = findProperty(this).toString().toInt()
|
||||
|
||||
abstract class GenerateFBTestClasses : DefaultTask() {
|
||||
@get:InputFiles
|
||||
abstract val inputFiles: ConfigurableFileCollection
|
||||
|
||||
@get:Input
|
||||
abstract val includeFolder: Property<String>
|
||||
|
||||
@get:Input
|
||||
abstract val outputFolder: Property<String>
|
||||
|
||||
@get:Input
|
||||
abstract val variant: Property<String>
|
||||
|
||||
@Inject
|
||||
protected open fun getExecActionFactory(): org.gradle.process.internal.ExecActionFactory? {
|
||||
throw UnsupportedOperationException()
|
||||
}
|
||||
|
||||
init {
|
||||
includeFolder.set("")
|
||||
}
|
||||
|
||||
@TaskAction
|
||||
fun compile() {
|
||||
val execAction = getExecActionFactory()!!.newExecAction()
|
||||
val sources = inputFiles.asPath.split(":")
|
||||
val args = mutableListOf("flatc","-o", outputFolder.get(), "--${variant.get()}")
|
||||
if (includeFolder.get().isNotEmpty()) {
|
||||
args.add("-I")
|
||||
args.add(includeFolder.get())
|
||||
}
|
||||
args.addAll(sources)
|
||||
println(args)
|
||||
execAction.commandLine = args
|
||||
print(execAction.execute())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -110,16 +110,23 @@ public interface ReadBuffer {
|
||||
public fun getDouble(index: Int): Double
|
||||
|
||||
/**
|
||||
* Read an UTF-8 string from the buffer.
|
||||
* Read a UTF-8 string from the buffer.
|
||||
* @param start initial element of the string
|
||||
* @param size size of the string in bytes.
|
||||
* @return a `String`
|
||||
*/
|
||||
public fun getString(start: Int, size: Int): String
|
||||
public fun getString(start: Int = 0, size: Int = limit): String
|
||||
|
||||
/**
|
||||
* Read a ByteArray from the buffer.
|
||||
* @param start position from the [ReadBuffer] to be read
|
||||
* @param length maximum number of bytes to be written in the buffer
|
||||
*/
|
||||
public fun getBytes(array: ByteArray, start: Int, length: Int = array.size)
|
||||
|
||||
/**
|
||||
* Expose [ReadBuffer] as an array of bytes.
|
||||
* This method is meant to be as efficient as possible, so for a array-backed [ReadBuffer], it should
|
||||
* This method is meant to be as efficient as possible, so for an array-backed [ReadBuffer], it should
|
||||
* return its own internal data. In case access to internal data is not possible,
|
||||
* a copy of the data into an array of bytes might occur.
|
||||
* @return [ReadBuffer] as an array of bytes
|
||||
@@ -151,6 +158,29 @@ public interface ReadWriteBuffer : ReadBuffer {
|
||||
*/
|
||||
public fun clear()
|
||||
|
||||
/**
|
||||
* Request capacity of the buffer relative to [writePosition]. In case buffer is already larger
|
||||
* than the requested, this method will just return true. Otherwise,
|
||||
* It might try to resize the buffer. In case of being unable to allocate
|
||||
* enough memory, an exception will be thrown.
|
||||
* @param additional capacity in bytes to be added on top of [writePosition]
|
||||
* @param copyAtEnd copy current data at the end of new underlying buffer
|
||||
* @return new capacity in bytes
|
||||
*/
|
||||
public fun requestAdditionalCapacity(additional: Int, copyAtEnd: Boolean = false): Int =
|
||||
requestCapacity(writePosition + additional, copyAtEnd)
|
||||
|
||||
/**
|
||||
* Request capacity of the buffer in absolute values. In case buffer is already larger
|
||||
* than the requested the method is a no-op. Otherwise,
|
||||
* It might try to resize the buffer. In case of being unable to allocate
|
||||
* enough memory, an exception will be thrown.
|
||||
* @param capacity new capacity
|
||||
* @param copyAtEnd copy current data at the end of new underlying buffer
|
||||
* @return new capacity in bytes
|
||||
*/
|
||||
public fun requestCapacity(capacity: Int, copyAtEnd: Boolean = false): Int
|
||||
|
||||
/**
|
||||
* Put a [Boolean] into the buffer at [writePosition] . Booleans as stored as single byte.
|
||||
* Write position will be incremented.
|
||||
@@ -164,7 +194,15 @@ public interface ReadWriteBuffer : ReadBuffer {
|
||||
* @param start initial position on value to be copied
|
||||
* @param length amount of bytes to be copied
|
||||
*/
|
||||
public fun put(value: ByteArray, start: Int, length: Int)
|
||||
public fun put(value: ByteArray, start: Int = 0, length: Int = value.size)
|
||||
|
||||
/**
|
||||
* Put an array of bytes into the buffer at [writePosition]. Write position will be incremented.
|
||||
* @param value [ReadBuffer] the data to be copied
|
||||
* @param start initial position on value to be copied
|
||||
* @param length amount of bytes to be copied
|
||||
*/
|
||||
public fun put(value: ReadBuffer, start: Int = 0, length: Int = value.limit - start)
|
||||
|
||||
/**
|
||||
* Write a [Byte] into the buffer at [writePosition]. Write position will be incremented.
|
||||
@@ -182,7 +220,7 @@ public interface ReadWriteBuffer : ReadBuffer {
|
||||
public fun put(value: Short)
|
||||
|
||||
/**
|
||||
* Writea [UShort] into in the buffer at [writePosition]. Write position will be incremented.
|
||||
* Write a [UShort] into in the buffer at [writePosition]. Write position will be incremented.
|
||||
*/
|
||||
public fun put(value: UShort)
|
||||
|
||||
@@ -224,7 +262,7 @@ public interface ReadWriteBuffer : ReadBuffer {
|
||||
* Write a [String] encoded as UTF-8 into the buffer at [writePosition]. Write position will be incremented.
|
||||
* @return size in bytes of the encoded string
|
||||
*/
|
||||
public fun put(value: String, encodedLength: Int = -1): Int
|
||||
public fun put(value: CharSequence, encodedLength: Int = -1): Int
|
||||
|
||||
/**
|
||||
* Write an array of bytes into the buffer.
|
||||
@@ -233,7 +271,16 @@ public interface ReadWriteBuffer : ReadBuffer {
|
||||
* @param srcStart initial position on [src] that will be copied.
|
||||
* @param srcLength amount of bytes to be copied
|
||||
*/
|
||||
public operator fun set(dstIndex: Int, src: ByteArray, srcStart: Int, srcLength: Int)
|
||||
public fun set(dstIndex: Int, src: ByteArray, srcStart: Int = 0, srcLength: Int = src.size)
|
||||
|
||||
/**
|
||||
* Write an array of bytes into the buffer.
|
||||
* @param dstIndex initial position where [src] will be copied into.
|
||||
* @param src the data to be copied.
|
||||
* @param srcStart initial position on [src] that will be copied.
|
||||
* @param srcLength amount of bytes to be copied
|
||||
*/
|
||||
public operator fun set(dstIndex: Int, src: ReadBuffer, srcStart: Int = 0, srcLength: Int)
|
||||
|
||||
/**
|
||||
* Write [Boolean] into a given position [index] on the buffer. Booleans as stored as single byte.
|
||||
@@ -301,63 +348,95 @@ public interface ReadWriteBuffer : ReadBuffer {
|
||||
*/
|
||||
public fun set(index: Int, value: Double)
|
||||
|
||||
public fun fill(value: Byte, start: Int, end: Int)
|
||||
|
||||
/**
|
||||
* Current position of the buffer to be written. It will be automatically updated on [put] operations.
|
||||
*/
|
||||
public var writePosition: Int
|
||||
|
||||
/**
|
||||
* Defines the size of the message in the buffer. It also determines last position that buffer
|
||||
* can be read or write. Last byte to be accessed is in position `limit() -1`.
|
||||
* @return indicate last position
|
||||
* Creates a new [ReadWriteBuffer] point to a region of the current buffer, starting at [offset] with size [size].
|
||||
* @param offset starting position of the [ReadWriteBuffer]
|
||||
* @param size in bytes of the [ReadWriteBuffer]
|
||||
* @return [ReadWriteBuffer] slice.
|
||||
*/
|
||||
override val limit: Int
|
||||
public fun writeSlice(offset: Int, size: Int): ReadWriteBuffer
|
||||
|
||||
/**
|
||||
* Request capacity of the buffer. In case buffer is already larger
|
||||
* than the requested, this method will just return true. Otherwise
|
||||
* It might try to resize the buffer. In case of being unable to allocate
|
||||
* enough memory, an exception will be thrown.
|
||||
* Special operation where we increase the backed buffer size to [capacity]
|
||||
* and shift all already written data to the end of the buffer.
|
||||
*
|
||||
* This function is mostly used when creating a Flatbuffer message, as
|
||||
* data is written from the end of the buffer towards index 0.
|
||||
* @param capacity required in bytes
|
||||
* @return new capacity in bytes
|
||||
*/
|
||||
public fun requestCapacity(capacity: Int)
|
||||
public fun moveWrittenDataToEnd(capacity: Int): Int
|
||||
|
||||
/**
|
||||
* Maximum size in bytes that the backed buffer supports.
|
||||
*/
|
||||
public val capacity: Int
|
||||
|
||||
/**
|
||||
* Defines last relative position of the backed buffer that can be written.
|
||||
* Any addition to the buffer that goes beyond will throw an exception
|
||||
* instead of regrow the buffer (default behavior).
|
||||
*/
|
||||
public val writeLimit: Int
|
||||
}
|
||||
|
||||
public open class ArrayReadBuffer(protected var buffer: ByteArray, override val limit: Int = buffer.size) : ReadBuffer {
|
||||
public open class ArrayReadBuffer(protected var buffer: ByteArray,
|
||||
// offsets writePosition against backed buffer e.g. offset = 1, writePosition = 1
|
||||
// will write first byte at position 2 of the backed buffer
|
||||
internal val offset: Int = 0,
|
||||
override val limit: Int = buffer.size - offset) : ReadBuffer {
|
||||
|
||||
|
||||
override fun findFirst(value: Byte, start: Int, end: Int): Int {
|
||||
val e = min(end, limit)
|
||||
val s = max(0, start)
|
||||
val s = max(0, this.offset + start)
|
||||
for (i in s until e) if (buffer[i] == value) return i
|
||||
return -1
|
||||
}
|
||||
|
||||
override fun getBoolean(index: Int): Boolean = buffer[index] != 0.toByte()
|
||||
override fun getBoolean(index: Int): Boolean = buffer[offset + index] != 0.toByte()
|
||||
|
||||
override operator fun get(index: Int): Byte = buffer[index]
|
||||
override operator fun get(index: Int): Byte = buffer[offset + index]
|
||||
|
||||
override fun getUByte(index: Int): UByte = buffer.getUByte(index)
|
||||
override fun getUByte(index: Int): UByte = buffer.getUByte(offset + index)
|
||||
|
||||
override fun getShort(index: Int): Short = buffer.getShort(index)
|
||||
override fun getShort(index: Int): Short = buffer.getShort(offset + index)
|
||||
|
||||
override fun getUShort(index: Int): UShort = buffer.getUShort(index)
|
||||
override fun getUShort(index: Int): UShort = buffer.getUShort(offset + index)
|
||||
|
||||
override fun getInt(index: Int): Int = buffer.getInt(index)
|
||||
override fun getInt(index: Int): Int = buffer.getInt(offset + index)
|
||||
|
||||
override fun getUInt(index: Int): UInt = buffer.getUInt(index)
|
||||
override fun getUInt(index: Int): UInt = buffer.getUInt(offset + index)
|
||||
|
||||
override fun getLong(index: Int): Long = buffer.getLong(index)
|
||||
override fun getLong(index: Int): Long = buffer.getLong(offset + index)
|
||||
|
||||
override fun getULong(index: Int): ULong = buffer.getULong(index)
|
||||
override fun getULong(index: Int): ULong = buffer.getULong(offset + index)
|
||||
|
||||
override fun getFloat(index: Int): Float = buffer.getFloat(index)
|
||||
override fun getFloat(index: Int): Float = buffer.getFloat(offset + index)
|
||||
|
||||
override fun getDouble(index: Int): Double = buffer.getDouble(index)
|
||||
override fun getDouble(index: Int): Double = buffer.getDouble(offset + index)
|
||||
|
||||
override fun getString(start: Int, size: Int): String = buffer.decodeToString(start, start + size)
|
||||
override fun getString(start: Int, size: Int): String = buffer.decodeToString(this.offset + start,
|
||||
this.offset + start + size)
|
||||
|
||||
override fun getBytes(array: ByteArray, start: Int, length: Int) {
|
||||
val end = min(this.offset + start + length, buffer.size)
|
||||
var j = 0
|
||||
for (i in this.offset + start until end) {
|
||||
array[j++] = buffer[i]
|
||||
}
|
||||
}
|
||||
|
||||
override fun data(): ByteArray = buffer
|
||||
|
||||
override fun slice(start: Int, size: Int): ReadBuffer = ArrayReadBuffer(buffer, limit)
|
||||
override fun slice(start: Int, size: Int): ReadBuffer = ArrayReadBuffer(buffer, this.offset + start, size)
|
||||
}
|
||||
/**
|
||||
* Implements `[ReadWriteBuffer]` using [ByteArray] as backing buffer. Using array of bytes are
|
||||
@@ -365,14 +444,20 @@ public open class ArrayReadBuffer(protected var buffer: ByteArray, override val
|
||||
*
|
||||
* This class is not thread-safe, meaning that
|
||||
* it must operate on a single thread. Operating from
|
||||
* multiple thread leads into a undefined behavior
|
||||
* multiple thread leads into an undefined behavior
|
||||
*
|
||||
* All operations assumes Little Endian byte order.
|
||||
* All operations assume Little Endian byte order.
|
||||
*/
|
||||
|
||||
public class ArrayReadWriteBuffer(
|
||||
buffer: ByteArray,
|
||||
override var writePosition: Int = 0
|
||||
) : ArrayReadBuffer(buffer, writePosition), ReadWriteBuffer {
|
||||
offset: Int = 0,
|
||||
// Defines last position of the backed buffer that can be written.
|
||||
// Any addition to the buffer that goes beyond will throw an exception
|
||||
// instead of regrow the buffer (default behavior).
|
||||
public override val writeLimit: Int = -1,
|
||||
override var writePosition: Int = offset
|
||||
) : ArrayReadBuffer(buffer, offset, writePosition), ReadWriteBuffer {
|
||||
|
||||
public constructor(initialCapacity: Int = 10) : this(ByteArray(initialCapacity))
|
||||
|
||||
@@ -390,6 +475,11 @@ public class ArrayReadWriteBuffer(
|
||||
writePosition += length
|
||||
}
|
||||
|
||||
override fun put(value: ReadBuffer, start: Int, length: Int) {
|
||||
set(writePosition, value, start, length)
|
||||
writePosition += length
|
||||
}
|
||||
|
||||
override fun put(value: Byte) {
|
||||
set(writePosition, value)
|
||||
writePosition++
|
||||
@@ -440,50 +530,87 @@ public class ArrayReadWriteBuffer(
|
||||
writePosition += 8
|
||||
}
|
||||
|
||||
override fun put(value: String, encodedLength: Int): Int {
|
||||
override fun put(value: CharSequence, encodedLength: Int): Int {
|
||||
val length = if (encodedLength != -1) encodedLength else Utf8.encodedLength(value)
|
||||
withCapacity(writePosition + length) {
|
||||
writePosition = setString(writePosition, value)
|
||||
}
|
||||
writePosition = buffer.setCharSequence(writePosition, value)
|
||||
return length
|
||||
}
|
||||
|
||||
override fun set(index: Int, value: Boolean) {
|
||||
set(index, if (value) 1.toByte() else 0.toByte())
|
||||
buffer[index] = if (value) 1.toByte() else 0.toByte()
|
||||
}
|
||||
|
||||
override operator fun set(dstIndex: Int, src: ByteArray, srcStart: Int, srcLength: Int) {
|
||||
withCapacity(dstIndex + (srcLength + srcStart)) {
|
||||
src.copyInto(buffer, dstIndex, srcStart, srcStart + srcLength)
|
||||
}
|
||||
override fun set(dstIndex: Int, src: ByteArray, srcStart: Int, srcLength: Int) {
|
||||
src.copyInto(buffer, dstIndex, srcStart, srcStart + srcLength)
|
||||
}
|
||||
|
||||
override operator fun set(index: Int, value: Byte): Unit = withCapacity(index + 1) { set(index, value) }
|
||||
override operator fun set(index: Int, value: UByte): Unit = withCapacity(index + 1) { setUByte(index, value) }
|
||||
override operator fun set(index: Int, value: Short): Unit = withCapacity(index + 2) { setShort(index, value) }
|
||||
override operator fun set(index: Int, value: UShort): Unit = withCapacity(index + 2) { setUShort(index, value) }
|
||||
override operator fun set(index: Int, value: Int): Unit = withCapacity(index + 4) { setInt(index, value) }
|
||||
override operator fun set(index: Int, value: UInt): Unit = withCapacity(index + 4) { setUInt(index, value) }
|
||||
override operator fun set(index: Int, value: Long): Unit = withCapacity(index + 8) { setLong(index, value) }
|
||||
override operator fun set(index: Int, value: ULong): Unit = withCapacity(index + 8) { setULong(index, value) }
|
||||
override operator fun set(index: Int, value: Float): Unit = withCapacity(index + 4) { setFloat(index, value) }
|
||||
override operator fun set(index: Int, value: Double): Unit = withCapacity(index + 8) { setDouble(index, value) }
|
||||
override operator fun set(dstIndex: Int, src: ReadBuffer, srcStart: Int, srcLength: Int) {
|
||||
when(src) {
|
||||
is ArrayReadBuffer -> {
|
||||
src.data().copyInto(buffer, dstIndex, src.offset + srcStart, src.offset + srcStart + srcLength)
|
||||
}
|
||||
else -> {
|
||||
for (i in 0 until srcLength) {
|
||||
buffer[dstIndex + i] = src[srcStart + i]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun requestCapacity(capacity: Int) {
|
||||
override operator fun set(index: Int, value: Byte) { buffer[index] = value }
|
||||
override operator fun set(index: Int, value: UByte) { buffer.setUByte(index, value) }
|
||||
override operator fun set(index: Int, value: Short) { buffer.setShort(index, value) }
|
||||
override operator fun set(index: Int, value: UShort) { buffer.setUShort(index, value) }
|
||||
override operator fun set(index: Int, value: Int) { buffer.setInt(index, value) }
|
||||
override operator fun set(index: Int, value: UInt) { buffer.setUInt(index, value) }
|
||||
override operator fun set(index: Int, value: Long) { buffer.setLong(index, value) }
|
||||
override operator fun set(index: Int, value: ULong) { buffer.setULong(index, value) }
|
||||
override operator fun set(index: Int, value: Float) { buffer.setFloat(index, value) }
|
||||
override operator fun set(index: Int, value: Double) { buffer.setDouble(index, value) }
|
||||
override fun fill(value: Byte, start: Int, end: Int) { buffer.fill(value, start, end) }
|
||||
|
||||
/**
|
||||
* Request capacity of the buffer. In case buffer is already larger
|
||||
* than the requested, it is a no-op. Otherwise,
|
||||
* It might try to resize the buffer. In case of being unable to allocate
|
||||
* enough memory, an exception will be thrown.
|
||||
* @param capacity new capacity
|
||||
* @param copyAtEnd copy current data at the end of new underlying buffer
|
||||
*/
|
||||
override fun requestCapacity(capacity: Int, copyAtEnd: Boolean): Int {
|
||||
if (capacity < 0) error("Capacity may not be negative (likely a previous int overflow)")
|
||||
|
||||
if (buffer.size >= capacity) return
|
||||
if (buffer.size >= capacity) return buffer.size
|
||||
|
||||
if (writeLimit > 0 && writeLimit + offset >= buffer.size) error("Buffer in writeLimit mode. In writeLimit mode" +
|
||||
" the buffer does not grow automatically and any write beyond writeLimit will throw exception. " +
|
||||
"(writeLimit: $writeLimit, newCapacity: $capacity")
|
||||
// implemented in the same growing fashion as ArrayList
|
||||
val oldCapacity = buffer.size
|
||||
var newCapacity = oldCapacity + (oldCapacity shr 1)
|
||||
if (newCapacity < capacity) { // Note: this also catches newCapacity int overflow
|
||||
newCapacity = capacity
|
||||
if (oldCapacity == Int.MAX_VALUE - 8) { // Ensure we don't grow beyond what fits in an int.
|
||||
error("FlatBuffers: cannot grow buffer beyond 2 gigabytes.")
|
||||
}
|
||||
buffer = buffer.copyOf(newCapacity)
|
||||
//(old_buf_size & 0xC0000000) != 0 ? MAX_BUFFER_SIZE : old_buf_size << 1;
|
||||
var newCapacity = 8
|
||||
while (newCapacity < capacity) { // Note: this also catches newCapacity int overflow
|
||||
newCapacity = if (newCapacity and -0x40000000 != 0) Int.MAX_VALUE - 8 else newCapacity shl 1
|
||||
}
|
||||
val newBuffer = ByteArray(newCapacity)
|
||||
|
||||
buffer.copyInto(newBuffer, if (copyAtEnd) newBuffer.size - buffer.size else 0)
|
||||
buffer = newBuffer
|
||||
return newCapacity
|
||||
}
|
||||
|
||||
private inline fun withCapacity(size: Int, crossinline action: ByteArray.() -> Unit) {
|
||||
requestCapacity(size)
|
||||
buffer.action()
|
||||
override fun writeSlice(offset: Int, size: Int): ReadWriteBuffer {
|
||||
return ArrayReadWriteBuffer(this.buffer, offset=offset, writeLimit=size)
|
||||
}
|
||||
|
||||
override fun moveWrittenDataToEnd(capacity: Int): Int = requestCapacity(capacity, true)
|
||||
|
||||
override val capacity: Int
|
||||
get() = buffer.size
|
||||
|
||||
}
|
||||
|
||||
public val emptyBuffer: ReadWriteBuffer = ArrayReadWriteBuffer(ByteArray(1))
|
||||
|
||||
@@ -14,13 +14,14 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
@file:Suppress("NOTHING_TO_INLINE")
|
||||
|
||||
package com.google.flatbuffers.kotlin
|
||||
|
||||
import kotlin.experimental.and
|
||||
|
||||
internal fun ByteArray.getString(index: Int, size: Int): String = Utf8.decodeUtf8Array(this, index, size)
|
||||
|
||||
internal fun ByteArray.setString(index: Int, value: String): Int =
|
||||
internal fun ByteArray.setCharSequence(index: Int, value: CharSequence): Int =
|
||||
Utf8.encodeUtf8Array(value, this, index, this.size - index)
|
||||
|
||||
// List of functions that needs to be implemented on all platforms.
|
||||
@@ -35,7 +36,7 @@ internal expect inline fun ByteArray.getFloat(index: Int): Float
|
||||
internal expect inline fun ByteArray.getDouble(index: Int): Double
|
||||
|
||||
internal expect inline fun ByteArray.setUByte(index: Int, value: UByte)
|
||||
internal expect inline fun ByteArray.setShort(index: Int, value: Short)
|
||||
public expect inline fun ByteArray.setShort(index: Int, value: Short)
|
||||
internal expect inline fun ByteArray.setUShort(index: Int, value: UShort)
|
||||
internal expect inline fun ByteArray.setInt(index: Int, value: Int)
|
||||
internal expect inline fun ByteArray.setUInt(index: Int, value: UInt)
|
||||
@@ -102,43 +103,20 @@ public object ByteArrayOps {
|
||||
public inline fun setUInt(ary: ByteArray, index: Int, value: UInt): Unit = setInt(ary, index, value.toInt())
|
||||
|
||||
public inline fun setLong(ary: ByteArray, index: Int, value: Long) {
|
||||
var idx = index
|
||||
var i = value.toInt()
|
||||
ary[idx++] = (i and 0xff).toByte()
|
||||
ary[idx++] = (i shr 8 and 0xff).toByte()
|
||||
ary[idx++] = (i shr 16 and 0xff).toByte()
|
||||
ary[idx++] = (i shr 24 and 0xff).toByte()
|
||||
setInt(ary, index, i)
|
||||
i = (value shr 32).toInt()
|
||||
ary[idx++] = (i and 0xff).toByte()
|
||||
ary[idx++] = (i shr 8 and 0xff).toByte()
|
||||
ary[idx++] = (i shr 16 and 0xff).toByte()
|
||||
ary[idx] = (i shr 24 and 0xff).toByte()
|
||||
setInt(ary, index + 4, i)
|
||||
}
|
||||
|
||||
public inline fun setULong(ary: ByteArray, index: Int, value: ULong): Unit = setLong(ary, index, value.toLong())
|
||||
|
||||
public inline fun setFloat(ary: ByteArray, index: Int, value: Float) {
|
||||
var idx = index
|
||||
val iValue: Int = value.toRawBits()
|
||||
ary[idx++] = (iValue and 0xff).toByte()
|
||||
ary[idx++] = (iValue shr 8 and 0xff).toByte()
|
||||
ary[idx++] = (iValue shr 16 and 0xff).toByte()
|
||||
ary[idx] = (iValue shr 24 and 0xff).toByte()
|
||||
setInt(ary, index, value.toRawBits())
|
||||
}
|
||||
|
||||
public inline fun setDouble(ary: ByteArray, index: Int, value: Double) {
|
||||
var idx = index
|
||||
val lValue: Long = value.toRawBits()
|
||||
var i = lValue.toInt()
|
||||
ary[idx++] = (i and 0xff).toByte()
|
||||
ary[idx++] = (i shr 8 and 0xff).toByte()
|
||||
ary[idx++] = (i shr 16 and 0xff).toByte()
|
||||
ary[idx++] = (i shr 24 and 0xff).toByte()
|
||||
i = (lValue shr 32).toInt()
|
||||
ary[idx++] = (i and 0xff).toByte()
|
||||
ary[idx++] = (i shr 8 and 0xff).toByte()
|
||||
ary[idx++] = (i shr 16 and 0xff).toByte()
|
||||
ary[idx] = (i shr 24 and 0xff).toByte()
|
||||
setLong(ary, index, value.toRawBits())
|
||||
}
|
||||
|
||||
public inline fun getFloat(ary: ByteArray, index: Int): Float = Float.fromBits(getInt(ary, index))
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,367 @@
|
||||
/*
|
||||
* Copyright 2021 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.
|
||||
*/
|
||||
package com.google.flatbuffers.kotlin
|
||||
|
||||
import kotlin.jvm.JvmInline
|
||||
import kotlin.math.min
|
||||
|
||||
// For now a typealias to guarantee type safety.
|
||||
public typealias UnionOffset = Offset<Any>
|
||||
public typealias UnionOffsetArray = OffsetArray<Any>
|
||||
public typealias StringOffsetArray = OffsetArray<String>
|
||||
|
||||
public inline fun UnionOffsetArray(size: Int, crossinline call: (Int) -> Offset<Any>): UnionOffsetArray =
|
||||
UnionOffsetArray(IntArray(size) { call(it).value })
|
||||
public inline fun StringOffsetArray(size: Int, crossinline call: (Int) -> Offset<String>): StringOffsetArray =
|
||||
StringOffsetArray(IntArray(size) { call(it).value })
|
||||
/**
|
||||
* Represents a "pointer" to a pointer types (table, string, struct) within the buffer
|
||||
*/
|
||||
@JvmInline
|
||||
public value class Offset<T>(public val value: Int) {
|
||||
public fun toUnion(): UnionOffset = UnionOffset(value)
|
||||
}
|
||||
|
||||
/**
|
||||
* Represents an array of offsets. Used to avoid boxing
|
||||
* offset types.
|
||||
*/
|
||||
@JvmInline
|
||||
public value class OffsetArray<T>(public val value: IntArray) {
|
||||
public inline val size: Int
|
||||
get() = value.size
|
||||
public inline operator fun get(index: Int): Offset<T> = Offset(value[index])
|
||||
}
|
||||
|
||||
public inline fun <T> OffsetArray(size: Int, crossinline call: (Int) -> Offset<T>): OffsetArray<T> {
|
||||
return OffsetArray(IntArray(size) { call(it).value })
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Represents a "pointer" to a vector type with elements T
|
||||
*/
|
||||
@JvmInline
|
||||
public value class VectorOffset<T>(public val value: Int)
|
||||
|
||||
public fun <T> Int.toOffset(): Offset<T> = Offset(this)
|
||||
|
||||
public operator fun <T> Offset<T>.minus(other: Int): Offset<T> = Offset(this.value - other)
|
||||
|
||||
public operator fun <T> Int.minus(other: Offset<T>): Int {
|
||||
return this - other.value
|
||||
}
|
||||
/**
|
||||
* All tables in the generated code derive from this class, and add their own accessors.
|
||||
*/
|
||||
public open class Table {
|
||||
|
||||
/** Used to hold the position of the `bb` buffer. */
|
||||
public var bufferPos: Int = 0
|
||||
|
||||
/** The underlying ReadWriteBuffer to hold the data of the Table. */
|
||||
public var bb: ReadWriteBuffer = emptyBuffer
|
||||
|
||||
/** Used to hold the vtable position. */
|
||||
public var vtableStart: Int = 0
|
||||
|
||||
/** Used to hold the vtable size. */
|
||||
public var vtableSize: Int = 0
|
||||
|
||||
protected inline fun <reified T> Int.invalid(default: T, crossinline valid: (Int) -> T) : T =
|
||||
if (this != 0) valid(this) else default
|
||||
|
||||
protected inline fun <reified T> lookupField(i: Int, default: T, crossinline found: (Int) -> T) : T =
|
||||
offset(i).invalid(default) { found(it) }
|
||||
|
||||
/**
|
||||
* Look up a field in the vtable.
|
||||
*
|
||||
* @param vtableOffset An `int` offset to the vtable in the Table's ReadWriteBuffer.
|
||||
* @return Returns an offset into the object, or `0` if the field is not present.
|
||||
*/
|
||||
public fun offset(vtableOffset: Int): Int =
|
||||
if (vtableOffset < vtableSize) bb.getShort(vtableStart + vtableOffset).toInt() else 0
|
||||
|
||||
/**
|
||||
* Retrieve a relative offset.
|
||||
*
|
||||
* @param offset An `int` index into the Table's ReadWriteBuffer containing the relative offset.
|
||||
* @return Returns the relative offset stored at `offset`.
|
||||
*/
|
||||
public fun indirect(offset: Int): Int = offset + bb.getInt(offset)
|
||||
|
||||
/**
|
||||
* Create a Java `String` from UTF-8 data stored inside the FlatBuffer.
|
||||
*
|
||||
* This allocates a new string and converts to wide chars upon each access,
|
||||
* which is not very efficient. Instead, each FlatBuffer string also comes with an
|
||||
* accessor based on __vector_as_ReadWriteBuffer below, which is much more efficient,
|
||||
* assuming your Java program can handle UTF-8 data directly.
|
||||
*
|
||||
* @param offset An `int` index into the Table's ReadWriteBuffer.
|
||||
* @return Returns a `String` from the data stored inside the FlatBuffer at `offset`.
|
||||
*/
|
||||
public fun string(offset: Int): String = string(offset, bb)
|
||||
|
||||
/**
|
||||
* Get the length of a vector.
|
||||
*
|
||||
* @param offset An `int` index into the Table's ReadWriteBuffer.
|
||||
* @return Returns the length of the vector whose offset is stored at `offset`.
|
||||
*/
|
||||
public fun vectorLength(offset: Int): Int {
|
||||
var newOffset = offset
|
||||
newOffset += bufferPos
|
||||
newOffset += bb.getInt(newOffset)
|
||||
return bb.getInt(newOffset)
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the start data of a vector.
|
||||
*
|
||||
* @param offset An `int` index into the Table's ReadWriteBuffer.
|
||||
* @return Returns the start of the vector data whose offset is stored at `offset`.
|
||||
*/
|
||||
public fun vector(offset: Int): Int {
|
||||
var newOffset = offset
|
||||
newOffset += bufferPos
|
||||
return newOffset + bb.getInt(newOffset) + Int.SIZE_BYTES // data starts after the length
|
||||
}
|
||||
/**
|
||||
* Initialize vector as a ReadWriteBuffer.
|
||||
*
|
||||
* This is more efficient than using duplicate, since it doesn't copy the data
|
||||
* nor allocates a new [ReadBuffer], creating no garbage to be collected.
|
||||
*
|
||||
* @param buffer The [ReadBuffer] for the array
|
||||
* @param vectorOffset The position of the vector in the byte buffer
|
||||
* @param elemSize The size of each element in the array
|
||||
* @return The [ReadBuffer] for the array
|
||||
*/
|
||||
public fun vectorAsBuffer(buffer: ReadWriteBuffer, vectorOffset: Int, elemSize: Int): ReadBuffer {
|
||||
val o = offset(vectorOffset)
|
||||
if (o == 0) return emptyBuffer
|
||||
val vectorStart = vector(o)
|
||||
return buffer.slice(vectorStart, vectorLength(o) * elemSize)
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize any Table-derived type to point to the union at the given `offset`.
|
||||
*
|
||||
* @param t A `Table`-derived type that should point to the union at `offset`.
|
||||
* @param offset An `int` index into the Table's ReadWriteBuffer.
|
||||
* @return Returns the Table that points to the union at `offset`.
|
||||
*/
|
||||
public fun union(t: Table, offset: Int): Table = union(t, offset, bb)
|
||||
|
||||
/**
|
||||
* Sort tables by the key.
|
||||
*
|
||||
* @param offsets An 'int' indexes of the tables into the bb.
|
||||
* @param bb A `ReadWriteBuffer` to get the tables.
|
||||
*/
|
||||
public fun <T> sortTables(offsets: Array<Offset<T>>, bb: ReadWriteBuffer) {
|
||||
val off = offsets.sortedWith { o1, o2 -> keysCompare(o1, o2, bb) }
|
||||
for (i in offsets.indices) offsets[i] = off[i]
|
||||
}
|
||||
|
||||
/**
|
||||
* Compare two tables by the key.
|
||||
*
|
||||
* @param o1 An 'Integer' index of the first key into the bb.
|
||||
* @param o2 An 'Integer' index of the second key into the bb.
|
||||
* @param buffer A `ReadWriteBuffer` to get the keys.
|
||||
*/
|
||||
public open fun keysCompare(o1: Offset<*>, o2: Offset<*>, buffer: ReadWriteBuffer): Int = 0
|
||||
|
||||
/**
|
||||
* Re-init the internal state with an external buffer `ReadWriteBuffer` and an offset within.
|
||||
*
|
||||
* This method exists primarily to allow recycling Table instances without risking memory leaks
|
||||
* due to `ReadWriteBuffer` references.
|
||||
*/
|
||||
public inline fun <reified T: Table> reset(i: Int, reuseBuffer: ReadWriteBuffer): T {
|
||||
bb = reuseBuffer
|
||||
if (bb != emptyBuffer) {
|
||||
bufferPos = i
|
||||
vtableStart = bufferPos - bb.getInt(bufferPos)
|
||||
vtableSize = bb.getShort(vtableStart).toInt()
|
||||
} else {
|
||||
bufferPos = 0
|
||||
vtableStart = 0
|
||||
vtableSize = 0
|
||||
}
|
||||
return this as T
|
||||
}
|
||||
|
||||
/**
|
||||
* Resets the internal state with a null `ReadWriteBuffer` and a zero position.
|
||||
*
|
||||
* This method exists primarily to allow recycling Table instances without risking memory leaks
|
||||
* due to `ReadWriteBuffer` references. The instance will be unusable until it is assigned
|
||||
* again to a `ReadWriteBuffer`.
|
||||
*/
|
||||
public inline fun <reified T: Table> reset(): T = reset(0, emptyBuffer)
|
||||
|
||||
public companion object {
|
||||
|
||||
public fun offset(vtableOffset: Int, offset: Offset<*>, bb: ReadWriteBuffer): Int {
|
||||
val vtable: Int = bb.capacity - offset.value
|
||||
return bb.getShort(vtable + vtableOffset - bb.getInt(vtable)) + vtable
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve a relative offset.
|
||||
*
|
||||
* @param offset An `int` index into a ReadWriteBuffer containing the relative offset.
|
||||
* @param bb from which the relative offset will be retrieved.
|
||||
* @return Returns the relative offset stored at `offset`.
|
||||
*/
|
||||
public fun indirect(offset: Int, bb: ReadWriteBuffer): Int {
|
||||
return offset + bb.getInt(offset)
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a Java `String` from UTF-8 data stored inside the FlatBuffer.
|
||||
*
|
||||
* This allocates a new string and converts to wide chars upon each access,
|
||||
* which is not very efficient. Instead, each FlatBuffer string also comes with an
|
||||
* accessor based on __vector_as_ReadWriteBuffer below, which is much more efficient,
|
||||
* assuming your Java program can handle UTF-8 data directly.
|
||||
*
|
||||
* @param offset An `int` index into the Table's ReadWriteBuffer.
|
||||
* @param bb Table ReadWriteBuffer used to read a string at given offset.
|
||||
* @return Returns a `String` from the data stored inside the FlatBuffer at `offset`.
|
||||
*/
|
||||
public fun string(offset: Int, bb: ReadWriteBuffer): String {
|
||||
var newOffset = offset
|
||||
newOffset += bb.getInt(newOffset)
|
||||
val length: Int = bb.getInt(newOffset)
|
||||
return bb.getString(newOffset + Int.SIZE_BYTES, length)
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize any Table-derived type to point to the union at the given `offset`.
|
||||
*
|
||||
* @param t A `Table`-derived type that should point to the union at `offset`.
|
||||
* @param offset An `int` index into the Table's ReadWriteBuffer.
|
||||
* @param bb Table ReadWriteBuffer used to initialize the object Table-derived type.
|
||||
* @return Returns the Table that points to the union at `offset`.
|
||||
*/
|
||||
public fun union(t: Table, offset: Int, bb: ReadWriteBuffer): Table =
|
||||
t.reset(indirect(offset, bb), bb)
|
||||
|
||||
/**
|
||||
* Check if a [ReadWriteBuffer] contains a file identifier.
|
||||
*
|
||||
* @param bb A `ReadWriteBuffer` to check if it contains the identifier
|
||||
* `ident`.
|
||||
* @param ident A `String` identifier of the FlatBuffer file.
|
||||
* @return True if the buffer contains the file identifier
|
||||
*/
|
||||
public fun hasIdentifier(bb: ReadWriteBuffer?, ident: String): Boolean {
|
||||
val identifierLength = 4
|
||||
if (ident.length != identifierLength)
|
||||
throw AssertionError("FlatBuffers: file identifier must be length $identifierLength")
|
||||
for (i in 0 until identifierLength) {
|
||||
if (ident[i].code.toByte() != bb!![bb.limit + Int.SIZE_BYTES + i]) return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
/**
|
||||
* Compare two strings in the buffer.
|
||||
*
|
||||
* @param offsetA An 'int' index of the first string into the bb.
|
||||
* @param offsetB An 'int' index of the second string into the bb.
|
||||
* @param bb A `ReadWriteBuffer` to get the strings.
|
||||
*/
|
||||
public fun compareStrings(offsetA: Int, offsetB: Int, bb: ReadWriteBuffer): Int {
|
||||
var offset1 = offsetA
|
||||
var offset2 = offsetB
|
||||
offset1 += bb.getInt(offset1)
|
||||
offset2 += bb.getInt(offset2)
|
||||
val len1: Int = bb.getInt(offset1)
|
||||
val len2: Int = bb.getInt(offset2)
|
||||
val startPos1: Int = offset1 + Int.SIZE_BYTES
|
||||
val startPos2: Int = offset2 + Int.SIZE_BYTES
|
||||
val len: Int = min(len1, len2)
|
||||
for (i in 0 until len) {
|
||||
if (bb[i + startPos1] != bb[i + startPos2]) {
|
||||
return bb[i + startPos1] - bb[i + startPos2]
|
||||
}
|
||||
}
|
||||
return len1 - len2
|
||||
}
|
||||
|
||||
/**
|
||||
* Compare string from the buffer with the 'String' object.
|
||||
*
|
||||
* @param offset An 'int' index of the first string into the bb.
|
||||
* @param key Second string as a byte array.
|
||||
* @param bb A `ReadWriteBuffer` to get the first string.
|
||||
*/
|
||||
public fun compareStrings(offset: Int, key: ByteArray, bb: ReadWriteBuffer): Int {
|
||||
var offset1 = offset
|
||||
offset1 += bb.getInt(offset1)
|
||||
val len1: Int = bb.getInt(offset1)
|
||||
val len2 = key.size
|
||||
val startPos: Int = offset1 + Int.SIZE_BYTES
|
||||
val len: Int = min(len1, len2)
|
||||
for (i in 0 until len) {
|
||||
if (bb[i + startPos] != key[i]) return bb[i + startPos] - key[i]
|
||||
}
|
||||
return len1 - len2
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* All structs in the generated code derive from this class, and add their own accessors.
|
||||
*/
|
||||
public open class Struct {
|
||||
/** Used to hold the position of the `bb` buffer. */
|
||||
protected var bufferPos: Int = 0
|
||||
|
||||
/** The underlying ByteBuffer to hold the data of the Struct. */
|
||||
protected var bb: ReadWriteBuffer = emptyBuffer
|
||||
|
||||
/**
|
||||
* Re-init the internal state with an external buffer `ByteBuffer` and an offset within.
|
||||
*
|
||||
* This method exists primarily to allow recycling Table instances without risking memory leaks
|
||||
* due to `ByteBuffer` references.
|
||||
*/
|
||||
protected inline fun <reified T: Struct> reset(i: Int, reuseBuffer: ReadWriteBuffer): T {
|
||||
bb = reuseBuffer
|
||||
bufferPos = if (bb != emptyBuffer) i else 0
|
||||
return this as T
|
||||
}
|
||||
|
||||
/**
|
||||
* Resets internal state with a null `ByteBuffer` and a zero position.
|
||||
*
|
||||
* This method exists primarily to allow recycling Struct instances without risking memory leaks
|
||||
* due to `ByteBuffer` references. The instance will be unusable until it is assigned
|
||||
* again to a `ByteBuffer`.
|
||||
*/
|
||||
private inline fun <reified T: Struct> reset(): T = reset(0, emptyBuffer)
|
||||
}
|
||||
|
||||
public inline val <T> T.value: T get() = this
|
||||
|
||||
public const val VERSION_2_0_8: Int = 1
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user