mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-01 19:58:15 +00:00
Compare commits
426 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
38df29380a | ||
|
|
1f438bd40f | ||
|
|
392165432a | ||
|
|
e6bbb3d22e | ||
|
|
a6979fe14a | ||
|
|
bab10754d9 | ||
|
|
ac7ef1176a | ||
|
|
d6444fb7fc | ||
|
|
e223d69b36 | ||
|
|
05cc7a2eff | ||
|
|
8a12183c3b | ||
|
|
21b706b62d | ||
|
|
c5f151ab33 | ||
|
|
3860f1cf7f | ||
|
|
4e582b0c1d | ||
|
|
8396e00dd8 | ||
|
|
48babd417d | ||
|
|
22770f7e85 | ||
|
|
21b033227e | ||
|
|
93f587a6d3 | ||
|
|
8afb68f074 | ||
|
|
2e07f269b9 | ||
|
|
10c994155c | ||
|
|
fc9909c30a | ||
|
|
e35817577c | ||
|
|
9e3fe5d3f6 | ||
|
|
dc9217347e | ||
|
|
a7fed2ce67 | ||
|
|
de3b97355d | ||
|
|
8aa7084f01 | ||
|
|
0f469cad54 | ||
|
|
72e51c61f7 | ||
|
|
31590a8a3b | ||
|
|
24c2432d99 | ||
|
|
292870612c | ||
|
|
57659d9f38 | ||
|
|
2b8e4d3af0 | ||
|
|
08b6372a36 | ||
|
|
9c383559e0 | ||
|
|
c13c3bf956 | ||
|
|
47eeb8f4e9 | ||
|
|
e7c6874192 | ||
|
|
8d2c333b36 | ||
|
|
abc9bfebff | ||
|
|
94d6b8086b | ||
|
|
fa709636b4 | ||
|
|
60463e25a8 | ||
|
|
b8e3d215b8 | ||
|
|
d71c0ab4ac | ||
|
|
fcf75449b8 | ||
|
|
c21bda1649 | ||
|
|
03fffb25e2 | ||
|
|
1a7495a6dd | ||
|
|
3c1bb67ae1 | ||
|
|
5b9de8b6c0 | ||
|
|
ea0a73d168 | ||
|
|
4623cfa4bc | ||
|
|
9c2c56dc6a | ||
|
|
429c28c783 | ||
|
|
e5a9ff757f | ||
|
|
e53732b9b9 | ||
|
|
b84b676c89 | ||
|
|
3211f857d1 | ||
|
|
95ff1f1d80 | ||
|
|
af8997b567 | ||
|
|
0d67abde45 | ||
|
|
d74e2945f7 | ||
|
|
8914d06ab7 | ||
|
|
522f2379a6 | ||
|
|
7cb0bcb212 | ||
|
|
b1e7868db6 | ||
|
|
68e3c839c3 | ||
|
|
0723245085 | ||
|
|
9d64b9c0c0 | ||
|
|
d01f20f2fb | ||
|
|
7e163021e5 | ||
|
|
57fdd4f995 | ||
|
|
8cb53ccc95 | ||
|
|
fb55e0c9de | ||
|
|
d9fde67eb5 | ||
|
|
f74fda299d | ||
|
|
15802fa26c | ||
|
|
a86afae939 | ||
|
|
60910fb7f5 | ||
|
|
7bfaabc358 | ||
|
|
e1407e4341 | ||
|
|
c9a301e601 | ||
|
|
19b2300f93 | ||
|
|
e60c0ab9e2 | ||
|
|
541dd1a8f5 | ||
|
|
7711e84919 | ||
|
|
89430a14d6 | ||
|
|
cfce38ec99 | ||
|
|
5469bc9ef1 | ||
|
|
b39f79e5e9 | ||
|
|
dc623919bd | ||
|
|
a1e125af11 | ||
|
|
0b60686e3d | ||
|
|
17ceaae16e | ||
|
|
a5343d6116 | ||
|
|
4786322b90 | ||
|
|
646a8bc96a | ||
|
|
0e3471d6a7 | ||
|
|
b07589a0f9 | ||
|
|
2062c33cd4 | ||
|
|
adb7add87e | ||
|
|
29f99937c4 | ||
|
|
597e76a268 | ||
|
|
a577050817 | ||
|
|
31ab0bf6c8 | ||
|
|
e4775aa3fe | ||
|
|
97d26ab4ae | ||
|
|
7dd38fa23a | ||
|
|
7350c3668f | ||
|
|
49d2db93a7 | ||
|
|
807b43c0d7 | ||
|
|
4b823b1b98 | ||
|
|
4c47f4c11e | ||
|
|
2b107e20c5 | ||
|
|
84f4b83d3e | ||
|
|
185e41fac4 | ||
|
|
8b02fe6178 | ||
|
|
6e0dad8c5f | ||
|
|
e3e355d498 | ||
|
|
8e901ce17c | ||
|
|
7808ae5c88 | ||
|
|
20068cfa05 | ||
|
|
afd07bdec5 | ||
|
|
2951d5383a | ||
|
|
ba563de877 | ||
|
|
46a2f3f2c2 | ||
|
|
7675121eab | ||
|
|
ea2b5148e5 | ||
|
|
20548ff3b6 | ||
|
|
7ea8db05d8 | ||
|
|
c7b6b66ccb | ||
|
|
ac8b124496 | ||
|
|
88b033b964 | ||
|
|
e68355cb22 | ||
|
|
e3ee24830e | ||
|
|
2a8f4568e0 | ||
|
|
cbf0850828 | ||
|
|
7150dfb5c4 | ||
|
|
fa87eccd1a | ||
|
|
a62f45fed8 | ||
|
|
599847236c | ||
|
|
4173b84d4b | ||
|
|
5fe90a9160 | ||
|
|
78a3d59a65 | ||
|
|
5ed02dc04a | ||
|
|
592dc50037 | ||
|
|
dd77af75b7 | ||
|
|
051604aeb5 | ||
|
|
4b09586652 | ||
|
|
4c0eecd25a | ||
|
|
de25052c72 | ||
|
|
95053e6a47 | ||
|
|
27325e002a | ||
|
|
1872409707 | ||
|
|
c427e1a65d | ||
|
|
caf3b494db | ||
|
|
0e047869da | ||
|
|
881eaab706 | ||
|
|
48eccb83db | ||
|
|
3c0511fa6a | ||
|
|
82396fa0fe | ||
|
|
a6b337f803 | ||
|
|
35230bd70c | ||
|
|
deb3d93454 | ||
|
|
b87d04af8c | ||
|
|
1e6c851dba | ||
|
|
6164edf558 | ||
|
|
ef1030ff0b | ||
|
|
53c8c2ef16 | ||
|
|
f83525fe67 | ||
|
|
b2cce474ba | ||
|
|
067bfdbde9 | ||
|
|
5218e29aa4 | ||
|
|
957e09d684 | ||
|
|
af4b99a1d7 | ||
|
|
b85b90e346 | ||
|
|
ae3821233c | ||
|
|
ff9cba2bff | ||
|
|
1759061908 | ||
|
|
34af7fff70 | ||
|
|
518bf42df8 | ||
|
|
575d616e60 | ||
|
|
f32a7dcbd2 | ||
|
|
860d645349 | ||
|
|
06a53df0d3 | ||
|
|
c526cb640b | ||
|
|
ca73ff34b7 | ||
|
|
2e49b3ba60 | ||
|
|
f830c47d68 | ||
|
|
501810f4d1 | ||
|
|
1047d7ec13 | ||
|
|
07c2eb5fe7 | ||
|
|
c7b9dc83f5 | ||
|
|
4c9079e31b | ||
|
|
64e5252b4e | ||
|
|
00c30807ff | ||
|
|
c15fe421ba | ||
|
|
6b251aa1cf | ||
|
|
6fe8afb3b6 | ||
|
|
00eec2445b | ||
|
|
b8db3a9a6a | ||
|
|
75556437cc | ||
|
|
31beb0fb2f | ||
|
|
dfd92124aa | ||
|
|
a2916d37e7 | ||
|
|
5a95b7b6bc | ||
|
|
595ac94a6a | ||
|
|
5822c1c8dd | ||
|
|
609c72ca1a | ||
|
|
bd1b2d0baf | ||
|
|
1c514626e8 | ||
|
|
820a7f277f | ||
|
|
396c3f56df | ||
|
|
c49e81d6ec | ||
|
|
a285e7ef1a | ||
|
|
0312061985 | ||
|
|
9f94ceedbc | ||
|
|
bcd2b9d039 | ||
|
|
82fefbf252 | ||
|
|
65e49faf76 | ||
|
|
50be3cfe8c | ||
|
|
026c243dc5 | ||
|
|
a9257b6963 | ||
|
|
fceafd438d | ||
|
|
33a15d63cf | ||
|
|
ad6d6638f3 | ||
|
|
69ac6a712d | ||
|
|
4b69b27d43 | ||
|
|
9318c6c981 | ||
|
|
df287ee6a7 | ||
|
|
0d7bf7e8a7 | ||
|
|
e67310bf1c | ||
|
|
121c4c99ae | ||
|
|
27f5a0fdae | ||
|
|
3592b19150 | ||
|
|
733e432bfd | ||
|
|
5414e04b45 | ||
|
|
c9a286bf29 | ||
|
|
f9a70c79f1 | ||
|
|
1eb4bd3ca7 | ||
|
|
41e47e4951 | ||
|
|
4999936289 | ||
|
|
8e2852fa73 | ||
|
|
7e52f59f14 | ||
|
|
1ff248739e | ||
|
|
2cffba28b4 | ||
|
|
34f0728ea2 | ||
|
|
569e6cb461 | ||
|
|
086097ff94 | ||
|
|
2b0ce37b12 | ||
|
|
67bf1084c0 | ||
|
|
f82c4ac904 | ||
|
|
9a40ab2495 | ||
|
|
5c14ee7e8b | ||
|
|
26e77dce41 | ||
|
|
6913c34e62 | ||
|
|
0222cd4a63 | ||
|
|
0042afa5e2 | ||
|
|
8852f10a84 | ||
|
|
a8df3c8f35 | ||
|
|
b8629d402e | ||
|
|
ccdab58c11 | ||
|
|
a96fe8f206 | ||
|
|
99fda81905 | ||
|
|
8694806f14 | ||
|
|
5a75ad407d | ||
|
|
2d86857bec | ||
|
|
0f90dc8290 | ||
|
|
c9125e6385 | ||
|
|
28ddfaeda7 | ||
|
|
7e59e0727c | ||
|
|
79d9e33ea3 | ||
|
|
bbb6b932fc | ||
|
|
46cc3d6432 | ||
|
|
fb3ccd36c0 | ||
|
|
492475a1b2 | ||
|
|
c75a0154eb | ||
|
|
a2cd1ea3b6 | ||
|
|
32e63af684 | ||
|
|
1f4a9038ce | ||
|
|
a9df44828d | ||
|
|
5f453ef738 | ||
|
|
49061f8c7c | ||
|
|
807adb73b2 | ||
|
|
2f59a0319b | ||
|
|
6a8898573c | ||
|
|
d7a70db6ac | ||
|
|
b127c57ff0 | ||
|
|
2436bd8175 | ||
|
|
69a53e495d | ||
|
|
c7a8102b12 | ||
|
|
2146bacd2e | ||
|
|
8db59321d9 | ||
|
|
42879f6ea6 | ||
|
|
7833affd7e | ||
|
|
c065e972db | ||
|
|
06b12d55ea | ||
|
|
baddf90599 | ||
|
|
8b35a6bc32 | ||
|
|
6cb4d671a8 | ||
|
|
fb9afbafc7 | ||
|
|
dafd2f1f29 | ||
|
|
6ede1ccc9e | ||
|
|
8755c35a18 | ||
|
|
75f05d6389 | ||
|
|
3b27f5396e | ||
|
|
58c8eb5847 | ||
|
|
0e034ecdba | ||
|
|
0f8b71180f | ||
|
|
a5a2da0161 | ||
|
|
28783927af | ||
|
|
a1378fbd16 | ||
|
|
dcacfc5b11 | ||
|
|
f9dabf511a | ||
|
|
5ba66f71c5 | ||
|
|
5adfac9fc3 | ||
|
|
c6fce30e9b | ||
|
|
ef30729a71 | ||
|
|
30ae5f189c | ||
|
|
299725fe2e | ||
|
|
a41fefa1a8 | ||
|
|
d89f611f6f | ||
|
|
150644d7f4 | ||
|
|
c696275eaf | ||
|
|
7106d86685 | ||
|
|
da6472013f | ||
|
|
e646392647 | ||
|
|
e040f4e975 | ||
|
|
f4a9c5325b | ||
|
|
8f2e1dbd88 | ||
|
|
595bf0007a | ||
|
|
0cfb7eb80b | ||
|
|
67eb95de92 | ||
|
|
b1f617fcb2 | ||
|
|
960cd4d635 | ||
|
|
6ff9e90e7e | ||
|
|
5b32e8f5c2 | ||
|
|
0bed8cd4a0 | ||
|
|
7cd216c51e | ||
|
|
129ef422e8 | ||
|
|
e5fc3b16d8 | ||
|
|
c0d16995a4 | ||
|
|
70c8292c29 | ||
|
|
d47cd10d77 | ||
|
|
66bd3d7400 | ||
|
|
0cc1edb3ad | ||
|
|
57375a9e1c | ||
|
|
0346535221 | ||
|
|
7d62dcc422 | ||
|
|
b3cd878dfe | ||
|
|
09486a9f97 | ||
|
|
dd79eed495 | ||
|
|
0e1305c8e2 | ||
|
|
88549130e1 | ||
|
|
6dfc59dfcc | ||
|
|
5ba80c24e0 | ||
|
|
da55ac3a27 | ||
|
|
c6f9e010bb | ||
|
|
94ff188a3e | ||
|
|
5a937f1ba1 | ||
|
|
e1c3690a2a | ||
|
|
b08abbbbf6 | ||
|
|
7d6d99c6be | ||
|
|
d3055a97e7 | ||
|
|
0dc5a75dc0 | ||
|
|
f175e60998 | ||
|
|
a632c3c004 | ||
|
|
11789e41b6 | ||
|
|
a9c0845504 | ||
|
|
526c92546f | ||
|
|
eb80ead90b | ||
|
|
386b6353ed | ||
|
|
d09696bbe6 | ||
|
|
a228e8c9b8 | ||
|
|
91a3172519 | ||
|
|
e0d4562782 | ||
|
|
49677b0b70 | ||
|
|
8e34ad5db7 | ||
|
|
eb64390080 | ||
|
|
46577d0d2f | ||
|
|
32029ac699 | ||
|
|
4354945727 | ||
|
|
755573bcda | ||
|
|
205285c35c | ||
|
|
f4e23bf91e | ||
|
|
1fdb5d263a | ||
|
|
c4211538bd | ||
|
|
bcb9ef1876 | ||
|
|
c5441dc199 | ||
|
|
7f417e3397 | ||
|
|
3c35a143ea | ||
|
|
56e2bc30b0 | ||
|
|
eb40a54672 | ||
|
|
15f16f149e | ||
|
|
053d39adaf | ||
|
|
6f71b76e6f | ||
|
|
4b7d8e0df9 | ||
|
|
0def91105f | ||
|
|
8176a204fc | ||
|
|
e8b2492cf1 | ||
|
|
5d4386b1bc | ||
|
|
a6a3989dd4 | ||
|
|
696f47f1f7 | ||
|
|
a3dfcf3326 | ||
|
|
d3e8cb60a1 | ||
|
|
0343396e49 | ||
|
|
f625ff3330 | ||
|
|
362dd663f8 | ||
|
|
5a8a395756 | ||
|
|
afafd206a3 | ||
|
|
48da238920 | ||
|
|
8836ddab41 | ||
|
|
23922e7eba | ||
|
|
f8fe811d5c | ||
|
|
0cc525b722 | ||
|
|
28861d1d7d | ||
|
|
204473cdb5 | ||
|
|
85088a196d | ||
|
|
6e214c3a49 | ||
|
|
96294e9f84 | ||
|
|
b7856f8e27 |
@@ -1,24 +1,16 @@
|
||||
---
|
||||
buildifier: latest
|
||||
platforms:
|
||||
ubuntu1804:
|
||||
matrix:
|
||||
bazel:
|
||||
- 7.x
|
||||
- 8.x
|
||||
tasks:
|
||||
verify_ubuntu2004:
|
||||
platform: ubuntu2004
|
||||
bazel: ${{ bazel }}
|
||||
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:
|
||||
- "//..."
|
||||
test_targets:
|
||||
- "//..."
|
||||
ubuntu2004:
|
||||
environment:
|
||||
CC: clang
|
||||
SWIFT_VERSION: "5.5.3"
|
||||
SWIFT_VERSION: "5.10"
|
||||
SWIFT_HOME: "$HOME/swift-$SWIFT_VERSION"
|
||||
PATH: "$PATH:$SWIFT_HOME/usr/bin"
|
||||
shell_commands:
|
||||
@@ -29,8 +21,40 @@ platforms:
|
||||
- "//..."
|
||||
test_targets:
|
||||
- "//..."
|
||||
macos:
|
||||
verify_ubuntu2204:
|
||||
platform: ubuntu2204
|
||||
bazel: ${{ bazel }}
|
||||
environment:
|
||||
CC: clang
|
||||
SWIFT_VERSION: "5.10"
|
||||
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/ubuntu2204/swift-${SWIFT_VERSION}-RELEASE/swift-${SWIFT_VERSION}-RELEASE-ubuntu22.04.tar.gz | tar xvz --strip-components=1 -C $SWIFT_HOME"
|
||||
build_targets:
|
||||
- "//..."
|
||||
test_targets:
|
||||
- "//..."
|
||||
test_module_cpp:
|
||||
platform: ubuntu2204
|
||||
bazel: ${{ bazel }}
|
||||
working_directory: tests/bazel_repository_test_dir
|
||||
build_targets:
|
||||
- "//..."
|
||||
test_module_ts:
|
||||
platform: ubuntu2204
|
||||
bazel: ${{ bazel }}
|
||||
working_directory: tests/ts/bazel_repository_test_dir
|
||||
test_targets:
|
||||
- "//..."
|
||||
verify_macos:
|
||||
platform: macos
|
||||
bazel: ${{ bazel }}
|
||||
xcode_version: "15.2"
|
||||
build_targets:
|
||||
- "//:flatbuffers"
|
||||
- "//:flatc"
|
||||
test_targets:
|
||||
- "//tests:flatbuffers_test"
|
||||
|
||||
@@ -1 +1,5 @@
|
||||
node_modules
|
||||
ts/node_modules
|
||||
|
||||
# Test workspaces
|
||||
tests/bazel_repository_test_dir
|
||||
tests/ts/bazel_repository_test_dir
|
||||
|
||||
18
.bazelrc
18
.bazelrc
@@ -1,4 +1,18 @@
|
||||
# We cannot use "common" here because the "version" command doesn't support
|
||||
# --deleted_packages. We need to specify it for both build and query instead.
|
||||
build --deleted_packages=tests/ts/bazel_repository_test_dir
|
||||
query --deleted_packages=tests/ts/bazel_repository_test_dir
|
||||
build --deleted_packages=tests/bazel_repository_test_dir,tests/ts/bazel_repository_test_dir
|
||||
query --deleted_packages=tests/bazel_repository_test_dir,tests/ts/bazel_repository_test_dir
|
||||
# Point tools such as coursier (used in rules_jvm_external) to Bazel's internal JDK
|
||||
# suggested in https://github.com/bazelbuild/rules_jvm_external/issues/445
|
||||
common --repo_env=JAVA_HOME=../bazel_tools/jdk
|
||||
common --action_env=JAVA_HOME=../bazel_tools/jdk
|
||||
# Workaround "Error: need --enable_runfiles on Windows for to support rules_js"
|
||||
common:windows --enable_runfiles
|
||||
# Swift is not required on Windows
|
||||
common:windows --deleted_packages=swift
|
||||
# Ignore warnings in external dependencies
|
||||
build --per_file_copt=external/.*@-Wno-everything --host_per_file_copt=external/.*@-Wno-everything
|
||||
# Honor the setting of `skipLibCheck` in the tsconfig.json file.
|
||||
common --@aspect_rules_ts//ts:skipLibCheck=honor_tsconfig
|
||||
# Use "tsc" as the transpiler when ts_project has no `transpiler` set.
|
||||
common --@aspect_rules_ts//ts:default_to_tsc_transpiler
|
||||
|
||||
@@ -1,13 +1,5 @@
|
||||
---
|
||||
Language: Cpp
|
||||
BasedOnStyle: Google
|
||||
DerivePointerAlignment: false
|
||||
PointerAlignment: Right
|
||||
IndentPPDirectives: AfterHash
|
||||
Cpp11BracedListStyle: false
|
||||
AlwaysBreakTemplateDeclarations: false
|
||||
AllowShortCaseLabelsOnASingleLine: true
|
||||
SpaceAfterTemplateKeyword: false
|
||||
AllowShortBlocksOnASingleLine: true
|
||||
...
|
||||
|
||||
|
||||
13
.eslintrc.js
13
.eslintrc.js
@@ -1,13 +0,0 @@
|
||||
/* eslint-env node */
|
||||
|
||||
module.exports = {
|
||||
root: true,
|
||||
parser: '@typescript-eslint/parser',
|
||||
plugins: [
|
||||
'@typescript-eslint',
|
||||
],
|
||||
extends: [
|
||||
'eslint:recommended',
|
||||
'plugin:@typescript-eslint/recommended',
|
||||
]
|
||||
};
|
||||
5
.github/CODEOWNERS
vendored
Normal file
5
.github/CODEOWNERS
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
# Default owner
|
||||
* @dbaileychess derekbailey@google.com
|
||||
|
||||
# Prevent modification of this file
|
||||
.github/CODEOWNERS @dbaileychess derekbailey@google.com
|
||||
11
.github/ISSUE_TEMPLATE/404-doc.md
vendored
Normal file
11
.github/ISSUE_TEMPLATE/404-doc.md
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
---
|
||||
name: 404 Doc
|
||||
about: To fix broken documentation links
|
||||
title: "[Doc 404]"
|
||||
labels: documentation
|
||||
assignees: dbaileychess
|
||||
|
||||
---
|
||||
|
||||
Target URL:
|
||||
[Optional] Source Site:
|
||||
6
.github/dependabot.yml
vendored
Normal file
6
.github/dependabot.yml
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
version: 2
|
||||
updates:
|
||||
- package-ecosystem: "github-actions"
|
||||
directory: "/"
|
||||
schedule:
|
||||
interval: "weekly"
|
||||
145
.github/labeler.yml
vendored
145
.github/labeler.yml
vendored
@@ -5,92 +5,133 @@
|
||||
#
|
||||
# See .github/workflows/label.yml for Github Action workflow script
|
||||
|
||||
c#:
|
||||
- '**/*.cs'
|
||||
- net/**/*
|
||||
- tests/FlatBuffers.Test/**/*
|
||||
- tests/FlatBuffers.Benchmarks/**/*
|
||||
- src/idl_gen_csharp.cpp
|
||||
"c#":
|
||||
- changed-files:
|
||||
- any-glob-to-any-file:
|
||||
- '**/*.cs'
|
||||
- 'net/**/*'
|
||||
- 'tests/FlatBuffers.Test/**/*'
|
||||
- 'tests/FlatBuffers.Benchmarks/**/*'
|
||||
- 'src/idl_gen_csharp.cpp'
|
||||
|
||||
swift:
|
||||
- '**/*.swift'
|
||||
- swift/**/*
|
||||
- tests/swift/**
|
||||
- src/idl_gen_swift.cpp
|
||||
- changed-files:
|
||||
- any-glob-to-any-file:
|
||||
- '**/*.swift'
|
||||
- 'swift/**/*'
|
||||
- 'tests/swift/**'
|
||||
- 'src/idl_gen_swift.cpp'
|
||||
|
||||
nim:
|
||||
- '**/*.nim'
|
||||
- nim/**/*
|
||||
- src/idl_gen_nim.cpp
|
||||
- src/bfbs_gen_nim.cpp
|
||||
- changed-files:
|
||||
- any-glob-to-any-file:
|
||||
- '**/*.nim'
|
||||
- 'nim/**/*'
|
||||
- 'src/idl_gen_nim.cpp'
|
||||
- 'src/bfbs_gen_nim.cpp'
|
||||
|
||||
javascript:
|
||||
- '**/*.js'
|
||||
- src/idl_gen_ts.cpp
|
||||
- changed-files:
|
||||
- any-glob-to-any-file:
|
||||
- '**/*.js'
|
||||
- 'src/idl_gen_ts.cpp'
|
||||
|
||||
typescript:
|
||||
- '**/*.ts'
|
||||
- src/idl_gen_ts.cpp
|
||||
- grpc/flatbuffers-js-grpc/**/*.ts
|
||||
- changed-files:
|
||||
- any-glob-to-any-file:
|
||||
- '**/*.ts'
|
||||
- 'src/idl_gen_ts.cpp'
|
||||
- 'grpc/flatbuffers-js-grpc/**/*.ts'
|
||||
|
||||
golang:
|
||||
- '**/*.go'
|
||||
- src/idl_gen_go.cpp
|
||||
- changed-files:
|
||||
- any-glob-to-any-file:
|
||||
- '**/*.go'
|
||||
- 'src/idl_gen_go.cpp'
|
||||
|
||||
python:
|
||||
- '**/*.py'
|
||||
- src/idl_gen_python.cpp
|
||||
- changed-files:
|
||||
- any-glob-to-any-file:
|
||||
- '**/*.py'
|
||||
- 'src/idl_gen_python.cpp'
|
||||
|
||||
java:
|
||||
- '**/*.java'
|
||||
- src/idl_gen_java.cpp
|
||||
- changed-files:
|
||||
- any-glob-to-any-file:
|
||||
- '**/*.java'
|
||||
- 'src/idl_gen_java.cpp'
|
||||
|
||||
kotlin:
|
||||
- '**/*.kt'
|
||||
- src/idl_gen_kotlin.cpp
|
||||
- changed-files:
|
||||
- any-glob-to-any-file:
|
||||
- '**/*.kt'
|
||||
- 'src/idl_gen_kotlin.cpp'
|
||||
- 'src/idl_gen_kotlin_kmp.cpp'
|
||||
|
||||
lua:
|
||||
- '**/*.lua'
|
||||
- lua/**/*
|
||||
- src/bfbs_gen_lua.cpp
|
||||
- changed-files:
|
||||
- any-glob-to-any-file:
|
||||
- '**/*.lua'
|
||||
- 'lua/**/*'
|
||||
- 'src/bfbs_gen_lua.cpp'
|
||||
|
||||
lobster:
|
||||
- '**/*.lobster'
|
||||
- src/idl_gen_lobster.cpp
|
||||
- changed-files:
|
||||
- any-glob-to-any-file:
|
||||
- '**/*.lobster'
|
||||
- 'src/idl_gen_lobster.cpp'
|
||||
|
||||
php:
|
||||
- '**/*.php'
|
||||
- src/idl_gen_php.cpp
|
||||
- changed-files:
|
||||
- any-glob-to-any-file:
|
||||
- '**/*.php'
|
||||
- 'src/idl_gen_php.cpp'
|
||||
|
||||
rust:
|
||||
- '**/*.rs'
|
||||
- rust/**/*
|
||||
- src/idl_gen_rust.cpp
|
||||
- changed-files:
|
||||
- any-glob-to-any-file:
|
||||
- '**/*.rs'
|
||||
- 'rust/**/*'
|
||||
- 'src/idl_gen_rust.cpp'
|
||||
|
||||
dart:
|
||||
- '**/*.dart'
|
||||
- src/idl_gen_dart.cpp
|
||||
- changed-files:
|
||||
- any-glob-to-any-file:
|
||||
- '**/*.dart'
|
||||
- 'src/idl_gen_dart.cpp'
|
||||
|
||||
c++:
|
||||
- '**/*.cc'
|
||||
- '**/*.cpp'
|
||||
- '**/*.h'
|
||||
"c++":
|
||||
- changed-files:
|
||||
- any-glob-to-any-file:
|
||||
- '**/*.cc'
|
||||
- '**/*.cpp'
|
||||
- '**/*.h'
|
||||
|
||||
json:
|
||||
- '**/*.json'
|
||||
- src/idl_gen_json_schema.cpp
|
||||
- changed-files:
|
||||
- any-glob-to-any-file:
|
||||
- '**/*.json'
|
||||
- 'src/idl_gen_json_schema.cpp'
|
||||
|
||||
codegen:
|
||||
- src/**/*
|
||||
- changed-files:
|
||||
- any-glob-to-any-file:
|
||||
- 'src/**/*'
|
||||
|
||||
documentation:
|
||||
- docs/**/*
|
||||
- '**/*.md'
|
||||
- changed-files:
|
||||
- any-glob-to-any-file:
|
||||
- 'docs/**/*'
|
||||
- '**/*.md'
|
||||
|
||||
CI:
|
||||
- '.github/**/*'
|
||||
- '.bazelci/**/*'
|
||||
- changed-files:
|
||||
- any-glob-to-any-file:
|
||||
- '.github/**/*'
|
||||
- '.bazelci/**/*'
|
||||
|
||||
grpc:
|
||||
- grpc/**/*
|
||||
- src/idl_gen_grpc.cpp
|
||||
- changed-files:
|
||||
- any-glob-to-any-file:
|
||||
- 'grpc/**/*'
|
||||
- 'src/idl_gen_grpc.cpp'
|
||||
|
||||
372
.github/workflows/build.yml
vendored
372
.github/workflows/build.yml
vendored
@@ -9,10 +9,12 @@ on:
|
||||
- "*" # new tag version, like `0.8.4` or else
|
||||
branches:
|
||||
- master
|
||||
- flatbuffers-64
|
||||
pull_request:
|
||||
branches:
|
||||
- master
|
||||
schedule:
|
||||
# Run daily at 4:45 A.M. to catch dependencies that break us.
|
||||
- cron: '45 4 * * *'
|
||||
|
||||
jobs:
|
||||
build-linux:
|
||||
@@ -22,13 +24,13 @@ jobs:
|
||||
digests-gcc: ${{ steps.hash-gcc.outputs.hashes }}
|
||||
digests-clang: ${{ steps.hash-clang.outputs.hashes }}
|
||||
name: Build Linux
|
||||
runs-on: ubuntu-latest
|
||||
runs-on: ubuntu-24.04
|
||||
strategy:
|
||||
matrix:
|
||||
cxx: [g++-10, clang++-12]
|
||||
cxx: [g++-13, clang++-18]
|
||||
fail-fast: false
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- uses: actions/checkout@v6
|
||||
- name: cmake
|
||||
run: CXX=${{ matrix.cxx }} cmake -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=Release -DFLATBUFFERS_STRICT_MODE=ON -DFLATBUFFERS_STATIC_FLATC=ON .
|
||||
- name: build
|
||||
@@ -39,12 +41,8 @@ jobs:
|
||||
run: |
|
||||
chmod +x flatc
|
||||
./flatc --version
|
||||
# - name: flatc tests
|
||||
# run: |
|
||||
# yarn global add esbuild
|
||||
# python3 tests/flatc/main.py
|
||||
- name: upload build artifacts
|
||||
uses: actions/upload-artifact@v1
|
||||
uses: actions/upload-artifact@v7
|
||||
with:
|
||||
name: Linux flatc binary ${{ matrix.cxx }}
|
||||
path: flatc
|
||||
@@ -53,40 +51,42 @@ jobs:
|
||||
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
|
||||
uses: softprops/action-gh-release@v2
|
||||
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/')
|
||||
if: matrix.cxx == 'clang++-18' && startsWith(github.ref, 'refs/tags/')
|
||||
id: hash-clang
|
||||
run: echo "hashes=$(sha256sum Linux.flatc.binary.${{ matrix.cxx }}.zip | base64 -w0)" >> $GITHUB_OUTPUT
|
||||
- name: Generate SLSA subjects - gcc
|
||||
if: matrix.cxx == 'g++-10' && startsWith(github.ref, 'refs/tags/')
|
||||
if: matrix.cxx == 'g++-13' && startsWith(github.ref, 'refs/tags/')
|
||||
id: hash-gcc
|
||||
run: echo "hashes=$(sha256sum Linux.flatc.binary.${{ matrix.cxx }}.zip | base64 -w0)" >> $GITHUB_OUTPUT
|
||||
|
||||
build-linux-no-file-tests:
|
||||
|
||||
build-linux-no-file-tests:
|
||||
name: Build Linux with -DFLATBUFFERS_NO_FILE_TESTS
|
||||
runs-on: ubuntu-latest
|
||||
runs-on: ubuntu-24.04
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- uses: actions/checkout@v6
|
||||
- name: cmake
|
||||
run: CXX=clang++-12 cmake -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=Release -DFLATBUFFERS_STRICT_MODE=ON -DFLATBUFFERS_CXX_FLAGS="-DFLATBUFFERS_NO_FILE_TESTS" .
|
||||
run: CXX=clang++-18 cmake -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=Release -DFLATBUFFERS_STRICT_MODE=ON -DFLATBUFFERS_CXX_FLAGS="-DFLATBUFFERS_NO_FILE_TESTS" .
|
||||
- name: build
|
||||
run: make -j
|
||||
- name: test
|
||||
run: ./flattests
|
||||
|
||||
build-linux-out-of-source:
|
||||
build-linux-out-of-source:
|
||||
name: Build Linux with out-of-source build location
|
||||
runs-on: ubuntu-latest
|
||||
runs-on: ubuntu-24.04
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- uses: actions/checkout@v6
|
||||
- name: make build directory
|
||||
run: mkdir build
|
||||
- name: cmake
|
||||
working-directory: build
|
||||
run: >
|
||||
CXX=clang++-12 cmake .. -G "Unix Makefiles" -DFLATBUFFERS_STRICT_MODE=ON
|
||||
CXX=clang++-18 cmake .. -G "Unix Makefiles" -DFLATBUFFERS_STRICT_MODE=ON
|
||||
-DFLATBUFFERS_BUILD_CPP17=ON -DFLATBUFFERS_CPP_STD=17
|
||||
- name: build
|
||||
working-directory: build
|
||||
@@ -100,22 +100,23 @@ jobs:
|
||||
|
||||
build-linux-cpp-std:
|
||||
name: Build Linux C++
|
||||
runs-on: ubuntu-latest
|
||||
runs-on: ubuntu-24.04
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
std: [11, 14, 17, 20, 23]
|
||||
cxx: [g++-10, clang++-12]
|
||||
cxx: [g++-13, clang++-18]
|
||||
exclude:
|
||||
# GCC 10.3.0 doesn't support std 23
|
||||
- cxx: g++-10
|
||||
# Clang++15 10.3.0 stdlibc++ doesn't fully support std 23
|
||||
- cxx: clang++-18
|
||||
std: 23
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- uses: actions/checkout@v6
|
||||
- name: cmake
|
||||
run: >
|
||||
CXX=${{ matrix.cxx }} cmake -G "Unix Makefiles"
|
||||
-DCMAKE_BUILD_TYPE=Release -DFLATBUFFERS_STRICT_MODE=ON
|
||||
CXX=${{ matrix.cxx }} cmake -G "Unix Makefiles"
|
||||
-DCMAKE_BUILD_TYPE=Release -DFLATBUFFERS_STRICT_MODE=ON
|
||||
-DFLATBUFFERS_CPP_STD=${{ matrix.std }}
|
||||
-DFLATBUFFERS_BUILD_CPP17=${{ matrix.std >= 17 && 'On' || 'Off'}}
|
||||
- name: build
|
||||
@@ -126,21 +127,21 @@ jobs:
|
||||
if: matrix.std >= 17
|
||||
run: ./flattests_cpp17
|
||||
|
||||
build-windows-cpp-std:
|
||||
build-cpp-std:
|
||||
name: Build Windows C++
|
||||
runs-on: windows-2019
|
||||
runs-on: windows-2022
|
||||
strategy:
|
||||
matrix:
|
||||
std: [11, 14, 17, 20, 23]
|
||||
fail-fast: false
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- uses: actions/checkout@v6
|
||||
- name: Add msbuild to PATH
|
||||
uses: microsoft/setup-msbuild@v1.1
|
||||
uses: microsoft/setup-msbuild@v2
|
||||
- name: cmake
|
||||
run: >
|
||||
cmake -G "Visual Studio 16 2019" -A x64 -DCMAKE_BUILD_TYPE=Release
|
||||
-DFLATBUFFERS_STRICT_MODE=ON
|
||||
cmake -G "Visual Studio 17 2022" -A x64 -DCMAKE_BUILD_TYPE=Release
|
||||
-DFLATBUFFERS_STRICT_MODE=ON
|
||||
-DFLATBUFFERS_CPP_STD=${{ matrix.std }}
|
||||
-DFLATBUFFERS_BUILD_CPP17=${{ matrix.std >= 17 && 'On' || 'Off'}}
|
||||
- name: build
|
||||
@@ -156,22 +157,20 @@ jobs:
|
||||
contents: write
|
||||
outputs:
|
||||
digests: ${{ steps.hash.outputs.hashes }}
|
||||
name: Build Windows 2019
|
||||
runs-on: windows-2019
|
||||
name: Build Windows 2022
|
||||
runs-on: windows-2022
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- uses: actions/checkout@v6
|
||||
- name: Add msbuild to PATH
|
||||
uses: microsoft/setup-msbuild@v1.1
|
||||
uses: microsoft/setup-msbuild@v2
|
||||
- name: cmake
|
||||
run: cmake -G "Visual Studio 16 2019" -A x64 -DCMAKE_BUILD_TYPE=Release -DFLATBUFFERS_BUILD_CPP17=ON -DFLATBUFFERS_STRICT_MODE=ON .
|
||||
run: cmake -G "Visual Studio 17 2022" -A x64 -DCMAKE_BUILD_TYPE=Release -DFLATBUFFERS_BUILD_CPP17=ON -DFLATBUFFERS_STRICT_MODE=ON .
|
||||
- name: build
|
||||
run: msbuild.exe FlatBuffers.sln /p:Configuration=Release /p:Platform=x64
|
||||
- name: test
|
||||
run: Release\flattests.exe
|
||||
# - name: flatc tests
|
||||
# run: python3 tests/flatc/main.py --flatc Release\flatc.exe
|
||||
- name: upload build artifacts
|
||||
uses: actions/upload-artifact@v1
|
||||
uses: actions/upload-artifact@v7
|
||||
with:
|
||||
name: Windows flatc binary
|
||||
path: Release\flatc.exe
|
||||
@@ -180,7 +179,7 @@ jobs:
|
||||
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
|
||||
uses: softprops/action-gh-release@v2
|
||||
if: startsWith(github.ref, 'refs/tags/')
|
||||
with:
|
||||
files: Windows.flatc.binary.zip
|
||||
@@ -190,61 +189,37 @@ jobs:
|
||||
shell: bash
|
||||
run: echo "hashes=$(sha256sum Windows.flatc.binary.zip | base64 -w0)" >> $GITHUB_OUTPUT
|
||||
|
||||
build-windows-2017:
|
||||
name: Build Windows 2017
|
||||
runs-on: windows-2019
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- name: Add msbuild to PATH
|
||||
uses: microsoft/setup-msbuild@v1.1
|
||||
- name: cmake
|
||||
run: cmake -G "Visual Studio 16 2019" -A x64 -DCMAKE_BUILD_TYPE=Release -DFLATBUFFERS_STRICT_MODE=ON .
|
||||
- name: build tool version 15 (VS 2017)
|
||||
run: msbuild.exe FlatBuffers.sln /p:Configuration=Release /p:Platform=x64 /p:VisualStudioVersion=15.0
|
||||
- name: test
|
||||
run: Release\flattests.exe
|
||||
|
||||
build-windows-2015:
|
||||
name: Build Windows 2015
|
||||
runs-on: windows-2019
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- name: Add msbuild to PATH
|
||||
uses: microsoft/setup-msbuild@v1.1
|
||||
- name: cmake
|
||||
run: cmake -G "Visual Studio 14 2015" -A x64 -DCMAKE_BUILD_TYPE=Release -DFLATBUFFERS_STRICT_MODE=ON .
|
||||
- name: build tool version 14 (VS 2015)
|
||||
run: msbuild.exe FlatBuffers.sln /p:Configuration=Release /p:Platform=x64 /p:VisualStudioVersion=14.0
|
||||
- name: test
|
||||
run: Release\flattests.exe
|
||||
|
||||
build-dotnet-windows:
|
||||
name: Build .NET Windows
|
||||
runs-on: windows-2019
|
||||
runs-on: windows-2022
|
||||
strategy:
|
||||
matrix:
|
||||
configuration: [
|
||||
'',
|
||||
'-p:UnsafeByteBuffer=true',
|
||||
# Fails two tests currently.
|
||||
#'-p:EnableSpanT=true,UnsafeByteBuffer=true'
|
||||
'-p:UnsafeByteBuffer=true',
|
||||
'-p:EnableSpanT=true,UnsafeByteBuffer=true'
|
||||
]
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- uses: actions/checkout@v6
|
||||
- name: Setup .NET Core SDK
|
||||
uses: actions/setup-dotnet@v3
|
||||
with:
|
||||
dotnet-version: '3.1.x'
|
||||
uses: actions/setup-dotnet@v5
|
||||
with:
|
||||
dotnet-version: '8.0.x'
|
||||
- name: Build
|
||||
run: |
|
||||
cd tests\FlatBuffers.Test
|
||||
dotnet new sln --force --name FlatBuffers.Core.Test
|
||||
dotnet sln FlatBuffers.Core.Test.sln add FlatBuffers.Core.Test.csproj
|
||||
dotnet build -c Release ${{matrix.configuration}} -o out FlatBuffers.Core.Test.sln
|
||||
- name: Run
|
||||
dotnet new sln --force --name FlatBuffers.Test --format sln
|
||||
dotnet sln FlatBuffers.Test.sln add FlatBuffers.Test.csproj
|
||||
dotnet build -c Release ${{matrix.configuration}} FlatBuffers.Test.sln
|
||||
- name: Run net6.0
|
||||
run: |
|
||||
cd tests\FlatBuffers.Test
|
||||
out\FlatBuffers.Core.Test.exe
|
||||
cd tests\FlatBuffers.Test\bin\Release\net6.0
|
||||
dir
|
||||
.\FlatBuffers.Test.exe
|
||||
- name: Run net8.0
|
||||
run: |
|
||||
cd tests\FlatBuffers.Test\bin\Release\net8.0
|
||||
.\FlatBuffers.Test.exe
|
||||
|
||||
build-mac-intel:
|
||||
permissions:
|
||||
@@ -252,11 +227,11 @@ jobs:
|
||||
outputs:
|
||||
digests: ${{ steps.hash.outputs.hashes }}
|
||||
name: Build Mac (for Intel)
|
||||
runs-on: macos-latest
|
||||
runs-on: macos-15-intel
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- uses: actions/checkout@v6
|
||||
- name: cmake
|
||||
run: cmake -G "Xcode" -DCMAKE_BUILD_TYPE=Release -DFLATBUFFERS_STRICT_MODE=ON .
|
||||
run: cmake -G "Xcode" -DCMAKE_OSX_ARCHITECTURES="x86_64" -DCMAKE_BUILD_TYPE=Release -DFLATBUFFERS_STRICT_MODE=ON .
|
||||
- name: build
|
||||
run: xcodebuild -toolchain clang -configuration Release -target flattests
|
||||
- name: check that the binary is x86_64
|
||||
@@ -270,19 +245,17 @@ jobs:
|
||||
run: |
|
||||
chmod +x Release/flatc
|
||||
Release/flatc --version
|
||||
# - name: flatc tests
|
||||
# run: python3 tests/flatc/main.py --flatc Release/flatc
|
||||
- name: upload build artifacts
|
||||
uses: actions/upload-artifact@v1
|
||||
uses: actions/upload-artifact@v7
|
||||
with:
|
||||
name: Mac flatc binary
|
||||
name: Mac flatc binary Intel
|
||||
path: Release/flatc
|
||||
# Below if only for release.
|
||||
- name: Zip file
|
||||
if: startsWith(github.ref, 'refs/tags/')
|
||||
run: mv Release/flatc . && zip MacIntel.flatc.binary.zip flatc
|
||||
- name: Release binary
|
||||
uses: softprops/action-gh-release@v1
|
||||
uses: softprops/action-gh-release@v2
|
||||
if: startsWith(github.ref, 'refs/tags/')
|
||||
with:
|
||||
files: MacIntel.flatc.binary.zip
|
||||
@@ -299,7 +272,7 @@ jobs:
|
||||
name: Build Mac (universal build)
|
||||
runs-on: macos-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- uses: actions/checkout@v6
|
||||
- name: cmake
|
||||
run: cmake -G "Xcode" -DCMAKE_OSX_ARCHITECTURES="arm64;x86_64" -DCMAKE_BUILD_TYPE=Release -DFLATBUFFERS_STRICT_MODE=ON .
|
||||
- name: build
|
||||
@@ -316,16 +289,16 @@ jobs:
|
||||
chmod +x Release/flatc
|
||||
Release/flatc --version
|
||||
- name: upload build artifacts
|
||||
uses: actions/upload-artifact@v1
|
||||
uses: actions/upload-artifact@v7
|
||||
with:
|
||||
name: Mac flatc binary
|
||||
name: Mac flatc binary Universal
|
||||
path: Release/flatc
|
||||
# Below if only for release.
|
||||
- name: Zip file
|
||||
if: startsWith(github.ref, 'refs/tags/')
|
||||
run: mv Release/flatc . && zip Mac.flatc.binary.zip flatc
|
||||
- name: Release binary
|
||||
uses: softprops/action-gh-release@v1
|
||||
uses: softprops/action-gh-release@v2
|
||||
if: startsWith(github.ref, 'refs/tags/')
|
||||
with:
|
||||
files: Mac.flatc.binary.zip
|
||||
@@ -336,14 +309,17 @@ jobs:
|
||||
|
||||
build-android:
|
||||
name: Build Android (on Linux)
|
||||
runs-on: ubuntu-latest
|
||||
if: false #disabled due to continual failure
|
||||
runs-on: ubuntu-24.04
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- uses: actions/checkout@v6
|
||||
- name: set up Java
|
||||
uses: actions/setup-java@v3
|
||||
uses: actions/setup-java@v5
|
||||
with:
|
||||
distribution: 'temurin'
|
||||
java-version: '11'
|
||||
distribution: temurin
|
||||
java-version: 17
|
||||
- name: set up Gradle
|
||||
uses: gradle/actions/setup-gradle@v5
|
||||
- name: set up flatc
|
||||
run: |
|
||||
cmake -DFLATBUFFERS_BUILD_TESTS=OFF -DFLATBUFFERS_BUILD_FLATLIB=OFF -DFLATBUFFERS_BUILD_FLATHASH=OFF -DFLATBUFFERS_STRICT_MODE=ON .
|
||||
@@ -355,12 +331,12 @@ jobs:
|
||||
|
||||
build-generator:
|
||||
name: Check Generated Code
|
||||
runs-on: ubuntu-latest
|
||||
runs-on: ubuntu-24.04
|
||||
strategy:
|
||||
matrix:
|
||||
cxx: [g++-10, clang++-12]
|
||||
cxx: [g++-13, clang++-18]
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- uses: actions/checkout@v6
|
||||
- name: cmake
|
||||
run: CXX=${{ matrix.cxx }} cmake -G "Unix Makefiles" -DFLATBUFFERS_BUILD_TESTS=OFF -DCMAKE_BUILD_TYPE=Release -DFLATBUFFERS_STRICT_MODE=ON . && make -j
|
||||
- name: Generate
|
||||
@@ -370,13 +346,13 @@ jobs:
|
||||
|
||||
build-generator-windows:
|
||||
name: Check Generated Code on Windows
|
||||
runs-on: windows-2019
|
||||
runs-on: windows-2022
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- uses: actions/checkout@v6
|
||||
- name: Add msbuild to PATH
|
||||
uses: microsoft/setup-msbuild@v1.1
|
||||
uses: microsoft/setup-msbuild@v2
|
||||
- name: cmake
|
||||
run: cmake -G "Visual Studio 16 2019" -A x64 -DCMAKE_BUILD_TYPE=Release -DFLATBUFFERS_BUILD_CPP17=ON -DFLATBUFFERS_STRICT_MODE=ON .
|
||||
run: cmake -G "Visual Studio 17 2022" -A x64 -DCMAKE_BUILD_TYPE=Release -DFLATBUFFERS_BUILD_CPP17=ON -DFLATBUFFERS_STRICT_MODE=ON .
|
||||
- name: build
|
||||
run: msbuild.exe FlatBuffers.sln /p:Configuration=Release /p:Platform=x64
|
||||
- name: Generate
|
||||
@@ -386,57 +362,72 @@ jobs:
|
||||
|
||||
build-benchmarks:
|
||||
name: Build Benchmarks (on Linux)
|
||||
runs-on: ubuntu-latest
|
||||
runs-on: ubuntu-24.04
|
||||
strategy:
|
||||
matrix:
|
||||
cxx: [g++-10]
|
||||
cxx: [g++-13]
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- uses: actions/checkout@v6
|
||||
- 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
|
||||
uses: actions/upload-artifact@v7
|
||||
with:
|
||||
name: Linux flatbenchmark results ${{matrix.cxx}}
|
||||
path: benchmarks/results_${{matrix.cxx}}
|
||||
|
||||
build-java:
|
||||
name: Build Java
|
||||
runs-on: ubuntu-latest
|
||||
runs-on: ubuntu-24.04
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- uses: actions/checkout@v6
|
||||
- name: test
|
||||
working-directory: java
|
||||
run: mvn test
|
||||
|
||||
build-kotlin-macos:
|
||||
name: Build Kotlin MacOS
|
||||
runs-on: macos-latest
|
||||
runs-on: macos-15
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v3
|
||||
- uses: gradle/wrapper-validation-action@v1.0.5
|
||||
- uses: actions/setup-java@v3
|
||||
uses: actions/checkout@v6
|
||||
- name: set up Java
|
||||
uses: actions/setup-java@v5
|
||||
with:
|
||||
distribution: 'temurin'
|
||||
java-version: '11'
|
||||
distribution: temurin
|
||||
java-version: 17
|
||||
- name: set up Gradle
|
||||
uses: gradle/actions/setup-gradle@v5
|
||||
- name: Build flatc
|
||||
run: |
|
||||
cmake -DFLATBUFFERS_BUILD_TESTS=OFF -DFLATBUFFERS_BUILD_FLATLIB=OFF -DFLATBUFFERS_BUILD_FLATHASH=OFF .
|
||||
make -j
|
||||
echo "${PWD}" >> $GITHUB_PATH
|
||||
- name: Build
|
||||
working-directory: kotlin
|
||||
run: ./gradlew clean iosX64Test macosX64Test
|
||||
run: ./gradlew clean iosSimulatorArm64Test macosX64Test macosArm64Test
|
||||
|
||||
build-kotlin-linux:
|
||||
name: Build Kotlin Linux
|
||||
runs-on: ubuntu-latest
|
||||
if: false #disabled due to continual failure
|
||||
runs-on: ubuntu-24.04
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v3
|
||||
- uses: actions/setup-java@v3
|
||||
uses: actions/checkout@v6
|
||||
- name: set up Java
|
||||
uses: actions/setup-java@v5
|
||||
with:
|
||||
distribution: 'temurin'
|
||||
java-version: '11'
|
||||
- uses: gradle/wrapper-validation-action@v1.0.5
|
||||
distribution: temurin
|
||||
java-version: 17
|
||||
- name: set up Gradle
|
||||
uses: gradle/actions/setup-gradle@v5
|
||||
- name: Build flatc
|
||||
run: |
|
||||
cmake -DFLATBUFFERS_BUILD_TESTS=OFF -DFLATBUFFERS_BUILD_FLATLIB=OFF -DFLATBUFFERS_BUILD_FLATHASH=OFF .
|
||||
make -j
|
||||
echo "${PWD}" >> $GITHUB_PATH
|
||||
- name: Build
|
||||
working-directory: kotlin
|
||||
# we are using docker's version of gradle
|
||||
@@ -446,27 +437,27 @@ jobs:
|
||||
|
||||
build-rust-linux:
|
||||
name: Build Rust Linux
|
||||
runs-on: ubuntu-latest
|
||||
runs-on: ubuntu-24.04
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- uses: actions/checkout@v6
|
||||
- name: test
|
||||
working-directory: tests
|
||||
run: bash RustTest.sh
|
||||
|
||||
|
||||
build-rust-windows:
|
||||
name: Build Rust Windows
|
||||
runs-on: windows-2019
|
||||
runs-on: windows-2022
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- uses: actions/checkout@v6
|
||||
- name: test
|
||||
working-directory: tests
|
||||
run: ./RustTest.bat
|
||||
|
||||
build-python:
|
||||
name: Build Python
|
||||
runs-on: ubuntu-latest
|
||||
runs-on: ubuntu-24.04
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- uses: actions/checkout@v6
|
||||
- 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
|
||||
@@ -476,9 +467,9 @@ jobs:
|
||||
|
||||
build-go:
|
||||
name: Build Go
|
||||
runs-on: ubuntu-latest
|
||||
runs-on: ubuntu-24.04
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- uses: actions/checkout@v6
|
||||
- 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
|
||||
@@ -488,9 +479,9 @@ jobs:
|
||||
|
||||
build-php:
|
||||
name: Build PHP
|
||||
runs-on: ubuntu-latest
|
||||
runs-on: ubuntu-24.04
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- uses: actions/checkout@v6
|
||||
- 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
|
||||
@@ -501,52 +492,74 @@ jobs:
|
||||
sh phpUnionVectorTest.sh
|
||||
|
||||
build-swift:
|
||||
name: Build Swift
|
||||
runs-on: ubuntu-latest
|
||||
name: Test Swift Linux
|
||||
strategy:
|
||||
matrix:
|
||||
swift: ["6.0", "6.1", "6.2"]
|
||||
runs-on: ubuntu-24.04
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- uses: actions/checkout@v6
|
||||
- uses: swift-actions/setup-swift@v2
|
||||
with:
|
||||
swift-version: ${{ matrix.swift }}
|
||||
- name: Get swift version
|
||||
run: swift --version
|
||||
- name: test
|
||||
working-directory: tests/swift/tests
|
||||
run: |
|
||||
swift build --build-tests
|
||||
swift test
|
||||
run: swift test
|
||||
|
||||
build-swift-windows:
|
||||
name: Test swift windows
|
||||
runs-on: windows-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v6
|
||||
- uses: SwiftyLab/setup-swift@latest
|
||||
with:
|
||||
swift-version: '6.1'
|
||||
- run: swift build
|
||||
- run: swift test
|
||||
|
||||
build-swift-wasm:
|
||||
name: Build Swift Wasm
|
||||
runs-on: ubuntu-latest
|
||||
container:
|
||||
image: ghcr.io/swiftwasm/carton:0.15.3
|
||||
name: Test Swift Wasm
|
||||
runs-on: ubuntu-24.04
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- name: Setup Wasmer
|
||||
uses: wasmerio/setup-wasmer@v2
|
||||
- name: Test
|
||||
working-directory: tests/swift/Wasm.tests
|
||||
run: carton test
|
||||
- uses: actions/checkout@v6
|
||||
- uses: swift-actions/setup-swift@v2
|
||||
with:
|
||||
swift-version: 6.2.1
|
||||
- uses: bytecodealliance/actions/wasmtime/setup@v1
|
||||
- name: Install Swift SDK
|
||||
run: swift sdk install https://download.swift.org/swift-6.2.1-release/wasm-sdk/swift-6.2.1-RELEASE/swift-6.2.1-RELEASE_wasm.artifactbundle.tar.gz --checksum 482b9f95462b87bedfafca94a092cf9ec4496671ca13b43745097122d20f18af
|
||||
- name: Test
|
||||
working-directory: tests/swift/Wasm.tests
|
||||
run: |
|
||||
swift sdk list
|
||||
swift build --build-tests --swift-sdk swift-6.2.1-RELEASE_wasm
|
||||
wasmtime --dir . .build/wasm32-unknown-wasip1/debug/FlatBuffers.Test.Swift.WasmPackageTests.xctest --testing-library swift-testing
|
||||
|
||||
build-ts:
|
||||
name: Build TS
|
||||
runs-on: ubuntu-latest
|
||||
runs-on: ubuntu-24.04
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- uses: actions/checkout@v6
|
||||
- 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: pnpm
|
||||
run: npm install -g pnpm
|
||||
- name: deps
|
||||
run: yarn
|
||||
run: pnpm i
|
||||
- name: compile
|
||||
run: yarn compile
|
||||
run: pnpm compile
|
||||
- name: test
|
||||
working-directory: tests/ts
|
||||
run: |
|
||||
yarn global add esbuild
|
||||
python3 TypeScriptTest.py
|
||||
|
||||
build-dart:
|
||||
name: Build Dart
|
||||
runs-on: ubuntu-latest
|
||||
runs-on: ubuntu-24.04
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- uses: actions/checkout@v6
|
||||
- uses: dart-lang/setup-dart@v1
|
||||
with:
|
||||
sdk: stable
|
||||
@@ -559,26 +572,46 @@ jobs:
|
||||
|
||||
build-nim:
|
||||
name: Build Nim
|
||||
runs-on: ubuntu-latest
|
||||
runs-on: ubuntu-24.04
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- uses: actions/checkout@v6
|
||||
- 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
|
||||
- uses: jiro4989/setup-nim-action@v1
|
||||
- uses: jiro4989/setup-nim-action@v2
|
||||
- name: install library
|
||||
working-directory: nim
|
||||
run: nimble -y develop
|
||||
run: nimble -y develop && nimble install
|
||||
- name: test
|
||||
working-directory: tests/nim
|
||||
run: python3 testnim.py
|
||||
|
||||
bazel:
|
||||
name: Bazel
|
||||
runs-on: ubuntu-24.04
|
||||
steps:
|
||||
- uses: actions/checkout@v6
|
||||
# Explicitly use 8.5.1 until we can update or https://github.com/actions/runner-images/issues/13564 is fixed.
|
||||
- name: Set env
|
||||
run: >
|
||||
echo "USE_BAZEL_VERSION=8.5.1" >> $GITHUB_ENV
|
||||
- name: bazel build
|
||||
run: >
|
||||
bazel build
|
||||
//:flatc
|
||||
//:flatbuffers
|
||||
//tests:flatbuffers_test
|
||||
- name: bazel test
|
||||
run: >
|
||||
bazel test
|
||||
//tests:flatbuffers_test
|
||||
|
||||
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
|
||||
runs-on: ubuntu-24.04
|
||||
steps:
|
||||
- name: Merge results
|
||||
id: hash
|
||||
@@ -604,8 +637,7 @@ jobs:
|
||||
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.1
|
||||
uses: slsa-framework/slsa-github-generator/.github/workflows/generator_generic_slsa3.yml@v2.1.0
|
||||
with:
|
||||
base64-subjects: "${{ needs.release-digests.outputs.digests }}"
|
||||
upload-assets: true # Optional: Upload to a new release
|
||||
compile-generator: true # Workaround for https://github.com/slsa-framework/slsa-github-generator/issues/1163
|
||||
|
||||
71
.github/workflows/codeql.yml
vendored
71
.github/workflows/codeql.yml
vendored
@@ -1,71 +0,0 @@
|
||||
# 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
|
||||
36
.github/workflows/docs.yml
vendored
Normal file
36
.github/workflows/docs.yml
vendored
Normal file
@@ -0,0 +1,36 @@
|
||||
name: docs
|
||||
on:
|
||||
# For manual pushes.
|
||||
workflow_dispatch:
|
||||
|
||||
# Pushes to main that touch the documentation directory.
|
||||
push:
|
||||
branches:
|
||||
- master
|
||||
paths:
|
||||
- 'docs/**'
|
||||
|
||||
permissions:
|
||||
contents: write
|
||||
jobs:
|
||||
deploy:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v6
|
||||
- name: Configure Git Credentials
|
||||
run: |
|
||||
git config user.name github-actions[bot]
|
||||
git config user.email 41898282+github-actions[bot]@users.noreply.github.com
|
||||
- uses: actions/setup-python@v6
|
||||
with:
|
||||
python-version: 3.x
|
||||
- run: echo "cache_id=$(date --utc '+%V')" >> $GITHUB_ENV
|
||||
- uses: actions/cache@v5
|
||||
with:
|
||||
key: mkdocs-material-${{ env.cache_id }}
|
||||
path: .cache
|
||||
restore-keys: |
|
||||
mkdocs-material-
|
||||
- run: pip install mkdocs-material
|
||||
- run: pip install mkdocs-redirects
|
||||
- run: mkdocs gh-deploy --force -f docs/mkdocs.yml
|
||||
35
.github/workflows/extrabuild.yml
vendored
35
.github/workflows/extrabuild.yml
vendored
@@ -1,35 +0,0 @@
|
||||
name: Build and unit tests that are more time consuming
|
||||
permissions: read-all
|
||||
|
||||
on:
|
||||
# For manual tests.
|
||||
workflow_dispatch:
|
||||
pull_request:
|
||||
types:
|
||||
- closed
|
||||
schedule:
|
||||
- cron: "30 20 * * *"
|
||||
|
||||
jobs:
|
||||
build-linux-s390x:
|
||||
name: Build Linux on s390x arch and run unit tests
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- uses: uraimo/run-on-arch-action@v2
|
||||
name: Run commands
|
||||
id: runcmd
|
||||
with:
|
||||
arch: s390x
|
||||
distro: ubuntu_latest
|
||||
install: |
|
||||
apt-get update -q -y
|
||||
apt-get -y install cmake
|
||||
apt-get -y install make
|
||||
apt-get -y install g++
|
||||
run: |
|
||||
lscpu | grep Endian
|
||||
cmake -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=Release
|
||||
make -j
|
||||
./flattests
|
||||
|
||||
4
.github/workflows/label.yml
vendored
4
.github/workflows/label.yml
vendored
@@ -19,6 +19,6 @@ jobs:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- uses: actions/labeler@main
|
||||
- uses: actions/labeler@v6
|
||||
with:
|
||||
repo-token: "${{ secrets.GITHUB_TOKEN }}"
|
||||
repo-token: "${{ secrets.GITHUB_TOKEN }}"
|
||||
|
||||
4
.github/workflows/main.yml
vendored
4
.github/workflows/main.yml
vendored
@@ -1,7 +1,7 @@
|
||||
name: OSS-Fuzz
|
||||
permissions: read-all
|
||||
|
||||
on:
|
||||
on:
|
||||
pull_request:
|
||||
branches:
|
||||
- master
|
||||
@@ -27,7 +27,7 @@ jobs:
|
||||
language: c++
|
||||
fuzz-seconds: 60
|
||||
- name: Upload Crash
|
||||
uses: actions/upload-artifact@v1
|
||||
uses: actions/upload-artifact@v7
|
||||
if: failure() && steps.build.outcome == 'success'
|
||||
with:
|
||||
name: artifacts
|
||||
|
||||
106
.github/workflows/release.yml
vendored
106
.github/workflows/release.yml
vendored
@@ -5,23 +5,23 @@ on:
|
||||
# For manual tests.
|
||||
workflow_dispatch:
|
||||
release:
|
||||
types: [created]
|
||||
types: [published]
|
||||
|
||||
jobs:
|
||||
publish-npm:
|
||||
name: Publish NPM
|
||||
runs-on: ubuntu-latest
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- uses: actions/setup-node@v3
|
||||
- uses: actions/checkout@v6
|
||||
- uses: actions/setup-node@v6
|
||||
with:
|
||||
node-version: '16.x'
|
||||
node-version: '20.x'
|
||||
registry-url: 'https://registry.npmjs.org'
|
||||
|
||||
|
||||
- run: npm publish
|
||||
env:
|
||||
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
|
||||
|
||||
|
||||
publish-pypi:
|
||||
name: Publish PyPi
|
||||
runs-on: ubuntu-latest
|
||||
@@ -29,20 +29,20 @@ jobs:
|
||||
run:
|
||||
working-directory: ./python
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- uses: actions/setup-python@v4
|
||||
- uses: actions/checkout@v6
|
||||
- uses: actions/setup-python@v6
|
||||
with:
|
||||
python-version: '3.10'
|
||||
|
||||
|
||||
- name: Install Dependencies
|
||||
run: |
|
||||
python3 -m pip install --upgrade pip
|
||||
python3 -m pip install setuptools wheel twine
|
||||
|
||||
python3 -m pip install build twine
|
||||
|
||||
- name: Build
|
||||
run: |
|
||||
python3 setup.py sdist bdist_wheel
|
||||
|
||||
python3 -m build .
|
||||
|
||||
- name: Upload to PyPi
|
||||
run: |
|
||||
python3 -m twine upload dist/*
|
||||
@@ -57,23 +57,22 @@ jobs:
|
||||
run:
|
||||
working-directory: ./net/flatbuffers
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- uses: actions/setup-dotnet@v3
|
||||
- uses: actions/checkout@v6
|
||||
- uses: actions/setup-dotnet@v5
|
||||
with:
|
||||
dotnet-version: '6.0.x'
|
||||
|
||||
dotnet-version: '8.0.x'
|
||||
- name: Build
|
||||
run: |
|
||||
dotnet build Google.FlatBuffers.csproj -c Release
|
||||
|
||||
|
||||
- name: Pack
|
||||
run: |
|
||||
dotnet pack Google.FlatBuffers.csproj -c Release
|
||||
|
||||
|
||||
- name: Upload to NuGet
|
||||
run: |
|
||||
dotnet nuget push .\bin\Release\Google.FlatBuffers.*.nupkg -k ${{ secrets.NUGET_API_KEY }} -s https://api.nuget.org/v3/index.json
|
||||
|
||||
dotnet nuget push .\bin\Release\Google.FlatBuffers.*.nupkg -k ${{ secrets.NUGET_API_KEY }} -s https://api.nuget.org/v3/index.json
|
||||
|
||||
publish-maven:
|
||||
name: Publish Maven
|
||||
runs-on: ubuntu-latest
|
||||
@@ -81,10 +80,10 @@ jobs:
|
||||
run:
|
||||
working-directory: ./java
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
|
||||
- uses: actions/checkout@v6
|
||||
|
||||
- name: Set up Maven Central Repository
|
||||
uses: actions/setup-java@v3
|
||||
uses: actions/setup-java@v5
|
||||
with:
|
||||
java-version: '11'
|
||||
distribution: 'adopt'
|
||||
@@ -94,13 +93,60 @@ jobs:
|
||||
server-password: OSSRH_PASSWORD
|
||||
gpg-private-key: ${{ secrets.MAVEN_GPG_PRIVATE_KEY }}
|
||||
gpg-passphrase: MAVEN_GPG_PASSPHRASE # this needs to be an env var
|
||||
|
||||
|
||||
- name: Publish Maven
|
||||
run: mvn --batch-mode clean deploy
|
||||
env:
|
||||
OSSRH_USERNAME: ${{ secrets.OSSRH_USERNAME }}
|
||||
OSSRH_PASSWORD: ${{ secrets.OSSRH_TOKEN }}
|
||||
OSSRH_USERNAME: ${{ secrets.OSSRH_USER_V2 }}
|
||||
OSSRH_PASSWORD: ${{ secrets.OSSRH_TOKEN_V2 }}
|
||||
MAVEN_GPG_PASSPHRASE: ${{ secrets.MAVEN_GPG_PASSPHRASE }}
|
||||
|
||||
|
||||
|
||||
publish-maven-kotlin:
|
||||
name: Publish Maven - Kotlin
|
||||
runs-on: ubuntu-latest
|
||||
defaults:
|
||||
run:
|
||||
working-directory: ./kotlin
|
||||
steps:
|
||||
- uses: actions/checkout@v6
|
||||
- name: Set up Maven Central Repository
|
||||
uses: actions/setup-java@v5
|
||||
with:
|
||||
java-version: '11'
|
||||
distribution: 'adopt'
|
||||
cache: 'maven'
|
||||
server-id: ossrh
|
||||
server-username: OSSRH_USERNAME
|
||||
server-password: OSSRH_PASSWORD
|
||||
gpg-private-key: ${{ secrets.MAVEN_GPG_PRIVATE_KEY }}
|
||||
gpg-passphrase: MAVEN_GPG_PASSPHRASE # this needs to be an env var
|
||||
|
||||
- name: Publish Kotlin Library on Maven
|
||||
run: ./gradlew publishAllPublicationsToSonatypeRepository
|
||||
env:
|
||||
OSSRH_USERNAME: ${{ secrets.OSSRH_USER_V2 }}
|
||||
OSSRH_PASSWORD: ${{ secrets.OSSRH_TOKEN_V2 }}
|
||||
MAVEN_GPG_PASSPHRASE: ${{ secrets.MAVEN_GPG_PASSPHRASE }}
|
||||
|
||||
|
||||
publish-crates:
|
||||
name: Publish crates.io
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v6
|
||||
- uses: actions-rs/toolchain@v1
|
||||
with:
|
||||
toolchain: stable
|
||||
override: true
|
||||
|
||||
- name: Publish Flatbuffers
|
||||
uses: katyo/publish-crates@v2
|
||||
with:
|
||||
path: ./rust/flatbuffers
|
||||
registry-token: ${{ secrets.CARGO_TOKEN }}
|
||||
|
||||
- name: Publish Flexbuffers
|
||||
uses: katyo/publish-crates@v2
|
||||
with:
|
||||
path: ./rust/flexbuffers
|
||||
registry-token: ${{ secrets.CARGO_TOKEN }}
|
||||
|
||||
55
.github/workflows/scorecards.yml
vendored
55
.github/workflows/scorecards.yml
vendored
@@ -1,55 +0,0 @@
|
||||
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@ce330fde6b1a5c9c75b417e7efc510b822a35564 # v1.1.2
|
||||
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
|
||||
10
.github/workflows/stale.yml
vendored
10
.github/workflows/stale.yml
vendored
@@ -15,7 +15,7 @@ jobs:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- uses: actions/stale@v7.0.0
|
||||
- uses: actions/stale@v10
|
||||
with:
|
||||
repo-token: ${{ secrets.GITHUB_TOKEN }}
|
||||
operations-per-run: 500
|
||||
@@ -28,10 +28,10 @@ jobs:
|
||||
days-before-issue-close: 14 # 2 weeks
|
||||
exempt-issue-labels: not-stale
|
||||
|
||||
stale-pr-message: 'This pull request is stale because it has been open 3 weeks with no activity. Please comment or label `not-stale`, or this will be closed in 7 days.'
|
||||
close-pr-message: 'This pull request was automatically closed due to no activity for 3 weeks plus the 7 day notice period.'
|
||||
days-before-pr-stale: 21 # 3 weeks
|
||||
days-before-pr-close: 7 # 1 week
|
||||
stale-pr-message: 'This pull request is stale because it has been open 6 months with no activity. Please comment or label `not-stale`, or this will be closed in 14 days.'
|
||||
close-pr-message: 'This pull request was automatically closed due to no activity for 6 months plus the 14 day notice period.'
|
||||
days-before-pr-stale: 182 # 6 months
|
||||
days-before-pr-close: 14 # 2 week
|
||||
exempt-pr-labels: not-stale
|
||||
exempt-draft-pr: false
|
||||
|
||||
|
||||
9
.gitignore
vendored
9
.gitignore
vendored
@@ -151,3 +151,12 @@ flatbuffers.pc
|
||||
# https://cmake.org/cmake/help/latest/module/FetchContent.html#variable:FETCHCONTENT_BASE_DIR
|
||||
cmake-build-debug/
|
||||
_deps/
|
||||
**/.gradle/**
|
||||
kotlin/**/generated
|
||||
MODULE.bazel.lock
|
||||
|
||||
# Ignore the generated docs
|
||||
docs/site
|
||||
|
||||
# Ignore generated files
|
||||
*.fbs.h
|
||||
|
||||
26
BUILD.bazel
26
BUILD.bazel
@@ -1,5 +1,3 @@
|
||||
load("@aspect_rules_js//npm:defs.bzl", "npm_link_package")
|
||||
load("@npm//:defs.bzl", "npm_link_all_packages")
|
||||
load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_library")
|
||||
|
||||
licenses(["notice"])
|
||||
@@ -8,13 +6,6 @@ package(
|
||||
default_visibility = ["//visibility:public"],
|
||||
)
|
||||
|
||||
npm_link_all_packages(name = "node_modules")
|
||||
|
||||
npm_link_package(
|
||||
name = "node_modules/flatbuffers",
|
||||
src = "//ts:flatbuffers",
|
||||
)
|
||||
|
||||
exports_files([
|
||||
"LICENSE",
|
||||
"tsconfig.json",
|
||||
@@ -37,11 +28,16 @@ config_setting(
|
||||
filegroup(
|
||||
name = "distribution",
|
||||
srcs = [
|
||||
".bazelignore",
|
||||
".npmrc",
|
||||
"BUILD.bazel",
|
||||
"WORKSPACE",
|
||||
"MODULE.bazel",
|
||||
"build_defs.bzl",
|
||||
"package.json",
|
||||
"pnpm-lock.yaml",
|
||||
"typescript.bzl",
|
||||
"//grpc/src/compiler:distribution",
|
||||
"//include/codegen:distribution",
|
||||
"//reflection:distribution",
|
||||
"//src:distribution",
|
||||
"//ts:distribution",
|
||||
@@ -125,15 +121,7 @@ filegroup(
|
||||
# Library used by flatbuffer_cc_library rules.
|
||||
cc_library(
|
||||
name = "runtime_cc",
|
||||
hdrs = [
|
||||
"include/flatbuffers/base.h",
|
||||
"include/flatbuffers/flatbuffers.h",
|
||||
"include/flatbuffers/flexbuffers.h",
|
||||
"include/flatbuffers/stl_emulation.h",
|
||||
"include/flatbuffers/util.h",
|
||||
"include/flatbuffers/vector.h",
|
||||
"include/flatbuffers/verifier.h",
|
||||
],
|
||||
hdrs = ["//:public_headers"],
|
||||
linkstatic = 1,
|
||||
strip_include_prefix = "/include",
|
||||
)
|
||||
|
||||
46
CHANGELOG.md
46
CHANGELOG.md
@@ -4,6 +4,52 @@ 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.
|
||||
|
||||
## [25.12.19] (December 19 2025)(https://github.com/google/flatbuffers/releases/tag/v25.12.19)
|
||||
|
||||
* [C++] Default emptry vector support (#8870)
|
||||
* [C++] Add --gen-absl-hash option (#8868)
|
||||
* [Kotlin] Upgrade to MacOS 15 (#8845)
|
||||
* [C++] Fix vector of table with naked ptrs (#8830)
|
||||
* [Python] Optimize Offset/Pad/Prep (#8808)
|
||||
* Implement `--file-names-only` (#8788)
|
||||
* [C++] Fix size verifer (#8740)
|
||||
|
||||
## [25.9.23] (September 23 2025)(https://github.com/google/flatbuffers/releases/tag/v25.9.23)
|
||||
|
||||
* flatc: `--grpc-callback-api` flag generates C++ gRPC Callback API server `CallbackService` skeletons AND client native callback/async stubs (unary + all streaming reactor forms) (opt-in, non-breaking, issue #8596).
|
||||
* Swift - Adds new API to reduce memory copying within swift (#8484)
|
||||
* Rust - Support Rust edition 2024 (#8638)
|
||||
* [C++] - Use the Google Style for clang-format without exceptions (#8706)
|
||||
|
||||
## [25.2.10] (February 10 2025)(https://github.com/google/flatbuffers/releases/tag/v25.2.10)
|
||||
|
||||
* Removed the old documentation pages. The new one is live at https://flatbuffers.dev
|
||||
* Swift version 6.0 support (#8414)
|
||||
|
||||
## [25.1.24] (January 24 2025)(https://github.com/google/flatbuffers/releases/tag/v25.1.24)
|
||||
|
||||
* Mostly related to bazel build support.
|
||||
* Min bazel supported is now 7 or higher, as WORKSPACE files are removed (#8509)
|
||||
* Minor C++ codegen fix removing extra semicolon (#8488)
|
||||
|
||||
## [25.1.21] (January 21 2025)(https://github.com/google/flatbuffers/releases/tag/v25.1.21)
|
||||
|
||||
* Rust Full Reflection (#8102)
|
||||
* Mostly documentation updates hosted at https://flatbuffers.dev
|
||||
|
||||
## [24.3.25] (March 25 2024)(https://github.com/google/flatbuffers/releases/tag/v24.3.25)
|
||||
|
||||
* Fixed license metadata parsing (#8253)
|
||||
* [C++] Allow string_view in `LookUpByKey` in addition to null-terminated c-style strings (#8203)
|
||||
|
||||
## [24.3.7] (March 7 2024)(https://github.com/google/flatbuffers/releases/tag/v24.3.7)
|
||||
|
||||
* Just to fix some of the CI build issues from the 24.3.6 release.
|
||||
|
||||
## [24.3.6] (March 6 2024)(https://github.com/google/flatbuffers/releases/tag/v24.3.6)
|
||||
|
||||
* Fix typescript object API to allow 0 values for null-default scalars (#7864)
|
||||
|
||||
## [23.5.26 (May 26 2023)](https://github.com/google/flatbuffers/releases/tag/v23.5.26)
|
||||
|
||||
* Mostly bug fixing for 64-bit support
|
||||
|
||||
@@ -305,8 +305,7 @@ function(flatbuffers_generate_headers)
|
||||
${FLATBUFFERS_GENERATE_HEADERS_SCHEMAS})
|
||||
add_dependencies(
|
||||
${FLATBUFFERS_GENERATE_HEADERS_TARGET}
|
||||
${FLATC}
|
||||
${FLATBUFFERS_GENERATE_HEADERS_SCHEMAS})
|
||||
${FLATC_TARGET})
|
||||
target_include_directories(
|
||||
${FLATBUFFERS_GENERATE_HEADERS_TARGET}
|
||||
INTERFACE ${generated_target_dir})
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
set(VERSION_MAJOR 23)
|
||||
set(VERSION_MINOR 5)
|
||||
set(VERSION_PATCH 26)
|
||||
set(VERSION_MAJOR 25)
|
||||
set(VERSION_MINOR 12)
|
||||
set(VERSION_PATCH 19)
|
||||
set(VERSION_COMMIT 0)
|
||||
|
||||
if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/.git")
|
||||
@@ -29,7 +29,7 @@ if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/.git")
|
||||
message(WARNING "\"${GIT_DESCRIBE_DIRTY}\" does not match pattern v<major>.<minor>.<patch>-<commit>")
|
||||
endif()
|
||||
else()
|
||||
message(WARNING "git describe failed with exit code: ${GIT_DESCRIBE_RESULT}")
|
||||
message(WARNING "git describe failed with exit code: ${GIT_DESCRIBE_RESULT}\nMake sure you cloned with tags or run 'git fetch --tags'.")
|
||||
endif()
|
||||
else()
|
||||
message(WARNING "git is not found")
|
||||
|
||||
@@ -112,6 +112,7 @@ endif()
|
||||
add_definitions(-DFLATBUFFERS_LOCALE_INDEPENDENT=$<BOOL:${FLATBUFFERS_LOCALE_INDEPENDENT}>)
|
||||
|
||||
if(NOT WIN32)
|
||||
include(CheckSymbolExists)
|
||||
check_symbol_exists(realpath "stdlib.h" HAVE_REALPATH)
|
||||
if(NOT HAVE_REALPATH)
|
||||
add_definitions(-DFLATBUFFERS_NO_ABSOLUTE_PATH_RESOLUTION)
|
||||
@@ -146,6 +147,8 @@ set(FlatBuffers_Library_SRCS
|
||||
include/flatbuffers/vector.h
|
||||
include/flatbuffers/vector_downward.h
|
||||
include/flatbuffers/verifier.h
|
||||
src/file_manager.cpp
|
||||
src/file_name_manager.cpp
|
||||
src/idl_parser.cpp
|
||||
src/idl_gen_text.cpp
|
||||
src/reflection.cpp
|
||||
@@ -160,6 +163,7 @@ set(FlatBuffers_Compiler_SRCS
|
||||
src/idl_gen_csharp.cpp
|
||||
src/idl_gen_dart.cpp
|
||||
src/idl_gen_kotlin.cpp
|
||||
src/idl_gen_kotlin_kmp.cpp
|
||||
src/idl_gen_go.cpp
|
||||
src/idl_gen_java.cpp
|
||||
src/idl_gen_ts.cpp
|
||||
@@ -171,9 +175,6 @@ set(FlatBuffers_Compiler_SRCS
|
||||
src/idl_gen_grpc.cpp
|
||||
src/idl_gen_json_schema.cpp
|
||||
src/idl_gen_swift.cpp
|
||||
src/file_name_saving_file_manager.cpp
|
||||
src/file_binary_writer.cpp
|
||||
src/file_writer.cpp
|
||||
src/idl_namer.h
|
||||
src/namer.h
|
||||
src/flatc.cpp
|
||||
@@ -182,6 +183,10 @@ set(FlatBuffers_Compiler_SRCS
|
||||
src/bfbs_gen_lua.h
|
||||
src/bfbs_gen_nim.h
|
||||
src/bfbs_namer.h
|
||||
include/codegen/idl_namer.h
|
||||
include/codegen/namer.h
|
||||
include/codegen/python.h
|
||||
include/codegen/python.cc
|
||||
include/flatbuffers/code_generators.h
|
||||
src/binary_annotator.h
|
||||
src/binary_annotator.cpp
|
||||
@@ -213,6 +218,8 @@ set(FlatHash_SRCS
|
||||
set(FlatBuffers_Tests_SRCS
|
||||
${FlatBuffers_Library_SRCS}
|
||||
src/idl_gen_fbs.cpp
|
||||
tests/default_vectors_strings_test.cpp
|
||||
tests/default_vectors_strings_test.h
|
||||
tests/evolution_test.cpp
|
||||
tests/flexbuffers_test.cpp
|
||||
tests/fuzz_test.cpp
|
||||
@@ -229,6 +236,8 @@ set(FlatBuffers_Tests_SRCS
|
||||
tests/test_builder.h
|
||||
tests/test_builder.cpp
|
||||
tests/util_test.cpp
|
||||
tests/vector_table_naked_ptr_test.h
|
||||
tests/vector_table_naked_ptr_test.cpp
|
||||
tests/native_type_test_impl.h
|
||||
tests/native_type_test_impl.cpp
|
||||
tests/alignment_test.h
|
||||
@@ -273,6 +282,8 @@ set(FlatBuffers_GRPCTest_SRCS
|
||||
tests/test_builder.cpp
|
||||
grpc/tests/grpctest.cpp
|
||||
grpc/tests/message_builder_test.cpp
|
||||
grpc/tests/grpctest_callback_compile.cpp
|
||||
grpc/tests/grpctest_callback_client_compile.cpp
|
||||
)
|
||||
|
||||
# TODO(dbaileychess): Figure out how this would now work. I posted a question on
|
||||
@@ -487,28 +498,34 @@ if(FLATBUFFERS_BUILD_SHAREDLIB)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
function(compile_schema SRC_FBS OPT OUT_GEN_FILE)
|
||||
function(compile_schema SRC_FBS OPT SUFFIX OUT_GEN_FILE)
|
||||
get_filename_component(SRC_FBS_DIR ${SRC_FBS} PATH)
|
||||
string(REGEX REPLACE "\\.fbs$" "_generated.h" GEN_HEADER ${SRC_FBS})
|
||||
string(REGEX REPLACE "\\.fbs$" "${SUFFIX}.h" GEN_HEADER ${SRC_FBS})
|
||||
add_custom_command(
|
||||
OUTPUT ${GEN_HEADER}
|
||||
COMMAND "${FLATBUFFERS_FLATC_EXECUTABLE}"
|
||||
${OPT}
|
||||
--filename-suffix ${SUFFIX}
|
||||
-o "${SRC_FBS_DIR}"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/${SRC_FBS}"
|
||||
DEPENDS flatc
|
||||
DEPENDS flatc ${SRC_FBS}
|
||||
COMMENT "flatc generation: `${SRC_FBS}` -> `${GEN_HEADER}`"
|
||||
)
|
||||
)
|
||||
set(${OUT_GEN_FILE} ${GEN_HEADER} PARENT_SCOPE)
|
||||
endfunction()
|
||||
|
||||
function(compile_schema_for_test SRC_FBS OPT)
|
||||
compile_schema("${SRC_FBS}" "${OPT}" GEN_FILE)
|
||||
compile_schema("${SRC_FBS}" "${OPT}" "_generated" GEN_FILE)
|
||||
target_sources(flattests PRIVATE ${GEN_FILE})
|
||||
endfunction()
|
||||
|
||||
function(compile_schema_for_test_fbsh SRC_FBS OPT)
|
||||
compile_schema("${SRC_FBS}" "${OPT}" ".fbs" GEN_FILE)
|
||||
target_sources(flattests PRIVATE ${GEN_FILE})
|
||||
endfunction()
|
||||
|
||||
function(compile_schema_for_samples SRC_FBS OPT)
|
||||
compile_schema("${SRC_FBS}" "${OPT}" GEN_FILE)
|
||||
compile_schema("${SRC_FBS}" "${OPT}" "_generated" GEN_FILE)
|
||||
target_sources(flatsample PRIVATE ${GEN_FILE})
|
||||
endfunction()
|
||||
|
||||
@@ -529,18 +546,20 @@ if(FLATBUFFERS_BUILD_TESTS)
|
||||
add_definitions(-DFLATBUFFERS_TEST_PATH_PREFIX=${CMAKE_CURRENT_SOURCE_DIR}/)
|
||||
|
||||
# The flattest target needs some generated files
|
||||
SET(FLATC_OPT --cpp --gen-mutable --gen-object-api --reflect-names)
|
||||
SET(FLATC_OPT_COMP ${FLATC_OPT};--gen-compare)
|
||||
SET(FLATC_OPT_COMP --cpp --gen-compare --gen-mutable --gen-object-api --reflect-names)
|
||||
SET(FLATC_OPT_SCOPED_ENUMS ${FLATC_OPT_COMP};--scoped-enums)
|
||||
|
||||
compile_schema_for_test(tests/alignment_test.fbs "${FLATC_OPT_COMP}")
|
||||
compile_schema_for_test(tests/arrays_test.fbs "${FLATC_OPT_COMP};--scoped-enums")
|
||||
compile_schema_for_test_fbsh(tests/default_vectors_strings_test.fbs "${FLATC_OPT_COMP}")
|
||||
compile_schema_for_test(tests/arrays_test.fbs "${FLATC_OPT_SCOPED_ENUMS}")
|
||||
compile_schema_for_test(tests/native_inline_table_test.fbs "${FLATC_OPT_COMP}")
|
||||
compile_schema_for_test(tests/native_type_test.fbs "${FLATC_OPT}")
|
||||
compile_schema_for_test(tests/native_type_test.fbs "${FLATC_OPT_COMP}")
|
||||
compile_schema_for_test(tests/key_field/key_field_sample.fbs "${FLATC_OPT_COMP}")
|
||||
compile_schema_for_test(tests/64bit/test_64bit.fbs "${FLATC_OPT_COMP};--bfbs-gen-embed")
|
||||
compile_schema_for_test(tests/64bit/evolution/v1.fbs "${FLATC_OPT_COMP}")
|
||||
compile_schema_for_test(tests/64bit/evolution/v2.fbs "${FLATC_OPT_COMP}")
|
||||
compile_schema_for_test(tests/union_underlying_type_test.fbs "${FLATC_OPT_COMP}")
|
||||
compile_schema_for_test(tests/union_underlying_type_test.fbs "${FLATC_OPT_SCOPED_ENUMS}")
|
||||
compile_schema_for_test(tests/cross_namespace_pack_test.fbs "${FLATC_OPT_COMP}")
|
||||
|
||||
if(FLATBUFFERS_CODE_SANITIZE)
|
||||
add_fsanitize_to_target(flattests ${FLATBUFFERS_CODE_SANITIZE})
|
||||
@@ -554,12 +573,14 @@ if(FLATBUFFERS_BUILD_TESTS)
|
||||
|
||||
# Add a library so there is a single target that the generated samples can
|
||||
# link too.
|
||||
add_library(flatsample INTERFACE)
|
||||
if(MSVC OR ${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.20.0")
|
||||
add_library(flatsample INTERFACE)
|
||||
else()
|
||||
add_library(flatsample STATIC)
|
||||
endif()
|
||||
|
||||
# Since flatsample has no sources, we have to explicitly set the linker lang.
|
||||
set_target_properties(flatsample PROPERTIES LINKER_LANGUAGE CXX)
|
||||
|
||||
compile_schema_for_samples(samples/monster.fbs "${FLATC_OPT_COMP}")
|
||||
|
||||
target_link_libraries(flatsamplebinary PRIVATE $<BUILD_INTERFACE:ProjectConfig> flatsample)
|
||||
target_link_libraries(flatsampletext PRIVATE $<BUILD_INTERFACE:ProjectConfig> flatsample)
|
||||
@@ -592,7 +613,7 @@ if(FLATBUFFERS_BUILD_GRPCTEST)
|
||||
find_package(protobuf CONFIG REQUIRED)
|
||||
find_package(gRPC CONFIG REQUIRED)
|
||||
add_executable(grpctest ${FlatBuffers_GRPCTest_SRCS})
|
||||
target_link_libraries(grpctext
|
||||
target_link_libraries(grpctest
|
||||
PRIVATE
|
||||
$<BUILD_INTERFACE:ProjectConfig>
|
||||
gRPC::grpc++_unsecure
|
||||
|
||||
@@ -30,7 +30,7 @@ Some tips for good pull requests:
|
||||
* Write a descriptive commit message. What problem are you solving and what
|
||||
are the consequences? Where and what did you test? Some good tips:
|
||||
[here](http://robots.thoughtbot.com/5-useful-tips-for-a-better-commit-message)
|
||||
and [here](https://www.kernel.org/doc/Documentation/SubmittingPatches).
|
||||
and [here](https://www.kernel.org/doc/Documentation/process/submitting-patches.rst).
|
||||
* If your PR consists of multiple commits which are successive improvements /
|
||||
fixes to your first commit, consider squashing them into a single commit
|
||||
(`git rebase -i`) such that your PR is a single commit on top of the current
|
||||
@@ -40,3 +40,26 @@ Some tips for good pull requests:
|
||||
# The small print
|
||||
Contributions made by corporations are covered by a different agreement than
|
||||
the one above, the Software Grant and Corporate Contributor License Agreement.
|
||||
|
||||
# Code
|
||||
|
||||
TL/DR
|
||||
|
||||
See [how to build flatc](https://flatbuffers.dev/building/).
|
||||
|
||||
When making changes, build `flatc` and then re-generate the goldens files to see the effect of your changes:
|
||||
|
||||
```
|
||||
$ cp build/flatc .
|
||||
$ goldens/generate_goldens.py
|
||||
```
|
||||
|
||||
Re-generate other code files to see the effects of the changes:
|
||||
|
||||
```
|
||||
$ scripts/generate_code.py
|
||||
```
|
||||
|
||||
Run tests with [TestAll.sh](tests/TestAll.sh) in [tests](tests), or directly any of the sub-scripts run by it.
|
||||
|
||||
[Format the code](Formatters.md) before submitting a PR.
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
Pod::Spec.new do |s|
|
||||
s.name = 'FlatBuffers'
|
||||
s.version = '23.5.26'
|
||||
s.version = '25.12.19'
|
||||
s.summary = 'FlatBuffers: Memory Efficient Serialization Library'
|
||||
|
||||
s.description = "FlatBuffers is a cross platform serialization library architected for
|
||||
@@ -10,12 +10,15 @@ Pod::Spec.new do |s|
|
||||
|
||||
s.homepage = 'https://github.com/google/flatbuffers'
|
||||
s.license = { :type => 'Apache2.0', :file => 'LICENSE' }
|
||||
s.author = { 'mustii' => 'mustii@mmk.one' }
|
||||
s.source = { :git => 'https://github.com/google/flatbuffers.git', :tag => s.version.to_s, :submodules => true }
|
||||
s.author = { 'mustii' => 'me@mustiikhalil.se' }
|
||||
s.source = { :git => 'https://github.com/google/flatbuffers.git', :tag => "v" + s.version.to_s, :submodules => true }
|
||||
|
||||
s.ios.deployment_target = '11.0'
|
||||
s.osx.deployment_target = '10.14'
|
||||
|
||||
s.swift_version = '5.0'
|
||||
s.swift_version = '5.10'
|
||||
s.source_files = 'swift/Sources/Flatbuffers/*.swift'
|
||||
s.pod_target_xcconfig = {
|
||||
'BUILD_LIBRARY_FOR_DISTRIBUTION' => 'YES'
|
||||
}
|
||||
end
|
||||
|
||||
@@ -19,4 +19,4 @@ Swift uses swiftformat as it's formatter. Take a look at [how to install here](h
|
||||
|
||||
## Typescript
|
||||
|
||||
Typescript uses eslint as it's linter. Take a look at [how to install here](https://eslint.org/docs/user-guide/getting-started). Run the following command `eslint ts/** --ext .ts` in the root directory of the project
|
||||
Typescript uses eslint as it's linter. Take a look at [how to install here](https://eslint.org/docs/user-guide/getting-started). Run the following command `eslint ts/** --ext .ts` in the root directory of the project
|
||||
|
||||
75
MODULE.bazel
Normal file
75
MODULE.bazel
Normal file
@@ -0,0 +1,75 @@
|
||||
module(
|
||||
name = "flatbuffers",
|
||||
version = "25.12.19",
|
||||
compatibility_level = 1,
|
||||
repo_name = "com_github_google_flatbuffers",
|
||||
)
|
||||
|
||||
bazel_dep(
|
||||
name = "aspect_bazel_lib",
|
||||
version = "2.14.0",
|
||||
)
|
||||
bazel_dep(
|
||||
name = "aspect_rules_esbuild",
|
||||
version = "0.21.0",
|
||||
)
|
||||
bazel_dep(
|
||||
name = "aspect_rules_js",
|
||||
version = "2.3.8",
|
||||
)
|
||||
bazel_dep(
|
||||
name = "aspect_rules_ts",
|
||||
version = "3.6.0",
|
||||
)
|
||||
bazel_dep(
|
||||
name = "grpc",
|
||||
version = "1.76.0",
|
||||
repo_name = "com_github_grpc_grpc",
|
||||
)
|
||||
bazel_dep(
|
||||
name = "platforms",
|
||||
version = "0.0.11",
|
||||
)
|
||||
bazel_dep(
|
||||
name = "rules_cc",
|
||||
version = "0.1.1",
|
||||
)
|
||||
bazel_dep(
|
||||
name = "rules_go",
|
||||
version = "0.50.1",
|
||||
repo_name = "io_bazel_rules_go",
|
||||
)
|
||||
bazel_dep(
|
||||
name = "rules_nodejs",
|
||||
version = "6.3.3",
|
||||
)
|
||||
bazel_dep(
|
||||
name = "rules_shell",
|
||||
version = "0.3.0",
|
||||
)
|
||||
bazel_dep(
|
||||
name = "rules_swift",
|
||||
version = "3.1.2",
|
||||
max_compatibility_level = 3,
|
||||
repo_name = "build_bazel_rules_swift",
|
||||
)
|
||||
bazel_dep(
|
||||
name = "bazel_skylib",
|
||||
version = "1.7.1",
|
||||
)
|
||||
|
||||
npm = use_extension("@aspect_rules_js//npm:extensions.bzl", "npm")
|
||||
npm.npm_translate_lock(
|
||||
name = "flatbuffers_npm",
|
||||
npmrc = "//:.npmrc",
|
||||
pnpm_lock = "//ts:pnpm-lock.yaml",
|
||||
verify_node_modules_ignored = "//:.bazelignore",
|
||||
)
|
||||
use_repo(npm, "flatbuffers_npm")
|
||||
|
||||
node = use_extension("@rules_nodejs//nodejs:extensions.bzl", "node")
|
||||
use_repo(node, "nodejs_linux_amd64")
|
||||
|
||||
rules_ts_ext = use_extension("@aspect_rules_ts//ts:extensions.bzl", "ext", dev_dependency = True)
|
||||
rules_ts_ext.deps()
|
||||
use_repo(rules_ts_ext, "npm_typescript")
|
||||
@@ -1,4 +1,4 @@
|
||||
// swift-tools-version:5.2
|
||||
// swift-tools-version:6.0
|
||||
/*
|
||||
* Copyright 2020 Google Inc. All rights reserved.
|
||||
*
|
||||
@@ -20,18 +20,79 @@ import PackageDescription
|
||||
let package = Package(
|
||||
name: "FlatBuffers",
|
||||
platforms: [
|
||||
.iOS(.v11),
|
||||
.iOS(.v12),
|
||||
.macOS(.v10_14),
|
||||
],
|
||||
products: [
|
||||
.library(
|
||||
name: "FlatBuffers",
|
||||
targets: ["FlatBuffers"]),
|
||||
.library(
|
||||
name: "FlexBuffers",
|
||||
targets: ["FlexBuffers"]),
|
||||
],
|
||||
dependencies: .dependencies,
|
||||
targets: [
|
||||
.target(
|
||||
name: "FlatBuffers",
|
||||
dependencies: [],
|
||||
path: "swift/Sources",
|
||||
exclude: ["Documentation.docc/Resources/code/swift"]),
|
||||
])
|
||||
dependencies: ["Common"],
|
||||
path: "swift/Sources/FlatBuffers",
|
||||
swiftSettings: .settings),
|
||||
.target(
|
||||
name: "FlexBuffers",
|
||||
dependencies: ["Common"],
|
||||
path: "swift/Sources/FlexBuffers",
|
||||
swiftSettings: .settings),
|
||||
.target(
|
||||
name: "Common",
|
||||
path: "swift/Sources/Common",
|
||||
swiftSettings: .settings),
|
||||
.testTarget(
|
||||
name: "FlatbuffersTests",
|
||||
dependencies: .dependencies,
|
||||
path: "tests/swift/Tests/Flatbuffers"),
|
||||
.testTarget(
|
||||
name: "FlexbuffersTests",
|
||||
dependencies: ["FlexBuffers"],
|
||||
path: "tests/swift/Tests/Flexbuffers"),
|
||||
],
|
||||
swiftLanguageModes: [.v6])
|
||||
|
||||
extension Array where Element == SwiftSetting {
|
||||
static var settings: [SwiftSetting] {
|
||||
[.enableUpcomingFeature("ExistentialAny")]
|
||||
}
|
||||
}
|
||||
|
||||
extension Array where Element == Package.Dependency {
|
||||
static var dependencies: [Package.Dependency] {
|
||||
#if os(Windows)
|
||||
[]
|
||||
#else
|
||||
// Test only Dependency
|
||||
[
|
||||
.package(url: "https://github.com/grpc/grpc-swift-2.git", from: "2.0.0"),
|
||||
.package(
|
||||
url: "https://github.com/grpc/grpc-swift-nio-transport.git",
|
||||
from: "2.0.0"),
|
||||
]
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
extension Array where Element == PackageDescription.Target.Dependency {
|
||||
static var dependencies: [PackageDescription.Target.Dependency] {
|
||||
#if os(Windows)
|
||||
["FlatBuffers"]
|
||||
#else
|
||||
// Test only Dependency
|
||||
[
|
||||
.product(name: "GRPCCore", package: "grpc-swift-2"),
|
||||
.product(
|
||||
name: "GRPCNIOTransportHTTP2",
|
||||
package: "grpc-swift-nio-transport"),
|
||||
"FlatBuffers",
|
||||
]
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
13
README.md
13
README.md
@@ -1,11 +1,9 @@
|
||||
 FlatBuffers
|
||||
 FlatBuffers
|
||||
===========
|
||||
|
||||

|
||||
[](https://buildkite.com/bazel/flatbuffers)
|
||||
[](https://bugs.chromium.org/p/oss-fuzz/issues/list?sort=-opened&can=1&q=proj:flatbuffers)
|
||||
[](https://api.securityscorecards.dev/projects/github.com/google/flatbuffers)
|
||||
[](https://gitter.im/google/flatbuffers?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
|
||||
[](https:///discord.gg/6qgKs3R)
|
||||
[](https://twitter.com/wvo)
|
||||
[](https://twitter.com/dbaileychess)
|
||||
@@ -18,7 +16,7 @@ maximum memory efficiency. It allows you to directly access serialized data with
|
||||
|
||||
1. Build the compiler for flatbuffers (`flatc`)
|
||||
|
||||
Use `cmake` to create the build files for your platform and then perform the compliation (Linux example).
|
||||
Use `cmake` to create the build files for your platform and then perform the compilation (Linux example).
|
||||
|
||||
```
|
||||
cmake -G "Unix Makefiles"
|
||||
@@ -36,7 +34,7 @@ maximum memory efficiency. It allows you to directly access serialized data with
|
||||
```
|
||||
./flatc --cpp --rust monster.fbs
|
||||
```
|
||||
|
||||
|
||||
Which generates `monster_generated.h` and `monster_generated.rs` files.
|
||||
|
||||
4. Serialize data
|
||||
@@ -50,7 +48,7 @@ maximum memory efficiency. It allows you to directly access serialized data with
|
||||
6. Read the data
|
||||
|
||||
Use the generated accessors to read the data from the serialized buffer.
|
||||
|
||||
|
||||
It doesn't need to be the same language/schema version, FlatBuffers ensures the data is readable across languages and schema versions. See the [`Rust` example](https://github.com/google/flatbuffers/blob/master/samples/sample_binary.rs#L92-L106) reading the data written by `C++`.
|
||||
|
||||
## Documentation
|
||||
@@ -98,10 +96,7 @@ FlatBuffers does not follow traditional SemVer versioning (see [rationale](https
|
||||
|
||||
## Community
|
||||
|
||||
* [FlatBuffers Google Group][] to discuss FlatBuffers with other developers and users.
|
||||
* [Discord Server](https:///discord.gg/6qgKs3R)
|
||||
* [Gitter](https://gitter.im/google/flatbuffers)
|
||||
|
||||
|
||||
## Security
|
||||
|
||||
|
||||
156
WORKSPACE
156
WORKSPACE
@@ -1,156 +0,0 @@
|
||||
workspace(name = "com_github_google_flatbuffers")
|
||||
|
||||
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive", "http_file")
|
||||
|
||||
http_archive(
|
||||
name = "platforms",
|
||||
sha256 = "379113459b0feaf6bfbb584a91874c065078aa673222846ac765f86661c27407",
|
||||
urls = [
|
||||
"https://mirror.bazel.build/github.com/bazelbuild/platforms/releases/download/0.0.5/platforms-0.0.5.tar.gz",
|
||||
"https://github.com/bazelbuild/platforms/releases/download/0.0.5/platforms-0.0.5.tar.gz",
|
||||
],
|
||||
)
|
||||
|
||||
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 = "ae013bf35bd23234d1dea46b079f1e05ba74ac0321423830119d3e787ec73483",
|
||||
urls = [
|
||||
"https://mirror.bazel.build/github.com/bazelbuild/rules_go/releases/download/v0.36.0/rules_go-v0.36.0.zip",
|
||||
"https://github.com/bazelbuild/rules_go/releases/download/v0.36.0/rules_go-v0.36.0.zip",
|
||||
],
|
||||
)
|
||||
|
||||
load("@io_bazel_rules_go//go:deps.bzl", "go_rules_dependencies")
|
||||
|
||||
go_rules_dependencies()
|
||||
|
||||
##### Protobuf
|
||||
_PROTOBUF_VERSION = "3.15.2"
|
||||
|
||||
http_archive(
|
||||
name = "com_google_protobuf",
|
||||
strip_prefix = "protobuf-" + _PROTOBUF_VERSION,
|
||||
urls = [
|
||||
"https://github.com/protocolbuffers/protobuf/archive/v" + _PROTOBUF_VERSION + ".tar.gz",
|
||||
],
|
||||
)
|
||||
|
||||
##### GRPC
|
||||
_GRPC_VERSION = "1.49.0" # https://github.com/grpc/grpc/releases/tag/v1.48.0
|
||||
|
||||
http_archive(
|
||||
name = "com_github_grpc_grpc",
|
||||
patch_args = ["-p1"],
|
||||
patches = ["//grpc:build_grpc_with_cxx14.patch"],
|
||||
sha256 = "15715e1847cc9e42014f02c727dbcb48e39dbdb90f79ad3d66fe4361709ff935",
|
||||
strip_prefix = "grpc-" + _GRPC_VERSION,
|
||||
urls = ["https://github.com/grpc/grpc/archive/refs/tags/v" + _GRPC_VERSION + ".tar.gz"],
|
||||
)
|
||||
|
||||
load("@com_github_grpc_grpc//bazel:grpc_deps.bzl", "grpc_deps")
|
||||
|
||||
grpc_deps()
|
||||
|
||||
load("@com_github_grpc_grpc//bazel:grpc_extra_deps.bzl", "grpc_extra_deps")
|
||||
|
||||
grpc_extra_deps()
|
||||
|
||||
# rules_go from https://github.com/bazelbuild/rules_go/releases/tag/v0.34.0
|
||||
|
||||
http_archive(
|
||||
name = "aspect_rules_js",
|
||||
sha256 = "124ed29fb0b3d0cba5b44f8f8e07897cf61b34e35e33b1f83d1a943dfd91b193",
|
||||
strip_prefix = "rules_js-1.24.0",
|
||||
url = "https://github.com/aspect-build/rules_js/releases/download/v1.24.0/rules_js-v1.24.0.tar.gz",
|
||||
)
|
||||
|
||||
load("@aspect_rules_js//js:repositories.bzl", "rules_js_dependencies")
|
||||
|
||||
rules_js_dependencies()
|
||||
|
||||
load("@aspect_rules_js//npm:npm_import.bzl", "npm_translate_lock", "pnpm_repository")
|
||||
|
||||
pnpm_repository(name = "pnpm")
|
||||
|
||||
http_archive(
|
||||
name = "aspect_rules_ts",
|
||||
sha256 = "8eb25d1fdafc0836f5778d33fb8eaac37c64176481d67872b54b0a05de5be5c0",
|
||||
strip_prefix = "rules_ts-1.3.3",
|
||||
url = "https://github.com/aspect-build/rules_ts/releases/download/v1.3.3/rules_ts-v1.3.3.tar.gz",
|
||||
)
|
||||
|
||||
load("@aspect_rules_ts//ts:repositories.bzl", "rules_ts_dependencies")
|
||||
|
||||
rules_ts_dependencies(
|
||||
# Since rules_ts doesn't always have the newest integrity hashes, we
|
||||
# compute it manually here.
|
||||
# $ curl --silent https://registry.npmjs.org/typescript/5.0.4 | jq ._integrity
|
||||
ts_integrity = "sha512-cW9T5W9xY37cc+jfEnaUvX91foxtHkza3Nw3wkoF4sSlKn0MONdkdEndig/qPBWXNkmplh3NzayQzCiHM4/hqw==",
|
||||
ts_version_from = "//:package.json",
|
||||
)
|
||||
|
||||
load("@rules_nodejs//nodejs:repositories.bzl", "DEFAULT_NODE_VERSION", "nodejs_register_toolchains")
|
||||
|
||||
nodejs_register_toolchains(
|
||||
name = "nodejs",
|
||||
node_version = DEFAULT_NODE_VERSION,
|
||||
)
|
||||
|
||||
npm_translate_lock(
|
||||
name = "npm",
|
||||
npmrc = "//:.npmrc",
|
||||
pnpm_lock = "//:pnpm-lock.yaml",
|
||||
# Set this to True when the lock file needs to be updated, commit the
|
||||
# changes, then set to False again.
|
||||
update_pnpm_lock = False,
|
||||
verify_node_modules_ignored = "//:.bazelignore",
|
||||
)
|
||||
|
||||
load("@npm//:repositories.bzl", "npm_repositories")
|
||||
|
||||
npm_repositories()
|
||||
|
||||
http_archive(
|
||||
name = "aspect_rules_esbuild",
|
||||
sha256 = "2ea31bd97181a315e048be693ddc2815fddda0f3a12ca7b7cc6e91e80f31bac7",
|
||||
strip_prefix = "rules_esbuild-0.14.4",
|
||||
url = "https://github.com/aspect-build/rules_esbuild/releases/download/v0.14.4/rules_esbuild-v0.14.4.tar.gz",
|
||||
)
|
||||
|
||||
# Register a toolchain containing esbuild npm package and native bindings
|
||||
load("@aspect_rules_esbuild//esbuild:repositories.bzl", "LATEST_VERSION", "esbuild_register_toolchains")
|
||||
|
||||
esbuild_register_toolchains(
|
||||
name = "esbuild",
|
||||
esbuild_version = LATEST_VERSION,
|
||||
)
|
||||
|
||||
http_file(
|
||||
name = "bazel_linux_x86_64",
|
||||
downloaded_file_path = "bazel",
|
||||
executable = True,
|
||||
sha256 = "e89747d63443e225b140d7d37ded952dacea73aaed896bca01ccd745827c6289",
|
||||
urls = [
|
||||
"https://github.com/bazelbuild/bazel/releases/download/6.1.2/bazel-6.1.2-linux-x86_64",
|
||||
],
|
||||
)
|
||||
@@ -10,7 +10,7 @@
|
||||
</natures>
|
||||
<filteredResources>
|
||||
<filter>
|
||||
<id>1677235311958</id>
|
||||
<id>1672434305228</id>
|
||||
<name></name>
|
||||
<type>30</type>
|
||||
<matcher>
|
||||
|
||||
21
android/app/proguard-rules.pro
vendored
21
android/app/proguard-rules.pro
vendored
@@ -1,21 +0,0 @@
|
||||
# Add project specific ProGuard rules here.
|
||||
# You can control the set of applied configuration files using the
|
||||
# proguardFiles setting in build.gradle.
|
||||
#
|
||||
# For more details, see
|
||||
# http://developer.android.com/guide/developing/tools/proguard.html
|
||||
|
||||
# If your project uses WebView with JS, uncomment the following
|
||||
# and specify the fully qualified class name to the JavaScript interface
|
||||
# class:
|
||||
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
|
||||
# public *;
|
||||
#}
|
||||
|
||||
# Uncomment this to preserve the line number information for
|
||||
# debugging stack traces.
|
||||
#-keepattributes SourceFile,LineNumberTable
|
||||
|
||||
# If you keep the line number information, uncomment this to
|
||||
# hide the original source file name.
|
||||
#-renamesourcefileattribute SourceFile
|
||||
@@ -15,25 +15,27 @@
|
||||
*/
|
||||
|
||||
#include <jni.h>
|
||||
#include <string>
|
||||
#include <search.h>
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "generated/animal_generated.h"
|
||||
|
||||
using namespace com::fbs::app;
|
||||
using namespace flatbuffers;
|
||||
|
||||
extern "C" JNIEXPORT jbyteArray JNICALL Java_com_flatbuffers_app_MainActivity_createAnimalFromJNI(
|
||||
JNIEnv* env,
|
||||
jobject /* this */) {
|
||||
// create a new animal flatbuffers
|
||||
auto fb = FlatBufferBuilder(1024);
|
||||
auto tiger = CreateAnimalDirect(fb, "Tiger", "Roar", 300);
|
||||
fb.Finish(tiger);
|
||||
extern "C" JNIEXPORT jbyteArray JNICALL
|
||||
Java_com_flatbuffers_app_MainActivity_createAnimalFromJNI(JNIEnv* env,
|
||||
jobject /* this */) {
|
||||
// create a new animal flatbuffers
|
||||
auto fb = FlatBufferBuilder(1024);
|
||||
auto tiger = CreateAnimalDirect(fb, "Tiger", "Roar", 300);
|
||||
fb.Finish(tiger);
|
||||
|
||||
// copies it to a Java byte array.
|
||||
auto buf = reinterpret_cast<jbyte*>(fb.GetBufferPointer());
|
||||
int size = fb.GetSize();
|
||||
auto ret = env->NewByteArray(size);
|
||||
env->SetByteArrayRegion (ret, 0, fb.GetSize(), buf);
|
||||
// copies it to a Java byte array.
|
||||
auto buf = reinterpret_cast<jbyte*>(fb.GetBufferPointer());
|
||||
int size = fb.GetSize();
|
||||
auto ret = env->NewByteArray(size);
|
||||
env->SetByteArrayRegion(ret, 0, fb.GetSize(), buf);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
// automatically generated by the FlatBuffers compiler, do not modify
|
||||
|
||||
|
||||
#ifndef FLATBUFFERS_GENERATED_ANIMAL_COM_FBS_APP_H_
|
||||
#define FLATBUFFERS_GENERATED_ANIMAL_COM_FBS_APP_H_
|
||||
|
||||
@@ -8,10 +7,10 @@
|
||||
|
||||
// Ensure the included flatbuffers.h is the same version as when this file was
|
||||
// generated, otherwise it may not be compatible.
|
||||
static_assert(FLATBUFFERS_VERSION_MAJOR == 23 &&
|
||||
FLATBUFFERS_VERSION_MINOR == 1 &&
|
||||
FLATBUFFERS_VERSION_REVISION == 21,
|
||||
"Non-compatible flatbuffers version included");
|
||||
static_assert(FLATBUFFERS_VERSION_MAJOR == 24 &&
|
||||
FLATBUFFERS_VERSION_MINOR == 12 &&
|
||||
FLATBUFFERS_VERSION_REVISION == 23,
|
||||
"Non-compatible flatbuffers version included");
|
||||
|
||||
namespace com {
|
||||
namespace fbs {
|
||||
@@ -27,29 +26,24 @@ struct Animal FLATBUFFERS_FINAL_CLASS : private ::flatbuffers::Table {
|
||||
VT_SOUND = 6,
|
||||
VT_WEIGHT = 8
|
||||
};
|
||||
const ::flatbuffers::String *name() const {
|
||||
return GetPointer<const ::flatbuffers::String *>(VT_NAME);
|
||||
const ::flatbuffers::String* name() const {
|
||||
return GetPointer<const ::flatbuffers::String*>(VT_NAME);
|
||||
}
|
||||
const ::flatbuffers::String *sound() const {
|
||||
return GetPointer<const ::flatbuffers::String *>(VT_SOUND);
|
||||
const ::flatbuffers::String* sound() const {
|
||||
return GetPointer<const ::flatbuffers::String*>(VT_SOUND);
|
||||
}
|
||||
uint16_t weight() const {
|
||||
return GetField<uint16_t>(VT_WEIGHT, 0);
|
||||
}
|
||||
bool Verify(::flatbuffers::Verifier &verifier) const {
|
||||
return VerifyTableStart(verifier) &&
|
||||
VerifyOffset(verifier, VT_NAME) &&
|
||||
verifier.VerifyString(name()) &&
|
||||
VerifyOffset(verifier, VT_SOUND) &&
|
||||
uint16_t weight() const { return GetField<uint16_t>(VT_WEIGHT, 0); }
|
||||
bool Verify(::flatbuffers::Verifier& verifier) const {
|
||||
return VerifyTableStart(verifier) && VerifyOffset(verifier, VT_NAME) &&
|
||||
verifier.VerifyString(name()) && VerifyOffset(verifier, VT_SOUND) &&
|
||||
verifier.VerifyString(sound()) &&
|
||||
VerifyField<uint16_t>(verifier, VT_WEIGHT, 2) &&
|
||||
verifier.EndTable();
|
||||
VerifyField<uint16_t>(verifier, VT_WEIGHT, 2) && verifier.EndTable();
|
||||
}
|
||||
};
|
||||
|
||||
struct AnimalBuilder {
|
||||
typedef Animal Table;
|
||||
::flatbuffers::FlatBufferBuilder &fbb_;
|
||||
::flatbuffers::FlatBufferBuilder& fbb_;
|
||||
::flatbuffers::uoffset_t start_;
|
||||
void add_name(::flatbuffers::Offset<::flatbuffers::String> name) {
|
||||
fbb_.AddOffset(Animal::VT_NAME, name);
|
||||
@@ -60,8 +54,7 @@ struct AnimalBuilder {
|
||||
void add_weight(uint16_t weight) {
|
||||
fbb_.AddElement<uint16_t>(Animal::VT_WEIGHT, weight, 0);
|
||||
}
|
||||
explicit AnimalBuilder(::flatbuffers::FlatBufferBuilder &_fbb)
|
||||
: fbb_(_fbb) {
|
||||
explicit AnimalBuilder(::flatbuffers::FlatBufferBuilder& _fbb) : fbb_(_fbb) {
|
||||
start_ = fbb_.StartTable();
|
||||
}
|
||||
::flatbuffers::Offset<Animal> Finish() {
|
||||
@@ -72,7 +65,7 @@ struct AnimalBuilder {
|
||||
};
|
||||
|
||||
inline ::flatbuffers::Offset<Animal> CreateAnimal(
|
||||
::flatbuffers::FlatBufferBuilder &_fbb,
|
||||
::flatbuffers::FlatBufferBuilder& _fbb,
|
||||
::flatbuffers::Offset<::flatbuffers::String> name = 0,
|
||||
::flatbuffers::Offset<::flatbuffers::String> sound = 0,
|
||||
uint16_t weight = 0) {
|
||||
@@ -84,45 +77,37 @@ inline ::flatbuffers::Offset<Animal> CreateAnimal(
|
||||
}
|
||||
|
||||
inline ::flatbuffers::Offset<Animal> CreateAnimalDirect(
|
||||
::flatbuffers::FlatBufferBuilder &_fbb,
|
||||
const char *name = nullptr,
|
||||
const char *sound = nullptr,
|
||||
uint16_t weight = 0) {
|
||||
::flatbuffers::FlatBufferBuilder& _fbb, const char* name = nullptr,
|
||||
const char* sound = nullptr, uint16_t weight = 0) {
|
||||
auto name__ = name ? _fbb.CreateString(name) : 0;
|
||||
auto sound__ = sound ? _fbb.CreateString(sound) : 0;
|
||||
return com::fbs::app::CreateAnimal(
|
||||
_fbb,
|
||||
name__,
|
||||
sound__,
|
||||
weight);
|
||||
return com::fbs::app::CreateAnimal(_fbb, name__, sound__, weight);
|
||||
}
|
||||
|
||||
inline const com::fbs::app::Animal *GetAnimal(const void *buf) {
|
||||
inline const com::fbs::app::Animal* GetAnimal(const void* buf) {
|
||||
return ::flatbuffers::GetRoot<com::fbs::app::Animal>(buf);
|
||||
}
|
||||
|
||||
inline const com::fbs::app::Animal *GetSizePrefixedAnimal(const void *buf) {
|
||||
inline const com::fbs::app::Animal* GetSizePrefixedAnimal(const void* buf) {
|
||||
return ::flatbuffers::GetSizePrefixedRoot<com::fbs::app::Animal>(buf);
|
||||
}
|
||||
|
||||
inline bool VerifyAnimalBuffer(
|
||||
::flatbuffers::Verifier &verifier) {
|
||||
inline bool VerifyAnimalBuffer(::flatbuffers::Verifier& verifier) {
|
||||
return verifier.VerifyBuffer<com::fbs::app::Animal>(nullptr);
|
||||
}
|
||||
|
||||
inline bool VerifySizePrefixedAnimalBuffer(
|
||||
::flatbuffers::Verifier &verifier) {
|
||||
inline bool VerifySizePrefixedAnimalBuffer(::flatbuffers::Verifier& verifier) {
|
||||
return verifier.VerifySizePrefixedBuffer<com::fbs::app::Animal>(nullptr);
|
||||
}
|
||||
|
||||
inline void FinishAnimalBuffer(
|
||||
::flatbuffers::FlatBufferBuilder &fbb,
|
||||
::flatbuffers::FlatBufferBuilder& fbb,
|
||||
::flatbuffers::Offset<com::fbs::app::Animal> root) {
|
||||
fbb.Finish(root);
|
||||
}
|
||||
|
||||
inline void FinishSizePrefixedAnimalBuffer(
|
||||
::flatbuffers::FlatBufferBuilder &fbb,
|
||||
::flatbuffers::FlatBufferBuilder& fbb,
|
||||
::flatbuffers::Offset<com::fbs::app::Animal> root) {
|
||||
fbb.FinishSizePrefixed(root);
|
||||
}
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
package com.flatbuffers.app
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import android.os.Bundle
|
||||
import android.widget.TextView
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import com.fbs.app.Animal
|
||||
import com.google.flatbuffers.FlatBufferBuilder
|
||||
import java.nio.ByteBuffer
|
||||
@@ -27,14 +27,15 @@ class MainActivity : AppCompatActivity() {
|
||||
private external fun createAnimalFromJNI(): ByteArray
|
||||
|
||||
// Create a "Cow" Animal flatbuffers from Kotlin
|
||||
private fun createAnimalFromKotlin():Animal {
|
||||
private fun createAnimalFromKotlin(): Animal {
|
||||
val fb = FlatBufferBuilder(100)
|
||||
val cowOffset = Animal.createAnimal(
|
||||
builder = fb,
|
||||
nameOffset = fb.createString("Cow"),
|
||||
soundOffset = fb.createString("Moo"),
|
||||
weight = 720u
|
||||
)
|
||||
val cowOffset =
|
||||
Animal.createAnimal(
|
||||
builder = fb,
|
||||
nameOffset = fb.createString("Cow"),
|
||||
soundOffset = fb.createString("Moo"),
|
||||
weight = 720u,
|
||||
)
|
||||
fb.finish(cowOffset)
|
||||
return Animal.getRootAsAnimal(fb.dataBuffer())
|
||||
}
|
||||
|
||||
@@ -2,83 +2,101 @@
|
||||
|
||||
package com.fbs.app
|
||||
|
||||
import com.google.flatbuffers.BaseVector
|
||||
import com.google.flatbuffers.BooleanVector
|
||||
import com.google.flatbuffers.ByteVector
|
||||
import com.google.flatbuffers.Constants
|
||||
import com.google.flatbuffers.DoubleVector
|
||||
import com.google.flatbuffers.FlatBufferBuilder
|
||||
import com.google.flatbuffers.FloatVector
|
||||
import com.google.flatbuffers.LongVector
|
||||
import com.google.flatbuffers.StringVector
|
||||
import com.google.flatbuffers.Struct
|
||||
import com.google.flatbuffers.Table
|
||||
import com.google.flatbuffers.UnionVector
|
||||
import java.nio.ByteBuffer
|
||||
import java.nio.ByteOrder
|
||||
import kotlin.math.sign
|
||||
|
||||
@Suppress("unused")
|
||||
@kotlin.ExperimentalUnsignedTypes
|
||||
class Animal : Table() {
|
||||
|
||||
fun __init(_i: Int, _bb: ByteBuffer) {
|
||||
__reset(_i, _bb)
|
||||
fun __init(_i: Int, _bb: ByteBuffer) {
|
||||
__reset(_i, _bb)
|
||||
}
|
||||
|
||||
fun __assign(_i: Int, _bb: ByteBuffer): Animal {
|
||||
__init(_i, _bb)
|
||||
return this
|
||||
}
|
||||
|
||||
val name: String?
|
||||
get() {
|
||||
val o = __offset(4)
|
||||
return if (o != 0) {
|
||||
__string(o + bb_pos)
|
||||
} else {
|
||||
null
|
||||
}
|
||||
}
|
||||
fun __assign(_i: Int, _bb: ByteBuffer) : Animal {
|
||||
__init(_i, _bb)
|
||||
return this
|
||||
|
||||
val nameAsByteBuffer: ByteBuffer
|
||||
get() = __vector_as_bytebuffer(4, 1)
|
||||
|
||||
fun nameInByteBuffer(_bb: ByteBuffer): ByteBuffer = __vector_in_bytebuffer(_bb, 4, 1)
|
||||
|
||||
val sound: String?
|
||||
get() {
|
||||
val o = __offset(6)
|
||||
return if (o != 0) {
|
||||
__string(o + bb_pos)
|
||||
} else {
|
||||
null
|
||||
}
|
||||
}
|
||||
val name : String?
|
||||
get() {
|
||||
val o = __offset(4)
|
||||
return if (o != 0) {
|
||||
__string(o + bb_pos)
|
||||
} else {
|
||||
null
|
||||
}
|
||||
}
|
||||
val nameAsByteBuffer : ByteBuffer get() = __vector_as_bytebuffer(4, 1)
|
||||
fun nameInByteBuffer(_bb: ByteBuffer) : ByteBuffer = __vector_in_bytebuffer(_bb, 4, 1)
|
||||
val sound : String?
|
||||
get() {
|
||||
val o = __offset(6)
|
||||
return if (o != 0) {
|
||||
__string(o + bb_pos)
|
||||
} else {
|
||||
null
|
||||
}
|
||||
}
|
||||
val soundAsByteBuffer : ByteBuffer get() = __vector_as_bytebuffer(6, 1)
|
||||
fun soundInByteBuffer(_bb: ByteBuffer) : ByteBuffer = __vector_in_bytebuffer(_bb, 6, 1)
|
||||
val weight : UShort
|
||||
get() {
|
||||
val o = __offset(8)
|
||||
return if(o != 0) bb.getShort(o + bb_pos).toUShort() else 0u
|
||||
}
|
||||
companion object {
|
||||
fun validateVersion() = Constants.FLATBUFFERS_23_5_26()
|
||||
fun getRootAsAnimal(_bb: ByteBuffer): Animal = getRootAsAnimal(_bb, Animal())
|
||||
fun getRootAsAnimal(_bb: ByteBuffer, obj: Animal): Animal {
|
||||
_bb.order(ByteOrder.LITTLE_ENDIAN)
|
||||
return (obj.__assign(_bb.getInt(_bb.position()) + _bb.position(), _bb))
|
||||
}
|
||||
fun createAnimal(builder: FlatBufferBuilder, nameOffset: Int, soundOffset: Int, weight: UShort) : Int {
|
||||
builder.startTable(3)
|
||||
addSound(builder, soundOffset)
|
||||
addName(builder, nameOffset)
|
||||
addWeight(builder, weight)
|
||||
return endAnimal(builder)
|
||||
}
|
||||
fun startAnimal(builder: FlatBufferBuilder) = builder.startTable(3)
|
||||
fun addName(builder: FlatBufferBuilder, name: Int) = builder.addOffset(0, name, 0)
|
||||
fun addSound(builder: FlatBufferBuilder, sound: Int) = builder.addOffset(1, sound, 0)
|
||||
fun addWeight(builder: FlatBufferBuilder, weight: UShort) = builder.addShort(2, weight.toShort(), 0)
|
||||
fun endAnimal(builder: FlatBufferBuilder) : Int {
|
||||
val o = builder.endTable()
|
||||
return o
|
||||
}
|
||||
fun finishAnimalBuffer(builder: FlatBufferBuilder, offset: Int) = builder.finish(offset)
|
||||
fun finishSizePrefixedAnimalBuffer(builder: FlatBufferBuilder, offset: Int) = builder.finishSizePrefixed(offset)
|
||||
|
||||
val soundAsByteBuffer: ByteBuffer
|
||||
get() = __vector_as_bytebuffer(6, 1)
|
||||
|
||||
fun soundInByteBuffer(_bb: ByteBuffer): ByteBuffer = __vector_in_bytebuffer(_bb, 6, 1)
|
||||
|
||||
val weight: UShort
|
||||
get() {
|
||||
val o = __offset(8)
|
||||
return if (o != 0) bb.getShort(o + bb_pos).toUShort() else 0u
|
||||
}
|
||||
|
||||
companion object {
|
||||
fun validateVersion() = Constants.FLATBUFFERS_25_12_19()
|
||||
|
||||
fun getRootAsAnimal(_bb: ByteBuffer): Animal = getRootAsAnimal(_bb, Animal())
|
||||
|
||||
fun getRootAsAnimal(_bb: ByteBuffer, obj: Animal): Animal {
|
||||
_bb.order(ByteOrder.LITTLE_ENDIAN)
|
||||
return (obj.__assign(_bb.getInt(_bb.position()) + _bb.position(), _bb))
|
||||
}
|
||||
|
||||
fun createAnimal(
|
||||
builder: FlatBufferBuilder,
|
||||
nameOffset: Int,
|
||||
soundOffset: Int,
|
||||
weight: UShort,
|
||||
): Int {
|
||||
builder.startTable(3)
|
||||
addSound(builder, soundOffset)
|
||||
addName(builder, nameOffset)
|
||||
addWeight(builder, weight)
|
||||
return endAnimal(builder)
|
||||
}
|
||||
|
||||
fun startAnimal(builder: FlatBufferBuilder) = builder.startTable(3)
|
||||
|
||||
fun addName(builder: FlatBufferBuilder, name: Int) = builder.addOffset(0, name, 0)
|
||||
|
||||
fun addSound(builder: FlatBufferBuilder, sound: Int) = builder.addOffset(1, sound, 0)
|
||||
|
||||
fun addWeight(builder: FlatBufferBuilder, weight: UShort) =
|
||||
builder.addShort(2, weight.toShort(), 0)
|
||||
|
||||
fun endAnimal(builder: FlatBufferBuilder): Int {
|
||||
val o = builder.endTable()
|
||||
return o
|
||||
}
|
||||
|
||||
fun finishAnimalBuffer(builder: FlatBufferBuilder, offset: Int) = builder.finish(offset)
|
||||
|
||||
fun finishSizePrefixedAnimalBuffer(builder: FlatBufferBuilder, offset: Int) =
|
||||
builder.finishSizePrefixed(offset)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,12 +8,12 @@ struct 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;
|
||||
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_
|
||||
#endif // BENCHMARKS_CPP_BENCH_H_
|
||||
@@ -5,8 +5,8 @@
|
||||
#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) {
|
||||
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);
|
||||
@@ -14,31 +14,33 @@ static inline void Encode(benchmark::State &state,
|
||||
}
|
||||
}
|
||||
|
||||
static inline void Decode(benchmark::State &state,
|
||||
std::unique_ptr<Bench> &bench, uint8_t *buffer) {
|
||||
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);
|
||||
uint8_t* encoded = bench->Encode(buffer, length);
|
||||
|
||||
for (auto _ : state) {
|
||||
void *decoded = bench->Decode(encoded, length);
|
||||
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) {
|
||||
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);
|
||||
uint8_t* encoded = bench->Encode(buffer, length);
|
||||
void* decoded = bench->Decode(encoded, length);
|
||||
|
||||
int64_t sum = 0;
|
||||
|
||||
for (auto _ : state) { sum = bench->Use(decoded); }
|
||||
for (auto _ : state) {
|
||||
sum = bench->Use(decoded);
|
||||
}
|
||||
|
||||
EXPECT_EQ(sum, check_sum);
|
||||
}
|
||||
|
||||
static void BM_Flatbuffers_Encode(benchmark::State &state) {
|
||||
static void BM_Flatbuffers_Encode(benchmark::State& state) {
|
||||
const int64_t kBufferLength = 1024;
|
||||
uint8_t buffer[kBufferLength];
|
||||
|
||||
@@ -48,7 +50,7 @@ static void BM_Flatbuffers_Encode(benchmark::State &state) {
|
||||
}
|
||||
BENCHMARK(BM_Flatbuffers_Encode);
|
||||
|
||||
static void BM_Flatbuffers_Decode(benchmark::State &state) {
|
||||
static void BM_Flatbuffers_Decode(benchmark::State& state) {
|
||||
const int64_t kBufferLength = 1024;
|
||||
uint8_t buffer[kBufferLength];
|
||||
|
||||
@@ -58,7 +60,7 @@ static void BM_Flatbuffers_Decode(benchmark::State &state) {
|
||||
}
|
||||
BENCHMARK(BM_Flatbuffers_Decode);
|
||||
|
||||
static void BM_Flatbuffers_Use(benchmark::State &state) {
|
||||
static void BM_Flatbuffers_Use(benchmark::State& state) {
|
||||
const int64_t kBufferLength = 1024;
|
||||
uint8_t buffer[kBufferLength];
|
||||
|
||||
@@ -68,7 +70,7 @@ static void BM_Flatbuffers_Use(benchmark::State &state) {
|
||||
}
|
||||
BENCHMARK(BM_Flatbuffers_Use);
|
||||
|
||||
static void BM_Raw_Encode(benchmark::State &state) {
|
||||
static void BM_Raw_Encode(benchmark::State& state) {
|
||||
const int64_t kBufferLength = 1024;
|
||||
uint8_t buffer[kBufferLength];
|
||||
|
||||
@@ -77,7 +79,7 @@ static void BM_Raw_Encode(benchmark::State &state) {
|
||||
}
|
||||
BENCHMARK(BM_Raw_Encode);
|
||||
|
||||
static void BM_Raw_Decode(benchmark::State &state) {
|
||||
static void BM_Raw_Decode(benchmark::State& state) {
|
||||
const int64_t kBufferLength = 1024;
|
||||
uint8_t buffer[kBufferLength];
|
||||
|
||||
@@ -86,7 +88,7 @@ static void BM_Raw_Decode(benchmark::State &state) {
|
||||
}
|
||||
BENCHMARK(BM_Raw_Decode);
|
||||
|
||||
static void BM_Raw_Use(benchmark::State &state) {
|
||||
static void BM_Raw_Use(benchmark::State& state) {
|
||||
const int64_t kBufferLength = 1024;
|
||||
uint8_t buffer[kBufferLength];
|
||||
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
// automatically generated by the FlatBuffers compiler, do not modify
|
||||
|
||||
|
||||
#ifndef FLATBUFFERS_GENERATED_BENCH_BENCHMARKS_FLATBUFFERS_H_
|
||||
#define FLATBUFFERS_GENERATED_BENCH_BENCHMARKS_FLATBUFFERS_H_
|
||||
|
||||
@@ -8,10 +7,10 @@
|
||||
|
||||
// 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");
|
||||
static_assert(FLATBUFFERS_VERSION_MAJOR == 24 &&
|
||||
FLATBUFFERS_VERSION_MINOR == 12 &&
|
||||
FLATBUFFERS_VERSION_REVISION == 23,
|
||||
"Non-compatible flatbuffers version included");
|
||||
|
||||
namespace benchmarks_flatbuffers {
|
||||
|
||||
@@ -34,25 +33,16 @@ enum Enum : int16_t {
|
||||
};
|
||||
|
||||
inline const Enum (&EnumValuesEnum())[3] {
|
||||
static const Enum values[] = {
|
||||
Enum_Apples,
|
||||
Enum_Pears,
|
||||
Enum_Bananas
|
||||
};
|
||||
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
|
||||
};
|
||||
inline const char* const* EnumNamesEnum() {
|
||||
static const char* const names[4] = {"Apples", "Pears", "Bananas", nullptr};
|
||||
return names;
|
||||
}
|
||||
|
||||
inline const char *EnumNameEnum(Enum e) {
|
||||
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];
|
||||
@@ -67,12 +57,7 @@ FLATBUFFERS_MANUALLY_ALIGNED_STRUCT(8) Foo FLATBUFFERS_FINAL_CLASS {
|
||||
uint32_t length_;
|
||||
|
||||
public:
|
||||
Foo()
|
||||
: id_(0),
|
||||
count_(0),
|
||||
prefix_(0),
|
||||
padding0__(0),
|
||||
length_(0) {
|
||||
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)
|
||||
@@ -83,18 +68,10 @@ FLATBUFFERS_MANUALLY_ALIGNED_STRUCT(8) Foo FLATBUFFERS_FINAL_CLASS {
|
||||
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_);
|
||||
}
|
||||
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);
|
||||
|
||||
@@ -104,20 +81,17 @@ FLATBUFFERS_MANUALLY_ALIGNED_STRUCT(8) Bar FLATBUFFERS_FINAL_CLASS {
|
||||
int32_t time_;
|
||||
float ratio_;
|
||||
uint16_t size_;
|
||||
int16_t padding0__; int32_t padding1__;
|
||||
int16_t padding0__;
|
||||
int32_t padding1__;
|
||||
|
||||
public:
|
||||
Bar()
|
||||
: parent_(),
|
||||
time_(0),
|
||||
ratio_(0),
|
||||
size_(0),
|
||||
padding0__(0),
|
||||
padding1__(0) {
|
||||
: 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)
|
||||
Bar(const benchmarks_flatbuffers::Foo& _parent, int32_t _time, float _ratio,
|
||||
uint16_t _size)
|
||||
: parent_(_parent),
|
||||
time_(flatbuffers::EndianScalar(_time)),
|
||||
ratio_(flatbuffers::EndianScalar(_ratio)),
|
||||
@@ -127,18 +101,10 @@ FLATBUFFERS_MANUALLY_ALIGNED_STRUCT(8) Bar FLATBUFFERS_FINAL_CLASS {
|
||||
(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_);
|
||||
}
|
||||
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);
|
||||
|
||||
@@ -150,34 +116,28 @@ struct FooBar FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table {
|
||||
VT_RATING = 8,
|
||||
VT_POSTFIX = 10
|
||||
};
|
||||
const benchmarks_flatbuffers::Bar *sibling() const {
|
||||
return GetStruct<const benchmarks_flatbuffers::Bar *>(VT_SIBLING);
|
||||
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);
|
||||
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 {
|
||||
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()) &&
|
||||
VerifyOffset(verifier, VT_NAME) && verifier.VerifyString(name()) &&
|
||||
VerifyField<double>(verifier, VT_RATING, 8) &&
|
||||
VerifyField<uint8_t>(verifier, VT_POSTFIX, 1) &&
|
||||
verifier.EndTable();
|
||||
VerifyField<uint8_t>(verifier, VT_POSTFIX, 1) && verifier.EndTable();
|
||||
}
|
||||
};
|
||||
|
||||
struct FooBarBuilder {
|
||||
typedef FooBar Table;
|
||||
flatbuffers::FlatBufferBuilder &fbb_;
|
||||
flatbuffers::FlatBufferBuilder& fbb_;
|
||||
flatbuffers::uoffset_t start_;
|
||||
void add_sibling(const benchmarks_flatbuffers::Bar *sibling) {
|
||||
void add_sibling(const benchmarks_flatbuffers::Bar* sibling) {
|
||||
fbb_.AddStruct(FooBar::VT_SIBLING, sibling);
|
||||
}
|
||||
void add_name(flatbuffers::Offset<flatbuffers::String> name) {
|
||||
@@ -189,8 +149,7 @@ struct FooBarBuilder {
|
||||
void add_postfix(uint8_t postfix) {
|
||||
fbb_.AddElement<uint8_t>(FooBar::VT_POSTFIX, postfix, 0);
|
||||
}
|
||||
explicit FooBarBuilder(flatbuffers::FlatBufferBuilder &_fbb)
|
||||
: fbb_(_fbb) {
|
||||
explicit FooBarBuilder(flatbuffers::FlatBufferBuilder& _fbb) : fbb_(_fbb) {
|
||||
start_ = fbb_.StartTable();
|
||||
}
|
||||
flatbuffers::Offset<FooBar> Finish() {
|
||||
@@ -201,10 +160,9 @@ struct FooBarBuilder {
|
||||
};
|
||||
|
||||
inline flatbuffers::Offset<FooBar> CreateFooBar(
|
||||
flatbuffers::FlatBufferBuilder &_fbb,
|
||||
const benchmarks_flatbuffers::Bar *sibling = nullptr,
|
||||
flatbuffers::Offset<flatbuffers::String> name = 0,
|
||||
double rating = 0.0,
|
||||
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);
|
||||
@@ -215,18 +173,12 @@ inline flatbuffers::Offset<FooBar> CreateFooBar(
|
||||
}
|
||||
|
||||
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) {
|
||||
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);
|
||||
return benchmarks_flatbuffers::CreateFooBar(_fbb, sibling, name__, rating,
|
||||
postfix);
|
||||
}
|
||||
|
||||
struct FooBarContainer FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table {
|
||||
@@ -237,49 +189,53 @@ struct FooBarContainer FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table {
|
||||
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;
|
||||
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));
|
||||
return static_cast<benchmarks_flatbuffers::Enum>(
|
||||
GetField<int16_t>(VT_FRUIT, 0));
|
||||
}
|
||||
const flatbuffers::String *location() const {
|
||||
return GetPointer<const flatbuffers::String *>(VT_LOCATION);
|
||||
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) &&
|
||||
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();
|
||||
verifier.VerifyString(location()) && verifier.EndTable();
|
||||
}
|
||||
};
|
||||
|
||||
struct FooBarContainerBuilder {
|
||||
typedef FooBarContainer Table;
|
||||
flatbuffers::FlatBufferBuilder &fbb_;
|
||||
flatbuffers::FlatBufferBuilder& fbb_;
|
||||
flatbuffers::uoffset_t start_;
|
||||
void add_list(flatbuffers::Offset<flatbuffers::Vector<flatbuffers::Offset<benchmarks_flatbuffers::FooBar>>> list) {
|
||||
void add_list(flatbuffers::Offset<flatbuffers::Vector<
|
||||
flatbuffers::Offset<benchmarks_flatbuffers::FooBar>>>
|
||||
list) {
|
||||
fbb_.AddOffset(FooBarContainer::VT_LIST, list);
|
||||
}
|
||||
void add_initialized(bool initialized) {
|
||||
fbb_.AddElement<uint8_t>(FooBarContainer::VT_INITIALIZED, static_cast<uint8_t>(initialized), 0);
|
||||
fbb_.AddElement<uint8_t>(FooBarContainer::VT_INITIALIZED,
|
||||
static_cast<uint8_t>(initialized), 0);
|
||||
}
|
||||
void add_fruit(benchmarks_flatbuffers::Enum fruit) {
|
||||
fbb_.AddElement<int16_t>(FooBarContainer::VT_FRUIT, static_cast<int16_t>(fruit), 0);
|
||||
fbb_.AddElement<int16_t>(FooBarContainer::VT_FRUIT,
|
||||
static_cast<int16_t>(fruit), 0);
|
||||
}
|
||||
void add_location(flatbuffers::Offset<flatbuffers::String> location) {
|
||||
fbb_.AddOffset(FooBarContainer::VT_LOCATION, location);
|
||||
}
|
||||
explicit FooBarContainerBuilder(flatbuffers::FlatBufferBuilder &_fbb)
|
||||
: fbb_(_fbb) {
|
||||
explicit FooBarContainerBuilder(flatbuffers::FlatBufferBuilder& _fbb)
|
||||
: fbb_(_fbb) {
|
||||
start_ = fbb_.StartTable();
|
||||
}
|
||||
flatbuffers::Offset<FooBarContainer> Finish() {
|
||||
@@ -290,8 +246,10 @@ struct FooBarContainerBuilder {
|
||||
};
|
||||
|
||||
inline flatbuffers::Offset<FooBarContainer> CreateFooBarContainer(
|
||||
flatbuffers::FlatBufferBuilder &_fbb,
|
||||
flatbuffers::Offset<flatbuffers::Vector<flatbuffers::Offset<benchmarks_flatbuffers::FooBar>>> list = 0,
|
||||
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) {
|
||||
@@ -304,47 +262,52 @@ inline flatbuffers::Offset<FooBarContainer> CreateFooBarContainer(
|
||||
}
|
||||
|
||||
inline flatbuffers::Offset<FooBarContainer> CreateFooBarContainerDirect(
|
||||
flatbuffers::FlatBufferBuilder &_fbb,
|
||||
const std::vector<flatbuffers::Offset<benchmarks_flatbuffers::FooBar>> *list = nullptr,
|
||||
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;
|
||||
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__);
|
||||
_fbb, list__, initialized, fruit, location__);
|
||||
}
|
||||
|
||||
inline const benchmarks_flatbuffers::FooBarContainer *GetFooBarContainer(const void *buf) {
|
||||
inline const benchmarks_flatbuffers::FooBarContainer* GetFooBarContainer(
|
||||
const void* buf) {
|
||||
return flatbuffers::GetRoot<benchmarks_flatbuffers::FooBarContainer>(buf);
|
||||
}
|
||||
|
||||
inline const benchmarks_flatbuffers::FooBarContainer *GetSizePrefixedFooBarContainer(const void *buf) {
|
||||
return flatbuffers::GetSizePrefixedRoot<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 VerifyFooBarContainerBuffer(flatbuffers::Verifier& verifier) {
|
||||
return verifier.VerifyBuffer<benchmarks_flatbuffers::FooBarContainer>(
|
||||
nullptr);
|
||||
}
|
||||
|
||||
inline bool VerifySizePrefixedFooBarContainerBuffer(
|
||||
flatbuffers::Verifier &verifier) {
|
||||
return verifier.VerifySizePrefixedBuffer<benchmarks_flatbuffers::FooBarContainer>(nullptr);
|
||||
flatbuffers::Verifier& verifier) {
|
||||
return verifier
|
||||
.VerifySizePrefixedBuffer<benchmarks_flatbuffers::FooBarContainer>(
|
||||
nullptr);
|
||||
}
|
||||
|
||||
inline void FinishFooBarContainerBuffer(
|
||||
flatbuffers::FlatBufferBuilder &fbb,
|
||||
flatbuffers::FlatBufferBuilder& fbb,
|
||||
flatbuffers::Offset<benchmarks_flatbuffers::FooBarContainer> root) {
|
||||
fbb.Finish(root);
|
||||
}
|
||||
|
||||
inline void FinishSizePrefixedFooBarContainerBuffer(
|
||||
flatbuffers::FlatBufferBuilder &fbb,
|
||||
flatbuffers::FlatBufferBuilder& fbb,
|
||||
flatbuffers::Offset<benchmarks_flatbuffers::FooBarContainer> root) {
|
||||
fbb.FinishSizePrefixed(root);
|
||||
}
|
||||
|
||||
@@ -13,10 +13,10 @@ using namespace benchmarks_flatbuffers;
|
||||
namespace {
|
||||
|
||||
struct FlatBufferBench : Bench {
|
||||
explicit FlatBufferBench(int64_t initial_size, Allocator *allocator)
|
||||
explicit FlatBufferBench(int64_t initial_size, Allocator* allocator)
|
||||
: fbb(initial_size, allocator, false) {}
|
||||
|
||||
uint8_t *Encode(void *, int64_t &len) override {
|
||||
uint8_t* Encode(void*, int64_t& len) override {
|
||||
fbb.Clear();
|
||||
|
||||
const int kVectorLength = 3;
|
||||
@@ -40,7 +40,7 @@ struct FlatBufferBench : Bench {
|
||||
return fbb.GetBufferPointer();
|
||||
}
|
||||
|
||||
int64_t Use(void *decoded) override {
|
||||
int64_t Use(void* decoded) override {
|
||||
sum = 0;
|
||||
auto foobarcontainer = GetFooBarContainer(decoded);
|
||||
sum = 0;
|
||||
@@ -56,7 +56,7 @@ struct FlatBufferBench : Bench {
|
||||
Add(static_cast<int64_t>(bar->ratio()));
|
||||
Add(bar->size());
|
||||
Add(bar->time());
|
||||
auto &foo = bar->parent();
|
||||
auto& foo = bar->parent();
|
||||
Add(foo.count());
|
||||
Add(foo.id());
|
||||
Add(foo.length());
|
||||
@@ -65,8 +65,8 @@ struct FlatBufferBench : Bench {
|
||||
return sum;
|
||||
}
|
||||
|
||||
void *Decode(void *buffer, int64_t) override { return buffer; }
|
||||
void Dealloc(void *) override {};
|
||||
void* Decode(void* buffer, int64_t) override { return buffer; }
|
||||
void Dealloc(void*) override {};
|
||||
|
||||
FlatBufferBuilder fbb;
|
||||
};
|
||||
@@ -74,7 +74,7 @@ struct FlatBufferBench : Bench {
|
||||
} // namespace
|
||||
|
||||
std::unique_ptr<Bench> NewFlatBuffersBench(int64_t initial_size,
|
||||
Allocator *allocator) {
|
||||
Allocator* allocator) {
|
||||
return std::unique_ptr<FlatBufferBench>(
|
||||
new FlatBufferBench(initial_size, allocator));
|
||||
}
|
||||
|
||||
@@ -8,16 +8,16 @@
|
||||
#include "include/flatbuffers/flatbuffers.h"
|
||||
|
||||
struct StaticAllocator : public flatbuffers::Allocator {
|
||||
explicit StaticAllocator(uint8_t *buffer) : buffer_(buffer) {}
|
||||
explicit StaticAllocator(uint8_t* buffer) : buffer_(buffer) {}
|
||||
|
||||
uint8_t *allocate(size_t) override { return buffer_; }
|
||||
uint8_t* allocate(size_t) override { return buffer_; }
|
||||
|
||||
void deallocate(uint8_t *, size_t) override {}
|
||||
void deallocate(uint8_t*, size_t) override {}
|
||||
|
||||
uint8_t *buffer_;
|
||||
uint8_t* buffer_;
|
||||
};
|
||||
|
||||
std::unique_ptr<Bench> NewFlatBuffersBench(
|
||||
int64_t initial_size = 1024, flatbuffers::Allocator *allocator = nullptr);
|
||||
int64_t initial_size = 1024, flatbuffers::Allocator* allocator = nullptr);
|
||||
|
||||
#endif // BENCHMARKS_CPP_FLATBUFFERS_FB_BENCH_H_
|
||||
@@ -45,8 +45,8 @@ struct FooBarContainer {
|
||||
};
|
||||
|
||||
struct RawBench : Bench {
|
||||
uint8_t *Encode(void *buf, int64_t &len) override {
|
||||
FooBarContainer *fbc = new (buf) FooBarContainer;
|
||||
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;
|
||||
@@ -54,16 +54,16 @@ struct RawBench : Bench {
|
||||
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];
|
||||
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;
|
||||
auto& bar = foobar.sibling;
|
||||
bar.ratio = 3.14159f + i;
|
||||
bar.size = 10000 + i;
|
||||
bar.time = 123456 + i;
|
||||
auto &foo = bar.parent;
|
||||
auto& foo = bar.parent;
|
||||
foo.id = 0xABADCAFEABADCAFE + i;
|
||||
foo.count = 10000 + i;
|
||||
foo.length = 1000000 + i;
|
||||
@@ -71,11 +71,11 @@ struct RawBench : Bench {
|
||||
}
|
||||
|
||||
len = sizeof(FooBarContainer);
|
||||
return reinterpret_cast<uint8_t *>(fbc);
|
||||
return reinterpret_cast<uint8_t*>(fbc);
|
||||
};
|
||||
|
||||
int64_t Use(void *decoded) override {
|
||||
auto foobarcontainer = reinterpret_cast<FooBarContainer *>(decoded);
|
||||
int64_t Use(void* decoded) override {
|
||||
auto foobarcontainer = reinterpret_cast<FooBarContainer*>(decoded);
|
||||
sum = 0;
|
||||
Add(foobarcontainer->initialized);
|
||||
Add(foobarcontainer->location_len);
|
||||
@@ -89,7 +89,7 @@ struct RawBench : Bench {
|
||||
Add(static_cast<int64_t>(bar->ratio));
|
||||
Add(bar->size);
|
||||
Add(bar->time);
|
||||
auto &foo = bar->parent;
|
||||
auto& foo = bar->parent;
|
||||
Add(foo.count);
|
||||
Add(foo.id);
|
||||
Add(foo.length);
|
||||
@@ -98,8 +98,8 @@ struct RawBench : Bench {
|
||||
return sum;
|
||||
}
|
||||
|
||||
void *Decode(void *buf, int64_t) override { return buf; }
|
||||
void Dealloc(void *) override{};
|
||||
void* Decode(void* buf, int64_t) override { return buf; }
|
||||
void Dealloc(void*) override {};
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
@@ -0,0 +1,250 @@
|
||||
/*
|
||||
* Copyright 2024 Google Inc. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import Benchmark
|
||||
import FlatBuffers
|
||||
import Foundation
|
||||
|
||||
@usableFromInline
|
||||
struct AA: NativeStruct {
|
||||
public init(a: Double, b: Double) {
|
||||
self.a = a
|
||||
self.b = b
|
||||
}
|
||||
var a: Double
|
||||
var b: Double
|
||||
}
|
||||
|
||||
let benchmarks = {
|
||||
let oneGB: Int32 = 1_024_000_000
|
||||
let data = {
|
||||
var array = [8888.88, 8888.88]
|
||||
var data = Data()
|
||||
array.withUnsafeBytes { ptr in
|
||||
data.append(contentsOf: ptr)
|
||||
}
|
||||
return data
|
||||
}()
|
||||
let ints: [Int] = Array(repeating: 42, count: 100)
|
||||
let bytes: [UInt8] = Array(repeating: 42, count: 100)
|
||||
let str10 = (0...9).map { _ -> String in "x" }.joined()
|
||||
let str100 = (0...99).map { _ -> String in "x" }.joined()
|
||||
let array: [AA] = [
|
||||
AA(a: 2.4, b: 2.4),
|
||||
AA(a: 2.4, b: 2.4),
|
||||
AA(a: 2.4, b: 2.4),
|
||||
AA(a: 2.4, b: 2.4),
|
||||
AA(a: 2.4, b: 2.4),
|
||||
]
|
||||
|
||||
let metrics: [BenchmarkMetric] = [
|
||||
.cpuTotal,
|
||||
.wallClock,
|
||||
.mallocCountTotal,
|
||||
.releaseCount,
|
||||
.peakMemoryResident,
|
||||
]
|
||||
let maxIterations = 1_000_000
|
||||
let maxDuration: Duration = .seconds(3)
|
||||
let singleConfiguration: Benchmark.Configuration = .init(
|
||||
metrics: metrics,
|
||||
warmupIterations: 1,
|
||||
scalingFactor: .one,
|
||||
maxDuration: maxDuration,
|
||||
maxIterations: maxIterations)
|
||||
let kiloConfiguration: Benchmark.Configuration = .init(
|
||||
metrics: metrics,
|
||||
warmupIterations: 1,
|
||||
scalingFactor: .kilo,
|
||||
maxDuration: maxDuration,
|
||||
maxIterations: maxIterations)
|
||||
let megaConfiguration: Benchmark.Configuration = .init(
|
||||
metrics: metrics,
|
||||
warmupIterations: 1,
|
||||
scalingFactor: .mega,
|
||||
maxDuration: maxDuration,
|
||||
maxIterations: maxIterations)
|
||||
|
||||
Benchmark.defaultConfiguration = megaConfiguration
|
||||
|
||||
Benchmark("Allocating 1GB", configuration: singleConfiguration) { benchmark in
|
||||
for _ in benchmark.scaledIterations {
|
||||
blackHole(FlatBufferBuilder(initialSize: oneGB))
|
||||
}
|
||||
}
|
||||
|
||||
Benchmark(
|
||||
"Allocating ByteBuffer 1GB",
|
||||
configuration: singleConfiguration)
|
||||
{ benchmark in
|
||||
let memory = UnsafeMutableRawPointer.allocate(
|
||||
byteCount: 1_024_000_000,
|
||||
alignment: 1)
|
||||
benchmark.startMeasurement()
|
||||
for _ in benchmark.scaledIterations {
|
||||
blackHole(ByteBuffer(assumingMemoryBound: memory, capacity: Int(oneGB)))
|
||||
}
|
||||
}
|
||||
|
||||
Benchmark("Clearing 1GB", configuration: singleConfiguration) { benchmark in
|
||||
var fb = FlatBufferBuilder(initialSize: oneGB)
|
||||
benchmark.startMeasurement()
|
||||
for _ in benchmark.scaledIterations {
|
||||
blackHole(fb.clear())
|
||||
}
|
||||
}
|
||||
|
||||
Benchmark("Strings 10") { benchmark in
|
||||
var fb = FlatBufferBuilder(initialSize: 1 << 20)
|
||||
benchmark.startMeasurement()
|
||||
for _ in benchmark.scaledIterations {
|
||||
blackHole(fb.create(string: str10))
|
||||
}
|
||||
}
|
||||
|
||||
Benchmark("Strings 100") { benchmark in
|
||||
var fb = FlatBufferBuilder(initialSize: 1 << 20)
|
||||
benchmark.startMeasurement()
|
||||
for _ in benchmark.scaledIterations {
|
||||
blackHole(fb.create(string: str100))
|
||||
}
|
||||
}
|
||||
|
||||
Benchmark("Vector 1 Bytes") { benchmark in
|
||||
var fb = FlatBufferBuilder(initialSize: 1 << 20)
|
||||
benchmark.startMeasurement()
|
||||
for _ in benchmark.scaledIterations {
|
||||
blackHole(fb.createVector(bytes: bytes))
|
||||
}
|
||||
}
|
||||
|
||||
Benchmark("Vector 1 Ints") { benchmark in
|
||||
var fb = FlatBufferBuilder(initialSize: 1 << 20)
|
||||
benchmark.startMeasurement()
|
||||
for _ in benchmark.scaledIterations {
|
||||
blackHole(fb.createVector(ints))
|
||||
}
|
||||
}
|
||||
|
||||
Benchmark("Vector 100 Ints") { benchmark in
|
||||
var fb = FlatBufferBuilder(initialSize: 1 << 20)
|
||||
benchmark.startMeasurement()
|
||||
for i in benchmark.scaledIterations {
|
||||
blackHole(fb.createVector(ints))
|
||||
}
|
||||
}
|
||||
|
||||
Benchmark("Vector 100 Bytes") { benchmark in
|
||||
var fb = FlatBufferBuilder(initialSize: 1 << 20)
|
||||
benchmark.startMeasurement()
|
||||
for i in benchmark.scaledIterations {
|
||||
blackHole(fb.createVector(bytes))
|
||||
}
|
||||
}
|
||||
|
||||
Benchmark("Vector 100 ContiguousBytes") { benchmark in
|
||||
var fb = FlatBufferBuilder(initialSize: 1 << 20)
|
||||
benchmark.startMeasurement()
|
||||
for i in benchmark.scaledIterations {
|
||||
blackHole(fb.createVector(bytes: bytes))
|
||||
}
|
||||
}
|
||||
|
||||
Benchmark(
|
||||
"FlatBufferBuilder Add",
|
||||
configuration: kiloConfiguration)
|
||||
{ benchmark in
|
||||
var fb = FlatBufferBuilder(initialSize: 1024 * 1024 * 32)
|
||||
benchmark.startMeasurement()
|
||||
for _ in benchmark.scaledIterations {
|
||||
let off = fb.create(string: "T")
|
||||
let s = fb.startTable(with: 4)
|
||||
fb.add(element: 3.2, def: 0, at: 2)
|
||||
fb.add(element: 4.2, def: 0, at: 4)
|
||||
fb.add(element: 5.2, def: 0, at: 6)
|
||||
fb.add(offset: off, at: 8)
|
||||
blackHole(fb.endTable(at: s))
|
||||
}
|
||||
}
|
||||
|
||||
Benchmark(
|
||||
"FlatBufferBuilder Start table",
|
||||
configuration: kiloConfiguration)
|
||||
{ benchmark in
|
||||
var fb = FlatBufferBuilder(initialSize: 1024 * 1024 * 32)
|
||||
benchmark.startMeasurement()
|
||||
for _ in benchmark.scaledIterations {
|
||||
let s = fb.startTable(with: 4)
|
||||
blackHole(fb.endTable(at: s))
|
||||
}
|
||||
}
|
||||
|
||||
Benchmark("Struct") { benchmark in
|
||||
var fb = FlatBufferBuilder(initialSize: 1024 * 1024 * 32)
|
||||
benchmark.startMeasurement()
|
||||
for _ in benchmark.scaledIterations {
|
||||
blackHole(fb.create(struct: array.first!))
|
||||
}
|
||||
}
|
||||
|
||||
Benchmark("Structs") { benchmark in
|
||||
let rawSize = ((16 * 5) * benchmark.scaledIterations.count) / 1024
|
||||
var fb = FlatBufferBuilder(initialSize: Int32(rawSize * 1600))
|
||||
var offsets: [Offset] = []
|
||||
|
||||
benchmark.startMeasurement()
|
||||
for _ in benchmark.scaledIterations {
|
||||
let vector = fb.createVector(
|
||||
ofStructs: array)
|
||||
let start = fb.startTable(with: 1)
|
||||
fb.add(offset: vector, at: 4)
|
||||
offsets.append(Offset(offset: fb.endTable(at: start)))
|
||||
}
|
||||
|
||||
let vector = fb.createVector(ofOffsets: offsets)
|
||||
let start = fb.startTable(with: 1)
|
||||
fb.add(offset: vector, at: 4)
|
||||
let root = Offset(offset: fb.endTable(at: start))
|
||||
blackHole(fb.finish(offset: root))
|
||||
}
|
||||
|
||||
Benchmark("Vector of Offsets") { benchmark in
|
||||
let rawSize = ((16 * 5) * benchmark.scaledIterations.count) / 1024
|
||||
var fb = FlatBufferBuilder(initialSize: Int32(rawSize * 1600))
|
||||
benchmark.startMeasurement()
|
||||
for _ in benchmark.scaledIterations {
|
||||
let offsets = [
|
||||
fb.create(string: "T"),
|
||||
fb.create(string: "2"),
|
||||
fb.create(string: "3"),
|
||||
]
|
||||
let off = fb.createVector(ofOffsets: [
|
||||
fb.createVector(ofOffsets: offsets),
|
||||
fb.createVector(ofOffsets: offsets),
|
||||
])
|
||||
let s = fb.startTable(with: 2)
|
||||
fb.add(offset: off, at: 2)
|
||||
blackHole(fb.endTable(at: s))
|
||||
}
|
||||
}
|
||||
|
||||
Benchmark("Reading Doubles") { benchmark in
|
||||
let byteBuffer = ByteBuffer(data: data)
|
||||
for _ in benchmark.scaledIterations {
|
||||
blackHole(byteBuffer.read(def: Double.self, position: 0))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
// swift-tools-version:5.1
|
||||
// swift-tools-version:5.10
|
||||
/*
|
||||
* Copyright 2020 Google Inc. All rights reserved.
|
||||
*
|
||||
@@ -20,15 +20,23 @@ import PackageDescription
|
||||
let package = Package(
|
||||
name: "benchmarks",
|
||||
platforms: [
|
||||
.macOS(.v10_14),
|
||||
.macOS(.v13),
|
||||
],
|
||||
dependencies: [
|
||||
.package(path: "../../.."),
|
||||
.package(url: "https://github.com/google/swift-benchmark", from: "0.1.0"),
|
||||
.package(path: "../.."),
|
||||
.package(
|
||||
url: "https://github.com/ordo-one/package-benchmark",
|
||||
from: "1.27.0"),
|
||||
],
|
||||
targets: [
|
||||
.target(
|
||||
name: "benchmarks",
|
||||
dependencies: ["FlatBuffers",
|
||||
.product(name: "Benchmark", package: "swift-benchmark")]),
|
||||
.executableTarget(
|
||||
name: "FlatbuffersBenchmarks",
|
||||
dependencies: [
|
||||
.product(name: "FlatBuffers", package: "flatbuffers"),
|
||||
.product(name: "Benchmark", package: "package-benchmark"),
|
||||
],
|
||||
path: "Benchmarks/FlatbuffersBenchmarks",
|
||||
plugins: [
|
||||
.plugin(name: "BenchmarkPlugin", package: "package-benchmark"),
|
||||
]),
|
||||
])
|
||||
9
benchmarks/swift/README.md
Normal file
9
benchmarks/swift/README.md
Normal file
@@ -0,0 +1,9 @@
|
||||
# Benchmarks
|
||||
|
||||
To open the benchmarks in xcode use:
|
||||
|
||||
`open --env BENCHMARK_DISABLE_JEMALLOC=true Package.swift`
|
||||
|
||||
or running them directly within terminal using:
|
||||
|
||||
`swift package benchmark`
|
||||
@@ -7,13 +7,13 @@ Rules for building C++ flatbuffers with Bazel.
|
||||
|
||||
load("@rules_cc//cc:defs.bzl", "cc_library")
|
||||
|
||||
TRUE_FLATC_PATH = "@com_github_google_flatbuffers//:flatc"
|
||||
TRUE_FLATC_PATH = Label("//:flatc")
|
||||
|
||||
DEFAULT_INCLUDE_PATHS = [
|
||||
"./",
|
||||
"$(GENDIR)",
|
||||
"$(BINDIR)",
|
||||
"$(execpath @com_github_google_flatbuffers//:flatc).runfiles/com_github_google_flatbuffers",
|
||||
"$(execpath %s).runfiles/%s" % (TRUE_FLATC_PATH, TRUE_FLATC_PATH.repo_name),
|
||||
]
|
||||
|
||||
def default_include_paths(flatc_path):
|
||||
@@ -21,7 +21,7 @@ def default_include_paths(flatc_path):
|
||||
"./",
|
||||
"$(GENDIR)",
|
||||
"$(BINDIR)",
|
||||
"$(execpath %s).runfiles/com_github_google_flatbuffers" % (flatc_path),
|
||||
"$(execpath %s).runfiles/%s" % (flatc_path, flatc_path.repo_name),
|
||||
]
|
||||
|
||||
DEFAULT_FLATC_ARGS = [
|
||||
@@ -47,7 +47,7 @@ def flatbuffer_library_public(
|
||||
compatible_with = None,
|
||||
restricted_to = None,
|
||||
target_compatible_with = None,
|
||||
flatc_path = "@com_github_google_flatbuffers//:flatc",
|
||||
flatc_path = None,
|
||||
output_to_bindir = False,
|
||||
tools = None,
|
||||
extra_env = None,
|
||||
@@ -87,6 +87,12 @@ def flatbuffer_library_public(
|
||||
optionally a Fileset([reflection_name]) with all generated reflection
|
||||
binaries.
|
||||
"""
|
||||
if flatc_path == None:
|
||||
flatc_path = TRUE_FLATC_PATH
|
||||
else:
|
||||
flatc_path = native.package_relative_label(flatc_path)
|
||||
|
||||
reflection_include_paths = include_paths
|
||||
if include_paths == None:
|
||||
include_paths = default_include_paths(flatc_path)
|
||||
include_paths_cmd = ["-I %s" % (s) for s in include_paths]
|
||||
@@ -124,22 +130,28 @@ def flatbuffer_library_public(
|
||||
**kwargs
|
||||
)
|
||||
if reflection_name:
|
||||
if reflection_include_paths == None:
|
||||
reflection_include_paths = default_include_paths(TRUE_FLATC_PATH)
|
||||
reflection_include_paths_cmd = ["-I %s" % (s) for s in reflection_include_paths]
|
||||
reflection_genrule_cmd = " ".join([
|
||||
"SRCS=($(SRCS));",
|
||||
"for f in $${SRCS[@]:0:%s}; do" % len(srcs),
|
||||
# Move the .fbs file into the current package if it is not there already
|
||||
'if [[ $$(dirname $$f) != "{0}" ]]; then s="$$f"; f="{0}/$$(basename "$$f")"; mkdir -p "{0}"; mv "$$s" "$$f"; fi;'.format(native.package_relative_label(":invalid").package),
|
||||
"$(location %s)" % (TRUE_FLATC_PATH),
|
||||
"-b --schema",
|
||||
" ".join(flatc_args),
|
||||
" ".join(include_paths_cmd),
|
||||
" ".join(reflection_include_paths_cmd),
|
||||
language_flag,
|
||||
output_directory,
|
||||
"$$f;",
|
||||
"done",
|
||||
])
|
||||
reflection_outs = [
|
||||
(out_prefix + "%s.bfbs") % (s.replace(".fbs", "").split("/")[-1])
|
||||
(out_prefix + "%s.bfbs") % (native.package_relative_label(s).name.removesuffix(".fbs"))
|
||||
for s in srcs
|
||||
]
|
||||
|
||||
native.genrule(
|
||||
name = "%s_srcs" % reflection_name,
|
||||
srcs = srcs + includes,
|
||||
@@ -175,6 +187,7 @@ def flatbuffer_cc_library(
|
||||
visibility = None,
|
||||
compatible_with = None,
|
||||
restricted_to = None,
|
||||
filename_suffix = "_generated",
|
||||
target_compatible_with = None,
|
||||
srcs_filegroup_visibility = None,
|
||||
gen_reflections = False):
|
||||
@@ -218,10 +231,13 @@ def flatbuffer_cc_library(
|
||||
Fileset([name]_reflection): (Optional) all generated reflection binaries.
|
||||
cc_library([name]): library with sources and flatbuffers deps.
|
||||
"""
|
||||
output_headers = [
|
||||
(out_prefix + "%s_generated.h") % (s.replace(".fbs", "").split("/")[-1].split(":")[-1])
|
||||
for s in srcs
|
||||
]
|
||||
|
||||
output_headers = []
|
||||
for s in srcs:
|
||||
base_name = s.split("/")[-1].split(":")[-1].replace(".fbs", "")
|
||||
header = out_prefix + base_name + filename_suffix + ".h"
|
||||
output_headers.append(header)
|
||||
|
||||
if deps and includes:
|
||||
# There is no inherent reason we couldn't support both, but this discourages
|
||||
# use of includes without good reason.
|
||||
@@ -258,8 +274,8 @@ def flatbuffer_cc_library(
|
||||
"-parse_headers",
|
||||
],
|
||||
deps = [
|
||||
"@com_github_google_flatbuffers//:runtime_cc",
|
||||
"@com_github_google_flatbuffers//:flatbuffers",
|
||||
Label("//:runtime_cc"),
|
||||
Label("//:flatbuffers"),
|
||||
] + deps,
|
||||
includes = cc_include_paths,
|
||||
compatible_with = compatible_with,
|
||||
|
||||
@@ -1,12 +0,0 @@
|
||||
cmake_minimum_required(VERSION 2.8)
|
||||
|
||||
message(STATUS "Conan FlatBuffers Wrapper")
|
||||
|
||||
include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
|
||||
conan_basic_setup()
|
||||
|
||||
if (WIN32 AND MSVC_LIKE AND FLATBUFFERS_BUILD_SHAREDLIB)
|
||||
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)
|
||||
endif(WIN32 AND MSVC_LIKE AND FLATBUFFERS_BUILD_SHAREDLIB)
|
||||
|
||||
include(${CMAKE_SOURCE_DIR}/CMakeListsOriginal.txt)
|
||||
@@ -1,50 +0,0 @@
|
||||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
import os
|
||||
import re
|
||||
import subprocess
|
||||
from cpt.packager import ConanMultiPackager
|
||||
|
||||
|
||||
|
||||
def get_branch():
|
||||
try:
|
||||
for line in subprocess.check_output("git branch", shell=True).decode().splitlines():
|
||||
line = line.strip()
|
||||
if line.startswith("*") and " (HEAD detached" not in line:
|
||||
return line.replace("*", "", 1).strip()
|
||||
return ""
|
||||
except Exception:
|
||||
pass
|
||||
return ""
|
||||
|
||||
|
||||
def get_version():
|
||||
version = get_branch()
|
||||
match = re.search(r"v(\d+\.\d+\.\d+.*)", version)
|
||||
if match:
|
||||
return match.group(1)
|
||||
return version
|
||||
|
||||
|
||||
def get_reference(username):
|
||||
return "flatbuffers/{}@google/stable".format(get_version())
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
login_username = os.getenv("CONAN_LOGIN_USERNAME", "aardappel")
|
||||
username = os.getenv("CONAN_USERNAME", "google")
|
||||
upload = os.getenv("CONAN_UPLOAD", "https://api.bintray.com/conan/aardappel/flatbuffers")
|
||||
stable_branch_pattern = os.getenv("CONAN_STABLE_BRANCH_PATTERN", r"v\d+\.\d+\.\d+.*")
|
||||
test_folder = os.getenv("CPT_TEST_FOLDER", os.path.join("conan", "test_package"))
|
||||
upload_only_when_stable = os.getenv("CONAN_UPLOAD_ONLY_WHEN_STABLE", True)
|
||||
|
||||
builder = ConanMultiPackager(reference=get_reference(username),
|
||||
username=username,
|
||||
login_username=login_username,
|
||||
upload=upload,
|
||||
stable_branch_pattern=stable_branch_pattern,
|
||||
upload_only_when_stable=upload_only_when_stable,
|
||||
test_folder=test_folder)
|
||||
builder.add_common_builds(pure_c=False)
|
||||
builder.run()
|
||||
@@ -1,9 +0,0 @@
|
||||
project(test_package CXX)
|
||||
cmake_minimum_required(VERSION 2.8.11)
|
||||
|
||||
include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
|
||||
conan_basic_setup()
|
||||
|
||||
add_executable(${PROJECT_NAME} test_package.cpp)
|
||||
target_link_libraries(${PROJECT_NAME} ${CONAN_LIBS})
|
||||
set_property(TARGET ${PROJECT_NAME} PROPERTY CXX_STANDARD 11)
|
||||
@@ -1,21 +0,0 @@
|
||||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
from conans import ConanFile, CMake
|
||||
import os
|
||||
|
||||
|
||||
class TestPackageConan(ConanFile):
|
||||
settings = "os", "compiler", "build_type", "arch"
|
||||
generators = "cmake"
|
||||
|
||||
def build(self):
|
||||
cmake = CMake(self)
|
||||
cmake.configure()
|
||||
cmake.build()
|
||||
|
||||
def test(self):
|
||||
bin_path = os.path.join("bin", "test_package")
|
||||
self.run(bin_path, run_environment=True)
|
||||
self.run("flatc --version", run_environment=True)
|
||||
self.run("flathash fnv1_16 conan", run_environment=True)
|
||||
@@ -1,35 +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.
|
||||
*/
|
||||
|
||||
#include <cstdlib>
|
||||
#include <iostream>
|
||||
#include "flatbuffers/util.h"
|
||||
|
||||
// Test to validate Conan package generated
|
||||
|
||||
int main(int /*argc*/, const char * /*argv*/ []) {
|
||||
|
||||
const std::string filename("conanbuildinfo.cmake");
|
||||
|
||||
if (flatbuffers::FileExists(filename.c_str())) {
|
||||
std::cout << "File " << filename << " exists.\n";
|
||||
} else {
|
||||
std::cout << "File " << filename << " does not exist.\n";
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
75
conanfile.py
75
conanfile.py
@@ -1,75 +0,0 @@
|
||||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
"""Conan recipe package for Google FlatBuffers
|
||||
"""
|
||||
import os
|
||||
import shutil
|
||||
from conans import ConanFile, CMake, tools
|
||||
|
||||
|
||||
class FlatbuffersConan(ConanFile):
|
||||
name = "flatbuffers"
|
||||
license = "Apache-2.0"
|
||||
url = "https://github.com/google/flatbuffers"
|
||||
homepage = "http://google.github.io/flatbuffers/"
|
||||
author = "Wouter van Oortmerssen"
|
||||
topics = ("conan", "flatbuffers", "serialization", "rpc", "json-parser")
|
||||
description = "Memory Efficient Serialization Library"
|
||||
settings = "os", "compiler", "build_type", "arch"
|
||||
options = {"shared": [True, False], "fPIC": [True, False]}
|
||||
default_options = {"shared": False, "fPIC": True}
|
||||
generators = "cmake"
|
||||
exports = "LICENSE"
|
||||
exports_sources = ["CMake/*", "include/*", "src/*", "grpc/*", "CMakeLists.txt", "conan/CMakeLists.txt"]
|
||||
|
||||
def source(self):
|
||||
"""Wrap the original CMake file to call conan_basic_setup
|
||||
"""
|
||||
shutil.move("CMakeLists.txt", "CMakeListsOriginal.txt")
|
||||
shutil.move(os.path.join("conan", "CMakeLists.txt"), "CMakeLists.txt")
|
||||
|
||||
def config_options(self):
|
||||
"""Remove fPIC option on Windows platform
|
||||
"""
|
||||
if self.settings.os == "Windows":
|
||||
self.options.remove("fPIC")
|
||||
|
||||
def configure_cmake(self):
|
||||
"""Create CMake instance and execute configure step
|
||||
"""
|
||||
cmake = CMake(self)
|
||||
cmake.definitions["FLATBUFFERS_BUILD_TESTS"] = False
|
||||
cmake.definitions["FLATBUFFERS_BUILD_SHAREDLIB"] = self.options.shared
|
||||
cmake.definitions["FLATBUFFERS_BUILD_FLATLIB"] = not self.options.shared
|
||||
cmake.configure()
|
||||
return cmake
|
||||
|
||||
def build(self):
|
||||
"""Configure, build and install FlatBuffers using CMake.
|
||||
"""
|
||||
cmake = self.configure_cmake()
|
||||
cmake.build()
|
||||
|
||||
def package(self):
|
||||
"""Copy Flatbuffers' artifacts to package folder
|
||||
"""
|
||||
cmake = self.configure_cmake()
|
||||
cmake.install()
|
||||
self.copy(pattern="LICENSE", dst="licenses")
|
||||
self.copy(pattern="FindFlatBuffers.cmake", dst=os.path.join("lib", "cmake", "flatbuffers"), src="CMake")
|
||||
self.copy(pattern="flathash*", dst="bin", src="bin")
|
||||
self.copy(pattern="flatc*", dst="bin", src="bin")
|
||||
if self.settings.os == "Windows" and self.options.shared:
|
||||
if self.settings.compiler == "Visual Studio":
|
||||
shutil.move(os.path.join(self.package_folder, "lib", "%s.dll" % self.name),
|
||||
os.path.join(self.package_folder, "bin", "%s.dll" % self.name))
|
||||
elif self.settings.compiler == "gcc":
|
||||
shutil.move(os.path.join(self.package_folder, "lib", "lib%s.dll" % self.name),
|
||||
os.path.join(self.package_folder, "bin", "lib%s.dll" % self.name))
|
||||
|
||||
def package_info(self):
|
||||
"""Collect built libraries names and solve flatc path.
|
||||
"""
|
||||
self.cpp_info.libs = tools.collect_libs(self)
|
||||
self.user_info.flatc = os.path.join(self.package_folder, "bin", "flatc")
|
||||
@@ -1,3 +1,23 @@
|
||||
# Changelog
|
||||
|
||||
## 25.9.23
|
||||
|
||||
- use enhanced enums (#8313)
|
||||
- fix incorrect write in Float64 write method (#8290)
|
||||
- code format improvements (#8707)
|
||||
|
||||
## 23.5.26
|
||||
|
||||
- omit type annotationes for local variables (#7067, #7069, #7070)
|
||||
- remove BSD 3-clause license (#7073)
|
||||
- correctly parse lists of enums (#7157)
|
||||
- align naming conventions for generated code (#7187)
|
||||
- add `putBool` to fix errors when serializing structs with booleans (#7359)
|
||||
- fix handling of +/-inf defaults in codegen (#7588)
|
||||
- fix import issues in generated code (#7621)
|
||||
- Fix incorrect storage of floats as ints in some cases (#7703)
|
||||
- add final modifiers to the library implementation (#7943)
|
||||
|
||||
## 2.0.5
|
||||
|
||||
- switch to null safety (#6696)
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
This package is used to read and write [FlatBuffers](https://google.github.io/flatbuffers/).
|
||||
|
||||
Most consumers will want to use the [`flatc` - FlatBuffer compiler](https://github.com/google/flatbuffers) binary for your platform.
|
||||
You can find it in the `generator/{Platform}` directory of the [released package archive](https://pub.dev/packages/flat_buffers/versions/2.0.5.tar.gz).
|
||||
You can download the flatc version matching your dart package version from [GitHub releases](https://github.com/google/flatbuffers/releases).
|
||||
|
||||
The FlatBuffer compiler `flatc` reads a FlatBuffers IDL schema and generates Dart code.
|
||||
The generated classes can be used to read or write binary data/files that are interoperable with
|
||||
@@ -13,11 +13,3 @@ examples folder.
|
||||
For more details and documentation, head over to the official site and read the
|
||||
[Tutorial](https://google.github.io/flatbuffers/flatbuffers_guide_tutorial.html) and how to
|
||||
[use FlatBuffers in Dart](https://google.github.io/flatbuffers/flatbuffers_guide_use_dart.html).
|
||||
|
||||
## Dart 2.0 notes
|
||||
Version 2.0.5 ships with it's own custom build of `flatc` because this is an extraordinary release to catch-up
|
||||
with FlatBuffers for other platforms. This generator can only generate dart code (to avoid generating code for other platforms which isn't released yet).
|
||||
On the other hand, the generated code still produces standard binary FlatBuffers compatible with other languages.
|
||||
In other words: only `flatc --dart ...` works with this generator, but your app will be able to produce and read standard binary (`Uint8List`) FlatBuffers that are fully compotible with other languages supporting FlatBuffers (e.g. Java, C++, ...).
|
||||
|
||||
In the future a common `flatc` binary for all platforms would be shipped through GitHub release page instead.
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
*/
|
||||
|
||||
import 'package:flat_buffers/flat_buffers.dart' as fb;
|
||||
|
||||
import './monster_my_game.sample_generated.dart' as my_game;
|
||||
|
||||
// Example how to use FlatBuffers to create and read binary buffers.
|
||||
@@ -78,7 +79,8 @@ void builderTest() {
|
||||
builder.finish(monsteroff);
|
||||
if (verify(builder.buffer)) {
|
||||
print(
|
||||
"The FlatBuffer was successfully created with a builder and verified!");
|
||||
"The FlatBuffer was successfully created with a builder and verified!",
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -94,7 +96,10 @@ void objectBuilderTest() {
|
||||
name: 'Orc',
|
||||
inventory: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9],
|
||||
color: my_game.Color.Red,
|
||||
weapons: [my_game.WeaponObjectBuilder(name: 'Sword', damage: 3), axe],
|
||||
weapons: [
|
||||
my_game.WeaponObjectBuilder(name: 'Sword', damage: 3),
|
||||
axe,
|
||||
],
|
||||
equippedType: my_game.EquipmentTypeId.Weapon,
|
||||
equipped: axe,
|
||||
);
|
||||
@@ -108,7 +113,8 @@ void objectBuilderTest() {
|
||||
// Instead, we're going to access it right away (as if we just received it).
|
||||
if (verify(buffer)) {
|
||||
print(
|
||||
"The FlatBuffer was successfully created with an object builder and verified!");
|
||||
"The FlatBuffer was successfully created with an object builder and verified!",
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -4,8 +4,8 @@
|
||||
library my_game.sample;
|
||||
|
||||
import 'dart:typed_data' show Uint8List;
|
||||
import 'package:flat_buffers/flat_buffers.dart' as fb;
|
||||
|
||||
import 'package:flat_buffers/flat_buffers.dart' as fb;
|
||||
|
||||
class Color {
|
||||
final int value;
|
||||
@@ -19,7 +19,7 @@ class Color {
|
||||
return result;
|
||||
}
|
||||
|
||||
static Color? _createOrNull(int? value) =>
|
||||
static Color? _createOrNull(int? value) =>
|
||||
value == null ? null : Color.fromValue(value);
|
||||
|
||||
static const int minValue = 0;
|
||||
@@ -29,10 +29,7 @@ class Color {
|
||||
static const Color Red = Color._(0);
|
||||
static const Color Green = Color._(1);
|
||||
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 = _ColorReader();
|
||||
|
||||
@@ -60,12 +57,14 @@ class EquipmentTypeId {
|
||||
factory EquipmentTypeId.fromValue(int value) {
|
||||
final result = values[value];
|
||||
if (result == null) {
|
||||
throw StateError('Invalid value $value for bit flag enum EquipmentTypeId');
|
||||
throw StateError(
|
||||
'Invalid value $value for bit flag enum EquipmentTypeId',
|
||||
);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
static EquipmentTypeId? _createOrNull(int? value) =>
|
||||
static EquipmentTypeId? _createOrNull(int? value) =>
|
||||
value == null ? null : EquipmentTypeId.fromValue(value);
|
||||
|
||||
static const int minValue = 0;
|
||||
@@ -74,9 +73,7 @@ class EquipmentTypeId {
|
||||
|
||||
static const EquipmentTypeId NONE = EquipmentTypeId._(0);
|
||||
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 = _EquipmentTypeIdReader();
|
||||
|
||||
@@ -122,8 +119,7 @@ class _Vec3Reader extends fb.StructReader<Vec3> {
|
||||
int get size => 12;
|
||||
|
||||
@override
|
||||
Vec3 createObject(fb.BufferContext bc, int offset) =>
|
||||
Vec3._(bc, offset);
|
||||
Vec3 createObject(fb.BufferContext bc, int offset) => Vec3._(bc, offset);
|
||||
}
|
||||
|
||||
class Vec3Builder {
|
||||
@@ -137,7 +133,6 @@ class Vec3Builder {
|
||||
fbBuilder.putFloat32(x);
|
||||
return fbBuilder.offset;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class Vec3ObjectBuilder extends fb.ObjectBuilder {
|
||||
@@ -145,14 +140,10 @@ class Vec3ObjectBuilder extends fb.ObjectBuilder {
|
||||
final double _y;
|
||||
final double _z;
|
||||
|
||||
Vec3ObjectBuilder({
|
||||
required double x,
|
||||
required double y,
|
||||
required double z,
|
||||
})
|
||||
: _x = x,
|
||||
_y = y,
|
||||
_z = z;
|
||||
Vec3ObjectBuilder({required double x, required double y, required double z})
|
||||
: _x = x,
|
||||
_y = y,
|
||||
_z = z;
|
||||
|
||||
/// Finish building, and store into the [fbBuilder].
|
||||
@override
|
||||
@@ -171,6 +162,7 @@ class Vec3ObjectBuilder extends fb.ObjectBuilder {
|
||||
return fbBuilder.buffer;
|
||||
}
|
||||
}
|
||||
|
||||
class Monster {
|
||||
Monster._(this._bc, this._bcOffset);
|
||||
factory Monster(List<int> bytes) {
|
||||
@@ -186,18 +178,30 @@ class Monster {
|
||||
Vec3? get pos => Vec3.reader.vTableGetNullable(_bc, _bcOffset, 4);
|
||||
int get mana => const fb.Int16Reader().vTableGet(_bc, _bcOffset, 6, 150);
|
||||
int get hp => const fb.Int16Reader().vTableGet(_bc, _bcOffset, 8, 100);
|
||||
String? get name => const fb.StringReader().vTableGetNullable(_bc, _bcOffset, 10);
|
||||
List<int>? get inventory => const fb.Uint8ListReader().vTableGetNullable(_bc, _bcOffset, 14);
|
||||
Color get color => Color.fromValue(const fb.Int8Reader().vTableGet(_bc, _bcOffset, 16, 2));
|
||||
List<Weapon>? get weapons => const fb.ListReader<Weapon>(Weapon.reader).vTableGetNullable(_bc, _bcOffset, 18);
|
||||
EquipmentTypeId? get equippedType => EquipmentTypeId._createOrNull(const fb.Uint8Reader().vTableGetNullable(_bc, _bcOffset, 20));
|
||||
String? get name =>
|
||||
const fb.StringReader().vTableGetNullable(_bc, _bcOffset, 10);
|
||||
List<int>? get inventory =>
|
||||
const fb.Uint8ListReader().vTableGetNullable(_bc, _bcOffset, 14);
|
||||
Color get color =>
|
||||
Color.fromValue(const fb.Int8Reader().vTableGet(_bc, _bcOffset, 16, 2));
|
||||
List<Weapon>? get weapons => const fb.ListReader<Weapon>(
|
||||
Weapon.reader,
|
||||
).vTableGetNullable(_bc, _bcOffset, 18);
|
||||
EquipmentTypeId? get equippedType => EquipmentTypeId._createOrNull(
|
||||
const fb.Uint8Reader().vTableGetNullable(_bc, _bcOffset, 20),
|
||||
);
|
||||
dynamic get equipped {
|
||||
switch (equippedType?.value) {
|
||||
case 1: return Weapon.reader.vTableGetNullable(_bc, _bcOffset, 22);
|
||||
default: return null;
|
||||
case 1:
|
||||
return Weapon.reader.vTableGetNullable(_bc, _bcOffset, 22);
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
List<Vec3>? get path => const fb.ListReader<Vec3>(Vec3.reader).vTableGetNullable(_bc, _bcOffset, 24);
|
||||
|
||||
List<Vec3>? get path => const fb.ListReader<Vec3>(
|
||||
Vec3.reader,
|
||||
).vTableGetNullable(_bc, _bcOffset, 24);
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
@@ -209,8 +213,8 @@ class _MonsterReader extends fb.TableReader<Monster> {
|
||||
const _MonsterReader();
|
||||
|
||||
@override
|
||||
Monster createObject(fb.BufferContext bc, int offset) =>
|
||||
Monster._(bc, offset);
|
||||
Monster createObject(fb.BufferContext bc, int offset) =>
|
||||
Monster._(bc, offset);
|
||||
}
|
||||
|
||||
class MonsterBuilder {
|
||||
@@ -226,38 +230,47 @@ class MonsterBuilder {
|
||||
fbBuilder.addStruct(0, offset);
|
||||
return fbBuilder.offset;
|
||||
}
|
||||
|
||||
int addMana(int? mana) {
|
||||
fbBuilder.addInt16(1, mana);
|
||||
return fbBuilder.offset;
|
||||
}
|
||||
|
||||
int addHp(int? hp) {
|
||||
fbBuilder.addInt16(2, hp);
|
||||
return fbBuilder.offset;
|
||||
}
|
||||
|
||||
int addNameOffset(int? offset) {
|
||||
fbBuilder.addOffset(3, offset);
|
||||
return fbBuilder.offset;
|
||||
}
|
||||
|
||||
int addInventoryOffset(int? offset) {
|
||||
fbBuilder.addOffset(5, offset);
|
||||
return fbBuilder.offset;
|
||||
}
|
||||
|
||||
int addColor(Color? color) {
|
||||
fbBuilder.addInt8(6, color?.value);
|
||||
return fbBuilder.offset;
|
||||
}
|
||||
|
||||
int addWeaponsOffset(int? offset) {
|
||||
fbBuilder.addOffset(7, offset);
|
||||
return fbBuilder.offset;
|
||||
}
|
||||
|
||||
int addEquippedType(EquipmentTypeId? equippedType) {
|
||||
fbBuilder.addUint8(8, equippedType?.value);
|
||||
return fbBuilder.offset;
|
||||
}
|
||||
|
||||
int addEquippedOffset(int? offset) {
|
||||
fbBuilder.addOffset(9, offset);
|
||||
return fbBuilder.offset;
|
||||
}
|
||||
|
||||
int addPathOffset(int? offset) {
|
||||
fbBuilder.addOffset(10, offset);
|
||||
return fbBuilder.offset;
|
||||
@@ -291,29 +304,34 @@ class MonsterObjectBuilder extends fb.ObjectBuilder {
|
||||
EquipmentTypeId? equippedType,
|
||||
dynamic equipped,
|
||||
List<Vec3ObjectBuilder>? path,
|
||||
})
|
||||
: _pos = pos,
|
||||
_mana = mana,
|
||||
_hp = hp,
|
||||
_name = name,
|
||||
_inventory = inventory,
|
||||
_color = color,
|
||||
_weapons = weapons,
|
||||
_equippedType = equippedType,
|
||||
_equipped = equipped,
|
||||
_path = path;
|
||||
}) : _pos = pos,
|
||||
_mana = mana,
|
||||
_hp = hp,
|
||||
_name = name,
|
||||
_inventory = inventory,
|
||||
_color = color,
|
||||
_weapons = weapons,
|
||||
_equippedType = equippedType,
|
||||
_equipped = equipped,
|
||||
_path = path;
|
||||
|
||||
/// Finish building, and store into the [fbBuilder].
|
||||
@override
|
||||
int finish(fb.Builder fbBuilder) {
|
||||
final int? nameOffset = _name == null ? null
|
||||
final int? nameOffset = _name == null
|
||||
? null
|
||||
: fbBuilder.writeString(_name!);
|
||||
final int? inventoryOffset = _inventory == null ? null
|
||||
final int? inventoryOffset = _inventory == null
|
||||
? null
|
||||
: fbBuilder.writeListUint8(_inventory!);
|
||||
final int? weaponsOffset = _weapons == null ? null
|
||||
: fbBuilder.writeList(_weapons!.map((b) => b.getOrCreateOffset(fbBuilder)).toList());
|
||||
final int? weaponsOffset = _weapons == null
|
||||
? null
|
||||
: fbBuilder.writeList(
|
||||
_weapons!.map((b) => b.getOrCreateOffset(fbBuilder)).toList(),
|
||||
);
|
||||
final int? equippedOffset = _equipped?.getOrCreateOffset(fbBuilder);
|
||||
final int? pathOffset = _path == null ? null
|
||||
final int? pathOffset = _path == null
|
||||
? null
|
||||
: fbBuilder.writeListOfStructs(_path!);
|
||||
fbBuilder.startTable(10);
|
||||
if (_pos != null) {
|
||||
@@ -339,6 +357,7 @@ class MonsterObjectBuilder extends fb.ObjectBuilder {
|
||||
return fbBuilder.buffer;
|
||||
}
|
||||
}
|
||||
|
||||
class Weapon {
|
||||
Weapon._(this._bc, this._bcOffset);
|
||||
factory Weapon(List<int> bytes) {
|
||||
@@ -351,7 +370,8 @@ class Weapon {
|
||||
final fb.BufferContext _bc;
|
||||
final int _bcOffset;
|
||||
|
||||
String? get name => const fb.StringReader().vTableGetNullable(_bc, _bcOffset, 4);
|
||||
String? get name =>
|
||||
const fb.StringReader().vTableGetNullable(_bc, _bcOffset, 4);
|
||||
int get damage => const fb.Int16Reader().vTableGet(_bc, _bcOffset, 6, 0);
|
||||
|
||||
@override
|
||||
@@ -364,8 +384,7 @@ class _WeaponReader extends fb.TableReader<Weapon> {
|
||||
const _WeaponReader();
|
||||
|
||||
@override
|
||||
Weapon createObject(fb.BufferContext bc, int offset) =>
|
||||
Weapon._(bc, offset);
|
||||
Weapon createObject(fb.BufferContext bc, int offset) => Weapon._(bc, offset);
|
||||
}
|
||||
|
||||
class WeaponBuilder {
|
||||
@@ -381,6 +400,7 @@ class WeaponBuilder {
|
||||
fbBuilder.addOffset(0, offset);
|
||||
return fbBuilder.offset;
|
||||
}
|
||||
|
||||
int addDamage(int? damage) {
|
||||
fbBuilder.addInt16(1, damage);
|
||||
return fbBuilder.offset;
|
||||
@@ -395,17 +415,15 @@ class WeaponObjectBuilder extends fb.ObjectBuilder {
|
||||
final String? _name;
|
||||
final int? _damage;
|
||||
|
||||
WeaponObjectBuilder({
|
||||
String? name,
|
||||
int? damage,
|
||||
})
|
||||
: _name = name,
|
||||
_damage = damage;
|
||||
WeaponObjectBuilder({String? name, int? damage})
|
||||
: _name = name,
|
||||
_damage = damage;
|
||||
|
||||
/// Finish building, and store into the [fbBuilder].
|
||||
@override
|
||||
int finish(fb.Builder fbBuilder) {
|
||||
final int? nameOffset = _name == null ? null
|
||||
final int? nameOffset = _name == null
|
||||
? null
|
||||
: fbBuilder.writeString(_name!);
|
||||
fbBuilder.startTable(2);
|
||||
fbBuilder.addOffset(0, nameOffset);
|
||||
|
||||
@@ -27,10 +27,11 @@ class BufferContext {
|
||||
ByteData get buffer => _buffer;
|
||||
|
||||
/// Create from a FlatBuffer represented by a list of bytes (uint8).
|
||||
factory BufferContext.fromBytes(List<int> byteList) =>
|
||||
BufferContext(byteList is Uint8List
|
||||
? byteList.buffer.asByteData(byteList.offsetInBytes)
|
||||
: ByteData.view(Uint8List.fromList(byteList).buffer));
|
||||
factory BufferContext.fromBytes(List<int> byteList) => BufferContext(
|
||||
byteList is Uint8List
|
||||
? byteList.buffer.asByteData(byteList.offsetInBytes)
|
||||
: ByteData.view(Uint8List.fromList(byteList).buffer),
|
||||
);
|
||||
|
||||
/// Create from a FlatBuffer represented by ByteData.
|
||||
BufferContext(this._buffer);
|
||||
@@ -149,9 +150,9 @@ class Builder {
|
||||
bool internStrings = false,
|
||||
Allocator allocator = const DefaultAllocator(),
|
||||
this.deduplicateTables = true,
|
||||
}) : _allocator = allocator,
|
||||
_buf = allocator.allocate(initialSize),
|
||||
_vTables = deduplicateTables ? [] : const [] {
|
||||
}) : _allocator = allocator,
|
||||
_buf = allocator.allocate(initialSize),
|
||||
_vTables = deduplicateTables ? [] : const [] {
|
||||
if (internStrings) {
|
||||
_strings = <String, int>{};
|
||||
}
|
||||
@@ -350,8 +351,10 @@ class Builder {
|
||||
Uint8List get buffer {
|
||||
assert(_finished);
|
||||
final finishedSize = size();
|
||||
return _buf.buffer
|
||||
.asUint8List(_buf.lengthInBytes - finishedSize, finishedSize);
|
||||
return _buf.buffer.asUint8List(
|
||||
_buf.lengthInBytes - finishedSize,
|
||||
finishedSize,
|
||||
);
|
||||
}
|
||||
|
||||
/// Finish off the creation of the buffer. The given [offset] is used as the
|
||||
@@ -368,14 +371,18 @@ class Builder {
|
||||
if (fileIdentifier != null) {
|
||||
for (var i = 0; i < 4; i++) {
|
||||
_setUint8AtTail(
|
||||
finishedSize - _sizeofUint32 - i, fileIdentifier.codeUnitAt(i));
|
||||
finishedSize - _sizeofUint32 - i,
|
||||
fileIdentifier.codeUnitAt(i),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// zero out the added padding
|
||||
for (var i = sizeBeforePadding + 1;
|
||||
i <= finishedSize - requiredBytes;
|
||||
i++) {
|
||||
for (
|
||||
var i = sizeBeforePadding + 1;
|
||||
i <= finishedSize - requiredBytes;
|
||||
i++
|
||||
) {
|
||||
_setUint8AtTail(i, 0);
|
||||
}
|
||||
_finished = true;
|
||||
@@ -386,7 +393,7 @@ class Builder {
|
||||
/// Updates the [offset] pointer. This method is intended for use when writing structs to the buffer.
|
||||
void putFloat64(double value) {
|
||||
_prepare(_sizeofFloat64, 1);
|
||||
_setFloat32AtTail(_tail, value);
|
||||
_setFloat64AtTail(_tail, value);
|
||||
}
|
||||
|
||||
/// Writes a Float32 to the tail of the buffer after preparing space for it.
|
||||
@@ -687,8 +694,10 @@ class Builder {
|
||||
int writeString(String value, {bool asciiOptimization = false}) {
|
||||
assert(!_inVTable);
|
||||
if (_strings != null) {
|
||||
return _strings!
|
||||
.putIfAbsent(value, () => _writeString(value, asciiOptimization));
|
||||
return _strings!.putIfAbsent(
|
||||
value,
|
||||
() => _writeString(value, asciiOptimization),
|
||||
);
|
||||
} else {
|
||||
return _writeString(value, asciiOptimization);
|
||||
}
|
||||
@@ -1005,8 +1014,11 @@ class ListReader<E> extends Reader<List<E>> {
|
||||
: List<E>.generate(
|
||||
bc.buffer.getUint32(listOffset, Endian.little),
|
||||
(int index) => _elementReader.read(
|
||||
bc, listOffset + size + _elementReader.size * index),
|
||||
growable: true);
|
||||
bc,
|
||||
listOffset + size + _elementReader.size * index,
|
||||
),
|
||||
growable: true,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1284,7 +1296,7 @@ class _FbGenericList<E> extends _FbList<E> {
|
||||
List<E?>? _items;
|
||||
|
||||
_FbGenericList(this.elementReader, BufferContext bp, int offset)
|
||||
: super(bp, offset);
|
||||
: super(bp, offset);
|
||||
|
||||
@override
|
||||
@pragma('vm:prefer-inline')
|
||||
@@ -1454,7 +1466,11 @@ abstract class Allocator {
|
||||
/// Params [inUseBack] and [inUseFront] indicate how much of [oldData] is
|
||||
/// actually in use at each end, and needs to be copied.
|
||||
ByteData resize(
|
||||
ByteData oldData, int newSize, int inUseBack, int inUseFront) {
|
||||
ByteData oldData,
|
||||
int newSize,
|
||||
int inUseBack,
|
||||
int inUseFront,
|
||||
) {
|
||||
final newData = allocate(newSize);
|
||||
_copyDownward(oldData, newData, inUseBack, inUseFront);
|
||||
deallocate(oldData);
|
||||
@@ -1465,17 +1481,25 @@ abstract class Allocator {
|
||||
/// memory of size [inUseFront] and [inUseBack] will be copied from the front
|
||||
/// and back of the old memory allocation.
|
||||
void _copyDownward(
|
||||
ByteData oldData, ByteData newData, int inUseBack, int inUseFront) {
|
||||
ByteData oldData,
|
||||
ByteData newData,
|
||||
int inUseBack,
|
||||
int inUseFront,
|
||||
) {
|
||||
if (inUseBack != 0) {
|
||||
newData.buffer.asUint8List().setAll(
|
||||
newData.lengthInBytes - inUseBack,
|
||||
oldData.buffer.asUint8List().getRange(
|
||||
oldData.lengthInBytes - inUseBack, oldData.lengthInBytes));
|
||||
newData.lengthInBytes - inUseBack,
|
||||
oldData.buffer.asUint8List().getRange(
|
||||
oldData.lengthInBytes - inUseBack,
|
||||
oldData.lengthInBytes,
|
||||
),
|
||||
);
|
||||
}
|
||||
if (inUseFront != 0) {
|
||||
newData.buffer
|
||||
.asUint8List()
|
||||
.setAll(0, oldData.buffer.asUint8List().getRange(0, inUseFront));
|
||||
newData.buffer.asUint8List().setAll(
|
||||
0,
|
||||
oldData.buffer.asUint8List().getRange(0, inUseFront),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ import 'types.dart';
|
||||
|
||||
/// The main builder class for creation of a FlexBuffer.
|
||||
class Builder {
|
||||
final ByteData _buffer;
|
||||
ByteData _buffer;
|
||||
List<_StackValue> _stack = [];
|
||||
List<_StackPointer> _stackPointers = [];
|
||||
int _offset = 0;
|
||||
@@ -107,8 +107,11 @@ class Builder {
|
||||
final newOffset = _newOffset(length + 1);
|
||||
_pushBuffer(utf8String);
|
||||
_offset = newOffset;
|
||||
final stackValue =
|
||||
_StackValue.withOffset(stringOffset, ValueType.String, bitWidth);
|
||||
final stackValue = _StackValue.withOffset(
|
||||
stringOffset,
|
||||
ValueType.String,
|
||||
bitWidth,
|
||||
);
|
||||
_stack.add(stackValue);
|
||||
_stringCache[value] = stackValue;
|
||||
}
|
||||
@@ -128,8 +131,11 @@ class Builder {
|
||||
final newOffset = _newOffset(length + 1);
|
||||
_pushBuffer(utf8String);
|
||||
_offset = newOffset;
|
||||
final stackValue =
|
||||
_StackValue.withOffset(keyOffset, ValueType.Key, BitWidth.width8);
|
||||
final stackValue = _StackValue.withOffset(
|
||||
keyOffset,
|
||||
ValueType.Key,
|
||||
BitWidth.width8,
|
||||
);
|
||||
_stack.add(stackValue);
|
||||
_keyCache[value] = stackValue;
|
||||
}
|
||||
@@ -147,8 +153,11 @@ class Builder {
|
||||
final newOffset = _newOffset(length);
|
||||
_pushBuffer(value.asUint8List());
|
||||
_offset = newOffset;
|
||||
final stackValue =
|
||||
_StackValue.withOffset(blobOffset, ValueType.Blob, bitWidth);
|
||||
final stackValue = _StackValue.withOffset(
|
||||
blobOffset,
|
||||
ValueType.Blob,
|
||||
bitWidth,
|
||||
);
|
||||
_stack.add(stackValue);
|
||||
}
|
||||
|
||||
@@ -170,7 +179,10 @@ class Builder {
|
||||
final valueOffset = _offset;
|
||||
_pushBuffer(stackValue.asU8List(stackValue.width));
|
||||
final stackOffset = _StackValue.withOffset(
|
||||
valueOffset, ValueType.IndirectInt, stackValue.width);
|
||||
valueOffset,
|
||||
ValueType.IndirectInt,
|
||||
stackValue.width,
|
||||
);
|
||||
_stack.add(stackOffset);
|
||||
_offset = newOffset;
|
||||
if (cache) {
|
||||
@@ -195,7 +207,10 @@ class Builder {
|
||||
final valueOffset = _offset;
|
||||
_pushBuffer(stackValue.asU8List(stackValue.width));
|
||||
final stackOffset = _StackValue.withOffset(
|
||||
valueOffset, ValueType.IndirectFloat, stackValue.width);
|
||||
valueOffset,
|
||||
ValueType.IndirectFloat,
|
||||
stackValue.width,
|
||||
);
|
||||
_stack.add(stackOffset);
|
||||
_offset = newOffset;
|
||||
if (cache) {
|
||||
@@ -252,9 +267,10 @@ class Builder {
|
||||
tmp._offset = _offset;
|
||||
tmp._stack = List.from(_stack);
|
||||
tmp._stackPointers = List.from(_stackPointers);
|
||||
tmp._buffer.buffer
|
||||
.asUint8List()
|
||||
.setAll(0, _buffer.buffer.asUint8List(0, _offset));
|
||||
tmp._buffer.buffer.asUint8List().setAll(
|
||||
0,
|
||||
_buffer.buffer.asUint8List(0, _offset),
|
||||
);
|
||||
for (var i = 0; i < tmp._stackPointers.length; i++) {
|
||||
tmp.end();
|
||||
}
|
||||
@@ -271,7 +287,8 @@ class Builder {
|
||||
if (_stackPointers.isNotEmpty && _stackPointers.last.isVector == false) {
|
||||
if (_stack.last.type != ValueType.Key) {
|
||||
throw StateError(
|
||||
'Adding value to a map before adding a key is prohibited');
|
||||
'Adding value to a map before adding a key is prohibited',
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -288,7 +305,8 @@ class Builder {
|
||||
void _finish() {
|
||||
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]');
|
||||
'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 byteWidth = _align(value.elementWidth(_offset, 0));
|
||||
@@ -298,8 +316,12 @@ class Builder {
|
||||
_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 prefixElements = 1;
|
||||
if (keys != null) {
|
||||
@@ -326,7 +348,8 @@ class Builder {
|
||||
}
|
||||
}
|
||||
final byteWidth = _align(bitWidth);
|
||||
final fix = typed & ValueTypeUtils.isNumber(vectorType) &&
|
||||
final fix =
|
||||
typed & ValueTypeUtils.isNumber(vectorType) &&
|
||||
vecLength >= 2 &&
|
||||
vecLength <= 4;
|
||||
if (keys != null) {
|
||||
@@ -349,8 +372,10 @@ class Builder {
|
||||
return _StackValue.withOffset(vecOffset, ValueType.Map, bitWidth);
|
||||
}
|
||||
if (typed) {
|
||||
final vType =
|
||||
ValueTypeUtils.toTypedVector(vectorType, fix ? vecLength : 0);
|
||||
final vType = ValueTypeUtils.toTypedVector(
|
||||
vectorType,
|
||||
fix ? vecLength : 0,
|
||||
);
|
||||
return _StackValue.withOffset(vecOffset, vType, bitWidth);
|
||||
}
|
||||
return _StackValue.withOffset(vecOffset, ValueType.Vector, bitWidth);
|
||||
@@ -366,7 +391,8 @@ class Builder {
|
||||
void _sortKeysAndEndMap(_StackPointer pointer) {
|
||||
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.');
|
||||
'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;
|
||||
@@ -412,8 +438,12 @@ class Builder {
|
||||
keysStackValue = _createVector(pointer.stackPosition, vecLength, 2);
|
||||
_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.add(vec);
|
||||
}
|
||||
@@ -421,7 +451,8 @@ class Builder {
|
||||
bool _shouldFlip(_StackValue v1, _StackValue v2) {
|
||||
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.');
|
||||
'Stack values are not keys $v1 | $v2. Check if you combined [addKey] with add... method calls properly.',
|
||||
);
|
||||
}
|
||||
|
||||
late int c1, c2;
|
||||
@@ -450,7 +481,8 @@ class Builder {
|
||||
_writeUInt(relativeOffset, byteWidth);
|
||||
} else {
|
||||
throw StateError(
|
||||
'Unexpected size $byteWidth. This might be a bug. Please create an issue https://github.com/google/flatbuffers/issues/new');
|
||||
'Unexpected size $byteWidth. This might be a bug. Please create an issue https://github.com/google/flatbuffers/issues/new',
|
||||
);
|
||||
}
|
||||
} else {
|
||||
_pushBuffer(value.asU8List(BitWidthUtil.fromByteWidth(byteWidth)));
|
||||
@@ -474,6 +506,7 @@ class Builder {
|
||||
if (prevSize < size) {
|
||||
final newBuf = ByteData(size);
|
||||
newBuf.buffer.asUint8List().setAll(0, _buffer.buffer.asUint8List());
|
||||
_buffer = newBuf;
|
||||
}
|
||||
return newOffset;
|
||||
}
|
||||
@@ -523,29 +556,27 @@ class _StackValue {
|
||||
final ValueType _type;
|
||||
final BitWidth _width;
|
||||
|
||||
_StackValue.withNull()
|
||||
: _type = ValueType.Null,
|
||||
_width = BitWidth.width8;
|
||||
_StackValue.withNull() : _type = ValueType.Null, _width = BitWidth.width8;
|
||||
|
||||
_StackValue.withInt(int value)
|
||||
: _type = ValueType.Int,
|
||||
_width = BitWidthUtil.width(value),
|
||||
_value = value;
|
||||
: _type = ValueType.Int,
|
||||
_width = BitWidthUtil.width(value),
|
||||
_value = value;
|
||||
|
||||
_StackValue.withBool(bool value)
|
||||
: _type = ValueType.Bool,
|
||||
_width = BitWidth.width8,
|
||||
_value = value;
|
||||
: _type = ValueType.Bool,
|
||||
_width = BitWidth.width8,
|
||||
_value = value;
|
||||
|
||||
_StackValue.withDouble(double value)
|
||||
: _type = ValueType.Float,
|
||||
_width = BitWidthUtil.width(value),
|
||||
_value = value;
|
||||
: _type = ValueType.Float,
|
||||
_width = BitWidthUtil.width(value),
|
||||
_value = value;
|
||||
|
||||
_StackValue.withOffset(int value, ValueType type, BitWidth width)
|
||||
: _offset = value,
|
||||
_type = type,
|
||||
_width = width;
|
||||
: _offset = value,
|
||||
_type = type,
|
||||
_width = width;
|
||||
|
||||
BitWidth storedWidth({BitWidth width = BitWidth.width8}) {
|
||||
return ValueTypeUtils.isInline(_type)
|
||||
@@ -562,16 +593,16 @@ class _StackValue {
|
||||
final offset = _offset!;
|
||||
for (var i = 0; i < 4; i++) {
|
||||
final width = 1 << i;
|
||||
final bitWidth = BitWidthUtil.uwidth(size +
|
||||
BitWidthUtil.paddingSize(size, width) +
|
||||
index * width -
|
||||
offset);
|
||||
final bitWidth = BitWidthUtil.uwidth(
|
||||
size + BitWidthUtil.paddingSize(size, width) + index * width - offset,
|
||||
);
|
||||
if (1 << bitWidth.index == width) {
|
||||
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');
|
||||
'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) {
|
||||
@@ -619,7 +650,8 @@ class _StackValue {
|
||||
}
|
||||
|
||||
throw StateError(
|
||||
'Unexpected type: $_type. This might be a bug. Please create an issue https://github.com/google/flatbuffers/issues/new');
|
||||
'Unexpected type: $_type. This might be a bug. Please create an issue https://github.com/google/flatbuffers/issues/new',
|
||||
);
|
||||
}
|
||||
|
||||
ValueType get type {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import 'dart:collection';
|
||||
import 'dart:convert';
|
||||
import 'dart:typed_data';
|
||||
|
||||
import 'types.dart';
|
||||
|
||||
/// Main class to read a value out of a FlexBuffer.
|
||||
@@ -16,10 +17,15 @@ class Reference {
|
||||
int? _length;
|
||||
|
||||
Reference._(
|
||||
this._buffer, this._offset, this._parentWidth, int packedType, this._path,
|
||||
[int? byteWidth, ValueType? valueType])
|
||||
: _byteWidth = byteWidth ?? 1 << (packedType & 3),
|
||||
_valueType = valueType ?? ValueTypeUtils.fromInt(packedType >> 2);
|
||||
this._buffer,
|
||||
this._offset,
|
||||
this._parentWidth,
|
||||
int packedType,
|
||||
this._path, [
|
||||
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.
|
||||
static Reference fromBuffer(ByteBuffer buffer) {
|
||||
@@ -31,8 +37,13 @@ class Reference {
|
||||
final byteWidth = byteData.getUint8(len - 1);
|
||||
final packedType = byteData.getUint8(len - 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.
|
||||
@@ -138,7 +149,8 @@ class Reference {
|
||||
final index = key;
|
||||
if (index >= length || index < 0) {
|
||||
throw ArgumentError(
|
||||
'Key: [$key] is not applicable on: $_path of: $_valueType length: $length');
|
||||
'Key: [$key] is not applicable on: $_path of: $_valueType length: $length',
|
||||
);
|
||||
}
|
||||
final elementOffset = _indirect + index * _byteWidth;
|
||||
int packedType = 0;
|
||||
@@ -154,13 +166,14 @@ class Reference {
|
||||
packedType = _buffer.getUint8(_indirect + length * _byteWidth + index);
|
||||
}
|
||||
return Reference._(
|
||||
_buffer,
|
||||
elementOffset,
|
||||
BitWidthUtil.fromByteWidth(_byteWidth),
|
||||
packedType,
|
||||
"$_path[$index]",
|
||||
byteWidth,
|
||||
valueType);
|
||||
_buffer,
|
||||
elementOffset,
|
||||
BitWidthUtil.fromByteWidth(_byteWidth),
|
||||
packedType,
|
||||
"$_path[$index]",
|
||||
byteWidth,
|
||||
valueType,
|
||||
);
|
||||
}
|
||||
if (key is String && _valueType == ValueType.Map) {
|
||||
final index = _keyIndex(key);
|
||||
@@ -169,7 +182,8 @@ class Reference {
|
||||
}
|
||||
}
|
||||
throw ArgumentError(
|
||||
'Key: [$key] is not applicable on: $_path of: $_valueType');
|
||||
'Key: [$key] is not applicable on: $_path of: $_valueType',
|
||||
);
|
||||
}
|
||||
|
||||
/// Get an iterable if the underlying flexBuffer value is a vector.
|
||||
@@ -213,18 +227,24 @@ class Reference {
|
||||
ValueTypeUtils.isAVector(_valueType) ||
|
||||
_valueType == ValueType.Map) {
|
||||
_length = _readUInt(
|
||||
_indirect - _byteWidth, BitWidthUtil.fromByteWidth(_byteWidth));
|
||||
_indirect - _byteWidth,
|
||||
BitWidthUtil.fromByteWidth(_byteWidth),
|
||||
);
|
||||
} else if (_valueType == ValueType.Null) {
|
||||
_length = 0;
|
||||
} else if (_valueType == ValueType.String) {
|
||||
final indirect = _indirect;
|
||||
var sizeByteWidth = _byteWidth;
|
||||
var size = _readUInt(indirect - sizeByteWidth,
|
||||
BitWidthUtil.fromByteWidth(sizeByteWidth));
|
||||
var size = _readUInt(
|
||||
indirect - sizeByteWidth,
|
||||
BitWidthUtil.fromByteWidth(sizeByteWidth),
|
||||
);
|
||||
while (_buffer.getInt8(indirect + size) != 0) {
|
||||
sizeByteWidth <<= 1;
|
||||
size = _readUInt(indirect - sizeByteWidth,
|
||||
BitWidthUtil.fromByteWidth(sizeByteWidth));
|
||||
size = _readUInt(
|
||||
indirect - sizeByteWidth,
|
||||
BitWidthUtil.fromByteWidth(sizeByteWidth),
|
||||
);
|
||||
}
|
||||
_length = size;
|
||||
} else if (_valueType == ValueType.Key) {
|
||||
@@ -289,7 +309,8 @@ class Reference {
|
||||
return result.toString();
|
||||
}
|
||||
throw UnsupportedError(
|
||||
'Type: $_valueType is not supported for JSON conversion');
|
||||
'Type: $_valueType is not supported for JSON conversion',
|
||||
);
|
||||
}
|
||||
|
||||
/// Computes the indirect offset of the value.
|
||||
@@ -354,10 +375,13 @@ class Reference {
|
||||
int? _keyIndex(String key) {
|
||||
final input = utf8.encode(key);
|
||||
final keysVectorOffset = _indirect - _byteWidth * 3;
|
||||
final indirectOffset = keysVectorOffset -
|
||||
final indirectOffset =
|
||||
keysVectorOffset -
|
||||
_readUInt(keysVectorOffset, BitWidthUtil.fromByteWidth(_byteWidth));
|
||||
final byteWidth = _readUInt(
|
||||
keysVectorOffset + _byteWidth, BitWidthUtil.fromByteWidth(_byteWidth));
|
||||
keysVectorOffset + _byteWidth,
|
||||
BitWidthUtil.fromByteWidth(_byteWidth),
|
||||
);
|
||||
var low = 0;
|
||||
var high = length - 1;
|
||||
while (low <= high) {
|
||||
@@ -390,24 +414,37 @@ class Reference {
|
||||
final indirect = _indirect;
|
||||
final elementOffset = indirect + index * _byteWidth;
|
||||
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) {
|
||||
final indirect = _indirect;
|
||||
final elementOffset = indirect + index * _byteWidth;
|
||||
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) {
|
||||
final keysVectorOffset = _indirect - _byteWidth * 3;
|
||||
final indirectOffset = keysVectorOffset -
|
||||
final indirectOffset =
|
||||
keysVectorOffset -
|
||||
_readUInt(keysVectorOffset, BitWidthUtil.fromByteWidth(_byteWidth));
|
||||
final byteWidth = _readUInt(
|
||||
keysVectorOffset + _byteWidth, BitWidthUtil.fromByteWidth(_byteWidth));
|
||||
keysVectorOffset + _byteWidth,
|
||||
BitWidthUtil.fromByteWidth(_byteWidth),
|
||||
);
|
||||
final keyOffset = indirectOffset + index * byteWidth;
|
||||
final keyIndirectOffset =
|
||||
keyOffset - _readUInt(keyOffset, BitWidthUtil.fromByteWidth(byteWidth));
|
||||
|
||||
@@ -86,7 +86,8 @@ enum ValueType {
|
||||
VectorFloat,
|
||||
VectorKey,
|
||||
@Deprecated(
|
||||
'VectorString is deprecated due to a flaw in the binary format (https://github.com/google/flatbuffers/issues/5627)')
|
||||
'VectorString is deprecated due to a flaw in the binary format (https://github.com/google/flatbuffers/issues/5627)',
|
||||
)
|
||||
VectorString,
|
||||
VectorInt2,
|
||||
VectorUInt2,
|
||||
@@ -99,7 +100,7 @@ enum ValueType {
|
||||
VectorFloat4,
|
||||
Blob,
|
||||
Bool,
|
||||
VectorBool
|
||||
VectorBool,
|
||||
}
|
||||
|
||||
class ValueTypeUtils {
|
||||
@@ -153,31 +154,37 @@ class ValueTypeUtils {
|
||||
static ValueType toTypedVector(ValueType self, int length) {
|
||||
if (length == 0) {
|
||||
return ValueTypeUtils.fromInt(
|
||||
toInt(self) - toInt(ValueType.Int) + toInt(ValueType.VectorInt));
|
||||
toInt(self) - toInt(ValueType.Int) + toInt(ValueType.VectorInt),
|
||||
);
|
||||
}
|
||||
if (length == 2) {
|
||||
return ValueTypeUtils.fromInt(
|
||||
toInt(self) - toInt(ValueType.Int) + toInt(ValueType.VectorInt2));
|
||||
toInt(self) - toInt(ValueType.Int) + toInt(ValueType.VectorInt2),
|
||||
);
|
||||
}
|
||||
if (length == 3) {
|
||||
return ValueTypeUtils.fromInt(
|
||||
toInt(self) - toInt(ValueType.Int) + toInt(ValueType.VectorInt3));
|
||||
toInt(self) - toInt(ValueType.Int) + toInt(ValueType.VectorInt3),
|
||||
);
|
||||
}
|
||||
if (length == 4) {
|
||||
return ValueTypeUtils.fromInt(
|
||||
toInt(self) - toInt(ValueType.Int) + toInt(ValueType.VectorInt4));
|
||||
toInt(self) - toInt(ValueType.Int) + toInt(ValueType.VectorInt4),
|
||||
);
|
||||
}
|
||||
throw Exception('unexpected length ' + length.toString());
|
||||
}
|
||||
|
||||
static ValueType typedVectorElementType(ValueType self) {
|
||||
return ValueTypeUtils.fromInt(
|
||||
toInt(self) - toInt(ValueType.VectorInt) + toInt(ValueType.Int));
|
||||
toInt(self) - toInt(ValueType.VectorInt) + toInt(ValueType.Int),
|
||||
);
|
||||
}
|
||||
|
||||
static ValueType fixedTypedVectorElementType(ValueType self) {
|
||||
return ValueTypeUtils.fromInt(
|
||||
(toInt(self) - toInt(ValueType.VectorInt2)) % 3 + toInt(ValueType.Int));
|
||||
(toInt(self) - toInt(ValueType.VectorInt2)) % 3 + toInt(ValueType.Int),
|
||||
);
|
||||
}
|
||||
|
||||
static int fixedTypedVectorElementSize(ValueType self) {
|
||||
|
||||
@@ -1,15 +1,14 @@
|
||||
name: flat_buffers
|
||||
version: 23.5.26
|
||||
version: 25.12.19
|
||||
description: FlatBuffers reading and writing library for Dart. Based on original work by Konstantin Scheglov and Paul Berry of the Dart SDK team.
|
||||
homepage: https://github.com/google/flatbuffers
|
||||
documentation: https://google.github.io/flatbuffers/index.html
|
||||
|
||||
environment:
|
||||
sdk: '>=2.12.0 <3.0.0'
|
||||
sdk: '>=2.17.0 <4.0.0'
|
||||
|
||||
dev_dependencies:
|
||||
test: ^1.17.7
|
||||
test_reflective_loader: ^0.2.0
|
||||
path: ^1.8.0
|
||||
lints: ^1.0.1
|
||||
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
// automatically generated by the FlatBuffers compiler, do not modify
|
||||
// ignore_for_file: unused_import, unused_field, unused_element, unused_local_variable
|
||||
// ignore_for_file: unused_import, unused_field, unused_element, unused_local_variable, constant_identifier_names
|
||||
|
||||
import 'dart:typed_data' show Uint8List;
|
||||
import 'package:flat_buffers/flat_buffers.dart' as fb;
|
||||
|
||||
import 'package:flat_buffers/flat_buffers.dart' as fb;
|
||||
|
||||
class Foo {
|
||||
Foo._(this._bc, this._bcOffset);
|
||||
@@ -17,15 +17,15 @@ class Foo {
|
||||
final fb.BufferContext _bc;
|
||||
final int _bcOffset;
|
||||
|
||||
FooProperties? get myFoo => FooProperties.reader.vTableGetNullable(_bc, _bcOffset, 4);
|
||||
FooProperties? get myFoo =>
|
||||
FooProperties.reader.vTableGetNullable(_bc, _bcOffset, 4);
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return 'Foo{myFoo: ${myFoo}}';
|
||||
}
|
||||
|
||||
FooT unpack() => FooT(
|
||||
myFoo: myFoo?.unpack());
|
||||
FooT unpack() => FooT(myFoo: myFoo?.unpack());
|
||||
|
||||
static int pack(fb.Builder fbBuilder, FooT? object) {
|
||||
if (object == null) return 0;
|
||||
@@ -36,8 +36,7 @@ class Foo {
|
||||
class FooT implements fb.Packable {
|
||||
FooPropertiesT? myFoo;
|
||||
|
||||
FooT({
|
||||
this.myFoo});
|
||||
FooT({this.myFoo});
|
||||
|
||||
@override
|
||||
int pack(fb.Builder fbBuilder) {
|
||||
@@ -58,8 +57,7 @@ class _FooReader extends fb.TableReader<Foo> {
|
||||
const _FooReader();
|
||||
|
||||
@override
|
||||
Foo createObject(fb.BufferContext bc, int offset) =>
|
||||
Foo._(bc, offset);
|
||||
Foo createObject(fb.BufferContext bc, int offset) => Foo._(bc, offset);
|
||||
}
|
||||
|
||||
class FooBuilder {
|
||||
@@ -84,10 +82,7 @@ class FooBuilder {
|
||||
class FooObjectBuilder extends fb.ObjectBuilder {
|
||||
final FooPropertiesObjectBuilder? _myFoo;
|
||||
|
||||
FooObjectBuilder({
|
||||
FooPropertiesObjectBuilder? myFoo,
|
||||
})
|
||||
: _myFoo = myFoo;
|
||||
FooObjectBuilder({FooPropertiesObjectBuilder? myFoo}) : _myFoo = myFoo;
|
||||
|
||||
/// Finish building, and store into the [fbBuilder].
|
||||
@override
|
||||
@@ -107,6 +102,7 @@ class FooObjectBuilder extends fb.ObjectBuilder {
|
||||
return fbBuilder.buffer;
|
||||
}
|
||||
}
|
||||
|
||||
class FooProperties {
|
||||
FooProperties._(this._bc, this._bcOffset);
|
||||
|
||||
@@ -123,9 +119,7 @@ class FooProperties {
|
||||
return 'FooProperties{a: ${a}, b: ${b}}';
|
||||
}
|
||||
|
||||
FooPropertiesT unpack() => FooPropertiesT(
|
||||
a: a,
|
||||
b: b);
|
||||
FooPropertiesT unpack() => FooPropertiesT(a: a, b: b);
|
||||
|
||||
static int pack(fb.Builder fbBuilder, FooPropertiesT? object) {
|
||||
if (object == null) return 0;
|
||||
@@ -137,9 +131,7 @@ class FooPropertiesT implements fb.Packable {
|
||||
bool a;
|
||||
bool b;
|
||||
|
||||
FooPropertiesT({
|
||||
required this.a,
|
||||
required this.b});
|
||||
FooPropertiesT({required this.a, required this.b});
|
||||
|
||||
@override
|
||||
int pack(fb.Builder fbBuilder) {
|
||||
@@ -161,8 +153,8 @@ class _FooPropertiesReader extends fb.StructReader<FooProperties> {
|
||||
int get size => 2;
|
||||
|
||||
@override
|
||||
FooProperties createObject(fb.BufferContext bc, int offset) =>
|
||||
FooProperties._(bc, offset);
|
||||
FooProperties createObject(fb.BufferContext bc, int offset) =>
|
||||
FooProperties._(bc, offset);
|
||||
}
|
||||
|
||||
class FooPropertiesBuilder {
|
||||
@@ -175,19 +167,15 @@ class FooPropertiesBuilder {
|
||||
fbBuilder.putBool(a);
|
||||
return fbBuilder.offset;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class FooPropertiesObjectBuilder extends fb.ObjectBuilder {
|
||||
final bool _a;
|
||||
final bool _b;
|
||||
|
||||
FooPropertiesObjectBuilder({
|
||||
required bool a,
|
||||
required bool b,
|
||||
})
|
||||
: _a = a,
|
||||
_b = b;
|
||||
FooPropertiesObjectBuilder({required bool a, required bool b})
|
||||
: _a = a,
|
||||
_b = b;
|
||||
|
||||
/// Finish building, and store into the [fbBuilder].
|
||||
@override
|
||||
|
||||
@@ -1,43 +1,37 @@
|
||||
// automatically generated by the FlatBuffers compiler, do not modify
|
||||
// ignore_for_file: unused_import, unused_field, unused_element, unused_local_variable
|
||||
// ignore_for_file: unused_import, unused_field, unused_element, unused_local_variable, constant_identifier_names
|
||||
|
||||
import 'dart:typed_data' show Uint8List;
|
||||
|
||||
import 'package:flat_buffers/flat_buffers.dart' as fb;
|
||||
|
||||
enum OptionsEnum {
|
||||
A(1),
|
||||
B(2),
|
||||
C(3);
|
||||
|
||||
class OptionsEnum {
|
||||
final int value;
|
||||
const OptionsEnum._(this.value);
|
||||
const OptionsEnum(this.value);
|
||||
|
||||
factory OptionsEnum.fromValue(int value) {
|
||||
final result = values[value];
|
||||
if (result == null) {
|
||||
throw StateError('Invalid value $value for bit flag enum OptionsEnum');
|
||||
switch (value) {
|
||||
case 1:
|
||||
return OptionsEnum.A;
|
||||
case 2:
|
||||
return OptionsEnum.B;
|
||||
case 3:
|
||||
return OptionsEnum.C;
|
||||
default:
|
||||
throw StateError('Invalid value $value for bit flag enum');
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
static OptionsEnum? _createOrNull(int? value) =>
|
||||
static OptionsEnum? _createOrNull(int? value) =>
|
||||
value == null ? null : OptionsEnum.fromValue(value);
|
||||
|
||||
static const int minValue = 1;
|
||||
static const int maxValue = 3;
|
||||
static bool containsValue(int value) => values.containsKey(value);
|
||||
|
||||
static const OptionsEnum A = OptionsEnum._(1);
|
||||
static const OptionsEnum B = OptionsEnum._(2);
|
||||
static const OptionsEnum C = OptionsEnum._(3);
|
||||
static const Map<int, OptionsEnum> values = {
|
||||
1: A,
|
||||
2: B,
|
||||
3: C};
|
||||
|
||||
static const fb.Reader<OptionsEnum> reader = _OptionsEnumReader();
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return 'OptionsEnum{value: $value}';
|
||||
}
|
||||
}
|
||||
|
||||
class _OptionsEnumReader extends fb.Reader<OptionsEnum> {
|
||||
@@ -63,7 +57,9 @@ class MyTable {
|
||||
final fb.BufferContext _bc;
|
||||
final int _bcOffset;
|
||||
|
||||
List<OptionsEnum>? get options => const fb.ListReader<OptionsEnum>(OptionsEnum.reader).vTableGetNullable(_bc, _bcOffset, 4);
|
||||
List<OptionsEnum>? get options => const fb.ListReader<OptionsEnum>(
|
||||
OptionsEnum.reader,
|
||||
).vTableGetNullable(_bc, _bcOffset, 4);
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
@@ -71,7 +67,11 @@ class MyTable {
|
||||
}
|
||||
|
||||
MyTableT unpack() => MyTableT(
|
||||
options: const fb.ListReader<OptionsEnum>(OptionsEnum.reader, lazy: false).vTableGetNullable(_bc, _bcOffset, 4));
|
||||
options: const fb.ListReader<OptionsEnum>(
|
||||
OptionsEnum.reader,
|
||||
lazy: false,
|
||||
).vTableGetNullable(_bc, _bcOffset, 4),
|
||||
);
|
||||
|
||||
static int pack(fb.Builder fbBuilder, MyTableT? object) {
|
||||
if (object == null) return 0;
|
||||
@@ -82,12 +82,12 @@ class MyTable {
|
||||
class MyTableT implements fb.Packable {
|
||||
List<OptionsEnum>? options;
|
||||
|
||||
MyTableT({
|
||||
this.options});
|
||||
MyTableT({this.options});
|
||||
|
||||
@override
|
||||
int pack(fb.Builder fbBuilder) {
|
||||
final int? optionsOffset = options == null ? null
|
||||
final int? optionsOffset = options == null
|
||||
? null
|
||||
: fbBuilder.writeListUint32(options!.map((f) => f.value).toList());
|
||||
fbBuilder.startTable(1);
|
||||
fbBuilder.addOffset(0, optionsOffset);
|
||||
@@ -104,8 +104,8 @@ class _MyTableReader extends fb.TableReader<MyTable> {
|
||||
const _MyTableReader();
|
||||
|
||||
@override
|
||||
MyTable createObject(fb.BufferContext bc, int offset) =>
|
||||
MyTable._(bc, offset);
|
||||
MyTable createObject(fb.BufferContext bc, int offset) =>
|
||||
MyTable._(bc, offset);
|
||||
}
|
||||
|
||||
class MyTableBuilder {
|
||||
@@ -130,15 +130,13 @@ class MyTableBuilder {
|
||||
class MyTableObjectBuilder extends fb.ObjectBuilder {
|
||||
final List<OptionsEnum>? _options;
|
||||
|
||||
MyTableObjectBuilder({
|
||||
List<OptionsEnum>? options,
|
||||
})
|
||||
: _options = options;
|
||||
MyTableObjectBuilder({List<OptionsEnum>? options}) : _options = options;
|
||||
|
||||
/// Finish building, and store into the [fbBuilder].
|
||||
@override
|
||||
int finish(fb.Builder fbBuilder) {
|
||||
final int? optionsOffset = _options == null ? null
|
||||
final int? optionsOffset = _options == null
|
||||
? null
|
||||
: fbBuilder.writeListUint32(_options!.map((f) => f.value).toList());
|
||||
fbBuilder.startTable(1);
|
||||
fbBuilder.addOffset(0, optionsOffset);
|
||||
@@ -1,17 +1,15 @@
|
||||
import 'dart:typed_data';
|
||||
import 'dart:io' as io;
|
||||
|
||||
import 'package:path/path.dart' as path;
|
||||
import 'dart:typed_data';
|
||||
|
||||
import 'package:flat_buffers/flat_buffers.dart';
|
||||
import 'package:path/path.dart' as path;
|
||||
import 'package:test/test.dart';
|
||||
import 'package:test_reflective_loader/test_reflective_loader.dart';
|
||||
|
||||
import './monster_test_my_game.example_generated.dart' as example;
|
||||
import './monster_test_my_game.example2_generated.dart' as example2;
|
||||
import './list_of_enums_generated.dart' as example3;
|
||||
import './bool_structs_generated.dart' as example4;
|
||||
import './keyword_test_keyword_test_generated.dart' as keyword_test;
|
||||
import './monster_test_my_game.example2_generated.dart' as example2;
|
||||
import './monster_test_my_game.example_generated.dart' as example;
|
||||
import 'enums_generated.dart' as example3;
|
||||
|
||||
main() {
|
||||
defineReflectiveSuite(() {
|
||||
@@ -30,11 +28,9 @@ int indexToField(int index) {
|
||||
@reflectiveTest
|
||||
class CheckOtherLangaugesData {
|
||||
test_cppData() async {
|
||||
List<int> data = await io.File(path.join(
|
||||
path.context.current,
|
||||
'test',
|
||||
'monsterdata_test.mon',
|
||||
)).readAsBytes();
|
||||
List<int> data = await io.File(
|
||||
path.join(path.context.current, 'test', 'monsterdata_test.mon'),
|
||||
).readAsBytes();
|
||||
example.Monster mon = example.Monster(data);
|
||||
expect(mon.hp, 80);
|
||||
expect(mon.mana, 150);
|
||||
@@ -64,11 +60,11 @@ class CheckOtherLangaugesData {
|
||||
expect(
|
||||
mon.toString(),
|
||||
'Monster{'
|
||||
'pos: Vec3{x: 1.0, y: 2.0, z: 3.0, test1: 3.0, test2: Color{value: 2}, test3: Test{a: 5, b: 6}}, '
|
||||
'pos: Vec3{x: 1.0, y: 2.0, z: 3.0, test1: 3.0, test2: Color.Green, test3: Test{a: 5, b: 6}}, '
|
||||
'mana: 150, hp: 80, name: MyMonster, inventory: [0, 1, 2, 3, 4], '
|
||||
'color: Color{value: 8}, testType: AnyTypeId{value: 1}, '
|
||||
'color: Color.Blue, testType: AnyTypeId.Monster, '
|
||||
'test: Monster{pos: null, mana: 150, hp: 100, name: Fred, '
|
||||
'inventory: null, color: Color{value: 8}, testType: null, '
|
||||
'inventory: null, color: Color.Blue, testType: null, '
|
||||
'test: null, test4: null, testarrayofstring: null, '
|
||||
'testarrayoftables: null, enemy: null, testnestedflatbuffer: null, '
|
||||
'testempty: null, testbool: false, testhashs32Fnv1: 0, '
|
||||
@@ -83,18 +79,18 @@ class CheckOtherLangaugesData {
|
||||
'coOwningReference: 0, vectorOfCoOwningReferences: null, '
|
||||
'nonOwningReference: 0, vectorOfNonOwningReferences: null, '
|
||||
'anyUniqueType: null, anyUnique: null, anyAmbiguousType: null, '
|
||||
'anyAmbiguous: null, vectorOfEnums: null, signedEnum: Race{value: -1}, '
|
||||
'anyAmbiguous: null, vectorOfEnums: null, signedEnum: Race.None, '
|
||||
'testrequirednestedflatbuffer: null, scalarKeySortedTables: null, '
|
||||
'nativeInline: null, '
|
||||
'longEnumNonEnumDefault: LongEnum{value: 0}, '
|
||||
'longEnumNormalDefault: LongEnum{value: 2}, nanDefault: NaN, '
|
||||
'longEnumNonEnumDefault: LongEnum._default, '
|
||||
'longEnumNormalDefault: LongEnum.LongOne, nanDefault: NaN, '
|
||||
'infDefault: Infinity, positiveInfDefault: Infinity, infinityDefault: '
|
||||
'Infinity, positiveInfinityDefault: Infinity, negativeInfDefault: '
|
||||
'-Infinity, negativeInfinityDefault: -Infinity, doubleInfDefault: Infinity}, '
|
||||
'test4: [Test{a: 10, b: 20}, Test{a: 30, b: 40}], '
|
||||
'testarrayofstring: [test1, test2], testarrayoftables: null, '
|
||||
'enemy: Monster{pos: null, mana: 150, hp: 100, name: Fred, '
|
||||
'inventory: null, color: Color{value: 8}, testType: null, '
|
||||
'inventory: null, color: Color.Blue, testType: null, '
|
||||
'test: null, test4: null, testarrayofstring: null, '
|
||||
'testarrayoftables: null, enemy: null, testnestedflatbuffer: null, '
|
||||
'testempty: null, testbool: false, testhashs32Fnv1: 0, '
|
||||
@@ -109,11 +105,11 @@ class CheckOtherLangaugesData {
|
||||
'coOwningReference: 0, vectorOfCoOwningReferences: null, '
|
||||
'nonOwningReference: 0, vectorOfNonOwningReferences: null, '
|
||||
'anyUniqueType: null, anyUnique: null, anyAmbiguousType: null, '
|
||||
'anyAmbiguous: null, vectorOfEnums: null, signedEnum: Race{value: -1}, '
|
||||
'anyAmbiguous: null, vectorOfEnums: null, signedEnum: Race.None, '
|
||||
'testrequirednestedflatbuffer: null, scalarKeySortedTables: null, '
|
||||
'nativeInline: null, '
|
||||
'longEnumNonEnumDefault: LongEnum{value: 0}, '
|
||||
'longEnumNormalDefault: LongEnum{value: 2}, nanDefault: NaN, '
|
||||
'longEnumNonEnumDefault: LongEnum._default, '
|
||||
'longEnumNormalDefault: LongEnum.LongOne, nanDefault: NaN, '
|
||||
'infDefault: Infinity, positiveInfDefault: Infinity, infinityDefault: '
|
||||
'Infinity, positiveInfinityDefault: Infinity, negativeInfDefault: '
|
||||
'-Infinity, negativeInfinityDefault: -Infinity, doubleInfDefault: Infinity}, '
|
||||
@@ -138,15 +134,15 @@ class CheckOtherLangaugesData {
|
||||
'vectorOfNonOwningReferences: null, '
|
||||
'anyUniqueType: null, anyUnique: null, '
|
||||
'anyAmbiguousType: null, '
|
||||
'anyAmbiguous: null, vectorOfEnums: null, signedEnum: Race{value: -1}, '
|
||||
'anyAmbiguous: null, vectorOfEnums: null, signedEnum: Race.None, '
|
||||
'testrequirednestedflatbuffer: null, scalarKeySortedTables: [Stat{id: '
|
||||
'miss, val: 0, count: 0}, Stat{id: hit, val: 10, count: 1}], '
|
||||
'nativeInline: Test{a: 1, b: 2}, '
|
||||
'longEnumNonEnumDefault: LongEnum{value: 0}, '
|
||||
'longEnumNormalDefault: LongEnum{value: 2}, nanDefault: NaN, '
|
||||
'longEnumNonEnumDefault: LongEnum._default, '
|
||||
'longEnumNormalDefault: LongEnum.LongOne, nanDefault: NaN, '
|
||||
'infDefault: Infinity, positiveInfDefault: Infinity, infinityDefault: '
|
||||
'Infinity, positiveInfinityDefault: Infinity, negativeInfDefault: '
|
||||
'-Infinity, negativeInfinityDefault: -Infinity, doubleInfDefault: Infinity}'
|
||||
'-Infinity, negativeInfinityDefault: -Infinity, doubleInfDefault: Infinity}',
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -217,6 +213,10 @@ class BuilderTest {
|
||||
..addTestarrayofstringOffset(testArrayOfString);
|
||||
final mon = monBuilder.finish();
|
||||
fbBuilder.finish(mon);
|
||||
|
||||
final mon3 = example.Monster(fbBuilder.buffer);
|
||||
expect(mon3.name, 'MyMonster');
|
||||
expect(mon3.pos!.test1, 3.0);
|
||||
}
|
||||
|
||||
void test_error_addInt32_withoutStartTable([Builder? builder]) {
|
||||
@@ -296,20 +296,72 @@ class BuilderTest {
|
||||
expect(allocator.buffer(builder.size()), [2, 0, 0, 0, 0, 0, 0, 1]);
|
||||
|
||||
builder.putUint8(3);
|
||||
expect(
|
||||
allocator.buffer(builder.size()), [0, 0, 0, 3, 2, 0, 0, 0, 0, 0, 0, 1]);
|
||||
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]);
|
||||
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]);
|
||||
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]);
|
||||
expect(allocator.buffer(builder.size()), [
|
||||
6,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
5,
|
||||
4,
|
||||
3,
|
||||
2,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
1,
|
||||
]);
|
||||
}
|
||||
|
||||
void test_table_default() {
|
||||
@@ -329,14 +381,14 @@ class BuilderTest {
|
||||
int objectOffset = buffer.derefObject(0);
|
||||
// was not written, so uses the new default value
|
||||
expect(
|
||||
const Int32Reader()
|
||||
.vTableGet(buffer, objectOffset, indexToField(0), 15),
|
||||
15);
|
||||
const Int32Reader().vTableGet(buffer, objectOffset, indexToField(0), 15),
|
||||
15,
|
||||
);
|
||||
// has the written value
|
||||
expect(
|
||||
const Int32Reader()
|
||||
.vTableGet(buffer, objectOffset, indexToField(1), 15),
|
||||
20);
|
||||
const Int32Reader().vTableGet(buffer, objectOffset, indexToField(1), 15),
|
||||
20,
|
||||
);
|
||||
}
|
||||
|
||||
void test_table_format([Builder? builder]) {
|
||||
@@ -368,7 +420,9 @@ class BuilderTest {
|
||||
for (int i = 0; i < 3; i++) {
|
||||
int offset = byteData.getUint16(vTableLoc + 4 + 2 * i, Endian.little);
|
||||
expect(
|
||||
byteData.getInt32(tableDataLoc + offset, Endian.little), 10 + 10 * i);
|
||||
byteData.getInt32(tableDataLoc + offset, Endian.little),
|
||||
10 + 10 * i,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -378,10 +432,14 @@ class BuilderTest {
|
||||
List<int> byteList;
|
||||
{
|
||||
Builder builder = Builder(initialSize: 0);
|
||||
int? latinStringOffset =
|
||||
builder.writeString(latinString, asciiOptimization: true);
|
||||
int? unicodeStringOffset =
|
||||
builder.writeString(unicodeString, asciiOptimization: true);
|
||||
int? latinStringOffset = builder.writeString(
|
||||
latinString,
|
||||
asciiOptimization: true,
|
||||
);
|
||||
int? unicodeStringOffset = builder.writeString(
|
||||
unicodeString,
|
||||
asciiOptimization: true,
|
||||
);
|
||||
builder.startTable(2);
|
||||
builder.addOffset(0, latinStringOffset);
|
||||
builder.addOffset(1, unicodeStringOffset);
|
||||
@@ -393,13 +451,19 @@ class BuilderTest {
|
||||
BufferContext buf = BufferContext.fromBytes(byteList);
|
||||
int objectOffset = buf.derefObject(0);
|
||||
expect(
|
||||
const StringReader()
|
||||
.vTableGetNullable(buf, objectOffset, indexToField(0)),
|
||||
latinString);
|
||||
const StringReader().vTableGetNullable(
|
||||
buf,
|
||||
objectOffset,
|
||||
indexToField(0),
|
||||
),
|
||||
latinString,
|
||||
);
|
||||
expect(
|
||||
const StringReader(asciiOptimization: true)
|
||||
.vTableGetNullable(buf, objectOffset, indexToField(1)),
|
||||
unicodeString);
|
||||
const StringReader(
|
||||
asciiOptimization: true,
|
||||
).vTableGetNullable(buf, objectOffset, indexToField(1)),
|
||||
unicodeString,
|
||||
);
|
||||
}
|
||||
|
||||
void test_table_types([Builder? builder]) {
|
||||
@@ -423,33 +487,41 @@ class BuilderTest {
|
||||
BufferContext buf = BufferContext.fromBytes(byteList);
|
||||
int objectOffset = buf.derefObject(0);
|
||||
expect(
|
||||
const BoolReader()
|
||||
.vTableGetNullable(buf, objectOffset, indexToField(0)),
|
||||
true);
|
||||
const BoolReader().vTableGetNullable(buf, objectOffset, indexToField(0)),
|
||||
true,
|
||||
);
|
||||
expect(
|
||||
const Int8Reader()
|
||||
.vTableGetNullable(buf, objectOffset, indexToField(1)),
|
||||
10);
|
||||
const Int8Reader().vTableGetNullable(buf, objectOffset, indexToField(1)),
|
||||
10,
|
||||
);
|
||||
expect(
|
||||
const Int32Reader()
|
||||
.vTableGetNullable(buf, objectOffset, indexToField(2)),
|
||||
20);
|
||||
const Int32Reader().vTableGetNullable(buf, objectOffset, indexToField(2)),
|
||||
20,
|
||||
);
|
||||
expect(
|
||||
const StringReader()
|
||||
.vTableGetNullable(buf, objectOffset, indexToField(3)),
|
||||
'12345');
|
||||
const StringReader().vTableGetNullable(
|
||||
buf,
|
||||
objectOffset,
|
||||
indexToField(3),
|
||||
),
|
||||
'12345',
|
||||
);
|
||||
expect(
|
||||
const Int32Reader()
|
||||
.vTableGetNullable(buf, objectOffset, indexToField(4)),
|
||||
40);
|
||||
const Int32Reader().vTableGetNullable(buf, objectOffset, indexToField(4)),
|
||||
40,
|
||||
);
|
||||
expect(
|
||||
const Uint32Reader()
|
||||
.vTableGetNullable(buf, objectOffset, indexToField(5)),
|
||||
0x9ABCDEF0);
|
||||
const Uint32Reader().vTableGetNullable(
|
||||
buf,
|
||||
objectOffset,
|
||||
indexToField(5),
|
||||
),
|
||||
0x9ABCDEF0,
|
||||
);
|
||||
expect(
|
||||
const Uint8Reader()
|
||||
.vTableGetNullable(buf, objectOffset, indexToField(6)),
|
||||
0x9A);
|
||||
const Uint8Reader().vTableGetNullable(buf, objectOffset, indexToField(6)),
|
||||
0x9A,
|
||||
);
|
||||
}
|
||||
|
||||
void test_writeList_of_Uint32() {
|
||||
@@ -594,8 +666,9 @@ class BuilderTest {
|
||||
}
|
||||
// read and verify
|
||||
BufferContext buf = BufferContext.fromBytes(byteList);
|
||||
List<TestPointImpl> items =
|
||||
const ListReader<TestPointImpl>(TestPointReader()).read(buf, 0);
|
||||
List<TestPointImpl> items = const ListReader<TestPointImpl>(
|
||||
TestPointReader(),
|
||||
).read(buf, 0);
|
||||
expect(items, hasLength(2));
|
||||
expect(items[0].x, 10);
|
||||
expect(items[0].y, 20);
|
||||
@@ -625,8 +698,10 @@ class BuilderTest {
|
||||
List<int> byteList;
|
||||
{
|
||||
builder ??= Builder(initialSize: 0);
|
||||
int listOffset = builder.writeList(
|
||||
[builder.writeString('12345'), builder.writeString('ABC')]);
|
||||
int listOffset = builder.writeList([
|
||||
builder.writeString('12345'),
|
||||
builder.writeString('ABC'),
|
||||
]);
|
||||
builder.startTable(1);
|
||||
builder.addOffset(0, listOffset);
|
||||
int offset = builder.endTable();
|
||||
@@ -705,13 +780,14 @@ class BuilderTest {
|
||||
test_table_format,
|
||||
test_table_types,
|
||||
test_writeList_ofObjects,
|
||||
test_writeList_ofStrings_inObject
|
||||
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));
|
||||
final testCasesPermutations = _permutationsOf(
|
||||
List.generate(testCases.length, (index) => index),
|
||||
);
|
||||
expect(testCasesPermutations.length, _factorial(testCases.length));
|
||||
|
||||
for (var indexes in testCasesPermutations) {
|
||||
@@ -769,7 +845,6 @@ class BuilderTest {
|
||||
class ObjectAPITest {
|
||||
void test_tableStat() {
|
||||
final object1 = example.StatT(count: 3, id: "foo", val: 4);
|
||||
expect(object1 is Packable, isTrue);
|
||||
final fbb = Builder();
|
||||
fbb.finish(object1.pack(fbb));
|
||||
final object2 = example.Stat(fbb.buffer).unpack();
|
||||
@@ -782,28 +857,28 @@ class ObjectAPITest {
|
||||
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))
|
||||
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')
|
||||
..testarrayoftables = [example.MonsterT(name: 'Oof', testf: 2.75)]
|
||||
..enemy = example.MonsterT(name: 'Enemy', testf: 2.5)
|
||||
..testarrayofbools = [false, true, false]
|
||||
..testf = 42.24
|
||||
..testf = 42.25
|
||||
..testarrayofsortedstruct = [
|
||||
example.AbilityT(id: 1, distance: 5),
|
||||
example.AbilityT(id: 3, distance: 7)
|
||||
example.AbilityT(id: 3, distance: 7),
|
||||
]
|
||||
..vectorOfLongs = [5, 6, 7]
|
||||
..vectorOfDoubles = [8.9, 9.0, 10.1, 11.2]
|
||||
@@ -818,16 +893,15 @@ class ObjectAPITest {
|
||||
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());
|
||||
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() {
|
||||
@@ -866,8 +940,9 @@ class StringListWrapperImpl {
|
||||
|
||||
StringListWrapperImpl(this.bp, this.offset);
|
||||
|
||||
List<String>? get items => const ListReader<String>(StringReader())
|
||||
.vTableGetNullable(bp, offset, indexToField(0));
|
||||
List<String>? get items => const ListReader<String>(
|
||||
StringReader(),
|
||||
).vTableGetNullable(bp, offset, indexToField(0));
|
||||
}
|
||||
|
||||
class StringListWrapperReader extends TableReader<StringListWrapperImpl> {
|
||||
@@ -905,10 +980,14 @@ class GeneratorTest {
|
||||
expect(example.Color.values, same(example.Color.values));
|
||||
expect(example.Race.values, same(example.Race.values));
|
||||
expect(example.AnyTypeId.values, same(example.AnyTypeId.values));
|
||||
expect(example.AnyUniqueAliasesTypeId.values,
|
||||
same(example.AnyUniqueAliasesTypeId.values));
|
||||
expect(example.AnyAmbiguousAliasesTypeId.values,
|
||||
same(example.AnyAmbiguousAliasesTypeId.values));
|
||||
expect(
|
||||
example.AnyUniqueAliasesTypeId.values,
|
||||
same(example.AnyUniqueAliasesTypeId.values),
|
||||
);
|
||||
expect(
|
||||
example.AnyAmbiguousAliasesTypeId.values,
|
||||
same(example.AnyAmbiguousAliasesTypeId.values),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -916,11 +995,13 @@ class GeneratorTest {
|
||||
@reflectiveTest
|
||||
class ListOfEnumsTest {
|
||||
void test_listOfEnums() async {
|
||||
var mytable = example3.MyTableObjectBuilder(options: [
|
||||
example3.OptionsEnum.A,
|
||||
example3.OptionsEnum.B,
|
||||
example3.OptionsEnum.C
|
||||
]);
|
||||
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);
|
||||
@@ -933,7 +1014,8 @@ class ListOfEnumsTest {
|
||||
class BoolInStructTest {
|
||||
void test_boolInStruct() async {
|
||||
var mystruct = example4.FooObjectBuilder(
|
||||
myFoo: example4.FooPropertiesObjectBuilder(a: true, b: false));
|
||||
myFoo: example4.FooPropertiesObjectBuilder(a: true, b: false),
|
||||
);
|
||||
var bytes = mystruct.toBytes();
|
||||
var mystruct_read = example4.Foo(bytes);
|
||||
expect(mystruct_read.myFoo!.a, true);
|
||||
|
||||
@@ -62,8 +62,23 @@ void main() {
|
||||
{
|
||||
var flx = Builder();
|
||||
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,
|
||||
]);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -117,7 +132,7 @@ void main() {
|
||||
192,
|
||||
16,
|
||||
75,
|
||||
1
|
||||
1,
|
||||
]);
|
||||
}
|
||||
{
|
||||
@@ -177,7 +192,7 @@ void main() {
|
||||
7,
|
||||
3,
|
||||
60,
|
||||
1
|
||||
1,
|
||||
]);
|
||||
}
|
||||
{
|
||||
@@ -215,7 +230,7 @@ void main() {
|
||||
10,
|
||||
6,
|
||||
60,
|
||||
1
|
||||
1,
|
||||
]);
|
||||
}
|
||||
{
|
||||
@@ -300,9 +315,24 @@ void main() {
|
||||
104,
|
||||
45,
|
||||
43,
|
||||
1
|
||||
1,
|
||||
]);
|
||||
}
|
||||
{
|
||||
// Default buffer is 2048 bytes, add 2300 bytes of strings that force it
|
||||
// to grow.
|
||||
final s1 = 'A' * 1000;
|
||||
final s2 = 'B' * 800;
|
||||
final s3 = 'C' * 500;
|
||||
|
||||
var flx = Builder()
|
||||
..startVector()
|
||||
..addString(s1)
|
||||
..addString(s2)
|
||||
..addString(s3)
|
||||
..end();
|
||||
expect(flx.finish().length, 2323);
|
||||
}
|
||||
});
|
||||
|
||||
test('build map', () {
|
||||
@@ -322,8 +352,24 @@ void main() {
|
||||
..addKey('')
|
||||
..addInt(45)
|
||||
..end();
|
||||
expect(
|
||||
flx.finish(), [97, 0, 0, 2, 2, 5, 2, 1, 2, 45, 12, 4, 4, 4, 36, 1]);
|
||||
expect(flx.finish(), [
|
||||
97,
|
||||
0,
|
||||
0,
|
||||
2,
|
||||
2,
|
||||
5,
|
||||
2,
|
||||
1,
|
||||
2,
|
||||
45,
|
||||
12,
|
||||
4,
|
||||
4,
|
||||
4,
|
||||
36,
|
||||
1,
|
||||
]);
|
||||
}
|
||||
{
|
||||
var flx = Builder()
|
||||
@@ -367,7 +413,7 @@ void main() {
|
||||
36,
|
||||
4,
|
||||
40,
|
||||
1
|
||||
1,
|
||||
]);
|
||||
}
|
||||
});
|
||||
@@ -381,133 +427,152 @@ void main() {
|
||||
|
||||
test('build from object', () {
|
||||
expect(
|
||||
Builder.buildFromObject(Uint8List.fromList([1, 2, 3]).buffer)
|
||||
.asUint8List(),
|
||||
[3, 1, 2, 3, 3, 100, 1]);
|
||||
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(true).asUint8List(), [1, 104, 1]);
|
||||
expect(Builder.buildFromObject(false).asUint8List(), [0, 104, 1]);
|
||||
expect(Builder.buildFromObject(25).asUint8List(), [25, 4, 1]);
|
||||
expect(Builder.buildFromObject(-250).asUint8List(), [6, 255, 5, 2]);
|
||||
expect(Builder.buildFromObject(-2.50).asUint8List(), [
|
||||
0,
|
||||
0,
|
||||
32,
|
||||
192,
|
||||
14,
|
||||
4,
|
||||
]);
|
||||
expect(Builder.buildFromObject('Maxim').asUint8List(), [
|
||||
5,
|
||||
77,
|
||||
97,
|
||||
120,
|
||||
105,
|
||||
109,
|
||||
0,
|
||||
6,
|
||||
20,
|
||||
1,
|
||||
]);
|
||||
expect(
|
||||
Builder.buildFromObject(-2.50).asUint8List(), [0, 0, 32, 192, 14, 4]);
|
||||
expect(Builder.buildFromObject('Maxim').asUint8List(),
|
||||
[5, 77, 97, 120, 105, 109, 0, 6, 20, 1]);
|
||||
Builder.buildFromObject([1, 3.3, 'max', true, null, false]).asUint8List(),
|
||||
[
|
||||
3,
|
||||
109,
|
||||
97,
|
||||
120,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
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([1, 3.3, 'max', true, null, false])
|
||||
.asUint8List(),
|
||||
[
|
||||
3,
|
||||
109,
|
||||
97,
|
||||
120,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
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
|
||||
]);
|
||||
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', () {
|
||||
@@ -543,7 +608,7 @@ void main() {
|
||||
35,
|
||||
8,
|
||||
40,
|
||||
1
|
||||
1,
|
||||
]);
|
||||
});
|
||||
|
||||
@@ -580,7 +645,7 @@ void main() {
|
||||
27,
|
||||
8,
|
||||
40,
|
||||
1
|
||||
1,
|
||||
]);
|
||||
});
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -48,116 +48,210 @@ void main() {
|
||||
expect(ValueTypeUtils.isFixedTypedVector(ValueType.VectorInt), isFalse);
|
||||
});
|
||||
test('to typed vector', () {
|
||||
expect(ValueTypeUtils.toTypedVector(ValueType.Int, 0),
|
||||
equals(ValueType.VectorInt));
|
||||
expect(ValueTypeUtils.toTypedVector(ValueType.UInt, 0),
|
||||
equals(ValueType.VectorUInt));
|
||||
expect(ValueTypeUtils.toTypedVector(ValueType.Bool, 0),
|
||||
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, 0),
|
||||
equals(ValueType.VectorInt),
|
||||
);
|
||||
expect(
|
||||
ValueTypeUtils.toTypedVector(ValueType.UInt, 0),
|
||||
equals(ValueType.VectorUInt),
|
||||
);
|
||||
expect(
|
||||
ValueTypeUtils.toTypedVector(ValueType.Bool, 0),
|
||||
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.UInt, 2),
|
||||
equals(ValueType.VectorUInt2));
|
||||
expect(ValueTypeUtils.toTypedVector(ValueType.Float, 2),
|
||||
equals(ValueType.VectorFloat2));
|
||||
expect(
|
||||
ValueTypeUtils.toTypedVector(ValueType.Int, 2),
|
||||
equals(ValueType.VectorInt2),
|
||||
);
|
||||
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.UInt, 3),
|
||||
equals(ValueType.VectorUInt3));
|
||||
expect(ValueTypeUtils.toTypedVector(ValueType.Float, 3),
|
||||
equals(ValueType.VectorFloat3));
|
||||
expect(
|
||||
ValueTypeUtils.toTypedVector(ValueType.Int, 3),
|
||||
equals(ValueType.VectorInt3),
|
||||
);
|
||||
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.UInt, 4),
|
||||
equals(ValueType.VectorUInt4));
|
||||
expect(ValueTypeUtils.toTypedVector(ValueType.Float, 4),
|
||||
equals(ValueType.VectorFloat4));
|
||||
expect(
|
||||
ValueTypeUtils.toTypedVector(ValueType.Int, 4),
|
||||
equals(ValueType.VectorInt4),
|
||||
);
|
||||
expect(
|
||||
ValueTypeUtils.toTypedVector(ValueType.UInt, 4),
|
||||
equals(ValueType.VectorUInt4),
|
||||
);
|
||||
expect(
|
||||
ValueTypeUtils.toTypedVector(ValueType.Float, 4),
|
||||
equals(ValueType.VectorFloat4),
|
||||
);
|
||||
});
|
||||
test('typed vector element type', () {
|
||||
expect(ValueTypeUtils.typedVectorElementType(ValueType.VectorInt),
|
||||
equals(ValueType.Int));
|
||||
expect(ValueTypeUtils.typedVectorElementType(ValueType.VectorUInt),
|
||||
equals(ValueType.UInt));
|
||||
expect(ValueTypeUtils.typedVectorElementType(ValueType.VectorFloat),
|
||||
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));
|
||||
expect(
|
||||
ValueTypeUtils.typedVectorElementType(ValueType.VectorInt),
|
||||
equals(ValueType.Int),
|
||||
);
|
||||
expect(
|
||||
ValueTypeUtils.typedVectorElementType(ValueType.VectorUInt),
|
||||
equals(ValueType.UInt),
|
||||
);
|
||||
expect(
|
||||
ValueTypeUtils.typedVectorElementType(ValueType.VectorFloat),
|
||||
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', () {
|
||||
expect(ValueTypeUtils.fixedTypedVectorElementType(ValueType.VectorInt2),
|
||||
equals(ValueType.Int));
|
||||
expect(ValueTypeUtils.fixedTypedVectorElementType(ValueType.VectorInt3),
|
||||
equals(ValueType.Int));
|
||||
expect(ValueTypeUtils.fixedTypedVectorElementType(ValueType.VectorInt4),
|
||||
equals(ValueType.Int));
|
||||
expect(
|
||||
ValueTypeUtils.fixedTypedVectorElementType(ValueType.VectorInt2),
|
||||
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.VectorUInt3),
|
||||
equals(ValueType.UInt));
|
||||
expect(ValueTypeUtils.fixedTypedVectorElementType(ValueType.VectorUInt4),
|
||||
equals(ValueType.UInt));
|
||||
expect(
|
||||
ValueTypeUtils.fixedTypedVectorElementType(ValueType.VectorUInt2),
|
||||
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.VectorFloat3),
|
||||
equals(ValueType.Float));
|
||||
expect(ValueTypeUtils.fixedTypedVectorElementType(ValueType.VectorFloat4),
|
||||
equals(ValueType.Float));
|
||||
expect(
|
||||
ValueTypeUtils.fixedTypedVectorElementType(ValueType.VectorFloat2),
|
||||
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', () {
|
||||
expect(ValueTypeUtils.fixedTypedVectorElementSize(ValueType.VectorInt2),
|
||||
equals(2));
|
||||
expect(ValueTypeUtils.fixedTypedVectorElementSize(ValueType.VectorInt3),
|
||||
equals(3));
|
||||
expect(ValueTypeUtils.fixedTypedVectorElementSize(ValueType.VectorInt4),
|
||||
equals(4));
|
||||
expect(
|
||||
ValueTypeUtils.fixedTypedVectorElementSize(ValueType.VectorInt2),
|
||||
equals(2),
|
||||
);
|
||||
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.VectorUInt3),
|
||||
equals(3));
|
||||
expect(ValueTypeUtils.fixedTypedVectorElementSize(ValueType.VectorUInt4),
|
||||
equals(4));
|
||||
expect(
|
||||
ValueTypeUtils.fixedTypedVectorElementSize(ValueType.VectorUInt2),
|
||||
equals(2),
|
||||
);
|
||||
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.VectorFloat3),
|
||||
equals(3));
|
||||
expect(ValueTypeUtils.fixedTypedVectorElementSize(ValueType.VectorFloat4),
|
||||
equals(4));
|
||||
expect(
|
||||
ValueTypeUtils.fixedTypedVectorElementSize(ValueType.VectorFloat2),
|
||||
equals(2),
|
||||
);
|
||||
expect(
|
||||
ValueTypeUtils.fixedTypedVectorElementSize(ValueType.VectorFloat3),
|
||||
equals(3),
|
||||
);
|
||||
expect(
|
||||
ValueTypeUtils.fixedTypedVectorElementSize(ValueType.VectorFloat4),
|
||||
equals(4),
|
||||
);
|
||||
});
|
||||
test('packed type', () {
|
||||
expect(
|
||||
ValueTypeUtils.packedType(ValueType.Null, BitWidth.width8), equals(0));
|
||||
ValueTypeUtils.packedType(ValueType.Null, BitWidth.width8),
|
||||
equals(0),
|
||||
);
|
||||
expect(
|
||||
ValueTypeUtils.packedType(ValueType.Null, BitWidth.width16), equals(1));
|
||||
ValueTypeUtils.packedType(ValueType.Null, BitWidth.width16),
|
||||
equals(1),
|
||||
);
|
||||
expect(
|
||||
ValueTypeUtils.packedType(ValueType.Null, BitWidth.width32), equals(2));
|
||||
ValueTypeUtils.packedType(ValueType.Null, BitWidth.width32),
|
||||
equals(2),
|
||||
);
|
||||
expect(
|
||||
ValueTypeUtils.packedType(ValueType.Null, BitWidth.width64), equals(3));
|
||||
ValueTypeUtils.packedType(ValueType.Null, BitWidth.width64),
|
||||
equals(3),
|
||||
);
|
||||
|
||||
expect(
|
||||
ValueTypeUtils.packedType(ValueType.Int, BitWidth.width8), equals(4));
|
||||
ValueTypeUtils.packedType(ValueType.Int, BitWidth.width8),
|
||||
equals(4),
|
||||
);
|
||||
expect(
|
||||
ValueTypeUtils.packedType(ValueType.Int, BitWidth.width16), equals(5));
|
||||
ValueTypeUtils.packedType(ValueType.Int, BitWidth.width16),
|
||||
equals(5),
|
||||
);
|
||||
expect(
|
||||
ValueTypeUtils.packedType(ValueType.Int, BitWidth.width32), equals(6));
|
||||
ValueTypeUtils.packedType(ValueType.Int, BitWidth.width32),
|
||||
equals(6),
|
||||
);
|
||||
expect(
|
||||
ValueTypeUtils.packedType(ValueType.Int, BitWidth.width64), equals(7));
|
||||
ValueTypeUtils.packedType(ValueType.Int, BitWidth.width64),
|
||||
equals(7),
|
||||
);
|
||||
});
|
||||
test('bit width', () {
|
||||
expect(BitWidthUtil.width(0), BitWidth.width8);
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
// automatically generated by the FlatBuffers compiler, do not modify
|
||||
// ignore_for_file: unused_import, unused_field, unused_element, unused_local_variable
|
||||
// ignore_for_file: unused_import, unused_field, unused_element, unused_local_variable, constant_identifier_names
|
||||
|
||||
import 'dart:typed_data' show Uint8List;
|
||||
|
||||
import 'package:flat_buffers/flat_buffers.dart' as fb;
|
||||
|
||||
|
||||
import './include_test2_my_game.other_name_space_generated.dart' as my_game_other_name_space;
|
||||
import './include_test2_my_game.other_name_space_generated.dart'
|
||||
as my_game_other_name_space;
|
||||
|
||||
class TableA {
|
||||
TableA._(this._bc, this._bcOffset);
|
||||
@@ -19,15 +20,17 @@ class TableA {
|
||||
final fb.BufferContext _bc;
|
||||
final int _bcOffset;
|
||||
|
||||
my_game_other_name_space.TableB? get b => my_game_other_name_space.TableB.reader.vTableGetNullable(_bc, _bcOffset, 4);
|
||||
my_game_other_name_space.TableB? get b => my_game_other_name_space
|
||||
.TableB
|
||||
.reader
|
||||
.vTableGetNullable(_bc, _bcOffset, 4);
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return 'TableA{b: ${b}}';
|
||||
}
|
||||
|
||||
TableAT unpack() => TableAT(
|
||||
b: b?.unpack());
|
||||
TableAT unpack() => TableAT(b: b?.unpack());
|
||||
|
||||
static int pack(fb.Builder fbBuilder, TableAT? object) {
|
||||
if (object == null) return 0;
|
||||
@@ -38,8 +41,7 @@ class TableA {
|
||||
class TableAT implements fb.Packable {
|
||||
my_game_other_name_space.TableBT? b;
|
||||
|
||||
TableAT({
|
||||
this.b});
|
||||
TableAT({this.b});
|
||||
|
||||
@override
|
||||
int pack(fb.Builder fbBuilder) {
|
||||
@@ -59,8 +61,7 @@ class _TableAReader extends fb.TableReader<TableA> {
|
||||
const _TableAReader();
|
||||
|
||||
@override
|
||||
TableA createObject(fb.BufferContext bc, int offset) =>
|
||||
TableA._(bc, offset);
|
||||
TableA createObject(fb.BufferContext bc, int offset) => TableA._(bc, offset);
|
||||
}
|
||||
|
||||
class TableABuilder {
|
||||
@@ -85,10 +86,8 @@ class TableABuilder {
|
||||
class TableAObjectBuilder extends fb.ObjectBuilder {
|
||||
final my_game_other_name_space.TableBObjectBuilder? _b;
|
||||
|
||||
TableAObjectBuilder({
|
||||
my_game_other_name_space.TableBObjectBuilder? b,
|
||||
})
|
||||
: _b = b;
|
||||
TableAObjectBuilder({my_game_other_name_space.TableBObjectBuilder? b})
|
||||
: _b = b;
|
||||
|
||||
/// Finish building, and store into the [fbBuilder].
|
||||
@override
|
||||
|
||||
@@ -1,43 +1,35 @@
|
||||
// automatically generated by the FlatBuffers compiler, do not modify
|
||||
// ignore_for_file: unused_import, unused_field, unused_element, unused_local_variable
|
||||
// ignore_for_file: unused_import, unused_field, unused_element, unused_local_variable, constant_identifier_names
|
||||
|
||||
library my_game.other_name_space;
|
||||
|
||||
import 'dart:typed_data' show Uint8List;
|
||||
import 'package:flat_buffers/flat_buffers.dart' as fb;
|
||||
|
||||
import 'package:flat_buffers/flat_buffers.dart' as fb;
|
||||
|
||||
import './include_test1_generated.dart';
|
||||
|
||||
class FromInclude {
|
||||
enum FromInclude {
|
||||
IncludeVal(0);
|
||||
|
||||
final int value;
|
||||
const FromInclude._(this.value);
|
||||
const FromInclude(this.value);
|
||||
|
||||
factory FromInclude.fromValue(int value) {
|
||||
final result = values[value];
|
||||
if (result == null) {
|
||||
throw StateError('Invalid value $value for bit flag enum FromInclude');
|
||||
switch (value) {
|
||||
case 0:
|
||||
return FromInclude.IncludeVal;
|
||||
default:
|
||||
throw StateError('Invalid value $value for bit flag enum');
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
static FromInclude? _createOrNull(int? value) =>
|
||||
static FromInclude? _createOrNull(int? value) =>
|
||||
value == null ? null : FromInclude.fromValue(value);
|
||||
|
||||
static const int minValue = 0;
|
||||
static const int maxValue = 0;
|
||||
static bool containsValue(int value) => values.containsKey(value);
|
||||
|
||||
static const FromInclude IncludeVal = FromInclude._(0);
|
||||
static const Map<int, FromInclude> values = {
|
||||
0: IncludeVal};
|
||||
|
||||
static const fb.Reader<FromInclude> reader = _FromIncludeReader();
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return 'FromInclude{value: $value}';
|
||||
}
|
||||
}
|
||||
|
||||
class _FromIncludeReader extends fb.Reader<FromInclude> {
|
||||
@@ -66,8 +58,7 @@ class Unused {
|
||||
return 'Unused{a: ${a}}';
|
||||
}
|
||||
|
||||
UnusedT unpack() => UnusedT(
|
||||
a: a);
|
||||
UnusedT unpack() => UnusedT(a: a);
|
||||
|
||||
static int pack(fb.Builder fbBuilder, UnusedT? object) {
|
||||
if (object == null) return 0;
|
||||
@@ -78,8 +69,7 @@ class Unused {
|
||||
class UnusedT implements fb.Packable {
|
||||
int a;
|
||||
|
||||
UnusedT({
|
||||
required this.a});
|
||||
UnusedT({required this.a});
|
||||
|
||||
@override
|
||||
int pack(fb.Builder fbBuilder) {
|
||||
@@ -100,8 +90,7 @@ class _UnusedReader extends fb.StructReader<Unused> {
|
||||
int get size => 4;
|
||||
|
||||
@override
|
||||
Unused createObject(fb.BufferContext bc, int offset) =>
|
||||
Unused._(bc, offset);
|
||||
Unused createObject(fb.BufferContext bc, int offset) => Unused._(bc, offset);
|
||||
}
|
||||
|
||||
class UnusedBuilder {
|
||||
@@ -113,16 +102,12 @@ class UnusedBuilder {
|
||||
fbBuilder.putInt32(a);
|
||||
return fbBuilder.offset;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class UnusedObjectBuilder extends fb.ObjectBuilder {
|
||||
final int _a;
|
||||
|
||||
UnusedObjectBuilder({
|
||||
required int a,
|
||||
})
|
||||
: _a = a;
|
||||
UnusedObjectBuilder({required int a}) : _a = a;
|
||||
|
||||
/// Finish building, and store into the [fbBuilder].
|
||||
@override
|
||||
@@ -139,6 +124,7 @@ class UnusedObjectBuilder extends fb.ObjectBuilder {
|
||||
return fbBuilder.buffer;
|
||||
}
|
||||
}
|
||||
|
||||
class TableB {
|
||||
TableB._(this._bc, this._bcOffset);
|
||||
factory TableB(List<int> bytes) {
|
||||
@@ -158,8 +144,7 @@ class TableB {
|
||||
return 'TableB{a: ${a}}';
|
||||
}
|
||||
|
||||
TableBT unpack() => TableBT(
|
||||
a: a?.unpack());
|
||||
TableBT unpack() => TableBT(a: a?.unpack());
|
||||
|
||||
static int pack(fb.Builder fbBuilder, TableBT? object) {
|
||||
if (object == null) return 0;
|
||||
@@ -170,8 +155,7 @@ class TableB {
|
||||
class TableBT implements fb.Packable {
|
||||
TableAT? a;
|
||||
|
||||
TableBT({
|
||||
this.a});
|
||||
TableBT({this.a});
|
||||
|
||||
@override
|
||||
int pack(fb.Builder fbBuilder) {
|
||||
@@ -191,8 +175,7 @@ class _TableBReader extends fb.TableReader<TableB> {
|
||||
const _TableBReader();
|
||||
|
||||
@override
|
||||
TableB createObject(fb.BufferContext bc, int offset) =>
|
||||
TableB._(bc, offset);
|
||||
TableB createObject(fb.BufferContext bc, int offset) => TableB._(bc, offset);
|
||||
}
|
||||
|
||||
class TableBBuilder {
|
||||
@@ -217,10 +200,7 @@ class TableBBuilder {
|
||||
class TableBObjectBuilder extends fb.ObjectBuilder {
|
||||
final TableAObjectBuilder? _a;
|
||||
|
||||
TableBObjectBuilder({
|
||||
TableAObjectBuilder? a,
|
||||
})
|
||||
: _a = a;
|
||||
TableBObjectBuilder({TableAObjectBuilder? a}) : _a = a;
|
||||
|
||||
/// Finish building, and store into the [fbBuilder].
|
||||
@override
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// automatically generated by the FlatBuffers compiler, do not modify
|
||||
// ignore_for_file: unused_import, unused_field, unused_element, unused_local_variable
|
||||
// ignore_for_file: unused_import, unused_field, unused_element, unused_local_variable, constant_identifier_names
|
||||
|
||||
library keyword_test;
|
||||
|
||||
@@ -7,39 +7,30 @@ import 'dart:typed_data' show Uint8List;
|
||||
import 'package:flat_buffers/flat_buffers.dart' as fb;
|
||||
|
||||
|
||||
class Abc {
|
||||
|
||||
enum Abc {
|
||||
$void(0),
|
||||
where(1),
|
||||
stackalloc(2);
|
||||
|
||||
final int value;
|
||||
const Abc._(this.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');
|
||||
switch (value) {
|
||||
case 0: return Abc.$void;
|
||||
case 1: return Abc.where;
|
||||
case 2: return Abc.stackalloc;
|
||||
default: throw StateError('Invalid value $value for bit flag enum');
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
static Abc? _createOrNull(int? value) =>
|
||||
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> {
|
||||
@@ -53,35 +44,25 @@ class _AbcReader extends fb.Reader<Abc> {
|
||||
Abc.fromValue(const fb.Int32Reader().read(bc, offset));
|
||||
}
|
||||
|
||||
class Public {
|
||||
enum Public {
|
||||
NONE(0);
|
||||
|
||||
final int value;
|
||||
const Public._(this.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');
|
||||
switch (value) {
|
||||
case 0: return Public.NONE;
|
||||
default: throw StateError('Invalid value $value for bit flag enum');
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
static Public? _createOrNull(int? value) =>
|
||||
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> {
|
||||
@@ -95,39 +76,29 @@ class _PublicReader extends fb.Reader<Public> {
|
||||
Public.fromValue(const fb.Int32Reader().read(bc, offset));
|
||||
}
|
||||
|
||||
class KeywordsInUnionTypeId {
|
||||
enum KeywordsInUnionTypeId {
|
||||
NONE(0),
|
||||
$static(1),
|
||||
internal(2);
|
||||
|
||||
final int value;
|
||||
const KeywordsInUnionTypeId._(this.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');
|
||||
switch (value) {
|
||||
case 0: return KeywordsInUnionTypeId.NONE;
|
||||
case 1: return KeywordsInUnionTypeId.$static;
|
||||
case 2: return KeywordsInUnionTypeId.internal;
|
||||
default: throw StateError('Invalid value $value for bit flag enum');
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
static KeywordsInUnionTypeId? _createOrNull(int? value) =>
|
||||
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> {
|
||||
@@ -306,7 +277,7 @@ class Table2 {
|
||||
|
||||
Table2T unpack() => Table2T(
|
||||
typeType: typeType,
|
||||
type: type);
|
||||
type: type?.unpack());
|
||||
|
||||
static int pack(fb.Builder fbBuilder, Table2T? object) {
|
||||
if (object == null) return 0;
|
||||
|
||||
@@ -59,8 +59,6 @@ struct Vec3 (force_align: 8) {
|
||||
test3:Test;
|
||||
}
|
||||
|
||||
// Stats for monster
|
||||
|
||||
struct Ability {
|
||||
id:uint(key);
|
||||
distance:uint;
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
// automatically generated by the FlatBuffers compiler, do not modify
|
||||
// ignore_for_file: unused_import, unused_field, unused_element, unused_local_variable
|
||||
// ignore_for_file: unused_import, unused_field, unused_element, unused_local_variable, constant_identifier_names
|
||||
|
||||
library my_game.example2;
|
||||
|
||||
import 'dart:typed_data' show Uint8List;
|
||||
|
||||
import 'package:flat_buffers/flat_buffers.dart' as fb;
|
||||
|
||||
import './monster_test_my_game_generated.dart' as my_game;
|
||||
import './monster_test_my_game.example_generated.dart' as my_game_example;
|
||||
|
||||
import './include_test1_generated.dart';
|
||||
import './monster_test_my_game.example_generated.dart' as my_game_example;
|
||||
import './monster_test_my_game_generated.dart' as my_game;
|
||||
|
||||
class Monster {
|
||||
Monster._(this._bc, this._bcOffset);
|
||||
@@ -23,7 +23,6 @@ class Monster {
|
||||
final fb.BufferContext _bc;
|
||||
final int _bcOffset;
|
||||
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return 'Monster{}';
|
||||
@@ -54,12 +53,11 @@ class _MonsterReader extends fb.TableReader<Monster> {
|
||||
const _MonsterReader();
|
||||
|
||||
@override
|
||||
Monster createObject(fb.BufferContext bc, int offset) =>
|
||||
Monster._(bc, offset);
|
||||
Monster createObject(fb.BufferContext bc, int offset) =>
|
||||
Monster._(bc, offset);
|
||||
}
|
||||
|
||||
class MonsterObjectBuilder extends fb.ObjectBuilder {
|
||||
|
||||
MonsterObjectBuilder();
|
||||
|
||||
/// Finish building, and store into the [fbBuilder].
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,15 +1,15 @@
|
||||
// automatically generated by the FlatBuffers compiler, do not modify
|
||||
// ignore_for_file: unused_import, unused_field, unused_element, unused_local_variable
|
||||
// ignore_for_file: unused_import, unused_field, unused_element, unused_local_variable, constant_identifier_names
|
||||
|
||||
library my_game;
|
||||
|
||||
import 'dart:typed_data' show Uint8List;
|
||||
|
||||
import 'package:flat_buffers/flat_buffers.dart' as fb;
|
||||
|
||||
import './monster_test_my_game.example_generated.dart' as my_game_example;
|
||||
import './monster_test_my_game.example2_generated.dart' as my_game_example2;
|
||||
|
||||
import './include_test1_generated.dart';
|
||||
import './monster_test_my_game.example2_generated.dart' as my_game_example2;
|
||||
import './monster_test_my_game.example_generated.dart' as my_game_example;
|
||||
|
||||
class InParentNamespace {
|
||||
InParentNamespace._(this._bc, this._bcOffset);
|
||||
@@ -23,7 +23,6 @@ class InParentNamespace {
|
||||
final fb.BufferContext _bc;
|
||||
final int _bcOffset;
|
||||
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return 'InParentNamespace{}';
|
||||
@@ -54,12 +53,11 @@ class _InParentNamespaceReader extends fb.TableReader<InParentNamespace> {
|
||||
const _InParentNamespaceReader();
|
||||
|
||||
@override
|
||||
InParentNamespace createObject(fb.BufferContext bc, int offset) =>
|
||||
InParentNamespace._(bc, offset);
|
||||
InParentNamespace createObject(fb.BufferContext bc, int offset) =>
|
||||
InParentNamespace._(bc, offset);
|
||||
}
|
||||
|
||||
class InParentNamespaceObjectBuilder extends fb.ObjectBuilder {
|
||||
|
||||
InParentNamespaceObjectBuilder();
|
||||
|
||||
/// Finish building, and store into the [fbBuilder].
|
||||
|
||||
24
docs/README.md
Normal file
24
docs/README.md
Normal file
@@ -0,0 +1,24 @@
|
||||
# Documentation
|
||||
|
||||
This is the source of the FlatBuffers documentation, that is served at
|
||||
https://flatbuffers.dev.
|
||||
|
||||
|
||||
## Local Building
|
||||
|
||||
The documentation can be built and served locally during development, see <https://flatbuffers.dev/contributing/#local-development> for full details.
|
||||
|
||||
__tl;dr__
|
||||
|
||||
Install:
|
||||
|
||||
```
|
||||
pip install mkdocs-material
|
||||
pip install mkdocs-redirects
|
||||
```
|
||||
|
||||
Build and Serve:
|
||||
|
||||
```
|
||||
mkdocs serve -f docs/mkdocs.yml
|
||||
```
|
||||
@@ -1,14 +0,0 @@
|
||||
<!-- Google Analytics -->
|
||||
<script>
|
||||
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
|
||||
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
|
||||
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
|
||||
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
|
||||
|
||||
ga('create', 'UA-49880327-7', 'auto');
|
||||
ga('send', 'pageview');
|
||||
|
||||
</script>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
@@ -1,62 +0,0 @@
|
||||
<!-- HTML header for doxygen 1.8.6-->
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||
<html xmlns="http://www.w3.org/1999/xhtml">
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
|
||||
<meta name="generator" content="Doxygen $doxygenversion"/>
|
||||
<!--BEGIN PROJECT_NAME--><title>$projectname: $title</title><!--END PROJECT_NAME-->
|
||||
<!--BEGIN !PROJECT_NAME--><title>$title</title><!--END !PROJECT_NAME-->
|
||||
<link href="$relpath^tabs.css" rel="stylesheet" type="text/css"/>
|
||||
<script type="text/javascript" src="$relpath^jquery.js"></script>
|
||||
<script type="text/javascript" src="$relpath^dynsections.js"></script>
|
||||
$treeview
|
||||
$search
|
||||
$mathjax
|
||||
<link href="$relpath^$stylesheet" rel="stylesheet" type="text/css" />
|
||||
<link href="https://fonts.googleapis.com/css?family=Roboto:300,400,400italic,500,500italic,700,700italic|Roboto+Mono:400,700" rel="stylesheet">
|
||||
$extrastylesheet
|
||||
</head>
|
||||
<body>
|
||||
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
|
||||
|
||||
<!--BEGIN TITLEAREA-->
|
||||
<div id="titlearea" style="height: 110px;">
|
||||
<table cellspacing="0" cellpadding="0">
|
||||
<tbody>
|
||||
<tr style="height: 56px;">
|
||||
<!--BEGIN PROJECT_LOGO-->
|
||||
<td id="projectlogo"><img alt="Logo" src="$relpath^$projectlogo"/></td>
|
||||
<!--END PROJECT_LOGO-->
|
||||
<td id="commonprojectlogo">
|
||||
<img alt="Logo" src="$relpath^fpl_logo_small.png"/>
|
||||
</td>
|
||||
<!--BEGIN PROJECT_NAME-->
|
||||
<td style="padding-left: 0.5em;">
|
||||
<div id="projectname">$projectname
|
||||
<!--BEGIN PROJECT_NUMBER--> <span id="projectnumber">$projectnumber</span><!--END PROJECT_NUMBER-->
|
||||
</div>
|
||||
<div style="font-size:12px;">
|
||||
An open source project by <a href="https://developers.google.com/games/#Tools">FPL</a>.
|
||||
</div>
|
||||
<!--BEGIN PROJECT_BRIEF--><div id="projectbrief">$projectbrief</div><!--END PROJECT_BRIEF-->
|
||||
</td>
|
||||
<!--END PROJECT_NAME-->
|
||||
<!--BEGIN !PROJECT_NAME-->
|
||||
<!--BEGIN PROJECT_BRIEF-->
|
||||
<td style="padding-left: 0.5em;">
|
||||
<div id="projectbrief">$projectbrief</div>
|
||||
</td>
|
||||
<!--END PROJECT_BRIEF-->
|
||||
<!--END !PROJECT_NAME-->
|
||||
<!--BEGIN DISABLE_INDEX-->
|
||||
<!--BEGIN SEARCHENGINE-->
|
||||
<td>$searchbox</td>
|
||||
<!--END SEARCHENGINE-->
|
||||
<!--END DISABLE_INDEX-->
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<!--END TITLEAREA-->
|
||||
<!-- end header part -->
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 5.0 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 1.0 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 1.0 KiB |
159
docs/mkdocs.yml
Normal file
159
docs/mkdocs.yml
Normal file
@@ -0,0 +1,159 @@
|
||||
site_name: FlatBuffers Docs
|
||||
docs_dir: source
|
||||
site_url: https://flatbuffers.dev
|
||||
repo_name: google/FlatBuffers
|
||||
repo_url: https://github.com/google/flatbuffers
|
||||
edit_uri: edit/master/docs/source/
|
||||
copyright: Copyright © 2025 Google
|
||||
theme:
|
||||
name: material
|
||||
logo: assets/flatbuffers_logo.svg
|
||||
icon:
|
||||
repo: fontawesome/brands/github
|
||||
custom_dir: overrides
|
||||
palette:
|
||||
# Palette toggle for light mode
|
||||
- scheme: default
|
||||
toggle:
|
||||
icon: material/brightness-7
|
||||
name: Switch to dark mode
|
||||
|
||||
# Palette toggle for dark mode
|
||||
- scheme: slate
|
||||
toggle:
|
||||
icon: material/brightness-4
|
||||
name: Switch to light mode
|
||||
|
||||
features:
|
||||
# Allows code block annotations
|
||||
- content.code.annotate
|
||||
|
||||
# Allows content tabs to link together
|
||||
- content.tabs.link
|
||||
|
||||
# Expand nav folders by default
|
||||
- navigation.expand
|
||||
|
||||
# Enable the footer
|
||||
- navigation.footer
|
||||
|
||||
# Auto hide the header after scrolling
|
||||
- header.autohide
|
||||
|
||||
- content.action.edit
|
||||
|
||||
extra:
|
||||
social:
|
||||
- icon: fontawesome/brands/github
|
||||
link: https://github.com/google/flatbuffers
|
||||
|
||||
- icon: fontawesome/brands/discord
|
||||
link: https:///discord.gg/6qgKs3R
|
||||
|
||||
- icon: fontawesome/brands/x-twitter
|
||||
link: https://twitter.com/dbaileychess
|
||||
|
||||
plugins:
|
||||
# Use redirects to update links from the original docs to the new ones.
|
||||
#
|
||||
# https://github.com/mkdocs/mkdocs-redirects
|
||||
- redirects:
|
||||
# Note the .html are suffixed with .md to avoid warnings. Got from
|
||||
# https://github.com/mkdocs/mkdocs-redirects/issues/51#issuecomment-2408548029
|
||||
redirect_maps:
|
||||
'flatbuffers_guide_building.html.md': 'building.md'
|
||||
'flatbuffers_guide_tutorial.html.md': 'tutorial.md'
|
||||
'flatbuffers_guide_using_schema_compiler.html.md': 'flatc.md'
|
||||
'flatbuffers_guide_writing_schema.html.md': 'schema.md'
|
||||
'md__schemas.html.md': 'schema.md' # issue #8485
|
||||
'flatbuffers_guide_use_c.html.md': 'languages/c.md'
|
||||
'flatbuffers_guide_use_cpp.html.md': 'languages/cpp.md'
|
||||
'flatbuffers_guide_use_c-sharp.html.md': 'languages/c_sharp.md'
|
||||
'flatbuffers_guide_use_dart.html.md': 'languages/dart.md'
|
||||
'flatbuffers_guide_use_go.html.md': 'languages/go.md'
|
||||
'flatbuffers_guide_use_java.html.md': 'languages/java.md'
|
||||
'flatbuffers_guide_use_javascript.html.md': 'languages/javascript.md'
|
||||
'flatbuffers_guide_use_lobster.html.md': 'languages/lobster.md'
|
||||
'flatbuffers_guide_use_lua.html.md': 'languages/lua.md'
|
||||
'flatbuffers_guide_use_php.html.md': 'languages/php.md'
|
||||
'flatbuffers_guide_use_python.html.md': 'languages/python.md'
|
||||
'flatbuffers_guide_use_rust.html.md': 'languages/rust.md'
|
||||
'flatbuffers_guide_use_swift.html.md': 'languages/swift.md'
|
||||
'flatbuffers_guide_use_typescript.html.md': 'languages/typescript.md'
|
||||
'flatbuffers_grpc_guide_use_cpp.html.md' : "languages/cpp.md#grpc"
|
||||
'flatbuffers_support.html.md': 'support.md'
|
||||
'flatbuffers_white_paper.html.md': 'white_paper.md'
|
||||
'flatbuffers_grammar.html.md': 'grammar.md'
|
||||
'flatbuffers_internals.html.md': 'internals.md'
|
||||
'intermediate_representation.html.md': 'intermediate_representation.md'
|
||||
'flatbuffers_benchmarks.html.md': 'benchmarks.md'
|
||||
'flexbuffers.html.md': 'flexbuffers.md'
|
||||
'contributing.html.md': 'contributing.md'
|
||||
|
||||
|
||||
markdown_extensions:
|
||||
- admonition
|
||||
- attr_list
|
||||
- md_in_html
|
||||
- pymdownx.critic
|
||||
- pymdownx.details
|
||||
- pymdownx.emoji:
|
||||
emoji_index: !!python/name:material.extensions.emoji.twemoji
|
||||
emoji_generator: !!python/name:material.extensions.emoji.to_svg
|
||||
- pymdownx.snippets:
|
||||
# Allows direct embedded of remote files
|
||||
url_download: true
|
||||
- pymdownx.superfences
|
||||
- pymdownx.tabbed:
|
||||
alternate_style: true
|
||||
slugify: !!python/object/apply:pymdownx.slugs.slugify
|
||||
kwds:
|
||||
case: lower
|
||||
- pymdownx.highlight:
|
||||
extend_pygments_lang:
|
||||
# PHP wasn't highlighting correctly. This is a work around found
|
||||
# https://github.com/squidfunk/mkdocs-material/issues/138#issuecomment-2294025627
|
||||
- name: php
|
||||
lang: php
|
||||
options:
|
||||
startinline: true
|
||||
- tables
|
||||
|
||||
|
||||
|
||||
nav:
|
||||
- Overview: "index.md"
|
||||
- Quick Start: "quick_start.md"
|
||||
- Tutorial: "tutorial.md"
|
||||
- Compiler (flatc):
|
||||
- Building: "building.md"
|
||||
- Using: "flatc.md"
|
||||
- Schema (.fbs):
|
||||
- Overview: "schema.md"
|
||||
- Evolution: "evolution.md"
|
||||
- Grammar: "grammar.md"
|
||||
- Language Guides:
|
||||
- C: "languages/c.md"
|
||||
- C++: "languages/cpp.md"
|
||||
- C#: "languages/c_sharp.md"
|
||||
- Dart: "languages/dart.md"
|
||||
- Go: "languages/go.md"
|
||||
- Java: "languages/java.md"
|
||||
- JavaScript: "languages/javascript.md"
|
||||
- Kotlin: "languages/kotlin.md"
|
||||
- Lobster: "languages/lobster.md"
|
||||
- Lua: "languages/lua.md"
|
||||
- PHP: "languages/php.md"
|
||||
- Python: "languages/python.md"
|
||||
- Rust: "languages/rust.md"
|
||||
- Swift: "languages/swift.md"
|
||||
- TypeScript: "languages/typescript.md"
|
||||
- Supported Configurations: "support.md"
|
||||
- White Paper: "white_paper.md"
|
||||
- Advanced:
|
||||
- FlatBuffers Internals: "internals.md"
|
||||
- Intermediate Representation: "intermediate_representation.md"
|
||||
- Annotating Buffers (.afb): "annotation.md"
|
||||
- Benchmarks: "benchmarks.md"
|
||||
- FlexBuffers (Schema-less version): "flexbuffers.md"
|
||||
- Contributing: "contributing.md"
|
||||
10
docs/overrides/404.html
Normal file
10
docs/overrides/404.html
Normal file
@@ -0,0 +1,10 @@
|
||||
{% extends "main.html" %}
|
||||
|
||||
<!-- Content -->
|
||||
{% block content %}
|
||||
<h1>404 - Not found</h1>
|
||||
<br>
|
||||
FlatBuffers has migrated their documentation system recently.
|
||||
|
||||
Please <a href="https://github.com/google/flatbuffers/issues/new?template=404-doc.md">file an issue</a> indicating the broken link.
|
||||
{% endblock %}
|
||||
1
docs/overrides/main.html
Normal file
1
docs/overrides/main.html
Normal file
@@ -0,0 +1 @@
|
||||
{% extends "base.html" %}
|
||||
1
docs/source/CNAME
Normal file
1
docs/source/CNAME
Normal file
@@ -0,0 +1 @@
|
||||
flatbuffers.dev
|
||||
@@ -1 +0,0 @@
|
||||
../../CONTRIBUTING.md
|
||||
@@ -1,188 +0,0 @@
|
||||
FlatBuffers {#flatbuffers_index}
|
||||
===========
|
||||
|
||||
# Overview {#flatbuffers_overview}
|
||||
|
||||
[FlatBuffers](@ref flatbuffers_overview) is an efficient cross platform
|
||||
serialization library for C++, C#, C, Go, Java, Kotlin, JavaScript, Lobster, Lua, TypeScript, PHP, Python, Rust and Swift.
|
||||
It was originally created at Google for game development and other
|
||||
performance-critical applications.
|
||||
|
||||
It is available as Open Source on [GitHub](http://github.com/google/flatbuffers)
|
||||
under the Apache license, v2 (see LICENSE).
|
||||
|
||||
## Why use FlatBuffers?
|
||||
|
||||
- **Access to serialized data without parsing/unpacking** - What sets
|
||||
FlatBuffers apart is that it represents hierarchical data in a flat
|
||||
binary buffer in such a way that it can still be accessed directly
|
||||
without parsing/unpacking, while also still supporting data
|
||||
structure evolution (forwards/backwards compatibility).
|
||||
|
||||
- **Memory efficiency and speed** - The only memory needed to access
|
||||
your data is that of the buffer. It requires 0 additional allocations
|
||||
(in C++, other languages may vary). FlatBuffers is also very
|
||||
suitable for use with mmap (or streaming), requiring only part of the
|
||||
buffer to be in memory. Access is close to the speed of raw
|
||||
struct access with only one extra indirection (a kind of vtable) to
|
||||
allow for format evolution and optional fields. It is aimed at
|
||||
projects where spending time and space (many memory allocations) to
|
||||
be able to access or construct serialized data is undesirable, such
|
||||
as in games or any other performance sensitive applications. See the
|
||||
[benchmarks](@ref flatbuffers_benchmarks) for details.
|
||||
|
||||
- **Flexible** - Optional fields means not only do you get great
|
||||
forwards and backwards compatibility (increasingly important for
|
||||
long-lived games: don't have to update all data with each new
|
||||
version!). It also means you have a lot of choice in what data you
|
||||
write and what data you don't, and how you design data structures.
|
||||
|
||||
- **Tiny code footprint** - Small amounts of generated code, and just
|
||||
a single small header as the minimum dependency, which is very easy
|
||||
to integrate. Again, see the benchmark section for details.
|
||||
|
||||
- **Strongly typed** - Errors happen at compile time rather than
|
||||
manually having to write repetitive and error prone run-time checks.
|
||||
Useful code can be generated for you.
|
||||
|
||||
- **Convenient to use** - Generated C++ code allows for terse access
|
||||
& construction code. Then there's optional functionality for parsing
|
||||
schemas and JSON-like text representations at runtime efficiently if
|
||||
needed (faster and more memory efficient than other JSON
|
||||
parsers).
|
||||
|
||||
Java, Kotlin and Go code supports object-reuse. C# has efficient struct based
|
||||
accessors.
|
||||
|
||||
- **Cross platform code with no dependencies** - C++ code will work
|
||||
with any recent gcc/clang and VS2010. Comes with build files for the tests &
|
||||
samples (Android .mk files, and cmake for all other platforms).
|
||||
|
||||
### Why not use Protocol Buffers, or .. ?
|
||||
|
||||
Protocol Buffers is indeed relatively similar to FlatBuffers,
|
||||
with the primary difference being that FlatBuffers does not need a parsing/
|
||||
unpacking step to a secondary representation before you can
|
||||
access data, often coupled with per-object memory allocation. The code
|
||||
is an order of magnitude bigger, too. Protocol Buffers has no optional
|
||||
text import/export.
|
||||
|
||||
### But all the cool kids use JSON!
|
||||
|
||||
JSON is very readable (which is why we use it as our optional text
|
||||
format) and very convenient when used together with dynamically typed
|
||||
languages (such as JavaScript). When serializing data from statically
|
||||
typed languages, however, JSON not only has the obvious drawback of runtime
|
||||
inefficiency, but also forces you to write *more* code to access data
|
||||
(counterintuitively) due to its dynamic-typing serialization system.
|
||||
In this context, it is only a better choice for systems that have very
|
||||
little to no information ahead of time about what data needs to be stored.
|
||||
|
||||
If you do need to store data that doesn't fit a schema, FlatBuffers also
|
||||
offers a schema-less (self-describing) version!
|
||||
|
||||
Read more about the "why" of FlatBuffers in the
|
||||
[white paper](@ref flatbuffers_white_paper).
|
||||
|
||||
### Who uses FlatBuffers?
|
||||
- [Cocos2d-x](http://www.cocos2d-x.org/), the #1 open source mobile game
|
||||
engine, uses it to serialize all their
|
||||
[game data](http://www.cocos2d-x.org/reference/native-cpp/V3.5/d7/d2d/namespaceflatbuffers.html).
|
||||
- [Facebook](http://facebook.com/) uses it for client-server communication in
|
||||
their Android app. They have a nice
|
||||
[article](https://code.facebook.com/posts/872547912839369/improving-facebook-s-performance-on-android-with-flatbuffers/)
|
||||
explaining how it speeds up loading their posts.
|
||||
- [Fun Propulsion Labs](https://developers.google.com/games/#Tools)
|
||||
at Google uses it extensively in all their libraries and games.
|
||||
|
||||
## Usage in brief
|
||||
|
||||
This section is a quick rundown of how to use this system. Subsequent
|
||||
sections provide a more in-depth usage guide.
|
||||
|
||||
- Write a schema file that allows you to define the data structures
|
||||
you may want to serialize. Fields can have a scalar type
|
||||
(ints/floats of all sizes), or they can be a: string; array of any type;
|
||||
reference to yet another object; or, a set of possible objects (unions).
|
||||
Fields are optional and have defaults, so they don't need to be
|
||||
present for every object instance.
|
||||
|
||||
- Use `flatc` (the FlatBuffer compiler) to generate a C++ header (or
|
||||
Java/Kotlin/C#/Go/Python.. classes) with helper classes to access and construct
|
||||
serialized data. This header (say `mydata_generated.h`) only depends on
|
||||
`flatbuffers.h`, which defines the core functionality.
|
||||
|
||||
- Use the `FlatBufferBuilder` class to construct a flat binary buffer.
|
||||
The generated functions allow you to add objects to this
|
||||
buffer recursively, often as simply as making a single function call.
|
||||
|
||||
- Store or send your buffer somewhere!
|
||||
|
||||
- When reading it back, you can obtain the pointer to the root object
|
||||
from the binary buffer, and from there traverse it conveniently
|
||||
in-place with `object->field()`.
|
||||
|
||||
## In-depth documentation
|
||||
|
||||
- How to [build the compiler](@ref flatbuffers_guide_building) and samples on
|
||||
various platforms.
|
||||
- How to [use the compiler](@ref flatbuffers_guide_using_schema_compiler).
|
||||
- How to [write a schema](@ref flatbuffers_guide_writing_schema).
|
||||
- How to [use the generated C++ code](@ref flatbuffers_guide_use_cpp) in your
|
||||
own programs.
|
||||
- How to [use the generated Java code](@ref flatbuffers_guide_use_java)
|
||||
in your own programs.
|
||||
- How to [use the generated C# code](@ref flatbuffers_guide_use_c-sharp)
|
||||
in your own programs.
|
||||
- How to [use the generated Kotlin code](@ref flatbuffers_guide_use_kotlin)
|
||||
in your own programs.
|
||||
- How to [use the generated Go code](@ref flatbuffers_guide_use_go) in your
|
||||
own programs.
|
||||
- How to [use the generated Lua code](@ref flatbuffers_guide_use_lua) in your
|
||||
own programs.
|
||||
- How to [use the generated JavaScript code](@ref flatbuffers_guide_use_javascript) in your
|
||||
own programs.
|
||||
- How to [use the generated TypeScript code](@ref flatbuffers_guide_use_typescript) in your
|
||||
own programs.
|
||||
- How to [use FlatBuffers in C with `flatcc`](@ref flatbuffers_guide_use_c) in your
|
||||
own programs.
|
||||
- How to [use the generated Lobster code](@ref flatbuffers_guide_use_lobster) in your
|
||||
own programs.
|
||||
- How to [use the generated Rust code](@ref flatbuffers_guide_use_rust) in your
|
||||
own programs.
|
||||
- How to [use the generated Swift code](@ref flatbuffers_guide_use_swift) in your
|
||||
own programs.
|
||||
- [Support matrix](@ref flatbuffers_support) for platforms/languages/features.
|
||||
- Some [benchmarks](@ref flatbuffers_benchmarks) showing the advantage of
|
||||
using FlatBuffers.
|
||||
- A [white paper](@ref flatbuffers_white_paper) explaining the "why" of
|
||||
FlatBuffers.
|
||||
- How to use the [schema-less](@ref flexbuffers) version of
|
||||
FlatBuffers.
|
||||
- A description of the [internals](@ref flatbuffers_internals) of FlatBuffers.
|
||||
- A formal [grammar](@ref flatbuffers_grammar) of the schema language.
|
||||
|
||||
## Online resources
|
||||
|
||||
- [GitHub repository](http://github.com/google/flatbuffers)
|
||||
- [Landing page](http://google.github.io/flatbuffers)
|
||||
- [FlatBuffers Google Group](https://groups.google.com/forum/#!forum/flatbuffers)
|
||||
- [Discord](https://discord.gg/6qgKs3R) and [Gitter](https://gitter.im/lobster_programming_language/community) chat.
|
||||
- [FlatBuffers Issues Tracker](http://github.com/google/flatbuffers/issues)
|
||||
- Independent implementations & tools:
|
||||
- [FlatCC](https://github.com/dvidelabs/flatcc) Alternative FlatBuffers
|
||||
parser, code generator and runtime all in C.
|
||||
- Videos:
|
||||
- Colt's [DevByte](https://www.youtube.com/watch?v=iQTxMkSJ1dQ).
|
||||
- GDC 2015 [Lightning Talk](https://www.youtube.com/watch?v=olmL1fUnQAQ).
|
||||
- FlatBuffers for [Go](https://www.youtube.com/watch?v=-BPVId_lA5w).
|
||||
- Evolution of FlatBuffers
|
||||
[visualization](https://www.youtube.com/watch?v=a0QE0xS8rKM).
|
||||
- Useful documentation created by others:
|
||||
- [FlatBuffers in Go](https://rwinslow.com/tags/flatbuffers/)
|
||||
- [FlatBuffers in Android](http://frogermcs.github.io/flatbuffers-in-android-introdution/)
|
||||
- [Parsing JSON to FlatBuffers in Java](http://frogermcs.github.io/json-parsing-with-flatbuffers-in-android/)
|
||||
- [FlatBuffers in Unity](http://exiin.com/blog/flatbuffers-for-unity-sample-code/)
|
||||
- [FlexBuffers C#](https://github.com/mzaks/FlexBuffers-CSharp) and
|
||||
[article](https://medium.com/@icex33/flexbuffers-for-unity3d-4d1ab5c53fbe?)
|
||||
on its use.
|
||||
@@ -1,26 +0,0 @@
|
||||
Go API
|
||||
======
|
||||
|
||||
\addtogroup flatbuffers_go_api
|
||||
|
||||
<!-- Note: The `GoApi_generate.txt` code snippet was generated using `godoc` and
|
||||
customized for use with this markdown file. To regenerate the file, use the
|
||||
`godoc` tool (http://godoc.org) with the files in the `flatbuffers/go`
|
||||
folder.
|
||||
|
||||
You may need to ensure that copies of the files exist in the `src/`
|
||||
subfolder at the path set by the `$GOROOT` environment variable. You can
|
||||
either move the files to `$GOROOT/src/flatbuffers` manually, if `$GOROOT`
|
||||
is already set, otherwise you will need to manually set the `$GOROOT`
|
||||
variable to a path and create `src/flatbuffers` subfolders at that path.
|
||||
Then copy the flatbuffers files into `$GOROOT/src/flatbuffers`. (Some
|
||||
versions of `godoc` include a `-path` flag. This could be used instead, if
|
||||
available).
|
||||
|
||||
Once the files exist at the `$GOROOT/src/flatbuffers` location, you can
|
||||
regenerate this doc using the following command:
|
||||
`godoc flatbuffers > GoApi_generated.txt`.
|
||||
|
||||
After the documentation is generated, you will have to manually remove any
|
||||
non-user facing documentation from this file. -->
|
||||
\snippet GoApi_generated.txt Go API
|
||||
@@ -1,125 +0,0 @@
|
||||
// This file was generated using `godoc` and customized for use with the
|
||||
// API Reference documentation. To recreate this file, use the `godoc` tool
|
||||
// (http://godoc.org) with the files in the `flatbuffers/go` folder.
|
||||
//
|
||||
// Note: You may need to ensure that copies of the files exist in the
|
||||
// `src/` subfolder at the path set by the `$GOROOT` environment variable.
|
||||
// You can either move the files to `$GOROOT/src/flatbuffers` manually, if
|
||||
// `$GOROOT` is already set, otherwise you will need to manually set the
|
||||
// `$GOROOT` variable to a path and create `src/flatbuffers` subfolders at that
|
||||
// path. Then copy these files into `$GOROOT/src/flatbuffers`. (Some versions of
|
||||
// `godoc` include a `-path` flag. This could be used instead, if available).
|
||||
//
|
||||
// Once the files exist at the `$GOROOT/src/flatbuffers` location, you can
|
||||
// regenerate this doc using the following command:
|
||||
// `godoc flatbuffers > GoApi_generated.txt`.
|
||||
//
|
||||
// After the documentation is generated, you will have to manually remove any
|
||||
// non-user facing documentation from this file.
|
||||
|
||||
/// [Go API]
|
||||
PACKAGE DOCUMENTATION
|
||||
|
||||
package flatbuffers
|
||||
Package flatbuffers provides facilities to read and write flatbuffers
|
||||
objects.
|
||||
|
||||
TYPES
|
||||
|
||||
type Builder struct {
|
||||
// `Bytes` gives raw access to the buffer. Most users will want to use
|
||||
// FinishedBytes() instead.
|
||||
Bytes []byte
|
||||
}
|
||||
Builder is a state machine for creating FlatBuffer objects. Use a
|
||||
Builder to construct object(s) starting from leaf nodes.
|
||||
|
||||
A Builder constructs byte buffers in a last-first manner for simplicity
|
||||
and performance.
|
||||
|
||||
FUNCTIONS
|
||||
|
||||
func NewBuilder(initialSize int) *Builder
|
||||
NewBuilder initializes a Builder of size `initial_size`. The internal
|
||||
buffer is grown as needed.
|
||||
|
||||
func (b *Builder) CreateByteString(s []byte) UOffsetT
|
||||
CreateByteString writes a byte slice as a string (null-terminated).
|
||||
|
||||
func (b *Builder) CreateByteVector(v []byte) UOffsetT
|
||||
CreateByteVector writes a ubyte vector
|
||||
|
||||
func (b *Builder) CreateString(s string) UOffsetT
|
||||
CreateString writes a null-terminated string as a vector.
|
||||
|
||||
func (b *Builder) EndVector(vectorNumElems int) UOffsetT
|
||||
EndVector writes data necessary to finish vector construction.
|
||||
|
||||
func (b *Builder) Finish(rootTable UOffsetT)
|
||||
Finish finalizes a buffer, pointing to the given `rootTable`.
|
||||
|
||||
func (b *Builder) FinishedBytes() []byte
|
||||
FinishedBytes returns a pointer to the written data in the byte buffer.
|
||||
Panics if the builder is not in a finished state (which is caused by
|
||||
calling `Finish()`).
|
||||
|
||||
func (b *Builder) Head() UOffsetT
|
||||
Head gives the start of useful data in the underlying byte buffer. Note:
|
||||
unlike other functions, this value is interpreted as from the left.
|
||||
|
||||
func (b *Builder) PrependBool(x bool)
|
||||
PrependBool prepends a bool to the Builder buffer. Aligns and checks for
|
||||
space.
|
||||
|
||||
func (b *Builder) PrependByte(x byte)
|
||||
PrependByte prepends a byte to the Builder buffer. Aligns and checks for
|
||||
space.
|
||||
|
||||
func (b *Builder) PrependFloat32(x float32)
|
||||
PrependFloat32 prepends a float32 to the Builder buffer. Aligns and
|
||||
checks for space.
|
||||
|
||||
func (b *Builder) PrependFloat64(x float64)
|
||||
PrependFloat64 prepends a float64 to the Builder buffer. Aligns and
|
||||
checks for space.
|
||||
|
||||
func (b *Builder) PrependInt16(x int16)
|
||||
PrependInt16 prepends a int16 to the Builder buffer. Aligns and checks
|
||||
for space.
|
||||
|
||||
func (b *Builder) PrependInt32(x int32)
|
||||
PrependInt32 prepends a int32 to the Builder buffer. Aligns and checks
|
||||
for space.
|
||||
|
||||
func (b *Builder) PrependInt64(x int64)
|
||||
PrependInt64 prepends a int64 to the Builder buffer. Aligns and checks
|
||||
for space.
|
||||
|
||||
func (b *Builder) PrependInt8(x int8)
|
||||
PrependInt8 prepends a int8 to the Builder buffer. Aligns and checks for
|
||||
space.
|
||||
|
||||
func (b *Builder) PrependUOffsetT(off UOffsetT)
|
||||
PrependUOffsetT prepends an UOffsetT, relative to where it will be
|
||||
written.
|
||||
|
||||
func (b *Builder) PrependUint16(x uint16)
|
||||
PrependUint16 prepends a uint16 to the Builder buffer. Aligns and checks
|
||||
for space.
|
||||
|
||||
func (b *Builder) PrependUint32(x uint32)
|
||||
PrependUint32 prepends a uint32 to the Builder buffer. Aligns and checks
|
||||
for space.
|
||||
|
||||
func (b *Builder) PrependUint64(x uint64)
|
||||
PrependUint64 prepends a uint64 to the Builder buffer. Aligns and checks
|
||||
for space.
|
||||
|
||||
func (b *Builder) PrependUint8(x uint8)
|
||||
PrependUint8 prepends a uint8 to the Builder buffer. Aligns and checks
|
||||
for space.
|
||||
|
||||
func (b *Builder) Reset()
|
||||
Reset truncates the underlying Builder buffer, facilitating alloc-free
|
||||
reuse of a Builder. It also resets bookkeeping data.
|
||||
/// [Go API]
|
||||
@@ -1,74 +0,0 @@
|
||||
Grammar of the schema language {#flatbuffers_grammar}
|
||||
==============================
|
||||
|
||||
schema = include*
|
||||
( namespace\_decl | type\_decl | enum\_decl | root\_decl |
|
||||
file_extension_decl | file_identifier_decl |
|
||||
attribute\_decl | rpc\_decl | object )*
|
||||
|
||||
include = `include` string\_constant `;`
|
||||
|
||||
namespace\_decl = `namespace` ident ( `.` ident )* `;`
|
||||
|
||||
attribute\_decl = `attribute` ident | `"` ident `"` `;`
|
||||
|
||||
type\_decl = ( `table` | `struct` ) ident metadata `{` field\_decl+ `}`
|
||||
|
||||
enum\_decl = ( `enum` ident `:` type | `union` ident ) metadata `{`
|
||||
commasep( enumval\_decl ) `}`
|
||||
|
||||
root\_decl = `root_type` ident `;`
|
||||
|
||||
field\_decl = ident `:` type [ `=` scalar ] metadata `;`
|
||||
|
||||
rpc\_decl = `rpc_service` ident `{` rpc\_method+ `}`
|
||||
|
||||
rpc\_method = ident `(` ident `)` `:` ident metadata `;`
|
||||
|
||||
type = `bool` | `byte` | `ubyte` | `short` | `ushort` | `int` | `uint` |
|
||||
`float` | `long` | `ulong` | `double` |
|
||||
`int8` | `uint8` | `int16` | `uint16` | `int32` | `uint32`| `int64` | `uint64` |
|
||||
`float32` | `float64` |
|
||||
`string` | `[` type `]` | ident
|
||||
|
||||
enumval\_decl = ident [ `=` integer\_constant ] metadata
|
||||
|
||||
metadata = [ `(` commasep( ident [ `:` single\_value ] ) `)` ]
|
||||
|
||||
scalar = boolean\_constant | integer\_constant | float\_constant
|
||||
|
||||
object = `{` commasep( ident `:` value ) `}`
|
||||
|
||||
single\_value = scalar | string\_constant
|
||||
|
||||
value = single\_value | object | `[` commasep( value ) `]`
|
||||
|
||||
commasep(x) = [ x ( `,` x )\* ]
|
||||
|
||||
file_extension_decl = `file_extension` string\_constant `;`
|
||||
|
||||
file_identifier_decl = `file_identifier` string\_constant `;`
|
||||
|
||||
string\_constant = `\".*?\"`
|
||||
|
||||
ident = `[a-zA-Z_][a-zA-Z0-9_]*`
|
||||
|
||||
`[:digit:]` = `[0-9]`
|
||||
|
||||
`[:xdigit:]` = `[0-9a-fA-F]`
|
||||
|
||||
dec\_integer\_constant = `[-+]?[:digit:]+`
|
||||
|
||||
hex\_integer\_constant = `[-+]?0[xX][:xdigit:]+`
|
||||
|
||||
integer\_constant = dec\_integer\_constant | hex\_integer\_constant
|
||||
|
||||
dec\_float\_constant = `[-+]?(([.][:digit:]+)|([:digit:]+[.][:digit:]*)|([:digit:]+))([eE][-+]?[:digit:]+)?`
|
||||
|
||||
hex\_float\_constant = `[-+]?0[xX](([.][:xdigit:]+)|([:xdigit:]+[.][:xdigit:]*)|([:xdigit:]+))([pP][-+]?[:digit:]+)`
|
||||
|
||||
special\_float\_constant = `[-+]?(nan|inf|infinity)`
|
||||
|
||||
float\_constant = dec\_float\_constant | hex\_float\_constant | special\_float\_constant
|
||||
|
||||
boolean\_constant = `true` | `false`
|
||||
@@ -1,32 +0,0 @@
|
||||
## Prerequisites
|
||||
|
||||
To generate the docs for FlatBuffers from the source files, you
|
||||
will first need to install two programs.
|
||||
|
||||
1. You will need to install `doxygen`. See
|
||||
[Download Doxygen](https://doxygen.nl/download.html).
|
||||
|
||||
2. You will need to install `doxypypy` to format python comments appropriately.
|
||||
Install it from [here](https://github.com/Feneric/doxypypy).
|
||||
|
||||
*Note: You will need both `doxygen` and `doxypypy` to be in your
|
||||
[PATH](https://en.wikipedia.org/wiki/PATH_(variable)) environment variable.*
|
||||
|
||||
After you have both of those files installed and in your path, you need to
|
||||
set up the `py_filter` to invoke `doxypypy` from `doxygen`.
|
||||
|
||||
Follow the steps
|
||||
[here](https://github.com/Feneric/doxypypy#invoking-doxypypy-from-doxygen).
|
||||
|
||||
## Generating Docs
|
||||
|
||||
Run the following commands to generate the docs:
|
||||
|
||||
`cd flatbuffers/docs/source`
|
||||
`doxygen`
|
||||
|
||||
The output is placed in `flatbuffers/docs/html`.
|
||||
|
||||
*Note: The Go API Reference code must be generated ahead of time. For
|
||||
instructions on how to regenerated this file, please read the comments
|
||||
in `GoApi.md`.*
|
||||
@@ -1,685 +0,0 @@
|
||||
Writing a schema {#flatbuffers_guide_writing_schema}
|
||||
================
|
||||
|
||||
The syntax of the schema language (aka IDL, [Interface Definition Language][])
|
||||
should look quite familiar to users of any of the C family of
|
||||
languages, and also to users of other IDLs. Let's look at an example
|
||||
first:
|
||||
|
||||
// example IDL file
|
||||
|
||||
namespace MyGame;
|
||||
|
||||
attribute "priority";
|
||||
|
||||
enum Color : byte { Red = 1, Green, Blue }
|
||||
|
||||
union Any { Monster, Weapon, Pickup }
|
||||
|
||||
struct Vec3 {
|
||||
x:float;
|
||||
y:float;
|
||||
z:float;
|
||||
}
|
||||
|
||||
table Monster {
|
||||
pos:Vec3;
|
||||
mana:short = 150;
|
||||
hp:short = 100;
|
||||
name:string;
|
||||
friendly:bool = false (deprecated, priority: 1);
|
||||
inventory:[ubyte];
|
||||
color:Color = Blue;
|
||||
test:Any;
|
||||
}
|
||||
|
||||
root_type Monster;
|
||||
|
||||
(`Weapon` & `Pickup` not defined as part of this example).
|
||||
|
||||
### Tables
|
||||
|
||||
Tables are the main way of defining objects in FlatBuffers, and consist of a
|
||||
name (here `Monster`) and a list of fields. Each field has a name, a type, and
|
||||
optionally a default value. If the default value is not specified in the schema,
|
||||
it will be `0` for scalar types, or `null` for other types. Some languages
|
||||
support setting a scalar's default to `null`. This makes the scalar optional.
|
||||
|
||||
Fields do not have to appear in the wire representation, and you can choose
|
||||
to omit fields when constructing an object. You have the flexibility to add
|
||||
fields without fear of bloating your data. This design is also FlatBuffer's
|
||||
mechanism for forward and backwards compatibility. Note that:
|
||||
|
||||
- You can add new fields in the schema ONLY at the end of a table
|
||||
definition. Older data will still
|
||||
read correctly, and give you the default value when read. Older code
|
||||
will simply ignore the new field.
|
||||
If you want to have flexibility to use any order for fields in your
|
||||
schema, you can manually assign ids (much like Protocol Buffers),
|
||||
see the `id` attribute below.
|
||||
|
||||
- You cannot delete fields you don't use anymore from the schema,
|
||||
but you can simply
|
||||
stop writing them into your data for almost the same effect.
|
||||
Additionally you can mark them as `deprecated` as in the example
|
||||
above, which will prevent the generation of accessors in the
|
||||
generated C++, as a way to enforce the field not being used any more.
|
||||
(careful: this may break code!).
|
||||
|
||||
- You may change field names and table names, if you're ok with your
|
||||
code breaking until you've renamed them there too.
|
||||
|
||||
See "Schema evolution examples" below for more on this
|
||||
topic.
|
||||
|
||||
### Structs
|
||||
|
||||
Similar to a table, only now none of the fields are optional (so no defaults
|
||||
either), and fields may not be added or be deprecated. Structs may only contain
|
||||
scalars or other structs. Use this for
|
||||
simple objects where you are very sure no changes will ever be made
|
||||
(as quite clear in the example `Vec3`). Structs use less memory than
|
||||
tables and are even faster to access (they are always stored in-line in their
|
||||
parent object, and use no virtual table).
|
||||
|
||||
### Types
|
||||
|
||||
Built-in scalar types are
|
||||
|
||||
- 8 bit: `byte` (`int8`), `ubyte` (`uint8`), `bool`
|
||||
|
||||
- 16 bit: `short` (`int16`), `ushort` (`uint16`)
|
||||
|
||||
- 32 bit: `int` (`int32`), `uint` (`uint32`), `float` (`float32`)
|
||||
|
||||
- 64 bit: `long` (`int64`), `ulong` (`uint64`), `double` (`float64`)
|
||||
|
||||
The type names in parentheses are alias names such that for example
|
||||
`uint8` can be used in place of `ubyte`, and `int32` can be used in
|
||||
place of `int` without affecting code generation.
|
||||
|
||||
Built-in non-scalar types:
|
||||
|
||||
- Vector of any other type (denoted with `[type]`). Nesting vectors
|
||||
is not supported, instead you can wrap the inner vector in a table.
|
||||
|
||||
- `string`, which may only hold UTF-8 or 7-bit ASCII. For other text encodings
|
||||
or general binary data use vectors (`[byte]` or `[ubyte]`) instead.
|
||||
|
||||
- References to other tables or structs, enums or unions (see
|
||||
below).
|
||||
|
||||
You can't change types of fields once they're used, with the exception
|
||||
of same-size data where a `reinterpret_cast` would give you a desirable result,
|
||||
e.g. you could change a `uint` to an `int` if no values in current data use the
|
||||
high bit yet.
|
||||
|
||||
### Arrays
|
||||
|
||||
Arrays are a convenience short-hand for a fixed-length collection of elements.
|
||||
Arrays can be used to replace the following schema:
|
||||
|
||||
struct Vec3 {
|
||||
x:float;
|
||||
y:float;
|
||||
z:float;
|
||||
}
|
||||
|
||||
with the following schema:
|
||||
|
||||
struct Vec3 {
|
||||
v:[float:3];
|
||||
}
|
||||
|
||||
Both representations are binary equivalent.
|
||||
|
||||
Arrays are currently only supported in a `struct`.
|
||||
|
||||
### Default, Optional and Required Values
|
||||
|
||||
There are three, mutually exclusive, reactions to the non-presence of a table's
|
||||
field in the binary data:
|
||||
|
||||
1. Default valued fields will return the default value (as defined in the schema).
|
||||
2. Optional valued fields will return some form of `null` depending on the
|
||||
local language. (In a sense, `null` is the default value).
|
||||
3. Required fields will cause an error. Flatbuffer verifiers would
|
||||
consider the whole buffer invalid. See the `required` tag below.
|
||||
|
||||
When writing a schema, values are a sequence of digits. Values may be optionally
|
||||
followed by a decimal point (`.`) and more digits, for float constants, or
|
||||
optionally prefixed by a `-`. Floats may also be in scientific notation;
|
||||
optionally ending with an `e` or `E`, followed by a `+` or `-` and more digits.
|
||||
Values can also be the keyword `null`.
|
||||
|
||||
Only scalar values can have defaults, non-scalar (string/vector/table) fields
|
||||
default to `null` when not present.
|
||||
|
||||
You generally do not want to change default values after they're initially
|
||||
defined. Fields that have the default value are not actually stored in the
|
||||
serialized data (see also Gotchas below). Values explicitly written by code
|
||||
generated by the old schema old version, if they happen to be the default, will
|
||||
be read as a different value by code generated with the new schema. This is
|
||||
slightly less bad when converting an optional scalar into a default valued
|
||||
scalar since non-presence would not be overloaded with a previous default value.
|
||||
There are situations, however, where this may be desirable, especially if you
|
||||
can ensure a simultaneous rebuild of all code.
|
||||
|
||||
### Enums
|
||||
|
||||
Define a sequence of named constants, each with a given value, or
|
||||
increasing by one from the previous one. The default first value
|
||||
is `0`. As you can see in the enum declaration, you specify the underlying
|
||||
integral type of the enum with `:` (in this case `byte`), which then determines
|
||||
the type of any fields declared with this enum type.
|
||||
|
||||
Only integer types are allowed, i.e. `byte`, `ubyte`, `short` `ushort`, `int`,
|
||||
`uint`, `long` and `ulong`.
|
||||
|
||||
Typically, enum values should only ever be added, never removed (there is no
|
||||
deprecation for enums). This requires code to handle forwards compatibility
|
||||
itself, by handling unknown enum values.
|
||||
|
||||
### Unions
|
||||
|
||||
Unions share a lot of properties with enums, but instead of new names
|
||||
for constants, you use names of tables. You can then declare
|
||||
a union field, which can hold a reference to any of those types, and
|
||||
additionally a field with the suffix `_type` is generated that holds
|
||||
the corresponding enum value, allowing you to know which type to cast
|
||||
to at runtime.
|
||||
|
||||
It's possible to give an alias name to a type union. This way a type can even be
|
||||
used to mean different things depending on the name used:
|
||||
|
||||
table PointPosition { x:uint; y:uint; }
|
||||
table MarkerPosition {}
|
||||
union Position {
|
||||
Start:MarkerPosition,
|
||||
Point:PointPosition,
|
||||
Finish:MarkerPosition
|
||||
}
|
||||
|
||||
Unions contain a special `NONE` marker to denote that no value is stored so that
|
||||
name cannot be used as an alias.
|
||||
|
||||
Unions are a good way to be able to send multiple message types as a FlatBuffer.
|
||||
Note that because a union field is really two fields, it must always be
|
||||
part of a table, it cannot be the root of a FlatBuffer by itself.
|
||||
|
||||
If you have a need to distinguish between different FlatBuffers in a more
|
||||
open-ended way, for example for use as files, see the file identification
|
||||
feature below.
|
||||
|
||||
There is an experimental support only in C++ for a vector of unions (and
|
||||
types). In the example IDL file above, use [Any] to add a vector of Any to
|
||||
Monster table. There is also experimental support for other types besides
|
||||
tables in unions, in particular structs and strings. There's no direct support
|
||||
for scalars in unions, but they can be wrapped in a struct at no space cost.
|
||||
|
||||
### Namespaces
|
||||
|
||||
These will generate the corresponding namespace in C++ for all helper
|
||||
code, and packages in Java. You can use `.` to specify nested namespaces /
|
||||
packages.
|
||||
|
||||
### Includes
|
||||
|
||||
You can include other schemas files in your current one, e.g.:
|
||||
|
||||
include "mydefinitions.fbs";
|
||||
|
||||
This makes it easier to refer to types defined elsewhere. `include`
|
||||
automatically ensures each file is parsed just once, even when referred to
|
||||
more than once.
|
||||
|
||||
When using the `flatc` compiler to generate code for schema definitions,
|
||||
only definitions in the current file will be generated, not those from the
|
||||
included files (those you still generate separately).
|
||||
|
||||
### Root type
|
||||
|
||||
This declares what you consider to be the root table of the serialized
|
||||
data. This is particularly important for parsing JSON data, which doesn't
|
||||
include object type information.
|
||||
|
||||
### File identification and extension
|
||||
|
||||
Typically, a FlatBuffer binary buffer is not self-describing, i.e. it
|
||||
needs you to know its schema to parse it correctly. But if you
|
||||
want to use a FlatBuffer as a file format, it would be convenient
|
||||
to be able to have a "magic number" in there, like most file formats
|
||||
have, to be able to do a sanity check to see if you're reading the
|
||||
kind of file you're expecting.
|
||||
|
||||
Now, you can always prefix a FlatBuffer with your own file header,
|
||||
but FlatBuffers has a built-in way to add an identifier to a
|
||||
FlatBuffer that takes up minimal space, and keeps the buffer
|
||||
compatible with buffers that don't have such an identifier.
|
||||
|
||||
You can specify in a schema, similar to `root_type`, that you intend
|
||||
for this type of FlatBuffer to be used as a file format:
|
||||
|
||||
file_identifier "MYFI";
|
||||
|
||||
Identifiers must always be exactly 4 characters long. These 4 characters
|
||||
will end up as bytes at offsets 4-7 (inclusive) in the buffer.
|
||||
|
||||
For any schema that has such an identifier, `flatc` will automatically
|
||||
add the identifier to any binaries it generates (with `-b`),
|
||||
and generated calls like `FinishMonsterBuffer` also add the identifier.
|
||||
If you have specified an identifier and wish to generate a buffer
|
||||
without one, you can always still do so by calling
|
||||
`FlatBufferBuilder::Finish` explicitly.
|
||||
|
||||
After loading a buffer, you can use a call like
|
||||
`MonsterBufferHasIdentifier` to check if the identifier is present.
|
||||
|
||||
Note that this is best for open-ended uses such as files. If you simply wanted
|
||||
to send one of a set of possible messages over a network for example, you'd
|
||||
be better off with a union.
|
||||
|
||||
Additionally, by default `flatc` will output binary files as `.bin`.
|
||||
This declaration in the schema will change that to whatever you want:
|
||||
|
||||
file_extension "ext";
|
||||
|
||||
### RPC interface declarations
|
||||
|
||||
You can declare RPC calls in a schema, that define a set of functions
|
||||
that take a FlatBuffer as an argument (the request) and return a FlatBuffer
|
||||
as the response (both of which must be table types):
|
||||
|
||||
rpc_service MonsterStorage {
|
||||
Store(Monster):StoreResponse;
|
||||
Retrieve(MonsterId):Monster;
|
||||
}
|
||||
|
||||
What code this produces and how it is used depends on language and RPC system
|
||||
used, there is preliminary support for GRPC through the `--grpc` code generator,
|
||||
see `grpc/tests` for an example.
|
||||
|
||||
### Comments & documentation
|
||||
|
||||
May be written as in most C-based languages. Additionally, a triple
|
||||
comment (`///`) on a line by itself signals that a comment is documentation
|
||||
for whatever is declared on the line after it
|
||||
(table/struct/field/enum/union/element), and the comment is output
|
||||
in the corresponding C++ code. Multiple such lines per item are allowed.
|
||||
|
||||
### Attributes
|
||||
|
||||
Attributes may be attached to a declaration, behind a field/enum value,
|
||||
or after the name of a table/struct/enum/union. These may either have
|
||||
a value or not. Some attributes like `deprecated` are understood by
|
||||
the compiler; user defined ones need to be declared with the attribute
|
||||
declaration (like `priority` in the example above), and are
|
||||
available to query if you parse the schema at runtime.
|
||||
This is useful if you write your own code generators/editors etc., and
|
||||
you wish to add additional information specific to your tool (such as a
|
||||
help text).
|
||||
|
||||
Current understood attributes:
|
||||
|
||||
- `id: n` (on a table field): manually set the field identifier to `n`.
|
||||
If you use this attribute, you must use it on ALL fields of this table,
|
||||
and the numbers must be a contiguous range from 0 onwards.
|
||||
Additionally, since a union type effectively adds two fields, its
|
||||
id must be that of the second field (the first field is the type
|
||||
field and not explicitly declared in the schema).
|
||||
For example, if the last field before the union field had id 6,
|
||||
the union field should have id 8, and the unions type field will
|
||||
implicitly be 7.
|
||||
IDs allow the fields to be placed in any order in the schema.
|
||||
When a new field is added to the schema it must use the next available ID.
|
||||
- `deprecated` (on a field): do not generate accessors for this field
|
||||
anymore, code should stop using this data. Old data may still contain this
|
||||
field, but it won't be accessible anymore by newer code. Note that if you
|
||||
deprecate a field that was previous required, old code may fail to validate
|
||||
new data (when using the optional verifier).
|
||||
- `required` (on a non-scalar table field): this field must always be set.
|
||||
By default, fields do not need to be present in the binary. This is
|
||||
desirable, as it helps with forwards/backwards compatibility, and
|
||||
flexibility of data structures. By specifying this attribute, you make non-
|
||||
presence in an error for both reader and writer. The reading code may access
|
||||
the field directly, without checking for null. If the constructing code does
|
||||
not initialize this field, they will get an assert, and also the verifier
|
||||
will fail on buffers that have missing required fields. Both adding and
|
||||
removing this attribute may be forwards/backwards incompatible as readers
|
||||
will be unable read old or new data, respectively, unless the data happens to
|
||||
always have the field set.
|
||||
- `force_align: size` (on a struct): force the alignment of this struct
|
||||
to be something higher than what it is naturally aligned to. Causes
|
||||
these structs to be aligned to that amount inside a buffer, IF that
|
||||
buffer is allocated with that alignment (which is not necessarily
|
||||
the case for buffers accessed directly inside a `FlatBufferBuilder`).
|
||||
Note: currently not guaranteed to have an effect when used with
|
||||
`--object-api`, since that may allocate objects at alignments less than
|
||||
what you specify with `force_align`.
|
||||
- `force_align: size` (on a vector): force the alignment of this vector to be
|
||||
something different than what the element size would normally dictate.
|
||||
Note: Now only work for generated C++ code.
|
||||
- `bit_flags` (on an unsigned enum): the values of this field indicate bits,
|
||||
meaning that any unsigned value N specified in the schema will end up
|
||||
representing 1<<N, or if you don't specify values at all, you'll get
|
||||
the sequence 1, 2, 4, 8, ...
|
||||
- `nested_flatbuffer: "table_name"` (on a field): this indicates that the field
|
||||
(which must be a vector of ubyte) contains flatbuffer data, for which the
|
||||
root type is given by `table_name`. The generated code will then produce
|
||||
a convenient accessor for the nested FlatBuffer.
|
||||
- `flexbuffer` (on a field): this indicates that the field
|
||||
(which must be a vector of ubyte) contains flexbuffer data. The generated
|
||||
code will then produce a convenient accessor for the FlexBuffer root.
|
||||
- `key` (on a field): this field is meant to be used as a key when sorting
|
||||
a vector of the type of table it sits in. Can be used for in-place
|
||||
binary search.
|
||||
- `hash` (on a field). This is an (un)signed 32/64 bit integer field, whose
|
||||
value during JSON parsing is allowed to be a string, which will then be
|
||||
stored as its hash. The value of attribute is the hashing algorithm to
|
||||
use, one of `fnv1_32` `fnv1_64` `fnv1a_32` `fnv1a_64`.
|
||||
- `original_order` (on a table): since elements in a table do not need
|
||||
to be stored in any particular order, they are often optimized for
|
||||
space by sorting them to size. This attribute stops that from happening.
|
||||
There should generally not be any reason to use this flag.
|
||||
- 'native_*'. Several attributes have been added to support the [C++ object
|
||||
Based API](@ref flatbuffers_cpp_object_based_api). All such attributes
|
||||
are prefixed with the term "native_".
|
||||
|
||||
|
||||
## JSON Parsing
|
||||
|
||||
The same parser that parses the schema declarations above is also able
|
||||
to parse JSON objects that conform to this schema. So, unlike other JSON
|
||||
parsers, this parser is strongly typed, and parses directly into a FlatBuffer
|
||||
(see the compiler documentation on how to do this from the command line, or
|
||||
the C++ documentation on how to do this at runtime).
|
||||
|
||||
Besides needing a schema, there are a few other changes to how it parses
|
||||
JSON:
|
||||
|
||||
- It accepts field names with and without quotes, like many JSON parsers
|
||||
already do. It outputs them without quotes as well, though can be made
|
||||
to output them using the `strict_json` flag.
|
||||
- If a field has an enum type, the parser will recognize symbolic enum
|
||||
values (with or without quotes) instead of numbers, e.g.
|
||||
`field: EnumVal`. If a field is of integral type, you can still use
|
||||
symbolic names, but values need to be prefixed with their type and
|
||||
need to be quoted, e.g. `field: "Enum.EnumVal"`. For enums
|
||||
representing flags, you may place multiple inside a string
|
||||
separated by spaces to OR them, e.g.
|
||||
`field: "EnumVal1 EnumVal2"` or `field: "Enum.EnumVal1 Enum.EnumVal2"`.
|
||||
- Similarly, for unions, these need to specified with two fields much like
|
||||
you do when serializing from code. E.g. for a field `foo`, you must
|
||||
add a field `foo_type: FooOne` right before the `foo` field, where
|
||||
`FooOne` would be the table out of the union you want to use.
|
||||
- A field that has the value `null` (e.g. `field: null`) is intended to
|
||||
have the default value for that field (thus has the same effect as if
|
||||
that field wasn't specified at all).
|
||||
- It has some built in conversion functions, so you can write for example
|
||||
`rad(180)` where ever you'd normally write `3.14159`.
|
||||
Currently supports the following functions: `rad`, `deg`, `cos`, `sin`,
|
||||
`tan`, `acos`, `asin`, `atan`.
|
||||
|
||||
When parsing JSON, it recognizes the following escape codes in strings:
|
||||
|
||||
- `\n` - linefeed.
|
||||
- `\t` - tab.
|
||||
- `\r` - carriage return.
|
||||
- `\b` - backspace.
|
||||
- `\f` - form feed.
|
||||
- `\"` - double quote.
|
||||
- `\\` - backslash.
|
||||
- `\/` - forward slash.
|
||||
- `\uXXXX` - 16-bit unicode code point, converted to the equivalent UTF-8
|
||||
representation.
|
||||
- `\xXX` - 8-bit binary hexadecimal number XX. This is the only one that is
|
||||
not in the JSON spec (see http://json.org/), but is needed to be able to
|
||||
encode arbitrary binary in strings to text and back without losing
|
||||
information (e.g. the byte 0xFF can't be represented in standard JSON).
|
||||
|
||||
It also generates these escape codes back again when generating JSON from a
|
||||
binary representation.
|
||||
|
||||
When parsing numbers, the parser is more flexible than JSON.
|
||||
A format of numeric literals is more close to the C/C++.
|
||||
According to the [grammar](@ref flatbuffers_grammar), it accepts the following
|
||||
numerical literals:
|
||||
|
||||
- An integer literal can have any number of leading zero `0` digits.
|
||||
Unlike C/C++, the parser ignores a leading zero, not interpreting it as the
|
||||
beginning of the octal number.
|
||||
The numbers `[081, -00094]` are equal to `[81, -94]` decimal integers.
|
||||
- The parser accepts unsigned and signed hexadecimal integer numbers.
|
||||
For example: `[0x123, +0x45, -0x67]` are equal to `[291, 69, -103]` decimals.
|
||||
- The format of float-point numbers is fully compatible with C/C++ format.
|
||||
If a modern C++ compiler is used the parser accepts hexadecimal and special
|
||||
floating-point literals as well:
|
||||
`[-1.0, 2., .3e0, 3.e4, 0x21.34p-5, -inf, nan]`.
|
||||
|
||||
The following conventions for floating-point numbers are used:
|
||||
- The exponent suffix of hexadecimal floating-point number is mandatory.
|
||||
- Parsed `NaN` converted to unsigned IEEE-754 `quiet-NaN` value.
|
||||
|
||||
Extended floating-point support was tested with:
|
||||
- x64 Windows: `MSVC2015` and higher.
|
||||
- x64 Linux: `LLVM 6.0`, `GCC 4.9` and higher.
|
||||
|
||||
For details, see [Use in C++](@ref flatbuffers_guide_use_cpp) section.
|
||||
|
||||
- For compatibility with a JSON lint tool all numeric literals of scalar
|
||||
fields can be wrapped to quoted string:
|
||||
`"1", "2.0", "0x48A", "0x0C.0Ep-1", "-inf", "true"`.
|
||||
|
||||
## Guidelines
|
||||
|
||||
### Efficiency
|
||||
|
||||
FlatBuffers is all about efficiency, but to realize that efficiency you
|
||||
require an efficient schema. There are usually multiple choices on
|
||||
how to represent data that have vastly different size characteristics.
|
||||
|
||||
It is very common nowadays to represent any kind of data as dictionaries
|
||||
(as in e.g. JSON), because of its flexibility and extensibility. While
|
||||
it is possible to emulate this in FlatBuffers (as a vector
|
||||
of tables with key and value(s)), this is a bad match for a strongly
|
||||
typed system like FlatBuffers, leading to relatively large binaries.
|
||||
FlatBuffer tables are more flexible than classes/structs in most systems,
|
||||
since having a large number of fields only few of which are actually
|
||||
used is still efficient. You should thus try to organize your data
|
||||
as much as possible such that you can use tables where you might be
|
||||
tempted to use a dictionary.
|
||||
|
||||
Similarly, strings as values should only be used when they are
|
||||
truly open-ended. If you can, always use an enum instead.
|
||||
|
||||
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,
|
||||
so an alternative to a union is to have a single table that has
|
||||
all the fields of all the data structures you are trying to
|
||||
represent, if they are relatively similar / share many fields.
|
||||
Again, this is efficient because non-present fields are cheap.
|
||||
|
||||
FlatBuffers supports the full range of integer sizes, so try to pick
|
||||
the smallest size needed, rather than defaulting to int/long.
|
||||
|
||||
Remember that you can share data (refer to the same string/table
|
||||
within a buffer), so factoring out repeating data into its own
|
||||
data structure may be worth it.
|
||||
|
||||
### Style guide
|
||||
|
||||
Identifiers in a schema are meant to translate to many different programming
|
||||
languages, so using the style of your "main" language is generally a bad idea.
|
||||
|
||||
For this reason, below is a suggested style guide to adhere to, to keep schemas
|
||||
consistent for interoperation regardless of the target language.
|
||||
|
||||
Where possible, the code generators for specific languages will generate
|
||||
identifiers that adhere to the language style, based on the schema identifiers.
|
||||
|
||||
- Table, struct, enum and rpc names (types): UpperCamelCase.
|
||||
- Table and struct field names: snake_case. This is translated to lowerCamelCase
|
||||
automatically for some languages, e.g. Java.
|
||||
- Enum values: UpperCamelCase.
|
||||
- namespaces: UpperCamelCase.
|
||||
|
||||
Formatting (this is less important, but still worth adhering to):
|
||||
|
||||
- Opening brace: on the same line as the start of the declaration.
|
||||
- Spacing: Indent by 2 spaces. None around `:` for types, on both sides for `=`.
|
||||
|
||||
For an example, see the schema at the top of this file.
|
||||
|
||||
## Gotchas
|
||||
|
||||
### Schemas and version control
|
||||
|
||||
FlatBuffers relies on new field declarations being added at the end, and earlier
|
||||
declarations to not be removed, but be marked deprecated when needed. We think
|
||||
this is an improvement over the manual number assignment that happens in
|
||||
Protocol Buffers (and which is still an option using the `id` attribute
|
||||
mentioned above).
|
||||
|
||||
One place where this is possibly problematic however is source control. If user
|
||||
A adds a field, generates new binary data with this new schema, then tries to
|
||||
commit both to source control after user B already committed a new field also,
|
||||
and just auto-merges the schema, the binary files are now invalid compared to
|
||||
the new schema.
|
||||
|
||||
The solution of course is that you should not be generating binary data before
|
||||
your schema changes have been committed, ensuring consistency with the rest of
|
||||
the world. If this is not practical for you, use explicit field ids, which
|
||||
should always generate a merge conflict if two people try to allocate the same
|
||||
id.
|
||||
|
||||
### Schema evolution examples (tables)
|
||||
|
||||
Some examples to clarify what happens as you change a schema:
|
||||
|
||||
If we have the following original schema:
|
||||
|
||||
table { a:int; b:int; }
|
||||
|
||||
And we extend it:
|
||||
|
||||
table { a:int; b:int; c:int; }
|
||||
|
||||
This is ok. Code compiled with the old schema reading data generated with the
|
||||
new one will simply ignore the presence of the new field. Code compiled with the
|
||||
new schema reading old data will get the default value for `c` (which is 0
|
||||
in this case, since it is not specified).
|
||||
|
||||
table { a:int (deprecated); b:int; }
|
||||
|
||||
This is also ok. Code compiled with the old schema reading newer data will now
|
||||
always get the default value for `a` since it is not present. Code compiled
|
||||
with the new schema now cannot read nor write `a` anymore (any existing code
|
||||
that tries to do so will result in compile errors), but can still read
|
||||
old data (they will ignore the field).
|
||||
|
||||
table { c:int; a:int; b:int; }
|
||||
|
||||
This is NOT ok, as this makes the schemas incompatible. Old code reading newer
|
||||
data will interpret `c` as if it was `a`, and new code reading old data
|
||||
accessing `a` will instead receive `b`.
|
||||
|
||||
table { c:int (id: 2); a:int (id: 0); b:int (id: 1); }
|
||||
|
||||
This is ok. If your intent was to order/group fields in a way that makes sense
|
||||
semantically, you can do so using explicit id assignment. Now we are compatible
|
||||
with the original schema, and the fields can be ordered in any way, as long as
|
||||
we keep the sequence of ids.
|
||||
|
||||
table { b:int; }
|
||||
|
||||
NOT ok. We can only remove a field by deprecation, regardless of whether we use
|
||||
explicit ids or not.
|
||||
|
||||
table { a:uint; b:uint; }
|
||||
|
||||
This is MAYBE ok, and only in the case where the type change is the same size,
|
||||
like here. If old data never contained any negative numbers, this will be
|
||||
safe to do.
|
||||
|
||||
table { a:int = 1; b:int = 2; }
|
||||
|
||||
Generally NOT ok. Any older data written that had 0 values were not written to
|
||||
the buffer, and rely on the default value to be recreated. These will now have
|
||||
those values appear to `1` and `2` instead. There may be cases in which this
|
||||
is ok, but care must be taken.
|
||||
|
||||
table { aa:int; bb:int; }
|
||||
|
||||
Occasionally ok. You've renamed fields, which will break all code (and JSON
|
||||
files!) that use this schema, but as long as the change is obvious, this is not
|
||||
incompatible with the actual binary buffers, since those only ever address
|
||||
fields by id/offset.
|
||||
|
||||
#### Schema evolution examples (unions)
|
||||
|
||||
Suppose we have the following schema:
|
||||
```
|
||||
union Foo { A, B }
|
||||
```
|
||||
We can add another variant at the end.
|
||||
```
|
||||
union Foo { A, B, another_a: A }
|
||||
```
|
||||
and this will be okay. Old code will not recognize `another_a`.
|
||||
However if we add `another_a` anywhere but the end, e.g.
|
||||
```
|
||||
union Foo { A, another_a: A, B }
|
||||
```
|
||||
this is not okay. When new code writes `another_a`, old code will
|
||||
misinterpret it as `B` (and vice versa). However you can explicitly
|
||||
set the union's "discriminant" value like so:
|
||||
```
|
||||
union Foo { A = 1, another_a: A = 3, B = 2 }
|
||||
```
|
||||
This is okay.
|
||||
|
||||
```
|
||||
union Foo { original_a: A = 1, another_a: A = 3, B = 2 }
|
||||
```
|
||||
Renaming fields will break code and any saved human readable representations,
|
||||
such as json files, but the binary buffers will be the same.
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<br>
|
||||
|
||||
### Testing whether a field is present in a table
|
||||
|
||||
Most serialization formats (e.g. JSON or Protocol Buffers) make it very
|
||||
explicit in the format whether a field is present in an object or not,
|
||||
allowing you to use this as "extra" information.
|
||||
|
||||
FlatBuffers will not write fields that are equal to their default value,
|
||||
sometimes resulting in significant space savings. However, this also means we
|
||||
cannot disambiguate the meaning of non-presence as "written default value" or
|
||||
"not written at all". This only applies to scalar fields since only they support
|
||||
default values. Unless otherwise specified, their default is 0.
|
||||
|
||||
If you care about the presence of scalars, most languages support "optional
|
||||
scalars." You can set `null` as the default value in the schema. `null` is a
|
||||
value that's outside of all types, so we will always write if `add_field` is
|
||||
called. The generated field accessor should use the local language's canonical
|
||||
optional type.
|
||||
|
||||
Some `FlatBufferBuilder` implementations have an option called `force_defaults`
|
||||
that circumvents this "not writing defaults" behavior you can then use
|
||||
`IsFieldPresent` to query presence.
|
||||
/
|
||||
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
|
||||
less ergonomic but structs don't take up any more space than the scalar they
|
||||
represent.
|
||||
|
||||
[Interface Definition Language]: https://en.wikipedia.org/wiki/Interface_description_language
|
||||
|
||||
## Writing your own code generator.
|
||||
|
||||
See [our intermediate representation](@ref intermediate_representation).
|
||||
File diff suppressed because it is too large
Load Diff
149
docs/source/annotation.md
Normal file
149
docs/source/annotation.md
Normal file
@@ -0,0 +1,149 @@
|
||||
# Annotating FlatBuffers
|
||||
|
||||
This provides a way to annotate flatbuffer binary data, byte-by-byte, with a
|
||||
schema. It is useful for development purposes and understanding the details of
|
||||
the internal format.
|
||||
|
||||
## Annotating
|
||||
|
||||
Given a `schema`, as either a plain-text (`.fbs`) or a binary schema (`.bfbs`),
|
||||
and `binary` file(s) that were created by the `schema`. You can annotate them
|
||||
using:
|
||||
|
||||
```sh
|
||||
flatc --annotate SCHEMA -- BINARY_FILES...
|
||||
```
|
||||
|
||||
This will produce a set of annotated files (`.afb` Annotated FlatBuffer)
|
||||
corresponding to the input binary files.
|
||||
|
||||
### Example
|
||||
|
||||
Taken from the [tests/annotated_binary](https://github.com/google/flatbuffers/tree/master/tests/annotated_binary).
|
||||
|
||||
```sh
|
||||
cd tests/annotated_binary
|
||||
../../flatc --annotate annotated_binary.fbs -- annotated_binary.bin
|
||||
```
|
||||
|
||||
Which will produce a `annotated_binary.afb` file in the current directory.
|
||||
|
||||
The `annotated_binary.bin` is the flatbufer binary of the data contained within
|
||||
`annotated_binary.json`, which was made by the following command:
|
||||
|
||||
```sh
|
||||
..\..\flatc -b annotated_binary.fbs annotated_binary.json
|
||||
```
|
||||
|
||||
## .afb Text Format
|
||||
|
||||
Currently there is a built-in text-based format for outputting the annotations.
|
||||
A full example is shown here:
|
||||
[`annotated_binary.afb`](https://github.com/google/flatbuffers/blob/master/tests/annotated_binary/annotated_binary.afb)
|
||||
|
||||
The data is organized as a table with fixed [columns](#columns) grouped into
|
||||
Binary [sections](#binary-sections) and [regions](#binary-regions), starting
|
||||
from the beginning of the binary (offset `0`).
|
||||
|
||||
### Columns
|
||||
|
||||
The columns are as follows:
|
||||
|
||||
1. The offset from the start of the binary, expressed in hexadecimal format
|
||||
(e.g. `+0x003c`).
|
||||
|
||||
The prefix `+` is added to make searching for the offset (compared to some
|
||||
random value) a bit easier.
|
||||
|
||||
2. The raw binary data, expressed in hexadecimal format.
|
||||
|
||||
This is in the little endian format the buffer uses internally and what you
|
||||
would see with a normal binary text viewer.
|
||||
|
||||
3. The type of the data.
|
||||
|
||||
This may be the type specified in the schema or some internally defined
|
||||
types:
|
||||
|
||||
|
||||
| Internal Type | Purpose |
|
||||
|---------------|----------------------------------------------------|
|
||||
| `VOffset16` | Virtual table offset, relative to the table offset |
|
||||
| `UOffset32` | Unsigned offset, relative to the current offset |
|
||||
| `SOffset32` | Signed offset, relative to the current offset |
|
||||
|
||||
|
||||
4. The value of the data.
|
||||
|
||||
This is shown in big endian format that is generally written for humans to
|
||||
consume (e.g. `0x0013`). As well as the "casted" value (e.g. `0x0013 `is
|
||||
`19` in decimal) in parentheses.
|
||||
|
||||
5. Notes about the particular data.
|
||||
|
||||
This describes what the data is about, either some internal usage, or tied
|
||||
to the schema.
|
||||
|
||||
### Binary Sections
|
||||
|
||||
The file is broken up into Binary Sections, which are comprised of contiguous
|
||||
[binary regions](#binary-regions) that are logically grouped together. For
|
||||
example, a binary section may be a single instance of a flatbuffer `Table` or
|
||||
its `vtable`. The sections may be labelled with the name of the associated type,
|
||||
as defined in the input schema.
|
||||
|
||||
An example of a `vtable` Binary Section that is associated with the user-defined
|
||||
`AnnotateBinary.Bar` table.
|
||||
|
||||
```
|
||||
vtable (AnnotatedBinary.Bar):
|
||||
+0x00A0 | 08 00 | uint16_t | 0x0008 (8) | size of this vtable
|
||||
+0x00A2 | 13 00 | uint16_t | 0x0013 (19) | size of referring table
|
||||
+0x00A4 | 08 00 | VOffset16 | 0x0008 (8) | offset to field `a` (id: 0)
|
||||
+0x00A6 | 04 00 | VOffset16 | 0x0004 (4) | offset to field `b` (id: 1)
|
||||
```
|
||||
|
||||
These are purely annotative, there is no embedded information about these
|
||||
regions in the flatbuffer itself.
|
||||
|
||||
### Binary Regions
|
||||
|
||||
Binary regions are contiguous bytes regions that are grouped together to form
|
||||
some sort of value, e.g. a `scalar` or an array of scalars. A binary region may
|
||||
be split up over multiple text lines, if the size of the region is large.
|
||||
|
||||
#### Annotation Example
|
||||
|
||||
Looking at an example binary region:
|
||||
|
||||
```
|
||||
vtable (AnnotatedBinary.Bar):
|
||||
+0x00A0 | 08 00 | uint16_t | 0x0008 (8) | size of this vtable
|
||||
```
|
||||
|
||||
The first column (`+0x00A0`) is the offset to this region from the beginning of
|
||||
the buffer.
|
||||
|
||||
The second column are the raw bytes (hexadecimal) that make up this region.
|
||||
These are expressed in the little-endian format that flatbuffers uses for the
|
||||
wire format.
|
||||
|
||||
The third column is the type to interpret the bytes as. For the above example,
|
||||
the type is `uint16_t` which is a 16-bit unsigned integer type.
|
||||
|
||||
The fourth column shows the raw bytes as a compacted, big-endian value. The raw
|
||||
bytes are duplicated in this fashion since it is more intuitive to read the data
|
||||
in the big-endian format (e.g., `0x0008`). This value is followed by the decimal
|
||||
representation of the value (e.g., `(8)`). For strings, the raw string value is
|
||||
shown instead.
|
||||
|
||||
The fifth column is a textual comment on what the value is. As much metadata as
|
||||
known is provided.
|
||||
|
||||
### Offsets
|
||||
|
||||
If the type in the 3rd column is of an absolute offset (`SOffet32` or
|
||||
`Offset32`), the fourth column also shows an `Loc: +0x025A` value which shows
|
||||
where in the binary this region is pointing to. These values are absolute from
|
||||
the beginning of the file, their calculation from the raw value in the 4th
|
||||
column depends on the context.
|
||||
318
docs/source/assets/flatbuffers_logo.svg
Normal file
318
docs/source/assets/flatbuffers_logo.svg
Normal file
@@ -0,0 +1,318 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<!-- Created with Inkscape (http://www.inkscape.org/) -->
|
||||
|
||||
<svg
|
||||
width="48"
|
||||
height="48"
|
||||
viewBox="0 0 12.699999 12.699999"
|
||||
version="1.1"
|
||||
id="svg5"
|
||||
xml:space="preserve"
|
||||
inkscape:version="1.2.1 (9c6d41e410, 2022-07-14)"
|
||||
sodipodi:docname="flatbuffer_logo.svg"
|
||||
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
|
||||
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
|
||||
xmlns:xlink="http://www.w3.org/1999/xlink"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
xmlns:svg="http://www.w3.org/2000/svg"><sodipodi:namedview
|
||||
id="namedview7"
|
||||
pagecolor="#ffffff"
|
||||
bordercolor="#000000"
|
||||
borderopacity="0.25"
|
||||
inkscape:showpageshadow="2"
|
||||
inkscape:pageopacity="0.0"
|
||||
inkscape:pagecheckerboard="0"
|
||||
inkscape:deskcolor="#d1d1d1"
|
||||
inkscape:document-units="mm"
|
||||
showgrid="false"
|
||||
inkscape:zoom="16"
|
||||
inkscape:cx="30.03125"
|
||||
inkscape:cy="31.0625"
|
||||
inkscape:window-width="2560"
|
||||
inkscape:window-height="1377"
|
||||
inkscape:window-x="2552"
|
||||
inkscape:window-y="-8"
|
||||
inkscape:window-maximized="1"
|
||||
inkscape:current-layer="layer1" /><defs
|
||||
id="defs2"><linearGradient
|
||||
inkscape:collect="always"
|
||||
id="linearGradient51996"><stop
|
||||
style="stop-color:#ff0c0c;stop-opacity:1;"
|
||||
offset="0"
|
||||
id="stop51992" /><stop
|
||||
style="stop-color:#ffc402;stop-opacity:1;"
|
||||
offset="1"
|
||||
id="stop51994" /></linearGradient><inkscape:path-effect
|
||||
effect="mirror_symmetry"
|
||||
start_point="78.68,115.48"
|
||||
end_point="78.68,120.48705"
|
||||
center_point="78.68,117.98353"
|
||||
id="path-effect36913"
|
||||
is_visible="true"
|
||||
lpeversion="1.2"
|
||||
lpesatellites=""
|
||||
mode="free"
|
||||
discard_orig_path="false"
|
||||
fuse_paths="true"
|
||||
oposite_fuse="true"
|
||||
split_items="false"
|
||||
split_open="false"
|
||||
link_styles="false" /><inkscape:path-effect
|
||||
effect="mirror_symmetry"
|
||||
start_point="78.68,115.48"
|
||||
end_point="78.68,120.48705"
|
||||
center_point="78.68,117.98353"
|
||||
id="path-effect36913-5"
|
||||
is_visible="true"
|
||||
lpeversion="1.2"
|
||||
lpesatellites=""
|
||||
mode="free"
|
||||
discard_orig_path="false"
|
||||
fuse_paths="true"
|
||||
oposite_fuse="true"
|
||||
split_items="false"
|
||||
split_open="false"
|
||||
link_styles="false" /><linearGradient
|
||||
inkscape:collect="always"
|
||||
xlink:href="#linearGradient51996"
|
||||
id="linearGradient51998"
|
||||
x1="78.572853"
|
||||
y1="121.57343"
|
||||
x2="78.605698"
|
||||
y2="123.67016"
|
||||
gradientUnits="userSpaceOnUse" /><linearGradient
|
||||
inkscape:collect="always"
|
||||
xlink:href="#linearGradient51996"
|
||||
id="linearGradient1071"
|
||||
gradientUnits="userSpaceOnUse"
|
||||
x1="78.572853"
|
||||
y1="121.57343"
|
||||
x2="78.605698"
|
||||
y2="123.67016" /><linearGradient
|
||||
inkscape:collect="always"
|
||||
xlink:href="#linearGradient51996"
|
||||
id="linearGradient1073"
|
||||
gradientUnits="userSpaceOnUse"
|
||||
x1="78.572853"
|
||||
y1="121.57343"
|
||||
x2="78.605698"
|
||||
y2="123.67016" /><linearGradient
|
||||
inkscape:collect="always"
|
||||
xlink:href="#linearGradient51996"
|
||||
id="linearGradient1075"
|
||||
gradientUnits="userSpaceOnUse"
|
||||
x1="78.572853"
|
||||
y1="121.57343"
|
||||
x2="78.579903"
|
||||
y2="124.25231" /><linearGradient
|
||||
inkscape:collect="always"
|
||||
xlink:href="#linearGradient51996"
|
||||
id="linearGradient1077"
|
||||
gradientUnits="userSpaceOnUse"
|
||||
x1="78.572853"
|
||||
y1="121.57343"
|
||||
x2="78.605698"
|
||||
y2="123.67016" /><linearGradient
|
||||
inkscape:collect="always"
|
||||
xlink:href="#linearGradient51996"
|
||||
id="linearGradient1079"
|
||||
gradientUnits="userSpaceOnUse"
|
||||
x1="78.572853"
|
||||
y1="121.57343"
|
||||
x2="78.605698"
|
||||
y2="123.67016" /><linearGradient
|
||||
inkscape:collect="always"
|
||||
xlink:href="#linearGradient51996"
|
||||
id="linearGradient1081"
|
||||
gradientUnits="userSpaceOnUse"
|
||||
x1="78.572853"
|
||||
y1="121.57343"
|
||||
x2="78.605698"
|
||||
y2="123.67016" /><linearGradient
|
||||
inkscape:collect="always"
|
||||
xlink:href="#linearGradient51996"
|
||||
id="linearGradient1083"
|
||||
gradientUnits="userSpaceOnUse"
|
||||
x1="78.572853"
|
||||
y1="121.57343"
|
||||
x2="78.605698"
|
||||
y2="123.67016" /><linearGradient
|
||||
inkscape:collect="always"
|
||||
xlink:href="#linearGradient51996"
|
||||
id="linearGradient1085"
|
||||
gradientUnits="userSpaceOnUse"
|
||||
x1="78.572853"
|
||||
y1="121.57343"
|
||||
x2="78.605698"
|
||||
y2="123.67016" /><linearGradient
|
||||
inkscape:collect="always"
|
||||
xlink:href="#linearGradient51996"
|
||||
id="linearGradient1087"
|
||||
gradientUnits="userSpaceOnUse"
|
||||
x1="78.572853"
|
||||
y1="121.57343"
|
||||
x2="78.605698"
|
||||
y2="123.67016" /><linearGradient
|
||||
inkscape:collect="always"
|
||||
xlink:href="#linearGradient51996"
|
||||
id="linearGradient1089"
|
||||
gradientUnits="userSpaceOnUse"
|
||||
x1="78.572853"
|
||||
y1="121.57343"
|
||||
x2="78.605698"
|
||||
y2="123.67016" /><linearGradient
|
||||
inkscape:collect="always"
|
||||
xlink:href="#linearGradient51996"
|
||||
id="linearGradient1091"
|
||||
gradientUnits="userSpaceOnUse"
|
||||
x1="78.572853"
|
||||
y1="121.57343"
|
||||
x2="78.605698"
|
||||
y2="123.67016" /><linearGradient
|
||||
inkscape:collect="always"
|
||||
xlink:href="#linearGradient51996"
|
||||
id="linearGradient1093"
|
||||
gradientUnits="userSpaceOnUse"
|
||||
x1="78.572853"
|
||||
y1="121.57343"
|
||||
x2="78.605698"
|
||||
y2="123.67016" /><linearGradient
|
||||
inkscape:collect="always"
|
||||
xlink:href="#linearGradient51996"
|
||||
id="linearGradient1095"
|
||||
gradientUnits="userSpaceOnUse"
|
||||
x1="78.572853"
|
||||
y1="121.57343"
|
||||
x2="78.605698"
|
||||
y2="123.67016" /><linearGradient
|
||||
inkscape:collect="always"
|
||||
xlink:href="#linearGradient51996"
|
||||
id="linearGradient1097"
|
||||
gradientUnits="userSpaceOnUse"
|
||||
x1="78.572853"
|
||||
y1="121.57343"
|
||||
x2="78.605698"
|
||||
y2="123.67016" /><linearGradient
|
||||
inkscape:collect="always"
|
||||
xlink:href="#linearGradient51996"
|
||||
id="linearGradient1099"
|
||||
gradientUnits="userSpaceOnUse"
|
||||
x1="78.572853"
|
||||
y1="121.57343"
|
||||
x2="78.605698"
|
||||
y2="123.67016" /><linearGradient
|
||||
inkscape:collect="always"
|
||||
xlink:href="#linearGradient51996"
|
||||
id="linearGradient1101"
|
||||
gradientUnits="userSpaceOnUse"
|
||||
x1="78.572853"
|
||||
y1="121.57343"
|
||||
x2="78.605698"
|
||||
y2="123.67016" /></defs><g
|
||||
inkscape:label="Layer 1"
|
||||
inkscape:groupmode="layer"
|
||||
id="layer1"><path
|
||||
style="fill:#ee2349;fill-opacity:1;stroke-width:0.264583"
|
||||
d="m 78.679688,115.50977 c -0.120712,0.0641 -0.42793,0.23077 -0.582032,0.34961 -0.183353,0.14139 -0.341667,0.2967 -0.496094,0.48632 -0.09316,0.11439 -0.175141,0.29861 -0.208984,0.46485 -0.05593,0.27473 -0.01958,0.56221 0.01953,0.83984 0.0674,0.47849 0.369141,1.40234 0.369141,1.40234 0,0 -0.370215,0.25236 -0.529297,0.40821 -0.08369,0.082 -0.134669,0.16526 -0.179687,0.27344 -0.06269,0.15064 -0.0906,0.32319 -0.09375,0.48632 -0.0016,0.0822 0.01367,0.26563 0.01367,0.26563 -10e-7,0 0.365376,-0.37098 0.609374,-0.45117 0.135542,-0.0445 0.296791,-0.0606 0.427735,-0.004 0.05341,0.0231 0.05909,0.12539 0.117187,0.12891 0.134803,0.008 0.418285,0.003 0.533204,0 0.114918,0.003 0.3984,0.008 0.533203,0 0.05809,-0.004 0.06378,-0.10581 0.117187,-0.12891 0.130944,-0.0567 0.294146,-0.0406 0.429688,0.004 0.243998,0.0802 0.607422,0.45117 0.607422,0.45117 0,0 0.01722,-0.18343 0.01562,-0.26563 -0.0031,-0.16313 -0.03106,-0.33569 -0.09375,-0.48632 -0.04502,-0.10818 -0.09795,-0.19144 -0.18164,-0.27344 -0.159082,-0.15585 -0.529297,-0.40821 -0.529297,-0.40821 0,0 0.303694,-0.92385 0.371094,-1.40234 0.03911,-0.27763 0.07351,-0.56511 0.01758,-0.83984 -0.03384,-0.16624 -0.115825,-0.35046 -0.208985,-0.46485 -0.154426,-0.18962 -0.31274,-0.34493 -0.496093,-0.48632 -0.154102,-0.11884 -0.46132,-0.28549 -0.582031,-0.34961 z"
|
||||
id="path36791-6"
|
||||
sodipodi:nodetypes="csssscssscssscc"
|
||||
class="UnoptimicedTransforms"
|
||||
transform="matrix(-1.5867841,0,0,1.5867841,131.19823,-183.26425)"
|
||||
inkscape:path-effect="#path-effect36913"
|
||||
inkscape:original-d="m 78.629702,115.48256 c 0,0 0.438268,0.22675 0.632602,0.37661 0.183353,0.1414 0.340934,0.29733 0.49536,0.48695 0.09316,0.11439 0.17524,0.29778 0.209083,0.46402 0.05593,0.27473 0.02088,0.56327 -0.01823,0.8409 -0.0674,0.47849 -0.370162,1.40159 -0.370162,1.40159 0,0 0.369865,0.25228 0.528947,0.40813 0.08369,0.082 0.136292,0.16564 0.18131,0.27381 0.06269,0.15064 0.09017,0.32334 0.09332,0.48647 0.0016,0.0822 -0.01413,0.26601 -0.01413,0.26601 0,0 -0.36491,-0.37107 -0.608908,-0.45126 -0.135542,-0.0445 -0.29706,-0.0607 -0.428004,-0.004 -0.05341,0.0231 -0.06025,0.12485 -0.118343,0.12837 -0.171522,0.0104 -0.582695,-0.002 -0.582695,-0.002 z" /><circle
|
||||
style="fill:#ffffff;fill-opacity:1;stroke-width:0.461723"
|
||||
id="path37027"
|
||||
cx="6.346231"
|
||||
cy="2.3943322"
|
||||
r="1.2447678" /><circle
|
||||
style="font-variation-settings:normal;vector-effect:none;fill:#ffc402;fill-opacity:1;stroke-width:0.141574;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;-inkscape-stroke:none;stop-color:#000000"
|
||||
id="path37568-5-9-1-3-6-1"
|
||||
cx="6.5362368"
|
||||
cy="12.559268"
|
||||
r="0.11592077" /><g
|
||||
id="g51228"
|
||||
style="fill:url(#linearGradient51998);fill-opacity:1"
|
||||
transform="matrix(1.5867841,0,0,1.5867841,-120.3592,-185.13424)"><circle
|
||||
style="fill:url(#linearGradient1071);fill-opacity:1;stroke-width:0.224809"
|
||||
id="path37568"
|
||||
cx="79.219589"
|
||||
cy="121.77583"
|
||||
r="0.18407404" /><circle
|
||||
style="font-variation-settings:normal;opacity:1;vector-effect:none;fill:url(#linearGradient1073);fill-opacity:1;stroke-width:0.377183;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;-inkscape-stroke:none;stop-color:#000000;stop-opacity:1"
|
||||
id="path37568-5"
|
||||
cx="79.928802"
|
||||
cy="121.81054"
|
||||
r="0.30883789" /><circle
|
||||
style="font-variation-settings:normal;vector-effect:none;fill:url(#linearGradient1075);fill-opacity:1;stroke-width:0.518098;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;-inkscape-stroke:none;stop-color:#000000"
|
||||
id="path37568-5-9"
|
||||
cx="79.265541"
|
||||
cy="122.34314"
|
||||
r="0.42421949" /><circle
|
||||
style="font-variation-settings:normal;vector-effect:none;fill:url(#linearGradient1077);fill-opacity:1;stroke-width:0.194865;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;-inkscape-stroke:none;stop-color:#000000"
|
||||
id="path37568-5-9-8"
|
||||
cx="78.911224"
|
||||
cy="122.55578"
|
||||
r="0.15955541" /><circle
|
||||
style="font-variation-settings:normal;vector-effect:none;fill:url(#linearGradient1079);fill-opacity:1;stroke-width:0.317766;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;-inkscape-stroke:none;stop-color:#000000"
|
||||
id="path37568-5-9-1"
|
||||
cx="79.634331"
|
||||
cy="122.87711"
|
||||
r="0.26018718" /><circle
|
||||
style="font-variation-settings:normal;vector-effect:none;fill:url(#linearGradient1081);fill-opacity:1;stroke-width:0.378906;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;-inkscape-stroke:none;stop-color:#000000"
|
||||
id="path37568-5-9-1-3"
|
||||
cx="80.265633"
|
||||
cy="123.65545"
|
||||
r="0.31024873" /><circle
|
||||
style="font-variation-settings:normal;vector-effect:none;fill:url(#linearGradient1083);fill-opacity:1;stroke-width:0.177006;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;-inkscape-stroke:none;stop-color:#000000"
|
||||
id="path37568-5-9-1-3-6"
|
||||
cx="79.914619"
|
||||
cy="124.27737"
|
||||
r="0.14493258" /><circle
|
||||
style="font-variation-settings:normal;vector-effect:none;fill:url(#linearGradient1085);fill-opacity:1;stroke-width:0.0989143;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;-inkscape-stroke:none;stop-color:#000000"
|
||||
id="path37568-5-9-1-3-6-6"
|
||||
cx="80.206474"
|
||||
cy="124.00723"
|
||||
r="0.080991074" /><circle
|
||||
style="font-variation-settings:normal;vector-effect:none;fill:url(#linearGradient1087);fill-opacity:1;stroke-width:0.221224;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;-inkscape-stroke:none;stop-color:#000000"
|
||||
id="path37568-5-9-1-3-6-0"
|
||||
cx="79.695312"
|
||||
cy="123.76383"
|
||||
r="0.18113838" /><ellipse
|
||||
style="font-variation-settings:normal;vector-effect:none;fill:url(#linearGradient1089);fill-opacity:1;stroke-width:0.271828;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;-inkscape-stroke:none;stop-color:#000000"
|
||||
id="path37568-5-9-1-3-6-0-6"
|
||||
cx="79.60508"
|
||||
cy="123.37116"
|
||||
rx="0.22375529"
|
||||
ry="0.22139755" /><ellipse
|
||||
style="font-variation-settings:normal;vector-effect:none;fill:url(#linearGradient1091);fill-opacity:1;stroke-width:0.271828;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;-inkscape-stroke:none;stop-color:#000000"
|
||||
id="path37568-5-9-1-3-6-0-6-7"
|
||||
cx="79.846291"
|
||||
cy="123.10796"
|
||||
rx="0.22375529"
|
||||
ry="0.22139755" /><ellipse
|
||||
style="font-variation-settings:normal;vector-effect:none;fill:url(#linearGradient1093);fill-opacity:1;stroke-width:0.244555;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;-inkscape-stroke:none;stop-color:#000000"
|
||||
id="path37568-5-9-1-3-6-0-6-2"
|
||||
cx="79.247681"
|
||||
cy="123.40287"
|
||||
rx="0.19959654"
|
||||
ry="0.20088845" /><circle
|
||||
style="font-variation-settings:normal;vector-effect:none;fill:url(#linearGradient1095);fill-opacity:1;stroke-width:0.243037;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;-inkscape-stroke:none;stop-color:#000000"
|
||||
id="path37568-5-9-1-2"
|
||||
cx="80.333969"
|
||||
cy="122.72621"
|
||||
r="0.19899905" /><circle
|
||||
style="font-variation-settings:normal;vector-effect:none;fill:url(#linearGradient1097);fill-opacity:1;stroke-width:0.282009;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;-inkscape-stroke:none;stop-color:#000000"
|
||||
id="path37568-5-9-1-2-0-9"
|
||||
cx="80.747818"
|
||||
cy="122.34882"
|
||||
r="0.23090924" /><circle
|
||||
style="font-variation-settings:normal;vector-effect:none;fill:url(#linearGradient1099);fill-opacity:1;stroke-width:0.313683;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;-inkscape-stroke:none;stop-color:#000000"
|
||||
id="path37568-5-9-1-2-7"
|
||||
cx="80.58844"
|
||||
cy="122.97715"
|
||||
r="0.25684434" /><circle
|
||||
style="fill:url(#linearGradient1101);fill-opacity:1;stroke-width:0.426803"
|
||||
id="path37568-5-6"
|
||||
cx="80.422928"
|
||||
cy="122.06255"
|
||||
r="0.34946665" /></g></g></svg>
|
||||
|
After Width: | Height: | Size: 16 KiB |
@@ -1,52 +1,104 @@
|
||||
Building {#flatbuffers_guide_building}
|
||||
========
|
||||
# Building
|
||||
|
||||
## Building with CMake
|
||||
|
||||
The distribution comes with a `cmake` file that should allow
|
||||
you to build project/make files for any platform. For details on `cmake`, see
|
||||
<https://www.cmake.org>. In brief, depending on your platform, use one of
|
||||
e.g.:
|
||||
The distribution main build system is configured by
|
||||
[`cmake`](https://www.cmake.org) which allows you to build the project for any
|
||||
platform.
|
||||
|
||||
### Configuration
|
||||
|
||||
Use `cmake` to configure a project based on your environment and platform.
|
||||
|
||||
=== "Unix"
|
||||
|
||||
```sh
|
||||
cmake -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=Release
|
||||
cmake -G "Visual Studio 10" -DCMAKE_BUILD_TYPE=Release
|
||||
```
|
||||
|
||||
To use `clang` instead of `gcc` you may need to set prepend some environment
|
||||
variables e.g. `CC=/usr/bin/clang CXX=/usr/bin/clang++ cmake -G "Unix
|
||||
MakeFiles"`
|
||||
|
||||
=== "Windows"
|
||||
|
||||
```sh
|
||||
cmake -G "Visual Studio 17 2022" -DCMAKE_BUILD_TYPE=Release
|
||||
```
|
||||
|
||||
=== "MacOS"
|
||||
|
||||
```sh
|
||||
cmake -G "Xcode" -DCMAKE_BUILD_TYPE=Release
|
||||
```
|
||||
|
||||
Then, build as normal for your platform. This should result in a `flatc`
|
||||
executable, essential for the next steps.
|
||||
Note that to use clang instead of gcc, you may need to set up your environment
|
||||
variables, e.g.
|
||||
`CC=/usr/bin/clang CXX=/usr/bin/clang++ cmake -G "Unix Makefiles"`.
|
||||
#### Strict Mode
|
||||
|
||||
Optionally, run the `flattests` executable from the root `flatbuffers/`
|
||||
directory to ensure everything is working correctly on your system. If this
|
||||
fails, please contact us!
|
||||
By default, `cmake` will configure targets to **not** build with strict warnings
|
||||
on (e.g. `-Werror` or `/WX`). This may cause into issues when submitting code
|
||||
changes since our CI requires the code to compile in strict mode.
|
||||
|
||||
Building should also produce two sample executables, `flatsamplebinary` and
|
||||
`flatsampletext`, see the corresponding `.cpp` files in the
|
||||
`flatbuffers/samples` directory.
|
||||
To enable the extra warnings, turn on strict mode with the
|
||||
`FLATBUFFERS_STRICT_MODE` cmake option.
|
||||
|
||||
*Note that you MUST be in the root of the FlatBuffers distribution when you
|
||||
run 'flattests' or `flatsampletext`, or it will fail to load its files.*
|
||||
|
||||
### Make all warnings into errors
|
||||
|
||||
By default all Flatbuffers `cmake` targets are **not** built with the `-Werror`
|
||||
(or `/WX` for MSVC) flag that treats any warning as an error. This allows more
|
||||
flexibility for users of Flatbuffers to use newer compilers and toolsets that
|
||||
may add new warnings that would cause a build failure.
|
||||
|
||||
To enable a stricter build that does treat warnings as errors, set the
|
||||
`FLATBUFFERS_STRICT_MODE` `cmake` compliation flag to `ON`.
|
||||
|
||||
```
|
||||
cmake . -DFLATBUFFERS_STRICT_MODE=ON
|
||||
```cmake
|
||||
cmake -DFLATBUFFERS_STRICT_MODE=ON
|
||||
```
|
||||
|
||||
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
|
||||
|
||||
Once the project files are generated, build as normal for your platform.
|
||||
|
||||
=== "Unix"
|
||||
|
||||
```sh
|
||||
make -j
|
||||
```
|
||||
|
||||
=== "Windows"
|
||||
|
||||
```sh
|
||||
msbuild.exe FlatBuffers.sln
|
||||
```
|
||||
|
||||
=== "MacOS"
|
||||
|
||||
```sh
|
||||
xcodebuild -toolchain clang -configuration Release
|
||||
```
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
## Building with Bazel
|
||||
|
||||
You can use [Bazelisk](https://github.com/bazelbuild/bazelisk) to manage your Bazel environment.
|
||||
For Swift support, you also need Clang and [Swift SDK](https://download.swift.org/).
|
||||
|
||||
```sh
|
||||
curl -sL --fail https://github.com/bazelbuild/bazelisk/releases/download/v1.25.0/bazelisk-linux-amd64 -o bazelisk && chmod +x bazelisk
|
||||
sudo apt install -y clang
|
||||
SWIFT_VERSION="6.0.3"
|
||||
curl -L https://download.swift.org/swift-${SWIFT_VERSION}-release/debian12/swift-${SWIFT_VERSION}-RELEASE/swift-${SWIFT_VERSION}-RELEASE-debian12.tar.gz | tar xz
|
||||
CC=clang PATH=$PATH:$(pwd)/swift-${SWIFT_VERSION}-RELEASE-debian12/usr/bin bazel build //...
|
||||
CC=clang PATH=$PATH:$(pwd)/swift-${SWIFT_VERSION}-RELEASE-debian12/usr/bin bazel test //...
|
||||
```
|
||||
|
||||
If you are unsure which versions to use, check our CI config at `.bazelci/presubmit.yml`.
|
||||
|
||||
## Building with Conan
|
||||
|
||||
You can download and install flatbuffers using the [Conan](https://conan.io/) dependency manager:
|
||||
|
||||
conan install --requires="flatbuffers/[*]" --build=missing
|
||||
|
||||
The flatbuffers package in Conan Center is maintained by
|
||||
[ConanCenterIndex](https://github.com/conan-io/conan-center-index) community.
|
||||
If the version is out of date or the package does not work,
|
||||
please create an issue or pull request on the [Conan Center Index repository](https://github.com/conan-io/conan-center-index).
|
||||
|
||||
## Building with VCPKG
|
||||
|
||||
@@ -61,17 +113,7 @@ 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.
|
||||
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
|
||||
|
||||
@@ -96,7 +138,7 @@ also compile/link `src/idl_parser.cpp` (and `src/idl_gen_text.cpp` if you
|
||||
also want to be able convert binary to text).
|
||||
|
||||
To see how to include FlatBuffers in any of our supported languages, please
|
||||
view the [Tutorial](@ref flatbuffers_guide_tutorial) and select your appropriate
|
||||
view the [Tutorial](tutorial.md) and select your appropriate
|
||||
language using the radio buttons.
|
||||
|
||||
### Using in CMake-based projects
|
||||
@@ -121,13 +163,26 @@ add_subdirectory(${FLATBUFFERS_SRC_DIR}
|
||||
# The flatbuffers target carry header search path automatically if CMake > 2.8.11.
|
||||
target_link_libraries(own_project_target PRIVATE flatbuffers)
|
||||
```
|
||||
When build your project the `flatbuffers` library will be compiled and linked
|
||||
When build your project the `flatbuffers` library will be compiled and linked
|
||||
to a target as part of your project.
|
||||
|
||||
#### Override default depth limit of nested objects
|
||||
To override [the depth limit of recursion](@ref flatbuffers_guide_use_cpp),
|
||||
To override [the depth limit of recursion](languages/cpp.md),
|
||||
add this directive:
|
||||
```cmake
|
||||
set(FLATBUFFERS_MAX_PARSING_DEPTH 16)
|
||||
```
|
||||
to `CMakeLists.txt` file before `add_subdirectory(${FLATBUFFERS_SRC_DIR})` line.
|
||||
|
||||
## Downloading binaries
|
||||
You can download the binaries from the
|
||||
[GitHub release page](https://github.com/google/flatbuffers/releases).
|
||||
|
||||
We generate [SLSA3 signatures](http://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
|
||||
```
|
||||
80
docs/source/contributing.md
Normal file
80
docs/source/contributing.md
Normal file
@@ -0,0 +1,80 @@
|
||||
# Contributing
|
||||
|
||||
We encourage community contributions to FlatBuffers through pull requests at the
|
||||
main
|
||||
[http://github.com/google/flatbuffers](http://github.com/google/flatbuffers)
|
||||
repository.
|
||||
|
||||
!!! note
|
||||
|
||||
The FlatBuffers project is not staffed by any full time Google employee, and
|
||||
is managed by a small team of 20%ers. So response time and expertise vary.
|
||||
|
||||
## Before you contribute
|
||||
|
||||
Before we can use your contributions, you __must__ sign one of the following license agreements. The agreements are self-served at the following links.
|
||||
|
||||
Our code review process will automatically check if you have signed the CLA, so
|
||||
don't fret. Though it may be prudent to check before spending a lot of time on
|
||||
contribution.
|
||||
|
||||
### Individual Contributions
|
||||
|
||||
For individuals, the [Google Individual
|
||||
Contributor License Agreement
|
||||
(CLA)](https://cla.developers.google.com/about/google-individual?csw=1) which is
|
||||
self served at the link. The CLA is required since you own the copyright to your
|
||||
changes, even after your contribution becomes part of our codebase, so we need
|
||||
your permission to use and distribute your code.
|
||||
|
||||
### Corporate Contributions
|
||||
|
||||
Contributions made by corporations are covered by the [Google Software Grant and
|
||||
Corporate Contributor License
|
||||
Agreement](https://cla.developers.google.com/about/google-corporate).
|
||||
|
||||
## Code Reviews
|
||||
|
||||
All submissions require a code review via Github Pull Requests.
|
||||
|
||||
1. Please adhere to the [Google Style Guide](https://google.github.io/styleguide/cppguide.html) for the language(s) you are submitting in.
|
||||
2. Keep PRs small and focused. Its good practice and makes it more likely your PR will be approved.
|
||||
3. Please add tests if possible.
|
||||
4. Include descriptive commit messages and context to the change/issues fixed.
|
||||
|
||||
## Documentation
|
||||
|
||||
FlatBuffers uses [MkDocs](https://www.mkdocs.org/) to generate the static
|
||||
documentation pages served at
|
||||
[https://flatbuffers.dev](https://flatbuffers.dev). Specifically, we use the
|
||||
[Material for MkDocs](https://squidfunk.github.io/mkdocs-material/) framework.
|
||||
|
||||
The documentation source is contained in the main repo under the
|
||||
[docs/](https://github.com/google/flatbuffers/tree/master/docs) directory. This
|
||||
[automatically](https://github.com/google/flatbuffers/blob/46cc3d6432da17cca7694777dcce12e49dd48387/.github/workflows/docs.yml#L6-L11) get built and published when the commit is made.
|
||||
|
||||
### Local Development
|
||||
|
||||
We encourage contributors to keep the documentation up-to-date as well, and it
|
||||
is easy to with `MkDocs` local building and serving tools.
|
||||
|
||||
First install `mkdocs-material` (see
|
||||
[Installation](https://squidfunk.github.io/mkdocs-material/getting-started/) for
|
||||
other ways)
|
||||
|
||||
```
|
||||
pip install mkdocs-material
|
||||
pip install mkdocs-redirects
|
||||
```
|
||||
|
||||
Then, in the `root` directory of flatbuffers, run
|
||||
|
||||
```
|
||||
mkdocs serve -f docs/mkdocs.yml
|
||||
```
|
||||
|
||||
This will continually watch the repo for changes to the documentation and serve
|
||||
the rendered pages locally.
|
||||
|
||||
Submit your documentation changes with your code changes and they will
|
||||
automatically get published when your code is submitted.
|
||||
2375
docs/source/doxyfile
2375
docs/source/doxyfile
File diff suppressed because it is too large
Load Diff
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user