mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-16 01:07:29 +00:00
Compare commits
215 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
38df29380a | ||
|
|
1f438bd40f | ||
|
|
392165432a | ||
|
|
e6bbb3d22e | ||
|
|
a6979fe14a | ||
|
|
bab10754d9 | ||
|
|
ac7ef1176a | ||
|
|
d6444fb7fc | ||
|
|
e223d69b36 | ||
|
|
05cc7a2eff | ||
|
|
8a12183c3b | ||
|
|
21b706b62d | ||
|
|
c5f151ab33 | ||
|
|
3860f1cf7f | ||
|
|
4e582b0c1d | ||
|
|
8396e00dd8 | ||
|
|
48babd417d | ||
|
|
22770f7e85 | ||
|
|
21b033227e | ||
|
|
93f587a6d3 | ||
|
|
8afb68f074 | ||
|
|
2e07f269b9 | ||
|
|
10c994155c | ||
|
|
fc9909c30a | ||
|
|
e35817577c | ||
|
|
9e3fe5d3f6 | ||
|
|
dc9217347e | ||
|
|
a7fed2ce67 | ||
|
|
de3b97355d | ||
|
|
8aa7084f01 | ||
|
|
0f469cad54 | ||
|
|
72e51c61f7 | ||
|
|
31590a8a3b | ||
|
|
24c2432d99 | ||
|
|
292870612c | ||
|
|
57659d9f38 | ||
|
|
2b8e4d3af0 | ||
|
|
08b6372a36 | ||
|
|
9c383559e0 | ||
|
|
c13c3bf956 | ||
|
|
47eeb8f4e9 | ||
|
|
e7c6874192 | ||
|
|
8d2c333b36 | ||
|
|
abc9bfebff | ||
|
|
94d6b8086b | ||
|
|
fa709636b4 | ||
|
|
60463e25a8 | ||
|
|
b8e3d215b8 | ||
|
|
d71c0ab4ac | ||
|
|
fcf75449b8 | ||
|
|
c21bda1649 | ||
|
|
03fffb25e2 | ||
|
|
1a7495a6dd | ||
|
|
3c1bb67ae1 | ||
|
|
5b9de8b6c0 | ||
|
|
ea0a73d168 | ||
|
|
4623cfa4bc | ||
|
|
9c2c56dc6a | ||
|
|
429c28c783 | ||
|
|
e5a9ff757f | ||
|
|
e53732b9b9 | ||
|
|
b84b676c89 | ||
|
|
3211f857d1 | ||
|
|
95ff1f1d80 | ||
|
|
af8997b567 | ||
|
|
0d67abde45 | ||
|
|
d74e2945f7 | ||
|
|
8914d06ab7 | ||
|
|
522f2379a6 | ||
|
|
7cb0bcb212 | ||
|
|
b1e7868db6 | ||
|
|
68e3c839c3 | ||
|
|
0723245085 | ||
|
|
9d64b9c0c0 | ||
|
|
d01f20f2fb | ||
|
|
7e163021e5 | ||
|
|
57fdd4f995 | ||
|
|
8cb53ccc95 | ||
|
|
fb55e0c9de | ||
|
|
d9fde67eb5 | ||
|
|
f74fda299d | ||
|
|
15802fa26c | ||
|
|
a86afae939 | ||
|
|
60910fb7f5 | ||
|
|
7bfaabc358 | ||
|
|
e1407e4341 | ||
|
|
c9a301e601 | ||
|
|
19b2300f93 | ||
|
|
e60c0ab9e2 | ||
|
|
541dd1a8f5 | ||
|
|
7711e84919 | ||
|
|
89430a14d6 | ||
|
|
cfce38ec99 | ||
|
|
5469bc9ef1 | ||
|
|
b39f79e5e9 | ||
|
|
dc623919bd | ||
|
|
a1e125af11 | ||
|
|
0b60686e3d | ||
|
|
17ceaae16e | ||
|
|
a5343d6116 | ||
|
|
4786322b90 | ||
|
|
646a8bc96a | ||
|
|
0e3471d6a7 | ||
|
|
b07589a0f9 | ||
|
|
2062c33cd4 | ||
|
|
adb7add87e | ||
|
|
29f99937c4 | ||
|
|
597e76a268 | ||
|
|
a577050817 | ||
|
|
31ab0bf6c8 | ||
|
|
e4775aa3fe | ||
|
|
97d26ab4ae | ||
|
|
7dd38fa23a | ||
|
|
7350c3668f | ||
|
|
49d2db93a7 | ||
|
|
807b43c0d7 | ||
|
|
4b823b1b98 | ||
|
|
4c47f4c11e | ||
|
|
2b107e20c5 | ||
|
|
84f4b83d3e | ||
|
|
185e41fac4 | ||
|
|
8b02fe6178 | ||
|
|
6e0dad8c5f | ||
|
|
e3e355d498 | ||
|
|
8e901ce17c | ||
|
|
7808ae5c88 | ||
|
|
20068cfa05 | ||
|
|
afd07bdec5 | ||
|
|
2951d5383a | ||
|
|
ba563de877 | ||
|
|
46a2f3f2c2 | ||
|
|
7675121eab | ||
|
|
ea2b5148e5 | ||
|
|
20548ff3b6 | ||
|
|
7ea8db05d8 | ||
|
|
c7b6b66ccb | ||
|
|
ac8b124496 | ||
|
|
88b033b964 | ||
|
|
e68355cb22 | ||
|
|
e3ee24830e | ||
|
|
2a8f4568e0 | ||
|
|
cbf0850828 | ||
|
|
7150dfb5c4 | ||
|
|
fa87eccd1a | ||
|
|
a62f45fed8 | ||
|
|
599847236c | ||
|
|
4173b84d4b | ||
|
|
5fe90a9160 | ||
|
|
78a3d59a65 | ||
|
|
5ed02dc04a | ||
|
|
592dc50037 | ||
|
|
dd77af75b7 | ||
|
|
051604aeb5 | ||
|
|
4b09586652 | ||
|
|
4c0eecd25a | ||
|
|
de25052c72 | ||
|
|
95053e6a47 | ||
|
|
27325e002a | ||
|
|
1872409707 | ||
|
|
c427e1a65d | ||
|
|
caf3b494db | ||
|
|
0e047869da | ||
|
|
881eaab706 | ||
|
|
48eccb83db | ||
|
|
3c0511fa6a | ||
|
|
82396fa0fe | ||
|
|
a6b337f803 | ||
|
|
35230bd70c | ||
|
|
deb3d93454 | ||
|
|
b87d04af8c | ||
|
|
1e6c851dba | ||
|
|
6164edf558 | ||
|
|
ef1030ff0b | ||
|
|
53c8c2ef16 | ||
|
|
f83525fe67 | ||
|
|
b2cce474ba | ||
|
|
067bfdbde9 | ||
|
|
5218e29aa4 | ||
|
|
957e09d684 | ||
|
|
af4b99a1d7 | ||
|
|
b85b90e346 | ||
|
|
ae3821233c | ||
|
|
ff9cba2bff | ||
|
|
1759061908 | ||
|
|
34af7fff70 | ||
|
|
518bf42df8 | ||
|
|
575d616e60 | ||
|
|
f32a7dcbd2 | ||
|
|
860d645349 | ||
|
|
06a53df0d3 | ||
|
|
c526cb640b | ||
|
|
ca73ff34b7 | ||
|
|
2e49b3ba60 | ||
|
|
f830c47d68 | ||
|
|
501810f4d1 | ||
|
|
1047d7ec13 | ||
|
|
07c2eb5fe7 | ||
|
|
c7b9dc83f5 | ||
|
|
4c9079e31b | ||
|
|
64e5252b4e | ||
|
|
00c30807ff | ||
|
|
c15fe421ba | ||
|
|
6b251aa1cf | ||
|
|
6fe8afb3b6 | ||
|
|
00eec2445b | ||
|
|
b8db3a9a6a | ||
|
|
75556437cc | ||
|
|
31beb0fb2f | ||
|
|
dfd92124aa | ||
|
|
a2916d37e7 | ||
|
|
5a95b7b6bc | ||
|
|
595ac94a6a | ||
|
|
5822c1c8dd | ||
|
|
609c72ca1a | ||
|
|
bd1b2d0baf |
@@ -10,7 +10,7 @@ tasks:
|
|||||||
bazel: ${{ bazel }}
|
bazel: ${{ bazel }}
|
||||||
environment:
|
environment:
|
||||||
CC: clang
|
CC: clang
|
||||||
SWIFT_VERSION: "5.9"
|
SWIFT_VERSION: "5.10"
|
||||||
SWIFT_HOME: "$HOME/swift-$SWIFT_VERSION"
|
SWIFT_HOME: "$HOME/swift-$SWIFT_VERSION"
|
||||||
PATH: "$PATH:$SWIFT_HOME/usr/bin"
|
PATH: "$PATH:$SWIFT_HOME/usr/bin"
|
||||||
shell_commands:
|
shell_commands:
|
||||||
@@ -26,7 +26,7 @@ tasks:
|
|||||||
bazel: ${{ bazel }}
|
bazel: ${{ bazel }}
|
||||||
environment:
|
environment:
|
||||||
CC: clang
|
CC: clang
|
||||||
SWIFT_VERSION: "5.9"
|
SWIFT_VERSION: "5.10"
|
||||||
SWIFT_HOME: "$HOME/swift-$SWIFT_VERSION"
|
SWIFT_HOME: "$HOME/swift-$SWIFT_VERSION"
|
||||||
PATH: "$PATH:$SWIFT_HOME/usr/bin"
|
PATH: "$PATH:$SWIFT_HOME/usr/bin"
|
||||||
shell_commands:
|
shell_commands:
|
||||||
|
|||||||
@@ -1,13 +1,5 @@
|
|||||||
---
|
---
|
||||||
Language: Cpp
|
Language: Cpp
|
||||||
BasedOnStyle: Google
|
BasedOnStyle: Google
|
||||||
DerivePointerAlignment: false
|
|
||||||
PointerAlignment: Right
|
|
||||||
IndentPPDirectives: AfterHash
|
|
||||||
Cpp11BracedListStyle: false
|
|
||||||
AlwaysBreakTemplateDeclarations: false
|
|
||||||
AllowShortCaseLabelsOnASingleLine: true
|
|
||||||
SpaceAfterTemplateKeyword: false
|
|
||||||
AllowShortBlocksOnASingleLine: true
|
|
||||||
...
|
...
|
||||||
|
|
||||||
|
|||||||
13
.eslintrc.js
13
.eslintrc.js
@@ -1,13 +0,0 @@
|
|||||||
/* eslint-env node */
|
|
||||||
|
|
||||||
module.exports = {
|
|
||||||
root: true,
|
|
||||||
parser: '@typescript-eslint/parser',
|
|
||||||
plugins: [
|
|
||||||
'@typescript-eslint',
|
|
||||||
],
|
|
||||||
extends: [
|
|
||||||
'eslint:recommended',
|
|
||||||
'plugin:@typescript-eslint/recommended',
|
|
||||||
]
|
|
||||||
};
|
|
||||||
5
.github/CODEOWNERS
vendored
Normal file
5
.github/CODEOWNERS
vendored
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
# Default owner
|
||||||
|
* @dbaileychess derekbailey@google.com
|
||||||
|
|
||||||
|
# Prevent modification of this file
|
||||||
|
.github/CODEOWNERS @dbaileychess derekbailey@google.com
|
||||||
6
.github/dependabot.yml
vendored
Normal file
6
.github/dependabot.yml
vendored
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
version: 2
|
||||||
|
updates:
|
||||||
|
- package-ecosystem: "github-actions"
|
||||||
|
directory: "/"
|
||||||
|
schedule:
|
||||||
|
interval: "weekly"
|
||||||
104
.github/labeler.yml
vendored
104
.github/labeler.yml
vendored
@@ -5,93 +5,133 @@
|
|||||||
#
|
#
|
||||||
# See .github/workflows/label.yml for Github Action workflow script
|
# See .github/workflows/label.yml for Github Action workflow script
|
||||||
|
|
||||||
c#:
|
"c#":
|
||||||
|
- changed-files:
|
||||||
|
- any-glob-to-any-file:
|
||||||
- '**/*.cs'
|
- '**/*.cs'
|
||||||
- net/**/*
|
- 'net/**/*'
|
||||||
- tests/FlatBuffers.Test/**/*
|
- 'tests/FlatBuffers.Test/**/*'
|
||||||
- tests/FlatBuffers.Benchmarks/**/*
|
- 'tests/FlatBuffers.Benchmarks/**/*'
|
||||||
- src/idl_gen_csharp.cpp
|
- 'src/idl_gen_csharp.cpp'
|
||||||
|
|
||||||
swift:
|
swift:
|
||||||
|
- changed-files:
|
||||||
|
- any-glob-to-any-file:
|
||||||
- '**/*.swift'
|
- '**/*.swift'
|
||||||
- swift/**/*
|
- 'swift/**/*'
|
||||||
- tests/swift/**
|
- 'tests/swift/**'
|
||||||
- src/idl_gen_swift.cpp
|
- 'src/idl_gen_swift.cpp'
|
||||||
|
|
||||||
nim:
|
nim:
|
||||||
|
- changed-files:
|
||||||
|
- any-glob-to-any-file:
|
||||||
- '**/*.nim'
|
- '**/*.nim'
|
||||||
- nim/**/*
|
- 'nim/**/*'
|
||||||
- src/idl_gen_nim.cpp
|
- 'src/idl_gen_nim.cpp'
|
||||||
- src/bfbs_gen_nim.cpp
|
- 'src/bfbs_gen_nim.cpp'
|
||||||
|
|
||||||
javascript:
|
javascript:
|
||||||
|
- changed-files:
|
||||||
|
- any-glob-to-any-file:
|
||||||
- '**/*.js'
|
- '**/*.js'
|
||||||
- src/idl_gen_ts.cpp
|
- 'src/idl_gen_ts.cpp'
|
||||||
|
|
||||||
typescript:
|
typescript:
|
||||||
|
- changed-files:
|
||||||
|
- any-glob-to-any-file:
|
||||||
- '**/*.ts'
|
- '**/*.ts'
|
||||||
- src/idl_gen_ts.cpp
|
- 'src/idl_gen_ts.cpp'
|
||||||
- grpc/flatbuffers-js-grpc/**/*.ts
|
- 'grpc/flatbuffers-js-grpc/**/*.ts'
|
||||||
|
|
||||||
golang:
|
golang:
|
||||||
|
- changed-files:
|
||||||
|
- any-glob-to-any-file:
|
||||||
- '**/*.go'
|
- '**/*.go'
|
||||||
- src/idl_gen_go.cpp
|
- 'src/idl_gen_go.cpp'
|
||||||
|
|
||||||
python:
|
python:
|
||||||
|
- changed-files:
|
||||||
|
- any-glob-to-any-file:
|
||||||
- '**/*.py'
|
- '**/*.py'
|
||||||
- src/idl_gen_python.cpp
|
- 'src/idl_gen_python.cpp'
|
||||||
|
|
||||||
java:
|
java:
|
||||||
|
- changed-files:
|
||||||
|
- any-glob-to-any-file:
|
||||||
- '**/*.java'
|
- '**/*.java'
|
||||||
- src/idl_gen_java.cpp
|
- 'src/idl_gen_java.cpp'
|
||||||
|
|
||||||
kotlin:
|
kotlin:
|
||||||
|
- changed-files:
|
||||||
|
- any-glob-to-any-file:
|
||||||
- '**/*.kt'
|
- '**/*.kt'
|
||||||
- src/idl_gen_kotlin.cpp
|
- 'src/idl_gen_kotlin.cpp'
|
||||||
- src/idl_gen_kotlin_kmp.cpp
|
- 'src/idl_gen_kotlin_kmp.cpp'
|
||||||
|
|
||||||
lua:
|
lua:
|
||||||
|
- changed-files:
|
||||||
|
- any-glob-to-any-file:
|
||||||
- '**/*.lua'
|
- '**/*.lua'
|
||||||
- lua/**/*
|
- 'lua/**/*'
|
||||||
- src/bfbs_gen_lua.cpp
|
- 'src/bfbs_gen_lua.cpp'
|
||||||
|
|
||||||
lobster:
|
lobster:
|
||||||
|
- changed-files:
|
||||||
|
- any-glob-to-any-file:
|
||||||
- '**/*.lobster'
|
- '**/*.lobster'
|
||||||
- src/idl_gen_lobster.cpp
|
- 'src/idl_gen_lobster.cpp'
|
||||||
|
|
||||||
php:
|
php:
|
||||||
|
- changed-files:
|
||||||
|
- any-glob-to-any-file:
|
||||||
- '**/*.php'
|
- '**/*.php'
|
||||||
- src/idl_gen_php.cpp
|
- 'src/idl_gen_php.cpp'
|
||||||
|
|
||||||
rust:
|
rust:
|
||||||
|
- changed-files:
|
||||||
|
- any-glob-to-any-file:
|
||||||
- '**/*.rs'
|
- '**/*.rs'
|
||||||
- rust/**/*
|
- 'rust/**/*'
|
||||||
- src/idl_gen_rust.cpp
|
- 'src/idl_gen_rust.cpp'
|
||||||
|
|
||||||
dart:
|
dart:
|
||||||
|
- changed-files:
|
||||||
|
- any-glob-to-any-file:
|
||||||
- '**/*.dart'
|
- '**/*.dart'
|
||||||
- src/idl_gen_dart.cpp
|
- 'src/idl_gen_dart.cpp'
|
||||||
|
|
||||||
c++:
|
"c++":
|
||||||
|
- changed-files:
|
||||||
|
- any-glob-to-any-file:
|
||||||
- '**/*.cc'
|
- '**/*.cc'
|
||||||
- '**/*.cpp'
|
- '**/*.cpp'
|
||||||
- '**/*.h'
|
- '**/*.h'
|
||||||
|
|
||||||
json:
|
json:
|
||||||
|
- changed-files:
|
||||||
|
- any-glob-to-any-file:
|
||||||
- '**/*.json'
|
- '**/*.json'
|
||||||
- src/idl_gen_json_schema.cpp
|
- 'src/idl_gen_json_schema.cpp'
|
||||||
|
|
||||||
codegen:
|
codegen:
|
||||||
- src/**/*
|
- changed-files:
|
||||||
|
- any-glob-to-any-file:
|
||||||
|
- 'src/**/*'
|
||||||
|
|
||||||
documentation:
|
documentation:
|
||||||
- docs/**/*
|
- changed-files:
|
||||||
|
- any-glob-to-any-file:
|
||||||
|
- 'docs/**/*'
|
||||||
- '**/*.md'
|
- '**/*.md'
|
||||||
|
|
||||||
CI:
|
CI:
|
||||||
|
- changed-files:
|
||||||
|
- any-glob-to-any-file:
|
||||||
- '.github/**/*'
|
- '.github/**/*'
|
||||||
- '.bazelci/**/*'
|
- '.bazelci/**/*'
|
||||||
|
|
||||||
grpc:
|
grpc:
|
||||||
- grpc/**/*
|
- changed-files:
|
||||||
- src/idl_gen_grpc.cpp
|
- any-glob-to-any-file:
|
||||||
|
- 'grpc/**/*'
|
||||||
|
- 'src/idl_gen_grpc.cpp'
|
||||||
|
|||||||
201
.github/workflows/build.yml
vendored
201
.github/workflows/build.yml
vendored
@@ -30,7 +30,7 @@ jobs:
|
|||||||
cxx: [g++-13, clang++-18]
|
cxx: [g++-13, clang++-18]
|
||||||
fail-fast: false
|
fail-fast: false
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v6
|
||||||
- name: cmake
|
- name: cmake
|
||||||
run: CXX=${{ matrix.cxx }} cmake -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=Release -DFLATBUFFERS_STRICT_MODE=ON -DFLATBUFFERS_STATIC_FLATC=ON .
|
run: CXX=${{ matrix.cxx }} cmake -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=Release -DFLATBUFFERS_STRICT_MODE=ON -DFLATBUFFERS_STATIC_FLATC=ON .
|
||||||
- name: build
|
- name: build
|
||||||
@@ -42,7 +42,7 @@ jobs:
|
|||||||
chmod +x flatc
|
chmod +x flatc
|
||||||
./flatc --version
|
./flatc --version
|
||||||
- name: upload build artifacts
|
- name: upload build artifacts
|
||||||
uses: actions/upload-artifact@v4
|
uses: actions/upload-artifact@v7
|
||||||
with:
|
with:
|
||||||
name: Linux flatc binary ${{ matrix.cxx }}
|
name: Linux flatc binary ${{ matrix.cxx }}
|
||||||
path: flatc
|
path: flatc
|
||||||
@@ -51,7 +51,7 @@ jobs:
|
|||||||
if: startsWith(github.ref, 'refs/tags/')
|
if: startsWith(github.ref, 'refs/tags/')
|
||||||
run: zip Linux.flatc.binary.${{ matrix.cxx }}.zip flatc
|
run: zip Linux.flatc.binary.${{ matrix.cxx }}.zip flatc
|
||||||
- name: Release zip file
|
- name: Release zip file
|
||||||
uses: softprops/action-gh-release@v1
|
uses: softprops/action-gh-release@v2
|
||||||
if: startsWith(github.ref, 'refs/tags/')
|
if: startsWith(github.ref, 'refs/tags/')
|
||||||
with:
|
with:
|
||||||
files: Linux.flatc.binary.${{ matrix.cxx }}.zip
|
files: Linux.flatc.binary.${{ matrix.cxx }}.zip
|
||||||
@@ -68,7 +68,7 @@ jobs:
|
|||||||
name: Build Linux with -DFLATBUFFERS_NO_FILE_TESTS
|
name: Build Linux with -DFLATBUFFERS_NO_FILE_TESTS
|
||||||
runs-on: ubuntu-24.04
|
runs-on: ubuntu-24.04
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v6
|
||||||
- name: cmake
|
- name: cmake
|
||||||
run: CXX=clang++-18 cmake -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=Release -DFLATBUFFERS_STRICT_MODE=ON -DFLATBUFFERS_CXX_FLAGS="-DFLATBUFFERS_NO_FILE_TESTS" .
|
run: CXX=clang++-18 cmake -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=Release -DFLATBUFFERS_STRICT_MODE=ON -DFLATBUFFERS_CXX_FLAGS="-DFLATBUFFERS_NO_FILE_TESTS" .
|
||||||
- name: build
|
- name: build
|
||||||
@@ -80,7 +80,7 @@ jobs:
|
|||||||
name: Build Linux with out-of-source build location
|
name: Build Linux with out-of-source build location
|
||||||
runs-on: ubuntu-24.04
|
runs-on: ubuntu-24.04
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v6
|
||||||
- name: make build directory
|
- name: make build directory
|
||||||
run: mkdir build
|
run: mkdir build
|
||||||
- name: cmake
|
- name: cmake
|
||||||
@@ -112,7 +112,7 @@ jobs:
|
|||||||
std: 23
|
std: 23
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v6
|
||||||
- name: cmake
|
- name: cmake
|
||||||
run: >
|
run: >
|
||||||
CXX=${{ matrix.cxx }} cmake -G "Unix Makefiles"
|
CXX=${{ matrix.cxx }} cmake -G "Unix Makefiles"
|
||||||
@@ -129,18 +129,18 @@ jobs:
|
|||||||
|
|
||||||
build-cpp-std:
|
build-cpp-std:
|
||||||
name: Build Windows C++
|
name: Build Windows C++
|
||||||
runs-on: windows-2019
|
runs-on: windows-2022
|
||||||
strategy:
|
strategy:
|
||||||
matrix:
|
matrix:
|
||||||
std: [11, 14, 17, 20, 23]
|
std: [11, 14, 17, 20, 23]
|
||||||
fail-fast: false
|
fail-fast: false
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v6
|
||||||
- name: Add msbuild to PATH
|
- name: Add msbuild to PATH
|
||||||
uses: microsoft/setup-msbuild@v1.1
|
uses: microsoft/setup-msbuild@v2
|
||||||
- name: cmake
|
- name: cmake
|
||||||
run: >
|
run: >
|
||||||
cmake -G "Visual Studio 16 2019" -A x64 -DCMAKE_BUILD_TYPE=Release
|
cmake -G "Visual Studio 17 2022" -A x64 -DCMAKE_BUILD_TYPE=Release
|
||||||
-DFLATBUFFERS_STRICT_MODE=ON
|
-DFLATBUFFERS_STRICT_MODE=ON
|
||||||
-DFLATBUFFERS_CPP_STD=${{ matrix.std }}
|
-DFLATBUFFERS_CPP_STD=${{ matrix.std }}
|
||||||
-DFLATBUFFERS_BUILD_CPP17=${{ matrix.std >= 17 && 'On' || 'Off'}}
|
-DFLATBUFFERS_BUILD_CPP17=${{ matrix.std >= 17 && 'On' || 'Off'}}
|
||||||
@@ -157,20 +157,20 @@ jobs:
|
|||||||
contents: write
|
contents: write
|
||||||
outputs:
|
outputs:
|
||||||
digests: ${{ steps.hash.outputs.hashes }}
|
digests: ${{ steps.hash.outputs.hashes }}
|
||||||
name: Build Windows 2019
|
name: Build Windows 2022
|
||||||
runs-on: windows-2019
|
runs-on: windows-2022
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v6
|
||||||
- name: Add msbuild to PATH
|
- name: Add msbuild to PATH
|
||||||
uses: microsoft/setup-msbuild@v1.1
|
uses: microsoft/setup-msbuild@v2
|
||||||
- name: cmake
|
- name: cmake
|
||||||
run: cmake -G "Visual Studio 16 2019" -A x64 -DCMAKE_BUILD_TYPE=Release -DFLATBUFFERS_BUILD_CPP17=ON -DFLATBUFFERS_STRICT_MODE=ON .
|
run: cmake -G "Visual Studio 17 2022" -A x64 -DCMAKE_BUILD_TYPE=Release -DFLATBUFFERS_BUILD_CPP17=ON -DFLATBUFFERS_STRICT_MODE=ON .
|
||||||
- name: build
|
- name: build
|
||||||
run: msbuild.exe FlatBuffers.sln /p:Configuration=Release /p:Platform=x64
|
run: msbuild.exe FlatBuffers.sln /p:Configuration=Release /p:Platform=x64
|
||||||
- name: test
|
- name: test
|
||||||
run: Release\flattests.exe
|
run: Release\flattests.exe
|
||||||
- name: upload build artifacts
|
- name: upload build artifacts
|
||||||
uses: actions/upload-artifact@v4
|
uses: actions/upload-artifact@v7
|
||||||
with:
|
with:
|
||||||
name: Windows flatc binary
|
name: Windows flatc binary
|
||||||
path: Release\flatc.exe
|
path: Release\flatc.exe
|
||||||
@@ -179,7 +179,7 @@ jobs:
|
|||||||
if: startsWith(github.ref, 'refs/tags/')
|
if: startsWith(github.ref, 'refs/tags/')
|
||||||
run: move Release/flatc.exe . && Compress-Archive flatc.exe Windows.flatc.binary.zip
|
run: move Release/flatc.exe . && Compress-Archive flatc.exe Windows.flatc.binary.zip
|
||||||
- name: Release binary
|
- name: Release binary
|
||||||
uses: softprops/action-gh-release@v1
|
uses: softprops/action-gh-release@v2
|
||||||
if: startsWith(github.ref, 'refs/tags/')
|
if: startsWith(github.ref, 'refs/tags/')
|
||||||
with:
|
with:
|
||||||
files: Windows.flatc.binary.zip
|
files: Windows.flatc.binary.zip
|
||||||
@@ -191,25 +191,24 @@ jobs:
|
|||||||
|
|
||||||
build-dotnet-windows:
|
build-dotnet-windows:
|
||||||
name: Build .NET Windows
|
name: Build .NET Windows
|
||||||
runs-on: windows-2022-64core
|
runs-on: windows-2022
|
||||||
strategy:
|
strategy:
|
||||||
matrix:
|
matrix:
|
||||||
configuration: [
|
configuration: [
|
||||||
'',
|
'',
|
||||||
'-p:UnsafeByteBuffer=true',
|
'-p:UnsafeByteBuffer=true',
|
||||||
# Fails two tests currently.
|
'-p:EnableSpanT=true,UnsafeByteBuffer=true'
|
||||||
#'-p:EnableSpanT=true,UnsafeByteBuffer=true'
|
|
||||||
]
|
]
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v6
|
||||||
- name: Setup .NET Core SDK
|
- name: Setup .NET Core SDK
|
||||||
uses: actions/setup-dotnet@v4.2.0
|
uses: actions/setup-dotnet@v5
|
||||||
with:
|
with:
|
||||||
dotnet-version: '8.0.x'
|
dotnet-version: '8.0.x'
|
||||||
- name: Build
|
- name: Build
|
||||||
run: |
|
run: |
|
||||||
cd tests\FlatBuffers.Test
|
cd tests\FlatBuffers.Test
|
||||||
dotnet new sln --force --name FlatBuffers.Test
|
dotnet new sln --force --name FlatBuffers.Test --format sln
|
||||||
dotnet sln FlatBuffers.Test.sln add FlatBuffers.Test.csproj
|
dotnet sln FlatBuffers.Test.sln add FlatBuffers.Test.csproj
|
||||||
dotnet build -c Release ${{matrix.configuration}} FlatBuffers.Test.sln
|
dotnet build -c Release ${{matrix.configuration}} FlatBuffers.Test.sln
|
||||||
- name: Run net6.0
|
- name: Run net6.0
|
||||||
@@ -228,9 +227,9 @@ jobs:
|
|||||||
outputs:
|
outputs:
|
||||||
digests: ${{ steps.hash.outputs.hashes }}
|
digests: ${{ steps.hash.outputs.hashes }}
|
||||||
name: Build Mac (for Intel)
|
name: Build Mac (for Intel)
|
||||||
runs-on: macos-latest-large
|
runs-on: macos-15-intel
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v6
|
||||||
- name: cmake
|
- name: cmake
|
||||||
run: cmake -G "Xcode" -DCMAKE_OSX_ARCHITECTURES="x86_64" -DCMAKE_BUILD_TYPE=Release -DFLATBUFFERS_STRICT_MODE=ON .
|
run: cmake -G "Xcode" -DCMAKE_OSX_ARCHITECTURES="x86_64" -DCMAKE_BUILD_TYPE=Release -DFLATBUFFERS_STRICT_MODE=ON .
|
||||||
- name: build
|
- name: build
|
||||||
@@ -247,7 +246,7 @@ jobs:
|
|||||||
chmod +x Release/flatc
|
chmod +x Release/flatc
|
||||||
Release/flatc --version
|
Release/flatc --version
|
||||||
- name: upload build artifacts
|
- name: upload build artifacts
|
||||||
uses: actions/upload-artifact@v4
|
uses: actions/upload-artifact@v7
|
||||||
with:
|
with:
|
||||||
name: Mac flatc binary Intel
|
name: Mac flatc binary Intel
|
||||||
path: Release/flatc
|
path: Release/flatc
|
||||||
@@ -256,7 +255,7 @@ jobs:
|
|||||||
if: startsWith(github.ref, 'refs/tags/')
|
if: startsWith(github.ref, 'refs/tags/')
|
||||||
run: mv Release/flatc . && zip MacIntel.flatc.binary.zip flatc
|
run: mv Release/flatc . && zip MacIntel.flatc.binary.zip flatc
|
||||||
- name: Release binary
|
- name: Release binary
|
||||||
uses: softprops/action-gh-release@v1
|
uses: softprops/action-gh-release@v2
|
||||||
if: startsWith(github.ref, 'refs/tags/')
|
if: startsWith(github.ref, 'refs/tags/')
|
||||||
with:
|
with:
|
||||||
files: MacIntel.flatc.binary.zip
|
files: MacIntel.flatc.binary.zip
|
||||||
@@ -273,7 +272,7 @@ jobs:
|
|||||||
name: Build Mac (universal build)
|
name: Build Mac (universal build)
|
||||||
runs-on: macos-latest
|
runs-on: macos-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v6
|
||||||
- name: cmake
|
- name: cmake
|
||||||
run: cmake -G "Xcode" -DCMAKE_OSX_ARCHITECTURES="arm64;x86_64" -DCMAKE_BUILD_TYPE=Release -DFLATBUFFERS_STRICT_MODE=ON .
|
run: cmake -G "Xcode" -DCMAKE_OSX_ARCHITECTURES="arm64;x86_64" -DCMAKE_BUILD_TYPE=Release -DFLATBUFFERS_STRICT_MODE=ON .
|
||||||
- name: build
|
- name: build
|
||||||
@@ -290,7 +289,7 @@ jobs:
|
|||||||
chmod +x Release/flatc
|
chmod +x Release/flatc
|
||||||
Release/flatc --version
|
Release/flatc --version
|
||||||
- name: upload build artifacts
|
- name: upload build artifacts
|
||||||
uses: actions/upload-artifact@v4
|
uses: actions/upload-artifact@v7
|
||||||
with:
|
with:
|
||||||
name: Mac flatc binary Universal
|
name: Mac flatc binary Universal
|
||||||
path: Release/flatc
|
path: Release/flatc
|
||||||
@@ -299,7 +298,7 @@ jobs:
|
|||||||
if: startsWith(github.ref, 'refs/tags/')
|
if: startsWith(github.ref, 'refs/tags/')
|
||||||
run: mv Release/flatc . && zip Mac.flatc.binary.zip flatc
|
run: mv Release/flatc . && zip Mac.flatc.binary.zip flatc
|
||||||
- name: Release binary
|
- name: Release binary
|
||||||
uses: softprops/action-gh-release@v1
|
uses: softprops/action-gh-release@v2
|
||||||
if: startsWith(github.ref, 'refs/tags/')
|
if: startsWith(github.ref, 'refs/tags/')
|
||||||
with:
|
with:
|
||||||
files: Mac.flatc.binary.zip
|
files: Mac.flatc.binary.zip
|
||||||
@@ -310,14 +309,17 @@ jobs:
|
|||||||
|
|
||||||
build-android:
|
build-android:
|
||||||
name: Build Android (on Linux)
|
name: Build Android (on Linux)
|
||||||
|
if: false #disabled due to continual failure
|
||||||
runs-on: ubuntu-24.04
|
runs-on: ubuntu-24.04
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v6
|
||||||
- name: set up Java
|
- name: set up Java
|
||||||
uses: actions/setup-java@v3
|
uses: actions/setup-java@v5
|
||||||
with:
|
with:
|
||||||
distribution: 'temurin'
|
distribution: temurin
|
||||||
java-version: '11'
|
java-version: 17
|
||||||
|
- name: set up Gradle
|
||||||
|
uses: gradle/actions/setup-gradle@v5
|
||||||
- name: set up flatc
|
- name: set up flatc
|
||||||
run: |
|
run: |
|
||||||
cmake -DFLATBUFFERS_BUILD_TESTS=OFF -DFLATBUFFERS_BUILD_FLATLIB=OFF -DFLATBUFFERS_BUILD_FLATHASH=OFF -DFLATBUFFERS_STRICT_MODE=ON .
|
cmake -DFLATBUFFERS_BUILD_TESTS=OFF -DFLATBUFFERS_BUILD_FLATLIB=OFF -DFLATBUFFERS_BUILD_FLATHASH=OFF -DFLATBUFFERS_STRICT_MODE=ON .
|
||||||
@@ -334,7 +336,7 @@ jobs:
|
|||||||
matrix:
|
matrix:
|
||||||
cxx: [g++-13, clang++-18]
|
cxx: [g++-13, clang++-18]
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v6
|
||||||
- name: cmake
|
- name: cmake
|
||||||
run: CXX=${{ matrix.cxx }} cmake -G "Unix Makefiles" -DFLATBUFFERS_BUILD_TESTS=OFF -DCMAKE_BUILD_TYPE=Release -DFLATBUFFERS_STRICT_MODE=ON . && make -j
|
run: CXX=${{ matrix.cxx }} cmake -G "Unix Makefiles" -DFLATBUFFERS_BUILD_TESTS=OFF -DCMAKE_BUILD_TYPE=Release -DFLATBUFFERS_STRICT_MODE=ON . && make -j
|
||||||
- name: Generate
|
- name: Generate
|
||||||
@@ -344,13 +346,13 @@ jobs:
|
|||||||
|
|
||||||
build-generator-windows:
|
build-generator-windows:
|
||||||
name: Check Generated Code on Windows
|
name: Check Generated Code on Windows
|
||||||
runs-on: windows-2019
|
runs-on: windows-2022
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v6
|
||||||
- name: Add msbuild to PATH
|
- name: Add msbuild to PATH
|
||||||
uses: microsoft/setup-msbuild@v1.1
|
uses: microsoft/setup-msbuild@v2
|
||||||
- name: cmake
|
- name: cmake
|
||||||
run: cmake -G "Visual Studio 16 2019" -A x64 -DCMAKE_BUILD_TYPE=Release -DFLATBUFFERS_BUILD_CPP17=ON -DFLATBUFFERS_STRICT_MODE=ON .
|
run: cmake -G "Visual Studio 17 2022" -A x64 -DCMAKE_BUILD_TYPE=Release -DFLATBUFFERS_BUILD_CPP17=ON -DFLATBUFFERS_STRICT_MODE=ON .
|
||||||
- name: build
|
- name: build
|
||||||
run: msbuild.exe FlatBuffers.sln /p:Configuration=Release /p:Platform=x64
|
run: msbuild.exe FlatBuffers.sln /p:Configuration=Release /p:Platform=x64
|
||||||
- name: Generate
|
- name: Generate
|
||||||
@@ -365,13 +367,13 @@ jobs:
|
|||||||
matrix:
|
matrix:
|
||||||
cxx: [g++-13]
|
cxx: [g++-13]
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v6
|
||||||
- name: cmake
|
- name: cmake
|
||||||
run: CXX=${{ matrix.cxx }} cmake -G "Unix Makefiles" -DFLATBUFFERS_CXX_FLAGS="-Wno-unused-parameter -fno-aligned-new" -DFLATBUFFERS_BUILD_BENCHMARKS=ON -DCMAKE_BUILD_TYPE=Release -DFLATBUFFERS_STRICT_MODE=ON . && make -j
|
run: CXX=${{ matrix.cxx }} cmake -G "Unix Makefiles" -DFLATBUFFERS_CXX_FLAGS="-Wno-unused-parameter -fno-aligned-new" -DFLATBUFFERS_BUILD_BENCHMARKS=ON -DCMAKE_BUILD_TYPE=Release -DFLATBUFFERS_STRICT_MODE=ON . && make -j
|
||||||
- name: Run benchmarks
|
- name: Run benchmarks
|
||||||
run: ./flatbenchmark --benchmark_repetitions=5 --benchmark_display_aggregates_only=true --benchmark_out_format=console --benchmark_out=benchmarks/results_${{matrix.cxx}}
|
run: ./flatbenchmark --benchmark_repetitions=5 --benchmark_display_aggregates_only=true --benchmark_out_format=console --benchmark_out=benchmarks/results_${{matrix.cxx}}
|
||||||
- name: Upload benchmarks results
|
- name: Upload benchmarks results
|
||||||
uses: actions/upload-artifact@v4
|
uses: actions/upload-artifact@v7
|
||||||
with:
|
with:
|
||||||
name: Linux flatbenchmark results ${{matrix.cxx}}
|
name: Linux flatbenchmark results ${{matrix.cxx}}
|
||||||
path: benchmarks/results_${{matrix.cxx}}
|
path: benchmarks/results_${{matrix.cxx}}
|
||||||
@@ -380,29 +382,24 @@ jobs:
|
|||||||
name: Build Java
|
name: Build Java
|
||||||
runs-on: ubuntu-24.04
|
runs-on: ubuntu-24.04
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v6
|
||||||
- name: test
|
- name: test
|
||||||
working-directory: java
|
working-directory: java
|
||||||
run: mvn test
|
run: mvn test
|
||||||
|
|
||||||
build-kotlin-macos:
|
build-kotlin-macos:
|
||||||
name: Build Kotlin MacOS
|
name: Build Kotlin MacOS
|
||||||
runs-on: macos-13
|
runs-on: macos-15
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v3
|
uses: actions/checkout@v6
|
||||||
# Force Xcode 14.3 since Xcode 15 doesnt support older versions of
|
- name: set up Java
|
||||||
# kotlin. For Xcode 15, kotlin should be bumpped to 1.9.10
|
uses: actions/setup-java@v5
|
||||||
# https://stackoverflow.com/a/77150623
|
|
||||||
# For now, run with macos-13 which has this 14.3 installed:
|
|
||||||
# https://github.com/actions/runner-images/blob/main/images/macos/macos-13-Readme.md#xcode
|
|
||||||
- name: Set up Xcode version
|
|
||||||
run: sudo xcode-select -s /Applications/Xcode_14.3.app/Contents/Developer
|
|
||||||
- uses: gradle/wrapper-validation-action@v1.0.5
|
|
||||||
- uses: actions/setup-java@v3
|
|
||||||
with:
|
with:
|
||||||
distribution: 'temurin'
|
distribution: temurin
|
||||||
java-version: '11'
|
java-version: 17
|
||||||
|
- name: set up Gradle
|
||||||
|
uses: gradle/actions/setup-gradle@v5
|
||||||
- name: Build flatc
|
- name: Build flatc
|
||||||
run: |
|
run: |
|
||||||
cmake -DFLATBUFFERS_BUILD_TESTS=OFF -DFLATBUFFERS_BUILD_FLATLIB=OFF -DFLATBUFFERS_BUILD_FLATHASH=OFF .
|
cmake -DFLATBUFFERS_BUILD_TESTS=OFF -DFLATBUFFERS_BUILD_FLATLIB=OFF -DFLATBUFFERS_BUILD_FLATHASH=OFF .
|
||||||
@@ -414,15 +411,18 @@ jobs:
|
|||||||
|
|
||||||
build-kotlin-linux:
|
build-kotlin-linux:
|
||||||
name: Build Kotlin Linux
|
name: Build Kotlin Linux
|
||||||
|
if: false #disabled due to continual failure
|
||||||
runs-on: ubuntu-24.04
|
runs-on: ubuntu-24.04
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v3
|
uses: actions/checkout@v6
|
||||||
- uses: actions/setup-java@v3
|
- name: set up Java
|
||||||
|
uses: actions/setup-java@v5
|
||||||
with:
|
with:
|
||||||
distribution: 'temurin'
|
distribution: temurin
|
||||||
java-version: '11'
|
java-version: 17
|
||||||
- uses: gradle/wrapper-validation-action@v1.0.5
|
- name: set up Gradle
|
||||||
|
uses: gradle/actions/setup-gradle@v5
|
||||||
- name: Build flatc
|
- name: Build flatc
|
||||||
run: |
|
run: |
|
||||||
cmake -DFLATBUFFERS_BUILD_TESTS=OFF -DFLATBUFFERS_BUILD_FLATLIB=OFF -DFLATBUFFERS_BUILD_FLATHASH=OFF .
|
cmake -DFLATBUFFERS_BUILD_TESTS=OFF -DFLATBUFFERS_BUILD_FLATLIB=OFF -DFLATBUFFERS_BUILD_FLATHASH=OFF .
|
||||||
@@ -439,16 +439,16 @@ jobs:
|
|||||||
name: Build Rust Linux
|
name: Build Rust Linux
|
||||||
runs-on: ubuntu-24.04
|
runs-on: ubuntu-24.04
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v6
|
||||||
- name: test
|
- name: test
|
||||||
working-directory: tests
|
working-directory: tests
|
||||||
run: bash RustTest.sh
|
run: bash RustTest.sh
|
||||||
|
|
||||||
build-rust-windows:
|
build-rust-windows:
|
||||||
name: Build Rust Windows
|
name: Build Rust Windows
|
||||||
runs-on: windows-2022-64core
|
runs-on: windows-2022
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v6
|
||||||
- name: test
|
- name: test
|
||||||
working-directory: tests
|
working-directory: tests
|
||||||
run: ./RustTest.bat
|
run: ./RustTest.bat
|
||||||
@@ -457,7 +457,7 @@ jobs:
|
|||||||
name: Build Python
|
name: Build Python
|
||||||
runs-on: ubuntu-24.04
|
runs-on: ubuntu-24.04
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v6
|
||||||
- name: flatc
|
- name: flatc
|
||||||
# FIXME: make test script not rely on flatc
|
# FIXME: make test script not rely on flatc
|
||||||
run: cmake -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=Release -DFLATBUFFERS_BUILD_TESTS=OFF -DFLATBUFFERS_INSTALL=OFF -DFLATBUFFERS_BUILD_FLATLIB=OFF -DFLATBUFFERS_BUILD_FLATHASH=OFF -DFLATBUFFERS_STRICT_MODE=ON . && make -j
|
run: cmake -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=Release -DFLATBUFFERS_BUILD_TESTS=OFF -DFLATBUFFERS_INSTALL=OFF -DFLATBUFFERS_BUILD_FLATLIB=OFF -DFLATBUFFERS_BUILD_FLATHASH=OFF -DFLATBUFFERS_STRICT_MODE=ON . && make -j
|
||||||
@@ -469,7 +469,7 @@ jobs:
|
|||||||
name: Build Go
|
name: Build Go
|
||||||
runs-on: ubuntu-24.04
|
runs-on: ubuntu-24.04
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v6
|
||||||
- name: flatc
|
- name: flatc
|
||||||
# FIXME: make test script not rely on flatc
|
# FIXME: make test script not rely on flatc
|
||||||
run: cmake -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=Release -DFLATBUFFERS_BUILD_TESTS=OFF -DFLATBUFFERS_INSTALL=OFF -DFLATBUFFERS_BUILD_FLATLIB=OFF -DFLATBUFFERS_BUILD_FLATHASH=OFF -DFLATBUFFERS_STRICT_MODE=ON . && make -j
|
run: cmake -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=Release -DFLATBUFFERS_BUILD_TESTS=OFF -DFLATBUFFERS_INSTALL=OFF -DFLATBUFFERS_BUILD_FLATLIB=OFF -DFLATBUFFERS_BUILD_FLATHASH=OFF -DFLATBUFFERS_STRICT_MODE=ON . && make -j
|
||||||
@@ -481,7 +481,7 @@ jobs:
|
|||||||
name: Build PHP
|
name: Build PHP
|
||||||
runs-on: ubuntu-24.04
|
runs-on: ubuntu-24.04
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v6
|
||||||
- name: flatc
|
- name: flatc
|
||||||
# FIXME: make test script not rely on flatc
|
# FIXME: make test script not rely on flatc
|
||||||
run: cmake -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=Release -DFLATBUFFERS_BUILD_TESTS=OFF -DFLATBUFFERS_INSTALL=OFF -DFLATBUFFERS_BUILD_FLATLIB=OFF -DFLATBUFFERS_BUILD_FLATHASH=OFF -DFLATBUFFERS_STRICT_MODE=ON . && make -j
|
run: cmake -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=Release -DFLATBUFFERS_BUILD_TESTS=OFF -DFLATBUFFERS_INSTALL=OFF -DFLATBUFFERS_BUILD_FLATLIB=OFF -DFLATBUFFERS_BUILD_FLATHASH=OFF -DFLATBUFFERS_STRICT_MODE=ON . && make -j
|
||||||
@@ -492,63 +492,74 @@ jobs:
|
|||||||
sh phpUnionVectorTest.sh
|
sh phpUnionVectorTest.sh
|
||||||
|
|
||||||
build-swift:
|
build-swift:
|
||||||
name: Build Swift
|
name: Test Swift Linux
|
||||||
strategy:
|
strategy:
|
||||||
matrix:
|
matrix:
|
||||||
swift: ["5.9", "5.10", "6.0"]
|
swift: ["6.0", "6.1", "6.2"]
|
||||||
# Only 22.04 has swift at the moment https://github.com/actions/runner-images/blob/main/images/ubuntu/Ubuntu2204-Readme.md?plain=1#L30
|
runs-on: ubuntu-24.04
|
||||||
runs-on: ubuntu-22.04
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v6
|
||||||
- uses: swift-actions/setup-swift@v2
|
- uses: swift-actions/setup-swift@v2
|
||||||
with:
|
with:
|
||||||
swift-version: ${{ matrix.swift }}
|
swift-version: ${{ matrix.swift }}
|
||||||
- name: Get swift version
|
- name: Get swift version
|
||||||
run: swift --version
|
run: swift --version
|
||||||
- name: test
|
- name: test
|
||||||
working-directory: tests/swift/tests
|
run: swift test
|
||||||
run: |
|
|
||||||
swift build --build-tests
|
build-swift-windows:
|
||||||
swift test
|
name: Test swift windows
|
||||||
|
runs-on: windows-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v6
|
||||||
|
- uses: SwiftyLab/setup-swift@latest
|
||||||
|
with:
|
||||||
|
swift-version: '6.1'
|
||||||
|
- run: swift build
|
||||||
|
- run: swift test
|
||||||
|
|
||||||
build-swift-wasm:
|
build-swift-wasm:
|
||||||
name: Build Swift Wasm
|
name: Test Swift Wasm
|
||||||
runs-on: ubuntu-24.04
|
runs-on: ubuntu-24.04
|
||||||
container:
|
|
||||||
image: ghcr.io/swiftwasm/carton:0.20.1
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v6
|
||||||
- uses: bytecodealliance/actions/wasmtime/setup@v1
|
- uses: swift-actions/setup-swift@v2
|
||||||
- uses: swiftwasm/setup-swiftwasm@v1
|
|
||||||
with:
|
with:
|
||||||
swift-version: "wasm-6.0.2-RELEASE"
|
swift-version: 6.2.1
|
||||||
|
- uses: bytecodealliance/actions/wasmtime/setup@v1
|
||||||
|
- name: Install Swift SDK
|
||||||
|
run: swift sdk install https://download.swift.org/swift-6.2.1-release/wasm-sdk/swift-6.2.1-RELEASE/swift-6.2.1-RELEASE_wasm.artifactbundle.tar.gz --checksum 482b9f95462b87bedfafca94a092cf9ec4496671ca13b43745097122d20f18af
|
||||||
- name: Test
|
- name: Test
|
||||||
working-directory: tests/swift/Wasm.tests
|
working-directory: tests/swift/Wasm.tests
|
||||||
run: swift run carton test
|
run: |
|
||||||
|
swift sdk list
|
||||||
|
swift build --build-tests --swift-sdk swift-6.2.1-RELEASE_wasm
|
||||||
|
wasmtime --dir . .build/wasm32-unknown-wasip1/debug/FlatBuffers.Test.Swift.WasmPackageTests.xctest --testing-library swift-testing
|
||||||
|
|
||||||
build-ts:
|
build-ts:
|
||||||
name: Build TS
|
name: Build TS
|
||||||
runs-on: ubuntu-24.04
|
runs-on: ubuntu-24.04
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v6
|
||||||
- name: flatc
|
- name: flatc
|
||||||
# FIXME: make test script not rely on flatc
|
# FIXME: make test script not rely on flatc
|
||||||
run: cmake -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=Release -DFLATBUFFERS_BUILD_TESTS=OFF -DFLATBUFFERS_INSTALL=OFF -DFLATBUFFERS_BUILD_FLATLIB=OFF -DFLATBUFFERS_BUILD_FLATHASH=OFF . && make -j
|
run: cmake -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=Release -DFLATBUFFERS_BUILD_TESTS=OFF -DFLATBUFFERS_INSTALL=OFF -DFLATBUFFERS_BUILD_FLATLIB=OFF -DFLATBUFFERS_BUILD_FLATHASH=OFF . && make -j
|
||||||
|
- name: pnpm
|
||||||
|
run: npm install -g pnpm
|
||||||
- name: deps
|
- name: deps
|
||||||
run: yarn
|
run: pnpm i
|
||||||
- name: compile
|
- name: compile
|
||||||
run: yarn compile
|
run: pnpm compile
|
||||||
- name: test
|
- name: test
|
||||||
working-directory: tests/ts
|
working-directory: tests/ts
|
||||||
run: |
|
run: |
|
||||||
yarn global add esbuild
|
|
||||||
python3 TypeScriptTest.py
|
python3 TypeScriptTest.py
|
||||||
|
|
||||||
build-dart:
|
build-dart:
|
||||||
name: Build Dart
|
name: Build Dart
|
||||||
runs-on: ubuntu-24.04
|
runs-on: ubuntu-24.04
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v6
|
||||||
- uses: dart-lang/setup-dart@v1
|
- uses: dart-lang/setup-dart@v1
|
||||||
with:
|
with:
|
||||||
sdk: stable
|
sdk: stable
|
||||||
@@ -563,11 +574,11 @@ jobs:
|
|||||||
name: Build Nim
|
name: Build Nim
|
||||||
runs-on: ubuntu-24.04
|
runs-on: ubuntu-24.04
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v6
|
||||||
- name: flatc
|
- name: flatc
|
||||||
# FIXME: make test script not rely on flatc
|
# FIXME: make test script not rely on flatc
|
||||||
run: cmake -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=Release -DFLATBUFFERS_BUILD_TESTS=OFF -DFLATBUFFERS_INSTALL=OFF -DFLATBUFFERS_BUILD_FLATLIB=OFF -DFLATBUFFERS_BUILD_FLATHASH=OFF . && make -j
|
run: cmake -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=Release -DFLATBUFFERS_BUILD_TESTS=OFF -DFLATBUFFERS_INSTALL=OFF -DFLATBUFFERS_BUILD_FLATLIB=OFF -DFLATBUFFERS_BUILD_FLATHASH=OFF . && make -j
|
||||||
- uses: jiro4989/setup-nim-action@v1
|
- uses: jiro4989/setup-nim-action@v2
|
||||||
- name: install library
|
- name: install library
|
||||||
working-directory: nim
|
working-directory: nim
|
||||||
run: nimble -y develop && nimble install
|
run: nimble -y develop && nimble install
|
||||||
@@ -579,12 +590,17 @@ jobs:
|
|||||||
name: Bazel
|
name: Bazel
|
||||||
runs-on: ubuntu-24.04
|
runs-on: ubuntu-24.04
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v6
|
||||||
|
# Explicitly use 8.5.1 until we can update or https://github.com/actions/runner-images/issues/13564 is fixed.
|
||||||
|
- name: Set env
|
||||||
|
run: >
|
||||||
|
echo "USE_BAZEL_VERSION=8.5.1" >> $GITHUB_ENV
|
||||||
- name: bazel build
|
- name: bazel build
|
||||||
run: >
|
run: >
|
||||||
bazel build
|
bazel build
|
||||||
//:flatc
|
//:flatc
|
||||||
//:flatbuffers
|
//:flatbuffers
|
||||||
|
//tests:flatbuffers_test
|
||||||
- name: bazel test
|
- name: bazel test
|
||||||
run: >
|
run: >
|
||||||
bazel test
|
bazel test
|
||||||
@@ -621,8 +637,7 @@ jobs:
|
|||||||
actions: read # To read the workflow path.
|
actions: read # To read the workflow path.
|
||||||
id-token: write # To sign the provenance.
|
id-token: write # To sign the provenance.
|
||||||
contents: write # To add assets to a release.
|
contents: write # To add assets to a release.
|
||||||
uses: slsa-framework/slsa-github-generator/.github/workflows/generator_generic_slsa3.yml@v1.2.1
|
uses: slsa-framework/slsa-github-generator/.github/workflows/generator_generic_slsa3.yml@v2.1.0
|
||||||
with:
|
with:
|
||||||
base64-subjects: "${{ needs.release-digests.outputs.digests }}"
|
base64-subjects: "${{ needs.release-digests.outputs.digests }}"
|
||||||
upload-assets: true # Optional: Upload to a new release
|
upload-assets: true # Optional: Upload to a new release
|
||||||
compile-generator: true # Workaround for https://github.com/slsa-framework/slsa-github-generator/issues/1163
|
|
||||||
|
|||||||
6
.github/workflows/docs.yml
vendored
6
.github/workflows/docs.yml
vendored
@@ -16,16 +16,16 @@ jobs:
|
|||||||
deploy:
|
deploy:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v6
|
||||||
- name: Configure Git Credentials
|
- name: Configure Git Credentials
|
||||||
run: |
|
run: |
|
||||||
git config user.name github-actions[bot]
|
git config user.name github-actions[bot]
|
||||||
git config user.email 41898282+github-actions[bot]@users.noreply.github.com
|
git config user.email 41898282+github-actions[bot]@users.noreply.github.com
|
||||||
- uses: actions/setup-python@v5
|
- uses: actions/setup-python@v6
|
||||||
with:
|
with:
|
||||||
python-version: 3.x
|
python-version: 3.x
|
||||||
- run: echo "cache_id=$(date --utc '+%V')" >> $GITHUB_ENV
|
- run: echo "cache_id=$(date --utc '+%V')" >> $GITHUB_ENV
|
||||||
- uses: actions/cache@v4
|
- uses: actions/cache@v5
|
||||||
with:
|
with:
|
||||||
key: mkdocs-material-${{ env.cache_id }}
|
key: mkdocs-material-${{ env.cache_id }}
|
||||||
path: .cache
|
path: .cache
|
||||||
|
|||||||
2
.github/workflows/label.yml
vendored
2
.github/workflows/label.yml
vendored
@@ -19,6 +19,6 @@ jobs:
|
|||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/labeler@ee18d5d34efd9b4f7dafdb0e363cb688eb438044 # 4.1.0
|
- uses: actions/labeler@v6
|
||||||
with:
|
with:
|
||||||
repo-token: "${{ secrets.GITHUB_TOKEN }}"
|
repo-token: "${{ secrets.GITHUB_TOKEN }}"
|
||||||
|
|||||||
2
.github/workflows/main.yml
vendored
2
.github/workflows/main.yml
vendored
@@ -27,7 +27,7 @@ jobs:
|
|||||||
language: c++
|
language: c++
|
||||||
fuzz-seconds: 60
|
fuzz-seconds: 60
|
||||||
- name: Upload Crash
|
- name: Upload Crash
|
||||||
uses: actions/upload-artifact@v4
|
uses: actions/upload-artifact@v7
|
||||||
if: failure() && steps.build.outcome == 'success'
|
if: failure() && steps.build.outcome == 'success'
|
||||||
with:
|
with:
|
||||||
name: artifacts
|
name: artifacts
|
||||||
|
|||||||
26
.github/workflows/release.yml
vendored
26
.github/workflows/release.yml
vendored
@@ -12,8 +12,8 @@ jobs:
|
|||||||
name: Publish NPM
|
name: Publish NPM
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v6
|
||||||
- uses: actions/setup-node@v3
|
- uses: actions/setup-node@v6
|
||||||
with:
|
with:
|
||||||
node-version: '20.x'
|
node-version: '20.x'
|
||||||
registry-url: 'https://registry.npmjs.org'
|
registry-url: 'https://registry.npmjs.org'
|
||||||
@@ -29,19 +29,19 @@ jobs:
|
|||||||
run:
|
run:
|
||||||
working-directory: ./python
|
working-directory: ./python
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v6
|
||||||
- uses: actions/setup-python@v4
|
- uses: actions/setup-python@v6
|
||||||
with:
|
with:
|
||||||
python-version: '3.10'
|
python-version: '3.10'
|
||||||
|
|
||||||
- name: Install Dependencies
|
- name: Install Dependencies
|
||||||
run: |
|
run: |
|
||||||
python3 -m pip install --upgrade pip
|
python3 -m pip install --upgrade pip
|
||||||
python3 -m pip install setuptools wheel twine
|
python3 -m pip install build twine
|
||||||
|
|
||||||
- name: Build
|
- name: Build
|
||||||
run: |
|
run: |
|
||||||
python3 setup.py sdist bdist_wheel
|
python3 -m build .
|
||||||
|
|
||||||
- name: Upload to PyPi
|
- name: Upload to PyPi
|
||||||
run: |
|
run: |
|
||||||
@@ -57,8 +57,8 @@ jobs:
|
|||||||
run:
|
run:
|
||||||
working-directory: ./net/flatbuffers
|
working-directory: ./net/flatbuffers
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v6
|
||||||
- uses: actions/setup-dotnet@v3
|
- uses: actions/setup-dotnet@v5
|
||||||
with:
|
with:
|
||||||
dotnet-version: '8.0.x'
|
dotnet-version: '8.0.x'
|
||||||
- name: Build
|
- name: Build
|
||||||
@@ -80,10 +80,10 @@ jobs:
|
|||||||
run:
|
run:
|
||||||
working-directory: ./java
|
working-directory: ./java
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v6
|
||||||
|
|
||||||
- name: Set up Maven Central Repository
|
- name: Set up Maven Central Repository
|
||||||
uses: actions/setup-java@v3
|
uses: actions/setup-java@v5
|
||||||
with:
|
with:
|
||||||
java-version: '11'
|
java-version: '11'
|
||||||
distribution: 'adopt'
|
distribution: 'adopt'
|
||||||
@@ -108,9 +108,9 @@ jobs:
|
|||||||
run:
|
run:
|
||||||
working-directory: ./kotlin
|
working-directory: ./kotlin
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v6
|
||||||
- name: Set up Maven Central Repository
|
- name: Set up Maven Central Repository
|
||||||
uses: actions/setup-java@v3
|
uses: actions/setup-java@v5
|
||||||
with:
|
with:
|
||||||
java-version: '11'
|
java-version: '11'
|
||||||
distribution: 'adopt'
|
distribution: 'adopt'
|
||||||
@@ -133,7 +133,7 @@ jobs:
|
|||||||
name: Publish crates.io
|
name: Publish crates.io
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v6
|
||||||
- uses: actions-rs/toolchain@v1
|
- uses: actions-rs/toolchain@v1
|
||||||
with:
|
with:
|
||||||
toolchain: stable
|
toolchain: stable
|
||||||
|
|||||||
2
.github/workflows/stale.yml
vendored
2
.github/workflows/stale.yml
vendored
@@ -15,7 +15,7 @@ jobs:
|
|||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/stale@v7.0.0
|
- uses: actions/stale@v10
|
||||||
with:
|
with:
|
||||||
repo-token: ${{ secrets.GITHUB_TOKEN }}
|
repo-token: ${{ secrets.GITHUB_TOKEN }}
|
||||||
operations-per-run: 500
|
operations-per-run: 500
|
||||||
|
|||||||
3
.gitignore
vendored
3
.gitignore
vendored
@@ -157,3 +157,6 @@ MODULE.bazel.lock
|
|||||||
|
|
||||||
# Ignore the generated docs
|
# Ignore the generated docs
|
||||||
docs/site
|
docs/site
|
||||||
|
|
||||||
|
# Ignore generated files
|
||||||
|
*.fbs.h
|
||||||
|
|||||||
17
CHANGELOG.md
17
CHANGELOG.md
@@ -4,6 +4,23 @@ All major or breaking changes will be documented in this file, as well as any
|
|||||||
new features that should be highlighted. Minor fixes or improvements are not
|
new features that should be highlighted. Minor fixes or improvements are not
|
||||||
necessarily listed.
|
necessarily listed.
|
||||||
|
|
||||||
|
## [25.12.19] (December 19 2025)(https://github.com/google/flatbuffers/releases/tag/v25.12.19)
|
||||||
|
|
||||||
|
* [C++] Default emptry vector support (#8870)
|
||||||
|
* [C++] Add --gen-absl-hash option (#8868)
|
||||||
|
* [Kotlin] Upgrade to MacOS 15 (#8845)
|
||||||
|
* [C++] Fix vector of table with naked ptrs (#8830)
|
||||||
|
* [Python] Optimize Offset/Pad/Prep (#8808)
|
||||||
|
* Implement `--file-names-only` (#8788)
|
||||||
|
* [C++] Fix size verifer (#8740)
|
||||||
|
|
||||||
|
## [25.9.23] (September 23 2025)(https://github.com/google/flatbuffers/releases/tag/v25.9.23)
|
||||||
|
|
||||||
|
* flatc: `--grpc-callback-api` flag generates C++ gRPC Callback API server `CallbackService` skeletons AND client native callback/async stubs (unary + all streaming reactor forms) (opt-in, non-breaking, issue #8596).
|
||||||
|
* Swift - Adds new API to reduce memory copying within swift (#8484)
|
||||||
|
* Rust - Support Rust edition 2024 (#8638)
|
||||||
|
* [C++] - Use the Google Style for clang-format without exceptions (#8706)
|
||||||
|
|
||||||
## [25.2.10] (February 10 2025)(https://github.com/google/flatbuffers/releases/tag/v25.2.10)
|
## [25.2.10] (February 10 2025)(https://github.com/google/flatbuffers/releases/tag/v25.2.10)
|
||||||
|
|
||||||
* Removed the old documentation pages. The new one is live at https://flatbuffers.dev
|
* Removed the old documentation pages. The new one is live at https://flatbuffers.dev
|
||||||
|
|||||||
@@ -305,8 +305,7 @@ function(flatbuffers_generate_headers)
|
|||||||
${FLATBUFFERS_GENERATE_HEADERS_SCHEMAS})
|
${FLATBUFFERS_GENERATE_HEADERS_SCHEMAS})
|
||||||
add_dependencies(
|
add_dependencies(
|
||||||
${FLATBUFFERS_GENERATE_HEADERS_TARGET}
|
${FLATBUFFERS_GENERATE_HEADERS_TARGET}
|
||||||
${FLATC}
|
${FLATC_TARGET})
|
||||||
${FLATBUFFERS_GENERATE_HEADERS_SCHEMAS})
|
|
||||||
target_include_directories(
|
target_include_directories(
|
||||||
${FLATBUFFERS_GENERATE_HEADERS_TARGET}
|
${FLATBUFFERS_GENERATE_HEADERS_TARGET}
|
||||||
INTERFACE ${generated_target_dir})
|
INTERFACE ${generated_target_dir})
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
set(VERSION_MAJOR 25)
|
set(VERSION_MAJOR 25)
|
||||||
set(VERSION_MINOR 2)
|
set(VERSION_MINOR 12)
|
||||||
set(VERSION_PATCH 10)
|
set(VERSION_PATCH 19)
|
||||||
set(VERSION_COMMIT 0)
|
set(VERSION_COMMIT 0)
|
||||||
|
|
||||||
if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/.git")
|
if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/.git")
|
||||||
|
|||||||
@@ -112,6 +112,7 @@ endif()
|
|||||||
add_definitions(-DFLATBUFFERS_LOCALE_INDEPENDENT=$<BOOL:${FLATBUFFERS_LOCALE_INDEPENDENT}>)
|
add_definitions(-DFLATBUFFERS_LOCALE_INDEPENDENT=$<BOOL:${FLATBUFFERS_LOCALE_INDEPENDENT}>)
|
||||||
|
|
||||||
if(NOT WIN32)
|
if(NOT WIN32)
|
||||||
|
include(CheckSymbolExists)
|
||||||
check_symbol_exists(realpath "stdlib.h" HAVE_REALPATH)
|
check_symbol_exists(realpath "stdlib.h" HAVE_REALPATH)
|
||||||
if(NOT HAVE_REALPATH)
|
if(NOT HAVE_REALPATH)
|
||||||
add_definitions(-DFLATBUFFERS_NO_ABSOLUTE_PATH_RESOLUTION)
|
add_definitions(-DFLATBUFFERS_NO_ABSOLUTE_PATH_RESOLUTION)
|
||||||
@@ -146,6 +147,8 @@ set(FlatBuffers_Library_SRCS
|
|||||||
include/flatbuffers/vector.h
|
include/flatbuffers/vector.h
|
||||||
include/flatbuffers/vector_downward.h
|
include/flatbuffers/vector_downward.h
|
||||||
include/flatbuffers/verifier.h
|
include/flatbuffers/verifier.h
|
||||||
|
src/file_manager.cpp
|
||||||
|
src/file_name_manager.cpp
|
||||||
src/idl_parser.cpp
|
src/idl_parser.cpp
|
||||||
src/idl_gen_text.cpp
|
src/idl_gen_text.cpp
|
||||||
src/reflection.cpp
|
src/reflection.cpp
|
||||||
@@ -172,9 +175,6 @@ set(FlatBuffers_Compiler_SRCS
|
|||||||
src/idl_gen_grpc.cpp
|
src/idl_gen_grpc.cpp
|
||||||
src/idl_gen_json_schema.cpp
|
src/idl_gen_json_schema.cpp
|
||||||
src/idl_gen_swift.cpp
|
src/idl_gen_swift.cpp
|
||||||
src/file_name_saving_file_manager.cpp
|
|
||||||
src/file_binary_writer.cpp
|
|
||||||
src/file_writer.cpp
|
|
||||||
src/idl_namer.h
|
src/idl_namer.h
|
||||||
src/namer.h
|
src/namer.h
|
||||||
src/flatc.cpp
|
src/flatc.cpp
|
||||||
@@ -218,6 +218,8 @@ set(FlatHash_SRCS
|
|||||||
set(FlatBuffers_Tests_SRCS
|
set(FlatBuffers_Tests_SRCS
|
||||||
${FlatBuffers_Library_SRCS}
|
${FlatBuffers_Library_SRCS}
|
||||||
src/idl_gen_fbs.cpp
|
src/idl_gen_fbs.cpp
|
||||||
|
tests/default_vectors_strings_test.cpp
|
||||||
|
tests/default_vectors_strings_test.h
|
||||||
tests/evolution_test.cpp
|
tests/evolution_test.cpp
|
||||||
tests/flexbuffers_test.cpp
|
tests/flexbuffers_test.cpp
|
||||||
tests/fuzz_test.cpp
|
tests/fuzz_test.cpp
|
||||||
@@ -234,6 +236,8 @@ set(FlatBuffers_Tests_SRCS
|
|||||||
tests/test_builder.h
|
tests/test_builder.h
|
||||||
tests/test_builder.cpp
|
tests/test_builder.cpp
|
||||||
tests/util_test.cpp
|
tests/util_test.cpp
|
||||||
|
tests/vector_table_naked_ptr_test.h
|
||||||
|
tests/vector_table_naked_ptr_test.cpp
|
||||||
tests/native_type_test_impl.h
|
tests/native_type_test_impl.h
|
||||||
tests/native_type_test_impl.cpp
|
tests/native_type_test_impl.cpp
|
||||||
tests/alignment_test.h
|
tests/alignment_test.h
|
||||||
@@ -278,6 +282,8 @@ set(FlatBuffers_GRPCTest_SRCS
|
|||||||
tests/test_builder.cpp
|
tests/test_builder.cpp
|
||||||
grpc/tests/grpctest.cpp
|
grpc/tests/grpctest.cpp
|
||||||
grpc/tests/message_builder_test.cpp
|
grpc/tests/message_builder_test.cpp
|
||||||
|
grpc/tests/grpctest_callback_compile.cpp
|
||||||
|
grpc/tests/grpctest_callback_client_compile.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
# TODO(dbaileychess): Figure out how this would now work. I posted a question on
|
# TODO(dbaileychess): Figure out how this would now work. I posted a question on
|
||||||
@@ -492,13 +498,14 @@ if(FLATBUFFERS_BUILD_SHAREDLIB)
|
|||||||
endif()
|
endif()
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
function(compile_schema SRC_FBS OPT OUT_GEN_FILE)
|
function(compile_schema SRC_FBS OPT SUFFIX OUT_GEN_FILE)
|
||||||
get_filename_component(SRC_FBS_DIR ${SRC_FBS} PATH)
|
get_filename_component(SRC_FBS_DIR ${SRC_FBS} PATH)
|
||||||
string(REGEX REPLACE "\\.fbs$" "_generated.h" GEN_HEADER ${SRC_FBS})
|
string(REGEX REPLACE "\\.fbs$" "${SUFFIX}.h" GEN_HEADER ${SRC_FBS})
|
||||||
add_custom_command(
|
add_custom_command(
|
||||||
OUTPUT ${GEN_HEADER}
|
OUTPUT ${GEN_HEADER}
|
||||||
COMMAND "${FLATBUFFERS_FLATC_EXECUTABLE}"
|
COMMAND "${FLATBUFFERS_FLATC_EXECUTABLE}"
|
||||||
${OPT}
|
${OPT}
|
||||||
|
--filename-suffix ${SUFFIX}
|
||||||
-o "${SRC_FBS_DIR}"
|
-o "${SRC_FBS_DIR}"
|
||||||
"${CMAKE_CURRENT_SOURCE_DIR}/${SRC_FBS}"
|
"${CMAKE_CURRENT_SOURCE_DIR}/${SRC_FBS}"
|
||||||
DEPENDS flatc ${SRC_FBS}
|
DEPENDS flatc ${SRC_FBS}
|
||||||
@@ -508,12 +515,17 @@ function(compile_schema SRC_FBS OPT OUT_GEN_FILE)
|
|||||||
endfunction()
|
endfunction()
|
||||||
|
|
||||||
function(compile_schema_for_test SRC_FBS OPT)
|
function(compile_schema_for_test SRC_FBS OPT)
|
||||||
compile_schema("${SRC_FBS}" "${OPT}" GEN_FILE)
|
compile_schema("${SRC_FBS}" "${OPT}" "_generated" GEN_FILE)
|
||||||
|
target_sources(flattests PRIVATE ${GEN_FILE})
|
||||||
|
endfunction()
|
||||||
|
|
||||||
|
function(compile_schema_for_test_fbsh SRC_FBS OPT)
|
||||||
|
compile_schema("${SRC_FBS}" "${OPT}" ".fbs" GEN_FILE)
|
||||||
target_sources(flattests PRIVATE ${GEN_FILE})
|
target_sources(flattests PRIVATE ${GEN_FILE})
|
||||||
endfunction()
|
endfunction()
|
||||||
|
|
||||||
function(compile_schema_for_samples SRC_FBS OPT)
|
function(compile_schema_for_samples SRC_FBS OPT)
|
||||||
compile_schema("${SRC_FBS}" "${OPT}" GEN_FILE)
|
compile_schema("${SRC_FBS}" "${OPT}" "_generated" GEN_FILE)
|
||||||
target_sources(flatsample PRIVATE ${GEN_FILE})
|
target_sources(flatsample PRIVATE ${GEN_FILE})
|
||||||
endfunction()
|
endfunction()
|
||||||
|
|
||||||
@@ -534,19 +546,20 @@ if(FLATBUFFERS_BUILD_TESTS)
|
|||||||
add_definitions(-DFLATBUFFERS_TEST_PATH_PREFIX=${CMAKE_CURRENT_SOURCE_DIR}/)
|
add_definitions(-DFLATBUFFERS_TEST_PATH_PREFIX=${CMAKE_CURRENT_SOURCE_DIR}/)
|
||||||
|
|
||||||
# The flattest target needs some generated files
|
# The flattest target needs some generated files
|
||||||
SET(FLATC_OPT --cpp --gen-mutable --gen-object-api --reflect-names)
|
SET(FLATC_OPT_COMP --cpp --gen-compare --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)
|
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/alignment_test.fbs "${FLATC_OPT_COMP}")
|
||||||
|
compile_schema_for_test_fbsh(tests/default_vectors_strings_test.fbs "${FLATC_OPT_COMP}")
|
||||||
compile_schema_for_test(tests/arrays_test.fbs "${FLATC_OPT_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_inline_table_test.fbs "${FLATC_OPT_COMP}")
|
||||||
compile_schema_for_test(tests/native_type_test.fbs "${FLATC_OPT}")
|
compile_schema_for_test(tests/native_type_test.fbs "${FLATC_OPT_COMP}")
|
||||||
compile_schema_for_test(tests/key_field/key_field_sample.fbs "${FLATC_OPT_COMP}")
|
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/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/v1.fbs "${FLATC_OPT_COMP}")
|
||||||
compile_schema_for_test(tests/64bit/evolution/v2.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_SCOPED_ENUMS}")
|
compile_schema_for_test(tests/union_underlying_type_test.fbs "${FLATC_OPT_SCOPED_ENUMS}")
|
||||||
|
compile_schema_for_test(tests/cross_namespace_pack_test.fbs "${FLATC_OPT_COMP}")
|
||||||
|
|
||||||
if(FLATBUFFERS_CODE_SANITIZE)
|
if(FLATBUFFERS_CODE_SANITIZE)
|
||||||
add_fsanitize_to_target(flattests ${FLATBUFFERS_CODE_SANITIZE})
|
add_fsanitize_to_target(flattests ${FLATBUFFERS_CODE_SANITIZE})
|
||||||
@@ -569,8 +582,6 @@ if(FLATBUFFERS_BUILD_TESTS)
|
|||||||
# Since flatsample has no sources, we have to explicitly set the linker lang.
|
# Since flatsample has no sources, we have to explicitly set the linker lang.
|
||||||
set_target_properties(flatsample PROPERTIES LINKER_LANGUAGE CXX)
|
set_target_properties(flatsample PROPERTIES LINKER_LANGUAGE CXX)
|
||||||
|
|
||||||
compile_schema_for_samples(samples/monster.fbs "${FLATC_OPT_COMP}")
|
|
||||||
|
|
||||||
target_link_libraries(flatsamplebinary PRIVATE $<BUILD_INTERFACE:ProjectConfig> flatsample)
|
target_link_libraries(flatsamplebinary PRIVATE $<BUILD_INTERFACE:ProjectConfig> flatsample)
|
||||||
target_link_libraries(flatsampletext PRIVATE $<BUILD_INTERFACE:ProjectConfig> flatsample)
|
target_link_libraries(flatsampletext PRIVATE $<BUILD_INTERFACE:ProjectConfig> flatsample)
|
||||||
target_link_libraries(flatsamplebfbs PRIVATE $<BUILD_INTERFACE:ProjectConfig> flatsample)
|
target_link_libraries(flatsamplebfbs PRIVATE $<BUILD_INTERFACE:ProjectConfig> flatsample)
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ Some tips for good pull requests:
|
|||||||
* Write a descriptive commit message. What problem are you solving and what
|
* Write a descriptive commit message. What problem are you solving and what
|
||||||
are the consequences? Where and what did you test? Some good tips:
|
are the consequences? Where and what did you test? Some good tips:
|
||||||
[here](http://robots.thoughtbot.com/5-useful-tips-for-a-better-commit-message)
|
[here](http://robots.thoughtbot.com/5-useful-tips-for-a-better-commit-message)
|
||||||
and [here](https://www.kernel.org/doc/Documentation/SubmittingPatches).
|
and [here](https://www.kernel.org/doc/Documentation/process/submitting-patches.rst).
|
||||||
* If your PR consists of multiple commits which are successive improvements /
|
* If your PR consists of multiple commits which are successive improvements /
|
||||||
fixes to your first commit, consider squashing them into a single commit
|
fixes to your first commit, consider squashing them into a single commit
|
||||||
(`git rebase -i`) such that your PR is a single commit on top of the current
|
(`git rebase -i`) such that your PR is a single commit on top of the current
|
||||||
@@ -40,3 +40,26 @@ Some tips for good pull requests:
|
|||||||
# The small print
|
# The small print
|
||||||
Contributions made by corporations are covered by a different agreement than
|
Contributions made by corporations are covered by a different agreement than
|
||||||
the one above, the Software Grant and Corporate Contributor License Agreement.
|
the one above, the Software Grant and Corporate Contributor License Agreement.
|
||||||
|
|
||||||
|
# Code
|
||||||
|
|
||||||
|
TL/DR
|
||||||
|
|
||||||
|
See [how to build flatc](https://flatbuffers.dev/building/).
|
||||||
|
|
||||||
|
When making changes, build `flatc` and then re-generate the goldens files to see the effect of your changes:
|
||||||
|
|
||||||
|
```
|
||||||
|
$ cp build/flatc .
|
||||||
|
$ goldens/generate_goldens.py
|
||||||
|
```
|
||||||
|
|
||||||
|
Re-generate other code files to see the effects of the changes:
|
||||||
|
|
||||||
|
```
|
||||||
|
$ scripts/generate_code.py
|
||||||
|
```
|
||||||
|
|
||||||
|
Run tests with [TestAll.sh](tests/TestAll.sh) in [tests](tests), or directly any of the sub-scripts run by it.
|
||||||
|
|
||||||
|
[Format the code](Formatters.md) before submitting a PR.
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
Pod::Spec.new do |s|
|
Pod::Spec.new do |s|
|
||||||
s.name = 'FlatBuffers'
|
s.name = 'FlatBuffers'
|
||||||
s.version = '25.2.10'
|
s.version = '25.12.19'
|
||||||
s.summary = 'FlatBuffers: Memory Efficient Serialization Library'
|
s.summary = 'FlatBuffers: Memory Efficient Serialization Library'
|
||||||
|
|
||||||
s.description = "FlatBuffers is a cross platform serialization library architected for
|
s.description = "FlatBuffers is a cross platform serialization library architected for
|
||||||
@@ -16,7 +16,7 @@ Pod::Spec.new do |s|
|
|||||||
s.ios.deployment_target = '11.0'
|
s.ios.deployment_target = '11.0'
|
||||||
s.osx.deployment_target = '10.14'
|
s.osx.deployment_target = '10.14'
|
||||||
|
|
||||||
s.swift_version = '5.0'
|
s.swift_version = '5.10'
|
||||||
s.source_files = 'swift/Sources/Flatbuffers/*.swift'
|
s.source_files = 'swift/Sources/Flatbuffers/*.swift'
|
||||||
s.pod_target_xcconfig = {
|
s.pod_target_xcconfig = {
|
||||||
'BUILD_LIBRARY_FOR_DISTRIBUTION' => 'YES'
|
'BUILD_LIBRARY_FOR_DISTRIBUTION' => 'YES'
|
||||||
|
|||||||
22
MODULE.bazel
22
MODULE.bazel
@@ -1,13 +1,13 @@
|
|||||||
module(
|
module(
|
||||||
name = "flatbuffers",
|
name = "flatbuffers",
|
||||||
version = "25.2.10",
|
version = "25.12.19",
|
||||||
compatibility_level = 1,
|
compatibility_level = 1,
|
||||||
repo_name = "com_github_google_flatbuffers",
|
repo_name = "com_github_google_flatbuffers",
|
||||||
)
|
)
|
||||||
|
|
||||||
bazel_dep(
|
bazel_dep(
|
||||||
name = "aspect_bazel_lib",
|
name = "aspect_bazel_lib",
|
||||||
version = "2.11.0",
|
version = "2.14.0",
|
||||||
)
|
)
|
||||||
bazel_dep(
|
bazel_dep(
|
||||||
name = "aspect_rules_esbuild",
|
name = "aspect_rules_esbuild",
|
||||||
@@ -15,24 +15,24 @@ bazel_dep(
|
|||||||
)
|
)
|
||||||
bazel_dep(
|
bazel_dep(
|
||||||
name = "aspect_rules_js",
|
name = "aspect_rules_js",
|
||||||
version = "2.1.3",
|
version = "2.3.8",
|
||||||
)
|
)
|
||||||
bazel_dep(
|
bazel_dep(
|
||||||
name = "aspect_rules_ts",
|
name = "aspect_rules_ts",
|
||||||
version = "3.4.0",
|
version = "3.6.0",
|
||||||
)
|
)
|
||||||
bazel_dep(
|
bazel_dep(
|
||||||
name = "grpc",
|
name = "grpc",
|
||||||
version = "1.70.1",
|
version = "1.76.0",
|
||||||
repo_name = "com_github_grpc_grpc",
|
repo_name = "com_github_grpc_grpc",
|
||||||
)
|
)
|
||||||
bazel_dep(
|
bazel_dep(
|
||||||
name = "platforms",
|
name = "platforms",
|
||||||
version = "0.0.10",
|
version = "0.0.11",
|
||||||
)
|
)
|
||||||
bazel_dep(
|
bazel_dep(
|
||||||
name = "rules_cc",
|
name = "rules_cc",
|
||||||
version = "0.0.16",
|
version = "0.1.1",
|
||||||
)
|
)
|
||||||
bazel_dep(
|
bazel_dep(
|
||||||
name = "rules_go",
|
name = "rules_go",
|
||||||
@@ -49,7 +49,8 @@ bazel_dep(
|
|||||||
)
|
)
|
||||||
bazel_dep(
|
bazel_dep(
|
||||||
name = "rules_swift",
|
name = "rules_swift",
|
||||||
version = "2.1.1",
|
version = "3.1.2",
|
||||||
|
max_compatibility_level = 3,
|
||||||
repo_name = "build_bazel_rules_swift",
|
repo_name = "build_bazel_rules_swift",
|
||||||
)
|
)
|
||||||
bazel_dep(
|
bazel_dep(
|
||||||
@@ -62,9 +63,6 @@ npm.npm_translate_lock(
|
|||||||
name = "flatbuffers_npm",
|
name = "flatbuffers_npm",
|
||||||
npmrc = "//:.npmrc",
|
npmrc = "//:.npmrc",
|
||||||
pnpm_lock = "//ts:pnpm-lock.yaml",
|
pnpm_lock = "//ts:pnpm-lock.yaml",
|
||||||
# Override the Bazel package where pnpm-lock.yaml is located and link
|
|
||||||
# to the specified package instead.
|
|
||||||
root_package = "ts",
|
|
||||||
verify_node_modules_ignored = "//:.bazelignore",
|
verify_node_modules_ignored = "//:.bazelignore",
|
||||||
)
|
)
|
||||||
use_repo(npm, "flatbuffers_npm")
|
use_repo(npm, "flatbuffers_npm")
|
||||||
@@ -72,6 +70,6 @@ use_repo(npm, "flatbuffers_npm")
|
|||||||
node = use_extension("@rules_nodejs//nodejs:extensions.bzl", "node")
|
node = use_extension("@rules_nodejs//nodejs:extensions.bzl", "node")
|
||||||
use_repo(node, "nodejs_linux_amd64")
|
use_repo(node, "nodejs_linux_amd64")
|
||||||
|
|
||||||
rules_ts_ext = use_extension("@aspect_rules_ts//ts:extensions.bzl", "ext")
|
rules_ts_ext = use_extension("@aspect_rules_ts//ts:extensions.bzl", "ext", dev_dependency = True)
|
||||||
rules_ts_ext.deps()
|
rules_ts_ext.deps()
|
||||||
use_repo(rules_ts_ext, "npm_typescript")
|
use_repo(rules_ts_ext, "npm_typescript")
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
// swift-tools-version:5.9
|
// swift-tools-version:6.0
|
||||||
/*
|
/*
|
||||||
* Copyright 2020 Google Inc. All rights reserved.
|
* Copyright 2020 Google Inc. All rights reserved.
|
||||||
*
|
*
|
||||||
@@ -20,17 +20,79 @@ import PackageDescription
|
|||||||
let package = Package(
|
let package = Package(
|
||||||
name: "FlatBuffers",
|
name: "FlatBuffers",
|
||||||
platforms: [
|
platforms: [
|
||||||
.iOS(.v11),
|
.iOS(.v12),
|
||||||
.macOS(.v10_14),
|
.macOS(.v10_14),
|
||||||
],
|
],
|
||||||
products: [
|
products: [
|
||||||
.library(
|
.library(
|
||||||
name: "FlatBuffers",
|
name: "FlatBuffers",
|
||||||
targets: ["FlatBuffers"]),
|
targets: ["FlatBuffers"]),
|
||||||
|
.library(
|
||||||
|
name: "FlexBuffers",
|
||||||
|
targets: ["FlexBuffers"]),
|
||||||
],
|
],
|
||||||
|
dependencies: .dependencies,
|
||||||
targets: [
|
targets: [
|
||||||
.target(
|
.target(
|
||||||
name: "FlatBuffers",
|
name: "FlatBuffers",
|
||||||
dependencies: [],
|
dependencies: ["Common"],
|
||||||
path: "swift/Sources"),
|
path: "swift/Sources/FlatBuffers",
|
||||||
])
|
swiftSettings: .settings),
|
||||||
|
.target(
|
||||||
|
name: "FlexBuffers",
|
||||||
|
dependencies: ["Common"],
|
||||||
|
path: "swift/Sources/FlexBuffers",
|
||||||
|
swiftSettings: .settings),
|
||||||
|
.target(
|
||||||
|
name: "Common",
|
||||||
|
path: "swift/Sources/Common",
|
||||||
|
swiftSettings: .settings),
|
||||||
|
.testTarget(
|
||||||
|
name: "FlatbuffersTests",
|
||||||
|
dependencies: .dependencies,
|
||||||
|
path: "tests/swift/Tests/Flatbuffers"),
|
||||||
|
.testTarget(
|
||||||
|
name: "FlexbuffersTests",
|
||||||
|
dependencies: ["FlexBuffers"],
|
||||||
|
path: "tests/swift/Tests/Flexbuffers"),
|
||||||
|
],
|
||||||
|
swiftLanguageModes: [.v6])
|
||||||
|
|
||||||
|
extension Array where Element == SwiftSetting {
|
||||||
|
static var settings: [SwiftSetting] {
|
||||||
|
[.enableUpcomingFeature("ExistentialAny")]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
extension Array where Element == Package.Dependency {
|
||||||
|
static var dependencies: [Package.Dependency] {
|
||||||
|
#if os(Windows)
|
||||||
|
[]
|
||||||
|
#else
|
||||||
|
// Test only Dependency
|
||||||
|
[
|
||||||
|
.package(url: "https://github.com/grpc/grpc-swift-2.git", from: "2.0.0"),
|
||||||
|
.package(
|
||||||
|
url: "https://github.com/grpc/grpc-swift-nio-transport.git",
|
||||||
|
from: "2.0.0"),
|
||||||
|
]
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
extension Array where Element == PackageDescription.Target.Dependency {
|
||||||
|
static var dependencies: [PackageDescription.Target.Dependency] {
|
||||||
|
#if os(Windows)
|
||||||
|
["FlatBuffers"]
|
||||||
|
#else
|
||||||
|
// Test only Dependency
|
||||||
|
[
|
||||||
|
.product(name: "GRPCCore", package: "grpc-swift-2"),
|
||||||
|
.product(
|
||||||
|
name: "GRPCNIOTransportHTTP2",
|
||||||
|
package: "grpc-swift-nio-transport"),
|
||||||
|
"FlatBuffers",
|
||||||
|
]
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
 FlatBuffers
|
 FlatBuffers
|
||||||
===========
|
===========
|
||||||
|
|
||||||

|

|
||||||
|
|||||||
21
android/app/proguard-rules.pro
vendored
21
android/app/proguard-rules.pro
vendored
@@ -1,21 +0,0 @@
|
|||||||
# Add project specific ProGuard rules here.
|
|
||||||
# You can control the set of applied configuration files using the
|
|
||||||
# proguardFiles setting in build.gradle.
|
|
||||||
#
|
|
||||||
# For more details, see
|
|
||||||
# http://developer.android.com/guide/developing/tools/proguard.html
|
|
||||||
|
|
||||||
# If your project uses WebView with JS, uncomment the following
|
|
||||||
# and specify the fully qualified class name to the JavaScript interface
|
|
||||||
# class:
|
|
||||||
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
|
|
||||||
# public *;
|
|
||||||
#}
|
|
||||||
|
|
||||||
# Uncomment this to preserve the line number information for
|
|
||||||
# debugging stack traces.
|
|
||||||
#-keepattributes SourceFile,LineNumberTable
|
|
||||||
|
|
||||||
# If you keep the line number information, uncomment this to
|
|
||||||
# hide the original source file name.
|
|
||||||
#-renamesourcefileattribute SourceFile
|
|
||||||
@@ -15,15 +15,17 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include <jni.h>
|
#include <jni.h>
|
||||||
#include <string>
|
|
||||||
#include <search.h>
|
#include <search.h>
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
|
||||||
#include "generated/animal_generated.h"
|
#include "generated/animal_generated.h"
|
||||||
|
|
||||||
using namespace com::fbs::app;
|
using namespace com::fbs::app;
|
||||||
using namespace flatbuffers;
|
using namespace flatbuffers;
|
||||||
|
|
||||||
extern "C" JNIEXPORT jbyteArray JNICALL Java_com_flatbuffers_app_MainActivity_createAnimalFromJNI(
|
extern "C" JNIEXPORT jbyteArray JNICALL
|
||||||
JNIEnv* env,
|
Java_com_flatbuffers_app_MainActivity_createAnimalFromJNI(JNIEnv* env,
|
||||||
jobject /* this */) {
|
jobject /* this */) {
|
||||||
// create a new animal flatbuffers
|
// create a new animal flatbuffers
|
||||||
auto fb = FlatBufferBuilder(1024);
|
auto fb = FlatBufferBuilder(1024);
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
// automatically generated by the FlatBuffers compiler, do not modify
|
// automatically generated by the FlatBuffers compiler, do not modify
|
||||||
|
|
||||||
|
|
||||||
#ifndef FLATBUFFERS_GENERATED_ANIMAL_COM_FBS_APP_H_
|
#ifndef FLATBUFFERS_GENERATED_ANIMAL_COM_FBS_APP_H_
|
||||||
#define FLATBUFFERS_GENERATED_ANIMAL_COM_FBS_APP_H_
|
#define FLATBUFFERS_GENERATED_ANIMAL_COM_FBS_APP_H_
|
||||||
|
|
||||||
@@ -33,17 +32,12 @@ struct Animal FLATBUFFERS_FINAL_CLASS : private ::flatbuffers::Table {
|
|||||||
const ::flatbuffers::String* sound() const {
|
const ::flatbuffers::String* sound() const {
|
||||||
return GetPointer<const ::flatbuffers::String*>(VT_SOUND);
|
return GetPointer<const ::flatbuffers::String*>(VT_SOUND);
|
||||||
}
|
}
|
||||||
uint16_t weight() const {
|
uint16_t weight() const { return GetField<uint16_t>(VT_WEIGHT, 0); }
|
||||||
return GetField<uint16_t>(VT_WEIGHT, 0);
|
|
||||||
}
|
|
||||||
bool Verify(::flatbuffers::Verifier& verifier) const {
|
bool Verify(::flatbuffers::Verifier& verifier) const {
|
||||||
return VerifyTableStart(verifier) &&
|
return VerifyTableStart(verifier) && VerifyOffset(verifier, VT_NAME) &&
|
||||||
VerifyOffset(verifier, VT_NAME) &&
|
verifier.VerifyString(name()) && VerifyOffset(verifier, VT_SOUND) &&
|
||||||
verifier.VerifyString(name()) &&
|
|
||||||
VerifyOffset(verifier, VT_SOUND) &&
|
|
||||||
verifier.VerifyString(sound()) &&
|
verifier.VerifyString(sound()) &&
|
||||||
VerifyField<uint16_t>(verifier, VT_WEIGHT, 2) &&
|
VerifyField<uint16_t>(verifier, VT_WEIGHT, 2) && verifier.EndTable();
|
||||||
verifier.EndTable();
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -60,8 +54,7 @@ struct AnimalBuilder {
|
|||||||
void add_weight(uint16_t weight) {
|
void add_weight(uint16_t weight) {
|
||||||
fbb_.AddElement<uint16_t>(Animal::VT_WEIGHT, weight, 0);
|
fbb_.AddElement<uint16_t>(Animal::VT_WEIGHT, weight, 0);
|
||||||
}
|
}
|
||||||
explicit AnimalBuilder(::flatbuffers::FlatBufferBuilder &_fbb)
|
explicit AnimalBuilder(::flatbuffers::FlatBufferBuilder& _fbb) : fbb_(_fbb) {
|
||||||
: fbb_(_fbb) {
|
|
||||||
start_ = fbb_.StartTable();
|
start_ = fbb_.StartTable();
|
||||||
}
|
}
|
||||||
::flatbuffers::Offset<Animal> Finish() {
|
::flatbuffers::Offset<Animal> Finish() {
|
||||||
@@ -84,17 +77,11 @@ inline ::flatbuffers::Offset<Animal> CreateAnimal(
|
|||||||
}
|
}
|
||||||
|
|
||||||
inline ::flatbuffers::Offset<Animal> CreateAnimalDirect(
|
inline ::flatbuffers::Offset<Animal> CreateAnimalDirect(
|
||||||
::flatbuffers::FlatBufferBuilder &_fbb,
|
::flatbuffers::FlatBufferBuilder& _fbb, const char* name = nullptr,
|
||||||
const char *name = nullptr,
|
const char* sound = nullptr, uint16_t weight = 0) {
|
||||||
const char *sound = nullptr,
|
|
||||||
uint16_t weight = 0) {
|
|
||||||
auto name__ = name ? _fbb.CreateString(name) : 0;
|
auto name__ = name ? _fbb.CreateString(name) : 0;
|
||||||
auto sound__ = sound ? _fbb.CreateString(sound) : 0;
|
auto sound__ = sound ? _fbb.CreateString(sound) : 0;
|
||||||
return com::fbs::app::CreateAnimal(
|
return com::fbs::app::CreateAnimal(_fbb, name__, sound__, weight);
|
||||||
_fbb,
|
|
||||||
name__,
|
|
||||||
sound__,
|
|
||||||
weight);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
inline const com::fbs::app::Animal* GetAnimal(const void* buf) {
|
inline const com::fbs::app::Animal* GetAnimal(const void* buf) {
|
||||||
@@ -105,13 +92,11 @@ inline const com::fbs::app::Animal *GetSizePrefixedAnimal(const void *buf) {
|
|||||||
return ::flatbuffers::GetSizePrefixedRoot<com::fbs::app::Animal>(buf);
|
return ::flatbuffers::GetSizePrefixedRoot<com::fbs::app::Animal>(buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool VerifyAnimalBuffer(
|
inline bool VerifyAnimalBuffer(::flatbuffers::Verifier& verifier) {
|
||||||
::flatbuffers::Verifier &verifier) {
|
|
||||||
return verifier.VerifyBuffer<com::fbs::app::Animal>(nullptr);
|
return verifier.VerifyBuffer<com::fbs::app::Animal>(nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool VerifySizePrefixedAnimalBuffer(
|
inline bool VerifySizePrefixedAnimalBuffer(::flatbuffers::Verifier& verifier) {
|
||||||
::flatbuffers::Verifier &verifier) {
|
|
||||||
return verifier.VerifySizePrefixedBuffer<com::fbs::app::Animal>(nullptr);
|
return verifier.VerifySizePrefixedBuffer<com::fbs::app::Animal>(nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
package com.flatbuffers.app
|
package com.flatbuffers.app
|
||||||
|
|
||||||
import android.annotation.SuppressLint
|
import android.annotation.SuppressLint
|
||||||
import androidx.appcompat.app.AppCompatActivity
|
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.widget.TextView
|
import android.widget.TextView
|
||||||
|
import androidx.appcompat.app.AppCompatActivity
|
||||||
import com.fbs.app.Animal
|
import com.fbs.app.Animal
|
||||||
import com.google.flatbuffers.FlatBufferBuilder
|
import com.google.flatbuffers.FlatBufferBuilder
|
||||||
import java.nio.ByteBuffer
|
import java.nio.ByteBuffer
|
||||||
@@ -29,11 +29,12 @@ class MainActivity : AppCompatActivity() {
|
|||||||
// Create a "Cow" Animal flatbuffers from Kotlin
|
// Create a "Cow" Animal flatbuffers from Kotlin
|
||||||
private fun createAnimalFromKotlin(): Animal {
|
private fun createAnimalFromKotlin(): Animal {
|
||||||
val fb = FlatBufferBuilder(100)
|
val fb = FlatBufferBuilder(100)
|
||||||
val cowOffset = Animal.createAnimal(
|
val cowOffset =
|
||||||
|
Animal.createAnimal(
|
||||||
builder = fb,
|
builder = fb,
|
||||||
nameOffset = fb.createString("Cow"),
|
nameOffset = fb.createString("Cow"),
|
||||||
soundOffset = fb.createString("Moo"),
|
soundOffset = fb.createString("Moo"),
|
||||||
weight = 720u
|
weight = 720u,
|
||||||
)
|
)
|
||||||
fb.finish(cowOffset)
|
fb.finish(cowOffset)
|
||||||
return Animal.getRootAsAnimal(fb.dataBuffer())
|
return Animal.getRootAsAnimal(fb.dataBuffer())
|
||||||
|
|||||||
@@ -2,21 +2,11 @@
|
|||||||
|
|
||||||
package com.fbs.app
|
package com.fbs.app
|
||||||
|
|
||||||
import com.google.flatbuffers.BaseVector
|
|
||||||
import com.google.flatbuffers.BooleanVector
|
|
||||||
import com.google.flatbuffers.ByteVector
|
|
||||||
import com.google.flatbuffers.Constants
|
import com.google.flatbuffers.Constants
|
||||||
import com.google.flatbuffers.DoubleVector
|
|
||||||
import com.google.flatbuffers.FlatBufferBuilder
|
import com.google.flatbuffers.FlatBufferBuilder
|
||||||
import com.google.flatbuffers.FloatVector
|
|
||||||
import com.google.flatbuffers.LongVector
|
|
||||||
import com.google.flatbuffers.StringVector
|
|
||||||
import com.google.flatbuffers.Struct
|
|
||||||
import com.google.flatbuffers.Table
|
import com.google.flatbuffers.Table
|
||||||
import com.google.flatbuffers.UnionVector
|
|
||||||
import java.nio.ByteBuffer
|
import java.nio.ByteBuffer
|
||||||
import java.nio.ByteOrder
|
import java.nio.ByteOrder
|
||||||
import kotlin.math.sign
|
|
||||||
|
|
||||||
@Suppress("unused")
|
@Suppress("unused")
|
||||||
@kotlin.ExperimentalUnsignedTypes
|
@kotlin.ExperimentalUnsignedTypes
|
||||||
@@ -25,10 +15,12 @@ class Animal : Table() {
|
|||||||
fun __init(_i: Int, _bb: ByteBuffer) {
|
fun __init(_i: Int, _bb: ByteBuffer) {
|
||||||
__reset(_i, _bb)
|
__reset(_i, _bb)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun __assign(_i: Int, _bb: ByteBuffer): Animal {
|
fun __assign(_i: Int, _bb: ByteBuffer): Animal {
|
||||||
__init(_i, _bb)
|
__init(_i, _bb)
|
||||||
return this
|
return this
|
||||||
}
|
}
|
||||||
|
|
||||||
val name: String?
|
val name: String?
|
||||||
get() {
|
get() {
|
||||||
val o = __offset(4)
|
val o = __offset(4)
|
||||||
@@ -38,8 +30,12 @@ class Animal : Table() {
|
|||||||
null
|
null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
val nameAsByteBuffer : ByteBuffer get() = __vector_as_bytebuffer(4, 1)
|
|
||||||
|
val nameAsByteBuffer: ByteBuffer
|
||||||
|
get() = __vector_as_bytebuffer(4, 1)
|
||||||
|
|
||||||
fun nameInByteBuffer(_bb: ByteBuffer): ByteBuffer = __vector_in_bytebuffer(_bb, 4, 1)
|
fun nameInByteBuffer(_bb: ByteBuffer): ByteBuffer = __vector_in_bytebuffer(_bb, 4, 1)
|
||||||
|
|
||||||
val sound: String?
|
val sound: String?
|
||||||
get() {
|
get() {
|
||||||
val o = __offset(6)
|
val o = __offset(6)
|
||||||
@@ -49,36 +45,58 @@ class Animal : Table() {
|
|||||||
null
|
null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
val soundAsByteBuffer : ByteBuffer get() = __vector_as_bytebuffer(6, 1)
|
|
||||||
|
val soundAsByteBuffer: ByteBuffer
|
||||||
|
get() = __vector_as_bytebuffer(6, 1)
|
||||||
|
|
||||||
fun soundInByteBuffer(_bb: ByteBuffer): ByteBuffer = __vector_in_bytebuffer(_bb, 6, 1)
|
fun soundInByteBuffer(_bb: ByteBuffer): ByteBuffer = __vector_in_bytebuffer(_bb, 6, 1)
|
||||||
|
|
||||||
val weight: UShort
|
val weight: UShort
|
||||||
get() {
|
get() {
|
||||||
val o = __offset(8)
|
val o = __offset(8)
|
||||||
return if (o != 0) bb.getShort(o + bb_pos).toUShort() else 0u
|
return if (o != 0) bb.getShort(o + bb_pos).toUShort() else 0u
|
||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
fun validateVersion() = Constants.FLATBUFFERS_25_2_10()
|
fun validateVersion() = Constants.FLATBUFFERS_25_12_19()
|
||||||
|
|
||||||
fun getRootAsAnimal(_bb: ByteBuffer): Animal = getRootAsAnimal(_bb, Animal())
|
fun getRootAsAnimal(_bb: ByteBuffer): Animal = getRootAsAnimal(_bb, Animal())
|
||||||
|
|
||||||
fun getRootAsAnimal(_bb: ByteBuffer, obj: Animal): Animal {
|
fun getRootAsAnimal(_bb: ByteBuffer, obj: Animal): Animal {
|
||||||
_bb.order(ByteOrder.LITTLE_ENDIAN)
|
_bb.order(ByteOrder.LITTLE_ENDIAN)
|
||||||
return (obj.__assign(_bb.getInt(_bb.position()) + _bb.position(), _bb))
|
return (obj.__assign(_bb.getInt(_bb.position()) + _bb.position(), _bb))
|
||||||
}
|
}
|
||||||
fun createAnimal(builder: FlatBufferBuilder, nameOffset: Int, soundOffset: Int, weight: UShort) : Int {
|
|
||||||
|
fun createAnimal(
|
||||||
|
builder: FlatBufferBuilder,
|
||||||
|
nameOffset: Int,
|
||||||
|
soundOffset: Int,
|
||||||
|
weight: UShort,
|
||||||
|
): Int {
|
||||||
builder.startTable(3)
|
builder.startTable(3)
|
||||||
addSound(builder, soundOffset)
|
addSound(builder, soundOffset)
|
||||||
addName(builder, nameOffset)
|
addName(builder, nameOffset)
|
||||||
addWeight(builder, weight)
|
addWeight(builder, weight)
|
||||||
return endAnimal(builder)
|
return endAnimal(builder)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun startAnimal(builder: FlatBufferBuilder) = builder.startTable(3)
|
fun startAnimal(builder: FlatBufferBuilder) = builder.startTable(3)
|
||||||
|
|
||||||
fun addName(builder: FlatBufferBuilder, name: Int) = builder.addOffset(0, name, 0)
|
fun addName(builder: FlatBufferBuilder, name: Int) = builder.addOffset(0, name, 0)
|
||||||
|
|
||||||
fun addSound(builder: FlatBufferBuilder, sound: Int) = builder.addOffset(1, sound, 0)
|
fun addSound(builder: FlatBufferBuilder, sound: Int) = builder.addOffset(1, sound, 0)
|
||||||
fun addWeight(builder: FlatBufferBuilder, weight: UShort) = builder.addShort(2, weight.toShort(), 0)
|
|
||||||
|
fun addWeight(builder: FlatBufferBuilder, weight: UShort) =
|
||||||
|
builder.addShort(2, weight.toShort(), 0)
|
||||||
|
|
||||||
fun endAnimal(builder: FlatBufferBuilder): Int {
|
fun endAnimal(builder: FlatBufferBuilder): Int {
|
||||||
val o = builder.endTable()
|
val o = builder.endTable()
|
||||||
return o
|
return o
|
||||||
}
|
}
|
||||||
|
|
||||||
fun finishAnimalBuffer(builder: FlatBufferBuilder, offset: Int) = builder.finish(offset)
|
fun finishAnimalBuffer(builder: FlatBufferBuilder, offset: Int) = builder.finish(offset)
|
||||||
fun finishSizePrefixedAnimalBuffer(builder: FlatBufferBuilder, offset: Int) = builder.finishSizePrefixed(offset)
|
|
||||||
|
fun finishSizePrefixedAnimalBuffer(builder: FlatBufferBuilder, offset: Int) =
|
||||||
|
builder.finishSizePrefixed(offset)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -33,7 +33,9 @@ static inline void Use(benchmark::State &state, std::unique_ptr<Bench> &bench,
|
|||||||
|
|
||||||
int64_t sum = 0;
|
int64_t sum = 0;
|
||||||
|
|
||||||
for (auto _ : state) { sum = bench->Use(decoded); }
|
for (auto _ : state) {
|
||||||
|
sum = bench->Use(decoded);
|
||||||
|
}
|
||||||
|
|
||||||
EXPECT_EQ(sum, check_sum);
|
EXPECT_EQ(sum, check_sum);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
// automatically generated by the FlatBuffers compiler, do not modify
|
// automatically generated by the FlatBuffers compiler, do not modify
|
||||||
|
|
||||||
|
|
||||||
#ifndef FLATBUFFERS_GENERATED_BENCH_BENCHMARKS_FLATBUFFERS_H_
|
#ifndef FLATBUFFERS_GENERATED_BENCH_BENCHMARKS_FLATBUFFERS_H_
|
||||||
#define FLATBUFFERS_GENERATED_BENCH_BENCHMARKS_FLATBUFFERS_H_
|
#define FLATBUFFERS_GENERATED_BENCH_BENCHMARKS_FLATBUFFERS_H_
|
||||||
|
|
||||||
@@ -34,21 +33,12 @@ enum Enum : int16_t {
|
|||||||
};
|
};
|
||||||
|
|
||||||
inline const Enum (&EnumValuesEnum())[3] {
|
inline const Enum (&EnumValuesEnum())[3] {
|
||||||
static const Enum values[] = {
|
static const Enum values[] = {Enum_Apples, Enum_Pears, Enum_Bananas};
|
||||||
Enum_Apples,
|
|
||||||
Enum_Pears,
|
|
||||||
Enum_Bananas
|
|
||||||
};
|
|
||||||
return values;
|
return values;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline const char* const* EnumNamesEnum() {
|
inline const char* const* EnumNamesEnum() {
|
||||||
static const char * const names[4] = {
|
static const char* const names[4] = {"Apples", "Pears", "Bananas", nullptr};
|
||||||
"Apples",
|
|
||||||
"Pears",
|
|
||||||
"Bananas",
|
|
||||||
nullptr
|
|
||||||
};
|
|
||||||
return names;
|
return names;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -67,12 +57,7 @@ FLATBUFFERS_MANUALLY_ALIGNED_STRUCT(8) Foo FLATBUFFERS_FINAL_CLASS {
|
|||||||
uint32_t length_;
|
uint32_t length_;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Foo()
|
Foo() : id_(0), count_(0), prefix_(0), padding0__(0), length_(0) {
|
||||||
: id_(0),
|
|
||||||
count_(0),
|
|
||||||
prefix_(0),
|
|
||||||
padding0__(0),
|
|
||||||
length_(0) {
|
|
||||||
(void)padding0__;
|
(void)padding0__;
|
||||||
}
|
}
|
||||||
Foo(uint64_t _id, int16_t _count, int8_t _prefix, uint32_t _length)
|
Foo(uint64_t _id, int16_t _count, int8_t _prefix, uint32_t _length)
|
||||||
@@ -83,18 +68,10 @@ FLATBUFFERS_MANUALLY_ALIGNED_STRUCT(8) Foo FLATBUFFERS_FINAL_CLASS {
|
|||||||
length_(flatbuffers::EndianScalar(_length)) {
|
length_(flatbuffers::EndianScalar(_length)) {
|
||||||
(void)padding0__;
|
(void)padding0__;
|
||||||
}
|
}
|
||||||
uint64_t id() const {
|
uint64_t id() const { return flatbuffers::EndianScalar(id_); }
|
||||||
return flatbuffers::EndianScalar(id_);
|
int16_t count() const { return flatbuffers::EndianScalar(count_); }
|
||||||
}
|
int8_t prefix() const { return flatbuffers::EndianScalar(prefix_); }
|
||||||
int16_t count() const {
|
uint32_t length() const { return flatbuffers::EndianScalar(length_); }
|
||||||
return flatbuffers::EndianScalar(count_);
|
|
||||||
}
|
|
||||||
int8_t prefix() const {
|
|
||||||
return flatbuffers::EndianScalar(prefix_);
|
|
||||||
}
|
|
||||||
uint32_t length() const {
|
|
||||||
return flatbuffers::EndianScalar(length_);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
FLATBUFFERS_STRUCT_END(Foo, 16);
|
FLATBUFFERS_STRUCT_END(Foo, 16);
|
||||||
|
|
||||||
@@ -104,20 +81,17 @@ FLATBUFFERS_MANUALLY_ALIGNED_STRUCT(8) Bar FLATBUFFERS_FINAL_CLASS {
|
|||||||
int32_t time_;
|
int32_t time_;
|
||||||
float ratio_;
|
float ratio_;
|
||||||
uint16_t size_;
|
uint16_t size_;
|
||||||
int16_t padding0__; int32_t padding1__;
|
int16_t padding0__;
|
||||||
|
int32_t padding1__;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Bar()
|
Bar()
|
||||||
: parent_(),
|
: parent_(), time_(0), ratio_(0), size_(0), padding0__(0), padding1__(0) {
|
||||||
time_(0),
|
|
||||||
ratio_(0),
|
|
||||||
size_(0),
|
|
||||||
padding0__(0),
|
|
||||||
padding1__(0) {
|
|
||||||
(void)padding0__;
|
(void)padding0__;
|
||||||
(void)padding1__;
|
(void)padding1__;
|
||||||
}
|
}
|
||||||
Bar(const benchmarks_flatbuffers::Foo &_parent, int32_t _time, float _ratio, uint16_t _size)
|
Bar(const benchmarks_flatbuffers::Foo& _parent, int32_t _time, float _ratio,
|
||||||
|
uint16_t _size)
|
||||||
: parent_(_parent),
|
: parent_(_parent),
|
||||||
time_(flatbuffers::EndianScalar(_time)),
|
time_(flatbuffers::EndianScalar(_time)),
|
||||||
ratio_(flatbuffers::EndianScalar(_ratio)),
|
ratio_(flatbuffers::EndianScalar(_ratio)),
|
||||||
@@ -127,18 +101,10 @@ FLATBUFFERS_MANUALLY_ALIGNED_STRUCT(8) Bar FLATBUFFERS_FINAL_CLASS {
|
|||||||
(void)padding0__;
|
(void)padding0__;
|
||||||
(void)padding1__;
|
(void)padding1__;
|
||||||
}
|
}
|
||||||
const benchmarks_flatbuffers::Foo &parent() const {
|
const benchmarks_flatbuffers::Foo& parent() const { return parent_; }
|
||||||
return parent_;
|
int32_t time() const { return flatbuffers::EndianScalar(time_); }
|
||||||
}
|
float ratio() const { return flatbuffers::EndianScalar(ratio_); }
|
||||||
int32_t time() const {
|
uint16_t size() const { return flatbuffers::EndianScalar(size_); }
|
||||||
return flatbuffers::EndianScalar(time_);
|
|
||||||
}
|
|
||||||
float ratio() const {
|
|
||||||
return flatbuffers::EndianScalar(ratio_);
|
|
||||||
}
|
|
||||||
uint16_t size() const {
|
|
||||||
return flatbuffers::EndianScalar(size_);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
FLATBUFFERS_STRUCT_END(Bar, 32);
|
FLATBUFFERS_STRUCT_END(Bar, 32);
|
||||||
|
|
||||||
@@ -156,20 +122,14 @@ struct FooBar FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table {
|
|||||||
const flatbuffers::String* name() const {
|
const flatbuffers::String* name() const {
|
||||||
return GetPointer<const flatbuffers::String*>(VT_NAME);
|
return GetPointer<const flatbuffers::String*>(VT_NAME);
|
||||||
}
|
}
|
||||||
double rating() const {
|
double rating() const { return GetField<double>(VT_RATING, 0.0); }
|
||||||
return GetField<double>(VT_RATING, 0.0);
|
uint8_t postfix() const { return GetField<uint8_t>(VT_POSTFIX, 0); }
|
||||||
}
|
|
||||||
uint8_t postfix() const {
|
|
||||||
return GetField<uint8_t>(VT_POSTFIX, 0);
|
|
||||||
}
|
|
||||||
bool Verify(flatbuffers::Verifier& verifier) const {
|
bool Verify(flatbuffers::Verifier& verifier) const {
|
||||||
return VerifyTableStart(verifier) &&
|
return VerifyTableStart(verifier) &&
|
||||||
VerifyField<benchmarks_flatbuffers::Bar>(verifier, VT_SIBLING, 8) &&
|
VerifyField<benchmarks_flatbuffers::Bar>(verifier, VT_SIBLING, 8) &&
|
||||||
VerifyOffset(verifier, VT_NAME) &&
|
VerifyOffset(verifier, VT_NAME) && verifier.VerifyString(name()) &&
|
||||||
verifier.VerifyString(name()) &&
|
|
||||||
VerifyField<double>(verifier, VT_RATING, 8) &&
|
VerifyField<double>(verifier, VT_RATING, 8) &&
|
||||||
VerifyField<uint8_t>(verifier, VT_POSTFIX, 1) &&
|
VerifyField<uint8_t>(verifier, VT_POSTFIX, 1) && verifier.EndTable();
|
||||||
verifier.EndTable();
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -189,8 +149,7 @@ struct FooBarBuilder {
|
|||||||
void add_postfix(uint8_t postfix) {
|
void add_postfix(uint8_t postfix) {
|
||||||
fbb_.AddElement<uint8_t>(FooBar::VT_POSTFIX, postfix, 0);
|
fbb_.AddElement<uint8_t>(FooBar::VT_POSTFIX, postfix, 0);
|
||||||
}
|
}
|
||||||
explicit FooBarBuilder(flatbuffers::FlatBufferBuilder &_fbb)
|
explicit FooBarBuilder(flatbuffers::FlatBufferBuilder& _fbb) : fbb_(_fbb) {
|
||||||
: fbb_(_fbb) {
|
|
||||||
start_ = fbb_.StartTable();
|
start_ = fbb_.StartTable();
|
||||||
}
|
}
|
||||||
flatbuffers::Offset<FooBar> Finish() {
|
flatbuffers::Offset<FooBar> Finish() {
|
||||||
@@ -203,8 +162,7 @@ struct FooBarBuilder {
|
|||||||
inline flatbuffers::Offset<FooBar> CreateFooBar(
|
inline flatbuffers::Offset<FooBar> CreateFooBar(
|
||||||
flatbuffers::FlatBufferBuilder& _fbb,
|
flatbuffers::FlatBufferBuilder& _fbb,
|
||||||
const benchmarks_flatbuffers::Bar* sibling = nullptr,
|
const benchmarks_flatbuffers::Bar* sibling = nullptr,
|
||||||
flatbuffers::Offset<flatbuffers::String> name = 0,
|
flatbuffers::Offset<flatbuffers::String> name = 0, double rating = 0.0,
|
||||||
double rating = 0.0,
|
|
||||||
uint8_t postfix = 0) {
|
uint8_t postfix = 0) {
|
||||||
FooBarBuilder builder_(_fbb);
|
FooBarBuilder builder_(_fbb);
|
||||||
builder_.add_rating(rating);
|
builder_.add_rating(rating);
|
||||||
@@ -217,15 +175,9 @@ inline flatbuffers::Offset<FooBar> CreateFooBar(
|
|||||||
inline flatbuffers::Offset<FooBar> CreateFooBarDirect(
|
inline flatbuffers::Offset<FooBar> CreateFooBarDirect(
|
||||||
flatbuffers::FlatBufferBuilder& _fbb,
|
flatbuffers::FlatBufferBuilder& _fbb,
|
||||||
const benchmarks_flatbuffers::Bar* sibling = nullptr,
|
const benchmarks_flatbuffers::Bar* sibling = nullptr,
|
||||||
const char *name = nullptr,
|
const char* name = nullptr, double rating = 0.0, uint8_t postfix = 0) {
|
||||||
double rating = 0.0,
|
|
||||||
uint8_t postfix = 0) {
|
|
||||||
auto name__ = name ? _fbb.CreateString(name) : 0;
|
auto name__ = name ? _fbb.CreateString(name) : 0;
|
||||||
return benchmarks_flatbuffers::CreateFooBar(
|
return benchmarks_flatbuffers::CreateFooBar(_fbb, sibling, name__, rating,
|
||||||
_fbb,
|
|
||||||
sibling,
|
|
||||||
name__,
|
|
||||||
rating,
|
|
||||||
postfix);
|
postfix);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -237,28 +189,28 @@ struct FooBarContainer FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table {
|
|||||||
VT_FRUIT = 8,
|
VT_FRUIT = 8,
|
||||||
VT_LOCATION = 10
|
VT_LOCATION = 10
|
||||||
};
|
};
|
||||||
const flatbuffers::Vector<flatbuffers::Offset<benchmarks_flatbuffers::FooBar>> *list() const {
|
const flatbuffers::Vector<
|
||||||
return GetPointer<const flatbuffers::Vector<flatbuffers::Offset<benchmarks_flatbuffers::FooBar>> *>(VT_LIST);
|
flatbuffers::Offset<benchmarks_flatbuffers::FooBar>>*
|
||||||
}
|
list() const {
|
||||||
bool initialized() const {
|
return GetPointer<const flatbuffers::Vector<
|
||||||
return GetField<uint8_t>(VT_INITIALIZED, 0) != 0;
|
flatbuffers::Offset<benchmarks_flatbuffers::FooBar>>*>(VT_LIST);
|
||||||
}
|
}
|
||||||
|
bool initialized() const { return GetField<uint8_t>(VT_INITIALIZED, 0) != 0; }
|
||||||
benchmarks_flatbuffers::Enum fruit() const {
|
benchmarks_flatbuffers::Enum fruit() const {
|
||||||
return static_cast<benchmarks_flatbuffers::Enum>(GetField<int16_t>(VT_FRUIT, 0));
|
return static_cast<benchmarks_flatbuffers::Enum>(
|
||||||
|
GetField<int16_t>(VT_FRUIT, 0));
|
||||||
}
|
}
|
||||||
const flatbuffers::String* location() const {
|
const flatbuffers::String* location() const {
|
||||||
return GetPointer<const flatbuffers::String*>(VT_LOCATION);
|
return GetPointer<const flatbuffers::String*>(VT_LOCATION);
|
||||||
}
|
}
|
||||||
bool Verify(flatbuffers::Verifier& verifier) const {
|
bool Verify(flatbuffers::Verifier& verifier) const {
|
||||||
return VerifyTableStart(verifier) &&
|
return VerifyTableStart(verifier) && VerifyOffset(verifier, VT_LIST) &&
|
||||||
VerifyOffset(verifier, VT_LIST) &&
|
|
||||||
verifier.VerifyVector(list()) &&
|
verifier.VerifyVector(list()) &&
|
||||||
verifier.VerifyVectorOfTables(list()) &&
|
verifier.VerifyVectorOfTables(list()) &&
|
||||||
VerifyField<uint8_t>(verifier, VT_INITIALIZED, 1) &&
|
VerifyField<uint8_t>(verifier, VT_INITIALIZED, 1) &&
|
||||||
VerifyField<int16_t>(verifier, VT_FRUIT, 2) &&
|
VerifyField<int16_t>(verifier, VT_FRUIT, 2) &&
|
||||||
VerifyOffset(verifier, VT_LOCATION) &&
|
VerifyOffset(verifier, VT_LOCATION) &&
|
||||||
verifier.VerifyString(location()) &&
|
verifier.VerifyString(location()) && verifier.EndTable();
|
||||||
verifier.EndTable();
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -266,14 +218,18 @@ struct FooBarContainerBuilder {
|
|||||||
typedef FooBarContainer Table;
|
typedef FooBarContainer Table;
|
||||||
flatbuffers::FlatBufferBuilder& fbb_;
|
flatbuffers::FlatBufferBuilder& fbb_;
|
||||||
flatbuffers::uoffset_t start_;
|
flatbuffers::uoffset_t start_;
|
||||||
void add_list(flatbuffers::Offset<flatbuffers::Vector<flatbuffers::Offset<benchmarks_flatbuffers::FooBar>>> list) {
|
void add_list(flatbuffers::Offset<flatbuffers::Vector<
|
||||||
|
flatbuffers::Offset<benchmarks_flatbuffers::FooBar>>>
|
||||||
|
list) {
|
||||||
fbb_.AddOffset(FooBarContainer::VT_LIST, list);
|
fbb_.AddOffset(FooBarContainer::VT_LIST, list);
|
||||||
}
|
}
|
||||||
void add_initialized(bool initialized) {
|
void add_initialized(bool initialized) {
|
||||||
fbb_.AddElement<uint8_t>(FooBarContainer::VT_INITIALIZED, static_cast<uint8_t>(initialized), 0);
|
fbb_.AddElement<uint8_t>(FooBarContainer::VT_INITIALIZED,
|
||||||
|
static_cast<uint8_t>(initialized), 0);
|
||||||
}
|
}
|
||||||
void add_fruit(benchmarks_flatbuffers::Enum fruit) {
|
void add_fruit(benchmarks_flatbuffers::Enum fruit) {
|
||||||
fbb_.AddElement<int16_t>(FooBarContainer::VT_FRUIT, static_cast<int16_t>(fruit), 0);
|
fbb_.AddElement<int16_t>(FooBarContainer::VT_FRUIT,
|
||||||
|
static_cast<int16_t>(fruit), 0);
|
||||||
}
|
}
|
||||||
void add_location(flatbuffers::Offset<flatbuffers::String> location) {
|
void add_location(flatbuffers::Offset<flatbuffers::String> location) {
|
||||||
fbb_.AddOffset(FooBarContainer::VT_LOCATION, location);
|
fbb_.AddOffset(FooBarContainer::VT_LOCATION, location);
|
||||||
@@ -291,7 +247,9 @@ struct FooBarContainerBuilder {
|
|||||||
|
|
||||||
inline flatbuffers::Offset<FooBarContainer> CreateFooBarContainer(
|
inline flatbuffers::Offset<FooBarContainer> CreateFooBarContainer(
|
||||||
flatbuffers::FlatBufferBuilder& _fbb,
|
flatbuffers::FlatBufferBuilder& _fbb,
|
||||||
flatbuffers::Offset<flatbuffers::Vector<flatbuffers::Offset<benchmarks_flatbuffers::FooBar>>> list = 0,
|
flatbuffers::Offset<flatbuffers::Vector<
|
||||||
|
flatbuffers::Offset<benchmarks_flatbuffers::FooBar>>>
|
||||||
|
list = 0,
|
||||||
bool initialized = false,
|
bool initialized = false,
|
||||||
benchmarks_flatbuffers::Enum fruit = benchmarks_flatbuffers::Enum_Apples,
|
benchmarks_flatbuffers::Enum fruit = benchmarks_flatbuffers::Enum_Apples,
|
||||||
flatbuffers::Offset<flatbuffers::String> location = 0) {
|
flatbuffers::Offset<flatbuffers::String> location = 0) {
|
||||||
@@ -305,36 +263,41 @@ inline flatbuffers::Offset<FooBarContainer> CreateFooBarContainer(
|
|||||||
|
|
||||||
inline flatbuffers::Offset<FooBarContainer> CreateFooBarContainerDirect(
|
inline flatbuffers::Offset<FooBarContainer> CreateFooBarContainerDirect(
|
||||||
flatbuffers::FlatBufferBuilder& _fbb,
|
flatbuffers::FlatBufferBuilder& _fbb,
|
||||||
const std::vector<flatbuffers::Offset<benchmarks_flatbuffers::FooBar>> *list = nullptr,
|
const std::vector<flatbuffers::Offset<benchmarks_flatbuffers::FooBar>>*
|
||||||
|
list = nullptr,
|
||||||
bool initialized = false,
|
bool initialized = false,
|
||||||
benchmarks_flatbuffers::Enum fruit = benchmarks_flatbuffers::Enum_Apples,
|
benchmarks_flatbuffers::Enum fruit = benchmarks_flatbuffers::Enum_Apples,
|
||||||
const char* location = nullptr) {
|
const char* location = nullptr) {
|
||||||
auto list__ = list ? _fbb.CreateVector<flatbuffers::Offset<benchmarks_flatbuffers::FooBar>>(*list) : 0;
|
auto list__ =
|
||||||
|
list ? _fbb.CreateVector<
|
||||||
|
flatbuffers::Offset<benchmarks_flatbuffers::FooBar>>(*list)
|
||||||
|
: 0;
|
||||||
auto location__ = location ? _fbb.CreateString(location) : 0;
|
auto location__ = location ? _fbb.CreateString(location) : 0;
|
||||||
return benchmarks_flatbuffers::CreateFooBarContainer(
|
return benchmarks_flatbuffers::CreateFooBarContainer(
|
||||||
_fbb,
|
_fbb, list__, initialized, fruit, location__);
|
||||||
list__,
|
|
||||||
initialized,
|
|
||||||
fruit,
|
|
||||||
location__);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
inline const benchmarks_flatbuffers::FooBarContainer *GetFooBarContainer(const void *buf) {
|
inline const benchmarks_flatbuffers::FooBarContainer* GetFooBarContainer(
|
||||||
|
const void* buf) {
|
||||||
return flatbuffers::GetRoot<benchmarks_flatbuffers::FooBarContainer>(buf);
|
return flatbuffers::GetRoot<benchmarks_flatbuffers::FooBarContainer>(buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline const benchmarks_flatbuffers::FooBarContainer *GetSizePrefixedFooBarContainer(const void *buf) {
|
inline const benchmarks_flatbuffers::FooBarContainer*
|
||||||
return flatbuffers::GetSizePrefixedRoot<benchmarks_flatbuffers::FooBarContainer>(buf);
|
GetSizePrefixedFooBarContainer(const void* buf) {
|
||||||
|
return flatbuffers::GetSizePrefixedRoot<
|
||||||
|
benchmarks_flatbuffers::FooBarContainer>(buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool VerifyFooBarContainerBuffer(
|
inline bool VerifyFooBarContainerBuffer(flatbuffers::Verifier& verifier) {
|
||||||
flatbuffers::Verifier &verifier) {
|
return verifier.VerifyBuffer<benchmarks_flatbuffers::FooBarContainer>(
|
||||||
return verifier.VerifyBuffer<benchmarks_flatbuffers::FooBarContainer>(nullptr);
|
nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool VerifySizePrefixedFooBarContainerBuffer(
|
inline bool VerifySizePrefixedFooBarContainerBuffer(
|
||||||
flatbuffers::Verifier& verifier) {
|
flatbuffers::Verifier& verifier) {
|
||||||
return verifier.VerifySizePrefixedBuffer<benchmarks_flatbuffers::FooBarContainer>(nullptr);
|
return verifier
|
||||||
|
.VerifySizePrefixedBuffer<benchmarks_flatbuffers::FooBarContainer>(
|
||||||
|
nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void FinishFooBarContainerBuffer(
|
inline void FinishFooBarContainerBuffer(
|
||||||
|
|||||||
@@ -15,8 +15,8 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import Benchmark
|
import Benchmark
|
||||||
import CoreFoundation
|
|
||||||
import FlatBuffers
|
import FlatBuffers
|
||||||
|
import Foundation
|
||||||
|
|
||||||
@usableFromInline
|
@usableFromInline
|
||||||
struct AA: NativeStruct {
|
struct AA: NativeStruct {
|
||||||
@@ -29,6 +29,15 @@ struct AA: NativeStruct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let benchmarks = {
|
let benchmarks = {
|
||||||
|
let oneGB: Int32 = 1_024_000_000
|
||||||
|
let data = {
|
||||||
|
var array = [8888.88, 8888.88]
|
||||||
|
var data = Data()
|
||||||
|
array.withUnsafeBytes { ptr in
|
||||||
|
data.append(contentsOf: ptr)
|
||||||
|
}
|
||||||
|
return data
|
||||||
|
}()
|
||||||
let ints: [Int] = Array(repeating: 42, count: 100)
|
let ints: [Int] = Array(repeating: 42, count: 100)
|
||||||
let bytes: [UInt8] = Array(repeating: 42, count: 100)
|
let bytes: [UInt8] = Array(repeating: 42, count: 100)
|
||||||
let str10 = (0...9).map { _ -> String in "x" }.joined()
|
let str10 = (0...9).map { _ -> String in "x" }.joined()
|
||||||
@@ -73,12 +82,25 @@ let benchmarks = {
|
|||||||
|
|
||||||
Benchmark("Allocating 1GB", configuration: singleConfiguration) { benchmark in
|
Benchmark("Allocating 1GB", configuration: singleConfiguration) { benchmark in
|
||||||
for _ in benchmark.scaledIterations {
|
for _ in benchmark.scaledIterations {
|
||||||
blackHole(FlatBufferBuilder(initialSize: 1_024_000_000))
|
blackHole(FlatBufferBuilder(initialSize: oneGB))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Benchmark(
|
||||||
|
"Allocating ByteBuffer 1GB",
|
||||||
|
configuration: singleConfiguration)
|
||||||
|
{ benchmark in
|
||||||
|
let memory = UnsafeMutableRawPointer.allocate(
|
||||||
|
byteCount: 1_024_000_000,
|
||||||
|
alignment: 1)
|
||||||
|
benchmark.startMeasurement()
|
||||||
|
for _ in benchmark.scaledIterations {
|
||||||
|
blackHole(ByteBuffer(assumingMemoryBound: memory, capacity: Int(oneGB)))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Benchmark("Clearing 1GB", configuration: singleConfiguration) { benchmark in
|
Benchmark("Clearing 1GB", configuration: singleConfiguration) { benchmark in
|
||||||
var fb = FlatBufferBuilder(initialSize: 1_024_000_000)
|
var fb = FlatBufferBuilder(initialSize: oneGB)
|
||||||
benchmark.startMeasurement()
|
benchmark.startMeasurement()
|
||||||
for _ in benchmark.scaledIterations {
|
for _ in benchmark.scaledIterations {
|
||||||
blackHole(fb.clear())
|
blackHole(fb.clear())
|
||||||
@@ -158,6 +180,26 @@ let benchmarks = {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Benchmark(
|
||||||
|
"FlatBufferBuilder Start table",
|
||||||
|
configuration: kiloConfiguration)
|
||||||
|
{ benchmark in
|
||||||
|
var fb = FlatBufferBuilder(initialSize: 1024 * 1024 * 32)
|
||||||
|
benchmark.startMeasurement()
|
||||||
|
for _ in benchmark.scaledIterations {
|
||||||
|
let s = fb.startTable(with: 4)
|
||||||
|
blackHole(fb.endTable(at: s))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Benchmark("Struct") { benchmark in
|
||||||
|
var fb = FlatBufferBuilder(initialSize: 1024 * 1024 * 32)
|
||||||
|
benchmark.startMeasurement()
|
||||||
|
for _ in benchmark.scaledIterations {
|
||||||
|
blackHole(fb.create(struct: array.first!))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Benchmark("Structs") { benchmark in
|
Benchmark("Structs") { benchmark in
|
||||||
let rawSize = ((16 * 5) * benchmark.scaledIterations.count) / 1024
|
let rawSize = ((16 * 5) * benchmark.scaledIterations.count) / 1024
|
||||||
var fb = FlatBufferBuilder(initialSize: Int32(rawSize * 1600))
|
var fb = FlatBufferBuilder(initialSize: Int32(rawSize * 1600))
|
||||||
@@ -176,7 +218,7 @@ let benchmarks = {
|
|||||||
let start = fb.startTable(with: 1)
|
let start = fb.startTable(with: 1)
|
||||||
fb.add(offset: vector, at: 4)
|
fb.add(offset: vector, at: 4)
|
||||||
let root = Offset(offset: fb.endTable(at: start))
|
let root = Offset(offset: fb.endTable(at: start))
|
||||||
fb.finish(offset: root)
|
blackHole(fb.finish(offset: root))
|
||||||
}
|
}
|
||||||
|
|
||||||
Benchmark("Vector of Offsets") { benchmark in
|
Benchmark("Vector of Offsets") { benchmark in
|
||||||
@@ -198,4 +240,11 @@ let benchmarks = {
|
|||||||
blackHole(fb.endTable(at: s))
|
blackHole(fb.endTable(at: s))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Benchmark("Reading Doubles") { benchmark in
|
||||||
|
let byteBuffer = ByteBuffer(data: data)
|
||||||
|
for _ in benchmark.scaledIterations {
|
||||||
|
blackHole(byteBuffer.read(def: Double.self, position: 0))
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
// swift-tools-version:5.9
|
// swift-tools-version:5.10
|
||||||
/*
|
/*
|
||||||
* Copyright 2020 Google Inc. All rights reserved.
|
* Copyright 2020 Google Inc. All rights reserved.
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -187,6 +187,7 @@ def flatbuffer_cc_library(
|
|||||||
visibility = None,
|
visibility = None,
|
||||||
compatible_with = None,
|
compatible_with = None,
|
||||||
restricted_to = None,
|
restricted_to = None,
|
||||||
|
filename_suffix = "_generated",
|
||||||
target_compatible_with = None,
|
target_compatible_with = None,
|
||||||
srcs_filegroup_visibility = None,
|
srcs_filegroup_visibility = None,
|
||||||
gen_reflections = False):
|
gen_reflections = False):
|
||||||
@@ -230,10 +231,13 @@ def flatbuffer_cc_library(
|
|||||||
Fileset([name]_reflection): (Optional) all generated reflection binaries.
|
Fileset([name]_reflection): (Optional) all generated reflection binaries.
|
||||||
cc_library([name]): library with sources and flatbuffers deps.
|
cc_library([name]): library with sources and flatbuffers deps.
|
||||||
"""
|
"""
|
||||||
output_headers = [
|
|
||||||
(out_prefix + "%s_generated.h") % (s.replace(".fbs", "").split("/")[-1].split(":")[-1])
|
output_headers = []
|
||||||
for s in srcs
|
for s in srcs:
|
||||||
]
|
base_name = s.split("/")[-1].split(":")[-1].replace(".fbs", "")
|
||||||
|
header = out_prefix + base_name + filename_suffix + ".h"
|
||||||
|
output_headers.append(header)
|
||||||
|
|
||||||
if deps and includes:
|
if deps and includes:
|
||||||
# There is no inherent reason we couldn't support both, but this discourages
|
# There is no inherent reason we couldn't support both, but this discourages
|
||||||
# use of includes without good reason.
|
# use of includes without good reason.
|
||||||
|
|||||||
@@ -1,12 +0,0 @@
|
|||||||
cmake_minimum_required(VERSION 2.8)
|
|
||||||
|
|
||||||
message(STATUS "Conan FlatBuffers Wrapper")
|
|
||||||
|
|
||||||
include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
|
|
||||||
conan_basic_setup()
|
|
||||||
|
|
||||||
if (WIN32 AND MSVC_LIKE AND FLATBUFFERS_BUILD_SHAREDLIB)
|
|
||||||
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)
|
|
||||||
endif(WIN32 AND MSVC_LIKE AND FLATBUFFERS_BUILD_SHAREDLIB)
|
|
||||||
|
|
||||||
include(${CMAKE_SOURCE_DIR}/CMakeListsOriginal.txt)
|
|
||||||
@@ -1,50 +0,0 @@
|
|||||||
#!/usr/bin/env python
|
|
||||||
# -*- coding: utf-8 -*-
|
|
||||||
import os
|
|
||||||
import re
|
|
||||||
import subprocess
|
|
||||||
from cpt.packager import ConanMultiPackager
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def get_branch():
|
|
||||||
try:
|
|
||||||
for line in subprocess.check_output("git branch", shell=True).decode().splitlines():
|
|
||||||
line = line.strip()
|
|
||||||
if line.startswith("*") and " (HEAD detached" not in line:
|
|
||||||
return line.replace("*", "", 1).strip()
|
|
||||||
return ""
|
|
||||||
except Exception:
|
|
||||||
pass
|
|
||||||
return ""
|
|
||||||
|
|
||||||
|
|
||||||
def get_version():
|
|
||||||
version = get_branch()
|
|
||||||
match = re.search(r"v(\d+\.\d+\.\d+.*)", version)
|
|
||||||
if match:
|
|
||||||
return match.group(1)
|
|
||||||
return version
|
|
||||||
|
|
||||||
|
|
||||||
def get_reference(username):
|
|
||||||
return "flatbuffers/{}@google/stable".format(get_version())
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
login_username = os.getenv("CONAN_LOGIN_USERNAME", "aardappel")
|
|
||||||
username = os.getenv("CONAN_USERNAME", "google")
|
|
||||||
upload = os.getenv("CONAN_UPLOAD", "https://api.bintray.com/conan/aardappel/flatbuffers")
|
|
||||||
stable_branch_pattern = os.getenv("CONAN_STABLE_BRANCH_PATTERN", r"v\d+\.\d+\.\d+.*")
|
|
||||||
test_folder = os.getenv("CPT_TEST_FOLDER", os.path.join("conan", "test_package"))
|
|
||||||
upload_only_when_stable = os.getenv("CONAN_UPLOAD_ONLY_WHEN_STABLE", True)
|
|
||||||
|
|
||||||
builder = ConanMultiPackager(reference=get_reference(username),
|
|
||||||
username=username,
|
|
||||||
login_username=login_username,
|
|
||||||
upload=upload,
|
|
||||||
stable_branch_pattern=stable_branch_pattern,
|
|
||||||
upload_only_when_stable=upload_only_when_stable,
|
|
||||||
test_folder=test_folder)
|
|
||||||
builder.add_common_builds(pure_c=False)
|
|
||||||
builder.run()
|
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
project(test_package CXX)
|
|
||||||
cmake_minimum_required(VERSION 2.8.11)
|
|
||||||
|
|
||||||
include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
|
|
||||||
conan_basic_setup()
|
|
||||||
|
|
||||||
add_executable(${PROJECT_NAME} test_package.cpp)
|
|
||||||
target_link_libraries(${PROJECT_NAME} ${CONAN_LIBS})
|
|
||||||
set_property(TARGET ${PROJECT_NAME} PROPERTY CXX_STANDARD 11)
|
|
||||||
@@ -1,21 +0,0 @@
|
|||||||
#!/usr/bin/env python
|
|
||||||
# -*- coding: utf-8 -*-
|
|
||||||
|
|
||||||
from conans import ConanFile, CMake
|
|
||||||
import os
|
|
||||||
|
|
||||||
|
|
||||||
class TestPackageConan(ConanFile):
|
|
||||||
settings = "os", "compiler", "build_type", "arch"
|
|
||||||
generators = "cmake"
|
|
||||||
|
|
||||||
def build(self):
|
|
||||||
cmake = CMake(self)
|
|
||||||
cmake.configure()
|
|
||||||
cmake.build()
|
|
||||||
|
|
||||||
def test(self):
|
|
||||||
bin_path = os.path.join("bin", "test_package")
|
|
||||||
self.run(bin_path, run_environment=True)
|
|
||||||
self.run("flatc --version", run_environment=True)
|
|
||||||
self.run("flathash fnv1_16 conan", run_environment=True)
|
|
||||||
75
conanfile.py
75
conanfile.py
@@ -1,75 +0,0 @@
|
|||||||
#!/usr/bin/env python
|
|
||||||
# -*- coding: utf-8 -*-
|
|
||||||
|
|
||||||
"""Conan recipe package for Google FlatBuffers
|
|
||||||
"""
|
|
||||||
import os
|
|
||||||
import shutil
|
|
||||||
from conans import ConanFile, CMake, tools
|
|
||||||
|
|
||||||
|
|
||||||
class FlatbuffersConan(ConanFile):
|
|
||||||
name = "flatbuffers"
|
|
||||||
license = "Apache-2.0"
|
|
||||||
url = "https://github.com/google/flatbuffers"
|
|
||||||
homepage = "http://google.github.io/flatbuffers/"
|
|
||||||
author = "Wouter van Oortmerssen"
|
|
||||||
topics = ("conan", "flatbuffers", "serialization", "rpc", "json-parser")
|
|
||||||
description = "Memory Efficient Serialization Library"
|
|
||||||
settings = "os", "compiler", "build_type", "arch"
|
|
||||||
options = {"shared": [True, False], "fPIC": [True, False]}
|
|
||||||
default_options = {"shared": False, "fPIC": True}
|
|
||||||
generators = "cmake"
|
|
||||||
exports = "LICENSE"
|
|
||||||
exports_sources = ["CMake/*", "include/*", "src/*", "grpc/*", "CMakeLists.txt", "conan/CMakeLists.txt"]
|
|
||||||
|
|
||||||
def source(self):
|
|
||||||
"""Wrap the original CMake file to call conan_basic_setup
|
|
||||||
"""
|
|
||||||
shutil.move("CMakeLists.txt", "CMakeListsOriginal.txt")
|
|
||||||
shutil.move(os.path.join("conan", "CMakeLists.txt"), "CMakeLists.txt")
|
|
||||||
|
|
||||||
def config_options(self):
|
|
||||||
"""Remove fPIC option on Windows platform
|
|
||||||
"""
|
|
||||||
if self.settings.os == "Windows":
|
|
||||||
self.options.remove("fPIC")
|
|
||||||
|
|
||||||
def configure_cmake(self):
|
|
||||||
"""Create CMake instance and execute configure step
|
|
||||||
"""
|
|
||||||
cmake = CMake(self)
|
|
||||||
cmake.definitions["FLATBUFFERS_BUILD_TESTS"] = False
|
|
||||||
cmake.definitions["FLATBUFFERS_BUILD_SHAREDLIB"] = self.options.shared
|
|
||||||
cmake.definitions["FLATBUFFERS_BUILD_FLATLIB"] = not self.options.shared
|
|
||||||
cmake.configure()
|
|
||||||
return cmake
|
|
||||||
|
|
||||||
def build(self):
|
|
||||||
"""Configure, build and install FlatBuffers using CMake.
|
|
||||||
"""
|
|
||||||
cmake = self.configure_cmake()
|
|
||||||
cmake.build()
|
|
||||||
|
|
||||||
def package(self):
|
|
||||||
"""Copy Flatbuffers' artifacts to package folder
|
|
||||||
"""
|
|
||||||
cmake = self.configure_cmake()
|
|
||||||
cmake.install()
|
|
||||||
self.copy(pattern="LICENSE", dst="licenses")
|
|
||||||
self.copy(pattern="FindFlatBuffers.cmake", dst=os.path.join("lib", "cmake", "flatbuffers"), src="CMake")
|
|
||||||
self.copy(pattern="flathash*", dst="bin", src="bin")
|
|
||||||
self.copy(pattern="flatc*", dst="bin", src="bin")
|
|
||||||
if self.settings.os == "Windows" and self.options.shared:
|
|
||||||
if self.settings.compiler == "Visual Studio":
|
|
||||||
shutil.move(os.path.join(self.package_folder, "lib", "%s.dll" % self.name),
|
|
||||||
os.path.join(self.package_folder, "bin", "%s.dll" % self.name))
|
|
||||||
elif self.settings.compiler == "gcc":
|
|
||||||
shutil.move(os.path.join(self.package_folder, "lib", "lib%s.dll" % self.name),
|
|
||||||
os.path.join(self.package_folder, "bin", "lib%s.dll" % self.name))
|
|
||||||
|
|
||||||
def package_info(self):
|
|
||||||
"""Collect built libraries names and solve flatc path.
|
|
||||||
"""
|
|
||||||
self.cpp_info.libs = tools.collect_libs(self)
|
|
||||||
self.user_info.flatc = os.path.join(self.package_folder, "bin", "flatc")
|
|
||||||
@@ -1,5 +1,11 @@
|
|||||||
# Changelog
|
# Changelog
|
||||||
|
|
||||||
|
## 25.9.23
|
||||||
|
|
||||||
|
- use enhanced enums (#8313)
|
||||||
|
- fix incorrect write in Float64 write method (#8290)
|
||||||
|
- code format improvements (#8707)
|
||||||
|
|
||||||
## 23.5.26
|
## 23.5.26
|
||||||
|
|
||||||
- omit type annotationes for local variables (#7067, #7069, #7070)
|
- omit type annotationes for local variables (#7067, #7069, #7070)
|
||||||
|
|||||||
@@ -15,6 +15,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import 'package:flat_buffers/flat_buffers.dart' as fb;
|
import 'package:flat_buffers/flat_buffers.dart' as fb;
|
||||||
|
|
||||||
import './monster_my_game.sample_generated.dart' as my_game;
|
import './monster_my_game.sample_generated.dart' as my_game;
|
||||||
|
|
||||||
// Example how to use FlatBuffers to create and read binary buffers.
|
// Example how to use FlatBuffers to create and read binary buffers.
|
||||||
@@ -78,7 +79,8 @@ void builderTest() {
|
|||||||
builder.finish(monsteroff);
|
builder.finish(monsteroff);
|
||||||
if (verify(builder.buffer)) {
|
if (verify(builder.buffer)) {
|
||||||
print(
|
print(
|
||||||
"The FlatBuffer was successfully created with a builder and verified!");
|
"The FlatBuffer was successfully created with a builder and verified!",
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -94,7 +96,10 @@ void objectBuilderTest() {
|
|||||||
name: 'Orc',
|
name: 'Orc',
|
||||||
inventory: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9],
|
inventory: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9],
|
||||||
color: my_game.Color.Red,
|
color: my_game.Color.Red,
|
||||||
weapons: [my_game.WeaponObjectBuilder(name: 'Sword', damage: 3), axe],
|
weapons: [
|
||||||
|
my_game.WeaponObjectBuilder(name: 'Sword', damage: 3),
|
||||||
|
axe,
|
||||||
|
],
|
||||||
equippedType: my_game.EquipmentTypeId.Weapon,
|
equippedType: my_game.EquipmentTypeId.Weapon,
|
||||||
equipped: axe,
|
equipped: axe,
|
||||||
);
|
);
|
||||||
@@ -108,7 +113,8 @@ void objectBuilderTest() {
|
|||||||
// Instead, we're going to access it right away (as if we just received it).
|
// Instead, we're going to access it right away (as if we just received it).
|
||||||
if (verify(buffer)) {
|
if (verify(buffer)) {
|
||||||
print(
|
print(
|
||||||
"The FlatBuffer was successfully created with an object builder and verified!");
|
"The FlatBuffer was successfully created with an object builder and verified!",
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -4,8 +4,8 @@
|
|||||||
library my_game.sample;
|
library my_game.sample;
|
||||||
|
|
||||||
import 'dart:typed_data' show Uint8List;
|
import 'dart:typed_data' show Uint8List;
|
||||||
import 'package:flat_buffers/flat_buffers.dart' as fb;
|
|
||||||
|
|
||||||
|
import 'package:flat_buffers/flat_buffers.dart' as fb;
|
||||||
|
|
||||||
class Color {
|
class Color {
|
||||||
final int value;
|
final int value;
|
||||||
@@ -29,10 +29,7 @@ class Color {
|
|||||||
static const Color Red = Color._(0);
|
static const Color Red = Color._(0);
|
||||||
static const Color Green = Color._(1);
|
static const Color Green = Color._(1);
|
||||||
static const Color Blue = Color._(2);
|
static const Color Blue = Color._(2);
|
||||||
static const Map<int, Color> values = {
|
static const Map<int, Color> values = {0: Red, 1: Green, 2: Blue};
|
||||||
0: Red,
|
|
||||||
1: Green,
|
|
||||||
2: Blue};
|
|
||||||
|
|
||||||
static const fb.Reader<Color> reader = _ColorReader();
|
static const fb.Reader<Color> reader = _ColorReader();
|
||||||
|
|
||||||
@@ -60,7 +57,9 @@ class EquipmentTypeId {
|
|||||||
factory EquipmentTypeId.fromValue(int value) {
|
factory EquipmentTypeId.fromValue(int value) {
|
||||||
final result = values[value];
|
final result = values[value];
|
||||||
if (result == null) {
|
if (result == null) {
|
||||||
throw StateError('Invalid value $value for bit flag enum EquipmentTypeId');
|
throw StateError(
|
||||||
|
'Invalid value $value for bit flag enum EquipmentTypeId',
|
||||||
|
);
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@@ -74,9 +73,7 @@ class EquipmentTypeId {
|
|||||||
|
|
||||||
static const EquipmentTypeId NONE = EquipmentTypeId._(0);
|
static const EquipmentTypeId NONE = EquipmentTypeId._(0);
|
||||||
static const EquipmentTypeId Weapon = EquipmentTypeId._(1);
|
static const EquipmentTypeId Weapon = EquipmentTypeId._(1);
|
||||||
static const Map<int, EquipmentTypeId> values = {
|
static const Map<int, EquipmentTypeId> values = {0: NONE, 1: Weapon};
|
||||||
0: NONE,
|
|
||||||
1: Weapon};
|
|
||||||
|
|
||||||
static const fb.Reader<EquipmentTypeId> reader = _EquipmentTypeIdReader();
|
static const fb.Reader<EquipmentTypeId> reader = _EquipmentTypeIdReader();
|
||||||
|
|
||||||
@@ -122,8 +119,7 @@ class _Vec3Reader extends fb.StructReader<Vec3> {
|
|||||||
int get size => 12;
|
int get size => 12;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Vec3 createObject(fb.BufferContext bc, int offset) =>
|
Vec3 createObject(fb.BufferContext bc, int offset) => Vec3._(bc, offset);
|
||||||
Vec3._(bc, offset);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class Vec3Builder {
|
class Vec3Builder {
|
||||||
@@ -137,7 +133,6 @@ class Vec3Builder {
|
|||||||
fbBuilder.putFloat32(x);
|
fbBuilder.putFloat32(x);
|
||||||
return fbBuilder.offset;
|
return fbBuilder.offset;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class Vec3ObjectBuilder extends fb.ObjectBuilder {
|
class Vec3ObjectBuilder extends fb.ObjectBuilder {
|
||||||
@@ -145,11 +140,7 @@ class Vec3ObjectBuilder extends fb.ObjectBuilder {
|
|||||||
final double _y;
|
final double _y;
|
||||||
final double _z;
|
final double _z;
|
||||||
|
|
||||||
Vec3ObjectBuilder({
|
Vec3ObjectBuilder({required double x, required double y, required double z})
|
||||||
required double x,
|
|
||||||
required double y,
|
|
||||||
required double z,
|
|
||||||
})
|
|
||||||
: _x = x,
|
: _x = x,
|
||||||
_y = y,
|
_y = y,
|
||||||
_z = z;
|
_z = z;
|
||||||
@@ -171,6 +162,7 @@ class Vec3ObjectBuilder extends fb.ObjectBuilder {
|
|||||||
return fbBuilder.buffer;
|
return fbBuilder.buffer;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class Monster {
|
class Monster {
|
||||||
Monster._(this._bc, this._bcOffset);
|
Monster._(this._bc, this._bcOffset);
|
||||||
factory Monster(List<int> bytes) {
|
factory Monster(List<int> bytes) {
|
||||||
@@ -186,18 +178,30 @@ class Monster {
|
|||||||
Vec3? get pos => Vec3.reader.vTableGetNullable(_bc, _bcOffset, 4);
|
Vec3? get pos => Vec3.reader.vTableGetNullable(_bc, _bcOffset, 4);
|
||||||
int get mana => const fb.Int16Reader().vTableGet(_bc, _bcOffset, 6, 150);
|
int get mana => const fb.Int16Reader().vTableGet(_bc, _bcOffset, 6, 150);
|
||||||
int get hp => const fb.Int16Reader().vTableGet(_bc, _bcOffset, 8, 100);
|
int get hp => const fb.Int16Reader().vTableGet(_bc, _bcOffset, 8, 100);
|
||||||
String? get name => const fb.StringReader().vTableGetNullable(_bc, _bcOffset, 10);
|
String? get name =>
|
||||||
List<int>? get inventory => const fb.Uint8ListReader().vTableGetNullable(_bc, _bcOffset, 14);
|
const fb.StringReader().vTableGetNullable(_bc, _bcOffset, 10);
|
||||||
Color get color => Color.fromValue(const fb.Int8Reader().vTableGet(_bc, _bcOffset, 16, 2));
|
List<int>? get inventory =>
|
||||||
List<Weapon>? get weapons => const fb.ListReader<Weapon>(Weapon.reader).vTableGetNullable(_bc, _bcOffset, 18);
|
const fb.Uint8ListReader().vTableGetNullable(_bc, _bcOffset, 14);
|
||||||
EquipmentTypeId? get equippedType => EquipmentTypeId._createOrNull(const fb.Uint8Reader().vTableGetNullable(_bc, _bcOffset, 20));
|
Color get color =>
|
||||||
|
Color.fromValue(const fb.Int8Reader().vTableGet(_bc, _bcOffset, 16, 2));
|
||||||
|
List<Weapon>? get weapons => const fb.ListReader<Weapon>(
|
||||||
|
Weapon.reader,
|
||||||
|
).vTableGetNullable(_bc, _bcOffset, 18);
|
||||||
|
EquipmentTypeId? get equippedType => EquipmentTypeId._createOrNull(
|
||||||
|
const fb.Uint8Reader().vTableGetNullable(_bc, _bcOffset, 20),
|
||||||
|
);
|
||||||
dynamic get equipped {
|
dynamic get equipped {
|
||||||
switch (equippedType?.value) {
|
switch (equippedType?.value) {
|
||||||
case 1: return Weapon.reader.vTableGetNullable(_bc, _bcOffset, 22);
|
case 1:
|
||||||
default: return null;
|
return Weapon.reader.vTableGetNullable(_bc, _bcOffset, 22);
|
||||||
|
default:
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
List<Vec3>? get path => const fb.ListReader<Vec3>(Vec3.reader).vTableGetNullable(_bc, _bcOffset, 24);
|
|
||||||
|
List<Vec3>? get path => const fb.ListReader<Vec3>(
|
||||||
|
Vec3.reader,
|
||||||
|
).vTableGetNullable(_bc, _bcOffset, 24);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String toString() {
|
String toString() {
|
||||||
@@ -226,38 +230,47 @@ class MonsterBuilder {
|
|||||||
fbBuilder.addStruct(0, offset);
|
fbBuilder.addStruct(0, offset);
|
||||||
return fbBuilder.offset;
|
return fbBuilder.offset;
|
||||||
}
|
}
|
||||||
|
|
||||||
int addMana(int? mana) {
|
int addMana(int? mana) {
|
||||||
fbBuilder.addInt16(1, mana);
|
fbBuilder.addInt16(1, mana);
|
||||||
return fbBuilder.offset;
|
return fbBuilder.offset;
|
||||||
}
|
}
|
||||||
|
|
||||||
int addHp(int? hp) {
|
int addHp(int? hp) {
|
||||||
fbBuilder.addInt16(2, hp);
|
fbBuilder.addInt16(2, hp);
|
||||||
return fbBuilder.offset;
|
return fbBuilder.offset;
|
||||||
}
|
}
|
||||||
|
|
||||||
int addNameOffset(int? offset) {
|
int addNameOffset(int? offset) {
|
||||||
fbBuilder.addOffset(3, offset);
|
fbBuilder.addOffset(3, offset);
|
||||||
return fbBuilder.offset;
|
return fbBuilder.offset;
|
||||||
}
|
}
|
||||||
|
|
||||||
int addInventoryOffset(int? offset) {
|
int addInventoryOffset(int? offset) {
|
||||||
fbBuilder.addOffset(5, offset);
|
fbBuilder.addOffset(5, offset);
|
||||||
return fbBuilder.offset;
|
return fbBuilder.offset;
|
||||||
}
|
}
|
||||||
|
|
||||||
int addColor(Color? color) {
|
int addColor(Color? color) {
|
||||||
fbBuilder.addInt8(6, color?.value);
|
fbBuilder.addInt8(6, color?.value);
|
||||||
return fbBuilder.offset;
|
return fbBuilder.offset;
|
||||||
}
|
}
|
||||||
|
|
||||||
int addWeaponsOffset(int? offset) {
|
int addWeaponsOffset(int? offset) {
|
||||||
fbBuilder.addOffset(7, offset);
|
fbBuilder.addOffset(7, offset);
|
||||||
return fbBuilder.offset;
|
return fbBuilder.offset;
|
||||||
}
|
}
|
||||||
|
|
||||||
int addEquippedType(EquipmentTypeId? equippedType) {
|
int addEquippedType(EquipmentTypeId? equippedType) {
|
||||||
fbBuilder.addUint8(8, equippedType?.value);
|
fbBuilder.addUint8(8, equippedType?.value);
|
||||||
return fbBuilder.offset;
|
return fbBuilder.offset;
|
||||||
}
|
}
|
||||||
|
|
||||||
int addEquippedOffset(int? offset) {
|
int addEquippedOffset(int? offset) {
|
||||||
fbBuilder.addOffset(9, offset);
|
fbBuilder.addOffset(9, offset);
|
||||||
return fbBuilder.offset;
|
return fbBuilder.offset;
|
||||||
}
|
}
|
||||||
|
|
||||||
int addPathOffset(int? offset) {
|
int addPathOffset(int? offset) {
|
||||||
fbBuilder.addOffset(10, offset);
|
fbBuilder.addOffset(10, offset);
|
||||||
return fbBuilder.offset;
|
return fbBuilder.offset;
|
||||||
@@ -291,8 +304,7 @@ class MonsterObjectBuilder extends fb.ObjectBuilder {
|
|||||||
EquipmentTypeId? equippedType,
|
EquipmentTypeId? equippedType,
|
||||||
dynamic equipped,
|
dynamic equipped,
|
||||||
List<Vec3ObjectBuilder>? path,
|
List<Vec3ObjectBuilder>? path,
|
||||||
})
|
}) : _pos = pos,
|
||||||
: _pos = pos,
|
|
||||||
_mana = mana,
|
_mana = mana,
|
||||||
_hp = hp,
|
_hp = hp,
|
||||||
_name = name,
|
_name = name,
|
||||||
@@ -306,14 +318,20 @@ class MonsterObjectBuilder extends fb.ObjectBuilder {
|
|||||||
/// Finish building, and store into the [fbBuilder].
|
/// Finish building, and store into the [fbBuilder].
|
||||||
@override
|
@override
|
||||||
int finish(fb.Builder fbBuilder) {
|
int finish(fb.Builder fbBuilder) {
|
||||||
final int? nameOffset = _name == null ? null
|
final int? nameOffset = _name == null
|
||||||
|
? null
|
||||||
: fbBuilder.writeString(_name!);
|
: fbBuilder.writeString(_name!);
|
||||||
final int? inventoryOffset = _inventory == null ? null
|
final int? inventoryOffset = _inventory == null
|
||||||
|
? null
|
||||||
: fbBuilder.writeListUint8(_inventory!);
|
: fbBuilder.writeListUint8(_inventory!);
|
||||||
final int? weaponsOffset = _weapons == null ? null
|
final int? weaponsOffset = _weapons == null
|
||||||
: fbBuilder.writeList(_weapons!.map((b) => b.getOrCreateOffset(fbBuilder)).toList());
|
? null
|
||||||
|
: fbBuilder.writeList(
|
||||||
|
_weapons!.map((b) => b.getOrCreateOffset(fbBuilder)).toList(),
|
||||||
|
);
|
||||||
final int? equippedOffset = _equipped?.getOrCreateOffset(fbBuilder);
|
final int? equippedOffset = _equipped?.getOrCreateOffset(fbBuilder);
|
||||||
final int? pathOffset = _path == null ? null
|
final int? pathOffset = _path == null
|
||||||
|
? null
|
||||||
: fbBuilder.writeListOfStructs(_path!);
|
: fbBuilder.writeListOfStructs(_path!);
|
||||||
fbBuilder.startTable(10);
|
fbBuilder.startTable(10);
|
||||||
if (_pos != null) {
|
if (_pos != null) {
|
||||||
@@ -339,6 +357,7 @@ class MonsterObjectBuilder extends fb.ObjectBuilder {
|
|||||||
return fbBuilder.buffer;
|
return fbBuilder.buffer;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class Weapon {
|
class Weapon {
|
||||||
Weapon._(this._bc, this._bcOffset);
|
Weapon._(this._bc, this._bcOffset);
|
||||||
factory Weapon(List<int> bytes) {
|
factory Weapon(List<int> bytes) {
|
||||||
@@ -351,7 +370,8 @@ class Weapon {
|
|||||||
final fb.BufferContext _bc;
|
final fb.BufferContext _bc;
|
||||||
final int _bcOffset;
|
final int _bcOffset;
|
||||||
|
|
||||||
String? get name => const fb.StringReader().vTableGetNullable(_bc, _bcOffset, 4);
|
String? get name =>
|
||||||
|
const fb.StringReader().vTableGetNullable(_bc, _bcOffset, 4);
|
||||||
int get damage => const fb.Int16Reader().vTableGet(_bc, _bcOffset, 6, 0);
|
int get damage => const fb.Int16Reader().vTableGet(_bc, _bcOffset, 6, 0);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@@ -364,8 +384,7 @@ class _WeaponReader extends fb.TableReader<Weapon> {
|
|||||||
const _WeaponReader();
|
const _WeaponReader();
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Weapon createObject(fb.BufferContext bc, int offset) =>
|
Weapon createObject(fb.BufferContext bc, int offset) => Weapon._(bc, offset);
|
||||||
Weapon._(bc, offset);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class WeaponBuilder {
|
class WeaponBuilder {
|
||||||
@@ -381,6 +400,7 @@ class WeaponBuilder {
|
|||||||
fbBuilder.addOffset(0, offset);
|
fbBuilder.addOffset(0, offset);
|
||||||
return fbBuilder.offset;
|
return fbBuilder.offset;
|
||||||
}
|
}
|
||||||
|
|
||||||
int addDamage(int? damage) {
|
int addDamage(int? damage) {
|
||||||
fbBuilder.addInt16(1, damage);
|
fbBuilder.addInt16(1, damage);
|
||||||
return fbBuilder.offset;
|
return fbBuilder.offset;
|
||||||
@@ -395,17 +415,15 @@ class WeaponObjectBuilder extends fb.ObjectBuilder {
|
|||||||
final String? _name;
|
final String? _name;
|
||||||
final int? _damage;
|
final int? _damage;
|
||||||
|
|
||||||
WeaponObjectBuilder({
|
WeaponObjectBuilder({String? name, int? damage})
|
||||||
String? name,
|
|
||||||
int? damage,
|
|
||||||
})
|
|
||||||
: _name = name,
|
: _name = name,
|
||||||
_damage = damage;
|
_damage = damage;
|
||||||
|
|
||||||
/// Finish building, and store into the [fbBuilder].
|
/// Finish building, and store into the [fbBuilder].
|
||||||
@override
|
@override
|
||||||
int finish(fb.Builder fbBuilder) {
|
int finish(fb.Builder fbBuilder) {
|
||||||
final int? nameOffset = _name == null ? null
|
final int? nameOffset = _name == null
|
||||||
|
? null
|
||||||
: fbBuilder.writeString(_name!);
|
: fbBuilder.writeString(_name!);
|
||||||
fbBuilder.startTable(2);
|
fbBuilder.startTable(2);
|
||||||
fbBuilder.addOffset(0, nameOffset);
|
fbBuilder.addOffset(0, nameOffset);
|
||||||
|
|||||||
@@ -27,10 +27,11 @@ class BufferContext {
|
|||||||
ByteData get buffer => _buffer;
|
ByteData get buffer => _buffer;
|
||||||
|
|
||||||
/// Create from a FlatBuffer represented by a list of bytes (uint8).
|
/// Create from a FlatBuffer represented by a list of bytes (uint8).
|
||||||
factory BufferContext.fromBytes(List<int> byteList) =>
|
factory BufferContext.fromBytes(List<int> byteList) => BufferContext(
|
||||||
BufferContext(byteList is Uint8List
|
byteList is Uint8List
|
||||||
? byteList.buffer.asByteData(byteList.offsetInBytes)
|
? byteList.buffer.asByteData(byteList.offsetInBytes)
|
||||||
: ByteData.view(Uint8List.fromList(byteList).buffer));
|
: ByteData.view(Uint8List.fromList(byteList).buffer),
|
||||||
|
);
|
||||||
|
|
||||||
/// Create from a FlatBuffer represented by ByteData.
|
/// Create from a FlatBuffer represented by ByteData.
|
||||||
BufferContext(this._buffer);
|
BufferContext(this._buffer);
|
||||||
@@ -350,8 +351,10 @@ class Builder {
|
|||||||
Uint8List get buffer {
|
Uint8List get buffer {
|
||||||
assert(_finished);
|
assert(_finished);
|
||||||
final finishedSize = size();
|
final finishedSize = size();
|
||||||
return _buf.buffer
|
return _buf.buffer.asUint8List(
|
||||||
.asUint8List(_buf.lengthInBytes - finishedSize, finishedSize);
|
_buf.lengthInBytes - finishedSize,
|
||||||
|
finishedSize,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Finish off the creation of the buffer. The given [offset] is used as the
|
/// Finish off the creation of the buffer. The given [offset] is used as the
|
||||||
@@ -368,14 +371,18 @@ class Builder {
|
|||||||
if (fileIdentifier != null) {
|
if (fileIdentifier != null) {
|
||||||
for (var i = 0; i < 4; i++) {
|
for (var i = 0; i < 4; i++) {
|
||||||
_setUint8AtTail(
|
_setUint8AtTail(
|
||||||
finishedSize - _sizeofUint32 - i, fileIdentifier.codeUnitAt(i));
|
finishedSize - _sizeofUint32 - i,
|
||||||
|
fileIdentifier.codeUnitAt(i),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// zero out the added padding
|
// zero out the added padding
|
||||||
for (var i = sizeBeforePadding + 1;
|
for (
|
||||||
|
var i = sizeBeforePadding + 1;
|
||||||
i <= finishedSize - requiredBytes;
|
i <= finishedSize - requiredBytes;
|
||||||
i++) {
|
i++
|
||||||
|
) {
|
||||||
_setUint8AtTail(i, 0);
|
_setUint8AtTail(i, 0);
|
||||||
}
|
}
|
||||||
_finished = true;
|
_finished = true;
|
||||||
@@ -687,8 +694,10 @@ class Builder {
|
|||||||
int writeString(String value, {bool asciiOptimization = false}) {
|
int writeString(String value, {bool asciiOptimization = false}) {
|
||||||
assert(!_inVTable);
|
assert(!_inVTable);
|
||||||
if (_strings != null) {
|
if (_strings != null) {
|
||||||
return _strings!
|
return _strings!.putIfAbsent(
|
||||||
.putIfAbsent(value, () => _writeString(value, asciiOptimization));
|
value,
|
||||||
|
() => _writeString(value, asciiOptimization),
|
||||||
|
);
|
||||||
} else {
|
} else {
|
||||||
return _writeString(value, asciiOptimization);
|
return _writeString(value, asciiOptimization);
|
||||||
}
|
}
|
||||||
@@ -1005,8 +1014,11 @@ class ListReader<E> extends Reader<List<E>> {
|
|||||||
: List<E>.generate(
|
: List<E>.generate(
|
||||||
bc.buffer.getUint32(listOffset, Endian.little),
|
bc.buffer.getUint32(listOffset, Endian.little),
|
||||||
(int index) => _elementReader.read(
|
(int index) => _elementReader.read(
|
||||||
bc, listOffset + size + _elementReader.size * index),
|
bc,
|
||||||
growable: true);
|
listOffset + size + _elementReader.size * index,
|
||||||
|
),
|
||||||
|
growable: true,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1454,7 +1466,11 @@ abstract class Allocator {
|
|||||||
/// Params [inUseBack] and [inUseFront] indicate how much of [oldData] is
|
/// Params [inUseBack] and [inUseFront] indicate how much of [oldData] is
|
||||||
/// actually in use at each end, and needs to be copied.
|
/// actually in use at each end, and needs to be copied.
|
||||||
ByteData resize(
|
ByteData resize(
|
||||||
ByteData oldData, int newSize, int inUseBack, int inUseFront) {
|
ByteData oldData,
|
||||||
|
int newSize,
|
||||||
|
int inUseBack,
|
||||||
|
int inUseFront,
|
||||||
|
) {
|
||||||
final newData = allocate(newSize);
|
final newData = allocate(newSize);
|
||||||
_copyDownward(oldData, newData, inUseBack, inUseFront);
|
_copyDownward(oldData, newData, inUseBack, inUseFront);
|
||||||
deallocate(oldData);
|
deallocate(oldData);
|
||||||
@@ -1465,17 +1481,25 @@ abstract class Allocator {
|
|||||||
/// memory of size [inUseFront] and [inUseBack] will be copied from the front
|
/// memory of size [inUseFront] and [inUseBack] will be copied from the front
|
||||||
/// and back of the old memory allocation.
|
/// and back of the old memory allocation.
|
||||||
void _copyDownward(
|
void _copyDownward(
|
||||||
ByteData oldData, ByteData newData, int inUseBack, int inUseFront) {
|
ByteData oldData,
|
||||||
|
ByteData newData,
|
||||||
|
int inUseBack,
|
||||||
|
int inUseFront,
|
||||||
|
) {
|
||||||
if (inUseBack != 0) {
|
if (inUseBack != 0) {
|
||||||
newData.buffer.asUint8List().setAll(
|
newData.buffer.asUint8List().setAll(
|
||||||
newData.lengthInBytes - inUseBack,
|
newData.lengthInBytes - inUseBack,
|
||||||
oldData.buffer.asUint8List().getRange(
|
oldData.buffer.asUint8List().getRange(
|
||||||
oldData.lengthInBytes - inUseBack, oldData.lengthInBytes));
|
oldData.lengthInBytes - inUseBack,
|
||||||
|
oldData.lengthInBytes,
|
||||||
|
),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
if (inUseFront != 0) {
|
if (inUseFront != 0) {
|
||||||
newData.buffer
|
newData.buffer.asUint8List().setAll(
|
||||||
.asUint8List()
|
0,
|
||||||
.setAll(0, oldData.buffer.asUint8List().getRange(0, inUseFront));
|
oldData.buffer.asUint8List().getRange(0, inUseFront),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import 'types.dart';
|
|||||||
|
|
||||||
/// The main builder class for creation of a FlexBuffer.
|
/// The main builder class for creation of a FlexBuffer.
|
||||||
class Builder {
|
class Builder {
|
||||||
final ByteData _buffer;
|
ByteData _buffer;
|
||||||
List<_StackValue> _stack = [];
|
List<_StackValue> _stack = [];
|
||||||
List<_StackPointer> _stackPointers = [];
|
List<_StackPointer> _stackPointers = [];
|
||||||
int _offset = 0;
|
int _offset = 0;
|
||||||
@@ -107,8 +107,11 @@ class Builder {
|
|||||||
final newOffset = _newOffset(length + 1);
|
final newOffset = _newOffset(length + 1);
|
||||||
_pushBuffer(utf8String);
|
_pushBuffer(utf8String);
|
||||||
_offset = newOffset;
|
_offset = newOffset;
|
||||||
final stackValue =
|
final stackValue = _StackValue.withOffset(
|
||||||
_StackValue.withOffset(stringOffset, ValueType.String, bitWidth);
|
stringOffset,
|
||||||
|
ValueType.String,
|
||||||
|
bitWidth,
|
||||||
|
);
|
||||||
_stack.add(stackValue);
|
_stack.add(stackValue);
|
||||||
_stringCache[value] = stackValue;
|
_stringCache[value] = stackValue;
|
||||||
}
|
}
|
||||||
@@ -128,8 +131,11 @@ class Builder {
|
|||||||
final newOffset = _newOffset(length + 1);
|
final newOffset = _newOffset(length + 1);
|
||||||
_pushBuffer(utf8String);
|
_pushBuffer(utf8String);
|
||||||
_offset = newOffset;
|
_offset = newOffset;
|
||||||
final stackValue =
|
final stackValue = _StackValue.withOffset(
|
||||||
_StackValue.withOffset(keyOffset, ValueType.Key, BitWidth.width8);
|
keyOffset,
|
||||||
|
ValueType.Key,
|
||||||
|
BitWidth.width8,
|
||||||
|
);
|
||||||
_stack.add(stackValue);
|
_stack.add(stackValue);
|
||||||
_keyCache[value] = stackValue;
|
_keyCache[value] = stackValue;
|
||||||
}
|
}
|
||||||
@@ -147,8 +153,11 @@ class Builder {
|
|||||||
final newOffset = _newOffset(length);
|
final newOffset = _newOffset(length);
|
||||||
_pushBuffer(value.asUint8List());
|
_pushBuffer(value.asUint8List());
|
||||||
_offset = newOffset;
|
_offset = newOffset;
|
||||||
final stackValue =
|
final stackValue = _StackValue.withOffset(
|
||||||
_StackValue.withOffset(blobOffset, ValueType.Blob, bitWidth);
|
blobOffset,
|
||||||
|
ValueType.Blob,
|
||||||
|
bitWidth,
|
||||||
|
);
|
||||||
_stack.add(stackValue);
|
_stack.add(stackValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -170,7 +179,10 @@ class Builder {
|
|||||||
final valueOffset = _offset;
|
final valueOffset = _offset;
|
||||||
_pushBuffer(stackValue.asU8List(stackValue.width));
|
_pushBuffer(stackValue.asU8List(stackValue.width));
|
||||||
final stackOffset = _StackValue.withOffset(
|
final stackOffset = _StackValue.withOffset(
|
||||||
valueOffset, ValueType.IndirectInt, stackValue.width);
|
valueOffset,
|
||||||
|
ValueType.IndirectInt,
|
||||||
|
stackValue.width,
|
||||||
|
);
|
||||||
_stack.add(stackOffset);
|
_stack.add(stackOffset);
|
||||||
_offset = newOffset;
|
_offset = newOffset;
|
||||||
if (cache) {
|
if (cache) {
|
||||||
@@ -195,7 +207,10 @@ class Builder {
|
|||||||
final valueOffset = _offset;
|
final valueOffset = _offset;
|
||||||
_pushBuffer(stackValue.asU8List(stackValue.width));
|
_pushBuffer(stackValue.asU8List(stackValue.width));
|
||||||
final stackOffset = _StackValue.withOffset(
|
final stackOffset = _StackValue.withOffset(
|
||||||
valueOffset, ValueType.IndirectFloat, stackValue.width);
|
valueOffset,
|
||||||
|
ValueType.IndirectFloat,
|
||||||
|
stackValue.width,
|
||||||
|
);
|
||||||
_stack.add(stackOffset);
|
_stack.add(stackOffset);
|
||||||
_offset = newOffset;
|
_offset = newOffset;
|
||||||
if (cache) {
|
if (cache) {
|
||||||
@@ -252,9 +267,10 @@ class Builder {
|
|||||||
tmp._offset = _offset;
|
tmp._offset = _offset;
|
||||||
tmp._stack = List.from(_stack);
|
tmp._stack = List.from(_stack);
|
||||||
tmp._stackPointers = List.from(_stackPointers);
|
tmp._stackPointers = List.from(_stackPointers);
|
||||||
tmp._buffer.buffer
|
tmp._buffer.buffer.asUint8List().setAll(
|
||||||
.asUint8List()
|
0,
|
||||||
.setAll(0, _buffer.buffer.asUint8List(0, _offset));
|
_buffer.buffer.asUint8List(0, _offset),
|
||||||
|
);
|
||||||
for (var i = 0; i < tmp._stackPointers.length; i++) {
|
for (var i = 0; i < tmp._stackPointers.length; i++) {
|
||||||
tmp.end();
|
tmp.end();
|
||||||
}
|
}
|
||||||
@@ -271,7 +287,8 @@ class Builder {
|
|||||||
if (_stackPointers.isNotEmpty && _stackPointers.last.isVector == false) {
|
if (_stackPointers.isNotEmpty && _stackPointers.last.isVector == false) {
|
||||||
if (_stack.last.type != ValueType.Key) {
|
if (_stack.last.type != ValueType.Key) {
|
||||||
throw StateError(
|
throw StateError(
|
||||||
'Adding value to a map before adding a key is prohibited');
|
'Adding value to a map before adding a key is prohibited',
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -288,7 +305,8 @@ class Builder {
|
|||||||
void _finish() {
|
void _finish() {
|
||||||
if (_stack.length != 1) {
|
if (_stack.length != 1) {
|
||||||
throw StateError(
|
throw StateError(
|
||||||
'Stack has to be exactly 1, but is ${_stack.length}. You have to end all started vectors and maps, before calling [finish]');
|
'Stack has to be exactly 1, but is ${_stack.length}. You have to end all started vectors and maps, before calling [finish]',
|
||||||
|
);
|
||||||
}
|
}
|
||||||
final value = _stack[0];
|
final value = _stack[0];
|
||||||
final byteWidth = _align(value.elementWidth(_offset, 0));
|
final byteWidth = _align(value.elementWidth(_offset, 0));
|
||||||
@@ -298,8 +316,12 @@ class Builder {
|
|||||||
_finished = true;
|
_finished = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
_StackValue _createVector(int start, int vecLength, int step,
|
_StackValue _createVector(
|
||||||
[_StackValue? keys]) {
|
int start,
|
||||||
|
int vecLength,
|
||||||
|
int step, [
|
||||||
|
_StackValue? keys,
|
||||||
|
]) {
|
||||||
var bitWidth = BitWidthUtil.uwidth(vecLength);
|
var bitWidth = BitWidthUtil.uwidth(vecLength);
|
||||||
var prefixElements = 1;
|
var prefixElements = 1;
|
||||||
if (keys != null) {
|
if (keys != null) {
|
||||||
@@ -326,7 +348,8 @@ class Builder {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
final byteWidth = _align(bitWidth);
|
final byteWidth = _align(bitWidth);
|
||||||
final fix = typed & ValueTypeUtils.isNumber(vectorType) &&
|
final fix =
|
||||||
|
typed & ValueTypeUtils.isNumber(vectorType) &&
|
||||||
vecLength >= 2 &&
|
vecLength >= 2 &&
|
||||||
vecLength <= 4;
|
vecLength <= 4;
|
||||||
if (keys != null) {
|
if (keys != null) {
|
||||||
@@ -349,8 +372,10 @@ class Builder {
|
|||||||
return _StackValue.withOffset(vecOffset, ValueType.Map, bitWidth);
|
return _StackValue.withOffset(vecOffset, ValueType.Map, bitWidth);
|
||||||
}
|
}
|
||||||
if (typed) {
|
if (typed) {
|
||||||
final vType =
|
final vType = ValueTypeUtils.toTypedVector(
|
||||||
ValueTypeUtils.toTypedVector(vectorType, fix ? vecLength : 0);
|
vectorType,
|
||||||
|
fix ? vecLength : 0,
|
||||||
|
);
|
||||||
return _StackValue.withOffset(vecOffset, vType, bitWidth);
|
return _StackValue.withOffset(vecOffset, vType, bitWidth);
|
||||||
}
|
}
|
||||||
return _StackValue.withOffset(vecOffset, ValueType.Vector, bitWidth);
|
return _StackValue.withOffset(vecOffset, ValueType.Vector, bitWidth);
|
||||||
@@ -366,7 +391,8 @@ class Builder {
|
|||||||
void _sortKeysAndEndMap(_StackPointer pointer) {
|
void _sortKeysAndEndMap(_StackPointer pointer) {
|
||||||
if (((_stack.length - pointer.stackPosition) & 1) == 1) {
|
if (((_stack.length - pointer.stackPosition) & 1) == 1) {
|
||||||
throw StateError(
|
throw StateError(
|
||||||
'The stack needs to hold key value pairs (even number of elements). Check if you combined [addKey] with add... method calls properly.');
|
'The stack needs to hold key value pairs (even number of elements). Check if you combined [addKey] with add... method calls properly.',
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
var sorted = true;
|
var sorted = true;
|
||||||
@@ -412,8 +438,12 @@ class Builder {
|
|||||||
keysStackValue = _createVector(pointer.stackPosition, vecLength, 2);
|
keysStackValue = _createVector(pointer.stackPosition, vecLength, 2);
|
||||||
_keyVectorCache[keysHash] = keysStackValue;
|
_keyVectorCache[keysHash] = keysStackValue;
|
||||||
}
|
}
|
||||||
final vec =
|
final vec = _createVector(
|
||||||
_createVector(pointer.stackPosition + 1, vecLength, 2, keysStackValue);
|
pointer.stackPosition + 1,
|
||||||
|
vecLength,
|
||||||
|
2,
|
||||||
|
keysStackValue,
|
||||||
|
);
|
||||||
_stack.removeRange(pointer.stackPosition, _stack.length);
|
_stack.removeRange(pointer.stackPosition, _stack.length);
|
||||||
_stack.add(vec);
|
_stack.add(vec);
|
||||||
}
|
}
|
||||||
@@ -421,7 +451,8 @@ class Builder {
|
|||||||
bool _shouldFlip(_StackValue v1, _StackValue v2) {
|
bool _shouldFlip(_StackValue v1, _StackValue v2) {
|
||||||
if (v1.type != ValueType.Key || v2.type != ValueType.Key) {
|
if (v1.type != ValueType.Key || v2.type != ValueType.Key) {
|
||||||
throw StateError(
|
throw StateError(
|
||||||
'Stack values are not keys $v1 | $v2. Check if you combined [addKey] with add... method calls properly.');
|
'Stack values are not keys $v1 | $v2. Check if you combined [addKey] with add... method calls properly.',
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
late int c1, c2;
|
late int c1, c2;
|
||||||
@@ -450,7 +481,8 @@ class Builder {
|
|||||||
_writeUInt(relativeOffset, byteWidth);
|
_writeUInt(relativeOffset, byteWidth);
|
||||||
} else {
|
} else {
|
||||||
throw StateError(
|
throw StateError(
|
||||||
'Unexpected size $byteWidth. This might be a bug. Please create an issue https://github.com/google/flatbuffers/issues/new');
|
'Unexpected size $byteWidth. This might be a bug. Please create an issue https://github.com/google/flatbuffers/issues/new',
|
||||||
|
);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
_pushBuffer(value.asU8List(BitWidthUtil.fromByteWidth(byteWidth)));
|
_pushBuffer(value.asU8List(BitWidthUtil.fromByteWidth(byteWidth)));
|
||||||
@@ -474,6 +506,7 @@ class Builder {
|
|||||||
if (prevSize < size) {
|
if (prevSize < size) {
|
||||||
final newBuf = ByteData(size);
|
final newBuf = ByteData(size);
|
||||||
newBuf.buffer.asUint8List().setAll(0, _buffer.buffer.asUint8List());
|
newBuf.buffer.asUint8List().setAll(0, _buffer.buffer.asUint8List());
|
||||||
|
_buffer = newBuf;
|
||||||
}
|
}
|
||||||
return newOffset;
|
return newOffset;
|
||||||
}
|
}
|
||||||
@@ -523,9 +556,7 @@ class _StackValue {
|
|||||||
final ValueType _type;
|
final ValueType _type;
|
||||||
final BitWidth _width;
|
final BitWidth _width;
|
||||||
|
|
||||||
_StackValue.withNull()
|
_StackValue.withNull() : _type = ValueType.Null, _width = BitWidth.width8;
|
||||||
: _type = ValueType.Null,
|
|
||||||
_width = BitWidth.width8;
|
|
||||||
|
|
||||||
_StackValue.withInt(int value)
|
_StackValue.withInt(int value)
|
||||||
: _type = ValueType.Int,
|
: _type = ValueType.Int,
|
||||||
@@ -562,16 +593,16 @@ class _StackValue {
|
|||||||
final offset = _offset!;
|
final offset = _offset!;
|
||||||
for (var i = 0; i < 4; i++) {
|
for (var i = 0; i < 4; i++) {
|
||||||
final width = 1 << i;
|
final width = 1 << i;
|
||||||
final bitWidth = BitWidthUtil.uwidth(size +
|
final bitWidth = BitWidthUtil.uwidth(
|
||||||
BitWidthUtil.paddingSize(size, width) +
|
size + BitWidthUtil.paddingSize(size, width) + index * width - offset,
|
||||||
index * width -
|
);
|
||||||
offset);
|
|
||||||
if (1 << bitWidth.index == width) {
|
if (1 << bitWidth.index == width) {
|
||||||
return bitWidth;
|
return bitWidth;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
throw StateError(
|
throw StateError(
|
||||||
'Element is of unknown. Size: $size at index: $index. This might be a bug. Please create an issue https://github.com/google/flatbuffers/issues/new');
|
'Element is of unknown. Size: $size at index: $index. This might be a bug. Please create an issue https://github.com/google/flatbuffers/issues/new',
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
List<int> asU8List(BitWidth width) {
|
List<int> asU8List(BitWidth width) {
|
||||||
@@ -619,7 +650,8 @@ class _StackValue {
|
|||||||
}
|
}
|
||||||
|
|
||||||
throw StateError(
|
throw StateError(
|
||||||
'Unexpected type: $_type. This might be a bug. Please create an issue https://github.com/google/flatbuffers/issues/new');
|
'Unexpected type: $_type. This might be a bug. Please create an issue https://github.com/google/flatbuffers/issues/new',
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
ValueType get type {
|
ValueType get type {
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import 'dart:collection';
|
import 'dart:collection';
|
||||||
import 'dart:convert';
|
import 'dart:convert';
|
||||||
import 'dart:typed_data';
|
import 'dart:typed_data';
|
||||||
|
|
||||||
import 'types.dart';
|
import 'types.dart';
|
||||||
|
|
||||||
/// Main class to read a value out of a FlexBuffer.
|
/// Main class to read a value out of a FlexBuffer.
|
||||||
@@ -16,9 +17,14 @@ class Reference {
|
|||||||
int? _length;
|
int? _length;
|
||||||
|
|
||||||
Reference._(
|
Reference._(
|
||||||
this._buffer, this._offset, this._parentWidth, int packedType, this._path,
|
this._buffer,
|
||||||
[int? byteWidth, ValueType? valueType])
|
this._offset,
|
||||||
: _byteWidth = byteWidth ?? 1 << (packedType & 3),
|
this._parentWidth,
|
||||||
|
int packedType,
|
||||||
|
this._path, [
|
||||||
|
int? byteWidth,
|
||||||
|
ValueType? valueType,
|
||||||
|
]) : _byteWidth = byteWidth ?? 1 << (packedType & 3),
|
||||||
_valueType = valueType ?? ValueTypeUtils.fromInt(packedType >> 2);
|
_valueType = valueType ?? ValueTypeUtils.fromInt(packedType >> 2);
|
||||||
|
|
||||||
/// Use this method to access the root value of a FlexBuffer.
|
/// Use this method to access the root value of a FlexBuffer.
|
||||||
@@ -31,8 +37,13 @@ class Reference {
|
|||||||
final byteWidth = byteData.getUint8(len - 1);
|
final byteWidth = byteData.getUint8(len - 1);
|
||||||
final packedType = byteData.getUint8(len - 2);
|
final packedType = byteData.getUint8(len - 2);
|
||||||
final offset = len - byteWidth - 2;
|
final offset = len - byteWidth - 2;
|
||||||
return Reference._(ByteData.view(buffer), offset,
|
return Reference._(
|
||||||
BitWidthUtil.fromByteWidth(byteWidth), packedType, "/");
|
ByteData.view(buffer),
|
||||||
|
offset,
|
||||||
|
BitWidthUtil.fromByteWidth(byteWidth),
|
||||||
|
packedType,
|
||||||
|
"/",
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns true if the underlying value is null.
|
/// Returns true if the underlying value is null.
|
||||||
@@ -138,7 +149,8 @@ class Reference {
|
|||||||
final index = key;
|
final index = key;
|
||||||
if (index >= length || index < 0) {
|
if (index >= length || index < 0) {
|
||||||
throw ArgumentError(
|
throw ArgumentError(
|
||||||
'Key: [$key] is not applicable on: $_path of: $_valueType length: $length');
|
'Key: [$key] is not applicable on: $_path of: $_valueType length: $length',
|
||||||
|
);
|
||||||
}
|
}
|
||||||
final elementOffset = _indirect + index * _byteWidth;
|
final elementOffset = _indirect + index * _byteWidth;
|
||||||
int packedType = 0;
|
int packedType = 0;
|
||||||
@@ -160,7 +172,8 @@ class Reference {
|
|||||||
packedType,
|
packedType,
|
||||||
"$_path[$index]",
|
"$_path[$index]",
|
||||||
byteWidth,
|
byteWidth,
|
||||||
valueType);
|
valueType,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
if (key is String && _valueType == ValueType.Map) {
|
if (key is String && _valueType == ValueType.Map) {
|
||||||
final index = _keyIndex(key);
|
final index = _keyIndex(key);
|
||||||
@@ -169,7 +182,8 @@ class Reference {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
throw ArgumentError(
|
throw ArgumentError(
|
||||||
'Key: [$key] is not applicable on: $_path of: $_valueType');
|
'Key: [$key] is not applicable on: $_path of: $_valueType',
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get an iterable if the underlying flexBuffer value is a vector.
|
/// Get an iterable if the underlying flexBuffer value is a vector.
|
||||||
@@ -213,18 +227,24 @@ class Reference {
|
|||||||
ValueTypeUtils.isAVector(_valueType) ||
|
ValueTypeUtils.isAVector(_valueType) ||
|
||||||
_valueType == ValueType.Map) {
|
_valueType == ValueType.Map) {
|
||||||
_length = _readUInt(
|
_length = _readUInt(
|
||||||
_indirect - _byteWidth, BitWidthUtil.fromByteWidth(_byteWidth));
|
_indirect - _byteWidth,
|
||||||
|
BitWidthUtil.fromByteWidth(_byteWidth),
|
||||||
|
);
|
||||||
} else if (_valueType == ValueType.Null) {
|
} else if (_valueType == ValueType.Null) {
|
||||||
_length = 0;
|
_length = 0;
|
||||||
} else if (_valueType == ValueType.String) {
|
} else if (_valueType == ValueType.String) {
|
||||||
final indirect = _indirect;
|
final indirect = _indirect;
|
||||||
var sizeByteWidth = _byteWidth;
|
var sizeByteWidth = _byteWidth;
|
||||||
var size = _readUInt(indirect - sizeByteWidth,
|
var size = _readUInt(
|
||||||
BitWidthUtil.fromByteWidth(sizeByteWidth));
|
indirect - sizeByteWidth,
|
||||||
|
BitWidthUtil.fromByteWidth(sizeByteWidth),
|
||||||
|
);
|
||||||
while (_buffer.getInt8(indirect + size) != 0) {
|
while (_buffer.getInt8(indirect + size) != 0) {
|
||||||
sizeByteWidth <<= 1;
|
sizeByteWidth <<= 1;
|
||||||
size = _readUInt(indirect - sizeByteWidth,
|
size = _readUInt(
|
||||||
BitWidthUtil.fromByteWidth(sizeByteWidth));
|
indirect - sizeByteWidth,
|
||||||
|
BitWidthUtil.fromByteWidth(sizeByteWidth),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
_length = size;
|
_length = size;
|
||||||
} else if (_valueType == ValueType.Key) {
|
} else if (_valueType == ValueType.Key) {
|
||||||
@@ -289,7 +309,8 @@ class Reference {
|
|||||||
return result.toString();
|
return result.toString();
|
||||||
}
|
}
|
||||||
throw UnsupportedError(
|
throw UnsupportedError(
|
||||||
'Type: $_valueType is not supported for JSON conversion');
|
'Type: $_valueType is not supported for JSON conversion',
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Computes the indirect offset of the value.
|
/// Computes the indirect offset of the value.
|
||||||
@@ -354,10 +375,13 @@ class Reference {
|
|||||||
int? _keyIndex(String key) {
|
int? _keyIndex(String key) {
|
||||||
final input = utf8.encode(key);
|
final input = utf8.encode(key);
|
||||||
final keysVectorOffset = _indirect - _byteWidth * 3;
|
final keysVectorOffset = _indirect - _byteWidth * 3;
|
||||||
final indirectOffset = keysVectorOffset -
|
final indirectOffset =
|
||||||
|
keysVectorOffset -
|
||||||
_readUInt(keysVectorOffset, BitWidthUtil.fromByteWidth(_byteWidth));
|
_readUInt(keysVectorOffset, BitWidthUtil.fromByteWidth(_byteWidth));
|
||||||
final byteWidth = _readUInt(
|
final byteWidth = _readUInt(
|
||||||
keysVectorOffset + _byteWidth, BitWidthUtil.fromByteWidth(_byteWidth));
|
keysVectorOffset + _byteWidth,
|
||||||
|
BitWidthUtil.fromByteWidth(_byteWidth),
|
||||||
|
);
|
||||||
var low = 0;
|
var low = 0;
|
||||||
var high = length - 1;
|
var high = length - 1;
|
||||||
while (low <= high) {
|
while (low <= high) {
|
||||||
@@ -390,24 +414,37 @@ class Reference {
|
|||||||
final indirect = _indirect;
|
final indirect = _indirect;
|
||||||
final elementOffset = indirect + index * _byteWidth;
|
final elementOffset = indirect + index * _byteWidth;
|
||||||
final packedType = _buffer.getUint8(indirect + length * _byteWidth + index);
|
final packedType = _buffer.getUint8(indirect + length * _byteWidth + index);
|
||||||
return Reference._(_buffer, elementOffset,
|
return Reference._(
|
||||||
BitWidthUtil.fromByteWidth(_byteWidth), packedType, "$_path/$key");
|
_buffer,
|
||||||
|
elementOffset,
|
||||||
|
BitWidthUtil.fromByteWidth(_byteWidth),
|
||||||
|
packedType,
|
||||||
|
"$_path/$key",
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Reference _valueForIndex(int index) {
|
Reference _valueForIndex(int index) {
|
||||||
final indirect = _indirect;
|
final indirect = _indirect;
|
||||||
final elementOffset = indirect + index * _byteWidth;
|
final elementOffset = indirect + index * _byteWidth;
|
||||||
final packedType = _buffer.getUint8(indirect + length * _byteWidth + index);
|
final packedType = _buffer.getUint8(indirect + length * _byteWidth + index);
|
||||||
return Reference._(_buffer, elementOffset,
|
return Reference._(
|
||||||
BitWidthUtil.fromByteWidth(_byteWidth), packedType, "$_path/[$index]");
|
_buffer,
|
||||||
|
elementOffset,
|
||||||
|
BitWidthUtil.fromByteWidth(_byteWidth),
|
||||||
|
packedType,
|
||||||
|
"$_path/[$index]",
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
String _keyForIndex(int index) {
|
String _keyForIndex(int index) {
|
||||||
final keysVectorOffset = _indirect - _byteWidth * 3;
|
final keysVectorOffset = _indirect - _byteWidth * 3;
|
||||||
final indirectOffset = keysVectorOffset -
|
final indirectOffset =
|
||||||
|
keysVectorOffset -
|
||||||
_readUInt(keysVectorOffset, BitWidthUtil.fromByteWidth(_byteWidth));
|
_readUInt(keysVectorOffset, BitWidthUtil.fromByteWidth(_byteWidth));
|
||||||
final byteWidth = _readUInt(
|
final byteWidth = _readUInt(
|
||||||
keysVectorOffset + _byteWidth, BitWidthUtil.fromByteWidth(_byteWidth));
|
keysVectorOffset + _byteWidth,
|
||||||
|
BitWidthUtil.fromByteWidth(_byteWidth),
|
||||||
|
);
|
||||||
final keyOffset = indirectOffset + index * byteWidth;
|
final keyOffset = indirectOffset + index * byteWidth;
|
||||||
final keyIndirectOffset =
|
final keyIndirectOffset =
|
||||||
keyOffset - _readUInt(keyOffset, BitWidthUtil.fromByteWidth(byteWidth));
|
keyOffset - _readUInt(keyOffset, BitWidthUtil.fromByteWidth(byteWidth));
|
||||||
|
|||||||
@@ -86,7 +86,8 @@ enum ValueType {
|
|||||||
VectorFloat,
|
VectorFloat,
|
||||||
VectorKey,
|
VectorKey,
|
||||||
@Deprecated(
|
@Deprecated(
|
||||||
'VectorString is deprecated due to a flaw in the binary format (https://github.com/google/flatbuffers/issues/5627)')
|
'VectorString is deprecated due to a flaw in the binary format (https://github.com/google/flatbuffers/issues/5627)',
|
||||||
|
)
|
||||||
VectorString,
|
VectorString,
|
||||||
VectorInt2,
|
VectorInt2,
|
||||||
VectorUInt2,
|
VectorUInt2,
|
||||||
@@ -99,7 +100,7 @@ enum ValueType {
|
|||||||
VectorFloat4,
|
VectorFloat4,
|
||||||
Blob,
|
Blob,
|
||||||
Bool,
|
Bool,
|
||||||
VectorBool
|
VectorBool,
|
||||||
}
|
}
|
||||||
|
|
||||||
class ValueTypeUtils {
|
class ValueTypeUtils {
|
||||||
@@ -153,31 +154,37 @@ class ValueTypeUtils {
|
|||||||
static ValueType toTypedVector(ValueType self, int length) {
|
static ValueType toTypedVector(ValueType self, int length) {
|
||||||
if (length == 0) {
|
if (length == 0) {
|
||||||
return ValueTypeUtils.fromInt(
|
return ValueTypeUtils.fromInt(
|
||||||
toInt(self) - toInt(ValueType.Int) + toInt(ValueType.VectorInt));
|
toInt(self) - toInt(ValueType.Int) + toInt(ValueType.VectorInt),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
if (length == 2) {
|
if (length == 2) {
|
||||||
return ValueTypeUtils.fromInt(
|
return ValueTypeUtils.fromInt(
|
||||||
toInt(self) - toInt(ValueType.Int) + toInt(ValueType.VectorInt2));
|
toInt(self) - toInt(ValueType.Int) + toInt(ValueType.VectorInt2),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
if (length == 3) {
|
if (length == 3) {
|
||||||
return ValueTypeUtils.fromInt(
|
return ValueTypeUtils.fromInt(
|
||||||
toInt(self) - toInt(ValueType.Int) + toInt(ValueType.VectorInt3));
|
toInt(self) - toInt(ValueType.Int) + toInt(ValueType.VectorInt3),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
if (length == 4) {
|
if (length == 4) {
|
||||||
return ValueTypeUtils.fromInt(
|
return ValueTypeUtils.fromInt(
|
||||||
toInt(self) - toInt(ValueType.Int) + toInt(ValueType.VectorInt4));
|
toInt(self) - toInt(ValueType.Int) + toInt(ValueType.VectorInt4),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
throw Exception('unexpected length ' + length.toString());
|
throw Exception('unexpected length ' + length.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
static ValueType typedVectorElementType(ValueType self) {
|
static ValueType typedVectorElementType(ValueType self) {
|
||||||
return ValueTypeUtils.fromInt(
|
return ValueTypeUtils.fromInt(
|
||||||
toInt(self) - toInt(ValueType.VectorInt) + toInt(ValueType.Int));
|
toInt(self) - toInt(ValueType.VectorInt) + toInt(ValueType.Int),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
static ValueType fixedTypedVectorElementType(ValueType self) {
|
static ValueType fixedTypedVectorElementType(ValueType self) {
|
||||||
return ValueTypeUtils.fromInt(
|
return ValueTypeUtils.fromInt(
|
||||||
(toInt(self) - toInt(ValueType.VectorInt2)) % 3 + toInt(ValueType.Int));
|
(toInt(self) - toInt(ValueType.VectorInt2)) % 3 + toInt(ValueType.Int),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int fixedTypedVectorElementSize(ValueType self) {
|
static int fixedTypedVectorElementSize(ValueType self) {
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
name: flat_buffers
|
name: flat_buffers
|
||||||
version: 25.2.10
|
version: 25.12.19
|
||||||
description: FlatBuffers reading and writing library for Dart. Based on original work by Konstantin Scheglov and Paul Berry of the Dart SDK team.
|
description: FlatBuffers reading and writing library for Dart. Based on original work by Konstantin Scheglov and Paul Berry of the Dart SDK team.
|
||||||
homepage: https://github.com/google/flatbuffers
|
homepage: https://github.com/google/flatbuffers
|
||||||
documentation: https://google.github.io/flatbuffers/index.html
|
documentation: https://google.github.io/flatbuffers/index.html
|
||||||
|
|||||||
@@ -2,8 +2,8 @@
|
|||||||
// ignore_for_file: unused_import, unused_field, unused_element, unused_local_variable, constant_identifier_names
|
// ignore_for_file: unused_import, unused_field, unused_element, unused_local_variable, constant_identifier_names
|
||||||
|
|
||||||
import 'dart:typed_data' show Uint8List;
|
import 'dart:typed_data' show Uint8List;
|
||||||
import 'package:flat_buffers/flat_buffers.dart' as fb;
|
|
||||||
|
|
||||||
|
import 'package:flat_buffers/flat_buffers.dart' as fb;
|
||||||
|
|
||||||
class Foo {
|
class Foo {
|
||||||
Foo._(this._bc, this._bcOffset);
|
Foo._(this._bc, this._bcOffset);
|
||||||
@@ -17,15 +17,15 @@ class Foo {
|
|||||||
final fb.BufferContext _bc;
|
final fb.BufferContext _bc;
|
||||||
final int _bcOffset;
|
final int _bcOffset;
|
||||||
|
|
||||||
FooProperties? get myFoo => FooProperties.reader.vTableGetNullable(_bc, _bcOffset, 4);
|
FooProperties? get myFoo =>
|
||||||
|
FooProperties.reader.vTableGetNullable(_bc, _bcOffset, 4);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String toString() {
|
String toString() {
|
||||||
return 'Foo{myFoo: ${myFoo}}';
|
return 'Foo{myFoo: ${myFoo}}';
|
||||||
}
|
}
|
||||||
|
|
||||||
FooT unpack() => FooT(
|
FooT unpack() => FooT(myFoo: myFoo?.unpack());
|
||||||
myFoo: myFoo?.unpack());
|
|
||||||
|
|
||||||
static int pack(fb.Builder fbBuilder, FooT? object) {
|
static int pack(fb.Builder fbBuilder, FooT? object) {
|
||||||
if (object == null) return 0;
|
if (object == null) return 0;
|
||||||
@@ -36,8 +36,7 @@ class Foo {
|
|||||||
class FooT implements fb.Packable {
|
class FooT implements fb.Packable {
|
||||||
FooPropertiesT? myFoo;
|
FooPropertiesT? myFoo;
|
||||||
|
|
||||||
FooT({
|
FooT({this.myFoo});
|
||||||
this.myFoo});
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
int pack(fb.Builder fbBuilder) {
|
int pack(fb.Builder fbBuilder) {
|
||||||
@@ -58,8 +57,7 @@ class _FooReader extends fb.TableReader<Foo> {
|
|||||||
const _FooReader();
|
const _FooReader();
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Foo createObject(fb.BufferContext bc, int offset) =>
|
Foo createObject(fb.BufferContext bc, int offset) => Foo._(bc, offset);
|
||||||
Foo._(bc, offset);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class FooBuilder {
|
class FooBuilder {
|
||||||
@@ -84,10 +82,7 @@ class FooBuilder {
|
|||||||
class FooObjectBuilder extends fb.ObjectBuilder {
|
class FooObjectBuilder extends fb.ObjectBuilder {
|
||||||
final FooPropertiesObjectBuilder? _myFoo;
|
final FooPropertiesObjectBuilder? _myFoo;
|
||||||
|
|
||||||
FooObjectBuilder({
|
FooObjectBuilder({FooPropertiesObjectBuilder? myFoo}) : _myFoo = myFoo;
|
||||||
FooPropertiesObjectBuilder? myFoo,
|
|
||||||
})
|
|
||||||
: _myFoo = myFoo;
|
|
||||||
|
|
||||||
/// Finish building, and store into the [fbBuilder].
|
/// Finish building, and store into the [fbBuilder].
|
||||||
@override
|
@override
|
||||||
@@ -107,6 +102,7 @@ class FooObjectBuilder extends fb.ObjectBuilder {
|
|||||||
return fbBuilder.buffer;
|
return fbBuilder.buffer;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class FooProperties {
|
class FooProperties {
|
||||||
FooProperties._(this._bc, this._bcOffset);
|
FooProperties._(this._bc, this._bcOffset);
|
||||||
|
|
||||||
@@ -123,9 +119,7 @@ class FooProperties {
|
|||||||
return 'FooProperties{a: ${a}, b: ${b}}';
|
return 'FooProperties{a: ${a}, b: ${b}}';
|
||||||
}
|
}
|
||||||
|
|
||||||
FooPropertiesT unpack() => FooPropertiesT(
|
FooPropertiesT unpack() => FooPropertiesT(a: a, b: b);
|
||||||
a: a,
|
|
||||||
b: b);
|
|
||||||
|
|
||||||
static int pack(fb.Builder fbBuilder, FooPropertiesT? object) {
|
static int pack(fb.Builder fbBuilder, FooPropertiesT? object) {
|
||||||
if (object == null) return 0;
|
if (object == null) return 0;
|
||||||
@@ -137,9 +131,7 @@ class FooPropertiesT implements fb.Packable {
|
|||||||
bool a;
|
bool a;
|
||||||
bool b;
|
bool b;
|
||||||
|
|
||||||
FooPropertiesT({
|
FooPropertiesT({required this.a, required this.b});
|
||||||
required this.a,
|
|
||||||
required this.b});
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
int pack(fb.Builder fbBuilder) {
|
int pack(fb.Builder fbBuilder) {
|
||||||
@@ -175,17 +167,13 @@ class FooPropertiesBuilder {
|
|||||||
fbBuilder.putBool(a);
|
fbBuilder.putBool(a);
|
||||||
return fbBuilder.offset;
|
return fbBuilder.offset;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class FooPropertiesObjectBuilder extends fb.ObjectBuilder {
|
class FooPropertiesObjectBuilder extends fb.ObjectBuilder {
|
||||||
final bool _a;
|
final bool _a;
|
||||||
final bool _b;
|
final bool _b;
|
||||||
|
|
||||||
FooPropertiesObjectBuilder({
|
FooPropertiesObjectBuilder({required bool a, required bool b})
|
||||||
required bool a,
|
|
||||||
required bool b,
|
|
||||||
})
|
|
||||||
: _a = a,
|
: _a = a,
|
||||||
_b = b;
|
_b = b;
|
||||||
|
|
||||||
|
|||||||
@@ -2,8 +2,8 @@
|
|||||||
// ignore_for_file: unused_import, unused_field, unused_element, unused_local_variable, constant_identifier_names
|
// ignore_for_file: unused_import, unused_field, unused_element, unused_local_variable, constant_identifier_names
|
||||||
|
|
||||||
import 'dart:typed_data' show Uint8List;
|
import 'dart:typed_data' show Uint8List;
|
||||||
import 'package:flat_buffers/flat_buffers.dart' as fb;
|
|
||||||
|
|
||||||
|
import 'package:flat_buffers/flat_buffers.dart' as fb;
|
||||||
|
|
||||||
enum OptionsEnum {
|
enum OptionsEnum {
|
||||||
A(1),
|
A(1),
|
||||||
@@ -15,10 +15,14 @@ enum OptionsEnum {
|
|||||||
|
|
||||||
factory OptionsEnum.fromValue(int value) {
|
factory OptionsEnum.fromValue(int value) {
|
||||||
switch (value) {
|
switch (value) {
|
||||||
case 1: return OptionsEnum.A;
|
case 1:
|
||||||
case 2: return OptionsEnum.B;
|
return OptionsEnum.A;
|
||||||
case 3: return OptionsEnum.C;
|
case 2:
|
||||||
default: throw StateError('Invalid value $value for bit flag enum');
|
return OptionsEnum.B;
|
||||||
|
case 3:
|
||||||
|
return OptionsEnum.C;
|
||||||
|
default:
|
||||||
|
throw StateError('Invalid value $value for bit flag enum');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -53,7 +57,9 @@ class MyTable {
|
|||||||
final fb.BufferContext _bc;
|
final fb.BufferContext _bc;
|
||||||
final int _bcOffset;
|
final int _bcOffset;
|
||||||
|
|
||||||
List<OptionsEnum>? get options => const fb.ListReader<OptionsEnum>(OptionsEnum.reader).vTableGetNullable(_bc, _bcOffset, 4);
|
List<OptionsEnum>? get options => const fb.ListReader<OptionsEnum>(
|
||||||
|
OptionsEnum.reader,
|
||||||
|
).vTableGetNullable(_bc, _bcOffset, 4);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String toString() {
|
String toString() {
|
||||||
@@ -61,7 +67,11 @@ class MyTable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
MyTableT unpack() => MyTableT(
|
MyTableT unpack() => MyTableT(
|
||||||
options: const fb.ListReader<OptionsEnum>(OptionsEnum.reader, lazy: false).vTableGetNullable(_bc, _bcOffset, 4));
|
options: const fb.ListReader<OptionsEnum>(
|
||||||
|
OptionsEnum.reader,
|
||||||
|
lazy: false,
|
||||||
|
).vTableGetNullable(_bc, _bcOffset, 4),
|
||||||
|
);
|
||||||
|
|
||||||
static int pack(fb.Builder fbBuilder, MyTableT? object) {
|
static int pack(fb.Builder fbBuilder, MyTableT? object) {
|
||||||
if (object == null) return 0;
|
if (object == null) return 0;
|
||||||
@@ -72,12 +82,12 @@ class MyTable {
|
|||||||
class MyTableT implements fb.Packable {
|
class MyTableT implements fb.Packable {
|
||||||
List<OptionsEnum>? options;
|
List<OptionsEnum>? options;
|
||||||
|
|
||||||
MyTableT({
|
MyTableT({this.options});
|
||||||
this.options});
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
int pack(fb.Builder fbBuilder) {
|
int pack(fb.Builder fbBuilder) {
|
||||||
final int? optionsOffset = options == null ? null
|
final int? optionsOffset = options == null
|
||||||
|
? null
|
||||||
: fbBuilder.writeListUint32(options!.map((f) => f.value).toList());
|
: fbBuilder.writeListUint32(options!.map((f) => f.value).toList());
|
||||||
fbBuilder.startTable(1);
|
fbBuilder.startTable(1);
|
||||||
fbBuilder.addOffset(0, optionsOffset);
|
fbBuilder.addOffset(0, optionsOffset);
|
||||||
@@ -120,15 +130,13 @@ class MyTableBuilder {
|
|||||||
class MyTableObjectBuilder extends fb.ObjectBuilder {
|
class MyTableObjectBuilder extends fb.ObjectBuilder {
|
||||||
final List<OptionsEnum>? _options;
|
final List<OptionsEnum>? _options;
|
||||||
|
|
||||||
MyTableObjectBuilder({
|
MyTableObjectBuilder({List<OptionsEnum>? options}) : _options = options;
|
||||||
List<OptionsEnum>? options,
|
|
||||||
})
|
|
||||||
: _options = options;
|
|
||||||
|
|
||||||
/// Finish building, and store into the [fbBuilder].
|
/// Finish building, and store into the [fbBuilder].
|
||||||
@override
|
@override
|
||||||
int finish(fb.Builder fbBuilder) {
|
int finish(fb.Builder fbBuilder) {
|
||||||
final int? optionsOffset = _options == null ? null
|
final int? optionsOffset = _options == null
|
||||||
|
? null
|
||||||
: fbBuilder.writeListUint32(_options!.map((f) => f.value).toList());
|
: fbBuilder.writeListUint32(_options!.map((f) => f.value).toList());
|
||||||
fbBuilder.startTable(1);
|
fbBuilder.startTable(1);
|
||||||
fbBuilder.addOffset(0, optionsOffset);
|
fbBuilder.addOffset(0, optionsOffset);
|
||||||
|
|||||||
@@ -1,16 +1,15 @@
|
|||||||
import 'dart:typed_data';
|
|
||||||
import 'dart:io' as io;
|
import 'dart:io' as io;
|
||||||
|
import 'dart:typed_data';
|
||||||
import 'package:path/path.dart' as path;
|
|
||||||
|
|
||||||
import 'package:flat_buffers/flat_buffers.dart';
|
import 'package:flat_buffers/flat_buffers.dart';
|
||||||
|
import 'package:path/path.dart' as path;
|
||||||
import 'package:test/test.dart';
|
import 'package:test/test.dart';
|
||||||
import 'package:test_reflective_loader/test_reflective_loader.dart';
|
import 'package:test_reflective_loader/test_reflective_loader.dart';
|
||||||
|
|
||||||
import './monster_test_my_game.example_generated.dart' as example;
|
|
||||||
import './monster_test_my_game.example2_generated.dart' as example2;
|
|
||||||
import 'enums_generated.dart' as example3;
|
|
||||||
import './bool_structs_generated.dart' as example4;
|
import './bool_structs_generated.dart' as example4;
|
||||||
|
import './monster_test_my_game.example2_generated.dart' as example2;
|
||||||
|
import './monster_test_my_game.example_generated.dart' as example;
|
||||||
|
import 'enums_generated.dart' as example3;
|
||||||
|
|
||||||
main() {
|
main() {
|
||||||
defineReflectiveSuite(() {
|
defineReflectiveSuite(() {
|
||||||
@@ -29,11 +28,9 @@ int indexToField(int index) {
|
|||||||
@reflectiveTest
|
@reflectiveTest
|
||||||
class CheckOtherLangaugesData {
|
class CheckOtherLangaugesData {
|
||||||
test_cppData() async {
|
test_cppData() async {
|
||||||
List<int> data = await io.File(path.join(
|
List<int> data = await io.File(
|
||||||
path.context.current,
|
path.join(path.context.current, 'test', 'monsterdata_test.mon'),
|
||||||
'test',
|
).readAsBytes();
|
||||||
'monsterdata_test.mon',
|
|
||||||
)).readAsBytes();
|
|
||||||
example.Monster mon = example.Monster(data);
|
example.Monster mon = example.Monster(data);
|
||||||
expect(mon.hp, 80);
|
expect(mon.hp, 80);
|
||||||
expect(mon.mana, 150);
|
expect(mon.mana, 150);
|
||||||
@@ -145,7 +142,8 @@ class CheckOtherLangaugesData {
|
|||||||
'longEnumNormalDefault: LongEnum.LongOne, nanDefault: NaN, '
|
'longEnumNormalDefault: LongEnum.LongOne, nanDefault: NaN, '
|
||||||
'infDefault: Infinity, positiveInfDefault: Infinity, infinityDefault: '
|
'infDefault: Infinity, positiveInfDefault: Infinity, infinityDefault: '
|
||||||
'Infinity, positiveInfinityDefault: Infinity, negativeInfDefault: '
|
'Infinity, positiveInfinityDefault: Infinity, negativeInfDefault: '
|
||||||
'-Infinity, negativeInfinityDefault: -Infinity, doubleInfDefault: Infinity}');
|
'-Infinity, negativeInfinityDefault: -Infinity, doubleInfDefault: Infinity}',
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -298,20 +296,72 @@ class BuilderTest {
|
|||||||
expect(allocator.buffer(builder.size()), [2, 0, 0, 0, 0, 0, 0, 1]);
|
expect(allocator.buffer(builder.size()), [2, 0, 0, 0, 0, 0, 0, 1]);
|
||||||
|
|
||||||
builder.putUint8(3);
|
builder.putUint8(3);
|
||||||
expect(
|
expect(allocator.buffer(builder.size()), [
|
||||||
allocator.buffer(builder.size()), [0, 0, 0, 3, 2, 0, 0, 0, 0, 0, 0, 1]);
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
3,
|
||||||
|
2,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
1,
|
||||||
|
]);
|
||||||
|
|
||||||
builder.putUint8(4);
|
builder.putUint8(4);
|
||||||
expect(
|
expect(allocator.buffer(builder.size()), [
|
||||||
allocator.buffer(builder.size()), [0, 0, 4, 3, 2, 0, 0, 0, 0, 0, 0, 1]);
|
0,
|
||||||
|
0,
|
||||||
|
4,
|
||||||
|
3,
|
||||||
|
2,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
1,
|
||||||
|
]);
|
||||||
|
|
||||||
builder.putUint8(5);
|
builder.putUint8(5);
|
||||||
expect(
|
expect(allocator.buffer(builder.size()), [
|
||||||
allocator.buffer(builder.size()), [0, 5, 4, 3, 2, 0, 0, 0, 0, 0, 0, 1]);
|
0,
|
||||||
|
5,
|
||||||
|
4,
|
||||||
|
3,
|
||||||
|
2,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
1,
|
||||||
|
]);
|
||||||
|
|
||||||
builder.putUint32(6);
|
builder.putUint32(6);
|
||||||
expect(allocator.buffer(builder.size()),
|
expect(allocator.buffer(builder.size()), [
|
||||||
[6, 0, 0, 0, 0, 5, 4, 3, 2, 0, 0, 0, 0, 0, 0, 1]);
|
6,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
5,
|
||||||
|
4,
|
||||||
|
3,
|
||||||
|
2,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
1,
|
||||||
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
void test_table_default() {
|
void test_table_default() {
|
||||||
@@ -331,14 +381,14 @@ class BuilderTest {
|
|||||||
int objectOffset = buffer.derefObject(0);
|
int objectOffset = buffer.derefObject(0);
|
||||||
// was not written, so uses the new default value
|
// was not written, so uses the new default value
|
||||||
expect(
|
expect(
|
||||||
const Int32Reader()
|
const Int32Reader().vTableGet(buffer, objectOffset, indexToField(0), 15),
|
||||||
.vTableGet(buffer, objectOffset, indexToField(0), 15),
|
15,
|
||||||
15);
|
);
|
||||||
// has the written value
|
// has the written value
|
||||||
expect(
|
expect(
|
||||||
const Int32Reader()
|
const Int32Reader().vTableGet(buffer, objectOffset, indexToField(1), 15),
|
||||||
.vTableGet(buffer, objectOffset, indexToField(1), 15),
|
20,
|
||||||
20);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
void test_table_format([Builder? builder]) {
|
void test_table_format([Builder? builder]) {
|
||||||
@@ -370,7 +420,9 @@ class BuilderTest {
|
|||||||
for (int i = 0; i < 3; i++) {
|
for (int i = 0; i < 3; i++) {
|
||||||
int offset = byteData.getUint16(vTableLoc + 4 + 2 * i, Endian.little);
|
int offset = byteData.getUint16(vTableLoc + 4 + 2 * i, Endian.little);
|
||||||
expect(
|
expect(
|
||||||
byteData.getInt32(tableDataLoc + offset, Endian.little), 10 + 10 * i);
|
byteData.getInt32(tableDataLoc + offset, Endian.little),
|
||||||
|
10 + 10 * i,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -380,10 +432,14 @@ class BuilderTest {
|
|||||||
List<int> byteList;
|
List<int> byteList;
|
||||||
{
|
{
|
||||||
Builder builder = Builder(initialSize: 0);
|
Builder builder = Builder(initialSize: 0);
|
||||||
int? latinStringOffset =
|
int? latinStringOffset = builder.writeString(
|
||||||
builder.writeString(latinString, asciiOptimization: true);
|
latinString,
|
||||||
int? unicodeStringOffset =
|
asciiOptimization: true,
|
||||||
builder.writeString(unicodeString, asciiOptimization: true);
|
);
|
||||||
|
int? unicodeStringOffset = builder.writeString(
|
||||||
|
unicodeString,
|
||||||
|
asciiOptimization: true,
|
||||||
|
);
|
||||||
builder.startTable(2);
|
builder.startTable(2);
|
||||||
builder.addOffset(0, latinStringOffset);
|
builder.addOffset(0, latinStringOffset);
|
||||||
builder.addOffset(1, unicodeStringOffset);
|
builder.addOffset(1, unicodeStringOffset);
|
||||||
@@ -395,13 +451,19 @@ class BuilderTest {
|
|||||||
BufferContext buf = BufferContext.fromBytes(byteList);
|
BufferContext buf = BufferContext.fromBytes(byteList);
|
||||||
int objectOffset = buf.derefObject(0);
|
int objectOffset = buf.derefObject(0);
|
||||||
expect(
|
expect(
|
||||||
const StringReader()
|
const StringReader().vTableGetNullable(
|
||||||
.vTableGetNullable(buf, objectOffset, indexToField(0)),
|
buf,
|
||||||
latinString);
|
objectOffset,
|
||||||
|
indexToField(0),
|
||||||
|
),
|
||||||
|
latinString,
|
||||||
|
);
|
||||||
expect(
|
expect(
|
||||||
const StringReader(asciiOptimization: true)
|
const StringReader(
|
||||||
.vTableGetNullable(buf, objectOffset, indexToField(1)),
|
asciiOptimization: true,
|
||||||
unicodeString);
|
).vTableGetNullable(buf, objectOffset, indexToField(1)),
|
||||||
|
unicodeString,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
void test_table_types([Builder? builder]) {
|
void test_table_types([Builder? builder]) {
|
||||||
@@ -425,33 +487,41 @@ class BuilderTest {
|
|||||||
BufferContext buf = BufferContext.fromBytes(byteList);
|
BufferContext buf = BufferContext.fromBytes(byteList);
|
||||||
int objectOffset = buf.derefObject(0);
|
int objectOffset = buf.derefObject(0);
|
||||||
expect(
|
expect(
|
||||||
const BoolReader()
|
const BoolReader().vTableGetNullable(buf, objectOffset, indexToField(0)),
|
||||||
.vTableGetNullable(buf, objectOffset, indexToField(0)),
|
true,
|
||||||
true);
|
);
|
||||||
expect(
|
expect(
|
||||||
const Int8Reader()
|
const Int8Reader().vTableGetNullable(buf, objectOffset, indexToField(1)),
|
||||||
.vTableGetNullable(buf, objectOffset, indexToField(1)),
|
10,
|
||||||
10);
|
);
|
||||||
expect(
|
expect(
|
||||||
const Int32Reader()
|
const Int32Reader().vTableGetNullable(buf, objectOffset, indexToField(2)),
|
||||||
.vTableGetNullable(buf, objectOffset, indexToField(2)),
|
20,
|
||||||
20);
|
);
|
||||||
expect(
|
expect(
|
||||||
const StringReader()
|
const StringReader().vTableGetNullable(
|
||||||
.vTableGetNullable(buf, objectOffset, indexToField(3)),
|
buf,
|
||||||
'12345');
|
objectOffset,
|
||||||
|
indexToField(3),
|
||||||
|
),
|
||||||
|
'12345',
|
||||||
|
);
|
||||||
expect(
|
expect(
|
||||||
const Int32Reader()
|
const Int32Reader().vTableGetNullable(buf, objectOffset, indexToField(4)),
|
||||||
.vTableGetNullable(buf, objectOffset, indexToField(4)),
|
40,
|
||||||
40);
|
);
|
||||||
expect(
|
expect(
|
||||||
const Uint32Reader()
|
const Uint32Reader().vTableGetNullable(
|
||||||
.vTableGetNullable(buf, objectOffset, indexToField(5)),
|
buf,
|
||||||
0x9ABCDEF0);
|
objectOffset,
|
||||||
|
indexToField(5),
|
||||||
|
),
|
||||||
|
0x9ABCDEF0,
|
||||||
|
);
|
||||||
expect(
|
expect(
|
||||||
const Uint8Reader()
|
const Uint8Reader().vTableGetNullable(buf, objectOffset, indexToField(6)),
|
||||||
.vTableGetNullable(buf, objectOffset, indexToField(6)),
|
0x9A,
|
||||||
0x9A);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
void test_writeList_of_Uint32() {
|
void test_writeList_of_Uint32() {
|
||||||
@@ -596,8 +666,9 @@ class BuilderTest {
|
|||||||
}
|
}
|
||||||
// read and verify
|
// read and verify
|
||||||
BufferContext buf = BufferContext.fromBytes(byteList);
|
BufferContext buf = BufferContext.fromBytes(byteList);
|
||||||
List<TestPointImpl> items =
|
List<TestPointImpl> items = const ListReader<TestPointImpl>(
|
||||||
const ListReader<TestPointImpl>(TestPointReader()).read(buf, 0);
|
TestPointReader(),
|
||||||
|
).read(buf, 0);
|
||||||
expect(items, hasLength(2));
|
expect(items, hasLength(2));
|
||||||
expect(items[0].x, 10);
|
expect(items[0].x, 10);
|
||||||
expect(items[0].y, 20);
|
expect(items[0].y, 20);
|
||||||
@@ -627,8 +698,10 @@ class BuilderTest {
|
|||||||
List<int> byteList;
|
List<int> byteList;
|
||||||
{
|
{
|
||||||
builder ??= Builder(initialSize: 0);
|
builder ??= Builder(initialSize: 0);
|
||||||
int listOffset = builder.writeList(
|
int listOffset = builder.writeList([
|
||||||
[builder.writeString('12345'), builder.writeString('ABC')]);
|
builder.writeString('12345'),
|
||||||
|
builder.writeString('ABC'),
|
||||||
|
]);
|
||||||
builder.startTable(1);
|
builder.startTable(1);
|
||||||
builder.addOffset(0, listOffset);
|
builder.addOffset(0, listOffset);
|
||||||
int offset = builder.endTable();
|
int offset = builder.endTable();
|
||||||
@@ -707,13 +780,14 @@ class BuilderTest {
|
|||||||
test_table_format,
|
test_table_format,
|
||||||
test_table_types,
|
test_table_types,
|
||||||
test_writeList_ofObjects,
|
test_writeList_ofObjects,
|
||||||
test_writeList_ofStrings_inObject
|
test_writeList_ofStrings_inObject,
|
||||||
];
|
];
|
||||||
|
|
||||||
// Execute all test cases in all permutations of their order.
|
// Execute all test cases in all permutations of their order.
|
||||||
// To do that, we generate permutations of test case indexes.
|
// To do that, we generate permutations of test case indexes.
|
||||||
final testCasesPermutations =
|
final testCasesPermutations = _permutationsOf(
|
||||||
_permutationsOf(List.generate(testCases.length, (index) => index));
|
List.generate(testCases.length, (index) => index),
|
||||||
|
);
|
||||||
expect(testCasesPermutations.length, _factorial(testCases.length));
|
expect(testCasesPermutations.length, _factorial(testCases.length));
|
||||||
|
|
||||||
for (var indexes in testCasesPermutations) {
|
for (var indexes in testCasesPermutations) {
|
||||||
@@ -788,23 +862,23 @@ class ObjectAPITest {
|
|||||||
z: 3,
|
z: 3,
|
||||||
test1: 4.0,
|
test1: 4.0,
|
||||||
test2: example.Color.Red,
|
test2: example.Color.Red,
|
||||||
test3: example.TestT(a: 1, b: 2))
|
test3: example.TestT(a: 1, b: 2),
|
||||||
|
)
|
||||||
..mana = 2
|
..mana = 2
|
||||||
..name = 'Monstrous'
|
..name = 'Monstrous'
|
||||||
..inventory = [24, 42]
|
..inventory = [24, 42]
|
||||||
..color = example.Color.Green
|
..color = example.Color.Green
|
||||||
// TODO be smarter for unions and automatically set the `type` field?
|
|
||||||
..testType = example.AnyTypeId.MyGame_Example2_Monster
|
..testType = example.AnyTypeId.MyGame_Example2_Monster
|
||||||
..test = example2.MonsterT()
|
..test = example2.MonsterT()
|
||||||
..test4 = [example.TestT(a: 3, b: 4), example.TestT(a: 5, b: 6)]
|
..test4 = [example.TestT(a: 3, b: 4), example.TestT(a: 5, b: 6)]
|
||||||
..testarrayofstring = ["foo", "bar"]
|
..testarrayofstring = ["foo", "bar"]
|
||||||
..testarrayoftables = [example.MonsterT(name: 'Oof')]
|
..testarrayoftables = [example.MonsterT(name: 'Oof', testf: 2.75)]
|
||||||
..enemy = example.MonsterT(name: 'Enemy')
|
..enemy = example.MonsterT(name: 'Enemy', testf: 2.5)
|
||||||
..testarrayofbools = [false, true, false]
|
..testarrayofbools = [false, true, false]
|
||||||
..testf = 42.24
|
..testf = 42.25
|
||||||
..testarrayofsortedstruct = [
|
..testarrayofsortedstruct = [
|
||||||
example.AbilityT(id: 1, distance: 5),
|
example.AbilityT(id: 1, distance: 5),
|
||||||
example.AbilityT(id: 3, distance: 7)
|
example.AbilityT(id: 3, distance: 7),
|
||||||
]
|
]
|
||||||
..vectorOfLongs = [5, 6, 7]
|
..vectorOfLongs = [5, 6, 7]
|
||||||
..vectorOfDoubles = [8.9, 9.0, 10.1, 11.2]
|
..vectorOfDoubles = [8.9, 9.0, 10.1, 11.2]
|
||||||
@@ -819,16 +893,15 @@ class ObjectAPITest {
|
|||||||
fbBuilder.finish(offset);
|
fbBuilder.finish(offset);
|
||||||
final data = fbBuilder.buffer;
|
final data = fbBuilder.buffer;
|
||||||
|
|
||||||
// TODO currently broken because of struct builder issue, see #6688
|
final monster2 = example.Monster(data); // Monster (reader)
|
||||||
// final monster2 = example.Monster(data); // Monster (reader)
|
expect(
|
||||||
// expect(
|
// map Monster => MonsterT, Vec3 => Vec3T, ...
|
||||||
// // map Monster => MonsterT, Vec3 => Vec3T, ...
|
monster2.toString().replaceAllMapped(
|
||||||
// monster2.toString().replaceAllMapped(
|
RegExp('([a-zA-z0-9]+){'), (match) => match.group(1)! + 'T{'),
|
||||||
// RegExp('([a-zA-z0-9]+){'), (match) => match.group(1) + 'T{'),
|
monster.toString());
|
||||||
// monster.toString());
|
|
||||||
//
|
final monster3 = monster2.unpack(); // MonsterT
|
||||||
// final monster3 = monster2.unpack(); // MonsterT
|
expect(monster3.toString(), monster.toString());
|
||||||
// expect(monster3.toString(), monster.toString());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void test_Lists() {
|
void test_Lists() {
|
||||||
@@ -867,8 +940,9 @@ class StringListWrapperImpl {
|
|||||||
|
|
||||||
StringListWrapperImpl(this.bp, this.offset);
|
StringListWrapperImpl(this.bp, this.offset);
|
||||||
|
|
||||||
List<String>? get items => const ListReader<String>(StringReader())
|
List<String>? get items => const ListReader<String>(
|
||||||
.vTableGetNullable(bp, offset, indexToField(0));
|
StringReader(),
|
||||||
|
).vTableGetNullable(bp, offset, indexToField(0));
|
||||||
}
|
}
|
||||||
|
|
||||||
class StringListWrapperReader extends TableReader<StringListWrapperImpl> {
|
class StringListWrapperReader extends TableReader<StringListWrapperImpl> {
|
||||||
@@ -906,10 +980,14 @@ class GeneratorTest {
|
|||||||
expect(example.Color.values, same(example.Color.values));
|
expect(example.Color.values, same(example.Color.values));
|
||||||
expect(example.Race.values, same(example.Race.values));
|
expect(example.Race.values, same(example.Race.values));
|
||||||
expect(example.AnyTypeId.values, same(example.AnyTypeId.values));
|
expect(example.AnyTypeId.values, same(example.AnyTypeId.values));
|
||||||
expect(example.AnyUniqueAliasesTypeId.values,
|
expect(
|
||||||
same(example.AnyUniqueAliasesTypeId.values));
|
example.AnyUniqueAliasesTypeId.values,
|
||||||
expect(example.AnyAmbiguousAliasesTypeId.values,
|
same(example.AnyUniqueAliasesTypeId.values),
|
||||||
same(example.AnyAmbiguousAliasesTypeId.values));
|
);
|
||||||
|
expect(
|
||||||
|
example.AnyAmbiguousAliasesTypeId.values,
|
||||||
|
same(example.AnyAmbiguousAliasesTypeId.values),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -917,11 +995,13 @@ class GeneratorTest {
|
|||||||
@reflectiveTest
|
@reflectiveTest
|
||||||
class ListOfEnumsTest {
|
class ListOfEnumsTest {
|
||||||
void test_listOfEnums() async {
|
void test_listOfEnums() async {
|
||||||
var mytable = example3.MyTableObjectBuilder(options: [
|
var mytable = example3.MyTableObjectBuilder(
|
||||||
|
options: [
|
||||||
example3.OptionsEnum.A,
|
example3.OptionsEnum.A,
|
||||||
example3.OptionsEnum.B,
|
example3.OptionsEnum.B,
|
||||||
example3.OptionsEnum.C
|
example3.OptionsEnum.C,
|
||||||
]);
|
],
|
||||||
|
);
|
||||||
var bytes = mytable.toBytes();
|
var bytes = mytable.toBytes();
|
||||||
var mytable_read = example3.MyTable(bytes);
|
var mytable_read = example3.MyTable(bytes);
|
||||||
expect(mytable_read.options![0].value, example3.OptionsEnum.A.value);
|
expect(mytable_read.options![0].value, example3.OptionsEnum.A.value);
|
||||||
@@ -934,7 +1014,8 @@ class ListOfEnumsTest {
|
|||||||
class BoolInStructTest {
|
class BoolInStructTest {
|
||||||
void test_boolInStruct() async {
|
void test_boolInStruct() async {
|
||||||
var mystruct = example4.FooObjectBuilder(
|
var mystruct = example4.FooObjectBuilder(
|
||||||
myFoo: example4.FooPropertiesObjectBuilder(a: true, b: false));
|
myFoo: example4.FooPropertiesObjectBuilder(a: true, b: false),
|
||||||
|
);
|
||||||
var bytes = mystruct.toBytes();
|
var bytes = mystruct.toBytes();
|
||||||
var mystruct_read = example4.Foo(bytes);
|
var mystruct_read = example4.Foo(bytes);
|
||||||
expect(mystruct_read.myFoo!.a, true);
|
expect(mystruct_read.myFoo!.a, true);
|
||||||
|
|||||||
@@ -62,8 +62,23 @@ void main() {
|
|||||||
{
|
{
|
||||||
var flx = Builder();
|
var flx = Builder();
|
||||||
flx.addString('hello 😱');
|
flx.addString('hello 😱');
|
||||||
expect(flx.finish(),
|
expect(flx.finish(), [
|
||||||
[10, 104, 101, 108, 108, 111, 32, 240, 159, 152, 177, 0, 11, 20, 1]);
|
10,
|
||||||
|
104,
|
||||||
|
101,
|
||||||
|
108,
|
||||||
|
108,
|
||||||
|
111,
|
||||||
|
32,
|
||||||
|
240,
|
||||||
|
159,
|
||||||
|
152,
|
||||||
|
177,
|
||||||
|
0,
|
||||||
|
11,
|
||||||
|
20,
|
||||||
|
1,
|
||||||
|
]);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -117,7 +132,7 @@ void main() {
|
|||||||
192,
|
192,
|
||||||
16,
|
16,
|
||||||
75,
|
75,
|
||||||
1
|
1,
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
@@ -177,7 +192,7 @@ void main() {
|
|||||||
7,
|
7,
|
||||||
3,
|
3,
|
||||||
60,
|
60,
|
||||||
1
|
1,
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
@@ -215,7 +230,7 @@ void main() {
|
|||||||
10,
|
10,
|
||||||
6,
|
6,
|
||||||
60,
|
60,
|
||||||
1
|
1,
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
@@ -300,9 +315,24 @@ void main() {
|
|||||||
104,
|
104,
|
||||||
45,
|
45,
|
||||||
43,
|
43,
|
||||||
1
|
1,
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
{
|
||||||
|
// Default buffer is 2048 bytes, add 2300 bytes of strings that force it
|
||||||
|
// to grow.
|
||||||
|
final s1 = 'A' * 1000;
|
||||||
|
final s2 = 'B' * 800;
|
||||||
|
final s3 = 'C' * 500;
|
||||||
|
|
||||||
|
var flx = Builder()
|
||||||
|
..startVector()
|
||||||
|
..addString(s1)
|
||||||
|
..addString(s2)
|
||||||
|
..addString(s3)
|
||||||
|
..end();
|
||||||
|
expect(flx.finish().length, 2323);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
test('build map', () {
|
test('build map', () {
|
||||||
@@ -322,8 +352,24 @@ void main() {
|
|||||||
..addKey('')
|
..addKey('')
|
||||||
..addInt(45)
|
..addInt(45)
|
||||||
..end();
|
..end();
|
||||||
expect(
|
expect(flx.finish(), [
|
||||||
flx.finish(), [97, 0, 0, 2, 2, 5, 2, 1, 2, 45, 12, 4, 4, 4, 36, 1]);
|
97,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
2,
|
||||||
|
2,
|
||||||
|
5,
|
||||||
|
2,
|
||||||
|
1,
|
||||||
|
2,
|
||||||
|
45,
|
||||||
|
12,
|
||||||
|
4,
|
||||||
|
4,
|
||||||
|
4,
|
||||||
|
36,
|
||||||
|
1,
|
||||||
|
]);
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
var flx = Builder()
|
var flx = Builder()
|
||||||
@@ -367,7 +413,7 @@ void main() {
|
|||||||
36,
|
36,
|
||||||
4,
|
4,
|
||||||
40,
|
40,
|
||||||
1
|
1,
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -381,21 +427,38 @@ void main() {
|
|||||||
|
|
||||||
test('build from object', () {
|
test('build from object', () {
|
||||||
expect(
|
expect(
|
||||||
Builder.buildFromObject(Uint8List.fromList([1, 2, 3]).buffer)
|
Builder.buildFromObject(
|
||||||
.asUint8List(),
|
Uint8List.fromList([1, 2, 3]).buffer,
|
||||||
[3, 1, 2, 3, 3, 100, 1]);
|
).asUint8List(),
|
||||||
|
[3, 1, 2, 3, 3, 100, 1],
|
||||||
|
);
|
||||||
expect(Builder.buildFromObject(null).asUint8List(), [0, 0, 1]);
|
expect(Builder.buildFromObject(null).asUint8List(), [0, 0, 1]);
|
||||||
expect(Builder.buildFromObject(true).asUint8List(), [1, 104, 1]);
|
expect(Builder.buildFromObject(true).asUint8List(), [1, 104, 1]);
|
||||||
expect(Builder.buildFromObject(false).asUint8List(), [0, 104, 1]);
|
expect(Builder.buildFromObject(false).asUint8List(), [0, 104, 1]);
|
||||||
expect(Builder.buildFromObject(25).asUint8List(), [25, 4, 1]);
|
expect(Builder.buildFromObject(25).asUint8List(), [25, 4, 1]);
|
||||||
expect(Builder.buildFromObject(-250).asUint8List(), [6, 255, 5, 2]);
|
expect(Builder.buildFromObject(-250).asUint8List(), [6, 255, 5, 2]);
|
||||||
|
expect(Builder.buildFromObject(-2.50).asUint8List(), [
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
32,
|
||||||
|
192,
|
||||||
|
14,
|
||||||
|
4,
|
||||||
|
]);
|
||||||
|
expect(Builder.buildFromObject('Maxim').asUint8List(), [
|
||||||
|
5,
|
||||||
|
77,
|
||||||
|
97,
|
||||||
|
120,
|
||||||
|
105,
|
||||||
|
109,
|
||||||
|
0,
|
||||||
|
6,
|
||||||
|
20,
|
||||||
|
1,
|
||||||
|
]);
|
||||||
expect(
|
expect(
|
||||||
Builder.buildFromObject(-2.50).asUint8List(), [0, 0, 32, 192, 14, 4]);
|
Builder.buildFromObject([1, 3.3, 'max', true, null, false]).asUint8List(),
|
||||||
expect(Builder.buildFromObject('Maxim').asUint8List(),
|
|
||||||
[5, 77, 97, 120, 105, 109, 0, 6, 20, 1]);
|
|
||||||
expect(
|
|
||||||
Builder.buildFromObject([1, 3.3, 'max', true, null, false])
|
|
||||||
.asUint8List(),
|
|
||||||
[
|
[
|
||||||
3,
|
3,
|
||||||
109,
|
109,
|
||||||
@@ -469,12 +532,13 @@ void main() {
|
|||||||
104,
|
104,
|
||||||
54,
|
54,
|
||||||
43,
|
43,
|
||||||
1
|
1,
|
||||||
]);
|
],
|
||||||
|
);
|
||||||
expect(
|
expect(
|
||||||
Builder.buildFromObject([
|
Builder.buildFromObject([
|
||||||
{'something': 12},
|
{'something': 12},
|
||||||
{'something': 45}
|
{'something': 45},
|
||||||
]).asUint8List(),
|
]).asUint8List(),
|
||||||
[
|
[
|
||||||
115,
|
115,
|
||||||
@@ -506,8 +570,9 @@ void main() {
|
|||||||
36,
|
36,
|
||||||
4,
|
4,
|
||||||
40,
|
40,
|
||||||
1
|
1,
|
||||||
]);
|
],
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('add double indirectly', () {
|
test('add double indirectly', () {
|
||||||
@@ -543,7 +608,7 @@ void main() {
|
|||||||
35,
|
35,
|
||||||
8,
|
8,
|
||||||
40,
|
40,
|
||||||
1
|
1,
|
||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -580,7 +645,7 @@ void main() {
|
|||||||
27,
|
27,
|
||||||
8,
|
8,
|
||||||
40,
|
40,
|
||||||
1
|
1,
|
||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -20,70 +20,76 @@ void main() {
|
|||||||
expect(Reference.fromBuffer(b([1, 4, 5, 2])).intValue, 1025);
|
expect(Reference.fromBuffer(b([1, 4, 5, 2])).intValue, 1025);
|
||||||
expect(Reference.fromBuffer(b([255, 251, 5, 2])).intValue, -1025);
|
expect(Reference.fromBuffer(b([255, 251, 5, 2])).intValue, -1025);
|
||||||
expect(Reference.fromBuffer(b([1, 4, 9, 2])).intValue, 1025);
|
expect(Reference.fromBuffer(b([1, 4, 9, 2])).intValue, 1025);
|
||||||
expect(Reference.fromBuffer(b([255, 255, 255, 127, 6, 4])).intValue,
|
expect(
|
||||||
2147483647);
|
Reference.fromBuffer(b([255, 255, 255, 127, 6, 4])).intValue,
|
||||||
|
2147483647,
|
||||||
|
);
|
||||||
expect(Reference.fromBuffer(b([0, 0, 0, 128, 6, 4])).intValue, -2147483648);
|
expect(Reference.fromBuffer(b([0, 0, 0, 128, 6, 4])).intValue, -2147483648);
|
||||||
expect(
|
expect(
|
||||||
Reference.fromBuffer(b([255, 255, 255, 255, 0, 0, 0, 0, 7, 8]))
|
Reference.fromBuffer(b([255, 255, 255, 255, 0, 0, 0, 0, 7, 8])).intValue,
|
||||||
.intValue,
|
4294967295,
|
||||||
4294967295);
|
);
|
||||||
expect(
|
expect(
|
||||||
Reference.fromBuffer(b([255, 255, 255, 255, 255, 255, 255, 127, 7, 8]))
|
Reference.fromBuffer(
|
||||||
.intValue,
|
b([255, 255, 255, 255, 255, 255, 255, 127, 7, 8]),
|
||||||
9223372036854775807);
|
).intValue,
|
||||||
expect(Reference.fromBuffer(b([0, 0, 0, 0, 0, 0, 0, 128, 7, 8])).intValue,
|
9223372036854775807,
|
||||||
-9223372036854775808);
|
);
|
||||||
|
expect(
|
||||||
|
Reference.fromBuffer(b([0, 0, 0, 0, 0, 0, 0, 128, 7, 8])).intValue,
|
||||||
|
-9223372036854775808,
|
||||||
|
);
|
||||||
// Dart does not really support UInt64
|
// Dart does not really support UInt64
|
||||||
// expect(FlxValue.fromBuffer(b([255, 255, 255, 255, 255, 255, 255, 255, 11, 8])).intValue, 18446744073709551615);
|
// expect(FlxValue.fromBuffer(b([255, 255, 255, 255, 255, 255, 255, 255, 11, 8])).intValue, 18446744073709551615);
|
||||||
});
|
});
|
||||||
test('double value', () {
|
test('double value', () {
|
||||||
expect(Reference.fromBuffer(b([0, 0, 128, 63, 14, 4])).doubleValue, 1.0);
|
expect(Reference.fromBuffer(b([0, 0, 128, 63, 14, 4])).doubleValue, 1.0);
|
||||||
expect(Reference.fromBuffer(b([0, 0, 144, 64, 14, 4])).doubleValue, 4.5);
|
expect(Reference.fromBuffer(b([0, 0, 144, 64, 14, 4])).doubleValue, 4.5);
|
||||||
expect(Reference.fromBuffer(b([205, 204, 204, 61, 14, 4])).doubleValue,
|
|
||||||
closeTo(.1, .001));
|
|
||||||
expect(
|
expect(
|
||||||
Reference.fromBuffer(b([154, 153, 153, 153, 153, 153, 185, 63, 15, 8]))
|
Reference.fromBuffer(b([205, 204, 204, 61, 14, 4])).doubleValue,
|
||||||
.doubleValue,
|
closeTo(.1, .001),
|
||||||
.1);
|
);
|
||||||
|
expect(
|
||||||
|
Reference.fromBuffer(
|
||||||
|
b([154, 153, 153, 153, 153, 153, 185, 63, 15, 8]),
|
||||||
|
).doubleValue,
|
||||||
|
.1,
|
||||||
|
);
|
||||||
});
|
});
|
||||||
test('num value', () {
|
test('num value', () {
|
||||||
expect(Reference.fromBuffer(b([0, 0, 144, 64, 14, 4])).numValue, 4.5);
|
expect(Reference.fromBuffer(b([0, 0, 144, 64, 14, 4])).numValue, 4.5);
|
||||||
expect(Reference.fromBuffer(b([205, 204, 204, 61, 14, 4])).numValue,
|
|
||||||
closeTo(.1, .001));
|
|
||||||
expect(
|
expect(
|
||||||
Reference.fromBuffer(b([154, 153, 153, 153, 153, 153, 185, 63, 15, 8]))
|
Reference.fromBuffer(b([205, 204, 204, 61, 14, 4])).numValue,
|
||||||
.numValue,
|
closeTo(.1, .001),
|
||||||
.1);
|
);
|
||||||
|
expect(
|
||||||
|
Reference.fromBuffer(
|
||||||
|
b([154, 153, 153, 153, 153, 153, 185, 63, 15, 8]),
|
||||||
|
).numValue,
|
||||||
|
.1,
|
||||||
|
);
|
||||||
expect(Reference.fromBuffer(b([255, 251, 5, 2])).numValue, -1025);
|
expect(Reference.fromBuffer(b([255, 251, 5, 2])).numValue, -1025);
|
||||||
});
|
});
|
||||||
test('string value', () {
|
test('string value', () {
|
||||||
expect(
|
expect(
|
||||||
Reference.fromBuffer(b([5, 77, 97, 120, 105, 109, 0, 6, 20, 1]))
|
Reference.fromBuffer(
|
||||||
.stringValue,
|
b([5, 77, 97, 120, 105, 109, 0, 6, 20, 1]),
|
||||||
'Maxim');
|
).stringValue,
|
||||||
|
'Maxim',
|
||||||
|
);
|
||||||
expect(
|
expect(
|
||||||
Reference.fromBuffer(b([
|
Reference.fromBuffer(
|
||||||
10,
|
b([10, 104, 101, 108, 108, 111, 32, 240, 159, 152, 177, 0, 11, 20, 1]),
|
||||||
104,
|
).stringValue,
|
||||||
101,
|
'hello 😱',
|
||||||
108,
|
);
|
||||||
108,
|
|
||||||
111,
|
|
||||||
32,
|
|
||||||
240,
|
|
||||||
159,
|
|
||||||
152,
|
|
||||||
177,
|
|
||||||
0,
|
|
||||||
11,
|
|
||||||
20,
|
|
||||||
1
|
|
||||||
])).stringValue,
|
|
||||||
'hello 😱');
|
|
||||||
});
|
});
|
||||||
test('blob value', () {
|
test('blob value', () {
|
||||||
expect(
|
expect(Reference.fromBuffer(b([3, 1, 2, 3, 3, 100, 1])).blobValue, [
|
||||||
Reference.fromBuffer(b([3, 1, 2, 3, 3, 100, 1])).blobValue, [1, 2, 3]);
|
1,
|
||||||
|
2,
|
||||||
|
3,
|
||||||
|
]);
|
||||||
});
|
});
|
||||||
test('bool vector', () {
|
test('bool vector', () {
|
||||||
var flx = Reference.fromBuffer(b([3, 1, 0, 1, 3, 144, 1]));
|
var flx = Reference.fromBuffer(b([3, 1, 0, 1, 3, 144, 1]));
|
||||||
@@ -95,9 +101,12 @@ void main() {
|
|||||||
testNumbers([3, 1, 2, 3, 3, 44, 1], [1, 2, 3]);
|
testNumbers([3, 1, 2, 3, 3, 44, 1], [1, 2, 3]);
|
||||||
testNumbers([3, 255, 2, 3, 3, 44, 1], [-1, 2, 3]);
|
testNumbers([3, 255, 2, 3, 3, 44, 1], [-1, 2, 3]);
|
||||||
testNumbers([3, 0, 1, 0, 43, 2, 3, 0, 6, 45, 1], [1, 555, 3]);
|
testNumbers([3, 0, 1, 0, 43, 2, 3, 0, 6, 45, 1], [1, 555, 3]);
|
||||||
testNumbers([3, 0, 0, 0, 1, 0, 0, 0, 204, 216, 0, 0, 3, 0, 0, 0, 12, 46, 1],
|
testNumbers(
|
||||||
[1, 55500, 3]);
|
[3, 0, 0, 0, 1, 0, 0, 0, 204, 216, 0, 0, 3, 0, 0, 0, 12, 46, 1],
|
||||||
testNumbers([
|
[1, 55500, 3],
|
||||||
|
);
|
||||||
|
testNumbers(
|
||||||
|
[
|
||||||
3,
|
3,
|
||||||
0,
|
0,
|
||||||
0,
|
0,
|
||||||
@@ -132,16 +141,16 @@ void main() {
|
|||||||
0,
|
0,
|
||||||
24,
|
24,
|
||||||
47,
|
47,
|
||||||
1
|
|
||||||
], [
|
|
||||||
1,
|
1,
|
||||||
55555555500,
|
],
|
||||||
3
|
[1, 55555555500, 3],
|
||||||
]);
|
);
|
||||||
testNumbers(
|
testNumbers(
|
||||||
[3, 0, 0, 0, 0, 0, 192, 63, 0, 0, 32, 64, 0, 0, 96, 64, 12, 54, 1],
|
[3, 0, 0, 0, 0, 0, 192, 63, 0, 0, 32, 64, 0, 0, 96, 64, 12, 54, 1],
|
||||||
[1.5, 2.5, 3.5]);
|
[1.5, 2.5, 3.5],
|
||||||
testNumbers([
|
);
|
||||||
|
testNumbers(
|
||||||
|
[
|
||||||
3,
|
3,
|
||||||
0,
|
0,
|
||||||
0,
|
0,
|
||||||
@@ -176,18 +185,17 @@ void main() {
|
|||||||
64,
|
64,
|
||||||
24,
|
24,
|
||||||
55,
|
55,
|
||||||
1
|
1,
|
||||||
], [
|
],
|
||||||
1.1,
|
[1.1, 2.2, 3.3],
|
||||||
2.2,
|
);
|
||||||
3.3
|
|
||||||
]);
|
|
||||||
});
|
});
|
||||||
test('number vector, fixed type', () {
|
test('number vector, fixed type', () {
|
||||||
testNumbers([1, 2, 2, 64, 1], [1, 2]);
|
testNumbers([1, 2, 2, 64, 1], [1, 2]);
|
||||||
testNumbers([255, 255, 0, 1, 4, 65, 1], [-1, 256]);
|
testNumbers([255, 255, 0, 1, 4, 65, 1], [-1, 256]);
|
||||||
testNumbers([211, 255, 255, 255, 0, 232, 3, 0, 8, 66, 1], [-45, 256000]);
|
testNumbers([211, 255, 255, 255, 0, 232, 3, 0, 8, 66, 1], [-45, 256000]);
|
||||||
testNumbers([
|
testNumbers(
|
||||||
|
[
|
||||||
211,
|
211,
|
||||||
255,
|
255,
|
||||||
255,
|
255,
|
||||||
@@ -206,18 +214,18 @@ void main() {
|
|||||||
127,
|
127,
|
||||||
16,
|
16,
|
||||||
67,
|
67,
|
||||||
1
|
1,
|
||||||
], [
|
],
|
||||||
-45,
|
[-45, 9223372036854775807],
|
||||||
9223372036854775807
|
);
|
||||||
]);
|
|
||||||
|
|
||||||
testNumbers([1, 2, 2, 68, 1], [1, 2]);
|
testNumbers([1, 2, 2, 68, 1], [1, 2]);
|
||||||
testNumbers([1, 0, 0, 1, 4, 69, 1], [1, 256]);
|
testNumbers([1, 0, 0, 1, 4, 69, 1], [1, 256]);
|
||||||
testNumbers([45, 0, 0, 0, 0, 232, 3, 0, 8, 70, 1], [45, 256000]);
|
testNumbers([45, 0, 0, 0, 0, 232, 3, 0, 8, 70, 1], [45, 256000]);
|
||||||
|
|
||||||
testNumbers([205, 204, 140, 63, 0, 0, 0, 192, 8, 74, 1], [1.1, -2]);
|
testNumbers([205, 204, 140, 63, 0, 0, 0, 192, 8, 74, 1], [1.1, -2]);
|
||||||
testNumbers([
|
testNumbers(
|
||||||
|
[
|
||||||
154,
|
154,
|
||||||
153,
|
153,
|
||||||
153,
|
153,
|
||||||
@@ -236,16 +244,18 @@ void main() {
|
|||||||
192,
|
192,
|
||||||
16,
|
16,
|
||||||
75,
|
75,
|
||||||
1
|
1,
|
||||||
], [
|
],
|
||||||
1.1,
|
[1.1, -256],
|
||||||
-256
|
);
|
||||||
]);
|
|
||||||
|
|
||||||
testNumbers([211, 255, 255, 255, 0, 232, 3, 0, 4, 0, 0, 0, 12, 78, 1],
|
testNumbers(
|
||||||
[-45, 256000, 4]);
|
[211, 255, 255, 255, 0, 232, 3, 0, 4, 0, 0, 0, 12, 78, 1],
|
||||||
|
[-45, 256000, 4],
|
||||||
|
);
|
||||||
|
|
||||||
testNumbers([
|
testNumbers(
|
||||||
|
[
|
||||||
211,
|
211,
|
||||||
255,
|
255,
|
||||||
255,
|
255,
|
||||||
@@ -280,15 +290,13 @@ void main() {
|
|||||||
0,
|
0,
|
||||||
32,
|
32,
|
||||||
91,
|
91,
|
||||||
1
|
1,
|
||||||
], [
|
],
|
||||||
-45,
|
[-45, 9223372036854775807, 4, 9],
|
||||||
9223372036854775807,
|
);
|
||||||
4,
|
|
||||||
9
|
|
||||||
]);
|
|
||||||
|
|
||||||
testNumbers([
|
testNumbers(
|
||||||
|
[
|
||||||
45,
|
45,
|
||||||
0,
|
0,
|
||||||
0,
|
0,
|
||||||
@@ -323,15 +331,13 @@ void main() {
|
|||||||
0,
|
0,
|
||||||
32,
|
32,
|
||||||
95,
|
95,
|
||||||
1
|
1,
|
||||||
], [
|
],
|
||||||
45,
|
[45, 9223372036854775807, 4, 9],
|
||||||
9223372036854775807,
|
);
|
||||||
4,
|
|
||||||
9
|
|
||||||
]);
|
|
||||||
|
|
||||||
testNumbers([
|
testNumbers(
|
||||||
|
[
|
||||||
154,
|
154,
|
||||||
153,
|
153,
|
||||||
153,
|
153,
|
||||||
@@ -358,14 +364,13 @@ void main() {
|
|||||||
64,
|
64,
|
||||||
24,
|
24,
|
||||||
87,
|
87,
|
||||||
1
|
1,
|
||||||
], [
|
],
|
||||||
1.1,
|
[1.1, 256, 4],
|
||||||
256,
|
);
|
||||||
4
|
|
||||||
]);
|
|
||||||
|
|
||||||
testNumbers([
|
testNumbers(
|
||||||
|
[
|
||||||
154,
|
154,
|
||||||
153,
|
153,
|
||||||
153,
|
153,
|
||||||
@@ -400,16 +405,14 @@ void main() {
|
|||||||
64,
|
64,
|
||||||
32,
|
32,
|
||||||
99,
|
99,
|
||||||
1
|
1,
|
||||||
], [
|
],
|
||||||
1.1,
|
[1.1, 256, 4, 9],
|
||||||
256,
|
);
|
||||||
4,
|
|
||||||
9
|
|
||||||
]);
|
|
||||||
});
|
});
|
||||||
test('string vector', () {
|
test('string vector', () {
|
||||||
testStrings([
|
testStrings(
|
||||||
|
[
|
||||||
3,
|
3,
|
||||||
102,
|
102,
|
||||||
111,
|
111,
|
||||||
@@ -431,13 +434,12 @@ void main() {
|
|||||||
7,
|
7,
|
||||||
3,
|
3,
|
||||||
60,
|
60,
|
||||||
1
|
1,
|
||||||
], [
|
],
|
||||||
'foo',
|
['foo', 'bar', 'baz'],
|
||||||
'bar',
|
);
|
||||||
'baz'
|
testStrings(
|
||||||
]);
|
[
|
||||||
testStrings([
|
|
||||||
3,
|
3,
|
||||||
102,
|
102,
|
||||||
111,
|
111,
|
||||||
@@ -462,18 +464,14 @@ void main() {
|
|||||||
10,
|
10,
|
||||||
6,
|
6,
|
||||||
60,
|
60,
|
||||||
1
|
1,
|
||||||
], [
|
],
|
||||||
'foo',
|
['foo', 'bar', 'baz', 'foo', 'bar', 'baz'],
|
||||||
'bar',
|
);
|
||||||
'baz',
|
|
||||||
'foo',
|
|
||||||
'bar',
|
|
||||||
'baz'
|
|
||||||
]);
|
|
||||||
});
|
});
|
||||||
test('mixed vector', () {
|
test('mixed vector', () {
|
||||||
var flx = Reference.fromBuffer(b([
|
var flx = Reference.fromBuffer(
|
||||||
|
b([
|
||||||
3,
|
3,
|
||||||
102,
|
102,
|
||||||
111,
|
111,
|
||||||
@@ -537,8 +535,9 @@ void main() {
|
|||||||
104,
|
104,
|
||||||
45,
|
45,
|
||||||
43,
|
43,
|
||||||
1
|
1,
|
||||||
]));
|
]),
|
||||||
|
);
|
||||||
expect(flx.length, 5);
|
expect(flx.length, 5);
|
||||||
expect(flx[0].stringValue, 'foo');
|
expect(flx[0].stringValue, 'foo');
|
||||||
expect(flx[1].numValue, 1);
|
expect(flx[1].numValue, 1);
|
||||||
@@ -554,7 +553,8 @@ void main() {
|
|||||||
});
|
});
|
||||||
test('two value map', () {
|
test('two value map', () {
|
||||||
var flx = Reference.fromBuffer(
|
var flx = Reference.fromBuffer(
|
||||||
b([0, 97, 0, 2, 4, 4, 2, 1, 2, 45, 12, 4, 4, 4, 36, 1]));
|
b([0, 97, 0, 2, 4, 4, 2, 1, 2, 45, 12, 4, 4, 4, 36, 1]),
|
||||||
|
);
|
||||||
expect(flx.length, 2);
|
expect(flx.length, 2);
|
||||||
expect(flx['a'].numValue, 12);
|
expect(flx['a'].numValue, 12);
|
||||||
expect(flx[''].numValue, 45);
|
expect(flx[''].numValue, 45);
|
||||||
@@ -579,54 +579,89 @@ void main() {
|
|||||||
|
|
||||||
expect(
|
expect(
|
||||||
() => flx['address']['country'].stringValue,
|
() => flx['address']['country'].stringValue,
|
||||||
throwsA(predicate((dynamic e) =>
|
throwsA(
|
||||||
|
predicate(
|
||||||
|
(dynamic e) =>
|
||||||
e is ArgumentError &&
|
e is ArgumentError &&
|
||||||
e.message ==
|
e.message ==
|
||||||
'Key: [country] is not applicable on: //address of: ValueType.Map')));
|
'Key: [country] is not applicable on: //address of: ValueType.Map',
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
expect(
|
expect(
|
||||||
() => flx['address']['countryCode'][0],
|
() => flx['address']['countryCode'][0],
|
||||||
throwsA(predicate((dynamic e) =>
|
throwsA(
|
||||||
|
predicate(
|
||||||
|
(dynamic e) =>
|
||||||
e is ArgumentError &&
|
e is ArgumentError &&
|
||||||
e.message ==
|
e.message ==
|
||||||
'Key: [0] is not applicable on: //address/countryCode of: ValueType.String')));
|
'Key: [0] is not applicable on: //address/countryCode of: ValueType.String',
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
expect(
|
expect(
|
||||||
() => flx[1],
|
() => flx[1],
|
||||||
throwsA(predicate((dynamic e) =>
|
throwsA(
|
||||||
|
predicate(
|
||||||
|
(dynamic e) =>
|
||||||
e is ArgumentError &&
|
e is ArgumentError &&
|
||||||
e.message ==
|
e.message == 'Key: [1] is not applicable on: / of: ValueType.Map',
|
||||||
'Key: [1] is not applicable on: / of: ValueType.Map')));
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
expect(
|
expect(
|
||||||
() => flx['flags'][4],
|
() => flx['flags'][4],
|
||||||
throwsA(predicate((dynamic e) =>
|
throwsA(
|
||||||
|
predicate(
|
||||||
|
(dynamic e) =>
|
||||||
e is ArgumentError &&
|
e is ArgumentError &&
|
||||||
e.message ==
|
e.message ==
|
||||||
'Key: [4] is not applicable on: //flags of: ValueType.VectorBool length: 4')));
|
'Key: [4] is not applicable on: //flags of: ValueType.VectorBool length: 4',
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
expect(
|
expect(
|
||||||
() => flx['flags'][-1],
|
() => flx['flags'][-1],
|
||||||
throwsA(predicate((dynamic e) =>
|
throwsA(
|
||||||
|
predicate(
|
||||||
|
(dynamic e) =>
|
||||||
e is ArgumentError &&
|
e is ArgumentError &&
|
||||||
e.message ==
|
e.message ==
|
||||||
'Key: [-1] is not applicable on: //flags of: ValueType.VectorBool length: 4')));
|
'Key: [-1] is not applicable on: //flags of: ValueType.VectorBool length: 4',
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
});
|
});
|
||||||
test('complex map to json', () {
|
test('complex map to json', () {
|
||||||
var flx = complexMap();
|
var flx = complexMap();
|
||||||
expect(flx.json,
|
expect(
|
||||||
'{"address":{"city":"Bla","countryCode":"XX","zip":"12345"},"age":35,"flags":[true,false,true,true],"name":"Maxim","weight":72.5}');
|
flx.json,
|
||||||
|
'{"address":{"city":"Bla","countryCode":"XX","zip":"12345"},"age":35,"flags":[true,false,true,true],"name":"Maxim","weight":72.5}',
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('complex map iterators', () {
|
test('complex map iterators', () {
|
||||||
var flx = complexMap();
|
var flx = complexMap();
|
||||||
expect(flx.mapKeyIterable.map((e) => e).toList(),
|
expect(flx.mapKeyIterable.map((e) => e).toList(), [
|
||||||
['address', 'age', 'flags', 'name', 'weight']);
|
'address',
|
||||||
|
'age',
|
||||||
|
'flags',
|
||||||
|
'name',
|
||||||
|
'weight',
|
||||||
|
]);
|
||||||
expect(flx.mapValueIterable.map((e) => e.json).toList(), [
|
expect(flx.mapValueIterable.map((e) => e.json).toList(), [
|
||||||
flx['address'].json,
|
flx['address'].json,
|
||||||
flx['age'].json,
|
flx['age'].json,
|
||||||
flx['flags'].json,
|
flx['flags'].json,
|
||||||
flx['name'].json,
|
flx['name'].json,
|
||||||
flx['weight'].json
|
flx['weight'].json,
|
||||||
|
]);
|
||||||
|
expect(flx['flags'].vectorIterable.map((e) => e.boolValue).toList(), [
|
||||||
|
true,
|
||||||
|
false,
|
||||||
|
true,
|
||||||
|
true,
|
||||||
]);
|
]);
|
||||||
expect(flx['flags'].vectorIterable.map((e) => e.boolValue).toList(),
|
|
||||||
[true, false, true, true]);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
test('bug where offest were stored as int instead of uint', () {
|
test('bug where offest were stored as int instead of uint', () {
|
||||||
@@ -790,11 +825,13 @@ void main() {
|
|||||||
4,
|
4,
|
||||||
16,
|
16,
|
||||||
36,
|
36,
|
||||||
1
|
1,
|
||||||
];
|
];
|
||||||
var flx = Reference.fromBuffer(b(data));
|
var flx = Reference.fromBuffer(b(data));
|
||||||
expect(flx.json,
|
expect(
|
||||||
'{"channels_in":64,"dilation_height_factor":1,"dilation_width_factor":1,"fused_activation_function":1,"pad_values":1,"padding":0,"stride_height":1,"stride_width":1}');
|
flx.json,
|
||||||
|
'{"channels_in":64,"dilation_height_factor":1,"dilation_width_factor":1,"fused_activation_function":1,"pad_values":1,"padding":0,"stride_height":1,"stride_width":1}',
|
||||||
|
);
|
||||||
const object = {
|
const object = {
|
||||||
"channels_in": 64,
|
"channels_in": 64,
|
||||||
"dilation_height_factor": 1,
|
"dilation_height_factor": 1,
|
||||||
@@ -803,13 +840,15 @@ void main() {
|
|||||||
"pad_values": 1,
|
"pad_values": 1,
|
||||||
"padding": 0,
|
"padding": 0,
|
||||||
"stride_height": 1,
|
"stride_height": 1,
|
||||||
"stride_width": 1
|
"stride_width": 1,
|
||||||
};
|
};
|
||||||
var data1 = Builder.buildFromObject(object).asUint8List();
|
var data1 = Builder.buildFromObject(object).asUint8List();
|
||||||
expect(data1.length, data.length);
|
expect(data1.length, data.length);
|
||||||
var flx1 = Reference.fromBuffer(b(data1));
|
var flx1 = Reference.fromBuffer(b(data1));
|
||||||
expect(flx1.json,
|
expect(
|
||||||
'{"channels_in":64,"dilation_height_factor":1,"dilation_width_factor":1,"fused_activation_function":1,"pad_values":1,"padding":0,"stride_height":1,"stride_width":1}');
|
flx1.json,
|
||||||
|
'{"channels_in":64,"dilation_height_factor":1,"dilation_width_factor":1,"fused_activation_function":1,"pad_values":1,"padding":0,"stride_height":1,"stride_width":1}',
|
||||||
|
);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -846,7 +885,8 @@ Reference complexMap() {
|
|||||||
// "countryCode": "XX",
|
// "countryCode": "XX",
|
||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
return Reference.fromBuffer(b([
|
return Reference.fromBuffer(
|
||||||
|
b([
|
||||||
97,
|
97,
|
||||||
100,
|
100,
|
||||||
100,
|
100,
|
||||||
@@ -986,6 +1026,7 @@ Reference complexMap() {
|
|||||||
14,
|
14,
|
||||||
25,
|
25,
|
||||||
38,
|
38,
|
||||||
1
|
1,
|
||||||
]));
|
]),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -48,116 +48,210 @@ void main() {
|
|||||||
expect(ValueTypeUtils.isFixedTypedVector(ValueType.VectorInt), isFalse);
|
expect(ValueTypeUtils.isFixedTypedVector(ValueType.VectorInt), isFalse);
|
||||||
});
|
});
|
||||||
test('to typed vector', () {
|
test('to typed vector', () {
|
||||||
expect(ValueTypeUtils.toTypedVector(ValueType.Int, 0),
|
expect(
|
||||||
equals(ValueType.VectorInt));
|
ValueTypeUtils.toTypedVector(ValueType.Int, 0),
|
||||||
expect(ValueTypeUtils.toTypedVector(ValueType.UInt, 0),
|
equals(ValueType.VectorInt),
|
||||||
equals(ValueType.VectorUInt));
|
);
|
||||||
expect(ValueTypeUtils.toTypedVector(ValueType.Bool, 0),
|
expect(
|
||||||
equals(ValueType.VectorBool));
|
ValueTypeUtils.toTypedVector(ValueType.UInt, 0),
|
||||||
expect(ValueTypeUtils.toTypedVector(ValueType.Float, 0),
|
equals(ValueType.VectorUInt),
|
||||||
equals(ValueType.VectorFloat));
|
);
|
||||||
expect(ValueTypeUtils.toTypedVector(ValueType.Key, 0),
|
expect(
|
||||||
equals(ValueType.VectorKey));
|
ValueTypeUtils.toTypedVector(ValueType.Bool, 0),
|
||||||
expect(ValueTypeUtils.toTypedVector(ValueType.String, 0),
|
equals(ValueType.VectorBool),
|
||||||
equals(ValueType.VectorString));
|
);
|
||||||
|
expect(
|
||||||
|
ValueTypeUtils.toTypedVector(ValueType.Float, 0),
|
||||||
|
equals(ValueType.VectorFloat),
|
||||||
|
);
|
||||||
|
expect(
|
||||||
|
ValueTypeUtils.toTypedVector(ValueType.Key, 0),
|
||||||
|
equals(ValueType.VectorKey),
|
||||||
|
);
|
||||||
|
expect(
|
||||||
|
ValueTypeUtils.toTypedVector(ValueType.String, 0),
|
||||||
|
equals(ValueType.VectorString),
|
||||||
|
);
|
||||||
|
|
||||||
expect(ValueTypeUtils.toTypedVector(ValueType.Int, 2),
|
expect(
|
||||||
equals(ValueType.VectorInt2));
|
ValueTypeUtils.toTypedVector(ValueType.Int, 2),
|
||||||
expect(ValueTypeUtils.toTypedVector(ValueType.UInt, 2),
|
equals(ValueType.VectorInt2),
|
||||||
equals(ValueType.VectorUInt2));
|
);
|
||||||
expect(ValueTypeUtils.toTypedVector(ValueType.Float, 2),
|
expect(
|
||||||
equals(ValueType.VectorFloat2));
|
ValueTypeUtils.toTypedVector(ValueType.UInt, 2),
|
||||||
|
equals(ValueType.VectorUInt2),
|
||||||
|
);
|
||||||
|
expect(
|
||||||
|
ValueTypeUtils.toTypedVector(ValueType.Float, 2),
|
||||||
|
equals(ValueType.VectorFloat2),
|
||||||
|
);
|
||||||
|
|
||||||
expect(ValueTypeUtils.toTypedVector(ValueType.Int, 3),
|
expect(
|
||||||
equals(ValueType.VectorInt3));
|
ValueTypeUtils.toTypedVector(ValueType.Int, 3),
|
||||||
expect(ValueTypeUtils.toTypedVector(ValueType.UInt, 3),
|
equals(ValueType.VectorInt3),
|
||||||
equals(ValueType.VectorUInt3));
|
);
|
||||||
expect(ValueTypeUtils.toTypedVector(ValueType.Float, 3),
|
expect(
|
||||||
equals(ValueType.VectorFloat3));
|
ValueTypeUtils.toTypedVector(ValueType.UInt, 3),
|
||||||
|
equals(ValueType.VectorUInt3),
|
||||||
|
);
|
||||||
|
expect(
|
||||||
|
ValueTypeUtils.toTypedVector(ValueType.Float, 3),
|
||||||
|
equals(ValueType.VectorFloat3),
|
||||||
|
);
|
||||||
|
|
||||||
expect(ValueTypeUtils.toTypedVector(ValueType.Int, 4),
|
expect(
|
||||||
equals(ValueType.VectorInt4));
|
ValueTypeUtils.toTypedVector(ValueType.Int, 4),
|
||||||
expect(ValueTypeUtils.toTypedVector(ValueType.UInt, 4),
|
equals(ValueType.VectorInt4),
|
||||||
equals(ValueType.VectorUInt4));
|
);
|
||||||
expect(ValueTypeUtils.toTypedVector(ValueType.Float, 4),
|
expect(
|
||||||
equals(ValueType.VectorFloat4));
|
ValueTypeUtils.toTypedVector(ValueType.UInt, 4),
|
||||||
|
equals(ValueType.VectorUInt4),
|
||||||
|
);
|
||||||
|
expect(
|
||||||
|
ValueTypeUtils.toTypedVector(ValueType.Float, 4),
|
||||||
|
equals(ValueType.VectorFloat4),
|
||||||
|
);
|
||||||
});
|
});
|
||||||
test('typed vector element type', () {
|
test('typed vector element type', () {
|
||||||
expect(ValueTypeUtils.typedVectorElementType(ValueType.VectorInt),
|
expect(
|
||||||
equals(ValueType.Int));
|
ValueTypeUtils.typedVectorElementType(ValueType.VectorInt),
|
||||||
expect(ValueTypeUtils.typedVectorElementType(ValueType.VectorUInt),
|
equals(ValueType.Int),
|
||||||
equals(ValueType.UInt));
|
);
|
||||||
expect(ValueTypeUtils.typedVectorElementType(ValueType.VectorFloat),
|
expect(
|
||||||
equals(ValueType.Float));
|
ValueTypeUtils.typedVectorElementType(ValueType.VectorUInt),
|
||||||
expect(ValueTypeUtils.typedVectorElementType(ValueType.VectorString),
|
equals(ValueType.UInt),
|
||||||
equals(ValueType.String));
|
);
|
||||||
expect(ValueTypeUtils.typedVectorElementType(ValueType.VectorKey),
|
expect(
|
||||||
equals(ValueType.Key));
|
ValueTypeUtils.typedVectorElementType(ValueType.VectorFloat),
|
||||||
expect(ValueTypeUtils.typedVectorElementType(ValueType.VectorBool),
|
equals(ValueType.Float),
|
||||||
equals(ValueType.Bool));
|
);
|
||||||
|
expect(
|
||||||
|
ValueTypeUtils.typedVectorElementType(ValueType.VectorString),
|
||||||
|
equals(ValueType.String),
|
||||||
|
);
|
||||||
|
expect(
|
||||||
|
ValueTypeUtils.typedVectorElementType(ValueType.VectorKey),
|
||||||
|
equals(ValueType.Key),
|
||||||
|
);
|
||||||
|
expect(
|
||||||
|
ValueTypeUtils.typedVectorElementType(ValueType.VectorBool),
|
||||||
|
equals(ValueType.Bool),
|
||||||
|
);
|
||||||
});
|
});
|
||||||
test('fixed typed vector element type', () {
|
test('fixed typed vector element type', () {
|
||||||
expect(ValueTypeUtils.fixedTypedVectorElementType(ValueType.VectorInt2),
|
expect(
|
||||||
equals(ValueType.Int));
|
ValueTypeUtils.fixedTypedVectorElementType(ValueType.VectorInt2),
|
||||||
expect(ValueTypeUtils.fixedTypedVectorElementType(ValueType.VectorInt3),
|
equals(ValueType.Int),
|
||||||
equals(ValueType.Int));
|
);
|
||||||
expect(ValueTypeUtils.fixedTypedVectorElementType(ValueType.VectorInt4),
|
expect(
|
||||||
equals(ValueType.Int));
|
ValueTypeUtils.fixedTypedVectorElementType(ValueType.VectorInt3),
|
||||||
|
equals(ValueType.Int),
|
||||||
|
);
|
||||||
|
expect(
|
||||||
|
ValueTypeUtils.fixedTypedVectorElementType(ValueType.VectorInt4),
|
||||||
|
equals(ValueType.Int),
|
||||||
|
);
|
||||||
|
|
||||||
expect(ValueTypeUtils.fixedTypedVectorElementType(ValueType.VectorUInt2),
|
expect(
|
||||||
equals(ValueType.UInt));
|
ValueTypeUtils.fixedTypedVectorElementType(ValueType.VectorUInt2),
|
||||||
expect(ValueTypeUtils.fixedTypedVectorElementType(ValueType.VectorUInt3),
|
equals(ValueType.UInt),
|
||||||
equals(ValueType.UInt));
|
);
|
||||||
expect(ValueTypeUtils.fixedTypedVectorElementType(ValueType.VectorUInt4),
|
expect(
|
||||||
equals(ValueType.UInt));
|
ValueTypeUtils.fixedTypedVectorElementType(ValueType.VectorUInt3),
|
||||||
|
equals(ValueType.UInt),
|
||||||
|
);
|
||||||
|
expect(
|
||||||
|
ValueTypeUtils.fixedTypedVectorElementType(ValueType.VectorUInt4),
|
||||||
|
equals(ValueType.UInt),
|
||||||
|
);
|
||||||
|
|
||||||
expect(ValueTypeUtils.fixedTypedVectorElementType(ValueType.VectorFloat2),
|
expect(
|
||||||
equals(ValueType.Float));
|
ValueTypeUtils.fixedTypedVectorElementType(ValueType.VectorFloat2),
|
||||||
expect(ValueTypeUtils.fixedTypedVectorElementType(ValueType.VectorFloat3),
|
equals(ValueType.Float),
|
||||||
equals(ValueType.Float));
|
);
|
||||||
expect(ValueTypeUtils.fixedTypedVectorElementType(ValueType.VectorFloat4),
|
expect(
|
||||||
equals(ValueType.Float));
|
ValueTypeUtils.fixedTypedVectorElementType(ValueType.VectorFloat3),
|
||||||
|
equals(ValueType.Float),
|
||||||
|
);
|
||||||
|
expect(
|
||||||
|
ValueTypeUtils.fixedTypedVectorElementType(ValueType.VectorFloat4),
|
||||||
|
equals(ValueType.Float),
|
||||||
|
);
|
||||||
});
|
});
|
||||||
test('fixed typed vector element size', () {
|
test('fixed typed vector element size', () {
|
||||||
expect(ValueTypeUtils.fixedTypedVectorElementSize(ValueType.VectorInt2),
|
expect(
|
||||||
equals(2));
|
ValueTypeUtils.fixedTypedVectorElementSize(ValueType.VectorInt2),
|
||||||
expect(ValueTypeUtils.fixedTypedVectorElementSize(ValueType.VectorInt3),
|
equals(2),
|
||||||
equals(3));
|
);
|
||||||
expect(ValueTypeUtils.fixedTypedVectorElementSize(ValueType.VectorInt4),
|
expect(
|
||||||
equals(4));
|
ValueTypeUtils.fixedTypedVectorElementSize(ValueType.VectorInt3),
|
||||||
|
equals(3),
|
||||||
|
);
|
||||||
|
expect(
|
||||||
|
ValueTypeUtils.fixedTypedVectorElementSize(ValueType.VectorInt4),
|
||||||
|
equals(4),
|
||||||
|
);
|
||||||
|
|
||||||
expect(ValueTypeUtils.fixedTypedVectorElementSize(ValueType.VectorUInt2),
|
expect(
|
||||||
equals(2));
|
ValueTypeUtils.fixedTypedVectorElementSize(ValueType.VectorUInt2),
|
||||||
expect(ValueTypeUtils.fixedTypedVectorElementSize(ValueType.VectorUInt3),
|
equals(2),
|
||||||
equals(3));
|
);
|
||||||
expect(ValueTypeUtils.fixedTypedVectorElementSize(ValueType.VectorUInt4),
|
expect(
|
||||||
equals(4));
|
ValueTypeUtils.fixedTypedVectorElementSize(ValueType.VectorUInt3),
|
||||||
|
equals(3),
|
||||||
|
);
|
||||||
|
expect(
|
||||||
|
ValueTypeUtils.fixedTypedVectorElementSize(ValueType.VectorUInt4),
|
||||||
|
equals(4),
|
||||||
|
);
|
||||||
|
|
||||||
expect(ValueTypeUtils.fixedTypedVectorElementSize(ValueType.VectorFloat2),
|
expect(
|
||||||
equals(2));
|
ValueTypeUtils.fixedTypedVectorElementSize(ValueType.VectorFloat2),
|
||||||
expect(ValueTypeUtils.fixedTypedVectorElementSize(ValueType.VectorFloat3),
|
equals(2),
|
||||||
equals(3));
|
);
|
||||||
expect(ValueTypeUtils.fixedTypedVectorElementSize(ValueType.VectorFloat4),
|
expect(
|
||||||
equals(4));
|
ValueTypeUtils.fixedTypedVectorElementSize(ValueType.VectorFloat3),
|
||||||
|
equals(3),
|
||||||
|
);
|
||||||
|
expect(
|
||||||
|
ValueTypeUtils.fixedTypedVectorElementSize(ValueType.VectorFloat4),
|
||||||
|
equals(4),
|
||||||
|
);
|
||||||
});
|
});
|
||||||
test('packed type', () {
|
test('packed type', () {
|
||||||
expect(
|
expect(
|
||||||
ValueTypeUtils.packedType(ValueType.Null, BitWidth.width8), equals(0));
|
ValueTypeUtils.packedType(ValueType.Null, BitWidth.width8),
|
||||||
|
equals(0),
|
||||||
|
);
|
||||||
expect(
|
expect(
|
||||||
ValueTypeUtils.packedType(ValueType.Null, BitWidth.width16), equals(1));
|
ValueTypeUtils.packedType(ValueType.Null, BitWidth.width16),
|
||||||
|
equals(1),
|
||||||
|
);
|
||||||
expect(
|
expect(
|
||||||
ValueTypeUtils.packedType(ValueType.Null, BitWidth.width32), equals(2));
|
ValueTypeUtils.packedType(ValueType.Null, BitWidth.width32),
|
||||||
|
equals(2),
|
||||||
|
);
|
||||||
expect(
|
expect(
|
||||||
ValueTypeUtils.packedType(ValueType.Null, BitWidth.width64), equals(3));
|
ValueTypeUtils.packedType(ValueType.Null, BitWidth.width64),
|
||||||
|
equals(3),
|
||||||
|
);
|
||||||
|
|
||||||
expect(
|
expect(
|
||||||
ValueTypeUtils.packedType(ValueType.Int, BitWidth.width8), equals(4));
|
ValueTypeUtils.packedType(ValueType.Int, BitWidth.width8),
|
||||||
|
equals(4),
|
||||||
|
);
|
||||||
expect(
|
expect(
|
||||||
ValueTypeUtils.packedType(ValueType.Int, BitWidth.width16), equals(5));
|
ValueTypeUtils.packedType(ValueType.Int, BitWidth.width16),
|
||||||
|
equals(5),
|
||||||
|
);
|
||||||
expect(
|
expect(
|
||||||
ValueTypeUtils.packedType(ValueType.Int, BitWidth.width32), equals(6));
|
ValueTypeUtils.packedType(ValueType.Int, BitWidth.width32),
|
||||||
|
equals(6),
|
||||||
|
);
|
||||||
expect(
|
expect(
|
||||||
ValueTypeUtils.packedType(ValueType.Int, BitWidth.width64), equals(7));
|
ValueTypeUtils.packedType(ValueType.Int, BitWidth.width64),
|
||||||
|
equals(7),
|
||||||
|
);
|
||||||
});
|
});
|
||||||
test('bit width', () {
|
test('bit width', () {
|
||||||
expect(BitWidthUtil.width(0), BitWidth.width8);
|
expect(BitWidthUtil.width(0), BitWidth.width8);
|
||||||
|
|||||||
@@ -2,10 +2,11 @@
|
|||||||
// ignore_for_file: unused_import, unused_field, unused_element, unused_local_variable, constant_identifier_names
|
// ignore_for_file: unused_import, unused_field, unused_element, unused_local_variable, constant_identifier_names
|
||||||
|
|
||||||
import 'dart:typed_data' show Uint8List;
|
import 'dart:typed_data' show Uint8List;
|
||||||
|
|
||||||
import 'package:flat_buffers/flat_buffers.dart' as fb;
|
import 'package:flat_buffers/flat_buffers.dart' as fb;
|
||||||
|
|
||||||
|
import './include_test2_my_game.other_name_space_generated.dart'
|
||||||
import './include_test2_my_game.other_name_space_generated.dart' as my_game_other_name_space;
|
as my_game_other_name_space;
|
||||||
|
|
||||||
class TableA {
|
class TableA {
|
||||||
TableA._(this._bc, this._bcOffset);
|
TableA._(this._bc, this._bcOffset);
|
||||||
@@ -19,15 +20,17 @@ class TableA {
|
|||||||
final fb.BufferContext _bc;
|
final fb.BufferContext _bc;
|
||||||
final int _bcOffset;
|
final int _bcOffset;
|
||||||
|
|
||||||
my_game_other_name_space.TableB? get b => my_game_other_name_space.TableB.reader.vTableGetNullable(_bc, _bcOffset, 4);
|
my_game_other_name_space.TableB? get b => my_game_other_name_space
|
||||||
|
.TableB
|
||||||
|
.reader
|
||||||
|
.vTableGetNullable(_bc, _bcOffset, 4);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String toString() {
|
String toString() {
|
||||||
return 'TableA{b: ${b}}';
|
return 'TableA{b: ${b}}';
|
||||||
}
|
}
|
||||||
|
|
||||||
TableAT unpack() => TableAT(
|
TableAT unpack() => TableAT(b: b?.unpack());
|
||||||
b: b?.unpack());
|
|
||||||
|
|
||||||
static int pack(fb.Builder fbBuilder, TableAT? object) {
|
static int pack(fb.Builder fbBuilder, TableAT? object) {
|
||||||
if (object == null) return 0;
|
if (object == null) return 0;
|
||||||
@@ -38,8 +41,7 @@ class TableA {
|
|||||||
class TableAT implements fb.Packable {
|
class TableAT implements fb.Packable {
|
||||||
my_game_other_name_space.TableBT? b;
|
my_game_other_name_space.TableBT? b;
|
||||||
|
|
||||||
TableAT({
|
TableAT({this.b});
|
||||||
this.b});
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
int pack(fb.Builder fbBuilder) {
|
int pack(fb.Builder fbBuilder) {
|
||||||
@@ -59,8 +61,7 @@ class _TableAReader extends fb.TableReader<TableA> {
|
|||||||
const _TableAReader();
|
const _TableAReader();
|
||||||
|
|
||||||
@override
|
@override
|
||||||
TableA createObject(fb.BufferContext bc, int offset) =>
|
TableA createObject(fb.BufferContext bc, int offset) => TableA._(bc, offset);
|
||||||
TableA._(bc, offset);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class TableABuilder {
|
class TableABuilder {
|
||||||
@@ -85,9 +86,7 @@ class TableABuilder {
|
|||||||
class TableAObjectBuilder extends fb.ObjectBuilder {
|
class TableAObjectBuilder extends fb.ObjectBuilder {
|
||||||
final my_game_other_name_space.TableBObjectBuilder? _b;
|
final my_game_other_name_space.TableBObjectBuilder? _b;
|
||||||
|
|
||||||
TableAObjectBuilder({
|
TableAObjectBuilder({my_game_other_name_space.TableBObjectBuilder? b})
|
||||||
my_game_other_name_space.TableBObjectBuilder? b,
|
|
||||||
})
|
|
||||||
: _b = b;
|
: _b = b;
|
||||||
|
|
||||||
/// Finish building, and store into the [fbBuilder].
|
/// Finish building, and store into the [fbBuilder].
|
||||||
|
|||||||
@@ -4,8 +4,8 @@
|
|||||||
library my_game.other_name_space;
|
library my_game.other_name_space;
|
||||||
|
|
||||||
import 'dart:typed_data' show Uint8List;
|
import 'dart:typed_data' show Uint8List;
|
||||||
import 'package:flat_buffers/flat_buffers.dart' as fb;
|
|
||||||
|
|
||||||
|
import 'package:flat_buffers/flat_buffers.dart' as fb;
|
||||||
|
|
||||||
import './include_test1_generated.dart';
|
import './include_test1_generated.dart';
|
||||||
|
|
||||||
@@ -17,8 +17,10 @@ enum FromInclude {
|
|||||||
|
|
||||||
factory FromInclude.fromValue(int value) {
|
factory FromInclude.fromValue(int value) {
|
||||||
switch (value) {
|
switch (value) {
|
||||||
case 0: return FromInclude.IncludeVal;
|
case 0:
|
||||||
default: throw StateError('Invalid value $value for bit flag enum');
|
return FromInclude.IncludeVal;
|
||||||
|
default:
|
||||||
|
throw StateError('Invalid value $value for bit flag enum');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -56,8 +58,7 @@ class Unused {
|
|||||||
return 'Unused{a: ${a}}';
|
return 'Unused{a: ${a}}';
|
||||||
}
|
}
|
||||||
|
|
||||||
UnusedT unpack() => UnusedT(
|
UnusedT unpack() => UnusedT(a: a);
|
||||||
a: a);
|
|
||||||
|
|
||||||
static int pack(fb.Builder fbBuilder, UnusedT? object) {
|
static int pack(fb.Builder fbBuilder, UnusedT? object) {
|
||||||
if (object == null) return 0;
|
if (object == null) return 0;
|
||||||
@@ -68,8 +69,7 @@ class Unused {
|
|||||||
class UnusedT implements fb.Packable {
|
class UnusedT implements fb.Packable {
|
||||||
int a;
|
int a;
|
||||||
|
|
||||||
UnusedT({
|
UnusedT({required this.a});
|
||||||
required this.a});
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
int pack(fb.Builder fbBuilder) {
|
int pack(fb.Builder fbBuilder) {
|
||||||
@@ -90,8 +90,7 @@ class _UnusedReader extends fb.StructReader<Unused> {
|
|||||||
int get size => 4;
|
int get size => 4;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Unused createObject(fb.BufferContext bc, int offset) =>
|
Unused createObject(fb.BufferContext bc, int offset) => Unused._(bc, offset);
|
||||||
Unused._(bc, offset);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class UnusedBuilder {
|
class UnusedBuilder {
|
||||||
@@ -103,16 +102,12 @@ class UnusedBuilder {
|
|||||||
fbBuilder.putInt32(a);
|
fbBuilder.putInt32(a);
|
||||||
return fbBuilder.offset;
|
return fbBuilder.offset;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class UnusedObjectBuilder extends fb.ObjectBuilder {
|
class UnusedObjectBuilder extends fb.ObjectBuilder {
|
||||||
final int _a;
|
final int _a;
|
||||||
|
|
||||||
UnusedObjectBuilder({
|
UnusedObjectBuilder({required int a}) : _a = a;
|
||||||
required int a,
|
|
||||||
})
|
|
||||||
: _a = a;
|
|
||||||
|
|
||||||
/// Finish building, and store into the [fbBuilder].
|
/// Finish building, and store into the [fbBuilder].
|
||||||
@override
|
@override
|
||||||
@@ -129,6 +124,7 @@ class UnusedObjectBuilder extends fb.ObjectBuilder {
|
|||||||
return fbBuilder.buffer;
|
return fbBuilder.buffer;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class TableB {
|
class TableB {
|
||||||
TableB._(this._bc, this._bcOffset);
|
TableB._(this._bc, this._bcOffset);
|
||||||
factory TableB(List<int> bytes) {
|
factory TableB(List<int> bytes) {
|
||||||
@@ -148,8 +144,7 @@ class TableB {
|
|||||||
return 'TableB{a: ${a}}';
|
return 'TableB{a: ${a}}';
|
||||||
}
|
}
|
||||||
|
|
||||||
TableBT unpack() => TableBT(
|
TableBT unpack() => TableBT(a: a?.unpack());
|
||||||
a: a?.unpack());
|
|
||||||
|
|
||||||
static int pack(fb.Builder fbBuilder, TableBT? object) {
|
static int pack(fb.Builder fbBuilder, TableBT? object) {
|
||||||
if (object == null) return 0;
|
if (object == null) return 0;
|
||||||
@@ -160,8 +155,7 @@ class TableB {
|
|||||||
class TableBT implements fb.Packable {
|
class TableBT implements fb.Packable {
|
||||||
TableAT? a;
|
TableAT? a;
|
||||||
|
|
||||||
TableBT({
|
TableBT({this.a});
|
||||||
this.a});
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
int pack(fb.Builder fbBuilder) {
|
int pack(fb.Builder fbBuilder) {
|
||||||
@@ -181,8 +175,7 @@ class _TableBReader extends fb.TableReader<TableB> {
|
|||||||
const _TableBReader();
|
const _TableBReader();
|
||||||
|
|
||||||
@override
|
@override
|
||||||
TableB createObject(fb.BufferContext bc, int offset) =>
|
TableB createObject(fb.BufferContext bc, int offset) => TableB._(bc, offset);
|
||||||
TableB._(bc, offset);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class TableBBuilder {
|
class TableBBuilder {
|
||||||
@@ -207,10 +200,7 @@ class TableBBuilder {
|
|||||||
class TableBObjectBuilder extends fb.ObjectBuilder {
|
class TableBObjectBuilder extends fb.ObjectBuilder {
|
||||||
final TableAObjectBuilder? _a;
|
final TableAObjectBuilder? _a;
|
||||||
|
|
||||||
TableBObjectBuilder({
|
TableBObjectBuilder({TableAObjectBuilder? a}) : _a = a;
|
||||||
TableAObjectBuilder? a,
|
|
||||||
})
|
|
||||||
: _a = a;
|
|
||||||
|
|
||||||
/// Finish building, and store into the [fbBuilder].
|
/// Finish building, and store into the [fbBuilder].
|
||||||
@override
|
@override
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import 'dart:typed_data' show Uint8List;
|
|||||||
import 'package:flat_buffers/flat_buffers.dart' as fb;
|
import 'package:flat_buffers/flat_buffers.dart' as fb;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
enum Abc {
|
enum Abc {
|
||||||
$void(0),
|
$void(0),
|
||||||
where(1),
|
where(1),
|
||||||
@@ -276,7 +277,7 @@ class Table2 {
|
|||||||
|
|
||||||
Table2T unpack() => Table2T(
|
Table2T unpack() => Table2T(
|
||||||
typeType: typeType,
|
typeType: typeType,
|
||||||
type: type);
|
type: type?.unpack());
|
||||||
|
|
||||||
static int pack(fb.Builder fbBuilder, Table2T? object) {
|
static int pack(fb.Builder fbBuilder, Table2T? object) {
|
||||||
if (object == null) return 0;
|
if (object == null) return 0;
|
||||||
|
|||||||
@@ -4,12 +4,12 @@
|
|||||||
library my_game.example2;
|
library my_game.example2;
|
||||||
|
|
||||||
import 'dart:typed_data' show Uint8List;
|
import 'dart:typed_data' show Uint8List;
|
||||||
|
|
||||||
import 'package:flat_buffers/flat_buffers.dart' as fb;
|
import 'package:flat_buffers/flat_buffers.dart' as fb;
|
||||||
|
|
||||||
import './monster_test_my_game_generated.dart' as my_game;
|
|
||||||
import './monster_test_my_game.example_generated.dart' as my_game_example;
|
|
||||||
|
|
||||||
import './include_test1_generated.dart';
|
import './include_test1_generated.dart';
|
||||||
|
import './monster_test_my_game.example_generated.dart' as my_game_example;
|
||||||
|
import './monster_test_my_game_generated.dart' as my_game;
|
||||||
|
|
||||||
class Monster {
|
class Monster {
|
||||||
Monster._(this._bc, this._bcOffset);
|
Monster._(this._bc, this._bcOffset);
|
||||||
@@ -23,7 +23,6 @@ class Monster {
|
|||||||
final fb.BufferContext _bc;
|
final fb.BufferContext _bc;
|
||||||
final int _bcOffset;
|
final int _bcOffset;
|
||||||
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String toString() {
|
String toString() {
|
||||||
return 'Monster{}';
|
return 'Monster{}';
|
||||||
@@ -59,7 +58,6 @@ class _MonsterReader extends fb.TableReader<Monster> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class MonsterObjectBuilder extends fb.ObjectBuilder {
|
class MonsterObjectBuilder extends fb.ObjectBuilder {
|
||||||
|
|
||||||
MonsterObjectBuilder();
|
MonsterObjectBuilder();
|
||||||
|
|
||||||
/// Finish building, and store into the [fbBuilder].
|
/// Finish building, and store into the [fbBuilder].
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -4,12 +4,12 @@
|
|||||||
library my_game;
|
library my_game;
|
||||||
|
|
||||||
import 'dart:typed_data' show Uint8List;
|
import 'dart:typed_data' show Uint8List;
|
||||||
|
|
||||||
import 'package:flat_buffers/flat_buffers.dart' as fb;
|
import 'package:flat_buffers/flat_buffers.dart' as fb;
|
||||||
|
|
||||||
import './monster_test_my_game.example_generated.dart' as my_game_example;
|
|
||||||
import './monster_test_my_game.example2_generated.dart' as my_game_example2;
|
|
||||||
|
|
||||||
import './include_test1_generated.dart';
|
import './include_test1_generated.dart';
|
||||||
|
import './monster_test_my_game.example2_generated.dart' as my_game_example2;
|
||||||
|
import './monster_test_my_game.example_generated.dart' as my_game_example;
|
||||||
|
|
||||||
class InParentNamespace {
|
class InParentNamespace {
|
||||||
InParentNamespace._(this._bc, this._bcOffset);
|
InParentNamespace._(this._bc, this._bcOffset);
|
||||||
@@ -23,7 +23,6 @@ class InParentNamespace {
|
|||||||
final fb.BufferContext _bc;
|
final fb.BufferContext _bc;
|
||||||
final int _bcOffset;
|
final int _bcOffset;
|
||||||
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String toString() {
|
String toString() {
|
||||||
return 'InParentNamespace{}';
|
return 'InParentNamespace{}';
|
||||||
@@ -59,7 +58,6 @@ class _InParentNamespaceReader extends fb.TableReader<InParentNamespace> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class InParentNamespaceObjectBuilder extends fb.ObjectBuilder {
|
class InParentNamespaceObjectBuilder extends fb.ObjectBuilder {
|
||||||
|
|
||||||
InParentNamespaceObjectBuilder();
|
InParentNamespaceObjectBuilder();
|
||||||
|
|
||||||
/// Finish building, and store into the [fbBuilder].
|
/// Finish building, and store into the [fbBuilder].
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ https://flatbuffers.dev.
|
|||||||
|
|
||||||
## Local Building
|
## Local Building
|
||||||
|
|
||||||
The documentation can be built and served locally during development, see [https//flatbuffers.dev/contributing/#local-development] for full details.
|
The documentation can be built and served locally during development, see <https://flatbuffers.dev/contributing/#local-development> for full details.
|
||||||
|
|
||||||
__tl;dr__
|
__tl;dr__
|
||||||
|
|
||||||
|
|||||||
@@ -139,7 +139,7 @@ nav:
|
|||||||
- Dart: "languages/dart.md"
|
- Dart: "languages/dart.md"
|
||||||
- Go: "languages/go.md"
|
- Go: "languages/go.md"
|
||||||
- Java: "languages/java.md"
|
- Java: "languages/java.md"
|
||||||
- JavasScript: "languages/javascript.md"
|
- JavaScript: "languages/javascript.md"
|
||||||
- Kotlin: "languages/kotlin.md"
|
- Kotlin: "languages/kotlin.md"
|
||||||
- Lobster: "languages/lobster.md"
|
- Lobster: "languages/lobster.md"
|
||||||
- Lua: "languages/lua.md"
|
- Lua: "languages/lua.md"
|
||||||
|
|||||||
@@ -89,6 +89,17 @@ CC=clang PATH=$PATH:$(pwd)/swift-${SWIFT_VERSION}-RELEASE-debian12/usr/bin bazel
|
|||||||
|
|
||||||
If you are unsure which versions to use, check our CI config at `.bazelci/presubmit.yml`.
|
If you are unsure which versions to use, check our CI config at `.bazelci/presubmit.yml`.
|
||||||
|
|
||||||
|
## Building with Conan
|
||||||
|
|
||||||
|
You can download and install flatbuffers using the [Conan](https://conan.io/) dependency manager:
|
||||||
|
|
||||||
|
conan install --requires="flatbuffers/[*]" --build=missing
|
||||||
|
|
||||||
|
The flatbuffers package in Conan Center is maintained by
|
||||||
|
[ConanCenterIndex](https://github.com/conan-io/conan-center-index) community.
|
||||||
|
If the version is out of date or the package does not work,
|
||||||
|
please create an issue or pull request on the [Conan Center Index repository](https://github.com/conan-io/conan-center-index).
|
||||||
|
|
||||||
## Building with VCPKG
|
## Building with VCPKG
|
||||||
|
|
||||||
You can download and install flatbuffers using the [vcpkg](https://github.com/Microsoft/vcpkg/) dependency manager:
|
You can download and install flatbuffers using the [vcpkg](https://github.com/Microsoft/vcpkg/) dependency manager:
|
||||||
|
|||||||
@@ -79,11 +79,12 @@ list of `FILES...`.
|
|||||||
`myschema.fbs` to JSON:
|
`myschema.fbs` to JSON:
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
flatc --json myschema.fbs mydata.bin
|
flatc --json myschema.fbs -- mydata.bin
|
||||||
```
|
```
|
||||||
|
|
||||||
This will generate a `mydata.json` file.
|
This will generate a `mydata.json` file. If there is no
|
||||||
|
[`file_identifier`](schema.md/#file-identification-and-extension) defined
|
||||||
|
for this schema, you will need to use the `--raw-binary` option.
|
||||||
|
|
||||||
### Additional options
|
### Additional options
|
||||||
|
|
||||||
@@ -131,7 +132,7 @@ list of `FILES...`.
|
|||||||
- `--gen-mutable` : Generate additional non-const accessors for mutating
|
- `--gen-mutable` : Generate additional non-const accessors for mutating
|
||||||
FlatBuffers in-place.
|
FlatBuffers in-place.
|
||||||
|
|
||||||
- `--gen-onefile` : Generate single output file for C#, Go, and Python.
|
- `--gen-onefile` : Generate a single output file for C#, Go, Java, Kotlin and Python.
|
||||||
|
|
||||||
- `--gen-name-strings` : Generate type name functions for C++.
|
- `--gen-name-strings` : Generate type name functions for C++.
|
||||||
|
|
||||||
@@ -259,6 +260,11 @@ list of `FILES...`.
|
|||||||
|
|
||||||
- `--python-typing` : Generate Python type annotations
|
- `--python-typing` : Generate Python type annotations
|
||||||
|
|
||||||
|
- `--python-decode-obj-api-strings` : Decode bytes automaticaly with utf-8
|
||||||
|
|
||||||
|
- `--file-names-only` : Prints out files which would be generated by this command, one per
|
||||||
|
line, to `stdout`. No actual files are generated. This is useful for various CI checks.
|
||||||
|
|
||||||
Additional gRPC options:
|
Additional gRPC options:
|
||||||
|
|
||||||
- `--grpc-filename-suffix`: `[C++]` An optional suffix for the generated
|
- `--grpc-filename-suffix`: `[C++]` An optional suffix for the generated
|
||||||
|
|||||||
@@ -21,15 +21,15 @@ It is available as Open Source on
|
|||||||
- :material-memory:{ .lg .middle } **Memory Efficiency and Speed**
|
- :material-memory:{ .lg .middle } **Memory Efficiency and Speed**
|
||||||
|
|
||||||
---
|
---
|
||||||
The only memory needed to access your data is that of the buffer. No heap is
|
The only memory needed to access your data is that of the buffer.
|
||||||
required.
|
No heap is required.
|
||||||
|
|
||||||
- :material-compare-horizontal:{ .lg .middle } **Backwards and Forwards
|
- :material-compare-horizontal:{ .lg .middle } **Backwards and Forwards
|
||||||
Compatibility**
|
Compatibility**
|
||||||
|
|
||||||
---
|
---
|
||||||
The only memory needed to access your data is that of the buffer. No heap is
|
FlatBuffers enables the schema to evolve over time while still maintaining
|
||||||
required.
|
forwards and backwards compatibility with old flatbuffers.
|
||||||
|
|
||||||
- :material-scale-off:{ .lg .middle } **Small Footprint**
|
- :material-scale-off:{ .lg .middle } **Small Footprint**
|
||||||
|
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ FlatBuffers).
|
|||||||
|
|
||||||
## Building the FlatBuffers C# library
|
## Building the FlatBuffers C# library
|
||||||
|
|
||||||
The `FlatBuffers.csproj` project contains multitargeting for .NET Standard 2.1,
|
The `FlatBuffers.csproj` project contains multitargeting for .NET Standard 2.0, 2.1,
|
||||||
.NET 6 and .NET 8.
|
.NET 6 and .NET 8.
|
||||||
|
|
||||||
You can build for a specific framework target when using the cross-platform
|
You can build for a specific framework target when using the cross-platform
|
||||||
|
|||||||
@@ -57,7 +57,7 @@ a `char *` array, which you pass to `GetMonster()`.
|
|||||||
|
|
||||||
```cpp
|
```cpp
|
||||||
#include "flatbuffers/flatbuffers.h"
|
#include "flatbuffers/flatbuffers.h"
|
||||||
#include "monster_test_generate.h"
|
#include "monster_test_generated.h"
|
||||||
#include <iostream> // C++ header file for printing
|
#include <iostream> // C++ header file for printing
|
||||||
#include <fstream> // C++ header file for file access
|
#include <fstream> // C++ header file for file access
|
||||||
|
|
||||||
@@ -242,6 +242,41 @@ provide the following functions to aide in the serialization process:
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
- `native_type("type")` (on a table): Tables can also be represented with
|
||||||
|
native types. For example, the following schema:
|
||||||
|
|
||||||
|
```cpp
|
||||||
|
table Matrix (native_type: "NativeMatrix") {
|
||||||
|
rows: int32;
|
||||||
|
columns: int32;
|
||||||
|
values: [float];
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
Would be represented by a user-defined C++ class:
|
||||||
|
|
||||||
|
```cpp
|
||||||
|
class NativeMatrix { ... }
|
||||||
|
```
|
||||||
|
|
||||||
|
In this case, the following function declarations are generated by the compiler.
|
||||||
|
The user must provide and link the matching function definitions:
|
||||||
|
|
||||||
|
```cpp
|
||||||
|
struct Matrix FLATBUFFERS_FINAL_CLASS : private ::flatbuffers::Table {
|
||||||
|
// ...
|
||||||
|
|
||||||
|
static ::flatbuffers::Offset<Matrix> Pack(
|
||||||
|
::flatbuffers::FlatBufferBuilder& _fbb,
|
||||||
|
const NativeMatrix* _o,
|
||||||
|
const ::flatbuffers::rehasher_function_t* _rehasher = nullptr);
|
||||||
|
|
||||||
|
void UnPackTo(
|
||||||
|
NativeMatrix* _o,
|
||||||
|
const ::flatbuffers::resolver_function_t* _resolver = nullptr) const;
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
Finally, the following top-level attributes:
|
Finally, the following top-level attributes:
|
||||||
|
|
||||||
- `native_include("path")` (at file level): Because the `native_type` attribute
|
- `native_include("path")` (at file level): Because the `native_type` attribute
|
||||||
@@ -419,7 +454,8 @@ Each root type will have a verification function generated for it,
|
|||||||
e.g. for `Monster`, you can call:
|
e.g. for `Monster`, you can call:
|
||||||
|
|
||||||
```cpp
|
```cpp
|
||||||
bool ok = VerifyMonsterBuffer(Verifier(buf, len));
|
Verifier verifier(buf, len);
|
||||||
|
bool ok = VerifyMonsterBuffer(verifier);
|
||||||
```
|
```
|
||||||
|
|
||||||
if `ok` is true, the buffer is safe to read.
|
if `ok` is true, the buffer is safe to read.
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ function). Then you can read a FlatBuffer binary file, which you
|
|||||||
pass the contents of to the `GetRootAsMonster` function:
|
pass the contents of to the `GetRootAsMonster` function:
|
||||||
|
|
||||||
~~~{.php}
|
~~~{.php}
|
||||||
// It is recommended that your use PSR autoload when using FlatBuffers in PHP.
|
// It is recommended that you use PSR autoload when using FlatBuffers in PHP.
|
||||||
// Here is an example:
|
// Here is an example:
|
||||||
function __autoload($class_name) {
|
function __autoload($class_name) {
|
||||||
// The last segment of the class name matches the file name.
|
// The last segment of the class name matches the file name.
|
||||||
@@ -69,7 +69,7 @@ pass the contents of to the `GetRootAsMonster` function:
|
|||||||
// Read the contents of the FlatBuffer binary file.
|
// Read the contents of the FlatBuffer binary file.
|
||||||
$filename = "monster.dat";
|
$filename = "monster.dat";
|
||||||
$handle = fopen($filename, "rb");
|
$handle = fopen($filename, "rb");
|
||||||
$contents = $fread($handle, filesize($filename));
|
$contents = fread($handle, filesize($filename));
|
||||||
fclose($handle);
|
fclose($handle);
|
||||||
|
|
||||||
// Pass the contents to `GetRootAsMonster`.
|
// Pass the contents to `GetRootAsMonster`.
|
||||||
|
|||||||
@@ -97,6 +97,61 @@ convenient accessors for all fields, e.g. `hp()`, `mana()`, etc:
|
|||||||
|
|
||||||
*Note: That we never stored a `mana` value, so it will return the default.*
|
*Note: That we never stored a `mana` value, so it will return the default.*
|
||||||
|
|
||||||
|
## Fallible API and Custom Allocators
|
||||||
|
|
||||||
|
Every `FlatBufferBuilder` method that may allocate has a `try_*` counterpart
|
||||||
|
(e.g. `try_create_string`, `try_push`, `try_finish`) that returns
|
||||||
|
`Result<T, A::Error>` instead of panicking. This is useful when allocation
|
||||||
|
failures must be handled gracefully: for example in `no_std` environments or
|
||||||
|
with fixed-capacity buffers.
|
||||||
|
|
||||||
|
The existing panicking methods are unchanged and remain the simplest option
|
||||||
|
when using the default allocator.
|
||||||
|
|
||||||
|
#### Custom allocators
|
||||||
|
|
||||||
|
Implement the `Allocator` trait and pass it to `FlatBufferBuilder::new_in()`:
|
||||||
|
|
||||||
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.rs}
|
||||||
|
use flatbuffers::{Allocator, FlatBufferBuilder};
|
||||||
|
|
||||||
|
struct MyAllocator { /* ... */ }
|
||||||
|
|
||||||
|
unsafe impl Allocator for MyAllocator {
|
||||||
|
type Error = MyError;
|
||||||
|
fn grow_downwards(&mut self) -> Result<(), Self::Error> { /* ... */ }
|
||||||
|
fn len(&self) -> usize { /* ... */ }
|
||||||
|
}
|
||||||
|
|
||||||
|
let alloc = MyAllocator::new(/* ... */);
|
||||||
|
let mut builder = FlatBufferBuilder::new_in(alloc);
|
||||||
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
|
The built-in `DefaultAllocator` uses `Vec<u8>` and sets `Error = Infallible`,
|
||||||
|
so the `try_*` methods on a default builder can never fail.
|
||||||
|
|
||||||
|
#### Example: building a buffer with error propagation
|
||||||
|
|
||||||
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.rs}
|
||||||
|
fn build<A: flatbuffers::Allocator>(
|
||||||
|
builder: &mut FlatBufferBuilder<A>,
|
||||||
|
) -> Result<(), A::Error> {
|
||||||
|
let name = builder.try_create_string("Orc")?;
|
||||||
|
let inventory = builder.try_create_vector(&[0u8, 1, 2, 3, 4])?;
|
||||||
|
|
||||||
|
let table_start = builder.start_table();
|
||||||
|
builder.try_push_slot_always(Monster::VT_NAME, name)?;
|
||||||
|
builder.try_push_slot_always(Monster::VT_INVENTORY, inventory)?;
|
||||||
|
builder.try_push_slot(Monster::VT_HP, 80i16, 100)?;
|
||||||
|
let root = builder.try_end_table(table_start)?;
|
||||||
|
|
||||||
|
builder.try_finish(root, None)?;
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
|
See the `FlatBufferBuilder` rustdoc for the full list of `try_*` methods.
|
||||||
|
|
||||||
## Direct memory access
|
## Direct memory access
|
||||||
|
|
||||||
As you can see from the above examples, all elements in a buffer are
|
As you can see from the above examples, all elements in a buffer are
|
||||||
@@ -177,6 +232,75 @@ functions require a mutable (aka exclusive) reference which can only be created
|
|||||||
when no other references to the `FlatBufferBuilder` exist, and may not be copied
|
when no other references to the `FlatBufferBuilder` exist, and may not be copied
|
||||||
within the same thread, let alone to a second thread.
|
within the same thread, let alone to a second thread.
|
||||||
|
|
||||||
|
## Reflection (& Resizing)
|
||||||
|
|
||||||
|
There is experimental support for reflection in FlatBuffers, allowing you to
|
||||||
|
read and write data even if you don't know the exact format of a buffer, and
|
||||||
|
even allows you to change sizes of strings in-place.
|
||||||
|
|
||||||
|
The way this works is very elegant; there is actually a FlatBuffer schema that
|
||||||
|
describes schemas (\!) which you can find in `reflection/reflection.fbs`.
|
||||||
|
The compiler, `flatc`, can write out any schemas it has just parsed as a binary
|
||||||
|
FlatBuffer, corresponding to this meta-schema.
|
||||||
|
|
||||||
|
Loading in one of these binary schemas at runtime allows you to traverse any
|
||||||
|
FlatBuffer data that corresponds to it without knowing the exact format. You
|
||||||
|
can query what fields are present, and then read/write them after.
|
||||||
|
|
||||||
|
For convenient field manipulation, you can use the crate
|
||||||
|
`flatbuffers-reflection` which includes both the generated code from the meta
|
||||||
|
schema, as well as a lot of helper functions.
|
||||||
|
|
||||||
|
And example of usage, for the time being, can be found in
|
||||||
|
`tests/rust_reflection_test/src/lib.rs`. Two sets of APIs are provided:
|
||||||
|
|
||||||
|
- [Unsafe getters/setters](https://docs.rs/flatbuffers-reflection/latest/flatbuffers_reflection/#functions),
|
||||||
|
which you can use when you are processing trusted data (either from a source you know, or has been verified)
|
||||||
|
|
||||||
|
- Safe getters in [SafeBuffer](https://docs.rs/flatbuffers-reflection/latest/flatbuffers_reflection/struct.SafeBuffer.html),
|
||||||
|
which does verification when constructed so you can use it for any data source
|
||||||
|
|
||||||
|
## Buffer pre allocation in a latency-sensitive context
|
||||||
|
|
||||||
|
In latency-sensitive applications, dynamic memory allocations can introduce unpredictable latency spikes. The `FlatBufferBuilder` internally uses several `Vec`s that may reallocate during serialization:
|
||||||
|
|
||||||
|
- The backing buffer for the FlatBuffer data
|
||||||
|
- `field_locs` for tracking field locations within tables
|
||||||
|
- `written_vtable_revpos` for deduplicating vtables
|
||||||
|
- `strings_pool` for shared string interning
|
||||||
|
|
||||||
|
To avoid allocations during serialization, you can preallocate all internal vectors upfront using the `with_internal_capacity` constructor:
|
||||||
|
|
||||||
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.rs}
|
||||||
|
// Preallocate: 1KB buffer, 8 field locations, 16 vtables, 32 shared strings
|
||||||
|
let mut builder = FlatBufferBuilder::with_internal_capacity(1024, 8, 16, 32);
|
||||||
|
|
||||||
|
// All subsequent operations will not allocate (if capacities are sufficient)
|
||||||
|
let name = builder.create_shared_string("MyMonster");
|
||||||
|
// ... build your FlatBuffer ...
|
||||||
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
|
There are three variants available:
|
||||||
|
|
||||||
|
- `with_internal_capacity(size, field_locs, vtables, strings)` - Creates a new builder with all capacities preallocated
|
||||||
|
- `from_vec_with_internal_capacity(buffer, field_locs, vtables, strings)` - Reuses an existing `Vec<u8>` as the backing buffer
|
||||||
|
- `new_in_with_internal_capacity(allocator, field_locs, vtables, strings)` - Uses a custom `Allocator` with preallocated internal vecs
|
||||||
|
|
||||||
|
When combined with `reset()`, you can reuse the same builder across multiple serializations without any allocations after the initial setup:
|
||||||
|
|
||||||
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.rs}
|
||||||
|
let mut builder = FlatBufferBuilder::with_internal_capacity(1024, 8, 16, 32);
|
||||||
|
|
||||||
|
loop {
|
||||||
|
// Build a FlatBuffer (allocation-free if capacities are sufficient)
|
||||||
|
let data = build_message(&mut builder);
|
||||||
|
send(data);
|
||||||
|
|
||||||
|
// Reset for reuse - clears state but retains allocated capacity
|
||||||
|
builder.reset();
|
||||||
|
}
|
||||||
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
## Useful tools created by others
|
## Useful tools created by others
|
||||||
|
|
||||||
* [flatc-rust](https://github.com/frol/flatc-rust) - FlatBuffers compiler
|
* [flatc-rust](https://github.com/frol/flatc-rust) - FlatBuffers compiler
|
||||||
|
|||||||
@@ -57,7 +57,7 @@ a data object from the server, which you can pass into the `GetRootAsMonster` fu
|
|||||||
let url = URL(fileURLWithPath: path, isDirectory: true).appendingPathComponent("monsterdata_test").appendingPathExtension("mon")
|
let url = URL(fileURLWithPath: path, isDirectory: true).appendingPathComponent("monsterdata_test").appendingPathExtension("mon")
|
||||||
guard let data = try? Data(contentsOf: url) else { return }
|
guard let data = try? Data(contentsOf: url) else { return }
|
||||||
|
|
||||||
let monster = Monster.getRootAsMonster(bb: ByteBuffer(data: data))
|
let monster: Monster = try! getCheckedRoot(byteBuffer: &byteBuffer)
|
||||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
Now you can access values like this:
|
Now you can access values like this:
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ See the [Tutorial](tutorial.md) for a more in depth guide.
|
|||||||
code:
|
code:
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
./flatc --cpp --rust mosnter.fbs
|
./flatc --cpp --rust monster.fbs
|
||||||
```
|
```
|
||||||
|
|
||||||
Which generates `monster_generated.h` and `monster_generated.rs` files.
|
Which generates `monster_generated.h` and `monster_generated.rs` files.
|
||||||
@@ -61,7 +61,7 @@ See the [Tutorial](tutorial.md) for a more in depth guide.
|
|||||||
|
|
||||||
5. **Transmit/Store the serialized FlatBuffer**
|
5. **Transmit/Store the serialized FlatBuffer**
|
||||||
|
|
||||||
Use your serialized buffer however you want. Send it to someone, save if for
|
Use your serialized buffer however you want. Send it to someone, save it for
|
||||||
later, etc...
|
later, etc...
|
||||||
|
|
||||||
```c++ title="my_monster_factory.cc" linenums="13"
|
```c++ title="my_monster_factory.cc" linenums="13"
|
||||||
|
|||||||
@@ -427,9 +427,6 @@ Current understood attributes:
|
|||||||
it won't be accessible anymore by newer code. Note that if you deprecate a
|
it won't be accessible anymore by newer code. Note that if you deprecate a
|
||||||
field that was previous required, old code may fail to validate new data (when
|
field that was previous required, old code may fail to validate new data (when
|
||||||
using the optional verifier).
|
using the optional verifier).
|
||||||
|
|
||||||
### `required`
|
|
||||||
|
|
||||||
- `required` (on a non-scalar table field): this field must always be set. By
|
- `required` (on a non-scalar table field): this field must always be set. By
|
||||||
default, fields do not need to be present in the binary. This is desirable, as
|
default, fields do not need to be present in the binary. This is desirable, as
|
||||||
it helps with forwards/backwards compatibility, and flexibility of data
|
it helps with forwards/backwards compatibility, and flexibility of data
|
||||||
|
|||||||
@@ -24,14 +24,14 @@ Codegen for all basic features | Yes | Yes | Yes | Yes | Yes | Ye
|
|||||||
JSON parsing | Yes | No | No | No | No | No | No | Yes | No | No | Yes | No | No
|
JSON parsing | Yes | No | No | No | No | No | No | Yes | No | No | Yes | No | No
|
||||||
Simple mutation | Yes | Yes | Yes | Yes | No | No | No | No | No | No | No | No | Yes
|
Simple mutation | Yes | Yes | Yes | Yes | No | No | No | No | No | No | No | No | Yes
|
||||||
Reflection | Yes | No | No | No | No | No | No | Basic | No | No | No | No | No
|
Reflection | Yes | No | No | No | No | No | No | Basic | No | No | No | No | No
|
||||||
Buffer verifier | Yes | No | No | No | No | No | No | Yes | No | No | No | No | No
|
Buffer verifier | Yes | No | No | No | No | No | No | Yes | No | No | No | No | Yes
|
||||||
Native Object API | Yes | No | Yes | Yes | Yes | Yes | Yes | No | No | Yes | No | No | No
|
Native Object API | Yes | No | Yes | Yes | Yes | Yes | Yes | No | No | Yes | No | No | Yes
|
||||||
Optional Scalars | Yes | Yes | Yes | No | No | Yes | Yes | Yes | No | No | Yes | Yes | Yes
|
Optional Scalars | Yes | Yes | Yes | Yes | No | Yes | Yes | Yes | No | No | Yes | Yes | Yes
|
||||||
Flexbuffers | Yes | Yes | ? | ? | ? | ? | ? | ? | ? | ? | ? | Yes | ?
|
Flexbuffers | Yes | Yes | ? | ? | ? | ? | ? | ? | ? | ? | ? | Yes | Yes
|
||||||
Testing: basic | Yes | Yes | Yes | Yes | Yes | Yes | Yes | Yes | ? | Yes | Yes | Yes | Yes
|
Testing: basic | Yes | Yes | Yes | Yes | Yes | Yes | Yes | Yes | ? | Yes | Yes | Yes | Yes
|
||||||
Testing: fuzz | Yes | No | No | Yes | Yes | No | No | No | ? | No | No | Yes | No
|
Testing: fuzz | Yes | No | No | Yes | Yes | No | No | No | ? | No | No | Yes | No
|
||||||
Performance: | Superb | Great | Great | Great | Ok | ? | ? | Superb | ? | ? | Great | Superb | Great
|
Performance: | Superb | Great | Great | Great | Ok | ? | ? | Superb | ? | ? | Great | Superb | Great
|
||||||
Platform: Windows | VS2010 | Yes | Yes | ? | ? | ? | Yes | VS2010 | ? | Yes | Yes | Yes | No
|
Platform: Windows | VS2010 | Yes | Yes | ? | ? | ? | Yes | VS2010 | ? | Yes | Yes | Yes | Yes
|
||||||
Platform: Linux | GCC282 | Yes | ? | Yes | Yes | ? | Yes | Yes | ? | Yes | Yes | Yes | Yes
|
Platform: Linux | GCC282 | Yes | ? | Yes | Yes | ? | Yes | Yes | ? | Yes | Yes | Yes | Yes
|
||||||
Platform: OS X | Xcode4 | ? | ? | ? | Yes | ? | Yes | Yes | ? | Yes | Yes | Yes | Yes
|
Platform: OS X | Xcode4 | ? | ? | ? | Yes | ? | Yes | Yes | ? | Yes | Yes | Yes | Yes
|
||||||
Platform: Android | NDK10d | Yes | ? | ? | ? | ? | ? | ? | ? | Flutter | Yes | ? | No
|
Platform: Android | NDK10d | Yes | ? | ? | ? | ? | ? | ? | ? | Flutter | Yes | ? | No
|
||||||
|
|||||||
@@ -1134,12 +1134,8 @@ The Builder provides multiple ways to create `vectors`.
|
|||||||
=== "Python"
|
=== "Python"
|
||||||
|
|
||||||
```py
|
```py
|
||||||
# Create a FlatBuffer vector and prepend the weapons.
|
# Use the generated helper to create the weapons vector from offsets.
|
||||||
# Note: Since we prepend the data, prepend them in reverse order.
|
weapons = MyGame.Sample.Monster.CreateWeaponsVector(builder, [sword, axe])
|
||||||
MyGame.Sample.Monster.StartWeaponsVector(builder, 2)
|
|
||||||
builder.PrependUOffsetTRelative(axe)
|
|
||||||
builder.PrependUOffsetTRelative(sword)
|
|
||||||
weapons = builder.EndVector()
|
|
||||||
```
|
```
|
||||||
|
|
||||||
=== "Rust"
|
=== "Rust"
|
||||||
@@ -1352,16 +1348,13 @@ bit more directly.
|
|||||||
```py
|
```py
|
||||||
# Create a `vector` representing the inventory of the Orc. Each number
|
# Create a `vector` representing the inventory of the Orc. Each number
|
||||||
# could correspond to an item that can be claimed after he is slain.
|
# could correspond to an item that can be claimed after he is slain.
|
||||||
# Note: Since we prepend the bytes, this loop iterates in reverse.
|
inv = MyGame.Sample.Monster.CreateInventoryVector(builder, range(0, 10))
|
||||||
MyGame.Sample.Monster.StartInventoryVector(builder, 10)
|
|
||||||
for i in reversed(range(0, 10)):
|
|
||||||
builder.PrependByte(i)
|
|
||||||
inv = builder.EndVector()
|
|
||||||
|
|
||||||
MyGame.Sample.Monster.StartPathVector(builder, 2)
|
path_points = [
|
||||||
MyGame.Sample.Vec3.CreateVec3(builder, 1.0, 2.0, 3.0)
|
MyGame.Sample.Vec3T(x=1.0, y=2.0, z=3.0),
|
||||||
MyGame.Sample.Vec3.CreateVec3(builder, 4.0, 5.0, 6.0)
|
MyGame.Sample.Vec3T(x=4.0, y=5.0, z=6.0),
|
||||||
path = builder.EndVector()
|
]
|
||||||
|
path = MyGame.Sample.Monster.CreatePathVector(builder, path_points)
|
||||||
```
|
```
|
||||||
|
|
||||||
=== "Rust"
|
=== "Rust"
|
||||||
@@ -2011,6 +2004,8 @@ like so:
|
|||||||
let buf = builder.sizedByteArray
|
let buf = builder.sizedByteArray
|
||||||
// or you can use to get an object of type Data
|
// or you can use to get an object of type Data
|
||||||
let bufData = ByteBuffer(data: builder.data)
|
let bufData = ByteBuffer(data: builder.data)
|
||||||
|
// or
|
||||||
|
let buf = builder.sizedBuffer
|
||||||
```
|
```
|
||||||
|
|
||||||
=== "TypeScript"
|
=== "TypeScript"
|
||||||
@@ -2054,7 +2049,7 @@ functions to get the root object given the buffer.
|
|||||||
```c++
|
```c++
|
||||||
uint8_t *buffer_pointer = /* the data you just read */;
|
uint8_t *buffer_pointer = /* the data you just read */;
|
||||||
|
|
||||||
// Get an view to the root object inside the buffer.
|
// Get a view to the root object inside the buffer.
|
||||||
Monster monster = GetMonster(buffer_pointer);
|
Monster monster = GetMonster(buffer_pointer);
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -2074,7 +2069,7 @@ functions to get the root object given the buffer.
|
|||||||
```c#
|
```c#
|
||||||
byte[] bytes = /* the data you just read */
|
byte[] bytes = /* the data you just read */
|
||||||
|
|
||||||
// Get an view to the root object inside the buffer.
|
// Get a view to the root object inside the buffer.
|
||||||
Monster monster = Monster.GetRootAsMonster(new ByteBuffer(bytes));
|
Monster monster = Monster.GetRootAsMonster(new ByteBuffer(bytes));
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|||||||
10
eslint.config.mjs
Normal file
10
eslint.config.mjs
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
import globals from "globals";
|
||||||
|
import pluginJs from "@eslint/js";
|
||||||
|
import tseslint from "typescript-eslint";
|
||||||
|
|
||||||
|
export default [
|
||||||
|
{files: ["**/*.{js,mjs,cjs,ts}"]},
|
||||||
|
{languageOptions: { globals: {...globals.browser, ...globals.node} }},
|
||||||
|
pluginJs.configs.recommended,
|
||||||
|
...tseslint.configs.recommended,
|
||||||
|
];
|
||||||
@@ -104,13 +104,16 @@ func (b *Builder) StartObject(numfields int) {
|
|||||||
// logically-equal vtables will be deduplicated.
|
// logically-equal vtables will be deduplicated.
|
||||||
//
|
//
|
||||||
// A vtable has the following format:
|
// A vtable has the following format:
|
||||||
|
//
|
||||||
// <VOffsetT: size of the vtable in bytes, including this value>
|
// <VOffsetT: size of the vtable in bytes, including this value>
|
||||||
// <VOffsetT: size of the object in bytes, including the vtable offset>
|
// <VOffsetT: size of the object in bytes, including the vtable offset>
|
||||||
// <VOffsetT: offset for a field> * N, where N is the number of fields in
|
// <VOffsetT: offset for a field> * N, where N is the number of fields in
|
||||||
// the schema for this type. Includes deprecated fields.
|
// the schema for this type. Includes deprecated fields.
|
||||||
|
//
|
||||||
// Thus, a vtable is made of 2 + N elements, each SizeVOffsetT bytes wide.
|
// Thus, a vtable is made of 2 + N elements, each SizeVOffsetT bytes wide.
|
||||||
//
|
//
|
||||||
// An object has the following format:
|
// An object has the following format:
|
||||||
|
//
|
||||||
// <SOffsetT: offset to this object's vtable (may be negative)>
|
// <SOffsetT: offset to this object's vtable (may be negative)>
|
||||||
// <byte: data>+
|
// <byte: data>+
|
||||||
func (b *Builder) WriteVtable() (n UOffsetT) {
|
func (b *Builder) WriteVtable() (n UOffsetT) {
|
||||||
@@ -296,6 +299,7 @@ func (b *Builder) PrependUOffsetT(off UOffsetT) {
|
|||||||
// StartVector initializes bookkeeping for writing a new vector.
|
// StartVector initializes bookkeeping for writing a new vector.
|
||||||
//
|
//
|
||||||
// A vector has the following format:
|
// A vector has the following format:
|
||||||
|
//
|
||||||
// <UOffsetT: number of elements in this vector>
|
// <UOffsetT: number of elements in this vector>
|
||||||
// <T: data>+, where T is the type of elements of this vector.
|
// <T: data>+, where T is the type of elements of this vector.
|
||||||
func (b *Builder) StartVector(elemSize, numElems, alignment int) UOffsetT {
|
func (b *Builder) StartVector(elemSize, numElems, alignment int) UOffsetT {
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ func GetByte(buf []byte) byte {
|
|||||||
|
|
||||||
// GetBool decodes a little-endian bool from a byte slice.
|
// GetBool decodes a little-endian bool from a byte slice.
|
||||||
func GetBool(buf []byte) bool {
|
func GetBool(buf []byte) bool {
|
||||||
return buf[0] == 1
|
return buf[0] != 0
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetUint8 decodes a little-endian uint8 from a byte slice.
|
// GetUint8 decodes a little-endian uint8 from a byte slice.
|
||||||
|
|||||||
28
go/grpc.go
28
go/grpc.go
@@ -1,7 +1,17 @@
|
|||||||
package flatbuffers
|
package flatbuffers
|
||||||
|
|
||||||
|
import "errors"
|
||||||
|
|
||||||
|
var (
|
||||||
// Codec implements gRPC-go Codec which is used to encode and decode messages.
|
// Codec implements gRPC-go Codec which is used to encode and decode messages.
|
||||||
var Codec = "flatbuffers"
|
Codec = "flatbuffers"
|
||||||
|
|
||||||
|
// ErrInsufficientData is returned when the data is too short to read the root UOffsetT.
|
||||||
|
ErrInsufficientData = errors.New("insufficient data")
|
||||||
|
|
||||||
|
// ErrInvalidRootOffset is returned when the root UOffsetT is out of bounds.
|
||||||
|
ErrInvalidRootOffset = errors.New("invalid root offset")
|
||||||
|
)
|
||||||
|
|
||||||
// FlatbuffersCodec defines the interface gRPC uses to encode and decode messages. Note
|
// FlatbuffersCodec defines the interface gRPC uses to encode and decode messages. Note
|
||||||
// that implementations of this interface must be thread safe; a Codec's
|
// that implementations of this interface must be thread safe; a Codec's
|
||||||
@@ -15,7 +25,21 @@ func (FlatbuffersCodec) Marshal(v interface{}) ([]byte, error) {
|
|||||||
|
|
||||||
// Unmarshal parses the wire format into v.
|
// Unmarshal parses the wire format into v.
|
||||||
func (FlatbuffersCodec) Unmarshal(data []byte, v interface{}) error {
|
func (FlatbuffersCodec) Unmarshal(data []byte, v interface{}) error {
|
||||||
v.(flatbuffersInit).Init(data, GetUOffsetT(data))
|
// Need at least 4 bytes to read the root table offset (UOffsetT).
|
||||||
|
// Vtable soffset_t and metadata are read later during field access.
|
||||||
|
if len(data) < SizeUOffsetT {
|
||||||
|
return ErrInsufficientData
|
||||||
|
}
|
||||||
|
|
||||||
|
off := GetUOffsetT(data)
|
||||||
|
|
||||||
|
// The root UOffsetT must be within the data buffer
|
||||||
|
// Compare in the unsigned domain to avoid signedness pitfalls
|
||||||
|
if off > UOffsetT(len(data)-SizeUOffsetT) {
|
||||||
|
return ErrInvalidRootOffset
|
||||||
|
}
|
||||||
|
|
||||||
|
v.(flatbuffersInit).Init(data, off)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
15
go/table.go
15
go/table.go
@@ -31,10 +31,25 @@ func (t *Table) String(off UOffsetT) string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ByteVector gets a byte slice from data stored inside the flatbuffer.
|
// ByteVector gets a byte slice from data stored inside the flatbuffer.
|
||||||
|
// If the offset is invalid or out of bounds, returns nil to prevent crashes.
|
||||||
func (t *Table) ByteVector(off UOffsetT) []byte {
|
func (t *Table) ByteVector(off UOffsetT) []byte {
|
||||||
|
n := UOffsetT(len(t.Bytes))
|
||||||
|
// Need at least SizeUOffsetT bytes to read the relative vector offset.
|
||||||
|
u := UOffsetT(SizeUOffsetT)
|
||||||
|
if n < u || off > n-u {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
off += GetUOffsetT(t.Bytes[off:])
|
off += GetUOffsetT(t.Bytes[off:])
|
||||||
|
// Need at least SizeUOffsetT bytes to read the vector length.
|
||||||
|
if n < u || off > n-u {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
start := off + UOffsetT(SizeUOffsetT)
|
start := off + UOffsetT(SizeUOffsetT)
|
||||||
length := GetUOffsetT(t.Bytes[off:])
|
length := GetUOffsetT(t.Bytes[off:])
|
||||||
|
// Avoid overflow by checking the length against the remaining buffer space.
|
||||||
|
if length > n-start {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
return t.Bytes[start : start+length]
|
return t.Bytes[start : start+length]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,8 +3,8 @@
|
|||||||
This directory is a repository for the generated files of `flatc`.
|
This directory is a repository for the generated files of `flatc`.
|
||||||
|
|
||||||
We check in the generated code so we can see, during a PR review, how the
|
We check in the generated code so we can see, during a PR review, how the
|
||||||
changes affect the generated output. Its also useful as a reference to point too
|
changes affect the generated output. It's also useful as a reference to show
|
||||||
as how things work across various languages.
|
how things work across various languages.
|
||||||
|
|
||||||
These files are **NOT** intended to be depended on by any code, such as tests or
|
These files are **NOT** intended to be depended on by any code, such as tests or
|
||||||
or compiled examples.
|
or compiled examples.
|
||||||
|
|||||||
@@ -9,8 +9,8 @@
|
|||||||
// Ensure the included flatbuffers.h is the same version as when this file was
|
// Ensure the included flatbuffers.h is the same version as when this file was
|
||||||
// generated, otherwise it may not be compatible.
|
// generated, otherwise it may not be compatible.
|
||||||
static_assert(FLATBUFFERS_VERSION_MAJOR == 25 &&
|
static_assert(FLATBUFFERS_VERSION_MAJOR == 25 &&
|
||||||
FLATBUFFERS_VERSION_MINOR == 2 &&
|
FLATBUFFERS_VERSION_MINOR == 12 &&
|
||||||
FLATBUFFERS_VERSION_REVISION == 10,
|
FLATBUFFERS_VERSION_REVISION == 19,
|
||||||
"Non-compatible flatbuffers version included");
|
"Non-compatible flatbuffers version included");
|
||||||
|
|
||||||
namespace flatbuffers {
|
namespace flatbuffers {
|
||||||
@@ -30,7 +30,8 @@ struct Galaxy FLATBUFFERS_FINAL_CLASS : private ::flatbuffers::Table {
|
|||||||
int64_t num_stars() const {
|
int64_t num_stars() const {
|
||||||
return GetField<int64_t>(VT_NUM_STARS, 0);
|
return GetField<int64_t>(VT_NUM_STARS, 0);
|
||||||
}
|
}
|
||||||
bool Verify(::flatbuffers::Verifier &verifier) const {
|
template <bool B = false>
|
||||||
|
bool Verify(::flatbuffers::VerifierTemplate<B> &verifier) const {
|
||||||
return VerifyTableStart(verifier) &&
|
return VerifyTableStart(verifier) &&
|
||||||
VerifyField<int64_t>(verifier, VT_NUM_STARS, 8) &&
|
VerifyField<int64_t>(verifier, VT_NUM_STARS, 8) &&
|
||||||
verifier.EndTable();
|
verifier.EndTable();
|
||||||
@@ -75,7 +76,8 @@ struct Universe FLATBUFFERS_FINAL_CLASS : private ::flatbuffers::Table {
|
|||||||
const ::flatbuffers::Vector<::flatbuffers::Offset<flatbuffers::goldens::Galaxy>> *galaxies() const {
|
const ::flatbuffers::Vector<::flatbuffers::Offset<flatbuffers::goldens::Galaxy>> *galaxies() const {
|
||||||
return GetPointer<const ::flatbuffers::Vector<::flatbuffers::Offset<flatbuffers::goldens::Galaxy>> *>(VT_GALAXIES);
|
return GetPointer<const ::flatbuffers::Vector<::flatbuffers::Offset<flatbuffers::goldens::Galaxy>> *>(VT_GALAXIES);
|
||||||
}
|
}
|
||||||
bool Verify(::flatbuffers::Verifier &verifier) const {
|
template <bool B = false>
|
||||||
|
bool Verify(::flatbuffers::VerifierTemplate<B> &verifier) const {
|
||||||
return VerifyTableStart(verifier) &&
|
return VerifyTableStart(verifier) &&
|
||||||
VerifyField<double>(verifier, VT_AGE, 8) &&
|
VerifyField<double>(verifier, VT_AGE, 8) &&
|
||||||
VerifyOffset(verifier, VT_GALAXIES) &&
|
VerifyOffset(verifier, VT_GALAXIES) &&
|
||||||
@@ -135,14 +137,16 @@ inline const flatbuffers::goldens::Universe *GetSizePrefixedUniverse(const void
|
|||||||
return ::flatbuffers::GetSizePrefixedRoot<flatbuffers::goldens::Universe>(buf);
|
return ::flatbuffers::GetSizePrefixedRoot<flatbuffers::goldens::Universe>(buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <bool B = false>
|
||||||
inline bool VerifyUniverseBuffer(
|
inline bool VerifyUniverseBuffer(
|
||||||
::flatbuffers::Verifier &verifier) {
|
::flatbuffers::VerifierTemplate<B> &verifier) {
|
||||||
return verifier.VerifyBuffer<flatbuffers::goldens::Universe>(nullptr);
|
return verifier.template VerifyBuffer<flatbuffers::goldens::Universe>(nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <bool B = false>
|
||||||
inline bool VerifySizePrefixedUniverseBuffer(
|
inline bool VerifySizePrefixedUniverseBuffer(
|
||||||
::flatbuffers::Verifier &verifier) {
|
::flatbuffers::VerifierTemplate<B> &verifier) {
|
||||||
return verifier.VerifySizePrefixedBuffer<flatbuffers::goldens::Universe>(nullptr);
|
return verifier.template VerifySizePrefixedBuffer<flatbuffers::goldens::Universe>(nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void FinishUniverseBuffer(
|
inline void FinishUniverseBuffer(
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ public struct Galaxy : IFlatbufferObject
|
|||||||
{
|
{
|
||||||
private Table __p;
|
private Table __p;
|
||||||
public ByteBuffer ByteBuffer { get { return __p.bb; } }
|
public ByteBuffer ByteBuffer { get { return __p.bb; } }
|
||||||
public static void ValidateVersion() { FlatBufferConstants.FLATBUFFERS_25_2_10(); }
|
public static void ValidateVersion() { FlatBufferConstants.FLATBUFFERS_25_12_19(); }
|
||||||
public static Galaxy GetRootAsGalaxy(ByteBuffer _bb) { return GetRootAsGalaxy(_bb, new Galaxy()); }
|
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 static Galaxy GetRootAsGalaxy(ByteBuffer _bb, Galaxy obj) { return (obj.__assign(_bb.GetInt(_bb.Position) + _bb.Position, _bb)); }
|
||||||
public void __init(int _i, ByteBuffer _bb) { __p = new Table(_i, _bb); }
|
public void __init(int _i, ByteBuffer _bb) { __p = new Table(_i, _bb); }
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ public struct Universe : IFlatbufferObject
|
|||||||
{
|
{
|
||||||
private Table __p;
|
private Table __p;
|
||||||
public ByteBuffer ByteBuffer { get { return __p.bb; } }
|
public ByteBuffer ByteBuffer { get { return __p.bb; } }
|
||||||
public static void ValidateVersion() { FlatBufferConstants.FLATBUFFERS_25_2_10(); }
|
public static void ValidateVersion() { FlatBufferConstants.FLATBUFFERS_25_12_19(); }
|
||||||
public static Universe GetRootAsUniverse(ByteBuffer _bb) { return GetRootAsUniverse(_bb, new Universe()); }
|
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 Universe GetRootAsUniverse(ByteBuffer _bb, Universe obj) { return (obj.__assign(_bb.GetInt(_bb.Position) + _bb.Position, _bb)); }
|
||||||
public static bool VerifyUniverse(ByteBuffer _bb) {Google.FlatBuffers.Verifier verifier = new Google.FlatBuffers.Verifier(_bb); return verifier.VerifyBuffer("", false, UniverseVerify.Verify); }
|
public static bool VerifyUniverse(ByteBuffer _bb) {Google.FlatBuffers.Verifier verifier = new Google.FlatBuffers.Verifier(_bb); return verifier.VerifyBuffer("", false, UniverseVerify.Verify); }
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import 'dart:typed_data' show Uint8List;
|
|||||||
import 'package:flat_buffers/flat_buffers.dart' as fb;
|
import 'package:flat_buffers/flat_buffers.dart' as fb;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class Galaxy {
|
class Galaxy {
|
||||||
Galaxy._(this._bc, this._bcOffset);
|
Galaxy._(this._bc, this._bcOffset);
|
||||||
factory Galaxy(List<int> bytes) {
|
factory Galaxy(List<int> bytes) {
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import sys
|
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
import sys
|
||||||
|
|
||||||
# Get the path where this script is located so we can invoke the script from
|
# Get the path where this script is located so we can invoke the script from
|
||||||
# any directory and have the paths work correctly.
|
# any directory and have the paths work correctly.
|
||||||
|
|||||||
@@ -14,14 +14,13 @@ import com.google.flatbuffers.LongVector;
|
|||||||
import com.google.flatbuffers.ShortVector;
|
import com.google.flatbuffers.ShortVector;
|
||||||
import com.google.flatbuffers.StringVector;
|
import com.google.flatbuffers.StringVector;
|
||||||
import com.google.flatbuffers.Struct;
|
import com.google.flatbuffers.Struct;
|
||||||
import com.google.flatbuffers.Table;
|
|
||||||
import com.google.flatbuffers.UnionVector;
|
import com.google.flatbuffers.UnionVector;
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
import java.nio.ByteOrder;
|
import java.nio.ByteOrder;
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
public final class Galaxy extends Table {
|
public final class Galaxy extends com.google.flatbuffers.Table {
|
||||||
public static void ValidateVersion() { Constants.FLATBUFFERS_25_2_10(); }
|
public static void ValidateVersion() { Constants.FLATBUFFERS_25_12_19(); }
|
||||||
public static Galaxy getRootAsGalaxy(ByteBuffer _bb) { return getRootAsGalaxy(_bb, new Galaxy()); }
|
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 static Galaxy getRootAsGalaxy(ByteBuffer _bb, Galaxy obj) { _bb.order(ByteOrder.LITTLE_ENDIAN); return (obj.__assign(_bb.getInt(_bb.position()) + _bb.position(), _bb)); }
|
||||||
public void __init(int _i, ByteBuffer _bb) { __reset(_i, _bb); }
|
public void __init(int _i, ByteBuffer _bb) { __reset(_i, _bb); }
|
||||||
|
|||||||
@@ -14,14 +14,13 @@ import com.google.flatbuffers.LongVector;
|
|||||||
import com.google.flatbuffers.ShortVector;
|
import com.google.flatbuffers.ShortVector;
|
||||||
import com.google.flatbuffers.StringVector;
|
import com.google.flatbuffers.StringVector;
|
||||||
import com.google.flatbuffers.Struct;
|
import com.google.flatbuffers.Struct;
|
||||||
import com.google.flatbuffers.Table;
|
|
||||||
import com.google.flatbuffers.UnionVector;
|
import com.google.flatbuffers.UnionVector;
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
import java.nio.ByteOrder;
|
import java.nio.ByteOrder;
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
public final class Universe extends Table {
|
public final class Universe extends com.google.flatbuffers.Table {
|
||||||
public static void ValidateVersion() { Constants.FLATBUFFERS_25_2_10(); }
|
public static void ValidateVersion() { Constants.FLATBUFFERS_25_12_19(); }
|
||||||
public static Universe getRootAsUniverse(ByteBuffer _bb) { return getRootAsUniverse(_bb, new Universe()); }
|
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 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 void __init(int _i, ByteBuffer _bb) { __reset(_i, _bb); }
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ class Galaxy : Table() {
|
|||||||
return if(o != 0) bb.getLong(o + bb_pos) else 0L
|
return if(o != 0) bb.getLong(o + bb_pos) else 0L
|
||||||
}
|
}
|
||||||
companion object {
|
companion object {
|
||||||
fun validateVersion() = Constants.FLATBUFFERS_25_2_10()
|
fun validateVersion() = Constants.FLATBUFFERS_25_12_19()
|
||||||
fun getRootAsGalaxy(_bb: ByteBuffer): Galaxy = getRootAsGalaxy(_bb, Galaxy())
|
fun getRootAsGalaxy(_bb: ByteBuffer): Galaxy = getRootAsGalaxy(_bb, Galaxy())
|
||||||
fun getRootAsGalaxy(_bb: ByteBuffer, obj: Galaxy): Galaxy {
|
fun getRootAsGalaxy(_bb: ByteBuffer, obj: Galaxy): Galaxy {
|
||||||
_bb.order(ByteOrder.LITTLE_ENDIAN)
|
_bb.order(ByteOrder.LITTLE_ENDIAN)
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ class Universe : Table() {
|
|||||||
val o = __offset(6); return if (o != 0) __vector_len(o) else 0
|
val o = __offset(6); return if (o != 0) __vector_len(o) else 0
|
||||||
}
|
}
|
||||||
companion object {
|
companion object {
|
||||||
fun validateVersion() = Constants.FLATBUFFERS_25_2_10()
|
fun validateVersion() = Constants.FLATBUFFERS_25_12_19()
|
||||||
fun getRootAsUniverse(_bb: ByteBuffer): Universe = getRootAsUniverse(_bb, Universe())
|
fun getRootAsUniverse(_bb: ByteBuffer): Universe = getRootAsUniverse(_bb, Universe())
|
||||||
fun getRootAsUniverse(_bb: ByteBuffer, obj: Universe): Universe {
|
fun getRootAsUniverse(_bb: ByteBuffer, obj: Universe): Universe {
|
||||||
_bb.order(ByteOrder.LITTLE_ENDIAN)
|
_bb.order(ByteOrder.LITTLE_ENDIAN)
|
||||||
|
|||||||
@@ -80,6 +80,12 @@ def UniverseStartGalaxiesVector(builder, numElems):
|
|||||||
def StartGalaxiesVector(builder, numElems):
|
def StartGalaxiesVector(builder, numElems):
|
||||||
return UniverseStartGalaxiesVector(builder, numElems)
|
return UniverseStartGalaxiesVector(builder, numElems)
|
||||||
|
|
||||||
|
def UniverseCreateGalaxiesVector(builder, data):
|
||||||
|
return builder.CreateVectorOfTables(data)
|
||||||
|
|
||||||
|
def CreateGalaxiesVector(builder, data):
|
||||||
|
UniverseCreateGalaxiesVector(builder, data)
|
||||||
|
|
||||||
def UniverseEnd(builder):
|
def UniverseEnd(builder):
|
||||||
return builder.EndObject()
|
return builder.EndObject()
|
||||||
|
|
||||||
|
|||||||
@@ -1,58 +1,44 @@
|
|||||||
// automatically generated by the FlatBuffers compiler, do not modify
|
// automatically generated by the FlatBuffers compiler, do not modify
|
||||||
|
|
||||||
|
|
||||||
// @generated
|
// @generated
|
||||||
|
extern crate alloc;
|
||||||
use core::mem;
|
|
||||||
use core::cmp::Ordering;
|
|
||||||
|
|
||||||
extern crate flatbuffers;
|
|
||||||
use self::flatbuffers::{EndianScalar, Follow};
|
|
||||||
|
|
||||||
#[allow(unused_imports, dead_code)]
|
#[allow(unused_imports, dead_code)]
|
||||||
pub mod flatbuffers {
|
pub mod flatbuffers {
|
||||||
|
extern crate alloc;
|
||||||
|
|
||||||
use core::mem;
|
|
||||||
use core::cmp::Ordering;
|
|
||||||
|
|
||||||
extern crate flatbuffers;
|
|
||||||
use self::flatbuffers::{EndianScalar, Follow};
|
|
||||||
#[allow(unused_imports, dead_code)]
|
#[allow(unused_imports, dead_code)]
|
||||||
pub mod goldens {
|
pub mod goldens {
|
||||||
|
extern crate alloc;
|
||||||
use core::mem;
|
|
||||||
use core::cmp::Ordering;
|
|
||||||
|
|
||||||
extern crate flatbuffers;
|
|
||||||
use self::flatbuffers::{EndianScalar, Follow};
|
|
||||||
|
|
||||||
pub enum GalaxyOffset {}
|
pub enum GalaxyOffset {}
|
||||||
#[derive(Copy, Clone, PartialEq)]
|
|
||||||
|
|
||||||
|
#[derive(Copy, Clone, PartialEq)]
|
||||||
pub struct Galaxy<'a> {
|
pub struct Galaxy<'a> {
|
||||||
pub _tab: flatbuffers::Table<'a>,
|
pub _tab: ::flatbuffers::Table<'a>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> flatbuffers::Follow<'a> for Galaxy<'a> {
|
impl<'a> ::flatbuffers::Follow<'a> for Galaxy<'a> {
|
||||||
type Inner = Galaxy<'a>;
|
type Inner = Galaxy<'a>;
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||||
Self { _tab: flatbuffers::Table::new(buf, loc) }
|
Self { _tab: unsafe { ::flatbuffers::Table::new(buf, loc) } }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> Galaxy<'a> {
|
impl<'a> Galaxy<'a> {
|
||||||
pub const VT_NUM_STARS: flatbuffers::VOffsetT = 4;
|
pub const VT_NUM_STARS: ::flatbuffers::VOffsetT = 4;
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub unsafe fn init_from_table(table: flatbuffers::Table<'a>) -> Self {
|
pub unsafe fn init_from_table(table: ::flatbuffers::Table<'a>) -> Self {
|
||||||
Galaxy { _tab: table }
|
Galaxy { _tab: table }
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(unused_mut)]
|
#[allow(unused_mut)]
|
||||||
pub fn create<'bldr: 'args, 'args: 'mut_bldr, 'mut_bldr, A: flatbuffers::Allocator + 'bldr>(
|
pub fn create<'bldr: 'args, 'args: 'mut_bldr, 'mut_bldr, A: ::flatbuffers::Allocator + 'bldr>(
|
||||||
_fbb: &'mut_bldr mut flatbuffers::FlatBufferBuilder<'bldr, A>,
|
_fbb: &'mut_bldr mut ::flatbuffers::FlatBufferBuilder<'bldr, A>,
|
||||||
args: &'args GalaxyArgs
|
args: &'args GalaxyArgs
|
||||||
) -> flatbuffers::WIPOffset<Galaxy<'bldr>> {
|
) -> ::flatbuffers::WIPOffset<Galaxy<'bldr>> {
|
||||||
let mut builder = GalaxyBuilder::new(_fbb);
|
let mut builder = GalaxyBuilder::new(_fbb);
|
||||||
builder.add_num_stars(args.num_stars);
|
builder.add_num_stars(args.num_stars);
|
||||||
builder.finish()
|
builder.finish()
|
||||||
@@ -68,21 +54,22 @@ impl<'a> Galaxy<'a> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl flatbuffers::Verifiable for Galaxy<'_> {
|
impl ::flatbuffers::Verifiable for Galaxy<'_> {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn run_verifier(
|
fn run_verifier(
|
||||||
v: &mut flatbuffers::Verifier, pos: usize
|
v: &mut ::flatbuffers::Verifier, pos: usize
|
||||||
) -> Result<(), flatbuffers::InvalidFlatbuffer> {
|
) -> Result<(), ::flatbuffers::InvalidFlatbuffer> {
|
||||||
use self::flatbuffers::Verifiable;
|
|
||||||
v.visit_table(pos)?
|
v.visit_table(pos)?
|
||||||
.visit_field::<i64>("num_stars", Self::VT_NUM_STARS, false)?
|
.visit_field::<i64>("num_stars", Self::VT_NUM_STARS, false)?
|
||||||
.finish();
|
.finish();
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct GalaxyArgs {
|
pub struct GalaxyArgs {
|
||||||
pub num_stars: i64,
|
pub num_stars: i64,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> Default for GalaxyArgs {
|
impl<'a> Default for GalaxyArgs {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
@@ -92,65 +79,71 @@ impl<'a> Default for GalaxyArgs {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct GalaxyBuilder<'a: 'b, 'b, A: flatbuffers::Allocator + 'a> {
|
pub struct GalaxyBuilder<'a: 'b, 'b, A: ::flatbuffers::Allocator + 'a> {
|
||||||
fbb_: &'b mut flatbuffers::FlatBufferBuilder<'a, A>,
|
fbb_: &'b mut ::flatbuffers::FlatBufferBuilder<'a, A>,
|
||||||
start_: flatbuffers::WIPOffset<flatbuffers::TableUnfinishedWIPOffset>,
|
start_: ::flatbuffers::WIPOffset<::flatbuffers::TableUnfinishedWIPOffset>,
|
||||||
}
|
}
|
||||||
impl<'a: 'b, 'b, A: flatbuffers::Allocator + 'a> GalaxyBuilder<'a, 'b, A> {
|
|
||||||
|
impl<'a: 'b, 'b, A: ::flatbuffers::Allocator + 'a> GalaxyBuilder<'a, 'b, A> {
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn add_num_stars(&mut self, num_stars: i64) {
|
pub fn add_num_stars(&mut self, num_stars: i64) {
|
||||||
self.fbb_.push_slot::<i64>(Galaxy::VT_NUM_STARS, num_stars, 0);
|
self.fbb_.push_slot::<i64>(Galaxy::VT_NUM_STARS, num_stars, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn new(_fbb: &'b mut flatbuffers::FlatBufferBuilder<'a, A>) -> GalaxyBuilder<'a, 'b, A> {
|
pub fn new(_fbb: &'b mut ::flatbuffers::FlatBufferBuilder<'a, A>) -> GalaxyBuilder<'a, 'b, A> {
|
||||||
let start = _fbb.start_table();
|
let start = _fbb.start_table();
|
||||||
GalaxyBuilder {
|
GalaxyBuilder {
|
||||||
fbb_: _fbb,
|
fbb_: _fbb,
|
||||||
start_: start,
|
start_: start,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn finish(self) -> flatbuffers::WIPOffset<Galaxy<'a>> {
|
pub fn finish(self) -> ::flatbuffers::WIPOffset<Galaxy<'a>> {
|
||||||
let o = self.fbb_.end_table(self.start_);
|
let o = self.fbb_.end_table(self.start_);
|
||||||
flatbuffers::WIPOffset::new(o.value())
|
::flatbuffers::WIPOffset::new(o.value())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl core::fmt::Debug for Galaxy<'_> {
|
impl ::core::fmt::Debug for Galaxy<'_> {
|
||||||
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
|
fn fmt(&self, f: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result {
|
||||||
let mut ds = f.debug_struct("Galaxy");
|
let mut ds = f.debug_struct("Galaxy");
|
||||||
ds.field("num_stars", &self.num_stars());
|
ds.field("num_stars", &self.num_stars());
|
||||||
ds.finish()
|
ds.finish()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pub enum UniverseOffset {}
|
|
||||||
#[derive(Copy, Clone, PartialEq)]
|
|
||||||
|
|
||||||
|
pub enum UniverseOffset {}
|
||||||
|
|
||||||
|
#[derive(Copy, Clone, PartialEq)]
|
||||||
pub struct Universe<'a> {
|
pub struct Universe<'a> {
|
||||||
pub _tab: flatbuffers::Table<'a>,
|
pub _tab: ::flatbuffers::Table<'a>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> flatbuffers::Follow<'a> for Universe<'a> {
|
impl<'a> ::flatbuffers::Follow<'a> for Universe<'a> {
|
||||||
type Inner = Universe<'a>;
|
type Inner = Universe<'a>;
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
unsafe fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
|
||||||
Self { _tab: flatbuffers::Table::new(buf, loc) }
|
Self { _tab: unsafe { ::flatbuffers::Table::new(buf, loc) } }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> Universe<'a> {
|
impl<'a> Universe<'a> {
|
||||||
pub const VT_AGE: flatbuffers::VOffsetT = 4;
|
pub const VT_AGE: ::flatbuffers::VOffsetT = 4;
|
||||||
pub const VT_GALAXIES: flatbuffers::VOffsetT = 6;
|
pub const VT_GALAXIES: ::flatbuffers::VOffsetT = 6;
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub unsafe fn init_from_table(table: flatbuffers::Table<'a>) -> Self {
|
pub unsafe fn init_from_table(table: ::flatbuffers::Table<'a>) -> Self {
|
||||||
Universe { _tab: table }
|
Universe { _tab: table }
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(unused_mut)]
|
#[allow(unused_mut)]
|
||||||
pub fn create<'bldr: 'args, 'args: 'mut_bldr, 'mut_bldr, A: flatbuffers::Allocator + 'bldr>(
|
pub fn create<'bldr: 'args, 'args: 'mut_bldr, 'mut_bldr, A: ::flatbuffers::Allocator + 'bldr>(
|
||||||
_fbb: &'mut_bldr mut flatbuffers::FlatBufferBuilder<'bldr, A>,
|
_fbb: &'mut_bldr mut ::flatbuffers::FlatBufferBuilder<'bldr, A>,
|
||||||
args: &'args UniverseArgs<'args>
|
args: &'args UniverseArgs<'args>
|
||||||
) -> flatbuffers::WIPOffset<Universe<'bldr>> {
|
) -> ::flatbuffers::WIPOffset<Universe<'bldr>> {
|
||||||
let mut builder = UniverseBuilder::new(_fbb);
|
let mut builder = UniverseBuilder::new(_fbb);
|
||||||
builder.add_age(args.age);
|
builder.add_age(args.age);
|
||||||
if let Some(x) = args.galaxies { builder.add_galaxies(x); }
|
if let Some(x) = args.galaxies { builder.add_galaxies(x); }
|
||||||
@@ -165,32 +158,34 @@ impl<'a> Universe<'a> {
|
|||||||
// which contains a valid value in this slot
|
// which contains a valid value in this slot
|
||||||
unsafe { self._tab.get::<f64>(Universe::VT_AGE, Some(0.0)).unwrap()}
|
unsafe { self._tab.get::<f64>(Universe::VT_AGE, Some(0.0)).unwrap()}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn galaxies(&self) -> Option<flatbuffers::Vector<'a, flatbuffers::ForwardsUOffset<Galaxy<'a>>>> {
|
pub fn galaxies(&self) -> Option<::flatbuffers::Vector<'a, ::flatbuffers::ForwardsUOffset<Galaxy<'a>>>> {
|
||||||
// Safety:
|
// Safety:
|
||||||
// Created from valid Table for this object
|
// Created from valid Table for this object
|
||||||
// which contains a valid value in this slot
|
// which contains a valid value in this slot
|
||||||
unsafe { self._tab.get::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<'a, flatbuffers::ForwardsUOffset<Galaxy>>>>(Universe::VT_GALAXIES, None)}
|
unsafe { self._tab.get::<::flatbuffers::ForwardsUOffset<::flatbuffers::Vector<'a, ::flatbuffers::ForwardsUOffset<Galaxy>>>>(Universe::VT_GALAXIES, None)}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl flatbuffers::Verifiable for Universe<'_> {
|
impl ::flatbuffers::Verifiable for Universe<'_> {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn run_verifier(
|
fn run_verifier(
|
||||||
v: &mut flatbuffers::Verifier, pos: usize
|
v: &mut ::flatbuffers::Verifier, pos: usize
|
||||||
) -> Result<(), flatbuffers::InvalidFlatbuffer> {
|
) -> Result<(), ::flatbuffers::InvalidFlatbuffer> {
|
||||||
use self::flatbuffers::Verifiable;
|
|
||||||
v.visit_table(pos)?
|
v.visit_table(pos)?
|
||||||
.visit_field::<f64>("age", Self::VT_AGE, false)?
|
.visit_field::<f64>("age", Self::VT_AGE, false)?
|
||||||
.visit_field::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<'_, flatbuffers::ForwardsUOffset<Galaxy>>>>("galaxies", Self::VT_GALAXIES, false)?
|
.visit_field::<::flatbuffers::ForwardsUOffset<::flatbuffers::Vector<'_, ::flatbuffers::ForwardsUOffset<Galaxy>>>>("galaxies", Self::VT_GALAXIES, false)?
|
||||||
.finish();
|
.finish();
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct UniverseArgs<'a> {
|
pub struct UniverseArgs<'a> {
|
||||||
pub age: f64,
|
pub age: f64,
|
||||||
pub galaxies: Option<flatbuffers::WIPOffset<flatbuffers::Vector<'a, flatbuffers::ForwardsUOffset<Galaxy<'a>>>>>,
|
pub galaxies: Option<::flatbuffers::WIPOffset<::flatbuffers::Vector<'a, ::flatbuffers::ForwardsUOffset<Galaxy<'a>>>>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> Default for UniverseArgs<'a> {
|
impl<'a> Default for UniverseArgs<'a> {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
@@ -201,113 +196,127 @@ impl<'a> Default for UniverseArgs<'a> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct UniverseBuilder<'a: 'b, 'b, A: flatbuffers::Allocator + 'a> {
|
pub struct UniverseBuilder<'a: 'b, 'b, A: ::flatbuffers::Allocator + 'a> {
|
||||||
fbb_: &'b mut flatbuffers::FlatBufferBuilder<'a, A>,
|
fbb_: &'b mut ::flatbuffers::FlatBufferBuilder<'a, A>,
|
||||||
start_: flatbuffers::WIPOffset<flatbuffers::TableUnfinishedWIPOffset>,
|
start_: ::flatbuffers::WIPOffset<::flatbuffers::TableUnfinishedWIPOffset>,
|
||||||
}
|
}
|
||||||
impl<'a: 'b, 'b, A: flatbuffers::Allocator + 'a> UniverseBuilder<'a, 'b, A> {
|
|
||||||
|
impl<'a: 'b, 'b, A: ::flatbuffers::Allocator + 'a> UniverseBuilder<'a, 'b, A> {
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn add_age(&mut self, age: f64) {
|
pub fn add_age(&mut self, age: f64) {
|
||||||
self.fbb_.push_slot::<f64>(Universe::VT_AGE, age, 0.0);
|
self.fbb_.push_slot::<f64>(Universe::VT_AGE, age, 0.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn add_galaxies(&mut self, galaxies: flatbuffers::WIPOffset<flatbuffers::Vector<'b , flatbuffers::ForwardsUOffset<Galaxy<'b >>>>) {
|
pub fn add_galaxies(&mut self, galaxies: ::flatbuffers::WIPOffset<::flatbuffers::Vector<'b , ::flatbuffers::ForwardsUOffset<Galaxy<'b >>>>) {
|
||||||
self.fbb_.push_slot_always::<flatbuffers::WIPOffset<_>>(Universe::VT_GALAXIES, galaxies);
|
self.fbb_.push_slot_always::<::flatbuffers::WIPOffset<_>>(Universe::VT_GALAXIES, galaxies);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn new(_fbb: &'b mut flatbuffers::FlatBufferBuilder<'a, A>) -> UniverseBuilder<'a, 'b, A> {
|
pub fn new(_fbb: &'b mut ::flatbuffers::FlatBufferBuilder<'a, A>) -> UniverseBuilder<'a, 'b, A> {
|
||||||
let start = _fbb.start_table();
|
let start = _fbb.start_table();
|
||||||
UniverseBuilder {
|
UniverseBuilder {
|
||||||
fbb_: _fbb,
|
fbb_: _fbb,
|
||||||
start_: start,
|
start_: start,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn finish(self) -> flatbuffers::WIPOffset<Universe<'a>> {
|
pub fn finish(self) -> ::flatbuffers::WIPOffset<Universe<'a>> {
|
||||||
let o = self.fbb_.end_table(self.start_);
|
let o = self.fbb_.end_table(self.start_);
|
||||||
flatbuffers::WIPOffset::new(o.value())
|
::flatbuffers::WIPOffset::new(o.value())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl core::fmt::Debug for Universe<'_> {
|
impl ::core::fmt::Debug for Universe<'_> {
|
||||||
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
|
fn fmt(&self, f: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result {
|
||||||
let mut ds = f.debug_struct("Universe");
|
let mut ds = f.debug_struct("Universe");
|
||||||
ds.field("age", &self.age());
|
ds.field("age", &self.age());
|
||||||
ds.field("galaxies", &self.galaxies());
|
ds.field("galaxies", &self.galaxies());
|
||||||
ds.finish()
|
ds.finish()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#[inline]
|
|
||||||
/// Verifies that a buffer of bytes contains a `Universe`
|
/// Verifies that a buffer of bytes contains a `Universe`
|
||||||
/// and returns it.
|
/// and returns it.
|
||||||
/// Note that verification is still experimental and may not
|
/// Note that verification is still experimental and may not
|
||||||
/// catch every error, or be maximally performant. For the
|
/// catch every error, or be maximally performant. For the
|
||||||
/// previous, unchecked, behavior use
|
/// previous, unchecked, behavior use
|
||||||
/// `root_as_universe_unchecked`.
|
/// `root_as_universe_unchecked`.
|
||||||
pub fn root_as_universe(buf: &[u8]) -> Result<Universe, flatbuffers::InvalidFlatbuffer> {
|
|
||||||
flatbuffers::root::<Universe>(buf)
|
|
||||||
}
|
|
||||||
#[inline]
|
#[inline]
|
||||||
|
pub fn root_as_universe(buf: &[u8]) -> Result<Universe<'_>, ::flatbuffers::InvalidFlatbuffer> {
|
||||||
|
::flatbuffers::root::<Universe>(buf)
|
||||||
|
}
|
||||||
|
|
||||||
/// Verifies that a buffer of bytes contains a size prefixed
|
/// Verifies that a buffer of bytes contains a size prefixed
|
||||||
/// `Universe` and returns it.
|
/// `Universe` and returns it.
|
||||||
/// Note that verification is still experimental and may not
|
/// Note that verification is still experimental and may not
|
||||||
/// catch every error, or be maximally performant. For the
|
/// catch every error, or be maximally performant. For the
|
||||||
/// previous, unchecked, behavior use
|
/// previous, unchecked, behavior use
|
||||||
/// `size_prefixed_root_as_universe_unchecked`.
|
/// `size_prefixed_root_as_universe_unchecked`.
|
||||||
pub fn size_prefixed_root_as_universe(buf: &[u8]) -> Result<Universe, flatbuffers::InvalidFlatbuffer> {
|
|
||||||
flatbuffers::size_prefixed_root::<Universe>(buf)
|
|
||||||
}
|
|
||||||
#[inline]
|
#[inline]
|
||||||
|
pub fn size_prefixed_root_as_universe(buf: &[u8]) -> Result<Universe<'_>, ::flatbuffers::InvalidFlatbuffer> {
|
||||||
|
::flatbuffers::size_prefixed_root::<Universe>(buf)
|
||||||
|
}
|
||||||
|
|
||||||
/// Verifies, with the given options, that a buffer of bytes
|
/// Verifies, with the given options, that a buffer of bytes
|
||||||
/// contains a `Universe` and returns it.
|
/// contains a `Universe` and returns it.
|
||||||
/// Note that verification is still experimental and may not
|
/// Note that verification is still experimental and may not
|
||||||
/// catch every error, or be maximally performant. For the
|
/// catch every error, or be maximally performant. For the
|
||||||
/// previous, unchecked, behavior use
|
/// previous, unchecked, behavior use
|
||||||
/// `root_as_universe_unchecked`.
|
/// `root_as_universe_unchecked`.
|
||||||
pub fn root_as_universe_with_opts<'b, 'o>(
|
|
||||||
opts: &'o flatbuffers::VerifierOptions,
|
|
||||||
buf: &'b [u8],
|
|
||||||
) -> Result<Universe<'b>, flatbuffers::InvalidFlatbuffer> {
|
|
||||||
flatbuffers::root_with_opts::<Universe<'b>>(opts, buf)
|
|
||||||
}
|
|
||||||
#[inline]
|
#[inline]
|
||||||
|
pub fn root_as_universe_with_opts<'b, 'o>(
|
||||||
|
opts: &'o ::flatbuffers::VerifierOptions,
|
||||||
|
buf: &'b [u8],
|
||||||
|
) -> Result<Universe<'b>, ::flatbuffers::InvalidFlatbuffer> {
|
||||||
|
::flatbuffers::root_with_opts::<Universe<'b>>(opts, buf)
|
||||||
|
}
|
||||||
|
|
||||||
/// Verifies, with the given verifier options, that a buffer of
|
/// Verifies, with the given verifier options, that a buffer of
|
||||||
/// bytes contains a size prefixed `Universe` and returns
|
/// bytes contains a size prefixed `Universe` and returns
|
||||||
/// it. Note that verification is still experimental and may not
|
/// it. Note that verification is still experimental and may not
|
||||||
/// catch every error, or be maximally performant. For the
|
/// catch every error, or be maximally performant. For the
|
||||||
/// previous, unchecked, behavior use
|
/// previous, unchecked, behavior use
|
||||||
/// `root_as_universe_unchecked`.
|
/// `root_as_universe_unchecked`.
|
||||||
pub fn size_prefixed_root_as_universe_with_opts<'b, 'o>(
|
|
||||||
opts: &'o flatbuffers::VerifierOptions,
|
|
||||||
buf: &'b [u8],
|
|
||||||
) -> Result<Universe<'b>, flatbuffers::InvalidFlatbuffer> {
|
|
||||||
flatbuffers::size_prefixed_root_with_opts::<Universe<'b>>(opts, buf)
|
|
||||||
}
|
|
||||||
#[inline]
|
#[inline]
|
||||||
|
pub fn size_prefixed_root_as_universe_with_opts<'b, 'o>(
|
||||||
|
opts: &'o ::flatbuffers::VerifierOptions,
|
||||||
|
buf: &'b [u8],
|
||||||
|
) -> Result<Universe<'b>, ::flatbuffers::InvalidFlatbuffer> {
|
||||||
|
::flatbuffers::size_prefixed_root_with_opts::<Universe<'b>>(opts, buf)
|
||||||
|
}
|
||||||
|
|
||||||
/// Assumes, without verification, that a buffer of bytes contains a Universe and returns it.
|
/// Assumes, without verification, that a buffer of bytes contains a Universe and returns it.
|
||||||
/// # Safety
|
/// # Safety
|
||||||
/// Callers must trust the given bytes do indeed contain a valid `Universe`.
|
/// Callers must trust the given bytes do indeed contain a valid `Universe`.
|
||||||
pub unsafe fn root_as_universe_unchecked(buf: &[u8]) -> Universe {
|
|
||||||
flatbuffers::root_unchecked::<Universe>(buf)
|
|
||||||
}
|
|
||||||
#[inline]
|
#[inline]
|
||||||
|
pub unsafe fn root_as_universe_unchecked(buf: &[u8]) -> Universe<'_> {
|
||||||
|
unsafe { ::flatbuffers::root_unchecked::<Universe>(buf) }
|
||||||
|
}
|
||||||
|
|
||||||
/// Assumes, without verification, that a buffer of bytes contains a size prefixed Universe and returns it.
|
/// Assumes, without verification, that a buffer of bytes contains a size prefixed Universe and returns it.
|
||||||
/// # Safety
|
/// # Safety
|
||||||
/// Callers must trust the given bytes do indeed contain a valid size prefixed `Universe`.
|
/// Callers must trust the given bytes do indeed contain a valid size prefixed `Universe`.
|
||||||
pub unsafe fn size_prefixed_root_as_universe_unchecked(buf: &[u8]) -> Universe {
|
|
||||||
flatbuffers::size_prefixed_root_unchecked::<Universe>(buf)
|
|
||||||
}
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn finish_universe_buffer<'a, 'b, A: flatbuffers::Allocator + 'a>(
|
pub unsafe fn size_prefixed_root_as_universe_unchecked(buf: &[u8]) -> Universe<'_> {
|
||||||
fbb: &'b mut flatbuffers::FlatBufferBuilder<'a, A>,
|
unsafe { ::flatbuffers::size_prefixed_root_unchecked::<Universe>(buf) }
|
||||||
root: flatbuffers::WIPOffset<Universe<'a>>) {
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
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);
|
fbb.finish(root, None);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
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>>) {
|
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);
|
fbb.finish_size_prefixed(root, None);
|
||||||
}
|
}
|
||||||
} // pub mod goldens
|
} // pub mod goldens
|
||||||
} // pub mod flatbuffers
|
} // pub mod flatbuffers
|
||||||
|
|
||||||
|
|||||||
@@ -2,11 +2,15 @@
|
|||||||
// swiftlint:disable all
|
// swiftlint:disable all
|
||||||
// swiftformat:disable all
|
// swiftformat:disable all
|
||||||
|
|
||||||
|
#if canImport(Common)
|
||||||
|
import Common
|
||||||
|
#endif
|
||||||
|
|
||||||
import FlatBuffers
|
import FlatBuffers
|
||||||
|
|
||||||
public struct flatbuffers_goldens_Galaxy: FlatBufferObject, Verifiable {
|
public struct flatbuffers_goldens_Galaxy: FlatBufferTable, FlatbuffersVectorInitializable, Verifiable {
|
||||||
|
|
||||||
static func validateVersion() { FlatBuffersVersion_25_2_10() }
|
static func validateVersion() { FlatBuffersVersion_25_12_19() }
|
||||||
public var __buffer: ByteBuffer! { return _accessor.bb }
|
public var __buffer: ByteBuffer! { return _accessor.bb }
|
||||||
private var _accessor: Table
|
private var _accessor: Table
|
||||||
|
|
||||||
@@ -39,9 +43,9 @@ public struct flatbuffers_goldens_Galaxy: FlatBufferObject, Verifiable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public struct flatbuffers_goldens_Universe: FlatBufferObject, Verifiable {
|
public struct flatbuffers_goldens_Universe: FlatBufferTable, FlatbuffersVectorInitializable, Verifiable {
|
||||||
|
|
||||||
static func validateVersion() { FlatBuffersVersion_25_2_10() }
|
static func validateVersion() { FlatBuffersVersion_25_12_19() }
|
||||||
public var __buffer: ByteBuffer! { return _accessor.bb }
|
public var __buffer: ByteBuffer! { return _accessor.bb }
|
||||||
private var _accessor: Table
|
private var _accessor: Table
|
||||||
|
|
||||||
@@ -56,9 +60,7 @@ public struct flatbuffers_goldens_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 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 galaxies: FlatbufferVector<flatbuffers_goldens_Galaxy> { return _accessor.vector(at: VTOFFSET.galaxies.v, byteSize: 4) }
|
||||||
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) -> 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 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 add(age: Double, _ fbb: inout FlatBufferBuilder) { fbb.add(element: age, def: 0.0, at: VTOFFSET.age.p) }
|
||||||
public static func addVectorOf(galaxies: Offset, _ fbb: inout FlatBufferBuilder) { fbb.add(offset: galaxies, at: VTOFFSET.galaxies.p) }
|
public static func addVectorOf(galaxies: Offset, _ fbb: inout FlatBufferBuilder) { fbb.add(offset: galaxies, at: VTOFFSET.galaxies.p) }
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
|
|
||||||
import * as flatbuffers from 'flatbuffers';
|
import * as flatbuffers from 'flatbuffers';
|
||||||
|
|
||||||
import { Galaxy } from '../../flatbuffers/goldens/galaxy.js';
|
import { Galaxy } from './galaxy.js';
|
||||||
|
|
||||||
|
|
||||||
export class Universe {
|
export class Universe {
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
GRPC implementation and test
|
GRPC implementation and test
|
||||||
============================
|
|
||||||
|
|
||||||
NOTE: files in `src/` are shared with the GRPC project, and maintained there
|
NOTE: files in `src/` are shared with the GRPC project, and maintained there
|
||||||
(any changes should be submitted to GRPC instead). These files are copied
|
(any changes should be submitted to GRPC instead). These files are copied
|
||||||
@@ -40,3 +39,63 @@ For Bazel users:
|
|||||||
```shell
|
```shell
|
||||||
$bazel test tests/...
|
$bazel test tests/...
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## C++ Callback API Generation
|
||||||
|
|
||||||
|
FlatBuffers gRPC C++ code generation now optionally supports the modern gRPC Callback API.
|
||||||
|
|
||||||
|
To enable generation of a `CallbackService` skeleton alongside the existing `Service` and async mixins, invoke `flatc` with both `--grpc` and `--grpc-callback-api`:
|
||||||
|
|
||||||
|
```shell
|
||||||
|
flatc --cpp --grpc --grpc-callback-api your_service.fbs
|
||||||
|
```
|
||||||
|
|
||||||
|
This adds (guarded by `#if defined(GRPC_CALLBACK_API_NONEXPERIMENTAL)`) a class:
|
||||||
|
|
||||||
|
```cpp
|
||||||
|
class YourService::CallbackService : public ::grpc::Service { /* reactor virtuals */ };
|
||||||
|
```
|
||||||
|
|
||||||
|
Each RPC shape maps to the appropriate reactor return type:
|
||||||
|
|
||||||
|
- Unary -> `::grpc::ServerUnaryReactor*` Method(...)
|
||||||
|
- Client streaming -> `::grpc::ServerReadReactor<Request>*`
|
||||||
|
- Server streaming -> `::grpc::ServerWriteReactor<Response>*`
|
||||||
|
- Bidi streaming -> `::grpc::ServerBidiReactor<Request, Response>*`
|
||||||
|
|
||||||
|
Default generated implementations return `nullptr`; override in your derived class and return a reactor instance you manage (see gRPC docs for lifecycle patterns).
|
||||||
|
|
||||||
|
If your gRPC library predates the stable callback API macro, the code inside the guard will be skipped (no breaking changes). Ensure you build against a recent gRPC (1.38+; verify current minimum in grpc repo) to use this feature.
|
||||||
|
|
||||||
|
### Client Callback Stubs
|
||||||
|
|
||||||
|
When `--grpc-callback-api` is supplied, the generated C++ client stub gains native callback / reactor based async methods in addition to the existing synchronous / generic async flavors, guarded by the same macro. For each RPC named `Foo`:
|
||||||
|
|
||||||
|
Unary:
|
||||||
|
|
||||||
|
```
|
||||||
|
void async_Foo(::grpc::ClientContext*, const Request&, Response*, std::function<void(::grpc::Status)>);
|
||||||
|
void async_Foo(::grpc::ClientContext*, const Request&, Response*, ::grpc::ClientUnaryReactor*);
|
||||||
|
```
|
||||||
|
|
||||||
|
Client streaming:
|
||||||
|
|
||||||
|
```
|
||||||
|
::grpc::ClientWriteReactor<Request>* async_Foo(::grpc::ClientContext*, Response*, ::grpc::ClientWriteReactor<Request>*);
|
||||||
|
```
|
||||||
|
|
||||||
|
Server streaming:
|
||||||
|
|
||||||
|
```
|
||||||
|
::grpc::ClientReadReactor<Response>* async_Foo(::grpc::ClientContext*, const Request&, ::grpc::ClientReadReactor<Response>*);
|
||||||
|
```
|
||||||
|
|
||||||
|
Bidirectional streaming:
|
||||||
|
|
||||||
|
```
|
||||||
|
::grpc::ClientBidiReactor<Request, Response>* async_Foo(::grpc::ClientContext*, ::grpc::ClientBidiReactor<Request, Response>*);
|
||||||
|
```
|
||||||
|
|
||||||
|
These map directly onto the native gRPC callback API factories (e.g. `CallbackUnaryCall`, `ClientCallbackWriterFactory::Create`, etc.) and do not spawn threads. Override the appropriate reactor callbacks per gRPC's documentation to drive I/O.
|
||||||
|
|
||||||
|
If your build uses an older gRPC lacking the non-experimental macro, these symbols will not be emitted, preserving backwards compatibility.
|
||||||
|
|||||||
16
grpc/examples/greeter_v2.fbs
Normal file
16
grpc/examples/greeter_v2.fbs
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
namespace models;
|
||||||
|
|
||||||
|
table HelloResponse {
|
||||||
|
message:string;
|
||||||
|
}
|
||||||
|
|
||||||
|
table HelloRequest {
|
||||||
|
name:string;
|
||||||
|
}
|
||||||
|
|
||||||
|
rpc_service Greeter {
|
||||||
|
Get(HelloRequest):HelloResponse;
|
||||||
|
Collect(HelloRequest):HelloResponse (streaming: "client");
|
||||||
|
Expand(HelloRequest):HelloResponse (streaming: "server");
|
||||||
|
Update(HelloRequest):HelloResponse (streaming: "bidi");
|
||||||
|
}
|
||||||
@@ -1,31 +1,36 @@
|
|||||||
import sys
|
|
||||||
import argparse
|
import argparse
|
||||||
|
import sys
|
||||||
import grpc
|
import grpc
|
||||||
|
|
||||||
sys.path.insert(0, '../../../../../flatbuffers/python')
|
sys.path.insert(0, "../../../../../flatbuffers/python")
|
||||||
|
|
||||||
import flatbuffers
|
import flatbuffers
|
||||||
from models import HelloReply, HelloRequest, greeter_grpc_fb
|
from models import HelloReply, HelloRequest, greeter_grpc_fb
|
||||||
|
|
||||||
parser = argparse.ArgumentParser()
|
parser = argparse.ArgumentParser()
|
||||||
parser.add_argument("port", help="server port to connect to", default=3000)
|
parser.add_argument("port", help="server port to connect to", default=3000)
|
||||||
parser.add_argument("name", help="name to be sent to server", default="flatbuffers")
|
parser.add_argument(
|
||||||
|
"name", help="name to be sent to server", default="flatbuffers"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def say_hello(stub, hello_request):
|
def say_hello(stub, hello_request):
|
||||||
reply = stub.SayHello(hello_request)
|
reply = stub.SayHello(hello_request)
|
||||||
r = HelloReply.HelloReply.GetRootAs(reply)
|
r = HelloReply.HelloReply.GetRootAs(reply)
|
||||||
print(r.Message())
|
print(r.Message())
|
||||||
|
|
||||||
|
|
||||||
def say_many_hellos(stub, hello_request):
|
def say_many_hellos(stub, hello_request):
|
||||||
greetings = stub.SayManyHellos(hello_request)
|
greetings = stub.SayManyHellos(hello_request)
|
||||||
for greeting in greetings:
|
for greeting in greetings:
|
||||||
r = HelloReply.HelloReply.GetRootAs(greeting)
|
r = HelloReply.HelloReply.GetRootAs(greeting)
|
||||||
print(r.Message())
|
print(r.Message())
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
with grpc.insecure_channel('localhost:' + args.port) as channel:
|
with grpc.insecure_channel("localhost:" + args.port) as channel:
|
||||||
builder = flatbuffers.Builder()
|
builder = flatbuffers.Builder()
|
||||||
ind = builder.CreateString(args.name)
|
ind = builder.CreateString(args.name)
|
||||||
HelloRequest.HelloRequestStart(builder)
|
HelloRequest.HelloRequestStart(builder)
|
||||||
@@ -37,4 +42,5 @@ def main():
|
|||||||
say_hello(stub, output)
|
say_hello(stub, output)
|
||||||
say_many_hellos(stub, output)
|
say_many_hellos(stub, output)
|
||||||
|
|
||||||
|
|
||||||
main()
|
main()
|
||||||
@@ -2,30 +2,29 @@
|
|||||||
|
|
||||||
import flatbuffers
|
import flatbuffers
|
||||||
import grpc
|
import grpc
|
||||||
|
|
||||||
from models.HelloReply import HelloReply
|
from models.HelloReply import HelloReply
|
||||||
from models.HelloRequest import HelloRequest
|
from models.HelloRequest import HelloRequest
|
||||||
|
|
||||||
|
|
||||||
class GreeterStub(object):
|
class GreeterStub(object):
|
||||||
'''Interface exported by the server.'''
|
"""Interface exported by the server."""
|
||||||
|
|
||||||
def __init__(self, channel):
|
def __init__(self, channel):
|
||||||
'''Constructor.
|
"""Constructor.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
channel: A grpc.Channel.
|
channel: A grpc.Channel.
|
||||||
'''
|
"""
|
||||||
|
|
||||||
self.SayHello = channel.unary_unary(
|
self.SayHello = channel.unary_unary(method='/models.Greeter/SayHello')
|
||||||
method='/models.Greeter/SayHello')
|
|
||||||
|
|
||||||
self.SayManyHellos = channel.unary_stream(
|
self.SayManyHellos = channel.unary_stream(
|
||||||
method='/models.Greeter/SayManyHellos')
|
method='/models.Greeter/SayManyHellos'
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class GreeterServicer(object):
|
class GreeterServicer(object):
|
||||||
'''Interface exported by the server.'''
|
"""Interface exported by the server."""
|
||||||
|
|
||||||
def SayHello(self, request, context):
|
def SayHello(self, request, context):
|
||||||
context.set_code(grpc.StatusCode.UNIMPLEMENTED)
|
context.set_code(grpc.StatusCode.UNIMPLEMENTED)
|
||||||
@@ -40,15 +39,14 @@ class GreeterServicer(object):
|
|||||||
|
|
||||||
def add_GreeterServicer_to_server(servicer, server):
|
def add_GreeterServicer_to_server(servicer, server):
|
||||||
rpc_method_handlers = {
|
rpc_method_handlers = {
|
||||||
'SayHello': grpc.unary_unary_rpc_method_handler(
|
'SayHello': grpc.unary_unary_rpc_method_handler(servicer.SayHello),
|
||||||
servicer.SayHello),
|
|
||||||
'SayManyHellos': grpc.unary_stream_rpc_method_handler(
|
'SayManyHellos': grpc.unary_stream_rpc_method_handler(
|
||||||
servicer.SayManyHellos),
|
servicer.SayManyHellos
|
||||||
|
),
|
||||||
}
|
}
|
||||||
|
|
||||||
generic_handler = grpc.method_handlers_generic_handler(
|
generic_handler = grpc.method_handlers_generic_handler(
|
||||||
'models.Greeter', rpc_method_handlers)
|
'models.Greeter', rpc_method_handlers
|
||||||
|
)
|
||||||
|
|
||||||
server.add_generic_rpc_handlers((generic_handler,))
|
server.add_generic_rpc_handlers((generic_handler,))
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,52 +1,54 @@
|
|||||||
# Generated by the gRPC Python protocol compiler plugin. DO NOT EDIT!
|
# Generated by the gRPC FlatBuffers compiler. DO NOT EDIT!
|
||||||
|
|
||||||
|
import flatbuffers
|
||||||
import grpc
|
import grpc
|
||||||
|
|
||||||
|
from models.HelloReply import HelloReply
|
||||||
|
from models.HelloRequest import HelloRequest
|
||||||
|
|
||||||
|
|
||||||
class GreeterStub(object):
|
class GreeterStub(object):
|
||||||
""" Interface exported by the server. """
|
'''Interface exported by the server.'''
|
||||||
|
|
||||||
def __init__(self, channel):
|
def __init__(self, channel):
|
||||||
""" Constructor.
|
'''Constructor.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
channel: A grpc.Channel.
|
channel: A grpc.Channel.
|
||||||
"""
|
'''
|
||||||
|
|
||||||
self.SayHello = channel.unary_unary(
|
self.SayHello = channel.unary_unary(
|
||||||
"/models.Greeter/SayHello"
|
method='/models.Greeter/SayHello')
|
||||||
)
|
|
||||||
|
|
||||||
self.SayManyHellos = channel.unary_stream(
|
self.SayManyHellos = channel.unary_stream(
|
||||||
"/models.Greeter/SayManyHellos"
|
method='/models.Greeter/SayManyHellos')
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
class GreeterServicer(object):
|
class GreeterServicer(object):
|
||||||
""" Interface exported by the server. """
|
'''Interface exported by the server.'''
|
||||||
|
|
||||||
def SayHello(self, request, context):
|
def SayHello(self, request, context):
|
||||||
context.set_code(grpc.StatusCode.UNIMPLEMENTED)
|
context.set_code(grpc.StatusCode.UNIMPLEMENTED)
|
||||||
context.set_details('Method not implemented!')
|
context.set_details('Method not implemented!')
|
||||||
raise NotImplementedError('Method not implemented!')
|
raise NotImplementedError('Method not implemented!')
|
||||||
|
|
||||||
|
|
||||||
def SayManyHellos(self, request, context):
|
def SayManyHellos(self, request, context):
|
||||||
context.set_code(grpc.StatusCode.UNIMPLEMENTED)
|
context.set_code(grpc.StatusCode.UNIMPLEMENTED)
|
||||||
context.set_details('Method not implemented!')
|
context.set_details('Method not implemented!')
|
||||||
raise NotImplementedError('Method not implemented!')
|
raise NotImplementedError('Method not implemented!')
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def add_GreeterServicer_to_server(servicer, server):
|
def add_GreeterServicer_to_server(servicer, server):
|
||||||
rpc_method_handlers = {
|
rpc_method_handlers = {
|
||||||
'SayHello': grpc.unary_unary_rpc_method_handler(
|
'SayHello': grpc.unary_unary_rpc_method_handler(
|
||||||
servicer.SayHello
|
servicer.SayHello),
|
||||||
),
|
|
||||||
'SayManyHellos': grpc.unary_stream_rpc_method_handler(
|
'SayManyHellos': grpc.unary_stream_rpc_method_handler(
|
||||||
servicer.SayManyHellos
|
servicer.SayManyHellos),
|
||||||
),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
generic_handler = grpc.method_handlers_generic_handler(
|
generic_handler = grpc.method_handlers_generic_handler(
|
||||||
'models.Greeter', rpc_method_handlers)
|
'models.Greeter', rpc_method_handlers)
|
||||||
|
|
||||||
server.add_generic_rpc_handlers((generic_handler,))
|
server.add_generic_rpc_handlers((generic_handler,))
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
|
import argparse
|
||||||
from concurrent import futures
|
from concurrent import futures
|
||||||
import sys
|
import sys
|
||||||
import argparse
|
|
||||||
import grpc
|
import grpc
|
||||||
|
|
||||||
sys.path.insert(0, '../../../../../flatbuffers/python')
|
sys.path.insert(0, "../../../../../flatbuffers/python")
|
||||||
|
|
||||||
import flatbuffers
|
import flatbuffers
|
||||||
from models import HelloReply, HelloRequest, greeter_grpc_fb
|
from models import HelloReply, HelloRequest, greeter_grpc_fb
|
||||||
@@ -11,6 +11,7 @@ from models import HelloReply, HelloRequest, greeter_grpc_fb
|
|||||||
parser = argparse.ArgumentParser()
|
parser = argparse.ArgumentParser()
|
||||||
parser.add_argument("port", help="server on port", default=3000)
|
parser.add_argument("port", help="server on port", default=3000)
|
||||||
|
|
||||||
|
|
||||||
def build_reply(message):
|
def build_reply(message):
|
||||||
builder = flatbuffers.Builder()
|
builder = flatbuffers.Builder()
|
||||||
ind = builder.CreateString(message)
|
ind = builder.CreateString(message)
|
||||||
@@ -20,6 +21,7 @@ def build_reply(message):
|
|||||||
builder.Finish(root)
|
builder.Finish(root)
|
||||||
return bytes(builder.Output())
|
return bytes(builder.Output())
|
||||||
|
|
||||||
|
|
||||||
class GreeterServicer(greeter_grpc_fb.GreeterServicer):
|
class GreeterServicer(greeter_grpc_fb.GreeterServicer):
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
@@ -30,7 +32,7 @@ class GreeterServicer(greeter_grpc_fb.GreeterServicer):
|
|||||||
reply = "Unknown"
|
reply = "Unknown"
|
||||||
if r.Name():
|
if r.Name():
|
||||||
reply = r.Name()
|
reply = r.Name()
|
||||||
return build_reply("welcome " + reply.decode('UTF-8'))
|
return build_reply("welcome " + reply.decode("UTF-8"))
|
||||||
|
|
||||||
def SayManyHellos(self, request, context):
|
def SayManyHellos(self, request, context):
|
||||||
r = HelloRequest.HelloRequest().GetRootAs(request, 0)
|
r = HelloRequest.HelloRequest().GetRootAs(request, 0)
|
||||||
@@ -40,18 +42,17 @@ class GreeterServicer(greeter_grpc_fb.GreeterServicer):
|
|||||||
|
|
||||||
for greeting in self.greetings:
|
for greeting in self.greetings:
|
||||||
print(type(reply))
|
print(type(reply))
|
||||||
yield build_reply(greeting + " " + reply.decode('UTF-8'))
|
yield build_reply(greeting + " " + reply.decode("UTF-8"))
|
||||||
|
|
||||||
|
|
||||||
def serve():
|
def serve():
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
server = grpc.server(futures.ThreadPoolExecutor(max_workers=10))
|
server = grpc.server(futures.ThreadPoolExecutor(max_workers=10))
|
||||||
greeter_grpc_fb.add_GreeterServicer_to_server(
|
greeter_grpc_fb.add_GreeterServicer_to_server(GreeterServicer(), server)
|
||||||
GreeterServicer(), server
|
server.add_insecure_port("[::]:" + args.port)
|
||||||
)
|
|
||||||
server.add_insecure_port('[::]:' + args.port)
|
|
||||||
server.start()
|
server.start()
|
||||||
server.wait_for_termination()
|
server.wait_for_termination()
|
||||||
|
|
||||||
if __name__ == '__main__':
|
|
||||||
|
if __name__ == "__main__":
|
||||||
serve()
|
serve()
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
// swift-tools-version:5.9
|
// swift-tools-version:6.2
|
||||||
/*
|
/*
|
||||||
* Copyright 2020 Google Inc. All rights reserved.
|
* Copyright 2020 Google Inc. All rights reserved.
|
||||||
*
|
*
|
||||||
@@ -20,39 +20,43 @@ import PackageDescription
|
|||||||
let package = Package(
|
let package = Package(
|
||||||
name: "Greeter",
|
name: "Greeter",
|
||||||
platforms: [
|
platforms: [
|
||||||
.iOS(.v11),
|
.iOS(.v18),
|
||||||
.macOS(.v10_14),
|
.macOS(.v15),
|
||||||
],
|
],
|
||||||
dependencies: [
|
dependencies: [
|
||||||
.package(path: "../../../../swift"),
|
.package(path: "../../../.."),
|
||||||
.package(url: "https://github.com/grpc/grpc-swift.git", from: "1.0.0"),
|
.package(url: "https://github.com/grpc/grpc-swift-2.git", from: "2.0.0"),
|
||||||
|
.package(
|
||||||
|
url: "https://github.com/grpc/grpc-swift-nio-transport.git",
|
||||||
|
from: "2.0.0"),
|
||||||
|
.package(
|
||||||
|
url: "https://github.com/apple/swift-argument-parser.git",
|
||||||
|
from: "1.5.0"),
|
||||||
],
|
],
|
||||||
targets: [
|
targets: [
|
||||||
// Targets are the basic building blocks of a package. A target can define a module or a test suite.
|
// Targets are the basic building blocks of a package. A target can define a module or a test suite.
|
||||||
// Targets can depend on other targets in this package, and on products in packages which this package depends on.
|
// Targets can depend on other targets in this package, and on products in packages which this package depends on.
|
||||||
.target(
|
.target(
|
||||||
name: "Model",
|
name: "Models",
|
||||||
dependencies: [
|
dependencies: [
|
||||||
"GRPC",
|
.product(name: "FlatBuffers", package: "flatbuffers"),
|
||||||
"FlatBuffers",
|
.product(name: "GRPCCore", package: "grpc-swift-2"),
|
||||||
],
|
.product(
|
||||||
path: "Sources/Model"),
|
name: "GRPCNIOTransportHTTP2",
|
||||||
|
package: "grpc-swift-nio-transport"),
|
||||||
|
]),
|
||||||
|
|
||||||
// Client for the Greeter example
|
// Client for the Greeter example
|
||||||
.target(
|
.executableTarget(
|
||||||
name: "Client",
|
name: "Commands",
|
||||||
dependencies: [
|
dependencies: [
|
||||||
"GRPC",
|
.product(name: "GRPCCore", package: "grpc-swift-2"),
|
||||||
"Model",
|
.product(
|
||||||
],
|
name: "GRPCNIOTransportHTTP2",
|
||||||
path: "Sources/client"),
|
package: "grpc-swift-nio-transport"),
|
||||||
|
.product(
|
||||||
// Server for the Greeter example
|
name: "ArgumentParser",
|
||||||
.target(
|
package: "swift-argument-parser"),
|
||||||
name: "Server",
|
"Models",
|
||||||
dependencies: [
|
]),
|
||||||
"GRPC",
|
|
||||||
"Model",
|
|
||||||
],
|
|
||||||
path: "Sources/server"),
|
|
||||||
])
|
])
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2018 Google Inc. All rights reserved.
|
* Copyright 2024 Google Inc. All rights reserved.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -14,22 +14,15 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <cstdlib>
|
import ArgumentParser
|
||||||
#include <iostream>
|
|
||||||
#include "flatbuffers/util.h"
|
|
||||||
|
|
||||||
// Test to validate Conan package generated
|
let port = 3000
|
||||||
|
|
||||||
int main(int /*argc*/, const char * /*argv*/ []) {
|
@main
|
||||||
|
struct GreeterCommand: AsyncParsableCommand {
|
||||||
const std::string filename("conanbuildinfo.cmake");
|
static let configuration = CommandConfiguration(
|
||||||
|
commandName: "greeter",
|
||||||
if (flatbuffers::FileExists(filename.c_str())) {
|
abstract: "A multi-tool to run an echo server and execute RPCs against it.",
|
||||||
std::cout << "File " << filename << " exists.\n";
|
subcommands: [ServerCommand.self, ClientCommand.self])
|
||||||
} else {
|
|
||||||
std::cout << "File " << filename << " does not exist.\n";
|
|
||||||
return EXIT_FAILURE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return EXIT_SUCCESS;
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,121 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2024 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 FlatBuffers
|
||||||
|
import GRPCCore
|
||||||
|
import Models
|
||||||
|
|
||||||
|
struct GreeterService: models_Greeter.SimpleServiceProtocol {
|
||||||
|
func Get(
|
||||||
|
request: GRPCMessage<models_HelloResponse>,
|
||||||
|
context: GRPCCore
|
||||||
|
.ServerContext) async throws -> GRPCMessage<models_HelloResponse>
|
||||||
|
{
|
||||||
|
let model = try request.decode()
|
||||||
|
print("## GreeterService.Get: \(model.message)")
|
||||||
|
|
||||||
|
var builder = FlatBufferBuilder(initialSize: 128)
|
||||||
|
let off = builder.create(string: "Hello \(model.message ?? "Unknown")")
|
||||||
|
let root = models_HelloResponse.createHelloResponse(
|
||||||
|
&builder,
|
||||||
|
messageOffset: off)
|
||||||
|
builder.finish(offset: root)
|
||||||
|
return try GRPCMessage<models_HelloResponse>(builder: &builder)
|
||||||
|
}
|
||||||
|
|
||||||
|
func Collect(
|
||||||
|
request: GRPCCore.RPCAsyncSequence<
|
||||||
|
GRPCMessage<models_HelloResponse>,
|
||||||
|
any Swift.Error
|
||||||
|
>,
|
||||||
|
context: GRPCCore
|
||||||
|
.ServerContext) async throws -> GRPCMessage<models_HelloResponse>
|
||||||
|
{
|
||||||
|
let messages: [String] = try await request
|
||||||
|
.reduce(into: []) { array, message in
|
||||||
|
let model = try message.decode()
|
||||||
|
return array.append(model.message ?? "Unknown")
|
||||||
|
}
|
||||||
|
|
||||||
|
let joined = messages.joined(separator: ", ")
|
||||||
|
print("## GreeterService.Collect: \(joined)")
|
||||||
|
|
||||||
|
var builder = FlatBufferBuilder(initialSize: 128)
|
||||||
|
let off = builder.create(string: "Hello \(joined)")
|
||||||
|
let root = models_HelloResponse.createHelloResponse(
|
||||||
|
&builder,
|
||||||
|
messageOffset: off)
|
||||||
|
builder.finish(offset: root)
|
||||||
|
return try GRPCMessage<models_HelloResponse>(builder: &builder)
|
||||||
|
}
|
||||||
|
|
||||||
|
func Expand(
|
||||||
|
request: GRPCMessage<models_HelloResponse>,
|
||||||
|
response: GRPCCore.RPCWriter<GRPCMessage<models_HelloResponse>>,
|
||||||
|
context: GRPCCore.ServerContext) async throws
|
||||||
|
{
|
||||||
|
|
||||||
|
let model = try request.decode()
|
||||||
|
print("## GreeterService.Expand: \(model.message)")
|
||||||
|
|
||||||
|
let message = model.message ?? "Unknown"
|
||||||
|
let stream = AsyncThrowingStream<
|
||||||
|
GRPCMessage<models_HelloResponse>,
|
||||||
|
Error
|
||||||
|
> { continuation in
|
||||||
|
var builder = FlatBufferBuilder(initialSize: 128)
|
||||||
|
for char in message {
|
||||||
|
let off = builder.create(string: "\(char)")
|
||||||
|
let root = models_HelloResponse.createHelloResponse(
|
||||||
|
&builder,
|
||||||
|
messageOffset: off)
|
||||||
|
builder.finish(offset: root)
|
||||||
|
|
||||||
|
do {
|
||||||
|
continuation
|
||||||
|
.yield(try GRPCMessage<models_HelloResponse>(builder: &builder))
|
||||||
|
} catch {
|
||||||
|
continuation.finish(throwing: error)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
continuation.finish()
|
||||||
|
}
|
||||||
|
try await response.write(contentsOf: stream)
|
||||||
|
}
|
||||||
|
|
||||||
|
func Update(
|
||||||
|
request: GRPCCore.RPCAsyncSequence<
|
||||||
|
GRPCMessage<models_HelloResponse>,
|
||||||
|
any Swift.Error
|
||||||
|
>,
|
||||||
|
response: GRPCCore.RPCWriter<GRPCMessage<models_HelloResponse>>,
|
||||||
|
context: GRPCCore.ServerContext) async throws
|
||||||
|
{
|
||||||
|
for try await message in request {
|
||||||
|
let model = try message.decode()
|
||||||
|
print("## GreeterService.Update: \(model.message)")
|
||||||
|
var builder = FlatBufferBuilder(initialSize: 128)
|
||||||
|
let off = builder.create(string: "Hello \(model.message ?? "Unknown")")
|
||||||
|
let root = models_HelloResponse.createHelloResponse(
|
||||||
|
&builder,
|
||||||
|
messageOffset: off)
|
||||||
|
builder.finish(offset: root)
|
||||||
|
try await response
|
||||||
|
.write(try GRPCMessage<models_HelloResponse>(builder: &builder))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,140 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2024 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 ArgumentParser
|
||||||
|
import FlatBuffers
|
||||||
|
import GRPCCore
|
||||||
|
import GRPCNIOTransportHTTP2
|
||||||
|
import Models
|
||||||
|
|
||||||
|
enum ClientRequest: String, ExpressibleByArgument {
|
||||||
|
case get, expand, collect, update
|
||||||
|
}
|
||||||
|
|
||||||
|
struct ClientCommand: AsyncParsableCommand {
|
||||||
|
static let configuration = CommandConfiguration(
|
||||||
|
commandName: "client")
|
||||||
|
|
||||||
|
@Option(help: "Name to send to the server")
|
||||||
|
var name: String
|
||||||
|
|
||||||
|
@Option(help: "request type")
|
||||||
|
var request: ClientRequest
|
||||||
|
|
||||||
|
func run() async throws {
|
||||||
|
try await withGRPCClient(
|
||||||
|
transport: .http2NIOPosix(
|
||||||
|
target: .dns(host: "localhost", port: port),
|
||||||
|
transportSecurity: .plaintext))
|
||||||
|
{
|
||||||
|
let client = models_Greeter.Client(wrapping: $0)
|
||||||
|
|
||||||
|
switch request {
|
||||||
|
case .get: try await get(client: client)
|
||||||
|
case .expand: try await expand(client: client)
|
||||||
|
case .collect: try await collect(client: client)
|
||||||
|
case .update: try await update(client: client)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func get(
|
||||||
|
client: models_Greeter
|
||||||
|
.Client<HTTP2ClientTransport.Posix>) async throws
|
||||||
|
{
|
||||||
|
for _ in 0..<3 {
|
||||||
|
var builder = FlatBufferBuilder(initialSize: 64)
|
||||||
|
let off = builder.create(string: name)
|
||||||
|
let root = models_HelloRequest.createHelloRequest(
|
||||||
|
&builder,
|
||||||
|
nameOffset: off)
|
||||||
|
builder.finish(offset: root)
|
||||||
|
|
||||||
|
let response = try await client
|
||||||
|
.Get(GRPCMessage(builder: &builder))
|
||||||
|
let message = try? response.decode().message
|
||||||
|
print("get message: \(message ?? "nil")")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func expand(
|
||||||
|
client: models_Greeter
|
||||||
|
.Client<HTTP2ClientTransport.Posix>) async throws
|
||||||
|
{
|
||||||
|
for _ in 0..<3 {
|
||||||
|
var builder = FlatBufferBuilder(initialSize: 64)
|
||||||
|
let off = builder.create(string: name)
|
||||||
|
let root = models_HelloRequest.createHelloRequest(
|
||||||
|
&builder,
|
||||||
|
nameOffset: off)
|
||||||
|
builder.finish(offset: root)
|
||||||
|
try await client.Expand(GRPCMessage(builder: &builder)) { response in
|
||||||
|
for try await message in response.messages {
|
||||||
|
let message = try? message.decode().message
|
||||||
|
print("expand message: \(message ?? "nil")")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func collect(
|
||||||
|
client: models_Greeter
|
||||||
|
.Client<HTTP2ClientTransport.Posix>) async throws
|
||||||
|
{
|
||||||
|
for _ in 0..<3 {
|
||||||
|
let response = try await client.Collect { writer in
|
||||||
|
for part in name {
|
||||||
|
print("collect sending: \(part)")
|
||||||
|
var builder = FlatBufferBuilder(initialSize: 64)
|
||||||
|
let off = builder.create(string: String(part))
|
||||||
|
let root = models_HelloRequest.createHelloRequest(
|
||||||
|
&builder,
|
||||||
|
nameOffset: off)
|
||||||
|
builder.finish(offset: root)
|
||||||
|
try await writer.write(GRPCMessage(builder: &builder))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let message = try response.decode().message
|
||||||
|
print("collect message: \(message ?? "nil")")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func update(
|
||||||
|
client: models_Greeter
|
||||||
|
.Client<HTTP2ClientTransport.Posix>) async throws
|
||||||
|
{
|
||||||
|
for _ in 0..<3 {
|
||||||
|
try await client.Update { writer in
|
||||||
|
for part in name {
|
||||||
|
print("update sending: \(part)")
|
||||||
|
var builder = FlatBufferBuilder(initialSize: 64)
|
||||||
|
let off = builder.create(string: String(part))
|
||||||
|
let root = models_HelloRequest.createHelloRequest(
|
||||||
|
&builder,
|
||||||
|
nameOffset: off)
|
||||||
|
builder.finish(offset: root)
|
||||||
|
try await writer.write(GRPCMessage(builder: &builder))
|
||||||
|
}
|
||||||
|
} onResponse: { response in
|
||||||
|
for try await message in response.messages {
|
||||||
|
let message = try message.decode().message
|
||||||
|
print("collect message: \(message ?? "nil")")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user