mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-07 05:47:36 +00:00
Compare commits
424 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8367664f15 | ||
|
|
d6f06c33f7 | ||
|
|
627e8bf364 | ||
|
|
883c42b7db | ||
|
|
7aae0af305 | ||
|
|
b057aa917f | ||
|
|
f1b26ff7fb | ||
|
|
9610a666b1 | ||
|
|
1e0f75a647 | ||
|
|
82b75407a3 | ||
|
|
f7c511957f | ||
|
|
a66de58af9 | ||
|
|
a3508f36d5 | ||
|
|
137fec7164 | ||
|
|
214125e417 | ||
|
|
44a7dc9995 | ||
|
|
3cc2daa78f | ||
|
|
fa1174aa7b | ||
|
|
83d4e2a100 | ||
|
|
8a09f3fb0b | ||
|
|
9dbe819efd | ||
|
|
67c4149588 | ||
|
|
8b8c7dbdfc | ||
|
|
2ee20a5f3d | ||
|
|
4be605604e | ||
|
|
fc5d86f1e7 | ||
|
|
9dce287adb | ||
|
|
7798be3bb6 | ||
|
|
966362e074 | ||
|
|
a89c279ed6 | ||
|
|
a212b3c036 | ||
|
|
9230f600d7 | ||
|
|
c793621567 | ||
|
|
ee2ced236d | ||
|
|
468c00a3fe | ||
|
|
47c757f714 | ||
|
|
9a5ff89003 | ||
|
|
950444a343 | ||
|
|
30d76198c7 | ||
|
|
cce3a66f0d | ||
|
|
8d1cc6ac7d | ||
|
|
5b207639a1 | ||
|
|
359e0f9d66 | ||
|
|
ebbed05137 | ||
|
|
aa395e5a59 | ||
|
|
32328075d8 | ||
|
|
97e89c5acd | ||
|
|
5f6672be44 | ||
|
|
28e858c855 | ||
|
|
987bebe678 | ||
|
|
ec0129369c | ||
|
|
50dd385b30 | ||
|
|
da702cfd8f | ||
|
|
6e2791640e | ||
|
|
52fce5e532 | ||
|
|
b7f13cd8e8 | ||
|
|
e42985e5aa | ||
|
|
0a80646371 | ||
|
|
b9eea76a86 | ||
|
|
1b90300150 | ||
|
|
83a43fc797 | ||
|
|
5f01376027 | ||
|
|
9a1913a87a | ||
|
|
b4647beb8f | ||
|
|
d6060977ad | ||
|
|
987aa5b5ee | ||
|
|
42acdb63c3 | ||
|
|
0cc1aeb8ca | ||
|
|
ba6c671705 | ||
|
|
d2f33fc454 | ||
|
|
0d1b72cbc2 | ||
|
|
9fce2fbf2a | ||
|
|
a18ea40d6a | ||
|
|
090caa2809 | ||
|
|
49e1ea3335 | ||
|
|
11a1988705 | ||
|
|
967df08b1d | ||
|
|
9aa08a429e | ||
|
|
9e8c758f54 | ||
|
|
74a25536be | ||
|
|
12917af8a2 | ||
|
|
1ea2472f7a | ||
|
|
0fe13cb28c | ||
|
|
385dddc66a | ||
|
|
750dde7669 | ||
|
|
9917a168cd | ||
|
|
76d3cca19c | ||
|
|
c86e6d0e30 | ||
|
|
d34dc32c20 | ||
|
|
234d86c92a | ||
|
|
746c73b910 | ||
|
|
0bbfd4b2e3 | ||
|
|
7165219535 | ||
|
|
a45f564cf1 | ||
|
|
9d45a64036 | ||
|
|
ccfb4c20bf | ||
|
|
7bcd857b87 | ||
|
|
23c8ab34c1 | ||
|
|
70002dc5ca | ||
|
|
6e0e79f24f | ||
|
|
b856368d75 | ||
|
|
e37156a305 | ||
|
|
a10b0e5464 | ||
|
|
275b739944 | ||
|
|
9d1ce9a100 | ||
|
|
79afe6c3d2 | ||
|
|
c6dbb22300 | ||
|
|
18bacd3ea5 | ||
|
|
a2c913aec3 | ||
|
|
67b33b2942 | ||
|
|
7b5fd2bd05 | ||
|
|
7181d77700 | ||
|
|
7f663b1204 | ||
|
|
173ebb6944 | ||
|
|
d658239484 | ||
|
|
ab4bf59e8c | ||
|
|
eee44bbb26 | ||
|
|
a63fa51a15 | ||
|
|
2049e52101 | ||
|
|
832c618f5f | ||
|
|
14615699fa | ||
|
|
20aad0c41e | ||
|
|
f083b33f2a | ||
|
|
bf17df346e | ||
|
|
35281dedb5 | ||
|
|
c9651b7420 | ||
|
|
26c3b3adab | ||
|
|
da6e1b9856 | ||
|
|
ad27d751e3 | ||
|
|
0aab623cb1 | ||
|
|
6a446bdd83 | ||
|
|
21fb5cbbc9 | ||
|
|
0da6f94867 | ||
|
|
59e9713081 | ||
|
|
40866a8927 | ||
|
|
b71d968fad | ||
|
|
fac0d7be02 | ||
|
|
6c5603fd98 | ||
|
|
2d21853a7e | ||
|
|
fec1a8d015 | ||
|
|
7fd8576233 | ||
|
|
a4cb1599d8 | ||
|
|
ae4ce72651 | ||
|
|
e2be0c0b06 | ||
|
|
2ad408697f | ||
|
|
4213d91054 | ||
|
|
5a13f622cf | ||
|
|
23a7e4e0b0 | ||
|
|
eeb49c2757 | ||
|
|
824763b316 | ||
|
|
d3aeee32bb | ||
|
|
0bceba24db | ||
|
|
b8c77d4041 | ||
|
|
8468eab83b | ||
|
|
2b2e8d4aec | ||
|
|
b80b32bfaf | ||
|
|
e5f331db99 | ||
|
|
2f84c60385 | ||
|
|
d648396515 | ||
|
|
777e78d8dd | ||
|
|
4016c549d3 | ||
|
|
40827b21b2 | ||
|
|
65a10b6e32 | ||
|
|
8db2fef3f7 | ||
|
|
9ed1323044 | ||
|
|
1a4c405662 | ||
|
|
318594e4b4 | ||
|
|
3d903302c3 | ||
|
|
c9571d9897 | ||
|
|
3694b830a2 | ||
|
|
0471fa807c | ||
|
|
914344ea9b | ||
|
|
b40266c56f | ||
|
|
8a9303d464 | ||
|
|
30c4bf47f9 | ||
|
|
46ce45601b | ||
|
|
433312c55a | ||
|
|
9c52ec3744 | ||
|
|
70e2f49bff | ||
|
|
5ac0367ed3 | ||
|
|
5d101afb52 | ||
|
|
06f4af11b6 | ||
|
|
57e338f819 | ||
|
|
615616cb55 | ||
|
|
3413c33004 | ||
|
|
69f5660a44 | ||
|
|
d5add9fca5 | ||
|
|
15df50eb7f | ||
|
|
a94132a45f | ||
|
|
48befb6bef | ||
|
|
b300691336 | ||
|
|
faadbc10ea | ||
|
|
ed6ae8d322 | ||
|
|
e910bddbcc | ||
|
|
c85fb690f4 | ||
|
|
c1daa6ba0c | ||
|
|
4c71c7b023 | ||
|
|
f5664d33fb | ||
|
|
39c8a19ce2 | ||
|
|
826193ff68 | ||
|
|
fd0d1ed929 | ||
|
|
424988f308 | ||
|
|
b2550dbaa9 | ||
|
|
a2b238960f | ||
|
|
619b784374 | ||
|
|
68a7661546 | ||
|
|
7dac9961f0 | ||
|
|
c65c389c6d | ||
|
|
6446dcf3d6 | ||
|
|
e090d8da17 | ||
|
|
bc901436db | ||
|
|
240be9b5ae | ||
|
|
bc366a7f9e | ||
|
|
14b19d446f | ||
|
|
9e6f17b94d | ||
|
|
c3801ad375 | ||
|
|
4f3b24db09 | ||
|
|
1d294a31b8 | ||
|
|
dd8fccfb1b | ||
|
|
7089c9ecdd | ||
|
|
43203984f7 | ||
|
|
5993338ee3 | ||
|
|
19920db39f | ||
|
|
dbbaeac85c | ||
|
|
028f0fde62 | ||
|
|
87343631b9 | ||
|
|
1fbfaf5c5e | ||
|
|
4421375bb6 | ||
|
|
162ad7a37e | ||
|
|
a0a6c3f8c6 | ||
|
|
a2d38fbb98 | ||
|
|
9ef1524d3f | ||
|
|
0c9de0352a | ||
|
|
a783bc9267 | ||
|
|
aff818cebf | ||
|
|
d7b75417fc | ||
|
|
a42e898979 | ||
|
|
96cc2f3ee3 | ||
|
|
3250a1f8dd | ||
|
|
ace4a37f22 | ||
|
|
f28c2b2936 | ||
|
|
96f3cf690f | ||
|
|
b3edfdbfb7 | ||
|
|
b8aaccee82 | ||
|
|
2dc8ae7742 | ||
|
|
5b0d491127 | ||
|
|
d8b7041d7e | ||
|
|
5a0c3366c3 | ||
|
|
f8148b8dad | ||
|
|
a22b1b6267 | ||
|
|
4264daadd2 | ||
|
|
3cbc120a08 | ||
|
|
8dcd2682c7 | ||
|
|
b78002ff3e | ||
|
|
c555ee8fac | ||
|
|
b92bb0584d | ||
|
|
956d11569e | ||
|
|
e367ca32ad | ||
|
|
705f27f6ee | ||
|
|
5fc87f4c4b | ||
|
|
11749095a1 | ||
|
|
d0cede9c90 | ||
|
|
fcc2bee0b6 | ||
|
|
e08da4dea2 | ||
|
|
18538c401c | ||
|
|
e57f4ab2d2 | ||
|
|
deed68db5d | ||
|
|
061d61f3f8 | ||
|
|
cffe0c4546 | ||
|
|
fadd40e402 | ||
|
|
e47dc0e465 | ||
|
|
5c54754790 | ||
|
|
4f7f6dc301 | ||
|
|
0fadaf391d | ||
|
|
4d0e9a8706 | ||
|
|
c05f6783a6 | ||
|
|
a14f4052cf | ||
|
|
9e4ca857b6 | ||
|
|
a2b99084b4 | ||
|
|
85b4effac6 | ||
|
|
790f411542 | ||
|
|
e89de4411d | ||
|
|
256ab3798d | ||
|
|
a59288a019 | ||
|
|
587bbd49a7 | ||
|
|
a9c341545f | ||
|
|
8aa18b6291 | ||
|
|
d727579b6d | ||
|
|
97a30171cb | ||
|
|
0989fc5e59 | ||
|
|
927175ea20 | ||
|
|
6748c373be | ||
|
|
3fab0c6ee4 | ||
|
|
6c8c291559 | ||
|
|
fd4ff23da0 | ||
|
|
f8b69e3308 | ||
|
|
c0394bb09c | ||
|
|
8433eb108c | ||
|
|
f2f9380c86 | ||
|
|
e672dabfea | ||
|
|
9a4ca2764c | ||
|
|
4c7a9c10d3 | ||
|
|
38295a1873 | ||
|
|
31bb0b9726 | ||
|
|
45e5642e91 | ||
|
|
a592f4c89e | ||
|
|
b9d43a557c | ||
|
|
2ece9e25b4 | ||
|
|
2dd2126379 | ||
|
|
f63c130c28 | ||
|
|
e2b26ee19b | ||
|
|
9d686bf433 | ||
|
|
1d26daff3e | ||
|
|
e72e18d9fd | ||
|
|
354d97f6da | ||
|
|
6f7a57eaa0 | ||
|
|
90baa1444b | ||
|
|
0a3b017f09 | ||
|
|
47d35f1053 | ||
|
|
8fb8c2ce1d | ||
|
|
1d063d87cf | ||
|
|
338331b55b | ||
|
|
156a30c753 | ||
|
|
550d2f9048 | ||
|
|
c3a38242e6 | ||
|
|
74c3d7eba2 | ||
|
|
db6eae5c42 | ||
|
|
0e9d79c355 | ||
|
|
b20c4d3aad | ||
|
|
ae145293cc | ||
|
|
e3c76a5cde | ||
|
|
4b9123baff | ||
|
|
f89e0b1a6c | ||
|
|
273f6084e5 | ||
|
|
4a0879458d | ||
|
|
d6f51ea16d | ||
|
|
067dce6e79 | ||
|
|
2ca5f0e72b | ||
|
|
f20d2253ae | ||
|
|
390d438e2a | ||
|
|
6fb2c90d9e | ||
|
|
a7b527d942 | ||
|
|
5d77820b34 | ||
|
|
909ce970ae | ||
|
|
35e2cac6eb | ||
|
|
c39fc9dd9c | ||
|
|
775c6567d1 | ||
|
|
97d9527f6c | ||
|
|
e012054667 | ||
|
|
5235133f32 | ||
|
|
c871df7702 | ||
|
|
a6eeeb3b9c | ||
|
|
3dd02144d5 | ||
|
|
e77926f0ed | ||
|
|
ac23482022 | ||
|
|
8be8a0a713 | ||
|
|
12e341e4f8 | ||
|
|
c36672d803 | ||
|
|
2bfc8e9f01 | ||
|
|
674a9f2aae | ||
|
|
016e6aa13f | ||
|
|
65700441d3 | ||
|
|
dd5bb55cad | ||
|
|
e8423da1b7 | ||
|
|
0980e39c9b | ||
|
|
e73fab27d4 | ||
|
|
92ae532e43 | ||
|
|
7482b25f8b | ||
|
|
3f77dc9a0e | ||
|
|
838c93b843 | ||
|
|
089f48a4a6 | ||
|
|
bf3470c161 | ||
|
|
8f8196e136 | ||
|
|
8ab35b2a5f | ||
|
|
c0ba2870c9 | ||
|
|
22498cf3a9 | ||
|
|
bd37e67ac0 | ||
|
|
a6ee335574 | ||
|
|
71d43f3be9 | ||
|
|
c8db1ca5d4 | ||
|
|
962751a6ec | ||
|
|
06fd6d640c | ||
|
|
acce4ac3f0 | ||
|
|
8fd7861b75 | ||
|
|
c58ae94225 | ||
|
|
2cf7bb7966 | ||
|
|
4e3a66c141 | ||
|
|
d959e23208 | ||
|
|
a9fb540884 | ||
|
|
337eb8b8f7 | ||
|
|
6415ef05d3 | ||
|
|
f069396d1b | ||
|
|
021177af0d | ||
|
|
e1e9f93739 | ||
|
|
15110094eb | ||
|
|
093badb0a0 | ||
|
|
752c7b576d | ||
|
|
7c3e267e1e | ||
|
|
baaffbaedd | ||
|
|
4cb3f222b1 | ||
|
|
eabdbda755 | ||
|
|
bec23700fc | ||
|
|
12f2eedadc | ||
|
|
221eeb2312 | ||
|
|
813d3632ec | ||
|
|
d84bccb0c7 | ||
|
|
b4e67f9bf0 | ||
|
|
54c11932fa | ||
|
|
fbcb3c4236 | ||
|
|
8937dcfd78 | ||
|
|
512d5a6897 | ||
|
|
a92cb5dd7b | ||
|
|
d151dcbb9d | ||
|
|
f1884c66f4 | ||
|
|
72730ecd8a | ||
|
|
fe2bc2b0a7 | ||
|
|
4867c94564 | ||
|
|
ef0eb3701d | ||
|
|
f83ee1af59 | ||
|
|
a5175c513a | ||
|
|
04b10f5a3a | ||
|
|
c121c03456 | ||
|
|
8fd10606c1 | ||
|
|
a1730fcea8 |
@@ -1,41 +0,0 @@
|
|||||||
:: Copyright 2018 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.
|
|
||||||
set buildtype=Release
|
|
||||||
if "%1"=="-b" set buildtype=%2
|
|
||||||
|
|
||||||
cd tests
|
|
||||||
call generate_code.bat -b %buildtype% || goto FAIL
|
|
||||||
|
|
||||||
:: TODO: Release and Debug builds produce differences here for some reason.
|
|
||||||
git checkout HEAD -- monster_test.bfbs
|
|
||||||
git checkout HEAD -- arrays_test.bfbs
|
|
||||||
|
|
||||||
git -c core.autocrlf=true diff --exit-code --quiet || goto :DIFFFOUND
|
|
||||||
goto SUCCESS
|
|
||||||
|
|
||||||
:DIFFFOUND
|
|
||||||
@echo "" >&2
|
|
||||||
@echo "ERROR: ********************************************************" >&2
|
|
||||||
@echo "ERROR: The following differences were found after running the" >&2
|
|
||||||
@echo "ERROR: tests/generate_code.sh script. Maybe you forgot to run" >&2
|
|
||||||
@echo "ERROR: it after making changes in a generator or schema?" >&2
|
|
||||||
@echo "ERROR: ********************************************************" >&2
|
|
||||||
@echo "" >&2
|
|
||||||
@git -c core.autocrlf=true --no-pager diff --binary
|
|
||||||
|
|
||||||
:FAIL
|
|
||||||
set EXITCODE=1
|
|
||||||
:SUCCESS
|
|
||||||
cd ..
|
|
||||||
EXIT /B %EXITCODE%
|
|
||||||
@@ -1,18 +1,36 @@
|
|||||||
---
|
---
|
||||||
buildifier: latest
|
buildifier: latest
|
||||||
platforms:
|
platforms:
|
||||||
ubuntu1604:
|
|
||||||
build_targets:
|
|
||||||
- "..."
|
|
||||||
test_targets:
|
|
||||||
- "..."
|
|
||||||
ubuntu1804:
|
ubuntu1804:
|
||||||
|
environment:
|
||||||
|
CC: clang
|
||||||
|
SWIFT_VERSION: "5.5.3"
|
||||||
|
SWIFT_HOME: "$HOME/swift-$SWIFT_VERSION"
|
||||||
|
PATH: "$PATH:$SWIFT_HOME/usr/bin"
|
||||||
|
shell_commands:
|
||||||
|
- "echo --- Downloading and extracting Swift $SWIFT_VERSION to $SWIFT_HOME"
|
||||||
|
- "mkdir $SWIFT_HOME"
|
||||||
|
- "curl https://download.swift.org/swift-${SWIFT_VERSION}-release/ubuntu1804/swift-${SWIFT_VERSION}-RELEASE/swift-${SWIFT_VERSION}-RELEASE-ubuntu18.04.tar.gz | tar xvz --strip-components=1 -C $SWIFT_HOME"
|
||||||
build_targets:
|
build_targets:
|
||||||
- "..."
|
- "//..."
|
||||||
test_targets:
|
test_targets:
|
||||||
- "..."
|
- "//..."
|
||||||
|
ubuntu2004:
|
||||||
|
environment:
|
||||||
|
CC: clang
|
||||||
|
SWIFT_VERSION: "5.5.3"
|
||||||
|
SWIFT_HOME: "$HOME/swift-$SWIFT_VERSION"
|
||||||
|
PATH: "$PATH:$SWIFT_HOME/usr/bin"
|
||||||
|
shell_commands:
|
||||||
|
- "echo --- Downloading and extracting Swift $SWIFT_VERSION to $SWIFT_HOME"
|
||||||
|
- "mkdir $SWIFT_HOME"
|
||||||
|
- "curl https://download.swift.org/swift-${SWIFT_VERSION}-release/ubuntu2004/swift-${SWIFT_VERSION}-RELEASE/swift-${SWIFT_VERSION}-RELEASE-ubuntu20.04.tar.gz | tar xvz --strip-components=1 -C $SWIFT_HOME"
|
||||||
|
build_targets:
|
||||||
|
- "//..."
|
||||||
|
test_targets:
|
||||||
|
- "//..."
|
||||||
macos:
|
macos:
|
||||||
build_targets:
|
build_targets:
|
||||||
- "..."
|
- "//..."
|
||||||
test_targets:
|
test_targets:
|
||||||
- "..."
|
- "//..."
|
||||||
|
|||||||
15
.github/PULL_REQUEST_TEMPLATE.md
vendored
15
.github/PULL_REQUEST_TEMPLATE.md
vendored
@@ -2,18 +2,17 @@ Thank you for submitting a PR!
|
|||||||
|
|
||||||
Please delete this standard text once you've created your own description.
|
Please delete this standard text once you've created your own description.
|
||||||
|
|
||||||
Make sure you include the names of the affected language(s) in your PR title.
|
If you make changes to any of the code generators (`src/idl_gen*`) be sure to
|
||||||
This helps us get the correct maintainers to look at your issue.
|
build your project, as it will generate code based on the changes. If necessary
|
||||||
|
the code generation script can be directly run (`scripts/generate_code.py`),
|
||||||
|
requires Python3. This allows us to better see the effect of the PR.
|
||||||
|
|
||||||
If you make changes to any of the code generators, be sure to run
|
If your PR includes C++ code, please adhere to the
|
||||||
`cd tests && bash generate_code.sh` (or equivalent .bat) and include the generated
|
[Google C++ Style Guide](https://google.github.io/styleguide/cppguide.html),
|
||||||
code changes in the PR. This allows us to better see the effect of the PR.
|
|
||||||
|
|
||||||
If your PR includes C++ code, please adhere to the Google C++ Style Guide,
|
|
||||||
and don't forget we try to support older compilers (e.g. VS2010, GCC 4.6.3),
|
and don't forget we try to support older compilers (e.g. VS2010, GCC 4.6.3),
|
||||||
so only some C++11 support is available.
|
so only some C++11 support is available.
|
||||||
|
|
||||||
For any C++ changes, please make sure to run `sh src/clang-format-git.sh`
|
For any C++ changes, please make sure to run `sh scripts/clang-format-git.sh`
|
||||||
|
|
||||||
Include other details as appropriate.
|
Include other details as appropriate.
|
||||||
|
|
||||||
|
|||||||
3
.github/labeler.yml
vendored
3
.github/labeler.yml
vendored
@@ -49,6 +49,7 @@ lua:
|
|||||||
- '**/*.lua'
|
- '**/*.lua'
|
||||||
- lua/**/*
|
- lua/**/*
|
||||||
- src/idl_gen_lua.cpp
|
- src/idl_gen_lua.cpp
|
||||||
|
- src/bfbs_gen_lua.cpp
|
||||||
|
|
||||||
lobster:
|
lobster:
|
||||||
- '**/*.lobster'
|
- '**/*.lobster'
|
||||||
@@ -85,11 +86,9 @@ documentation:
|
|||||||
|
|
||||||
CI:
|
CI:
|
||||||
- '.github/**/*'
|
- '.github/**/*'
|
||||||
- '.appveyor/**/*'
|
|
||||||
- '.travis/**/*'
|
- '.travis/**/*'
|
||||||
- '.bazelci/**/*'
|
- '.bazelci/**/*'
|
||||||
- .travis.yml
|
- .travis.yml
|
||||||
- appveyor.yml
|
|
||||||
|
|
||||||
grpc:
|
grpc:
|
||||||
- grpc/**/*
|
- grpc/**/*
|
||||||
|
|||||||
402
.github/workflows/build.yml
vendored
402
.github/workflows/build.yml
vendored
@@ -1,7 +1,12 @@
|
|||||||
name: CI
|
name: CI
|
||||||
|
permissions: read-all
|
||||||
|
|
||||||
on:
|
on:
|
||||||
|
# For manual tests.
|
||||||
|
workflow_dispatch:
|
||||||
push:
|
push:
|
||||||
|
tags:
|
||||||
|
- "*" # new tag version, like `0.8.4` or else
|
||||||
branches:
|
branches:
|
||||||
- master
|
- master
|
||||||
pull_request:
|
pull_request:
|
||||||
@@ -10,165 +15,346 @@ on:
|
|||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build-linux:
|
build-linux:
|
||||||
|
permissions:
|
||||||
|
contents: write
|
||||||
|
outputs:
|
||||||
|
digests-gcc: ${{ steps.hash-gcc.outputs.hashes }}
|
||||||
|
digests-clang: ${{ steps.hash-clang.outputs.hashes }}
|
||||||
name: Build Linux
|
name: Build Linux
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
strategy:
|
strategy:
|
||||||
matrix:
|
matrix:
|
||||||
cxx: [g++-9, clang++-9]
|
cxx: [g++-10, clang++-12]
|
||||||
|
fail-fast: false
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v1
|
- uses: actions/checkout@v2
|
||||||
- name: cmake
|
- name: cmake
|
||||||
run: CXX=${{ matrix.cxx }} cmake -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=Release .
|
run: CXX=${{ matrix.cxx }} cmake -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=Release -DFLATBUFFERS_STRICT_MODE=ON .
|
||||||
- name: build
|
- name: build
|
||||||
run: make -j4
|
run: make -j
|
||||||
- name: test
|
- name: test
|
||||||
run: ./flattests
|
run: ./flattests
|
||||||
|
- name: make flatc executable
|
||||||
|
run: |
|
||||||
|
chmod +x flatc
|
||||||
|
./flatc --version
|
||||||
|
- name: flatc tests
|
||||||
|
run: python3 tests/flatc/main.py
|
||||||
- name: upload build artifacts
|
- name: upload build artifacts
|
||||||
uses: actions/upload-artifact@v1
|
uses: actions/upload-artifact@v1
|
||||||
with:
|
with:
|
||||||
name: Linux flatc binary ${{ matrix.cxx }}
|
name: Linux flatc binary ${{ matrix.cxx }}
|
||||||
path: flatc
|
path: flatc
|
||||||
|
# Below if only for release.
|
||||||
|
- name: Zip file
|
||||||
|
if: startsWith(github.ref, 'refs/tags/')
|
||||||
|
run: zip Linux.flatc.binary.${{ matrix.cxx }}.zip flatc
|
||||||
|
- name: Release zip file
|
||||||
|
uses: softprops/action-gh-release@v1
|
||||||
|
if: startsWith(github.ref, 'refs/tags/')
|
||||||
|
with:
|
||||||
|
files: Linux.flatc.binary.${{ matrix.cxx }}.zip
|
||||||
|
- name: Generate SLSA subjects - clang
|
||||||
|
if: matrix.cxx == 'clang++-12' && startsWith(github.ref, 'refs/tags/')
|
||||||
|
id: hash-clang
|
||||||
|
run: echo "::set-output name=hashes::$(sha256sum Linux.flatc.binary.${{ matrix.cxx }}.zip | base64 -w0)"
|
||||||
|
- name: Generate SLSA subjects - gcc
|
||||||
|
if: matrix.cxx == 'g++-10' && startsWith(github.ref, 'refs/tags/')
|
||||||
|
id: hash-gcc
|
||||||
|
run: echo "::set-output name=hashes::$(sha256sum Linux.flatc.binary.${{ matrix.cxx }}.zip | base64 -w0)"
|
||||||
|
|
||||||
build-windows:
|
build-windows:
|
||||||
name: Build Windows
|
permissions:
|
||||||
runs-on: windows-latest
|
contents: write
|
||||||
|
outputs:
|
||||||
|
digests: ${{ steps.hash.outputs.hashes }}
|
||||||
|
name: Build Windows 2019
|
||||||
|
runs-on: windows-2019
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v1
|
- uses: actions/checkout@v2
|
||||||
- name: Add msbuild to PATH
|
- name: Add msbuild to PATH
|
||||||
uses: microsoft/setup-msbuild@v1.0.2
|
uses: microsoft/setup-msbuild@v1.1
|
||||||
- name: cmake
|
- name: cmake
|
||||||
run: cmake -G "Visual Studio 16 2019" -A x64 -DCMAKE_BUILD_TYPE=Release -DFLATBUFFERS_BUILD_CPP17=ON .
|
run: cmake -G "Visual Studio 16 2019" -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: flatc tests
|
||||||
|
run: python3 tests/flatc/main.py --flatc Release\flatc.exe
|
||||||
- name: upload build artifacts
|
- name: upload build artifacts
|
||||||
uses: actions/upload-artifact@v1
|
uses: actions/upload-artifact@v1
|
||||||
with:
|
with:
|
||||||
name: Windows flatc binary
|
name: Windows flatc binary
|
||||||
path: Release\flatc.exe
|
path: Release\flatc.exe
|
||||||
|
# Below if only for release.
|
||||||
|
- name: Zip file
|
||||||
|
if: startsWith(github.ref, 'refs/tags/')
|
||||||
|
run: move Release/flatc.exe . && Compress-Archive flatc.exe Windows.flatc.binary.zip
|
||||||
|
- name: Release binary
|
||||||
|
uses: softprops/action-gh-release@v1
|
||||||
|
if: startsWith(github.ref, 'refs/tags/')
|
||||||
|
with:
|
||||||
|
files: Windows.flatc.binary.zip
|
||||||
|
- name: Generate SLSA subjects
|
||||||
|
if: startsWith(github.ref, 'refs/tags/')
|
||||||
|
id: hash
|
||||||
|
shell: bash
|
||||||
|
run: echo "::set-output name=hashes::$(sha256sum Windows.flatc.binary.zip | base64 -w0)"
|
||||||
|
|
||||||
build-windows-2017:
|
build-windows-2017:
|
||||||
name: Build Windows 2017
|
name: Build Windows 2017
|
||||||
runs-on: windows-2016
|
runs-on: windows-2019
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v1
|
- uses: actions/checkout@v2
|
||||||
- name: Add msbuild to PATH
|
- name: Add msbuild to PATH
|
||||||
uses: microsoft/setup-msbuild@v1.0.2
|
uses: microsoft/setup-msbuild@v1.1
|
||||||
- name: cmake
|
- name: cmake
|
||||||
run: cmake -G "Visual Studio 15 2017" -A x64 -DCMAKE_BUILD_TYPE=Release .
|
run: cmake -G "Visual Studio 16 2019" -A x64 -DCMAKE_BUILD_TYPE=Release -DFLATBUFFERS_STRICT_MODE=ON .
|
||||||
- name: build
|
- name: build tool version 15 (VS 2017)
|
||||||
run: msbuild.exe FlatBuffers.sln /p:Configuration=Release /p:Platform=x64
|
run: msbuild.exe FlatBuffers.sln /p:Configuration=Release /p:Platform=x64 /p:VisualStudioVersion=15.0
|
||||||
- name: test
|
- name: test
|
||||||
run: Release\flattests.exe
|
run: Release\flattests.exe
|
||||||
|
|
||||||
build-mac:
|
build-windows-2015:
|
||||||
name: Build Mac
|
name: Build Windows 2015
|
||||||
|
runs-on: windows-2019
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v2
|
||||||
|
- name: Add msbuild to PATH
|
||||||
|
uses: microsoft/setup-msbuild@v1.1
|
||||||
|
- name: cmake
|
||||||
|
run: cmake -G "Visual Studio 14 2015" -A x64 -DCMAKE_BUILD_TYPE=Release -DFLATBUFFERS_STRICT_MODE=ON .
|
||||||
|
- name: build tool version 14 (VS 2015)
|
||||||
|
run: msbuild.exe FlatBuffers.sln /p:Configuration=Release /p:Platform=x64 /p:VisualStudioVersion=14.0
|
||||||
|
- name: test
|
||||||
|
run: Release\flattests.exe
|
||||||
|
|
||||||
|
build-dotnet-windows:
|
||||||
|
name: Build .NET Windows
|
||||||
|
runs-on: windows-2019
|
||||||
|
strategy:
|
||||||
|
matrix:
|
||||||
|
configuration: [
|
||||||
|
'',
|
||||||
|
'-p:UnsafeByteBuffer=true',
|
||||||
|
# Fails two tests currently.
|
||||||
|
#'-p:EnableSpanT=true,UnsafeByteBuffer=true'
|
||||||
|
]
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v2
|
||||||
|
- name: Setup .NET Core SDK
|
||||||
|
uses: actions/setup-dotnet@v1.9.0
|
||||||
|
with:
|
||||||
|
dotnet-version: '3.1.x'
|
||||||
|
- name: Build
|
||||||
|
run: |
|
||||||
|
cd tests\FlatBuffers.Test
|
||||||
|
dotnet new sln --force --name FlatBuffers.Core.Test
|
||||||
|
dotnet sln FlatBuffers.Core.Test.sln add FlatBuffers.Core.Test.csproj
|
||||||
|
dotnet build -c Release ${{matrix.configuration}} -o out FlatBuffers.Core.Test.sln
|
||||||
|
- name: Run
|
||||||
|
run: |
|
||||||
|
cd tests\FlatBuffers.Test
|
||||||
|
out\FlatBuffers.Core.Test.exe
|
||||||
|
|
||||||
|
build-mac-intel:
|
||||||
|
permissions:
|
||||||
|
contents: write
|
||||||
|
outputs:
|
||||||
|
digests: ${{ steps.hash.outputs.hashes }}
|
||||||
|
name: Build Mac (for Intel)
|
||||||
runs-on: macos-latest
|
runs-on: macos-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v1
|
- uses: actions/checkout@v2
|
||||||
- name: cmake
|
- name: cmake
|
||||||
run: cmake -G "Xcode" -DCMAKE_BUILD_TYPE=Release -DFLATBUFFERS_FLATC_EXECUTABLE=_build/Release/flatc .
|
run: cmake -G "Xcode" -DCMAKE_BUILD_TYPE=Release -DFLATBUFFERS_FLATC_EXECUTABLE=_build/Release/flatc -DFLATBUFFERS_STRICT_MODE=ON .
|
||||||
- name: build
|
- name: build
|
||||||
# NOTE: we need this _build dir to not have xcodebuild's default ./build dir clash with the BUILD file.
|
# NOTE: we need this _build dir to not have xcodebuild's default ./build dir clash with the BUILD file.
|
||||||
run: xcodebuild -toolchain clang -configuration Release -target flattests SYMROOT=$(PWD)/_build
|
run: xcodebuild -toolchain clang -configuration Release -target flattests SYMROOT=$(PWD)/_build
|
||||||
|
- name: check that the binary is x86_64
|
||||||
|
run: |
|
||||||
|
info=$(file _build/Release/flatc)
|
||||||
|
echo $info
|
||||||
|
echo $info | grep "Mach-O 64-bit executable x86_64"
|
||||||
- name: test
|
- name: test
|
||||||
run: _build/Release/flattests
|
run: _build/Release/flattests
|
||||||
|
- name: make flatc executable
|
||||||
|
run: |
|
||||||
|
chmod +x _build/Release/flatc
|
||||||
|
./_build/Release/flatc --version
|
||||||
|
- name: flatc tests
|
||||||
|
run: python3 tests/flatc/main.py --flatc ./_build/Release/flatc
|
||||||
- name: upload build artifacts
|
- name: upload build artifacts
|
||||||
uses: actions/upload-artifact@v1
|
uses: actions/upload-artifact@v1
|
||||||
with:
|
with:
|
||||||
name: Mac flatc binary
|
name: Mac flatc binary
|
||||||
path: _build/Release/flatc
|
path: _build/Release/flatc
|
||||||
|
# Below if only for release.
|
||||||
|
- name: Zip file
|
||||||
|
if: startsWith(github.ref, 'refs/tags/')
|
||||||
|
run: mv _build/Release/flatc . && zip MacIntel.flatc.binary.zip flatc
|
||||||
|
- name: Release binary
|
||||||
|
uses: softprops/action-gh-release@v1
|
||||||
|
if: startsWith(github.ref, 'refs/tags/')
|
||||||
|
with:
|
||||||
|
files: MacIntel.flatc.binary.zip
|
||||||
|
- name: Generate SLSA subjects
|
||||||
|
if: startsWith(github.ref, 'refs/tags/')
|
||||||
|
id: hash
|
||||||
|
run: echo "::set-output name=hashes::$(shasum -a 256 MacIntel.flatc.binary.zip | base64)"
|
||||||
|
|
||||||
|
build-mac-universal:
|
||||||
|
permissions:
|
||||||
|
contents: write
|
||||||
|
outputs:
|
||||||
|
digests: ${{ steps.hash.outputs.hashes }}
|
||||||
|
name: Build Mac (universal build)
|
||||||
|
runs-on: macos-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v2
|
||||||
|
- name: cmake
|
||||||
|
run: cmake -G "Xcode" -DCMAKE_OSX_ARCHITECTURES="arm64;x86_64" -DCMAKE_BUILD_TYPE=Release -DFLATBUFFERS_FLATC_EXECUTABLE=_build/Release/flatc -DFLATBUFFERS_STRICT_MODE=ON .
|
||||||
|
- name: build
|
||||||
|
# NOTE: we need this _build dir to not have xcodebuild's default ./build dir clash with the BUILD file.
|
||||||
|
run: xcodebuild -toolchain clang -configuration Release -target flattests SYMROOT=$(PWD)/_build
|
||||||
|
- name: check that the binary is "universal"
|
||||||
|
run: |
|
||||||
|
info=$(file _build/Release/flatc)
|
||||||
|
echo $info
|
||||||
|
echo $info | grep "Mach-O universal binary with 2 architectures"
|
||||||
|
- name: test
|
||||||
|
run: _build/Release/flattests
|
||||||
|
- name: make flatc executable
|
||||||
|
run: |
|
||||||
|
chmod +x _build/Release/flatc
|
||||||
|
./_build/Release/flatc --version
|
||||||
|
- name: upload build artifacts
|
||||||
|
uses: actions/upload-artifact@v1
|
||||||
|
with:
|
||||||
|
name: Mac flatc binary
|
||||||
|
path: _build/Release/flatc
|
||||||
|
# Below if only for release.
|
||||||
|
- name: Zip file
|
||||||
|
if: startsWith(github.ref, 'refs/tags/')
|
||||||
|
run: mv _build/Release/flatc . && zip Mac.flatc.binary.zip flatc
|
||||||
|
- name: Release binary
|
||||||
|
uses: softprops/action-gh-release@v1
|
||||||
|
if: startsWith(github.ref, 'refs/tags/')
|
||||||
|
with:
|
||||||
|
files: Mac.flatc.binary.zip
|
||||||
|
- name: Generate SLSA subjects
|
||||||
|
if: startsWith(github.ref, 'refs/tags/')
|
||||||
|
id: hash
|
||||||
|
run: echo "::set-output name=hashes::$(shasum -a 256 Mac.flatc.binary.zip | base64)"
|
||||||
|
|
||||||
build-android:
|
build-android:
|
||||||
name: Build Android (on Linux)
|
name: Build Android (on Linux)
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v1
|
- uses: actions/checkout@v2
|
||||||
- name: set up JDK 1.8
|
- name: set up JDK 1.8
|
||||||
uses: actions/setup-java@v1
|
uses: actions/setup-java@v1
|
||||||
with:
|
with:
|
||||||
java-version: 1.8
|
java-version: 1.8
|
||||||
- name: set up flatc
|
- name: set up 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 -DFLATBUFFERS_STRICT_MODE=ON .
|
||||||
make
|
make -j
|
||||||
echo "${PWD}" >> $GITHUB_PATH
|
echo "${PWD}" >> $GITHUB_PATH
|
||||||
- name: build
|
- name: build
|
||||||
working-directory: android
|
working-directory: android
|
||||||
run: bash ./gradlew clean build
|
run: gradle clean build
|
||||||
|
|
||||||
build-generator:
|
build-generator:
|
||||||
name: Check Generated Code
|
name: Check Generated Code
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
strategy:
|
strategy:
|
||||||
matrix:
|
matrix:
|
||||||
cxx: [g++-9, clang++-9]
|
cxx: [g++-10, clang++-12]
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v1
|
- uses: actions/checkout@v2
|
||||||
- name: cmake
|
- name: cmake
|
||||||
run: CXX=${{ matrix.cxx }} cmake -G "Unix Makefiles" -DFLATBUFFERS_BUILD_TESTS=OFF -DCMAKE_BUILD_TYPE=Release . && make -j4
|
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
|
||||||
run: bash scripts/check-generate-code.sh && bash scripts/check-grpc-generated-code.sh
|
run: scripts/check_generate_code.py
|
||||||
|
- name: Generate gRPC
|
||||||
|
run: scripts/check-grpc-generated-code.py
|
||||||
|
|
||||||
|
build-benchmarks:
|
||||||
|
name: Build Benchmarks (on Linux)
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
strategy:
|
||||||
|
matrix:
|
||||||
|
cxx: [g++-10]
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v2
|
||||||
|
- 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
|
||||||
|
- name: Run benchmarks
|
||||||
|
run: ./flatbenchmark --benchmark_repetitions=5 --benchmark_display_aggregates_only=true --benchmark_out_format=console --benchmark_out=benchmarks/results_${{matrix.cxx}}
|
||||||
|
- name: Upload benchmarks results
|
||||||
|
uses: actions/upload-artifact@v1
|
||||||
|
with:
|
||||||
|
name: Linux flatbenchmark results ${{matrix.cxx}}
|
||||||
|
path: benchmarks/results_${{matrix.cxx}}
|
||||||
|
|
||||||
build-java:
|
build-java:
|
||||||
name: Build Java
|
name: Build Java
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v1
|
- uses: actions/checkout@v2
|
||||||
- name: test
|
- name: test
|
||||||
working-directory: tests
|
working-directory: tests
|
||||||
run: bash JavaTest.sh
|
run: bash JavaTest.sh
|
||||||
|
|
||||||
build-kotlin:
|
build-kotlin-macos:
|
||||||
name: Build Kotlin
|
name: Build Kotlin MacOS
|
||||||
runs-on: macos-latest
|
runs-on: macos-latest
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v1
|
uses: actions/checkout@v2
|
||||||
|
- uses: gradle/wrapper-validation-action@v1
|
||||||
|
- uses: actions/setup-java@v2
|
||||||
|
with:
|
||||||
|
distribution: 'adopt-hotspot'
|
||||||
|
java-version: '11'
|
||||||
- name: Build
|
- name: Build
|
||||||
working-directory: kotlin
|
working-directory: kotlin
|
||||||
run: ./gradlew clean build allTests
|
run: ./gradlew clean iosX64Test macosX64Test
|
||||||
- name: Run Benchmark
|
|
||||||
working-directory: kotlin
|
build-kotlin-linux:
|
||||||
run: ./gradlew benchmark
|
name: Build Kotlin Linux
|
||||||
- name: Generate Benchmark Report
|
runs-on: ubuntu-latest
|
||||||
working-directory: kotlin
|
steps:
|
||||||
run: |
|
- name: Checkout
|
||||||
./gradlew jmhReport;
|
uses: actions/checkout@v2
|
||||||
mv benchmark/build/reports/benchmarks/main/* benchmark_latest
|
- uses: actions/setup-java@v2
|
||||||
- name: Archive benchmark report
|
|
||||||
uses: actions/upload-artifact@v1
|
|
||||||
with:
|
with:
|
||||||
name: Kotlin Benchmark Report
|
distribution: 'adopt-hotspot'
|
||||||
path: kotlin/benchmark_latest
|
java-version: '11'
|
||||||
|
- uses: gradle/wrapper-validation-action@v1
|
||||||
|
- name: Build
|
||||||
|
working-directory: kotlin
|
||||||
|
# we are using docker's version of gradle
|
||||||
|
# so no need for wrapper validadation or user
|
||||||
|
# gradlew
|
||||||
|
run: gradle jvmMainClasses jvmTest jsTest jsBrowserTest
|
||||||
|
|
||||||
build-rust:
|
build-rust:
|
||||||
name: Build Rust
|
name: Build Rust
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v1
|
- uses: actions/checkout@v2
|
||||||
- name: test
|
- name: test
|
||||||
working-directory: tests
|
working-directory: tests
|
||||||
run: bash RustTest.sh
|
run: bash RustTest.sh
|
||||||
|
|
||||||
#build-js:
|
|
||||||
# name: Build JS
|
|
||||||
# runs-on: ubuntu-latest
|
|
||||||
# steps:
|
|
||||||
# - uses: actions/checkout@v1
|
|
||||||
# - name: flatc
|
|
||||||
# # FIXME: make test script not rely on flatc
|
|
||||||
# run: cmake -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=Release -DFLATBUFFERS_BUILD_TESTS=OFF -DFLATBUFFERS_INSTALL=OFF -DFLATBUFFERS_BUILD_FLATLIB=OFF -DFLATBUFFERS_BUILD_FLATHASH=OFF . && make -j4
|
|
||||||
# - name: test
|
|
||||||
# working-directory: tests
|
|
||||||
# run: bash JavaScriptTest.sh
|
|
||||||
|
|
||||||
build-python:
|
build-python:
|
||||||
name: Build Python
|
name: Build Python
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v1
|
- uses: actions/checkout@v2
|
||||||
- name: test
|
- name: test
|
||||||
working-directory: tests
|
working-directory: tests
|
||||||
run: bash PythonTest.sh
|
run: bash PythonTest.sh
|
||||||
@@ -177,53 +363,97 @@ jobs:
|
|||||||
name: Build Go
|
name: Build Go
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v1
|
- uses: actions/checkout@v2
|
||||||
- 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 -j4
|
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
|
||||||
- name: test
|
- name: test
|
||||||
working-directory: tests
|
working-directory: tests
|
||||||
run: bash GoTest.sh
|
run: bash GoTest.sh
|
||||||
|
|
||||||
#build-csharp:
|
|
||||||
# name: Build CSharp
|
|
||||||
# runs-on: ubuntu-latest
|
|
||||||
# steps:
|
|
||||||
# - uses: actions/checkout@v1
|
|
||||||
# - name: test
|
|
||||||
# working-directory: tests/FlatBuffers.Test
|
|
||||||
# run: bash NetTest.sh
|
|
||||||
|
|
||||||
#build-php:
|
|
||||||
# name: Build PHP
|
|
||||||
# runs-on: ubuntu-latest
|
|
||||||
# steps:
|
|
||||||
# - uses: actions/checkout@v1
|
|
||||||
# - name: flatc
|
|
||||||
# # FIXME: make test script not rely on flatc
|
|
||||||
# run: cmake -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=Release -DFLATBUFFERS_BUILD_TESTS=OFF -DFLATBUFFERS_INSTALL=OFF -DFLATBUFFERS_BUILD_FLATLIB=OFF -DFLATBUFFERS_BUILD_FLATHASH=OFF . && make -j4
|
|
||||||
# - name: test
|
|
||||||
# working-directory: tests
|
|
||||||
# run: |
|
|
||||||
# php phpTest.php
|
|
||||||
# sh phpUnionVectorTest.sh
|
|
||||||
|
|
||||||
build-swift:
|
build-swift:
|
||||||
name: Build Swift
|
name: Build Swift
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v1
|
- uses: actions/checkout@v2
|
||||||
- name: test
|
- name: test
|
||||||
working-directory: tests/FlatBuffers.Test.Swift
|
working-directory: tests/FlatBuffers.Test.Swift
|
||||||
run: sh SwiftTest.sh
|
run: sh SwiftTest.sh
|
||||||
|
|
||||||
|
build-swift-wasm:
|
||||||
|
name: Build Swift Wasm
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
container:
|
||||||
|
image: ghcr.io/swiftwasm/carton:0.15.3
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v2
|
||||||
|
- name: Setup Wasmer
|
||||||
|
uses: wasmerio/setup-wasmer@v1
|
||||||
|
- name: Test
|
||||||
|
working-directory: tests/FlatBuffers.Test.Swift.Wasm
|
||||||
|
run: carton test
|
||||||
|
|
||||||
build-ts:
|
build-ts:
|
||||||
name: Build TS
|
name: Build TS
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v1
|
- uses: actions/checkout@v2
|
||||||
|
- name: flatc
|
||||||
|
# FIXME: make test script not rely on flatc
|
||||||
|
run: cmake -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=Release -DFLATBUFFERS_BUILD_TESTS=OFF -DFLATBUFFERS_INSTALL=OFF -DFLATBUFFERS_BUILD_FLATLIB=OFF -DFLATBUFFERS_BUILD_FLATHASH=OFF . && make -j
|
||||||
- name: compile
|
- name: compile
|
||||||
run: npm run compile
|
run: npm run compile
|
||||||
- name: test
|
- name: test
|
||||||
working-directory: tests
|
working-directory: tests
|
||||||
run: sh TypeScriptTest.sh
|
run: python3 TypeScriptTest.py
|
||||||
|
|
||||||
|
build-dart:
|
||||||
|
name: Build Dart
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v2
|
||||||
|
- uses: dart-lang/setup-dart@v1
|
||||||
|
with:
|
||||||
|
sdk: stable
|
||||||
|
- name: flatc
|
||||||
|
# FIXME: make test script not rely on flatc
|
||||||
|
run: cmake -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=Release -DFLATBUFFERS_BUILD_TESTS=OFF -DFLATBUFFERS_INSTALL=OFF -DFLATBUFFERS_BUILD_FLATLIB=OFF -DFLATBUFFERS_BUILD_FLATHASH=OFF -DFLATBUFFERS_STRICT_MODE=ON . && make -j
|
||||||
|
- name: test
|
||||||
|
working-directory: tests
|
||||||
|
run: bash DartTest.sh
|
||||||
|
|
||||||
|
release-digests:
|
||||||
|
if: startsWith(github.ref, 'refs/tags/')
|
||||||
|
needs: [build-linux, build-windows, build-mac-intel, build-mac-universal]
|
||||||
|
outputs:
|
||||||
|
digests: ${{ steps.hash.outputs.digests }}
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Merge results
|
||||||
|
id: hash
|
||||||
|
env:
|
||||||
|
LINUXGCC_DIGESTS: "${{ needs.build-linux.outputs.digests-gcc }}"
|
||||||
|
LINUXCLANG_DIGESTS: "${{ needs.build-linux.outputs.digests-clang }}"
|
||||||
|
MAC_DIGESTS: "${{ needs.build-mac-universal.outputs.digests }}"
|
||||||
|
MACINTEL_DIGESTS: "${{ needs.build-mac-intel.outputs.digests }}"
|
||||||
|
WINDOWS_DIGESTS: "${{ needs.build-windows.outputs.digests }}"
|
||||||
|
run: |
|
||||||
|
set -euo pipefail
|
||||||
|
echo "$LINUXGCC_DIGESTS" | base64 -d > checksums.txt
|
||||||
|
echo "$LINUXCLANG_DIGESTS" | base64 -d >> checksums.txt
|
||||||
|
echo "$MAC_DIGESTS" | base64 -d >> checksums.txt
|
||||||
|
echo "$MACINTEL_DIGESTS" | base64 -d >> checksums.txt
|
||||||
|
echo "$WINDOWS_DIGESTS" | base64 -d >> checksums.txt
|
||||||
|
echo "::set-output name=digests::$(cat checksums.txt | base64 -w0)"
|
||||||
|
|
||||||
|
provenance:
|
||||||
|
if: startsWith(github.ref, 'refs/tags/')
|
||||||
|
needs: [release-digests]
|
||||||
|
permissions:
|
||||||
|
actions: read # To read the workflow path.
|
||||||
|
id-token: write # To sign the provenance.
|
||||||
|
contents: write # To add assets to a release.
|
||||||
|
uses: slsa-framework/slsa-github-generator/.github/workflows/generator_generic_slsa3.yml@v1.2.0
|
||||||
|
with:
|
||||||
|
base64-subjects: "${{ needs.release-digests.outputs.digests }}"
|
||||||
|
upload-assets: true # Optional: Upload to a new release
|
||||||
|
|||||||
71
.github/workflows/codeql.yml
vendored
Normal file
71
.github/workflows/codeql.yml
vendored
Normal file
@@ -0,0 +1,71 @@
|
|||||||
|
# For most projects, this workflow file will not need changing; you simply need
|
||||||
|
# to commit it to your repository.
|
||||||
|
#
|
||||||
|
# You may wish to alter this file to override the set of languages analyzed,
|
||||||
|
# or to provide custom queries or build logic.
|
||||||
|
#
|
||||||
|
# ******** NOTE ********
|
||||||
|
# We have attempted to detect the languages in your repository. Please check
|
||||||
|
# the `language` matrix defined below to confirm you have the correct set of
|
||||||
|
# supported CodeQL languages.
|
||||||
|
#
|
||||||
|
name: "CodeQL"
|
||||||
|
permissions: read-all
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches: [ master ]
|
||||||
|
pull_request:
|
||||||
|
# The branches below must be a subset of the branches above
|
||||||
|
branches: [ master ]
|
||||||
|
schedule:
|
||||||
|
- cron: '16 20 * * 0'
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
analyze:
|
||||||
|
name: Analyze
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
permissions:
|
||||||
|
actions: read
|
||||||
|
contents: read
|
||||||
|
security-events: write
|
||||||
|
|
||||||
|
strategy:
|
||||||
|
fail-fast: false
|
||||||
|
matrix:
|
||||||
|
language: [ 'cpp' ]
|
||||||
|
# CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby' ]
|
||||||
|
# Learn more about CodeQL language support at https://git.io/codeql-language-support
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Checkout repository
|
||||||
|
uses: actions/checkout@v3
|
||||||
|
|
||||||
|
# Initializes the CodeQL tools for scanning.
|
||||||
|
- name: Initialize CodeQL
|
||||||
|
uses: github/codeql-action/init@v2
|
||||||
|
with:
|
||||||
|
languages: ${{ matrix.language }}
|
||||||
|
# If you wish to specify custom queries, you can do so here or in a config file.
|
||||||
|
# By default, queries listed here will override any specified in a config file.
|
||||||
|
# Prefix the list here with "+" to use these queries and those in the config file.
|
||||||
|
# queries: ./path/to/local/query, your-org/your-repo/queries@main
|
||||||
|
|
||||||
|
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
|
||||||
|
# If this step fails, then you should remove it and run the build manually (see below)
|
||||||
|
# - name: Autobuild
|
||||||
|
# uses: github/codeql-action/autobuild@v2
|
||||||
|
|
||||||
|
# ℹ️ Command-line programs to run using the OS shell.
|
||||||
|
# 📚 https://git.io/JvXDl
|
||||||
|
|
||||||
|
# ✏️ If the Autobuild fails above, remove it and uncomment the following three lines
|
||||||
|
# and modify them (or add more) to build your code if your project
|
||||||
|
# uses a compiled language
|
||||||
|
|
||||||
|
- run: |
|
||||||
|
cmake -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=Release -DFLATBUFFERS_STRICT_MODE=ON .
|
||||||
|
make -j
|
||||||
|
|
||||||
|
- name: Perform CodeQL Analysis
|
||||||
|
uses: github/codeql-action/analyze@v2
|
||||||
5
.github/workflows/label.yml
vendored
5
.github/workflows/label.yml
vendored
@@ -6,10 +6,15 @@
|
|||||||
# https://github.com/actions/labeler
|
# https://github.com/actions/labeler
|
||||||
|
|
||||||
name: Labeler
|
name: Labeler
|
||||||
|
permissions: read-all
|
||||||
|
|
||||||
on: [pull_request_target]
|
on: [pull_request_target]
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
label:
|
label:
|
||||||
|
permissions:
|
||||||
|
contents: read
|
||||||
|
pull-requests: write
|
||||||
|
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
|
|||||||
34
.github/workflows/main.yml
vendored
Normal file
34
.github/workflows/main.yml
vendored
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
name: OSS-Fuzz
|
||||||
|
permissions: read-all
|
||||||
|
|
||||||
|
on:
|
||||||
|
pull_request:
|
||||||
|
branches:
|
||||||
|
- master
|
||||||
|
paths:
|
||||||
|
- include/**
|
||||||
|
- src/**
|
||||||
|
- tests/**.cpp
|
||||||
|
- tests/**.h
|
||||||
|
jobs:
|
||||||
|
Fuzzing:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Build Fuzzers
|
||||||
|
id: build
|
||||||
|
uses: google/oss-fuzz/infra/cifuzz/actions/build_fuzzers@master
|
||||||
|
with:
|
||||||
|
oss-fuzz-project-name: 'flatbuffers'
|
||||||
|
language: c++
|
||||||
|
- name: Run Fuzzers
|
||||||
|
uses: google/oss-fuzz/infra/cifuzz/actions/run_fuzzers@master
|
||||||
|
with:
|
||||||
|
oss-fuzz-project-name: 'flatbuffers'
|
||||||
|
language: c++
|
||||||
|
fuzz-seconds: 60
|
||||||
|
- name: Upload Crash
|
||||||
|
uses: actions/upload-artifact@v1
|
||||||
|
if: failure() && steps.build.outcome == 'success'
|
||||||
|
with:
|
||||||
|
name: artifacts
|
||||||
|
path: ./out/artifacts
|
||||||
55
.github/workflows/scorecards.yml
vendored
Normal file
55
.github/workflows/scorecards.yml
vendored
Normal file
@@ -0,0 +1,55 @@
|
|||||||
|
name: Scorecards supply-chain security
|
||||||
|
on:
|
||||||
|
# Only the default branch is supported.
|
||||||
|
branch_protection_rule:
|
||||||
|
schedule:
|
||||||
|
- cron: '21 2 * * 5'
|
||||||
|
push:
|
||||||
|
branches: [ master ]
|
||||||
|
|
||||||
|
# Declare default permissions as read only.
|
||||||
|
permissions: read-all
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
analysis:
|
||||||
|
name: Scorecards analysis
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
permissions:
|
||||||
|
# Needed to upload the results to code-scanning dashboard.
|
||||||
|
security-events: write
|
||||||
|
actions: read
|
||||||
|
contents: read
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: "Checkout code"
|
||||||
|
uses: actions/checkout@a12a3943b4bdde767164f792f33f40b04645d846 # v3.0.0
|
||||||
|
with:
|
||||||
|
persist-credentials: false
|
||||||
|
|
||||||
|
- name: "Run analysis"
|
||||||
|
uses: ossf/scorecard-action@c1aec4ac820532bab364f02a81873c555a0ba3a1 # v1.0.4
|
||||||
|
with:
|
||||||
|
results_file: results.sarif
|
||||||
|
results_format: sarif
|
||||||
|
# Read-only PAT token. To create it,
|
||||||
|
# follow the steps in https://github.com/ossf/scorecard-action#pat-token-creation.
|
||||||
|
repo_token: ${{ secrets.SCORECARD_READ_TOKEN }}
|
||||||
|
# Publish the results to enable scorecard badges. For more details, see
|
||||||
|
# https://github.com/ossf/scorecard-action#publishing-results.
|
||||||
|
# For private repositories, `publish_results` will automatically be set to `false`,
|
||||||
|
# regardless of the value entered here.
|
||||||
|
publish_results: true
|
||||||
|
|
||||||
|
# Upload the results as artifacts (optional).
|
||||||
|
- name: "Upload artifact"
|
||||||
|
uses: actions/upload-artifact@6673cd052c4cd6fcf4b4e6e60ea986c889389535 # v3.0.0
|
||||||
|
with:
|
||||||
|
name: SARIF file
|
||||||
|
path: results.sarif
|
||||||
|
retention-days: 5
|
||||||
|
|
||||||
|
# Upload the results to GitHub's code scanning dashboard.
|
||||||
|
- name: "Upload to code-scanning"
|
||||||
|
uses: github/codeql-action/upload-sarif@5f532563584d71fdef14ee64d17bafb34f751ce5 # v1.0.26
|
||||||
|
with:
|
||||||
|
sarif_file: results.sarif
|
||||||
6
.github/workflows/stale.yml
vendored
6
.github/workflows/stale.yml
vendored
@@ -1,4 +1,5 @@
|
|||||||
name: Mark stale issues and pull requests
|
name: Mark stale issues and pull requests
|
||||||
|
permissions: read-all
|
||||||
|
|
||||||
on:
|
on:
|
||||||
schedule:
|
schedule:
|
||||||
@@ -10,7 +11,7 @@ jobs:
|
|||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/stale@v3
|
- uses: actions/stale@v4.0.0
|
||||||
with:
|
with:
|
||||||
repo-token: ${{ secrets.GITHUB_TOKEN }}
|
repo-token: ${{ secrets.GITHUB_TOKEN }}
|
||||||
stale-pr-message: 'This pull request is stale because it has been open 6 months with no activity. Please comment or this will be closed in 14 days.'
|
stale-pr-message: 'This pull request is stale because it has been open 6 months with no activity. Please comment or this will be closed in 14 days.'
|
||||||
@@ -18,3 +19,6 @@ jobs:
|
|||||||
days-before-stale: 182 # 6 months
|
days-before-stale: 182 # 6 months
|
||||||
days-before-close: 14
|
days-before-close: 14
|
||||||
operations-per-run: 1500
|
operations-per-run: 1500
|
||||||
|
exempt-issue-labels: not-stale
|
||||||
|
exempt-pr-labels: not-stale
|
||||||
|
exempt-all-milestones: true
|
||||||
|
|||||||
20
.gitignore
vendored
20
.gitignore
vendored
@@ -46,12 +46,16 @@ project.properties
|
|||||||
proguard-project.txt
|
proguard-project.txt
|
||||||
linklint_results
|
linklint_results
|
||||||
Makefile
|
Makefile
|
||||||
|
flatbenchmark
|
||||||
|
flatbenchmark.exe
|
||||||
flatc
|
flatc
|
||||||
flatc.exe
|
flatc.exe
|
||||||
flathash
|
flathash
|
||||||
flathash.exe
|
flathash.exe
|
||||||
flattests
|
flattests
|
||||||
flattests.exe
|
flattests.exe
|
||||||
|
flattests_cpp17
|
||||||
|
flattests_cpp17.exe
|
||||||
flatsamplebinary
|
flatsamplebinary
|
||||||
flatsamplebinary.exe
|
flatsamplebinary.exe
|
||||||
flatsampletext
|
flatsampletext
|
||||||
@@ -74,7 +78,7 @@ tests/php/
|
|||||||
CMakeLists.txt.user
|
CMakeLists.txt.user
|
||||||
CMakeScripts/**
|
CMakeScripts/**
|
||||||
CTestTestfile.cmake
|
CTestTestfile.cmake
|
||||||
FlatbuffersConfigVersion.cmake
|
FlatBuffersConfigVersion.cmake
|
||||||
FlatBuffers.cbp
|
FlatBuffers.cbp
|
||||||
build/Xcode/FlatBuffers.xcodeproj/project.xcworkspace/**
|
build/Xcode/FlatBuffers.xcodeproj/project.xcworkspace/**
|
||||||
build/Xcode/FlatBuffers.xcodeproj/xcuserdata/**
|
build/Xcode/FlatBuffers.xcodeproj/xcuserdata/**
|
||||||
@@ -101,7 +105,10 @@ android/build/
|
|||||||
samples/android/.externalNativeBuild/
|
samples/android/.externalNativeBuild/
|
||||||
samples/android/.gradle/
|
samples/android/.gradle/
|
||||||
samples/android/build/
|
samples/android/build/
|
||||||
js/flatbuffers.mjs
|
js/**/*.js
|
||||||
|
js/**/*.d.ts
|
||||||
|
mjs/**/*.js
|
||||||
|
mjs/**/*.d.ts
|
||||||
/bazel-bin
|
/bazel-bin
|
||||||
/bazel-flatbuffers
|
/bazel-flatbuffers
|
||||||
/bazel-genfiles
|
/bazel-genfiles
|
||||||
@@ -129,10 +136,6 @@ package-lock.json
|
|||||||
/*.ilk
|
/*.ilk
|
||||||
/*.pdb
|
/*.pdb
|
||||||
.clwb
|
.clwb
|
||||||
js/**/*.js
|
|
||||||
js/**/*.d.ts
|
|
||||||
mjs/**/*.js
|
|
||||||
mjs/**/*.d.ts
|
|
||||||
yarn-error.log
|
yarn-error.log
|
||||||
.cache/
|
.cache/
|
||||||
/flatbuffers.lib
|
/flatbuffers.lib
|
||||||
@@ -141,3 +144,8 @@ yarn-error.log
|
|||||||
**/vendor
|
**/vendor
|
||||||
**/go.sum
|
**/go.sum
|
||||||
flatbuffers.pc
|
flatbuffers.pc
|
||||||
|
**/FlatBuffers.Test.Swift.xcodeproj
|
||||||
|
**/html/**
|
||||||
|
**/latex/**
|
||||||
|
# https://cmake.org/cmake/help/latest/module/FetchContent.html#variable:FETCHCONTENT_BASE_DIR
|
||||||
|
_deps/
|
||||||
@@ -115,7 +115,6 @@ matrix:
|
|||||||
-DFLATBUFFERS_CODE_SANITIZE=ON
|
-DFLATBUFFERS_CODE_SANITIZE=ON
|
||||||
- cmake --build . --target all --clean-first -- -j${JOBS}
|
- cmake --build . --target all --clean-first -- -j${JOBS}
|
||||||
- LD_LIBRARY_PATH=$TRAVIS_BUILD_DIR/google/grpc/install/lib ctest --extra-verbose --output-on-failure
|
- LD_LIBRARY_PATH=$TRAVIS_BUILD_DIR/google/grpc/install/lib ctest --extra-verbose --output-on-failure
|
||||||
- bash scripts/check-generate-code.sh
|
|
||||||
|
|
||||||
- language: cpp
|
- language: cpp
|
||||||
os: osx
|
os: osx
|
||||||
@@ -140,7 +139,6 @@ matrix:
|
|||||||
-DFLATBUFFERS_CODE_SANITIZE=ON
|
-DFLATBUFFERS_CODE_SANITIZE=ON
|
||||||
- cmake --build . -- -j${JOBS}
|
- cmake --build . -- -j${JOBS}
|
||||||
- DYLD_LIBRARY_PATH=$TRAVIS_BUILD_DIR/google/grpc/install/lib ctest --extra-verbose --output-on-failure
|
- DYLD_LIBRARY_PATH=$TRAVIS_BUILD_DIR/google/grpc/install/lib ctest --extra-verbose --output-on-failure
|
||||||
- bash scripts/check-generate-code.sh
|
|
||||||
|
|
||||||
- <<: *conan-linux-master
|
- <<: *conan-linux-master
|
||||||
env: CONAN_GCC_VERSIONS=8 CONAN_DOCKER_IMAGE=conanio/gcc8
|
env: CONAN_GCC_VERSIONS=8 CONAN_DOCKER_IMAGE=conanio/gcc8
|
||||||
|
|||||||
@@ -1,45 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
#
|
|
||||||
# Copyright 2018 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.
|
|
||||||
set -e
|
|
||||||
|
|
||||||
docker build -t build_cpp_image -f tests/docker/Dockerfile.testing.cpp.debian_buster .
|
|
||||||
# Run tests with sanitizers (--cap-add SYS_PTRACE), both GCC and Clang.
|
|
||||||
cpp_test_args="--cap-add SYS_PTRACE build_cpp_image sh ./tests/docker/cpp_test.run.sh Debug"
|
|
||||||
docker run --rm $cpp_test_args
|
|
||||||
docker run --rm --env CC=/usr/bin/clang --env CXX=/usr/bin/clang++ $cpp_test_args
|
|
||||||
# Build flatc on debian once to speed up the test loop below.
|
|
||||||
docker run --name flatc_container build_cpp_image sh ./tests/docker/build_flatc.run.sh Debug
|
|
||||||
# All dependent dockers refer to 'flatc_debian_stretch'.
|
|
||||||
docker cp flatc_container:/flatbuffers/flatc flatc_debian_stretch
|
|
||||||
|
|
||||||
for f in $(ls tests/docker/languages | sort)
|
|
||||||
do
|
|
||||||
# docker pull sometimes fails for unknown reasons, probably travisci-related. this retries the pull we need a few times.
|
|
||||||
REQUIRED_BASE_IMAGE=$(cat tests/docker/languages/${f} | head -n 1 | awk ' { print $2 } ')
|
|
||||||
|
|
||||||
set +e
|
|
||||||
n=0
|
|
||||||
until [ $n -ge 5 ]
|
|
||||||
do
|
|
||||||
docker pull $REQUIRED_BASE_IMAGE && break
|
|
||||||
n=$[$n+1]
|
|
||||||
sleep 1
|
|
||||||
done
|
|
||||||
set -e
|
|
||||||
|
|
||||||
docker build -t $(echo ${f} | cut -f 3- -d .) -f tests/docker/languages/${f} .
|
|
||||||
echo "TEST OK: ${f}"
|
|
||||||
done
|
|
||||||
@@ -1,33 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
#
|
|
||||||
# Copyright 2018 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.
|
|
||||||
set -e
|
|
||||||
|
|
||||||
if [ -n "$1" ]; then
|
|
||||||
scan_dir="$1"
|
|
||||||
else
|
|
||||||
scan_dir="$( pwd )"
|
|
||||||
fi
|
|
||||||
|
|
||||||
py_checker="$0.py"
|
|
||||||
|
|
||||||
echo "scan root directory = '$scan_dir'"
|
|
||||||
python3 --version
|
|
||||||
# Scan recursively and search all *.cpp and *.h files using regex patterns.
|
|
||||||
# Assume that script running from a root of Flatbuffers working dir.
|
|
||||||
python3 $py_checker "ascii" "$scan_dir/include" "\.h$"
|
|
||||||
python3 $py_checker "ascii" "$scan_dir/src" "\.cpp$"
|
|
||||||
python3 $py_checker "ascii" "$scan_dir/tests" "\.h$"
|
|
||||||
python3 $py_checker "utf-8" "$scan_dir/tests" "\.cpp$"
|
|
||||||
@@ -1,35 +0,0 @@
|
|||||||
import os
|
|
||||||
import re
|
|
||||||
import sys
|
|
||||||
|
|
||||||
def check_encoding(encoding, scan_dir, regex_pattern):
|
|
||||||
fname = None
|
|
||||||
try:
|
|
||||||
assert encoding in ['ascii', 'utf-8'], "unexpected encoding"
|
|
||||||
cmp = re.compile(regex_pattern)
|
|
||||||
for root, dirs, files in os.walk(scan_dir):
|
|
||||||
fname = root
|
|
||||||
cmp_list = [f for f in files if cmp.search(f) is not None]
|
|
||||||
for f in cmp_list:
|
|
||||||
fname = os.path.join(root, f)
|
|
||||||
with open(fname, mode='rb') as test_file:
|
|
||||||
btext = test_file.read()
|
|
||||||
# check encoding
|
|
||||||
btext.decode(encoding=encoding, errors="strict")
|
|
||||||
if encoding == "utf-8" and btext.startswith(b'\xEF\xBB\xBF'):
|
|
||||||
raise ValueError("unexpected BOM in file")
|
|
||||||
# check LF line endings
|
|
||||||
LF = btext.count(b'\n')
|
|
||||||
CR = btext.count(b'\r')
|
|
||||||
if CR!=0:
|
|
||||||
raise ValueError("invalid line endings: LF({})/CR({})".format(LF, CR))
|
|
||||||
except Exception as err:
|
|
||||||
print("ERROR with [{}]: {}".format(fname, err))
|
|
||||||
return -1
|
|
||||||
else:
|
|
||||||
return 0
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
# python check-sources.sh.py 'ascii' '.' '.*\.(cpp|h)$'
|
|
||||||
res = check_encoding(sys.argv[1], sys.argv[2], sys.argv[3])
|
|
||||||
sys.exit(0 if res == 0 else -1)
|
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
|
|
||||||
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
|
||||||
PROD_REPOSITORY="https://upload.pypi.org/legacy/"
|
|
||||||
TEST_REPOSITORY="https://test.pypi.org/legacy/"
|
|
||||||
|
|
||||||
twine upload \
|
|
||||||
--username "$PYPI_USERNAME" \
|
|
||||||
--password "$PYPI_PASSWORD" \
|
|
||||||
--repository-url "$PROD_REPOSITORY" \
|
|
||||||
"$DIR/../python/dist/"*
|
|
||||||
|
|
||||||
@@ -1,52 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
#
|
|
||||||
# Copyright 2021 Google Inc. All rights reserved.
|
|
||||||
#
|
|
||||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
# you may not use this file except in compliance with the License.
|
|
||||||
# You may obtain a copy of the License at
|
|
||||||
#
|
|
||||||
# http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
#
|
|
||||||
# Unless required by applicable law or agreed to in writing, software
|
|
||||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
# See the License for the specific language governing permissions and
|
|
||||||
# limitations under the License.
|
|
||||||
|
|
||||||
set -e
|
|
||||||
|
|
||||||
# HACKY solution to make nodejs work.
|
|
||||||
source ~/.nvm/nvm.sh
|
|
||||||
nvm alias default node
|
|
||||||
nvm use default
|
|
||||||
|
|
||||||
sh src/clang-format-git.sh
|
|
||||||
|
|
||||||
# Check formatting for go lang
|
|
||||||
|
|
||||||
cd go
|
|
||||||
gofmt -w .
|
|
||||||
cd ..
|
|
||||||
cd grpc/examples/go
|
|
||||||
sh format.sh
|
|
||||||
cd ../../..
|
|
||||||
|
|
||||||
node_modules/.bin/eslint ts/** --ext .ts --quiet --fix
|
|
||||||
|
|
||||||
#PYTHON IS DISABLED UNTIL WE CREATE A .pylintrc FILE FOR IT
|
|
||||||
pylint python/** --disable=all
|
|
||||||
|
|
||||||
swiftformat --config swift.swiftformat .
|
|
||||||
|
|
||||||
|
|
||||||
if ! git diff --quiet; then
|
|
||||||
echo >&2
|
|
||||||
echo "ERROR: ********************************************************" >&2
|
|
||||||
echo "ERROR: The following differences were found after running" >&2
|
|
||||||
echo "ERROR: .travis/format_check.sh script. Maybe you forgot to format" >&2
|
|
||||||
echo "ERROR: the code after making changes? please check Formatters.md" >&2
|
|
||||||
echo "ERROR: ********************************************************" >&2
|
|
||||||
echo >&2
|
|
||||||
git diff --binary --exit-code
|
|
||||||
fi
|
|
||||||
@@ -1,90 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
#
|
|
||||||
# Copyright 2020 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.
|
|
||||||
|
|
||||||
set -e
|
|
||||||
set -x
|
|
||||||
|
|
||||||
# install devtools
|
|
||||||
install_languages() {
|
|
||||||
sudo apt update
|
|
||||||
|
|
||||||
# Install nodeJS and yarn
|
|
||||||
wget https://raw.githubusercontent.com/creationix/nvm/v0.31.0/nvm.sh -O ~/.nvm/nvm.sh
|
|
||||||
source ~/.nvm/nvm.sh
|
|
||||||
nvm install node
|
|
||||||
node --version
|
|
||||||
curl -o- -L https://yarnpkg.com/install.sh | bash
|
|
||||||
export PATH="$HOME/.yarn/bin:$PATH"
|
|
||||||
yarn config set prefix ~/.yarn -g
|
|
||||||
export PATH="$HOME/.yarn/bin:$HOME/.config/yarn/global/node_modules/.bin:$PATH"
|
|
||||||
|
|
||||||
# Install swift
|
|
||||||
sudo apt-get install \
|
|
||||||
binutils \
|
|
||||||
git \
|
|
||||||
libc6-dev \
|
|
||||||
libcurl3 \
|
|
||||||
libedit2 \
|
|
||||||
libgcc-5-dev \
|
|
||||||
libpython2.7 \
|
|
||||||
libsqlite3-0 \
|
|
||||||
libstdc++-5-dev \
|
|
||||||
libxml2 \
|
|
||||||
pkg-config \
|
|
||||||
tzdata \
|
|
||||||
zlib1g-dev
|
|
||||||
|
|
||||||
SWIFT_URL=https://swift.org/builds/swift-5.3.1-release/ubuntu1604/swift-5.3.1-RELEASE/swift-5.3.1-RELEASE-ubuntu16.04.tar.gz
|
|
||||||
curl -fSsL "$SWIFT_URL" -o swift.tar.gz
|
|
||||||
|
|
||||||
mkdir ~/swiftbuild
|
|
||||||
tar -xvzf swift.tar.gz -C ~/swiftbuild
|
|
||||||
|
|
||||||
export PATH="~/swiftbuild/swift-5.3.1-RELEASE-ubuntu16.04/usr/bin:$PATH"
|
|
||||||
|
|
||||||
|
|
||||||
mkdir ~/gobuild
|
|
||||||
wget -c https://golang.org/dl/go1.15.2.linux-amd64.tar.gz
|
|
||||||
tar -xvzf go1.15.2.linux-amd64.tar.gz -C ~/gobuild
|
|
||||||
|
|
||||||
export PATH="~/gobuild/go/bin:$PATH"
|
|
||||||
|
|
||||||
swift --version
|
|
||||||
go version
|
|
||||||
yarn -v
|
|
||||||
node -v
|
|
||||||
}
|
|
||||||
|
|
||||||
install_formatters() {
|
|
||||||
# installing swift formatter
|
|
||||||
git clone --depth 1 --branch 0.47.4 https://github.com/nicklockwood/SwiftFormat.git
|
|
||||||
cd SwiftFormat
|
|
||||||
swift build -c release
|
|
||||||
sudo cp .build/release/swiftformat /usr/local/bin/swiftformat
|
|
||||||
cd ..
|
|
||||||
|
|
||||||
which yarn
|
|
||||||
which node
|
|
||||||
yarn -v
|
|
||||||
node -v
|
|
||||||
|
|
||||||
yarn install
|
|
||||||
pip install pylint
|
|
||||||
}
|
|
||||||
|
|
||||||
install_languages
|
|
||||||
export PATH="~/swift/swift/usr/bin:$PATH"
|
|
||||||
install_formatters
|
|
||||||
33
BUILD.bazel
33
BUILD.bazel
@@ -8,8 +8,23 @@ package(
|
|||||||
|
|
||||||
exports_files([
|
exports_files([
|
||||||
"LICENSE",
|
"LICENSE",
|
||||||
|
"tsconfig.json",
|
||||||
])
|
])
|
||||||
|
|
||||||
|
config_setting(
|
||||||
|
name = "platform_freebsd",
|
||||||
|
constraint_values = [
|
||||||
|
"@platforms//os:freebsd",
|
||||||
|
],
|
||||||
|
)
|
||||||
|
|
||||||
|
config_setting(
|
||||||
|
name = "platform_openbsd",
|
||||||
|
constraint_values = [
|
||||||
|
"@platforms//os:openbsd",
|
||||||
|
],
|
||||||
|
)
|
||||||
|
|
||||||
# Public flatc library to compile flatbuffer files at runtime.
|
# Public flatc library to compile flatbuffer files at runtime.
|
||||||
cc_library(
|
cc_library(
|
||||||
name = "flatbuffers",
|
name = "flatbuffers",
|
||||||
@@ -23,9 +38,18 @@ cc_library(
|
|||||||
filegroup(
|
filegroup(
|
||||||
name = "public_headers",
|
name = "public_headers",
|
||||||
srcs = [
|
srcs = [
|
||||||
|
"include/flatbuffers/allocator.h",
|
||||||
|
"include/flatbuffers/array.h",
|
||||||
"include/flatbuffers/base.h",
|
"include/flatbuffers/base.h",
|
||||||
|
"include/flatbuffers/bfbs_generator.h",
|
||||||
|
"include/flatbuffers/buffer.h",
|
||||||
|
"include/flatbuffers/buffer_ref.h",
|
||||||
"include/flatbuffers/code_generators.h",
|
"include/flatbuffers/code_generators.h",
|
||||||
|
"include/flatbuffers/default_allocator.h",
|
||||||
|
"include/flatbuffers/detached_buffer.h",
|
||||||
|
"include/flatbuffers/flatbuffer_builder.h",
|
||||||
"include/flatbuffers/flatbuffers.h",
|
"include/flatbuffers/flatbuffers.h",
|
||||||
|
"include/flatbuffers/flex_flat_util.h",
|
||||||
"include/flatbuffers/flexbuffers.h",
|
"include/flatbuffers/flexbuffers.h",
|
||||||
"include/flatbuffers/grpc.h",
|
"include/flatbuffers/grpc.h",
|
||||||
"include/flatbuffers/hash.h",
|
"include/flatbuffers/hash.h",
|
||||||
@@ -35,7 +59,13 @@ filegroup(
|
|||||||
"include/flatbuffers/reflection_generated.h",
|
"include/flatbuffers/reflection_generated.h",
|
||||||
"include/flatbuffers/registry.h",
|
"include/flatbuffers/registry.h",
|
||||||
"include/flatbuffers/stl_emulation.h",
|
"include/flatbuffers/stl_emulation.h",
|
||||||
|
"include/flatbuffers/string.h",
|
||||||
|
"include/flatbuffers/struct.h",
|
||||||
|
"include/flatbuffers/table.h",
|
||||||
"include/flatbuffers/util.h",
|
"include/flatbuffers/util.h",
|
||||||
|
"include/flatbuffers/vector.h",
|
||||||
|
"include/flatbuffers/vector_downward.h",
|
||||||
|
"include/flatbuffers/verifier.h",
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -51,6 +81,7 @@ cc_library(
|
|||||||
# Public flatc compiler.
|
# Public flatc compiler.
|
||||||
cc_binary(
|
cc_binary(
|
||||||
name = "flatc",
|
name = "flatc",
|
||||||
|
data = ["//reflection:reflection_fbs_schema"],
|
||||||
deps = [
|
deps = [
|
||||||
"//src:flatc",
|
"//src:flatc",
|
||||||
],
|
],
|
||||||
@@ -73,6 +104,8 @@ cc_library(
|
|||||||
"include/flatbuffers/flexbuffers.h",
|
"include/flatbuffers/flexbuffers.h",
|
||||||
"include/flatbuffers/stl_emulation.h",
|
"include/flatbuffers/stl_emulation.h",
|
||||||
"include/flatbuffers/util.h",
|
"include/flatbuffers/util.h",
|
||||||
|
"include/flatbuffers/vector.h",
|
||||||
|
"include/flatbuffers/verifier.h",
|
||||||
],
|
],
|
||||||
linkstatic = 1,
|
linkstatic = 1,
|
||||||
strip_include_prefix = "/include",
|
strip_include_prefix = "/include",
|
||||||
|
|||||||
22
CHANGELOG.md
Normal file
22
CHANGELOG.md
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
# Flatbuffers Change Log
|
||||||
|
|
||||||
|
All major or breaking changes will be documented in this file, as well as any
|
||||||
|
new features that should be highlighted. Minor fixes or improvements are not
|
||||||
|
necessarily listed.
|
||||||
|
|
||||||
|
## 2.0.7 (Aug 22 2022)
|
||||||
|
|
||||||
|
* This is the first version with an explicit change log, so all the previous
|
||||||
|
features will not be listed.
|
||||||
|
|
||||||
|
* Verifier now checks that buffers are at least the minimum size required to be
|
||||||
|
a flatbuffers (12 bytes). This includes nested flatbuffers, which previously
|
||||||
|
could be declared valid at size 0.
|
||||||
|
|
||||||
|
* Annotated binaries. Given a flatbuffer binary and a schema (or binary schema)
|
||||||
|
one can generate an annotated flatbuffer (.afb) to describe each byte in the
|
||||||
|
binary with schema metadata and value.
|
||||||
|
|
||||||
|
* First binary schema generator (Lua) to generate Lua code via a .bfbs file.
|
||||||
|
This is mostly an implementation detail of flatc internals, but will be slowly
|
||||||
|
applied to the other language generators.
|
||||||
@@ -95,7 +95,7 @@ function(build_flatbuffers flatbuffers_schemas
|
|||||||
set(generated_include ${generated_includes_dir}/${filename}_generated.h)
|
set(generated_include ${generated_includes_dir}/${filename}_generated.h)
|
||||||
add_custom_command(
|
add_custom_command(
|
||||||
OUTPUT ${generated_include}
|
OUTPUT ${generated_include}
|
||||||
COMMAND ${FLATC} ${FLATC_ARGS}
|
COMMAND ${FLATC} ${FLATC_SCHEMA_ARGS}
|
||||||
-o ${generated_includes_dir}
|
-o ${generated_includes_dir}
|
||||||
${include_params}
|
${include_params}
|
||||||
-c ${schema}
|
-c ${schema}
|
||||||
@@ -230,16 +230,30 @@ function(flatbuffers_generate_headers)
|
|||||||
foreach(schema ${FLATBUFFERS_GENERATE_HEADERS_SCHEMAS})
|
foreach(schema ${FLATBUFFERS_GENERATE_HEADERS_SCHEMAS})
|
||||||
get_filename_component(filename ${schema} NAME_WE)
|
get_filename_component(filename ${schema} NAME_WE)
|
||||||
set(generated_include "${generated_include_dir}/${filename}_generated.h")
|
set(generated_include "${generated_include_dir}/${filename}_generated.h")
|
||||||
|
|
||||||
|
# Generate files for grpc if needed
|
||||||
|
set(generated_source_file)
|
||||||
|
if("${FLATBUFFERS_GENERATE_HEADERS_FLAGS}" MATCHES "--grpc")
|
||||||
|
# Check if schema file contain a rpc_service definition
|
||||||
|
file(STRINGS ${schema} has_grpc REGEX "rpc_service")
|
||||||
|
if(has_grpc)
|
||||||
|
list(APPEND generated_include "${generated_include_dir}/${filename}.grpc.fb.h")
|
||||||
|
set(generated_source_file "${generated_include_dir}/${filename}.grpc.fb.cc")
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
|
|
||||||
add_custom_command(
|
add_custom_command(
|
||||||
OUTPUT ${generated_include}
|
OUTPUT ${generated_include} ${generated_source_file}
|
||||||
COMMAND ${FLATC} ${FLATC_ARGS}
|
COMMAND ${FLATC} ${FLATC_ARGS}
|
||||||
-o ${generated_include_dir}
|
-o ${generated_include_dir}
|
||||||
${include_params}
|
${include_params}
|
||||||
-c ${schema}
|
-c ${schema}
|
||||||
${FLATBUFFERS_GENERATE_HEADERS_FLAGS}
|
${FLATBUFFERS_GENERATE_HEADERS_FLAGS}
|
||||||
DEPENDS ${FLATC_TARGET} ${schema}
|
DEPENDS ${FLATC_TARGET} ${schema}
|
||||||
WORKING_DIRECTORY "${working_dir}")
|
WORKING_DIRECTORY "${working_dir}"
|
||||||
|
COMMENT "Building ${schema} flatbuffers...")
|
||||||
list(APPEND all_generated_header_files ${generated_include})
|
list(APPEND all_generated_header_files ${generated_include})
|
||||||
|
list(APPEND all_generated_source_files ${generated_source_file})
|
||||||
|
|
||||||
# Geneate the binary flatbuffers schemas if instructed to.
|
# Geneate the binary flatbuffers schemas if instructed to.
|
||||||
if (NOT ${FLATBUFFERS_GENERATE_HEADERS_BINARY_SCHEMAS_DIR} STREQUAL "")
|
if (NOT ${FLATBUFFERS_GENERATE_HEADERS_BINARY_SCHEMAS_DIR} STREQUAL "")
|
||||||
@@ -264,6 +278,7 @@ function(flatbuffers_generate_headers)
|
|||||||
INTERFACE
|
INTERFACE
|
||||||
${all_generated_header_files}
|
${all_generated_header_files}
|
||||||
${all_generated_binary_files}
|
${all_generated_binary_files}
|
||||||
|
${all_generated_source_files}
|
||||||
${FLATBUFFERS_GENERATE_HEADERS_SCHEMAS})
|
${FLATBUFFERS_GENERATE_HEADERS_SCHEMAS})
|
||||||
add_dependencies(
|
add_dependencies(
|
||||||
${FLATBUFFERS_GENERATE_HEADERS_TARGET}
|
${FLATBUFFERS_GENERATE_HEADERS_TARGET}
|
||||||
@@ -278,6 +293,10 @@ function(flatbuffers_generate_headers)
|
|||||||
TREE "${generated_target_dir}"
|
TREE "${generated_target_dir}"
|
||||||
PREFIX "Flatbuffers/Generated/Headers Files"
|
PREFIX "Flatbuffers/Generated/Headers Files"
|
||||||
FILES ${all_generated_header_files})
|
FILES ${all_generated_header_files})
|
||||||
|
source_group(
|
||||||
|
TREE "${generated_target_dir}"
|
||||||
|
PREFIX "Flatbuffers/Generated/Source Files"
|
||||||
|
FILES ${all_generated_source_files})
|
||||||
source_group(
|
source_group(
|
||||||
TREE ${working_dir}
|
TREE ${working_dir}
|
||||||
PREFIX "Flatbuffers/Schemas"
|
PREFIX "Flatbuffers/Schemas"
|
||||||
@@ -371,7 +390,8 @@ function(flatbuffers_generate_binary_files)
|
|||||||
-b ${FLATBUFFERS_GENERATE_BINARY_FILES_SCHEMA} ${json_file}
|
-b ${FLATBUFFERS_GENERATE_BINARY_FILES_SCHEMA} ${json_file}
|
||||||
${FLATBUFFERS_GENERATE_BINARY_FILES_FLAGS}
|
${FLATBUFFERS_GENERATE_BINARY_FILES_FLAGS}
|
||||||
DEPENDS ${FLATC_TARGET} ${json_file}
|
DEPENDS ${FLATC_TARGET} ${json_file}
|
||||||
WORKING_DIRECTORY "${working_dir}")
|
WORKING_DIRECTORY "${working_dir}"
|
||||||
|
COMMENT "Building ${json_file} binary flatbuffers...")
|
||||||
list(APPEND all_generated_binary_files ${generated_binary_file})
|
list(APPEND all_generated_binary_files ${generated_binary_file})
|
||||||
endforeach()
|
endforeach()
|
||||||
|
|
||||||
|
|||||||
780
CMake/CMakeLists_legacy.cmake.in
Normal file
780
CMake/CMakeLists_legacy.cmake.in
Normal file
@@ -0,0 +1,780 @@
|
|||||||
|
# This was the legacy <root>/CMakeLists.txt that supported cmake version 2.8.12.
|
||||||
|
# It was originally copied on Jan 30 2022, and is conditionally included in the
|
||||||
|
# current <root>/CMakeLists.txt if the cmake version used is older than the new
|
||||||
|
# minimum version.
|
||||||
|
#
|
||||||
|
# Only add to this file to fix immediate issues or if a change cannot be made
|
||||||
|
# <root>/CMakeList.txt in a compatible way.
|
||||||
|
|
||||||
|
if (POLICY CMP0048)
|
||||||
|
cmake_policy(SET CMP0048 NEW)
|
||||||
|
if(CMAKE_VERSION VERSION_LESS 3.9)
|
||||||
|
project(FlatBuffers
|
||||||
|
VERSION 2.0.0
|
||||||
|
LANGUAGES CXX)
|
||||||
|
else()
|
||||||
|
project(FlatBuffers
|
||||||
|
DESCRIPTION "Flatbuffers serialization library"
|
||||||
|
VERSION 2.0.0
|
||||||
|
LANGUAGES CXX)
|
||||||
|
endif()
|
||||||
|
else()
|
||||||
|
project(FlatBuffers)
|
||||||
|
endif (POLICY CMP0048)
|
||||||
|
|
||||||
|
include(CMake/Version.cmake)
|
||||||
|
|
||||||
|
# generate compile_commands.json
|
||||||
|
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
||||||
|
|
||||||
|
# NOTE: Code coverage only works on Linux & OSX.
|
||||||
|
option(FLATBUFFERS_CODE_COVERAGE "Enable the code coverage build option." OFF)
|
||||||
|
option(FLATBUFFERS_BUILD_TESTS "Enable the build of tests and samples." ON)
|
||||||
|
option(FLATBUFFERS_INSTALL "Enable the installation of targets." ON)
|
||||||
|
option(FLATBUFFERS_BUILD_FLATLIB "Enable the build of the flatbuffers library"
|
||||||
|
ON)
|
||||||
|
option(FLATBUFFERS_BUILD_FLATC "Enable the build of the flatbuffers compiler"
|
||||||
|
ON)
|
||||||
|
option(FLATBUFFERS_STATIC_FLATC "Build flatbuffers compiler with -static flag"
|
||||||
|
OFF)
|
||||||
|
option(FLATBUFFERS_BUILD_FLATHASH "Enable the build of flathash" ON)
|
||||||
|
option(FLATBUFFERS_BUILD_BENCHMARKS "Enable the build of flatbenchmark. \"
|
||||||
|
Requires C++11."
|
||||||
|
OFF)
|
||||||
|
option(FLATBUFFERS_BUILD_GRPCTEST "Enable the build of grpctest" OFF)
|
||||||
|
option(FLATBUFFERS_BUILD_SHAREDLIB
|
||||||
|
"Enable the build of the flatbuffers shared library"
|
||||||
|
OFF)
|
||||||
|
option(FLATBUFFERS_LIBCXX_WITH_CLANG "Force libc++ when using Clang" ON)
|
||||||
|
# NOTE: Sanitizer check only works on Linux & OSX (gcc & llvm).
|
||||||
|
option(FLATBUFFERS_CODE_SANITIZE
|
||||||
|
"Add '-fsanitize' flags to 'flattests' and 'flatc' targets."
|
||||||
|
OFF)
|
||||||
|
option(FLATBUFFERS_PACKAGE_REDHAT
|
||||||
|
"Build an rpm using the 'package' target."
|
||||||
|
OFF)
|
||||||
|
option(FLATBUFFERS_PACKAGE_DEBIAN
|
||||||
|
"Build an deb using the 'package' target."
|
||||||
|
OFF)
|
||||||
|
option(FLATBUFFERS_BUILD_CPP17
|
||||||
|
"Enable the build of c++17 test target. \"
|
||||||
|
Requirements: Clang6, GCC7, MSVC2017 (_MSC_VER >= 1914) or higher."
|
||||||
|
OFF)
|
||||||
|
option(FLATBUFFERS_BUILD_LEGACY
|
||||||
|
"Run C++ code generator with '--cpp-std c++0x' switch."
|
||||||
|
OFF)
|
||||||
|
option(FLATBUFFERS_ENABLE_PCH
|
||||||
|
"Enable precompile headers support for 'flatbuffers' and 'flatc'. \"
|
||||||
|
Only work if CMake supports 'target_precompile_headers'. \"
|
||||||
|
This can speed up compilation time."
|
||||||
|
OFF)
|
||||||
|
option(FLATBUFFERS_SKIP_MONSTER_EXTRA
|
||||||
|
"Skip generating monster_extra.fbs that contains non-supported numerical\"
|
||||||
|
types." OFF)
|
||||||
|
option(FLATBUFFERS_OSX_BUILD_UNIVERSAL
|
||||||
|
"Enable the build for multiple architectures on OS X (arm64, x86_64)."
|
||||||
|
ON)
|
||||||
|
|
||||||
|
if(NOT FLATBUFFERS_BUILD_FLATC AND FLATBUFFERS_BUILD_TESTS)
|
||||||
|
message(WARNING
|
||||||
|
"Cannot build tests without building the compiler. Tests will be disabled.")
|
||||||
|
set(FLATBUFFERS_BUILD_TESTS OFF)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(DEFINED FLATBUFFERS_MAX_PARSING_DEPTH)
|
||||||
|
# Override the default recursion depth limit.
|
||||||
|
add_definitions(-DFLATBUFFERS_MAX_PARSING_DEPTH=${FLATBUFFERS_MAX_PARSING_DEPTH})
|
||||||
|
message(STATUS "FLATBUFFERS_MAX_PARSING_DEPTH: ${FLATBUFFERS_MAX_PARSING_DEPTH}")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
# Auto-detect locale-narrow 'strtod_l' and 'strtoull_l' functions.
|
||||||
|
if(NOT DEFINED FLATBUFFERS_LOCALE_INDEPENDENT)
|
||||||
|
include(CheckCXXSymbolExists)
|
||||||
|
|
||||||
|
set(FLATBUFFERS_LOCALE_INDEPENDENT 0)
|
||||||
|
if(MSVC)
|
||||||
|
check_cxx_symbol_exists(_strtof_l stdlib.h FLATBUFFERS_HAS_STRTOF_L)
|
||||||
|
check_cxx_symbol_exists(_strtoui64_l stdlib.h FLATBUFFERS_HAS_STRTOULL_L)
|
||||||
|
else()
|
||||||
|
check_cxx_symbol_exists(strtof_l stdlib.h FLATBUFFERS_HAS_STRTOF_L)
|
||||||
|
check_cxx_symbol_exists(strtoull_l stdlib.h FLATBUFFERS_HAS_STRTOULL_L)
|
||||||
|
endif()
|
||||||
|
if(FLATBUFFERS_HAS_STRTOF_L AND FLATBUFFERS_HAS_STRTOULL_L)
|
||||||
|
set(FLATBUFFERS_LOCALE_INDEPENDENT 1)
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
|
add_definitions(-DFLATBUFFERS_LOCALE_INDEPENDENT=$<BOOL:${FLATBUFFERS_LOCALE_INDEPENDENT}>)
|
||||||
|
|
||||||
|
set(FlatBuffers_Library_SRCS
|
||||||
|
include/flatbuffers/allocator.h
|
||||||
|
include/flatbuffers/array.h
|
||||||
|
include/flatbuffers/base.h
|
||||||
|
include/flatbuffers/bfbs_generator.h
|
||||||
|
include/flatbuffers/buffer.h
|
||||||
|
include/flatbuffers/buffer_ref.h
|
||||||
|
include/flatbuffers/default_allocator.h
|
||||||
|
include/flatbuffers/detached_buffer.h
|
||||||
|
include/flatbuffers/flatbuffer_builder.h
|
||||||
|
include/flatbuffers/flatbuffers.h
|
||||||
|
include/flatbuffers/flexbuffers.h
|
||||||
|
include/flatbuffers/hash.h
|
||||||
|
include/flatbuffers/idl.h
|
||||||
|
include/flatbuffers/minireflect.h
|
||||||
|
include/flatbuffers/reflection.h
|
||||||
|
include/flatbuffers/reflection_generated.h
|
||||||
|
include/flatbuffers/registry.h
|
||||||
|
include/flatbuffers/stl_emulation.h
|
||||||
|
include/flatbuffers/string.h
|
||||||
|
include/flatbuffers/struct.h
|
||||||
|
include/flatbuffers/table.h
|
||||||
|
include/flatbuffers/util.h
|
||||||
|
include/flatbuffers/vector.h
|
||||||
|
include/flatbuffers/vector_downward.h
|
||||||
|
include/flatbuffers/verifier.h
|
||||||
|
src/idl_parser.cpp
|
||||||
|
src/idl_gen_text.cpp
|
||||||
|
src/reflection.cpp
|
||||||
|
src/util.cpp
|
||||||
|
)
|
||||||
|
|
||||||
|
set(FlatBuffers_Compiler_SRCS
|
||||||
|
${FlatBuffers_Library_SRCS}
|
||||||
|
src/idl_gen_cpp.cpp
|
||||||
|
src/idl_gen_csharp.cpp
|
||||||
|
src/idl_gen_dart.cpp
|
||||||
|
src/idl_gen_kotlin.cpp
|
||||||
|
src/idl_gen_go.cpp
|
||||||
|
src/idl_gen_java.cpp
|
||||||
|
src/idl_gen_ts.cpp
|
||||||
|
src/idl_gen_php.cpp
|
||||||
|
src/idl_gen_python.cpp
|
||||||
|
src/idl_gen_lobster.cpp
|
||||||
|
src/idl_gen_lua.cpp
|
||||||
|
src/idl_gen_rust.cpp
|
||||||
|
src/idl_gen_fbs.cpp
|
||||||
|
src/idl_gen_grpc.cpp
|
||||||
|
src/idl_gen_json_schema.cpp
|
||||||
|
src/idl_gen_swift.cpp
|
||||||
|
src/flatc.cpp
|
||||||
|
src/flatc_main.cpp
|
||||||
|
src/bfbs_gen.h
|
||||||
|
src/bfbs_gen_lua.h
|
||||||
|
include/flatbuffers/code_generators.h
|
||||||
|
src/bfbs_gen_lua.cpp
|
||||||
|
src/code_generators.cpp
|
||||||
|
grpc/src/compiler/schema_interface.h
|
||||||
|
grpc/src/compiler/cpp_generator.h
|
||||||
|
grpc/src/compiler/cpp_generator.cc
|
||||||
|
grpc/src/compiler/go_generator.h
|
||||||
|
grpc/src/compiler/go_generator.cc
|
||||||
|
grpc/src/compiler/java_generator.h
|
||||||
|
grpc/src/compiler/java_generator.cc
|
||||||
|
grpc/src/compiler/python_generator.h
|
||||||
|
grpc/src/compiler/python_generator.cc
|
||||||
|
grpc/src/compiler/swift_generator.h
|
||||||
|
grpc/src/compiler/swift_generator.cc
|
||||||
|
grpc/src/compiler/ts_generator.h
|
||||||
|
grpc/src/compiler/ts_generator.cc
|
||||||
|
)
|
||||||
|
|
||||||
|
set(FlatHash_SRCS
|
||||||
|
include/flatbuffers/hash.h
|
||||||
|
src/flathash.cpp
|
||||||
|
)
|
||||||
|
|
||||||
|
set(FlatBuffers_Tests_SRCS
|
||||||
|
${FlatBuffers_Library_SRCS}
|
||||||
|
src/idl_gen_fbs.cpp
|
||||||
|
tests/test.cpp
|
||||||
|
tests/test_assert.h
|
||||||
|
tests/test_assert.cpp
|
||||||
|
tests/test_builder.h
|
||||||
|
tests/test_builder.cpp
|
||||||
|
tests/native_type_test_impl.h
|
||||||
|
tests/native_type_test_impl.cpp
|
||||||
|
include/flatbuffers/code_generators.h
|
||||||
|
src/code_generators.cpp
|
||||||
|
# file generate by running compiler on tests/monster_test.fbs
|
||||||
|
${CMAKE_CURRENT_BINARY_DIR}/tests/monster_test_generated.h
|
||||||
|
# file generate by running compiler on namespace_test/namespace_test1.fbs
|
||||||
|
${CMAKE_CURRENT_BINARY_DIR}/tests/namespace_test/namespace_test1_generated.h
|
||||||
|
${CMAKE_CURRENT_BINARY_DIR}/tests/namespace_test/namespace_test2_generated.h
|
||||||
|
# file generate by running compiler on union_vector/union_vector.fbs
|
||||||
|
${CMAKE_CURRENT_BINARY_DIR}/tests/union_vector/union_vector_generated.h
|
||||||
|
# file generate by running compiler on tests/arrays_test.fbs
|
||||||
|
${CMAKE_CURRENT_BINARY_DIR}/tests/arrays_test_generated.h
|
||||||
|
# file generate by running compiler on tests/native_type_test.fbs
|
||||||
|
${CMAKE_CURRENT_BINARY_DIR}/tests/native_type_test_generated.h
|
||||||
|
# file generate by running compiler on tests/monster_extra.fbs
|
||||||
|
${CMAKE_CURRENT_BINARY_DIR}/tests/monster_extra_generated.h
|
||||||
|
# file generate by running compiler on tests/monster_test.fbs
|
||||||
|
${CMAKE_CURRENT_BINARY_DIR}/tests/monster_test_bfbs_generated.h
|
||||||
|
# file generate by running compiler on tests/optional_scalars.fbs
|
||||||
|
${CMAKE_CURRENT_BINARY_DIR}/tests/optional_scalars_generated.h
|
||||||
|
)
|
||||||
|
|
||||||
|
set(FlatBuffers_Tests_CPP17_SRCS
|
||||||
|
${FlatBuffers_Library_SRCS}
|
||||||
|
tests/test_assert.h
|
||||||
|
tests/test_assert.cpp
|
||||||
|
tests/cpp17/test_cpp17.cpp
|
||||||
|
# file generate by running compiler on tests/monster_test.fbs
|
||||||
|
${CMAKE_CURRENT_BINARY_DIR}/tests/cpp17/generated_cpp17/monster_test_generated.h
|
||||||
|
${CMAKE_CURRENT_BINARY_DIR}/tests/monster_test_generated.h
|
||||||
|
${CMAKE_CURRENT_BINARY_DIR}/tests/cpp17/generated_cpp17/optional_scalars_generated.h
|
||||||
|
${CMAKE_CURRENT_BINARY_DIR}/tests/optional_scalars_generated.h
|
||||||
|
)
|
||||||
|
|
||||||
|
set(FlatBuffers_Sample_Binary_SRCS
|
||||||
|
include/flatbuffers/flatbuffers.h
|
||||||
|
samples/sample_binary.cpp
|
||||||
|
# file generated by running compiler on samples/monster.fbs
|
||||||
|
${CMAKE_CURRENT_BINARY_DIR}/samples/monster_generated.h
|
||||||
|
)
|
||||||
|
|
||||||
|
set(FlatBuffers_Sample_Text_SRCS
|
||||||
|
${FlatBuffers_Library_SRCS}
|
||||||
|
samples/sample_text.cpp
|
||||||
|
# file generated by running compiler on samples/monster.fbs
|
||||||
|
${CMAKE_CURRENT_BINARY_DIR}/samples/monster_generated.h
|
||||||
|
)
|
||||||
|
|
||||||
|
set(FlatBuffers_Sample_BFBS_SRCS
|
||||||
|
${FlatBuffers_Library_SRCS}
|
||||||
|
samples/sample_bfbs.cpp
|
||||||
|
# file generated by running compiler on samples/monster.fbs
|
||||||
|
${CMAKE_CURRENT_BINARY_DIR}/samples/monster_generated.h
|
||||||
|
)
|
||||||
|
|
||||||
|
set(FlatBuffers_GRPCTest_SRCS
|
||||||
|
include/flatbuffers/flatbuffers.h
|
||||||
|
include/flatbuffers/grpc.h
|
||||||
|
include/flatbuffers/util.h
|
||||||
|
src/util.cpp
|
||||||
|
tests/monster_test.grpc.fb.h
|
||||||
|
tests/test_assert.h
|
||||||
|
tests/test_builder.h
|
||||||
|
tests/monster_test.grpc.fb.cc
|
||||||
|
tests/test_assert.cpp
|
||||||
|
tests/test_builder.cpp
|
||||||
|
grpc/tests/grpctest.cpp
|
||||||
|
grpc/tests/message_builder_test.cpp
|
||||||
|
# file generate by running compiler on tests/monster_test.fbs
|
||||||
|
${CMAKE_CURRENT_BINARY_DIR}/tests/monster_test_generated.h
|
||||||
|
)
|
||||||
|
|
||||||
|
# source_group(Compiler FILES ${FlatBuffers_Compiler_SRCS})
|
||||||
|
# source_group(Tests FILES ${FlatBuffers_Tests_SRCS})
|
||||||
|
|
||||||
|
if(EXISTS "${CMAKE_TOOLCHAIN_FILE}")
|
||||||
|
# do not apply any global settings if the toolchain
|
||||||
|
# is being configured externally
|
||||||
|
message(STATUS "Using toolchain file: ${CMAKE_TOOLCHAIN_FILE}.")
|
||||||
|
elseif(CMAKE_COMPILER_IS_GNUCXX)
|
||||||
|
if(CYGWIN)
|
||||||
|
set(CMAKE_CXX_FLAGS
|
||||||
|
"${CMAKE_CXX_FLAGS} -std=gnu++11")
|
||||||
|
else(CYGWIN)
|
||||||
|
set(CMAKE_CXX_FLAGS
|
||||||
|
"${CMAKE_CXX_FLAGS} -std=c++0x")
|
||||||
|
endif(CYGWIN)
|
||||||
|
set(CMAKE_CXX_FLAGS
|
||||||
|
"${CMAKE_CXX_FLAGS} -Wall -pedantic -Werror -Wextra -Werror=shadow")
|
||||||
|
set(FLATBUFFERS_PRIVATE_CXX_FLAGS "-Wold-style-cast")
|
||||||
|
if (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 4.4)
|
||||||
|
if (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 7.0)
|
||||||
|
set(CMAKE_CXX_FLAGS
|
||||||
|
"${CMAKE_CXX_FLAGS} -faligned-new -Werror=implicit-fallthrough=2")
|
||||||
|
endif()
|
||||||
|
set(CMAKE_CXX_FLAGS
|
||||||
|
"${CMAKE_CXX_FLAGS} -Wunused-result -Werror=unused-result -Wunused-parameter -Werror=unused-parameter")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
# Certain platforms such as ARM do not use signed chars by default
|
||||||
|
# which causes issues with certain bounds checks.
|
||||||
|
set(CMAKE_CXX_FLAGS
|
||||||
|
"${CMAKE_CXX_FLAGS} -fsigned-char")
|
||||||
|
|
||||||
|
# MSVC **MUST** come before the Clang check, as clang-cl is flagged by CMake as "MSVC", but it still textually
|
||||||
|
# matches as Clang in its Compiler Id :)
|
||||||
|
# Note: in CMake >= 3.14 we can check CMAKE_CXX_COMPILER_FRONTEND_VARIANT STREQUAL "GNU" or "MSVC" to differentiate...
|
||||||
|
elseif(MSVC)
|
||||||
|
# Visual Studio pedantic build settings
|
||||||
|
# warning C4512: assignment operator could not be generated
|
||||||
|
# warning C4316: object allocated on the heap may not be aligned
|
||||||
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W4 /WX /wd4512 /wd4316")
|
||||||
|
|
||||||
|
if(${CMAKE_CXX_COMPILER_ID} MATCHES "Clang")
|
||||||
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /D_CRT_SECURE_NO_WARNINGS")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
elseif(${CMAKE_CXX_COMPILER_ID} MATCHES "Clang")
|
||||||
|
if(APPLE)
|
||||||
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
|
||||||
|
|
||||||
|
if(FLATBUFFERS_OSX_BUILD_UNIVERSAL)
|
||||||
|
set(CMAKE_OSX_ARCHITECTURES "arm64;x86_64")
|
||||||
|
endif()
|
||||||
|
else()
|
||||||
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -pedantic -Werror -Wextra -Wno-unused-parameter")
|
||||||
|
set(FLATBUFFERS_PRIVATE_CXX_FLAGS "-Wold-style-cast")
|
||||||
|
if(NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 3.8)
|
||||||
|
list(APPEND FLATBUFFERS_PRIVATE_CXX_FLAGS "-Wimplicit-fallthrough" "-Wextra-semi" "-Werror=unused-private-field") # enable warning
|
||||||
|
endif()
|
||||||
|
if(FLATBUFFERS_LIBCXX_WITH_CLANG)
|
||||||
|
if(NOT "${CMAKE_SYSTEM_NAME}" MATCHES "Linux")
|
||||||
|
set(CMAKE_CXX_FLAGS
|
||||||
|
"${CMAKE_CXX_FLAGS} -stdlib=libc++")
|
||||||
|
endif()
|
||||||
|
if(NOT ("${CMAKE_SYSTEM_NAME}" MATCHES "FreeBSD" OR
|
||||||
|
"${CMAKE_SYSTEM_NAME}" MATCHES "Linux"))
|
||||||
|
set(CMAKE_EXE_LINKER_FLAGS
|
||||||
|
"${CMAKE_EXE_LINKER_FLAGS} -lc++abi")
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
|
|
||||||
|
# Certain platforms such as ARM do not use signed chars by default
|
||||||
|
# which causes issues with certain bounds checks.
|
||||||
|
set(CMAKE_CXX_FLAGS
|
||||||
|
"${CMAKE_CXX_FLAGS} -fsigned-char")
|
||||||
|
|
||||||
|
endif()
|
||||||
|
|
||||||
|
# Append FLATBUFFERS_CXX_FLAGS to CMAKE_CXX_FLAGS.
|
||||||
|
if(DEFINED FLATBUFFERS_CXX_FLAGS AND NOT EXISTS "${CMAKE_TOOLCHAIN_FILE}")
|
||||||
|
message(STATUS "extend CXX_FLAGS with ${FLATBUFFERS_CXX_FLAGS}")
|
||||||
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${FLATBUFFERS_CXX_FLAGS}")
|
||||||
|
endif()
|
||||||
|
message(STATUS "CMAKE_CXX_FLAGS: ${CMAKE_CXX_FLAGS}")
|
||||||
|
|
||||||
|
if(FLATBUFFERS_CODE_COVERAGE)
|
||||||
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -fprofile-arcs -ftest-coverage")
|
||||||
|
set(CMAKE_EXE_LINKER_FLAGS
|
||||||
|
"${CMAKE_EXE_LINKER_FLAGS} -fprofile-arcs -ftest-coverage")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
function(add_fsanitize_to_target _target _sanitizer)
|
||||||
|
if(WIN32)
|
||||||
|
target_compile_definitions(${_target} PRIVATE FLATBUFFERS_MEMORY_LEAK_TRACKING)
|
||||||
|
message(STATUS "Sanitizer MSVC::_CrtDumpMemoryLeaks added to ${_target}")
|
||||||
|
else()
|
||||||
|
# FLATBUFFERS_CODE_SANITIZE: boolean {ON,OFF,YES,NO} or string with list of sanitizer.
|
||||||
|
# List of sanitizer is string starts with '=': "=address,undefined,thread,memory".
|
||||||
|
if((${CMAKE_CXX_COMPILER_ID} MATCHES "Clang") OR
|
||||||
|
((${CMAKE_CXX_COMPILER_ID} MATCHES "GNU") AND NOT (CMAKE_CXX_COMPILER_VERSION VERSION_LESS "4.9"))
|
||||||
|
)
|
||||||
|
set(_sanitizer_flags "=address,undefined")
|
||||||
|
if(_sanitizer MATCHES "=.*")
|
||||||
|
# override default by user-defined sanitizer list
|
||||||
|
set(_sanitizer_flags ${_sanitizer})
|
||||||
|
endif()
|
||||||
|
target_compile_options(${_target} PRIVATE
|
||||||
|
-g -fsigned-char -fno-omit-frame-pointer
|
||||||
|
"-fsanitize${_sanitizer_flags}")
|
||||||
|
target_link_libraries(${_target} PRIVATE
|
||||||
|
"-fsanitize${_sanitizer_flags}")
|
||||||
|
set_property(TARGET ${_target} PROPERTY POSITION_INDEPENDENT_CODE ON)
|
||||||
|
message(STATUS "Sanitizer ${_sanitizer_flags} added to ${_target}")
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
|
endfunction()
|
||||||
|
|
||||||
|
function(add_pch_to_target _target _pch_header)
|
||||||
|
if(COMMAND target_precompile_headers)
|
||||||
|
target_precompile_headers(${_target} PRIVATE ${_pch_header})
|
||||||
|
if(NOT MSVC)
|
||||||
|
set_source_files_properties(src/util.cpp PROPERTIES SKIP_PRECOMPILE_HEADERS ON)
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
|
endfunction()
|
||||||
|
|
||||||
|
if(BIICODE)
|
||||||
|
include(biicode/cmake/biicode.cmake)
|
||||||
|
return()
|
||||||
|
endif()
|
||||||
|
|
||||||
|
include_directories(include)
|
||||||
|
include_directories(grpc)
|
||||||
|
|
||||||
|
if(FLATBUFFERS_BUILD_FLATLIB)
|
||||||
|
add_library(flatbuffers STATIC ${FlatBuffers_Library_SRCS})
|
||||||
|
# Attach header directory for when build via add_subdirectory().
|
||||||
|
target_include_directories(flatbuffers INTERFACE
|
||||||
|
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>)
|
||||||
|
target_compile_options(flatbuffers PRIVATE "${FLATBUFFERS_PRIVATE_CXX_FLAGS}")
|
||||||
|
if(FLATBUFFERS_ENABLE_PCH)
|
||||||
|
add_pch_to_target(flatbuffers include/flatbuffers/pch/pch.h)
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(FLATBUFFERS_BUILD_FLATC)
|
||||||
|
add_executable(flatc ${FlatBuffers_Compiler_SRCS})
|
||||||
|
if(FLATBUFFERS_ENABLE_PCH)
|
||||||
|
add_pch_to_target(flatc include/flatbuffers/pch/flatc_pch.h)
|
||||||
|
endif()
|
||||||
|
target_compile_options(flatc PRIVATE "${FLATBUFFERS_PRIVATE_CXX_FLAGS}")
|
||||||
|
if(FLATBUFFERS_CODE_SANITIZE AND NOT WIN32)
|
||||||
|
add_fsanitize_to_target(flatc ${FLATBUFFERS_CODE_SANITIZE})
|
||||||
|
endif()
|
||||||
|
if(NOT FLATBUFFERS_FLATC_EXECUTABLE)
|
||||||
|
set(FLATBUFFERS_FLATC_EXECUTABLE $<TARGET_FILE:flatc>)
|
||||||
|
endif()
|
||||||
|
if(MSVC)
|
||||||
|
# Make flatc.exe not depend on runtime dlls for easy distribution.
|
||||||
|
target_compile_options(flatc PUBLIC $<$<CONFIG:Release>:/MT>)
|
||||||
|
endif()
|
||||||
|
if(FLATBUFFERS_STATIC_FLATC AND NOT MSVC)
|
||||||
|
target_link_libraries(flatc PRIVATE -static)
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(FLATBUFFERS_BUILD_FLATHASH)
|
||||||
|
add_executable(flathash ${FlatHash_SRCS})
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(FLATBUFFERS_BUILD_SHAREDLIB)
|
||||||
|
add_library(flatbuffers_shared SHARED ${FlatBuffers_Library_SRCS})
|
||||||
|
|
||||||
|
# Shared object version: "major.minor.micro"
|
||||||
|
# - micro updated every release when there is no API/ABI changes
|
||||||
|
# - minor updated when there are additions in API/ABI
|
||||||
|
# - major (ABI number) updated when there are changes in ABI (or removals)
|
||||||
|
set(FlatBuffers_Library_SONAME_MAJOR ${VERSION_MAJOR})
|
||||||
|
set(FlatBuffers_Library_SONAME_FULL "${FlatBuffers_Library_SONAME_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}")
|
||||||
|
set_target_properties(flatbuffers_shared PROPERTIES OUTPUT_NAME flatbuffers
|
||||||
|
SOVERSION "${FlatBuffers_Library_SONAME_MAJOR}"
|
||||||
|
VERSION "${FlatBuffers_Library_SONAME_FULL}")
|
||||||
|
if(FLATBUFFERS_ENABLE_PCH)
|
||||||
|
add_pch_to_target(flatbuffers_shared include/flatbuffers/pch/pch.h)
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
|
|
||||||
|
# Global list of generated files.
|
||||||
|
# Use the global property to be independent of PARENT_SCOPE.
|
||||||
|
set_property(GLOBAL PROPERTY FBS_GENERATED_OUTPUTS)
|
||||||
|
|
||||||
|
function(get_generated_output generated_files)
|
||||||
|
get_property(tmp GLOBAL PROPERTY FBS_GENERATED_OUTPUTS)
|
||||||
|
set(${generated_files} ${tmp} PARENT_SCOPE)
|
||||||
|
endfunction(get_generated_output)
|
||||||
|
|
||||||
|
function(register_generated_output file_name)
|
||||||
|
get_property(tmp GLOBAL PROPERTY FBS_GENERATED_OUTPUTS)
|
||||||
|
list(APPEND tmp ${file_name})
|
||||||
|
set_property(GLOBAL PROPERTY FBS_GENERATED_OUTPUTS ${tmp})
|
||||||
|
endfunction(register_generated_output)
|
||||||
|
|
||||||
|
function(compile_flatbuffers_schema_to_cpp_opt SRC_FBS OPT)
|
||||||
|
if(FLATBUFFERS_BUILD_LEGACY)
|
||||||
|
set(OPT ${OPT};--cpp-std c++0x)
|
||||||
|
else()
|
||||||
|
# --cpp-std is defined by flatc default settings.
|
||||||
|
endif()
|
||||||
|
message(STATUS "`${SRC_FBS}`: add generation of C++ code with '${OPT}'")
|
||||||
|
get_filename_component(SRC_FBS_DIR ${SRC_FBS} PATH)
|
||||||
|
string(REGEX REPLACE "\\.fbs$" "_generated.h" GEN_HEADER ${SRC_FBS})
|
||||||
|
add_custom_command(
|
||||||
|
OUTPUT ${GEN_HEADER}
|
||||||
|
COMMAND "${FLATBUFFERS_FLATC_EXECUTABLE}"
|
||||||
|
--cpp --gen-mutable --gen-object-api --reflect-names
|
||||||
|
--cpp-ptr-type flatbuffers::unique_ptr # Used to test with C++98 STLs
|
||||||
|
${OPT}
|
||||||
|
-I "${CMAKE_CURRENT_SOURCE_DIR}/tests/include_test"
|
||||||
|
-o "${SRC_FBS_DIR}"
|
||||||
|
"${CMAKE_CURRENT_SOURCE_DIR}/${SRC_FBS}"
|
||||||
|
DEPENDS flatc
|
||||||
|
COMMENT "Run generation: '${GEN_HEADER}'")
|
||||||
|
register_generated_output(${GEN_HEADER})
|
||||||
|
endfunction()
|
||||||
|
|
||||||
|
function(compile_flatbuffers_schema_to_cpp SRC_FBS)
|
||||||
|
compile_flatbuffers_schema_to_cpp_opt(${SRC_FBS} "--no-includes;--gen-compare")
|
||||||
|
endfunction()
|
||||||
|
|
||||||
|
function(compile_flatbuffers_schema_to_binary SRC_FBS)
|
||||||
|
message(STATUS "`${SRC_FBS}`: add generation of binary (.bfbs) schema")
|
||||||
|
get_filename_component(SRC_FBS_DIR ${SRC_FBS} PATH)
|
||||||
|
string(REGEX REPLACE "\\.fbs$" ".bfbs" GEN_BINARY_SCHEMA ${SRC_FBS})
|
||||||
|
# For details about flags see generate_code.py
|
||||||
|
add_custom_command(
|
||||||
|
OUTPUT ${GEN_BINARY_SCHEMA}
|
||||||
|
COMMAND "${FLATBUFFERS_FLATC_EXECUTABLE}"
|
||||||
|
-b --schema --bfbs-comments --bfbs-builtins
|
||||||
|
--bfbs-filenames ${SRC_FBS_DIR}
|
||||||
|
-I "${CMAKE_CURRENT_SOURCE_DIR}/tests/include_test"
|
||||||
|
-o "${SRC_FBS_DIR}"
|
||||||
|
"${CMAKE_CURRENT_SOURCE_DIR}/${SRC_FBS}"
|
||||||
|
DEPENDS flatc
|
||||||
|
COMMENT "Run generation: '${GEN_BINARY_SCHEMA}'")
|
||||||
|
register_generated_output(${GEN_BINARY_SCHEMA})
|
||||||
|
endfunction()
|
||||||
|
|
||||||
|
function(compile_flatbuffers_schema_to_embedded_binary SRC_FBS OPT)
|
||||||
|
if(FLATBUFFERS_BUILD_LEGACY)
|
||||||
|
set(OPT ${OPT};--cpp-std c++0x)
|
||||||
|
else()
|
||||||
|
# --cpp-std is defined by flatc default settings.
|
||||||
|
endif()
|
||||||
|
message(STATUS "`${SRC_FBS}`: add generation of C++ embedded binary schema code with '${OPT}'")
|
||||||
|
get_filename_component(SRC_FBS_DIR ${SRC_FBS} PATH)
|
||||||
|
string(REGEX REPLACE "\\.fbs$" "_bfbs_generated.h" GEN_BFBS_HEADER ${SRC_FBS})
|
||||||
|
# For details about flags see generate_code.py
|
||||||
|
add_custom_command(
|
||||||
|
OUTPUT ${GEN_BFBS_HEADER}
|
||||||
|
COMMAND "${FLATBUFFERS_FLATC_EXECUTABLE}"
|
||||||
|
--cpp --gen-mutable --gen-object-api --reflect-names
|
||||||
|
--cpp-ptr-type flatbuffers::unique_ptr # Used to test with C++98 STLs
|
||||||
|
${OPT}
|
||||||
|
--bfbs-comments --bfbs-builtins --bfbs-gen-embed
|
||||||
|
--bfbs-filenames ${SRC_FBS_DIR}
|
||||||
|
-I "${CMAKE_CURRENT_SOURCE_DIR}/tests/include_test"
|
||||||
|
-o "${SRC_FBS_DIR}"
|
||||||
|
"${CMAKE_CURRENT_SOURCE_DIR}/${SRC_FBS}"
|
||||||
|
DEPENDS flatc
|
||||||
|
COMMENT "Run generation: '${GEN_BFBS_HEADER}'")
|
||||||
|
register_generated_output(${GEN_BFBS_HEADER})
|
||||||
|
endfunction()
|
||||||
|
|
||||||
|
# Look if we have python 3.5 installed so that we can run the generate code
|
||||||
|
# python script after flatc is built.
|
||||||
|
find_package(PythonInterp 3.5)
|
||||||
|
|
||||||
|
if(PYTHONINTERP_FOUND AND
|
||||||
|
# Skip doing this if the MSVC version is below VS 12.
|
||||||
|
# https://cmake.org/cmake/help/latest/variable/MSVC_VERSION.html
|
||||||
|
(NOT MSVC OR MSVC_VERSION GREATER 1800))
|
||||||
|
set(GENERATION_SCRIPT ${PYTHON_EXECUTABLE} scripts/generate_code.py)
|
||||||
|
if(FLATBUFFERS_BUILD_LEGACY)
|
||||||
|
# Need to set --cpp-std c++-0x options
|
||||||
|
set(GENERATION_SCRIPT ${GENERATION_SCRIPT} --cpp-0x)
|
||||||
|
endif()
|
||||||
|
if(FLATBUFFERS_SKIP_MONSTER_EXTRA)
|
||||||
|
set(GENERATION_SCRIPT ${GENERATION_SCRIPT} --skip-monster-extra)
|
||||||
|
endif()
|
||||||
|
add_custom_command(
|
||||||
|
TARGET flatc
|
||||||
|
POST_BUILD
|
||||||
|
COMMAND ${GENERATION_SCRIPT} --flatc "${FLATBUFFERS_FLATC_EXECUTABLE}"
|
||||||
|
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
|
||||||
|
COMMENT "Running ${GENERATION_SCRIPT}..."
|
||||||
|
VERBATIM)
|
||||||
|
else()
|
||||||
|
message("No Python3 interpreter found! Unable to generate files automatically.")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(FLATBUFFERS_BUILD_TESTS)
|
||||||
|
file(COPY "${CMAKE_CURRENT_SOURCE_DIR}/tests" DESTINATION "${CMAKE_CURRENT_BINARY_DIR}")
|
||||||
|
file(COPY "${CMAKE_CURRENT_SOURCE_DIR}/samples" DESTINATION "${CMAKE_CURRENT_BINARY_DIR}")
|
||||||
|
|
||||||
|
# TODO Add (monster_test.fbs monsterdata_test.json)->monsterdata_test.mon
|
||||||
|
compile_flatbuffers_schema_to_cpp(tests/monster_test.fbs)
|
||||||
|
compile_flatbuffers_schema_to_binary(tests/monster_test.fbs)
|
||||||
|
compile_flatbuffers_schema_to_cpp_opt(tests/namespace_test/namespace_test1.fbs "--no-includes;--gen-compare;--gen-name-strings")
|
||||||
|
compile_flatbuffers_schema_to_cpp_opt(tests/namespace_test/namespace_test2.fbs "--no-includes;--gen-compare;--gen-name-strings")
|
||||||
|
compile_flatbuffers_schema_to_cpp_opt(tests/union_vector/union_vector.fbs "--no-includes;--gen-compare;--gen-name-strings")
|
||||||
|
compile_flatbuffers_schema_to_cpp(tests/optional_scalars.fbs)
|
||||||
|
compile_flatbuffers_schema_to_cpp_opt(tests/native_type_test.fbs "")
|
||||||
|
compile_flatbuffers_schema_to_cpp_opt(tests/arrays_test.fbs "--scoped-enums;--gen-compare")
|
||||||
|
compile_flatbuffers_schema_to_binary(tests/arrays_test.fbs)
|
||||||
|
compile_flatbuffers_schema_to_embedded_binary(tests/monster_test.fbs "--no-includes;--gen-compare")
|
||||||
|
if(NOT (MSVC AND (MSVC_VERSION LESS 1900)))
|
||||||
|
compile_flatbuffers_schema_to_cpp(tests/monster_extra.fbs) # Test floating-point NAN/INF.
|
||||||
|
endif()
|
||||||
|
include_directories(${CMAKE_CURRENT_BINARY_DIR}/tests)
|
||||||
|
add_executable(flattests ${FlatBuffers_Tests_SRCS})
|
||||||
|
add_dependencies(flattests generated_code)
|
||||||
|
set_property(TARGET flattests
|
||||||
|
PROPERTY COMPILE_DEFINITIONS FLATBUFFERS_TRACK_VERIFIER_BUFFER_SIZE
|
||||||
|
FLATBUFFERS_DEBUG_VERIFICATION_FAILURE=1)
|
||||||
|
if(FLATBUFFERS_CODE_SANITIZE)
|
||||||
|
add_fsanitize_to_target(flattests ${FLATBUFFERS_CODE_SANITIZE})
|
||||||
|
endif()
|
||||||
|
|
||||||
|
compile_flatbuffers_schema_to_cpp(samples/monster.fbs)
|
||||||
|
compile_flatbuffers_schema_to_binary(samples/monster.fbs)
|
||||||
|
include_directories(${CMAKE_CURRENT_BINARY_DIR}/samples)
|
||||||
|
add_executable(flatsamplebinary ${FlatBuffers_Sample_Binary_SRCS})
|
||||||
|
add_dependencies(flatsamplebinary generated_code)
|
||||||
|
add_executable(flatsampletext ${FlatBuffers_Sample_Text_SRCS})
|
||||||
|
add_dependencies(flatsampletext generated_code)
|
||||||
|
add_executable(flatsamplebfbs ${FlatBuffers_Sample_BFBS_SRCS})
|
||||||
|
add_dependencies(flatsamplebfbs generated_code)
|
||||||
|
|
||||||
|
if(FLATBUFFERS_BUILD_CPP17)
|
||||||
|
# Don't generate header for flattests_cpp17 target.
|
||||||
|
# This target uses "generated_cpp17/monster_test_generated.h"
|
||||||
|
# produced by direct call of generate_code.py script.
|
||||||
|
add_executable(flattests_cpp17 ${FlatBuffers_Tests_CPP17_SRCS})
|
||||||
|
add_dependencies(flattests_cpp17 generated_code)
|
||||||
|
target_compile_features(flattests_cpp17 PRIVATE cxx_std_17)
|
||||||
|
target_compile_definitions(flattests_cpp17 PRIVATE
|
||||||
|
FLATBUFFERS_TRACK_VERIFIER_BUFFER_SIZE
|
||||||
|
FLATBUFFERS_DEBUG_VERIFICATION_FAILURE=1
|
||||||
|
)
|
||||||
|
if(FLATBUFFERS_CODE_SANITIZE)
|
||||||
|
add_fsanitize_to_target(flattests_cpp17 ${FLATBUFFERS_CODE_SANITIZE})
|
||||||
|
endif()
|
||||||
|
endif(FLATBUFFERS_BUILD_CPP17)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(FLATBUFFERS_BUILD_GRPCTEST)
|
||||||
|
if(CMAKE_COMPILER_IS_GNUCXX)
|
||||||
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unused-parameter -Wno-shadow")
|
||||||
|
endif()
|
||||||
|
if(NOT GRPC_INSTALL_PATH)
|
||||||
|
message(SEND_ERROR "GRPC_INSTALL_PATH variable is not defined. See grpc/README.md")
|
||||||
|
endif()
|
||||||
|
if(NOT PROTOBUF_DOWNLOAD_PATH)
|
||||||
|
message(SEND_ERROR "PROTOBUF_DOWNLOAD_PATH variable is not defined. See grpc/README.md")
|
||||||
|
endif()
|
||||||
|
INCLUDE_DIRECTORIES(${GRPC_INSTALL_PATH}/include)
|
||||||
|
INCLUDE_DIRECTORIES(${PROTOBUF_DOWNLOAD_PATH}/src)
|
||||||
|
find_package(Threads REQUIRED)
|
||||||
|
list(APPEND CMAKE_PREFIX_PATH ${GRPC_INSTALL_PATH})
|
||||||
|
find_package(absl CONFIG REQUIRED)
|
||||||
|
find_package(protobuf CONFIG REQUIRED)
|
||||||
|
find_package(gRPC CONFIG REQUIRED)
|
||||||
|
add_executable(grpctest ${FlatBuffers_GRPCTest_SRCS})
|
||||||
|
add_dependencies(grpctest generated_code)
|
||||||
|
target_link_libraries(grpctest PRIVATE gRPC::grpc++_unsecure gRPC::grpc_unsecure gRPC::gpr pthread dl)
|
||||||
|
if(FLATBUFFERS_CODE_SANITIZE AND NOT WIN32)
|
||||||
|
# GRPC test has problems with alignment and will fail under ASAN/UBSAN.
|
||||||
|
# add_fsanitize_to_target(grpctest ${FLATBUFFERS_CODE_SANITIZE})
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
|
|
||||||
|
|
||||||
|
if(FLATBUFFERS_INSTALL)
|
||||||
|
include(GNUInstallDirs)
|
||||||
|
|
||||||
|
install(DIRECTORY include/flatbuffers DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
|
||||||
|
|
||||||
|
set(FB_CMAKE_DIR "${CMAKE_INSTALL_LIBDIR}/cmake/flatbuffers")
|
||||||
|
|
||||||
|
configure_file(CMake/FlatBuffersConfigVersion.cmake.in FlatBuffersConfigVersion.cmake @ONLY)
|
||||||
|
install(
|
||||||
|
FILES "CMake/FlatBuffersConfig.cmake" "${CMAKE_CURRENT_BINARY_DIR}/FlatBuffersConfigVersion.cmake"
|
||||||
|
DESTINATION ${FB_CMAKE_DIR}
|
||||||
|
)
|
||||||
|
|
||||||
|
if(FLATBUFFERS_BUILD_FLATLIB)
|
||||||
|
if(CMAKE_VERSION VERSION_LESS 3.0)
|
||||||
|
install(
|
||||||
|
TARGETS flatbuffers EXPORT FlatBuffersTargets
|
||||||
|
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
||||||
|
)
|
||||||
|
else()
|
||||||
|
install(
|
||||||
|
TARGETS flatbuffers EXPORT FlatBuffersTargets
|
||||||
|
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
||||||
|
INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
|
||||||
|
)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
install(EXPORT FlatBuffersTargets
|
||||||
|
FILE FlatBuffersTargets.cmake
|
||||||
|
NAMESPACE flatbuffers::
|
||||||
|
DESTINATION ${FB_CMAKE_DIR}
|
||||||
|
)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(FLATBUFFERS_BUILD_FLATC)
|
||||||
|
install(
|
||||||
|
TARGETS flatc EXPORT FlatcTargets
|
||||||
|
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
|
||||||
|
)
|
||||||
|
|
||||||
|
install(
|
||||||
|
EXPORT FlatcTargets
|
||||||
|
FILE FlatcTargets.cmake
|
||||||
|
NAMESPACE flatbuffers::
|
||||||
|
DESTINATION ${FB_CMAKE_DIR}
|
||||||
|
)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(FLATBUFFERS_BUILD_SHAREDLIB)
|
||||||
|
if(CMAKE_VERSION VERSION_LESS 3.0)
|
||||||
|
install(
|
||||||
|
TARGETS flatbuffers_shared EXPORT FlatBuffersSharedTargets
|
||||||
|
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
||||||
|
RUNTIME DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
||||||
|
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
||||||
|
)
|
||||||
|
else()
|
||||||
|
install(
|
||||||
|
TARGETS flatbuffers_shared EXPORT FlatBuffersSharedTargets
|
||||||
|
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
||||||
|
RUNTIME DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
||||||
|
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
||||||
|
INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
|
||||||
|
)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
install(
|
||||||
|
EXPORT FlatBuffersSharedTargets
|
||||||
|
FILE FlatBuffersSharedTargets.cmake
|
||||||
|
NAMESPACE flatbuffers::
|
||||||
|
DESTINATION ${FB_CMAKE_DIR}
|
||||||
|
)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(FLATBUFFERS_BUILD_SHAREDLIB OR FLATBUFFERS_BUILD_FLATLIB)
|
||||||
|
configure_file(CMake/flatbuffers.pc.in flatbuffers.pc @ONLY)
|
||||||
|
install(
|
||||||
|
FILES "${CMAKE_CURRENT_BINARY_DIR}/flatbuffers.pc"
|
||||||
|
DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig
|
||||||
|
)
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(FLATBUFFERS_BUILD_TESTS)
|
||||||
|
enable_testing()
|
||||||
|
|
||||||
|
add_test(NAME flattests COMMAND flattests)
|
||||||
|
if(FLATBUFFERS_BUILD_CPP17)
|
||||||
|
add_test(NAME flattests_cpp17 COMMAND flattests_cpp17)
|
||||||
|
endif()
|
||||||
|
if(FLATBUFFERS_BUILD_GRPCTEST)
|
||||||
|
add_test(NAME grpctest COMMAND grpctest)
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
|
|
||||||
|
# This target is sync-barrier.
|
||||||
|
# Other generate-dependent targets can depend on 'generated_code' only.
|
||||||
|
get_generated_output(fbs_generated)
|
||||||
|
if(fbs_generated)
|
||||||
|
# message(STATUS "Add generated_code target with files:${fbs_generated}")
|
||||||
|
add_custom_target(generated_code
|
||||||
|
DEPENDS ${fbs_generated}
|
||||||
|
COMMENT "All generated files were updated.")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
include(CMake/BuildFlatBuffers.cmake)
|
||||||
|
|
||||||
|
if(UNIX)
|
||||||
|
# Use of CPack only supported on Linux systems.
|
||||||
|
if(FLATBUFFERS_PACKAGE_DEBIAN)
|
||||||
|
include(CMake/PackageDebian.cmake)
|
||||||
|
include(CPack)
|
||||||
|
endif()
|
||||||
|
if (FLATBUFFERS_PACKAGE_REDHAT)
|
||||||
|
include(CMake/PackageRedhat.cmake)
|
||||||
|
include(CPack)
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
|
|
||||||
|
# Include for running Google Benchmarks.
|
||||||
|
if(FLATBUFFERS_BUILD_BENCHMARKS AND CMAKE_VERSION VERSION_GREATER 3.13)
|
||||||
|
add_subdirectory(benchmarks)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
# Add FlatBuffers::FlatBuffers interface, needed for FetchContent_Declare
|
||||||
|
add_library(FlatBuffers INTERFACE)
|
||||||
|
add_library(FlatBuffers::FlatBuffers ALIAS FlatBuffers)
|
||||||
|
target_include_directories(
|
||||||
|
FlatBuffers
|
||||||
|
INTERFACE $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
|
||||||
|
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/include>)
|
||||||
3
CMake/FlatBuffersConfig.cmake
Normal file
3
CMake/FlatBuffersConfig.cmake
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
include("${CMAKE_CURRENT_LIST_DIR}/FlatBuffersTargets.cmake" OPTIONAL)
|
||||||
|
include("${CMAKE_CURRENT_LIST_DIR}/FlatcTargets.cmake" OPTIONAL)
|
||||||
|
include("${CMAKE_CURRENT_LIST_DIR}/FlatBuffersSharedTargets.cmake" OPTIONAL)
|
||||||
@@ -1,4 +0,0 @@
|
|||||||
include("${CMAKE_CURRENT_LIST_DIR}/FlatbuffersTargets.cmake" OPTIONAL)
|
|
||||||
include("${CMAKE_CURRENT_LIST_DIR}/FlatcTargets.cmake" OPTIONAL)
|
|
||||||
include("${CMAKE_CURRENT_LIST_DIR}/FlatbuffersSharedTargets.cmake" OPTIONAL)
|
|
||||||
|
|
||||||
@@ -1,12 +1,12 @@
|
|||||||
set(VERSION_MAJOR 2)
|
set(VERSION_MAJOR 2)
|
||||||
set(VERSION_MINOR 0)
|
set(VERSION_MINOR 0)
|
||||||
set(VERSION_PATCH 0)
|
set(VERSION_PATCH 7)
|
||||||
set(VERSION_COMMIT 0)
|
set(VERSION_COMMIT 0)
|
||||||
|
|
||||||
find_program(GIT git)
|
find_program(GIT git)
|
||||||
if(GIT)
|
if(GIT AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/.git")
|
||||||
execute_process(
|
execute_process(
|
||||||
COMMAND ${GIT} describe
|
COMMAND ${GIT} describe --tags
|
||||||
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
|
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
|
||||||
OUTPUT_VARIABLE GIT_DESCRIBE_DIRTY
|
OUTPUT_VARIABLE GIT_DESCRIBE_DIRTY
|
||||||
OUTPUT_STRIP_TRAILING_WHITESPACE
|
OUTPUT_STRIP_TRAILING_WHITESPACE
|
||||||
|
|||||||
415
CMakeLists.txt
415
CMakeLists.txt
@@ -1,9 +1,35 @@
|
|||||||
cmake_minimum_required(VERSION 2.8.12)
|
# This is the legacy minimum version flatbuffers supported for a while.
|
||||||
|
cmake_minimum_required(VERSION 2.8.12...3.22.1)
|
||||||
|
|
||||||
|
# CMake version 3.16 is the 'de-facto' minimum version for flatbuffers. If the
|
||||||
|
# current cmake is older than this, warn the user and include the legacy file to
|
||||||
|
# provide some level of support.
|
||||||
|
if(CMAKE_VERSION VERSION_LESS 3.16)
|
||||||
|
message(WARNING "Using cmake version ${CMAKE_VERSION} which is older than "
|
||||||
|
"our target version of 3.16. This will use the legacy CMakeLists.txt that "
|
||||||
|
"supports version 2.8.12 and higher, but not actively maintained. Consider "
|
||||||
|
"upgrading cmake to a newer version, as this may become a fatal error in the "
|
||||||
|
"future.")
|
||||||
|
# Use the legacy version of CMakeLists.txt
|
||||||
|
include(CMake/CMakeLists_legacy.cmake.in)
|
||||||
|
return()
|
||||||
|
endif()
|
||||||
|
|
||||||
|
# Attempt to read the current version of flatbuffers by looking at the latest tag.
|
||||||
|
include(CMake/Version.cmake)
|
||||||
|
|
||||||
|
if (POLICY CMP0048)
|
||||||
|
cmake_policy(SET CMP0048 NEW)
|
||||||
|
project(FlatBuffers
|
||||||
|
DESCRIPTION "Flatbuffers serialization library"
|
||||||
|
VERSION ${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}
|
||||||
|
LANGUAGES CXX)
|
||||||
|
else()
|
||||||
|
project(FlatBuffers)
|
||||||
|
endif (POLICY CMP0048)
|
||||||
|
|
||||||
# generate compile_commands.json
|
# generate compile_commands.json
|
||||||
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
||||||
include(CheckCXXSymbolExists)
|
|
||||||
|
|
||||||
project(FlatBuffers)
|
|
||||||
|
|
||||||
# NOTE: Code coverage only works on Linux & OSX.
|
# NOTE: Code coverage only works on Linux & OSX.
|
||||||
option(FLATBUFFERS_CODE_COVERAGE "Enable the code coverage build option." OFF)
|
option(FLATBUFFERS_CODE_COVERAGE "Enable the code coverage build option." OFF)
|
||||||
@@ -16,6 +42,8 @@ option(FLATBUFFERS_BUILD_FLATC "Enable the build of the flatbuffers compiler"
|
|||||||
option(FLATBUFFERS_STATIC_FLATC "Build flatbuffers compiler with -static flag"
|
option(FLATBUFFERS_STATIC_FLATC "Build flatbuffers compiler with -static flag"
|
||||||
OFF)
|
OFF)
|
||||||
option(FLATBUFFERS_BUILD_FLATHASH "Enable the build of flathash" ON)
|
option(FLATBUFFERS_BUILD_FLATHASH "Enable the build of flathash" ON)
|
||||||
|
option(FLATBUFFERS_BUILD_BENCHMARKS "Enable the build of flatbenchmark."
|
||||||
|
OFF)
|
||||||
option(FLATBUFFERS_BUILD_GRPCTEST "Enable the build of grpctest" OFF)
|
option(FLATBUFFERS_BUILD_GRPCTEST "Enable the build of grpctest" OFF)
|
||||||
option(FLATBUFFERS_BUILD_SHAREDLIB
|
option(FLATBUFFERS_BUILD_SHAREDLIB
|
||||||
"Enable the build of the flatbuffers shared library"
|
"Enable the build of the flatbuffers shared library"
|
||||||
@@ -43,6 +71,17 @@ option(FLATBUFFERS_ENABLE_PCH
|
|||||||
Only work if CMake supports 'target_precompile_headers'. \"
|
Only work if CMake supports 'target_precompile_headers'. \"
|
||||||
This can speed up compilation time."
|
This can speed up compilation time."
|
||||||
OFF)
|
OFF)
|
||||||
|
option(FLATBUFFERS_SKIP_MONSTER_EXTRA
|
||||||
|
"Skip generating monster_extra.fbs that contains non-supported numerical\"
|
||||||
|
types." OFF)
|
||||||
|
option(FLATBUFFERS_STRICT_MODE
|
||||||
|
"Build flatbuffers with all warnings as errors (-Werror or /WX)."
|
||||||
|
OFF)
|
||||||
|
|
||||||
|
set(MSVC_LIKE OFF)
|
||||||
|
if(MSVC OR CMAKE_CXX_COMPILER_FRONTEND_VARIANT STREQUAL "MSVC")
|
||||||
|
set(MSVC_LIKE ON)
|
||||||
|
endif()
|
||||||
|
|
||||||
if(NOT FLATBUFFERS_BUILD_FLATC AND FLATBUFFERS_BUILD_TESTS)
|
if(NOT FLATBUFFERS_BUILD_FLATC AND FLATBUFFERS_BUILD_TESTS)
|
||||||
message(WARNING
|
message(WARNING
|
||||||
@@ -58,8 +97,10 @@ endif()
|
|||||||
|
|
||||||
# Auto-detect locale-narrow 'strtod_l' and 'strtoull_l' functions.
|
# Auto-detect locale-narrow 'strtod_l' and 'strtoull_l' functions.
|
||||||
if(NOT DEFINED FLATBUFFERS_LOCALE_INDEPENDENT)
|
if(NOT DEFINED FLATBUFFERS_LOCALE_INDEPENDENT)
|
||||||
|
include(CheckCXXSymbolExists)
|
||||||
|
|
||||||
set(FLATBUFFERS_LOCALE_INDEPENDENT 0)
|
set(FLATBUFFERS_LOCALE_INDEPENDENT 0)
|
||||||
if(MSVC)
|
if(MSVC_LIKE)
|
||||||
check_cxx_symbol_exists(_strtof_l stdlib.h FLATBUFFERS_HAS_STRTOF_L)
|
check_cxx_symbol_exists(_strtof_l stdlib.h FLATBUFFERS_HAS_STRTOF_L)
|
||||||
check_cxx_symbol_exists(_strtoui64_l stdlib.h FLATBUFFERS_HAS_STRTOULL_L)
|
check_cxx_symbol_exists(_strtoui64_l stdlib.h FLATBUFFERS_HAS_STRTOULL_L)
|
||||||
else()
|
else()
|
||||||
@@ -73,17 +114,32 @@ endif()
|
|||||||
add_definitions(-DFLATBUFFERS_LOCALE_INDEPENDENT=$<BOOL:${FLATBUFFERS_LOCALE_INDEPENDENT}>)
|
add_definitions(-DFLATBUFFERS_LOCALE_INDEPENDENT=$<BOOL:${FLATBUFFERS_LOCALE_INDEPENDENT}>)
|
||||||
|
|
||||||
set(FlatBuffers_Library_SRCS
|
set(FlatBuffers_Library_SRCS
|
||||||
|
include/flatbuffers/allocator.h
|
||||||
|
include/flatbuffers/array.h
|
||||||
include/flatbuffers/base.h
|
include/flatbuffers/base.h
|
||||||
|
include/flatbuffers/bfbs_generator.h
|
||||||
|
include/flatbuffers/buffer.h
|
||||||
|
include/flatbuffers/buffer_ref.h
|
||||||
|
include/flatbuffers/default_allocator.h
|
||||||
|
include/flatbuffers/detached_buffer.h
|
||||||
|
include/flatbuffers/flatbuffer_builder.h
|
||||||
include/flatbuffers/flatbuffers.h
|
include/flatbuffers/flatbuffers.h
|
||||||
|
include/flatbuffers/flexbuffers.h
|
||||||
|
include/flatbuffers/flex_flat_util.h
|
||||||
include/flatbuffers/hash.h
|
include/flatbuffers/hash.h
|
||||||
include/flatbuffers/idl.h
|
include/flatbuffers/idl.h
|
||||||
include/flatbuffers/util.h
|
include/flatbuffers/minireflect.h
|
||||||
include/flatbuffers/reflection.h
|
include/flatbuffers/reflection.h
|
||||||
include/flatbuffers/reflection_generated.h
|
include/flatbuffers/reflection_generated.h
|
||||||
include/flatbuffers/stl_emulation.h
|
|
||||||
include/flatbuffers/flexbuffers.h
|
|
||||||
include/flatbuffers/registry.h
|
include/flatbuffers/registry.h
|
||||||
include/flatbuffers/minireflect.h
|
include/flatbuffers/stl_emulation.h
|
||||||
|
include/flatbuffers/string.h
|
||||||
|
include/flatbuffers/struct.h
|
||||||
|
include/flatbuffers/table.h
|
||||||
|
include/flatbuffers/util.h
|
||||||
|
include/flatbuffers/vector.h
|
||||||
|
include/flatbuffers/vector_downward.h
|
||||||
|
include/flatbuffers/verifier.h
|
||||||
src/idl_parser.cpp
|
src/idl_parser.cpp
|
||||||
src/idl_gen_text.cpp
|
src/idl_gen_text.cpp
|
||||||
src/reflection.cpp
|
src/reflection.cpp
|
||||||
@@ -108,9 +164,19 @@ 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/idl_namer.h
|
||||||
|
src/namer.h
|
||||||
src/flatc.cpp
|
src/flatc.cpp
|
||||||
src/flatc_main.cpp
|
src/flatc_main.cpp
|
||||||
|
src/bfbs_gen.h
|
||||||
|
src/bfbs_gen_lua.h
|
||||||
|
src/bfbs_namer.h
|
||||||
include/flatbuffers/code_generators.h
|
include/flatbuffers/code_generators.h
|
||||||
|
src/binary_annotator.h
|
||||||
|
src/binary_annotator.cpp
|
||||||
|
src/annotated_binary_text_gen.h
|
||||||
|
src/annotated_binary_text_gen.cpp
|
||||||
|
src/bfbs_gen_lua.cpp
|
||||||
src/code_generators.cpp
|
src/code_generators.cpp
|
||||||
grpc/src/compiler/schema_interface.h
|
grpc/src/compiler/schema_interface.h
|
||||||
grpc/src/compiler/cpp_generator.h
|
grpc/src/compiler/cpp_generator.h
|
||||||
@@ -213,76 +279,8 @@ set(FlatBuffers_GRPCTest_SRCS
|
|||||||
${CMAKE_CURRENT_BINARY_DIR}/tests/monster_test_generated.h
|
${CMAKE_CURRENT_BINARY_DIR}/tests/monster_test_generated.h
|
||||||
)
|
)
|
||||||
|
|
||||||
# source_group(Compiler FILES ${FlatBuffers_Compiler_SRCS})
|
# TODO(dbaileychess): Figure out how this would now work. I posted a question on
|
||||||
# source_group(Tests FILES ${FlatBuffers_Tests_SRCS})
|
# https://stackoverflow.com/questions/71772330/override-target-compile-options-via-cmake-command-line.
|
||||||
|
|
||||||
if(EXISTS "${CMAKE_TOOLCHAIN_FILE}")
|
|
||||||
# do not apply any global settings if the toolchain
|
|
||||||
# is being configured externally
|
|
||||||
message(STATUS "Using toolchain file: ${CMAKE_TOOLCHAIN_FILE}.")
|
|
||||||
elseif(APPLE)
|
|
||||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -stdlib=libc++")
|
|
||||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -pedantic -Werror -Wextra -Wno-unused-parameter")
|
|
||||||
set(FLATBUFFERS_PRIVATE_CXX_FLAGS "-Wold-style-cast")
|
|
||||||
elseif(CMAKE_COMPILER_IS_GNUCXX)
|
|
||||||
if(CYGWIN)
|
|
||||||
set(CMAKE_CXX_FLAGS
|
|
||||||
"${CMAKE_CXX_FLAGS} -std=gnu++11")
|
|
||||||
else(CYGWIN)
|
|
||||||
set(CMAKE_CXX_FLAGS
|
|
||||||
"${CMAKE_CXX_FLAGS} -std=c++0x")
|
|
||||||
endif(CYGWIN)
|
|
||||||
set(CMAKE_CXX_FLAGS
|
|
||||||
"${CMAKE_CXX_FLAGS} -Wall -pedantic -Werror -Wextra -Werror=shadow")
|
|
||||||
set(FLATBUFFERS_PRIVATE_CXX_FLAGS "-Wold-style-cast")
|
|
||||||
if (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 4.4)
|
|
||||||
if (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 7.0)
|
|
||||||
set(CMAKE_CXX_FLAGS
|
|
||||||
"${CMAKE_CXX_FLAGS} -faligned-new -Werror=implicit-fallthrough=2")
|
|
||||||
endif()
|
|
||||||
set(CMAKE_CXX_FLAGS
|
|
||||||
"${CMAKE_CXX_FLAGS} -Wunused-result -Werror=unused-result -Wunused-parameter -Werror=unused-parameter")
|
|
||||||
endif()
|
|
||||||
|
|
||||||
# Certain platforms such as ARM do not use signed chars by default
|
|
||||||
# which causes issues with certain bounds checks.
|
|
||||||
set(CMAKE_CXX_FLAGS
|
|
||||||
"${CMAKE_CXX_FLAGS} -fsigned-char")
|
|
||||||
|
|
||||||
elseif(${CMAKE_CXX_COMPILER_ID} MATCHES "Clang")
|
|
||||||
set(CMAKE_CXX_FLAGS
|
|
||||||
"${CMAKE_CXX_FLAGS} -std=c++0x -Wall -pedantic -Werror -Wextra -Wno-unused-parameter")
|
|
||||||
set(FLATBUFFERS_PRIVATE_CXX_FLAGS "-Wold-style-cast")
|
|
||||||
if(NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 3.8)
|
|
||||||
list(APPEND FLATBUFFERS_PRIVATE_CXX_FLAGS "-Wimplicit-fallthrough" "-Wextra-semi" "-Werror=unused-private-field") # enable warning
|
|
||||||
endif()
|
|
||||||
if(FLATBUFFERS_LIBCXX_WITH_CLANG)
|
|
||||||
if(NOT "${CMAKE_SYSTEM_NAME}" MATCHES "Linux")
|
|
||||||
set(CMAKE_CXX_FLAGS
|
|
||||||
"${CMAKE_CXX_FLAGS} -stdlib=libc++")
|
|
||||||
endif()
|
|
||||||
if(NOT ("${CMAKE_SYSTEM_NAME}" MATCHES "FreeBSD" OR
|
|
||||||
"${CMAKE_SYSTEM_NAME}" MATCHES "Linux"))
|
|
||||||
set(CMAKE_EXE_LINKER_FLAGS
|
|
||||||
"${CMAKE_EXE_LINKER_FLAGS} -lc++abi")
|
|
||||||
endif()
|
|
||||||
endif()
|
|
||||||
|
|
||||||
# Certain platforms such as ARM do not use signed chars by default
|
|
||||||
# which causes issues with certain bounds checks.
|
|
||||||
set(CMAKE_CXX_FLAGS
|
|
||||||
"${CMAKE_CXX_FLAGS} -fsigned-char")
|
|
||||||
|
|
||||||
elseif(MSVC)
|
|
||||||
# Visual Studio pedantic build settings
|
|
||||||
# warning C4512: assignment operator could not be generated
|
|
||||||
# warning C4316: object allocated on the heap may not be aligned
|
|
||||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W4 /WX /wd4512 /wd4316")
|
|
||||||
|
|
||||||
# multi-core build.
|
|
||||||
add_definitions("/MP")
|
|
||||||
endif()
|
|
||||||
|
|
||||||
# Append FLATBUFFERS_CXX_FLAGS to CMAKE_CXX_FLAGS.
|
# Append FLATBUFFERS_CXX_FLAGS to CMAKE_CXX_FLAGS.
|
||||||
if(DEFINED FLATBUFFERS_CXX_FLAGS AND NOT EXISTS "${CMAKE_TOOLCHAIN_FILE}")
|
if(DEFINED FLATBUFFERS_CXX_FLAGS AND NOT EXISTS "${CMAKE_TOOLCHAIN_FILE}")
|
||||||
message(STATUS "extend CXX_FLAGS with ${FLATBUFFERS_CXX_FLAGS}")
|
message(STATUS "extend CXX_FLAGS with ${FLATBUFFERS_CXX_FLAGS}")
|
||||||
@@ -290,12 +288,6 @@ if(DEFINED FLATBUFFERS_CXX_FLAGS AND NOT EXISTS "${CMAKE_TOOLCHAIN_FILE}")
|
|||||||
endif()
|
endif()
|
||||||
message(STATUS "CMAKE_CXX_FLAGS: ${CMAKE_CXX_FLAGS}")
|
message(STATUS "CMAKE_CXX_FLAGS: ${CMAKE_CXX_FLAGS}")
|
||||||
|
|
||||||
if(FLATBUFFERS_CODE_COVERAGE)
|
|
||||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -fprofile-arcs -ftest-coverage")
|
|
||||||
set(CMAKE_EXE_LINKER_FLAGS
|
|
||||||
"${CMAKE_EXE_LINKER_FLAGS} -fprofile-arcs -ftest-coverage")
|
|
||||||
endif()
|
|
||||||
|
|
||||||
function(add_fsanitize_to_target _target _sanitizer)
|
function(add_fsanitize_to_target _target _sanitizer)
|
||||||
if(WIN32)
|
if(WIN32)
|
||||||
target_compile_definitions(${_target} PRIVATE FLATBUFFERS_MEMORY_LEAK_TRACKING)
|
target_compile_definitions(${_target} PRIVATE FLATBUFFERS_MEMORY_LEAK_TRACKING)
|
||||||
@@ -331,20 +323,119 @@ function(add_pch_to_target _target _pch_header)
|
|||||||
endif()
|
endif()
|
||||||
endfunction()
|
endfunction()
|
||||||
|
|
||||||
if(BIICODE)
|
|
||||||
include(biicode/cmake/biicode.cmake)
|
|
||||||
return()
|
|
||||||
endif()
|
|
||||||
|
|
||||||
include_directories(include)
|
include_directories(include)
|
||||||
include_directories(grpc)
|
include_directories(grpc)
|
||||||
|
|
||||||
|
# Creates an interface library that stores the configuration settings that each
|
||||||
|
# target links too. This is a compromise between setting configuration globally
|
||||||
|
# with add_compile_options() and the more targetted target_compile_options().
|
||||||
|
# This way each target in this file can share settings and override them if
|
||||||
|
# needed.
|
||||||
|
add_library(ProjectConfig INTERFACE)
|
||||||
|
target_compile_features(ProjectConfig
|
||||||
|
INTERFACE
|
||||||
|
cxx_std_11
|
||||||
|
)
|
||||||
|
|
||||||
|
# Force the standard to be met.
|
||||||
|
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||||
|
|
||||||
|
# We shouldn't rely on any compiler-extensions to make things work.
|
||||||
|
set(CMAKE_CXX_EXTENSIONS OFF)
|
||||||
|
|
||||||
|
if(MSVC_LIKE)
|
||||||
|
target_compile_options(ProjectConfig
|
||||||
|
INTERFACE
|
||||||
|
/W4
|
||||||
|
$<$<BOOL:${FLATBUFFERS_STRICT_MODE}>:
|
||||||
|
/WX # Treat all compiler warnings as errors
|
||||||
|
>
|
||||||
|
/wd4512 # C4512: assignment operator could not be generated
|
||||||
|
/wd4316 # C4316: object allocated on the heap may not be aligned
|
||||||
|
/wd4456 # C4456: hides previous local declaration
|
||||||
|
$<$<CXX_COMPILER_ID:Clang>:
|
||||||
|
/D_CRT_SECURE_NO_WARNINGS
|
||||||
|
>
|
||||||
|
)
|
||||||
|
else()
|
||||||
|
target_compile_options(ProjectConfig
|
||||||
|
INTERFACE
|
||||||
|
-Wall
|
||||||
|
-Wno-unknown-warning-option
|
||||||
|
$<$<BOOL:${FLATBUFFERS_STRICT_MODE}>:
|
||||||
|
-Werror # Treat all compiler warnings as errors
|
||||||
|
|
||||||
|
# False positive string overflow
|
||||||
|
# https://github.com/google/flatbuffers/issues/7366
|
||||||
|
-Wno-error=stringop-overflow
|
||||||
|
>
|
||||||
|
-pedantic
|
||||||
|
-Wextra
|
||||||
|
-Wno-unused-parameter
|
||||||
|
-Wold-style-cast
|
||||||
|
-Wimplicit-fallthrough
|
||||||
|
-fsigned-char
|
||||||
|
-Wnon-virtual-dtor
|
||||||
|
|
||||||
|
$<$<CXX_COMPILER_ID:CLANG>:
|
||||||
|
-Wmissing-declarations
|
||||||
|
-Wzero-as-null-pointer-constant
|
||||||
|
$<$<VERSION_GREATER:$<CXX_COMPILER_VERSION>,3.8>:
|
||||||
|
-Wimplicit-fallthrough
|
||||||
|
-Wextra-semi
|
||||||
|
$<$<BOOL:${FLATBUFFERS_STRICT_MODE}>:
|
||||||
|
-Werror=unused-private-field
|
||||||
|
>
|
||||||
|
>
|
||||||
|
>
|
||||||
|
|
||||||
|
$<$<CXX_COMPILER_ID:GNU>:
|
||||||
|
$<$<VERSION_GREATER:$<CXX_COMPILER_VERSION>,4.4>:
|
||||||
|
-Wunused-result
|
||||||
|
-Wunused-parameter
|
||||||
|
-Werror=unused-parameter
|
||||||
|
-Wmissing-declarations
|
||||||
|
>
|
||||||
|
$<$<VERSION_GREATER:$<CXX_COMPILER_VERSION>,4.7>:
|
||||||
|
-Wzero-as-null-pointer-constant
|
||||||
|
>
|
||||||
|
$<$<VERSION_GREATER:$<CXX_COMPILER_VERSION>,7.0>:
|
||||||
|
-faligned-new
|
||||||
|
$<$<BOOL:${FLATBUFFERS_STRICT_MODE}>:
|
||||||
|
-Werror=implicit-fallthrough=2
|
||||||
|
>
|
||||||
|
>
|
||||||
|
$<$<VERSION_GREATER:$<CXX_COMPILER_VERSION>,8.0>:
|
||||||
|
-Wextra-semi
|
||||||
|
>
|
||||||
|
>
|
||||||
|
|
||||||
|
$<$<BOOL:${FLATBUFFERS_CODE_COVERAGE}>:
|
||||||
|
-g
|
||||||
|
-fprofile-arcs
|
||||||
|
-ftest-coverage
|
||||||
|
>
|
||||||
|
)
|
||||||
|
|
||||||
|
if(FLATBUFFERS_CODE_COVERAGE)
|
||||||
|
target_link_options(ProjectConfig
|
||||||
|
INTERFACE
|
||||||
|
-fprofile-arcs
|
||||||
|
-ftest-coverage
|
||||||
|
)
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
|
|
||||||
if(FLATBUFFERS_BUILD_FLATLIB)
|
if(FLATBUFFERS_BUILD_FLATLIB)
|
||||||
add_library(flatbuffers STATIC ${FlatBuffers_Library_SRCS})
|
add_library(flatbuffers STATIC ${FlatBuffers_Library_SRCS})
|
||||||
|
|
||||||
# Attach header directory for when build via add_subdirectory().
|
# Attach header directory for when build via add_subdirectory().
|
||||||
target_include_directories(flatbuffers INTERFACE
|
target_include_directories(flatbuffers
|
||||||
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>)
|
INTERFACE
|
||||||
target_compile_options(flatbuffers PRIVATE "${FLATBUFFERS_PRIVATE_CXX_FLAGS}")
|
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
|
||||||
|
)
|
||||||
|
target_link_libraries(flatbuffers PRIVATE $<BUILD_INTERFACE:ProjectConfig>)
|
||||||
|
|
||||||
if(FLATBUFFERS_ENABLE_PCH)
|
if(FLATBUFFERS_ENABLE_PCH)
|
||||||
add_pch_to_target(flatbuffers include/flatbuffers/pch/pch.h)
|
add_pch_to_target(flatbuffers include/flatbuffers/pch/pch.h)
|
||||||
endif()
|
endif()
|
||||||
@@ -355,17 +446,21 @@ if(FLATBUFFERS_BUILD_FLATC)
|
|||||||
if(FLATBUFFERS_ENABLE_PCH)
|
if(FLATBUFFERS_ENABLE_PCH)
|
||||||
add_pch_to_target(flatc include/flatbuffers/pch/flatc_pch.h)
|
add_pch_to_target(flatc include/flatbuffers/pch/flatc_pch.h)
|
||||||
endif()
|
endif()
|
||||||
target_compile_options(flatc PRIVATE "${FLATBUFFERS_PRIVATE_CXX_FLAGS}")
|
|
||||||
|
target_link_libraries(flatc PRIVATE $<BUILD_INTERFACE:ProjectConfig>)
|
||||||
|
target_compile_options(flatc
|
||||||
|
PUBLIC
|
||||||
|
$<$<AND:$<BOOL:${MSVC_LIKE}>,$<CONFIG:Release>>:
|
||||||
|
/MT
|
||||||
|
>
|
||||||
|
)
|
||||||
|
|
||||||
if(FLATBUFFERS_CODE_SANITIZE AND NOT WIN32)
|
if(FLATBUFFERS_CODE_SANITIZE AND NOT WIN32)
|
||||||
add_fsanitize_to_target(flatc ${FLATBUFFERS_CODE_SANITIZE})
|
add_fsanitize_to_target(flatc ${FLATBUFFERS_CODE_SANITIZE})
|
||||||
endif()
|
endif()
|
||||||
if(NOT FLATBUFFERS_FLATC_EXECUTABLE)
|
if(NOT FLATBUFFERS_FLATC_EXECUTABLE)
|
||||||
set(FLATBUFFERS_FLATC_EXECUTABLE $<TARGET_FILE:flatc>)
|
set(FLATBUFFERS_FLATC_EXECUTABLE $<TARGET_FILE:flatc>)
|
||||||
endif()
|
endif()
|
||||||
if(MSVC)
|
|
||||||
# Make flatc.exe not depend on runtime dlls for easy distribution.
|
|
||||||
target_compile_options(flatc PUBLIC $<$<CONFIG:Release>:/MT>)
|
|
||||||
endif()
|
|
||||||
if(FLATBUFFERS_STATIC_FLATC AND NOT MSVC)
|
if(FLATBUFFERS_STATIC_FLATC AND NOT MSVC)
|
||||||
target_link_libraries(flatc PRIVATE -static)
|
target_link_libraries(flatc PRIVATE -static)
|
||||||
endif()
|
endif()
|
||||||
@@ -373,17 +468,18 @@ endif()
|
|||||||
|
|
||||||
if(FLATBUFFERS_BUILD_FLATHASH)
|
if(FLATBUFFERS_BUILD_FLATHASH)
|
||||||
add_executable(flathash ${FlatHash_SRCS})
|
add_executable(flathash ${FlatHash_SRCS})
|
||||||
|
target_link_libraries(flathash PRIVATE $<BUILD_INTERFACE:ProjectConfig>)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if(FLATBUFFERS_BUILD_SHAREDLIB)
|
if(FLATBUFFERS_BUILD_SHAREDLIB)
|
||||||
add_library(flatbuffers_shared SHARED ${FlatBuffers_Library_SRCS})
|
add_library(flatbuffers_shared SHARED ${FlatBuffers_Library_SRCS})
|
||||||
|
target_link_libraries(flatbuffers_shared PRIVATE $<BUILD_INTERFACE:ProjectConfig>)
|
||||||
# Shared object version: "major.minor.micro"
|
# Shared object version: "major.minor.micro"
|
||||||
# - micro updated every release when there is no API/ABI changes
|
# - micro updated every release when there is no API/ABI changes
|
||||||
# - minor updated when there are additions in API/ABI
|
# - minor updated when there are additions in API/ABI
|
||||||
# - major (ABI number) updated when there are changes in ABI (or removals)
|
# - major (ABI number) updated when there are changes in ABI (or removals)
|
||||||
set(FlatBuffers_Library_SONAME_MAJOR "2")
|
set(FlatBuffers_Library_SONAME_MAJOR ${VERSION_MAJOR})
|
||||||
set(FlatBuffers_Library_SONAME_FULL "${FlatBuffers_Library_SONAME_MAJOR}.0.0")
|
set(FlatBuffers_Library_SONAME_FULL "${FlatBuffers_Library_SONAME_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}")
|
||||||
set_target_properties(flatbuffers_shared PROPERTIES OUTPUT_NAME flatbuffers
|
set_target_properties(flatbuffers_shared PROPERTIES OUTPUT_NAME flatbuffers
|
||||||
SOVERSION "${FlatBuffers_Library_SONAME_MAJOR}"
|
SOVERSION "${FlatBuffers_Library_SONAME_MAJOR}"
|
||||||
VERSION "${FlatBuffers_Library_SONAME_FULL}")
|
VERSION "${FlatBuffers_Library_SONAME_FULL}")
|
||||||
@@ -438,11 +534,12 @@ function(compile_flatbuffers_schema_to_binary SRC_FBS)
|
|||||||
message(STATUS "`${SRC_FBS}`: add generation of binary (.bfbs) schema")
|
message(STATUS "`${SRC_FBS}`: add generation of binary (.bfbs) schema")
|
||||||
get_filename_component(SRC_FBS_DIR ${SRC_FBS} PATH)
|
get_filename_component(SRC_FBS_DIR ${SRC_FBS} PATH)
|
||||||
string(REGEX REPLACE "\\.fbs$" ".bfbs" GEN_BINARY_SCHEMA ${SRC_FBS})
|
string(REGEX REPLACE "\\.fbs$" ".bfbs" GEN_BINARY_SCHEMA ${SRC_FBS})
|
||||||
# For details about flags see generate_code.bat(sh)
|
# For details about flags see generate_code.py
|
||||||
add_custom_command(
|
add_custom_command(
|
||||||
OUTPUT ${GEN_BINARY_SCHEMA}
|
OUTPUT ${GEN_BINARY_SCHEMA}
|
||||||
COMMAND "${FLATBUFFERS_FLATC_EXECUTABLE}"
|
COMMAND "${FLATBUFFERS_FLATC_EXECUTABLE}"
|
||||||
-b --schema --bfbs-comments --bfbs-builtins
|
-b --schema --bfbs-comments --bfbs-builtins
|
||||||
|
--bfbs-filenames ${SRC_FBS_DIR}
|
||||||
-I "${CMAKE_CURRENT_SOURCE_DIR}/tests/include_test"
|
-I "${CMAKE_CURRENT_SOURCE_DIR}/tests/include_test"
|
||||||
-o "${SRC_FBS_DIR}"
|
-o "${SRC_FBS_DIR}"
|
||||||
"${CMAKE_CURRENT_SOURCE_DIR}/${SRC_FBS}"
|
"${CMAKE_CURRENT_SOURCE_DIR}/${SRC_FBS}"
|
||||||
@@ -460,7 +557,7 @@ function(compile_flatbuffers_schema_to_embedded_binary SRC_FBS OPT)
|
|||||||
message(STATUS "`${SRC_FBS}`: add generation of C++ embedded binary schema code with '${OPT}'")
|
message(STATUS "`${SRC_FBS}`: add generation of C++ embedded binary schema code with '${OPT}'")
|
||||||
get_filename_component(SRC_FBS_DIR ${SRC_FBS} PATH)
|
get_filename_component(SRC_FBS_DIR ${SRC_FBS} PATH)
|
||||||
string(REGEX REPLACE "\\.fbs$" "_bfbs_generated.h" GEN_BFBS_HEADER ${SRC_FBS})
|
string(REGEX REPLACE "\\.fbs$" "_bfbs_generated.h" GEN_BFBS_HEADER ${SRC_FBS})
|
||||||
# For details about flags see generate_code.bat(sh)
|
# For details about flags see generate_code.py
|
||||||
add_custom_command(
|
add_custom_command(
|
||||||
OUTPUT ${GEN_BFBS_HEADER}
|
OUTPUT ${GEN_BFBS_HEADER}
|
||||||
COMMAND "${FLATBUFFERS_FLATC_EXECUTABLE}"
|
COMMAND "${FLATBUFFERS_FLATC_EXECUTABLE}"
|
||||||
@@ -468,6 +565,7 @@ function(compile_flatbuffers_schema_to_embedded_binary SRC_FBS OPT)
|
|||||||
--cpp-ptr-type flatbuffers::unique_ptr # Used to test with C++98 STLs
|
--cpp-ptr-type flatbuffers::unique_ptr # Used to test with C++98 STLs
|
||||||
${OPT}
|
${OPT}
|
||||||
--bfbs-comments --bfbs-builtins --bfbs-gen-embed
|
--bfbs-comments --bfbs-builtins --bfbs-gen-embed
|
||||||
|
--bfbs-filenames ${SRC_FBS_DIR}
|
||||||
-I "${CMAKE_CURRENT_SOURCE_DIR}/tests/include_test"
|
-I "${CMAKE_CURRENT_SOURCE_DIR}/tests/include_test"
|
||||||
-o "${SRC_FBS_DIR}"
|
-o "${SRC_FBS_DIR}"
|
||||||
"${CMAKE_CURRENT_SOURCE_DIR}/${SRC_FBS}"
|
"${CMAKE_CURRENT_SOURCE_DIR}/${SRC_FBS}"
|
||||||
@@ -483,9 +581,9 @@ if(FLATBUFFERS_BUILD_TESTS)
|
|||||||
# TODO Add (monster_test.fbs monsterdata_test.json)->monsterdata_test.mon
|
# TODO Add (monster_test.fbs monsterdata_test.json)->monsterdata_test.mon
|
||||||
compile_flatbuffers_schema_to_cpp(tests/monster_test.fbs)
|
compile_flatbuffers_schema_to_cpp(tests/monster_test.fbs)
|
||||||
compile_flatbuffers_schema_to_binary(tests/monster_test.fbs)
|
compile_flatbuffers_schema_to_binary(tests/monster_test.fbs)
|
||||||
compile_flatbuffers_schema_to_cpp(tests/namespace_test/namespace_test1.fbs)
|
compile_flatbuffers_schema_to_cpp_opt(tests/namespace_test/namespace_test1.fbs "--no-includes;--gen-compare;--gen-name-strings")
|
||||||
compile_flatbuffers_schema_to_cpp(tests/namespace_test/namespace_test2.fbs)
|
compile_flatbuffers_schema_to_cpp_opt(tests/namespace_test/namespace_test2.fbs "--no-includes;--gen-compare;--gen-name-strings")
|
||||||
compile_flatbuffers_schema_to_cpp(tests/union_vector/union_vector.fbs)
|
compile_flatbuffers_schema_to_cpp_opt(tests/union_vector/union_vector.fbs "--no-includes;--gen-compare;--gen-name-strings")
|
||||||
compile_flatbuffers_schema_to_cpp(tests/optional_scalars.fbs)
|
compile_flatbuffers_schema_to_cpp(tests/optional_scalars.fbs)
|
||||||
compile_flatbuffers_schema_to_cpp_opt(tests/native_type_test.fbs "")
|
compile_flatbuffers_schema_to_cpp_opt(tests/native_type_test.fbs "")
|
||||||
compile_flatbuffers_schema_to_cpp_opt(tests/arrays_test.fbs "--scoped-enums;--gen-compare")
|
compile_flatbuffers_schema_to_cpp_opt(tests/arrays_test.fbs "--scoped-enums;--gen-compare")
|
||||||
@@ -496,10 +594,10 @@ if(FLATBUFFERS_BUILD_TESTS)
|
|||||||
endif()
|
endif()
|
||||||
include_directories(${CMAKE_CURRENT_BINARY_DIR}/tests)
|
include_directories(${CMAKE_CURRENT_BINARY_DIR}/tests)
|
||||||
add_executable(flattests ${FlatBuffers_Tests_SRCS})
|
add_executable(flattests ${FlatBuffers_Tests_SRCS})
|
||||||
|
target_link_libraries(flattests PRIVATE $<BUILD_INTERFACE:ProjectConfig>)
|
||||||
|
|
||||||
add_dependencies(flattests generated_code)
|
add_dependencies(flattests generated_code)
|
||||||
set_property(TARGET flattests
|
|
||||||
PROPERTY COMPILE_DEFINITIONS FLATBUFFERS_TRACK_VERIFIER_BUFFER_SIZE
|
|
||||||
FLATBUFFERS_DEBUG_VERIFICATION_FAILURE=1)
|
|
||||||
if(FLATBUFFERS_CODE_SANITIZE)
|
if(FLATBUFFERS_CODE_SANITIZE)
|
||||||
add_fsanitize_to_target(flattests ${FLATBUFFERS_CODE_SANITIZE})
|
add_fsanitize_to_target(flattests ${FLATBUFFERS_CODE_SANITIZE})
|
||||||
endif()
|
endif()
|
||||||
@@ -507,24 +605,27 @@ if(FLATBUFFERS_BUILD_TESTS)
|
|||||||
compile_flatbuffers_schema_to_cpp(samples/monster.fbs)
|
compile_flatbuffers_schema_to_cpp(samples/monster.fbs)
|
||||||
compile_flatbuffers_schema_to_binary(samples/monster.fbs)
|
compile_flatbuffers_schema_to_binary(samples/monster.fbs)
|
||||||
include_directories(${CMAKE_CURRENT_BINARY_DIR}/samples)
|
include_directories(${CMAKE_CURRENT_BINARY_DIR}/samples)
|
||||||
|
|
||||||
add_executable(flatsamplebinary ${FlatBuffers_Sample_Binary_SRCS})
|
add_executable(flatsamplebinary ${FlatBuffers_Sample_Binary_SRCS})
|
||||||
|
target_link_libraries(flatsamplebinary PRIVATE $<BUILD_INTERFACE:ProjectConfig>)
|
||||||
add_dependencies(flatsamplebinary generated_code)
|
add_dependencies(flatsamplebinary generated_code)
|
||||||
|
|
||||||
add_executable(flatsampletext ${FlatBuffers_Sample_Text_SRCS})
|
add_executable(flatsampletext ${FlatBuffers_Sample_Text_SRCS})
|
||||||
|
target_link_libraries(flatsampletext PRIVATE $<BUILD_INTERFACE:ProjectConfig>)
|
||||||
add_dependencies(flatsampletext generated_code)
|
add_dependencies(flatsampletext generated_code)
|
||||||
|
|
||||||
add_executable(flatsamplebfbs ${FlatBuffers_Sample_BFBS_SRCS})
|
add_executable(flatsamplebfbs ${FlatBuffers_Sample_BFBS_SRCS})
|
||||||
|
target_link_libraries(flatsamplebfbs PRIVATE $<BUILD_INTERFACE:ProjectConfig>)
|
||||||
add_dependencies(flatsamplebfbs generated_code)
|
add_dependencies(flatsamplebfbs generated_code)
|
||||||
|
|
||||||
if(FLATBUFFERS_BUILD_CPP17)
|
if(FLATBUFFERS_BUILD_CPP17)
|
||||||
# Don't generate header for flattests_cpp17 target.
|
# Don't generate header for flattests_cpp17 target.
|
||||||
# This target uses "generated_cpp17/monster_test_generated.h"
|
# This target uses "generated_cpp17/monster_test_generated.h"
|
||||||
# produced by direct call of generate_code.bat(sh) script.
|
|
||||||
add_executable(flattests_cpp17 ${FlatBuffers_Tests_CPP17_SRCS})
|
add_executable(flattests_cpp17 ${FlatBuffers_Tests_CPP17_SRCS})
|
||||||
add_dependencies(flattests_cpp17 generated_code)
|
add_dependencies(flattests_cpp17 generated_code)
|
||||||
|
target_link_libraries(flattests_cpp17 PRIVATE $<BUILD_INTERFACE:ProjectConfig>)
|
||||||
target_compile_features(flattests_cpp17 PRIVATE cxx_std_17)
|
target_compile_features(flattests_cpp17 PRIVATE cxx_std_17)
|
||||||
target_compile_definitions(flattests_cpp17 PRIVATE
|
|
||||||
FLATBUFFERS_TRACK_VERIFIER_BUFFER_SIZE
|
|
||||||
FLATBUFFERS_DEBUG_VERIFICATION_FAILURE=1
|
|
||||||
)
|
|
||||||
if(FLATBUFFERS_CODE_SANITIZE)
|
if(FLATBUFFERS_CODE_SANITIZE)
|
||||||
add_fsanitize_to_target(flattests_cpp17 ${FLATBUFFERS_CODE_SANITIZE})
|
add_fsanitize_to_target(flattests_cpp17 ${FLATBUFFERS_CODE_SANITIZE})
|
||||||
endif()
|
endif()
|
||||||
@@ -532,9 +633,6 @@ if(FLATBUFFERS_BUILD_TESTS)
|
|||||||
endif()
|
endif()
|
||||||
|
|
||||||
if(FLATBUFFERS_BUILD_GRPCTEST)
|
if(FLATBUFFERS_BUILD_GRPCTEST)
|
||||||
if(CMAKE_COMPILER_IS_GNUCXX)
|
|
||||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unused-parameter -Wno-shadow")
|
|
||||||
endif()
|
|
||||||
if(NOT GRPC_INSTALL_PATH)
|
if(NOT GRPC_INSTALL_PATH)
|
||||||
message(SEND_ERROR "GRPC_INSTALL_PATH variable is not defined. See grpc/README.md")
|
message(SEND_ERROR "GRPC_INSTALL_PATH variable is not defined. See grpc/README.md")
|
||||||
endif()
|
endif()
|
||||||
@@ -545,19 +643,21 @@ if(FLATBUFFERS_BUILD_GRPCTEST)
|
|||||||
INCLUDE_DIRECTORIES(${PROTOBUF_DOWNLOAD_PATH}/src)
|
INCLUDE_DIRECTORIES(${PROTOBUF_DOWNLOAD_PATH}/src)
|
||||||
find_package(Threads REQUIRED)
|
find_package(Threads REQUIRED)
|
||||||
list(APPEND CMAKE_PREFIX_PATH ${GRPC_INSTALL_PATH})
|
list(APPEND CMAKE_PREFIX_PATH ${GRPC_INSTALL_PATH})
|
||||||
|
find_package(absl CONFIG REQUIRED)
|
||||||
find_package(protobuf CONFIG REQUIRED)
|
find_package(protobuf CONFIG REQUIRED)
|
||||||
find_package(gRPC CONFIG REQUIRED)
|
find_package(gRPC CONFIG REQUIRED)
|
||||||
add_executable(grpctest ${FlatBuffers_GRPCTest_SRCS})
|
add_executable(grpctest ${FlatBuffers_GRPCTest_SRCS})
|
||||||
add_dependencies(grpctest generated_code)
|
add_dependencies(grpctest generated_code)
|
||||||
target_link_libraries(grpctest PRIVATE gRPC::grpc++_unsecure gRPC::grpc_unsecure gRPC::gpr pthread dl)
|
target_link_libraries(grpctext
|
||||||
if(FLATBUFFERS_CODE_SANITIZE AND NOT WIN32)
|
PRIVATE
|
||||||
# GRPC test has problems with alignment and will fail under ASAN/UBSAN.
|
$<BUILD_INTERFACE:ProjectConfig>
|
||||||
# add_fsanitize_to_target(grpctest ${FLATBUFFERS_CODE_SANITIZE})
|
gRPC::grpc++_unsecure
|
||||||
endif()
|
gRPC::gpr
|
||||||
|
pthread
|
||||||
|
dl
|
||||||
|
)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
include(CMake/Version.cmake)
|
|
||||||
|
|
||||||
if(FLATBUFFERS_INSTALL)
|
if(FLATBUFFERS_INSTALL)
|
||||||
include(GNUInstallDirs)
|
include(GNUInstallDirs)
|
||||||
|
|
||||||
@@ -565,28 +665,21 @@ if(FLATBUFFERS_INSTALL)
|
|||||||
|
|
||||||
set(FB_CMAKE_DIR "${CMAKE_INSTALL_LIBDIR}/cmake/flatbuffers")
|
set(FB_CMAKE_DIR "${CMAKE_INSTALL_LIBDIR}/cmake/flatbuffers")
|
||||||
|
|
||||||
configure_file(CMake/FlatbuffersConfigVersion.cmake.in FlatbuffersConfigVersion.cmake @ONLY)
|
configure_file(CMake/FlatBuffersConfigVersion.cmake.in FlatBuffersConfigVersion.cmake @ONLY)
|
||||||
install(
|
install(
|
||||||
FILES "CMake/FlatbuffersConfig.cmake" "${CMAKE_CURRENT_BINARY_DIR}/FlatbuffersConfigVersion.cmake"
|
FILES "CMake/FlatBuffersConfig.cmake" "${CMAKE_CURRENT_BINARY_DIR}/FlatBuffersConfigVersion.cmake"
|
||||||
DESTINATION ${FB_CMAKE_DIR}
|
DESTINATION ${FB_CMAKE_DIR}
|
||||||
)
|
)
|
||||||
|
|
||||||
if(FLATBUFFERS_BUILD_FLATLIB)
|
if(FLATBUFFERS_BUILD_FLATLIB)
|
||||||
if(CMAKE_VERSION VERSION_LESS 3.0)
|
install(
|
||||||
install(
|
TARGETS flatbuffers EXPORT FlatBuffersTargets
|
||||||
TARGETS flatbuffers EXPORT FlatbuffersTargets
|
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
||||||
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
|
||||||
)
|
)
|
||||||
else()
|
|
||||||
install(
|
|
||||||
TARGETS flatbuffers EXPORT FlatbuffersTargets
|
|
||||||
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
|
||||||
INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
|
|
||||||
)
|
|
||||||
endif()
|
|
||||||
|
|
||||||
install(EXPORT FlatbuffersTargets
|
install(EXPORT FlatBuffersTargets
|
||||||
FILE FlatbuffersTargets.cmake
|
FILE FlatBuffersTargets.cmake
|
||||||
NAMESPACE flatbuffers::
|
NAMESPACE flatbuffers::
|
||||||
DESTINATION ${FB_CMAKE_DIR}
|
DESTINATION ${FB_CMAKE_DIR}
|
||||||
)
|
)
|
||||||
@@ -607,26 +700,17 @@ if(FLATBUFFERS_INSTALL)
|
|||||||
endif()
|
endif()
|
||||||
|
|
||||||
if(FLATBUFFERS_BUILD_SHAREDLIB)
|
if(FLATBUFFERS_BUILD_SHAREDLIB)
|
||||||
if(CMAKE_VERSION VERSION_LESS 3.0)
|
install(
|
||||||
install(
|
TARGETS flatbuffers_shared EXPORT FlatBuffersSharedTargets
|
||||||
TARGETS flatbuffers_shared EXPORT FlatbuffersSharedTargets
|
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
||||||
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
RUNTIME DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
||||||
RUNTIME DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
||||||
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
|
||||||
)
|
)
|
||||||
else()
|
|
||||||
install(
|
|
||||||
TARGETS flatbuffers_shared EXPORT FlatbuffersSharedTargets
|
|
||||||
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
|
||||||
RUNTIME DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
|
||||||
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
|
||||||
INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
|
|
||||||
)
|
|
||||||
endif()
|
|
||||||
|
|
||||||
install(
|
install(
|
||||||
EXPORT FlatbuffersSharedTargets
|
EXPORT FlatBuffersSharedTargets
|
||||||
FILE FlatbuffersSharedTargets.cmake
|
FILE FlatBuffersSharedTargets.cmake
|
||||||
NAMESPACE flatbuffers::
|
NAMESPACE flatbuffers::
|
||||||
DESTINATION ${FB_CMAKE_DIR}
|
DESTINATION ${FB_CMAKE_DIR}
|
||||||
)
|
)
|
||||||
@@ -676,3 +760,16 @@ if(UNIX)
|
|||||||
include(CPack)
|
include(CPack)
|
||||||
endif()
|
endif()
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
# Include for running Google Benchmarks.
|
||||||
|
if(FLATBUFFERS_BUILD_BENCHMARKS)
|
||||||
|
add_subdirectory(benchmarks)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
# Add FlatBuffers::FlatBuffers interface, needed for FetchContent_Declare
|
||||||
|
add_library(FlatBuffers INTERFACE)
|
||||||
|
add_library(FlatBuffers::FlatBuffers ALIAS FlatBuffers)
|
||||||
|
target_include_directories(
|
||||||
|
FlatBuffers
|
||||||
|
INTERFACE $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
|
||||||
|
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/include>)
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ If you are interesting in contributing to the flatbuffers project, please take a
|
|||||||
|
|
||||||
## C++
|
## C++
|
||||||
|
|
||||||
C++ uses `clang-format` as it's formatter. Run the following script `sh src/clang-format-git.sh`, and it should style the C++ code according to [google style guide](https://google.github.io/styleguide/cppguide.html).
|
C++ uses `clang-format` as it's formatter. Run the following script `sh scripts/clang-format-git.sh`, and it should style the C++ code according to [google style guide](https://google.github.io/styleguide/cppguide.html).
|
||||||
|
|
||||||
## Swift
|
## Swift
|
||||||
|
|
||||||
|
|||||||
11
SECURITY.md
Normal file
11
SECURITY.md
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
# Security Policy
|
||||||
|
|
||||||
|
## Reporting a Vulnerability
|
||||||
|
|
||||||
|
To report a security issue, please use http://g.co/vulnz. We use
|
||||||
|
http://g.co/vulnz for our intake, and do coordination and disclosure here on
|
||||||
|
GitHub (including using GitHub Security Advisory). The Google Security Team will
|
||||||
|
respond within 5 working days of your report on g.co/vulnz.
|
||||||
|
|
||||||
|
Select the `I want to report a technical security or an abuse risk related bug
|
||||||
|
in a Google product (SQLi, XSS, etc.)` option and complete the form.
|
||||||
70
WORKSPACE
70
WORKSPACE
@@ -3,20 +3,47 @@ workspace(name = "com_github_google_flatbuffers")
|
|||||||
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
|
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
|
||||||
|
|
||||||
http_archive(
|
http_archive(
|
||||||
name = "io_bazel_rules_go",
|
name = "platforms",
|
||||||
sha256 = "d1ffd055969c8f8d431e2d439813e42326961d0942bdf734d2c95dc30c369566",
|
sha256 = "379113459b0feaf6bfbb584a91874c065078aa673222846ac765f86661c27407",
|
||||||
urls = [
|
urls = [
|
||||||
"https://mirror.bazel.build/github.com/bazelbuild/rules_go/releases/download/v0.24.5/rules_go-v0.24.5.tar.gz",
|
"https://mirror.bazel.build/github.com/bazelbuild/platforms/releases/download/0.0.5/platforms-0.0.5.tar.gz",
|
||||||
"https://github.com/bazelbuild/rules_go/releases/download/v0.24.5/rules_go-v0.24.5.tar.gz",
|
"https://github.com/bazelbuild/platforms/releases/download/0.0.5/platforms-0.0.5.tar.gz",
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
||||||
load("@io_bazel_rules_go//go:deps.bzl", "go_register_toolchains", "go_rules_dependencies")
|
http_archive(
|
||||||
|
name = "build_bazel_rules_swift",
|
||||||
|
sha256 = "a2fd565e527f83fb3f9eb07eb9737240e668c9242d3bc318712efa54a7deda97",
|
||||||
|
url = "https://github.com/bazelbuild/rules_swift/releases/download/0.27.0/rules_swift.0.27.0.tar.gz",
|
||||||
|
)
|
||||||
|
|
||||||
|
load(
|
||||||
|
"@build_bazel_rules_swift//swift:repositories.bzl",
|
||||||
|
"swift_rules_dependencies",
|
||||||
|
)
|
||||||
|
|
||||||
|
swift_rules_dependencies()
|
||||||
|
|
||||||
|
load(
|
||||||
|
"@build_bazel_rules_swift//swift:extras.bzl",
|
||||||
|
"swift_rules_extra_dependencies",
|
||||||
|
)
|
||||||
|
|
||||||
|
swift_rules_extra_dependencies()
|
||||||
|
|
||||||
|
http_archive(
|
||||||
|
name = "io_bazel_rules_go",
|
||||||
|
sha256 = "16e9fca53ed6bd4ff4ad76facc9b7b651a89db1689a2877d6fd7b82aa824e366",
|
||||||
|
urls = [
|
||||||
|
"https://mirror.bazel.build/github.com/bazelbuild/rules_go/releases/download/v0.34.0/rules_go-v0.34.0.zip",
|
||||||
|
"https://github.com/bazelbuild/rules_go/releases/download/v0.34.0/rules_go-v0.34.0.zip",
|
||||||
|
],
|
||||||
|
)
|
||||||
|
|
||||||
|
load("@io_bazel_rules_go//go:deps.bzl", "go_rules_dependencies")
|
||||||
|
|
||||||
go_rules_dependencies()
|
go_rules_dependencies()
|
||||||
|
|
||||||
go_register_toolchains()
|
|
||||||
|
|
||||||
##### Protobuf
|
##### Protobuf
|
||||||
_PROTOBUF_VERSION = "3.15.2"
|
_PROTOBUF_VERSION = "3.15.2"
|
||||||
|
|
||||||
@@ -29,12 +56,12 @@ http_archive(
|
|||||||
)
|
)
|
||||||
|
|
||||||
##### GRPC
|
##### GRPC
|
||||||
_GRPC_VERSION = "1.36.1"
|
_GRPC_VERSION = "1.48.0" # https://github.com/grpc/grpc/releases/tag/v1.48.0
|
||||||
|
|
||||||
http_archive(
|
http_archive(
|
||||||
name = "com_github_grpc_grpc",
|
name = "com_github_grpc_grpc",
|
||||||
strip_prefix = "grpc-" + _GRPC_VERSION,
|
strip_prefix = "grpc-" + _GRPC_VERSION,
|
||||||
urls = ["https://github.com/grpc/grpc/archive/v" + _GRPC_VERSION + ".tar.gz"],
|
urls = ["https://github.com/grpc/grpc/archive/refs/tags/v" + _GRPC_VERSION + ".tar.gz"],
|
||||||
)
|
)
|
||||||
|
|
||||||
load("@com_github_grpc_grpc//bazel:grpc_deps.bzl", "grpc_deps")
|
load("@com_github_grpc_grpc//bazel:grpc_deps.bzl", "grpc_deps")
|
||||||
@@ -44,3 +71,28 @@ grpc_deps()
|
|||||||
load("@com_github_grpc_grpc//bazel:grpc_extra_deps.bzl", "grpc_extra_deps")
|
load("@com_github_grpc_grpc//bazel:grpc_extra_deps.bzl", "grpc_extra_deps")
|
||||||
|
|
||||||
grpc_extra_deps()
|
grpc_extra_deps()
|
||||||
|
|
||||||
|
# rules_go from https://github.com/bazelbuild/rules_go/releases/tag/v0.34.0
|
||||||
|
http_archive(
|
||||||
|
name = "build_bazel_rules_nodejs",
|
||||||
|
sha256 = "965ee2492a2b087cf9e0f2ca472aeaf1be2eb650e0cfbddf514b9a7d3ea4b02a",
|
||||||
|
urls = ["https://github.com/bazelbuild/rules_nodejs/releases/download/5.2.0/rules_nodejs-5.2.0.tar.gz"],
|
||||||
|
)
|
||||||
|
|
||||||
|
load("@build_bazel_rules_nodejs//:repositories.bzl", "build_bazel_rules_nodejs_dependencies")
|
||||||
|
|
||||||
|
build_bazel_rules_nodejs_dependencies()
|
||||||
|
|
||||||
|
load("@build_bazel_rules_nodejs//:index.bzl", "node_repositories", "yarn_install")
|
||||||
|
|
||||||
|
node_repositories()
|
||||||
|
|
||||||
|
yarn_install(
|
||||||
|
name = "npm",
|
||||||
|
exports_directories_only = False,
|
||||||
|
# Unfreeze to add/remove packages.
|
||||||
|
frozen_lockfile = True,
|
||||||
|
package_json = "//:package.json",
|
||||||
|
symlink_node_modules = False,
|
||||||
|
yarn_lock = "//:yarn.lock",
|
||||||
|
)
|
||||||
|
|||||||
@@ -1,20 +1,4 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<!-- Copyright (c) 2013 Google, Inc.
|
|
||||||
|
|
||||||
This software is provided 'as-is', without any express or implied
|
|
||||||
warranty. In no event will the authors be held liable for any damages
|
|
||||||
arising from the use of this software.
|
|
||||||
Permission is granted to anyone to use this software for any purpose,
|
|
||||||
including commercial applications, and to alter it and redistribute it
|
|
||||||
freely, subject to the following restrictions:
|
|
||||||
1. The origin of this software must not be misrepresented; you must not
|
|
||||||
claim that you wrote the original software. If you use this software
|
|
||||||
in a product, an acknowledgment in the product documentation would be
|
|
||||||
appreciated but is not required.
|
|
||||||
2. Altered source versions must be plainly marked as such, and must not be
|
|
||||||
misrepresented as being the original software.
|
|
||||||
3. This notice may not be removed or altered from any source distribution.
|
|
||||||
-->
|
|
||||||
<!-- BEGIN_INCLUDE(manifest) -->
|
<!-- BEGIN_INCLUDE(manifest) -->
|
||||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
package="com.example.FlatBufferTest">
|
package="com.example.FlatBufferTest">
|
||||||
|
|||||||
@@ -18,6 +18,10 @@ android {
|
|||||||
targetCompatibility JavaVersion.VERSION_1_8
|
targetCompatibility JavaVersion.VERSION_1_8
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ndk {
|
||||||
|
abiFilters 'arm64-v8a', 'armeabi-v7a'
|
||||||
|
}
|
||||||
|
|
||||||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
||||||
externalNativeBuild {
|
externalNativeBuild {
|
||||||
cmake {
|
cmake {
|
||||||
@@ -33,7 +37,6 @@ android {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ndkVersion "21.3.6528147"
|
|
||||||
externalNativeBuild {
|
externalNativeBuild {
|
||||||
cmake {
|
cmake {
|
||||||
path "src/main/cpp/CMakeLists.txt"
|
path "src/main/cpp/CMakeLists.txt"
|
||||||
@@ -52,16 +55,17 @@ android {
|
|||||||
fbsFiles.forEach{
|
fbsFiles.forEach{
|
||||||
commandLineArgs.add(it.path)
|
commandLineArgs.add(it.path)
|
||||||
}
|
}
|
||||||
|
|
||||||
commandLine commandLineArgs
|
commandLine commandLineArgs
|
||||||
|
|
||||||
doFirst {
|
doFirst {
|
||||||
delete "$outputCppDir/"
|
delete "$outputCppDir/"
|
||||||
mkdir "$outputCppDir/"
|
mkdir "$outputCppDir/"
|
||||||
}
|
}
|
||||||
|
|
||||||
doLast {
|
doLast {
|
||||||
if (execResult.getExitValue() != 0) {
|
if (executionResult.get().exitValue != 0) {
|
||||||
println(standardOutput.toString())
|
throw new GradleException("flatc failed with: ${executionResult.get().toString()}")
|
||||||
throw new GradleException("flatc command line failed")
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -74,6 +78,10 @@ android {
|
|||||||
|
|
||||||
standardOutput = new ByteArrayOutputStream()
|
standardOutput = new ByteArrayOutputStream()
|
||||||
errorOutput = new ByteArrayOutputStream()
|
errorOutput = new ByteArrayOutputStream()
|
||||||
|
|
||||||
|
setErrorOutput(errorOutput)
|
||||||
|
setStandardOutput(standardOutput)
|
||||||
|
|
||||||
def commandLineArgs = ['flatc', '-o', outputKotlinDir, '--kotlin']
|
def commandLineArgs = ['flatc', '-o', outputKotlinDir, '--kotlin']
|
||||||
fbsFiles.forEach{
|
fbsFiles.forEach{
|
||||||
commandLineArgs.add(it.path)
|
commandLineArgs.add(it.path)
|
||||||
@@ -85,53 +93,42 @@ android {
|
|||||||
mkdir "$outputKotlinDir/"
|
mkdir "$outputKotlinDir/"
|
||||||
}
|
}
|
||||||
doLast {
|
doLast {
|
||||||
if (execResult.getExitValue() != 0) {
|
if (executionResult.get().exitValue != 0) {
|
||||||
println(standardOutput.toString())
|
throw new GradleException("flatc failed with: ${executionResult.get().toString()}")
|
||||||
throw new GradleException("flatc command line failed")
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
afterEvaluate {
|
afterEvaluate {
|
||||||
android.applicationVariants.all { variant ->
|
tasks.named("preBuild") {
|
||||||
variant.javaCompiler.dependsOn(generateFbsKotlin)
|
dependsOn(generateFbsKotlin)
|
||||||
variant.javaCompiler.dependsOn(generateFbsCpp)
|
dependsOn(generateFbsCpp)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
flavorDimensions "stl-variant"
|
// flavorDimensions "stl-variant"
|
||||||
productFlavors {
|
// productFlavors {
|
||||||
stlport {
|
// gnustl {
|
||||||
dimension "stl-variant"
|
// dimension "stl-variant"
|
||||||
applicationIdSuffix ".stlport"
|
// applicationIdSuffix ".gnustl"
|
||||||
versionNameSuffix "-stlport"
|
// versionNameSuffix "-gnustl"
|
||||||
externalNativeBuild {
|
// externalNativeBuild {
|
||||||
ndkBuild {
|
// ndkBuild {
|
||||||
arguments "APP_STL=stlport_static"
|
// arguments "APP_STL=gnustl_static"
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
gnustl {
|
// libcpp {
|
||||||
dimension "stl-variant"
|
// dimension "stl-variant"
|
||||||
applicationIdSuffix ".gnustl"
|
// applicationIdSuffix ".libcpp"
|
||||||
versionNameSuffix "-gnustl"
|
// versionNameSuffix "-libcpp"
|
||||||
externalNativeBuild {
|
// externalNativeBuild {
|
||||||
ndkBuild {
|
// ndkBuild {
|
||||||
arguments "APP_STL=gnustl_static"
|
// arguments "APP_STL=c++_static"
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
libcpp {
|
// }
|
||||||
dimension "stl-variant"
|
|
||||||
applicationIdSuffix ".libcpp"
|
|
||||||
versionNameSuffix "-libcpp"
|
|
||||||
externalNativeBuild {
|
|
||||||
ndkBuild {
|
|
||||||
arguments "APP_STL=c++_static"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
|
|||||||
@@ -15,17 +15,32 @@ set(CMAKE_CXX_FLAGS
|
|||||||
"${CMAKE_CXX_FLAGS} -fsigned-char")
|
"${CMAKE_CXX_FLAGS} -fsigned-char")
|
||||||
|
|
||||||
set(FlatBuffers_Library_SRCS
|
set(FlatBuffers_Library_SRCS
|
||||||
|
${FLATBUFFERS_SRC}/include/flatbuffers/allocator.h
|
||||||
|
${FLATBUFFERS_SRC}/include/flatbuffers/array.h
|
||||||
${FLATBUFFERS_SRC}/include/flatbuffers/base.h
|
${FLATBUFFERS_SRC}/include/flatbuffers/base.h
|
||||||
|
${FLATBUFFERS_SRC}/include/flatbuffers/bfbs_generator.h
|
||||||
|
${FLATBUFFERS_SRC}/include/flatbuffers/buffer.h
|
||||||
|
${FLATBUFFERS_SRC}/include/flatbuffers/buffer_ref.h
|
||||||
|
${FLATBUFFERS_SRC}/include/flatbuffers/default_allocator.h
|
||||||
|
${FLATBUFFERS_SRC}/include/flatbuffers/detached_buffer.h
|
||||||
|
${FLATBUFFERS_SRC}/include/flatbuffers/flatbuffer_builder.h
|
||||||
${FLATBUFFERS_SRC}/include/flatbuffers/flatbuffers.h
|
${FLATBUFFERS_SRC}/include/flatbuffers/flatbuffers.h
|
||||||
|
${FLATBUFFERS_SRC}/include/flatbuffers/flexbuffers.h
|
||||||
|
${FLATBUFFERS_SRC}/include/flatbuffers/flex_flat_util.h
|
||||||
${FLATBUFFERS_SRC}/include/flatbuffers/hash.h
|
${FLATBUFFERS_SRC}/include/flatbuffers/hash.h
|
||||||
${FLATBUFFERS_SRC}/include/flatbuffers/idl.h
|
${FLATBUFFERS_SRC}/include/flatbuffers/idl.h
|
||||||
${FLATBUFFERS_SRC}/include/flatbuffers/util.h
|
${FLATBUFFERS_SRC}/include/flatbuffers/minireflect.h
|
||||||
${FLATBUFFERS_SRC}/include/flatbuffers/reflection.h
|
${FLATBUFFERS_SRC}/include/flatbuffers/reflection.h
|
||||||
${FLATBUFFERS_SRC}/include/flatbuffers/reflection_generated.h
|
${FLATBUFFERS_SRC}/include/flatbuffers/reflection_generated.h
|
||||||
${FLATBUFFERS_SRC}/include/flatbuffers/stl_emulation.h
|
|
||||||
${FLATBUFFERS_SRC}/include/flatbuffers/flexbuffers.h
|
|
||||||
${FLATBUFFERS_SRC}/include/flatbuffers/registry.h
|
${FLATBUFFERS_SRC}/include/flatbuffers/registry.h
|
||||||
${FLATBUFFERS_SRC}/include/flatbuffers/minireflect.h
|
${FLATBUFFERS_SRC}/include/flatbuffers/stl_emulation.h
|
||||||
|
${FLATBUFFERS_SRC}/include/flatbuffers/string.h
|
||||||
|
${FLATBUFFERS_SRC}/include/flatbuffers/struct.h
|
||||||
|
${FLATBUFFERS_SRC}/include/flatbuffers/table.h
|
||||||
|
${FLATBUFFERS_SRC}/include/flatbuffers/util.h
|
||||||
|
${FLATBUFFERS_SRC}/include/flatbuffers/vector.h
|
||||||
|
${FLATBUFFERS_SRC}/include/flatbuffers/vector_downward.h
|
||||||
|
${FLATBUFFERS_SRC}/include/flatbuffers/verifier.h
|
||||||
${FLATBUFFERS_SRC}/src/idl_parser.cpp
|
${FLATBUFFERS_SRC}/src/idl_parser.cpp
|
||||||
${FLATBUFFERS_SRC}/src/idl_gen_text.cpp
|
${FLATBUFFERS_SRC}/src/idl_gen_text.cpp
|
||||||
${FLATBUFFERS_SRC}/src/reflection.cpp
|
${FLATBUFFERS_SRC}/src/reflection.cpp
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ struct Animal FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table {
|
|||||||
verifier.VerifyString(name()) &&
|
verifier.VerifyString(name()) &&
|
||||||
VerifyOffset(verifier, VT_SOUND) &&
|
VerifyOffset(verifier, VT_SOUND) &&
|
||||||
verifier.VerifyString(sound()) &&
|
verifier.VerifyString(sound()) &&
|
||||||
VerifyField<uint16_t>(verifier, VT_WEIGHT) &&
|
VerifyField<uint16_t>(verifier, VT_WEIGHT, 2) &&
|
||||||
verifier.EndTable();
|
verifier.EndTable();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -57,7 +57,6 @@ struct AnimalBuilder {
|
|||||||
: fbb_(_fbb) {
|
: fbb_(_fbb) {
|
||||||
start_ = fbb_.StartTable();
|
start_ = fbb_.StartTable();
|
||||||
}
|
}
|
||||||
AnimalBuilder &operator=(const AnimalBuilder &);
|
|
||||||
flatbuffers::Offset<Animal> Finish() {
|
flatbuffers::Offset<Animal> Finish() {
|
||||||
const auto end = fbb_.EndTable(start_);
|
const auto end = fbb_.EndTable(start_);
|
||||||
auto o = flatbuffers::Offset<Animal>(end);
|
auto o = flatbuffers::Offset<Animal>(end);
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ import kotlin.math.sign
|
|||||||
import com.google.flatbuffers.*
|
import com.google.flatbuffers.*
|
||||||
|
|
||||||
@Suppress("unused")
|
@Suppress("unused")
|
||||||
@ExperimentalUnsignedTypes
|
|
||||||
class Animal : Table() {
|
class Animal : Table() {
|
||||||
|
|
||||||
fun __init(_i: Int, _bb: ByteBuffer) {
|
fun __init(_i: Int, _bb: ByteBuffer) {
|
||||||
|
|||||||
@@ -19,3 +19,5 @@ android.useAndroidX=true
|
|||||||
android.enableJetifier=true
|
android.enableJetifier=true
|
||||||
# Kotlin code style for this project: "official" or "obsolete":
|
# Kotlin code style for this project: "official" or "obsolete":
|
||||||
kotlin.code.style=official
|
kotlin.code.style=official
|
||||||
|
# Use parallel builds
|
||||||
|
org.gradle.parallel=true
|
||||||
BIN
android/gradle/wrapper/gradle-wrapper.jar
vendored
BIN
android/gradle/wrapper/gradle-wrapper.jar
vendored
Binary file not shown.
@@ -1,6 +1,5 @@
|
|||||||
#Thu Oct 29 19:47:23 CET 2020
|
|
||||||
distributionBase=GRADLE_USER_HOME
|
distributionBase=GRADLE_USER_HOME
|
||||||
distributionPath=wrapper/dists
|
distributionPath=wrapper/dists
|
||||||
|
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4.2-bin.zip
|
||||||
zipStoreBase=GRADLE_USER_HOME
|
zipStoreBase=GRADLE_USER_HOME
|
||||||
zipStorePath=wrapper/dists
|
zipStorePath=wrapper/dists
|
||||||
distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-all.zip
|
|
||||||
|
|||||||
89
appveyor.yml
89
appveyor.yml
@@ -1,89 +0,0 @@
|
|||||||
branches:
|
|
||||||
only:
|
|
||||||
- master
|
|
||||||
|
|
||||||
environment:
|
|
||||||
nodejs_version: "14"
|
|
||||||
|
|
||||||
global:
|
|
||||||
# Workaround for https://github.com/conda/conda-build/issues/636
|
|
||||||
PYTHONIOENCODING: UTF-8
|
|
||||||
CONDA_INSTALL_LOCN: "C:\\Miniconda35-x64"
|
|
||||||
CMAKE_OPTIONS: ""
|
|
||||||
CPP_TEST_OPTIONS: ""
|
|
||||||
|
|
||||||
matrix:
|
|
||||||
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015
|
|
||||||
CMAKE_VS_VERSION: "10 2010"
|
|
||||||
CMAKE_OPTIONS: "-DFLATBUFFERS_BUILD_LEGACY=1"
|
|
||||||
CPP_TEST_OPTIONS: "--std-cpp c++0x"
|
|
||||||
MONSTER_EXTRA: "skip"
|
|
||||||
|
|
||||||
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015
|
|
||||||
CMAKE_VS_VERSION: "12 2013"
|
|
||||||
MONSTER_EXTRA: "skip"
|
|
||||||
|
|
||||||
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015
|
|
||||||
CMAKE_VS_VERSION: "14 2015"
|
|
||||||
MONSTER_EXTRA: ""
|
|
||||||
|
|
||||||
platform:
|
|
||||||
- x86
|
|
||||||
- x64
|
|
||||||
|
|
||||||
configuration:
|
|
||||||
- Debug
|
|
||||||
- Release
|
|
||||||
|
|
||||||
before_build:
|
|
||||||
- set MONSTER_EXTRA=%MONSTER_EXTRA%
|
|
||||||
- cmake . -G"Visual Studio %CMAKE_VS_VERSION%" -DFLATBUFFERS_CODE_SANITIZE=1 %CMAKE_OPTIONS%
|
|
||||||
# This cuts down on a lot of noise generated by xamarin warnings.
|
|
||||||
- if exist "C:\Program Files (x86)\MSBuild\14.0\Microsoft.Common.targets\ImportAfter\Xamarin.Common.targets" del "C:\Program Files (x86)\MSBuild\14.0\Microsoft.Common.targets\ImportAfter\Xamarin.Common.targets"
|
|
||||||
|
|
||||||
build:
|
|
||||||
project: ALL_BUILD.vcxproj
|
|
||||||
verbosity: minimal
|
|
||||||
|
|
||||||
after_build:
|
|
||||||
- python conan/appveyor/install.py
|
|
||||||
- python conan/appveyor/build.py
|
|
||||||
|
|
||||||
install:
|
|
||||||
- set PATH=%CONDA_INSTALL_LOCN%;%CONDA_INSTALL_LOCN%\scripts;%PATH%;
|
|
||||||
- ps: Install-Product node $env:nodejs_version
|
|
||||||
|
|
||||||
test_script:
|
|
||||||
- call .appveyor\check-generate-code.bat -b %CONFIGURATION%
|
|
||||||
- "cd tests"
|
|
||||||
- rem "Building all code"
|
|
||||||
- generate_code.bat -b %CONFIGURATION% %CPP_TEST_OPTIONS%
|
|
||||||
- 7z a GeneratedMyGameCode.zip MyGame\
|
|
||||||
- rem "---------------- C++ -----------------"
|
|
||||||
- "cd .."
|
|
||||||
- "%CONFIGURATION%\\flattests.exe"
|
|
||||||
- rem "---------------- JS -----------------"
|
|
||||||
- "node --version"
|
|
||||||
- "npm install"
|
|
||||||
- "npm run compile"
|
|
||||||
- "cd tests"
|
|
||||||
- "TypeScriptTest.bat"
|
|
||||||
- rem "---------------- C# -----------------"
|
|
||||||
# Have to compile this here rather than in "build" above because AppVeyor only
|
|
||||||
# supports building one project??
|
|
||||||
- "cd FlatBuffers.Test"
|
|
||||||
- "dotnet new sln"
|
|
||||||
- "dotnet sln add FlatBuffers.Test.csproj"
|
|
||||||
- "nuget restore"
|
|
||||||
- "mkdir .tmp"
|
|
||||||
- "msbuild.exe /property:Configuration=Release;OutputPath=.tmp /verbosity:minimal FlatBuffers.Test.csproj"
|
|
||||||
- ".tmp\\FlatBuffers.Test.exe"
|
|
||||||
# Run tests with UNSAFE_BYTEBUFFER
|
|
||||||
- "msbuild.exe /property:Configuration=Release;UnsafeByteBuffer=true;OutputPath=.tmp /verbosity:minimal FlatBuffers.Test.csproj"
|
|
||||||
- ".tmp\\FlatBuffers.Test.exe"
|
|
||||||
|
|
||||||
artifacts:
|
|
||||||
- path: $(CONFIGURATION)\flatc.exe
|
|
||||||
name: flatc.exe
|
|
||||||
- path: tests\GeneratedMyGameCode.zip
|
|
||||||
name: GeneratedMyGameCode.zip
|
|
||||||
87
benchmarks/CMakeLists.txt
Normal file
87
benchmarks/CMakeLists.txt
Normal file
@@ -0,0 +1,87 @@
|
|||||||
|
# Setup for running Google Benchmarks (https://github.com/google/benchmark) on
|
||||||
|
# flatbuffers. This requires both that benchmark library and its depenency gtest
|
||||||
|
# to build. Instead of including them here or doing a submodule, this uses
|
||||||
|
# FetchContent (https://cmake.org/cmake/help/latest/module/FetchContent.html) to
|
||||||
|
# grab the dependencies at config time. This requires CMake 3.14 or higher.
|
||||||
|
cmake_minimum_required(VERSION 3.14)
|
||||||
|
include(FetchContent)
|
||||||
|
|
||||||
|
# No particular reason for the specific GIT_TAGs for the following repos, they
|
||||||
|
# were just the latest releases when this was added.
|
||||||
|
FetchContent_Declare(
|
||||||
|
googletest
|
||||||
|
GIT_REPOSITORY https://github.com/google/googletest.git
|
||||||
|
GIT_TAG e2239ee6043f73722e7aa812a459f54a28552929 # release-1.11.0
|
||||||
|
)
|
||||||
|
FetchContent_Declare(
|
||||||
|
googlebenchmark
|
||||||
|
GIT_REPOSITORY https://github.com/google/benchmark.git
|
||||||
|
GIT_TAG 0d98dba29d66e93259db7daa53a9327df767a415 # v1.6.1
|
||||||
|
)
|
||||||
|
|
||||||
|
# For Windows: Prevent overriding the parent project's compiler/linker
|
||||||
|
# settings.
|
||||||
|
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
|
||||||
|
FetchContent_MakeAvailable(
|
||||||
|
googletest
|
||||||
|
googlebenchmark
|
||||||
|
)
|
||||||
|
|
||||||
|
set(CPP_BENCH_DIR cpp)
|
||||||
|
set(CPP_FB_BENCH_DIR ${CPP_BENCH_DIR}/flatbuffers)
|
||||||
|
set(CPP_RAW_BENCH_DIR ${CPP_BENCH_DIR}/raw)
|
||||||
|
set(CPP_BENCH_FBS ${CPP_FB_BENCH_DIR}/bench.fbs)
|
||||||
|
set(CPP_BENCH_FB_GEN ${CPP_FB_BENCH_DIR}/bench_generated.h)
|
||||||
|
|
||||||
|
set(FlatBenchmark_SRCS
|
||||||
|
${CPP_BENCH_DIR}/benchmark_main.cpp
|
||||||
|
${CPP_FB_BENCH_DIR}/fb_bench.cpp
|
||||||
|
${CPP_RAW_BENCH_DIR}/raw_bench.cpp
|
||||||
|
${CPP_BENCH_FB_GEN}
|
||||||
|
)
|
||||||
|
|
||||||
|
# Generate the flatbuffers benchmark code from the flatbuffers schema using
|
||||||
|
# flatc itself, thus it depends on flatc. This also depends on the C++ runtime
|
||||||
|
# flatbuffers and the schema file itself, so it should auto-generated at the
|
||||||
|
# correct times.
|
||||||
|
add_custom_command(
|
||||||
|
OUTPUT ${CPP_BENCH_FB_GEN}
|
||||||
|
COMMAND
|
||||||
|
"${FLATBUFFERS_FLATC_EXECUTABLE}"
|
||||||
|
--cpp
|
||||||
|
-o ${CPP_FB_BENCH_DIR}
|
||||||
|
${CPP_BENCH_FBS}
|
||||||
|
DEPENDS
|
||||||
|
flatc
|
||||||
|
flatbuffers
|
||||||
|
${CPP_BENCH_FBS}
|
||||||
|
COMMENT "Run Flatbuffers Benchmark Codegen: ${CPP_BENCH_FB_GEN}"
|
||||||
|
VERBATIM)
|
||||||
|
|
||||||
|
# The main flatbuffers benchmark executable
|
||||||
|
add_executable(flatbenchmark ${FlatBenchmark_SRCS})
|
||||||
|
|
||||||
|
# Benchmark requires C++11
|
||||||
|
target_compile_features(flatbenchmark PUBLIC
|
||||||
|
cxx_std_11
|
||||||
|
)
|
||||||
|
|
||||||
|
target_compile_options(flatbenchmark
|
||||||
|
PRIVATE
|
||||||
|
-fno-aligned-new
|
||||||
|
-Wno-deprecated-declarations
|
||||||
|
)
|
||||||
|
|
||||||
|
# Set the output directory to the root binary directory
|
||||||
|
set_target_properties(flatbenchmark
|
||||||
|
PROPERTIES RUNTIME_OUTPUT_DIRECTORY
|
||||||
|
"${CMAKE_BINARY_DIR}"
|
||||||
|
)
|
||||||
|
|
||||||
|
# The includes of the benchmark files are fully qualified from flatbuffers root.
|
||||||
|
target_include_directories(flatbenchmark PUBLIC ${CMAKE_SOURCE_DIR})
|
||||||
|
|
||||||
|
target_link_libraries(flatbenchmark
|
||||||
|
benchmark::benchmark_main # _main to use their entry point
|
||||||
|
gtest # Link to gtest so we can also assert in the benchmarks
|
||||||
|
)
|
||||||
19
benchmarks/cpp/bench.h
Normal file
19
benchmarks/cpp/bench.h
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
#ifndef BENCHMARKS_CPP_BENCH_H_
|
||||||
|
#define BENCHMARKS_CPP_BENCH_H_
|
||||||
|
|
||||||
|
#include <cstdint>
|
||||||
|
|
||||||
|
struct Bench {
|
||||||
|
virtual ~Bench() {}
|
||||||
|
|
||||||
|
inline void Add(int64_t value) { sum += value; }
|
||||||
|
|
||||||
|
virtual uint8_t *Encode(void *buf, int64_t &len) = 0;
|
||||||
|
virtual void *Decode(void *buf, int64_t len) = 0;
|
||||||
|
virtual int64_t Use(void *decoded) = 0;
|
||||||
|
virtual void Dealloc(void *decoded) = 0;
|
||||||
|
|
||||||
|
int64_t sum = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // BENCHMARKS_CPP_BENCH_H_
|
||||||
96
benchmarks/cpp/benchmark_main.cpp
Normal file
96
benchmarks/cpp/benchmark_main.cpp
Normal file
@@ -0,0 +1,96 @@
|
|||||||
|
#include <benchmark/benchmark.h>
|
||||||
|
#include <gtest/gtest.h>
|
||||||
|
|
||||||
|
#include "benchmarks/cpp/bench.h"
|
||||||
|
#include "benchmarks/cpp/flatbuffers/fb_bench.h"
|
||||||
|
#include "benchmarks/cpp/raw/raw_bench.h"
|
||||||
|
|
||||||
|
static inline void Encode(benchmark::State &state,
|
||||||
|
std::unique_ptr<Bench> &bench, uint8_t *buffer) {
|
||||||
|
int64_t length;
|
||||||
|
for (auto _ : state) {
|
||||||
|
bench->Encode(buffer, length);
|
||||||
|
benchmark::DoNotOptimize(length);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline void Decode(benchmark::State &state,
|
||||||
|
std::unique_ptr<Bench> &bench, uint8_t *buffer) {
|
||||||
|
int64_t length;
|
||||||
|
uint8_t *encoded = bench->Encode(buffer, length);
|
||||||
|
|
||||||
|
for (auto _ : state) {
|
||||||
|
void *decoded = bench->Decode(encoded, length);
|
||||||
|
benchmark::DoNotOptimize(decoded);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline void Use(benchmark::State &state, std::unique_ptr<Bench> &bench,
|
||||||
|
uint8_t *buffer, int64_t check_sum) {
|
||||||
|
int64_t length;
|
||||||
|
uint8_t *encoded = bench->Encode(buffer, length);
|
||||||
|
void *decoded = bench->Decode(encoded, length);
|
||||||
|
|
||||||
|
int64_t sum = 0;
|
||||||
|
|
||||||
|
for (auto _ : state) { sum = bench->Use(decoded); }
|
||||||
|
|
||||||
|
EXPECT_EQ(sum, check_sum);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void BM_Flatbuffers_Encode(benchmark::State &state) {
|
||||||
|
const int64_t kBufferLength = 1024;
|
||||||
|
uint8_t buffer[kBufferLength];
|
||||||
|
|
||||||
|
StaticAllocator allocator(&buffer[0]);
|
||||||
|
std::unique_ptr<Bench> bench = NewFlatBuffersBench(kBufferLength, &allocator);
|
||||||
|
Encode(state, bench, buffer);
|
||||||
|
}
|
||||||
|
BENCHMARK(BM_Flatbuffers_Encode);
|
||||||
|
|
||||||
|
static void BM_Flatbuffers_Decode(benchmark::State &state) {
|
||||||
|
const int64_t kBufferLength = 1024;
|
||||||
|
uint8_t buffer[kBufferLength];
|
||||||
|
|
||||||
|
StaticAllocator allocator(&buffer[0]);
|
||||||
|
std::unique_ptr<Bench> bench = NewFlatBuffersBench(kBufferLength, &allocator);
|
||||||
|
Decode(state, bench, buffer);
|
||||||
|
}
|
||||||
|
BENCHMARK(BM_Flatbuffers_Decode);
|
||||||
|
|
||||||
|
static void BM_Flatbuffers_Use(benchmark::State &state) {
|
||||||
|
const int64_t kBufferLength = 1024;
|
||||||
|
uint8_t buffer[kBufferLength];
|
||||||
|
|
||||||
|
StaticAllocator allocator(&buffer[0]);
|
||||||
|
std::unique_ptr<Bench> bench = NewFlatBuffersBench(kBufferLength, &allocator);
|
||||||
|
Use(state, bench, buffer, 218812692406581874);
|
||||||
|
}
|
||||||
|
BENCHMARK(BM_Flatbuffers_Use);
|
||||||
|
|
||||||
|
static void BM_Raw_Encode(benchmark::State &state) {
|
||||||
|
const int64_t kBufferLength = 1024;
|
||||||
|
uint8_t buffer[kBufferLength];
|
||||||
|
|
||||||
|
std::unique_ptr<Bench> bench = NewRawBench();
|
||||||
|
Encode(state, bench, buffer);
|
||||||
|
}
|
||||||
|
BENCHMARK(BM_Raw_Encode);
|
||||||
|
|
||||||
|
static void BM_Raw_Decode(benchmark::State &state) {
|
||||||
|
const int64_t kBufferLength = 1024;
|
||||||
|
uint8_t buffer[kBufferLength];
|
||||||
|
|
||||||
|
std::unique_ptr<Bench> bench = NewRawBench();
|
||||||
|
Decode(state, bench, buffer);
|
||||||
|
}
|
||||||
|
BENCHMARK(BM_Raw_Decode);
|
||||||
|
|
||||||
|
static void BM_Raw_Use(benchmark::State &state) {
|
||||||
|
const int64_t kBufferLength = 1024;
|
||||||
|
uint8_t buffer[kBufferLength];
|
||||||
|
|
||||||
|
std::unique_ptr<Bench> bench = NewRawBench();
|
||||||
|
Use(state, bench, buffer, 218812692406581874);
|
||||||
|
}
|
||||||
|
BENCHMARK(BM_Raw_Use);
|
||||||
52
benchmarks/cpp/flatbuffers/bench.fbs
Normal file
52
benchmarks/cpp/flatbuffers/bench.fbs
Normal file
@@ -0,0 +1,52 @@
|
|||||||
|
// Copyright 2021 Google Inc. All rights reserved.
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
|
||||||
|
|
||||||
|
// trying to represent a typical mix of datatypes:
|
||||||
|
// 1 array of 3 elements, each element: 1 string, 3 nested objects, 9 scalars
|
||||||
|
// root element has the array, additional string and an enum
|
||||||
|
|
||||||
|
namespace benchmarks_flatbuffers;
|
||||||
|
|
||||||
|
enum Enum : short { Apples, Pears, Bananas}
|
||||||
|
|
||||||
|
struct Foo {
|
||||||
|
id:ulong;
|
||||||
|
count:short;
|
||||||
|
prefix:byte;
|
||||||
|
length:uint;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct Bar {
|
||||||
|
parent:Foo;
|
||||||
|
time:int;
|
||||||
|
ratio:float;
|
||||||
|
size:ushort;
|
||||||
|
}
|
||||||
|
|
||||||
|
table FooBar {
|
||||||
|
sibling:Bar;
|
||||||
|
name:string;
|
||||||
|
rating:double;
|
||||||
|
postfix:ubyte;
|
||||||
|
}
|
||||||
|
|
||||||
|
table FooBarContainer {
|
||||||
|
list:[FooBar]; // 3 copies of the above
|
||||||
|
initialized:bool;
|
||||||
|
fruit:Enum;
|
||||||
|
location:string;
|
||||||
|
}
|
||||||
|
|
||||||
|
root_type FooBarContainer;
|
||||||
354
benchmarks/cpp/flatbuffers/bench_generated.h
Normal file
354
benchmarks/cpp/flatbuffers/bench_generated.h
Normal file
@@ -0,0 +1,354 @@
|
|||||||
|
// automatically generated by the FlatBuffers compiler, do not modify
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef FLATBUFFERS_GENERATED_BENCH_BENCHMARKS_FLATBUFFERS_H_
|
||||||
|
#define FLATBUFFERS_GENERATED_BENCH_BENCHMARKS_FLATBUFFERS_H_
|
||||||
|
|
||||||
|
#include "flatbuffers/flatbuffers.h"
|
||||||
|
|
||||||
|
// Ensure the included flatbuffers.h is the same version as when this file was
|
||||||
|
// generated, otherwise it may not be compatible.
|
||||||
|
static_assert(FLATBUFFERS_VERSION_MAJOR == 2 &&
|
||||||
|
FLATBUFFERS_VERSION_MINOR == 0 &&
|
||||||
|
FLATBUFFERS_VERSION_REVISION == 6,
|
||||||
|
"Non-compatible flatbuffers version included");
|
||||||
|
|
||||||
|
namespace benchmarks_flatbuffers {
|
||||||
|
|
||||||
|
struct Foo;
|
||||||
|
|
||||||
|
struct Bar;
|
||||||
|
|
||||||
|
struct FooBar;
|
||||||
|
struct FooBarBuilder;
|
||||||
|
|
||||||
|
struct FooBarContainer;
|
||||||
|
struct FooBarContainerBuilder;
|
||||||
|
|
||||||
|
enum Enum : int16_t {
|
||||||
|
Enum_Apples = 0,
|
||||||
|
Enum_Pears = 1,
|
||||||
|
Enum_Bananas = 2,
|
||||||
|
Enum_MIN = Enum_Apples,
|
||||||
|
Enum_MAX = Enum_Bananas
|
||||||
|
};
|
||||||
|
|
||||||
|
inline const Enum (&EnumValuesEnum())[3] {
|
||||||
|
static const Enum values[] = {
|
||||||
|
Enum_Apples,
|
||||||
|
Enum_Pears,
|
||||||
|
Enum_Bananas
|
||||||
|
};
|
||||||
|
return values;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline const char * const *EnumNamesEnum() {
|
||||||
|
static const char * const names[4] = {
|
||||||
|
"Apples",
|
||||||
|
"Pears",
|
||||||
|
"Bananas",
|
||||||
|
nullptr
|
||||||
|
};
|
||||||
|
return names;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline const char *EnumNameEnum(Enum e) {
|
||||||
|
if (flatbuffers::IsOutRange(e, Enum_Apples, Enum_Bananas)) return "";
|
||||||
|
const size_t index = static_cast<size_t>(e);
|
||||||
|
return EnumNamesEnum()[index];
|
||||||
|
}
|
||||||
|
|
||||||
|
FLATBUFFERS_MANUALLY_ALIGNED_STRUCT(8) Foo FLATBUFFERS_FINAL_CLASS {
|
||||||
|
private:
|
||||||
|
uint64_t id_;
|
||||||
|
int16_t count_;
|
||||||
|
int8_t prefix_;
|
||||||
|
int8_t padding0__;
|
||||||
|
uint32_t length_;
|
||||||
|
|
||||||
|
public:
|
||||||
|
Foo()
|
||||||
|
: id_(0),
|
||||||
|
count_(0),
|
||||||
|
prefix_(0),
|
||||||
|
padding0__(0),
|
||||||
|
length_(0) {
|
||||||
|
(void)padding0__;
|
||||||
|
}
|
||||||
|
Foo(uint64_t _id, int16_t _count, int8_t _prefix, uint32_t _length)
|
||||||
|
: id_(flatbuffers::EndianScalar(_id)),
|
||||||
|
count_(flatbuffers::EndianScalar(_count)),
|
||||||
|
prefix_(flatbuffers::EndianScalar(_prefix)),
|
||||||
|
padding0__(0),
|
||||||
|
length_(flatbuffers::EndianScalar(_length)) {
|
||||||
|
(void)padding0__;
|
||||||
|
}
|
||||||
|
uint64_t id() const {
|
||||||
|
return flatbuffers::EndianScalar(id_);
|
||||||
|
}
|
||||||
|
int16_t count() const {
|
||||||
|
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_MANUALLY_ALIGNED_STRUCT(8) Bar FLATBUFFERS_FINAL_CLASS {
|
||||||
|
private:
|
||||||
|
benchmarks_flatbuffers::Foo parent_;
|
||||||
|
int32_t time_;
|
||||||
|
float ratio_;
|
||||||
|
uint16_t size_;
|
||||||
|
int16_t padding0__; int32_t padding1__;
|
||||||
|
|
||||||
|
public:
|
||||||
|
Bar()
|
||||||
|
: parent_(),
|
||||||
|
time_(0),
|
||||||
|
ratio_(0),
|
||||||
|
size_(0),
|
||||||
|
padding0__(0),
|
||||||
|
padding1__(0) {
|
||||||
|
(void)padding0__;
|
||||||
|
(void)padding1__;
|
||||||
|
}
|
||||||
|
Bar(const benchmarks_flatbuffers::Foo &_parent, int32_t _time, float _ratio, uint16_t _size)
|
||||||
|
: parent_(_parent),
|
||||||
|
time_(flatbuffers::EndianScalar(_time)),
|
||||||
|
ratio_(flatbuffers::EndianScalar(_ratio)),
|
||||||
|
size_(flatbuffers::EndianScalar(_size)),
|
||||||
|
padding0__(0),
|
||||||
|
padding1__(0) {
|
||||||
|
(void)padding0__;
|
||||||
|
(void)padding1__;
|
||||||
|
}
|
||||||
|
const benchmarks_flatbuffers::Foo &parent() const {
|
||||||
|
return parent_;
|
||||||
|
}
|
||||||
|
int32_t time() const {
|
||||||
|
return flatbuffers::EndianScalar(time_);
|
||||||
|
}
|
||||||
|
float ratio() const {
|
||||||
|
return flatbuffers::EndianScalar(ratio_);
|
||||||
|
}
|
||||||
|
uint16_t size() const {
|
||||||
|
return flatbuffers::EndianScalar(size_);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
FLATBUFFERS_STRUCT_END(Bar, 32);
|
||||||
|
|
||||||
|
struct FooBar FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table {
|
||||||
|
typedef FooBarBuilder Builder;
|
||||||
|
enum FlatBuffersVTableOffset FLATBUFFERS_VTABLE_UNDERLYING_TYPE {
|
||||||
|
VT_SIBLING = 4,
|
||||||
|
VT_NAME = 6,
|
||||||
|
VT_RATING = 8,
|
||||||
|
VT_POSTFIX = 10
|
||||||
|
};
|
||||||
|
const benchmarks_flatbuffers::Bar *sibling() const {
|
||||||
|
return GetStruct<const benchmarks_flatbuffers::Bar *>(VT_SIBLING);
|
||||||
|
}
|
||||||
|
const flatbuffers::String *name() const {
|
||||||
|
return GetPointer<const flatbuffers::String *>(VT_NAME);
|
||||||
|
}
|
||||||
|
double rating() const {
|
||||||
|
return GetField<double>(VT_RATING, 0.0);
|
||||||
|
}
|
||||||
|
uint8_t postfix() const {
|
||||||
|
return GetField<uint8_t>(VT_POSTFIX, 0);
|
||||||
|
}
|
||||||
|
bool Verify(flatbuffers::Verifier &verifier) const {
|
||||||
|
return VerifyTableStart(verifier) &&
|
||||||
|
VerifyField<benchmarks_flatbuffers::Bar>(verifier, VT_SIBLING, 8) &&
|
||||||
|
VerifyOffset(verifier, VT_NAME) &&
|
||||||
|
verifier.VerifyString(name()) &&
|
||||||
|
VerifyField<double>(verifier, VT_RATING, 8) &&
|
||||||
|
VerifyField<uint8_t>(verifier, VT_POSTFIX, 1) &&
|
||||||
|
verifier.EndTable();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
struct FooBarBuilder {
|
||||||
|
typedef FooBar Table;
|
||||||
|
flatbuffers::FlatBufferBuilder &fbb_;
|
||||||
|
flatbuffers::uoffset_t start_;
|
||||||
|
void add_sibling(const benchmarks_flatbuffers::Bar *sibling) {
|
||||||
|
fbb_.AddStruct(FooBar::VT_SIBLING, sibling);
|
||||||
|
}
|
||||||
|
void add_name(flatbuffers::Offset<flatbuffers::String> name) {
|
||||||
|
fbb_.AddOffset(FooBar::VT_NAME, name);
|
||||||
|
}
|
||||||
|
void add_rating(double rating) {
|
||||||
|
fbb_.AddElement<double>(FooBar::VT_RATING, rating, 0.0);
|
||||||
|
}
|
||||||
|
void add_postfix(uint8_t postfix) {
|
||||||
|
fbb_.AddElement<uint8_t>(FooBar::VT_POSTFIX, postfix, 0);
|
||||||
|
}
|
||||||
|
explicit FooBarBuilder(flatbuffers::FlatBufferBuilder &_fbb)
|
||||||
|
: fbb_(_fbb) {
|
||||||
|
start_ = fbb_.StartTable();
|
||||||
|
}
|
||||||
|
flatbuffers::Offset<FooBar> Finish() {
|
||||||
|
const auto end = fbb_.EndTable(start_);
|
||||||
|
auto o = flatbuffers::Offset<FooBar>(end);
|
||||||
|
return o;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
inline flatbuffers::Offset<FooBar> CreateFooBar(
|
||||||
|
flatbuffers::FlatBufferBuilder &_fbb,
|
||||||
|
const benchmarks_flatbuffers::Bar *sibling = nullptr,
|
||||||
|
flatbuffers::Offset<flatbuffers::String> name = 0,
|
||||||
|
double rating = 0.0,
|
||||||
|
uint8_t postfix = 0) {
|
||||||
|
FooBarBuilder builder_(_fbb);
|
||||||
|
builder_.add_rating(rating);
|
||||||
|
builder_.add_name(name);
|
||||||
|
builder_.add_sibling(sibling);
|
||||||
|
builder_.add_postfix(postfix);
|
||||||
|
return builder_.Finish();
|
||||||
|
}
|
||||||
|
|
||||||
|
inline flatbuffers::Offset<FooBar> CreateFooBarDirect(
|
||||||
|
flatbuffers::FlatBufferBuilder &_fbb,
|
||||||
|
const benchmarks_flatbuffers::Bar *sibling = nullptr,
|
||||||
|
const char *name = nullptr,
|
||||||
|
double rating = 0.0,
|
||||||
|
uint8_t postfix = 0) {
|
||||||
|
auto name__ = name ? _fbb.CreateString(name) : 0;
|
||||||
|
return benchmarks_flatbuffers::CreateFooBar(
|
||||||
|
_fbb,
|
||||||
|
sibling,
|
||||||
|
name__,
|
||||||
|
rating,
|
||||||
|
postfix);
|
||||||
|
}
|
||||||
|
|
||||||
|
struct FooBarContainer FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table {
|
||||||
|
typedef FooBarContainerBuilder Builder;
|
||||||
|
enum FlatBuffersVTableOffset FLATBUFFERS_VTABLE_UNDERLYING_TYPE {
|
||||||
|
VT_LIST = 4,
|
||||||
|
VT_INITIALIZED = 6,
|
||||||
|
VT_FRUIT = 8,
|
||||||
|
VT_LOCATION = 10
|
||||||
|
};
|
||||||
|
const flatbuffers::Vector<flatbuffers::Offset<benchmarks_flatbuffers::FooBar>> *list() const {
|
||||||
|
return GetPointer<const flatbuffers::Vector<flatbuffers::Offset<benchmarks_flatbuffers::FooBar>> *>(VT_LIST);
|
||||||
|
}
|
||||||
|
bool initialized() const {
|
||||||
|
return GetField<uint8_t>(VT_INITIALIZED, 0) != 0;
|
||||||
|
}
|
||||||
|
benchmarks_flatbuffers::Enum fruit() const {
|
||||||
|
return static_cast<benchmarks_flatbuffers::Enum>(GetField<int16_t>(VT_FRUIT, 0));
|
||||||
|
}
|
||||||
|
const flatbuffers::String *location() const {
|
||||||
|
return GetPointer<const flatbuffers::String *>(VT_LOCATION);
|
||||||
|
}
|
||||||
|
bool Verify(flatbuffers::Verifier &verifier) const {
|
||||||
|
return VerifyTableStart(verifier) &&
|
||||||
|
VerifyOffset(verifier, VT_LIST) &&
|
||||||
|
verifier.VerifyVector(list()) &&
|
||||||
|
verifier.VerifyVectorOfTables(list()) &&
|
||||||
|
VerifyField<uint8_t>(verifier, VT_INITIALIZED, 1) &&
|
||||||
|
VerifyField<int16_t>(verifier, VT_FRUIT, 2) &&
|
||||||
|
VerifyOffset(verifier, VT_LOCATION) &&
|
||||||
|
verifier.VerifyString(location()) &&
|
||||||
|
verifier.EndTable();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
struct FooBarContainerBuilder {
|
||||||
|
typedef FooBarContainer Table;
|
||||||
|
flatbuffers::FlatBufferBuilder &fbb_;
|
||||||
|
flatbuffers::uoffset_t start_;
|
||||||
|
void add_list(flatbuffers::Offset<flatbuffers::Vector<flatbuffers::Offset<benchmarks_flatbuffers::FooBar>>> list) {
|
||||||
|
fbb_.AddOffset(FooBarContainer::VT_LIST, list);
|
||||||
|
}
|
||||||
|
void add_initialized(bool initialized) {
|
||||||
|
fbb_.AddElement<uint8_t>(FooBarContainer::VT_INITIALIZED, static_cast<uint8_t>(initialized), 0);
|
||||||
|
}
|
||||||
|
void add_fruit(benchmarks_flatbuffers::Enum fruit) {
|
||||||
|
fbb_.AddElement<int16_t>(FooBarContainer::VT_FRUIT, static_cast<int16_t>(fruit), 0);
|
||||||
|
}
|
||||||
|
void add_location(flatbuffers::Offset<flatbuffers::String> location) {
|
||||||
|
fbb_.AddOffset(FooBarContainer::VT_LOCATION, location);
|
||||||
|
}
|
||||||
|
explicit FooBarContainerBuilder(flatbuffers::FlatBufferBuilder &_fbb)
|
||||||
|
: fbb_(_fbb) {
|
||||||
|
start_ = fbb_.StartTable();
|
||||||
|
}
|
||||||
|
flatbuffers::Offset<FooBarContainer> Finish() {
|
||||||
|
const auto end = fbb_.EndTable(start_);
|
||||||
|
auto o = flatbuffers::Offset<FooBarContainer>(end);
|
||||||
|
return o;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
inline flatbuffers::Offset<FooBarContainer> CreateFooBarContainer(
|
||||||
|
flatbuffers::FlatBufferBuilder &_fbb,
|
||||||
|
flatbuffers::Offset<flatbuffers::Vector<flatbuffers::Offset<benchmarks_flatbuffers::FooBar>>> list = 0,
|
||||||
|
bool initialized = false,
|
||||||
|
benchmarks_flatbuffers::Enum fruit = benchmarks_flatbuffers::Enum_Apples,
|
||||||
|
flatbuffers::Offset<flatbuffers::String> location = 0) {
|
||||||
|
FooBarContainerBuilder builder_(_fbb);
|
||||||
|
builder_.add_location(location);
|
||||||
|
builder_.add_list(list);
|
||||||
|
builder_.add_fruit(fruit);
|
||||||
|
builder_.add_initialized(initialized);
|
||||||
|
return builder_.Finish();
|
||||||
|
}
|
||||||
|
|
||||||
|
inline flatbuffers::Offset<FooBarContainer> CreateFooBarContainerDirect(
|
||||||
|
flatbuffers::FlatBufferBuilder &_fbb,
|
||||||
|
const std::vector<flatbuffers::Offset<benchmarks_flatbuffers::FooBar>> *list = nullptr,
|
||||||
|
bool initialized = false,
|
||||||
|
benchmarks_flatbuffers::Enum fruit = benchmarks_flatbuffers::Enum_Apples,
|
||||||
|
const char *location = nullptr) {
|
||||||
|
auto list__ = list ? _fbb.CreateVector<flatbuffers::Offset<benchmarks_flatbuffers::FooBar>>(*list) : 0;
|
||||||
|
auto location__ = location ? _fbb.CreateString(location) : 0;
|
||||||
|
return benchmarks_flatbuffers::CreateFooBarContainer(
|
||||||
|
_fbb,
|
||||||
|
list__,
|
||||||
|
initialized,
|
||||||
|
fruit,
|
||||||
|
location__);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline const benchmarks_flatbuffers::FooBarContainer *GetFooBarContainer(const void *buf) {
|
||||||
|
return flatbuffers::GetRoot<benchmarks_flatbuffers::FooBarContainer>(buf);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline const benchmarks_flatbuffers::FooBarContainer *GetSizePrefixedFooBarContainer(const void *buf) {
|
||||||
|
return flatbuffers::GetSizePrefixedRoot<benchmarks_flatbuffers::FooBarContainer>(buf);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline bool VerifyFooBarContainerBuffer(
|
||||||
|
flatbuffers::Verifier &verifier) {
|
||||||
|
return verifier.VerifyBuffer<benchmarks_flatbuffers::FooBarContainer>(nullptr);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline bool VerifySizePrefixedFooBarContainerBuffer(
|
||||||
|
flatbuffers::Verifier &verifier) {
|
||||||
|
return verifier.VerifySizePrefixedBuffer<benchmarks_flatbuffers::FooBarContainer>(nullptr);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void FinishFooBarContainerBuffer(
|
||||||
|
flatbuffers::FlatBufferBuilder &fbb,
|
||||||
|
flatbuffers::Offset<benchmarks_flatbuffers::FooBarContainer> root) {
|
||||||
|
fbb.Finish(root);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void FinishSizePrefixedFooBarContainerBuffer(
|
||||||
|
flatbuffers::FlatBufferBuilder &fbb,
|
||||||
|
flatbuffers::Offset<benchmarks_flatbuffers::FooBarContainer> root) {
|
||||||
|
fbb.FinishSizePrefixed(root);
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace benchmarks_flatbuffers
|
||||||
|
|
||||||
|
#endif // FLATBUFFERS_GENERATED_BENCH_BENCHMARKS_FLATBUFFERS_H_
|
||||||
80
benchmarks/cpp/flatbuffers/fb_bench.cpp
Normal file
80
benchmarks/cpp/flatbuffers/fb_bench.cpp
Normal file
@@ -0,0 +1,80 @@
|
|||||||
|
#include "benchmarks/cpp/flatbuffers/fb_bench.h"
|
||||||
|
|
||||||
|
#include <cstdint>
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
|
#include "benchmarks/cpp/bench.h"
|
||||||
|
#include "benchmarks/cpp/flatbuffers/bench_generated.h"
|
||||||
|
#include "flatbuffers/flatbuffers.h"
|
||||||
|
|
||||||
|
using namespace flatbuffers;
|
||||||
|
using namespace benchmarks_flatbuffers;
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
|
||||||
|
struct FlatBufferBench : Bench {
|
||||||
|
explicit FlatBufferBench(int64_t initial_size, Allocator *allocator)
|
||||||
|
: fbb(initial_size, allocator, false) {}
|
||||||
|
|
||||||
|
uint8_t *Encode(void *, int64_t &len) override {
|
||||||
|
fbb.Clear();
|
||||||
|
|
||||||
|
const int kVectorLength = 3;
|
||||||
|
Offset<FooBar> vec[kVectorLength];
|
||||||
|
|
||||||
|
for (int i = 0; i < kVectorLength; ++i) {
|
||||||
|
Foo foo(0xABADCAFEABADCAFE + i, 10000 + i, '@' + i, 1000000 + i);
|
||||||
|
Bar bar(foo, 123456 + i, 3.14159f + i, 10000 + i);
|
||||||
|
auto name = fbb.CreateString("Hello, World!");
|
||||||
|
auto foobar =
|
||||||
|
CreateFooBar(fbb, &bar, name, 3.1415432432445543543 + i, '!' + i);
|
||||||
|
vec[i] = foobar;
|
||||||
|
}
|
||||||
|
auto location = fbb.CreateString("http://google.com/flatbuffers/");
|
||||||
|
auto foobarvec = fbb.CreateVector(vec, kVectorLength);
|
||||||
|
auto foobarcontainer =
|
||||||
|
CreateFooBarContainer(fbb, foobarvec, true, Enum_Bananas, location);
|
||||||
|
fbb.Finish(foobarcontainer);
|
||||||
|
|
||||||
|
len = fbb.GetSize();
|
||||||
|
return fbb.GetBufferPointer();
|
||||||
|
}
|
||||||
|
|
||||||
|
int64_t Use(void *decoded) override {
|
||||||
|
sum = 0;
|
||||||
|
auto foobarcontainer = GetFooBarContainer(decoded);
|
||||||
|
sum = 0;
|
||||||
|
Add(foobarcontainer->initialized());
|
||||||
|
Add(foobarcontainer->location()->Length());
|
||||||
|
Add(foobarcontainer->fruit());
|
||||||
|
for (unsigned int i = 0; i < foobarcontainer->list()->Length(); i++) {
|
||||||
|
auto foobar = foobarcontainer->list()->Get(i);
|
||||||
|
Add(foobar->name()->Length());
|
||||||
|
Add(foobar->postfix());
|
||||||
|
Add(static_cast<int64_t>(foobar->rating()));
|
||||||
|
auto bar = foobar->sibling();
|
||||||
|
Add(static_cast<int64_t>(bar->ratio()));
|
||||||
|
Add(bar->size());
|
||||||
|
Add(bar->time());
|
||||||
|
auto &foo = bar->parent();
|
||||||
|
Add(foo.count());
|
||||||
|
Add(foo.id());
|
||||||
|
Add(foo.length());
|
||||||
|
Add(foo.prefix());
|
||||||
|
}
|
||||||
|
return sum;
|
||||||
|
}
|
||||||
|
|
||||||
|
void *Decode(void *buffer, int64_t) override { return buffer; }
|
||||||
|
void Dealloc(void *) override {};
|
||||||
|
|
||||||
|
FlatBufferBuilder fbb;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace
|
||||||
|
|
||||||
|
std::unique_ptr<Bench> NewFlatBuffersBench(int64_t initial_size,
|
||||||
|
Allocator *allocator) {
|
||||||
|
return std::unique_ptr<FlatBufferBench>(
|
||||||
|
new FlatBufferBench(initial_size, allocator));
|
||||||
|
}
|
||||||
23
benchmarks/cpp/flatbuffers/fb_bench.h
Normal file
23
benchmarks/cpp/flatbuffers/fb_bench.h
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
#ifndef BENCHMARKS_CPP_FLATBUFFERS_FB_BENCH_H_
|
||||||
|
#define BENCHMARKS_CPP_FLATBUFFERS_FB_BENCH_H_
|
||||||
|
|
||||||
|
#include <cstdint>
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
|
#include "benchmarks/cpp/bench.h"
|
||||||
|
#include "include/flatbuffers/flatbuffers.h"
|
||||||
|
|
||||||
|
struct StaticAllocator : public flatbuffers::Allocator {
|
||||||
|
explicit StaticAllocator(uint8_t *buffer) : buffer_(buffer) {}
|
||||||
|
|
||||||
|
uint8_t *allocate(size_t) override { return buffer_; }
|
||||||
|
|
||||||
|
void deallocate(uint8_t *, size_t) override {}
|
||||||
|
|
||||||
|
uint8_t *buffer_;
|
||||||
|
};
|
||||||
|
|
||||||
|
std::unique_ptr<Bench> NewFlatBuffersBench(
|
||||||
|
int64_t initial_size = 1024, flatbuffers::Allocator *allocator = nullptr);
|
||||||
|
|
||||||
|
#endif // BENCHMARKS_CPP_FLATBUFFERS_FB_BENCH_H_
|
||||||
109
benchmarks/cpp/raw/raw_bench.cpp
Normal file
109
benchmarks/cpp/raw/raw_bench.cpp
Normal file
@@ -0,0 +1,109 @@
|
|||||||
|
#include "benchmarks/cpp/raw/raw_bench.h"
|
||||||
|
|
||||||
|
#include <cstdint>
|
||||||
|
#include <cstring>
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
|
#include "benchmarks/cpp/bench.h"
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
const int64_t kStringLength = 32;
|
||||||
|
const int64_t kVectorLength = 3;
|
||||||
|
|
||||||
|
enum Enum { Apples, Pears, Bananas };
|
||||||
|
|
||||||
|
struct Foo {
|
||||||
|
int64_t id;
|
||||||
|
short count;
|
||||||
|
char prefix;
|
||||||
|
int length;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct Bar {
|
||||||
|
Foo parent;
|
||||||
|
int time;
|
||||||
|
float ratio;
|
||||||
|
unsigned short size;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct FooBar {
|
||||||
|
Bar sibling;
|
||||||
|
// We have to stick this in, otherwise strlen() will make it slower than
|
||||||
|
// FlatBuffers:
|
||||||
|
int name_len;
|
||||||
|
char name[kStringLength];
|
||||||
|
double rating;
|
||||||
|
unsigned char postfix;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct FooBarContainer {
|
||||||
|
FooBar list[kVectorLength]; // 3 copies of the above
|
||||||
|
bool initialized;
|
||||||
|
Enum fruit;
|
||||||
|
int location_len;
|
||||||
|
char location[kStringLength];
|
||||||
|
};
|
||||||
|
|
||||||
|
struct RawBench : Bench {
|
||||||
|
uint8_t *Encode(void *buf, int64_t &len) override {
|
||||||
|
FooBarContainer *fbc = new (buf) FooBarContainer;
|
||||||
|
strcpy(fbc->location, "http://google.com/flatbuffers/"); // Unsafe eek!
|
||||||
|
fbc->location_len = (int)strlen(fbc->location);
|
||||||
|
fbc->fruit = Bananas;
|
||||||
|
fbc->initialized = true;
|
||||||
|
for (int i = 0; i < kVectorLength; i++) {
|
||||||
|
// We add + i to not make these identical copies for a more realistic
|
||||||
|
// compression test.
|
||||||
|
auto &foobar = fbc->list[i];
|
||||||
|
foobar.rating = 3.1415432432445543543 + i;
|
||||||
|
foobar.postfix = '!' + i;
|
||||||
|
strcpy(foobar.name, "Hello, World!");
|
||||||
|
foobar.name_len = (int)strlen(foobar.name);
|
||||||
|
auto &bar = foobar.sibling;
|
||||||
|
bar.ratio = 3.14159f + i;
|
||||||
|
bar.size = 10000 + i;
|
||||||
|
bar.time = 123456 + i;
|
||||||
|
auto &foo = bar.parent;
|
||||||
|
foo.id = 0xABADCAFEABADCAFE + i;
|
||||||
|
foo.count = 10000 + i;
|
||||||
|
foo.length = 1000000 + i;
|
||||||
|
foo.prefix = '@' + i;
|
||||||
|
}
|
||||||
|
|
||||||
|
len = sizeof(FooBarContainer);
|
||||||
|
return reinterpret_cast<uint8_t *>(fbc);
|
||||||
|
};
|
||||||
|
|
||||||
|
int64_t Use(void *decoded) override {
|
||||||
|
auto foobarcontainer = reinterpret_cast<FooBarContainer *>(decoded);
|
||||||
|
sum = 0;
|
||||||
|
Add(foobarcontainer->initialized);
|
||||||
|
Add(foobarcontainer->location_len);
|
||||||
|
Add(foobarcontainer->fruit);
|
||||||
|
for (unsigned int i = 0; i < kVectorLength; i++) {
|
||||||
|
auto foobar = &foobarcontainer->list[i];
|
||||||
|
Add(foobar->name_len);
|
||||||
|
Add(foobar->postfix);
|
||||||
|
Add(static_cast<int64_t>(foobar->rating));
|
||||||
|
auto bar = &foobar->sibling;
|
||||||
|
Add(static_cast<int64_t>(bar->ratio));
|
||||||
|
Add(bar->size);
|
||||||
|
Add(bar->time);
|
||||||
|
auto &foo = bar->parent;
|
||||||
|
Add(foo.count);
|
||||||
|
Add(foo.id);
|
||||||
|
Add(foo.length);
|
||||||
|
Add(foo.prefix);
|
||||||
|
}
|
||||||
|
return sum;
|
||||||
|
}
|
||||||
|
|
||||||
|
void *Decode(void *buf, int64_t) override { return buf; }
|
||||||
|
void Dealloc(void *) override{};
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace
|
||||||
|
|
||||||
|
std::unique_ptr<Bench> NewRawBench() {
|
||||||
|
return std::unique_ptr<RawBench>(new RawBench());
|
||||||
|
}
|
||||||
10
benchmarks/cpp/raw/raw_bench.h
Normal file
10
benchmarks/cpp/raw/raw_bench.h
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
#ifndef BENCHMARKS_CPP_RAW_RAW_BENCH_H_
|
||||||
|
#define BENCHMARKS_CPP_RAW_RAW_BENCH_H_
|
||||||
|
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
|
#include "benchmarks/cpp/bench.h"
|
||||||
|
|
||||||
|
std::unique_ptr<Bench> NewRawBench();
|
||||||
|
|
||||||
|
#endif // BENCHMARKS_CPP_RAW_RAW_BENCH_H_
|
||||||
@@ -13,6 +13,7 @@ DEFAULT_INCLUDE_PATHS = [
|
|||||||
"./",
|
"./",
|
||||||
"$(GENDIR)",
|
"$(GENDIR)",
|
||||||
"$(BINDIR)",
|
"$(BINDIR)",
|
||||||
|
"$(execpath @com_github_google_flatbuffers//:flatc).runfiles/com_github_google_flatbuffers",
|
||||||
]
|
]
|
||||||
|
|
||||||
DEFAULT_FLATC_ARGS = [
|
DEFAULT_FLATC_ARGS = [
|
||||||
@@ -37,6 +38,7 @@ def flatbuffer_library_public(
|
|||||||
reflection_visibility = None,
|
reflection_visibility = None,
|
||||||
compatible_with = None,
|
compatible_with = None,
|
||||||
restricted_to = None,
|
restricted_to = None,
|
||||||
|
target_compatible_with = None,
|
||||||
output_to_bindir = False):
|
output_to_bindir = False):
|
||||||
"""Generates code files for reading/writing the given flatbuffers in the requested language using the public compiler.
|
"""Generates code files for reading/writing the given flatbuffers in the requested language using the public compiler.
|
||||||
|
|
||||||
@@ -58,6 +60,8 @@ def flatbuffer_library_public(
|
|||||||
built for, in addition to default-supported environments.
|
built for, in addition to default-supported environments.
|
||||||
restricted_to: Optional, The list of environments this rule can be built
|
restricted_to: Optional, The list of environments this rule can be built
|
||||||
for, instead of default-supported environments.
|
for, instead of default-supported environments.
|
||||||
|
target_compatible_with: Optional, The list of target platform constraints
|
||||||
|
to use.
|
||||||
output_to_bindir: Passed to genrule for output to bin directory.
|
output_to_bindir: Passed to genrule for output to bin directory.
|
||||||
|
|
||||||
|
|
||||||
@@ -92,6 +96,7 @@ def flatbuffer_library_public(
|
|||||||
tools = [flatc_path],
|
tools = [flatc_path],
|
||||||
cmd = genrule_cmd,
|
cmd = genrule_cmd,
|
||||||
compatible_with = compatible_with,
|
compatible_with = compatible_with,
|
||||||
|
target_compatible_with = target_compatible_with,
|
||||||
restricted_to = restricted_to,
|
restricted_to = restricted_to,
|
||||||
message = "Generating flatbuffer files for %s:" % (name),
|
message = "Generating flatbuffer files for %s:" % (name),
|
||||||
)
|
)
|
||||||
@@ -120,8 +125,10 @@ def flatbuffer_library_public(
|
|||||||
tools = [flatc_path],
|
tools = [flatc_path],
|
||||||
compatible_with = compatible_with,
|
compatible_with = compatible_with,
|
||||||
restricted_to = restricted_to,
|
restricted_to = restricted_to,
|
||||||
|
target_compatible_with = target_compatible_with,
|
||||||
cmd = reflection_genrule_cmd,
|
cmd = reflection_genrule_cmd,
|
||||||
message = "Generating flatbuffer reflection binary for %s:" % (name),
|
message = "Generating flatbuffer reflection binary for %s:" % (name),
|
||||||
|
visibility = reflection_visibility,
|
||||||
)
|
)
|
||||||
native.filegroup(
|
native.filegroup(
|
||||||
name = "%s_out" % reflection_name,
|
name = "%s_out" % reflection_name,
|
||||||
@@ -136,15 +143,18 @@ def flatbuffer_cc_library(
|
|||||||
srcs,
|
srcs,
|
||||||
srcs_filegroup_name = "",
|
srcs_filegroup_name = "",
|
||||||
out_prefix = "",
|
out_prefix = "",
|
||||||
|
deps = [],
|
||||||
includes = [],
|
includes = [],
|
||||||
include_paths = DEFAULT_INCLUDE_PATHS,
|
include_paths = DEFAULT_INCLUDE_PATHS,
|
||||||
|
cc_include_paths = [],
|
||||||
flatc_args = DEFAULT_FLATC_ARGS,
|
flatc_args = DEFAULT_FLATC_ARGS,
|
||||||
visibility = None,
|
visibility = None,
|
||||||
compatible_with = None,
|
compatible_with = None,
|
||||||
restricted_to = None,
|
restricted_to = None,
|
||||||
|
target_compatible_with = None,
|
||||||
srcs_filegroup_visibility = None,
|
srcs_filegroup_visibility = None,
|
||||||
gen_reflections = False):
|
gen_reflections = False):
|
||||||
'''A cc_library with the generated reader/writers for the given flatbuffer definitions.
|
"""A cc_library with the generated reader/writers for the given flatbuffer definitions.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
name: Rule name.
|
name: Rule name.
|
||||||
@@ -154,9 +164,12 @@ def flatbuffer_cc_library(
|
|||||||
flatbuffer_cc_library that depends on this one's schemas.
|
flatbuffer_cc_library that depends on this one's schemas.
|
||||||
out_prefix: Prepend this path to the front of all generated files. Usually
|
out_prefix: Prepend this path to the front of all generated files. Usually
|
||||||
is a directory name.
|
is a directory name.
|
||||||
|
deps: Optional, list of other flatbuffer_cc_library's to depend on. Cannot be specified
|
||||||
|
alongside includes.
|
||||||
includes: Optional, list of filegroups of schemas that the srcs depend on.
|
includes: Optional, list of filegroups of schemas that the srcs depend on.
|
||||||
** SEE REMARKS BELOW **
|
Use of this is discouraged, and may be deprecated.
|
||||||
include_paths: Optional, list of paths the includes files can be found in.
|
include_paths: Optional, list of paths the includes files can be found in.
|
||||||
|
cc_include_paths: Optional, list of paths to add to the cc_library includes attribute.
|
||||||
flatc_args: Optional list of additional arguments to pass to flatc
|
flatc_args: Optional list of additional arguments to pass to flatc
|
||||||
(e.g. --gen-mutable).
|
(e.g. --gen-mutable).
|
||||||
visibility: The visibility of the generated cc_library. By default, use the
|
visibility: The visibility of the generated cc_library. By default, use the
|
||||||
@@ -169,6 +182,8 @@ def flatbuffer_cc_library(
|
|||||||
for, in addition to default-supported environments.
|
for, in addition to default-supported environments.
|
||||||
restricted_to: Optional, The list of environments this rule can be built
|
restricted_to: Optional, The list of environments this rule can be built
|
||||||
for, instead of default-supported environments.
|
for, instead of default-supported environments.
|
||||||
|
target_compatible_with: Optional, The list of target platform constraints
|
||||||
|
to use.
|
||||||
|
|
||||||
This produces:
|
This produces:
|
||||||
filegroup([name]_srcs): all generated .h files.
|
filegroup([name]_srcs): all generated .h files.
|
||||||
@@ -177,41 +192,17 @@ def flatbuffer_cc_library(
|
|||||||
parameter, if they depend on the schemas in this library.
|
parameter, if they depend on the schemas in this 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.
|
||||||
|
"""
|
||||||
Remarks:
|
|
||||||
** Because the genrule used to call flatc does not have any trivial way of
|
|
||||||
computing the output list of files transitively generated by includes and
|
|
||||||
--gen-includes (the default) being defined for flatc, the --gen-includes
|
|
||||||
flag will not work as expected. The way around this is to add a dependency
|
|
||||||
to the flatbuffer_cc_library defined alongside the flatc included Fileset.
|
|
||||||
For example you might define:
|
|
||||||
|
|
||||||
flatbuffer_cc_library(
|
|
||||||
name = "my_fbs",
|
|
||||||
srcs = [ "schemas/foo.fbs" ],
|
|
||||||
includes = [ "//third_party/bazz:bazz_fbs_includes" ],
|
|
||||||
)
|
|
||||||
|
|
||||||
In which foo.fbs includes a few files from the Fileset defined at
|
|
||||||
//third_party/bazz:bazz_fbs_includes. When compiling the library that
|
|
||||||
includes foo_generated.h, and therefore has my_fbs as a dependency, it
|
|
||||||
will fail to find any of the bazz *_generated.h files unless you also
|
|
||||||
add bazz's flatbuffer_cc_library to your own dependency list, e.g.:
|
|
||||||
|
|
||||||
cc_library(
|
|
||||||
name = "my_lib",
|
|
||||||
deps = [
|
|
||||||
":my_fbs",
|
|
||||||
"//third_party/bazz:bazz_fbs"
|
|
||||||
],
|
|
||||||
)
|
|
||||||
|
|
||||||
Happy dependent Flatbuffering!
|
|
||||||
'''
|
|
||||||
output_headers = [
|
output_headers = [
|
||||||
(out_prefix + "%s_generated.h") % (s.replace(".fbs", "").split("/")[-1])
|
(out_prefix + "%s_generated.h") % (s.replace(".fbs", "").split("/")[-1].split(":")[-1])
|
||||||
for s in srcs
|
for s in srcs
|
||||||
]
|
]
|
||||||
|
if deps and includes:
|
||||||
|
# There is no inherent reason we couldn't support both, but this discourages
|
||||||
|
# use of includes without good reason.
|
||||||
|
fail("Cannot specify both deps and include in flatbuffer_cc_library.")
|
||||||
|
if deps:
|
||||||
|
includes = [d + "_includes" for d in deps]
|
||||||
reflection_name = "%s_reflection" % name if gen_reflections else ""
|
reflection_name = "%s_reflection" % name if gen_reflections else ""
|
||||||
|
|
||||||
srcs_lib = "%s_srcs" % (name)
|
srcs_lib = "%s_srcs" % (name)
|
||||||
@@ -226,6 +217,7 @@ def flatbuffer_cc_library(
|
|||||||
flatc_args = flatc_args,
|
flatc_args = flatc_args,
|
||||||
compatible_with = compatible_with,
|
compatible_with = compatible_with,
|
||||||
restricted_to = restricted_to,
|
restricted_to = restricted_to,
|
||||||
|
target_compatible_with = target_compatible_with,
|
||||||
reflection_name = reflection_name,
|
reflection_name = reflection_name,
|
||||||
reflection_visibility = visibility,
|
reflection_visibility = visibility,
|
||||||
)
|
)
|
||||||
@@ -242,10 +234,12 @@ def flatbuffer_cc_library(
|
|||||||
],
|
],
|
||||||
deps = [
|
deps = [
|
||||||
"@com_github_google_flatbuffers//:runtime_cc",
|
"@com_github_google_flatbuffers//:runtime_cc",
|
||||||
],
|
"@com_github_google_flatbuffers//:flatbuffers",
|
||||||
includes = [],
|
] + deps,
|
||||||
|
includes = cc_include_paths,
|
||||||
compatible_with = compatible_with,
|
compatible_with = compatible_with,
|
||||||
restricted_to = restricted_to,
|
restricted_to = restricted_to,
|
||||||
|
target_compatible_with = target_compatible_with,
|
||||||
linkstatic = 1,
|
linkstatic = 1,
|
||||||
visibility = visibility,
|
visibility = visibility,
|
||||||
)
|
)
|
||||||
@@ -254,7 +248,7 @@ def flatbuffer_cc_library(
|
|||||||
# Flatbuffer set.
|
# Flatbuffer set.
|
||||||
native.filegroup(
|
native.filegroup(
|
||||||
name = srcs_filegroup_name if srcs_filegroup_name else "%s_includes" % (name),
|
name = srcs_filegroup_name if srcs_filegroup_name else "%s_includes" % (name),
|
||||||
srcs = srcs,
|
srcs = srcs + includes,
|
||||||
compatible_with = compatible_with,
|
compatible_with = compatible_with,
|
||||||
restricted_to = restricted_to,
|
restricted_to = restricted_to,
|
||||||
visibility = srcs_filegroup_visibility if srcs_filegroup_visibility != None else visibility,
|
visibility = srcs_filegroup_visibility if srcs_filegroup_visibility != None else visibility,
|
||||||
|
|||||||
@@ -5,8 +5,8 @@ message(STATUS "Conan FlatBuffers Wrapper")
|
|||||||
include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
|
include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
|
||||||
conan_basic_setup()
|
conan_basic_setup()
|
||||||
|
|
||||||
if (WIN32 AND MSVC AND FLATBUFFERS_BUILD_SHAREDLIB)
|
if (WIN32 AND MSVC_LIKE AND FLATBUFFERS_BUILD_SHAREDLIB)
|
||||||
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)
|
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)
|
||||||
endif(WIN32 AND MSVC AND FLATBUFFERS_BUILD_SHAREDLIB)
|
endif(WIN32 AND MSVC_LIKE AND FLATBUFFERS_BUILD_SHAREDLIB)
|
||||||
|
|
||||||
include(${CMAKE_SOURCE_DIR}/CMakeListsOriginal.txt)
|
include(${CMAKE_SOURCE_DIR}/CMakeListsOriginal.txt)
|
||||||
|
|||||||
@@ -6,16 +6,6 @@ import subprocess
|
|||||||
from cpt.packager import ConanMultiPackager
|
from cpt.packager import ConanMultiPackager
|
||||||
|
|
||||||
|
|
||||||
def set_appveyor_environment():
|
|
||||||
if os.getenv("APPVEYOR") is not None:
|
|
||||||
compiler_version = os.getenv("CMAKE_VS_VERSION").split(" ")[0].replace('"', '')
|
|
||||||
os.environ["CONAN_VISUAL_VERSIONS"] = compiler_version
|
|
||||||
os.environ["CONAN_STABLE_BRANCH_PATTERN"] = "master"
|
|
||||||
ci_platform = os.getenv("Platform").replace('"', '')
|
|
||||||
ci_platform = "x86" if ci_platform == "x86" else "x86_64"
|
|
||||||
os.environ["CONAN_ARCHS"] = ci_platform
|
|
||||||
os.environ["CONAN_BUILD_TYPES"] = os.getenv("Configuration").replace('"', '')
|
|
||||||
|
|
||||||
|
|
||||||
def get_branch():
|
def get_branch():
|
||||||
try:
|
try:
|
||||||
@@ -56,7 +46,6 @@ if __name__ == "__main__":
|
|||||||
stable_branch_pattern = os.getenv("CONAN_STABLE_BRANCH_PATTERN", r"v\d+\.\d+\.\d+.*")
|
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"))
|
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)
|
upload_only_when_stable = os.getenv("CONAN_UPLOAD_ONLY_WHEN_STABLE", True)
|
||||||
set_appveyor_environment()
|
|
||||||
|
|
||||||
builder = ConanMultiPackager(reference=get_reference(username),
|
builder = ConanMultiPackager(reference=get_reference(username),
|
||||||
username=username,
|
username=username,
|
||||||
|
|||||||
@@ -1,4 +1,22 @@
|
|||||||
# CHANGELOG
|
## 2.0.5
|
||||||
|
|
||||||
|
- switch to null safety (#6696)
|
||||||
|
- add Object APIs (pack/unpack) (#6682, #6723, #6846)
|
||||||
|
- add custom builder buffer allocator support (#6711)
|
||||||
|
- add `Builder.size()` - finished buffer size (#6403)
|
||||||
|
- make `writeString()` argument non-nullable (#6737)
|
||||||
|
- make tables fixed size (expect the number of fields when creating) (#6735)
|
||||||
|
- make table deduplication optional (param `deduplicateTables`) (#6734)
|
||||||
|
- change `Builder.reset()` to reuse an existing buffer (#6661)
|
||||||
|
- change table building to assert() instead of exceptions (#6754)
|
||||||
|
- optimize `writeString()` for ASCII (param `asciiOptimization`) (#6736)
|
||||||
|
- change `StringReader` to make ASCII optimization optional (param `asciiOptimization`) (#6758)
|
||||||
|
- change `[byte]` and `[ubyte]` representation to `dart:typed_data` `Int8List` and `Uint8List` (#6839)
|
||||||
|
- rename `lowFinish()` to `buffer` getter (#6712)
|
||||||
|
- fix `Builder._writeString()` - always write trailing zero byte (#6390)
|
||||||
|
- fix `Builder.reset()` - clear vTables (#6386)
|
||||||
|
- make sure added padding is zeroed, same as in C++ (#6716)
|
||||||
|
- many performance improvements (#6755)
|
||||||
|
|
||||||
## 1.9.2
|
## 1.9.2
|
||||||
|
|
||||||
|
|||||||
32
dart/LICENSE
32
dart/LICENSE
@@ -1,35 +1,3 @@
|
|||||||
The code in lib/flat_buffers.dart is based on code that was releases under the
|
|
||||||
following license:
|
|
||||||
|
|
||||||
Copyright 2012, the Dart project authors. All rights reserved.
|
|
||||||
Redistribution and use in source and binary forms, with or without
|
|
||||||
modification, are permitted provided that the following conditions are
|
|
||||||
met:
|
|
||||||
* Redistributions of source code must retain the above copyright
|
|
||||||
notice, this list of conditions and the following disclaimer.
|
|
||||||
* Redistributions in binary form must reproduce the above
|
|
||||||
copyright notice, this list of conditions and the following
|
|
||||||
disclaimer in the documentation and/or other materials provided
|
|
||||||
with the distribution.
|
|
||||||
* Neither the name of Google Inc. nor the names of its
|
|
||||||
contributors may be used to endorse or promote products derived
|
|
||||||
from this software without specific prior written permission.
|
|
||||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
||||||
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
||||||
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
||||||
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
||||||
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
||||||
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
||||||
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
||||||
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
||||||
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
||||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
||||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
||||||
|
|
||||||
To the extent permissible, the changes to that code and the other assets in
|
|
||||||
this package are licensed under the Apache2 license:
|
|
||||||
|
|
||||||
|
|
||||||
Apache License
|
Apache License
|
||||||
Version 2.0, January 2004
|
Version 2.0, January 2004
|
||||||
http://www.apache.org/licenses/
|
http://www.apache.org/licenses/
|
||||||
|
|||||||
@@ -1,13 +1,23 @@
|
|||||||
# FlatBuffers for Dart
|
# FlatBuffers for Dart
|
||||||
|
|
||||||
This package is used to read and write FlatBuffer files in Dart.
|
This package is used to read and write [FlatBuffers](https://google.github.io/flatbuffers/).
|
||||||
|
|
||||||
Most consumers will want to use the [`flatc`](https://github.com/google/flatbuffers)
|
Most consumers will want to use the [`flatc` - FlatBuffer compiler](https://github.com/google/flatbuffers) binary for your platform.
|
||||||
compiler to generate Dart code from a FlatBuffers IDL schema. For example, the
|
You can find it in the `generator/{Platform}` directory of the [released package archive](https://pub.dev/packages/flat_buffers/versions/2.0.5.tar.gz).
|
||||||
`monster_my_game.sample_generated.dart` was generated with `flatc` from
|
|
||||||
`monster.fbs` in the example folder. The generated classes can be used to read
|
The FlatBuffer compiler `flatc` reads a FlatBuffers IDL schema and generates Dart code.
|
||||||
or write binary files that are interoperable with other languages and platforms
|
The generated classes can be used to read or write binary data/files that are interoperable with
|
||||||
supported by FlatBuffers, as illustrated in the `example.dart` in the
|
other languages and platforms supported by FlatBuffers, as illustrated in the `example.dart` in the
|
||||||
examples folder.
|
examples folder.
|
||||||
|
|
||||||
Additional documentation and examples are available [at the FlatBuffers site](https://google.github.io/flatbuffers/index.html)
|
For more details and documentation, head over to the official site and read the
|
||||||
|
[Tutorial](https://google.github.io/flatbuffers/flatbuffers_guide_tutorial.html) and how to
|
||||||
|
[use FlatBuffers in Dart](https://google.github.io/flatbuffers/flatbuffers_guide_use_dart.html).
|
||||||
|
|
||||||
|
## Dart 2.0 notes
|
||||||
|
Version 2.0.5 ships with it's own custom build of `flatc` because this is an extraordinary release to catch-up
|
||||||
|
with FlatBuffers for other platforms. This generator can only generate dart code (to avoid generating code for other platforms which isn't released yet).
|
||||||
|
On the other hand, the generated code still produces standard binary FlatBuffers compatible with other languages.
|
||||||
|
In other words: only `flatc --dart ...` works with this generator, but your app will be able to produce and read standard binary (`Uint8List`) FlatBuffers that are fully compotible with other languages supporting FlatBuffers (e.g. Java, C++, ...).
|
||||||
|
|
||||||
|
In the future a common `flatc` binary for all platforms would be shipped through GitHub release page instead.
|
||||||
|
|||||||
1
dart/analysis_options.yaml
Normal file
1
dart/analysis_options.yaml
Normal file
@@ -0,0 +1 @@
|
|||||||
|
include: package:lints/recommended.yaml
|
||||||
@@ -15,7 +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 myGame;
|
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.
|
||||||
|
|
||||||
@@ -25,27 +25,27 @@ void main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void builderTest() {
|
void builderTest() {
|
||||||
final builder = new fb.Builder(initialSize: 1024);
|
final builder = fb.Builder(initialSize: 1024);
|
||||||
final int weaponOneName = builder.writeString("Sword");
|
final int? weaponOneName = builder.writeString("Sword");
|
||||||
final int weaponOneDamage = 3;
|
final int weaponOneDamage = 3;
|
||||||
|
|
||||||
final int weaponTwoName = builder.writeString("Axe");
|
final int? weaponTwoName = builder.writeString("Axe");
|
||||||
final int weaponTwoDamage = 5;
|
final int weaponTwoDamage = 5;
|
||||||
|
|
||||||
final swordBuilder = new myGame.WeaponBuilder(builder)
|
final swordBuilder = my_game.WeaponBuilder(builder)
|
||||||
..begin()
|
..begin()
|
||||||
..addNameOffset(weaponOneName)
|
..addNameOffset(weaponOneName)
|
||||||
..addDamage(weaponOneDamage);
|
..addDamage(weaponOneDamage);
|
||||||
final int sword = swordBuilder.finish();
|
final int sword = swordBuilder.finish();
|
||||||
|
|
||||||
final axeBuilder = new myGame.WeaponBuilder(builder)
|
final axeBuilder = my_game.WeaponBuilder(builder)
|
||||||
..begin()
|
..begin()
|
||||||
..addNameOffset(weaponTwoName)
|
..addNameOffset(weaponTwoName)
|
||||||
..addDamage(weaponTwoDamage);
|
..addDamage(weaponTwoDamage);
|
||||||
final int axe = axeBuilder.finish();
|
final int axe = axeBuilder.finish();
|
||||||
|
|
||||||
// Serialize a name for our monster, called "Orc".
|
// Serialize a name for our monster, called "Orc".
|
||||||
final int name = builder.writeString('Orc');
|
final int? name = builder.writeString('Orc');
|
||||||
|
|
||||||
// Create a list representing the inventory of the Orc. Each number
|
// Create a list 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.
|
||||||
@@ -54,7 +54,7 @@ void builderTest() {
|
|||||||
final weapons = builder.writeList([sword, axe]);
|
final weapons = builder.writeList([sword, axe]);
|
||||||
|
|
||||||
// Struct builders are very easy to reuse.
|
// Struct builders are very easy to reuse.
|
||||||
final vec3Builder = new myGame.Vec3Builder(builder);
|
final vec3Builder = my_game.Vec3Builder(builder);
|
||||||
|
|
||||||
vec3Builder.finish(4.0, 5.0, 6.0);
|
vec3Builder.finish(4.0, 5.0, 6.0);
|
||||||
vec3Builder.finish(1.0, 2.0, 3.0);
|
vec3Builder.finish(1.0, 2.0, 3.0);
|
||||||
@@ -62,21 +62,21 @@ void builderTest() {
|
|||||||
final int hp = 300;
|
final int hp = 300;
|
||||||
final int mana = 150;
|
final int mana = 150;
|
||||||
|
|
||||||
final monster = new myGame.MonsterBuilder(builder)
|
final monster = my_game.MonsterBuilder(builder)
|
||||||
..begin()
|
..begin()
|
||||||
..addNameOffset(name)
|
..addNameOffset(name)
|
||||||
..addInventoryOffset(inventory)
|
..addInventoryOffset(inventory)
|
||||||
..addWeaponsOffset(weapons)
|
..addWeaponsOffset(weapons)
|
||||||
..addEquippedType(myGame.EquipmentTypeId.Weapon)
|
..addEquippedType(my_game.EquipmentTypeId.Weapon)
|
||||||
..addEquippedOffset(axe)
|
..addEquippedOffset(axe)
|
||||||
..addHp(hp)
|
..addHp(hp)
|
||||||
..addMana(mana)
|
..addMana(mana)
|
||||||
..addPos(vec3Builder.finish(1.0, 2.0, 3.0))
|
..addPos(vec3Builder.finish(1.0, 2.0, 3.0))
|
||||||
..addColor(myGame.Color.Red);
|
..addColor(my_game.Color.Red);
|
||||||
|
|
||||||
final int monsteroff = monster.finish();
|
final int monsteroff = monster.finish();
|
||||||
final buffer = builder.finish(monsteroff);
|
builder.finish(monsteroff);
|
||||||
if (verify(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!");
|
||||||
}
|
}
|
||||||
@@ -85,17 +85,17 @@ void builderTest() {
|
|||||||
void objectBuilderTest() {
|
void objectBuilderTest() {
|
||||||
// Create the builder here so we can use it for both weapons and equipped
|
// Create the builder here so we can use it for both weapons and equipped
|
||||||
// the actual data will only be written to the buffer once.
|
// the actual data will only be written to the buffer once.
|
||||||
var axe = new myGame.WeaponObjectBuilder(name: 'Axe', damage: 5);
|
var axe = my_game.WeaponObjectBuilder(name: 'Axe', damage: 5);
|
||||||
|
|
||||||
var monsterBuilder = new myGame.MonsterObjectBuilder(
|
var monsterBuilder = my_game.MonsterObjectBuilder(
|
||||||
pos: new myGame.Vec3ObjectBuilder(x: 1.0, y: 2.0, z: 3.0),
|
pos: my_game.Vec3ObjectBuilder(x: 1.0, y: 2.0, z: 3.0),
|
||||||
mana: 150,
|
mana: 150,
|
||||||
hp: 300,
|
hp: 300,
|
||||||
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: myGame.Color.Red,
|
color: my_game.Color.Red,
|
||||||
weapons: [new myGame.WeaponObjectBuilder(name: 'Sword', damage: 3), axe],
|
weapons: [my_game.WeaponObjectBuilder(name: 'Sword', damage: 3), axe],
|
||||||
equippedType: myGame.EquipmentTypeId.Weapon,
|
equippedType: my_game.EquipmentTypeId.Weapon,
|
||||||
equipped: axe,
|
equipped: axe,
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -114,7 +114,7 @@ void objectBuilderTest() {
|
|||||||
|
|
||||||
bool verify(List<int> buffer) {
|
bool verify(List<int> buffer) {
|
||||||
// Get access to the root:
|
// Get access to the root:
|
||||||
var monster = new myGame.Monster(buffer);
|
var monster = my_game.Monster(buffer);
|
||||||
|
|
||||||
// Get and test some scalar types from the FlatBuffer.
|
// Get and test some scalar types from the FlatBuffer.
|
||||||
assert(monster.hp == 80);
|
assert(monster.hp == 80);
|
||||||
@@ -122,31 +122,29 @@ bool verify(List<int> buffer) {
|
|||||||
assert(monster.name == "MyMonster");
|
assert(monster.name == "MyMonster");
|
||||||
|
|
||||||
// Get and test a field of the FlatBuffer's `struct`.
|
// Get and test a field of the FlatBuffer's `struct`.
|
||||||
var pos = monster.pos;
|
var pos = monster.pos!;
|
||||||
assert(pos != null);
|
|
||||||
assert(pos.z == 3.0);
|
assert(pos.z == 3.0);
|
||||||
|
|
||||||
// Get a test an element from the `inventory` FlatBuffer's `vector`.
|
// Get a test an element from the `inventory` FlatBuffer's `vector`.
|
||||||
var inv = monster.inventory;
|
var inv = monster.inventory!;
|
||||||
assert(inv != null);
|
|
||||||
assert(inv.length == 10);
|
assert(inv.length == 10);
|
||||||
assert(inv[9] == 9);
|
assert(inv[9] == 9);
|
||||||
|
|
||||||
// Get and test the `weapons` FlatBuffers's `vector`.
|
// Get and test the `weapons` FlatBuffers's `vector`.
|
||||||
var expected_weapon_names = ["Sword", "Axe"];
|
var expectedWeaponNames = ["Sword", "Axe"];
|
||||||
var expected_weapon_damages = [3, 5];
|
var expectedWeaponDamages = [3, 5];
|
||||||
var weps = monster.weapons;
|
var weps = monster.weapons!;
|
||||||
for (int i = 0; i < weps.length; i++) {
|
for (int i = 0; i < weps.length; i++) {
|
||||||
assert(weps[i].name == expected_weapon_names[i]);
|
assert(weps[i].name == expectedWeaponNames[i]);
|
||||||
assert(weps[i].damage == expected_weapon_damages[i]);
|
assert(weps[i].damage == expectedWeaponDamages[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get and test the `Equipment` union (`equipped` field).
|
// Get and test the `Equipment` union (`equipped` field).
|
||||||
assert(monster.equippedType.value == myGame.EquipmentTypeId.Weapon.value);
|
assert(monster.equippedType!.value == my_game.EquipmentTypeId.Weapon.value);
|
||||||
assert(monster.equippedType == myGame.EquipmentTypeId.Weapon);
|
assert(monster.equippedType == my_game.EquipmentTypeId.Weapon);
|
||||||
|
|
||||||
assert(monster.equipped is myGame.Weapon);
|
assert(monster.equipped is my_game.Weapon);
|
||||||
var equipped = monster.equipped as myGame.Weapon;
|
var equipped = monster.equipped as my_game.Weapon;
|
||||||
assert(equipped.name == "Axe");
|
assert(equipped.name == "Axe");
|
||||||
assert(equipped.damage == 5);
|
assert(equipped.damage == 5);
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
// automatically generated by the FlatBuffers compiler, do not modify
|
// automatically generated by the FlatBuffers compiler, do not modify
|
||||||
// ignore_for_file: unused_import, unused_field, unused_local_variable
|
// ignore_for_file: unused_import, unused_field, unused_element, unused_local_variable
|
||||||
|
|
||||||
library my_game.sample;
|
library my_game.sample;
|
||||||
|
|
||||||
@@ -12,23 +12,29 @@ class Color {
|
|||||||
const Color._(this.value);
|
const Color._(this.value);
|
||||||
|
|
||||||
factory Color.fromValue(int value) {
|
factory Color.fromValue(int value) {
|
||||||
if (value == null) value = 0;
|
final result = values[value];
|
||||||
if (!values.containsKey(value)) {
|
if (result == null) {
|
||||||
throw new StateError('Invalid value $value for bit flag enum Color');
|
throw StateError('Invalid value $value for bit flag enum Color');
|
||||||
}
|
}
|
||||||
return values[value];
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static Color? _createOrNull(int? value) =>
|
||||||
|
value == null ? null : Color.fromValue(value);
|
||||||
|
|
||||||
static const int minValue = 0;
|
static const int minValue = 0;
|
||||||
static const int maxValue = 2;
|
static const int maxValue = 2;
|
||||||
static bool containsValue(int value) => values.containsKey(value);
|
static bool containsValue(int value) => values.containsKey(value);
|
||||||
|
|
||||||
static const Color Red = const Color._(0);
|
static const Color Red = Color._(0);
|
||||||
static const Color Green = const Color._(1);
|
static const Color Green = Color._(1);
|
||||||
static const Color Blue = const Color._(2);
|
static const Color Blue = Color._(2);
|
||||||
static const Map<int,Color> values = {0: Red,1: Green,2: Blue,};
|
static const Map<int, Color> values = {
|
||||||
|
0: Red,
|
||||||
|
1: Green,
|
||||||
|
2: Blue};
|
||||||
|
|
||||||
static const fb.Reader<Color> reader = const _ColorReader();
|
static const fb.Reader<Color> reader = _ColorReader();
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String toString() {
|
String toString() {
|
||||||
@@ -44,7 +50,7 @@ class _ColorReader extends fb.Reader<Color> {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Color read(fb.BufferContext bc, int offset) =>
|
Color read(fb.BufferContext bc, int offset) =>
|
||||||
new Color.fromValue(const fb.Int8Reader().read(bc, offset));
|
Color.fromValue(const fb.Int8Reader().read(bc, offset));
|
||||||
}
|
}
|
||||||
|
|
||||||
class EquipmentTypeId {
|
class EquipmentTypeId {
|
||||||
@@ -52,22 +58,27 @@ class EquipmentTypeId {
|
|||||||
const EquipmentTypeId._(this.value);
|
const EquipmentTypeId._(this.value);
|
||||||
|
|
||||||
factory EquipmentTypeId.fromValue(int value) {
|
factory EquipmentTypeId.fromValue(int value) {
|
||||||
if (value == null) value = 0;
|
final result = values[value];
|
||||||
if (!values.containsKey(value)) {
|
if (result == null) {
|
||||||
throw new StateError('Invalid value $value for bit flag enum EquipmentTypeId');
|
throw StateError('Invalid value $value for bit flag enum EquipmentTypeId');
|
||||||
}
|
}
|
||||||
return values[value];
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static EquipmentTypeId? _createOrNull(int? value) =>
|
||||||
|
value == null ? null : EquipmentTypeId.fromValue(value);
|
||||||
|
|
||||||
static const int minValue = 0;
|
static const int minValue = 0;
|
||||||
static const int maxValue = 1;
|
static const int maxValue = 1;
|
||||||
static bool containsValue(int value) => values.containsKey(value);
|
static bool containsValue(int value) => values.containsKey(value);
|
||||||
|
|
||||||
static const EquipmentTypeId NONE = const EquipmentTypeId._(0);
|
static const EquipmentTypeId NONE = EquipmentTypeId._(0);
|
||||||
static const EquipmentTypeId Weapon = const EquipmentTypeId._(1);
|
static const EquipmentTypeId Weapon = EquipmentTypeId._(1);
|
||||||
static const Map<int,EquipmentTypeId> values = {0: NONE,1: Weapon,};
|
static const Map<int, EquipmentTypeId> values = {
|
||||||
|
0: NONE,
|
||||||
|
1: Weapon};
|
||||||
|
|
||||||
static const fb.Reader<EquipmentTypeId> reader = const _EquipmentTypeIdReader();
|
static const fb.Reader<EquipmentTypeId> reader = _EquipmentTypeIdReader();
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String toString() {
|
String toString() {
|
||||||
@@ -83,13 +94,13 @@ class _EquipmentTypeIdReader extends fb.Reader<EquipmentTypeId> {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
EquipmentTypeId read(fb.BufferContext bc, int offset) =>
|
EquipmentTypeId read(fb.BufferContext bc, int offset) =>
|
||||||
new EquipmentTypeId.fromValue(const fb.Uint8Reader().read(bc, offset));
|
EquipmentTypeId.fromValue(const fb.Uint8Reader().read(bc, offset));
|
||||||
}
|
}
|
||||||
|
|
||||||
class Vec3 {
|
class Vec3 {
|
||||||
Vec3._(this._bc, this._bcOffset);
|
Vec3._(this._bc, this._bcOffset);
|
||||||
|
|
||||||
static const fb.Reader<Vec3> reader = const _Vec3Reader();
|
static const fb.Reader<Vec3> reader = _Vec3Reader();
|
||||||
|
|
||||||
final fb.BufferContext _bc;
|
final fb.BufferContext _bc;
|
||||||
final int _bcOffset;
|
final int _bcOffset;
|
||||||
@@ -112,13 +123,11 @@ class _Vec3Reader extends fb.StructReader<Vec3> {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Vec3 createObject(fb.BufferContext bc, int offset) =>
|
Vec3 createObject(fb.BufferContext bc, int offset) =>
|
||||||
new Vec3._(bc, offset);
|
Vec3._(bc, offset);
|
||||||
}
|
}
|
||||||
|
|
||||||
class Vec3Builder {
|
class Vec3Builder {
|
||||||
Vec3Builder(this.fbBuilder) {
|
Vec3Builder(this.fbBuilder);
|
||||||
assert(fbBuilder != null);
|
|
||||||
}
|
|
||||||
|
|
||||||
final fb.Builder fbBuilder;
|
final fb.Builder fbBuilder;
|
||||||
|
|
||||||
@@ -137,9 +146,9 @@ class Vec3ObjectBuilder extends fb.ObjectBuilder {
|
|||||||
final double _z;
|
final double _z;
|
||||||
|
|
||||||
Vec3ObjectBuilder({
|
Vec3ObjectBuilder({
|
||||||
double x,
|
required double x,
|
||||||
double y,
|
required double y,
|
||||||
double z,
|
required double z,
|
||||||
})
|
})
|
||||||
: _x = x,
|
: _x = x,
|
||||||
_y = y,
|
_y = y,
|
||||||
@@ -147,10 +156,7 @@ class Vec3ObjectBuilder extends fb.ObjectBuilder {
|
|||||||
|
|
||||||
/// Finish building, and store into the [fbBuilder].
|
/// Finish building, and store into the [fbBuilder].
|
||||||
@override
|
@override
|
||||||
int finish(
|
int finish(fb.Builder fbBuilder) {
|
||||||
fb.Builder fbBuilder) {
|
|
||||||
assert(fbBuilder != null);
|
|
||||||
|
|
||||||
fbBuilder.putFloat32(_z);
|
fbBuilder.putFloat32(_z);
|
||||||
fbBuilder.putFloat32(_y);
|
fbBuilder.putFloat32(_y);
|
||||||
fbBuilder.putFloat32(_x);
|
fbBuilder.putFloat32(_x);
|
||||||
@@ -159,39 +165,39 @@ class Vec3ObjectBuilder extends fb.ObjectBuilder {
|
|||||||
|
|
||||||
/// Convenience method to serialize to byte list.
|
/// Convenience method to serialize to byte list.
|
||||||
@override
|
@override
|
||||||
Uint8List toBytes([String fileIdentifier]) {
|
Uint8List toBytes([String? fileIdentifier]) {
|
||||||
fb.Builder fbBuilder = new fb.Builder();
|
final fbBuilder = fb.Builder(deduplicateTables: false);
|
||||||
int offset = finish(fbBuilder);
|
fbBuilder.finish(finish(fbBuilder), fileIdentifier);
|
||||||
return fbBuilder.finish(offset, fileIdentifier);
|
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) {
|
||||||
fb.BufferContext rootRef = new fb.BufferContext.fromBytes(bytes);
|
final rootRef = fb.BufferContext.fromBytes(bytes);
|
||||||
return reader.read(rootRef, 0);
|
return reader.read(rootRef, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
static const fb.Reader<Monster> reader = const _MonsterReader();
|
static const fb.Reader<Monster> reader = _MonsterReader();
|
||||||
|
|
||||||
final fb.BufferContext _bc;
|
final fb.BufferContext _bc;
|
||||||
final int _bcOffset;
|
final int _bcOffset;
|
||||||
|
|
||||||
Vec3 get pos => Vec3.reader.vTableGet(_bc, _bcOffset, 4, null);
|
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().vTableGet(_bc, _bcOffset, 10, null);
|
String? get name => const fb.StringReader().vTableGetNullable(_bc, _bcOffset, 10);
|
||||||
List<int> get inventory => const fb.ListReader<int>(const fb.Uint8Reader()).vTableGet(_bc, _bcOffset, 14, null);
|
List<int>? get inventory => const fb.Uint8ListReader().vTableGetNullable(_bc, _bcOffset, 14);
|
||||||
Color get color => new Color.fromValue(const fb.Int8Reader().vTableGet(_bc, _bcOffset, 16, 2));
|
Color get color => Color.fromValue(const fb.Int8Reader().vTableGet(_bc, _bcOffset, 16, 2));
|
||||||
List<Weapon> get weapons => const fb.ListReader<Weapon>(Weapon.reader).vTableGet(_bc, _bcOffset, 18, null);
|
List<Weapon>? get weapons => const fb.ListReader<Weapon>(Weapon.reader).vTableGetNullable(_bc, _bcOffset, 18);
|
||||||
EquipmentTypeId get equippedType => new EquipmentTypeId.fromValue(const fb.Uint8Reader().vTableGet(_bc, _bcOffset, 20, 0));
|
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.vTableGet(_bc, _bcOffset, 22, null);
|
case 1: return Weapon.reader.vTableGetNullable(_bc, _bcOffset, 22);
|
||||||
default: return null;
|
default: return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
List<Vec3> get path => const fb.ListReader<Vec3>(Vec3.reader).vTableGet(_bc, _bcOffset, 24, null);
|
List<Vec3>? get path => const fb.ListReader<Vec3>(Vec3.reader).vTableGetNullable(_bc, _bcOffset, 24);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String toString() {
|
String toString() {
|
||||||
@@ -204,57 +210,55 @@ class _MonsterReader extends fb.TableReader<Monster> {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Monster createObject(fb.BufferContext bc, int offset) =>
|
Monster createObject(fb.BufferContext bc, int offset) =>
|
||||||
new Monster._(bc, offset);
|
Monster._(bc, offset);
|
||||||
}
|
}
|
||||||
|
|
||||||
class MonsterBuilder {
|
class MonsterBuilder {
|
||||||
MonsterBuilder(this.fbBuilder) {
|
MonsterBuilder(this.fbBuilder);
|
||||||
assert(fbBuilder != null);
|
|
||||||
}
|
|
||||||
|
|
||||||
final fb.Builder fbBuilder;
|
final fb.Builder fbBuilder;
|
||||||
|
|
||||||
void begin() {
|
void begin() {
|
||||||
fbBuilder.startTable();
|
fbBuilder.startTable(10);
|
||||||
}
|
}
|
||||||
|
|
||||||
int addPos(int offset) {
|
int addPos(int offset) {
|
||||||
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;
|
||||||
}
|
}
|
||||||
@@ -265,28 +269,28 @@ class MonsterBuilder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class MonsterObjectBuilder extends fb.ObjectBuilder {
|
class MonsterObjectBuilder extends fb.ObjectBuilder {
|
||||||
final Vec3ObjectBuilder _pos;
|
final Vec3ObjectBuilder? _pos;
|
||||||
final int _mana;
|
final int? _mana;
|
||||||
final int _hp;
|
final int? _hp;
|
||||||
final String _name;
|
final String? _name;
|
||||||
final List<int> _inventory;
|
final List<int>? _inventory;
|
||||||
final Color _color;
|
final Color? _color;
|
||||||
final List<WeaponObjectBuilder> _weapons;
|
final List<WeaponObjectBuilder>? _weapons;
|
||||||
final EquipmentTypeId _equippedType;
|
final EquipmentTypeId? _equippedType;
|
||||||
final dynamic _equipped;
|
final dynamic _equipped;
|
||||||
final List<Vec3ObjectBuilder> _path;
|
final List<Vec3ObjectBuilder>? _path;
|
||||||
|
|
||||||
MonsterObjectBuilder({
|
MonsterObjectBuilder({
|
||||||
Vec3ObjectBuilder pos,
|
Vec3ObjectBuilder? pos,
|
||||||
int mana,
|
int? mana,
|
||||||
int hp,
|
int? hp,
|
||||||
String name,
|
String? name,
|
||||||
List<int> inventory,
|
List<int>? inventory,
|
||||||
Color color,
|
Color? color,
|
||||||
List<WeaponObjectBuilder> weapons,
|
List<WeaponObjectBuilder>? weapons,
|
||||||
EquipmentTypeId equippedType,
|
EquipmentTypeId? equippedType,
|
||||||
dynamic equipped,
|
dynamic equipped,
|
||||||
List<Vec3ObjectBuilder> path,
|
List<Vec3ObjectBuilder>? path,
|
||||||
})
|
})
|
||||||
: _pos = pos,
|
: _pos = pos,
|
||||||
_mana = mana,
|
_mana = mana,
|
||||||
@@ -301,68 +305,53 @@ class MonsterObjectBuilder extends fb.ObjectBuilder {
|
|||||||
|
|
||||||
/// Finish building, and store into the [fbBuilder].
|
/// Finish building, and store into the [fbBuilder].
|
||||||
@override
|
@override
|
||||||
int finish(
|
int finish(fb.Builder fbBuilder) {
|
||||||
fb.Builder fbBuilder) {
|
final int? nameOffset = _name == null ? null
|
||||||
assert(fbBuilder != null);
|
: fbBuilder.writeString(_name!);
|
||||||
final int nameOffset = fbBuilder.writeString(_name);
|
final int? inventoryOffset = _inventory == null ? null
|
||||||
final int inventoryOffset = _inventory?.isNotEmpty == true
|
: fbBuilder.writeListUint8(_inventory!);
|
||||||
? fbBuilder.writeListUint8(_inventory)
|
final int? weaponsOffset = _weapons == null ? null
|
||||||
: null;
|
: fbBuilder.writeList(_weapons!.map((b) => b.getOrCreateOffset(fbBuilder)).toList());
|
||||||
final int weaponsOffset = _weapons?.isNotEmpty == true
|
final int? equippedOffset = _equipped?.getOrCreateOffset(fbBuilder);
|
||||||
? fbBuilder.writeList(_weapons.map((b) => b.getOrCreateOffset(fbBuilder)).toList())
|
final int? pathOffset = _path == null ? null
|
||||||
: null;
|
: fbBuilder.writeListOfStructs(_path!);
|
||||||
final int equippedOffset = _equipped?.getOrCreateOffset(fbBuilder);
|
fbBuilder.startTable(10);
|
||||||
final int pathOffset = _path?.isNotEmpty == true
|
|
||||||
? fbBuilder.writeListOfStructs(_path)
|
|
||||||
: null;
|
|
||||||
|
|
||||||
fbBuilder.startTable();
|
|
||||||
if (_pos != null) {
|
if (_pos != null) {
|
||||||
fbBuilder.addStruct(0, _pos.finish(fbBuilder));
|
fbBuilder.addStruct(0, _pos!.finish(fbBuilder));
|
||||||
}
|
}
|
||||||
fbBuilder.addInt16(1, _mana);
|
fbBuilder.addInt16(1, _mana);
|
||||||
fbBuilder.addInt16(2, _hp);
|
fbBuilder.addInt16(2, _hp);
|
||||||
if (nameOffset != null) {
|
fbBuilder.addOffset(3, nameOffset);
|
||||||
fbBuilder.addOffset(3, nameOffset);
|
fbBuilder.addOffset(5, inventoryOffset);
|
||||||
}
|
|
||||||
if (inventoryOffset != null) {
|
|
||||||
fbBuilder.addOffset(5, inventoryOffset);
|
|
||||||
}
|
|
||||||
fbBuilder.addInt8(6, _color?.value);
|
fbBuilder.addInt8(6, _color?.value);
|
||||||
if (weaponsOffset != null) {
|
fbBuilder.addOffset(7, weaponsOffset);
|
||||||
fbBuilder.addOffset(7, weaponsOffset);
|
|
||||||
}
|
|
||||||
fbBuilder.addUint8(8, _equippedType?.value);
|
fbBuilder.addUint8(8, _equippedType?.value);
|
||||||
if (equippedOffset != null) {
|
fbBuilder.addOffset(9, equippedOffset);
|
||||||
fbBuilder.addOffset(9, equippedOffset);
|
fbBuilder.addOffset(10, pathOffset);
|
||||||
}
|
|
||||||
if (pathOffset != null) {
|
|
||||||
fbBuilder.addOffset(10, pathOffset);
|
|
||||||
}
|
|
||||||
return fbBuilder.endTable();
|
return fbBuilder.endTable();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Convenience method to serialize to byte list.
|
/// Convenience method to serialize to byte list.
|
||||||
@override
|
@override
|
||||||
Uint8List toBytes([String fileIdentifier]) {
|
Uint8List toBytes([String? fileIdentifier]) {
|
||||||
fb.Builder fbBuilder = new fb.Builder();
|
final fbBuilder = fb.Builder(deduplicateTables: false);
|
||||||
int offset = finish(fbBuilder);
|
fbBuilder.finish(finish(fbBuilder), fileIdentifier);
|
||||||
return fbBuilder.finish(offset, fileIdentifier);
|
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) {
|
||||||
fb.BufferContext rootRef = new fb.BufferContext.fromBytes(bytes);
|
final rootRef = fb.BufferContext.fromBytes(bytes);
|
||||||
return reader.read(rootRef, 0);
|
return reader.read(rootRef, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
static const fb.Reader<Weapon> reader = const _WeaponReader();
|
static const fb.Reader<Weapon> reader = _WeaponReader();
|
||||||
|
|
||||||
final fb.BufferContext _bc;
|
final fb.BufferContext _bc;
|
||||||
final int _bcOffset;
|
final int _bcOffset;
|
||||||
|
|
||||||
String get name => const fb.StringReader().vTableGet(_bc, _bcOffset, 4, null);
|
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
|
||||||
@@ -376,25 +365,23 @@ class _WeaponReader extends fb.TableReader<Weapon> {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Weapon createObject(fb.BufferContext bc, int offset) =>
|
Weapon createObject(fb.BufferContext bc, int offset) =>
|
||||||
new Weapon._(bc, offset);
|
Weapon._(bc, offset);
|
||||||
}
|
}
|
||||||
|
|
||||||
class WeaponBuilder {
|
class WeaponBuilder {
|
||||||
WeaponBuilder(this.fbBuilder) {
|
WeaponBuilder(this.fbBuilder);
|
||||||
assert(fbBuilder != null);
|
|
||||||
}
|
|
||||||
|
|
||||||
final fb.Builder fbBuilder;
|
final fb.Builder fbBuilder;
|
||||||
|
|
||||||
void begin() {
|
void begin() {
|
||||||
fbBuilder.startTable();
|
fbBuilder.startTable(2);
|
||||||
}
|
}
|
||||||
|
|
||||||
int addNameOffset(int offset) {
|
int addNameOffset(int? offset) {
|
||||||
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;
|
||||||
}
|
}
|
||||||
@@ -405,36 +392,32 @@ class WeaponBuilder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class WeaponObjectBuilder extends fb.ObjectBuilder {
|
class WeaponObjectBuilder extends fb.ObjectBuilder {
|
||||||
final String _name;
|
final String? _name;
|
||||||
final int _damage;
|
final int? _damage;
|
||||||
|
|
||||||
WeaponObjectBuilder({
|
WeaponObjectBuilder({
|
||||||
String name,
|
String? name,
|
||||||
int damage,
|
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(
|
int finish(fb.Builder fbBuilder) {
|
||||||
fb.Builder fbBuilder) {
|
final int? nameOffset = _name == null ? null
|
||||||
assert(fbBuilder != null);
|
: fbBuilder.writeString(_name!);
|
||||||
final int nameOffset = fbBuilder.writeString(_name);
|
fbBuilder.startTable(2);
|
||||||
|
fbBuilder.addOffset(0, nameOffset);
|
||||||
fbBuilder.startTable();
|
|
||||||
if (nameOffset != null) {
|
|
||||||
fbBuilder.addOffset(0, nameOffset);
|
|
||||||
}
|
|
||||||
fbBuilder.addInt16(1, _damage);
|
fbBuilder.addInt16(1, _damage);
|
||||||
return fbBuilder.endTable();
|
return fbBuilder.endTable();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Convenience method to serialize to byte list.
|
/// Convenience method to serialize to byte list.
|
||||||
@override
|
@override
|
||||||
Uint8List toBytes([String fileIdentifier]) {
|
Uint8List toBytes([String? fileIdentifier]) {
|
||||||
fb.Builder fbBuilder = new fb.Builder();
|
final fbBuilder = fb.Builder(deduplicateTables: false);
|
||||||
int offset = finish(fbBuilder);
|
fbBuilder.finish(finish(fbBuilder), fileIdentifier);
|
||||||
return fbBuilder.finish(offset, fileIdentifier);
|
return fbBuilder.buffer;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -5,38 +5,27 @@ 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 {
|
||||||
ByteData _buffer;
|
final ByteData _buffer;
|
||||||
List<_StackValue> _stack;
|
List<_StackValue> _stack = [];
|
||||||
List<_StackPointer> _stackPointers;
|
List<_StackPointer> _stackPointers = [];
|
||||||
int _offset;
|
int _offset = 0;
|
||||||
bool _finished;
|
bool _finished = false;
|
||||||
Map<String, _StackValue> _stringCache;
|
final Map<String, _StackValue> _stringCache = {};
|
||||||
Map<String, _StackValue> _keyCache;
|
final Map<String, _StackValue> _keyCache = {};
|
||||||
Map<_KeysHash, _StackValue> _keyVectorCache;
|
final Map<_KeysHash, _StackValue> _keyVectorCache = {};
|
||||||
Map<int, _StackValue> _indirectIntCache;
|
final Map<int, _StackValue> _indirectIntCache = {};
|
||||||
Map<double, _StackValue> _indirectDoubleCache;
|
final Map<double, _StackValue> _indirectDoubleCache = {};
|
||||||
|
|
||||||
/// Instantiate the builder if you intent to gradually build up the buffer by calling
|
/// Instantiate the builder if you intent to gradually build up the buffer by calling
|
||||||
/// add... methods and calling [finish] to receive the the resulting byte array.
|
/// add... methods and calling [finish] to receive the the resulting byte array.
|
||||||
///
|
///
|
||||||
/// The default size of internal buffer is set to 2048. Provide a different value in order to avoid buffer copies.
|
/// The default size of internal buffer is set to 2048. Provide a different value in order to avoid buffer copies.
|
||||||
Builder({int size = 2048}) {
|
Builder({int size = 2048}) : _buffer = ByteData(size);
|
||||||
_buffer = ByteData(size);
|
|
||||||
_stack = [];
|
|
||||||
_stackPointers = [];
|
|
||||||
_offset = 0;
|
|
||||||
_finished = false;
|
|
||||||
_stringCache = {};
|
|
||||||
_keyCache = {};
|
|
||||||
_keyVectorCache = {};
|
|
||||||
_indirectIntCache = {};
|
|
||||||
_indirectDoubleCache = {};
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Use this method in order to turn an object into a FlexBuffer directly.
|
/// Use this method in order to turn an object into a FlexBuffer directly.
|
||||||
///
|
///
|
||||||
/// Use the manual instantiation of the [Builder] and gradual addition of values, if performance is more important than convenience.
|
/// Use the manual instantiation of the [Builder] and gradual addition of values, if performance is more important than convenience.
|
||||||
static ByteBuffer buildFromObject(Object value) {
|
static ByteBuffer buildFromObject(Object? value) {
|
||||||
final builder = Builder();
|
final builder = Builder();
|
||||||
builder._add(value);
|
builder._add(value);
|
||||||
final buffer = builder.finish();
|
final buffer = builder.finish();
|
||||||
@@ -45,7 +34,7 @@ class Builder {
|
|||||||
return byteData.buffer;
|
return byteData.buffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
void _add(Object value) {
|
void _add(Object? value) {
|
||||||
if (value == null) {
|
if (value == null) {
|
||||||
addNull();
|
addNull();
|
||||||
} else if (value is bool) {
|
} else if (value is bool) {
|
||||||
@@ -81,32 +70,32 @@ class Builder {
|
|||||||
/// Specifically useful when building up a vector where values can be null.
|
/// Specifically useful when building up a vector where values can be null.
|
||||||
void addNull() {
|
void addNull() {
|
||||||
_integrityCheckOnValueAddition();
|
_integrityCheckOnValueAddition();
|
||||||
_stack.add(_StackValue.WithNull());
|
_stack.add(_StackValue.withNull());
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Adds a string value.
|
/// Adds a string value.
|
||||||
void addInt(int value) {
|
void addInt(int value) {
|
||||||
_integrityCheckOnValueAddition();
|
_integrityCheckOnValueAddition();
|
||||||
_stack.add(_StackValue.WithInt(value));
|
_stack.add(_StackValue.withInt(value));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Adds a bool value.
|
/// Adds a bool value.
|
||||||
void addBool(bool value) {
|
void addBool(bool value) {
|
||||||
_integrityCheckOnValueAddition();
|
_integrityCheckOnValueAddition();
|
||||||
_stack.add(_StackValue.WithBool(value));
|
_stack.add(_StackValue.withBool(value));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Adds a double value.
|
/// Adds a double value.
|
||||||
void addDouble(double value) {
|
void addDouble(double value) {
|
||||||
_integrityCheckOnValueAddition();
|
_integrityCheckOnValueAddition();
|
||||||
_stack.add(_StackValue.WithDouble(value));
|
_stack.add(_StackValue.withDouble(value));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Adds a string value.
|
/// Adds a string value.
|
||||||
void addString(String value) {
|
void addString(String value) {
|
||||||
_integrityCheckOnValueAddition();
|
_integrityCheckOnValueAddition();
|
||||||
if (_stringCache.containsKey(value)) {
|
if (_stringCache.containsKey(value)) {
|
||||||
_stack.add(_stringCache[value]);
|
_stack.add(_stringCache[value]!);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
final utf8String = utf8.encode(value);
|
final utf8String = utf8.encode(value);
|
||||||
@@ -118,7 +107,8 @@ class Builder {
|
|||||||
final newOffset = _newOffset(length + 1);
|
final newOffset = _newOffset(length + 1);
|
||||||
_pushBuffer(utf8String);
|
_pushBuffer(utf8String);
|
||||||
_offset = newOffset;
|
_offset = newOffset;
|
||||||
final stackValue = _StackValue.WithOffset(stringOffset, ValueType.String, bitWidth);
|
final stackValue =
|
||||||
|
_StackValue.withOffset(stringOffset, ValueType.String, bitWidth);
|
||||||
_stack.add(stackValue);
|
_stack.add(stackValue);
|
||||||
_stringCache[value] = stackValue;
|
_stringCache[value] = stackValue;
|
||||||
}
|
}
|
||||||
@@ -129,7 +119,7 @@ class Builder {
|
|||||||
void addKey(String value) {
|
void addKey(String value) {
|
||||||
_integrityCheckOnKeyAddition();
|
_integrityCheckOnKeyAddition();
|
||||||
if (_keyCache.containsKey(value)) {
|
if (_keyCache.containsKey(value)) {
|
||||||
_stack.add(_keyCache[value]);
|
_stack.add(_keyCache[value]!);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
final utf8String = utf8.encode(value);
|
final utf8String = utf8.encode(value);
|
||||||
@@ -138,7 +128,8 @@ class Builder {
|
|||||||
final newOffset = _newOffset(length + 1);
|
final newOffset = _newOffset(length + 1);
|
||||||
_pushBuffer(utf8String);
|
_pushBuffer(utf8String);
|
||||||
_offset = newOffset;
|
_offset = newOffset;
|
||||||
final stackValue = _StackValue.WithOffset(keyOffset, ValueType.Key, BitWidth.width8);
|
final stackValue =
|
||||||
|
_StackValue.withOffset(keyOffset, ValueType.Key, BitWidth.width8);
|
||||||
_stack.add(stackValue);
|
_stack.add(stackValue);
|
||||||
_keyCache[value] = stackValue;
|
_keyCache[value] = stackValue;
|
||||||
}
|
}
|
||||||
@@ -156,7 +147,8 @@ class Builder {
|
|||||||
final newOffset = _newOffset(length);
|
final newOffset = _newOffset(length);
|
||||||
_pushBuffer(value.asUint8List());
|
_pushBuffer(value.asUint8List());
|
||||||
_offset = newOffset;
|
_offset = newOffset;
|
||||||
final stackValue = _StackValue.WithOffset(blobOffset, ValueType.Blob, bitWidth);
|
final stackValue =
|
||||||
|
_StackValue.withOffset(blobOffset, ValueType.Blob, bitWidth);
|
||||||
_stack.add(stackValue);
|
_stack.add(stackValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -169,15 +161,16 @@ class Builder {
|
|||||||
void addIntIndirectly(int value, {bool cache = false}) {
|
void addIntIndirectly(int value, {bool cache = false}) {
|
||||||
_integrityCheckOnValueAddition();
|
_integrityCheckOnValueAddition();
|
||||||
if (_indirectIntCache.containsKey(value)) {
|
if (_indirectIntCache.containsKey(value)) {
|
||||||
_stack.add(_indirectIntCache[value]);
|
_stack.add(_indirectIntCache[value]!);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
final stackValue = _StackValue.WithInt(value);
|
final stackValue = _StackValue.withInt(value);
|
||||||
final byteWidth = _align(stackValue.width);
|
final byteWidth = _align(stackValue.width);
|
||||||
final newOffset = _newOffset(byteWidth);
|
final newOffset = _newOffset(byteWidth);
|
||||||
final valueOffset = _offset;
|
final valueOffset = _offset;
|
||||||
_pushBuffer(stackValue.asU8List(stackValue.width));
|
_pushBuffer(stackValue.asU8List(stackValue.width));
|
||||||
final stackOffset = _StackValue.WithOffset(valueOffset, ValueType.IndirectInt, stackValue.width);
|
final stackOffset = _StackValue.withOffset(
|
||||||
|
valueOffset, ValueType.IndirectInt, stackValue.width);
|
||||||
_stack.add(stackOffset);
|
_stack.add(stackOffset);
|
||||||
_offset = newOffset;
|
_offset = newOffset;
|
||||||
if (cache) {
|
if (cache) {
|
||||||
@@ -193,15 +186,16 @@ class Builder {
|
|||||||
void addDoubleIndirectly(double value, {bool cache = false}) {
|
void addDoubleIndirectly(double value, {bool cache = false}) {
|
||||||
_integrityCheckOnValueAddition();
|
_integrityCheckOnValueAddition();
|
||||||
if (cache && _indirectDoubleCache.containsKey(value)) {
|
if (cache && _indirectDoubleCache.containsKey(value)) {
|
||||||
_stack.add(_indirectDoubleCache[value]);
|
_stack.add(_indirectDoubleCache[value]!);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
final stackValue = _StackValue.WithDouble(value);
|
final stackValue = _StackValue.withDouble(value);
|
||||||
final byteWidth = _align(stackValue.width);
|
final byteWidth = _align(stackValue.width);
|
||||||
final newOffset = _newOffset(byteWidth);
|
final newOffset = _newOffset(byteWidth);
|
||||||
final valueOffset = _offset;
|
final valueOffset = _offset;
|
||||||
_pushBuffer(stackValue.asU8List(stackValue.width));
|
_pushBuffer(stackValue.asU8List(stackValue.width));
|
||||||
final stackOffset = _StackValue.WithOffset(valueOffset, ValueType.IndirectFloat, stackValue.width);
|
final stackOffset = _StackValue.withOffset(
|
||||||
|
valueOffset, ValueType.IndirectFloat, stackValue.width);
|
||||||
_stack.add(stackOffset);
|
_stack.add(stackOffset);
|
||||||
_offset = newOffset;
|
_offset = newOffset;
|
||||||
if (cache) {
|
if (cache) {
|
||||||
@@ -258,8 +252,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.asUint8List().setAll(0, _buffer.buffer.asUint8List(0, _offset));
|
tmp._buffer.buffer
|
||||||
for (var i = 0; i < tmp._stackPointers.length; i++){
|
.asUint8List()
|
||||||
|
.setAll(0, _buffer.buffer.asUint8List(0, _offset));
|
||||||
|
for (var i = 0; i < tmp._stackPointers.length; i++) {
|
||||||
tmp.end();
|
tmp.end();
|
||||||
}
|
}
|
||||||
final buffer = tmp.finish();
|
final buffer = tmp.finish();
|
||||||
@@ -274,7 +270,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('Adding value to a map before adding a key is prohibited');
|
throw StateError(
|
||||||
|
'Adding value to a map before adding a key is prohibited');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -290,7 +287,8 @@ class Builder {
|
|||||||
|
|
||||||
void _finish() {
|
void _finish() {
|
||||||
if (_stack.length != 1) {
|
if (_stack.length != 1) {
|
||||||
throw StateError('Stack has to be exactly 1, but is ${_stack.length}. You have to end all started vectors and maps, before calling [finish]');
|
throw StateError(
|
||||||
|
'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));
|
||||||
@@ -300,7 +298,8 @@ class Builder {
|
|||||||
_finished = true;
|
_finished = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
_StackValue _createVector(int start, int vecLength, int step, [_StackValue keys]) {
|
_StackValue _createVector(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) {
|
||||||
@@ -327,7 +326,9 @@ class Builder {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
final byteWidth = _align(bitWidth);
|
final byteWidth = _align(bitWidth);
|
||||||
final fix = typed & ValueTypeUtils.isNumber(vectorType) && vecLength >= 2 && vecLength <= 4;
|
final fix = typed & ValueTypeUtils.isNumber(vectorType) &&
|
||||||
|
vecLength >= 2 &&
|
||||||
|
vecLength <= 4;
|
||||||
if (keys != null) {
|
if (keys != null) {
|
||||||
_writeStackValue(keys, byteWidth);
|
_writeStackValue(keys, byteWidth);
|
||||||
_writeUInt(1 << keys.width.index, byteWidth);
|
_writeUInt(1 << keys.width.index, byteWidth);
|
||||||
@@ -345,13 +346,14 @@ class Builder {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (keys != null) {
|
if (keys != null) {
|
||||||
return _StackValue.WithOffset(vecOffset, ValueType.Map, bitWidth);
|
return _StackValue.withOffset(vecOffset, ValueType.Map, bitWidth);
|
||||||
}
|
}
|
||||||
if (typed) {
|
if (typed) {
|
||||||
final vType = ValueTypeUtils.toTypedVector(vectorType, fix ? vecLength : 0);
|
final vType =
|
||||||
return _StackValue.WithOffset(vecOffset, vType, bitWidth);
|
ValueTypeUtils.toTypedVector(vectorType, fix ? vecLength : 0);
|
||||||
|
return _StackValue.withOffset(vecOffset, vType, bitWidth);
|
||||||
}
|
}
|
||||||
return _StackValue.WithOffset(vecOffset, ValueType.Vector, bitWidth);
|
return _StackValue.withOffset(vecOffset, ValueType.Vector, bitWidth);
|
||||||
}
|
}
|
||||||
|
|
||||||
void _endVector(_StackPointer pointer) {
|
void _endVector(_StackPointer pointer) {
|
||||||
@@ -363,12 +365,13 @@ 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('The stack needs to hold key value pairs (even number of elements). Check if you combined [addKey] with add... method calls properly.');
|
throw StateError(
|
||||||
|
'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;
|
||||||
for (var i = pointer.stackPosition; i < _stack.length - 2; i += 2) {
|
for (var i = pointer.stackPosition; i < _stack.length - 2; i += 2) {
|
||||||
if (_shouldFlip(_stack[i], _stack[i+2])) {
|
if (_shouldFlip(_stack[i], _stack[i + 2])) {
|
||||||
sorted = false;
|
sorted = false;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -399,31 +402,33 @@ class Builder {
|
|||||||
final vecLength = (_stack.length - pointer.stackPosition) >> 1;
|
final vecLength = (_stack.length - pointer.stackPosition) >> 1;
|
||||||
final offsets = <int>[];
|
final offsets = <int>[];
|
||||||
for (var i = pointer.stackPosition; i < _stack.length; i += 2) {
|
for (var i = pointer.stackPosition; i < _stack.length; i += 2) {
|
||||||
offsets.add(_stack[i].offset);
|
offsets.add(_stack[i].offset!);
|
||||||
}
|
}
|
||||||
final keysHash = _KeysHash(offsets);
|
final keysHash = _KeysHash(offsets);
|
||||||
var keysStackValue;
|
_StackValue? keysStackValue;
|
||||||
if (_keyVectorCache.containsKey(keysHash)) {
|
if (_keyVectorCache.containsKey(keysHash)) {
|
||||||
keysStackValue = _keyVectorCache[keysHash];
|
keysStackValue = _keyVectorCache[keysHash];
|
||||||
} else {
|
} else {
|
||||||
keysStackValue = _createVector(pointer.stackPosition, vecLength, 2);
|
keysStackValue = _createVector(pointer.stackPosition, vecLength, 2);
|
||||||
_keyVectorCache[keysHash] = keysStackValue;
|
_keyVectorCache[keysHash] = keysStackValue;
|
||||||
}
|
}
|
||||||
final vec = _createVector(pointer.stackPosition + 1, vecLength, 2, keysStackValue);
|
final vec =
|
||||||
|
_createVector(pointer.stackPosition + 1, vecLength, 2, keysStackValue);
|
||||||
_stack.removeRange(pointer.stackPosition, _stack.length);
|
_stack.removeRange(pointer.stackPosition, _stack.length);
|
||||||
_stack.add(vec);
|
_stack.add(vec);
|
||||||
}
|
}
|
||||||
|
|
||||||
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('Stack values are not keys $v1 | $v2. Check if you combined [addKey] with add... method calls properly.');
|
throw StateError(
|
||||||
|
'Stack values are not keys $v1 | $v2. Check if you combined [addKey] with add... method calls properly.');
|
||||||
}
|
}
|
||||||
|
|
||||||
var c1, c2;
|
late int c1, c2;
|
||||||
var index = 0;
|
var index = 0;
|
||||||
do {
|
do {
|
||||||
c1 = _buffer.getUint8(v1.offset + index);
|
c1 = _buffer.getUint8(v1.offset! + index);
|
||||||
c2 = _buffer.getUint8(v2.offset + index);
|
c2 = _buffer.getUint8(v2.offset! + index);
|
||||||
if (c2 < c1) return true;
|
if (c2 < c1) return true;
|
||||||
if (c1 < c2) return false;
|
if (c1 < c2) return false;
|
||||||
index += 1;
|
index += 1;
|
||||||
@@ -440,11 +445,12 @@ class Builder {
|
|||||||
void _writeStackValue(_StackValue value, int byteWidth) {
|
void _writeStackValue(_StackValue value, int byteWidth) {
|
||||||
final newOffset = _newOffset(byteWidth);
|
final newOffset = _newOffset(byteWidth);
|
||||||
if (value.isOffset) {
|
if (value.isOffset) {
|
||||||
final relativeOffset = _offset - value.offset;
|
final relativeOffset = _offset - value.offset!;
|
||||||
if (byteWidth == 8 || relativeOffset < (1 << (byteWidth * 8))) {
|
if (byteWidth == 8 || relativeOffset < (1 << (byteWidth * 8))) {
|
||||||
_writeUInt(relativeOffset, byteWidth);
|
_writeUInt(relativeOffset, byteWidth);
|
||||||
} else {
|
} else {
|
||||||
throw StateError('Unexpected size $byteWidth. This might be a bug. Please create an issue https://github.com/google/flatbuffers/issues/new');
|
throw StateError(
|
||||||
|
'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)));
|
||||||
@@ -467,16 +473,13 @@ class Builder {
|
|||||||
}
|
}
|
||||||
if (prevSize < size) {
|
if (prevSize < size) {
|
||||||
final newBuf = ByteData(size);
|
final newBuf = ByteData(size);
|
||||||
newBuf.buffer
|
newBuf.buffer.asUint8List().setAll(0, _buffer.buffer.asUint8List());
|
||||||
.asUint8List()
|
|
||||||
.setAll(0, _buffer.buffer.asUint8List());
|
|
||||||
}
|
}
|
||||||
return newOffset;
|
return newOffset;
|
||||||
}
|
}
|
||||||
|
|
||||||
void _pushInt(int value, BitWidth width) {
|
void _pushInt(int value, BitWidth width) {
|
||||||
switch (width) {
|
switch (width) {
|
||||||
|
|
||||||
case BitWidth.width8:
|
case BitWidth.width8:
|
||||||
_buffer.setInt8(_offset, value);
|
_buffer.setInt8(_offset, value);
|
||||||
break;
|
break;
|
||||||
@@ -494,7 +497,6 @@ class Builder {
|
|||||||
|
|
||||||
void _pushUInt(int value, BitWidth width) {
|
void _pushUInt(int value, BitWidth width) {
|
||||||
switch (width) {
|
switch (width) {
|
||||||
|
|
||||||
case BitWidth.width8:
|
case BitWidth.width8:
|
||||||
_buffer.setUint8(_offset, value);
|
_buffer.setUint8(_offset, value);
|
||||||
break;
|
break;
|
||||||
@@ -516,37 +518,39 @@ class Builder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class _StackValue {
|
class _StackValue {
|
||||||
Object _value;
|
late Object _value;
|
||||||
int _offset;
|
int? _offset;
|
||||||
ValueType _type;
|
final ValueType _type;
|
||||||
BitWidth _width;
|
final BitWidth _width;
|
||||||
_StackValue.WithNull() {
|
|
||||||
_type = ValueType.Null;
|
_StackValue.withNull()
|
||||||
_width = BitWidth.width8;
|
: _type = ValueType.Null,
|
||||||
}
|
_width = BitWidth.width8;
|
||||||
_StackValue.WithInt(int value) {
|
|
||||||
_type = value != null ? ValueType.Int : ValueType.Null;
|
_StackValue.withInt(int value)
|
||||||
_width = BitWidthUtil.width(value);
|
: _type = ValueType.Int,
|
||||||
_value = value;
|
_width = BitWidthUtil.width(value),
|
||||||
}
|
_value = value;
|
||||||
_StackValue.WithBool(bool value) {
|
|
||||||
_type = value != null ? ValueType.Bool : ValueType.Null;
|
_StackValue.withBool(bool value)
|
||||||
_width = BitWidth.width8;
|
: _type = ValueType.Bool,
|
||||||
_value = value;
|
_width = BitWidth.width8,
|
||||||
}
|
_value = value;
|
||||||
_StackValue.WithDouble(double value) {
|
|
||||||
_type = value != null ? ValueType.Float : ValueType.Null;
|
_StackValue.withDouble(double value)
|
||||||
_width = BitWidthUtil.width(value);
|
: _type = ValueType.Float,
|
||||||
_value = value;
|
_width = BitWidthUtil.width(value),
|
||||||
}
|
_value = value;
|
||||||
_StackValue.WithOffset(int value, ValueType type, BitWidth width) {
|
|
||||||
_offset = value;
|
_StackValue.withOffset(int value, ValueType type, BitWidth width)
|
||||||
_type = type;
|
: _offset = value,
|
||||||
_width = width;
|
_type = type,
|
||||||
}
|
_width = width;
|
||||||
|
|
||||||
BitWidth storedWidth({BitWidth width = BitWidth.width8}) {
|
BitWidth storedWidth({BitWidth width = BitWidth.width8}) {
|
||||||
return ValueTypeUtils.isInline(_type) ? BitWidthUtil.max(_width, width) : _width;
|
return ValueTypeUtils.isInline(_type)
|
||||||
|
? BitWidthUtil.max(_width, width)
|
||||||
|
: _width;
|
||||||
}
|
}
|
||||||
|
|
||||||
int storedPackedType({BitWidth width = BitWidth.width8}) {
|
int storedPackedType({BitWidth width = BitWidth.width8}) {
|
||||||
@@ -555,16 +559,19 @@ class _StackValue {
|
|||||||
|
|
||||||
BitWidth elementWidth(int size, int index) {
|
BitWidth elementWidth(int size, int index) {
|
||||||
if (ValueTypeUtils.isInline(_type)) return _width;
|
if (ValueTypeUtils.isInline(_type)) return _width;
|
||||||
for(var i = 0; i < 4; i++) {
|
final offset = _offset!;
|
||||||
|
for (var i = 0; i < 4; i++) {
|
||||||
final width = 1 << i;
|
final width = 1 << i;
|
||||||
final offsetLoc = size + BitWidthUtil.paddingSize(size, width) + index * width;
|
final bitWidth = BitWidthUtil.uwidth(size +
|
||||||
final offset = offsetLoc - _offset;
|
BitWidthUtil.paddingSize(size, width) +
|
||||||
final bitWidth = BitWidthUtil.uwidth(offset);
|
index * width -
|
||||||
|
offset);
|
||||||
if (1 << bitWidth.index == width) {
|
if (1 << bitWidth.index == width) {
|
||||||
return bitWidth;
|
return bitWidth;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
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');
|
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');
|
||||||
}
|
}
|
||||||
|
|
||||||
List<int> asU8List(BitWidth width) {
|
List<int> asU8List(BitWidth width) {
|
||||||
@@ -572,30 +579,30 @@ class _StackValue {
|
|||||||
if (_type == ValueType.Float) {
|
if (_type == ValueType.Float) {
|
||||||
if (width == BitWidth.width32) {
|
if (width == BitWidth.width32) {
|
||||||
final result = ByteData(4);
|
final result = ByteData(4);
|
||||||
result.setFloat32(0, _value, Endian.little);
|
result.setFloat32(0, _value as double, Endian.little);
|
||||||
return result.buffer.asUint8List();
|
return result.buffer.asUint8List();
|
||||||
} else {
|
} else {
|
||||||
final result = ByteData(8);
|
final result = ByteData(8);
|
||||||
result.setFloat64(0, _value, Endian.little);
|
result.setFloat64(0, _value as double, Endian.little);
|
||||||
return result.buffer.asUint8List();
|
return result.buffer.asUint8List();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
switch(width) {
|
switch (width) {
|
||||||
case BitWidth.width8:
|
case BitWidth.width8:
|
||||||
final result = ByteData(1);
|
final result = ByteData(1);
|
||||||
result.setInt8(0, _value);
|
result.setInt8(0, _value as int);
|
||||||
return result.buffer.asUint8List();
|
return result.buffer.asUint8List();
|
||||||
case BitWidth.width16:
|
case BitWidth.width16:
|
||||||
final result = ByteData(2);
|
final result = ByteData(2);
|
||||||
result.setInt16(0, _value, Endian.little);
|
result.setInt16(0, _value as int, Endian.little);
|
||||||
return result.buffer.asUint8List();
|
return result.buffer.asUint8List();
|
||||||
case BitWidth.width32:
|
case BitWidth.width32:
|
||||||
final result = ByteData(4);
|
final result = ByteData(4);
|
||||||
result.setInt32(0, _value, Endian.little);
|
result.setInt32(0, _value as int, Endian.little);
|
||||||
return result.buffer.asUint8List();
|
return result.buffer.asUint8List();
|
||||||
case BitWidth.width64:
|
case BitWidth.width64:
|
||||||
final result = ByteData(8);
|
final result = ByteData(8);
|
||||||
result.setInt64(0, _value, Endian.little);
|
result.setInt64(0, _value as int, Endian.little);
|
||||||
return result.buffer.asUint8List();
|
return result.buffer.asUint8List();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -607,11 +614,12 @@ class _StackValue {
|
|||||||
}
|
}
|
||||||
if (_type == ValueType.Bool) {
|
if (_type == ValueType.Bool) {
|
||||||
final result = ByteData(1);
|
final result = ByteData(1);
|
||||||
result.setInt8(0, _value ? 1 : 0);
|
result.setInt8(0, _value as bool ? 1 : 0);
|
||||||
return result.buffer.asUint8List();
|
return result.buffer.asUint8List();
|
||||||
}
|
}
|
||||||
|
|
||||||
throw StateError('Unexpected type: $_type. This might be a bug. Please create an issue https://github.com/google/flatbuffers/issues/new');
|
throw StateError(
|
||||||
|
'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 {
|
||||||
@@ -625,7 +633,8 @@ class _StackValue {
|
|||||||
bool get isOffset {
|
bool get isOffset {
|
||||||
return !ValueTypeUtils.isInline(_type);
|
return !ValueTypeUtils.isInline(_type);
|
||||||
}
|
}
|
||||||
int get offset => _offset;
|
|
||||||
|
int? get offset => _offset;
|
||||||
|
|
||||||
bool get isFloat32 {
|
bool get isFloat32 {
|
||||||
return _type == ValueType.Float && _width == BitWidth.width32;
|
return _type == ValueType.Float && _width == BitWidth.width32;
|
||||||
@@ -635,6 +644,7 @@ class _StackValue {
|
|||||||
class _StackPointer {
|
class _StackPointer {
|
||||||
int stackPosition;
|
int stackPosition;
|
||||||
bool isVector;
|
bool isVector;
|
||||||
|
|
||||||
_StackPointer(this.stackPosition, this.isVector);
|
_StackPointer(this.stackPosition, this.isVector);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -11,14 +11,15 @@ class Reference {
|
|||||||
final int _offset;
|
final int _offset;
|
||||||
final BitWidth _parentWidth;
|
final BitWidth _parentWidth;
|
||||||
final String _path;
|
final String _path;
|
||||||
int _byteWidth;
|
final int _byteWidth;
|
||||||
ValueType _valueType;
|
final ValueType _valueType;
|
||||||
int _length;
|
int? _length;
|
||||||
|
|
||||||
Reference._(this._buffer, this._offset, this._parentWidth, int packedType, this._path) {
|
Reference._(
|
||||||
_byteWidth = 1 << (packedType & 3);
|
this._buffer, this._offset, this._parentWidth, int packedType, this._path,
|
||||||
_valueType = ValueTypeUtils.fromInt(packedType >> 2);
|
[int? byteWidth, ValueType? valueType])
|
||||||
}
|
: _byteWidth = byteWidth ?? 1 << (packedType & 3),
|
||||||
|
_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.
|
||||||
static Reference fromBuffer(ByteBuffer buffer) {
|
static Reference fromBuffer(ByteBuffer buffer) {
|
||||||
@@ -30,31 +31,44 @@ 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, BitWidthUtil.fromByteWidth(byteWidth), packedType, "/");
|
return Reference._(ByteData.view(buffer), offset,
|
||||||
|
BitWidthUtil.fromByteWidth(byteWidth), packedType, "/");
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns true if the underlying value is null.
|
/// Returns true if the underlying value is null.
|
||||||
bool get isNull => _valueType == ValueType.Null;
|
bool get isNull => _valueType == ValueType.Null;
|
||||||
|
|
||||||
/// Returns true if the underlying value can be represented as [num].
|
/// Returns true if the underlying value can be represented as [num].
|
||||||
bool get isNum => ValueTypeUtils.isNumber(_valueType) || ValueTypeUtils.isIndirectNumber(_valueType);
|
bool get isNum =>
|
||||||
|
ValueTypeUtils.isNumber(_valueType) ||
|
||||||
|
ValueTypeUtils.isIndirectNumber(_valueType);
|
||||||
|
|
||||||
/// Returns true if the underlying value was encoded as a float (direct or indirect).
|
/// Returns true if the underlying value was encoded as a float (direct or indirect).
|
||||||
bool get isDouble => _valueType == ValueType.Float || _valueType == ValueType.IndirectFloat;
|
bool get isDouble =>
|
||||||
|
_valueType == ValueType.Float || _valueType == ValueType.IndirectFloat;
|
||||||
|
|
||||||
/// Returns true if the underlying value was encoded as an int or uint (direct or indirect).
|
/// Returns true if the underlying value was encoded as an int or uint (direct or indirect).
|
||||||
bool get isInt => isNum && !isDouble;
|
bool get isInt => isNum && !isDouble;
|
||||||
|
|
||||||
/// Returns true if the underlying value was encoded as a string or a key.
|
/// Returns true if the underlying value was encoded as a string or a key.
|
||||||
bool get isString => _valueType == ValueType.String || _valueType == ValueType.Key;
|
bool get isString =>
|
||||||
|
_valueType == ValueType.String || _valueType == ValueType.Key;
|
||||||
|
|
||||||
/// Returns true if the underlying value was encoded as a bool.
|
/// Returns true if the underlying value was encoded as a bool.
|
||||||
bool get isBool => _valueType == ValueType.Bool;
|
bool get isBool => _valueType == ValueType.Bool;
|
||||||
|
|
||||||
/// Returns true if the underlying value was encoded as a blob.
|
/// Returns true if the underlying value was encoded as a blob.
|
||||||
bool get isBlob => _valueType == ValueType.Blob;
|
bool get isBlob => _valueType == ValueType.Blob;
|
||||||
|
|
||||||
/// Returns true if the underlying value points to a vector.
|
/// Returns true if the underlying value points to a vector.
|
||||||
bool get isVector => ValueTypeUtils.isAVector(_valueType);
|
bool get isVector => ValueTypeUtils.isAVector(_valueType);
|
||||||
|
|
||||||
/// Returns true if the underlying value points to a map.
|
/// Returns true if the underlying value points to a map.
|
||||||
bool get isMap => _valueType == ValueType.Map;
|
bool get isMap => _valueType == ValueType.Map;
|
||||||
|
|
||||||
/// If this [isBool], returns the bool value. Otherwise, returns null.
|
/// If this [isBool], returns the bool value. Otherwise, returns null.
|
||||||
bool get boolValue {
|
bool? get boolValue {
|
||||||
if(_valueType == ValueType.Bool) {
|
if (_valueType == ValueType.Bool) {
|
||||||
return _readInt(_offset, _parentWidth) != 0;
|
return _readInt(_offset, _parentWidth) != 0;
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
@@ -63,7 +77,7 @@ class Reference {
|
|||||||
/// Returns an [int], if the underlying value can be represented as an int.
|
/// Returns an [int], if the underlying value can be represented as an int.
|
||||||
///
|
///
|
||||||
/// Otherwise returns [null].
|
/// Otherwise returns [null].
|
||||||
int get intValue {
|
int? get intValue {
|
||||||
if (_valueType == ValueType.Int) {
|
if (_valueType == ValueType.Int) {
|
||||||
return _readInt(_offset, _parentWidth);
|
return _readInt(_offset, _parentWidth);
|
||||||
}
|
}
|
||||||
@@ -82,7 +96,7 @@ class Reference {
|
|||||||
/// Returns [double], if the underlying value [isDouble].
|
/// Returns [double], if the underlying value [isDouble].
|
||||||
///
|
///
|
||||||
/// Otherwise returns [null].
|
/// Otherwise returns [null].
|
||||||
double get doubleValue {
|
double? get doubleValue {
|
||||||
if (_valueType == ValueType.Float) {
|
if (_valueType == ValueType.Float) {
|
||||||
return _readFloat(_offset, _parentWidth);
|
return _readFloat(_offset, _parentWidth);
|
||||||
}
|
}
|
||||||
@@ -95,12 +109,12 @@ class Reference {
|
|||||||
/// Returns [num], if the underlying value is numeric, be it int uint, or float (direct or indirect).
|
/// Returns [num], if the underlying value is numeric, be it int uint, or float (direct or indirect).
|
||||||
///
|
///
|
||||||
/// Otherwise returns [null].
|
/// Otherwise returns [null].
|
||||||
num get numValue => doubleValue ?? intValue;
|
num? get numValue => doubleValue ?? intValue;
|
||||||
|
|
||||||
/// Returns [String] value or null otherwise.
|
/// Returns [String] value or null otherwise.
|
||||||
///
|
///
|
||||||
/// This method performers a utf8 decoding, as FlexBuffers format stores strings in utf8 encoding.
|
/// This method performers a utf8 decoding, as FlexBuffers format stores strings in utf8 encoding.
|
||||||
String get stringValue {
|
String? get stringValue {
|
||||||
if (_valueType == ValueType.String || _valueType == ValueType.Key) {
|
if (_valueType == ValueType.String || _valueType == ValueType.Key) {
|
||||||
return utf8.decode(_buffer.buffer.asUint8List(_indirect, length));
|
return utf8.decode(_buffer.buffer.asUint8List(_indirect, length));
|
||||||
}
|
}
|
||||||
@@ -108,7 +122,7 @@ class Reference {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Returns [Uint8List] value or null otherwise.
|
/// Returns [Uint8List] value or null otherwise.
|
||||||
Uint8List get blobValue {
|
Uint8List? get blobValue {
|
||||||
if (_valueType == ValueType.Blob) {
|
if (_valueType == ValueType.Blob) {
|
||||||
return _buffer.buffer.asUint8List(_indirect, length);
|
return _buffer.buffer.asUint8List(_indirect, length);
|
||||||
}
|
}
|
||||||
@@ -122,22 +136,31 @@ class Reference {
|
|||||||
Reference operator [](Object key) {
|
Reference operator [](Object key) {
|
||||||
if (key is int && ValueTypeUtils.isAVector(_valueType)) {
|
if (key is int && ValueTypeUtils.isAVector(_valueType)) {
|
||||||
final index = key;
|
final index = key;
|
||||||
if(index >= length || index < 0) {
|
if (index >= length || index < 0) {
|
||||||
throw ArgumentError('Key: [$key] is not applicable on: $_path of: $_valueType length: $length');
|
throw ArgumentError(
|
||||||
|
'Key: [$key] is not applicable on: $_path of: $_valueType length: $length');
|
||||||
}
|
}
|
||||||
final elementOffset = _indirect + index * _byteWidth;
|
final elementOffset = _indirect + index * _byteWidth;
|
||||||
final reference = Reference._(_buffer, elementOffset, BitWidthUtil.fromByteWidth(_byteWidth), 0, "$_path[$index]");
|
int packedType = 0;
|
||||||
reference._byteWidth = 1;
|
int? byteWidth;
|
||||||
|
ValueType? valueType;
|
||||||
if (ValueTypeUtils.isTypedVector(_valueType)) {
|
if (ValueTypeUtils.isTypedVector(_valueType)) {
|
||||||
reference._valueType = ValueTypeUtils.typedVectorElementType(_valueType);
|
byteWidth = 1;
|
||||||
return reference;
|
valueType = ValueTypeUtils.typedVectorElementType(_valueType);
|
||||||
|
} else if (ValueTypeUtils.isFixedTypedVector(_valueType)) {
|
||||||
|
byteWidth = 1;
|
||||||
|
valueType = ValueTypeUtils.fixedTypedVectorElementType(_valueType);
|
||||||
|
} else {
|
||||||
|
packedType = _buffer.getUint8(_indirect + length * _byteWidth + index);
|
||||||
}
|
}
|
||||||
if(ValueTypeUtils.isFixedTypedVector(_valueType)) {
|
return Reference._(
|
||||||
reference._valueType = ValueTypeUtils.fixedTypedVectorElementType(_valueType);
|
_buffer,
|
||||||
return reference;
|
elementOffset,
|
||||||
}
|
BitWidthUtil.fromByteWidth(_byteWidth),
|
||||||
final packedType = _buffer.getUint8(_indirect + length * _byteWidth + index);
|
packedType,
|
||||||
return Reference._(_buffer, elementOffset, BitWidthUtil.fromByteWidth(_byteWidth), packedType, "$_path[$index]");
|
"$_path[$index]",
|
||||||
|
byteWidth,
|
||||||
|
valueType);
|
||||||
}
|
}
|
||||||
if (key is String && _valueType == ValueType.Map) {
|
if (key is String && _valueType == ValueType.Map) {
|
||||||
final index = _keyIndex(key);
|
final index = _keyIndex(key);
|
||||||
@@ -145,13 +168,14 @@ class Reference {
|
|||||||
return _valueForIndexWithKey(index, key);
|
return _valueForIndexWithKey(index, key);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
throw ArgumentError('Key: [$key] is not applicable on: $_path of: $_valueType');
|
throw ArgumentError(
|
||||||
|
'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.
|
||||||
/// Otherwise throws an exception.
|
/// Otherwise throws an exception.
|
||||||
Iterable<Reference> get vectorIterable {
|
Iterable<Reference> get vectorIterable {
|
||||||
if(isVector == false) {
|
if (isVector == false) {
|
||||||
throw UnsupportedError('Value is not a vector. It is: $_valueType');
|
throw UnsupportedError('Value is not a vector. It is: $_valueType');
|
||||||
}
|
}
|
||||||
return _VectorIterator(this);
|
return _VectorIterator(this);
|
||||||
@@ -160,7 +184,7 @@ class Reference {
|
|||||||
/// Get an iterable for keys if the underlying flexBuffer value is a map.
|
/// Get an iterable for keys if the underlying flexBuffer value is a map.
|
||||||
/// Otherwise throws an exception.
|
/// Otherwise throws an exception.
|
||||||
Iterable<String> get mapKeyIterable {
|
Iterable<String> get mapKeyIterable {
|
||||||
if(isMap == false) {
|
if (isMap == false) {
|
||||||
throw UnsupportedError('Value is not a map. It is: $_valueType');
|
throw UnsupportedError('Value is not a map. It is: $_valueType');
|
||||||
}
|
}
|
||||||
return _MapKeyIterator(this);
|
return _MapKeyIterator(this);
|
||||||
@@ -169,7 +193,7 @@ class Reference {
|
|||||||
/// Get an iterable for values if the underlying flexBuffer value is a map.
|
/// Get an iterable for values if the underlying flexBuffer value is a map.
|
||||||
/// Otherwise throws an exception.
|
/// Otherwise throws an exception.
|
||||||
Iterable<Reference> get mapValueIterable {
|
Iterable<Reference> get mapValueIterable {
|
||||||
if(isMap == false) {
|
if (isMap == false) {
|
||||||
throw UnsupportedError('Value is not a map. It is: $_valueType');
|
throw UnsupportedError('Value is not a map. It is: $_valueType');
|
||||||
}
|
}
|
||||||
return _MapValueIterator(this);
|
return _MapValueIterator(this);
|
||||||
@@ -181,59 +205,62 @@ class Reference {
|
|||||||
/// If the underlying value is a vector, or map, the length reflects number of elements / element pairs.
|
/// If the underlying value is a vector, or map, the length reflects number of elements / element pairs.
|
||||||
/// If the values is a string or a blob, the length reflects a number of bytes the value occupies (strings are encoded in utf8 format).
|
/// If the values is a string or a blob, the length reflects a number of bytes the value occupies (strings are encoded in utf8 format).
|
||||||
int get length {
|
int get length {
|
||||||
if (_length != null) {
|
if (_length == null) {
|
||||||
return _length;
|
// needs to be checked before more generic isAVector
|
||||||
}
|
if (ValueTypeUtils.isFixedTypedVector(_valueType)) {
|
||||||
// needs to be checked before more generic isAVector
|
_length = ValueTypeUtils.fixedTypedVectorElementSize(_valueType);
|
||||||
if(ValueTypeUtils.isFixedTypedVector(_valueType)) {
|
} else if (_valueType == ValueType.Blob ||
|
||||||
_length = ValueTypeUtils.fixedTypedVectorElementSize(_valueType);
|
ValueTypeUtils.isAVector(_valueType) ||
|
||||||
} else if(_valueType == ValueType.Blob || ValueTypeUtils.isAVector(_valueType) || _valueType == ValueType.Map){
|
_valueType == ValueType.Map) {
|
||||||
_length = _readUInt(_indirect - _byteWidth, BitWidthUtil.fromByteWidth(_byteWidth));
|
_length = _readUInt(
|
||||||
} else if (_valueType == ValueType.Null) {
|
_indirect - _byteWidth, BitWidthUtil.fromByteWidth(_byteWidth));
|
||||||
_length = 0;
|
} else if (_valueType == ValueType.Null) {
|
||||||
} else if (_valueType == ValueType.String) {
|
_length = 0;
|
||||||
final indirect = _indirect;
|
} else if (_valueType == ValueType.String) {
|
||||||
var size_byte_width = _byteWidth;
|
final indirect = _indirect;
|
||||||
var size = _readUInt(indirect - size_byte_width, BitWidthUtil.fromByteWidth(size_byte_width));
|
var sizeByteWidth = _byteWidth;
|
||||||
while (_buffer.getInt8(indirect + size) != 0) {
|
var size = _readUInt(indirect - sizeByteWidth,
|
||||||
size_byte_width <<= 1;
|
BitWidthUtil.fromByteWidth(sizeByteWidth));
|
||||||
size = _readUInt(indirect - size_byte_width, BitWidthUtil.fromByteWidth(size_byte_width));
|
while (_buffer.getInt8(indirect + size) != 0) {
|
||||||
|
sizeByteWidth <<= 1;
|
||||||
|
size = _readUInt(indirect - sizeByteWidth,
|
||||||
|
BitWidthUtil.fromByteWidth(sizeByteWidth));
|
||||||
|
}
|
||||||
|
_length = size;
|
||||||
|
} else if (_valueType == ValueType.Key) {
|
||||||
|
final indirect = _indirect;
|
||||||
|
var size = 1;
|
||||||
|
while (_buffer.getInt8(indirect + size) != 0) {
|
||||||
|
size += 1;
|
||||||
|
}
|
||||||
|
_length = size;
|
||||||
|
} else {
|
||||||
|
_length = 1;
|
||||||
}
|
}
|
||||||
_length = size;
|
|
||||||
} else if (_valueType == ValueType.Key) {
|
|
||||||
final indirect = _indirect;
|
|
||||||
var size = 1;
|
|
||||||
while (_buffer.getInt8(indirect + size) != 0) {
|
|
||||||
size += 1;
|
|
||||||
}
|
|
||||||
_length = size;
|
|
||||||
} else {
|
|
||||||
_length = 1;
|
|
||||||
}
|
}
|
||||||
return _length;
|
return _length!;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// Returns a minified JSON representation of the underlying FlexBuffer value.
|
/// Returns a minified JSON representation of the underlying FlexBuffer value.
|
||||||
///
|
///
|
||||||
/// This method involves materializing the entire object tree, which may be
|
/// This method involves materializing the entire object tree, which may be
|
||||||
/// expensive. It is more efficient to work with [Reference] and access only the needed data.
|
/// expensive. It is more efficient to work with [Reference] and access only the needed data.
|
||||||
/// Blob values are represented as base64 encoded string.
|
/// Blob values are represented as base64 encoded string.
|
||||||
String get json {
|
String get json {
|
||||||
if(_valueType == ValueType.Bool) {
|
if (_valueType == ValueType.Bool) {
|
||||||
return boolValue ? 'true' : 'false';
|
return boolValue! ? 'true' : 'false';
|
||||||
}
|
}
|
||||||
if (_valueType == ValueType.Null) {
|
if (_valueType == ValueType.Null) {
|
||||||
return 'null';
|
return 'null';
|
||||||
}
|
}
|
||||||
if(ValueTypeUtils.isNumber(_valueType)) {
|
if (ValueTypeUtils.isNumber(_valueType)) {
|
||||||
return jsonEncode(numValue);
|
return jsonEncode(numValue);
|
||||||
}
|
}
|
||||||
if (_valueType == ValueType.String) {
|
if (_valueType == ValueType.String) {
|
||||||
return jsonEncode(stringValue);
|
return jsonEncode(stringValue);
|
||||||
}
|
}
|
||||||
if (_valueType == ValueType.Blob) {
|
if (_valueType == ValueType.Blob) {
|
||||||
return jsonEncode(base64Encode(blobValue));
|
return jsonEncode(base64Encode(blobValue!));
|
||||||
}
|
}
|
||||||
if (ValueTypeUtils.isAVector(_valueType)) {
|
if (ValueTypeUtils.isAVector(_valueType)) {
|
||||||
final result = StringBuffer();
|
final result = StringBuffer();
|
||||||
@@ -261,7 +288,8 @@ class Reference {
|
|||||||
result.write('}');
|
result.write('}');
|
||||||
return result.toString();
|
return result.toString();
|
||||||
}
|
}
|
||||||
throw UnsupportedError('Type: $_valueType is not supported for JSON conversion');
|
throw UnsupportedError(
|
||||||
|
'Type: $_valueType is not supported for JSON conversion');
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Computes the indirect offset of the value.
|
/// Computes the indirect offset of the value.
|
||||||
@@ -316,16 +344,20 @@ class Reference {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void _validateOffset(int offset, BitWidth width) {
|
void _validateOffset(int offset, BitWidth width) {
|
||||||
if (_offset < 0 || _buffer.lengthInBytes <= offset + width.index || offset & (BitWidthUtil.toByteWidth(width) - 1) != 0) {
|
if (_offset < 0 ||
|
||||||
|
_buffer.lengthInBytes <= offset + width.index ||
|
||||||
|
offset & (BitWidthUtil.toByteWidth(width) - 1) != 0) {
|
||||||
throw StateError('Bad offset: $offset, width: $width');
|
throw StateError('Bad offset: $offset, width: $width');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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 - _readUInt(keysVectorOffset, BitWidthUtil.fromByteWidth(_byteWidth));
|
final indirectOffset = keysVectorOffset -
|
||||||
final byteWidth = _readUInt(keysVectorOffset + _byteWidth, BitWidthUtil.fromByteWidth(_byteWidth));
|
_readUInt(keysVectorOffset, BitWidthUtil.fromByteWidth(_byteWidth));
|
||||||
|
final byteWidth = _readUInt(
|
||||||
|
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) {
|
||||||
@@ -341,9 +373,10 @@ class Reference {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
int _diffKeys(List<int> input, int index, int indirect_offset, int byteWidth) {
|
int _diffKeys(List<int> input, int index, int indirectOffset, int byteWidth) {
|
||||||
final keyOffset = indirect_offset + index * byteWidth;
|
final keyOffset = indirectOffset + index * byteWidth;
|
||||||
final keyIndirectOffset = keyOffset - _readUInt(keyOffset, BitWidthUtil.fromByteWidth(byteWidth));
|
final keyIndirectOffset =
|
||||||
|
keyOffset - _readUInt(keyOffset, BitWidthUtil.fromByteWidth(byteWidth));
|
||||||
for (var i = 0; i < input.length; i++) {
|
for (var i = 0; i < input.length; i++) {
|
||||||
final dif = input[i] - _buffer.getUint8(keyIndirectOffset + i);
|
final dif = input[i] - _buffer.getUint8(keyIndirectOffset + i);
|
||||||
if (dif != 0) {
|
if (dif != 0) {
|
||||||
@@ -357,38 +390,42 @@ 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, BitWidthUtil.fromByteWidth(_byteWidth), packedType, "$_path/$key");
|
return Reference._(_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, BitWidthUtil.fromByteWidth(_byteWidth), packedType, "$_path/[$index]");
|
return Reference._(_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 - _readUInt(keysVectorOffset, BitWidthUtil.fromByteWidth(_byteWidth));
|
final indirectOffset = keysVectorOffset -
|
||||||
final byteWidth = _readUInt(keysVectorOffset + _byteWidth, BitWidthUtil.fromByteWidth(_byteWidth));
|
_readUInt(keysVectorOffset, BitWidthUtil.fromByteWidth(_byteWidth));
|
||||||
|
final byteWidth = _readUInt(
|
||||||
|
keysVectorOffset + _byteWidth, BitWidthUtil.fromByteWidth(_byteWidth));
|
||||||
final keyOffset = indirectOffset + index * byteWidth;
|
final keyOffset = indirectOffset + index * byteWidth;
|
||||||
final keyIndirectOffset = keyOffset - _readUInt(keyOffset, BitWidthUtil.fromByteWidth(byteWidth));
|
final keyIndirectOffset =
|
||||||
|
keyOffset - _readUInt(keyOffset, BitWidthUtil.fromByteWidth(byteWidth));
|
||||||
var length = 0;
|
var length = 0;
|
||||||
while (_buffer.getUint8(keyIndirectOffset + length) != 0) {
|
while (_buffer.getUint8(keyIndirectOffset + length) != 0) {
|
||||||
length += 1;
|
length += 1;
|
||||||
}
|
}
|
||||||
return utf8.decode(_buffer.buffer.asUint8List(keyIndirectOffset, length));
|
return utf8.decode(_buffer.buffer.asUint8List(keyIndirectOffset, length));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class _VectorIterator with IterableMixin<Reference> implements Iterator<Reference> {
|
class _VectorIterator
|
||||||
|
with IterableMixin<Reference>
|
||||||
|
implements Iterator<Reference> {
|
||||||
final Reference _vector;
|
final Reference _vector;
|
||||||
int index;
|
int index = -1;
|
||||||
|
|
||||||
_VectorIterator(this._vector) {
|
_VectorIterator(this._vector);
|
||||||
index = -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Reference get current => _vector[index];
|
Reference get current => _vector[index];
|
||||||
@@ -405,11 +442,9 @@ class _VectorIterator with IterableMixin<Reference> implements Iterator<Referenc
|
|||||||
|
|
||||||
class _MapKeyIterator with IterableMixin<String> implements Iterator<String> {
|
class _MapKeyIterator with IterableMixin<String> implements Iterator<String> {
|
||||||
final Reference _map;
|
final Reference _map;
|
||||||
int index;
|
int index = -1;
|
||||||
|
|
||||||
_MapKeyIterator(this._map) {
|
_MapKeyIterator(this._map);
|
||||||
index = -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String get current => _map._keyForIndex(index);
|
String get current => _map._keyForIndex(index);
|
||||||
@@ -424,13 +459,13 @@ class _MapKeyIterator with IterableMixin<String> implements Iterator<String> {
|
|||||||
Iterator<String> get iterator => this;
|
Iterator<String> get iterator => this;
|
||||||
}
|
}
|
||||||
|
|
||||||
class _MapValueIterator with IterableMixin<Reference> implements Iterator<Reference> {
|
class _MapValueIterator
|
||||||
|
with IterableMixin<Reference>
|
||||||
|
implements Iterator<Reference> {
|
||||||
final Reference _map;
|
final Reference _map;
|
||||||
int index;
|
int index = -1;
|
||||||
|
|
||||||
_MapValueIterator(this._map) {
|
_MapValueIterator(this._map);
|
||||||
index = -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Reference get current => _map._valueForIndex(index);
|
Reference get current => _map._valueForIndex(index);
|
||||||
|
|||||||
@@ -1,17 +1,13 @@
|
|||||||
import 'dart:typed_data';
|
import 'dart:typed_data';
|
||||||
|
|
||||||
/// Represents the number of bits a value occupies.
|
/// Represents the number of bits a value occupies.
|
||||||
enum BitWidth {
|
enum BitWidth { width8, width16, width32, width64 }
|
||||||
width8,
|
|
||||||
width16,
|
|
||||||
width32,
|
|
||||||
width64
|
|
||||||
}
|
|
||||||
|
|
||||||
class BitWidthUtil {
|
class BitWidthUtil {
|
||||||
static int toByteWidth(BitWidth self) {
|
static int toByteWidth(BitWidth self) {
|
||||||
return 1 << self.index;
|
return 1 << self.index;
|
||||||
}
|
}
|
||||||
|
|
||||||
static BitWidth width(num value) {
|
static BitWidth width(num value) {
|
||||||
if (value.toInt() == value) {
|
if (value.toInt() == value) {
|
||||||
var v = value.toInt().abs();
|
var v = value.toInt().abs();
|
||||||
@@ -20,8 +16,11 @@ class BitWidthUtil {
|
|||||||
if (v >> 31 == 0) return BitWidth.width32;
|
if (v >> 31 == 0) return BitWidth.width32;
|
||||||
return BitWidth.width64;
|
return BitWidth.width64;
|
||||||
}
|
}
|
||||||
return value == _toF32(value) ? BitWidth.width32 : BitWidth.width64;
|
return value == _toF32(value as double)
|
||||||
|
? BitWidth.width32
|
||||||
|
: BitWidth.width64;
|
||||||
}
|
}
|
||||||
|
|
||||||
static BitWidth uwidth(num value) {
|
static BitWidth uwidth(num value) {
|
||||||
if (value.toInt() == value) {
|
if (value.toInt() == value) {
|
||||||
var v = value.toInt().abs();
|
var v = value.toInt().abs();
|
||||||
@@ -30,8 +29,11 @@ class BitWidthUtil {
|
|||||||
if (v >> 32 == 0) return BitWidth.width32;
|
if (v >> 32 == 0) return BitWidth.width32;
|
||||||
return BitWidth.width64;
|
return BitWidth.width64;
|
||||||
}
|
}
|
||||||
return value == _toF32(value) ? BitWidth.width32 : BitWidth.width64;
|
return value == _toF32(value as double)
|
||||||
|
? BitWidth.width32
|
||||||
|
: BitWidth.width64;
|
||||||
}
|
}
|
||||||
|
|
||||||
static BitWidth fromByteWidth(int value) {
|
static BitWidth fromByteWidth(int value) {
|
||||||
if (value == 1) {
|
if (value == 1) {
|
||||||
return BitWidth.width8;
|
return BitWidth.width8;
|
||||||
@@ -45,11 +47,13 @@ class BitWidthUtil {
|
|||||||
if (value == 8) {
|
if (value == 8) {
|
||||||
return BitWidth.width64;
|
return BitWidth.width64;
|
||||||
}
|
}
|
||||||
throw Exception('Unexpected value ${value}');
|
throw Exception('Unexpected value $value');
|
||||||
}
|
}
|
||||||
|
|
||||||
static int paddingSize(int bufSize, int scalarSize) {
|
static int paddingSize(int bufSize, int scalarSize) {
|
||||||
return (~bufSize + 1) & (scalarSize - 1);
|
return (~bufSize + 1) & (scalarSize - 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
static double _toF32(double value) {
|
static double _toF32(double value) {
|
||||||
var bdata = ByteData(4);
|
var bdata = ByteData(4);
|
||||||
bdata.setFloat32(0, value);
|
bdata.setFloat32(0, value);
|
||||||
@@ -66,15 +70,36 @@ class BitWidthUtil {
|
|||||||
|
|
||||||
/// Represents all internal FlexBuffer types.
|
/// Represents all internal FlexBuffer types.
|
||||||
enum ValueType {
|
enum ValueType {
|
||||||
Null, Int, UInt, Float,
|
Null,
|
||||||
Key, String, IndirectInt, IndirectUInt, IndirectFloat,
|
Int,
|
||||||
Map, Vector, VectorInt, VectorUInt, VectorFloat, VectorKey,
|
UInt,
|
||||||
@Deprecated('VectorString is deprecated due to a flaw in the binary format (https://github.com/google/flatbuffers/issues/5627)')
|
Float,
|
||||||
|
Key,
|
||||||
|
String,
|
||||||
|
IndirectInt,
|
||||||
|
IndirectUInt,
|
||||||
|
IndirectFloat,
|
||||||
|
Map,
|
||||||
|
Vector,
|
||||||
|
VectorInt,
|
||||||
|
VectorUInt,
|
||||||
|
VectorFloat,
|
||||||
|
VectorKey,
|
||||||
|
@Deprecated(
|
||||||
|
'VectorString is deprecated due to a flaw in the binary format (https://github.com/google/flatbuffers/issues/5627)')
|
||||||
VectorString,
|
VectorString,
|
||||||
VectorInt2, VectorUInt2, VectorFloat2,
|
VectorInt2,
|
||||||
VectorInt3, VectorUInt3, VectorFloat3,
|
VectorUInt2,
|
||||||
VectorInt4, VectorUInt4, VectorFloat4,
|
VectorFloat2,
|
||||||
Blob, Bool, VectorBool
|
VectorInt3,
|
||||||
|
VectorUInt3,
|
||||||
|
VectorFloat3,
|
||||||
|
VectorInt4,
|
||||||
|
VectorUInt4,
|
||||||
|
VectorFloat4,
|
||||||
|
Blob,
|
||||||
|
Bool,
|
||||||
|
VectorBool
|
||||||
}
|
}
|
||||||
|
|
||||||
class ValueTypeUtils {
|
class ValueTypeUtils {
|
||||||
@@ -89,71 +114,70 @@ class ValueTypeUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static bool isInline(ValueType self) {
|
static bool isInline(ValueType self) {
|
||||||
return self == ValueType.Bool
|
return self == ValueType.Bool || toInt(self) <= toInt(ValueType.Float);
|
||||||
|| toInt(self) <= toInt(ValueType.Float);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool isNumber(ValueType self) {
|
static bool isNumber(ValueType self) {
|
||||||
return toInt(self) >= toInt(ValueType.Int)
|
return toInt(self) >= toInt(ValueType.Int) &&
|
||||||
&& toInt(self) <= toInt(ValueType.Float);
|
toInt(self) <= toInt(ValueType.Float);
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool isIndirectNumber(ValueType self) {
|
static bool isIndirectNumber(ValueType self) {
|
||||||
return toInt(self) >= toInt(ValueType.IndirectInt)
|
return toInt(self) >= toInt(ValueType.IndirectInt) &&
|
||||||
&& toInt(self) <= toInt(ValueType.IndirectFloat);
|
toInt(self) <= toInt(ValueType.IndirectFloat);
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool isTypedVectorElement(ValueType self) {
|
static bool isTypedVectorElement(ValueType self) {
|
||||||
return self == ValueType.Bool ||
|
return self == ValueType.Bool ||
|
||||||
(
|
(toInt(self) >= toInt(ValueType.Int) &&
|
||||||
toInt(self) >= toInt(ValueType.Int)
|
toInt(self) <= toInt(ValueType.String));
|
||||||
&& toInt(self) <= toInt(ValueType.String)
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool isTypedVector(ValueType self) {
|
static bool isTypedVector(ValueType self) {
|
||||||
return self == ValueType.VectorBool ||
|
return self == ValueType.VectorBool ||
|
||||||
(
|
(toInt(self) >= toInt(ValueType.VectorInt) &&
|
||||||
toInt(self) >= toInt(ValueType.VectorInt)
|
toInt(self) <= toInt(ValueType.VectorString));
|
||||||
&& toInt(self) <= toInt(ValueType.VectorString)
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool isFixedTypedVector(ValueType self) {
|
static bool isFixedTypedVector(ValueType self) {
|
||||||
return (
|
return (toInt(self) >= toInt(ValueType.VectorInt2) &&
|
||||||
toInt(self) >= toInt(ValueType.VectorInt2)
|
toInt(self) <= toInt(ValueType.VectorFloat4));
|
||||||
&& toInt(self) <= toInt(ValueType.VectorFloat4)
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool isAVector(ValueType self) {
|
static bool isAVector(ValueType self) {
|
||||||
return (
|
return (isTypedVector(self) ||
|
||||||
isTypedVector(self) || isFixedTypedVector(self) || self == ValueType.Vector
|
isFixedTypedVector(self) ||
|
||||||
);
|
self == ValueType.Vector);
|
||||||
}
|
}
|
||||||
|
|
||||||
static ValueType toTypedVector(ValueType self, int length) {
|
static ValueType toTypedVector(ValueType self, int length) {
|
||||||
if (length == 0) {
|
if (length == 0) {
|
||||||
return ValueTypeUtils.fromInt(toInt(self) - toInt(ValueType.Int) + toInt(ValueType.VectorInt));
|
return ValueTypeUtils.fromInt(
|
||||||
|
toInt(self) - toInt(ValueType.Int) + toInt(ValueType.VectorInt));
|
||||||
}
|
}
|
||||||
if (length == 2) {
|
if (length == 2) {
|
||||||
return ValueTypeUtils.fromInt(toInt(self) - toInt(ValueType.Int) + toInt(ValueType.VectorInt2));
|
return ValueTypeUtils.fromInt(
|
||||||
|
toInt(self) - toInt(ValueType.Int) + toInt(ValueType.VectorInt2));
|
||||||
}
|
}
|
||||||
if (length == 3) {
|
if (length == 3) {
|
||||||
return ValueTypeUtils.fromInt(toInt(self) - toInt(ValueType.Int) + toInt(ValueType.VectorInt3));
|
return ValueTypeUtils.fromInt(
|
||||||
|
toInt(self) - toInt(ValueType.Int) + toInt(ValueType.VectorInt3));
|
||||||
}
|
}
|
||||||
if (length == 4) {
|
if (length == 4) {
|
||||||
return ValueTypeUtils.fromInt(toInt(self) - toInt(ValueType.Int) + toInt(ValueType.VectorInt4));
|
return ValueTypeUtils.fromInt(
|
||||||
|
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(toInt(self) - toInt(ValueType.VectorInt) + toInt(ValueType.Int));
|
return ValueTypeUtils.fromInt(
|
||||||
|
toInt(self) - toInt(ValueType.VectorInt) + toInt(ValueType.Int));
|
||||||
}
|
}
|
||||||
|
|
||||||
static ValueType fixedTypedVectorElementType(ValueType self) {
|
static ValueType fixedTypedVectorElementType(ValueType self) {
|
||||||
return ValueTypeUtils.fromInt((toInt(self) - toInt(ValueType.VectorInt2)) % 3 + toInt(ValueType.Int));
|
return ValueTypeUtils.fromInt(
|
||||||
|
(toInt(self) - toInt(ValueType.VectorInt2)) % 3 + toInt(ValueType.Int));
|
||||||
}
|
}
|
||||||
|
|
||||||
static int fixedTypedVectorElementSize(ValueType self) {
|
static int fixedTypedVectorElementSize(ValueType self) {
|
||||||
|
|||||||
@@ -21,17 +21,12 @@ set -e
|
|||||||
|
|
||||||
command -v dart >/dev/null 2>&1 || { echo >&2 "Require `dart` but it's not installed. Aborting."; exit 1; }
|
command -v dart >/dev/null 2>&1 || { echo >&2 "Require `dart` but it's not installed. Aborting."; exit 1; }
|
||||||
|
|
||||||
cp ../samples/monster.fbs example/
|
pushd ../tests
|
||||||
cp ../tests/monster_test.fbs test/
|
./DartTest.sh
|
||||||
cp -r ../tests/include_test/*.fbs test/
|
|
||||||
cp -r ../tests/include_test/sub test/
|
|
||||||
|
|
||||||
pushd example
|
|
||||||
../../flatc --dart ./monster.fbs
|
|
||||||
popd
|
popd
|
||||||
|
|
||||||
pushd test
|
pushd ../samples
|
||||||
../../flatc --dart ./monster_test.fbs
|
./dart_sample.sh
|
||||||
popd
|
popd
|
||||||
|
|
||||||
dart pub publish
|
dart pub publish
|
||||||
|
|||||||
@@ -1,20 +1,15 @@
|
|||||||
name: flat_buffers
|
name: flat_buffers
|
||||||
version: 2.0.0
|
version: 2.0.5
|
||||||
description: >
|
description: FlatBuffers reading and writing library for Dart. Based on original work by Konstantin Scheglov and Paul Berry of the Dart SDK team.
|
||||||
FlatBuffers reading and writing library for Dart. Use the flatc compiler to
|
|
||||||
generate Dart classes for a FlatBuffers schema, and this library to assist with
|
|
||||||
reading and writing the binary format.
|
|
||||||
|
|
||||||
Based on original work by Konstantin Scheglov and Paul Berry of the Dart SDK team.
|
|
||||||
authors:
|
|
||||||
- Dan Field <dfield@gmail.com>
|
|
||||||
- Konstantin Scheglov
|
|
||||||
- Paul Berry
|
|
||||||
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
|
||||||
dev_dependencies:
|
|
||||||
test: ^1.3.0
|
|
||||||
test_reflective_loader: ^0.1.4
|
|
||||||
path: ^1.5.1
|
|
||||||
environment:
|
environment:
|
||||||
sdk: '>=2.0.0-dev.28.0 <3.0.0'
|
sdk: '>=2.12.0 <3.0.0'
|
||||||
|
|
||||||
|
dev_dependencies:
|
||||||
|
test: ^1.17.7
|
||||||
|
test_reflective_loader: ^0.2.0
|
||||||
|
path: ^1.8.0
|
||||||
|
lints: ^1.0.1
|
||||||
|
|
||||||
|
|||||||
10
dart/test/bool_structs.fbs
Normal file
10
dart/test/bool_structs.fbs
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
// Test for #7355
|
||||||
|
table Foo {
|
||||||
|
my_foo : foo_properties;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct foo_properties
|
||||||
|
{
|
||||||
|
a : bool;
|
||||||
|
b : bool;
|
||||||
|
}
|
||||||
@@ -1,7 +1,3 @@
|
|||||||
// Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file
|
|
||||||
// for details. All rights reserved. Use of this source code is governed by a
|
|
||||||
// BSD-style license that can be found in the LICENSE file.
|
|
||||||
|
|
||||||
import 'dart:typed_data';
|
import 'dart:typed_data';
|
||||||
import 'dart:io' as io;
|
import 'dart:io' as io;
|
||||||
|
|
||||||
@@ -12,12 +8,18 @@ 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.example_generated.dart' as example;
|
||||||
|
import './monster_test_my_game.example2_generated.dart' as example2;
|
||||||
|
import './list_of_enums_generated.dart' as example3;
|
||||||
|
import './bool_structs_generated.dart' as example4;
|
||||||
|
import './keyword_test_keyword_test_generated.dart' as keyword_test;
|
||||||
|
|
||||||
main() {
|
main() {
|
||||||
defineReflectiveSuite(() {
|
defineReflectiveSuite(() {
|
||||||
defineReflectiveTests(BuilderTest);
|
defineReflectiveTests(BuilderTest);
|
||||||
|
defineReflectiveTests(ObjectAPITest);
|
||||||
defineReflectiveTests(CheckOtherLangaugesData);
|
defineReflectiveTests(CheckOtherLangaugesData);
|
||||||
defineReflectiveTests(GeneratorTest);
|
defineReflectiveTests(GeneratorTest);
|
||||||
|
defineReflectiveTests(ListOfEnumsTest);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -28,34 +30,35 @@ int indexToField(int index) {
|
|||||||
@reflectiveTest
|
@reflectiveTest
|
||||||
class CheckOtherLangaugesData {
|
class CheckOtherLangaugesData {
|
||||||
test_cppData() async {
|
test_cppData() async {
|
||||||
List<int> data = await new io.File(path.join(
|
List<int> data = await io.File(path.join(
|
||||||
path.dirname(io.Platform.script.path),
|
path.context.current,
|
||||||
|
'test',
|
||||||
'monsterdata_test.mon',
|
'monsterdata_test.mon',
|
||||||
)).readAsBytes();
|
)).readAsBytes();
|
||||||
example.Monster mon = new 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);
|
||||||
expect(mon.name, 'MyMonster');
|
expect(mon.name, 'MyMonster');
|
||||||
expect(mon.pos.x, 1.0);
|
expect(mon.pos!.x, 1.0);
|
||||||
expect(mon.pos.y, 2.0);
|
expect(mon.pos!.y, 2.0);
|
||||||
expect(mon.pos.z, 3.0);
|
expect(mon.pos!.z, 3.0);
|
||||||
expect(mon.pos.test1, 3.0);
|
expect(mon.pos!.test1, 3.0);
|
||||||
expect(mon.pos.test2.value, 2.0);
|
expect(mon.pos!.test2.value, 2.0);
|
||||||
expect(mon.pos.test3.a, 5);
|
expect(mon.pos!.test3.a, 5);
|
||||||
expect(mon.pos.test3.b, 6);
|
expect(mon.pos!.test3.b, 6);
|
||||||
expect(mon.testType.value, example.AnyTypeId.Monster.value);
|
expect(mon.testType!.value, example.AnyTypeId.Monster.value);
|
||||||
expect(mon.test is example.Monster, true);
|
expect(mon.test is example.Monster, true);
|
||||||
final monster2 = mon.test as example.Monster;
|
final monster2 = mon.test as example.Monster;
|
||||||
expect(monster2.name, "Fred");
|
expect(monster2.name, "Fred");
|
||||||
|
|
||||||
expect(mon.inventory.length, 5);
|
expect(mon.inventory!.length, 5);
|
||||||
expect(mon.inventory.reduce((cur, next) => cur + next), 10);
|
expect(mon.inventory!.reduce((cur, next) => cur + next), 10);
|
||||||
expect(mon.test4.length, 2);
|
final test4 = mon.test4!;
|
||||||
expect(
|
expect(test4.length, 2);
|
||||||
mon.test4[0].a + mon.test4[0].b + mon.test4[1].a + mon.test4[1].b, 100);
|
expect(test4[0].a + test4[0].b + test4[1].a + test4[1].b, 100);
|
||||||
expect(mon.testarrayofstring.length, 2);
|
expect(mon.testarrayofstring!.length, 2);
|
||||||
expect(mon.testarrayofstring[0], "test1");
|
expect(mon.testarrayofstring![0], "test1");
|
||||||
expect(mon.testarrayofstring[1], "test2");
|
expect(mon.testarrayofstring![1], "test2");
|
||||||
|
|
||||||
// this will fail if accessing any field fails.
|
// this will fail if accessing any field fails.
|
||||||
expect(
|
expect(
|
||||||
@@ -65,7 +68,7 @@ class CheckOtherLangaugesData {
|
|||||||
'mana: 150, hp: 80, name: MyMonster, inventory: [0, 1, 2, 3, 4], '
|
'mana: 150, hp: 80, name: MyMonster, inventory: [0, 1, 2, 3, 4], '
|
||||||
'color: Color{value: 8}, testType: AnyTypeId{value: 1}, '
|
'color: Color{value: 8}, testType: AnyTypeId{value: 1}, '
|
||||||
'test: Monster{pos: null, mana: 150, hp: 100, name: Fred, '
|
'test: Monster{pos: null, mana: 150, hp: 100, name: Fred, '
|
||||||
'inventory: null, color: Color{value: 8}, testType: AnyTypeId{value: 0}, '
|
'inventory: null, color: Color{value: 8}, testType: null, '
|
||||||
'test: null, test4: null, testarrayofstring: null, '
|
'test: null, test4: null, testarrayofstring: null, '
|
||||||
'testarrayoftables: null, enemy: null, testnestedflatbuffer: null, '
|
'testarrayoftables: null, enemy: null, testnestedflatbuffer: null, '
|
||||||
'testempty: null, testbool: false, testhashs32Fnv1: 0, '
|
'testempty: null, testbool: false, testhashs32Fnv1: 0, '
|
||||||
@@ -79,14 +82,16 @@ class CheckOtherLangaugesData {
|
|||||||
'vectorOfWeakReferences: null, vectorOfStrongReferrables: null, '
|
'vectorOfWeakReferences: null, vectorOfStrongReferrables: null, '
|
||||||
'coOwningReference: 0, vectorOfCoOwningReferences: null, '
|
'coOwningReference: 0, vectorOfCoOwningReferences: null, '
|
||||||
'nonOwningReference: 0, vectorOfNonOwningReferences: null, '
|
'nonOwningReference: 0, vectorOfNonOwningReferences: null, '
|
||||||
'anyUniqueType: AnyUniqueAliasesTypeId{value: 0}, anyUnique: null, '
|
'anyUniqueType: null, anyUnique: null, anyAmbiguousType: null, '
|
||||||
'anyAmbiguousType: AnyAmbiguousAliasesTypeId{value: 0}, '
|
|
||||||
'anyAmbiguous: null, vectorOfEnums: null, signedEnum: Race{value: -1}, '
|
'anyAmbiguous: null, vectorOfEnums: null, signedEnum: Race{value: -1}, '
|
||||||
'testrequirednestedflatbuffer: null}, '
|
'testrequirednestedflatbuffer: null, scalarKeySortedTables: null, '
|
||||||
|
'nativeInline: null, '
|
||||||
|
'longEnumNonEnumDefault: LongEnum{value: 0}, '
|
||||||
|
'longEnumNormalDefault: LongEnum{value: 2}}, '
|
||||||
'test4: [Test{a: 10, b: 20}, Test{a: 30, b: 40}], '
|
'test4: [Test{a: 10, b: 20}, Test{a: 30, b: 40}], '
|
||||||
'testarrayofstring: [test1, test2], testarrayoftables: null, '
|
'testarrayofstring: [test1, test2], testarrayoftables: null, '
|
||||||
'enemy: Monster{pos: null, mana: 150, hp: 100, name: Fred, '
|
'enemy: Monster{pos: null, mana: 150, hp: 100, name: Fred, '
|
||||||
'inventory: null, color: Color{value: 8}, testType: AnyTypeId{value: 0}, '
|
'inventory: null, color: Color{value: 8}, testType: null, '
|
||||||
'test: null, test4: null, testarrayofstring: null, '
|
'test: null, test4: null, testarrayofstring: null, '
|
||||||
'testarrayoftables: null, enemy: null, testnestedflatbuffer: null, '
|
'testarrayoftables: null, enemy: null, testnestedflatbuffer: null, '
|
||||||
'testempty: null, testbool: false, testhashs32Fnv1: 0, '
|
'testempty: null, testbool: false, testhashs32Fnv1: 0, '
|
||||||
@@ -100,10 +105,12 @@ class CheckOtherLangaugesData {
|
|||||||
'vectorOfWeakReferences: null, vectorOfStrongReferrables: null, '
|
'vectorOfWeakReferences: null, vectorOfStrongReferrables: null, '
|
||||||
'coOwningReference: 0, vectorOfCoOwningReferences: null, '
|
'coOwningReference: 0, vectorOfCoOwningReferences: null, '
|
||||||
'nonOwningReference: 0, vectorOfNonOwningReferences: null, '
|
'nonOwningReference: 0, vectorOfNonOwningReferences: null, '
|
||||||
'anyUniqueType: AnyUniqueAliasesTypeId{value: 0}, anyUnique: null, '
|
'anyUniqueType: null, anyUnique: null, anyAmbiguousType: null, '
|
||||||
'anyAmbiguousType: AnyAmbiguousAliasesTypeId{value: 0}, '
|
|
||||||
'anyAmbiguous: null, vectorOfEnums: null, signedEnum: Race{value: -1}, '
|
'anyAmbiguous: null, vectorOfEnums: null, signedEnum: Race{value: -1}, '
|
||||||
'testrequirednestedflatbuffer: null}, '
|
'testrequirednestedflatbuffer: null, scalarKeySortedTables: null, '
|
||||||
|
'nativeInline: null, '
|
||||||
|
'longEnumNonEnumDefault: LongEnum{value: 0}, '
|
||||||
|
'longEnumNormalDefault: LongEnum{value: 2}}, '
|
||||||
'testnestedflatbuffer: null, testempty: null, testbool: true, '
|
'testnestedflatbuffer: null, testempty: null, testbool: true, '
|
||||||
'testhashs32Fnv1: -579221183, testhashu32Fnv1: 3715746113, '
|
'testhashs32Fnv1: -579221183, testhashu32Fnv1: 3715746113, '
|
||||||
'testhashs64Fnv1: 7930699090847568257, '
|
'testhashs64Fnv1: 7930699090847568257, '
|
||||||
@@ -112,7 +119,9 @@ class CheckOtherLangaugesData {
|
|||||||
'testhashs64Fnv1a: 4898026182817603057, '
|
'testhashs64Fnv1a: 4898026182817603057, '
|
||||||
'testhashu64Fnv1a: 4898026182817603057, '
|
'testhashu64Fnv1a: 4898026182817603057, '
|
||||||
'testarrayofbools: [true, false, true], testf: 3.14159, testf2: 3.0, '
|
'testarrayofbools: [true, false, true], testf: 3.14159, testf2: 3.0, '
|
||||||
'testf3: 0.0, testarrayofstring2: null, testarrayofsortedstruct: null, '
|
'testf3: 0.0, testarrayofstring2: null, testarrayofsortedstruct: ['
|
||||||
|
'Ability{id: 0, distance: 45}, Ability{id: 1, distance: 21}, '
|
||||||
|
'Ability{id: 5, distance: 12}], '
|
||||||
'flex: null, test5: [Test{a: 10, b: 20}, Test{a: 30, b: 40}], '
|
'flex: null, test5: [Test{a: 10, b: 20}, Test{a: 30, b: 40}], '
|
||||||
'vectorOfLongs: [1, 100, 10000, 1000000, 100000000], '
|
'vectorOfLongs: [1, 100, 10000, 1000000, 100000000], '
|
||||||
'vectorOfDoubles: [-1.7976931348623157e+308, 0.0, 1.7976931348623157e+308], '
|
'vectorOfDoubles: [-1.7976931348623157e+308, 0.0, 1.7976931348623157e+308], '
|
||||||
@@ -121,22 +130,46 @@ class CheckOtherLangaugesData {
|
|||||||
'vectorOfStrongReferrables: null, coOwningReference: 0, '
|
'vectorOfStrongReferrables: null, coOwningReference: 0, '
|
||||||
'vectorOfCoOwningReferences: null, nonOwningReference: 0, '
|
'vectorOfCoOwningReferences: null, nonOwningReference: 0, '
|
||||||
'vectorOfNonOwningReferences: null, '
|
'vectorOfNonOwningReferences: null, '
|
||||||
'anyUniqueType: AnyUniqueAliasesTypeId{value: 0}, anyUnique: null, '
|
'anyUniqueType: null, anyUnique: null, '
|
||||||
'anyAmbiguousType: AnyAmbiguousAliasesTypeId{value: 0}, '
|
'anyAmbiguousType: null, '
|
||||||
'anyAmbiguous: null, vectorOfEnums: null, signedEnum: Race{value: -1}, '
|
'anyAmbiguous: null, vectorOfEnums: null, signedEnum: Race{value: -1}, '
|
||||||
'testrequirednestedflatbuffer: null}',
|
'testrequirednestedflatbuffer: null, scalarKeySortedTables: [Stat{id: '
|
||||||
|
'miss, val: 0, count: 0}, Stat{id: hit, val: 10, count: 1}], '
|
||||||
|
'nativeInline: Test{a: 1, b: 2}, '
|
||||||
|
'longEnumNonEnumDefault: LongEnum{value: 0}, '
|
||||||
|
'longEnumNormalDefault: LongEnum{value: 2}}',
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Test a custom, fixed-memory allocator (no actual allocations performed)
|
||||||
|
class CustomAllocator extends Allocator {
|
||||||
|
final _memory = ByteData(10 * 1024);
|
||||||
|
int _used = 0;
|
||||||
|
|
||||||
|
Uint8List buffer(int size) => _memory.buffer.asUint8List(_used - size, size);
|
||||||
|
|
||||||
|
@override
|
||||||
|
ByteData allocate(int size) {
|
||||||
|
if (size > _memory.lengthInBytes) {
|
||||||
|
throw UnsupportedError('Trying to allocate too much');
|
||||||
|
}
|
||||||
|
_used = size;
|
||||||
|
return ByteData.sublistView(_memory, 0, size);
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void deallocate(ByteData _) {}
|
||||||
|
}
|
||||||
|
|
||||||
@reflectiveTest
|
@reflectiveTest
|
||||||
class BuilderTest {
|
class BuilderTest {
|
||||||
void test_monsterBuilder() {
|
void test_monsterBuilder([Builder? builder]) {
|
||||||
final fbBuilder = new Builder();
|
final fbBuilder = builder ?? Builder();
|
||||||
final str = fbBuilder.writeString('MyMonster');
|
final str = fbBuilder.writeString('MyMonster');
|
||||||
|
|
||||||
fbBuilder.writeString('test1');
|
fbBuilder.writeString('test1');
|
||||||
fbBuilder.writeString('test2');
|
fbBuilder.writeString('test2', asciiOptimization: true);
|
||||||
final testArrayOfString = fbBuilder.endStructVector(2);
|
final testArrayOfString = fbBuilder.endStructVector(2);
|
||||||
|
|
||||||
final fred = fbBuilder.writeString('Fred');
|
final fred = fbBuilder.writeString('Fred');
|
||||||
@@ -144,12 +177,12 @@ class BuilderTest {
|
|||||||
final List<int> treasure = [0, 1, 2, 3, 4];
|
final List<int> treasure = [0, 1, 2, 3, 4];
|
||||||
final inventory = fbBuilder.writeListUint8(treasure);
|
final inventory = fbBuilder.writeListUint8(treasure);
|
||||||
|
|
||||||
final monBuilder = new example.MonsterBuilder(fbBuilder)
|
final monBuilder = example.MonsterBuilder(fbBuilder)
|
||||||
..begin()
|
..begin()
|
||||||
..addNameOffset(fred);
|
..addNameOffset(fred);
|
||||||
final mon2 = monBuilder.finish();
|
final mon2 = monBuilder.finish();
|
||||||
|
|
||||||
final testBuilder = new example.TestBuilder(fbBuilder);
|
final testBuilder = example.TestBuilder(fbBuilder);
|
||||||
testBuilder.finish(10, 20);
|
testBuilder.finish(10, 20);
|
||||||
testBuilder.finish(30, 40);
|
testBuilder.finish(30, 40);
|
||||||
final test4 = fbBuilder.endStructVector(2);
|
final test4 = fbBuilder.endStructVector(2);
|
||||||
@@ -157,7 +190,7 @@ class BuilderTest {
|
|||||||
monBuilder
|
monBuilder
|
||||||
..begin()
|
..begin()
|
||||||
..addPos(
|
..addPos(
|
||||||
new example.Vec3Builder(fbBuilder).finish(
|
example.Vec3Builder(fbBuilder).finish(
|
||||||
1.0,
|
1.0,
|
||||||
2.0,
|
2.0,
|
||||||
3.0,
|
3.0,
|
||||||
@@ -177,50 +210,51 @@ class BuilderTest {
|
|||||||
fbBuilder.finish(mon);
|
fbBuilder.finish(mon);
|
||||||
}
|
}
|
||||||
|
|
||||||
void test_error_addInt32_withoutStartTable() {
|
void test_error_addInt32_withoutStartTable([Builder? builder]) {
|
||||||
Builder builder = new Builder();
|
builder ??= Builder();
|
||||||
expect(() {
|
expect(() {
|
||||||
builder.addInt32(0, 0);
|
builder!.addInt32(0, 0);
|
||||||
}, throwsStateError);
|
}, throwsA(isA<AssertionError>()));
|
||||||
}
|
}
|
||||||
|
|
||||||
void test_error_addOffset_withoutStartTable() {
|
void test_error_addOffset_withoutStartTable() {
|
||||||
Builder builder = new Builder();
|
Builder builder = Builder();
|
||||||
expect(() {
|
expect(() {
|
||||||
builder.addOffset(0, 0);
|
builder.addOffset(0, 0);
|
||||||
}, throwsStateError);
|
}, throwsA(isA<AssertionError>()));
|
||||||
}
|
}
|
||||||
|
|
||||||
void test_error_endTable_withoutStartTable() {
|
void test_error_endTable_withoutStartTable() {
|
||||||
Builder builder = new Builder();
|
Builder builder = Builder();
|
||||||
expect(() {
|
expect(() {
|
||||||
builder.endTable();
|
builder.endTable();
|
||||||
}, throwsStateError);
|
}, throwsA(isA<AssertionError>()));
|
||||||
}
|
}
|
||||||
|
|
||||||
void test_error_startTable_duringTable() {
|
void test_error_startTable_duringTable() {
|
||||||
Builder builder = new Builder();
|
Builder builder = Builder();
|
||||||
builder.startTable();
|
builder.startTable(0);
|
||||||
expect(() {
|
expect(() {
|
||||||
builder.startTable();
|
builder.startTable(0);
|
||||||
}, throwsStateError);
|
}, throwsA(isA<AssertionError>()));
|
||||||
}
|
}
|
||||||
|
|
||||||
void test_error_writeString_duringTable() {
|
void test_error_writeString_duringTable() {
|
||||||
Builder builder = new Builder();
|
Builder builder = Builder();
|
||||||
builder.startTable();
|
builder.startTable(1);
|
||||||
expect(() {
|
expect(() {
|
||||||
builder.writeString('12345');
|
builder.writeString('12345');
|
||||||
}, throwsStateError);
|
}, throwsA(isA<AssertionError>()));
|
||||||
}
|
}
|
||||||
|
|
||||||
void test_file_identifier() {
|
void test_file_identifier() {
|
||||||
Uint8List byteList;
|
Uint8List byteList;
|
||||||
{
|
{
|
||||||
Builder builder = new Builder(initialSize: 0);
|
Builder builder = Builder(initialSize: 0);
|
||||||
builder.startTable();
|
builder.startTable(0);
|
||||||
int offset = builder.endTable();
|
int offset = builder.endTable();
|
||||||
byteList = builder.finish(offset, 'Az~ÿ');
|
builder.finish(offset, 'Az~ÿ');
|
||||||
|
byteList = builder.buffer;
|
||||||
}
|
}
|
||||||
// Convert byteList to a ByteData so that we can read data from it.
|
// Convert byteList to a ByteData so that we can read data from it.
|
||||||
ByteData byteData = byteList.buffer.asByteData(byteList.offsetInBytes);
|
ByteData byteData = byteList.buffer.asByteData(byteList.offsetInBytes);
|
||||||
@@ -243,32 +277,46 @@ class BuilderTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void test_low() {
|
void test_low() {
|
||||||
Builder builder = new Builder(initialSize: 0);
|
final allocator = CustomAllocator();
|
||||||
expect((builder..putUint8(1)).lowFinish(), [1]);
|
final builder = Builder(initialSize: 0, allocator: allocator);
|
||||||
expect((builder..putUint32(2)).lowFinish(), [2, 0, 0, 0, 0, 0, 0, 1]);
|
|
||||||
expect((builder..putUint8(3)).lowFinish(),
|
builder.putUint8(1);
|
||||||
[0, 0, 0, 3, 2, 0, 0, 0, 0, 0, 0, 1]);
|
expect(allocator.buffer(builder.size()), [1]);
|
||||||
expect((builder..putUint8(4)).lowFinish(),
|
|
||||||
[0, 0, 4, 3, 2, 0, 0, 0, 0, 0, 0, 1]);
|
builder.putUint32(2);
|
||||||
expect((builder..putUint8(5)).lowFinish(),
|
expect(allocator.buffer(builder.size()), [2, 0, 0, 0, 0, 0, 0, 1]);
|
||||||
[0, 5, 4, 3, 2, 0, 0, 0, 0, 0, 0, 1]);
|
|
||||||
expect((builder..putUint32(6)).lowFinish(),
|
builder.putUint8(3);
|
||||||
|
expect(
|
||||||
|
allocator.buffer(builder.size()), [0, 0, 0, 3, 2, 0, 0, 0, 0, 0, 0, 1]);
|
||||||
|
|
||||||
|
builder.putUint8(4);
|
||||||
|
expect(
|
||||||
|
allocator.buffer(builder.size()), [0, 0, 4, 3, 2, 0, 0, 0, 0, 0, 0, 1]);
|
||||||
|
|
||||||
|
builder.putUint8(5);
|
||||||
|
expect(
|
||||||
|
allocator.buffer(builder.size()), [0, 5, 4, 3, 2, 0, 0, 0, 0, 0, 0, 1]);
|
||||||
|
|
||||||
|
builder.putUint32(6);
|
||||||
|
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() {
|
||||||
List<int> byteList;
|
List<int> byteList;
|
||||||
{
|
{
|
||||||
Builder builder = new Builder(initialSize: 0);
|
final builder = Builder(initialSize: 0, allocator: CustomAllocator());
|
||||||
builder.startTable();
|
builder.startTable(2);
|
||||||
builder.addInt32(0, 10, 10);
|
builder.addInt32(0, 10, 10);
|
||||||
builder.addInt32(1, 20, 10);
|
builder.addInt32(1, 20, 10);
|
||||||
int offset = builder.endTable();
|
int offset = builder.endTable();
|
||||||
byteList = builder.finish(offset);
|
builder.finish(offset);
|
||||||
|
byteList = builder.buffer;
|
||||||
expect(builder.size(), byteList.length);
|
expect(builder.size(), byteList.length);
|
||||||
}
|
}
|
||||||
// read and verify
|
// read and verify
|
||||||
BufferContext buffer = new BufferContext.fromBytes(byteList);
|
BufferContext buffer = BufferContext.fromBytes(byteList);
|
||||||
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(
|
||||||
@@ -282,15 +330,16 @@ class BuilderTest {
|
|||||||
20);
|
20);
|
||||||
}
|
}
|
||||||
|
|
||||||
void test_table_format() {
|
void test_table_format([Builder? builder]) {
|
||||||
Uint8List byteList;
|
Uint8List byteList;
|
||||||
{
|
{
|
||||||
Builder builder = new Builder(initialSize: 0);
|
builder ??= Builder(initialSize: 0);
|
||||||
builder.startTable();
|
builder.startTable(3);
|
||||||
builder.addInt32(0, 10);
|
builder.addInt32(0, 10);
|
||||||
builder.addInt32(1, 20);
|
builder.addInt32(1, 20);
|
||||||
builder.addInt32(2, 30);
|
builder.addInt32(2, 30);
|
||||||
byteList = builder.finish(builder.endTable());
|
builder.finish(builder.endTable());
|
||||||
|
byteList = builder.buffer;
|
||||||
}
|
}
|
||||||
// Convert byteList to a ByteData so that we can read data from it.
|
// Convert byteList to a ByteData so that we can read data from it.
|
||||||
ByteData byteData = byteList.buffer.asByteData(byteList.offsetInBytes);
|
ByteData byteData = byteList.buffer.asByteData(byteList.offsetInBytes);
|
||||||
@@ -319,30 +368,37 @@ class BuilderTest {
|
|||||||
String unicodeString = 'Проба пера';
|
String unicodeString = 'Проба пера';
|
||||||
List<int> byteList;
|
List<int> byteList;
|
||||||
{
|
{
|
||||||
Builder builder = new Builder(initialSize: 0);
|
Builder builder = Builder(initialSize: 0);
|
||||||
int latinStringOffset = builder.writeString(latinString);
|
int? latinStringOffset =
|
||||||
int unicodeStringOffset = builder.writeString(unicodeString);
|
builder.writeString(latinString, asciiOptimization: true);
|
||||||
builder.startTable();
|
int? unicodeStringOffset =
|
||||||
|
builder.writeString(unicodeString, asciiOptimization: true);
|
||||||
|
builder.startTable(2);
|
||||||
builder.addOffset(0, latinStringOffset);
|
builder.addOffset(0, latinStringOffset);
|
||||||
builder.addOffset(1, unicodeStringOffset);
|
builder.addOffset(1, unicodeStringOffset);
|
||||||
int offset = builder.endTable();
|
int offset = builder.endTable();
|
||||||
byteList = builder.finish(offset);
|
builder.finish(offset);
|
||||||
|
byteList = builder.buffer;
|
||||||
}
|
}
|
||||||
// read and verify
|
// read and verify
|
||||||
BufferContext buf = new BufferContext.fromBytes(byteList);
|
BufferContext buf = BufferContext.fromBytes(byteList);
|
||||||
int objectOffset = buf.derefObject(0);
|
int objectOffset = buf.derefObject(0);
|
||||||
expect(const StringReader().vTableGet(buf, objectOffset, indexToField(0)),
|
expect(
|
||||||
|
const StringReader()
|
||||||
|
.vTableGetNullable(buf, objectOffset, indexToField(0)),
|
||||||
latinString);
|
latinString);
|
||||||
expect(const StringReader().vTableGet(buf, objectOffset, indexToField(1)),
|
expect(
|
||||||
|
const StringReader(asciiOptimization: true)
|
||||||
|
.vTableGetNullable(buf, objectOffset, indexToField(1)),
|
||||||
unicodeString);
|
unicodeString);
|
||||||
}
|
}
|
||||||
|
|
||||||
void test_table_types() {
|
void test_table_types([Builder? builder]) {
|
||||||
List<int> byteList;
|
List<int> byteList;
|
||||||
{
|
{
|
||||||
Builder builder = new Builder(initialSize: 0);
|
builder ??= Builder(initialSize: 0);
|
||||||
int stringOffset = builder.writeString('12345');
|
int? stringOffset = builder.writeString('12345');
|
||||||
builder.startTable();
|
builder.startTable(7);
|
||||||
builder.addBool(0, true);
|
builder.addBool(0, true);
|
||||||
builder.addInt8(1, 10);
|
builder.addInt8(1, 10);
|
||||||
builder.addInt32(2, 20);
|
builder.addInt32(2, 20);
|
||||||
@@ -351,24 +407,39 @@ class BuilderTest {
|
|||||||
builder.addUint32(5, 0x9ABCDEF0);
|
builder.addUint32(5, 0x9ABCDEF0);
|
||||||
builder.addUint8(6, 0x9A);
|
builder.addUint8(6, 0x9A);
|
||||||
int offset = builder.endTable();
|
int offset = builder.endTable();
|
||||||
byteList = builder.finish(offset);
|
builder.finish(offset);
|
||||||
|
byteList = builder.buffer;
|
||||||
}
|
}
|
||||||
// read and verify
|
// read and verify
|
||||||
BufferContext buf = new BufferContext.fromBytes(byteList);
|
BufferContext buf = BufferContext.fromBytes(byteList);
|
||||||
int objectOffset = buf.derefObject(0);
|
int objectOffset = buf.derefObject(0);
|
||||||
expect(
|
expect(
|
||||||
const BoolReader().vTableGet(buf, objectOffset, indexToField(0)), true);
|
const BoolReader()
|
||||||
|
.vTableGetNullable(buf, objectOffset, indexToField(0)),
|
||||||
|
true);
|
||||||
expect(
|
expect(
|
||||||
const Int8Reader().vTableGet(buf, objectOffset, indexToField(1)), 10);
|
const Int8Reader()
|
||||||
|
.vTableGetNullable(buf, objectOffset, indexToField(1)),
|
||||||
|
10);
|
||||||
expect(
|
expect(
|
||||||
const Int32Reader().vTableGet(buf, objectOffset, indexToField(2)), 20);
|
const Int32Reader()
|
||||||
expect(const StringReader().vTableGet(buf, objectOffset, indexToField(3)),
|
.vTableGetNullable(buf, objectOffset, indexToField(2)),
|
||||||
|
20);
|
||||||
|
expect(
|
||||||
|
const StringReader()
|
||||||
|
.vTableGetNullable(buf, objectOffset, indexToField(3)),
|
||||||
'12345');
|
'12345');
|
||||||
expect(
|
expect(
|
||||||
const Int32Reader().vTableGet(buf, objectOffset, indexToField(4)), 40);
|
const Int32Reader()
|
||||||
expect(const Uint32Reader().vTableGet(buf, objectOffset, indexToField(5)),
|
.vTableGetNullable(buf, objectOffset, indexToField(4)),
|
||||||
|
40);
|
||||||
|
expect(
|
||||||
|
const Uint32Reader()
|
||||||
|
.vTableGetNullable(buf, objectOffset, indexToField(5)),
|
||||||
0x9ABCDEF0);
|
0x9ABCDEF0);
|
||||||
expect(const Uint8Reader().vTableGet(buf, objectOffset, indexToField(6)),
|
expect(
|
||||||
|
const Uint8Reader()
|
||||||
|
.vTableGetNullable(buf, objectOffset, indexToField(6)),
|
||||||
0x9A);
|
0x9A);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -377,12 +448,13 @@ class BuilderTest {
|
|||||||
// write
|
// write
|
||||||
List<int> byteList;
|
List<int> byteList;
|
||||||
{
|
{
|
||||||
Builder builder = new Builder(initialSize: 0);
|
Builder builder = Builder(initialSize: 0);
|
||||||
int offset = builder.writeListUint32(values);
|
int offset = builder.writeListUint32(values);
|
||||||
byteList = builder.finish(offset);
|
builder.finish(offset);
|
||||||
|
byteList = builder.buffer;
|
||||||
}
|
}
|
||||||
// read and verify
|
// read and verify
|
||||||
BufferContext buf = new BufferContext.fromBytes(byteList);
|
BufferContext buf = BufferContext.fromBytes(byteList);
|
||||||
List<int> items = const Uint32ListReader().read(buf, 0);
|
List<int> items = const Uint32ListReader().read(buf, 0);
|
||||||
expect(items, hasLength(4));
|
expect(items, hasLength(4));
|
||||||
expect(items, orderedEquals(values));
|
expect(items, orderedEquals(values));
|
||||||
@@ -393,16 +465,17 @@ class BuilderTest {
|
|||||||
// write
|
// write
|
||||||
List<int> byteList;
|
List<int> byteList;
|
||||||
{
|
{
|
||||||
Builder builder = new Builder(initialSize: 0);
|
Builder builder = Builder(initialSize: 0);
|
||||||
List<bool> values = new List<bool>.filled(len, false);
|
List<bool> values = List<bool>.filled(len, false);
|
||||||
for (int bit in trueBits) {
|
for (int bit in trueBits) {
|
||||||
values[bit] = true;
|
values[bit] = true;
|
||||||
}
|
}
|
||||||
int offset = builder.writeListBool(values);
|
int offset = builder.writeListBool(values);
|
||||||
byteList = builder.finish(offset);
|
builder.finish(offset);
|
||||||
|
byteList = builder.buffer;
|
||||||
}
|
}
|
||||||
// read and verify
|
// read and verify
|
||||||
BufferContext buf = new BufferContext.fromBytes(byteList);
|
BufferContext buf = BufferContext.fromBytes(byteList);
|
||||||
List<bool> items = const BoolListReader().read(buf, 0);
|
List<bool> items = const BoolListReader().read(buf, 0);
|
||||||
expect(items, hasLength(len));
|
expect(items, hasLength(len));
|
||||||
for (int i = 0; i < items.length; i++) {
|
for (int i = 0; i < items.length; i++) {
|
||||||
@@ -421,25 +494,26 @@ class BuilderTest {
|
|||||||
verifyListBooleans(33, <int>[1, 2, 24, 25, 31, 32]);
|
verifyListBooleans(33, <int>[1, 2, 24, 25, 31, 32]);
|
||||||
verifyListBooleans(63, <int>[]);
|
verifyListBooleans(63, <int>[]);
|
||||||
verifyListBooleans(63, <int>[0, 1, 2, 61, 62]);
|
verifyListBooleans(63, <int>[0, 1, 2, 61, 62]);
|
||||||
verifyListBooleans(63, new List<int>.generate(63, (i) => i));
|
verifyListBooleans(63, List<int>.generate(63, (i) => i));
|
||||||
verifyListBooleans(64, <int>[]);
|
verifyListBooleans(64, <int>[]);
|
||||||
verifyListBooleans(64, <int>[0, 1, 2, 61, 62, 63]);
|
verifyListBooleans(64, <int>[0, 1, 2, 61, 62, 63]);
|
||||||
verifyListBooleans(64, <int>[1, 2, 62]);
|
verifyListBooleans(64, <int>[1, 2, 62]);
|
||||||
verifyListBooleans(64, <int>[0, 1, 2, 63]);
|
verifyListBooleans(64, <int>[0, 1, 2, 63]);
|
||||||
verifyListBooleans(64, new List<int>.generate(64, (i) => i));
|
verifyListBooleans(64, List<int>.generate(64, (i) => i));
|
||||||
verifyListBooleans(100, <int>[0, 3, 30, 60, 90, 99]);
|
verifyListBooleans(100, <int>[0, 3, 30, 60, 90, 99]);
|
||||||
}
|
}
|
||||||
|
|
||||||
void test_writeList_ofInt32() {
|
void test_writeList_ofInt32() {
|
||||||
List<int> byteList;
|
List<int> byteList;
|
||||||
{
|
{
|
||||||
Builder builder = new Builder(initialSize: 0);
|
Builder builder = Builder(initialSize: 0);
|
||||||
int offset = builder.writeListInt32(<int>[1, 2, 3, 4, 5]);
|
int offset = builder.writeListInt32(<int>[1, 2, 3, 4, 5]);
|
||||||
byteList = builder.finish(offset);
|
builder.finish(offset);
|
||||||
|
byteList = builder.buffer;
|
||||||
}
|
}
|
||||||
// read and verify
|
// read and verify
|
||||||
BufferContext buf = new BufferContext.fromBytes(byteList);
|
BufferContext buf = BufferContext.fromBytes(byteList);
|
||||||
List<int> items = const ListReader<int>(const Int32Reader()).read(buf, 0);
|
List<int> items = const ListReader<int>(Int32Reader()).read(buf, 0);
|
||||||
expect(items, hasLength(5));
|
expect(items, hasLength(5));
|
||||||
expect(items, orderedEquals(<int>[1, 2, 3, 4, 5]));
|
expect(items, orderedEquals(<int>[1, 2, 3, 4, 5]));
|
||||||
}
|
}
|
||||||
@@ -449,13 +523,14 @@ class BuilderTest {
|
|||||||
// write
|
// write
|
||||||
List<int> byteList;
|
List<int> byteList;
|
||||||
{
|
{
|
||||||
Builder builder = new Builder(initialSize: 0);
|
Builder builder = Builder(initialSize: 0);
|
||||||
int offset = builder.writeListFloat64(values);
|
int offset = builder.writeListFloat64(values);
|
||||||
byteList = builder.finish(offset);
|
builder.finish(offset);
|
||||||
|
byteList = builder.buffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
// read and verify
|
// read and verify
|
||||||
BufferContext buf = new BufferContext.fromBytes(byteList);
|
BufferContext buf = BufferContext.fromBytes(byteList);
|
||||||
List<double> items = const Float64ListReader().read(buf, 0);
|
List<double> items = const Float64ListReader().read(buf, 0);
|
||||||
|
|
||||||
expect(items, hasLength(values.length));
|
expect(items, hasLength(values.length));
|
||||||
@@ -469,12 +544,13 @@ class BuilderTest {
|
|||||||
// write
|
// write
|
||||||
List<int> byteList;
|
List<int> byteList;
|
||||||
{
|
{
|
||||||
Builder builder = new Builder(initialSize: 0);
|
Builder builder = Builder(initialSize: 0);
|
||||||
int offset = builder.writeListFloat32(values);
|
int offset = builder.writeListFloat32(values);
|
||||||
byteList = builder.finish(offset);
|
builder.finish(offset);
|
||||||
|
byteList = builder.buffer;
|
||||||
}
|
}
|
||||||
// read and verify
|
// read and verify
|
||||||
BufferContext buf = new BufferContext.fromBytes(byteList);
|
BufferContext buf = BufferContext.fromBytes(byteList);
|
||||||
List<double> items = const Float32ListReader().read(buf, 0);
|
List<double> items = const Float32ListReader().read(buf, 0);
|
||||||
expect(items, hasLength(5));
|
expect(items, hasLength(5));
|
||||||
for (int i = 0; i < values.length; i++) {
|
for (int i = 0; i < values.length; i++) {
|
||||||
@@ -482,14 +558,14 @@ class BuilderTest {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void test_writeList_ofObjects() {
|
void test_writeList_ofObjects([Builder? builder]) {
|
||||||
List<int> byteList;
|
List<int> byteList;
|
||||||
{
|
{
|
||||||
Builder builder = new Builder(initialSize: 0);
|
builder ??= Builder(initialSize: 0);
|
||||||
// write the object #1
|
// write the object #1
|
||||||
int object1;
|
int object1;
|
||||||
{
|
{
|
||||||
builder.startTable();
|
builder.startTable(2);
|
||||||
builder.addInt32(0, 10);
|
builder.addInt32(0, 10);
|
||||||
builder.addInt32(1, 20);
|
builder.addInt32(1, 20);
|
||||||
object1 = builder.endTable();
|
object1 = builder.endTable();
|
||||||
@@ -497,19 +573,20 @@ class BuilderTest {
|
|||||||
// write the object #1
|
// write the object #1
|
||||||
int object2;
|
int object2;
|
||||||
{
|
{
|
||||||
builder.startTable();
|
builder.startTable(2);
|
||||||
builder.addInt32(0, 100);
|
builder.addInt32(0, 100);
|
||||||
builder.addInt32(1, 200);
|
builder.addInt32(1, 200);
|
||||||
object2 = builder.endTable();
|
object2 = builder.endTable();
|
||||||
}
|
}
|
||||||
// write the list
|
// write the list
|
||||||
int offset = builder.writeList([object1, object2]);
|
int offset = builder.writeList([object1, object2]);
|
||||||
byteList = builder.finish(offset);
|
builder.finish(offset);
|
||||||
|
byteList = builder.buffer;
|
||||||
}
|
}
|
||||||
// read and verify
|
// read and verify
|
||||||
BufferContext buf = new BufferContext.fromBytes(byteList);
|
BufferContext buf = BufferContext.fromBytes(byteList);
|
||||||
List<TestPointImpl> items =
|
List<TestPointImpl> items =
|
||||||
const ListReader<TestPointImpl>(const TestPointReader()).read(buf, 0);
|
const ListReader<TestPointImpl>(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);
|
||||||
@@ -520,36 +597,37 @@ class BuilderTest {
|
|||||||
void test_writeList_ofStrings_asRoot() {
|
void test_writeList_ofStrings_asRoot() {
|
||||||
List<int> byteList;
|
List<int> byteList;
|
||||||
{
|
{
|
||||||
Builder builder = new Builder(initialSize: 0);
|
Builder builder = Builder(initialSize: 0);
|
||||||
int str1 = builder.writeString('12345');
|
int? str1 = builder.writeString('12345');
|
||||||
int str2 = builder.writeString('ABC');
|
int? str2 = builder.writeString('ABC');
|
||||||
int offset = builder.writeList([str1, str2]);
|
int offset = builder.writeList([str1, str2]);
|
||||||
byteList = builder.finish(offset);
|
builder.finish(offset);
|
||||||
|
byteList = builder.buffer;
|
||||||
}
|
}
|
||||||
// read and verify
|
// read and verify
|
||||||
BufferContext buf = new BufferContext.fromBytes(byteList);
|
BufferContext buf = BufferContext.fromBytes(byteList);
|
||||||
List<String> items =
|
List<String> items = const ListReader<String>(StringReader()).read(buf, 0);
|
||||||
const ListReader<String>(const StringReader()).read(buf, 0);
|
|
||||||
expect(items, hasLength(2));
|
expect(items, hasLength(2));
|
||||||
expect(items, contains('12345'));
|
expect(items, contains('12345'));
|
||||||
expect(items, contains('ABC'));
|
expect(items, contains('ABC'));
|
||||||
}
|
}
|
||||||
|
|
||||||
void test_writeList_ofStrings_inObject() {
|
void test_writeList_ofStrings_inObject([Builder? builder]) {
|
||||||
List<int> byteList;
|
List<int> byteList;
|
||||||
{
|
{
|
||||||
Builder builder = new 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();
|
builder.startTable(1);
|
||||||
builder.addOffset(0, listOffset);
|
builder.addOffset(0, listOffset);
|
||||||
int offset = builder.endTable();
|
int offset = builder.endTable();
|
||||||
byteList = builder.finish(offset);
|
builder.finish(offset);
|
||||||
|
byteList = builder.buffer;
|
||||||
}
|
}
|
||||||
// read and verify
|
// read and verify
|
||||||
BufferContext buf = new BufferContext.fromBytes(byteList);
|
BufferContext buf = BufferContext.fromBytes(byteList);
|
||||||
StringListWrapperImpl reader = new StringListWrapperReader().read(buf, 0);
|
StringListWrapperImpl reader = StringListWrapperReader().read(buf, 0);
|
||||||
List<String> items = reader.items;
|
List<String>? items = reader.items;
|
||||||
expect(items, hasLength(2));
|
expect(items, hasLength(2));
|
||||||
expect(items, contains('12345'));
|
expect(items, contains('12345'));
|
||||||
expect(items, contains('ABC'));
|
expect(items, contains('ABC'));
|
||||||
@@ -558,12 +636,13 @@ class BuilderTest {
|
|||||||
void test_writeList_ofUint32() {
|
void test_writeList_ofUint32() {
|
||||||
List<int> byteList;
|
List<int> byteList;
|
||||||
{
|
{
|
||||||
Builder builder = new Builder(initialSize: 0);
|
Builder builder = Builder(initialSize: 0);
|
||||||
int offset = builder.writeListUint32(<int>[1, 2, 0x9ABCDEF0]);
|
int offset = builder.writeListUint32(<int>[1, 2, 0x9ABCDEF0]);
|
||||||
byteList = builder.finish(offset);
|
builder.finish(offset);
|
||||||
|
byteList = builder.buffer;
|
||||||
}
|
}
|
||||||
// read and verify
|
// read and verify
|
||||||
BufferContext buf = new BufferContext.fromBytes(byteList);
|
BufferContext buf = BufferContext.fromBytes(byteList);
|
||||||
List<int> items = const Uint32ListReader().read(buf, 0);
|
List<int> items = const Uint32ListReader().read(buf, 0);
|
||||||
expect(items, hasLength(3));
|
expect(items, hasLength(3));
|
||||||
expect(items, orderedEquals(<int>[1, 2, 0x9ABCDEF0]));
|
expect(items, orderedEquals(<int>[1, 2, 0x9ABCDEF0]));
|
||||||
@@ -572,12 +651,13 @@ class BuilderTest {
|
|||||||
void test_writeList_ofUint16() {
|
void test_writeList_ofUint16() {
|
||||||
List<int> byteList;
|
List<int> byteList;
|
||||||
{
|
{
|
||||||
Builder builder = new Builder(initialSize: 0);
|
Builder builder = Builder(initialSize: 0);
|
||||||
int offset = builder.writeListUint16(<int>[1, 2, 60000]);
|
int offset = builder.writeListUint16(<int>[1, 2, 60000]);
|
||||||
byteList = builder.finish(offset);
|
builder.finish(offset);
|
||||||
|
byteList = builder.buffer;
|
||||||
}
|
}
|
||||||
// read and verify
|
// read and verify
|
||||||
BufferContext buf = new BufferContext.fromBytes(byteList);
|
BufferContext buf = BufferContext.fromBytes(byteList);
|
||||||
List<int> items = const Uint16ListReader().read(buf, 0);
|
List<int> items = const Uint16ListReader().read(buf, 0);
|
||||||
expect(items, hasLength(3));
|
expect(items, hasLength(3));
|
||||||
expect(items, orderedEquals(<int>[1, 2, 60000]));
|
expect(items, orderedEquals(<int>[1, 2, 60000]));
|
||||||
@@ -586,15 +666,188 @@ class BuilderTest {
|
|||||||
void test_writeList_ofUint8() {
|
void test_writeList_ofUint8() {
|
||||||
List<int> byteList;
|
List<int> byteList;
|
||||||
{
|
{
|
||||||
Builder builder = new Builder(initialSize: 0);
|
Builder builder = Builder(initialSize: 0);
|
||||||
int offset = builder.writeListUint8(<int>[1, 2, 3, 4, 0x9A]);
|
int offset = builder.writeListUint8(<int>[1, 2, 3, 4, 0x9A, 0xFA]);
|
||||||
byteList = builder.finish(offset);
|
builder.finish(offset);
|
||||||
|
byteList = builder.buffer;
|
||||||
}
|
}
|
||||||
// read and verify
|
// read and verify
|
||||||
BufferContext buf = new BufferContext.fromBytes(byteList);
|
BufferContext buf = BufferContext.fromBytes(byteList);
|
||||||
List<int> items = const Uint8ListReader().read(buf, 0);
|
const buffOffset = 8; // 32-bit offset to the list, + 32-bit length
|
||||||
expect(items, hasLength(5));
|
for (final lazy in [true, false]) {
|
||||||
expect(items, orderedEquals(<int>[1, 2, 3, 4, 0x9A]));
|
List<int> items = Uint8ListReader(lazy: lazy).read(buf, 0);
|
||||||
|
expect(items, hasLength(6));
|
||||||
|
expect(items, orderedEquals(<int>[1, 2, 3, 4, 0x9A, 0xFA]));
|
||||||
|
|
||||||
|
// overwrite the buffer to verify the laziness
|
||||||
|
buf.buffer.setUint8(buffOffset + 1, 99);
|
||||||
|
expect(items, orderedEquals(<int>[1, lazy ? 99 : 2, 3, 4, 0x9A, 0xFA]));
|
||||||
|
|
||||||
|
// restore the previous value for the next loop
|
||||||
|
buf.buffer.setUint8(buffOffset + 1, 2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void test_reset() {
|
||||||
|
// We'll run a selection of tests , reusing the builder between them.
|
||||||
|
final testCases = <void Function(Builder?)>[
|
||||||
|
test_monsterBuilder,
|
||||||
|
test_error_addInt32_withoutStartTable,
|
||||||
|
test_table_format,
|
||||||
|
test_table_types,
|
||||||
|
test_writeList_ofObjects,
|
||||||
|
test_writeList_ofStrings_inObject
|
||||||
|
];
|
||||||
|
|
||||||
|
// Execute all test cases in all permutations of their order.
|
||||||
|
// To do that, we generate permutations of test case indexes.
|
||||||
|
final testCasesPermutations =
|
||||||
|
_permutationsOf(List.generate(testCases.length, (index) => index));
|
||||||
|
expect(testCasesPermutations.length, _factorial(testCases.length));
|
||||||
|
|
||||||
|
for (var indexes in testCasesPermutations) {
|
||||||
|
// print the order so failures are reproducible
|
||||||
|
printOnFailure('Running reset() test cases in order: $indexes');
|
||||||
|
|
||||||
|
Builder? builder;
|
||||||
|
for (var index in indexes) {
|
||||||
|
if (builder == null) {
|
||||||
|
// Initial size small enough so at least one test case increases it.
|
||||||
|
// On the other hand, it's large enough so that some test cases don't.
|
||||||
|
builder = Builder(initialSize: 32);
|
||||||
|
} else {
|
||||||
|
builder.reset();
|
||||||
|
}
|
||||||
|
testCases[index](builder);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Generate permutations of the given list
|
||||||
|
List<List<T>> _permutationsOf<T>(List<T> source) {
|
||||||
|
final result = <List<T>>[];
|
||||||
|
|
||||||
|
void permutate(List<T> items, int startAt) {
|
||||||
|
for (var i = startAt; i < items.length; i++) {
|
||||||
|
List<T> permutation = items.toList(growable: false);
|
||||||
|
permutation[i] = items[startAt];
|
||||||
|
permutation[startAt] = items[i];
|
||||||
|
|
||||||
|
// add the current list upon reaching the end
|
||||||
|
if (startAt == items.length - 1) {
|
||||||
|
result.add(items);
|
||||||
|
} else {
|
||||||
|
permutate(permutation, startAt + 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
permutate(source, 0);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
// a very simple implementation of n!
|
||||||
|
int _factorial(int n) {
|
||||||
|
var result = 1;
|
||||||
|
for (var i = 2; i <= n; i++) {
|
||||||
|
result *= i;
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@reflectiveTest
|
||||||
|
class ObjectAPITest {
|
||||||
|
void test_tableStat() {
|
||||||
|
final object1 = example.StatT(count: 3, id: "foo", val: 4);
|
||||||
|
expect(object1 is Packable, isTrue);
|
||||||
|
final fbb = Builder();
|
||||||
|
fbb.finish(object1.pack(fbb));
|
||||||
|
final object2 = example.Stat(fbb.buffer).unpack();
|
||||||
|
expect(object2.count, object1.count);
|
||||||
|
expect(object2.id, object1.id);
|
||||||
|
expect(object2.val, object1.val);
|
||||||
|
expect(object2.toString(), object1.toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
void test_tableMonster() {
|
||||||
|
final monster = example.MonsterT()
|
||||||
|
..pos = example.Vec3T(
|
||||||
|
x: 1,
|
||||||
|
y: 2,
|
||||||
|
z: 3,
|
||||||
|
test1: 4.0,
|
||||||
|
test2: example.Color.Red,
|
||||||
|
test3: example.TestT(a: 1, b: 2))
|
||||||
|
..mana = 2
|
||||||
|
..name = 'Monstrous'
|
||||||
|
..inventory = [24, 42]
|
||||||
|
..color = example.Color.Green
|
||||||
|
// TODO be smarter for unions and automatically set the `type` field?
|
||||||
|
..testType = example.AnyTypeId.MyGame_Example2_Monster
|
||||||
|
..test = example2.MonsterT()
|
||||||
|
..test4 = [example.TestT(a: 3, b: 4), example.TestT(a: 5, b: 6)]
|
||||||
|
..testarrayofstring = ["foo", "bar"]
|
||||||
|
..testarrayoftables = [example.MonsterT(name: 'Oof')]
|
||||||
|
..enemy = example.MonsterT(name: 'Enemy')
|
||||||
|
..testarrayofbools = [false, true, false]
|
||||||
|
..testf = 42.24
|
||||||
|
..testarrayofsortedstruct = [
|
||||||
|
example.AbilityT(id: 1, distance: 5),
|
||||||
|
example.AbilityT(id: 3, distance: 7)
|
||||||
|
]
|
||||||
|
..vectorOfLongs = [5, 6, 7]
|
||||||
|
..vectorOfDoubles = [8.9, 9.0, 10.1, 11.2]
|
||||||
|
..anyAmbiguousType = example.AnyAmbiguousAliasesTypeId.M2
|
||||||
|
..anyAmbiguous = null
|
||||||
|
..vectorOfEnums = [example.Color.Blue, example.Color.Green]
|
||||||
|
..signedEnum = example.Race.None;
|
||||||
|
|
||||||
|
final fbBuilder = Builder();
|
||||||
|
final offset = monster.pack(fbBuilder);
|
||||||
|
expect(offset, isNonZero);
|
||||||
|
fbBuilder.finish(offset);
|
||||||
|
final data = fbBuilder.buffer;
|
||||||
|
|
||||||
|
// TODO currently broken because of struct builder issue, see #6688
|
||||||
|
// final monster2 = example.Monster(data); // Monster (reader)
|
||||||
|
// expect(
|
||||||
|
// // map Monster => MonsterT, Vec3 => Vec3T, ...
|
||||||
|
// monster2.toString().replaceAllMapped(
|
||||||
|
// RegExp('([a-zA-z0-9]+){'), (match) => match.group(1) + 'T{'),
|
||||||
|
// monster.toString());
|
||||||
|
//
|
||||||
|
// final monster3 = monster2.unpack(); // MonsterT
|
||||||
|
// expect(monster3.toString(), monster.toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
void test_Lists() {
|
||||||
|
// Ensure unpack() reads lists eagerly by reusing the same builder and
|
||||||
|
// overwriting data. Why: because standard reader reads lists lazily...
|
||||||
|
final fbb = Builder();
|
||||||
|
|
||||||
|
final object1 = example.TypeAliasesT(v8: [1, 2, 3], vf64: [5, 6]);
|
||||||
|
fbb.finish(object1.pack(fbb));
|
||||||
|
final object1Read = example.TypeAliases(fbb.buffer).unpack();
|
||||||
|
|
||||||
|
// overwrite the original buffer by writing to the same builder
|
||||||
|
fbb.reset();
|
||||||
|
final object2 = example.TypeAliasesT(v8: [7, 8, 9], vf64: [10, 11]);
|
||||||
|
fbb.finish(object2.pack(fbb));
|
||||||
|
final object2Read = example.TypeAliases(fbb.buffer).unpack();
|
||||||
|
|
||||||
|
// this is fine even with lazy lists:
|
||||||
|
expect(object2.toString(), object2Read.toString());
|
||||||
|
|
||||||
|
// this fails with lazy lists:
|
||||||
|
expect(object1.toString(), object1Read.toString());
|
||||||
|
|
||||||
|
// empty list must be serialized as such (were stored NULL before v2.0)
|
||||||
|
fbb.reset();
|
||||||
|
final object3 = example.TypeAliasesT(v8: [], vf64: null);
|
||||||
|
fbb.finish(object3.pack(fbb));
|
||||||
|
final object3Read = example.TypeAliases(fbb.buffer).unpack();
|
||||||
|
expect(object3.toString(), object3Read.toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -604,8 +857,8 @@ class StringListWrapperImpl {
|
|||||||
|
|
||||||
StringListWrapperImpl(this.bp, this.offset);
|
StringListWrapperImpl(this.bp, this.offset);
|
||||||
|
|
||||||
List<String> get items => const ListReader<String>(const StringReader())
|
List<String>? get items => const ListReader<String>(StringReader())
|
||||||
.vTableGet(bp, offset, indexToField(0));
|
.vTableGetNullable(bp, offset, indexToField(0));
|
||||||
}
|
}
|
||||||
|
|
||||||
class StringListWrapperReader extends TableReader<StringListWrapperImpl> {
|
class StringListWrapperReader extends TableReader<StringListWrapperImpl> {
|
||||||
@@ -613,7 +866,7 @@ class StringListWrapperReader extends TableReader<StringListWrapperImpl> {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
StringListWrapperImpl createObject(BufferContext object, int offset) {
|
StringListWrapperImpl createObject(BufferContext object, int offset) {
|
||||||
return new StringListWrapperImpl(object, offset);
|
return StringListWrapperImpl(object, offset);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -633,7 +886,7 @@ class TestPointReader extends TableReader<TestPointImpl> {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
TestPointImpl createObject(BufferContext object, int offset) {
|
TestPointImpl createObject(BufferContext object, int offset) {
|
||||||
return new TestPointImpl(object, offset);
|
return TestPointImpl(object, offset);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -643,7 +896,38 @@ 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, same(example.AnyUniqueAliasesTypeId.values));
|
expect(example.AnyUniqueAliasesTypeId.values,
|
||||||
expect(example.AnyAmbiguousAliasesTypeId.values, same(example.AnyAmbiguousAliasesTypeId.values));
|
same(example.AnyUniqueAliasesTypeId.values));
|
||||||
|
expect(example.AnyAmbiguousAliasesTypeId.values,
|
||||||
|
same(example.AnyAmbiguousAliasesTypeId.values));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// See #6869
|
||||||
|
@reflectiveTest
|
||||||
|
class ListOfEnumsTest {
|
||||||
|
void test_listOfEnums() async {
|
||||||
|
var mytable = example3.MyTableObjectBuilder(options: [
|
||||||
|
example3.OptionsEnum.A,
|
||||||
|
example3.OptionsEnum.B,
|
||||||
|
example3.OptionsEnum.C
|
||||||
|
]);
|
||||||
|
var bytes = mytable.toBytes();
|
||||||
|
var mytable_read = example3.MyTable(bytes);
|
||||||
|
expect(mytable_read.options![0].value, example3.OptionsEnum.A.value);
|
||||||
|
expect(mytable_read.options![1].value, example3.OptionsEnum.B.value);
|
||||||
|
expect(mytable_read.options![2].value, example3.OptionsEnum.C.value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@reflectiveTest
|
||||||
|
class BoolInStructTest {
|
||||||
|
void test_boolInStruct() async {
|
||||||
|
var mystruct = example4.FooObjectBuilder(
|
||||||
|
myFoo: example4.FooPropertiesObjectBuilder(a: true, b: false));
|
||||||
|
var bytes = mystruct.toBytes();
|
||||||
|
var mystruct_read = example4.Foo(bytes);
|
||||||
|
expect(mystruct_read.myFoo!.a, true);
|
||||||
|
expect(mystruct_read.myFoo!.b, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -58,18 +58,18 @@ void main() {
|
|||||||
{
|
{
|
||||||
var flx = Builder();
|
var flx = Builder();
|
||||||
flx.addString('hello 😱');
|
flx.addString('hello 😱');
|
||||||
expect(flx.finish(), [10, 104, 101, 108, 108, 111, 32, 240, 159, 152, 177, 0, 11, 20, 1]);
|
expect(flx.finish(),
|
||||||
|
[10, 104, 101, 108, 108, 111, 32, 240, 159, 152, 177, 0, 11, 20, 1]);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
test('build vector', (){
|
test('build vector', () {
|
||||||
{
|
{
|
||||||
var flx = Builder()
|
var flx = Builder()
|
||||||
..startVector()
|
..startVector()
|
||||||
..addInt(1)
|
..addInt(1)
|
||||||
..addInt(2)
|
..addInt(2)
|
||||||
..end()
|
..end();
|
||||||
;
|
|
||||||
expect(flx.finish(), [1, 2, 2, 64, 1]);
|
expect(flx.finish(), [1, 2, 2, 64, 1]);
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
@@ -77,8 +77,7 @@ void main() {
|
|||||||
..startVector()
|
..startVector()
|
||||||
..addInt(-1)
|
..addInt(-1)
|
||||||
..addInt(256)
|
..addInt(256)
|
||||||
..end()
|
..end();
|
||||||
;
|
|
||||||
expect(flx.finish(), [255, 255, 0, 1, 4, 65, 1]);
|
expect(flx.finish(), [255, 255, 0, 1, 4, 65, 1]);
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
@@ -86,8 +85,7 @@ void main() {
|
|||||||
..startVector()
|
..startVector()
|
||||||
..addInt(-45)
|
..addInt(-45)
|
||||||
..addInt(256000)
|
..addInt(256000)
|
||||||
..end()
|
..end();
|
||||||
;
|
|
||||||
expect(flx.finish(), [211, 255, 255, 255, 0, 232, 3, 0, 8, 66, 1]);
|
expect(flx.finish(), [211, 255, 255, 255, 0, 232, 3, 0, 8, 66, 1]);
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
@@ -95,9 +93,28 @@ void main() {
|
|||||||
..startVector()
|
..startVector()
|
||||||
..addDouble(1.1)
|
..addDouble(1.1)
|
||||||
..addDouble(-256)
|
..addDouble(-256)
|
||||||
..end()
|
..end();
|
||||||
;
|
expect(flx.finish(), [
|
||||||
expect(flx.finish(), [154, 153, 153, 153, 153, 153, 241, 63, 0, 0, 0, 0, 0, 0, 112, 192, 16, 75, 1]);
|
154,
|
||||||
|
153,
|
||||||
|
153,
|
||||||
|
153,
|
||||||
|
153,
|
||||||
|
153,
|
||||||
|
241,
|
||||||
|
63,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
112,
|
||||||
|
192,
|
||||||
|
16,
|
||||||
|
75,
|
||||||
|
1
|
||||||
|
]);
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
var flx = Builder()
|
var flx = Builder()
|
||||||
@@ -105,8 +122,7 @@ void main() {
|
|||||||
..addInt(1)
|
..addInt(1)
|
||||||
..addInt(2)
|
..addInt(2)
|
||||||
..addInt(4)
|
..addInt(4)
|
||||||
..end()
|
..end();
|
||||||
;
|
|
||||||
expect(flx.finish(), [1, 2, 4, 3, 76, 1]);
|
expect(flx.finish(), [1, 2, 4, 3, 76, 1]);
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
@@ -115,19 +131,17 @@ void main() {
|
|||||||
..addInt(-1)
|
..addInt(-1)
|
||||||
..addInt(256)
|
..addInt(256)
|
||||||
..addInt(4)
|
..addInt(4)
|
||||||
..end()
|
..end();
|
||||||
;
|
|
||||||
expect(flx.finish(), [255, 255, 0, 1, 4, 0, 6, 77, 1]);
|
expect(flx.finish(), [255, 255, 0, 1, 4, 0, 6, 77, 1]);
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
var flx = Builder()
|
var flx = Builder()
|
||||||
..startVector()
|
..startVector()
|
||||||
..startVector()
|
..startVector()
|
||||||
..addInt(61)
|
..addInt(61)
|
||||||
..end()
|
|
||||||
..addInt(64)
|
|
||||||
..end()
|
..end()
|
||||||
;
|
..addInt(64)
|
||||||
|
..end();
|
||||||
expect(flx.finish(), [1, 61, 2, 2, 64, 44, 4, 4, 40, 1]);
|
expect(flx.finish(), [1, 61, 2, 2, 64, 44, 4, 4, 40, 1]);
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
@@ -136,9 +150,31 @@ void main() {
|
|||||||
..addString('foo')
|
..addString('foo')
|
||||||
..addString('bar')
|
..addString('bar')
|
||||||
..addString('baz')
|
..addString('baz')
|
||||||
..end()
|
..end();
|
||||||
;
|
expect(flx.finish(), [
|
||||||
expect(flx.finish(), [3, 102, 111, 111, 0, 3, 98, 97, 114, 0, 3, 98, 97, 122, 0, 3, 15, 11, 7, 3, 60, 1]);
|
3,
|
||||||
|
102,
|
||||||
|
111,
|
||||||
|
111,
|
||||||
|
0,
|
||||||
|
3,
|
||||||
|
98,
|
||||||
|
97,
|
||||||
|
114,
|
||||||
|
0,
|
||||||
|
3,
|
||||||
|
98,
|
||||||
|
97,
|
||||||
|
122,
|
||||||
|
0,
|
||||||
|
3,
|
||||||
|
15,
|
||||||
|
11,
|
||||||
|
7,
|
||||||
|
3,
|
||||||
|
60,
|
||||||
|
1
|
||||||
|
]);
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
var flx = Builder()
|
var flx = Builder()
|
||||||
@@ -149,9 +185,34 @@ void main() {
|
|||||||
..addString('foo')
|
..addString('foo')
|
||||||
..addString('bar')
|
..addString('bar')
|
||||||
..addString('baz')
|
..addString('baz')
|
||||||
..end()
|
..end();
|
||||||
;
|
expect(flx.finish(), [
|
||||||
expect(flx.finish(), [3, 102, 111, 111, 0, 3, 98, 97, 114, 0, 3, 98, 97, 122, 0, 6, 15, 11, 7, 18, 14, 10, 6, 60, 1]);
|
3,
|
||||||
|
102,
|
||||||
|
111,
|
||||||
|
111,
|
||||||
|
0,
|
||||||
|
3,
|
||||||
|
98,
|
||||||
|
97,
|
||||||
|
114,
|
||||||
|
0,
|
||||||
|
3,
|
||||||
|
98,
|
||||||
|
97,
|
||||||
|
122,
|
||||||
|
0,
|
||||||
|
6,
|
||||||
|
15,
|
||||||
|
11,
|
||||||
|
7,
|
||||||
|
18,
|
||||||
|
14,
|
||||||
|
10,
|
||||||
|
6,
|
||||||
|
60,
|
||||||
|
1
|
||||||
|
]);
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
var flx = Builder()
|
var flx = Builder()
|
||||||
@@ -159,8 +220,7 @@ void main() {
|
|||||||
..addBool(true)
|
..addBool(true)
|
||||||
..addBool(false)
|
..addBool(false)
|
||||||
..addBool(true)
|
..addBool(true)
|
||||||
..end()
|
..end();
|
||||||
;
|
|
||||||
expect(flx.finish(), [3, 1, 0, 1, 3, 144, 1]);
|
expect(flx.finish(), [3, 1, 0, 1, 3, 144, 1]);
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
@@ -171,29 +231,83 @@ void main() {
|
|||||||
..addInt(-5)
|
..addInt(-5)
|
||||||
..addDouble(1.3)
|
..addDouble(1.3)
|
||||||
..addBool(true)
|
..addBool(true)
|
||||||
..end()
|
..end();
|
||||||
;
|
|
||||||
expect(flx.finish(), [
|
expect(flx.finish(), [
|
||||||
3, 102, 111, 111, 0, 0, 0, 0,
|
3,
|
||||||
5, 0, 0, 0, 0, 0, 0, 0,
|
102,
|
||||||
15, 0, 0, 0, 0, 0, 0, 0,
|
111,
|
||||||
1, 0, 0, 0, 0, 0, 0, 0,
|
111,
|
||||||
251, 255, 255, 255, 255, 255, 255, 255,
|
0,
|
||||||
205, 204, 204, 204, 204, 204, 244, 63,
|
0,
|
||||||
1, 0, 0, 0, 0, 0, 0, 0,
|
0,
|
||||||
20, 4, 4, 15, 104, 45, 43, 1]);
|
0,
|
||||||
|
5,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
15,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
1,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
251,
|
||||||
|
255,
|
||||||
|
255,
|
||||||
|
255,
|
||||||
|
255,
|
||||||
|
255,
|
||||||
|
255,
|
||||||
|
255,
|
||||||
|
205,
|
||||||
|
204,
|
||||||
|
204,
|
||||||
|
204,
|
||||||
|
204,
|
||||||
|
204,
|
||||||
|
244,
|
||||||
|
63,
|
||||||
|
1,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
20,
|
||||||
|
4,
|
||||||
|
4,
|
||||||
|
15,
|
||||||
|
104,
|
||||||
|
45,
|
||||||
|
43,
|
||||||
|
1
|
||||||
|
]);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
test('build map', ()
|
test('build map', () {
|
||||||
{
|
|
||||||
{
|
{
|
||||||
var flx = Builder()
|
var flx = Builder()
|
||||||
..startMap()
|
..startMap()
|
||||||
..addKey('a')
|
..addKey('a')
|
||||||
..addInt(12)
|
..addInt(12)
|
||||||
..end()
|
..end();
|
||||||
;
|
|
||||||
expect(flx.finish(), [97, 0, 1, 3, 1, 1, 1, 12, 4, 2, 36, 1]);
|
expect(flx.finish(), [97, 0, 1, 3, 1, 1, 1, 12, 4, 2, 36, 1]);
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
@@ -203,105 +317,270 @@ void main() {
|
|||||||
..addInt(12)
|
..addInt(12)
|
||||||
..addKey('')
|
..addKey('')
|
||||||
..addInt(45)
|
..addInt(45)
|
||||||
..end()
|
..end();
|
||||||
;
|
expect(
|
||||||
expect(flx.finish(), [97, 0, 0, 2, 2, 5, 2, 1, 2, 45, 12, 4, 4, 4, 36, 1]);
|
flx.finish(), [97, 0, 0, 2, 2, 5, 2, 1, 2, 45, 12, 4, 4, 4, 36, 1]);
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
var flx = Builder()
|
var flx = Builder()
|
||||||
..startVector()
|
..startVector()
|
||||||
..startMap()
|
..startMap()
|
||||||
..addKey('something')
|
..addKey('something')
|
||||||
..addInt(12)
|
..addInt(12)
|
||||||
..end()
|
|
||||||
..startMap()
|
|
||||||
..addKey('something')
|
|
||||||
..addInt(45)
|
|
||||||
..end()
|
|
||||||
..end()
|
..end()
|
||||||
;
|
..startMap()
|
||||||
expect(flx.finish(), [115, 111, 109, 101, 116, 104, 105, 110, 103, 0,
|
..addKey('something')
|
||||||
1, 11, 1, 1, 1, 12, 4, 6, 1, 1, 45, 4, 2, 8, 4, 36, 36, 4, 40, 1]);
|
..addInt(45)
|
||||||
|
..end()
|
||||||
|
..end();
|
||||||
|
expect(flx.finish(), [
|
||||||
|
115,
|
||||||
|
111,
|
||||||
|
109,
|
||||||
|
101,
|
||||||
|
116,
|
||||||
|
104,
|
||||||
|
105,
|
||||||
|
110,
|
||||||
|
103,
|
||||||
|
0,
|
||||||
|
1,
|
||||||
|
11,
|
||||||
|
1,
|
||||||
|
1,
|
||||||
|
1,
|
||||||
|
12,
|
||||||
|
4,
|
||||||
|
6,
|
||||||
|
1,
|
||||||
|
1,
|
||||||
|
45,
|
||||||
|
4,
|
||||||
|
2,
|
||||||
|
8,
|
||||||
|
4,
|
||||||
|
36,
|
||||||
|
36,
|
||||||
|
4,
|
||||||
|
40,
|
||||||
|
1
|
||||||
|
]);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
test('build blob', ()
|
test('build blob', () {
|
||||||
{
|
|
||||||
{
|
{
|
||||||
var flx = Builder()
|
var flx = Builder()..addBlob(Uint8List.fromList([1, 2, 3]).buffer);
|
||||||
..addBlob(Uint8List.fromList([1, 2, 3]).buffer)
|
|
||||||
;
|
|
||||||
expect(flx.finish(), [3, 1, 2, 3, 3, 100, 1]);
|
expect(flx.finish(), [3, 1, 2, 3, 3, 100, 1]);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
test('build from object', (){
|
test('build from object', () {
|
||||||
expect(Builder.buildFromObject(Uint8List.fromList([1, 2, 3]).buffer).asUint8List(), [3, 1, 2, 3, 3, 100, 1]);
|
expect(
|
||||||
|
Builder.buildFromObject(Uint8List.fromList([1, 2, 3]).buffer)
|
||||||
|
.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(
|
||||||
expect(Builder.buildFromObject('Maxim').asUint8List(), [5, 77, 97, 120, 105, 109, 0, 6, 20, 1]);
|
Builder.buildFromObject(-2.50).asUint8List(), [0, 0, 32, 192, 14, 4]);
|
||||||
expect(Builder.buildFromObject([1, 3.3, 'max', true, null, false]).asUint8List(), [
|
expect(Builder.buildFromObject('Maxim').asUint8List(),
|
||||||
3, 109, 97, 120, 0, 0, 0, 0,
|
[5, 77, 97, 120, 105, 109, 0, 6, 20, 1]);
|
||||||
6, 0, 0, 0, 0, 0, 0, 0,
|
expect(
|
||||||
1, 0, 0, 0, 0, 0, 0, 0,
|
Builder.buildFromObject([1, 3.3, 'max', true, null, false])
|
||||||
102, 102, 102, 102, 102, 102, 10, 64,
|
.asUint8List(),
|
||||||
31, 0, 0, 0, 0, 0, 0, 0,
|
[
|
||||||
1, 0, 0, 0, 0, 0, 0, 0,
|
3,
|
||||||
0, 0, 0, 0, 0, 0, 0, 0,
|
109,
|
||||||
0, 0, 0, 0, 0, 0, 0, 0,
|
97,
|
||||||
4, 15, 20, 104, 0, 104, 54, 43, 1
|
120,
|
||||||
]);
|
0,
|
||||||
expect(Builder.buildFromObject([{'something':12}, {'something': 45}]).asUint8List(), [
|
0,
|
||||||
115, 111, 109, 101, 116, 104, 105, 110, 103, 0,
|
0,
|
||||||
1, 11, 1, 1, 1, 12, 4, 6, 1, 1, 45, 4, 2, 8, 4, 36, 36, 4, 40, 1
|
0,
|
||||||
]);
|
6,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
1,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
102,
|
||||||
|
102,
|
||||||
|
102,
|
||||||
|
102,
|
||||||
|
102,
|
||||||
|
102,
|
||||||
|
10,
|
||||||
|
64,
|
||||||
|
31,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
1,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
4,
|
||||||
|
15,
|
||||||
|
20,
|
||||||
|
104,
|
||||||
|
0,
|
||||||
|
104,
|
||||||
|
54,
|
||||||
|
43,
|
||||||
|
1
|
||||||
|
]);
|
||||||
|
expect(
|
||||||
|
Builder.buildFromObject([
|
||||||
|
{'something': 12},
|
||||||
|
{'something': 45}
|
||||||
|
]).asUint8List(),
|
||||||
|
[
|
||||||
|
115,
|
||||||
|
111,
|
||||||
|
109,
|
||||||
|
101,
|
||||||
|
116,
|
||||||
|
104,
|
||||||
|
105,
|
||||||
|
110,
|
||||||
|
103,
|
||||||
|
0,
|
||||||
|
1,
|
||||||
|
11,
|
||||||
|
1,
|
||||||
|
1,
|
||||||
|
1,
|
||||||
|
12,
|
||||||
|
4,
|
||||||
|
6,
|
||||||
|
1,
|
||||||
|
1,
|
||||||
|
45,
|
||||||
|
4,
|
||||||
|
2,
|
||||||
|
8,
|
||||||
|
4,
|
||||||
|
36,
|
||||||
|
36,
|
||||||
|
4,
|
||||||
|
40,
|
||||||
|
1
|
||||||
|
]);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('add double indirectly', (){
|
test('add double indirectly', () {
|
||||||
var flx = Builder()
|
var flx = Builder()..addDoubleIndirectly(0.1);
|
||||||
..addDoubleIndirectly(0.1)
|
|
||||||
;
|
|
||||||
expect(flx.finish(), [154, 153, 153, 153, 153, 153, 185, 63, 8, 35, 1]);
|
expect(flx.finish(), [154, 153, 153, 153, 153, 153, 185, 63, 8, 35, 1]);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('add double indirectly to vector with cache', (){
|
test('add double indirectly to vector with cache', () {
|
||||||
var flx = Builder()
|
var flx = Builder()
|
||||||
..startVector()
|
..startVector()
|
||||||
..addDoubleIndirectly(0.1, cache: true)
|
..addDoubleIndirectly(0.1, cache: true)
|
||||||
..addDoubleIndirectly(0.1, cache: true)
|
..addDoubleIndirectly(0.1, cache: true)
|
||||||
..addDoubleIndirectly(0.1, cache: true)
|
..addDoubleIndirectly(0.1, cache: true)
|
||||||
..addDoubleIndirectly(0.1, cache: true)
|
..addDoubleIndirectly(0.1, cache: true)
|
||||||
..end()
|
..end();
|
||||||
;
|
expect(flx.finish(), [
|
||||||
expect(flx.finish(), [154, 153, 153, 153, 153, 153, 185, 63,
|
154,
|
||||||
4, 9, 10, 11, 12, 35, 35, 35, 35, 8, 40, 1]);
|
153,
|
||||||
|
153,
|
||||||
|
153,
|
||||||
|
153,
|
||||||
|
153,
|
||||||
|
185,
|
||||||
|
63,
|
||||||
|
4,
|
||||||
|
9,
|
||||||
|
10,
|
||||||
|
11,
|
||||||
|
12,
|
||||||
|
35,
|
||||||
|
35,
|
||||||
|
35,
|
||||||
|
35,
|
||||||
|
8,
|
||||||
|
40,
|
||||||
|
1
|
||||||
|
]);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('add int indirectly', (){
|
test('add int indirectly', () {
|
||||||
var flx = Builder()
|
var flx = Builder()..addIntIndirectly(2345234523452345);
|
||||||
..addIntIndirectly(2345234523452345)
|
|
||||||
;
|
|
||||||
expect(flx.finish(), [185, 115, 175, 118, 250, 84, 8, 0, 8, 27, 1]);
|
expect(flx.finish(), [185, 115, 175, 118, 250, 84, 8, 0, 8, 27, 1]);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('add int indirectly to vector with cache', (){
|
test('add int indirectly to vector with cache', () {
|
||||||
var flx = Builder()
|
var flx = Builder()
|
||||||
..startVector()
|
..startVector()
|
||||||
..addIntIndirectly(2345234523452345, cache: true)
|
..addIntIndirectly(2345234523452345, cache: true)
|
||||||
..addIntIndirectly(2345234523452345, cache: true)
|
..addIntIndirectly(2345234523452345, cache: true)
|
||||||
..addIntIndirectly(2345234523452345, cache: true)
|
..addIntIndirectly(2345234523452345, cache: true)
|
||||||
..addIntIndirectly(2345234523452345, cache: true)
|
..addIntIndirectly(2345234523452345, cache: true)
|
||||||
..end()
|
..end();
|
||||||
;
|
expect(flx.finish(), [
|
||||||
expect(flx.finish(), [185, 115, 175, 118, 250, 84, 8, 0,
|
185,
|
||||||
4, 9, 10, 11, 12, 27, 27, 27, 27, 8, 40, 1]);
|
115,
|
||||||
|
175,
|
||||||
|
118,
|
||||||
|
250,
|
||||||
|
84,
|
||||||
|
8,
|
||||||
|
0,
|
||||||
|
4,
|
||||||
|
9,
|
||||||
|
10,
|
||||||
|
11,
|
||||||
|
12,
|
||||||
|
27,
|
||||||
|
27,
|
||||||
|
27,
|
||||||
|
27,
|
||||||
|
8,
|
||||||
|
40,
|
||||||
|
1
|
||||||
|
]);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('snapshot', (){
|
test('snapshot', () {
|
||||||
var flx = Builder();
|
var flx = Builder();
|
||||||
flx.startVector();
|
flx.startVector();
|
||||||
flx.addInt(12);
|
flx.addInt(12);
|
||||||
@@ -312,4 +591,3 @@ void main() {
|
|||||||
expect(flx.snapshot().asUint8List(), [12, 24, 45, 3, 76, 1]);
|
expect(flx.snapshot().asUint8List(), [12, 24, 45, 3, 76, 1]);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -48,69 +48,116 @@ 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), equals(ValueType.VectorInt));
|
expect(ValueTypeUtils.toTypedVector(ValueType.Int, 0),
|
||||||
expect(ValueTypeUtils.toTypedVector(ValueType.UInt,0), equals(ValueType.VectorUInt));
|
equals(ValueType.VectorInt));
|
||||||
expect(ValueTypeUtils.toTypedVector(ValueType.Bool,0), equals(ValueType.VectorBool));
|
expect(ValueTypeUtils.toTypedVector(ValueType.UInt, 0),
|
||||||
expect(ValueTypeUtils.toTypedVector(ValueType.Float,0), equals(ValueType.VectorFloat));
|
equals(ValueType.VectorUInt));
|
||||||
expect(ValueTypeUtils.toTypedVector(ValueType.Key,0), equals(ValueType.VectorKey));
|
expect(ValueTypeUtils.toTypedVector(ValueType.Bool, 0),
|
||||||
expect(ValueTypeUtils.toTypedVector(ValueType.String,0), equals(ValueType.VectorString));
|
equals(ValueType.VectorBool));
|
||||||
|
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), equals(ValueType.VectorInt2));
|
expect(ValueTypeUtils.toTypedVector(ValueType.Int, 2),
|
||||||
expect(ValueTypeUtils.toTypedVector(ValueType.UInt,2), equals(ValueType.VectorUInt2));
|
equals(ValueType.VectorInt2));
|
||||||
expect(ValueTypeUtils.toTypedVector(ValueType.Float,2), equals(ValueType.VectorFloat2));
|
expect(ValueTypeUtils.toTypedVector(ValueType.UInt, 2),
|
||||||
|
equals(ValueType.VectorUInt2));
|
||||||
|
expect(ValueTypeUtils.toTypedVector(ValueType.Float, 2),
|
||||||
|
equals(ValueType.VectorFloat2));
|
||||||
|
|
||||||
expect(ValueTypeUtils.toTypedVector(ValueType.Int,3), equals(ValueType.VectorInt3));
|
expect(ValueTypeUtils.toTypedVector(ValueType.Int, 3),
|
||||||
expect(ValueTypeUtils.toTypedVector(ValueType.UInt,3), equals(ValueType.VectorUInt3));
|
equals(ValueType.VectorInt3));
|
||||||
expect(ValueTypeUtils.toTypedVector(ValueType.Float,3), equals(ValueType.VectorFloat3));
|
expect(ValueTypeUtils.toTypedVector(ValueType.UInt, 3),
|
||||||
|
equals(ValueType.VectorUInt3));
|
||||||
|
expect(ValueTypeUtils.toTypedVector(ValueType.Float, 3),
|
||||||
|
equals(ValueType.VectorFloat3));
|
||||||
|
|
||||||
expect(ValueTypeUtils.toTypedVector(ValueType.Int,4), equals(ValueType.VectorInt4));
|
expect(ValueTypeUtils.toTypedVector(ValueType.Int, 4),
|
||||||
expect(ValueTypeUtils.toTypedVector(ValueType.UInt,4), equals(ValueType.VectorUInt4));
|
equals(ValueType.VectorInt4));
|
||||||
expect(ValueTypeUtils.toTypedVector(ValueType.Float,4), equals(ValueType.VectorFloat4));
|
expect(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), equals(ValueType.Int));
|
expect(ValueTypeUtils.typedVectorElementType(ValueType.VectorInt),
|
||||||
expect(ValueTypeUtils.typedVectorElementType(ValueType.VectorUInt), equals(ValueType.UInt));
|
equals(ValueType.Int));
|
||||||
expect(ValueTypeUtils.typedVectorElementType(ValueType.VectorFloat), equals(ValueType.Float));
|
expect(ValueTypeUtils.typedVectorElementType(ValueType.VectorUInt),
|
||||||
expect(ValueTypeUtils.typedVectorElementType(ValueType.VectorString), equals(ValueType.String));
|
equals(ValueType.UInt));
|
||||||
expect(ValueTypeUtils.typedVectorElementType(ValueType.VectorKey), equals(ValueType.Key));
|
expect(ValueTypeUtils.typedVectorElementType(ValueType.VectorFloat),
|
||||||
expect(ValueTypeUtils.typedVectorElementType(ValueType.VectorBool), equals(ValueType.Bool));
|
equals(ValueType.Float));
|
||||||
|
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), equals(ValueType.Int));
|
expect(ValueTypeUtils.fixedTypedVectorElementType(ValueType.VectorInt2),
|
||||||
expect(ValueTypeUtils.fixedTypedVectorElementType(ValueType.VectorInt3), equals(ValueType.Int));
|
equals(ValueType.Int));
|
||||||
expect(ValueTypeUtils.fixedTypedVectorElementType(ValueType.VectorInt4), equals(ValueType.Int));
|
expect(ValueTypeUtils.fixedTypedVectorElementType(ValueType.VectorInt3),
|
||||||
|
equals(ValueType.Int));
|
||||||
|
expect(ValueTypeUtils.fixedTypedVectorElementType(ValueType.VectorInt4),
|
||||||
|
equals(ValueType.Int));
|
||||||
|
|
||||||
expect(ValueTypeUtils.fixedTypedVectorElementType(ValueType.VectorUInt2), equals(ValueType.UInt));
|
expect(ValueTypeUtils.fixedTypedVectorElementType(ValueType.VectorUInt2),
|
||||||
expect(ValueTypeUtils.fixedTypedVectorElementType(ValueType.VectorUInt3), equals(ValueType.UInt));
|
equals(ValueType.UInt));
|
||||||
expect(ValueTypeUtils.fixedTypedVectorElementType(ValueType.VectorUInt4), equals(ValueType.UInt));
|
expect(ValueTypeUtils.fixedTypedVectorElementType(ValueType.VectorUInt3),
|
||||||
|
equals(ValueType.UInt));
|
||||||
|
expect(ValueTypeUtils.fixedTypedVectorElementType(ValueType.VectorUInt4),
|
||||||
|
equals(ValueType.UInt));
|
||||||
|
|
||||||
expect(ValueTypeUtils.fixedTypedVectorElementType(ValueType.VectorFloat2), equals(ValueType.Float));
|
expect(ValueTypeUtils.fixedTypedVectorElementType(ValueType.VectorFloat2),
|
||||||
expect(ValueTypeUtils.fixedTypedVectorElementType(ValueType.VectorFloat3), equals(ValueType.Float));
|
equals(ValueType.Float));
|
||||||
expect(ValueTypeUtils.fixedTypedVectorElementType(ValueType.VectorFloat4), equals(ValueType.Float));
|
expect(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), equals(2));
|
expect(ValueTypeUtils.fixedTypedVectorElementSize(ValueType.VectorInt2),
|
||||||
expect(ValueTypeUtils.fixedTypedVectorElementSize(ValueType.VectorInt3), equals(3));
|
equals(2));
|
||||||
expect(ValueTypeUtils.fixedTypedVectorElementSize(ValueType.VectorInt4), equals(4));
|
expect(ValueTypeUtils.fixedTypedVectorElementSize(ValueType.VectorInt3),
|
||||||
|
equals(3));
|
||||||
|
expect(ValueTypeUtils.fixedTypedVectorElementSize(ValueType.VectorInt4),
|
||||||
|
equals(4));
|
||||||
|
|
||||||
expect(ValueTypeUtils.fixedTypedVectorElementSize(ValueType.VectorUInt2), equals(2));
|
expect(ValueTypeUtils.fixedTypedVectorElementSize(ValueType.VectorUInt2),
|
||||||
expect(ValueTypeUtils.fixedTypedVectorElementSize(ValueType.VectorUInt3), equals(3));
|
equals(2));
|
||||||
expect(ValueTypeUtils.fixedTypedVectorElementSize(ValueType.VectorUInt4), equals(4));
|
expect(ValueTypeUtils.fixedTypedVectorElementSize(ValueType.VectorUInt3),
|
||||||
|
equals(3));
|
||||||
|
expect(ValueTypeUtils.fixedTypedVectorElementSize(ValueType.VectorUInt4),
|
||||||
|
equals(4));
|
||||||
|
|
||||||
expect(ValueTypeUtils.fixedTypedVectorElementSize(ValueType.VectorFloat2), equals(2));
|
expect(ValueTypeUtils.fixedTypedVectorElementSize(ValueType.VectorFloat2),
|
||||||
expect(ValueTypeUtils.fixedTypedVectorElementSize(ValueType.VectorFloat3), equals(3));
|
equals(2));
|
||||||
expect(ValueTypeUtils.fixedTypedVectorElementSize(ValueType.VectorFloat4), equals(4));
|
expect(ValueTypeUtils.fixedTypedVectorElementSize(ValueType.VectorFloat3),
|
||||||
|
equals(3));
|
||||||
|
expect(ValueTypeUtils.fixedTypedVectorElementSize(ValueType.VectorFloat4),
|
||||||
|
equals(4));
|
||||||
});
|
});
|
||||||
test('packed type', () {
|
test('packed type', () {
|
||||||
expect(ValueTypeUtils.packedType(ValueType.Null, BitWidth.width8), equals(0));
|
expect(
|
||||||
expect(ValueTypeUtils.packedType(ValueType.Null, BitWidth.width16), equals(1));
|
ValueTypeUtils.packedType(ValueType.Null, BitWidth.width8), equals(0));
|
||||||
expect(ValueTypeUtils.packedType(ValueType.Null, BitWidth.width32), equals(2));
|
expect(
|
||||||
expect(ValueTypeUtils.packedType(ValueType.Null, BitWidth.width64), equals(3));
|
ValueTypeUtils.packedType(ValueType.Null, BitWidth.width16), equals(1));
|
||||||
|
expect(
|
||||||
|
ValueTypeUtils.packedType(ValueType.Null, BitWidth.width32), equals(2));
|
||||||
|
expect(
|
||||||
|
ValueTypeUtils.packedType(ValueType.Null, BitWidth.width64), equals(3));
|
||||||
|
|
||||||
expect(ValueTypeUtils.packedType(ValueType.Int, BitWidth.width8), equals(4));
|
expect(
|
||||||
expect(ValueTypeUtils.packedType(ValueType.Int, BitWidth.width16), equals(5));
|
ValueTypeUtils.packedType(ValueType.Int, BitWidth.width8), equals(4));
|
||||||
expect(ValueTypeUtils.packedType(ValueType.Int, BitWidth.width32), equals(6));
|
expect(
|
||||||
expect(ValueTypeUtils.packedType(ValueType.Int, BitWidth.width64), equals(7));
|
ValueTypeUtils.packedType(ValueType.Int, BitWidth.width16), equals(5));
|
||||||
|
expect(
|
||||||
|
ValueTypeUtils.packedType(ValueType.Int, BitWidth.width32), equals(6));
|
||||||
|
expect(
|
||||||
|
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);
|
||||||
|
|||||||
280
dart/test/keyword_test_keyword_test_generated.dart
Normal file
280
dart/test/keyword_test_keyword_test_generated.dart
Normal file
@@ -0,0 +1,280 @@
|
|||||||
|
// automatically generated by the FlatBuffers compiler, do not modify
|
||||||
|
// ignore_for_file: unused_import, unused_field, unused_element, unused_local_variable
|
||||||
|
|
||||||
|
library keyword_test;
|
||||||
|
|
||||||
|
import 'dart:typed_data' show Uint8List;
|
||||||
|
import 'package:flat_buffers/flat_buffers.dart' as fb;
|
||||||
|
|
||||||
|
|
||||||
|
class Abc {
|
||||||
|
final int value;
|
||||||
|
const Abc._(this.value);
|
||||||
|
|
||||||
|
factory Abc.fromValue(int value) {
|
||||||
|
final result = values[value];
|
||||||
|
if (result == null) {
|
||||||
|
throw StateError('Invalid value $value for bit flag enum Abc');
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
static Abc? _createOrNull(int? value) =>
|
||||||
|
value == null ? null : Abc.fromValue(value);
|
||||||
|
|
||||||
|
static const int minValue = 0;
|
||||||
|
static const int maxValue = 2;
|
||||||
|
static bool containsValue(int value) => values.containsKey(value);
|
||||||
|
|
||||||
|
static const Abc $void = Abc._(0);
|
||||||
|
static const Abc where = Abc._(1);
|
||||||
|
static const Abc stackalloc = Abc._(2);
|
||||||
|
static const Map<int, Abc> values = {
|
||||||
|
0: $void,
|
||||||
|
1: where,
|
||||||
|
2: stackalloc};
|
||||||
|
|
||||||
|
static const fb.Reader<Abc> reader = _AbcReader();
|
||||||
|
|
||||||
|
@override
|
||||||
|
String toString() {
|
||||||
|
return 'Abc{value: $value}';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class _AbcReader extends fb.Reader<Abc> {
|
||||||
|
const _AbcReader();
|
||||||
|
|
||||||
|
@override
|
||||||
|
int get size => 4;
|
||||||
|
|
||||||
|
@override
|
||||||
|
Abc read(fb.BufferContext bc, int offset) =>
|
||||||
|
Abc.fromValue(const fb.Int32Reader().read(bc, offset));
|
||||||
|
}
|
||||||
|
|
||||||
|
class Public {
|
||||||
|
final int value;
|
||||||
|
const Public._(this.value);
|
||||||
|
|
||||||
|
factory Public.fromValue(int value) {
|
||||||
|
final result = values[value];
|
||||||
|
if (result == null) {
|
||||||
|
throw StateError('Invalid value $value for bit flag enum Public');
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
static Public? _createOrNull(int? value) =>
|
||||||
|
value == null ? null : Public.fromValue(value);
|
||||||
|
|
||||||
|
static const int minValue = 0;
|
||||||
|
static const int maxValue = 0;
|
||||||
|
static bool containsValue(int value) => values.containsKey(value);
|
||||||
|
|
||||||
|
static const Public NONE = Public._(0);
|
||||||
|
static const Map<int, Public> values = {
|
||||||
|
0: NONE};
|
||||||
|
|
||||||
|
static const fb.Reader<Public> reader = _PublicReader();
|
||||||
|
|
||||||
|
@override
|
||||||
|
String toString() {
|
||||||
|
return 'Public{value: $value}';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class _PublicReader extends fb.Reader<Public> {
|
||||||
|
const _PublicReader();
|
||||||
|
|
||||||
|
@override
|
||||||
|
int get size => 4;
|
||||||
|
|
||||||
|
@override
|
||||||
|
Public read(fb.BufferContext bc, int offset) =>
|
||||||
|
Public.fromValue(const fb.Int32Reader().read(bc, offset));
|
||||||
|
}
|
||||||
|
|
||||||
|
class KeywordsInUnionTypeId {
|
||||||
|
final int value;
|
||||||
|
const KeywordsInUnionTypeId._(this.value);
|
||||||
|
|
||||||
|
factory KeywordsInUnionTypeId.fromValue(int value) {
|
||||||
|
final result = values[value];
|
||||||
|
if (result == null) {
|
||||||
|
throw StateError('Invalid value $value for bit flag enum KeywordsInUnionTypeId');
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
static KeywordsInUnionTypeId? _createOrNull(int? value) =>
|
||||||
|
value == null ? null : KeywordsInUnionTypeId.fromValue(value);
|
||||||
|
|
||||||
|
static const int minValue = 0;
|
||||||
|
static const int maxValue = 2;
|
||||||
|
static bool containsValue(int value) => values.containsKey(value);
|
||||||
|
|
||||||
|
static const KeywordsInUnionTypeId NONE = KeywordsInUnionTypeId._(0);
|
||||||
|
static const KeywordsInUnionTypeId $static = KeywordsInUnionTypeId._(1);
|
||||||
|
static const KeywordsInUnionTypeId internal = KeywordsInUnionTypeId._(2);
|
||||||
|
static const Map<int, KeywordsInUnionTypeId> values = {
|
||||||
|
0: NONE,
|
||||||
|
1: $static,
|
||||||
|
2: internal};
|
||||||
|
|
||||||
|
static const fb.Reader<KeywordsInUnionTypeId> reader = _KeywordsInUnionTypeIdReader();
|
||||||
|
|
||||||
|
@override
|
||||||
|
String toString() {
|
||||||
|
return 'KeywordsInUnionTypeId{value: $value}';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class _KeywordsInUnionTypeIdReader extends fb.Reader<KeywordsInUnionTypeId> {
|
||||||
|
const _KeywordsInUnionTypeIdReader();
|
||||||
|
|
||||||
|
@override
|
||||||
|
int get size => 1;
|
||||||
|
|
||||||
|
@override
|
||||||
|
KeywordsInUnionTypeId read(fb.BufferContext bc, int offset) =>
|
||||||
|
KeywordsInUnionTypeId.fromValue(const fb.Uint8Reader().read(bc, offset));
|
||||||
|
}
|
||||||
|
|
||||||
|
class KeywordsInTable {
|
||||||
|
KeywordsInTable._(this._bc, this._bcOffset);
|
||||||
|
factory KeywordsInTable(List<int> bytes) {
|
||||||
|
final rootRef = fb.BufferContext.fromBytes(bytes);
|
||||||
|
return reader.read(rootRef, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
static const fb.Reader<KeywordsInTable> reader = _KeywordsInTableReader();
|
||||||
|
|
||||||
|
final fb.BufferContext _bc;
|
||||||
|
final int _bcOffset;
|
||||||
|
|
||||||
|
Abc get $is => Abc.fromValue(const fb.Int32Reader().vTableGet(_bc, _bcOffset, 4, 0));
|
||||||
|
Public get private => Public.fromValue(const fb.Int32Reader().vTableGet(_bc, _bcOffset, 6, 0));
|
||||||
|
int get type => const fb.Int32Reader().vTableGet(_bc, _bcOffset, 8, 0);
|
||||||
|
bool get $default => const fb.BoolReader().vTableGet(_bc, _bcOffset, 10, false);
|
||||||
|
|
||||||
|
@override
|
||||||
|
String toString() {
|
||||||
|
return 'KeywordsInTable{\$is: ${$is}, private: ${private}, type: ${type}, \$default: ${$default}}';
|
||||||
|
}
|
||||||
|
|
||||||
|
KeywordsInTableT unpack() => KeywordsInTableT(
|
||||||
|
$is: $is,
|
||||||
|
private: private,
|
||||||
|
type: type,
|
||||||
|
$default: $default);
|
||||||
|
|
||||||
|
static int pack(fb.Builder fbBuilder, KeywordsInTableT? object) {
|
||||||
|
if (object == null) return 0;
|
||||||
|
return object.pack(fbBuilder);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class KeywordsInTableT implements fb.Packable {
|
||||||
|
Abc $is;
|
||||||
|
Public private;
|
||||||
|
int type;
|
||||||
|
bool $default;
|
||||||
|
|
||||||
|
KeywordsInTableT({
|
||||||
|
this.$is = Abc.$void,
|
||||||
|
this.private = Public.NONE,
|
||||||
|
this.type = 0,
|
||||||
|
this.$default = false});
|
||||||
|
|
||||||
|
@override
|
||||||
|
int pack(fb.Builder fbBuilder) {
|
||||||
|
fbBuilder.startTable(4);
|
||||||
|
fbBuilder.addInt32(0, $is.value);
|
||||||
|
fbBuilder.addInt32(1, private.value);
|
||||||
|
fbBuilder.addInt32(2, type);
|
||||||
|
fbBuilder.addBool(3, $default);
|
||||||
|
return fbBuilder.endTable();
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
String toString() {
|
||||||
|
return 'KeywordsInTableT{\$is: ${$is}, private: ${private}, type: ${type}, \$default: ${$default}}';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class _KeywordsInTableReader extends fb.TableReader<KeywordsInTable> {
|
||||||
|
const _KeywordsInTableReader();
|
||||||
|
|
||||||
|
@override
|
||||||
|
KeywordsInTable createObject(fb.BufferContext bc, int offset) =>
|
||||||
|
KeywordsInTable._(bc, offset);
|
||||||
|
}
|
||||||
|
|
||||||
|
class KeywordsInTableBuilder {
|
||||||
|
KeywordsInTableBuilder(this.fbBuilder);
|
||||||
|
|
||||||
|
final fb.Builder fbBuilder;
|
||||||
|
|
||||||
|
void begin() {
|
||||||
|
fbBuilder.startTable(4);
|
||||||
|
}
|
||||||
|
|
||||||
|
int addIs(Abc? $is) {
|
||||||
|
fbBuilder.addInt32(0, $is?.value);
|
||||||
|
return fbBuilder.offset;
|
||||||
|
}
|
||||||
|
int addPrivate(Public? private) {
|
||||||
|
fbBuilder.addInt32(1, private?.value);
|
||||||
|
return fbBuilder.offset;
|
||||||
|
}
|
||||||
|
int addType(int? type) {
|
||||||
|
fbBuilder.addInt32(2, type);
|
||||||
|
return fbBuilder.offset;
|
||||||
|
}
|
||||||
|
int addDefault(bool? $default) {
|
||||||
|
fbBuilder.addBool(3, $default);
|
||||||
|
return fbBuilder.offset;
|
||||||
|
}
|
||||||
|
|
||||||
|
int finish() {
|
||||||
|
return fbBuilder.endTable();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class KeywordsInTableObjectBuilder extends fb.ObjectBuilder {
|
||||||
|
final Abc? _$is;
|
||||||
|
final Public? _private;
|
||||||
|
final int? _type;
|
||||||
|
final bool? _$default;
|
||||||
|
|
||||||
|
KeywordsInTableObjectBuilder({
|
||||||
|
Abc? $is,
|
||||||
|
Public? private,
|
||||||
|
int? type,
|
||||||
|
bool? $default,
|
||||||
|
})
|
||||||
|
: _$is = $is,
|
||||||
|
_private = private,
|
||||||
|
_type = type,
|
||||||
|
_$default = $default;
|
||||||
|
|
||||||
|
/// Finish building, and store into the [fbBuilder].
|
||||||
|
@override
|
||||||
|
int finish(fb.Builder fbBuilder) {
|
||||||
|
fbBuilder.startTable(4);
|
||||||
|
fbBuilder.addInt32(0, _$is?.value);
|
||||||
|
fbBuilder.addInt32(1, _private?.value);
|
||||||
|
fbBuilder.addInt32(2, _type);
|
||||||
|
fbBuilder.addBool(3, _$default);
|
||||||
|
return fbBuilder.endTable();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Convenience method to serialize to byte list.
|
||||||
|
@override
|
||||||
|
Uint8List toBytes([String? fileIdentifier]) {
|
||||||
|
final fbBuilder = fb.Builder(deduplicateTables: false);
|
||||||
|
fbBuilder.finish(finish(fbBuilder), fileIdentifier);
|
||||||
|
return fbBuilder.buffer;
|
||||||
|
}
|
||||||
|
}
|
||||||
10
dart/test/list_of_enums.fbs
Normal file
10
dart/test/list_of_enums.fbs
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
enum OptionsEnum : uint32
|
||||||
|
{
|
||||||
|
A = 1,
|
||||||
|
B = 2,
|
||||||
|
C = 3
|
||||||
|
}
|
||||||
|
|
||||||
|
table MyTable {
|
||||||
|
options : [OptionsEnum];
|
||||||
|
}
|
||||||
154
dart/test/monster_test.fbs
Normal file
154
dart/test/monster_test.fbs
Normal file
@@ -0,0 +1,154 @@
|
|||||||
|
// test schema file
|
||||||
|
|
||||||
|
include "include_test1.fbs";
|
||||||
|
|
||||||
|
namespace MyGame;
|
||||||
|
|
||||||
|
table InParentNamespace {}
|
||||||
|
|
||||||
|
namespace MyGame.Example2;
|
||||||
|
|
||||||
|
table Monster {} // Test having same name as below, but in different namespace.
|
||||||
|
|
||||||
|
namespace MyGame.Example;
|
||||||
|
|
||||||
|
attribute "priority";
|
||||||
|
|
||||||
|
/// Composite components of Monster color.
|
||||||
|
enum Color:ubyte (bit_flags) {
|
||||||
|
Red = 0, // color Red = (1u << 0)
|
||||||
|
/// \brief color Green
|
||||||
|
/// Green is bit_flag with value (1u << 1)
|
||||||
|
Green,
|
||||||
|
/// \brief color Blue (1u << 3)
|
||||||
|
Blue = 3,
|
||||||
|
}
|
||||||
|
|
||||||
|
enum Race:byte {
|
||||||
|
None = -1,
|
||||||
|
Human = 0,
|
||||||
|
Dwarf,
|
||||||
|
Elf,
|
||||||
|
}
|
||||||
|
|
||||||
|
union Any { Monster, TestSimpleTableWithEnum, MyGame.Example2.Monster }
|
||||||
|
|
||||||
|
union AnyUniqueAliases { M: Monster, TS: TestSimpleTableWithEnum, M2: MyGame.Example2.Monster }
|
||||||
|
union AnyAmbiguousAliases { M1: Monster, M2: Monster, M3: Monster }
|
||||||
|
|
||||||
|
struct Test { a:short; b:byte; }
|
||||||
|
|
||||||
|
table TestSimpleTableWithEnum (csharp_partial, private) {
|
||||||
|
color: Color = Green;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct Vec3 (force_align: 8) {
|
||||||
|
x:float;
|
||||||
|
y:float;
|
||||||
|
z:float;
|
||||||
|
test1:double;
|
||||||
|
test2:Color;
|
||||||
|
test3:Test;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct Ability {
|
||||||
|
id:uint(key);
|
||||||
|
distance:uint;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct StructOfStructs {
|
||||||
|
a: Ability;
|
||||||
|
b: Test;
|
||||||
|
c: Ability;
|
||||||
|
}
|
||||||
|
|
||||||
|
table Stat {
|
||||||
|
id:string;
|
||||||
|
val:long;
|
||||||
|
count:ushort (key);
|
||||||
|
}
|
||||||
|
|
||||||
|
table Referrable {
|
||||||
|
id:ulong(key, hash:"fnv1a_64");
|
||||||
|
}
|
||||||
|
|
||||||
|
/// an example documentation comment: "monster object"
|
||||||
|
table Monster {
|
||||||
|
pos:Vec3 (id: 0);
|
||||||
|
hp:short = 100 (id: 2);
|
||||||
|
mana:short = 150 (id: 1);
|
||||||
|
name:string (id: 3, key);
|
||||||
|
color:Color = Blue (id: 6);
|
||||||
|
inventory:[ubyte] (id: 5);
|
||||||
|
friendly:bool = false (deprecated, priority: 1, id: 4);
|
||||||
|
/// an example documentation comment: this will end up in the generated code
|
||||||
|
/// multiline too
|
||||||
|
testarrayoftables:[Monster] (id: 11);
|
||||||
|
testarrayofstring:[string] (id: 10);
|
||||||
|
testarrayofstring2:[string] (id: 28);
|
||||||
|
testarrayofbools:[bool] (id: 24);
|
||||||
|
testarrayofsortedstruct:[Ability] (id: 29);
|
||||||
|
enemy:MyGame.Example.Monster (id:12); // Test referring by full namespace.
|
||||||
|
test:Any (id: 8);
|
||||||
|
test4:[Test] (id: 9);
|
||||||
|
test5:[Test] (id: 31);
|
||||||
|
testnestedflatbuffer:[ubyte] (id:13, nested_flatbuffer: "Monster");
|
||||||
|
testempty:Stat (id:14);
|
||||||
|
testbool:bool (id:15);
|
||||||
|
testhashs32_fnv1:int (id:16, hash:"fnv1_32");
|
||||||
|
testhashu32_fnv1:uint (id:17, hash:"fnv1_32");
|
||||||
|
testhashs64_fnv1:long (id:18, hash:"fnv1_64");
|
||||||
|
testhashu64_fnv1:ulong (id:19, hash:"fnv1_64");
|
||||||
|
testhashs32_fnv1a:int (id:20, hash:"fnv1a_32");
|
||||||
|
testhashu32_fnv1a:uint (id:21, hash:"fnv1a_32", cpp_type:"Stat");
|
||||||
|
testhashs64_fnv1a:long (id:22, hash:"fnv1a_64");
|
||||||
|
testhashu64_fnv1a:ulong (id:23, hash:"fnv1a_64");
|
||||||
|
testf:float = 3.14159 (id:25);
|
||||||
|
testf2:float = 3 (id:26);
|
||||||
|
testf3:float (id:27);
|
||||||
|
flex:[ubyte] (id:30, flexbuffer);
|
||||||
|
vector_of_longs:[long] (id:32);
|
||||||
|
vector_of_doubles:[double] (id:33);
|
||||||
|
parent_namespace_test:InParentNamespace (id:34);
|
||||||
|
vector_of_referrables:[Referrable](id:35);
|
||||||
|
single_weak_reference:ulong(id:36, hash:"fnv1a_64", cpp_type:"ReferrableT");
|
||||||
|
vector_of_weak_references:[ulong](id:37, hash:"fnv1a_64", cpp_type:"ReferrableT");
|
||||||
|
vector_of_strong_referrables:[Referrable](id:38, cpp_ptr_type:"default_ptr_type"); //was shared_ptr
|
||||||
|
co_owning_reference:ulong(id:39, hash:"fnv1a_64", cpp_type:"ReferrableT", cpp_ptr_type:"naked"); //was shared_ptr as well
|
||||||
|
vector_of_co_owning_references:[ulong](id:40, hash:"fnv1a_64", cpp_type:"ReferrableT", cpp_ptr_type:"default_ptr_type", cpp_ptr_type_get:".get()"); //was shared_ptr
|
||||||
|
non_owning_reference:ulong(id:41, hash:"fnv1a_64", cpp_type:"ReferrableT", cpp_ptr_type:"naked", cpp_ptr_type_get:""); //was weak_ptr
|
||||||
|
vector_of_non_owning_references:[ulong](id:42, hash:"fnv1a_64", cpp_type:"ReferrableT", cpp_ptr_type:"naked", cpp_ptr_type_get:""); //was weak_ptr
|
||||||
|
any_unique:AnyUniqueAliases(id:44);
|
||||||
|
any_ambiguous:AnyAmbiguousAliases (id:46);
|
||||||
|
vector_of_enums:[Color] (id:47);
|
||||||
|
signed_enum:Race = None (id:48);
|
||||||
|
testrequirednestedflatbuffer:[ubyte] (id:49, nested_flatbuffer: "Monster");
|
||||||
|
scalar_key_sorted_tables:[Stat] (id: 50);
|
||||||
|
}
|
||||||
|
|
||||||
|
table TypeAliases {
|
||||||
|
i8:int8;
|
||||||
|
u8:uint8;
|
||||||
|
i16:int16;
|
||||||
|
u16:uint16;
|
||||||
|
i32:int32;
|
||||||
|
u32:uint32;
|
||||||
|
i64:int64;
|
||||||
|
u64:uint64;
|
||||||
|
f32:float32;
|
||||||
|
f64:float64;
|
||||||
|
v8:[int8];
|
||||||
|
vf64:[float64];
|
||||||
|
}
|
||||||
|
|
||||||
|
rpc_service MonsterStorage {
|
||||||
|
Store(Monster):Stat (streaming: "none");
|
||||||
|
Retrieve(Stat):Monster (streaming: "server", idempotent);
|
||||||
|
GetMaxHitPoint(Monster):Stat (streaming: "client");
|
||||||
|
GetMinMaxHitPoints(Monster):Stat (streaming: "bidi");
|
||||||
|
}
|
||||||
|
|
||||||
|
root_type Monster;
|
||||||
|
|
||||||
|
file_identifier "MONS";
|
||||||
|
file_extension "mon";
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
// automatically generated by the FlatBuffers compiler, do not modify
|
// automatically generated by the FlatBuffers compiler, do not modify
|
||||||
// ignore_for_file: unused_import, unused_field, unused_local_variable
|
// ignore_for_file: unused_import, unused_field, unused_element, unused_local_variable
|
||||||
|
|
||||||
library my_game.example2;
|
library my_game.example2;
|
||||||
|
|
||||||
@@ -12,11 +12,11 @@ import './monster_test_my_game.example_generated.dart' as my_game_example;
|
|||||||
class Monster {
|
class Monster {
|
||||||
Monster._(this._bc, this._bcOffset);
|
Monster._(this._bc, this._bcOffset);
|
||||||
factory Monster(List<int> bytes) {
|
factory Monster(List<int> bytes) {
|
||||||
fb.BufferContext rootRef = new fb.BufferContext.fromBytes(bytes);
|
final rootRef = fb.BufferContext.fromBytes(bytes);
|
||||||
return reader.read(rootRef, 0);
|
return reader.read(rootRef, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
static const fb.Reader<Monster> reader = const _MonsterReader();
|
static const fb.Reader<Monster> reader = _MonsterReader();
|
||||||
|
|
||||||
final fb.BufferContext _bc;
|
final fb.BufferContext _bc;
|
||||||
final int _bcOffset;
|
final int _bcOffset;
|
||||||
@@ -26,6 +26,26 @@ class Monster {
|
|||||||
String toString() {
|
String toString() {
|
||||||
return 'Monster{}';
|
return 'Monster{}';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
MonsterT unpack() => MonsterT();
|
||||||
|
|
||||||
|
static int pack(fb.Builder fbBuilder, MonsterT? object) {
|
||||||
|
if (object == null) return 0;
|
||||||
|
return object.pack(fbBuilder);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class MonsterT implements fb.Packable {
|
||||||
|
@override
|
||||||
|
int pack(fb.Builder fbBuilder) {
|
||||||
|
fbBuilder.startTable(0);
|
||||||
|
return fbBuilder.endTable();
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
String toString() {
|
||||||
|
return 'MonsterT{}';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class _MonsterReader extends fb.TableReader<Monster> {
|
class _MonsterReader extends fb.TableReader<Monster> {
|
||||||
@@ -33,7 +53,7 @@ class _MonsterReader extends fb.TableReader<Monster> {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Monster createObject(fb.BufferContext bc, int offset) =>
|
Monster createObject(fb.BufferContext bc, int offset) =>
|
||||||
new Monster._(bc, offset);
|
Monster._(bc, offset);
|
||||||
}
|
}
|
||||||
|
|
||||||
class MonsterObjectBuilder extends fb.ObjectBuilder {
|
class MonsterObjectBuilder extends fb.ObjectBuilder {
|
||||||
@@ -42,19 +62,16 @@ class MonsterObjectBuilder extends fb.ObjectBuilder {
|
|||||||
|
|
||||||
/// Finish building, and store into the [fbBuilder].
|
/// Finish building, and store into the [fbBuilder].
|
||||||
@override
|
@override
|
||||||
int finish(
|
int finish(fb.Builder fbBuilder) {
|
||||||
fb.Builder fbBuilder) {
|
fbBuilder.startTable(0);
|
||||||
assert(fbBuilder != null);
|
|
||||||
|
|
||||||
fbBuilder.startTable();
|
|
||||||
return fbBuilder.endTable();
|
return fbBuilder.endTable();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Convenience method to serialize to byte list.
|
/// Convenience method to serialize to byte list.
|
||||||
@override
|
@override
|
||||||
Uint8List toBytes([String fileIdentifier]) {
|
Uint8List toBytes([String? fileIdentifier]) {
|
||||||
fb.Builder fbBuilder = new fb.Builder();
|
final fbBuilder = fb.Builder(deduplicateTables: false);
|
||||||
int offset = finish(fbBuilder);
|
fbBuilder.finish(finish(fbBuilder), fileIdentifier);
|
||||||
return fbBuilder.finish(offset, fileIdentifier);
|
return fbBuilder.buffer;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -1,5 +1,5 @@
|
|||||||
// automatically generated by the FlatBuffers compiler, do not modify
|
// automatically generated by the FlatBuffers compiler, do not modify
|
||||||
// ignore_for_file: unused_import, unused_field, unused_local_variable
|
// ignore_for_file: unused_import, unused_field, unused_element, unused_local_variable
|
||||||
|
|
||||||
library my_game;
|
library my_game;
|
||||||
|
|
||||||
@@ -12,11 +12,11 @@ import './monster_test_my_game.example2_generated.dart' as my_game_example2;
|
|||||||
class InParentNamespace {
|
class InParentNamespace {
|
||||||
InParentNamespace._(this._bc, this._bcOffset);
|
InParentNamespace._(this._bc, this._bcOffset);
|
||||||
factory InParentNamespace(List<int> bytes) {
|
factory InParentNamespace(List<int> bytes) {
|
||||||
fb.BufferContext rootRef = new fb.BufferContext.fromBytes(bytes);
|
final rootRef = fb.BufferContext.fromBytes(bytes);
|
||||||
return reader.read(rootRef, 0);
|
return reader.read(rootRef, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
static const fb.Reader<InParentNamespace> reader = const _InParentNamespaceReader();
|
static const fb.Reader<InParentNamespace> reader = _InParentNamespaceReader();
|
||||||
|
|
||||||
final fb.BufferContext _bc;
|
final fb.BufferContext _bc;
|
||||||
final int _bcOffset;
|
final int _bcOffset;
|
||||||
@@ -26,6 +26,26 @@ class InParentNamespace {
|
|||||||
String toString() {
|
String toString() {
|
||||||
return 'InParentNamespace{}';
|
return 'InParentNamespace{}';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
InParentNamespaceT unpack() => InParentNamespaceT();
|
||||||
|
|
||||||
|
static int pack(fb.Builder fbBuilder, InParentNamespaceT? object) {
|
||||||
|
if (object == null) return 0;
|
||||||
|
return object.pack(fbBuilder);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class InParentNamespaceT implements fb.Packable {
|
||||||
|
@override
|
||||||
|
int pack(fb.Builder fbBuilder) {
|
||||||
|
fbBuilder.startTable(0);
|
||||||
|
return fbBuilder.endTable();
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
String toString() {
|
||||||
|
return 'InParentNamespaceT{}';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class _InParentNamespaceReader extends fb.TableReader<InParentNamespace> {
|
class _InParentNamespaceReader extends fb.TableReader<InParentNamespace> {
|
||||||
@@ -33,7 +53,7 @@ class _InParentNamespaceReader extends fb.TableReader<InParentNamespace> {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
InParentNamespace createObject(fb.BufferContext bc, int offset) =>
|
InParentNamespace createObject(fb.BufferContext bc, int offset) =>
|
||||||
new InParentNamespace._(bc, offset);
|
InParentNamespace._(bc, offset);
|
||||||
}
|
}
|
||||||
|
|
||||||
class InParentNamespaceObjectBuilder extends fb.ObjectBuilder {
|
class InParentNamespaceObjectBuilder extends fb.ObjectBuilder {
|
||||||
@@ -42,19 +62,16 @@ class InParentNamespaceObjectBuilder extends fb.ObjectBuilder {
|
|||||||
|
|
||||||
/// Finish building, and store into the [fbBuilder].
|
/// Finish building, and store into the [fbBuilder].
|
||||||
@override
|
@override
|
||||||
int finish(
|
int finish(fb.Builder fbBuilder) {
|
||||||
fb.Builder fbBuilder) {
|
fbBuilder.startTable(0);
|
||||||
assert(fbBuilder != null);
|
|
||||||
|
|
||||||
fbBuilder.startTable();
|
|
||||||
return fbBuilder.endTable();
|
return fbBuilder.endTable();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Convenience method to serialize to byte list.
|
/// Convenience method to serialize to byte list.
|
||||||
@override
|
@override
|
||||||
Uint8List toBytes([String fileIdentifier]) {
|
Uint8List toBytes([String? fileIdentifier]) {
|
||||||
fb.Builder fbBuilder = new fb.Builder();
|
final fbBuilder = fb.Builder(deduplicateTables: false);
|
||||||
int offset = finish(fbBuilder);
|
fbBuilder.finish(finish(fbBuilder), fileIdentifier);
|
||||||
return fbBuilder.finish(offset, fileIdentifier);
|
return fbBuilder.buffer;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
BIN
dart/test/monsterdata_test.mon
Normal file
BIN
dart/test/monsterdata_test.mon
Normal file
Binary file not shown.
@@ -31,24 +31,22 @@ run 'flattests' or `flatsampletext`, or it will fail to load its files.*
|
|||||||
|
|
||||||
### Make all warnings into errors
|
### Make all warnings into errors
|
||||||
|
|
||||||
By default all Flatbuffers `cmake` targets are build with `-Werror` flag.
|
By default all Flatbuffers `cmake` targets are **not** built with the `-Werror`
|
||||||
With this flag (or `/WX` for MSVC) C++ compiler will treat all warnings as errors.
|
(or `/WX` for MSVC) flag that treats any warning as an error. This allows more
|
||||||
Additionally `-Wall -pedantic -Wextra` (or `/W4` form MSVC) flags are set.
|
flexibility for users of Flatbuffers to use newer compilers and toolsets that
|
||||||
These flags minimize the number of possible defects in code and keep code highly portable.
|
may add new warnings that would cause a build failure.
|
||||||
Using these flags is considered good practice but sometimes it can break dependent projects
|
|
||||||
if a compiler is upgraded or a toolset is changed.
|
|
||||||
Usually, newer compiler versions add new compile-time diagnostics that were unavailable before.
|
|
||||||
These new diagnostic warnings could stop the build process if `-Werror` flag is set.
|
|
||||||
|
|
||||||
It is possible to cancel `warnings as errors` flag at `cmake` configuration stage using
|
To enable a stricter build that does treat warnings as errors, set the
|
||||||
`FLATBUFFERS_CXX_FLAGS` option. Compilation flags declared in `FLATBUFFERS_CXX_FLAGS` will be
|
`FLATBUFFERS_STRICT_MODE` `cmake` compliation flag to `ON`.
|
||||||
appended to the project-level `CMAKE_CXX_FLAGS` variable.
|
|
||||||
Examples:
|
|
||||||
|
|
||||||
- GCC and Clang: `cmake . -D FLATBUFFERS_CXX_FLAGS="-Wno-error"`
|
```
|
||||||
- MSVC: `cmake . -D FLATBUFFERS_CXX_FLAGS="/WX-"`
|
cmake . -DFLATBUFFERS_STRICT_MODE=ON
|
||||||
- MSVC: `cmake . -D FLATBUFFERS_CXX_FLAGS="/Wv <compiler.version>"`
|
```
|
||||||
|
|
||||||
|
Our CI builds run with strict mode on, ensuring the code that is committed to
|
||||||
|
the project is as portable and warning free as possible. Thus developers
|
||||||
|
contributing to the project should enable strict mode locally before making a
|
||||||
|
PR.
|
||||||
|
|
||||||
## Building with VCPKG
|
## Building with VCPKG
|
||||||
|
|
||||||
@@ -63,6 +61,18 @@ You can download and install flatbuffers using the [vcpkg](https://github.com/Mi
|
|||||||
The flatbuffers port in vcpkg is kept up to date by Microsoft team members and community contributors.
|
The flatbuffers port in vcpkg is kept up to date by Microsoft team members and community contributors.
|
||||||
If the version is out of date, please [create an issue or pull request](https://github.com/Microsoft/vcpkg) on the vcpkg repository.
|
If the version is out of date, please [create an issue or pull request](https://github.com/Microsoft/vcpkg) on the vcpkg repository.
|
||||||
|
|
||||||
|
## Downloading binaries
|
||||||
|
You can download the binaries from the
|
||||||
|
[GitHub release page](https://github.com/google/flatbuffers/releases).
|
||||||
|
|
||||||
|
We generate [SLSA3 signatures](slsa.dev) using the OpenSSF's [slsa-framework/slsa-github-generator](https://github.com/slsa-framework/slsa-github-generator). To verify the binaries:
|
||||||
|
1. Install the verification tool from [slsa-framework/slsa-verifier#installation](https://github.com/slsa-framework/slsa-verifier#installation)
|
||||||
|
1. Download the file named `attestation.intoto.jsonl` from the GitHub release
|
||||||
|
1. Run:
|
||||||
|
```shell
|
||||||
|
$ slsa-verifier -artifact-path <downloaded.zip> -provenance attestation.intoto.jsonl -source github.com/google/flatbuffers -tag <version>
|
||||||
|
PASSED: Verified SLSA provenance
|
||||||
|
|
||||||
## Building for Android
|
## Building for Android
|
||||||
|
|
||||||
There is a `flatbuffers/android` directory that contains all you need to build
|
There is a `flatbuffers/android` directory that contains all you need to build
|
||||||
@@ -121,14 +131,3 @@ add this directive:
|
|||||||
set(FLATBUFFERS_MAX_PARSING_DEPTH 16)
|
set(FLATBUFFERS_MAX_PARSING_DEPTH 16)
|
||||||
```
|
```
|
||||||
to `CMakeLists.txt` file before `add_subdirectory(${FLATBUFFERS_SRC_DIR})` line.
|
to `CMakeLists.txt` file before `add_subdirectory(${FLATBUFFERS_SRC_DIR})` line.
|
||||||
|
|
||||||
#### For Google Play apps
|
|
||||||
|
|
||||||
For applications on Google Play that integrate this library, usage is tracked.
|
|
||||||
This tracking is done automatically using the embedded version string
|
|
||||||
(flatbuffer_version_string), and helps us continue to optimize it.
|
|
||||||
Aside from consuming a few extra bytes in your application binary, it shouldn't
|
|
||||||
affect your application at all. We use this information to let us know if
|
|
||||||
FlatBuffers is useful and if we should continue to invest in it. Since this is
|
|
||||||
open source, you are free to remove the version string but we would appreciate
|
|
||||||
if you would leave it in.
|
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ The `flatcc` C schema compiler can generate code offline as well as
|
|||||||
online via a C library. It can also generate buffer verifiers and fast
|
online via a C library. It can also generate buffer verifiers and fast
|
||||||
JSON parsers, printers.
|
JSON parsers, printers.
|
||||||
|
|
||||||
Great care has been taken to ensure compatibily with the main `flatc`
|
Great care has been taken to ensure compatibility with the main `flatc`
|
||||||
project.
|
project.
|
||||||
|
|
||||||
## General Documention
|
## General Documention
|
||||||
|
|||||||
@@ -79,7 +79,7 @@ Additional options:
|
|||||||
- `--allow-non-utf8` : Pass non-UTF-8 input through parser and emit nonstandard
|
- `--allow-non-utf8` : Pass non-UTF-8 input through parser and emit nonstandard
|
||||||
\x escapes in JSON. (Default is to raise parse error on non-UTF-8 input.)
|
\x escapes in JSON. (Default is to raise parse error on non-UTF-8 input.)
|
||||||
|
|
||||||
- `--natural-utf8` : Output strings with UTF-8 as human-readable strings.
|
- `--natural-utf8` : Output strings with UTF-8 as human-readable strings.
|
||||||
By default, UTF-8 characters are printed as \uXXXX escapes."
|
By default, UTF-8 characters are printed as \uXXXX escapes."
|
||||||
|
|
||||||
- `--defaults-json` : Output fields whose value is equal to the default value
|
- `--defaults-json` : Output fields whose value is equal to the default value
|
||||||
@@ -101,7 +101,7 @@ Additional options:
|
|||||||
- `--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# and Go.
|
- `--gen-onefile` : Generate single output file for C#, Go, and Python.
|
||||||
|
|
||||||
- `--gen-name-strings` : Generate type name functions for C++.
|
- `--gen-name-strings` : Generate type name functions for C++.
|
||||||
|
|
||||||
@@ -216,7 +216,13 @@ Additional options:
|
|||||||
- `--flexbuffers` : Used with "binary" and "json" options, it generates
|
- `--flexbuffers` : Used with "binary" and "json" options, it generates
|
||||||
data using schema-less FlexBuffers.
|
data using schema-less FlexBuffers.
|
||||||
|
|
||||||
- `--no-warnings` : Inhibit all warning messages.
|
- `--no-warnings` : Inhibit all warning messages.
|
||||||
|
|
||||||
|
- `--cs-global-alias` : Prepend `global::` to all user generated csharp classes and structs.
|
||||||
|
|
||||||
|
- `--json-nested-bytes` : Allow a nested_flatbuffer field to be parsed as a
|
||||||
|
vector of bytes in JSON, which is unsafe unless checked by a verifier
|
||||||
|
afterwards.
|
||||||
|
|
||||||
NOTE: short-form options for generators are deprecated, use the long form
|
NOTE: short-form options for generators are deprecated, use the long form
|
||||||
whenever possible.
|
whenever possible.
|
||||||
|
|||||||
@@ -56,7 +56,7 @@ For example, here is how you would read a FlatBuffer binary file in C++:
|
|||||||
First, include the library and generated code. Then read the file into
|
First, include the library and generated code. Then read the file into
|
||||||
a `char *` array, which you pass to `GetMonster()`.
|
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_generate.h"
|
||||||
#include <iostream> // C++ header file for printing
|
#include <iostream> // C++ header file for printing
|
||||||
@@ -73,18 +73,18 @@ a `char *` array, which you pass to `GetMonster()`.
|
|||||||
infile.close();
|
infile.close();
|
||||||
|
|
||||||
auto monster = GetMonster(data);
|
auto monster = GetMonster(data);
|
||||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
```
|
||||||
|
|
||||||
`monster` is of type `Monster *`, and points to somewhere *inside* your
|
`monster` is of type `Monster *`, and points to somewhere *inside* your
|
||||||
buffer (root object pointers are not the same as `buffer_pointer` !).
|
buffer (root object pointers are not the same as `buffer_pointer` \!).
|
||||||
If you look in your generated header, you'll see it has
|
If you look in your generated header, you'll see it has
|
||||||
convenient accessors for all fields, e.g. `hp()`, `mana()`, etc:
|
convenient accessors for all fields, e.g. `hp()`, `mana()`, etc:
|
||||||
|
|
||||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
|
```cpp
|
||||||
std::cout << "hp : " << monster->hp() << std::endl; // `80`
|
std::cout << "hp : " << monster->hp() << std::endl; // '80'
|
||||||
std::cout << "mana : " << monster->mana() << std::endl; // default value of `150`
|
std::cout << "mana : " << monster->mana() << std::endl; // default value of '150'
|
||||||
std::cout << "name : " << monster->name()->c_str() << std::endl; // "MyMonster"
|
std::cout << "name : " << monster->name()->c_str() << std::endl; // "MyMonster"
|
||||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
```
|
||||||
|
|
||||||
*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.*
|
||||||
|
|
||||||
@@ -96,7 +96,7 @@ The following attributes are supported:
|
|||||||
Specifically, `CreateXxxDirect` functions and `Pack` functions for object
|
Specifically, `CreateXxxDirect` functions and `Pack` functions for object
|
||||||
based API (see below) will use `CreateSharedString` to create strings.
|
based API (see below) will use `CreateSharedString` to create strings.
|
||||||
|
|
||||||
## Object based API. {#flatbuffers_cpp_object_based_api}
|
## Object based API {#flatbuffers_cpp_object_based_api}
|
||||||
|
|
||||||
FlatBuffers is all about memory efficiency, which is why its base API is written
|
FlatBuffers is all about memory efficiency, which is why its base API is written
|
||||||
around using as little as possible of it. This does make the API clumsier
|
around using as little as possible of it. This does make the API clumsier
|
||||||
@@ -109,7 +109,7 @@ construction, access and mutation.
|
|||||||
|
|
||||||
To use:
|
To use:
|
||||||
|
|
||||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
|
```cpp
|
||||||
// Autogenerated class from table Monster.
|
// Autogenerated class from table Monster.
|
||||||
MonsterT monsterobj;
|
MonsterT monsterobj;
|
||||||
|
|
||||||
@@ -123,7 +123,7 @@ To use:
|
|||||||
// Serialize into new flatbuffer.
|
// Serialize into new flatbuffer.
|
||||||
FlatBufferBuilder fbb;
|
FlatBufferBuilder fbb;
|
||||||
fbb.Finish(Monster::Pack(fbb, &monsterobj));
|
fbb.Finish(Monster::Pack(fbb, &monsterobj));
|
||||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
```
|
||||||
|
|
||||||
The following attributes are specific to the object-based API code generation:
|
The following attributes are specific to the object-based API code generation:
|
||||||
|
|
||||||
@@ -144,19 +144,19 @@ The following attributes are specific to the object-based API code generation:
|
|||||||
This can be used to provide allocation from a pool for example, for faster
|
This can be used to provide allocation from a pool for example, for faster
|
||||||
unpacking when using the object-based API.
|
unpacking when using the object-based API.
|
||||||
|
|
||||||
Minimal Example:
|
Minimal Example:
|
||||||
|
|
||||||
schema:
|
schema:
|
||||||
|
|
||||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
|
```cpp
|
||||||
table mytable(native_custom_alloc:"custom_allocator") {
|
table mytable(native_custom_alloc:"custom_allocator") {
|
||||||
...
|
...
|
||||||
}
|
}
|
||||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
```
|
||||||
|
|
||||||
with custom_allocator defined before `flatbuffers.h` is included, as:
|
with `custom_allocator` defined before `flatbuffers.h` is included, as:
|
||||||
|
|
||||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
|
```cpp
|
||||||
template <typename T> struct custom_allocator : public std::allocator<T> {
|
template <typename T> struct custom_allocator : public std::allocator<T> {
|
||||||
|
|
||||||
typedef T *pointer;
|
typedef T *pointer;
|
||||||
@@ -175,34 +175,35 @@ The following attributes are specific to the object-based API code generation:
|
|||||||
}
|
}
|
||||||
|
|
||||||
custom_allocator() throw() {}
|
custom_allocator() throw() {}
|
||||||
|
|
||||||
template <class U>
|
template <class U>
|
||||||
custom_allocator(const custom_allocator<U>&) throw() {}
|
custom_allocator(const custom_allocator<U>&) throw() {}
|
||||||
};
|
};
|
||||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
```
|
||||||
|
|
||||||
- `native_type("type")` (on a struct): In some cases, a more optimal C++ data
|
- `native_type("type")` (on a struct): In some cases, a more optimal C++ data
|
||||||
type exists for a given struct. For example, the following schema:
|
type exists for a given struct. For example, the following schema:
|
||||||
|
|
||||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
|
```cpp
|
||||||
struct Vec2 {
|
struct Vec2 {
|
||||||
x: float;
|
x: float;
|
||||||
y: float;
|
y: float;
|
||||||
}
|
}
|
||||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
```
|
||||||
|
|
||||||
generates the following Object-Based API class:
|
generates the following Object-Based API class:
|
||||||
|
|
||||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
|
```cpp
|
||||||
struct Vec2T : flatbuffers::NativeTable {
|
struct Vec2T : flatbuffers::NativeTable {
|
||||||
float x;
|
float x;
|
||||||
float y;
|
float y;
|
||||||
};
|
};
|
||||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
```
|
||||||
|
|
||||||
However, it can be useful to instead use a user-defined C++ type since it
|
However, it can be useful to instead use a user-defined C++ type since it
|
||||||
can provide more functionality, eg.
|
can provide more functionality, eg.
|
||||||
|
|
||||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
|
```cpp
|
||||||
struct vector2 {
|
struct vector2 {
|
||||||
float x = 0, y = 0;
|
float x = 0, y = 0;
|
||||||
vector2 operator+(vector2 rhs) const { ... }
|
vector2 operator+(vector2 rhs) const { ... }
|
||||||
@@ -210,22 +211,22 @@ The following attributes are specific to the object-based API code generation:
|
|||||||
float length() const { ... }
|
float length() const { ... }
|
||||||
// etc.
|
// etc.
|
||||||
};
|
};
|
||||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
```
|
||||||
|
|
||||||
The `native_type` attribute will replace the usage of the generated class
|
The `native_type` attribute will replace the usage of the generated class
|
||||||
with the given type. So, continuing with the example, the generated
|
with the given type. So, continuing with the example, the generated
|
||||||
code would use `vector2` in place of `Vec2T` for all generated code of
|
code would use `vector2` in place of `Vec2T` for all generated code of
|
||||||
the Object-Based API.
|
the Object-Based API.
|
||||||
|
|
||||||
However, because the `native_type` is unknown to flatbuffers, the user must
|
However, because the `native_type` is unknown to flatbuffers, the user must
|
||||||
provide the following functions to aide in the serialization process:
|
provide the following functions to aide in the serialization process:
|
||||||
|
|
||||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
|
```cpp
|
||||||
namespace flatbuffers {
|
namespace flatbuffers {
|
||||||
Vec2 Pack(const vector2& obj);
|
Vec2 Pack(const vector2& obj);
|
||||||
vector2 UnPack(const Vec2& obj);
|
vector2 UnPack(const Vec2& obj);
|
||||||
}
|
}
|
||||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
```
|
||||||
|
|
||||||
- `native_type_pack_name("name")` (on a struct when `native_type` is
|
- `native_type_pack_name("name")` (on a struct when `native_type` is
|
||||||
specified, too): when you want to use the same `native_type` multiple times
|
specified, too): when you want to use the same `native_type` multiple times
|
||||||
@@ -235,12 +236,12 @@ The following attributes are specific to the object-based API code generation:
|
|||||||
specify `native_type_pack_name("Vec2")` in the above example you now need to
|
specify `native_type_pack_name("Vec2")` in the above example you now need to
|
||||||
implement these serialization functions instead:
|
implement these serialization functions instead:
|
||||||
|
|
||||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
|
```cpp
|
||||||
namespace flatbuffers {
|
namespace flatbuffers {
|
||||||
Vec2 PackVec2(const vector2& obj);
|
Vec2 PackVec2(const vector2& obj);
|
||||||
vector2 UnPackVec2(const Vec2& obj);
|
vector2 UnPackVec2(const Vec2& obj);
|
||||||
}
|
}
|
||||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
```
|
||||||
|
|
||||||
Finally, the following top-level attributes:
|
Finally, the following top-level attributes:
|
||||||
|
|
||||||
@@ -253,7 +254,7 @@ Finally, the following top-level attributes:
|
|||||||
- `force_align`: this attribute may not be respected in the object API,
|
- `force_align`: this attribute may not be respected in the object API,
|
||||||
depending on the aligned of the allocator used with `new`.
|
depending on the aligned of the allocator used with `new`.
|
||||||
|
|
||||||
# External references.
|
# External references
|
||||||
|
|
||||||
An additional feature of the object API is the ability to allow you to load
|
An additional feature of the object API is the ability to allow you to load
|
||||||
multiple independent FlatBuffers, and have them refer to eachothers objects
|
multiple independent FlatBuffers, and have them refer to eachothers objects
|
||||||
@@ -272,7 +273,7 @@ same string (or hash).
|
|||||||
When you call `UnPack` (or `Create`), you'll need a function that maps from
|
When you call `UnPack` (or `Create`), you'll need a function that maps from
|
||||||
hash to the object (see `resolver_function_t` for details).
|
hash to the object (see `resolver_function_t` for details).
|
||||||
|
|
||||||
# Using different pointer types.
|
# Using different pointer types
|
||||||
|
|
||||||
By default the object tree is built out of `std::unique_ptr`, but you can
|
By default the object tree is built out of `std::unique_ptr`, but you can
|
||||||
influence this either globally (using the `--cpp-ptr-type` argument to
|
influence this either globally (using the `--cpp-ptr-type` argument to
|
||||||
@@ -283,13 +284,13 @@ you, so you'll have to manage their lifecycles manually. To reference the
|
|||||||
pointer type specified by the `--cpp-ptr-type` argument to `flatc` from a
|
pointer type specified by the `--cpp-ptr-type` argument to `flatc` from a
|
||||||
flatbuffer field set the `cpp_ptr_type` attribute to `default_ptr_type`.
|
flatbuffer field set the `cpp_ptr_type` attribute to `default_ptr_type`.
|
||||||
|
|
||||||
# Using different string type.
|
# Using different string type
|
||||||
|
|
||||||
By default the object tree is built out of `std::string`, but you can
|
By default the object tree is built out of `std::string`, but you can
|
||||||
influence this either globally (using the `--cpp-str-type` argument to
|
influence this either globally (using the `--cpp-str-type` argument to
|
||||||
`flatc`) or per field using the `cpp_str_type` attribute.
|
`flatc`) or per field using the `cpp_str_type` attribute.
|
||||||
|
|
||||||
The type must support T::c_str(), T::length() and T::empty() as member functions.
|
The type must support `T::c_str()`, `T::length()` and `T::empty()` as member functions.
|
||||||
|
|
||||||
Further, the type must be constructible from std::string, as by default a
|
Further, the type must be constructible from std::string, as by default a
|
||||||
std::string instance is constructed and then used to initialize the custom
|
std::string instance is constructed and then used to initialize the custom
|
||||||
@@ -298,7 +299,7 @@ custom string types; the `--cpp-str-flex-ctor` argument to `flatc` or the
|
|||||||
per field attribute `cpp_str_flex_ctor` can be used to change this behavior,
|
per field attribute `cpp_str_flex_ctor` can be used to change this behavior,
|
||||||
so that the custom string type is constructed by passing the pointer and
|
so that the custom string type is constructed by passing the pointer and
|
||||||
length of the FlatBuffers String. The custom string class will require a
|
length of the FlatBuffers String. The custom string class will require a
|
||||||
constructor in the following format: custom_str_class(const char *, size_t).
|
constructor in the following format: `custom_str_class(const char *, size_t)`.
|
||||||
Please note that the character array is not guaranteed to be NULL terminated,
|
Please note that the character array is not guaranteed to be NULL terminated,
|
||||||
you should always use the provided size to determine end of string.
|
you should always use the provided size to determine end of string.
|
||||||
|
|
||||||
@@ -309,7 +310,7 @@ 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 and vectors in-place.
|
even allows you to change sizes of strings and vectors in-place.
|
||||||
|
|
||||||
The way this works is very elegant; there is actually a FlatBuffer schema that
|
The way this works is very elegant; there is actually a FlatBuffer schema that
|
||||||
describes schemas (!) which you can find in `reflection/reflection.fbs`.
|
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
|
The compiler, `flatc`, can write out any schemas it has just parsed as a binary
|
||||||
FlatBuffer, corresponding to this meta-schema.
|
FlatBuffer, corresponding to this meta-schema.
|
||||||
|
|
||||||
@@ -418,9 +419,9 @@ is accessed, all reads will end up inside the buffer.
|
|||||||
Each root type will have a verification function generated for it,
|
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));
|
bool ok = VerifyMonsterBuffer(Verifier(buf, len));
|
||||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
```
|
||||||
|
|
||||||
if `ok` is true, the buffer is safe to read.
|
if `ok` is true, the buffer is safe to read.
|
||||||
|
|
||||||
@@ -486,15 +487,15 @@ Load text (either a schema or json) into an in-memory buffer (there is a
|
|||||||
convenient `LoadFile()` utility function in `flatbuffers/util.h` if you
|
convenient `LoadFile()` utility function in `flatbuffers/util.h` if you
|
||||||
wish). Construct a parser:
|
wish). Construct a parser:
|
||||||
|
|
||||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
|
```cpp
|
||||||
flatbuffers::Parser parser;
|
flatbuffers::Parser parser;
|
||||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
```
|
||||||
|
|
||||||
Now you can parse any number of text files in sequence:
|
Now you can parse any number of text files in sequence:
|
||||||
|
|
||||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
|
```cpp
|
||||||
parser.Parse(text_file.c_str());
|
parser.Parse(text_file.c_str());
|
||||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
```
|
||||||
|
|
||||||
This works similarly to how the command-line compiler works: a sequence
|
This works similarly to how the command-line compiler works: a sequence
|
||||||
of files parsed by the same `Parser` object allow later files to
|
of files parsed by the same `Parser` object allow later files to
|
||||||
@@ -526,7 +527,7 @@ Creating a FlatBuffer is not thread safe. All state related to building
|
|||||||
a FlatBuffer is contained in a FlatBufferBuilder instance, and no memory
|
a FlatBuffer is contained in a FlatBufferBuilder instance, and no memory
|
||||||
outside of it is touched. To make this thread safe, either do not
|
outside of it is touched. To make this thread safe, either do not
|
||||||
share instances of FlatBufferBuilder between threads (recommended), or
|
share instances of FlatBufferBuilder between threads (recommended), or
|
||||||
manually wrap it in synchronisation primites. There's no automatic way to
|
manually wrap it in synchronisation primitives. There's no automatic way to
|
||||||
accomplish this, by design, as we feel multithreaded construction
|
accomplish this, by design, as we feel multithreaded construction
|
||||||
of a single buffer will be rare, and synchronisation overhead would be costly.
|
of a single buffer will be rare, and synchronisation overhead would be costly.
|
||||||
|
|
||||||
|
|||||||
@@ -180,7 +180,8 @@ To use:
|
|||||||
An additional feature of the object API is the ability to allow you to
|
An additional feature of the object API is the ability to allow you to
|
||||||
serialize & deserialize a JSON text.
|
serialize & deserialize a JSON text.
|
||||||
To use Json Serialization, add `--cs-gen-json-serializer` option to `flatc` and
|
To use Json Serialization, add `--cs-gen-json-serializer` option to `flatc` and
|
||||||
add `Newtonsoft.Json` nuget package to csproj.
|
add `Newtonsoft.Json` nuget package to csproj. This requires explicitly setting
|
||||||
|
the `--gen-object-api` option as well.
|
||||||
|
|
||||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cs}
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cs}
|
||||||
// Deserialize MonsterT from json
|
// Deserialize MonsterT from json
|
||||||
@@ -192,7 +193,7 @@ add `Newtonsoft.Json` nuget package to csproj.
|
|||||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
* Limitation
|
* Limitation
|
||||||
* `hash` attribute currentry not supported.
|
* `hash` attribute currently not supported.
|
||||||
* NuGet package Dependency
|
* NuGet package Dependency
|
||||||
* [Newtonsoft.Json](https://github.com/JamesNK/Newtonsoft.Json)
|
* [Newtonsoft.Json](https://github.com/JamesNK/Newtonsoft.Json)
|
||||||
|
|
||||||
|
|||||||
@@ -105,4 +105,27 @@ Please see the C++ documentation for more on text parsing (note that this is
|
|||||||
not currently an option in Flutter - follow [this issue](https://github.com/flutter/flutter/issues/7053)
|
not currently an option in Flutter - follow [this issue](https://github.com/flutter/flutter/issues/7053)
|
||||||
for the latest).
|
for the latest).
|
||||||
|
|
||||||
<br>
|
## Object based API
|
||||||
|
|
||||||
|
FlatBuffers is all about memory efficiency, which is why its base API is written
|
||||||
|
around using as little as possible of it. This does make the API clumsier
|
||||||
|
(requiring pre-order construction of all data, and making mutation harder).
|
||||||
|
|
||||||
|
For times when efficiency is less important a more convenient object based API
|
||||||
|
can be used (through `--gen-object-api`) that is able to unpack & pack a FlatBuffer
|
||||||
|
into objects and lists, allowing for convenient construction, access and mutation.
|
||||||
|
|
||||||
|
To use:
|
||||||
|
|
||||||
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.dart}
|
||||||
|
// Deserialize from buffer into object.
|
||||||
|
MonsterT monster = Monster(flatbuffer).unpack();
|
||||||
|
|
||||||
|
// Update object directly like a Dart class instance.
|
||||||
|
print(monster.Name);
|
||||||
|
monster.Name = "Bob"; // Change the name.
|
||||||
|
|
||||||
|
// Serialize into new flatbuffer.
|
||||||
|
final fbb = Builder();
|
||||||
|
fbb.Finish(monster.pack(fbb));
|
||||||
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|||||||
@@ -52,10 +52,10 @@ a `[]byte`, which you pass to the `GetRootAsMonster` function:
|
|||||||
example "MyGame/Example"
|
example "MyGame/Example"
|
||||||
flatbuffers "github.com/google/flatbuffers/go"
|
flatbuffers "github.com/google/flatbuffers/go"
|
||||||
|
|
||||||
io/ioutil
|
"os"
|
||||||
)
|
)
|
||||||
|
|
||||||
buf, err := ioutil.ReadFile("monster.dat")
|
buf, err := os.ReadFile("monster.dat")
|
||||||
// handle err
|
// handle err
|
||||||
monster := example.GetRootAsMonster(buf, 0)
|
monster := example.GetRootAsMonster(buf, 0)
|
||||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|||||||
35
docs/source/IntermediateRepresentation.md
Normal file
35
docs/source/IntermediateRepresentation.md
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
# Flatbuffers Intermediate Representation {#intermediate_representation}
|
||||||
|
|
||||||
|
We use [reflection.fbs](https://github.com/google/flatbuffers/blob/master/reflection/reflection.fbs)
|
||||||
|
as our intermediate representation. `flatc` parses `.fbs` files, checks them for
|
||||||
|
errors and stores the resulting data in this IR, outputting `.bfbs` files.
|
||||||
|
Since this IR is a Flatbuffer, you can load and use it at runtime for runtime
|
||||||
|
reflection purposes.
|
||||||
|
|
||||||
|
There are some quirks:
|
||||||
|
- Tables and Structs are serialized as `Object`s.
|
||||||
|
- Unions and Enums are serialized as `Enum`s.
|
||||||
|
- It is the responsibility of the code generator to check the `advanced_features`
|
||||||
|
field of `Schema`. These mark the presence of new, backwards incompatible,
|
||||||
|
schema features. Code generators must error if generating a schema with
|
||||||
|
unrecognized advanced features.
|
||||||
|
- Filenames are relative to a "project root" denoted by "//" in the path. This
|
||||||
|
may be specified in flatc with `--bfbs-filenames=$PROJECT_ROOT`, or it will be
|
||||||
|
inferred to be the directory containing the first provided schema file.
|
||||||
|
|
||||||
|
|
||||||
|
## Invocation
|
||||||
|
You can invoke it like so
|
||||||
|
```{.sh}
|
||||||
|
flatc -b --schema ${your_fbs_files}
|
||||||
|
```
|
||||||
|
This generates `.bfbs` (binary flatbuffer schema) files.
|
||||||
|
|
||||||
|
Some information is not included by default. See the `--bfbs-filenames` and
|
||||||
|
`--bfbs-comments` flags. These may be necessary for code-generators, so they can
|
||||||
|
add documentation and maybe name generated files (depending on the generator).
|
||||||
|
|
||||||
|
|
||||||
|
TODO(cneo): Flags to output bfbs as flexbuffers or json.
|
||||||
|
|
||||||
|
TODO(cneo): Tutorial for building a flatc plugin.
|
||||||
@@ -85,7 +85,7 @@ referred to by offset.
|
|||||||
|
|
||||||
They start with an `soffset_t` to a vtable. This is a signed version of
|
They start with an `soffset_t` to a vtable. This is a signed version of
|
||||||
`uoffset_t`, since vtables may be stored anywhere relative to the object.
|
`uoffset_t`, since vtables may be stored anywhere relative to the object.
|
||||||
This offset is substracted (not added) from the object start to arrive at
|
This offset is subtracted (not added) from the object start to arrive at
|
||||||
the vtable start. This offset is followed by all the
|
the vtable start. This offset is followed by all the
|
||||||
fields as aligned scalars (or offsets). Unlike structs, not all fields
|
fields as aligned scalars (or offsets). Unlike structs, not all fields
|
||||||
need to be present. There is no set order and layout. A table may contain
|
need to be present. There is no set order and layout. A table may contain
|
||||||
@@ -435,7 +435,7 @@ The keys vector is a typed vector of keys. Both the keys and corresponding
|
|||||||
values *have* to be stored in sorted order (as determined by `strcmp`), such
|
values *have* to be stored in sorted order (as determined by `strcmp`), such
|
||||||
that lookups can be made using binary search.
|
that lookups can be made using binary search.
|
||||||
|
|
||||||
The reason the key vector is a seperate structure from the value vector is
|
The reason the key vector is a separate structure from the value vector is
|
||||||
such that it can be shared between multiple value vectors, and also to
|
such that it can be shared between multiple value vectors, and also to
|
||||||
allow it to be treated as its own individual vector in code.
|
allow it to be treated as its own individual vector in code.
|
||||||
|
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ https://www.npmjs.com/package/flatbuffers. To use it from sources:
|
|||||||
1. In your project, install it as a normal dependency, using the flatbuffers
|
1. In your project, install it as a normal dependency, using the flatbuffers
|
||||||
folder as the source.
|
folder as the source.
|
||||||
|
|
||||||
## Using the FlatBuffers JavaScript libary
|
## Using the FlatBuffers JavaScript library
|
||||||
|
|
||||||
*Note: See [Tutorial](@ref flatbuffers_guide_tutorial) for a more in-depth
|
*Note: See [Tutorial](@ref flatbuffers_guide_tutorial) for a more in-depth
|
||||||
example of how to use FlatBuffers.*
|
example of how to use FlatBuffers.*
|
||||||
|
|||||||
@@ -71,7 +71,7 @@ Using FlatBuffers in Lobster should be relatively fast, as the implementation
|
|||||||
makes use of native support for writing binary values, and access of vtables.
|
makes use of native support for writing binary values, and access of vtables.
|
||||||
Both generated code and the runtime library are therefore small and fast.
|
Both generated code and the runtime library are therefore small and fast.
|
||||||
|
|
||||||
Actual speed will depend on wether you use Lobster as bytecode VM or compiled to
|
Actual speed will depend on whether you use Lobster as bytecode VM or compiled to
|
||||||
C++.
|
C++.
|
||||||
|
|
||||||
## Text Parsing
|
## Text Parsing
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ The test code itself is located in
|
|||||||
[integration_test.rs](https://github.com/google/flatbuffers/blob/master/tests/rust_usage_test/tests/integration_test.rs)
|
[integration_test.rs](https://github.com/google/flatbuffers/blob/master/tests/rust_usage_test/tests/integration_test.rs)
|
||||||
|
|
||||||
This test file requires `flatc` to be present. To review how to build the project,
|
This test file requires `flatc` to be present. To review how to build the project,
|
||||||
please read the [Building](@ref flatbuffers_guide_building) documenation.
|
please read the [Building](@ref flatbuffers_guide_building) documentation.
|
||||||
|
|
||||||
To run the tests, execute `RustTest.sh` from the `flatbuffers/tests` directory.
|
To run the tests, execute `RustTest.sh` from the `flatbuffers/tests` directory.
|
||||||
For example, on [Linux](https://en.wikipedia.org/wiki/Linux), you would simply
|
For example, on [Linux](https://en.wikipedia.org/wiki/Linux), you would simply
|
||||||
@@ -58,7 +58,7 @@ and the generated code to read or write FlatBuffers.
|
|||||||
|
|
||||||
For example, here is how you would read a FlatBuffer binary file in Rust:
|
For example, here is how you would read a FlatBuffer binary file in Rust:
|
||||||
First, include the library and generated code. Then read the file into
|
First, include the library and generated code. Then read the file into
|
||||||
a `u8` vector, which you pass, as a byte slice, to `get_root_as_monster()`.
|
a `u8` vector, which you pass, as a byte slice, to `root_as_monster()`.
|
||||||
|
|
||||||
This full example program is available in the Rust test suite:
|
This full example program is available in the Rust test suite:
|
||||||
[monster_example.rs](https://github.com/google/flatbuffers/blob/master/tests/rust_usage_test/bin/monster_example.rs)
|
[monster_example.rs](https://github.com/google/flatbuffers/blob/master/tests/rust_usage_test/bin/monster_example.rs)
|
||||||
@@ -80,7 +80,7 @@ It can be run by `cd`ing to the `rust_usage_test` directory and executing: `carg
|
|||||||
let mut buf = Vec::new();
|
let mut buf = Vec::new();
|
||||||
f.read_to_end(&mut buf).expect("file reading failed");
|
f.read_to_end(&mut buf).expect("file reading failed");
|
||||||
|
|
||||||
let monster = my_game::example::get_root_as_monster(&buf[..]);
|
let monster = my_game::example::root_as_monster(&buf[..]);
|
||||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
`monster` is of type `Monster`, and points to somewhere *inside* your
|
`monster` is of type `Monster`, and points to somewhere *inside* your
|
||||||
@@ -108,7 +108,7 @@ the layout of things is generally not known to the user.
|
|||||||
For structs, layout is deterministic and guaranteed to be the same
|
For structs, layout is deterministic and guaranteed to be the same
|
||||||
across platforms (scalars are aligned to their
|
across platforms (scalars are aligned to their
|
||||||
own size, and structs themselves to their largest member), and you
|
own size, and structs themselves to their largest member), and you
|
||||||
are allowed to access this memory directly by using `safe_slice` and
|
are allowed to access this memory directly by using `safe_slice`
|
||||||
on the reference to a struct, or even an array of structs.
|
on the reference to a struct, or even an array of structs.
|
||||||
|
|
||||||
To compute offsets to sub-elements of a struct, make sure they
|
To compute offsets to sub-elements of a struct, make sure they
|
||||||
@@ -118,9 +118,10 @@ handy for use of arrays of structs with calls like `glVertexAttribPointer`
|
|||||||
in OpenGL or similar APIs.
|
in OpenGL or similar APIs.
|
||||||
|
|
||||||
It is important to note is that structs are still little endian on all
|
It is important to note is that structs are still little endian on all
|
||||||
machines, so only use tricks like this if you can guarantee you're not
|
machines, so the functions to enable tricks like this are only exposed on little
|
||||||
shipping on a big endian machine (using an `#[cfg(target_endian = "little")]`
|
endian machines. If you also ship on big endian machines, using an
|
||||||
attribute would be wise).
|
`#[cfg(target_endian = "little")]` attribute would be wise or your code will not
|
||||||
|
compile.
|
||||||
|
|
||||||
The special function `safe_slice` is implemented on Vector objects that are
|
The special function `safe_slice` is implemented on Vector objects that are
|
||||||
represented in memory the same way as they are represented on the wire. This
|
represented in memory the same way as they are represented on the wire. This
|
||||||
@@ -134,22 +135,22 @@ of `safe_slice`.
|
|||||||
|
|
||||||
## Access of untrusted buffers
|
## Access of untrusted buffers
|
||||||
|
|
||||||
|
The safe Rust functions to interpret a slice as a table (`root`,
|
||||||
|
`size_prefixed_root`, `root_with_opts`, and `size_prefixed_root_with_opts`)
|
||||||
|
verify the data first. This has some performance cost, but is intended to be
|
||||||
|
safe for use on flatbuffers from untrusted sources. There are corresponding
|
||||||
|
`unsafe` versions with names ending in `_unchecked` which skip this
|
||||||
|
verification, and may access arbitrary memory.
|
||||||
|
|
||||||
The generated accessor functions access fields over offsets, which is
|
The generated accessor functions access fields over offsets, which is
|
||||||
very quick. These offsets are used to index into Rust slices, so they are
|
very quick. The current implementation uses these to access memory without any
|
||||||
bounds-checked by the Rust runtime. However, our Rust implementation may
|
further bounds checking. All of the safe Rust APIs ensure the verifier is run
|
||||||
change: we may convert access functions to use direct pointer dereferencing, to
|
over these flatbuffers before accessing them.
|
||||||
improve lookup speed. As a result, users should not rely on the aforementioned
|
|
||||||
bounds-checking behavior.
|
|
||||||
|
|
||||||
When you're processing large amounts of data from a source you know (e.g.
|
When you're processing large amounts of data from a source you know (e.g.
|
||||||
your own generated data on disk), this is acceptable, but when reading
|
your own generated data on disk), the `_unchecked` versions are acceptable, but
|
||||||
data from the network that can potentially have been modified by an
|
when reading data from the network that can potentially have been modified by an
|
||||||
attacker, this is undesirable.
|
attacker, it is desirable to use the safe versions which use the verifier.
|
||||||
|
|
||||||
The C++ port provides a buffer verifier. At this time, Rust does not. Rust may
|
|
||||||
provide a verifier in a future version. In the meantime, Rust users can access
|
|
||||||
the buffer verifier generated by the C++ port through a foreign function
|
|
||||||
interface (FFI).
|
|
||||||
|
|
||||||
## Threading
|
## Threading
|
||||||
|
|
||||||
@@ -165,6 +166,17 @@ manually wrap it in synchronisation primitives. There's no automatic way to
|
|||||||
accomplish this, by design, as we feel multithreaded construction
|
accomplish this, by design, as we feel multithreaded construction
|
||||||
of a single buffer will be rare, and synchronisation overhead would be costly.
|
of a single buffer will be rare, and synchronisation overhead would be costly.
|
||||||
|
|
||||||
|
Unlike most other languages, in Rust these properties are exposed to and
|
||||||
|
enforced by the type system. `flatbuffers::Table` and the generated table types
|
||||||
|
are `Send + Sync`, indicating they may be freely shared across threads and data
|
||||||
|
may be accessed from any thread which receives a const (aka shared) reference.
|
||||||
|
There are no functions which require a mutable (aka exclusive) reference, which
|
||||||
|
means all the available functions may be called like this.
|
||||||
|
`flatbuffers::FlatBufferBuilder` is also `Send + Sync`, but all of the mutating
|
||||||
|
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
|
||||||
|
within the same thread, let alone to a second thread.
|
||||||
|
|
||||||
## 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
|
||||||
|
|||||||
@@ -239,9 +239,9 @@ included files (those you still generate separately).
|
|||||||
|
|
||||||
### Root type
|
### Root type
|
||||||
|
|
||||||
This declares what you consider to be the root table (or struct) of the
|
This declares what you consider to be the root table of the serialized
|
||||||
serialized data. This is particularly important for parsing JSON data,
|
data. This is particularly important for parsing JSON data, which doesn't
|
||||||
which doesn't include object type information.
|
include object type information.
|
||||||
|
|
||||||
### File identification and extension
|
### File identification and extension
|
||||||
|
|
||||||
@@ -490,7 +490,7 @@ as much as possible such that you can use tables where you might be
|
|||||||
tempted to use a dictionary.
|
tempted to use a dictionary.
|
||||||
|
|
||||||
Similarly, strings as values should only be used when they are
|
Similarly, strings as values should only be used when they are
|
||||||
truely open-ended. If you can, always use an enum instead.
|
truly open-ended. If you can, always use an enum instead.
|
||||||
|
|
||||||
FlatBuffers doesn't have inheritance, so the way to represent a set
|
FlatBuffers doesn't have inheritance, so the way to represent a set
|
||||||
of related data structures is a union. Unions do have a cost however,
|
of related data structures is a union. Unions do have a cost however,
|
||||||
@@ -592,7 +592,7 @@ we keep the sequence of ids.
|
|||||||
|
|
||||||
table { b:int; }
|
table { b:int; }
|
||||||
|
|
||||||
NOT ok. We can only remove a field by deprecation, regardless of wether we use
|
NOT ok. We can only remove a field by deprecation, regardless of whether we use
|
||||||
explicit ids or not.
|
explicit ids or not.
|
||||||
|
|
||||||
table { a:uint; b:uint; }
|
table { a:uint; b:uint; }
|
||||||
@@ -637,10 +637,14 @@ optional type.
|
|||||||
Some `FlatBufferBuilder` implementations have an option called `force_defaults`
|
Some `FlatBufferBuilder` implementations have an option called `force_defaults`
|
||||||
that circumvents this "not writing defaults" behavior you can then use
|
that circumvents this "not writing defaults" behavior you can then use
|
||||||
`IsFieldPresent` to query presence.
|
`IsFieldPresent` to query presence.
|
||||||
|
/
|
||||||
Another option that works in all languages is to wrap a scalar field in a
|
Another option that works in all languages is to wrap a scalar field in a
|
||||||
struct. This way it will return null if it is not present. This will be slightly
|
struct. This way it will return null if it is not present. This will be slightly
|
||||||
less ergonomic but structs don't take up any more space than the scalar they
|
less ergonomic but structs don't take up any more space than the scalar they
|
||||||
represent.
|
represent.
|
||||||
|
|
||||||
[Interface Definition Language]: https://en.wikipedia.org/wiki/Interface_description_language
|
[Interface Definition Language]: https://en.wikipedia.org/wiki/Interface_description_language
|
||||||
|
|
||||||
|
## Writing your own code generator.
|
||||||
|
|
||||||
|
See [our intermediate representation](@ref intermediate_representation).
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ JSON parsing | Yes | No | No | No | 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 | No
|
||||||
Native Object API | Yes | No | Yes | Yes | Yes | Yes | Yes | No | No | No | No | No | No
|
Native Object API | Yes | No | Yes | Yes | Yes | Yes | Yes | No | No | Yes | No | No | No
|
||||||
Optional Scalars | Yes | Yes | Yes | No | No | Yes | Yes | Yes | No | No | Yes | Yes | Yes
|
Optional Scalars | Yes | Yes | Yes | No | No | Yes | Yes | Yes | No | No | Yes | Yes | Yes
|
||||||
Flexbuffers | Yes | Yes | ? | ? | ? | ? | ? | ? | ? | ? | ? | Yes | ?
|
Flexbuffers | 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
|
||||||
|
|||||||
@@ -231,7 +231,7 @@ fields, such as `mana:short = 150`. If unspecified, scalar fields (like `int`,
|
|||||||
`uint`, or `float`) will be given a default of `0` while strings and tables will
|
`uint`, or `float`) will be given a default of `0` while strings and tables will
|
||||||
be given a default of `null`. Another thing to note is the line `friendly:bool =
|
be given a default of `null`. Another thing to note is the line `friendly:bool =
|
||||||
false (deprecated);`. Since you cannot delete fields from a `table` (to support
|
false (deprecated);`. Since you cannot delete fields from a `table` (to support
|
||||||
backwards compatability), you can set fields as `deprecated`, which will prevent
|
backwards compatibility), you can set fields as `deprecated`, which will prevent
|
||||||
the generation of accessors for this field in the generated code. Be careful
|
the generation of accessors for this field in the generated code. Be careful
|
||||||
when using `deprecated`, however, as it may break legacy code that used this
|
when using `deprecated`, however, as it may break legacy code that used this
|
||||||
accessor.
|
accessor.
|
||||||
@@ -1090,7 +1090,7 @@ traversal. This is generally easy to do on any tree structures.
|
|||||||
</div>
|
</div>
|
||||||
<div class="language-lua">
|
<div class="language-lua">
|
||||||
~~~{.py}
|
~~~{.py}
|
||||||
-- Serialize a name for our mosnter, called 'orc'
|
-- Serialize a name for our monster, called 'orc'
|
||||||
local name = builder:CreateString("Orc")
|
local name = builder:CreateString("Orc")
|
||||||
|
|
||||||
-- Create a `vector` representing the inventory of the Orc. Each number
|
-- Create a `vector` representing the inventory of the Orc. Each number
|
||||||
@@ -1820,7 +1820,7 @@ Here is a repetition of these lines, to help highlight them more clearly:
|
|||||||
<div class="language-cpp">
|
<div class="language-cpp">
|
||||||
~~~{.cpp}
|
~~~{.cpp}
|
||||||
monster_builder.add_equipped_type(Equipment_Weapon); // Union type
|
monster_builder.add_equipped_type(Equipment_Weapon); // Union type
|
||||||
monster_builder.add_equipped(axe); // Union data
|
monster_builder.add_equipped(axe.Union()); // Union data
|
||||||
~~~
|
~~~
|
||||||
</div>
|
</div>
|
||||||
<div class="language-java">
|
<div class="language-java">
|
||||||
@@ -2970,7 +2970,7 @@ We can access the type to dynamically cast the data as needed (since the
|
|||||||
|
|
||||||
<div class="language-cpp">
|
<div class="language-cpp">
|
||||||
~~~{.cpp}
|
~~~{.cpp}
|
||||||
auto union_type = monster.equipped_type();
|
auto union_type = monster->equipped_type();
|
||||||
|
|
||||||
if (union_type == Equipment_Weapon) {
|
if (union_type == Equipment_Weapon) {
|
||||||
auto weapon = static_cast<const Weapon*>(monster->equipped()); // Requires `static_cast`
|
auto weapon = static_cast<const Weapon*>(monster->equipped()); // Requires `static_cast`
|
||||||
@@ -3392,6 +3392,125 @@ decimals in the JSON document.*
|
|||||||
|
|
||||||
## Advanced Features for Each Language
|
## Advanced Features for Each Language
|
||||||
|
|
||||||
|
### Vector of Unions
|
||||||
|
|
||||||
|
Some languages support storing unions directly in a vector.
|
||||||
|
|
||||||
|
~~~
|
||||||
|
// File found in tests/union_vector/union_vector.fbs
|
||||||
|
namespace Example.VectorOfUnions;
|
||||||
|
|
||||||
|
// Demonstrates the ability to have vectors of unions, and also to
|
||||||
|
// store structs and strings in unions.
|
||||||
|
|
||||||
|
table Attacker {
|
||||||
|
sword_attack_damage: int;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct Rapunzel {
|
||||||
|
hair_length: int;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct BookReader {
|
||||||
|
books_read: int;
|
||||||
|
}
|
||||||
|
|
||||||
|
union Character {
|
||||||
|
MuLan: Attacker, // Can have name be different from type.
|
||||||
|
Rapunzel, // Or just both the same, as before.
|
||||||
|
Belle: BookReader,
|
||||||
|
BookFan: BookReader,
|
||||||
|
Other: string,
|
||||||
|
Unused: string
|
||||||
|
}
|
||||||
|
|
||||||
|
table Movie {
|
||||||
|
main_character: Character;
|
||||||
|
characters: [Character];
|
||||||
|
}
|
||||||
|
~~~
|
||||||
|
|
||||||
|
#### Creating
|
||||||
|
|
||||||
|
Analagously to how a union adds two fields to a table a vector of unions creates two different vectors:
|
||||||
|
one for the union data and one for the data types.
|
||||||
|
|
||||||
|
<div class="language-cpp">
|
||||||
|
C++ supports vectors of unions, but it isn't currently documented.
|
||||||
|
</div>
|
||||||
|
<div class="language-typescript">
|
||||||
|
Typescript supports vectors of unions, but it isn't currently documented.
|
||||||
|
</div>
|
||||||
|
<div class="language-php">
|
||||||
|
PHP supports vectors of unions, but it isn't currently documented.
|
||||||
|
</div>
|
||||||
|
<div class="language-java">
|
||||||
|
Java supports vectors of unions, but it isn't currently documented.
|
||||||
|
</div>
|
||||||
|
<div class="language-csharp">
|
||||||
|
~~~{.cs}
|
||||||
|
using FlatBuffers;
|
||||||
|
using Example.VectorOfUnions;
|
||||||
|
|
||||||
|
var fbb = new FlatBufferBuilder(100);
|
||||||
|
|
||||||
|
var characterTypes = new[]
|
||||||
|
{
|
||||||
|
Character.MuLan,
|
||||||
|
Character.Belle,
|
||||||
|
Character.Other,
|
||||||
|
};
|
||||||
|
var characterTypesOffset = Movie.CreateCharactersTypeVector(fbb, characterTypes);
|
||||||
|
|
||||||
|
var characters = new[]
|
||||||
|
{
|
||||||
|
Attacker.CreateAttacker(fbb, 10).Value,
|
||||||
|
BookReader.CreateBookReader(fbb, 20).Value,
|
||||||
|
fbb.CreateSharedString("Chip").Value,
|
||||||
|
};
|
||||||
|
var charactersOffset = Movie.CreateCharactersVector(fbb, characters);
|
||||||
|
|
||||||
|
var movieOffset = Movie.CreateMovie(
|
||||||
|
fbb,
|
||||||
|
Character.Rapunzel,
|
||||||
|
rapunzel,
|
||||||
|
characterTypesOffset,
|
||||||
|
charactersOffset);
|
||||||
|
Movie.FinishMovieBuffer(fbb, movieOffset);
|
||||||
|
~~~
|
||||||
|
</div>
|
||||||
|
<div class="language-kotlin">
|
||||||
|
Kotlin supports vectors of unions, but it isn't currently documented.
|
||||||
|
</div>
|
||||||
|
<div class="language-swift">
|
||||||
|
Swift supports vectors of unions, but it isn't currently documented.
|
||||||
|
</div>
|
||||||
|
|
||||||
|
#### Reading
|
||||||
|
<div class="language-csharp">
|
||||||
|
~~~{.cs}
|
||||||
|
var movie = Movie.GetRootAsMovie(fbb.DataBuffer);
|
||||||
|
|
||||||
|
for (var i = 0; i <= movie.CharactersLength; i++)
|
||||||
|
{
|
||||||
|
if (movie.CharactersType(i) == Character.MuLan)
|
||||||
|
{
|
||||||
|
var mulanSwordDamage = movie.Characters<Attacker>(i).Value.SwordAttackDamage;
|
||||||
|
}
|
||||||
|
else if (movie.CharactersType(i) == Character.Belle)
|
||||||
|
{
|
||||||
|
var belleBooksRead = movie.Characters<BookReader>(i).Value.BooksRead;
|
||||||
|
}
|
||||||
|
else if (movie.CharactersType(i) == Character.Other)
|
||||||
|
{
|
||||||
|
var otherStr = movie.CharactersAsString(i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
~~~
|
||||||
|
</div>
|
||||||
|
|
||||||
|
### Further Reading
|
||||||
|
|
||||||
Each language has a dedicated `Use in XXX` page in the Programmer's Guide
|
Each language has a dedicated `Use in XXX` page in the Programmer's Guide
|
||||||
to cover the nuances of FlatBuffers in that language.
|
to cover the nuances of FlatBuffers in that language.
|
||||||
|
|
||||||
|
|||||||
@@ -21,12 +21,12 @@ https://www.npmjs.com/package/flatbuffers.
|
|||||||
|
|
||||||
## Testing the FlatBuffers TypeScript library
|
## Testing the FlatBuffers TypeScript library
|
||||||
|
|
||||||
To run the tests, use the [TypeScriptTest.sh](https://github.com/google/
|
To run the tests, use the [TypeScriptTest.py](https://github.com/google/
|
||||||
flatbuffers/blob/master/tests/TypeScriptTest.sh) shell script.
|
flatbuffers/blob/master/tests/TypeScriptTest.py) Python3 script.
|
||||||
|
|
||||||
*Note: The TypeScript test file requires [Node.js](https://nodejs.org/en/).*
|
*Note: The TypeScript test file requires [Node.js](https://nodejs.org/en/).*
|
||||||
|
|
||||||
## Using the FlatBuffers TypeScript libary
|
## Using the FlatBuffers TypeScript library
|
||||||
|
|
||||||
*Note: See [Tutorial](@ref flatbuffers_guide_tutorial) for a more in-depth
|
*Note: See [Tutorial](@ref flatbuffers_guide_tutorial) for a more in-depth
|
||||||
example of how to use FlatBuffers in TypeScript.*
|
example of how to use FlatBuffers in TypeScript.*
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ and locality.
|
|||||||
If it would be possible to do serialization with no temporary objects,
|
If it would be possible to do serialization with no temporary objects,
|
||||||
no additional allocation, no copying, and good locality, this could be
|
no additional allocation, no copying, and good locality, this could be
|
||||||
of great value. The reason serialization systems usually don't manage
|
of great value. The reason serialization systems usually don't manage
|
||||||
this is because it goes counter to forwards/backwards compatability, and
|
this is because it goes counter to forwards/backwards compatibility, and
|
||||||
platform specifics like endianness and alignment.
|
platform specifics like endianness and alignment.
|
||||||
|
|
||||||
FlatBuffers is what you get if you try anyway.
|
FlatBuffers is what you get if you try anyway.
|
||||||
@@ -64,7 +64,7 @@ through a *vtable*. Each table comes with a vtable (which may be shared
|
|||||||
between multiple tables with the same layout), and contains information
|
between multiple tables with the same layout), and contains information
|
||||||
where fields for this particular kind of instance of vtable are stored.
|
where fields for this particular kind of instance of vtable are stored.
|
||||||
The vtable may also indicate that the field is not present (because this
|
The vtable may also indicate that the field is not present (because this
|
||||||
FlatBuffer was written with an older version of the software, of simply
|
FlatBuffer was written with an older version of the software, or simply
|
||||||
because the information was not necessary for this instance, or deemed
|
because the information was not necessary for this instance, or deemed
|
||||||
deprecated), in which case a default value is returned.
|
deprecated), in which case a default value is returned.
|
||||||
|
|
||||||
|
|||||||
@@ -768,6 +768,7 @@ INPUT = "FlatBuffers.md" \
|
|||||||
"WhitePaper.md" \
|
"WhitePaper.md" \
|
||||||
"FlexBuffers.md" \
|
"FlexBuffers.md" \
|
||||||
"Internals.md" \
|
"Internals.md" \
|
||||||
|
"IntermediateRepresentation.md" \
|
||||||
"Grammar.md" \
|
"Grammar.md" \
|
||||||
"../../CONTRIBUTING.md" \
|
"../../CONTRIBUTING.md" \
|
||||||
"Tutorial.md" \
|
"Tutorial.md" \
|
||||||
|
|||||||
@@ -66,6 +66,8 @@
|
|||||||
title="FlatBuffers white paper"/>
|
title="FlatBuffers white paper"/>
|
||||||
<tab type="user" url="@ref flatbuffers_internals"
|
<tab type="user" url="@ref flatbuffers_internals"
|
||||||
title="FlatBuffers internals"/>
|
title="FlatBuffers internals"/>
|
||||||
|
<tab type="user" url="@ref intermediate_representation"
|
||||||
|
title="Intermediate Representation"/>
|
||||||
<tab type="user" url="@ref flatbuffers_grammar"
|
<tab type="user" url="@ref flatbuffers_grammar"
|
||||||
title="Grammar of the schema language"/>
|
title="Grammar of the schema language"/>
|
||||||
<tab type="usergroup" url="" title="API Reference">
|
<tab type="usergroup" url="" title="API Reference">
|
||||||
|
|||||||
@@ -32,9 +32,8 @@ $bazel test src/compiler/...
|
|||||||
|
|
||||||
### Linux
|
### Linux
|
||||||
|
|
||||||
1. `ln -s ${GRPC_INSTALL_PATH}/lib/libgrpc++_unsecure.so.6 ${GRPC_INSTALL_PATH}/lib/libgrpc++_unsecure.so.1`
|
1. `export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:${GRPC_INSTALL_PATH}/lib`
|
||||||
2. `export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:${GRPC_INSTALL_PATH}/lib`
|
2. `make test ARGS=-V`
|
||||||
3. `make test ARGS=-V`
|
|
||||||
|
|
||||||
For Bazel users:
|
For Bazel users:
|
||||||
|
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
grpc_1_36_0_githash=736e3758351ced3cd842bad3ba4e2540f01bbc48
|
grpc_1_39_0_githash=58602e20a3f3e48f24a4114c757099b25b947f7b
|
||||||
|
|
||||||
function build_grpc () {
|
function build_grpc () {
|
||||||
git clone https://github.com/grpc/grpc.git google/grpc
|
git clone https://github.com/grpc/grpc.git google/grpc
|
||||||
cd google/grpc
|
cd google/grpc
|
||||||
git checkout ${grpc_1_36_0_githash}
|
git checkout ${grpc_1_39_0_githash}
|
||||||
git submodule update --init
|
git submodule update --init
|
||||||
# Apply boringssl build patch
|
# Apply boringssl build patch
|
||||||
cd third_party/boringssl-with-bazel
|
cd third_party/boringssl-with-bazel
|
||||||
@@ -13,11 +13,8 @@ function build_grpc () {
|
|||||||
cd ../..
|
cd ../..
|
||||||
mkdir ../grpc_build
|
mkdir ../grpc_build
|
||||||
cd ../grpc_build
|
cd ../grpc_build
|
||||||
cmake ../grpc -DgRPC_INSTALL=ON -DgRPC_BUILD_TESTS=OFF -DBUILD_SHARED_LIBS=ON -DCMAKE_INSTALL_PREFIX=`pwd`/../grpc/install
|
cmake ../grpc -DgRPC_INSTALL=ON -DgRPC_BUILD_TESTS=OFF -DABSL_ENABLE_INSTALL=ON -DBUILD_SHARED_LIBS=ON -DCMAKE_INSTALL_PREFIX=`pwd`/../grpc/install
|
||||||
cmake --build . --target install ${JOBS:+-j$JOBS}
|
cmake --build . --target install ${JOBS:+-j$JOBS}
|
||||||
if [ ! -f ${GRPC_INSTALL_PATH}/lib/libgrpc++_unsecure.so.1 ]; then
|
|
||||||
ln -s ${GRPC_INSTALL_PATH}/lib/libgrpc++_unsecure.so.6 ${GRPC_INSTALL_PATH}/lib/libgrpc++_unsecure.so.1
|
|
||||||
fi
|
|
||||||
cd ../..
|
cd ../..
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,71 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
#
|
|
||||||
# Copyright 2021 Google Inc. All rights reserved.
|
|
||||||
#
|
|
||||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
# you may not use this file except in compliance with the License.
|
|
||||||
# You may obtain a copy of the License at
|
|
||||||
#
|
|
||||||
# http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
#
|
|
||||||
# Unless required by applicable law or agreed to in writing, software
|
|
||||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
# See the License for the specific language governing permissions and
|
|
||||||
# limitations under the License.
|
|
||||||
|
|
||||||
set -e
|
|
||||||
|
|
||||||
current_dir=`pwd`
|
|
||||||
|
|
||||||
cd ../..
|
|
||||||
|
|
||||||
main_dir=`pwd`
|
|
||||||
|
|
||||||
cd ${current_dir}
|
|
||||||
|
|
||||||
# Looks for flatc within the root dir & debug
|
|
||||||
if [ -e ${main_dir}/flatc ]; then
|
|
||||||
alias fbc='${main_dir}/flatc'
|
|
||||||
elif [ -e ${main_dir}/Debug/flatc ]; then
|
|
||||||
alias fbc='${main_dir}/Debug/flatc'
|
|
||||||
else
|
|
||||||
echo 'flatc' could not be found. Make sure to build FlatBuffers from the \
|
|
||||||
$rootdir directory.
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
generator="--grpc $current_dir/greeter.fbs"
|
|
||||||
|
|
||||||
# Regenerate Go lang code
|
|
||||||
cd go
|
|
||||||
|
|
||||||
cd greeter
|
|
||||||
fbc --go ${generator}
|
|
||||||
|
|
||||||
cd ${current_dir}
|
|
||||||
|
|
||||||
# Regenerate Python code
|
|
||||||
cd python
|
|
||||||
|
|
||||||
cd greeter
|
|
||||||
|
|
||||||
fbc --python ${generator}
|
|
||||||
|
|
||||||
cd ${current_dir}
|
|
||||||
|
|
||||||
# Regenerate Swift code
|
|
||||||
cd swift
|
|
||||||
|
|
||||||
cd Greeter/Sources/Model
|
|
||||||
fbc --swift ${generator}
|
|
||||||
|
|
||||||
cd ${current_dir}
|
|
||||||
|
|
||||||
# Regenerate Typescript code
|
|
||||||
cd ts
|
|
||||||
|
|
||||||
cd greeter/src
|
|
||||||
fbc --ts ${generator}
|
|
||||||
|
|
||||||
cd ${current_dir}
|
|
||||||
@@ -9,8 +9,10 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
flatbuffers "github.com/google/flatbuffers/go"
|
flatbuffers "github.com/google/flatbuffers/go"
|
||||||
models "github.com/google/flatbuffers/grpc/examples/go/greeter/models"
|
|
||||||
"google.golang.org/grpc"
|
"google.golang.org/grpc"
|
||||||
|
"google.golang.org/grpc/credentials/insecure"
|
||||||
|
|
||||||
|
models "github.com/google/flatbuffers/grpc/examples/go/greeter/models"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@@ -63,7 +65,9 @@ func printSayManyHello(client models.GreeterClient, name string) {
|
|||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
conn, err := grpc.Dial(fmt.Sprintf("localhost:%d", 3000), grpc.WithInsecure(), grpc.WithCodec(flatbuffers.FlatbuffersCodec{}))
|
conn, err := grpc.Dial(fmt.Sprintf("localhost:%d", 3000),
|
||||||
|
grpc.WithTransportCredentials(insecure.NewCredentials()),
|
||||||
|
grpc.WithDefaultCallOptions(grpc.ForceCodec(flatbuffers.FlatbuffersCodec{})))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("fail to dial: %v", err)
|
log.Fatalf("fail to dial: %v", err)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,5 +7,5 @@ replace github.com/google/flatbuffers/grpc/examples/go/greeter/models v0.0.0 =>
|
|||||||
require (
|
require (
|
||||||
github.com/google/flatbuffers v1.12.0
|
github.com/google/flatbuffers v1.12.0
|
||||||
github.com/google/flatbuffers/grpc/examples/go/greeter/models v0.0.0
|
github.com/google/flatbuffers/grpc/examples/go/greeter/models v0.0.0
|
||||||
google.golang.org/grpc v1.35.0
|
google.golang.org/grpc v1.39.0-dev
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -9,7 +9,6 @@ import (
|
|||||||
flatbuffers "github.com/google/flatbuffers/go"
|
flatbuffers "github.com/google/flatbuffers/go"
|
||||||
models "github.com/google/flatbuffers/grpc/examples/go/greeter/models"
|
models "github.com/google/flatbuffers/grpc/examples/go/greeter/models"
|
||||||
"google.golang.org/grpc"
|
"google.golang.org/grpc"
|
||||||
"google.golang.org/grpc/encoding"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@@ -68,8 +67,8 @@ func main() {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("failed to listen: %v", err)
|
log.Fatalf("failed to listen: %v", err)
|
||||||
}
|
}
|
||||||
grpcServer := grpc.NewServer()
|
codec := &flatbuffers.FlatbuffersCodec{}
|
||||||
encoding.RegisterCodec(flatbuffers.FlatbuffersCodec{})
|
grpcServer := grpc.NewServer(grpc.ForceServerCodec(codec))
|
||||||
models.RegisterGreeterServer(grpcServer, newServer())
|
models.RegisterGreeterServer(grpcServer, newServer())
|
||||||
if err := grpcServer.Serve(lis); err != nil {
|
if err := grpcServer.Serve(lis); err != nil {
|
||||||
fmt.Print(err)
|
fmt.Print(err)
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user