FlatBuffers: Memory Efficient Serialization Library
Go to file
Wouter van Oortmerssen 7b94eab2b1 Add CodeWriter utility class.
Helps simplify code generation code.  Instead of this:
  code += "inline const " + cpp_qualified_name + " *Get";
  code += name;
  code += "(const void *buf) {\n  return flatbuffers::GetRoot<";
  code += cpp_qualified_name + ">(buf);\n}\n\n";

You do this:
  code.SetValue("NAME", struct_def.name);
  code.SetValue("CPP_NAME", cpp_qualified_name);
  code += "inline const {{CPP_NAME}} *Get{{NAME}}(const void *buf) {";
  code += "  return flatbuffers::GetRoot<{{CPP_NAME}}>(buf);";
  code += "}";
  code += "";

Updated the CPP code generator to use the CodeWriter class.  Most of the
changes in the generated code are white-space changes, esp. around new
lines (since the code generator class automatically appends new lines
when appending a string).  Actual code changes include:

* Renamed "rehasher" to "_rehasher" for consistency with other args in
  Pack function.

* Renamed "union_obj" to "obj: in UnPack function.

* Always do "(void)_o;" to prevent unused variable warning in Create
  function (instead of only doing it if there are no fields) in order
  to avoid two-passes.

* Renamed padding variables from __paddingX to paddingX__.
  "Each name that contains a double underscore (_ _) [...] is reserved
   to the implementation for any use."  C++ standards 17.4.3.1.2.

* Add braces around switch cases.

* Calculate index as a separate statement in EnumName function, eg.
    const size_t index = ...;
    return EnumNamesX()[index];
  vs.
    return EnumNamesX()[...];

* Stored end table offset in variable in Finish() functions, eg.
    const auto end = fbb_.EndTable(start_, ...);
    auto o = flatbuffers::Offset<T>(end);
  vs.
    auto o = flatbuffers::Offset<T>(fbb_.EndTable(start, ...));

* Separate reinterpret_cast calls from function calls in Union
  functions, eg.
    auto ptr = reinterpret_cast<const T *>(obj);
    return ptr->UnPack(resolver);
  vs.
    return reinterpret_cast<const T *>(obj)->UnPack(resolver);

* Removed unecessary (void)(padding__X) no-ops from constructors, eg.
    Test(int16_t a, int8_t b) : ... {
      (void)__padding0;  // <-- Removed this line.
    }

In the idl_gen_cpp.cpp file itself, I refactored some code generation into
new functions: GenParam, GenNativeTable, GenVerifyCall, GenBuilders,
GenUnpackFieldStatement, and GenCreateParam.

Change-Id: I727b1bd8719d05b7ce33cbce00eb58fda817b25d
2017-01-13 17:44:42 -08:00
CMake Debianization with CPack 2016-08-25 00:00:22 +03:00
android Merge "Removed reference to deprecated NDK toolchain version." into ub-games-master 2016-05-23 23:49:56 +00:00
biicode Made .sh files all have same comment formatting. 2016-05-23 14:08:21 -07:00
docs Documentation improvements: style guide & guide lines. 2016-12-19 16:04:08 -08:00
go Resolve Go fmt and vet warnings (#4134) 2017-01-09 17:13:44 -08:00
grpc Fix C++ gRPC test with streaming method (#4123) 2016-12-28 11:50:41 -08:00
include/flatbuffers Add CodeWriter utility class. 2017-01-13 17:44:42 -08:00
java/com/google/flatbuffers Fixed Java LookupByKey functionality for Java 1.6 2016-08-26 13:58:16 -07:00
js Fix Closure Compiler warnings (#4067) 2016-10-21 14:52:42 -07:00
net/FlatBuffers Added IFlatbufferObject.cs file to project for .net. 2016-09-19 16:16:15 +09:00
php [PHP] Use mb_detect_encoding when available (#3952) 2016-11-16 09:54:57 -08:00
python Added missing licenses to some sh/cs/py files. 2016-05-23 09:51:41 -07:00
reflection Made .sh files all have same comment formatting. 2016-05-23 14:08:21 -07:00
samples Add CodeWriter utility class. 2017-01-13 17:44:42 -08:00
src Add CodeWriter utility class. 2017-01-13 17:44:42 -08:00
tests Add CodeWriter utility class. 2017-01-13 17:44:42 -08:00
.gitattributes Initial commit of the FlatBuffers code. 2014-06-10 13:53:28 -07:00
.gitignore chore(lint) (#4079) 2016-11-07 10:27:26 -08:00
.travis.yml Disabled broken biicode builds on Travis for the moment. 2016-02-22 11:33:14 -08:00
CMakeLists.txt Add CodeWriter utility class. 2017-01-13 17:44:42 -08:00
CONTRIBUTING.md Rename CONTRIBUTING to CONTRIBUTING.md 2016-07-13 07:57:36 +05:30
ISSUE_TEMPLATE.md Create basic issue template (#4107) 2016-12-07 14:17:30 -08:00
LICENSE.txt Fix Visual Studio 2012 build warning. 2015-09-11 14:35:34 -07:00
appveyor.yml Improving AppVeyor CI with other languages. 2016-12-12 18:02:13 -08:00
biicode.conf added .travis.yml file (build with original and biicode building); 2015-04-15 13:43:25 -07:00
composer.json (PHP) add experimental support for PHP language. 2015-11-18 00:26:39 +09:00
pom.xml Updated version to 1.5 2017-01-03 14:56:44 -08:00
readme.md Add Gitter badge (#4075) 2016-11-02 14:05:31 -07:00

readme.md

logo FlatBuffers

Join the chat at https://gitter.im/google/flatbuffers Build Status Build status

FlatBuffers is an efficient cross platform serialization library for games and other memory constrained apps. It allows you to directly access serialized data without unpacking/parsing it first, while still having great forwards/backwards compatibility.

Go to our landing page to browse our documentation.

Supported operating systems

  • Android
  • Windows
  • MacOS X
  • Linux

Supported programming languages

  • C++
  • C#
  • C
  • Go
  • Java
  • JavaScript
  • PHP
  • Python

and many more in progress...

Contribution

To contribute to this project, see CONTRIBUTING.

Integration

For applications on Google Play that integrate this tool, usage is tracked. This tracking is done automatically using the embedded version string (flatbuffer_version_string), and helps us continue to optimize it. Aside from consuming a few extra bytes in your application binary, it shouldn't affect your application at all. We use this information to let us know if FlatBuffers is useful and if we should continue to invest in it. Since this is open source, you are free to remove the version string but we would appreciate if you would leave it in.

Licensing

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