diff --git a/.gitignore b/.gitignore index 46d1ae419..5d7a88540 100755 --- a/.gitignore +++ b/.gitignore @@ -42,6 +42,7 @@ tests/monsterdata_go_wire.mon CMakeLists.txt.user CMakeScripts/** CTestTestfile.cmake +FlatBuffers.cbp build/Xcode/FlatBuffers.xcodeproj/project.xcworkspace/** build/Xcode/FlatBuffers.xcodeproj/xcuserdata/** FlatBuffers.xcodeproj/ diff --git a/CMakeLists.txt b/CMakeLists.txt index b837b71e3..2d48b72cd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -20,6 +20,8 @@ set(FlatBuffers_Compiler_SRCS include/flatbuffers/hash.h include/flatbuffers/idl.h include/flatbuffers/util.h + include/flatbuffers/reflection.h + include/flatbuffers/reflection_generated.h src/idl_parser.cpp src/idl_gen_cpp.cpp src/idl_gen_general.cpp @@ -112,6 +114,15 @@ function(compile_flatbuffers_schema_to_cpp SRC_FBS) DEPENDS flatc) endfunction() +function(compile_flatbuffers_schema_to_binary SRC_FBS) + get_filename_component(SRC_FBS_DIR ${SRC_FBS} PATH) + string(REGEX REPLACE "\\.fbs$" ".bfbs" GEN_BINARY_SCHEMA ${SRC_FBS}) + add_custom_command( + OUTPUT ${GEN_BINARY_SCHEMA} + COMMAND flatc -b --schema -o "${SRC_FBS_DIR}" "${CMAKE_CURRENT_SOURCE_DIR}/${SRC_FBS}" + DEPENDS flatc) +endfunction() + if(FLATBUFFERS_BUILD_TESTS) compile_flatbuffers_schema_to_cpp(tests/monster_test.fbs) include_directories(${CMAKE_CURRENT_BINARY_DIR}/tests) diff --git a/docs/html/index.html b/docs/html/index.html index 639c1dae4..291a2bdfd 100644 --- a/docs/html/index.html +++ b/docs/html/index.html @@ -54,7 +54,7 @@ $(document).ready(function(){initNavTree('index.html','');});

FlatBuffers is an efficient cross platform serialization library for C++, with support for Java, C# and Go. It was created at Google specifically for game development and other performance-critical applications.

-

It is available as open source under the Apache license, v2 (see LICENSE.txt).

+

It is available as Open Source on GitHub under the Apache license, v2 (see LICENSE.txt).

Why use FlatBuffers?

Online resources

diff --git a/docs/html/md__compiler.html b/docs/html/md__compiler.html index 65ec45120..9dd85c5a6 100644 --- a/docs/html/md__compiler.html +++ b/docs/html/md__compiler.html @@ -68,12 +68,14 @@ $(document).ready(function(){initNavTree('md__compiler.html','');});
  • -o PATH : Output all generated files to PATH (either absolute, or relative to the current directory). If omitted, PATH will be the current directory. PATH should end in your systems path separator, e.g. / or \.
  • -I PATH : when encountering include statements, attempt to load the files from this path. Paths will be tried in the order given, and if all fail (or none are specified) it will try to load relative to the path of the schema file being parsed.
  • --strict-json : Require & generate strict JSON (field names are enclosed in quotes, no trailing commas in tables/vectors). By default, no quotes are required/generated, and trailing commas are allowed.
  • +
  • --defaults-json : Output fields whose value is equal to the default value when writing JSON text.
  • --no-prefix : Don't prefix enum values in generated C++ by their enum type.
  • --gen-includes : (deprecated), instead use:
  • --no-includes : Don't generate include statements for included schemas the generated file depends on (C++).
  • --gen-mutable : Generate additional non-const accessors for mutating FlatBuffers in-place.
  • --raw-binary : Allow binaries without a file_indentifier to be read. This may crash flatc given a mismatched schema.
  • -
  • --proto: Expect input files to be .proto files (protocol buffers). Output the corresponding .fbs file. Currently supports: package, message, enum. Does not support, but will skip without error: import, option. Does not support, will generate error: service, extend, extensions, oneof, group, custom options, nested declarations.
  • +
  • --proto: Expect input files to be .proto files (protocol buffers). Output the corresponding .fbs file. Currently supports: package, message, enum. Does not support, but will skip without error: import, option. Does not support, will generate error: service, extend, extensions, oneof, group, custom options, nested declarations.
  • +
  • --schema: Serialize schemas instead of JSON (use with -b). This will output a binary version of the specified schema that itself corresponds to the reflection/reflection.fbs schema. Loading this binary file is the basis for reflection functionality.
  • diff --git a/docs/html/md__cpp_usage.html b/docs/html/md__cpp_usage.html index 2217273de..27cdd0b75 100644 --- a/docs/html/md__cpp_usage.html +++ b/docs/html/md__cpp_usage.html @@ -114,8 +114,14 @@ $(document).ready(function(){initNavTree('md__cpp_usage.html','');});

    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.

    After the above mutations, you can send on the FlatBuffer to a new recipient without any further work!

    Note that any mutate_ functions on tables return a bool, which is false if the field we're trying to set isn't present in the buffer. Fields are not present if they weren't set, or even if they happen to be equal to the default value. For example, in the creation code above we set the mana field to 150, which is the default value, so it was never stored in the buffer. Trying to call mutate_mana() on such data will return false, and the value won't actually be modified!

    -

    There's two ways around this. First, you can call ForceDefaults() on a FlatBufferBuilder to force all fields you set to actually be written. This of course increases the size of the buffer somewhat, but this may be acceptable for a mutable buffer.

    -

    Alternatively, you can use mutation functions that are able to insert fields and change the size of things. These functions are expensive however, since they need to resize the buffer and create new data.

    +

    One way to solve this is to call ForceDefaults() on a FlatBufferBuilder to force all fields you set to actually be written. This of course increases the size of the buffer somewhat, but this may be acceptable for a mutable buffer.

    +

    Alternatively, you can use the more powerful reflection functionality:

    +

    Reflection (& Resizing)

    +

    If the above ways of accessing a buffer are still too static for you, there is experimental support for reflection in FlatBuffers, allowing you to read and write data even if you don't know the exact format of a buffer, and even allows you to change sizes of strings and vectors in-place.

    +

    The way this works is very elegant, there is actually a FlatBuffer schema that describes schemas (!) which you can find in reflection/reflection.fbs. The compiler flatc can write out any schemas it has just parsed as a binary FlatBuffer, corresponding to this meta-schema.

    +

    Loading in one of these binary schemas at runtime allows you traverse any FlatBuffer data that corresponds to it without knowing the exact format. You can query what fields are present, and then read/write them after.

    +

    For convenient field manipulation, you can include the header flatbuffers/reflection.h which includes both the generated code from the meta schema, as well as a lot of helper functions.

    +

    And example of usage for the moment you can find in test.cpp/ReflectionTest().

    Storing maps / dictionaries in a FlatBuffer

    FlatBuffers doesn't support maps 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 std::map or similar.

    To use it: