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/dart/lib/flat_buffers.dart b/dart/lib/flat_buffers.dart
index e251260..3d4cf81 100644
--- a/dart/lib/flat_buffers.dart
+++ b/dart/lib/flat_buffers.dart
@@ -492,7 +492,7 @@
/// Write the given list of 64-bit float [values].
int writeListFloat64(List<double> values) {
_ensureNoVTable();
- _prepare(4, 1 + (2 * values.length));
+ _prepare(_sizeofFloat64, values.length, additionalBytes: _sizeofUint32);
final int result = _tail;
int tail = _tail;
_setUint32AtTail(_buf, tail, values.length);
@@ -522,7 +522,7 @@
/// Write the given list of signed 64-bit integer [values].
int writeListInt64(List<int> values) {
_ensureNoVTable();
- _prepare(_sizeofUint32, 2 * values.length);
+ _prepare(_sizeofInt64, values.length, additionalBytes: _sizeofUint32);
final int result = _tail;
int tail = _tail;
_setUint32AtTail(_buf, tail, values.length);
@@ -537,7 +537,7 @@
/// Write the given list of signed 64-bit integer [values].
int writeListUint64(List<int> values) {
_ensureNoVTable();
- _prepare(_sizeofUint32, 2 * values.length);
+ _prepare(_sizeofUint64, values.length, additionalBytes: _sizeofUint32);
final int result = _tail;
int tail = _tail;
_setUint32AtTail(_buf, tail, values.length);
diff --git a/dart/lib/flex_buffers.dart b/dart/lib/flex_buffers.dart
new file mode 100644
index 0000000..824afff
--- /dev/null
+++ b/dart/lib/flex_buffers.dart
@@ -0,0 +1,2 @@
+export 'src/builder.dart';
+export 'src/reference.dart';
diff --git a/dart/lib/src/builder.dart b/dart/lib/src/builder.dart
new file mode 100644
index 0000000..5ce46dc
--- /dev/null
+++ b/dart/lib/src/builder.dart
@@ -0,0 +1,666 @@
+import 'dart:convert';
+import 'dart:typed_data';
+
+import 'types.dart';
+
+/// The main builder class for creation of a FlexBuffer.
+class Builder {
+ ByteData _buffer;
+ List<_StackValue> _stack;
+ List<_StackPointer> _stackPointers;
+ int _offset;
+ bool _finished;
+ Map<String, _StackValue> _stringCache;
+ Map<String, _StackValue> _keyCache;
+ Map<_KeysHash, _StackValue> _keyVectorCache;
+ Map<int, _StackValue> _indirectIntCache;
+ Map<double, _StackValue> _indirectDoubleCache;
+
+ /// Instantiate the builder if you intent to gradually build up the buffer by calling
+ /// add... methods and calling [finish] to receive the the resulting byte array.
+ ///
+ /// The default size of internal buffer is set to 2048. Provide a different value in order to avoid buffer copies.
+ Builder({int size = 2048}) {
+ _buffer = ByteData(size);
+ _stack = [];
+ _stackPointers = [];
+ _offset = 0;
+ _finished = false;
+ _stringCache = {};
+ _keyCache = {};
+ _keyVectorCache = {};
+ _indirectIntCache = {};
+ _indirectDoubleCache = {};
+ }
+
+ /// Use this method in order to turn an object into a FlexBuffer directly.
+ ///
+ /// Use the manual instantiation of the [Builder] and gradual addition of values, if performance is more important than convenience.
+ static ByteBuffer buildFromObject(Object value) {
+ final builder = Builder();
+ builder._add(value);
+ final buffer = builder.finish();
+ final byteData = ByteData(buffer.lengthInBytes);
+ byteData.buffer.asUint8List().setAll(0, buffer);
+ return byteData.buffer;
+ }
+
+ void _add(Object value) {
+ if (value == null) {
+ addNull();
+ } else if (value is bool) {
+ addBool(value);
+ } else if (value is int) {
+ addInt(value);
+ } else if (value is double) {
+ addDouble(value);
+ } else if (value is ByteBuffer) {
+ addBlob(value);
+ } else if (value is String) {
+ addString(value);
+ } else if (value is List<dynamic>) {
+ startVector();
+ for (var i = 0; i < value.length; i++) {
+ _add(value[i]);
+ }
+ end();
+ } else if (value is Map<String, dynamic>) {
+ startMap();
+ value.forEach((key, value) {
+ addKey(key);
+ _add(value);
+ });
+ end();
+ } else {
+ throw UnsupportedError('Value of unexpected type: $value');
+ }
+ }
+
+ /// Use this method if you want to store a null value.
+ ///
+ /// Specifically useful when building up a vector where values can be null.
+ void addNull() {
+ _integrityCheckOnValueAddition();
+ _stack.add(_StackValue.WithNull());
+ }
+
+ /// Adds a string value.
+ void addInt(int value) {
+ _integrityCheckOnValueAddition();
+ _stack.add(_StackValue.WithInt(value));
+ }
+
+ /// Adds a bool value.
+ void addBool(bool value) {
+ _integrityCheckOnValueAddition();
+ _stack.add(_StackValue.WithBool(value));
+ }
+
+ /// Adds a double value.
+ void addDouble(double value) {
+ _integrityCheckOnValueAddition();
+ _stack.add(_StackValue.WithDouble(value));
+ }
+
+ /// Adds a string value.
+ void addString(String value) {
+ _integrityCheckOnValueAddition();
+ if (_stringCache.containsKey(value)) {
+ _stack.add(_stringCache[value]);
+ return;
+ }
+ final utf8String = utf8.encode(value);
+ final length = utf8String.length;
+ final bitWidth = BitWidthUtil.uwidth(length);
+ final byteWidth = _align(bitWidth);
+ _writeUInt(length, byteWidth);
+ final stringOffset = _offset;
+ final newOffset = _newOffset(length + 1);
+ _pushBuffer(utf8String);
+ _offset = newOffset;
+ final stackValue = _StackValue.WithOffset(stringOffset, ValueType.String, bitWidth);
+ _stack.add(stackValue);
+ _stringCache[value] = stackValue;
+ }
+
+ /// This methods adds a key to a map and should be followed by an add... value call.
+ ///
+ /// It also implies that you call this method only after you called [startMap].
+ void addKey(String value) {
+ _integrityCheckOnKeyAddition();
+ if (_keyCache.containsKey(value)) {
+ _stack.add(_keyCache[value]);
+ return;
+ }
+ final utf8String = utf8.encode(value);
+ final length = utf8String.length;
+ final keyOffset = _offset;
+ final newOffset = _newOffset(length + 1);
+ _pushBuffer(utf8String);
+ _offset = newOffset;
+ final stackValue = _StackValue.WithOffset(keyOffset, ValueType.Key, BitWidth.width8);
+ _stack.add(stackValue);
+ _keyCache[value] = stackValue;
+ }
+
+ /// Adds a byte array.
+ ///
+ /// This method can be used to store any generic BLOB.
+ void addBlob(ByteBuffer value) {
+ _integrityCheckOnValueAddition();
+ final length = value.lengthInBytes;
+ final bitWidth = BitWidthUtil.uwidth(length);
+ final byteWidth = _align(bitWidth);
+ _writeUInt(length, byteWidth);
+ final blobOffset = _offset;
+ final newOffset = _newOffset(length);
+ _pushBuffer(value.asUint8List());
+ _offset = newOffset;
+ final stackValue = _StackValue.WithOffset(blobOffset, ValueType.Blob, bitWidth);
+ _stack.add(stackValue);
+ }
+
+ /// Stores int value indirectly in the buffer.
+ ///
+ /// Adding large integer values indirectly might be beneficial if those values suppose to be store in a vector together with small integer values.
+ /// This is due to the fact that FlexBuffers will add padding to small integer values, if they are stored together with large integer values.
+ /// When we add integer indirectly the vector of ints will contain not the value itself, but only the relative offset to the value.
+ /// By setting the [cache] parameter to true, you make sure that the builder tracks added int value and performs deduplication.
+ void addIntIndirectly(int value, {bool cache = false}) {
+ _integrityCheckOnValueAddition();
+ if (_indirectIntCache.containsKey(value)) {
+ _stack.add(_indirectIntCache[value]);
+ return;
+ }
+ final stackValue = _StackValue.WithInt(value);
+ final byteWidth = _align(stackValue.width);
+ final newOffset = _newOffset(byteWidth);
+ final valueOffset = _offset;
+ _pushBuffer(stackValue.asU8List(stackValue.width));
+ final stackOffset = _StackValue.WithOffset(valueOffset, ValueType.IndirectInt, stackValue.width);
+ _stack.add(stackOffset);
+ _offset = newOffset;
+ if (cache) {
+ _indirectIntCache[value] = stackOffset;
+ }
+ }
+
+ /// Stores double value indirectly in the buffer.
+ ///
+ /// Double are stored as 8 or 4 byte values in FlexBuffers. If they are stored in a mixed vector, values which are smaller than 4 / 8 bytes will be padded.
+ /// When we add double indirectly, the vector will contain not the value itself, but only the relative offset to the value. Which could occupy only 1 or 2 bytes, reducing the odds for unnecessary padding.
+ /// By setting the [cache] parameter to true, you make sure that the builder tracks already added double value and performs deduplication.
+ void addDoubleIndirectly(double value, {bool cache = false}) {
+ _integrityCheckOnValueAddition();
+ if (cache && _indirectDoubleCache.containsKey(value)) {
+ _stack.add(_indirectDoubleCache[value]);
+ return;
+ }
+ final stackValue = _StackValue.WithDouble(value);
+ final byteWidth = _align(stackValue.width);
+ final newOffset = _newOffset(byteWidth);
+ final valueOffset = _offset;
+ _pushBuffer(stackValue.asU8List(stackValue.width));
+ final stackOffset = _StackValue.WithOffset(valueOffset, ValueType.IndirectFloat, stackValue.width);
+ _stack.add(stackOffset);
+ _offset = newOffset;
+ if (cache) {
+ _indirectDoubleCache[value] = stackOffset;
+ }
+ }
+
+ /// This method starts a vector definition and needs to be followed by 0 to n add... value calls.
+ ///
+ /// The vector definition needs to be finished with an [end] call.
+ /// It is also possible to add nested vector or map by calling [startVector] / [startMap].
+ void startVector() {
+ _integrityCheckOnValueAddition();
+ _stackPointers.add(_StackPointer(_stack.length, true));
+ }
+
+ /// This method starts a map definition.
+ ///
+ /// This method call needs to be followed by 0 to n [addKey] + add... value calls.
+ /// The map definition needs to be finished with an [end] call.
+ /// It is also possible to add nested vector or map by calling [startVector] / [startMap] after calling [addKey].
+ void startMap() {
+ _integrityCheckOnValueAddition();
+ _stackPointers.add(_StackPointer(_stack.length, false));
+ }
+
+ /// Marks that the addition of values to the last vector, or map have ended.
+ void end() {
+ final pointer = _stackPointers.removeLast();
+ if (pointer.isVector) {
+ _endVector(pointer);
+ } else {
+ _sortKeysAndEndMap(pointer);
+ }
+ }
+
+ /// Finish building the FlatBuffer and return array of bytes.
+ ///
+ /// Can be called multiple times, to get the array of bytes.
+ /// After the first call, adding values, or starting vectors / maps will result in an exception.
+ Uint8List finish() {
+ if (_finished == false) {
+ _finish();
+ }
+ return _buffer.buffer.asUint8List(0, _offset);
+ }
+
+ /// Builds a FlatBuffer with current state without finishing the builder.
+ ///
+ /// Creates an internal temporary copy of current builder and finishes the copy.
+ /// Use this method, when the state of a long lasting builder need to be persisted periodically.
+ ByteBuffer snapshot() {
+ final tmp = Builder(size: _offset + 200);
+ tmp._offset = _offset;
+ tmp._stack = List.from(_stack);
+ tmp._stackPointers = List.from(_stackPointers);
+ tmp._buffer.buffer.asUint8List().setAll(0, _buffer.buffer.asUint8List(0, _offset));
+ for (var i = 0; i < tmp._stackPointers.length; i++){
+ tmp.end();
+ }
+ final buffer = tmp.finish();
+ final bd = ByteData(buffer.lengthInBytes);
+ bd.buffer.asUint8List().setAll(0, buffer);
+ return bd.buffer;
+ }
+
+ void _integrityCheckOnValueAddition() {
+ if (_finished) {
+ throw StateError('Adding values after finish is prohibited');
+ }
+ if (_stackPointers.isNotEmpty && _stackPointers.last.isVector == false) {
+ if (_stack.last.type != ValueType.Key) {
+ throw StateError('Adding value to a map before adding a key is prohibited');
+ }
+ }
+ }
+
+ void _integrityCheckOnKeyAddition() {
+ if (_finished) {
+ throw StateError('Adding values after finish is prohibited');
+ }
+ if (_stackPointers.isEmpty || _stackPointers.last.isVector) {
+ throw StateError('Adding key before staring a map is prohibited');
+ }
+ }
+
+ void _finish() {
+ if (_stack.length != 1) {
+ throw StateError('Stack has to be exactly 1, but is ${_stack.length}. You have to end all started vectors and maps, before calling [finish]');
+ }
+ final value = _stack[0];
+ final byteWidth = _align(value.elementWidth(_offset, 0));
+ _writeStackValue(value, byteWidth);
+ _writeUInt(value.storedPackedType(), 1);
+ _writeUInt(byteWidth, 1);
+ _finished = true;
+ }
+
+ _StackValue _createVector(int start, int vecLength, int step, [_StackValue keys]) {
+ var bitWidth = BitWidthUtil.uwidth(vecLength);
+ var prefixElements = 1;
+ if (keys != null) {
+ var elemWidth = keys.elementWidth(_offset, 0);
+ if (elemWidth.index > bitWidth.index) {
+ bitWidth = elemWidth;
+ }
+ prefixElements += 2;
+ }
+ var vectorType = ValueType.Key;
+ var typed = keys == null;
+ for (var i = start; i < _stack.length; i += step) {
+ final elemWidth = _stack[i].elementWidth(_offset, i + prefixElements);
+ if (elemWidth.index > bitWidth.index) {
+ bitWidth = elemWidth;
+ }
+ if (i == start) {
+ vectorType = _stack[i].type;
+ typed &= ValueTypeUtils.isTypedVectorElement(vectorType);
+ } else {
+ if (vectorType != _stack[i].type) {
+ typed = false;
+ }
+ }
+ }
+ final byteWidth = _align(bitWidth);
+ final fix = typed & ValueTypeUtils.isNumber(vectorType) && vecLength >= 2 && vecLength <= 4;
+ if (keys != null) {
+ _writeStackValue(keys, byteWidth);
+ _writeUInt(1 << keys.width.index, byteWidth);
+ }
+ if (fix == false) {
+ _writeUInt(vecLength, byteWidth);
+ }
+ final vecOffset = _offset;
+ for (var i = start; i < _stack.length; i += step) {
+ _writeStackValue(_stack[i], byteWidth);
+ }
+ if (typed == false) {
+ for (var i = start; i < _stack.length; i += step) {
+ _writeUInt(_stack[i].storedPackedType(), 1);
+ }
+ }
+ if (keys != null) {
+ return _StackValue.WithOffset(vecOffset, ValueType.Map, bitWidth);
+ }
+ if (typed) {
+ final vType = ValueTypeUtils.toTypedVector(vectorType, fix ? vecLength : 0);
+ return _StackValue.WithOffset(vecOffset, vType, bitWidth);
+ }
+ return _StackValue.WithOffset(vecOffset, ValueType.Vector, bitWidth);
+ }
+
+ void _endVector(_StackPointer pointer) {
+ final vecLength = _stack.length - pointer.stackPosition;
+ final vec = _createVector(pointer.stackPosition, vecLength, 1);
+ _stack.removeRange(pointer.stackPosition, _stack.length);
+ _stack.add(vec);
+ }
+
+ void _sortKeysAndEndMap(_StackPointer pointer) {
+ if (((_stack.length - pointer.stackPosition) & 1) == 1) {
+ throw StateError('The stack needs to hold key value pairs (even number of elements). Check if you combined [addKey] with add... method calls properly.');
+ }
+
+ var sorted = true;
+ for (var i = pointer.stackPosition; i < _stack.length - 2; i += 2) {
+ if (_shouldFlip(_stack[i], _stack[i+2])) {
+ sorted = false;
+ break;
+ }
+ }
+
+ if (sorted == false) {
+ for (var i = pointer.stackPosition; i < _stack.length; i += 2) {
+ var flipIndex = i;
+ for (var j = i + 2; j < _stack.length; j += 2) {
+ if (_shouldFlip(_stack[flipIndex], _stack[j])) {
+ flipIndex = j;
+ }
+ }
+ if (flipIndex != i) {
+ var k = _stack[flipIndex];
+ var v = _stack[flipIndex + 1];
+ _stack[flipIndex] = _stack[i];
+ _stack[flipIndex + 1] = _stack[i + 1];
+ _stack[i] = k;
+ _stack[i + 1] = v;
+ }
+ }
+ }
+ _endMap(pointer);
+ }
+
+ void _endMap(_StackPointer pointer) {
+ final vecLength = (_stack.length - pointer.stackPosition) >> 1;
+ final offsets = <int>[];
+ for (var i = pointer.stackPosition; i < _stack.length; i += 2) {
+ offsets.add(_stack[i].offset);
+ }
+ final keysHash = _KeysHash(offsets);
+ var keysStackValue;
+ if (_keyVectorCache.containsKey(keysHash)) {
+ keysStackValue = _keyVectorCache[keysHash];
+ } else {
+ keysStackValue = _createVector(pointer.stackPosition, vecLength, 2);
+ _keyVectorCache[keysHash] = keysStackValue;
+ }
+ final vec = _createVector(pointer.stackPosition + 1, vecLength, 2, keysStackValue);
+ _stack.removeRange(pointer.stackPosition, _stack.length);
+ _stack.add(vec);
+ }
+
+ bool _shouldFlip(_StackValue v1, _StackValue v2) {
+ if (v1.type != ValueType.Key || v2.type != ValueType.Key) {
+ throw StateError('Stack values are not keys $v1 | $v2. Check if you combined [addKey] with add... method calls properly.');
+ }
+
+ var c1, c2;
+ var index = 0;
+ do {
+ c1 = _buffer.getUint8(v1.offset + index);
+ c2 = _buffer.getUint8(v2.offset + index);
+ if (c2 < c1) return true;
+ if (c1 < c2) return false;
+ index += 1;
+ } while (c1 != 0 && c2 != 0);
+ return false;
+ }
+
+ int _align(BitWidth width) {
+ final byteWidth = BitWidthUtil.toByteWidth(width);
+ _offset += BitWidthUtil.paddingSize(_offset, byteWidth);
+ return byteWidth;
+ }
+
+ void _writeStackValue(_StackValue value, int byteWidth) {
+ final newOffset = _newOffset(byteWidth);
+ if (value.isOffset) {
+ final relativeOffset = _offset - value.offset;
+ if (byteWidth == 8 || relativeOffset < (1 << (byteWidth * 8))) {
+ _writeUInt(relativeOffset, byteWidth);
+ } else {
+ throw StateError('Unexpected size $byteWidth. This might be a bug. Please create an issue https://github.com/google/flatbuffers/issues/new');
+ }
+ } else {
+ _pushBuffer(value.asU8List(BitWidthUtil.fromByteWidth(byteWidth)));
+ }
+ _offset = newOffset;
+ }
+
+ void _writeUInt(int value, int byteWidth) {
+ final newOffset = _newOffset(byteWidth);
+ _pushUInt(value, BitWidthUtil.fromByteWidth(byteWidth));
+ _offset = newOffset;
+ }
+
+ int _newOffset(int newValueSize) {
+ final newOffset = _offset + newValueSize;
+ var size = _buffer.lengthInBytes;
+ final prevSize = size;
+ while (size < newOffset) {
+ size <<= 1;
+ }
+ if (prevSize < size) {
+ final newBuf = ByteData(size);
+ newBuf.buffer
+ .asUint8List()
+ .setAll(0, _buffer.buffer.asUint8List());
+ }
+ return newOffset;
+ }
+
+ void _pushInt(int value, BitWidth width) {
+ switch (width) {
+
+ case BitWidth.width8:
+ _buffer.setInt8(_offset, value);
+ break;
+ case BitWidth.width16:
+ _buffer.setInt16(_offset, value, Endian.little);
+ break;
+ case BitWidth.width32:
+ _buffer.setInt32(_offset, value, Endian.little);
+ break;
+ case BitWidth.width64:
+ _buffer.setInt64(_offset, value, Endian.little);
+ break;
+ }
+ }
+
+ void _pushUInt(int value, BitWidth width) {
+ switch (width) {
+
+ case BitWidth.width8:
+ _buffer.setUint8(_offset, value);
+ break;
+ case BitWidth.width16:
+ _buffer.setUint16(_offset, value, Endian.little);
+ break;
+ case BitWidth.width32:
+ _buffer.setUint32(_offset, value, Endian.little);
+ break;
+ case BitWidth.width64:
+ _buffer.setUint64(_offset, value, Endian.little);
+ break;
+ }
+ }
+
+ void _pushBuffer(List<int> value) {
+ _buffer.buffer.asUint8List().setAll(_offset, value);
+ }
+}
+
+class _StackValue {
+ Object _value;
+ int _offset;
+ ValueType _type;
+ BitWidth _width;
+ _StackValue.WithNull() {
+ _type = ValueType.Null;
+ _width = BitWidth.width8;
+ }
+ _StackValue.WithInt(int value) {
+ _type = value != null ? ValueType.Int : ValueType.Null;
+ _width = BitWidthUtil.width(value);
+ _value = value;
+ }
+ _StackValue.WithBool(bool value) {
+ _type = value != null ? ValueType.Bool : ValueType.Null;
+ _width = BitWidth.width8;
+ _value = value;
+ }
+ _StackValue.WithDouble(double value) {
+ _type = value != null ? ValueType.Float : ValueType.Null;
+ _width = BitWidthUtil.width(value);
+ _value = value;
+ }
+ _StackValue.WithOffset(int value, ValueType type, BitWidth width) {
+ _offset = value;
+ _type = type;
+ _width = width;
+ }
+
+ BitWidth storedWidth({BitWidth width = BitWidth.width8}) {
+ return ValueTypeUtils.isInline(_type) ? BitWidthUtil.max(_width, width) : _width;
+ }
+
+ int storedPackedType({BitWidth width = BitWidth.width8}) {
+ return ValueTypeUtils.packedType(_type, storedWidth(width: width));
+ }
+
+ BitWidth elementWidth(int size, int index) {
+ if (ValueTypeUtils.isInline(_type)) return _width;
+ for(var i = 0; i < 4; i++) {
+ final width = 1 << i;
+ final offsetLoc = size + BitWidthUtil.paddingSize(size, width) + index * width;
+ final offset = offsetLoc - _offset;
+ final bitWidth = BitWidthUtil.uwidth(offset);
+ if (1 << bitWidth.index == width) {
+ return bitWidth;
+ }
+ }
+ throw StateError('Element is of unknown. Size: $size at index: $index. This might be a bug. Please create an issue https://github.com/google/flatbuffers/issues/new');
+ }
+
+ List<int> asU8List(BitWidth width) {
+ if (ValueTypeUtils.isNumber(_type)) {
+ if (_type == ValueType.Float) {
+ if (width == BitWidth.width32) {
+ final result = ByteData(4);
+ result.setFloat32(0, _value, Endian.little);
+ return result.buffer.asUint8List();
+ } else {
+ final result = ByteData(8);
+ result.setFloat64(0, _value, Endian.little);
+ return result.buffer.asUint8List();
+ }
+ } else {
+ switch(width) {
+ case BitWidth.width8:
+ final result = ByteData(1);
+ result.setInt8(0, _value);
+ return result.buffer.asUint8List();
+ case BitWidth.width16:
+ final result = ByteData(2);
+ result.setInt16(0, _value, Endian.little);
+ return result.buffer.asUint8List();
+ case BitWidth.width32:
+ final result = ByteData(4);
+ result.setInt32(0, _value, Endian.little);
+ return result.buffer.asUint8List();
+ case BitWidth.width64:
+ final result = ByteData(8);
+ result.setInt64(0, _value, Endian.little);
+ return result.buffer.asUint8List();
+ }
+ }
+ }
+ if (_type == ValueType.Null) {
+ final result = ByteData(1);
+ result.setInt8(0, 0);
+ return result.buffer.asUint8List();
+ }
+ if (_type == ValueType.Bool) {
+ final result = ByteData(1);
+ result.setInt8(0, _value ? 1 : 0);
+ return result.buffer.asUint8List();
+ }
+
+ throw StateError('Unexpected type: $_type. This might be a bug. Please create an issue https://github.com/google/flatbuffers/issues/new');
+ }
+
+ ValueType get type {
+ return _type;
+ }
+
+ BitWidth get width {
+ return _width;
+ }
+
+ bool get isOffset {
+ return !ValueTypeUtils.isInline(_type);
+ }
+ int get offset => _offset;
+
+ bool get isFloat32 {
+ return _type == ValueType.Float && _width == BitWidth.width32;
+ }
+}
+
+class _StackPointer {
+ int stackPosition;
+ bool isVector;
+ _StackPointer(this.stackPosition, this.isVector);
+}
+
+class _KeysHash {
+ final List<int> keys;
+
+ const _KeysHash(this.keys);
+
+ @override
+ bool operator ==(Object other) {
+ if (other is _KeysHash) {
+ if (keys.length != other.keys.length) return false;
+ for (var i = 0; i < keys.length; i++) {
+ if (keys[i] != other.keys[i]) return false;
+ }
+ return true;
+ }
+ return false;
+ }
+
+ @override
+ int get hashCode {
+ var result = 17;
+ for (var i = 0; i < keys.length; i++) {
+ result = result * 23 + keys[i];
+ }
+ return result;
+ }
+}
diff --git a/dart/lib/src/reference.dart b/dart/lib/src/reference.dart
new file mode 100644
index 0000000..3954f06
--- /dev/null
+++ b/dart/lib/src/reference.dart
@@ -0,0 +1,446 @@
+import 'dart:collection';
+import 'dart:convert';
+import 'dart:typed_data';
+import 'types.dart';
+
+/// Main class to read a value out of a FlexBuffer.
+///
+/// This class let you access values stored in the buffer in a lazy fashion.
+class Reference {
+ final ByteData _buffer;
+ final int _offset;
+ final BitWidth _parentWidth;
+ final String _path;
+ int _byteWidth;
+ ValueType _valueType;
+ int _length;
+
+ Reference._(this._buffer, this._offset, this._parentWidth, int packedType, this._path) {
+ _byteWidth = 1 << (packedType & 3);
+ _valueType = ValueTypeUtils.fromInt(packedType >> 2);
+ }
+
+ /// Use this method to access the root value of a FlexBuffer.
+ static Reference fromBuffer(ByteBuffer buffer) {
+ final len = buffer.lengthInBytes;
+ if (len < 3) {
+ throw UnsupportedError('Buffer needs to be bigger than 3');
+ }
+ final byteData = ByteData.view(buffer);
+ final byteWidth = byteData.getUint8(len - 1);
+ final packedType = byteData.getUint8(len - 2);
+ final offset = len - byteWidth - 2;
+ return Reference._(ByteData.view(buffer), offset, BitWidthUtil.fromByteWidth(byteWidth), packedType, "/");
+ }
+
+ /// Returns true if the underlying value is null.
+ bool get isNull => _valueType == ValueType.Null;
+ /// Returns true if the underlying value can be represented as [num].
+ bool get isNum => ValueTypeUtils.isNumber(_valueType) || ValueTypeUtils.isIndirectNumber(_valueType);
+ /// Returns true if the underlying value was encoded as a float (direct or indirect).
+ bool get isDouble => _valueType == ValueType.Float || _valueType == ValueType.IndirectFloat;
+ /// Returns true if the underlying value was encoded as an int or uint (direct or indirect).
+ bool get isInt => isNum && !isDouble;
+ /// Returns true if the underlying value was encoded as a string or a key.
+ bool get isString => _valueType == ValueType.String || _valueType == ValueType.Key;
+ /// Returns true if the underlying value was encoded as a bool.
+ bool get isBool => _valueType == ValueType.Bool;
+ /// Returns true if the underlying value was encoded as a blob.
+ bool get isBlob => _valueType == ValueType.Blob;
+ /// Returns true if the underlying value points to a vector.
+ bool get isVector => ValueTypeUtils.isAVector(_valueType);
+ /// Returns true if the underlying value points to a map.
+ bool get isMap => _valueType == ValueType.Map;
+
+ /// If this [isBool], returns the bool value. Otherwise, returns null.
+ bool get boolValue {
+ if(_valueType == ValueType.Bool) {
+ return _readInt(_offset, _parentWidth) != 0;
+ }
+ return null;
+ }
+
+ /// Returns an [int], if the underlying value can be represented as an int.
+ ///
+ /// Otherwise returns [null].
+ int get intValue {
+ if (_valueType == ValueType.Int) {
+ return _readInt(_offset, _parentWidth);
+ }
+ if (_valueType == ValueType.UInt) {
+ return _readUInt(_offset, _parentWidth);
+ }
+ if (_valueType == ValueType.IndirectInt) {
+ return _readInt(_indirect, BitWidthUtil.fromByteWidth(_byteWidth));
+ }
+ if (_valueType == ValueType.IndirectUInt) {
+ return _readUInt(_indirect, BitWidthUtil.fromByteWidth(_byteWidth));
+ }
+ return null;
+ }
+
+ /// Returns [double], if the underlying value [isDouble].
+ ///
+ /// Otherwise returns [null].
+ double get doubleValue {
+ if (_valueType == ValueType.Float) {
+ return _readFloat(_offset, _parentWidth);
+ }
+ if (_valueType == ValueType.IndirectFloat) {
+ return _readFloat(_indirect, BitWidthUtil.fromByteWidth(_byteWidth));
+ }
+ return null;
+ }
+
+ /// Returns [num], if the underlying value is numeric, be it int uint, or float (direct or indirect).
+ ///
+ /// Otherwise returns [null].
+ num get numValue => doubleValue ?? intValue;
+
+ /// Returns [String] value or null otherwise.
+ ///
+ /// This method performers a utf8 decoding, as FlexBuffers format stores strings in utf8 encoding.
+ String get stringValue {
+ if (_valueType == ValueType.String || _valueType == ValueType.Key) {
+ return utf8.decode(_buffer.buffer.asUint8List(_indirect, length));
+ }
+ return null;
+ }
+
+ /// Returns [Uint8List] value or null otherwise.
+ Uint8List get blobValue {
+ if (_valueType == ValueType.Blob) {
+ return _buffer.buffer.asUint8List(_indirect, length);
+ }
+ return null;
+ }
+
+ /// Can be used with an [int] or a [String] value for key.
+ /// If the underlying value in FlexBuffer is a vector, then use [int] for access.
+ /// If the underlying value in FlexBuffer is a map, then use [String] for access.
+ /// Returns [Reference] value. Throws an exception when [key] is not applicable.
+ Reference operator [](Object key) {
+ if (key is int && ValueTypeUtils.isAVector(_valueType)) {
+ final index = key;
+ if(index >= length || index < 0) {
+ throw ArgumentError('Key: [$key] is not applicable on: $_path of: $_valueType length: $length');
+ }
+ final elementOffset = _indirect + index * _byteWidth;
+ final reference = Reference._(_buffer, elementOffset, BitWidthUtil.fromByteWidth(_byteWidth), 0, "$_path[$index]");
+ reference._byteWidth = 1;
+ if (ValueTypeUtils.isTypedVector(_valueType)) {
+ reference._valueType = ValueTypeUtils.typedVectorElementType(_valueType);
+ return reference;
+ }
+ if(ValueTypeUtils.isFixedTypedVector(_valueType)) {
+ reference._valueType = ValueTypeUtils.fixedTypedVectorElementType(_valueType);
+ return reference;
+ }
+ final packedType = _buffer.getUint8(_indirect + length * _byteWidth + index);
+ return Reference._(_buffer, elementOffset, BitWidthUtil.fromByteWidth(_byteWidth), packedType, "$_path[$index]");
+ }
+ if (key is String && _valueType == ValueType.Map) {
+ final index = _keyIndex(key);
+ if (index != null) {
+ return _valueForIndexWithKey(index, key);
+ }
+ }
+ throw ArgumentError('Key: [$key] is not applicable on: $_path of: $_valueType');
+ }
+
+ /// Get an iterable if the underlying flexBuffer value is a vector.
+ /// Otherwise throws an exception.
+ Iterable<Reference> get vectorIterable {
+ if(isVector == false) {
+ throw UnsupportedError('Value is not a vector. It is: $_valueType');
+ }
+ return _VectorIterator(this);
+ }
+
+ /// Get an iterable for keys if the underlying flexBuffer value is a map.
+ /// Otherwise throws an exception.
+ Iterable<String> get mapKeyIterable {
+ if(isMap == false) {
+ throw UnsupportedError('Value is not a map. It is: $_valueType');
+ }
+ return _MapKeyIterator(this);
+ }
+
+ /// Get an iterable for values if the underlying flexBuffer value is a map.
+ /// Otherwise throws an exception.
+ Iterable<Reference> get mapValueIterable {
+ if(isMap == false) {
+ throw UnsupportedError('Value is not a map. It is: $_valueType');
+ }
+ return _MapValueIterator(this);
+ }
+
+ /// Returns the length of the the underlying FlexBuffer value.
+ /// If the underlying value is [null] the length is 0.
+ /// If the underlying value is a number, or a bool, the length is 1.
+ /// If the underlying value is a vector, or map, the length reflects number of elements / element pairs.
+ /// If the values is a string or a blob, the length reflects a number of bytes the value occupies (strings are encoded in utf8 format).
+ int get length {
+ if (_length != null) {
+ return _length;
+ }
+ // needs to be checked before more generic isAVector
+ if(ValueTypeUtils.isFixedTypedVector(_valueType)) {
+ _length = ValueTypeUtils.fixedTypedVectorElementSize(_valueType);
+ } else if(_valueType == ValueType.Blob || ValueTypeUtils.isAVector(_valueType) || _valueType == ValueType.Map){
+ _length = _readUInt(_indirect - _byteWidth, BitWidthUtil.fromByteWidth(_byteWidth));
+ } else if (_valueType == ValueType.Null) {
+ _length = 0;
+ } else if (_valueType == ValueType.String) {
+ final indirect = _indirect;
+ var size_byte_width = _byteWidth;
+ var size = _readUInt(indirect - size_byte_width, BitWidthUtil.fromByteWidth(size_byte_width));
+ while (_buffer.getInt8(indirect + size) != 0) {
+ size_byte_width <<= 1;
+ size = _readUInt(indirect - size_byte_width, BitWidthUtil.fromByteWidth(size_byte_width));
+ }
+ _length = size;
+ } else if (_valueType == ValueType.Key) {
+ final indirect = _indirect;
+ var size = 1;
+ while (_buffer.getInt8(indirect + size) != 0) {
+ size += 1;
+ }
+ _length = size;
+ } else {
+ _length = 1;
+ }
+ return _length;
+ }
+
+
+ /// Returns a minified JSON representation of the underlying FlexBuffer value.
+ ///
+ /// This method involves materializing the entire object tree, which may be
+ /// expensive. It is more efficient to work with [Reference] and access only the needed data.
+ /// Blob values are represented as base64 encoded string.
+ String get json {
+ if(_valueType == ValueType.Bool) {
+ return boolValue ? 'true' : 'false';
+ }
+ if (_valueType == ValueType.Null) {
+ return 'null';
+ }
+ if(ValueTypeUtils.isNumber(_valueType)) {
+ return jsonEncode(numValue);
+ }
+ if (_valueType == ValueType.String) {
+ return jsonEncode(stringValue);
+ }
+ if (_valueType == ValueType.Blob) {
+ return jsonEncode(base64Encode(blobValue));
+ }
+ if (ValueTypeUtils.isAVector(_valueType)) {
+ final result = StringBuffer();
+ result.write('[');
+ for (var i = 0; i < length; i++) {
+ result.write(this[i].json);
+ if (i < length - 1) {
+ result.write(',');
+ }
+ }
+ result.write(']');
+ return result.toString();
+ }
+ if (_valueType == ValueType.Map) {
+ final result = StringBuffer();
+ result.write('{');
+ for (var i = 0; i < length; i++) {
+ result.write(jsonEncode(_keyForIndex(i)));
+ result.write(':');
+ result.write(_valueForIndex(i).json);
+ if (i < length - 1) {
+ result.write(',');
+ }
+ }
+ result.write('}');
+ return result.toString();
+ }
+ throw UnsupportedError('Type: $_valueType is not supported for JSON conversion');
+ }
+
+ /// Computes the indirect offset of the value.
+ ///
+ /// To optimize for the more common case of being called only once, this
+ /// value is not cached. Callers that need to use it more than once should
+ /// cache the return value in a local variable.
+ int get _indirect {
+ final step = _readUInt(_offset, _parentWidth);
+ return _offset - step;
+ }
+
+ int _readInt(int offset, BitWidth width) {
+ _validateOffset(offset, width);
+ if (width == BitWidth.width8) {
+ return _buffer.getInt8(offset);
+ }
+ if (width == BitWidth.width16) {
+ return _buffer.getInt16(offset, Endian.little);
+ }
+ if (width == BitWidth.width32) {
+ return _buffer.getInt32(offset, Endian.little);
+ }
+ return _buffer.getInt64(offset, Endian.little);
+ }
+
+ int _readUInt(int offset, BitWidth width) {
+ _validateOffset(offset, width);
+ if (width == BitWidth.width8) {
+ return _buffer.getUint8(offset);
+ }
+ if (width == BitWidth.width16) {
+ return _buffer.getUint16(offset, Endian.little);
+ }
+ if (width == BitWidth.width32) {
+ return _buffer.getUint32(offset, Endian.little);
+ }
+ return _buffer.getUint64(offset, Endian.little);
+ }
+
+ double _readFloat(int offset, BitWidth width) {
+ _validateOffset(offset, width);
+ if (width.index < BitWidth.width32.index) {
+ throw StateError('Bad width: $width');
+ }
+
+ if (width == BitWidth.width32) {
+ return _buffer.getFloat32(offset, Endian.little);
+ }
+
+ return _buffer.getFloat64(offset, Endian.little);
+ }
+
+ void _validateOffset(int offset, BitWidth width) {
+ if (_offset < 0 || _buffer.lengthInBytes <= offset + width.index || offset & (BitWidthUtil.toByteWidth(width) - 1) != 0) {
+ throw StateError('Bad offset: $offset, width: $width');
+ }
+ }
+
+ int _keyIndex(String key) {
+ final input = utf8.encode(key);
+ final keysVectorOffset = _indirect - _byteWidth * 3;
+ final indirectOffset = keysVectorOffset - _readUInt(keysVectorOffset, BitWidthUtil.fromByteWidth(_byteWidth));
+ final byteWidth = _readUInt(keysVectorOffset + _byteWidth, BitWidthUtil.fromByteWidth(_byteWidth));
+ var low = 0;
+ var high = length - 1;
+ while (low <= high) {
+ final mid = (high + low) >> 1;
+ final dif = _diffKeys(input, mid, indirectOffset, byteWidth);
+ if (dif == 0) return mid;
+ if (dif < 0) {
+ high = mid - 1;
+ } else {
+ low = mid + 1;
+ }
+ }
+ return null;
+ }
+
+ int _diffKeys(List<int> input, int index, int indirect_offset, int byteWidth) {
+ final keyOffset = indirect_offset + index * byteWidth;
+ final keyIndirectOffset = keyOffset - _readUInt(keyOffset, BitWidthUtil.fromByteWidth(byteWidth));
+ for (var i = 0; i < input.length; i++) {
+ final dif = input[i] - _buffer.getUint8(keyIndirectOffset + i);
+ if (dif != 0) {
+ return dif;
+ }
+ }
+ return (_buffer.getUint8(keyIndirectOffset + input.length) == 0) ? 0 : -1;
+ }
+
+ Reference _valueForIndexWithKey(int index, String key) {
+ final indirect = _indirect;
+ final elementOffset = indirect + index * _byteWidth;
+ final packedType = _buffer.getUint8(indirect + length * _byteWidth + index);
+ return Reference._(_buffer, elementOffset, BitWidthUtil.fromByteWidth(_byteWidth), packedType, "$_path/$key");
+ }
+
+ Reference _valueForIndex(int index) {
+ final indirect = _indirect;
+ final elementOffset = indirect + index * _byteWidth;
+ final packedType = _buffer.getUint8(indirect + length * _byteWidth + index);
+ return Reference._(_buffer, elementOffset, BitWidthUtil.fromByteWidth(_byteWidth), packedType, "$_path/[$index]");
+ }
+
+ String _keyForIndex(int index) {
+ final keysVectorOffset = _indirect - _byteWidth * 3;
+ final indirectOffset = keysVectorOffset - _readUInt(keysVectorOffset, BitWidthUtil.fromByteWidth(_byteWidth));
+ final byteWidth = _readUInt(keysVectorOffset + _byteWidth, BitWidthUtil.fromByteWidth(_byteWidth));
+ final keyOffset = indirectOffset + index * byteWidth;
+ final keyIndirectOffset = keyOffset - _readUInt(keyOffset, BitWidthUtil.fromByteWidth(byteWidth));
+ var length = 0;
+ while (_buffer.getUint8(keyIndirectOffset + length) != 0) {
+ length += 1;
+ }
+ return utf8.decode(_buffer.buffer.asUint8List(keyIndirectOffset, length));
+ }
+
+}
+
+class _VectorIterator with IterableMixin<Reference> implements Iterator<Reference> {
+ final Reference _vector;
+ int index;
+
+ _VectorIterator(this._vector) {
+ index = -1;
+ }
+
+ @override
+ Reference get current => _vector[index];
+
+ @override
+ bool moveNext() {
+ index++;
+ return index < _vector.length;
+ }
+
+ @override
+ Iterator<Reference> get iterator => this;
+}
+
+class _MapKeyIterator with IterableMixin<String> implements Iterator<String> {
+ final Reference _map;
+ int index;
+
+ _MapKeyIterator(this._map) {
+ index = -1;
+ }
+
+ @override
+ String get current => _map._keyForIndex(index);
+
+ @override
+ bool moveNext() {
+ index++;
+ return index < _map.length;
+ }
+
+ @override
+ Iterator<String> get iterator => this;
+}
+
+class _MapValueIterator with IterableMixin<Reference> implements Iterator<Reference> {
+ final Reference _map;
+ int index;
+
+ _MapValueIterator(this._map) {
+ index = -1;
+ }
+
+ @override
+ Reference get current => _map._valueForIndex(index);
+
+ @override
+ bool moveNext() {
+ index++;
+ return index < _map.length;
+ }
+
+ @override
+ Iterator<Reference> get iterator => this;
+}
diff --git a/dart/lib/src/types.dart b/dart/lib/src/types.dart
new file mode 100644
index 0000000..8aed272
--- /dev/null
+++ b/dart/lib/src/types.dart
@@ -0,0 +1,166 @@
+import 'dart:typed_data';
+
+/// Represents the number of bits a value occupies.
+enum BitWidth {
+ width8,
+ width16,
+ width32,
+ width64
+}
+
+class BitWidthUtil {
+ static int toByteWidth(BitWidth self) {
+ return 1 << self.index;
+ }
+ static BitWidth width(num value) {
+ if (value.toInt() == value) {
+ var v = value.toInt().abs();
+ if (v >> 7 == 0) return BitWidth.width8;
+ if (v >> 15 == 0) return BitWidth.width16;
+ if (v >> 31 == 0) return BitWidth.width32;
+ return BitWidth.width64;
+ }
+ return value == _toF32(value) ? BitWidth.width32 : BitWidth.width64;
+ }
+ static BitWidth uwidth(num value) {
+ if (value.toInt() == value) {
+ var v = value.toInt().abs();
+ if (v >> 8 == 0) return BitWidth.width8;
+ if (v >> 16 == 0) return BitWidth.width16;
+ if (v >> 32 == 0) return BitWidth.width32;
+ return BitWidth.width64;
+ }
+ return value == _toF32(value) ? BitWidth.width32 : BitWidth.width64;
+ }
+ static BitWidth fromByteWidth(int value) {
+ if (value == 1) {
+ return BitWidth.width8;
+ }
+ if (value == 2) {
+ return BitWidth.width16;
+ }
+ if (value == 4) {
+ return BitWidth.width32;
+ }
+ if (value == 8) {
+ return BitWidth.width64;
+ }
+ throw Exception('Unexpected value ${value}');
+ }
+ static int paddingSize(int bufSize, int scalarSize) {
+ return (~bufSize + 1) & (scalarSize - 1);
+ }
+ static double _toF32(double value) {
+ var bdata = ByteData(4);
+ bdata.setFloat32(0, value);
+ return bdata.getFloat32(0);
+ }
+
+ static BitWidth max(BitWidth self, BitWidth other) {
+ if (self.index < other.index) {
+ return other;
+ }
+ return self;
+ }
+}
+
+/// Represents all internal FlexBuffer types.
+enum ValueType {
+ Null, Int, UInt, Float,
+ Key, String, IndirectInt, IndirectUInt, IndirectFloat,
+ Map, Vector, VectorInt, VectorUInt, VectorFloat, VectorKey,
+ @Deprecated('VectorString is deprecated due to a flaw in the binary format (https://github.com/google/flatbuffers/issues/5627)')
+ VectorString,
+ VectorInt2, VectorUInt2, VectorFloat2,
+ VectorInt3, VectorUInt3, VectorFloat3,
+ VectorInt4, VectorUInt4, VectorFloat4,
+ Blob, Bool, VectorBool
+}
+
+class ValueTypeUtils {
+ static int toInt(ValueType self) {
+ if (self == ValueType.VectorBool) return 36;
+ return self.index;
+ }
+
+ static ValueType fromInt(int value) {
+ if (value == 36) return ValueType.VectorBool;
+ return ValueType.values[value];
+ }
+
+ static bool isInline(ValueType self) {
+ return self == ValueType.Bool
+ || toInt(self) <= toInt(ValueType.Float);
+ }
+
+ static bool isNumber(ValueType self) {
+ return toInt(self) >= toInt(ValueType.Int)
+ && toInt(self) <= toInt(ValueType.Float);
+ }
+
+ static bool isIndirectNumber(ValueType self) {
+ return toInt(self) >= toInt(ValueType.IndirectInt)
+ && toInt(self) <= toInt(ValueType.IndirectFloat);
+ }
+
+ static bool isTypedVectorElement(ValueType self) {
+ return self == ValueType.Bool ||
+ (
+ toInt(self) >= toInt(ValueType.Int)
+ && toInt(self) <= toInt(ValueType.String)
+ );
+ }
+
+ static bool isTypedVector(ValueType self) {
+ return self == ValueType.VectorBool ||
+ (
+ toInt(self) >= toInt(ValueType.VectorInt)
+ && toInt(self) <= toInt(ValueType.VectorString)
+ );
+ }
+
+ static bool isFixedTypedVector(ValueType self) {
+ return (
+ toInt(self) >= toInt(ValueType.VectorInt2)
+ && toInt(self) <= toInt(ValueType.VectorFloat4)
+ );
+ }
+
+ static bool isAVector(ValueType self) {
+ return (
+ isTypedVector(self) || isFixedTypedVector(self) || self == ValueType.Vector
+ );
+ }
+
+ static ValueType toTypedVector(ValueType self, int length) {
+ if (length == 0) {
+ return ValueTypeUtils.fromInt(toInt(self) - toInt(ValueType.Int) + toInt(ValueType.VectorInt));
+ }
+ if (length == 2) {
+ return ValueTypeUtils.fromInt(toInt(self) - toInt(ValueType.Int) + toInt(ValueType.VectorInt2));
+ }
+ if (length == 3) {
+ return ValueTypeUtils.fromInt(toInt(self) - toInt(ValueType.Int) + toInt(ValueType.VectorInt3));
+ }
+ if (length == 4) {
+ return ValueTypeUtils.fromInt(toInt(self) - toInt(ValueType.Int) + toInt(ValueType.VectorInt4));
+ }
+ throw Exception('unexpected length ' + length.toString());
+ }
+
+ static ValueType typedVectorElementType(ValueType self) {
+ return ValueTypeUtils.fromInt(toInt(self) - toInt(ValueType.VectorInt) + toInt(ValueType.Int));
+ }
+
+ static ValueType fixedTypedVectorElementType(ValueType self) {
+ return ValueTypeUtils.fromInt((toInt(self) - toInt(ValueType.VectorInt2)) % 3 + toInt(ValueType.Int));
+ }
+
+ static int fixedTypedVectorElementSize(ValueType self) {
+ return (toInt(self) - toInt(ValueType.VectorInt2)) ~/ 3 + 2;
+ }
+
+ static int packedType(ValueType self, BitWidth bitWidth) {
+ return bitWidth.index | (toInt(self) << 2);
+ }
+}
diff --git a/dart/pubspec.yaml b/dart/pubspec.yaml
index 4761ffc..78a7bf1 100644
--- a/dart/pubspec.yaml
+++ b/dart/pubspec.yaml
@@ -1,5 +1,5 @@
name: flat_buffers
-version: 1.11.0
+version: 1.12.0
description: >
FlatBuffers reading and writing library for Dart. Use the flatc compiler to
generate Dart classes for a FlatBuffers schema, and this library to assist with
diff --git a/dart/test/flat_buffers_test.dart b/dart/test/flat_buffers_test.dart
index f9c5e01..be500f2 100644
--- a/dart/test/flat_buffers_test.dart
+++ b/dart/test/flat_buffers_test.dart
@@ -17,6 +17,7 @@
defineReflectiveSuite(() {
defineReflectiveTests(BuilderTest);
defineReflectiveTests(CheckOtherLangaugesData);
+ defineReflectiveTests(GeneratorTest);
});
}
@@ -30,8 +31,7 @@
List<int> data = await new io.File(path.join(
path.dirname(io.Platform.script.path),
'monsterdata_test.mon',
- ))
- .readAsBytes();
+ )).readAsBytes();
example.Monster mon = new example.Monster(data);
expect(mon.hp, 80);
expect(mon.mana, 150);
@@ -58,8 +58,71 @@
expect(mon.testarrayofstring[1], "test2");
// this will fail if accessing any field fails.
- expect(mon.toString(),
- 'Monster{pos: Vec3{x: 1.0, y: 2.0, z: 3.0, test1: 3.0, test2: Color{value: 2}, test3: Test{a: 5, b: 6}}, mana: 150, hp: 80, name: MyMonster, inventory: [0, 1, 2, 3, 4], color: Color{value: 8}, testType: AnyTypeId{value: 1}, test: Monster{pos: null, mana: 150, hp: 100, name: Fred, inventory: null, color: Color{value: 8}, testType: AnyTypeId{value: 0}, test: null, test4: null, testarrayofstring: null, testarrayoftables: null, enemy: null, testnestedflatbuffer: null, testempty: null, testbool: false, testhashs32Fnv1: 0, testhashu32Fnv1: 0, testhashs64Fnv1: 0, testhashu64Fnv1: 0, testhashs32Fnv1a: 0, testhashu32Fnv1a: 0, testhashs64Fnv1a: 0, testhashu64Fnv1a: 0, testarrayofbools: null, testf: 3.14159, testf2: 3.0, testf3: 0.0, testarrayofstring2: null, testarrayofsortedstruct: null, flex: null, test5: null, vectorOfLongs: null, vectorOfDoubles: null, parentNamespaceTest: null, vectorOfReferrables: null, singleWeakReference: 0, vectorOfWeakReferences: null, vectorOfStrongReferrables: null, coOwningReference: 0, vectorOfCoOwningReferences: null, nonOwningReference: 0, vectorOfNonOwningReferences: null}, test4: [Test{a: 10, b: 20}, Test{a: 30, b: 40}], testarrayofstring: [test1, test2], testarrayoftables: null, enemy: Monster{pos: null, mana: 150, hp: 100, name: Fred, inventory: null, color: Color{value: 8}, testType: AnyTypeId{value: 0}, test: null, test4: null, testarrayofstring: null, testarrayoftables: null, enemy: null, testnestedflatbuffer: null, testempty: null, testbool: false, testhashs32Fnv1: 0, testhashu32Fnv1: 0, testhashs64Fnv1: 0, testhashu64Fnv1: 0, testhashs32Fnv1a: 0, testhashu32Fnv1a: 0, testhashs64Fnv1a: 0, testhashu64Fnv1a: 0, testarrayofbools: null, testf: 3.14159, testf2: 3.0, testf3: 0.0, testarrayofstring2: null, testarrayofsortedstruct: null, flex: null, test5: null, vectorOfLongs: null, vectorOfDoubles: null, parentNamespaceTest: null, vectorOfReferrables: null, singleWeakReference: 0, vectorOfWeakReferences: null, vectorOfStrongReferrables: null, coOwningReference: 0, vectorOfCoOwningReferences: null, nonOwningReference: 0, vectorOfNonOwningReferences: null}, testnestedflatbuffer: null, testempty: null, testbool: false, testhashs32Fnv1: -579221183, testhashu32Fnv1: 3715746113, testhashs64Fnv1: 7930699090847568257, testhashu64Fnv1: 7930699090847568257, testhashs32Fnv1a: -1904106383, testhashu32Fnv1a: 2390860913, testhashs64Fnv1a: 4898026182817603057, testhashu64Fnv1a: 4898026182817603057, testarrayofbools: [true, false, true], testf: 3.14159, testf2: 3.0, testf3: 0.0, testarrayofstring2: null, testarrayofsortedstruct: null, flex: null, test5: [Test{a: 10, b: 20}, Test{a: 30, b: 40}], vectorOfLongs: [1, 100, 10000, 1000000, 100000000], vectorOfDoubles: [-1.7976931348623157e+308, 0.0, 1.7976931348623157e+308], parentNamespaceTest: null, vectorOfReferrables: null, singleWeakReference: 0, vectorOfWeakReferences: null, vectorOfStrongReferrables: null, coOwningReference: 0, vectorOfCoOwningReferences: null, nonOwningReference: 0, vectorOfNonOwningReferences: null}');
+ expect(
+ mon.toString(),
+ 'Monster{'
+ 'pos: Vec3{x: 1.0, y: 2.0, z: 3.0, test1: 3.0, test2: Color{value: 2}, test3: Test{a: 5, b: 6}}, '
+ 'mana: 150, hp: 80, name: MyMonster, inventory: [0, 1, 2, 3, 4], '
+ 'color: Color{value: 8}, testType: AnyTypeId{value: 1}, '
+ 'test: Monster{pos: null, mana: 150, hp: 100, name: Fred, '
+ 'inventory: null, color: Color{value: 8}, testType: AnyTypeId{value: 0}, '
+ 'test: null, test4: null, testarrayofstring: null, '
+ 'testarrayoftables: null, enemy: null, testnestedflatbuffer: null, '
+ 'testempty: null, testbool: false, testhashs32Fnv1: 0, '
+ 'testhashu32Fnv1: 0, testhashs64Fnv1: 0, testhashu64Fnv1: 0, '
+ 'testhashs32Fnv1a: 0, testhashu32Fnv1a: 0, testhashs64Fnv1a: 0, '
+ 'testhashu64Fnv1a: 0, testarrayofbools: null, testf: 3.14159, '
+ 'testf2: 3.0, testf3: 0.0, testarrayofstring2: null, '
+ 'testarrayofsortedstruct: null, flex: null, test5: null, '
+ 'vectorOfLongs: null, vectorOfDoubles: null, parentNamespaceTest: null, '
+ 'vectorOfReferrables: null, singleWeakReference: 0, '
+ 'vectorOfWeakReferences: null, vectorOfStrongReferrables: null, '
+ 'coOwningReference: 0, vectorOfCoOwningReferences: null, '
+ 'nonOwningReference: 0, vectorOfNonOwningReferences: null, '
+ 'anyUniqueType: AnyUniqueAliasesTypeId{value: 0}, anyUnique: null, '
+ 'anyAmbiguousType: AnyAmbiguousAliasesTypeId{value: 0}, '
+ 'anyAmbiguous: null, vectorOfEnums: null, signedEnum: Race{value: -1}}, '
+ 'test4: [Test{a: 10, b: 20}, Test{a: 30, b: 40}], '
+ 'testarrayofstring: [test1, test2], testarrayoftables: null, '
+ 'enemy: Monster{pos: null, mana: 150, hp: 100, name: Fred, '
+ 'inventory: null, color: Color{value: 8}, testType: AnyTypeId{value: 0}, '
+ 'test: null, test4: null, testarrayofstring: null, '
+ 'testarrayoftables: null, enemy: null, testnestedflatbuffer: null, '
+ 'testempty: null, testbool: false, testhashs32Fnv1: 0, '
+ 'testhashu32Fnv1: 0, testhashs64Fnv1: 0, testhashu64Fnv1: 0, '
+ 'testhashs32Fnv1a: 0, testhashu32Fnv1a: 0, testhashs64Fnv1a: 0, '
+ 'testhashu64Fnv1a: 0, testarrayofbools: null, testf: 3.14159, '
+ 'testf2: 3.0, testf3: 0.0, testarrayofstring2: null, '
+ 'testarrayofsortedstruct: null, flex: null, test5: null, '
+ 'vectorOfLongs: null, vectorOfDoubles: null, parentNamespaceTest: null, '
+ 'vectorOfReferrables: null, singleWeakReference: 0, '
+ 'vectorOfWeakReferences: null, vectorOfStrongReferrables: null, '
+ 'coOwningReference: 0, vectorOfCoOwningReferences: null, '
+ 'nonOwningReference: 0, vectorOfNonOwningReferences: null, '
+ 'anyUniqueType: AnyUniqueAliasesTypeId{value: 0}, anyUnique: null, '
+ 'anyAmbiguousType: AnyAmbiguousAliasesTypeId{value: 0}, '
+ 'anyAmbiguous: null, vectorOfEnums: null, signedEnum: Race{value: -1}}, '
+ 'testnestedflatbuffer: null, testempty: null, testbool: true, '
+ 'testhashs32Fnv1: -579221183, testhashu32Fnv1: 3715746113, '
+ 'testhashs64Fnv1: 7930699090847568257, '
+ 'testhashu64Fnv1: 7930699090847568257, '
+ 'testhashs32Fnv1a: -1904106383, testhashu32Fnv1a: 2390860913, '
+ 'testhashs64Fnv1a: 4898026182817603057, '
+ 'testhashu64Fnv1a: 4898026182817603057, '
+ 'testarrayofbools: [true, false, true], testf: 3.14159, testf2: 3.0, '
+ 'testf3: 0.0, testarrayofstring2: null, testarrayofsortedstruct: null, '
+ 'flex: null, test5: [Test{a: 10, b: 20}, Test{a: 30, b: 40}], '
+ 'vectorOfLongs: [1, 100, 10000, 1000000, 100000000], '
+ 'vectorOfDoubles: [-1.7976931348623157e+308, 0.0, 1.7976931348623157e+308], '
+ 'parentNamespaceTest: null, vectorOfReferrables: null, '
+ 'singleWeakReference: 0, vectorOfWeakReferences: null, '
+ 'vectorOfStrongReferrables: null, coOwningReference: 0, '
+ 'vectorOfCoOwningReferences: null, nonOwningReference: 0, '
+ 'vectorOfNonOwningReferences: null, '
+ 'anyUniqueType: AnyUniqueAliasesTypeId{value: 0}, anyUnique: null, '
+ 'anyAmbiguousType: AnyAmbiguousAliasesTypeId{value: 0}, '
+ 'anyAmbiguous: null, vectorOfEnums: null, signedEnum: Race{value: -1}}',
+ );
}
}
@@ -88,7 +151,6 @@
testBuilder.finish(30, 40);
final test4 = fbBuilder.endStructVector(2);
-
monBuilder
..begin()
..addPos(
@@ -167,8 +229,8 @@
expect(byteData.getUint8(6), 126); // '~'
expect(byteData.getUint8(7), 255); // 'ÿ'
// First 4 bytes of the table data are a backwards offset to the vtable.
- int vTableLoc = tableDataLoc -
- byteData.getInt32(tableDataLoc, Endian.little);
+ int vTableLoc =
+ tableDataLoc - byteData.getInt32(tableDataLoc, Endian.little);
// First 2 bytes of the vtable are the size of the vtable in bytes, which
// should be 4.
expect(byteData.getUint16(vTableLoc, Endian.little), 4);
@@ -231,8 +293,8 @@
// First 4 bytes are an offset to the table data.
int tableDataLoc = byteData.getUint32(0, Endian.little);
// First 4 bytes of the table data are a backwards offset to the vtable.
- int vTableLoc = tableDataLoc -
- byteData.getInt32(tableDataLoc, Endian.little);
+ int vTableLoc =
+ tableDataLoc - byteData.getInt32(tableDataLoc, Endian.little);
// First 2 bytes of the vtable are the size of the vtable in bytes, which
// should be 10.
expect(byteData.getUint16(vTableLoc, Endian.little), 10);
@@ -242,10 +304,9 @@
// Remaining 6 bytes are the offsets within the object where the ints are
// located.
for (int i = 0; i < 3; i++) {
- int offset =
- byteData.getUint16(vTableLoc + 4 + 2 * i, Endian.little);
- expect(byteData.getInt32(tableDataLoc + offset, Endian.little),
- 10 + 10 * i);
+ int offset = byteData.getUint16(vTableLoc + 4 + 2 * i, Endian.little);
+ expect(
+ byteData.getInt32(tableDataLoc + offset, Endian.little), 10 + 10 * i);
}
}
@@ -571,3 +632,14 @@
return new TestPointImpl(object, offset);
}
}
+
+@reflectiveTest
+class GeneratorTest {
+ void test_constantEnumValues() async {
+ expect(example.Color.values, same(example.Color.values));
+ expect(example.Race.values, same(example.Race.values));
+ expect(example.AnyTypeId.values, same(example.AnyTypeId.values));
+ expect(example.AnyUniqueAliasesTypeId.values, same(example.AnyUniqueAliasesTypeId.values));
+ expect(example.AnyAmbiguousAliasesTypeId.values, same(example.AnyAmbiguousAliasesTypeId.values));
+ }
+}
diff --git a/dart/test/flex_builder_test.dart b/dart/test/flex_builder_test.dart
new file mode 100644
index 0000000..5a1c1a8
--- /dev/null
+++ b/dart/test/flex_builder_test.dart
@@ -0,0 +1,315 @@
+import 'dart:typed_data';
+
+import 'package:flat_buffers/flex_buffers.dart' show Builder;
+import 'package:test/test.dart';
+
+void main() {
+ test('build with single value', () {
+ {
+ var flx = Builder();
+ flx.addNull();
+ expect(flx.finish(), [0, 0, 1]);
+ }
+ {
+ var flx = Builder();
+ flx.addBool(true);
+ expect(flx.finish(), [1, 104, 1]);
+ }
+ {
+ var flx = Builder();
+ flx.addBool(false);
+ expect(flx.finish(), [0, 104, 1]);
+ }
+ {
+ var flx = Builder();
+ flx.addInt(1);
+ expect(flx.finish(), [1, 4, 1]);
+ }
+ {
+ var flx = Builder();
+ flx.addInt(230);
+ expect(flx.finish(), [230, 0, 5, 2]);
+ }
+ {
+ var flx = Builder();
+ flx.addInt(1025);
+ expect(flx.finish(), [1, 4, 5, 2]);
+ }
+ {
+ var flx = Builder();
+ flx.addInt(-1025);
+ expect(flx.finish(), [255, 251, 5, 2]);
+ }
+ {
+ var flx = Builder();
+ flx.addDouble(0.1);
+ expect(flx.finish(), [154, 153, 153, 153, 153, 153, 185, 63, 15, 8]);
+ }
+ {
+ var flx = Builder();
+ flx.addDouble(0.5);
+ expect(flx.finish(), [0, 0, 0, 63, 14, 4]);
+ }
+ {
+ var flx = Builder();
+ flx.addString('Maxim');
+ expect(flx.finish(), [5, 77, 97, 120, 105, 109, 0, 6, 20, 1]);
+ }
+ {
+ var flx = Builder();
+ flx.addString('hello 😱');
+ expect(flx.finish(), [10, 104, 101, 108, 108, 111, 32, 240, 159, 152, 177, 0, 11, 20, 1]);
+ }
+ });
+
+ test('build vector', (){
+ {
+ var flx = Builder()
+ ..startVector()
+ ..addInt(1)
+ ..addInt(2)
+ ..end()
+ ;
+ expect(flx.finish(), [1, 2, 2, 64, 1]);
+ }
+ {
+ var flx = Builder()
+ ..startVector()
+ ..addInt(-1)
+ ..addInt(256)
+ ..end()
+ ;
+ expect(flx.finish(), [255, 255, 0, 1, 4, 65, 1]);
+ }
+ {
+ var flx = Builder()
+ ..startVector()
+ ..addInt(-45)
+ ..addInt(256000)
+ ..end()
+ ;
+ expect(flx.finish(), [211, 255, 255, 255, 0, 232, 3, 0, 8, 66, 1]);
+ }
+ {
+ var flx = Builder()
+ ..startVector()
+ ..addDouble(1.1)
+ ..addDouble(-256)
+ ..end()
+ ;
+ expect(flx.finish(), [154, 153, 153, 153, 153, 153, 241, 63, 0, 0, 0, 0, 0, 0, 112, 192, 16, 75, 1]);
+ }
+ {
+ var flx = Builder()
+ ..startVector()
+ ..addInt(1)
+ ..addInt(2)
+ ..addInt(4)
+ ..end()
+ ;
+ expect(flx.finish(), [1, 2, 4, 3, 76, 1]);
+ }
+ {
+ var flx = Builder()
+ ..startVector()
+ ..addInt(-1)
+ ..addInt(256)
+ ..addInt(4)
+ ..end()
+ ;
+ expect(flx.finish(), [255, 255, 0, 1, 4, 0, 6, 77, 1]);
+ }
+ {
+ var flx = Builder()
+ ..startVector()
+ ..startVector()
+ ..addInt(61)
+ ..end()
+ ..addInt(64)
+ ..end()
+ ;
+ expect(flx.finish(), [1, 61, 2, 2, 64, 44, 4, 4, 40, 1]);
+ }
+ {
+ var flx = Builder()
+ ..startVector()
+ ..addString('foo')
+ ..addString('bar')
+ ..addString('baz')
+ ..end()
+ ;
+ expect(flx.finish(), [3, 102, 111, 111, 0, 3, 98, 97, 114, 0, 3, 98, 97, 122, 0, 3, 15, 11, 7, 3, 60, 1]);
+ }
+ {
+ var flx = Builder()
+ ..startVector()
+ ..addString('foo')
+ ..addString('bar')
+ ..addString('baz')
+ ..addString('foo')
+ ..addString('bar')
+ ..addString('baz')
+ ..end()
+ ;
+ expect(flx.finish(), [3, 102, 111, 111, 0, 3, 98, 97, 114, 0, 3, 98, 97, 122, 0, 6, 15, 11, 7, 18, 14, 10, 6, 60, 1]);
+ }
+ {
+ var flx = Builder()
+ ..startVector()
+ ..addBool(true)
+ ..addBool(false)
+ ..addBool(true)
+ ..end()
+ ;
+ expect(flx.finish(), [3, 1, 0, 1, 3, 144, 1]);
+ }
+ {
+ var flx = Builder()
+ ..startVector()
+ ..addString('foo')
+ ..addInt(1)
+ ..addInt(-5)
+ ..addDouble(1.3)
+ ..addBool(true)
+ ..end()
+ ;
+ expect(flx.finish(), [
+ 3, 102, 111, 111, 0, 0, 0, 0,
+ 5, 0, 0, 0, 0, 0, 0, 0,
+ 15, 0, 0, 0, 0, 0, 0, 0,
+ 1, 0, 0, 0, 0, 0, 0, 0,
+ 251, 255, 255, 255, 255, 255, 255, 255,
+ 205, 204, 204, 204, 204, 204, 244, 63,
+ 1, 0, 0, 0, 0, 0, 0, 0,
+ 20, 4, 4, 15, 104, 45, 43, 1]);
+ }
+ });
+
+ test('build map', ()
+ {
+ {
+ var flx = Builder()
+ ..startMap()
+ ..addKey('a')
+ ..addInt(12)
+ ..end()
+ ;
+ expect(flx.finish(), [97, 0, 1, 3, 1, 1, 1, 12, 4, 2, 36, 1]);
+ }
+ {
+ var flx = Builder()
+ ..startMap()
+ ..addKey('a')
+ ..addInt(12)
+ ..addKey('')
+ ..addInt(45)
+ ..end()
+ ;
+ expect(flx.finish(), [97, 0, 0, 2, 2, 5, 2, 1, 2, 45, 12, 4, 4, 4, 36, 1]);
+ }
+ {
+ var flx = Builder()
+ ..startVector()
+ ..startMap()
+ ..addKey('something')
+ ..addInt(12)
+ ..end()
+ ..startMap()
+ ..addKey('something')
+ ..addInt(45)
+ ..end()
+ ..end()
+ ;
+ expect(flx.finish(), [115, 111, 109, 101, 116, 104, 105, 110, 103, 0,
+ 1, 11, 1, 1, 1, 12, 4, 6, 1, 1, 45, 4, 2, 8, 4, 36, 36, 4, 40, 1]);
+ }
+ });
+
+ test('build blob', ()
+ {
+ {
+ var flx = Builder()
+ ..addBlob(Uint8List.fromList([1, 2, 3]).buffer)
+ ;
+ expect(flx.finish(), [3, 1, 2, 3, 3, 100, 1]);
+ }
+ });
+
+ test('build from object', (){
+ expect(Builder.buildFromObject(Uint8List.fromList([1, 2, 3]).buffer).asUint8List(), [3, 1, 2, 3, 3, 100, 1]);
+ expect(Builder.buildFromObject(null).asUint8List(), [0, 0, 1]);
+ expect(Builder.buildFromObject(true).asUint8List(), [1, 104, 1]);
+ expect(Builder.buildFromObject(false).asUint8List(), [0, 104, 1]);
+ expect(Builder.buildFromObject(25).asUint8List(), [25, 4, 1]);
+ expect(Builder.buildFromObject(-250).asUint8List(), [6, 255, 5, 2]);
+ expect(Builder.buildFromObject(-2.50).asUint8List(), [0, 0, 32, 192, 14, 4]);
+ expect(Builder.buildFromObject('Maxim').asUint8List(), [5, 77, 97, 120, 105, 109, 0, 6, 20, 1]);
+ expect(Builder.buildFromObject([1, 3.3, 'max', true, null, false]).asUint8List(), [
+ 3, 109, 97, 120, 0, 0, 0, 0,
+ 6, 0, 0, 0, 0, 0, 0, 0,
+ 1, 0, 0, 0, 0, 0, 0, 0,
+ 102, 102, 102, 102, 102, 102, 10, 64,
+ 31, 0, 0, 0, 0, 0, 0, 0,
+ 1, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0,
+ 4, 15, 20, 104, 0, 104, 54, 43, 1
+ ]);
+ expect(Builder.buildFromObject([{'something':12}, {'something': 45}]).asUint8List(), [
+ 115, 111, 109, 101, 116, 104, 105, 110, 103, 0,
+ 1, 11, 1, 1, 1, 12, 4, 6, 1, 1, 45, 4, 2, 8, 4, 36, 36, 4, 40, 1
+ ]);
+ });
+
+ test('add double indirectly', (){
+ var flx = Builder()
+ ..addDoubleIndirectly(0.1)
+ ;
+ expect(flx.finish(), [154, 153, 153, 153, 153, 153, 185, 63, 8, 35, 1]);
+ });
+
+ test('add double indirectly to vector with cache', (){
+ var flx = Builder()
+ ..startVector()
+ ..addDoubleIndirectly(0.1, cache: true)
+ ..addDoubleIndirectly(0.1, cache: true)
+ ..addDoubleIndirectly(0.1, cache: true)
+ ..addDoubleIndirectly(0.1, cache: true)
+ ..end()
+ ;
+ expect(flx.finish(), [154, 153, 153, 153, 153, 153, 185, 63,
+ 4, 9, 10, 11, 12, 35, 35, 35, 35, 8, 40, 1]);
+ });
+
+ test('add int indirectly', (){
+ var flx = Builder()
+ ..addIntIndirectly(2345234523452345)
+ ;
+ expect(flx.finish(), [185, 115, 175, 118, 250, 84, 8, 0, 8, 27, 1]);
+ });
+
+ test('add int indirectly to vector with cache', (){
+ var flx = Builder()
+ ..startVector()
+ ..addIntIndirectly(2345234523452345, cache: true)
+ ..addIntIndirectly(2345234523452345, cache: true)
+ ..addIntIndirectly(2345234523452345, cache: true)
+ ..addIntIndirectly(2345234523452345, cache: true)
+ ..end()
+ ;
+ expect(flx.finish(), [185, 115, 175, 118, 250, 84, 8, 0,
+ 4, 9, 10, 11, 12, 27, 27, 27, 27, 8, 40, 1]);
+ });
+
+ test('snapshot', (){
+ var flx = Builder();
+ flx.startVector();
+ flx.addInt(12);
+ expect(flx.snapshot().asUint8List(), [1, 12, 1, 44, 1]);
+ flx.addInt(24);
+ expect(flx.snapshot().asUint8List(), [12, 24, 2, 64, 1]);
+ flx.addInt(45);
+ expect(flx.snapshot().asUint8List(), [12, 24, 45, 3, 76, 1]);
+ });
+}
+
diff --git a/dart/test/flex_reader_test.dart b/dart/test/flex_reader_test.dart
new file mode 100644
index 0000000..ec30367
--- /dev/null
+++ b/dart/test/flex_reader_test.dart
@@ -0,0 +1,334 @@
+import 'dart:typed_data';
+
+import 'package:flat_buffers/flex_buffers.dart' show Reference, Builder;
+import 'package:test/test.dart';
+
+void main() {
+ test('is null', () {
+ expect(Reference.fromBuffer(b([0, 0, 1])).isNull, isTrue);
+ });
+
+ test('bool value', () {
+ expect(Reference.fromBuffer(b([1, 104, 1])).boolValue, isTrue);
+ expect(Reference.fromBuffer(b([0, 104, 1])).boolValue, isFalse);
+ });
+ test('int value', () {
+ expect(Reference.fromBuffer(b([25, 4, 1])).intValue, 25);
+ expect(Reference.fromBuffer(b([231, 4, 1])).intValue, -25);
+ expect(Reference.fromBuffer(b([230, 8, 1])).intValue, 230);
+ expect(Reference.fromBuffer(b([230, 0, 5, 2])).intValue, 230);
+ expect(Reference.fromBuffer(b([1, 4, 5, 2])).intValue, 1025);
+ expect(Reference.fromBuffer(b([255, 251, 5, 2])).intValue, -1025);
+ expect(Reference.fromBuffer(b([1, 4, 9, 2])).intValue, 1025);
+ expect(Reference.fromBuffer(b([255, 255, 255, 127, 6, 4])).intValue,
+ 2147483647);
+ expect(
+ Reference.fromBuffer(b([0, 0, 0, 128, 6, 4])).intValue, -2147483648);
+ expect(
+ Reference.fromBuffer(b([255, 255, 255, 255, 0, 0, 0, 0, 7, 8]))
+ .intValue,
+ 4294967295);
+ expect(
+ Reference.fromBuffer(b([255, 255, 255, 255, 255, 255, 255, 127, 7, 8]))
+ .intValue,
+ 9223372036854775807);
+ expect(Reference.fromBuffer(b([0, 0, 0, 0, 0, 0, 0, 128, 7, 8])).intValue,
+ -9223372036854775808);
+ // Dart does not really support UInt64
+// expect(FlxValue.fromBuffer(b([255, 255, 255, 255, 255, 255, 255, 255, 11, 8])).intValue, 18446744073709551615);
+ });
+ test('double value', () {
+ expect(Reference.fromBuffer(b([0, 0, 144, 64, 14, 4])).doubleValue, 4.5);
+ expect(Reference.fromBuffer(b([205, 204, 204, 61, 14, 4])).doubleValue,
+ closeTo(.1, .001));
+ expect(
+ Reference.fromBuffer(b([154, 153, 153, 153, 153, 153, 185, 63, 15, 8]))
+ .doubleValue,
+ .1);
+ });
+ test('num value', () {
+ expect(Reference.fromBuffer(b([0, 0, 144, 64, 14, 4])).numValue, 4.5);
+ expect(Reference.fromBuffer(b([205, 204, 204, 61, 14, 4])).numValue,
+ closeTo(.1, .001));
+ expect(
+ Reference.fromBuffer(b([154, 153, 153, 153, 153, 153, 185, 63, 15, 8]))
+ .numValue,
+ .1);
+ expect(Reference.fromBuffer(b([255, 251, 5, 2])).numValue, -1025);
+ });
+ test('string value', () {
+ expect(
+ Reference.fromBuffer(b([5, 77, 97, 120, 105, 109, 0, 6, 20, 1]))
+ .stringValue,
+ 'Maxim');
+ expect(
+ Reference.fromBuffer(b([
+ 10, 104, 101, 108, 108, 111, 32, 240, 159, 152, 177, 0, 11, 20, 1
+ ])).stringValue,
+ 'hello 😱');
+ });
+ test('blob value', () {
+ expect(
+ Reference.fromBuffer(b([3, 1, 2, 3, 3, 100, 1])).blobValue, [1, 2, 3]);
+ });
+ test('bool vector', () {
+ var flx = Reference.fromBuffer(b([3, 1, 0, 1, 3, 144, 1]));
+ expect(flx[0].boolValue, true);
+ expect(flx[1].boolValue, false);
+ expect(flx[2].boolValue, true);
+ });
+ test('number vector', () {
+ testNumbers([3, 1, 2, 3, 3, 44, 1], [1, 2, 3]);
+ testNumbers([3, 255, 2, 3, 3, 44, 1], [-1, 2, 3]);
+ testNumbers([3, 0, 1, 0, 43, 2, 3, 0, 6, 45, 1], [1, 555, 3]);
+ testNumbers(
+ [3, 0, 0, 0, 1, 0, 0, 0, 204, 216, 0, 0, 3, 0, 0, 0, 12, 46, 1],
+ [1, 55500, 3]);
+ testNumbers([
+ 3, 0, 0, 0, 0, 0, 0, 0,
+ 1, 0, 0, 0, 0, 0, 0, 0,
+ 172, 128, 94, 239, 12, 0, 0, 0,
+ 3, 0, 0, 0, 0, 0, 0, 0,
+ 24, 47, 1
+ ], [1, 55555555500, 3
+ ]);
+ testNumbers(
+ [3, 0, 0, 0, 0, 0, 192, 63, 0, 0, 32, 64, 0, 0, 96, 64, 12, 54, 1],
+ [1.5, 2.5, 3.5]);
+ testNumbers([
+ 3, 0, 0, 0, 0, 0, 0, 0,
+ 154, 153, 153, 153, 153, 153, 241, 63,
+ 154, 153, 153, 153, 153, 153, 1, 64,
+ 102, 102, 102, 102, 102, 102, 10, 64,
+ 24, 55, 1
+ ], [1.1, 2.2, 3.3
+ ]);
+ });
+ test('number vector, fixed type', () {
+ testNumbers([1, 2, 2, 64, 1], [1, 2]);
+ testNumbers([255, 255, 0, 1, 4, 65, 1], [-1, 256]);
+ testNumbers([211, 255, 255, 255, 0, 232, 3, 0, 8, 66, 1], [-45, 256000]);
+ testNumbers([
+ 211, 255, 255, 255, 255, 255, 255, 255,
+ 255, 255, 255, 255, 255, 255, 255, 127,
+ 16, 67, 1
+ ], [
+ -45, 9223372036854775807
+ ]);
+
+ testNumbers([1, 2, 2, 68, 1], [1, 2]);
+ testNumbers([1, 0, 0, 1, 4, 69, 1], [1, 256]);
+ testNumbers([45, 0, 0, 0, 0, 232, 3, 0, 8, 70, 1], [45, 256000]);
+
+ testNumbers([205, 204, 140, 63, 0, 0, 0, 192, 8, 74, 1], [1.1, -2]);
+ testNumbers([
+ 154, 153, 153, 153, 153, 153, 241, 63,
+ 0, 0, 0, 0, 0, 0, 112, 192,
+ 16, 75, 1
+ ], [
+ 1.1, -256
+ ]);
+
+ testNumbers([211, 255, 255, 255, 0, 232, 3, 0, 4, 0, 0, 0, 12, 78, 1],
+ [-45, 256000, 4]);
+
+ testNumbers([
+ 211, 255, 255, 255, 255, 255, 255, 255,
+ 255, 255, 255, 255, 255, 255, 255, 127,
+ 4, 0, 0, 0, 0, 0, 0, 0,
+ 9, 0, 0, 0, 0, 0, 0, 0,
+ 32, 91, 1
+ ], [
+ -45, 9223372036854775807, 4, 9
+ ]);
+
+ testNumbers([
+ 45, 0, 0, 0, 0, 0, 0, 0,
+ 255, 255, 255, 255, 255, 255, 255, 127,
+ 4, 0, 0, 0, 0, 0, 0, 0,
+ 9, 0, 0, 0, 0, 0, 0, 0,
+ 32, 95, 1
+ ], [
+ 45, 9223372036854775807, 4, 9
+ ]);
+
+ testNumbers([
+ 154, 153, 153, 153, 153, 153, 241, 63,
+ 0, 0, 0, 0, 0, 0, 112, 64,
+ 0, 0, 0, 0, 0, 0, 16, 64,
+ 24, 87, 1
+ ], [
+ 1.1, 256, 4
+ ]);
+
+ testNumbers([
+ 154, 153, 153, 153, 153, 153, 241, 63,
+ 0, 0, 0, 0, 0, 0, 112, 64,
+ 0, 0, 0, 0, 0, 0, 16, 64,
+ 0, 0, 0, 0, 0, 0, 34, 64,
+ 32, 99, 1
+ ], [
+ 1.1, 256, 4, 9
+ ]);
+ });
+ test('string vector', () {
+ testStrings([
+ 3, 102, 111, 111, 0,
+ 3, 98, 97, 114, 0,
+ 3, 98, 97, 122, 0,
+ 3, 15, 11, 7,
+ 3, 60, 1
+ ], [
+ 'foo', 'bar', 'baz'
+ ]);
+ testStrings([
+ 3, 102, 111, 111, 0,
+ 3, 98, 97, 114, 0,
+ 3, 98, 97, 122, 0,
+ 6, 15, 11, 7, 18, 14, 10,
+ 6, 60, 1
+ ], [
+ 'foo', 'bar', 'baz', 'foo', 'bar', 'baz'
+ ]);
+ });
+ test('mixed vector', () {
+ var flx = Reference.fromBuffer(b([
+ 3, 102, 111, 111, 0, 0, 0, 0,
+ 5, 0, 0, 0, 0, 0, 0, 0,
+ 15, 0, 0, 0, 0, 0, 0, 0,
+ 1, 0, 0, 0, 0, 0, 0, 0,
+ 251, 255, 255, 255, 255, 255, 255, 255,
+ 205, 204, 204, 204, 204, 204, 244, 63,
+ 1, 0, 0, 0, 0, 0, 0, 0,
+ 20, 4, 4, 15, 104, 45, 43, 1
+ ]));
+ expect(flx.length, 5);
+ expect(flx[0].stringValue, 'foo');
+ expect(flx[1].numValue, 1);
+ expect(flx[2].numValue, -5);
+ expect(flx[3].numValue, 1.3);
+ expect(flx[4].boolValue, true);
+ });
+
+ test('single value map', () {
+ var flx = Reference.fromBuffer(b([97, 0, 1, 3, 1, 1, 1, 12, 4, 2, 36, 1]));
+ expect(flx.length, 1);
+ expect(flx['a'].numValue, 12);
+ });
+ test('two value map', () {
+ var flx = Reference.fromBuffer(b([0, 97, 0, 2, 4, 4, 2, 1, 2, 45, 12, 4, 4, 4, 36, 1]));
+ expect(flx.length, 2);
+ expect(flx['a'].numValue, 12);
+ expect(flx[''].numValue, 45);
+ });
+ test('complex map', () {
+ var flx = complexMap();
+ expect(flx.length, 5);
+ expect(flx['age'].numValue, 35);
+ expect(flx['weight'].numValue, 72.5);
+ expect(flx['name'].stringValue, 'Maxim');
+
+ expect(flx['flags'].length, 4);
+ expect(flx['flags'][0].boolValue, true);
+ expect(flx['flags'][1].boolValue, false);
+ expect(flx['flags'][2].boolValue, true);
+ expect(flx['flags'][3].boolValue, true);
+
+ expect(flx['address'].length, 3);
+ expect(flx['address']['city'].stringValue, 'Bla');
+ expect(flx['address']['zip'].stringValue, '12345');
+ expect(flx['address']['countryCode'].stringValue, 'XX');
+
+ expect(() => flx['address']['country'].stringValue,
+ throwsA(predicate((e) => e is ArgumentError && e.message == 'Key: [country] is not applicable on: //address of: ValueType.Map')));
+ expect(() => flx['address']['countryCode'][0],
+ throwsA(predicate((e) => e is ArgumentError && e.message == 'Key: [0] is not applicable on: //address/countryCode of: ValueType.String')));
+ expect(() => flx[1],
+ throwsA(predicate((e) => e is ArgumentError && e.message == 'Key: [1] is not applicable on: / of: ValueType.Map')));
+ expect(() => flx['flags'][4],
+ throwsA(predicate((e) => e is ArgumentError && e.message == 'Key: [4] is not applicable on: //flags of: ValueType.VectorBool length: 4')));
+ expect(() => flx['flags'][-1],
+ throwsA(predicate((e) => e is ArgumentError && e.message == 'Key: [-1] is not applicable on: //flags of: ValueType.VectorBool length: 4')));
+ });
+ test('complex map to json', () {
+ var flx = complexMap();
+ expect(flx.json, '{"address":{"city":"Bla","countryCode":"XX","zip":"12345"},"age":35,"flags":[true,false,true,true],"name":"Maxim","weight":72.5}');
+ });
+
+ test('complex map iterators', () {
+ var flx = complexMap();
+ expect(flx.mapKeyIterable.map((e) => e).toList(), ['address', 'age', 'flags', 'name', 'weight']);
+ expect(flx.mapValueIterable.map((e) => e.json).toList(), [flx['address'].json, flx['age'].json, flx['flags'].json, flx['name'].json, flx['weight'].json]);
+ expect(flx['flags'].vectorIterable.map((e) => e.boolValue).toList(), [true, false, true, true]);
+ });
+
+ test('bug where offest were stored as int instead of uint', (){
+ const data = [99, 104, 97, 110, 110, 101, 108, 115, 95, 105, 110, 0,
+ 100, 105, 108, 97, 116, 105, 111, 110, 95, 104, 101, 105, 103, 104, 116, 95, 102, 97, 99, 116, 111, 114, 0,
+ 100, 105, 108, 97, 116, 105, 111, 110, 95, 119, 105, 100, 116, 104, 95, 102, 97, 99, 116, 111, 114, 0,
+ 102, 117, 115, 101, 100, 95, 97, 99, 116, 105, 118, 97, 116, 105, 111, 110, 95, 102, 117, 110, 99, 116, 105, 111, 110, 0,
+ 112, 97, 100, 95, 118, 97, 108, 117, 101, 115, 0, 112, 97, 100, 100, 105, 110, 103, 0,
+ 115, 116, 114, 105, 100, 101, 95, 104, 101, 105, 103, 104, 116, 0,
+ 115, 116, 114, 105, 100, 101, 95, 119, 105, 100, 116, 104, 0,
+ 8, 130, 119, 97, 76, 51, 41, 34, 21, 8, 1, 8, 64, 1, 1, 1, 1, 0, 1, 1, 4, 4, 4, 4, 4, 4, 4, 4, 16, 36, 1];
+ var flx = Reference.fromBuffer(b(data));
+ expect(flx.json, '{"channels_in":64,"dilation_height_factor":1,"dilation_width_factor":1,"fused_activation_function":1,"pad_values":1,"padding":0,"stride_height":1,"stride_width":1}');
+ const object = {"channels_in":64,"dilation_height_factor":1,"dilation_width_factor":1,"fused_activation_function":1,"pad_values":1,"padding":0,"stride_height":1,"stride_width":1};
+ var data1 = Builder.buildFromObject(object).asUint8List();
+ expect(data1.length, data.length);
+ var flx1 = Reference.fromBuffer(b(data1));
+ expect(flx1.json, '{"channels_in":64,"dilation_height_factor":1,"dilation_width_factor":1,"fused_activation_function":1,"pad_values":1,"padding":0,"stride_height":1,"stride_width":1}');
+ });
+}
+
+ByteBuffer b(List<int> values) {
+ var data = Uint8List.fromList(values);
+ return data.buffer;
+}
+
+void testNumbers(List<int> buffer, List<num> numbers) {
+ var flx = Reference.fromBuffer(b(buffer));
+ expect(flx.length, numbers.length);
+ for (var i = 0; i < flx.length; i++) {
+ expect(flx[i].numValue, closeTo(numbers[i], 0.001));
+ }
+}
+
+void testStrings(List<int> buffer, List<String> numbers) {
+ var flx = Reference.fromBuffer(b(buffer));
+ expect(flx.length, numbers.length);
+ for (var i = 0; i < flx.length; i++) {
+ expect(flx[i].stringValue, numbers[i]);
+ }
+}
+
+Reference complexMap(){
+// {
+// "age": 35,
+// "flags": [True, False, True, True],
+// "weight": 72.5,
+// "name": "Maxim",
+// "address": {
+// "city": "Bla",
+// "zip": "12345",
+// "countryCode": "XX",
+// }
+// }
+ return Reference.fromBuffer(b([
+ 97, 100, 100, 114, 101, 115, 115, 0,
+ 99, 105, 116, 121, 0, 3, 66, 108, 97, 0,
+ 99, 111, 117, 110, 116, 114, 121, 67, 111, 100, 101, 0,
+ 2, 88, 88, 0,
+ 122, 105, 112, 0,
+ 5, 49, 50, 51, 52, 53, 0,
+ 3, 38, 29, 14, 3, 1, 3, 38, 22, 15, 20, 20, 20,
+ 97, 103, 101, 0,
+ 102, 108, 97, 103, 115, 0,
+ 4, 1, 0, 1, 1,
+ 110, 97, 109, 101, 0,
+ 5, 77, 97, 120, 105, 109, 0,
+ 119, 101, 105, 103, 104, 116, 0,
+ 5, 93, 36, 33, 23, 12, 0, 0, 7, 0, 0, 0, 1, 0, 0, 0, 5, 0, 0, 0, 60, 0, 0, 0, 35, 0, 0, 0, 51, 0, 0, 0, 45,
+ 0, 0, 0, 0, 0, 145, 66, 36, 4, 144, 20, 14, 25, 38, 1
+ ]));
+}
diff --git a/dart/test/flex_types_test.dart b/dart/test/flex_types_test.dart
new file mode 100644
index 0000000..16235f6
--- /dev/null
+++ b/dart/test/flex_types_test.dart
@@ -0,0 +1,137 @@
+import 'package:flat_buffers/src/types.dart';
+import 'package:test/test.dart';
+
+void main() {
+ test('is inline', () {
+ expect(ValueTypeUtils.isInline(ValueType.Bool), isTrue);
+ expect(ValueTypeUtils.isInline(ValueType.Int), isTrue);
+ expect(ValueTypeUtils.isInline(ValueType.UInt), isTrue);
+ expect(ValueTypeUtils.isInline(ValueType.Float), isTrue);
+ expect(ValueTypeUtils.isInline(ValueType.Null), isTrue);
+ expect(ValueTypeUtils.isInline(ValueType.String), isFalse);
+ });
+ test('is type vector element', () {
+ expect(ValueTypeUtils.isTypedVectorElement(ValueType.Bool), isTrue);
+ expect(ValueTypeUtils.isTypedVectorElement(ValueType.Int), isTrue);
+ expect(ValueTypeUtils.isTypedVectorElement(ValueType.UInt), isTrue);
+ expect(ValueTypeUtils.isTypedVectorElement(ValueType.Float), isTrue);
+ expect(ValueTypeUtils.isTypedVectorElement(ValueType.Key), isTrue);
+ expect(ValueTypeUtils.isTypedVectorElement(ValueType.String), isTrue);
+
+ expect(ValueTypeUtils.isTypedVectorElement(ValueType.Null), isFalse);
+ expect(ValueTypeUtils.isTypedVectorElement(ValueType.Blob), isFalse);
+ });
+ test('is typed vector', () {
+ expect(ValueTypeUtils.isTypedVector(ValueType.VectorInt), isTrue);
+ expect(ValueTypeUtils.isTypedVector(ValueType.VectorUInt), isTrue);
+ expect(ValueTypeUtils.isTypedVector(ValueType.VectorFloat), isTrue);
+ expect(ValueTypeUtils.isTypedVector(ValueType.VectorBool), isTrue);
+ expect(ValueTypeUtils.isTypedVector(ValueType.VectorKey), isTrue);
+ expect(ValueTypeUtils.isTypedVector(ValueType.VectorString), isTrue);
+
+ expect(ValueTypeUtils.isTypedVector(ValueType.Vector), isFalse);
+ expect(ValueTypeUtils.isTypedVector(ValueType.Map), isFalse);
+ expect(ValueTypeUtils.isTypedVector(ValueType.Bool), isFalse);
+ expect(ValueTypeUtils.isTypedVector(ValueType.VectorInt2), isFalse);
+ });
+ test('is fixed typed vector', () {
+ expect(ValueTypeUtils.isFixedTypedVector(ValueType.VectorInt2), isTrue);
+ expect(ValueTypeUtils.isFixedTypedVector(ValueType.VectorInt3), isTrue);
+ expect(ValueTypeUtils.isFixedTypedVector(ValueType.VectorInt4), isTrue);
+ expect(ValueTypeUtils.isFixedTypedVector(ValueType.VectorUInt2), isTrue);
+ expect(ValueTypeUtils.isFixedTypedVector(ValueType.VectorUInt3), isTrue);
+ expect(ValueTypeUtils.isFixedTypedVector(ValueType.VectorUInt4), isTrue);
+ expect(ValueTypeUtils.isFixedTypedVector(ValueType.VectorFloat2), isTrue);
+ expect(ValueTypeUtils.isFixedTypedVector(ValueType.VectorFloat3), isTrue);
+ expect(ValueTypeUtils.isFixedTypedVector(ValueType.VectorFloat4), isTrue);
+
+ expect(ValueTypeUtils.isFixedTypedVector(ValueType.VectorInt), isFalse);
+ });
+ test('to typed vector', () {
+ expect(ValueTypeUtils.toTypedVector(ValueType.Int,0), equals(ValueType.VectorInt));
+ expect(ValueTypeUtils.toTypedVector(ValueType.UInt,0), equals(ValueType.VectorUInt));
+ expect(ValueTypeUtils.toTypedVector(ValueType.Bool,0), equals(ValueType.VectorBool));
+ expect(ValueTypeUtils.toTypedVector(ValueType.Float,0), equals(ValueType.VectorFloat));
+ expect(ValueTypeUtils.toTypedVector(ValueType.Key,0), equals(ValueType.VectorKey));
+ expect(ValueTypeUtils.toTypedVector(ValueType.String,0), equals(ValueType.VectorString));
+
+ expect(ValueTypeUtils.toTypedVector(ValueType.Int,2), equals(ValueType.VectorInt2));
+ expect(ValueTypeUtils.toTypedVector(ValueType.UInt,2), equals(ValueType.VectorUInt2));
+ expect(ValueTypeUtils.toTypedVector(ValueType.Float,2), equals(ValueType.VectorFloat2));
+
+ expect(ValueTypeUtils.toTypedVector(ValueType.Int,3), equals(ValueType.VectorInt3));
+ expect(ValueTypeUtils.toTypedVector(ValueType.UInt,3), equals(ValueType.VectorUInt3));
+ expect(ValueTypeUtils.toTypedVector(ValueType.Float,3), equals(ValueType.VectorFloat3));
+
+ expect(ValueTypeUtils.toTypedVector(ValueType.Int,4), equals(ValueType.VectorInt4));
+ expect(ValueTypeUtils.toTypedVector(ValueType.UInt,4), equals(ValueType.VectorUInt4));
+ expect(ValueTypeUtils.toTypedVector(ValueType.Float,4), equals(ValueType.VectorFloat4));
+ });
+ test('typed vector element type', () {
+ expect(ValueTypeUtils.typedVectorElementType(ValueType.VectorInt), equals(ValueType.Int));
+ expect(ValueTypeUtils.typedVectorElementType(ValueType.VectorUInt), equals(ValueType.UInt));
+ expect(ValueTypeUtils.typedVectorElementType(ValueType.VectorFloat), equals(ValueType.Float));
+ expect(ValueTypeUtils.typedVectorElementType(ValueType.VectorString), equals(ValueType.String));
+ expect(ValueTypeUtils.typedVectorElementType(ValueType.VectorKey), equals(ValueType.Key));
+ expect(ValueTypeUtils.typedVectorElementType(ValueType.VectorBool), equals(ValueType.Bool));
+ });
+ test('fixed typed vector element type', () {
+ expect(ValueTypeUtils.fixedTypedVectorElementType(ValueType.VectorInt2), equals(ValueType.Int));
+ expect(ValueTypeUtils.fixedTypedVectorElementType(ValueType.VectorInt3), equals(ValueType.Int));
+ expect(ValueTypeUtils.fixedTypedVectorElementType(ValueType.VectorInt4), equals(ValueType.Int));
+
+ expect(ValueTypeUtils.fixedTypedVectorElementType(ValueType.VectorUInt2), equals(ValueType.UInt));
+ expect(ValueTypeUtils.fixedTypedVectorElementType(ValueType.VectorUInt3), equals(ValueType.UInt));
+ expect(ValueTypeUtils.fixedTypedVectorElementType(ValueType.VectorUInt4), equals(ValueType.UInt));
+
+ expect(ValueTypeUtils.fixedTypedVectorElementType(ValueType.VectorFloat2), equals(ValueType.Float));
+ expect(ValueTypeUtils.fixedTypedVectorElementType(ValueType.VectorFloat3), equals(ValueType.Float));
+ expect(ValueTypeUtils.fixedTypedVectorElementType(ValueType.VectorFloat4), equals(ValueType.Float));
+ });
+ test('fixed typed vector element size', () {
+ expect(ValueTypeUtils.fixedTypedVectorElementSize(ValueType.VectorInt2), equals(2));
+ expect(ValueTypeUtils.fixedTypedVectorElementSize(ValueType.VectorInt3), equals(3));
+ expect(ValueTypeUtils.fixedTypedVectorElementSize(ValueType.VectorInt4), equals(4));
+
+ expect(ValueTypeUtils.fixedTypedVectorElementSize(ValueType.VectorUInt2), equals(2));
+ expect(ValueTypeUtils.fixedTypedVectorElementSize(ValueType.VectorUInt3), equals(3));
+ expect(ValueTypeUtils.fixedTypedVectorElementSize(ValueType.VectorUInt4), equals(4));
+
+ expect(ValueTypeUtils.fixedTypedVectorElementSize(ValueType.VectorFloat2), equals(2));
+ expect(ValueTypeUtils.fixedTypedVectorElementSize(ValueType.VectorFloat3), equals(3));
+ expect(ValueTypeUtils.fixedTypedVectorElementSize(ValueType.VectorFloat4), equals(4));
+ });
+ test('packed type', () {
+ expect(ValueTypeUtils.packedType(ValueType.Null, BitWidth.width8), equals(0));
+ expect(ValueTypeUtils.packedType(ValueType.Null, BitWidth.width16), equals(1));
+ expect(ValueTypeUtils.packedType(ValueType.Null, BitWidth.width32), equals(2));
+ expect(ValueTypeUtils.packedType(ValueType.Null, BitWidth.width64), equals(3));
+
+ expect(ValueTypeUtils.packedType(ValueType.Int, BitWidth.width8), equals(4));
+ expect(ValueTypeUtils.packedType(ValueType.Int, BitWidth.width16), equals(5));
+ expect(ValueTypeUtils.packedType(ValueType.Int, BitWidth.width32), equals(6));
+ expect(ValueTypeUtils.packedType(ValueType.Int, BitWidth.width64), equals(7));
+ });
+ test('bit width', () {
+ expect(BitWidthUtil.width(0), BitWidth.width8);
+ expect(BitWidthUtil.width(-20), BitWidth.width8);
+ expect(BitWidthUtil.width(127), BitWidth.width8);
+ expect(BitWidthUtil.width(128), BitWidth.width16);
+ expect(BitWidthUtil.width(128123), BitWidth.width32);
+ expect(BitWidthUtil.width(12812324534), BitWidth.width64);
+ expect(BitWidthUtil.width(-127), BitWidth.width8);
+ expect(BitWidthUtil.width(-128), BitWidth.width16);
+ expect(BitWidthUtil.width(-12812324534), BitWidth.width64);
+ expect(BitWidthUtil.width(-0.1), BitWidth.width64);
+ expect(BitWidthUtil.width(0.25), BitWidth.width32);
+ });
+ test('padding size', () {
+ expect(BitWidthUtil.paddingSize(10, 8), 6);
+ expect(BitWidthUtil.paddingSize(10, 4), 2);
+ expect(BitWidthUtil.paddingSize(15, 4), 1);
+ expect(BitWidthUtil.paddingSize(15, 2), 1);
+ expect(BitWidthUtil.paddingSize(15, 1), 0);
+ expect(BitWidthUtil.paddingSize(16, 8), 0);
+ expect(BitWidthUtil.paddingSize(17, 8), 7);
+ });
+}
diff --git a/dart/test/monster_test_my_game.example2_generated.dart b/dart/test/monster_test_my_game.example2_generated.dart
index 9a3ab66..eed14bc 100644
--- a/dart/test/monster_test_my_game.example2_generated.dart
+++ b/dart/test/monster_test_my_game.example2_generated.dart
@@ -6,8 +6,6 @@
import 'dart:typed_data' show Uint8List;
import 'package:flat_buffers/flat_buffers.dart' as fb;
-import 'include_test1_my_game.example2_generated.dart';
-import 'include_test2_my_game.example2_generated.dart';
import './monster_test_my_game_generated.dart' as my_game;
import './monster_test_my_game.example_generated.dart' as my_game_example;
diff --git a/dart/test/monster_test_my_game.example_generated.dart b/dart/test/monster_test_my_game.example_generated.dart
index 49e2ec1..7921892 100644
--- a/dart/test/monster_test_my_game.example_generated.dart
+++ b/dart/test/monster_test_my_game.example_generated.dart
@@ -6,11 +6,10 @@
import 'dart:typed_data' show Uint8List;
import 'package:flat_buffers/flat_buffers.dart' as fb;
-import 'include_test1_my_game.example_generated.dart';
-import 'include_test2_my_game.example_generated.dart';
import './monster_test_my_game_generated.dart' as my_game;
import './monster_test_my_game.example2_generated.dart' as my_game_example2;
+/// Composite components of Monster color.
class Color {
final int value;
const Color._(this.value);
@@ -26,9 +25,14 @@
static bool containsValue(int value) => values.containsKey(value);
static const Color Red = const Color._(1);
+
+ /// \brief color Green
+ /// Green is bit_flag with value (1u << 1)
static const Color Green = const Color._(2);
+
+ /// \brief color Blue (1u << 3)
static const Color Blue = const Color._(8);
- static get values => {1: Red,2: Green,8: Blue,};
+ static const values = {1: Red,2: Green,8: Blue,};
static const fb.Reader<Color> reader = const _ColorReader();
@@ -46,7 +50,48 @@
@override
Color read(fb.BufferContext bc, int offset) =>
- new Color.fromValue(const fb.Int8Reader().read(bc, offset));
+ new Color.fromValue(const fb.Uint8Reader().read(bc, offset));
+}
+
+class Race {
+ final int value;
+ const Race._(this.value);
+
+ factory Race.fromValue(int value) {
+ if (value == null) value = 0;
+ if (!values.containsKey(value)) {
+ throw new StateError('Invalid value $value for bit flag enum Race');
+ }
+ return values[value];
+ }
+
+ static const int minValue = -1;
+ static const int maxValue = 2;
+ static bool containsValue(int value) => values.containsKey(value);
+
+ static const Race None = const Race._(-1);
+ static const Race Human = const Race._(0);
+ static const Race Dwarf = const Race._(1);
+ static const Race Elf = const Race._(2);
+ static const values = {-1: None,0: Human,1: Dwarf,2: Elf,};
+
+ static const fb.Reader<Race> reader = const _RaceReader();
+
+ @override
+ String toString() {
+ return 'Race{value: $value}';
+ }
+}
+
+class _RaceReader extends fb.Reader<Race> {
+ const _RaceReader();
+
+ @override
+ int get size => 1;
+
+ @override
+ Race read(fb.BufferContext bc, int offset) =>
+ new Race.fromValue(const fb.Int8Reader().read(bc, offset));
}
class AnyTypeId {
@@ -69,7 +114,7 @@
static const AnyTypeId Monster = const AnyTypeId._(1);
static const AnyTypeId TestSimpleTableWithEnum = const AnyTypeId._(2);
static const AnyTypeId MyGame_Example2_Monster = const AnyTypeId._(3);
- static get values => {0: NONE,1: Monster,2: TestSimpleTableWithEnum,3: MyGame_Example2_Monster,};
+ static const values = {0: NONE,1: Monster,2: TestSimpleTableWithEnum,3: MyGame_Example2_Monster,};
static const fb.Reader<AnyTypeId> reader = const _AnyTypeIdReader();
@@ -108,9 +153,9 @@
static const AnyUniqueAliasesTypeId NONE = const AnyUniqueAliasesTypeId._(0);
static const AnyUniqueAliasesTypeId M = const AnyUniqueAliasesTypeId._(1);
- static const AnyUniqueAliasesTypeId T = const AnyUniqueAliasesTypeId._(2);
+ static const AnyUniqueAliasesTypeId TS = const AnyUniqueAliasesTypeId._(2);
static const AnyUniqueAliasesTypeId M2 = const AnyUniqueAliasesTypeId._(3);
- static get values => {0: NONE,1: M,2: T,3: M2,};
+ static const values = {0: NONE,1: M,2: TS,3: M2,};
static const fb.Reader<AnyUniqueAliasesTypeId> reader = const _AnyUniqueAliasesTypeIdReader();
@@ -151,7 +196,7 @@
static const AnyAmbiguousAliasesTypeId M1 = const AnyAmbiguousAliasesTypeId._(1);
static const AnyAmbiguousAliasesTypeId M2 = const AnyAmbiguousAliasesTypeId._(2);
static const AnyAmbiguousAliasesTypeId M3 = const AnyAmbiguousAliasesTypeId._(3);
- static get values => {0: NONE,1: M1,2: M2,3: M3,};
+ static const values = {0: NONE,1: M1,2: M2,3: M3,};
static const fb.Reader<AnyAmbiguousAliasesTypeId> reader = const _AnyAmbiguousAliasesTypeIdReader();
@@ -259,7 +304,7 @@
final fb.BufferContext _bc;
final int _bcOffset;
- Color get color => new Color.fromValue(const fb.Int8Reader().vTableGet(_bc, _bcOffset, 4, 2));
+ Color get color => new Color.fromValue(const fb.Uint8Reader().vTableGet(_bc, _bcOffset, 4, 2));
@override
String toString() {
@@ -287,7 +332,7 @@
}
int addColor(Color color) {
- fbBuilder.addInt8(0, color?.value);
+ fbBuilder.addUint8(0, color?.value);
return fbBuilder.offset;
}
@@ -311,7 +356,7 @@
assert(fbBuilder != null);
fbBuilder.startTable();
- fbBuilder.addInt8(0, _color?.value);
+ fbBuilder.addUint8(0, _color?.value);
return fbBuilder.endTable();
}
@@ -335,7 +380,7 @@
double get y => const fb.Float32Reader().read(_bc, _bcOffset + 4);
double get z => const fb.Float32Reader().read(_bc, _bcOffset + 8);
double get test1 => const fb.Float64Reader().read(_bc, _bcOffset + 16);
- Color get test2 => new Color.fromValue(const fb.Int8Reader().read(_bc, _bcOffset + 24));
+ Color get test2 => new Color.fromValue(const fb.Uint8Reader().read(_bc, _bcOffset + 24));
Test get test3 => Test.reader.read(_bc, _bcOffset + 26);
@override
@@ -366,7 +411,7 @@
fbBuilder.pad(2);
test3();
fbBuilder.pad(1);
- fbBuilder.putInt8(test2?.value);
+ fbBuilder.putUint8(test2?.value);
fbBuilder.putFloat64(test1);
fbBuilder.pad(4);
fbBuilder.putFloat32(z);
@@ -409,7 +454,7 @@
fbBuilder.pad(2);
_test3.finish(fbBuilder);
fbBuilder.pad(1);
- fbBuilder.putInt8(_test2?.value);
+ fbBuilder.putUint8(_test2?.value);
fbBuilder.putFloat64(_test1);
fbBuilder.pad(4);
fbBuilder.putFloat32(_z);
@@ -672,7 +717,7 @@
return fbBuilder.finish(offset, fileIdentifier);
}
}
-/// an example documentation comment: monster object
+/// an example documentation comment: "monster object"
class Monster {
Monster._(this._bc, this._bcOffset);
factory Monster(List<int> bytes) {
@@ -690,7 +735,7 @@
int get hp => const fb.Int16Reader().vTableGet(_bc, _bcOffset, 8, 100);
String get name => const fb.StringReader().vTableGet(_bc, _bcOffset, 10, null);
List<int> get inventory => const fb.ListReader<int>(const fb.Uint8Reader()).vTableGet(_bc, _bcOffset, 14, null);
- Color get color => new Color.fromValue(const fb.Int8Reader().vTableGet(_bc, _bcOffset, 16, 8));
+ Color get color => new Color.fromValue(const fb.Uint8Reader().vTableGet(_bc, _bcOffset, 16, 8));
AnyTypeId get testType => new AnyTypeId.fromValue(const fb.Uint8Reader().vTableGet(_bc, _bcOffset, 18, 0));
dynamic get test {
switch (testType?.value) {
@@ -702,8 +747,8 @@
}
List<Test> get test4 => const fb.ListReader<Test>(Test.reader).vTableGet(_bc, _bcOffset, 22, null);
List<String> get testarrayofstring => const fb.ListReader<String>(const fb.StringReader()).vTableGet(_bc, _bcOffset, 24, null);
-/// an example documentation comment: this will end up in the generated code
-/// multiline too
+ /// an example documentation comment: this will end up in the generated code
+ /// multiline too
List<Monster> get testarrayoftables => const fb.ListReader<Monster>(Monster.reader).vTableGet(_bc, _bcOffset, 26, null);
Monster get enemy => Monster.reader.vTableGet(_bc, _bcOffset, 28, null);
List<int> get testnestedflatbuffer => const fb.ListReader<int>(const fb.Uint8Reader()).vTableGet(_bc, _bcOffset, 30, null);
@@ -739,26 +784,27 @@
AnyUniqueAliasesTypeId get anyUniqueType => new AnyUniqueAliasesTypeId.fromValue(const fb.Uint8Reader().vTableGet(_bc, _bcOffset, 90, 0));
dynamic get anyUnique {
switch (anyUniqueType?.value) {
- case 1: return M.reader.vTableGet(_bc, _bcOffset, 92, null);
- case 2: return T.reader.vTableGet(_bc, _bcOffset, 92, null);
- case 3: return M2.reader.vTableGet(_bc, _bcOffset, 92, null);
+ case 1: return Monster.reader.vTableGet(_bc, _bcOffset, 92, null);
+ case 2: return TestSimpleTableWithEnum.reader.vTableGet(_bc, _bcOffset, 92, null);
+ case 3: return my_game_example2.Monster.reader.vTableGet(_bc, _bcOffset, 92, null);
default: return null;
}
}
AnyAmbiguousAliasesTypeId get anyAmbiguousType => new AnyAmbiguousAliasesTypeId.fromValue(const fb.Uint8Reader().vTableGet(_bc, _bcOffset, 94, 0));
dynamic get anyAmbiguous {
switch (anyAmbiguousType?.value) {
- case 1: return M1.reader.vTableGet(_bc, _bcOffset, 96, null);
- case 2: return M2.reader.vTableGet(_bc, _bcOffset, 96, null);
- case 3: return M3.reader.vTableGet(_bc, _bcOffset, 96, null);
+ case 1: return Monster.reader.vTableGet(_bc, _bcOffset, 96, null);
+ case 2: return Monster.reader.vTableGet(_bc, _bcOffset, 96, null);
+ case 3: return Monster.reader.vTableGet(_bc, _bcOffset, 96, null);
default: return null;
}
}
List<Color> get vectorOfEnums => const fb.ListReader<Color>(Color.reader).vTableGet(_bc, _bcOffset, 98, null);
+ Race get signedEnum => new Race.fromValue(const fb.Int8Reader().vTableGet(_bc, _bcOffset, 100, -1));
@override
String toString() {
- return 'Monster{pos: $pos, mana: $mana, hp: $hp, name: $name, inventory: $inventory, color: $color, testType: $testType, test: $test, test4: $test4, testarrayofstring: $testarrayofstring, testarrayoftables: $testarrayoftables, enemy: $enemy, testnestedflatbuffer: $testnestedflatbuffer, testempty: $testempty, testbool: $testbool, testhashs32Fnv1: $testhashs32Fnv1, testhashu32Fnv1: $testhashu32Fnv1, testhashs64Fnv1: $testhashs64Fnv1, testhashu64Fnv1: $testhashu64Fnv1, testhashs32Fnv1a: $testhashs32Fnv1a, testhashu32Fnv1a: $testhashu32Fnv1a, testhashs64Fnv1a: $testhashs64Fnv1a, testhashu64Fnv1a: $testhashu64Fnv1a, testarrayofbools: $testarrayofbools, testf: $testf, testf2: $testf2, testf3: $testf3, testarrayofstring2: $testarrayofstring2, testarrayofsortedstruct: $testarrayofsortedstruct, flex: $flex, test5: $test5, vectorOfLongs: $vectorOfLongs, vectorOfDoubles: $vectorOfDoubles, parentNamespaceTest: $parentNamespaceTest, vectorOfReferrables: $vectorOfReferrables, singleWeakReference: $singleWeakReference, vectorOfWeakReferences: $vectorOfWeakReferences, vectorOfStrongReferrables: $vectorOfStrongReferrables, coOwningReference: $coOwningReference, vectorOfCoOwningReferences: $vectorOfCoOwningReferences, nonOwningReference: $nonOwningReference, vectorOfNonOwningReferences: $vectorOfNonOwningReferences, anyUniqueType: $anyUniqueType, anyUnique: $anyUnique, anyAmbiguousType: $anyAmbiguousType, anyAmbiguous: $anyAmbiguous, vectorOfEnums: $vectorOfEnums}';
+ return 'Monster{pos: $pos, mana: $mana, hp: $hp, name: $name, inventory: $inventory, color: $color, testType: $testType, test: $test, test4: $test4, testarrayofstring: $testarrayofstring, testarrayoftables: $testarrayoftables, enemy: $enemy, testnestedflatbuffer: $testnestedflatbuffer, testempty: $testempty, testbool: $testbool, testhashs32Fnv1: $testhashs32Fnv1, testhashu32Fnv1: $testhashu32Fnv1, testhashs64Fnv1: $testhashs64Fnv1, testhashu64Fnv1: $testhashu64Fnv1, testhashs32Fnv1a: $testhashs32Fnv1a, testhashu32Fnv1a: $testhashu32Fnv1a, testhashs64Fnv1a: $testhashs64Fnv1a, testhashu64Fnv1a: $testhashu64Fnv1a, testarrayofbools: $testarrayofbools, testf: $testf, testf2: $testf2, testf3: $testf3, testarrayofstring2: $testarrayofstring2, testarrayofsortedstruct: $testarrayofsortedstruct, flex: $flex, test5: $test5, vectorOfLongs: $vectorOfLongs, vectorOfDoubles: $vectorOfDoubles, parentNamespaceTest: $parentNamespaceTest, vectorOfReferrables: $vectorOfReferrables, singleWeakReference: $singleWeakReference, vectorOfWeakReferences: $vectorOfWeakReferences, vectorOfStrongReferrables: $vectorOfStrongReferrables, coOwningReference: $coOwningReference, vectorOfCoOwningReferences: $vectorOfCoOwningReferences, nonOwningReference: $nonOwningReference, vectorOfNonOwningReferences: $vectorOfNonOwningReferences, anyUniqueType: $anyUniqueType, anyUnique: $anyUnique, anyAmbiguousType: $anyAmbiguousType, anyAmbiguous: $anyAmbiguous, vectorOfEnums: $vectorOfEnums, signedEnum: $signedEnum}';
}
}
@@ -802,7 +848,7 @@
return fbBuilder.offset;
}
int addColor(Color color) {
- fbBuilder.addInt8(6, color?.value);
+ fbBuilder.addUint8(6, color?.value);
return fbBuilder.offset;
}
int addTestType(AnyTypeId testType) {
@@ -969,6 +1015,10 @@
fbBuilder.addOffset(47, offset);
return fbBuilder.offset;
}
+ int addSignedEnum(Race signedEnum) {
+ fbBuilder.addInt8(48, signedEnum?.value);
+ return fbBuilder.offset;
+ }
int finish() {
return fbBuilder.endTable();
@@ -1023,6 +1073,7 @@
final AnyAmbiguousAliasesTypeId _anyAmbiguousType;
final dynamic _anyAmbiguous;
final List<Color> _vectorOfEnums;
+ final Race _signedEnum;
MonsterObjectBuilder({
Vec3ObjectBuilder pos,
@@ -1072,6 +1123,7 @@
AnyAmbiguousAliasesTypeId anyAmbiguousType,
dynamic anyAmbiguous,
List<Color> vectorOfEnums,
+ Race signedEnum,
})
: _pos = pos,
_mana = mana,
@@ -1119,7 +1171,8 @@
_anyUnique = anyUnique,
_anyAmbiguousType = anyAmbiguousType,
_anyAmbiguous = anyAmbiguous,
- _vectorOfEnums = vectorOfEnums;
+ _vectorOfEnums = vectorOfEnums,
+ _signedEnum = signedEnum;
/// Finish building, and store into the [fbBuilder].
@override
@@ -1185,7 +1238,7 @@
final int anyUniqueOffset = _anyUnique?.getOrCreateOffset(fbBuilder);
final int anyAmbiguousOffset = _anyAmbiguous?.getOrCreateOffset(fbBuilder);
final int vectorOfEnumsOffset = _vectorOfEnums?.isNotEmpty == true
- ? fbBuilder.writeListInt8(_vectorOfEnums.map((f) => f.value))
+ ? fbBuilder.writeListUint8(_vectorOfEnums.map((f) => f.value))
: null;
fbBuilder.startTable();
@@ -1200,7 +1253,7 @@
if (inventoryOffset != null) {
fbBuilder.addOffset(5, inventoryOffset);
}
- fbBuilder.addInt8(6, _color?.value);
+ fbBuilder.addUint8(6, _color?.value);
fbBuilder.addUint8(7, _testType?.value);
if (testOffset != null) {
fbBuilder.addOffset(8, testOffset);
@@ -1288,6 +1341,7 @@
if (vectorOfEnumsOffset != null) {
fbBuilder.addOffset(47, vectorOfEnumsOffset);
}
+ fbBuilder.addInt8(48, _signedEnum?.value);
return fbBuilder.endTable();
}
diff --git a/dart/test/monster_test_my_game_generated.dart b/dart/test/monster_test_my_game_generated.dart
index 26bb73b..abd538c 100644
--- a/dart/test/monster_test_my_game_generated.dart
+++ b/dart/test/monster_test_my_game_generated.dart
@@ -6,8 +6,6 @@
import 'dart:typed_data' show Uint8List;
import 'package:flat_buffers/flat_buffers.dart' as fb;
-import 'include_test1_my_game_generated.dart';
-import 'include_test2_my_game_generated.dart';
import './monster_test_my_game.example_generated.dart' as my_game_example;
import './monster_test_my_game.example2_generated.dart' as my_game_example2;