aboutsummaryrefslogtreecommitdiff
path: root/docs/source
diff options
context:
space:
mode:
authorAurimas Liutikas <aurimas@google.com>2020-03-16 21:08:19 +0000
committerAurimas Liutikas <aurimas@google.com>2020-03-16 21:08:19 +0000
commit420a0a2f2f9474aa5aaa0a877985401539edf1c9 (patch)
tree18b7abd8d5b485390ea5899f83a93844ecb93d7e /docs/source
parent18dd209e73277d8ec59241c11ddb7dc43c314c61 (diff)
downloadflatbuffers-420a0a2f2f9474aa5aaa0a877985401539edf1c9.tar.gz
Revert "Upgrade flatbuffers to v1.12.0"android-r-preview-4android-r-preview-3android-r-preview-2
Revert "Fix the API for new flatbuffer" Revert submission 1258647-flatbuffer Reason for revert: It broke ab/androidx-master-dev Reverted Changes: Ia8bdf90e3:Fix the API for new flatbuffer Iae8aa73e8:Upgrade flatbuffers to v1.12.0 Change-Id: I68ed60bbe33742dea85c8a704b21f37414576445
Diffstat (limited to 'docs/source')
-rw-r--r--docs/source/Building.md13
-rw-r--r--docs/source/Compiler.md25
-rw-r--r--docs/source/CppUsage.md64
-rw-r--r--docs/source/CsharpUsage.md175
-rw-r--r--docs/source/FlatBuffers.md18
-rw-r--r--docs/source/FlexBuffers.md52
-rw-r--r--docs/source/Internals.md6
-rw-r--r--docs/source/JavaCsharpUsage.md (renamed from docs/source/JavaUsage.md)86
-rw-r--r--docs/source/KotlinUsage.md84
-rw-r--r--docs/source/Schemas.md37
-rw-r--r--docs/source/Support.md36
-rw-r--r--docs/source/SwiftUsage.md91
-rw-r--r--docs/source/Tutorial.md497
-rw-r--r--docs/source/TypeScriptUsage.md2
-rw-r--r--docs/source/doxyfile2
-rw-r--r--docs/source/doxygen_layout.xml8
16 files changed, 162 insertions, 1034 deletions
diff --git a/docs/source/Building.md b/docs/source/Building.md
index ad9e972b..a8967110 100644
--- a/docs/source/Building.md
+++ b/docs/source/Building.md
@@ -29,19 +29,6 @@ Building should also produce two sample executables, `flatsamplebinary` and
*Note that you MUST be in the root of the FlatBuffers distribution when you
run 'flattests' or `flatsampletext`, or it will fail to load its files.*
-## Building with VCPKG
-
-You can download and install flatbuffers using the [vcpkg](https://github.com/Microsoft/vcpkg/) dependency manager:
-
- git clone https://github.com/Microsoft/vcpkg.git
- cd vcpkg
- ./bootstrap-vcpkg.sh
- ./vcpkg integrate install
- ./vcpkg install flatbuffers
-
-The flatbuffers port in vcpkg is kept up to date by Microsoft team members and community contributors.
-If the version is out of date, please [create an issue or pull request](https://github.com/Microsoft/vcpkg) on the vcpkg repository.
-
## Building for Android
There is a `flatbuffers/android` directory that contains all you need to build
diff --git a/docs/source/Compiler.md b/docs/source/Compiler.md
index aed579ca..90f8d8b4 100644
--- a/docs/source/Compiler.md
+++ b/docs/source/Compiler.md
@@ -3,7 +3,7 @@ Using the schema compiler {#flatbuffers_guide_using_schema_compiler}
Usage:
- flatc [ GENERATOR OPTIONS ] [ -o PATH ] [ -I PATH ] FILES...
+ flatc [ GENERATOR OPTIONS ] [ -o PATH ] [ -I PATH ] [ -S ] FILES...
[ -- FILES...]
The files are read and parsed in order, and can contain either schemas
@@ -23,8 +23,6 @@ For any schema input files, one or more generators can be specified:
- `--java`, `-j` : Generate Java code.
-- `--kotlin`, `-k` : Generate Kotlin code.
-
- `--csharp`, `-n` : Generate C# code.
- `--go`, `-g` : Generate Go code.
@@ -47,8 +45,6 @@ For any schema input files, one or more generators can be specified:
- `--rust`, `-r` : Generate Rust code.
-- `--swift`: Generate Swift code.
-
For any data input files:
- `--binary`, `-b` : If data is contained in this file, generate a
@@ -96,7 +92,7 @@ Additional options:
statements) use `--no-includes.`
- `--no-includes` : Don't generate include statements for included schemas the
- generated file depends on (C++ / Python).
+ generated file depends on (C++).
- `--gen-mutable` : Generate additional non-const accessors for mutating
FlatBuffers in-place.
@@ -121,8 +117,6 @@ Additional options:
output (by default the case for C++ and JS), all code will end up in
this one file.
-- `--cpp-include` : Adds an #include in generated file
-
- `--cpp-ptr-type T` : Set object API pointer type (default std::unique_ptr)
- `--cpp-str-type T` : Set object API string type (default std::string)
@@ -134,11 +128,6 @@ Additional options:
std::string from Flatbuffers, but (char* + length). This allows efficient
construction of custom string types, including zero-copy construction.
-- `--cpp-std CPP_STD` : Generate a C++ code using features of selected C++ standard.
- Supported `CPP_STD` values:
- * `c++0x` - generate code compatible with old compilers (VS2010).
- * `c++11` - use C++11 code generator (default);
-
- `--object-prefix` : Customise class prefix for C++ object-based API.
- `--object-suffix` : Customise class suffix for C++ object-based API.
@@ -188,13 +177,6 @@ Additional options:
- `--conform-includes PATH` : Include path for the schema given with
`--conform PATH`.
-- `--filename-suffix SUFFIX` : The suffix appended to the generated
- file names. Default is '_generated'.
-
-- `--filename-ext EXTENSION` : The extension appended to the generated
- file names. Default is language-specific (e.g. "h" for C++). This
- should not be used when multiple languages are specified.
-
- `--include-prefix PATH` : Prefix this path to any generated include
statements.
@@ -217,8 +199,5 @@ Additional options:
- `--force-empty` : When serializing from object API representation, force
strings and vectors to empty rather than null.
-- `--force-empty-vectors` : When serializing from object API representation, force
- vectors to empty rather than null.
-
NOTE: short-form options for generators are deprecated, use the long form
whenever possible.
diff --git a/docs/source/CppUsage.md b/docs/source/CppUsage.md
index 6fec30c7..6cf36d1f 100644
--- a/docs/source/CppUsage.md
+++ b/docs/source/CppUsage.md
@@ -35,7 +35,7 @@ The test code itself is located in
[test.cpp](https://github.com/google/flatbuffers/blob/master/tests/test.cpp).
This test file is built alongside `flatc`. To review how to build the project,
-please read the [Building](@ref flatbuffers_guide_building) documentation.
+please read the [Building](@ref flatbuffers_guide_building) documenation.
To run the tests, execute `flattests` from the root `flatbuffers/` directory.
For example, on [Linux](https://en.wikipedia.org/wiki/Linux), you would simply
@@ -114,7 +114,7 @@ To use:
MonsterT monsterobj;
// Deserialize from buffer into object.
- GetMonster(flatbuffer)->UnPackTo(&monsterobj);
+ UnPackTo(&monsterobj, flatbuffer);
// Update object directly like a C++ class instance.
cout << monsterobj->name; // This is now a std::string!
@@ -122,7 +122,7 @@ To use:
// Serialize into new flatbuffer.
FlatBufferBuilder fbb;
- fbb.Finish(Monster::Pack(fbb, &monsterobj));
+ Pack(fbb, &monsterobj);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The following attributes are specific to the object-based API code generation:
@@ -426,8 +426,6 @@ it, this will provide you an easy way to use that data directly.
(see the schema documentation for some specifics on the JSON format
accepted).
-Schema evolution compatibility for the JSON format follows the same rules as the binary format (JSON formatted data will be forwards/backwards compatible with schemas that evolve in a compatible way).
-
There are two ways to use text formats:
#### Using the compiler as a conversion tool
@@ -479,7 +477,7 @@ include paths. If not specified, any include statements try to resolve from
the current directory.
If there were any parsing errors, `Parse` will return `false`, and
-`Parser::error_` contains a human readable error string with a line number
+`Parser::err` contains a human readable error string with a line number
etc, which you should present to the creator of that file.
After each JSON file, the `Parser::fbb` member variable is the
@@ -548,63 +546,21 @@ locale-independent or locale-narrow functions `strtof_l`, `strtod_l`,
These functions use specified locale rather than the global or per-thread
locale instead. They are part of POSIX-2008 but not part of the C/C++
standard library, therefore, may be missing on some platforms.
+
The Flatbuffers library try to detect these functions at configuration and
compile time:
-- CMake `"CMakeLists.txt"`:
- - Check existence of `strtol_l` and `strtod_l` in the `<stdlib.h>`.
-- Compile-time `"/include/base.h"`:
- - `_MSC_VER >= 1900`: MSVC2012 or higher if build with MSVC.
- - `_XOPEN_SOURCE>=700`: POSIX-2008 if build with GCC/Clang.
+- `_MSC_VER >= 1900`: check MSVC2012 or higher for MSVC buid
+- `_XOPEN_SOURCE>=700`: check POSIX-2008 for GCC/Clang build
+- `check_cxx_symbol_exists(strtof_l stdlib.h)`: CMake check of `strtod_f`
After detection, the definition `FLATBUFFERS_LOCALE_INDEPENDENT` will be
set to `0` or `1`.
-To override or stop this detection use CMake `-DFLATBUFFERS_LOCALE_INDEPENDENT={0|1}`
-or predefine `FLATBUFFERS_LOCALE_INDEPENDENT` symbol.
-To test the compatibility of the Flatbuffers library with
-a specific locale use the environment variable `FLATBUFFERS_TEST_LOCALE`:
+It is possible to test the compatibility of the Flatbuffers library with
+a specific locale using the environment variable `FLATBUFFERS_TEST_LOCALE`:
```sh
>FLATBUFFERS_TEST_LOCALE="" ./flattests
>FLATBUFFERS_TEST_LOCALE="ru_RU.CP1251" ./flattests
```
-## Support of floating-point numbers
-The Flatbuffers library assumes that a C++ compiler and a CPU are
-compatible with the `IEEE-754` floating-point standard.
-The schema and json parser may fail if `fast-math` or `/fp:fast` mode is active.
-
-### Support of hexadecimal and special floating-point numbers
-According to the [grammar](@ref flatbuffers_grammar) `fbs` and `json` files
-may use hexadecimal and special (`NaN`, `Inf`) floating-point literals.
-The Flatbuffers uses `strtof` and `strtod` functions to parse floating-point
-literals. The Flatbuffers library has a code to detect a compiler compatibility
-with the literals. If necessary conditions are met the preprocessor constant
-`FLATBUFFERS_HAS_NEW_STRTOD` will be set to `1`.
-The support of floating-point literals will be limited at compile time
-if `FLATBUFFERS_HAS_NEW_STRTOD` constant is less than `1`.
-In this case, schemas with hexadecimal or special literals cannot be used.
-
-### Comparison of floating-point NaN values
-The floating-point `NaN` (`not a number`) is special value which
-representing an undefined or unrepresentable value.
-`NaN` may be explicitly assigned to variables, typically as a representation
-for missing values or may be a result of a mathematical operation.
-The `IEEE-754` defines two kind of `NaNs`:
-- Quiet NaNs, or `qNaNs`.
-- Signaling NaNs, or `sNaNs`.
-
-According to the `IEEE-754`, a comparison with `NaN` always returns
-an unordered result even when compared with itself. As a result, a whole
-Flatbuffers object will be not equal to itself if has one or more `NaN`.
-Flatbuffers scalar fields that have the default value are not actually stored
-in the serialized data but are generated in code (see [Writing a schema](@ref flatbuffers_guide_writing_schema)).
-Scalar fields with `NaN` defaults break this behavior.
-If a schema has a lot of `NaN` defaults the Flatbuffers can override
-the unordered comparison by the ordered: `(NaN==NaN)->true`.
-This ordered comparison is enabled when compiling a program with the symbol
-`FLATBUFFERS_NAN_DEFAULTS` defined.
-Additional computations added by `FLATBUFFERS_NAN_DEFAULTS` are very cheap
-if GCC or Clang used. These compilers have a compile-time implementation
-of `isnan` checking which MSVC does not.
-
<br>
diff --git a/docs/source/CsharpUsage.md b/docs/source/CsharpUsage.md
deleted file mode 100644
index f7f585db..00000000
--- a/docs/source/CsharpUsage.md
+++ /dev/null
@@ -1,175 +0,0 @@
-Use in C# {#flatbuffers_guide_use_c-sharp}
-==============
-
-## Before you get started
-
-Before diving into the FlatBuffers usage in C#, it should be noted that
-the [Tutorial](@ref flatbuffers_guide_tutorial) page has a complete guide to
-general FlatBuffers usage in all of the supported languages (including C#).
-This page is designed to cover the nuances of FlatBuffers usage,
-specific to C#.
-
-You should also have read the [Building](@ref flatbuffers_guide_building)
-documentation to build `flatc` and should be familiar with
-[Using the schema compiler](@ref flatbuffers_guide_using_schema_compiler) and
-[Writing a schema](@ref flatbuffers_guide_writing_schema).
-
-## FlatBuffers C-sharp code location
-
-The code for the FlatBuffers C# library can be found at
-`flatbuffers/net/FlatBuffers`. You can browse the library on the
-[FlatBuffers GitHub page](https://github.com/google/flatbuffers/tree/master/net/
-FlatBuffers).
-
-## Testing the FlatBuffers C-sharp libraries
-
-The code to test the libraries can be found at `flatbuffers/tests`.
-
-The test code for C# is located in the [FlatBuffers.Test](https://github.com/
-google/flatbuffers/tree/master/tests/FlatBuffers.Test) subfolder. To run the
-tests, open `FlatBuffers.Test.csproj` in [Visual Studio](
-https://www.visualstudio.com), and compile/run the project.
-
-Optionally, you can run this using [Mono](http://www.mono-project.com/) instead.
-Once you have installed `Mono`, you can run the tests from the command line
-by running the following commands from inside the `FlatBuffers.Test` folder:
-
-~~~{.sh}
- mcs *.cs ../MyGame/Example/*.cs ../../net/FlatBuffers/*.cs
- mono Assert.exe
-~~~
-
-## Using the FlatBuffers C# library
-
-*Note: See [Tutorial](@ref flatbuffers_guide_tutorial) for a more in-depth
-example of how to use FlatBuffers in C#.*
-
-FlatBuffers supports reading and writing binary FlatBuffers in C#.
-
-To use FlatBuffers in your own code, first generate C# classes from your
-schema with the `--csharp` option to `flatc`.
-Then you can include both FlatBuffers and the generated code to read
-or write a FlatBuffer.
-
-For example, here is how you would read a FlatBuffer binary file in C#:
-First, import the library and generated code. Then, you read a FlatBuffer binary
-file into a `byte[]`. You then turn the `byte[]` into a `ByteBuffer`, which you
-pass to the `GetRootAsMyRootType` function:
-
-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cs}
- using MyGame.Example;
- using FlatBuffers;
-
- // This snippet ignores exceptions for brevity.
- byte[] data = File.ReadAllBytes("monsterdata_test.mon");
-
- ByteBuffer bb = new ByteBuffer(data);
- Monster monster = Monster.GetRootAsMonster(bb);
-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-
-Now you can access the data from the `Monster monster`:
-
-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cs}
- short hp = monster.Hp;
- Vec3 pos = monster.Pos;
-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-
-C# code naming follows standard C# style with `PascalCasing` identifiers,
-e.g. `GetRootAsMyRootType`. Also, values (except vectors and unions) are
-available as properties instead of parameterless accessor methods.
-The performance-enhancing methods to which you can pass an already created
-object are prefixed with `Get`, e.g.:
-
-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cs}
- // property
- var pos = monster.Pos;
-
- // method filling a preconstructed object
- var preconstructedPos = new Vec3();
- monster.GetPos(preconstructedPos);
-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-
-## Storing dictionaries in a FlatBuffer
-
-FlatBuffers doesn't support dictionaries natively, but there is support to
-emulate their behavior with vectors and binary search, which means you
-can have fast lookups directly from a FlatBuffer without having to unpack
-your data into a `Dictionary` or similar.
-
-To use it:
-- Designate one of the fields in a table as the "key" field. You do this
- by setting the `key` attribute on this field, e.g.
- `name:string (key)`.
- You may only have one key field, and it must be of string or scalar type.
-- Write out tables of this type as usual, collect their offsets in an
- array.
-- Instead of calling standard generated method,
- e.g.: `Monster.createTestarrayoftablesVector`,
- call `CreateSortedVectorOfMonster` in C#
- which will first sort all offsets such that the tables they refer to
- are sorted by the key field, then serialize it.
-- Now when you're accessing the FlatBuffer, you can use
- the `ByKey` accessor to access elements of the vector, e.g.:
- `monster.TestarrayoftablesByKey("Frodo")` in C#,
- which returns an object of the corresponding table type,
- or `null` if not found.
- `ByKey` performs a binary search, so should have a similar
- speed to `Dictionary`, though may be faster because of better caching.
- `ByKey` only works if the vector has been sorted, it will
- likely not find elements if it hasn't been sorted.
-
-## Text parsing
-
-There currently is no support for parsing text (Schema's and JSON) directly
-from C#, though you could use the C++ parser through native call
-interfaces available to each language. Please see the
-C++ documentation for more on text parsing.
-
-## Object based API
-
-FlatBuffers is all about memory efficiency, which is why its base API is written
-around using as little as possible of it. This does make the API clumsier
-(requiring pre-order construction of all data, and making mutation harder).
-
-For times when efficiency is less important a more convenient object based API
-can be used (through `--gen-object-api`) that is able to unpack & pack a
-FlatBuffer into objects and standard System.Collections.Generic containers, allowing for convenient
-construction, access and mutation.
-
-To use:
-
-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cs}
- // Deserialize from buffer into object.
- MonsterT monsterobj = GetMonster(flatbuffer).UnPack();
-
- // Update object directly like a C# class instance.
- Console.WriteLine(monsterobj.Name);
- monsterobj.Name = "Bob"; // Change the name.
-
- // Serialize into new flatbuffer.
- FlatBufferBuilder fbb = new FlatBufferBuilder(1);
- fbb.Finish(Monster.Pack(fbb, monsterobj).Value);
-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-
-### Json Serialization
-
-An additional feature of the object API is the ability to allow you to
-serialize & deserialize a JSON text.
-To use Json Serialization, add `--gen-json-serializer` option to `flatc` and
-add `Newtonsoft.Json` nuget package to csproj.
-
-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cs}
- // Deserialize MonsterT from json
- string jsonText = File.ReadAllText(@"Resources/monsterdata_test.json");
- MonsterT mon = MonsterT.DeserializeFromJson(jsonText);
-
- // Serialize MonsterT to json
- string jsonText2 = mon.SerializeToJson();
-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-
-* Limitation
- * `hash` attribute currentry not supported.
-* NuGet package Dependency
- * [Newtonsoft.Json](https://github.com/JamesNK/Newtonsoft.Json)
-
-<br>
diff --git a/docs/source/FlatBuffers.md b/docs/source/FlatBuffers.md
index 2a2133f7..7cc93b92 100644
--- a/docs/source/FlatBuffers.md
+++ b/docs/source/FlatBuffers.md
@@ -4,7 +4,7 @@ FlatBuffers {#flatbuffers_index}
# Overview {#flatbuffers_overview}
[FlatBuffers](@ref flatbuffers_overview) is an efficient cross platform
-serialization library for C++, C#, C, Go, Java, Kotlin, JavaScript, Lobster, Lua, TypeScript, PHP, Python, Rust and Swift.
+serialization library for C++, C#, C, Go, Java, JavaScript, Lobster, Lua, TypeScript, PHP, Python, and Rust.
It was originally created at Google for game development and other
performance-critical applications.
@@ -51,7 +51,7 @@ under the Apache license, v2 (see LICENSE.txt).
needed (faster and more memory efficient than other JSON
parsers).
- Java, Kotlin and Go code supports object-reuse. C# has efficient struct based
+ Java and Go code supports object-reuse. C# has efficient struct based
accessors.
- **Cross platform code with no dependencies** - C++ code will work
@@ -108,7 +108,7 @@ sections provide a more in-depth usage guide.
present for every object instance.
- Use `flatc` (the FlatBuffer compiler) to generate a C++ header (or
- Java/Kotlin/C#/Go/Python.. classes) with helper classes to access and construct
+ Java/C#/Go/Python.. classes) with helper classes to access and construct
serialized data. This header (say `mydata_generated.h`) only depends on
`flatbuffers.h`, which defines the core functionality.
@@ -130,12 +130,8 @@ sections provide a more in-depth usage guide.
- How to [write a schema](@ref flatbuffers_guide_writing_schema).
- How to [use the generated C++ code](@ref flatbuffers_guide_use_cpp) in your
own programs.
-- How to [use the generated Java code](@ref flatbuffers_guide_use_java)
+- How to [use the generated Java/C# code](@ref flatbuffers_guide_use_java_c-sharp)
in your own programs.
-- How to [use the generated C# code](@ref flatbuffers_guide_use_c-sharp)
- in your own programs.
-- How to [use the generated Kotlin code](@ref flatbuffers_guide_use_kotlin)
- in your own programs.
- How to [use the generated Go code](@ref flatbuffers_guide_use_go) in your
own programs.
- How to [use the generated Lua code](@ref flatbuffers_guide_use_lua) in your
@@ -150,8 +146,6 @@ sections provide a more in-depth usage guide.
own programs.
- How to [use the generated Rust code](@ref flatbuffers_guide_use_rust) in your
own programs.
-- How to [use the generated Swift code](@ref flatbuffers_guide_use_swift) in your
- own programs.
- [Support matrix](@ref flatbuffers_support) for platforms/languages/features.
- Some [benchmarks](@ref flatbuffers_benchmarks) showing the advantage of
using FlatBuffers.
@@ -167,7 +161,6 @@ sections provide a more in-depth usage guide.
- [GitHub repository](http://github.com/google/flatbuffers)
- [Landing page](http://google.github.io/flatbuffers)
- [FlatBuffers Google Group](https://groups.google.com/forum/#!forum/flatbuffers)
-- [Discord](https://discord.gg/6qgKs3R) and [Gitter](https://gitter.im/lobster_programming_language/community) chat.
- [FlatBuffers Issues Tracker](http://github.com/google/flatbuffers/issues)
- Independent implementations & tools:
- [FlatCC](https://github.com/dvidelabs/flatcc) Alternative FlatBuffers
@@ -183,6 +176,3 @@ sections provide a more in-depth usage guide.
- [FlatBuffers in Android](http://frogermcs.github.io/flatbuffers-in-android-introdution/)
- [Parsing JSON to FlatBuffers in Java](http://frogermcs.github.io/json-parsing-with-flatbuffers-in-android/)
- [FlatBuffers in Unity](http://exiin.com/blog/flatbuffers-for-unity-sample-code/)
- - [FlexBuffers C#](https://github.com/mzaks/FlexBuffers-CSharp) and
- [article](https://medium.com/@icex33/flexbuffers-for-unity3d-4d1ab5c53fbe?)
- on its use.
diff --git a/docs/source/FlexBuffers.md b/docs/source/FlexBuffers.md
index 974dd693..a089df32 100644
--- a/docs/source/FlexBuffers.md
+++ b/docs/source/FlexBuffers.md
@@ -29,7 +29,9 @@ FlexBuffers is still slower than regular FlatBuffers though, so we recommend to
only use it if you need it.
-# Usage in C++
+# Usage
+
+This is for C++, other languages may follow.
Include the header `flexbuffers.h`, which in turn depends on `flatbuffers.h`
and `util.h`.
@@ -96,10 +98,10 @@ allows a single type, and uses a bit less memory.
`IndirectFloat` is an interesting feature that allows you to store values
by offset rather than inline. Though that doesn't make any visible change
to the user, the consequence is that large values (especially doubles or
-64 bit ints) that occur more than once can be shared (see ReuseValue).
-Another use case is inside of vectors, where the largest element makes
-up the size of all elements (e.g. a single double forces all elements to
-64bit), so storing a lot of small integers together with a double is more efficient if the double is indirect.
+64 bit ints) that occur more than once can be shared. Another use case is
+inside of vectors, where the largest element makes up the size of all elements
+(e.g. a single double forces all elements to 64bit), so storing a lot of small
+integers together with a double is more efficient if the double is indirect.
Accessing it:
@@ -120,46 +122,6 @@ map["unknown"].IsNull(); // true
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-# Usage in Java
-
-Java implementation follows the C++ one, closely.
-
-For creating the equivalent of the same JSON `{ vec: [ -100, "Fred", 4.0 ], foo: 100 }`,
-one could use the following code:
-
-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.java}
-FlexBuffersBuilder builder = new FlexBuffersBuilder(ByteBuffer.allocate(512),
- FlexBuffersBuilder.BUILDER_FLAG_SHARE_KEYS_AND_STRINGS);
-int smap = builder.startMap();
-int svec = builder.startVector();
-builder.putInt(-100);
-builder.putString("Fred");
-builder.putFloat(4.0);
-builder.endVector("vec", svec, false, false);
-builder.putInt("foo", 100);
-builder.endMap(null, smap);
-ByteBuffer bb = builder.finish();
-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-
-Similarly, to read the data, just:
-
-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.java}
-FlexBuffers.Map map = FlexBuffers.getRoot(bb).asMap();
-map.size(); // 2
-FlexBuffers.Vector vec = map.get("vec").asVector();
-vec.size(); // 3
-vec.get(0).asLong(); // -100;
-vec.get(1).asString(); // "Fred";
-vec.get(1).asLong(); // 0 (Number parsing failed).
-vec.get(2).asFloat(); // 4.0
-vec.get(2).asString().isEmpty(); // true (Wrong Type).
-vec.get(2).asString(); // "" (This still works though).
-vec.get(2).toString(); // "4.0" (Or have it converted).
-map.get("foo").asUInt(); // 100
-map.get("unknown").isNull(); // true
-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-
-
# Binary encoding
A description of how FlexBuffers are encoded is in the
diff --git a/docs/source/Internals.md b/docs/source/Internals.md
index d2064ca6..e8f453a8 100644
--- a/docs/source/Internals.md
+++ b/docs/source/Internals.md
@@ -15,12 +15,6 @@ all commonly used CPUs today. FlatBuffers will also work on big-endian
machines, but will be slightly slower because of additional
byte-swap intrinsics.
-It is assumed that the following conditions are met, to ensure
-cross-platform interoperability:
-- The binary `IEEE-754` format is used for floating-point numbers.
-- The `two's complemented` representation is used for signed integers.
-- The endianness is the same for floating-point numbers as for integers.
-
On purpose, the format leaves a lot of details about where exactly
things live in memory undefined, e.g. fields in a table can have any
order, and objects to some extent can be stored in many orders. This is
diff --git a/docs/source/JavaUsage.md b/docs/source/JavaCsharpUsage.md
index 30ba0613..102ce371 100644
--- a/docs/source/JavaUsage.md
+++ b/docs/source/JavaCsharpUsage.md
@@ -1,30 +1,41 @@
-Use in Java {#flatbuffers_guide_use_java}
+Use in Java/C# {#flatbuffers_guide_use_java_c-sharp}
==============
## Before you get started
-Before diving into the FlatBuffers usage in Java, it should be noted that
+Before diving into the FlatBuffers usage in Java or C#, it should be noted that
the [Tutorial](@ref flatbuffers_guide_tutorial) page has a complete guide to
-general FlatBuffers usage in all of the supported languages (including Java).
-This page is designed to cover the nuances of FlatBuffers usage,
-specific to Java.
+general FlatBuffers usage in all of the supported languages (including both Java
+and C#). This page is designed to cover the nuances of FlatBuffers usage,
+specific to Java and C#.
You should also have read the [Building](@ref flatbuffers_guide_building)
documentation to build `flatc` and should be familiar with
[Using the schema compiler](@ref flatbuffers_guide_using_schema_compiler) and
[Writing a schema](@ref flatbuffers_guide_writing_schema).
-## FlatBuffers Java code location
+## FlatBuffers Java and C-sharp code location
+
+#### Java
The code for the FlatBuffers Java library can be found at
`flatbuffers/java/com/google/flatbuffers`. You can browse the library on the
[FlatBuffers GitHub page](https://github.com/google/flatbuffers/tree/master/
java/com/google/flatbuffers).
-## Testing the FlatBuffers Java libraries
+#### C-sharp
+
+The code for the FlatBuffers C# library can be found at
+`flatbuffers/net/FlatBuffers`. You can browse the library on the
+[FlatBuffers GitHub page](https://github.com/google/flatbuffers/tree/master/net/
+FlatBuffers).
+
+## Testing the FlatBuffers Java and C-sharp libraries
The code to test the libraries can be found at `flatbuffers/tests`.
+#### Java
+
The test code for Java is located in [JavaTest.java](https://github.com/google
/flatbuffers/blob/master/tests/JavaTest.java).
@@ -36,15 +47,31 @@ system.
*Note: These scripts require that [Java](https://www.oracle.com/java/index.html)
is installed.*
-## Using the FlatBuffers Java library
+#### C-sharp
+
+The test code for C# is located in the [FlatBuffers.Test](https://github.com/
+google/flatbuffers/tree/master/tests/FlatBuffers.Test) subfolder. To run the
+tests, open `FlatBuffers.Test.csproj` in [Visual Studio](
+https://www.visualstudio.com), and compile/run the project.
+
+Optionally, you can run this using [Mono](http://www.mono-project.com/) instead.
+Once you have installed `Mono`, you can run the tests from the command line
+by running the following commands from inside the `FlatBuffers.Test` folder:
+
+~~~{.sh}
+ mcs *.cs ../MyGame/Example/*.cs ../../net/FlatBuffers/*.cs
+ mono Assert.exe
+~~~
+
+## Using the FlatBuffers Java (and C#) library
*Note: See [Tutorial](@ref flatbuffers_guide_tutorial) for a more in-depth
-example of how to use FlatBuffers in Java.*
+example of how to use FlatBuffers in Java or C#.*
-FlatBuffers supports reading and writing binary FlatBuffers in Java.
+FlatBuffers supports reading and writing binary FlatBuffers in Java and C#.
To use FlatBuffers in your own code, first generate Java classes from your
-schema with the `--java` option to `flatc`.
+schema with the `--java` option to `flatc`. (Or for C# with `--csharp`).
Then you can include both FlatBuffers and the generated code to read
or write a FlatBuffer.
@@ -53,6 +80,11 @@ First, import the library and generated code. Then, you read a FlatBuffer binary
file into a `byte[]`. You then turn the `byte[]` into a `ByteBuffer`, which you
pass to the `getRootAsMyRootType` function:
+*Note: The code here is written from the perspective of Java. Code for both
+languages is both generated and used in nearly the exact same way, with only
+minor differences. These differences are
+[explained in a section below](#differences_in_c-sharp).*
+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.java}
import MyGame.Example.*;
import com.google.flatbuffers.FlatBufferBuilder;
@@ -75,6 +107,30 @@ Now you can access the data from the `Monster monster`:
Vec3 pos = monster.pos();
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+<a name="differences_in_c-sharp">
+#### Differences in C-sharp
+</a>
+
+C# code works almost identically to Java, with only a few minor differences.
+You can see an example of C# code in
+`tests/FlatBuffers.Test/FlatBuffersExampleTests.cs` or
+`samples/SampleBinary.cs`.
+
+First of all, naming follows standard C# style with `PascalCasing` identifiers,
+e.g. `GetRootAsMyRootType`. Also, values (except vectors and unions) are
+available as properties instead of parameterless accessor methods as in Java.
+The performance-enhancing methods to which you can pass an already created
+object are prefixed with `Get`, e.g.:
+
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cs}
+ // property
+ var pos = monster.Pos;
+
+ // method filling a preconstructed object
+ var preconstructedPos = new Vec3();
+ monster.GetPos(preconstructedPos);
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
## Storing dictionaries in a FlatBuffer
FlatBuffers doesn't support dictionaries natively, but there is support to
@@ -91,12 +147,14 @@ To use it:
array.
- Instead of calling standard generated method,
e.g.: `Monster.createTestarrayoftablesVector`,
- call `createSortedVectorOfTables` (from the `FlatBufferBuilder` object).
+ call `CreateSortedVectorOfMonster` in C# or
+ `createSortedVectorOfTables` (from the `FlatBufferBuilder` object) in Java,
which will first sort all offsets such that the tables they refer to
are sorted by the key field, then serialize it.
- Now when you're accessing the FlatBuffer, you can use
the `ByKey` accessor to access elements of the vector, e.g.:
- `monster.testarrayoftablesByKey("Frodo")`.
+ `monster.testarrayoftablesByKey("Frodo")` in Java or
+ `monster.TestarrayoftablesByKey("Frodo")` in C#,
which returns an object of the corresponding table type,
or `null` if not found.
`ByKey` performs a binary search, so should have a similar
@@ -107,7 +165,7 @@ To use it:
## Text parsing
There currently is no support for parsing text (Schema's and JSON) directly
-from Java, though you could use the C++ parser through native call
+from Java or C#, though you could use the C++ parser through native call
interfaces available to each language. Please see the
C++ documentation for more on text parsing.
diff --git a/docs/source/KotlinUsage.md b/docs/source/KotlinUsage.md
deleted file mode 100644
index 092fcd7f..00000000
--- a/docs/source/KotlinUsage.md
+++ /dev/null
@@ -1,84 +0,0 @@
-Use in Kotlin {#flatbuffers_guide_use_kotlin}
-==============
-
-## Before you get started
-
-Before diving into the FlatBuffers usage in Kotlin, it should be noted that
-the [Tutorial](@ref flatbuffers_guide_tutorial) page has a complete guide to
-general FlatBuffers usage in all of the supported languages (including K).
-
-This page is designed to cover the nuances of FlatBuffers usage, specific to Kotlin.
-
-You should also have read the [Building](@ref flatbuffers_guide_building)
-documentation to build `flatc` and should be familiar with
-[Using the schema compiler](@ref flatbuffers_guide_using_schema_compiler) and
-[Writing a schema](@ref flatbuffers_guide_writing_schema).
-
-## Kotlin and FlatBuffers Java code location
-
-Code generated for Kotlin currently uses the flatbuffers java runtime library. That means that Kotlin generated code can only have Java virtual machine as target architecture (which includes Android). Kotlin Native and Kotlin.js are currently not supported.
-
-The code for the FlatBuffers Java library can be found at
-`flatbuffers/java/com/google/flatbuffers`. You can browse the library on the
-[FlatBuffers GitHub page](https://github.com/google/flatbuffers/tree/master/
-java/com/google/flatbuffers).
-
-## Testing FlatBuffers Kotlin
-
-The test code for Java is located in [KotlinTest.java](https://github.com/google
-/flatbuffers/blob/master/tests/KotlinTest.kt).
-
-To run the tests, use [KotlinTest.sh](https://github.com/google/
-flatbuffers/blob/master/tests/KotlinTest.sh) shell script.
-
-*Note: These scripts require that [Kotlin](https://kotlinlang.org/) is installed.*
-
-## Using the FlatBuffers Kotlin library
-
-*Note: See [Tutorial](@ref flatbuffers_guide_tutorial) for a more in-depth
-example of how to use FlatBuffers in Kotlin.*
-
-FlatBuffers supports reading and writing binary FlatBuffers in Kotlin.
-
-To use FlatBuffers in your own code, first generate Java classes from your
-schema with the `--kotlin` option to `flatc`.
-Then you can include both FlatBuffers and the generated code to read
-or write a FlatBuffer.
-
-For example, here is how you would read a FlatBuffer binary file in Kotlin:
-First, import the library and generated code. Then, you read a FlatBuffer binary
-file into a `ByteArray`. You then turn the `ByteArray` into a `ByteBuffer`, which you
-pass to the `getRootAsMyRootType` function:
-
-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.kt}
- import MyGame.Example.*
- import com.google.flatbuffers.FlatBufferBuilder
-
- // This snippet ignores exceptions for brevity.
- val data = RandomAccessFile(File("monsterdata_test.mon"), "r").use {
- val temp = ByteArray(it.length().toInt())
- it.readFully(temp)
- temp
- }
-
- val bb = ByteBuffer.wrap(data)
- val monster = Monster.getRootAsMonster(bb)
-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-
-Now you can access the data from the `Monster monster`:
-
-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.kt}
- val hp = monster.hp
- val pos = monster.pos!!;
-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-
-
-
-## Differences between Kotlin and Java code
-
-Kotlin generated code was designed to be as close as possible to the java counterpart, as for now, we only support kotlin on java virtual machine. So the differences in implementation and usage are basically the ones introduced by the Kotlin language itself. You can find more in-depth information [here](https://kotlinlang.org/docs/reference/comparison-to-java.html).
-
-The most obvious ones are:
-
-* Fields as accessed as Kotlin [properties](https://kotlinlang.org/docs/reference/properties.html)
-* Static methods are accessed in [companion object](https://kotlinlang.org/docs/reference/classes.html#companion-objects) \ No newline at end of file
diff --git a/docs/source/Schemas.md b/docs/source/Schemas.md
index bd119b0b..4f7bd728 100644
--- a/docs/source/Schemas.md
+++ b/docs/source/Schemas.md
@@ -114,27 +114,6 @@ of same-size data where a `reinterpret_cast` would give you a desirable result,
e.g. you could change a `uint` to an `int` if no values in current data use the
high bit yet.
-### Arrays
-
-Arrays are a convenience short-hand for a fixed-length collection of elements.
-Arrays can be used to replace the following schema:
-
- struct Vec3 {
- x:float;
- y:float;
- z:float;
- }
-
-with the following schema:
-
- struct Vec3 {
- v:[float:3];
- }
-
-Both representations are binary equivalent.
-
-Arrays are currently only supported in a `struct`.
-
### (Default) Values
Values are a sequence of digits. Values may be optionally followed by a decimal
@@ -345,9 +324,6 @@ Current understood attributes:
Note: currently not guaranteed to have an effect when used with
`--object-api`, since that may allocate objects at alignments less than
what you specify with `force_align`.
-- `force_align: size` (on a vector): force the alignment of this vector to be
- something different than what the element size would normally dictate.
- Note: Now only work for generated C++ code.
- `bit_flags` (on an unsigned enum): the values of this field indicate bits,
meaning that any unsigned value N specified in the schema will end up
representing 1<<N, or if you don't specify values at all, you'll get
@@ -442,19 +418,14 @@ numerical literals:
For example: `[0x123, +0x45, -0x67]` are equal to `[291, 69, -103]` decimals.
- The format of float-point numbers is fully compatible with C/C++ format.
If a modern C++ compiler is used the parser accepts hexadecimal and special
- floating-point literals as well:
+ float-point literals as well:
`[-1.0, 2., .3e0, 3.e4, 0x21.34p-5, -inf, nan]`.
+ The exponent suffix of hexadecimal float-point number is mandatory.
- The following conventions for floating-point numbers are used:
- - The exponent suffix of hexadecimal floating-point number is mandatory.
- - Parsed `NaN` converted to unsigned IEEE-754 `quiet-NaN` value.
-
- Extended floating-point support was tested with:
+ Extended float-point support was tested with:
- x64 Windows: `MSVC2015` and higher.
- x64 Linux: `LLVM 6.0`, `GCC 4.9` and higher.
- For details, see [Use in C++](@ref flatbuffers_guide_use_cpp) section.
-
- For compatibility with a JSON lint tool all numeric literals of scalar
fields can be wrapped to quoted string:
`"1", "2.0", "0x48A", "0x0C.0Ep-1", "-inf", "true"`.
@@ -566,7 +537,7 @@ with the new schema now cannot read nor write `a` anymore (any existing code
that tries to do so will result in compile errors), but can still read
old data (they will ignore the field).
- table { c:int; a:int; b:int; }
+ table { c:int a:int; b:int; }
This is NOT ok, as this makes the schemas incompatible. Old code reading newer
data will interpret `c` as if it was `a`, and new code reading old data
diff --git a/docs/source/Support.md b/docs/source/Support.md
index 1e435a66..c8ac7f7e 100644
--- a/docs/source/Support.md
+++ b/docs/source/Support.md
@@ -18,23 +18,23 @@ In general:
NOTE: this table is a start, it needs to be extended.
-Feature | C++ | Java | C# | Go | Python | JS | TS | C | PHP | Dart | Lobster | Rust | Swift
------------------------------- | ------ | ------ | ------ | ------ | ------ | --------- | --------- | ------ | --- | ------- | ------- | ------- | ------
-Codegen for all basic features | Yes | Yes | Yes | Yes | Yes | Yes | Yes | Yes | WiP | Yes | Yes | Yes | Yes
-JSON parsing | Yes | No | No | No | No | No | No | Yes | No | No | Yes | No | No
-Simple mutation | Yes | Yes | Yes | Yes | No | No | No | No | No | No | No | No | No
-Reflection | Yes | No | No | No | No | No | No | Basic | No | No | No | No | No
-Buffer verifier | Yes | No | No | No | No | No | No | Yes | No | No | No | No | No
-Testing: basic | Yes | Yes | Yes | Yes | Yes | Yes | Yes | Yes | ? | Yes | Yes | Yes | Yes
-Testing: fuzz | Yes | No | No | Yes | Yes | No | No | No | ? | No | No | Yes | No
-Performance: | Superb | Great | Great | Great | Ok | ? | ? | Superb | ? | ? | Great | Superb | ?
-Platform: Windows | VS2010 | Yes | Yes | ? | ? | ? | Yes | VS2010 | ? | Yes | Yes | Yes | No
-Platform: Linux | GCC282 | Yes | ? | Yes | Yes | ? | Yes | Yes | ? | Yes | Yes | Yes | Yes
-Platform: OS X | Xcode4 | ? | ? | ? | Yes | ? | Yes | Yes | ? | Yes | Yes | Yes | Yes
-Platform: Android | NDK10d | Yes | ? | ? | ? | ? | ? | ? | ? | Flutter | Yes | ? | No
-Platform: iOS | ? | ? | ? | ? | ? | ? | ? | ? | ? | Flutter | Yes | ? | Yes
-Engine: Unity | ? | ? | Yes | ? | ? | ? | ? | ? | ? | ? | No | ? | No
-Primary authors (github) | aard* | aard* | ev*/js*| rw | rw | evanw/ev* | kr* | mik* | ch* | dnfield | aard* | rw | mi*/mz*
+Feature | C++ | Java | C# | Go | Python | JS | TS | C | PHP | Dart | Lobster | Rust
+------------------------------ | ------ | ------ | ------ | ------ | ------ | --------- | --------- | ------ | --- | ------- | ------- | ----
+Codegen for all basic features | Yes | Yes | Yes | Yes | Yes | Yes | Yes | Yes | WiP | Yes | Yes | Yes
+JSON parsing | Yes | No | No | No | No | No | No | Yes | No | No | Yes | No
+Simple mutation | Yes | Yes | Yes | Yes | No | No | No | No | No | No | No | No
+Reflection | Yes | No | No | No | No | No | No | Basic | No | No | No | No
+Buffer verifier | Yes | No | No | No | No | No | No | Yes | No | No | No | No
+Testing: basic | Yes | Yes | Yes | Yes | Yes | Yes | Yes | Yes | ? | Yes | Yes | Yes
+Testing: fuzz | Yes | No | No | Yes | Yes | No | No | No | ? | No | No | Yes
+Performance: | Superb | Great | Great | Great | Ok | ? | ? | Superb | ? | ? | Great | Superb
+Platform: Windows | VS2010 | Yes | Yes | ? | ? | ? | Yes | VS2010 | ? | Yes | Yes | Yes
+Platform: Linux | GCC282 | Yes | ? | Yes | Yes | ? | Yes | Yes | ? | Yes | Yes | Yes
+Platform: OS X | Xcode4 | ? | ? | ? | Yes | ? | Yes | Yes | ? | Yes | Yes | Yes
+Platform: Android | NDK10d | Yes | ? | ? | ? | ? | ? | ? | ? | Flutter | Yes | ?
+Platform: iOS | ? | ? | ? | ? | ? | ? | ? | ? | ? | Flutter | Yes | ?
+Engine: Unity | ? | ? | Yes | ? | ? | ? | ? | ? | ? | ? | No | ?
+Primary authors (github) | aard* | aard* | ev*/js*| rw | rw | evanw/ev* | kr* | mik* | ch* | dnfield | aard* | rw
* aard = aardappel (previously: gwvo)
* ev = evolutional
@@ -42,7 +42,5 @@ Primary authors (github) | aard* | aard* | ev*/js*| rw | rw | ev
* mik = mikkelfj
* ch = chobie
* kr = krojew
- * mi = mustiikhalil
- * mz = mzaks
<br>
diff --git a/docs/source/SwiftUsage.md b/docs/source/SwiftUsage.md
deleted file mode 100644
index d5640f6c..00000000
--- a/docs/source/SwiftUsage.md
+++ /dev/null
@@ -1,91 +0,0 @@
-Use in Swift {#flatbuffers_guide_use_swift}
-=========
-
-## Before you get started
-
-Before diving into the FlatBuffers usage in Swift, it should be noted that
-the [Tutorial](@ref flatbuffers_guide_tutorial) page has a complete guide
-to general FlatBuffers usage in all of the supported languages (including Swift).
-This page is designed to cover the nuances of FlatBuffers usage, specific to
-Swift.
-
-You should also have read the [Building](@ref flatbuffers_guide_building)
-documentation to build `flatc` and should be familiar with
-[Using the schema compiler](@ref flatbuffers_guide_using_schema_compiler) and
-[Writing a schema](@ref flatbuffers_guide_writing_schema).
-
-## FlatBuffers Swift library code location
-
-The code for the FlatBuffers Swift library can be found at
-`flatbuffers/swift`. You can browse the library code on the [FlatBuffers
-GitHub page](https://github.com/google/flatbuffers/tree/master/swift).
-
-## Testing the FlatBuffers Swift library
-
-The code to test the Swift library can be found at `flatbuffers/Flatbuffers.Test.Swift`.
-The test code itself is located in [Flatbuffers.Test.Swift](https://github.com/google/flatbuffers/blob/master/tests/FlatBuffers.Test.Swift).
-
-To run the tests, use the [SwiftTest.sh](https://github.com/google/flatbuffers/blob/master/tests/FlatBuffers.Test.Swift/SwiftTest.sh) shell script.
-
-*Note: The shell script requires [Swift](https://swift.org) to
-be installed.*
-
-## Using the FlatBuffers Swift library
-
-*Note: See [Tutorial](@ref flatbuffers_guide_tutorial) for a more in-depth
-example of how to use FlatBuffers in Swift.*
-
-FlatBuffers supports reading and writing binary FlatBuffers in Swift.
-
-To use FlatBuffers in your own code, first generate Swift structs from your
-schema with the `--swift` option to `flatc`. Then include FlatBuffers using `SPM` in
-by adding the path to `FlatBuffers/swift` into it. The generated code should also be
-added to xcode or the path of the package you will be using. Note: sometimes xcode cant
-and wont see the generated files, so it's better that you copy them to xcode.
-
-For example, here is how you would read a FlatBuffer binary file in Swift: First,
-include the library and copy thegenerated code. Then read a FlatBuffer binary file or
-a data object from the server, which you can pass into the `GetRootAsMonster` function.
-
-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.swift}
- import FlatBuffers
-
- typealias Monster1 = MyGame.Sample.Monster
- typealias Vec3 = MyGame.Sample.Vec3
-
- let path = FileManager.default.currentDirectoryPath
- let url = URL(fileURLWithPath: path, isDirectory: true).appendingPathComponent("monsterdata_test").appendingPathExtension("mon")
- guard let data = try? Data(contentsOf: url) else { return }
-
- let monster = Monster.getRootAsMonster(bb: ByteBuffer(data: data))
-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-
-Now you can access values like this:
-
-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.swift}
- let hp = monster.hp
- let pos = monster.pos
-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-
-
-In some cases it's necessary to modify values in an existing FlatBuffer in place (without creating a copy). For this reason, scalar fields of a Flatbuffer table or struct can be mutated.
-
-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.swift}
- let monster = Monster.getRootAsMonster(bb: ByteBuffer(data: data))
-
- if !monster.mutate(hp: 10) {
- fatalError("couldn't mutate")
- }
- // mutate a struct field
- let vec = monster.pos.mutate(z: 4)
-
- // This mutation will fail because the mana field is not available in
- // the buffer. It should be set when creating the buffer.
- if !monster.mutate(mana: 20) {
- fatalError("couldn't mutate")
- }
-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-
-The term `mutate` is used instead of `set` to indicate that this is a special use case. All mutate functions return a boolean value which is false if the field we're trying to mutate is not available in the buffer.
-
-<br>
diff --git a/docs/source/Tutorial.md b/docs/source/Tutorial.md
index c0f3b9e7..e23068b6 100644
--- a/docs/source/Tutorial.md
+++ b/docs/source/Tutorial.md
@@ -23,7 +23,6 @@ Please select your desired language for our quest:
<form>
<input type="radio" name="language" value="cpp" checked="checked">C++</input>
<input type="radio" name="language" value="java">Java</input>
- <input type="radio" name="language" value="kotlin">Kotlin</input>
<input type="radio" name="language" value="csharp">C#</input>
<input type="radio" name="language" value="go">Go</input>
<input type="radio" name="language" value="python">Python</input>
@@ -35,7 +34,6 @@ Please select your desired language for our quest:
<input type="radio" name="language" value="lua">Lua</input>
<input type="radio" name="language" value="lobster">Lobster</input>
<input type="radio" name="language" value="rust">Rust</input>
- <input type="radio" name="language" value="swift">Swift</input>
</form>
\endhtmlonly
@@ -117,9 +115,6 @@ For your chosen language, please cross-reference with:
<div class="language-java">
[SampleBinary.java](https://github.com/google/flatbuffers/blob/master/samples/SampleBinary.java)
</div>
-<div class="language-kotlin">
-[SampleBinary.kt](https://github.com/google/flatbuffers/blob/master/samples/SampleBinary.kt)
-</div>
<div class="language-csharp">
[SampleBinary.cs](https://github.com/google/flatbuffers/blob/master/samples/SampleBinary.cs)
</div>
@@ -153,9 +148,6 @@ For your chosen language, please cross-reference with:
<div class="language-rust">
[sample_binary.rs](https://github.com/google/flatbuffers/blob/master/samples/sample_binary.rs)
</div>
-<div class="language-swift">
-[sample_binary.swift](https://github.com/google/flatbuffers/blob/master/samples/sample_binary.swift)
-</div>
## Writing the Monsters' FlatBuffer Schema
@@ -292,12 +284,6 @@ Please be aware of the difference between `flatc` and `flatcc` tools.
./../flatc --java monster.fbs
~~~
</div>
-<div class="language-kotlin">
-~~~{.sh}
- cd flatbuffers/samples
- ./../flatc --kotlin monster.fbs
-~~~
-</div>
<div class="language-csharp">
~~~{.sh}
cd flatbuffers/samples
@@ -367,12 +353,6 @@ Please be aware of the difference between `flatc` and `flatcc` tools.
./../flatc --rust monster.fbs
~~~
</div>
-<div class="language-swift">
-~~~{.sh}
- cd flatbuffers/samples
- ./../flatc --swift monster.fbs
-~~~
-</div>
For a more complete guide to using the `flatc` compiler, please read the
[Using the schema compiler](@ref flatbuffers_guide_using_schema_compiler)
@@ -402,13 +382,6 @@ The first step is to import/include the library, generated files, etc.
import com.google.flatbuffers.FlatBufferBuilder;
~~~
</div>
-<div class="language-kotlin">
-~~~{.kotlin}
- import MyGame.Sample.* //The `flatc` generated files. (Monster, Vec3, etc.)
-
- import com.google.flatbuffers.FlatBufferBuilder
-~~~
-</div>
<div class="language-csharp">
~~~{.cs}
using FlatBuffers;
@@ -451,7 +424,7 @@ The first step is to import/include the library, generated files, etc.
~~~
</div>
<div class="language-typescript">
- // note: import flatbuffers with your desired import method
+ // note: import flabuffers with your desired import method
import { MyGame } from './monster_generated';
</div>
@@ -512,8 +485,8 @@ The first step is to import/include the library, generated files, etc.
</div>
<div class="language-lobster">
~~~{.lobster}
- import from "../lobster/" // Where to find flatbuffers.lobster
- import monster_generated
+ include from "../lobster/" // Where to find flatbuffers.lobster
+ include "monster_generated.lobster"
~~~
</div>
<div class="language-rust">
@@ -533,21 +506,6 @@ The first step is to import/include the library, generated files, etc.
~~~
</div>
-<div class="language-swift">
-~~~{.swift}
- /**
- // make sure that monster_generated.swift is included in your project
- */
- import Flatbuffers
-
- // typealiases for convenience
- typealias Monster = MyGame1.Sample.Monster
- typealias Weapon = MyGame1.Sample.Weapon
- typealias Color = MyGame1.Sample.Color
- typealias Vec3 = MyGame1.Sample.Vec3
-~~~
-</div>
-
Now we are ready to start building some buffers. In order to start, we need
to create an instance of the `FlatBufferBuilder`, which will contain the buffer
as it grows. You can pass an initial size of the buffer (here 1024 bytes),
@@ -567,13 +525,6 @@ which will grow automatically if needed:
FlatBufferBuilder builder = new FlatBufferBuilder(1024);
~~~
</div>
-<div class="language-kotlin">
-~~~{.kt}
- // Create a `FlatBufferBuilder`, which will be used to create our
- // monsters' FlatBuffers.
- val builder = FlatBufferBuilder(1024)
-~~~
-</div>
<div class="language-csharp">
~~~{.cs}
// Create a `FlatBufferBuilder`, which will be used to create our
@@ -641,7 +592,7 @@ which will grow automatically if needed:
</div>
<div class="language-lobster">
~~~{.lobster}
- // get access to the builder
+ -- get access to the builder
let builder = flatbuffers_builder {}
~~~
</div>
@@ -652,12 +603,6 @@ which will grow automatically if needed:
let mut builder = flatbuffers::FlatBufferBuilder::new_with_capacity(1024);
~~~
</div>
-<div class="language-swift">
-~~~{.swift}
- // create a `FlatBufferBuilder`, which will be used to serialize objects
- let builder = FlatBufferBuilder(initialSize: 1024)
-~~~
-</div>
After creating the `builder`, we can start serializing our data. Before we make
our `orc` Monster, lets create some `Weapon`s: a `Sword` and an `Axe`.
@@ -688,19 +633,6 @@ our `orc` Monster, lets create some `Weapon`s: a `Sword` and an `Axe`.
int axe = Weapon.createWeapon(builder, weaponTwoName, weaponTwoDamage);
~~~
</div>
-<div class="language-kotlin">
-~~~{.kt}
- val weaponOneName = builder.createString("Sword")
- val weaponOneDamage: Short = 3;
-
- val weaponTwoName = builder.createString("Axe")
- val weaponTwoDamage: Short = 5;
-
- // Use the `createWeapon()` helper function to create the weapons, since we set every field.
- val sword = Weapon.createWeapon(builder, weaponOneName, weaponOneDamage)
- val axe = Weapon.createWeapon(builder, weaponTwoName, weaponTwoDamage)
-~~~
-</div>
<div class="language-csharp">
~~~{.cs}
var weaponOneName = builder.CreateString("Sword");
@@ -881,13 +813,12 @@ our `orc` Monster, lets create some `Weapon`s: a `Sword` and an `Axe`.
let weapon_names = [ "Sword", "Axe" ]
let weapon_damages = [ 3, 5 ]
- let weapon_offsets = map(weapon_names) name, i:
+ weapon_offsets := map(weapon_names) name, i:
let ns = builder.CreateString(name)
- MyGame_Sample_WeaponBuilder { b }
- .start()
- .add_name(ns)
- .add_damage(weapon_damages[i])
- .end()
+ builder.MyGame_Sample_WeaponStart()
+ builder.MyGame_Sample_WeaponAddName(ns)
+ builder.MyGame_Sample_WeaponAddDamage(weapon_damages[i])
+ builder.MyGame_Sample_WeaponEnd()
~~~
</div>
<div class="language-rust">
@@ -909,25 +840,6 @@ our `orc` Monster, lets create some `Weapon`s: a `Sword` and an `Axe`.
~~~
</div>
-<div class="language-swift">
-~~~{.swift}
- let weapon1Name = builder.create(string: "Sword")
- let weapon2Name = builder.create(string: "Axe")
-
- // start creating the weapon by calling startWeapon
- let weapon1Start = Weapon.startWeapon(builder)
- Weapon.add(name: weapon1Name, builder)
- Weapon.add(damage: 3, builder)
- // end the object by passing the start point for the weapon 1
- let sword = Weapon.endWeapon(builder, start: weapon1Start)
-
- let weapon2Start = Weapon.startWeapon(builder)
- Weapon.add(name: weapon2Name, builder)
- Weapon.add(damage: 5, builder)
- let axe = Weapon.endWeapon(builder, start: weapon2Start)
-~~~
-</div>
-
Now let's create our monster, the `orc`. For this `orc`, lets make him
`red` with rage, positioned at `(1.0, 2.0, 3.0)`, and give him
a large pool of hit points with `300`. We can give him a vector of weapons
@@ -962,17 +874,6 @@ traversal. This is generally easy to do on any tree structures.
int inv = Monster.createInventoryVector(builder, treasure);
~~~
</div>
-<div class="language-kotlin">
-~~~{.kt}
- // Serialize a name for our monster, called "Orc".
- val name = builder.createString("Orc")
-
- // Create a `vector` representing the inventory of the Orc. Each number
- // could correspond to an item that can be claimed after he is slain.
- val treasure = byteArrayOf(0, 1, 2, 3, 4, 5, 6, 7, 8, 9)
- val inv = Monster.createInventoryVector(builder, treasure)
-~~~
-</div>
<div class="language-csharp">
~~~{.cs}
// Serialize a name for our monster, called "Orc".
@@ -1118,16 +1019,6 @@ traversal. This is generally easy to do on any tree structures.
let inventory = builder.create_vector(&[0u8, 1, 2, 3, 4, 5, 6, 7, 8, 9]);
~~~
</div>
-<div class="language-swift">
-~~~{.swift}
- // Name of the Monster.
- let name = builder.create(string: "Orc")
-
- // create inventory
- let inventory: [Byte] = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
- let inventoryOffset = builder.createVector(inventory)
-~~~
-</div>
We serialized two built-in data types (`string` and `vector`) and captured
their return values. These values are offsets into the serialized data,
@@ -1168,16 +1059,6 @@ offsets.
int weapons = Monster.createWeaponsVector(builder, weaps);
~~~
</div>
-<div class="language-kotlin">
-~~~{.kt}
- // Place the two weapons into an array, and pass it to the `createWeaponsVector()` method to
- // create a FlatBuffer vector.
- val weaps = intArrayOf(sword, axe)
-
- // Pass the `weaps` array into the `createWeaponsVector()` method to create a FlatBuffer vector.
- val weapons = Monster.createWeaponsVector(builder, weaps)
-~~~
-</div>
<div class="language-csharp">
~~~{.cs}
var weaps = new Offset<Weapon>[2];
@@ -1272,13 +1153,6 @@ offsets.
let weapons = builder.create_vector(&[sword, axe]);
~~~
</div>
-<div class="language-swift">
-~~~{.swift}
- // Create a FlatBuffer `vector` that contains offsets to the sword and axe
- // we created above.
- let weaponsOffset = builder.createVector(ofOffsets: [sword, axe])
-~~~
-</div>
<br>
Note there's additional convenience overloads of `CreateVector`, allowing you
@@ -1305,14 +1179,6 @@ for the `path` field above:
int path = fbb.endVector();
~~~
</div>
-<div class="language-kotlin">
-~~~{.kt}
- Monster.startPathVector(fbb, 2)
- Vec3.createVec3(builder, 1.0f, 2.0f, 3.0f)
- Vec3.createVec3(builder, 4.0f, 5.0f, 6.0f)
- val path = fbb.endVector()
-~~~
-</div>
<div class="language-csharp">
~~~{.cs}
Monster.StartPathVector(fbb, 2);
@@ -1415,15 +1281,6 @@ for the `path` field above:
// let path = builder.create_vector(&[&x, &y]);
~~~
</div>
-<div class="language-swift">
-~~~{.swift}
- //
- let points = builder.createVector(structs: [MyGame.Sample.createVec3(x: 1, y: 2, z: 3),
- MyGame.Sample.createVec3(x: 4, y: 5, z: 6)],
- type: Vec3.self)
-~~~
-</div>
-
We have now serialized the non-scalar components of the orc, so we
can serialize the monster itself:
@@ -1460,22 +1317,6 @@ can serialize the monster itself:
int orc = Monster.endMonster(builder);
~~~
</div>
-<div class="language-kotlin">
-~~~{.kt}
- // Create our monster using `startMonster()` and `endMonster()`.
- Monster.startMonster(builder)
- Monster.addPos(builder, Vec3.createVec3(builder, 1.0f, 2.0f, 3.0f))
- Monster.addName(builder, name)
- Monster.addColor(builder, Color.Red)
- Monster.addHp(builder, 300.toShort())
- Monster.addInventory(builder, inv)
- Monster.addWeapons(builder, weapons)
- Monster.addEquippedType(builder, Equipment.Weapon)
- Monster.addEquipped(builder, axe)
- Monster.addPath(builder, path)
- val orc = Monster.endMonster(builder)
-~~~
-</div>
<div class="language-csharp">
~~~{.cs}
// Create our monster using `StartMonster()` and `EndMonster()`.
@@ -1662,18 +1503,17 @@ can serialize the monster itself:
</div>
<div class="language-lobster">
~~~{.lobster}
- let orc = MyGame_Sample_MonsterBuilder { b }
- .start()
- .add_pos(b.MyGame_Sample_CreateVec3(1.0, 2.0, 3.0))
- .add_hp(300)
- .add_name(name)
- .add_inventory(inv)
- .add_color(MyGame_Sample_Color_Red)
- .add_weapons(weapons)
- .add_equipped_type(MyGame_Sample_Equipment_Weapon)
- .add_equipped(weapon_offsets[1])
- .add_path(path)
- .end()
+ builder.MyGame_Sample_MonsterStart()
+ builder.MyGame_Sample_MonsterAddPos(builder.MyGame_Sample_CreateVec3(1.0, 2.0, 3.0))
+ builder.MyGame_Sample_MonsterAddHp(300)
+ builder.MyGame_Sample_MonsterAddName(name)
+ builder.MyGame_Sample_MonsterAddInventory(inv)
+ builder.MyGame_Sample_MonsterAddColor(MyGame_Sample_Color_Red)
+ builder.MyGame_Sample_MonsterAddWeapons(weapons)
+ builder.MyGame_Sample_MonsterAddEquippedType(MyGame_Sample_Equipment_Weapon)
+ builder.MyGame_Sample_MonsterAddEquipped(weapon_offsets[1])
+ builder.MyGame_Sample_MonsterAddPath(path)
+ let orc = builder.MyGame_Sample_MonsterEnd()
~~~
</div>
<div class="language-rust">
@@ -1697,19 +1537,6 @@ can serialize the monster itself:
});
~~~
</div>
-<div class="language-swift">
-~~~{.swift}
- let orc = Monster.createMonster(builder,
- offsetOfPos: pos,
- hp: 300,
- offsetOfName: name,
- vectorOfInventory: inventoryOffset,
- color: .red,
- vectorOfWeapons: weaponsOffset,
- equippedType: .weapon,
- offsetOfEquipped: axe)
-~~~
-</div>
Note how we create `Vec3` struct in-line in the table. Unlike tables, structs
are simple combinations of scalars that are always stored inline, just like
@@ -1775,21 +1602,6 @@ a bit more flexibility.
~~~
</div>
-<div class="language-swift">
-~~~{.swift}
- let start = Monster.startMonster(builder)
- Monster.add(pos: pos, builder)
- Monster.add(hp: 300, builder)
- Monster.add(name: name, builder)
- Monster.addVectorOf(inventory: inventoryOffset, builder)
- Monster.add(color: .red, builder)
- Monster.addVectorOf(weapons: weaponsOffset, builder)
- Monster.add(equippedType: .weapon, builder)
- Monster.add(equipped: axe, builder)
- var orc = Monster.endMonster(builder, start: start)
-~~~
-</div>
-
Before finishing the serialization, let's take a quick look at FlatBuffer
`union Equipped`. There are two parts to each FlatBuffer `union`. The first, is
a hidden field `_type`, that is generated to hold the type of `table` referred
@@ -1813,12 +1625,6 @@ Here is a repetition these lines, to help highlight them more clearly:
Monster.addEquipped(axe); // Union data
~~~
</div>
-<div class="language-kotlin">
- ~~~{.kt}
- Monster.addEquippedType(builder, Equipment.Weapon) // Union type
- Monster.addEquipped(axe) // Union data
- ~~~
-</div>
<div class="language-csharp">
~~~{.cs}
Monster.AddEquippedType(builder, Equipment.Weapon); // Union type
@@ -1881,8 +1687,8 @@ Here is a repetition these lines, to help highlight them more clearly:
</div>
<div class="language-lobster">
~~~{.lobster}
- .add_equipped_type(MyGame_Sample_Equipment_Weapon)
- .add_equipped(axe)
+ builder.MyGame_Sample_MonsterAddEquippedType(MyGame_Sample_Equipment_Weapon)
+ builder.MyGame_Sample_MonsterAddEquipped(axe)
~~~
</div>
<div class="language-rust">
@@ -1893,13 +1699,6 @@ Here is a repetition these lines, to help highlight them more clearly:
monster_builder.add_equipped(axe.as_union_value()); // Union data
~~~
</div>
-<div class="language-swift">
- ~~~{.swift}
- Monster.add(equippedType: .weapon, builder) // Type of union
- Monster.add(equipped: axe, builder) // Union data
- ~~~
-</div>
-
After you have created your buffer, you will have the offset to the root of the
data in the `orc` variable, so you can finish the buffer by calling the
@@ -1921,12 +1720,6 @@ appropriate `finish` method.
builder.finish(orc); // You could also call `Monster.finishMonsterBuffer(builder, orc);`.
~~~
</div>
-<div class="language-kotlin">
-~~~{.kt}
- // Call `finish()` to instruct the builder that this monster is complete.
- builder.finish(orc) // You could also call `Monster.finishMonsterBuffer(builder, orc);`.
-~~~
-</div>
<div class="language-csharp">
~~~{.cs}
// Call `Finish()` to instruct the builder that this monster is complete.
@@ -1995,12 +1788,6 @@ appropriate `finish` method.
builder.finish(orc, None);
~~~
</div>
-<div class="language-swift">
-~~~{.swift}
- // Call `finish(offset:)` to instruct the builder that this monster is complete.
- builder.finish(offset: orc)
-~~~
-</div>
The buffer is now ready to be stored somewhere, sent over the network, be
compressed, or whatever you'd like to do with it. You can access the buffer
@@ -2025,17 +1812,6 @@ like so:
byte[] buf = builder.sizedByteArray();
~~~
</div>
-<div class="language-kotlin">
-~~~{.kt}
- // This must be called after `finish()`.
- val buf = builder.dataBuffer()
- // The data in this ByteBuffer does NOT start at 0, but at buf.position().
- // The number of bytes is buf.remaining().
-
- // Alternatively this copies the above data out of the ByteBuffer for you:
- val buf = builder.sizedByteArray()
-~~~
-</div>
<div class="language-csharp">
~~~{.cs}
// This must be called after `Finish()`.
@@ -2129,15 +1905,6 @@ like so:
~~~
</div>
-<div class="language-swift">
-~~~{.swift}
- // This must be called after `finish()`.
- // `sizedByteArray` returns the finished buf of type [UInt8].
- let buf = builder.sizedByteArray
- // or you can use to get an object of type Data
- let bufData = ByteBuffer(data: builder.data)
-~~~
-</div>
Now you can write the bytes to a file, send them over the network..
**Make sure your file mode (or transfer protocol) is set to BINARY, not text.**
@@ -2167,13 +1934,6 @@ before:
import com.google.flatbuffers.FlatBufferBuilder;
~~~
</div>
-<div class="language-kotlin">
-~~~{.kt}
- import MyGame.Sample.* //The `flatc` generated files. (Monster, Vec3, etc.)
-
- import com.google.flatbuffers.FlatBufferBuilder
-~~~
-</div>
<div class="language-csharp">
~~~{.cs}
using FlatBuffers;
@@ -2273,8 +2033,8 @@ import './monster_my_game.sample_generated.dart' as myGame;
</div>
<div class="language-lobster">
~~~{.lobster}
- import from "../lobster/" // Where to find flatbuffers.lobster
- import monster_generated
+ include from "../lobster/" // Where to find flatbuffers.lobster
+ include "monster_generated.lobster"
~~~
</div>
<div class="language-rust">
@@ -2322,15 +2082,6 @@ won't work**
Monster monster = Monster.getRootAsMonster(buf);
~~~
</div>
-<div class="language-kotlin">
-~~~{.kt}
- val bytes = /* the data you just read */
- val buf = java.nio.ByteBuffer.wrap(bytes)
-
- // Get an accessor to the root object inside the buffer.
- Monster monster = Monster.getRootAsMonster(buf)
-~~~
-</div>
<div class="language-csharp">
~~~{.cs}
byte[] bytes = /* the data you just read */
@@ -2438,16 +2189,6 @@ myGame.Monster monster = new myGame.Monster(data);
~~~
</div>
-<div class="language-swift">
-~~~{.swift}
- // create a ByteBuffer(:) from an [UInt8] or Data()
- let buf = // Get your data
-
- // Get an accessor to the root object inside the buffer.
- let monster = Monster.getRootAsMonster(bb: ByteBuffer(bytes: buf))
-~~~
-</div>
-
If you look in the generated files from the schema compiler, you will see it generated
accessors for all non-`deprecated` fields. For example:
@@ -2465,13 +2206,6 @@ accessors for all non-`deprecated` fields. For example:
String name = monster.name();
~~~
</div>
-<div class="language-kotlin">
-~~~{.kt}
- val hp = monster.hp
- val mana = monster.mana
- val name = monster.name
-~~~
-</div>
<div class="language-csharp">
~~~{.cs}
// For C#, unlike most other languages support by FlatBuffers, most values (except for
@@ -2555,14 +2289,6 @@ accessors for all non-`deprecated` fields. For example:
~~~
</div>
-<div class="language-swift">
-~~~{.swift}
- let hp = monster.hp
- let mana = monster.mana
- let name = monster.name // returns an optional string
-~~~
-</div>
-
These should hold `300`, `150`, and `"Orc"` respectively.
*Note: The default value `150` wasn't stored in `mana`, but we are still able to retrieve it.*
@@ -2585,14 +2311,6 @@ To access sub-objects, in the case of our `pos`, which is a `Vec3`:
float z = pos.z();
~~~
</div>
-<div class="language-kotlin">
-~~~{.kt}
- val pos = monster.pos!!
- val x = pos.x
- val y = pos.y
- val z = pos.z
-~~~
-</div>
<div class="language-csharp">
~~~{.cs}
var pos = monster.Pos.Value;
@@ -2688,15 +2406,6 @@ To access sub-objects, in the case of our `pos`, which is a `Vec3`:
~~~
</div>
-<div class="language-swift">
-~~~{.swift}
- let pos = monster.pos
- let x = pos.x
- let y = pos.y
- let z = pos.z
-~~~
-</div>
-
`x`, `y`, and `z` will contain `1.0`, `2.0`, and `3.0`, respectively.
*Note: Had we not set `pos` during serialization, it would be a `NULL`-value.*
@@ -2708,7 +2417,7 @@ FlatBuffers `vector`.
<div class="language-cpp">
~~~{.cpp}
auto inv = monster->inventory(); // A pointer to a `flatbuffers::Vector<>`.
- auto inv_len = inv->size();
+ auto inv_len = inv->Length();
auto third_item = inv->Get(2);
~~~
</div>
@@ -2718,12 +2427,6 @@ FlatBuffers `vector`.
byte thirdItem = monster.inventory(2);
~~~
</div>
-<div class="language-kotlin">
-~~~{.kotlin}
- val invLength = monster.inventoryLength
- val thirdItem = monster.inventory(2)!!
-~~~
-</div>
<div class="language-csharp">
~~~{.cs}
int invLength = monster.InventoryLength;
@@ -2797,27 +2500,13 @@ FlatBuffers `vector`.
~~~
</div>
-<div class="language-swift">
-~~~{.swift}
- // Get a the count of objects in the vector
- let count = monster.inventoryCount
-
- // get item at index 4
- let object = monster.inventory(at: 4)
-
- // or you can fetch the entire array
- let inv = monster.inventory
- // inv[4] should equal object
-~~~
-</div>
-
For `vector`s of `table`s, you can access the elements like any other vector,
except your need to handle the result as a FlatBuffer `table`:
<div class="language-cpp">
~~~{.cpp}
auto weapons = monster->weapons(); // A pointer to a `flatbuffers::Vector<>`.
- auto weapon_len = weapons->size();
+ auto weapon_len = weapons->Length();
auto second_weapon_name = weapons->Get(1)->name()->str();
auto second_weapon_damage = weapons->Get(1)->damage()
~~~
@@ -2829,13 +2518,6 @@ except your need to handle the result as a FlatBuffer `table`:
short secondWeaponDamage = monster.weapons(1).damage();
~~~
</div>
-<div class="language-kotlin">
-~~~{.kt}
- val weaponsLength = monster.weaponsLength
- val secondWeaponName = monster.weapons(1)!!.name
- val secondWeaponDamage = monster.weapons(1)!!.damage
-~~~
-</div>
<div class="language-csharp">
~~~{.cs}
int weaponsLength = monster.WeaponsLength;
@@ -2923,16 +2605,6 @@ except your need to handle the result as a FlatBuffer `table`:
let second_weapon_damage = wep2.damage();
~~~
</div>
-<div class="language-swift">
-~~~{.swift}
- // Get the count of weapon objects
- let wepsCount = monster.weaponsCount
-
- let weapon2 = monster.weapons(at: 1)
- let weaponName = weapon2.name
- let weaponDmg = weapon2.damage
-~~~
-</div>
Last, we can access our `Equipped` FlatBuffer `union`. Just like when we created
the `union`, we need to get both parts of the `union`: the type and the data.
@@ -2966,19 +2638,6 @@ We can access the type to dynamically cast the data as needed (since the
}
~~~
</div>
-<div class="language-kotlin">
-~~~{.kt}
- val unionType = monster.EquippedType
-
- if (unionType == Equipment.Weapon) {
- val weapon = monster.equipped(Weapon()) as Weapon // Requires explicit cast
- // to `Weapon`.
-
- val weaponName = weapon.name // "Axe"
- val weaponDamage = weapon.damage // 5
- }
-~~~
-</div>
<div class="language-csharp">
~~~{.cs}
var unionType = monster.EquippedType;
@@ -3120,17 +2779,6 @@ We can access the type to dynamically cast the data as needed (since the
~~~
</div>
-<div class="language-swift">
-~~~{.swift}
- // Get and check if the monster has an equipped item
- if monster.equippedType == .weapon {
- let _weapon = monster.equipped(type: Weapon.self)
- let name = _weapon.name // should return "Axe"
- let dmg = _weapon.damage // should return 5
- }
-~~~
-</div>
-
## Mutating FlatBuffers
As you saw above, typically once you have created a FlatBuffer, it is read-only
@@ -3166,14 +2814,6 @@ mutators like so:
monster.mutateInventory(0, 1); // Set vector element.
~~~
</div>
-<div class="language-kotlin">
-~~~{.kt}
- val monster = Monster.getRootAsMonster(buf)
- monster.mutateHp(10) // Set table field.
- monster.pos!!.mutateZ(4) // Set struct field.
- monster.mutateInventory(0, 1) // Set vector element.
-~~~
-</div>
<div class="language-csharp">
~~~{.cs}
var monster = Monster.GetRootAsMonster(buf);
@@ -3234,15 +2874,6 @@ mutators like so:
~~~
</div>
-<div class="language-swift">
-~~~{.swift}
- let monster = Monster.getRootAsMonster(bb: ByteBuffer(bytes: buf))
- monster.mutate(hp: 10) // mutates a value in a table
- monster.pos.mutate(z: 4) // mutates a value in a struct
- monster.mutate(inventory: 6, at index: 0) // mutates a value in an Scalar array
-~~~
-</div>
-
We use the somewhat verbose term `mutate` instead of `set` to indicate that this
is a special use case, not to be confused with the default way of constructing
FlatBuffer data.
@@ -3266,17 +2897,15 @@ If this is not sufficient, other ways of mutating FlatBuffers may be supported
in your language through an object based API (`--gen-object-api`) or reflection.
See the individual language documents for support.
-## Using `flatc` as a JSON Conversion Tool
+## JSON with FlatBuffers
-If you are working with C, C++, or Lobster, you can parse JSON at runtime.
-If your language does not support JSON at the moment, `flatc` may provide an
-alternative. Using `flatc` is often the preferred method, as it doesn't require you to
-add any new code to your program. It is also efficient, since you can ship with
-the binary data. The drawback is that it requires an extra step for your
-users/developers to perform (although it may be able to be automated
-as part of your compilation).
+#### Using `flatc` as a Conversion Tool
-#### JSON to binary representation
+This is often the preferred method to use JSON with FlatBuffers, as it doesn't
+require you to add any new code to your program. It is also efficient, since you
+can ship with the binary data. The drawback is that it requires an extra step
+for your users/developers to perform (although it may be able to be automated
+as part of your compilation).
Lets say you have a JSON file that describes your monster. In this example,
we will use the file `flatbuffers/samples/monsterdata.json`.
@@ -3286,31 +2915,16 @@ Here are the contents of the file:
~~~{.json}
{
pos: {
- x: 1.0,
- y: 2.0,
- z: 3.0
+ x: 1,
+ y: 2,
+ z: 3
},
hp: 300,
- name: "Orc",
- weapons: [
- {
- name: "axe",
- damage: 100
- },
- {
- name: "bow",
- damage: 90
- }
- ],
- equipped_type: "Weapon",
- equipped: {
- name: "bow",
- damage: 90
- }
+ name: "Orc"
}
~~~
-You can run this file through the `flatc` compiler with the `-b` flag and
+You can run this file through the `flatc` compile with the `-b` flag and
our `monster.fbs` schema to produce a FlatBuffer binary file.
~~~{.sh}
@@ -3339,30 +2953,6 @@ for `flatcc` to support this.*
Guide for more information.*
</div>
-#### FlatBuffer binary to JSON
-
-Converting from a FlatBuffer binary representation to JSON is supported as well:
-~~~{.sh}
-./../flatc --json --raw-binary monster.fbs -- monsterdata.bin
-~~~
-This will convert `monsterdata.bin` back to its original JSON representation.
-You need to pass the corresponding FlatBuffers schema so that flatc knows how to
-interpret the binary buffer. Since `monster.fbs` does not specify an explicit
-`file_identifier` for binary buffers, `flatc` needs to be forced into reading
-the `.bin` file using the `--raw-binary` option.
-
-The FlatBuffer binary representation does not explicitly encode default values,
-therefore they are not present in the resulting JSON unless you specify
-`--defaults-json`.
-
-If you intend to process the JSON with other tools, you may consider switching
-on `--strict-json` so that identifiers are quoted properly.
-
-*Note: The resulting JSON file is not necessarily identical with the original JSON.
-If the binary representation contains floating point numbers, floats and doubles
-are rounded to 6 and 12 digits, respectively, in order to represent them as
-decimals in the JSON document. *
-
## Advanced Features for Each Language
Each language has a dedicated `Use in XXX` page in the Programmer's Guide
@@ -3374,13 +2964,10 @@ For your chosen language, see:
[Use in C++](@ref flatbuffers_guide_use_cpp)
</div>
<div class="language-java">
-[Use in Java](@ref flatbuffers_guide_use_java)
-</div>
-<div class="language-kotlin">
-[Use in Kotlin](@ref flatbuffers_guide_use_kotlin)
+[Use in Java/C#](@ref flatbuffers_guide_use_java_c-sharp)
</div>
<div class="language-csharp">
-[Use in C#](@ref flatbuffers_guide_use_c-sharp)
+[Use in Java/C#](@ref flatbuffers_guide_use_java_c-sharp)
</div>
<div class="language-go">
[Use in Go](@ref flatbuffers_guide_use_go)
@@ -3412,7 +2999,5 @@ For your chosen language, see:
<div class="language-rust">
[Use in Rust](@ref flatbuffers_guide_use_rust)
</div>
-<div class="language-swift">
-[Use in Swift](@ref flatbuffers_guide_use_swift)
-</div>
+
<br>
diff --git a/docs/source/TypeScriptUsage.md b/docs/source/TypeScriptUsage.md
index 02aa239e..832c46ee 100644
--- a/docs/source/TypeScriptUsage.md
+++ b/docs/source/TypeScriptUsage.md
@@ -43,7 +43,7 @@ First, include the library and generated code. Then read the file into an
the ByteBuffer to the `getRootAsMonster` function.
~~~{.ts}
- // note: import flatbuffers with your desired import method
+ // note: import flabuffers with your desired import method
import { MyGame } from './monster_generated';
diff --git a/docs/source/doxyfile b/docs/source/doxyfile
index b381e3dd..6ba3c108 100644
--- a/docs/source/doxyfile
+++ b/docs/source/doxyfile
@@ -778,7 +778,7 @@ INPUT = "FlatBuffers.md" \
"../../php/FlatbufferBuilder.php" \
"../../net/FlatBuffers/FlatBufferBuilder.cs" \
"../../include/flatbuffers/flatbuffers.h" \
- "../../go/builder.go" \
+ "../../go/builder.go"
"../../rust/flatbuffers/src/builder.rs"
# This tag can be used to specify the character encoding of the source files
diff --git a/docs/source/doxygen_layout.xml b/docs/source/doxygen_layout.xml
index 72888f95..a2325075 100644
--- a/docs/source/doxygen_layout.xml
+++ b/docs/source/doxygen_layout.xml
@@ -29,10 +29,8 @@
title="Use in C"/>
<tab type="user" url="@ref flatbuffers_guide_use_go"
title="Use in Go"/>
- <tab type="user" url="@ref flatbuffers_guide_use_java"
- title="Use in Java"/>
- <tab type="user" url="@ref flatbuffers_guide_use_c-sharp"
- title="Use in C#"/>
+ <tab type="user" url="@ref flatbuffers_guide_use_java_c-sharp"
+ title="Use in Java/C#"/>
<tab type="user" url="@ref flatbuffers_guide_use_javascript"
title="Use in JavaScript"/>
<tab type="user" url="@ref flatbuffers_guide_use_typescript"
@@ -50,7 +48,7 @@
<tab type="user" url="@ref flatbuffers_guide_use_rust"
title="Use in Rust"/>
<tab type="user" url="@ref flexbuffers"
- title="FlexBuffers (Schema-less version)"/>
+ title="Schema-less version"/>
<tab type="usergroup" url="" title="gRPC">
<tab type="user" url="@ref flatbuffers_grpc_guide_use_cpp"
title="Use in C++"/>