mirror of https://github.com/vee1e/flatbuffers - FlatBuffers: Memory Efficient Serialization Library
Find a file
Adam Oleksy 5822c1c8dd
Fix dereference operator of VectorIterator to structures (#8425)
For Vector or Array of structures the dereference operator of an
iterator returns the pointer to the structure. However, IndirectHelper,
which is used in the implementation of this operator, is instantiated
in the way that the IndirectHelper::Read returns structure by value.

This is because, Vector and Array instantiate IndirectHelper with
const T*, but VectorIterator instantiates IndirectHelper with T. There
are three IndirectHelper template definition: first for T, second for
Offset<T> and the last one for const T*. Those have different
IndirectHelper:Read implementations and (more importantly) return type.
This is the reason of mismatch in VectorIterator::operator* between
return type declaration and what was exactly returned.

That is, for Array<T,...> where T is scalar the VectorIterator is
instantiated as VectorIterator<T, T>, dereference operator returns T
and its implementation uses IndirectHelper<T> which Read function
returns T.
When T is not scalar, then VectorIterator is instantiated as
VectorIterator<T, const T *>, dereference operator returns const T * and
its implementation uses IndirectHelper<T> which Read function returns T.

The fix is done as follows:
* implement type trait is_specialization_of_Offset and
 is_specialization_of_Offset64,
* change partial specialization of IndirectHelper with const T * that
 it is instantiated by T and enabled only if T is not scalar and not
 specialization of Offset or Offset64,
* remove type differentiation (due to scalar) from Array..

The above makes the IndirectHelper able to correctly instantiate itself
basing only on T. Thus, the instantiation in VectorIterator correctly
instantiate IndirectHelper::Read function, especially the return type.
2025-05-17 22:01:09 -07:00
.bazelci Adds swift 6 to the build matrix (#8414) 2025-02-04 09:11:46 -08:00
.github Adds swift 6 to the build matrix (#8414) 2025-02-04 09:11:46 -08:00
android FlatBuffers Version 25.2.10 2025-02-10 20:25:03 -08:00
bazel
benchmarks [Swift] Adds new API to reduce memory copying within swift (#8484) 2025-03-18 07:48:39 +01:00
CMake FlatBuffers Version 25.2.10 2025-02-10 20:25:03 -08:00
conan
dart FlatBuffers Version 25.2.10 2025-02-10 20:25:03 -08:00
docs [Swift] Adds new API to reduce memory copying within swift (#8484) 2025-03-18 07:48:39 +01:00
examples/go-echo Go: make generated code more compliant to "go fmt" (#7907) 2023-04-26 05:19:07 +00:00
go Support file_identifier in Go (#7904) 2023-04-26 05:15:09 +00:00
goldens FlatBuffers Version 25.2.10 2025-02-10 20:25:03 -08:00
grpc [Swift] Adds new API to reduce memory copying within swift (#8484) 2025-03-18 07:48:39 +01:00
include Fix dereference operator of VectorIterator to structures (#8425) 2025-05-17 22:01:09 -07:00
java FlatBuffers Version 25.2.10 2025-02-10 20:25:03 -08:00
js
kotlin Update libs.versions.toml (#8387) 2024-09-06 01:26:51 +00:00
lobster
lua
mjs
net/FlatBuffers FlatBuffers Version 25.2.10 2025-02-10 20:25:03 -08:00
nim
php Fix PHP byte validation and reenable builds (#7670) 2022-11-29 08:12:28 -08:00
python FlatBuffers Version 25.2.10 2025-02-10 20:25:03 -08:00
reflection Fix npm bzlmod (#8506) 2025-01-23 21:01:31 +00:00
rust FlatBuffers Version 25.2.10 2025-02-10 20:25:03 -08:00
samples [Swift] Adds new API to reduce memory copying within swift (#8484) 2025-03-18 07:48:39 +01:00
scripts [Swift] Adds new API to reduce memory copying within swift (#8484) 2025-03-18 07:48:39 +01:00
snap
src [C++] Fixes #8446 (#8447) 2025-04-14 08:54:10 -07:00
swift [Swift] Adds new API to reduce memory copying within swift (#8484) 2025-03-18 07:48:39 +01:00
tests Fix dereference operator of VectorIterator to structures (#8425) 2025-05-17 22:01:09 -07:00
ts Rust reflection: simplify dependencies, fix Android build compatibility (#8512) 2025-02-04 08:40:31 -08:00
.bazelignore Test external modules explicitly in CI (#8507) 2025-01-23 23:04:06 +00:00
.bazelrc Bump the versions of all aspect Bazel dependencies (#8508) 2025-01-24 10:09:22 -08:00
.clang-format
.clang-tidy Add clang-tidy, fix some bugpron problems. (#7708) 2022-12-14 21:58:55 -08:00
.editorconfig Editorconfig: als configure to trim whitespaces end EOL. (#7833) 2023-02-27 19:56:18 -08:00
.eslintrc.js
.gitattributes
.gitignore Add support for Bzlmod (#8494) 2025-01-21 16:53:46 -08:00
.npmrc Migrate from rules_nodejs to rules_js/rules_ts (take 2) (#7928) 2023-05-03 11:48:15 -07:00
BUILD.bazel Remove Bazel WORKSPACE setup. (#8509) 2025-01-24 18:16:10 +00:00
build_defs.bzl Remove Bazel WORKSPACE setup. (#8509) 2025-01-24 18:16:10 +00:00
CHANGELOG.md FlatBuffers Version 25.2.10 2025-02-10 20:25:03 -08:00
CMakeLists.txt [gRPC] Update the code generator for Python to produce typed handlers (#8326) 2024-06-18 16:02:57 -07:00
composer.json
conanfile.py Updated remaining usages of LICENSE.txt 2023-03-03 12:01:08 -08:00
CONTRIBUTING.md
extensions.bzl Add support for Bzlmod (#8494) 2025-01-21 16:53:46 -08:00
FlatBuffers.podspec FlatBuffers Version 25.2.10 2025-02-10 20:25:03 -08:00
Formatters.md
LICENSE Rename LICENSE.txt to LICENSE (#7808) 2023-01-30 21:36:30 -08:00
MODULE.bazel FlatBuffers Version 25.2.10 2025-02-10 20:25:03 -08:00
package.json FlatBuffers Version 25.2.10 2025-02-10 20:25:03 -08:00
Package.swift Adds swift 6 to the build matrix (#8414) 2025-02-04 09:11:46 -08:00
pnpm-lock.yaml [TS/JS] Upgrade dependencies (#7996) 2023-12-13 16:57:46 -08:00
README.md cleanup github ci 2025-01-13 22:07:54 -08:00
SECURITY.md
swift.swiftformat [Swift] Adds new API to reduce memory copying within swift (#8484) 2025-03-18 07:48:39 +01:00
tsconfig.json Simplify and fix TypeScript compilation output (#7815) 2023-02-06 13:10:20 -08:00
tsconfig.mjs.json [TS/JS] Upgrade dependencies (#7996) 2023-12-13 16:57:46 -08:00
typescript.bzl Fix reflection.fbs import path (#8499) 2025-01-23 19:43:23 +00:00

logo FlatBuffers

Build status BuildKite status Fuzzing Status Discord Chat Twitter Follow Twitter Follow

FlatBuffers is a cross platform serialization library architected for maximum memory efficiency. It allows you to directly access serialized data without parsing/unpacking it first, while still having great forwards/backwards compatibility.

Quick Start

  1. Build the compiler for flatbuffers (flatc)

    Use cmake to create the build files for your platform and then perform the compilation (Linux example).

    cmake -G "Unix Makefiles"
    make -j
    
  2. Define your flatbuffer schema (.fbs)

    Write the schema to define the data you want to serialize. See monster.fbs for an example.

  3. Generate code for your language(s)

    Use the flatc compiler to take your schema and generate language-specific code:

    ./flatc --cpp --rust monster.fbs
    

    Which generates monster_generated.h and monster_generated.rs files.

  4. Serialize data

    Use the generated code, as well as the FlatBufferBuilder to construct your serialized buffer. (C++ example)

  5. Transmit/store/save Buffer

    Use your serialized buffer however you want. Send it to someone, save it for later, etc...

  6. Read the data

    Use the generated accessors to read the data from the serialized buffer.

    It doesn't need to be the same language/schema version, FlatBuffers ensures the data is readable across languages and schema versions. See the Rust example reading the data written by C++.

Documentation

Go to our landing page to browse our documentation.

Supported operating systems

  • Windows
  • macOS
  • Linux
  • Android
  • And any others with a recent C++ compiler (C++ 11 and newer)

Supported programming languages

Code generation and runtime libraries for many popular languages.

  1. C
  2. C++ - snapcraft.io
  3. C# - nuget.org
  4. Dart - pub.dev
  5. Go - go.dev
  6. Java - Maven
  7. JavaScript - NPM
  8. Kotlin
  9. Lobster
  10. Lua
  11. PHP
  12. Python - PyPI
  13. Rust - crates.io
  14. Swift - swiftpackageindex
  15. TypeScript - NPM
  16. Nim

Versioning

FlatBuffers does not follow traditional SemVer versioning (see rationale) but rather uses a format of the date of the release.

Contribution

To contribute to this project, see CONTRIBUTING.

Community

Security

Please see our Security Policy for reporting vulnerabilities.

Licensing

Flatbuffers is licensed under the Apache License, Version 2.0. See LICENSE for the full license text.