mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-10 23:17:27 +00:00
Compare commits
481 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
cebdad4d23 | ||
|
|
d798100be9 | ||
|
|
1fb6b9ee6f | ||
|
|
2d6e8f096b | ||
|
|
ec8038cc3d | ||
|
|
2df3d1c965 | ||
|
|
2272229983 | ||
|
|
b7bfecb4ee | ||
|
|
c7c4bbfce2 | ||
|
|
d7ba17dfe5 | ||
|
|
60b11435e6 | ||
|
|
ed2110d7b3 | ||
|
|
a9514de978 | ||
|
|
c57ab92e60 | ||
|
|
f878024d0b | ||
|
|
aac6be1153 | ||
|
|
dabe030890 | ||
|
|
29574282a2 | ||
|
|
2dd6ba57d1 | ||
|
|
6cc2307c71 | ||
|
|
74c8c7137a | ||
|
|
f9055ff9a7 | ||
|
|
9b3d8b318a | ||
|
|
87e29b25de | ||
|
|
f7bc9bd51b | ||
|
|
3dee617c86 | ||
|
|
2fb25e2bb3 | ||
|
|
b395359b6e | ||
|
|
fd61d70205 | ||
|
|
4f4495a693 | ||
|
|
68bbe983e9 | ||
|
|
bbef92c17d | ||
|
|
25c884158f | ||
|
|
3f936c5655 | ||
|
|
42a265b419 | ||
|
|
4bc4979acc | ||
|
|
b095367d17 | ||
|
|
eac2905568 | ||
|
|
12fd0c6838 | ||
|
|
19101826a8 | ||
|
|
7b94eab2b1 | ||
|
|
1a21b54560 | ||
|
|
b55f18649a | ||
|
|
e2373668d9 | ||
|
|
8c1a723ba5 | ||
|
|
ab7949dc16 | ||
|
|
2c4dce5ba7 | ||
|
|
cc84240098 | ||
|
|
b29ba4c70c | ||
|
|
fea6b525ee | ||
|
|
69dc71b5ed | ||
|
|
1a89682251 | ||
|
|
5fd0fefab6 | ||
|
|
f8a964d2b0 | ||
|
|
84033ae035 | ||
|
|
b9efbf6a3d | ||
|
|
13194ececa | ||
|
|
9ec9303abb | ||
|
|
03ee3db240 | ||
|
|
cf825b8819 | ||
|
|
377a8ba6b2 | ||
|
|
13cf6e66e3 | ||
|
|
81b6bacead | ||
|
|
e6fa14a08d | ||
|
|
c66683f27f | ||
|
|
6d6271db2f | ||
|
|
ab76c57ec8 | ||
|
|
d1e8899310 | ||
|
|
ccba2edb7c | ||
|
|
2a7a44be33 | ||
|
|
6301da75d1 | ||
|
|
059661b9ac | ||
|
|
dc5975ba7a | ||
|
|
0de4f3f75b | ||
|
|
b59aafc659 | ||
|
|
92a6ae93fa | ||
|
|
a31ddd2bb3 | ||
|
|
bc2ec7119b | ||
|
|
641b397f8b | ||
|
|
d342918790 | ||
|
|
c4377390a8 | ||
|
|
5608be0f96 | ||
|
|
dbecdf209d | ||
|
|
c05803bf96 | ||
|
|
d298adc4e6 | ||
|
|
c2050aa0e3 | ||
|
|
290e9f270b | ||
|
|
76ae10df42 | ||
|
|
cf0d7829a6 | ||
|
|
af21b9064d | ||
|
|
e31fbb0b23 | ||
|
|
43ba7c6369 | ||
|
|
dae513e0e7 | ||
|
|
d8944e45a2 | ||
|
|
5b5fcbfc00 | ||
|
|
6862b2ff08 | ||
|
|
22e87071dd | ||
|
|
606098cac8 | ||
|
|
b5c622762b | ||
|
|
2beb985fcc | ||
|
|
fd97404c51 | ||
|
|
d9fe4e2769 | ||
|
|
424fc0c3ac | ||
|
|
c81239f6ea | ||
|
|
b830dac266 | ||
|
|
dc38f93ca8 | ||
|
|
f9025eeb52 | ||
|
|
486c048a0d | ||
|
|
ab51b03093 | ||
|
|
dc2fa215b8 | ||
|
|
199157e8f4 | ||
|
|
520d68449f | ||
|
|
b075b8c49d | ||
|
|
f6c1a1ebcf | ||
|
|
c4aede2268 | ||
|
|
4a43c2bb2c | ||
|
|
b2e55c556e | ||
|
|
df0991b7de | ||
|
|
3368407aff | ||
|
|
25f3f358a0 | ||
|
|
00e8aa87b3 | ||
|
|
09ee46a83e | ||
|
|
02dfa64a89 | ||
|
|
f136570417 | ||
|
|
b6ba322a04 | ||
|
|
4b79ff5351 | ||
|
|
edd77ae2f3 | ||
|
|
985de211af | ||
|
|
8e3fa336eb | ||
|
|
582fd90c4a | ||
|
|
a15659e9f8 | ||
|
|
afd230af8d | ||
|
|
52ca75506a | ||
|
|
3bb9b839b8 | ||
|
|
5e7bfd0461 | ||
|
|
d05d114523 | ||
|
|
722b903f89 | ||
|
|
2ff6152204 | ||
|
|
98f9af8ecc | ||
|
|
481d332e72 | ||
|
|
1a18122e3f | ||
|
|
ee56418cef | ||
|
|
e1f8037cb5 | ||
|
|
ea9ee4c99e | ||
|
|
4026117ba1 | ||
|
|
49ee30a207 | ||
|
|
7c69c5dc3d | ||
|
|
223ebebbeb | ||
|
|
f96eb472b3 | ||
|
|
c1b0abe079 | ||
|
|
b04e21db16 | ||
|
|
756050b62c | ||
|
|
ef67a58410 | ||
|
|
2da0821286 | ||
|
|
928effd198 | ||
|
|
2e7806ede0 | ||
|
|
67967476b2 | ||
|
|
79d127c863 | ||
|
|
4f3e1c2831 | ||
|
|
199a49b5b3 | ||
|
|
96ab6ade5a | ||
|
|
9f16090f90 | ||
|
|
63b240ec7b | ||
|
|
c4ba502f57 | ||
|
|
94d5643f97 | ||
|
|
f0d91fa143 | ||
|
|
726a5f523e | ||
|
|
eba6b6f7c9 | ||
|
|
fa74ce6d16 | ||
|
|
8fdced4e11 | ||
|
|
9031597f49 | ||
|
|
a0b8f669ee | ||
|
|
18d67ed83b | ||
|
|
205ddb175f | ||
|
|
be908939da | ||
|
|
c96fc7fcef | ||
|
|
026c6ddb17 | ||
|
|
3eebba789f | ||
|
|
b36bd67b39 | ||
|
|
dc7f5bc0d8 | ||
|
|
ec20233fab | ||
|
|
867dfc5957 | ||
|
|
73d5bf46b4 | ||
|
|
f6416d8471 | ||
|
|
52acb4b347 | ||
|
|
d70f5ac6b0 | ||
|
|
c9b9fd0407 | ||
|
|
6897bb99bb | ||
|
|
4c861daa3e | ||
|
|
c9ee9fb99d | ||
|
|
50e13ef9c6 | ||
|
|
f624065eaa | ||
|
|
03adfa7b1a | ||
|
|
97a9a82324 | ||
|
|
307694e397 | ||
|
|
d268d11ca2 | ||
|
|
094f4d1bad | ||
|
|
a0398ce0f5 | ||
|
|
30c07f4e55 | ||
|
|
fc19f746b0 | ||
|
|
a351124cfd | ||
|
|
0230a7173f | ||
|
|
5f351a35a2 | ||
|
|
2d427e0502 | ||
|
|
1bba4fd9ea | ||
|
|
f98870715a | ||
|
|
b7a26d73ee | ||
|
|
1ba4d3c4c7 | ||
|
|
f61f0449c7 | ||
|
|
06c1ad5a73 | ||
|
|
38b3893211 | ||
|
|
42e0b02149 | ||
|
|
a56c6e5195 | ||
|
|
5efa22447e | ||
|
|
bdd668df7b | ||
|
|
05b00c50ad | ||
|
|
77e9122681 | ||
|
|
e067040375 | ||
|
|
370e101a69 | ||
|
|
91f5cf357c | ||
|
|
7c7c571bbe | ||
|
|
3101e327c0 | ||
|
|
46bf9f5177 | ||
|
|
694725beb0 | ||
|
|
ce3e7fbd72 | ||
|
|
53e9606ea2 | ||
|
|
ffc0d6209a | ||
|
|
9fdb6dcf1f | ||
|
|
298dd21ec8 | ||
|
|
64fa8ba9a9 | ||
|
|
36daedf35f | ||
|
|
a8d2eeee34 | ||
|
|
e21a61d458 | ||
|
|
410fb15a07 | ||
|
|
a69b19fa8f | ||
|
|
58924538a3 | ||
|
|
e750268f0c | ||
|
|
0328dedab5 | ||
|
|
9605dc5981 | ||
|
|
00694d271e | ||
|
|
b22db6e8eb | ||
|
|
14e7e8260e | ||
|
|
3a1f776132 | ||
|
|
4b53762cf2 | ||
|
|
0d56276102 | ||
|
|
98c7a0c169 | ||
|
|
676f0712fd | ||
|
|
7a3f1cf78e | ||
|
|
49c10bc219 | ||
|
|
df9990acf5 | ||
|
|
3d7b1a32a3 | ||
|
|
db99c1aa64 | ||
|
|
247388a20c | ||
|
|
f6f88e567e | ||
|
|
e527b992f9 | ||
|
|
aade31b263 | ||
|
|
e733d95e66 | ||
|
|
14bdce41fe | ||
|
|
4a49493e27 | ||
|
|
df5575de17 | ||
|
|
f0b2cc8f6e | ||
|
|
5f2b4e7872 | ||
|
|
22697722d9 | ||
|
|
ffbc93526e | ||
|
|
d9d47a53bd | ||
|
|
71d30d5c02 | ||
|
|
1661f3a2e8 | ||
|
|
d9767b8315 | ||
|
|
193a631708 | ||
|
|
a6764b9bf1 | ||
|
|
0f5dc152b8 | ||
|
|
8e1aae0fd6 | ||
|
|
084e5dbc4b | ||
|
|
dfbda986d7 | ||
|
|
248432b92d | ||
|
|
f738981ed5 | ||
|
|
4bb6ab3cd5 | ||
|
|
72e8219a65 | ||
|
|
7a955a09f4 | ||
|
|
b730a74a19 | ||
|
|
cc2b04ce1c | ||
|
|
4f8abaaf10 | ||
|
|
5043764247 | ||
|
|
9fd4d66438 | ||
|
|
aae48e3a9d | ||
|
|
ff57f52b72 | ||
|
|
7d84a4914f | ||
|
|
c2411e9c8c | ||
|
|
bf26a0eccc | ||
|
|
68a83eddd4 | ||
|
|
b999d49945 | ||
|
|
c94cb6dae9 | ||
|
|
5ea2b49f58 | ||
|
|
70deb70b76 | ||
|
|
48f37f9e0a | ||
|
|
6dff7c68f1 | ||
|
|
ec59dc026f | ||
|
|
c97abb1eea | ||
|
|
2fdafa9a49 | ||
|
|
f794f97d88 | ||
|
|
03ad8fa4d9 | ||
|
|
43fedfa8ba | ||
|
|
2f52618c4e | ||
|
|
a9e21170bc | ||
|
|
cb6cc3dfb6 | ||
|
|
66f2aac26f | ||
|
|
4a249752ff | ||
|
|
f0695e0edf | ||
|
|
07d4066847 | ||
|
|
57ba8a4d46 | ||
|
|
9e6c5f9f2c | ||
|
|
3639032d1e | ||
|
|
6f75ec8490 | ||
|
|
fd43d3709e | ||
|
|
6e177bf03f | ||
|
|
d3ac0bc149 | ||
|
|
afa276288c | ||
|
|
4832238708 | ||
|
|
1f8e3c13e6 | ||
|
|
5a401aef57 | ||
|
|
78ecf45527 | ||
|
|
3ae503a191 | ||
|
|
bafd48d96c | ||
|
|
cf7e4b027a | ||
|
|
15863c34a0 | ||
|
|
9875b0e0f8 | ||
|
|
2bdf44a25d | ||
|
|
4ffc881fb6 | ||
|
|
e92ae5199d | ||
|
|
a3a2bf890f | ||
|
|
a9194c4c68 | ||
|
|
ca32eb77f3 | ||
|
|
886441df98 | ||
|
|
e02ceca54b | ||
|
|
b3c35750c2 | ||
|
|
3e52fecd1e | ||
|
|
cccd7003ed | ||
|
|
038ea7c1d3 | ||
|
|
0b0cf58f24 | ||
|
|
7d1f372ba6 | ||
|
|
25e4ad19f6 | ||
|
|
7dfe8e726b | ||
|
|
61b101d442 | ||
|
|
cd1493b082 | ||
|
|
a98bff3ea1 | ||
|
|
06eb6e94e3 | ||
|
|
4a8801da34 | ||
|
|
b1e8be27a9 | ||
|
|
b922a3c952 | ||
|
|
b52826e7cc | ||
|
|
0ef72db7bf | ||
|
|
505d0f2288 | ||
|
|
6704b19db6 | ||
|
|
64b91da9cf | ||
|
|
fe9787e58d | ||
|
|
d06e571b31 | ||
|
|
208c15f29d | ||
|
|
a82dbb6e01 | ||
|
|
a42a99029f | ||
|
|
0c7b700895 | ||
|
|
1aa3ee2170 | ||
|
|
8c0d56d55a | ||
|
|
c41a0453c1 | ||
|
|
1a161a8333 | ||
|
|
9d8ae1b0c3 | ||
|
|
2de558057d | ||
|
|
0756caa42e | ||
|
|
99c1ddc792 | ||
|
|
69eef0a0ec | ||
|
|
42bd6447c0 | ||
|
|
747a8c628e | ||
|
|
023fec627e | ||
|
|
3a8bc309e2 | ||
|
|
3400727fff | ||
|
|
77742a3fba | ||
|
|
7cce55d8f0 | ||
|
|
933c195e51 | ||
|
|
d0898fd0c8 | ||
|
|
6765c19d45 | ||
|
|
599f5e3915 | ||
|
|
ba7204a7b7 | ||
|
|
e8ac0f293e | ||
|
|
a0d1161feb | ||
|
|
828b2680c0 | ||
|
|
c17cf022ea | ||
|
|
f6330ab8f1 | ||
|
|
6908826f95 | ||
|
|
fd542c71e3 | ||
|
|
9fb87f813b | ||
|
|
b0146b3d9a | ||
|
|
286587d151 | ||
|
|
6f751d5d26 | ||
|
|
4d7890c2c9 | ||
|
|
fdfaf23361 | ||
|
|
38597160f2 | ||
|
|
791c83aa7e | ||
|
|
29d957ed5e | ||
|
|
8d8b7c19b7 | ||
|
|
039ab48b7a | ||
|
|
8a64afabfd | ||
|
|
4a04bac250 | ||
|
|
72fc45aa6a | ||
|
|
9f2b05df1b | ||
|
|
83dc5ed4a7 | ||
|
|
e597ad8f0f | ||
|
|
3ea5446680 | ||
|
|
8b18e487bd | ||
|
|
c837d29eab | ||
|
|
ec1daef858 | ||
|
|
7d396bc2e7 | ||
|
|
8128df7655 | ||
|
|
cfaa7782b6 | ||
|
|
5e3f9d5175 | ||
|
|
cdc5d5b18d | ||
|
|
e98b1912b3 | ||
|
|
c8c0082413 | ||
|
|
1c1d079113 | ||
|
|
7523e4ad49 | ||
|
|
f4a5c9de50 | ||
|
|
1db9783bfc | ||
|
|
5b38134431 | ||
|
|
4c16038e72 | ||
|
|
2f7f50b8cb | ||
|
|
a1633055f7 | ||
|
|
35f6bb5060 | ||
|
|
28a3c939e7 | ||
|
|
7d9779fc67 | ||
|
|
9b8c91c90b | ||
|
|
47d4b46950 | ||
|
|
a649cb7db5 | ||
|
|
68c69b3717 | ||
|
|
ce4d3316d3 | ||
|
|
e6b79f0002 | ||
|
|
1a63eb46bb | ||
|
|
91c27148c0 | ||
|
|
1e7310e6cd | ||
|
|
b49a7d146d | ||
|
|
fbc8af40e3 | ||
|
|
709e720839 | ||
|
|
3cd9181ef8 | ||
|
|
81e4d3c6c3 | ||
|
|
958fc6ec49 | ||
|
|
19afcdc704 | ||
|
|
51d48bd953 | ||
|
|
26f15bcd77 | ||
|
|
412b8d2c80 | ||
|
|
617fedf349 | ||
|
|
59caa536ed | ||
|
|
3d5f7f64f8 | ||
|
|
66126cc32d | ||
|
|
31b30335f6 | ||
|
|
959866b848 | ||
|
|
cbab26673b | ||
|
|
1cf5e3f751 | ||
|
|
9a76ce8a65 | ||
|
|
574404e2ee | ||
|
|
20c0082ee5 | ||
|
|
9d92aeb182 | ||
|
|
2f5d7ae645 | ||
|
|
d2bc73bbbe | ||
|
|
697cad7027 | ||
|
|
472fb12273 | ||
|
|
d779308b3e | ||
|
|
a03f3287b3 | ||
|
|
a88cf317fd | ||
|
|
4802e8a285 | ||
|
|
b611dc4b99 | ||
|
|
5f19ea5e45 | ||
|
|
e4abeef65c | ||
|
|
ac49eda053 | ||
|
|
1fa803d187 | ||
|
|
6d1ff8a525 | ||
|
|
59dc29a19a | ||
|
|
6db667b6b1 | ||
|
|
07da3fc216 | ||
|
|
c5835b896c | ||
|
|
345e8ca804 | ||
|
|
9202f0cf09 | ||
|
|
d10f9a6abc | ||
|
|
ec0c0b14ca | ||
|
|
6267f8c6c0 |
12
.github/ISSUE_TEMPLATE.md
vendored
Normal file
12
.github/ISSUE_TEMPLATE.md
vendored
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
Thank you for submitting an issue!
|
||||||
|
|
||||||
|
Please make sure you include the names of the affected language(s), compiler version(s), operating system version(s), and FlatBuffers version(s) in your issue title.
|
||||||
|
|
||||||
|
This helps us get the correct maintainers to look at your issue. Here are examples of good titles:
|
||||||
|
|
||||||
|
- Crash when accessing FlatBuffer [C++, gcc 4.8, OS X, master]
|
||||||
|
- Flatc converts a protobuf 'bytes' field to 'string' in fbs schema file [all languages, FlatBuffers 1.4]
|
||||||
|
|
||||||
|
Include other details as appropriate.
|
||||||
|
|
||||||
|
Thanks!
|
||||||
16
.github/PULL_REQUEST_TEMPLATE.md
vendored
Normal file
16
.github/PULL_REQUEST_TEMPLATE.md
vendored
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
Thank you for submitting a PR!
|
||||||
|
|
||||||
|
Please make sure you include the names of the affected language(s) in your PR title.
|
||||||
|
This helps us get the correct maintainers to look at your issue.
|
||||||
|
|
||||||
|
If you make changes to any of the code generators, be sure to run
|
||||||
|
`cd tests && sh generate_code.sh` (or equivalent .bat) and include the generated
|
||||||
|
code changes in the PR. This allows us to better see the effect of the PR.
|
||||||
|
|
||||||
|
If your PR includes C++ code, please adhere to the Google C++ Style Guide,
|
||||||
|
and don't forget we try to support older compilers (e.g. VS2010, GCC 4.6.3),
|
||||||
|
so only some C++11 support is available.
|
||||||
|
|
||||||
|
Include other details as appropriate.
|
||||||
|
|
||||||
|
Thanks!
|
||||||
9
.gitignore
vendored
9
.gitignore
vendored
@@ -40,6 +40,8 @@ flatsamplebinary
|
|||||||
flatsamplebinary.exe
|
flatsamplebinary.exe
|
||||||
flatsampletext
|
flatsampletext
|
||||||
flatsampletext.exe
|
flatsampletext.exe
|
||||||
|
grpctest
|
||||||
|
grpctest.exe
|
||||||
snapshot.sh
|
snapshot.sh
|
||||||
tests/go_gen
|
tests/go_gen
|
||||||
tests/monsterdata_java_wire.mon
|
tests/monsterdata_java_wire.mon
|
||||||
@@ -55,9 +57,12 @@ build/Xcode/FlatBuffers.xcodeproj/xcuserdata/**
|
|||||||
FlatBuffers.xcodeproj/
|
FlatBuffers.xcodeproj/
|
||||||
java/.idea
|
java/.idea
|
||||||
java/*.iml
|
java/*.iml
|
||||||
java/target
|
|
||||||
**/*.pyc
|
|
||||||
.idea
|
.idea
|
||||||
|
*.iml
|
||||||
|
target
|
||||||
|
**/*.pyc
|
||||||
build/VS2010/FlatBuffers.sdf
|
build/VS2010/FlatBuffers.sdf
|
||||||
build/VS2010/FlatBuffers.opensdf
|
build/VS2010/FlatBuffers.opensdf
|
||||||
build/VS2010/ipch/**/*.ipch
|
build/VS2010/ipch/**/*.ipch
|
||||||
|
*.so
|
||||||
|
Testing/Temporary
|
||||||
|
|||||||
@@ -12,8 +12,9 @@ env:
|
|||||||
matrix:
|
matrix:
|
||||||
- BUILD_TYPE=Debug BIICODE=false
|
- BUILD_TYPE=Debug BIICODE=false
|
||||||
- BUILD_TYPE=Release BIICODE=false
|
- BUILD_TYPE=Release BIICODE=false
|
||||||
- BUILD_TYPE=Release BIICODE=true
|
# biicode .deb files no longer available.
|
||||||
- BUILD_TYPE=Debug BIICODE=true
|
# - BUILD_TYPE=Release BIICODE=true
|
||||||
|
# - BUILD_TYPE=Debug BIICODE=true
|
||||||
global:
|
global:
|
||||||
- GCC_VERSION="4.9"
|
- GCC_VERSION="4.9"
|
||||||
|
|
||||||
|
|||||||
@@ -63,6 +63,13 @@ function(build_flatbuffers flatbuffers_schemas
|
|||||||
set(FLATC_TARGET flatc)
|
set(FLATC_TARGET flatc)
|
||||||
set(FLATC flatc)
|
set(FLATC flatc)
|
||||||
endif()
|
endif()
|
||||||
|
set(FLATC_SCHEMA_ARGS --gen-mutable)
|
||||||
|
if(FLATBUFFERS_FLATC_SCHEMA_EXTRA_ARGS)
|
||||||
|
set(FLATC_SCHEMA_ARGS
|
||||||
|
${FLATBUFFERS_FLATC_SCHEMA_EXTRA_ARGS}
|
||||||
|
${FLATC_SCHEMA_ARGS}
|
||||||
|
)
|
||||||
|
endif()
|
||||||
|
|
||||||
set(schema_glob "*.fbs")
|
set(schema_glob "*.fbs")
|
||||||
# Generate the include files parameters.
|
# Generate the include files parameters.
|
||||||
@@ -86,7 +93,7 @@ function(build_flatbuffers flatbuffers_schemas
|
|||||||
set(generated_include ${generated_includes_dir}/${filename}_generated.h)
|
set(generated_include ${generated_includes_dir}/${filename}_generated.h)
|
||||||
add_custom_command(
|
add_custom_command(
|
||||||
OUTPUT ${generated_include}
|
OUTPUT ${generated_include}
|
||||||
COMMAND ${FLATC} --gen-mutable
|
COMMAND ${FLATC} ${FLATC_SCHEMA_ARGS}
|
||||||
-o ${generated_includes_dir}
|
-o ${generated_includes_dir}
|
||||||
${include_params}
|
${include_params}
|
||||||
-c ${schema}
|
-c ${schema}
|
||||||
|
|||||||
57
CMake/PackageDebian.cmake
Normal file
57
CMake/PackageDebian.cmake
Normal file
@@ -0,0 +1,57 @@
|
|||||||
|
# ------------------- Debianization ---------------------
|
||||||
|
if (UNIX)
|
||||||
|
|
||||||
|
# Set build environment
|
||||||
|
SET(CPACK_GENERATOR "TGZ;DEB")
|
||||||
|
SET(CPACK_SOURCE_TGZ "ON")
|
||||||
|
|
||||||
|
# Common package information
|
||||||
|
SET(CPACK_PACKAGE_DESCRIPTION_SUMMARY
|
||||||
|
"FlatBuffers is an efficient cross platform serialization library for C++, with support for Java, C# and Go. It was created at Google specifically for game development and other performance-critical applications.")
|
||||||
|
SET(CPACK_DEBIAN_PACKAGE_HOMEPAGE "https://github.com/google/flatbuffers")
|
||||||
|
SET(CPACK_DEBIAN_PACKAGE_MAINTAINER "Vitaly Isaev <vitalyisaev2@gmail.com>")
|
||||||
|
|
||||||
|
# Derive package version from git
|
||||||
|
EXECUTE_PROCESS(
|
||||||
|
COMMAND date +%Y%m%d
|
||||||
|
OUTPUT_VARIABLE DATE
|
||||||
|
OUTPUT_STRIP_TRAILING_WHITESPACE
|
||||||
|
)
|
||||||
|
EXECUTE_PROCESS(
|
||||||
|
COMMAND git describe
|
||||||
|
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
|
||||||
|
OUTPUT_VARIABLE GIT_DESCRIBE_DIRTY
|
||||||
|
OUTPUT_STRIP_TRAILING_WHITESPACE
|
||||||
|
)
|
||||||
|
string(REGEX REPLACE "^v([0-9]+)\\..*" "\\1" VERSION_MAJOR "${GIT_DESCRIBE_DIRTY}")
|
||||||
|
string(REGEX REPLACE "^v[0-9]+\\.([0-9]+).*" "\\1" VERSION_MINOR "${GIT_DESCRIBE_DIRTY}")
|
||||||
|
string(REGEX REPLACE "^v[0-9]+\\.[0-9]+\\.([0-9]+).*" "\\1" VERSION_PATCH "${GIT_DESCRIBE_DIRTY}")
|
||||||
|
string(REGEX REPLACE "^v[0-9]+\\.[0-9]+\\.[0-9]+\\-([0-9]+).*" "\\1" VERSION_COMMIT "${GIT_DESCRIBE_DIRTY}")
|
||||||
|
SET(CPACK_PACKAGE_VERSION_MAJOR ${VERSION_MAJOR})
|
||||||
|
SET(CPACK_PACKAGE_VERSION_MINOR ${VERSION_MINOR})
|
||||||
|
SET(CPACK_PACKAGE_VERSION_PATCH ${VERSION_PATCH})
|
||||||
|
SET(CPACK_PACKAGE_VERSION "${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}-${VERSION_COMMIT}")
|
||||||
|
SET(CPACK_DEBIAN_PACKAGE_VERSION "${CPACK_PACKAGE_VERSION}")
|
||||||
|
|
||||||
|
# Derive architecture
|
||||||
|
IF(NOT CPACK_DEBIAN_PACKAGE_ARCHITECTURE)
|
||||||
|
FIND_PROGRAM(DPKG_CMD dpkg)
|
||||||
|
IF(NOT DPKG_CMD)
|
||||||
|
MESSAGE(STATUS "Can not find dpkg in your path, default to i386.")
|
||||||
|
SET(CPACK_DEBIAN_PACKAGE_ARCHITECTURE i386)
|
||||||
|
ENDIF(NOT DPKG_CMD)
|
||||||
|
EXECUTE_PROCESS(COMMAND "${DPKG_CMD}" --print-architecture
|
||||||
|
OUTPUT_VARIABLE CPACK_DEBIAN_PACKAGE_ARCHITECTURE
|
||||||
|
OUTPUT_STRIP_TRAILING_WHITESPACE
|
||||||
|
)
|
||||||
|
ENDIF(NOT CPACK_DEBIAN_PACKAGE_ARCHITECTURE)
|
||||||
|
|
||||||
|
# Package name
|
||||||
|
SET(CPACK_DEBIAN_PACKAGE_NAME "flatbuffers")
|
||||||
|
SET(CPACK_RESOURCE_FILE_LICENSE ${CMAKE_SOURCE_DIR}/LICENSE.txt)
|
||||||
|
SET(CPACK_PACKAGE_FILE_NAME
|
||||||
|
"${CPACK_DEBIAN_PACKAGE_NAME}_${CPACK_DEBIAN_PACKAGE_VERSION}_${CPACK_DEBIAN_PACKAGE_ARCHITECTURE}")
|
||||||
|
|
||||||
|
endif(UNIX)
|
||||||
|
|
||||||
|
INCLUDE(CPack)
|
||||||
119
CMakeLists.txt
119
CMakeLists.txt
@@ -6,9 +6,15 @@ project(FlatBuffers)
|
|||||||
option(FLATBUFFERS_CODE_COVERAGE "Enable the code coverage build option." OFF)
|
option(FLATBUFFERS_CODE_COVERAGE "Enable the code coverage build option." OFF)
|
||||||
option(FLATBUFFERS_BUILD_TESTS "Enable the build of tests and samples." ON)
|
option(FLATBUFFERS_BUILD_TESTS "Enable the build of tests and samples." ON)
|
||||||
option(FLATBUFFERS_INSTALL "Enable the installation of targets." ON)
|
option(FLATBUFFERS_INSTALL "Enable the installation of targets." ON)
|
||||||
option(FLATBUFFERS_BUILD_FLATLIB "Enable the build of the flatbuffers library" ON)
|
option(FLATBUFFERS_BUILD_FLATLIB "Enable the build of the flatbuffers library"
|
||||||
option(FLATBUFFERS_BUILD_FLATC "Enable the build of the flatbuffers compiler" ON)
|
ON)
|
||||||
|
option(FLATBUFFERS_BUILD_FLATC "Enable the build of the flatbuffers compiler"
|
||||||
|
ON)
|
||||||
option(FLATBUFFERS_BUILD_FLATHASH "Enable the build of flathash" ON)
|
option(FLATBUFFERS_BUILD_FLATHASH "Enable the build of flathash" ON)
|
||||||
|
option(FLATBUFFERS_BUILD_GRPCTEST "Enable the build of grpctest" OFF)
|
||||||
|
option(FLATBUFFERS_BUILD_SHAREDLIB
|
||||||
|
"Enable the build of the flatbuffers shared library"
|
||||||
|
OFF)
|
||||||
|
|
||||||
if(NOT FLATBUFFERS_BUILD_FLATC AND FLATBUFFERS_BUILD_TESTS)
|
if(NOT FLATBUFFERS_BUILD_FLATC AND FLATBUFFERS_BUILD_TESTS)
|
||||||
message(WARNING
|
message(WARNING
|
||||||
@@ -17,15 +23,19 @@ if(NOT FLATBUFFERS_BUILD_FLATC AND FLATBUFFERS_BUILD_TESTS)
|
|||||||
endif()
|
endif()
|
||||||
|
|
||||||
set(FlatBuffers_Library_SRCS
|
set(FlatBuffers_Library_SRCS
|
||||||
|
include/flatbuffers/code_generators.h
|
||||||
include/flatbuffers/flatbuffers.h
|
include/flatbuffers/flatbuffers.h
|
||||||
include/flatbuffers/hash.h
|
include/flatbuffers/hash.h
|
||||||
include/flatbuffers/idl.h
|
include/flatbuffers/idl.h
|
||||||
include/flatbuffers/util.h
|
include/flatbuffers/util.h
|
||||||
include/flatbuffers/reflection.h
|
include/flatbuffers/reflection.h
|
||||||
include/flatbuffers/reflection_generated.h
|
include/flatbuffers/reflection_generated.h
|
||||||
|
include/flatbuffers/flexbuffers.h
|
||||||
|
src/code_generators.cpp
|
||||||
src/idl_parser.cpp
|
src/idl_parser.cpp
|
||||||
src/idl_gen_text.cpp
|
src/idl_gen_text.cpp
|
||||||
src/reflection.cpp
|
src/reflection.cpp
|
||||||
|
src/util.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
set(FlatBuffers_Compiler_SRCS
|
set(FlatBuffers_Compiler_SRCS
|
||||||
@@ -37,7 +47,14 @@ set(FlatBuffers_Compiler_SRCS
|
|||||||
src/idl_gen_php.cpp
|
src/idl_gen_php.cpp
|
||||||
src/idl_gen_python.cpp
|
src/idl_gen_python.cpp
|
||||||
src/idl_gen_fbs.cpp
|
src/idl_gen_fbs.cpp
|
||||||
|
src/idl_gen_grpc.cpp
|
||||||
src/flatc.cpp
|
src/flatc.cpp
|
||||||
|
src/flatc_main.cpp
|
||||||
|
grpc/src/compiler/schema_interface.h
|
||||||
|
grpc/src/compiler/cpp_generator.h
|
||||||
|
grpc/src/compiler/cpp_generator.cc
|
||||||
|
grpc/src/compiler/go_generator.h
|
||||||
|
grpc/src/compiler/go_generator.cc
|
||||||
)
|
)
|
||||||
|
|
||||||
set(FlatHash_SRCS
|
set(FlatHash_SRCS
|
||||||
@@ -48,7 +65,6 @@ set(FlatHash_SRCS
|
|||||||
set(FlatBuffers_Tests_SRCS
|
set(FlatBuffers_Tests_SRCS
|
||||||
${FlatBuffers_Library_SRCS}
|
${FlatBuffers_Library_SRCS}
|
||||||
src/idl_gen_fbs.cpp
|
src/idl_gen_fbs.cpp
|
||||||
src/idl_gen_general.cpp
|
|
||||||
tests/test.cpp
|
tests/test.cpp
|
||||||
# file generate by running compiler on tests/monster_test.fbs
|
# file generate by running compiler on tests/monster_test.fbs
|
||||||
${CMAKE_CURRENT_BINARY_DIR}/tests/monster_test_generated.h
|
${CMAKE_CURRENT_BINARY_DIR}/tests/monster_test_generated.h
|
||||||
@@ -62,31 +78,66 @@ set(FlatBuffers_Sample_Binary_SRCS
|
|||||||
)
|
)
|
||||||
|
|
||||||
set(FlatBuffers_Sample_Text_SRCS
|
set(FlatBuffers_Sample_Text_SRCS
|
||||||
include/flatbuffers/flatbuffers.h
|
${FlatBuffers_Library_SRCS}
|
||||||
include/flatbuffers/hash.h
|
|
||||||
include/flatbuffers/idl.h
|
|
||||||
include/flatbuffers/util.h
|
|
||||||
src/idl_parser.cpp
|
|
||||||
src/idl_gen_text.cpp
|
|
||||||
samples/sample_text.cpp
|
samples/sample_text.cpp
|
||||||
# file generated by running compiler on samples/monster.fbs
|
# file generated by running compiler on samples/monster.fbs
|
||||||
${CMAKE_CURRENT_BINARY_DIR}/samples/monster_generated.h
|
${CMAKE_CURRENT_BINARY_DIR}/samples/monster_generated.h
|
||||||
)
|
)
|
||||||
|
|
||||||
|
set(FlatBuffers_GRPCTest_SRCS
|
||||||
|
include/flatbuffers/flatbuffers.h
|
||||||
|
include/flatbuffers/grpc.h
|
||||||
|
tests/monster_test.grpc.fb.h
|
||||||
|
tests/monster_test.grpc.fb.cc
|
||||||
|
grpc/tests/grpctest.cpp
|
||||||
|
# file generated by running compiler on samples/monster.fbs
|
||||||
|
${CMAKE_CURRENT_BINARY_DIR}/samples/monster_generated.h
|
||||||
|
)
|
||||||
|
|
||||||
# source_group(Compiler FILES ${FlatBuffers_Compiler_SRCS})
|
# source_group(Compiler FILES ${FlatBuffers_Compiler_SRCS})
|
||||||
# source_group(Tests FILES ${FlatBuffers_Tests_SRCS})
|
# source_group(Tests FILES ${FlatBuffers_Tests_SRCS})
|
||||||
|
|
||||||
if(APPLE)
|
if(EXISTS "${CMAKE_TOOLCHAIN_FILE}")
|
||||||
set(CMAKE_CXX_FLAGS
|
# do not apply any global settings if the toolchain
|
||||||
"${CMAKE_CXX_FLAGS} -std=c++11 -stdlib=libc++ -Wall -pedantic -Werror -Wextra")
|
# is being configured externally
|
||||||
|
elseif(APPLE)
|
||||||
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -stdlib=libc++")
|
||||||
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -pedantic -Werror -Wextra")
|
||||||
elseif(CMAKE_COMPILER_IS_GNUCXX)
|
elseif(CMAKE_COMPILER_IS_GNUCXX)
|
||||||
|
if(CYGWIN)
|
||||||
|
set(CMAKE_CXX_FLAGS
|
||||||
|
"${CMAKE_CXX_FLAGS} -std=gnu++11")
|
||||||
|
else(CYGWIN)
|
||||||
|
set(CMAKE_CXX_FLAGS
|
||||||
|
"${CMAKE_CXX_FLAGS} -std=c++0x")
|
||||||
|
endif(CYGWIN)
|
||||||
set(CMAKE_CXX_FLAGS
|
set(CMAKE_CXX_FLAGS
|
||||||
"${CMAKE_CXX_FLAGS} -std=c++0x -Wall -pedantic -Werror -Wextra -Werror=shadow -Wunused-result -Werror=unused-result")
|
"${CMAKE_CXX_FLAGS} -Wall -pedantic -Werror -Wextra -Werror=shadow")
|
||||||
elseif("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
|
if (GCC_VERSION VERSION_GREATER 4.4)
|
||||||
|
set(CMAKE_CXX_FLAGS
|
||||||
|
"${CMAKE_CXX_FLAGS} -Wunused-result -Werror=unused-result \
|
||||||
|
-Wunused-parameter -Werror=unused-parameter")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
# Certain platforms such as ARM do not use signed chars by default
|
||||||
|
# which causes issues with certain bounds checks.
|
||||||
set(CMAKE_CXX_FLAGS
|
set(CMAKE_CXX_FLAGS
|
||||||
"${CMAKE_CXX_FLAGS} -std=c++0x -stdlib=libc++ -Wall -pedantic -Werror -Wextra")
|
"${CMAKE_CXX_FLAGS} -fsigned-char")
|
||||||
set(CMAKE_EXE_LINKER_FLAGS
|
|
||||||
"${CMAKE_EXE_LINKER_FLAGS} -lc++abi")
|
elseif(${CMAKE_CXX_COMPILER_ID} MATCHES "Clang")
|
||||||
|
set(CMAKE_CXX_FLAGS
|
||||||
|
"${CMAKE_CXX_FLAGS} -std=c++0x -stdlib=libc++ -Wall -pedantic -Werror \
|
||||||
|
-Wextra")
|
||||||
|
if(NOT "${CMAKE_SYSTEM_NAME}" MATCHES "FreeBSD")
|
||||||
|
set(CMAKE_EXE_LINKER_FLAGS
|
||||||
|
"${CMAKE_EXE_LINKER_FLAGS} -lc++abi")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
# Certain platforms such as ARM do not use signed chars by default
|
||||||
|
# which causes issues with certain bounds checks.
|
||||||
|
set(CMAKE_CXX_FLAGS
|
||||||
|
"${CMAKE_CXX_FLAGS} -fsigned-char")
|
||||||
|
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if(FLATBUFFERS_CODE_COVERAGE)
|
if(FLATBUFFERS_CODE_COVERAGE)
|
||||||
@@ -101,6 +152,7 @@ if(BIICODE)
|
|||||||
endif()
|
endif()
|
||||||
|
|
||||||
include_directories(include)
|
include_directories(include)
|
||||||
|
include_directories(grpc)
|
||||||
|
|
||||||
if(FLATBUFFERS_BUILD_FLATLIB)
|
if(FLATBUFFERS_BUILD_FLATLIB)
|
||||||
add_library(flatbuffers STATIC ${FlatBuffers_Library_SRCS})
|
add_library(flatbuffers STATIC ${FlatBuffers_Library_SRCS})
|
||||||
@@ -108,18 +160,28 @@ endif()
|
|||||||
|
|
||||||
if(FLATBUFFERS_BUILD_FLATC)
|
if(FLATBUFFERS_BUILD_FLATC)
|
||||||
add_executable(flatc ${FlatBuffers_Compiler_SRCS})
|
add_executable(flatc ${FlatBuffers_Compiler_SRCS})
|
||||||
|
if(NOT FLATBUFFERS_FLATC_EXECUTABLE)
|
||||||
|
set(FLATBUFFERS_FLATC_EXECUTABLE $<TARGET_FILE:flatc>)
|
||||||
|
endif()
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if(FLATBUFFERS_BUILD_FLATHASH)
|
if(FLATBUFFERS_BUILD_FLATHASH)
|
||||||
add_executable(flathash ${FlatHash_SRCS})
|
add_executable(flathash ${FlatHash_SRCS})
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
if(FLATBUFFERS_BUILD_SHAREDLIB)
|
||||||
|
add_library(flatbuffers_shared SHARED ${FlatBuffers_Library_SRCS})
|
||||||
|
set_target_properties(flatbuffers_shared PROPERTIES OUTPUT_NAME flatbuffers)
|
||||||
|
endif()
|
||||||
|
|
||||||
function(compile_flatbuffers_schema_to_cpp SRC_FBS)
|
function(compile_flatbuffers_schema_to_cpp SRC_FBS)
|
||||||
get_filename_component(SRC_FBS_DIR ${SRC_FBS} PATH)
|
get_filename_component(SRC_FBS_DIR ${SRC_FBS} PATH)
|
||||||
string(REGEX REPLACE "\\.fbs$" "_generated.h" GEN_HEADER ${SRC_FBS})
|
string(REGEX REPLACE "\\.fbs$" "_generated.h" GEN_HEADER ${SRC_FBS})
|
||||||
add_custom_command(
|
add_custom_command(
|
||||||
OUTPUT ${GEN_HEADER}
|
OUTPUT ${GEN_HEADER}
|
||||||
COMMAND "${FLATBUFFERS_FLATC_EXECUTABLE}" -c --no-includes --gen-mutable -o "${SRC_FBS_DIR}" "${CMAKE_CURRENT_SOURCE_DIR}/${SRC_FBS}"
|
COMMAND "${FLATBUFFERS_FLATC_EXECUTABLE}" -c --no-includes --gen-mutable
|
||||||
|
--gen-object-api -o "${SRC_FBS_DIR}"
|
||||||
|
"${CMAKE_CURRENT_SOURCE_DIR}/${SRC_FBS}"
|
||||||
DEPENDS flatc)
|
DEPENDS flatc)
|
||||||
endfunction()
|
endfunction()
|
||||||
|
|
||||||
@@ -128,7 +190,8 @@ function(compile_flatbuffers_schema_to_binary SRC_FBS)
|
|||||||
string(REGEX REPLACE "\\.fbs$" ".bfbs" GEN_BINARY_SCHEMA ${SRC_FBS})
|
string(REGEX REPLACE "\\.fbs$" ".bfbs" GEN_BINARY_SCHEMA ${SRC_FBS})
|
||||||
add_custom_command(
|
add_custom_command(
|
||||||
OUTPUT ${GEN_BINARY_SCHEMA}
|
OUTPUT ${GEN_BINARY_SCHEMA}
|
||||||
COMMAND "${FLATBUFFERS_FLATC_EXECUTABLE}" -b --schema -o "${SRC_FBS_DIR}" "${CMAKE_CURRENT_SOURCE_DIR}/${SRC_FBS}"
|
COMMAND "${FLATBUFFERS_FLATC_EXECUTABLE}" -b --schema -o "${SRC_FBS_DIR}"
|
||||||
|
"${CMAKE_CURRENT_SOURCE_DIR}/${SRC_FBS}"
|
||||||
DEPENDS flatc)
|
DEPENDS flatc)
|
||||||
endfunction()
|
endfunction()
|
||||||
|
|
||||||
@@ -136,6 +199,9 @@ if(FLATBUFFERS_BUILD_TESTS)
|
|||||||
compile_flatbuffers_schema_to_cpp(tests/monster_test.fbs)
|
compile_flatbuffers_schema_to_cpp(tests/monster_test.fbs)
|
||||||
include_directories(${CMAKE_CURRENT_BINARY_DIR}/tests)
|
include_directories(${CMAKE_CURRENT_BINARY_DIR}/tests)
|
||||||
add_executable(flattests ${FlatBuffers_Tests_SRCS})
|
add_executable(flattests ${FlatBuffers_Tests_SRCS})
|
||||||
|
set_property(TARGET flattests
|
||||||
|
PROPERTY COMPILE_DEFINITIONS FLATBUFFERS_TRACK_VERIFIER_BUFFER_SIZE
|
||||||
|
FLATBUFFERS_DEBUG_VERIFICATION_FAILURE=1)
|
||||||
|
|
||||||
compile_flatbuffers_schema_to_cpp(samples/monster.fbs)
|
compile_flatbuffers_schema_to_cpp(samples/monster.fbs)
|
||||||
include_directories(${CMAKE_CURRENT_BINARY_DIR}/samples)
|
include_directories(${CMAKE_CURRENT_BINARY_DIR}/samples)
|
||||||
@@ -143,6 +209,14 @@ if(FLATBUFFERS_BUILD_TESTS)
|
|||||||
add_executable(flatsampletext ${FlatBuffers_Sample_Text_SRCS})
|
add_executable(flatsampletext ${FlatBuffers_Sample_Text_SRCS})
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
if(FLATBUFFERS_BUILD_GRPCTEST)
|
||||||
|
if(CMAKE_COMPILER_IS_GNUCXX)
|
||||||
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unused-parameter")
|
||||||
|
endif()
|
||||||
|
add_executable(grpctest ${FlatBuffers_GRPCTest_SRCS})
|
||||||
|
target_link_libraries(grpctest grpc++_unsecure grpc pthread dl)
|
||||||
|
endif()
|
||||||
|
|
||||||
if(FLATBUFFERS_INSTALL)
|
if(FLATBUFFERS_INSTALL)
|
||||||
install(DIRECTORY include/flatbuffers DESTINATION include)
|
install(DIRECTORY include/flatbuffers DESTINATION include)
|
||||||
if(FLATBUFFERS_BUILD_FLATLIB)
|
if(FLATBUFFERS_BUILD_FLATLIB)
|
||||||
@@ -151,6 +225,9 @@ if(FLATBUFFERS_INSTALL)
|
|||||||
if(FLATBUFFERS_BUILD_FLATC)
|
if(FLATBUFFERS_BUILD_FLATC)
|
||||||
install(TARGETS flatc DESTINATION bin)
|
install(TARGETS flatc DESTINATION bin)
|
||||||
endif()
|
endif()
|
||||||
|
if(FLATBUFFERS_BUILD_SHAREDLIB)
|
||||||
|
install(TARGETS flatbuffers_shared DESTINATION lib)
|
||||||
|
endif()
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if(FLATBUFFERS_BUILD_TESTS)
|
if(FLATBUFFERS_BUILD_TESTS)
|
||||||
@@ -162,3 +239,7 @@ if(FLATBUFFERS_BUILD_TESTS)
|
|||||||
endif()
|
endif()
|
||||||
|
|
||||||
include(CMake/BuildFlatBuffers.cmake)
|
include(CMake/BuildFlatBuffers.cmake)
|
||||||
|
|
||||||
|
if(FLATBUFFERS_PACKAGE_DEBIAN)
|
||||||
|
include(CMake/PackageDebian.cmake)
|
||||||
|
endif()
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ use Github pull requests for this purpose.
|
|||||||
|
|
||||||
Some tips for good pull requests:
|
Some tips for good pull requests:
|
||||||
* Use our code
|
* Use our code
|
||||||
[style guide](http://google-styleguide.googlecode.com/svn/trunk/cppguide.html).
|
[style guide](https://google.github.io/styleguide/cppguide.html).
|
||||||
When in doubt, try to stay true to the existing code of the project.
|
When in doubt, try to stay true to the existing code of the project.
|
||||||
* Write a descriptive commit message. What problem are you solving and what
|
* Write a descriptive commit message. What problem are you solving and what
|
||||||
are the consequences? Where and what did you test? Some good tips:
|
are the consequences? Where and what did you test? Some good tips:
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
#!/bin/bash -eu
|
#!/bin/bash -eu
|
||||||
|
#
|
||||||
# Copyright (c) 2013 Google, Inc.
|
# Copyright (c) 2013 Google, Inc.
|
||||||
#
|
#
|
||||||
# This software is provided 'as-is', without any express or implied
|
# This software is provided 'as-is', without any express or implied
|
||||||
|
|||||||
@@ -24,7 +24,9 @@ LOCAL_PATH := $(call realpath-portable,$(LOCAL_PATH))
|
|||||||
include $(CLEAR_VARS)
|
include $(CLEAR_VARS)
|
||||||
LOCAL_MODULE := flatbuffers
|
LOCAL_MODULE := flatbuffers
|
||||||
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/include
|
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/include
|
||||||
LOCAL_EXPORT_CPPFLAGS := -std=c++11 -fexceptions -Wall -Wno-literal-suffix
|
LOCAL_EXPORT_CPPFLAGS := -std=c++11 -fexceptions -Wall \
|
||||||
|
-DFLATBUFFERS_TRACK_VERIFIER_BUFFER_SIZE
|
||||||
|
|
||||||
include $(BUILD_STATIC_LIBRARY)
|
include $(BUILD_STATIC_LIBRARY)
|
||||||
|
|
||||||
# static library that additionally includes text parsing/generation/reflection
|
# static library that additionally includes text parsing/generation/reflection
|
||||||
@@ -33,7 +35,9 @@ include $(CLEAR_VARS)
|
|||||||
LOCAL_MODULE := flatbuffers_extra
|
LOCAL_MODULE := flatbuffers_extra
|
||||||
LOCAL_SRC_FILES := src/idl_parser.cpp \
|
LOCAL_SRC_FILES := src/idl_parser.cpp \
|
||||||
src/idl_gen_text.cpp \
|
src/idl_gen_text.cpp \
|
||||||
src/reflection.cpp
|
src/reflection.cpp \
|
||||||
|
src/util.cpp \
|
||||||
|
src/code_generators.cpp
|
||||||
LOCAL_STATIC_LIBRARIES := flatbuffers
|
LOCAL_STATIC_LIBRARIES := flatbuffers
|
||||||
include $(BUILD_STATIC_LIBRARY)
|
include $(BUILD_STATIC_LIBRARY)
|
||||||
|
|
||||||
|
|||||||
@@ -18,5 +18,5 @@ APP_PROJECT_PATH := $(call my-dir)/..
|
|||||||
APP_STL := gnustl_static
|
APP_STL := gnustl_static
|
||||||
|
|
||||||
APP_ABI := armeabi-v7a
|
APP_ABI := armeabi-v7a
|
||||||
NDK_TOOLCHAIN_VERSION := 4.8
|
|
||||||
APP_CPPFLAGS += -std=c++11
|
APP_CPPFLAGS += -std=c++11
|
||||||
|
|||||||
46
appveyor.yml
Normal file
46
appveyor.yml
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
branches:
|
||||||
|
only:
|
||||||
|
- master
|
||||||
|
|
||||||
|
os: Visual Studio 2015
|
||||||
|
|
||||||
|
platform:
|
||||||
|
- x86
|
||||||
|
- x64
|
||||||
|
|
||||||
|
configuration:
|
||||||
|
- Debug
|
||||||
|
- Release
|
||||||
|
|
||||||
|
before_build:
|
||||||
|
- cmake -G"Visual Studio 10 2010"
|
||||||
|
# This cuts down on a lot of noise generated by xamarin warnings.
|
||||||
|
- del "C:\Program Files (x86)\MSBuild\14.0\Microsoft.Common.targets\ImportAfter\Xamarin.Common.targets"
|
||||||
|
|
||||||
|
build:
|
||||||
|
project: ALL_BUILD.vcxproj
|
||||||
|
verbosity: minimal
|
||||||
|
|
||||||
|
test_script:
|
||||||
|
- rem "---------------- C++ -----------------"
|
||||||
|
- "%CONFIGURATION%\\flattests.exe"
|
||||||
|
- rem "---------------- Java -----------------"
|
||||||
|
- "cd tests"
|
||||||
|
- "java -version"
|
||||||
|
- "JavaTest.bat"
|
||||||
|
- rem "---------------- JS -----------------"
|
||||||
|
- "node --version"
|
||||||
|
- "..\\%CONFIGURATION%\\flatc -b monster_test.fbs unicode_test.json"
|
||||||
|
- "node JavaScriptTest"
|
||||||
|
- rem "---------------- C# -----------------"
|
||||||
|
# Have to compile this here rather than in "build" above because AppVeyor only
|
||||||
|
# supports building one project??
|
||||||
|
- "cd FlatBuffers.Test"
|
||||||
|
- "msbuild.exe /property:Configuration=Release;OutputPath=tempcs /verbosity:minimal FlatBuffers.Test.csproj"
|
||||||
|
- "tempcs\\FlatBuffers.Test.exe"
|
||||||
|
# TODO: add more languages.
|
||||||
|
- "cd ..\\.."
|
||||||
|
|
||||||
|
artifacts:
|
||||||
|
- path: $(CONFIGURATION)\\flatc.exe
|
||||||
|
name: flatc.exe
|
||||||
@@ -1,4 +1,18 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
#
|
||||||
|
# Copyright 2016 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.
|
||||||
|
|
||||||
sudo apt-get update -qq
|
sudo apt-get update -qq
|
||||||
sudo apt-get install libglu1-mesa-dev xorg-dev
|
sudo apt-get install libglu1-mesa-dev xorg-dev
|
||||||
|
|||||||
@@ -1,55 +0,0 @@
|
|||||||
Microsoft Visual Studio Solution File, Format Version 11.00
|
|
||||||
# Visual Studio 2010
|
|
||||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "flatc", "flatc.vcxproj", "{5B5857E1-64E2-4CED-A12E-45E1B3880496}"
|
|
||||||
EndProject
|
|
||||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "flatsamplebinary", "flatsamplebinary.vcxproj", "{16FA5518-3DE1-4B15-A1E0-F4734C276FB4}"
|
|
||||||
EndProject
|
|
||||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "flatsampletext", "flatsampletext.vcxproj", "{F0A15675-1017-4217-BB5B-3372F2C636AB}"
|
|
||||||
EndProject
|
|
||||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "flattests", "flattests.vcxproj", "{DC7BBA00-9FC6-48AF-B7E9-12CA91AC02AA}"
|
|
||||||
EndProject
|
|
||||||
Global
|
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
|
||||||
Debug|Win32 = Debug|Win32
|
|
||||||
Debug|x64 = Debug|x64
|
|
||||||
Release|Win32 = Release|Win32
|
|
||||||
Release|x64 = Release|x64
|
|
||||||
EndGlobalSection
|
|
||||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
|
||||||
{5B5857E1-64E2-4CED-A12E-45E1B3880496}.Debug|Win32.ActiveCfg = Debug|Win32
|
|
||||||
{5B5857E1-64E2-4CED-A12E-45E1B3880496}.Debug|Win32.Build.0 = Debug|Win32
|
|
||||||
{5B5857E1-64E2-4CED-A12E-45E1B3880496}.Debug|x64.ActiveCfg = Debug|x64
|
|
||||||
{5B5857E1-64E2-4CED-A12E-45E1B3880496}.Debug|x64.Build.0 = Debug|x64
|
|
||||||
{5B5857E1-64E2-4CED-A12E-45E1B3880496}.Release|Win32.ActiveCfg = Release|Win32
|
|
||||||
{5B5857E1-64E2-4CED-A12E-45E1B3880496}.Release|Win32.Build.0 = Release|Win32
|
|
||||||
{5B5857E1-64E2-4CED-A12E-45E1B3880496}.Release|x64.ActiveCfg = Release|x64
|
|
||||||
{5B5857E1-64E2-4CED-A12E-45E1B3880496}.Release|x64.Build.0 = Release|x64
|
|
||||||
{16FA5518-3DE1-4B15-A1E0-F4734C276FB4}.Debug|Win32.ActiveCfg = Debug|Win32
|
|
||||||
{16FA5518-3DE1-4B15-A1E0-F4734C276FB4}.Debug|Win32.Build.0 = Debug|Win32
|
|
||||||
{16FA5518-3DE1-4B15-A1E0-F4734C276FB4}.Debug|x64.ActiveCfg = Debug|x64
|
|
||||||
{16FA5518-3DE1-4B15-A1E0-F4734C276FB4}.Debug|x64.Build.0 = Debug|x64
|
|
||||||
{16FA5518-3DE1-4B15-A1E0-F4734C276FB4}.Release|Win32.ActiveCfg = Release|Win32
|
|
||||||
{16FA5518-3DE1-4B15-A1E0-F4734C276FB4}.Release|Win32.Build.0 = Release|Win32
|
|
||||||
{16FA5518-3DE1-4B15-A1E0-F4734C276FB4}.Release|x64.ActiveCfg = Release|x64
|
|
||||||
{16FA5518-3DE1-4B15-A1E0-F4734C276FB4}.Release|x64.Build.0 = Release|x64
|
|
||||||
{F0A15675-1017-4217-BB5B-3372F2C636AB}.Debug|Win32.ActiveCfg = Debug|Win32
|
|
||||||
{F0A15675-1017-4217-BB5B-3372F2C636AB}.Debug|Win32.Build.0 = Debug|Win32
|
|
||||||
{F0A15675-1017-4217-BB5B-3372F2C636AB}.Debug|x64.ActiveCfg = Debug|x64
|
|
||||||
{F0A15675-1017-4217-BB5B-3372F2C636AB}.Debug|x64.Build.0 = Debug|x64
|
|
||||||
{F0A15675-1017-4217-BB5B-3372F2C636AB}.Release|Win32.ActiveCfg = Release|Win32
|
|
||||||
{F0A15675-1017-4217-BB5B-3372F2C636AB}.Release|Win32.Build.0 = Release|Win32
|
|
||||||
{F0A15675-1017-4217-BB5B-3372F2C636AB}.Release|x64.ActiveCfg = Release|x64
|
|
||||||
{F0A15675-1017-4217-BB5B-3372F2C636AB}.Release|x64.Build.0 = Release|x64
|
|
||||||
{DC7BBA00-9FC6-48AF-B7E9-12CA91AC02AA}.Debug|Win32.ActiveCfg = Debug|Win32
|
|
||||||
{DC7BBA00-9FC6-48AF-B7E9-12CA91AC02AA}.Debug|Win32.Build.0 = Debug|Win32
|
|
||||||
{DC7BBA00-9FC6-48AF-B7E9-12CA91AC02AA}.Debug|x64.ActiveCfg = Debug|x64
|
|
||||||
{DC7BBA00-9FC6-48AF-B7E9-12CA91AC02AA}.Debug|x64.Build.0 = Debug|x64
|
|
||||||
{DC7BBA00-9FC6-48AF-B7E9-12CA91AC02AA}.Release|Win32.ActiveCfg = Release|Win32
|
|
||||||
{DC7BBA00-9FC6-48AF-B7E9-12CA91AC02AA}.Release|Win32.Build.0 = Release|Win32
|
|
||||||
{DC7BBA00-9FC6-48AF-B7E9-12CA91AC02AA}.Release|x64.ActiveCfg = Release|x64
|
|
||||||
{DC7BBA00-9FC6-48AF-B7E9-12CA91AC02AA}.Release|x64.Build.0 = Release|x64
|
|
||||||
EndGlobalSection
|
|
||||||
GlobalSection(SolutionProperties) = preSolution
|
|
||||||
HideSolutionNode = FALSE
|
|
||||||
EndGlobalSection
|
|
||||||
EndGlobal
|
|
||||||
@@ -1,285 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
|
||||||
<ItemGroup Label="ProjectConfigurations">
|
|
||||||
<ProjectConfiguration Include="Debug|Win32">
|
|
||||||
<Configuration>Debug</Configuration>
|
|
||||||
<Platform>Win32</Platform>
|
|
||||||
</ProjectConfiguration>
|
|
||||||
<ProjectConfiguration Include="Debug|x64">
|
|
||||||
<Configuration>Debug</Configuration>
|
|
||||||
<Platform>x64</Platform>
|
|
||||||
</ProjectConfiguration>
|
|
||||||
<ProjectConfiguration Include="Release|Win32">
|
|
||||||
<Configuration>Release</Configuration>
|
|
||||||
<Platform>Win32</Platform>
|
|
||||||
</ProjectConfiguration>
|
|
||||||
<ProjectConfiguration Include="Release|x64">
|
|
||||||
<Configuration>Release</Configuration>
|
|
||||||
<Platform>x64</Platform>
|
|
||||||
</ProjectConfiguration>
|
|
||||||
</ItemGroup>
|
|
||||||
<PropertyGroup Label="Globals">
|
|
||||||
<ProjectGUID>{5B5857E1-64E2-4CED-A12E-45E1B3880496}</ProjectGUID>
|
|
||||||
<Keyword>Win32Proj</Keyword>
|
|
||||||
<Platform>Win32</Platform>
|
|
||||||
<ProjectName>flatc</ProjectName>
|
|
||||||
</PropertyGroup>
|
|
||||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
|
||||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
|
|
||||||
<ConfigurationType>Application</ConfigurationType>
|
|
||||||
<UseOfMfc>false</UseOfMfc>
|
|
||||||
<CharacterSet>MultiByte</CharacterSet>
|
|
||||||
</PropertyGroup>
|
|
||||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
|
|
||||||
<ConfigurationType>Application</ConfigurationType>
|
|
||||||
<UseOfMfc>false</UseOfMfc>
|
|
||||||
<CharacterSet>MultiByte</CharacterSet>
|
|
||||||
</PropertyGroup>
|
|
||||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
|
||||||
<ConfigurationType>Application</ConfigurationType>
|
|
||||||
<UseOfMfc>false</UseOfMfc>
|
|
||||||
<CharacterSet>MultiByte</CharacterSet>
|
|
||||||
</PropertyGroup>
|
|
||||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
|
|
||||||
<ConfigurationType>Application</ConfigurationType>
|
|
||||||
<UseOfMfc>false</UseOfMfc>
|
|
||||||
<CharacterSet>MultiByte</CharacterSet>
|
|
||||||
</PropertyGroup>
|
|
||||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
|
||||||
<ImportGroup Label="ExtensionSettings">
|
|
||||||
</ImportGroup>
|
|
||||||
<ImportGroup Label="PropertySheets">
|
|
||||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
|
||||||
</ImportGroup>
|
|
||||||
<PropertyGroup Label="UserMacros" />
|
|
||||||
<PropertyGroup>
|
|
||||||
<_ProjectFileVersion>10.0.20506.1</_ProjectFileVersion>
|
|
||||||
<OutDir Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">$(IntDir)</OutDir>
|
|
||||||
<OutDir Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">$(IntDir)</OutDir>
|
|
||||||
<IntDir Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">flatc.dir\Debug\</IntDir>
|
|
||||||
<IntDir Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">flatc.dir\Debug\</IntDir>
|
|
||||||
<TargetName Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">flatc</TargetName>
|
|
||||||
<TargetName Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">flatc</TargetName>
|
|
||||||
<TargetExt Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">.exe</TargetExt>
|
|
||||||
<TargetExt Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">.exe</TargetExt>
|
|
||||||
<LinkIncremental Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</LinkIncremental>
|
|
||||||
<LinkIncremental Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</LinkIncremental>
|
|
||||||
<GenerateManifest Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</GenerateManifest>
|
|
||||||
<GenerateManifest Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</GenerateManifest>
|
|
||||||
<OutDir Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">$(IntDir)</OutDir>
|
|
||||||
<OutDir Condition="'$(Configuration)|$(Platform)'=='Release|x64'">$(IntDir)</OutDir>
|
|
||||||
<IntDir Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">flatc.dir\Release\</IntDir>
|
|
||||||
<IntDir Condition="'$(Configuration)|$(Platform)'=='Release|x64'">flatc.dir\Release\</IntDir>
|
|
||||||
<TargetName Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">flatc</TargetName>
|
|
||||||
<TargetName Condition="'$(Configuration)|$(Platform)'=='Release|x64'">flatc</TargetName>
|
|
||||||
<TargetExt Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">.exe</TargetExt>
|
|
||||||
<TargetExt Condition="'$(Configuration)|$(Platform)'=='Release|x64'">.exe</TargetExt>
|
|
||||||
<LinkIncremental Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">false</LinkIncremental>
|
|
||||||
<LinkIncremental Condition="'$(Configuration)|$(Platform)'=='Release|x64'">false</LinkIncremental>
|
|
||||||
<GenerateManifest Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</GenerateManifest>
|
|
||||||
<GenerateManifest Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</GenerateManifest>
|
|
||||||
</PropertyGroup>
|
|
||||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
|
||||||
<ClCompile>
|
|
||||||
<AdditionalIncludeDirectories>../../include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
|
||||||
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
|
|
||||||
<CompileAs>CompileAsCpp</CompileAs>
|
|
||||||
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
|
|
||||||
<ExceptionHandling>Sync</ExceptionHandling>
|
|
||||||
<InlineFunctionExpansion>Disabled</InlineFunctionExpansion>
|
|
||||||
<Optimization>Disabled</Optimization>
|
|
||||||
<PrecompiledHeader>NotUsing</PrecompiledHeader>
|
|
||||||
<RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
|
|
||||||
<RuntimeTypeInfo>true</RuntimeTypeInfo>
|
|
||||||
<WarningLevel>Level4</WarningLevel>
|
|
||||||
<PreprocessorDefinitions>WIN32;_WINDOWS;_DEBUG;CMAKE_INTDIR="Debug";%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
|
||||||
<AssemblerListingLocation>Debug</AssemblerListingLocation>
|
|
||||||
<ObjectFileName>$(IntDir)</ObjectFileName>
|
|
||||||
<ProgramDataBaseFileName>../../Debug/flatc.pdb</ProgramDataBaseFileName>
|
|
||||||
<TreatWarningAsError>true</TreatWarningAsError>
|
|
||||||
</ClCompile>
|
|
||||||
<ResourceCompile>
|
|
||||||
<PreprocessorDefinitions>WIN32;_WINDOWS;_DEBUG;CMAKE_INTDIR=\"Debug\";%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
|
||||||
<AdditionalIncludeDirectories>../../include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
|
||||||
</ResourceCompile>
|
|
||||||
<Midl>
|
|
||||||
<AdditionalIncludeDirectories>../../include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
|
||||||
<OutputDirectory>$(IntDir)</OutputDirectory>
|
|
||||||
<HeaderFileName>%(Filename).h</HeaderFileName>
|
|
||||||
<TypeLibraryName>%(Filename).tlb</TypeLibraryName>
|
|
||||||
<InterfaceIdentifierFileName>%(Filename)_i.c</InterfaceIdentifierFileName>
|
|
||||||
<ProxyFileName>%(Filename)_p.c</ProxyFileName>
|
|
||||||
</Midl>
|
|
||||||
<Link>
|
|
||||||
<AdditionalOptions> /machine:X86 /debug %(AdditionalOptions)</AdditionalOptions>
|
|
||||||
<AdditionalDependencies>kernel32.lib;user32.lib;gdi32.lib;winspool.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;comdlg32.lib;advapi32.lib</AdditionalDependencies>
|
|
||||||
<AdditionalLibraryDirectories>%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
|
|
||||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
|
||||||
<ImportLibrary>../../Debug/flatc.lib</ImportLibrary>
|
|
||||||
<ProgramDataBaseFile>../../Debug/flatc.pdb</ProgramDataBaseFile>
|
|
||||||
<SubSystem>Console</SubSystem>
|
|
||||||
<Version>
|
|
||||||
</Version>
|
|
||||||
</Link>
|
|
||||||
<ProjectReference>
|
|
||||||
<LinkLibraryDependencies>false</LinkLibraryDependencies>
|
|
||||||
</ProjectReference>
|
|
||||||
</ItemDefinitionGroup>
|
|
||||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
|
||||||
<ClCompile>
|
|
||||||
<AdditionalIncludeDirectories>../../include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
|
||||||
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
|
|
||||||
<CompileAs>CompileAsCpp</CompileAs>
|
|
||||||
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
|
|
||||||
<ExceptionHandling>Sync</ExceptionHandling>
|
|
||||||
<InlineFunctionExpansion>Disabled</InlineFunctionExpansion>
|
|
||||||
<Optimization>Disabled</Optimization>
|
|
||||||
<PrecompiledHeader>NotUsing</PrecompiledHeader>
|
|
||||||
<RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
|
|
||||||
<RuntimeTypeInfo>true</RuntimeTypeInfo>
|
|
||||||
<WarningLevel>Level4</WarningLevel>
|
|
||||||
<PreprocessorDefinitions>WIN32;_WINDOWS;_DEBUG;CMAKE_INTDIR="Debug";%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
|
||||||
<AssemblerListingLocation>Debug</AssemblerListingLocation>
|
|
||||||
<ObjectFileName>$(IntDir)</ObjectFileName>
|
|
||||||
<ProgramDataBaseFileName>../../Debug/flatc.pdb</ProgramDataBaseFileName>
|
|
||||||
<TreatWarningAsError>true</TreatWarningAsError>
|
|
||||||
</ClCompile>
|
|
||||||
<ResourceCompile>
|
|
||||||
<PreprocessorDefinitions>WIN32;_WINDOWS;_DEBUG;CMAKE_INTDIR=\"Debug\";%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
|
||||||
<AdditionalIncludeDirectories>../../include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
|
||||||
</ResourceCompile>
|
|
||||||
<Midl>
|
|
||||||
<AdditionalIncludeDirectories>../../include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
|
||||||
<OutputDirectory>$(IntDir)</OutputDirectory>
|
|
||||||
<HeaderFileName>%(Filename).h</HeaderFileName>
|
|
||||||
<TypeLibraryName>%(Filename).tlb</TypeLibraryName>
|
|
||||||
<InterfaceIdentifierFileName>%(Filename)_i.c</InterfaceIdentifierFileName>
|
|
||||||
<ProxyFileName>%(Filename)_p.c</ProxyFileName>
|
|
||||||
</Midl>
|
|
||||||
<Link>
|
|
||||||
<AdditionalOptions>/debug %(AdditionalOptions)</AdditionalOptions>
|
|
||||||
<AdditionalDependencies>kernel32.lib;user32.lib;gdi32.lib;winspool.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;comdlg32.lib;advapi32.lib</AdditionalDependencies>
|
|
||||||
<AdditionalLibraryDirectories>%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
|
|
||||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
|
||||||
<ImportLibrary>../../Debug/flatc.lib</ImportLibrary>
|
|
||||||
<ProgramDataBaseFile>../../Debug/flatc.pdb</ProgramDataBaseFile>
|
|
||||||
<SubSystem>Console</SubSystem>
|
|
||||||
<Version>
|
|
||||||
</Version>
|
|
||||||
</Link>
|
|
||||||
<ProjectReference>
|
|
||||||
<LinkLibraryDependencies>false</LinkLibraryDependencies>
|
|
||||||
</ProjectReference>
|
|
||||||
</ItemDefinitionGroup>
|
|
||||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
|
||||||
<ClCompile>
|
|
||||||
<AdditionalIncludeDirectories>../../include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
|
||||||
<CompileAs>CompileAsCpp</CompileAs>
|
|
||||||
<ExceptionHandling>Sync</ExceptionHandling>
|
|
||||||
<InlineFunctionExpansion>AnySuitable</InlineFunctionExpansion>
|
|
||||||
<Optimization>MaxSpeed</Optimization>
|
|
||||||
<PrecompiledHeader>NotUsing</PrecompiledHeader>
|
|
||||||
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
|
|
||||||
<RuntimeTypeInfo>true</RuntimeTypeInfo>
|
|
||||||
<WarningLevel>Level4</WarningLevel>
|
|
||||||
<DebugInformationFormat>
|
|
||||||
</DebugInformationFormat>
|
|
||||||
<PreprocessorDefinitions>WIN32;_WINDOWS;NDEBUG;CMAKE_INTDIR="Release";%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
|
||||||
<AssemblerListingLocation>Release</AssemblerListingLocation>
|
|
||||||
<ObjectFileName>$(IntDir)</ObjectFileName>
|
|
||||||
<ProgramDataBaseFileName>../../Release/flatc.pdb</ProgramDataBaseFileName>
|
|
||||||
<TreatWarningAsError>true</TreatWarningAsError>
|
|
||||||
</ClCompile>
|
|
||||||
<ResourceCompile>
|
|
||||||
<PreprocessorDefinitions>WIN32;_WINDOWS;NDEBUG;CMAKE_INTDIR=\"Release\";%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
|
||||||
<AdditionalIncludeDirectories>../../include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
|
||||||
</ResourceCompile>
|
|
||||||
<Midl>
|
|
||||||
<AdditionalIncludeDirectories>../../include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
|
||||||
<OutputDirectory>$(IntDir)</OutputDirectory>
|
|
||||||
<HeaderFileName>%(Filename).h</HeaderFileName>
|
|
||||||
<TypeLibraryName>%(Filename).tlb</TypeLibraryName>
|
|
||||||
<InterfaceIdentifierFileName>%(Filename)_i.c</InterfaceIdentifierFileName>
|
|
||||||
<ProxyFileName>%(Filename)_p.c</ProxyFileName>
|
|
||||||
</Midl>
|
|
||||||
<Link>
|
|
||||||
<AdditionalOptions> /machine:X86 %(AdditionalOptions)</AdditionalOptions>
|
|
||||||
<AdditionalDependencies>kernel32.lib;user32.lib;gdi32.lib;winspool.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;comdlg32.lib;advapi32.lib</AdditionalDependencies>
|
|
||||||
<AdditionalLibraryDirectories>%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
|
|
||||||
<GenerateDebugInformation>false</GenerateDebugInformation>
|
|
||||||
<ImportLibrary>../../Release/flatc.lib</ImportLibrary>
|
|
||||||
<ProgramDataBaseFile>../../Release/flatc.pdb</ProgramDataBaseFile>
|
|
||||||
<SubSystem>Console</SubSystem>
|
|
||||||
<Version>
|
|
||||||
</Version>
|
|
||||||
</Link>
|
|
||||||
<ProjectReference>
|
|
||||||
<LinkLibraryDependencies>false</LinkLibraryDependencies>
|
|
||||||
</ProjectReference>
|
|
||||||
</ItemDefinitionGroup>
|
|
||||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
|
||||||
<ClCompile>
|
|
||||||
<AdditionalIncludeDirectories>../../include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
|
||||||
<CompileAs>CompileAsCpp</CompileAs>
|
|
||||||
<ExceptionHandling>Sync</ExceptionHandling>
|
|
||||||
<InlineFunctionExpansion>AnySuitable</InlineFunctionExpansion>
|
|
||||||
<Optimization>MaxSpeed</Optimization>
|
|
||||||
<PrecompiledHeader>NotUsing</PrecompiledHeader>
|
|
||||||
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
|
|
||||||
<RuntimeTypeInfo>true</RuntimeTypeInfo>
|
|
||||||
<WarningLevel>Level4</WarningLevel>
|
|
||||||
<DebugInformationFormat>
|
|
||||||
</DebugInformationFormat>
|
|
||||||
<PreprocessorDefinitions>WIN32;_WINDOWS;NDEBUG;CMAKE_INTDIR="Release";%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
|
||||||
<AssemblerListingLocation>Release</AssemblerListingLocation>
|
|
||||||
<ObjectFileName>$(IntDir)</ObjectFileName>
|
|
||||||
<ProgramDataBaseFileName>../../Release/flatc.pdb</ProgramDataBaseFileName>
|
|
||||||
<TreatWarningAsError>true</TreatWarningAsError>
|
|
||||||
</ClCompile>
|
|
||||||
<ResourceCompile>
|
|
||||||
<PreprocessorDefinitions>WIN32;_WINDOWS;NDEBUG;CMAKE_INTDIR=\"Release\";%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
|
||||||
<AdditionalIncludeDirectories>../../include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
|
||||||
</ResourceCompile>
|
|
||||||
<Midl>
|
|
||||||
<AdditionalIncludeDirectories>../../include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
|
||||||
<OutputDirectory>$(IntDir)</OutputDirectory>
|
|
||||||
<HeaderFileName>%(Filename).h</HeaderFileName>
|
|
||||||
<TypeLibraryName>%(Filename).tlb</TypeLibraryName>
|
|
||||||
<InterfaceIdentifierFileName>%(Filename)_i.c</InterfaceIdentifierFileName>
|
|
||||||
<ProxyFileName>%(Filename)_p.c</ProxyFileName>
|
|
||||||
</Midl>
|
|
||||||
<Link>
|
|
||||||
<AdditionalDependencies>kernel32.lib;user32.lib;gdi32.lib;winspool.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;comdlg32.lib;advapi32.lib</AdditionalDependencies>
|
|
||||||
<AdditionalLibraryDirectories>%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
|
|
||||||
<GenerateDebugInformation>false</GenerateDebugInformation>
|
|
||||||
<ImportLibrary>../../Release/flatc.lib</ImportLibrary>
|
|
||||||
<ProgramDataBaseFile>../../Release/flatc.pdb</ProgramDataBaseFile>
|
|
||||||
<SubSystem>Console</SubSystem>
|
|
||||||
<Version>
|
|
||||||
</Version>
|
|
||||||
</Link>
|
|
||||||
<ProjectReference>
|
|
||||||
<LinkLibraryDependencies>false</LinkLibraryDependencies>
|
|
||||||
</ProjectReference>
|
|
||||||
</ItemDefinitionGroup>
|
|
||||||
<ItemGroup>
|
|
||||||
<ClInclude Include="..\..\include\flatbuffers\flatbuffers.h" />
|
|
||||||
<ClInclude Include="..\..\include\flatbuffers\idl.h" />
|
|
||||||
<ClInclude Include="..\..\include\flatbuffers\util.h" />
|
|
||||||
<ClCompile Include="..\..\src\idl_gen_fbs.cpp" />
|
|
||||||
<ClCompile Include="..\..\src\idl_gen_general.cpp" />
|
|
||||||
<ClCompile Include="..\..\src\idl_gen_go.cpp">
|
|
||||||
<WarningLevel Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Level4</WarningLevel>
|
|
||||||
</ClCompile>
|
|
||||||
<ClCompile Include="..\..\src\idl_gen_js.cpp" />
|
|
||||||
<ClCompile Include="..\..\src\idl_gen_php.cpp" />
|
|
||||||
<ClCompile Include="..\..\src\idl_gen_python.cpp" />
|
|
||||||
<ClCompile Include="..\..\src\idl_parser.cpp" />
|
|
||||||
<ClCompile Include="..\..\src\idl_gen_cpp.cpp" />
|
|
||||||
<ClCompile Include="..\..\src\idl_gen_text.cpp" />
|
|
||||||
<ClCompile Include="..\..\src\flatc.cpp" />
|
|
||||||
</ItemGroup>
|
|
||||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
|
||||||
<ImportGroup Label="ExtensionTargets">
|
|
||||||
</ImportGroup>
|
|
||||||
</Project>
|
|
||||||
@@ -1,27 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
|
||||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
|
||||||
<LocalDebuggerWorkingDirectory>..\..\tests</LocalDebuggerWorkingDirectory>
|
|
||||||
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
|
|
||||||
<LocalDebuggerCommandArguments>-j -c -n -g --php --no-includes --gen-mutable monster_test.fbs</LocalDebuggerCommandArguments>
|
|
||||||
</PropertyGroup>
|
|
||||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
|
||||||
<LocalDebuggerWorkingDirectory>..\..</LocalDebuggerWorkingDirectory>
|
|
||||||
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
|
|
||||||
<LocalDebuggerCommandArguments>-j -c -n -g -b -t monster_test.fbs monsterdata_test.golden</LocalDebuggerCommandArguments>
|
|
||||||
</PropertyGroup>
|
|
||||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
|
||||||
<LocalDebuggerCommandArguments>-j -c -g -n -b -t monster_test.fbs monsterdata_test.golden</LocalDebuggerCommandArguments>
|
|
||||||
</PropertyGroup>
|
|
||||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
|
||||||
<LocalDebuggerWorkingDirectory>..\..\tests</LocalDebuggerWorkingDirectory>
|
|
||||||
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
|
|
||||||
</PropertyGroup>
|
|
||||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
|
||||||
<LocalDebuggerCommandArguments>-j -c -g -b -t monster_test.fbs monsterdata_test.json</LocalDebuggerCommandArguments>
|
|
||||||
</PropertyGroup>
|
|
||||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
|
||||||
<LocalDebuggerWorkingDirectory>..\..\tests</LocalDebuggerWorkingDirectory>
|
|
||||||
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
|
|
||||||
</PropertyGroup>
|
|
||||||
</Project>
|
|
||||||
@@ -1,273 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
|
||||||
<ItemGroup Label="ProjectConfigurations">
|
|
||||||
<ProjectConfiguration Include="Debug|Win32">
|
|
||||||
<Configuration>Debug</Configuration>
|
|
||||||
<Platform>Win32</Platform>
|
|
||||||
</ProjectConfiguration>
|
|
||||||
<ProjectConfiguration Include="Debug|x64">
|
|
||||||
<Configuration>Debug</Configuration>
|
|
||||||
<Platform>x64</Platform>
|
|
||||||
</ProjectConfiguration>
|
|
||||||
<ProjectConfiguration Include="Release|Win32">
|
|
||||||
<Configuration>Release</Configuration>
|
|
||||||
<Platform>Win32</Platform>
|
|
||||||
</ProjectConfiguration>
|
|
||||||
<ProjectConfiguration Include="Release|x64">
|
|
||||||
<Configuration>Release</Configuration>
|
|
||||||
<Platform>x64</Platform>
|
|
||||||
</ProjectConfiguration>
|
|
||||||
</ItemGroup>
|
|
||||||
<PropertyGroup Label="Globals">
|
|
||||||
<ProjectGUID>{16FA5518-3DE1-4B15-A1E0-F4734C276FB4}</ProjectGUID>
|
|
||||||
<Keyword>Win32Proj</Keyword>
|
|
||||||
<Platform>Win32</Platform>
|
|
||||||
<ProjectName>flatsamplebinary</ProjectName>
|
|
||||||
</PropertyGroup>
|
|
||||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
|
||||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
|
|
||||||
<ConfigurationType>Application</ConfigurationType>
|
|
||||||
<UseOfMfc>false</UseOfMfc>
|
|
||||||
<CharacterSet>MultiByte</CharacterSet>
|
|
||||||
</PropertyGroup>
|
|
||||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
|
|
||||||
<ConfigurationType>Application</ConfigurationType>
|
|
||||||
<UseOfMfc>false</UseOfMfc>
|
|
||||||
<CharacterSet>MultiByte</CharacterSet>
|
|
||||||
</PropertyGroup>
|
|
||||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
|
||||||
<ConfigurationType>Application</ConfigurationType>
|
|
||||||
<UseOfMfc>false</UseOfMfc>
|
|
||||||
<CharacterSet>MultiByte</CharacterSet>
|
|
||||||
</PropertyGroup>
|
|
||||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
|
|
||||||
<ConfigurationType>Application</ConfigurationType>
|
|
||||||
<UseOfMfc>false</UseOfMfc>
|
|
||||||
<CharacterSet>MultiByte</CharacterSet>
|
|
||||||
</PropertyGroup>
|
|
||||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
|
||||||
<ImportGroup Label="ExtensionSettings">
|
|
||||||
</ImportGroup>
|
|
||||||
<ImportGroup Label="PropertySheets">
|
|
||||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
|
||||||
</ImportGroup>
|
|
||||||
<PropertyGroup Label="UserMacros" />
|
|
||||||
<PropertyGroup>
|
|
||||||
<_ProjectFileVersion>10.0.20506.1</_ProjectFileVersion>
|
|
||||||
<OutDir Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">$(IntDir)</OutDir>
|
|
||||||
<OutDir Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">$(IntDir)</OutDir>
|
|
||||||
<IntDir Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">flatsamplebinary.dir\Debug\</IntDir>
|
|
||||||
<IntDir Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">flatsamplebinary.dir\Debug\</IntDir>
|
|
||||||
<TargetName Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">flatsamplebinary</TargetName>
|
|
||||||
<TargetName Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">flatsamplebinary</TargetName>
|
|
||||||
<TargetExt Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">.exe</TargetExt>
|
|
||||||
<TargetExt Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">.exe</TargetExt>
|
|
||||||
<LinkIncremental Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</LinkIncremental>
|
|
||||||
<LinkIncremental Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</LinkIncremental>
|
|
||||||
<GenerateManifest Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</GenerateManifest>
|
|
||||||
<GenerateManifest Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</GenerateManifest>
|
|
||||||
<OutDir Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">$(IntDir)</OutDir>
|
|
||||||
<OutDir Condition="'$(Configuration)|$(Platform)'=='Release|x64'">$(IntDir)</OutDir>
|
|
||||||
<IntDir Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">flatsamplebinary.dir\Release\</IntDir>
|
|
||||||
<IntDir Condition="'$(Configuration)|$(Platform)'=='Release|x64'">flatsamplebinary.dir\Release\</IntDir>
|
|
||||||
<TargetName Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">flatsamplebinary</TargetName>
|
|
||||||
<TargetName Condition="'$(Configuration)|$(Platform)'=='Release|x64'">flatsamplebinary</TargetName>
|
|
||||||
<TargetExt Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">.exe</TargetExt>
|
|
||||||
<TargetExt Condition="'$(Configuration)|$(Platform)'=='Release|x64'">.exe</TargetExt>
|
|
||||||
<LinkIncremental Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">false</LinkIncremental>
|
|
||||||
<LinkIncremental Condition="'$(Configuration)|$(Platform)'=='Release|x64'">false</LinkIncremental>
|
|
||||||
<GenerateManifest Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</GenerateManifest>
|
|
||||||
<GenerateManifest Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</GenerateManifest>
|
|
||||||
</PropertyGroup>
|
|
||||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
|
||||||
<ClCompile>
|
|
||||||
<AdditionalIncludeDirectories>../../include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
|
||||||
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
|
|
||||||
<CompileAs>CompileAsCpp</CompileAs>
|
|
||||||
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
|
|
||||||
<ExceptionHandling>Sync</ExceptionHandling>
|
|
||||||
<InlineFunctionExpansion>Disabled</InlineFunctionExpansion>
|
|
||||||
<Optimization>Disabled</Optimization>
|
|
||||||
<PrecompiledHeader>NotUsing</PrecompiledHeader>
|
|
||||||
<RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
|
|
||||||
<RuntimeTypeInfo>true</RuntimeTypeInfo>
|
|
||||||
<WarningLevel>Level4</WarningLevel>
|
|
||||||
<PreprocessorDefinitions>WIN32;_WINDOWS;_DEBUG;CMAKE_INTDIR="Debug";%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
|
||||||
<AssemblerListingLocation>Debug</AssemblerListingLocation>
|
|
||||||
<ObjectFileName>$(IntDir)</ObjectFileName>
|
|
||||||
<ProgramDataBaseFileName>../../Debug/flatsamplebinary.pdb</ProgramDataBaseFileName>
|
|
||||||
<TreatWarningAsError>true</TreatWarningAsError>
|
|
||||||
</ClCompile>
|
|
||||||
<ResourceCompile>
|
|
||||||
<PreprocessorDefinitions>WIN32;_WINDOWS;_DEBUG;CMAKE_INTDIR=\"Debug\";%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
|
||||||
<AdditionalIncludeDirectories>../../include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
|
||||||
</ResourceCompile>
|
|
||||||
<Midl>
|
|
||||||
<AdditionalIncludeDirectories>../../include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
|
||||||
<OutputDirectory>$(IntDir)</OutputDirectory>
|
|
||||||
<HeaderFileName>%(Filename).h</HeaderFileName>
|
|
||||||
<TypeLibraryName>%(Filename).tlb</TypeLibraryName>
|
|
||||||
<InterfaceIdentifierFileName>%(Filename)_i.c</InterfaceIdentifierFileName>
|
|
||||||
<ProxyFileName>%(Filename)_p.c</ProxyFileName>
|
|
||||||
</Midl>
|
|
||||||
<Link>
|
|
||||||
<AdditionalOptions> /machine:X86 /debug %(AdditionalOptions)</AdditionalOptions>
|
|
||||||
<AdditionalDependencies>kernel32.lib;user32.lib;gdi32.lib;winspool.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;comdlg32.lib;advapi32.lib</AdditionalDependencies>
|
|
||||||
<AdditionalLibraryDirectories>%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
|
|
||||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
|
||||||
<ImportLibrary>../../Debug/flatsamplebinary.lib</ImportLibrary>
|
|
||||||
<ProgramDataBaseFile>../../Debug/flatsamplebinary.pdb</ProgramDataBaseFile>
|
|
||||||
<SubSystem>Console</SubSystem>
|
|
||||||
<Version>
|
|
||||||
</Version>
|
|
||||||
</Link>
|
|
||||||
<ProjectReference>
|
|
||||||
<LinkLibraryDependencies>false</LinkLibraryDependencies>
|
|
||||||
</ProjectReference>
|
|
||||||
</ItemDefinitionGroup>
|
|
||||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
|
||||||
<ClCompile>
|
|
||||||
<AdditionalIncludeDirectories>../../include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
|
||||||
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
|
|
||||||
<CompileAs>CompileAsCpp</CompileAs>
|
|
||||||
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
|
|
||||||
<ExceptionHandling>Sync</ExceptionHandling>
|
|
||||||
<InlineFunctionExpansion>Disabled</InlineFunctionExpansion>
|
|
||||||
<Optimization>Disabled</Optimization>
|
|
||||||
<PrecompiledHeader>NotUsing</PrecompiledHeader>
|
|
||||||
<RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
|
|
||||||
<RuntimeTypeInfo>true</RuntimeTypeInfo>
|
|
||||||
<WarningLevel>Level4</WarningLevel>
|
|
||||||
<PreprocessorDefinitions>WIN32;_WINDOWS;_DEBUG;CMAKE_INTDIR="Debug";%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
|
||||||
<AssemblerListingLocation>Debug</AssemblerListingLocation>
|
|
||||||
<ObjectFileName>$(IntDir)</ObjectFileName>
|
|
||||||
<ProgramDataBaseFileName>../../Debug/flatsamplebinary.pdb</ProgramDataBaseFileName>
|
|
||||||
<TreatWarningAsError>true</TreatWarningAsError>
|
|
||||||
</ClCompile>
|
|
||||||
<ResourceCompile>
|
|
||||||
<PreprocessorDefinitions>WIN32;_WINDOWS;_DEBUG;CMAKE_INTDIR=\"Debug\";%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
|
||||||
<AdditionalIncludeDirectories>../../include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
|
||||||
</ResourceCompile>
|
|
||||||
<Midl>
|
|
||||||
<AdditionalIncludeDirectories>../../include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
|
||||||
<OutputDirectory>$(IntDir)</OutputDirectory>
|
|
||||||
<HeaderFileName>%(Filename).h</HeaderFileName>
|
|
||||||
<TypeLibraryName>%(Filename).tlb</TypeLibraryName>
|
|
||||||
<InterfaceIdentifierFileName>%(Filename)_i.c</InterfaceIdentifierFileName>
|
|
||||||
<ProxyFileName>%(Filename)_p.c</ProxyFileName>
|
|
||||||
</Midl>
|
|
||||||
<Link>
|
|
||||||
<AdditionalOptions>/debug %(AdditionalOptions)</AdditionalOptions>
|
|
||||||
<AdditionalDependencies>kernel32.lib;user32.lib;gdi32.lib;winspool.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;comdlg32.lib;advapi32.lib</AdditionalDependencies>
|
|
||||||
<AdditionalLibraryDirectories>%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
|
|
||||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
|
||||||
<ImportLibrary>../../Debug/flatsamplebinary.lib</ImportLibrary>
|
|
||||||
<ProgramDataBaseFile>../../Debug/flatsamplebinary.pdb</ProgramDataBaseFile>
|
|
||||||
<SubSystem>Console</SubSystem>
|
|
||||||
<Version>
|
|
||||||
</Version>
|
|
||||||
</Link>
|
|
||||||
<ProjectReference>
|
|
||||||
<LinkLibraryDependencies>false</LinkLibraryDependencies>
|
|
||||||
</ProjectReference>
|
|
||||||
</ItemDefinitionGroup>
|
|
||||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
|
||||||
<ClCompile>
|
|
||||||
<AdditionalIncludeDirectories>../../include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
|
||||||
<CompileAs>CompileAsCpp</CompileAs>
|
|
||||||
<ExceptionHandling>Sync</ExceptionHandling>
|
|
||||||
<InlineFunctionExpansion>AnySuitable</InlineFunctionExpansion>
|
|
||||||
<Optimization>MaxSpeed</Optimization>
|
|
||||||
<PrecompiledHeader>NotUsing</PrecompiledHeader>
|
|
||||||
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
|
|
||||||
<RuntimeTypeInfo>true</RuntimeTypeInfo>
|
|
||||||
<WarningLevel>Level4</WarningLevel>
|
|
||||||
<DebugInformationFormat>
|
|
||||||
</DebugInformationFormat>
|
|
||||||
<PreprocessorDefinitions>WIN32;_WINDOWS;NDEBUG;CMAKE_INTDIR="Release";%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
|
||||||
<AssemblerListingLocation>Release</AssemblerListingLocation>
|
|
||||||
<ObjectFileName>$(IntDir)</ObjectFileName>
|
|
||||||
<ProgramDataBaseFileName>../../Release/flatsamplebinary.pdb</ProgramDataBaseFileName>
|
|
||||||
<TreatWarningAsError>true</TreatWarningAsError>
|
|
||||||
</ClCompile>
|
|
||||||
<ResourceCompile>
|
|
||||||
<PreprocessorDefinitions>WIN32;_WINDOWS;NDEBUG;CMAKE_INTDIR=\"Release\";%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
|
||||||
<AdditionalIncludeDirectories>../../include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
|
||||||
</ResourceCompile>
|
|
||||||
<Midl>
|
|
||||||
<AdditionalIncludeDirectories>../../include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
|
||||||
<OutputDirectory>$(IntDir)</OutputDirectory>
|
|
||||||
<HeaderFileName>%(Filename).h</HeaderFileName>
|
|
||||||
<TypeLibraryName>%(Filename).tlb</TypeLibraryName>
|
|
||||||
<InterfaceIdentifierFileName>%(Filename)_i.c</InterfaceIdentifierFileName>
|
|
||||||
<ProxyFileName>%(Filename)_p.c</ProxyFileName>
|
|
||||||
</Midl>
|
|
||||||
<Link>
|
|
||||||
<AdditionalOptions> /machine:X86 %(AdditionalOptions)</AdditionalOptions>
|
|
||||||
<AdditionalDependencies>kernel32.lib;user32.lib;gdi32.lib;winspool.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;comdlg32.lib;advapi32.lib</AdditionalDependencies>
|
|
||||||
<AdditionalLibraryDirectories>%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
|
|
||||||
<GenerateDebugInformation>false</GenerateDebugInformation>
|
|
||||||
<ImportLibrary>../../Release/flatsamplebinary.lib</ImportLibrary>
|
|
||||||
<ProgramDataBaseFile>../../Release/flatsamplebinary.pdb</ProgramDataBaseFile>
|
|
||||||
<SubSystem>Console</SubSystem>
|
|
||||||
<Version>
|
|
||||||
</Version>
|
|
||||||
</Link>
|
|
||||||
<ProjectReference>
|
|
||||||
<LinkLibraryDependencies>false</LinkLibraryDependencies>
|
|
||||||
</ProjectReference>
|
|
||||||
</ItemDefinitionGroup>
|
|
||||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
|
||||||
<ClCompile>
|
|
||||||
<AdditionalIncludeDirectories>../../include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
|
||||||
<CompileAs>CompileAsCpp</CompileAs>
|
|
||||||
<ExceptionHandling>Sync</ExceptionHandling>
|
|
||||||
<InlineFunctionExpansion>AnySuitable</InlineFunctionExpansion>
|
|
||||||
<Optimization>MaxSpeed</Optimization>
|
|
||||||
<PrecompiledHeader>NotUsing</PrecompiledHeader>
|
|
||||||
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
|
|
||||||
<RuntimeTypeInfo>true</RuntimeTypeInfo>
|
|
||||||
<WarningLevel>Level4</WarningLevel>
|
|
||||||
<DebugInformationFormat>
|
|
||||||
</DebugInformationFormat>
|
|
||||||
<PreprocessorDefinitions>WIN32;_WINDOWS;NDEBUG;CMAKE_INTDIR="Release";%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
|
||||||
<AssemblerListingLocation>Release</AssemblerListingLocation>
|
|
||||||
<ObjectFileName>$(IntDir)</ObjectFileName>
|
|
||||||
<ProgramDataBaseFileName>../../Release/flatsamplebinary.pdb</ProgramDataBaseFileName>
|
|
||||||
<TreatWarningAsError>true</TreatWarningAsError>
|
|
||||||
</ClCompile>
|
|
||||||
<ResourceCompile>
|
|
||||||
<PreprocessorDefinitions>WIN32;_WINDOWS;NDEBUG;CMAKE_INTDIR=\"Release\";%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
|
||||||
<AdditionalIncludeDirectories>../../include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
|
||||||
</ResourceCompile>
|
|
||||||
<Midl>
|
|
||||||
<AdditionalIncludeDirectories>../../include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
|
||||||
<OutputDirectory>$(IntDir)</OutputDirectory>
|
|
||||||
<HeaderFileName>%(Filename).h</HeaderFileName>
|
|
||||||
<TypeLibraryName>%(Filename).tlb</TypeLibraryName>
|
|
||||||
<InterfaceIdentifierFileName>%(Filename)_i.c</InterfaceIdentifierFileName>
|
|
||||||
<ProxyFileName>%(Filename)_p.c</ProxyFileName>
|
|
||||||
</Midl>
|
|
||||||
<Link>
|
|
||||||
<AdditionalDependencies>kernel32.lib;user32.lib;gdi32.lib;winspool.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;comdlg32.lib;advapi32.lib</AdditionalDependencies>
|
|
||||||
<AdditionalLibraryDirectories>%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
|
|
||||||
<GenerateDebugInformation>false</GenerateDebugInformation>
|
|
||||||
<ImportLibrary>../../Release/flatsamplebinary.lib</ImportLibrary>
|
|
||||||
<ProgramDataBaseFile>../../Release/flatsamplebinary.pdb</ProgramDataBaseFile>
|
|
||||||
<SubSystem>Console</SubSystem>
|
|
||||||
<Version>
|
|
||||||
</Version>
|
|
||||||
</Link>
|
|
||||||
<ProjectReference>
|
|
||||||
<LinkLibraryDependencies>false</LinkLibraryDependencies>
|
|
||||||
</ProjectReference>
|
|
||||||
</ItemDefinitionGroup>
|
|
||||||
<ItemGroup>
|
|
||||||
<ClInclude Include="..\..\include\flatbuffers\flatbuffers.h" />
|
|
||||||
<ClInclude Include="..\..\samples\monster_generated.h" />
|
|
||||||
<ClCompile Include="..\..\samples\sample_binary.cpp" />
|
|
||||||
</ItemGroup>
|
|
||||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
|
||||||
<ImportGroup Label="ExtensionTargets">
|
|
||||||
</ImportGroup>
|
|
||||||
</Project>
|
|
||||||
@@ -1,11 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
|
||||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
|
||||||
<LocalDebuggerWorkingDirectory>..\..</LocalDebuggerWorkingDirectory>
|
|
||||||
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
|
|
||||||
</PropertyGroup>
|
|
||||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
|
||||||
<LocalDebuggerWorkingDirectory>..\..</LocalDebuggerWorkingDirectory>
|
|
||||||
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
|
|
||||||
</PropertyGroup>
|
|
||||||
</Project>
|
|
||||||
@@ -1,277 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
|
||||||
<ItemGroup Label="ProjectConfigurations">
|
|
||||||
<ProjectConfiguration Include="Debug|Win32">
|
|
||||||
<Configuration>Debug</Configuration>
|
|
||||||
<Platform>Win32</Platform>
|
|
||||||
</ProjectConfiguration>
|
|
||||||
<ProjectConfiguration Include="Debug|x64">
|
|
||||||
<Configuration>Debug</Configuration>
|
|
||||||
<Platform>x64</Platform>
|
|
||||||
</ProjectConfiguration>
|
|
||||||
<ProjectConfiguration Include="Release|Win32">
|
|
||||||
<Configuration>Release</Configuration>
|
|
||||||
<Platform>Win32</Platform>
|
|
||||||
</ProjectConfiguration>
|
|
||||||
<ProjectConfiguration Include="Release|x64">
|
|
||||||
<Configuration>Release</Configuration>
|
|
||||||
<Platform>x64</Platform>
|
|
||||||
</ProjectConfiguration>
|
|
||||||
</ItemGroup>
|
|
||||||
<PropertyGroup Label="Globals">
|
|
||||||
<ProjectGUID>{F0A15675-1017-4217-BB5B-3372F2C636AB}</ProjectGUID>
|
|
||||||
<Keyword>Win32Proj</Keyword>
|
|
||||||
<Platform>Win32</Platform>
|
|
||||||
<ProjectName>flatsampletext</ProjectName>
|
|
||||||
</PropertyGroup>
|
|
||||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
|
||||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
|
|
||||||
<ConfigurationType>Application</ConfigurationType>
|
|
||||||
<UseOfMfc>false</UseOfMfc>
|
|
||||||
<CharacterSet>MultiByte</CharacterSet>
|
|
||||||
</PropertyGroup>
|
|
||||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
|
|
||||||
<ConfigurationType>Application</ConfigurationType>
|
|
||||||
<UseOfMfc>false</UseOfMfc>
|
|
||||||
<CharacterSet>MultiByte</CharacterSet>
|
|
||||||
</PropertyGroup>
|
|
||||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
|
||||||
<ConfigurationType>Application</ConfigurationType>
|
|
||||||
<UseOfMfc>false</UseOfMfc>
|
|
||||||
<CharacterSet>MultiByte</CharacterSet>
|
|
||||||
</PropertyGroup>
|
|
||||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
|
|
||||||
<ConfigurationType>Application</ConfigurationType>
|
|
||||||
<UseOfMfc>false</UseOfMfc>
|
|
||||||
<CharacterSet>MultiByte</CharacterSet>
|
|
||||||
</PropertyGroup>
|
|
||||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
|
||||||
<ImportGroup Label="ExtensionSettings">
|
|
||||||
</ImportGroup>
|
|
||||||
<ImportGroup Label="PropertySheets">
|
|
||||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
|
||||||
</ImportGroup>
|
|
||||||
<PropertyGroup Label="UserMacros" />
|
|
||||||
<PropertyGroup>
|
|
||||||
<_ProjectFileVersion>10.0.20506.1</_ProjectFileVersion>
|
|
||||||
<OutDir Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">$(IntDir)</OutDir>
|
|
||||||
<OutDir Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">$(IntDir)</OutDir>
|
|
||||||
<IntDir Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">flatsampletext.dir\Debug\</IntDir>
|
|
||||||
<IntDir Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">flatsampletext.dir\Debug\</IntDir>
|
|
||||||
<TargetName Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">flatsampletext</TargetName>
|
|
||||||
<TargetName Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">flatsampletext</TargetName>
|
|
||||||
<TargetExt Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">.exe</TargetExt>
|
|
||||||
<TargetExt Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">.exe</TargetExt>
|
|
||||||
<LinkIncremental Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</LinkIncremental>
|
|
||||||
<LinkIncremental Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</LinkIncremental>
|
|
||||||
<GenerateManifest Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</GenerateManifest>
|
|
||||||
<GenerateManifest Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</GenerateManifest>
|
|
||||||
<OutDir Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">$(IntDir)</OutDir>
|
|
||||||
<OutDir Condition="'$(Configuration)|$(Platform)'=='Release|x64'">$(IntDir)</OutDir>
|
|
||||||
<IntDir Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">flatsampletext.dir\Release\</IntDir>
|
|
||||||
<IntDir Condition="'$(Configuration)|$(Platform)'=='Release|x64'">flatsampletext.dir\Release\</IntDir>
|
|
||||||
<TargetName Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">flatsampletext</TargetName>
|
|
||||||
<TargetName Condition="'$(Configuration)|$(Platform)'=='Release|x64'">flatsampletext</TargetName>
|
|
||||||
<TargetExt Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">.exe</TargetExt>
|
|
||||||
<TargetExt Condition="'$(Configuration)|$(Platform)'=='Release|x64'">.exe</TargetExt>
|
|
||||||
<LinkIncremental Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">false</LinkIncremental>
|
|
||||||
<LinkIncremental Condition="'$(Configuration)|$(Platform)'=='Release|x64'">false</LinkIncremental>
|
|
||||||
<GenerateManifest Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</GenerateManifest>
|
|
||||||
<GenerateManifest Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</GenerateManifest>
|
|
||||||
</PropertyGroup>
|
|
||||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
|
||||||
<ClCompile>
|
|
||||||
<AdditionalIncludeDirectories>../../include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
|
||||||
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
|
|
||||||
<CompileAs>CompileAsCpp</CompileAs>
|
|
||||||
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
|
|
||||||
<ExceptionHandling>Sync</ExceptionHandling>
|
|
||||||
<InlineFunctionExpansion>Disabled</InlineFunctionExpansion>
|
|
||||||
<Optimization>Disabled</Optimization>
|
|
||||||
<PrecompiledHeader>NotUsing</PrecompiledHeader>
|
|
||||||
<RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
|
|
||||||
<RuntimeTypeInfo>true</RuntimeTypeInfo>
|
|
||||||
<WarningLevel>Level4</WarningLevel>
|
|
||||||
<PreprocessorDefinitions>WIN32;_WINDOWS;_DEBUG;CMAKE_INTDIR="Debug";%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
|
||||||
<AssemblerListingLocation>Debug</AssemblerListingLocation>
|
|
||||||
<ObjectFileName>$(IntDir)</ObjectFileName>
|
|
||||||
<ProgramDataBaseFileName>../../Debug/flatsampletext.pdb</ProgramDataBaseFileName>
|
|
||||||
<TreatWarningAsError>true</TreatWarningAsError>
|
|
||||||
</ClCompile>
|
|
||||||
<ResourceCompile>
|
|
||||||
<PreprocessorDefinitions>WIN32;_WINDOWS;_DEBUG;CMAKE_INTDIR=\"Debug\";%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
|
||||||
<AdditionalIncludeDirectories>../../include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
|
||||||
</ResourceCompile>
|
|
||||||
<Midl>
|
|
||||||
<AdditionalIncludeDirectories>../../include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
|
||||||
<OutputDirectory>$(IntDir)</OutputDirectory>
|
|
||||||
<HeaderFileName>%(Filename).h</HeaderFileName>
|
|
||||||
<TypeLibraryName>%(Filename).tlb</TypeLibraryName>
|
|
||||||
<InterfaceIdentifierFileName>%(Filename)_i.c</InterfaceIdentifierFileName>
|
|
||||||
<ProxyFileName>%(Filename)_p.c</ProxyFileName>
|
|
||||||
</Midl>
|
|
||||||
<Link>
|
|
||||||
<AdditionalOptions> /machine:X86 /debug %(AdditionalOptions)</AdditionalOptions>
|
|
||||||
<AdditionalDependencies>kernel32.lib;user32.lib;gdi32.lib;winspool.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;comdlg32.lib;advapi32.lib</AdditionalDependencies>
|
|
||||||
<AdditionalLibraryDirectories>%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
|
|
||||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
|
||||||
<ImportLibrary>../../Debug/flatsampletext.lib</ImportLibrary>
|
|
||||||
<ProgramDataBaseFile>../../Debug/flatsampletext.pdb</ProgramDataBaseFile>
|
|
||||||
<SubSystem>Console</SubSystem>
|
|
||||||
<Version>
|
|
||||||
</Version>
|
|
||||||
</Link>
|
|
||||||
<ProjectReference>
|
|
||||||
<LinkLibraryDependencies>false</LinkLibraryDependencies>
|
|
||||||
</ProjectReference>
|
|
||||||
</ItemDefinitionGroup>
|
|
||||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
|
||||||
<ClCompile>
|
|
||||||
<AdditionalIncludeDirectories>../../include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
|
||||||
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
|
|
||||||
<CompileAs>CompileAsCpp</CompileAs>
|
|
||||||
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
|
|
||||||
<ExceptionHandling>Sync</ExceptionHandling>
|
|
||||||
<InlineFunctionExpansion>Disabled</InlineFunctionExpansion>
|
|
||||||
<Optimization>Disabled</Optimization>
|
|
||||||
<PrecompiledHeader>NotUsing</PrecompiledHeader>
|
|
||||||
<RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
|
|
||||||
<RuntimeTypeInfo>true</RuntimeTypeInfo>
|
|
||||||
<WarningLevel>Level4</WarningLevel>
|
|
||||||
<PreprocessorDefinitions>WIN32;_WINDOWS;_DEBUG;CMAKE_INTDIR="Debug";%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
|
||||||
<AssemblerListingLocation>Debug</AssemblerListingLocation>
|
|
||||||
<ObjectFileName>$(IntDir)</ObjectFileName>
|
|
||||||
<ProgramDataBaseFileName>../../Debug/flatsampletext.pdb</ProgramDataBaseFileName>
|
|
||||||
<TreatWarningAsError>true</TreatWarningAsError>
|
|
||||||
</ClCompile>
|
|
||||||
<ResourceCompile>
|
|
||||||
<PreprocessorDefinitions>WIN32;_WINDOWS;_DEBUG;CMAKE_INTDIR=\"Debug\";%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
|
||||||
<AdditionalIncludeDirectories>../../include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
|
||||||
</ResourceCompile>
|
|
||||||
<Midl>
|
|
||||||
<AdditionalIncludeDirectories>../../include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
|
||||||
<OutputDirectory>$(IntDir)</OutputDirectory>
|
|
||||||
<HeaderFileName>%(Filename).h</HeaderFileName>
|
|
||||||
<TypeLibraryName>%(Filename).tlb</TypeLibraryName>
|
|
||||||
<InterfaceIdentifierFileName>%(Filename)_i.c</InterfaceIdentifierFileName>
|
|
||||||
<ProxyFileName>%(Filename)_p.c</ProxyFileName>
|
|
||||||
</Midl>
|
|
||||||
<Link>
|
|
||||||
<AdditionalOptions>/debug %(AdditionalOptions)</AdditionalOptions>
|
|
||||||
<AdditionalDependencies>kernel32.lib;user32.lib;gdi32.lib;winspool.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;comdlg32.lib;advapi32.lib</AdditionalDependencies>
|
|
||||||
<AdditionalLibraryDirectories>%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
|
|
||||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
|
||||||
<ImportLibrary>../../Debug/flatsampletext.lib</ImportLibrary>
|
|
||||||
<ProgramDataBaseFile>../../Debug/flatsampletext.pdb</ProgramDataBaseFile>
|
|
||||||
<SubSystem>Console</SubSystem>
|
|
||||||
<Version>
|
|
||||||
</Version>
|
|
||||||
</Link>
|
|
||||||
<ProjectReference>
|
|
||||||
<LinkLibraryDependencies>false</LinkLibraryDependencies>
|
|
||||||
</ProjectReference>
|
|
||||||
</ItemDefinitionGroup>
|
|
||||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
|
||||||
<ClCompile>
|
|
||||||
<AdditionalIncludeDirectories>../../include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
|
||||||
<CompileAs>CompileAsCpp</CompileAs>
|
|
||||||
<ExceptionHandling>Sync</ExceptionHandling>
|
|
||||||
<InlineFunctionExpansion>AnySuitable</InlineFunctionExpansion>
|
|
||||||
<Optimization>MaxSpeed</Optimization>
|
|
||||||
<PrecompiledHeader>NotUsing</PrecompiledHeader>
|
|
||||||
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
|
|
||||||
<RuntimeTypeInfo>true</RuntimeTypeInfo>
|
|
||||||
<WarningLevel>Level4</WarningLevel>
|
|
||||||
<DebugInformationFormat>
|
|
||||||
</DebugInformationFormat>
|
|
||||||
<PreprocessorDefinitions>WIN32;_WINDOWS;NDEBUG;CMAKE_INTDIR="Release";%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
|
||||||
<AssemblerListingLocation>Release</AssemblerListingLocation>
|
|
||||||
<ObjectFileName>$(IntDir)</ObjectFileName>
|
|
||||||
<ProgramDataBaseFileName>../../Release/flatsampletext.pdb</ProgramDataBaseFileName>
|
|
||||||
<TreatWarningAsError>true</TreatWarningAsError>
|
|
||||||
</ClCompile>
|
|
||||||
<ResourceCompile>
|
|
||||||
<PreprocessorDefinitions>WIN32;_WINDOWS;NDEBUG;CMAKE_INTDIR=\"Release\";%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
|
||||||
<AdditionalIncludeDirectories>../../include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
|
||||||
</ResourceCompile>
|
|
||||||
<Midl>
|
|
||||||
<AdditionalIncludeDirectories>../../include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
|
||||||
<OutputDirectory>$(IntDir)</OutputDirectory>
|
|
||||||
<HeaderFileName>%(Filename).h</HeaderFileName>
|
|
||||||
<TypeLibraryName>%(Filename).tlb</TypeLibraryName>
|
|
||||||
<InterfaceIdentifierFileName>%(Filename)_i.c</InterfaceIdentifierFileName>
|
|
||||||
<ProxyFileName>%(Filename)_p.c</ProxyFileName>
|
|
||||||
</Midl>
|
|
||||||
<Link>
|
|
||||||
<AdditionalOptions> /machine:X86 %(AdditionalOptions)</AdditionalOptions>
|
|
||||||
<AdditionalDependencies>kernel32.lib;user32.lib;gdi32.lib;winspool.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;comdlg32.lib;advapi32.lib</AdditionalDependencies>
|
|
||||||
<AdditionalLibraryDirectories>%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
|
|
||||||
<GenerateDebugInformation>false</GenerateDebugInformation>
|
|
||||||
<ImportLibrary>../../Release/flatsampletext.lib</ImportLibrary>
|
|
||||||
<ProgramDataBaseFile>../../Release/flatsampletext.pdb</ProgramDataBaseFile>
|
|
||||||
<SubSystem>Console</SubSystem>
|
|
||||||
<Version>
|
|
||||||
</Version>
|
|
||||||
</Link>
|
|
||||||
<ProjectReference>
|
|
||||||
<LinkLibraryDependencies>false</LinkLibraryDependencies>
|
|
||||||
</ProjectReference>
|
|
||||||
</ItemDefinitionGroup>
|
|
||||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
|
||||||
<ClCompile>
|
|
||||||
<AdditionalIncludeDirectories>../../include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
|
||||||
<CompileAs>CompileAsCpp</CompileAs>
|
|
||||||
<ExceptionHandling>Sync</ExceptionHandling>
|
|
||||||
<InlineFunctionExpansion>AnySuitable</InlineFunctionExpansion>
|
|
||||||
<Optimization>MaxSpeed</Optimization>
|
|
||||||
<PrecompiledHeader>NotUsing</PrecompiledHeader>
|
|
||||||
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
|
|
||||||
<RuntimeTypeInfo>true</RuntimeTypeInfo>
|
|
||||||
<WarningLevel>Level4</WarningLevel>
|
|
||||||
<DebugInformationFormat>
|
|
||||||
</DebugInformationFormat>
|
|
||||||
<PreprocessorDefinitions>WIN32;_WINDOWS;NDEBUG;CMAKE_INTDIR="Release";%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
|
||||||
<AssemblerListingLocation>Release</AssemblerListingLocation>
|
|
||||||
<ObjectFileName>$(IntDir)</ObjectFileName>
|
|
||||||
<ProgramDataBaseFileName>../../Release/flatsampletext.pdb</ProgramDataBaseFileName>
|
|
||||||
<TreatWarningAsError>true</TreatWarningAsError>
|
|
||||||
</ClCompile>
|
|
||||||
<ResourceCompile>
|
|
||||||
<PreprocessorDefinitions>WIN32;_WINDOWS;NDEBUG;CMAKE_INTDIR=\"Release\";%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
|
||||||
<AdditionalIncludeDirectories>../../include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
|
||||||
</ResourceCompile>
|
|
||||||
<Midl>
|
|
||||||
<AdditionalIncludeDirectories>../../include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
|
||||||
<OutputDirectory>$(IntDir)</OutputDirectory>
|
|
||||||
<HeaderFileName>%(Filename).h</HeaderFileName>
|
|
||||||
<TypeLibraryName>%(Filename).tlb</TypeLibraryName>
|
|
||||||
<InterfaceIdentifierFileName>%(Filename)_i.c</InterfaceIdentifierFileName>
|
|
||||||
<ProxyFileName>%(Filename)_p.c</ProxyFileName>
|
|
||||||
</Midl>
|
|
||||||
<Link>
|
|
||||||
<AdditionalDependencies>kernel32.lib;user32.lib;gdi32.lib;winspool.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;comdlg32.lib;advapi32.lib</AdditionalDependencies>
|
|
||||||
<AdditionalLibraryDirectories>%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
|
|
||||||
<GenerateDebugInformation>false</GenerateDebugInformation>
|
|
||||||
<ImportLibrary>../../Release/flatsampletext.lib</ImportLibrary>
|
|
||||||
<ProgramDataBaseFile>../../Release/flatsampletext.pdb</ProgramDataBaseFile>
|
|
||||||
<SubSystem>Console</SubSystem>
|
|
||||||
<Version>
|
|
||||||
</Version>
|
|
||||||
</Link>
|
|
||||||
<ProjectReference>
|
|
||||||
<LinkLibraryDependencies>false</LinkLibraryDependencies>
|
|
||||||
</ProjectReference>
|
|
||||||
</ItemDefinitionGroup>
|
|
||||||
<ItemGroup>
|
|
||||||
<ClInclude Include="..\..\include\flatbuffers\flatbuffers.h" />
|
|
||||||
<ClInclude Include="..\..\include\flatbuffers\idl.h" />
|
|
||||||
<ClInclude Include="..\..\include\flatbuffers\util.h" />
|
|
||||||
<ClInclude Include="..\..\samples\monster_generated.h" />
|
|
||||||
<ClCompile Include="..\..\src\idl_parser.cpp" />
|
|
||||||
<ClCompile Include="..\..\src\idl_gen_text.cpp" />
|
|
||||||
<ClCompile Include="..\..\samples\sample_text.cpp" />
|
|
||||||
</ItemGroup>
|
|
||||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
|
||||||
<ImportGroup Label="ExtensionTargets">
|
|
||||||
</ImportGroup>
|
|
||||||
</Project>
|
|
||||||
@@ -1,19 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
|
||||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
|
||||||
<LocalDebuggerWorkingDirectory>..\..</LocalDebuggerWorkingDirectory>
|
|
||||||
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
|
|
||||||
</PropertyGroup>
|
|
||||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
|
||||||
<LocalDebuggerWorkingDirectory>..\..</LocalDebuggerWorkingDirectory>
|
|
||||||
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
|
|
||||||
</PropertyGroup>
|
|
||||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
|
||||||
<LocalDebuggerWorkingDirectory>..\..</LocalDebuggerWorkingDirectory>
|
|
||||||
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
|
|
||||||
</PropertyGroup>
|
|
||||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
|
||||||
<LocalDebuggerWorkingDirectory>..\..</LocalDebuggerWorkingDirectory>
|
|
||||||
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
|
|
||||||
</PropertyGroup>
|
|
||||||
</Project>
|
|
||||||
@@ -1,281 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
|
||||||
<ItemGroup Label="ProjectConfigurations">
|
|
||||||
<ProjectConfiguration Include="Debug|Win32">
|
|
||||||
<Configuration>Debug</Configuration>
|
|
||||||
<Platform>Win32</Platform>
|
|
||||||
</ProjectConfiguration>
|
|
||||||
<ProjectConfiguration Include="Debug|x64">
|
|
||||||
<Configuration>Debug</Configuration>
|
|
||||||
<Platform>x64</Platform>
|
|
||||||
</ProjectConfiguration>
|
|
||||||
<ProjectConfiguration Include="Release|Win32">
|
|
||||||
<Configuration>Release</Configuration>
|
|
||||||
<Platform>Win32</Platform>
|
|
||||||
</ProjectConfiguration>
|
|
||||||
<ProjectConfiguration Include="Release|x64">
|
|
||||||
<Configuration>Release</Configuration>
|
|
||||||
<Platform>x64</Platform>
|
|
||||||
</ProjectConfiguration>
|
|
||||||
</ItemGroup>
|
|
||||||
<PropertyGroup Label="Globals">
|
|
||||||
<ProjectGUID>{DC7BBA00-9FC6-48AF-B7E9-12CA91AC02AA}</ProjectGUID>
|
|
||||||
<Keyword>Win32Proj</Keyword>
|
|
||||||
<Platform>Win32</Platform>
|
|
||||||
<ProjectName>flattests</ProjectName>
|
|
||||||
</PropertyGroup>
|
|
||||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
|
||||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
|
|
||||||
<ConfigurationType>Application</ConfigurationType>
|
|
||||||
<UseOfMfc>false</UseOfMfc>
|
|
||||||
<CharacterSet>MultiByte</CharacterSet>
|
|
||||||
</PropertyGroup>
|
|
||||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
|
|
||||||
<ConfigurationType>Application</ConfigurationType>
|
|
||||||
<UseOfMfc>false</UseOfMfc>
|
|
||||||
<CharacterSet>MultiByte</CharacterSet>
|
|
||||||
</PropertyGroup>
|
|
||||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
|
||||||
<ConfigurationType>Application</ConfigurationType>
|
|
||||||
<UseOfMfc>false</UseOfMfc>
|
|
||||||
<CharacterSet>MultiByte</CharacterSet>
|
|
||||||
</PropertyGroup>
|
|
||||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
|
|
||||||
<ConfigurationType>Application</ConfigurationType>
|
|
||||||
<UseOfMfc>false</UseOfMfc>
|
|
||||||
<CharacterSet>MultiByte</CharacterSet>
|
|
||||||
</PropertyGroup>
|
|
||||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
|
||||||
<ImportGroup Label="ExtensionSettings">
|
|
||||||
</ImportGroup>
|
|
||||||
<ImportGroup Label="PropertySheets">
|
|
||||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
|
||||||
</ImportGroup>
|
|
||||||
<PropertyGroup Label="UserMacros" />
|
|
||||||
<PropertyGroup>
|
|
||||||
<_ProjectFileVersion>10.0.20506.1</_ProjectFileVersion>
|
|
||||||
<OutDir Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">$(IntDir)</OutDir>
|
|
||||||
<OutDir Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">$(IntDir)</OutDir>
|
|
||||||
<IntDir Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">flattests.dir\Debug\</IntDir>
|
|
||||||
<IntDir Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">flattests.dir\Debug\</IntDir>
|
|
||||||
<TargetName Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">flattests</TargetName>
|
|
||||||
<TargetName Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">flattests</TargetName>
|
|
||||||
<TargetExt Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">.exe</TargetExt>
|
|
||||||
<TargetExt Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">.exe</TargetExt>
|
|
||||||
<LinkIncremental Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</LinkIncremental>
|
|
||||||
<LinkIncremental Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</LinkIncremental>
|
|
||||||
<GenerateManifest Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</GenerateManifest>
|
|
||||||
<GenerateManifest Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</GenerateManifest>
|
|
||||||
<OutDir Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">$(IntDir)</OutDir>
|
|
||||||
<OutDir Condition="'$(Configuration)|$(Platform)'=='Release|x64'">$(IntDir)</OutDir>
|
|
||||||
<IntDir Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">flattests.dir\Release\</IntDir>
|
|
||||||
<IntDir Condition="'$(Configuration)|$(Platform)'=='Release|x64'">flattests.dir\Release\</IntDir>
|
|
||||||
<TargetName Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">flattests</TargetName>
|
|
||||||
<TargetName Condition="'$(Configuration)|$(Platform)'=='Release|x64'">flattests</TargetName>
|
|
||||||
<TargetExt Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">.exe</TargetExt>
|
|
||||||
<TargetExt Condition="'$(Configuration)|$(Platform)'=='Release|x64'">.exe</TargetExt>
|
|
||||||
<LinkIncremental Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">false</LinkIncremental>
|
|
||||||
<LinkIncremental Condition="'$(Configuration)|$(Platform)'=='Release|x64'">false</LinkIncremental>
|
|
||||||
<GenerateManifest Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</GenerateManifest>
|
|
||||||
<GenerateManifest Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</GenerateManifest>
|
|
||||||
</PropertyGroup>
|
|
||||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
|
||||||
<ClCompile>
|
|
||||||
<AdditionalIncludeDirectories>../../include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
|
||||||
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
|
|
||||||
<CompileAs>CompileAsCpp</CompileAs>
|
|
||||||
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
|
|
||||||
<ExceptionHandling>Sync</ExceptionHandling>
|
|
||||||
<InlineFunctionExpansion>Disabled</InlineFunctionExpansion>
|
|
||||||
<Optimization>Disabled</Optimization>
|
|
||||||
<PrecompiledHeader>NotUsing</PrecompiledHeader>
|
|
||||||
<RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
|
|
||||||
<RuntimeTypeInfo>true</RuntimeTypeInfo>
|
|
||||||
<WarningLevel>Level4</WarningLevel>
|
|
||||||
<PreprocessorDefinitions>WIN32;_WINDOWS;_DEBUG;CMAKE_INTDIR="Debug";%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
|
||||||
<AssemblerListingLocation>Debug</AssemblerListingLocation>
|
|
||||||
<ObjectFileName>$(IntDir)</ObjectFileName>
|
|
||||||
<ProgramDataBaseFileName>../../Debug/flattests.pdb</ProgramDataBaseFileName>
|
|
||||||
<TreatWarningAsError>true</TreatWarningAsError>
|
|
||||||
</ClCompile>
|
|
||||||
<ResourceCompile>
|
|
||||||
<PreprocessorDefinitions>WIN32;_WINDOWS;_DEBUG;CMAKE_INTDIR=\"Debug\";%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
|
||||||
<AdditionalIncludeDirectories>../../include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
|
||||||
</ResourceCompile>
|
|
||||||
<Midl>
|
|
||||||
<AdditionalIncludeDirectories>../../include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
|
||||||
<OutputDirectory>$(IntDir)</OutputDirectory>
|
|
||||||
<HeaderFileName>%(Filename).h</HeaderFileName>
|
|
||||||
<TypeLibraryName>%(Filename).tlb</TypeLibraryName>
|
|
||||||
<InterfaceIdentifierFileName>%(Filename)_i.c</InterfaceIdentifierFileName>
|
|
||||||
<ProxyFileName>%(Filename)_p.c</ProxyFileName>
|
|
||||||
</Midl>
|
|
||||||
<Link>
|
|
||||||
<AdditionalOptions> /machine:X86 /debug %(AdditionalOptions)</AdditionalOptions>
|
|
||||||
<AdditionalDependencies>kernel32.lib;user32.lib;gdi32.lib;winspool.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;comdlg32.lib;advapi32.lib</AdditionalDependencies>
|
|
||||||
<AdditionalLibraryDirectories>%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
|
|
||||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
|
||||||
<ImportLibrary>../../Debug/flattests.lib</ImportLibrary>
|
|
||||||
<ProgramDataBaseFile>../../Debug/flattests.pdb</ProgramDataBaseFile>
|
|
||||||
<SubSystem>Console</SubSystem>
|
|
||||||
<Version>
|
|
||||||
</Version>
|
|
||||||
</Link>
|
|
||||||
<ProjectReference>
|
|
||||||
<LinkLibraryDependencies>false</LinkLibraryDependencies>
|
|
||||||
</ProjectReference>
|
|
||||||
</ItemDefinitionGroup>
|
|
||||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
|
||||||
<ClCompile>
|
|
||||||
<AdditionalIncludeDirectories>../../include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
|
||||||
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
|
|
||||||
<CompileAs>CompileAsCpp</CompileAs>
|
|
||||||
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
|
|
||||||
<ExceptionHandling>Sync</ExceptionHandling>
|
|
||||||
<InlineFunctionExpansion>Disabled</InlineFunctionExpansion>
|
|
||||||
<Optimization>Disabled</Optimization>
|
|
||||||
<PrecompiledHeader>NotUsing</PrecompiledHeader>
|
|
||||||
<RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
|
|
||||||
<RuntimeTypeInfo>true</RuntimeTypeInfo>
|
|
||||||
<WarningLevel>Level4</WarningLevel>
|
|
||||||
<PreprocessorDefinitions>WIN32;_WINDOWS;_DEBUG;CMAKE_INTDIR="Debug";%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
|
||||||
<AssemblerListingLocation>Debug</AssemblerListingLocation>
|
|
||||||
<ObjectFileName>$(IntDir)</ObjectFileName>
|
|
||||||
<ProgramDataBaseFileName>../../Debug/flattests.pdb</ProgramDataBaseFileName>
|
|
||||||
<TreatWarningAsError>true</TreatWarningAsError>
|
|
||||||
</ClCompile>
|
|
||||||
<ResourceCompile>
|
|
||||||
<PreprocessorDefinitions>WIN32;_WINDOWS;_DEBUG;CMAKE_INTDIR=\"Debug\";%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
|
||||||
<AdditionalIncludeDirectories>../../include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
|
||||||
</ResourceCompile>
|
|
||||||
<Midl>
|
|
||||||
<AdditionalIncludeDirectories>../../include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
|
||||||
<OutputDirectory>$(IntDir)</OutputDirectory>
|
|
||||||
<HeaderFileName>%(Filename).h</HeaderFileName>
|
|
||||||
<TypeLibraryName>%(Filename).tlb</TypeLibraryName>
|
|
||||||
<InterfaceIdentifierFileName>%(Filename)_i.c</InterfaceIdentifierFileName>
|
|
||||||
<ProxyFileName>%(Filename)_p.c</ProxyFileName>
|
|
||||||
</Midl>
|
|
||||||
<Link>
|
|
||||||
<AdditionalOptions>/debug %(AdditionalOptions)</AdditionalOptions>
|
|
||||||
<AdditionalDependencies>kernel32.lib;user32.lib;gdi32.lib;winspool.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;comdlg32.lib;advapi32.lib</AdditionalDependencies>
|
|
||||||
<AdditionalLibraryDirectories>%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
|
|
||||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
|
||||||
<ImportLibrary>../../Debug/flattests.lib</ImportLibrary>
|
|
||||||
<ProgramDataBaseFile>../../Debug/flattests.pdb</ProgramDataBaseFile>
|
|
||||||
<SubSystem>Console</SubSystem>
|
|
||||||
<Version>
|
|
||||||
</Version>
|
|
||||||
</Link>
|
|
||||||
<ProjectReference>
|
|
||||||
<LinkLibraryDependencies>false</LinkLibraryDependencies>
|
|
||||||
</ProjectReference>
|
|
||||||
</ItemDefinitionGroup>
|
|
||||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
|
||||||
<ClCompile>
|
|
||||||
<AdditionalIncludeDirectories>../../include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
|
||||||
<CompileAs>CompileAsCpp</CompileAs>
|
|
||||||
<ExceptionHandling>Sync</ExceptionHandling>
|
|
||||||
<InlineFunctionExpansion>AnySuitable</InlineFunctionExpansion>
|
|
||||||
<Optimization>MaxSpeed</Optimization>
|
|
||||||
<PrecompiledHeader>NotUsing</PrecompiledHeader>
|
|
||||||
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
|
|
||||||
<RuntimeTypeInfo>true</RuntimeTypeInfo>
|
|
||||||
<WarningLevel>Level4</WarningLevel>
|
|
||||||
<DebugInformationFormat>
|
|
||||||
</DebugInformationFormat>
|
|
||||||
<PreprocessorDefinitions>WIN32;_WINDOWS;NDEBUG;CMAKE_INTDIR="Release";%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
|
||||||
<AssemblerListingLocation>Release</AssemblerListingLocation>
|
|
||||||
<ObjectFileName>$(IntDir)</ObjectFileName>
|
|
||||||
<ProgramDataBaseFileName>../../Release/flattests.pdb</ProgramDataBaseFileName>
|
|
||||||
<TreatWarningAsError>true</TreatWarningAsError>
|
|
||||||
</ClCompile>
|
|
||||||
<ResourceCompile>
|
|
||||||
<PreprocessorDefinitions>WIN32;_WINDOWS;NDEBUG;CMAKE_INTDIR=\"Release\";%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
|
||||||
<AdditionalIncludeDirectories>../../include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
|
||||||
</ResourceCompile>
|
|
||||||
<Midl>
|
|
||||||
<AdditionalIncludeDirectories>../../include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
|
||||||
<OutputDirectory>$(IntDir)</OutputDirectory>
|
|
||||||
<HeaderFileName>%(Filename).h</HeaderFileName>
|
|
||||||
<TypeLibraryName>%(Filename).tlb</TypeLibraryName>
|
|
||||||
<InterfaceIdentifierFileName>%(Filename)_i.c</InterfaceIdentifierFileName>
|
|
||||||
<ProxyFileName>%(Filename)_p.c</ProxyFileName>
|
|
||||||
</Midl>
|
|
||||||
<Link>
|
|
||||||
<AdditionalOptions> /machine:X86 %(AdditionalOptions)</AdditionalOptions>
|
|
||||||
<AdditionalDependencies>kernel32.lib;user32.lib;gdi32.lib;winspool.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;comdlg32.lib;advapi32.lib</AdditionalDependencies>
|
|
||||||
<AdditionalLibraryDirectories>%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
|
|
||||||
<GenerateDebugInformation>false</GenerateDebugInformation>
|
|
||||||
<ImportLibrary>../../Release/flattests.lib</ImportLibrary>
|
|
||||||
<ProgramDataBaseFile>../../Release/flattests.pdb</ProgramDataBaseFile>
|
|
||||||
<SubSystem>Console</SubSystem>
|
|
||||||
<Version>
|
|
||||||
</Version>
|
|
||||||
</Link>
|
|
||||||
<ProjectReference>
|
|
||||||
<LinkLibraryDependencies>false</LinkLibraryDependencies>
|
|
||||||
</ProjectReference>
|
|
||||||
</ItemDefinitionGroup>
|
|
||||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
|
||||||
<ClCompile>
|
|
||||||
<AdditionalIncludeDirectories>../../include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
|
||||||
<CompileAs>CompileAsCpp</CompileAs>
|
|
||||||
<ExceptionHandling>Sync</ExceptionHandling>
|
|
||||||
<InlineFunctionExpansion>AnySuitable</InlineFunctionExpansion>
|
|
||||||
<Optimization>MaxSpeed</Optimization>
|
|
||||||
<PrecompiledHeader>NotUsing</PrecompiledHeader>
|
|
||||||
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
|
|
||||||
<RuntimeTypeInfo>true</RuntimeTypeInfo>
|
|
||||||
<WarningLevel>Level4</WarningLevel>
|
|
||||||
<DebugInformationFormat>
|
|
||||||
</DebugInformationFormat>
|
|
||||||
<PreprocessorDefinitions>WIN32;_WINDOWS;NDEBUG;CMAKE_INTDIR="Release";%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
|
||||||
<AssemblerListingLocation>Release</AssemblerListingLocation>
|
|
||||||
<ObjectFileName>$(IntDir)</ObjectFileName>
|
|
||||||
<ProgramDataBaseFileName>../../Release/flattests.pdb</ProgramDataBaseFileName>
|
|
||||||
<TreatWarningAsError>true</TreatWarningAsError>
|
|
||||||
</ClCompile>
|
|
||||||
<ResourceCompile>
|
|
||||||
<PreprocessorDefinitions>WIN32;_WINDOWS;NDEBUG;CMAKE_INTDIR=\"Release\";%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
|
||||||
<AdditionalIncludeDirectories>../../include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
|
||||||
</ResourceCompile>
|
|
||||||
<Midl>
|
|
||||||
<AdditionalIncludeDirectories>../../include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
|
||||||
<OutputDirectory>$(IntDir)</OutputDirectory>
|
|
||||||
<HeaderFileName>%(Filename).h</HeaderFileName>
|
|
||||||
<TypeLibraryName>%(Filename).tlb</TypeLibraryName>
|
|
||||||
<InterfaceIdentifierFileName>%(Filename)_i.c</InterfaceIdentifierFileName>
|
|
||||||
<ProxyFileName>%(Filename)_p.c</ProxyFileName>
|
|
||||||
</Midl>
|
|
||||||
<Link>
|
|
||||||
<AdditionalDependencies>kernel32.lib;user32.lib;gdi32.lib;winspool.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;comdlg32.lib;advapi32.lib</AdditionalDependencies>
|
|
||||||
<AdditionalLibraryDirectories>%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
|
|
||||||
<GenerateDebugInformation>false</GenerateDebugInformation>
|
|
||||||
<ImportLibrary>../../Release/flattests.lib</ImportLibrary>
|
|
||||||
<ProgramDataBaseFile>../../Release/flattests.pdb</ProgramDataBaseFile>
|
|
||||||
<SubSystem>Console</SubSystem>
|
|
||||||
<Version>
|
|
||||||
</Version>
|
|
||||||
</Link>
|
|
||||||
<ProjectReference>
|
|
||||||
<LinkLibraryDependencies>false</LinkLibraryDependencies>
|
|
||||||
</ProjectReference>
|
|
||||||
</ItemDefinitionGroup>
|
|
||||||
<ItemGroup>
|
|
||||||
<ClInclude Include="..\..\include\flatbuffers\flatbuffers.h" />
|
|
||||||
<ClInclude Include="..\..\include\flatbuffers\idl.h" />
|
|
||||||
<ClInclude Include="..\..\include\flatbuffers\reflection.h" />
|
|
||||||
<ClInclude Include="..\..\include\flatbuffers\util.h" />
|
|
||||||
<ClInclude Include="..\..\tests\monster_test_generated.h" />
|
|
||||||
<ClCompile Include="..\..\src\idl_gen_fbs.cpp" />
|
|
||||||
<ClCompile Include="..\..\src\idl_gen_general.cpp" />
|
|
||||||
<ClCompile Include="..\..\src\idl_parser.cpp" />
|
|
||||||
<ClCompile Include="..\..\src\idl_gen_text.cpp" />
|
|
||||||
<ClCompile Include="..\..\src\reflection.cpp" />
|
|
||||||
<ClCompile Include="..\..\tests\test.cpp" />
|
|
||||||
</ItemGroup>
|
|
||||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
|
||||||
<ImportGroup Label="ExtensionTargets">
|
|
||||||
</ImportGroup>
|
|
||||||
</Project>
|
|
||||||
@@ -1,19 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
|
||||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
|
||||||
<LocalDebuggerWorkingDirectory>..\..</LocalDebuggerWorkingDirectory>
|
|
||||||
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
|
|
||||||
</PropertyGroup>
|
|
||||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
|
||||||
<LocalDebuggerWorkingDirectory>..\..</LocalDebuggerWorkingDirectory>
|
|
||||||
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
|
|
||||||
</PropertyGroup>
|
|
||||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
|
||||||
<LocalDebuggerWorkingDirectory>..\..</LocalDebuggerWorkingDirectory>
|
|
||||||
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
|
|
||||||
</PropertyGroup>
|
|
||||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
|
||||||
<LocalDebuggerWorkingDirectory>..\..</LocalDebuggerWorkingDirectory>
|
|
||||||
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
|
|
||||||
</PropertyGroup>
|
|
||||||
</Project>
|
|
||||||
File diff suppressed because it is too large
Load Diff
@@ -1,14 +1,9 @@
|
|||||||
Building {#flatbuffers_guide_building}
|
Building {#flatbuffers_guide_building}
|
||||||
========
|
========
|
||||||
|
|
||||||
## Building with Visual Studio or Xcode projects
|
|
||||||
|
|
||||||
There are project files for Visual Studio and Xcode that should allow you
|
|
||||||
to build the compiler `flatc`, the samples and the tests out of the box.
|
|
||||||
|
|
||||||
## Building with CMake
|
## Building with CMake
|
||||||
|
|
||||||
Alternatively, the distribution comes with a `cmake` file that should allow
|
The distribution comes with a `cmake` file that should allow
|
||||||
you to build project/make files for any platform. For details on `cmake`, see
|
you to build project/make files for any platform. For details on `cmake`, see
|
||||||
<http://www.cmake.org>. In brief, depending on your platform, use one of
|
<http://www.cmake.org>. In brief, depending on your platform, use one of
|
||||||
e.g.:
|
e.g.:
|
||||||
|
|||||||
224
docs/source/CUsage.md
Normal file
224
docs/source/CUsage.md
Normal file
@@ -0,0 +1,224 @@
|
|||||||
|
Use in C {#flatbuffers_guide_use_c}
|
||||||
|
==========
|
||||||
|
|
||||||
|
The C language binding exists in a separate project named [FlatCC](https://github.com/dvidelabs/flatcc).
|
||||||
|
|
||||||
|
The `flatcc` C schema compiler can generate code offline as well as
|
||||||
|
online via a C library. It can also generate buffer verifiers and fast
|
||||||
|
JSON parsers, printers.
|
||||||
|
|
||||||
|
Great care has been taken to ensure compatibily with the main `flatc`
|
||||||
|
project.
|
||||||
|
|
||||||
|
## General Documention
|
||||||
|
|
||||||
|
- [Tutorial](@ref flatbuffers_guide_tutorial) - select C as language
|
||||||
|
when scrolling down
|
||||||
|
- [FlatCC Guide](https://github.com/dvidelabs/flatcc#flatcc-flatbuffers-in-c-for-c)
|
||||||
|
- [The C Builder Interface](https://github.com/dvidelabs/flatcc/blob/master/doc/builder.md#the-builder-interface)
|
||||||
|
- [The Monster Sample in C](https://github.com/dvidelabs/flatcc/blob/master/samples/monster/monster.c)
|
||||||
|
- [GitHub](https://github.com/dvidelabs/flatcc)
|
||||||
|
|
||||||
|
|
||||||
|
## Supported Platforms
|
||||||
|
|
||||||
|
- Ubuntu (clang / gcc, ninja / gnu make)
|
||||||
|
- OS-X (clang / gcc, ninja / gnu make)
|
||||||
|
- Windows MSVC 2010, 2013, 2015
|
||||||
|
|
||||||
|
CI builds recent versions of gcc, clang and MSVC on OS-X, Ubuntu, and
|
||||||
|
Windows, and occasionally older compiler versions. See main project [Status](https://github.com/dvidelabs/flatcc#status).
|
||||||
|
|
||||||
|
Other platforms may well work, including Centos, but are not tested
|
||||||
|
regularly.
|
||||||
|
|
||||||
|
The monster sample project was specifically written for C99 in order to
|
||||||
|
follow the C++ version and for that reason it will not work with MSVC
|
||||||
|
2010.
|
||||||
|
|
||||||
|
## Modular Object Creation
|
||||||
|
|
||||||
|
In the tutorial we used the call `Monster_create_as_root` to create the
|
||||||
|
root buffer object since this is easier in simple use cases. Sometimes
|
||||||
|
we need more modularity so we can reuse a function to create nested
|
||||||
|
tables and root tables the same way. For this we need the
|
||||||
|
`flatcc_builder_buffer_create_call`. It is best to keep `flatcc_builder`
|
||||||
|
calls isolated at the top driver level, so we get:
|
||||||
|
|
||||||
|
<div class="language-c">
|
||||||
|
~~~{.c}
|
||||||
|
ns(Monster_ref_t) create_orc(flatcc_builder_t *B)
|
||||||
|
{
|
||||||
|
// ... same as in the tutorial.
|
||||||
|
return s(Monster_create(B, ...));
|
||||||
|
}
|
||||||
|
|
||||||
|
void create_monster_buffer()
|
||||||
|
{
|
||||||
|
uint8_t *buf;
|
||||||
|
size_t size;
|
||||||
|
flatcc_builder_t builder, *B;
|
||||||
|
|
||||||
|
// Initialize the builder object.
|
||||||
|
B = &builder;
|
||||||
|
flatcc_builder_init(B);
|
||||||
|
// Only use `buffer_create` without `create/start/end_as_root`.
|
||||||
|
flatcc_builder_buffer_create(create_orc(B));
|
||||||
|
// Allocate and copy buffer to user memory.
|
||||||
|
buf = flatcc_builder_finalize_buffer(B, &size);
|
||||||
|
// ... write the buffer to disk or network, or something.
|
||||||
|
|
||||||
|
free(buf);
|
||||||
|
flatcc_builder_clear(B);
|
||||||
|
}
|
||||||
|
~~~
|
||||||
|
</div>
|
||||||
|
|
||||||
|
The same principle applies with `start/end` vs `start/end_as_root` in
|
||||||
|
the top-down approach.
|
||||||
|
|
||||||
|
|
||||||
|
## Top Down Example
|
||||||
|
|
||||||
|
The tutorial uses a bottom up approach. In C it is also possible to use
|
||||||
|
a top-down approach by starting and ending objects nested within each
|
||||||
|
other. In the tutorial there is no deep nesting, so the difference is
|
||||||
|
limited, but it shows the idea:
|
||||||
|
|
||||||
|
<div class="language-c">
|
||||||
|
<br>
|
||||||
|
~~~{.c}
|
||||||
|
uint8_t treasure[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
|
||||||
|
size_t treasure_count = c_vec_len(treasure);
|
||||||
|
ns(Weapon_ref_t) axe;
|
||||||
|
|
||||||
|
// NOTE: if we use end_as_root, we MUST also start as root.
|
||||||
|
ns(Monster_start_as_root(B));
|
||||||
|
ns(Monster_pos_create(B, 1.0f, 2.0f, 3.0f));
|
||||||
|
ns(Monster_hp_add(B, 300));
|
||||||
|
ns(Monster_mana_add(B, 150));
|
||||||
|
// We use create_str instead of add because we have no existing string reference.
|
||||||
|
ns(Monster_name_create_str(B, "Orc"));
|
||||||
|
// Again we use create because we no existing vector object, only a C-array.
|
||||||
|
ns(Monster_inventory_create(B, treasure, treasure_count));
|
||||||
|
ns(Monster_color_add(B, ns(Color_Red)));
|
||||||
|
if (1) {
|
||||||
|
ns(Monster_weapons_start(B));
|
||||||
|
ns(Monster_weapons_push_create(B, flatbuffers_string_create_str(B, "Sword"), 3));
|
||||||
|
// We reuse the axe object later. Note that we dereference a pointer
|
||||||
|
// because push always returns a short-term pointer to the stored element.
|
||||||
|
// We could also have created the axe object first and simply pushed it.
|
||||||
|
axe = *ns(Monster_weapons_push_create(B, flatbuffers_string_create_str(B, "Axe"), 5));
|
||||||
|
ns(Monster_weapons_end(B));
|
||||||
|
} else {
|
||||||
|
// We can have more control with the table elements added to a vector:
|
||||||
|
//
|
||||||
|
ns(Monster_weapons_start(B));
|
||||||
|
ns(Monster_weapons_push_start(B));
|
||||||
|
ns(Weapon_name_create_str(B, "Sword"));
|
||||||
|
ns(Weapon_damage_add(B, 3));
|
||||||
|
ns(Monster_weapons_push_end(B));
|
||||||
|
ns(Monster_weapons_push_start(B));
|
||||||
|
ns(Monster_weapons_push_start(B));
|
||||||
|
ns(Weapon_name_create_str(B, "Axe"));
|
||||||
|
ns(Weapon_damage_add(B, 5));
|
||||||
|
axe = *ns(Monster_weapons_push_end(B));
|
||||||
|
ns(Monster_weapons_end(B));
|
||||||
|
}
|
||||||
|
// Unions can get their type by using a type-specific add/create/start method.
|
||||||
|
ns(Monster_equipped_Weapon_add(B, axe));
|
||||||
|
|
||||||
|
ns(Monster_end_as_root(B));
|
||||||
|
~~~
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
## Basic Reflection
|
||||||
|
|
||||||
|
The C-API does support reading binary schema (.bfbs)
|
||||||
|
files via code generated from the `reflection.fbs` schema, and an
|
||||||
|
[example usage](https://github.com/dvidelabs/flatcc/tree/master/samples/reflection)
|
||||||
|
shows how to use this. The reflection schema files are pre-generated
|
||||||
|
in the [runtime distribution](https://github.com/dvidelabs/flatcc/tree/master/include/flatcc/reflection).
|
||||||
|
|
||||||
|
|
||||||
|
## Mutations and Reflection
|
||||||
|
|
||||||
|
The C-API does not support mutating reflection like C++ does, nor does
|
||||||
|
the reader interface support mutating scalars (and it is generally
|
||||||
|
unsafe to do so even after verification).
|
||||||
|
|
||||||
|
The generated reader interface supports sorting vectors in-place after
|
||||||
|
casting them to a mutating type because it is not practical to do so
|
||||||
|
while building a buffer. This is covered in the builder documentation.
|
||||||
|
The reflection example makes use of this feature to look up objects by
|
||||||
|
name.
|
||||||
|
|
||||||
|
It is possible to build new buffers using complex objects from existing
|
||||||
|
buffers as source. This can be very efficient due to direct copy
|
||||||
|
semantics without endian conversion or temporary stack allocation.
|
||||||
|
|
||||||
|
Scalars, structs and strings can be used as source, as well vectors of
|
||||||
|
these.
|
||||||
|
|
||||||
|
It is currently not possible to use an existing table or vector of table
|
||||||
|
as source, but it would be possible to add support for this at some
|
||||||
|
point.
|
||||||
|
|
||||||
|
|
||||||
|
## Namespaces
|
||||||
|
|
||||||
|
The `FLATBUFFERS_WRAP_NAMESPACE` approach used in the tutorial is convenient
|
||||||
|
when each function has a very long namespace prefix. But it isn't always
|
||||||
|
the best approach. If the namespace is absent, or simple and
|
||||||
|
informative, we might as well use the prefix directly. The
|
||||||
|
[reflection example](https://github.com/dvidelabs/flatcc/blob/master/samples/reflection/bfbs2json.c)
|
||||||
|
mentioned above uses this approach.
|
||||||
|
|
||||||
|
|
||||||
|
## Checking for Present Members
|
||||||
|
|
||||||
|
Not all languages support testing if a field is present, but in C we can
|
||||||
|
elaborate the reader section of the tutorial with tests for this. Recall
|
||||||
|
that `mana` was set to the default value `150` and therefore shouldn't
|
||||||
|
be present.
|
||||||
|
|
||||||
|
<div class="language-c">
|
||||||
|
~~~{.c}
|
||||||
|
int hp_present = ns(Monster_hp_is_present(monster)); // 1
|
||||||
|
int mana_present = ns(Monster_mana_is_present(monster)); // 0
|
||||||
|
~~~
|
||||||
|
</div>
|
||||||
|
|
||||||
|
## Alternative ways to add a Union
|
||||||
|
|
||||||
|
In the tutorial we used a single call to add a union. Here we show
|
||||||
|
different ways to accomplish the same thing. The last form is rarely
|
||||||
|
used, but is the low-level way to do it. It can be used to group small
|
||||||
|
values together in the table by adding type and data at different
|
||||||
|
points in time.
|
||||||
|
|
||||||
|
<div class="language-c">
|
||||||
|
~~~{.c}
|
||||||
|
ns(Equipment_union_ref_t) equipped = ns(Equipment_as_Weapon(axe));
|
||||||
|
ns(Monster_equipped_add(B, equipped));
|
||||||
|
// or alternatively
|
||||||
|
ns(Monster_equipped_Weapon_add(B, axe);
|
||||||
|
// or alternatively
|
||||||
|
ns(Monster_equipped_add_type(B, ns(Equipment_Weapon));
|
||||||
|
ns(Monster_equipped_add_member(B, axe));
|
||||||
|
~~~
|
||||||
|
</div>
|
||||||
|
|
||||||
|
## Why not integrate with the `flatc` tool?
|
||||||
|
|
||||||
|
[It was considered how the C code generator could be integrated into the
|
||||||
|
`flatc` tool](https://github.com/dvidelabs/flatcc/issues/1), but it
|
||||||
|
would either require that the standalone C implementation of the schema
|
||||||
|
compiler was dropped, or it would lead to excessive code duplication, or
|
||||||
|
a complicated intermediate representation would have to be invented.
|
||||||
|
Neither of these alternatives are very attractive, and it isn't a big
|
||||||
|
deal to use the `flatcc` tool instead of `flatc` given that the
|
||||||
|
FlatBuffers C runtime library needs to be made available regardless.
|
||||||
|
|
||||||
|
|
||||||
@@ -33,6 +33,8 @@ For any schema input files, one or more generators can be specified:
|
|||||||
|
|
||||||
- `--php`: Generate PHP code.
|
- `--php`: Generate PHP code.
|
||||||
|
|
||||||
|
- `--grpc`: Generate RPC stub code for GRPC.
|
||||||
|
|
||||||
For any data input files:
|
For any data input files:
|
||||||
|
|
||||||
- `--binary`, `-b` : If data is contained in this file, generate a
|
- `--binary`, `-b` : If data is contained in this file, generate a
|
||||||
@@ -79,6 +81,11 @@ Additional options:
|
|||||||
- `--gen-mutable` : Generate additional non-const accessors for mutating
|
- `--gen-mutable` : Generate additional non-const accessors for mutating
|
||||||
FlatBuffers in-place.
|
FlatBuffers in-place.
|
||||||
|
|
||||||
|
`--gen-object-api` : Generate an additional object-based API. This API is
|
||||||
|
more convenient for object construction and mutation than the base API,
|
||||||
|
at the cost of efficiency (object allocation). Recommended only to be used
|
||||||
|
if other options are insufficient.
|
||||||
|
|
||||||
- `--gen-onefile` : Generate single output file (useful for C#)
|
- `--gen-onefile` : Generate single output file (useful for C#)
|
||||||
|
|
||||||
- `--gen-all`: Generate not just code for the current schema files, but
|
- `--gen-all`: Generate not just code for the current schema files, but
|
||||||
@@ -86,6 +93,12 @@ Additional options:
|
|||||||
output (by default the case for C++ and JS), all code will end up in
|
output (by default the case for C++ and JS), all code will end up in
|
||||||
this one file.
|
this one file.
|
||||||
|
|
||||||
|
- `--no-js-exports` : Removes Node.js style export lines (useful for JS)
|
||||||
|
|
||||||
|
- `--goog-js-export` : Uses goog.exportsSymbol and goog.exportsProperty
|
||||||
|
instead of Node.js style exporting. Needed for compatibility with the
|
||||||
|
Google closure compiler (useful for JS).
|
||||||
|
|
||||||
- `--raw-binary` : Allow binaries without a file_indentifier to be read.
|
- `--raw-binary` : Allow binaries without a file_indentifier to be read.
|
||||||
This may crash flatc given a mismatched schema.
|
This may crash flatc given a mismatched schema.
|
||||||
|
|
||||||
@@ -101,5 +114,14 @@ Additional options:
|
|||||||
to the reflection/reflection.fbs schema. Loading this binary file is the
|
to the reflection/reflection.fbs schema. Loading this binary file is the
|
||||||
basis for reflection functionality.
|
basis for reflection functionality.
|
||||||
|
|
||||||
|
- `--bfbs-comments`: Add doc comments to the binary schema files.
|
||||||
|
|
||||||
|
- `--conform FILE` : Specify a schema the following schemas should be
|
||||||
|
an evolution of. Gives errors if not. Useful to check if schema
|
||||||
|
modifications don't break schema evolution rules.
|
||||||
|
|
||||||
|
- `--include-prefix PATH` : Prefix this path to any generated include
|
||||||
|
statements.
|
||||||
|
|
||||||
NOTE: short-form options for generators are deprecated, use the long form
|
NOTE: short-form options for generators are deprecated, use the long form
|
||||||
whenever possible.
|
whenever possible.
|
||||||
|
|||||||
@@ -26,8 +26,7 @@ your program by including the header. As noted, this header relies on
|
|||||||
|
|
||||||
The code for the FlatBuffers C++ library can be found at
|
The code for the FlatBuffers C++ library can be found at
|
||||||
`flatbuffers/include/flatbuffers`. You can browse the library code on the
|
`flatbuffers/include/flatbuffers`. You can browse the library code on the
|
||||||
[FlatBuffers GitHub page](https://github.com/google/flatbuffers/tree/master/
|
[FlatBuffers GitHub page](https://github.com/google/flatbuffers/tree/master/include/flatbuffers).
|
||||||
include/flatbuffers).
|
|
||||||
|
|
||||||
## Testing the FlatBuffers C++ library
|
## Testing the FlatBuffers C++ library
|
||||||
|
|
||||||
@@ -86,6 +85,121 @@ convenient accessors for all fields, e.g. `hp()`, `mana()`, etc:
|
|||||||
|
|
||||||
*Note: That we never stored a `mana` value, so it will return the default.*
|
*Note: That we never stored a `mana` value, so it will return the default.*
|
||||||
|
|
||||||
|
## Object based API. {#flatbuffers_cpp_object_based_api}
|
||||||
|
|
||||||
|
FlatBuffers is all about memory efficiency, which is why its base API is written
|
||||||
|
around using as little as possible of it. This does make the API clumsier
|
||||||
|
(requiring pre-order construction of all data, and making mutation harder).
|
||||||
|
|
||||||
|
For times when efficiency is less important a more convenient object based API
|
||||||
|
can be used (through `--gen-object-api`) that is able to unpack & pack a
|
||||||
|
FlatBuffer into objects and standard STL containers, allowing for convenient
|
||||||
|
construction, access and mutation.
|
||||||
|
|
||||||
|
To use:
|
||||||
|
|
||||||
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
|
||||||
|
// Autogenerated class from table Monster.
|
||||||
|
MonsterT monsterobj;
|
||||||
|
|
||||||
|
// Deserialize from buffer into object.
|
||||||
|
UnPackTo(&monsterobj, flatbuffer);
|
||||||
|
|
||||||
|
// Update object directly like a C++ class instance.
|
||||||
|
cout << monsterobj->name; // This is now a std::string!
|
||||||
|
monsterobj->name = "Bob"; // Change the name.
|
||||||
|
|
||||||
|
// Serialize into new flatbuffer.
|
||||||
|
FlatBufferBuilder fbb;
|
||||||
|
Pack(fbb, &monsterobj);
|
||||||
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
|
The following attributes are specific to the object-based API code generation:
|
||||||
|
|
||||||
|
- `native_inline` (on a field): Because FlatBuffer tables and structs are
|
||||||
|
optionally present in a given buffer, they are best represented as pointers
|
||||||
|
(specifically std::unique_ptrs) in the native class since they can be null.
|
||||||
|
This attribute changes the member declaration to use the type directly
|
||||||
|
rather than wrapped in a unique_ptr.
|
||||||
|
|
||||||
|
- `native_default`: "value" (on a field): For members that are declared
|
||||||
|
"native_inline", the value specified with this attribute will be included
|
||||||
|
verbatim in the class constructor initializer list for this member.
|
||||||
|
|
||||||
|
- `native_type`' "type" (on a struct): In some cases, a more optimal C++ data
|
||||||
|
type exists for a given struct. For example, the following schema:
|
||||||
|
|
||||||
|
struct Vec2 {
|
||||||
|
x: float;
|
||||||
|
y: float;
|
||||||
|
}
|
||||||
|
|
||||||
|
generates the following Object-Based API class:
|
||||||
|
|
||||||
|
struct Vec2T : flatbuffers::NativeTable {
|
||||||
|
float x;
|
||||||
|
float y;
|
||||||
|
};
|
||||||
|
|
||||||
|
However, it can be useful to instead use a user-defined C++ type since it
|
||||||
|
can provide more functionality, eg.
|
||||||
|
|
||||||
|
struct vector2 {
|
||||||
|
float x = 0, y = 0;
|
||||||
|
vector2 operator+(vector2 rhs) const { ... }
|
||||||
|
vector2 operator-(vector2 rhs) const { ... }
|
||||||
|
float length() const { ... }
|
||||||
|
// etc.
|
||||||
|
};
|
||||||
|
|
||||||
|
The `native_type` attribute will replace the usage of the generated class
|
||||||
|
with the given type. So, continuing with the example, the generated
|
||||||
|
code would use |vector2| in place of |Vec2T| for all generated code.
|
||||||
|
|
||||||
|
However, becuase the native_type is unknown to flatbuffers, the user must
|
||||||
|
provide the following functions to aide in the serialization process:
|
||||||
|
|
||||||
|
namespace flatbuffers {
|
||||||
|
FlatbufferStruct Pack(const native_type& obj);
|
||||||
|
native_type UnPack(const FlatbufferStruct& obj);
|
||||||
|
}
|
||||||
|
|
||||||
|
Finally, the following top-level attribute
|
||||||
|
|
||||||
|
- native_include: "path" (at file level): Because the `native_type` attribute
|
||||||
|
can be used to introduce types that are unknown to flatbuffers, it may be
|
||||||
|
necessary to include "external" header files in the generated code. This
|
||||||
|
attribute can be used to directly add an #include directive to the top of
|
||||||
|
the generated code that includes the specified path directly.
|
||||||
|
|
||||||
|
# External references.
|
||||||
|
|
||||||
|
An additional feature of the object API is the ability to allow you to load
|
||||||
|
multiple independent FlatBuffers, and have them refer to eachothers objects
|
||||||
|
using hashes which are then represented as typed pointers in the object API.
|
||||||
|
|
||||||
|
To make this work have a field in the objects you want to referred to which is
|
||||||
|
using the string hashing feature (see `hash` attribute in the
|
||||||
|
[schema](@ref flatbuffers_guide_writing_schema) documentation). Then you have
|
||||||
|
a similar hash in the field referring to it, along with a `cpp_type`
|
||||||
|
attribute specifying the C++ type this will refer to (this can be any C++
|
||||||
|
type, and will get a `*` added).
|
||||||
|
|
||||||
|
Then, in JSON or however you create these buffers, make sure they use the
|
||||||
|
same string (or hash).
|
||||||
|
|
||||||
|
When you call `UnPack` (or `Create`), you'll need a function that maps from
|
||||||
|
hash to the object (see `resolver_function_t` for details).
|
||||||
|
|
||||||
|
# Using different pointer types.
|
||||||
|
|
||||||
|
By default the object tree is built out of `std::unique_ptr`, but you can
|
||||||
|
influence this either globally (using the `--cpp-ptr-type` argument to
|
||||||
|
`flatc`) or per field (using the `cpp_ptr_type` attribute) to by any smart
|
||||||
|
pointer type (`my_ptr<T>`), or by specifying `naked` as the type to get `T *`
|
||||||
|
pointers. Unlike the smart pointers, naked pointers do not manage memory for
|
||||||
|
you, so you'll have to manage their lifecycles manually.
|
||||||
|
|
||||||
## Reflection (& Resizing)
|
## Reflection (& Resizing)
|
||||||
|
|
||||||
There is experimental support for reflection in FlatBuffers, allowing you to
|
There is experimental support for reflection in FlatBuffers, allowing you to
|
||||||
|
|||||||
@@ -4,9 +4,9 @@ FlatBuffers {#flatbuffers_index}
|
|||||||
# Overview {#flatbuffers_overview}
|
# Overview {#flatbuffers_overview}
|
||||||
|
|
||||||
[FlatBuffers](@ref flatbuffers_overview) is an efficient cross platform
|
[FlatBuffers](@ref flatbuffers_overview) is an efficient cross platform
|
||||||
serialization library for C++, C#, Go, Java, JavaScript, PHP, and Python
|
serialization library for C++, C#, C, Go, Java, JavaScript, PHP, and Python.
|
||||||
(C and Ruby in progress). It was originally created at Google for game
|
It was originally created at Google for game development and other
|
||||||
development and other performance-critical applications.
|
performance-critical applications.
|
||||||
|
|
||||||
It is available as Open Source on [GitHub](http://github.com/google/flatbuffers)
|
It is available as Open Source on [GitHub](http://github.com/google/flatbuffers)
|
||||||
under the Apache license, v2 (see LICENSE.txt).
|
under the Apache license, v2 (see LICENSE.txt).
|
||||||
@@ -78,6 +78,9 @@ inefficiency, but also forces you to write *more* code to access data
|
|||||||
In this context, it is only a better choice for systems that have very
|
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.
|
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
|
Read more about the "why" of FlatBuffers in the
|
||||||
[white paper](@ref flatbuffers_white_paper).
|
[white paper](@ref flatbuffers_white_paper).
|
||||||
|
|
||||||
@@ -131,11 +134,15 @@ sections provide a more in-depth usage guide.
|
|||||||
in your own programs.
|
in your own programs.
|
||||||
- How to [use the generated Go code](@ref flatbuffers_guide_use_go) in your
|
- How to [use the generated Go code](@ref flatbuffers_guide_use_go) in your
|
||||||
own programs.
|
own programs.
|
||||||
|
- How to [use FlatBuffers in C with `flatcc`](@ref flatbuffers_guide_use_c) in your
|
||||||
|
own programs.
|
||||||
- [Support matrix](@ref flatbuffers_support) for platforms/languages/features.
|
- [Support matrix](@ref flatbuffers_support) for platforms/languages/features.
|
||||||
- Some [benchmarks](@ref flatbuffers_benchmarks) showing the advantage of
|
- Some [benchmarks](@ref flatbuffers_benchmarks) showing the advantage of
|
||||||
using FlatBuffers.
|
using FlatBuffers.
|
||||||
- A [white paper](@ref flatbuffers_white_paper) explaining the "why" of
|
- A [white paper](@ref flatbuffers_white_paper) explaining the "why" of
|
||||||
FlatBuffers.
|
FlatBuffers.
|
||||||
|
- How to use the [schema-less](@ref flexbuffers) version of
|
||||||
|
FlatBuffers.
|
||||||
- A description of the [internals](@ref flatbuffers_internals) of FlatBuffers.
|
- A description of the [internals](@ref flatbuffers_internals) of FlatBuffers.
|
||||||
- A formal [grammar](@ref flatbuffers_grammar) of the schema language.
|
- A formal [grammar](@ref flatbuffers_grammar) of the schema language.
|
||||||
|
|
||||||
@@ -143,7 +150,7 @@ sections provide a more in-depth usage guide.
|
|||||||
|
|
||||||
- [GitHub repository](http://github.com/google/flatbuffers)
|
- [GitHub repository](http://github.com/google/flatbuffers)
|
||||||
- [Landing page](http://google.github.io/flatbuffers)
|
- [Landing page](http://google.github.io/flatbuffers)
|
||||||
- [FlatBuffers Google Group](http://group.google.com/group/flatbuffers)
|
- [FlatBuffers Google Group](https://groups.google.com/forum/#!forum/flatbuffers)
|
||||||
- [FlatBuffers Issues Tracker](http://github.com/google/flatbuffers/issues)
|
- [FlatBuffers Issues Tracker](http://github.com/google/flatbuffers/issues)
|
||||||
- Independent implementations & tools:
|
- Independent implementations & tools:
|
||||||
- [FlatCC](https://github.com/dvidelabs/flatcc) Alternative FlatBuffers
|
- [FlatCC](https://github.com/dvidelabs/flatcc) Alternative FlatBuffers
|
||||||
|
|||||||
156
docs/source/FlexBuffers.md
Normal file
156
docs/source/FlexBuffers.md
Normal file
@@ -0,0 +1,156 @@
|
|||||||
|
FlexBuffers {#flexbuffers}
|
||||||
|
==========
|
||||||
|
|
||||||
|
FlatBuffers was designed around schemas, because when you want maximum
|
||||||
|
performance and data consistency, strong typing is helpful.
|
||||||
|
|
||||||
|
There are however times when you want to store data that doesn't fit a
|
||||||
|
schema, because you can't know ahead of time what all needs to be stored.
|
||||||
|
|
||||||
|
For this, FlatBuffers has a dedicated format, called FlexBuffers.
|
||||||
|
This is a binary format that can be used in conjunction
|
||||||
|
with FlatBuffers (by storing a part of a buffer in FlexBuffers
|
||||||
|
format), or also as its own independent serialization format.
|
||||||
|
|
||||||
|
While it loses the strong typing, you retain the most unique advantage
|
||||||
|
FlatBuffers has over other serialization formats (schema-based or not):
|
||||||
|
FlexBuffers can also be accessed without parsing / copying / object allocation.
|
||||||
|
This is a huge win in efficiency / memory friendly-ness, and allows unique
|
||||||
|
use cases such as mmap-ing large amounts of free-form data.
|
||||||
|
|
||||||
|
FlexBuffers' design and implementation allows for a very compact encoding,
|
||||||
|
combining automatic pooling of strings with automatic sizing of containers to
|
||||||
|
their smallest possible representation (8/16/32/64 bits). Many values and
|
||||||
|
offsets can be encoded in just 8 bits. While a schema-less representation is
|
||||||
|
usually more bulky because of the need to be self-descriptive, FlexBuffers
|
||||||
|
generates smaller binaries for many cases than regular FlatBuffers.
|
||||||
|
|
||||||
|
FlexBuffers is still slower than regular FlatBuffers though, so we recommend to
|
||||||
|
only use it if you need it.
|
||||||
|
|
||||||
|
|
||||||
|
# Usage
|
||||||
|
|
||||||
|
This is for C++, other languages may follow.
|
||||||
|
|
||||||
|
Include the header `flexbuffers.h`, which in turn depends on `flatbuffers.h`
|
||||||
|
and `util.h`.
|
||||||
|
|
||||||
|
To create a buffer:
|
||||||
|
|
||||||
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
|
||||||
|
flexbuffers::Builder fbb;
|
||||||
|
fbb.Int(13);
|
||||||
|
fbb.Finish();
|
||||||
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
|
You create any value, followed by `Finish`. Unlike FlatBuffers which requires
|
||||||
|
the root value to be a table, here any value can be the root, including a lonely
|
||||||
|
int value.
|
||||||
|
|
||||||
|
You can now access the `std::vector<uint8_t>` that contains the encoded value
|
||||||
|
as `fbb.GetBuffer()`. Write it, send it, or store it in a parent FlatBuffer. In
|
||||||
|
this case, the buffer is just 3 bytes in size.
|
||||||
|
|
||||||
|
To read this value back, you could just say:
|
||||||
|
|
||||||
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
|
||||||
|
auto root = flexbuffers::GetRoot(my_buffer);
|
||||||
|
int64_t i = root.AsInt64();
|
||||||
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
|
FlexBuffers stores ints only as big as needed, so it doesn't differentiate
|
||||||
|
between different sizes of ints. You can ask for the 64 bit version,
|
||||||
|
regardless of what you put in. In fact, since you demand to read the root
|
||||||
|
as an int, if you supply a buffer that actually contains a float, or a
|
||||||
|
string with numbers in it, it will convert it for you on the fly as well,
|
||||||
|
or return 0 if it can't. If instead you actually want to know what is inside
|
||||||
|
the buffer before you access it, you can call `root.GetType()` or `root.IsInt()`
|
||||||
|
etc.
|
||||||
|
|
||||||
|
Here's a slightly more complex value you could write instead of `fbb.Int` above:
|
||||||
|
|
||||||
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
|
||||||
|
fbb.Map([&]() {
|
||||||
|
fbb.Vector("vec", [&]() {
|
||||||
|
fbb.Int(-100);
|
||||||
|
fbb.String("Fred");
|
||||||
|
fbb.IndirectFloat(4.0f);
|
||||||
|
});
|
||||||
|
fbb.UInt("foo", 100);
|
||||||
|
});
|
||||||
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
|
This stores the equivalent of the JSON value
|
||||||
|
`{ vec: [ -100, "Fred", 4.0 ], foo: 100 }`. The root is a dictionary that has
|
||||||
|
just two key-value pairs, with keys `vec` and `foo`. Unlike FlatBuffers, it
|
||||||
|
actually has to store these keys in the buffer (which it does only once if
|
||||||
|
you store multiple such objects, by pooling key values), but also unlike
|
||||||
|
FlatBuffers it has no restriction on the keys (fields) that you use.
|
||||||
|
|
||||||
|
The map constructor uses a C++11 Lambda to group its children, but you can
|
||||||
|
also use more conventional start/end calls if you prefer.
|
||||||
|
|
||||||
|
The first value in the map is a vector. You'll notice that unlike FlatBuffers,
|
||||||
|
you can use mixed types. There is also a `TypedVector` variant that only
|
||||||
|
allows a single type, and uses a bit less memory.
|
||||||
|
|
||||||
|
`IndirectFloat` is an interesting feature that allows you to store values
|
||||||
|
by offset rather than inline. Though that doesn't make any visible change
|
||||||
|
to the user, the consequence is that large values (especially doubles or
|
||||||
|
64 bit ints) that occur more than once can be shared. Another use case is
|
||||||
|
inside of vectors, where the largest element makes up the size of all elements
|
||||||
|
(e.g. a single double forces all elements to 64bit), so storing a lot of small
|
||||||
|
integers together with a double is more efficient if the double is indirect.
|
||||||
|
|
||||||
|
Accessing it:
|
||||||
|
|
||||||
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
|
||||||
|
auto map = flexbuffers::GetRoot(my_buffer).AsMap();
|
||||||
|
map.size(); // 2
|
||||||
|
auto vec = map["vec"].AsVector();
|
||||||
|
vec.size(); // 3
|
||||||
|
vec[0].AsInt64(); // -100;
|
||||||
|
vec[1].AsString().c_str(); // "Fred";
|
||||||
|
vec[1].AsInt64(); // 0 (Number parsing failed).
|
||||||
|
vec[2].AsDouble(); // 4.0
|
||||||
|
vec[2].AsString().IsTheEmptyString(); // true (Wrong Type).
|
||||||
|
vec[2].AsString().c_str(); // "" (This still works though).
|
||||||
|
vec[2].ToString().c_str(); // "4" (Or have it converted).
|
||||||
|
map["foo"].AsUInt8(); // 100
|
||||||
|
map["unknown"].IsNull(); // true
|
||||||
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
|
|
||||||
|
# Binary encoding
|
||||||
|
|
||||||
|
A description of how FlexBuffers are encoded is in the
|
||||||
|
[internals](@ref flatbuffers_internals) document.
|
||||||
|
|
||||||
|
|
||||||
|
# Efficiency tips
|
||||||
|
|
||||||
|
* Vectors generally are a lot more efficient than maps, so prefer them over maps
|
||||||
|
when possible for small objects. Instead of a map with keys `x`, `y` and `z`,
|
||||||
|
use a vector. Better yet, use a typed vector. Or even better, use a fixed
|
||||||
|
size typed vector.
|
||||||
|
* Maps are backwards compatible with vectors, and can be iterated as such.
|
||||||
|
You can iterate either just the values (`map.Values()`), or in parallel with
|
||||||
|
the keys vector (`map.Keys()`). If you intend
|
||||||
|
to access most or all elements, this is faster than looking up each element
|
||||||
|
by key, since that involves a binary search of the key vector.
|
||||||
|
* When possible, don't mix values that require a big bit width (such as double)
|
||||||
|
in a large vector of smaller values, since all elements will take on this
|
||||||
|
width. Use `IndirectDouble` when this is a possibility. Note that
|
||||||
|
integers automatically use the smallest width possible, i.e. if you ask
|
||||||
|
to serialize an int64_t whose value is actually small, you will use less
|
||||||
|
bits. Doubles are represented as floats whenever possible losslessly, but
|
||||||
|
this is only possible for few values.
|
||||||
|
Since nested vectors/maps are stored over offsets, they typically don't
|
||||||
|
affect the vector width.
|
||||||
|
* To store large arrays of byte data, use a blob. If you'd use a typed
|
||||||
|
vector, the bit width of the size field may make it use more space than
|
||||||
|
expected, and may not be compatible with `memcpy`.
|
||||||
|
Similarly, large arrays of (u)int16_t may be better off stored as a
|
||||||
|
binary blob if their size could exceed 64k elements.
|
||||||
|
Construction and use are otherwise similar to strings.
|
||||||
@@ -67,6 +67,29 @@ Now you can access values like this:
|
|||||||
pos := monster.Pos(nil)
|
pos := monster.Pos(nil)
|
||||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
|
|
||||||
|
In some cases it's necessary to modify values in an existing FlatBuffer in place (without creating a copy). For this reason, scalar fields of a Flatbuffer table or struct can be mutated.
|
||||||
|
|
||||||
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.go}
|
||||||
|
monster := example.GetRootAsMonster(buf, 0)
|
||||||
|
|
||||||
|
// Set table field.
|
||||||
|
if ok := monster.MutateHp(10); !ok {
|
||||||
|
panic("failed to mutate Hp")
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set struct field.
|
||||||
|
monster.Pos().MutateZ(4)
|
||||||
|
|
||||||
|
// This mutation will fail because the mana field is not available in
|
||||||
|
// the buffer. It should be set when creating the buffer.
|
||||||
|
if ok := monster.MutateMana(20); !ok {
|
||||||
|
panic("failed to mutate Hp")
|
||||||
|
}
|
||||||
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
|
The term `mutate` is used instead of `set` to indicate that this is a special use case. All mutate functions return a boolean value which is false if the field we're trying to mutate is not available in the buffer.
|
||||||
|
|
||||||
## Text Parsing
|
## Text Parsing
|
||||||
|
|
||||||
There currently is no support for parsing text (Schema's and JSON) directly
|
There currently is no support for parsing text (Schema's and JSON) directly
|
||||||
|
|||||||
@@ -292,4 +292,148 @@ flexibility in which of the children of root object to write first (though in
|
|||||||
this case there's only one string), and what order to write the fields in.
|
this case there's only one string), and what order to write the fields in.
|
||||||
Different orders may also cause different alignments to happen.
|
Different orders may also cause different alignments to happen.
|
||||||
|
|
||||||
|
# FlexBuffers
|
||||||
|
|
||||||
|
The [schema-less](@ref flexbuffers) version of FlatBuffers have their
|
||||||
|
own encoding, detailed here.
|
||||||
|
|
||||||
|
It shares many properties mentioned above, in that all data is accessed
|
||||||
|
over offsets, all scalars are aligned to their own size, and
|
||||||
|
all data is always stored in little endian format.
|
||||||
|
|
||||||
|
One difference is that FlexBuffers are built front to back, so children are
|
||||||
|
stored before parents, and the root of the data starts at the last byte.
|
||||||
|
|
||||||
|
Another difference is that scalar data is stored with a variable number of bits
|
||||||
|
(8/16/32/64). The current width is always determined by the *parent*, i.e. if
|
||||||
|
the scalar sits in a vector, the vector determines the bit width for all
|
||||||
|
elements at once. Selecting the minimum bit width for a particular vector is
|
||||||
|
something the encoder does automatically and thus is typically of no concern
|
||||||
|
to the user, though being aware of this feature (and not sticking a double in
|
||||||
|
the same vector as a bunch of byte sized elements) is helpful for efficiency.
|
||||||
|
|
||||||
|
Unlike FlatBuffers there is only one kind of offset, and that is an unsigned
|
||||||
|
integer indicating the number of bytes in a negative direction from the address
|
||||||
|
of itself (where the offset is stored).
|
||||||
|
|
||||||
|
### Vectors
|
||||||
|
|
||||||
|
The representation of the vector is at the core of how FlexBuffers works (since
|
||||||
|
maps are really just a combination of 2 vectors), so it is worth starting there.
|
||||||
|
|
||||||
|
As mentioned, a vector is governed by a single bit width (supplied by its
|
||||||
|
parent). This includes the size field. For example, a vector that stores the
|
||||||
|
integer values `1, 2, 3` is encoded as follows:
|
||||||
|
|
||||||
|
uint8_t 3, 1, 2, 3, 4, 4, 4
|
||||||
|
|
||||||
|
The first `3` is the size field, and is placed before the vector (an offset
|
||||||
|
from the parent to this vector points to the first element, not the size
|
||||||
|
field, so the size field is effectively at index -1).
|
||||||
|
Since this is an untyped vector `SL_VECTOR`, it is followed by 3 type
|
||||||
|
bytes (one per element of the vector), which are always following the vector,
|
||||||
|
and are always a uint8_t even if the vector is made up of bigger scalars.
|
||||||
|
|
||||||
|
### Types
|
||||||
|
|
||||||
|
A type byte is made up of 2 components (see flexbuffers.h for exact values):
|
||||||
|
|
||||||
|
* 2 lower bits representing the bit-width of the child (8, 16, 32, 64).
|
||||||
|
This is only used if the child is accessed over an offset, such as a child
|
||||||
|
vector. It is ignored for inline types.
|
||||||
|
* 6 bits representing the actual type (see flexbuffers.h).
|
||||||
|
|
||||||
|
Thus, in this example `4` means 8 bit child (value 0, unused, since the value is
|
||||||
|
in-line), type `SL_INT` (value 1).
|
||||||
|
|
||||||
|
### Typed Vectors
|
||||||
|
|
||||||
|
These are like the Vectors above, but omit the type bytes. The type is instead
|
||||||
|
determined by the vector type supplied by the parent. Typed vectors are only
|
||||||
|
available for a subset of types for which these savings can be significant,
|
||||||
|
namely inline signed/unsigned integers (`TYPE_VECTOR_INT` / `TYPE_VECTOR_UINT`),
|
||||||
|
floats (`TYPE_VECTOR_FLOAT`), and keys (`TYPE_VECTOR_KEY`, see below).
|
||||||
|
|
||||||
|
Additionally, for scalars, there are fixed length vectors of sizes 2 / 3 / 4
|
||||||
|
that don't store the size (`TYPE_VECTOR_INT2` etc.), for an additional savings
|
||||||
|
in space when storing common vector or color data.
|
||||||
|
|
||||||
|
### Scalars
|
||||||
|
|
||||||
|
FlexBuffers supports integers (`TYPE_INT` and `TYPE_UINT`) and floats
|
||||||
|
(`TYPE_FLOAT`), available in the bit-widths mentioned above. They can be stored
|
||||||
|
both inline and over an offset (`TYPE_INDIRECT_*`).
|
||||||
|
|
||||||
|
The offset version is useful to encode costly 64bit (or even 32bit) quantities
|
||||||
|
into vectors / maps of smaller sizes, and to share / repeat a value multiple
|
||||||
|
times.
|
||||||
|
|
||||||
|
### Blobs, Strings and Keys.
|
||||||
|
|
||||||
|
A blob (`TYPE_BLOB`) is encoded similar to a vector, with one difference: the
|
||||||
|
elements are always `uint8_t`. The parent bit width only determines the width of
|
||||||
|
the size field, allowing blobs to be large without the elements being large.
|
||||||
|
|
||||||
|
Strings (`TYPE_STRING`) are similar to blobs, except they have an additional 0
|
||||||
|
termination byte for convenience, and they MUST be UTF-8 encoded (since an
|
||||||
|
accessor in a language that does not support pointers to UTF-8 data may have to
|
||||||
|
convert them to a native string type).
|
||||||
|
|
||||||
|
A "Key" (`TYPE_KEY`) is similar to a string, but doesn't store the size
|
||||||
|
field. They're so named because they are used with maps, which don't care
|
||||||
|
for the size, and can thus be even more compact. Unlike strings, keys cannot
|
||||||
|
contain bytes of value 0 as part of their data (size can only be determined by
|
||||||
|
`strlen`), so while you can use them outside the context of maps if you so
|
||||||
|
desire, you're usually better off with strings.
|
||||||
|
|
||||||
|
### Maps
|
||||||
|
|
||||||
|
A map (`TYPE_MAP`) is like an (untyped) vector, but with 2 prefixes before the
|
||||||
|
size field:
|
||||||
|
|
||||||
|
| index | field |
|
||||||
|
| ----: | :----------------------------------------------------------- |
|
||||||
|
| -3 | An offset to the keys vector (may be shared between tables). |
|
||||||
|
| -2 | Byte width of the keys vector. |
|
||||||
|
| -1 | Size (from here on it is compatible with `TYPE_VECTOR`) |
|
||||||
|
| 0 | Elements. |
|
||||||
|
| Size | Types. |
|
||||||
|
|
||||||
|
Since a map is otherwise the same as a vector, it can be iterated like
|
||||||
|
a vector (which is probably faster than lookup by key).
|
||||||
|
|
||||||
|
The keys vector is a typed vector of keys. Both the keys and corresponding
|
||||||
|
values *have* to be stored in sorted order (as determined by `strcmp`), such
|
||||||
|
that lookups can be made using binary search.
|
||||||
|
|
||||||
|
The reason the key vector is a seperate structure from the value vector is
|
||||||
|
such that it can be shared between multiple value vectors, and also to
|
||||||
|
allow it to be treated as its own indivual vector in code.
|
||||||
|
|
||||||
|
An example map { foo: 13, bar: 14 } would be encoded as:
|
||||||
|
|
||||||
|
0 : uint8_t 'f', 'o', 'o', 0
|
||||||
|
4 : uint8_t 'b', 'a', 'r', 0
|
||||||
|
8 : uint8_t 2 // key vector of size 2
|
||||||
|
// key vector offset points here
|
||||||
|
9 : uint8_t 9, 6 // offsets to foo_key and bar_key
|
||||||
|
11: uint8_t 3, 1 // offset to key vector, and its byte width
|
||||||
|
13: uint8_t 2 // value vector of size
|
||||||
|
// value vector offset points here
|
||||||
|
14: uint8_t 13, 14 // values
|
||||||
|
16: uint8_t 4, 4 // types
|
||||||
|
|
||||||
|
### The root
|
||||||
|
|
||||||
|
As mentioned, the root starts at the end of the buffer.
|
||||||
|
The last uint8_t is the width in bytes of the root (normally the parent
|
||||||
|
determines the width, but the root has no parent). The uint8_t before this is
|
||||||
|
the type of the root, and the bytes before that are the root value (of the
|
||||||
|
number of bytes specified by the last byte).
|
||||||
|
|
||||||
|
So for example, the integer value `13` as root would be:
|
||||||
|
|
||||||
|
uint8_t 13, 4, 1 // Value, type, root byte width.
|
||||||
|
|
||||||
|
|
||||||
<br>
|
<br>
|
||||||
|
|||||||
@@ -131,6 +131,36 @@ object are prefixed with `Get`, e.g.:
|
|||||||
monster.GetPos(preconstructedPos);
|
monster.GetPos(preconstructedPos);
|
||||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
|
## Storing dictionaries in a FlatBuffer
|
||||||
|
|
||||||
|
FlatBuffers doesn't support dictionaries natively, but there is support to
|
||||||
|
emulate their behavior with vectors and binary search, which means you
|
||||||
|
can have fast lookups directly from a FlatBuffer without having to unpack
|
||||||
|
your data into a `Dictionary` or similar.
|
||||||
|
|
||||||
|
To use it:
|
||||||
|
- Designate one of the fields in a table as they "key" field. You do this
|
||||||
|
by setting the `key` attribute on this field, e.g.
|
||||||
|
`name:string (key)`.
|
||||||
|
You may only have one key field, and it must be of string or scalar type.
|
||||||
|
- Write out tables of this type as usual, collect their offsets in an
|
||||||
|
array.
|
||||||
|
- Instead of calling standard generated method,
|
||||||
|
e.g.: `Monster.createTestarrayoftablesVector`,
|
||||||
|
call `CreateMySortedVectorOfTables` in C# or
|
||||||
|
`createSortedVectorOfTables` (from the `FlatBufferBuilder` object) in Java,
|
||||||
|
which will first sort all offsets such that the tables they refer to
|
||||||
|
are sorted by the key field, then serialize it.
|
||||||
|
- Now when you're accessing the FlatBuffer, you can use `LookupByKey`
|
||||||
|
to access elements of the vector, e.g.:
|
||||||
|
`Monster.lookupByKey(tablesVectorOffset, "Frodo", dataBuffer)`,
|
||||||
|
which returns an object of the corresponding table type,
|
||||||
|
or `null` if not found.
|
||||||
|
`LookupByKey` performs a binary search, so should have a similar speed to
|
||||||
|
`Dictionary`, though may be faster because of better caching. `LookupByKey`
|
||||||
|
only works if the vector has been sorted, it will likely not find elements
|
||||||
|
if it hasn't been sorted.
|
||||||
|
|
||||||
## Text parsing
|
## Text parsing
|
||||||
|
|
||||||
There currently is no support for parsing text (Schema's and JSON) directly
|
There currently is no support for parsing text (Schema's and JSON) directly
|
||||||
|
|||||||
@@ -122,7 +122,8 @@ default to `NULL` when not present.
|
|||||||
|
|
||||||
You generally do not want to change default values after they're initially
|
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
|
defined. Fields that have the default value are not actually stored in the
|
||||||
serialized data but are generated in code, so when you change the default, you'd
|
serialized data (see also Gotchas below) but are generated in code,
|
||||||
|
so when you change the default, you'd
|
||||||
now get a different value than from code generated from an older version of
|
now get a different value than from code generated from an older version of
|
||||||
the schema. There are situations, however, where this may be
|
the schema. There are situations, however, where this may be
|
||||||
desirable, especially if you can ensure a simultaneous rebuild of
|
desirable, especially if you can ensure a simultaneous rebuild of
|
||||||
@@ -157,6 +158,10 @@ 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
|
open-ended way, for example for use as files, see the file identification
|
||||||
feature below.
|
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.
|
||||||
|
|
||||||
### Namespaces
|
### Namespaces
|
||||||
|
|
||||||
These will generate the corresponding namespace in C++ for all helper
|
These will generate the corresponding namespace in C++ for all helper
|
||||||
@@ -224,6 +229,21 @@ This declaration in the schema will change that to whatever you want:
|
|||||||
|
|
||||||
file_extension "ext";
|
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
|
### Comments & documentation
|
||||||
|
|
||||||
May be written as in most C-based languages. Additionally, a triple
|
May be written as in most C-based languages. Additionally, a triple
|
||||||
@@ -256,7 +276,7 @@ Current understood attributes:
|
|||||||
the union field should have id 8, and the unions type field will
|
the union field should have id 8, and the unions type field will
|
||||||
implicitly be 7.
|
implicitly be 7.
|
||||||
IDs allow the fields to be placed in any order in the schema.
|
IDs allow the fields to be placed in any order in the schema.
|
||||||
When a new field is added to the schema is must use the next available ID.
|
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
|
- `deprecated` (on a field): do not generate accessors for this field
|
||||||
anymore, code should stop using this data.
|
anymore, code should stop using this data.
|
||||||
- `required` (on a non-scalar table field): this field must always be set.
|
- `required` (on a non-scalar table field): this field must always be set.
|
||||||
@@ -269,9 +289,6 @@ Current understood attributes:
|
|||||||
code may access it directly, without checking for NULL. If the constructing
|
code may access it directly, without checking for NULL. If the constructing
|
||||||
code does not initialize this field, they will get an assert, and also
|
code does not initialize this field, they will get an assert, and also
|
||||||
the verifier will fail on buffers that have missing required fields.
|
the verifier will fail on buffers that have missing required fields.
|
||||||
- `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.
|
|
||||||
- `force_align: size` (on a struct): force the alignment of this struct
|
- `force_align: size` (on a struct): force the alignment of this struct
|
||||||
to be something higher than what it is naturally aligned to. Causes
|
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
|
these structs to be aligned to that amount inside a buffer, IF that
|
||||||
@@ -288,6 +305,18 @@ Current understood attributes:
|
|||||||
- `key` (on a field): this field is meant to be used as a key when sorting
|
- `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
|
a vector of the type of table it sits in. Can be used for in-place
|
||||||
binary search.
|
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
|
## JSON Parsing
|
||||||
|
|
||||||
@@ -318,6 +347,10 @@ JSON:
|
|||||||
- A field that has the value `null` (e.g. `field: null`) is intended to
|
- 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
|
have the default value for that field (thus has the same effect as if
|
||||||
that field wasn't specified at all).
|
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:
|
When parsing JSON, it recognizes the following escape codes in strings:
|
||||||
|
|
||||||
@@ -339,6 +372,66 @@ When parsing JSON, it recognizes the following escape codes in strings:
|
|||||||
It also generates these escape codes back again when generating JSON from a
|
It also generates these escape codes back again when generating JSON from a
|
||||||
binary representation.
|
binary representation.
|
||||||
|
|
||||||
|
## 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
|
||||||
|
truely 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 optional 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
|
## Gotchas
|
||||||
|
|
||||||
### Schemas and version control
|
### Schemas and version control
|
||||||
@@ -425,4 +518,28 @@ incompatible with the actual binary buffers, since those only ever address
|
|||||||
fields by id/offset.
|
fields by id/offset.
|
||||||
<br>
|
<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.
|
||||||
|
|
||||||
|
In FlatBuffers, this also holds for everything except scalar values.
|
||||||
|
|
||||||
|
FlatBuffers by default will not write fields that are equal to the default
|
||||||
|
value (for scalars), sometimes resulting in a significant space savings.
|
||||||
|
|
||||||
|
However, this also means testing whether a field is "present" is somewhat
|
||||||
|
meaningless, since it does not tell you if the field was actually written by
|
||||||
|
calling `add_field` style calls, unless you're only interested in this
|
||||||
|
information for non-default values.
|
||||||
|
|
||||||
|
Some `FlatBufferBuilder` implementations have an option called `force_defaults`
|
||||||
|
that circumvents this behavior, and writes fields even if they are equal to
|
||||||
|
the default. You can then use `IsFieldPresent` to query this.
|
||||||
|
|
||||||
|
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. The cool thing
|
||||||
|
is that structs don't take up any more space than the scalar they represent.
|
||||||
|
|
||||||
[Interface Definition Language]: https://en.wikipedia.org/wiki/Interface_description_language
|
[Interface Definition Language]: https://en.wikipedia.org/wiki/Interface_description_language
|
||||||
|
|||||||
@@ -18,23 +18,23 @@ In general:
|
|||||||
|
|
||||||
NOTE: this table is a start, it needs to be extended.
|
NOTE: this table is a start, it needs to be extended.
|
||||||
|
|
||||||
Feature | C++ | Java | C# | Go | Python | JS | C | PHP | Ruby
|
Feature | C++ | Java | C# | Go | Python | JS | C | PHP | Ruby
|
||||||
------------------------------ | ------ | ------ | ------ | ------ | ------ | --------- | ---- | --- | ----
|
------------------------------ | ------ | ------ | ------ | ------ | ------ | --------- | ------ | --- | ----
|
||||||
Codegen for all basic features | Yes | Yes | Yes | Yes | Yes | Yes | WiP | WiP | WiP
|
Codegen for all basic features | Yes | Yes | Yes | Yes | Yes | Yes | Yes | WiP | WiP
|
||||||
JSON parsing | Yes | No | No | No | No | No | No | No | No
|
JSON parsing | Yes | No | No | No | No | No | Yes | No | No
|
||||||
Simple mutation | Yes | WIP | WIP | No | No | No | No | No | No
|
Simple mutation | Yes | WIP | WIP | No | No | No | No | No | No
|
||||||
Reflection | Yes | No | No | No | No | No | No | No | No
|
Reflection | Yes | No | No | No | No | No | Basic | No | No
|
||||||
Buffer verifier | Yes | No | No | No | No | No | No | No | No
|
Buffer verifier | Yes | No | No | No | No | No | Yes | No | No
|
||||||
Testing: basic | Yes | Yes | Yes | Yes | Yes | Yes | ? | ? | ?
|
Testing: basic | Yes | Yes | Yes | Yes | Yes | Yes | Yes | ? | ?
|
||||||
Testing: fuzz | Yes | No | No | Yes | Yes | No | ? | ? | ?
|
Testing: fuzz | Yes | No | No | Yes | Yes | No | No | ? | ?
|
||||||
Performance: | Superb | Great | Great | Great | Ok | ? |Superb| ? | ?
|
Performance: | Superb | Great | Great | Great | Ok | ? | Superb | ? | ?
|
||||||
Platform: Windows | VS2010 | Yes | Yes | ? | ? | ? | ? | ? | ?
|
Platform: Windows | VS2010 | Yes | Yes | ? | ? | ? | VS2010 | ? | ?
|
||||||
Platform: Linux | GCC282 | Yes | ? | Yes | Yes | ? | ? | ? | ?
|
Platform: Linux | GCC282 | Yes | ? | Yes | Yes | ? | Yes | ? | ?
|
||||||
Platform: OS X | Xcode4 | ? | ? | ? | Yes | ? | ? | ? | ?
|
Platform: OS X | Xcode4 | ? | ? | ? | Yes | ? | Yes | ? | ?
|
||||||
Platform: Android | NDK10d | Yes | ? | ? | ? | ? | ? | ? | ?
|
Platform: Android | NDK10d | Yes | ? | ? | ? | ? | ? | ? | ?
|
||||||
Platform: iOS | ? | ? | ? | ? | ? | ? | ? | ? | ?
|
Platform: iOS | ? | ? | ? | ? | ? | ? | ? | ? | ?
|
||||||
Engine: Unity | ? | ? | Yes | ? | ? | ? | ? | ? | ?
|
Engine: Unity | ? | ? | Yes | ? | ? | ? | ? | ? | ?
|
||||||
Primary authors (github) | gwvo | gwvo | ev*/js*| rw | rw | evanw/ev* | mik* | ch* | rw
|
Primary authors (github) | gwvo | gwvo | ev*/js*| rw | rw | evanw/ev* | mik* | ch* | rw
|
||||||
|
|
||||||
* ev = evolutional
|
* ev = evolutional
|
||||||
* js = jonsimantov
|
* js = jonsimantov
|
||||||
|
|||||||
@@ -19,7 +19,6 @@ character, the hero of the story, needs to slay some `orc`s. We will walk
|
|||||||
through each step necessary to create this monster type using FlatBuffers.
|
through each step necessary to create this monster type using FlatBuffers.
|
||||||
|
|
||||||
Please select your desired language for our quest:
|
Please select your desired language for our quest:
|
||||||
|
|
||||||
\htmlonly
|
\htmlonly
|
||||||
<form>
|
<form>
|
||||||
<input type="radio" name="language" value="cpp" checked="checked">C++</input>
|
<input type="radio" name="language" value="cpp" checked="checked">C++</input>
|
||||||
@@ -29,6 +28,7 @@ Please select your desired language for our quest:
|
|||||||
<input type="radio" name="language" value="python">Python</input>
|
<input type="radio" name="language" value="python">Python</input>
|
||||||
<input type="radio" name="language" value="javascript">JavaScript</input>
|
<input type="radio" name="language" value="javascript">JavaScript</input>
|
||||||
<input type="radio" name="language" value="php">PHP</input>
|
<input type="radio" name="language" value="php">PHP</input>
|
||||||
|
<input type="radio" name="language" value="c">C</input>
|
||||||
</form>
|
</form>
|
||||||
\endhtmlonly
|
\endhtmlonly
|
||||||
|
|
||||||
@@ -98,6 +98,10 @@ Samples demonstating the concepts in this example are located in the source code
|
|||||||
package, under the `samples` directory. You can browse the samples on GitHub
|
package, under the `samples` directory. You can browse the samples on GitHub
|
||||||
[here](https://github.com/google/flatbuffers/tree/master/samples).
|
[here](https://github.com/google/flatbuffers/tree/master/samples).
|
||||||
|
|
||||||
|
<div class="language-c">
|
||||||
|
*Note: The above does not apply to C, instead [look here](https://github.com/dvidelabs/flatcc/tree/master/samples).*
|
||||||
|
</div>
|
||||||
|
|
||||||
For your chosen language, please cross-reference with:
|
For your chosen language, please cross-reference with:
|
||||||
|
|
||||||
<div class="language-cpp">
|
<div class="language-cpp">
|
||||||
@@ -121,6 +125,9 @@ For your chosen language, please cross-reference with:
|
|||||||
<div class="language-php">
|
<div class="language-php">
|
||||||
[SampleBinary.php](https://github.com/google/flatbuffers/blob/master/samples/SampleBinary.php)
|
[SampleBinary.php](https://github.com/google/flatbuffers/blob/master/samples/SampleBinary.php)
|
||||||
</div>
|
</div>
|
||||||
|
<div class="language-c">
|
||||||
|
[monster.c](https://github.com/dvidelabs/flatcc/blob/master/samples/monster/monster.c)
|
||||||
|
</div>
|
||||||
|
|
||||||
## Writing the Monsters' FlatBuffer Schema
|
## Writing the Monsters' FlatBuffer Schema
|
||||||
|
|
||||||
@@ -225,6 +232,15 @@ FlatBuffer compiler.
|
|||||||
|
|
||||||
Once `flatc` is built successfully, compile the schema for your language:
|
Once `flatc` is built successfully, compile the schema for your language:
|
||||||
|
|
||||||
|
<div class="language-c">
|
||||||
|
*Note: If you're working in C, you need to use the separate project [FlatCC](https://github.com/dvidelabs/flatcc) which contains a schema compiler and runtime library in C for C.*
|
||||||
|
<br>
|
||||||
|
See [flatcc build instructions](https://github.com/dvidelabs/flatcc#building).
|
||||||
|
<br>
|
||||||
|
Please be aware of the difference between `flatc` and `flatcc` tools.
|
||||||
|
<br>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div class="language-cpp">
|
<div class="language-cpp">
|
||||||
~~~{.sh}
|
~~~{.sh}
|
||||||
cd flatbuffers/sample
|
cd flatbuffers/sample
|
||||||
@@ -267,8 +283,17 @@ Once `flatc` is built successfully, compile the schema for your language:
|
|||||||
./../flatc --php samples/monster.fbs
|
./../flatc --php samples/monster.fbs
|
||||||
~~~
|
~~~
|
||||||
</div>
|
</div>
|
||||||
|
<div class="language-c">
|
||||||
|
~~~{.sh}
|
||||||
|
cd flatcc
|
||||||
|
mkdir -p build/tmp/samples/monster
|
||||||
|
bin/flatcc -a -o build/tmp/samples/monster samples/monster/monster.fbs
|
||||||
|
# or just
|
||||||
|
flatcc/samples/monster/build.sh
|
||||||
|
~~~
|
||||||
|
</div>
|
||||||
|
|
||||||
For a more complete guide to using the `flatc` compiler, pleaes read the
|
For a more complete guide to using the `flatc` compiler, please read the
|
||||||
[Using the schema compiler](@ref flatbuffers_guide_using_schema_compiler)
|
[Using the schema compiler](@ref flatbuffers_guide_using_schema_compiler)
|
||||||
section of the Programmer's Guide.
|
section of the Programmer's Guide.
|
||||||
|
|
||||||
@@ -359,58 +384,79 @@ The first step is to import/include the library, generated files, etc.
|
|||||||
}
|
}
|
||||||
~~~
|
~~~
|
||||||
</div>
|
</div>
|
||||||
|
<div class="language-c">
|
||||||
|
~~~{.c}
|
||||||
|
#include "monster_builder.h" // Generated by `flatcc`.
|
||||||
|
|
||||||
|
// Convenient namespace macro to manage long namespace prefix.
|
||||||
|
#undef ns
|
||||||
|
#define ns(x) FLATBUFFERS_WRAP_NAMESPACE(MyGame_Sample, x) // Specified in the schema.
|
||||||
|
|
||||||
|
// A helper to simplify creating vectors from C-arrays.
|
||||||
|
#define c_vec_len(V) (sizeof(V)/sizeof((V)[0]))
|
||||||
|
~~~
|
||||||
|
</div>
|
||||||
|
|
||||||
Now we are ready to start building some buffers. In order to start, we need
|
Now we are ready to start building some buffers. In order to start, we need
|
||||||
to create an instance of the `FlatBufferBuilder`, which will contain the buffer
|
to create an instance of the `FlatBufferBuilder`, which will contain the buffer
|
||||||
as it grows:
|
as it grows. You can pass an initial size of the buffer (here 1024 bytes),
|
||||||
|
which will grow automatically if needed:
|
||||||
|
|
||||||
<div class="language-cpp">
|
<div class="language-cpp">
|
||||||
~~~{.cpp}
|
~~~{.cpp}
|
||||||
// Create a `FlatBufferBuilder`, which will be used to create our
|
// Create a `FlatBufferBuilder`, which will be used to create our
|
||||||
// monsters' FlatBuffers.
|
// monsters' FlatBuffers.
|
||||||
flatbuffers::FlatBufferBuilder builder;
|
flatbuffers::FlatBufferBuilder builder(1024);
|
||||||
~~~
|
~~~
|
||||||
</div>
|
</div>
|
||||||
<div class="language-java">
|
<div class="language-java">
|
||||||
~~~{.java}
|
~~~{.java}
|
||||||
// Create a `FlatBufferBuilder`, which will be used to create our
|
// Create a `FlatBufferBuilder`, which will be used to create our
|
||||||
// monsters' FlatBuffers.
|
// monsters' FlatBuffers.
|
||||||
FlatBufferBuilder builder = new FlatBufferBuilder(0);
|
FlatBufferBuilder builder = new FlatBufferBuilder(1024);
|
||||||
~~~
|
~~~
|
||||||
</div>
|
</div>
|
||||||
<div class="language-csharp">
|
<div class="language-csharp">
|
||||||
~~~{.cs}
|
~~~{.cs}
|
||||||
// Create a `FlatBufferBuilder`, which will be used to create our
|
// Create a `FlatBufferBuilder`, which will be used to create our
|
||||||
// monsters' FlatBuffers.
|
// monsters' FlatBuffers.
|
||||||
var builder = new FlatBufferBuilder(1);
|
var builder = new FlatBufferBuilder(1024);
|
||||||
~~~
|
~~~
|
||||||
</div>
|
</div>
|
||||||
<div class="language-go">
|
<div class="language-go">
|
||||||
~~~{.go}
|
~~~{.go}
|
||||||
// Create a `FlatBufferBuilder`, which will be used to create our
|
// Create a `FlatBufferBuilder`, which will be used to create our
|
||||||
// monsters' FlatBuffers.
|
// monsters' FlatBuffers.
|
||||||
builder := flatbuffers.NewBuilder(0)
|
builder := flatbuffers.NewBuilder(1024)
|
||||||
~~~
|
~~~
|
||||||
</div>
|
</div>
|
||||||
<div class="language-python">
|
<div class="language-python">
|
||||||
~~~{.py}
|
~~~{.py}
|
||||||
# Create a `FlatBufferBuilder`, which will be used to create our
|
# Create a `FlatBufferBuilder`, which will be used to create our
|
||||||
# monsters' FlatBuffers.
|
# monsters' FlatBuffers.
|
||||||
builder = flatbuffers.Builder(0)
|
builder = flatbuffers.Builder(1024)
|
||||||
~~~
|
~~~
|
||||||
</div>
|
</div>
|
||||||
<div class="language-javascript">
|
<div class="language-javascript">
|
||||||
~~~{.js}
|
~~~{.js}
|
||||||
// Create a `flatbuffer.Builder`, which will be used to create our
|
// Create a `flatbuffer.Builder`, which will be used to create our
|
||||||
// monsters' FlatBuffers.
|
// monsters' FlatBuffers.
|
||||||
var builder = new flatbuffers.Builder(1);
|
var builder = new flatbuffers.Builder(1024);
|
||||||
~~~
|
~~~
|
||||||
</div>
|
</div>
|
||||||
<div class="language-php">
|
<div class="language-php">
|
||||||
~~~{.php}
|
~~~{.php}
|
||||||
// Create a `FlatBufferBuilder`, which will be used to create our
|
// Create a `FlatBufferBuilder`, which will be used to create our
|
||||||
// monsters' FlatBuffers.
|
// monsters' FlatBuffers.
|
||||||
$builder = new Google\FlatBuffers\FlatbufferBuilder(0);
|
$builder = new Google\FlatBuffers\FlatbufferBuilder(1024);
|
||||||
|
~~~
|
||||||
|
</div>
|
||||||
|
<div class="language-c">
|
||||||
|
~~~{.c}
|
||||||
|
flatcc_builder_t builder, *B;
|
||||||
|
B = &builder;
|
||||||
|
// Initialize the builder object.
|
||||||
|
flatcc_builder_init(B);
|
||||||
~~~
|
~~~
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@@ -432,10 +478,10 @@ our `orc` Monster, lets create some `Weapon`s: a `Sword` and an `Axe`.
|
|||||||
</div>
|
</div>
|
||||||
<div class="language-java">
|
<div class="language-java">
|
||||||
~~~{.java}
|
~~~{.java}
|
||||||
String weaponOneName = builder.createString("Sword")
|
int weaponOneName = builder.createString("Sword")
|
||||||
short weaponOneDamage = 3;
|
short weaponOneDamage = 3;
|
||||||
|
|
||||||
String weaponTwoName = builder.createString("Axe");
|
int weaponTwoName = builder.createString("Axe");
|
||||||
short weaponTwoDamage = 5;
|
short weaponTwoDamage = 5;
|
||||||
|
|
||||||
// Use the `createWeapon()` helper function to create the weapons, since we set every field.
|
// Use the `createWeapon()` helper function to create the weapons, since we set every field.
|
||||||
@@ -525,6 +571,18 @@ our `orc` Monster, lets create some `Weapon`s: a `Sword` and an `Axe`.
|
|||||||
$weapons = \MyGame\Sample\Monster::CreateWeaponsVector($builder, $weaps);
|
$weapons = \MyGame\Sample\Monster::CreateWeaponsVector($builder, $weaps);
|
||||||
~~~
|
~~~
|
||||||
</div>
|
</div>
|
||||||
|
<div class="language-c">
|
||||||
|
~~~{.c}
|
||||||
|
ns(Weapon_ref_t) weapon_one_name = flatbuffers_string_create_str(B, "Sword");
|
||||||
|
uint16_t weapon_one_damage = 3;
|
||||||
|
|
||||||
|
ns(Weapon_ref_t) weapon_two_name = flatbuffers_string_create_str(B, "Axe");
|
||||||
|
uint16_t weapon_two_damage = 5;
|
||||||
|
|
||||||
|
ns(Weapon_ref_t) sword = ns(Weapon_create(B, weapon_one_name, weapon_one_damage));
|
||||||
|
ns(Weapon_ref_t) axe = ns(Weapon_create(B, weapon_two_name, weapon_two_damage));
|
||||||
|
~~~
|
||||||
|
</div>
|
||||||
|
|
||||||
Now let's create our monster, the `orc`. For this `orc`, lets make him
|
Now let's create our monster, the `orc`. For this `orc`, lets make him
|
||||||
`red` with rage, positioned at `(1.0, 2.0, 3.0)`, and give him
|
`red` with rage, positioned at `(1.0, 2.0, 3.0)`, and give him
|
||||||
@@ -627,6 +685,20 @@ traversal. This is generally easy to do on any tree structures.
|
|||||||
$inv = \MyGame\Sample\Monster::CreateInventoryVector($builder, $treasure);
|
$inv = \MyGame\Sample\Monster::CreateInventoryVector($builder, $treasure);
|
||||||
~~~
|
~~~
|
||||||
</div>
|
</div>
|
||||||
|
<div class="language-c">
|
||||||
|
~~~{.c}
|
||||||
|
// Serialize a name for our monster, called "Orc".
|
||||||
|
// The _str suffix indicates the source is an ascii-z string.
|
||||||
|
flatbuffers_string_ref_t name = flatbuffers_string_create_str(B, "Orc");
|
||||||
|
|
||||||
|
// Create a `vector` representing the inventory of the Orc. Each number
|
||||||
|
// could correspond to an item that can be claimed after he is slain.
|
||||||
|
uint8_t treasure[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
|
||||||
|
flatbuffers_uint8_vec_ref_t inventory;
|
||||||
|
// `c_vec_len` is the convenience macro we defined earlier.
|
||||||
|
inventory = flatbuffers_uint8_vec_create(B, treasure, c_vec_len(treasure));
|
||||||
|
~~~
|
||||||
|
</div>
|
||||||
|
|
||||||
We serialized two built-in data types (`string` and `vector`) and captured
|
We serialized two built-in data types (`string` and `vector`) and captured
|
||||||
their return values. These values are offsets into the serialized data,
|
their return values. These values are offsets into the serialized data,
|
||||||
@@ -656,8 +728,8 @@ offsets.
|
|||||||
// Place the two weapons into an array, and pass it to the `createWeaponsVector()` method to
|
// Place the two weapons into an array, and pass it to the `createWeaponsVector()` method to
|
||||||
// create a FlatBuffer vector.
|
// create a FlatBuffer vector.
|
||||||
int[] weaps = new int[2];
|
int[] weaps = new int[2];
|
||||||
weaps[1] = sword;
|
weaps[0] = sword;
|
||||||
weaps[2] = axe;
|
weaps[1] = axe;
|
||||||
|
|
||||||
// Pass the `weaps` array into the `createWeaponsVector()` method to create a FlatBuffer vector.
|
// Pass the `weaps` array into the `createWeaponsVector()` method to create a FlatBuffer vector.
|
||||||
int weapons = Monster.createWeaponsVector(builder, weaps);
|
int weapons = Monster.createWeaponsVector(builder, weaps);
|
||||||
@@ -709,50 +781,22 @@ offsets.
|
|||||||
$weapons = \MyGame\Sample\Monster::CreateWeaponsVector($builder, $weaps);
|
$weapons = \MyGame\Sample\Monster::CreateWeaponsVector($builder, $weaps);
|
||||||
~~~
|
~~~
|
||||||
</div>
|
</div>
|
||||||
|
<div class="language-c">
|
||||||
To create a `struct`, use the `Vec3` class/struct that was generated by `flatc`:
|
~~~{.c}
|
||||||
|
// We use the internal builder stack to implement a dynamic vector.
|
||||||
|
ns(Weapon_vec_start(B));
|
||||||
|
ns(Weapon_vec_push(B, sword));
|
||||||
|
ns(Weapon_vec_push(B, axe));
|
||||||
|
ns(Weapon_vec_ref_t) weapons = ns(Weapon_vec_end(B));
|
||||||
|
~~~
|
||||||
|
</div>
|
||||||
|
|
||||||
<div class="language-cpp">
|
<div class="language-cpp">
|
||||||
~~~{.cpp}
|
<br>
|
||||||
// Create a `Vec3`, representing the Orc's position in 3-D space.
|
Note there's additional convenience overloads of `CreateVector`, allowing you
|
||||||
auto pos = Vec3(1.0f, 2.0f, 3.0f);
|
to work with data that's not in a `std::vector`, or allowing you to generate
|
||||||
~~~
|
elements by calling a lambda. For the common case of `std::vector<std::string>`
|
||||||
</div>
|
there's also `CreateVectorOfStrings`.
|
||||||
<div class="language-java">
|
|
||||||
~~~{.java}
|
|
||||||
// Create a `Vec3`, representing the Orc's position in 3-D space.
|
|
||||||
int pos = Vec3.createVec3(builder, 1.0f, 2.0f, 3.0f);
|
|
||||||
~~~
|
|
||||||
</div>
|
|
||||||
<div class="language-csharp">
|
|
||||||
~~~{.cs}
|
|
||||||
// Create a `Vec3`, representing the Orc's position in 3-D space.
|
|
||||||
var pos = Vec3.CreateVec3(builder, 1.0f, 2.0f, 3.0f);
|
|
||||||
~~~
|
|
||||||
</div>
|
|
||||||
<div class="language-go">
|
|
||||||
~~~{.go}
|
|
||||||
// Create a `Vec3`, representing the Orc's position in 3-D space.
|
|
||||||
pos := sample.CreateVec3(builder, 1.0, 2.0, 3.0)
|
|
||||||
~~~
|
|
||||||
</div>
|
|
||||||
<div class="language-python">
|
|
||||||
~~~{.py}
|
|
||||||
# Create a `Vec3`, representing the Orc's position in 3-D space.
|
|
||||||
pos = MyGame.Sample.Vec3.CreateVec3(builder, 1.0, 2.0, 3.0)
|
|
||||||
~~~
|
|
||||||
</div>
|
|
||||||
<div class="language-javascript">
|
|
||||||
~~~{.js}
|
|
||||||
// Create a `Vec3`, representing the Orc's position in 3-D space.
|
|
||||||
var pos = MyGame.Sample.Vec3.createVec3(builder, 1.0, 2.0, 3.0);
|
|
||||||
~~~
|
|
||||||
</div>
|
|
||||||
<div class="language-php">
|
|
||||||
~~~{.js}
|
|
||||||
// Create a `Vec3`, representing the Orc's position in 3-D space.
|
|
||||||
$pos = \MyGame\Sample\Vec3::CreateVec3($builder, 1.0, 2.0, 3.0);
|
|
||||||
~~~
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
We have now serialized the non-scalar components of the orc, so we
|
We have now serialized the non-scalar components of the orc, so we
|
||||||
@@ -766,15 +810,16 @@ can serialize the monster itself:
|
|||||||
|
|
||||||
// Finally, create the monster using the `CreateMonster` helper function
|
// Finally, create the monster using the `CreateMonster` helper function
|
||||||
// to set all fields.
|
// to set all fields.
|
||||||
auto orc = CreateMonster(builder, &pos, mana, hp, name, inventory, Color_Red,
|
auto orc = CreateMonster(builder, Vec3(1.0f, 2.0f, 3.0f), mana, hp, name,
|
||||||
weapons, Equipment_Weapon, axe.Union());
|
inventory, Color_Red, weapons, Equipment_Weapon,
|
||||||
|
axe.Union());
|
||||||
~~~
|
~~~
|
||||||
</div>
|
</div>
|
||||||
<div class="language-java">
|
<div class="language-java">
|
||||||
~~~{.java}
|
~~~{.java}
|
||||||
// Create our monster using `startMonster()` and `endMonster()`.
|
// Create our monster using `startMonster()` and `endMonster()`.
|
||||||
Monster.startMonster(builder);
|
Monster.startMonster(builder);
|
||||||
Monster.addPos(builder, pos);
|
Monster.addPos(builder, Vec3.createVec3(builder, 1.0f, 2.0f, 3.0f));
|
||||||
Monster.addName(builder, name);
|
Monster.addName(builder, name);
|
||||||
Monster.addColor(builder, Color.Red);
|
Monster.addColor(builder, Color.Red);
|
||||||
Monster.addHp(builder, (short)300);
|
Monster.addHp(builder, (short)300);
|
||||||
@@ -789,7 +834,7 @@ can serialize the monster itself:
|
|||||||
~~~{.cs}
|
~~~{.cs}
|
||||||
// Create our monster using `StartMonster()` and `EndMonster()`.
|
// Create our monster using `StartMonster()` and `EndMonster()`.
|
||||||
Monster.StartMonster(builder);
|
Monster.StartMonster(builder);
|
||||||
Monster.AddPos(builder, pos);
|
Monster.AddPos(builder, Vec3.CreateVec3(builder, 1.0f, 2.0f, 3.0f));
|
||||||
Monster.AddHp(builder, (short)300);
|
Monster.AddHp(builder, (short)300);
|
||||||
Monster.AddName(builder, name);
|
Monster.AddName(builder, name);
|
||||||
Monster.AddInventory(builder, inv);
|
Monster.AddInventory(builder, inv);
|
||||||
@@ -804,7 +849,7 @@ can serialize the monster itself:
|
|||||||
~~~{.go}
|
~~~{.go}
|
||||||
// Create our monster using `MonsterStart()` and `MonsterEnd()`.
|
// Create our monster using `MonsterStart()` and `MonsterEnd()`.
|
||||||
sample.MonsterStart(builder)
|
sample.MonsterStart(builder)
|
||||||
sample.MonsterAddPos(builder, pos)
|
sample.MonsterAddPos(builder, sample.CreateVec3(builder, 1.0, 2.0, 3.0))
|
||||||
sample.MonsterAddHp(builder, 300)
|
sample.MonsterAddHp(builder, 300)
|
||||||
sample.MonsterAddName(builder, name)
|
sample.MonsterAddName(builder, name)
|
||||||
sample.MonsterAddInventory(builder, inv)
|
sample.MonsterAddInventory(builder, inv)
|
||||||
@@ -819,7 +864,8 @@ can serialize the monster itself:
|
|||||||
~~~{.py}
|
~~~{.py}
|
||||||
# Create our monster by using `MonsterStart()` and `MonsterEnd()`.
|
# Create our monster by using `MonsterStart()` and `MonsterEnd()`.
|
||||||
MyGame.Sample.Monster.MonsterStart(builder)
|
MyGame.Sample.Monster.MonsterStart(builder)
|
||||||
MyGame.Sample.Monster.MonsterAddPos(builder, pos)
|
MyGame.Sample.Monster.MonsterAddPos(builder,
|
||||||
|
MyGame.Sample.Vec3.CreateVec3(builder, 1.0, 2.0, 3.0))
|
||||||
MyGame.Sample.Monster.MonsterAddHp(builder, 300)
|
MyGame.Sample.Monster.MonsterAddHp(builder, 300)
|
||||||
MyGame.Sample.Monster.MonsterAddName(builder, name)
|
MyGame.Sample.Monster.MonsterAddName(builder, name)
|
||||||
MyGame.Sample.Monster.MonsterAddInventory(builder, inv)
|
MyGame.Sample.Monster.MonsterAddInventory(builder, inv)
|
||||||
@@ -836,7 +882,8 @@ can serialize the monster itself:
|
|||||||
~~~{.js}
|
~~~{.js}
|
||||||
// Create our monster by using `startMonster()` and `endMonster()`.
|
// Create our monster by using `startMonster()` and `endMonster()`.
|
||||||
MyGame.Sample.Monster.startMonster(builder);
|
MyGame.Sample.Monster.startMonster(builder);
|
||||||
MyGame.Sample.Monster.addPos(builder, pos);
|
MyGame.Sample.Monster.addPos(builder,
|
||||||
|
MyGame.Sample.Vec3.createVec3(builder, 1.0, 2.0, 3.0));
|
||||||
MyGame.Sample.Monster.addHp(builder, 300);
|
MyGame.Sample.Monster.addHp(builder, 300);
|
||||||
MyGame.Sample.Monster.addColor(builder, MyGame.Sample.Color.Red)
|
MyGame.Sample.Monster.addColor(builder, MyGame.Sample.Color.Red)
|
||||||
MyGame.Sample.Monster.addName(builder, name);
|
MyGame.Sample.Monster.addName(builder, name);
|
||||||
@@ -851,7 +898,8 @@ can serialize the monster itself:
|
|||||||
~~~{.php}
|
~~~{.php}
|
||||||
// Create our monster by using `StartMonster()` and `EndMonster()`.
|
// Create our monster by using `StartMonster()` and `EndMonster()`.
|
||||||
\MyGame\Sample\Monster::StartMonster($builder);
|
\MyGame\Sample\Monster::StartMonster($builder);
|
||||||
\MyGame\Sample\Monster::AddPos($builder, $pos);
|
\MyGame\Sample\Monster::AddPos($builder,
|
||||||
|
\MyGame\Sample\Vec3::CreateVec3($builder, 1.0, 2.0, 3.0));
|
||||||
\MyGame\Sample\Monster::AddHp($builder, 300);
|
\MyGame\Sample\Monster::AddHp($builder, 300);
|
||||||
\MyGame\Sample\Monster::AddName($builder, $name);
|
\MyGame\Sample\Monster::AddName($builder, $name);
|
||||||
\MyGame\Sample\Monster::AddInventory($builder, $inv);
|
\MyGame\Sample\Monster::AddInventory($builder, $inv);
|
||||||
@@ -862,16 +910,39 @@ can serialize the monster itself:
|
|||||||
$orc = \MyGame\Sample\Monster::EndMonster($builder);
|
$orc = \MyGame\Sample\Monster::EndMonster($builder);
|
||||||
~~~
|
~~~
|
||||||
</div>
|
</div>
|
||||||
|
<div class="language-c">
|
||||||
|
~~~{.c}
|
||||||
|
// Set his hit points to 300 and his mana to 150.
|
||||||
|
uint16_t hp = 300;
|
||||||
|
uint16_t mana = 150;
|
||||||
|
|
||||||
<div class="language-cpp">
|
// Define an equipment union. `create` calls in C has a single
|
||||||
<br>
|
// argument for unions where C++ has both a type and a data argument.
|
||||||
*Note: Since we passing `150` as the `mana` field, which happens to be the
|
ns(Equipment_union_ref_t) equipped = ns(Equipment_as_Weapon(axe));
|
||||||
|
ns(Vec3_t) pos = { 1.0f, 2.0f, 3.0f };
|
||||||
|
ns(Monster_create_as_root(B, &pos, mana, hp, name, inventory, ns(Color_Red),
|
||||||
|
weapons, equipped));
|
||||||
|
~~~
|
||||||
|
</div>
|
||||||
|
|
||||||
|
Note how we create `Vec3` struct in-line in the table. Unlike tables, structs
|
||||||
|
are simple combinations of scalars that are always stored inline, just like
|
||||||
|
scalars themselves.
|
||||||
|
|
||||||
|
**Important**: you should not nest tables or any other objects, which is why
|
||||||
|
we created all the strings/vectors/tables that this monster refers to before
|
||||||
|
`start`. If you try to create any of them between `start` and `end`, you
|
||||||
|
will get an assert/exception/panic depending on your language.
|
||||||
|
|
||||||
|
*Note: Since we are passing `150` as the `mana` field, which happens to be the
|
||||||
default value, the field will not actually be written to the buffer, since the
|
default value, the field will not actually be written to the buffer, since the
|
||||||
default value will be returned on query anyway. This is a nice space savings,
|
default value will be returned on query anyway. This is a nice space savings,
|
||||||
especially if default values are common in your data. It also means that you do
|
especially if default values are common in your data. It also means that you do
|
||||||
not need to be worried of adding a lot of fields that are only used in a small
|
not need to be worried of adding a lot of fields that are only used in a small
|
||||||
number of instances, as it will not bloat the buffer if unused.*
|
number of instances, as it will not bloat the buffer if unused.*
|
||||||
<br><br>
|
|
||||||
|
<div class="language-cpp">
|
||||||
|
<br>
|
||||||
If you do not wish to set every field in a `table`, it may be more convenient to
|
If you do not wish to set every field in a `table`, it may be more convenient to
|
||||||
manually set each field of your monster, instead of calling `CreateMonster()`.
|
manually set each field of your monster, instead of calling `CreateMonster()`.
|
||||||
The following snippet is functionally equivalent to the above code, but provides
|
The following snippet is functionally equivalent to the above code, but provides
|
||||||
@@ -892,6 +963,31 @@ a bit more flexibility.
|
|||||||
auto orc = monster_builder.Finish();
|
auto orc = monster_builder.Finish();
|
||||||
~~~
|
~~~
|
||||||
</div>
|
</div>
|
||||||
|
<div class="language-c">
|
||||||
|
If you do not wish to set every field in a `table`, it may be more convenient to
|
||||||
|
manually set each field of your monster, instead of calling `create_monster_as_root()`.
|
||||||
|
The following snippet is functionally equivalent to the above code, but provides
|
||||||
|
a bit more flexibility.
|
||||||
|
<br>
|
||||||
|
~~~{.c}
|
||||||
|
// It is important to pair `start_as_root` with `end_as_root`.
|
||||||
|
ns(Monster_start_as_root(B));
|
||||||
|
ns(Monster_pos_create(B, 1.0f, 2.0f, 3.0f));
|
||||||
|
// or alternatively
|
||||||
|
//ns(Monster_pos_add(&pos);
|
||||||
|
|
||||||
|
ns(Monster_hp_add(B, hp));
|
||||||
|
// Notice that `Monser_name_add` adds a string reference unlike the
|
||||||
|
// add_str and add_strn variants.
|
||||||
|
ns(Monster_name_add(B, name));
|
||||||
|
ns(Monster_inventory_add(B, inventory));
|
||||||
|
ns(Monster_color_add(B, ns(Color_Red)));
|
||||||
|
ns(Monster_weapons_add(B, weapons));
|
||||||
|
ns(Monster_equipped_add(B, equipped));
|
||||||
|
// Complete the monster object and make it the buffer root object.
|
||||||
|
ns(Monster_end_as_root(B));
|
||||||
|
~~~
|
||||||
|
</div>
|
||||||
|
|
||||||
Before finishing the serialization, let's take a quick look at FlatBuffer
|
Before finishing the serialization, let's take a quick look at FlatBuffer
|
||||||
`union Equipped`. There are two parts to each FlatBuffer `union`. The first, is
|
`union Equipped`. There are two parts to each FlatBuffer `union`. The first, is
|
||||||
@@ -947,11 +1043,18 @@ Here is a repetition these lines, to help highlight them more clearly:
|
|||||||
\MyGame\Sample\Monster::AddEquipped($builder, $axe); // Union data
|
\MyGame\Sample\Monster::AddEquipped($builder, $axe); // Union data
|
||||||
~~~
|
~~~
|
||||||
</div>
|
</div>
|
||||||
|
<div class="language-c">
|
||||||
|
~~~{.c}
|
||||||
|
// Add union type and data simultanously.
|
||||||
|
ns(Monster_equipped_Weapon_add(B, axe));
|
||||||
|
~~~
|
||||||
|
</div>
|
||||||
|
|
||||||
After you have created your buffer, you will have the offset to the root of the
|
After you have created your buffer, you will have the offset to the root of the
|
||||||
data in the `orc` variable, so you can finish the buffer by calling the
|
data in the `orc` variable, so you can finish the buffer by calling the
|
||||||
appropriate `finish` method.
|
appropriate `finish` method.
|
||||||
|
|
||||||
|
|
||||||
<div class="language-cpp">
|
<div class="language-cpp">
|
||||||
~~~{.cpp}
|
~~~{.cpp}
|
||||||
// Call `Finish()` to instruct the builder that this monster is complete.
|
// Call `Finish()` to instruct the builder that this monster is complete.
|
||||||
@@ -999,6 +1102,11 @@ appropriate `finish` method.
|
|||||||
// $builder, $orc);`.
|
// $builder, $orc);`.
|
||||||
~~~
|
~~~
|
||||||
</div>
|
</div>
|
||||||
|
<div class="language-c">
|
||||||
|
~~~{.c}
|
||||||
|
// Because we used `Monster_create_as_root`, we do not need a `finish` call in C`.
|
||||||
|
~~~
|
||||||
|
</div>
|
||||||
|
|
||||||
The buffer is now ready to be stored somewhere, sent over the network, be
|
The buffer is now ready to be stored somewhere, sent over the network, be
|
||||||
compressed, or whatever you'd like to do with it. You can access the buffer
|
compressed, or whatever you'd like to do with it. You can access the buffer
|
||||||
@@ -1016,12 +1124,23 @@ like so:
|
|||||||
~~~{.java}
|
~~~{.java}
|
||||||
// This must be called after `finish()`.
|
// This must be called after `finish()`.
|
||||||
java.nio.ByteBuffer buf = builder.dataBuffer();
|
java.nio.ByteBuffer buf = builder.dataBuffer();
|
||||||
|
// The data in this ByteBuffer does NOT start at 0, but at buf.position().
|
||||||
|
// The number of bytes is buf.remaining().
|
||||||
|
|
||||||
|
// Alternatively this copies the above data out of the ByteBuffer for you:
|
||||||
|
bytes[] buf = builder.sizedByteArray();
|
||||||
~~~
|
~~~
|
||||||
</div>
|
</div>
|
||||||
<div class="language-csharp">
|
<div class="language-csharp">
|
||||||
~~~{.cs}
|
~~~{.cs}
|
||||||
// This must be called after `Finish()`.
|
// This must be called after `Finish()`.
|
||||||
var buf = builder.DataBuffer; // Of type `FlatBuffers.ByteBuffer`.
|
var buf = builder.DataBuffer; // Of type `FlatBuffers.ByteBuffer`.
|
||||||
|
// The data in this ByteBuffer does NOT start at 0, but at buf.Position.
|
||||||
|
// The end of the data is marked by buf.Length, so the size is
|
||||||
|
// buf.Length - buf.Position.
|
||||||
|
|
||||||
|
// Alternatively this copies the above data out of the ByteBuffer for you:
|
||||||
|
bytes[] buf = builder.SizedByteArray();
|
||||||
~~~
|
~~~
|
||||||
</div>
|
</div>
|
||||||
<div class="language-go">
|
<div class="language-go">
|
||||||
@@ -1039,15 +1158,46 @@ like so:
|
|||||||
<div class="language-javascript">
|
<div class="language-javascript">
|
||||||
~~~{.js}
|
~~~{.js}
|
||||||
// This must be called after `finish()`.
|
// This must be called after `finish()`.
|
||||||
var buf = builder.dataBuffer(); // Of type `flatbuffers.ByteBuffer`.
|
var buf = builder.asUint8Array(); // Of type `Uint8Array`.
|
||||||
~~~
|
~~~
|
||||||
</div>
|
</div>
|
||||||
<div class="language-php">
|
<div class="language-php">
|
||||||
~~~{.php}
|
~~~{.php}
|
||||||
// This must be called after `finish()`.
|
// This must be called after `finish()`.
|
||||||
$buf = $builder->dataBuffer(); // Of type `Google\FlatBuffers\ByteBuffer`
|
$buf = $builder->dataBuffer(); // Of type `Google\FlatBuffers\ByteBuffer`
|
||||||
|
// The data in this ByteBuffer does NOT start at 0, but at buf->getPosition().
|
||||||
|
// The end of the data is marked by buf->capacity(), so the size is
|
||||||
|
// buf->capacity() - buf->getPosition().
|
||||||
~~~
|
~~~
|
||||||
</div>
|
</div>
|
||||||
|
<div class="language-c">
|
||||||
|
~~~{.c}
|
||||||
|
uint8_t *buf;
|
||||||
|
size_t size;
|
||||||
|
|
||||||
|
// Allocate and extract a readable buffer from internal builder heap.
|
||||||
|
// The returned buffer must be deallocated using `free`.
|
||||||
|
// NOTE: Finalizing the buffer does NOT change the builder, it
|
||||||
|
// just creates a snapshot of the builder content.
|
||||||
|
buf = flatcc_builder_finalize_buffer(B, &size);
|
||||||
|
// use buf
|
||||||
|
free(buf);
|
||||||
|
|
||||||
|
// Optionally reset builder to reuse builder without deallocating
|
||||||
|
// internal stack and heap.
|
||||||
|
flatcc_builder_reset(B);
|
||||||
|
// build next buffer.
|
||||||
|
// ...
|
||||||
|
|
||||||
|
// Cleanup.
|
||||||
|
flatcc_builder_clear(B);
|
||||||
|
~~~
|
||||||
|
</div>
|
||||||
|
|
||||||
|
Now you can write the bytes to a file, send them over the network..
|
||||||
|
**Make sure your file mode (or tranfer protocol) is set to BINARY, not text.**
|
||||||
|
If you transfer a FlatBuffer in text mode, the buffer will be corrupted,
|
||||||
|
which will lead to hard to find problems when you read the buffer.
|
||||||
|
|
||||||
#### Reading Orc FlatBuffers
|
#### Reading Orc FlatBuffers
|
||||||
|
|
||||||
@@ -1055,7 +1205,7 @@ Now that we have successfully created an `Orc` FlatBuffer, the monster data can
|
|||||||
be saved, sent over a network, etc. Let's now adventure into the inverse, and
|
be saved, sent over a network, etc. Let's now adventure into the inverse, and
|
||||||
deserialize a FlatBuffer.
|
deserialize a FlatBuffer.
|
||||||
|
|
||||||
This seciton requires the same import/include, namespace, etc. requirements as
|
This section requires the same import/include, namespace, etc. requirements as
|
||||||
before:
|
before:
|
||||||
|
|
||||||
<div class="language-cpp">
|
<div class="language-cpp">
|
||||||
@@ -1134,98 +1284,107 @@ before:
|
|||||||
}
|
}
|
||||||
~~~
|
~~~
|
||||||
</div>
|
</div>
|
||||||
|
<div class="language-c">
|
||||||
|
~~~{.c}
|
||||||
|
// Only needed if we don't have `#include "monster_builder.h"`.
|
||||||
|
#include "monster_reader.h"
|
||||||
|
|
||||||
Then, assuming you have a variable containing to the bytes of data from disk,
|
#undef ns
|
||||||
network, etc., you can create a monster from this data:
|
#define ns(x) FLATBUFFERS_WRAP_NAMESPACE(MyGame_Sample, x) // Specified in the schema.
|
||||||
|
~~~
|
||||||
|
</div>
|
||||||
|
|
||||||
|
Then, assuming you have a buffer of bytes received from disk,
|
||||||
|
network, etc., you can create start accessing the buffer like so:
|
||||||
|
|
||||||
|
**Again, make sure you read the bytes in BINARY mode, otherwise the code below
|
||||||
|
won't work**
|
||||||
|
|
||||||
<div class="language-cpp">
|
<div class="language-cpp">
|
||||||
~~~{.cpp}
|
~~~{.cpp}
|
||||||
// We can access the buffer we just made directly. Pretend this came over a
|
uint8_t *buffer_pointer = /* the data you just read */;
|
||||||
// network, was read off of disk, etc.
|
|
||||||
auto buffer_pointer = builder.GetBufferPointer();
|
|
||||||
|
|
||||||
// Deserialize the data from the buffer.
|
// Get a pointer to the root object inside the buffer.
|
||||||
auto monster = GetMonster(buffer_pointer);
|
auto monster = GetMonster(buffer_pointer);
|
||||||
|
|
||||||
// `monster` is of type`Monster *`, and points to somewhere inside the buffer.
|
// `monster` is of type `Monster *`.
|
||||||
|
|
||||||
// Note: root object pointers are NOT the same as `buffer_pointer`.
|
// Note: root object pointers are NOT the same as `buffer_pointer`.
|
||||||
~~~
|
~~~
|
||||||
</div>
|
</div>
|
||||||
<div class="language-java">
|
<div class="language-java">
|
||||||
~~~{.java}
|
~~~{.java}
|
||||||
// We can access the buffer we just made directly. Pretend this came over a
|
byte[] bytes = /* the data you just read */
|
||||||
// network, was read off of disk, etc.
|
java.nio.ByteBuffer buf = java.nio.ByteBuffer.wrap(bytes);
|
||||||
java.nio.ByteBuffer buf = builder.dataBuffer();
|
|
||||||
|
|
||||||
// Deserialize the data from the buffer.
|
// Get an accessor to the root object inside the buffer.
|
||||||
Monster monster = Monster.getRootAsMonster(buf);
|
Monster monster = Monster.getRootAsMonster(buf);
|
||||||
~~~
|
~~~
|
||||||
</div>
|
</div>
|
||||||
<div class="language-csharp">
|
<div class="language-csharp">
|
||||||
~~~{.cs}
|
~~~{.cs}
|
||||||
// We can access the buffer we just made directly. Pretend this came over a
|
byte[] bytes = /* the data you just read */
|
||||||
// network, was read off of disk, etc.
|
var buf = new ByteBuffer(bytes);
|
||||||
var buf = builder.DataBuffer;
|
|
||||||
|
|
||||||
// Deserialize the data from the buffer.
|
// Get an accessor to the root object inside the buffer.
|
||||||
var monster = Monster.GetRootAsMonster(buf);
|
var monster = Monster.GetRootAsMonster(buf);
|
||||||
~~~
|
~~~
|
||||||
</div>
|
</div>
|
||||||
<div class="language-go">
|
<div class="language-go">
|
||||||
~~~{.go}
|
~~~{.go}
|
||||||
// We can access the buffer we just made directly. Pretend this came over a
|
var buf []byte = /* the data you just read */
|
||||||
// network, was read off of disk, etc.
|
|
||||||
buf := builder.FinishedBytes()
|
|
||||||
|
|
||||||
// Deserialize the data from the buffer.
|
// Get an accessor to the root object inside the buffer.
|
||||||
monster := sample.GetRootAsMonster(buf, 0)
|
monster := sample.GetRootAsMonster(buf, 0)
|
||||||
|
|
||||||
// Note: We use `0` for the offset here, since we got the data using the
|
// Note: We use `0` for the offset here, which is typical for most buffers
|
||||||
// `builder.FinishedBytes()` method. This simulates the data you would
|
// you would read. If you wanted to read from `builder.Bytes` directly, you
|
||||||
// store/receive in your FlatBuffer. If you wanted to read from the
|
// would need to pass in the offset of `builder.Head()`, as the builder
|
||||||
// `builder.Bytes` directly, you would need to pass in the offset of
|
// constructs the buffer backwards, so may not start at offset 0.
|
||||||
// `builder.Head()`, as the builder actually constructs the buffer backwards.
|
|
||||||
~~~
|
~~~
|
||||||
</div>
|
</div>
|
||||||
<div class="language-python">
|
<div class="language-python">
|
||||||
~~~{.py}
|
~~~{.py}
|
||||||
# We can access the buffer we just made directly. Pretend this came over a
|
buf = /* the data you just read, in an object of type "bytearray" */
|
||||||
# network, was read off of disk, etc.
|
|
||||||
buf = builder.Output()
|
|
||||||
|
|
||||||
# Deserialize the data from the buffer.
|
// Get an accessor to the root object inside the buffer.
|
||||||
monster = MyGame.Sample.Monster.Monster.GetRootAsMonster(buf, 0)
|
monster = MyGame.Sample.Monster.Monster.GetRootAsMonster(buf, 0)
|
||||||
|
|
||||||
# Note: We use `0` for the offset here, since we got the data using the
|
# Note: We use `0` for the offset here, which is typical for most buffers
|
||||||
# `builder.Output()` method. This simulates the data you would store/receive
|
# you would read. If you wanted to read from the `builder.Bytes` directly,
|
||||||
# in your FlatBuffer. If you wanted to read from the `builder.Bytes` directly,
|
|
||||||
# you would need to pass in the offset of `builder.Head()`, as the builder
|
# you would need to pass in the offset of `builder.Head()`, as the builder
|
||||||
# actually constructs the buffer backwards.
|
# constructs the buffer backwards, so may not start at offset 0.
|
||||||
~~~
|
~~~
|
||||||
</div>
|
</div>
|
||||||
<div class="language-javascript">
|
<div class="language-javascript">
|
||||||
~~~{.js}
|
~~~{.js}
|
||||||
// We can access the buffer we just made directly. Pretend this came over a
|
var bytes = /* the data you just read, in an object of type "Uint8Array" */
|
||||||
// network, was read off of disk, etc.
|
var buf = new flatbuffers.ByteBuffer(bytes);
|
||||||
var buf = builder.dataBuffer();
|
|
||||||
|
|
||||||
// Deserialize the data from the buffer.
|
// Get an accessor to the root object inside the buffer.
|
||||||
var monster = MyGame.Sample.Monster.getRootAsMonster(buf);
|
var monster = MyGame.Sample.Monster.getRootAsMonster(buf);
|
||||||
~~~
|
~~~
|
||||||
</div>
|
</div>
|
||||||
<div class="language-php">
|
<div class="language-php">
|
||||||
~~~{.php}
|
~~~{.php}
|
||||||
// We can access the buffer we just made directly. Pretend this came over a
|
$bytes = /* the data you just read, in a string */
|
||||||
// network, was read off of disk, etc.
|
$buf = Google\FlatBuffers\ByteBuffer::wrap($bytes);
|
||||||
$buf = $builder->dataBuffer();
|
|
||||||
|
|
||||||
// Deserialize the data from the buffer.
|
// Get an accessor to the root object inside the buffer.
|
||||||
$monster = \MyGame\Sample\Monster::GetRootAsMonster($buf);
|
$monster = \MyGame\Sample\Monster::GetRootAsMonster($buf);
|
||||||
~~~
|
~~~
|
||||||
</div>
|
</div>
|
||||||
|
<div class="language-c">
|
||||||
|
~~~{.c}
|
||||||
|
// Note that we use the `table_t` suffix when reading a table object
|
||||||
|
// as opposed to the `ref_t` suffix used during the construction of
|
||||||
|
// the buffer.
|
||||||
|
ns(Monster_table_t) monster = ns(Monster_as_root(buffer));
|
||||||
|
|
||||||
If you look in the generated files from `flatc`, you will see it generated
|
// Note: root object pointers are NOT the same as the `buffer` pointer.
|
||||||
|
~~~
|
||||||
|
</div>
|
||||||
|
|
||||||
|
If you look in the generated files from the schema compiler, you will see it generated
|
||||||
accessors for all non-`deprecated` fields. For example:
|
accessors for all non-`deprecated` fields. For example:
|
||||||
|
|
||||||
<div class="language-cpp">
|
<div class="language-cpp">
|
||||||
@@ -1279,10 +1438,17 @@ accessors for all non-`deprecated` fields. For example:
|
|||||||
$name = monster->getName();
|
$name = monster->getName();
|
||||||
~~~
|
~~~
|
||||||
</div>
|
</div>
|
||||||
|
<div class="language-c">
|
||||||
|
~~~{.c}
|
||||||
|
uint16_t hp = ns(Monster_hp(monster));
|
||||||
|
uint16_t mana = ns(Monster_mana(monster));
|
||||||
|
flatbuffers_string_t name = ns(Monster_name(monster));
|
||||||
|
~~~
|
||||||
|
</div>
|
||||||
|
|
||||||
These should hold `300`, `150`, and `"Orc"` respectively.
|
These should hold `300`, `150`, and `"Orc"` respectively.
|
||||||
|
|
||||||
*Note: We never stored a value in `mp`, so we got the default value of `150`.*
|
*Note: The default value `150` wasn't stored in `mana`, but we are still able to retrieve it.*
|
||||||
|
|
||||||
To access sub-objects, in the case of our `pos`, which is a `Vec3`:
|
To access sub-objects, in the case of our `pos`, which is a `Vec3`:
|
||||||
|
|
||||||
@@ -1348,10 +1514,18 @@ To access sub-objects, in the case of our `pos`, which is a `Vec3`:
|
|||||||
$z = $pos->getZ();
|
$z = $pos->getZ();
|
||||||
~~~
|
~~~
|
||||||
</div>
|
</div>
|
||||||
|
<div class="language-c">
|
||||||
|
~~~{.c}
|
||||||
|
ns(Vec3_struct_t) pos = ns(Monster_pos(monster));
|
||||||
|
float x = ns(Vec3_x(pos));
|
||||||
|
float y = ns(Vec3_y(pos));
|
||||||
|
float z = ns(Vec3_z(pos));
|
||||||
|
~~~
|
||||||
|
</div>
|
||||||
|
|
||||||
`x`, `y`, and `z` will contain `1.0`, `2.0`, and `3.0`, respectively.
|
`x`, `y`, and `z` will contain `1.0`, `2.0`, and `3.0`, respectively.
|
||||||
|
|
||||||
*Note: Had we not set `pos` during serialization, it would be `NULL`-value.*
|
*Note: Had we not set `pos` during serialization, it would be a `NULL`-value.*
|
||||||
|
|
||||||
Similarly, we can access elements of the inventory `vector` by indexing it. You
|
Similarly, we can access elements of the inventory `vector` by indexing it. You
|
||||||
can also iterate over the length of the array/vector representing the
|
can also iterate over the length of the array/vector representing the
|
||||||
@@ -1400,6 +1574,14 @@ FlatBuffers `vector`.
|
|||||||
$third_item = $monster->getInventory(2);
|
$third_item = $monster->getInventory(2);
|
||||||
~~~
|
~~~
|
||||||
</div>
|
</div>
|
||||||
|
<div class="language-c">
|
||||||
|
~~~{.c}
|
||||||
|
// If `inv` hasn't been set, it will be null. It is valid get
|
||||||
|
// the length of null which will be 0, useful for iteration.
|
||||||
|
flatbuffers_uint8_vec_t inv = ns(Monster_inventory(monster));
|
||||||
|
size_t inv_len = flatbuffers_uint8_vec_len(inv);
|
||||||
|
~~~
|
||||||
|
</div>
|
||||||
|
|
||||||
For `vector`s of `table`s, you can access the elements like any other vector,
|
For `vector`s of `table`s, you can access the elements like any other vector,
|
||||||
except your need to handle the result as a FlatBuffer `table`:
|
except your need to handle the result as a FlatBuffer `table`:
|
||||||
@@ -1458,6 +1640,15 @@ except your need to handle the result as a FlatBuffer `table`:
|
|||||||
$second_weapon_damage = $monster->getWeapons(1)->getDamage();
|
$second_weapon_damage = $monster->getWeapons(1)->getDamage();
|
||||||
~~~
|
~~~
|
||||||
</div>
|
</div>
|
||||||
|
<div class="language-c">
|
||||||
|
~~~{.c}
|
||||||
|
ns(Weapon_vec_t) weapons = ns(Monster_weapons(monster));
|
||||||
|
size_t weapons_len = ns(Weapon_vec_len(weapons));
|
||||||
|
// We can use `const char *` instead of `flatbuffers_string_t`.
|
||||||
|
const char *second_weapon_name = ns(Weapon_name(ns(Weapon_vec_at(weapons, 1))));
|
||||||
|
uint16_t second_weapon_damage = ns(Weapon_damage(ns(Weapon_vec_at(weapons, 1))));
|
||||||
|
~~~
|
||||||
|
</div>
|
||||||
|
|
||||||
Last, we can access our `Equipped` FlatBuffer `union`. Just like when we created
|
Last, we can access our `Equipped` FlatBuffer `union`. Just like when we created
|
||||||
the `union`, we need to get both parts of the `union`: the type and the data.
|
the `union`, we need to get both parts of the `union`: the type and the data.
|
||||||
@@ -1560,6 +1751,18 @@ We can access the type to dynamically cast the data as needed (since the
|
|||||||
}
|
}
|
||||||
~~~
|
~~~
|
||||||
</div>
|
</div>
|
||||||
|
<div class="language-c">
|
||||||
|
~~~{.c}
|
||||||
|
// Access union type field.
|
||||||
|
if (ns(Monster_equipped_type(monster)) == ns(Equipment_Weapon)) {
|
||||||
|
// Cast to appropriate type:
|
||||||
|
// C allows for silent void pointer assignment, so we need no explicit cast.
|
||||||
|
ns(Weapon_table_t) weapon = ns(Monster_equipped(monster));
|
||||||
|
const char *weapon_name = ns(Weapon_name(weapon)); // "Axe"
|
||||||
|
uint16_t weapon_damage = ns(Weapon_damage(weapon)); // 5
|
||||||
|
}
|
||||||
|
~~~
|
||||||
|
</div>
|
||||||
|
|
||||||
## Mutating FlatBuffers
|
## Mutating FlatBuffers
|
||||||
|
|
||||||
@@ -1624,6 +1827,12 @@ mutators like so:
|
|||||||
<API for mutating FlatBuffers is not yet supported in PHP.>
|
<API for mutating FlatBuffers is not yet supported in PHP.>
|
||||||
~~~
|
~~~
|
||||||
</div>
|
</div>
|
||||||
|
<div class="language-c">
|
||||||
|
~~~{.c}
|
||||||
|
<API for in-place mutating FlatBuffers will not be supported in C
|
||||||
|
(except in-place vector sorting is possible).>
|
||||||
|
~~~
|
||||||
|
</div>
|
||||||
|
|
||||||
We use the somewhat verbose term `mutate` instead of `set` to indicate that this
|
We use the somewhat verbose term `mutate` instead of `set` to indicate that this
|
||||||
is a special use case, not to be confused with the default way of constructing
|
is a special use case, not to be confused with the default way of constructing
|
||||||
@@ -1644,6 +1853,9 @@ One way to solve this is to call `ForceDefaults` on a FlatBufferBuilder to
|
|||||||
force all fields you set to actually be written. This, of course, increases the
|
force all fields you set to actually be written. This, of course, increases the
|
||||||
size of the buffer somewhat, but this may be acceptable for a mutable buffer.
|
size of the buffer somewhat, but this may be acceptable for a mutable buffer.
|
||||||
|
|
||||||
|
If this is not sufficient, other ways of mutating FlatBuffers may be supported
|
||||||
|
in your language through an object based API (`--gen-object-api`) or reflection.
|
||||||
|
See the individual language documents for support.
|
||||||
|
|
||||||
## JSON with FlatBuffers
|
## JSON with FlatBuffers
|
||||||
|
|
||||||
@@ -1687,6 +1899,14 @@ FlatBuffer binary representation of the contents from our `.json` file.
|
|||||||
[Use in C++](@ref flatbuffers_guide_use_cpp) section of the Programmer's
|
[Use in C++](@ref flatbuffers_guide_use_cpp) section of the Programmer's
|
||||||
Guide for more information.*
|
Guide for more information.*
|
||||||
</div>
|
</div>
|
||||||
|
<div class="language-c">
|
||||||
|
*Note: If you're working in C, the `flatcc --json` (not `flatc`)
|
||||||
|
compiler will generate schema specific high performance json parsers and
|
||||||
|
printers that you can compile and use at runtime. The `flatc` compiler (not
|
||||||
|
`flatcc`) on the other hand, is still useful for general offline json to
|
||||||
|
flatbuffer conversion from a given schema. There are no current plans
|
||||||
|
for `flatcc` to support this.*
|
||||||
|
</div>
|
||||||
|
|
||||||
## Advanced Features for Each Language
|
## Advanced Features for Each Language
|
||||||
|
|
||||||
@@ -1716,5 +1936,8 @@ For your chosen language, see:
|
|||||||
<div class="language-php">
|
<div class="language-php">
|
||||||
[Use in PHP](@ref flatbuffers_guide_use_php)
|
[Use in PHP](@ref flatbuffers_guide_use_php)
|
||||||
</div>
|
</div>
|
||||||
|
<div class="language-c">
|
||||||
|
[Use in C](@ref flatbuffers_guide_use_c)
|
||||||
|
</div>
|
||||||
|
|
||||||
<br>
|
<br>
|
||||||
|
|||||||
@@ -750,6 +750,7 @@ INPUT = "FlatBuffers.md" \
|
|||||||
"Compiler.md" \
|
"Compiler.md" \
|
||||||
"Schemas.md" \
|
"Schemas.md" \
|
||||||
"CppUsage.md" \
|
"CppUsage.md" \
|
||||||
|
"CUsage.md" \
|
||||||
"GoUsage.md" \
|
"GoUsage.md" \
|
||||||
"JavaCsharpUsage.md" \
|
"JavaCsharpUsage.md" \
|
||||||
"JavaScriptUsage.md" \
|
"JavaScriptUsage.md" \
|
||||||
@@ -758,9 +759,10 @@ INPUT = "FlatBuffers.md" \
|
|||||||
"Support.md" \
|
"Support.md" \
|
||||||
"Benchmarks.md" \
|
"Benchmarks.md" \
|
||||||
"WhitePaper.md" \
|
"WhitePaper.md" \
|
||||||
|
"FlexBuffers.md" \
|
||||||
"Internals.md" \
|
"Internals.md" \
|
||||||
"Grammar.md" \
|
"Grammar.md" \
|
||||||
"CONTRIBUTING.md" \
|
"../../CONTRIBUTING.md" \
|
||||||
"Tutorial.md" \
|
"Tutorial.md" \
|
||||||
"GoApi.md" \
|
"GoApi.md" \
|
||||||
"groups" \
|
"groups" \
|
||||||
|
|||||||
@@ -25,6 +25,8 @@
|
|||||||
title="Writing a schema"/>
|
title="Writing a schema"/>
|
||||||
<tab type="user" url="@ref flatbuffers_guide_use_cpp"
|
<tab type="user" url="@ref flatbuffers_guide_use_cpp"
|
||||||
title="Use in C++"/>
|
title="Use in C++"/>
|
||||||
|
<tab type="user" url="@ref flatbuffers_guide_use_c"
|
||||||
|
title="Use in C"/>
|
||||||
<tab type="user" url="@ref flatbuffers_guide_use_go"
|
<tab type="user" url="@ref flatbuffers_guide_use_go"
|
||||||
title="Use in Go"/>
|
title="Use in Go"/>
|
||||||
<tab type="user" url="@ref flatbuffers_guide_use_java_c-sharp"
|
<tab type="user" url="@ref flatbuffers_guide_use_java_c-sharp"
|
||||||
@@ -35,6 +37,8 @@
|
|||||||
title="Use in PHP"/>
|
title="Use in PHP"/>
|
||||||
<tab type="user" url="@ref flatbuffers_guide_use_python"
|
<tab type="user" url="@ref flatbuffers_guide_use_python"
|
||||||
title="Use in Python"/>
|
title="Use in Python"/>
|
||||||
|
<tab type="user" url="@ref flexbuffers"
|
||||||
|
title="Schema-less version"/>
|
||||||
</tab>
|
</tab>
|
||||||
<tab type="user" url="@ref flatbuffers_support"
|
<tab type="user" url="@ref flatbuffers_support"
|
||||||
title="Platform / Language / Feature support"/>
|
title="Platform / Language / Feature support"/>
|
||||||
@@ -45,7 +49,7 @@
|
|||||||
<tab type="user" url="@ref flatbuffers_internals"
|
<tab type="user" url="@ref flatbuffers_internals"
|
||||||
title="FlatBuffers internals"/>
|
title="FlatBuffers internals"/>
|
||||||
<tab type="user" url="@ref flatbuffers_grammar"
|
<tab type="user" url="@ref flatbuffers_grammar"
|
||||||
title="Grammar of the schema langauge"/>
|
title="Grammar of the schema language"/>
|
||||||
<tab type="usergroup" url="" title="API Reference">
|
<tab type="usergroup" url="" title="API Reference">
|
||||||
<tab type="modules" visible="yes" title="APIs" intro=""/>
|
<tab type="modules" visible="yes" title="APIs" intro=""/>
|
||||||
<tab type="classes" visible="yes" title="">
|
<tab type="classes" visible="yes" title="">
|
||||||
|
|||||||
23
go/grpc.go
Normal file
23
go/grpc.go
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
package flatbuffers
|
||||||
|
|
||||||
|
// Codec implements gRPC-go Codec which is used to encode and decode messages.
|
||||||
|
var Codec = "flatbuffers"
|
||||||
|
|
||||||
|
type FlatbuffersCodec struct{}
|
||||||
|
|
||||||
|
func (FlatbuffersCodec) Marshal(v interface{}) ([]byte, error) {
|
||||||
|
return v.(*Builder).FinishedBytes(), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (FlatbuffersCodec) Unmarshal(data []byte, v interface{}) error {
|
||||||
|
v.(flatbuffersInit).Init(data, GetUOffsetT(data))
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (FlatbuffersCodec) String() string {
|
||||||
|
return Codec
|
||||||
|
}
|
||||||
|
|
||||||
|
type flatbuffersInit interface {
|
||||||
|
Init(data []byte, i UOffsetT)
|
||||||
|
}
|
||||||
13
go/lib.go
Normal file
13
go/lib.go
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
package flatbuffers
|
||||||
|
|
||||||
|
// FlatBuffer is the interface that represents a flatbuffer.
|
||||||
|
type FlatBuffer interface {
|
||||||
|
Table() Table
|
||||||
|
Init(buf []byte, i UOffsetT)
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetRootAs is a generic helper to initialize a FlatBuffer with the provided buffer bytes and its data offset.
|
||||||
|
func GetRootAs(buf []byte, offset UOffsetT, fb FlatBuffer) {
|
||||||
|
n := GetUOffsetT(buf[offset:])
|
||||||
|
fb.Init(buf, n+offset)
|
||||||
|
}
|
||||||
@@ -1,45 +1,55 @@
|
|||||||
package flatbuffers
|
package flatbuffers
|
||||||
|
|
||||||
import "unsafe"
|
import (
|
||||||
|
"unsafe"
|
||||||
|
)
|
||||||
|
|
||||||
var (
|
const (
|
||||||
// See http://golang.org/ref/spec#Numeric_types
|
// See http://golang.org/ref/spec#Numeric_types
|
||||||
|
|
||||||
// SizeUint8 is the byte size of a uint8.
|
// SizeUint8 is the byte size of a uint8.
|
||||||
SizeUint8 = int(unsafe.Sizeof(uint8(0)))
|
SizeUint8 = 1
|
||||||
// SizeUint16 is the byte size of a uint16.
|
// SizeUint16 is the byte size of a uint16.
|
||||||
SizeUint16 = int(unsafe.Sizeof(uint16(0)))
|
SizeUint16 = 2
|
||||||
// SizeUint32 is the byte size of a uint32.
|
// SizeUint32 is the byte size of a uint32.
|
||||||
SizeUint32 = int(unsafe.Sizeof(uint32(0)))
|
SizeUint32 = 4
|
||||||
// SizeUint64 is the byte size of a uint64.
|
// SizeUint64 is the byte size of a uint64.
|
||||||
SizeUint64 = int(unsafe.Sizeof(uint64(0)))
|
SizeUint64 = 8
|
||||||
|
|
||||||
// SizeInt8 is the byte size of a int8.
|
// SizeInt8 is the byte size of a int8.
|
||||||
SizeInt8 = int(unsafe.Sizeof(int8(0)))
|
SizeInt8 = 1
|
||||||
// SizeInt16 is the byte size of a int16.
|
// SizeInt16 is the byte size of a int16.
|
||||||
SizeInt16 = int(unsafe.Sizeof(int16(0)))
|
SizeInt16 = 2
|
||||||
// SizeInt32 is the byte size of a int32.
|
// SizeInt32 is the byte size of a int32.
|
||||||
SizeInt32 = int(unsafe.Sizeof(int32(0)))
|
SizeInt32 = 4
|
||||||
// SizeInt64 is the byte size of a int64.
|
// SizeInt64 is the byte size of a int64.
|
||||||
SizeInt64 = int(unsafe.Sizeof(int64(0)))
|
SizeInt64 = 8
|
||||||
|
|
||||||
// SizeFloat32 is the byte size of a float32.
|
// SizeFloat32 is the byte size of a float32.
|
||||||
SizeFloat32 = int(unsafe.Sizeof(float32(0)))
|
SizeFloat32 = 4
|
||||||
// SizeFloat64 is the byte size of a float64.
|
// SizeFloat64 is the byte size of a float64.
|
||||||
SizeFloat64 = int(unsafe.Sizeof(float64(0)))
|
SizeFloat64 = 8
|
||||||
|
|
||||||
// SizeByte is the byte size of a byte.
|
// SizeByte is the byte size of a byte.
|
||||||
// The `byte` type is aliased (by Go definition) to uint8.
|
// The `byte` type is aliased (by Go definition) to uint8.
|
||||||
SizeByte = SizeUint8
|
SizeByte = 1
|
||||||
|
|
||||||
// SizeBool is the byte size of a bool.
|
// SizeBool is the byte size of a bool.
|
||||||
// The `bool` type is aliased (by flatbuffers convention) to uint8.
|
// The `bool` type is aliased (by flatbuffers convention) to uint8.
|
||||||
SizeBool = SizeUint8
|
SizeBool = 1
|
||||||
|
|
||||||
// SizeSOffsetT is the byte size of an SOffsetT.
|
// SizeSOffsetT is the byte size of an SOffsetT.
|
||||||
SizeSOffsetT = int(unsafe.Sizeof(SOffsetT(0)))
|
// The `SOffsetT` type is aliased (by flatbuffers convention) to int32.
|
||||||
|
SizeSOffsetT = 4
|
||||||
// SizeUOffsetT is the byte size of an UOffsetT.
|
// SizeUOffsetT is the byte size of an UOffsetT.
|
||||||
SizeUOffsetT = int(unsafe.Sizeof(UOffsetT(0)))
|
// The `UOffsetT` type is aliased (by flatbuffers convention) to uint32.
|
||||||
|
SizeUOffsetT = 4
|
||||||
// SizeVOffsetT is the byte size of an VOffsetT.
|
// SizeVOffsetT is the byte size of an VOffsetT.
|
||||||
SizeVOffsetT = int(unsafe.Sizeof(VOffsetT(0)))
|
// The `VOffsetT` type is aliased (by flatbuffers convention) to uint16.
|
||||||
|
SizeVOffsetT = 2
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// byteSliceToString converts a []byte to string without a heap allocation.
|
||||||
|
func byteSliceToString(b []byte) string {
|
||||||
|
return *(*string)(unsafe.Pointer(&b))
|
||||||
|
}
|
||||||
215
go/table.go
215
go/table.go
@@ -10,7 +10,7 @@ type Table struct {
|
|||||||
|
|
||||||
// Offset provides access into the Table's vtable.
|
// Offset provides access into the Table's vtable.
|
||||||
//
|
//
|
||||||
// Deprecated fields are ignored by checking against the vtable's length.
|
// Fields which are deprecated are ignored by checking against the vtable's length.
|
||||||
func (t *Table) Offset(vtableOffset VOffsetT) VOffsetT {
|
func (t *Table) Offset(vtableOffset VOffsetT) VOffsetT {
|
||||||
vtable := UOffsetT(SOffsetT(t.Pos) - t.GetSOffsetT(t.Pos))
|
vtable := UOffsetT(SOffsetT(t.Pos) - t.GetSOffsetT(t.Pos))
|
||||||
if vtableOffset < t.GetVOffsetT(vtable) {
|
if vtableOffset < t.GetVOffsetT(vtable) {
|
||||||
@@ -26,7 +26,8 @@ func (t *Table) Indirect(off UOffsetT) UOffsetT {
|
|||||||
|
|
||||||
// String gets a string from data stored inside the flatbuffer.
|
// String gets a string from data stored inside the flatbuffer.
|
||||||
func (t *Table) String(off UOffsetT) string {
|
func (t *Table) String(off UOffsetT) string {
|
||||||
return string(t.ByteVector(off))
|
b := t.ByteVector(off)
|
||||||
|
return byteSliceToString(b)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ByteVector gets a byte slice from data stored inside the flatbuffer.
|
// ByteVector gets a byte slice from data stored inside the flatbuffer.
|
||||||
@@ -292,3 +293,213 @@ func (t *Table) GetVOffsetTSlot(slot VOffsetT, d VOffsetT) VOffsetT {
|
|||||||
}
|
}
|
||||||
return VOffsetT(off)
|
return VOffsetT(off)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// MutateBool updates a bool at the given offset.
|
||||||
|
func (t *Table) MutateBool(off UOffsetT, n bool) bool {
|
||||||
|
WriteBool(t.Bytes[off:], n)
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
// MutateByte updates a Byte at the given offset.
|
||||||
|
func (t *Table) MutateByte(off UOffsetT, n byte) bool {
|
||||||
|
WriteByte(t.Bytes[off:], n)
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
// MutateUint8 updates a Uint8 at the given offset.
|
||||||
|
func (t *Table) MutateUint8(off UOffsetT, n uint8) bool {
|
||||||
|
WriteUint8(t.Bytes[off:], n)
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
// MutateUint16 updates a Uint16 at the given offset.
|
||||||
|
func (t *Table) MutateUint16(off UOffsetT, n uint16) bool {
|
||||||
|
WriteUint16(t.Bytes[off:], n)
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
// MutateUint32 updates a Uint32 at the given offset.
|
||||||
|
func (t *Table) MutateUint32(off UOffsetT, n uint32) bool {
|
||||||
|
WriteUint32(t.Bytes[off:], n)
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
// MutateUint64 updates a Uint64 at the given offset.
|
||||||
|
func (t *Table) MutateUint64(off UOffsetT, n uint64) bool {
|
||||||
|
WriteUint64(t.Bytes[off:], n)
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
// MutateInt8 updates a Int8 at the given offset.
|
||||||
|
func (t *Table) MutateInt8(off UOffsetT, n int8) bool {
|
||||||
|
WriteInt8(t.Bytes[off:], n)
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
// MutateInt16 updates a Int16 at the given offset.
|
||||||
|
func (t *Table) MutateInt16(off UOffsetT, n int16) bool {
|
||||||
|
WriteInt16(t.Bytes[off:], n)
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
// MutateInt32 updates a Int32 at the given offset.
|
||||||
|
func (t *Table) MutateInt32(off UOffsetT, n int32) bool {
|
||||||
|
WriteInt32(t.Bytes[off:], n)
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
// MutateInt64 updates a Int64 at the given offset.
|
||||||
|
func (t *Table) MutateInt64(off UOffsetT, n int64) bool {
|
||||||
|
WriteInt64(t.Bytes[off:], n)
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
// MutateFloat32 updates a Float32 at the given offset.
|
||||||
|
func (t *Table) MutateFloat32(off UOffsetT, n float32) bool {
|
||||||
|
WriteFloat32(t.Bytes[off:], n)
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
// MutateFloat64 updates a Float64 at the given offset.
|
||||||
|
func (t *Table) MutateFloat64(off UOffsetT, n float64) bool {
|
||||||
|
WriteFloat64(t.Bytes[off:], n)
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
// MutateUOffsetT updates a UOffsetT at the given offset.
|
||||||
|
func (t *Table) MutateUOffsetT(off UOffsetT, n UOffsetT) bool {
|
||||||
|
WriteUOffsetT(t.Bytes[off:], n)
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
// MutateVOffsetT updates a VOffsetT at the given offset.
|
||||||
|
func (t *Table) MutateVOffsetT(off UOffsetT, n VOffsetT) bool {
|
||||||
|
WriteVOffsetT(t.Bytes[off:], n)
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
// MutateSOffsetT updates a SOffsetT at the given offset.
|
||||||
|
func (t *Table) MutateSOffsetT(off UOffsetT, n SOffsetT) bool {
|
||||||
|
WriteSOffsetT(t.Bytes[off:], n)
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
// MutateBoolSlot updates the bool at given vtable location
|
||||||
|
func (t *Table) MutateBoolSlot(slot VOffsetT, n bool) bool {
|
||||||
|
if off := t.Offset(slot); off != 0 {
|
||||||
|
t.MutateBool(t.Pos+UOffsetT(off), n)
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
// MutateByteSlot updates the byte at given vtable location
|
||||||
|
func (t *Table) MutateByteSlot(slot VOffsetT, n byte) bool {
|
||||||
|
if off := t.Offset(slot); off != 0 {
|
||||||
|
t.MutateByte(t.Pos+UOffsetT(off), n)
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
// MutateInt8Slot updates the int8 at given vtable location
|
||||||
|
func (t *Table) MutateInt8Slot(slot VOffsetT, n int8) bool {
|
||||||
|
if off := t.Offset(slot); off != 0 {
|
||||||
|
t.MutateInt8(t.Pos+UOffsetT(off), n)
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
// MutateUint8Slot updates the uint8 at given vtable location
|
||||||
|
func (t *Table) MutateUint8Slot(slot VOffsetT, n uint8) bool {
|
||||||
|
if off := t.Offset(slot); off != 0 {
|
||||||
|
t.MutateUint8(t.Pos+UOffsetT(off), n)
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
// MutateInt16Slot updates the int16 at given vtable location
|
||||||
|
func (t *Table) MutateInt16Slot(slot VOffsetT, n int16) bool {
|
||||||
|
if off := t.Offset(slot); off != 0 {
|
||||||
|
t.MutateInt16(t.Pos+UOffsetT(off), n)
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
// MutateUint16Slot updates the uint16 at given vtable location
|
||||||
|
func (t *Table) MutateUint16Slot(slot VOffsetT, n uint16) bool {
|
||||||
|
if off := t.Offset(slot); off != 0 {
|
||||||
|
t.MutateUint16(t.Pos+UOffsetT(off), n)
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
// MutateInt32Slot updates the int32 at given vtable location
|
||||||
|
func (t *Table) MutateInt32Slot(slot VOffsetT, n int32) bool {
|
||||||
|
if off := t.Offset(slot); off != 0 {
|
||||||
|
t.MutateInt32(t.Pos+UOffsetT(off), n)
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
// MutateUint32Slot updates the uint32 at given vtable location
|
||||||
|
func (t *Table) MutateUint32Slot(slot VOffsetT, n uint32) bool {
|
||||||
|
if off := t.Offset(slot); off != 0 {
|
||||||
|
t.MutateUint32(t.Pos+UOffsetT(off), n)
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
// MutateInt64Slot updates the int64 at given vtable location
|
||||||
|
func (t *Table) MutateInt64Slot(slot VOffsetT, n int64) bool {
|
||||||
|
if off := t.Offset(slot); off != 0 {
|
||||||
|
t.MutateInt64(t.Pos+UOffsetT(off), n)
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
// MutateUint64Slot updates the uint64 at given vtable location
|
||||||
|
func (t *Table) MutateUint64Slot(slot VOffsetT, n uint64) bool {
|
||||||
|
if off := t.Offset(slot); off != 0 {
|
||||||
|
t.MutateUint64(t.Pos+UOffsetT(off), n)
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
// MutateFloat32Slot updates the float32 at given vtable location
|
||||||
|
func (t *Table) MutateFloat32Slot(slot VOffsetT, n float32) bool {
|
||||||
|
if off := t.Offset(slot); off != 0 {
|
||||||
|
t.MutateFloat32(t.Pos+UOffsetT(off), n)
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
// MutateFloat64Slot updates the float64 at given vtable location
|
||||||
|
func (t *Table) MutateFloat64Slot(slot VOffsetT, n float64) bool {
|
||||||
|
if off := t.Offset(slot); off != 0 {
|
||||||
|
t.MutateFloat64(t.Pos+UOffsetT(off), n)
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|||||||
11
grpc/README.md
Normal file
11
grpc/README.md
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
GRPC implementation and test
|
||||||
|
============================
|
||||||
|
|
||||||
|
NOTE: files in `src/` are shared with the GRPC project, and maintained there
|
||||||
|
(any changes should be submitted to GRPC instead). These files are copied
|
||||||
|
from GRPC, and work with both the Protobuf and FlatBuffers code generator.
|
||||||
|
|
||||||
|
`tests/` contains a GRPC specific test, you need to have built and installed
|
||||||
|
the GRPC libraries for this to compile. This test will build using the
|
||||||
|
`FLATBUFFERS_BUILD_GRPCTEST` option to the main FlatBuffers CMake project.
|
||||||
|
|
||||||
1203
grpc/src/compiler/cpp_generator.cc
Normal file
1203
grpc/src/compiler/cpp_generator.cc
Normal file
File diff suppressed because it is too large
Load Diff
84
grpc/src/compiler/cpp_generator.h
Normal file
84
grpc/src/compiler/cpp_generator.h
Normal file
@@ -0,0 +1,84 @@
|
|||||||
|
/*
|
||||||
|
*
|
||||||
|
* Copyright 2015, Google Inc.
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions are
|
||||||
|
* met:
|
||||||
|
*
|
||||||
|
* * Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* * Redistributions in binary form must reproduce the above
|
||||||
|
* copyright notice, this list of conditions and the following disclaimer
|
||||||
|
* in the documentation and/or other materials provided with the
|
||||||
|
* distribution.
|
||||||
|
* * Neither the name of Google Inc. nor the names of its
|
||||||
|
* contributors may be used to endorse or promote products derived from
|
||||||
|
* this software without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||||
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||||
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||||
|
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||||
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||||
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||||
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||||
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||||
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||||
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef GRPC_INTERNAL_COMPILER_CPP_GENERATOR_H
|
||||||
|
#define GRPC_INTERNAL_COMPILER_CPP_GENERATOR_H
|
||||||
|
|
||||||
|
// cpp_generator.h/.cc do not directly depend on GRPC/ProtoBuf, such that they
|
||||||
|
// can be used to generate code for other serialization systems, such as
|
||||||
|
// FlatBuffers.
|
||||||
|
|
||||||
|
#include <memory>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
#include "src/compiler/schema_interface.h"
|
||||||
|
|
||||||
|
namespace grpc_cpp_generator {
|
||||||
|
|
||||||
|
// Contains all the parameters that are parsed from the command line.
|
||||||
|
struct Parameters {
|
||||||
|
// Puts the service into a namespace
|
||||||
|
grpc::string services_namespace;
|
||||||
|
// Use system includes (<>) or local includes ("")
|
||||||
|
bool use_system_headers;
|
||||||
|
// Prefix to any grpc include
|
||||||
|
grpc::string grpc_search_path;
|
||||||
|
};
|
||||||
|
|
||||||
|
// Return the prologue of the generated header file.
|
||||||
|
grpc::string GetHeaderPrologue(grpc_generator::File *file, const Parameters ¶ms);
|
||||||
|
|
||||||
|
// Return the includes needed for generated header file.
|
||||||
|
grpc::string GetHeaderIncludes(grpc_generator::File *file, const Parameters ¶ms);
|
||||||
|
|
||||||
|
// Return the includes needed for generated source file.
|
||||||
|
grpc::string GetSourceIncludes(grpc_generator::File *file, const Parameters ¶ms);
|
||||||
|
|
||||||
|
// Return the epilogue of the generated header file.
|
||||||
|
grpc::string GetHeaderEpilogue(grpc_generator::File *file, const Parameters ¶ms);
|
||||||
|
|
||||||
|
// Return the prologue of the generated source file.
|
||||||
|
grpc::string GetSourcePrologue(grpc_generator::File *file, const Parameters ¶ms);
|
||||||
|
|
||||||
|
// Return the services for generated header file.
|
||||||
|
grpc::string GetHeaderServices(grpc_generator::File *file, const Parameters ¶ms);
|
||||||
|
|
||||||
|
// Return the services for generated source file.
|
||||||
|
grpc::string GetSourceServices(grpc_generator::File *file, const Parameters ¶ms);
|
||||||
|
|
||||||
|
// Return the epilogue of the generated source file.
|
||||||
|
grpc::string GetSourceEpilogue(grpc_generator::File *file, const Parameters ¶ms);
|
||||||
|
|
||||||
|
} // namespace grpc_cpp_generator
|
||||||
|
|
||||||
|
#endif // GRPC_INTERNAL_COMPILER_CPP_GENERATOR_H
|
||||||
437
grpc/src/compiler/go_generator.cc
Normal file
437
grpc/src/compiler/go_generator.cc
Normal file
@@ -0,0 +1,437 @@
|
|||||||
|
/*
|
||||||
|
*
|
||||||
|
* Copyright 2015, Google Inc.
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions are
|
||||||
|
* met:
|
||||||
|
*
|
||||||
|
* * Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* * Redistributions in binary form must reproduce the above
|
||||||
|
* copyright notice, this list of conditions and the following disclaimer
|
||||||
|
* in the documentation AN/or other materials provided with the
|
||||||
|
* distribution.
|
||||||
|
* * Neither the name of Google Inc. nor the names of its
|
||||||
|
* contributors may be used to endorse or promote products derived from
|
||||||
|
* this software without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||||
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||||
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||||
|
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||||
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||||
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||||
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||||
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||||
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||||
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <map>
|
||||||
|
#include <cctype>
|
||||||
|
#include <sstream>
|
||||||
|
|
||||||
|
#include "src/compiler/go_generator.h"
|
||||||
|
|
||||||
|
template <class T>
|
||||||
|
grpc::string as_string(T x) {
|
||||||
|
std::ostringstream out;
|
||||||
|
out << x;
|
||||||
|
return out.str();
|
||||||
|
}
|
||||||
|
|
||||||
|
namespace grpc_go_generator {
|
||||||
|
|
||||||
|
// Returns string with first letter to lowerCase
|
||||||
|
grpc::string unexportName(grpc::string s) {
|
||||||
|
if (s.empty())
|
||||||
|
return s;
|
||||||
|
s[0] = static_cast<char>(std::tolower(s[0]));
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Returns string with first letter to uppercase
|
||||||
|
grpc::string exportName(grpc::string s) {
|
||||||
|
if (s.empty())
|
||||||
|
return s;
|
||||||
|
s[0] = static_cast<char>(std::toupper(s[0]));
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Generates imports for the service
|
||||||
|
void GenerateImports(grpc_generator::File *file, grpc_generator::Printer *printer,
|
||||||
|
std::map<grpc::string, grpc::string> vars) {
|
||||||
|
vars["filename"] = file->filename();
|
||||||
|
printer->Print("//Generated by gRPC Go plugin\n");
|
||||||
|
printer->Print("//If you make any local changes, they will be lost\n");
|
||||||
|
printer->Print(vars, "//source: $filename$\n\n");
|
||||||
|
printer->Print(vars, "package $Package$\n\n");
|
||||||
|
if (file->additional_imports() != "") {
|
||||||
|
printer->Print(file->additional_imports().c_str());
|
||||||
|
printer->Print("\n\n");
|
||||||
|
}
|
||||||
|
printer->Print("import (\n");
|
||||||
|
printer->Indent();
|
||||||
|
printer->Print(vars, "$context$ \"golang.org/x/net/context\"\n");
|
||||||
|
printer->Print(vars, "$grpc$ \"google.golang.org/grpc\"\n");
|
||||||
|
printer->Outdent();
|
||||||
|
printer->Print(")\n\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Generates Server method signature source
|
||||||
|
void GenerateServerMethodSignature(const grpc_generator::Method *method, grpc_generator::Printer *printer,
|
||||||
|
std::map<grpc::string, grpc::string> vars) {
|
||||||
|
vars["Method"] = exportName(method->name());
|
||||||
|
vars["Request"] = method->input_name();
|
||||||
|
vars["Response"] = (vars["CustomMethodIO"] == "") ? method->output_name() : vars["CustomMethodIO"];
|
||||||
|
if (method->NoStreaming()) {
|
||||||
|
printer->Print(vars, "$Method$($context$.Context, *$Request$) (*$Response$, error)");
|
||||||
|
} else if (method->ServerOnlyStreaming()) {
|
||||||
|
printer->Print(vars, "$Method$(*$Request$, $Service$_$Method$Server) error");
|
||||||
|
} else {
|
||||||
|
printer->Print(vars, "$Method$($Service$_$Method$Server) error");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void GenerateServerMethod(const grpc_generator::Method *method, grpc_generator::Printer *printer,
|
||||||
|
std::map<grpc::string, grpc::string> vars) {
|
||||||
|
vars["Method"] = exportName(method->name());
|
||||||
|
vars["Request"] = method->input_name();
|
||||||
|
vars["Response"] = (vars["CustomMethodIO"] == "") ? method->output_name() : vars["CustomMethodIO"];
|
||||||
|
vars["FullMethodName"] = "/" + vars["Package"] + "." + vars["Service"] + "/" + vars["Method"];
|
||||||
|
vars["Handler"] = "_" + vars["Service"] + "_" + vars["Method"] + "_Handler";
|
||||||
|
if (method->NoStreaming()) {
|
||||||
|
printer->Print(vars, "func $Handler$(srv interface{}, ctx $context$.Context,\n\tdec func(interface{}) error, interceptor $grpc$.UnaryServerInterceptor) (interface{}, error) {\n");
|
||||||
|
printer->Indent();
|
||||||
|
printer->Print(vars, "in := new($Request$)\n");
|
||||||
|
printer->Print("if err := dec(in); err != nil { return nil, err }\n");
|
||||||
|
printer->Print(vars, "if interceptor == nil { return srv.($Service$Server).$Method$(ctx, in) }\n");
|
||||||
|
printer->Print(vars, "info := &$grpc$.UnaryServerInfo{\n");
|
||||||
|
printer->Indent();
|
||||||
|
printer->Print("Server: srv,\n");
|
||||||
|
printer->Print(vars, "FullMethod: \"$FullMethodName$\",\n");
|
||||||
|
printer->Outdent();
|
||||||
|
printer->Print("}\n\n");
|
||||||
|
printer->Print(vars, "handler := func(ctx $context$.Context, req interface{}) (interface{}, error) {\n");
|
||||||
|
printer->Indent();
|
||||||
|
printer->Print(vars, "return srv.($Service$Server).$Method$(ctx, req.(* $Request$))\n");
|
||||||
|
printer->Outdent();
|
||||||
|
printer->Print("}\n");
|
||||||
|
printer->Print("return interceptor(ctx, in, info, handler)\n");
|
||||||
|
printer->Outdent();
|
||||||
|
printer->Print("}\n\n");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
vars["StreamType"] = vars["ServiceUnexported"] + vars["Method"] + "Server";
|
||||||
|
printer->Print(vars, "func $Handler$(srv interface{}, stream $grpc$.ServerStream) error {\n");
|
||||||
|
printer->Indent();
|
||||||
|
if (method->ServerOnlyStreaming()) {
|
||||||
|
printer->Print(vars, "m := new($Request$)\n");
|
||||||
|
printer->Print(vars, "if err := stream.RecvMsg(m); err != nil { return err }\n");
|
||||||
|
printer->Print(vars, "return srv.($Service$Server).$Method$(m, &$StreamType${stream})\n");
|
||||||
|
} else {
|
||||||
|
printer->Print(vars, "return srv.($Service$Server).$Method$(&$StreamType${stream})\n");
|
||||||
|
}
|
||||||
|
printer->Outdent();
|
||||||
|
printer->Print("}\n\n");
|
||||||
|
|
||||||
|
bool genSend = method->BidiStreaming() || method->ServerOnlyStreaming();
|
||||||
|
bool genRecv = method->BidiStreaming() || method->ClientOnlyStreaming();
|
||||||
|
bool genSendAndClose = method->ClientOnlyStreaming();
|
||||||
|
|
||||||
|
printer->Print(vars, "type $Service$_$Method$Server interface { \n");
|
||||||
|
printer->Indent();
|
||||||
|
if (genSend) {
|
||||||
|
printer->Print(vars, "Send(* $Response$) error\n");
|
||||||
|
}
|
||||||
|
if (genRecv) {
|
||||||
|
printer->Print(vars, "Recv() (* $Request$, error)\n");
|
||||||
|
}
|
||||||
|
if (genSendAndClose) {
|
||||||
|
printer->Print(vars, "SendAndClose(* $Response$) error\n");
|
||||||
|
}
|
||||||
|
printer->Print(vars, "$grpc$.ServerStream\n");
|
||||||
|
printer->Outdent();
|
||||||
|
printer->Print("}\n\n");
|
||||||
|
|
||||||
|
printer->Print(vars, "type $StreamType$ struct {\n");
|
||||||
|
printer->Indent();
|
||||||
|
printer->Print(vars, "$grpc$.ServerStream\n");
|
||||||
|
printer->Outdent();
|
||||||
|
printer->Print("}\n\n");
|
||||||
|
|
||||||
|
if (genSend) {
|
||||||
|
printer->Print(vars, "func (x *$StreamType$) Send(m *$Response$) error {\n");
|
||||||
|
printer->Indent();
|
||||||
|
printer->Print("return x.ServerStream.SendMsg(m)\n");
|
||||||
|
printer->Outdent();
|
||||||
|
printer->Print("}\n\n");
|
||||||
|
}
|
||||||
|
if (genRecv) {
|
||||||
|
printer->Print(vars, "func (x *$StreamType$) Recv() (*$Request$, error) {\n");
|
||||||
|
printer->Indent();
|
||||||
|
printer->Print(vars, "m := new($Request$)\n");
|
||||||
|
printer->Print("if err := x.ServerStream.RecvMsg(m); err != nil { return nil, err }\n");
|
||||||
|
printer->Print("return m, nil\n");
|
||||||
|
printer->Outdent();
|
||||||
|
printer->Print("}\n\n");
|
||||||
|
}
|
||||||
|
if (genSendAndClose) {
|
||||||
|
printer->Print(vars, "func (x *$StreamType$) SendAndClose(m *$Response$) error {\n");
|
||||||
|
printer->Indent();
|
||||||
|
printer->Print("return x.ServerStream.SendMsg(m)\n");
|
||||||
|
printer->Outdent();
|
||||||
|
printer->Print("}\n\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// Generates Client method signature source
|
||||||
|
void GenerateClientMethodSignature(const grpc_generator::Method *method, grpc_generator::Printer *printer,
|
||||||
|
std::map<grpc::string, grpc::string> vars) {
|
||||||
|
vars["Method"] = exportName(method->name());
|
||||||
|
vars["Request"] = ", in *" + ((vars["CustomMethodIO"] == "") ? method->input_name() : vars["CustomMethodIO"]);
|
||||||
|
if (method->ClientOnlyStreaming() || method->BidiStreaming()) {
|
||||||
|
vars["Request"] = "";
|
||||||
|
}
|
||||||
|
vars["Response"] = "* " + method->output_name();
|
||||||
|
if (method->ClientOnlyStreaming() || method->BidiStreaming() || method->ServerOnlyStreaming()) {
|
||||||
|
vars["Response"] = vars["Service"] + "_" + vars["Method"] + "Client" ;
|
||||||
|
}
|
||||||
|
printer->Print(vars, "$Method$(ctx $context$.Context$Request$, \n\topts... $grpc$.CallOption) ($Response$, error)");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Generates Client method source
|
||||||
|
void GenerateClientMethod(const grpc_generator::Method *method, grpc_generator::Printer *printer,
|
||||||
|
std::map<grpc::string, grpc::string> vars) {
|
||||||
|
printer->Print(vars, "func (c *$ServiceUnexported$Client) ");
|
||||||
|
GenerateClientMethodSignature(method, printer, vars);
|
||||||
|
printer->Print(" {\n");
|
||||||
|
printer->Indent();
|
||||||
|
vars["Method"] = exportName(method->name());
|
||||||
|
vars["Request"] = (vars["CustomMethodIO"] == "") ? method->input_name() : vars["CustomMethodIO"];
|
||||||
|
vars["Response"] = method->output_name();
|
||||||
|
vars["FullMethodName"] = "/" + vars["Package"] + "." + vars["Service"] + "/" + vars["Method"];
|
||||||
|
if (method->NoStreaming()) {
|
||||||
|
printer->Print(vars, "out := new($Response$)\n");
|
||||||
|
printer->Print(vars, "err := $grpc$.Invoke(ctx, \"$FullMethodName$\", in, out, c.cc, opts...)\n");
|
||||||
|
printer->Print("if err != nil { return nil, err }\n");
|
||||||
|
printer->Print("return out, nil\n");
|
||||||
|
printer->Outdent();
|
||||||
|
printer->Print("}\n\n");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
vars["StreamType"] = vars["ServiceUnexported"] + vars["Method"] + "Client";
|
||||||
|
printer->Print(vars, "stream, err := $grpc$.NewClientStream(ctx, &$MethodDesc$, c.cc, \"$FullMethodName$\", opts...)\n");
|
||||||
|
printer->Print("if err != nil { return nil, err }\n");
|
||||||
|
|
||||||
|
printer->Print(vars, "x := &$StreamType${stream}\n");
|
||||||
|
if (method->ServerOnlyStreaming()) {
|
||||||
|
printer->Print("if err := x.ClientStream.SendMsg(in); err != nil { return nil, err }\n");
|
||||||
|
printer->Print("if err := x.ClientStream.CloseSend(); err != nil { return nil, err }\n");
|
||||||
|
}
|
||||||
|
printer->Print("return x,nil\n");
|
||||||
|
printer->Outdent();
|
||||||
|
printer->Print("}\n\n");
|
||||||
|
|
||||||
|
bool genSend = method->BidiStreaming() || method->ClientOnlyStreaming();
|
||||||
|
bool genRecv = method->BidiStreaming() || method->ServerOnlyStreaming();
|
||||||
|
bool genCloseAndRecv = method->ClientOnlyStreaming();
|
||||||
|
|
||||||
|
//Stream interface
|
||||||
|
printer->Print(vars, "type $Service$_$Method$Client interface {\n");
|
||||||
|
printer->Indent();
|
||||||
|
if (genSend) {
|
||||||
|
printer->Print(vars, "Send(*$Request$) error\n");
|
||||||
|
}
|
||||||
|
if (genRecv) {
|
||||||
|
printer->Print(vars, "Recv() (*$Response$, error)\n");
|
||||||
|
}
|
||||||
|
if (genCloseAndRecv) {
|
||||||
|
printer->Print(vars, "CloseAndRecv() (*$Response$, error)\n");
|
||||||
|
}
|
||||||
|
printer->Print(vars, "$grpc$.ClientStream\n");
|
||||||
|
printer->Outdent();
|
||||||
|
printer->Print("}\n\n");
|
||||||
|
|
||||||
|
//Stream Client
|
||||||
|
printer->Print(vars, "type $StreamType$ struct{\n");
|
||||||
|
printer->Indent();
|
||||||
|
printer->Print(vars, "$grpc$.ClientStream\n");
|
||||||
|
printer->Outdent();
|
||||||
|
printer->Print("}\n\n");
|
||||||
|
|
||||||
|
if (genSend) {
|
||||||
|
printer->Print(vars, "func (x *$StreamType$) Send(m *$Request$) error {\n");
|
||||||
|
printer->Indent();
|
||||||
|
printer->Print("return x.ClientStream.SendMsg(m)\n");
|
||||||
|
printer->Outdent();
|
||||||
|
printer->Print("}\n\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (genRecv) {
|
||||||
|
printer->Print(vars, "func (x *$StreamType$) Recv() (*$Response$, error) {\n");
|
||||||
|
printer->Indent();
|
||||||
|
printer->Print(vars, "m := new($Response$)\n");
|
||||||
|
printer->Print("if err := x.ClientStream.RecvMsg(m); err != nil { return nil, err }\n");
|
||||||
|
printer->Print("return m, nil\n");
|
||||||
|
printer->Outdent();
|
||||||
|
printer->Print("}\n\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (genCloseAndRecv) {
|
||||||
|
printer->Print(vars, "func (x *$StreamType$) CloseAndRecv() (*$Response$, error) {\n");
|
||||||
|
printer->Indent();
|
||||||
|
printer->Print("if err := x.ClientStream.CloseSend(); err != nil { return nil, err }\n");
|
||||||
|
printer->Print(vars, "m := new ($Response$)\n");
|
||||||
|
printer->Print("if err := x.ClientStream.RecvMsg(m); err != nil { return nil, err }\n");
|
||||||
|
printer->Print("return m, nil\n");
|
||||||
|
printer->Outdent();
|
||||||
|
printer->Print("}\n\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Generates client API for the service
|
||||||
|
void GenerateService(const grpc_generator::Service *service, grpc_generator::Printer* printer,
|
||||||
|
std::map<grpc::string, grpc::string> vars) {
|
||||||
|
vars["Service"] = exportName(service->name());
|
||||||
|
// Client Interface
|
||||||
|
printer->Print(vars, "// Client API for $Service$ service\n");
|
||||||
|
printer->Print(vars, "type $Service$Client interface{\n");
|
||||||
|
printer->Indent();
|
||||||
|
for (int i = 0; i < service->method_count(); i++) {
|
||||||
|
GenerateClientMethodSignature(service->method(i).get(), printer, vars);
|
||||||
|
printer->Print("\n");
|
||||||
|
}
|
||||||
|
printer->Outdent();
|
||||||
|
printer->Print("}\n\n");
|
||||||
|
|
||||||
|
// Client structure
|
||||||
|
vars["ServiceUnexported"] = unexportName(vars["Service"]);
|
||||||
|
printer->Print(vars, "type $ServiceUnexported$Client struct {\n");
|
||||||
|
printer->Indent();
|
||||||
|
printer->Print(vars, "cc *$grpc$.ClientConn\n");
|
||||||
|
printer->Outdent();
|
||||||
|
printer->Print("}\n\n");
|
||||||
|
|
||||||
|
// NewClient
|
||||||
|
printer->Print(vars, "func New$Service$Client(cc *$grpc$.ClientConn) $Service$Client {\n");
|
||||||
|
printer->Indent();
|
||||||
|
printer->Print(vars, "return &$ServiceUnexported$Client{cc}");
|
||||||
|
printer->Outdent();
|
||||||
|
printer->Print("\n}\n\n");
|
||||||
|
|
||||||
|
int unary_methods = 0, streaming_methods = 0;
|
||||||
|
vars["ServiceDesc"] = "_" + vars["Service"] + "_serviceDesc";
|
||||||
|
for (int i = 0; i < service->method_count(); i++) {
|
||||||
|
auto method = service->method(i);
|
||||||
|
if (method->NoStreaming()) {
|
||||||
|
vars["MethodDesc"] = vars["ServiceDesc"] + ".Method[" + as_string(unary_methods) + "]";
|
||||||
|
unary_methods++;
|
||||||
|
} else {
|
||||||
|
vars["MethodDesc"] = vars["ServiceDesc"] + ".Streams[" + as_string(streaming_methods) + "]";
|
||||||
|
streaming_methods++;
|
||||||
|
}
|
||||||
|
GenerateClientMethod(method.get(), printer, vars);
|
||||||
|
}
|
||||||
|
|
||||||
|
//Server Interface
|
||||||
|
printer->Print(vars, "// Server API for $Service$ service\n");
|
||||||
|
printer->Print(vars, "type $Service$Server interface {\n");
|
||||||
|
printer->Indent();
|
||||||
|
for (int i = 0; i < service->method_count(); i++) {
|
||||||
|
GenerateServerMethodSignature(service->method(i).get(), printer, vars);
|
||||||
|
printer->Print("\n");
|
||||||
|
}
|
||||||
|
printer->Outdent();
|
||||||
|
printer->Print("}\n\n");
|
||||||
|
|
||||||
|
// Server registration.
|
||||||
|
printer->Print(vars, "func Register$Service$Server(s *$grpc$.Server, srv $Service$Server) {\n");
|
||||||
|
printer->Indent();
|
||||||
|
printer->Print(vars, "s.RegisterService(&$ServiceDesc$, srv)\n");
|
||||||
|
printer->Outdent();
|
||||||
|
printer->Print("}\n\n");
|
||||||
|
|
||||||
|
for (int i = 0; i < service->method_count(); i++) {
|
||||||
|
GenerateServerMethod(service->method(i).get(), printer, vars);
|
||||||
|
printer->Print("\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//Service Descriptor
|
||||||
|
printer->Print(vars, "var $ServiceDesc$ = $grpc$.ServiceDesc{\n");
|
||||||
|
printer->Indent();
|
||||||
|
printer->Print(vars, "ServiceName: \"$Package$.$Service$\",\n");
|
||||||
|
printer->Print(vars, "HandlerType: (*$Service$Server)(nil),\n");
|
||||||
|
printer->Print(vars, "Methods: []$grpc$.MethodDesc{\n");
|
||||||
|
printer->Indent();
|
||||||
|
for (int i = 0; i < service->method_count(); i++) {
|
||||||
|
auto method = service->method(i);
|
||||||
|
vars["Method"] = method->name();
|
||||||
|
vars["Handler"] = "_" + vars["Service"] + "_" + vars["Method"] + "_Handler";
|
||||||
|
if (method->NoStreaming()) {
|
||||||
|
printer->Print("{\n");
|
||||||
|
printer->Indent();
|
||||||
|
printer->Print(vars, "MethodName: \"$Method$\",\n");
|
||||||
|
printer->Print(vars, "Handler: $Handler$, \n");
|
||||||
|
printer->Outdent();
|
||||||
|
printer->Print("},\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
printer->Outdent();
|
||||||
|
printer->Print("},\n");
|
||||||
|
printer->Print(vars, "Streams: []$grpc$.StreamDesc{\n");
|
||||||
|
printer->Indent();
|
||||||
|
for (int i = 0; i < service->method_count(); i++) {
|
||||||
|
auto method = service->method(i);
|
||||||
|
vars["Method"] = method->name();
|
||||||
|
vars["Handler"] = "_" + vars["Service"] + "_" + vars["Method"] + "_Handler";
|
||||||
|
if (!method->NoStreaming()) {
|
||||||
|
printer->Print("{\n");
|
||||||
|
printer->Indent();
|
||||||
|
printer->Print(vars, "StreamName: \"$Method$\",\n");
|
||||||
|
printer->Print(vars, "Handler: $Handler$, \n");
|
||||||
|
if (method->ClientOnlyStreaming()) {
|
||||||
|
printer->Print("ClientStreams: true,\n");
|
||||||
|
} else if (method->ServerOnlyStreaming()) {
|
||||||
|
printer->Print("ServerStreams: true,\n");
|
||||||
|
} else {
|
||||||
|
printer->Print("ServerStreams: true,\n");
|
||||||
|
printer->Print("ClientStreams: true,\n");
|
||||||
|
}
|
||||||
|
printer->Outdent();
|
||||||
|
printer->Print("},\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
printer->Outdent();
|
||||||
|
printer->Print("},\n");
|
||||||
|
printer->Outdent();
|
||||||
|
printer->Print("}\n\n");
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Returns source for the service
|
||||||
|
grpc::string GenerateServiceSource(grpc_generator::File *file,
|
||||||
|
const grpc_generator::Service *service,
|
||||||
|
grpc_go_generator::Parameters *parameters) {
|
||||||
|
grpc::string out;
|
||||||
|
auto p = file->CreatePrinter(&out);
|
||||||
|
auto printer = p.get();
|
||||||
|
std::map<grpc::string, grpc::string> vars;
|
||||||
|
vars["Package"] = parameters->package_name;
|
||||||
|
vars["grpc"] = "grpc";
|
||||||
|
vars["context"] = "context";
|
||||||
|
GenerateImports(file, printer, vars);
|
||||||
|
if (parameters->custom_method_io_type != "") {
|
||||||
|
vars["CustomMethodIO"] = parameters->custom_method_io_type;
|
||||||
|
}
|
||||||
|
GenerateService(service, printer, vars);
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
}// Namespace grpc_go_generator
|
||||||
61
grpc/src/compiler/go_generator.h
Normal file
61
grpc/src/compiler/go_generator.h
Normal file
@@ -0,0 +1,61 @@
|
|||||||
|
/*
|
||||||
|
*
|
||||||
|
* Copyright 2015, Google Inc.
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions are
|
||||||
|
* met:
|
||||||
|
*
|
||||||
|
* * Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* * Redistributions in binary form must reproduce the above
|
||||||
|
* copyright notice, this list of conditions and the following disclaimer
|
||||||
|
* in the documentation and/or other materials provided with the
|
||||||
|
* distribution.
|
||||||
|
* * Neither the name of Google Inc. nor the names of its
|
||||||
|
* contributors may be used to endorse or promote products derived from
|
||||||
|
* this software without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||||
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||||
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||||
|
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||||
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||||
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||||
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||||
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||||
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||||
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef GRPC_INTERNAL_COMPILER_GO_GENERATOR_H
|
||||||
|
#define GRPC_INTERNAL_COMPILER_GO_GENERATOR_H
|
||||||
|
|
||||||
|
//go generator is used to generate GRPC code for serialization system, such as flatbuffers
|
||||||
|
#include <memory>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
#include "src/compiler/schema_interface.h"
|
||||||
|
|
||||||
|
namespace grpc_go_generator {
|
||||||
|
|
||||||
|
struct Parameters {
|
||||||
|
//Defines the custom parameter types for methods
|
||||||
|
//eg: flatbuffers uses flatbuffers.Builder as input for the client and output for the server
|
||||||
|
grpc::string custom_method_io_type;
|
||||||
|
|
||||||
|
//Package name for the service
|
||||||
|
grpc::string package_name;
|
||||||
|
};
|
||||||
|
|
||||||
|
// Return the source of the generated service file.
|
||||||
|
grpc::string GenerateServiceSource(grpc_generator::File *file,
|
||||||
|
const grpc_generator::Service *service,
|
||||||
|
grpc_go_generator::Parameters *parameters);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // GRPC_INTERNAL_COMPILER_GO_GENERATOR_H
|
||||||
112
grpc/src/compiler/schema_interface.h
Normal file
112
grpc/src/compiler/schema_interface.h
Normal file
@@ -0,0 +1,112 @@
|
|||||||
|
/*
|
||||||
|
*
|
||||||
|
* Copyright 2015, Google Inc.
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions are
|
||||||
|
* met:
|
||||||
|
*
|
||||||
|
* * Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* * Redistributions in binary form must reproduce the above
|
||||||
|
* copyright notice, this list of conditions and the following disclaimer
|
||||||
|
* in the documentation and/or other materials provided with the
|
||||||
|
* distribution.
|
||||||
|
* * Neither the name of Google Inc. nor the names of its
|
||||||
|
* contributors may be used to endorse or promote products derived from
|
||||||
|
* this software without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||||
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||||
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||||
|
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||||
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||||
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||||
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||||
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||||
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||||
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef GRPC_INTERNAL_COMPILER_SCHEMA_INTERFACE_H
|
||||||
|
#define GRPC_INTERNAL_COMPILER_SCHEMA_INTERFACE_H
|
||||||
|
|
||||||
|
#include <map>
|
||||||
|
#include <memory>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
#ifndef GRPC_CUSTOM_STRING
|
||||||
|
#include <string>
|
||||||
|
#define GRPC_CUSTOM_STRING std::string
|
||||||
|
#endif
|
||||||
|
|
||||||
|
namespace grpc {
|
||||||
|
|
||||||
|
typedef GRPC_CUSTOM_STRING string;
|
||||||
|
|
||||||
|
} // namespace grpc
|
||||||
|
|
||||||
|
namespace grpc_generator {
|
||||||
|
|
||||||
|
// An abstract interface representing a method.
|
||||||
|
struct Method {
|
||||||
|
virtual ~Method() {}
|
||||||
|
|
||||||
|
virtual grpc::string name() const = 0;
|
||||||
|
|
||||||
|
virtual grpc::string input_type_name() const = 0;
|
||||||
|
virtual grpc::string output_type_name() const = 0;
|
||||||
|
virtual grpc::string input_name() const = 0;
|
||||||
|
virtual grpc::string output_name() const = 0;
|
||||||
|
|
||||||
|
virtual bool NoStreaming() const = 0;
|
||||||
|
virtual bool ClientOnlyStreaming() const = 0;
|
||||||
|
virtual bool ServerOnlyStreaming() const = 0;
|
||||||
|
virtual bool BidiStreaming() const = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
// An abstract interface representing a service.
|
||||||
|
struct Service {
|
||||||
|
virtual ~Service() {}
|
||||||
|
|
||||||
|
virtual grpc::string name() const = 0;
|
||||||
|
|
||||||
|
virtual int method_count() const = 0;
|
||||||
|
virtual std::unique_ptr<const Method> method(int i) const = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct Printer {
|
||||||
|
virtual ~Printer() {}
|
||||||
|
|
||||||
|
virtual void Print(const std::map<grpc::string, grpc::string> &vars,
|
||||||
|
const char *template_string) = 0;
|
||||||
|
virtual void Print(const char *string) = 0;
|
||||||
|
virtual void Indent() = 0;
|
||||||
|
virtual void Outdent() = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
// An interface that allows the source generated to be output using various
|
||||||
|
// libraries/idls/serializers.
|
||||||
|
struct File {
|
||||||
|
virtual ~File() {}
|
||||||
|
|
||||||
|
virtual grpc::string filename() const = 0;
|
||||||
|
virtual grpc::string filename_without_ext() const = 0;
|
||||||
|
virtual grpc::string message_header_ext() const = 0;
|
||||||
|
virtual grpc::string service_header_ext() const = 0;
|
||||||
|
virtual grpc::string package() const = 0;
|
||||||
|
virtual std::vector<grpc::string> package_parts() const = 0;
|
||||||
|
virtual grpc::string additional_headers() const = 0;
|
||||||
|
virtual grpc::string additional_imports() const = 0;
|
||||||
|
|
||||||
|
virtual int service_count() const = 0;
|
||||||
|
virtual std::unique_ptr<const Service> service(int i) const = 0;
|
||||||
|
|
||||||
|
virtual std::unique_ptr<Printer> CreatePrinter(grpc::string *str) const = 0;
|
||||||
|
};
|
||||||
|
} // namespace grpc_generator
|
||||||
|
|
||||||
|
#endif // GRPC_INTERNAL_COMPILER_SCHEMA_INTERFACE_H
|
||||||
93
grpc/tests/go_test.go
Normal file
93
grpc/tests/go_test.go
Normal file
@@ -0,0 +1,93 @@
|
|||||||
|
package testing
|
||||||
|
|
||||||
|
import (
|
||||||
|
"../../tests/MyGame/Example"
|
||||||
|
|
||||||
|
"net"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"golang.org/x/net/context"
|
||||||
|
"google.golang.org/grpc"
|
||||||
|
)
|
||||||
|
|
||||||
|
type server struct{}
|
||||||
|
|
||||||
|
// test used to send and receive in grpc methods
|
||||||
|
var test = "Flatbuffers"
|
||||||
|
var addr = "0.0.0.0:50051"
|
||||||
|
|
||||||
|
// gRPC server store method
|
||||||
|
func (s *server) Store(context context.Context, in *Example.Monster) (*flatbuffers.Builder, error) {
|
||||||
|
b := flatbuffers.NewBuilder(0)
|
||||||
|
i := b.CreateString(test)
|
||||||
|
Example.StatStart(b)
|
||||||
|
Example.StatAddId(b, i)
|
||||||
|
b.Finish(Example.StatEnd(b))
|
||||||
|
return b, nil
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// gRPC server retrieve method
|
||||||
|
func (s *server) Retrieve(context context.Context, in *Example.Stat) (*flatbuffers.Builder, error) {
|
||||||
|
b := flatbuffers.NewBuilder(0)
|
||||||
|
i := b.CreateString(test)
|
||||||
|
Example.MonsterStart(b)
|
||||||
|
Example.MonsterAddName(b, i)
|
||||||
|
b.Finish(Example.MonsterEnd(b))
|
||||||
|
return b, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func StoreClient(c Example.MonsterStorageClient, t *testing.T) {
|
||||||
|
b := flatbuffers.NewBuilder(0)
|
||||||
|
i := b.CreateString(test)
|
||||||
|
Example.MonsterStart(b)
|
||||||
|
Example.MonsterAddName(b, i)
|
||||||
|
b.Finish(Example.MonsterEnd(b))
|
||||||
|
out, err := c.Store(context.Background(), b)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("Store client failed: %v", err)
|
||||||
|
}
|
||||||
|
if string(out.Id()) != test {
|
||||||
|
t.Errorf("StoreClient failed: expected=%s, got=%s\n", test, out.Id())
|
||||||
|
t.Fail()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func RetrieveClient(c Example.MonsterStorageClient, t *testing.T) {
|
||||||
|
b := flatbuffers.NewBuilder(0)
|
||||||
|
i := b.CreateString(test)
|
||||||
|
Example.StatStart(b)
|
||||||
|
Example.StatAddId(b, i)
|
||||||
|
b.Finish(Example.StatEnd(b))
|
||||||
|
out, err := c.Retrieve(context.Background(), b)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("Retrieve client failed: %v", err)
|
||||||
|
}
|
||||||
|
if string(out.Name()) != test {
|
||||||
|
t.Errorf("RetrieveClient failed: expected=%s, got=%s\n", test, out.Name())
|
||||||
|
t.Fail()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestGRPC(t *testing.T) {
|
||||||
|
lis, err := net.Listen("tcp", addr)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("Failed to listen: %v", err)
|
||||||
|
}
|
||||||
|
ser := grpc.NewServer(grpc.CustomCodec(flatbuffers.FlatbuffersCodec{}))
|
||||||
|
Example.RegisterMonsterStorageServer(ser, &server{})
|
||||||
|
go func() {
|
||||||
|
if err := ser.Serve(lis); err != nil {
|
||||||
|
t.Fatalf("Failed to serve: %v", err)
|
||||||
|
t.FailNow()
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
conn, err := grpc.Dial(addr, grpc.WithInsecure(), grpc.WithCodec(flatbuffers.FlatbuffersCodec{}))
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("Failed to connect: %v", err)
|
||||||
|
}
|
||||||
|
defer conn.Close()
|
||||||
|
client := Example.NewMonsterStorageClient(conn)
|
||||||
|
StoreClient(client, t)
|
||||||
|
RetrieveClient(client, t)
|
||||||
|
}
|
||||||
124
grpc/tests/grpctest.cpp
Normal file
124
grpc/tests/grpctest.cpp
Normal file
@@ -0,0 +1,124 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2014 Google Inc. All rights reserved.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <thread>
|
||||||
|
|
||||||
|
#include <grpc++/grpc++.h>
|
||||||
|
|
||||||
|
#include "monster_test_generated.h"
|
||||||
|
#include "monster_test.grpc.fb.h"
|
||||||
|
|
||||||
|
using namespace MyGame::Example;
|
||||||
|
|
||||||
|
// The callback implementation of our server, that derives from the generated
|
||||||
|
// code. It implements all rpcs specified in the FlatBuffers schema.
|
||||||
|
class ServiceImpl final : public MyGame::Example::MonsterStorage::Service {
|
||||||
|
virtual ::grpc::Status Store(::grpc::ServerContext* context,
|
||||||
|
const flatbuffers::BufferRef<Monster> *request,
|
||||||
|
flatbuffers::BufferRef<Stat> *response)
|
||||||
|
override {
|
||||||
|
// Create a response from the incoming request name.
|
||||||
|
fbb_.Clear();
|
||||||
|
auto stat_offset = CreateStat(fbb_, fbb_.CreateString("Hello, " +
|
||||||
|
request->GetRoot()->name()->str()));
|
||||||
|
fbb_.Finish(stat_offset);
|
||||||
|
// Since we keep reusing the same FlatBufferBuilder, the memory it owns
|
||||||
|
// remains valid until the next call (this BufferRef doesn't own the
|
||||||
|
// memory it points to).
|
||||||
|
*response = flatbuffers::BufferRef<Stat>(fbb_.GetBufferPointer(),
|
||||||
|
fbb_.GetSize());
|
||||||
|
return grpc::Status::OK;
|
||||||
|
}
|
||||||
|
virtual ::grpc::Status Retrieve(::grpc::ServerContext *context,
|
||||||
|
const flatbuffers::BufferRef<Stat> *request,
|
||||||
|
::grpc::ServerWriter< flatbuffers::BufferRef<Monster>>* writer)
|
||||||
|
override {
|
||||||
|
assert(false); // We're not actually using this RPC.
|
||||||
|
return grpc::Status::CANCELLED;
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
flatbuffers::FlatBufferBuilder fbb_;
|
||||||
|
};
|
||||||
|
|
||||||
|
// Track the server instance, so we can terminate it later.
|
||||||
|
grpc::Server *server_instance = nullptr;
|
||||||
|
// Mutex to protec this variable.
|
||||||
|
std::mutex wait_for_server;
|
||||||
|
std::condition_variable server_instance_cv;
|
||||||
|
|
||||||
|
// This function implements the server thread.
|
||||||
|
void RunServer() {
|
||||||
|
auto server_address = "0.0.0.0:50051";
|
||||||
|
// Callback interface we implemented above.
|
||||||
|
ServiceImpl service;
|
||||||
|
grpc::ServerBuilder builder;
|
||||||
|
builder.AddListeningPort(server_address, grpc::InsecureServerCredentials());
|
||||||
|
builder.RegisterService(&service);
|
||||||
|
|
||||||
|
// Start the server. Lock to change the variable we're changing.
|
||||||
|
wait_for_server.lock();
|
||||||
|
server_instance = builder.BuildAndStart().release();
|
||||||
|
wait_for_server.unlock();
|
||||||
|
server_instance_cv.notify_one();
|
||||||
|
|
||||||
|
std::cout << "Server listening on " << server_address << std::endl;
|
||||||
|
// This will block the thread and serve requests.
|
||||||
|
server_instance->Wait();
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(int /*argc*/, const char * /*argv*/[]) {
|
||||||
|
// Launch server.
|
||||||
|
std::thread server_thread(RunServer);
|
||||||
|
|
||||||
|
// wait for server to spin up.
|
||||||
|
std::unique_lock<std::mutex> lock(wait_for_server);
|
||||||
|
while (!server_instance) server_instance_cv.wait(lock);
|
||||||
|
|
||||||
|
// Now connect the client.
|
||||||
|
auto channel = grpc::CreateChannel("localhost:50051",
|
||||||
|
grpc::InsecureChannelCredentials());
|
||||||
|
auto stub = MyGame::Example::MonsterStorage::NewStub(channel);
|
||||||
|
|
||||||
|
grpc::ClientContext context;
|
||||||
|
|
||||||
|
// Build a request with the name set.
|
||||||
|
flatbuffers::FlatBufferBuilder fbb;
|
||||||
|
auto monster_offset = CreateMonster(fbb, 0, 0, 0, fbb.CreateString("Fred"));
|
||||||
|
fbb.Finish(monster_offset);
|
||||||
|
auto request = flatbuffers::BufferRef<Monster>(fbb.GetBufferPointer(),
|
||||||
|
fbb.GetSize());
|
||||||
|
flatbuffers::BufferRef<Stat> response;
|
||||||
|
|
||||||
|
// The actual RPC.
|
||||||
|
auto status = stub->Store(&context, request, &response);
|
||||||
|
|
||||||
|
if (status.ok()) {
|
||||||
|
auto resp = response.GetRoot()->id();
|
||||||
|
std::cout << "RPC response: " << resp->str() << std::endl;
|
||||||
|
} else {
|
||||||
|
std::cout << "RPC failed" << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
server_instance->Shutdown();
|
||||||
|
|
||||||
|
server_thread.join();
|
||||||
|
|
||||||
|
delete server_instance;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
137
include/flatbuffers/code_generators.h
Normal file
137
include/flatbuffers/code_generators.h
Normal file
@@ -0,0 +1,137 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2014 Google Inc. All rights reserved.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef FLATBUFFERS_CODE_GENERATORS_H_
|
||||||
|
#define FLATBUFFERS_CODE_GENERATORS_H_
|
||||||
|
|
||||||
|
#include <map>
|
||||||
|
#include <sstream>
|
||||||
|
#include "flatbuffers/idl.h"
|
||||||
|
|
||||||
|
namespace flatbuffers {
|
||||||
|
|
||||||
|
// Utility class to assist in generating code through use of text templates.
|
||||||
|
//
|
||||||
|
// Example code:
|
||||||
|
// CodeWriter code;
|
||||||
|
// code.SetValue("NAME", "Foo");
|
||||||
|
// code += "void {{NAME}}() { printf("%s", "{{NAME}}"); }";
|
||||||
|
// code.SetValue("NAME", "Bar");
|
||||||
|
// code += "void {{NAME}}() { printf("%s", "{{NAME}}"); }";
|
||||||
|
// std::cout << code.ToString() << std::endl;
|
||||||
|
//
|
||||||
|
// Output:
|
||||||
|
// void Foo() { printf("%s", "Foo"); }
|
||||||
|
// void Bar() { printf("%s", "Bar"); }
|
||||||
|
class CodeWriter {
|
||||||
|
public:
|
||||||
|
CodeWriter() {}
|
||||||
|
|
||||||
|
// Clears the current "written" code.
|
||||||
|
void Clear() {
|
||||||
|
stream_.str("");
|
||||||
|
stream_.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Associates a key with a value. All subsequent calls to operator+=, where
|
||||||
|
// the specified key is contained in {{ and }} delimiters will be replaced by
|
||||||
|
// the given value.
|
||||||
|
void SetValue(const std::string& key, const std::string& value) {
|
||||||
|
value_map_[key] = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Appends the given text to the generated code as well as a newline
|
||||||
|
// character. Any text within {{ and }} delimeters is replaced by values
|
||||||
|
// previously stored in the CodeWriter by calling SetValue above. The newline
|
||||||
|
// will be suppressed if the text ends with the \\ character.
|
||||||
|
void operator+=(std::string text);
|
||||||
|
|
||||||
|
// Returns the current contents of the CodeWriter as a std::string.
|
||||||
|
std::string ToString() const { return stream_.str(); }
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::map<std::string, std::string> value_map_;
|
||||||
|
std::stringstream stream_;
|
||||||
|
};
|
||||||
|
|
||||||
|
class BaseGenerator {
|
||||||
|
public:
|
||||||
|
virtual bool generate() = 0;
|
||||||
|
|
||||||
|
static std::string NamespaceDir(const Parser &parser,
|
||||||
|
const std::string &path,
|
||||||
|
const Namespace &ns);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
BaseGenerator(const Parser &parser, const std::string &path,
|
||||||
|
const std::string &file_name,
|
||||||
|
const std::string qualifying_start,
|
||||||
|
const std::string qualifying_separator)
|
||||||
|
: parser_(parser),
|
||||||
|
path_(path),
|
||||||
|
file_name_(file_name),
|
||||||
|
qualifying_start_(qualifying_start),
|
||||||
|
qualifying_separator_(qualifying_separator) {}
|
||||||
|
virtual ~BaseGenerator() {}
|
||||||
|
|
||||||
|
// No copy/assign.
|
||||||
|
BaseGenerator &operator=(const BaseGenerator &);
|
||||||
|
BaseGenerator(const BaseGenerator &);
|
||||||
|
|
||||||
|
std::string NamespaceDir(const Namespace &ns) const;
|
||||||
|
|
||||||
|
static const char *FlatBuffersGeneratedWarning();
|
||||||
|
|
||||||
|
bool IsEverythingGenerated() const;
|
||||||
|
|
||||||
|
static std::string FullNamespace(const char *separator, const Namespace &ns);
|
||||||
|
|
||||||
|
static std::string LastNamespacePart(const Namespace &ns);
|
||||||
|
|
||||||
|
// tracks the current namespace for early exit in WrapInNameSpace
|
||||||
|
// c++, java and csharp returns a different namespace from
|
||||||
|
// the following default (no early exit, always fully qualify),
|
||||||
|
// which works for js and php
|
||||||
|
virtual const Namespace *CurrentNameSpace() const { return nullptr; }
|
||||||
|
|
||||||
|
// Ensure that a type is prefixed with its namespace whenever it is used
|
||||||
|
// outside of its namespace.
|
||||||
|
std::string WrapInNameSpace(const Namespace *ns,
|
||||||
|
const std::string &name) const;
|
||||||
|
|
||||||
|
std::string WrapInNameSpace(const Definition &def) const;
|
||||||
|
|
||||||
|
const Parser &parser_;
|
||||||
|
const std::string &path_;
|
||||||
|
const std::string &file_name_;
|
||||||
|
const std::string qualifying_start_;
|
||||||
|
const std::string qualifying_separator_;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct CommentConfig {
|
||||||
|
const char *first_line;
|
||||||
|
const char *content_line_prefix;
|
||||||
|
const char *last_line;
|
||||||
|
};
|
||||||
|
|
||||||
|
extern void GenComment(const std::vector<std::string> &dc,
|
||||||
|
std::string *code_ptr,
|
||||||
|
const CommentConfig *config,
|
||||||
|
const char *prefix = "");
|
||||||
|
|
||||||
|
} // namespace flatbuffers
|
||||||
|
|
||||||
|
#endif // FLATBUFFERS_CODE_GENERATORS_H_
|
||||||
File diff suppressed because it is too large
Load Diff
96
include/flatbuffers/flatc.h
Normal file
96
include/flatbuffers/flatc.h
Normal file
@@ -0,0 +1,96 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2017 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 "flatbuffers/flatbuffers.h"
|
||||||
|
#include "flatbuffers/idl.h"
|
||||||
|
#include "flatbuffers/util.h"
|
||||||
|
#include <functional>
|
||||||
|
#include <limits>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
#ifndef FLATC_H_
|
||||||
|
#define FLATC_H_
|
||||||
|
|
||||||
|
namespace flatbuffers {
|
||||||
|
|
||||||
|
class FlatCompiler {
|
||||||
|
public:
|
||||||
|
// Output generator for the various programming languages and formats we
|
||||||
|
// support.
|
||||||
|
struct Generator {
|
||||||
|
typedef bool (*GenerateFn)(const flatbuffers::Parser &parser,
|
||||||
|
const std::string &path,
|
||||||
|
const std::string &file_name);
|
||||||
|
typedef std::string (*MakeRuleFn)(const flatbuffers::Parser &parser,
|
||||||
|
const std::string &path,
|
||||||
|
const std::string &file_name);
|
||||||
|
|
||||||
|
GenerateFn generate;
|
||||||
|
const char *generator_opt_short;
|
||||||
|
const char *generator_opt_long;
|
||||||
|
const char *lang_name;
|
||||||
|
GenerateFn generateGRPC;
|
||||||
|
flatbuffers::IDLOptions::Language lang;
|
||||||
|
const char *generator_help;
|
||||||
|
MakeRuleFn make_rule;
|
||||||
|
};
|
||||||
|
|
||||||
|
typedef void (*WarnFn)(const FlatCompiler *flatc,
|
||||||
|
const std::string &warn,
|
||||||
|
bool show_exe_name);
|
||||||
|
|
||||||
|
typedef void (*ErrorFn)(const FlatCompiler *flatc,
|
||||||
|
const std::string &err,
|
||||||
|
bool usage, bool show_exe_name);
|
||||||
|
|
||||||
|
// Parameters required to initialize the FlatCompiler.
|
||||||
|
struct InitParams {
|
||||||
|
InitParams()
|
||||||
|
: generators(nullptr),
|
||||||
|
num_generators(0),
|
||||||
|
warn_fn(nullptr),
|
||||||
|
error_fn(nullptr) {}
|
||||||
|
|
||||||
|
const Generator* generators;
|
||||||
|
size_t num_generators;
|
||||||
|
WarnFn warn_fn;
|
||||||
|
ErrorFn error_fn;
|
||||||
|
};
|
||||||
|
|
||||||
|
explicit FlatCompiler(const InitParams& params) : params_(params) {}
|
||||||
|
|
||||||
|
int Compile(int argc, const char** argv);
|
||||||
|
|
||||||
|
std::string GetUsageString(const char* program_name) const;
|
||||||
|
|
||||||
|
private:
|
||||||
|
void ParseFile(flatbuffers::Parser &parser,
|
||||||
|
const std::string &filename,
|
||||||
|
const std::string &contents,
|
||||||
|
std::vector<const char *> &include_directories) const;
|
||||||
|
|
||||||
|
void Warn(const std::string &warn, bool show_exe_name = true) const;
|
||||||
|
|
||||||
|
void Error(const std::string &err, bool usage = true,
|
||||||
|
bool show_exe_name = true) const;
|
||||||
|
|
||||||
|
InitParams params_;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
} // namespace flatbuffers
|
||||||
|
|
||||||
|
#endif // FLATC_H_
|
||||||
1341
include/flatbuffers/flexbuffers.h
Normal file
1341
include/flatbuffers/flexbuffers.h
Normal file
File diff suppressed because it is too large
Load Diff
70
include/flatbuffers/grpc.h
Normal file
70
include/flatbuffers/grpc.h
Normal file
@@ -0,0 +1,70 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2014 Google Inc. All rights reserved.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef FLATBUFFERS_GRPC_H_
|
||||||
|
#define FLATBUFFERS_GRPC_H_
|
||||||
|
|
||||||
|
// Helper functionality to glue FlatBuffers and GRPC.
|
||||||
|
|
||||||
|
#include "grpc++/support/byte_buffer.h"
|
||||||
|
#include "grpc/byte_buffer_reader.h"
|
||||||
|
|
||||||
|
namespace grpc {
|
||||||
|
|
||||||
|
template <class T>
|
||||||
|
class SerializationTraits<T, typename std::enable_if<std::is_base_of<
|
||||||
|
flatbuffers::BufferRefBase, T>::value>::type> {
|
||||||
|
public:
|
||||||
|
// The type we're passing here is a BufferRef, which is already serialized
|
||||||
|
// FlatBuffer data, which then gets passed to GRPC.
|
||||||
|
static grpc::Status Serialize(const T& msg,
|
||||||
|
grpc_byte_buffer **buffer,
|
||||||
|
bool *own_buffer) {
|
||||||
|
// TODO(wvo): make this work without copying.
|
||||||
|
auto slice = gpr_slice_from_copied_buffer(
|
||||||
|
reinterpret_cast<const char *>(msg.buf), msg.len);
|
||||||
|
*buffer = grpc_raw_byte_buffer_create(&slice, 1);
|
||||||
|
*own_buffer = true;
|
||||||
|
return grpc::Status();
|
||||||
|
}
|
||||||
|
|
||||||
|
// There is no de-serialization step in FlatBuffers, so we just receive
|
||||||
|
// the data from GRPC.
|
||||||
|
static grpc::Status Deserialize(grpc_byte_buffer *buffer, T *msg) {
|
||||||
|
// TODO(wvo): make this more efficient / zero copy when possible.
|
||||||
|
auto len = grpc_byte_buffer_length(buffer);
|
||||||
|
msg->buf = reinterpret_cast<uint8_t *>(malloc(len));
|
||||||
|
msg->len = static_cast<flatbuffers::uoffset_t>(len);
|
||||||
|
msg->must_free = true;
|
||||||
|
uint8_t *current = msg->buf;
|
||||||
|
grpc_byte_buffer_reader reader;
|
||||||
|
grpc_byte_buffer_reader_init(&reader, buffer);
|
||||||
|
gpr_slice slice;
|
||||||
|
while (grpc_byte_buffer_reader_next(&reader, &slice)) {
|
||||||
|
memcpy(current, GPR_SLICE_START_PTR(slice), GPR_SLICE_LENGTH(slice));
|
||||||
|
current += GPR_SLICE_LENGTH(slice);
|
||||||
|
gpr_slice_unref(slice);
|
||||||
|
}
|
||||||
|
GPR_ASSERT(current == msg->buf + msg->len);
|
||||||
|
grpc_byte_buffer_reader_destroy(&reader);
|
||||||
|
grpc_byte_buffer_destroy(buffer);
|
||||||
|
return grpc::Status();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace grpc;
|
||||||
|
|
||||||
|
#endif // FLATBUFFERS_GRPC_H_
|
||||||
@@ -18,7 +18,6 @@
|
|||||||
#define FLATBUFFERS_IDL_H_
|
#define FLATBUFFERS_IDL_H_
|
||||||
|
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <set>
|
|
||||||
#include <stack>
|
#include <stack>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
@@ -103,6 +102,8 @@ inline bool IsInteger(BaseType t) { return t >= BASE_TYPE_UTYPE &&
|
|||||||
t <= BASE_TYPE_ULONG; }
|
t <= BASE_TYPE_ULONG; }
|
||||||
inline bool IsFloat (BaseType t) { return t == BASE_TYPE_FLOAT ||
|
inline bool IsFloat (BaseType t) { return t == BASE_TYPE_FLOAT ||
|
||||||
t == BASE_TYPE_DOUBLE; }
|
t == BASE_TYPE_DOUBLE; }
|
||||||
|
inline bool IsLong (BaseType t) { return t == BASE_TYPE_LONG ||
|
||||||
|
t == BASE_TYPE_ULONG; }
|
||||||
|
|
||||||
extern const char *const kTypeNames[];
|
extern const char *const kTypeNames[];
|
||||||
extern const char kTypeSizes[];
|
extern const char kTypeSizes[];
|
||||||
@@ -113,6 +114,7 @@ inline size_t SizeOf(BaseType t) {
|
|||||||
|
|
||||||
struct StructDef;
|
struct StructDef;
|
||||||
struct EnumDef;
|
struct EnumDef;
|
||||||
|
class Parser;
|
||||||
|
|
||||||
// Represents any type in the IDL, which is a combination of the BaseType
|
// Represents any type in the IDL, which is a combination of the BaseType
|
||||||
// and additional information for vectors/structs_.
|
// and additional information for vectors/structs_.
|
||||||
@@ -184,10 +186,8 @@ template<typename T> class SymbolTable {
|
|||||||
return it == dict.end() ? nullptr : it->second;
|
return it == dict.end() ? nullptr : it->second;
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
|
||||||
std::map<std::string, T *> dict; // quick lookup
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
std::map<std::string, T *> dict; // quick lookup
|
||||||
std::vector<T *> vec; // Used to iterate in order of insertion
|
std::vector<T *> vec; // Used to iterate in order of insertion
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -208,6 +208,11 @@ struct Definition {
|
|||||||
Definition() : generated(false), defined_namespace(nullptr),
|
Definition() : generated(false), defined_namespace(nullptr),
|
||||||
serialized_location(0), index(-1) {}
|
serialized_location(0), index(-1) {}
|
||||||
|
|
||||||
|
flatbuffers::Offset<flatbuffers::Vector<flatbuffers::Offset<
|
||||||
|
reflection::KeyValue>>>
|
||||||
|
SerializeAttributes(FlatBufferBuilder *builder,
|
||||||
|
const Parser &parser) const;
|
||||||
|
|
||||||
std::string name;
|
std::string name;
|
||||||
std::string file;
|
std::string file;
|
||||||
std::vector<std::string> doc_comment;
|
std::vector<std::string> doc_comment;
|
||||||
@@ -223,14 +228,16 @@ struct Definition {
|
|||||||
struct FieldDef : public Definition {
|
struct FieldDef : public Definition {
|
||||||
FieldDef() : deprecated(false), required(false), key(false), padding(0) {}
|
FieldDef() : deprecated(false), required(false), key(false), padding(0) {}
|
||||||
|
|
||||||
Offset<reflection::Field> Serialize(FlatBufferBuilder *builder, uint16_t id)
|
Offset<reflection::Field> Serialize(FlatBufferBuilder *builder, uint16_t id,
|
||||||
const;
|
const Parser &parser) const;
|
||||||
|
|
||||||
Value value;
|
Value value;
|
||||||
bool deprecated; // Field is allowed to be present in old data, but can't be
|
bool deprecated; // Field is allowed to be present in old data, but can't be
|
||||||
// written in new data nor accessed in new code.
|
// written in new data nor accessed in new code.
|
||||||
bool required; // Field must always be present.
|
bool required; // Field must always be present.
|
||||||
bool key; // Field functions as a key for creating sorted vectors.
|
bool key; // Field functions as a key for creating sorted vectors.
|
||||||
|
bool native_inline; // Field will be defined inline (instead of as a pointer)
|
||||||
|
// for native tables if field is a struct.
|
||||||
size_t padding; // Bytes to always pad after this field.
|
size_t padding; // Bytes to always pad after this field.
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -250,7 +257,8 @@ struct StructDef : public Definition {
|
|||||||
if (fields.vec.size()) fields.vec.back()->padding = padding;
|
if (fields.vec.size()) fields.vec.back()->padding = padding;
|
||||||
}
|
}
|
||||||
|
|
||||||
Offset<reflection::Object> Serialize(FlatBufferBuilder *builder) const;
|
Offset<reflection::Object> Serialize(FlatBufferBuilder *builder,
|
||||||
|
const Parser &parser) const;
|
||||||
|
|
||||||
SymbolTable<FieldDef> fields;
|
SymbolTable<FieldDef> fields;
|
||||||
bool fixed; // If it's struct, not a table.
|
bool fixed; // If it's struct, not a table.
|
||||||
@@ -299,17 +307,37 @@ struct EnumDef : public Definition {
|
|||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
Offset<reflection::Enum> Serialize(FlatBufferBuilder *builder) const;
|
Offset<reflection::Enum> Serialize(FlatBufferBuilder *builder,
|
||||||
|
const Parser &parser) const;
|
||||||
|
|
||||||
SymbolTable<EnumVal> vals;
|
SymbolTable<EnumVal> vals;
|
||||||
bool is_union;
|
bool is_union;
|
||||||
Type underlying_type;
|
Type underlying_type;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
inline bool EqualByName(const Type &a, const Type &b) {
|
||||||
|
return a.base_type == b.base_type && a.element == b.element &&
|
||||||
|
(a.struct_def == b.struct_def ||
|
||||||
|
a.struct_def->name == b.struct_def->name) &&
|
||||||
|
(a.enum_def == b.enum_def ||
|
||||||
|
a.enum_def->name == b.enum_def->name);
|
||||||
|
}
|
||||||
|
|
||||||
|
struct RPCCall {
|
||||||
|
std::string name;
|
||||||
|
SymbolTable<Value> attributes;
|
||||||
|
StructDef *request, *response;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct ServiceDef : public Definition {
|
||||||
|
SymbolTable<RPCCall> calls;
|
||||||
|
};
|
||||||
|
|
||||||
// Container of options that may apply to any of the source/text generators.
|
// Container of options that may apply to any of the source/text generators.
|
||||||
struct IDLOptions {
|
struct IDLOptions {
|
||||||
bool strict_json;
|
bool strict_json;
|
||||||
bool skip_js_exports;
|
bool skip_js_exports;
|
||||||
|
bool use_goog_js_export_format;
|
||||||
bool output_default_scalars_in_json;
|
bool output_default_scalars_in_json;
|
||||||
int indent_step;
|
int indent_step;
|
||||||
bool output_enum_identifiers;
|
bool output_enum_identifiers;
|
||||||
@@ -321,15 +349,39 @@ struct IDLOptions {
|
|||||||
bool proto_mode;
|
bool proto_mode;
|
||||||
bool generate_all;
|
bool generate_all;
|
||||||
bool skip_unexpected_fields_in_json;
|
bool skip_unexpected_fields_in_json;
|
||||||
|
bool generate_name_strings;
|
||||||
|
bool escape_proto_identifiers;
|
||||||
|
bool generate_object_based_api;
|
||||||
|
std::string cpp_object_api_pointer_type;
|
||||||
|
bool union_value_namespacing;
|
||||||
|
bool allow_non_utf8;
|
||||||
|
std::string include_prefix;
|
||||||
|
bool binary_schema_comments;
|
||||||
|
|
||||||
// Possible options for the more general generator below.
|
// Possible options for the more general generator below.
|
||||||
enum Language { kJava, kCSharp, kGo, kMAX };
|
enum Language {
|
||||||
|
kJava = 1 << 0,
|
||||||
|
kCSharp = 1 << 1,
|
||||||
|
kGo = 1 << 2,
|
||||||
|
kCpp = 1 << 3,
|
||||||
|
kJs = 1 << 4,
|
||||||
|
kPython = 1 << 5,
|
||||||
|
kPhp = 1 << 6,
|
||||||
|
kJson = 1 << 7,
|
||||||
|
kBinary = 1 << 8,
|
||||||
|
kMAX
|
||||||
|
};
|
||||||
|
|
||||||
Language lang;
|
Language lang;
|
||||||
|
|
||||||
|
// The corresponding language bit will be set if a language is included
|
||||||
|
// for code generation.
|
||||||
|
unsigned long lang_to_generate;
|
||||||
|
|
||||||
IDLOptions()
|
IDLOptions()
|
||||||
: strict_json(false),
|
: strict_json(false),
|
||||||
skip_js_exports(false),
|
skip_js_exports(false),
|
||||||
|
use_goog_js_export_format(false),
|
||||||
output_default_scalars_in_json(false),
|
output_default_scalars_in_json(false),
|
||||||
indent_step(2),
|
indent_step(2),
|
||||||
output_enum_identifiers(true), prefixed_enums(true), scoped_enums(false),
|
output_enum_identifiers(true), prefixed_enums(true), scoped_enums(false),
|
||||||
@@ -339,7 +391,28 @@ struct IDLOptions {
|
|||||||
proto_mode(false),
|
proto_mode(false),
|
||||||
generate_all(false),
|
generate_all(false),
|
||||||
skip_unexpected_fields_in_json(false),
|
skip_unexpected_fields_in_json(false),
|
||||||
lang(IDLOptions::kJava) {}
|
generate_name_strings(false),
|
||||||
|
escape_proto_identifiers(false),
|
||||||
|
generate_object_based_api(false),
|
||||||
|
cpp_object_api_pointer_type("std::unique_ptr"),
|
||||||
|
union_value_namespacing(true),
|
||||||
|
allow_non_utf8(false),
|
||||||
|
binary_schema_comments(false),
|
||||||
|
lang(IDLOptions::kJava),
|
||||||
|
lang_to_generate(0) {}
|
||||||
|
};
|
||||||
|
|
||||||
|
// This encapsulates where the parser is in the current source file.
|
||||||
|
struct ParserState {
|
||||||
|
ParserState() : cursor_(nullptr), line_(1), token_(-1) {}
|
||||||
|
|
||||||
|
protected:
|
||||||
|
const char *cursor_;
|
||||||
|
int line_; // the current line being parsed
|
||||||
|
int token_;
|
||||||
|
|
||||||
|
std::string attribute_;
|
||||||
|
std::vector<std::string> doc_comment_;
|
||||||
};
|
};
|
||||||
|
|
||||||
// A way to make error propagation less error prone by requiring values to be
|
// A way to make error propagation less error prone by requiring values to be
|
||||||
@@ -383,27 +456,32 @@ class CheckedError {
|
|||||||
#define FLATBUFFERS_CHECKED_ERROR CheckedError
|
#define FLATBUFFERS_CHECKED_ERROR CheckedError
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
class Parser {
|
class Parser : public ParserState {
|
||||||
public:
|
public:
|
||||||
explicit Parser(const IDLOptions &options = IDLOptions())
|
explicit Parser(const IDLOptions &options = IDLOptions())
|
||||||
: root_struct_def_(nullptr),
|
: root_struct_def_(nullptr),
|
||||||
opts(options),
|
opts(options),
|
||||||
source_(nullptr),
|
source_(nullptr),
|
||||||
cursor_(nullptr),
|
|
||||||
line_(1),
|
|
||||||
anonymous_counter(0) {
|
anonymous_counter(0) {
|
||||||
// Just in case none are declared:
|
// Just in case none are declared:
|
||||||
namespaces_.push_back(new Namespace());
|
namespaces_.push_back(new Namespace());
|
||||||
known_attributes_.insert("deprecated");
|
known_attributes_["deprecated"] = true;
|
||||||
known_attributes_.insert("required");
|
known_attributes_["required"] = true;
|
||||||
known_attributes_.insert("key");
|
known_attributes_["key"] = true;
|
||||||
known_attributes_.insert("hash");
|
known_attributes_["hash"] = true;
|
||||||
known_attributes_.insert("id");
|
known_attributes_["id"] = true;
|
||||||
known_attributes_.insert("force_align");
|
known_attributes_["force_align"] = true;
|
||||||
known_attributes_.insert("bit_flags");
|
known_attributes_["bit_flags"] = true;
|
||||||
known_attributes_.insert("original_order");
|
known_attributes_["original_order"] = true;
|
||||||
known_attributes_.insert("nested_flatbuffer");
|
known_attributes_["nested_flatbuffer"] = true;
|
||||||
known_attributes_.insert("csharp_partial");
|
known_attributes_["csharp_partial"] = true;
|
||||||
|
known_attributes_["streaming"] = true;
|
||||||
|
known_attributes_["idempotent"] = true;
|
||||||
|
known_attributes_["cpp_type"] = true;
|
||||||
|
known_attributes_["cpp_ptr_type"] = true;
|
||||||
|
known_attributes_["native_inline"] = true;
|
||||||
|
known_attributes_["native_type"] = true;
|
||||||
|
known_attributes_["native_default"] = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
~Parser() {
|
~Parser() {
|
||||||
@@ -439,11 +517,15 @@ class Parser {
|
|||||||
// See reflection/reflection.fbs
|
// See reflection/reflection.fbs
|
||||||
void Serialize();
|
void Serialize();
|
||||||
|
|
||||||
|
// Checks that the schema represented by this parser is a safe evolution
|
||||||
|
// of the schema provided. Returns non-empty error on any problems.
|
||||||
|
std::string ConformTo(const Parser &base);
|
||||||
|
|
||||||
FLATBUFFERS_CHECKED_ERROR CheckBitsFit(int64_t val, size_t bits);
|
FLATBUFFERS_CHECKED_ERROR CheckBitsFit(int64_t val, size_t bits);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
FLATBUFFERS_CHECKED_ERROR Error(const std::string &msg);
|
FLATBUFFERS_CHECKED_ERROR Error(const std::string &msg);
|
||||||
FLATBUFFERS_CHECKED_ERROR ParseHexNum(int nibbles, int64_t *val);
|
FLATBUFFERS_CHECKED_ERROR ParseHexNum(int nibbles, uint64_t *val);
|
||||||
FLATBUFFERS_CHECKED_ERROR Next();
|
FLATBUFFERS_CHECKED_ERROR Next();
|
||||||
FLATBUFFERS_CHECKED_ERROR SkipByteOrderMark();
|
FLATBUFFERS_CHECKED_ERROR SkipByteOrderMark();
|
||||||
bool Is(int t);
|
bool Is(int t);
|
||||||
@@ -459,18 +541,19 @@ private:
|
|||||||
FieldDef **dest);
|
FieldDef **dest);
|
||||||
FLATBUFFERS_CHECKED_ERROR ParseField(StructDef &struct_def);
|
FLATBUFFERS_CHECKED_ERROR ParseField(StructDef &struct_def);
|
||||||
FLATBUFFERS_CHECKED_ERROR ParseAnyValue(Value &val, FieldDef *field,
|
FLATBUFFERS_CHECKED_ERROR ParseAnyValue(Value &val, FieldDef *field,
|
||||||
size_t parent_fieldn);
|
size_t parent_fieldn,
|
||||||
|
const StructDef *parent_struct_def);
|
||||||
FLATBUFFERS_CHECKED_ERROR ParseTable(const StructDef &struct_def,
|
FLATBUFFERS_CHECKED_ERROR ParseTable(const StructDef &struct_def,
|
||||||
std::string *value, uoffset_t *ovalue);
|
std::string *value, uoffset_t *ovalue);
|
||||||
void SerializeStruct(const StructDef &struct_def, const Value &val);
|
void SerializeStruct(const StructDef &struct_def, const Value &val);
|
||||||
void AddVector(bool sortbysize, int count);
|
void AddVector(bool sortbysize, int count);
|
||||||
FLATBUFFERS_CHECKED_ERROR ParseVector(const Type &type, uoffset_t *ovalue);
|
FLATBUFFERS_CHECKED_ERROR ParseVector(const Type &type, uoffset_t *ovalue);
|
||||||
FLATBUFFERS_CHECKED_ERROR ParseMetaData(Definition &def);
|
FLATBUFFERS_CHECKED_ERROR ParseMetaData(SymbolTable<Value> *attributes);
|
||||||
FLATBUFFERS_CHECKED_ERROR TryTypedValue(int dtoken, bool check, Value &e,
|
FLATBUFFERS_CHECKED_ERROR TryTypedValue(int dtoken, bool check, Value &e,
|
||||||
BaseType req, bool *destmatch);
|
BaseType req, bool *destmatch);
|
||||||
FLATBUFFERS_CHECKED_ERROR ParseHash(Value &e, FieldDef* field);
|
FLATBUFFERS_CHECKED_ERROR ParseHash(Value &e, FieldDef* field);
|
||||||
FLATBUFFERS_CHECKED_ERROR ParseSingleValue(Value &e);
|
FLATBUFFERS_CHECKED_ERROR ParseSingleValue(Value &e);
|
||||||
FLATBUFFERS_CHECKED_ERROR ParseIntegerFromString(Type &type, int64_t *result);
|
FLATBUFFERS_CHECKED_ERROR ParseEnumFromString(Type &type, int64_t *result);
|
||||||
StructDef *LookupCreateStruct(const std::string &name,
|
StructDef *LookupCreateStruct(const std::string &name,
|
||||||
bool create_if_new = true,
|
bool create_if_new = true,
|
||||||
bool definition = false);
|
bool definition = false);
|
||||||
@@ -479,6 +562,7 @@ private:
|
|||||||
FLATBUFFERS_CHECKED_ERROR StartStruct(const std::string &name,
|
FLATBUFFERS_CHECKED_ERROR StartStruct(const std::string &name,
|
||||||
StructDef **dest);
|
StructDef **dest);
|
||||||
FLATBUFFERS_CHECKED_ERROR ParseDecl();
|
FLATBUFFERS_CHECKED_ERROR ParseDecl();
|
||||||
|
FLATBUFFERS_CHECKED_ERROR ParseService();
|
||||||
FLATBUFFERS_CHECKED_ERROR ParseProtoFields(StructDef *struct_def,
|
FLATBUFFERS_CHECKED_ERROR ParseProtoFields(StructDef *struct_def,
|
||||||
bool isextend, bool inside_oneof);
|
bool isextend, bool inside_oneof);
|
||||||
FLATBUFFERS_CHECKED_ERROR ParseProtoOption();
|
FLATBUFFERS_CHECKED_ERROR ParseProtoOption();
|
||||||
@@ -499,8 +583,10 @@ private:
|
|||||||
BaseType baseType);
|
BaseType baseType);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
SymbolTable<Type> types_;
|
||||||
SymbolTable<StructDef> structs_;
|
SymbolTable<StructDef> structs_;
|
||||||
SymbolTable<EnumDef> enums_;
|
SymbolTable<EnumDef> enums_;
|
||||||
|
SymbolTable<ServiceDef> services_;
|
||||||
std::vector<Namespace *> namespaces_;
|
std::vector<Namespace *> namespaces_;
|
||||||
std::string error_; // User readable error_ if Parse() == false
|
std::string error_; // User readable error_ if Parse() == false
|
||||||
|
|
||||||
@@ -511,22 +597,19 @@ private:
|
|||||||
|
|
||||||
std::map<std::string, bool> included_files_;
|
std::map<std::string, bool> included_files_;
|
||||||
std::map<std::string, std::set<std::string>> files_included_per_file_;
|
std::map<std::string, std::set<std::string>> files_included_per_file_;
|
||||||
|
std::vector<std::string> native_included_files_;
|
||||||
|
|
||||||
|
std::map<std::string, bool> known_attributes_;
|
||||||
|
|
||||||
IDLOptions opts;
|
IDLOptions opts;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
const char *source_, *cursor_;
|
const char *source_;
|
||||||
int line_; // the current line being parsed
|
|
||||||
int token_;
|
|
||||||
std::string file_being_parsed_;
|
std::string file_being_parsed_;
|
||||||
|
|
||||||
std::string attribute_;
|
|
||||||
std::vector<std::string> doc_comment_;
|
|
||||||
|
|
||||||
std::vector<std::pair<Value, FieldDef *>> field_stack_;
|
std::vector<std::pair<Value, FieldDef *>> field_stack_;
|
||||||
|
|
||||||
std::set<std::string> known_attributes_;
|
|
||||||
|
|
||||||
int anonymous_counter;
|
int anonymous_counter;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -534,20 +617,15 @@ private:
|
|||||||
|
|
||||||
extern std::string MakeCamel(const std::string &in, bool first = true);
|
extern std::string MakeCamel(const std::string &in, bool first = true);
|
||||||
|
|
||||||
struct CommentConfig;
|
|
||||||
|
|
||||||
extern void GenComment(const std::vector<std::string> &dc,
|
|
||||||
std::string *code_ptr,
|
|
||||||
const CommentConfig *config,
|
|
||||||
const char *prefix = "");
|
|
||||||
|
|
||||||
// Generate text (JSON) from a given FlatBuffer, and a given Parser
|
// Generate text (JSON) from a given FlatBuffer, and a given Parser
|
||||||
// object that has been populated with the corresponding schema.
|
// object that has been populated with the corresponding schema.
|
||||||
// If ident_step is 0, no indentation will be generated. Additionally,
|
// If ident_step is 0, no indentation will be generated. Additionally,
|
||||||
// if it is less than 0, no linefeeds will be generated either.
|
// if it is less than 0, no linefeeds will be generated either.
|
||||||
// See idl_gen_text.cpp.
|
// See idl_gen_text.cpp.
|
||||||
// strict_json adds "quotes" around field names if true.
|
// strict_json adds "quotes" around field names if true.
|
||||||
extern void GenerateText(const Parser &parser,
|
// If the flatbuffer cannot be encoded in JSON (e.g., it contains non-UTF-8
|
||||||
|
// byte arrays in String values), returns false.
|
||||||
|
extern bool GenerateText(const Parser &parser,
|
||||||
const void *flatbuffer,
|
const void *flatbuffer,
|
||||||
std::string *text);
|
std::string *text);
|
||||||
extern bool GenerateTextFile(const Parser &parser,
|
extern bool GenerateTextFile(const Parser &parser,
|
||||||
@@ -591,8 +669,8 @@ extern bool GenerateJava(const Parser &parser,
|
|||||||
// Generate Php code from the definitions in the Parser object.
|
// Generate Php code from the definitions in the Parser object.
|
||||||
// See idl_gen_php.
|
// See idl_gen_php.
|
||||||
extern bool GeneratePhp(const Parser &parser,
|
extern bool GeneratePhp(const Parser &parser,
|
||||||
const std::string &path,
|
const std::string &path,
|
||||||
const std::string &file_name);
|
const std::string &file_name);
|
||||||
|
|
||||||
// Generate Python files from the definitions in the Parser object.
|
// Generate Python files from the definitions in the Parser object.
|
||||||
// See idl_gen_python.cpp.
|
// See idl_gen_python.cpp.
|
||||||
@@ -650,6 +728,18 @@ extern std::string BinaryMakeRule(const Parser &parser,
|
|||||||
const std::string &path,
|
const std::string &path,
|
||||||
const std::string &file_name);
|
const std::string &file_name);
|
||||||
|
|
||||||
|
// Generate GRPC Cpp interfaces.
|
||||||
|
// See idl_gen_grpc.cpp.
|
||||||
|
bool GenerateCppGRPC(const Parser &parser,
|
||||||
|
const std::string &path,
|
||||||
|
const std::string &file_name);
|
||||||
|
|
||||||
|
// Generate GRPC Go interfaces.
|
||||||
|
// See idl_gen_grpc.cpp.
|
||||||
|
bool GenerateGoGRPC(const Parser &parser,
|
||||||
|
const std::string &path,
|
||||||
|
const std::string &file_name);
|
||||||
|
|
||||||
} // namespace flatbuffers
|
} // namespace flatbuffers
|
||||||
|
|
||||||
#endif // FLATBUFFERS_IDL_H_
|
#endif // FLATBUFFERS_IDL_H_
|
||||||
|
|||||||
@@ -105,6 +105,22 @@ inline Table *GetFieldT(const Table &table,
|
|||||||
return table.GetPointer<Table *>(field.offset());
|
return table.GetPointer<Table *>(field.offset());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Get a field, if you know it's a struct.
|
||||||
|
inline const Struct *GetFieldStruct(const Table &table,
|
||||||
|
const reflection::Field &field) {
|
||||||
|
// TODO: This does NOT check if the field is a table or struct, but we'd need
|
||||||
|
// access to the schema to check the is_struct flag.
|
||||||
|
assert(field.type()->base_type() == reflection::Obj);
|
||||||
|
return table.GetStruct<const Struct *>(field.offset());
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get a structure's field, if you know it's a struct.
|
||||||
|
inline const Struct *GetFieldStruct(const Struct &structure,
|
||||||
|
const reflection::Field &field) {
|
||||||
|
assert(field.type()->base_type() == reflection::Obj);
|
||||||
|
return structure.GetStruct<const Struct *>(field.offset());
|
||||||
|
}
|
||||||
|
|
||||||
// Raw helper functions used below: get any value in memory as a 64bit int, a
|
// Raw helper functions used below: get any value in memory as a 64bit int, a
|
||||||
// double or a string.
|
// double or a string.
|
||||||
// All scalars get static_cast to an int64_t, strings use strtoull, every other
|
// All scalars get static_cast to an int64_t, strings use strtoull, every other
|
||||||
@@ -335,6 +351,8 @@ template<typename T, typename U> pointer_inside_vector<T, U> piv(T *ptr,
|
|||||||
return pointer_inside_vector<T, U>(ptr, vec);
|
return pointer_inside_vector<T, U>(ptr, vec);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline const char *UnionTypeFieldSuffix() { return "_type"; }
|
||||||
|
|
||||||
// Helper to figure out the actual table type a union refers to.
|
// Helper to figure out the actual table type a union refers to.
|
||||||
inline const reflection::Object &GetUnionType(
|
inline const reflection::Object &GetUnionType(
|
||||||
const reflection::Schema &schema, const reflection::Object &parent,
|
const reflection::Schema &schema, const reflection::Object &parent,
|
||||||
@@ -342,7 +360,7 @@ inline const reflection::Object &GetUnionType(
|
|||||||
auto enumdef = schema.enums()->Get(unionfield.type()->index());
|
auto enumdef = schema.enums()->Get(unionfield.type()->index());
|
||||||
// TODO: this is clumsy and slow, but no other way to find it?
|
// TODO: this is clumsy and slow, but no other way to find it?
|
||||||
auto type_field = parent.fields()->LookupByKey(
|
auto type_field = parent.fields()->LookupByKey(
|
||||||
(unionfield.name()->str() + "_type").c_str());
|
(unionfield.name()->str() + UnionTypeFieldSuffix()).c_str());
|
||||||
assert(type_field);
|
assert(type_field);
|
||||||
auto union_type = GetFieldI<uint8_t>(table, *type_field);
|
auto union_type = GetFieldI<uint8_t>(table, *type_field);
|
||||||
auto enumval = enumdef->values()->LookupByKey(union_type);
|
auto enumval = enumdef->values()->LookupByKey(union_type);
|
||||||
@@ -368,6 +386,7 @@ uint8_t *ResizeAnyVector(const reflection::Schema &schema, uoffset_t newsize,
|
|||||||
uoffset_t elem_size, std::vector<uint8_t> *flatbuf,
|
uoffset_t elem_size, std::vector<uint8_t> *flatbuf,
|
||||||
const reflection::Object *root_table = nullptr);
|
const reflection::Object *root_table = nullptr);
|
||||||
|
|
||||||
|
#ifndef FLATBUFFERS_CPP98_STL
|
||||||
template <typename T>
|
template <typename T>
|
||||||
void ResizeVector(const reflection::Schema &schema, uoffset_t newsize, T val,
|
void ResizeVector(const reflection::Schema &schema, uoffset_t newsize, T val,
|
||||||
const Vector<T> *vec, std::vector<uint8_t> *flatbuf,
|
const Vector<T> *vec, std::vector<uint8_t> *flatbuf,
|
||||||
@@ -389,6 +408,7 @@ void ResizeVector(const reflection::Schema &schema, uoffset_t newsize, T val,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
// Adds any new data (in the form of a new FlatBuffer) to an existing
|
// Adds any new data (in the form of a new FlatBuffer) to an existing
|
||||||
// FlatBuffer. This can be used when any of the above methods are not
|
// FlatBuffer. This can be used when any of the above methods are not
|
||||||
@@ -415,12 +435,23 @@ inline bool SetFieldT(Table *table, const reflection::Field &field,
|
|||||||
// above resizing functionality has introduced garbage in a buffer you want
|
// above resizing functionality has introduced garbage in a buffer you want
|
||||||
// to remove.
|
// to remove.
|
||||||
// Note: this does not deal with DAGs correctly. If the table passed forms a
|
// Note: this does not deal with DAGs correctly. If the table passed forms a
|
||||||
// DAG, the copy will be a tree instead (with duplicates).
|
// DAG, the copy will be a tree instead (with duplicates). Strings can be
|
||||||
|
// shared however, by passing true for use_string_pooling.
|
||||||
|
|
||||||
Offset<const Table *> CopyTable(FlatBufferBuilder &fbb,
|
Offset<const Table *> CopyTable(FlatBufferBuilder &fbb,
|
||||||
const reflection::Schema &schema,
|
const reflection::Schema &schema,
|
||||||
const reflection::Object &objectdef,
|
const reflection::Object &objectdef,
|
||||||
const Table &table);
|
const Table &table,
|
||||||
|
bool use_string_pooling = false);
|
||||||
|
|
||||||
|
// Verifies the provided flatbuffer using reflection.
|
||||||
|
// root should point to the root type for this flatbuffer.
|
||||||
|
// buf should point to the start of flatbuffer data.
|
||||||
|
// length specifies the size of the flatbuffer data.
|
||||||
|
bool Verify(const reflection::Schema &schema,
|
||||||
|
const reflection::Object &root,
|
||||||
|
const uint8_t *buf,
|
||||||
|
size_t length);
|
||||||
|
|
||||||
} // namespace flatbuffers
|
} // namespace flatbuffers
|
||||||
|
|
||||||
|
|||||||
@@ -1,18 +1,25 @@
|
|||||||
// automatically generated by the FlatBuffers compiler, do not modify
|
// automatically generated by the FlatBuffers compiler, do not modify
|
||||||
|
|
||||||
|
|
||||||
#ifndef FLATBUFFERS_GENERATED_REFLECTION_REFLECTION_H_
|
#ifndef FLATBUFFERS_GENERATED_REFLECTION_REFLECTION_H_
|
||||||
#define FLATBUFFERS_GENERATED_REFLECTION_REFLECTION_H_
|
#define FLATBUFFERS_GENERATED_REFLECTION_REFLECTION_H_
|
||||||
|
|
||||||
#include "flatbuffers/flatbuffers.h"
|
#include "flatbuffers/flatbuffers.h"
|
||||||
|
|
||||||
|
|
||||||
namespace reflection {
|
namespace reflection {
|
||||||
|
|
||||||
struct Type;
|
struct Type;
|
||||||
|
|
||||||
|
struct KeyValue;
|
||||||
|
|
||||||
struct EnumVal;
|
struct EnumVal;
|
||||||
|
|
||||||
struct Enum;
|
struct Enum;
|
||||||
|
|
||||||
struct Field;
|
struct Field;
|
||||||
|
|
||||||
struct Object;
|
struct Object;
|
||||||
|
|
||||||
struct Schema;
|
struct Schema;
|
||||||
|
|
||||||
enum BaseType {
|
enum BaseType {
|
||||||
@@ -36,21 +43,54 @@ enum BaseType {
|
|||||||
};
|
};
|
||||||
|
|
||||||
inline const char **EnumNamesBaseType() {
|
inline const char **EnumNamesBaseType() {
|
||||||
static const char *names[] = { "None", "UType", "Bool", "Byte", "UByte", "Short", "UShort", "Int", "UInt", "Long", "ULong", "Float", "Double", "String", "Vector", "Obj", "Union", nullptr };
|
static const char *names[] = {
|
||||||
|
"None",
|
||||||
|
"UType",
|
||||||
|
"Bool",
|
||||||
|
"Byte",
|
||||||
|
"UByte",
|
||||||
|
"Short",
|
||||||
|
"UShort",
|
||||||
|
"Int",
|
||||||
|
"UInt",
|
||||||
|
"Long",
|
||||||
|
"ULong",
|
||||||
|
"Float",
|
||||||
|
"Double",
|
||||||
|
"String",
|
||||||
|
"Vector",
|
||||||
|
"Obj",
|
||||||
|
"Union",
|
||||||
|
nullptr
|
||||||
|
};
|
||||||
return names;
|
return names;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline const char *EnumNameBaseType(BaseType e) { return EnumNamesBaseType()[e]; }
|
inline const char *EnumNameBaseType(BaseType e) {
|
||||||
|
const size_t index = static_cast<int>(e);
|
||||||
|
return EnumNamesBaseType()[index];
|
||||||
|
}
|
||||||
|
|
||||||
struct Type FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table {
|
struct Type FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table {
|
||||||
BaseType base_type() const { return static_cast<BaseType>(GetField<int8_t>(4, 0)); }
|
enum {
|
||||||
BaseType element() const { return static_cast<BaseType>(GetField<int8_t>(6, 0)); }
|
VT_BASE_TYPE = 4,
|
||||||
int32_t index() const { return GetField<int32_t>(8, -1); }
|
VT_ELEMENT = 6,
|
||||||
|
VT_INDEX = 8
|
||||||
|
};
|
||||||
|
BaseType base_type() const {
|
||||||
|
return static_cast<BaseType>(GetField<int8_t>(VT_BASE_TYPE, 0));
|
||||||
|
}
|
||||||
|
BaseType element() const {
|
||||||
|
return static_cast<BaseType>(GetField<int8_t>(VT_ELEMENT, 0));
|
||||||
|
}
|
||||||
|
int32_t index() const {
|
||||||
|
return GetField<int32_t>(VT_INDEX, -1);
|
||||||
|
}
|
||||||
bool Verify(flatbuffers::Verifier &verifier) const {
|
bool Verify(flatbuffers::Verifier &verifier) const {
|
||||||
return VerifyTableStart(verifier) &&
|
return VerifyTableStart(verifier) &&
|
||||||
VerifyField<int8_t>(verifier, 4 /* base_type */) &&
|
VerifyField<int8_t>(verifier, VT_BASE_TYPE) &&
|
||||||
VerifyField<int8_t>(verifier, 6 /* element */) &&
|
VerifyField<int8_t>(verifier, VT_ELEMENT) &&
|
||||||
VerifyField<int32_t>(verifier, 8 /* index */) &&
|
VerifyField<int32_t>(verifier, VT_INDEX) &&
|
||||||
verifier.EndTable();
|
verifier.EndTable();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -58,21 +98,32 @@ struct Type FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table {
|
|||||||
struct TypeBuilder {
|
struct TypeBuilder {
|
||||||
flatbuffers::FlatBufferBuilder &fbb_;
|
flatbuffers::FlatBufferBuilder &fbb_;
|
||||||
flatbuffers::uoffset_t start_;
|
flatbuffers::uoffset_t start_;
|
||||||
void add_base_type(BaseType base_type) { fbb_.AddElement<int8_t>(4, static_cast<int8_t>(base_type), 0); }
|
void add_base_type(BaseType base_type) {
|
||||||
void add_element(BaseType element) { fbb_.AddElement<int8_t>(6, static_cast<int8_t>(element), 0); }
|
fbb_.AddElement<int8_t>(Type::VT_BASE_TYPE, static_cast<int8_t>(base_type), 0);
|
||||||
void add_index(int32_t index) { fbb_.AddElement<int32_t>(8, index, -1); }
|
}
|
||||||
TypeBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) { start_ = fbb_.StartTable(); }
|
void add_element(BaseType element) {
|
||||||
|
fbb_.AddElement<int8_t>(Type::VT_ELEMENT, static_cast<int8_t>(element), 0);
|
||||||
|
}
|
||||||
|
void add_index(int32_t index) {
|
||||||
|
fbb_.AddElement<int32_t>(Type::VT_INDEX, index, -1);
|
||||||
|
}
|
||||||
|
TypeBuilder(flatbuffers::FlatBufferBuilder &_fbb)
|
||||||
|
: fbb_(_fbb) {
|
||||||
|
start_ = fbb_.StartTable();
|
||||||
|
}
|
||||||
TypeBuilder &operator=(const TypeBuilder &);
|
TypeBuilder &operator=(const TypeBuilder &);
|
||||||
flatbuffers::Offset<Type> Finish() {
|
flatbuffers::Offset<Type> Finish() {
|
||||||
auto o = flatbuffers::Offset<Type>(fbb_.EndTable(start_, 3));
|
const auto end = fbb_.EndTable(start_, 3);
|
||||||
|
auto o = flatbuffers::Offset<Type>(end);
|
||||||
return o;
|
return o;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
inline flatbuffers::Offset<Type> CreateType(flatbuffers::FlatBufferBuilder &_fbb,
|
inline flatbuffers::Offset<Type> CreateType(
|
||||||
BaseType base_type = None,
|
flatbuffers::FlatBufferBuilder &_fbb,
|
||||||
BaseType element = None,
|
BaseType base_type = None,
|
||||||
int32_t index = -1) {
|
BaseType element = None,
|
||||||
|
int32_t index = -1) {
|
||||||
TypeBuilder builder_(_fbb);
|
TypeBuilder builder_(_fbb);
|
||||||
builder_.add_index(index);
|
builder_.add_index(index);
|
||||||
builder_.add_element(element);
|
builder_.add_element(element);
|
||||||
@@ -80,18 +131,109 @@ inline flatbuffers::Offset<Type> CreateType(flatbuffers::FlatBufferBuilder &_fbb
|
|||||||
return builder_.Finish();
|
return builder_.Finish();
|
||||||
}
|
}
|
||||||
|
|
||||||
struct EnumVal FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table {
|
struct KeyValue FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table {
|
||||||
const flatbuffers::String *name() const { return GetPointer<const flatbuffers::String *>(4); }
|
enum {
|
||||||
int64_t value() const { return GetField<int64_t>(6, 0); }
|
VT_KEY = 4,
|
||||||
bool KeyCompareLessThan(const EnumVal *o) const { return value() < o->value(); }
|
VT_VALUE = 6
|
||||||
int KeyCompareWithValue(int64_t val) const { return value() < val ? -1 : value() > val; }
|
};
|
||||||
const Object *object() const { return GetPointer<const Object *>(8); }
|
const flatbuffers::String *key() const {
|
||||||
|
return GetPointer<const flatbuffers::String *>(VT_KEY);
|
||||||
|
}
|
||||||
|
bool KeyCompareLessThan(const KeyValue *o) const {
|
||||||
|
return *key() < *o->key();
|
||||||
|
}
|
||||||
|
int KeyCompareWithValue(const char *val) const {
|
||||||
|
return strcmp(key()->c_str(), val);
|
||||||
|
}
|
||||||
|
const flatbuffers::String *value() const {
|
||||||
|
return GetPointer<const flatbuffers::String *>(VT_VALUE);
|
||||||
|
}
|
||||||
bool Verify(flatbuffers::Verifier &verifier) const {
|
bool Verify(flatbuffers::Verifier &verifier) const {
|
||||||
return VerifyTableStart(verifier) &&
|
return VerifyTableStart(verifier) &&
|
||||||
VerifyFieldRequired<flatbuffers::uoffset_t>(verifier, 4 /* name */) &&
|
VerifyFieldRequired<flatbuffers::uoffset_t>(verifier, VT_KEY) &&
|
||||||
|
verifier.Verify(key()) &&
|
||||||
|
VerifyField<flatbuffers::uoffset_t>(verifier, VT_VALUE) &&
|
||||||
|
verifier.Verify(value()) &&
|
||||||
|
verifier.EndTable();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
struct KeyValueBuilder {
|
||||||
|
flatbuffers::FlatBufferBuilder &fbb_;
|
||||||
|
flatbuffers::uoffset_t start_;
|
||||||
|
void add_key(flatbuffers::Offset<flatbuffers::String> key) {
|
||||||
|
fbb_.AddOffset(KeyValue::VT_KEY, key);
|
||||||
|
}
|
||||||
|
void add_value(flatbuffers::Offset<flatbuffers::String> value) {
|
||||||
|
fbb_.AddOffset(KeyValue::VT_VALUE, value);
|
||||||
|
}
|
||||||
|
KeyValueBuilder(flatbuffers::FlatBufferBuilder &_fbb)
|
||||||
|
: fbb_(_fbb) {
|
||||||
|
start_ = fbb_.StartTable();
|
||||||
|
}
|
||||||
|
KeyValueBuilder &operator=(const KeyValueBuilder &);
|
||||||
|
flatbuffers::Offset<KeyValue> Finish() {
|
||||||
|
const auto end = fbb_.EndTable(start_, 2);
|
||||||
|
auto o = flatbuffers::Offset<KeyValue>(end);
|
||||||
|
fbb_.Required(o, KeyValue::VT_KEY);
|
||||||
|
return o;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
inline flatbuffers::Offset<KeyValue> CreateKeyValue(
|
||||||
|
flatbuffers::FlatBufferBuilder &_fbb,
|
||||||
|
flatbuffers::Offset<flatbuffers::String> key = 0,
|
||||||
|
flatbuffers::Offset<flatbuffers::String> value = 0) {
|
||||||
|
KeyValueBuilder builder_(_fbb);
|
||||||
|
builder_.add_value(value);
|
||||||
|
builder_.add_key(key);
|
||||||
|
return builder_.Finish();
|
||||||
|
}
|
||||||
|
|
||||||
|
inline flatbuffers::Offset<KeyValue> CreateKeyValueDirect(
|
||||||
|
flatbuffers::FlatBufferBuilder &_fbb,
|
||||||
|
const char *key = nullptr,
|
||||||
|
const char *value = nullptr) {
|
||||||
|
return reflection::CreateKeyValue(
|
||||||
|
_fbb,
|
||||||
|
key ? _fbb.CreateString(key) : 0,
|
||||||
|
value ? _fbb.CreateString(value) : 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
struct EnumVal FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table {
|
||||||
|
enum {
|
||||||
|
VT_NAME = 4,
|
||||||
|
VT_VALUE = 6,
|
||||||
|
VT_OBJECT = 8
|
||||||
|
};
|
||||||
|
const flatbuffers::String *name() const {
|
||||||
|
return GetPointer<const flatbuffers::String *>(VT_NAME);
|
||||||
|
}
|
||||||
|
int64_t value() const {
|
||||||
|
return GetField<int64_t>(VT_VALUE, 0);
|
||||||
|
}
|
||||||
|
bool KeyCompareLessThan(const EnumVal *o) const {
|
||||||
|
return value() < o->value();
|
||||||
|
}
|
||||||
|
int KeyCompareWithValue(int64_t val) const {
|
||||||
|
const auto key = value();
|
||||||
|
if (key < val) {
|
||||||
|
return -1;
|
||||||
|
} else if (key > val) {
|
||||||
|
return 1;
|
||||||
|
} else {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
const Object *object() const {
|
||||||
|
return GetPointer<const Object *>(VT_OBJECT);
|
||||||
|
}
|
||||||
|
bool Verify(flatbuffers::Verifier &verifier) const {
|
||||||
|
return VerifyTableStart(verifier) &&
|
||||||
|
VerifyFieldRequired<flatbuffers::uoffset_t>(verifier, VT_NAME) &&
|
||||||
verifier.Verify(name()) &&
|
verifier.Verify(name()) &&
|
||||||
VerifyField<int64_t>(verifier, 6 /* value */) &&
|
VerifyField<int64_t>(verifier, VT_VALUE) &&
|
||||||
VerifyField<flatbuffers::uoffset_t>(verifier, 8 /* object */) &&
|
VerifyField<flatbuffers::uoffset_t>(verifier, VT_OBJECT) &&
|
||||||
verifier.VerifyTable(object()) &&
|
verifier.VerifyTable(object()) &&
|
||||||
verifier.EndTable();
|
verifier.EndTable();
|
||||||
}
|
}
|
||||||
@@ -100,22 +242,33 @@ struct EnumVal FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table {
|
|||||||
struct EnumValBuilder {
|
struct EnumValBuilder {
|
||||||
flatbuffers::FlatBufferBuilder &fbb_;
|
flatbuffers::FlatBufferBuilder &fbb_;
|
||||||
flatbuffers::uoffset_t start_;
|
flatbuffers::uoffset_t start_;
|
||||||
void add_name(flatbuffers::Offset<flatbuffers::String> name) { fbb_.AddOffset(4, name); }
|
void add_name(flatbuffers::Offset<flatbuffers::String> name) {
|
||||||
void add_value(int64_t value) { fbb_.AddElement<int64_t>(6, value, 0); }
|
fbb_.AddOffset(EnumVal::VT_NAME, name);
|
||||||
void add_object(flatbuffers::Offset<Object> object) { fbb_.AddOffset(8, object); }
|
}
|
||||||
EnumValBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) { start_ = fbb_.StartTable(); }
|
void add_value(int64_t value) {
|
||||||
|
fbb_.AddElement<int64_t>(EnumVal::VT_VALUE, value, 0);
|
||||||
|
}
|
||||||
|
void add_object(flatbuffers::Offset<Object> object) {
|
||||||
|
fbb_.AddOffset(EnumVal::VT_OBJECT, object);
|
||||||
|
}
|
||||||
|
EnumValBuilder(flatbuffers::FlatBufferBuilder &_fbb)
|
||||||
|
: fbb_(_fbb) {
|
||||||
|
start_ = fbb_.StartTable();
|
||||||
|
}
|
||||||
EnumValBuilder &operator=(const EnumValBuilder &);
|
EnumValBuilder &operator=(const EnumValBuilder &);
|
||||||
flatbuffers::Offset<EnumVal> Finish() {
|
flatbuffers::Offset<EnumVal> Finish() {
|
||||||
auto o = flatbuffers::Offset<EnumVal>(fbb_.EndTable(start_, 3));
|
const auto end = fbb_.EndTable(start_, 3);
|
||||||
fbb_.Required(o, 4); // name
|
auto o = flatbuffers::Offset<EnumVal>(end);
|
||||||
|
fbb_.Required(o, EnumVal::VT_NAME);
|
||||||
return o;
|
return o;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
inline flatbuffers::Offset<EnumVal> CreateEnumVal(flatbuffers::FlatBufferBuilder &_fbb,
|
inline flatbuffers::Offset<EnumVal> CreateEnumVal(
|
||||||
flatbuffers::Offset<flatbuffers::String> name = 0,
|
flatbuffers::FlatBufferBuilder &_fbb,
|
||||||
int64_t value = 0,
|
flatbuffers::Offset<flatbuffers::String> name = 0,
|
||||||
flatbuffers::Offset<Object> object = 0) {
|
int64_t value = 0,
|
||||||
|
flatbuffers::Offset<Object> object = 0) {
|
||||||
EnumValBuilder builder_(_fbb);
|
EnumValBuilder builder_(_fbb);
|
||||||
builder_.add_value(value);
|
builder_.add_value(value);
|
||||||
builder_.add_object(object);
|
builder_.add_object(object);
|
||||||
@@ -123,23 +276,67 @@ inline flatbuffers::Offset<EnumVal> CreateEnumVal(flatbuffers::FlatBufferBuilder
|
|||||||
return builder_.Finish();
|
return builder_.Finish();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline flatbuffers::Offset<EnumVal> CreateEnumValDirect(
|
||||||
|
flatbuffers::FlatBufferBuilder &_fbb,
|
||||||
|
const char *name = nullptr,
|
||||||
|
int64_t value = 0,
|
||||||
|
flatbuffers::Offset<Object> object = 0) {
|
||||||
|
return reflection::CreateEnumVal(
|
||||||
|
_fbb,
|
||||||
|
name ? _fbb.CreateString(name) : 0,
|
||||||
|
value,
|
||||||
|
object);
|
||||||
|
}
|
||||||
|
|
||||||
struct Enum FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table {
|
struct Enum FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table {
|
||||||
const flatbuffers::String *name() const { return GetPointer<const flatbuffers::String *>(4); }
|
enum {
|
||||||
bool KeyCompareLessThan(const Enum *o) const { return *name() < *o->name(); }
|
VT_NAME = 4,
|
||||||
int KeyCompareWithValue(const char *val) const { return strcmp(name()->c_str(), val); }
|
VT_VALUES = 6,
|
||||||
const flatbuffers::Vector<flatbuffers::Offset<EnumVal>> *values() const { return GetPointer<const flatbuffers::Vector<flatbuffers::Offset<EnumVal>> *>(6); }
|
VT_IS_UNION = 8,
|
||||||
uint8_t is_union() const { return GetField<uint8_t>(8, 0); }
|
VT_UNDERLYING_TYPE = 10,
|
||||||
const Type *underlying_type() const { return GetPointer<const Type *>(10); }
|
VT_ATTRIBUTES = 12,
|
||||||
|
VT_DOCUMENTATION = 14
|
||||||
|
};
|
||||||
|
const flatbuffers::String *name() const {
|
||||||
|
return GetPointer<const flatbuffers::String *>(VT_NAME);
|
||||||
|
}
|
||||||
|
bool KeyCompareLessThan(const Enum *o) const {
|
||||||
|
return *name() < *o->name();
|
||||||
|
}
|
||||||
|
int KeyCompareWithValue(const char *val) const {
|
||||||
|
return strcmp(name()->c_str(), val);
|
||||||
|
}
|
||||||
|
const flatbuffers::Vector<flatbuffers::Offset<EnumVal>> *values() const {
|
||||||
|
return GetPointer<const flatbuffers::Vector<flatbuffers::Offset<EnumVal>> *>(VT_VALUES);
|
||||||
|
}
|
||||||
|
bool is_union() const {
|
||||||
|
return GetField<uint8_t>(VT_IS_UNION, 0) != 0;
|
||||||
|
}
|
||||||
|
const Type *underlying_type() const {
|
||||||
|
return GetPointer<const Type *>(VT_UNDERLYING_TYPE);
|
||||||
|
}
|
||||||
|
const flatbuffers::Vector<flatbuffers::Offset<KeyValue>> *attributes() const {
|
||||||
|
return GetPointer<const flatbuffers::Vector<flatbuffers::Offset<KeyValue>> *>(VT_ATTRIBUTES);
|
||||||
|
}
|
||||||
|
const flatbuffers::Vector<flatbuffers::Offset<flatbuffers::String>> *documentation() const {
|
||||||
|
return GetPointer<const flatbuffers::Vector<flatbuffers::Offset<flatbuffers::String>> *>(VT_DOCUMENTATION);
|
||||||
|
}
|
||||||
bool Verify(flatbuffers::Verifier &verifier) const {
|
bool Verify(flatbuffers::Verifier &verifier) const {
|
||||||
return VerifyTableStart(verifier) &&
|
return VerifyTableStart(verifier) &&
|
||||||
VerifyFieldRequired<flatbuffers::uoffset_t>(verifier, 4 /* name */) &&
|
VerifyFieldRequired<flatbuffers::uoffset_t>(verifier, VT_NAME) &&
|
||||||
verifier.Verify(name()) &&
|
verifier.Verify(name()) &&
|
||||||
VerifyFieldRequired<flatbuffers::uoffset_t>(verifier, 6 /* values */) &&
|
VerifyFieldRequired<flatbuffers::uoffset_t>(verifier, VT_VALUES) &&
|
||||||
verifier.Verify(values()) &&
|
verifier.Verify(values()) &&
|
||||||
verifier.VerifyVectorOfTables(values()) &&
|
verifier.VerifyVectorOfTables(values()) &&
|
||||||
VerifyField<uint8_t>(verifier, 8 /* is_union */) &&
|
VerifyField<uint8_t>(verifier, VT_IS_UNION) &&
|
||||||
VerifyFieldRequired<flatbuffers::uoffset_t>(verifier, 10 /* underlying_type */) &&
|
VerifyFieldRequired<flatbuffers::uoffset_t>(verifier, VT_UNDERLYING_TYPE) &&
|
||||||
verifier.VerifyTable(underlying_type()) &&
|
verifier.VerifyTable(underlying_type()) &&
|
||||||
|
VerifyField<flatbuffers::uoffset_t>(verifier, VT_ATTRIBUTES) &&
|
||||||
|
verifier.Verify(attributes()) &&
|
||||||
|
verifier.VerifyVectorOfTables(attributes()) &&
|
||||||
|
VerifyField<flatbuffers::uoffset_t>(verifier, VT_DOCUMENTATION) &&
|
||||||
|
verifier.Verify(documentation()) &&
|
||||||
|
verifier.VerifyVectorOfStrings(documentation()) &&
|
||||||
verifier.EndTable();
|
verifier.EndTable();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -147,27 +344,50 @@ struct Enum FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table {
|
|||||||
struct EnumBuilder {
|
struct EnumBuilder {
|
||||||
flatbuffers::FlatBufferBuilder &fbb_;
|
flatbuffers::FlatBufferBuilder &fbb_;
|
||||||
flatbuffers::uoffset_t start_;
|
flatbuffers::uoffset_t start_;
|
||||||
void add_name(flatbuffers::Offset<flatbuffers::String> name) { fbb_.AddOffset(4, name); }
|
void add_name(flatbuffers::Offset<flatbuffers::String> name) {
|
||||||
void add_values(flatbuffers::Offset<flatbuffers::Vector<flatbuffers::Offset<EnumVal>>> values) { fbb_.AddOffset(6, values); }
|
fbb_.AddOffset(Enum::VT_NAME, name);
|
||||||
void add_is_union(uint8_t is_union) { fbb_.AddElement<uint8_t>(8, is_union, 0); }
|
}
|
||||||
void add_underlying_type(flatbuffers::Offset<Type> underlying_type) { fbb_.AddOffset(10, underlying_type); }
|
void add_values(flatbuffers::Offset<flatbuffers::Vector<flatbuffers::Offset<EnumVal>>> values) {
|
||||||
EnumBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) { start_ = fbb_.StartTable(); }
|
fbb_.AddOffset(Enum::VT_VALUES, values);
|
||||||
|
}
|
||||||
|
void add_is_union(bool is_union) {
|
||||||
|
fbb_.AddElement<uint8_t>(Enum::VT_IS_UNION, static_cast<uint8_t>(is_union), 0);
|
||||||
|
}
|
||||||
|
void add_underlying_type(flatbuffers::Offset<Type> underlying_type) {
|
||||||
|
fbb_.AddOffset(Enum::VT_UNDERLYING_TYPE, underlying_type);
|
||||||
|
}
|
||||||
|
void add_attributes(flatbuffers::Offset<flatbuffers::Vector<flatbuffers::Offset<KeyValue>>> attributes) {
|
||||||
|
fbb_.AddOffset(Enum::VT_ATTRIBUTES, attributes);
|
||||||
|
}
|
||||||
|
void add_documentation(flatbuffers::Offset<flatbuffers::Vector<flatbuffers::Offset<flatbuffers::String>>> documentation) {
|
||||||
|
fbb_.AddOffset(Enum::VT_DOCUMENTATION, documentation);
|
||||||
|
}
|
||||||
|
EnumBuilder(flatbuffers::FlatBufferBuilder &_fbb)
|
||||||
|
: fbb_(_fbb) {
|
||||||
|
start_ = fbb_.StartTable();
|
||||||
|
}
|
||||||
EnumBuilder &operator=(const EnumBuilder &);
|
EnumBuilder &operator=(const EnumBuilder &);
|
||||||
flatbuffers::Offset<Enum> Finish() {
|
flatbuffers::Offset<Enum> Finish() {
|
||||||
auto o = flatbuffers::Offset<Enum>(fbb_.EndTable(start_, 4));
|
const auto end = fbb_.EndTable(start_, 6);
|
||||||
fbb_.Required(o, 4); // name
|
auto o = flatbuffers::Offset<Enum>(end);
|
||||||
fbb_.Required(o, 6); // values
|
fbb_.Required(o, Enum::VT_NAME);
|
||||||
fbb_.Required(o, 10); // underlying_type
|
fbb_.Required(o, Enum::VT_VALUES);
|
||||||
|
fbb_.Required(o, Enum::VT_UNDERLYING_TYPE);
|
||||||
return o;
|
return o;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
inline flatbuffers::Offset<Enum> CreateEnum(flatbuffers::FlatBufferBuilder &_fbb,
|
inline flatbuffers::Offset<Enum> CreateEnum(
|
||||||
flatbuffers::Offset<flatbuffers::String> name = 0,
|
flatbuffers::FlatBufferBuilder &_fbb,
|
||||||
flatbuffers::Offset<flatbuffers::Vector<flatbuffers::Offset<EnumVal>>> values = 0,
|
flatbuffers::Offset<flatbuffers::String> name = 0,
|
||||||
uint8_t is_union = 0,
|
flatbuffers::Offset<flatbuffers::Vector<flatbuffers::Offset<EnumVal>>> values = 0,
|
||||||
flatbuffers::Offset<Type> underlying_type = 0) {
|
bool is_union = false,
|
||||||
|
flatbuffers::Offset<Type> underlying_type = 0,
|
||||||
|
flatbuffers::Offset<flatbuffers::Vector<flatbuffers::Offset<KeyValue>>> attributes = 0,
|
||||||
|
flatbuffers::Offset<flatbuffers::Vector<flatbuffers::Offset<flatbuffers::String>>> documentation = 0) {
|
||||||
EnumBuilder builder_(_fbb);
|
EnumBuilder builder_(_fbb);
|
||||||
|
builder_.add_documentation(documentation);
|
||||||
|
builder_.add_attributes(attributes);
|
||||||
builder_.add_underlying_type(underlying_type);
|
builder_.add_underlying_type(underlying_type);
|
||||||
builder_.add_values(values);
|
builder_.add_values(values);
|
||||||
builder_.add_name(name);
|
builder_.add_name(name);
|
||||||
@@ -175,31 +395,96 @@ inline flatbuffers::Offset<Enum> CreateEnum(flatbuffers::FlatBufferBuilder &_fbb
|
|||||||
return builder_.Finish();
|
return builder_.Finish();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline flatbuffers::Offset<Enum> CreateEnumDirect(
|
||||||
|
flatbuffers::FlatBufferBuilder &_fbb,
|
||||||
|
const char *name = nullptr,
|
||||||
|
const std::vector<flatbuffers::Offset<EnumVal>> *values = nullptr,
|
||||||
|
bool is_union = false,
|
||||||
|
flatbuffers::Offset<Type> underlying_type = 0,
|
||||||
|
const std::vector<flatbuffers::Offset<KeyValue>> *attributes = nullptr,
|
||||||
|
const std::vector<flatbuffers::Offset<flatbuffers::String>> *documentation = nullptr) {
|
||||||
|
return reflection::CreateEnum(
|
||||||
|
_fbb,
|
||||||
|
name ? _fbb.CreateString(name) : 0,
|
||||||
|
values ? _fbb.CreateVector<flatbuffers::Offset<EnumVal>>(*values) : 0,
|
||||||
|
is_union,
|
||||||
|
underlying_type,
|
||||||
|
attributes ? _fbb.CreateVector<flatbuffers::Offset<KeyValue>>(*attributes) : 0,
|
||||||
|
documentation ? _fbb.CreateVector<flatbuffers::Offset<flatbuffers::String>>(*documentation) : 0);
|
||||||
|
}
|
||||||
|
|
||||||
struct Field FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table {
|
struct Field FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table {
|
||||||
const flatbuffers::String *name() const { return GetPointer<const flatbuffers::String *>(4); }
|
enum {
|
||||||
bool KeyCompareLessThan(const Field *o) const { return *name() < *o->name(); }
|
VT_NAME = 4,
|
||||||
int KeyCompareWithValue(const char *val) const { return strcmp(name()->c_str(), val); }
|
VT_TYPE = 6,
|
||||||
const Type *type() const { return GetPointer<const Type *>(6); }
|
VT_ID = 8,
|
||||||
uint16_t id() const { return GetField<uint16_t>(8, 0); }
|
VT_OFFSET = 10,
|
||||||
uint16_t offset() const { return GetField<uint16_t>(10, 0); }
|
VT_DEFAULT_INTEGER = 12,
|
||||||
int64_t default_integer() const { return GetField<int64_t>(12, 0); }
|
VT_DEFAULT_REAL = 14,
|
||||||
double default_real() const { return GetField<double>(14, 0.0); }
|
VT_DEPRECATED = 16,
|
||||||
uint8_t deprecated() const { return GetField<uint8_t>(16, 0); }
|
VT_REQUIRED = 18,
|
||||||
uint8_t required() const { return GetField<uint8_t>(18, 0); }
|
VT_KEY = 20,
|
||||||
uint8_t key() const { return GetField<uint8_t>(20, 0); }
|
VT_ATTRIBUTES = 22,
|
||||||
|
VT_DOCUMENTATION = 24
|
||||||
|
};
|
||||||
|
const flatbuffers::String *name() const {
|
||||||
|
return GetPointer<const flatbuffers::String *>(VT_NAME);
|
||||||
|
}
|
||||||
|
bool KeyCompareLessThan(const Field *o) const {
|
||||||
|
return *name() < *o->name();
|
||||||
|
}
|
||||||
|
int KeyCompareWithValue(const char *val) const {
|
||||||
|
return strcmp(name()->c_str(), val);
|
||||||
|
}
|
||||||
|
const Type *type() const {
|
||||||
|
return GetPointer<const Type *>(VT_TYPE);
|
||||||
|
}
|
||||||
|
uint16_t id() const {
|
||||||
|
return GetField<uint16_t>(VT_ID, 0);
|
||||||
|
}
|
||||||
|
uint16_t offset() const {
|
||||||
|
return GetField<uint16_t>(VT_OFFSET, 0);
|
||||||
|
}
|
||||||
|
int64_t default_integer() const {
|
||||||
|
return GetField<int64_t>(VT_DEFAULT_INTEGER, 0);
|
||||||
|
}
|
||||||
|
double default_real() const {
|
||||||
|
return GetField<double>(VT_DEFAULT_REAL, 0.0);
|
||||||
|
}
|
||||||
|
bool deprecated() const {
|
||||||
|
return GetField<uint8_t>(VT_DEPRECATED, 0) != 0;
|
||||||
|
}
|
||||||
|
bool required() const {
|
||||||
|
return GetField<uint8_t>(VT_REQUIRED, 0) != 0;
|
||||||
|
}
|
||||||
|
bool key() const {
|
||||||
|
return GetField<uint8_t>(VT_KEY, 0) != 0;
|
||||||
|
}
|
||||||
|
const flatbuffers::Vector<flatbuffers::Offset<KeyValue>> *attributes() const {
|
||||||
|
return GetPointer<const flatbuffers::Vector<flatbuffers::Offset<KeyValue>> *>(VT_ATTRIBUTES);
|
||||||
|
}
|
||||||
|
const flatbuffers::Vector<flatbuffers::Offset<flatbuffers::String>> *documentation() const {
|
||||||
|
return GetPointer<const flatbuffers::Vector<flatbuffers::Offset<flatbuffers::String>> *>(VT_DOCUMENTATION);
|
||||||
|
}
|
||||||
bool Verify(flatbuffers::Verifier &verifier) const {
|
bool Verify(flatbuffers::Verifier &verifier) const {
|
||||||
return VerifyTableStart(verifier) &&
|
return VerifyTableStart(verifier) &&
|
||||||
VerifyFieldRequired<flatbuffers::uoffset_t>(verifier, 4 /* name */) &&
|
VerifyFieldRequired<flatbuffers::uoffset_t>(verifier, VT_NAME) &&
|
||||||
verifier.Verify(name()) &&
|
verifier.Verify(name()) &&
|
||||||
VerifyFieldRequired<flatbuffers::uoffset_t>(verifier, 6 /* type */) &&
|
VerifyFieldRequired<flatbuffers::uoffset_t>(verifier, VT_TYPE) &&
|
||||||
verifier.VerifyTable(type()) &&
|
verifier.VerifyTable(type()) &&
|
||||||
VerifyField<uint16_t>(verifier, 8 /* id */) &&
|
VerifyField<uint16_t>(verifier, VT_ID) &&
|
||||||
VerifyField<uint16_t>(verifier, 10 /* offset */) &&
|
VerifyField<uint16_t>(verifier, VT_OFFSET) &&
|
||||||
VerifyField<int64_t>(verifier, 12 /* default_integer */) &&
|
VerifyField<int64_t>(verifier, VT_DEFAULT_INTEGER) &&
|
||||||
VerifyField<double>(verifier, 14 /* default_real */) &&
|
VerifyField<double>(verifier, VT_DEFAULT_REAL) &&
|
||||||
VerifyField<uint8_t>(verifier, 16 /* deprecated */) &&
|
VerifyField<uint8_t>(verifier, VT_DEPRECATED) &&
|
||||||
VerifyField<uint8_t>(verifier, 18 /* required */) &&
|
VerifyField<uint8_t>(verifier, VT_REQUIRED) &&
|
||||||
VerifyField<uint8_t>(verifier, 20 /* key */) &&
|
VerifyField<uint8_t>(verifier, VT_KEY) &&
|
||||||
|
VerifyField<flatbuffers::uoffset_t>(verifier, VT_ATTRIBUTES) &&
|
||||||
|
verifier.Verify(attributes()) &&
|
||||||
|
verifier.VerifyVectorOfTables(attributes()) &&
|
||||||
|
VerifyField<flatbuffers::uoffset_t>(verifier, VT_DOCUMENTATION) &&
|
||||||
|
verifier.Verify(documentation()) &&
|
||||||
|
verifier.VerifyVectorOfStrings(documentation()) &&
|
||||||
verifier.EndTable();
|
verifier.EndTable();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -207,38 +492,71 @@ struct Field FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table {
|
|||||||
struct FieldBuilder {
|
struct FieldBuilder {
|
||||||
flatbuffers::FlatBufferBuilder &fbb_;
|
flatbuffers::FlatBufferBuilder &fbb_;
|
||||||
flatbuffers::uoffset_t start_;
|
flatbuffers::uoffset_t start_;
|
||||||
void add_name(flatbuffers::Offset<flatbuffers::String> name) { fbb_.AddOffset(4, name); }
|
void add_name(flatbuffers::Offset<flatbuffers::String> name) {
|
||||||
void add_type(flatbuffers::Offset<Type> type) { fbb_.AddOffset(6, type); }
|
fbb_.AddOffset(Field::VT_NAME, name);
|
||||||
void add_id(uint16_t id) { fbb_.AddElement<uint16_t>(8, id, 0); }
|
}
|
||||||
void add_offset(uint16_t offset) { fbb_.AddElement<uint16_t>(10, offset, 0); }
|
void add_type(flatbuffers::Offset<Type> type) {
|
||||||
void add_default_integer(int64_t default_integer) { fbb_.AddElement<int64_t>(12, default_integer, 0); }
|
fbb_.AddOffset(Field::VT_TYPE, type);
|
||||||
void add_default_real(double default_real) { fbb_.AddElement<double>(14, default_real, 0.0); }
|
}
|
||||||
void add_deprecated(uint8_t deprecated) { fbb_.AddElement<uint8_t>(16, deprecated, 0); }
|
void add_id(uint16_t id) {
|
||||||
void add_required(uint8_t required) { fbb_.AddElement<uint8_t>(18, required, 0); }
|
fbb_.AddElement<uint16_t>(Field::VT_ID, id, 0);
|
||||||
void add_key(uint8_t key) { fbb_.AddElement<uint8_t>(20, key, 0); }
|
}
|
||||||
FieldBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) { start_ = fbb_.StartTable(); }
|
void add_offset(uint16_t offset) {
|
||||||
|
fbb_.AddElement<uint16_t>(Field::VT_OFFSET, offset, 0);
|
||||||
|
}
|
||||||
|
void add_default_integer(int64_t default_integer) {
|
||||||
|
fbb_.AddElement<int64_t>(Field::VT_DEFAULT_INTEGER, default_integer, 0);
|
||||||
|
}
|
||||||
|
void add_default_real(double default_real) {
|
||||||
|
fbb_.AddElement<double>(Field::VT_DEFAULT_REAL, default_real, 0.0);
|
||||||
|
}
|
||||||
|
void add_deprecated(bool deprecated) {
|
||||||
|
fbb_.AddElement<uint8_t>(Field::VT_DEPRECATED, static_cast<uint8_t>(deprecated), 0);
|
||||||
|
}
|
||||||
|
void add_required(bool required) {
|
||||||
|
fbb_.AddElement<uint8_t>(Field::VT_REQUIRED, static_cast<uint8_t>(required), 0);
|
||||||
|
}
|
||||||
|
void add_key(bool key) {
|
||||||
|
fbb_.AddElement<uint8_t>(Field::VT_KEY, static_cast<uint8_t>(key), 0);
|
||||||
|
}
|
||||||
|
void add_attributes(flatbuffers::Offset<flatbuffers::Vector<flatbuffers::Offset<KeyValue>>> attributes) {
|
||||||
|
fbb_.AddOffset(Field::VT_ATTRIBUTES, attributes);
|
||||||
|
}
|
||||||
|
void add_documentation(flatbuffers::Offset<flatbuffers::Vector<flatbuffers::Offset<flatbuffers::String>>> documentation) {
|
||||||
|
fbb_.AddOffset(Field::VT_DOCUMENTATION, documentation);
|
||||||
|
}
|
||||||
|
FieldBuilder(flatbuffers::FlatBufferBuilder &_fbb)
|
||||||
|
: fbb_(_fbb) {
|
||||||
|
start_ = fbb_.StartTable();
|
||||||
|
}
|
||||||
FieldBuilder &operator=(const FieldBuilder &);
|
FieldBuilder &operator=(const FieldBuilder &);
|
||||||
flatbuffers::Offset<Field> Finish() {
|
flatbuffers::Offset<Field> Finish() {
|
||||||
auto o = flatbuffers::Offset<Field>(fbb_.EndTable(start_, 9));
|
const auto end = fbb_.EndTable(start_, 11);
|
||||||
fbb_.Required(o, 4); // name
|
auto o = flatbuffers::Offset<Field>(end);
|
||||||
fbb_.Required(o, 6); // type
|
fbb_.Required(o, Field::VT_NAME);
|
||||||
|
fbb_.Required(o, Field::VT_TYPE);
|
||||||
return o;
|
return o;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
inline flatbuffers::Offset<Field> CreateField(flatbuffers::FlatBufferBuilder &_fbb,
|
inline flatbuffers::Offset<Field> CreateField(
|
||||||
flatbuffers::Offset<flatbuffers::String> name = 0,
|
flatbuffers::FlatBufferBuilder &_fbb,
|
||||||
flatbuffers::Offset<Type> type = 0,
|
flatbuffers::Offset<flatbuffers::String> name = 0,
|
||||||
uint16_t id = 0,
|
flatbuffers::Offset<Type> type = 0,
|
||||||
uint16_t offset = 0,
|
uint16_t id = 0,
|
||||||
int64_t default_integer = 0,
|
uint16_t offset = 0,
|
||||||
double default_real = 0.0,
|
int64_t default_integer = 0,
|
||||||
uint8_t deprecated = 0,
|
double default_real = 0.0,
|
||||||
uint8_t required = 0,
|
bool deprecated = false,
|
||||||
uint8_t key = 0) {
|
bool required = false,
|
||||||
|
bool key = false,
|
||||||
|
flatbuffers::Offset<flatbuffers::Vector<flatbuffers::Offset<KeyValue>>> attributes = 0,
|
||||||
|
flatbuffers::Offset<flatbuffers::Vector<flatbuffers::Offset<flatbuffers::String>>> documentation = 0) {
|
||||||
FieldBuilder builder_(_fbb);
|
FieldBuilder builder_(_fbb);
|
||||||
builder_.add_default_real(default_real);
|
builder_.add_default_real(default_real);
|
||||||
builder_.add_default_integer(default_integer);
|
builder_.add_default_integer(default_integer);
|
||||||
|
builder_.add_documentation(documentation);
|
||||||
|
builder_.add_attributes(attributes);
|
||||||
builder_.add_type(type);
|
builder_.add_type(type);
|
||||||
builder_.add_name(name);
|
builder_.add_name(name);
|
||||||
builder_.add_offset(offset);
|
builder_.add_offset(offset);
|
||||||
@@ -249,24 +567,87 @@ inline flatbuffers::Offset<Field> CreateField(flatbuffers::FlatBufferBuilder &_f
|
|||||||
return builder_.Finish();
|
return builder_.Finish();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline flatbuffers::Offset<Field> CreateFieldDirect(
|
||||||
|
flatbuffers::FlatBufferBuilder &_fbb,
|
||||||
|
const char *name = nullptr,
|
||||||
|
flatbuffers::Offset<Type> type = 0,
|
||||||
|
uint16_t id = 0,
|
||||||
|
uint16_t offset = 0,
|
||||||
|
int64_t default_integer = 0,
|
||||||
|
double default_real = 0.0,
|
||||||
|
bool deprecated = false,
|
||||||
|
bool required = false,
|
||||||
|
bool key = false,
|
||||||
|
const std::vector<flatbuffers::Offset<KeyValue>> *attributes = nullptr,
|
||||||
|
const std::vector<flatbuffers::Offset<flatbuffers::String>> *documentation = nullptr) {
|
||||||
|
return reflection::CreateField(
|
||||||
|
_fbb,
|
||||||
|
name ? _fbb.CreateString(name) : 0,
|
||||||
|
type,
|
||||||
|
id,
|
||||||
|
offset,
|
||||||
|
default_integer,
|
||||||
|
default_real,
|
||||||
|
deprecated,
|
||||||
|
required,
|
||||||
|
key,
|
||||||
|
attributes ? _fbb.CreateVector<flatbuffers::Offset<KeyValue>>(*attributes) : 0,
|
||||||
|
documentation ? _fbb.CreateVector<flatbuffers::Offset<flatbuffers::String>>(*documentation) : 0);
|
||||||
|
}
|
||||||
|
|
||||||
struct Object FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table {
|
struct Object FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table {
|
||||||
const flatbuffers::String *name() const { return GetPointer<const flatbuffers::String *>(4); }
|
enum {
|
||||||
bool KeyCompareLessThan(const Object *o) const { return *name() < *o->name(); }
|
VT_NAME = 4,
|
||||||
int KeyCompareWithValue(const char *val) const { return strcmp(name()->c_str(), val); }
|
VT_FIELDS = 6,
|
||||||
const flatbuffers::Vector<flatbuffers::Offset<Field>> *fields() const { return GetPointer<const flatbuffers::Vector<flatbuffers::Offset<Field>> *>(6); }
|
VT_IS_STRUCT = 8,
|
||||||
uint8_t is_struct() const { return GetField<uint8_t>(8, 0); }
|
VT_MINALIGN = 10,
|
||||||
int32_t minalign() const { return GetField<int32_t>(10, 0); }
|
VT_BYTESIZE = 12,
|
||||||
int32_t bytesize() const { return GetField<int32_t>(12, 0); }
|
VT_ATTRIBUTES = 14,
|
||||||
|
VT_DOCUMENTATION = 16
|
||||||
|
};
|
||||||
|
const flatbuffers::String *name() const {
|
||||||
|
return GetPointer<const flatbuffers::String *>(VT_NAME);
|
||||||
|
}
|
||||||
|
bool KeyCompareLessThan(const Object *o) const {
|
||||||
|
return *name() < *o->name();
|
||||||
|
}
|
||||||
|
int KeyCompareWithValue(const char *val) const {
|
||||||
|
return strcmp(name()->c_str(), val);
|
||||||
|
}
|
||||||
|
const flatbuffers::Vector<flatbuffers::Offset<Field>> *fields() const {
|
||||||
|
return GetPointer<const flatbuffers::Vector<flatbuffers::Offset<Field>> *>(VT_FIELDS);
|
||||||
|
}
|
||||||
|
bool is_struct() const {
|
||||||
|
return GetField<uint8_t>(VT_IS_STRUCT, 0) != 0;
|
||||||
|
}
|
||||||
|
int32_t minalign() const {
|
||||||
|
return GetField<int32_t>(VT_MINALIGN, 0);
|
||||||
|
}
|
||||||
|
int32_t bytesize() const {
|
||||||
|
return GetField<int32_t>(VT_BYTESIZE, 0);
|
||||||
|
}
|
||||||
|
const flatbuffers::Vector<flatbuffers::Offset<KeyValue>> *attributes() const {
|
||||||
|
return GetPointer<const flatbuffers::Vector<flatbuffers::Offset<KeyValue>> *>(VT_ATTRIBUTES);
|
||||||
|
}
|
||||||
|
const flatbuffers::Vector<flatbuffers::Offset<flatbuffers::String>> *documentation() const {
|
||||||
|
return GetPointer<const flatbuffers::Vector<flatbuffers::Offset<flatbuffers::String>> *>(VT_DOCUMENTATION);
|
||||||
|
}
|
||||||
bool Verify(flatbuffers::Verifier &verifier) const {
|
bool Verify(flatbuffers::Verifier &verifier) const {
|
||||||
return VerifyTableStart(verifier) &&
|
return VerifyTableStart(verifier) &&
|
||||||
VerifyFieldRequired<flatbuffers::uoffset_t>(verifier, 4 /* name */) &&
|
VerifyFieldRequired<flatbuffers::uoffset_t>(verifier, VT_NAME) &&
|
||||||
verifier.Verify(name()) &&
|
verifier.Verify(name()) &&
|
||||||
VerifyFieldRequired<flatbuffers::uoffset_t>(verifier, 6 /* fields */) &&
|
VerifyFieldRequired<flatbuffers::uoffset_t>(verifier, VT_FIELDS) &&
|
||||||
verifier.Verify(fields()) &&
|
verifier.Verify(fields()) &&
|
||||||
verifier.VerifyVectorOfTables(fields()) &&
|
verifier.VerifyVectorOfTables(fields()) &&
|
||||||
VerifyField<uint8_t>(verifier, 8 /* is_struct */) &&
|
VerifyField<uint8_t>(verifier, VT_IS_STRUCT) &&
|
||||||
VerifyField<int32_t>(verifier, 10 /* minalign */) &&
|
VerifyField<int32_t>(verifier, VT_MINALIGN) &&
|
||||||
VerifyField<int32_t>(verifier, 12 /* bytesize */) &&
|
VerifyField<int32_t>(verifier, VT_BYTESIZE) &&
|
||||||
|
VerifyField<flatbuffers::uoffset_t>(verifier, VT_ATTRIBUTES) &&
|
||||||
|
verifier.Verify(attributes()) &&
|
||||||
|
verifier.VerifyVectorOfTables(attributes()) &&
|
||||||
|
VerifyField<flatbuffers::uoffset_t>(verifier, VT_DOCUMENTATION) &&
|
||||||
|
verifier.Verify(documentation()) &&
|
||||||
|
verifier.VerifyVectorOfStrings(documentation()) &&
|
||||||
verifier.EndTable();
|
verifier.EndTable();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -274,28 +655,53 @@ struct Object FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table {
|
|||||||
struct ObjectBuilder {
|
struct ObjectBuilder {
|
||||||
flatbuffers::FlatBufferBuilder &fbb_;
|
flatbuffers::FlatBufferBuilder &fbb_;
|
||||||
flatbuffers::uoffset_t start_;
|
flatbuffers::uoffset_t start_;
|
||||||
void add_name(flatbuffers::Offset<flatbuffers::String> name) { fbb_.AddOffset(4, name); }
|
void add_name(flatbuffers::Offset<flatbuffers::String> name) {
|
||||||
void add_fields(flatbuffers::Offset<flatbuffers::Vector<flatbuffers::Offset<Field>>> fields) { fbb_.AddOffset(6, fields); }
|
fbb_.AddOffset(Object::VT_NAME, name);
|
||||||
void add_is_struct(uint8_t is_struct) { fbb_.AddElement<uint8_t>(8, is_struct, 0); }
|
}
|
||||||
void add_minalign(int32_t minalign) { fbb_.AddElement<int32_t>(10, minalign, 0); }
|
void add_fields(flatbuffers::Offset<flatbuffers::Vector<flatbuffers::Offset<Field>>> fields) {
|
||||||
void add_bytesize(int32_t bytesize) { fbb_.AddElement<int32_t>(12, bytesize, 0); }
|
fbb_.AddOffset(Object::VT_FIELDS, fields);
|
||||||
ObjectBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) { start_ = fbb_.StartTable(); }
|
}
|
||||||
|
void add_is_struct(bool is_struct) {
|
||||||
|
fbb_.AddElement<uint8_t>(Object::VT_IS_STRUCT, static_cast<uint8_t>(is_struct), 0);
|
||||||
|
}
|
||||||
|
void add_minalign(int32_t minalign) {
|
||||||
|
fbb_.AddElement<int32_t>(Object::VT_MINALIGN, minalign, 0);
|
||||||
|
}
|
||||||
|
void add_bytesize(int32_t bytesize) {
|
||||||
|
fbb_.AddElement<int32_t>(Object::VT_BYTESIZE, bytesize, 0);
|
||||||
|
}
|
||||||
|
void add_attributes(flatbuffers::Offset<flatbuffers::Vector<flatbuffers::Offset<KeyValue>>> attributes) {
|
||||||
|
fbb_.AddOffset(Object::VT_ATTRIBUTES, attributes);
|
||||||
|
}
|
||||||
|
void add_documentation(flatbuffers::Offset<flatbuffers::Vector<flatbuffers::Offset<flatbuffers::String>>> documentation) {
|
||||||
|
fbb_.AddOffset(Object::VT_DOCUMENTATION, documentation);
|
||||||
|
}
|
||||||
|
ObjectBuilder(flatbuffers::FlatBufferBuilder &_fbb)
|
||||||
|
: fbb_(_fbb) {
|
||||||
|
start_ = fbb_.StartTable();
|
||||||
|
}
|
||||||
ObjectBuilder &operator=(const ObjectBuilder &);
|
ObjectBuilder &operator=(const ObjectBuilder &);
|
||||||
flatbuffers::Offset<Object> Finish() {
|
flatbuffers::Offset<Object> Finish() {
|
||||||
auto o = flatbuffers::Offset<Object>(fbb_.EndTable(start_, 5));
|
const auto end = fbb_.EndTable(start_, 7);
|
||||||
fbb_.Required(o, 4); // name
|
auto o = flatbuffers::Offset<Object>(end);
|
||||||
fbb_.Required(o, 6); // fields
|
fbb_.Required(o, Object::VT_NAME);
|
||||||
|
fbb_.Required(o, Object::VT_FIELDS);
|
||||||
return o;
|
return o;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
inline flatbuffers::Offset<Object> CreateObject(flatbuffers::FlatBufferBuilder &_fbb,
|
inline flatbuffers::Offset<Object> CreateObject(
|
||||||
flatbuffers::Offset<flatbuffers::String> name = 0,
|
flatbuffers::FlatBufferBuilder &_fbb,
|
||||||
flatbuffers::Offset<flatbuffers::Vector<flatbuffers::Offset<Field>>> fields = 0,
|
flatbuffers::Offset<flatbuffers::String> name = 0,
|
||||||
uint8_t is_struct = 0,
|
flatbuffers::Offset<flatbuffers::Vector<flatbuffers::Offset<Field>>> fields = 0,
|
||||||
int32_t minalign = 0,
|
bool is_struct = false,
|
||||||
int32_t bytesize = 0) {
|
int32_t minalign = 0,
|
||||||
|
int32_t bytesize = 0,
|
||||||
|
flatbuffers::Offset<flatbuffers::Vector<flatbuffers::Offset<KeyValue>>> attributes = 0,
|
||||||
|
flatbuffers::Offset<flatbuffers::Vector<flatbuffers::Offset<flatbuffers::String>>> documentation = 0) {
|
||||||
ObjectBuilder builder_(_fbb);
|
ObjectBuilder builder_(_fbb);
|
||||||
|
builder_.add_documentation(documentation);
|
||||||
|
builder_.add_attributes(attributes);
|
||||||
builder_.add_bytesize(bytesize);
|
builder_.add_bytesize(bytesize);
|
||||||
builder_.add_minalign(minalign);
|
builder_.add_minalign(minalign);
|
||||||
builder_.add_fields(fields);
|
builder_.add_fields(fields);
|
||||||
@@ -304,25 +710,62 @@ inline flatbuffers::Offset<Object> CreateObject(flatbuffers::FlatBufferBuilder &
|
|||||||
return builder_.Finish();
|
return builder_.Finish();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline flatbuffers::Offset<Object> CreateObjectDirect(
|
||||||
|
flatbuffers::FlatBufferBuilder &_fbb,
|
||||||
|
const char *name = nullptr,
|
||||||
|
const std::vector<flatbuffers::Offset<Field>> *fields = nullptr,
|
||||||
|
bool is_struct = false,
|
||||||
|
int32_t minalign = 0,
|
||||||
|
int32_t bytesize = 0,
|
||||||
|
const std::vector<flatbuffers::Offset<KeyValue>> *attributes = nullptr,
|
||||||
|
const std::vector<flatbuffers::Offset<flatbuffers::String>> *documentation = nullptr) {
|
||||||
|
return reflection::CreateObject(
|
||||||
|
_fbb,
|
||||||
|
name ? _fbb.CreateString(name) : 0,
|
||||||
|
fields ? _fbb.CreateVector<flatbuffers::Offset<Field>>(*fields) : 0,
|
||||||
|
is_struct,
|
||||||
|
minalign,
|
||||||
|
bytesize,
|
||||||
|
attributes ? _fbb.CreateVector<flatbuffers::Offset<KeyValue>>(*attributes) : 0,
|
||||||
|
documentation ? _fbb.CreateVector<flatbuffers::Offset<flatbuffers::String>>(*documentation) : 0);
|
||||||
|
}
|
||||||
|
|
||||||
struct Schema FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table {
|
struct Schema FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table {
|
||||||
const flatbuffers::Vector<flatbuffers::Offset<Object>> *objects() const { return GetPointer<const flatbuffers::Vector<flatbuffers::Offset<Object>> *>(4); }
|
enum {
|
||||||
const flatbuffers::Vector<flatbuffers::Offset<Enum>> *enums() const { return GetPointer<const flatbuffers::Vector<flatbuffers::Offset<Enum>> *>(6); }
|
VT_OBJECTS = 4,
|
||||||
const flatbuffers::String *file_ident() const { return GetPointer<const flatbuffers::String *>(8); }
|
VT_ENUMS = 6,
|
||||||
const flatbuffers::String *file_ext() const { return GetPointer<const flatbuffers::String *>(10); }
|
VT_FILE_IDENT = 8,
|
||||||
const Object *root_table() const { return GetPointer<const Object *>(12); }
|
VT_FILE_EXT = 10,
|
||||||
|
VT_ROOT_TABLE = 12
|
||||||
|
};
|
||||||
|
const flatbuffers::Vector<flatbuffers::Offset<Object>> *objects() const {
|
||||||
|
return GetPointer<const flatbuffers::Vector<flatbuffers::Offset<Object>> *>(VT_OBJECTS);
|
||||||
|
}
|
||||||
|
const flatbuffers::Vector<flatbuffers::Offset<Enum>> *enums() const {
|
||||||
|
return GetPointer<const flatbuffers::Vector<flatbuffers::Offset<Enum>> *>(VT_ENUMS);
|
||||||
|
}
|
||||||
|
const flatbuffers::String *file_ident() const {
|
||||||
|
return GetPointer<const flatbuffers::String *>(VT_FILE_IDENT);
|
||||||
|
}
|
||||||
|
const flatbuffers::String *file_ext() const {
|
||||||
|
return GetPointer<const flatbuffers::String *>(VT_FILE_EXT);
|
||||||
|
}
|
||||||
|
const Object *root_table() const {
|
||||||
|
return GetPointer<const Object *>(VT_ROOT_TABLE);
|
||||||
|
}
|
||||||
bool Verify(flatbuffers::Verifier &verifier) const {
|
bool Verify(flatbuffers::Verifier &verifier) const {
|
||||||
return VerifyTableStart(verifier) &&
|
return VerifyTableStart(verifier) &&
|
||||||
VerifyFieldRequired<flatbuffers::uoffset_t>(verifier, 4 /* objects */) &&
|
VerifyFieldRequired<flatbuffers::uoffset_t>(verifier, VT_OBJECTS) &&
|
||||||
verifier.Verify(objects()) &&
|
verifier.Verify(objects()) &&
|
||||||
verifier.VerifyVectorOfTables(objects()) &&
|
verifier.VerifyVectorOfTables(objects()) &&
|
||||||
VerifyFieldRequired<flatbuffers::uoffset_t>(verifier, 6 /* enums */) &&
|
VerifyFieldRequired<flatbuffers::uoffset_t>(verifier, VT_ENUMS) &&
|
||||||
verifier.Verify(enums()) &&
|
verifier.Verify(enums()) &&
|
||||||
verifier.VerifyVectorOfTables(enums()) &&
|
verifier.VerifyVectorOfTables(enums()) &&
|
||||||
VerifyField<flatbuffers::uoffset_t>(verifier, 8 /* file_ident */) &&
|
VerifyField<flatbuffers::uoffset_t>(verifier, VT_FILE_IDENT) &&
|
||||||
verifier.Verify(file_ident()) &&
|
verifier.Verify(file_ident()) &&
|
||||||
VerifyField<flatbuffers::uoffset_t>(verifier, 10 /* file_ext */) &&
|
VerifyField<flatbuffers::uoffset_t>(verifier, VT_FILE_EXT) &&
|
||||||
verifier.Verify(file_ext()) &&
|
verifier.Verify(file_ext()) &&
|
||||||
VerifyField<flatbuffers::uoffset_t>(verifier, 12 /* root_table */) &&
|
VerifyField<flatbuffers::uoffset_t>(verifier, VT_ROOT_TABLE) &&
|
||||||
verifier.VerifyTable(root_table()) &&
|
verifier.VerifyTable(root_table()) &&
|
||||||
verifier.EndTable();
|
verifier.EndTable();
|
||||||
}
|
}
|
||||||
@@ -331,27 +774,42 @@ struct Schema FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table {
|
|||||||
struct SchemaBuilder {
|
struct SchemaBuilder {
|
||||||
flatbuffers::FlatBufferBuilder &fbb_;
|
flatbuffers::FlatBufferBuilder &fbb_;
|
||||||
flatbuffers::uoffset_t start_;
|
flatbuffers::uoffset_t start_;
|
||||||
void add_objects(flatbuffers::Offset<flatbuffers::Vector<flatbuffers::Offset<Object>>> objects) { fbb_.AddOffset(4, objects); }
|
void add_objects(flatbuffers::Offset<flatbuffers::Vector<flatbuffers::Offset<Object>>> objects) {
|
||||||
void add_enums(flatbuffers::Offset<flatbuffers::Vector<flatbuffers::Offset<Enum>>> enums) { fbb_.AddOffset(6, enums); }
|
fbb_.AddOffset(Schema::VT_OBJECTS, objects);
|
||||||
void add_file_ident(flatbuffers::Offset<flatbuffers::String> file_ident) { fbb_.AddOffset(8, file_ident); }
|
}
|
||||||
void add_file_ext(flatbuffers::Offset<flatbuffers::String> file_ext) { fbb_.AddOffset(10, file_ext); }
|
void add_enums(flatbuffers::Offset<flatbuffers::Vector<flatbuffers::Offset<Enum>>> enums) {
|
||||||
void add_root_table(flatbuffers::Offset<Object> root_table) { fbb_.AddOffset(12, root_table); }
|
fbb_.AddOffset(Schema::VT_ENUMS, enums);
|
||||||
SchemaBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) { start_ = fbb_.StartTable(); }
|
}
|
||||||
|
void add_file_ident(flatbuffers::Offset<flatbuffers::String> file_ident) {
|
||||||
|
fbb_.AddOffset(Schema::VT_FILE_IDENT, file_ident);
|
||||||
|
}
|
||||||
|
void add_file_ext(flatbuffers::Offset<flatbuffers::String> file_ext) {
|
||||||
|
fbb_.AddOffset(Schema::VT_FILE_EXT, file_ext);
|
||||||
|
}
|
||||||
|
void add_root_table(flatbuffers::Offset<Object> root_table) {
|
||||||
|
fbb_.AddOffset(Schema::VT_ROOT_TABLE, root_table);
|
||||||
|
}
|
||||||
|
SchemaBuilder(flatbuffers::FlatBufferBuilder &_fbb)
|
||||||
|
: fbb_(_fbb) {
|
||||||
|
start_ = fbb_.StartTable();
|
||||||
|
}
|
||||||
SchemaBuilder &operator=(const SchemaBuilder &);
|
SchemaBuilder &operator=(const SchemaBuilder &);
|
||||||
flatbuffers::Offset<Schema> Finish() {
|
flatbuffers::Offset<Schema> Finish() {
|
||||||
auto o = flatbuffers::Offset<Schema>(fbb_.EndTable(start_, 5));
|
const auto end = fbb_.EndTable(start_, 5);
|
||||||
fbb_.Required(o, 4); // objects
|
auto o = flatbuffers::Offset<Schema>(end);
|
||||||
fbb_.Required(o, 6); // enums
|
fbb_.Required(o, Schema::VT_OBJECTS);
|
||||||
|
fbb_.Required(o, Schema::VT_ENUMS);
|
||||||
return o;
|
return o;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
inline flatbuffers::Offset<Schema> CreateSchema(flatbuffers::FlatBufferBuilder &_fbb,
|
inline flatbuffers::Offset<Schema> CreateSchema(
|
||||||
flatbuffers::Offset<flatbuffers::Vector<flatbuffers::Offset<Object>>> objects = 0,
|
flatbuffers::FlatBufferBuilder &_fbb,
|
||||||
flatbuffers::Offset<flatbuffers::Vector<flatbuffers::Offset<Enum>>> enums = 0,
|
flatbuffers::Offset<flatbuffers::Vector<flatbuffers::Offset<Object>>> objects = 0,
|
||||||
flatbuffers::Offset<flatbuffers::String> file_ident = 0,
|
flatbuffers::Offset<flatbuffers::Vector<flatbuffers::Offset<Enum>>> enums = 0,
|
||||||
flatbuffers::Offset<flatbuffers::String> file_ext = 0,
|
flatbuffers::Offset<flatbuffers::String> file_ident = 0,
|
||||||
flatbuffers::Offset<Object> root_table = 0) {
|
flatbuffers::Offset<flatbuffers::String> file_ext = 0,
|
||||||
|
flatbuffers::Offset<Object> root_table = 0) {
|
||||||
SchemaBuilder builder_(_fbb);
|
SchemaBuilder builder_(_fbb);
|
||||||
builder_.add_root_table(root_table);
|
builder_.add_root_table(root_table);
|
||||||
builder_.add_file_ext(file_ext);
|
builder_.add_file_ext(file_ext);
|
||||||
@@ -361,17 +819,49 @@ inline flatbuffers::Offset<Schema> CreateSchema(flatbuffers::FlatBufferBuilder &
|
|||||||
return builder_.Finish();
|
return builder_.Finish();
|
||||||
}
|
}
|
||||||
|
|
||||||
inline const reflection::Schema *GetSchema(const void *buf) { return flatbuffers::GetRoot<reflection::Schema>(buf); }
|
inline flatbuffers::Offset<Schema> CreateSchemaDirect(
|
||||||
|
flatbuffers::FlatBufferBuilder &_fbb,
|
||||||
|
const std::vector<flatbuffers::Offset<Object>> *objects = nullptr,
|
||||||
|
const std::vector<flatbuffers::Offset<Enum>> *enums = nullptr,
|
||||||
|
const char *file_ident = nullptr,
|
||||||
|
const char *file_ext = nullptr,
|
||||||
|
flatbuffers::Offset<Object> root_table = 0) {
|
||||||
|
return reflection::CreateSchema(
|
||||||
|
_fbb,
|
||||||
|
objects ? _fbb.CreateVector<flatbuffers::Offset<Object>>(*objects) : 0,
|
||||||
|
enums ? _fbb.CreateVector<flatbuffers::Offset<Enum>>(*enums) : 0,
|
||||||
|
file_ident ? _fbb.CreateString(file_ident) : 0,
|
||||||
|
file_ext ? _fbb.CreateString(file_ext) : 0,
|
||||||
|
root_table);
|
||||||
|
}
|
||||||
|
|
||||||
inline bool VerifySchemaBuffer(flatbuffers::Verifier &verifier) { return verifier.VerifyBuffer<reflection::Schema>(); }
|
inline const reflection::Schema *GetSchema(const void *buf) {
|
||||||
|
return flatbuffers::GetRoot<reflection::Schema>(buf);
|
||||||
|
}
|
||||||
|
|
||||||
inline const char *SchemaIdentifier() { return "BFBS"; }
|
inline const char *SchemaIdentifier() {
|
||||||
|
return "BFBS";
|
||||||
|
}
|
||||||
|
|
||||||
inline bool SchemaBufferHasIdentifier(const void *buf) { return flatbuffers::BufferHasIdentifier(buf, SchemaIdentifier()); }
|
inline bool SchemaBufferHasIdentifier(const void *buf) {
|
||||||
|
return flatbuffers::BufferHasIdentifier(
|
||||||
|
buf, SchemaIdentifier());
|
||||||
|
}
|
||||||
|
|
||||||
inline const char *SchemaExtension() { return "bfbs"; }
|
inline bool VerifySchemaBuffer(
|
||||||
|
flatbuffers::Verifier &verifier) {
|
||||||
|
return verifier.VerifyBuffer<reflection::Schema>(SchemaIdentifier());
|
||||||
|
}
|
||||||
|
|
||||||
inline void FinishSchemaBuffer(flatbuffers::FlatBufferBuilder &fbb, flatbuffers::Offset<reflection::Schema> root) { fbb.Finish(root, SchemaIdentifier()); }
|
inline const char *SchemaExtension() {
|
||||||
|
return "bfbs";
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void FinishSchemaBuffer(
|
||||||
|
flatbuffers::FlatBufferBuilder &fbb,
|
||||||
|
flatbuffers::Offset<reflection::Schema> root) {
|
||||||
|
fbb.Finish(root, SchemaIdentifier());
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace reflection
|
} // namespace reflection
|
||||||
|
|
||||||
|
|||||||
@@ -21,6 +21,7 @@
|
|||||||
#include <iomanip>
|
#include <iomanip>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
#include <stdint.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
@@ -34,9 +35,10 @@
|
|||||||
#include <winbase.h>
|
#include <winbase.h>
|
||||||
#include <direct.h>
|
#include <direct.h>
|
||||||
#else
|
#else
|
||||||
#include <sys/stat.h>
|
|
||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
#endif
|
#endif
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
|
||||||
#include "flatbuffers/flatbuffers.h"
|
#include "flatbuffers/flatbuffers.h"
|
||||||
|
|
||||||
@@ -93,50 +95,46 @@ inline std::string IntToStringHex(int i, int xdigits) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Portable implementation of strtoll().
|
// Portable implementation of strtoll().
|
||||||
inline int64_t StringToInt(const char *str, int base = 10) {
|
inline int64_t StringToInt(const char *str, char **endptr = nullptr,
|
||||||
|
int base = 10) {
|
||||||
#ifdef _MSC_VER
|
#ifdef _MSC_VER
|
||||||
return _strtoi64(str, nullptr, base);
|
return _strtoi64(str, endptr, base);
|
||||||
#else
|
#else
|
||||||
return strtoll(str, nullptr, base);
|
return strtoll(str, endptr, base);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
// Portable implementation of strtoull().
|
// Portable implementation of strtoull().
|
||||||
inline int64_t StringToUInt(const char *str, int base = 10) {
|
inline uint64_t StringToUInt(const char *str, char **endptr = nullptr,
|
||||||
|
int base = 10) {
|
||||||
#ifdef _MSC_VER
|
#ifdef _MSC_VER
|
||||||
return _strtoui64(str, nullptr, base);
|
return _strtoui64(str, endptr, base);
|
||||||
#else
|
#else
|
||||||
return strtoull(str, nullptr, base);
|
return strtoull(str, endptr, base);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
typedef bool (*LoadFileFunction)(const char *filename, bool binary,
|
||||||
|
std::string *dest);
|
||||||
|
typedef bool (*FileExistsFunction)(const char *filename);
|
||||||
|
|
||||||
|
LoadFileFunction SetLoadFileFunction(LoadFileFunction load_file_function);
|
||||||
|
|
||||||
|
FileExistsFunction SetFileExistsFunction(FileExistsFunction
|
||||||
|
file_exists_function);
|
||||||
|
|
||||||
|
|
||||||
// Check if file "name" exists.
|
// Check if file "name" exists.
|
||||||
inline bool FileExists(const char *name) {
|
bool FileExists(const char *name);
|
||||||
std::ifstream ifs(name);
|
|
||||||
return ifs.good();
|
// Check if "name" exists and it is also a directory.
|
||||||
}
|
bool DirExists(const char *name);
|
||||||
|
|
||||||
// Load file "name" into "buf" returning true if successful
|
// Load file "name" into "buf" returning true if successful
|
||||||
// false otherwise. If "binary" is false data is read
|
// false otherwise. If "binary" is false data is read
|
||||||
// using ifstream's text mode, otherwise data is read with
|
// using ifstream's text mode, otherwise data is read with
|
||||||
// no transcoding.
|
// no transcoding.
|
||||||
inline bool LoadFile(const char *name, bool binary, std::string *buf) {
|
bool LoadFile(const char *name, bool binary, std::string *buf);
|
||||||
std::ifstream ifs(name, binary ? std::ifstream::binary : std::ifstream::in);
|
|
||||||
if (!ifs.is_open()) return false;
|
|
||||||
if (binary) {
|
|
||||||
// The fastest way to read a file into a string.
|
|
||||||
ifs.seekg(0, std::ios::end);
|
|
||||||
(*buf).resize(static_cast<size_t>(ifs.tellg()));
|
|
||||||
ifs.seekg(0, std::ios::beg);
|
|
||||||
ifs.read(&(*buf)[0], (*buf).size());
|
|
||||||
} else {
|
|
||||||
// This is slower, but works correctly on all platforms for text files.
|
|
||||||
std::ostringstream oss;
|
|
||||||
oss << ifs.rdbuf();
|
|
||||||
*buf = oss.str();
|
|
||||||
}
|
|
||||||
return !ifs.bad();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Save data "buf" of length "len" bytes into a file
|
// Save data "buf" of length "len" bytes into a file
|
||||||
// "name" returning true if successful, false otherwise.
|
// "name" returning true if successful, false otherwise.
|
||||||
@@ -280,6 +278,10 @@ inline int FromUTF8(const char **in) {
|
|||||||
}
|
}
|
||||||
if ((**in << len) & 0x80) return -1; // Bit after leading 1's must be 0.
|
if ((**in << len) & 0x80) return -1; // Bit after leading 1's must be 0.
|
||||||
if (!len) return *(*in)++;
|
if (!len) return *(*in)++;
|
||||||
|
// UTF-8 encoded values with a length are between 2 and 4 bytes.
|
||||||
|
if (len < 2 || len > 4) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
// Grab initial bits of the code.
|
// Grab initial bits of the code.
|
||||||
int ucc = *(*in)++ & ((1 << (7 - len)) - 1);
|
int ucc = *(*in)++ & ((1 << (7 - len)) - 1);
|
||||||
for (int i = 0; i < len - 1; i++) {
|
for (int i = 0; i < len - 1; i++) {
|
||||||
@@ -287,6 +289,32 @@ inline int FromUTF8(const char **in) {
|
|||||||
ucc <<= 6;
|
ucc <<= 6;
|
||||||
ucc |= *(*in)++ & 0x3F; // Grab 6 more bits of the code.
|
ucc |= *(*in)++ & 0x3F; // Grab 6 more bits of the code.
|
||||||
}
|
}
|
||||||
|
// UTF-8 cannot encode values between 0xD800 and 0xDFFF (reserved for
|
||||||
|
// UTF-16 surrogate pairs).
|
||||||
|
if (ucc >= 0xD800 && ucc <= 0xDFFF) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
// UTF-8 must represent code points in their shortest possible encoding.
|
||||||
|
switch (len) {
|
||||||
|
case 2:
|
||||||
|
// Two bytes of UTF-8 can represent code points from U+0080 to U+07FF.
|
||||||
|
if (ucc < 0x0080 || ucc > 0x07FF) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
// Three bytes of UTF-8 can represent code points from U+0800 to U+FFFF.
|
||||||
|
if (ucc < 0x0800 || ucc > 0xFFFF) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 4:
|
||||||
|
// Four bytes of UTF-8 can represent code points from U+10000 to U+10FFFF.
|
||||||
|
if (ucc < 0x10000 || ucc > 0x10FFFF) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
return ucc;
|
return ucc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -23,10 +23,18 @@ package com.google.flatbuffers;
|
|||||||
*/
|
*/
|
||||||
public class Constants {
|
public class Constants {
|
||||||
// Java doesn't seem to have these.
|
// Java doesn't seem to have these.
|
||||||
|
/** The number of bytes in an `byte`. */
|
||||||
|
static final int SIZEOF_BYTE = 1;
|
||||||
/** The number of bytes in a `short`. */
|
/** The number of bytes in a `short`. */
|
||||||
static final int SIZEOF_SHORT = 2;
|
static final int SIZEOF_SHORT = 2;
|
||||||
/** The number of bytes in an `int`. */
|
/** The number of bytes in an `int`. */
|
||||||
static final int SIZEOF_INT = 4;
|
static final int SIZEOF_INT = 4;
|
||||||
|
/** The number of bytes in an `float`. */
|
||||||
|
static final int SIZEOF_FLOAT = 4;
|
||||||
|
/** The number of bytes in an `long`. */
|
||||||
|
static final int SIZEOF_LONG = 8;
|
||||||
|
/** The number of bytes in an `double`. */
|
||||||
|
static final int SIZEOF_DOUBLE = 8;
|
||||||
/** The number of bytes in a file identifier. */
|
/** The number of bytes in a file identifier. */
|
||||||
static final int FILE_IDENTIFIER_LENGTH = 4;
|
static final int FILE_IDENTIFIER_LENGTH = 4;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,6 +17,11 @@
|
|||||||
package com.google.flatbuffers;
|
package com.google.flatbuffers;
|
||||||
|
|
||||||
import static com.google.flatbuffers.Constants.*;
|
import static com.google.flatbuffers.Constants.*;
|
||||||
|
|
||||||
|
import java.nio.CharBuffer;
|
||||||
|
import java.nio.charset.CharacterCodingException;
|
||||||
|
import java.nio.charset.CharsetEncoder;
|
||||||
|
import java.nio.charset.CoderResult;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
import java.nio.ByteOrder;
|
import java.nio.ByteOrder;
|
||||||
@@ -28,8 +33,7 @@ import java.nio.charset.Charset;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Class that helps you build a FlatBuffer. See the section
|
* Class that helps you build a FlatBuffer. See the section
|
||||||
* @ref flatbuffers_guide_use_java_c-sharp "Use in Java/C#" in the
|
* "Use in Java/C#" in the main FlatBuffers documentation.
|
||||||
* main FlatBuffers documentation.
|
|
||||||
*/
|
*/
|
||||||
public class FlatBufferBuilder {
|
public class FlatBufferBuilder {
|
||||||
/// @cond FLATBUFFERS_INTERNAL
|
/// @cond FLATBUFFERS_INTERNAL
|
||||||
@@ -46,6 +50,8 @@ public class FlatBufferBuilder {
|
|||||||
int num_vtables = 0; // Number of entries in `vtables` in use.
|
int num_vtables = 0; // Number of entries in `vtables` in use.
|
||||||
int vector_num_elems = 0; // For the current vector being built.
|
int vector_num_elems = 0; // For the current vector being built.
|
||||||
boolean force_defaults = false; // False omits default values from the serialized data.
|
boolean force_defaults = false; // False omits default values from the serialized data.
|
||||||
|
CharsetEncoder encoder = utf8charset.newEncoder();
|
||||||
|
ByteBuffer dst;
|
||||||
/// @endcond
|
/// @endcond
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -182,7 +188,7 @@ public class FlatBufferBuilder {
|
|||||||
*
|
*
|
||||||
* @param x A `boolean` to put into the buffer.
|
* @param x A `boolean` to put into the buffer.
|
||||||
*/
|
*/
|
||||||
public void putBoolean(boolean x) { bb.put (space -= 1, (byte)(x ? 1 : 0)); }
|
public void putBoolean(boolean x) { bb.put (space -= Constants.SIZEOF_BYTE, (byte)(x ? 1 : 0)); }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add a `byte` to the buffer, backwards from the current location. Doesn't align nor
|
* Add a `byte` to the buffer, backwards from the current location. Doesn't align nor
|
||||||
@@ -190,7 +196,7 @@ public class FlatBufferBuilder {
|
|||||||
*
|
*
|
||||||
* @param x A `byte` to put into the buffer.
|
* @param x A `byte` to put into the buffer.
|
||||||
*/
|
*/
|
||||||
public void putByte (byte x) { bb.put (space -= 1, x); }
|
public void putByte (byte x) { bb.put (space -= Constants.SIZEOF_BYTE, x); }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add a `short` to the buffer, backwards from the current location. Doesn't align nor
|
* Add a `short` to the buffer, backwards from the current location. Doesn't align nor
|
||||||
@@ -198,7 +204,7 @@ public class FlatBufferBuilder {
|
|||||||
*
|
*
|
||||||
* @param x A `short` to put into the buffer.
|
* @param x A `short` to put into the buffer.
|
||||||
*/
|
*/
|
||||||
public void putShort (short x) { bb.putShort (space -= 2, x); }
|
public void putShort (short x) { bb.putShort (space -= Constants.SIZEOF_SHORT, x); }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add an `int` to the buffer, backwards from the current location. Doesn't align nor
|
* Add an `int` to the buffer, backwards from the current location. Doesn't align nor
|
||||||
@@ -206,7 +212,7 @@ public class FlatBufferBuilder {
|
|||||||
*
|
*
|
||||||
* @param x An `int` to put into the buffer.
|
* @param x An `int` to put into the buffer.
|
||||||
*/
|
*/
|
||||||
public void putInt (int x) { bb.putInt (space -= 4, x); }
|
public void putInt (int x) { bb.putInt (space -= Constants.SIZEOF_INT, x); }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add a `long` to the buffer, backwards from the current location. Doesn't align nor
|
* Add a `long` to the buffer, backwards from the current location. Doesn't align nor
|
||||||
@@ -214,7 +220,7 @@ public class FlatBufferBuilder {
|
|||||||
*
|
*
|
||||||
* @param x A `long` to put into the buffer.
|
* @param x A `long` to put into the buffer.
|
||||||
*/
|
*/
|
||||||
public void putLong (long x) { bb.putLong (space -= 8, x); }
|
public void putLong (long x) { bb.putLong (space -= Constants.SIZEOF_LONG, x); }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add a `float` to the buffer, backwards from the current location. Doesn't align nor
|
* Add a `float` to the buffer, backwards from the current location. Doesn't align nor
|
||||||
@@ -222,7 +228,7 @@ public class FlatBufferBuilder {
|
|||||||
*
|
*
|
||||||
* @param x A `float` to put into the buffer.
|
* @param x A `float` to put into the buffer.
|
||||||
*/
|
*/
|
||||||
public void putFloat (float x) { bb.putFloat (space -= 4, x); }
|
public void putFloat (float x) { bb.putFloat (space -= Constants.SIZEOF_FLOAT, x); }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add a `double` to the buffer, backwards from the current location. Doesn't align nor
|
* Add a `double` to the buffer, backwards from the current location. Doesn't align nor
|
||||||
@@ -230,7 +236,7 @@ public class FlatBufferBuilder {
|
|||||||
*
|
*
|
||||||
* @param x A `double` to put into the buffer.
|
* @param x A `double` to put into the buffer.
|
||||||
*/
|
*/
|
||||||
public void putDouble (double x) { bb.putDouble(space -= 8, x); }
|
public void putDouble (double x) { bb.putDouble(space -= Constants.SIZEOF_DOUBLE, x); }
|
||||||
/// @endcond
|
/// @endcond
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -238,49 +244,49 @@ public class FlatBufferBuilder {
|
|||||||
*
|
*
|
||||||
* @param x A `boolean` to put into the buffer.
|
* @param x A `boolean` to put into the buffer.
|
||||||
*/
|
*/
|
||||||
public void addBoolean(boolean x) { prep(1, 0); putBoolean(x); }
|
public void addBoolean(boolean x) { prep(Constants.SIZEOF_BYTE, 0); putBoolean(x); }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add a `byte` to the buffer, properly aligned, and grows the buffer (if necessary).
|
* Add a `byte` to the buffer, properly aligned, and grows the buffer (if necessary).
|
||||||
*
|
*
|
||||||
* @param x A `byte` to put into the buffer.
|
* @param x A `byte` to put into the buffer.
|
||||||
*/
|
*/
|
||||||
public void addByte (byte x) { prep(1, 0); putByte (x); }
|
public void addByte (byte x) { prep(Constants.SIZEOF_BYTE, 0); putByte (x); }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add a `short` to the buffer, properly aligned, and grows the buffer (if necessary).
|
* Add a `short` to the buffer, properly aligned, and grows the buffer (if necessary).
|
||||||
*
|
*
|
||||||
* @param x A `short` to put into the buffer.
|
* @param x A `short` to put into the buffer.
|
||||||
*/
|
*/
|
||||||
public void addShort (short x) { prep(2, 0); putShort (x); }
|
public void addShort (short x) { prep(Constants.SIZEOF_SHORT, 0); putShort (x); }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add an `int` to the buffer, properly aligned, and grows the buffer (if necessary).
|
* Add an `int` to the buffer, properly aligned, and grows the buffer (if necessary).
|
||||||
*
|
*
|
||||||
* @param x An `int` to put into the buffer.
|
* @param x An `int` to put into the buffer.
|
||||||
*/
|
*/
|
||||||
public void addInt (int x) { prep(4, 0); putInt (x); }
|
public void addInt (int x) { prep(Constants.SIZEOF_INT, 0); putInt (x); }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add a `long` to the buffer, properly aligned, and grows the buffer (if necessary).
|
* Add a `long` to the buffer, properly aligned, and grows the buffer (if necessary).
|
||||||
*
|
*
|
||||||
* @param x A `long` to put into the buffer.
|
* @param x A `long` to put into the buffer.
|
||||||
*/
|
*/
|
||||||
public void addLong (long x) { prep(8, 0); putLong (x); }
|
public void addLong (long x) { prep(Constants.SIZEOF_LONG, 0); putLong (x); }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add a `float` to the buffer, properly aligned, and grows the buffer (if necessary).
|
* Add a `float` to the buffer, properly aligned, and grows the buffer (if necessary).
|
||||||
*
|
*
|
||||||
* @param x A `float` to put into the buffer.
|
* @param x A `float` to put into the buffer.
|
||||||
*/
|
*/
|
||||||
public void addFloat (float x) { prep(4, 0); putFloat (x); }
|
public void addFloat (float x) { prep(Constants.SIZEOF_FLOAT, 0); putFloat (x); }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add a `double` to the buffer, properly aligned, and grows the buffer (if necessary).
|
* Add a `double` to the buffer, properly aligned, and grows the buffer (if necessary).
|
||||||
*
|
*
|
||||||
* @param x A `double` to put into the buffer.
|
* @param x A `double` to put into the buffer.
|
||||||
*/
|
*/
|
||||||
public void addDouble (double x) { prep(8, 0); putDouble (x); }
|
public void addDouble (double x) { prep(Constants.SIZEOF_DOUBLE, 0); putDouble (x); }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds on offset, relative to where it will be written.
|
* Adds on offset, relative to where it will be written.
|
||||||
@@ -361,19 +367,82 @@ public class FlatBufferBuilder {
|
|||||||
}
|
}
|
||||||
/// @endcond
|
/// @endcond
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new array/vector and return a ByteBuffer to be filled later.
|
||||||
|
* Call {@link #endVector} after this method to get an offset to the beginning
|
||||||
|
* of vector.
|
||||||
|
*
|
||||||
|
* @param elem_size the size of each element in bytes.
|
||||||
|
* @param num_elems number of elements in the vector.
|
||||||
|
* @param alignment byte alignment.
|
||||||
|
* @return ByteBuffer with position and limit set to the space allocated for the array.
|
||||||
|
*/
|
||||||
|
public ByteBuffer createUnintializedVector(int elem_size, int num_elems, int alignment) {
|
||||||
|
int length = elem_size * num_elems;
|
||||||
|
startVector(elem_size, num_elems, alignment);
|
||||||
|
|
||||||
|
bb.position(space -= length);
|
||||||
|
|
||||||
|
// Slice and limit the copy vector to point to the 'array'
|
||||||
|
ByteBuffer copy = bb.slice().order(ByteOrder.LITTLE_ENDIAN);
|
||||||
|
copy.limit(length);
|
||||||
|
return copy;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Encode the string `s` in the buffer using UTF-8.
|
* Create a vector of tables.
|
||||||
|
*
|
||||||
|
* @param offsets Offsets of the tables.
|
||||||
|
* @return Returns offset of the vector.
|
||||||
|
*/
|
||||||
|
public int createVectorOfTables(int[] offsets) {
|
||||||
|
notNested();
|
||||||
|
startVector(Constants.SIZEOF_INT, offsets.length, Constants.SIZEOF_INT);
|
||||||
|
for(int i = offsets.length - 1; i >= 0; i--) addOffset(offsets[i]);
|
||||||
|
return endVector();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a vector of sorted by the key tables.
|
||||||
|
*
|
||||||
|
* @param obj Instance of the table subclass.
|
||||||
|
* @param offsets Offsets of the tables.
|
||||||
|
* @return Returns offset of the sorted vector.
|
||||||
|
*/
|
||||||
|
public <T extends Table> int createSortedVectorOfTables(T obj, int[] offsets) {
|
||||||
|
obj.sortTables(offsets, bb);
|
||||||
|
return createVectorOfTables(offsets);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Encode the string `s` in the buffer using UTF-8. If {@code s} is
|
||||||
|
* already a {@link CharBuffer}, this method is allocation free.
|
||||||
*
|
*
|
||||||
* @param s The string to encode.
|
* @param s The string to encode.
|
||||||
* @return The offset in the buffer where the encoded string starts.
|
* @return The offset in the buffer where the encoded string starts.
|
||||||
*/
|
*/
|
||||||
public int createString(String s) {
|
public int createString(CharSequence s) {
|
||||||
byte[] utf8 = s.getBytes(utf8charset);
|
int length = s.length();
|
||||||
addByte((byte)0);
|
int estimatedDstCapacity = (int) (length * encoder.maxBytesPerChar());
|
||||||
startVector(1, utf8.length, 1);
|
if (dst == null || dst.capacity() < estimatedDstCapacity) {
|
||||||
bb.position(space -= utf8.length);
|
dst = ByteBuffer.allocate(Math.max(128, estimatedDstCapacity));
|
||||||
bb.put(utf8, 0, utf8.length);
|
}
|
||||||
return endVector();
|
|
||||||
|
dst.clear();
|
||||||
|
|
||||||
|
CharBuffer src = s instanceof CharBuffer ? (CharBuffer) s :
|
||||||
|
CharBuffer.wrap(s);
|
||||||
|
CoderResult result = encoder.encode(src, dst, true);
|
||||||
|
if (result.isError()) {
|
||||||
|
try {
|
||||||
|
result.throwException();
|
||||||
|
} catch (CharacterCodingException x) {
|
||||||
|
throw new Error(x);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
dst.flip();
|
||||||
|
return createString(dst);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -391,6 +460,20 @@ public class FlatBufferBuilder {
|
|||||||
return endVector();
|
return endVector();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a byte array in the buffer.
|
||||||
|
*
|
||||||
|
* @param arr A source array with data
|
||||||
|
* @return The offset in the buffer where the encoded array starts.
|
||||||
|
*/
|
||||||
|
public int createByteVector(byte[] arr) {
|
||||||
|
int length = arr.length;
|
||||||
|
startVector(1, length, 1);
|
||||||
|
bb.position(space -= length);
|
||||||
|
bb.put(arr);
|
||||||
|
return endVector();
|
||||||
|
}
|
||||||
|
|
||||||
/// @cond FLATBUFFERS_INTERNAL
|
/// @cond FLATBUFFERS_INTERNAL
|
||||||
/**
|
/**
|
||||||
* Should not be accessing the final buffer before it is finished.
|
* Should not be accessing the final buffer before it is finished.
|
||||||
@@ -428,8 +511,7 @@ public class FlatBufferBuilder {
|
|||||||
* call this directly. The `FlatBuffers` compiler will generate helper methods
|
* call this directly. The `FlatBuffers` compiler will generate helper methods
|
||||||
* that call this method internally.
|
* that call this method internally.
|
||||||
* <p>
|
* <p>
|
||||||
* For example, using the "Monster" code found on the
|
* For example, using the "Monster" code found on the "landing page". An
|
||||||
* @ref flatbuffers_guide_use_java_c-sharp "landing page". An
|
|
||||||
* object of type `Monster` can be created using the following code:
|
* object of type `Monster` can be created using the following code:
|
||||||
*
|
*
|
||||||
* <pre>{@code
|
* <pre>{@code
|
||||||
@@ -708,6 +790,8 @@ public class FlatBufferBuilder {
|
|||||||
* Get the ByteBuffer representing the FlatBuffer. Only call this after you've
|
* Get the ByteBuffer representing the FlatBuffer. Only call this after you've
|
||||||
* called `finish()`. The actual data starts at the ByteBuffer's current position,
|
* called `finish()`. The actual data starts at the ByteBuffer's current position,
|
||||||
* not necessarily at `0`.
|
* not necessarily at `0`.
|
||||||
|
*
|
||||||
|
* @return The {@link ByteBuffer} representing the FlatBuffer
|
||||||
*/
|
*/
|
||||||
public ByteBuffer dataBuffer() {
|
public ByteBuffer dataBuffer() {
|
||||||
finished();
|
finished();
|
||||||
|
|||||||
@@ -19,6 +19,11 @@ package com.google.flatbuffers;
|
|||||||
import static com.google.flatbuffers.Constants.*;
|
import static com.google.flatbuffers.Constants.*;
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
import java.nio.ByteOrder;
|
import java.nio.ByteOrder;
|
||||||
|
import java.nio.CharBuffer;
|
||||||
|
import java.nio.charset.CharacterCodingException;
|
||||||
|
import java.nio.charset.Charset;
|
||||||
|
import java.nio.charset.CharsetDecoder;
|
||||||
|
import java.nio.charset.CoderResult;
|
||||||
|
|
||||||
/// @cond FLATBUFFERS_INTERNAL
|
/// @cond FLATBUFFERS_INTERNAL
|
||||||
|
|
||||||
@@ -26,6 +31,19 @@ import java.nio.ByteOrder;
|
|||||||
* All tables in the generated code derive from this class, and add their own accessors.
|
* All tables in the generated code derive from this class, and add their own accessors.
|
||||||
*/
|
*/
|
||||||
public class Table {
|
public class Table {
|
||||||
|
private final static ThreadLocal<CharsetDecoder> UTF8_DECODER = new ThreadLocal<CharsetDecoder>() {
|
||||||
|
@Override
|
||||||
|
protected CharsetDecoder initialValue() {
|
||||||
|
return Charset.forName("UTF-8").newDecoder();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
public final static ThreadLocal<Charset> UTF8_CHARSET = new ThreadLocal<Charset>() {
|
||||||
|
@Override
|
||||||
|
protected Charset initialValue() {
|
||||||
|
return Charset.forName("UTF-8");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
private final static ThreadLocal<CharBuffer> CHAR_BUFFER = new ThreadLocal<CharBuffer>();
|
||||||
/** Used to hold the position of the `bb` buffer. */
|
/** Used to hold the position of the `bb` buffer. */
|
||||||
protected int bb_pos;
|
protected int bb_pos;
|
||||||
/** The underlying ByteBuffer to hold the data of the Table. */
|
/** The underlying ByteBuffer to hold the data of the Table. */
|
||||||
@@ -49,6 +67,11 @@ public class Table {
|
|||||||
return vtable_offset < bb.getShort(vtable) ? bb.getShort(vtable + vtable_offset) : 0;
|
return vtable_offset < bb.getShort(vtable) ? bb.getShort(vtable + vtable_offset) : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected static int __offset(int vtable_offset, int offset, ByteBuffer bb) {
|
||||||
|
int vtable = bb.array().length - offset;
|
||||||
|
return bb.getShort(vtable + vtable_offset - bb.getInt(vtable)) + vtable;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieve a relative offset.
|
* Retrieve a relative offset.
|
||||||
*
|
*
|
||||||
@@ -59,6 +82,10 @@ public class Table {
|
|||||||
return offset + bb.getInt(offset);
|
return offset + bb.getInt(offset);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected static int __indirect(int offset, ByteBuffer bb) {
|
||||||
|
return offset + bb.getInt(offset);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a Java `String` from UTF-8 data stored inside the FlatBuffer.
|
* Create a Java `String` from UTF-8 data stored inside the FlatBuffer.
|
||||||
*
|
*
|
||||||
@@ -71,20 +98,34 @@ public class Table {
|
|||||||
* @return Returns a `String` from the data stored inside the FlatBuffer at `offset`.
|
* @return Returns a `String` from the data stored inside the FlatBuffer at `offset`.
|
||||||
*/
|
*/
|
||||||
protected String __string(int offset) {
|
protected String __string(int offset) {
|
||||||
|
CharsetDecoder decoder = UTF8_DECODER.get();
|
||||||
|
decoder.reset();
|
||||||
|
|
||||||
offset += bb.getInt(offset);
|
offset += bb.getInt(offset);
|
||||||
if (bb.hasArray()) {
|
ByteBuffer src = bb.duplicate().order(ByteOrder.LITTLE_ENDIAN);
|
||||||
return new String(bb.array(), bb.arrayOffset() + offset + SIZEOF_INT, bb.getInt(offset),
|
int length = src.getInt(offset);
|
||||||
FlatBufferBuilder.utf8charset);
|
src.position(offset + SIZEOF_INT);
|
||||||
} else {
|
src.limit(offset + SIZEOF_INT + length);
|
||||||
// We can't access .array(), since the ByteBuffer is read-only,
|
|
||||||
// off-heap or a memory map
|
int required = (int)((float)length * decoder.maxCharsPerByte());
|
||||||
ByteBuffer bb = this.bb.duplicate().order(ByteOrder.LITTLE_ENDIAN);
|
CharBuffer dst = CHAR_BUFFER.get();
|
||||||
// We're forced to make an extra copy:
|
if (dst == null || dst.capacity() < required) {
|
||||||
byte[] copy = new byte[bb.getInt(offset)];
|
dst = CharBuffer.allocate(required);
|
||||||
bb.position(offset + SIZEOF_INT);
|
CHAR_BUFFER.set(dst);
|
||||||
bb.get(copy);
|
|
||||||
return new String(copy, 0, copy.length, FlatBufferBuilder.utf8charset);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
dst.clear();
|
||||||
|
|
||||||
|
try {
|
||||||
|
CoderResult cr = decoder.decode(src, dst, true);
|
||||||
|
if (!cr.isUnderflow()) {
|
||||||
|
cr.throwException();
|
||||||
|
}
|
||||||
|
} catch (CharacterCodingException x) {
|
||||||
|
throw new Error(x);
|
||||||
|
}
|
||||||
|
|
||||||
|
return dst.flip().toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -113,9 +154,13 @@ public class Table {
|
|||||||
/**
|
/**
|
||||||
* Get a whole vector as a ByteBuffer.
|
* Get a whole vector as a ByteBuffer.
|
||||||
*
|
*
|
||||||
* This is efficient, since it only allocates a new bytebuffer object, but does not actually copy
|
* This is efficient, since it only allocates a new {@link ByteBuffer} object,
|
||||||
* the data, it still refers to the same bytes as the original ByteBuffer. Also useful with nested
|
* but does not actually copy the data, it still refers to the same bytes
|
||||||
* FlatBuffers, etc.
|
* as the original ByteBuffer. Also useful with nested FlatBuffers, etc.
|
||||||
|
*
|
||||||
|
* @param vector_offset The position of the vector in the byte buffer
|
||||||
|
* @param elem_size The size of each element in the array
|
||||||
|
* @return The {@link ByteBuffer} for the array
|
||||||
*/
|
*/
|
||||||
protected ByteBuffer __vector_as_bytebuffer(int vector_offset, int elem_size) {
|
protected ByteBuffer __vector_as_bytebuffer(int vector_offset, int elem_size) {
|
||||||
int o = __offset(vector_offset);
|
int o = __offset(vector_offset);
|
||||||
@@ -142,10 +187,12 @@ public class Table {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check if a ByteBuffer contains a file identifier.
|
* Check if a {@link ByteBuffer} contains a file identifier.
|
||||||
*
|
*
|
||||||
* @param bb A `ByteBuffer` to check if it contains the identifier `ident`.
|
* @param bb A {@code ByteBuffer} to check if it contains the identifier
|
||||||
* @param ident A `String` identifier of the flatbuffer file.
|
* `ident`.
|
||||||
|
* @param ident A `String` identifier of the FlatBuffer file.
|
||||||
|
* @return True if the buffer contains the file identifier
|
||||||
*/
|
*/
|
||||||
protected static boolean __has_identifier(ByteBuffer bb, String ident) {
|
protected static boolean __has_identifier(ByteBuffer bb, String ident) {
|
||||||
if (ident.length() != FILE_IDENTIFIER_LENGTH)
|
if (ident.length() != FILE_IDENTIFIER_LENGTH)
|
||||||
@@ -156,6 +203,76 @@ public class Table {
|
|||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sort tables by the key.
|
||||||
|
*
|
||||||
|
* @param offsets An 'int' indexes of the tables into the bb.
|
||||||
|
* @param bb A {@code ByteBuffer} to get the tables.
|
||||||
|
*/
|
||||||
|
protected void sortTables(int[] offsets, final ByteBuffer bb) {
|
||||||
|
Integer[] off = new Integer[offsets.length];
|
||||||
|
for (int i = 0; i < offsets.length; i++) off[i] = offsets[i];
|
||||||
|
java.util.Arrays.sort(off, new java.util.Comparator<Integer>() {
|
||||||
|
public int compare(Integer o1, Integer o2) {
|
||||||
|
return keysCompare(o1, o2, bb);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
for (int i = 0; i < offsets.length; i++) offsets[i] = off[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Compare two tables by the key.
|
||||||
|
*
|
||||||
|
* @param o1 An 'Integer' index of the first key into the bb.
|
||||||
|
* @param o2 An 'Integer' index of the second key into the bb.
|
||||||
|
* @param bb A {@code ByteBuffer} to get the keys.
|
||||||
|
*/
|
||||||
|
protected int keysCompare(Integer o1, Integer o2, ByteBuffer bb) { return 0; }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Compare two strings in the buffer.
|
||||||
|
*
|
||||||
|
* @param offset_1 An 'int' index of the first string into the bb.
|
||||||
|
* @param offset_2 An 'int' index of the second string into the bb.
|
||||||
|
* @param bb A {@code ByteBuffer} to get the strings.
|
||||||
|
*/
|
||||||
|
protected static int compareStrings(int offset_1, int offset_2, ByteBuffer bb) {
|
||||||
|
offset_1 += bb.getInt(offset_1);
|
||||||
|
offset_2 += bb.getInt(offset_2);
|
||||||
|
int len_1 = bb.getInt(offset_1);
|
||||||
|
int len_2 = bb.getInt(offset_2);
|
||||||
|
int startPos_1 = offset_1 + SIZEOF_INT;
|
||||||
|
int startPos_2 = offset_2 + SIZEOF_INT;
|
||||||
|
int len = Math.min(len_1, len_2);
|
||||||
|
byte[] bbArray = bb.array();
|
||||||
|
for(int i = 0; i < len; i++) {
|
||||||
|
if (bbArray[i + startPos_1] != bbArray[i + startPos_2])
|
||||||
|
return bbArray[i + startPos_1] - bbArray[i + startPos_2];
|
||||||
|
}
|
||||||
|
return len_1 - len_2;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Compare string from the buffer with the 'String' object.
|
||||||
|
*
|
||||||
|
* @param offset_1 An 'int' index of the first string into the bb.
|
||||||
|
* @param key Second string as a byte array.
|
||||||
|
* @param bb A {@code ByteBuffer} to get the first string.
|
||||||
|
*/
|
||||||
|
protected static int compareStrings(int offset_1, byte[] key, ByteBuffer bb) {
|
||||||
|
offset_1 += bb.getInt(offset_1);
|
||||||
|
int len_1 = bb.getInt(offset_1);
|
||||||
|
int len_2 = key.length;
|
||||||
|
int startPos_1 = offset_1 + Constants.SIZEOF_INT;
|
||||||
|
int len = Math.min(len_1, len_2);
|
||||||
|
byte[] bbArray = bb.array();
|
||||||
|
for (int i = 0; i < len; i++) {
|
||||||
|
if (bbArray[i + startPos_1] != key[i])
|
||||||
|
return bbArray[i + startPos_1] - key[i];
|
||||||
|
}
|
||||||
|
return len_1 - len_2;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// @endcond
|
/// @endcond
|
||||||
|
|||||||
@@ -2,6 +2,19 @@
|
|||||||
/// @addtogroup flatbuffers_javascript_api
|
/// @addtogroup flatbuffers_javascript_api
|
||||||
/// @{
|
/// @{
|
||||||
/// @cond FLATBUFFERS_INTERNAL
|
/// @cond FLATBUFFERS_INTERNAL
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @fileoverview
|
||||||
|
*
|
||||||
|
* Need to suppress 'global this' error so the Node.js export line doesn't cause
|
||||||
|
* closure compile to error out.
|
||||||
|
* @suppress {globalThis}
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @const
|
||||||
|
* @namespace
|
||||||
|
*/
|
||||||
var flatbuffers = {};
|
var flatbuffers = {};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -71,8 +84,8 @@ flatbuffers.isLittleEndian = new Uint16Array(new Uint8Array([1, 0]).buffer)[0] =
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @constructor
|
* @constructor
|
||||||
* @param {number} high
|
|
||||||
* @param {number} low
|
* @param {number} low
|
||||||
|
* @param {number} high
|
||||||
*/
|
*/
|
||||||
flatbuffers.Long = function(low, high) {
|
flatbuffers.Long = function(low, high) {
|
||||||
/**
|
/**
|
||||||
@@ -88,6 +101,16 @@ flatbuffers.Long = function(low, high) {
|
|||||||
this.high = high | 0;
|
this.high = high | 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {number} low
|
||||||
|
* @param {number} high
|
||||||
|
* @returns {flatbuffers.Long}
|
||||||
|
*/
|
||||||
|
flatbuffers.Long.create = function(low, high) {
|
||||||
|
// Special-case zero to avoid GC overhead for default values
|
||||||
|
return low == 0 && high == 0 ? flatbuffers.Long.ZERO : new flatbuffers.Long(low, high);
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @returns {number}
|
* @returns {number}
|
||||||
*/
|
*/
|
||||||
@@ -115,11 +138,13 @@ flatbuffers.Long.ZERO = new flatbuffers.Long(0, 0);
|
|||||||
* Create a FlatBufferBuilder.
|
* Create a FlatBufferBuilder.
|
||||||
*
|
*
|
||||||
* @constructor
|
* @constructor
|
||||||
* @param {number=} initial_size
|
* @param {number=} opt_initial_size
|
||||||
*/
|
*/
|
||||||
flatbuffers.Builder = function(initial_size) {
|
flatbuffers.Builder = function(opt_initial_size) {
|
||||||
if (!initial_size) {
|
if (!opt_initial_size) {
|
||||||
initial_size = 1024;
|
var initial_size = 1024;
|
||||||
|
} else {
|
||||||
|
var initial_size = opt_initial_size;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -224,9 +249,8 @@ flatbuffers.Builder.prototype.dataBuffer = function() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the ByteBuffer representing the FlatBuffer. Only call this after you've
|
* Get the bytes representing the FlatBuffer. Only call this after you've
|
||||||
* called finish(). The actual data starts at the ByteBuffer's current position,
|
* called finish().
|
||||||
* not necessarily at 0.
|
|
||||||
*
|
*
|
||||||
* @returns {Uint8Array}
|
* @returns {Uint8Array}
|
||||||
*/
|
*/
|
||||||
@@ -515,6 +539,10 @@ flatbuffers.Builder.prototype.offset = function() {
|
|||||||
* @param {flatbuffers.ByteBuffer} bb The current buffer with the existing data
|
* @param {flatbuffers.ByteBuffer} bb The current buffer with the existing data
|
||||||
* @returns {flatbuffers.ByteBuffer} A new byte buffer with the old data copied
|
* @returns {flatbuffers.ByteBuffer} A new byte buffer with the old data copied
|
||||||
* to it. The data is located at the end of the buffer.
|
* to it. The data is located at the end of the buffer.
|
||||||
|
*
|
||||||
|
* uint8Array.set() formally takes {Array<number>|ArrayBufferView}, so to pass
|
||||||
|
* it a uint8Array we need to suppress the type check:
|
||||||
|
* @suppress {checkTypes}
|
||||||
*/
|
*/
|
||||||
flatbuffers.Builder.growByteBuffer = function(bb) {
|
flatbuffers.Builder.growByteBuffer = function(bb) {
|
||||||
var old_buf_size = bb.capacity();
|
var old_buf_size = bb.capacity();
|
||||||
@@ -629,10 +657,11 @@ outer_loop:
|
|||||||
* Finalize a buffer, poiting to the given `root_table`.
|
* Finalize a buffer, poiting to the given `root_table`.
|
||||||
*
|
*
|
||||||
* @param {flatbuffers.Offset} root_table
|
* @param {flatbuffers.Offset} root_table
|
||||||
* @param {string=} file_identifier
|
* @param {string=} opt_file_identifier
|
||||||
*/
|
*/
|
||||||
flatbuffers.Builder.prototype.finish = function(root_table, file_identifier) {
|
flatbuffers.Builder.prototype.finish = function(root_table, opt_file_identifier) {
|
||||||
if (file_identifier) {
|
if (opt_file_identifier) {
|
||||||
|
var file_identifier = opt_file_identifier;
|
||||||
this.prep(this.minalign, flatbuffers.SIZEOF_INT +
|
this.prep(this.minalign, flatbuffers.SIZEOF_INT +
|
||||||
flatbuffers.FILE_IDENTIFIER_LENGTH);
|
flatbuffers.FILE_IDENTIFIER_LENGTH);
|
||||||
if (file_identifier.length != flatbuffers.FILE_IDENTIFIER_LENGTH) {
|
if (file_identifier.length != flatbuffers.FILE_IDENTIFIER_LENGTH) {
|
||||||
@@ -751,6 +780,17 @@ flatbuffers.Builder.prototype.createString = function(s) {
|
|||||||
}
|
}
|
||||||
return this.endVector();
|
return this.endVector();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A helper function to avoid generated code depending on this file directly.
|
||||||
|
*
|
||||||
|
* @param {number} low
|
||||||
|
* @param {number} high
|
||||||
|
* @returns {flatbuffers.Long}
|
||||||
|
*/
|
||||||
|
flatbuffers.Builder.prototype.createLong = function(low, high) {
|
||||||
|
return flatbuffers.Long.create(low, high);
|
||||||
|
};
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
/// @cond FLATBUFFERS_INTERNAL
|
/// @cond FLATBUFFERS_INTERNAL
|
||||||
/**
|
/**
|
||||||
@@ -994,10 +1034,10 @@ flatbuffers.ByteBuffer.prototype.__union = function(t, offset) {
|
|||||||
* FlatBuffer later on.
|
* FlatBuffer later on.
|
||||||
*
|
*
|
||||||
* @param {number} offset
|
* @param {number} offset
|
||||||
* @param {flatbuffers.Encoding=} optionalEncoding Defaults to UTF16_STRING
|
* @param {flatbuffers.Encoding=} opt_encoding Defaults to UTF16_STRING
|
||||||
* @returns {string|Uint8Array}
|
* @returns {string|Uint8Array}
|
||||||
*/
|
*/
|
||||||
flatbuffers.ByteBuffer.prototype.__string = function(offset, optionalEncoding) {
|
flatbuffers.ByteBuffer.prototype.__string = function(offset, opt_encoding) {
|
||||||
offset += this.readInt32(offset);
|
offset += this.readInt32(offset);
|
||||||
|
|
||||||
var length = this.readInt32(offset);
|
var length = this.readInt32(offset);
|
||||||
@@ -1006,7 +1046,7 @@ flatbuffers.ByteBuffer.prototype.__string = function(offset, optionalEncoding) {
|
|||||||
|
|
||||||
offset += flatbuffers.SIZEOF_INT;
|
offset += flatbuffers.SIZEOF_INT;
|
||||||
|
|
||||||
if (optionalEncoding === flatbuffers.Encoding.UTF8_BYTES) {
|
if (opt_encoding === flatbuffers.Encoding.UTF8_BYTES) {
|
||||||
return this.bytes_.subarray(offset, offset + length);
|
return this.bytes_.subarray(offset, offset + length);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1101,6 +1141,17 @@ flatbuffers.ByteBuffer.prototype.__has_identifier = function(ident) {
|
|||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A helper function to avoid generated code depending on this file directly.
|
||||||
|
*
|
||||||
|
* @param {number} low
|
||||||
|
* @param {number} high
|
||||||
|
* @returns {flatbuffers.Long}
|
||||||
|
*/
|
||||||
|
flatbuffers.ByteBuffer.prototype.createLong = function(low, high) {
|
||||||
|
return flatbuffers.Long.create(low, high);
|
||||||
|
};
|
||||||
|
|
||||||
// Exports for Node.js and RequireJS
|
// Exports for Node.js and RequireJS
|
||||||
this.flatbuffers = flatbuffers;
|
this.flatbuffers = flatbuffers;
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2014 Google Inc. All rights reserved.
|
* Copyright 2014 Google Inc. All rights reserved.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
@@ -14,7 +14,20 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
//#define UNSAFE_BYTEBUFFER // uncomment this line to use faster ByteBuffer
|
// There are 2 #defines that have an impact on performance of this ByteBuffer implementation
|
||||||
|
//
|
||||||
|
// UNSAFE_BYTEBUFFER
|
||||||
|
// This will use unsafe code to manipulate the underlying byte array. This
|
||||||
|
// can yield a reasonable performance increase.
|
||||||
|
//
|
||||||
|
// BYTEBUFFER_NO_BOUNDS_CHECK
|
||||||
|
// This will disable the bounds check asserts to the byte array. This can
|
||||||
|
// yield a small performance gain in normal code..
|
||||||
|
//
|
||||||
|
// Using UNSAFE_BYTEBUFFER and BYTEBUFFER_NO_BOUNDS_CHECK together can yield a
|
||||||
|
// performance gain of ~15% for some operations, however doing so is potentially
|
||||||
|
// dangerous. Do so at your own risk!
|
||||||
|
//
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
|
|
||||||
@@ -22,9 +35,6 @@ namespace FlatBuffers
|
|||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Class to mimic Java's ByteBuffer which is used heavily in Flatbuffers.
|
/// Class to mimic Java's ByteBuffer which is used heavily in Flatbuffers.
|
||||||
/// If your execution environment allows unsafe code, you should enable
|
|
||||||
/// unsafe code in your project and #define UNSAFE_BYTEBUFFER to use a
|
|
||||||
/// MUCH faster version of ByteBuffer.
|
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class ByteBuffer
|
public class ByteBuffer
|
||||||
{
|
{
|
||||||
@@ -126,12 +136,14 @@ namespace FlatBuffers
|
|||||||
}
|
}
|
||||||
#endif // !UNSAFE_BYTEBUFFER
|
#endif // !UNSAFE_BYTEBUFFER
|
||||||
|
|
||||||
|
|
||||||
private void AssertOffsetAndLength(int offset, int length)
|
private void AssertOffsetAndLength(int offset, int length)
|
||||||
{
|
{
|
||||||
|
#if !BYTEBUFFER_NO_BOUNDS_CHECK
|
||||||
if (offset < 0 ||
|
if (offset < 0 ||
|
||||||
offset >= _buffer.Length ||
|
offset > _buffer.Length - length)
|
||||||
offset + length > _buffer.Length)
|
|
||||||
throw new ArgumentOutOfRangeException();
|
throw new ArgumentOutOfRangeException();
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
public void PutSbyte(int offset, sbyte value)
|
public void PutSbyte(int offset, sbyte value)
|
||||||
@@ -201,7 +213,6 @@ namespace FlatBuffers
|
|||||||
public unsafe void PutUlong(int offset, ulong value)
|
public unsafe void PutUlong(int offset, ulong value)
|
||||||
{
|
{
|
||||||
AssertOffsetAndLength(offset, sizeof(ulong));
|
AssertOffsetAndLength(offset, sizeof(ulong));
|
||||||
|
|
||||||
fixed (byte* ptr = _buffer)
|
fixed (byte* ptr = _buffer)
|
||||||
{
|
{
|
||||||
*(ulong*)(ptr + offset) = BitConverter.IsLittleEndian
|
*(ulong*)(ptr + offset) = BitConverter.IsLittleEndian
|
||||||
|
|||||||
@@ -80,9 +80,9 @@ namespace FlatBuffers
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets and sets a Boolean to disable the optimization when serializing
|
/// Gets and sets a Boolean to disable the optimization when serializing
|
||||||
/// default values to a Table.
|
/// default values to a Table.
|
||||||
///
|
///
|
||||||
/// In order to save space, fields that are set to their default value
|
/// In order to save space, fields that are set to their default value
|
||||||
/// don't get serialized into the buffer.
|
/// don't get serialized into the buffer.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public bool ForceDefaults { get; set; }
|
public bool ForceDefaults { get; set; }
|
||||||
|
|
||||||
@@ -296,6 +296,18 @@ namespace FlatBuffers
|
|||||||
return new VectorOffset(Offset);
|
return new VectorOffset(Offset);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Creates a vector of tables.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="offsets">Offsets of the tables.</param>
|
||||||
|
public VectorOffset CreateVectorOfTables<T>(Offset<T>[] offsets) where T : struct
|
||||||
|
{
|
||||||
|
NotNested();
|
||||||
|
StartVector(sizeof(int), offsets.Length, sizeof(int));
|
||||||
|
for (int i = offsets.Length - 1; i >= 0; i--) AddOffset(offsets[i].Value);
|
||||||
|
return EndVector();
|
||||||
|
}
|
||||||
|
|
||||||
/// @cond FLATBUFFERS_INTENRAL
|
/// @cond FLATBUFFERS_INTENRAL
|
||||||
public void Nested(int obj)
|
public void Nested(int obj)
|
||||||
{
|
{
|
||||||
@@ -349,7 +361,7 @@ namespace FlatBuffers
|
|||||||
/// and <see cref="ForceDefaults"/> is false, the value will be skipped.</param>
|
/// and <see cref="ForceDefaults"/> is false, the value will be skipped.</param>
|
||||||
/// <param name="d">The default value to compare the value against</param>
|
/// <param name="d">The default value to compare the value against</param>
|
||||||
public void AddBool(int o, bool x, bool d) { if (ForceDefaults || x != d) { AddBool(x); Slot(o); } }
|
public void AddBool(int o, bool x, bool d) { if (ForceDefaults || x != d) { AddBool(x); Slot(o); } }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Adds a SByte to the Table at index `o` in its vtable using the value `x` and default `d`
|
/// Adds a SByte to the Table at index `o` in its vtable using the value `x` and default `d`
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -358,7 +370,7 @@ namespace FlatBuffers
|
|||||||
/// and <see cref="ForceDefaults"/> is false, the value will be skipped.</param>
|
/// and <see cref="ForceDefaults"/> is false, the value will be skipped.</param>
|
||||||
/// <param name="d">The default value to compare the value against</param>
|
/// <param name="d">The default value to compare the value against</param>
|
||||||
public void AddSbyte(int o, sbyte x, sbyte d) { if (ForceDefaults || x != d) { AddSbyte(x); Slot(o); } }
|
public void AddSbyte(int o, sbyte x, sbyte d) { if (ForceDefaults || x != d) { AddSbyte(x); Slot(o); } }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Adds a Byte to the Table at index `o` in its vtable using the value `x` and default `d`
|
/// Adds a Byte to the Table at index `o` in its vtable using the value `x` and default `d`
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -582,6 +594,8 @@ namespace FlatBuffers
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <remarks>
|
/// <remarks>
|
||||||
/// This is typically only called after you call `Finish()`.
|
/// This is typically only called after you call `Finish()`.
|
||||||
|
/// The actual data starts at the ByteBuffer's current position,
|
||||||
|
/// not necessarily at `0`.
|
||||||
/// </remarks>
|
/// </remarks>
|
||||||
/// <returns>
|
/// <returns>
|
||||||
/// Returns the ByteBuffer for this FlatBuffer.
|
/// Returns the ByteBuffer for this FlatBuffer.
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2014 Google Inc. All rights reserved.
|
* Copyright 2014 Google Inc. All rights reserved.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
|||||||
@@ -37,6 +37,7 @@
|
|||||||
<Compile Include="ByteBuffer.cs" />
|
<Compile Include="ByteBuffer.cs" />
|
||||||
<Compile Include="FlatBufferBuilder.cs" />
|
<Compile Include="FlatBufferBuilder.cs" />
|
||||||
<Compile Include="FlatBufferConstants.cs" />
|
<Compile Include="FlatBufferConstants.cs" />
|
||||||
|
<Compile Include="IFlatbufferObject.cs" />
|
||||||
<Compile Include="Offset.cs" />
|
<Compile Include="Offset.cs" />
|
||||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
<Compile Include="Struct.cs" />
|
<Compile Include="Struct.cs" />
|
||||||
|
|||||||
28
net/FlatBuffers/IFlatbufferObject.cs
Normal file
28
net/FlatBuffers/IFlatbufferObject.cs
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2014 Google Inc. All rights reserved.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace FlatBuffers
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// This is the base for both structs and tables.
|
||||||
|
/// </summary>
|
||||||
|
public interface IFlatbufferObject
|
||||||
|
{
|
||||||
|
void __init(int _i, ByteBuffer _bb);
|
||||||
|
|
||||||
|
ByteBuffer ByteBuffer { get; }
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -19,7 +19,7 @@ namespace FlatBuffers
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Offset class for typesafe assignments.
|
/// Offset class for typesafe assignments.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public struct Offset<T> where T : class
|
public struct Offset<T> where T : struct
|
||||||
{
|
{
|
||||||
public int Value;
|
public int Value;
|
||||||
public Offset(int value)
|
public Offset(int value)
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2014 Google Inc. All rights reserved.
|
* Copyright 2014 Google Inc. All rights reserved.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
@@ -26,7 +26,7 @@ using System.Runtime.InteropServices;
|
|||||||
[assembly: AssemblyConfiguration("")]
|
[assembly: AssemblyConfiguration("")]
|
||||||
[assembly: AssemblyCompany("")]
|
[assembly: AssemblyCompany("")]
|
||||||
[assembly: AssemblyProduct("FlatBuffers")]
|
[assembly: AssemblyProduct("FlatBuffers")]
|
||||||
[assembly: AssemblyCopyright("Copyright © 2015 Google Inc")]
|
[assembly: AssemblyCopyright("Copyright (c) 2015 Google Inc")]
|
||||||
[assembly: AssemblyTrademark("")]
|
[assembly: AssemblyTrademark("")]
|
||||||
[assembly: AssemblyCulture("")]
|
[assembly: AssemblyCulture("")]
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2014 Google Inc. All rights reserved.
|
* Copyright 2014 Google Inc. All rights reserved.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
@@ -19,9 +19,9 @@ namespace FlatBuffers
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// All structs in the generated code derive from this class, and add their own accessors.
|
/// All structs in the generated code derive from this class, and add their own accessors.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public abstract class Struct
|
public struct Struct
|
||||||
{
|
{
|
||||||
protected int bb_pos;
|
public int bb_pos;
|
||||||
protected ByteBuffer bb;
|
public ByteBuffer bb;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,31 +20,42 @@ using System.Text;
|
|||||||
namespace FlatBuffers
|
namespace FlatBuffers
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// All tables in the generated code derive from this class, and add their own accessors.
|
/// All tables in the generated code derive from this struct, and add their own accessors.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public abstract class Table
|
public struct Table
|
||||||
{
|
{
|
||||||
protected int bb_pos;
|
public int bb_pos;
|
||||||
protected ByteBuffer bb;
|
public ByteBuffer bb;
|
||||||
|
|
||||||
public ByteBuffer ByteBuffer { get { return bb; } }
|
public ByteBuffer ByteBuffer { get { return bb; } }
|
||||||
|
|
||||||
// Look up a field in the vtable, return an offset into the object, or 0 if the field is not
|
// Look up a field in the vtable, return an offset into the object, or 0 if the field is not
|
||||||
// present.
|
// present.
|
||||||
protected int __offset(int vtableOffset)
|
public int __offset(int vtableOffset)
|
||||||
{
|
{
|
||||||
int vtable = bb_pos - bb.GetInt(bb_pos);
|
int vtable = bb_pos - bb.GetInt(bb_pos);
|
||||||
return vtableOffset < bb.GetShort(vtable) ? (int)bb.GetShort(vtable + vtableOffset) : 0;
|
return vtableOffset < bb.GetShort(vtable) ? (int)bb.GetShort(vtable + vtableOffset) : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static int __offset(int vtableOffset, int offset, ByteBuffer bb)
|
||||||
|
{
|
||||||
|
int vtable = bb.Length - offset;
|
||||||
|
return (int)bb.GetShort(vtable + vtableOffset - bb.GetInt(vtable)) + vtable;
|
||||||
|
}
|
||||||
|
|
||||||
// Retrieve the relative offset stored at "offset"
|
// Retrieve the relative offset stored at "offset"
|
||||||
protected int __indirect(int offset)
|
public int __indirect(int offset)
|
||||||
|
{
|
||||||
|
return offset + bb.GetInt(offset);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static int __indirect(int offset, ByteBuffer bb)
|
||||||
{
|
{
|
||||||
return offset + bb.GetInt(offset);
|
return offset + bb.GetInt(offset);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create a .NET String from UTF-8 data stored inside the flatbuffer.
|
// Create a .NET String from UTF-8 data stored inside the flatbuffer.
|
||||||
protected string __string(int offset)
|
public string __string(int offset)
|
||||||
{
|
{
|
||||||
offset += bb.GetInt(offset);
|
offset += bb.GetInt(offset);
|
||||||
var len = bb.GetInt(offset);
|
var len = bb.GetInt(offset);
|
||||||
@@ -53,7 +64,7 @@ namespace FlatBuffers
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Get the length of a vector whose offset is stored at "offset" in this object.
|
// Get the length of a vector whose offset is stored at "offset" in this object.
|
||||||
protected int __vector_len(int offset)
|
public int __vector_len(int offset)
|
||||||
{
|
{
|
||||||
offset += bb_pos;
|
offset += bb_pos;
|
||||||
offset += bb.GetInt(offset);
|
offset += bb.GetInt(offset);
|
||||||
@@ -61,7 +72,7 @@ namespace FlatBuffers
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Get the start of data of a vector whose offset is stored at "offset" in this object.
|
// Get the start of data of a vector whose offset is stored at "offset" in this object.
|
||||||
protected int __vector(int offset)
|
public int __vector(int offset)
|
||||||
{
|
{
|
||||||
offset += bb_pos;
|
offset += bb_pos;
|
||||||
return offset + bb.GetInt(offset) + sizeof(int); // data starts after the length
|
return offset + bb.GetInt(offset) + sizeof(int); // data starts after the length
|
||||||
@@ -70,7 +81,8 @@ namespace FlatBuffers
|
|||||||
// Get the data of a vector whoses offset is stored at "offset" in this object as an
|
// Get the data of a vector whoses offset is stored at "offset" in this object as an
|
||||||
// ArraySegment<byte>. If the vector is not present in the ByteBuffer,
|
// ArraySegment<byte>. If the vector is not present in the ByteBuffer,
|
||||||
// then a null value will be returned.
|
// then a null value will be returned.
|
||||||
protected ArraySegment<byte>? __vector_as_arraysegment(int offset) {
|
public ArraySegment<byte>? __vector_as_arraysegment(int offset)
|
||||||
|
{
|
||||||
var o = this.__offset(offset);
|
var o = this.__offset(offset);
|
||||||
if (0 == o)
|
if (0 == o)
|
||||||
{
|
{
|
||||||
@@ -83,15 +95,15 @@ namespace FlatBuffers
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Initialize any Table-derived type to point to the union at the given offset.
|
// Initialize any Table-derived type to point to the union at the given offset.
|
||||||
protected TTable __union<TTable>(TTable t, int offset) where TTable : Table
|
public T __union<T>(int offset) where T : struct, IFlatbufferObject
|
||||||
{
|
{
|
||||||
offset += bb_pos;
|
offset += bb_pos;
|
||||||
t.bb_pos = offset + bb.GetInt(offset);
|
T t = new T();
|
||||||
t.bb = bb;
|
t.__init(offset + bb.GetInt(offset), bb);
|
||||||
return t;
|
return t;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static bool __has_identifier(ByteBuffer bb, string ident)
|
public static bool __has_identifier(ByteBuffer bb, string ident)
|
||||||
{
|
{
|
||||||
if (ident.Length != FlatBufferConstants.FileIdentifierLength)
|
if (ident.Length != FlatBufferConstants.FileIdentifierLength)
|
||||||
throw new ArgumentException("FlatBuffers: file identifier must be length " + FlatBufferConstants.FileIdentifierLength, "ident");
|
throw new ArgumentException("FlatBuffers: file identifier must be length " + FlatBufferConstants.FileIdentifierLength, "ident");
|
||||||
@@ -104,6 +116,38 @@ namespace FlatBuffers
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Compare strings in the ByteBuffer.
|
||||||
|
public static int CompareStrings(int offset_1, int offset_2, ByteBuffer bb)
|
||||||
|
{
|
||||||
|
offset_1 += bb.GetInt(offset_1);
|
||||||
|
offset_2 += bb.GetInt(offset_2);
|
||||||
|
var len_1 = bb.GetInt(offset_1);
|
||||||
|
var len_2 = bb.GetInt(offset_2);
|
||||||
|
var startPos_1 = offset_1 + sizeof(int);
|
||||||
|
var startPos_2 = offset_2 + sizeof(int);
|
||||||
|
var len = Math.Min(len_1, len_2);
|
||||||
|
byte[] bbArray = bb.Data;
|
||||||
|
for(int i = 0; i < len; i++) {
|
||||||
|
if (bbArray[i + startPos_1] != bbArray[i + startPos_2])
|
||||||
|
return bbArray[i + startPos_1] - bbArray[i + startPos_2];
|
||||||
|
}
|
||||||
|
return len_1 - len_2;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Compare string from the ByteBuffer with the string object
|
||||||
|
public static int CompareStrings(int offset_1, byte[] key, ByteBuffer bb)
|
||||||
|
{
|
||||||
|
offset_1 += bb.GetInt(offset_1);
|
||||||
|
var len_1 = bb.GetInt(offset_1);
|
||||||
|
var len_2 = key.Length;
|
||||||
|
var startPos_1 = offset_1 + sizeof(int);
|
||||||
|
var len = Math.Min(len_1, len_2);
|
||||||
|
byte[] bbArray = bb.Data;
|
||||||
|
for (int i = 0; i < len; i++) {
|
||||||
|
if (bbArray[i + startPos_1] != key[i])
|
||||||
|
return bbArray[i + startPos_1] - key[i];
|
||||||
|
}
|
||||||
|
return len_1 - len_2;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
27
package.json
Normal file
27
package.json
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
{
|
||||||
|
"name": "flatbuffers",
|
||||||
|
"version": "1.6.0",
|
||||||
|
"description": "Memory Efficient Serialization Library",
|
||||||
|
"files": ["js/flatbuffers.js"],
|
||||||
|
"main": "js/flatbuffers.js",
|
||||||
|
"directories": {
|
||||||
|
"doc": "docs",
|
||||||
|
"test": "tests"
|
||||||
|
},
|
||||||
|
"scripts": {
|
||||||
|
"test": "tests/JavaScriptTest.sh"
|
||||||
|
},
|
||||||
|
"repository": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "git+https://github.com/google/flatbuffers.git"
|
||||||
|
},
|
||||||
|
"keywords": [
|
||||||
|
"flatbuffers"
|
||||||
|
],
|
||||||
|
"author": "The FlatBuffers project",
|
||||||
|
"license": "SEE LICENSE IN LICENSE.txt",
|
||||||
|
"bugs": {
|
||||||
|
"url": "https://github.com/google/flatbuffers/issues"
|
||||||
|
},
|
||||||
|
"homepage": "https://google.github.io/flatbuffers/"
|
||||||
|
}
|
||||||
@@ -233,7 +233,7 @@ class FlatbufferBuilder
|
|||||||
public function putUint($x)
|
public function putUint($x)
|
||||||
{
|
{
|
||||||
if ($x > PHP_INT_MAX) {
|
if ($x > PHP_INT_MAX) {
|
||||||
throw new \InvalidArgumentException("your platform can't handling uint correctly. use 64bit machine.");
|
throw new \InvalidArgumentException("your platform can't handle uint correctly. use 64bit machine.");
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->bb->putUint($this->space -= 4, $x);
|
$this->bb->putUint($this->space -= 4, $x);
|
||||||
@@ -245,7 +245,7 @@ class FlatbufferBuilder
|
|||||||
public function putLong($x)
|
public function putLong($x)
|
||||||
{
|
{
|
||||||
if ($x > PHP_INT_MAX) {
|
if ($x > PHP_INT_MAX) {
|
||||||
throw new \InvalidArgumentException("your platform can't handling long correctly. use 64bit machine.");
|
throw new \InvalidArgumentException("Your platform can't handle long correctly. Use a 64bit machine.");
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->bb->putLong($this->space -= 8, $x);
|
$this->bb->putLong($this->space -= 8, $x);
|
||||||
@@ -257,7 +257,7 @@ class FlatbufferBuilder
|
|||||||
public function putUlong($x)
|
public function putUlong($x)
|
||||||
{
|
{
|
||||||
if ($x > PHP_INT_MAX) {
|
if ($x > PHP_INT_MAX) {
|
||||||
throw new \InvalidArgumentException("your platform can't handling ulong correctly. this is php limitations. please wait extension release.");
|
throw new \InvalidArgumentException("Your platform can't handle ulong correctly. This is a php limitation. Please wait for the extension release.");
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->bb->putUlong($this->space -= 8, $x);
|
$this->bb->putUlong($this->space -= 8, $x);
|
||||||
@@ -593,6 +593,10 @@ class FlatbufferBuilder
|
|||||||
|
|
||||||
protected function is_utf8($bytes)
|
protected function is_utf8($bytes)
|
||||||
{
|
{
|
||||||
|
if (function_exists('mb_detect_encoding')) {
|
||||||
|
return (bool) mb_detect_encoding($bytes, 'UTF-8', true);
|
||||||
|
}
|
||||||
|
|
||||||
$len = strlen($bytes);
|
$len = strlen($bytes);
|
||||||
if ($len < 1) {
|
if ($len < 1) {
|
||||||
/* NOTE: always return 1 when passed string is null */
|
/* NOTE: always return 1 when passed string is null */
|
||||||
|
|||||||
@@ -89,9 +89,15 @@ abstract class Table
|
|||||||
return $offset + $this->bb->getInt($offset) + Constants::SIZEOF_INT;
|
return $offset + $this->bb->getInt($offset) + Constants::SIZEOF_INT;
|
||||||
}
|
}
|
||||||
|
|
||||||
// protected function __vector_as_bytebuffer($vector_offset, $elem_size)
|
protected function __vector_as_bytes($vector_offset, $elem_size=1)
|
||||||
// {
|
{
|
||||||
// }
|
$o = $this->__offset($vector_offset);
|
||||||
|
if ($o == 0) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return substr($this->bb->_buffer, $this->__vector($o), $this->__vector_len($o) * $elem_size);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param Table $table
|
* @param Table $table
|
||||||
|
|||||||
@@ -5,8 +5,8 @@
|
|||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<groupId>com.google.flatbuffers</groupId>
|
<groupId>com.google.flatbuffers</groupId>
|
||||||
<artifactId>flatbuffers-java</artifactId>
|
<artifactId>flatbuffers-java</artifactId>
|
||||||
<version>1.2.0-SNAPSHOT</version>
|
<version>1.6.0-SNAPSHOT</version>
|
||||||
<packaging>jar</packaging>
|
<packaging>bundle</packaging>
|
||||||
<name>FlatBuffers Java API</name>
|
<name>FlatBuffers Java API</name>
|
||||||
<description>
|
<description>
|
||||||
Memory Efficient Serialization Library
|
Memory Efficient Serialization Library
|
||||||
@@ -33,7 +33,7 @@
|
|||||||
<dependencies>
|
<dependencies>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
<build>
|
<build>
|
||||||
<sourceDirectory>./</sourceDirectory>
|
<sourceDirectory>java</sourceDirectory>
|
||||||
<plugins>
|
<plugins>
|
||||||
<plugin>
|
<plugin>
|
||||||
<artifactId>maven-compiler-plugin</artifactId>
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
@@ -78,6 +78,12 @@
|
|||||||
</execution>
|
</execution>
|
||||||
</executions>
|
</executions>
|
||||||
</plugin>
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.felix</groupId>
|
||||||
|
<artifactId>maven-bundle-plugin</artifactId>
|
||||||
|
<version>3.0.1</version>
|
||||||
|
<extensions>true</extensions>
|
||||||
|
</plugin>
|
||||||
</plugins>
|
</plugins>
|
||||||
</build>
|
</build>
|
||||||
</project>
|
</project>
|
||||||
@@ -401,7 +401,7 @@ class Builder(object):
|
|||||||
|
|
||||||
if isinstance(s, compat.string_types):
|
if isinstance(s, compat.string_types):
|
||||||
x = s.encode(encoding, errors)
|
x = s.encode(encoding, errors)
|
||||||
elif isinstance(s, compat.binary_type):
|
elif isinstance(s, compat.binary_types):
|
||||||
x = s
|
x = s
|
||||||
else:
|
else:
|
||||||
raise TypeError("non-string passed to CreateString")
|
raise TypeError("non-string passed to CreateString")
|
||||||
|
|||||||
@@ -1,3 +1,17 @@
|
|||||||
|
# Copyright 2016 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.
|
||||||
|
|
||||||
""" A tiny version of `six` to help with backwards compability. """
|
""" A tiny version of `six` to help with backwards compability. """
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
@@ -11,13 +25,16 @@ PY34 = sys.version_info[0:2] >= (3, 4)
|
|||||||
|
|
||||||
if PY3:
|
if PY3:
|
||||||
string_types = (str,)
|
string_types = (str,)
|
||||||
binary_type = bytes
|
binary_types = (bytes,bytearray)
|
||||||
range_func = range
|
range_func = range
|
||||||
memoryview_type = memoryview
|
memoryview_type = memoryview
|
||||||
struct_bool_decl = "?"
|
struct_bool_decl = "?"
|
||||||
else:
|
else:
|
||||||
string_types = (basestring,)
|
string_types = (unicode,)
|
||||||
binary_type = str
|
if PY26 or PY27:
|
||||||
|
binary_types = (str,bytearray)
|
||||||
|
else:
|
||||||
|
binary_types = (str,)
|
||||||
range_func = xrange
|
range_func = xrange
|
||||||
if PY26 or (PY27 and not PY275):
|
if PY26 or (PY27 and not PY275):
|
||||||
memoryview_type = buffer
|
memoryview_type = buffer
|
||||||
|
|||||||
@@ -12,8 +12,6 @@
|
|||||||
# See the License for the specific language governing permissions and
|
# See the License for the specific language governing permissions and
|
||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
|
||||||
import ctypes
|
|
||||||
|
|
||||||
from . import number_types as N
|
from . import number_types as N
|
||||||
from . import packer
|
from . import packer
|
||||||
from .compat import memoryview_type
|
from .compat import memoryview_type
|
||||||
|
|||||||
@@ -12,10 +12,8 @@
|
|||||||
# See the License for the specific language governing permissions and
|
# See the License for the specific language governing permissions and
|
||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
|
||||||
import ctypes
|
|
||||||
import collections
|
import collections
|
||||||
import struct
|
import struct
|
||||||
from ctypes import sizeof
|
|
||||||
|
|
||||||
from . import packer
|
from . import packer
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,17 @@
|
|||||||
|
# Copyright 2016 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.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
Provide pre-compiled struct packers for encoding and decoding.
|
Provide pre-compiled struct packers for encoding and decoding.
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,17 @@
|
|||||||
|
# Copyright 2016 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.
|
||||||
|
|
||||||
from setuptools import setup
|
from setuptools import setup
|
||||||
|
|
||||||
setup(
|
setup(
|
||||||
|
|||||||
21
readme.md
21
readme.md
@@ -1,8 +1,12 @@
|
|||||||
 FlatBuffers [](https://travis-ci.org/google/flatbuffers)
|
 FlatBuffers
|
||||||
===========
|
===========
|
||||||
**FlatBuffers** is an efficient cross platform serialization library for games and
|
|
||||||
other memory constrained apps. It allows you to directly access serialized data without
|
[](https://gitter.im/google/flatbuffers?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
|
||||||
unpacking/parsing it first, while still having great forwards/backwards compatibility.
|
[](https://travis-ci.org/google/flatbuffers) [](https://ci.appveyor.com/project/gwvo/flatbuffers)
|
||||||
|
|
||||||
|
**FlatBuffers** is an efficient cross platform serialization library for games and
|
||||||
|
other memory constrained apps. It allows you to directly access serialized data without
|
||||||
|
unpacking/parsing it first, while still having great forwards/backwards compatibility.
|
||||||
|
|
||||||
**Go to our [landing page][] to browse our documentation.**
|
**Go to our [landing page][] to browse our documentation.**
|
||||||
|
|
||||||
@@ -11,10 +15,11 @@ unpacking/parsing it first, while still having great forwards/backwards compatib
|
|||||||
* Windows
|
* Windows
|
||||||
* MacOS X
|
* MacOS X
|
||||||
* Linux
|
* Linux
|
||||||
|
|
||||||
## Supported programming languages
|
## Supported programming languages
|
||||||
* C++
|
* C++
|
||||||
* C#
|
* C#
|
||||||
|
* C
|
||||||
* Go
|
* Go
|
||||||
* Java
|
* Java
|
||||||
* JavaScript
|
* JavaScript
|
||||||
@@ -23,7 +28,7 @@ unpacking/parsing it first, while still having great forwards/backwards compatib
|
|||||||
|
|
||||||
*and many more in progress...*
|
*and many more in progress...*
|
||||||
|
|
||||||
## Contribution
|
## Contribution
|
||||||
* [FlatBuffers Google Group][] to discuss FlatBuffers with other developers and users.
|
* [FlatBuffers Google Group][] to discuss FlatBuffers with other developers and users.
|
||||||
* [FlatBuffers Issues Tracker][] to submit an issue.
|
* [FlatBuffers Issues Tracker][] to submit an issue.
|
||||||
* [stackoverflow.com][] with [`flatbuffers` tag][] for any questions regarding FlatBuffers.
|
* [stackoverflow.com][] with [`flatbuffers` tag][] for any questions regarding FlatBuffers.
|
||||||
@@ -45,9 +50,9 @@ you would leave it in.
|
|||||||
|
|
||||||
<br>
|
<br>
|
||||||
|
|
||||||
[CONTRIBUTING]: http://github.com/google/flatbuffers/blob/master/CONTRIBUTING
|
[CONTRIBUTING]: http://github.com/google/flatbuffers/blob/master/CONTRIBUTING.md
|
||||||
[`flatbuffers` tag]: https://stackoverflow.com/questions/tagged/flatbuffers
|
[`flatbuffers` tag]: https://stackoverflow.com/questions/tagged/flatbuffers
|
||||||
[FlatBuffers Google Group]: http://group.google.com/group/flatbuffers
|
[FlatBuffers Google Group]: https://groups.google.com/forum/#!forum/flatbuffers
|
||||||
[FlatBuffers Issues Tracker]: http://github.com/google/flatbuffers/issues
|
[FlatBuffers Issues Tracker]: http://github.com/google/flatbuffers/issues
|
||||||
[stackoverflow.com]: http://www.stackoverflow.com
|
[stackoverflow.com]: http://www.stackoverflow.com
|
||||||
[landing page]: http://google.github.io/flatbuffers
|
[landing page]: http://google.github.io/flatbuffers
|
||||||
|
|||||||
@@ -1 +1,17 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
#
|
||||||
|
# Copyright 2016 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.
|
||||||
|
|
||||||
../flatc -c --no-prefix -o ../include/flatbuffers reflection.fbs
|
../flatc -c --no-prefix -o ../include/flatbuffers reflection.fbs
|
||||||
|
|||||||
@@ -34,6 +34,11 @@ table Type {
|
|||||||
// from an enum, index into "enums" below.
|
// from an enum, index into "enums" below.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
table KeyValue {
|
||||||
|
key:string (required, key);
|
||||||
|
value:string;
|
||||||
|
}
|
||||||
|
|
||||||
table EnumVal {
|
table EnumVal {
|
||||||
name:string (required);
|
name:string (required);
|
||||||
value:long (key);
|
value:long (key);
|
||||||
@@ -45,6 +50,8 @@ table Enum {
|
|||||||
values:[EnumVal] (required); // In order of their values.
|
values:[EnumVal] (required); // In order of their values.
|
||||||
is_union:bool = false;
|
is_union:bool = false;
|
||||||
underlying_type:Type (required);
|
underlying_type:Type (required);
|
||||||
|
attributes:[KeyValue];
|
||||||
|
documentation:[string];
|
||||||
}
|
}
|
||||||
|
|
||||||
table Field {
|
table Field {
|
||||||
@@ -57,6 +64,8 @@ table Field {
|
|||||||
deprecated:bool = false;
|
deprecated:bool = false;
|
||||||
required:bool = false;
|
required:bool = false;
|
||||||
key:bool = false;
|
key:bool = false;
|
||||||
|
attributes:[KeyValue];
|
||||||
|
documentation:[string];
|
||||||
}
|
}
|
||||||
|
|
||||||
table Object { // Used for both tables and structs.
|
table Object { // Used for both tables and structs.
|
||||||
@@ -65,6 +74,8 @@ table Object { // Used for both tables and structs.
|
|||||||
is_struct:bool = false;
|
is_struct:bool = false;
|
||||||
minalign:int;
|
minalign:int;
|
||||||
bytesize:int; // For structs.
|
bytesize:int; // For structs.
|
||||||
|
attributes:[KeyValue];
|
||||||
|
documentation:[string];
|
||||||
}
|
}
|
||||||
|
|
||||||
table Schema {
|
table Schema {
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
#!/bin/bash -eu
|
#!/bin/bash -eu
|
||||||
|
#
|
||||||
# Copyright (c) 2013 Google, Inc.
|
# Copyright (c) 2013 Google, Inc.
|
||||||
#
|
#
|
||||||
# This software is provided 'as-is', without any express or implied
|
# This software is provided 'as-is', without any express or implied
|
||||||
|
|||||||
@@ -18,5 +18,5 @@ APP_PROJECT_PATH := $(call my-dir)/..
|
|||||||
APP_STL := gnustl_static
|
APP_STL := gnustl_static
|
||||||
|
|
||||||
APP_ABI := armeabi-v7a
|
APP_ABI := armeabi-v7a
|
||||||
NDK_TOOLCHAIN_VERSION := 4.8
|
|
||||||
APP_CPPFLAGS += -std=c++11
|
APP_CPPFLAGS += -std=c++11
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
#
|
||||||
# Copyright 2015 Google Inc. All rights reserved.
|
# Copyright 2015 Google Inc. All rights reserved.
|
||||||
#
|
#
|
||||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
@@ -12,7 +13,7 @@
|
|||||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
# See the License for the specific language governing permissions and
|
# See the License for the specific language governing permissions and
|
||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
#
|
||||||
# Note: This script requires the Android NDK and Android SDK to be installed.
|
# Note: This script requires the Android NDK and Android SDK to be installed.
|
||||||
# It also requires an Android device to be connected for installing and
|
# It also requires an Android device to be connected for installing and
|
||||||
# running the applicaton.
|
# running the applicaton.
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
#
|
||||||
# Copyright 2015 Google Inc. All rights reserved.
|
# Copyright 2015 Google Inc. All rights reserved.
|
||||||
#
|
#
|
||||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
@@ -12,7 +13,7 @@
|
|||||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
# See the License for the specific language governing permissions and
|
# See the License for the specific language governing permissions and
|
||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
#
|
||||||
# Note: This script runs on Mac and Linux. It requires `mono` to be installed
|
# Note: This script runs on Mac and Linux. It requires `mono` to be installed
|
||||||
# and `flatc` to be built (using `cmake` in the root directory).
|
# and `flatc` to be built (using `cmake` in the root directory).
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
#
|
||||||
# Copyright 2015 Google Inc. All rights reserved.
|
# Copyright 2015 Google Inc. All rights reserved.
|
||||||
#
|
#
|
||||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
@@ -12,7 +13,7 @@
|
|||||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
# See the License for the specific language governing permissions and
|
# See the License for the specific language governing permissions and
|
||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
#
|
||||||
# Note: This script runs on Mac and Linux. It requires `go` to be installed
|
# Note: This script runs on Mac and Linux. It requires `go` to be installed
|
||||||
# and 'flatc' to be built (using `cmake` in the root directory).
|
# and 'flatc' to be built (using `cmake` in the root directory).
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
#
|
||||||
# Copyright 2015 Google Inc. All rights reserved.
|
# Copyright 2015 Google Inc. All rights reserved.
|
||||||
#
|
#
|
||||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
@@ -12,7 +13,7 @@
|
|||||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
# See the License for the specific language governing permissions and
|
# See the License for the specific language governing permissions and
|
||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
#
|
||||||
# Note: This script runs on Mac and Linux. It requires `java` to be installed
|
# Note: This script runs on Mac and Linux. It requires `java` to be installed
|
||||||
# and `flatc` to be built (using `cmake` in the root directory).
|
# and `flatc` to be built (using `cmake` in the root directory).
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
#
|
||||||
# Copyright 2015 Google Inc. All rights reserved.
|
# Copyright 2015 Google Inc. All rights reserved.
|
||||||
#
|
#
|
||||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
@@ -12,7 +13,7 @@
|
|||||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
# See the License for the specific language governing permissions and
|
# See the License for the specific language governing permissions and
|
||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
#
|
||||||
# Note: This script runs on Mac and Linux. It requires `Node.js` to be installed
|
# Note: This script runs on Mac and Linux. It requires `Node.js` to be installed
|
||||||
# and `flatc` to be built (using `cmake` in the root directory).
|
# and `flatc` to be built (using `cmake` in the root directory).
|
||||||
|
|
||||||
|
|||||||
@@ -1,17 +1,21 @@
|
|||||||
// automatically generated by the FlatBuffers compiler, do not modify
|
// automatically generated by the FlatBuffers compiler, do not modify
|
||||||
|
|
||||||
|
|
||||||
#ifndef FLATBUFFERS_GENERATED_MONSTER_MYGAME_SAMPLE_H_
|
#ifndef FLATBUFFERS_GENERATED_MONSTER_MYGAME_SAMPLE_H_
|
||||||
#define FLATBUFFERS_GENERATED_MONSTER_MYGAME_SAMPLE_H_
|
#define FLATBUFFERS_GENERATED_MONSTER_MYGAME_SAMPLE_H_
|
||||||
|
|
||||||
#include "flatbuffers/flatbuffers.h"
|
#include "flatbuffers/flatbuffers.h"
|
||||||
|
|
||||||
|
|
||||||
namespace MyGame {
|
namespace MyGame {
|
||||||
namespace Sample {
|
namespace Sample {
|
||||||
|
|
||||||
struct Vec3;
|
struct Vec3;
|
||||||
|
|
||||||
struct Monster;
|
struct Monster;
|
||||||
|
struct MonsterT;
|
||||||
|
|
||||||
struct Weapon;
|
struct Weapon;
|
||||||
|
struct WeaponT;
|
||||||
|
|
||||||
enum Color {
|
enum Color {
|
||||||
Color_Red = 0,
|
Color_Red = 0,
|
||||||
@@ -22,11 +26,19 @@ enum Color {
|
|||||||
};
|
};
|
||||||
|
|
||||||
inline const char **EnumNamesColor() {
|
inline const char **EnumNamesColor() {
|
||||||
static const char *names[] = { "Red", "Green", "Blue", nullptr };
|
static const char *names[] = {
|
||||||
|
"Red",
|
||||||
|
"Green",
|
||||||
|
"Blue",
|
||||||
|
nullptr
|
||||||
|
};
|
||||||
return names;
|
return names;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline const char *EnumNameColor(Color e) { return EnumNamesColor()[static_cast<int>(e)]; }
|
inline const char *EnumNameColor(Color e) {
|
||||||
|
const size_t index = static_cast<int>(e);
|
||||||
|
return EnumNamesColor()[index];
|
||||||
|
}
|
||||||
|
|
||||||
enum Equipment {
|
enum Equipment {
|
||||||
Equipment_NONE = 0,
|
Equipment_NONE = 0,
|
||||||
@@ -36,13 +48,60 @@ enum Equipment {
|
|||||||
};
|
};
|
||||||
|
|
||||||
inline const char **EnumNamesEquipment() {
|
inline const char **EnumNamesEquipment() {
|
||||||
static const char *names[] = { "NONE", "Weapon", nullptr };
|
static const char *names[] = {
|
||||||
|
"NONE",
|
||||||
|
"Weapon",
|
||||||
|
nullptr
|
||||||
|
};
|
||||||
return names;
|
return names;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline const char *EnumNameEquipment(Equipment e) { return EnumNamesEquipment()[static_cast<int>(e)]; }
|
inline const char *EnumNameEquipment(Equipment e) {
|
||||||
|
const size_t index = static_cast<int>(e);
|
||||||
|
return EnumNamesEquipment()[index];
|
||||||
|
}
|
||||||
|
|
||||||
inline bool VerifyEquipment(flatbuffers::Verifier &verifier, const void *union_obj, Equipment type);
|
template<typename T> struct EquipmentTraits {
|
||||||
|
static const Equipment enum_value = Equipment_NONE;
|
||||||
|
};
|
||||||
|
|
||||||
|
template<> struct EquipmentTraits<Weapon> {
|
||||||
|
static const Equipment enum_value = Equipment_Weapon;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct EquipmentUnion {
|
||||||
|
Equipment type;
|
||||||
|
flatbuffers::NativeTable *table;
|
||||||
|
|
||||||
|
EquipmentUnion() : type(Equipment_NONE), table(nullptr) {}
|
||||||
|
EquipmentUnion(EquipmentUnion&& u):
|
||||||
|
type(std::move(u.type)), table(std::move(u.table)) {}
|
||||||
|
EquipmentUnion(const EquipmentUnion &);
|
||||||
|
EquipmentUnion &operator=(const EquipmentUnion &);
|
||||||
|
~EquipmentUnion() { Reset(); }
|
||||||
|
|
||||||
|
void Reset();
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
void Set(T&& value) {
|
||||||
|
Reset();
|
||||||
|
type = EquipmentTraits<typename T::TableType>::enum_value;
|
||||||
|
if (type != Equipment_NONE) {
|
||||||
|
table = new T(std::forward<T>(value));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static flatbuffers::NativeTable *UnPack(const void *obj, Equipment type, const flatbuffers::resolver_function_t *resolver);
|
||||||
|
flatbuffers::Offset<void> Pack(flatbuffers::FlatBufferBuilder &_fbb, const flatbuffers::rehasher_function_t *_rehasher = nullptr) const;
|
||||||
|
|
||||||
|
WeaponT *AsWeapon() {
|
||||||
|
return type == Equipment_Weapon ?
|
||||||
|
reinterpret_cast<WeaponT *>(table) : nullptr;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
bool VerifyEquipment(flatbuffers::Verifier &verifier, const void *obj, Equipment type);
|
||||||
|
bool VerifyEquipmentVector(flatbuffers::Verifier &verifier, const flatbuffers::Vector<flatbuffers::Offset<void>> *values, const flatbuffers::Vector<uint8_t> *types);
|
||||||
|
|
||||||
MANUALLY_ALIGNED_STRUCT(4) Vec3 FLATBUFFERS_FINAL_CLASS {
|
MANUALLY_ALIGNED_STRUCT(4) Vec3 FLATBUFFERS_FINAL_CLASS {
|
||||||
private:
|
private:
|
||||||
@@ -51,16 +110,57 @@ MANUALLY_ALIGNED_STRUCT(4) Vec3 FLATBUFFERS_FINAL_CLASS {
|
|||||||
float z_;
|
float z_;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
Vec3() {
|
||||||
|
memset(this, 0, sizeof(Vec3));
|
||||||
|
}
|
||||||
|
Vec3(const Vec3 &_o) {
|
||||||
|
memcpy(this, &_o, sizeof(Vec3));
|
||||||
|
}
|
||||||
Vec3(float _x, float _y, float _z)
|
Vec3(float _x, float _y, float _z)
|
||||||
: x_(flatbuffers::EndianScalar(_x)), y_(flatbuffers::EndianScalar(_y)), z_(flatbuffers::EndianScalar(_z)) { }
|
: x_(flatbuffers::EndianScalar(_x)),
|
||||||
|
y_(flatbuffers::EndianScalar(_y)),
|
||||||
float x() const { return flatbuffers::EndianScalar(x_); }
|
z_(flatbuffers::EndianScalar(_z)) {
|
||||||
float y() const { return flatbuffers::EndianScalar(y_); }
|
}
|
||||||
float z() const { return flatbuffers::EndianScalar(z_); }
|
float x() const {
|
||||||
|
return flatbuffers::EndianScalar(x_);
|
||||||
|
}
|
||||||
|
void mutate_x(float _x) {
|
||||||
|
flatbuffers::WriteScalar(&x_, _x);
|
||||||
|
}
|
||||||
|
float y() const {
|
||||||
|
return flatbuffers::EndianScalar(y_);
|
||||||
|
}
|
||||||
|
void mutate_y(float _y) {
|
||||||
|
flatbuffers::WriteScalar(&y_, _y);
|
||||||
|
}
|
||||||
|
float z() const {
|
||||||
|
return flatbuffers::EndianScalar(z_);
|
||||||
|
}
|
||||||
|
void mutate_z(float _z) {
|
||||||
|
flatbuffers::WriteScalar(&z_, _z);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
STRUCT_END(Vec3, 12);
|
STRUCT_END(Vec3, 12);
|
||||||
|
|
||||||
|
struct MonsterT : public flatbuffers::NativeTable {
|
||||||
|
typedef Monster TableType;
|
||||||
|
std::unique_ptr<Vec3> pos;
|
||||||
|
int16_t mana;
|
||||||
|
int16_t hp;
|
||||||
|
std::string name;
|
||||||
|
std::vector<uint8_t> inventory;
|
||||||
|
Color color;
|
||||||
|
std::vector<std::unique_ptr<WeaponT>> weapons;
|
||||||
|
EquipmentUnion equipped;
|
||||||
|
MonsterT()
|
||||||
|
: mana(150),
|
||||||
|
hp(100),
|
||||||
|
color(Color_Blue) {
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
struct Monster FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table {
|
struct Monster FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table {
|
||||||
|
typedef MonsterT NativeTableType;
|
||||||
enum {
|
enum {
|
||||||
VT_POS = 4,
|
VT_POS = 4,
|
||||||
VT_MANA = 6,
|
VT_MANA = 6,
|
||||||
@@ -72,15 +172,60 @@ struct Monster FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table {
|
|||||||
VT_EQUIPPED_TYPE = 20,
|
VT_EQUIPPED_TYPE = 20,
|
||||||
VT_EQUIPPED = 22
|
VT_EQUIPPED = 22
|
||||||
};
|
};
|
||||||
const Vec3 *pos() const { return GetStruct<const Vec3 *>(VT_POS); }
|
const Vec3 *pos() const {
|
||||||
int16_t mana() const { return GetField<int16_t>(VT_MANA, 150); }
|
return GetStruct<const Vec3 *>(VT_POS);
|
||||||
int16_t hp() const { return GetField<int16_t>(VT_HP, 100); }
|
}
|
||||||
const flatbuffers::String *name() const { return GetPointer<const flatbuffers::String *>(VT_NAME); }
|
Vec3 *mutable_pos() {
|
||||||
const flatbuffers::Vector<uint8_t> *inventory() const { return GetPointer<const flatbuffers::Vector<uint8_t> *>(VT_INVENTORY); }
|
return GetStruct<Vec3 *>(VT_POS);
|
||||||
Color color() const { return static_cast<Color>(GetField<int8_t>(VT_COLOR, 2)); }
|
}
|
||||||
const flatbuffers::Vector<flatbuffers::Offset<Weapon>> *weapons() const { return GetPointer<const flatbuffers::Vector<flatbuffers::Offset<Weapon>> *>(VT_WEAPONS); }
|
int16_t mana() const {
|
||||||
Equipment equipped_type() const { return static_cast<Equipment>(GetField<uint8_t>(VT_EQUIPPED_TYPE, 0)); }
|
return GetField<int16_t>(VT_MANA, 150);
|
||||||
const void *equipped() const { return GetPointer<const void *>(VT_EQUIPPED); }
|
}
|
||||||
|
bool mutate_mana(int16_t _mana) {
|
||||||
|
return SetField(VT_MANA, _mana);
|
||||||
|
}
|
||||||
|
int16_t hp() const {
|
||||||
|
return GetField<int16_t>(VT_HP, 100);
|
||||||
|
}
|
||||||
|
bool mutate_hp(int16_t _hp) {
|
||||||
|
return SetField(VT_HP, _hp);
|
||||||
|
}
|
||||||
|
const flatbuffers::String *name() const {
|
||||||
|
return GetPointer<const flatbuffers::String *>(VT_NAME);
|
||||||
|
}
|
||||||
|
flatbuffers::String *mutable_name() {
|
||||||
|
return GetPointer<flatbuffers::String *>(VT_NAME);
|
||||||
|
}
|
||||||
|
const flatbuffers::Vector<uint8_t> *inventory() const {
|
||||||
|
return GetPointer<const flatbuffers::Vector<uint8_t> *>(VT_INVENTORY);
|
||||||
|
}
|
||||||
|
flatbuffers::Vector<uint8_t> *mutable_inventory() {
|
||||||
|
return GetPointer<flatbuffers::Vector<uint8_t> *>(VT_INVENTORY);
|
||||||
|
}
|
||||||
|
Color color() const {
|
||||||
|
return static_cast<Color>(GetField<int8_t>(VT_COLOR, 2));
|
||||||
|
}
|
||||||
|
bool mutate_color(Color _color) {
|
||||||
|
return SetField(VT_COLOR, static_cast<int8_t>(_color));
|
||||||
|
}
|
||||||
|
const flatbuffers::Vector<flatbuffers::Offset<Weapon>> *weapons() const {
|
||||||
|
return GetPointer<const flatbuffers::Vector<flatbuffers::Offset<Weapon>> *>(VT_WEAPONS);
|
||||||
|
}
|
||||||
|
flatbuffers::Vector<flatbuffers::Offset<Weapon>> *mutable_weapons() {
|
||||||
|
return GetPointer<flatbuffers::Vector<flatbuffers::Offset<Weapon>> *>(VT_WEAPONS);
|
||||||
|
}
|
||||||
|
Equipment equipped_type() const {
|
||||||
|
return static_cast<Equipment>(GetField<uint8_t>(VT_EQUIPPED_TYPE, 0));
|
||||||
|
}
|
||||||
|
bool mutate_equipped_type(Equipment _equipped_type) {
|
||||||
|
return SetField(VT_EQUIPPED_TYPE, static_cast<uint8_t>(_equipped_type));
|
||||||
|
}
|
||||||
|
const void *equipped() const {
|
||||||
|
return GetPointer<const void *>(VT_EQUIPPED);
|
||||||
|
}
|
||||||
|
void *mutable_equipped() {
|
||||||
|
return GetPointer<void *>(VT_EQUIPPED);
|
||||||
|
}
|
||||||
bool Verify(flatbuffers::Verifier &verifier) const {
|
bool Verify(flatbuffers::Verifier &verifier) const {
|
||||||
return VerifyTableStart(verifier) &&
|
return VerifyTableStart(verifier) &&
|
||||||
VerifyField<Vec3>(verifier, VT_POS) &&
|
VerifyField<Vec3>(verifier, VT_POS) &&
|
||||||
@@ -99,38 +244,64 @@ struct Monster FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table {
|
|||||||
VerifyEquipment(verifier, equipped(), equipped_type()) &&
|
VerifyEquipment(verifier, equipped(), equipped_type()) &&
|
||||||
verifier.EndTable();
|
verifier.EndTable();
|
||||||
}
|
}
|
||||||
|
MonsterT *UnPack(const flatbuffers::resolver_function_t *_resolver = nullptr) const;
|
||||||
|
void UnPackTo(MonsterT *_o, const flatbuffers::resolver_function_t *_resolver = nullptr) const;
|
||||||
|
static flatbuffers::Offset<Monster> Pack(flatbuffers::FlatBufferBuilder &_fbb, const MonsterT* _o, const flatbuffers::rehasher_function_t *_rehasher = nullptr);
|
||||||
};
|
};
|
||||||
|
|
||||||
struct MonsterBuilder {
|
struct MonsterBuilder {
|
||||||
flatbuffers::FlatBufferBuilder &fbb_;
|
flatbuffers::FlatBufferBuilder &fbb_;
|
||||||
flatbuffers::uoffset_t start_;
|
flatbuffers::uoffset_t start_;
|
||||||
void add_pos(const Vec3 *pos) { fbb_.AddStruct(Monster::VT_POS, pos); }
|
void add_pos(const Vec3 *pos) {
|
||||||
void add_mana(int16_t mana) { fbb_.AddElement<int16_t>(Monster::VT_MANA, mana, 150); }
|
fbb_.AddStruct(Monster::VT_POS, pos);
|
||||||
void add_hp(int16_t hp) { fbb_.AddElement<int16_t>(Monster::VT_HP, hp, 100); }
|
}
|
||||||
void add_name(flatbuffers::Offset<flatbuffers::String> name) { fbb_.AddOffset(Monster::VT_NAME, name); }
|
void add_mana(int16_t mana) {
|
||||||
void add_inventory(flatbuffers::Offset<flatbuffers::Vector<uint8_t>> inventory) { fbb_.AddOffset(Monster::VT_INVENTORY, inventory); }
|
fbb_.AddElement<int16_t>(Monster::VT_MANA, mana, 150);
|
||||||
void add_color(Color color) { fbb_.AddElement<int8_t>(Monster::VT_COLOR, static_cast<int8_t>(color), 2); }
|
}
|
||||||
void add_weapons(flatbuffers::Offset<flatbuffers::Vector<flatbuffers::Offset<Weapon>>> weapons) { fbb_.AddOffset(Monster::VT_WEAPONS, weapons); }
|
void add_hp(int16_t hp) {
|
||||||
void add_equipped_type(Equipment equipped_type) { fbb_.AddElement<uint8_t>(Monster::VT_EQUIPPED_TYPE, static_cast<uint8_t>(equipped_type), 0); }
|
fbb_.AddElement<int16_t>(Monster::VT_HP, hp, 100);
|
||||||
void add_equipped(flatbuffers::Offset<void> equipped) { fbb_.AddOffset(Monster::VT_EQUIPPED, equipped); }
|
}
|
||||||
MonsterBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) { start_ = fbb_.StartTable(); }
|
void add_name(flatbuffers::Offset<flatbuffers::String> name) {
|
||||||
|
fbb_.AddOffset(Monster::VT_NAME, name);
|
||||||
|
}
|
||||||
|
void add_inventory(flatbuffers::Offset<flatbuffers::Vector<uint8_t>> inventory) {
|
||||||
|
fbb_.AddOffset(Monster::VT_INVENTORY, inventory);
|
||||||
|
}
|
||||||
|
void add_color(Color color) {
|
||||||
|
fbb_.AddElement<int8_t>(Monster::VT_COLOR, static_cast<int8_t>(color), 2);
|
||||||
|
}
|
||||||
|
void add_weapons(flatbuffers::Offset<flatbuffers::Vector<flatbuffers::Offset<Weapon>>> weapons) {
|
||||||
|
fbb_.AddOffset(Monster::VT_WEAPONS, weapons);
|
||||||
|
}
|
||||||
|
void add_equipped_type(Equipment equipped_type) {
|
||||||
|
fbb_.AddElement<uint8_t>(Monster::VT_EQUIPPED_TYPE, static_cast<uint8_t>(equipped_type), 0);
|
||||||
|
}
|
||||||
|
void add_equipped(flatbuffers::Offset<void> equipped) {
|
||||||
|
fbb_.AddOffset(Monster::VT_EQUIPPED, equipped);
|
||||||
|
}
|
||||||
|
MonsterBuilder(flatbuffers::FlatBufferBuilder &_fbb)
|
||||||
|
: fbb_(_fbb) {
|
||||||
|
start_ = fbb_.StartTable();
|
||||||
|
}
|
||||||
MonsterBuilder &operator=(const MonsterBuilder &);
|
MonsterBuilder &operator=(const MonsterBuilder &);
|
||||||
flatbuffers::Offset<Monster> Finish() {
|
flatbuffers::Offset<Monster> Finish() {
|
||||||
auto o = flatbuffers::Offset<Monster>(fbb_.EndTable(start_, 10));
|
const auto end = fbb_.EndTable(start_, 10);
|
||||||
|
auto o = flatbuffers::Offset<Monster>(end);
|
||||||
return o;
|
return o;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
inline flatbuffers::Offset<Monster> CreateMonster(flatbuffers::FlatBufferBuilder &_fbb,
|
inline flatbuffers::Offset<Monster> CreateMonster(
|
||||||
const Vec3 *pos = 0,
|
flatbuffers::FlatBufferBuilder &_fbb,
|
||||||
int16_t mana = 150,
|
const Vec3 *pos = 0,
|
||||||
int16_t hp = 100,
|
int16_t mana = 150,
|
||||||
flatbuffers::Offset<flatbuffers::String> name = 0,
|
int16_t hp = 100,
|
||||||
flatbuffers::Offset<flatbuffers::Vector<uint8_t>> inventory = 0,
|
flatbuffers::Offset<flatbuffers::String> name = 0,
|
||||||
Color color = Color_Blue,
|
flatbuffers::Offset<flatbuffers::Vector<uint8_t>> inventory = 0,
|
||||||
flatbuffers::Offset<flatbuffers::Vector<flatbuffers::Offset<Weapon>>> weapons = 0,
|
Color color = Color_Blue,
|
||||||
Equipment equipped_type = Equipment_NONE,
|
flatbuffers::Offset<flatbuffers::Vector<flatbuffers::Offset<Weapon>>> weapons = 0,
|
||||||
flatbuffers::Offset<void> equipped = 0) {
|
Equipment equipped_type = Equipment_NONE,
|
||||||
|
flatbuffers::Offset<void> equipped = 0) {
|
||||||
MonsterBuilder builder_(_fbb);
|
MonsterBuilder builder_(_fbb);
|
||||||
builder_.add_equipped(equipped);
|
builder_.add_equipped(equipped);
|
||||||
builder_.add_weapons(weapons);
|
builder_.add_weapons(weapons);
|
||||||
@@ -144,13 +315,59 @@ inline flatbuffers::Offset<Monster> CreateMonster(flatbuffers::FlatBufferBuilder
|
|||||||
return builder_.Finish();
|
return builder_.Finish();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline flatbuffers::Offset<Monster> CreateMonsterDirect(
|
||||||
|
flatbuffers::FlatBufferBuilder &_fbb,
|
||||||
|
const Vec3 *pos = 0,
|
||||||
|
int16_t mana = 150,
|
||||||
|
int16_t hp = 100,
|
||||||
|
const char *name = nullptr,
|
||||||
|
const std::vector<uint8_t> *inventory = nullptr,
|
||||||
|
Color color = Color_Blue,
|
||||||
|
const std::vector<flatbuffers::Offset<Weapon>> *weapons = nullptr,
|
||||||
|
Equipment equipped_type = Equipment_NONE,
|
||||||
|
flatbuffers::Offset<void> equipped = 0) {
|
||||||
|
return MyGame::Sample::CreateMonster(
|
||||||
|
_fbb,
|
||||||
|
pos,
|
||||||
|
mana,
|
||||||
|
hp,
|
||||||
|
name ? _fbb.CreateString(name) : 0,
|
||||||
|
inventory ? _fbb.CreateVector<uint8_t>(*inventory) : 0,
|
||||||
|
color,
|
||||||
|
weapons ? _fbb.CreateVector<flatbuffers::Offset<Weapon>>(*weapons) : 0,
|
||||||
|
equipped_type,
|
||||||
|
equipped);
|
||||||
|
}
|
||||||
|
|
||||||
|
flatbuffers::Offset<Monster> CreateMonster(flatbuffers::FlatBufferBuilder &_fbb, const MonsterT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr);
|
||||||
|
|
||||||
|
struct WeaponT : public flatbuffers::NativeTable {
|
||||||
|
typedef Weapon TableType;
|
||||||
|
std::string name;
|
||||||
|
int16_t damage;
|
||||||
|
WeaponT()
|
||||||
|
: damage(0) {
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
struct Weapon FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table {
|
struct Weapon FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table {
|
||||||
|
typedef WeaponT NativeTableType;
|
||||||
enum {
|
enum {
|
||||||
VT_NAME = 4,
|
VT_NAME = 4,
|
||||||
VT_DAMAGE = 6
|
VT_DAMAGE = 6
|
||||||
};
|
};
|
||||||
const flatbuffers::String *name() const { return GetPointer<const flatbuffers::String *>(VT_NAME); }
|
const flatbuffers::String *name() const {
|
||||||
int16_t damage() const { return GetField<int16_t>(VT_DAMAGE, 0); }
|
return GetPointer<const flatbuffers::String *>(VT_NAME);
|
||||||
|
}
|
||||||
|
flatbuffers::String *mutable_name() {
|
||||||
|
return GetPointer<flatbuffers::String *>(VT_NAME);
|
||||||
|
}
|
||||||
|
int16_t damage() const {
|
||||||
|
return GetField<int16_t>(VT_DAMAGE, 0);
|
||||||
|
}
|
||||||
|
bool mutate_damage(int16_t _damage) {
|
||||||
|
return SetField(VT_DAMAGE, _damage);
|
||||||
|
}
|
||||||
bool Verify(flatbuffers::Verifier &verifier) const {
|
bool Verify(flatbuffers::Verifier &verifier) const {
|
||||||
return VerifyTableStart(verifier) &&
|
return VerifyTableStart(verifier) &&
|
||||||
VerifyField<flatbuffers::uoffset_t>(verifier, VT_NAME) &&
|
VerifyField<flatbuffers::uoffset_t>(verifier, VT_NAME) &&
|
||||||
@@ -158,43 +375,212 @@ struct Weapon FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table {
|
|||||||
VerifyField<int16_t>(verifier, VT_DAMAGE) &&
|
VerifyField<int16_t>(verifier, VT_DAMAGE) &&
|
||||||
verifier.EndTable();
|
verifier.EndTable();
|
||||||
}
|
}
|
||||||
|
WeaponT *UnPack(const flatbuffers::resolver_function_t *_resolver = nullptr) const;
|
||||||
|
void UnPackTo(WeaponT *_o, const flatbuffers::resolver_function_t *_resolver = nullptr) const;
|
||||||
|
static flatbuffers::Offset<Weapon> Pack(flatbuffers::FlatBufferBuilder &_fbb, const WeaponT* _o, const flatbuffers::rehasher_function_t *_rehasher = nullptr);
|
||||||
};
|
};
|
||||||
|
|
||||||
struct WeaponBuilder {
|
struct WeaponBuilder {
|
||||||
flatbuffers::FlatBufferBuilder &fbb_;
|
flatbuffers::FlatBufferBuilder &fbb_;
|
||||||
flatbuffers::uoffset_t start_;
|
flatbuffers::uoffset_t start_;
|
||||||
void add_name(flatbuffers::Offset<flatbuffers::String> name) { fbb_.AddOffset(Weapon::VT_NAME, name); }
|
void add_name(flatbuffers::Offset<flatbuffers::String> name) {
|
||||||
void add_damage(int16_t damage) { fbb_.AddElement<int16_t>(Weapon::VT_DAMAGE, damage, 0); }
|
fbb_.AddOffset(Weapon::VT_NAME, name);
|
||||||
WeaponBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) { start_ = fbb_.StartTable(); }
|
}
|
||||||
|
void add_damage(int16_t damage) {
|
||||||
|
fbb_.AddElement<int16_t>(Weapon::VT_DAMAGE, damage, 0);
|
||||||
|
}
|
||||||
|
WeaponBuilder(flatbuffers::FlatBufferBuilder &_fbb)
|
||||||
|
: fbb_(_fbb) {
|
||||||
|
start_ = fbb_.StartTable();
|
||||||
|
}
|
||||||
WeaponBuilder &operator=(const WeaponBuilder &);
|
WeaponBuilder &operator=(const WeaponBuilder &);
|
||||||
flatbuffers::Offset<Weapon> Finish() {
|
flatbuffers::Offset<Weapon> Finish() {
|
||||||
auto o = flatbuffers::Offset<Weapon>(fbb_.EndTable(start_, 2));
|
const auto end = fbb_.EndTable(start_, 2);
|
||||||
|
auto o = flatbuffers::Offset<Weapon>(end);
|
||||||
return o;
|
return o;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
inline flatbuffers::Offset<Weapon> CreateWeapon(flatbuffers::FlatBufferBuilder &_fbb,
|
inline flatbuffers::Offset<Weapon> CreateWeapon(
|
||||||
flatbuffers::Offset<flatbuffers::String> name = 0,
|
flatbuffers::FlatBufferBuilder &_fbb,
|
||||||
int16_t damage = 0) {
|
flatbuffers::Offset<flatbuffers::String> name = 0,
|
||||||
|
int16_t damage = 0) {
|
||||||
WeaponBuilder builder_(_fbb);
|
WeaponBuilder builder_(_fbb);
|
||||||
builder_.add_name(name);
|
builder_.add_name(name);
|
||||||
builder_.add_damage(damage);
|
builder_.add_damage(damage);
|
||||||
return builder_.Finish();
|
return builder_.Finish();
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool VerifyEquipment(flatbuffers::Verifier &verifier, const void *union_obj, Equipment type) {
|
inline flatbuffers::Offset<Weapon> CreateWeaponDirect(
|
||||||
|
flatbuffers::FlatBufferBuilder &_fbb,
|
||||||
|
const char *name = nullptr,
|
||||||
|
int16_t damage = 0) {
|
||||||
|
return MyGame::Sample::CreateWeapon(
|
||||||
|
_fbb,
|
||||||
|
name ? _fbb.CreateString(name) : 0,
|
||||||
|
damage);
|
||||||
|
}
|
||||||
|
|
||||||
|
flatbuffers::Offset<Weapon> CreateWeapon(flatbuffers::FlatBufferBuilder &_fbb, const WeaponT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr);
|
||||||
|
|
||||||
|
inline MonsterT *Monster::UnPack(const flatbuffers::resolver_function_t *_resolver) const {
|
||||||
|
auto _o = new MonsterT();
|
||||||
|
UnPackTo(_o, _resolver);
|
||||||
|
return _o;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void Monster::UnPackTo(MonsterT *_o, const flatbuffers::resolver_function_t *_resolver) const {
|
||||||
|
(void)_o;
|
||||||
|
(void)_resolver;
|
||||||
|
{ auto _e = pos(); if (_e) _o->pos = std::unique_ptr<Vec3>(new Vec3(*_e)); };
|
||||||
|
{ auto _e = mana(); _o->mana = _e; };
|
||||||
|
{ auto _e = hp(); _o->hp = _e; };
|
||||||
|
{ auto _e = name(); if (_e) _o->name = _e->str(); };
|
||||||
|
{ auto _e = inventory(); if (_e) for (flatbuffers::uoffset_t _i = 0; _i < _e->size(); _i++) { _o->inventory.push_back(_e->Get(_i)); } };
|
||||||
|
{ auto _e = color(); _o->color = _e; };
|
||||||
|
{ auto _e = weapons(); if (_e) for (flatbuffers::uoffset_t _i = 0; _i < _e->size(); _i++) { _o->weapons.push_back(std::unique_ptr<WeaponT>(_e->Get(_i)->UnPack(_resolver))); } };
|
||||||
|
{ auto _e = equipped_type(); _o->equipped.type = _e; };
|
||||||
|
{ auto _e = equipped(); if (_e) _o->equipped.table = EquipmentUnion::UnPack(_e, equipped_type(),_resolver); };
|
||||||
|
}
|
||||||
|
|
||||||
|
inline flatbuffers::Offset<Monster> Monster::Pack(flatbuffers::FlatBufferBuilder &_fbb, const MonsterT* _o, const flatbuffers::rehasher_function_t *_rehasher) {
|
||||||
|
return CreateMonster(_fbb, _o, _rehasher);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline flatbuffers::Offset<Monster> CreateMonster(flatbuffers::FlatBufferBuilder &_fbb, const MonsterT *_o, const flatbuffers::rehasher_function_t *_rehasher) {
|
||||||
|
(void)_rehasher;
|
||||||
|
(void)_o;
|
||||||
|
auto _pos = _o->pos ? _o->pos.get() : 0;
|
||||||
|
auto _mana = _o->mana;
|
||||||
|
auto _hp = _o->hp;
|
||||||
|
auto _name = _o->name.size() ? _fbb.CreateString(_o->name) : 0;
|
||||||
|
auto _inventory = _o->inventory.size() ? _fbb.CreateVector(_o->inventory) : 0;
|
||||||
|
auto _color = _o->color;
|
||||||
|
auto _weapons = _o->weapons.size() ? _fbb.CreateVector<flatbuffers::Offset<Weapon>>(_o->weapons.size(), [&](size_t i) { return CreateWeapon(_fbb, _o->weapons[i].get(), _rehasher); }) : 0;
|
||||||
|
auto _equipped_type = _o->equipped.type;
|
||||||
|
auto _equipped = _o->equipped.Pack(_fbb);
|
||||||
|
return MyGame::Sample::CreateMonster(
|
||||||
|
_fbb,
|
||||||
|
_pos,
|
||||||
|
_mana,
|
||||||
|
_hp,
|
||||||
|
_name,
|
||||||
|
_inventory,
|
||||||
|
_color,
|
||||||
|
_weapons,
|
||||||
|
_equipped_type,
|
||||||
|
_equipped);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline WeaponT *Weapon::UnPack(const flatbuffers::resolver_function_t *_resolver) const {
|
||||||
|
auto _o = new WeaponT();
|
||||||
|
UnPackTo(_o, _resolver);
|
||||||
|
return _o;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void Weapon::UnPackTo(WeaponT *_o, const flatbuffers::resolver_function_t *_resolver) const {
|
||||||
|
(void)_o;
|
||||||
|
(void)_resolver;
|
||||||
|
{ auto _e = name(); if (_e) _o->name = _e->str(); };
|
||||||
|
{ auto _e = damage(); _o->damage = _e; };
|
||||||
|
}
|
||||||
|
|
||||||
|
inline flatbuffers::Offset<Weapon> Weapon::Pack(flatbuffers::FlatBufferBuilder &_fbb, const WeaponT* _o, const flatbuffers::rehasher_function_t *_rehasher) {
|
||||||
|
return CreateWeapon(_fbb, _o, _rehasher);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline flatbuffers::Offset<Weapon> CreateWeapon(flatbuffers::FlatBufferBuilder &_fbb, const WeaponT *_o, const flatbuffers::rehasher_function_t *_rehasher) {
|
||||||
|
(void)_rehasher;
|
||||||
|
(void)_o;
|
||||||
|
auto _name = _o->name.size() ? _fbb.CreateString(_o->name) : 0;
|
||||||
|
auto _damage = _o->damage;
|
||||||
|
return MyGame::Sample::CreateWeapon(
|
||||||
|
_fbb,
|
||||||
|
_name,
|
||||||
|
_damage);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline bool VerifyEquipment(flatbuffers::Verifier &verifier, const void *obj, Equipment type) {
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case Equipment_NONE: return true;
|
case Equipment_NONE: {
|
||||||
case Equipment_Weapon: return verifier.VerifyTable(reinterpret_cast<const Weapon *>(union_obj));
|
return true;
|
||||||
|
}
|
||||||
|
case Equipment_Weapon: {
|
||||||
|
auto ptr = reinterpret_cast<const Weapon *>(obj);
|
||||||
|
return verifier.VerifyTable(ptr);
|
||||||
|
}
|
||||||
default: return false;
|
default: return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
inline const MyGame::Sample::Monster *GetMonster(const void *buf) { return flatbuffers::GetRoot<MyGame::Sample::Monster>(buf); }
|
inline bool VerifyEquipmentVector(flatbuffers::Verifier &verifier, const flatbuffers::Vector<flatbuffers::Offset<void>> *values, const flatbuffers::Vector<uint8_t> *types) {
|
||||||
|
if (values->size() != types->size()) return false;
|
||||||
|
for (flatbuffers::uoffset_t i = 0; i < values->size(); ++i) {
|
||||||
|
if (!VerifyEquipment(
|
||||||
|
verifier, values->Get(i), types->GetEnum<Equipment>(i))) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
inline bool VerifyMonsterBuffer(flatbuffers::Verifier &verifier) { return verifier.VerifyBuffer<MyGame::Sample::Monster>(); }
|
inline flatbuffers::NativeTable *EquipmentUnion::UnPack(const void *obj, Equipment type, const flatbuffers::resolver_function_t *resolver) {
|
||||||
|
switch (type) {
|
||||||
|
case Equipment_Weapon: {
|
||||||
|
auto ptr = reinterpret_cast<const Weapon *>(obj);
|
||||||
|
return ptr->UnPack(resolver);
|
||||||
|
}
|
||||||
|
default: return nullptr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
inline void FinishMonsterBuffer(flatbuffers::FlatBufferBuilder &fbb, flatbuffers::Offset<MyGame::Sample::Monster> root) { fbb.Finish(root); }
|
inline flatbuffers::Offset<void> EquipmentUnion::Pack(flatbuffers::FlatBufferBuilder &_fbb, const flatbuffers::rehasher_function_t *_rehasher) const {
|
||||||
|
switch (type) {
|
||||||
|
case Equipment_Weapon: {
|
||||||
|
auto ptr = reinterpret_cast<const WeaponT *>(table);
|
||||||
|
return CreateWeapon(_fbb, ptr, _rehasher).Union();
|
||||||
|
}
|
||||||
|
default: return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void EquipmentUnion::Reset() {
|
||||||
|
switch (type) {
|
||||||
|
case Equipment_Weapon: {
|
||||||
|
auto ptr = reinterpret_cast<WeaponT *>(table);
|
||||||
|
delete ptr;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default: break;
|
||||||
|
}
|
||||||
|
table = nullptr;
|
||||||
|
type = Equipment_NONE;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline const MyGame::Sample::Monster *GetMonster(const void *buf) {
|
||||||
|
return flatbuffers::GetRoot<MyGame::Sample::Monster>(buf);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline Monster *GetMutableMonster(void *buf) {
|
||||||
|
return flatbuffers::GetMutableRoot<Monster>(buf);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline bool VerifyMonsterBuffer(
|
||||||
|
flatbuffers::Verifier &verifier) {
|
||||||
|
return verifier.VerifyBuffer<MyGame::Sample::Monster>(nullptr);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void FinishMonsterBuffer(
|
||||||
|
flatbuffers::FlatBufferBuilder &fbb,
|
||||||
|
flatbuffers::Offset<MyGame::Sample::Monster> root) {
|
||||||
|
fbb.Finish(root);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline std::unique_ptr<MonsterT> UnPackMonster(
|
||||||
|
const void *buf,
|
||||||
|
const flatbuffers::resolver_function_t *res = nullptr) {
|
||||||
|
return std::unique_ptr<MonsterT>(GetMonster(buf)->UnPack(res));
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace Sample
|
} // namespace Sample
|
||||||
} // namespace MyGame
|
} // namespace MyGame
|
||||||
|
|||||||
@@ -5,5 +5,21 @@
|
|||||||
z: 3
|
z: 3
|
||||||
},
|
},
|
||||||
hp: 300,
|
hp: 300,
|
||||||
name: "Orc"
|
name: "Orc",
|
||||||
|
weapons:[
|
||||||
|
{
|
||||||
|
name: "axe",
|
||||||
|
damage:100
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "bow",
|
||||||
|
damage:90
|
||||||
|
}
|
||||||
|
],
|
||||||
|
equipped_type: "Weapon",
|
||||||
|
equipped:
|
||||||
|
{
|
||||||
|
name: "bow",
|
||||||
|
damage:90
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
#
|
||||||
# Copyright 2015 Google Inc. All rights reserved.
|
# Copyright 2015 Google Inc. All rights reserved.
|
||||||
#
|
#
|
||||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
@@ -12,7 +13,7 @@
|
|||||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
# See the License for the specific language governing permissions and
|
# See the License for the specific language governing permissions and
|
||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
#
|
||||||
# Note: This script runs on Mac and Linux. It requires `php` to be installed
|
# Note: This script runs on Mac and Linux. It requires `php` to be installed
|
||||||
# and `flatc` to be built (using `cmake` in the root directory).
|
# and `flatc` to be built (using `cmake` in the root directory).
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
#
|
||||||
# Copyright 2015 Google Inc. All rights reserved.
|
# Copyright 2015 Google Inc. All rights reserved.
|
||||||
#
|
#
|
||||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
@@ -12,7 +13,7 @@
|
|||||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
# See the License for the specific language governing permissions and
|
# See the License for the specific language governing permissions and
|
||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
#
|
||||||
# Note: This script runs on Mac and Linux. It requires `python` to be installed
|
# Note: This script runs on Mac and Linux. It requires `python` to be installed
|
||||||
# and `flatc` to be built (using `cmake` in the root directory).
|
# and `flatc` to be built (using `cmake` in the root directory).
|
||||||
|
|
||||||
|
|||||||
@@ -19,147 +19,147 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
flatbuffers "github.com/google/flatbuffers/go"
|
sample "MyGame/Sample"
|
||||||
"fmt"
|
"fmt"
|
||||||
"strconv"
|
flatbuffers "github.com/google/flatbuffers/go"
|
||||||
sample "MyGame/Sample"
|
"strconv"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Example how to use Flatbuffers to create and read binary buffers.
|
// Example how to use Flatbuffers to create and read binary buffers.
|
||||||
func main() {
|
func main() {
|
||||||
builder := flatbuffers.NewBuilder(0)
|
builder := flatbuffers.NewBuilder(0)
|
||||||
|
|
||||||
// Create some weapons for our Monster ("Sword" and "Axe").
|
// Create some weapons for our Monster ("Sword" and "Axe").
|
||||||
weaponOne := builder.CreateString("Sword")
|
weaponOne := builder.CreateString("Sword")
|
||||||
weaponTwo := builder.CreateString("Axe")
|
weaponTwo := builder.CreateString("Axe")
|
||||||
|
|
||||||
sample.WeaponStart(builder)
|
sample.WeaponStart(builder)
|
||||||
sample.WeaponAddName(builder, weaponOne)
|
sample.WeaponAddName(builder, weaponOne)
|
||||||
sample.WeaponAddDamage(builder, 3)
|
sample.WeaponAddDamage(builder, 3)
|
||||||
sword := sample.WeaponEnd(builder)
|
sword := sample.WeaponEnd(builder)
|
||||||
|
|
||||||
sample.WeaponStart(builder)
|
sample.WeaponStart(builder)
|
||||||
sample.WeaponAddName(builder, weaponTwo)
|
sample.WeaponAddName(builder, weaponTwo)
|
||||||
sample.WeaponAddDamage(builder, 5)
|
sample.WeaponAddDamage(builder, 5)
|
||||||
axe := sample.WeaponEnd(builder)
|
axe := sample.WeaponEnd(builder)
|
||||||
|
|
||||||
// Serialize the FlatBuffer data.
|
// Serialize the FlatBuffer data.
|
||||||
name := builder.CreateString("Orc")
|
name := builder.CreateString("Orc")
|
||||||
|
|
||||||
sample.MonsterStartInventoryVector(builder, 10)
|
sample.MonsterStartInventoryVector(builder, 10)
|
||||||
// Note: Since we prepend the bytes, this loop iterates in reverse.
|
// Note: Since we prepend the bytes, this loop iterates in reverse.
|
||||||
for i := 9; i >= 0; i-- {
|
for i := 9; i >= 0; i-- {
|
||||||
builder.PrependByte(byte(i))
|
builder.PrependByte(byte(i))
|
||||||
}
|
}
|
||||||
inv := builder.EndVector(10)
|
inv := builder.EndVector(10)
|
||||||
|
|
||||||
sample.MonsterStartWeaponsVector(builder, 2)
|
sample.MonsterStartWeaponsVector(builder, 2)
|
||||||
// Note: Since we prepend the weapons, prepend in reverse order.
|
// Note: Since we prepend the weapons, prepend in reverse order.
|
||||||
builder.PrependUOffsetT(axe)
|
builder.PrependUOffsetT(axe)
|
||||||
builder.PrependUOffsetT(sword)
|
builder.PrependUOffsetT(sword)
|
||||||
weapons := builder.EndVector(2)
|
weapons := builder.EndVector(2)
|
||||||
|
|
||||||
pos := sample.CreateVec3(builder, 1.0, 2.0, 3.0)
|
pos := sample.CreateVec3(builder, 1.0, 2.0, 3.0)
|
||||||
|
|
||||||
sample.MonsterStart(builder)
|
sample.MonsterStart(builder)
|
||||||
sample.MonsterAddPos(builder, pos)
|
sample.MonsterAddPos(builder, pos)
|
||||||
sample.MonsterAddHp(builder, 300)
|
sample.MonsterAddHp(builder, 300)
|
||||||
sample.MonsterAddName(builder, name)
|
sample.MonsterAddName(builder, name)
|
||||||
sample.MonsterAddInventory(builder, inv)
|
sample.MonsterAddInventory(builder, inv)
|
||||||
sample.MonsterAddColor(builder, sample.ColorRed)
|
sample.MonsterAddColor(builder, sample.ColorRed)
|
||||||
sample.MonsterAddWeapons(builder, weapons)
|
sample.MonsterAddWeapons(builder, weapons)
|
||||||
sample.MonsterAddEquippedType(builder, sample.EquipmentWeapon)
|
sample.MonsterAddEquippedType(builder, sample.EquipmentWeapon)
|
||||||
sample.MonsterAddEquipped(builder, axe)
|
sample.MonsterAddEquipped(builder, axe)
|
||||||
orc := sample.MonsterEnd(builder)
|
orc := sample.MonsterEnd(builder)
|
||||||
|
|
||||||
builder.Finish(orc)
|
builder.Finish(orc)
|
||||||
|
|
||||||
// We now have a FlatBuffer that we could store on disk or send over a network.
|
// We now have a FlatBuffer that we could store on disk or send over a network.
|
||||||
|
|
||||||
// ...Saving to file or sending over a network code goes here...
|
// ...Saving to file or sending over a network code goes here...
|
||||||
|
|
||||||
// Instead, we are going to access this buffer right away (as if we just received it).
|
// Instead, we are going to access this buffer right away (as if we just received it).
|
||||||
|
|
||||||
buf := builder.FinishedBytes()
|
buf := builder.FinishedBytes()
|
||||||
|
|
||||||
// Note: We use `0` for the offset here, since we got the data using the
|
// Note: We use `0` for the offset here, since we got the data using the
|
||||||
// `builder.FinishedBytes()` method. This simulates the data you would store/receive in your
|
// `builder.FinishedBytes()` method. This simulates the data you would store/receive in your
|
||||||
// FlatBuffer. If you wanted to read from the `builder.Bytes` directly, you would need to
|
// FlatBuffer. If you wanted to read from the `builder.Bytes` directly, you would need to
|
||||||
// pass in the offset of `builder.Head()`, as the builder actually constructs the buffer
|
// pass in the offset of `builder.Head()`, as the builder actually constructs the buffer
|
||||||
// backwards.
|
// backwards.
|
||||||
monster := sample.GetRootAsMonster(buf, 0)
|
monster := sample.GetRootAsMonster(buf, 0)
|
||||||
|
|
||||||
// Note: We did not set the `mana` field explicitly, so we get the
|
// Note: We did not set the `mana` field explicitly, so we get the
|
||||||
// default value.
|
// default value.
|
||||||
assert(monster.Mana() == 150, "`monster.Mana()`", strconv.Itoa(int(monster.Mana())), "150")
|
assert(monster.Mana() == 150, "`monster.Mana()`", strconv.Itoa(int(monster.Mana())), "150")
|
||||||
assert(monster.Hp() == 300, "`monster.Hp()`", strconv.Itoa(int(monster.Hp())), "300")
|
assert(monster.Hp() == 300, "`monster.Hp()`", strconv.Itoa(int(monster.Hp())), "300")
|
||||||
assert(string(monster.Name()) == "Orc", "`string(monster.Name())`", string(monster.Name()),
|
assert(string(monster.Name()) == "Orc", "`string(monster.Name())`", string(monster.Name()),
|
||||||
"\"Orc\"")
|
"\"Orc\"")
|
||||||
assert(monster.Color() == sample.ColorRed, "`monster.Color()`",
|
assert(monster.Color() == sample.ColorRed, "`monster.Color()`",
|
||||||
strconv.Itoa(int(monster.Color())), strconv.Itoa(int(sample.ColorRed)))
|
strconv.Itoa(int(monster.Color())), strconv.Itoa(int(sample.ColorRed)))
|
||||||
|
|
||||||
// Note: Whenever you access a new object, like in `Pos()`, a new temporary accessor object
|
// Note: Whenever you access a new object, like in `Pos()`, a new temporary accessor object
|
||||||
// gets created. If your code is very performance sensitive, you can pass in a pointer to an
|
// gets created. If your code is very performance sensitive, you can pass in a pointer to an
|
||||||
// existing `Vec3` instead of `nil`. This allows you to reuse it across many calls to reduce
|
// existing `Vec3` instead of `nil`. This allows you to reuse it across many calls to reduce
|
||||||
// the amount of object allocation/garbage collection.
|
// the amount of object allocation/garbage collection.
|
||||||
assert(monster.Pos(nil).X() == 1.0, "`monster.Pos(nil).X()`",
|
assert(monster.Pos(nil).X() == 1.0, "`monster.Pos(nil).X()`",
|
||||||
strconv.FormatFloat(float64(monster.Pos(nil).X()), 'f', 1, 32), "1.0")
|
strconv.FormatFloat(float64(monster.Pos(nil).X()), 'f', 1, 32), "1.0")
|
||||||
assert(monster.Pos(nil).Y() == 2.0, "`monster.Pos(nil).Y()`",
|
assert(monster.Pos(nil).Y() == 2.0, "`monster.Pos(nil).Y()`",
|
||||||
strconv.FormatFloat(float64(monster.Pos(nil).Y()), 'f', 1, 32), "2.0")
|
strconv.FormatFloat(float64(monster.Pos(nil).Y()), 'f', 1, 32), "2.0")
|
||||||
assert(monster.Pos(nil).Z() == 3.0, "`monster.Pos(nil).Z()`",
|
assert(monster.Pos(nil).Z() == 3.0, "`monster.Pos(nil).Z()`",
|
||||||
strconv.FormatFloat(float64(monster.Pos(nil).Z()), 'f', 1, 32), "3.0")
|
strconv.FormatFloat(float64(monster.Pos(nil).Z()), 'f', 1, 32), "3.0")
|
||||||
|
|
||||||
// For vectors, like `Inventory`, they have a method suffixed with 'Length' that can be used
|
// For vectors, like `Inventory`, they have a method suffixed with 'Length' that can be used
|
||||||
// to query the length of the vector. You can index the vector by passing an index value
|
// to query the length of the vector. You can index the vector by passing an index value
|
||||||
// into the accessor.
|
// into the accessor.
|
||||||
for i := 0; i < monster.InventoryLength(); i++ {
|
for i := 0; i < monster.InventoryLength(); i++ {
|
||||||
assert(monster.Inventory(i) == byte(i), "`monster.Inventory(i)`",
|
assert(monster.Inventory(i) == byte(i), "`monster.Inventory(i)`",
|
||||||
strconv.Itoa(int(monster.Inventory(i))), strconv.Itoa(int(byte(i))))
|
strconv.Itoa(int(monster.Inventory(i))), strconv.Itoa(int(byte(i))))
|
||||||
}
|
}
|
||||||
|
|
||||||
expectedWeaponNames := []string{"Sword", "Axe"}
|
expectedWeaponNames := []string{"Sword", "Axe"}
|
||||||
expectedWeaponDamages := []int{3, 5}
|
expectedWeaponDamages := []int{3, 5}
|
||||||
weapon := new(sample.Weapon) // We need a `sample.Weapon` to pass into `monster.Weapons()`
|
weapon := new(sample.Weapon) // We need a `sample.Weapon` to pass into `monster.Weapons()`
|
||||||
// to capture the output of that function.
|
// to capture the output of that function.
|
||||||
for i := 0; i < monster.WeaponsLength(); i++ {
|
for i := 0; i < monster.WeaponsLength(); i++ {
|
||||||
if monster.Weapons(weapon, i) {
|
if monster.Weapons(weapon, i) {
|
||||||
assert(string(weapon.Name()) == expectedWeaponNames[i], "`weapon.Name()`",
|
assert(string(weapon.Name()) == expectedWeaponNames[i], "`weapon.Name()`",
|
||||||
string(weapon.Name()), expectedWeaponNames[i])
|
string(weapon.Name()), expectedWeaponNames[i])
|
||||||
assert(int(weapon.Damage()) == expectedWeaponDamages[i],
|
assert(int(weapon.Damage()) == expectedWeaponDamages[i],
|
||||||
"`weapon.Damage()`", strconv.Itoa(int(weapon.Damage())),
|
"`weapon.Damage()`", strconv.Itoa(int(weapon.Damage())),
|
||||||
strconv.Itoa(expectedWeaponDamages[i]))
|
strconv.Itoa(expectedWeaponDamages[i]))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// For FlatBuffer `union`s, you can get the type of the union, as well as the union
|
// For FlatBuffer `union`s, you can get the type of the union, as well as the union
|
||||||
// data itself.
|
// data itself.
|
||||||
assert(monster.EquippedType() == sample.EquipmentWeapon, "`monster.EquippedType()`",
|
assert(monster.EquippedType() == sample.EquipmentWeapon, "`monster.EquippedType()`",
|
||||||
strconv.Itoa(int(monster.EquippedType())), strconv.Itoa(int(sample.EquipmentWeapon)))
|
strconv.Itoa(int(monster.EquippedType())), strconv.Itoa(int(sample.EquipmentWeapon)))
|
||||||
|
|
||||||
unionTable := new(flatbuffers.Table)
|
unionTable := new(flatbuffers.Table)
|
||||||
if monster.Equipped(unionTable) {
|
if monster.Equipped(unionTable) {
|
||||||
// An example of how you can appropriately convert the table depending on the
|
// An example of how you can appropriately convert the table depending on the
|
||||||
// FlatBuffer `union` type. You could add `else if` and `else` clauses to handle
|
// FlatBuffer `union` type. You could add `else if` and `else` clauses to handle
|
||||||
// other FlatBuffer `union` types for this field. (Similarly, this could be
|
// other FlatBuffer `union` types for this field. (Similarly, this could be
|
||||||
// done in a switch statement.)
|
// done in a switch statement.)
|
||||||
if monster.EquippedType() == sample.EquipmentWeapon {
|
if monster.EquippedType() == sample.EquipmentWeapon {
|
||||||
unionWeapon := new(sample.Weapon)
|
unionWeapon := new(sample.Weapon)
|
||||||
unionWeapon.Init(unionTable.Bytes, unionTable.Pos)
|
unionWeapon.Init(unionTable.Bytes, unionTable.Pos)
|
||||||
|
|
||||||
assert(string(unionWeapon.Name()) == "Axe", "`unionWeapon.Name()`",
|
assert(string(unionWeapon.Name()) == "Axe", "`unionWeapon.Name()`",
|
||||||
string(unionWeapon.Name()), "Axe")
|
string(unionWeapon.Name()), "Axe")
|
||||||
assert(int(unionWeapon.Damage()) == 5, "`unionWeapon.Damage()`",
|
assert(int(unionWeapon.Damage()) == 5, "`unionWeapon.Damage()`",
|
||||||
strconv.Itoa(int(unionWeapon.Damage())), strconv.Itoa(5))
|
strconv.Itoa(int(unionWeapon.Damage())), strconv.Itoa(5))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Printf("The FlatBuffer was successfully created and verified!\n")
|
fmt.Printf("The FlatBuffer was successfully created and verified!\n")
|
||||||
}
|
}
|
||||||
|
|
||||||
// A helper function to print out if an assertion failed.
|
// A helper function to print out if an assertion failed.
|
||||||
func assert(assertPassed bool, codeExecuted string, actualValue string, expectedValue string) {
|
func assert(assertPassed bool, codeExecuted string, actualValue string, expectedValue string) {
|
||||||
if assertPassed == false {
|
if assertPassed == false {
|
||||||
panic("Assert failed! " + codeExecuted + " (" + actualValue +
|
panic("Assert failed! " + codeExecuted + " (" + actualValue +
|
||||||
") was not equal to " + expectedValue + ".")
|
") was not equal to " + expectedValue + ".")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -46,7 +46,10 @@ int main(int /*argc*/, const char * /*argv*/[]) {
|
|||||||
// to ensure it is correct, we now generate text back from the binary,
|
// to ensure it is correct, we now generate text back from the binary,
|
||||||
// and compare the two:
|
// and compare the two:
|
||||||
std::string jsongen;
|
std::string jsongen;
|
||||||
GenerateText(parser, parser.builder_.GetBufferPointer(), &jsongen);
|
if (!GenerateText(parser, parser.builder_.GetBufferPointer(), &jsongen)) {
|
||||||
|
printf("Couldn't serialize parsed data to JSON!\n");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
if (jsongen != jsonfile) {
|
if (jsongen != jsonfile) {
|
||||||
printf("%s----------------\n%s", jsongen.c_str(), jsonfile.c_str());
|
printf("%s----------------\n%s", jsongen.c_str(), jsonfile.c_str());
|
||||||
|
|||||||
158
src/code_generators.cpp
Normal file
158
src/code_generators.cpp
Normal file
@@ -0,0 +1,158 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2016 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 "flatbuffers/code_generators.h"
|
||||||
|
#include <assert.h>
|
||||||
|
#include "flatbuffers/util.h"
|
||||||
|
|
||||||
|
namespace flatbuffers {
|
||||||
|
|
||||||
|
void CodeWriter::operator+=(std::string text) {
|
||||||
|
|
||||||
|
while (true) {
|
||||||
|
auto begin = text.find("{{");
|
||||||
|
if (begin == std::string::npos) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto end = text.find("}}");
|
||||||
|
if (end == std::string::npos || end < begin) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Write all the text before the first {{ into the stream.
|
||||||
|
stream_.write(text.c_str(), begin);
|
||||||
|
|
||||||
|
// The key is between the {{ and }}.
|
||||||
|
const std::string key = text.substr(begin + 2, end - begin - 2);
|
||||||
|
|
||||||
|
// Find the value associated with the key. If it exists, write the
|
||||||
|
// value into the stream, otherwise write the key itself into the stream.
|
||||||
|
auto iter = value_map_.find(key);
|
||||||
|
if (iter != value_map_.end()) {
|
||||||
|
const std::string &value = iter->second;
|
||||||
|
stream_ << value;
|
||||||
|
} else {
|
||||||
|
assert(false && "could not find key");
|
||||||
|
stream_ << key;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update the text to everything after the }}.
|
||||||
|
text = text.substr(end + 2);
|
||||||
|
}
|
||||||
|
if (!text.empty() && text.back() == '\\') {
|
||||||
|
text.pop_back();
|
||||||
|
stream_ << text;
|
||||||
|
} else {
|
||||||
|
stream_ << text << std::endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const char *BaseGenerator::FlatBuffersGeneratedWarning() {
|
||||||
|
return "automatically generated by the FlatBuffers compiler,"
|
||||||
|
" do not modify\n\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string BaseGenerator::NamespaceDir(const Parser &parser,
|
||||||
|
const std::string &path,
|
||||||
|
const Namespace &ns) {
|
||||||
|
EnsureDirExists(path.c_str());
|
||||||
|
if (parser.opts.one_file) return path;
|
||||||
|
std::string namespace_dir = path; // Either empty or ends in separator.
|
||||||
|
auto &namespaces = ns.components;
|
||||||
|
for (auto it = namespaces.begin(); it != namespaces.end(); ++it) {
|
||||||
|
namespace_dir += *it + kPathSeparator;
|
||||||
|
EnsureDirExists(namespace_dir.c_str());
|
||||||
|
}
|
||||||
|
return namespace_dir;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string BaseGenerator::NamespaceDir(const Namespace &ns) const {
|
||||||
|
return BaseGenerator::NamespaceDir(parser_, path_, ns);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool BaseGenerator::IsEverythingGenerated() const {
|
||||||
|
for (auto it = parser_.enums_.vec.begin(); it != parser_.enums_.vec.end();
|
||||||
|
++it) {
|
||||||
|
if (!(*it)->generated) return false;
|
||||||
|
}
|
||||||
|
for (auto it = parser_.structs_.vec.begin();
|
||||||
|
it != parser_.structs_.vec.end(); ++it) {
|
||||||
|
if (!(*it)->generated) return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string BaseGenerator::FullNamespace(const char *separator,
|
||||||
|
const Namespace &ns) {
|
||||||
|
std::string namespace_name;
|
||||||
|
auto &namespaces = ns.components;
|
||||||
|
for (auto it = namespaces.begin(); it != namespaces.end(); ++it) {
|
||||||
|
if (namespace_name.length()) namespace_name += separator;
|
||||||
|
namespace_name += *it;
|
||||||
|
}
|
||||||
|
return namespace_name;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string BaseGenerator::LastNamespacePart(const Namespace &ns) {
|
||||||
|
if (!ns.components.empty())
|
||||||
|
return ns.components.back();
|
||||||
|
else
|
||||||
|
return std::string("");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Ensure that a type is prefixed with its namespace whenever it is used
|
||||||
|
// outside of its namespace.
|
||||||
|
std::string BaseGenerator::WrapInNameSpace(const Namespace *ns,
|
||||||
|
const std::string &name) const {
|
||||||
|
if (CurrentNameSpace() == ns) return name;
|
||||||
|
std::string qualified_name = qualifying_start_;
|
||||||
|
for (auto it = ns->components.begin(); it != ns->components.end(); ++it)
|
||||||
|
qualified_name += *it + qualifying_separator_;
|
||||||
|
return qualified_name + name;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
std::string BaseGenerator::WrapInNameSpace(const Definition &def) const {
|
||||||
|
return WrapInNameSpace(def.defined_namespace, def.name);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Generate a documentation comment, if available.
|
||||||
|
void GenComment(const std::vector<std::string> &dc, std::string *code_ptr,
|
||||||
|
const CommentConfig *config, const char *prefix) {
|
||||||
|
if (dc.begin() == dc.end()) {
|
||||||
|
// Don't output empty comment blocks with 0 lines of comment content.
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string &code = *code_ptr;
|
||||||
|
if (config != nullptr && config->first_line != nullptr) {
|
||||||
|
code += std::string(prefix) + std::string(config->first_line) + "\n";
|
||||||
|
}
|
||||||
|
std::string line_prefix = std::string(prefix) +
|
||||||
|
((config != nullptr && config->content_line_prefix != nullptr) ?
|
||||||
|
config->content_line_prefix : "///");
|
||||||
|
for (auto it = dc.begin();
|
||||||
|
it != dc.end();
|
||||||
|
++it) {
|
||||||
|
code += line_prefix + *it + "\n";
|
||||||
|
}
|
||||||
|
if (config != nullptr && config->last_line != nullptr) {
|
||||||
|
code += std::string(prefix) + std::string(config->last_line) + "\n";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace flatbuffers
|
||||||
310
src/flatc.cpp
310
src/flatc.cpp
@@ -14,138 +14,121 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "flatbuffers/flatbuffers.h"
|
#include "flatbuffers/flatc.h"
|
||||||
#include "flatbuffers/idl.h"
|
|
||||||
#include "flatbuffers/util.h"
|
|
||||||
#include <limits>
|
|
||||||
|
|
||||||
#define FLATC_VERSION "1.3.0 (" __DATE__ ")"
|
#define FLATC_VERSION "1.6.0 (" __DATE__ ")"
|
||||||
|
|
||||||
static void Error(const std::string &err, bool usage = false,
|
namespace flatbuffers {
|
||||||
bool show_exe_name = true);
|
|
||||||
|
|
||||||
// This struct allows us to create a table of all possible output generators
|
void FlatCompiler::ParseFile(
|
||||||
// for the various programming languages and formats we support.
|
flatbuffers::Parser &parser,
|
||||||
struct Generator {
|
const std::string &filename,
|
||||||
bool (*generate)(const flatbuffers::Parser &parser,
|
const std::string &contents,
|
||||||
const std::string &path,
|
std::vector<const char *> &include_directories) const {
|
||||||
const std::string &file_name);
|
auto local_include_directory = flatbuffers::StripFileName(filename);
|
||||||
const char *generator_opt_short;
|
include_directories.push_back(local_include_directory.c_str());
|
||||||
const char *generator_opt_long;
|
include_directories.push_back(nullptr);
|
||||||
const char *lang_name;
|
if (!parser.Parse(contents.c_str(), &include_directories[0],
|
||||||
flatbuffers::IDLOptions::Language lang;
|
filename.c_str()))
|
||||||
const char *generator_help;
|
Error(parser.error_, false, false);
|
||||||
|
include_directories.pop_back();
|
||||||
|
include_directories.pop_back();
|
||||||
|
}
|
||||||
|
|
||||||
std::string (*make_rule)(const flatbuffers::Parser &parser,
|
void FlatCompiler::Warn(const std::string &warn, bool show_exe_name) const {
|
||||||
const std::string &path,
|
params_.warn_fn(this, warn, show_exe_name);
|
||||||
const std::string &file_name);
|
}
|
||||||
};
|
|
||||||
|
|
||||||
const Generator generators[] = {
|
void FlatCompiler::Error(const std::string &err, bool usage,
|
||||||
{ flatbuffers::GenerateBinary, "-b", "--binary", "binary",
|
bool show_exe_name) const {
|
||||||
flatbuffers::IDLOptions::kMAX,
|
params_.error_fn(this, err, usage, show_exe_name);
|
||||||
"Generate wire format binaries for any data definitions",
|
}
|
||||||
flatbuffers::BinaryMakeRule },
|
|
||||||
{ flatbuffers::GenerateTextFile, "-t", "--json", "text",
|
|
||||||
flatbuffers::IDLOptions::kMAX,
|
|
||||||
"Generate text output for any data definitions",
|
|
||||||
flatbuffers::TextMakeRule },
|
|
||||||
{ flatbuffers::GenerateCPP, "-c", "--cpp", "C++",
|
|
||||||
flatbuffers::IDLOptions::kMAX,
|
|
||||||
"Generate C++ headers for tables/structs",
|
|
||||||
flatbuffers::CPPMakeRule },
|
|
||||||
{ flatbuffers::GenerateGo, "-g", "--go", "Go",
|
|
||||||
flatbuffers::IDLOptions::kGo,
|
|
||||||
"Generate Go files for tables/structs",
|
|
||||||
flatbuffers::GeneralMakeRule },
|
|
||||||
{ flatbuffers::GenerateGeneral, "-j", "--java", "Java",
|
|
||||||
flatbuffers::IDLOptions::kJava,
|
|
||||||
"Generate Java classes for tables/structs",
|
|
||||||
flatbuffers::GeneralMakeRule },
|
|
||||||
{ flatbuffers::GenerateJS, "-s", "--js", "JavaScript",
|
|
||||||
flatbuffers::IDLOptions::kMAX,
|
|
||||||
"Generate JavaScript code for tables/structs",
|
|
||||||
flatbuffers::JSMakeRule },
|
|
||||||
{ flatbuffers::GenerateGeneral, "-n", "--csharp", "C#",
|
|
||||||
flatbuffers::IDLOptions::kCSharp,
|
|
||||||
"Generate C# classes for tables/structs",
|
|
||||||
flatbuffers::GeneralMakeRule },
|
|
||||||
{ flatbuffers::GeneratePython, "-p", "--python", "Python",
|
|
||||||
flatbuffers::IDLOptions::kMAX,
|
|
||||||
"Generate Python files for tables/structs",
|
|
||||||
flatbuffers::GeneralMakeRule },
|
|
||||||
{ flatbuffers::GeneratePhp, nullptr, "--php", "PHP",
|
|
||||||
flatbuffers::IDLOptions::kMAX,
|
|
||||||
"Generate PHP files for tables/structs",
|
|
||||||
flatbuffers::GeneralMakeRule },
|
|
||||||
};
|
|
||||||
|
|
||||||
const char *program_name = nullptr;
|
std::string FlatCompiler::GetUsageString(const char* program_name) const {
|
||||||
flatbuffers::Parser *parser = nullptr;
|
std::stringstream ss;
|
||||||
|
ss << "Usageaa: " << program_name << " [OPTION]... FILE... [-- FILE...]\n";
|
||||||
|
for (size_t i = 0; i < params_.num_generators; ++i) {
|
||||||
|
const Generator& g = params_.generators[i];
|
||||||
|
|
||||||
static void Error(const std::string &err, bool usage, bool show_exe_name) {
|
std::stringstream full_name;
|
||||||
if (show_exe_name) printf("%s: ", program_name);
|
full_name << std::setw(12) << std::left << g.generator_opt_long;
|
||||||
printf("%s\n", err.c_str());
|
const char *name = g.generator_opt_short ? g.generator_opt_short : " ";
|
||||||
if (usage) {
|
const char *help = g.generator_help;
|
||||||
printf("usage: %s [OPTION]... FILE... [-- FILE...]\n", program_name);
|
|
||||||
for (size_t i = 0; i < sizeof(generators) / sizeof(generators[0]); ++i)
|
ss << " " << full_name.str() << " " << name << " " << help << ".\n";
|
||||||
printf(" %-12s %s %s.\n",
|
}
|
||||||
generators[i].generator_opt_long,
|
ss <<
|
||||||
generators[i].generator_opt_short
|
" -o PATH Prefix PATH to all generated files.\n"
|
||||||
? generators[i].generator_opt_short
|
" -I PATH Search for includes in the specified path.\n"
|
||||||
: " ",
|
" -M Print make rules for generated files.\n"
|
||||||
generators[i].generator_help);
|
" --version Print the version number of flatc and exit.\n"
|
||||||
printf(
|
" --strict-json Strict JSON: field names must be / will be quoted,\n"
|
||||||
" -o PATH Prefix PATH to all generated files.\n"
|
" no trailing commas in tables/vectors.\n"
|
||||||
" -I PATH Search for includes in the specified path.\n"
|
" --allow-non-utf8 Pass non-UTF-8 input through parser and emit nonstandard\n"
|
||||||
" -M Print make rules for generated files.\n"
|
" \\x escapes in JSON. (Default is to raise parse error on\n"
|
||||||
" --version Print the version number of flatc and exit.\n"
|
" non-UTF-8 input.)\n"
|
||||||
" --strict-json Strict JSON: field names must be / will be quoted,\n"
|
" --defaults-json Output fields whose value is the default when\n"
|
||||||
" no trailing commas in tables/vectors.\n"
|
" writing JSON\n"
|
||||||
" --defaults-json Output fields whose value is the default when\n"
|
" --unknown-json Allow fields in JSON that are not defined in the\n"
|
||||||
" writing JSON\n"
|
" schema. These fields will be discared when generating\n"
|
||||||
" --unknown-json Allow fields in JSON that are not defined in the\n"
|
" binaries.\n"
|
||||||
" schema. These fields will be discared when generating\n"
|
" --no-prefix Don\'t prefix enum values with the enum type in C++.\n"
|
||||||
" binaries.\n"
|
" --scoped-enums Use C++11 style scoped and strongly typed enums.\n"
|
||||||
" --no-prefix Don\'t prefix enum values with the enum type in C++.\n"
|
" also implies --no-prefix.\n"
|
||||||
" --scoped-enums Use C++11 style scoped and strongly typed enums.\n"
|
" --gen-includes (deprecated), this is the default behavior.\n"
|
||||||
" also implies --no-prefix.\n"
|
" If the original behavior is required (no include\n"
|
||||||
" --gen-includes (deprecated), this is the default behavior.\n"
|
" statements) use --no-includes.\n"
|
||||||
" If the original behavior is required (no include\n"
|
" --no-includes Don\'t generate include statements for included\n"
|
||||||
" statements) use --no-includes.\n"
|
" schemas the generated file depends on (C++).\n"
|
||||||
" --no-includes Don\'t generate include statements for included\n"
|
" --gen-mutable Generate accessors that can mutate buffers in-place.\n"
|
||||||
" schemas the generated file depends on (C++).\n"
|
" --gen-onefile Generate single output file for C#.\n"
|
||||||
" --gen-mutable Generate accessors that can mutate buffers in-place.\n"
|
" --gen-name-strings Generate type name functions for C++.\n"
|
||||||
" --gen-onefile Generate single output file for C#\n"
|
" --escape-proto-ids Disable appending '_' in namespaces names.\n"
|
||||||
" --raw-binary Allow binaries without file_indentifier to be read.\n"
|
" --gen-object-api Generate an additional object-based API.\n"
|
||||||
" This may crash flatc given a mismatched schema.\n"
|
" --cpp-ptr-type T Set object API pointer type (default std::unique_ptr)\n"
|
||||||
" --proto Input is a .proto, translate to .fbs.\n"
|
" --no-js-exports Removes Node.js style export lines in JS.\n"
|
||||||
" --schema Serialize schemas instead of JSON (use with -b)\n"
|
" --goog-js-export Uses goog.exports* for closure compiler exporting in JS.\n"
|
||||||
|
" --raw-binary Allow binaries without file_indentifier to be read.\n"
|
||||||
|
" This may crash flatc given a mismatched schema.\n"
|
||||||
|
" --proto Input is a .proto, translate to .fbs.\n"
|
||||||
|
" --grpc Generate GRPC interfaces for the specified languages\n"
|
||||||
|
" --schema Serialize schemas instead of JSON (use with -b)\n"
|
||||||
|
" --bfbs-comments Add doc comments to the binary schema files.\n"
|
||||||
|
" --conform FILE Specify a schema the following schemas should be\n"
|
||||||
|
" an evolution of. Gives errors if not.\n"
|
||||||
|
" --conform-includes Include path for the schema given with --conform\n"
|
||||||
|
" PATH \n"
|
||||||
|
" --include-prefix Prefix this path to any generated include statements.\n"
|
||||||
|
" PATH\n"
|
||||||
"FILEs may be schemas, or JSON files (conforming to preceding schema)\n"
|
"FILEs may be schemas, or JSON files (conforming to preceding schema)\n"
|
||||||
"FILEs after the -- must be binary flatbuffer format files.\n"
|
"FILEs after the -- must be binary flatbuffer format files.\n"
|
||||||
"Output files are named using the base file name of the input,\n"
|
"Output files are named using the base file name of the input,\n"
|
||||||
"and written to the current directory or the path given by -o.\n"
|
"and written to the current directory or the path given by -o.\n"
|
||||||
"example: %s -c -b schema1.fbs schema2.fbs data.json\n",
|
"example: " << program_name << " -c -b schema1.fbs schema2.fbs data.json\n";
|
||||||
program_name);
|
return ss.str();
|
||||||
}
|
|
||||||
if (parser) delete parser;
|
|
||||||
exit(1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, const char *argv[]) {
|
int FlatCompiler::Compile(int argc, const char** argv) {
|
||||||
program_name = argv[0];
|
if (params_.generators == nullptr || params_.num_generators == 0) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
flatbuffers::IDLOptions opts;
|
flatbuffers::IDLOptions opts;
|
||||||
std::string output_path;
|
std::string output_path;
|
||||||
const size_t num_generators = sizeof(generators) / sizeof(generators[0]);
|
|
||||||
bool generator_enabled[num_generators] = { false };
|
|
||||||
bool any_generator = false;
|
bool any_generator = false;
|
||||||
bool print_make_rules = false;
|
bool print_make_rules = false;
|
||||||
bool raw_binary = false;
|
bool raw_binary = false;
|
||||||
bool schema_binary = false;
|
bool schema_binary = false;
|
||||||
|
bool grpc_enabled = false;
|
||||||
std::vector<std::string> filenames;
|
std::vector<std::string> filenames;
|
||||||
std::vector<const char *> include_directories;
|
std::vector<const char *> include_directories;
|
||||||
|
std::vector<const char *> conform_include_directories;
|
||||||
|
std::vector<bool> generator_enabled(params_.num_generators, false);
|
||||||
size_t binary_files_from = std::numeric_limits<size_t>::max();
|
size_t binary_files_from = std::numeric_limits<size_t>::max();
|
||||||
for (int argi = 1; argi < argc; argi++) {
|
std::string conform_to_schema;
|
||||||
|
|
||||||
|
for (int argi = 0; argi < argc; argi++) {
|
||||||
std::string arg = argv[argi];
|
std::string arg = argv[argi];
|
||||||
if (arg[0] == '-') {
|
if (arg[0] == '-') {
|
||||||
if (filenames.size() && arg[1] != '-')
|
if (filenames.size() && arg[1] != '-')
|
||||||
@@ -156,10 +139,25 @@ int main(int argc, const char *argv[]) {
|
|||||||
} else if(arg == "-I") {
|
} else if(arg == "-I") {
|
||||||
if (++argi >= argc) Error("missing path following" + arg, true);
|
if (++argi >= argc) Error("missing path following" + arg, true);
|
||||||
include_directories.push_back(argv[argi]);
|
include_directories.push_back(argv[argi]);
|
||||||
|
} else if(arg == "--conform") {
|
||||||
|
if (++argi >= argc) Error("missing path following" + arg, true);
|
||||||
|
conform_to_schema = argv[argi];
|
||||||
|
} else if (arg == "--conform-includes") {
|
||||||
|
if (++argi >= argc) Error("missing path following" + arg, true);
|
||||||
|
conform_include_directories.push_back(argv[argi]);
|
||||||
|
} else if (arg == "--include-prefix") {
|
||||||
|
if (++argi >= argc) Error("missing path following" + arg, true);
|
||||||
|
opts.include_prefix = argv[argi];
|
||||||
|
if (opts.include_prefix.back() != '/' &&
|
||||||
|
opts.include_prefix.back() != '\\') opts.include_prefix += "/";
|
||||||
} else if(arg == "--strict-json") {
|
} else if(arg == "--strict-json") {
|
||||||
opts.strict_json = true;
|
opts.strict_json = true;
|
||||||
|
} else if(arg == "--allow-non-utf8") {
|
||||||
|
opts.allow_non_utf8 = true;
|
||||||
} else if(arg == "--no-js-exports") {
|
} else if(arg == "--no-js-exports") {
|
||||||
opts.skip_js_exports = true;
|
opts.skip_js_exports = true;
|
||||||
|
} else if(arg == "--goog-js-export") {
|
||||||
|
opts.use_goog_js_export_format = true;
|
||||||
} else if(arg == "--defaults-json") {
|
} else if(arg == "--defaults-json") {
|
||||||
opts.output_default_scalars_in_json = true;
|
opts.output_default_scalars_in_json = true;
|
||||||
} else if (arg == "--unknown-json") {
|
} else if (arg == "--unknown-json") {
|
||||||
@@ -169,8 +167,17 @@ int main(int argc, const char *argv[]) {
|
|||||||
} else if(arg == "--scoped-enums") {
|
} else if(arg == "--scoped-enums") {
|
||||||
opts.prefixed_enums = false;
|
opts.prefixed_enums = false;
|
||||||
opts.scoped_enums = true;
|
opts.scoped_enums = true;
|
||||||
|
} else if (arg == "--no-union-value-namespacing") {
|
||||||
|
opts.union_value_namespacing = false;
|
||||||
} else if(arg == "--gen-mutable") {
|
} else if(arg == "--gen-mutable") {
|
||||||
opts.mutable_buffer = true;
|
opts.mutable_buffer = true;
|
||||||
|
} else if(arg == "--gen-name-strings") {
|
||||||
|
opts.generate_name_strings = true;
|
||||||
|
} else if(arg == "--gen-object-api") {
|
||||||
|
opts.generate_object_based_api = true;
|
||||||
|
} else if (arg == "--cpp-ptr-type") {
|
||||||
|
if (++argi >= argc) Error("missing type following" + arg, true);
|
||||||
|
opts.cpp_object_api_pointer_type = argv[argi];
|
||||||
} else if(arg == "--gen-all") {
|
} else if(arg == "--gen-all") {
|
||||||
opts.generate_all = true;
|
opts.generate_all = true;
|
||||||
opts.include_dependence_headers = false;
|
opts.include_dependence_headers = false;
|
||||||
@@ -187,6 +194,8 @@ int main(int argc, const char *argv[]) {
|
|||||||
binary_files_from = filenames.size();
|
binary_files_from = filenames.size();
|
||||||
} else if(arg == "--proto") {
|
} else if(arg == "--proto") {
|
||||||
opts.proto_mode = true;
|
opts.proto_mode = true;
|
||||||
|
} else if(arg == "--escape-proto-ids") {
|
||||||
|
opts.escape_proto_identifiers = true;
|
||||||
} else if(arg == "--schema") {
|
} else if(arg == "--schema") {
|
||||||
schema_binary = true;
|
schema_binary = true;
|
||||||
} else if(arg == "-M") {
|
} else if(arg == "-M") {
|
||||||
@@ -194,17 +203,22 @@ int main(int argc, const char *argv[]) {
|
|||||||
} else if(arg == "--version") {
|
} else if(arg == "--version") {
|
||||||
printf("flatc version %s\n", FLATC_VERSION);
|
printf("flatc version %s\n", FLATC_VERSION);
|
||||||
exit(0);
|
exit(0);
|
||||||
|
} else if(arg == "--grpc") {
|
||||||
|
grpc_enabled = true;
|
||||||
|
} else if(arg == "--bfbs-comments") {
|
||||||
|
opts.binary_schema_comments = true;
|
||||||
} else {
|
} else {
|
||||||
for (size_t i = 0; i < num_generators; ++i) {
|
for (size_t i = 0; i < params_.num_generators; ++i) {
|
||||||
if (arg == generators[i].generator_opt_long ||
|
if (arg == params_.generators[i].generator_opt_long ||
|
||||||
(generators[i].generator_opt_short &&
|
(params_.generators[i].generator_opt_short &&
|
||||||
arg == generators[i].generator_opt_short)) {
|
arg == params_.generators[i].generator_opt_short)) {
|
||||||
generator_enabled[i] = true;
|
generator_enabled[i] = true;
|
||||||
any_generator = true;
|
any_generator = true;
|
||||||
|
opts.lang_to_generate |= params_.generators[i].lang;
|
||||||
goto found;
|
goto found;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Error("unknown commandline argument" + arg, true);
|
Error("unknown commandline argument: " + arg, true);
|
||||||
found:;
|
found:;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@@ -217,12 +231,21 @@ int main(int argc, const char *argv[]) {
|
|||||||
if (opts.proto_mode) {
|
if (opts.proto_mode) {
|
||||||
if (any_generator)
|
if (any_generator)
|
||||||
Error("cannot generate code directly from .proto files", true);
|
Error("cannot generate code directly from .proto files", true);
|
||||||
} else if (!any_generator) {
|
} else if (!any_generator && conform_to_schema.empty()) {
|
||||||
Error("no options: specify at least one generator.", true);
|
Error("no options: specify at least one generator.", true);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Now process the files:
|
flatbuffers::Parser conform_parser;
|
||||||
parser = new flatbuffers::Parser(opts);
|
if (!conform_to_schema.empty()) {
|
||||||
|
std::string contents;
|
||||||
|
if (!flatbuffers::LoadFile(conform_to_schema.c_str(), true, &contents))
|
||||||
|
Error("unable to load schema: " + conform_to_schema);
|
||||||
|
ParseFile(conform_parser, conform_to_schema, contents,
|
||||||
|
conform_include_directories);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::unique_ptr<flatbuffers::Parser> parser(new flatbuffers::Parser(opts));
|
||||||
|
|
||||||
for (auto file_it = filenames.begin();
|
for (auto file_it = filenames.begin();
|
||||||
file_it != filenames.end();
|
file_it != filenames.end();
|
||||||
++file_it) {
|
++file_it) {
|
||||||
@@ -249,7 +272,7 @@ int main(int argc, const char *argv[]) {
|
|||||||
"\" matches the schema, use --raw-binary to read this file"
|
"\" matches the schema, use --raw-binary to read this file"
|
||||||
" anyway.");
|
" anyway.");
|
||||||
} else if (!flatbuffers::BufferHasIdentifier(contents.c_str(),
|
} else if (!flatbuffers::BufferHasIdentifier(contents.c_str(),
|
||||||
parser->file_identifier_.c_str())) {
|
parser->file_identifier_.c_str())) {
|
||||||
Error("binary \"" +
|
Error("binary \"" +
|
||||||
*file_it +
|
*file_it +
|
||||||
"\" does not have expected file_identifier \"" +
|
"\" does not have expected file_identifier \"" +
|
||||||
@@ -262,58 +285,67 @@ int main(int argc, const char *argv[]) {
|
|||||||
if (contents.length() != strlen(contents.c_str())) {
|
if (contents.length() != strlen(contents.c_str())) {
|
||||||
Error("input file appears to be binary: " + *file_it, true);
|
Error("input file appears to be binary: " + *file_it, true);
|
||||||
}
|
}
|
||||||
if (flatbuffers::GetExtension(*file_it) == "fbs") {
|
auto is_schema = flatbuffers::GetExtension(*file_it) == "fbs";
|
||||||
|
if (is_schema) {
|
||||||
// If we're processing multiple schemas, make sure to start each
|
// If we're processing multiple schemas, make sure to start each
|
||||||
// one from scratch. If it depends on previous schemas it must do
|
// one from scratch. If it depends on previous schemas it must do
|
||||||
// so explicitly using an include.
|
// so explicitly using an include.
|
||||||
delete parser;
|
parser.reset(new flatbuffers::Parser(opts));
|
||||||
parser = new flatbuffers::Parser(opts);
|
}
|
||||||
|
ParseFile(*parser.get(), *file_it, contents, include_directories);
|
||||||
|
if (is_schema && !conform_to_schema.empty()) {
|
||||||
|
auto err = parser->ConformTo(conform_parser);
|
||||||
|
if (!err.empty()) Error("schemas don\'t conform: " + err);
|
||||||
}
|
}
|
||||||
auto local_include_directory = flatbuffers::StripFileName(*file_it);
|
|
||||||
include_directories.push_back(local_include_directory.c_str());
|
|
||||||
include_directories.push_back(nullptr);
|
|
||||||
if (!parser->Parse(contents.c_str(), &include_directories[0],
|
|
||||||
file_it->c_str()))
|
|
||||||
Error(parser->error_, false, false);
|
|
||||||
if (schema_binary) {
|
if (schema_binary) {
|
||||||
parser->Serialize();
|
parser->Serialize();
|
||||||
parser->file_extension_ = reflection::SchemaExtension();
|
parser->file_extension_ = reflection::SchemaExtension();
|
||||||
}
|
}
|
||||||
include_directories.pop_back();
|
|
||||||
include_directories.pop_back();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string filebase = flatbuffers::StripPath(
|
std::string filebase = flatbuffers::StripPath(
|
||||||
flatbuffers::StripExtension(*file_it));
|
flatbuffers::StripExtension(*file_it));
|
||||||
|
|
||||||
for (size_t i = 0; i < num_generators; ++i) {
|
for (size_t i = 0; i < params_.num_generators; ++i) {
|
||||||
parser->opts.lang = generators[i].lang;
|
parser->opts.lang = params_.generators[i].lang;
|
||||||
if (generator_enabled[i]) {
|
if (generator_enabled[i]) {
|
||||||
if (!print_make_rules) {
|
if (!print_make_rules) {
|
||||||
flatbuffers::EnsureDirExists(output_path);
|
flatbuffers::EnsureDirExists(output_path);
|
||||||
if (!generators[i].generate(*parser, output_path, filebase)) {
|
if (!params_.generators[i].generate(*parser.get(), output_path, filebase)) {
|
||||||
Error(std::string("Unable to generate ") +
|
Error(std::string("Unable to generate ") +
|
||||||
generators[i].lang_name +
|
params_.generators[i].lang_name +
|
||||||
" for " +
|
" for " +
|
||||||
filebase);
|
filebase);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
std::string make_rule = generators[i].make_rule(
|
std::string make_rule = params_.generators[i].make_rule(
|
||||||
*parser, output_path, *file_it);
|
*parser.get(), output_path, *file_it);
|
||||||
if (!make_rule.empty())
|
if (!make_rule.empty())
|
||||||
printf("%s\n", flatbuffers::WordWrap(
|
printf("%s\n", flatbuffers::WordWrap(
|
||||||
make_rule, 80, " ", " \\").c_str());
|
make_rule, 80, " ", " \\").c_str());
|
||||||
}
|
}
|
||||||
|
if (grpc_enabled) {
|
||||||
|
if (params_.generators[i].generateGRPC != nullptr) {
|
||||||
|
if (!params_.generators[i].generateGRPC(*parser.get(), output_path,
|
||||||
|
filebase)) {
|
||||||
|
Error(std::string("Unable to generate GRPC interface for") +
|
||||||
|
params_.generators[i].lang_name);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Warn(std::string("GRPC interface generator not implemented for ")
|
||||||
|
+ params_.generators[i].lang_name);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (opts.proto_mode) GenerateFBS(*parser, output_path, filebase);
|
if (opts.proto_mode) GenerateFBS(*parser.get(), output_path, filebase);
|
||||||
|
|
||||||
// We do not want to generate code for the definitions in this file
|
// We do not want to generate code for the definitions in this file
|
||||||
// in any files coming up next.
|
// in any files coming up next.
|
||||||
parser->MarkGenerated();
|
parser->MarkGenerated();
|
||||||
}
|
}
|
||||||
|
|
||||||
delete parser;
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} // namespace flatbuffers
|
||||||
|
|||||||
104
src/flatc_main.cpp
Normal file
104
src/flatc_main.cpp
Normal file
@@ -0,0 +1,104 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2017 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 "flatbuffers/flatc.h"
|
||||||
|
|
||||||
|
static const char *g_program_name = nullptr;
|
||||||
|
|
||||||
|
static void Warn(const flatbuffers::FlatCompiler *flatc,
|
||||||
|
const std::string &warn,
|
||||||
|
bool show_exe_name) {
|
||||||
|
(void)flatc;
|
||||||
|
if (show_exe_name) {
|
||||||
|
printf("%s: ", g_program_name);
|
||||||
|
}
|
||||||
|
printf("warning: %s\n", warn.c_str());
|
||||||
|
}
|
||||||
|
|
||||||
|
static void Error(const flatbuffers::FlatCompiler *flatc,
|
||||||
|
const std::string &err,
|
||||||
|
bool usage,
|
||||||
|
bool show_exe_name) {
|
||||||
|
if (show_exe_name) {
|
||||||
|
printf("%s: ", g_program_name);
|
||||||
|
}
|
||||||
|
printf("error: %s\n", err.c_str());
|
||||||
|
if (usage) {
|
||||||
|
printf("%s", flatc->GetUsageString(g_program_name).c_str());
|
||||||
|
}
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(int argc, const char *argv[]) {
|
||||||
|
g_program_name = argv[0];
|
||||||
|
|
||||||
|
const flatbuffers::FlatCompiler::Generator generators[] = {
|
||||||
|
{ flatbuffers::GenerateBinary, "-b", "--binary", "binary",
|
||||||
|
nullptr,
|
||||||
|
flatbuffers::IDLOptions::kBinary,
|
||||||
|
"Generate wire format binaries for any data definitions",
|
||||||
|
flatbuffers::BinaryMakeRule },
|
||||||
|
{ flatbuffers::GenerateTextFile, "-t", "--json", "text",
|
||||||
|
nullptr,
|
||||||
|
flatbuffers::IDLOptions::kJson,
|
||||||
|
"Generate text output for any data definitions",
|
||||||
|
flatbuffers::TextMakeRule },
|
||||||
|
{ flatbuffers::GenerateCPP, "-c", "--cpp", "C++",
|
||||||
|
flatbuffers::GenerateCppGRPC,
|
||||||
|
flatbuffers::IDLOptions::kCpp,
|
||||||
|
"Generate C++ headers for tables/structs",
|
||||||
|
flatbuffers::CPPMakeRule },
|
||||||
|
{ flatbuffers::GenerateGo, "-g", "--go", "Go",
|
||||||
|
flatbuffers::GenerateGoGRPC,
|
||||||
|
flatbuffers::IDLOptions::kGo,
|
||||||
|
"Generate Go files for tables/structs",
|
||||||
|
flatbuffers::GeneralMakeRule },
|
||||||
|
{ flatbuffers::GenerateGeneral, "-j", "--java", "Java",
|
||||||
|
nullptr,
|
||||||
|
flatbuffers::IDLOptions::kJava,
|
||||||
|
"Generate Java classes for tables/structs",
|
||||||
|
flatbuffers::GeneralMakeRule },
|
||||||
|
{ flatbuffers::GenerateJS, "-s", "--js", "JavaScript",
|
||||||
|
nullptr,
|
||||||
|
flatbuffers::IDLOptions::kJs,
|
||||||
|
"Generate JavaScript code for tables/structs",
|
||||||
|
flatbuffers::JSMakeRule },
|
||||||
|
{ flatbuffers::GenerateGeneral, "-n", "--csharp", "C#",
|
||||||
|
nullptr,
|
||||||
|
flatbuffers::IDLOptions::kCSharp,
|
||||||
|
"Generate C# classes for tables/structs",
|
||||||
|
flatbuffers::GeneralMakeRule },
|
||||||
|
{ flatbuffers::GeneratePython, "-p", "--python", "Python",
|
||||||
|
nullptr,
|
||||||
|
flatbuffers::IDLOptions::kPython,
|
||||||
|
"Generate Python files for tables/structs",
|
||||||
|
flatbuffers::GeneralMakeRule },
|
||||||
|
{ flatbuffers::GeneratePhp, nullptr, "--php", "PHP",
|
||||||
|
nullptr,
|
||||||
|
flatbuffers::IDLOptions::kPhp,
|
||||||
|
"Generate PHP files for tables/structs",
|
||||||
|
flatbuffers::GeneralMakeRule },
|
||||||
|
};
|
||||||
|
|
||||||
|
flatbuffers::FlatCompiler::InitParams params;
|
||||||
|
params.generators = generators;
|
||||||
|
params.num_generators = sizeof(generators) / sizeof(generators[0]);
|
||||||
|
params.warn_fn = Warn;
|
||||||
|
params.error_fn = Error;
|
||||||
|
|
||||||
|
flatbuffers::FlatCompiler flatc(params);
|
||||||
|
return flatc.Compile(argc - 1, argv + 1);
|
||||||
|
}
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user