Squashed 'third_party/flatbuffers/' changes from acc9990ab..d6a8dbd26
d6a8dbd26 Experimental fix for failing oss-fuzz coverage build (#6259)
ed391e177 BREAKING: Rust flexbuffers serde human readable set to false (#6257)
a49531414 Update to flags in fuzzing-cmake file (#6256)
de1f0342c Remove _POSIX_C_SOURCE and _XOPEN_SOURCE definitions when compiling o… (#6205)
d0d51e2a5 flatc should support --binary --schema with optional scalar fields. (#6252)
33ab26017 Bump version of rules_go to 0.24.5 (#6234)
febb9d87c Union As Accessors for C# (#6251)
8778dc7c2 Resets buffer without deallocating current pointer (#6247)
aae376e9a Add GetBufferSpan() function to bufferbuilder (#6235)
0ff047148 Modernize android build and sample (#6229)
46a8c7e95 Added required-nested-flatbuffer to monster_test and fixed rust (#6236)
bc56c553e Notify based on Labelling issues and PR (#6241)
07d7cd78a Converted globs to use single quotes (#6240)
cdef70e24 More adjustments to the auto labeler (#6239)
9dd44df35 Updated Lua labeller glob (#6238)
c9b29d088 Support size-prefixed buffers and add tests for size-prefixed messages (#6232)
fba93e0ab Removes duplicate swift in labeler (#6228)
d1a545b1f Added more labels for auto labeler (#6227)
ea92a668d [C#] Optional Scalars (#6217)
6034de286 [Label Bot] Add Java and Kotlin support for the label bot (#6226)
b08b0a440 Implement `Debug` trait for Rust flatbuffers. (#6207)
17ae48dec [Label Bot] Adds some languages to labeler bot (#6222)
fc8097925 Auto Labeler Setup, Just C# for now (#6221)
55658f523 Auto Labeler Setup, Just C# for now (#6218)
14ecfe423 Updated comments and fixed a fundamental type error. (#6214)
a0182cdb1 optional scalars for ts/js (#6215)
0dfcc0a37 Adds NetTest.bat to run .NET Core tests on Windows (#6216)
f9a18ea63 [Java] Implement optional scalars (#6212)
c7586e85a Empties the sharedString map on reset on go and csharp (#6187)
914c64601 Removed C# references from java generator. Move annotations closer to definitions (#6204)
42d7c7997 Adds readable size to asserts in read functions (#6210)
e68e8d7de Refactor idl_gen_rust (#6206)
84809be7e Fix typo in flatbuffers::span declaration. (#6202)
1606fb637 Kotlin test optional enum (#6201)
fe8e3c7e5 Mass Refactoring to use `IsString` and other BASE_TYPE helpers (#6193)
8f6fa4b71 Updated SupportsAdvancedUnionFeatures to look out for string (#6190)
b46db38f5 [JS/TS] Rewrite flexbuffers JS to TS (#6148)
9fa1d2705 Rework enums in rust. (#6098)
a402b3aba idl_gen_json_schema Fix generation of arrays of enums (#6184)
0e1415b99 fix(go_test): remove deprecated grpc call (#6183)
5cd713710 Add generation of JSON Schema to library (#6165)
5be777e1d Bump junit from 4.12 to 4.13.1 in /grpc/tests (#6173)
a49d440ec Bump junit from 4.12 to 4.13.1 in /grpc (#6172)
4ec5e8db9 [C++] Add option to not generate direct copy methods. (#6166)
04bec23a3 Add Array initialization from struct constructor (#5865) (#6147)
77d57fd07 Cast to right type for reserved_ subtraction (#6167)
543c1bbeb Fixed rust nested flatbuffers for tables other than self (#6062)
cb971eece [C++] Fix -Wnarrowing and -Woverflow due to signed bitfields on G++ ARM (#6163)
7b9e61fcc [TS] GRPC Implementation (#6141)
3359e3042 Moved C++ to optional_scalars2 and added some tests. (#6162)
187a4787f [Rust] Upgrade flatbuffers library to 2018 edition (#6159)
08943aa26 Flatbuffer C++ UnpackTo optimization for vectors of non-bool bytes. (#6154)
5975658eb Enables optional enums in swift (#6160)
5d3cf440e Updated Lobster test for optional bools/enums
8ec8322f0 Ruopt enum (#6156)
bbcc85fd4 Fix generation of C++ code with Optional<Enum> (#6155)
0bdf2fa15 [C#] Fix and improve project files (#6142)
2eedc769d possibility to create a vector from an iterator (#6135)
ab01ae162 flatc should output a warning, when an attribute is attached more than once (#6146)
689bfafa7 [Python/JS/TS] Codegen SizeOf method for structs (#6136)
641309a5b unix2dos on tests/FlatBuffers.Test/FlatBuffers.Core.Test.csproj (#6133)
52e362879 SpanT is available in .Net Standard 2.0. (#6137)
dca12522a Add static cast to avoid implicit double promotion. (#6132)
e0bbaa6f9 [C#]Change to ENABLE_SPAN_T that doesn't require UNSAFE_BYTEBUFFER. (#6073)
ab139d6be Revert "[C#] Fix and improve project files (#6116)" (#6130)
34d67b425 Minireflect fixed array (#6129)
96d5e3597 [JS/TS] fix flatbuffers default export (#6123)
eb686a86f Add missed file generated by optional_scalar.fbs (#6125)
750281630 [C#] Fix and improve project files (#6116)
fb4e1c34f Add CharToLower and CharToUpper into util.s (#6126)
8c67b5b12 Add support of Optional<T> scalars to C++ code generator (#6092)
6228b66d3 [Kotlin] Support for optional scalars. (#6115)
e1be8aaad Bump version for latest swift version (#6121)
94873e595 [JS/TS] Modernize TypeScript / JavaScript flatbuffers support (#6095)
b8e87fafe [JS] Add getFullyQualifiedName() (#6119)
f96d1ef74 [Java] allowing larger buffer sizes when growing a byte buffer (#6118)
89435303b [Swift] Migrates struct write APIS to write directly to the buffer (#6093)
c75ae2429 Optional-ness in reflection (#6097)
338944d3d Rename Nullable scalars to Optional scalars (#6112)
f5ab24bc4 Avoid memcpy call for empty vectors (#6111)
92a8c1a0f [JS] FlexBuffers Fix for wrong type of offset and length values (#6107)
6cea45dcd fix c# json serializer commandline argument docs (#6104)
fec58aa12 Fix for issue 6100: incorrect shrinking logic in ResizeContext() (#6102)
71aca81ff [JS] FlexBuffers Support (#5973)
04d87ffec [C++] Small refactoring of the C++ code generator (#6091)
bb25956f0 Wrap verify file id condition in Check call (#6085)
49f4948f0 + Add `removable-media` plug to the snapcraft config (#6083)
eeacc53d2 Adds proper access types for swift object api & flatbuffers & grpc (#6081)
f3003e08d [Lobster] missed a test
d713a0084 [CMake] enabled multi-core builds in VS projects
77f966f89 [Lobster] optional scalars support
e86d5b8e9 [Kotlin] Attach JvmStatic annotation to each method in companion object (#6052)
db2aa9b4e [C#] Cleaned up .NET testing script for Mono (#6016)
63cc0eec4 Adds a serialize helper function to native table (#6059)
c30a87de6 [TS] Fix four bugs with imported types in TypeScript. (#6054)
a0fb30575 [Swift] Append namespace for Swift Grpc implementation (#6049)
77c18c1d6 export a __version__ variable for python module (#5309)
f1f23d08e adding fb import when no other imports are present (#6030)
f1025b284 [Feature] Checks for Nullable strings (#6050)
5d052f4e5 [Swift] RFC: Switch Swift namespace from public enum to ordinary concat with _ (#6045)
18b015d25 Rust codegen improvements and lint fixes (#6046)
d76e93f27 adds code gen for optional scalars in swift (#6038)
82fac326c [C++] Fix compiler error from deleted assignment operator (#6036) (#6047)
043b52bd4 Optional Scalars support for Rust (#6034)
c8fa0afdf Allow to run cpp tests under grpc/tests/ using bazel. (#6040)
6d0aae73c Fix git command executed in wrong folder when doing cmake superbuild (#6039)
ff1b73128 [Swift] Optional Scalars Preparation (#6028)
2e48c8dd3 tests: Check for both quiet and signaling NaN on mipsel/hppa (#6029)
6942704f2 support deprecated flag in json schema (#6022)
9ecd2e16c Flatc parser support for nullable scalars (#6026)
33e2d8079 [Dart] Generate constant values map for enums (#6025)
969d0f7a6 Using proper symbol name for reexport (#6021)
515a4052a Silence false positive "-Wstringop-overflow" on GCC 10.0 to 11.0 (#6020)
36fbe6f13 Updated FB import (#6019)
b69fc8cc9 [Java] Add support for shared strings on FlatBufferBuilder. (#6012)
ab6af18d9 Not using non-existent create method for obj api (#6015)
37a5dee10 Code cleanup + updates test and readme (#6004)
8a721f69a Serde with bytes maps to Blob (#6009)
e810635ea [Swift] FlatBuffers createMonster method doesn't treat struct properly (#5992)
4995e1527 Manage grpc dependency in Bazel's WORKSPACE file. (#5995)
60b6066fe Add warning to schema parser if field name is not snake_case. (#6005)
35d45cac7 [Rust] Flexbuffers dependency cleanup and fixes (#5998)
165a6e3d1 Re-added Evolution Schema Code Generation Command (#5999)
13d3fb2ea Fix RPM install conflict (#6003)
d64078eb2 [Swift] Initialize memory when clear ByteBuffer (#5982)
ca1190a3d [TS] Use proper TypedArray in create*Vector (#5991)
7571b2ac5 [C++] Updates real_path to be truly portable (#5787)
e5a8f76a4 [C++] Generate default member initializers for >= C++11 (#5989)
413bb9b55 [Kotlin] Fix Access to union of vector element (#5994)
f35184aef [Swift] Add parsing from unowned UnsafeMutableRawPointer for ByteBuffer (#5981)
b124b7625 Removed requirement that enums be declared in ascending order. (#5887)
0ec7600c6 Do not remove the last digit from float values (#5974)
14baf45c9 Mark GetBufferMinAlignment() const (#5985)
9abb2ec2c TypeScript/JavaScript docs improvements (#5984)
2e57d80b1 [Swift] Internal library improvements (#5965)
cfc7753a4 [Doc] Added missing letters to compiler options (#5976)
12ddc8a92 Rust Flexbuffers Documentation update (#5979)
24ad35709 [docs] typo: updates monsterdata.json to be valid json (#5978)
cc44a4442 [idl_parser] Mark typefield as deprecated (#5958)
9ab4a5c0e Deleted old stale bot
6682cfe87 Increased Operations per run in stale.yml
64922904b Adding Stale Action to clean up PR and Issues
8e505cb67 [C++] Fixed/Enabled --cpp-ptr-type std::shared_ptr [#5813] (#5959)
a28357d7a Propagate boolean default values from proto to fbs (#5964)
7cb4762a6 [Swift] Improving reallocation time by using memcpy and moving reallocation code to storage (#5960)
4e45f7c9e Fix error in SimpleQSort (#5955)
7ac026405 fix error on GRPC Python - ignore namespace tree if not specified (#5862) (#5922)
108e981db Required is now implemented in swift (#5952)
94a78e385 Fixed: Access violation and ASAN/UNSAN failures with sorted tables
53fb453e0 [rust] Add FlatBufferBuilder::force_defaults API (#5946)
17c1f35fa [FlexBuffer][Java] ReadWriteBuf and ReadBuf interface public (#5948)
2eaf57778 [Java] Grow ArrayReadWriteBuf enough to match requested capacity. (#5921)
666800da3 Adds bool support in structs + updates grpc support + CI upgrades (#5943)
38ed69eb3 fixed mutating inline values (#5942)
d026e6f07 Add static asserts to ensure that reflection API arrays are kept in sync (#5934)
988164f6e [C++] Got rid of memset's in constructors (#5938)
7179a5a8b General Codebase clean up (#5939)
a0da0c08c Add GetStringView like GetString, GetCstring (#5937)
ac203b209 [C#] Add file identifier to ObjectAPI Serialization Utility. (#5920)
8dd1bf25b not creating creation methods when using structs (#5919)
5aa443d98 [Dart] Adding FlexBuffers support (#5853)
0fa087657 [Dart] Getting tests/DartTest.sh to work on master. (#5915)
424a473e1 Schema parser: prohibit declaration of an array of pointers inside structs (#5907)
c3faa8346 Fix Cargo.toml dependencies (#5911)
91399ad05 fix union type names (#5902)
32782e4ad Update Rust Flexbuffers metadata before publishing (#5905)
e7f3b1690 [TS] Make Obj-API work with --short-names (#5898)
12ed1fe4a fixed invalid imports with --gen-all (#5895)
85ee4df7a [C#] Thread safe reads of Double and Float values from a ByteBuffer (#5900)
de89bd193 Implement flexbuffers in python (#5880)
8be05f6bd Rust Flexbuffers (#5669)
870ecbc09 [swift] Moves code to use VTablesStorage (#5888)
c2da8d5d8 [Java][FlexBuffers] Make FlexBuffersBuilder reusable by adding clear() (#5889) (#5890)
e84cbff67 Align package name to FindFlatBuffers.cmake (#5899)
f94e6c84e Small tutorial improvements - documentation only (#5894)
f12cca8bc Attempt at adding Github Actions CI
7e4124d6e Handle git program or .git folder absence (#5878)
a875d247a only add native_include_files if object based api is enabled (#5886)
6e9f5d981 Respect shared attribute in Parser (#5885)
ff1c78233 include/flatbuffers: typo fixes in comments (#5884)
2e9a19673 Updates swift docs for package management (#5883)
e3cb07d32 [Rust] idl_gen_rust.cpp: (Option/required-aware codegen for unions) (#5850)
712866d57 Propagate use_string_pooling in CopyTable (#5879)
44c919a9e Not using reexports with --gen-all (#5873)
99aa1ef21 Added INCLUDE_PREFIX option for flatbuffers_generate_headers (#5866)
40ba170c9 Fixed text in internals doc that implied structs can be root
cb4d0f72e [Swift] Object API support (#5826)
003e16405 [TS] Add Obj API (#5788)
21cf300f4 fix cpp usage markdown error (#5845)
9655e12d6 Upgraded swift implementation for grpc (#5843)
fb96fadc2 [C#] Fix nested structs and arrays in Object API (#5765)
408f11fbd [ts] Fix empty source/dest namespaces when reexporting. (#5841)
a83caf591 Improves performance for the swift library by using structs + a storage class (#5835)
925fab6b1 [Java][FlexBuffers] Optimize Map access (#5735)
d9fecc332 [CMake] : Add precompiled header support with FLATBUFFERS_ENABLE_PCH (#5827)
e9d453240 Added flatbuffers_generate_headers and flatbuffers_generate_binary_files cmake functions. (#5830)
c37c989ed Correct calculation of vector element size (#5831)
6b271b7ec Fix Clang-trunk warnings about special members deprecated in C++20. (#5829)
90f3b8e8c Fix `float_constant` definition in './doc/Grammar.md` (#5828)
3af735934 [csharp] flatc should generate a 'Create…' method for tables with struct field… (#5818)
c4231c3cb Updated doxyfile - added missing files (#5824)
9657df184 Update Grammar.md (#5820)
97ffc590e Include CPack only when explictly packaging (#5817)
8b52af65b [C++] Add max_depth and max_tables parameters to reflection::Verify (#5815)
9b034eee1 Fix interpretation of 'nan(number)' by the idl_parser (#5810)
3e9ac3cff [Scripts] Adds swift to generated code (#5806)
697147a2e updated maven build files
6df40a247 pre-tag version bump for 1.12
0dba63909 Removes the inner loop in the endtable check written tables (#5803)
0e3fdd0ee Escape characters in jsonschema descriptions (#5644)
45a2b07cb Remove `noexcept` qualifier copy-ctor of `union` type (#5800) (#5802)
d10c16314 Replace 'assert' by 'FLATBUFFERS_ASSERT' inside idl_parser.cpp (#5799)
35abb7f89 Add non-nullable modifier to return type of functions never returning null (#5797)
9954e09ab [C++] Generate code for vector force_align attribute. (#5796)
95a21327f rust: pub export the VectorIter type (#5736)
89b6183ee Fix Python min alignment
5a98d65e8 [Rust] Add gen-name-strings for Rust (#5757)
f73d205bc Removed assert that wasn't backwards compatible.
7c37abe92 [C#] add ObjectAPI Serialization Utility (#5785)
4749e77b0 Fixed docs on how to obtain parser error.
6ff189841 Added --filename-suffix and --filename-ext to flatc (#5778)
c9a30c9ca Fixed refractoring issue in reflection/generate_code.sh. Also, mv deletes the original file, so I don't need to clean it up manually in that case. (#5777)
8c02d17be Skip writing reflection_generated.h if not changed (#5776)
34305c4ce [Swift] Adds GRPC to Swift (#5758)
cd88e6b2a [Java][FlexBuffers] Abstract buffer access from ByteBuffer (#5743)
3ec7a53c6 Adds cocoapods and a readme of how to get the package (#5771)
6d44cede7 [snap] Fix versioning (#5727)
cc08c0835 [Python] Fixed potential allignment issue (#5768)
54f8b787c Fix memory leak on cpp object api (#5761)
17557f913 [Python] Fixed issue #5499 (#5764)
d54af8cd4 [C++] Use strong enum type for vectors when scoped-enums is on. (#5750)
173e10fdf [C#] support Json Serialization (#5752)
8f56990f6 FlexBuffers: C++: scalar-only typed vectors were not aligned.
6400c9b05 Bump Rust port to 0.6.1 (#5747)
7418d8587 [C#] support Object API (#5710)
c580fa284 Adds min and max, comments, and all of swift's keywords + fix docs (#5737)
f2a127230 Use VS 2017 and 2019 on CI, fix cast issue in dart_idl (#5740)
316d7c208 Creates a flatbuffers validation function + small fix (#5725)
47026ea6b Added the code to embed the binary schema to the source (--bfbs-gen-embed). (#5701)
3f677f241 [Java][FlexBuffers] Deprecate typed vector strings due to design flaw (#5722)
a593a11e5 [Go] Implements a SharedStrings function (#5733)
7cdfc8475 [Swift] Fix padding function overflow when bufSize is 0 (#5721)
bab2b0db4 Add vcpkg installation instructions (#5732)
89418eb84 [Dart] Fix deprecated field support, inf/nan (#5724)
9cadf05d8 [typescript] Size-prefixed root accessors not taking into account size prefix (#5717)
6da1cf79d [rust] Add use declarations to Rust-generated bindings for imported FB definitions (#5645)
bee1df96d [Go] Replace references to hardcoded ”Monster" etc with idiomatic go wherever possible (#5716)
01189d7ed [C++] Fix for printing of enum in case output_enum_identifiers=1. (#5706)
c4b2b0a25 [Swift] Support create long string (#5709)
a4b2884e4 Added create function for swift (#5707)
04d80f255 [Swift] Swift implementation 🎉🎉 (#5603)
55686100a Changed direct calls to strtod to use StringToNumber
718351831 Document JSON compatibility guarantees. (#5704)
d1b34f0f2 Add CMake 'generated_code' target to simplify resolution of build dependencies (#5697)
21b706196 (Optionally) add an additional suffix namespace to generated fbs files. (#5698)
35daaf83d [Java] Replace Table.UTF8_CHARSET with StandardCharsets.UTF_8 (#5696)
3b458f7a1 Rust: Temporarily disable 2 endianness unit tests (#5695)
a5d9d0f7d [C++17] Add Traits class for Tables and Factory function within it. (#5678)
3cd9b6434 Removed code_generators.cpp from library targets
355dfd48d [rust] Make enum names public (#5690)
bcd58a159 Correct inverted logic around include prefixes. (#5689)
a2c12900a Optimize Pack method using numpy (#5662)
901b89e73 [C++] Add Builder and Table typedefs (#5685)
31f879908 Minor doc updates: FlexBuffers C#, Discord, CppUsage.
8023d99e2 Upgrade rules_go (#5684)
b4154405d Fix --incompatible_load_cc_rules_from_bzl (#5683)
04c17c7a7 Add support for absl::string_view when available (#5682)
62ec7d52c [Bazel] Add support for compatible_with and restricted_to (#5681)
7de668053 CI: New Docker tests for Python with numpy (#5677)
3a70e0b30 Fixed struct initialization error on older versions of C#
9b1320135 Fixed warnings in FlexBuffers.java
5e3916050 Fixed out of date licenses on gRPC Python files.
c95755051 Removed test proto output.
44bf71988 Add flatc '--cpp_std' switch (#5656)
3e8f15df9 Fix for FlexBuffers FBT_VECTOR_STRING size bit-width.
602721a73 Added Check to VerifyAlignment (#5675)
13c05f4da Improve import handling for proto conversion (#5673)
ce3a1c43a [Dart] Fix prepare space for writeListInt64 and writeListUint64 (#5654)
aa75e5734 Make Rust constants public (#5659)
2790fee25 Add namespace qualification to union types (#5666)
eddebec1b Bugfix for Rust generation of union fields named with language keywords (#5592)
030fee36a wrap multiple statements in do {} while(!IsConstTrue(true)) (#5655)
f9724d1bd [gRPC] Uncomment MessageBuilder (#5658)
b20801ca4 Supress unsigned-integer-overflow for PaddingBytes (#5647)
a8e800bd7 Add --force-empty-vectors option (#5653)
d7530ae96 Fixed enum min/max values not properly escaped.
99d11e279 Split Bazel targets into multiple packages (#5640)
4fd8eb214 Remove a static_assert (#5643)
65f870357 Flatbuffers Python Object API (#5616)
75823cc27 [Clang 10]: definition of implicit copy constructor for 'TableKeyComparatoris deprecated #5649 (#5650)
58e279244 [docs]: add missing semicolon (#5648)
3c964e10a [GO] Fix support for enums with underscores and Unions with imported members (#5600)
c3c32ec94 Fix ambiguity of a type deduction in TEST_EQ macro if arguments have `enum class` type. (#5630)
075e8d676 Simplify declarations of x-macro FLATBUFFERS_TD (#5638)
bcf1bd5c9 read vtable size through ReadScalar() (#5636)
136d75fa6 Changed null checks in test. Removed verifier pointer usage (#5634)
091fa1fd1 Add testing of C++ with sanitizers (CI-Docker) (#5631)
ff3781dc2 add namespace prefix in FLATBUFFERS_MAX_BUFFER_SIZE (#5629)
6beb9f49c Support for python grpc - continuing the work from the pull request #4270 #4705 (#5613)
80988ea86 Removed idl_gen_general.cpp and move contents to code_generators.cpp (#5625)
0f2ff7eaa Lua cleanup (#5624)
dda095023 [C++] Adds basic schema evolution tests (#5611)
adbcbba5d [C++, C#, Java] Separated C# and Java generators into their own classes (#5618)
cbbd6aca0 add check for root_type specified for json schema generation (#5622)
405c64e07 [Rust] Bump smallvec version to 1.0 (#5621)
42c08cbca Ran src/clang-format-all.sh (#5617)
33d5dd9bd Improved pull request & clang-format instructions.
105dd528e Change monster_extra generation to use flatbuffers::unique_ptr (#5612)
f0f0efe7b [C++] Refactor to conform to Google C++ style guide (#5608)
e837d5a29 Fixed deprecated method in GRPC Java test.
9834ee978 Fixed Apache license not using canonical version.
44b2ab087 include/flatbuffers/base.h: fix no_sanitize issue with old clang (#5610)
46ae3f80a [C++, Java, C#, TypeScript, JavaScript] Skip generation of mutable union types (#5599)
7b38aa71e flatbuffers.h: fix documentation warning (#5607)
661bedd83 Add Lua FlatbufferBuilder Clean() method to enable reuseable builders (#5606)
8526e12d7 [Kotlin] Fix union vector accessor after change in Java API (#5605)
3c7b660d6 [flatc] Remove an always true condition for flexbuffers (#5604)
964365ba6 [Go] Add UnPackTo functions (#5598)
32254b7ac [Go] Object API support (#5339)
521e255ad Rust: Add idiomatic iterator for Vector type (#5579)
1b85292fd Fix typos in comments (#5590)
480815447 C++ verifier for evolved union fields should return true (#5586)
8d5e424c6 Add ByteBuffer copy for vector of bytes in Java (#5587)
b4774d235 Rust: Fix Copy and Clone impls for a few generic types (#5577)
26f238c24 Add `--clean-first` to the cmake-build command (travis) (#5574)
e93c8c46e Fix Follow implementation for bool (#5554)
e21516b9d Fix issue #5557 (#5573)
fbc11e8ae Avoid intentional unsigned integer overflow getting caught by sanitizers (#5572)
e9d29c21a Python: Add forceDefaults opt to python Builder (#5564)
8bfafc76d Java: Don't annotate vector-of-tables item getters with @nullable. (#5562)
df3e8bf4a Fixed warnings generated by recent JSON sorting feature.
5665cfe49 [Java] byte buffer factory returned buffer capcity is used instead of the requested size (#5558)
5797540ed #5544 Fix of Array of table is not sorted if Create<type>Direct() is used (#5546)
7f1af7cb0 Fix build with gcc version 7.4.0 (#5570)
32f47ad24 Fixed JSON parser not sorting vectors of tables/structs with key.
842f672ba [FlexBuffers][Java] Cache size of Sized objects in FlexBuffers (#5551)
d4cae0a62 Fix issue #5542 (#5543)
f1147f65b Fixed Android STLPort related error.
69d3fec48 Fix namespaced struct/field name collision detection (#5540) (#5545)
cfb4ecf6f [flac] Add FlexBuffers option for generating data (#5519)
a92039687 Update Rust versions under test from 1.30.1 to 1.37.0 (#5538)
625338d09 Adds XOPEN_SOURCE for PATH_MAX and POSIX 1993 for stat (#5529)
3f8ce99c5 [FlexBuffers][Java] Add override Key::toString (#5533)
0798b7b69 [FlexBuffers][Java] Fix wrong access to a string using Reference::asString(). (#5532)
cbdf82e2f Fix Mutate() methods of Array<scalar/struct> (override 5508) (#5526)
e365c502f Java: Added access object for vector of struct and vector of tables. (#5233)
97f3aa917 Fixed DetachedBuffer self move assignment (#5521)
2f5bb2eec Fix buildifier warnings found in new bazel (#5517)
917687c7a Fixed Reflection Verifier not handling vectors of unions.
f9277e691 Fixed GenerateText not handling vectors of unions.
2706381ee Add element size parameter to __vector_as_arraysegment [c#] (#5512)
b5560fcd5 [Java][FlexBuffers] Improve documentation for FlexBuffers in Java. (#5506)
782b865c5 Annotate getters with @Pure when --java-checkerframework is specified. (#5510)
3bfc86eaf [Dart]fix: segment fault with empty namespace when generating dart file (#5507)
c0282873f Rust: Fixed cargo clippy on non-generated code (#5485)
4b870aca9 [Javascript] Fix syntax error for signed enum (#5503)
d0e3870c0 [C#] Fix retrieving enumeration vectors as arrays (#5457)
fb25eb87f Doc typo fixes (#5505)
cb35d3a0e Use all of the available space in the buffer returned by ByteBufferFactory to allow the factory to keep a pool of larger than initialsize sized buffers. (#5500)
8e6cabb31 [FlexBuffers][Java] Implementation of FlexBuffers API (#5476)
bd31dd242 Clarified value reuse in FlexBuffers
65b67d213 Fixed test build invocation of arrays_test.fbs
1fbb71132 FlexBuffers: allow any values to be shared.
cd75a3658 Android: remove app_dummy() calls
ec6b0bf29 Fixed STLPort Android compile error
c11b5d744 [bugfix]flexbuffers isvector bugfix (#5488)
4525c91be Fix incorrect padding in arrays of structs (Issue #5484) (#5491)
b97b342f5 Fixed missing generated code.
c1058a903 C++ IDL generation adds superfluous semicolon in GenTablePost, causing (#5483)
303044934 [go]add Name() for ForceCodec interface (#5486)
a2485d4ec reflection: check for valid union enum value during object verification (#5475)
a20e71ac9 has_method support for primitive fields in java runtime. Changed: idl.h, FlatBufferBuilder.java , idl_gen_general.cpp, idl_parser.cpp, flatc.cpp (#5468)
Change-Id: I836f4b43e6818bb16425a87899e6234ac86242aa
git-subtree-dir: third_party/flatbuffers
git-subtree-split: d6a8dbd26ff08a8868e0d0c1b4b67d31b40e4a7f
diff --git a/docs/source/Building.md b/docs/source/Building.md
index a896711..ad9e972 100644
--- a/docs/source/Building.md
+++ b/docs/source/Building.md
@@ -29,6 +29,19 @@
*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.*
+## Building with VCPKG
+
+You can download and install flatbuffers using the [vcpkg](https://github.com/Microsoft/vcpkg/) dependency manager:
+
+ git clone https://github.com/Microsoft/vcpkg.git
+ cd vcpkg
+ ./bootstrap-vcpkg.sh
+ ./vcpkg integrate install
+ ./vcpkg install flatbuffers
+
+The flatbuffers port in vcpkg is kept up to date by Microsoft team members and community contributors.
+If the version is out of date, please [create an issue or pull request](https://github.com/Microsoft/vcpkg) on the vcpkg repository.
+
## Building for Android
There is a `flatbuffers/android` directory that contains all you need to build
diff --git a/docs/source/Compiler.md b/docs/source/Compiler.md
index 7889abd..4636428 100644
--- a/docs/source/Compiler.md
+++ b/docs/source/Compiler.md
@@ -47,6 +47,8 @@
- `--rust`, `-r` : Generate Rust code.
+- `--swift`: Generate Swift code.
+
For any data input files:
- `--binary`, `-b` : If data is contained in this file, generate a
@@ -94,7 +96,7 @@
statements) use `--no-includes.`
- `--no-includes` : Don't generate include statements for included schemas the
- generated file depends on (C++).
+ generated file depends on (C++ / Python).
- `--gen-mutable` : Generate additional non-const accessors for mutating
FlatBuffers in-place.
@@ -114,6 +116,9 @@
- `--gen-generated` : Add @Generated annotation for Java.
+- `--gen-jvmstatic` : Add @JvmStatic annotation for Kotlin methods
+ in companion object for interop from Java to Kotlin.
+
- `--gen-all` : Generate not just code for the current schema files, but
for all files it includes as well. If the language uses a single file for
output (by default the case for C++ and JS), all code will end up in
@@ -132,6 +137,14 @@
std::string from Flatbuffers, but (char* + length). This allows efficient
construction of custom string types, including zero-copy construction.
+- `--no-cpp-direct-copy` : Don't generate direct copy methods for C++
+ object-based API.
+
+- `--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);
+
- `--object-prefix` : Customise class prefix for C++ object-based API.
- `--object-suffix` : Customise class suffix for C++ object-based API.
@@ -181,16 +194,23 @@
- `--conform-includes PATH` : Include path for the schema given with
`--conform PATH`.
+- `--filename-suffix SUFFIX` : The suffix appended to the generated
+ file names. Default is '_generated'.
+
+- `--filename-ext EXTENSION` : The extension appended to the generated
+ file names. Default is language-specific (e.g. "h" for C++). This
+ should not be used when multiple languages are specified.
+
- `--include-prefix PATH` : Prefix this path to any generated include
statements.
- `--keep-prefix` : Keep original prefix of schema include statement.
-- `--no-fb-impor` : Don't include flatbuffers import statement for TypeScript.
+- `--no-fb-import` : Don't include flatbuffers import statement for TypeScript.
-- `--no-ts-reexpor` : Don't re-export imported dependencies for TypeScript.
+- `--no-ts-reexport` : Don't re-export imported dependencies for TypeScript.
-- `--short-name` : Use short function names for JS and TypeScript.
+- `--short-names` : Use short function names for JS and TypeScript.
- `--reflect-types` : Add minimal type reflection to code generation.
@@ -203,5 +223,8 @@
- `--force-empty` : When serializing from object API representation, force
strings and vectors to empty rather than null.
+- `--force-empty-vectors` : When serializing from object API representation, force
+ vectors to empty rather than null.
+
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 7867f4b..2333f48 100644
--- a/docs/source/CppUsage.md
+++ b/docs/source/CppUsage.md
@@ -114,15 +114,15 @@
MonsterT monsterobj;
// Deserialize from buffer into object.
- UnPackTo(&monsterobj, flatbuffer);
+ GetMonster(flatbuffer)->UnPackTo(&monsterobj);
// Update object directly like a C++ class instance.
- cout << monsterobj->name; // This is now a std::string!
- monsterobj->name = "Bob"; // Change the name.
+ cout << monsterobj.name; // This is now a std::string!
+ monsterobj.name = "Bob"; // Change the name.
// Serialize into new flatbuffer.
FlatBufferBuilder fbb;
- Pack(fbb, &monsterobj);
+ fbb.Finish(Monster::Pack(fbb, &monsterobj));
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The following attributes are specific to the object-based API code generation:
@@ -426,6 +426,8 @@
(see the schema documentation for some specifics on the JSON format
accepted).
+Schema evolution compatibility for the JSON format follows the same rules as the binary format (JSON formatted data will be forwards/backwards compatible with schemas that evolve in a compatible way).
+
There are two ways to use text formats:
#### Using the compiler as a conversion tool
@@ -477,7 +479,7 @@
the current directory.
If there were any parsing errors, `Parse` will return `false`, and
-`Parser::err` contains a human readable error string with a line number
+`Parser::error_` contains a human readable error string with a line number
etc, which you should present to the creator of that file.
After each JSON file, the `Parser::fbb` member variable is the
@@ -567,15 +569,15 @@
```
## Support of floating-point numbers
-The Flatbuffers library assumes that a C++ compiler and a CPU are
+The Flatbuffers library assumes that a C++ compiler and a CPU are
compatible with the `IEEE-754` floating-point standard.
The schema and json parser may fail if `fast-math` or `/fp:fast` mode is active.
### Support of hexadecimal and special floating-point numbers
-According to the [grammar](@ref flatbuffers_grammar) `fbs` and `json` files
+According to the [grammar](@ref flatbuffers_grammar) `fbs` and `json` files
may use hexadecimal and special (`NaN`, `Inf`) floating-point literals.
The Flatbuffers uses `strtof` and `strtod` functions to parse floating-point
-literals. The Flatbuffers library has a code to detect a compiler compatibility
+literals. The Flatbuffers library has a code to detect a compiler compatibility
with the literals. If necessary conditions are met the preprocessor constant
`FLATBUFFERS_HAS_NEW_STRTOD` will be set to `1`.
The support of floating-point literals will be limited at compile time
@@ -583,26 +585,26 @@
In this case, schemas with hexadecimal or special literals cannot be used.
### Comparison of floating-point NaN values
-The floating-point `NaN` (`not a number`) is special value which
+The floating-point `NaN` (`not a number`) is special value which
representing an undefined or unrepresentable value.
-`NaN` may be explicitly assigned to variables, typically as a representation
+`NaN` may be explicitly assigned to variables, typically as a representation
for missing values or may be a result of a mathematical operation.
The `IEEE-754` defines two kind of `NaNs`:
- Quiet NaNs, or `qNaNs`.
- Signaling NaNs, or `sNaNs`.
-According to the `IEEE-754`, a comparison with `NaN` always returns
-an unordered result even when compared with itself. As a result, a whole
+According to the `IEEE-754`, a comparison with `NaN` always returns
+an unordered result even when compared with itself. As a result, a whole
Flatbuffers object will be not equal to itself if has one or more `NaN`.
-Flatbuffers scalar fields that have the default value are not actually stored
+Flatbuffers scalar fields that have the default value are not actually stored
in the serialized data but are generated in code (see [Writing a schema](@ref flatbuffers_guide_writing_schema)).
Scalar fields with `NaN` defaults break this behavior.
-If a schema has a lot of `NaN` defaults the Flatbuffers can override
+If a schema has a lot of `NaN` defaults the Flatbuffers can override
the unordered comparison by the ordered: `(NaN==NaN)->true`.
This ordered comparison is enabled when compiling a program with the symbol
`FLATBUFFERS_NAN_DEFAULTS` defined.
Additional computations added by `FLATBUFFERS_NAN_DEFAULTS` are very cheap
-if GCC or Clang used. These compilers have a compile-time implementation
+if GCC or Clang used. These compilers have a compile-time implementation
of `isnan` checking which MSVC does not.
<br>
diff --git a/docs/source/CsharpUsage.md b/docs/source/CsharpUsage.md
new file mode 100644
index 0000000..83f4842
--- /dev/null
+++ b/docs/source/CsharpUsage.md
@@ -0,0 +1,226 @@
+Use in C# {#flatbuffers_guide_use_c-sharp}
+==============
+
+## Before you get started
+
+Before diving into the FlatBuffers usage in C#, it should be noted that
+the [Tutorial](@ref flatbuffers_guide_tutorial) page has a complete guide to
+general FlatBuffers usage in all of the supported languages (including C#).
+This page is designed to cover the nuances of FlatBuffers usage,
+specific to C#.
+
+You should also have read the [Building](@ref flatbuffers_guide_building)
+documentation to build `flatc` and should be familiar with
+[Using the schema compiler](@ref flatbuffers_guide_using_schema_compiler) and
+[Writing a schema](@ref flatbuffers_guide_writing_schema).
+
+## FlatBuffers C# code location
+
+The code for the FlatBuffers C# library can be found at
+`flatbuffers/net/FlatBuffers`. You can browse the library on the
+[FlatBuffers GitHub page](https://github.com/google/flatbuffers/tree/master/net/
+FlatBuffers).
+
+## Building the FlatBuffers C# library
+
+The `FlatBuffers.csproj` project contains multitargeting for .NET Standard 2.1,
+.NET Standard 2.0, and .NET Framework 4.6 (Unity 2017). Support for .NET
+Framework 3.5 (Unity 5) is provided by the `FlatBuffers.net35.csproj` project.
+In most cases (including Unity 2018 and newer), .NET Standard 2.0 is
+recommended.
+
+You can build for a specific framework target when using the cross-platform
+[.NET Core SDK](https://dotnet.microsoft.com/download) by adding the `-f`
+command line option:
+
+~~~{.sh}
+ dotnet build -f netstandard2.0 "FlatBuffers.csproj"
+~~~
+
+The `FlatBuffers.csproj` project also provides support for defining various
+conditional compilation symbols (see "Conditional compilation symbols" section
+below) using the `-p` command line option:
+
+~~~{.sh}
+ dotnet build -f netstandard2.1 -p:ENABLE_SPAN_T=true -p:UNSAFE_BYTEBUFFER=true "FlatBuffers.csproj"
+~~~
+
+## Testing the FlatBuffers C# library
+
+The code to test the libraries can be found at `flatbuffers/tests`.
+
+The test code for C# is located in the [FlatBuffers.Test](https://github.com/
+google/flatbuffers/tree/master/tests/FlatBuffers.Test) subfolder. To run the
+tests, open `FlatBuffers.Test.csproj` in [Visual Studio](
+https://www.visualstudio.com), and compile/run the project.
+
+Optionally, you can run this using [Mono](http://www.mono-project.com/) instead.
+Once you have installed Mono, you can run the tests from the command line
+by running the following commands from inside the `FlatBuffers.Test` folder:
+
+~~~{.sh}
+ mcs *.cs ../MyGame/Example/*.cs ../../net/FlatBuffers/*.cs
+ mono Assert.exe
+~~~
+
+## Using the FlatBuffers C# library
+
+*Note: See [Tutorial](@ref flatbuffers_guide_tutorial) for a more in-depth
+example of how to use FlatBuffers in C#.*
+
+FlatBuffers supports reading and writing binary FlatBuffers in C#.
+
+To use FlatBuffers in your own code, first generate C# classes from your
+schema with the `--csharp` option to `flatc`.
+Then you can include both FlatBuffers and the generated code to read
+or write a FlatBuffer.
+
+For example, here is how you would read a FlatBuffer binary file in C#:
+First, import the library and generated code. Then, you read a FlatBuffer binary
+file into a `byte[]`. You then turn the `byte[]` into a `ByteBuffer`, which you
+pass to the `GetRootAsMyRootType` function:
+
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cs}
+ using MyGame.Example;
+ using FlatBuffers;
+
+ // This snippet ignores exceptions for brevity.
+ byte[] data = File.ReadAllBytes("monsterdata_test.mon");
+
+ ByteBuffer bb = new ByteBuffer(data);
+ Monster monster = Monster.GetRootAsMonster(bb);
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+Now you can access the data from the `Monster monster`:
+
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cs}
+ short hp = monster.Hp;
+ Vec3 pos = monster.Pos;
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+C# code naming follows standard C# style with PascalCasing identifiers,
+e.g. `GetRootAsMyRootType`. Also, values (except vectors and unions) are
+available as properties instead of parameterless accessor methods.
+The performance-enhancing methods to which you can pass an already created
+object are prefixed with `Get`, e.g.:
+
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cs}
+ // property
+ var pos = monster.Pos;
+
+ // method filling a preconstructed object
+ var preconstructedPos = new Vec3();
+ monster.GetPos(preconstructedPos);
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+## Storing dictionaries in a FlatBuffer
+
+FlatBuffers doesn't support dictionaries natively, but there is support to
+emulate their behavior with vectors and binary search, which means you
+can have fast lookups directly from a FlatBuffer without having to unpack
+your data into a `Dictionary` or similar.
+
+To use it:
+- Designate one of the fields in a table as the "key" field. You do this
+ by setting the `key` attribute on this field, e.g.
+ `name:string (key)`.
+ You may only have one key field, and it must be of string or scalar type.
+- Write out tables of this type as usual, collect their offsets in an
+ array.
+- Instead of calling standard generated method,
+ e.g.: `Monster.createTestarrayoftablesVector`,
+ call `CreateSortedVectorOfMonster` in C#
+ which will first sort all offsets such that the tables they refer to
+ are sorted by the key field, then serialize it.
+- Now when you're accessing the FlatBuffer, you can use
+ the `ByKey` accessor to access elements of the vector, e.g.:
+ `monster.TestarrayoftablesByKey("Frodo")` in C#,
+ which returns an object of the corresponding table type,
+ or `null` if not found.
+ `ByKey` performs a binary search, so should have a similar
+ speed to `Dictionary`, though may be faster because of better caching.
+ `ByKey` only works if the vector has been sorted, it will
+ likely not find elements if it hasn't been sorted.
+
+## Text parsing
+
+There currently is no support for parsing text (Schema's and JSON) directly
+from C#, though you could use the C++ parser through native call
+interfaces available to each language. Please see the
+C++ documentation for more on text parsing.
+
+## Object based API
+
+FlatBuffers is all about memory efficiency, which is why its base API is written
+around using as little as possible of it. This does make the API clumsier
+(requiring pre-order construction of all data, and making mutation harder).
+
+For times when efficiency is less important a more convenient object based API
+can be used (through `--gen-object-api`) that is able to unpack & pack a
+FlatBuffer into objects and standard `System.Collections.Generic` containers,
+allowing for convenient construction, access and mutation.
+
+To use:
+
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cs}
+ // Deserialize from buffer into object.
+ MonsterT monsterobj = GetMonster(flatbuffer).UnPack();
+
+ // Update object directly like a C# class instance.
+ Console.WriteLine(monsterobj.Name);
+ monsterobj.Name = "Bob"; // Change the name.
+
+ // Serialize into new flatbuffer.
+ FlatBufferBuilder fbb = new FlatBufferBuilder(1);
+ fbb.Finish(Monster.Pack(fbb, monsterobj).Value);
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+### Json Serialization
+
+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.
+
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cs}
+ // Deserialize MonsterT from json
+ string jsonText = File.ReadAllText(@"Resources/monsterdata_test.json");
+ MonsterT mon = MonsterT.DeserializeFromJson(jsonText);
+
+ // Serialize MonsterT to json
+ string jsonText2 = mon.SerializeToJson();
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+* Limitation
+ * `hash` attribute currentry not supported.
+* NuGet package Dependency
+ * [Newtonsoft.Json](https://github.com/JamesNK/Newtonsoft.Json)
+
+## Conditional compilation symbols
+
+There are three conditional compilation symbols that have an impact on
+performance/features of the C# `ByteBuffer` implementation.
+
+* `UNSAFE_BYTEBUFFER`
+
+ This will use unsafe code to manipulate the underlying byte array. This can
+ yield a reasonable performance increase.
+
+* `BYTEBUFFER_NO_BOUNDS_CHECK`
+
+ This will disable the bounds check asserts to the byte array. This can yield a
+ small performance gain in normal code.
+
+* `ENABLE_SPAN_T`
+
+ This will enable reading and writing blocks of memory with a `Span<T>` instead
+ of just `T[]`. You can also enable writing directly to shared memory or other
+ types of memory by providing a custom implementation of `ByteBufferAllocator`.
+ `ENABLE_SPAN_T` also requires `UNSAFE_BYTEBUFFER` to be defined, or .NET
+ Standard 2.1.
+
+Using `UNSAFE_BYTEBUFFER` and `BYTEBUFFER_NO_BOUNDS_CHECK` together can yield a
+performance gain of ~15% for some operations, however doing so is potentially
+dangerous. Do so at your own risk!
+
+<br>
diff --git a/docs/source/FlatBuffers.md b/docs/source/FlatBuffers.md
index dc77500..2a2133f 100644
--- a/docs/source/FlatBuffers.md
+++ b/docs/source/FlatBuffers.md
@@ -4,7 +4,7 @@
# Overview {#flatbuffers_overview}
[FlatBuffers](@ref flatbuffers_overview) is an efficient cross platform
-serialization library for C++, C#, C, Go, Java, Kotlin, JavaScript, Lobster, Lua, TypeScript, PHP, Python, and Rust.
+serialization library for C++, C#, C, Go, Java, Kotlin, JavaScript, Lobster, Lua, TypeScript, PHP, Python, Rust and Swift.
It was originally created at Google for game development and other
performance-critical applications.
@@ -130,7 +130,9 @@
- How to [write a schema](@ref flatbuffers_guide_writing_schema).
- How to [use the generated C++ code](@ref flatbuffers_guide_use_cpp) in your
own programs.
-- How to [use the generated Java/C# code](@ref flatbuffers_guide_use_java_c-sharp)
+- How to [use the generated Java code](@ref flatbuffers_guide_use_java)
+ in your own programs.
+- How to [use the generated C# code](@ref flatbuffers_guide_use_c-sharp)
in your own programs.
- How to [use the generated Kotlin code](@ref flatbuffers_guide_use_kotlin)
in your own programs.
@@ -148,6 +150,8 @@
own programs.
- How to [use the generated Rust code](@ref flatbuffers_guide_use_rust) in your
own programs.
+- How to [use the generated Swift code](@ref flatbuffers_guide_use_swift) in your
+ own programs.
- [Support matrix](@ref flatbuffers_support) for platforms/languages/features.
- Some [benchmarks](@ref flatbuffers_benchmarks) showing the advantage of
using FlatBuffers.
@@ -163,6 +167,7 @@
- [GitHub repository](http://github.com/google/flatbuffers)
- [Landing page](http://google.github.io/flatbuffers)
- [FlatBuffers Google Group](https://groups.google.com/forum/#!forum/flatbuffers)
+- [Discord](https://discord.gg/6qgKs3R) and [Gitter](https://gitter.im/lobster_programming_language/community) chat.
- [FlatBuffers Issues Tracker](http://github.com/google/flatbuffers/issues)
- Independent implementations & tools:
- [FlatCC](https://github.com/dvidelabs/flatcc) Alternative FlatBuffers
@@ -178,3 +183,6 @@
- [FlatBuffers in Android](http://frogermcs.github.io/flatbuffers-in-android-introdution/)
- [Parsing JSON to FlatBuffers in Java](http://frogermcs.github.io/json-parsing-with-flatbuffers-in-android/)
- [FlatBuffers in Unity](http://exiin.com/blog/flatbuffers-for-unity-sample-code/)
+ - [FlexBuffers C#](https://github.com/mzaks/FlexBuffers-CSharp) and
+ [article](https://medium.com/@icex33/flexbuffers-for-unity3d-4d1ab5c53fbe?)
+ on its use.
diff --git a/docs/source/FlexBuffers.md b/docs/source/FlexBuffers.md
index a089df3..974dd69 100644
--- a/docs/source/FlexBuffers.md
+++ b/docs/source/FlexBuffers.md
@@ -29,9 +29,7 @@
only use it if you need it.
-# Usage
-
-This is for C++, other languages may follow.
+# Usage in C++
Include the header `flexbuffers.h`, which in turn depends on `flatbuffers.h`
and `util.h`.
@@ -98,10 +96,10 @@
`IndirectFloat` is an interesting feature that allows you to store values
by offset rather than inline. Though that doesn't make any visible change
to the user, the consequence is that large values (especially doubles or
-64 bit ints) that occur more than once can be shared. Another use case is
-inside of vectors, where the largest element makes up the size of all elements
-(e.g. a single double forces all elements to 64bit), so storing a lot of small
-integers together with a double is more efficient if the double is indirect.
+64 bit ints) that occur more than once can be shared (see ReuseValue).
+Another use case is inside of vectors, where the largest element makes
+up the size of all elements (e.g. a single double forces all elements to
+64bit), so storing a lot of small integers together with a double is more efficient if the double is indirect.
Accessing it:
@@ -122,6 +120,46 @@
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+# Usage in Java
+
+Java implementation follows the C++ one, closely.
+
+For creating the equivalent of the same JSON `{ vec: [ -100, "Fred", 4.0 ], foo: 100 }`,
+one could use the following code:
+
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.java}
+FlexBuffersBuilder builder = new FlexBuffersBuilder(ByteBuffer.allocate(512),
+ FlexBuffersBuilder.BUILDER_FLAG_SHARE_KEYS_AND_STRINGS);
+int smap = builder.startMap();
+int svec = builder.startVector();
+builder.putInt(-100);
+builder.putString("Fred");
+builder.putFloat(4.0);
+builder.endVector("vec", svec, false, false);
+builder.putInt("foo", 100);
+builder.endMap(null, smap);
+ByteBuffer bb = builder.finish();
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+Similarly, to read the data, just:
+
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.java}
+FlexBuffers.Map map = FlexBuffers.getRoot(bb).asMap();
+map.size(); // 2
+FlexBuffers.Vector vec = map.get("vec").asVector();
+vec.size(); // 3
+vec.get(0).asLong(); // -100;
+vec.get(1).asString(); // "Fred";
+vec.get(1).asLong(); // 0 (Number parsing failed).
+vec.get(2).asFloat(); // 4.0
+vec.get(2).asString().isEmpty(); // true (Wrong Type).
+vec.get(2).asString(); // "" (This still works though).
+vec.get(2).toString(); // "4.0" (Or have it converted).
+map.get("foo").asUInt(); // 100
+map.get("unknown").isNull(); // true
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+
# Binary encoding
A description of how FlexBuffers are encoded is in the
diff --git a/docs/source/Grammar.md b/docs/source/Grammar.md
index 51cc5f0..f8cf832 100644
--- a/docs/source/Grammar.md
+++ b/docs/source/Grammar.md
@@ -35,9 +35,9 @@
metadata = [ `(` commasep( ident [ `:` single\_value ] ) `)` ]
-scalar = integer\_constant | float\_constant
+scalar = boolean\_constant | integer\_constant | float\_constant
-object = { commasep( ident `:` value ) }
+object = `{` commasep( ident `:` value ) `}`
single\_value = scalar | string\_constant
@@ -69,6 +69,6 @@
special\_float\_constant = `[-+]?(nan|inf|infinity)`
-float\_constant = decimal\_float\_constant | hexadecimal\_float\_constant | special\_float\_constant
+float\_constant = dec\_float\_constant | hex\_float\_constant | special\_float\_constant
-boolean\_constant = `(true|false)` | (integer\_constant ? `true` : `false`)
+boolean\_constant = `true` | `false`
diff --git a/docs/source/Internals.md b/docs/source/Internals.md
index d2064ca..389a8f9 100644
--- a/docs/source/Internals.md
+++ b/docs/source/Internals.md
@@ -62,7 +62,7 @@
typically is forward (towards a higher memory location). Any backwards
offsets will be explicitly marked as such.
-The format starts with an `uoffset_t` to the root object in the buffer.
+The format starts with an `uoffset_t` to the root table in the buffer.
We have two kinds of objects, structs and tables.
diff --git a/docs/source/JavaCsharpUsage.md b/docs/source/JavaCsharpUsage.md
deleted file mode 100644
index 102ce37..0000000
--- a/docs/source/JavaCsharpUsage.md
+++ /dev/null
@@ -1,172 +0,0 @@
-Use in Java/C# {#flatbuffers_guide_use_java_c-sharp}
-==============
-
-## Before you get started
-
-Before diving into the FlatBuffers usage in Java or C#, it should be noted that
-the [Tutorial](@ref flatbuffers_guide_tutorial) page has a complete guide to
-general FlatBuffers usage in all of the supported languages (including both Java
-and C#). This page is designed to cover the nuances of FlatBuffers usage,
-specific to Java and C#.
-
-You should also have read the [Building](@ref flatbuffers_guide_building)
-documentation to build `flatc` and should be familiar with
-[Using the schema compiler](@ref flatbuffers_guide_using_schema_compiler) and
-[Writing a schema](@ref flatbuffers_guide_writing_schema).
-
-## FlatBuffers Java and C-sharp code location
-
-#### Java
-
-The code for the FlatBuffers Java library can be found at
-`flatbuffers/java/com/google/flatbuffers`. You can browse the library on the
-[FlatBuffers GitHub page](https://github.com/google/flatbuffers/tree/master/
-java/com/google/flatbuffers).
-
-#### C-sharp
-
-The code for the FlatBuffers C# library can be found at
-`flatbuffers/net/FlatBuffers`. You can browse the library on the
-[FlatBuffers GitHub page](https://github.com/google/flatbuffers/tree/master/net/
-FlatBuffers).
-
-## Testing the FlatBuffers Java and C-sharp libraries
-
-The code to test the libraries can be found at `flatbuffers/tests`.
-
-#### Java
-
-The test code for Java is located in [JavaTest.java](https://github.com/google
-/flatbuffers/blob/master/tests/JavaTest.java).
-
-To run the tests, use either [JavaTest.sh](https://github.com/google/
-flatbuffers/blob/master/tests/JavaTest.sh) or [JavaTest.bat](https://github.com/
-google/flatbuffers/blob/master/tests/JavaTest.bat), depending on your operating
-system.
-
-*Note: These scripts require that [Java](https://www.oracle.com/java/index.html)
-is installed.*
-
-#### C-sharp
-
-The test code for C# is located in the [FlatBuffers.Test](https://github.com/
-google/flatbuffers/tree/master/tests/FlatBuffers.Test) subfolder. To run the
-tests, open `FlatBuffers.Test.csproj` in [Visual Studio](
-https://www.visualstudio.com), and compile/run the project.
-
-Optionally, you can run this using [Mono](http://www.mono-project.com/) instead.
-Once you have installed `Mono`, you can run the tests from the command line
-by running the following commands from inside the `FlatBuffers.Test` folder:
-
-~~~{.sh}
- mcs *.cs ../MyGame/Example/*.cs ../../net/FlatBuffers/*.cs
- mono Assert.exe
-~~~
-
-## Using the FlatBuffers Java (and C#) library
-
-*Note: See [Tutorial](@ref flatbuffers_guide_tutorial) for a more in-depth
-example of how to use FlatBuffers in Java or C#.*
-
-FlatBuffers supports reading and writing binary FlatBuffers in Java and C#.
-
-To use FlatBuffers in your own code, first generate Java classes from your
-schema with the `--java` option to `flatc`. (Or for C# with `--csharp`).
-Then you can include both FlatBuffers and the generated code to read
-or write a FlatBuffer.
-
-For example, here is how you would read a FlatBuffer binary file in Java:
-First, import the library and generated code. Then, you read a FlatBuffer binary
-file into a `byte[]`. You then turn the `byte[]` into a `ByteBuffer`, which you
-pass to the `getRootAsMyRootType` function:
-
-*Note: The code here is written from the perspective of Java. Code for both
-languages is both generated and used in nearly the exact same way, with only
-minor differences. These differences are
-[explained in a section below](#differences_in_c-sharp).*
-
-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.java}
- import MyGame.Example.*;
- import com.google.flatbuffers.FlatBufferBuilder;
-
- // This snippet ignores exceptions for brevity.
- File file = new File("monsterdata_test.mon");
- RandomAccessFile f = new RandomAccessFile(file, "r");
- byte[] data = new byte[(int)f.length()];
- f.readFully(data);
- f.close();
-
- ByteBuffer bb = ByteBuffer.wrap(data);
- Monster monster = Monster.getRootAsMonster(bb);
-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-
-Now you can access the data from the `Monster monster`:
-
-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.java}
- short hp = monster.hp();
- Vec3 pos = monster.pos();
-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-
-<a name="differences_in_c-sharp">
-#### Differences in C-sharp
-</a>
-
-C# code works almost identically to Java, with only a few minor differences.
-You can see an example of C# code in
-`tests/FlatBuffers.Test/FlatBuffersExampleTests.cs` or
-`samples/SampleBinary.cs`.
-
-First of all, naming follows standard C# style with `PascalCasing` identifiers,
-e.g. `GetRootAsMyRootType`. Also, values (except vectors and unions) are
-available as properties instead of parameterless accessor methods as in Java.
-The performance-enhancing methods to which you can pass an already created
-object are prefixed with `Get`, e.g.:
-
-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cs}
- // property
- var pos = monster.Pos;
-
- // method filling a preconstructed object
- var preconstructedPos = new Vec3();
- monster.GetPos(preconstructedPos);
-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-
-## Storing dictionaries in a FlatBuffer
-
-FlatBuffers doesn't support dictionaries natively, but there is support to
-emulate their behavior with vectors and binary search, which means you
-can have fast lookups directly from a FlatBuffer without having to unpack
-your data into a `Dictionary` or similar.
-
-To use it:
-- Designate one of the fields in a table as the "key" field. You do this
- by setting the `key` attribute on this field, e.g.
- `name:string (key)`.
- You may only have one key field, and it must be of string or scalar type.
-- Write out tables of this type as usual, collect their offsets in an
- array.
-- Instead of calling standard generated method,
- e.g.: `Monster.createTestarrayoftablesVector`,
- call `CreateSortedVectorOfMonster` in C# or
- `createSortedVectorOfTables` (from the `FlatBufferBuilder` object) in Java,
- which will first sort all offsets such that the tables they refer to
- are sorted by the key field, then serialize it.
-- Now when you're accessing the FlatBuffer, you can use
- the `ByKey` accessor to access elements of the vector, e.g.:
- `monster.testarrayoftablesByKey("Frodo")` in Java or
- `monster.TestarrayoftablesByKey("Frodo")` in C#,
- which returns an object of the corresponding table type,
- or `null` if not found.
- `ByKey` performs a binary search, so should have a similar
- speed to `Dictionary`, though may be faster because of better caching.
- `ByKey` only works if the vector has been sorted, it will
- likely not find elements if it hasn't been sorted.
-
-## Text parsing
-
-There currently is no support for parsing text (Schema's and JSON) directly
-from Java or C#, though you could use the C++ parser through native call
-interfaces available to each language. Please see the
-C++ documentation for more on text parsing.
-
-<br>
diff --git a/docs/source/JavaUsage.md b/docs/source/JavaUsage.md
new file mode 100644
index 0000000..30ba061
--- /dev/null
+++ b/docs/source/JavaUsage.md
@@ -0,0 +1,114 @@
+Use in Java {#flatbuffers_guide_use_java}
+==============
+
+## Before you get started
+
+Before diving into the FlatBuffers usage in Java, it should be noted that
+the [Tutorial](@ref flatbuffers_guide_tutorial) page has a complete guide to
+general FlatBuffers usage in all of the supported languages (including Java).
+This page is designed to cover the nuances of FlatBuffers usage,
+specific to Java.
+
+You should also have read the [Building](@ref flatbuffers_guide_building)
+documentation to build `flatc` and should be familiar with
+[Using the schema compiler](@ref flatbuffers_guide_using_schema_compiler) and
+[Writing a schema](@ref flatbuffers_guide_writing_schema).
+
+## FlatBuffers Java code location
+
+The code for the FlatBuffers Java library can be found at
+`flatbuffers/java/com/google/flatbuffers`. You can browse the library on the
+[FlatBuffers GitHub page](https://github.com/google/flatbuffers/tree/master/
+java/com/google/flatbuffers).
+
+## Testing the FlatBuffers Java libraries
+
+The code to test the libraries can be found at `flatbuffers/tests`.
+
+The test code for Java is located in [JavaTest.java](https://github.com/google
+/flatbuffers/blob/master/tests/JavaTest.java).
+
+To run the tests, use either [JavaTest.sh](https://github.com/google/
+flatbuffers/blob/master/tests/JavaTest.sh) or [JavaTest.bat](https://github.com/
+google/flatbuffers/blob/master/tests/JavaTest.bat), depending on your operating
+system.
+
+*Note: These scripts require that [Java](https://www.oracle.com/java/index.html)
+is installed.*
+
+## Using the FlatBuffers Java library
+
+*Note: See [Tutorial](@ref flatbuffers_guide_tutorial) for a more in-depth
+example of how to use FlatBuffers in Java.*
+
+FlatBuffers supports reading and writing binary FlatBuffers in Java.
+
+To use FlatBuffers in your own code, first generate Java classes from your
+schema with the `--java` option to `flatc`.
+Then you can include both FlatBuffers and the generated code to read
+or write a FlatBuffer.
+
+For example, here is how you would read a FlatBuffer binary file in Java:
+First, import the library and generated code. Then, you read a FlatBuffer binary
+file into a `byte[]`. You then turn the `byte[]` into a `ByteBuffer`, which you
+pass to the `getRootAsMyRootType` function:
+
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.java}
+ import MyGame.Example.*;
+ import com.google.flatbuffers.FlatBufferBuilder;
+
+ // This snippet ignores exceptions for brevity.
+ File file = new File("monsterdata_test.mon");
+ RandomAccessFile f = new RandomAccessFile(file, "r");
+ byte[] data = new byte[(int)f.length()];
+ f.readFully(data);
+ f.close();
+
+ ByteBuffer bb = ByteBuffer.wrap(data);
+ Monster monster = Monster.getRootAsMonster(bb);
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+Now you can access the data from the `Monster monster`:
+
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.java}
+ short hp = monster.hp();
+ Vec3 pos = monster.pos();
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+## Storing dictionaries in a FlatBuffer
+
+FlatBuffers doesn't support dictionaries natively, but there is support to
+emulate their behavior with vectors and binary search, which means you
+can have fast lookups directly from a FlatBuffer without having to unpack
+your data into a `Dictionary` or similar.
+
+To use it:
+- Designate one of the fields in a table as the "key" field. You do this
+ by setting the `key` attribute on this field, e.g.
+ `name:string (key)`.
+ You may only have one key field, and it must be of string or scalar type.
+- Write out tables of this type as usual, collect their offsets in an
+ array.
+- Instead of calling standard generated method,
+ e.g.: `Monster.createTestarrayoftablesVector`,
+ call `createSortedVectorOfTables` (from the `FlatBufferBuilder` object).
+ which will first sort all offsets such that the tables they refer to
+ are sorted by the key field, then serialize it.
+- Now when you're accessing the FlatBuffer, you can use
+ the `ByKey` accessor to access elements of the vector, e.g.:
+ `monster.testarrayoftablesByKey("Frodo")`.
+ which returns an object of the corresponding table type,
+ or `null` if not found.
+ `ByKey` performs a binary search, so should have a similar
+ speed to `Dictionary`, though may be faster because of better caching.
+ `ByKey` only works if the vector has been sorted, it will
+ likely not find elements if it hasn't been sorted.
+
+## Text parsing
+
+There currently is no support for parsing text (Schema's and JSON) directly
+from Java, though you could use the C++ parser through native call
+interfaces available to each language. Please see the
+C++ documentation for more on text parsing.
+
+<br>
diff --git a/docs/source/Schemas.md b/docs/source/Schemas.md
index 403aebb..bd119b0 100644
--- a/docs/source/Schemas.md
+++ b/docs/source/Schemas.md
@@ -345,6 +345,9 @@
Note: currently not guaranteed to have an effect when used with
`--object-api`, since that may allocate objects at alignments less than
what you specify with `force_align`.
+- `force_align: size` (on a vector): force the alignment of this vector to be
+ something different than what the element size would normally dictate.
+ Note: Now only work for generated C++ code.
- `bit_flags` (on an unsigned enum): the values of this field indicate bits,
meaning that any unsigned value N specified in the schema will end up
representing 1<<N, or if you don't specify values at all, you'll get
@@ -563,7 +566,7 @@
that tries to do so will result in compile errors), but can still read
old data (they will ignore the field).
- table { c:int a:int; b:int; }
+ table { c:int; a:int; b:int; }
This is NOT ok, as this makes the schemas incompatible. Old code reading newer
data will interpret `c` as if it was `a`, and new code reading old data
diff --git a/docs/source/Support.md b/docs/source/Support.md
index c8ac7f7..ab3b4bd 100644
--- a/docs/source/Support.md
+++ b/docs/source/Support.md
@@ -18,23 +18,23 @@
NOTE: this table is a start, it needs to be extended.
-Feature | C++ | Java | C# | Go | Python | JS | TS | C | PHP | Dart | Lobster | Rust
------------------------------- | ------ | ------ | ------ | ------ | ------ | --------- | --------- | ------ | --- | ------- | ------- | ----
-Codegen for all basic features | Yes | Yes | Yes | Yes | Yes | Yes | Yes | Yes | WiP | Yes | Yes | Yes
-JSON parsing | Yes | No | No | No | No | No | No | Yes | No | No | Yes | No
-Simple mutation | Yes | Yes | Yes | Yes | No | No | No | No | No | No | No | No
-Reflection | Yes | No | No | No | No | No | No | Basic | No | No | No | No
-Buffer verifier | Yes | No | No | No | No | No | No | Yes | No | No | No | No
-Testing: basic | Yes | Yes | Yes | Yes | Yes | Yes | Yes | Yes | ? | Yes | Yes | Yes
-Testing: fuzz | Yes | No | No | Yes | Yes | No | No | No | ? | No | No | Yes
-Performance: | Superb | Great | Great | Great | Ok | ? | ? | Superb | ? | ? | Great | Superb
-Platform: Windows | VS2010 | Yes | Yes | ? | ? | ? | Yes | VS2010 | ? | Yes | Yes | Yes
-Platform: Linux | GCC282 | Yes | ? | Yes | Yes | ? | Yes | Yes | ? | Yes | Yes | Yes
-Platform: OS X | Xcode4 | ? | ? | ? | Yes | ? | Yes | Yes | ? | Yes | Yes | Yes
-Platform: Android | NDK10d | Yes | ? | ? | ? | ? | ? | ? | ? | Flutter | Yes | ?
-Platform: iOS | ? | ? | ? | ? | ? | ? | ? | ? | ? | Flutter | Yes | ?
-Engine: Unity | ? | ? | Yes | ? | ? | ? | ? | ? | ? | ? | No | ?
-Primary authors (github) | aard* | aard* | ev*/js*| rw | rw | evanw/ev* | kr* | mik* | ch* | dnfield | aard* | rw
+Feature | C++ | Java | C# | Go | Python | JS | TS | C | PHP | Dart | Lobster | Rust | Swift
+------------------------------ | ------ | ------ | ------ | ------ | ------ | --------- | --------- | ------ | --- | ------- | ------- | ------- | ------
+Codegen for all basic features | Yes | Yes | Yes | Yes | Yes | Yes | Yes | Yes | WiP | Yes | Yes | Yes | Yes
+JSON parsing | Yes | No | No | No | No | No | No | Yes | No | No | Yes | No | No
+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
+Testing: basic | Yes | Yes | Yes | Yes | Yes | Yes | Yes | Yes | ? | Yes | Yes | Yes | Yes
+Testing: fuzz | Yes | No | No | Yes | Yes | No | No | No | ? | No | No | Yes | No
+Performance: | Superb | Great | Great | Great | Ok | ? | ? | Superb | ? | ? | Great | Superb | Great
+Platform: Windows | VS2010 | Yes | Yes | ? | ? | ? | Yes | VS2010 | ? | Yes | Yes | Yes | No
+Platform: Linux | GCC282 | Yes | ? | Yes | Yes | ? | Yes | Yes | ? | Yes | Yes | Yes | Yes
+Platform: OS X | Xcode4 | ? | ? | ? | Yes | ? | Yes | Yes | ? | Yes | Yes | Yes | Yes
+Platform: Android | NDK10d | Yes | ? | ? | ? | ? | ? | ? | ? | Flutter | Yes | ? | No
+Platform: iOS | ? | ? | ? | ? | ? | ? | ? | ? | ? | Flutter | Yes | ? | Yes
+Engine: Unity | ? | ? | Yes | ? | ? | ? | ? | ? | ? | ? | No | ? | No
+Primary authors (github) | aard* | aard* | ev*/js*| rw | rw | evanw/ev* | kr* | mik* | ch* | dnfield | aard* | rw | mi*/mz*
* aard = aardappel (previously: gwvo)
* ev = evolutional
@@ -42,5 +42,7 @@
* mik = mikkelfj
* ch = chobie
* kr = krojew
+ * mi = mustiikhalil
+ * mz = mzaks
<br>
diff --git a/docs/source/SwiftUsage.md b/docs/source/SwiftUsage.md
new file mode 100644
index 0000000..d5640f6
--- /dev/null
+++ b/docs/source/SwiftUsage.md
@@ -0,0 +1,91 @@
+Use in Swift {#flatbuffers_guide_use_swift}
+=========
+
+## Before you get started
+
+Before diving into the FlatBuffers usage in Swift, it should be noted that
+the [Tutorial](@ref flatbuffers_guide_tutorial) page has a complete guide
+to general FlatBuffers usage in all of the supported languages (including Swift).
+This page is designed to cover the nuances of FlatBuffers usage, specific to
+Swift.
+
+You should also have read the [Building](@ref flatbuffers_guide_building)
+documentation to build `flatc` and should be familiar with
+[Using the schema compiler](@ref flatbuffers_guide_using_schema_compiler) and
+[Writing a schema](@ref flatbuffers_guide_writing_schema).
+
+## FlatBuffers Swift library code location
+
+The code for the FlatBuffers Swift library can be found at
+`flatbuffers/swift`. You can browse the library code on the [FlatBuffers
+GitHub page](https://github.com/google/flatbuffers/tree/master/swift).
+
+## Testing the FlatBuffers Swift library
+
+The code to test the Swift library can be found at `flatbuffers/Flatbuffers.Test.Swift`.
+The test code itself is located in [Flatbuffers.Test.Swift](https://github.com/google/flatbuffers/blob/master/tests/FlatBuffers.Test.Swift).
+
+To run the tests, use the [SwiftTest.sh](https://github.com/google/flatbuffers/blob/master/tests/FlatBuffers.Test.Swift/SwiftTest.sh) shell script.
+
+*Note: The shell script requires [Swift](https://swift.org) to
+be installed.*
+
+## Using the FlatBuffers Swift library
+
+*Note: See [Tutorial](@ref flatbuffers_guide_tutorial) for a more in-depth
+example of how to use FlatBuffers in Swift.*
+
+FlatBuffers supports reading and writing binary FlatBuffers in Swift.
+
+To use FlatBuffers in your own code, first generate Swift structs from your
+schema with the `--swift` option to `flatc`. Then include FlatBuffers using `SPM` in
+by adding the path to `FlatBuffers/swift` into it. The generated code should also be
+added to xcode or the path of the package you will be using. Note: sometimes xcode cant
+and wont see the generated files, so it's better that you copy them to xcode.
+
+For example, here is how you would read a FlatBuffer binary file in Swift: First,
+include the library and copy thegenerated code. Then read a FlatBuffer binary file or
+a data object from the server, which you can pass into the `GetRootAsMonster` function.
+
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.swift}
+ import FlatBuffers
+
+ typealias Monster1 = MyGame.Sample.Monster
+ typealias Vec3 = MyGame.Sample.Vec3
+
+ let path = FileManager.default.currentDirectoryPath
+ let url = URL(fileURLWithPath: path, isDirectory: true).appendingPathComponent("monsterdata_test").appendingPathExtension("mon")
+ guard let data = try? Data(contentsOf: url) else { return }
+
+ let monster = Monster.getRootAsMonster(bb: ByteBuffer(data: data))
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+Now you can access values like this:
+
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.swift}
+ let hp = monster.hp
+ let pos = monster.pos
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+
+In some cases it's necessary to modify values in an existing FlatBuffer in place (without creating a copy). For this reason, scalar fields of a Flatbuffer table or struct can be mutated.
+
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.swift}
+ let monster = Monster.getRootAsMonster(bb: ByteBuffer(data: data))
+
+ if !monster.mutate(hp: 10) {
+ fatalError("couldn't mutate")
+ }
+ // mutate a struct field
+ let vec = monster.pos.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.
+ if !monster.mutate(mana: 20) {
+ fatalError("couldn't mutate")
+ }
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+The term `mutate` is used instead of `set` to indicate that this is a special use case. All mutate functions return a boolean value which is false if the field we're trying to mutate is not available in the buffer.
+
+<br>
diff --git a/docs/source/Tutorial.md b/docs/source/Tutorial.md
index e8d8519..b4db5cf 100644
--- a/docs/source/Tutorial.md
+++ b/docs/source/Tutorial.md
@@ -35,6 +35,7 @@
<input type="radio" name="language" value="lua">Lua</input>
<input type="radio" name="language" value="lobster">Lobster</input>
<input type="radio" name="language" value="rust">Rust</input>
+ <input type="radio" name="language" value="swift">Swift</input>
</form>
\endhtmlonly
@@ -152,6 +153,9 @@
<div class="language-rust">
[sample_binary.rs](https://github.com/google/flatbuffers/blob/master/samples/sample_binary.rs)
</div>
+<div class="language-swift">
+[sample_binary.swift](https://github.com/google/flatbuffers/blob/master/samples/sample_binary.swift)
+</div>
## Writing the Monsters' FlatBuffer Schema
@@ -245,10 +249,12 @@
of `short` and `float32` instead of `float`. Thus we could also write
the `Weapon` table as:
+~~~
table Weapon {
name:string;
damage:int16;
}
+~~~
#### More Information About Schemas
@@ -275,7 +281,6 @@
Please be aware of the difference between `flatc` and `flatcc` tools.
<br>
</div>
-
<div class="language-cpp">
~~~{.sh}
cd flatbuffers/samples
@@ -363,6 +368,12 @@
./../flatc --rust monster.fbs
~~~
</div>
+<div class="language-swift">
+~~~{.sh}
+ cd flatbuffers/samples
+ ./../flatc --swift monster.fbs
+~~~
+</div>
For a more complete guide to using the `flatc` compiler, please read the
[Using the schema compiler](@ref flatbuffers_guide_using_schema_compiler)
@@ -441,9 +452,11 @@
~~~
</div>
<div class="language-typescript">
+~~~{.ts}
// note: import flatbuffers with your desired import method
import { MyGame } from './monster_generated';
+~~~
</div>
<div class="language-php">
~~~{.php}
@@ -522,6 +535,20 @@
Weapon, WeaponArgs};
~~~
</div>
+<div class="language-swift">
+~~~{.swift}
+ /**
+ // make sure that monster_generated.swift is included in your project
+ */
+ 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
+~~~
+</div>
Now we are ready to start building some buffers. In order to start, we need
to create an instance of the `FlatBufferBuilder`, which will contain the buffer
@@ -627,9 +654,15 @@
let mut builder = flatbuffers::FlatBufferBuilder::new_with_capacity(1024);
~~~
</div>
+<div class="language-swift">
+~~~{.swift}
+ // create a `FlatBufferBuilder`, which will be used to serialize objects
+ let builder = FlatBufferBuilder(initialSize: 1024)
+~~~
+</div>
After creating the `builder`, we can start serializing our data. Before we make
-our `orc` Monster, lets create some `Weapon`s: a `Sword` and an `Axe`.
+our `orc` Monster, let's create some `Weapon`s: a `Sword` and an `Axe`.
<div class="language-cpp">
~~~{.cpp}
@@ -738,7 +771,7 @@
~~~
</div>
<div class="language-typescript">
-~~~{.js}
+~~~{.ts}
let weaponOne = builder.createString('Sword');
let weaponTwo = builder.createString('Axe');
@@ -877,6 +910,24 @@
});
~~~
</div>
+<div class="language-swift">
+~~~{.swift}
+ let weapon1Name = builder.create(string: "Sword")
+ let weapon2Name = builder.create(string: "Axe")
+
+ // start creating the weapon by calling startWeapon
+ let weapon1Start = Weapon.startWeapon(&builder)
+ Weapon.add(name: weapon1Name, &builder)
+ Weapon.add(damage: 3, &builder)
+ // end the object by passing the start point for the weapon 1
+ let sword = Weapon.endWeapon(&builder, start: weapon1Start)
+
+ let weapon2Start = Weapon.startWeapon(&builder)
+ Weapon.add(name: weapon2Name, &builder)
+ Weapon.add(damage: 5, &builder)
+ let axe = Weapon.endWeapon(&builder, start: weapon2Start)
+~~~
+</div>
Now let's create our monster, the `orc`. For this `orc`, lets make him
`red` with rage, positioned at `(1.0, 2.0, 3.0)`, and give him
@@ -887,7 +938,7 @@
is defeated.
Before we serialize a monster, we need to first serialize any objects that are
-contained there-in, i.e. we serialize the data tree using depth-first, pre-order
+contained therein, i.e. we serialize the data tree using depth-first, pre-order
traversal. This is generally easy to do on any tree structures.
<div class="language-cpp">
@@ -980,7 +1031,7 @@
~~~
</div>
<div class="language-typescript">
-~~~{.js}
+~~~{.ts}
// Serialize a name for our monster, called 'Orc'.
let name = builder.createString('Orc');
@@ -1068,6 +1119,16 @@
let inventory = builder.create_vector(&[0u8, 1, 2, 3, 4, 5, 6, 7, 8, 9]);
~~~
</div>
+<div class="language-swift">
+~~~{.swift}
+ // Name of the Monster.
+ let name = builder.create(string: "Orc")
+
+ // create inventory
+ let inventory: [Byte] = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
+ let inventoryOffset = builder.createVector(inventory)
+~~~
+</div>
We serialized two built-in data types (`string` and `vector`) and captured
their return values. These values are offsets into the serialized data,
@@ -1212,10 +1273,17 @@
let weapons = builder.create_vector(&[sword, axe]);
~~~
</div>
+<div class="language-swift">
+~~~{.swift}
+ // Create a FlatBuffer `vector` that contains offsets to the sword and axe
+ // we created above.
+ let weaponsOffset = builder.createVector(ofOffsets: [sword, axe])
+~~~
+</div>
<br>
-Note there's additional convenience overloads of `CreateVector`, allowing you
-to work with data that's not in a `std::vector`, or allowing you to generate
+Note there are additional convenience overloads of `CreateVector`, allowing you
+to work with data that's not in a `std::vector` or allowing you to generate
elements by calling a lambda. For the common case of `std::vector<std::string>`
there's also `CreateVectorOfStrings`.
</div>
@@ -1348,6 +1416,16 @@
// let path = builder.create_vector(&[&x, &y]);
~~~
</div>
+<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)
+~~~
+</div>
+
We have now serialized the non-scalar components of the orc, so we
can serialize the monster itself:
@@ -1621,6 +1699,21 @@
});
~~~
</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)
+~~~
+</div>
Note how we create `Vec3` struct in-line in the table. Unlike tables, structs
are simple combinations of scalars that are always stored inline, just like
@@ -1635,7 +1728,7 @@
default value, the field will not actually be written to the buffer, since the
default value will be returned on query anyway. This is a nice space savings,
especially if default values are common in your data. It also means that you do
-not need to be worried of adding a lot of fields that are only used in a small
+not need to be worried about adding a lot of fields that are only used in a small
number of instances, as it will not bloat the buffer if unused.*
<div class="language-cpp">
@@ -1687,15 +1780,15 @@
</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
+`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
to by the `union`. This allows you to know which type to cast to at runtime.
-Second, is the `union`'s data.
+Second is the `union`'s data.
In our example, the last two things we added to our `Monster` were the
`Equipped Type` and the `Equipped` union itself.
-Here is a repetition these lines, to help highlight them more clearly:
+Here is a repetition of these lines, to help highlight them more clearly:
<div class="language-cpp">
~~~{.cpp}
@@ -1789,6 +1882,13 @@
monster_builder.add_equipped(axe.as_union_value()); // Union data
~~~
</div>
+<div class="language-swift">
+ ~~~{.swift}
+ Monster.add(equippedType: .weapon, builder) // Type of union
+ Monster.add(equipped: axe, builder) // Union data
+ ~~~
+</div>
+
After you have created your buffer, you will have the offset to the root of the
data in the `orc` variable, so you can finish the buffer by calling the
@@ -1800,8 +1900,7 @@
// Call `Finish()` to instruct the builder that this monster is complete.
// Note: Regardless of how you created the `orc`, you still need to call
// `Finish()` on the `FlatBufferBuilder`.
- builder.Finish(orc); // You could also call `FinishMonsterBuffer(builder,
- // orc);`.
+ builder.Finish(orc); // You could also call `FinishMonsterBuffer(builder, orc);`.
~~~
</div>
<div class="language-java">
@@ -1837,22 +1936,19 @@
<div class="language-javascript">
~~~{.js}
// Call `finish()` to instruct the builder that this monster is complete.
- builder.finish(orc); // You could also call `MyGame.Sample.Monster.finishMonsterBuffer(builder,
- // orc);`.
+ builder.finish(orc); // You could also call `MyGame.Sample.Monster.finishMonsterBuffer(builder, orc);`.
~~~
</div>
<div class="language-typescript">
~~~{.ts}
// Call `finish()` to instruct the builder that this monster is complete.
- builder.finish(orc); // You could also call `MyGame.Sample.Monster.finishMonsterBuffer(builder,
- // orc);`.
+ builder.finish(orc); // You could also call `MyGame.Sample.Monster.finishMonsterBuffer(builder, orc);`.
~~~
</div>
<div class="language-php">
~~~{.php}
// Call `finish()` to instruct the builder that this monster is complete.
- $builder->finish($orc); // You may also call `\MyGame\Sample\Monster::FinishMonsterBuffer(
- // $builder, $orc);`.
+ $builder->finish($orc); // You may also call `\MyGame\Sample\Monster::FinishMonsterBuffer($builder, $orc);`.
~~~
</div>
<div class="language-c">
@@ -1884,6 +1980,12 @@
builder.finish(orc, None);
~~~
</div>
+<div class="language-swift">
+~~~{.swift}
+ // Call `finish(offset:)` to instruct the builder that this monster is complete.
+ builder.finish(offset: orc)
+~~~
+</div>
The buffer is now ready to be stored somewhere, sent over the network, be
compressed, or whatever you'd like to do with it. You can access the buffer
@@ -2011,13 +2113,34 @@
let buf = builder.finished_data(); // Of type `&[u8]`
~~~
</div>
+<div class="language-swift">
+~~~{.swift}
+ // This must be called after `finish()`.
+ // `sizedByteArray` returns the finished buf of type [UInt8].
+ let buf = builder.sizedByteArray
+ // or you can use to get an object of type Data
+ let bufData = ByteBuffer(data: builder.data)
+~~~
+</div>
-
-Now you can write the bytes to a file, send them over the network..
+Now you can write the bytes to a file or send them over the network.
**Make sure your file mode (or transfer protocol) is set to BINARY, not text.**
If you transfer a FlatBuffer in text mode, the buffer will be corrupted,
which will lead to hard to find problems when you read the buffer.
+<div class="language-javascript">
+For example, in Node you can simply do:
+~~~{.js}
+ writeFileSync('monster.bin', buf, 'binary');
+~~~
+</div>
+<div class="language-typescript">
+For example, in Node you can simply do:
+~~~{.ts}
+ writeFileSync('monster.bin', buf, 'binary');
+~~~
+</div>
+
#### Reading Orc FlatBuffers
Now that we have successfully created an `Orc` FlatBuffer, the monster data can
@@ -2089,9 +2212,10 @@
~~~
</div>
<div class="language-typescript">
-~~~{.js}
- // note: import flabuffers with your desired import method
+~~~{.ts}
+ // note: import flatbuffers with your desired import method
+ // note: the `./monster_generated.ts` file was previously generated by `flatc` above using the `monster.fbs` schema
import { MyGame } from './monster_generated';
~~~
</div>
@@ -2169,10 +2293,10 @@
</div>
Then, assuming you have a buffer of bytes received from disk,
-network, etc., you can create start accessing the buffer like so:
+network, etc., you can start accessing the buffer like so:
**Again, make sure you read the bytes in BINARY mode, otherwise the code below
-won't work**
+won't work.**
<div class="language-cpp">
~~~{.cpp}
@@ -2242,7 +2366,11 @@
</div>
<div class="language-javascript">
~~~{.js}
- var bytes = /* the data you just read, in an object of type "Uint8Array" */
+ // the data you just read, as a `Uint8Array`
+ // Note that the example here uses `readFileSync` from the built-in `fs` module,
+ // but other methods for accessing the file contents will also work.
+ var bytes = new Uint8Array(readFileSync('./monsterdata.bin'));
+
var buf = new flatbuffers.ByteBuffer(bytes);
// Get an accessor to the root object inside the buffer.
@@ -2251,7 +2379,11 @@
</div>
<div class="language-typescript">
~~~{.ts}
- let bytes = /* the data you just read, in an object of type "Uint8Array" */
+ // the data you just read, as a `Uint8Array`.
+ // Note that the example here uses `readFileSync` from the built-in `fs` module,
+ // but other methods for accessing the file contents will also work.
+ let bytes = new Uint8Array(readFileSync('./monsterdata.bin'));
+
let buf = new flatbuffers.ByteBuffer(bytes);
// Get an accessor to the root object inside the buffer.
@@ -2311,6 +2443,15 @@
let monster = get_root_as_monster(buf);
~~~
</div>
+<div class="language-swift">
+~~~{.swift}
+ // create a ByteBuffer(:) from an [UInt8] or Data()
+ let buf = // Get your data
+
+ // Get an accessor to the root object inside the buffer.
+ let monster = Monster.getRootAsMonster(bb: ByteBuffer(bytes: buf))
+~~~
+</div>
If you look in the generated files from the schema compiler, you will see it generated
accessors for all non-`deprecated` fields. For example:
@@ -2361,16 +2502,16 @@
</div>
<div class="language-javascript">
~~~{.js}
- var hp = $monster.hp();
- var mana = $monster.mana();
- var name = $monster.name();
+ var hp = monster.hp();
+ var mana = monster.mana();
+ var name = monster.name();
~~~
</div>
<div class="language-typescript">
~~~{.ts}
- let hp = $monster.hp();
- let mana = $monster.mana();
- let name = $monster.name();
+ let hp = monster.hp();
+ let mana = monster.mana();
+ let name = monster.name();
~~~
</div>
<div class="language-php">
@@ -2418,6 +2559,13 @@
let name = monster.name();
~~~
</div>
+<div class="language-swift">
+~~~{.swift}
+ let hp = monster.hp
+ let mana = monster.mana
+ let name = monster.name // returns an optional string
+~~~
+</div>
These should hold `300`, `150`, and `"Orc"` respectively.
@@ -2543,6 +2691,14 @@
let z = pos.z();
~~~
</div>
+<div class="language-swift">
+~~~{.swift}
+ let pos = monster.pos
+ let x = pos.x
+ let y = pos.y
+ let z = pos.z
+~~~
+</div>
`x`, `y`, and `z` will contain `1.0`, `2.0`, and `3.0`, respectively.
@@ -2635,7 +2791,7 @@
</div>
<div class="language-rust">
~~~{.rs}
- // Get a test an element from the `inventory` FlatBuffer's `vector`.
+ // Get and test an element from the `inventory` FlatBuffer's `vector`.
let inv = monster.inventory().unwrap();
// Note that this vector is returned as a slice, because direct access for
@@ -2643,9 +2799,22 @@
let third_item = inv[2];
~~~
</div>
+<div class="language-swift">
+~~~{.swift}
+ // Get a the count of objects in the vector
+ let count = monster.inventoryCount
+
+ // get item at index 4
+ let object = monster.inventory(at: 4)
+
+ // or you can fetch the entire array
+ let inv = monster.inventory
+ // inv[4] should equal object
+~~~
+</div>
For `vector`s of `table`s, you can access the elements like any other vector,
-except your need to handle the result as a FlatBuffer `table`:
+except you need to handle the result as a FlatBuffer `table`:
<div class="language-cpp">
~~~{.cpp}
@@ -2756,6 +2925,16 @@
let second_weapon_damage = wep2.damage();
~~~
</div>
+<div class="language-swift">
+~~~{.swift}
+ // Get the count of weapon objects
+ let wepsCount = monster.weaponsCount
+
+ let weapon2 = monster.weapons(at: 1)
+ let weaponName = weapon2.name
+ let weaponDmg = weapon2.damage
+~~~
+</div>
Last, we can access our `Equipped` FlatBuffer `union`. Just like when we created
the `union`, we need to get both parts of the `union`: the type and the data.
@@ -2855,8 +3034,8 @@
var unionType = monster.equippedType();
if (unionType == MyGame.Sample.Equipment.Weapon) {
- var weapon_name = monster.equipped(new MyGame.Sample.Weapon()).name(); // 'Axe'
- var weapon_damage = monster.equipped(new MyGame.Sample.Weapon()).damage(); // 5
+ var weaponName = monster.equipped(new MyGame.Sample.Weapon()).name(); // 'Axe'
+ var weaponDamage = monster.equipped(new MyGame.Sample.Weapon()).damage(); // 5
}
~~~
</div>
@@ -2865,8 +3044,8 @@
let unionType = monster.equippedType();
if (unionType == MyGame.Sample.Equipment.Weapon) {
- let weapon_name = monster.equipped(new MyGame.Sample.Weapon()).name(); // 'Axe'
- let weapon_damage = monster.equipped(new MyGame.Sample.Weapon()).damage(); // 5
+ let weaponName = monster.equipped(new MyGame.Sample.Weapon()).name(); // 'Axe'
+ let weaponDamage = monster.equipped(new MyGame.Sample.Weapon()).damage(); // 5
}
~~~
</div>
@@ -2934,7 +3113,7 @@
~~~{.rs}
// Get and test the `Equipment` union (`equipped` field).
// `equipped_as_weapon` returns a FlatBuffer handle much like normal table
- // fields, but this will return `None` is the union is not actually of that
+ // fields, but this will return `None` if the union is not actually of that
// type.
if monster.equipped_type() == Equipment::Weapon {
let equipped = monster.equipped_as_weapon().unwrap();
@@ -2942,6 +3121,16 @@
let weapon_damage = equipped.damage();
~~~
</div>
+<div class="language-swift">
+~~~{.swift}
+ // Get and check if the monster has an equipped item
+ if monster.equippedType == .weapon {
+ let _weapon = monster.equipped(type: Weapon.self)
+ let name = _weapon.name // should return "Axe"
+ let dmg = _weapon.damage // should return 5
+ }
+~~~
+</div>
## Mutating FlatBuffers
@@ -3045,6 +3234,14 @@
<API for mutating FlatBuffers is not yet available in Rust.>
~~~
</div>
+<div class="language-swift">
+~~~{.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
+ monster.mutate(inventory: 6, at index: 0) // mutates a value in an Scalar array
+~~~
+</div>
We use the somewhat verbose term `mutate` instead of `set` to indicate that this
is a special use case, not to be confused with the default way of constructing
@@ -3055,7 +3252,7 @@
Note that any `mutate` functions on a table will return a boolean, which is
`false` if the field we're trying to set is not present in the buffer. Fields
-that are not present if they weren't set, or even if they happen to be equal to
+are not present if they weren't set, or even if they happen to be equal to
the default value. For example, in the creation code above, the `mana`
field is equal to `150`, which is the default value, so it was never stored in
the buffer. Trying to call the corresponding `mutate` method for `mana` on such
@@ -3081,34 +3278,34 @@
#### JSON to binary representation
-Lets say you have a JSON file that describes your monster. In this example,
+Let's say you have a JSON file that describes your monster. In this example,
we will use the file `flatbuffers/samples/monsterdata.json`.
Here are the contents of the file:
~~~{.json}
{
- pos: {
- x: 1.0,
- y: 2.0,
- z: 3.0
+ "pos": {
+ "x": 1.0,
+ "y": 2.0,
+ "z": 3.0
},
- hp: 300,
- name: "Orc",
- weapons: [
+ "hp": 300,
+ "name": "Orc",
+ "weapons": [
{
- name: "axe",
- damage: 100
+ "name": "axe",
+ "damage": 100
},
{
- name: "bow",
- damage: 90
+ "name": "bow",
+ "damage": 90
}
],
- equipped_type: "Weapon",
- equipped: {
- name: "bow",
- damage: 90
+ "equipped_type": "Weapon",
+ "equipped": {
+ "name": "bow",
+ "damage": 90
}
}
~~~
@@ -3117,7 +3314,7 @@
our `monster.fbs` schema to produce a FlatBuffer binary file.
~~~{.sh}
-./../flatc -b monster.fbs monsterdata.json
+./../flatc --binary monster.fbs monsterdata.json
~~~
The output of this will be a file `monsterdata.bin`, which will contain the
@@ -3164,7 +3361,7 @@
*Note: The resulting JSON file is not necessarily identical with the original JSON.
If the binary representation contains floating point numbers, floats and doubles
are rounded to 6 and 12 digits, respectively, in order to represent them as
-decimals in the JSON document. *
+decimals in the JSON document.*
## Advanced Features for Each Language
@@ -3177,13 +3374,13 @@
[Use in C++](@ref flatbuffers_guide_use_cpp)
</div>
<div class="language-java">
-[Use in Java/C#](@ref flatbuffers_guide_use_java_c-sharp)
+[Use in Java](@ref flatbuffers_guide_use_java)
</div>
<div class="language-kotlin">
[Use in Kotlin](@ref flatbuffers_guide_use_kotlin)
</div>
<div class="language-csharp">
-[Use in Java/C#](@ref flatbuffers_guide_use_java_c-sharp)
+[Use in C#](@ref flatbuffers_guide_use_c-sharp)
</div>
<div class="language-go">
[Use in Go](@ref flatbuffers_guide_use_go)
@@ -3215,5 +3412,7 @@
<div class="language-rust">
[Use in Rust](@ref flatbuffers_guide_use_rust)
</div>
-
+<div class="language-swift">
+[Use in Swift](@ref flatbuffers_guide_use_swift)
+</div>
<br>
diff --git a/docs/source/TypeScriptUsage.md b/docs/source/TypeScriptUsage.md
index 02aa239..0b9739e 100644
--- a/docs/source/TypeScriptUsage.md
+++ b/docs/source/TypeScriptUsage.md
@@ -60,6 +60,38 @@
let pos = monster.pos();
~~~
+## Object based API
+
+FlatBuffers is all about memory efficiency, which is why its base API is written
+around using as little as possible of it. This does make the API clumsier
+(requiring pre-order construction of all data, and making mutation harder).
+
+For times when efficiency is less important a more convenient object based API
+can be used (through `--gen-object-api`) that is able to unpack & pack a
+FlatBuffer into objects and standard 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}
+ // Autogenerated class from table Monster.
+ let monsterobj = new MonsterT();
+
+ // Deserialize from buffer into object.
+ Monster.getRootAsMonster(flatbuffer).unpackTo(monsterobj);
+ // or
+ let monsterobj = Monster.getRootAsMonster(flatbuffer).unpack();
+
+ // Update object directly like a regular TS class instance.
+ console.log(monsterobj.name);
+ monsterobj.name = "Bob";
+
+ // Serialize into new flatbuffer.
+ let fbb = new flatbuffers.Builder(1);
+ Monster.finishMonsterBuffer(fbb, monsterobj.pack(fbb));
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
## Text parsing FlatBuffers in TypeScript
There currently is no support for parsing text (Schema's and JSON) directly
diff --git a/docs/source/doxyfile b/docs/source/doxyfile
index 6ba3c10..3a5bd98 100644
--- a/docs/source/doxyfile
+++ b/docs/source/doxyfile
@@ -753,7 +753,9 @@
"CUsage.md" \
"DartUsage.md" \
"GoUsage.md" \
- "JavaCsharpUsage.md" \
+ "JavaUsage.md" \
+ "CsharpUsage.md" \
+ "SwiftUsage.md" \
"JavaScriptUsage.md" \
"TypeScriptUsage.md" \
"PHPUsage.md" \
@@ -778,7 +780,7 @@
"../../php/FlatbufferBuilder.php" \
"../../net/FlatBuffers/FlatBufferBuilder.cs" \
"../../include/flatbuffers/flatbuffers.h" \
- "../../go/builder.go"
+ "../../go/builder.go" \
"../../rust/flatbuffers/src/builder.rs"
# This tag can be used to specify the character encoding of the source files
diff --git a/docs/source/doxygen_layout.xml b/docs/source/doxygen_layout.xml
index a232507..e1a6b81 100644
--- a/docs/source/doxygen_layout.xml
+++ b/docs/source/doxygen_layout.xml
@@ -29,8 +29,10 @@
title="Use in C"/>
<tab type="user" url="@ref flatbuffers_guide_use_go"
title="Use in Go"/>
- <tab type="user" url="@ref flatbuffers_guide_use_java_c-sharp"
- title="Use in Java/C#"/>
+ <tab type="user" url="@ref flatbuffers_guide_use_java"
+ title="Use in Java"/>
+ <tab type="user" url="@ref flatbuffers_guide_use_c-sharp"
+ title="Use in C#"/>
<tab type="user" url="@ref flatbuffers_guide_use_javascript"
title="Use in JavaScript"/>
<tab type="user" url="@ref flatbuffers_guide_use_typescript"
@@ -47,8 +49,10 @@
title="Use in Lobster"/>
<tab type="user" url="@ref flatbuffers_guide_use_rust"
title="Use in Rust"/>
+ <tab type="user" url="@ref flatbuffers_guide_use_swift"
+ title="Use in Swift"/>
<tab type="user" url="@ref flexbuffers"
- title="Schema-less version"/>
+ title="FlexBuffers (Schema-less version)"/>
<tab type="usergroup" url="" title="gRPC">
<tab type="user" url="@ref flatbuffers_grpc_guide_use_cpp"
title="Use in C++"/>