Squashed 'third_party/flatbuffers/' changes from 338393f85..e5f331db9
e5f331db9 [TS] Add single-file ts codegen & bazel rule for typescript (#7161)
2f84c6038 Apply Namer to Go code gen (#7150)
d64839651 [Lobster] file_identifier support
777e78d8d [Lobster] support unsigned integer reads
4016c549d Apply Namer to Python code gen (#7146)
40827b21b Fix missing 'break' (#7151)
65a10b6e3 Implement a config based name manager and use it in Rust codegen (#7144)
8db2fef3f [TS] Escape keywords in typescript object names (#7137)
9ed132304 Fix 64-bit numeric enum values in typescript (#7135)
1a4c40566 updated npm to 2.0.6
318594e4b prevent name clash (#7133)
3d903302c [Rust] Add length checks to arrays and vectors. (#7130)
c9571d989 Replaced ToDasherCase with ConvertCase (#7131)
3694b830a Use ConvertCase instead of Make{Upper,Lower,Snake} implementations (#7127)
0471fa807 remove stall reference to version
914344ea9 some minor help edits
b40266c56 Use target_compile_features to target C++11 (#7122)
8a9303d46 update proto tests with alaised enum (#7121)
30c4bf47f Trigger fuzzing CI only on relevant changes (#7120)
46ce45601 remove auto generate code from cmakelists (#7119)
433312c55 add the missing checkNullConditionnal code in the "GenObjApi" function when the field is scalar optional (#7114)
9c52ec374 Add deps attribute to flatbuffer_cc_library (#7107)
70e2f49bf fixed string-json -> strict-json typo
5ac0367ed [TS] Fix generation of reserved words in object api (#7106) (#7115)
5d101afb5 Fix minor typo in WhitePaper.md (#7108)
06f4af11b Go optional scalars (#7104)
57e338f81 explicitly use windows-2019 to unblock ci (#7105)
615616cb5 Change Rust generated file defaults (#7101)
3413c3300 Fixed FlexBuffers verifier fuzzer timing out
69f5660a4 Fixed Parser not checking size of union types vector
d5add9fca Fixed FlexBuffers ToString unquoted non-ident keys
15df50eb7 Remove @ExperimentalUnsignedTypes annotation from kotlin code generator. (#7092)
a94132a45 Swift FlatBufferBuilder.sizedByteArray to ByteBuffer.toArray() (#7093)
48befb6be [TS] Refactor away circular ref (#7099)
b30069133 Add reflection support for python (#7026)
faadbc10e Add CreateVector overload to accept array like (#7095)
ed6ae8d32 explicitly defined std::allocator (#7094)
e910bddbc [JS] Add ".js" suffix to all import statements to generate a browser compatible mjs version. (#7086)
c85fb690f Add Parsing Completed function for Rust (#7084)
c1daa6ba0 rust: Bump thiserror version and remove git dependency (#7080)
4c71c7b02 replace framework include of flatbuffers (#7079)
f5664d33f fix go_test implement error (#7012)
39c8a19ce fixed comparator for native_inline (#7076)
826193ff6 skip generating reflection.fbs in generate_scripts (#7077)
fd0d1ed92 update C++ generator to emit scoped enums in vector of unions (#7075)
424988f30 replaced removed xml tag
b2550dbaa removed BSD-3-Clause license and Zlib licenses (#7073)
a2b238960 Fixed default value of bool in struct for Swift (#7072)
619b78437 one last dart omit local (#7070)
68a766154 more omit type annotations for dart local variables (#7069)
7dac9961f omit type annotations for dart local variables (#7067)
c65c389c6 add xmlns to .Net (#7066)
6446dcf3d Updates swift gen licence for grpc code (#7063)
e090d8da1 Fixed long cast to int in flexbufferbuilder.java (#7059)
bc901436d clang format on codebase (#7058)
240be9b5a attempt to remove appveyor (#7056)
bc366a7f9 Provide a short help text and default in error case (#6992)
14b19d446 Use FindPython3 (#7055)
9e6f17b94 remove BIICODE
c3801ad37 Update readme.md
4f3b24db0 Fixes a bug where bools arent being nil when marked optional (#7051)
1d294a31b Implement Serialize on generated rust types (#7022)
dd8fccfb1 Cmake 3.16 de-facto minimum version (#7049)
7089c9ecd Convert flatbuffers_version_string to inline function (#7046)
43203984f [C++] Support C++ object copies and moves (#5988)
5993338ee [ts] Builder incorrectly serializing empty strings (#7047)
19920db39 Include a SizePrefixed..HasIdentifier for c++. (#6871)
dbbaeac85 Use `${PYTHON_EXECUTABLE}` instead of `py` in cmake (#7042)
028f0fde6 'flattest': Add --test_path option (#7041)
87343631b Added support for clang-cl on windows (CMake) (#7038)
1fbfaf5c5 Fix/cmake build grpc (#7028)
4421375bb Add FlatBuffers::FlatBuffers interface, needed for FetchContent_Declare (#7023)
162ad7a37 Fix comment with line orders - Rust should be last. (#7037)
a0a6c3f8c Use actions/checkout@v2, which fixes security vulnerability. (#7036)
a2d38fbb9 Add --warnings-as-errors to flatc compiler. (#7034)
9ef1524d3 Emit include for bfbs-gen-embed (#7031)
0c9de0352 Upgraded GRPC version to 1.42.0 (#7033)
a783bc926 chore: dart 2.0.5 release changes (#6983)
aff818ceb rust: Allow for usage in no_std environment (#6989)
d7b75417f Make flatbuffer builder deterministic (#6993)
a42e89897 Added verifier alignment checking to table fields (#7018)
96cc2f3ee BuildFlatBuffers.cmake: fix arguments not passed properly to flatc (#7013)
3250a1f8d Add initial C# vector of unions support to the documentation. (#6880)
ace4a37f2 [TS/JS] BigInt implementation (#6998)
f28c2b293 Avoid implicit conversion from float to double. (#7003)
96f3cf690 Rearrange #include directives to pass to compilation with a particular DSP toolchain (#7000)
b3edfdbfb Reverting grpc generated file suffix (#6995)
b8aaccee8 Disable parsing of nested_flatbuffers as bytes by default
2dc8ae774 Enable OSS-Fuzz on CI
5b0d49112 Updated FlexBuffers fuzzer
d8b7041d7 Added alignment checking to FlexBuffers verifier
5a0c3366c FlexBuffers verifier additionally checks for nesting
f8148b8da Made FlexBuffers reuse tracker track types
a22b1b626 Prevent shadow with _{{FIELD_NAME}} (#6991)
4264daadd FlexBuffers fuzzer fixes
3cbc120a0 Refractor Flatc Options (#6987)
8dcd2682c [CMake] Add option for disable universal on OSX (#6990)
b78002ff3 Validate C# json/object-api options (#6985)
c555ee8fa Add .NET test to github workflows (#6982)
b92bb0584 [CMake]: Fix version in pkgconfig file (#6986)
956d11569 re-enabled FlexBuffer JSON in fuzzer
e367ca32a Verifier for FlexBuffers (#6977)
705f27f6e [CMake]: Fix python command for mingw environment (#6984)
5fc87f4c4 Enable --gen-onefile in Python (#6953)
11749095a Make idl_parser deterministic (#6976)
d0cede9c9 Bumping to Version 2.0.5 (#6967)
fcc2bee0b Fix typo in variable name (#6973)
e08da4dea remove Appveyor's Vs2010 and 13 builds (#6969)
18538c401 [TS] Fix reserved words as arguments (#6955) (#6956)
e57f4ab2d Update stale bot version and provide away to exempt issues with the not-stale label (#6968)
deed68db5 missing generated files (#6966)
061d61f3f Lua Generator using IR. (#6940)
cffe0c454 FixedTypedVector: add const to ElementType() and size() (#6965)
fadd40e40 Have grpc include file with correct filename-suffix given to flatc (#6954)
e47dc0e46 Removed test/generate_code.{sh|bat} (#6873)
5c5475479 switched to windows-lastest, removed deadcode (#6948)
4f7f6dc30 Restore FlatBufferBuilder::kFileIdentifierLength. (#6960)
0fadaf391 Enable verifier on nested_flatbuffers
4d0e9a870 Turn off nested FlatBuffers/FlexBuffers for the fuzzer
c05f6783a invalid conditional running genrate_code.py (#6952)
a14f4052c rust: remove needless borrow (#6922)
9e4ca857b Vector Downward GetSize optimization (#6925)
a2b99084b Fix flexbuffers clang-analyzer warning (#6947)
85b4effac test: fix undefined order of functio parameters. (#6946)
790f41154 [cmake] Fix getting version info from tags during the build (#6936)
e89de4411 clang-all (#6941)
256ab3798 WIP: Dart release 2.0 (#6927)
a59288a01 Add benchmarks to Linux CI (#6928)
587bbd49a [C++] Fix compile failure on Object API union construction for struct member (#6923)
a9c341545 Fix integer overflow warnings
8aa18b629 fixed cmp0048 error (#6932)
d727579b6 fuzzers: fix typo in file path (#6931)
97a30171c Added Raw C++ benchmarks (#6924)
0989fc5e5 Added Google benchmarks (and gtests) (#6920)
927175ea2 [Java] lookup by byteArray is giving back wrong entry (#6915)
6748c373b Removal of support for FLATBUFFERS_CPP98_STL (#6918)
3fab0c6ee move [[ ]] to calling sites (#6914)
6c8c29155 [C++] Split flatbuffers.h into separate files (#6868)
fd4ff23da Keep methods with struct name and switch them to default (#6879)
f8b69e330 [Python] Verify EnumDef is not generated in GenUnionCreator (#6903)
c0394bb09 Support `--conform` for vector of unions (#6883)
8433eb108 Typo fixes in comments of flatbuffers.h and flexbuffers.h (#6901)
f2f9380c8 [Java] Prevent generation of enum names when underlying type is long (#6781) (#6895)
e672dabfe [C++] Fix memory leak when using grpc (#6896) (#6897)
9a4ca2764 Output errors / warnings on stderr instead of stdout (#6881)
4c7a9c10d Adds JSON encoding to swift (#6874)
38295a187 [Kotlin] Fix missing escape for struct construction statements (#6877)
31bb0b972 add working directory (#6878)
45e5642e9 Default Arguments for Mutators C++ [Updated] (#6872)
a592f4c89 [Cmake] Add a post build command after flatc to run the new generate_code.py script. (#6866)
b9d43a557 dart - add Packable interface (#6846)
2ece9e25b Bumped package.json to 2.0.4
2dd212637 Fix linker errors on (Free|Open)BSD. (#6860)
f63c130c2 Improves documentation, and adding DocC (#6784)
e2b26ee19 Make and generate_code.sh generate same outputs (#6855)
9d686bf43 Include subdirectories in published npm package (#6850)
1d26daff3 Use ArrayBuffer type for JS flexbuffer's toObject (#6851)
e72e18d9f feat(build): compile "universal" libraries and executables for Mac (#6852)
354d97f6d fixed errant itemgroup element in C# test project (#6854)
6f7a57eaa [C#] Using 'global::' as qualifying_start_ within BaseGenerator (#6767)
90baa1444 Dart: binary lists (typed_data) (#6839)
0a3b017f0 Delete IDLOptions::lang (#6841)
47d35f105 BugFix: Optional enum when it is null (#6835)
8fb8c2ce1 [C#] Use @ for keyword escaping (#6834)
1d063d87c [C++] Let builder accept custom-alloc std::vector (#6814)
338331b55 Changes to support binary schema file loading and parsing (flatc) (#6823)
156a30c75 Move Apple-specific build flags to Clang section (#6802)
550d2f904 Issue error if jsonschema has no root type defined #6821 (#6831)
c3a38242e Fix typos in docs (#6829)
74c3d7eba [C++] Add mutable version of LookupByKey and test (#6826)
db6eae5c4 Add html and latex to gitignore (#6819)
0e9d79c35 [Java] Avoid casting ByteBuffer to Buffer (#6785)
b20c4d3aa [C++] Add GetMutableSizePrefixedRoot and generate GetMutableSizePrefixedXxx functions (#6815)
ae145293c flattests_cpp17 doesn't compile with Visual Studio 2017: warning C4100: 'indent': unreferenced formal parameter (#6811)
e3c76a5cd Dart lints (#6808)
4b9123baf fix parser string=null (#6810)
f89e0b1a6 Refactor idl_gen_rust and Rust generated code to use consistent whitespace (#6809)
273f6084e Fix Rust keyword inconsistency (#6794)
4a0879458 [C#] Remove superfluous semicolon in C# structs (#6791)
d6f51ea16 fix ptr in flatbuffers cpp tutorial (#6787)
067dce6e7 [C#] Handle keywords (#6775)
2ca5f0e72 [C#] Respect command line parameter for file name extension and suffix (#6779)
f20d2253a update Java version to 2.0.3
390d438e2 [Kotlin] Fix CI by changing compiler to Java 11 (#6783)
6fb2c90d9 avoiding even more NoSuchMethod exceptions (#6729)
a7b527d94 java: Use maven profile to target Java 8 bytecode (#6764)
5d77820b3 [C++] Using calculated fields_number for field_names size (#6769)
909ce970a [C++] Use UnPackTo instead of UnPack if pointer exists (#6725)
35e2cac6e Store vtables sorted in Rust builder (#6765)
c39fc9dd9 [C++] Use nullptr instead of 0 in generated headers (#6762)
775c6567d [C++] Fix compiler warning -Wredundant-parens in clang (#6761)
97d9527f6 Dart 2.0 release prep (#6759)
e01205466 [C++] Use proper gRPC C++ API when using MemoryBuffer Slice (#6756)
5235133f3 Dart - make ascii optimization optional in StringReader, same as in writeString() (#6758)
c871df770 Dart - change table building to assert() instead of exceptions (#6754)
a6eeeb3b9 Dart - inline small functions to increase performance (#6755)
3dd02144d [C#] Fix field name struct name collision (#6744) (#6757)
e77926f0e [C#] Add Union Constructor Utility for ObjectAPI. (#6105)
ac2348202 Dart - fixup writeString() return type after previous merges (#6753)
8be8a0a71 [C++] Fix union type handling on object api in C++17 (#6745)
12e341e4f Rework how Rust generated files are laid out (#6731)
c36672d80 Dart - optimize writeString for ASCII (#6736)
2bfc8e9f0 Dart - make writeString() argument non-nullable (#6737)
674a9f2aa fix lints in rust tests (#6743)
016e6aa13 Add a split on ':' to build_defs.bzl (#6742)
65700441d Dart - make vTable fixed size (expect the number of fields when creating) (#6735)
dd5bb55ca Dart - make vTable deduplication optional (#6734)
e8423da1b Dart - regenerate example after recent flatc changes (#6733)
0980e39c9 flexbuffers: Add variant of Blob() that takes a key (#6730)
e73fab27d Dart - store empty vectors instead of NULL (#6728)
92ae532e4 Dart - finish/lowFinish/buffer changes (#6712)
7482b25f8 Remove ubuntu1604 from presubmit.yml (#6715)
3f77dc9a0 Dart - unpack() must use eager list reader (#6723)
838c93b84 Dart - fix flex-builder compilation error (#6722)
089f48a4a Dart - make sure added padding is zeroed, same as in C++ (#6716)
bf3470c16 Fix UB in CreateVectorOfStructs in case of an empty vector: avoid calling memcpy in this case (#6726)
8f8196e13 Fix 6348 (#6717)
8ab35b2a5 Dart - add custom allocator support (#6711)
c0ba2870c Fix typo in docu (#6714)
22498cf3a [C++] add make_span for Array<T,N> (#6663)
bd37e67ac [C++] Fix a -Wdeprecated-copy warning. (#6708)
a6ee33557 Dart null safety (#6696)
71d43f3be Make --bfbs-filenames default to location of first schema file. (#6705)
c8db1ca5d Jsonschema add prop comments (#6617)
962751a6e Improve generated comparisons for tables (#6486)
06fd6d640 Replace filenames in reflection with filenames+includes. (#6703)
acce4ac3f Fix incorrect assertion usage. (#6702)
8fd7861b7 Fix warning about deprecated module: imp (#6362)
c58ae9422 Add the file a symbol is declared in to Reflection (#6613)
2cf7bb796 Intermediate Representation docs (#6685)
4e3a66c14 Dart object API (#6682)
d959e2320 dart - change Builder.reset() to reuse an existing buffer (#6661)
a9fb54088 use improved versioning (#6691)
337eb8b8f update docs - structs can't be roots (#6690)
6415ef05d [Python] [Codegen] Fixes nested structs with underscore names (#6686)
f069396d1 [C++] flatc --cpp-field-case-style option to permit camel-case field names in C++ (#6669)
021177af0 Fix snap version formatting (#6683)
e1e9f9373 [C++/grpc] added hiding of unused variables in the generated code (#6677)
15110094e Fix GitHub Actions CI gcc/clang versions
093badb0a Use unoptimized path for ReadUInt64 for win32 build as the optimized path crashes. (#6681)
752c7b576 avoiding more NoSuchMethod exceptions (#6671)
7c3e267e1 [Java] ObjectAPI implementation (#6521) (#6582)
baaffbaed npm update to 2.0.3 and script fix
4cb3f222b [TS] Fix module reference in package.json (#6676)
eabdbda75 [TS] Generate entry point module (#6674)
bec23700f Prepare for Java 2.0.1 release
12f2eedad Update CI to GCC/Clang 11
221eeb231 Fix typo in C++ doc (#6664)
813d3632e avoiding NoSuchMethod exception (#6658)
d84bccb0c Removed most heap allocations in builder (#6662)
b4e67f9bf Dart test fix (#6660)
54c11932f [Java] Flexbuffers - Negative signed object length (#6651)
fbcb3c423 [TS/JS] Updates the grpc (#6654)
8937dcfd7 Updates go lang support to allow other languages to communicate with it (#6653)
512d5a689 Update readme.md to point to security policy
a92cb5dd7 Create Security.md
d151dcbb9 Revert "[C++] Removed most heap allocations in builder (#6620)" (#6659)
f1884c66f Fix gRPC test to use EndVector without specifying the length. (#6646)
72730ecd8 [C++] Removed most heap allocations in builder (#6620)
fe2bc2b0a Added README for Rust Flatbuffers (before publishing v=2.0) (#6652)
4867c9456 Fixed generation of c++ code with flags (#6637)
ef0eb3701 Ran clang-format-all.sh. Removed default --style=file parameter (#6639)
f83ee1af5 [idl_parser] Check structs and enums do not clash in a namespace (#6562)
a5175c513 Implements verifier and code gen for swift (#6373)
04b10f5a3 Deprecate EnumVal.object (#6612)
c121c0345 Fixed Java gRPC version number dependency
8fd10606c Implement Serialize for flexbuffer::Reader (#6635)
a1730fcea [Swift] Updated cocoapods to 2.0.0 (#6634)
a9a295fec More missing version changes
5c01ad387 Dart generated code update
42ca1b914 Swift/Kotlin generated code version updates
6ed780dbd C++/Rust version changes
3412fab8e C#/Java generated code version updates
8a7d013f8 Updated main version numbers to 2.0
170af5978 [Go] Add missing namespace when using Object API (#6633)
c8c16de16 Fix reverse iterators for Vector and Array (#6626)
4525cd9c5 [Lua] manipulate byte array as string (#6624)
47361baf6 [C++] Fix union copy constructor to work with nested structs (#6552) (#6607)
8a582883a Updates swift generated monster sample file (#6616)
a4bb8f0c2 [Lua] Avoid infinite loop when creating empty string (#6614)
82aed82b8 Added support for Lua 5.1, 5.2 and 5.4 (#6606)
60ff76630 [TS] Remove wrong and obsolete NS prefix use (#6604)
a27c7d809 Fixed LuaJIT when not compiled with COMPAT mode (#6605)
363220823 removed unneeded type prefixing (#6601)
6b44c605b Bump Rust to 0.9.0 (#6610)
d3cd78a87 [Lua] Add LuaJIT support (#6584)
8fa3dfdb5 Introduce new_from_vec in Rust (also fix formatting) (#6599)
29379e8e4 fix typo in CppUsage.md (#6595)
14725d6c3 [Lua] GetRootAs can accept strings. Made Luatest Benchmarks optional (#6593)
16836ff95 Add advance feature indicators to reflection (#6546)
c87179e73 Rust Remove SafeSliceAccess for Arrays, and fix miri. (#6592)
c24031c36 Mark endian_scalar as unsafe. (#6588)
4ccc52c7a [swift] Implements union strings (#6589)
b82fe0738 [Rust] Fix small mistyping (#6585)
1e7f6c8c7 [TS] Commit the generated tests code (#6579)
84714b109 chore: ensure bash is used to generate code (#6577)
1045d7dd4 [Lua] Fix EnforceNumberAndPack for bool type (#6576)
0c7777596 [TS] Remove duplicated build-ts ci (#6575)
c43ba1752 [Rust] Specify Minimum Supported Rust Version (#6573)
da3bb64ef [Rust] Add support for fixed size arrays (#6548)
151900ba9 [Kotlin][FlexBuffers] Add support for Kotlin-iOS (#6564)
c012f29f9 silenced clippy warning (#6565)
df2df21ec [Kotlin] Bump kotlinx.benchmark dependency to 0.3.0 (#6560)
408e4db4a [TS] Add Build TS to CI jobs (#6524)
4d2364f34 [Kotlin][FlexBuffers] Add support for Kotlin-JS (#6554)
261cf3b20 Default-empty vectors of enums (#6505)
cd67261bb [CI] fixes buildkite (#6544)
1aa0c2f6a Limit formatter to pull requests only (#6540)
4133a39df Rust structz (#6539)
1c26d2a1a [Kotlin][FlexBuffers] JSON support for Flexbuffers (#6417)
276b1bc34 [grpc] Support latest version of grpc PoC (#6338)
124654ffc fixed packing structs (#6530)
3b7d1e86b [GO] Tries to add go format to the CI (#6518)
78f0c0d1d [C++] #6501 - Problem when mapping a native type multiple times (#6514)
c992eafb5 [fuzzer] Add `monster_debug` target (#6513)
ef8dd7792 [Swift] Removes allman rule (#6519)
69b329fc8 [flexbuffers, json] Parse `nan` and `inf` (#6512)
6543ba529 fixed packing structs in nested buffers (#6509)
0e453ac35 [idl_parser] Add kTokenNumericConstant token (#6432)
e9b4ae69d Remove `flatbuffers.pc` from the repository (#6508)
fc4fffea4 Bump grpc to 1.0.0 (#6507)
b240ab704 Move Traits struct and Create method out of --cpp-static-reflection. (#6503)
9a4f1f434 Disable x64-specific optimizations for ARM64EC ReadInt64 (#6506)
fac64918d Add --cpp-static-reflection to generate_code.bat. (#6502)
a69815f72 [C++17] Add compile-time reflection for fields. (#6324)
4033ff589 fixed invalid TS call and added test files (#6495)
a08357251 disable clippy (#6494)
5319dedb1 [idl_parser, JSON] Disable parsing of JSON for incomplete schemes (#6493)
bd4e0b30a [idl_parser] Track included files by hash (#6434)
bf9061200 fix for noUncheckedIndexedAccess in ts (#6474)
8142fedd1 Working on a python example plus fixing python grpc code (#6456)
c0be1cb7a [rust] Remove debug code (#6475)
8cccdfba5 Revert "[C#] Fix truncated ArraySegment<byte> if elementSize != 1 (#6462)" (#6488)
cbbbaa61b [C#] Fix truncated ArraySegment<byte> if elementSize != 1 (#6462)
ffc2ef77c [CI] Adds Code Generation tests on Github Actions (#6482)
1da6f4f18 [CMake] generate pkg-config flatbuffers.pc file (#6455)
b5da526e6 [Swift] Moves grpc example to grpc/examples (#6479)
3b5365762 [TS] Moves grpc code to examples folder (#6476)
e2f5438ac Fixes grammer (#6477)
5e3613f73 Fix sample_binary.py to use latest EndVector without a size. (#6478)
e6b911d40 updated JS docs to reflect current status (#6436)
0c7ae5816 [Go] Working on a go example plus fixing go grpc code (#6448)
ae603b977 [Swift] adds support for default vectors and strings (#6461)
7f47718b6 Update Building.md (#6473)
54dc09e8a GetUOffsetT must get value by GetUint32 not GetInt32 (#6072)
334c6be49 Fix a typo in Swift codegen (#6470)
4174c10e7 [rust] Genericize flexbuffer reader (#6450)
a20f606c2 [Swift] Renaming protocols (#6469)
a72a20827 Update swift docs (#6460)
86401e078 Default strings and vectors: Parser + Rust support (#6421)
6af37e672 [CMake] Renames BUILD files (#6457)
1b88655b0 [Build, cmake] Add -Werror override option (#6429)
0b15916e5 [C++]Fix extra char generation for byte type during json schema generation (#6276)
60eed0ca6 Updating working code (#6441)
0f83367f5 JSON schema - tailing double quotes for maximum (#6452)
fee095410 [idl_parser] Validate `force_align` on all possible paths (#6430)
6f3e45eca Implement Rust object API defaults (#6444)
815d3e820 Upgrade swift grpc to alpha 24 (#6439)
76e7a0ff5 [fuzzer] Limit parser_fuzzer execution time (#6431)
6d91096a2 This commit contains the initial implementation of Flexbuffers in Kotlin. The code was ported based (#6387)
13d9e3585 Better python generated code naming (#6336)
6effe431b Rust: remove inner attributes (#6410)
efcbdc769 [Rust] Ensure unions are referenced with the correct path (#6422)
e581013e3 Refactor FieldDef to model presense as an enum rather than 2 bools. (#6420)
0984d4328 [c++] Apply NativeName before WrapInNameSpace in idl_gen_cpp.cpp (#6419)
786f69b24 Formats cpp code (#6349)
1da0a2dfa Rust Object API (#6070)
796ed68fa Clarify that (Flat|Flex)Buffers do not deduplicate vector elements (#6415)
7b1ee31d8 Clarify that FlatBuffers unions do not support scalars (#6416)
4aff1198d Explain how FlatBuffers encodes unions (#6414)
ad3a729f9 dart Builder - expose finished buffer size (#6403)
52e217706 Remove invalid claim that Protocol Buffers does not support unions (#6413)
760c65755 [TS/JS] New gen TS code gen (#6302)
75c859e98 [idl_parser] Improve symbols lookup thru parent namespaces (#6407)
91b0958c4 Search for includes in the directory containg the current file (#6371)
8008dde11 Upgrade Rust dependencies (#6406)
c81cf8249 [TS/JS] New gen TS code gen prequel to preserve history (#6404)
8573108bb Unset FieldDef.optional if its key (#6402)
7abe612b5 [fuzzer] Fix the binary schema loading in the monster_fuzzer (#6396)
408cf5802 Fix Rust UB problems (#6393)
39e115fdb Define Vector::value_type for STL compatibility (#6394)
85719669c [fuzzer] Debug the monster_tets.bfbs on clusterfuzz server (#6392)
809fe49c7 Fix up scripts, fix generated enum value for strong mode, regenerate files (#6389)
41253e574 [go] tests/GoTest.sh: Fix flags.Parse location to work on new go SDKs. (#6388)
08d2ce844 fix Dart Builder._writeString() - always write trailing zero byte (#6390)
a15a8d930 fix Dart Builder.reset() - clear vTables (#6386)
83ce29cc2 [C++, JSON] Fix nullptr access when reading a key with a default value. (#6375)
4363c1d2c Fix generated EndVector. (#6385)
1bf1ec027 Implements type promotion for Java enum (#6382)
080097653 Delete label_notify.yml
795408115 Disabled PHP CI (#6381)
46545e627 fixed warnings (#6355)
0168178a1 Fix multiple fbs code generation failure (#6365)
82836a62b [idl_parser] Improve stack overflow protection (#6364)
e7430bbeb [idl_parser] Check the range of explicitly set field's id value (#6363)
24dd85fd2 Generate code to encode and decode nested flatbuffers in Python. (#6354)
57f68e289 [Rust] Shared String (#6367)
44cf2bde1 Updates license date to 2021 (#6378)
be37d4da1 include_prefix support for rust (#6330)
4e79d129c [Swift] Rebuild the way swift handles structs from scratch (#6326)
05192553f Fix typos in usage/comments; Make rust generator respect to --filenam… (#6342)
f2511d7d4 Renaming infinity variables in test.cpp (#6340)
f8b203c9c Add vectorNumElements attribute to Builder for simpler vector creation. (#6328)
8ab7c7e2c [CI] Adds formatter to CI (#6272)
7e0039028 Fix Max CI build path (#6333)
65c415911 Generate nullable properties in C# object-based API for optional scalars. (without -gen-mutable) (#6273)
a9e91116d [Python] Commit some orphan python genfile diffs. (#6325)
80a745d9b Fixed missing ending quotes in labeller (#6327)
9fca5e4f4 Add flatc option to inhibit all warnings #6005 (#6301)
92a806b4e [fuzzer] Rename fuzzing dictionaries for `oss-fuzz` (#6318)
9c9baf6d5 bumprust (#6322)
aafc5dc95 Set default initialSize for Builder to 0 (#6310)
442949bc1 Rust Flatbuffers Verifier (#6269)
9064072e8 Version message should be a "STATUS" to avoid going to stderr. (#6316)
fd4c1b5ff Replace std::string and const char* CreateSharedString with string_view (#6315)
bc7eb8ade [fuzzer] Fix mistakes in the `parser` and `scalar` fuzzers. (#6314)
fc960f367 Add default to offset param of Python generated GetRootAs (#6312)
f437f0f7e [fuzzer] Fix loading of schema in monster_fuzzer (#6308)
7f33cf682 [C++] Switch `flatc` to `--cpp-std c++11` C++ code generator (#6306)
8d9eae9ac [idl_parser] Unify parsing of NaN values read from .fbs and .json files (#6296)
2046bffa4 Moved various language tests from AppVeyor to GitHub Actions (#6300)
git-subtree-dir: third_party/flatbuffers
git-subtree-split: e5f331db998a808f78cf5a4880e6f5d0a321c4d0
Signed-off-by: James Kuszmaul <jabukuszmaul+collab@gmail.com>
Change-Id: I37f8aaf007fc86226cfa250169a87807afa64a78
diff --git a/docs/source/Building.md b/docs/source/Building.md
index ad9e972..d7e9ca3 100644
--- a/docs/source/Building.md
+++ b/docs/source/Building.md
@@ -29,6 +29,27 @@
*Note that you MUST be in the root of the FlatBuffers distribution when you
run 'flattests' or `flatsampletext`, or it will fail to load its files.*
+### Make all warnings into errors
+
+By default all Flatbuffers `cmake` targets are build with `-Werror` flag.
+With this flag (or `/WX` for MSVC) C++ compiler will treat all warnings as errors.
+Additionally `-Wall -pedantic -Wextra` (or `/W4` form MSVC) flags are set.
+These flags minimize the number of possible defects in code and keep code highly portable.
+Using these flags is considered good practice but sometimes it can break dependent projects
+if a compiler is upgraded or a toolset is changed.
+Usually, newer compiler versions add new compile-time diagnostics that were unavailable before.
+These new diagnostic warnings could stop the build process if `-Werror` flag is set.
+
+It is possible to cancel `warnings as errors` flag at `cmake` configuration stage using
+`FLATBUFFERS_CXX_FLAGS` option. Compilation flags declared in `FLATBUFFERS_CXX_FLAGS` will be
+appended to the project-level `CMAKE_CXX_FLAGS` variable.
+Examples:
+
+- GCC and Clang: `cmake . -D FLATBUFFERS_CXX_FLAGS="-Wno-error"`
+- MSVC: `cmake . -D FLATBUFFERS_CXX_FLAGS="/WX-"`
+- MSVC: `cmake . -D FLATBUFFERS_CXX_FLAGS="/Wv <compiler.version>"`
+
+
## Building with VCPKG
You can download and install flatbuffers using the [vcpkg](https://github.com/Microsoft/vcpkg/) dependency manager:
@@ -100,14 +121,3 @@
set(FLATBUFFERS_MAX_PARSING_DEPTH 16)
```
to `CMakeLists.txt` file before `add_subdirectory(${FLATBUFFERS_SRC_DIR})` line.
-
-#### For Google Play apps
-
-For applications on Google Play that integrate this library, usage is tracked.
-This tracking is done automatically using the embedded version string
-(flatbuffer_version_string), and helps us continue to optimize it.
-Aside from consuming a few extra bytes in your application binary, it shouldn't
-affect your application at all. We use this information to let us know if
-FlatBuffers is useful and if we should continue to invest in it. Since this is
-open source, you are free to remove the version string but we would appreciate
-if you would leave it in.
diff --git a/docs/source/CUsage.md b/docs/source/CUsage.md
index 9aafa6f..bd1ec15 100644
--- a/docs/source/CUsage.md
+++ b/docs/source/CUsage.md
@@ -7,7 +7,7 @@
online via a C library. It can also generate buffer verifiers and fast
JSON parsers, printers.
-Great care has been taken to ensure compatibily with the main `flatc`
+Great care has been taken to ensure compatibility with the main `flatc`
project.
## General Documention
diff --git a/docs/source/Compiler.md b/docs/source/Compiler.md
index 973c411..242506a 100644
--- a/docs/source/Compiler.md
+++ b/docs/source/Compiler.md
@@ -79,7 +79,7 @@
- `--allow-non-utf8` : Pass non-UTF-8 input through parser and emit nonstandard
\x escapes in JSON. (Default is to raise parse error on non-UTF-8 input.)
-- `--natural-utf8` : Output strings with UTF-8 as human-readable strings.
+- `--natural-utf8` : Output strings with UTF-8 as human-readable strings.
By default, UTF-8 characters are printed as \uXXXX escapes."
- `--defaults-json` : Output fields whose value is equal to the default value
@@ -101,7 +101,7 @@
- `--gen-mutable` : Generate additional non-const accessors for mutating
FlatBuffers in-place.
-- `--gen-onefile` : Generate single output file for C# and Go.
+- `--gen-onefile` : Generate single output file for C#, Go, and Python.
- `--gen-name-strings` : Generate type name functions for C++.
@@ -142,23 +142,14 @@
- `--cpp-std CPP_STD` : Generate a C++ code using features of selected C++ standard.
Supported `CPP_STD` values:
- * `c++0x` - generate code compatible with old compilers (VS2010).
- * `c++11` - use C++11 code generator (default);
+ * `c++0x` - generate code compatible with old compilers (VS2010),
+ * `c++11` - use C++11 code generator (default),
+ * `c++17` - use C++17 features in generated code (experimental).
- `--object-prefix` : Customise class prefix for C++ object-based API.
- `--object-suffix` : Customise class suffix for C++ object-based API.
-- `--no-js-exports` : Removes Node.js style export lines (useful for JS)
-
-- `--goog-js-export` : Uses goog.exportsSymbol and goog.exportsProperty
- instead of Node.js style exporting. Needed for compatibility with the
- Google closure compiler (useful for JS).
-
-- `--es6-js-export` : Generates ECMAScript v6 style export definitions
- instead of Node.js style exporting. Useful when integrating flatbuffers
- with modern Javascript projects.
-
- `--go-namespace` : Generate the overrided namespace in Golang.
- `--go-import` : Generate the overrided import for flatbuffers in Golang.
@@ -206,12 +197,6 @@
- `--keep-prefix` : Keep original prefix of schema include statement.
-- `--no-fb-import` : Don't include flatbuffers import statement for TypeScript.
-
-- `--no-ts-reexport` : Don't re-export imported dependencies for TypeScript.
-
-- `--short-names` : Use short function names for JS and TypeScript.
-
- `--reflect-types` : Add minimal type reflection to code generation.
- `--reflect-names` : Add minimal type/name reflection.
@@ -228,5 +213,16 @@
- `--force-empty-vectors` : When serializing from object API representation, force
vectors to empty rather than null.
+- `--flexbuffers` : Used with "binary" and "json" options, it generates
+ data using schema-less FlexBuffers.
+
+- `--no-warnings` : Inhibit all warning messages.
+
+- `--cs-global-alias` : Prepend `global::` to all user generated csharp classes and structs.
+
+- `--json-nested-bytes` : Allow a nested_flatbuffer field to be parsed as a
+ vector of bytes in JSON, which is unsafe unless checked by a verifier
+ afterwards.
+
NOTE: short-form options for generators are deprecated, use the long form
whenever possible.
diff --git a/docs/source/CppUsage.md b/docs/source/CppUsage.md
index 2333f48..82d6f15 100644
--- a/docs/source/CppUsage.md
+++ b/docs/source/CppUsage.md
@@ -56,7 +56,7 @@
First, include the library and generated code. Then read the file into
a `char *` array, which you pass to `GetMonster()`.
-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
+```cpp
#include "flatbuffers/flatbuffers.h"
#include "monster_test_generate.h"
#include <iostream> // C++ header file for printing
@@ -73,18 +73,18 @@
infile.close();
auto monster = GetMonster(data);
-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+```
`monster` is of type `Monster *`, and points to somewhere *inside* your
-buffer (root object pointers are not the same as `buffer_pointer` !).
+buffer (root object pointers are not the same as `buffer_pointer` \!).
If you look in your generated header, you'll see it has
convenient accessors for all fields, e.g. `hp()`, `mana()`, etc:
-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
- std::cout << "hp : " << monster->hp() << std::endl; // `80`
- std::cout << "mana : " << monster->mana() << std::endl; // default value of `150`
- std::cout << "name : " << monster->name()->c_str() << std::endl; // "MyMonster"
-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+```cpp
+ std::cout << "hp : " << monster->hp() << std::endl; // '80'
+ std::cout << "mana : " << monster->mana() << std::endl; // default value of '150'
+ std::cout << "name : " << monster->name()->c_str() << std::endl; // "MyMonster"
+```
*Note: That we never stored a `mana` value, so it will return the default.*
@@ -96,7 +96,7 @@
Specifically, `CreateXxxDirect` functions and `Pack` functions for object
based API (see below) will use `CreateSharedString` to create strings.
-## Object based API. {#flatbuffers_cpp_object_based_api}
+## Object based API {#flatbuffers_cpp_object_based_api}
FlatBuffers is all about memory efficiency, which is why its base API is written
around using as little as possible of it. This does make the API clumsier
@@ -109,7 +109,7 @@
To use:
-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
+```cpp
// Autogenerated class from table Monster.
MonsterT monsterobj;
@@ -123,7 +123,7 @@
// Serialize into new flatbuffer.
FlatBufferBuilder fbb;
fbb.Finish(Monster::Pack(fbb, &monsterobj));
-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+```
The following attributes are specific to the object-based API code generation:
@@ -133,27 +133,30 @@
This attribute changes the member declaration to use the type directly
rather than wrapped in a unique_ptr.
-- `native_default`: "value" (on a field): For members that are declared
+- `native_default("value")` (on a field): For members that are declared
"native_inline", the value specified with this attribute will be included
verbatim in the class constructor initializer list for this member.
-- `native_custom_alloc`:"custom_allocator" (on a table or struct): When using the
+- `native_custom_alloc("custom_allocator")` (on a table or struct): When using the
object-based API all generated NativeTables that are allocated when unpacking
your flatbuffer will use "custom allocator". The allocator is also used by
any std::vector that appears in a table defined with `native_custom_alloc`.
This can be used to provide allocation from a pool for example, for faster
unpacking when using the object-based API.
- Minimal Example:
+Minimal Example:
- schema:
+schema:
+```cpp
table mytable(native_custom_alloc:"custom_allocator") {
...
}
+```
- with custom_allocator defined before flatbuffers.h is included, as:
+with `custom_allocator` defined before `flatbuffers.h` is included, as:
+```cpp
template <typename T> struct custom_allocator : public std::allocator<T> {
typedef T *pointer;
@@ -172,51 +175,77 @@
}
custom_allocator() throw() {}
+
template <class U>
custom_allocator(const custom_allocator<U>&) throw() {}
};
+```
-- `native_type`' "type" (on a struct): In some cases, a more optimal C++ data
- type exists for a given struct. For example, the following schema:
+- `native_type("type")` (on a struct): In some cases, a more optimal C++ data
+type exists for a given struct. For example, the following schema:
- struct Vec2 {
- x: float;
- y: float;
- }
+```cpp
+ struct Vec2 {
+ x: float;
+ y: float;
+ }
+```
- generates the following Object-Based API class:
+generates the following Object-Based API class:
- struct Vec2T : flatbuffers::NativeTable {
- float x;
- float y;
- };
+```cpp
+ struct Vec2T : flatbuffers::NativeTable {
+ float x;
+ float y;
+ };
+```
- However, it can be useful to instead use a user-defined C++ type since it
- can provide more functionality, eg.
+However, it can be useful to instead use a user-defined C++ type since it
+can provide more functionality, eg.
- struct vector2 {
- float x = 0, y = 0;
- vector2 operator+(vector2 rhs) const { ... }
- vector2 operator-(vector2 rhs) const { ... }
- float length() const { ... }
- // etc.
- };
+```cpp
+ struct vector2 {
+ float x = 0, y = 0;
+ vector2 operator+(vector2 rhs) const { ... }
+ vector2 operator-(vector2 rhs) const { ... }
+ float length() const { ... }
+ // etc.
+ };
+```
- The `native_type` attribute will replace the usage of the generated class
- with the given type. So, continuing with the example, the generated
- code would use |vector2| in place of |Vec2T| for all generated code.
+The `native_type` attribute will replace the usage of the generated class
+with the given type. So, continuing with the example, the generated
+code would use `vector2` in place of `Vec2T` for all generated code of
+the Object-Based API.
- However, becuase the native_type is unknown to flatbuffers, the user must
- provide the following functions to aide in the serialization process:
+However, because the `native_type` is unknown to flatbuffers, the user must
+provide the following functions to aide in the serialization process:
- namespace flatbuffers {
- FlatbufferStruct Pack(const native_type& obj);
- native_type UnPack(const FlatbufferStruct& obj);
- }
+```cpp
+ namespace flatbuffers {
+ Vec2 Pack(const vector2& obj);
+ vector2 UnPack(const Vec2& obj);
+ }
+```
-Finally, the following top-level attribute
+- `native_type_pack_name("name")` (on a struct when `native_type` is
+ specified, too): when you want to use the same `native_type` multiple times
+ (e. g. with different precision) you must make the names of the Pack/UnPack
+ functions unique, otherwise you will run into compile errors. This attribute
+ appends a name to the expected Pack/UnPack functions. So when you
+ specify `native_type_pack_name("Vec2")` in the above example you now need to
+ implement these serialization functions instead:
-- `native_include`: "path" (at file level): Because the `native_type` attribute
+```cpp
+ namespace flatbuffers {
+ Vec2 PackVec2(const vector2& obj);
+ vector2 UnPackVec2(const Vec2& obj);
+ }
+```
+
+Finally, the following top-level attributes:
+
+- `native_include("path")` (at file level): Because the `native_type` attribute
can be used to introduce types that are unknown to flatbuffers, it may be
necessary to include "external" header files in the generated code. This
attribute can be used to directly add an #include directive to the top of
@@ -225,7 +254,7 @@
- `force_align`: this attribute may not be respected in the object API,
depending on the aligned of the allocator used with `new`.
-# External references.
+# External references
An additional feature of the object API is the ability to allow you to load
multiple independent FlatBuffers, and have them refer to eachothers objects
@@ -244,7 +273,7 @@
When you call `UnPack` (or `Create`), you'll need a function that maps from
hash to the object (see `resolver_function_t` for details).
-# Using different pointer types.
+# Using different pointer types
By default the object tree is built out of `std::unique_ptr`, but you can
influence this either globally (using the `--cpp-ptr-type` argument to
@@ -255,13 +284,13 @@
pointer type specified by the `--cpp-ptr-type` argument to `flatc` from a
flatbuffer field set the `cpp_ptr_type` attribute to `default_ptr_type`.
-# Using different string type.
+# Using different string type
By default the object tree is built out of `std::string`, but you can
influence this either globally (using the `--cpp-str-type` argument to
`flatc`) or per field using the `cpp_str_type` attribute.
-The type must support T::c_str(), T::length() and T::empty() as member functions.
+The type must support `T::c_str()`, `T::length()` and `T::empty()` as member functions.
Further, the type must be constructible from std::string, as by default a
std::string instance is constructed and then used to initialize the custom
@@ -270,7 +299,7 @@
per field attribute `cpp_str_flex_ctor` can be used to change this behavior,
so that the custom string type is constructed by passing the pointer and
length of the FlatBuffers String. The custom string class will require a
-constructor in the following format: custom_str_class(const char *, size_t).
+constructor in the following format: `custom_str_class(const char *, size_t)`.
Please note that the character array is not guaranteed to be NULL terminated,
you should always use the provided size to determine end of string.
@@ -281,7 +310,7 @@
even allows you to change sizes of strings and vectors in-place.
The way this works is very elegant; there is actually a FlatBuffer schema that
-describes schemas (!) which you can find in `reflection/reflection.fbs`.
+describes schemas (\!) which you can find in `reflection/reflection.fbs`.
The compiler, `flatc`, can write out any schemas it has just parsed as a binary
FlatBuffer, corresponding to this meta-schema.
@@ -299,7 +328,7 @@
## Mini Reflection
A more limited form of reflection is available for direct inclusion in
-generated code, which doesn't any (binary) schema access at all. It was designed
+generated code, which doesn't do any (binary) schema access at all. It was designed
to keep the overhead of reflection as low as possible (on the order of 2-6
bytes per field added to your executable), but doesn't contain all the
information the (binary) schema contains.
@@ -390,9 +419,9 @@
Each root type will have a verification function generated for it,
e.g. for `Monster`, you can call:
-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
+```cpp
bool ok = VerifyMonsterBuffer(Verifier(buf, len));
-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+```
if `ok` is true, the buffer is safe to read.
@@ -458,15 +487,15 @@
convenient `LoadFile()` utility function in `flatbuffers/util.h` if you
wish). Construct a parser:
-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
+```cpp
flatbuffers::Parser parser;
-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+```
Now you can parse any number of text files in sequence:
-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
+```cpp
parser.Parse(text_file.c_str());
-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+```
This works similarly to how the command-line compiler works: a sequence
of files parsed by the same `Parser` object allow later files to
@@ -498,7 +527,7 @@
a FlatBuffer is contained in a FlatBufferBuilder instance, and no memory
outside of it is touched. To make this thread safe, either do not
share instances of FlatBufferBuilder between threads (recommended), or
-manually wrap it in synchronisation primites. There's no automatic way to
+manually wrap it in synchronisation primitives. There's no automatic way to
accomplish this, by design, as we feel multithreaded construction
of a single buffer will be rare, and synchronisation overhead would be costly.
diff --git a/docs/source/CsharpUsage.md b/docs/source/CsharpUsage.md
index 83f4842..abfcbf6 100644
--- a/docs/source/CsharpUsage.md
+++ b/docs/source/CsharpUsage.md
@@ -180,7 +180,8 @@
An additional feature of the object API is the ability to allow you to
serialize & deserialize a JSON text.
To use Json Serialization, add `--cs-gen-json-serializer` option to `flatc` and
-add `Newtonsoft.Json` nuget package to csproj.
+add `Newtonsoft.Json` nuget package to csproj. This requires explicitly setting
+the `--gen-object-api` option as well.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cs}
// Deserialize MonsterT from json
@@ -192,7 +193,7 @@
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
* Limitation
- * `hash` attribute currentry not supported.
+ * `hash` attribute currently not supported.
* NuGet package Dependency
* [Newtonsoft.Json](https://github.com/JamesNK/Newtonsoft.Json)
diff --git a/docs/source/DartUsage.md b/docs/source/DartUsage.md
index 6670cc5..515a644 100644
--- a/docs/source/DartUsage.md
+++ b/docs/source/DartUsage.md
@@ -105,4 +105,27 @@
not currently an option in Flutter - follow [this issue](https://github.com/flutter/flutter/issues/7053)
for the latest).
-<br>
+## Object based API
+
+FlatBuffers is all about memory efficiency, which is why its base API is written
+around using as little as possible of it. This does make the API clumsier
+(requiring pre-order construction of all data, and making mutation harder).
+
+For times when efficiency is less important a more convenient object based API
+can be used (through `--gen-object-api`) that is able to unpack & pack a FlatBuffer
+into objects and lists, allowing for convenient construction, access and mutation.
+
+To use:
+
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.dart}
+ // Deserialize from buffer into object.
+ MonsterT monster = Monster(flatbuffer).unpack();
+
+ // Update object directly like a Dart class instance.
+ print(monster.Name);
+ monster.Name = "Bob"; // Change the name.
+
+ // Serialize into new flatbuffer.
+ final fbb = Builder();
+ fbb.Finish(monster.pack(fbb));
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
diff --git a/docs/source/FlatBuffers.md b/docs/source/FlatBuffers.md
index 2a2133f..bbd2cb0 100644
--- a/docs/source/FlatBuffers.md
+++ b/docs/source/FlatBuffers.md
@@ -64,8 +64,8 @@
with the primary difference being that FlatBuffers does not need a parsing/
unpacking step to a secondary representation before you can
access data, often coupled with per-object memory allocation. The code
-is an order of magnitude bigger, too. Protocol Buffers has neither optional
-text import/export nor schema language features like unions.
+is an order of magnitude bigger, too. Protocol Buffers has no optional
+text import/export.
### But all the cool kids use JSON!
diff --git a/docs/source/IntermediateRepresentation.md b/docs/source/IntermediateRepresentation.md
new file mode 100644
index 0000000..f4eb075
--- /dev/null
+++ b/docs/source/IntermediateRepresentation.md
@@ -0,0 +1,35 @@
+# Flatbuffers Intermediate Representation {#intermediate_representation}
+
+We use [reflection.fbs](https://github.com/google/flatbuffers/blob/master/reflection/reflection.fbs)
+as our intermediate representation. `flatc` parses `.fbs` files, checks them for
+errors and stores the resulting data in this IR, outputting `.bfbs` files.
+Since this IR is a Flatbuffer, you can load and use it at runtime for runtime
+reflection purposes.
+
+There are some quirks:
+- Tables and Structs are serialized as `Object`s.
+- Unions and Enums are serialized as `Enum`s.
+- It is the responsibility of the code generator to check the `advanced_features`
+ field of `Schema`. These mark the presence of new, backwards incompatible,
+ schema features. Code generators must error if generating a schema with
+ unrecognized advanced features.
+- Filenames are relative to a "project root" denoted by "//" in the path. This
+ may be specified in flatc with `--bfbs-filenames=$PROJECT_ROOT`, or it will be
+ inferred to be the directory containing the first provided schema file.
+
+
+## Invocation
+You can invoke it like so
+```{.sh}
+flatc -b --schema ${your_fbs_files}
+```
+This generates `.bfbs` (binary flatbuffer schema) files.
+
+Some information is not included by default. See the `--bfbs-filenames` and
+`--bfbs-comments` flags. These may be necessary for code-generators, so they can
+add documentation and maybe name generated files (depending on the generator).
+
+
+TODO(cneo): Flags to output bfbs as flexbuffers or json.
+
+TODO(cneo): Tutorial for building a flatc plugin.
diff --git a/docs/source/Internals.md b/docs/source/Internals.md
index 389a8f9..591f040 100644
--- a/docs/source/Internals.md
+++ b/docs/source/Internals.md
@@ -85,10 +85,12 @@
They start with an `soffset_t` to a vtable. This is a signed version of
`uoffset_t`, since vtables may be stored anywhere relative to the object.
-This offset is substracted (not added) from the object start to arrive at
+This offset is subtracted (not added) from the object start to arrive at
the vtable start. This offset is followed by all the
fields as aligned scalars (or offsets). Unlike structs, not all fields
-need to be present. There is no set order and layout.
+need to be present. There is no set order and layout. A table may contain
+field offsets that point to the same value if the user explicitly
+serializes the same offset twice.
To be able to access fields regardless of these uncertainties, we go
through a vtable of offsets. Vtables are shared between any objects that
@@ -111,13 +113,21 @@
default value is return. Otherwise, the entry is used as offset to the
field to be read.
+### Unions
+
+Unions are encoded as the combination of two fields: an enum representing the
+union choice and the offset to the actual element. FlatBuffers reserves the
+enumeration constant `NONE` (encoded as 0) to mean that the union field is not
+set.
+
### Strings and Vectors
Strings are simply a vector of bytes, and are always
null-terminated. Vectors are stored as contiguous aligned scalar
elements prefixed by a 32bit element count (not including any
null termination). Neither is stored inline in their parent, but are referred to
-by offset.
+by offset. A vector may consist of more than one offset pointing to the same
+value if the user explicitly serializes the same offset twice.
### Construction
@@ -346,6 +356,9 @@
bytes (one per element of the vector), which are always following the vector,
and are always a uint8_t even if the vector is made up of bigger scalars.
+A vector may include more than one offset pointing to the same value if the
+user explicitly serializes the same offset twice.
+
### Types
A type byte is made up of 2 components (see flexbuffers.h for exact values):
@@ -422,7 +435,7 @@
values *have* to be stored in sorted order (as determined by `strcmp`), such
that lookups can be made using binary search.
-The reason the key vector is a seperate structure from the value vector is
+The reason the key vector is a separate structure from the value vector is
such that it can be shared between multiple value vectors, and also to
allow it to be treated as its own individual vector in code.
diff --git a/docs/source/JavaScriptUsage.md b/docs/source/JavaScriptUsage.md
index c321c95..64764e2 100644
--- a/docs/source/JavaScriptUsage.md
+++ b/docs/source/JavaScriptUsage.md
@@ -16,43 +16,31 @@
## FlatBuffers JavaScript library code location
-The code for the FlatBuffers JavaScript library can be found at
-`flatbuffers/js`. You can browse the library code on the [FlatBuffers
-GitHub page](https://github.com/google/flatbuffers/tree/master/js).
+The generated code for the FlatBuffers JavaScript library can be found at
+https://www.npmjs.com/package/flatbuffers. To use it from sources:
-## Testing the FlatBuffers JavaScript library
+1. Run `npm run compile` from the main folder to generate JS files from TS.
+1. In your project, install it as a normal dependency, using the flatbuffers
+folder as the source.
-The code to test the JavaScript library can be found at `flatbuffers/tests`.
-The test code itself is located in [JavaScriptTest.js](https://github.com/
-google/flatbuffers/blob/master/tests/JavaScriptTest.js).
-
-To run the tests, use the [JavaScriptTest.sh](https://github.com/google/
-flatbuffers/blob/master/tests/JavaScriptTest.sh) shell script.
-
-*Note: The JavaScript test file requires [Node.js](https://nodejs.org/en/).*
-
-## Using the FlatBuffers JavaScript libary
+## Using the FlatBuffers JavaScript library
*Note: See [Tutorial](@ref flatbuffers_guide_tutorial) for a more in-depth
-example of how to use FlatBuffers in JavaScript.*
+example of how to use FlatBuffers.*
-FlatBuffers supports both reading and writing FlatBuffers in JavaScript.
+Due to the complexity related with large amounts of JS flavors and module types,
+native JS support has been replaced in 2.0 by transpilation from TypeScript.
-To use FlatBuffers in your own code, first generate JavaScript classes from your
-schema with the `--js` option to `flatc`. Then you can include both FlatBuffers
-and the generated code to read or write a FlatBuffer.
+Please look at [TypeScript usage](@ref flatbuffers_guide_use_typescript) and
+transpile your sources to desired JS flavor. The minimal steps to get up and
+running with JS are:
-For example, here is how you would read a FlatBuffer binary file in Javascript:
-First, include the library and generated code. Then read the file into an
-`Uint8Array`. Make a `flatbuffers.ByteBuffer` out of the `Uint8Array`, and pass
-the ByteBuffer to the `getRootAsMonster` function.
-
-*Note: Both JavaScript module loaders (e.g. Node.js) and browser-based
-HTML/JavaScript code segments are shown below in the following snippet:*
+1. Generate TS files from `*.fbs` by using the `--ts` option.
+1. Transpile resulting TS files to desired JS flavor using `tsc` (see
+ https://www.typescriptlang.org/download for installation instructions).
~~~{.js}
- // Note: These require functions are specific to JavaScript module loaders
- // (namely, Node.js). See below for a browser-based example.
+ // Note: These require functions are an example - use your desired module flavor.
var fs = require('fs');
var flatbuffers = require('../flatbuffers').flatbuffers;
@@ -65,7 +53,7 @@
//--------------------------------------------------------------------------//
- // Note: This code is specific to browser-based HTML/JavaScript. See above
+ // Note: This code is an example of browser-based HTML/JavaScript. See above
// for the code using JavaScript module loaders (e.g. Node.js).
<script src="../js/flatbuffers.js"></script>
<script src="monster_generated.js"></script>
diff --git a/docs/source/LobsterUsage.md b/docs/source/LobsterUsage.md
index 9d69caf..723966b 100644
--- a/docs/source/LobsterUsage.md
+++ b/docs/source/LobsterUsage.md
@@ -71,7 +71,7 @@
makes use of native support for writing binary values, and access of vtables.
Both generated code and the runtime library are therefore small and fast.
-Actual speed will depend on wether you use Lobster as bytecode VM or compiled to
+Actual speed will depend on whether you use Lobster as bytecode VM or compiled to
C++.
## Text Parsing
diff --git a/docs/source/LuaUsage.md b/docs/source/LuaUsage.md
index 75b1f3b..43c370f 100644
--- a/docs/source/LuaUsage.md
+++ b/docs/source/LuaUsage.md
@@ -29,8 +29,8 @@
To run the tests, use the [LuaTest.sh](https://github.com/google/flatbuffers/
blob/master/tests/LuaTest.sh) shell script.
-*Note: This script requires [Lua 5.3](https://www.lua.org/) to be
-installed.*
+*Note: This script requires [Lua 5.3](https://www.lua.org/) and
+[LuaJIT](http://luajit.org/) to be installed.*
## Using the FlatBuffers Lua library
diff --git a/docs/source/RustUsage.md b/docs/source/RustUsage.md
index 6819117..9e959a9 100644
--- a/docs/source/RustUsage.md
+++ b/docs/source/RustUsage.md
@@ -36,7 +36,7 @@
[integration_test.rs](https://github.com/google/flatbuffers/blob/master/tests/rust_usage_test/tests/integration_test.rs)
This test file requires `flatc` to be present. To review how to build the project,
-please read the [Building](@ref flatbuffers_guide_building) documenation.
+please read the [Building](@ref flatbuffers_guide_building) documentation.
To run the tests, execute `RustTest.sh` from the `flatbuffers/tests` directory.
For example, on [Linux](https://en.wikipedia.org/wiki/Linux), you would simply
diff --git a/docs/source/Schemas.md b/docs/source/Schemas.md
index 06c0f5c..10ed260 100644
--- a/docs/source/Schemas.md
+++ b/docs/source/Schemas.md
@@ -211,9 +211,11 @@
open-ended way, for example for use as files, see the file identification
feature below.
-There is an experimental support only in C++ for a vector of unions
-(and types). In the example IDL file above, use [Any] to add a
-vector of Any to Monster table.
+There is an experimental support only in C++ for a vector of unions (and
+types). In the example IDL file above, use [Any] to add a vector of Any to
+Monster table. There is also experimental support for other types besides
+tables in unions, in particular structs and strings. There's no direct support
+for scalars in unions, but they can be wrapped in a struct at no space cost.
### Namespaces
@@ -237,9 +239,9 @@
### Root type
-This declares what you consider to be the root table (or struct) of the
-serialized data. This is particularly important for parsing JSON data,
-which doesn't include object type information.
+This declares what you consider to be the root table of the serialized
+data. This is particularly important for parsing JSON data, which doesn't
+include object type information.
### File identification and extension
@@ -488,7 +490,7 @@
tempted to use a dictionary.
Similarly, strings as values should only be used when they are
-truely open-ended. If you can, always use an enum instead.
+truly open-ended. If you can, always use an enum instead.
FlatBuffers doesn't have inheritance, so the way to represent a set
of related data structures is a union. Unions do have a cost however,
@@ -590,7 +592,7 @@
table { b:int; }
-NOT ok. We can only remove a field by deprecation, regardless of wether we use
+NOT ok. We can only remove a field by deprecation, regardless of whether we use
explicit ids or not.
table { a:uint; b:uint; }
@@ -635,10 +637,14 @@
Some `FlatBufferBuilder` implementations have an option called `force_defaults`
that circumvents this "not writing defaults" behavior you can then use
`IsFieldPresent` to query presence.
-
+/
Another option that works in all languages is to wrap a scalar field in a
struct. This way it will return null if it is not present. This will be slightly
less ergonomic but structs don't take up any more space than the scalar they
represent.
[Interface Definition Language]: https://en.wikipedia.org/wiki/Interface_description_language
+
+## Writing your own code generator.
+
+See [our intermediate representation](@ref intermediate_representation).
diff --git a/docs/source/Support.md b/docs/source/Support.md
index 4cac209..3436a6f 100644
--- a/docs/source/Support.md
+++ b/docs/source/Support.md
@@ -25,7 +25,7 @@
Simple mutation | Yes | Yes | Yes | Yes | No | No | No | No | No | No | No | No | Yes
Reflection | Yes | No | No | No | No | No | No | Basic | No | No | No | No | No
Buffer verifier | Yes | No | No | No | No | No | No | Yes | No | No | No | No | No
-Native Object API | Yes | No | Yes | Yes | Yes | Yes | Yes | No | No | No | No | No | No
+Native Object API | Yes | No | Yes | Yes | Yes | Yes | Yes | No | No | Yes | No | No | No
Optional Scalars | Yes | Yes | Yes | No | No | Yes | Yes | Yes | No | No | Yes | Yes | Yes
Flexbuffers | Yes | Yes | ? | ? | ? | ? | ? | ? | ? | ? | ? | Yes | ?
Testing: basic | Yes | Yes | Yes | Yes | Yes | Yes | Yes | Yes | ? | Yes | Yes | Yes | Yes
diff --git a/docs/source/SwiftUsage.md b/docs/source/SwiftUsage.md
index d5640f6..1c438f2 100644
--- a/docs/source/SwiftUsage.md
+++ b/docs/source/SwiftUsage.md
@@ -64,7 +64,8 @@
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.swift}
let hp = monster.hp
- let pos = monster.pos
+ let pos = monster.pos // uses native swift structs
+ let pos = monster.mutablePos // uses flatbuffers structs
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -76,8 +77,10 @@
if !monster.mutate(hp: 10) {
fatalError("couldn't mutate")
}
- // mutate a struct field
- let vec = monster.pos.mutate(z: 4)
+ // mutate a struct field using flatbuffers struct
+ // DONT use monster.pos to mutate since swift copy on write
+ // will not mutate the value in the buffer
+ let vec = monster.mutablePos.mutate(z: 4)
// This mutation will fail because the mana field is not available in
// the buffer. It should be set when creating the buffer.
diff --git a/docs/source/Tutorial.md b/docs/source/Tutorial.md
index 419ea09..f633425 100644
--- a/docs/source/Tutorial.md
+++ b/docs/source/Tutorial.md
@@ -130,7 +130,7 @@
[sample_binary.py](https://github.com/google/flatbuffers/blob/master/samples/sample_binary.py)
</div>
<div class="language-javascript">
-[samplebinary.js](https://github.com/google/flatbuffers/blob/master/samples/samplebinary.js)
+No sample binary is provided, since JS needs to be transpiled from TypeScript. Please see TypeScript support.
</div>
<div class="language-typescript">
<em>none yet</em>
@@ -231,7 +231,7 @@
`uint`, or `float`) will be given a default of `0` while strings and tables will
be given a default of `null`. Another thing to note is the line `friendly:bool =
false (deprecated);`. Since you cannot delete fields from a `table` (to support
-backwards compatability), you can set fields as `deprecated`, which will prevent
+backwards compatibility), you can set fields as `deprecated`, which will prevent
the generation of accessors for this field in the generated code. Be careful
when using `deprecated`, however, as it may break legacy code that used this
accessor.
@@ -321,7 +321,9 @@
<div class="language-javascript">
~~~{.sh}
cd flatbuffers/samples
- ./../flatc --js monster.fbs
+ ./../flatc --ts monster.fbs
+ # customize your TS -> JS transpilation
+ tsc monster_generated.ts
~~~
</div>
<div class="language-typescript">
@@ -439,8 +441,7 @@
</div>
<div class="language-javascript">
~~~{.js}
- // The following code is for JavaScript module loaders (e.g. Node.js). See
- // below for a browser-based HTML/JavaScript example of including the library.
+ // The following code is an example - use your desired module flavor by transpiling from TS.
var flatbuffers = require('/js/flatbuffers').flatbuffers;
var MyGame = require('./monster_generated').MyGame; // Generated by `flatc`.
@@ -544,10 +545,10 @@
import Flatbuffers
// typealiases for convenience
- typealias Monster = MyGame1.Sample.Monster
- typealias Weapon = MyGame1.Sample.Weapon
- typealias Color = MyGame1.Sample.Color
- typealias Vec3 = MyGame1.Sample.Vec3
+ typealias Monster = MyGame1_Sample_Monster
+ typealias Weapon = MyGame1_Sample_Weapon
+ typealias Color = MyGame1_Sample_Color
+ typealias Vec3 = MyGame1_Sample_Vec3
~~~
</div>
@@ -741,16 +742,16 @@
weapon_two = builder.CreateString('Axe')
# Create the first `Weapon` ('Sword').
- MyGame.Sample.Weapon.WeaponStart(builder)
- MyGame.Sample.Weapon.WeaponAddName(builder, weapon_one)
- MyGame.Sample.Weapon.WeaponAddDamage(builder, 3)
- sword = MyGame.Sample.Weapon.WeaponEnd(builder)
+ MyGame.Sample.Weapon.Start(builder)
+ MyGame.Sample.Weapon.AddName(builder, weapon_one)
+ MyGame.Sample.Weapon.AddDamage(builder, 3)
+ sword = MyGame.Sample.Weapon.End(builder)
# Create the second `Weapon` ('Axe').
- MyGame.Sample.Weapon.WeaponStart(builder)
- MyGame.Sample.Weapon.WeaponAddName(builder, weapon_two)
- MyGame.Sample.Weapon.WeaponAddDamage(builder, 5)
- axe = MyGame.Sample.Weapon.WeaponEnd(builder)
+ MyGame.Sample.Weapon.Start(builder)
+ MyGame.Sample.Weapon.AddName(builder, weapon_two)
+ MyGame.Sample.Weapon.AddDamage(builder, 5)
+ axe = MyGame.Sample.Weapon.End(builder)
~~~
</div>
<div class="language-javascript">
@@ -1014,10 +1015,10 @@
# Create a `vector` representing the inventory of the Orc. Each number
# could correspond to an item that can be claimed after he is slain.
# Note: Since we prepend the bytes, this loop iterates in reverse.
- MyGame.Sample.Monster.MonsterStartInventoryVector(builder, 10)
+ MyGame.Sample.Monster.StartInventoryVector(builder, 10)
for i in reversed(range(0, 10)):
builder.PrependByte(i)
- inv = builder.EndVector(10)
+ inv = builder.EndVector()
~~~
</div>
<div class="language-javascript">
@@ -1089,7 +1090,7 @@
</div>
<div class="language-lua">
~~~{.py}
- -- Serialize a name for our mosnter, called 'orc'
+ -- Serialize a name for our monster, called 'orc'
local name = builder:CreateString("Orc")
-- Create a `vector` representing the inventory of the Orc. Each number
@@ -1204,10 +1205,10 @@
~~~{.py}
# Create a FlatBuffer vector and prepend the weapons.
# Note: Since we prepend the data, prepend them in reverse order.
- MyGame.Sample.Monster.MonsterStartWeaponsVector(builder, 2)
+ MyGame.Sample.Monster.StartWeaponsVector(builder, 2)
builder.PrependUOffsetTRelative(axe)
builder.PrependUOffsetTRelative(sword)
- weapons = builder.EndVector(2)
+ weapons = builder.EndVector()
~~~
</div>
<div class="language-javascript">
@@ -1333,10 +1334,10 @@
</div>
<div class="language-python">
~~~{.py}
- MyGame.Sample.Monster.MonsterStartPathVector(builder, 2)
+ MyGame.Sample.Monster.StartPathVector(builder, 2)
MyGame.Sample.Vec3.CreateVec3(builder, 1.0, 2.0, 3.0)
MyGame.Sample.Vec3.CreateVec3(builder, 4.0, 5.0, 6.0)
- path = builder.EndVector(2)
+ path = builder.EndVector()
~~~
</div>
<div class="language-javascript">
@@ -1420,10 +1421,21 @@
<div class="language-swift">
~~~{.swift}
//
- Monster.startVectorOfvec3(2, in: &fbb)
- MyGame_Example_Vec3.createVec3(builder: &fbb, x: 1, y: 2, z: 3)
- MyGame_Example_Vec3.createVec3(builder: &fbb, x: 4, y: 5, z: 6)
- let points = fbb.endVectorOfStructs(count: size)
+ let points = fbb.createVector(ofStructs: [
+ Vec3(x: 1, y: 2, z: 3),
+ Vec3(x: 4, y: 5, z: 6)
+ ])
+
+ // OR
+ var vec3 = [
+ Vec3(x: 1, y: 2, z: 3),
+ Vec3(x: 4, y: 5, z: 6)
+ ]
+ Monster.startVectorOfVec3(2, in: &fbb)
+ for i in obj {
+ _ = create(struct: i)
+ }
+ let points = fbb.endVector(len: size)
~~~
</div>
@@ -1513,21 +1525,21 @@
</div>
<div class="language-python">
~~~{.py}
- # Create our monster by using `MonsterStart()` and `MonsterEnd()`.
- MyGame.Sample.Monster.MonsterStart(builder)
- MyGame.Sample.Monster.MonsterAddPos(builder,
+ # Create our monster by using `Monster.Start()` and `Monster.End()`.
+ MyGame.Sample.Monster.Start(builder)
+ MyGame.Sample.Monster.AddPos(builder,
MyGame.Sample.Vec3.CreateVec3(builder, 1.0, 2.0, 3.0))
- MyGame.Sample.Monster.MonsterAddHp(builder, 300)
- MyGame.Sample.Monster.MonsterAddName(builder, name)
- MyGame.Sample.Monster.MonsterAddInventory(builder, inv)
- MyGame.Sample.Monster.MonsterAddColor(builder,
+ MyGame.Sample.Monster.AddHp(builder, 300)
+ MyGame.Sample.Monster.AddName(builder, name)
+ MyGame.Sample.Monster.AddInventory(builder, inv)
+ MyGame.Sample.Monster.AddColor(builder,
MyGame.Sample.Color.Color().Red)
- MyGame.Sample.Monster.MonsterAddWeapons(builder, weapons)
- MyGame.Sample.Monster.MonsterAddEquippedType(
+ MyGame.Sample.Monster.AddWeapons(builder, weapons)
+ MyGame.Sample.Monster.AddEquippedType(
builder, MyGame.Sample.Equipment.Equipment().Weapon)
- MyGame.Sample.Monster.MonsterAddEquipped(builder, axe)
- MyGame.Sample.Monster.MonsterAddPath(builder, path)
- orc = MyGame.Sample.Monster.MonsterEnd(builder)
+ MyGame.Sample.Monster.AddEquipped(builder, axe)
+ MyGame.Sample.Monster.AddPath(builder, path)
+ orc = MyGame.Sample.Monster.End(builder)
~~~
</div>
<div class="language-javascript">
@@ -1702,17 +1714,16 @@
</div>
<div class="language-swift">
~~~{.swift}
- let start = Monster.startMonster(&builder)
- let posStruct = MyGame_Example_Vec3.createVec3(builder: &builder, x: 1, y: 2, z: 3)
- Monster.add(pos: pos, &builder)
- Monster.add(hp: 300, &builder)
- Monster.add(name: name, &builder)
- Monster.addVectorOf(inventory: inventoryOffset, &builder)
- Monster.add(color: .red, &builder)
- Monster.addVectorOf(weapons: weaponsOffset, &builder)
- Monster.add(equippedType: .weapon, &builder)
- Monster.add(equipped: axe, &builder)
- var orc = Monster.endMonster(&builder, start: start)
+ let orc = Monster.createMonster(
+ &builder,
+ pos: MyGame_Sample_Vec3(x: 1, y: 2, z: 3),
+ hp: 300,
+ nameOffset: name,
+ inventoryVectorOffset: inventoryOffset,
+ color: .red,
+ weaponsVectorOffset: weaponsOffset,
+ equippedType: .weapon,
+ equippedOffset: axe)
~~~
</div>
@@ -1780,6 +1791,21 @@
~~~
</div>
+<div class="language-swift">
+~~~{.swift}
+ let start = Monster.startMonster(&builder)
+ Monster.add(pos: Vec3(x: 1, y: 2, z: 3), &builder)
+ Monster.add(hp: 300, &builder)
+ Monster.add(name: name, &builder)
+ Monster.addVectorOf(inventory: inventoryOffset, &builder)
+ Monster.add(color: .red, &builder)
+ Monster.addVectorOf(weapons: weaponsOffset, &builder)
+ Monster.add(equippedType: .weapon, &builder)
+ Monster.add(equipped: axe, &builder)
+ var orc = Monster.endMonster(&builder, start: start)
+~~~
+</div>
+
Before finishing the serialization, let's take a quick look at FlatBuffer
`union Equipped`. There are two parts to each FlatBuffer `union`. The first is
a hidden field `_type` that is generated to hold the type of `table` referred
@@ -1794,7 +1820,7 @@
<div class="language-cpp">
~~~{.cpp}
monster_builder.add_equipped_type(Equipment_Weapon); // Union type
- monster_builder.add_equipped(axe); // Union data
+ monster_builder.add_equipped(axe.Union()); // Union data
~~~
</div>
<div class="language-java">
@@ -1823,9 +1849,9 @@
</div>
<div class="language-python">
~~~{.py}
- MyGame.Sample.Monster.MonsterAddEquippedType( # Union type
+ MyGame.Sample.Monster.AddEquippedType( # Union type
builder, MyGame.Sample.Equipment.Equipment().Weapon)
- MyGame.Sample.Monster.MonsterAddEquipped(builder, axe) # Union data
+ MyGame.Sample.Monster.AddEquipped(builder, axe) # Union data
~~~
</div>
<div class="language-javascript">
@@ -2199,14 +2225,13 @@
</div>
<div class="language-javascript">
~~~{.js}
- // The following code is for JavaScript module loaders (e.g. Node.js). See
- // below for a browser-based HTML/JavaScript example of including the library.
+ // The following code is an example - use your desired module flavor by transpiling from TS.
var flatbuffers = require('/js/flatbuffers').flatbuffers;
var MyGame = require('./monster_generated').MyGame; // Generated by `flatc`.
//--------------------------------------------------------------------------//
- // The following code is for browser-based HTML/JavaScript. Use the above code
+ // The following code an example for browser-based HTML/JavaScript. Use the above code
// for JavaScript module loaders (e.g. Node.js).
<script src="../js/flatbuffers.js"></script>
<script src="monster_generated.js"></script> // Generated by `flatc`.
@@ -2357,7 +2382,7 @@
buf = /* the data you just read, in an object of type "bytearray" */
// Get an accessor to the root object inside the buffer.
- monster = MyGame.Sample.Monster.Monster.GetRootAsMonster(buf, 0)
+ monster = MyGame.Sample.Monster.Monster.GetRootAs(buf, 0)
# Note: We use `0` for the offset here, which is typical for most buffers
# you would read. If you wanted to read from the `builder.Bytes` directly,
@@ -2945,7 +2970,7 @@
<div class="language-cpp">
~~~{.cpp}
- auto union_type = monster.equipped_type();
+ auto union_type = monster->equipped_type();
if (union_type == Equipment_Weapon) {
auto weapon = static_cast<const Weapon*>(monster->equipped()); // Requires `static_cast`
@@ -3239,7 +3264,8 @@
~~~{.swift}
let monster = Monster.getRootAsMonster(bb: ByteBuffer(bytes: buf))
monster.mutate(hp: 10) // mutates a value in a table
- monster.pos.mutate(z: 4) // mutates a value in a struct
+ /// to mutate structs in swift you have to use the mutable accessors
+ monster.mutablePos.mutate(z: 4) // mutates a value in a struct
monster.mutate(inventory: 6, at index: 0) // mutates a value in an Scalar array
~~~
</div>
@@ -3366,6 +3392,125 @@
## Advanced Features for Each Language
+### Vector of Unions
+
+Some languages support storing unions directly in a vector.
+
+~~~
+// File found in tests/union_vector/union_vector.fbs
+namespace Example.VectorOfUnions;
+
+// Demonstrates the ability to have vectors of unions, and also to
+// store structs and strings in unions.
+
+table Attacker {
+ sword_attack_damage: int;
+}
+
+struct Rapunzel {
+ hair_length: int;
+}
+
+struct BookReader {
+ books_read: int;
+}
+
+union Character {
+ MuLan: Attacker, // Can have name be different from type.
+ Rapunzel, // Or just both the same, as before.
+ Belle: BookReader,
+ BookFan: BookReader,
+ Other: string,
+ Unused: string
+}
+
+table Movie {
+ main_character: Character;
+ characters: [Character];
+}
+~~~
+
+#### Creating
+
+Analagously to how a union adds two fields to a table a vector of unions creates two different vectors:
+one for the union data and one for the data types.
+
+<div class="language-cpp">
+C++ supports vectors of unions, but it isn't currently documented.
+</div>
+<div class="language-typescript">
+Typescript supports vectors of unions, but it isn't currently documented.
+</div>
+<div class="language-php">
+PHP supports vectors of unions, but it isn't currently documented.
+</div>
+<div class="language-java">
+Java supports vectors of unions, but it isn't currently documented.
+</div>
+<div class="language-csharp">
+~~~{.cs}
+using FlatBuffers;
+using Example.VectorOfUnions;
+
+var fbb = new FlatBufferBuilder(100);
+
+var characterTypes = new[]
+{
+ Character.MuLan,
+ Character.Belle,
+ Character.Other,
+};
+var characterTypesOffset = Movie.CreateCharactersTypeVector(fbb, characterTypes);
+
+var characters = new[]
+{
+ Attacker.CreateAttacker(fbb, 10).Value,
+ BookReader.CreateBookReader(fbb, 20).Value,
+ fbb.CreateSharedString("Chip").Value,
+};
+var charactersOffset = Movie.CreateCharactersVector(fbb, characters);
+
+var movieOffset = Movie.CreateMovie(
+ fbb,
+ Character.Rapunzel,
+ rapunzel,
+ characterTypesOffset,
+ charactersOffset);
+Movie.FinishMovieBuffer(fbb, movieOffset);
+~~~
+</div>
+<div class="language-kotlin">
+Kotlin supports vectors of unions, but it isn't currently documented.
+</div>
+<div class="language-swift">
+Swift supports vectors of unions, but it isn't currently documented.
+</div>
+
+#### Reading
+<div class="language-csharp">
+~~~{.cs}
+var movie = Movie.GetRootAsMovie(fbb.DataBuffer);
+
+for (var i = 0; i <= movie.CharactersLength; i++)
+{
+ if (movie.CharactersType(i) == Character.MuLan)
+ {
+ var mulanSwordDamage = movie.Characters<Attacker>(i).Value.SwordAttackDamage;
+ }
+ else if (movie.CharactersType(i) == Character.Belle)
+ {
+ var belleBooksRead = movie.Characters<BookReader>(i).Value.BooksRead;
+ }
+ else if (movie.CharactersType(i) == Character.Other)
+ {
+ var otherStr = movie.CharactersAsString(i);
+ }
+}
+~~~
+</div>
+
+### Further Reading
+
Each language has a dedicated `Use in XXX` page in the Programmer's Guide
to cover the nuances of FlatBuffers in that language.
diff --git a/docs/source/TypeScriptUsage.md b/docs/source/TypeScriptUsage.md
index 0b9739e..a1acaeb 100644
--- a/docs/source/TypeScriptUsage.md
+++ b/docs/source/TypeScriptUsage.md
@@ -17,7 +17,7 @@
## FlatBuffers TypeScript library code location
The code for the FlatBuffers TypeScript library can be found at
-`flatbuffers/js` with typings available at `@types/flatbuffers`.
+https://www.npmjs.com/package/flatbuffers.
## Testing the FlatBuffers TypeScript library
@@ -26,7 +26,7 @@
*Note: The TypeScript test file requires [Node.js](https://nodejs.org/en/).*
-## Using the FlatBuffers TypeScript libary
+## Using the FlatBuffers TypeScript library
*Note: See [Tutorial](@ref flatbuffers_guide_tutorial) for a more in-depth
example of how to use FlatBuffers in TypeScript.*
@@ -43,7 +43,7 @@
the ByteBuffer to the `getRootAsMonster` function.
~~~{.ts}
- // note: import flatbuffers with your desired import method
+ import * as flatbuffers from 'flatbuffers';
import { MyGame } from './monster_generated';
@@ -70,8 +70,6 @@
can be used (through `--gen-object-api`) that is able to unpack & pack a
FlatBuffer into objects and standard TS types.
-**When using the obj based API, the flatbuffers import need to be in the global namespace if you don't have `--no-fb-import` enabled** since creating default values require accessing the `flatbuffers.js` file.
-
To use:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.ts}
diff --git a/docs/source/WhitePaper.md b/docs/source/WhitePaper.md
index e504ada..dbad2cb 100644
--- a/docs/source/WhitePaper.md
+++ b/docs/source/WhitePaper.md
@@ -20,7 +20,7 @@
If it would be possible to do serialization with no temporary objects,
no additional allocation, no copying, and good locality, this could be
of great value. The reason serialization systems usually don't manage
-this is because it goes counter to forwards/backwards compatability, and
+this is because it goes counter to forwards/backwards compatibility, and
platform specifics like endianness and alignment.
FlatBuffers is what you get if you try anyway.
@@ -64,7 +64,7 @@
between multiple tables with the same layout), and contains information
where fields for this particular kind of instance of vtable are stored.
The vtable may also indicate that the field is not present (because this
-FlatBuffer was written with an older version of the software, of simply
+FlatBuffer was written with an older version of the software, or simply
because the information was not necessary for this instance, or deemed
deprecated), in which case a default value is returned.
diff --git a/docs/source/doxyfile b/docs/source/doxyfile
index 3a5bd98..8cf9000 100644
--- a/docs/source/doxyfile
+++ b/docs/source/doxyfile
@@ -768,6 +768,7 @@
"WhitePaper.md" \
"FlexBuffers.md" \
"Internals.md" \
+ "IntermediateRepresentation.md" \
"Grammar.md" \
"../../CONTRIBUTING.md" \
"Tutorial.md" \
diff --git a/docs/source/doxygen_layout.xml b/docs/source/doxygen_layout.xml
index e1a6b81..28dd065 100644
--- a/docs/source/doxygen_layout.xml
+++ b/docs/source/doxygen_layout.xml
@@ -66,6 +66,8 @@
title="FlatBuffers white paper"/>
<tab type="user" url="@ref flatbuffers_internals"
title="FlatBuffers internals"/>
+ <tab type="user" url="@ref intermediate_representation"
+ title="Intermediate Representation"/>
<tab type="user" url="@ref flatbuffers_grammar"
title="Grammar of the schema language"/>
<tab type="usergroup" url="" title="API Reference">