Compare commits
813 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
06c5c7ed0b | ||
|
|
b190ce11b0 | ||
|
|
bf5d23230a | ||
|
|
ce382d6dd3 | ||
|
|
41d9add7ef | ||
|
|
6a87427540 | ||
|
|
694add668b | ||
|
|
7edf8c9084 | ||
|
|
b86387442e | ||
|
|
e2eb5ee670 | ||
|
|
994502b6dd | ||
|
|
fa41e83679 | ||
|
|
799cc8f7b9 | ||
|
|
b7eb441470 | ||
|
|
8d01c5859c | ||
|
|
237e8b71fe | ||
|
|
eeb8fd60d5 | ||
|
|
fef2ffc4d0 | ||
|
|
8367664f15 | ||
|
|
d6f06c33f7 | ||
|
|
627e8bf364 | ||
|
|
883c42b7db | ||
|
|
7aae0af305 | ||
|
|
b057aa917f | ||
|
|
f1b26ff7fb | ||
|
|
9610a666b1 | ||
|
|
1e0f75a647 | ||
|
|
82b75407a3 | ||
|
|
f7c511957f | ||
|
|
a66de58af9 | ||
|
|
a3508f36d5 | ||
|
|
137fec7164 | ||
|
|
214125e417 | ||
|
|
44a7dc9995 | ||
|
|
3cc2daa78f | ||
|
|
fa1174aa7b | ||
|
|
83d4e2a100 | ||
|
|
8a09f3fb0b | ||
|
|
9dbe819efd | ||
|
|
67c4149588 | ||
|
|
8b8c7dbdfc | ||
|
|
2ee20a5f3d | ||
|
|
4be605604e | ||
|
|
fc5d86f1e7 | ||
|
|
9dce287adb | ||
|
|
7798be3bb6 | ||
|
|
966362e074 | ||
|
|
a89c279ed6 | ||
|
|
a212b3c036 | ||
|
|
9230f600d7 | ||
|
|
c793621567 | ||
|
|
ee2ced236d | ||
|
|
468c00a3fe | ||
|
|
47c757f714 | ||
|
|
9a5ff89003 | ||
|
|
950444a343 | ||
|
|
30d76198c7 | ||
|
|
cce3a66f0d | ||
|
|
8d1cc6ac7d | ||
|
|
5b207639a1 | ||
|
|
359e0f9d66 | ||
|
|
ebbed05137 | ||
|
|
aa395e5a59 | ||
|
|
32328075d8 | ||
|
|
97e89c5acd | ||
|
|
5f6672be44 | ||
|
|
28e858c855 | ||
|
|
987bebe678 | ||
|
|
ec0129369c | ||
|
|
50dd385b30 | ||
|
|
da702cfd8f | ||
|
|
6e2791640e | ||
|
|
52fce5e532 | ||
|
|
b7f13cd8e8 | ||
|
|
e42985e5aa | ||
|
|
0a80646371 | ||
|
|
b9eea76a86 | ||
|
|
1b90300150 | ||
|
|
83a43fc797 | ||
|
|
5f01376027 | ||
|
|
9a1913a87a | ||
|
|
b4647beb8f | ||
|
|
d6060977ad | ||
|
|
987aa5b5ee | ||
|
|
42acdb63c3 | ||
|
|
0cc1aeb8ca | ||
|
|
ba6c671705 | ||
|
|
d2f33fc454 | ||
|
|
0d1b72cbc2 | ||
|
|
9fce2fbf2a | ||
|
|
a18ea40d6a | ||
|
|
090caa2809 | ||
|
|
49e1ea3335 | ||
|
|
11a1988705 | ||
|
|
967df08b1d | ||
|
|
9aa08a429e | ||
|
|
9e8c758f54 | ||
|
|
74a25536be | ||
|
|
12917af8a2 | ||
|
|
1ea2472f7a | ||
|
|
0fe13cb28c | ||
|
|
385dddc66a | ||
|
|
750dde7669 | ||
|
|
9917a168cd | ||
|
|
76d3cca19c | ||
|
|
c86e6d0e30 | ||
|
|
d34dc32c20 | ||
|
|
234d86c92a | ||
|
|
746c73b910 | ||
|
|
0bbfd4b2e3 | ||
|
|
7165219535 | ||
|
|
a45f564cf1 | ||
|
|
9d45a64036 | ||
|
|
ccfb4c20bf | ||
|
|
7bcd857b87 | ||
|
|
23c8ab34c1 | ||
|
|
70002dc5ca | ||
|
|
6e0e79f24f | ||
|
|
b856368d75 | ||
|
|
e37156a305 | ||
|
|
a10b0e5464 | ||
|
|
275b739944 | ||
|
|
9d1ce9a100 | ||
|
|
79afe6c3d2 | ||
|
|
c6dbb22300 | ||
|
|
18bacd3ea5 | ||
|
|
a2c913aec3 | ||
|
|
67b33b2942 | ||
|
|
7b5fd2bd05 | ||
|
|
7181d77700 | ||
|
|
7f663b1204 | ||
|
|
173ebb6944 | ||
|
|
d658239484 | ||
|
|
ab4bf59e8c | ||
|
|
eee44bbb26 | ||
|
|
a63fa51a15 | ||
|
|
2049e52101 | ||
|
|
832c618f5f | ||
|
|
14615699fa | ||
|
|
20aad0c41e | ||
|
|
f083b33f2a | ||
|
|
bf17df346e | ||
|
|
35281dedb5 | ||
|
|
c9651b7420 | ||
|
|
26c3b3adab | ||
|
|
da6e1b9856 | ||
|
|
ad27d751e3 | ||
|
|
0aab623cb1 | ||
|
|
6a446bdd83 | ||
|
|
21fb5cbbc9 | ||
|
|
0da6f94867 | ||
|
|
59e9713081 | ||
|
|
40866a8927 | ||
|
|
b71d968fad | ||
|
|
fac0d7be02 | ||
|
|
6c5603fd98 | ||
|
|
2d21853a7e | ||
|
|
fec1a8d015 | ||
|
|
7fd8576233 | ||
|
|
a4cb1599d8 | ||
|
|
ae4ce72651 | ||
|
|
e2be0c0b06 | ||
|
|
2ad408697f | ||
|
|
4213d91054 | ||
|
|
5a13f622cf | ||
|
|
23a7e4e0b0 | ||
|
|
eeb49c2757 | ||
|
|
824763b316 | ||
|
|
d3aeee32bb | ||
|
|
0bceba24db | ||
|
|
b8c77d4041 | ||
|
|
8468eab83b | ||
|
|
2b2e8d4aec | ||
|
|
b80b32bfaf | ||
|
|
e5f331db99 | ||
|
|
2f84c60385 | ||
|
|
d648396515 | ||
|
|
777e78d8dd | ||
|
|
4016c549d3 | ||
|
|
40827b21b2 | ||
|
|
65a10b6e32 | ||
|
|
8db2fef3f7 | ||
|
|
9ed1323044 | ||
|
|
1a4c405662 | ||
|
|
318594e4b4 | ||
|
|
3d903302c3 | ||
|
|
c9571d9897 | ||
|
|
3694b830a2 | ||
|
|
0471fa807c | ||
|
|
914344ea9b | ||
|
|
b40266c56f | ||
|
|
8a9303d464 | ||
|
|
30c4bf47f9 | ||
|
|
46ce45601b | ||
|
|
433312c55a | ||
|
|
9c52ec3744 | ||
|
|
70e2f49bff | ||
|
|
5ac0367ed3 | ||
|
|
5d101afb52 | ||
|
|
06f4af11b6 | ||
|
|
57e338f819 | ||
|
|
615616cb55 | ||
|
|
3413c33004 | ||
|
|
69f5660a44 | ||
|
|
d5add9fca5 | ||
|
|
15df50eb7f | ||
|
|
a94132a45f | ||
|
|
48befb6bef | ||
|
|
b300691336 | ||
|
|
faadbc10ea | ||
|
|
ed6ae8d322 | ||
|
|
e910bddbcc | ||
|
|
c85fb690f4 | ||
|
|
c1daa6ba0c | ||
|
|
4c71c7b023 | ||
|
|
f5664d33fb | ||
|
|
39c8a19ce2 | ||
|
|
826193ff68 | ||
|
|
fd0d1ed929 | ||
|
|
424988f308 | ||
|
|
b2550dbaa9 | ||
|
|
a2b238960f | ||
|
|
619b784374 | ||
|
|
68a7661546 | ||
|
|
7dac9961f0 | ||
|
|
c65c389c6d | ||
|
|
6446dcf3d6 | ||
|
|
e090d8da17 | ||
|
|
bc901436db | ||
|
|
240be9b5ae | ||
|
|
bc366a7f9e | ||
|
|
14b19d446f | ||
|
|
9e6f17b94d | ||
|
|
c3801ad375 | ||
|
|
4f3b24db09 | ||
|
|
1d294a31b8 | ||
|
|
dd8fccfb1b | ||
|
|
7089c9ecdd | ||
|
|
43203984f7 | ||
|
|
5993338ee3 | ||
|
|
19920db39f | ||
|
|
dbbaeac85c | ||
|
|
028f0fde62 | ||
|
|
87343631b9 | ||
|
|
1fbfaf5c5e | ||
|
|
4421375bb6 | ||
|
|
162ad7a37e | ||
|
|
a0a6c3f8c6 | ||
|
|
a2d38fbb98 | ||
|
|
9ef1524d3f | ||
|
|
0c9de0352a | ||
|
|
a783bc9267 | ||
|
|
aff818cebf | ||
|
|
d7b75417fc | ||
|
|
a42e898979 | ||
|
|
96cc2f3ee3 | ||
|
|
3250a1f8dd | ||
|
|
ace4a37f22 | ||
|
|
f28c2b2936 | ||
|
|
96f3cf690f | ||
|
|
b3edfdbfb7 | ||
|
|
b8aaccee82 | ||
|
|
2dc8ae7742 | ||
|
|
5b0d491127 | ||
|
|
d8b7041d7e | ||
|
|
5a0c3366c3 | ||
|
|
f8148b8dad | ||
|
|
a22b1b6267 | ||
|
|
4264daadd2 | ||
|
|
3cbc120a08 | ||
|
|
8dcd2682c7 | ||
|
|
b78002ff3e | ||
|
|
c555ee8fac | ||
|
|
b92bb0584d | ||
|
|
956d11569e | ||
|
|
e367ca32ad | ||
|
|
705f27f6ee | ||
|
|
5fc87f4c4b | ||
|
|
11749095a1 | ||
|
|
d0cede9c90 | ||
|
|
fcc2bee0b6 | ||
|
|
e08da4dea2 | ||
|
|
18538c401c | ||
|
|
e57f4ab2d2 | ||
|
|
deed68db5d | ||
|
|
061d61f3f8 | ||
|
|
cffe0c4546 | ||
|
|
fadd40e402 | ||
|
|
e47dc0e465 | ||
|
|
5c54754790 | ||
|
|
4f7f6dc301 | ||
|
|
0fadaf391d | ||
|
|
4d0e9a8706 | ||
|
|
c05f6783a6 | ||
|
|
a14f4052cf | ||
|
|
9e4ca857b6 | ||
|
|
a2b99084b4 | ||
|
|
85b4effac6 | ||
|
|
790f411542 | ||
|
|
e89de4411d | ||
|
|
256ab3798d | ||
|
|
a59288a019 | ||
|
|
587bbd49a7 | ||
|
|
a9c341545f | ||
|
|
8aa18b6291 | ||
|
|
d727579b6d | ||
|
|
97a30171cb | ||
|
|
0989fc5e59 | ||
|
|
927175ea20 | ||
|
|
6748c373be | ||
|
|
3fab0c6ee4 | ||
|
|
6c8c291559 | ||
|
|
fd4ff23da0 | ||
|
|
f8b69e3308 | ||
|
|
c0394bb09c | ||
|
|
8433eb108c | ||
|
|
f2f9380c86 | ||
|
|
e672dabfea | ||
|
|
9a4ca2764c | ||
|
|
4c7a9c10d3 | ||
|
|
38295a1873 | ||
|
|
31bb0b9726 | ||
|
|
45e5642e91 | ||
|
|
a592f4c89e | ||
|
|
b9d43a557c | ||
|
|
2ece9e25b4 | ||
|
|
2dd2126379 | ||
|
|
f63c130c28 | ||
|
|
e2b26ee19b | ||
|
|
9d686bf433 | ||
|
|
1d26daff3e | ||
|
|
e72e18d9fd | ||
|
|
354d97f6da | ||
|
|
6f7a57eaa0 | ||
|
|
90baa1444b | ||
|
|
0a3b017f09 | ||
|
|
47d35f1053 | ||
|
|
8fb8c2ce1d | ||
|
|
1d063d87cf | ||
|
|
338331b55b | ||
|
|
156a30c753 | ||
|
|
550d2f9048 | ||
|
|
c3a38242e6 | ||
|
|
74c3d7eba2 | ||
|
|
db6eae5c42 | ||
|
|
0e9d79c355 | ||
|
|
b20c4d3aad | ||
|
|
ae145293cc | ||
|
|
e3c76a5cde | ||
|
|
4b9123baff | ||
|
|
f89e0b1a6c | ||
|
|
273f6084e5 | ||
|
|
4a0879458d | ||
|
|
d6f51ea16d | ||
|
|
067dce6e79 | ||
|
|
2ca5f0e72b | ||
|
|
f20d2253ae | ||
|
|
390d438e2a | ||
|
|
6fb2c90d9e | ||
|
|
a7b527d942 | ||
|
|
5d77820b34 | ||
|
|
909ce970ae | ||
|
|
35e2cac6eb | ||
|
|
c39fc9dd9c | ||
|
|
775c6567d1 | ||
|
|
97d9527f6c | ||
|
|
e012054667 | ||
|
|
5235133f32 | ||
|
|
c871df7702 | ||
|
|
a6eeeb3b9c | ||
|
|
3dd02144d5 | ||
|
|
e77926f0ed | ||
|
|
ac23482022 | ||
|
|
8be8a0a713 | ||
|
|
12e341e4f8 | ||
|
|
c36672d803 | ||
|
|
2bfc8e9f01 | ||
|
|
674a9f2aae | ||
|
|
016e6aa13f | ||
|
|
65700441d3 | ||
|
|
dd5bb55cad | ||
|
|
e8423da1b7 | ||
|
|
0980e39c9b | ||
|
|
e73fab27d4 | ||
|
|
92ae532e43 | ||
|
|
7482b25f8b | ||
|
|
3f77dc9a0e | ||
|
|
838c93b843 | ||
|
|
089f48a4a6 | ||
|
|
bf3470c161 | ||
|
|
8f8196e136 | ||
|
|
8ab35b2a5f | ||
|
|
c0ba2870c9 | ||
|
|
22498cf3a9 | ||
|
|
bd37e67ac0 | ||
|
|
a6ee335574 | ||
|
|
71d43f3be9 | ||
|
|
c8db1ca5d4 | ||
|
|
962751a6ec | ||
|
|
06fd6d640c | ||
|
|
acce4ac3f0 | ||
|
|
8fd7861b75 | ||
|
|
c58ae94225 | ||
|
|
2cf7bb7966 | ||
|
|
4e3a66c141 | ||
|
|
d959e23208 | ||
|
|
a9fb540884 | ||
|
|
337eb8b8f7 | ||
|
|
6415ef05d3 | ||
|
|
f069396d1b | ||
|
|
021177af0d | ||
|
|
e1e9f93739 | ||
|
|
15110094eb | ||
|
|
093badb0a0 | ||
|
|
752c7b576d | ||
|
|
7c3e267e1e | ||
|
|
baaffbaedd | ||
|
|
4cb3f222b1 | ||
|
|
eabdbda755 | ||
|
|
bec23700fc | ||
|
|
12f2eedadc | ||
|
|
221eeb2312 | ||
|
|
813d3632ec | ||
|
|
d84bccb0c7 | ||
|
|
b4e67f9bf0 | ||
|
|
54c11932fa | ||
|
|
fbcb3c4236 | ||
|
|
8937dcfd78 | ||
|
|
512d5a6897 | ||
|
|
a92cb5dd7b | ||
|
|
d151dcbb9d | ||
|
|
f1884c66f4 | ||
|
|
72730ecd8a | ||
|
|
fe2bc2b0a7 | ||
|
|
4867c94564 | ||
|
|
ef0eb3701d | ||
|
|
f83ee1af59 | ||
|
|
a5175c513a | ||
|
|
04b10f5a3a | ||
|
|
c121c03456 | ||
|
|
8fd10606c1 | ||
|
|
a1730fcea8 | ||
|
|
a9a295fecf | ||
|
|
5c01ad387f | ||
|
|
42ca1b9140 | ||
|
|
6ed780dbd5 | ||
|
|
3412fab8ee | ||
|
|
8a7d013f85 | ||
|
|
170af59788 | ||
|
|
c8c16de167 | ||
|
|
4525cd9c56 | ||
|
|
47361baf61 | ||
|
|
8a582883ac | ||
|
|
a4bb8f0c2e | ||
|
|
82aed82b84 | ||
|
|
60ff76630d | ||
|
|
a27c7d8093 | ||
|
|
3632208233 | ||
|
|
6b44c605b8 | ||
|
|
d3cd78a87c | ||
|
|
8fa3dfdb5d | ||
|
|
29379e8e49 | ||
|
|
14725d6c3b | ||
|
|
16836ff95a | ||
|
|
c87179e73e | ||
|
|
c24031c36b | ||
|
|
4ccc52c7a0 | ||
|
|
b82fe07384 | ||
|
|
1e7f6c8c7c | ||
|
|
84714b109b | ||
|
|
1045d7dd44 | ||
|
|
0c77775966 | ||
|
|
c43ba17520 | ||
|
|
da3bb64ef6 | ||
|
|
151900ba96 | ||
|
|
c012f29f91 | ||
|
|
df2df21ec1 | ||
|
|
408e4db4af | ||
|
|
4d2364f342 | ||
|
|
261cf3b204 | ||
|
|
cd67261bba | ||
|
|
1aa0c2f6a9 | ||
|
|
4133a39df8 | ||
|
|
1c26d2a1a0 | ||
|
|
276b1bc342 | ||
|
|
124654ffc4 | ||
|
|
3b7d1e86b4 | ||
|
|
78f0c0d1d9 | ||
|
|
c992eafb5b | ||
|
|
ef8dd7792a | ||
|
|
69b329fc87 | ||
|
|
6543ba5297 | ||
|
|
0e453ac352 | ||
|
|
e9b4ae69dc | ||
|
|
fc4fffea41 | ||
|
|
b240ab704d | ||
|
|
9a4f1f434b | ||
|
|
fac64918dc | ||
|
|
a69815f72c | ||
|
|
4033ff5892 | ||
|
|
a083572512 | ||
|
|
5319dedb1a | ||
|
|
bd4e0b30a7 | ||
|
|
bf90612007 | ||
|
|
8142fedd19 | ||
|
|
c0be1cb7a5 | ||
|
|
8cccdfba53 | ||
|
|
cbbbaa61b3 | ||
|
|
ffc2ef77ca | ||
|
|
1da6f4f18b | ||
|
|
b5da526e6d | ||
|
|
3b5365762d | ||
|
|
e2f5438ac1 | ||
|
|
5e3613f732 | ||
|
|
e6b911d40c | ||
|
|
0c7ae58164 | ||
|
|
ae603b9770 | ||
|
|
7f47718b6d | ||
|
|
54dc09e8ac | ||
|
|
334c6be496 | ||
|
|
4174c10e7a | ||
|
|
a20f606c29 | ||
|
|
a72a208272 | ||
|
|
86401e078d | ||
|
|
6af37e6729 | ||
|
|
1b88655b00 | ||
|
|
0b15916e50 | ||
|
|
60eed0ca66 | ||
|
|
0f83367f57 | ||
|
|
fee095410b | ||
|
|
6f3e45eca1 | ||
|
|
815d3e820d | ||
|
|
76e7a0ff55 | ||
|
|
6d91096a2f | ||
|
|
13d9e35858 | ||
|
|
6effe431bb | ||
|
|
efcbdc7698 | ||
|
|
e581013e3d | ||
|
|
0984d4328d | ||
|
|
786f69b248 | ||
|
|
1da0a2dfac | ||
|
|
796ed68faf | ||
|
|
7b1ee31d80 | ||
|
|
4aff1198dd | ||
|
|
ad3a729f96 | ||
|
|
52e2177069 | ||
|
|
760c657551 | ||
|
|
75c859e98f | ||
|
|
91b0958c43 | ||
|
|
8008dde117 | ||
|
|
c81cf82492 | ||
|
|
8573108bbe | ||
|
|
7abe612b59 | ||
|
|
408cf58024 | ||
|
|
39e115fdb4 | ||
|
|
85719669cb | ||
|
|
809fe49c7a | ||
|
|
41253e574e | ||
|
|
08d2ce844b | ||
|
|
a15a8d930d | ||
|
|
83ce29cc22 | ||
|
|
4363c1d2cb | ||
|
|
1bf1ec0270 | ||
|
|
0800976533 | ||
|
|
795408115a | ||
|
|
46545e6273 | ||
|
|
0168178a17 | ||
|
|
82836a62be | ||
|
|
e7430bbebd | ||
|
|
24dd85fd28 | ||
|
|
57f68e2896 | ||
|
|
44cf2bde19 | ||
|
|
be37d4da14 | ||
|
|
4e79d129cb | ||
|
|
05192553f4 | ||
|
|
f2511d7d49 | ||
|
|
f8b203c9c4 | ||
|
|
8ab7c7e2c8 | ||
|
|
7e00390289 | ||
|
|
65c415911a | ||
|
|
a9e91116d2 | ||
|
|
80a745d9b0 | ||
|
|
9fca5e4f42 | ||
|
|
92a806b4e8 | ||
|
|
9c9baf6d58 | ||
|
|
aafc5dc950 | ||
|
|
442949bc11 | ||
|
|
9064072e8c | ||
|
|
fd4c1b5ff7 | ||
|
|
bc7eb8adeb | ||
|
|
fc960f3670 | ||
|
|
f437f0f7ed | ||
|
|
7f33cf682a | ||
|
|
8d9eae9ac9 | ||
|
|
2046bffa40 | ||
|
|
338393f854 | ||
|
|
c27bc2d76f | ||
|
|
bc518a5127 | ||
|
|
100c59054c | ||
|
|
e58c182443 | ||
|
|
69a8b2a579 | ||
|
|
25eba6f35f | ||
|
|
e1f0f75ba6 | ||
|
|
faeb04fbe1 | ||
|
|
537212afee | ||
|
|
6764f25d91 | ||
|
|
d6a8dbd26f | ||
|
|
ed391e1777 | ||
|
|
a49531414b | ||
|
|
de1f0342c8 | ||
|
|
d0d51e2a5c | ||
|
|
33ab26017d | ||
|
|
febb9d87c9 | ||
|
|
8778dc7c2b | ||
|
|
aae376e9a8 | ||
|
|
0ff0471488 | ||
|
|
46a8c7e958 | ||
|
|
bc56c553ec | ||
|
|
07d7cd78a7 | ||
|
|
cdef70e246 | ||
|
|
9dd44df35c | ||
|
|
c9b29d0885 | ||
|
|
fba93e0abb | ||
|
|
d1a545b1fb | ||
|
|
ea92a668d8 | ||
|
|
6034de286a | ||
|
|
b08b0a4402 | ||
|
|
17ae48decc | ||
|
|
fc80979253 | ||
|
|
55658f523a | ||
|
|
14ecfe4236 | ||
|
|
a0182cdb11 | ||
|
|
0dfcc0a378 | ||
|
|
f9a18ea635 | ||
|
|
c7586e85aa | ||
|
|
914c646014 | ||
|
|
42d7c79977 | ||
|
|
e68e8d7de9 | ||
|
|
84809be7e7 | ||
|
|
1606fb6375 | ||
|
|
fe8e3c7e5d | ||
|
|
8f6fa4b715 | ||
|
|
b46db38f57 | ||
|
|
9fa1d27059 | ||
|
|
a402b3abae | ||
|
|
0e1415b996 | ||
|
|
5cd7137103 | ||
|
|
5be777e1d4 | ||
|
|
a49d440ecd | ||
|
|
4ec5e8db90 | ||
|
|
04bec23a37 | ||
|
|
77d57fd075 | ||
|
|
543c1bbeba | ||
|
|
cb971eece8 | ||
|
|
7b9e61fccf | ||
|
|
3359e3042f | ||
|
|
187a4787f9 | ||
|
|
08943aa26f | ||
|
|
5975658ebd | ||
|
|
5d3cf440e5 | ||
|
|
8ec8322f09 | ||
|
|
bbcc85fd4c | ||
|
|
0bdf2fa156 | ||
|
|
2eedc769d5 | ||
|
|
ab01ae1620 | ||
|
|
689bfafa7e | ||
|
|
641309a5bf | ||
|
|
52e3628794 | ||
|
|
dca12522a9 | ||
|
|
e0bbaa6f9c | ||
|
|
ab139d6bea | ||
|
|
34d67b425e | ||
|
|
96d5e35977 | ||
|
|
eb686a86f3 | ||
|
|
750281630b | ||
|
|
fb4e1c34f9 | ||
|
|
8c67b5b129 | ||
|
|
6228b66d3d | ||
|
|
e1be8aaadd | ||
|
|
94873e595c | ||
|
|
b8e87fafe4 | ||
|
|
f96d1ef744 | ||
|
|
89435303b7 | ||
|
|
c75ae24293 | ||
|
|
338944d3d9 | ||
|
|
f5ab24bc41 | ||
|
|
92a8c1a0f2 | ||
|
|
6cea45dcd3 | ||
|
|
fec58aa129 | ||
|
|
71aca81ff9 | ||
|
|
04d87ffec3 | ||
|
|
bb25956f09 | ||
|
|
49f4948f06 | ||
|
|
eeacc53d22 | ||
|
|
f3003e08d0 | ||
|
|
d713a00843 | ||
|
|
77f966f89f | ||
|
|
e86d5b8e97 | ||
|
|
db2aa9b4ec | ||
|
|
63cc0eec4e | ||
|
|
c30a87de6f | ||
|
|
a0fb30575c | ||
|
|
77c18c1d69 | ||
|
|
f1f23d08ed | ||
|
|
f1025b2847 | ||
|
|
5d052f4e55 | ||
|
|
18b015d25a | ||
|
|
d76e93f277 | ||
|
|
82fac326c5 | ||
|
|
043b52bd4a | ||
|
|
c8fa0afdfc | ||
|
|
6d0aae73cd | ||
|
|
ff1b73128d | ||
|
|
2e48c8dd31 | ||
|
|
6942704f2b | ||
|
|
9ecd2e16c2 | ||
|
|
33e2d80791 | ||
|
|
969d0f7a63 | ||
|
|
515a4052a7 | ||
|
|
36fbe6f13e | ||
|
|
b69fc8cc95 | ||
|
|
ab6af18d9f | ||
|
|
37a5dee105 | ||
|
|
8a721f69a1 | ||
|
|
e810635eaa | ||
|
|
4995e15273 | ||
|
|
60b6066feb | ||
|
|
35d45cac7a | ||
|
|
165a6e3d1e | ||
|
|
13d3fb2ea6 | ||
|
|
d64078eb27 | ||
|
|
ca1190a3d8 | ||
|
|
7571b2ac56 | ||
|
|
e5a8f76a4b | ||
|
|
413bb9b553 | ||
|
|
f35184aef9 | ||
|
|
b124b76258 | ||
|
|
0ec7600c67 | ||
|
|
14baf45c90 | ||
|
|
9abb2ec2cc | ||
|
|
2e57d80b13 | ||
|
|
cfc7753a4c | ||
|
|
12ddc8a920 | ||
|
|
24ad35709d | ||
|
|
cc44a44427 | ||
|
|
9ab4a5c0e2 | ||
|
|
6682cfe870 | ||
|
|
64922904bc | ||
|
|
8e505cb677 | ||
|
|
a28357d7ac | ||
|
|
7cb4762a61 | ||
|
|
4e45f7c9e8 | ||
|
|
7ac0264053 | ||
|
|
108e981dbe | ||
|
|
94a78e3853 | ||
|
|
53fb453e04 | ||
|
|
17c1f35fa0 | ||
|
|
2eaf57778c | ||
|
|
666800da36 | ||
|
|
38ed69eb3d | ||
|
|
d026e6f071 | ||
|
|
988164f6e1 | ||
|
|
7179a5a8ba | ||
|
|
a0da0c08c6 | ||
|
|
ac203b2092 | ||
|
|
8dd1bf25b5 | ||
|
|
5aa443d98c | ||
|
|
0fa087657e | ||
|
|
424a473e1f | ||
|
|
c3faa83463 | ||
|
|
91399ad055 | ||
|
|
32782e4ad1 | ||
|
|
e7f3b16905 | ||
|
|
12ed1fe4a9 | ||
|
|
85ee4df7a2 | ||
|
|
de89bd1933 | ||
|
|
8be05f6bd4 | ||
|
|
870ecbc09a | ||
|
|
c2da8d5d85 | ||
|
|
e84cbff673 | ||
|
|
f94e6c84e0 | ||
|
|
f12cca8bcb | ||
|
|
7e4124d6e6 | ||
|
|
a875d247ad | ||
|
|
6e9f5d9810 | ||
|
|
ff1c78233d | ||
|
|
2e9a196734 | ||
|
|
e3cb07d321 | ||
|
|
712866d57b | ||
|
|
44c919a9e8 | ||
|
|
99aa1ef21d | ||
|
|
40ba170c94 | ||
|
|
cb4d0f72e3 | ||
|
|
003e164057 | ||
|
|
21cf300f4c | ||
|
|
9655e12d6d | ||
|
|
fb96fadc20 | ||
|
|
408f11fbdd | ||
|
|
a83caf5910 | ||
|
|
925fab6b15 | ||
|
|
d9fecc3327 | ||
|
|
e9d4532401 | ||
|
|
c37c989ed6 | ||
|
|
6b271b7ecb | ||
|
|
90f3b8e8c7 | ||
|
|
3af7359345 | ||
|
|
c4231c3cb9 | ||
|
|
9657df184e | ||
|
|
97ffc590e3 | ||
|
|
8b52af65bc | ||
|
|
9b034eee12 | ||
|
|
3e9ac3cff9 | ||
|
|
697147a2e6 |
@@ -1,41 +0,0 @@
|
|||||||
:: Copyright 2018 Google Inc. All rights reserved.
|
|
||||||
::
|
|
||||||
:: Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
:: you may not use this file except in compliance with the License.
|
|
||||||
:: You may obtain a copy of the License at
|
|
||||||
::
|
|
||||||
:: http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
::
|
|
||||||
:: Unless required by applicable law or agreed to in writing, software
|
|
||||||
:: distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
:: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
:: See the License for the specific language governing permissions and
|
|
||||||
:: limitations under the License.
|
|
||||||
set buildtype=Release
|
|
||||||
if "%1"=="-b" set buildtype=%2
|
|
||||||
|
|
||||||
cd tests
|
|
||||||
call generate_code.bat -b %buildtype% || goto FAIL
|
|
||||||
|
|
||||||
:: TODO: Release and Debug builds produce differences here for some reason.
|
|
||||||
git checkout HEAD -- monster_test.bfbs
|
|
||||||
git checkout HEAD -- arrays_test.bfbs
|
|
||||||
|
|
||||||
git -c core.autocrlf=true diff --exit-code --quiet || goto :DIFFFOUND
|
|
||||||
goto SUCCESS
|
|
||||||
|
|
||||||
:DIFFFOUND
|
|
||||||
@echo "" >&2
|
|
||||||
@echo "ERROR: ********************************************************" >&2
|
|
||||||
@echo "ERROR: The following differences were found after running the" >&2
|
|
||||||
@echo "ERROR: tests/generate_code.sh script. Maybe you forgot to run" >&2
|
|
||||||
@echo "ERROR: it after making changes in a generator or schema?" >&2
|
|
||||||
@echo "ERROR: ********************************************************" >&2
|
|
||||||
@echo "" >&2
|
|
||||||
@git -c core.autocrlf=true --no-pager diff --binary
|
|
||||||
|
|
||||||
:FAIL
|
|
||||||
set EXITCODE=1
|
|
||||||
:SUCCESS
|
|
||||||
cd ..
|
|
||||||
EXIT /B %EXITCODE%
|
|
||||||
@@ -1,18 +1,36 @@
|
|||||||
---
|
---
|
||||||
buildifier: latest
|
buildifier: latest
|
||||||
platforms:
|
platforms:
|
||||||
ubuntu1604:
|
|
||||||
build_targets:
|
|
||||||
- "..."
|
|
||||||
test_targets:
|
|
||||||
- "..."
|
|
||||||
ubuntu1804:
|
ubuntu1804:
|
||||||
|
environment:
|
||||||
|
CC: clang
|
||||||
|
SWIFT_VERSION: "5.5.3"
|
||||||
|
SWIFT_HOME: "$HOME/swift-$SWIFT_VERSION"
|
||||||
|
PATH: "$PATH:$SWIFT_HOME/usr/bin"
|
||||||
|
shell_commands:
|
||||||
|
- "echo --- Downloading and extracting Swift $SWIFT_VERSION to $SWIFT_HOME"
|
||||||
|
- "mkdir $SWIFT_HOME"
|
||||||
|
- "curl https://download.swift.org/swift-${SWIFT_VERSION}-release/ubuntu1804/swift-${SWIFT_VERSION}-RELEASE/swift-${SWIFT_VERSION}-RELEASE-ubuntu18.04.tar.gz | tar xvz --strip-components=1 -C $SWIFT_HOME"
|
||||||
build_targets:
|
build_targets:
|
||||||
- "..."
|
- "//..."
|
||||||
test_targets:
|
test_targets:
|
||||||
- "..."
|
- "//..."
|
||||||
|
ubuntu2004:
|
||||||
|
environment:
|
||||||
|
CC: clang
|
||||||
|
SWIFT_VERSION: "5.5.3"
|
||||||
|
SWIFT_HOME: "$HOME/swift-$SWIFT_VERSION"
|
||||||
|
PATH: "$PATH:$SWIFT_HOME/usr/bin"
|
||||||
|
shell_commands:
|
||||||
|
- "echo --- Downloading and extracting Swift $SWIFT_VERSION to $SWIFT_HOME"
|
||||||
|
- "mkdir $SWIFT_HOME"
|
||||||
|
- "curl https://download.swift.org/swift-${SWIFT_VERSION}-release/ubuntu2004/swift-${SWIFT_VERSION}-RELEASE/swift-${SWIFT_VERSION}-RELEASE-ubuntu20.04.tar.gz | tar xvz --strip-components=1 -C $SWIFT_HOME"
|
||||||
|
build_targets:
|
||||||
|
- "//..."
|
||||||
|
test_targets:
|
||||||
|
- "//..."
|
||||||
macos:
|
macos:
|
||||||
build_targets:
|
build_targets:
|
||||||
- "..."
|
- "//..."
|
||||||
test_targets:
|
test_targets:
|
||||||
- "..."
|
- "//..."
|
||||||
|
|||||||
13
.eslintrc.js
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
/* eslint-env node */
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
root: true,
|
||||||
|
parser: '@typescript-eslint/parser',
|
||||||
|
plugins: [
|
||||||
|
'@typescript-eslint',
|
||||||
|
],
|
||||||
|
extends: [
|
||||||
|
'eslint:recommended',
|
||||||
|
'plugin:@typescript-eslint/recommended',
|
||||||
|
]
|
||||||
|
};
|
||||||
15
.github/PULL_REQUEST_TEMPLATE.md
vendored
@@ -2,18 +2,17 @@ Thank you for submitting a PR!
|
|||||||
|
|
||||||
Please delete this standard text once you've created your own description.
|
Please delete this standard text once you've created your own description.
|
||||||
|
|
||||||
Make sure you include the names of the affected language(s) in your PR title.
|
If you make changes to any of the code generators (`src/idl_gen*`) be sure to
|
||||||
This helps us get the correct maintainers to look at your issue.
|
build your project, as it will generate code based on the changes. If necessary
|
||||||
|
the code generation script can be directly run (`scripts/generate_code.py`),
|
||||||
|
requires Python3. This allows us to better see the effect of the PR.
|
||||||
|
|
||||||
If you make changes to any of the code generators, be sure to run
|
If your PR includes C++ code, please adhere to the
|
||||||
`cd tests && sh generate_code.sh` (or equivalent .bat) and include the generated
|
[Google C++ Style Guide](https://google.github.io/styleguide/cppguide.html),
|
||||||
code changes in the PR. This allows us to better see the effect of the PR.
|
|
||||||
|
|
||||||
If your PR includes C++ code, please adhere to the Google C++ Style Guide,
|
|
||||||
and don't forget we try to support older compilers (e.g. VS2010, GCC 4.6.3),
|
and don't forget we try to support older compilers (e.g. VS2010, GCC 4.6.3),
|
||||||
so only some C++11 support is available.
|
so only some C++11 support is available.
|
||||||
|
|
||||||
For any C++ changes, please make sure to run `sh src/clang-format-git.sh`
|
For any C++ changes, please make sure to run `sh scripts/clang-format-git.sh`
|
||||||
|
|
||||||
Include other details as appropriate.
|
Include other details as appropriate.
|
||||||
|
|
||||||
|
|||||||
95
.github/labeler.yml
vendored
Normal file
@@ -0,0 +1,95 @@
|
|||||||
|
# Configuration for Auto Labeler during pull request
|
||||||
|
#
|
||||||
|
# See https://github.com/actions/labeler for file format
|
||||||
|
# and https://github.com/google/flatbuffers/labels for a list of valid labels
|
||||||
|
#
|
||||||
|
# See .github/workflows/label.yml for Github Action workflow script
|
||||||
|
|
||||||
|
c#:
|
||||||
|
- '**/*.cs'
|
||||||
|
- net/**/*
|
||||||
|
- tests/FlatBuffers.Test/**/*
|
||||||
|
- tests/FlatBuffers.Benchmarks/**/*
|
||||||
|
- src/idl_gen_csharp.cpp
|
||||||
|
|
||||||
|
swift:
|
||||||
|
- '**/*.swift'
|
||||||
|
- swift/**/*
|
||||||
|
- tests/FlatBuffers.GRPC.Swift/**/*
|
||||||
|
- tests/FlatBuffers.Benchmarks.swift/**/*
|
||||||
|
- tests/FlatBuffers.Test.Swift/**/*
|
||||||
|
- src/idl_gen_swift.cpp
|
||||||
|
|
||||||
|
javascript:
|
||||||
|
- '**/*.js'
|
||||||
|
- src/idl_gen_ts.cpp
|
||||||
|
|
||||||
|
typescript:
|
||||||
|
- '**/*.ts'
|
||||||
|
- src/idl_gen_ts.cpp
|
||||||
|
- grpc/flatbuffers-js-grpc/**/*.ts
|
||||||
|
|
||||||
|
golang:
|
||||||
|
- '**/*.go'
|
||||||
|
- src/idl_gen_go.cpp
|
||||||
|
|
||||||
|
python:
|
||||||
|
- '**/*.py'
|
||||||
|
- src/idl_gen_python.cpp
|
||||||
|
|
||||||
|
java:
|
||||||
|
- '**/*.java'
|
||||||
|
- src/idl_gen_java.cpp
|
||||||
|
|
||||||
|
kotlin:
|
||||||
|
- '**/*.kt'
|
||||||
|
- src/idl_gen_kotlin.cpp
|
||||||
|
|
||||||
|
lua:
|
||||||
|
- '**/*.lua'
|
||||||
|
- lua/**/*
|
||||||
|
- src/idl_gen_lua.cpp
|
||||||
|
- src/bfbs_gen_lua.cpp
|
||||||
|
|
||||||
|
lobster:
|
||||||
|
- '**/*.lobster'
|
||||||
|
- src/idl_gen_lobster.cpp
|
||||||
|
|
||||||
|
php:
|
||||||
|
- '**/*.php'
|
||||||
|
- src/idl_gen_php.cpp
|
||||||
|
|
||||||
|
rust:
|
||||||
|
- '**/*.rs'
|
||||||
|
- rust/**/*
|
||||||
|
- src/idl_gen_rust.cpp
|
||||||
|
|
||||||
|
dart:
|
||||||
|
- '**/*.dart'
|
||||||
|
- src/idl_gen_dart.cpp
|
||||||
|
|
||||||
|
c++:
|
||||||
|
- '**/*.cc'
|
||||||
|
- '**/*.cpp'
|
||||||
|
- '**/*.h'
|
||||||
|
|
||||||
|
json:
|
||||||
|
- '**/*.json'
|
||||||
|
- src/idl_gen_json_schema.cpp
|
||||||
|
|
||||||
|
codegen:
|
||||||
|
- src/**/*
|
||||||
|
|
||||||
|
documentation:
|
||||||
|
- docs/**/*
|
||||||
|
- '**/*.md'
|
||||||
|
|
||||||
|
CI:
|
||||||
|
- '.github/**/*'
|
||||||
|
- '.travis/**/*'
|
||||||
|
- '.bazelci/**/*'
|
||||||
|
- .travis.yml
|
||||||
|
|
||||||
|
grpc:
|
||||||
|
- grpc/**/*
|
||||||
|
- src/idl_gen_grpc.cpp
|
||||||
18
.github/stale.yml
vendored
@@ -1,18 +0,0 @@
|
|||||||
# Number of days of inactivity before an issue becomes stale
|
|
||||||
daysUntilStale: 365
|
|
||||||
# Number of days of inactivity before a stale issue is closed
|
|
||||||
daysUntilClose: 14
|
|
||||||
# Issues with these labels will never be considered stale
|
|
||||||
exemptLabels:
|
|
||||||
- pinned
|
|
||||||
- security
|
|
||||||
# Label to use when marking an issue as stale
|
|
||||||
staleLabel: stale
|
|
||||||
# Comment to post when marking an issue as stale. Set to `false` to disable
|
|
||||||
markComment: >
|
|
||||||
This issue has been automatically marked as stale because it has not had
|
|
||||||
activity for 1 year. It will be automatically closed if no further activity occurs.
|
|
||||||
To keep it open, simply post a new comment. Maintainers will re-open on
|
|
||||||
new activity. Thank you for your contributions.
|
|
||||||
# Comment to post when closing a stale issue. Set to `false` to disable
|
|
||||||
closeComment: false
|
|
||||||
506
.github/workflows/build.yml
vendored
Normal file
@@ -0,0 +1,506 @@
|
|||||||
|
name: CI
|
||||||
|
permissions: read-all
|
||||||
|
|
||||||
|
on:
|
||||||
|
# For manual tests.
|
||||||
|
workflow_dispatch:
|
||||||
|
push:
|
||||||
|
tags:
|
||||||
|
- "*" # new tag version, like `0.8.4` or else
|
||||||
|
branches:
|
||||||
|
- master
|
||||||
|
pull_request:
|
||||||
|
branches:
|
||||||
|
- master
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build-linux:
|
||||||
|
permissions:
|
||||||
|
contents: write
|
||||||
|
outputs:
|
||||||
|
digests-gcc: ${{ steps.hash-gcc.outputs.hashes }}
|
||||||
|
digests-clang: ${{ steps.hash-clang.outputs.hashes }}
|
||||||
|
name: Build Linux
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
strategy:
|
||||||
|
matrix:
|
||||||
|
cxx: [g++-10, clang++-12]
|
||||||
|
fail-fast: false
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v2
|
||||||
|
- name: cmake
|
||||||
|
run: CXX=${{ matrix.cxx }} cmake -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=Release -DFLATBUFFERS_STRICT_MODE=ON .
|
||||||
|
- name: build
|
||||||
|
run: make -j
|
||||||
|
- name: test
|
||||||
|
run: ./flattests
|
||||||
|
- name: make flatc executable
|
||||||
|
run: |
|
||||||
|
chmod +x flatc
|
||||||
|
./flatc --version
|
||||||
|
- name: flatc tests
|
||||||
|
run: python3 tests/flatc/main.py
|
||||||
|
- name: upload build artifacts
|
||||||
|
uses: actions/upload-artifact@v1
|
||||||
|
with:
|
||||||
|
name: Linux flatc binary ${{ matrix.cxx }}
|
||||||
|
path: flatc
|
||||||
|
# Below if only for release.
|
||||||
|
- name: Zip file
|
||||||
|
if: startsWith(github.ref, 'refs/tags/')
|
||||||
|
run: zip Linux.flatc.binary.${{ matrix.cxx }}.zip flatc
|
||||||
|
- name: Release zip file
|
||||||
|
uses: softprops/action-gh-release@v1
|
||||||
|
if: startsWith(github.ref, 'refs/tags/')
|
||||||
|
with:
|
||||||
|
files: Linux.flatc.binary.${{ matrix.cxx }}.zip
|
||||||
|
- name: Generate SLSA subjects - clang
|
||||||
|
if: matrix.cxx == 'clang++-12' && startsWith(github.ref, 'refs/tags/')
|
||||||
|
id: hash-clang
|
||||||
|
run: echo "::set-output name=hashes::$(sha256sum Linux.flatc.binary.${{ matrix.cxx }}.zip | base64 -w0)"
|
||||||
|
- name: Generate SLSA subjects - gcc
|
||||||
|
if: matrix.cxx == 'g++-10' && startsWith(github.ref, 'refs/tags/')
|
||||||
|
id: hash-gcc
|
||||||
|
run: echo "::set-output name=hashes::$(sha256sum Linux.flatc.binary.${{ matrix.cxx }}.zip | base64 -w0)"
|
||||||
|
|
||||||
|
build-linux-cpp-std:
|
||||||
|
name: Build Linux C++
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
strategy:
|
||||||
|
fail-fast: false
|
||||||
|
matrix:
|
||||||
|
std: [11, 14, 17, 20, 23]
|
||||||
|
cxx: [g++-10, clang++-12]
|
||||||
|
exclude:
|
||||||
|
# GCC 10.3.0 doesn't support std 23
|
||||||
|
- cxx: g++-10
|
||||||
|
std: 23
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v2
|
||||||
|
- name: cmake
|
||||||
|
run: >
|
||||||
|
CXX=${{ matrix.cxx }} cmake -G "Unix Makefiles"
|
||||||
|
-DCMAKE_BUILD_TYPE=Release -DFLATBUFFERS_STRICT_MODE=ON
|
||||||
|
-DFLATBUFFERS_CPP_STD=${{ matrix.std }}
|
||||||
|
- name: build
|
||||||
|
run: make -j
|
||||||
|
- name: test
|
||||||
|
run: ./flattests
|
||||||
|
|
||||||
|
build-windows-cpp-std:
|
||||||
|
name: Build Windows C++
|
||||||
|
runs-on: windows-2019
|
||||||
|
strategy:
|
||||||
|
matrix:
|
||||||
|
std: [11, 14, 17, 20, 23]
|
||||||
|
fail-fast: false
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v2
|
||||||
|
- name: Add msbuild to PATH
|
||||||
|
uses: microsoft/setup-msbuild@v1.1
|
||||||
|
- name: cmake
|
||||||
|
run: >
|
||||||
|
cmake -G "Visual Studio 16 2019" -A x64 -DCMAKE_BUILD_TYPE=Release
|
||||||
|
-DFLATBUFFERS_STRICT_MODE=ON
|
||||||
|
-DFLATBUFFERS_CPP_STD=${{ matrix.std }}
|
||||||
|
- name: build
|
||||||
|
run: msbuild.exe FlatBuffers.sln /p:Configuration=Release /p:Platform=x64
|
||||||
|
- name: test
|
||||||
|
run: Release\flattests.exe
|
||||||
|
|
||||||
|
build-windows:
|
||||||
|
permissions:
|
||||||
|
contents: write
|
||||||
|
outputs:
|
||||||
|
digests: ${{ steps.hash.outputs.hashes }}
|
||||||
|
name: Build Windows 2019
|
||||||
|
runs-on: windows-2019
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v2
|
||||||
|
- name: Add msbuild to PATH
|
||||||
|
uses: microsoft/setup-msbuild@v1.1
|
||||||
|
- name: cmake
|
||||||
|
run: cmake -G "Visual Studio 16 2019" -A x64 -DCMAKE_BUILD_TYPE=Release -DFLATBUFFERS_BUILD_CPP17=ON -DFLATBUFFERS_STRICT_MODE=ON .
|
||||||
|
- name: build
|
||||||
|
run: msbuild.exe FlatBuffers.sln /p:Configuration=Release /p:Platform=x64
|
||||||
|
- name: test
|
||||||
|
run: Release\flattests.exe
|
||||||
|
- name: flatc tests
|
||||||
|
run: python3 tests/flatc/main.py --flatc Release\flatc.exe
|
||||||
|
- name: upload build artifacts
|
||||||
|
uses: actions/upload-artifact@v1
|
||||||
|
with:
|
||||||
|
name: Windows flatc binary
|
||||||
|
path: Release\flatc.exe
|
||||||
|
# Below if only for release.
|
||||||
|
- name: Zip file
|
||||||
|
if: startsWith(github.ref, 'refs/tags/')
|
||||||
|
run: move Release/flatc.exe . && Compress-Archive flatc.exe Windows.flatc.binary.zip
|
||||||
|
- name: Release binary
|
||||||
|
uses: softprops/action-gh-release@v1
|
||||||
|
if: startsWith(github.ref, 'refs/tags/')
|
||||||
|
with:
|
||||||
|
files: Windows.flatc.binary.zip
|
||||||
|
- name: Generate SLSA subjects
|
||||||
|
if: startsWith(github.ref, 'refs/tags/')
|
||||||
|
id: hash
|
||||||
|
shell: bash
|
||||||
|
run: echo "::set-output name=hashes::$(sha256sum Windows.flatc.binary.zip | base64 -w0)"
|
||||||
|
|
||||||
|
build-windows-2017:
|
||||||
|
name: Build Windows 2017
|
||||||
|
runs-on: windows-2019
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v2
|
||||||
|
- name: Add msbuild to PATH
|
||||||
|
uses: microsoft/setup-msbuild@v1.1
|
||||||
|
- name: cmake
|
||||||
|
run: cmake -G "Visual Studio 16 2019" -A x64 -DCMAKE_BUILD_TYPE=Release -DFLATBUFFERS_STRICT_MODE=ON .
|
||||||
|
- name: build tool version 15 (VS 2017)
|
||||||
|
run: msbuild.exe FlatBuffers.sln /p:Configuration=Release /p:Platform=x64 /p:VisualStudioVersion=15.0
|
||||||
|
- name: test
|
||||||
|
run: Release\flattests.exe
|
||||||
|
|
||||||
|
build-windows-2015:
|
||||||
|
name: Build Windows 2015
|
||||||
|
runs-on: windows-2019
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v2
|
||||||
|
- name: Add msbuild to PATH
|
||||||
|
uses: microsoft/setup-msbuild@v1.1
|
||||||
|
- name: cmake
|
||||||
|
run: cmake -G "Visual Studio 14 2015" -A x64 -DCMAKE_BUILD_TYPE=Release -DFLATBUFFERS_STRICT_MODE=ON .
|
||||||
|
- name: build tool version 14 (VS 2015)
|
||||||
|
run: msbuild.exe FlatBuffers.sln /p:Configuration=Release /p:Platform=x64 /p:VisualStudioVersion=14.0
|
||||||
|
- name: test
|
||||||
|
run: Release\flattests.exe
|
||||||
|
|
||||||
|
build-dotnet-windows:
|
||||||
|
name: Build .NET Windows
|
||||||
|
runs-on: windows-2019
|
||||||
|
strategy:
|
||||||
|
matrix:
|
||||||
|
configuration: [
|
||||||
|
'',
|
||||||
|
'-p:UnsafeByteBuffer=true',
|
||||||
|
# Fails two tests currently.
|
||||||
|
#'-p:EnableSpanT=true,UnsafeByteBuffer=true'
|
||||||
|
]
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v2
|
||||||
|
- name: Setup .NET Core SDK
|
||||||
|
uses: actions/setup-dotnet@v1.9.0
|
||||||
|
with:
|
||||||
|
dotnet-version: '3.1.x'
|
||||||
|
- name: Build
|
||||||
|
run: |
|
||||||
|
cd tests\FlatBuffers.Test
|
||||||
|
dotnet new sln --force --name FlatBuffers.Core.Test
|
||||||
|
dotnet sln FlatBuffers.Core.Test.sln add FlatBuffers.Core.Test.csproj
|
||||||
|
dotnet build -c Release ${{matrix.configuration}} -o out FlatBuffers.Core.Test.sln
|
||||||
|
- name: Run
|
||||||
|
run: |
|
||||||
|
cd tests\FlatBuffers.Test
|
||||||
|
out\FlatBuffers.Core.Test.exe
|
||||||
|
|
||||||
|
build-mac-intel:
|
||||||
|
permissions:
|
||||||
|
contents: write
|
||||||
|
outputs:
|
||||||
|
digests: ${{ steps.hash.outputs.hashes }}
|
||||||
|
name: Build Mac (for Intel)
|
||||||
|
runs-on: macos-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v2
|
||||||
|
- name: cmake
|
||||||
|
run: cmake -G "Xcode" -DCMAKE_BUILD_TYPE=Release -DFLATBUFFERS_FLATC_EXECUTABLE=_build/Release/flatc -DFLATBUFFERS_STRICT_MODE=ON .
|
||||||
|
- name: build
|
||||||
|
# NOTE: we need this _build dir to not have xcodebuild's default ./build dir clash with the BUILD file.
|
||||||
|
run: xcodebuild -toolchain clang -configuration Release -target flattests SYMROOT=$(PWD)/_build
|
||||||
|
- name: check that the binary is x86_64
|
||||||
|
run: |
|
||||||
|
info=$(file _build/Release/flatc)
|
||||||
|
echo $info
|
||||||
|
echo $info | grep "Mach-O 64-bit executable x86_64"
|
||||||
|
- name: test
|
||||||
|
run: _build/Release/flattests
|
||||||
|
- name: make flatc executable
|
||||||
|
run: |
|
||||||
|
chmod +x _build/Release/flatc
|
||||||
|
./_build/Release/flatc --version
|
||||||
|
- name: flatc tests
|
||||||
|
run: python3 tests/flatc/main.py --flatc ./_build/Release/flatc
|
||||||
|
- name: upload build artifacts
|
||||||
|
uses: actions/upload-artifact@v1
|
||||||
|
with:
|
||||||
|
name: Mac flatc binary
|
||||||
|
path: _build/Release/flatc
|
||||||
|
# Below if only for release.
|
||||||
|
- name: Zip file
|
||||||
|
if: startsWith(github.ref, 'refs/tags/')
|
||||||
|
run: mv _build/Release/flatc . && zip MacIntel.flatc.binary.zip flatc
|
||||||
|
- name: Release binary
|
||||||
|
uses: softprops/action-gh-release@v1
|
||||||
|
if: startsWith(github.ref, 'refs/tags/')
|
||||||
|
with:
|
||||||
|
files: MacIntel.flatc.binary.zip
|
||||||
|
- name: Generate SLSA subjects
|
||||||
|
if: startsWith(github.ref, 'refs/tags/')
|
||||||
|
id: hash
|
||||||
|
run: echo "::set-output name=hashes::$(shasum -a 256 MacIntel.flatc.binary.zip | base64)"
|
||||||
|
|
||||||
|
build-mac-universal:
|
||||||
|
permissions:
|
||||||
|
contents: write
|
||||||
|
outputs:
|
||||||
|
digests: ${{ steps.hash.outputs.hashes }}
|
||||||
|
name: Build Mac (universal build)
|
||||||
|
runs-on: macos-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v2
|
||||||
|
- name: cmake
|
||||||
|
run: cmake -G "Xcode" -DCMAKE_OSX_ARCHITECTURES="arm64;x86_64" -DCMAKE_BUILD_TYPE=Release -DFLATBUFFERS_FLATC_EXECUTABLE=_build/Release/flatc -DFLATBUFFERS_STRICT_MODE=ON .
|
||||||
|
- name: build
|
||||||
|
# NOTE: we need this _build dir to not have xcodebuild's default ./build dir clash with the BUILD file.
|
||||||
|
run: xcodebuild -toolchain clang -configuration Release -target flattests SYMROOT=$(PWD)/_build
|
||||||
|
- name: check that the binary is "universal"
|
||||||
|
run: |
|
||||||
|
info=$(file _build/Release/flatc)
|
||||||
|
echo $info
|
||||||
|
echo $info | grep "Mach-O universal binary with 2 architectures"
|
||||||
|
- name: test
|
||||||
|
run: _build/Release/flattests
|
||||||
|
- name: make flatc executable
|
||||||
|
run: |
|
||||||
|
chmod +x _build/Release/flatc
|
||||||
|
./_build/Release/flatc --version
|
||||||
|
- name: upload build artifacts
|
||||||
|
uses: actions/upload-artifact@v1
|
||||||
|
with:
|
||||||
|
name: Mac flatc binary
|
||||||
|
path: _build/Release/flatc
|
||||||
|
# Below if only for release.
|
||||||
|
- name: Zip file
|
||||||
|
if: startsWith(github.ref, 'refs/tags/')
|
||||||
|
run: mv _build/Release/flatc . && zip Mac.flatc.binary.zip flatc
|
||||||
|
- name: Release binary
|
||||||
|
uses: softprops/action-gh-release@v1
|
||||||
|
if: startsWith(github.ref, 'refs/tags/')
|
||||||
|
with:
|
||||||
|
files: Mac.flatc.binary.zip
|
||||||
|
- name: Generate SLSA subjects
|
||||||
|
if: startsWith(github.ref, 'refs/tags/')
|
||||||
|
id: hash
|
||||||
|
run: echo "::set-output name=hashes::$(shasum -a 256 Mac.flatc.binary.zip | base64)"
|
||||||
|
|
||||||
|
build-android:
|
||||||
|
name: Build Android (on Linux)
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v2
|
||||||
|
- name: set up JDK 1.8
|
||||||
|
uses: actions/setup-java@v1
|
||||||
|
with:
|
||||||
|
java-version: 1.8
|
||||||
|
- name: set up flatc
|
||||||
|
run: |
|
||||||
|
cmake -DFLATBUFFERS_BUILD_TESTS=OFF -DFLATBUFFERS_BUILD_FLATLIB=OFF -DFLATBUFFERS_BUILD_FLATHASH=OFF -DFLATBUFFERS_STRICT_MODE=ON .
|
||||||
|
make -j
|
||||||
|
echo "${PWD}" >> $GITHUB_PATH
|
||||||
|
- name: build
|
||||||
|
working-directory: android
|
||||||
|
run: gradle clean build
|
||||||
|
|
||||||
|
build-generator:
|
||||||
|
name: Check Generated Code
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
strategy:
|
||||||
|
matrix:
|
||||||
|
cxx: [g++-10, clang++-12]
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v2
|
||||||
|
- name: cmake
|
||||||
|
run: CXX=${{ matrix.cxx }} cmake -G "Unix Makefiles" -DFLATBUFFERS_BUILD_TESTS=OFF -DCMAKE_BUILD_TYPE=Release -DFLATBUFFERS_STRICT_MODE=ON . && make -j
|
||||||
|
- name: Generate
|
||||||
|
run: scripts/check_generate_code.py
|
||||||
|
- name: Generate gRPC
|
||||||
|
run: scripts/check-grpc-generated-code.py
|
||||||
|
|
||||||
|
build-benchmarks:
|
||||||
|
name: Build Benchmarks (on Linux)
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
strategy:
|
||||||
|
matrix:
|
||||||
|
cxx: [g++-10]
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v2
|
||||||
|
- name: cmake
|
||||||
|
run: CXX=${{ matrix.cxx }} cmake -G "Unix Makefiles" -DFLATBUFFERS_CXX_FLAGS="-Wno-unused-parameter -fno-aligned-new" -DFLATBUFFERS_BUILD_BENCHMARKS=ON -DCMAKE_BUILD_TYPE=Release -DFLATBUFFERS_STRICT_MODE=ON . && make -j
|
||||||
|
- name: Run benchmarks
|
||||||
|
run: ./flatbenchmark --benchmark_repetitions=5 --benchmark_display_aggregates_only=true --benchmark_out_format=console --benchmark_out=benchmarks/results_${{matrix.cxx}}
|
||||||
|
- name: Upload benchmarks results
|
||||||
|
uses: actions/upload-artifact@v1
|
||||||
|
with:
|
||||||
|
name: Linux flatbenchmark results ${{matrix.cxx}}
|
||||||
|
path: benchmarks/results_${{matrix.cxx}}
|
||||||
|
|
||||||
|
build-java:
|
||||||
|
name: Build Java
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v2
|
||||||
|
- name: test
|
||||||
|
working-directory: tests
|
||||||
|
run: bash JavaTest.sh
|
||||||
|
|
||||||
|
build-kotlin-macos:
|
||||||
|
name: Build Kotlin MacOS
|
||||||
|
runs-on: macos-latest
|
||||||
|
steps:
|
||||||
|
- name: Checkout
|
||||||
|
uses: actions/checkout@v2
|
||||||
|
- uses: gradle/wrapper-validation-action@v1
|
||||||
|
- uses: actions/setup-java@v2
|
||||||
|
with:
|
||||||
|
distribution: 'adopt-hotspot'
|
||||||
|
java-version: '11'
|
||||||
|
- name: Build
|
||||||
|
working-directory: kotlin
|
||||||
|
run: ./gradlew clean iosX64Test macosX64Test
|
||||||
|
|
||||||
|
build-kotlin-linux:
|
||||||
|
name: Build Kotlin Linux
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Checkout
|
||||||
|
uses: actions/checkout@v2
|
||||||
|
- uses: actions/setup-java@v2
|
||||||
|
with:
|
||||||
|
distribution: 'adopt-hotspot'
|
||||||
|
java-version: '11'
|
||||||
|
- uses: gradle/wrapper-validation-action@v1
|
||||||
|
- name: Build
|
||||||
|
working-directory: kotlin
|
||||||
|
# we are using docker's version of gradle
|
||||||
|
# so no need for wrapper validadation or user
|
||||||
|
# gradlew
|
||||||
|
run: gradle jvmMainClasses jvmTest jsTest jsBrowserTest
|
||||||
|
|
||||||
|
build-rust:
|
||||||
|
name: Build Rust
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v2
|
||||||
|
- name: test
|
||||||
|
working-directory: tests
|
||||||
|
run: bash RustTest.sh
|
||||||
|
|
||||||
|
build-python:
|
||||||
|
name: Build Python
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v2
|
||||||
|
- name: test
|
||||||
|
working-directory: tests
|
||||||
|
run: bash PythonTest.sh
|
||||||
|
|
||||||
|
build-go:
|
||||||
|
name: Build Go
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v2
|
||||||
|
- name: flatc
|
||||||
|
# FIXME: make test script not rely on flatc
|
||||||
|
run: cmake -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=Release -DFLATBUFFERS_BUILD_TESTS=OFF -DFLATBUFFERS_INSTALL=OFF -DFLATBUFFERS_BUILD_FLATLIB=OFF -DFLATBUFFERS_BUILD_FLATHASH=OFF -DFLATBUFFERS_STRICT_MODE=ON . && make -j
|
||||||
|
- name: test
|
||||||
|
working-directory: tests
|
||||||
|
run: bash GoTest.sh
|
||||||
|
|
||||||
|
build-swift:
|
||||||
|
name: Build Swift
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v2
|
||||||
|
- name: test
|
||||||
|
working-directory: tests/FlatBuffers.Test.Swift
|
||||||
|
run: sh SwiftTest.sh
|
||||||
|
|
||||||
|
build-swift-wasm:
|
||||||
|
name: Build Swift Wasm
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
container:
|
||||||
|
image: ghcr.io/swiftwasm/carton:0.15.3
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v2
|
||||||
|
- name: Setup Wasmer
|
||||||
|
uses: wasmerio/setup-wasmer@v1
|
||||||
|
- name: Test
|
||||||
|
working-directory: tests/FlatBuffers.Test.Swift.Wasm
|
||||||
|
run: carton test
|
||||||
|
|
||||||
|
build-ts:
|
||||||
|
name: Build TS
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v2
|
||||||
|
- name: flatc
|
||||||
|
# FIXME: make test script not rely on flatc
|
||||||
|
run: cmake -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=Release -DFLATBUFFERS_BUILD_TESTS=OFF -DFLATBUFFERS_INSTALL=OFF -DFLATBUFFERS_BUILD_FLATLIB=OFF -DFLATBUFFERS_BUILD_FLATHASH=OFF . && make -j
|
||||||
|
- name: deps
|
||||||
|
run: yarn
|
||||||
|
- name: compile
|
||||||
|
run: yarn compile
|
||||||
|
- name: test
|
||||||
|
working-directory: tests
|
||||||
|
run: python3 TypeScriptTest.py
|
||||||
|
|
||||||
|
build-dart:
|
||||||
|
name: Build Dart
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v2
|
||||||
|
- uses: dart-lang/setup-dart@v1
|
||||||
|
with:
|
||||||
|
sdk: stable
|
||||||
|
- name: flatc
|
||||||
|
# FIXME: make test script not rely on flatc
|
||||||
|
run: cmake -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=Release -DFLATBUFFERS_BUILD_TESTS=OFF -DFLATBUFFERS_INSTALL=OFF -DFLATBUFFERS_BUILD_FLATLIB=OFF -DFLATBUFFERS_BUILD_FLATHASH=OFF -DFLATBUFFERS_STRICT_MODE=ON . && make -j
|
||||||
|
- name: test
|
||||||
|
working-directory: tests
|
||||||
|
run: bash DartTest.sh
|
||||||
|
|
||||||
|
release-digests:
|
||||||
|
if: startsWith(github.ref, 'refs/tags/')
|
||||||
|
needs: [build-linux, build-windows, build-mac-intel, build-mac-universal]
|
||||||
|
outputs:
|
||||||
|
digests: ${{ steps.hash.outputs.digests }}
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Merge results
|
||||||
|
id: hash
|
||||||
|
env:
|
||||||
|
LINUXGCC_DIGESTS: "${{ needs.build-linux.outputs.digests-gcc }}"
|
||||||
|
LINUXCLANG_DIGESTS: "${{ needs.build-linux.outputs.digests-clang }}"
|
||||||
|
MAC_DIGESTS: "${{ needs.build-mac-universal.outputs.digests }}"
|
||||||
|
MACINTEL_DIGESTS: "${{ needs.build-mac-intel.outputs.digests }}"
|
||||||
|
WINDOWS_DIGESTS: "${{ needs.build-windows.outputs.digests }}"
|
||||||
|
run: |
|
||||||
|
set -euo pipefail
|
||||||
|
echo "$LINUXGCC_DIGESTS" | base64 -d > checksums.txt
|
||||||
|
echo "$LINUXCLANG_DIGESTS" | base64 -d >> checksums.txt
|
||||||
|
echo "$MAC_DIGESTS" | base64 -d >> checksums.txt
|
||||||
|
echo "$MACINTEL_DIGESTS" | base64 -d >> checksums.txt
|
||||||
|
echo "$WINDOWS_DIGESTS" | base64 -d >> checksums.txt
|
||||||
|
echo "::set-output name=digests::$(cat checksums.txt | base64 -w0)"
|
||||||
|
|
||||||
|
provenance:
|
||||||
|
if: startsWith(github.ref, 'refs/tags/')
|
||||||
|
needs: [release-digests]
|
||||||
|
permissions:
|
||||||
|
actions: read # To read the workflow path.
|
||||||
|
id-token: write # To sign the provenance.
|
||||||
|
contents: write # To add assets to a release.
|
||||||
|
uses: slsa-framework/slsa-github-generator/.github/workflows/generator_generic_slsa3.yml@v1.2.0
|
||||||
|
with:
|
||||||
|
base64-subjects: "${{ needs.release-digests.outputs.digests }}"
|
||||||
|
upload-assets: true # Optional: Upload to a new release
|
||||||
71
.github/workflows/codeql.yml
vendored
Normal file
@@ -0,0 +1,71 @@
|
|||||||
|
# For most projects, this workflow file will not need changing; you simply need
|
||||||
|
# to commit it to your repository.
|
||||||
|
#
|
||||||
|
# You may wish to alter this file to override the set of languages analyzed,
|
||||||
|
# or to provide custom queries or build logic.
|
||||||
|
#
|
||||||
|
# ******** NOTE ********
|
||||||
|
# We have attempted to detect the languages in your repository. Please check
|
||||||
|
# the `language` matrix defined below to confirm you have the correct set of
|
||||||
|
# supported CodeQL languages.
|
||||||
|
#
|
||||||
|
name: "CodeQL"
|
||||||
|
permissions: read-all
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches: [ master ]
|
||||||
|
pull_request:
|
||||||
|
# The branches below must be a subset of the branches above
|
||||||
|
branches: [ master ]
|
||||||
|
schedule:
|
||||||
|
- cron: '16 20 * * 0'
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
analyze:
|
||||||
|
name: Analyze
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
permissions:
|
||||||
|
actions: read
|
||||||
|
contents: read
|
||||||
|
security-events: write
|
||||||
|
|
||||||
|
strategy:
|
||||||
|
fail-fast: false
|
||||||
|
matrix:
|
||||||
|
language: [ 'cpp' ]
|
||||||
|
# CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby' ]
|
||||||
|
# Learn more about CodeQL language support at https://git.io/codeql-language-support
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Checkout repository
|
||||||
|
uses: actions/checkout@v3
|
||||||
|
|
||||||
|
# Initializes the CodeQL tools for scanning.
|
||||||
|
- name: Initialize CodeQL
|
||||||
|
uses: github/codeql-action/init@v2
|
||||||
|
with:
|
||||||
|
languages: ${{ matrix.language }}
|
||||||
|
# If you wish to specify custom queries, you can do so here or in a config file.
|
||||||
|
# By default, queries listed here will override any specified in a config file.
|
||||||
|
# Prefix the list here with "+" to use these queries and those in the config file.
|
||||||
|
# queries: ./path/to/local/query, your-org/your-repo/queries@main
|
||||||
|
|
||||||
|
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
|
||||||
|
# If this step fails, then you should remove it and run the build manually (see below)
|
||||||
|
# - name: Autobuild
|
||||||
|
# uses: github/codeql-action/autobuild@v2
|
||||||
|
|
||||||
|
# ℹ️ Command-line programs to run using the OS shell.
|
||||||
|
# 📚 https://git.io/JvXDl
|
||||||
|
|
||||||
|
# ✏️ If the Autobuild fails above, remove it and uncomment the following three lines
|
||||||
|
# and modify them (or add more) to build your code if your project
|
||||||
|
# uses a compiled language
|
||||||
|
|
||||||
|
- run: |
|
||||||
|
cmake -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=Release -DFLATBUFFERS_STRICT_MODE=ON .
|
||||||
|
make -j
|
||||||
|
|
||||||
|
- name: Perform CodeQL Analysis
|
||||||
|
uses: github/codeql-action/analyze@v2
|
||||||
24
.github/workflows/label.yml
vendored
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
# This workflow will triage pull requests and apply a label based on the
|
||||||
|
# paths that are modified in the pull request.
|
||||||
|
#
|
||||||
|
# To use this workflow, you will need to set up a .github/labeler.yml
|
||||||
|
# file with configuration. For more information, see:
|
||||||
|
# https://github.com/actions/labeler
|
||||||
|
|
||||||
|
name: Labeler
|
||||||
|
permissions: read-all
|
||||||
|
|
||||||
|
on: [pull_request_target]
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
label:
|
||||||
|
permissions:
|
||||||
|
contents: read
|
||||||
|
pull-requests: write
|
||||||
|
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- uses: actions/labeler@main
|
||||||
|
with:
|
||||||
|
repo-token: "${{ secrets.GITHUB_TOKEN }}"
|
||||||
34
.github/workflows/main.yml
vendored
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
name: OSS-Fuzz
|
||||||
|
permissions: read-all
|
||||||
|
|
||||||
|
on:
|
||||||
|
pull_request:
|
||||||
|
branches:
|
||||||
|
- master
|
||||||
|
paths:
|
||||||
|
- include/**
|
||||||
|
- src/**
|
||||||
|
- tests/**.cpp
|
||||||
|
- tests/**.h
|
||||||
|
jobs:
|
||||||
|
Fuzzing:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Build Fuzzers
|
||||||
|
id: build
|
||||||
|
uses: google/oss-fuzz/infra/cifuzz/actions/build_fuzzers@master
|
||||||
|
with:
|
||||||
|
oss-fuzz-project-name: 'flatbuffers'
|
||||||
|
language: c++
|
||||||
|
- name: Run Fuzzers
|
||||||
|
uses: google/oss-fuzz/infra/cifuzz/actions/run_fuzzers@master
|
||||||
|
with:
|
||||||
|
oss-fuzz-project-name: 'flatbuffers'
|
||||||
|
language: c++
|
||||||
|
fuzz-seconds: 60
|
||||||
|
- name: Upload Crash
|
||||||
|
uses: actions/upload-artifact@v1
|
||||||
|
if: failure() && steps.build.outcome == 'success'
|
||||||
|
with:
|
||||||
|
name: artifacts
|
||||||
|
path: ./out/artifacts
|
||||||
55
.github/workflows/scorecards.yml
vendored
Normal file
@@ -0,0 +1,55 @@
|
|||||||
|
name: Scorecards supply-chain security
|
||||||
|
on:
|
||||||
|
# Only the default branch is supported.
|
||||||
|
branch_protection_rule:
|
||||||
|
schedule:
|
||||||
|
- cron: '21 2 * * 5'
|
||||||
|
push:
|
||||||
|
branches: [ master ]
|
||||||
|
|
||||||
|
# Declare default permissions as read only.
|
||||||
|
permissions: read-all
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
analysis:
|
||||||
|
name: Scorecards analysis
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
permissions:
|
||||||
|
# Needed to upload the results to code-scanning dashboard.
|
||||||
|
security-events: write
|
||||||
|
actions: read
|
||||||
|
contents: read
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: "Checkout code"
|
||||||
|
uses: actions/checkout@a12a3943b4bdde767164f792f33f40b04645d846 # v3.0.0
|
||||||
|
with:
|
||||||
|
persist-credentials: false
|
||||||
|
|
||||||
|
- name: "Run analysis"
|
||||||
|
uses: ossf/scorecard-action@ce330fde6b1a5c9c75b417e7efc510b822a35564 # v1.1.2
|
||||||
|
with:
|
||||||
|
results_file: results.sarif
|
||||||
|
results_format: sarif
|
||||||
|
# Read-only PAT token. To create it,
|
||||||
|
# follow the steps in https://github.com/ossf/scorecard-action#pat-token-creation.
|
||||||
|
repo_token: ${{ secrets.SCORECARD_READ_TOKEN }}
|
||||||
|
# Publish the results to enable scorecard badges. For more details, see
|
||||||
|
# https://github.com/ossf/scorecard-action#publishing-results.
|
||||||
|
# For private repositories, `publish_results` will automatically be set to `false`,
|
||||||
|
# regardless of the value entered here.
|
||||||
|
publish_results: true
|
||||||
|
|
||||||
|
# Upload the results as artifacts (optional).
|
||||||
|
- name: "Upload artifact"
|
||||||
|
uses: actions/upload-artifact@6673cd052c4cd6fcf4b4e6e60ea986c889389535 # v3.0.0
|
||||||
|
with:
|
||||||
|
name: SARIF file
|
||||||
|
path: results.sarif
|
||||||
|
retention-days: 5
|
||||||
|
|
||||||
|
# Upload the results to GitHub's code scanning dashboard.
|
||||||
|
- name: "Upload to code-scanning"
|
||||||
|
uses: github/codeql-action/upload-sarif@5f532563584d71fdef14ee64d17bafb34f751ce5 # v1.0.26
|
||||||
|
with:
|
||||||
|
sarif_file: results.sarif
|
||||||
24
.github/workflows/stale.yml
vendored
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
name: Mark stale issues and pull requests
|
||||||
|
permissions: read-all
|
||||||
|
|
||||||
|
on:
|
||||||
|
schedule:
|
||||||
|
- cron: "30 20 * * *"
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
stale:
|
||||||
|
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- uses: actions/stale@v4.0.0
|
||||||
|
with:
|
||||||
|
repo-token: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
stale-pr-message: 'This pull request is stale because it has been open 6 months with no activity. Please comment or this will be closed in 14 days.'
|
||||||
|
stale-issue-message: 'This issue is stale because it has been open 6 months with no activity. Please comment or this will be closed in 14 days.'
|
||||||
|
days-before-stale: 182 # 6 months
|
||||||
|
days-before-close: 14
|
||||||
|
operations-per-run: 1500
|
||||||
|
exempt-issue-labels: not-stale
|
||||||
|
exempt-pr-labels: not-stale
|
||||||
|
exempt-all-milestones: true
|
||||||
32
.gitignore
vendored
@@ -2,6 +2,7 @@
|
|||||||
*_wire.bin
|
*_wire.bin
|
||||||
.DS_Store
|
.DS_Store
|
||||||
**/.build
|
**/.build
|
||||||
|
build
|
||||||
**/Packages
|
**/Packages
|
||||||
/*.xcodeproj
|
/*.xcodeproj
|
||||||
**/xcuserdata/
|
**/xcuserdata/
|
||||||
@@ -45,12 +46,16 @@ project.properties
|
|||||||
proguard-project.txt
|
proguard-project.txt
|
||||||
linklint_results
|
linklint_results
|
||||||
Makefile
|
Makefile
|
||||||
|
flatbenchmark
|
||||||
|
flatbenchmark.exe
|
||||||
flatc
|
flatc
|
||||||
flatc.exe
|
flatc.exe
|
||||||
flathash
|
flathash
|
||||||
flathash.exe
|
flathash.exe
|
||||||
flattests
|
flattests
|
||||||
flattests.exe
|
flattests.exe
|
||||||
|
flattests_cpp17
|
||||||
|
flattests_cpp17.exe
|
||||||
flatsamplebinary
|
flatsamplebinary
|
||||||
flatsamplebinary.exe
|
flatsamplebinary.exe
|
||||||
flatsampletext
|
flatsampletext
|
||||||
@@ -69,13 +74,11 @@ tests/monsterdata_go_wire.mon
|
|||||||
tests/monsterdata_javascript_wire.mon
|
tests/monsterdata_javascript_wire.mon
|
||||||
tests/monsterdata_lobster_wire.mon
|
tests/monsterdata_lobster_wire.mon
|
||||||
tests/monsterdata_rust_wire.mon
|
tests/monsterdata_rust_wire.mon
|
||||||
tests/unicode_test.mon
|
|
||||||
tests/ts/
|
|
||||||
tests/php/
|
tests/php/
|
||||||
CMakeLists.txt.user
|
CMakeLists.txt.user
|
||||||
CMakeScripts/**
|
CMakeScripts/**
|
||||||
CTestTestfile.cmake
|
CTestTestfile.cmake
|
||||||
FlatbuffersConfigVersion.cmake
|
FlatBuffersConfigVersion.cmake
|
||||||
FlatBuffers.cbp
|
FlatBuffers.cbp
|
||||||
build/Xcode/FlatBuffers.xcodeproj/project.xcworkspace/**
|
build/Xcode/FlatBuffers.xcodeproj/project.xcworkspace/**
|
||||||
build/Xcode/FlatBuffers.xcodeproj/xcuserdata/**
|
build/Xcode/FlatBuffers.xcodeproj/xcuserdata/**
|
||||||
@@ -102,7 +105,10 @@ android/build/
|
|||||||
samples/android/.externalNativeBuild/
|
samples/android/.externalNativeBuild/
|
||||||
samples/android/.gradle/
|
samples/android/.gradle/
|
||||||
samples/android/build/
|
samples/android/build/
|
||||||
js/flatbuffers.mjs
|
js/**/*.js
|
||||||
|
js/**/*.d.ts
|
||||||
|
mjs/**/*.js
|
||||||
|
mjs/**/*.d.ts
|
||||||
/bazel-bin
|
/bazel-bin
|
||||||
/bazel-flatbuffers
|
/bazel-flatbuffers
|
||||||
/bazel-genfiles
|
/bazel-genfiles
|
||||||
@@ -122,6 +128,24 @@ dart/doc/api/
|
|||||||
Cargo.lock
|
Cargo.lock
|
||||||
.corpus**
|
.corpus**
|
||||||
.seed**
|
.seed**
|
||||||
|
.crash**
|
||||||
grpc/google/
|
grpc/google/
|
||||||
**/Package.resolved
|
**/Package.resolved
|
||||||
.clangd/**
|
.clangd/**
|
||||||
|
package-lock.json
|
||||||
|
/*.ilk
|
||||||
|
/*.pdb
|
||||||
|
.clwb
|
||||||
|
yarn-error.log
|
||||||
|
.cache/
|
||||||
|
/flatbuffers.lib
|
||||||
|
.cmake/
|
||||||
|
**/dist
|
||||||
|
**/vendor
|
||||||
|
**/go.sum
|
||||||
|
flatbuffers.pc
|
||||||
|
**/FlatBuffers.Test.Swift.xcodeproj
|
||||||
|
**/html/**
|
||||||
|
**/latex/**
|
||||||
|
# https://cmake.org/cmake/help/latest/module/FetchContent.html#variable:FETCHCONTENT_BASE_DIR
|
||||||
|
_deps/
|
||||||
56
.travis.yml
@@ -104,6 +104,7 @@ matrix:
|
|||||||
- if [ "$TRAVIS_OS_NAME" == "linux" ]; then sudo ln -s -v -f $(which gcc-$GCC_VERSION) /usr/bin/gcc; fi
|
- if [ "$TRAVIS_OS_NAME" == "linux" ]; then sudo ln -s -v -f $(which gcc-$GCC_VERSION) /usr/bin/gcc; fi
|
||||||
|
|
||||||
script:
|
script:
|
||||||
|
- pip install cmake
|
||||||
- bash .travis/check-sources.sh
|
- bash .travis/check-sources.sh
|
||||||
- bash grpc/build_grpc.sh
|
- bash grpc/build_grpc.sh
|
||||||
- cmake .
|
- cmake .
|
||||||
@@ -114,7 +115,6 @@ matrix:
|
|||||||
-DFLATBUFFERS_CODE_SANITIZE=ON
|
-DFLATBUFFERS_CODE_SANITIZE=ON
|
||||||
- cmake --build . --target all --clean-first -- -j${JOBS}
|
- cmake --build . --target all --clean-first -- -j${JOBS}
|
||||||
- LD_LIBRARY_PATH=$TRAVIS_BUILD_DIR/google/grpc/install/lib ctest --extra-verbose --output-on-failure
|
- LD_LIBRARY_PATH=$TRAVIS_BUILD_DIR/google/grpc/install/lib ctest --extra-verbose --output-on-failure
|
||||||
- bash .travis/check-generate-code.sh
|
|
||||||
|
|
||||||
- language: cpp
|
- language: cpp
|
||||||
os: osx
|
os: osx
|
||||||
@@ -125,6 +125,11 @@ matrix:
|
|||||||
- BUILD_TYPE=Release
|
- BUILD_TYPE=Release
|
||||||
|
|
||||||
script:
|
script:
|
||||||
|
- pip install --user cmake
|
||||||
|
- mkdir ~/cmake_path
|
||||||
|
- ln -s $(find ~/Library/Python -name cmake -type f | head -n 1) ~/cmake_path/cmake
|
||||||
|
- ln -s $(find ~/Library/Python -name ctest -type f | head -n 1) ~/cmake_path/ctest
|
||||||
|
- export PATH=~/cmake_path:${PATH}
|
||||||
- bash grpc/build_grpc.sh
|
- bash grpc/build_grpc.sh
|
||||||
- cmake .
|
- cmake .
|
||||||
-DCMAKE_BUILD_TYPE=$BUILD_TYPE
|
-DCMAKE_BUILD_TYPE=$BUILD_TYPE
|
||||||
@@ -134,7 +139,6 @@ matrix:
|
|||||||
-DFLATBUFFERS_CODE_SANITIZE=ON
|
-DFLATBUFFERS_CODE_SANITIZE=ON
|
||||||
- cmake --build . -- -j${JOBS}
|
- cmake --build . -- -j${JOBS}
|
||||||
- DYLD_LIBRARY_PATH=$TRAVIS_BUILD_DIR/google/grpc/install/lib ctest --extra-verbose --output-on-failure
|
- DYLD_LIBRARY_PATH=$TRAVIS_BUILD_DIR/google/grpc/install/lib ctest --extra-verbose --output-on-failure
|
||||||
- bash .travis/check-generate-code.sh
|
|
||||||
|
|
||||||
- <<: *conan-linux-master
|
- <<: *conan-linux-master
|
||||||
env: CONAN_GCC_VERSIONS=8 CONAN_DOCKER_IMAGE=conanio/gcc8
|
env: CONAN_GCC_VERSIONS=8 CONAN_DOCKER_IMAGE=conanio/gcc8
|
||||||
@@ -185,37 +189,27 @@ matrix:
|
|||||||
components:
|
components:
|
||||||
- tools
|
- tools
|
||||||
- platform-tools
|
- platform-tools
|
||||||
- build-tools-25.0.2
|
|
||||||
- android-25
|
|
||||||
- extra-android-m2repository
|
- extra-android-m2repository
|
||||||
|
licenses:
|
||||||
|
- 'android-sdk-preview-license-52d11cd2'
|
||||||
|
- 'android-sdk-license-.+'
|
||||||
|
- 'google-gdk-license-.+'
|
||||||
compiler:
|
compiler:
|
||||||
- gcc
|
- gcc
|
||||||
|
|
||||||
before_install:
|
before_install:
|
||||||
# Output something every 10 minutes or Travis kills the job
|
- echo y | sdkmanager "platforms;android-30"
|
||||||
- while sleep 540; do echo "=====[ $SECONDS seconds still running ]====="; done &
|
- echo y | sdkmanager "build-tools;30.0.2"
|
||||||
# Install the r17c version of the NDK that still so that we can continue to test with gnustl
|
- echo y | sdkmanager "ndk-bundle"
|
||||||
# and stlport.
|
- echo y | sdkmanager "cmake;3.6.4111459"
|
||||||
- export ANDROID_NDK_HOME=$HOME/android-ndk
|
|
||||||
- NDK_ZIP=$ANDROID_NDK_HOME/ndk.zip
|
|
||||||
- mkdir -p $ANDROID_NDK_HOME
|
|
||||||
- curl -o $NDK_ZIP https://dl.google.com/android/repository/android-ndk-r17c-linux-x86_64.zip
|
|
||||||
- unzip -q -d $ANDROID_NDK_HOME $NDK_ZIP
|
|
||||||
- rm $NDK_ZIP
|
|
||||||
- mv $ANDROID_NDK_HOME/android-ndk-*/* $ANDROID_NDK_HOME
|
|
||||||
- rmdir $ANDROID_NDK_HOME/android-ndk-*
|
|
||||||
- export CMAKE=$(which cmake)
|
|
||||||
# libc required for prebuilt llvm toolchain the NDK r17c.
|
|
||||||
- if [ "$TRAVIS_OS_NAME" == "linux" ]; then sudo apt-get update -qq; fi
|
|
||||||
- if [ "$TRAVIS_OS_NAME" == "linux" ]; then sudo apt-get install -qq libc6; fi
|
|
||||||
# Setup environment for Linux build which is required to build the sample.
|
|
||||||
- if [ "$TRAVIS_OS_NAME" == "linux" ]; then sudo add-apt-repository -y ppa:ubuntu-toolchain-r/test; fi
|
|
||||||
- if [ "$TRAVIS_OS_NAME" == "linux" ]; then sudo apt-get update -qq; fi
|
|
||||||
- if [ "$TRAVIS_OS_NAME" == "linux" ]; then sudo apt-get install -qq g++-$GCC_VERSION; fi
|
|
||||||
- if [ "$TRAVIS_OS_NAME" == "linux" ]; then sudo apt-get install -qq gcc-$GCC_VERSION; fi
|
|
||||||
- if [ "$TRAVIS_OS_NAME" == "linux" ]; then sudo ln -s -v -f $(which g++-$GCC_VERSION) /usr/bin/g++; fi
|
|
||||||
- if [ "$TRAVIS_OS_NAME" == "linux" ]; then sudo ln -s -v -f $(which gcc-$GCC_VERSION) /usr/bin/gcc; fi
|
|
||||||
script:
|
script:
|
||||||
- failed=0; for build_gradle in $(git ls-files | grep build.gradle); do ( cd "$(dirname "${build_gradle}")" && ./gradlew build ) || failed=1; done; exit $((failed))
|
- cmake -DFLATBUFFERS_BUILD_TESTS=OFF -DFLATBUFFERS_BUILD_FLATLIB=OFF -DFLATBUFFERS_BUILD_FLATHASH=OFF .; make; export PATH="$PATH:${PWD}"
|
||||||
# Kill the sleep loop
|
- cd android; ./gradlew clean build
|
||||||
- kill %1
|
|
||||||
|
- language: generic
|
||||||
|
if: type IN (pull_request)
|
||||||
|
os: linux
|
||||||
|
install:
|
||||||
|
- bash .travis/format_install.sh
|
||||||
|
|
||||||
|
script:
|
||||||
|
- bash .travis/format_check.sh
|
||||||
|
|||||||
@@ -1,45 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
#
|
|
||||||
# Copyright 2018 Google Inc. All rights reserved.
|
|
||||||
#
|
|
||||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
# you may not use this file except in compliance with the License.
|
|
||||||
# You may obtain a copy of the License at
|
|
||||||
#
|
|
||||||
# http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
#
|
|
||||||
# Unless required by applicable law or agreed to in writing, software
|
|
||||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
# See the License for the specific language governing permissions and
|
|
||||||
# limitations under the License.
|
|
||||||
set -e
|
|
||||||
|
|
||||||
docker build -t build_cpp_image -f tests/docker/Dockerfile.testing.cpp.debian_buster .
|
|
||||||
# Run tests with sanitizers (--cap-add SYS_PTRACE), both GCC and Clang.
|
|
||||||
cpp_test_args="--cap-add SYS_PTRACE build_cpp_image sh ./tests/docker/cpp_test.run.sh Debug"
|
|
||||||
docker run --rm $cpp_test_args
|
|
||||||
docker run --rm --env CC=/usr/bin/clang --env CXX=/usr/bin/clang++ $cpp_test_args
|
|
||||||
# Build flatc on debian once to speed up the test loop below.
|
|
||||||
docker run --name flatc_container build_cpp_image sh ./tests/docker/build_flatc.run.sh Debug
|
|
||||||
# All dependent dockers refer to 'flatc_debian_stretch'.
|
|
||||||
docker cp flatc_container:/flatbuffers/flatc flatc_debian_stretch
|
|
||||||
|
|
||||||
for f in $(ls tests/docker/languages | sort)
|
|
||||||
do
|
|
||||||
# docker pull sometimes fails for unknown reasons, probably travisci-related. this retries the pull we need a few times.
|
|
||||||
REQUIRED_BASE_IMAGE=$(cat tests/docker/languages/${f} | head -n 1 | awk ' { print $2 } ')
|
|
||||||
|
|
||||||
set +e
|
|
||||||
n=0
|
|
||||||
until [ $n -ge 5 ]
|
|
||||||
do
|
|
||||||
docker pull $REQUIRED_BASE_IMAGE && break
|
|
||||||
n=$[$n+1]
|
|
||||||
sleep 1
|
|
||||||
done
|
|
||||||
set -e
|
|
||||||
|
|
||||||
docker build -t $(echo ${f} | cut -f 3- -d .) -f tests/docker/languages/${f} .
|
|
||||||
echo "TEST OK: ${f}"
|
|
||||||
done
|
|
||||||
@@ -1,36 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
#
|
|
||||||
# Copyright 2018 Google Inc. All rights reserved.
|
|
||||||
#
|
|
||||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
# you may not use this file except in compliance with the License.
|
|
||||||
# You may obtain a copy of the License at
|
|
||||||
#
|
|
||||||
# http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
#
|
|
||||||
# Unless required by applicable law or agreed to in writing, software
|
|
||||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
# See the License for the specific language governing permissions and
|
|
||||||
# limitations under the License.
|
|
||||||
set -e
|
|
||||||
|
|
||||||
cd tests
|
|
||||||
./generate_code.sh
|
|
||||||
cd ..
|
|
||||||
|
|
||||||
# TODO: Linux and macos builds produce differences here for some reason.
|
|
||||||
git checkout HEAD -- tests/monster_test.bfbs
|
|
||||||
git checkout HEAD -- tests/arrays_test.bfbs
|
|
||||||
git checkout HEAD -- samples/monster.bfbs
|
|
||||||
|
|
||||||
if ! git diff --quiet; then
|
|
||||||
echo >&2
|
|
||||||
echo "ERROR: ********************************************************" >&2
|
|
||||||
echo "ERROR: The following differences were found after running the" >&2
|
|
||||||
echo "ERROR: tests/generate_code.sh script. Maybe you forgot to run" >&2
|
|
||||||
echo "ERROR: it after making changes in a generator or schema?" >&2
|
|
||||||
echo "ERROR: ********************************************************" >&2
|
|
||||||
echo >&2
|
|
||||||
git diff --binary --exit-code
|
|
||||||
fi
|
|
||||||
@@ -1,33 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
#
|
|
||||||
# Copyright 2018 Google Inc. All rights reserved.
|
|
||||||
#
|
|
||||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
# you may not use this file except in compliance with the License.
|
|
||||||
# You may obtain a copy of the License at
|
|
||||||
#
|
|
||||||
# http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
#
|
|
||||||
# Unless required by applicable law or agreed to in writing, software
|
|
||||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
# See the License for the specific language governing permissions and
|
|
||||||
# limitations under the License.
|
|
||||||
set -e
|
|
||||||
|
|
||||||
if [ -n "$1" ]; then
|
|
||||||
scan_dir="$1"
|
|
||||||
else
|
|
||||||
scan_dir="$( pwd )"
|
|
||||||
fi
|
|
||||||
|
|
||||||
py_checker="$0.py"
|
|
||||||
|
|
||||||
echo "scan root directory = '$scan_dir'"
|
|
||||||
python3 --version
|
|
||||||
# Scan recursively and search all *.cpp and *.h files using regex patterns.
|
|
||||||
# Assume that script running from a root of Flatbuffers working dir.
|
|
||||||
python3 $py_checker "ascii" "$scan_dir/include" "\.h$"
|
|
||||||
python3 $py_checker "ascii" "$scan_dir/src" "\.cpp$"
|
|
||||||
python3 $py_checker "ascii" "$scan_dir/tests" "\.h$"
|
|
||||||
python3 $py_checker "utf-8" "$scan_dir/tests" "\.cpp$"
|
|
||||||
@@ -1,35 +0,0 @@
|
|||||||
import os
|
|
||||||
import re
|
|
||||||
import sys
|
|
||||||
|
|
||||||
def check_encoding(encoding, scan_dir, regex_pattern):
|
|
||||||
fname = None
|
|
||||||
try:
|
|
||||||
assert encoding in ['ascii', 'utf-8'], "unexpected encoding"
|
|
||||||
cmp = re.compile(regex_pattern)
|
|
||||||
for root, dirs, files in os.walk(scan_dir):
|
|
||||||
fname = root
|
|
||||||
cmp_list = [f for f in files if cmp.search(f) is not None]
|
|
||||||
for f in cmp_list:
|
|
||||||
fname = os.path.join(root, f)
|
|
||||||
with open(fname, mode='rb') as test_file:
|
|
||||||
btext = test_file.read()
|
|
||||||
# check encoding
|
|
||||||
btext.decode(encoding=encoding, errors="strict")
|
|
||||||
if encoding == "utf-8" and btext.startswith(b'\xEF\xBB\xBF'):
|
|
||||||
raise ValueError("unexpected BOM in file")
|
|
||||||
# check LF line endings
|
|
||||||
LF = btext.count(b'\n')
|
|
||||||
CR = btext.count(b'\r')
|
|
||||||
if CR!=0:
|
|
||||||
raise ValueError("invalid line endings: LF({})/CR({})".format(LF, CR))
|
|
||||||
except Exception as err:
|
|
||||||
print("ERROR with [{}]: {}".format(fname, err))
|
|
||||||
return -1
|
|
||||||
else:
|
|
||||||
return 0
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
# python check-sources.sh.py 'ascii' '.' '.*\.(cpp|h)$'
|
|
||||||
res = check_encoding(sys.argv[1], sys.argv[2], sys.argv[3])
|
|
||||||
sys.exit(0 if res == 0 else -1)
|
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
|
|
||||||
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
|
||||||
PROD_REPOSITORY="https://upload.pypi.org/legacy/"
|
|
||||||
TEST_REPOSITORY="https://test.pypi.org/legacy/"
|
|
||||||
|
|
||||||
twine upload \
|
|
||||||
--username "$PYPI_USERNAME" \
|
|
||||||
--password "$PYPI_PASSWORD" \
|
|
||||||
--repository-url "$PROD_REPOSITORY" \
|
|
||||||
"$DIR/../python/dist/"*
|
|
||||||
|
|
||||||
@@ -1,15 +1,30 @@
|
|||||||
licenses(["notice"])
|
|
||||||
|
|
||||||
load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_library")
|
load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_library")
|
||||||
|
|
||||||
|
licenses(["notice"])
|
||||||
|
|
||||||
package(
|
package(
|
||||||
default_visibility = ["//visibility:public"],
|
default_visibility = ["//visibility:public"],
|
||||||
)
|
)
|
||||||
|
|
||||||
exports_files([
|
exports_files([
|
||||||
"LICENSE",
|
"LICENSE",
|
||||||
|
"tsconfig.json",
|
||||||
])
|
])
|
||||||
|
|
||||||
|
config_setting(
|
||||||
|
name = "platform_freebsd",
|
||||||
|
constraint_values = [
|
||||||
|
"@platforms//os:freebsd",
|
||||||
|
],
|
||||||
|
)
|
||||||
|
|
||||||
|
config_setting(
|
||||||
|
name = "platform_openbsd",
|
||||||
|
constraint_values = [
|
||||||
|
"@platforms//os:openbsd",
|
||||||
|
],
|
||||||
|
)
|
||||||
|
|
||||||
# Public flatc library to compile flatbuffer files at runtime.
|
# Public flatc library to compile flatbuffer files at runtime.
|
||||||
cc_library(
|
cc_library(
|
||||||
name = "flatbuffers",
|
name = "flatbuffers",
|
||||||
@@ -23,10 +38,20 @@ cc_library(
|
|||||||
filegroup(
|
filegroup(
|
||||||
name = "public_headers",
|
name = "public_headers",
|
||||||
srcs = [
|
srcs = [
|
||||||
|
"include/flatbuffers/allocator.h",
|
||||||
|
"include/flatbuffers/array.h",
|
||||||
"include/flatbuffers/base.h",
|
"include/flatbuffers/base.h",
|
||||||
|
"include/flatbuffers/bfbs_generator.h",
|
||||||
|
"include/flatbuffers/buffer.h",
|
||||||
|
"include/flatbuffers/buffer_ref.h",
|
||||||
"include/flatbuffers/code_generators.h",
|
"include/flatbuffers/code_generators.h",
|
||||||
|
"include/flatbuffers/default_allocator.h",
|
||||||
|
"include/flatbuffers/detached_buffer.h",
|
||||||
|
"include/flatbuffers/flatbuffer_builder.h",
|
||||||
"include/flatbuffers/flatbuffers.h",
|
"include/flatbuffers/flatbuffers.h",
|
||||||
|
"include/flatbuffers/flex_flat_util.h",
|
||||||
"include/flatbuffers/flexbuffers.h",
|
"include/flatbuffers/flexbuffers.h",
|
||||||
|
"include/flatbuffers/grpc.h",
|
||||||
"include/flatbuffers/hash.h",
|
"include/flatbuffers/hash.h",
|
||||||
"include/flatbuffers/idl.h",
|
"include/flatbuffers/idl.h",
|
||||||
"include/flatbuffers/minireflect.h",
|
"include/flatbuffers/minireflect.h",
|
||||||
@@ -34,7 +59,13 @@ filegroup(
|
|||||||
"include/flatbuffers/reflection_generated.h",
|
"include/flatbuffers/reflection_generated.h",
|
||||||
"include/flatbuffers/registry.h",
|
"include/flatbuffers/registry.h",
|
||||||
"include/flatbuffers/stl_emulation.h",
|
"include/flatbuffers/stl_emulation.h",
|
||||||
|
"include/flatbuffers/string.h",
|
||||||
|
"include/flatbuffers/struct.h",
|
||||||
|
"include/flatbuffers/table.h",
|
||||||
"include/flatbuffers/util.h",
|
"include/flatbuffers/util.h",
|
||||||
|
"include/flatbuffers/vector.h",
|
||||||
|
"include/flatbuffers/vector_downward.h",
|
||||||
|
"include/flatbuffers/verifier.h",
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -50,6 +81,7 @@ cc_library(
|
|||||||
# Public flatc compiler.
|
# Public flatc compiler.
|
||||||
cc_binary(
|
cc_binary(
|
||||||
name = "flatc",
|
name = "flatc",
|
||||||
|
data = ["//reflection:reflection_fbs_schema"],
|
||||||
deps = [
|
deps = [
|
||||||
"//src:flatc",
|
"//src:flatc",
|
||||||
],
|
],
|
||||||
@@ -72,6 +104,8 @@ cc_library(
|
|||||||
"include/flatbuffers/flexbuffers.h",
|
"include/flatbuffers/flexbuffers.h",
|
||||||
"include/flatbuffers/stl_emulation.h",
|
"include/flatbuffers/stl_emulation.h",
|
||||||
"include/flatbuffers/util.h",
|
"include/flatbuffers/util.h",
|
||||||
|
"include/flatbuffers/vector.h",
|
||||||
|
"include/flatbuffers/verifier.h",
|
||||||
],
|
],
|
||||||
linkstatic = 1,
|
linkstatic = 1,
|
||||||
strip_include_prefix = "/include",
|
strip_include_prefix = "/include",
|
||||||
36
CHANGELOG.md
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
# Flatbuffers Change Log
|
||||||
|
|
||||||
|
All major or breaking changes will be documented in this file, as well as any
|
||||||
|
new features that should be highlighted. Minor fixes or improvements are not
|
||||||
|
necessarily listed.
|
||||||
|
|
||||||
|
## 2.0.8 (Aug 29 2022)
|
||||||
|
|
||||||
|
* Fix for `--keep-prefix` the was generating the wrong include statements for
|
||||||
|
C++ (#7469). The bug was introduced in 2.0.7.
|
||||||
|
|
||||||
|
* Added the `Verifier::Options` option struct to allow specifying runtime
|
||||||
|
configuration settings for the verifier (#7489). This allows to skip verifying
|
||||||
|
nested flatbuffers, a on-by-default change that was introduced in 2.0.7. This
|
||||||
|
deprecates the existing `Verifier` constructor, which may be removed in a future
|
||||||
|
version.
|
||||||
|
|
||||||
|
* Refactor of `tests/test.cpp` that lead to ~10% speedup in compilation of the
|
||||||
|
entire project (#7487).
|
||||||
|
|
||||||
|
## 2.0.7 (Aug 22 2022)
|
||||||
|
|
||||||
|
* This is the first version with an explicit change log, so all the previous
|
||||||
|
features will not be listed.
|
||||||
|
|
||||||
|
* Verifier now checks that buffers are at least the minimum size required to be
|
||||||
|
a flatbuffers (12 bytes). This includes nested flatbuffers, which previously
|
||||||
|
could be declared valid at size 0.
|
||||||
|
|
||||||
|
* Annotated binaries. Given a flatbuffer binary and a schema (or binary schema)
|
||||||
|
one can generate an annotated flatbuffer (.afb) to describe each byte in the
|
||||||
|
binary with schema metadata and value.
|
||||||
|
|
||||||
|
* First binary schema generator (Lua) to generate Lua code via a .bfbs file.
|
||||||
|
This is mostly an implementation detail of flatc internals, but will be slowly
|
||||||
|
applied to the other language generators.
|
||||||
@@ -150,3 +150,274 @@ function(build_flatbuffers flatbuffers_schemas
|
|||||||
${copy_text_schemas_dir})
|
${copy_text_schemas_dir})
|
||||||
endif()
|
endif()
|
||||||
endfunction()
|
endfunction()
|
||||||
|
|
||||||
|
# Creates a target that can be linked against that generates flatbuffer headers.
|
||||||
|
#
|
||||||
|
# This function takes a target name and a list of schemas. You can also specify
|
||||||
|
# other flagc flags using the FLAGS option to change the behavior of the flatc
|
||||||
|
# tool.
|
||||||
|
#
|
||||||
|
# Arguments:
|
||||||
|
# TARGET: The name of the target to generate.
|
||||||
|
# SCHEMAS: The list of schema files to generate code for.
|
||||||
|
# BINARY_SCHEMAS_DIR: Optional. The directory in which to generate binary
|
||||||
|
# schemas. Binary schemas will only be generated if a path is provided.
|
||||||
|
# INCLUDE: Optional. Search for includes in the specified paths. (Use this
|
||||||
|
# instead of "-I <path>" and the FLAGS option so that CMake is aware of
|
||||||
|
# the directories that need to be searched).
|
||||||
|
# INCLUDE_PREFIX: Optional. The directory in which to place the generated
|
||||||
|
# files. Use this instead of the --include-prefix option.
|
||||||
|
# FLAGS: Optional. A list of any additional flags that you would like to pass
|
||||||
|
# to flatc.
|
||||||
|
#
|
||||||
|
# Example:
|
||||||
|
#
|
||||||
|
# flatbuffers_generate_headers(
|
||||||
|
# TARGET my_generated_headers_target
|
||||||
|
# INCLUDE_PREFIX ${MY_INCLUDE_PREFIX}"
|
||||||
|
# SCHEMAS ${MY_SCHEMA_FILES}
|
||||||
|
# BINARY_SCHEMAS_DIR "${MY_BINARY_SCHEMA_DIRECTORY}"
|
||||||
|
# FLAGS --gen-object-api)
|
||||||
|
#
|
||||||
|
# target_link_libraries(MyExecutableTarget
|
||||||
|
# PRIVATE my_generated_headers_target
|
||||||
|
# )
|
||||||
|
function(flatbuffers_generate_headers)
|
||||||
|
# Parse function arguments.
|
||||||
|
set(options)
|
||||||
|
set(one_value_args
|
||||||
|
"TARGET"
|
||||||
|
"INCLUDE_PREFIX"
|
||||||
|
"BINARY_SCHEMAS_DIR")
|
||||||
|
set(multi_value_args
|
||||||
|
"SCHEMAS"
|
||||||
|
"INCLUDE"
|
||||||
|
"FLAGS")
|
||||||
|
cmake_parse_arguments(
|
||||||
|
PARSE_ARGV 0
|
||||||
|
FLATBUFFERS_GENERATE_HEADERS
|
||||||
|
"${options}"
|
||||||
|
"${one_value_args}"
|
||||||
|
"${multi_value_args}")
|
||||||
|
|
||||||
|
# Test if including from FindFlatBuffers
|
||||||
|
if(FLATBUFFERS_FLATC_EXECUTABLE)
|
||||||
|
set(FLATC_TARGET "")
|
||||||
|
set(FLATC ${FLATBUFFERS_FLATC_EXECUTABLE})
|
||||||
|
else()
|
||||||
|
set(FLATC_TARGET flatc)
|
||||||
|
set(FLATC flatc)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
set(working_dir "${CMAKE_CURRENT_SOURCE_DIR}")
|
||||||
|
|
||||||
|
# Generate the include files parameters.
|
||||||
|
set(include_params "")
|
||||||
|
foreach (include_dir ${FLATBUFFERS_GENERATE_HEADERS_INCLUDE})
|
||||||
|
set(include_params -I ${include_dir} ${include_params})
|
||||||
|
endforeach()
|
||||||
|
|
||||||
|
# Create a directory to place the generated code.
|
||||||
|
set(generated_target_dir "${CMAKE_CURRENT_BINARY_DIR}/${FLATBUFFERS_GENERATE_HEADERS_TARGET}")
|
||||||
|
set(generated_include_dir "${generated_target_dir}")
|
||||||
|
if (NOT ${FLATBUFFERS_GENERATE_HEADERS_INCLUDE_PREFIX} STREQUAL "")
|
||||||
|
set(generated_include_dir "${generated_include_dir}/${FLATBUFFERS_GENERATE_HEADERS_INCLUDE_PREFIX}")
|
||||||
|
list(APPEND FLATBUFFERS_GENERATE_HEADERS_FLAGS
|
||||||
|
"--include-prefix" ${FLATBUFFERS_GENERATE_HEADERS_INCLUDE_PREFIX})
|
||||||
|
endif()
|
||||||
|
|
||||||
|
# Create rules to generate the code for each schema.
|
||||||
|
foreach(schema ${FLATBUFFERS_GENERATE_HEADERS_SCHEMAS})
|
||||||
|
get_filename_component(filename ${schema} NAME_WE)
|
||||||
|
set(generated_include "${generated_include_dir}/${filename}_generated.h")
|
||||||
|
|
||||||
|
# Generate files for grpc if needed
|
||||||
|
set(generated_source_file)
|
||||||
|
if("${FLATBUFFERS_GENERATE_HEADERS_FLAGS}" MATCHES "--grpc")
|
||||||
|
# Check if schema file contain a rpc_service definition
|
||||||
|
file(STRINGS ${schema} has_grpc REGEX "rpc_service")
|
||||||
|
if(has_grpc)
|
||||||
|
list(APPEND generated_include "${generated_include_dir}/${filename}.grpc.fb.h")
|
||||||
|
set(generated_source_file "${generated_include_dir}/${filename}.grpc.fb.cc")
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
|
|
||||||
|
add_custom_command(
|
||||||
|
OUTPUT ${generated_include} ${generated_source_file}
|
||||||
|
COMMAND ${FLATC} ${FLATC_ARGS}
|
||||||
|
-o ${generated_include_dir}
|
||||||
|
${include_params}
|
||||||
|
-c ${schema}
|
||||||
|
${FLATBUFFERS_GENERATE_HEADERS_FLAGS}
|
||||||
|
DEPENDS ${FLATC_TARGET} ${schema}
|
||||||
|
WORKING_DIRECTORY "${working_dir}"
|
||||||
|
COMMENT "Building ${schema} flatbuffers...")
|
||||||
|
list(APPEND all_generated_header_files ${generated_include})
|
||||||
|
list(APPEND all_generated_source_files ${generated_source_file})
|
||||||
|
|
||||||
|
# Geneate the binary flatbuffers schemas if instructed to.
|
||||||
|
if (NOT ${FLATBUFFERS_GENERATE_HEADERS_BINARY_SCHEMAS_DIR} STREQUAL "")
|
||||||
|
set(binary_schema
|
||||||
|
"${FLATBUFFERS_GENERATE_HEADERS_BINARY_SCHEMAS_DIR}/${filename}.bfbs")
|
||||||
|
add_custom_command(
|
||||||
|
OUTPUT ${binary_schema}
|
||||||
|
COMMAND ${FLATC} -b --schema
|
||||||
|
-o ${FLATBUFFERS_GENERATE_HEADERS_BINARY_SCHEMAS_DIR}
|
||||||
|
${include_params}
|
||||||
|
${schema}
|
||||||
|
DEPENDS ${FLATC_TARGET} ${schema}
|
||||||
|
WORKING_DIRECTORY "${working_dir}")
|
||||||
|
list(APPEND all_generated_binary_files ${binary_schema})
|
||||||
|
endif()
|
||||||
|
endforeach()
|
||||||
|
|
||||||
|
# Set up interface library
|
||||||
|
add_library(${FLATBUFFERS_GENERATE_HEADERS_TARGET} INTERFACE)
|
||||||
|
target_sources(
|
||||||
|
${FLATBUFFERS_GENERATE_HEADERS_TARGET}
|
||||||
|
INTERFACE
|
||||||
|
${all_generated_header_files}
|
||||||
|
${all_generated_binary_files}
|
||||||
|
${all_generated_source_files}
|
||||||
|
${FLATBUFFERS_GENERATE_HEADERS_SCHEMAS})
|
||||||
|
add_dependencies(
|
||||||
|
${FLATBUFFERS_GENERATE_HEADERS_TARGET}
|
||||||
|
${FLATC}
|
||||||
|
${FLATBUFFERS_GENERATE_HEADERS_SCHEMAS})
|
||||||
|
target_include_directories(
|
||||||
|
${FLATBUFFERS_GENERATE_HEADERS_TARGET}
|
||||||
|
INTERFACE ${generated_target_dir})
|
||||||
|
|
||||||
|
# Organize file layout for IDEs.
|
||||||
|
source_group(
|
||||||
|
TREE "${generated_target_dir}"
|
||||||
|
PREFIX "Flatbuffers/Generated/Headers Files"
|
||||||
|
FILES ${all_generated_header_files})
|
||||||
|
source_group(
|
||||||
|
TREE "${generated_target_dir}"
|
||||||
|
PREFIX "Flatbuffers/Generated/Source Files"
|
||||||
|
FILES ${all_generated_source_files})
|
||||||
|
source_group(
|
||||||
|
TREE ${working_dir}
|
||||||
|
PREFIX "Flatbuffers/Schemas"
|
||||||
|
FILES ${FLATBUFFERS_GENERATE_HEADERS_SCHEMAS})
|
||||||
|
if (NOT ${FLATBUFFERS_GENERATE_HEADERS_BINARY_SCHEMAS_DIR} STREQUAL "")
|
||||||
|
source_group(
|
||||||
|
TREE "${FLATBUFFERS_GENERATE_HEADERS_BINARY_SCHEMAS_DIR}"
|
||||||
|
PREFIX "Flatbuffers/Generated/Binary Schemas"
|
||||||
|
FILES ${all_generated_binary_files})
|
||||||
|
endif()
|
||||||
|
endfunction()
|
||||||
|
|
||||||
|
# Creates a target that can be linked against that generates flatbuffer binaries
|
||||||
|
# from json files.
|
||||||
|
#
|
||||||
|
# This function takes a target name and a list of schemas and Json files. You
|
||||||
|
# can also specify other flagc flags and options to change the behavior of the
|
||||||
|
# flatc compiler.
|
||||||
|
#
|
||||||
|
# Adding this target to your executable ensurses that the flatbuffer binaries
|
||||||
|
# are compiled before your executable is run.
|
||||||
|
#
|
||||||
|
# Arguments:
|
||||||
|
# TARGET: The name of the target to generate.
|
||||||
|
# JSON_FILES: The list of json files to compile to flatbuffers binaries.
|
||||||
|
# SCHEMA: The flatbuffers schema of the Json files to be compiled.
|
||||||
|
# INCLUDE: Optional. Search for includes in the specified paths. (Use this
|
||||||
|
# instead of "-I <path>" and the FLAGS option so that CMake is aware of
|
||||||
|
# the directories that need to be searched).
|
||||||
|
# OUTPUT_DIR: The directly where the generated flatbuffers binaries should be
|
||||||
|
# placed.
|
||||||
|
# FLAGS: Optional. A list of any additional flags that you would like to pass
|
||||||
|
# to flatc.
|
||||||
|
#
|
||||||
|
# Example:
|
||||||
|
#
|
||||||
|
# flatbuffers_generate_binary_files(
|
||||||
|
# TARGET my_binary_data
|
||||||
|
# SCHEMA "${MY_SCHEMA_DIR}/my_example_schema.fbs"
|
||||||
|
# JSON_FILES ${MY_JSON_FILES}
|
||||||
|
# OUTPUT_DIR "${MY_BINARY_DATA_DIRECTORY}"
|
||||||
|
# FLAGS --strict-json)
|
||||||
|
#
|
||||||
|
# target_link_libraries(MyExecutableTarget
|
||||||
|
# PRIVATE my_binary_data
|
||||||
|
# )
|
||||||
|
function(flatbuffers_generate_binary_files)
|
||||||
|
# Parse function arguments.
|
||||||
|
set(options)
|
||||||
|
set(one_value_args
|
||||||
|
"TARGET"
|
||||||
|
"SCHEMA"
|
||||||
|
"OUTPUT_DIR")
|
||||||
|
set(multi_value_args
|
||||||
|
"JSON_FILES"
|
||||||
|
"INCLUDE"
|
||||||
|
"FLAGS")
|
||||||
|
cmake_parse_arguments(
|
||||||
|
PARSE_ARGV 0
|
||||||
|
FLATBUFFERS_GENERATE_BINARY_FILES
|
||||||
|
"${options}"
|
||||||
|
"${one_value_args}"
|
||||||
|
"${multi_value_args}")
|
||||||
|
|
||||||
|
# Test if including from FindFlatBuffers
|
||||||
|
if(FLATBUFFERS_FLATC_EXECUTABLE)
|
||||||
|
set(FLATC_TARGET "")
|
||||||
|
set(FLATC ${FLATBUFFERS_FLATC_EXECUTABLE})
|
||||||
|
else()
|
||||||
|
set(FLATC_TARGET flatc)
|
||||||
|
set(FLATC flatc)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
set(working_dir "${CMAKE_CURRENT_SOURCE_DIR}")
|
||||||
|
|
||||||
|
# Generate the include files parameters.
|
||||||
|
set(include_params "")
|
||||||
|
foreach (include_dir ${FLATBUFFERS_GENERATE_BINARY_FILES_INCLUDE})
|
||||||
|
set(include_params -I ${include_dir} ${include_params})
|
||||||
|
endforeach()
|
||||||
|
|
||||||
|
# Create rules to generate the flatbuffers binary for each json file.
|
||||||
|
foreach(json_file ${FLATBUFFERS_GENERATE_BINARY_FILES_JSON_FILES})
|
||||||
|
get_filename_component(filename ${json_file} NAME_WE)
|
||||||
|
set(generated_binary_file "${FLATBUFFERS_GENERATE_BINARY_FILES_OUTPUT_DIR}/${filename}.bin")
|
||||||
|
add_custom_command(
|
||||||
|
OUTPUT ${generated_binary_file}
|
||||||
|
COMMAND ${FLATC} ${FLATC_ARGS}
|
||||||
|
-o ${FLATBUFFERS_GENERATE_BINARY_FILES_OUTPUT_DIR}
|
||||||
|
${include_params}
|
||||||
|
-b ${FLATBUFFERS_GENERATE_BINARY_FILES_SCHEMA} ${json_file}
|
||||||
|
${FLATBUFFERS_GENERATE_BINARY_FILES_FLAGS}
|
||||||
|
DEPENDS ${FLATC_TARGET} ${json_file}
|
||||||
|
WORKING_DIRECTORY "${working_dir}"
|
||||||
|
COMMENT "Building ${json_file} binary flatbuffers...")
|
||||||
|
list(APPEND all_generated_binary_files ${generated_binary_file})
|
||||||
|
endforeach()
|
||||||
|
|
||||||
|
# Set up interface library
|
||||||
|
add_library(${FLATBUFFERS_GENERATE_BINARY_FILES_TARGET} INTERFACE)
|
||||||
|
target_sources(
|
||||||
|
${FLATBUFFERS_GENERATE_BINARY_FILES_TARGET}
|
||||||
|
INTERFACE
|
||||||
|
${all_generated_binary_files}
|
||||||
|
${FLATBUFFERS_GENERATE_BINARY_FILES_JSON_FILES}
|
||||||
|
${FLATBUFFERS_GENERATE_BINARY_FILES_SCHEMA})
|
||||||
|
add_dependencies(
|
||||||
|
${FLATBUFFERS_GENERATE_BINARY_FILES_TARGET}
|
||||||
|
${FLATC})
|
||||||
|
|
||||||
|
# Organize file layout for IDEs.
|
||||||
|
source_group(
|
||||||
|
TREE ${working_dir}
|
||||||
|
PREFIX "Flatbuffers/JSON Files"
|
||||||
|
FILES ${FLATBUFFERS_GENERATE_BINARY_FILES_JSON_FILES})
|
||||||
|
source_group(
|
||||||
|
TREE ${working_dir}
|
||||||
|
PREFIX "Flatbuffers/Schemas"
|
||||||
|
FILES ${FLATBUFFERS_GENERATE_BINARY_FILES_SCHEMA})
|
||||||
|
source_group(
|
||||||
|
TREE ${FLATBUFFERS_GENERATE_BINARY_FILES_OUTPUT_DIR}
|
||||||
|
PREFIX "Flatbuffers/Generated/Binary Files"
|
||||||
|
FILES ${all_generated_binary_files})
|
||||||
|
endfunction()
|
||||||
|
|||||||
780
CMake/CMakeLists_legacy.cmake.in
Normal file
@@ -0,0 +1,780 @@
|
|||||||
|
# This was the legacy <root>/CMakeLists.txt that supported cmake version 2.8.12.
|
||||||
|
# It was originally copied on Jan 30 2022, and is conditionally included in the
|
||||||
|
# current <root>/CMakeLists.txt if the cmake version used is older than the new
|
||||||
|
# minimum version.
|
||||||
|
#
|
||||||
|
# Only add to this file to fix immediate issues or if a change cannot be made
|
||||||
|
# <root>/CMakeList.txt in a compatible way.
|
||||||
|
|
||||||
|
if (POLICY CMP0048)
|
||||||
|
cmake_policy(SET CMP0048 NEW)
|
||||||
|
if(CMAKE_VERSION VERSION_LESS 3.9)
|
||||||
|
project(FlatBuffers
|
||||||
|
VERSION 2.0.0
|
||||||
|
LANGUAGES CXX)
|
||||||
|
else()
|
||||||
|
project(FlatBuffers
|
||||||
|
DESCRIPTION "Flatbuffers serialization library"
|
||||||
|
VERSION 2.0.0
|
||||||
|
LANGUAGES CXX)
|
||||||
|
endif()
|
||||||
|
else()
|
||||||
|
project(FlatBuffers)
|
||||||
|
endif (POLICY CMP0048)
|
||||||
|
|
||||||
|
include(CMake/Version.cmake)
|
||||||
|
|
||||||
|
# generate compile_commands.json
|
||||||
|
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
||||||
|
|
||||||
|
# NOTE: Code coverage only works on Linux & OSX.
|
||||||
|
option(FLATBUFFERS_CODE_COVERAGE "Enable the code coverage build option." OFF)
|
||||||
|
option(FLATBUFFERS_BUILD_TESTS "Enable the build of tests and samples." ON)
|
||||||
|
option(FLATBUFFERS_INSTALL "Enable the installation of targets." ON)
|
||||||
|
option(FLATBUFFERS_BUILD_FLATLIB "Enable the build of the flatbuffers library"
|
||||||
|
ON)
|
||||||
|
option(FLATBUFFERS_BUILD_FLATC "Enable the build of the flatbuffers compiler"
|
||||||
|
ON)
|
||||||
|
option(FLATBUFFERS_STATIC_FLATC "Build flatbuffers compiler with -static flag"
|
||||||
|
OFF)
|
||||||
|
option(FLATBUFFERS_BUILD_FLATHASH "Enable the build of flathash" ON)
|
||||||
|
option(FLATBUFFERS_BUILD_BENCHMARKS "Enable the build of flatbenchmark. \"
|
||||||
|
Requires C++11."
|
||||||
|
OFF)
|
||||||
|
option(FLATBUFFERS_BUILD_GRPCTEST "Enable the build of grpctest" OFF)
|
||||||
|
option(FLATBUFFERS_BUILD_SHAREDLIB
|
||||||
|
"Enable the build of the flatbuffers shared library"
|
||||||
|
OFF)
|
||||||
|
option(FLATBUFFERS_LIBCXX_WITH_CLANG "Force libc++ when using Clang" ON)
|
||||||
|
# NOTE: Sanitizer check only works on Linux & OSX (gcc & llvm).
|
||||||
|
option(FLATBUFFERS_CODE_SANITIZE
|
||||||
|
"Add '-fsanitize' flags to 'flattests' and 'flatc' targets."
|
||||||
|
OFF)
|
||||||
|
option(FLATBUFFERS_PACKAGE_REDHAT
|
||||||
|
"Build an rpm using the 'package' target."
|
||||||
|
OFF)
|
||||||
|
option(FLATBUFFERS_PACKAGE_DEBIAN
|
||||||
|
"Build an deb using the 'package' target."
|
||||||
|
OFF)
|
||||||
|
option(FLATBUFFERS_BUILD_CPP17
|
||||||
|
"Enable the build of c++17 test target. \"
|
||||||
|
Requirements: Clang6, GCC7, MSVC2017 (_MSC_VER >= 1914) or higher."
|
||||||
|
OFF)
|
||||||
|
option(FLATBUFFERS_BUILD_LEGACY
|
||||||
|
"Run C++ code generator with '--cpp-std c++0x' switch."
|
||||||
|
OFF)
|
||||||
|
option(FLATBUFFERS_ENABLE_PCH
|
||||||
|
"Enable precompile headers support for 'flatbuffers' and 'flatc'. \"
|
||||||
|
Only work if CMake supports 'target_precompile_headers'. \"
|
||||||
|
This can speed up compilation time."
|
||||||
|
OFF)
|
||||||
|
option(FLATBUFFERS_SKIP_MONSTER_EXTRA
|
||||||
|
"Skip generating monster_extra.fbs that contains non-supported numerical\"
|
||||||
|
types." OFF)
|
||||||
|
option(FLATBUFFERS_OSX_BUILD_UNIVERSAL
|
||||||
|
"Enable the build for multiple architectures on OS X (arm64, x86_64)."
|
||||||
|
ON)
|
||||||
|
|
||||||
|
if(NOT FLATBUFFERS_BUILD_FLATC AND FLATBUFFERS_BUILD_TESTS)
|
||||||
|
message(WARNING
|
||||||
|
"Cannot build tests without building the compiler. Tests will be disabled.")
|
||||||
|
set(FLATBUFFERS_BUILD_TESTS OFF)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(DEFINED FLATBUFFERS_MAX_PARSING_DEPTH)
|
||||||
|
# Override the default recursion depth limit.
|
||||||
|
add_definitions(-DFLATBUFFERS_MAX_PARSING_DEPTH=${FLATBUFFERS_MAX_PARSING_DEPTH})
|
||||||
|
message(STATUS "FLATBUFFERS_MAX_PARSING_DEPTH: ${FLATBUFFERS_MAX_PARSING_DEPTH}")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
# Auto-detect locale-narrow 'strtod_l' and 'strtoull_l' functions.
|
||||||
|
if(NOT DEFINED FLATBUFFERS_LOCALE_INDEPENDENT)
|
||||||
|
include(CheckCXXSymbolExists)
|
||||||
|
|
||||||
|
set(FLATBUFFERS_LOCALE_INDEPENDENT 0)
|
||||||
|
if(MSVC)
|
||||||
|
check_cxx_symbol_exists(_strtof_l stdlib.h FLATBUFFERS_HAS_STRTOF_L)
|
||||||
|
check_cxx_symbol_exists(_strtoui64_l stdlib.h FLATBUFFERS_HAS_STRTOULL_L)
|
||||||
|
else()
|
||||||
|
check_cxx_symbol_exists(strtof_l stdlib.h FLATBUFFERS_HAS_STRTOF_L)
|
||||||
|
check_cxx_symbol_exists(strtoull_l stdlib.h FLATBUFFERS_HAS_STRTOULL_L)
|
||||||
|
endif()
|
||||||
|
if(FLATBUFFERS_HAS_STRTOF_L AND FLATBUFFERS_HAS_STRTOULL_L)
|
||||||
|
set(FLATBUFFERS_LOCALE_INDEPENDENT 1)
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
|
add_definitions(-DFLATBUFFERS_LOCALE_INDEPENDENT=$<BOOL:${FLATBUFFERS_LOCALE_INDEPENDENT}>)
|
||||||
|
|
||||||
|
set(FlatBuffers_Library_SRCS
|
||||||
|
include/flatbuffers/allocator.h
|
||||||
|
include/flatbuffers/array.h
|
||||||
|
include/flatbuffers/base.h
|
||||||
|
include/flatbuffers/bfbs_generator.h
|
||||||
|
include/flatbuffers/buffer.h
|
||||||
|
include/flatbuffers/buffer_ref.h
|
||||||
|
include/flatbuffers/default_allocator.h
|
||||||
|
include/flatbuffers/detached_buffer.h
|
||||||
|
include/flatbuffers/flatbuffer_builder.h
|
||||||
|
include/flatbuffers/flatbuffers.h
|
||||||
|
include/flatbuffers/flexbuffers.h
|
||||||
|
include/flatbuffers/hash.h
|
||||||
|
include/flatbuffers/idl.h
|
||||||
|
include/flatbuffers/minireflect.h
|
||||||
|
include/flatbuffers/reflection.h
|
||||||
|
include/flatbuffers/reflection_generated.h
|
||||||
|
include/flatbuffers/registry.h
|
||||||
|
include/flatbuffers/stl_emulation.h
|
||||||
|
include/flatbuffers/string.h
|
||||||
|
include/flatbuffers/struct.h
|
||||||
|
include/flatbuffers/table.h
|
||||||
|
include/flatbuffers/util.h
|
||||||
|
include/flatbuffers/vector.h
|
||||||
|
include/flatbuffers/vector_downward.h
|
||||||
|
include/flatbuffers/verifier.h
|
||||||
|
src/idl_parser.cpp
|
||||||
|
src/idl_gen_text.cpp
|
||||||
|
src/reflection.cpp
|
||||||
|
src/util.cpp
|
||||||
|
)
|
||||||
|
|
||||||
|
set(FlatBuffers_Compiler_SRCS
|
||||||
|
${FlatBuffers_Library_SRCS}
|
||||||
|
src/idl_gen_cpp.cpp
|
||||||
|
src/idl_gen_csharp.cpp
|
||||||
|
src/idl_gen_dart.cpp
|
||||||
|
src/idl_gen_kotlin.cpp
|
||||||
|
src/idl_gen_go.cpp
|
||||||
|
src/idl_gen_java.cpp
|
||||||
|
src/idl_gen_ts.cpp
|
||||||
|
src/idl_gen_php.cpp
|
||||||
|
src/idl_gen_python.cpp
|
||||||
|
src/idl_gen_lobster.cpp
|
||||||
|
src/idl_gen_lua.cpp
|
||||||
|
src/idl_gen_rust.cpp
|
||||||
|
src/idl_gen_fbs.cpp
|
||||||
|
src/idl_gen_grpc.cpp
|
||||||
|
src/idl_gen_json_schema.cpp
|
||||||
|
src/idl_gen_swift.cpp
|
||||||
|
src/flatc.cpp
|
||||||
|
src/flatc_main.cpp
|
||||||
|
src/bfbs_gen.h
|
||||||
|
src/bfbs_gen_lua.h
|
||||||
|
include/flatbuffers/code_generators.h
|
||||||
|
src/bfbs_gen_lua.cpp
|
||||||
|
src/code_generators.cpp
|
||||||
|
grpc/src/compiler/schema_interface.h
|
||||||
|
grpc/src/compiler/cpp_generator.h
|
||||||
|
grpc/src/compiler/cpp_generator.cc
|
||||||
|
grpc/src/compiler/go_generator.h
|
||||||
|
grpc/src/compiler/go_generator.cc
|
||||||
|
grpc/src/compiler/java_generator.h
|
||||||
|
grpc/src/compiler/java_generator.cc
|
||||||
|
grpc/src/compiler/python_generator.h
|
||||||
|
grpc/src/compiler/python_generator.cc
|
||||||
|
grpc/src/compiler/swift_generator.h
|
||||||
|
grpc/src/compiler/swift_generator.cc
|
||||||
|
grpc/src/compiler/ts_generator.h
|
||||||
|
grpc/src/compiler/ts_generator.cc
|
||||||
|
)
|
||||||
|
|
||||||
|
set(FlatHash_SRCS
|
||||||
|
include/flatbuffers/hash.h
|
||||||
|
src/flathash.cpp
|
||||||
|
)
|
||||||
|
|
||||||
|
set(FlatBuffers_Tests_SRCS
|
||||||
|
${FlatBuffers_Library_SRCS}
|
||||||
|
src/idl_gen_fbs.cpp
|
||||||
|
tests/test.cpp
|
||||||
|
tests/test_assert.h
|
||||||
|
tests/test_assert.cpp
|
||||||
|
tests/test_builder.h
|
||||||
|
tests/test_builder.cpp
|
||||||
|
tests/native_type_test_impl.h
|
||||||
|
tests/native_type_test_impl.cpp
|
||||||
|
include/flatbuffers/code_generators.h
|
||||||
|
src/code_generators.cpp
|
||||||
|
# file generate by running compiler on tests/monster_test.fbs
|
||||||
|
${CMAKE_CURRENT_BINARY_DIR}/tests/monster_test_generated.h
|
||||||
|
# file generate by running compiler on namespace_test/namespace_test1.fbs
|
||||||
|
${CMAKE_CURRENT_BINARY_DIR}/tests/namespace_test/namespace_test1_generated.h
|
||||||
|
${CMAKE_CURRENT_BINARY_DIR}/tests/namespace_test/namespace_test2_generated.h
|
||||||
|
# file generate by running compiler on union_vector/union_vector.fbs
|
||||||
|
${CMAKE_CURRENT_BINARY_DIR}/tests/union_vector/union_vector_generated.h
|
||||||
|
# file generate by running compiler on tests/arrays_test.fbs
|
||||||
|
${CMAKE_CURRENT_BINARY_DIR}/tests/arrays_test_generated.h
|
||||||
|
# file generate by running compiler on tests/native_type_test.fbs
|
||||||
|
${CMAKE_CURRENT_BINARY_DIR}/tests/native_type_test_generated.h
|
||||||
|
# file generate by running compiler on tests/monster_extra.fbs
|
||||||
|
${CMAKE_CURRENT_BINARY_DIR}/tests/monster_extra_generated.h
|
||||||
|
# file generate by running compiler on tests/monster_test.fbs
|
||||||
|
${CMAKE_CURRENT_BINARY_DIR}/tests/monster_test_bfbs_generated.h
|
||||||
|
# file generate by running compiler on tests/optional_scalars.fbs
|
||||||
|
${CMAKE_CURRENT_BINARY_DIR}/tests/optional_scalars_generated.h
|
||||||
|
)
|
||||||
|
|
||||||
|
set(FlatBuffers_Tests_CPP17_SRCS
|
||||||
|
${FlatBuffers_Library_SRCS}
|
||||||
|
tests/test_assert.h
|
||||||
|
tests/test_assert.cpp
|
||||||
|
tests/cpp17/test_cpp17.cpp
|
||||||
|
# file generate by running compiler on tests/monster_test.fbs
|
||||||
|
${CMAKE_CURRENT_BINARY_DIR}/tests/cpp17/generated_cpp17/monster_test_generated.h
|
||||||
|
${CMAKE_CURRENT_BINARY_DIR}/tests/monster_test_generated.h
|
||||||
|
${CMAKE_CURRENT_BINARY_DIR}/tests/cpp17/generated_cpp17/optional_scalars_generated.h
|
||||||
|
${CMAKE_CURRENT_BINARY_DIR}/tests/optional_scalars_generated.h
|
||||||
|
)
|
||||||
|
|
||||||
|
set(FlatBuffers_Sample_Binary_SRCS
|
||||||
|
include/flatbuffers/flatbuffers.h
|
||||||
|
samples/sample_binary.cpp
|
||||||
|
# file generated by running compiler on samples/monster.fbs
|
||||||
|
${CMAKE_CURRENT_BINARY_DIR}/samples/monster_generated.h
|
||||||
|
)
|
||||||
|
|
||||||
|
set(FlatBuffers_Sample_Text_SRCS
|
||||||
|
${FlatBuffers_Library_SRCS}
|
||||||
|
samples/sample_text.cpp
|
||||||
|
# file generated by running compiler on samples/monster.fbs
|
||||||
|
${CMAKE_CURRENT_BINARY_DIR}/samples/monster_generated.h
|
||||||
|
)
|
||||||
|
|
||||||
|
set(FlatBuffers_Sample_BFBS_SRCS
|
||||||
|
${FlatBuffers_Library_SRCS}
|
||||||
|
samples/sample_bfbs.cpp
|
||||||
|
# file generated by running compiler on samples/monster.fbs
|
||||||
|
${CMAKE_CURRENT_BINARY_DIR}/samples/monster_generated.h
|
||||||
|
)
|
||||||
|
|
||||||
|
set(FlatBuffers_GRPCTest_SRCS
|
||||||
|
include/flatbuffers/flatbuffers.h
|
||||||
|
include/flatbuffers/grpc.h
|
||||||
|
include/flatbuffers/util.h
|
||||||
|
src/util.cpp
|
||||||
|
tests/monster_test.grpc.fb.h
|
||||||
|
tests/test_assert.h
|
||||||
|
tests/test_builder.h
|
||||||
|
tests/monster_test.grpc.fb.cc
|
||||||
|
tests/test_assert.cpp
|
||||||
|
tests/test_builder.cpp
|
||||||
|
grpc/tests/grpctest.cpp
|
||||||
|
grpc/tests/message_builder_test.cpp
|
||||||
|
# file generate by running compiler on tests/monster_test.fbs
|
||||||
|
${CMAKE_CURRENT_BINARY_DIR}/tests/monster_test_generated.h
|
||||||
|
)
|
||||||
|
|
||||||
|
# source_group(Compiler FILES ${FlatBuffers_Compiler_SRCS})
|
||||||
|
# source_group(Tests FILES ${FlatBuffers_Tests_SRCS})
|
||||||
|
|
||||||
|
if(EXISTS "${CMAKE_TOOLCHAIN_FILE}")
|
||||||
|
# do not apply any global settings if the toolchain
|
||||||
|
# is being configured externally
|
||||||
|
message(STATUS "Using toolchain file: ${CMAKE_TOOLCHAIN_FILE}.")
|
||||||
|
elseif(CMAKE_COMPILER_IS_GNUCXX)
|
||||||
|
if(CYGWIN)
|
||||||
|
set(CMAKE_CXX_FLAGS
|
||||||
|
"${CMAKE_CXX_FLAGS} -std=gnu++11")
|
||||||
|
else(CYGWIN)
|
||||||
|
set(CMAKE_CXX_FLAGS
|
||||||
|
"${CMAKE_CXX_FLAGS} -std=c++0x")
|
||||||
|
endif(CYGWIN)
|
||||||
|
set(CMAKE_CXX_FLAGS
|
||||||
|
"${CMAKE_CXX_FLAGS} -Wall -pedantic -Werror -Wextra -Werror=shadow")
|
||||||
|
set(FLATBUFFERS_PRIVATE_CXX_FLAGS "-Wold-style-cast")
|
||||||
|
if (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 4.4)
|
||||||
|
if (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 7.0)
|
||||||
|
set(CMAKE_CXX_FLAGS
|
||||||
|
"${CMAKE_CXX_FLAGS} -faligned-new -Werror=implicit-fallthrough=2")
|
||||||
|
endif()
|
||||||
|
set(CMAKE_CXX_FLAGS
|
||||||
|
"${CMAKE_CXX_FLAGS} -Wunused-result -Werror=unused-result -Wunused-parameter -Werror=unused-parameter")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
# Certain platforms such as ARM do not use signed chars by default
|
||||||
|
# which causes issues with certain bounds checks.
|
||||||
|
set(CMAKE_CXX_FLAGS
|
||||||
|
"${CMAKE_CXX_FLAGS} -fsigned-char")
|
||||||
|
|
||||||
|
# MSVC **MUST** come before the Clang check, as clang-cl is flagged by CMake as "MSVC", but it still textually
|
||||||
|
# matches as Clang in its Compiler Id :)
|
||||||
|
# Note: in CMake >= 3.14 we can check CMAKE_CXX_COMPILER_FRONTEND_VARIANT STREQUAL "GNU" or "MSVC" to differentiate...
|
||||||
|
elseif(MSVC)
|
||||||
|
# Visual Studio pedantic build settings
|
||||||
|
# warning C4512: assignment operator could not be generated
|
||||||
|
# warning C4316: object allocated on the heap may not be aligned
|
||||||
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W4 /WX /wd4512 /wd4316")
|
||||||
|
|
||||||
|
if(${CMAKE_CXX_COMPILER_ID} MATCHES "Clang")
|
||||||
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /D_CRT_SECURE_NO_WARNINGS")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
elseif(${CMAKE_CXX_COMPILER_ID} MATCHES "Clang")
|
||||||
|
if(APPLE)
|
||||||
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
|
||||||
|
|
||||||
|
if(FLATBUFFERS_OSX_BUILD_UNIVERSAL)
|
||||||
|
set(CMAKE_OSX_ARCHITECTURES "arm64;x86_64")
|
||||||
|
endif()
|
||||||
|
else()
|
||||||
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -pedantic -Werror -Wextra -Wno-unused-parameter")
|
||||||
|
set(FLATBUFFERS_PRIVATE_CXX_FLAGS "-Wold-style-cast")
|
||||||
|
if(NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 3.8)
|
||||||
|
list(APPEND FLATBUFFERS_PRIVATE_CXX_FLAGS "-Wimplicit-fallthrough" "-Wextra-semi" "-Werror=unused-private-field") # enable warning
|
||||||
|
endif()
|
||||||
|
if(FLATBUFFERS_LIBCXX_WITH_CLANG)
|
||||||
|
if(NOT "${CMAKE_SYSTEM_NAME}" MATCHES "Linux")
|
||||||
|
set(CMAKE_CXX_FLAGS
|
||||||
|
"${CMAKE_CXX_FLAGS} -stdlib=libc++")
|
||||||
|
endif()
|
||||||
|
if(NOT ("${CMAKE_SYSTEM_NAME}" MATCHES "FreeBSD" OR
|
||||||
|
"${CMAKE_SYSTEM_NAME}" MATCHES "Linux"))
|
||||||
|
set(CMAKE_EXE_LINKER_FLAGS
|
||||||
|
"${CMAKE_EXE_LINKER_FLAGS} -lc++abi")
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
|
|
||||||
|
# Certain platforms such as ARM do not use signed chars by default
|
||||||
|
# which causes issues with certain bounds checks.
|
||||||
|
set(CMAKE_CXX_FLAGS
|
||||||
|
"${CMAKE_CXX_FLAGS} -fsigned-char")
|
||||||
|
|
||||||
|
endif()
|
||||||
|
|
||||||
|
# Append FLATBUFFERS_CXX_FLAGS to CMAKE_CXX_FLAGS.
|
||||||
|
if(DEFINED FLATBUFFERS_CXX_FLAGS AND NOT EXISTS "${CMAKE_TOOLCHAIN_FILE}")
|
||||||
|
message(STATUS "extend CXX_FLAGS with ${FLATBUFFERS_CXX_FLAGS}")
|
||||||
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${FLATBUFFERS_CXX_FLAGS}")
|
||||||
|
endif()
|
||||||
|
message(STATUS "CMAKE_CXX_FLAGS: ${CMAKE_CXX_FLAGS}")
|
||||||
|
|
||||||
|
if(FLATBUFFERS_CODE_COVERAGE)
|
||||||
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -fprofile-arcs -ftest-coverage")
|
||||||
|
set(CMAKE_EXE_LINKER_FLAGS
|
||||||
|
"${CMAKE_EXE_LINKER_FLAGS} -fprofile-arcs -ftest-coverage")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
function(add_fsanitize_to_target _target _sanitizer)
|
||||||
|
if(WIN32)
|
||||||
|
target_compile_definitions(${_target} PRIVATE FLATBUFFERS_MEMORY_LEAK_TRACKING)
|
||||||
|
message(STATUS "Sanitizer MSVC::_CrtDumpMemoryLeaks added to ${_target}")
|
||||||
|
else()
|
||||||
|
# FLATBUFFERS_CODE_SANITIZE: boolean {ON,OFF,YES,NO} or string with list of sanitizer.
|
||||||
|
# List of sanitizer is string starts with '=': "=address,undefined,thread,memory".
|
||||||
|
if((${CMAKE_CXX_COMPILER_ID} MATCHES "Clang") OR
|
||||||
|
((${CMAKE_CXX_COMPILER_ID} MATCHES "GNU") AND NOT (CMAKE_CXX_COMPILER_VERSION VERSION_LESS "4.9"))
|
||||||
|
)
|
||||||
|
set(_sanitizer_flags "=address,undefined")
|
||||||
|
if(_sanitizer MATCHES "=.*")
|
||||||
|
# override default by user-defined sanitizer list
|
||||||
|
set(_sanitizer_flags ${_sanitizer})
|
||||||
|
endif()
|
||||||
|
target_compile_options(${_target} PRIVATE
|
||||||
|
-g -fsigned-char -fno-omit-frame-pointer
|
||||||
|
"-fsanitize${_sanitizer_flags}")
|
||||||
|
target_link_libraries(${_target} PRIVATE
|
||||||
|
"-fsanitize${_sanitizer_flags}")
|
||||||
|
set_property(TARGET ${_target} PROPERTY POSITION_INDEPENDENT_CODE ON)
|
||||||
|
message(STATUS "Sanitizer ${_sanitizer_flags} added to ${_target}")
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
|
endfunction()
|
||||||
|
|
||||||
|
function(add_pch_to_target _target _pch_header)
|
||||||
|
if(COMMAND target_precompile_headers)
|
||||||
|
target_precompile_headers(${_target} PRIVATE ${_pch_header})
|
||||||
|
if(NOT MSVC)
|
||||||
|
set_source_files_properties(src/util.cpp PROPERTIES SKIP_PRECOMPILE_HEADERS ON)
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
|
endfunction()
|
||||||
|
|
||||||
|
if(BIICODE)
|
||||||
|
include(biicode/cmake/biicode.cmake)
|
||||||
|
return()
|
||||||
|
endif()
|
||||||
|
|
||||||
|
include_directories(include)
|
||||||
|
include_directories(grpc)
|
||||||
|
|
||||||
|
if(FLATBUFFERS_BUILD_FLATLIB)
|
||||||
|
add_library(flatbuffers STATIC ${FlatBuffers_Library_SRCS})
|
||||||
|
# Attach header directory for when build via add_subdirectory().
|
||||||
|
target_include_directories(flatbuffers INTERFACE
|
||||||
|
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>)
|
||||||
|
target_compile_options(flatbuffers PRIVATE "${FLATBUFFERS_PRIVATE_CXX_FLAGS}")
|
||||||
|
if(FLATBUFFERS_ENABLE_PCH)
|
||||||
|
add_pch_to_target(flatbuffers include/flatbuffers/pch/pch.h)
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(FLATBUFFERS_BUILD_FLATC)
|
||||||
|
add_executable(flatc ${FlatBuffers_Compiler_SRCS})
|
||||||
|
if(FLATBUFFERS_ENABLE_PCH)
|
||||||
|
add_pch_to_target(flatc include/flatbuffers/pch/flatc_pch.h)
|
||||||
|
endif()
|
||||||
|
target_compile_options(flatc PRIVATE "${FLATBUFFERS_PRIVATE_CXX_FLAGS}")
|
||||||
|
if(FLATBUFFERS_CODE_SANITIZE AND NOT WIN32)
|
||||||
|
add_fsanitize_to_target(flatc ${FLATBUFFERS_CODE_SANITIZE})
|
||||||
|
endif()
|
||||||
|
if(NOT FLATBUFFERS_FLATC_EXECUTABLE)
|
||||||
|
set(FLATBUFFERS_FLATC_EXECUTABLE $<TARGET_FILE:flatc>)
|
||||||
|
endif()
|
||||||
|
if(MSVC)
|
||||||
|
# Make flatc.exe not depend on runtime dlls for easy distribution.
|
||||||
|
target_compile_options(flatc PUBLIC $<$<CONFIG:Release>:/MT>)
|
||||||
|
endif()
|
||||||
|
if(FLATBUFFERS_STATIC_FLATC AND NOT MSVC)
|
||||||
|
target_link_libraries(flatc PRIVATE -static)
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(FLATBUFFERS_BUILD_FLATHASH)
|
||||||
|
add_executable(flathash ${FlatHash_SRCS})
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(FLATBUFFERS_BUILD_SHAREDLIB)
|
||||||
|
add_library(flatbuffers_shared SHARED ${FlatBuffers_Library_SRCS})
|
||||||
|
|
||||||
|
# Shared object version: "major.minor.micro"
|
||||||
|
# - micro updated every release when there is no API/ABI changes
|
||||||
|
# - minor updated when there are additions in API/ABI
|
||||||
|
# - major (ABI number) updated when there are changes in ABI (or removals)
|
||||||
|
set(FlatBuffers_Library_SONAME_MAJOR ${VERSION_MAJOR})
|
||||||
|
set(FlatBuffers_Library_SONAME_FULL "${FlatBuffers_Library_SONAME_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}")
|
||||||
|
set_target_properties(flatbuffers_shared PROPERTIES OUTPUT_NAME flatbuffers
|
||||||
|
SOVERSION "${FlatBuffers_Library_SONAME_MAJOR}"
|
||||||
|
VERSION "${FlatBuffers_Library_SONAME_FULL}")
|
||||||
|
if(FLATBUFFERS_ENABLE_PCH)
|
||||||
|
add_pch_to_target(flatbuffers_shared include/flatbuffers/pch/pch.h)
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
|
|
||||||
|
# Global list of generated files.
|
||||||
|
# Use the global property to be independent of PARENT_SCOPE.
|
||||||
|
set_property(GLOBAL PROPERTY FBS_GENERATED_OUTPUTS)
|
||||||
|
|
||||||
|
function(get_generated_output generated_files)
|
||||||
|
get_property(tmp GLOBAL PROPERTY FBS_GENERATED_OUTPUTS)
|
||||||
|
set(${generated_files} ${tmp} PARENT_SCOPE)
|
||||||
|
endfunction(get_generated_output)
|
||||||
|
|
||||||
|
function(register_generated_output file_name)
|
||||||
|
get_property(tmp GLOBAL PROPERTY FBS_GENERATED_OUTPUTS)
|
||||||
|
list(APPEND tmp ${file_name})
|
||||||
|
set_property(GLOBAL PROPERTY FBS_GENERATED_OUTPUTS ${tmp})
|
||||||
|
endfunction(register_generated_output)
|
||||||
|
|
||||||
|
function(compile_flatbuffers_schema_to_cpp_opt SRC_FBS OPT)
|
||||||
|
if(FLATBUFFERS_BUILD_LEGACY)
|
||||||
|
set(OPT ${OPT};--cpp-std c++0x)
|
||||||
|
else()
|
||||||
|
# --cpp-std is defined by flatc default settings.
|
||||||
|
endif()
|
||||||
|
message(STATUS "`${SRC_FBS}`: add generation of C++ code with '${OPT}'")
|
||||||
|
get_filename_component(SRC_FBS_DIR ${SRC_FBS} PATH)
|
||||||
|
string(REGEX REPLACE "\\.fbs$" "_generated.h" GEN_HEADER ${SRC_FBS})
|
||||||
|
add_custom_command(
|
||||||
|
OUTPUT ${GEN_HEADER}
|
||||||
|
COMMAND "${FLATBUFFERS_FLATC_EXECUTABLE}"
|
||||||
|
--cpp --gen-mutable --gen-object-api --reflect-names
|
||||||
|
--cpp-ptr-type flatbuffers::unique_ptr # Used to test with C++98 STLs
|
||||||
|
${OPT}
|
||||||
|
-I "${CMAKE_CURRENT_SOURCE_DIR}/tests/include_test"
|
||||||
|
-o "${SRC_FBS_DIR}"
|
||||||
|
"${CMAKE_CURRENT_SOURCE_DIR}/${SRC_FBS}"
|
||||||
|
DEPENDS flatc
|
||||||
|
COMMENT "Run generation: '${GEN_HEADER}'")
|
||||||
|
register_generated_output(${GEN_HEADER})
|
||||||
|
endfunction()
|
||||||
|
|
||||||
|
function(compile_flatbuffers_schema_to_cpp SRC_FBS)
|
||||||
|
compile_flatbuffers_schema_to_cpp_opt(${SRC_FBS} "--no-includes;--gen-compare")
|
||||||
|
endfunction()
|
||||||
|
|
||||||
|
function(compile_flatbuffers_schema_to_binary SRC_FBS)
|
||||||
|
message(STATUS "`${SRC_FBS}`: add generation of binary (.bfbs) schema")
|
||||||
|
get_filename_component(SRC_FBS_DIR ${SRC_FBS} PATH)
|
||||||
|
string(REGEX REPLACE "\\.fbs$" ".bfbs" GEN_BINARY_SCHEMA ${SRC_FBS})
|
||||||
|
# For details about flags see generate_code.py
|
||||||
|
add_custom_command(
|
||||||
|
OUTPUT ${GEN_BINARY_SCHEMA}
|
||||||
|
COMMAND "${FLATBUFFERS_FLATC_EXECUTABLE}"
|
||||||
|
-b --schema --bfbs-comments --bfbs-builtins
|
||||||
|
--bfbs-filenames ${SRC_FBS_DIR}
|
||||||
|
-I "${CMAKE_CURRENT_SOURCE_DIR}/tests/include_test"
|
||||||
|
-o "${SRC_FBS_DIR}"
|
||||||
|
"${CMAKE_CURRENT_SOURCE_DIR}/${SRC_FBS}"
|
||||||
|
DEPENDS flatc
|
||||||
|
COMMENT "Run generation: '${GEN_BINARY_SCHEMA}'")
|
||||||
|
register_generated_output(${GEN_BINARY_SCHEMA})
|
||||||
|
endfunction()
|
||||||
|
|
||||||
|
function(compile_flatbuffers_schema_to_embedded_binary SRC_FBS OPT)
|
||||||
|
if(FLATBUFFERS_BUILD_LEGACY)
|
||||||
|
set(OPT ${OPT};--cpp-std c++0x)
|
||||||
|
else()
|
||||||
|
# --cpp-std is defined by flatc default settings.
|
||||||
|
endif()
|
||||||
|
message(STATUS "`${SRC_FBS}`: add generation of C++ embedded binary schema code with '${OPT}'")
|
||||||
|
get_filename_component(SRC_FBS_DIR ${SRC_FBS} PATH)
|
||||||
|
string(REGEX REPLACE "\\.fbs$" "_bfbs_generated.h" GEN_BFBS_HEADER ${SRC_FBS})
|
||||||
|
# For details about flags see generate_code.py
|
||||||
|
add_custom_command(
|
||||||
|
OUTPUT ${GEN_BFBS_HEADER}
|
||||||
|
COMMAND "${FLATBUFFERS_FLATC_EXECUTABLE}"
|
||||||
|
--cpp --gen-mutable --gen-object-api --reflect-names
|
||||||
|
--cpp-ptr-type flatbuffers::unique_ptr # Used to test with C++98 STLs
|
||||||
|
${OPT}
|
||||||
|
--bfbs-comments --bfbs-builtins --bfbs-gen-embed
|
||||||
|
--bfbs-filenames ${SRC_FBS_DIR}
|
||||||
|
-I "${CMAKE_CURRENT_SOURCE_DIR}/tests/include_test"
|
||||||
|
-o "${SRC_FBS_DIR}"
|
||||||
|
"${CMAKE_CURRENT_SOURCE_DIR}/${SRC_FBS}"
|
||||||
|
DEPENDS flatc
|
||||||
|
COMMENT "Run generation: '${GEN_BFBS_HEADER}'")
|
||||||
|
register_generated_output(${GEN_BFBS_HEADER})
|
||||||
|
endfunction()
|
||||||
|
|
||||||
|
# Look if we have python 3.5 installed so that we can run the generate code
|
||||||
|
# python script after flatc is built.
|
||||||
|
find_package(PythonInterp 3.5)
|
||||||
|
|
||||||
|
if(PYTHONINTERP_FOUND AND
|
||||||
|
# Skip doing this if the MSVC version is below VS 12.
|
||||||
|
# https://cmake.org/cmake/help/latest/variable/MSVC_VERSION.html
|
||||||
|
(NOT MSVC OR MSVC_VERSION GREATER 1800))
|
||||||
|
set(GENERATION_SCRIPT ${PYTHON_EXECUTABLE} scripts/generate_code.py)
|
||||||
|
if(FLATBUFFERS_BUILD_LEGACY)
|
||||||
|
# Need to set --cpp-std c++-0x options
|
||||||
|
set(GENERATION_SCRIPT ${GENERATION_SCRIPT} --cpp-0x)
|
||||||
|
endif()
|
||||||
|
if(FLATBUFFERS_SKIP_MONSTER_EXTRA)
|
||||||
|
set(GENERATION_SCRIPT ${GENERATION_SCRIPT} --skip-monster-extra)
|
||||||
|
endif()
|
||||||
|
add_custom_command(
|
||||||
|
TARGET flatc
|
||||||
|
POST_BUILD
|
||||||
|
COMMAND ${GENERATION_SCRIPT} --flatc "${FLATBUFFERS_FLATC_EXECUTABLE}"
|
||||||
|
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
|
||||||
|
COMMENT "Running ${GENERATION_SCRIPT}..."
|
||||||
|
VERBATIM)
|
||||||
|
else()
|
||||||
|
message("No Python3 interpreter found! Unable to generate files automatically.")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(FLATBUFFERS_BUILD_TESTS)
|
||||||
|
file(COPY "${CMAKE_CURRENT_SOURCE_DIR}/tests" DESTINATION "${CMAKE_CURRENT_BINARY_DIR}")
|
||||||
|
file(COPY "${CMAKE_CURRENT_SOURCE_DIR}/samples" DESTINATION "${CMAKE_CURRENT_BINARY_DIR}")
|
||||||
|
|
||||||
|
# TODO Add (monster_test.fbs monsterdata_test.json)->monsterdata_test.mon
|
||||||
|
compile_flatbuffers_schema_to_cpp(tests/monster_test.fbs)
|
||||||
|
compile_flatbuffers_schema_to_binary(tests/monster_test.fbs)
|
||||||
|
compile_flatbuffers_schema_to_cpp_opt(tests/namespace_test/namespace_test1.fbs "--no-includes;--gen-compare;--gen-name-strings")
|
||||||
|
compile_flatbuffers_schema_to_cpp_opt(tests/namespace_test/namespace_test2.fbs "--no-includes;--gen-compare;--gen-name-strings")
|
||||||
|
compile_flatbuffers_schema_to_cpp_opt(tests/union_vector/union_vector.fbs "--no-includes;--gen-compare;--gen-name-strings")
|
||||||
|
compile_flatbuffers_schema_to_cpp(tests/optional_scalars.fbs)
|
||||||
|
compile_flatbuffers_schema_to_cpp_opt(tests/native_type_test.fbs "")
|
||||||
|
compile_flatbuffers_schema_to_cpp_opt(tests/arrays_test.fbs "--scoped-enums;--gen-compare")
|
||||||
|
compile_flatbuffers_schema_to_binary(tests/arrays_test.fbs)
|
||||||
|
compile_flatbuffers_schema_to_embedded_binary(tests/monster_test.fbs "--no-includes;--gen-compare")
|
||||||
|
if(NOT (MSVC AND (MSVC_VERSION LESS 1900)))
|
||||||
|
compile_flatbuffers_schema_to_cpp(tests/monster_extra.fbs) # Test floating-point NAN/INF.
|
||||||
|
endif()
|
||||||
|
include_directories(${CMAKE_CURRENT_BINARY_DIR}/tests)
|
||||||
|
add_executable(flattests ${FlatBuffers_Tests_SRCS})
|
||||||
|
add_dependencies(flattests generated_code)
|
||||||
|
set_property(TARGET flattests
|
||||||
|
PROPERTY COMPILE_DEFINITIONS FLATBUFFERS_TRACK_VERIFIER_BUFFER_SIZE
|
||||||
|
FLATBUFFERS_DEBUG_VERIFICATION_FAILURE=1)
|
||||||
|
if(FLATBUFFERS_CODE_SANITIZE)
|
||||||
|
add_fsanitize_to_target(flattests ${FLATBUFFERS_CODE_SANITIZE})
|
||||||
|
endif()
|
||||||
|
|
||||||
|
compile_flatbuffers_schema_to_cpp(samples/monster.fbs)
|
||||||
|
compile_flatbuffers_schema_to_binary(samples/monster.fbs)
|
||||||
|
include_directories(${CMAKE_CURRENT_BINARY_DIR}/samples)
|
||||||
|
add_executable(flatsamplebinary ${FlatBuffers_Sample_Binary_SRCS})
|
||||||
|
add_dependencies(flatsamplebinary generated_code)
|
||||||
|
add_executable(flatsampletext ${FlatBuffers_Sample_Text_SRCS})
|
||||||
|
add_dependencies(flatsampletext generated_code)
|
||||||
|
add_executable(flatsamplebfbs ${FlatBuffers_Sample_BFBS_SRCS})
|
||||||
|
add_dependencies(flatsamplebfbs generated_code)
|
||||||
|
|
||||||
|
if(FLATBUFFERS_BUILD_CPP17)
|
||||||
|
# Don't generate header for flattests_cpp17 target.
|
||||||
|
# This target uses "generated_cpp17/monster_test_generated.h"
|
||||||
|
# produced by direct call of generate_code.py script.
|
||||||
|
add_executable(flattests_cpp17 ${FlatBuffers_Tests_CPP17_SRCS})
|
||||||
|
add_dependencies(flattests_cpp17 generated_code)
|
||||||
|
target_compile_features(flattests_cpp17 PRIVATE cxx_std_17)
|
||||||
|
target_compile_definitions(flattests_cpp17 PRIVATE
|
||||||
|
FLATBUFFERS_TRACK_VERIFIER_BUFFER_SIZE
|
||||||
|
FLATBUFFERS_DEBUG_VERIFICATION_FAILURE=1
|
||||||
|
)
|
||||||
|
if(FLATBUFFERS_CODE_SANITIZE)
|
||||||
|
add_fsanitize_to_target(flattests_cpp17 ${FLATBUFFERS_CODE_SANITIZE})
|
||||||
|
endif()
|
||||||
|
endif(FLATBUFFERS_BUILD_CPP17)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(FLATBUFFERS_BUILD_GRPCTEST)
|
||||||
|
if(CMAKE_COMPILER_IS_GNUCXX)
|
||||||
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unused-parameter -Wno-shadow")
|
||||||
|
endif()
|
||||||
|
if(NOT GRPC_INSTALL_PATH)
|
||||||
|
message(SEND_ERROR "GRPC_INSTALL_PATH variable is not defined. See grpc/README.md")
|
||||||
|
endif()
|
||||||
|
if(NOT PROTOBUF_DOWNLOAD_PATH)
|
||||||
|
message(SEND_ERROR "PROTOBUF_DOWNLOAD_PATH variable is not defined. See grpc/README.md")
|
||||||
|
endif()
|
||||||
|
INCLUDE_DIRECTORIES(${GRPC_INSTALL_PATH}/include)
|
||||||
|
INCLUDE_DIRECTORIES(${PROTOBUF_DOWNLOAD_PATH}/src)
|
||||||
|
find_package(Threads REQUIRED)
|
||||||
|
list(APPEND CMAKE_PREFIX_PATH ${GRPC_INSTALL_PATH})
|
||||||
|
find_package(absl CONFIG REQUIRED)
|
||||||
|
find_package(protobuf CONFIG REQUIRED)
|
||||||
|
find_package(gRPC CONFIG REQUIRED)
|
||||||
|
add_executable(grpctest ${FlatBuffers_GRPCTest_SRCS})
|
||||||
|
add_dependencies(grpctest generated_code)
|
||||||
|
target_link_libraries(grpctest PRIVATE gRPC::grpc++_unsecure gRPC::grpc_unsecure gRPC::gpr pthread dl)
|
||||||
|
if(FLATBUFFERS_CODE_SANITIZE AND NOT WIN32)
|
||||||
|
# GRPC test has problems with alignment and will fail under ASAN/UBSAN.
|
||||||
|
# add_fsanitize_to_target(grpctest ${FLATBUFFERS_CODE_SANITIZE})
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
|
|
||||||
|
|
||||||
|
if(FLATBUFFERS_INSTALL)
|
||||||
|
include(GNUInstallDirs)
|
||||||
|
|
||||||
|
install(DIRECTORY include/flatbuffers DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
|
||||||
|
|
||||||
|
set(FB_CMAKE_DIR "${CMAKE_INSTALL_LIBDIR}/cmake/flatbuffers")
|
||||||
|
|
||||||
|
configure_file(CMake/FlatBuffersConfigVersion.cmake.in FlatBuffersConfigVersion.cmake @ONLY)
|
||||||
|
install(
|
||||||
|
FILES "CMake/FlatBuffersConfig.cmake" "${CMAKE_CURRENT_BINARY_DIR}/FlatBuffersConfigVersion.cmake"
|
||||||
|
DESTINATION ${FB_CMAKE_DIR}
|
||||||
|
)
|
||||||
|
|
||||||
|
if(FLATBUFFERS_BUILD_FLATLIB)
|
||||||
|
if(CMAKE_VERSION VERSION_LESS 3.0)
|
||||||
|
install(
|
||||||
|
TARGETS flatbuffers EXPORT FlatBuffersTargets
|
||||||
|
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
||||||
|
)
|
||||||
|
else()
|
||||||
|
install(
|
||||||
|
TARGETS flatbuffers EXPORT FlatBuffersTargets
|
||||||
|
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
||||||
|
INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
|
||||||
|
)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
install(EXPORT FlatBuffersTargets
|
||||||
|
FILE FlatBuffersTargets.cmake
|
||||||
|
NAMESPACE flatbuffers::
|
||||||
|
DESTINATION ${FB_CMAKE_DIR}
|
||||||
|
)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(FLATBUFFERS_BUILD_FLATC)
|
||||||
|
install(
|
||||||
|
TARGETS flatc EXPORT FlatcTargets
|
||||||
|
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
|
||||||
|
)
|
||||||
|
|
||||||
|
install(
|
||||||
|
EXPORT FlatcTargets
|
||||||
|
FILE FlatcTargets.cmake
|
||||||
|
NAMESPACE flatbuffers::
|
||||||
|
DESTINATION ${FB_CMAKE_DIR}
|
||||||
|
)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(FLATBUFFERS_BUILD_SHAREDLIB)
|
||||||
|
if(CMAKE_VERSION VERSION_LESS 3.0)
|
||||||
|
install(
|
||||||
|
TARGETS flatbuffers_shared EXPORT FlatBuffersSharedTargets
|
||||||
|
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
||||||
|
RUNTIME DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
||||||
|
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
||||||
|
)
|
||||||
|
else()
|
||||||
|
install(
|
||||||
|
TARGETS flatbuffers_shared EXPORT FlatBuffersSharedTargets
|
||||||
|
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
||||||
|
RUNTIME DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
||||||
|
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
||||||
|
INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
|
||||||
|
)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
install(
|
||||||
|
EXPORT FlatBuffersSharedTargets
|
||||||
|
FILE FlatBuffersSharedTargets.cmake
|
||||||
|
NAMESPACE flatbuffers::
|
||||||
|
DESTINATION ${FB_CMAKE_DIR}
|
||||||
|
)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(FLATBUFFERS_BUILD_SHAREDLIB OR FLATBUFFERS_BUILD_FLATLIB)
|
||||||
|
configure_file(CMake/flatbuffers.pc.in flatbuffers.pc @ONLY)
|
||||||
|
install(
|
||||||
|
FILES "${CMAKE_CURRENT_BINARY_DIR}/flatbuffers.pc"
|
||||||
|
DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig
|
||||||
|
)
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(FLATBUFFERS_BUILD_TESTS)
|
||||||
|
enable_testing()
|
||||||
|
|
||||||
|
add_test(NAME flattests COMMAND flattests)
|
||||||
|
if(FLATBUFFERS_BUILD_CPP17)
|
||||||
|
add_test(NAME flattests_cpp17 COMMAND flattests_cpp17)
|
||||||
|
endif()
|
||||||
|
if(FLATBUFFERS_BUILD_GRPCTEST)
|
||||||
|
add_test(NAME grpctest COMMAND grpctest)
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
|
|
||||||
|
# This target is sync-barrier.
|
||||||
|
# Other generate-dependent targets can depend on 'generated_code' only.
|
||||||
|
get_generated_output(fbs_generated)
|
||||||
|
if(fbs_generated)
|
||||||
|
# message(STATUS "Add generated_code target with files:${fbs_generated}")
|
||||||
|
add_custom_target(generated_code
|
||||||
|
DEPENDS ${fbs_generated}
|
||||||
|
COMMENT "All generated files were updated.")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
include(CMake/BuildFlatBuffers.cmake)
|
||||||
|
|
||||||
|
if(UNIX)
|
||||||
|
# Use of CPack only supported on Linux systems.
|
||||||
|
if(FLATBUFFERS_PACKAGE_DEBIAN)
|
||||||
|
include(CMake/PackageDebian.cmake)
|
||||||
|
include(CPack)
|
||||||
|
endif()
|
||||||
|
if (FLATBUFFERS_PACKAGE_REDHAT)
|
||||||
|
include(CMake/PackageRedhat.cmake)
|
||||||
|
include(CPack)
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
|
|
||||||
|
# Include for running Google Benchmarks.
|
||||||
|
if(FLATBUFFERS_BUILD_BENCHMARKS AND CMAKE_VERSION VERSION_GREATER 3.13)
|
||||||
|
add_subdirectory(benchmarks)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
# Add FlatBuffers::FlatBuffers interface, needed for FetchContent_Declare
|
||||||
|
add_library(FlatBuffers INTERFACE)
|
||||||
|
add_library(FlatBuffers::FlatBuffers ALIAS FlatBuffers)
|
||||||
|
target_include_directories(
|
||||||
|
FlatBuffers
|
||||||
|
INTERFACE $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
|
||||||
|
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/include>)
|
||||||
@@ -30,7 +30,7 @@ find_program(FLATBUFFERS_FLATC_EXECUTABLE NAMES flatc)
|
|||||||
find_path(FLATBUFFERS_INCLUDE_DIR NAMES flatbuffers/flatbuffers.h)
|
find_path(FLATBUFFERS_INCLUDE_DIR NAMES flatbuffers/flatbuffers.h)
|
||||||
|
|
||||||
include(FindPackageHandleStandardArgs)
|
include(FindPackageHandleStandardArgs)
|
||||||
find_package_handle_standard_args(flatbuffers
|
find_package_handle_standard_args(FlatBuffers
|
||||||
DEFAULT_MSG FLATBUFFERS_FLATC_EXECUTABLE FLATBUFFERS_INCLUDE_DIR)
|
DEFAULT_MSG FLATBUFFERS_FLATC_EXECUTABLE FLATBUFFERS_INCLUDE_DIR)
|
||||||
|
|
||||||
if(FLATBUFFERS_FOUND)
|
if(FLATBUFFERS_FOUND)
|
||||||
@@ -58,4 +58,4 @@ else()
|
|||||||
set(FLATBUFFERS_INCLUDE_DIR)
|
set(FLATBUFFERS_INCLUDE_DIR)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
include("${FLATBUFFERS_CMAKE_DIR}/BuildFlatBuffers.cmake")
|
include("${FLATBUFFERS_CMAKE_DIR}/BuildFlatBuffers.cmake")
|
||||||
|
|||||||
3
CMake/FlatBuffersConfig.cmake
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
include("${CMAKE_CURRENT_LIST_DIR}/FlatBuffersTargets.cmake" OPTIONAL)
|
||||||
|
include("${CMAKE_CURRENT_LIST_DIR}/FlatcTargets.cmake" OPTIONAL)
|
||||||
|
include("${CMAKE_CURRENT_LIST_DIR}/FlatBuffersSharedTargets.cmake" OPTIONAL)
|
||||||
@@ -1,4 +0,0 @@
|
|||||||
include("${CMAKE_CURRENT_LIST_DIR}/FlatbuffersTargets.cmake" OPTIONAL)
|
|
||||||
include("${CMAKE_CURRENT_LIST_DIR}/FlatcTargets.cmake" OPTIONAL)
|
|
||||||
include("${CMAKE_CURRENT_LIST_DIR}/FlatbuffersSharedTargets.cmake" OPTIONAL)
|
|
||||||
|
|
||||||
@@ -31,4 +31,14 @@ if (UNIX)
|
|||||||
set(CPACK_RPM_PACKAGE_NAME "flatbuffers")
|
set(CPACK_RPM_PACKAGE_NAME "flatbuffers")
|
||||||
set(CPACK_PACKAGE_FILE_NAME
|
set(CPACK_PACKAGE_FILE_NAME
|
||||||
"${CPACK_RPM_PACKAGE_NAME}_${CPACK_RPM_PACKAGE_VERSION}_${CPACK_RPM_PACKAGE_ARCHITECTURE}")
|
"${CPACK_RPM_PACKAGE_NAME}_${CPACK_RPM_PACKAGE_VERSION}_${CPACK_RPM_PACKAGE_ARCHITECTURE}")
|
||||||
|
if(NOT DEFINED ${CPACK_PACKAGING_INSTALL_PREFIX})
|
||||||
|
# Default packaging install prefix on RedHat systems is /usr.
|
||||||
|
# This is the assumed value when this variable is not defined.
|
||||||
|
# There is currently a conflict with
|
||||||
|
# /usr/${CMAKE_INSTALL_LIBDIR}/cmake which is installed by default
|
||||||
|
# by other packages on RedHat (most notably cmake-filesystem). Ensure
|
||||||
|
# that on these systems, flatbuffers does not package this path.
|
||||||
|
# This patch is required for cmake pre-3.17.
|
||||||
|
list(APPEND CPACK_RPM_EXCLUDE_FROM_AUTO_FILELIST_ADDITION "/usr/${CMAKE_INSTALL_LIBDIR}/cmake")
|
||||||
|
endif()
|
||||||
endif(UNIX)
|
endif(UNIX)
|
||||||
|
|||||||
@@ -1,11 +1,37 @@
|
|||||||
|
set(VERSION_MAJOR 2)
|
||||||
|
set(VERSION_MINOR 0)
|
||||||
|
set(VERSION_PATCH 8)
|
||||||
|
set(VERSION_COMMIT 0)
|
||||||
|
|
||||||
find_program(GIT git)
|
find_program(GIT git)
|
||||||
execute_process(
|
if(GIT AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/.git")
|
||||||
COMMAND ${GIT} describe
|
execute_process(
|
||||||
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
|
COMMAND ${GIT} describe --tags
|
||||||
OUTPUT_VARIABLE GIT_DESCRIBE_DIRTY
|
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
|
||||||
OUTPUT_STRIP_TRAILING_WHITESPACE
|
OUTPUT_VARIABLE GIT_DESCRIBE_DIRTY
|
||||||
)
|
OUTPUT_STRIP_TRAILING_WHITESPACE
|
||||||
string(REGEX REPLACE "^v([0-9]+)\\..*" "\\1" VERSION_MAJOR "${GIT_DESCRIBE_DIRTY}")
|
RESULT_VARIABLE GIT_DESCRIBE_RESULT
|
||||||
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}")
|
if(GIT_DESCRIBE_RESULT EQUAL 0)
|
||||||
|
# Test if the most recent Git tag matches the pattern "v<major>.<minor>.<patch>*"
|
||||||
|
if(GIT_DESCRIBE_DIRTY MATCHES "^v[0-9]+\\.[0-9]+\\.[0-9]+.*")
|
||||||
|
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}")
|
||||||
|
# If the tag points to the commit, then only the tag is shown in "git describe"
|
||||||
|
if(VERSION_COMMIT STREQUAL GIT_DESCRIBE_DIRTY)
|
||||||
|
set(VERSION_COMMIT 0)
|
||||||
|
endif()
|
||||||
|
else()
|
||||||
|
message(WARNING "\"${GIT_DESCRIBE_DIRTY}\" does not match pattern v<major>.<minor>.<patch>-<commit>")
|
||||||
|
endif()
|
||||||
|
else()
|
||||||
|
message(WARNING "git describe failed with exit code: ${GIT_DESCRIBE_RESULT}")
|
||||||
|
endif()
|
||||||
|
else()
|
||||||
|
message(WARNING "git is not found")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
message(STATUS "Proceeding with version: ${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}.${VERSION_COMMIT}")
|
||||||
|
|||||||
9
CMake/flatbuffers.pc.in
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
libdir=@CMAKE_INSTALL_FULL_LIBDIR@
|
||||||
|
includedir=@CMAKE_INSTALL_FULL_INCLUDEDIR@
|
||||||
|
|
||||||
|
Name: FlatBuffers
|
||||||
|
Description: Memory Efficient Serialization Library
|
||||||
|
Version: @VERSION_MAJOR@.@VERSION_MINOR@.@VERSION_PATCH@
|
||||||
|
|
||||||
|
Libs: -L${libdir} -lflatbuffers
|
||||||
|
Cflags: -I${includedir}
|
||||||
496
CMakeLists.txt
@@ -1,9 +1,35 @@
|
|||||||
cmake_minimum_required(VERSION 2.8.12)
|
# This is the legacy minimum version flatbuffers supported for a while.
|
||||||
|
cmake_minimum_required(VERSION 2.8.12...3.22.1)
|
||||||
|
|
||||||
|
# CMake version 3.16 is the 'de-facto' minimum version for flatbuffers. If the
|
||||||
|
# current cmake is older than this, warn the user and include the legacy file to
|
||||||
|
# provide some level of support.
|
||||||
|
if(CMAKE_VERSION VERSION_LESS 3.16)
|
||||||
|
message(WARNING "Using cmake version ${CMAKE_VERSION} which is older than "
|
||||||
|
"our target version of 3.16. This will use the legacy CMakeLists.txt that "
|
||||||
|
"supports version 2.8.12 and higher, but not actively maintained. Consider "
|
||||||
|
"upgrading cmake to a newer version, as this may become a fatal error in the "
|
||||||
|
"future.")
|
||||||
|
# Use the legacy version of CMakeLists.txt
|
||||||
|
include(CMake/CMakeLists_legacy.cmake.in)
|
||||||
|
return()
|
||||||
|
endif()
|
||||||
|
|
||||||
|
# Attempt to read the current version of flatbuffers by looking at the latest tag.
|
||||||
|
include(CMake/Version.cmake)
|
||||||
|
|
||||||
|
if (POLICY CMP0048)
|
||||||
|
cmake_policy(SET CMP0048 NEW)
|
||||||
|
project(FlatBuffers
|
||||||
|
DESCRIPTION "Flatbuffers serialization library"
|
||||||
|
VERSION ${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}
|
||||||
|
LANGUAGES CXX)
|
||||||
|
else()
|
||||||
|
project(FlatBuffers)
|
||||||
|
endif (POLICY CMP0048)
|
||||||
|
|
||||||
# generate compile_commands.json
|
# generate compile_commands.json
|
||||||
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
||||||
include(CheckCXXSymbolExists)
|
|
||||||
|
|
||||||
project(FlatBuffers)
|
|
||||||
|
|
||||||
# NOTE: Code coverage only works on Linux & OSX.
|
# NOTE: Code coverage only works on Linux & OSX.
|
||||||
option(FLATBUFFERS_CODE_COVERAGE "Enable the code coverage build option." OFF)
|
option(FLATBUFFERS_CODE_COVERAGE "Enable the code coverage build option." OFF)
|
||||||
@@ -16,6 +42,8 @@ option(FLATBUFFERS_BUILD_FLATC "Enable the build of the flatbuffers compiler"
|
|||||||
option(FLATBUFFERS_STATIC_FLATC "Build flatbuffers compiler with -static flag"
|
option(FLATBUFFERS_STATIC_FLATC "Build flatbuffers compiler with -static flag"
|
||||||
OFF)
|
OFF)
|
||||||
option(FLATBUFFERS_BUILD_FLATHASH "Enable the build of flathash" ON)
|
option(FLATBUFFERS_BUILD_FLATHASH "Enable the build of flathash" ON)
|
||||||
|
option(FLATBUFFERS_BUILD_BENCHMARKS "Enable the build of flatbenchmark."
|
||||||
|
OFF)
|
||||||
option(FLATBUFFERS_BUILD_GRPCTEST "Enable the build of grpctest" OFF)
|
option(FLATBUFFERS_BUILD_GRPCTEST "Enable the build of grpctest" OFF)
|
||||||
option(FLATBUFFERS_BUILD_SHAREDLIB
|
option(FLATBUFFERS_BUILD_SHAREDLIB
|
||||||
"Enable the build of the flatbuffers shared library"
|
"Enable the build of the flatbuffers shared library"
|
||||||
@@ -38,6 +66,34 @@ option(FLATBUFFERS_BUILD_CPP17
|
|||||||
option(FLATBUFFERS_BUILD_LEGACY
|
option(FLATBUFFERS_BUILD_LEGACY
|
||||||
"Run C++ code generator with '--cpp-std c++0x' switch."
|
"Run C++ code generator with '--cpp-std c++0x' switch."
|
||||||
OFF)
|
OFF)
|
||||||
|
option(FLATBUFFERS_ENABLE_PCH
|
||||||
|
"Enable precompile headers support for 'flatbuffers' and 'flatc'. \"
|
||||||
|
Only work if CMake supports 'target_precompile_headers'. \"
|
||||||
|
This can speed up compilation time."
|
||||||
|
OFF)
|
||||||
|
option(FLATBUFFERS_SKIP_MONSTER_EXTRA
|
||||||
|
"Skip generating monster_extra.fbs that contains non-supported numerical\"
|
||||||
|
types." OFF)
|
||||||
|
option(FLATBUFFERS_STRICT_MODE
|
||||||
|
"Build flatbuffers with all warnings as errors (-Werror or /WX)."
|
||||||
|
OFF)
|
||||||
|
|
||||||
|
if(NOT DEFINED FLATBUFFERS_CPP_STD)
|
||||||
|
set(FLATBUFFERS_CPP_STD 11)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
set(MSVC_LIKE OFF)
|
||||||
|
if(MSVC OR CMAKE_CXX_COMPILER_FRONTEND_VARIANT STREQUAL "MSVC")
|
||||||
|
set(MSVC_LIKE ON)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(DEFINED FLATBUFFERS_COMPILATION_TIMINGS)
|
||||||
|
message("Recording Compilation Timings to ${FLATBUFFERS_COMPILATION_TIMINGS}")
|
||||||
|
file(REMOVE ${FLATBUFFERS_COMPILATION_TIMINGS})
|
||||||
|
set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE "time -f 'Wall: %E User: %U Sys: %S | %C' -q -a -o ${FLATBUFFERS_COMPILATION_TIMINGS}")
|
||||||
|
set_property(GLOBAL PROPERTY RULE_LAUNCH_CUSTOM "time -f 'Wall: %E User: %U Sys: %S | %C' -q -a -o ${FLATBUFFERS_COMPILATION_TIMINGS}")
|
||||||
|
set_property(GLOBAL PROPERTY RULE_LAUNCH_LINK "time -f 'Wall: %E User: %U Sys: %S | %C' -q -a -o ${FLATBUFFERS_COMPILATION_TIMINGS}")
|
||||||
|
endif()
|
||||||
|
|
||||||
if(NOT FLATBUFFERS_BUILD_FLATC AND FLATBUFFERS_BUILD_TESTS)
|
if(NOT FLATBUFFERS_BUILD_FLATC AND FLATBUFFERS_BUILD_TESTS)
|
||||||
message(WARNING
|
message(WARNING
|
||||||
@@ -53,8 +109,10 @@ endif()
|
|||||||
|
|
||||||
# Auto-detect locale-narrow 'strtod_l' and 'strtoull_l' functions.
|
# Auto-detect locale-narrow 'strtod_l' and 'strtoull_l' functions.
|
||||||
if(NOT DEFINED FLATBUFFERS_LOCALE_INDEPENDENT)
|
if(NOT DEFINED FLATBUFFERS_LOCALE_INDEPENDENT)
|
||||||
|
include(CheckCXXSymbolExists)
|
||||||
|
|
||||||
set(FLATBUFFERS_LOCALE_INDEPENDENT 0)
|
set(FLATBUFFERS_LOCALE_INDEPENDENT 0)
|
||||||
if(MSVC)
|
if(MSVC_LIKE)
|
||||||
check_cxx_symbol_exists(_strtof_l stdlib.h FLATBUFFERS_HAS_STRTOF_L)
|
check_cxx_symbol_exists(_strtof_l stdlib.h FLATBUFFERS_HAS_STRTOF_L)
|
||||||
check_cxx_symbol_exists(_strtoui64_l stdlib.h FLATBUFFERS_HAS_STRTOULL_L)
|
check_cxx_symbol_exists(_strtoui64_l stdlib.h FLATBUFFERS_HAS_STRTOULL_L)
|
||||||
else()
|
else()
|
||||||
@@ -68,17 +126,32 @@ endif()
|
|||||||
add_definitions(-DFLATBUFFERS_LOCALE_INDEPENDENT=$<BOOL:${FLATBUFFERS_LOCALE_INDEPENDENT}>)
|
add_definitions(-DFLATBUFFERS_LOCALE_INDEPENDENT=$<BOOL:${FLATBUFFERS_LOCALE_INDEPENDENT}>)
|
||||||
|
|
||||||
set(FlatBuffers_Library_SRCS
|
set(FlatBuffers_Library_SRCS
|
||||||
|
include/flatbuffers/allocator.h
|
||||||
|
include/flatbuffers/array.h
|
||||||
include/flatbuffers/base.h
|
include/flatbuffers/base.h
|
||||||
|
include/flatbuffers/bfbs_generator.h
|
||||||
|
include/flatbuffers/buffer.h
|
||||||
|
include/flatbuffers/buffer_ref.h
|
||||||
|
include/flatbuffers/default_allocator.h
|
||||||
|
include/flatbuffers/detached_buffer.h
|
||||||
|
include/flatbuffers/flatbuffer_builder.h
|
||||||
include/flatbuffers/flatbuffers.h
|
include/flatbuffers/flatbuffers.h
|
||||||
|
include/flatbuffers/flexbuffers.h
|
||||||
|
include/flatbuffers/flex_flat_util.h
|
||||||
include/flatbuffers/hash.h
|
include/flatbuffers/hash.h
|
||||||
include/flatbuffers/idl.h
|
include/flatbuffers/idl.h
|
||||||
include/flatbuffers/util.h
|
include/flatbuffers/minireflect.h
|
||||||
include/flatbuffers/reflection.h
|
include/flatbuffers/reflection.h
|
||||||
include/flatbuffers/reflection_generated.h
|
include/flatbuffers/reflection_generated.h
|
||||||
include/flatbuffers/stl_emulation.h
|
|
||||||
include/flatbuffers/flexbuffers.h
|
|
||||||
include/flatbuffers/registry.h
|
include/flatbuffers/registry.h
|
||||||
include/flatbuffers/minireflect.h
|
include/flatbuffers/stl_emulation.h
|
||||||
|
include/flatbuffers/string.h
|
||||||
|
include/flatbuffers/struct.h
|
||||||
|
include/flatbuffers/table.h
|
||||||
|
include/flatbuffers/util.h
|
||||||
|
include/flatbuffers/vector.h
|
||||||
|
include/flatbuffers/vector_downward.h
|
||||||
|
include/flatbuffers/verifier.h
|
||||||
src/idl_parser.cpp
|
src/idl_parser.cpp
|
||||||
src/idl_gen_text.cpp
|
src/idl_gen_text.cpp
|
||||||
src/reflection.cpp
|
src/reflection.cpp
|
||||||
@@ -93,7 +166,7 @@ set(FlatBuffers_Compiler_SRCS
|
|||||||
src/idl_gen_kotlin.cpp
|
src/idl_gen_kotlin.cpp
|
||||||
src/idl_gen_go.cpp
|
src/idl_gen_go.cpp
|
||||||
src/idl_gen_java.cpp
|
src/idl_gen_java.cpp
|
||||||
src/idl_gen_js_ts.cpp
|
src/idl_gen_ts.cpp
|
||||||
src/idl_gen_php.cpp
|
src/idl_gen_php.cpp
|
||||||
src/idl_gen_python.cpp
|
src/idl_gen_python.cpp
|
||||||
src/idl_gen_lobster.cpp
|
src/idl_gen_lobster.cpp
|
||||||
@@ -103,9 +176,19 @@ set(FlatBuffers_Compiler_SRCS
|
|||||||
src/idl_gen_grpc.cpp
|
src/idl_gen_grpc.cpp
|
||||||
src/idl_gen_json_schema.cpp
|
src/idl_gen_json_schema.cpp
|
||||||
src/idl_gen_swift.cpp
|
src/idl_gen_swift.cpp
|
||||||
|
src/idl_namer.h
|
||||||
|
src/namer.h
|
||||||
src/flatc.cpp
|
src/flatc.cpp
|
||||||
src/flatc_main.cpp
|
src/flatc_main.cpp
|
||||||
|
src/bfbs_gen.h
|
||||||
|
src/bfbs_gen_lua.h
|
||||||
|
src/bfbs_namer.h
|
||||||
include/flatbuffers/code_generators.h
|
include/flatbuffers/code_generators.h
|
||||||
|
src/binary_annotator.h
|
||||||
|
src/binary_annotator.cpp
|
||||||
|
src/annotated_binary_text_gen.h
|
||||||
|
src/annotated_binary_text_gen.cpp
|
||||||
|
src/bfbs_gen_lua.cpp
|
||||||
src/code_generators.cpp
|
src/code_generators.cpp
|
||||||
grpc/src/compiler/schema_interface.h
|
grpc/src/compiler/schema_interface.h
|
||||||
grpc/src/compiler/cpp_generator.h
|
grpc/src/compiler/cpp_generator.h
|
||||||
@@ -115,10 +198,11 @@ set(FlatBuffers_Compiler_SRCS
|
|||||||
grpc/src/compiler/java_generator.h
|
grpc/src/compiler/java_generator.h
|
||||||
grpc/src/compiler/java_generator.cc
|
grpc/src/compiler/java_generator.cc
|
||||||
grpc/src/compiler/python_generator.h
|
grpc/src/compiler/python_generator.h
|
||||||
grpc/src/compiler/python_private_generator.h
|
|
||||||
grpc/src/compiler/python_generator.cc
|
grpc/src/compiler/python_generator.cc
|
||||||
grpc/src/compiler/swift_generator.h
|
grpc/src/compiler/swift_generator.h
|
||||||
grpc/src/compiler/swift_generator.cc
|
grpc/src/compiler/swift_generator.cc
|
||||||
|
grpc/src/compiler/ts_generator.h
|
||||||
|
grpc/src/compiler/ts_generator.cc
|
||||||
)
|
)
|
||||||
|
|
||||||
set(FlatHash_SRCS
|
set(FlatHash_SRCS
|
||||||
@@ -129,11 +213,21 @@ set(FlatHash_SRCS
|
|||||||
set(FlatBuffers_Tests_SRCS
|
set(FlatBuffers_Tests_SRCS
|
||||||
${FlatBuffers_Library_SRCS}
|
${FlatBuffers_Library_SRCS}
|
||||||
src/idl_gen_fbs.cpp
|
src/idl_gen_fbs.cpp
|
||||||
|
tests/evolution_test.cpp
|
||||||
|
tests/flexbuffers_test.cpp
|
||||||
|
tests/fuzz_test.cpp
|
||||||
|
tests/json_test.cpp
|
||||||
|
tests/monster_test.cpp
|
||||||
|
tests/optional_scalars_test.cpp
|
||||||
|
tests/parser_test.cpp
|
||||||
|
tests/proto_test.cpp
|
||||||
|
tests/reflection_test.cpp
|
||||||
tests/test.cpp
|
tests/test.cpp
|
||||||
tests/test_assert.h
|
tests/test_assert.h
|
||||||
tests/test_assert.cpp
|
tests/test_assert.cpp
|
||||||
tests/test_builder.h
|
tests/test_builder.h
|
||||||
tests/test_builder.cpp
|
tests/test_builder.cpp
|
||||||
|
tests/util_test.cpp
|
||||||
tests/native_type_test_impl.h
|
tests/native_type_test_impl.h
|
||||||
tests/native_type_test_impl.cpp
|
tests/native_type_test_impl.cpp
|
||||||
include/flatbuffers/code_generators.h
|
include/flatbuffers/code_generators.h
|
||||||
@@ -153,6 +247,10 @@ set(FlatBuffers_Tests_SRCS
|
|||||||
${CMAKE_CURRENT_BINARY_DIR}/tests/monster_extra_generated.h
|
${CMAKE_CURRENT_BINARY_DIR}/tests/monster_extra_generated.h
|
||||||
# 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_bfbs_generated.h
|
${CMAKE_CURRENT_BINARY_DIR}/tests/monster_test_bfbs_generated.h
|
||||||
|
# file generate by running compiler on tests/optional_scalars.fbs
|
||||||
|
${CMAKE_CURRENT_BINARY_DIR}/tests/optional_scalars_generated.h
|
||||||
|
# file generate by running compiler on tests/native_inline_table_test.fbs
|
||||||
|
${CMAKE_CURRENT_BINARY_DIR}/tests/native_inline_table_test_generated.h
|
||||||
)
|
)
|
||||||
|
|
||||||
set(FlatBuffers_Tests_CPP17_SRCS
|
set(FlatBuffers_Tests_CPP17_SRCS
|
||||||
@@ -163,6 +261,8 @@ set(FlatBuffers_Tests_CPP17_SRCS
|
|||||||
# 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/cpp17/generated_cpp17/monster_test_generated.h
|
${CMAKE_CURRENT_BINARY_DIR}/tests/cpp17/generated_cpp17/monster_test_generated.h
|
||||||
${CMAKE_CURRENT_BINARY_DIR}/tests/monster_test_generated.h
|
${CMAKE_CURRENT_BINARY_DIR}/tests/monster_test_generated.h
|
||||||
|
${CMAKE_CURRENT_BINARY_DIR}/tests/cpp17/generated_cpp17/optional_scalars_generated.h
|
||||||
|
${CMAKE_CURRENT_BINARY_DIR}/tests/optional_scalars_generated.h
|
||||||
)
|
)
|
||||||
|
|
||||||
set(FlatBuffers_Sample_Binary_SRCS
|
set(FlatBuffers_Sample_Binary_SRCS
|
||||||
@@ -203,78 +303,14 @@ set(FlatBuffers_GRPCTest_SRCS
|
|||||||
${CMAKE_CURRENT_BINARY_DIR}/tests/monster_test_generated.h
|
${CMAKE_CURRENT_BINARY_DIR}/tests/monster_test_generated.h
|
||||||
)
|
)
|
||||||
|
|
||||||
# source_group(Compiler FILES ${FlatBuffers_Compiler_SRCS})
|
# TODO(dbaileychess): Figure out how this would now work. I posted a question on
|
||||||
# source_group(Tests FILES ${FlatBuffers_Tests_SRCS})
|
# https://stackoverflow.com/questions/71772330/override-target-compile-options-via-cmake-command-line.
|
||||||
|
# Append FLATBUFFERS_CXX_FLAGS to CMAKE_CXX_FLAGS.
|
||||||
if(EXISTS "${CMAKE_TOOLCHAIN_FILE}")
|
if(DEFINED FLATBUFFERS_CXX_FLAGS AND NOT EXISTS "${CMAKE_TOOLCHAIN_FILE}")
|
||||||
# do not apply any global settings if the toolchain
|
message(STATUS "extend CXX_FLAGS with ${FLATBUFFERS_CXX_FLAGS}")
|
||||||
# is being configured externally
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${FLATBUFFERS_CXX_FLAGS}")
|
||||||
message(STATUS "Using toolchain file: ${CMAKE_TOOLCHAIN_FILE}.")
|
|
||||||
elseif(APPLE)
|
|
||||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -stdlib=libc++")
|
|
||||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -pedantic -Werror -Wextra -Wno-unused-parameter")
|
|
||||||
set(FLATBUFFERS_PRIVATE_CXX_FLAGS "-Wold-style-cast")
|
|
||||||
elseif(CMAKE_COMPILER_IS_GNUCXX)
|
|
||||||
if(CYGWIN)
|
|
||||||
set(CMAKE_CXX_FLAGS
|
|
||||||
"${CMAKE_CXX_FLAGS} -std=gnu++11")
|
|
||||||
else(CYGWIN)
|
|
||||||
set(CMAKE_CXX_FLAGS
|
|
||||||
"${CMAKE_CXX_FLAGS} -std=c++0x")
|
|
||||||
endif(CYGWIN)
|
|
||||||
set(CMAKE_CXX_FLAGS
|
|
||||||
"${CMAKE_CXX_FLAGS} -Wall -pedantic -Werror -Wextra -Werror=shadow")
|
|
||||||
set(FLATBUFFERS_PRIVATE_CXX_FLAGS "-Wold-style-cast")
|
|
||||||
if (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 4.4)
|
|
||||||
if (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 7.0)
|
|
||||||
set(CMAKE_CXX_FLAGS
|
|
||||||
"${CMAKE_CXX_FLAGS} -faligned-new -Werror=implicit-fallthrough=2")
|
|
||||||
endif()
|
|
||||||
set(CMAKE_CXX_FLAGS
|
|
||||||
"${CMAKE_CXX_FLAGS} -Wunused-result -Werror=unused-result -Wunused-parameter -Werror=unused-parameter")
|
|
||||||
endif()
|
|
||||||
|
|
||||||
# Certain platforms such as ARM do not use signed chars by default
|
|
||||||
# which causes issues with certain bounds checks.
|
|
||||||
set(CMAKE_CXX_FLAGS
|
|
||||||
"${CMAKE_CXX_FLAGS} -fsigned-char")
|
|
||||||
|
|
||||||
elseif(${CMAKE_CXX_COMPILER_ID} MATCHES "Clang")
|
|
||||||
set(CMAKE_CXX_FLAGS
|
|
||||||
"${CMAKE_CXX_FLAGS} -std=c++0x -Wall -pedantic -Werror -Wextra -Wno-unused-parameter")
|
|
||||||
set(FLATBUFFERS_PRIVATE_CXX_FLAGS "-Wold-style-cast")
|
|
||||||
if(NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 3.8)
|
|
||||||
list(APPEND FLATBUFFERS_PRIVATE_CXX_FLAGS "-Wimplicit-fallthrough" "-Wextra-semi" "-Werror=unused-private-field") # enable warning
|
|
||||||
endif()
|
|
||||||
if(FLATBUFFERS_LIBCXX_WITH_CLANG)
|
|
||||||
if(NOT "${CMAKE_SYSTEM_NAME}" MATCHES "Linux")
|
|
||||||
set(CMAKE_CXX_FLAGS
|
|
||||||
"${CMAKE_CXX_FLAGS} -stdlib=libc++")
|
|
||||||
endif()
|
|
||||||
if(NOT ("${CMAKE_SYSTEM_NAME}" MATCHES "FreeBSD" OR
|
|
||||||
"${CMAKE_SYSTEM_NAME}" MATCHES "Linux"))
|
|
||||||
set(CMAKE_EXE_LINKER_FLAGS
|
|
||||||
"${CMAKE_EXE_LINKER_FLAGS} -lc++abi")
|
|
||||||
endif()
|
|
||||||
endif()
|
|
||||||
|
|
||||||
# Certain platforms such as ARM do not use signed chars by default
|
|
||||||
# which causes issues with certain bounds checks.
|
|
||||||
set(CMAKE_CXX_FLAGS
|
|
||||||
"${CMAKE_CXX_FLAGS} -fsigned-char")
|
|
||||||
|
|
||||||
elseif(MSVC)
|
|
||||||
# Visual Studio pedantic build settings
|
|
||||||
# warning C4512: assignment operator could not be generated
|
|
||||||
# warning C4316: object allocated on the heap may not be aligned
|
|
||||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W4 /WX /wd4512 /wd4316")
|
|
||||||
endif()
|
|
||||||
|
|
||||||
if(FLATBUFFERS_CODE_COVERAGE)
|
|
||||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -fprofile-arcs -ftest-coverage")
|
|
||||||
set(CMAKE_EXE_LINKER_FLAGS
|
|
||||||
"${CMAKE_EXE_LINKER_FLAGS} -fprofile-arcs -ftest-coverage")
|
|
||||||
endif()
|
endif()
|
||||||
|
message(STATUS "CMAKE_CXX_FLAGS: ${CMAKE_CXX_FLAGS}")
|
||||||
|
|
||||||
function(add_fsanitize_to_target _target _sanitizer)
|
function(add_fsanitize_to_target _target _sanitizer)
|
||||||
if(WIN32)
|
if(WIN32)
|
||||||
@@ -302,35 +338,162 @@ function(add_fsanitize_to_target _target _sanitizer)
|
|||||||
endif()
|
endif()
|
||||||
endfunction()
|
endfunction()
|
||||||
|
|
||||||
if(BIICODE)
|
function(add_pch_to_target _target _pch_header)
|
||||||
include(biicode/cmake/biicode.cmake)
|
if(COMMAND target_precompile_headers)
|
||||||
return()
|
target_precompile_headers(${_target} PRIVATE ${_pch_header})
|
||||||
endif()
|
if(NOT MSVC)
|
||||||
|
set_source_files_properties(src/util.cpp PROPERTIES SKIP_PRECOMPILE_HEADERS ON)
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
|
endfunction()
|
||||||
|
|
||||||
include_directories(include)
|
include_directories(include)
|
||||||
include_directories(grpc)
|
include_directories(grpc)
|
||||||
|
|
||||||
|
# Creates an interface library that stores the configuration settings that each
|
||||||
|
# target links too. This is a compromise between setting configuration globally
|
||||||
|
# with add_compile_options() and the more targetted target_compile_options().
|
||||||
|
# This way each target in this file can share settings and override them if
|
||||||
|
# needed.
|
||||||
|
add_library(ProjectConfig INTERFACE)
|
||||||
|
target_compile_features(ProjectConfig
|
||||||
|
INTERFACE
|
||||||
|
cxx_std_${FLATBUFFERS_CPP_STD}
|
||||||
|
)
|
||||||
|
|
||||||
|
# Force the standard to be met.
|
||||||
|
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||||
|
|
||||||
|
# We shouldn't rely on any compiler-extensions to make things work.
|
||||||
|
set(CMAKE_CXX_EXTENSIONS OFF)
|
||||||
|
|
||||||
|
if(MSVC_LIKE)
|
||||||
|
target_compile_options(ProjectConfig
|
||||||
|
INTERFACE
|
||||||
|
/W4
|
||||||
|
$<$<BOOL:${FLATBUFFERS_STRICT_MODE}>:
|
||||||
|
/WX # Treat all compiler warnings as errors
|
||||||
|
>
|
||||||
|
/wd4512 # C4512: assignment operator could not be generated
|
||||||
|
/wd4316 # C4316: object allocated on the heap may not be aligned
|
||||||
|
/wd4456 # C4456: hides previous local declaration
|
||||||
|
$<$<CXX_COMPILER_ID:Clang>:
|
||||||
|
/D_CRT_SECURE_NO_WARNINGS
|
||||||
|
>
|
||||||
|
)
|
||||||
|
else()
|
||||||
|
if("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
|
||||||
|
set(IS_CLANG ON)
|
||||||
|
else()
|
||||||
|
set(IS_CLANG OFF)
|
||||||
|
endif()
|
||||||
|
target_compile_options(ProjectConfig
|
||||||
|
INTERFACE
|
||||||
|
-Wall
|
||||||
|
$<$<BOOL:${FLATBUFFERS_STRICT_MODE}>:
|
||||||
|
-Werror # Treat all compiler warnings as errors
|
||||||
|
|
||||||
|
-fno-rtti # Disable runtime type information
|
||||||
|
|
||||||
|
$<$<CXX_COMPILER_ID:GNU>:
|
||||||
|
# False positive string overflow
|
||||||
|
# https://github.com/google/flatbuffers/issues/7366
|
||||||
|
-Wno-error=stringop-overflow
|
||||||
|
>
|
||||||
|
>
|
||||||
|
-pedantic
|
||||||
|
-Wextra
|
||||||
|
-Wno-unused-parameter
|
||||||
|
-Wold-style-cast
|
||||||
|
-fsigned-char
|
||||||
|
-Wnon-virtual-dtor
|
||||||
|
|
||||||
|
# This isn't working for some reason: $<$<CXX_COMPILER_ID:CLANG>:
|
||||||
|
$<$<BOOL:${IS_CLANG}>:
|
||||||
|
-Wno-unknown-warning-option
|
||||||
|
-Wmissing-declarations
|
||||||
|
-Wzero-as-null-pointer-constant
|
||||||
|
$<$<VERSION_GREATER:$<CXX_COMPILER_VERSION>,3.8>:
|
||||||
|
-Wimplicit-fallthrough
|
||||||
|
-Wextra-semi
|
||||||
|
$<$<BOOL:${FLATBUFFERS_STRICT_MODE}>:
|
||||||
|
-Werror=unused-private-field
|
||||||
|
>
|
||||||
|
>
|
||||||
|
>
|
||||||
|
|
||||||
|
$<$<CXX_COMPILER_ID:GNU>:
|
||||||
|
$<$<VERSION_GREATER:$<CXX_COMPILER_VERSION>,4.4>:
|
||||||
|
-Wunused-result
|
||||||
|
-Wunused-parameter
|
||||||
|
-Werror=unused-parameter
|
||||||
|
-Wmissing-declarations
|
||||||
|
>
|
||||||
|
$<$<VERSION_GREATER:$<CXX_COMPILER_VERSION>,4.7>:
|
||||||
|
-Wzero-as-null-pointer-constant
|
||||||
|
>
|
||||||
|
$<$<VERSION_GREATER:$<CXX_COMPILER_VERSION>,7.0>:
|
||||||
|
-faligned-new
|
||||||
|
$<$<BOOL:${FLATBUFFERS_STRICT_MODE}>:
|
||||||
|
-Werror=implicit-fallthrough=2
|
||||||
|
>
|
||||||
|
>
|
||||||
|
$<$<VERSION_GREATER:$<CXX_COMPILER_VERSION>,8.0>:
|
||||||
|
-Wextra-semi
|
||||||
|
>
|
||||||
|
>
|
||||||
|
|
||||||
|
$<$<BOOL:${FLATBUFFERS_CODE_COVERAGE}>:
|
||||||
|
-g
|
||||||
|
-fprofile-arcs
|
||||||
|
-ftest-coverage
|
||||||
|
>
|
||||||
|
)
|
||||||
|
|
||||||
|
if(FLATBUFFERS_CODE_COVERAGE)
|
||||||
|
target_link_options(ProjectConfig
|
||||||
|
INTERFACE
|
||||||
|
-fprofile-arcs
|
||||||
|
-ftest-coverage
|
||||||
|
)
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
|
|
||||||
if(FLATBUFFERS_BUILD_FLATLIB)
|
if(FLATBUFFERS_BUILD_FLATLIB)
|
||||||
add_library(flatbuffers STATIC ${FlatBuffers_Library_SRCS})
|
add_library(flatbuffers STATIC ${FlatBuffers_Library_SRCS})
|
||||||
|
|
||||||
# Attach header directory for when build via add_subdirectory().
|
# Attach header directory for when build via add_subdirectory().
|
||||||
target_include_directories(flatbuffers INTERFACE
|
target_include_directories(flatbuffers
|
||||||
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>)
|
INTERFACE
|
||||||
target_compile_options(flatbuffers PRIVATE "${FLATBUFFERS_PRIVATE_CXX_FLAGS}")
|
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
|
||||||
|
)
|
||||||
|
target_link_libraries(flatbuffers PRIVATE $<BUILD_INTERFACE:ProjectConfig>)
|
||||||
|
|
||||||
|
if(FLATBUFFERS_ENABLE_PCH)
|
||||||
|
add_pch_to_target(flatbuffers include/flatbuffers/pch/pch.h)
|
||||||
|
endif()
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if(FLATBUFFERS_BUILD_FLATC)
|
if(FLATBUFFERS_BUILD_FLATC)
|
||||||
add_executable(flatc ${FlatBuffers_Compiler_SRCS})
|
add_executable(flatc ${FlatBuffers_Compiler_SRCS})
|
||||||
target_compile_options(flatc PRIVATE "${FLATBUFFERS_PRIVATE_CXX_FLAGS}")
|
if(FLATBUFFERS_ENABLE_PCH)
|
||||||
|
add_pch_to_target(flatc include/flatbuffers/pch/flatc_pch.h)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
target_link_libraries(flatc PRIVATE $<BUILD_INTERFACE:ProjectConfig>)
|
||||||
|
target_compile_options(flatc
|
||||||
|
PUBLIC
|
||||||
|
$<$<AND:$<BOOL:${MSVC_LIKE}>,$<CONFIG:Release>>:
|
||||||
|
/MT
|
||||||
|
>
|
||||||
|
)
|
||||||
|
|
||||||
if(FLATBUFFERS_CODE_SANITIZE AND NOT WIN32)
|
if(FLATBUFFERS_CODE_SANITIZE AND NOT WIN32)
|
||||||
add_fsanitize_to_target(flatc ${FLATBUFFERS_CODE_SANITIZE})
|
add_fsanitize_to_target(flatc ${FLATBUFFERS_CODE_SANITIZE})
|
||||||
endif()
|
endif()
|
||||||
if(NOT FLATBUFFERS_FLATC_EXECUTABLE)
|
if(NOT FLATBUFFERS_FLATC_EXECUTABLE)
|
||||||
set(FLATBUFFERS_FLATC_EXECUTABLE $<TARGET_FILE:flatc>)
|
set(FLATBUFFERS_FLATC_EXECUTABLE $<TARGET_FILE:flatc>)
|
||||||
endif()
|
endif()
|
||||||
if(MSVC)
|
|
||||||
# Make flatc.exe not depend on runtime dlls for easy distribution.
|
|
||||||
target_compile_options(flatc PUBLIC $<$<CONFIG:Release>:/MT>)
|
|
||||||
endif()
|
|
||||||
if(FLATBUFFERS_STATIC_FLATC AND NOT MSVC)
|
if(FLATBUFFERS_STATIC_FLATC AND NOT MSVC)
|
||||||
target_link_libraries(flatc PRIVATE -static)
|
target_link_libraries(flatc PRIVATE -static)
|
||||||
endif()
|
endif()
|
||||||
@@ -338,20 +501,24 @@ endif()
|
|||||||
|
|
||||||
if(FLATBUFFERS_BUILD_FLATHASH)
|
if(FLATBUFFERS_BUILD_FLATHASH)
|
||||||
add_executable(flathash ${FlatHash_SRCS})
|
add_executable(flathash ${FlatHash_SRCS})
|
||||||
|
target_link_libraries(flathash PRIVATE $<BUILD_INTERFACE:ProjectConfig>)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if(FLATBUFFERS_BUILD_SHAREDLIB)
|
if(FLATBUFFERS_BUILD_SHAREDLIB)
|
||||||
add_library(flatbuffers_shared SHARED ${FlatBuffers_Library_SRCS})
|
add_library(flatbuffers_shared SHARED ${FlatBuffers_Library_SRCS})
|
||||||
|
target_link_libraries(flatbuffers_shared PRIVATE $<BUILD_INTERFACE:ProjectConfig>)
|
||||||
# Shared object version: "major.minor.micro"
|
# Shared object version: "major.minor.micro"
|
||||||
# - micro updated every release when there is no API/ABI changes
|
# - micro updated every release when there is no API/ABI changes
|
||||||
# - minor updated when there are additions in API/ABI
|
# - minor updated when there are additions in API/ABI
|
||||||
# - major (ABI number) updated when there are changes in ABI (or removals)
|
# - major (ABI number) updated when there are changes in ABI (or removals)
|
||||||
set(FlatBuffers_Library_SONAME_MAJOR "1")
|
set(FlatBuffers_Library_SONAME_MAJOR ${VERSION_MAJOR})
|
||||||
set(FlatBuffers_Library_SONAME_FULL "${FlatBuffers_Library_SONAME_MAJOR}.12.0")
|
set(FlatBuffers_Library_SONAME_FULL "${FlatBuffers_Library_SONAME_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}")
|
||||||
set_target_properties(flatbuffers_shared PROPERTIES OUTPUT_NAME flatbuffers
|
set_target_properties(flatbuffers_shared PROPERTIES OUTPUT_NAME flatbuffers
|
||||||
SOVERSION "${FlatBuffers_Library_SONAME_MAJOR}"
|
SOVERSION "${FlatBuffers_Library_SONAME_MAJOR}"
|
||||||
VERSION "${FlatBuffers_Library_SONAME_FULL}")
|
VERSION "${FlatBuffers_Library_SONAME_FULL}")
|
||||||
|
if(FLATBUFFERS_ENABLE_PCH)
|
||||||
|
add_pch_to_target(flatbuffers_shared include/flatbuffers/pch/pch.h)
|
||||||
|
endif()
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
# Global list of generated files.
|
# Global list of generated files.
|
||||||
@@ -400,11 +567,12 @@ function(compile_flatbuffers_schema_to_binary SRC_FBS)
|
|||||||
message(STATUS "`${SRC_FBS}`: add generation of binary (.bfbs) schema")
|
message(STATUS "`${SRC_FBS}`: add generation of binary (.bfbs) schema")
|
||||||
get_filename_component(SRC_FBS_DIR ${SRC_FBS} PATH)
|
get_filename_component(SRC_FBS_DIR ${SRC_FBS} PATH)
|
||||||
string(REGEX REPLACE "\\.fbs$" ".bfbs" GEN_BINARY_SCHEMA ${SRC_FBS})
|
string(REGEX REPLACE "\\.fbs$" ".bfbs" GEN_BINARY_SCHEMA ${SRC_FBS})
|
||||||
# For details about flags see generate_code.bat(sh)
|
# For details about flags see generate_code.py
|
||||||
add_custom_command(
|
add_custom_command(
|
||||||
OUTPUT ${GEN_BINARY_SCHEMA}
|
OUTPUT ${GEN_BINARY_SCHEMA}
|
||||||
COMMAND "${FLATBUFFERS_FLATC_EXECUTABLE}"
|
COMMAND "${FLATBUFFERS_FLATC_EXECUTABLE}"
|
||||||
-b --schema --bfbs-comments --bfbs-builtins
|
-b --schema --bfbs-comments --bfbs-builtins
|
||||||
|
--bfbs-filenames ${SRC_FBS_DIR}
|
||||||
-I "${CMAKE_CURRENT_SOURCE_DIR}/tests/include_test"
|
-I "${CMAKE_CURRENT_SOURCE_DIR}/tests/include_test"
|
||||||
-o "${SRC_FBS_DIR}"
|
-o "${SRC_FBS_DIR}"
|
||||||
"${CMAKE_CURRENT_SOURCE_DIR}/${SRC_FBS}"
|
"${CMAKE_CURRENT_SOURCE_DIR}/${SRC_FBS}"
|
||||||
@@ -422,7 +590,7 @@ function(compile_flatbuffers_schema_to_embedded_binary SRC_FBS OPT)
|
|||||||
message(STATUS "`${SRC_FBS}`: add generation of C++ embedded binary schema code with '${OPT}'")
|
message(STATUS "`${SRC_FBS}`: add generation of C++ embedded binary schema code with '${OPT}'")
|
||||||
get_filename_component(SRC_FBS_DIR ${SRC_FBS} PATH)
|
get_filename_component(SRC_FBS_DIR ${SRC_FBS} PATH)
|
||||||
string(REGEX REPLACE "\\.fbs$" "_bfbs_generated.h" GEN_BFBS_HEADER ${SRC_FBS})
|
string(REGEX REPLACE "\\.fbs$" "_bfbs_generated.h" GEN_BFBS_HEADER ${SRC_FBS})
|
||||||
# For details about flags see generate_code.bat(sh)
|
# For details about flags see generate_code.py
|
||||||
add_custom_command(
|
add_custom_command(
|
||||||
OUTPUT ${GEN_BFBS_HEADER}
|
OUTPUT ${GEN_BFBS_HEADER}
|
||||||
COMMAND "${FLATBUFFERS_FLATC_EXECUTABLE}"
|
COMMAND "${FLATBUFFERS_FLATC_EXECUTABLE}"
|
||||||
@@ -430,6 +598,7 @@ function(compile_flatbuffers_schema_to_embedded_binary SRC_FBS OPT)
|
|||||||
--cpp-ptr-type flatbuffers::unique_ptr # Used to test with C++98 STLs
|
--cpp-ptr-type flatbuffers::unique_ptr # Used to test with C++98 STLs
|
||||||
${OPT}
|
${OPT}
|
||||||
--bfbs-comments --bfbs-builtins --bfbs-gen-embed
|
--bfbs-comments --bfbs-builtins --bfbs-gen-embed
|
||||||
|
--bfbs-filenames ${SRC_FBS_DIR}
|
||||||
-I "${CMAKE_CURRENT_SOURCE_DIR}/tests/include_test"
|
-I "${CMAKE_CURRENT_SOURCE_DIR}/tests/include_test"
|
||||||
-o "${SRC_FBS_DIR}"
|
-o "${SRC_FBS_DIR}"
|
||||||
"${CMAKE_CURRENT_SOURCE_DIR}/${SRC_FBS}"
|
"${CMAKE_CURRENT_SOURCE_DIR}/${SRC_FBS}"
|
||||||
@@ -445,22 +614,24 @@ if(FLATBUFFERS_BUILD_TESTS)
|
|||||||
# TODO Add (monster_test.fbs monsterdata_test.json)->monsterdata_test.mon
|
# TODO Add (monster_test.fbs monsterdata_test.json)->monsterdata_test.mon
|
||||||
compile_flatbuffers_schema_to_cpp(tests/monster_test.fbs)
|
compile_flatbuffers_schema_to_cpp(tests/monster_test.fbs)
|
||||||
compile_flatbuffers_schema_to_binary(tests/monster_test.fbs)
|
compile_flatbuffers_schema_to_binary(tests/monster_test.fbs)
|
||||||
compile_flatbuffers_schema_to_cpp(tests/namespace_test/namespace_test1.fbs)
|
compile_flatbuffers_schema_to_cpp_opt(tests/namespace_test/namespace_test1.fbs "--no-includes;--gen-compare;--gen-name-strings")
|
||||||
compile_flatbuffers_schema_to_cpp(tests/namespace_test/namespace_test2.fbs)
|
compile_flatbuffers_schema_to_cpp_opt(tests/namespace_test/namespace_test2.fbs "--no-includes;--gen-compare;--gen-name-strings")
|
||||||
compile_flatbuffers_schema_to_cpp(tests/union_vector/union_vector.fbs)
|
compile_flatbuffers_schema_to_cpp_opt(tests/union_vector/union_vector.fbs "--no-includes;--gen-compare;--gen-name-strings")
|
||||||
|
compile_flatbuffers_schema_to_cpp(tests/optional_scalars.fbs)
|
||||||
compile_flatbuffers_schema_to_cpp_opt(tests/native_type_test.fbs "")
|
compile_flatbuffers_schema_to_cpp_opt(tests/native_type_test.fbs "")
|
||||||
compile_flatbuffers_schema_to_cpp_opt(tests/arrays_test.fbs "--scoped-enums;--gen-compare")
|
compile_flatbuffers_schema_to_cpp_opt(tests/arrays_test.fbs "--scoped-enums;--gen-compare")
|
||||||
compile_flatbuffers_schema_to_binary(tests/arrays_test.fbs)
|
compile_flatbuffers_schema_to_binary(tests/arrays_test.fbs)
|
||||||
compile_flatbuffers_schema_to_embedded_binary(tests/monster_test.fbs "--no-includes;--gen-compare")
|
compile_flatbuffers_schema_to_embedded_binary(tests/monster_test.fbs "--no-includes;--gen-compare")
|
||||||
|
compile_flatbuffers_schema_to_cpp(tests/native_inline_table_test.fbs "--gen-compare")
|
||||||
if(NOT (MSVC AND (MSVC_VERSION LESS 1900)))
|
if(NOT (MSVC AND (MSVC_VERSION LESS 1900)))
|
||||||
compile_flatbuffers_schema_to_cpp(tests/monster_extra.fbs) # Test floating-point NAN/INF.
|
compile_flatbuffers_schema_to_cpp(tests/monster_extra.fbs) # Test floating-point NAN/INF.
|
||||||
endif()
|
endif()
|
||||||
include_directories(${CMAKE_CURRENT_BINARY_DIR}/tests)
|
include_directories(${CMAKE_CURRENT_BINARY_DIR}/tests)
|
||||||
add_executable(flattests ${FlatBuffers_Tests_SRCS})
|
add_executable(flattests ${FlatBuffers_Tests_SRCS})
|
||||||
|
target_link_libraries(flattests PRIVATE $<BUILD_INTERFACE:ProjectConfig>)
|
||||||
|
|
||||||
add_dependencies(flattests generated_code)
|
add_dependencies(flattests generated_code)
|
||||||
set_property(TARGET flattests
|
|
||||||
PROPERTY COMPILE_DEFINITIONS FLATBUFFERS_TRACK_VERIFIER_BUFFER_SIZE
|
|
||||||
FLATBUFFERS_DEBUG_VERIFICATION_FAILURE=1)
|
|
||||||
if(FLATBUFFERS_CODE_SANITIZE)
|
if(FLATBUFFERS_CODE_SANITIZE)
|
||||||
add_fsanitize_to_target(flattests ${FLATBUFFERS_CODE_SANITIZE})
|
add_fsanitize_to_target(flattests ${FLATBUFFERS_CODE_SANITIZE})
|
||||||
endif()
|
endif()
|
||||||
@@ -468,24 +639,27 @@ if(FLATBUFFERS_BUILD_TESTS)
|
|||||||
compile_flatbuffers_schema_to_cpp(samples/monster.fbs)
|
compile_flatbuffers_schema_to_cpp(samples/monster.fbs)
|
||||||
compile_flatbuffers_schema_to_binary(samples/monster.fbs)
|
compile_flatbuffers_schema_to_binary(samples/monster.fbs)
|
||||||
include_directories(${CMAKE_CURRENT_BINARY_DIR}/samples)
|
include_directories(${CMAKE_CURRENT_BINARY_DIR}/samples)
|
||||||
|
|
||||||
add_executable(flatsamplebinary ${FlatBuffers_Sample_Binary_SRCS})
|
add_executable(flatsamplebinary ${FlatBuffers_Sample_Binary_SRCS})
|
||||||
|
target_link_libraries(flatsamplebinary PRIVATE $<BUILD_INTERFACE:ProjectConfig>)
|
||||||
add_dependencies(flatsamplebinary generated_code)
|
add_dependencies(flatsamplebinary generated_code)
|
||||||
|
|
||||||
add_executable(flatsampletext ${FlatBuffers_Sample_Text_SRCS})
|
add_executable(flatsampletext ${FlatBuffers_Sample_Text_SRCS})
|
||||||
|
target_link_libraries(flatsampletext PRIVATE $<BUILD_INTERFACE:ProjectConfig>)
|
||||||
add_dependencies(flatsampletext generated_code)
|
add_dependencies(flatsampletext generated_code)
|
||||||
|
|
||||||
add_executable(flatsamplebfbs ${FlatBuffers_Sample_BFBS_SRCS})
|
add_executable(flatsamplebfbs ${FlatBuffers_Sample_BFBS_SRCS})
|
||||||
|
target_link_libraries(flatsamplebfbs PRIVATE $<BUILD_INTERFACE:ProjectConfig>)
|
||||||
add_dependencies(flatsamplebfbs generated_code)
|
add_dependencies(flatsamplebfbs generated_code)
|
||||||
|
|
||||||
if(FLATBUFFERS_BUILD_CPP17)
|
if(FLATBUFFERS_BUILD_CPP17)
|
||||||
# Don't generate header for flattests_cpp17 target.
|
# Don't generate header for flattests_cpp17 target.
|
||||||
# This target uses "generated_cpp17/monster_test_generated.h"
|
# This target uses "generated_cpp17/monster_test_generated.h"
|
||||||
# produced by direct call of generate_code.bat(sh) script.
|
|
||||||
add_executable(flattests_cpp17 ${FlatBuffers_Tests_CPP17_SRCS})
|
add_executable(flattests_cpp17 ${FlatBuffers_Tests_CPP17_SRCS})
|
||||||
add_dependencies(flattests_cpp17 generated_code)
|
add_dependencies(flattests_cpp17 generated_code)
|
||||||
|
target_link_libraries(flattests_cpp17 PRIVATE $<BUILD_INTERFACE:ProjectConfig>)
|
||||||
target_compile_features(flattests_cpp17 PRIVATE cxx_std_17)
|
target_compile_features(flattests_cpp17 PRIVATE cxx_std_17)
|
||||||
target_compile_definitions(flattests_cpp17 PRIVATE
|
|
||||||
FLATBUFFERS_TRACK_VERIFIER_BUFFER_SIZE
|
|
||||||
FLATBUFFERS_DEBUG_VERIFICATION_FAILURE=1
|
|
||||||
)
|
|
||||||
if(FLATBUFFERS_CODE_SANITIZE)
|
if(FLATBUFFERS_CODE_SANITIZE)
|
||||||
add_fsanitize_to_target(flattests_cpp17 ${FLATBUFFERS_CODE_SANITIZE})
|
add_fsanitize_to_target(flattests_cpp17 ${FLATBUFFERS_CODE_SANITIZE})
|
||||||
endif()
|
endif()
|
||||||
@@ -493,9 +667,6 @@ if(FLATBUFFERS_BUILD_TESTS)
|
|||||||
endif()
|
endif()
|
||||||
|
|
||||||
if(FLATBUFFERS_BUILD_GRPCTEST)
|
if(FLATBUFFERS_BUILD_GRPCTEST)
|
||||||
if(CMAKE_COMPILER_IS_GNUCXX)
|
|
||||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unused-parameter -Wno-shadow")
|
|
||||||
endif()
|
|
||||||
if(NOT GRPC_INSTALL_PATH)
|
if(NOT GRPC_INSTALL_PATH)
|
||||||
message(SEND_ERROR "GRPC_INSTALL_PATH variable is not defined. See grpc/README.md")
|
message(SEND_ERROR "GRPC_INSTALL_PATH variable is not defined. See grpc/README.md")
|
||||||
endif()
|
endif()
|
||||||
@@ -504,18 +675,23 @@ if(FLATBUFFERS_BUILD_GRPCTEST)
|
|||||||
endif()
|
endif()
|
||||||
INCLUDE_DIRECTORIES(${GRPC_INSTALL_PATH}/include)
|
INCLUDE_DIRECTORIES(${GRPC_INSTALL_PATH}/include)
|
||||||
INCLUDE_DIRECTORIES(${PROTOBUF_DOWNLOAD_PATH}/src)
|
INCLUDE_DIRECTORIES(${PROTOBUF_DOWNLOAD_PATH}/src)
|
||||||
LINK_DIRECTORIES(${GRPC_INSTALL_PATH}/lib)
|
find_package(Threads REQUIRED)
|
||||||
|
list(APPEND CMAKE_PREFIX_PATH ${GRPC_INSTALL_PATH})
|
||||||
|
find_package(absl CONFIG REQUIRED)
|
||||||
|
find_package(protobuf CONFIG REQUIRED)
|
||||||
|
find_package(gRPC CONFIG REQUIRED)
|
||||||
add_executable(grpctest ${FlatBuffers_GRPCTest_SRCS})
|
add_executable(grpctest ${FlatBuffers_GRPCTest_SRCS})
|
||||||
add_dependencies(grpctest generated_code)
|
add_dependencies(grpctest generated_code)
|
||||||
target_link_libraries(grpctest PRIVATE grpc++_unsecure grpc_unsecure gpr pthread dl)
|
target_link_libraries(grpctext
|
||||||
if(FLATBUFFERS_CODE_SANITIZE AND NOT WIN32)
|
PRIVATE
|
||||||
# GRPC test has problems with alignment and will fail under ASAN/UBSAN.
|
$<BUILD_INTERFACE:ProjectConfig>
|
||||||
# add_fsanitize_to_target(grpctest ${FLATBUFFERS_CODE_SANITIZE})
|
gRPC::grpc++_unsecure
|
||||||
endif()
|
gRPC::gpr
|
||||||
|
pthread
|
||||||
|
dl
|
||||||
|
)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
include(CMake/Version.cmake)
|
|
||||||
|
|
||||||
if(FLATBUFFERS_INSTALL)
|
if(FLATBUFFERS_INSTALL)
|
||||||
include(GNUInstallDirs)
|
include(GNUInstallDirs)
|
||||||
|
|
||||||
@@ -523,28 +699,21 @@ if(FLATBUFFERS_INSTALL)
|
|||||||
|
|
||||||
set(FB_CMAKE_DIR "${CMAKE_INSTALL_LIBDIR}/cmake/flatbuffers")
|
set(FB_CMAKE_DIR "${CMAKE_INSTALL_LIBDIR}/cmake/flatbuffers")
|
||||||
|
|
||||||
configure_file(CMake/FlatbuffersConfigVersion.cmake.in FlatbuffersConfigVersion.cmake @ONLY)
|
configure_file(CMake/FlatBuffersConfigVersion.cmake.in FlatBuffersConfigVersion.cmake @ONLY)
|
||||||
install(
|
install(
|
||||||
FILES "CMake/FlatbuffersConfig.cmake" "${CMAKE_CURRENT_BINARY_DIR}/FlatbuffersConfigVersion.cmake"
|
FILES "CMake/FlatBuffersConfig.cmake" "${CMAKE_CURRENT_BINARY_DIR}/FlatBuffersConfigVersion.cmake"
|
||||||
DESTINATION ${FB_CMAKE_DIR}
|
DESTINATION ${FB_CMAKE_DIR}
|
||||||
)
|
)
|
||||||
|
|
||||||
if(FLATBUFFERS_BUILD_FLATLIB)
|
if(FLATBUFFERS_BUILD_FLATLIB)
|
||||||
if(CMAKE_VERSION VERSION_LESS 3.0)
|
install(
|
||||||
install(
|
TARGETS flatbuffers EXPORT FlatBuffersTargets
|
||||||
TARGETS flatbuffers EXPORT FlatbuffersTargets
|
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
||||||
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
|
||||||
)
|
)
|
||||||
else()
|
|
||||||
install(
|
|
||||||
TARGETS flatbuffers EXPORT FlatbuffersTargets
|
|
||||||
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
|
||||||
INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
|
|
||||||
)
|
|
||||||
endif()
|
|
||||||
|
|
||||||
install(EXPORT FlatbuffersTargets
|
install(EXPORT FlatBuffersTargets
|
||||||
FILE FlatbuffersTargets.cmake
|
FILE FlatBuffersTargets.cmake
|
||||||
NAMESPACE flatbuffers::
|
NAMESPACE flatbuffers::
|
||||||
DESTINATION ${FB_CMAKE_DIR}
|
DESTINATION ${FB_CMAKE_DIR}
|
||||||
)
|
)
|
||||||
@@ -565,30 +734,29 @@ if(FLATBUFFERS_INSTALL)
|
|||||||
endif()
|
endif()
|
||||||
|
|
||||||
if(FLATBUFFERS_BUILD_SHAREDLIB)
|
if(FLATBUFFERS_BUILD_SHAREDLIB)
|
||||||
if(CMAKE_VERSION VERSION_LESS 3.0)
|
install(
|
||||||
install(
|
TARGETS flatbuffers_shared EXPORT FlatBuffersSharedTargets
|
||||||
TARGETS flatbuffers_shared EXPORT FlatbuffersSharedTargets
|
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
||||||
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
RUNTIME DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
||||||
RUNTIME DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
||||||
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
|
||||||
)
|
)
|
||||||
else()
|
|
||||||
install(
|
|
||||||
TARGETS flatbuffers_shared EXPORT FlatbuffersSharedTargets
|
|
||||||
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
|
||||||
RUNTIME DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
|
||||||
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
|
||||||
INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
|
|
||||||
)
|
|
||||||
endif()
|
|
||||||
|
|
||||||
install(
|
install(
|
||||||
EXPORT FlatbuffersSharedTargets
|
EXPORT FlatBuffersSharedTargets
|
||||||
FILE FlatbuffersSharedTargets.cmake
|
FILE FlatBuffersSharedTargets.cmake
|
||||||
NAMESPACE flatbuffers::
|
NAMESPACE flatbuffers::
|
||||||
DESTINATION ${FB_CMAKE_DIR}
|
DESTINATION ${FB_CMAKE_DIR}
|
||||||
)
|
)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
if(FLATBUFFERS_BUILD_SHAREDLIB OR FLATBUFFERS_BUILD_FLATLIB)
|
||||||
|
configure_file(CMake/flatbuffers.pc.in flatbuffers.pc @ONLY)
|
||||||
|
install(
|
||||||
|
FILES "${CMAKE_CURRENT_BINARY_DIR}/flatbuffers.pc"
|
||||||
|
DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig
|
||||||
|
)
|
||||||
|
endif()
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if(FLATBUFFERS_BUILD_TESTS)
|
if(FLATBUFFERS_BUILD_TESTS)
|
||||||
@@ -619,9 +787,23 @@ if(UNIX)
|
|||||||
# Use of CPack only supported on Linux systems.
|
# Use of CPack only supported on Linux systems.
|
||||||
if(FLATBUFFERS_PACKAGE_DEBIAN)
|
if(FLATBUFFERS_PACKAGE_DEBIAN)
|
||||||
include(CMake/PackageDebian.cmake)
|
include(CMake/PackageDebian.cmake)
|
||||||
|
include(CPack)
|
||||||
endif()
|
endif()
|
||||||
if (FLATBUFFERS_PACKAGE_REDHAT)
|
if (FLATBUFFERS_PACKAGE_REDHAT)
|
||||||
include(CMake/PackageRedhat.cmake)
|
include(CMake/PackageRedhat.cmake)
|
||||||
|
include(CPack)
|
||||||
endif()
|
endif()
|
||||||
include(CPack)
|
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
# Include for running Google Benchmarks.
|
||||||
|
if(FLATBUFFERS_BUILD_BENCHMARKS)
|
||||||
|
add_subdirectory(benchmarks)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
# Add FlatBuffers::FlatBuffers interface, needed for FetchContent_Declare
|
||||||
|
add_library(FlatBuffers INTERFACE)
|
||||||
|
add_library(FlatBuffers::FlatBuffers ALIAS FlatBuffers)
|
||||||
|
target_include_directories(
|
||||||
|
FlatBuffers
|
||||||
|
INTERFACE $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
|
||||||
|
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/include>)
|
||||||
|
|||||||
22
Formatters.md
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
# Format Guidelines
|
||||||
|
|
||||||
|
If you are interesting in contributing to the flatbuffers project, please take a second to read this document. Each language has it's own set of rules, that are defined in their respective formatter/linter documents.
|
||||||
|
|
||||||
|
# Notes
|
||||||
|
|
||||||
|
- Run the linter on the language you are working on before making a Pull Request.
|
||||||
|
- DONT format/lint the generated code.
|
||||||
|
|
||||||
|
# Languages
|
||||||
|
|
||||||
|
## C++
|
||||||
|
|
||||||
|
C++ uses `clang-format` as it's formatter. Run the following script `sh scripts/clang-format-git.sh`, and it should style the C++ code according to [google style guide](https://google.github.io/styleguide/cppguide.html).
|
||||||
|
|
||||||
|
## Swift
|
||||||
|
|
||||||
|
Swift uses swiftformat as it's formatter. Take a look at [how to install here](https://github.com/nicklockwood/SwiftFormat/blob/master/README.md#how-do-i-install-it). Run the following command `swiftformat --config swift.swiftformat .` in the root directory of the project
|
||||||
|
|
||||||
|
## Typescript
|
||||||
|
|
||||||
|
Typescript uses eslint as it's linter. Take a look at [how to install here](https://eslint.org/docs/user-guide/getting-started). Run the following command `eslint ts/** --ext .ts` in the root directory of the project
|
||||||
11
SECURITY.md
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
# Security Policy
|
||||||
|
|
||||||
|
## Reporting a Vulnerability
|
||||||
|
|
||||||
|
To report a security issue, please use http://g.co/vulnz. We use
|
||||||
|
http://g.co/vulnz for our intake, and do coordination and disclosure here on
|
||||||
|
GitHub (including using GitHub Security Advisory). The Google Security Team will
|
||||||
|
respond within 5 working days of your report on g.co/vulnz.
|
||||||
|
|
||||||
|
Select the `I want to report a technical security or an abuse risk related bug
|
||||||
|
in a Google product (SQLi, XSS, etc.)` option and complete the form.
|
||||||
92
WORKSPACE
@@ -3,16 +3,96 @@ workspace(name = "com_github_google_flatbuffers")
|
|||||||
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
|
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
|
||||||
|
|
||||||
http_archive(
|
http_archive(
|
||||||
name = "io_bazel_rules_go",
|
name = "platforms",
|
||||||
|
sha256 = "379113459b0feaf6bfbb584a91874c065078aa673222846ac765f86661c27407",
|
||||||
urls = [
|
urls = [
|
||||||
"https://storage.googleapis.com/bazel-mirror/github.com/bazelbuild/rules_go/releases/download/v0.20.3/rules_go-v0.20.3.tar.gz",
|
"https://mirror.bazel.build/github.com/bazelbuild/platforms/releases/download/0.0.5/platforms-0.0.5.tar.gz",
|
||||||
"https://github.com/bazelbuild/rules_go/releases/download/v0.20.3/rules_go-v0.20.3.tar.gz",
|
"https://github.com/bazelbuild/platforms/releases/download/0.0.5/platforms-0.0.5.tar.gz",
|
||||||
],
|
],
|
||||||
sha256 = "e88471aea3a3a4f19ec1310a55ba94772d087e9ce46e41ae38ecebe17935de7b",
|
|
||||||
)
|
)
|
||||||
|
|
||||||
load("@io_bazel_rules_go//go:deps.bzl", "go_rules_dependencies", "go_register_toolchains")
|
http_archive(
|
||||||
|
name = "build_bazel_rules_swift",
|
||||||
|
sha256 = "a2fd565e527f83fb3f9eb07eb9737240e668c9242d3bc318712efa54a7deda97",
|
||||||
|
url = "https://github.com/bazelbuild/rules_swift/releases/download/0.27.0/rules_swift.0.27.0.tar.gz",
|
||||||
|
)
|
||||||
|
|
||||||
|
load(
|
||||||
|
"@build_bazel_rules_swift//swift:repositories.bzl",
|
||||||
|
"swift_rules_dependencies",
|
||||||
|
)
|
||||||
|
|
||||||
|
swift_rules_dependencies()
|
||||||
|
|
||||||
|
load(
|
||||||
|
"@build_bazel_rules_swift//swift:extras.bzl",
|
||||||
|
"swift_rules_extra_dependencies",
|
||||||
|
)
|
||||||
|
|
||||||
|
swift_rules_extra_dependencies()
|
||||||
|
|
||||||
|
http_archive(
|
||||||
|
name = "io_bazel_rules_go",
|
||||||
|
sha256 = "16e9fca53ed6bd4ff4ad76facc9b7b651a89db1689a2877d6fd7b82aa824e366",
|
||||||
|
urls = [
|
||||||
|
"https://mirror.bazel.build/github.com/bazelbuild/rules_go/releases/download/v0.34.0/rules_go-v0.34.0.zip",
|
||||||
|
"https://github.com/bazelbuild/rules_go/releases/download/v0.34.0/rules_go-v0.34.0.zip",
|
||||||
|
],
|
||||||
|
)
|
||||||
|
|
||||||
|
load("@io_bazel_rules_go//go:deps.bzl", "go_rules_dependencies")
|
||||||
|
|
||||||
go_rules_dependencies()
|
go_rules_dependencies()
|
||||||
|
|
||||||
go_register_toolchains()
|
##### Protobuf
|
||||||
|
_PROTOBUF_VERSION = "3.15.2"
|
||||||
|
|
||||||
|
http_archive(
|
||||||
|
name = "com_google_protobuf",
|
||||||
|
strip_prefix = "protobuf-" + _PROTOBUF_VERSION,
|
||||||
|
urls = [
|
||||||
|
"https://github.com/protocolbuffers/protobuf/archive/v" + _PROTOBUF_VERSION + ".tar.gz",
|
||||||
|
],
|
||||||
|
)
|
||||||
|
|
||||||
|
##### GRPC
|
||||||
|
_GRPC_VERSION = "1.48.0" # https://github.com/grpc/grpc/releases/tag/v1.48.0
|
||||||
|
|
||||||
|
http_archive(
|
||||||
|
name = "com_github_grpc_grpc",
|
||||||
|
strip_prefix = "grpc-" + _GRPC_VERSION,
|
||||||
|
urls = ["https://github.com/grpc/grpc/archive/refs/tags/v" + _GRPC_VERSION + ".tar.gz"],
|
||||||
|
)
|
||||||
|
|
||||||
|
load("@com_github_grpc_grpc//bazel:grpc_deps.bzl", "grpc_deps")
|
||||||
|
|
||||||
|
grpc_deps()
|
||||||
|
|
||||||
|
load("@com_github_grpc_grpc//bazel:grpc_extra_deps.bzl", "grpc_extra_deps")
|
||||||
|
|
||||||
|
grpc_extra_deps()
|
||||||
|
|
||||||
|
# rules_go from https://github.com/bazelbuild/rules_go/releases/tag/v0.34.0
|
||||||
|
http_archive(
|
||||||
|
name = "build_bazel_rules_nodejs",
|
||||||
|
sha256 = "965ee2492a2b087cf9e0f2ca472aeaf1be2eb650e0cfbddf514b9a7d3ea4b02a",
|
||||||
|
urls = ["https://github.com/bazelbuild/rules_nodejs/releases/download/5.2.0/rules_nodejs-5.2.0.tar.gz"],
|
||||||
|
)
|
||||||
|
|
||||||
|
load("@build_bazel_rules_nodejs//:repositories.bzl", "build_bazel_rules_nodejs_dependencies")
|
||||||
|
|
||||||
|
build_bazel_rules_nodejs_dependencies()
|
||||||
|
|
||||||
|
load("@build_bazel_rules_nodejs//:index.bzl", "node_repositories", "yarn_install")
|
||||||
|
|
||||||
|
node_repositories()
|
||||||
|
|
||||||
|
yarn_install(
|
||||||
|
name = "npm",
|
||||||
|
exports_directories_only = False,
|
||||||
|
# Unfreeze to add/remove packages.
|
||||||
|
frozen_lockfile = True,
|
||||||
|
package_json = "//:package.json",
|
||||||
|
symlink_node_modules = False,
|
||||||
|
yarn_lock = "//:yarn.lock",
|
||||||
|
)
|
||||||
|
|||||||
@@ -1,20 +1,4 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<!-- Copyright (c) 2013 Google, Inc.
|
|
||||||
|
|
||||||
This software is provided 'as-is', without any express or implied
|
|
||||||
warranty. In no event will the authors be held liable for any damages
|
|
||||||
arising from the use of this software.
|
|
||||||
Permission is granted to anyone to use this software for any purpose,
|
|
||||||
including commercial applications, and to alter it and redistribute it
|
|
||||||
freely, subject to the following restrictions:
|
|
||||||
1. The origin of this software must not be misrepresented; you must not
|
|
||||||
claim that you wrote the original software. If you use this software
|
|
||||||
in a product, an acknowledgment in the product documentation would be
|
|
||||||
appreciated but is not required.
|
|
||||||
2. Altered source versions must be plainly marked as such, and must not be
|
|
||||||
misrepresented as being the original software.
|
|
||||||
3. This notice may not be removed or altered from any source distribution.
|
|
||||||
-->
|
|
||||||
<!-- BEGIN_INCLUDE(manifest) -->
|
<!-- BEGIN_INCLUDE(manifest) -->
|
||||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
package="com.example.FlatBufferTest">
|
package="com.example.FlatBufferTest">
|
||||||
|
|||||||
1
android/app/.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
|||||||
|
/build
|
||||||
141
android/app/build.gradle
Normal file
@@ -0,0 +1,141 @@
|
|||||||
|
apply plugin: 'com.android.application'
|
||||||
|
apply plugin: 'kotlin-android'
|
||||||
|
apply plugin: 'kotlin-android-extensions'
|
||||||
|
|
||||||
|
android {
|
||||||
|
compileSdkVersion 30
|
||||||
|
buildToolsVersion "30.0.2"
|
||||||
|
|
||||||
|
defaultConfig {
|
||||||
|
applicationId "com.flatbuffers.app"
|
||||||
|
minSdkVersion 16
|
||||||
|
targetSdkVersion 30
|
||||||
|
versionCode 1
|
||||||
|
versionName "1.0"
|
||||||
|
|
||||||
|
compileOptions {
|
||||||
|
sourceCompatibility JavaVersion.VERSION_1_8
|
||||||
|
targetCompatibility JavaVersion.VERSION_1_8
|
||||||
|
}
|
||||||
|
|
||||||
|
ndk {
|
||||||
|
abiFilters 'arm64-v8a', 'armeabi-v7a'
|
||||||
|
}
|
||||||
|
|
||||||
|
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
||||||
|
externalNativeBuild {
|
||||||
|
cmake {
|
||||||
|
arguments "-DFLATBUFFERS_SRC=${rootProject.projectDir}/.."
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
buildTypes {
|
||||||
|
release {
|
||||||
|
minifyEnabled false
|
||||||
|
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
externalNativeBuild {
|
||||||
|
cmake {
|
||||||
|
path "src/main/cpp/CMakeLists.txt"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
task generateFbsCpp(type: Exec) {
|
||||||
|
def inputDir = file("$projectDir/src/main/fbs")
|
||||||
|
def outputCppDir = file("$projectDir/src/main/cpp/generated/")
|
||||||
|
def fbsFiles = layout.files { file(inputDir).listFiles() }.filter { File f -> f.name.endsWith(".fbs") }.toList()
|
||||||
|
ignoreExitValue(true)
|
||||||
|
|
||||||
|
standardOutput = new ByteArrayOutputStream()
|
||||||
|
errorOutput = new ByteArrayOutputStream()
|
||||||
|
def commandLineArgs = ['flatc', '-o', outputCppDir, '--cpp']
|
||||||
|
fbsFiles.forEach{
|
||||||
|
commandLineArgs.add(it.path)
|
||||||
|
}
|
||||||
|
|
||||||
|
commandLine commandLineArgs
|
||||||
|
|
||||||
|
doFirst {
|
||||||
|
delete "$outputCppDir/"
|
||||||
|
mkdir "$outputCppDir/"
|
||||||
|
}
|
||||||
|
|
||||||
|
doLast {
|
||||||
|
if (executionResult.get().exitValue != 0) {
|
||||||
|
throw new GradleException("flatc failed with: ${executionResult.get().toString()}")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
task generateFbsKotlin(type: Exec) {
|
||||||
|
def inputDir = file("$projectDir/src/main/fbs")
|
||||||
|
def outputKotlinDir = file("$projectDir/src/main/java/generated/")
|
||||||
|
def fbsFiles = layout.files { file(inputDir).listFiles() }.filter { File f -> f.name.endsWith(".fbs") }.toList()
|
||||||
|
ignoreExitValue(true)
|
||||||
|
|
||||||
|
standardOutput = new ByteArrayOutputStream()
|
||||||
|
errorOutput = new ByteArrayOutputStream()
|
||||||
|
|
||||||
|
setErrorOutput(errorOutput)
|
||||||
|
setStandardOutput(standardOutput)
|
||||||
|
|
||||||
|
def commandLineArgs = ['flatc', '-o', outputKotlinDir, '--kotlin']
|
||||||
|
fbsFiles.forEach{
|
||||||
|
commandLineArgs.add(it.path)
|
||||||
|
}
|
||||||
|
commandLine commandLineArgs
|
||||||
|
|
||||||
|
doFirst {
|
||||||
|
delete "$outputKotlinDir/"
|
||||||
|
mkdir "$outputKotlinDir/"
|
||||||
|
}
|
||||||
|
doLast {
|
||||||
|
if (executionResult.get().exitValue != 0) {
|
||||||
|
throw new GradleException("flatc failed with: ${executionResult.get().toString()}")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
afterEvaluate {
|
||||||
|
tasks.named("preBuild") {
|
||||||
|
dependsOn(generateFbsKotlin)
|
||||||
|
dependsOn(generateFbsCpp)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// flavorDimensions "stl-variant"
|
||||||
|
// productFlavors {
|
||||||
|
// gnustl {
|
||||||
|
// dimension "stl-variant"
|
||||||
|
// applicationIdSuffix ".gnustl"
|
||||||
|
// versionNameSuffix "-gnustl"
|
||||||
|
// externalNativeBuild {
|
||||||
|
// ndkBuild {
|
||||||
|
// arguments "APP_STL=gnustl_static"
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// libcpp {
|
||||||
|
// dimension "stl-variant"
|
||||||
|
// applicationIdSuffix ".libcpp"
|
||||||
|
// versionNameSuffix "-libcpp"
|
||||||
|
// externalNativeBuild {
|
||||||
|
// ndkBuild {
|
||||||
|
// arguments "APP_STL=c++_static"
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
implementation fileTree(dir: "libs", include: ["*.jar"])
|
||||||
|
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
|
||||||
|
implementation 'androidx.core:core-ktx:1.3.2'
|
||||||
|
implementation 'androidx.appcompat:appcompat:1.2.0'
|
||||||
|
implementation 'com.google.flatbuffers:flatbuffers-java:2.0.0'
|
||||||
|
|
||||||
|
}
|
||||||
21
android/app/proguard-rules.pro
vendored
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
# Add project specific ProGuard rules here.
|
||||||
|
# You can control the set of applied configuration files using the
|
||||||
|
# proguardFiles setting in build.gradle.
|
||||||
|
#
|
||||||
|
# For more details, see
|
||||||
|
# http://developer.android.com/guide/developing/tools/proguard.html
|
||||||
|
|
||||||
|
# If your project uses WebView with JS, uncomment the following
|
||||||
|
# and specify the fully qualified class name to the JavaScript interface
|
||||||
|
# class:
|
||||||
|
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
|
||||||
|
# public *;
|
||||||
|
#}
|
||||||
|
|
||||||
|
# Uncomment this to preserve the line number information for
|
||||||
|
# debugging stack traces.
|
||||||
|
#-keepattributes SourceFile,LineNumberTable
|
||||||
|
|
||||||
|
# If you keep the line number information, uncomment this to
|
||||||
|
# hide the original source file name.
|
||||||
|
#-renamesourcefileattribute SourceFile
|
||||||
21
android/app/src/main/AndroidManifest.xml
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
package="com.flatbuffers.app">
|
||||||
|
|
||||||
|
<application
|
||||||
|
android:allowBackup="true"
|
||||||
|
android:icon="@mipmap/ic_launcher"
|
||||||
|
android:label="@string/app_name"
|
||||||
|
android:roundIcon="@mipmap/ic_launcher_round"
|
||||||
|
android:supportsRtl="true"
|
||||||
|
android:theme="@style/AppTheme">
|
||||||
|
<activity android:name=".MainActivity">
|
||||||
|
<intent-filter>
|
||||||
|
<action android:name="android.intent.action.MAIN" />
|
||||||
|
|
||||||
|
<category android:name="android.intent.category.LAUNCHER" />
|
||||||
|
</intent-filter>
|
||||||
|
</activity>
|
||||||
|
</application>
|
||||||
|
|
||||||
|
</manifest>
|
||||||
54
android/app/src/main/cpp/CMakeLists.txt
Normal file
@@ -0,0 +1,54 @@
|
|||||||
|
# For more information about using CMake with Android Studio, read the
|
||||||
|
# documentation: https://d.android.com/studio/projects/add-native-code.html
|
||||||
|
|
||||||
|
# Sets the minimum version of CMake required to build the native library.
|
||||||
|
|
||||||
|
cmake_minimum_required(VERSION 3.4.1)
|
||||||
|
|
||||||
|
# Creates and names a library, sets it as either STATIC
|
||||||
|
# or SHARED, and provides the relative paths to its source code.
|
||||||
|
# You can define multiple libraries, and CMake builds them for you.
|
||||||
|
# Gradle automatically packages shared libraries with your APK.
|
||||||
|
|
||||||
|
include_directories(${FLATBUFFERS_SRC}/include)
|
||||||
|
|
||||||
|
add_subdirectory(flatbuffers)
|
||||||
|
|
||||||
|
FILE(GLOB Generated_SRCS generated/*.h)
|
||||||
|
|
||||||
|
add_library( # Sets the name of the library.
|
||||||
|
native-lib
|
||||||
|
|
||||||
|
# Sets the library as a shared library.
|
||||||
|
SHARED
|
||||||
|
|
||||||
|
# Provides a relative path to your source file(s).
|
||||||
|
animals.cpp
|
||||||
|
${Generated_SRCS}
|
||||||
|
|
||||||
|
)
|
||||||
|
|
||||||
|
# Searches for a specified prebuilt library and stores the path as a
|
||||||
|
# variable. Because CMake includes system libraries in the search path by
|
||||||
|
# default, you only need to specify the name of the public NDK library
|
||||||
|
# you want to add. CMake verifies that the library exists before
|
||||||
|
# completing its build.
|
||||||
|
|
||||||
|
find_library( # Sets the name of the path variable.
|
||||||
|
log-lib
|
||||||
|
|
||||||
|
# Specifies the name of the NDK library that
|
||||||
|
# you want CMake to locate.
|
||||||
|
log )
|
||||||
|
|
||||||
|
# Specifies libraries CMake should link to your target library. You
|
||||||
|
# can link multiple libraries, such as libraries you define in this
|
||||||
|
# build script, prebuilt third-party libraries, or system libraries.
|
||||||
|
|
||||||
|
target_link_libraries( # Specifies the target library.
|
||||||
|
native-lib
|
||||||
|
flatbuffers
|
||||||
|
flatbuffers_tests
|
||||||
|
# Links the target library to the log library
|
||||||
|
# included in the NDK.
|
||||||
|
${log-lib} )
|
||||||
39
android/app/src/main/cpp/animals.cpp
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
/*
|
||||||
|
* 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 <jni.h>
|
||||||
|
#include <string>
|
||||||
|
#include <search.h>
|
||||||
|
#include "generated/animal_generated.h"
|
||||||
|
|
||||||
|
using namespace com::fbs::app;
|
||||||
|
using namespace flatbuffers;
|
||||||
|
|
||||||
|
extern "C" JNIEXPORT jbyteArray JNICALL Java_com_flatbuffers_app_MainActivity_createAnimalFromJNI(
|
||||||
|
JNIEnv* env,
|
||||||
|
jobject /* this */) {
|
||||||
|
// create a new animal flatbuffers
|
||||||
|
auto fb = FlatBufferBuilder(1024);
|
||||||
|
auto tiger = CreateAnimalDirect(fb, "Tiger", "Roar", 300);
|
||||||
|
fb.Finish(tiger);
|
||||||
|
|
||||||
|
// copies it to a Java byte array.
|
||||||
|
auto buf = reinterpret_cast<jbyte*>(fb.GetBufferPointer());
|
||||||
|
int size = fb.GetSize();
|
||||||
|
auto ret = env->NewByteArray(size);
|
||||||
|
env->SetByteArrayRegion (ret, 0, fb.GetSize(), buf);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
74
android/app/src/main/cpp/flatbuffers/CMakeLists.txt
Normal file
@@ -0,0 +1,74 @@
|
|||||||
|
# For more information about using CMake with Android Studio, read the
|
||||||
|
# documentation: https://d.android.com/studio/projects/add-native-code.html
|
||||||
|
|
||||||
|
# Sets the minimum version of CMake required to build the native library.
|
||||||
|
|
||||||
|
cmake_minimum_required(VERSION 3.4.1)
|
||||||
|
|
||||||
|
include_directories(${FLATBUFFERS_SRC}/include)
|
||||||
|
|
||||||
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++11 -fexceptions -Wall -DFLATBUFFERS_TRACK_VERIFIER_BUFFER_SIZE")
|
||||||
|
|
||||||
|
# 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")
|
||||||
|
|
||||||
|
set(FlatBuffers_Library_SRCS
|
||||||
|
${FLATBUFFERS_SRC}/include/flatbuffers/allocator.h
|
||||||
|
${FLATBUFFERS_SRC}/include/flatbuffers/array.h
|
||||||
|
${FLATBUFFERS_SRC}/include/flatbuffers/base.h
|
||||||
|
${FLATBUFFERS_SRC}/include/flatbuffers/bfbs_generator.h
|
||||||
|
${FLATBUFFERS_SRC}/include/flatbuffers/buffer.h
|
||||||
|
${FLATBUFFERS_SRC}/include/flatbuffers/buffer_ref.h
|
||||||
|
${FLATBUFFERS_SRC}/include/flatbuffers/default_allocator.h
|
||||||
|
${FLATBUFFERS_SRC}/include/flatbuffers/detached_buffer.h
|
||||||
|
${FLATBUFFERS_SRC}/include/flatbuffers/flatbuffer_builder.h
|
||||||
|
${FLATBUFFERS_SRC}/include/flatbuffers/flatbuffers.h
|
||||||
|
${FLATBUFFERS_SRC}/include/flatbuffers/flexbuffers.h
|
||||||
|
${FLATBUFFERS_SRC}/include/flatbuffers/flex_flat_util.h
|
||||||
|
${FLATBUFFERS_SRC}/include/flatbuffers/hash.h
|
||||||
|
${FLATBUFFERS_SRC}/include/flatbuffers/idl.h
|
||||||
|
${FLATBUFFERS_SRC}/include/flatbuffers/minireflect.h
|
||||||
|
${FLATBUFFERS_SRC}/include/flatbuffers/reflection.h
|
||||||
|
${FLATBUFFERS_SRC}/include/flatbuffers/reflection_generated.h
|
||||||
|
${FLATBUFFERS_SRC}/include/flatbuffers/registry.h
|
||||||
|
${FLATBUFFERS_SRC}/include/flatbuffers/stl_emulation.h
|
||||||
|
${FLATBUFFERS_SRC}/include/flatbuffers/string.h
|
||||||
|
${FLATBUFFERS_SRC}/include/flatbuffers/struct.h
|
||||||
|
${FLATBUFFERS_SRC}/include/flatbuffers/table.h
|
||||||
|
${FLATBUFFERS_SRC}/include/flatbuffers/util.h
|
||||||
|
${FLATBUFFERS_SRC}/include/flatbuffers/vector.h
|
||||||
|
${FLATBUFFERS_SRC}/include/flatbuffers/vector_downward.h
|
||||||
|
${FLATBUFFERS_SRC}/include/flatbuffers/verifier.h
|
||||||
|
${FLATBUFFERS_SRC}/src/idl_parser.cpp
|
||||||
|
${FLATBUFFERS_SRC}/src/idl_gen_text.cpp
|
||||||
|
${FLATBUFFERS_SRC}/src/reflection.cpp
|
||||||
|
${FLATBUFFERS_SRC}/src/util.cpp
|
||||||
|
${FLATBUFFERS_SRC}/src/idl_gen_fbs.cpp
|
||||||
|
${FLATBUFFERS_SRC}/src/code_generators.cpp
|
||||||
|
)
|
||||||
|
|
||||||
|
set(FlatBuffers_Test_SRCS
|
||||||
|
${FLATBUFFERS_SRC}/tests/test.cpp
|
||||||
|
${FLATBUFFERS_SRC}/tests/test_assert.h
|
||||||
|
${FLATBUFFERS_SRC}/tests/test_builder.h
|
||||||
|
${FLATBUFFERS_SRC}/tests/test_assert.cpp
|
||||||
|
${FLATBUFFERS_SRC}/tests/test_builder.cpp
|
||||||
|
${FLATBUFFERS_SRC}/tests/native_type_test_impl.h
|
||||||
|
${FLATBUFFERS_SRC}/tests/native_type_test_impl.cpp
|
||||||
|
)
|
||||||
|
|
||||||
|
add_library( # Sets the name of the library.
|
||||||
|
flatbuffers
|
||||||
|
|
||||||
|
${FlatBuffers_Library_SRCS}
|
||||||
|
${FlatBuffers_Test_SRCS}
|
||||||
|
${Generated_SRCS}
|
||||||
|
)
|
||||||
|
|
||||||
|
add_library( # Sets the name of the library.
|
||||||
|
flatbuffers_tests
|
||||||
|
|
||||||
|
${FlatBuffers_Test_SRCS}
|
||||||
|
)
|
||||||
127
android/app/src/main/cpp/generated/animal_generated.h
Normal file
@@ -0,0 +1,127 @@
|
|||||||
|
// automatically generated by the FlatBuffers compiler, do not modify
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef FLATBUFFERS_GENERATED_ANIMAL_COM_FBS_APP_H_
|
||||||
|
#define FLATBUFFERS_GENERATED_ANIMAL_COM_FBS_APP_H_
|
||||||
|
|
||||||
|
#include "flatbuffers/flatbuffers.h"
|
||||||
|
|
||||||
|
namespace com {
|
||||||
|
namespace fbs {
|
||||||
|
namespace app {
|
||||||
|
|
||||||
|
struct Animal;
|
||||||
|
struct AnimalBuilder;
|
||||||
|
|
||||||
|
struct Animal FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table {
|
||||||
|
typedef AnimalBuilder Builder;
|
||||||
|
enum FlatBuffersVTableOffset FLATBUFFERS_VTABLE_UNDERLYING_TYPE {
|
||||||
|
VT_NAME = 4,
|
||||||
|
VT_SOUND = 6,
|
||||||
|
VT_WEIGHT = 8
|
||||||
|
};
|
||||||
|
const flatbuffers::String *name() const {
|
||||||
|
return GetPointer<const flatbuffers::String *>(VT_NAME);
|
||||||
|
}
|
||||||
|
const flatbuffers::String *sound() const {
|
||||||
|
return GetPointer<const flatbuffers::String *>(VT_SOUND);
|
||||||
|
}
|
||||||
|
uint16_t weight() const {
|
||||||
|
return GetField<uint16_t>(VT_WEIGHT, 0);
|
||||||
|
}
|
||||||
|
bool Verify(flatbuffers::Verifier &verifier) const {
|
||||||
|
return VerifyTableStart(verifier) &&
|
||||||
|
VerifyOffset(verifier, VT_NAME) &&
|
||||||
|
verifier.VerifyString(name()) &&
|
||||||
|
VerifyOffset(verifier, VT_SOUND) &&
|
||||||
|
verifier.VerifyString(sound()) &&
|
||||||
|
VerifyField<uint16_t>(verifier, VT_WEIGHT, 2) &&
|
||||||
|
verifier.EndTable();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
struct AnimalBuilder {
|
||||||
|
typedef Animal Table;
|
||||||
|
flatbuffers::FlatBufferBuilder &fbb_;
|
||||||
|
flatbuffers::uoffset_t start_;
|
||||||
|
void add_name(flatbuffers::Offset<flatbuffers::String> name) {
|
||||||
|
fbb_.AddOffset(Animal::VT_NAME, name);
|
||||||
|
}
|
||||||
|
void add_sound(flatbuffers::Offset<flatbuffers::String> sound) {
|
||||||
|
fbb_.AddOffset(Animal::VT_SOUND, sound);
|
||||||
|
}
|
||||||
|
void add_weight(uint16_t weight) {
|
||||||
|
fbb_.AddElement<uint16_t>(Animal::VT_WEIGHT, weight, 0);
|
||||||
|
}
|
||||||
|
explicit AnimalBuilder(flatbuffers::FlatBufferBuilder &_fbb)
|
||||||
|
: fbb_(_fbb) {
|
||||||
|
start_ = fbb_.StartTable();
|
||||||
|
}
|
||||||
|
flatbuffers::Offset<Animal> Finish() {
|
||||||
|
const auto end = fbb_.EndTable(start_);
|
||||||
|
auto o = flatbuffers::Offset<Animal>(end);
|
||||||
|
return o;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
inline flatbuffers::Offset<Animal> CreateAnimal(
|
||||||
|
flatbuffers::FlatBufferBuilder &_fbb,
|
||||||
|
flatbuffers::Offset<flatbuffers::String> name = 0,
|
||||||
|
flatbuffers::Offset<flatbuffers::String> sound = 0,
|
||||||
|
uint16_t weight = 0) {
|
||||||
|
AnimalBuilder builder_(_fbb);
|
||||||
|
builder_.add_sound(sound);
|
||||||
|
builder_.add_name(name);
|
||||||
|
builder_.add_weight(weight);
|
||||||
|
return builder_.Finish();
|
||||||
|
}
|
||||||
|
|
||||||
|
inline flatbuffers::Offset<Animal> CreateAnimalDirect(
|
||||||
|
flatbuffers::FlatBufferBuilder &_fbb,
|
||||||
|
const char *name = nullptr,
|
||||||
|
const char *sound = nullptr,
|
||||||
|
uint16_t weight = 0) {
|
||||||
|
auto name__ = name ? _fbb.CreateString(name) : 0;
|
||||||
|
auto sound__ = sound ? _fbb.CreateString(sound) : 0;
|
||||||
|
return com::fbs::app::CreateAnimal(
|
||||||
|
_fbb,
|
||||||
|
name__,
|
||||||
|
sound__,
|
||||||
|
weight);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline const com::fbs::app::Animal *GetAnimal(const void *buf) {
|
||||||
|
return flatbuffers::GetRoot<com::fbs::app::Animal>(buf);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline const com::fbs::app::Animal *GetSizePrefixedAnimal(const void *buf) {
|
||||||
|
return flatbuffers::GetSizePrefixedRoot<com::fbs::app::Animal>(buf);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline bool VerifyAnimalBuffer(
|
||||||
|
flatbuffers::Verifier &verifier) {
|
||||||
|
return verifier.VerifyBuffer<com::fbs::app::Animal>(nullptr);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline bool VerifySizePrefixedAnimalBuffer(
|
||||||
|
flatbuffers::Verifier &verifier) {
|
||||||
|
return verifier.VerifySizePrefixedBuffer<com::fbs::app::Animal>(nullptr);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void FinishAnimalBuffer(
|
||||||
|
flatbuffers::FlatBufferBuilder &fbb,
|
||||||
|
flatbuffers::Offset<com::fbs::app::Animal> root) {
|
||||||
|
fbb.Finish(root);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void FinishSizePrefixedAnimalBuffer(
|
||||||
|
flatbuffers::FlatBufferBuilder &fbb,
|
||||||
|
flatbuffers::Offset<com::fbs::app::Animal> root) {
|
||||||
|
fbb.FinishSizePrefixed(root);
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace app
|
||||||
|
} // namespace fbs
|
||||||
|
} // namespace com
|
||||||
|
|
||||||
|
#endif // FLATBUFFERS_GENERATED_ANIMAL_COM_FBS_APP_H_
|
||||||
@@ -12,11 +12,12 @@
|
|||||||
// 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.
|
||||||
|
|
||||||
namespace sample;
|
namespace com.fbs.app;
|
||||||
|
|
||||||
table Animal {
|
table Animal {
|
||||||
name:string;
|
name:string;
|
||||||
sound:string;
|
sound:string;
|
||||||
|
weight: uint16;
|
||||||
}
|
}
|
||||||
|
|
||||||
root_type Animal;
|
root_type Animal;
|
||||||
@@ -0,0 +1,51 @@
|
|||||||
|
package com.flatbuffers.app
|
||||||
|
|
||||||
|
import android.annotation.SuppressLint
|
||||||
|
import androidx.appcompat.app.AppCompatActivity
|
||||||
|
import android.os.Bundle
|
||||||
|
import android.widget.TextView
|
||||||
|
import com.fbs.app.Animal
|
||||||
|
import com.google.flatbuffers.FlatBufferBuilder
|
||||||
|
import java.nio.ByteBuffer
|
||||||
|
|
||||||
|
@ExperimentalUnsignedTypes
|
||||||
|
class MainActivity : AppCompatActivity() {
|
||||||
|
|
||||||
|
@SuppressLint("SetTextI18n")
|
||||||
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
|
super.onCreate(savedInstanceState)
|
||||||
|
setContentView(R.layout.activity_main)
|
||||||
|
|
||||||
|
val tiger = Animal.getRootAsAnimal(ByteBuffer.wrap(createAnimalFromJNI()))
|
||||||
|
findViewById<TextView>(R.id.tv_animal_one).text = animalInfo(tiger)
|
||||||
|
|
||||||
|
findViewById<TextView>(R.id.tv_animal_two).text = animalInfo(createAnimalFromKotlin())
|
||||||
|
}
|
||||||
|
|
||||||
|
// This function is a sample of communicating FlatBuffers between JNI (native C++) and Java.
|
||||||
|
// Implementation can be found on animals.cpp file.
|
||||||
|
private external fun createAnimalFromJNI(): ByteArray
|
||||||
|
|
||||||
|
// Create a "Cow" Animal flatbuffers from Kotlin
|
||||||
|
private fun createAnimalFromKotlin():Animal {
|
||||||
|
val fb = FlatBufferBuilder(100)
|
||||||
|
val cowOffset = Animal.createAnimal(
|
||||||
|
builder = fb,
|
||||||
|
nameOffset = fb.createString("Cow"),
|
||||||
|
soundOffset = fb.createString("Moo"),
|
||||||
|
weight = 720u
|
||||||
|
)
|
||||||
|
fb.finish(cowOffset)
|
||||||
|
return Animal.getRootAsAnimal(fb.dataBuffer())
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun animalInfo(animal: Animal): String =
|
||||||
|
"The ${animal.name} sound is ${animal.sound} and it weights ${animal.weight}kg."
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
// Used to load the 'native-lib' library on application startup.
|
||||||
|
init {
|
||||||
|
System.loadLibrary("native-lib")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
63
android/app/src/main/java/generated/com/fbs/app/Animal.kt
Normal file
@@ -0,0 +1,63 @@
|
|||||||
|
// automatically generated by the FlatBuffers compiler, do not modify
|
||||||
|
|
||||||
|
package com.fbs.app
|
||||||
|
|
||||||
|
import java.nio.*
|
||||||
|
import kotlin.math.sign
|
||||||
|
import com.google.flatbuffers.*
|
||||||
|
|
||||||
|
@Suppress("unused")
|
||||||
|
class Animal : Table() {
|
||||||
|
|
||||||
|
fun __init(_i: Int, _bb: ByteBuffer) {
|
||||||
|
__reset(_i, _bb)
|
||||||
|
}
|
||||||
|
fun __assign(_i: Int, _bb: ByteBuffer) : Animal {
|
||||||
|
__init(_i, _bb)
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
val name : String?
|
||||||
|
get() {
|
||||||
|
val o = __offset(4)
|
||||||
|
return if (o != 0) __string(o + bb_pos) else null
|
||||||
|
}
|
||||||
|
val nameAsByteBuffer : ByteBuffer get() = __vector_as_bytebuffer(4, 1)
|
||||||
|
fun nameInByteBuffer(_bb: ByteBuffer) : ByteBuffer = __vector_in_bytebuffer(_bb, 4, 1)
|
||||||
|
val sound : String?
|
||||||
|
get() {
|
||||||
|
val o = __offset(6)
|
||||||
|
return if (o != 0) __string(o + bb_pos) else null
|
||||||
|
}
|
||||||
|
val soundAsByteBuffer : ByteBuffer get() = __vector_as_bytebuffer(6, 1)
|
||||||
|
fun soundInByteBuffer(_bb: ByteBuffer) : ByteBuffer = __vector_in_bytebuffer(_bb, 6, 1)
|
||||||
|
val weight : UShort
|
||||||
|
get() {
|
||||||
|
val o = __offset(8)
|
||||||
|
return if(o != 0) bb.getShort(o + bb_pos).toUShort() else 0u
|
||||||
|
}
|
||||||
|
companion object {
|
||||||
|
fun validateVersion() = Constants.FLATBUFFERS_2_0_0()
|
||||||
|
fun getRootAsAnimal(_bb: ByteBuffer): Animal = getRootAsAnimal(_bb, Animal())
|
||||||
|
fun getRootAsAnimal(_bb: ByteBuffer, obj: Animal): Animal {
|
||||||
|
_bb.order(ByteOrder.LITTLE_ENDIAN)
|
||||||
|
return (obj.__assign(_bb.getInt(_bb.position()) + _bb.position(), _bb))
|
||||||
|
}
|
||||||
|
fun createAnimal(builder: FlatBufferBuilder, nameOffset: Int, soundOffset: Int, weight: UShort) : Int {
|
||||||
|
builder.startTable(3)
|
||||||
|
addSound(builder, soundOffset)
|
||||||
|
addName(builder, nameOffset)
|
||||||
|
addWeight(builder, weight)
|
||||||
|
return endAnimal(builder)
|
||||||
|
}
|
||||||
|
fun startAnimal(builder: FlatBufferBuilder) = builder.startTable(3)
|
||||||
|
fun addName(builder: FlatBufferBuilder, name: Int) = builder.addOffset(0, name, 0)
|
||||||
|
fun addSound(builder: FlatBufferBuilder, sound: Int) = builder.addOffset(1, sound, 0)
|
||||||
|
fun addWeight(builder: FlatBufferBuilder, weight: UShort) = builder.addShort(2, weight.toShort(), 0)
|
||||||
|
fun endAnimal(builder: FlatBufferBuilder) : Int {
|
||||||
|
val o = builder.endTable()
|
||||||
|
return o
|
||||||
|
}
|
||||||
|
fun finishAnimalBuffer(builder: FlatBufferBuilder, offset: Int) = builder.finish(offset)
|
||||||
|
fun finishSizePrefixedAnimalBuffer(builder: FlatBufferBuilder, offset: Int) = builder.finishSizePrefixed(offset)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:aapt="http://schemas.android.com/aapt"
|
||||||
|
android:width="108dp"
|
||||||
|
android:height="108dp"
|
||||||
|
android:viewportWidth="108"
|
||||||
|
android:viewportHeight="108">
|
||||||
|
<path android:pathData="M31,63.928c0,0 6.4,-11 12.1,-13.1c7.2,-2.6 26,-1.4 26,-1.4l38.1,38.1L107,108.928l-32,-1L31,63.928z">
|
||||||
|
<aapt:attr name="android:fillColor">
|
||||||
|
<gradient
|
||||||
|
android:endX="85.84757"
|
||||||
|
android:endY="92.4963"
|
||||||
|
android:startX="42.9492"
|
||||||
|
android:startY="49.59793"
|
||||||
|
android:type="linear">
|
||||||
|
<item
|
||||||
|
android:color="#44000000"
|
||||||
|
android:offset="0.0" />
|
||||||
|
<item
|
||||||
|
android:color="#00000000"
|
||||||
|
android:offset="1.0" />
|
||||||
|
</gradient>
|
||||||
|
</aapt:attr>
|
||||||
|
</path>
|
||||||
|
<path
|
||||||
|
android:fillColor="#FFFFFF"
|
||||||
|
android:fillType="nonZero"
|
||||||
|
android:pathData="M65.3,45.828l3.8,-6.6c0.2,-0.4 0.1,-0.9 -0.3,-1.1c-0.4,-0.2 -0.9,-0.1 -1.1,0.3l-3.9,6.7c-6.3,-2.8 -13.4,-2.8 -19.7,0l-3.9,-6.7c-0.2,-0.4 -0.7,-0.5 -1.1,-0.3C38.8,38.328 38.7,38.828 38.9,39.228l3.8,6.6C36.2,49.428 31.7,56.028 31,63.928h46C76.3,56.028 71.8,49.428 65.3,45.828zM43.4,57.328c-0.8,0 -1.5,-0.5 -1.8,-1.2c-0.3,-0.7 -0.1,-1.5 0.4,-2.1c0.5,-0.5 1.4,-0.7 2.1,-0.4c0.7,0.3 1.2,1 1.2,1.8C45.3,56.528 44.5,57.328 43.4,57.328L43.4,57.328zM64.6,57.328c-0.8,0 -1.5,-0.5 -1.8,-1.2s-0.1,-1.5 0.4,-2.1c0.5,-0.5 1.4,-0.7 2.1,-0.4c0.7,0.3 1.2,1 1.2,1.8C66.5,56.528 65.6,57.328 64.6,57.328L64.6,57.328z"
|
||||||
|
android:strokeWidth="1"
|
||||||
|
android:strokeColor="#00000000" />
|
||||||
|
</vector>
|
||||||
170
android/app/src/main/res/drawable/ic_launcher_background.xml
Normal file
@@ -0,0 +1,170 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:width="108dp"
|
||||||
|
android:height="108dp"
|
||||||
|
android:viewportWidth="108"
|
||||||
|
android:viewportHeight="108">
|
||||||
|
<path
|
||||||
|
android:fillColor="#3DDC84"
|
||||||
|
android:pathData="M0,0h108v108h-108z" />
|
||||||
|
<path
|
||||||
|
android:fillColor="#00000000"
|
||||||
|
android:pathData="M9,0L9,108"
|
||||||
|
android:strokeWidth="0.8"
|
||||||
|
android:strokeColor="#33FFFFFF" />
|
||||||
|
<path
|
||||||
|
android:fillColor="#00000000"
|
||||||
|
android:pathData="M19,0L19,108"
|
||||||
|
android:strokeWidth="0.8"
|
||||||
|
android:strokeColor="#33FFFFFF" />
|
||||||
|
<path
|
||||||
|
android:fillColor="#00000000"
|
||||||
|
android:pathData="M29,0L29,108"
|
||||||
|
android:strokeWidth="0.8"
|
||||||
|
android:strokeColor="#33FFFFFF" />
|
||||||
|
<path
|
||||||
|
android:fillColor="#00000000"
|
||||||
|
android:pathData="M39,0L39,108"
|
||||||
|
android:strokeWidth="0.8"
|
||||||
|
android:strokeColor="#33FFFFFF" />
|
||||||
|
<path
|
||||||
|
android:fillColor="#00000000"
|
||||||
|
android:pathData="M49,0L49,108"
|
||||||
|
android:strokeWidth="0.8"
|
||||||
|
android:strokeColor="#33FFFFFF" />
|
||||||
|
<path
|
||||||
|
android:fillColor="#00000000"
|
||||||
|
android:pathData="M59,0L59,108"
|
||||||
|
android:strokeWidth="0.8"
|
||||||
|
android:strokeColor="#33FFFFFF" />
|
||||||
|
<path
|
||||||
|
android:fillColor="#00000000"
|
||||||
|
android:pathData="M69,0L69,108"
|
||||||
|
android:strokeWidth="0.8"
|
||||||
|
android:strokeColor="#33FFFFFF" />
|
||||||
|
<path
|
||||||
|
android:fillColor="#00000000"
|
||||||
|
android:pathData="M79,0L79,108"
|
||||||
|
android:strokeWidth="0.8"
|
||||||
|
android:strokeColor="#33FFFFFF" />
|
||||||
|
<path
|
||||||
|
android:fillColor="#00000000"
|
||||||
|
android:pathData="M89,0L89,108"
|
||||||
|
android:strokeWidth="0.8"
|
||||||
|
android:strokeColor="#33FFFFFF" />
|
||||||
|
<path
|
||||||
|
android:fillColor="#00000000"
|
||||||
|
android:pathData="M99,0L99,108"
|
||||||
|
android:strokeWidth="0.8"
|
||||||
|
android:strokeColor="#33FFFFFF" />
|
||||||
|
<path
|
||||||
|
android:fillColor="#00000000"
|
||||||
|
android:pathData="M0,9L108,9"
|
||||||
|
android:strokeWidth="0.8"
|
||||||
|
android:strokeColor="#33FFFFFF" />
|
||||||
|
<path
|
||||||
|
android:fillColor="#00000000"
|
||||||
|
android:pathData="M0,19L108,19"
|
||||||
|
android:strokeWidth="0.8"
|
||||||
|
android:strokeColor="#33FFFFFF" />
|
||||||
|
<path
|
||||||
|
android:fillColor="#00000000"
|
||||||
|
android:pathData="M0,29L108,29"
|
||||||
|
android:strokeWidth="0.8"
|
||||||
|
android:strokeColor="#33FFFFFF" />
|
||||||
|
<path
|
||||||
|
android:fillColor="#00000000"
|
||||||
|
android:pathData="M0,39L108,39"
|
||||||
|
android:strokeWidth="0.8"
|
||||||
|
android:strokeColor="#33FFFFFF" />
|
||||||
|
<path
|
||||||
|
android:fillColor="#00000000"
|
||||||
|
android:pathData="M0,49L108,49"
|
||||||
|
android:strokeWidth="0.8"
|
||||||
|
android:strokeColor="#33FFFFFF" />
|
||||||
|
<path
|
||||||
|
android:fillColor="#00000000"
|
||||||
|
android:pathData="M0,59L108,59"
|
||||||
|
android:strokeWidth="0.8"
|
||||||
|
android:strokeColor="#33FFFFFF" />
|
||||||
|
<path
|
||||||
|
android:fillColor="#00000000"
|
||||||
|
android:pathData="M0,69L108,69"
|
||||||
|
android:strokeWidth="0.8"
|
||||||
|
android:strokeColor="#33FFFFFF" />
|
||||||
|
<path
|
||||||
|
android:fillColor="#00000000"
|
||||||
|
android:pathData="M0,79L108,79"
|
||||||
|
android:strokeWidth="0.8"
|
||||||
|
android:strokeColor="#33FFFFFF" />
|
||||||
|
<path
|
||||||
|
android:fillColor="#00000000"
|
||||||
|
android:pathData="M0,89L108,89"
|
||||||
|
android:strokeWidth="0.8"
|
||||||
|
android:strokeColor="#33FFFFFF" />
|
||||||
|
<path
|
||||||
|
android:fillColor="#00000000"
|
||||||
|
android:pathData="M0,99L108,99"
|
||||||
|
android:strokeWidth="0.8"
|
||||||
|
android:strokeColor="#33FFFFFF" />
|
||||||
|
<path
|
||||||
|
android:fillColor="#00000000"
|
||||||
|
android:pathData="M19,29L89,29"
|
||||||
|
android:strokeWidth="0.8"
|
||||||
|
android:strokeColor="#33FFFFFF" />
|
||||||
|
<path
|
||||||
|
android:fillColor="#00000000"
|
||||||
|
android:pathData="M19,39L89,39"
|
||||||
|
android:strokeWidth="0.8"
|
||||||
|
android:strokeColor="#33FFFFFF" />
|
||||||
|
<path
|
||||||
|
android:fillColor="#00000000"
|
||||||
|
android:pathData="M19,49L89,49"
|
||||||
|
android:strokeWidth="0.8"
|
||||||
|
android:strokeColor="#33FFFFFF" />
|
||||||
|
<path
|
||||||
|
android:fillColor="#00000000"
|
||||||
|
android:pathData="M19,59L89,59"
|
||||||
|
android:strokeWidth="0.8"
|
||||||
|
android:strokeColor="#33FFFFFF" />
|
||||||
|
<path
|
||||||
|
android:fillColor="#00000000"
|
||||||
|
android:pathData="M19,69L89,69"
|
||||||
|
android:strokeWidth="0.8"
|
||||||
|
android:strokeColor="#33FFFFFF" />
|
||||||
|
<path
|
||||||
|
android:fillColor="#00000000"
|
||||||
|
android:pathData="M19,79L89,79"
|
||||||
|
android:strokeWidth="0.8"
|
||||||
|
android:strokeColor="#33FFFFFF" />
|
||||||
|
<path
|
||||||
|
android:fillColor="#00000000"
|
||||||
|
android:pathData="M29,19L29,89"
|
||||||
|
android:strokeWidth="0.8"
|
||||||
|
android:strokeColor="#33FFFFFF" />
|
||||||
|
<path
|
||||||
|
android:fillColor="#00000000"
|
||||||
|
android:pathData="M39,19L39,89"
|
||||||
|
android:strokeWidth="0.8"
|
||||||
|
android:strokeColor="#33FFFFFF" />
|
||||||
|
<path
|
||||||
|
android:fillColor="#00000000"
|
||||||
|
android:pathData="M49,19L49,89"
|
||||||
|
android:strokeWidth="0.8"
|
||||||
|
android:strokeColor="#33FFFFFF" />
|
||||||
|
<path
|
||||||
|
android:fillColor="#00000000"
|
||||||
|
android:pathData="M59,19L59,89"
|
||||||
|
android:strokeWidth="0.8"
|
||||||
|
android:strokeColor="#33FFFFFF" />
|
||||||
|
<path
|
||||||
|
android:fillColor="#00000000"
|
||||||
|
android:pathData="M69,19L69,89"
|
||||||
|
android:strokeWidth="0.8"
|
||||||
|
android:strokeColor="#33FFFFFF" />
|
||||||
|
<path
|
||||||
|
android:fillColor="#00000000"
|
||||||
|
android:pathData="M79,19L79,89"
|
||||||
|
android:strokeWidth="0.8"
|
||||||
|
android:strokeColor="#33FFFFFF" />
|
||||||
|
</vector>
|
||||||
23
android/app/src/main/res/layout/activity_main.xml
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:orientation="vertical"
|
||||||
|
android:gravity="center"
|
||||||
|
tools:context=".MainActivity">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/tv_animal_one"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
tools:text="Text Sample"/>
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/tv_animal_two"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
tools:text="Text Sample 2"/>
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
|
<background android:drawable="@drawable/ic_launcher_background" />
|
||||||
|
<foreground android:drawable="@drawable/ic_launcher_foreground" />
|
||||||
|
</adaptive-icon>
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
|
<background android:drawable="@drawable/ic_launcher_background" />
|
||||||
|
<foreground android:drawable="@drawable/ic_launcher_foreground" />
|
||||||
|
</adaptive-icon>
|
||||||
BIN
android/app/src/main/res/mipmap-hdpi/ic_launcher.png
Normal file
|
After Width: | Height: | Size: 3.5 KiB |
BIN
android/app/src/main/res/mipmap-hdpi/ic_launcher_round.png
Normal file
|
After Width: | Height: | Size: 5.2 KiB |
BIN
android/app/src/main/res/mipmap-mdpi/ic_launcher.png
Normal file
|
After Width: | Height: | Size: 2.6 KiB |
BIN
android/app/src/main/res/mipmap-mdpi/ic_launcher_round.png
Normal file
|
After Width: | Height: | Size: 3.3 KiB |
BIN
android/app/src/main/res/mipmap-xhdpi/ic_launcher.png
Normal file
|
After Width: | Height: | Size: 4.8 KiB |
BIN
android/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png
Normal file
|
After Width: | Height: | Size: 7.3 KiB |
BIN
android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
Normal file
|
After Width: | Height: | Size: 7.7 KiB |
BIN
android/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
Normal file
|
After Width: | Height: | Size: 12 KiB |
BIN
android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
Normal file
|
After Width: | Height: | Size: 10 KiB |
BIN
android/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
Normal file
|
After Width: | Height: | Size: 16 KiB |
6
android/app/src/main/res/values/colors.xml
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<resources>
|
||||||
|
<color name="colorPrimary">#6200EE</color>
|
||||||
|
<color name="colorPrimaryDark">#3700B3</color>
|
||||||
|
<color name="colorAccent">#03DAC5</color>
|
||||||
|
</resources>
|
||||||
3
android/app/src/main/res/values/strings.xml
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
<resources>
|
||||||
|
<string name="app_name">FlatbuffersTestApp</string>
|
||||||
|
</resources>
|
||||||
10
android/app/src/main/res/values/styles.xml
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
<resources>
|
||||||
|
<!-- Base application theme. -->
|
||||||
|
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
|
||||||
|
<!-- Customize your theme here. -->
|
||||||
|
<item name="colorPrimary">@color/colorPrimary</item>
|
||||||
|
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
|
||||||
|
<item name="colorAccent">@color/colorAccent</item>
|
||||||
|
</style>
|
||||||
|
|
||||||
|
</resources>
|
||||||
@@ -1,108 +1,35 @@
|
|||||||
// Copyright (c) 2017 Google, Inc.
|
// Top-level build file where you can add configuration options common to all sub-projects/modules.
|
||||||
//
|
|
||||||
// This software is provided 'as-is', without any express or implied
|
|
||||||
// warranty. In no event will the authors be held liable for any damages
|
|
||||||
// arising from the use of this software.
|
|
||||||
// Permission is granted to anyone to use this software for any purpose,
|
|
||||||
// including commercial applications, and to alter it and redistribute it
|
|
||||||
// freely, subject to the following restrictions:
|
|
||||||
// 1. The origin of this software must not be misrepresented; you must not
|
|
||||||
// claim that you wrote the original software. If you use this software
|
|
||||||
// in a product, an acknowledgment in the product documentation would be
|
|
||||||
// appreciated but is not required.
|
|
||||||
// 2. Altered source versions must be plainly marked as such, and must not be
|
|
||||||
// misrepresented as being the original software.
|
|
||||||
// 3. This notice may not be removed or altered from any source distribution.
|
|
||||||
|
|
||||||
buildscript {
|
buildscript {
|
||||||
|
ext.kotlin_version = "1.4.10"
|
||||||
repositories {
|
repositories {
|
||||||
|
google()
|
||||||
jcenter()
|
jcenter()
|
||||||
}
|
}
|
||||||
dependencies {
|
dependencies {
|
||||||
classpath 'com.android.tools.build:gradle:2.3.0'
|
classpath 'com.android.tools.build:gradle:4.1.0'
|
||||||
|
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
|
||||||
|
|
||||||
|
// NOTE: Do not place your application dependencies here; they belong
|
||||||
|
// in the individual module build.gradle files
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
allprojects {
|
allprojects {
|
||||||
repositories {
|
repositories {
|
||||||
|
google()
|
||||||
jcenter()
|
jcenter()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
apply plugin: 'com.android.application'
|
tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).all {
|
||||||
|
sourceCompatibility = JavaVersion.VERSION_1_8
|
||||||
|
targetCompatibility = JavaVersion.VERSION_1_8
|
||||||
|
|
||||||
android {
|
compileKotlin {
|
||||||
compileSdkVersion 25
|
dependsOn flatbuffer
|
||||||
buildToolsVersion '25.0.2'
|
|
||||||
|
|
||||||
sourceSets {
|
|
||||||
main {
|
|
||||||
manifest.srcFile 'AndroidManifest.xml'
|
|
||||||
res.srcDirs = ['res']
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
externalNativeBuild {
|
|
||||||
ndkBuild {
|
|
||||||
path "jni/Android.mk"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
defaultConfig {
|
|
||||||
applicationId 'com.example.FlatBufferTest'
|
|
||||||
// This is the platform API where NativeActivity was introduced.
|
|
||||||
minSdkVersion 9
|
|
||||||
targetSdkVersion 25
|
|
||||||
versionCode 1
|
|
||||||
versionName "1.0"
|
|
||||||
|
|
||||||
buildTypes {
|
|
||||||
release {
|
|
||||||
minifyEnabled false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
externalNativeBuild {
|
|
||||||
ndkBuild {
|
|
||||||
targets "FlatBufferTest"
|
|
||||||
arguments "-j" + Runtime.getRuntime().availableProcessors()
|
|
||||||
abiFilters "armeabi-v7a", "arm64-v8a", "x86", "x86_64"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
lintOptions {
|
|
||||||
abortOnError false
|
|
||||||
}
|
|
||||||
|
|
||||||
// Build with each STL variant.
|
|
||||||
productFlavors {
|
|
||||||
stlport {
|
|
||||||
applicationIdSuffix ".stlport"
|
|
||||||
versionNameSuffix "-stlport"
|
|
||||||
externalNativeBuild {
|
|
||||||
ndkBuild {
|
|
||||||
arguments "APP_STL=stlport_static"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
gnustl {
|
|
||||||
applicationIdSuffix ".gnustl"
|
|
||||||
versionNameSuffix "-gnustl"
|
|
||||||
externalNativeBuild {
|
|
||||||
ndkBuild {
|
|
||||||
arguments "APP_STL=gnustl_static"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
libcpp {
|
|
||||||
applicationIdSuffix ".libcpp"
|
|
||||||
versionNameSuffix "-libcpp"
|
|
||||||
externalNativeBuild {
|
|
||||||
ndkBuild {
|
|
||||||
arguments "APP_STL=c++_static"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
task clean(type: Delete) {
|
||||||
|
delete rootProject.buildDir
|
||||||
|
}
|
||||||
|
|||||||
23
android/gradle.properties
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
# Project-wide Gradle settings.
|
||||||
|
# IDE (e.g. Android Studio) users:
|
||||||
|
# Gradle settings configured through the IDE *will override*
|
||||||
|
# any settings specified in this file.
|
||||||
|
# For more details on how to configure your build environment visit
|
||||||
|
# http://www.gradle.org/docs/current/userguide/build_environment.html
|
||||||
|
# Specifies the JVM arguments used for the daemon process.
|
||||||
|
# The setting is particularly useful for tweaking memory settings.
|
||||||
|
org.gradle.jvmargs=-Xmx2048m
|
||||||
|
# When configured, Gradle will run in incubating parallel mode.
|
||||||
|
# This option should only be used with decoupled projects. More details, visit
|
||||||
|
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
|
||||||
|
# org.gradle.parallel=true
|
||||||
|
# AndroidX package structure to make it clearer which packages are bundled with the
|
||||||
|
# Android operating system, and which are packaged with your app"s APK
|
||||||
|
# https://developer.android.com/topic/libraries/support-library/androidx-rn
|
||||||
|
android.useAndroidX=true
|
||||||
|
# Automatically convert third-party libraries to use AndroidX
|
||||||
|
android.enableJetifier=true
|
||||||
|
# Kotlin code style for this project: "official" or "obsolete":
|
||||||
|
kotlin.code.style=official
|
||||||
|
# Use parallel builds
|
||||||
|
org.gradle.parallel=true
|
||||||
BIN
android/gradle/wrapper/gradle-wrapper.jar
vendored
@@ -1,6 +1,5 @@
|
|||||||
#Mon Jun 19 11:54:59 PDT 2017
|
|
||||||
distributionBase=GRADLE_USER_HOME
|
distributionBase=GRADLE_USER_HOME
|
||||||
distributionPath=wrapper/dists
|
distributionPath=wrapper/dists
|
||||||
|
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4.2-bin.zip
|
||||||
zipStoreBase=GRADLE_USER_HOME
|
zipStoreBase=GRADLE_USER_HOME
|
||||||
zipStorePath=wrapper/dists
|
zipStorePath=wrapper/dists
|
||||||
distributionUrl=https\://services.gradle.org/distributions/gradle-4.0-all.zip
|
|
||||||
|
|||||||
@@ -1,64 +0,0 @@
|
|||||||
# Copyright (c) 2013 Google, Inc.
|
|
||||||
#
|
|
||||||
# This software is provided 'as-is', without any express or implied
|
|
||||||
# warranty. In no event will the authors be held liable for any damages
|
|
||||||
# arising from the use of this software.
|
|
||||||
# Permission is granted to anyone to use this software for any purpose,
|
|
||||||
# including commercial applications, and to alter it and redistribute it
|
|
||||||
# freely, subject to the following restrictions:
|
|
||||||
# 1. The origin of this software must not be misrepresented; you must not
|
|
||||||
# claim that you wrote the original software. If you use this software
|
|
||||||
# in a product, an acknowledgment in the product documentation would be
|
|
||||||
# appreciated but is not required.
|
|
||||||
# 2. Altered source versions must be plainly marked as such, and must not be
|
|
||||||
# misrepresented as being the original software.
|
|
||||||
# 3. This notice may not be removed or altered from any source distribution.
|
|
||||||
|
|
||||||
LOCAL_PATH := $(call my-dir)/../..
|
|
||||||
|
|
||||||
include $(LOCAL_PATH)/android/jni/include.mk
|
|
||||||
LOCAL_PATH := $(call realpath-portable,$(LOCAL_PATH))
|
|
||||||
|
|
||||||
# Empty static library so that other projects can include just the basic
|
|
||||||
# FlatBuffers headers as a module.
|
|
||||||
include $(CLEAR_VARS)
|
|
||||||
LOCAL_MODULE := flatbuffers
|
|
||||||
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/include
|
|
||||||
LOCAL_EXPORT_CPPFLAGS := -std=c++11 -fexceptions -Wall \
|
|
||||||
-DFLATBUFFERS_TRACK_VERIFIER_BUFFER_SIZE
|
|
||||||
|
|
||||||
include $(BUILD_STATIC_LIBRARY)
|
|
||||||
|
|
||||||
# static library that additionally includes text parsing/generation/reflection
|
|
||||||
# for projects that want richer functionality.
|
|
||||||
include $(CLEAR_VARS)
|
|
||||||
LOCAL_MODULE := flatbuffers_extra
|
|
||||||
LOCAL_SRC_FILES := src/idl_parser.cpp \
|
|
||||||
src/idl_gen_text.cpp \
|
|
||||||
src/reflection.cpp \
|
|
||||||
src/util.cpp
|
|
||||||
LOCAL_STATIC_LIBRARIES := flatbuffers
|
|
||||||
LOCAL_ARM_MODE := arm
|
|
||||||
include $(BUILD_STATIC_LIBRARY)
|
|
||||||
|
|
||||||
# FlatBuffers test
|
|
||||||
include $(CLEAR_VARS)
|
|
||||||
LOCAL_MODULE := FlatBufferTest
|
|
||||||
LOCAL_SRC_FILES := android/jni/main.cpp \
|
|
||||||
tests/test.cpp \
|
|
||||||
tests/test_assert.h \
|
|
||||||
tests/test_builder.h \
|
|
||||||
tests/test_assert.cpp \
|
|
||||||
tests/test_builder.cpp \
|
|
||||||
tests/native_type_test_impl.h \
|
|
||||||
tests/native_type_test_impl.cpp \
|
|
||||||
src/idl_gen_fbs.cpp \
|
|
||||||
src/code_generators.cpp
|
|
||||||
LOCAL_LDLIBS := -llog -landroid -latomic
|
|
||||||
LOCAL_STATIC_LIBRARIES := android_native_app_glue flatbuffers_extra
|
|
||||||
LOCAL_ARM_MODE := arm
|
|
||||||
include $(BUILD_SHARED_LIBRARY)
|
|
||||||
|
|
||||||
$(call import-module,android/native_app_glue)
|
|
||||||
|
|
||||||
$(call import-add-path,$(LOCAL_PATH)/../..)
|
|
||||||
@@ -1,20 +0,0 @@
|
|||||||
# Copyright (c) 2014 Google, Inc.
|
|
||||||
#
|
|
||||||
# This software is provided 'as-is', without any express or implied
|
|
||||||
# warranty. In no event will the authors be held liable for any damages
|
|
||||||
# arising from the use of this software.
|
|
||||||
# Permission is granted to anyone to use this software for any purpose,
|
|
||||||
# including commercial applications, and to alter it and redistribute it
|
|
||||||
# freely, subject to the following restrictions:
|
|
||||||
# 1. The origin of this software must not be misrepresented; you must not
|
|
||||||
# claim that you wrote the original software. If you use this software
|
|
||||||
# in a product, an acknowledgment in the product documentation would be
|
|
||||||
# appreciated but is not required.
|
|
||||||
# 2. Altered source versions must be plainly marked as such, and must not be
|
|
||||||
# misrepresented as being the original software.
|
|
||||||
# 3. This notice may not be removed or altered from any source distribution.
|
|
||||||
APP_PLATFORM := android-9
|
|
||||||
APP_PROJECT_PATH := $(call my-dir)/..
|
|
||||||
APP_STL ?= stlport_static
|
|
||||||
APP_ABI := armeabi-v7a
|
|
||||||
APP_CPPFLAGS += -std=c++11
|
|
||||||
@@ -1,68 +0,0 @@
|
|||||||
@rem Copyright (c) 2013 Google, Inc.
|
|
||||||
@rem
|
|
||||||
@rem This software is provided 'as-is', without any express or implied
|
|
||||||
@rem warranty. In no event will the authors be held liable for any damages
|
|
||||||
@rem arising from the use of this software.
|
|
||||||
@rem Permission is granted to anyone to use this software for any purpose,
|
|
||||||
@rem including commercial applications, and to alter it and redistribute it
|
|
||||||
@rem freely, subject to the following restrictions:
|
|
||||||
@rem 1. The origin of this software must not be misrepresented; you must not
|
|
||||||
@rem claim that you wrote the original software. If you use this software
|
|
||||||
@rem in a product, an acknowledgment in the product documentation would be
|
|
||||||
@rem appreciated but is not required.
|
|
||||||
@rem 2. Altered source versions must be plainly marked as such, and must not be
|
|
||||||
@rem misrepresented as being the original software.
|
|
||||||
@rem 3. This notice may not be removed or altered from any source distribution.
|
|
||||||
@echo off
|
|
||||||
|
|
||||||
setlocal enabledelayedexpansion
|
|
||||||
|
|
||||||
set thispath=%~dp0
|
|
||||||
|
|
||||||
rem Path to cmake passed in by caller.
|
|
||||||
set cmake=%1
|
|
||||||
rem Path to cmake project to build.
|
|
||||||
set cmake_project_path=%2
|
|
||||||
|
|
||||||
rem Newest and oldest version of Visual Studio that it's possible to select.
|
|
||||||
set visual_studio_version_max=20
|
|
||||||
set visual_studio_version_min=8
|
|
||||||
|
|
||||||
rem Determine the newest version of Visual Studio installed on this machine.
|
|
||||||
set visual_studio_version=
|
|
||||||
for /L %%a in (%visual_studio_version_max%,-1,%visual_studio_version_min%) do (
|
|
||||||
echo Searching for Visual Studio %%a >&2
|
|
||||||
reg query HKLM\SOFTWARE\Microsoft\VisualStudio\%%a.0 /ve 1>NUL 2>NUL
|
|
||||||
if !ERRORLEVEL! EQU 0 (
|
|
||||||
set visual_studio_version=%%a
|
|
||||||
goto found_vs
|
|
||||||
)
|
|
||||||
)
|
|
||||||
echo Unable to determine whether Visual Studio is installed. >&2
|
|
||||||
exit /B 1
|
|
||||||
:found_vs
|
|
||||||
|
|
||||||
rem Map Visual Studio version to cmake generator name.
|
|
||||||
if "%visual_studio_version%"=="8" (
|
|
||||||
set cmake_generator=Visual Studio 8 2005
|
|
||||||
)
|
|
||||||
if "%visual_studio_version%"=="9" (
|
|
||||||
set cmake_generator=Visual Studio 9 2008
|
|
||||||
)
|
|
||||||
if %visual_studio_version% GEQ 10 (
|
|
||||||
set cmake_generator=Visual Studio %visual_studio_version%
|
|
||||||
)
|
|
||||||
rem Set visual studio version variable for msbuild.
|
|
||||||
set VisualStudioVersion=%visual_studio_version%.0
|
|
||||||
|
|
||||||
rem Generate Visual Studio solution.
|
|
||||||
echo Generating solution for %cmake_generator%. >&2
|
|
||||||
cd "%cmake_project_path%"
|
|
||||||
%cmake% -G"%cmake_generator%"
|
|
||||||
if %ERRORLEVEL% NEQ 0 (
|
|
||||||
exit /B %ERRORLEVEL%
|
|
||||||
)
|
|
||||||
|
|
||||||
rem Build flatc
|
|
||||||
python %thispath%\msbuild.py flatc.vcxproj
|
|
||||||
if ERRORLEVEL 1 exit /B 1
|
|
||||||
@@ -1,237 +0,0 @@
|
|||||||
# 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.
|
|
||||||
|
|
||||||
# This file contains utility functions for Android projects using Flatbuffers.
|
|
||||||
# To use this file, include it in your project's Android.mk by calling near the
|
|
||||||
# top of your android makefile like so:
|
|
||||||
#
|
|
||||||
# include $(FLATBUFFERS_DIR)/android/jni/include.mk
|
|
||||||
#
|
|
||||||
# You will also need to import the flatbuffers module using the standard
|
|
||||||
# import-module function.
|
|
||||||
#
|
|
||||||
# The main functionality this file provides are the following functions:
|
|
||||||
# flatbuffers_fbs_to_h: Converts flatbuffer schema paths to header paths.
|
|
||||||
# flatbuffers_header_build_rule:
|
|
||||||
# Creates a build rule for a schema's generated header. This build rule
|
|
||||||
# has a dependency on the flatc compiler which will be built if necessary.
|
|
||||||
# flatbuffers_header_build_rules:
|
|
||||||
# Creates build rules for generated headers for each schema listed and sets
|
|
||||||
# up depenedendies.
|
|
||||||
#
|
|
||||||
# More information and example usage can be found in the comments preceeding
|
|
||||||
# each function.
|
|
||||||
|
|
||||||
# Targets to build the Flatbuffers compiler as well as some utility definitions
|
|
||||||
ifeq (,$(FLATBUFFERS_INCLUDE_MK_))
|
|
||||||
FLATBUFFERS_INCLUDE_MK_ := 1
|
|
||||||
|
|
||||||
# Portable version of $(realpath) that omits drive letters on Windows.
|
|
||||||
realpath-portable = $(join $(filter %:,$(subst :,: ,$1)),\
|
|
||||||
$(realpath $(filter-out %:,$(subst :,: ,$1))))
|
|
||||||
|
|
||||||
PROJECT_OS := $(OS)
|
|
||||||
ifeq (,$(OS))
|
|
||||||
PROJECT_OS := $(shell uname -s)
|
|
||||||
else
|
|
||||||
ifneq ($(findstring Windows,$(PROJECT_OS)),)
|
|
||||||
PROJECT_OS := Windows
|
|
||||||
endif
|
|
||||||
endif
|
|
||||||
|
|
||||||
# The following block generates build rules which result in headers being
|
|
||||||
# rebuilt from flatbuffers schemas.
|
|
||||||
|
|
||||||
FLATBUFFERS_CMAKELISTS_DIR := \
|
|
||||||
$(call realpath-portable,$(dir $(lastword $(MAKEFILE_LIST)))/../..)
|
|
||||||
|
|
||||||
# Directory that contains the FlatBuffers compiler.
|
|
||||||
ifeq (Windows,$(PROJECT_OS))
|
|
||||||
FLATBUFFERS_FLATC_PATH?=$(FLATBUFFERS_CMAKELISTS_DIR)
|
|
||||||
FLATBUFFERS_FLATC := $(lastword \
|
|
||||||
$(wildcard $(FLATBUFFERS_FLATC_PATH)/*/flatc.exe) \
|
|
||||||
$(wildcard $(FLATBUFFERS_FLATC_PATH)/flatc.exe))
|
|
||||||
endif
|
|
||||||
ifeq (Linux,$(PROJECT_OS))
|
|
||||||
FLATBUFFERS_FLATC_PATH?=$(FLATBUFFERS_CMAKELISTS_DIR)
|
|
||||||
FLATBUFFERS_FLATC := $(FLATBUFFERS_FLATC_PATH)/flatc
|
|
||||||
endif
|
|
||||||
ifeq (Darwin,$(PROJECT_OS))
|
|
||||||
FLATBUFFERS_FLATC_PATH?=$(FLATBUFFERS_CMAKELISTS_DIR)
|
|
||||||
FLATBUFFERS_FLATC := $(lastword \
|
|
||||||
$(wildcard $(FLATBUFFERS_FLATC_PATH)/*/flatc) \
|
|
||||||
$(wildcard $(FLATBUFFERS_FLATC_PATH)/flatc))
|
|
||||||
endif
|
|
||||||
|
|
||||||
FLATBUFFERS_FLATC_ARGS?=
|
|
||||||
|
|
||||||
# Search for cmake.
|
|
||||||
CMAKE_ROOT := \
|
|
||||||
$(call realpath-portable,$(LOCAL_PATH)/../../../../../../prebuilts/cmake)
|
|
||||||
ifeq (,$(CMAKE))
|
|
||||||
ifeq (Linux,$(PROJECT_OS))
|
|
||||||
CMAKE := $(wildcard $(CMAKE_ROOT)/linux-x86/current/bin/cmake*)
|
|
||||||
endif
|
|
||||||
ifeq (Darwin,$(PROJECT_OS))
|
|
||||||
CMAKE := \
|
|
||||||
$(wildcard $(CMAKE_ROOT)/darwin-x86_64/current/*.app/Contents/bin/cmake)
|
|
||||||
endif
|
|
||||||
ifeq (Windows,$(PROJECT_OS))
|
|
||||||
CMAKE := $(wildcard $(CMAKE_ROOT)/windows/current/bin/cmake*)
|
|
||||||
endif
|
|
||||||
endif
|
|
||||||
ifeq (,$(CMAKE))
|
|
||||||
CMAKE := cmake
|
|
||||||
endif
|
|
||||||
|
|
||||||
# Windows friendly portable local path.
|
|
||||||
# GNU-make doesn't like : in paths, must use relative paths on Windows.
|
|
||||||
ifeq (Windows,$(PROJECT_OS))
|
|
||||||
PORTABLE_LOCAL_PATH =
|
|
||||||
else
|
|
||||||
PORTABLE_LOCAL_PATH = $(LOCAL_PATH)/
|
|
||||||
endif
|
|
||||||
|
|
||||||
# Generate a host build rule for the flatbuffers compiler.
|
|
||||||
ifeq (Windows,$(PROJECT_OS))
|
|
||||||
define build_flatc_recipe
|
|
||||||
$(FLATBUFFERS_CMAKELISTS_DIR)\android\jni\build_flatc.bat \
|
|
||||||
$(CMAKE) $(FLATBUFFERS_CMAKELISTS_DIR)
|
|
||||||
endef
|
|
||||||
endif
|
|
||||||
ifeq (Linux,$(PROJECT_OS))
|
|
||||||
define build_flatc_recipe
|
|
||||||
+cd $(FLATBUFFERS_CMAKELISTS_DIR) && \
|
|
||||||
$(CMAKE) . && \
|
|
||||||
$(MAKE) flatc
|
|
||||||
endef
|
|
||||||
endif
|
|
||||||
ifeq (Darwin,$(PROJECT_OS))
|
|
||||||
define build_flatc_recipe
|
|
||||||
cd $(FLATBUFFERS_CMAKELISTS_DIR) && "$(CMAKE)" -GXcode . && \
|
|
||||||
xcodebuild -target flatc
|
|
||||||
endef
|
|
||||||
endif
|
|
||||||
ifeq (,$(build_flatc_recipe))
|
|
||||||
ifeq (,$(FLATBUFFERS_FLATC))
|
|
||||||
$(error flatc binary not found!)
|
|
||||||
endif
|
|
||||||
endif
|
|
||||||
|
|
||||||
# Generate a build rule for flatc.
|
|
||||||
ifeq ($(strip $(FLATBUFFERS_FLATC)),)
|
|
||||||
flatc_target := build_flatc
|
|
||||||
.PHONY: $(flatc_target)
|
|
||||||
FLATBUFFERS_FLATC := \
|
|
||||||
python $(FLATBUFFERS_CMAKELISTS_DIR)/android/jni/run_flatc.py \
|
|
||||||
$(FLATBUFFERS_CMAKELISTS_DIR)
|
|
||||||
else
|
|
||||||
flatc_target := $(FLATBUFFERS_FLATC)
|
|
||||||
endif
|
|
||||||
$(flatc_target):
|
|
||||||
$(call build_flatc_recipe)
|
|
||||||
|
|
||||||
# $(flatbuffers_fbs_to_h schema_dir,output_dir,path)
|
|
||||||
#
|
|
||||||
# Convert the specified schema path to a Flatbuffers generated header path.
|
|
||||||
# For example:
|
|
||||||
#
|
|
||||||
# $(call flatbuffers_fbs_to_h,$(MY_PROJ_DIR)/schemas,\
|
|
||||||
# $(MY_PROJ_DIR)/gen/include,$(MY_PROJ_DIR)/schemas/example.fbs)
|
|
||||||
#
|
|
||||||
# This will convert the file path `$(MY_PROJ_DIR)/schemas/example.fbs)` to
|
|
||||||
# `$(MY_PROJ_DIR)/gen/include/example_generated.h`
|
|
||||||
define flatbuffers_fbs_to_h
|
|
||||||
$(subst $(1),$(2),$(patsubst %.fbs,%_generated.h,$(3)))
|
|
||||||
endef
|
|
||||||
|
|
||||||
# $(flatbuffers_header_build_rule schema_file,schema_dir,output_dir,\
|
|
||||||
# schema_include_dirs)
|
|
||||||
#
|
|
||||||
# Generate a build rule that will convert a Flatbuffers schema to a generated
|
|
||||||
# header derived from the schema filename using flatbuffers_fbs_to_h. For
|
|
||||||
# example:
|
|
||||||
#
|
|
||||||
# $(call flatbuffers_header_build_rule,$(MY_PROJ_DIR)/schemas/example.fbs,\
|
|
||||||
# $(MY_PROJ_DIR)/schemas,$(MY_PROJ_DIR)/gen/include)
|
|
||||||
#
|
|
||||||
# The final argument, schema_include_dirs, is optional and is only needed when
|
|
||||||
# the schema files depend on other schema files outside their own directory.
|
|
||||||
define flatbuffers_header_build_rule
|
|
||||||
$(eval \
|
|
||||||
$(call flatbuffers_fbs_to_h,$(2),$(3),$(1)): $(1) $(flatc_target)
|
|
||||||
$(call host-echo-build-step,generic,Generate) \
|
|
||||||
$(subst $(LOCAL_PATH)/,,$(call flatbuffers_fbs_to_h,$(2),$(3),$(1)))
|
|
||||||
$(hide) $$(FLATBUFFERS_FLATC) $(FLATBUFFERS_FLATC_ARGS) \
|
|
||||||
$(foreach include,$(4),-I $(include)) -o $$(dir $$@) -c $$<)
|
|
||||||
endef
|
|
||||||
|
|
||||||
# TODO: Remove when the LOCAL_PATH expansion bug in the NDK is fixed.
|
|
||||||
# Override the default behavior of local-source-file-path to workaround
|
|
||||||
# a bug which prevents the build of deeply nested projects when NDK_OUT is
|
|
||||||
# set.
|
|
||||||
local-source-file-path=\
|
|
||||||
$(if $(call host-path-is-absolute,$1),$1,$(call \
|
|
||||||
realpath-portable,$(LOCAL_PATH)/$1))
|
|
||||||
|
|
||||||
|
|
||||||
# $(flatbuffers_header_build_rules schema_files,schema_dir,output_dir,\
|
|
||||||
# schema_include_dirs,src_files,[build_target],[dependencies]))
|
|
||||||
#
|
|
||||||
# $(1) schema_files: Space separated list of flatbuffer schema files.
|
|
||||||
# $(2) schema_dir: Directory containing the flatbuffer schemas.
|
|
||||||
# $(3) output_dir: Where to place the generated files.
|
|
||||||
# $(4) schema_include_dirs: Directories to include when generating schemas.
|
|
||||||
# $(5) src_files: Files that should depend upon the headers generated from the
|
|
||||||
# flatbuffer schemas.
|
|
||||||
# $(6) build_target: Name of a build target that depends upon all generated
|
|
||||||
# headers.
|
|
||||||
# $(7) dependencies: Space seperated list of additional build targets src_files
|
|
||||||
# should depend upon.
|
|
||||||
#
|
|
||||||
# Use this in your own Android.mk file to generate build rules that will
|
|
||||||
# generate header files for your flatbuffer schemas as well as automatically
|
|
||||||
# set your source files to be dependent on the generated headers. For example:
|
|
||||||
#
|
|
||||||
# $(call flatbuffers_header_build_rules,$(MY_PROJ_SCHEMA_FILES),\
|
|
||||||
# $(MY_PROJ_SCHEMA_DIR),$(MY_PROJ_GENERATED_OUTPUT_DIR),
|
|
||||||
# $(MY_PROJ_SCHEMA_INCLUDE_DIRS),$(LOCAL_SRC_FILES))
|
|
||||||
#
|
|
||||||
# NOTE: Due problesm with path processing in ndk-build when presented with
|
|
||||||
# deeply nested projects must redefine LOCAL_PATH after include this makefile
|
|
||||||
# using:
|
|
||||||
#
|
|
||||||
# LOCAL_PATH := $(call realpath-portable,$(LOCAL_PATH))
|
|
||||||
#
|
|
||||||
define flatbuffers_header_build_rules
|
|
||||||
$(foreach schema,$(1),\
|
|
||||||
$(call flatbuffers_header_build_rule,\
|
|
||||||
$(schema),$(strip $(2)),$(strip $(3)),$(strip $(4))))\
|
|
||||||
$(foreach src,$(strip $(5)),\
|
|
||||||
$(eval $(call local-source-file-path,$(src)): \
|
|
||||||
$(foreach schema,$(strip $(1)),\
|
|
||||||
$(call flatbuffers_fbs_to_h,$(strip $(2)),$(strip $(3)),$(schema)))))\
|
|
||||||
$(if $(6),\
|
|
||||||
$(foreach schema,$(strip $(1)),\
|
|
||||||
$(eval $(6): \
|
|
||||||
$(call flatbuffers_fbs_to_h,$(strip $(2)),$(strip $(3)),$(schema)))),)\
|
|
||||||
$(if $(7),\
|
|
||||||
$(foreach src,$(strip $(5)),\
|
|
||||||
$(eval $(call local-source-file-path,$(src)): $(strip $(7)))),)\
|
|
||||||
$(if $(7),\
|
|
||||||
$(foreach dependency,$(strip $(7)),\
|
|
||||||
$(eval $(6): $(dependency))),)
|
|
||||||
endef
|
|
||||||
|
|
||||||
endif # FLATBUFFERS_INCLUDE_MK_
|
|
||||||
@@ -1,77 +0,0 @@
|
|||||||
#!/usr/bin/python
|
|
||||||
# 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.
|
|
||||||
|
|
||||||
"""Simple script that locates the newest MSBuild in one of several locations.
|
|
||||||
|
|
||||||
This script will find the highest version number of MSBuild and run it,
|
|
||||||
passing its arguments through to MSBuild.
|
|
||||||
"""
|
|
||||||
|
|
||||||
import glob
|
|
||||||
import os
|
|
||||||
import re
|
|
||||||
import string
|
|
||||||
import subprocess
|
|
||||||
import sys
|
|
||||||
|
|
||||||
SYSTEMROOT = os.getenv("SYSTEMROOT", "c:\\windows")
|
|
||||||
PROGRAM_FILES = os.getenv("ProgramFiles", "c:\\Program Files")
|
|
||||||
PROGRAM_FILES_X86 = os.getenv("ProgramFiles(x86)", "c:\\Program Files (x86)")
|
|
||||||
|
|
||||||
SEARCH_FOLDERS = [ PROGRAM_FILES + "\\MSBuild\\*\\Bin\\MSBuild.exe",
|
|
||||||
PROGRAM_FILES_X86 + "\\MSBuild\\*\\Bin\\MSBuild.exe",
|
|
||||||
SYSTEMROOT + "\\Microsoft.NET\Framework\\*\\MSBuild.exe" ]
|
|
||||||
|
|
||||||
def compare_version(a, b):
|
|
||||||
"""Compare two version number strings of the form W.X.Y.Z.
|
|
||||||
|
|
||||||
The numbers are compared most-significant to least-significant.
|
|
||||||
For example, 12.345.67.89 > 2.987.88.99.
|
|
||||||
|
|
||||||
Args:
|
|
||||||
a: First version number string to compare
|
|
||||||
b: Second version number string to compare
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
0 if the numbers are identical, a positive number if 'a' is larger, and
|
|
||||||
a negative number if 'b' is larger.
|
|
||||||
"""
|
|
||||||
aa = string.split(a, ".")
|
|
||||||
bb = string.split(b, ".")
|
|
||||||
for i in range(0, 4):
|
|
||||||
if aa[i] != bb[i]:
|
|
||||||
return cmp(int(aa[i]), int(bb[i]))
|
|
||||||
return 0
|
|
||||||
|
|
||||||
def main():
|
|
||||||
msbuilds = []
|
|
||||||
|
|
||||||
for folder in SEARCH_FOLDERS:
|
|
||||||
for file in glob.glob(folder):
|
|
||||||
p = subprocess.Popen([file, "/version"], stdout=subprocess.PIPE)
|
|
||||||
out, err = p.communicate()
|
|
||||||
match = re.search("^[0-9]+\\.[0-9]+\\.[0-9]+\\.[0-9]+$", out, re.M)
|
|
||||||
if match:
|
|
||||||
msbuilds.append({ 'ver':match.group(), 'exe':file })
|
|
||||||
msbuilds.sort(lambda x, y: compare_version(x['ver'], y['ver']), reverse=True)
|
|
||||||
if len(msbuilds) == 0:
|
|
||||||
print "Unable to find MSBuild.\n"
|
|
||||||
return -1;
|
|
||||||
cmd = [msbuilds[0]['exe']]
|
|
||||||
cmd.extend(sys.argv[1:])
|
|
||||||
return subprocess.call(cmd)
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
|
||||||
sys.exit(main())
|
|
||||||
@@ -1,46 +0,0 @@
|
|||||||
#!/usr/bin/python
|
|
||||||
# Copyright 2015 Google Inc. All rights reserved.
|
|
||||||
#
|
|
||||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
# you may not use this file except in compliance with the License.
|
|
||||||
# You may obtain a copy of the License at
|
|
||||||
#
|
|
||||||
# http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
#
|
|
||||||
# Unless required by applicable law or agreed to in writing, software
|
|
||||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
# See the License for the specific language governing permissions and
|
|
||||||
# limitations under the License.
|
|
||||||
|
|
||||||
import os
|
|
||||||
import platform
|
|
||||||
import subprocess
|
|
||||||
import sys
|
|
||||||
|
|
||||||
EXECUTABLE_EXTENSION = '.exe' if platform.system() == 'Windows' else ''
|
|
||||||
# Paths to search for flatc relative to the current working directory.
|
|
||||||
FLATC_SEARCH_PATHS = [os.path.curdir, 'Release', 'Debug']
|
|
||||||
|
|
||||||
def main():
|
|
||||||
"""Script that finds and runs flatc built from source."""
|
|
||||||
if len(sys.argv) < 2:
|
|
||||||
sys.stderr.write('Usage: run_flatc.py flatbuffers_dir [flatc_args]\n')
|
|
||||||
return 1
|
|
||||||
cwd = os.getcwd()
|
|
||||||
flatc = ''
|
|
||||||
flatbuffers_dir = sys.argv[1]
|
|
||||||
for path in FLATC_SEARCH_PATHS:
|
|
||||||
current = os.path.join(flatbuffers_dir, path,
|
|
||||||
'flatc' + EXECUTABLE_EXTENSION)
|
|
||||||
if os.path.exists(current):
|
|
||||||
flatc = current
|
|
||||||
break
|
|
||||||
if not flatc:
|
|
||||||
sys.stderr.write('flatc not found\n')
|
|
||||||
return 1
|
|
||||||
command = [flatc] + sys.argv[2:]
|
|
||||||
return subprocess.call(command)
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
|
||||||
sys.exit(main())
|
|
||||||
@@ -1,20 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<!-- Copyright (c) 2014 Google, Inc.
|
|
||||||
|
|
||||||
This software is provided 'as-is', without any express or implied
|
|
||||||
warranty. In no event will the authors be held liable for any damages
|
|
||||||
arising from the use of this software.
|
|
||||||
Permission is granted to anyone to use this software for any purpose,
|
|
||||||
including commercial applications, and to alter it and redistribute it
|
|
||||||
freely, subject to the following restrictions:
|
|
||||||
1. The origin of this software must not be misrepresented; you must not
|
|
||||||
claim that you wrote the original software. If you use this software
|
|
||||||
in a product, an acknowledgment in the product documentation would be
|
|
||||||
appreciated but is not required.
|
|
||||||
2. Altered source versions must be plainly marked as such, and must not be
|
|
||||||
misrepresented as being the original software.
|
|
||||||
3. This notice may not be removed or altered from any source distribution.
|
|
||||||
-->
|
|
||||||
<resources>
|
|
||||||
<string name="app_name">FlatBufferTest</string>
|
|
||||||
</resources>
|
|
||||||
2
android/settings.gradle
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
include ':app'
|
||||||
|
rootProject.name = "FlatbuffersTest"
|
||||||
125
appveyor.yml
@@ -1,125 +0,0 @@
|
|||||||
branches:
|
|
||||||
only:
|
|
||||||
- master
|
|
||||||
|
|
||||||
environment:
|
|
||||||
|
|
||||||
global:
|
|
||||||
# Workaround for https://github.com/conda/conda-build/issues/636
|
|
||||||
PYTHONIOENCODING: UTF-8
|
|
||||||
CONDA_INSTALL_LOCN: "C:\\Miniconda35-x64"
|
|
||||||
CMAKE_OPTIONS: ""
|
|
||||||
CPP_TEST_OPTIONS: ""
|
|
||||||
|
|
||||||
matrix:
|
|
||||||
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015
|
|
||||||
CMAKE_VS_VERSION: "10 2010"
|
|
||||||
CMAKE_OPTIONS: "-DFLATBUFFERS_BUILD_LEGACY=1"
|
|
||||||
CPP_TEST_OPTIONS: "--std-cpp c++0x"
|
|
||||||
MONSTER_EXTRA: "skip"
|
|
||||||
|
|
||||||
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015
|
|
||||||
CMAKE_VS_VERSION: "12 2013"
|
|
||||||
MONSTER_EXTRA: "skip"
|
|
||||||
|
|
||||||
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015
|
|
||||||
CMAKE_VS_VERSION: "14 2015"
|
|
||||||
MONSTER_EXTRA: ""
|
|
||||||
|
|
||||||
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017
|
|
||||||
CMAKE_VS_VERSION: "15 2017"
|
|
||||||
MONSTER_EXTRA: ""
|
|
||||||
|
|
||||||
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2019
|
|
||||||
CMAKE_VS_VERSION: "16 2019"
|
|
||||||
MONSTER_EXTRA: ""
|
|
||||||
|
|
||||||
platform:
|
|
||||||
- x86
|
|
||||||
- x64
|
|
||||||
|
|
||||||
configuration:
|
|
||||||
- Debug
|
|
||||||
- Release
|
|
||||||
|
|
||||||
before_build:
|
|
||||||
- set MONSTER_EXTRA=%MONSTER_EXTRA%
|
|
||||||
- cmake . -G"Visual Studio %CMAKE_VS_VERSION%" -DFLATBUFFERS_CODE_SANITIZE=1 %CMAKE_OPTIONS%
|
|
||||||
# This cuts down on a lot of noise generated by xamarin warnings.
|
|
||||||
- if exist "C:\Program Files (x86)\MSBuild\14.0\Microsoft.Common.targets\ImportAfter\Xamarin.Common.targets" del "C:\Program Files (x86)\MSBuild\14.0\Microsoft.Common.targets\ImportAfter\Xamarin.Common.targets"
|
|
||||||
- if exist "C:\Program Files (x86)\MSBuild\15.0\Microsoft.Common.targets\ImportAfter\Xamarin.Common.targets" del "C:\Program Files (x86)\MSBuild\15.0\Microsoft.Common.targets\ImportAfter\Xamarin.Common.targets"
|
|
||||||
- if exist "C:\Program Files (x86)\MSBuild\16.0\Microsoft.Common.targets\ImportAfter\Xamarin.Common.targets" del "C:\Program Files (x86)\MSBuild\16.0\Microsoft.Common.targets\ImportAfter\Xamarin.Common.targets"
|
|
||||||
|
|
||||||
build:
|
|
||||||
project: ALL_BUILD.vcxproj
|
|
||||||
verbosity: minimal
|
|
||||||
|
|
||||||
after_build:
|
|
||||||
- python conan/appveyor/install.py
|
|
||||||
- python conan/appveyor/build.py
|
|
||||||
|
|
||||||
install:
|
|
||||||
- set PATH=%CONDA_INSTALL_LOCN%;%CONDA_INSTALL_LOCN%\scripts;%PATH%;
|
|
||||||
- curl -sSf -o rustup-init.exe https://win.rustup.rs/
|
|
||||||
- rustup-init.exe -y
|
|
||||||
- set PATH=%PATH%;C:\Users\appveyor\.cargo\bin
|
|
||||||
- rustc -V
|
|
||||||
- cargo -V
|
|
||||||
|
|
||||||
test_script:
|
|
||||||
- call .appveyor\check-generate-code.bat -b %CONFIGURATION%
|
|
||||||
- "cd tests"
|
|
||||||
- rem "Building all code"
|
|
||||||
- generate_code.bat -b %CONFIGURATION% %CPP_TEST_OPTIONS%
|
|
||||||
- 7z a GeneratedMyGameCode.zip MyGame\
|
|
||||||
- rem "---------------- C++ -----------------"
|
|
||||||
- "cd .."
|
|
||||||
- "%CONFIGURATION%\\flattests.exe"
|
|
||||||
- "cd tests"
|
|
||||||
- rem "---------------- Java -----------------"
|
|
||||||
- "java -version"
|
|
||||||
- "JavaTest.bat"
|
|
||||||
- rem "---------------- Rust ----------------"
|
|
||||||
- "RustTest.bat"
|
|
||||||
- rem "---------------- JS -----------------"
|
|
||||||
- "node --version"
|
|
||||||
- "..\\%CONFIGURATION%\\flatc -b -I include_test monster_test.fbs unicode_test.json"
|
|
||||||
- "node JavaScriptTest ./monster_test_generated"
|
|
||||||
- rem "-------------- Python ---------------"
|
|
||||||
- where python
|
|
||||||
- python --version
|
|
||||||
- where pip
|
|
||||||
- pip --version
|
|
||||||
- where conda
|
|
||||||
- conda --version
|
|
||||||
- rem "installing flatbuffers python library"
|
|
||||||
- pip install ../python
|
|
||||||
- rem "testing without installing Numpy"
|
|
||||||
- python py_test.py 0 0 0
|
|
||||||
- rem "testing after installing Numpy - disabled"
|
|
||||||
# FIXME: This has a LOT of unnecessary dependencies and makes the tests fail
|
|
||||||
# with timeouts.
|
|
||||||
# - conda install --yes numpy
|
|
||||||
# - python py_test.py 0 0 0
|
|
||||||
- rem "---------------- C# -----------------"
|
|
||||||
# Have to compile this here rather than in "build" above because AppVeyor only
|
|
||||||
# supports building one project??
|
|
||||||
- "cd FlatBuffers.Test"
|
|
||||||
- "copy ..\\monsterdata_test.mon Resources\\"
|
|
||||||
- "copy ..\\monsterdata_test.json Resources\\"
|
|
||||||
- "dotnet new sln"
|
|
||||||
- "dotnet sln add FlatBuffers.Test.csproj"
|
|
||||||
- "nuget restore"
|
|
||||||
- "msbuild.exe /property:Configuration=Release;OutputPath=tempcs /verbosity:minimal FlatBuffers.Test.csproj"
|
|
||||||
- "tempcs\\FlatBuffers.Test.exe"
|
|
||||||
# Run tests with UNSAFE_BYTEBUFFER
|
|
||||||
- "msbuild.exe /property:Configuration=Release;UnsafeByteBuffer=true;OutputPath=tempcsUnsafe /verbosity:minimal FlatBuffers.Test.csproj"
|
|
||||||
- "tempcsUnsafe\\FlatBuffers.Test.exe"
|
|
||||||
# TODO: add more languages.
|
|
||||||
- "cd ..\\.."
|
|
||||||
|
|
||||||
artifacts:
|
|
||||||
- path: $(CONFIGURATION)\flatc.exe
|
|
||||||
name: flatc.exe
|
|
||||||
- path: tests\GeneratedMyGameCode.zip
|
|
||||||
name: GeneratedMyGameCode.zip
|
|
||||||
87
benchmarks/CMakeLists.txt
Normal file
@@ -0,0 +1,87 @@
|
|||||||
|
# Setup for running Google Benchmarks (https://github.com/google/benchmark) on
|
||||||
|
# flatbuffers. This requires both that benchmark library and its depenency gtest
|
||||||
|
# to build. Instead of including them here or doing a submodule, this uses
|
||||||
|
# FetchContent (https://cmake.org/cmake/help/latest/module/FetchContent.html) to
|
||||||
|
# grab the dependencies at config time. This requires CMake 3.14 or higher.
|
||||||
|
cmake_minimum_required(VERSION 3.14)
|
||||||
|
include(FetchContent)
|
||||||
|
|
||||||
|
# No particular reason for the specific GIT_TAGs for the following repos, they
|
||||||
|
# were just the latest releases when this was added.
|
||||||
|
FetchContent_Declare(
|
||||||
|
googletest
|
||||||
|
GIT_REPOSITORY https://github.com/google/googletest.git
|
||||||
|
GIT_TAG e2239ee6043f73722e7aa812a459f54a28552929 # release-1.11.0
|
||||||
|
)
|
||||||
|
FetchContent_Declare(
|
||||||
|
googlebenchmark
|
||||||
|
GIT_REPOSITORY https://github.com/google/benchmark.git
|
||||||
|
GIT_TAG 0d98dba29d66e93259db7daa53a9327df767a415 # v1.6.1
|
||||||
|
)
|
||||||
|
|
||||||
|
# For Windows: Prevent overriding the parent project's compiler/linker
|
||||||
|
# settings.
|
||||||
|
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
|
||||||
|
FetchContent_MakeAvailable(
|
||||||
|
googletest
|
||||||
|
googlebenchmark
|
||||||
|
)
|
||||||
|
|
||||||
|
set(CPP_BENCH_DIR cpp)
|
||||||
|
set(CPP_FB_BENCH_DIR ${CPP_BENCH_DIR}/flatbuffers)
|
||||||
|
set(CPP_RAW_BENCH_DIR ${CPP_BENCH_DIR}/raw)
|
||||||
|
set(CPP_BENCH_FBS ${CPP_FB_BENCH_DIR}/bench.fbs)
|
||||||
|
set(CPP_BENCH_FB_GEN ${CPP_FB_BENCH_DIR}/bench_generated.h)
|
||||||
|
|
||||||
|
set(FlatBenchmark_SRCS
|
||||||
|
${CPP_BENCH_DIR}/benchmark_main.cpp
|
||||||
|
${CPP_FB_BENCH_DIR}/fb_bench.cpp
|
||||||
|
${CPP_RAW_BENCH_DIR}/raw_bench.cpp
|
||||||
|
${CPP_BENCH_FB_GEN}
|
||||||
|
)
|
||||||
|
|
||||||
|
# Generate the flatbuffers benchmark code from the flatbuffers schema using
|
||||||
|
# flatc itself, thus it depends on flatc. This also depends on the C++ runtime
|
||||||
|
# flatbuffers and the schema file itself, so it should auto-generated at the
|
||||||
|
# correct times.
|
||||||
|
add_custom_command(
|
||||||
|
OUTPUT ${CPP_BENCH_FB_GEN}
|
||||||
|
COMMAND
|
||||||
|
"${FLATBUFFERS_FLATC_EXECUTABLE}"
|
||||||
|
--cpp
|
||||||
|
-o ${CPP_FB_BENCH_DIR}
|
||||||
|
${CPP_BENCH_FBS}
|
||||||
|
DEPENDS
|
||||||
|
flatc
|
||||||
|
flatbuffers
|
||||||
|
${CPP_BENCH_FBS}
|
||||||
|
COMMENT "Run Flatbuffers Benchmark Codegen: ${CPP_BENCH_FB_GEN}"
|
||||||
|
VERBATIM)
|
||||||
|
|
||||||
|
# The main flatbuffers benchmark executable
|
||||||
|
add_executable(flatbenchmark ${FlatBenchmark_SRCS})
|
||||||
|
|
||||||
|
# Benchmark requires C++11
|
||||||
|
target_compile_features(flatbenchmark PUBLIC
|
||||||
|
cxx_std_11
|
||||||
|
)
|
||||||
|
|
||||||
|
target_compile_options(flatbenchmark
|
||||||
|
PRIVATE
|
||||||
|
-fno-aligned-new
|
||||||
|
-Wno-deprecated-declarations
|
||||||
|
)
|
||||||
|
|
||||||
|
# Set the output directory to the root binary directory
|
||||||
|
set_target_properties(flatbenchmark
|
||||||
|
PROPERTIES RUNTIME_OUTPUT_DIRECTORY
|
||||||
|
"${CMAKE_BINARY_DIR}"
|
||||||
|
)
|
||||||
|
|
||||||
|
# The includes of the benchmark files are fully qualified from flatbuffers root.
|
||||||
|
target_include_directories(flatbenchmark PUBLIC ${CMAKE_SOURCE_DIR})
|
||||||
|
|
||||||
|
target_link_libraries(flatbenchmark
|
||||||
|
benchmark::benchmark_main # _main to use their entry point
|
||||||
|
gtest # Link to gtest so we can also assert in the benchmarks
|
||||||
|
)
|
||||||
19
benchmarks/cpp/bench.h
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
#ifndef BENCHMARKS_CPP_BENCH_H_
|
||||||
|
#define BENCHMARKS_CPP_BENCH_H_
|
||||||
|
|
||||||
|
#include <cstdint>
|
||||||
|
|
||||||
|
struct Bench {
|
||||||
|
virtual ~Bench() {}
|
||||||
|
|
||||||
|
inline void Add(int64_t value) { sum += value; }
|
||||||
|
|
||||||
|
virtual uint8_t *Encode(void *buf, int64_t &len) = 0;
|
||||||
|
virtual void *Decode(void *buf, int64_t len) = 0;
|
||||||
|
virtual int64_t Use(void *decoded) = 0;
|
||||||
|
virtual void Dealloc(void *decoded) = 0;
|
||||||
|
|
||||||
|
int64_t sum = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // BENCHMARKS_CPP_BENCH_H_
|
||||||
96
benchmarks/cpp/benchmark_main.cpp
Normal file
@@ -0,0 +1,96 @@
|
|||||||
|
#include <benchmark/benchmark.h>
|
||||||
|
#include <gtest/gtest.h>
|
||||||
|
|
||||||
|
#include "benchmarks/cpp/bench.h"
|
||||||
|
#include "benchmarks/cpp/flatbuffers/fb_bench.h"
|
||||||
|
#include "benchmarks/cpp/raw/raw_bench.h"
|
||||||
|
|
||||||
|
static inline void Encode(benchmark::State &state,
|
||||||
|
std::unique_ptr<Bench> &bench, uint8_t *buffer) {
|
||||||
|
int64_t length;
|
||||||
|
for (auto _ : state) {
|
||||||
|
bench->Encode(buffer, length);
|
||||||
|
benchmark::DoNotOptimize(length);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline void Decode(benchmark::State &state,
|
||||||
|
std::unique_ptr<Bench> &bench, uint8_t *buffer) {
|
||||||
|
int64_t length;
|
||||||
|
uint8_t *encoded = bench->Encode(buffer, length);
|
||||||
|
|
||||||
|
for (auto _ : state) {
|
||||||
|
void *decoded = bench->Decode(encoded, length);
|
||||||
|
benchmark::DoNotOptimize(decoded);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline void Use(benchmark::State &state, std::unique_ptr<Bench> &bench,
|
||||||
|
uint8_t *buffer, int64_t check_sum) {
|
||||||
|
int64_t length;
|
||||||
|
uint8_t *encoded = bench->Encode(buffer, length);
|
||||||
|
void *decoded = bench->Decode(encoded, length);
|
||||||
|
|
||||||
|
int64_t sum = 0;
|
||||||
|
|
||||||
|
for (auto _ : state) { sum = bench->Use(decoded); }
|
||||||
|
|
||||||
|
EXPECT_EQ(sum, check_sum);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void BM_Flatbuffers_Encode(benchmark::State &state) {
|
||||||
|
const int64_t kBufferLength = 1024;
|
||||||
|
uint8_t buffer[kBufferLength];
|
||||||
|
|
||||||
|
StaticAllocator allocator(&buffer[0]);
|
||||||
|
std::unique_ptr<Bench> bench = NewFlatBuffersBench(kBufferLength, &allocator);
|
||||||
|
Encode(state, bench, buffer);
|
||||||
|
}
|
||||||
|
BENCHMARK(BM_Flatbuffers_Encode);
|
||||||
|
|
||||||
|
static void BM_Flatbuffers_Decode(benchmark::State &state) {
|
||||||
|
const int64_t kBufferLength = 1024;
|
||||||
|
uint8_t buffer[kBufferLength];
|
||||||
|
|
||||||
|
StaticAllocator allocator(&buffer[0]);
|
||||||
|
std::unique_ptr<Bench> bench = NewFlatBuffersBench(kBufferLength, &allocator);
|
||||||
|
Decode(state, bench, buffer);
|
||||||
|
}
|
||||||
|
BENCHMARK(BM_Flatbuffers_Decode);
|
||||||
|
|
||||||
|
static void BM_Flatbuffers_Use(benchmark::State &state) {
|
||||||
|
const int64_t kBufferLength = 1024;
|
||||||
|
uint8_t buffer[kBufferLength];
|
||||||
|
|
||||||
|
StaticAllocator allocator(&buffer[0]);
|
||||||
|
std::unique_ptr<Bench> bench = NewFlatBuffersBench(kBufferLength, &allocator);
|
||||||
|
Use(state, bench, buffer, 218812692406581874);
|
||||||
|
}
|
||||||
|
BENCHMARK(BM_Flatbuffers_Use);
|
||||||
|
|
||||||
|
static void BM_Raw_Encode(benchmark::State &state) {
|
||||||
|
const int64_t kBufferLength = 1024;
|
||||||
|
uint8_t buffer[kBufferLength];
|
||||||
|
|
||||||
|
std::unique_ptr<Bench> bench = NewRawBench();
|
||||||
|
Encode(state, bench, buffer);
|
||||||
|
}
|
||||||
|
BENCHMARK(BM_Raw_Encode);
|
||||||
|
|
||||||
|
static void BM_Raw_Decode(benchmark::State &state) {
|
||||||
|
const int64_t kBufferLength = 1024;
|
||||||
|
uint8_t buffer[kBufferLength];
|
||||||
|
|
||||||
|
std::unique_ptr<Bench> bench = NewRawBench();
|
||||||
|
Decode(state, bench, buffer);
|
||||||
|
}
|
||||||
|
BENCHMARK(BM_Raw_Decode);
|
||||||
|
|
||||||
|
static void BM_Raw_Use(benchmark::State &state) {
|
||||||
|
const int64_t kBufferLength = 1024;
|
||||||
|
uint8_t buffer[kBufferLength];
|
||||||
|
|
||||||
|
std::unique_ptr<Bench> bench = NewRawBench();
|
||||||
|
Use(state, bench, buffer, 218812692406581874);
|
||||||
|
}
|
||||||
|
BENCHMARK(BM_Raw_Use);
|
||||||
52
benchmarks/cpp/flatbuffers/bench.fbs
Normal file
@@ -0,0 +1,52 @@
|
|||||||
|
// Copyright 2021 Google Inc. All rights reserved.
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
|
||||||
|
|
||||||
|
// trying to represent a typical mix of datatypes:
|
||||||
|
// 1 array of 3 elements, each element: 1 string, 3 nested objects, 9 scalars
|
||||||
|
// root element has the array, additional string and an enum
|
||||||
|
|
||||||
|
namespace benchmarks_flatbuffers;
|
||||||
|
|
||||||
|
enum Enum : short { Apples, Pears, Bananas}
|
||||||
|
|
||||||
|
struct Foo {
|
||||||
|
id:ulong;
|
||||||
|
count:short;
|
||||||
|
prefix:byte;
|
||||||
|
length:uint;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct Bar {
|
||||||
|
parent:Foo;
|
||||||
|
time:int;
|
||||||
|
ratio:float;
|
||||||
|
size:ushort;
|
||||||
|
}
|
||||||
|
|
||||||
|
table FooBar {
|
||||||
|
sibling:Bar;
|
||||||
|
name:string;
|
||||||
|
rating:double;
|
||||||
|
postfix:ubyte;
|
||||||
|
}
|
||||||
|
|
||||||
|
table FooBarContainer {
|
||||||
|
list:[FooBar]; // 3 copies of the above
|
||||||
|
initialized:bool;
|
||||||
|
fruit:Enum;
|
||||||
|
location:string;
|
||||||
|
}
|
||||||
|
|
||||||
|
root_type FooBarContainer;
|
||||||
354
benchmarks/cpp/flatbuffers/bench_generated.h
Normal file
@@ -0,0 +1,354 @@
|
|||||||
|
// automatically generated by the FlatBuffers compiler, do not modify
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef FLATBUFFERS_GENERATED_BENCH_BENCHMARKS_FLATBUFFERS_H_
|
||||||
|
#define FLATBUFFERS_GENERATED_BENCH_BENCHMARKS_FLATBUFFERS_H_
|
||||||
|
|
||||||
|
#include "flatbuffers/flatbuffers.h"
|
||||||
|
|
||||||
|
// Ensure the included flatbuffers.h is the same version as when this file was
|
||||||
|
// generated, otherwise it may not be compatible.
|
||||||
|
static_assert(FLATBUFFERS_VERSION_MAJOR == 2 &&
|
||||||
|
FLATBUFFERS_VERSION_MINOR == 0 &&
|
||||||
|
FLATBUFFERS_VERSION_REVISION == 6,
|
||||||
|
"Non-compatible flatbuffers version included");
|
||||||
|
|
||||||
|
namespace benchmarks_flatbuffers {
|
||||||
|
|
||||||
|
struct Foo;
|
||||||
|
|
||||||
|
struct Bar;
|
||||||
|
|
||||||
|
struct FooBar;
|
||||||
|
struct FooBarBuilder;
|
||||||
|
|
||||||
|
struct FooBarContainer;
|
||||||
|
struct FooBarContainerBuilder;
|
||||||
|
|
||||||
|
enum Enum : int16_t {
|
||||||
|
Enum_Apples = 0,
|
||||||
|
Enum_Pears = 1,
|
||||||
|
Enum_Bananas = 2,
|
||||||
|
Enum_MIN = Enum_Apples,
|
||||||
|
Enum_MAX = Enum_Bananas
|
||||||
|
};
|
||||||
|
|
||||||
|
inline const Enum (&EnumValuesEnum())[3] {
|
||||||
|
static const Enum values[] = {
|
||||||
|
Enum_Apples,
|
||||||
|
Enum_Pears,
|
||||||
|
Enum_Bananas
|
||||||
|
};
|
||||||
|
return values;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline const char * const *EnumNamesEnum() {
|
||||||
|
static const char * const names[4] = {
|
||||||
|
"Apples",
|
||||||
|
"Pears",
|
||||||
|
"Bananas",
|
||||||
|
nullptr
|
||||||
|
};
|
||||||
|
return names;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline const char *EnumNameEnum(Enum e) {
|
||||||
|
if (flatbuffers::IsOutRange(e, Enum_Apples, Enum_Bananas)) return "";
|
||||||
|
const size_t index = static_cast<size_t>(e);
|
||||||
|
return EnumNamesEnum()[index];
|
||||||
|
}
|
||||||
|
|
||||||
|
FLATBUFFERS_MANUALLY_ALIGNED_STRUCT(8) Foo FLATBUFFERS_FINAL_CLASS {
|
||||||
|
private:
|
||||||
|
uint64_t id_;
|
||||||
|
int16_t count_;
|
||||||
|
int8_t prefix_;
|
||||||
|
int8_t padding0__;
|
||||||
|
uint32_t length_;
|
||||||
|
|
||||||
|
public:
|
||||||
|
Foo()
|
||||||
|
: id_(0),
|
||||||
|
count_(0),
|
||||||
|
prefix_(0),
|
||||||
|
padding0__(0),
|
||||||
|
length_(0) {
|
||||||
|
(void)padding0__;
|
||||||
|
}
|
||||||
|
Foo(uint64_t _id, int16_t _count, int8_t _prefix, uint32_t _length)
|
||||||
|
: id_(flatbuffers::EndianScalar(_id)),
|
||||||
|
count_(flatbuffers::EndianScalar(_count)),
|
||||||
|
prefix_(flatbuffers::EndianScalar(_prefix)),
|
||||||
|
padding0__(0),
|
||||||
|
length_(flatbuffers::EndianScalar(_length)) {
|
||||||
|
(void)padding0__;
|
||||||
|
}
|
||||||
|
uint64_t id() const {
|
||||||
|
return flatbuffers::EndianScalar(id_);
|
||||||
|
}
|
||||||
|
int16_t count() const {
|
||||||
|
return flatbuffers::EndianScalar(count_);
|
||||||
|
}
|
||||||
|
int8_t prefix() const {
|
||||||
|
return flatbuffers::EndianScalar(prefix_);
|
||||||
|
}
|
||||||
|
uint32_t length() const {
|
||||||
|
return flatbuffers::EndianScalar(length_);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
FLATBUFFERS_STRUCT_END(Foo, 16);
|
||||||
|
|
||||||
|
FLATBUFFERS_MANUALLY_ALIGNED_STRUCT(8) Bar FLATBUFFERS_FINAL_CLASS {
|
||||||
|
private:
|
||||||
|
benchmarks_flatbuffers::Foo parent_;
|
||||||
|
int32_t time_;
|
||||||
|
float ratio_;
|
||||||
|
uint16_t size_;
|
||||||
|
int16_t padding0__; int32_t padding1__;
|
||||||
|
|
||||||
|
public:
|
||||||
|
Bar()
|
||||||
|
: parent_(),
|
||||||
|
time_(0),
|
||||||
|
ratio_(0),
|
||||||
|
size_(0),
|
||||||
|
padding0__(0),
|
||||||
|
padding1__(0) {
|
||||||
|
(void)padding0__;
|
||||||
|
(void)padding1__;
|
||||||
|
}
|
||||||
|
Bar(const benchmarks_flatbuffers::Foo &_parent, int32_t _time, float _ratio, uint16_t _size)
|
||||||
|
: parent_(_parent),
|
||||||
|
time_(flatbuffers::EndianScalar(_time)),
|
||||||
|
ratio_(flatbuffers::EndianScalar(_ratio)),
|
||||||
|
size_(flatbuffers::EndianScalar(_size)),
|
||||||
|
padding0__(0),
|
||||||
|
padding1__(0) {
|
||||||
|
(void)padding0__;
|
||||||
|
(void)padding1__;
|
||||||
|
}
|
||||||
|
const benchmarks_flatbuffers::Foo &parent() const {
|
||||||
|
return parent_;
|
||||||
|
}
|
||||||
|
int32_t time() const {
|
||||||
|
return flatbuffers::EndianScalar(time_);
|
||||||
|
}
|
||||||
|
float ratio() const {
|
||||||
|
return flatbuffers::EndianScalar(ratio_);
|
||||||
|
}
|
||||||
|
uint16_t size() const {
|
||||||
|
return flatbuffers::EndianScalar(size_);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
FLATBUFFERS_STRUCT_END(Bar, 32);
|
||||||
|
|
||||||
|
struct FooBar FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table {
|
||||||
|
typedef FooBarBuilder Builder;
|
||||||
|
enum FlatBuffersVTableOffset FLATBUFFERS_VTABLE_UNDERLYING_TYPE {
|
||||||
|
VT_SIBLING = 4,
|
||||||
|
VT_NAME = 6,
|
||||||
|
VT_RATING = 8,
|
||||||
|
VT_POSTFIX = 10
|
||||||
|
};
|
||||||
|
const benchmarks_flatbuffers::Bar *sibling() const {
|
||||||
|
return GetStruct<const benchmarks_flatbuffers::Bar *>(VT_SIBLING);
|
||||||
|
}
|
||||||
|
const flatbuffers::String *name() const {
|
||||||
|
return GetPointer<const flatbuffers::String *>(VT_NAME);
|
||||||
|
}
|
||||||
|
double rating() const {
|
||||||
|
return GetField<double>(VT_RATING, 0.0);
|
||||||
|
}
|
||||||
|
uint8_t postfix() const {
|
||||||
|
return GetField<uint8_t>(VT_POSTFIX, 0);
|
||||||
|
}
|
||||||
|
bool Verify(flatbuffers::Verifier &verifier) const {
|
||||||
|
return VerifyTableStart(verifier) &&
|
||||||
|
VerifyField<benchmarks_flatbuffers::Bar>(verifier, VT_SIBLING, 8) &&
|
||||||
|
VerifyOffset(verifier, VT_NAME) &&
|
||||||
|
verifier.VerifyString(name()) &&
|
||||||
|
VerifyField<double>(verifier, VT_RATING, 8) &&
|
||||||
|
VerifyField<uint8_t>(verifier, VT_POSTFIX, 1) &&
|
||||||
|
verifier.EndTable();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
struct FooBarBuilder {
|
||||||
|
typedef FooBar Table;
|
||||||
|
flatbuffers::FlatBufferBuilder &fbb_;
|
||||||
|
flatbuffers::uoffset_t start_;
|
||||||
|
void add_sibling(const benchmarks_flatbuffers::Bar *sibling) {
|
||||||
|
fbb_.AddStruct(FooBar::VT_SIBLING, sibling);
|
||||||
|
}
|
||||||
|
void add_name(flatbuffers::Offset<flatbuffers::String> name) {
|
||||||
|
fbb_.AddOffset(FooBar::VT_NAME, name);
|
||||||
|
}
|
||||||
|
void add_rating(double rating) {
|
||||||
|
fbb_.AddElement<double>(FooBar::VT_RATING, rating, 0.0);
|
||||||
|
}
|
||||||
|
void add_postfix(uint8_t postfix) {
|
||||||
|
fbb_.AddElement<uint8_t>(FooBar::VT_POSTFIX, postfix, 0);
|
||||||
|
}
|
||||||
|
explicit FooBarBuilder(flatbuffers::FlatBufferBuilder &_fbb)
|
||||||
|
: fbb_(_fbb) {
|
||||||
|
start_ = fbb_.StartTable();
|
||||||
|
}
|
||||||
|
flatbuffers::Offset<FooBar> Finish() {
|
||||||
|
const auto end = fbb_.EndTable(start_);
|
||||||
|
auto o = flatbuffers::Offset<FooBar>(end);
|
||||||
|
return o;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
inline flatbuffers::Offset<FooBar> CreateFooBar(
|
||||||
|
flatbuffers::FlatBufferBuilder &_fbb,
|
||||||
|
const benchmarks_flatbuffers::Bar *sibling = nullptr,
|
||||||
|
flatbuffers::Offset<flatbuffers::String> name = 0,
|
||||||
|
double rating = 0.0,
|
||||||
|
uint8_t postfix = 0) {
|
||||||
|
FooBarBuilder builder_(_fbb);
|
||||||
|
builder_.add_rating(rating);
|
||||||
|
builder_.add_name(name);
|
||||||
|
builder_.add_sibling(sibling);
|
||||||
|
builder_.add_postfix(postfix);
|
||||||
|
return builder_.Finish();
|
||||||
|
}
|
||||||
|
|
||||||
|
inline flatbuffers::Offset<FooBar> CreateFooBarDirect(
|
||||||
|
flatbuffers::FlatBufferBuilder &_fbb,
|
||||||
|
const benchmarks_flatbuffers::Bar *sibling = nullptr,
|
||||||
|
const char *name = nullptr,
|
||||||
|
double rating = 0.0,
|
||||||
|
uint8_t postfix = 0) {
|
||||||
|
auto name__ = name ? _fbb.CreateString(name) : 0;
|
||||||
|
return benchmarks_flatbuffers::CreateFooBar(
|
||||||
|
_fbb,
|
||||||
|
sibling,
|
||||||
|
name__,
|
||||||
|
rating,
|
||||||
|
postfix);
|
||||||
|
}
|
||||||
|
|
||||||
|
struct FooBarContainer FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table {
|
||||||
|
typedef FooBarContainerBuilder Builder;
|
||||||
|
enum FlatBuffersVTableOffset FLATBUFFERS_VTABLE_UNDERLYING_TYPE {
|
||||||
|
VT_LIST = 4,
|
||||||
|
VT_INITIALIZED = 6,
|
||||||
|
VT_FRUIT = 8,
|
||||||
|
VT_LOCATION = 10
|
||||||
|
};
|
||||||
|
const flatbuffers::Vector<flatbuffers::Offset<benchmarks_flatbuffers::FooBar>> *list() const {
|
||||||
|
return GetPointer<const flatbuffers::Vector<flatbuffers::Offset<benchmarks_flatbuffers::FooBar>> *>(VT_LIST);
|
||||||
|
}
|
||||||
|
bool initialized() const {
|
||||||
|
return GetField<uint8_t>(VT_INITIALIZED, 0) != 0;
|
||||||
|
}
|
||||||
|
benchmarks_flatbuffers::Enum fruit() const {
|
||||||
|
return static_cast<benchmarks_flatbuffers::Enum>(GetField<int16_t>(VT_FRUIT, 0));
|
||||||
|
}
|
||||||
|
const flatbuffers::String *location() const {
|
||||||
|
return GetPointer<const flatbuffers::String *>(VT_LOCATION);
|
||||||
|
}
|
||||||
|
bool Verify(flatbuffers::Verifier &verifier) const {
|
||||||
|
return VerifyTableStart(verifier) &&
|
||||||
|
VerifyOffset(verifier, VT_LIST) &&
|
||||||
|
verifier.VerifyVector(list()) &&
|
||||||
|
verifier.VerifyVectorOfTables(list()) &&
|
||||||
|
VerifyField<uint8_t>(verifier, VT_INITIALIZED, 1) &&
|
||||||
|
VerifyField<int16_t>(verifier, VT_FRUIT, 2) &&
|
||||||
|
VerifyOffset(verifier, VT_LOCATION) &&
|
||||||
|
verifier.VerifyString(location()) &&
|
||||||
|
verifier.EndTable();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
struct FooBarContainerBuilder {
|
||||||
|
typedef FooBarContainer Table;
|
||||||
|
flatbuffers::FlatBufferBuilder &fbb_;
|
||||||
|
flatbuffers::uoffset_t start_;
|
||||||
|
void add_list(flatbuffers::Offset<flatbuffers::Vector<flatbuffers::Offset<benchmarks_flatbuffers::FooBar>>> list) {
|
||||||
|
fbb_.AddOffset(FooBarContainer::VT_LIST, list);
|
||||||
|
}
|
||||||
|
void add_initialized(bool initialized) {
|
||||||
|
fbb_.AddElement<uint8_t>(FooBarContainer::VT_INITIALIZED, static_cast<uint8_t>(initialized), 0);
|
||||||
|
}
|
||||||
|
void add_fruit(benchmarks_flatbuffers::Enum fruit) {
|
||||||
|
fbb_.AddElement<int16_t>(FooBarContainer::VT_FRUIT, static_cast<int16_t>(fruit), 0);
|
||||||
|
}
|
||||||
|
void add_location(flatbuffers::Offset<flatbuffers::String> location) {
|
||||||
|
fbb_.AddOffset(FooBarContainer::VT_LOCATION, location);
|
||||||
|
}
|
||||||
|
explicit FooBarContainerBuilder(flatbuffers::FlatBufferBuilder &_fbb)
|
||||||
|
: fbb_(_fbb) {
|
||||||
|
start_ = fbb_.StartTable();
|
||||||
|
}
|
||||||
|
flatbuffers::Offset<FooBarContainer> Finish() {
|
||||||
|
const auto end = fbb_.EndTable(start_);
|
||||||
|
auto o = flatbuffers::Offset<FooBarContainer>(end);
|
||||||
|
return o;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
inline flatbuffers::Offset<FooBarContainer> CreateFooBarContainer(
|
||||||
|
flatbuffers::FlatBufferBuilder &_fbb,
|
||||||
|
flatbuffers::Offset<flatbuffers::Vector<flatbuffers::Offset<benchmarks_flatbuffers::FooBar>>> list = 0,
|
||||||
|
bool initialized = false,
|
||||||
|
benchmarks_flatbuffers::Enum fruit = benchmarks_flatbuffers::Enum_Apples,
|
||||||
|
flatbuffers::Offset<flatbuffers::String> location = 0) {
|
||||||
|
FooBarContainerBuilder builder_(_fbb);
|
||||||
|
builder_.add_location(location);
|
||||||
|
builder_.add_list(list);
|
||||||
|
builder_.add_fruit(fruit);
|
||||||
|
builder_.add_initialized(initialized);
|
||||||
|
return builder_.Finish();
|
||||||
|
}
|
||||||
|
|
||||||
|
inline flatbuffers::Offset<FooBarContainer> CreateFooBarContainerDirect(
|
||||||
|
flatbuffers::FlatBufferBuilder &_fbb,
|
||||||
|
const std::vector<flatbuffers::Offset<benchmarks_flatbuffers::FooBar>> *list = nullptr,
|
||||||
|
bool initialized = false,
|
||||||
|
benchmarks_flatbuffers::Enum fruit = benchmarks_flatbuffers::Enum_Apples,
|
||||||
|
const char *location = nullptr) {
|
||||||
|
auto list__ = list ? _fbb.CreateVector<flatbuffers::Offset<benchmarks_flatbuffers::FooBar>>(*list) : 0;
|
||||||
|
auto location__ = location ? _fbb.CreateString(location) : 0;
|
||||||
|
return benchmarks_flatbuffers::CreateFooBarContainer(
|
||||||
|
_fbb,
|
||||||
|
list__,
|
||||||
|
initialized,
|
||||||
|
fruit,
|
||||||
|
location__);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline const benchmarks_flatbuffers::FooBarContainer *GetFooBarContainer(const void *buf) {
|
||||||
|
return flatbuffers::GetRoot<benchmarks_flatbuffers::FooBarContainer>(buf);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline const benchmarks_flatbuffers::FooBarContainer *GetSizePrefixedFooBarContainer(const void *buf) {
|
||||||
|
return flatbuffers::GetSizePrefixedRoot<benchmarks_flatbuffers::FooBarContainer>(buf);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline bool VerifyFooBarContainerBuffer(
|
||||||
|
flatbuffers::Verifier &verifier) {
|
||||||
|
return verifier.VerifyBuffer<benchmarks_flatbuffers::FooBarContainer>(nullptr);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline bool VerifySizePrefixedFooBarContainerBuffer(
|
||||||
|
flatbuffers::Verifier &verifier) {
|
||||||
|
return verifier.VerifySizePrefixedBuffer<benchmarks_flatbuffers::FooBarContainer>(nullptr);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void FinishFooBarContainerBuffer(
|
||||||
|
flatbuffers::FlatBufferBuilder &fbb,
|
||||||
|
flatbuffers::Offset<benchmarks_flatbuffers::FooBarContainer> root) {
|
||||||
|
fbb.Finish(root);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void FinishSizePrefixedFooBarContainerBuffer(
|
||||||
|
flatbuffers::FlatBufferBuilder &fbb,
|
||||||
|
flatbuffers::Offset<benchmarks_flatbuffers::FooBarContainer> root) {
|
||||||
|
fbb.FinishSizePrefixed(root);
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace benchmarks_flatbuffers
|
||||||
|
|
||||||
|
#endif // FLATBUFFERS_GENERATED_BENCH_BENCHMARKS_FLATBUFFERS_H_
|
||||||
80
benchmarks/cpp/flatbuffers/fb_bench.cpp
Normal file
@@ -0,0 +1,80 @@
|
|||||||
|
#include "benchmarks/cpp/flatbuffers/fb_bench.h"
|
||||||
|
|
||||||
|
#include <cstdint>
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
|
#include "benchmarks/cpp/bench.h"
|
||||||
|
#include "benchmarks/cpp/flatbuffers/bench_generated.h"
|
||||||
|
#include "flatbuffers/flatbuffers.h"
|
||||||
|
|
||||||
|
using namespace flatbuffers;
|
||||||
|
using namespace benchmarks_flatbuffers;
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
|
||||||
|
struct FlatBufferBench : Bench {
|
||||||
|
explicit FlatBufferBench(int64_t initial_size, Allocator *allocator)
|
||||||
|
: fbb(initial_size, allocator, false) {}
|
||||||
|
|
||||||
|
uint8_t *Encode(void *, int64_t &len) override {
|
||||||
|
fbb.Clear();
|
||||||
|
|
||||||
|
const int kVectorLength = 3;
|
||||||
|
Offset<FooBar> vec[kVectorLength];
|
||||||
|
|
||||||
|
for (int i = 0; i < kVectorLength; ++i) {
|
||||||
|
Foo foo(0xABADCAFEABADCAFE + i, 10000 + i, '@' + i, 1000000 + i);
|
||||||
|
Bar bar(foo, 123456 + i, 3.14159f + i, 10000 + i);
|
||||||
|
auto name = fbb.CreateString("Hello, World!");
|
||||||
|
auto foobar =
|
||||||
|
CreateFooBar(fbb, &bar, name, 3.1415432432445543543 + i, '!' + i);
|
||||||
|
vec[i] = foobar;
|
||||||
|
}
|
||||||
|
auto location = fbb.CreateString("http://google.com/flatbuffers/");
|
||||||
|
auto foobarvec = fbb.CreateVector(vec, kVectorLength);
|
||||||
|
auto foobarcontainer =
|
||||||
|
CreateFooBarContainer(fbb, foobarvec, true, Enum_Bananas, location);
|
||||||
|
fbb.Finish(foobarcontainer);
|
||||||
|
|
||||||
|
len = fbb.GetSize();
|
||||||
|
return fbb.GetBufferPointer();
|
||||||
|
}
|
||||||
|
|
||||||
|
int64_t Use(void *decoded) override {
|
||||||
|
sum = 0;
|
||||||
|
auto foobarcontainer = GetFooBarContainer(decoded);
|
||||||
|
sum = 0;
|
||||||
|
Add(foobarcontainer->initialized());
|
||||||
|
Add(foobarcontainer->location()->Length());
|
||||||
|
Add(foobarcontainer->fruit());
|
||||||
|
for (unsigned int i = 0; i < foobarcontainer->list()->Length(); i++) {
|
||||||
|
auto foobar = foobarcontainer->list()->Get(i);
|
||||||
|
Add(foobar->name()->Length());
|
||||||
|
Add(foobar->postfix());
|
||||||
|
Add(static_cast<int64_t>(foobar->rating()));
|
||||||
|
auto bar = foobar->sibling();
|
||||||
|
Add(static_cast<int64_t>(bar->ratio()));
|
||||||
|
Add(bar->size());
|
||||||
|
Add(bar->time());
|
||||||
|
auto &foo = bar->parent();
|
||||||
|
Add(foo.count());
|
||||||
|
Add(foo.id());
|
||||||
|
Add(foo.length());
|
||||||
|
Add(foo.prefix());
|
||||||
|
}
|
||||||
|
return sum;
|
||||||
|
}
|
||||||
|
|
||||||
|
void *Decode(void *buffer, int64_t) override { return buffer; }
|
||||||
|
void Dealloc(void *) override {};
|
||||||
|
|
||||||
|
FlatBufferBuilder fbb;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace
|
||||||
|
|
||||||
|
std::unique_ptr<Bench> NewFlatBuffersBench(int64_t initial_size,
|
||||||
|
Allocator *allocator) {
|
||||||
|
return std::unique_ptr<FlatBufferBench>(
|
||||||
|
new FlatBufferBench(initial_size, allocator));
|
||||||
|
}
|
||||||
23
benchmarks/cpp/flatbuffers/fb_bench.h
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
#ifndef BENCHMARKS_CPP_FLATBUFFERS_FB_BENCH_H_
|
||||||
|
#define BENCHMARKS_CPP_FLATBUFFERS_FB_BENCH_H_
|
||||||
|
|
||||||
|
#include <cstdint>
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
|
#include "benchmarks/cpp/bench.h"
|
||||||
|
#include "include/flatbuffers/flatbuffers.h"
|
||||||
|
|
||||||
|
struct StaticAllocator : public flatbuffers::Allocator {
|
||||||
|
explicit StaticAllocator(uint8_t *buffer) : buffer_(buffer) {}
|
||||||
|
|
||||||
|
uint8_t *allocate(size_t) override { return buffer_; }
|
||||||
|
|
||||||
|
void deallocate(uint8_t *, size_t) override {}
|
||||||
|
|
||||||
|
uint8_t *buffer_;
|
||||||
|
};
|
||||||
|
|
||||||
|
std::unique_ptr<Bench> NewFlatBuffersBench(
|
||||||
|
int64_t initial_size = 1024, flatbuffers::Allocator *allocator = nullptr);
|
||||||
|
|
||||||
|
#endif // BENCHMARKS_CPP_FLATBUFFERS_FB_BENCH_H_
|
||||||
109
benchmarks/cpp/raw/raw_bench.cpp
Normal file
@@ -0,0 +1,109 @@
|
|||||||
|
#include "benchmarks/cpp/raw/raw_bench.h"
|
||||||
|
|
||||||
|
#include <cstdint>
|
||||||
|
#include <cstring>
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
|
#include "benchmarks/cpp/bench.h"
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
const int64_t kStringLength = 32;
|
||||||
|
const int64_t kVectorLength = 3;
|
||||||
|
|
||||||
|
enum Enum { Apples, Pears, Bananas };
|
||||||
|
|
||||||
|
struct Foo {
|
||||||
|
int64_t id;
|
||||||
|
short count;
|
||||||
|
char prefix;
|
||||||
|
int length;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct Bar {
|
||||||
|
Foo parent;
|
||||||
|
int time;
|
||||||
|
float ratio;
|
||||||
|
unsigned short size;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct FooBar {
|
||||||
|
Bar sibling;
|
||||||
|
// We have to stick this in, otherwise strlen() will make it slower than
|
||||||
|
// FlatBuffers:
|
||||||
|
int name_len;
|
||||||
|
char name[kStringLength];
|
||||||
|
double rating;
|
||||||
|
unsigned char postfix;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct FooBarContainer {
|
||||||
|
FooBar list[kVectorLength]; // 3 copies of the above
|
||||||
|
bool initialized;
|
||||||
|
Enum fruit;
|
||||||
|
int location_len;
|
||||||
|
char location[kStringLength];
|
||||||
|
};
|
||||||
|
|
||||||
|
struct RawBench : Bench {
|
||||||
|
uint8_t *Encode(void *buf, int64_t &len) override {
|
||||||
|
FooBarContainer *fbc = new (buf) FooBarContainer;
|
||||||
|
strcpy(fbc->location, "http://google.com/flatbuffers/"); // Unsafe eek!
|
||||||
|
fbc->location_len = (int)strlen(fbc->location);
|
||||||
|
fbc->fruit = Bananas;
|
||||||
|
fbc->initialized = true;
|
||||||
|
for (int i = 0; i < kVectorLength; i++) {
|
||||||
|
// We add + i to not make these identical copies for a more realistic
|
||||||
|
// compression test.
|
||||||
|
auto &foobar = fbc->list[i];
|
||||||
|
foobar.rating = 3.1415432432445543543 + i;
|
||||||
|
foobar.postfix = '!' + i;
|
||||||
|
strcpy(foobar.name, "Hello, World!");
|
||||||
|
foobar.name_len = (int)strlen(foobar.name);
|
||||||
|
auto &bar = foobar.sibling;
|
||||||
|
bar.ratio = 3.14159f + i;
|
||||||
|
bar.size = 10000 + i;
|
||||||
|
bar.time = 123456 + i;
|
||||||
|
auto &foo = bar.parent;
|
||||||
|
foo.id = 0xABADCAFEABADCAFE + i;
|
||||||
|
foo.count = 10000 + i;
|
||||||
|
foo.length = 1000000 + i;
|
||||||
|
foo.prefix = '@' + i;
|
||||||
|
}
|
||||||
|
|
||||||
|
len = sizeof(FooBarContainer);
|
||||||
|
return reinterpret_cast<uint8_t *>(fbc);
|
||||||
|
};
|
||||||
|
|
||||||
|
int64_t Use(void *decoded) override {
|
||||||
|
auto foobarcontainer = reinterpret_cast<FooBarContainer *>(decoded);
|
||||||
|
sum = 0;
|
||||||
|
Add(foobarcontainer->initialized);
|
||||||
|
Add(foobarcontainer->location_len);
|
||||||
|
Add(foobarcontainer->fruit);
|
||||||
|
for (unsigned int i = 0; i < kVectorLength; i++) {
|
||||||
|
auto foobar = &foobarcontainer->list[i];
|
||||||
|
Add(foobar->name_len);
|
||||||
|
Add(foobar->postfix);
|
||||||
|
Add(static_cast<int64_t>(foobar->rating));
|
||||||
|
auto bar = &foobar->sibling;
|
||||||
|
Add(static_cast<int64_t>(bar->ratio));
|
||||||
|
Add(bar->size);
|
||||||
|
Add(bar->time);
|
||||||
|
auto &foo = bar->parent;
|
||||||
|
Add(foo.count);
|
||||||
|
Add(foo.id);
|
||||||
|
Add(foo.length);
|
||||||
|
Add(foo.prefix);
|
||||||
|
}
|
||||||
|
return sum;
|
||||||
|
}
|
||||||
|
|
||||||
|
void *Decode(void *buf, int64_t) override { return buf; }
|
||||||
|
void Dealloc(void *) override{};
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace
|
||||||
|
|
||||||
|
std::unique_ptr<Bench> NewRawBench() {
|
||||||
|
return std::unique_ptr<RawBench>(new RawBench());
|
||||||
|
}
|
||||||
10
benchmarks/cpp/raw/raw_bench.h
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
#ifndef BENCHMARKS_CPP_RAW_RAW_BENCH_H_
|
||||||
|
#define BENCHMARKS_CPP_RAW_RAW_BENCH_H_
|
||||||
|
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
|
#include "benchmarks/cpp/bench.h"
|
||||||
|
|
||||||
|
std::unique_ptr<Bench> NewRawBench();
|
||||||
|
|
||||||
|
#endif // BENCHMARKS_CPP_RAW_RAW_BENCH_H_
|
||||||
@@ -13,6 +13,7 @@ DEFAULT_INCLUDE_PATHS = [
|
|||||||
"./",
|
"./",
|
||||||
"$(GENDIR)",
|
"$(GENDIR)",
|
||||||
"$(BINDIR)",
|
"$(BINDIR)",
|
||||||
|
"$(execpath @com_github_google_flatbuffers//:flatc).runfiles/com_github_google_flatbuffers",
|
||||||
]
|
]
|
||||||
|
|
||||||
DEFAULT_FLATC_ARGS = [
|
DEFAULT_FLATC_ARGS = [
|
||||||
@@ -37,6 +38,7 @@ def flatbuffer_library_public(
|
|||||||
reflection_visibility = None,
|
reflection_visibility = None,
|
||||||
compatible_with = None,
|
compatible_with = None,
|
||||||
restricted_to = None,
|
restricted_to = None,
|
||||||
|
target_compatible_with = None,
|
||||||
output_to_bindir = False):
|
output_to_bindir = False):
|
||||||
"""Generates code files for reading/writing the given flatbuffers in the requested language using the public compiler.
|
"""Generates code files for reading/writing the given flatbuffers in the requested language using the public compiler.
|
||||||
|
|
||||||
@@ -58,6 +60,8 @@ def flatbuffer_library_public(
|
|||||||
built for, in addition to default-supported environments.
|
built for, in addition to default-supported environments.
|
||||||
restricted_to: Optional, The list of environments this rule can be built
|
restricted_to: Optional, The list of environments this rule can be built
|
||||||
for, instead of default-supported environments.
|
for, instead of default-supported environments.
|
||||||
|
target_compatible_with: Optional, The list of target platform constraints
|
||||||
|
to use.
|
||||||
output_to_bindir: Passed to genrule for output to bin directory.
|
output_to_bindir: Passed to genrule for output to bin directory.
|
||||||
|
|
||||||
|
|
||||||
@@ -92,6 +96,7 @@ def flatbuffer_library_public(
|
|||||||
tools = [flatc_path],
|
tools = [flatc_path],
|
||||||
cmd = genrule_cmd,
|
cmd = genrule_cmd,
|
||||||
compatible_with = compatible_with,
|
compatible_with = compatible_with,
|
||||||
|
target_compatible_with = target_compatible_with,
|
||||||
restricted_to = restricted_to,
|
restricted_to = restricted_to,
|
||||||
message = "Generating flatbuffer files for %s:" % (name),
|
message = "Generating flatbuffer files for %s:" % (name),
|
||||||
)
|
)
|
||||||
@@ -120,8 +125,10 @@ def flatbuffer_library_public(
|
|||||||
tools = [flatc_path],
|
tools = [flatc_path],
|
||||||
compatible_with = compatible_with,
|
compatible_with = compatible_with,
|
||||||
restricted_to = restricted_to,
|
restricted_to = restricted_to,
|
||||||
|
target_compatible_with = target_compatible_with,
|
||||||
cmd = reflection_genrule_cmd,
|
cmd = reflection_genrule_cmd,
|
||||||
message = "Generating flatbuffer reflection binary for %s:" % (name),
|
message = "Generating flatbuffer reflection binary for %s:" % (name),
|
||||||
|
visibility = reflection_visibility,
|
||||||
)
|
)
|
||||||
native.filegroup(
|
native.filegroup(
|
||||||
name = "%s_out" % reflection_name,
|
name = "%s_out" % reflection_name,
|
||||||
@@ -136,15 +143,18 @@ def flatbuffer_cc_library(
|
|||||||
srcs,
|
srcs,
|
||||||
srcs_filegroup_name = "",
|
srcs_filegroup_name = "",
|
||||||
out_prefix = "",
|
out_prefix = "",
|
||||||
|
deps = [],
|
||||||
includes = [],
|
includes = [],
|
||||||
include_paths = DEFAULT_INCLUDE_PATHS,
|
include_paths = DEFAULT_INCLUDE_PATHS,
|
||||||
|
cc_include_paths = [],
|
||||||
flatc_args = DEFAULT_FLATC_ARGS,
|
flatc_args = DEFAULT_FLATC_ARGS,
|
||||||
visibility = None,
|
visibility = None,
|
||||||
compatible_with = None,
|
compatible_with = None,
|
||||||
restricted_to = None,
|
restricted_to = None,
|
||||||
|
target_compatible_with = None,
|
||||||
srcs_filegroup_visibility = None,
|
srcs_filegroup_visibility = None,
|
||||||
gen_reflections = False):
|
gen_reflections = False):
|
||||||
'''A cc_library with the generated reader/writers for the given flatbuffer definitions.
|
"""A cc_library with the generated reader/writers for the given flatbuffer definitions.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
name: Rule name.
|
name: Rule name.
|
||||||
@@ -154,9 +164,12 @@ def flatbuffer_cc_library(
|
|||||||
flatbuffer_cc_library that depends on this one's schemas.
|
flatbuffer_cc_library that depends on this one's schemas.
|
||||||
out_prefix: Prepend this path to the front of all generated files. Usually
|
out_prefix: Prepend this path to the front of all generated files. Usually
|
||||||
is a directory name.
|
is a directory name.
|
||||||
|
deps: Optional, list of other flatbuffer_cc_library's to depend on. Cannot be specified
|
||||||
|
alongside includes.
|
||||||
includes: Optional, list of filegroups of schemas that the srcs depend on.
|
includes: Optional, list of filegroups of schemas that the srcs depend on.
|
||||||
** SEE REMARKS BELOW **
|
Use of this is discouraged, and may be deprecated.
|
||||||
include_paths: Optional, list of paths the includes files can be found in.
|
include_paths: Optional, list of paths the includes files can be found in.
|
||||||
|
cc_include_paths: Optional, list of paths to add to the cc_library includes attribute.
|
||||||
flatc_args: Optional list of additional arguments to pass to flatc
|
flatc_args: Optional list of additional arguments to pass to flatc
|
||||||
(e.g. --gen-mutable).
|
(e.g. --gen-mutable).
|
||||||
visibility: The visibility of the generated cc_library. By default, use the
|
visibility: The visibility of the generated cc_library. By default, use the
|
||||||
@@ -169,6 +182,8 @@ def flatbuffer_cc_library(
|
|||||||
for, in addition to default-supported environments.
|
for, in addition to default-supported environments.
|
||||||
restricted_to: Optional, The list of environments this rule can be built
|
restricted_to: Optional, The list of environments this rule can be built
|
||||||
for, instead of default-supported environments.
|
for, instead of default-supported environments.
|
||||||
|
target_compatible_with: Optional, The list of target platform constraints
|
||||||
|
to use.
|
||||||
|
|
||||||
This produces:
|
This produces:
|
||||||
filegroup([name]_srcs): all generated .h files.
|
filegroup([name]_srcs): all generated .h files.
|
||||||
@@ -177,41 +192,17 @@ def flatbuffer_cc_library(
|
|||||||
parameter, if they depend on the schemas in this library.
|
parameter, if they depend on the schemas in this library.
|
||||||
Fileset([name]_reflection): (Optional) all generated reflection binaries.
|
Fileset([name]_reflection): (Optional) all generated reflection binaries.
|
||||||
cc_library([name]): library with sources and flatbuffers deps.
|
cc_library([name]): library with sources and flatbuffers deps.
|
||||||
|
"""
|
||||||
Remarks:
|
|
||||||
** Because the genrule used to call flatc does not have any trivial way of
|
|
||||||
computing the output list of files transitively generated by includes and
|
|
||||||
--gen-includes (the default) being defined for flatc, the --gen-includes
|
|
||||||
flag will not work as expected. The way around this is to add a dependency
|
|
||||||
to the flatbuffer_cc_library defined alongside the flatc included Fileset.
|
|
||||||
For example you might define:
|
|
||||||
|
|
||||||
flatbuffer_cc_library(
|
|
||||||
name = "my_fbs",
|
|
||||||
srcs = [ "schemas/foo.fbs" ],
|
|
||||||
includes = [ "//third_party/bazz:bazz_fbs_includes" ],
|
|
||||||
)
|
|
||||||
|
|
||||||
In which foo.fbs includes a few files from the Fileset defined at
|
|
||||||
//third_party/bazz:bazz_fbs_includes. When compiling the library that
|
|
||||||
includes foo_generated.h, and therefore has my_fbs as a dependency, it
|
|
||||||
will fail to find any of the bazz *_generated.h files unless you also
|
|
||||||
add bazz's flatbuffer_cc_library to your own dependency list, e.g.:
|
|
||||||
|
|
||||||
cc_library(
|
|
||||||
name = "my_lib",
|
|
||||||
deps = [
|
|
||||||
":my_fbs",
|
|
||||||
"//third_party/bazz:bazz_fbs"
|
|
||||||
],
|
|
||||||
)
|
|
||||||
|
|
||||||
Happy dependent Flatbuffering!
|
|
||||||
'''
|
|
||||||
output_headers = [
|
output_headers = [
|
||||||
(out_prefix + "%s_generated.h") % (s.replace(".fbs", "").split("/")[-1])
|
(out_prefix + "%s_generated.h") % (s.replace(".fbs", "").split("/")[-1].split(":")[-1])
|
||||||
for s in srcs
|
for s in srcs
|
||||||
]
|
]
|
||||||
|
if deps and includes:
|
||||||
|
# There is no inherent reason we couldn't support both, but this discourages
|
||||||
|
# use of includes without good reason.
|
||||||
|
fail("Cannot specify both deps and include in flatbuffer_cc_library.")
|
||||||
|
if deps:
|
||||||
|
includes = [d + "_includes" for d in deps]
|
||||||
reflection_name = "%s_reflection" % name if gen_reflections else ""
|
reflection_name = "%s_reflection" % name if gen_reflections else ""
|
||||||
|
|
||||||
srcs_lib = "%s_srcs" % (name)
|
srcs_lib = "%s_srcs" % (name)
|
||||||
@@ -226,6 +217,7 @@ def flatbuffer_cc_library(
|
|||||||
flatc_args = flatc_args,
|
flatc_args = flatc_args,
|
||||||
compatible_with = compatible_with,
|
compatible_with = compatible_with,
|
||||||
restricted_to = restricted_to,
|
restricted_to = restricted_to,
|
||||||
|
target_compatible_with = target_compatible_with,
|
||||||
reflection_name = reflection_name,
|
reflection_name = reflection_name,
|
||||||
reflection_visibility = visibility,
|
reflection_visibility = visibility,
|
||||||
)
|
)
|
||||||
@@ -242,10 +234,12 @@ def flatbuffer_cc_library(
|
|||||||
],
|
],
|
||||||
deps = [
|
deps = [
|
||||||
"@com_github_google_flatbuffers//:runtime_cc",
|
"@com_github_google_flatbuffers//:runtime_cc",
|
||||||
],
|
"@com_github_google_flatbuffers//:flatbuffers",
|
||||||
includes = [],
|
] + deps,
|
||||||
|
includes = cc_include_paths,
|
||||||
compatible_with = compatible_with,
|
compatible_with = compatible_with,
|
||||||
restricted_to = restricted_to,
|
restricted_to = restricted_to,
|
||||||
|
target_compatible_with = target_compatible_with,
|
||||||
linkstatic = 1,
|
linkstatic = 1,
|
||||||
visibility = visibility,
|
visibility = visibility,
|
||||||
)
|
)
|
||||||
@@ -254,7 +248,7 @@ def flatbuffer_cc_library(
|
|||||||
# Flatbuffer set.
|
# Flatbuffer set.
|
||||||
native.filegroup(
|
native.filegroup(
|
||||||
name = srcs_filegroup_name if srcs_filegroup_name else "%s_includes" % (name),
|
name = srcs_filegroup_name if srcs_filegroup_name else "%s_includes" % (name),
|
||||||
srcs = srcs,
|
srcs = srcs + includes,
|
||||||
compatible_with = compatible_with,
|
compatible_with = compatible_with,
|
||||||
restricted_to = restricted_to,
|
restricted_to = restricted_to,
|
||||||
visibility = srcs_filegroup_visibility if srcs_filegroup_visibility != None else visibility,
|
visibility = srcs_filegroup_visibility if srcs_filegroup_visibility != None else visibility,
|
||||||
|
|||||||
@@ -5,8 +5,8 @@ message(STATUS "Conan FlatBuffers Wrapper")
|
|||||||
include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
|
include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
|
||||||
conan_basic_setup()
|
conan_basic_setup()
|
||||||
|
|
||||||
if (WIN32 AND MSVC AND FLATBUFFERS_BUILD_SHAREDLIB)
|
if (WIN32 AND MSVC_LIKE AND FLATBUFFERS_BUILD_SHAREDLIB)
|
||||||
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)
|
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)
|
||||||
endif(WIN32 AND MSVC AND FLATBUFFERS_BUILD_SHAREDLIB)
|
endif(WIN32 AND MSVC_LIKE AND FLATBUFFERS_BUILD_SHAREDLIB)
|
||||||
|
|
||||||
include(${CMAKE_SOURCE_DIR}/CMakeListsOriginal.txt)
|
include(${CMAKE_SOURCE_DIR}/CMakeListsOriginal.txt)
|
||||||
|
|||||||
@@ -6,16 +6,6 @@ import subprocess
|
|||||||
from cpt.packager import ConanMultiPackager
|
from cpt.packager import ConanMultiPackager
|
||||||
|
|
||||||
|
|
||||||
def set_appveyor_environment():
|
|
||||||
if os.getenv("APPVEYOR") is not None:
|
|
||||||
compiler_version = os.getenv("CMAKE_VS_VERSION").split(" ")[0].replace('"', '')
|
|
||||||
os.environ["CONAN_VISUAL_VERSIONS"] = compiler_version
|
|
||||||
os.environ["CONAN_STABLE_BRANCH_PATTERN"] = "master"
|
|
||||||
ci_platform = os.getenv("Platform").replace('"', '')
|
|
||||||
ci_platform = "x86" if ci_platform == "x86" else "x86_64"
|
|
||||||
os.environ["CONAN_ARCHS"] = ci_platform
|
|
||||||
os.environ["CONAN_BUILD_TYPES"] = os.getenv("Configuration").replace('"', '')
|
|
||||||
|
|
||||||
|
|
||||||
def get_branch():
|
def get_branch():
|
||||||
try:
|
try:
|
||||||
@@ -56,7 +46,6 @@ if __name__ == "__main__":
|
|||||||
stable_branch_pattern = os.getenv("CONAN_STABLE_BRANCH_PATTERN", r"v\d+\.\d+\.\d+.*")
|
stable_branch_pattern = os.getenv("CONAN_STABLE_BRANCH_PATTERN", r"v\d+\.\d+\.\d+.*")
|
||||||
test_folder = os.getenv("CPT_TEST_FOLDER", os.path.join("conan", "test_package"))
|
test_folder = os.getenv("CPT_TEST_FOLDER", os.path.join("conan", "test_package"))
|
||||||
upload_only_when_stable = os.getenv("CONAN_UPLOAD_ONLY_WHEN_STABLE", True)
|
upload_only_when_stable = os.getenv("CONAN_UPLOAD_ONLY_WHEN_STABLE", True)
|
||||||
set_appveyor_environment()
|
|
||||||
|
|
||||||
builder = ConanMultiPackager(reference=get_reference(username),
|
builder = ConanMultiPackager(reference=get_reference(username),
|
||||||
username=username,
|
username=username,
|
||||||
|
|||||||
@@ -1,4 +1,22 @@
|
|||||||
# CHANGELOG
|
## 2.0.5
|
||||||
|
|
||||||
|
- switch to null safety (#6696)
|
||||||
|
- add Object APIs (pack/unpack) (#6682, #6723, #6846)
|
||||||
|
- add custom builder buffer allocator support (#6711)
|
||||||
|
- add `Builder.size()` - finished buffer size (#6403)
|
||||||
|
- make `writeString()` argument non-nullable (#6737)
|
||||||
|
- make tables fixed size (expect the number of fields when creating) (#6735)
|
||||||
|
- make table deduplication optional (param `deduplicateTables`) (#6734)
|
||||||
|
- change `Builder.reset()` to reuse an existing buffer (#6661)
|
||||||
|
- change table building to assert() instead of exceptions (#6754)
|
||||||
|
- optimize `writeString()` for ASCII (param `asciiOptimization`) (#6736)
|
||||||
|
- change `StringReader` to make ASCII optimization optional (param `asciiOptimization`) (#6758)
|
||||||
|
- change `[byte]` and `[ubyte]` representation to `dart:typed_data` `Int8List` and `Uint8List` (#6839)
|
||||||
|
- rename `lowFinish()` to `buffer` getter (#6712)
|
||||||
|
- fix `Builder._writeString()` - always write trailing zero byte (#6390)
|
||||||
|
- fix `Builder.reset()` - clear vTables (#6386)
|
||||||
|
- make sure added padding is zeroed, same as in C++ (#6716)
|
||||||
|
- many performance improvements (#6755)
|
||||||
|
|
||||||
## 1.9.2
|
## 1.9.2
|
||||||
|
|
||||||
@@ -11,4 +29,4 @@
|
|||||||
|
|
||||||
## 1.9.0
|
## 1.9.0
|
||||||
|
|
||||||
- Initial release, supports Dart 1.x and many dev versions of Dart 2.x
|
- Initial release, supports Dart 1.x and many dev versions of Dart 2.x
|
||||||
|
|||||||
32
dart/LICENSE
@@ -1,35 +1,3 @@
|
|||||||
The code in lib/flat_buffers.dart is based on code that was releases under the
|
|
||||||
following license:
|
|
||||||
|
|
||||||
Copyright 2012, the Dart project authors. All rights reserved.
|
|
||||||
Redistribution and use in source and binary forms, with or without
|
|
||||||
modification, are permitted provided that the following conditions are
|
|
||||||
met:
|
|
||||||
* Redistributions of source code must retain the above copyright
|
|
||||||
notice, this list of conditions and the following disclaimer.
|
|
||||||
* Redistributions in binary form must reproduce the above
|
|
||||||
copyright notice, this list of conditions and the following
|
|
||||||
disclaimer in the documentation and/or other materials provided
|
|
||||||
with the distribution.
|
|
||||||
* Neither the name of Google Inc. nor the names of its
|
|
||||||
contributors may be used to endorse or promote products derived
|
|
||||||
from this software without specific prior written permission.
|
|
||||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
||||||
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
||||||
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
||||||
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
||||||
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
||||||
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
||||||
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
||||||
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
||||||
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
||||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
||||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
||||||
|
|
||||||
To the extent permissible, the changes to that code and the other assets in
|
|
||||||
this package are licensed under the Apache2 license:
|
|
||||||
|
|
||||||
|
|
||||||
Apache License
|
Apache License
|
||||||
Version 2.0, January 2004
|
Version 2.0, January 2004
|
||||||
http://www.apache.org/licenses/
|
http://www.apache.org/licenses/
|
||||||
|
|||||||
@@ -1,13 +1,23 @@
|
|||||||
# FlatBuffers for Dart
|
# FlatBuffers for Dart
|
||||||
|
|
||||||
This package is used to read and write FlatBuffer files in Dart.
|
This package is used to read and write [FlatBuffers](https://google.github.io/flatbuffers/).
|
||||||
|
|
||||||
Most consumers will want to use the [`flatc`](https://github.com/google/flatbuffers)
|
Most consumers will want to use the [`flatc` - FlatBuffer compiler](https://github.com/google/flatbuffers) binary for your platform.
|
||||||
compiler to generate Dart code from a FlatBuffers IDL schema. For example, the
|
You can find it in the `generator/{Platform}` directory of the [released package archive](https://pub.dev/packages/flat_buffers/versions/2.0.5.tar.gz).
|
||||||
`monster_my_game.sample_generated.dart` was generated with `flatc` from
|
|
||||||
`monster.fbs` in the example folder. The generated classes can be used to read
|
The FlatBuffer compiler `flatc` reads a FlatBuffers IDL schema and generates Dart code.
|
||||||
or write binary files that are interoperable with other languages and platforms
|
The generated classes can be used to read or write binary data/files that are interoperable with
|
||||||
supported by FlatBuffers, as illustrated in the `example.dart` in the
|
other languages and platforms supported by FlatBuffers, as illustrated in the `example.dart` in the
|
||||||
examples folder.
|
examples folder.
|
||||||
|
|
||||||
Additional documentation and examples are available [at the FlatBuffers site](https://google.github.io/flatbuffers/index.html)
|
For more details and documentation, head over to the official site and read the
|
||||||
|
[Tutorial](https://google.github.io/flatbuffers/flatbuffers_guide_tutorial.html) and how to
|
||||||
|
[use FlatBuffers in Dart](https://google.github.io/flatbuffers/flatbuffers_guide_use_dart.html).
|
||||||
|
|
||||||
|
## Dart 2.0 notes
|
||||||
|
Version 2.0.5 ships with it's own custom build of `flatc` because this is an extraordinary release to catch-up
|
||||||
|
with FlatBuffers for other platforms. This generator can only generate dart code (to avoid generating code for other platforms which isn't released yet).
|
||||||
|
On the other hand, the generated code still produces standard binary FlatBuffers compatible with other languages.
|
||||||
|
In other words: only `flatc --dart ...` works with this generator, but your app will be able to produce and read standard binary (`Uint8List`) FlatBuffers that are fully compotible with other languages supporting FlatBuffers (e.g. Java, C++, ...).
|
||||||
|
|
||||||
|
In the future a common `flatc` binary for all platforms would be shipped through GitHub release page instead.
|
||||||
|
|||||||
1
dart/analysis_options.yaml
Normal file
@@ -0,0 +1 @@
|
|||||||
|
include: package:lints/recommended.yaml
|
||||||
@@ -15,7 +15,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import 'package:flat_buffers/flat_buffers.dart' as fb;
|
import 'package:flat_buffers/flat_buffers.dart' as fb;
|
||||||
import './monster_my_game.sample_generated.dart' as myGame;
|
import './monster_my_game.sample_generated.dart' as my_game;
|
||||||
|
|
||||||
// Example how to use FlatBuffers to create and read binary buffers.
|
// Example how to use FlatBuffers to create and read binary buffers.
|
||||||
|
|
||||||
@@ -25,27 +25,27 @@ void main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void builderTest() {
|
void builderTest() {
|
||||||
final builder = new fb.Builder(initialSize: 1024);
|
final builder = fb.Builder(initialSize: 1024);
|
||||||
final int weaponOneName = builder.writeString("Sword");
|
final int? weaponOneName = builder.writeString("Sword");
|
||||||
final int weaponOneDamage = 3;
|
final int weaponOneDamage = 3;
|
||||||
|
|
||||||
final int weaponTwoName = builder.writeString("Axe");
|
final int? weaponTwoName = builder.writeString("Axe");
|
||||||
final int weaponTwoDamage = 5;
|
final int weaponTwoDamage = 5;
|
||||||
|
|
||||||
final swordBuilder = new myGame.WeaponBuilder(builder)
|
final swordBuilder = my_game.WeaponBuilder(builder)
|
||||||
..begin()
|
..begin()
|
||||||
..addNameOffset(weaponOneName)
|
..addNameOffset(weaponOneName)
|
||||||
..addDamage(weaponOneDamage);
|
..addDamage(weaponOneDamage);
|
||||||
final int sword = swordBuilder.finish();
|
final int sword = swordBuilder.finish();
|
||||||
|
|
||||||
final axeBuilder = new myGame.WeaponBuilder(builder)
|
final axeBuilder = my_game.WeaponBuilder(builder)
|
||||||
..begin()
|
..begin()
|
||||||
..addNameOffset(weaponTwoName)
|
..addNameOffset(weaponTwoName)
|
||||||
..addDamage(weaponTwoDamage);
|
..addDamage(weaponTwoDamage);
|
||||||
final int axe = axeBuilder.finish();
|
final int axe = axeBuilder.finish();
|
||||||
|
|
||||||
// Serialize a name for our monster, called "Orc".
|
// Serialize a name for our monster, called "Orc".
|
||||||
final int name = builder.writeString('Orc');
|
final int? name = builder.writeString('Orc');
|
||||||
|
|
||||||
// Create a list representing the inventory of the Orc. Each number
|
// Create a list representing the inventory of the Orc. Each number
|
||||||
// could correspond to an item that can be claimed after he is slain.
|
// could correspond to an item that can be claimed after he is slain.
|
||||||
@@ -54,7 +54,7 @@ void builderTest() {
|
|||||||
final weapons = builder.writeList([sword, axe]);
|
final weapons = builder.writeList([sword, axe]);
|
||||||
|
|
||||||
// Struct builders are very easy to reuse.
|
// Struct builders are very easy to reuse.
|
||||||
final vec3Builder = new myGame.Vec3Builder(builder);
|
final vec3Builder = my_game.Vec3Builder(builder);
|
||||||
|
|
||||||
vec3Builder.finish(4.0, 5.0, 6.0);
|
vec3Builder.finish(4.0, 5.0, 6.0);
|
||||||
vec3Builder.finish(1.0, 2.0, 3.0);
|
vec3Builder.finish(1.0, 2.0, 3.0);
|
||||||
@@ -62,21 +62,21 @@ void builderTest() {
|
|||||||
final int hp = 300;
|
final int hp = 300;
|
||||||
final int mana = 150;
|
final int mana = 150;
|
||||||
|
|
||||||
final monster = new myGame.MonsterBuilder(builder)
|
final monster = my_game.MonsterBuilder(builder)
|
||||||
..begin()
|
..begin()
|
||||||
..addNameOffset(name)
|
..addNameOffset(name)
|
||||||
..addInventoryOffset(inventory)
|
..addInventoryOffset(inventory)
|
||||||
..addWeaponsOffset(weapons)
|
..addWeaponsOffset(weapons)
|
||||||
..addEquippedType(myGame.EquipmentTypeId.Weapon)
|
..addEquippedType(my_game.EquipmentTypeId.Weapon)
|
||||||
..addEquippedOffset(axe)
|
..addEquippedOffset(axe)
|
||||||
..addHp(hp)
|
..addHp(hp)
|
||||||
..addMana(mana)
|
..addMana(mana)
|
||||||
..addPos(vec3Builder.finish(1.0, 2.0, 3.0))
|
..addPos(vec3Builder.finish(1.0, 2.0, 3.0))
|
||||||
..addColor(myGame.Color.Red);
|
..addColor(my_game.Color.Red);
|
||||||
|
|
||||||
final int monsteroff = monster.finish();
|
final int monsteroff = monster.finish();
|
||||||
final buffer = builder.finish(monsteroff);
|
builder.finish(monsteroff);
|
||||||
if (verify(buffer)) {
|
if (verify(builder.buffer)) {
|
||||||
print(
|
print(
|
||||||
"The FlatBuffer was successfully created with a builder and verified!");
|
"The FlatBuffer was successfully created with a builder and verified!");
|
||||||
}
|
}
|
||||||
@@ -85,17 +85,17 @@ void builderTest() {
|
|||||||
void objectBuilderTest() {
|
void objectBuilderTest() {
|
||||||
// Create the builder here so we can use it for both weapons and equipped
|
// Create the builder here so we can use it for both weapons and equipped
|
||||||
// the actual data will only be written to the buffer once.
|
// the actual data will only be written to the buffer once.
|
||||||
var axe = new myGame.WeaponObjectBuilder(name: 'Axe', damage: 5);
|
var axe = my_game.WeaponObjectBuilder(name: 'Axe', damage: 5);
|
||||||
|
|
||||||
var monsterBuilder = new myGame.MonsterObjectBuilder(
|
var monsterBuilder = my_game.MonsterObjectBuilder(
|
||||||
pos: new myGame.Vec3ObjectBuilder(x: 1.0, y: 2.0, z: 3.0),
|
pos: my_game.Vec3ObjectBuilder(x: 1.0, y: 2.0, z: 3.0),
|
||||||
mana: 150,
|
mana: 150,
|
||||||
hp: 300,
|
hp: 300,
|
||||||
name: 'Orc',
|
name: 'Orc',
|
||||||
inventory: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9],
|
inventory: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9],
|
||||||
color: myGame.Color.Red,
|
color: my_game.Color.Red,
|
||||||
weapons: [new myGame.WeaponObjectBuilder(name: 'Sword', damage: 3), axe],
|
weapons: [my_game.WeaponObjectBuilder(name: 'Sword', damage: 3), axe],
|
||||||
equippedType: myGame.EquipmentTypeId.Weapon,
|
equippedType: my_game.EquipmentTypeId.Weapon,
|
||||||
equipped: axe,
|
equipped: axe,
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -114,7 +114,7 @@ void objectBuilderTest() {
|
|||||||
|
|
||||||
bool verify(List<int> buffer) {
|
bool verify(List<int> buffer) {
|
||||||
// Get access to the root:
|
// Get access to the root:
|
||||||
var monster = new myGame.Monster(buffer);
|
var monster = my_game.Monster(buffer);
|
||||||
|
|
||||||
// Get and test some scalar types from the FlatBuffer.
|
// Get and test some scalar types from the FlatBuffer.
|
||||||
assert(monster.hp == 80);
|
assert(monster.hp == 80);
|
||||||
@@ -122,31 +122,29 @@ bool verify(List<int> buffer) {
|
|||||||
assert(monster.name == "MyMonster");
|
assert(monster.name == "MyMonster");
|
||||||
|
|
||||||
// Get and test a field of the FlatBuffer's `struct`.
|
// Get and test a field of the FlatBuffer's `struct`.
|
||||||
var pos = monster.pos;
|
var pos = monster.pos!;
|
||||||
assert(pos != null);
|
|
||||||
assert(pos.z == 3.0);
|
assert(pos.z == 3.0);
|
||||||
|
|
||||||
// Get a test an element from the `inventory` FlatBuffer's `vector`.
|
// Get a test an element from the `inventory` FlatBuffer's `vector`.
|
||||||
var inv = monster.inventory;
|
var inv = monster.inventory!;
|
||||||
assert(inv != null);
|
|
||||||
assert(inv.length == 10);
|
assert(inv.length == 10);
|
||||||
assert(inv[9] == 9);
|
assert(inv[9] == 9);
|
||||||
|
|
||||||
// Get and test the `weapons` FlatBuffers's `vector`.
|
// Get and test the `weapons` FlatBuffers's `vector`.
|
||||||
var expected_weapon_names = ["Sword", "Axe"];
|
var expectedWeaponNames = ["Sword", "Axe"];
|
||||||
var expected_weapon_damages = [3, 5];
|
var expectedWeaponDamages = [3, 5];
|
||||||
var weps = monster.weapons;
|
var weps = monster.weapons!;
|
||||||
for (int i = 0; i < weps.length; i++) {
|
for (int i = 0; i < weps.length; i++) {
|
||||||
assert(weps[i].name == expected_weapon_names[i]);
|
assert(weps[i].name == expectedWeaponNames[i]);
|
||||||
assert(weps[i].damage == expected_weapon_damages[i]);
|
assert(weps[i].damage == expectedWeaponDamages[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get and test the `Equipment` union (`equipped` field).
|
// Get and test the `Equipment` union (`equipped` field).
|
||||||
assert(monster.equippedType.value == myGame.EquipmentTypeId.Weapon.value);
|
assert(monster.equippedType!.value == my_game.EquipmentTypeId.Weapon.value);
|
||||||
assert(monster.equippedType == myGame.EquipmentTypeId.Weapon);
|
assert(monster.equippedType == my_game.EquipmentTypeId.Weapon);
|
||||||
|
|
||||||
assert(monster.equipped is myGame.Weapon);
|
assert(monster.equipped is my_game.Weapon);
|
||||||
var equipped = monster.equipped as myGame.Weapon;
|
var equipped = monster.equipped as my_game.Weapon;
|
||||||
assert(equipped.name == "Axe");
|
assert(equipped.name == "Axe");
|
||||||
assert(equipped.damage == 5);
|
assert(equipped.damage == 5);
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
// automatically generated by the FlatBuffers compiler, do not modify
|
// automatically generated by the FlatBuffers compiler, do not modify
|
||||||
// ignore_for_file: unused_import, non_constant_identifier_names
|
// ignore_for_file: unused_import, unused_field, unused_element, unused_local_variable
|
||||||
|
|
||||||
library my_game.sample;
|
library my_game.sample;
|
||||||
|
|
||||||
@@ -12,23 +12,29 @@ class Color {
|
|||||||
const Color._(this.value);
|
const Color._(this.value);
|
||||||
|
|
||||||
factory Color.fromValue(int value) {
|
factory Color.fromValue(int value) {
|
||||||
if (value == null) return null;
|
final result = values[value];
|
||||||
if (!values.containsKey(value)) {
|
if (result == null) {
|
||||||
throw new StateError('Invalid value $value for bit flag enum Color');
|
throw StateError('Invalid value $value for bit flag enum Color');
|
||||||
}
|
}
|
||||||
return values[value];
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static Color? _createOrNull(int? value) =>
|
||||||
|
value == null ? null : Color.fromValue(value);
|
||||||
|
|
||||||
static const int minValue = 0;
|
static const int minValue = 0;
|
||||||
static const int maxValue = 2;
|
static const int maxValue = 2;
|
||||||
static bool containsValue(int value) => values.containsKey(value);
|
static bool containsValue(int value) => values.containsKey(value);
|
||||||
|
|
||||||
static const Color Red = const Color._(0);
|
static const Color Red = Color._(0);
|
||||||
static const Color Green = const Color._(1);
|
static const Color Green = Color._(1);
|
||||||
static const Color Blue = const Color._(2);
|
static const Color Blue = Color._(2);
|
||||||
static get values => {0: Red,1: Green,2: Blue,};
|
static const Map<int, Color> values = {
|
||||||
|
0: Red,
|
||||||
|
1: Green,
|
||||||
|
2: Blue};
|
||||||
|
|
||||||
static const fb.Reader<Color> reader = const _ColorReader();
|
static const fb.Reader<Color> reader = _ColorReader();
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String toString() {
|
String toString() {
|
||||||
@@ -44,7 +50,7 @@ class _ColorReader extends fb.Reader<Color> {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Color read(fb.BufferContext bc, int offset) =>
|
Color read(fb.BufferContext bc, int offset) =>
|
||||||
new Color.fromValue(const fb.Int8Reader().read(bc, offset));
|
Color.fromValue(const fb.Int8Reader().read(bc, offset));
|
||||||
}
|
}
|
||||||
|
|
||||||
class EquipmentTypeId {
|
class EquipmentTypeId {
|
||||||
@@ -52,22 +58,27 @@ class EquipmentTypeId {
|
|||||||
const EquipmentTypeId._(this.value);
|
const EquipmentTypeId._(this.value);
|
||||||
|
|
||||||
factory EquipmentTypeId.fromValue(int value) {
|
factory EquipmentTypeId.fromValue(int value) {
|
||||||
if (value == null) return null;
|
final result = values[value];
|
||||||
if (!values.containsKey(value)) {
|
if (result == null) {
|
||||||
throw new StateError('Invalid value $value for bit flag enum EquipmentTypeId');
|
throw StateError('Invalid value $value for bit flag enum EquipmentTypeId');
|
||||||
}
|
}
|
||||||
return values[value];
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static EquipmentTypeId? _createOrNull(int? value) =>
|
||||||
|
value == null ? null : EquipmentTypeId.fromValue(value);
|
||||||
|
|
||||||
static const int minValue = 0;
|
static const int minValue = 0;
|
||||||
static const int maxValue = 1;
|
static const int maxValue = 1;
|
||||||
static bool containsValue(int value) => values.containsKey(value);
|
static bool containsValue(int value) => values.containsKey(value);
|
||||||
|
|
||||||
static const EquipmentTypeId NONE = const EquipmentTypeId._(0);
|
static const EquipmentTypeId NONE = EquipmentTypeId._(0);
|
||||||
static const EquipmentTypeId Weapon = const EquipmentTypeId._(1);
|
static const EquipmentTypeId Weapon = EquipmentTypeId._(1);
|
||||||
static get values => {0: NONE,1: Weapon,};
|
static const Map<int, EquipmentTypeId> values = {
|
||||||
|
0: NONE,
|
||||||
|
1: Weapon};
|
||||||
|
|
||||||
static const fb.Reader<EquipmentTypeId> reader = const _EquipmentTypeIdReader();
|
static const fb.Reader<EquipmentTypeId> reader = _EquipmentTypeIdReader();
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String toString() {
|
String toString() {
|
||||||
@@ -83,13 +94,13 @@ class _EquipmentTypeIdReader extends fb.Reader<EquipmentTypeId> {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
EquipmentTypeId read(fb.BufferContext bc, int offset) =>
|
EquipmentTypeId read(fb.BufferContext bc, int offset) =>
|
||||||
new EquipmentTypeId.fromValue(const fb.Uint8Reader().read(bc, offset));
|
EquipmentTypeId.fromValue(const fb.Uint8Reader().read(bc, offset));
|
||||||
}
|
}
|
||||||
|
|
||||||
class Vec3 {
|
class Vec3 {
|
||||||
Vec3._(this._bc, this._bcOffset);
|
Vec3._(this._bc, this._bcOffset);
|
||||||
|
|
||||||
static const fb.Reader<Vec3> reader = const _Vec3Reader();
|
static const fb.Reader<Vec3> reader = _Vec3Reader();
|
||||||
|
|
||||||
final fb.BufferContext _bc;
|
final fb.BufferContext _bc;
|
||||||
final int _bcOffset;
|
final int _bcOffset;
|
||||||
@@ -112,13 +123,11 @@ class _Vec3Reader extends fb.StructReader<Vec3> {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Vec3 createObject(fb.BufferContext bc, int offset) =>
|
Vec3 createObject(fb.BufferContext bc, int offset) =>
|
||||||
new Vec3._(bc, offset);
|
Vec3._(bc, offset);
|
||||||
}
|
}
|
||||||
|
|
||||||
class Vec3Builder {
|
class Vec3Builder {
|
||||||
Vec3Builder(this.fbBuilder) {
|
Vec3Builder(this.fbBuilder);
|
||||||
assert(fbBuilder != null);
|
|
||||||
}
|
|
||||||
|
|
||||||
final fb.Builder fbBuilder;
|
final fb.Builder fbBuilder;
|
||||||
|
|
||||||
@@ -137,9 +146,9 @@ class Vec3ObjectBuilder extends fb.ObjectBuilder {
|
|||||||
final double _z;
|
final double _z;
|
||||||
|
|
||||||
Vec3ObjectBuilder({
|
Vec3ObjectBuilder({
|
||||||
double x,
|
required double x,
|
||||||
double y,
|
required double y,
|
||||||
double z,
|
required double z,
|
||||||
})
|
})
|
||||||
: _x = x,
|
: _x = x,
|
||||||
_y = y,
|
_y = y,
|
||||||
@@ -147,10 +156,7 @@ class Vec3ObjectBuilder extends fb.ObjectBuilder {
|
|||||||
|
|
||||||
/// Finish building, and store into the [fbBuilder].
|
/// Finish building, and store into the [fbBuilder].
|
||||||
@override
|
@override
|
||||||
int finish(
|
int finish(fb.Builder fbBuilder) {
|
||||||
fb.Builder fbBuilder) {
|
|
||||||
assert(fbBuilder != null);
|
|
||||||
|
|
||||||
fbBuilder.putFloat32(_z);
|
fbBuilder.putFloat32(_z);
|
||||||
fbBuilder.putFloat32(_y);
|
fbBuilder.putFloat32(_y);
|
||||||
fbBuilder.putFloat32(_x);
|
fbBuilder.putFloat32(_x);
|
||||||
@@ -159,39 +165,39 @@ class Vec3ObjectBuilder extends fb.ObjectBuilder {
|
|||||||
|
|
||||||
/// Convenience method to serialize to byte list.
|
/// Convenience method to serialize to byte list.
|
||||||
@override
|
@override
|
||||||
Uint8List toBytes([String fileIdentifier]) {
|
Uint8List toBytes([String? fileIdentifier]) {
|
||||||
fb.Builder fbBuilder = new fb.Builder();
|
final fbBuilder = fb.Builder(deduplicateTables: false);
|
||||||
int offset = finish(fbBuilder);
|
fbBuilder.finish(finish(fbBuilder), fileIdentifier);
|
||||||
return fbBuilder.finish(offset, fileIdentifier);
|
return fbBuilder.buffer;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
class Monster {
|
class Monster {
|
||||||
Monster._(this._bc, this._bcOffset);
|
Monster._(this._bc, this._bcOffset);
|
||||||
factory Monster(List<int> bytes) {
|
factory Monster(List<int> bytes) {
|
||||||
fb.BufferContext rootRef = new fb.BufferContext.fromBytes(bytes);
|
final rootRef = fb.BufferContext.fromBytes(bytes);
|
||||||
return reader.read(rootRef, 0);
|
return reader.read(rootRef, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
static const fb.Reader<Monster> reader = const _MonsterReader();
|
static const fb.Reader<Monster> reader = _MonsterReader();
|
||||||
|
|
||||||
final fb.BufferContext _bc;
|
final fb.BufferContext _bc;
|
||||||
final int _bcOffset;
|
final int _bcOffset;
|
||||||
|
|
||||||
Vec3 get pos => Vec3.reader.vTableGet(_bc, _bcOffset, 4, null);
|
Vec3? get pos => Vec3.reader.vTableGetNullable(_bc, _bcOffset, 4);
|
||||||
int get mana => const fb.Int16Reader().vTableGet(_bc, _bcOffset, 6, 150);
|
int get mana => const fb.Int16Reader().vTableGet(_bc, _bcOffset, 6, 150);
|
||||||
int get hp => const fb.Int16Reader().vTableGet(_bc, _bcOffset, 8, 100);
|
int get hp => const fb.Int16Reader().vTableGet(_bc, _bcOffset, 8, 100);
|
||||||
String get name => const fb.StringReader().vTableGet(_bc, _bcOffset, 10, null);
|
String? get name => const fb.StringReader().vTableGetNullable(_bc, _bcOffset, 10);
|
||||||
List<int> get inventory => const fb.ListReader<int>(const fb.Uint8Reader()).vTableGet(_bc, _bcOffset, 14, null);
|
List<int>? get inventory => const fb.Uint8ListReader().vTableGetNullable(_bc, _bcOffset, 14);
|
||||||
Color get color => new Color.fromValue(const fb.Int8Reader().vTableGet(_bc, _bcOffset, 16, 2));
|
Color get color => Color.fromValue(const fb.Int8Reader().vTableGet(_bc, _bcOffset, 16, 2));
|
||||||
List<Weapon> get weapons => const fb.ListReader<Weapon>(Weapon.reader).vTableGet(_bc, _bcOffset, 18, null);
|
List<Weapon>? get weapons => const fb.ListReader<Weapon>(Weapon.reader).vTableGetNullable(_bc, _bcOffset, 18);
|
||||||
EquipmentTypeId get equippedType => new EquipmentTypeId.fromValue(const fb.Uint8Reader().vTableGet(_bc, _bcOffset, 20, null));
|
EquipmentTypeId? get equippedType => EquipmentTypeId._createOrNull(const fb.Uint8Reader().vTableGetNullable(_bc, _bcOffset, 20));
|
||||||
dynamic get equipped {
|
dynamic get equipped {
|
||||||
switch (equippedType?.value) {
|
switch (equippedType?.value) {
|
||||||
case 1: return Weapon.reader.vTableGet(_bc, _bcOffset, 22, null);
|
case 1: return Weapon.reader.vTableGetNullable(_bc, _bcOffset, 22);
|
||||||
default: return null;
|
default: return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
List<Vec3> get path => const fb.ListReader<Vec3>(Vec3.reader).vTableGet(_bc, _bcOffset, 24, null);
|
List<Vec3>? get path => const fb.ListReader<Vec3>(Vec3.reader).vTableGetNullable(_bc, _bcOffset, 24);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String toString() {
|
String toString() {
|
||||||
@@ -204,57 +210,55 @@ class _MonsterReader extends fb.TableReader<Monster> {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Monster createObject(fb.BufferContext bc, int offset) =>
|
Monster createObject(fb.BufferContext bc, int offset) =>
|
||||||
new Monster._(bc, offset);
|
Monster._(bc, offset);
|
||||||
}
|
}
|
||||||
|
|
||||||
class MonsterBuilder {
|
class MonsterBuilder {
|
||||||
MonsterBuilder(this.fbBuilder) {
|
MonsterBuilder(this.fbBuilder);
|
||||||
assert(fbBuilder != null);
|
|
||||||
}
|
|
||||||
|
|
||||||
final fb.Builder fbBuilder;
|
final fb.Builder fbBuilder;
|
||||||
|
|
||||||
void begin() {
|
void begin() {
|
||||||
fbBuilder.startTable();
|
fbBuilder.startTable(10);
|
||||||
}
|
}
|
||||||
|
|
||||||
int addPos(int offset) {
|
int addPos(int offset) {
|
||||||
fbBuilder.addStruct(0, offset);
|
fbBuilder.addStruct(0, offset);
|
||||||
return fbBuilder.offset;
|
return fbBuilder.offset;
|
||||||
}
|
}
|
||||||
int addMana(int mana) {
|
int addMana(int? mana) {
|
||||||
fbBuilder.addInt16(1, mana);
|
fbBuilder.addInt16(1, mana);
|
||||||
return fbBuilder.offset;
|
return fbBuilder.offset;
|
||||||
}
|
}
|
||||||
int addHp(int hp) {
|
int addHp(int? hp) {
|
||||||
fbBuilder.addInt16(2, hp);
|
fbBuilder.addInt16(2, hp);
|
||||||
return fbBuilder.offset;
|
return fbBuilder.offset;
|
||||||
}
|
}
|
||||||
int addNameOffset(int offset) {
|
int addNameOffset(int? offset) {
|
||||||
fbBuilder.addOffset(3, offset);
|
fbBuilder.addOffset(3, offset);
|
||||||
return fbBuilder.offset;
|
return fbBuilder.offset;
|
||||||
}
|
}
|
||||||
int addInventoryOffset(int offset) {
|
int addInventoryOffset(int? offset) {
|
||||||
fbBuilder.addOffset(5, offset);
|
fbBuilder.addOffset(5, offset);
|
||||||
return fbBuilder.offset;
|
return fbBuilder.offset;
|
||||||
}
|
}
|
||||||
int addColor(Color color) {
|
int addColor(Color? color) {
|
||||||
fbBuilder.addInt8(6, color?.value);
|
fbBuilder.addInt8(6, color?.value);
|
||||||
return fbBuilder.offset;
|
return fbBuilder.offset;
|
||||||
}
|
}
|
||||||
int addWeaponsOffset(int offset) {
|
int addWeaponsOffset(int? offset) {
|
||||||
fbBuilder.addOffset(7, offset);
|
fbBuilder.addOffset(7, offset);
|
||||||
return fbBuilder.offset;
|
return fbBuilder.offset;
|
||||||
}
|
}
|
||||||
int addEquippedType(EquipmentTypeId equippedType) {
|
int addEquippedType(EquipmentTypeId? equippedType) {
|
||||||
fbBuilder.addUint8(8, equippedType?.value);
|
fbBuilder.addUint8(8, equippedType?.value);
|
||||||
return fbBuilder.offset;
|
return fbBuilder.offset;
|
||||||
}
|
}
|
||||||
int addEquippedOffset(int offset) {
|
int addEquippedOffset(int? offset) {
|
||||||
fbBuilder.addOffset(9, offset);
|
fbBuilder.addOffset(9, offset);
|
||||||
return fbBuilder.offset;
|
return fbBuilder.offset;
|
||||||
}
|
}
|
||||||
int addPathOffset(int offset) {
|
int addPathOffset(int? offset) {
|
||||||
fbBuilder.addOffset(10, offset);
|
fbBuilder.addOffset(10, offset);
|
||||||
return fbBuilder.offset;
|
return fbBuilder.offset;
|
||||||
}
|
}
|
||||||
@@ -265,28 +269,28 @@ class MonsterBuilder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class MonsterObjectBuilder extends fb.ObjectBuilder {
|
class MonsterObjectBuilder extends fb.ObjectBuilder {
|
||||||
final Vec3ObjectBuilder _pos;
|
final Vec3ObjectBuilder? _pos;
|
||||||
final int _mana;
|
final int? _mana;
|
||||||
final int _hp;
|
final int? _hp;
|
||||||
final String _name;
|
final String? _name;
|
||||||
final List<int> _inventory;
|
final List<int>? _inventory;
|
||||||
final Color _color;
|
final Color? _color;
|
||||||
final List<WeaponObjectBuilder> _weapons;
|
final List<WeaponObjectBuilder>? _weapons;
|
||||||
final EquipmentTypeId _equippedType;
|
final EquipmentTypeId? _equippedType;
|
||||||
final dynamic _equipped;
|
final dynamic _equipped;
|
||||||
final List<Vec3ObjectBuilder> _path;
|
final List<Vec3ObjectBuilder>? _path;
|
||||||
|
|
||||||
MonsterObjectBuilder({
|
MonsterObjectBuilder({
|
||||||
Vec3ObjectBuilder pos,
|
Vec3ObjectBuilder? pos,
|
||||||
int mana,
|
int? mana,
|
||||||
int hp,
|
int? hp,
|
||||||
String name,
|
String? name,
|
||||||
List<int> inventory,
|
List<int>? inventory,
|
||||||
Color color,
|
Color? color,
|
||||||
List<WeaponObjectBuilder> weapons,
|
List<WeaponObjectBuilder>? weapons,
|
||||||
EquipmentTypeId equippedType,
|
EquipmentTypeId? equippedType,
|
||||||
dynamic equipped,
|
dynamic equipped,
|
||||||
List<Vec3ObjectBuilder> path,
|
List<Vec3ObjectBuilder>? path,
|
||||||
})
|
})
|
||||||
: _pos = pos,
|
: _pos = pos,
|
||||||
_mana = mana,
|
_mana = mana,
|
||||||
@@ -301,69 +305,54 @@ class MonsterObjectBuilder extends fb.ObjectBuilder {
|
|||||||
|
|
||||||
/// Finish building, and store into the [fbBuilder].
|
/// Finish building, and store into the [fbBuilder].
|
||||||
@override
|
@override
|
||||||
int finish(
|
int finish(fb.Builder fbBuilder) {
|
||||||
fb.Builder fbBuilder) {
|
final int? nameOffset = _name == null ? null
|
||||||
assert(fbBuilder != null);
|
: fbBuilder.writeString(_name!);
|
||||||
final int nameOffset = fbBuilder.writeString(_name);
|
final int? inventoryOffset = _inventory == null ? null
|
||||||
final int inventoryOffset = _inventory?.isNotEmpty == true
|
: fbBuilder.writeListUint8(_inventory!);
|
||||||
? fbBuilder.writeListUint8(_inventory)
|
final int? weaponsOffset = _weapons == null ? null
|
||||||
: null;
|
: fbBuilder.writeList(_weapons!.map((b) => b.getOrCreateOffset(fbBuilder)).toList());
|
||||||
final int weaponsOffset = _weapons?.isNotEmpty == true
|
final int? equippedOffset = _equipped?.getOrCreateOffset(fbBuilder);
|
||||||
? fbBuilder.writeList(_weapons.map((b) => b.getOrCreateOffset(fbBuilder)).toList())
|
final int? pathOffset = _path == null ? null
|
||||||
: null;
|
: fbBuilder.writeListOfStructs(_path!);
|
||||||
final int equippedOffset = _equipped?.getOrCreateOffset(fbBuilder);
|
fbBuilder.startTable(10);
|
||||||
final int pathOffset = _path?.isNotEmpty == true
|
|
||||||
? fbBuilder.writeListOfStructs(_path)
|
|
||||||
: null;
|
|
||||||
|
|
||||||
fbBuilder.startTable();
|
|
||||||
if (_pos != null) {
|
if (_pos != null) {
|
||||||
fbBuilder.addStruct(0, _pos.finish(fbBuilder));
|
fbBuilder.addStruct(0, _pos!.finish(fbBuilder));
|
||||||
}
|
}
|
||||||
fbBuilder.addInt16(1, _mana);
|
fbBuilder.addInt16(1, _mana);
|
||||||
fbBuilder.addInt16(2, _hp);
|
fbBuilder.addInt16(2, _hp);
|
||||||
if (nameOffset != null) {
|
fbBuilder.addOffset(3, nameOffset);
|
||||||
fbBuilder.addOffset(3, nameOffset);
|
fbBuilder.addOffset(5, inventoryOffset);
|
||||||
}
|
|
||||||
if (inventoryOffset != null) {
|
|
||||||
fbBuilder.addOffset(5, inventoryOffset);
|
|
||||||
}
|
|
||||||
fbBuilder.addInt8(6, _color?.value);
|
fbBuilder.addInt8(6, _color?.value);
|
||||||
if (weaponsOffset != null) {
|
fbBuilder.addOffset(7, weaponsOffset);
|
||||||
fbBuilder.addOffset(7, weaponsOffset);
|
|
||||||
}
|
|
||||||
fbBuilder.addUint8(8, _equippedType?.value);
|
fbBuilder.addUint8(8, _equippedType?.value);
|
||||||
if (equippedOffset != null) {
|
fbBuilder.addOffset(9, equippedOffset);
|
||||||
fbBuilder.addOffset(9, equippedOffset);
|
fbBuilder.addOffset(10, pathOffset);
|
||||||
}
|
|
||||||
if (pathOffset != null) {
|
|
||||||
fbBuilder.addOffset(10, pathOffset);
|
|
||||||
}
|
|
||||||
return fbBuilder.endTable();
|
return fbBuilder.endTable();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Convenience method to serialize to byte list.
|
/// Convenience method to serialize to byte list.
|
||||||
@override
|
@override
|
||||||
Uint8List toBytes([String fileIdentifier]) {
|
Uint8List toBytes([String? fileIdentifier]) {
|
||||||
fb.Builder fbBuilder = new fb.Builder();
|
final fbBuilder = fb.Builder(deduplicateTables: false);
|
||||||
int offset = finish(fbBuilder);
|
fbBuilder.finish(finish(fbBuilder), fileIdentifier);
|
||||||
return fbBuilder.finish(offset, fileIdentifier);
|
return fbBuilder.buffer;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
class Weapon {
|
class Weapon {
|
||||||
Weapon._(this._bc, this._bcOffset);
|
Weapon._(this._bc, this._bcOffset);
|
||||||
factory Weapon(List<int> bytes) {
|
factory Weapon(List<int> bytes) {
|
||||||
fb.BufferContext rootRef = new fb.BufferContext.fromBytes(bytes);
|
final rootRef = fb.BufferContext.fromBytes(bytes);
|
||||||
return reader.read(rootRef, 0);
|
return reader.read(rootRef, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
static const fb.Reader<Weapon> reader = const _WeaponReader();
|
static const fb.Reader<Weapon> reader = _WeaponReader();
|
||||||
|
|
||||||
final fb.BufferContext _bc;
|
final fb.BufferContext _bc;
|
||||||
final int _bcOffset;
|
final int _bcOffset;
|
||||||
|
|
||||||
String get name => const fb.StringReader().vTableGet(_bc, _bcOffset, 4, null);
|
String? get name => const fb.StringReader().vTableGetNullable(_bc, _bcOffset, 4);
|
||||||
int get damage => const fb.Int16Reader().vTableGet(_bc, _bcOffset, 6, null);
|
int get damage => const fb.Int16Reader().vTableGet(_bc, _bcOffset, 6, 0);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String toString() {
|
String toString() {
|
||||||
@@ -376,25 +365,23 @@ class _WeaponReader extends fb.TableReader<Weapon> {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Weapon createObject(fb.BufferContext bc, int offset) =>
|
Weapon createObject(fb.BufferContext bc, int offset) =>
|
||||||
new Weapon._(bc, offset);
|
Weapon._(bc, offset);
|
||||||
}
|
}
|
||||||
|
|
||||||
class WeaponBuilder {
|
class WeaponBuilder {
|
||||||
WeaponBuilder(this.fbBuilder) {
|
WeaponBuilder(this.fbBuilder);
|
||||||
assert(fbBuilder != null);
|
|
||||||
}
|
|
||||||
|
|
||||||
final fb.Builder fbBuilder;
|
final fb.Builder fbBuilder;
|
||||||
|
|
||||||
void begin() {
|
void begin() {
|
||||||
fbBuilder.startTable();
|
fbBuilder.startTable(2);
|
||||||
}
|
}
|
||||||
|
|
||||||
int addNameOffset(int offset) {
|
int addNameOffset(int? offset) {
|
||||||
fbBuilder.addOffset(0, offset);
|
fbBuilder.addOffset(0, offset);
|
||||||
return fbBuilder.offset;
|
return fbBuilder.offset;
|
||||||
}
|
}
|
||||||
int addDamage(int damage) {
|
int addDamage(int? damage) {
|
||||||
fbBuilder.addInt16(1, damage);
|
fbBuilder.addInt16(1, damage);
|
||||||
return fbBuilder.offset;
|
return fbBuilder.offset;
|
||||||
}
|
}
|
||||||
@@ -405,36 +392,32 @@ class WeaponBuilder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class WeaponObjectBuilder extends fb.ObjectBuilder {
|
class WeaponObjectBuilder extends fb.ObjectBuilder {
|
||||||
final String _name;
|
final String? _name;
|
||||||
final int _damage;
|
final int? _damage;
|
||||||
|
|
||||||
WeaponObjectBuilder({
|
WeaponObjectBuilder({
|
||||||
String name,
|
String? name,
|
||||||
int damage,
|
int? damage,
|
||||||
})
|
})
|
||||||
: _name = name,
|
: _name = name,
|
||||||
_damage = damage;
|
_damage = damage;
|
||||||
|
|
||||||
/// Finish building, and store into the [fbBuilder].
|
/// Finish building, and store into the [fbBuilder].
|
||||||
@override
|
@override
|
||||||
int finish(
|
int finish(fb.Builder fbBuilder) {
|
||||||
fb.Builder fbBuilder) {
|
final int? nameOffset = _name == null ? null
|
||||||
assert(fbBuilder != null);
|
: fbBuilder.writeString(_name!);
|
||||||
final int nameOffset = fbBuilder.writeString(_name);
|
fbBuilder.startTable(2);
|
||||||
|
fbBuilder.addOffset(0, nameOffset);
|
||||||
fbBuilder.startTable();
|
|
||||||
if (nameOffset != null) {
|
|
||||||
fbBuilder.addOffset(0, nameOffset);
|
|
||||||
}
|
|
||||||
fbBuilder.addInt16(1, _damage);
|
fbBuilder.addInt16(1, _damage);
|
||||||
return fbBuilder.endTable();
|
return fbBuilder.endTable();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Convenience method to serialize to byte list.
|
/// Convenience method to serialize to byte list.
|
||||||
@override
|
@override
|
||||||
Uint8List toBytes([String fileIdentifier]) {
|
Uint8List toBytes([String? fileIdentifier]) {
|
||||||
fb.Builder fbBuilder = new fb.Builder();
|
final fbBuilder = fb.Builder(deduplicateTables: false);
|
||||||
int offset = finish(fbBuilder);
|
fbBuilder.finish(finish(fbBuilder), fileIdentifier);
|
||||||
return fbBuilder.finish(offset, fileIdentifier);
|
return fbBuilder.buffer;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
2
dart/lib/flex_buffers.dart
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
export 'src/builder.dart';
|
||||||
|
export 'src/reference.dart';
|
||||||
676
dart/lib/src/builder.dart
Normal file
@@ -0,0 +1,676 @@
|
|||||||
|
import 'dart:convert';
|
||||||
|
import 'dart:typed_data';
|
||||||
|
|
||||||
|
import 'types.dart';
|
||||||
|
|
||||||
|
/// The main builder class for creation of a FlexBuffer.
|
||||||
|
class Builder {
|
||||||
|
final ByteData _buffer;
|
||||||
|
List<_StackValue> _stack = [];
|
||||||
|
List<_StackPointer> _stackPointers = [];
|
||||||
|
int _offset = 0;
|
||||||
|
bool _finished = false;
|
||||||
|
final Map<String, _StackValue> _stringCache = {};
|
||||||
|
final Map<String, _StackValue> _keyCache = {};
|
||||||
|
final Map<_KeysHash, _StackValue> _keyVectorCache = {};
|
||||||
|
final Map<int, _StackValue> _indirectIntCache = {};
|
||||||
|
final Map<double, _StackValue> _indirectDoubleCache = {};
|
||||||
|
|
||||||
|
/// Instantiate the builder if you intent to gradually build up the buffer by calling
|
||||||
|
/// add... methods and calling [finish] to receive the resulting byte array.
|
||||||
|
///
|
||||||
|
/// The default size of internal buffer is set to 2048. Provide a different value in order to avoid buffer copies.
|
||||||
|
Builder({int size = 2048}) : _buffer = ByteData(size);
|
||||||
|
|
||||||
|
/// Use this method in order to turn an object into a FlexBuffer directly.
|
||||||
|
///
|
||||||
|
/// Use the manual instantiation of the [Builder] and gradual addition of values, if performance is more important than convenience.
|
||||||
|
static ByteBuffer buildFromObject(Object? value) {
|
||||||
|
final builder = Builder();
|
||||||
|
builder._add(value);
|
||||||
|
final buffer = builder.finish();
|
||||||
|
final byteData = ByteData(buffer.lengthInBytes);
|
||||||
|
byteData.buffer.asUint8List().setAll(0, buffer);
|
||||||
|
return byteData.buffer;
|
||||||
|
}
|
||||||
|
|
||||||
|
void _add(Object? value) {
|
||||||
|
if (value == null) {
|
||||||
|
addNull();
|
||||||
|
} else if (value is bool) {
|
||||||
|
addBool(value);
|
||||||
|
} else if (value is int) {
|
||||||
|
addInt(value);
|
||||||
|
} else if (value is double) {
|
||||||
|
addDouble(value);
|
||||||
|
} else if (value is ByteBuffer) {
|
||||||
|
addBlob(value);
|
||||||
|
} else if (value is String) {
|
||||||
|
addString(value);
|
||||||
|
} else if (value is List<dynamic>) {
|
||||||
|
startVector();
|
||||||
|
for (var i = 0; i < value.length; i++) {
|
||||||
|
_add(value[i]);
|
||||||
|
}
|
||||||
|
end();
|
||||||
|
} else if (value is Map<String, dynamic>) {
|
||||||
|
startMap();
|
||||||
|
value.forEach((key, value) {
|
||||||
|
addKey(key);
|
||||||
|
_add(value);
|
||||||
|
});
|
||||||
|
end();
|
||||||
|
} else {
|
||||||
|
throw UnsupportedError('Value of unexpected type: $value');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Use this method if you want to store a null value.
|
||||||
|
///
|
||||||
|
/// Specifically useful when building up a vector where values can be null.
|
||||||
|
void addNull() {
|
||||||
|
_integrityCheckOnValueAddition();
|
||||||
|
_stack.add(_StackValue.withNull());
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Adds a string value.
|
||||||
|
void addInt(int value) {
|
||||||
|
_integrityCheckOnValueAddition();
|
||||||
|
_stack.add(_StackValue.withInt(value));
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Adds a bool value.
|
||||||
|
void addBool(bool value) {
|
||||||
|
_integrityCheckOnValueAddition();
|
||||||
|
_stack.add(_StackValue.withBool(value));
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Adds a double value.
|
||||||
|
void addDouble(double value) {
|
||||||
|
_integrityCheckOnValueAddition();
|
||||||
|
_stack.add(_StackValue.withDouble(value));
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Adds a string value.
|
||||||
|
void addString(String value) {
|
||||||
|
_integrityCheckOnValueAddition();
|
||||||
|
if (_stringCache.containsKey(value)) {
|
||||||
|
_stack.add(_stringCache[value]!);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
final utf8String = utf8.encode(value);
|
||||||
|
final length = utf8String.length;
|
||||||
|
final bitWidth = BitWidthUtil.uwidth(length);
|
||||||
|
final byteWidth = _align(bitWidth);
|
||||||
|
_writeUInt(length, byteWidth);
|
||||||
|
final stringOffset = _offset;
|
||||||
|
final newOffset = _newOffset(length + 1);
|
||||||
|
_pushBuffer(utf8String);
|
||||||
|
_offset = newOffset;
|
||||||
|
final stackValue =
|
||||||
|
_StackValue.withOffset(stringOffset, ValueType.String, bitWidth);
|
||||||
|
_stack.add(stackValue);
|
||||||
|
_stringCache[value] = stackValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// This methods adds a key to a map and should be followed by an add... value call.
|
||||||
|
///
|
||||||
|
/// It also implies that you call this method only after you called [startMap].
|
||||||
|
void addKey(String value) {
|
||||||
|
_integrityCheckOnKeyAddition();
|
||||||
|
if (_keyCache.containsKey(value)) {
|
||||||
|
_stack.add(_keyCache[value]!);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
final utf8String = utf8.encode(value);
|
||||||
|
final length = utf8String.length;
|
||||||
|
final keyOffset = _offset;
|
||||||
|
final newOffset = _newOffset(length + 1);
|
||||||
|
_pushBuffer(utf8String);
|
||||||
|
_offset = newOffset;
|
||||||
|
final stackValue =
|
||||||
|
_StackValue.withOffset(keyOffset, ValueType.Key, BitWidth.width8);
|
||||||
|
_stack.add(stackValue);
|
||||||
|
_keyCache[value] = stackValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Adds a byte array.
|
||||||
|
///
|
||||||
|
/// This method can be used to store any generic BLOB.
|
||||||
|
void addBlob(ByteBuffer value) {
|
||||||
|
_integrityCheckOnValueAddition();
|
||||||
|
final length = value.lengthInBytes;
|
||||||
|
final bitWidth = BitWidthUtil.uwidth(length);
|
||||||
|
final byteWidth = _align(bitWidth);
|
||||||
|
_writeUInt(length, byteWidth);
|
||||||
|
final blobOffset = _offset;
|
||||||
|
final newOffset = _newOffset(length);
|
||||||
|
_pushBuffer(value.asUint8List());
|
||||||
|
_offset = newOffset;
|
||||||
|
final stackValue =
|
||||||
|
_StackValue.withOffset(blobOffset, ValueType.Blob, bitWidth);
|
||||||
|
_stack.add(stackValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Stores int value indirectly in the buffer.
|
||||||
|
///
|
||||||
|
/// Adding large integer values indirectly might be beneficial if those values suppose to be store in a vector together with small integer values.
|
||||||
|
/// This is due to the fact that FlexBuffers will add padding to small integer values, if they are stored together with large integer values.
|
||||||
|
/// When we add integer indirectly the vector of ints will contain not the value itself, but only the relative offset to the value.
|
||||||
|
/// By setting the [cache] parameter to true, you make sure that the builder tracks added int value and performs deduplication.
|
||||||
|
void addIntIndirectly(int value, {bool cache = false}) {
|
||||||
|
_integrityCheckOnValueAddition();
|
||||||
|
if (_indirectIntCache.containsKey(value)) {
|
||||||
|
_stack.add(_indirectIntCache[value]!);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
final stackValue = _StackValue.withInt(value);
|
||||||
|
final byteWidth = _align(stackValue.width);
|
||||||
|
final newOffset = _newOffset(byteWidth);
|
||||||
|
final valueOffset = _offset;
|
||||||
|
_pushBuffer(stackValue.asU8List(stackValue.width));
|
||||||
|
final stackOffset = _StackValue.withOffset(
|
||||||
|
valueOffset, ValueType.IndirectInt, stackValue.width);
|
||||||
|
_stack.add(stackOffset);
|
||||||
|
_offset = newOffset;
|
||||||
|
if (cache) {
|
||||||
|
_indirectIntCache[value] = stackOffset;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Stores double value indirectly in the buffer.
|
||||||
|
///
|
||||||
|
/// Double are stored as 8 or 4 byte values in FlexBuffers. If they are stored in a mixed vector, values which are smaller than 4 / 8 bytes will be padded.
|
||||||
|
/// When we add double indirectly, the vector will contain not the value itself, but only the relative offset to the value. Which could occupy only 1 or 2 bytes, reducing the odds for unnecessary padding.
|
||||||
|
/// By setting the [cache] parameter to true, you make sure that the builder tracks already added double value and performs deduplication.
|
||||||
|
void addDoubleIndirectly(double value, {bool cache = false}) {
|
||||||
|
_integrityCheckOnValueAddition();
|
||||||
|
if (cache && _indirectDoubleCache.containsKey(value)) {
|
||||||
|
_stack.add(_indirectDoubleCache[value]!);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
final stackValue = _StackValue.withDouble(value);
|
||||||
|
final byteWidth = _align(stackValue.width);
|
||||||
|
final newOffset = _newOffset(byteWidth);
|
||||||
|
final valueOffset = _offset;
|
||||||
|
_pushBuffer(stackValue.asU8List(stackValue.width));
|
||||||
|
final stackOffset = _StackValue.withOffset(
|
||||||
|
valueOffset, ValueType.IndirectFloat, stackValue.width);
|
||||||
|
_stack.add(stackOffset);
|
||||||
|
_offset = newOffset;
|
||||||
|
if (cache) {
|
||||||
|
_indirectDoubleCache[value] = stackOffset;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// This method starts a vector definition and needs to be followed by 0 to n add... value calls.
|
||||||
|
///
|
||||||
|
/// The vector definition needs to be finished with an [end] call.
|
||||||
|
/// It is also possible to add nested vector or map by calling [startVector] / [startMap].
|
||||||
|
void startVector() {
|
||||||
|
_integrityCheckOnValueAddition();
|
||||||
|
_stackPointers.add(_StackPointer(_stack.length, true));
|
||||||
|
}
|
||||||
|
|
||||||
|
/// This method starts a map definition.
|
||||||
|
///
|
||||||
|
/// This method call needs to be followed by 0 to n [addKey] + add... value calls.
|
||||||
|
/// The map definition needs to be finished with an [end] call.
|
||||||
|
/// It is also possible to add nested vector or map by calling [startVector] / [startMap] after calling [addKey].
|
||||||
|
void startMap() {
|
||||||
|
_integrityCheckOnValueAddition();
|
||||||
|
_stackPointers.add(_StackPointer(_stack.length, false));
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Marks that the addition of values to the last vector, or map have ended.
|
||||||
|
void end() {
|
||||||
|
final pointer = _stackPointers.removeLast();
|
||||||
|
if (pointer.isVector) {
|
||||||
|
_endVector(pointer);
|
||||||
|
} else {
|
||||||
|
_sortKeysAndEndMap(pointer);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Finish building the FlatBuffer and return array of bytes.
|
||||||
|
///
|
||||||
|
/// Can be called multiple times, to get the array of bytes.
|
||||||
|
/// After the first call, adding values, or starting vectors / maps will result in an exception.
|
||||||
|
Uint8List finish() {
|
||||||
|
if (_finished == false) {
|
||||||
|
_finish();
|
||||||
|
}
|
||||||
|
return _buffer.buffer.asUint8List(0, _offset);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Builds a FlatBuffer with current state without finishing the builder.
|
||||||
|
///
|
||||||
|
/// Creates an internal temporary copy of current builder and finishes the copy.
|
||||||
|
/// Use this method, when the state of a long lasting builder need to be persisted periodically.
|
||||||
|
ByteBuffer snapshot() {
|
||||||
|
final tmp = Builder(size: _offset + 200);
|
||||||
|
tmp._offset = _offset;
|
||||||
|
tmp._stack = List.from(_stack);
|
||||||
|
tmp._stackPointers = List.from(_stackPointers);
|
||||||
|
tmp._buffer.buffer
|
||||||
|
.asUint8List()
|
||||||
|
.setAll(0, _buffer.buffer.asUint8List(0, _offset));
|
||||||
|
for (var i = 0; i < tmp._stackPointers.length; i++) {
|
||||||
|
tmp.end();
|
||||||
|
}
|
||||||
|
final buffer = tmp.finish();
|
||||||
|
final bd = ByteData(buffer.lengthInBytes);
|
||||||
|
bd.buffer.asUint8List().setAll(0, buffer);
|
||||||
|
return bd.buffer;
|
||||||
|
}
|
||||||
|
|
||||||
|
void _integrityCheckOnValueAddition() {
|
||||||
|
if (_finished) {
|
||||||
|
throw StateError('Adding values after finish is prohibited');
|
||||||
|
}
|
||||||
|
if (_stackPointers.isNotEmpty && _stackPointers.last.isVector == false) {
|
||||||
|
if (_stack.last.type != ValueType.Key) {
|
||||||
|
throw StateError(
|
||||||
|
'Adding value to a map before adding a key is prohibited');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void _integrityCheckOnKeyAddition() {
|
||||||
|
if (_finished) {
|
||||||
|
throw StateError('Adding values after finish is prohibited');
|
||||||
|
}
|
||||||
|
if (_stackPointers.isEmpty || _stackPointers.last.isVector) {
|
||||||
|
throw StateError('Adding key before staring a map is prohibited');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void _finish() {
|
||||||
|
if (_stack.length != 1) {
|
||||||
|
throw StateError(
|
||||||
|
'Stack has to be exactly 1, but is ${_stack.length}. You have to end all started vectors and maps, before calling [finish]');
|
||||||
|
}
|
||||||
|
final value = _stack[0];
|
||||||
|
final byteWidth = _align(value.elementWidth(_offset, 0));
|
||||||
|
_writeStackValue(value, byteWidth);
|
||||||
|
_writeUInt(value.storedPackedType(), 1);
|
||||||
|
_writeUInt(byteWidth, 1);
|
||||||
|
_finished = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
_StackValue _createVector(int start, int vecLength, int step,
|
||||||
|
[_StackValue? keys]) {
|
||||||
|
var bitWidth = BitWidthUtil.uwidth(vecLength);
|
||||||
|
var prefixElements = 1;
|
||||||
|
if (keys != null) {
|
||||||
|
var elemWidth = keys.elementWidth(_offset, 0);
|
||||||
|
if (elemWidth.index > bitWidth.index) {
|
||||||
|
bitWidth = elemWidth;
|
||||||
|
}
|
||||||
|
prefixElements += 2;
|
||||||
|
}
|
||||||
|
var vectorType = ValueType.Key;
|
||||||
|
var typed = keys == null;
|
||||||
|
for (var i = start; i < _stack.length; i += step) {
|
||||||
|
final elemWidth = _stack[i].elementWidth(_offset, i + prefixElements);
|
||||||
|
if (elemWidth.index > bitWidth.index) {
|
||||||
|
bitWidth = elemWidth;
|
||||||
|
}
|
||||||
|
if (i == start) {
|
||||||
|
vectorType = _stack[i].type;
|
||||||
|
typed &= ValueTypeUtils.isTypedVectorElement(vectorType);
|
||||||
|
} else {
|
||||||
|
if (vectorType != _stack[i].type) {
|
||||||
|
typed = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
final byteWidth = _align(bitWidth);
|
||||||
|
final fix = typed & ValueTypeUtils.isNumber(vectorType) &&
|
||||||
|
vecLength >= 2 &&
|
||||||
|
vecLength <= 4;
|
||||||
|
if (keys != null) {
|
||||||
|
_writeStackValue(keys, byteWidth);
|
||||||
|
_writeUInt(1 << keys.width.index, byteWidth);
|
||||||
|
}
|
||||||
|
if (fix == false) {
|
||||||
|
_writeUInt(vecLength, byteWidth);
|
||||||
|
}
|
||||||
|
final vecOffset = _offset;
|
||||||
|
for (var i = start; i < _stack.length; i += step) {
|
||||||
|
_writeStackValue(_stack[i], byteWidth);
|
||||||
|
}
|
||||||
|
if (typed == false) {
|
||||||
|
for (var i = start; i < _stack.length; i += step) {
|
||||||
|
_writeUInt(_stack[i].storedPackedType(), 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (keys != null) {
|
||||||
|
return _StackValue.withOffset(vecOffset, ValueType.Map, bitWidth);
|
||||||
|
}
|
||||||
|
if (typed) {
|
||||||
|
final vType =
|
||||||
|
ValueTypeUtils.toTypedVector(vectorType, fix ? vecLength : 0);
|
||||||
|
return _StackValue.withOffset(vecOffset, vType, bitWidth);
|
||||||
|
}
|
||||||
|
return _StackValue.withOffset(vecOffset, ValueType.Vector, bitWidth);
|
||||||
|
}
|
||||||
|
|
||||||
|
void _endVector(_StackPointer pointer) {
|
||||||
|
final vecLength = _stack.length - pointer.stackPosition;
|
||||||
|
final vec = _createVector(pointer.stackPosition, vecLength, 1);
|
||||||
|
_stack.removeRange(pointer.stackPosition, _stack.length);
|
||||||
|
_stack.add(vec);
|
||||||
|
}
|
||||||
|
|
||||||
|
void _sortKeysAndEndMap(_StackPointer pointer) {
|
||||||
|
if (((_stack.length - pointer.stackPosition) & 1) == 1) {
|
||||||
|
throw StateError(
|
||||||
|
'The stack needs to hold key value pairs (even number of elements). Check if you combined [addKey] with add... method calls properly.');
|
||||||
|
}
|
||||||
|
|
||||||
|
var sorted = true;
|
||||||
|
for (var i = pointer.stackPosition; i < _stack.length - 2; i += 2) {
|
||||||
|
if (_shouldFlip(_stack[i], _stack[i + 2])) {
|
||||||
|
sorted = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (sorted == false) {
|
||||||
|
for (var i = pointer.stackPosition; i < _stack.length; i += 2) {
|
||||||
|
var flipIndex = i;
|
||||||
|
for (var j = i + 2; j < _stack.length; j += 2) {
|
||||||
|
if (_shouldFlip(_stack[flipIndex], _stack[j])) {
|
||||||
|
flipIndex = j;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (flipIndex != i) {
|
||||||
|
var k = _stack[flipIndex];
|
||||||
|
var v = _stack[flipIndex + 1];
|
||||||
|
_stack[flipIndex] = _stack[i];
|
||||||
|
_stack[flipIndex + 1] = _stack[i + 1];
|
||||||
|
_stack[i] = k;
|
||||||
|
_stack[i + 1] = v;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_endMap(pointer);
|
||||||
|
}
|
||||||
|
|
||||||
|
void _endMap(_StackPointer pointer) {
|
||||||
|
final vecLength = (_stack.length - pointer.stackPosition) >> 1;
|
||||||
|
final offsets = <int>[];
|
||||||
|
for (var i = pointer.stackPosition; i < _stack.length; i += 2) {
|
||||||
|
offsets.add(_stack[i].offset!);
|
||||||
|
}
|
||||||
|
final keysHash = _KeysHash(offsets);
|
||||||
|
_StackValue? keysStackValue;
|
||||||
|
if (_keyVectorCache.containsKey(keysHash)) {
|
||||||
|
keysStackValue = _keyVectorCache[keysHash];
|
||||||
|
} else {
|
||||||
|
keysStackValue = _createVector(pointer.stackPosition, vecLength, 2);
|
||||||
|
_keyVectorCache[keysHash] = keysStackValue;
|
||||||
|
}
|
||||||
|
final vec =
|
||||||
|
_createVector(pointer.stackPosition + 1, vecLength, 2, keysStackValue);
|
||||||
|
_stack.removeRange(pointer.stackPosition, _stack.length);
|
||||||
|
_stack.add(vec);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool _shouldFlip(_StackValue v1, _StackValue v2) {
|
||||||
|
if (v1.type != ValueType.Key || v2.type != ValueType.Key) {
|
||||||
|
throw StateError(
|
||||||
|
'Stack values are not keys $v1 | $v2. Check if you combined [addKey] with add... method calls properly.');
|
||||||
|
}
|
||||||
|
|
||||||
|
late int c1, c2;
|
||||||
|
var index = 0;
|
||||||
|
do {
|
||||||
|
c1 = _buffer.getUint8(v1.offset! + index);
|
||||||
|
c2 = _buffer.getUint8(v2.offset! + index);
|
||||||
|
if (c2 < c1) return true;
|
||||||
|
if (c1 < c2) return false;
|
||||||
|
index += 1;
|
||||||
|
} while (c1 != 0 && c2 != 0);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
int _align(BitWidth width) {
|
||||||
|
final byteWidth = BitWidthUtil.toByteWidth(width);
|
||||||
|
_offset += BitWidthUtil.paddingSize(_offset, byteWidth);
|
||||||
|
return byteWidth;
|
||||||
|
}
|
||||||
|
|
||||||
|
void _writeStackValue(_StackValue value, int byteWidth) {
|
||||||
|
final newOffset = _newOffset(byteWidth);
|
||||||
|
if (value.isOffset) {
|
||||||
|
final relativeOffset = _offset - value.offset!;
|
||||||
|
if (byteWidth == 8 || relativeOffset < (1 << (byteWidth * 8))) {
|
||||||
|
_writeUInt(relativeOffset, byteWidth);
|
||||||
|
} else {
|
||||||
|
throw StateError(
|
||||||
|
'Unexpected size $byteWidth. This might be a bug. Please create an issue https://github.com/google/flatbuffers/issues/new');
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
_pushBuffer(value.asU8List(BitWidthUtil.fromByteWidth(byteWidth)));
|
||||||
|
}
|
||||||
|
_offset = newOffset;
|
||||||
|
}
|
||||||
|
|
||||||
|
void _writeUInt(int value, int byteWidth) {
|
||||||
|
final newOffset = _newOffset(byteWidth);
|
||||||
|
_pushUInt(value, BitWidthUtil.fromByteWidth(byteWidth));
|
||||||
|
_offset = newOffset;
|
||||||
|
}
|
||||||
|
|
||||||
|
int _newOffset(int newValueSize) {
|
||||||
|
final newOffset = _offset + newValueSize;
|
||||||
|
var size = _buffer.lengthInBytes;
|
||||||
|
final prevSize = size;
|
||||||
|
while (size < newOffset) {
|
||||||
|
size <<= 1;
|
||||||
|
}
|
||||||
|
if (prevSize < size) {
|
||||||
|
final newBuf = ByteData(size);
|
||||||
|
newBuf.buffer.asUint8List().setAll(0, _buffer.buffer.asUint8List());
|
||||||
|
}
|
||||||
|
return newOffset;
|
||||||
|
}
|
||||||
|
|
||||||
|
void _pushInt(int value, BitWidth width) {
|
||||||
|
switch (width) {
|
||||||
|
case BitWidth.width8:
|
||||||
|
_buffer.setInt8(_offset, value);
|
||||||
|
break;
|
||||||
|
case BitWidth.width16:
|
||||||
|
_buffer.setInt16(_offset, value, Endian.little);
|
||||||
|
break;
|
||||||
|
case BitWidth.width32:
|
||||||
|
_buffer.setInt32(_offset, value, Endian.little);
|
||||||
|
break;
|
||||||
|
case BitWidth.width64:
|
||||||
|
_buffer.setInt64(_offset, value, Endian.little);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void _pushUInt(int value, BitWidth width) {
|
||||||
|
switch (width) {
|
||||||
|
case BitWidth.width8:
|
||||||
|
_buffer.setUint8(_offset, value);
|
||||||
|
break;
|
||||||
|
case BitWidth.width16:
|
||||||
|
_buffer.setUint16(_offset, value, Endian.little);
|
||||||
|
break;
|
||||||
|
case BitWidth.width32:
|
||||||
|
_buffer.setUint32(_offset, value, Endian.little);
|
||||||
|
break;
|
||||||
|
case BitWidth.width64:
|
||||||
|
_buffer.setUint64(_offset, value, Endian.little);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void _pushBuffer(List<int> value) {
|
||||||
|
_buffer.buffer.asUint8List().setAll(_offset, value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class _StackValue {
|
||||||
|
late Object _value;
|
||||||
|
int? _offset;
|
||||||
|
final ValueType _type;
|
||||||
|
final BitWidth _width;
|
||||||
|
|
||||||
|
_StackValue.withNull()
|
||||||
|
: _type = ValueType.Null,
|
||||||
|
_width = BitWidth.width8;
|
||||||
|
|
||||||
|
_StackValue.withInt(int value)
|
||||||
|
: _type = ValueType.Int,
|
||||||
|
_width = BitWidthUtil.width(value),
|
||||||
|
_value = value;
|
||||||
|
|
||||||
|
_StackValue.withBool(bool value)
|
||||||
|
: _type = ValueType.Bool,
|
||||||
|
_width = BitWidth.width8,
|
||||||
|
_value = value;
|
||||||
|
|
||||||
|
_StackValue.withDouble(double value)
|
||||||
|
: _type = ValueType.Float,
|
||||||
|
_width = BitWidthUtil.width(value),
|
||||||
|
_value = value;
|
||||||
|
|
||||||
|
_StackValue.withOffset(int value, ValueType type, BitWidth width)
|
||||||
|
: _offset = value,
|
||||||
|
_type = type,
|
||||||
|
_width = width;
|
||||||
|
|
||||||
|
BitWidth storedWidth({BitWidth width = BitWidth.width8}) {
|
||||||
|
return ValueTypeUtils.isInline(_type)
|
||||||
|
? BitWidthUtil.max(_width, width)
|
||||||
|
: _width;
|
||||||
|
}
|
||||||
|
|
||||||
|
int storedPackedType({BitWidth width = BitWidth.width8}) {
|
||||||
|
return ValueTypeUtils.packedType(_type, storedWidth(width: width));
|
||||||
|
}
|
||||||
|
|
||||||
|
BitWidth elementWidth(int size, int index) {
|
||||||
|
if (ValueTypeUtils.isInline(_type)) return _width;
|
||||||
|
final offset = _offset!;
|
||||||
|
for (var i = 0; i < 4; i++) {
|
||||||
|
final width = 1 << i;
|
||||||
|
final bitWidth = BitWidthUtil.uwidth(size +
|
||||||
|
BitWidthUtil.paddingSize(size, width) +
|
||||||
|
index * width -
|
||||||
|
offset);
|
||||||
|
if (1 << bitWidth.index == width) {
|
||||||
|
return bitWidth;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
throw StateError(
|
||||||
|
'Element is of unknown. Size: $size at index: $index. This might be a bug. Please create an issue https://github.com/google/flatbuffers/issues/new');
|
||||||
|
}
|
||||||
|
|
||||||
|
List<int> asU8List(BitWidth width) {
|
||||||
|
if (ValueTypeUtils.isNumber(_type)) {
|
||||||
|
if (_type == ValueType.Float) {
|
||||||
|
if (width == BitWidth.width32) {
|
||||||
|
final result = ByteData(4);
|
||||||
|
result.setFloat32(0, _value as double, Endian.little);
|
||||||
|
return result.buffer.asUint8List();
|
||||||
|
} else {
|
||||||
|
final result = ByteData(8);
|
||||||
|
result.setFloat64(0, _value as double, Endian.little);
|
||||||
|
return result.buffer.asUint8List();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
switch (width) {
|
||||||
|
case BitWidth.width8:
|
||||||
|
final result = ByteData(1);
|
||||||
|
result.setInt8(0, _value as int);
|
||||||
|
return result.buffer.asUint8List();
|
||||||
|
case BitWidth.width16:
|
||||||
|
final result = ByteData(2);
|
||||||
|
result.setInt16(0, _value as int, Endian.little);
|
||||||
|
return result.buffer.asUint8List();
|
||||||
|
case BitWidth.width32:
|
||||||
|
final result = ByteData(4);
|
||||||
|
result.setInt32(0, _value as int, Endian.little);
|
||||||
|
return result.buffer.asUint8List();
|
||||||
|
case BitWidth.width64:
|
||||||
|
final result = ByteData(8);
|
||||||
|
result.setInt64(0, _value as int, Endian.little);
|
||||||
|
return result.buffer.asUint8List();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (_type == ValueType.Null) {
|
||||||
|
final result = ByteData(1);
|
||||||
|
result.setInt8(0, 0);
|
||||||
|
return result.buffer.asUint8List();
|
||||||
|
}
|
||||||
|
if (_type == ValueType.Bool) {
|
||||||
|
final result = ByteData(1);
|
||||||
|
result.setInt8(0, _value as bool ? 1 : 0);
|
||||||
|
return result.buffer.asUint8List();
|
||||||
|
}
|
||||||
|
|
||||||
|
throw StateError(
|
||||||
|
'Unexpected type: $_type. This might be a bug. Please create an issue https://github.com/google/flatbuffers/issues/new');
|
||||||
|
}
|
||||||
|
|
||||||
|
ValueType get type {
|
||||||
|
return _type;
|
||||||
|
}
|
||||||
|
|
||||||
|
BitWidth get width {
|
||||||
|
return _width;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool get isOffset {
|
||||||
|
return !ValueTypeUtils.isInline(_type);
|
||||||
|
}
|
||||||
|
|
||||||
|
int? get offset => _offset;
|
||||||
|
|
||||||
|
bool get isFloat32 {
|
||||||
|
return _type == ValueType.Float && _width == BitWidth.width32;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class _StackPointer {
|
||||||
|
int stackPosition;
|
||||||
|
bool isVector;
|
||||||
|
|
||||||
|
_StackPointer(this.stackPosition, this.isVector);
|
||||||
|
}
|
||||||
|
|
||||||
|
class _KeysHash {
|
||||||
|
final List<int> keys;
|
||||||
|
|
||||||
|
const _KeysHash(this.keys);
|
||||||
|
|
||||||
|
@override
|
||||||
|
bool operator ==(Object other) {
|
||||||
|
if (other is _KeysHash) {
|
||||||
|
if (keys.length != other.keys.length) return false;
|
||||||
|
for (var i = 0; i < keys.length; i++) {
|
||||||
|
if (keys[i] != other.keys[i]) return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
int get hashCode {
|
||||||
|
var result = 17;
|
||||||
|
for (var i = 0; i < keys.length; i++) {
|
||||||
|
result = result * 23 + keys[i];
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
481
dart/lib/src/reference.dart
Normal file
@@ -0,0 +1,481 @@
|
|||||||
|
import 'dart:collection';
|
||||||
|
import 'dart:convert';
|
||||||
|
import 'dart:typed_data';
|
||||||
|
import 'types.dart';
|
||||||
|
|
||||||
|
/// Main class to read a value out of a FlexBuffer.
|
||||||
|
///
|
||||||
|
/// This class let you access values stored in the buffer in a lazy fashion.
|
||||||
|
class Reference {
|
||||||
|
final ByteData _buffer;
|
||||||
|
final int _offset;
|
||||||
|
final BitWidth _parentWidth;
|
||||||
|
final String _path;
|
||||||
|
final int _byteWidth;
|
||||||
|
final ValueType _valueType;
|
||||||
|
int? _length;
|
||||||
|
|
||||||
|
Reference._(
|
||||||
|
this._buffer, this._offset, this._parentWidth, int packedType, this._path,
|
||||||
|
[int? byteWidth, ValueType? valueType])
|
||||||
|
: _byteWidth = byteWidth ?? 1 << (packedType & 3),
|
||||||
|
_valueType = valueType ?? ValueTypeUtils.fromInt(packedType >> 2);
|
||||||
|
|
||||||
|
/// Use this method to access the root value of a FlexBuffer.
|
||||||
|
static Reference fromBuffer(ByteBuffer buffer) {
|
||||||
|
final len = buffer.lengthInBytes;
|
||||||
|
if (len < 3) {
|
||||||
|
throw UnsupportedError('Buffer needs to be bigger than 3');
|
||||||
|
}
|
||||||
|
final byteData = ByteData.view(buffer);
|
||||||
|
final byteWidth = byteData.getUint8(len - 1);
|
||||||
|
final packedType = byteData.getUint8(len - 2);
|
||||||
|
final offset = len - byteWidth - 2;
|
||||||
|
return Reference._(ByteData.view(buffer), offset,
|
||||||
|
BitWidthUtil.fromByteWidth(byteWidth), packedType, "/");
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Returns true if the underlying value is null.
|
||||||
|
bool get isNull => _valueType == ValueType.Null;
|
||||||
|
|
||||||
|
/// Returns true if the underlying value can be represented as [num].
|
||||||
|
bool get isNum =>
|
||||||
|
ValueTypeUtils.isNumber(_valueType) ||
|
||||||
|
ValueTypeUtils.isIndirectNumber(_valueType);
|
||||||
|
|
||||||
|
/// Returns true if the underlying value was encoded as a float (direct or indirect).
|
||||||
|
bool get isDouble =>
|
||||||
|
_valueType == ValueType.Float || _valueType == ValueType.IndirectFloat;
|
||||||
|
|
||||||
|
/// Returns true if the underlying value was encoded as an int or uint (direct or indirect).
|
||||||
|
bool get isInt => isNum && !isDouble;
|
||||||
|
|
||||||
|
/// Returns true if the underlying value was encoded as a string or a key.
|
||||||
|
bool get isString =>
|
||||||
|
_valueType == ValueType.String || _valueType == ValueType.Key;
|
||||||
|
|
||||||
|
/// Returns true if the underlying value was encoded as a bool.
|
||||||
|
bool get isBool => _valueType == ValueType.Bool;
|
||||||
|
|
||||||
|
/// Returns true if the underlying value was encoded as a blob.
|
||||||
|
bool get isBlob => _valueType == ValueType.Blob;
|
||||||
|
|
||||||
|
/// Returns true if the underlying value points to a vector.
|
||||||
|
bool get isVector => ValueTypeUtils.isAVector(_valueType);
|
||||||
|
|
||||||
|
/// Returns true if the underlying value points to a map.
|
||||||
|
bool get isMap => _valueType == ValueType.Map;
|
||||||
|
|
||||||
|
/// If this [isBool], returns the bool value. Otherwise, returns null.
|
||||||
|
bool? get boolValue {
|
||||||
|
if (_valueType == ValueType.Bool) {
|
||||||
|
return _readInt(_offset, _parentWidth) != 0;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Returns an [int], if the underlying value can be represented as an int.
|
||||||
|
///
|
||||||
|
/// Otherwise returns [null].
|
||||||
|
int? get intValue {
|
||||||
|
if (_valueType == ValueType.Int) {
|
||||||
|
return _readInt(_offset, _parentWidth);
|
||||||
|
}
|
||||||
|
if (_valueType == ValueType.UInt) {
|
||||||
|
return _readUInt(_offset, _parentWidth);
|
||||||
|
}
|
||||||
|
if (_valueType == ValueType.IndirectInt) {
|
||||||
|
return _readInt(_indirect, BitWidthUtil.fromByteWidth(_byteWidth));
|
||||||
|
}
|
||||||
|
if (_valueType == ValueType.IndirectUInt) {
|
||||||
|
return _readUInt(_indirect, BitWidthUtil.fromByteWidth(_byteWidth));
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Returns [double], if the underlying value [isDouble].
|
||||||
|
///
|
||||||
|
/// Otherwise returns [null].
|
||||||
|
double? get doubleValue {
|
||||||
|
if (_valueType == ValueType.Float) {
|
||||||
|
return _readFloat(_offset, _parentWidth);
|
||||||
|
}
|
||||||
|
if (_valueType == ValueType.IndirectFloat) {
|
||||||
|
return _readFloat(_indirect, BitWidthUtil.fromByteWidth(_byteWidth));
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Returns [num], if the underlying value is numeric, be it int uint, or float (direct or indirect).
|
||||||
|
///
|
||||||
|
/// Otherwise returns [null].
|
||||||
|
num? get numValue => doubleValue ?? intValue;
|
||||||
|
|
||||||
|
/// Returns [String] value or null otherwise.
|
||||||
|
///
|
||||||
|
/// This method performers a utf8 decoding, as FlexBuffers format stores strings in utf8 encoding.
|
||||||
|
String? get stringValue {
|
||||||
|
if (_valueType == ValueType.String || _valueType == ValueType.Key) {
|
||||||
|
return utf8.decode(_buffer.buffer.asUint8List(_indirect, length));
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Returns [Uint8List] value or null otherwise.
|
||||||
|
Uint8List? get blobValue {
|
||||||
|
if (_valueType == ValueType.Blob) {
|
||||||
|
return _buffer.buffer.asUint8List(_indirect, length);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Can be used with an [int] or a [String] value for key.
|
||||||
|
/// If the underlying value in FlexBuffer is a vector, then use [int] for access.
|
||||||
|
/// If the underlying value in FlexBuffer is a map, then use [String] for access.
|
||||||
|
/// Returns [Reference] value. Throws an exception when [key] is not applicable.
|
||||||
|
Reference operator [](Object key) {
|
||||||
|
if (key is int && ValueTypeUtils.isAVector(_valueType)) {
|
||||||
|
final index = key;
|
||||||
|
if (index >= length || index < 0) {
|
||||||
|
throw ArgumentError(
|
||||||
|
'Key: [$key] is not applicable on: $_path of: $_valueType length: $length');
|
||||||
|
}
|
||||||
|
final elementOffset = _indirect + index * _byteWidth;
|
||||||
|
int packedType = 0;
|
||||||
|
int? byteWidth;
|
||||||
|
ValueType? valueType;
|
||||||
|
if (ValueTypeUtils.isTypedVector(_valueType)) {
|
||||||
|
byteWidth = 1;
|
||||||
|
valueType = ValueTypeUtils.typedVectorElementType(_valueType);
|
||||||
|
} else if (ValueTypeUtils.isFixedTypedVector(_valueType)) {
|
||||||
|
byteWidth = 1;
|
||||||
|
valueType = ValueTypeUtils.fixedTypedVectorElementType(_valueType);
|
||||||
|
} else {
|
||||||
|
packedType = _buffer.getUint8(_indirect + length * _byteWidth + index);
|
||||||
|
}
|
||||||
|
return Reference._(
|
||||||
|
_buffer,
|
||||||
|
elementOffset,
|
||||||
|
BitWidthUtil.fromByteWidth(_byteWidth),
|
||||||
|
packedType,
|
||||||
|
"$_path[$index]",
|
||||||
|
byteWidth,
|
||||||
|
valueType);
|
||||||
|
}
|
||||||
|
if (key is String && _valueType == ValueType.Map) {
|
||||||
|
final index = _keyIndex(key);
|
||||||
|
if (index != null) {
|
||||||
|
return _valueForIndexWithKey(index, key);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
throw ArgumentError(
|
||||||
|
'Key: [$key] is not applicable on: $_path of: $_valueType');
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Get an iterable if the underlying flexBuffer value is a vector.
|
||||||
|
/// Otherwise throws an exception.
|
||||||
|
Iterable<Reference> get vectorIterable {
|
||||||
|
if (isVector == false) {
|
||||||
|
throw UnsupportedError('Value is not a vector. It is: $_valueType');
|
||||||
|
}
|
||||||
|
return _VectorIterator(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Get an iterable for keys if the underlying flexBuffer value is a map.
|
||||||
|
/// Otherwise throws an exception.
|
||||||
|
Iterable<String> get mapKeyIterable {
|
||||||
|
if (isMap == false) {
|
||||||
|
throw UnsupportedError('Value is not a map. It is: $_valueType');
|
||||||
|
}
|
||||||
|
return _MapKeyIterator(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Get an iterable for values if the underlying flexBuffer value is a map.
|
||||||
|
/// Otherwise throws an exception.
|
||||||
|
Iterable<Reference> get mapValueIterable {
|
||||||
|
if (isMap == false) {
|
||||||
|
throw UnsupportedError('Value is not a map. It is: $_valueType');
|
||||||
|
}
|
||||||
|
return _MapValueIterator(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Returns the length of the underlying FlexBuffer value.
|
||||||
|
/// If the underlying value is [null] the length is 0.
|
||||||
|
/// If the underlying value is a number, or a bool, the length is 1.
|
||||||
|
/// If the underlying value is a vector, or map, the length reflects number of elements / element pairs.
|
||||||
|
/// If the values is a string or a blob, the length reflects a number of bytes the value occupies (strings are encoded in utf8 format).
|
||||||
|
int get length {
|
||||||
|
if (_length == null) {
|
||||||
|
// needs to be checked before more generic isAVector
|
||||||
|
if (ValueTypeUtils.isFixedTypedVector(_valueType)) {
|
||||||
|
_length = ValueTypeUtils.fixedTypedVectorElementSize(_valueType);
|
||||||
|
} else if (_valueType == ValueType.Blob ||
|
||||||
|
ValueTypeUtils.isAVector(_valueType) ||
|
||||||
|
_valueType == ValueType.Map) {
|
||||||
|
_length = _readUInt(
|
||||||
|
_indirect - _byteWidth, BitWidthUtil.fromByteWidth(_byteWidth));
|
||||||
|
} else if (_valueType == ValueType.Null) {
|
||||||
|
_length = 0;
|
||||||
|
} else if (_valueType == ValueType.String) {
|
||||||
|
final indirect = _indirect;
|
||||||
|
var sizeByteWidth = _byteWidth;
|
||||||
|
var size = _readUInt(indirect - sizeByteWidth,
|
||||||
|
BitWidthUtil.fromByteWidth(sizeByteWidth));
|
||||||
|
while (_buffer.getInt8(indirect + size) != 0) {
|
||||||
|
sizeByteWidth <<= 1;
|
||||||
|
size = _readUInt(indirect - sizeByteWidth,
|
||||||
|
BitWidthUtil.fromByteWidth(sizeByteWidth));
|
||||||
|
}
|
||||||
|
_length = size;
|
||||||
|
} else if (_valueType == ValueType.Key) {
|
||||||
|
final indirect = _indirect;
|
||||||
|
var size = 1;
|
||||||
|
while (_buffer.getInt8(indirect + size) != 0) {
|
||||||
|
size += 1;
|
||||||
|
}
|
||||||
|
_length = size;
|
||||||
|
} else {
|
||||||
|
_length = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return _length!;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Returns a minified JSON representation of the underlying FlexBuffer value.
|
||||||
|
///
|
||||||
|
/// This method involves materializing the entire object tree, which may be
|
||||||
|
/// expensive. It is more efficient to work with [Reference] and access only the needed data.
|
||||||
|
/// Blob values are represented as base64 encoded string.
|
||||||
|
String get json {
|
||||||
|
if (_valueType == ValueType.Bool) {
|
||||||
|
return boolValue! ? 'true' : 'false';
|
||||||
|
}
|
||||||
|
if (_valueType == ValueType.Null) {
|
||||||
|
return 'null';
|
||||||
|
}
|
||||||
|
if (ValueTypeUtils.isNumber(_valueType)) {
|
||||||
|
return jsonEncode(numValue);
|
||||||
|
}
|
||||||
|
if (_valueType == ValueType.String) {
|
||||||
|
return jsonEncode(stringValue);
|
||||||
|
}
|
||||||
|
if (_valueType == ValueType.Blob) {
|
||||||
|
return jsonEncode(base64Encode(blobValue!));
|
||||||
|
}
|
||||||
|
if (ValueTypeUtils.isAVector(_valueType)) {
|
||||||
|
final result = StringBuffer();
|
||||||
|
result.write('[');
|
||||||
|
for (var i = 0; i < length; i++) {
|
||||||
|
result.write(this[i].json);
|
||||||
|
if (i < length - 1) {
|
||||||
|
result.write(',');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
result.write(']');
|
||||||
|
return result.toString();
|
||||||
|
}
|
||||||
|
if (_valueType == ValueType.Map) {
|
||||||
|
final result = StringBuffer();
|
||||||
|
result.write('{');
|
||||||
|
for (var i = 0; i < length; i++) {
|
||||||
|
result.write(jsonEncode(_keyForIndex(i)));
|
||||||
|
result.write(':');
|
||||||
|
result.write(_valueForIndex(i).json);
|
||||||
|
if (i < length - 1) {
|
||||||
|
result.write(',');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
result.write('}');
|
||||||
|
return result.toString();
|
||||||
|
}
|
||||||
|
throw UnsupportedError(
|
||||||
|
'Type: $_valueType is not supported for JSON conversion');
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Computes the indirect offset of the value.
|
||||||
|
///
|
||||||
|
/// To optimize for the more common case of being called only once, this
|
||||||
|
/// value is not cached. Callers that need to use it more than once should
|
||||||
|
/// cache the return value in a local variable.
|
||||||
|
int get _indirect {
|
||||||
|
final step = _readUInt(_offset, _parentWidth);
|
||||||
|
return _offset - step;
|
||||||
|
}
|
||||||
|
|
||||||
|
int _readInt(int offset, BitWidth width) {
|
||||||
|
_validateOffset(offset, width);
|
||||||
|
if (width == BitWidth.width8) {
|
||||||
|
return _buffer.getInt8(offset);
|
||||||
|
}
|
||||||
|
if (width == BitWidth.width16) {
|
||||||
|
return _buffer.getInt16(offset, Endian.little);
|
||||||
|
}
|
||||||
|
if (width == BitWidth.width32) {
|
||||||
|
return _buffer.getInt32(offset, Endian.little);
|
||||||
|
}
|
||||||
|
return _buffer.getInt64(offset, Endian.little);
|
||||||
|
}
|
||||||
|
|
||||||
|
int _readUInt(int offset, BitWidth width) {
|
||||||
|
_validateOffset(offset, width);
|
||||||
|
if (width == BitWidth.width8) {
|
||||||
|
return _buffer.getUint8(offset);
|
||||||
|
}
|
||||||
|
if (width == BitWidth.width16) {
|
||||||
|
return _buffer.getUint16(offset, Endian.little);
|
||||||
|
}
|
||||||
|
if (width == BitWidth.width32) {
|
||||||
|
return _buffer.getUint32(offset, Endian.little);
|
||||||
|
}
|
||||||
|
return _buffer.getUint64(offset, Endian.little);
|
||||||
|
}
|
||||||
|
|
||||||
|
double _readFloat(int offset, BitWidth width) {
|
||||||
|
_validateOffset(offset, width);
|
||||||
|
if (width.index < BitWidth.width32.index) {
|
||||||
|
throw StateError('Bad width: $width');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (width == BitWidth.width32) {
|
||||||
|
return _buffer.getFloat32(offset, Endian.little);
|
||||||
|
}
|
||||||
|
|
||||||
|
return _buffer.getFloat64(offset, Endian.little);
|
||||||
|
}
|
||||||
|
|
||||||
|
void _validateOffset(int offset, BitWidth width) {
|
||||||
|
if (_offset < 0 ||
|
||||||
|
_buffer.lengthInBytes <= offset + width.index ||
|
||||||
|
offset & (BitWidthUtil.toByteWidth(width) - 1) != 0) {
|
||||||
|
throw StateError('Bad offset: $offset, width: $width');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int? _keyIndex(String key) {
|
||||||
|
final input = utf8.encode(key);
|
||||||
|
final keysVectorOffset = _indirect - _byteWidth * 3;
|
||||||
|
final indirectOffset = keysVectorOffset -
|
||||||
|
_readUInt(keysVectorOffset, BitWidthUtil.fromByteWidth(_byteWidth));
|
||||||
|
final byteWidth = _readUInt(
|
||||||
|
keysVectorOffset + _byteWidth, BitWidthUtil.fromByteWidth(_byteWidth));
|
||||||
|
var low = 0;
|
||||||
|
var high = length - 1;
|
||||||
|
while (low <= high) {
|
||||||
|
final mid = (high + low) >> 1;
|
||||||
|
final dif = _diffKeys(input, mid, indirectOffset, byteWidth);
|
||||||
|
if (dif == 0) return mid;
|
||||||
|
if (dif < 0) {
|
||||||
|
high = mid - 1;
|
||||||
|
} else {
|
||||||
|
low = mid + 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
int _diffKeys(List<int> input, int index, int indirectOffset, int byteWidth) {
|
||||||
|
final keyOffset = indirectOffset + index * byteWidth;
|
||||||
|
final keyIndirectOffset =
|
||||||
|
keyOffset - _readUInt(keyOffset, BitWidthUtil.fromByteWidth(byteWidth));
|
||||||
|
for (var i = 0; i < input.length; i++) {
|
||||||
|
final dif = input[i] - _buffer.getUint8(keyIndirectOffset + i);
|
||||||
|
if (dif != 0) {
|
||||||
|
return dif;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return (_buffer.getUint8(keyIndirectOffset + input.length) == 0) ? 0 : -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
Reference _valueForIndexWithKey(int index, String key) {
|
||||||
|
final indirect = _indirect;
|
||||||
|
final elementOffset = indirect + index * _byteWidth;
|
||||||
|
final packedType = _buffer.getUint8(indirect + length * _byteWidth + index);
|
||||||
|
return Reference._(_buffer, elementOffset,
|
||||||
|
BitWidthUtil.fromByteWidth(_byteWidth), packedType, "$_path/$key");
|
||||||
|
}
|
||||||
|
|
||||||
|
Reference _valueForIndex(int index) {
|
||||||
|
final indirect = _indirect;
|
||||||
|
final elementOffset = indirect + index * _byteWidth;
|
||||||
|
final packedType = _buffer.getUint8(indirect + length * _byteWidth + index);
|
||||||
|
return Reference._(_buffer, elementOffset,
|
||||||
|
BitWidthUtil.fromByteWidth(_byteWidth), packedType, "$_path/[$index]");
|
||||||
|
}
|
||||||
|
|
||||||
|
String _keyForIndex(int index) {
|
||||||
|
final keysVectorOffset = _indirect - _byteWidth * 3;
|
||||||
|
final indirectOffset = keysVectorOffset -
|
||||||
|
_readUInt(keysVectorOffset, BitWidthUtil.fromByteWidth(_byteWidth));
|
||||||
|
final byteWidth = _readUInt(
|
||||||
|
keysVectorOffset + _byteWidth, BitWidthUtil.fromByteWidth(_byteWidth));
|
||||||
|
final keyOffset = indirectOffset + index * byteWidth;
|
||||||
|
final keyIndirectOffset =
|
||||||
|
keyOffset - _readUInt(keyOffset, BitWidthUtil.fromByteWidth(byteWidth));
|
||||||
|
var length = 0;
|
||||||
|
while (_buffer.getUint8(keyIndirectOffset + length) != 0) {
|
||||||
|
length += 1;
|
||||||
|
}
|
||||||
|
return utf8.decode(_buffer.buffer.asUint8List(keyIndirectOffset, length));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class _VectorIterator
|
||||||
|
with IterableMixin<Reference>
|
||||||
|
implements Iterator<Reference> {
|
||||||
|
final Reference _vector;
|
||||||
|
int index = -1;
|
||||||
|
|
||||||
|
_VectorIterator(this._vector);
|
||||||
|
|
||||||
|
@override
|
||||||
|
Reference get current => _vector[index];
|
||||||
|
|
||||||
|
@override
|
||||||
|
bool moveNext() {
|
||||||
|
index++;
|
||||||
|
return index < _vector.length;
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Iterator<Reference> get iterator => this;
|
||||||
|
}
|
||||||
|
|
||||||
|
class _MapKeyIterator with IterableMixin<String> implements Iterator<String> {
|
||||||
|
final Reference _map;
|
||||||
|
int index = -1;
|
||||||
|
|
||||||
|
_MapKeyIterator(this._map);
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get current => _map._keyForIndex(index);
|
||||||
|
|
||||||
|
@override
|
||||||
|
bool moveNext() {
|
||||||
|
index++;
|
||||||
|
return index < _map.length;
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Iterator<String> get iterator => this;
|
||||||
|
}
|
||||||
|
|
||||||
|
class _MapValueIterator
|
||||||
|
with IterableMixin<Reference>
|
||||||
|
implements Iterator<Reference> {
|
||||||
|
final Reference _map;
|
||||||
|
int index = -1;
|
||||||
|
|
||||||
|
_MapValueIterator(this._map);
|
||||||
|
|
||||||
|
@override
|
||||||
|
Reference get current => _map._valueForIndex(index);
|
||||||
|
|
||||||
|
@override
|
||||||
|
bool moveNext() {
|
||||||
|
index++;
|
||||||
|
return index < _map.length;
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Iterator<Reference> get iterator => this;
|
||||||
|
}
|
||||||