Commit 4c861daa authored by TGIshib's avatar TGIshib

Merge remote-tracking branch 'refs/remotes/google/master'

parents b7a26d73 f624065e
...@@ -96,9 +96,8 @@ set(FlatBuffers_GRPCTest_SRCS ...@@ -96,9 +96,8 @@ set(FlatBuffers_GRPCTest_SRCS
# source_group(Tests FILES ${FlatBuffers_Tests_SRCS}) # source_group(Tests FILES ${FlatBuffers_Tests_SRCS})
if(APPLE) if(APPLE)
set(CMAKE_CXX_FLAGS set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -stdlib=libc++")
"${CMAKE_CXX_FLAGS} -std=c++11 -stdlib=libc++ -Wall -pedantic -Werror \ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -pedantic -Werror -Wextra")
-Wextra")
elseif(CMAKE_COMPILER_IS_GNUCXX) elseif(CMAKE_COMPILER_IS_GNUCXX)
if(CYGWIN) if(CYGWIN)
set(CMAKE_CXX_FLAGS set(CMAKE_CXX_FLAGS
......
branches:
only:
- master
os: Visual Studio 2015
platform:
- x86
- x64
configuration:
- Debug
- Release
before_build:
- cmake -G"Visual Studio 10 2010"
build:
project: ALL_BUILD.vcxproj
#test_script:
# - Debug/flattests.exe
#artifacts:
# - path: Release/flatc.exe
# name: flatc.exe
Microsoft Visual Studio Solution File, Format Version 11.00
# Visual Studio 2010
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "flatc", "flatc.vcxproj", "{5B5857E1-64E2-4CED-A12E-45E1B3880496}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "flatsamplebinary", "flatsamplebinary.vcxproj", "{16FA5518-3DE1-4B15-A1E0-F4734C276FB4}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "flatsampletext", "flatsampletext.vcxproj", "{F0A15675-1017-4217-BB5B-3372F2C636AB}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "flattests", "flattests.vcxproj", "{DC7BBA00-9FC6-48AF-B7E9-12CA91AC02AA}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Win32 = Debug|Win32
Debug|x64 = Debug|x64
Release|Win32 = Release|Win32
Release|x64 = Release|x64
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{5B5857E1-64E2-4CED-A12E-45E1B3880496}.Debug|Win32.ActiveCfg = Debug|Win32
{5B5857E1-64E2-4CED-A12E-45E1B3880496}.Debug|Win32.Build.0 = Debug|Win32
{5B5857E1-64E2-4CED-A12E-45E1B3880496}.Debug|x64.ActiveCfg = Debug|x64
{5B5857E1-64E2-4CED-A12E-45E1B3880496}.Debug|x64.Build.0 = Debug|x64
{5B5857E1-64E2-4CED-A12E-45E1B3880496}.Release|Win32.ActiveCfg = Release|Win32
{5B5857E1-64E2-4CED-A12E-45E1B3880496}.Release|Win32.Build.0 = Release|Win32
{5B5857E1-64E2-4CED-A12E-45E1B3880496}.Release|x64.ActiveCfg = Release|x64
{5B5857E1-64E2-4CED-A12E-45E1B3880496}.Release|x64.Build.0 = Release|x64
{16FA5518-3DE1-4B15-A1E0-F4734C276FB4}.Debug|Win32.ActiveCfg = Debug|Win32
{16FA5518-3DE1-4B15-A1E0-F4734C276FB4}.Debug|Win32.Build.0 = Debug|Win32
{16FA5518-3DE1-4B15-A1E0-F4734C276FB4}.Debug|x64.ActiveCfg = Debug|x64
{16FA5518-3DE1-4B15-A1E0-F4734C276FB4}.Debug|x64.Build.0 = Debug|x64
{16FA5518-3DE1-4B15-A1E0-F4734C276FB4}.Release|Win32.ActiveCfg = Release|Win32
{16FA5518-3DE1-4B15-A1E0-F4734C276FB4}.Release|Win32.Build.0 = Release|Win32
{16FA5518-3DE1-4B15-A1E0-F4734C276FB4}.Release|x64.ActiveCfg = Release|x64
{16FA5518-3DE1-4B15-A1E0-F4734C276FB4}.Release|x64.Build.0 = Release|x64
{F0A15675-1017-4217-BB5B-3372F2C636AB}.Debug|Win32.ActiveCfg = Debug|Win32
{F0A15675-1017-4217-BB5B-3372F2C636AB}.Debug|Win32.Build.0 = Debug|Win32
{F0A15675-1017-4217-BB5B-3372F2C636AB}.Debug|x64.ActiveCfg = Debug|x64
{F0A15675-1017-4217-BB5B-3372F2C636AB}.Debug|x64.Build.0 = Debug|x64
{F0A15675-1017-4217-BB5B-3372F2C636AB}.Release|Win32.ActiveCfg = Release|Win32
{F0A15675-1017-4217-BB5B-3372F2C636AB}.Release|Win32.Build.0 = Release|Win32
{F0A15675-1017-4217-BB5B-3372F2C636AB}.Release|x64.ActiveCfg = Release|x64
{F0A15675-1017-4217-BB5B-3372F2C636AB}.Release|x64.Build.0 = Release|x64
{DC7BBA00-9FC6-48AF-B7E9-12CA91AC02AA}.Debug|Win32.ActiveCfg = Debug|Win32
{DC7BBA00-9FC6-48AF-B7E9-12CA91AC02AA}.Debug|Win32.Build.0 = Debug|Win32
{DC7BBA00-9FC6-48AF-B7E9-12CA91AC02AA}.Debug|x64.ActiveCfg = Debug|x64
{DC7BBA00-9FC6-48AF-B7E9-12CA91AC02AA}.Debug|x64.Build.0 = Debug|x64
{DC7BBA00-9FC6-48AF-B7E9-12CA91AC02AA}.Release|Win32.ActiveCfg = Release|Win32
{DC7BBA00-9FC6-48AF-B7E9-12CA91AC02AA}.Release|Win32.Build.0 = Release|Win32
{DC7BBA00-9FC6-48AF-B7E9-12CA91AC02AA}.Release|x64.ActiveCfg = Release|x64
{DC7BBA00-9FC6-48AF-B7E9-12CA91AC02AA}.Release|x64.Build.0 = Release|x64
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
This diff is collapsed.
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<LocalDebuggerWorkingDirectory>..\..\tests</LocalDebuggerWorkingDirectory>
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
<LocalDebuggerCommandArguments>-j -c -n -g --php --no-includes --gen-mutable --gen-object-api monster_test.fbs</LocalDebuggerCommandArguments>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<LocalDebuggerWorkingDirectory>..\..</LocalDebuggerWorkingDirectory>
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
<LocalDebuggerCommandArguments>-j -c -n -g -b -t monster_test.fbs monsterdata_test.golden</LocalDebuggerCommandArguments>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<LocalDebuggerCommandArguments>-j -c -g -n -b -t monster_test.fbs monsterdata_test.golden</LocalDebuggerCommandArguments>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<LocalDebuggerWorkingDirectory>..\..\tests</LocalDebuggerWorkingDirectory>
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<LocalDebuggerCommandArguments>-j -c -g -b -t monster_test.fbs monsterdata_test.json</LocalDebuggerCommandArguments>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<LocalDebuggerWorkingDirectory>..\..\tests</LocalDebuggerWorkingDirectory>
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
</PropertyGroup>
</Project>
\ No newline at end of file
This diff is collapsed.
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<LocalDebuggerWorkingDirectory>..\..</LocalDebuggerWorkingDirectory>
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<LocalDebuggerWorkingDirectory>..\..</LocalDebuggerWorkingDirectory>
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
</PropertyGroup>
</Project>
\ No newline at end of file
This diff is collapsed.
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<LocalDebuggerWorkingDirectory>..\..</LocalDebuggerWorkingDirectory>
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<LocalDebuggerWorkingDirectory>..\..</LocalDebuggerWorkingDirectory>
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<LocalDebuggerWorkingDirectory>..\..</LocalDebuggerWorkingDirectory>
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<LocalDebuggerWorkingDirectory>..\..</LocalDebuggerWorkingDirectory>
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
</PropertyGroup>
</Project>
\ No newline at end of file
This diff is collapsed.
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<LocalDebuggerWorkingDirectory>..\..</LocalDebuggerWorkingDirectory>
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<LocalDebuggerWorkingDirectory>..\..</LocalDebuggerWorkingDirectory>
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<LocalDebuggerWorkingDirectory>..\..</LocalDebuggerWorkingDirectory>
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<LocalDebuggerWorkingDirectory>..\..</LocalDebuggerWorkingDirectory>
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
</PropertyGroup>
</Project>
\ No newline at end of file
This diff is collapsed.
Building {#flatbuffers_guide_building} Building {#flatbuffers_guide_building}
======== ========
## Building with Visual Studio or Xcode projects
There are project files for Visual Studio and Xcode that should allow you
to build the compiler `flatc`, the samples and the tests out of the box.
## Building with CMake ## Building with CMake
Alternatively, the distribution comes with a `cmake` file that should allow The distribution comes with a `cmake` file that should allow
you to build project/make files for any platform. For details on `cmake`, see you to build project/make files for any platform. For details on `cmake`, see
<http://www.cmake.org>. In brief, depending on your platform, use one of <http://www.cmake.org>. In brief, depending on your platform, use one of
e.g.: e.g.:
......
...@@ -103,7 +103,7 @@ To use: ...@@ -103,7 +103,7 @@ To use:
cout << monsterobj->name; // This is now a std::string! cout << monsterobj->name; // This is now a std::string!
monsterobj->name = "Bob"; // Change the name. monsterobj->name = "Bob"; // Change the name.
FlatBufferBuilder fbb; FlatBufferBuilder fbb;
monsterobj->Pack(fbb); // Serialize into new buffer. CreateMonster(fbb, monsterobj->get()); // Serialize into new buffer.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
## Reflection (& Resizing) ## Reflection (& Resizing)
......
...@@ -151,10 +151,7 @@ inline void EndianCheck() { ...@@ -151,10 +151,7 @@ inline void EndianCheck() {
(void)endiantest; (void)endiantest;
} }
template<typename T> T EndianScalar(T t) { template<typename T> T EndianSwap(T t) {
#if FLATBUFFERS_LITTLEENDIAN
return t;
#else
#if defined(_MSC_VER) #if defined(_MSC_VER)
#pragma push_macro("__builtin_bswap16") #pragma push_macro("__builtin_bswap16")
#pragma push_macro("__builtin_bswap32") #pragma push_macro("__builtin_bswap32")
...@@ -163,8 +160,6 @@ template<typename T> T EndianScalar(T t) { ...@@ -163,8 +160,6 @@ template<typename T> T EndianScalar(T t) {
#define __builtin_bswap32 _byteswap_ulong #define __builtin_bswap32 _byteswap_ulong
#define __builtin_bswap64 _byteswap_uint64 #define __builtin_bswap64 _byteswap_uint64
#endif #endif
// If you're on the few remaining big endian platforms, we make the bold
// assumption you're also on gcc/clang, and thus have bswap intrinsics:
if (sizeof(T) == 1) { // Compile-time if-then's. if (sizeof(T) == 1) { // Compile-time if-then's.
return t; return t;
} else if (sizeof(T) == 2) { } else if (sizeof(T) == 2) {
...@@ -184,6 +179,13 @@ template<typename T> T EndianScalar(T t) { ...@@ -184,6 +179,13 @@ template<typename T> T EndianScalar(T t) {
#pragma pop_macro("__builtin_bswap32") #pragma pop_macro("__builtin_bswap32")
#pragma pop_macro("__builtin_bswap64") #pragma pop_macro("__builtin_bswap64")
#endif #endif
}
template<typename T> T EndianScalar(T t) {
#if FLATBUFFERS_LITTLEENDIAN
return t;
#else
return EndianSwap(t);
#endif #endif
} }
...@@ -356,7 +358,8 @@ public: ...@@ -356,7 +358,8 @@ public:
void MutateOffset(uoffset_t i, const uint8_t *val) { void MutateOffset(uoffset_t i, const uint8_t *val) {
assert(i < size()); assert(i < size());
assert(sizeof(T) == sizeof(uoffset_t)); assert(sizeof(T) == sizeof(uoffset_t));
WriteScalar(data() + i, val - (Data() + i * sizeof(uoffset_t))); WriteScalar(data() + i,
static_cast<uoffset_t>(val - (Data() + i * sizeof(uoffset_t))));
} }
// Get a mutable pointer to tables/strings inside this vector. // Get a mutable pointer to tables/strings inside this vector.
...@@ -1495,7 +1498,8 @@ class Table { ...@@ -1495,7 +1498,8 @@ class Table {
bool SetPointer(voffset_t field, const uint8_t *val) { bool SetPointer(voffset_t field, const uint8_t *val) {
auto field_offset = GetOptionalFieldOffset(field); auto field_offset = GetOptionalFieldOffset(field);
if (!field_offset) return false; if (!field_offset) return false;
WriteScalar(data_ + field_offset, val - (data_ + field_offset)); WriteScalar(data_ + field_offset,
static_cast<uoffset_t>(val - (data_ + field_offset)));
return true; return true;
} }
......
...@@ -39,8 +39,6 @@ enum BaseType { ...@@ -39,8 +39,6 @@ enum BaseType {
Vector = 14, Vector = 14,
Obj = 15, Obj = 15,
Union = 16, Union = 16,
MIN = None,
MAX = Union
}; };
inline const char **EnumNamesBaseType() { inline const char **EnumNamesBaseType() {
...@@ -135,6 +133,12 @@ inline flatbuffers::Offset<KeyValue> CreateKeyValue(flatbuffers::FlatBufferBuild ...@@ -135,6 +133,12 @@ inline flatbuffers::Offset<KeyValue> CreateKeyValue(flatbuffers::FlatBufferBuild
return builder_.Finish(); return builder_.Finish();
} }
inline flatbuffers::Offset<KeyValue> CreateKeyValue(flatbuffers::FlatBufferBuilder &_fbb,
const char *key = nullptr,
const char *value = nullptr) {
return CreateKeyValue(_fbb, key ? 0 : _fbb.CreateString(key), value ? 0 : _fbb.CreateString(value));
}
struct EnumVal FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { struct EnumVal FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table {
enum { enum {
VT_NAME = 4, VT_NAME = 4,
...@@ -183,6 +187,13 @@ inline flatbuffers::Offset<EnumVal> CreateEnumVal(flatbuffers::FlatBufferBuilder ...@@ -183,6 +187,13 @@ inline flatbuffers::Offset<EnumVal> CreateEnumVal(flatbuffers::FlatBufferBuilder
return builder_.Finish(); return builder_.Finish();
} }
inline flatbuffers::Offset<EnumVal> CreateEnumVal(flatbuffers::FlatBufferBuilder &_fbb,
const char *name = nullptr,
int64_t value = 0,
flatbuffers::Offset<Object> object = 0) {
return CreateEnumVal(_fbb, name ? 0 : _fbb.CreateString(name), value, object);
}
struct Enum FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { struct Enum FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table {
enum { enum {
VT_NAME = 4, VT_NAME = 4,
...@@ -249,6 +260,15 @@ inline flatbuffers::Offset<Enum> CreateEnum(flatbuffers::FlatBufferBuilder &_fbb ...@@ -249,6 +260,15 @@ inline flatbuffers::Offset<Enum> CreateEnum(flatbuffers::FlatBufferBuilder &_fbb
return builder_.Finish(); return builder_.Finish();
} }
inline flatbuffers::Offset<Enum> CreateEnum(flatbuffers::FlatBufferBuilder &_fbb,
const char *name = nullptr,
const std::vector<flatbuffers::Offset<EnumVal>> *values = nullptr,
bool is_union = false,
flatbuffers::Offset<Type> underlying_type = 0,
const std::vector<flatbuffers::Offset<KeyValue>> *attributes = nullptr) {
return CreateEnum(_fbb, name ? 0 : _fbb.CreateString(name), values ? 0 : _fbb.CreateVector<flatbuffers::Offset<EnumVal>>(*values), is_union, underlying_type, attributes ? 0 : _fbb.CreateVector<flatbuffers::Offset<KeyValue>>(*attributes));
}
struct Field FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { struct Field FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table {
enum { enum {
VT_NAME = 4, VT_NAME = 4,
...@@ -342,6 +362,20 @@ inline flatbuffers::Offset<Field> CreateField(flatbuffers::FlatBufferBuilder &_f ...@@ -342,6 +362,20 @@ inline flatbuffers::Offset<Field> CreateField(flatbuffers::FlatBufferBuilder &_f
return builder_.Finish(); return builder_.Finish();
} }
inline flatbuffers::Offset<Field> CreateField(flatbuffers::FlatBufferBuilder &_fbb,
const char *name = nullptr,
flatbuffers::Offset<Type> type = 0,
uint16_t id = 0,
uint16_t offset = 0,
int64_t default_integer = 0,
double default_real = 0.0,
bool deprecated = false,
bool required = false,
bool key = false,
const std::vector<flatbuffers::Offset<KeyValue>> *attributes = nullptr) {
return CreateField(_fbb, name ? 0 : _fbb.CreateString(name), type, id, offset, default_integer, default_real, deprecated, required, key, attributes ? 0 : _fbb.CreateVector<flatbuffers::Offset<KeyValue>>(*attributes));
}
struct Object FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { struct Object FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table {
enum { enum {
VT_NAME = 4, VT_NAME = 4,
...@@ -412,6 +446,16 @@ inline flatbuffers::Offset<Object> CreateObject(flatbuffers::FlatBufferBuilder & ...@@ -412,6 +446,16 @@ inline flatbuffers::Offset<Object> CreateObject(flatbuffers::FlatBufferBuilder &
return builder_.Finish(); return builder_.Finish();
} }
inline flatbuffers::Offset<Object> CreateObject(flatbuffers::FlatBufferBuilder &_fbb,
const char *name = nullptr,
const std::vector<flatbuffers::Offset<Field>> *fields = nullptr,
bool is_struct = false,
int32_t minalign = 0,
int32_t bytesize = 0,
const std::vector<flatbuffers::Offset<KeyValue>> *attributes = nullptr) {
return CreateObject(_fbb, name ? 0 : _fbb.CreateString(name), fields ? 0 : _fbb.CreateVector<flatbuffers::Offset<Field>>(*fields), is_struct, minalign, bytesize, attributes ? 0 : _fbb.CreateVector<flatbuffers::Offset<KeyValue>>(*attributes));
}
struct Schema FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { struct Schema FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table {
enum { enum {
VT_OBJECTS = 4, VT_OBJECTS = 4,
...@@ -476,6 +520,15 @@ inline flatbuffers::Offset<Schema> CreateSchema(flatbuffers::FlatBufferBuilder & ...@@ -476,6 +520,15 @@ inline flatbuffers::Offset<Schema> CreateSchema(flatbuffers::FlatBufferBuilder &
return builder_.Finish(); return builder_.Finish();
} }
inline flatbuffers::Offset<Schema> CreateSchema(flatbuffers::FlatBufferBuilder &_fbb,
const std::vector<flatbuffers::Offset<Object>> *objects = nullptr,
const std::vector<flatbuffers::Offset<Enum>> *enums = nullptr,
const char *file_ident = nullptr,
const char *file_ext = nullptr,
flatbuffers::Offset<Object> root_table = 0) {
return CreateSchema(_fbb, objects ? 0 : _fbb.CreateVector<flatbuffers::Offset<Object>>(*objects), enums ? 0 : _fbb.CreateVector<flatbuffers::Offset<Enum>>(*enums), file_ident ? 0 : _fbb.CreateString(file_ident), file_ext ? 0 : _fbb.CreateString(file_ext), root_table);
}
inline const reflection::Schema *GetSchema(const void *buf) { return flatbuffers::GetRoot<reflection::Schema>(buf); } inline const reflection::Schema *GetSchema(const void *buf) { return flatbuffers::GetRoot<reflection::Schema>(buf); }
inline const char *SchemaIdentifier() { return "BFBS"; } inline const char *SchemaIdentifier() { return "BFBS"; }
......
![logo](http://google.github.io/flatbuffers/fpl_logo_small.png) FlatBuffers [![Build Status](https://travis-ci.org/google/flatbuffers.svg?branch=master)](https://travis-ci.org/google/flatbuffers) ![logo](http://google.github.io/flatbuffers/fpl_logo_small.png) FlatBuffers
=========== ===========
[![Build Status](https://travis-ci.org/google/flatbuffers.svg?branch=master)](https://travis-ci.org/google/flatbuffers) [![Build status](https://ci.appveyor.com/api/projects/status/yg5idd2fnusv1n10?svg=true)](https://ci.appveyor.com/project/gwvo/flatbuffers)
**FlatBuffers** is an efficient cross platform serialization library for games and **FlatBuffers** is an efficient cross platform serialization library for games and
other memory constrained apps. It allows you to directly access serialized data without other memory constrained apps. It allows you to directly access serialized data without
unpacking/parsing it first, while still having great forwards/backwards compatibility. unpacking/parsing it first, while still having great forwards/backwards compatibility.
......
...@@ -263,9 +263,9 @@ inline std::unique_ptr<MonsterT> Monster::UnPack() const { ...@@ -263,9 +263,9 @@ inline std::unique_ptr<MonsterT> Monster::UnPack() const {
{ auto _e = mana(); _o->mana = _e; }; { auto _e = mana(); _o->mana = _e; };
{ auto _e = hp(); _o->hp = _e; }; { auto _e = hp(); _o->hp = _e; };
{ auto _e = name(); if (_e) _o->name = _e->str(); }; { auto _e = name(); if (_e) _o->name = _e->str(); };
{ auto _e = inventory(); if (_e) { for (size_t _i = 0; _i < _e->size(); _i++) { _o->inventory.push_back(_e->Get(_i)); } } }; { auto _e = inventory(); if (_e) { for (flatbuffers::uoffset_t _i = 0; _i < _e->size(); _i++) { _o->inventory.push_back(_e->Get(_i)); } } };
{ auto _e = color(); _o->color = _e; }; { auto _e = color(); _o->color = _e; };
{ auto _e = weapons(); if (_e) { for (size_t _i = 0; _i < _e->size(); _i++) { _o->weapons.push_back(_e->Get(_i)->UnPack()); } } }; { auto _e = weapons(); if (_e) { for (flatbuffers::uoffset_t _i = 0; _i < _e->size(); _i++) { _o->weapons.push_back(_e->Get(_i)->UnPack()); } } };
{ auto _e = equipped_type(); _o->equipped.type = _e; }; { auto _e = equipped_type(); _o->equipped.type = _e; };
{ auto _e = equipped(); if (_e) _o->equipped.table = EquipmentUnion::UnPack(_e, equipped_type()); }; { auto _e = equipped(); if (_e) _o->equipped.table = EquipmentUnion::UnPack(_e, equipped_type()); };
return std::unique_ptr<MonsterT>(_o); return std::unique_ptr<MonsterT>(_o);
......
...@@ -85,7 +85,33 @@ static void EnumMember(const EnumDef &enum_def, const EnumVal ev, ...@@ -85,7 +85,33 @@ static void EnumMember(const EnumDef &enum_def, const EnumVal ev,
// End enum code. // End enum code.
static void EndEnum(std::string *code_ptr) { static void EndEnum(std::string *code_ptr) {
std::string &code = *code_ptr; std::string &code = *code_ptr;
code += ")\n"; code += ")\n\n";
}
// Begin enum name code.
static void BeginEnumNames(const EnumDef &enum_def, std::string *code_ptr) {
std::string &code = *code_ptr;
code += "var EnumNames";
code += enum_def.name;
code += " = map[int]string{\n";
}
// A single enum name member.
static void EnumNameMember(const EnumDef &enum_def, const EnumVal ev,
std::string *code_ptr) {
std::string &code = *code_ptr;
code += "\t";
code += enum_def.name;
code += ev.name;
code += ":\"";
code += ev.name;
code += "\",\n";
}
// End enum name code.
static void EndEnumNames(std::string *code_ptr) {
std::string &code = *code_ptr;
code += "}\n\n";
} }
// Initialize a new struct or table from existing data. // Initialize a new struct or table from existing data.
...@@ -597,6 +623,15 @@ static void GenEnum(const EnumDef &enum_def, std::string *code_ptr) { ...@@ -597,6 +623,15 @@ static void GenEnum(const EnumDef &enum_def, std::string *code_ptr) {
EnumMember(enum_def, ev, code_ptr); EnumMember(enum_def, ev, code_ptr);
} }
EndEnum(code_ptr); EndEnum(code_ptr);
BeginEnumNames(enum_def, code_ptr);
for (auto it = enum_def.vals.vec.begin();
it != enum_def.vals.vec.end();
++it) {
auto &ev = **it;
EnumNameMember(enum_def, ev, code_ptr);
}
EndEnumNames(code_ptr);
} }
// Returns the function name that is able to read a value of the given type. // Returns the function name that is able to read a value of the given type.
......
...@@ -204,16 +204,15 @@ class ResizeContext { ...@@ -204,16 +204,15 @@ class ResizeContext {
if (DagCheck(table)) if (DagCheck(table))
return; // Table already visited. return; // Table already visited.
auto vtable = table->GetVTable(); auto vtable = table->GetVTable();
// Check if the vtable offset points beyond the insertion point.
Straddle<soffset_t, -1>(table, vtable, table);
// This direction shouldn't happen because vtables that sit before tables
// are always directly adjacent, but check just in case we ever change the
// way flatbuffers are built.
Straddle<soffset_t, -1>(vtable, table, table);
// Early out: since all fields inside the table must point forwards in // Early out: since all fields inside the table must point forwards in
// memory, if the insertion point is before the table we can stop here. // memory, if the insertion point is before the table we can stop here.
auto tableloc = reinterpret_cast<uint8_t *>(table); auto tableloc = reinterpret_cast<uint8_t *>(table);
if (startptr_ <= tableloc) return; if (startptr_ <= tableloc) {
// Check if insertion point is between the table and a vtable that
// precedes it. This can't happen in current construction code, but check
// just in case we ever change the way flatbuffers are built.
Straddle<soffset_t, -1>(vtable, table, table);
} else {
// Check each field. // Check each field.
auto fielddefs = objectdef.fields(); auto fielddefs = objectdef.fields();
for (auto it = fielddefs->begin(); it != fielddefs->end(); ++it) { for (auto it = fielddefs->begin(); it != fielddefs->end(); ++it) {
...@@ -271,6 +270,11 @@ class ResizeContext { ...@@ -271,6 +270,11 @@ class ResizeContext {
assert(false); assert(false);
} }
} }
// Check if the vtable offset points beyond the insertion point.
// Must do this last, since GetOptionalFieldOffset above still reads
// this value.
Straddle<soffset_t, -1>(table, vtable, table);
}
} }
void operator=(const ResizeContext &rc); void operator=(const ResizeContext &rc);
......
...@@ -8,3 +8,11 @@ const ( ...@@ -8,3 +8,11 @@ const (
AnyTestSimpleTableWithEnum = 2 AnyTestSimpleTableWithEnum = 2
AnyMyGame_Example2_Monster = 3 AnyMyGame_Example2_Monster = 3
) )
var EnumNamesAny = map[int]string{
AnyNONE:"NONE",
AnyMonster:"Monster",
AnyTestSimpleTableWithEnum:"TestSimpleTableWithEnum",
AnyMyGame_Example2_Monster:"MyGame_Example2_Monster",
}
...@@ -7,3 +7,10 @@ const ( ...@@ -7,3 +7,10 @@ const (
ColorGreen = 2 ColorGreen = 2
ColorBlue = 8 ColorBlue = 8
) )
var EnumNamesColor = map[int]string{
ColorRed:"Red",
ColorGreen:"Green",
ColorBlue:"Blue",
}
...@@ -9,6 +9,13 @@ type Monster struct { ...@@ -9,6 +9,13 @@ type Monster struct {
_tab flatbuffers.Table _tab flatbuffers.Table
} }
func GetRootAsMonster(buf []byte, offset flatbuffers.UOffsetT) *Monster {
n := flatbuffers.GetUOffsetT(buf[offset:])
x := &Monster{}
x.Init(buf, n + offset)
return x
}
func (rcv *Monster) Init(buf []byte, i flatbuffers.UOffsetT) { func (rcv *Monster) Init(buf []byte, i flatbuffers.UOffsetT) {
rcv._tab.Bytes = buf rcv._tab.Bytes = buf
rcv._tab.Pos = i rcv._tab.Pos = i
......
...@@ -7,6 +7,13 @@ import flatbuffers ...@@ -7,6 +7,13 @@ import flatbuffers
class Monster(object): class Monster(object):
__slots__ = ['_tab'] __slots__ = ['_tab']
@classmethod
def GetRootAsMonster(cls, buf, offset):
n = flatbuffers.encode.Get(flatbuffers.packer.uoffset, buf, offset)
x = Monster()
x.Init(buf, n + offset)
return x
# Monster # Monster
def Init(self, buf, pos): def Init(self, buf, pos):
self._tab = flatbuffers.table.Table(buf, pos) self._tab = flatbuffers.table.Table(buf, pos)
......
...@@ -17,4 +17,7 @@ ...@@ -17,4 +17,7 @@
../flatc --cpp --java --csharp --go --binary --python --js --php --grpc --gen-mutable --gen-object-api --no-includes monster_test.fbs monsterdata_test.json ../flatc --cpp --java --csharp --go --binary --python --js --php --grpc --gen-mutable --gen-object-api --no-includes monster_test.fbs monsterdata_test.json
../flatc --cpp --java --csharp --go --binary --python --js --php --gen-mutable -o namespace_test namespace_test/namespace_test1.fbs namespace_test/namespace_test2.fbs ../flatc --cpp --java --csharp --go --binary --python --js --php --gen-mutable -o namespace_test namespace_test/namespace_test1.fbs namespace_test/namespace_test2.fbs
../flatc --binary --schema monster_test.fbs ../flatc --binary --schema monster_test.fbs
cd ../samples
../flatc --cpp --gen-mutable --gen-object-api monster.fbs
cd ../reflection
sh generate_code.sh
...@@ -100,6 +100,9 @@ func TestAll(t *testing.T) { ...@@ -100,6 +100,9 @@ func TestAll(t *testing.T) {
// Verify that vtables are deduplicated when written: // Verify that vtables are deduplicated when written:
CheckVtableDeduplication(t.Fatalf) CheckVtableDeduplication(t.Fatalf)
// Verify the enum names
CheckEnumNames(t.Fatalf)
// Verify that the Go code used in FlatBuffers documentation passes // Verify that the Go code used in FlatBuffers documentation passes
// some sanity checks: // some sanity checks:
CheckDocExample(generated, off, t.Fatalf) CheckDocExample(generated, off, t.Fatalf)
...@@ -1314,6 +1317,37 @@ func CheckFinishedBytesError(fail func(string, ...interface{})) { ...@@ -1314,6 +1317,37 @@ func CheckFinishedBytesError(fail func(string, ...interface{})) {
b.FinishedBytes() b.FinishedBytes()
} }
// CheckEnumNames checks that the generated enum names are correct.
func CheckEnumNames(fail func(string, ...interface{})) {
type testEnumNames struct {
EnumNames map[int]string
Expected map[int]string
}
data := [...]testEnumNames{
{example.EnumNamesAny,
map[int]string{
example.AnyNONE: "NONE",
example.AnyMonster: "Monster",
example.AnyTestSimpleTableWithEnum: "TestSimpleTableWithEnum",
},
},
{example.EnumNamesColor,
map[int]string{
example.ColorRed: "Red",
example.ColorGreen: "Green",
example.ColorBlue: "Blue",
},
},
}
for _, t := range data {
for val, name := range t.Expected {
if name != t.EnumNames[val] {
fail("enum name is not equal")
}
}
}
}
// CheckDocExample checks that the code given in FlatBuffers documentation // CheckDocExample checks that the code given in FlatBuffers documentation
// is syntactically correct. // is syntactically correct.
func CheckDocExample(buf []byte, off flatbuffers.UOffsetT, fail func(string, ...interface{})) { func CheckDocExample(buf []byte, off flatbuffers.UOffsetT, fail func(string, ...interface{})) {
......
No preview for this file type
...@@ -9,6 +9,13 @@ type TableInNestedNS struct { ...@@ -9,6 +9,13 @@ type TableInNestedNS struct {
_tab flatbuffers.Table _tab flatbuffers.Table
} }
func GetRootAsTableInNestedNS(buf []byte, offset flatbuffers.UOffsetT) *TableInNestedNS {
n := flatbuffers.GetUOffsetT(buf[offset:])
x := &TableInNestedNS{}
x.Init(buf, n + offset)
return x
}
func (rcv *TableInNestedNS) Init(buf []byte, i flatbuffers.UOffsetT) { func (rcv *TableInNestedNS) Init(buf []byte, i flatbuffers.UOffsetT) {
rcv._tab.Bytes = buf rcv._tab.Bytes = buf
rcv._tab.Pos = i rcv._tab.Pos = i
......
...@@ -7,6 +7,13 @@ import flatbuffers ...@@ -7,6 +7,13 @@ import flatbuffers
class TableInNestedNS(object): class TableInNestedNS(object):
__slots__ = ['_tab'] __slots__ = ['_tab']
@classmethod
def GetRootAsTableInNestedNS(cls, buf, offset):
n = flatbuffers.encode.Get(flatbuffers.packer.uoffset, buf, offset)
x = TableInNestedNS()
x.Init(buf, n + offset)
return x
# TableInNestedNS # TableInNestedNS
def Init(self, buf, pos): def Init(self, buf, pos):
self._tab = flatbuffers.table.Table(buf, pos) self._tab = flatbuffers.table.Table(buf, pos)
......
...@@ -9,6 +9,13 @@ type SecondTableInA struct { ...@@ -9,6 +9,13 @@ type SecondTableInA struct {
_tab flatbuffers.Table _tab flatbuffers.Table
} }
func GetRootAsSecondTableInA(buf []byte, offset flatbuffers.UOffsetT) *SecondTableInA {
n := flatbuffers.GetUOffsetT(buf[offset:])
x := &SecondTableInA{}
x.Init(buf, n + offset)
return x
}
func (rcv *SecondTableInA) Init(buf []byte, i flatbuffers.UOffsetT) { func (rcv *SecondTableInA) Init(buf []byte, i flatbuffers.UOffsetT) {
rcv._tab.Bytes = buf rcv._tab.Bytes = buf
rcv._tab.Pos = i rcv._tab.Pos = i
......
...@@ -7,6 +7,13 @@ import flatbuffers ...@@ -7,6 +7,13 @@ import flatbuffers
class SecondTableInA(object): class SecondTableInA(object):
__slots__ = ['_tab'] __slots__ = ['_tab']
@classmethod
def GetRootAsSecondTableInA(cls, buf, offset):
n = flatbuffers.encode.Get(flatbuffers.packer.uoffset, buf, offset)
x = SecondTableInA()
x.Init(buf, n + offset)
return x
# SecondTableInA # SecondTableInA
def Init(self, buf, pos): def Init(self, buf, pos):
self._tab = flatbuffers.table.Table(buf, pos) self._tab = flatbuffers.table.Table(buf, pos)
......
...@@ -9,6 +9,13 @@ type TableInFirstNS struct { ...@@ -9,6 +9,13 @@ type TableInFirstNS struct {
_tab flatbuffers.Table _tab flatbuffers.Table
} }
func GetRootAsTableInFirstNS(buf []byte, offset flatbuffers.UOffsetT) *TableInFirstNS {
n := flatbuffers.GetUOffsetT(buf[offset:])
x := &TableInFirstNS{}
x.Init(buf, n + offset)
return x
}
func (rcv *TableInFirstNS) Init(buf []byte, i flatbuffers.UOffsetT) { func (rcv *TableInFirstNS) Init(buf []byte, i flatbuffers.UOffsetT) {
rcv._tab.Bytes = buf rcv._tab.Bytes = buf
rcv._tab.Pos = i rcv._tab.Pos = i
......
...@@ -7,6 +7,13 @@ import flatbuffers ...@@ -7,6 +7,13 @@ import flatbuffers
class TableInFirstNS(object): class TableInFirstNS(object):
__slots__ = ['_tab'] __slots__ = ['_tab']
@classmethod
def GetRootAsTableInFirstNS(cls, buf, offset):
n = flatbuffers.encode.Get(flatbuffers.packer.uoffset, buf, offset)
x = TableInFirstNS()
x.Init(buf, n + offset)
return x
# TableInFirstNS # TableInFirstNS
def Init(self, buf, pos): def Init(self, buf, pos):
self._tab = flatbuffers.table.Table(buf, pos) self._tab = flatbuffers.table.Table(buf, pos)
......
...@@ -9,6 +9,13 @@ type TableInC struct { ...@@ -9,6 +9,13 @@ type TableInC struct {
_tab flatbuffers.Table _tab flatbuffers.Table
} }
func GetRootAsTableInC(buf []byte, offset flatbuffers.UOffsetT) *TableInC {
n := flatbuffers.GetUOffsetT(buf[offset:])
x := &TableInC{}
x.Init(buf, n + offset)
return x
}
func (rcv *TableInC) Init(buf []byte, i flatbuffers.UOffsetT) { func (rcv *TableInC) Init(buf []byte, i flatbuffers.UOffsetT) {
rcv._tab.Bytes = buf rcv._tab.Bytes = buf
rcv._tab.Pos = i rcv._tab.Pos = i
......
...@@ -7,6 +7,13 @@ import flatbuffers ...@@ -7,6 +7,13 @@ import flatbuffers
class TableInC(object): class TableInC(object):
__slots__ = ['_tab'] __slots__ = ['_tab']
@classmethod
def GetRootAsTableInC(cls, buf, offset):
n = flatbuffers.encode.Get(flatbuffers.packer.uoffset, buf, offset)
x = TableInC()
x.Init(buf, n + offset)
return x
# TableInC # TableInC
def Init(self, buf, pos): def Init(self, buf, pos):
self._tab = flatbuffers.table.Table(buf, pos) self._tab = flatbuffers.table.Table(buf, pos)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment