FlatBuffers: Memory Efficient Serialization Library
Go to file
Max Burke 6da1cf79d9 [rust] Add use declarations to Rust-generated bindings for imported FB definitions (#5645)
* Bugfix for Rust generation of union fields named with language keywords

Looking at ParseField, it appears that in the case of unions, an extra field with a `UnionTypeFieldSuffix` is added to the type definition, however, if the name of this field is a keyword in the target language, it isn't escaped.

For example, if generating code for rust for a union field named `type`, flatc will generate a (non-keyword escaped) field named `type_type` for this hidden union field, and one (keyword escaped) called `type_` for the actual union contents.

When the union accessors are generated, they refer to this `type_type` field, but they will escape it mistakenly, generating code like this:

```
  #[inline]
  #[allow(non_snake_case)]
  pub fn type__as_int(&self) -> Option<Int<'a>> {
    if self.type__type() == Type::Int {
      self.type_().map(|u| Int::init_from_table(u))
    } else {
      None
    }
  }
```

Which will fail to build because the field is called `self.type_type()`, not `self.type__type()`.

* [Rust] Add crate-relative use statements for FBS includes.

At present if a flatbuffer description includes a reference to a type in
another file, the generated Rust code needs to be hand-modified to add
the appropriate `use` statements.

This assumes that the dependencies are built into the same crate, which
I think is a reasonable assumption?

* Revert "[Rust] Add crate-relative use statements for FBS includes."

This reverts commit d554d79fec.

* Add updated generated test files.

* Fixing Rust test harness to handle new includes.

Test binaries need to add references to generated code that's
transitively included.

This also has the knock-on in that this code (which is referenced by
include directives directly in the flatbuffer schema files) also needs
to be generated, hence the changes to generate_code.sh.

* Test harnesses expect test data to be checked in.

Put include_test2 files into the same directory as the include_test2
schema definition.

Update all code generation scripts (forgot the batch file from last
time).

Path updates in Rust test.

* Include updated generated code

* Address comments raised in PR

* Fix failing Rust tests.

* Previous merge clobbered this branch change.

* Add updated imports to benchmarks.

* Clarifying comment per PR request

* Update documentation comments per feedback

* Remove non-Rust generated files for include tests, per feedback from @rw/@aardappel

* Broken code generation batch file

* Fix typo

* Add TODO for tidying up use declaration traversal sometime in the future

* Update test files.
2020-01-19 14:47:28 -08:00
.appveyor Add support for fixed-size arrays (#5313) 2019-06-18 00:15:13 +02:00
.bazelci Don't test on Ubuntu 14.04 (#5302) 2019-04-24 10:28:35 -07:00
.github Improved pull request & clang-format instructions. 2019-11-07 14:37:33 -08:00
.travis Add CMake 'generated_code' target to simplify resolution of build dependencies (#5697) 2020-01-06 15:26:41 -08:00
CMake Add RPM packaging support (#5177) 2019-02-21 20:06:04 +01:00
android Removed code_generators.cpp from library targets 2020-01-02 08:50:39 -08:00
conan Update Conan version Automatically (#5027) 2018-11-12 08:49:42 -08:00
dart [Dart] Fix prepare space for writeListInt64 and writeListUint64 (#5654) 2019-12-18 11:23:54 -08:00
docs Added create function for swift (#5707) 2020-01-13 12:34:06 -08:00
go [go]add Name() for ForceCodec interface (#5486) 2019-08-19 15:32:04 -07:00
grpc Fix --incompatible_load_cc_rules_from_bzl (#5683) 2019-12-26 10:03:22 -08:00
include/flatbuffers [C++] Fix for printing of enum in case output_enum_identifiers=1. (#5706) 2020-01-16 14:12:25 -08:00
java/com/google/flatbuffers [Java] Replace Table.UTF8_CHARSET with StandardCharsets.UTF_8 (#5696) 2020-01-06 09:28:19 -08:00
js [JS/TS] Size prefix support (#5326) 2019-05-16 11:43:31 -07:00
lobster Lobster: added builder API for tables 2019-05-22 19:42:13 -07:00
lua Lua cleanup (#5624) 2019-11-14 15:46:46 -08:00
net/FlatBuffers Fixed struct initialization error on older versions of C# 2019-12-23 17:35:54 -08:00
php Performance improvement to generated+supporting PHP (#5080) 2018-12-20 16:10:20 -08:00
python Python: Add forceDefaults opt to python Builder (#5564) 2019-10-17 15:25:05 -07:00
reflection Add flatc '--cpp_std' switch (#5656) 2019-12-23 12:13:48 -08:00
rust/flatbuffers [Rust] Bump smallvec version to 1.0 (#5621) 2019-11-11 09:52:26 -08:00
samples Added create function for swift (#5707) 2020-01-13 12:34:06 -08:00
snap Update snap include path instruction (#5297) 2019-04-18 15:15:21 -07:00
src [rust] Add use declarations to Rust-generated bindings for imported FB definitions (#5645) 2020-01-19 14:47:28 -08:00
swift [Swift] Support create long string (#5709) 2020-01-16 12:08:59 -08:00
tests [rust] Add use declarations to Rust-generated bindings for imported FB definitions (#5645) 2020-01-19 14:47:28 -08:00
.clang-format Made all C++ files clang-formatted. 2017-12-21 11:45:02 -08:00
.editorconfig Unify line ending rules in '.editorconfig' and '.gitattributes' (#5231) 2019-03-18 12:47:07 -07:00
.gitattributes Unify line ending rules in '.editorconfig' and '.gitattributes' (#5231) 2019-03-18 12:47:07 -07:00
.gitignore [Swift] Swift implementation 🎉🎉 (#5603) 2020-01-09 12:12:10 -08:00
.travis.yml Add `--clean-first` to the cmake-build command (travis) (#5574) 2019-10-21 10:11:32 -07:00
BUILD Split Bazel targets into multiple packages (#5640) 2019-12-02 14:14:48 -08:00
CMakeLists.txt [Swift] Swift implementation 🎉🎉 (#5603) 2020-01-09 12:12:10 -08:00
CONTRIBUTING.md Fixed link to Google C++ Style Guide. 2017-02-08 16:37:25 -08:00
LICENSE.txt Fixed Apache license not using canonical version. 2019-11-04 17:15:56 -08:00
WORKSPACE Upgrade rules_go (#5684) 2019-12-26 10:07:15 -08:00
appveyor.yml Add flatc '--cpp_std' switch (#5656) 2019-12-23 12:13:48 -08:00
build_defs.bzl [Bazel] Add support for compatible_with and restricted_to (#5681) 2019-12-26 09:58:48 -08:00
composer.json (PHP) add experimental support for PHP language. 2015-11-18 00:26:39 +09:00
conanfile.py Update Conan version Automatically (#5027) 2018-11-12 08:49:42 -08:00
package.json Bumped version to 1.11.0 2019-04-24 11:34:53 -07:00
pom.xml Enforce matching version in Java and C#. 2019-05-31 12:15:19 -07:00
readme.md Minor doc updates: FlexBuffers C#, Discord, CppUsage. 2019-12-26 12:36:41 -08:00

readme.md

logo FlatBuffers

Build Status Build status Join the chat at https://gitter.im/google/flatbuffers Discord Chat 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.

Go to our landing page to browse our documentation.

Supported operating systems

  • Windows
  • MacOS X
  • Linux
  • Android
  • And any others with a recent C++ compiler.

Supported programming languages

  • C++
  • C#
  • C
  • Dart
  • Go
  • Java
  • JavaScript
  • Lobster
  • Lua
  • PHP
  • Python
  • Rust
  • TypeScript

and more in progress...

Contribution

To contribute to this project, see CONTRIBUTING.

Licensing

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