platform/upstream/flatbuffers.git
4 years agoRemoves the inner loop in the endtable check written tables (#5803)
mustiikhalil [Thu, 12 Mar 2020 19:13:03 +0000 (22:13 +0300)]
Removes the inner loop in the endtable check written tables (#5803)

4 years agoEscape characters in jsonschema descriptions (#5644)
Marc Butler [Thu, 12 Mar 2020 19:10:30 +0000 (06:10 +1100)]
Escape characters in jsonschema descriptions (#5644)

* Escape JSON Schema comments

* Add quotes to monster comment

Thus exercising the JSON Schema comment escape support.

4 years agoRemove `noexcept` qualifier copy-ctor of `union` type (#5800) (#5802)
Vladimir Glavnyy [Thu, 12 Mar 2020 19:07:27 +0000 (02:07 +0700)]
Remove `noexcept` qualifier copy-ctor of `union` type (#5800) (#5802)

- Remove `noexcept` qualifier from generated 'union' copy-constructor
- Remove `noexcept` qualifier from generated 'union' assign-operator

4 years agoReplace 'assert' by 'FLATBUFFERS_ASSERT' inside idl_parser.cpp (#5799)
Vladimir Glavnyy [Thu, 12 Mar 2020 18:18:10 +0000 (01:18 +0700)]
Replace 'assert' by 'FLATBUFFERS_ASSERT' inside idl_parser.cpp (#5799)

4 years agoAdd non-nullable modifier to return type of functions never returning null (#5797)
Jakub Vrána [Thu, 12 Mar 2020 16:02:29 +0000 (17:02 +0100)]
Add non-nullable modifier to return type of functions never returning null (#5797)

4 years ago[C++] Generate code for vector force_align attribute. (#5796)
Myrice [Thu, 12 Mar 2020 15:32:29 +0000 (08:32 -0700)]
[C++] Generate code for vector force_align attribute. (#5796)

* [Flatbuffer] Generate code for force_align with CreateXDirect and Pack functions.

* Fixed Visual Studio 10.0 compile error for std::to_string.

* Fixed Visual Studio 10.0 compile error for std::to_string.

4 years agorust: pub export the VectorIter type (#5736)
jean-airoldie [Tue, 10 Mar 2020 00:25:03 +0000 (20:25 -0400)]
rust: pub export the VectorIter type (#5736)

4 years agoFix Python min alignment
Wouter van Oortmerssen [Mon, 9 Mar 2020 23:43:43 +0000 (16:43 -0700)]
Fix Python min alignment

This was accidentally deleted in:
https://github.com/google/flatbuffers/commit/9fa8245e81a2fd8ad19f9ae8f3da3a00e796e462

Change-Id: I8cad721e075279f6a67aca81259f73fb75aba482

4 years ago[Rust] Add gen-name-strings for Rust (#5757)
Lee Mracek [Mon, 9 Mar 2020 02:05:20 +0000 (22:05 -0400)]
[Rust] Add gen-name-strings for Rust (#5757)

* Add gen-name-strings for Rust

* Clang format

* Add tests and generate with gen-name-strings

* Clang-format

* Stop doing gen-name-strings with C++ code

* Bring generate_code.bat up with generate_code.sh

4 years agoRemoved assert that wasn't backwards compatible.
Wouter van Oortmerssen [Fri, 6 Mar 2020 01:20:51 +0000 (17:20 -0800)]
Removed assert that wasn't backwards compatible.

Change-Id: I8e74d6fddf91fe955fffc572af9d671160325731

4 years ago[C#] add ObjectAPI Serialization Utility (#5785)
Wouter van Oortmerssen [Thu, 5 Mar 2020 17:33:22 +0000 (09:33 -0800)]
[C#] add ObjectAPI Serialization Utility (#5785)

* [C#] add ObjectAPI Serialization Utility

* set InitialBufferSize to 64k

* rename SerializeToFlatBuffers to SerializeToBinary

4 years agoFixed docs on how to obtain parser error.
Wouter van Oortmerssen [Mon, 2 Mar 2020 20:15:35 +0000 (12:15 -0800)]
Fixed docs on how to obtain parser error.

Change-Id: Ib3ffbdf51ef6af1f5c8267b84b84dceed9d4a838

4 years agoAdded --filename-suffix and --filename-ext to flatc (#5778)
Derek Bailey [Mon, 2 Mar 2020 18:15:23 +0000 (10:15 -0800)]
Added --filename-suffix and --filename-ext to flatc (#5778)

* Fixed refractoring issue in reflection/generate_code.sh. Also, mv deletes the original file, so I don't need to clean it up manually in that case.

* Added --filename-suffix and --filename-ext to flatc

* Fixed typo and added example generation of suffix and extension for C++

* Removed extra ;

* Removed clang-format block from a region that didn't need it. Fixed an auto format of another clang-format block

* Added docs, fixed pointer alignment, removed suffix test file

4 years agoFixed refractoring issue in reflection/generate_code.sh. Also, mv deletes the origina...
Derek Bailey [Thu, 27 Feb 2020 20:59:44 +0000 (12:59 -0800)]
Fixed refractoring issue in reflection/generate_code.sh. Also, mv deletes the original file, so I don't need to clean it up manually in that case. (#5777)

4 years agoSkip writing reflection_generated.h if not changed (#5776)
Derek Bailey [Mon, 24 Feb 2020 22:46:24 +0000 (14:46 -0800)]
Skip writing reflection_generated.h if not changed (#5776)

4 years ago[Swift] Adds GRPC to Swift (#5758)
mustiikhalil [Mon, 24 Feb 2020 17:27:41 +0000 (20:27 +0300)]
[Swift] Adds GRPC to Swift (#5758)

* Adds the basic structure for required to add grpc support

Added the message implementation

Updated the code to confirm to the protocol flatbuffersobject

Adds an example for Swift flatbuffers GRPC

Started implementing the swift GRPC code Gen

Generator generates protocols now

Fixing ci issues

Migrated the logic to use grpc_generator::File instead of string

Refactored swift project

Implemented GRPC in swift

Finished implementing GRPC in swift

Fixes issues

Adds contiguousBytes initializer to swift

Adds documentation + fixes buffer nameing in tables + structs

Adds documentation + fixes buffer nameing in tables + structs

Updated tests

* Updated version

4 years ago[Java][FlexBuffers] Abstract buffer access from ByteBuffer (#5743)
Paulo Pinheiro [Fri, 21 Feb 2020 19:46:40 +0000 (20:46 +0100)]
[Java][FlexBuffers] Abstract buffer access from ByteBuffer (#5743)

To read and build flexbuffers on Java, one needs to wrap the data
using  ByteBuffer. But for the common case of having ByteBuffers
backed by arrays, accessing from a ByteBuffer might be inefficient.

So this change introduces two interfaces: ReadBuf and ReadWriteBuf.
It allows one to read and writes data directly on an array. It also allow
 other buffer implementations to be used with flexbuffers.

Another change is that FlexBuffersBuilder backed by array allows
the buffer to grow with the increase of the message size. Something
that could not be done with ByteBuffer.

4 years agoAdds cocoapods and a readme of how to get the package (#5771)
mustiikhalil [Fri, 21 Feb 2020 19:42:07 +0000 (22:42 +0300)]
Adds cocoapods and a readme of how to get the package (#5771)

4 years ago[snap] Fix versioning (#5727)
Omer Akram [Thu, 13 Feb 2020 16:05:21 +0000 (21:05 +0500)]
[snap] Fix versioning (#5727)

* fix snap versioning

* no need to install git as build packages

4 years ago[Python] Fixed potential allignment issue (#5768)
Joseph Pyott [Wed, 12 Feb 2020 21:53:09 +0000 (16:53 -0500)]
[Python] Fixed potential allignment issue (#5768)

4 years agoFix memory leak on cpp object api (#5761)
xtrm0 [Wed, 12 Feb 2020 20:12:45 +0000 (20:12 +0000)]
Fix memory leak on cpp object api (#5761)

Previously UnPack would allocate data with new and assign it to a
raw pointer. This behavior makes it possible for the pointer to be
leaked in case of OOM. This commit defaults to use the user specified
pointer (which needs to implement a move constructor, a .get() and a
 .release() operators), thus preventing these leaks.

4 years ago[Python] Fixed issue #5499 (#5764)
Joseph Pyott [Tue, 11 Feb 2020 23:02:21 +0000 (18:02 -0500)]
[Python] Fixed issue #5499 (#5764)

4 years ago[C++] Use strong enum type for vectors when scoped-enums is on. (#5750)
David P. Sicilia [Tue, 11 Feb 2020 01:45:32 +0000 (20:45 -0500)]
[C++] Use strong enum type for vectors when scoped-enums is on. (#5750)

* [C++] Use strong enum type for vectors when scoped-enums is on.

These changes only apply when scoped-enums is on, and thus only
the C++17 tests show diffs.

This may break users who use 1) use scoped-enums and 2) use
vectors of enums.  However, it seems that this change should
have been made originally when scoped-enums were added.

Fixes #5285

* [C++] Put strong enum change also behind C++17 flag.

It actually only needs C++11 technically, but this is being done
to avoid breaking any existing users.

Tests were rerun, but produced no additional diffs, as expected.

* [C++] Forgot one location in which C++17 guard needs to go.

This commit produces no additional diffs in generated code.

* Use g_only_fixed_enums instead of scoped_enums.

4 years ago[C#] support Json Serialization (#5752)
mugisoba [Tue, 11 Feb 2020 01:43:36 +0000 (10:43 +0900)]
[C#] support Json Serialization (#5752)

* support json serialization

* fix invalid json format.
* string must be written with double quotes.
* remove commma after the last object member.

* fix indent

* Revert "fix invalid json format."

This reverts commit d6820ed50c8e3d3cda3aa1849b3079f853608619.

* quated string value.

* add cs-gen-json-serializer flag.

* fix preprocessor indent

* ENABLE_JSON_SERIALIZATION -> ENABLE_JSON_SERIALIZATION_TEST

* share TestBuffer method

* remove ENABLE_JSON_SERIALIZATION

* remove duplicated test data

* [windows] add nuget restore and copy test data.

* [docker mono] share msbuild settings with windows. add nuget restore and copy test data.

* add some note for json api.

4 years agoFlexBuffers: C++: scalar-only typed vectors were not aligned.
Wouter van Oortmerssen [Thu, 6 Feb 2020 19:49:39 +0000 (11:49 -0800)]
FlexBuffers: C++: scalar-only typed vectors were not aligned.

This means data written with older versions of this code has
potentially misaligned data, which we'll need to support.
This isn't a problem on most architectures, but could be on
older ARM chips. To support them properly may require swapping
out uses of `flatbuffers::ReadScalar` with a version that does a
memcpy internally.

Change-Id: Ib352aab4a586f3a8c6602fb25488dcfff61e06e0

4 years agoBump Rust port to 0.6.1 (#5747)
Robert Winslow [Thu, 30 Jan 2020 21:55:44 +0000 (13:55 -0800)]
Bump Rust port to 0.6.1 (#5747)

4 years ago[C#] support Object API (#5710)
mugisoba [Thu, 30 Jan 2020 18:18:28 +0000 (03:18 +0900)]
[C#] support Object API (#5710)

* [C#] support Object API

* fix sign-compare

* fix indent

* add new line before for loop.

* using auto whenever possible

* reduce the amout of blank lines.

* wip: support vectors of union

* done: support unions of vectors

* set C# version to 4.0
* remove null propagation operator
* remove auto property initializer
* remove expression-bodied method
* remove pattern matching

* add Example2 to NetTest.sh

* separate JavaUsage.md and CsharpUsage.md from JavaCsharpUsage.md

* add C# Object based API notes.

* support vs2010.

* remove range based for loop.

* remove System.Linq

* fix indent

* CreateSharedString to CreateString

* check shared attribute

* snake case

4 years agoAdds min and max, comments, and all of swift's keywords + fix docs (#5737)
mustiikhalil [Mon, 27 Jan 2020 18:05:41 +0000 (21:05 +0300)]
Adds min and max, comments, and all of swift's keywords + fix docs (#5737)

4 years agoUse VS 2017 and 2019 on CI, fix cast issue in dart_idl (#5740)
Dan Field [Mon, 27 Jan 2020 18:03:00 +0000 (10:03 -0800)]
Use VS 2017 and 2019 on CI, fix cast issue in dart_idl (#5740)

* vs2019

* another attempt

* syntax

* fewer

* fix dart

4 years agoCreates a flatbuffers validation function + small fix (#5725)
mustiikhalil [Fri, 24 Jan 2020 22:55:57 +0000 (01:55 +0300)]
Creates a flatbuffers validation function + small fix (#5725)

4 years agoAdded the code to embed the binary schema to the source (--bfbs-gen-embed). (#5701)
sjoblom65 [Fri, 24 Jan 2020 22:55:34 +0000 (17:55 -0500)]
Added the code to embed the binary schema to the source (--bfbs-gen-embed). (#5701)

* Added the code to embed the binary schema to the source.
This is pulled forward from a old PR #5162 that will be closed.

* Update idl_gen_cpp.cpp

Added a small comment to trigger a new build. The build was failing in a strange location and doesn't look like it has anything to do with the code.

* Moved the EscapeAndWrapBuffer to util.cpp and did some formating.

* One more camelCases removed and renamed some variables.

* wrapped_line_xxx should have been passed as a const reference in the first place.

* Moved the bfbs embed sample to it's own file.

* Missed moving the namespace back.

* Moved the embedded bfbs to test.cpp instead of using a sample.

* Missed adding the generation of embedded bfbs to the build.

* See if this makes the build happier.

* Fixed a in-compatable cpp output of the generated header.

* Did some changes to reflect the code review comments.
1. Update the EscapeAndWrapBuffer to BufferToHexText and fixed a variable name.
2. Moved the include of the embedded binary schema to all the other includes.

* Moved some code to inline the instead of using a local variable.

* Moved the BufferToHexText back to be a inline function in util.h

4 years ago[Java][FlexBuffers] Deprecate typed vector strings due to design flaw (#5722)
Paulo Pinheiro [Fri, 24 Jan 2020 17:58:15 +0000 (18:58 +0100)]
[Java][FlexBuffers] Deprecate typed vector strings due to design flaw (#5722)

* [Java][FlexBuffers] Deprecate typed vector strings due to design flaw

It will still be possible to read buffers with this type, but the
elements will be treated as FBT_KEY and will be read as null-terminated
string.

Trying to build a vector of strings as typed will throw an exception.

More information on https://github.com/google/flatbuffers/issues/5627

Also, fix another bug on strings, where long strings were not properly
aligned.

* [Java][FlexBuffers] Make FBT_VECTOR_STRING_DEPRECATED considered typed.

The logic for FlexBuffers.isVectorType() was changed
to not consider FBT_VECTOR_STRING_DEPRECATED a typed
vector, but that can lead to missinterpretation for
existing serialized data. So we are reverting.

4 years ago[Go] Implements a SharedStrings function (#5733)
mustiikhalil [Fri, 24 Jan 2020 17:57:34 +0000 (20:57 +0300)]
[Go] Implements a SharedStrings function (#5733)

* Adds the sharedstring implementation for go

* Reimplemented testcase according to request

4 years ago[Swift] Fix padding function overflow when bufSize is 0 (#5721)
vkill [Fri, 24 Jan 2020 17:45:19 +0000 (01:45 +0800)]
[Swift] Fix padding function overflow when bufSize is 0 (#5721)

* [Swift] Fix padding function overflow when bufSize is 0

[Swift] Generate linuxmain

* [Swift] Using the overflow addition operator to resolve integer overflow

4 years agoAdd vcpkg installation instructions (#5732)
Phoebe [Thu, 23 Jan 2020 23:46:25 +0000 (07:46 +0800)]
Add vcpkg installation instructions (#5732)

* Add vcpkg installation instructions

* Update comments

4 years ago[Dart] Fix deprecated field support, inf/nan (#5724)
Dan Field [Thu, 23 Jan 2020 22:53:59 +0000 (14:53 -0800)]
[Dart] Fix deprecated field support, inf/nan (#5724)

* Fix deprecated field support, inf/nan

* unused params

* rerun tests

4 years ago[typescript] Size-prefixed root accessors not taking into account size prefix (#5717)
Max Burke [Tue, 21 Jan 2020 05:20:52 +0000 (21:20 -0800)]
[typescript] Size-prefixed root accessors not taking into account size prefix (#5717)

* [typescript/javascript] Size-prefixed root accessor needs to account for the size prefix.

* [typescript] Add parentheses after "new" expression.

* Update generated test files

4 years ago[rust] Add use declarations to Rust-generated bindings for imported FB definitions...
Max Burke [Sun, 19 Jan 2020 22:47:28 +0000 (14:47 -0800)]
[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 d554d79fecf5afd6da6fb993b30b4cd523a5889a.

* 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.

4 years ago[Go] Replace references to hardcoded ”Monster" etc with idiomatic go wherever possibl...
Somo [Fri, 17 Jan 2020 00:19:00 +0000 (19:19 -0500)]
[Go] Replace references to hardcoded ”Monster" etc with idiomatic go wherever possible (#5716)

* go: replace objAPI-generated Pack func with method

See discussion at https://github.com/google/flatbuffers/issues/5668

* go: replace generated union type UnPack func with method

Similar to discussion https://github.com/google/flatbuffers/issues/5668

But signature:
```
func AnyUnPack(t Any, table flatbuffers.Table) *AnyT
```

Becomes,
```
func (rcv Any) UnPack(table flatbuffers.Table) *AnyT
```

4 years ago[C++] Fix for printing of enum in case output_enum_identifiers=1. (#5706)
Vladimir Glavnyy [Thu, 16 Jan 2020 22:12:25 +0000 (05:12 +0700)]
[C++] Fix for printing of enum in case output_enum_identifiers=1. (#5706)

* Add test-case for testing of the future Color in json (output_enum_identifiers = true)

* Refactoring of idl_gen_text.cpp. Fix for printing of bit-enum with active output_enum_identifiers=1.

* Move  GenerateText implementation into class

* Remove unnecessary code from flatbuffers.h

4 years ago[Swift] Support create long string (#5709)
vkill [Thu, 16 Jan 2020 20:08:59 +0000 (04:08 +0800)]
[Swift] Support create long string (#5709)

* [Swift] Support create long string

* [Swift] Move the test case to correct dir

4 years agoAdded create function for swift (#5707)
mustiikhalil [Mon, 13 Jan 2020 20:34:06 +0000 (23:34 +0300)]
Added create function for swift (#5707)

Fixed the create functions and updated the test cases in swift

Removes unneeded code

Updated documentation

4 years ago[Swift] Swift implementation 🎉🎉 (#5603)
mustiikhalil [Thu, 9 Jan 2020 20:12:10 +0000 (23:12 +0300)]
[Swift] Swift implementation 🎉🎉 (#5603)

* Implemented the swift version of Flatbuffers

Implemented serailzing, reading, and mutating data from object monster

Fixes mis-aligned pointer issue

Fixes issue when shared strings are removed from table

Adds swift enum, structs code gen

Fixed namespace issues + started implementing the table gen

Added Mutate function to the code generator

Generated linux test cases

Fixed an issue with bools, and structs readers in table writer

Swift docker image added

Updated the test cases, and removed a method parameters in swift

Fixed createVector api when called with scalars

Fixed issues with scalar arrays, and fixed the code gen namespaces, added sample_binary.swift

Cleaned up project

Added enum vectors, and their readers

Refactored code

Added swift into the support document

Added documentation in docs, and fixed a small issue with Data() not being returned correctly

Fixes Lowercase issue, and prevents generating lookups for deprecated keys

* Made all the required funcs to have const + removed unneeded code + fix lowercase func

* Removed transform from lowercased and moved it to function

* Fixes an issue with iOS allocation from read

* Refactored cpp code to be more readable

* casts position into int for position

* Fix enums issue, moves scalar writer code to use memcpy

* Removed c_str from struct function

* Fixed script to generate new objects when ran on travis ci: fix

* Handles deallocating space allocated for structs

* Updated the test cases to adhere to the fileprivate lookup, no mutation for unions, and updated the names of the vector functions

4 years agoChanged direct calls to strtod to use StringToNumber
Wouter van Oortmerssen [Thu, 9 Jan 2020 19:47:02 +0000 (11:47 -0800)]
Changed direct calls to strtod to use StringToNumber

StringToNumber will correctly use locale-insensitive functions
when available.

Change-Id: I6bde11039a541634186f8f791012af2eb0d86b8d

4 years agoDocument JSON compatibility guarantees. (#5704)
emkornfield [Thu, 9 Jan 2020 18:56:35 +0000 (10:56 -0800)]
Document JSON compatibility guarantees. (#5704)

https://github.com/google/flatbuffers/issues/5688

4 years agoAdd CMake 'generated_code' target to simplify resolution of build dependencies (...
Vladimir Glavnyy [Mon, 6 Jan 2020 23:26:41 +0000 (06:26 +0700)]
Add CMake 'generated_code' target to simplify resolution of build dependencies (#5697)

4 years ago(Optionally) add an additional suffix namespace to generated fbs files. (#5698)
Michael Beardsworth [Mon, 6 Jan 2020 18:00:59 +0000 (10:00 -0800)]
(Optionally) add an additional suffix namespace to generated fbs files. (#5698)

This change allows for the generation of fbs files (from proto) that
don't contain name collisions with the protobuf generated C++ code,
allowing both the proto and fbs message types to be linked into the same binary.

4 years ago[Java] Replace Table.UTF8_CHARSET with StandardCharsets.UTF_8 (#5696)
dreifachstein [Mon, 6 Jan 2020 17:28:19 +0000 (01:28 +0800)]
[Java] Replace Table.UTF8_CHARSET with StandardCharsets.UTF_8 (#5696)

StandardCharsets.UTF_8 is already used in FlexBuffersBuilder.

4 years agoRust: Temporarily disable 2 endianness unit tests (#5695)
Robert Winslow [Thu, 2 Jan 2020 21:34:47 +0000 (13:34 -0800)]
Rust: Temporarily disable 2 endianness unit tests (#5695)

Rare failures occur on AppVeyor in these functions; the failures appear
spurious.

4 years ago[C++17] Add Traits class for Tables and Factory function within it. (#5678)
David P. Sicilia [Thu, 2 Jan 2020 18:12:14 +0000 (13:12 -0500)]
[C++17] Add Traits class for Tables and Factory function within it. (#5678)

* Include flattests_cpp17 in unit tests when C++17 build is enabled.

* [C++17] Generate generic table factory function.

1. For each table, generate a convenient free-standing factory
   function that allows creating the table in a generic way by
   specifying only the type.  This is the first change in a series
   of changes to make Flatbuffers generated C++ code more friendly
   to code bases that make use of C++ template metaprogramming
   techniques to manage the serialization process.  Example:

     Before :(

       // The name of the Flatbuffers type (and namespace) must
       // be hard-coded when writing the factory function.
       auto monster = MyGame::Example::CreateMonster(fbb, ...);

     After  :)

       using type_to_create = MyGame::Example::Monster;
       // No namespace needed on CreateByTagType.
       auto monster = CreateByTagType((type_to_create*)nullptr,
                                      fbb, ...);

   This feature requires building with C++14 or greater, and thus
   it is guarded behind --cpp-std >= c++17 in the flatbuffers C++
   generator.

2. Fix a CMake bug to include C++17 unit tests in test suite.

* [C++17] Replace standalone variadic factory function with type_traits.

Add a `type_traits` to each table class.  This `type_traits` can be
populated with various compile-time info about the table.  Initially,
we have the Create* function and type, but is extensible in the future.

* Remove empty line and fix stale comments.

* Rename type_traits to Traits and move fwd declaration.

* Fix parameter evaluation order issue and use lambda for scope.

4 years agoRemoved code_generators.cpp from library targets
Wouter van Oortmerssen [Thu, 2 Jan 2020 16:49:57 +0000 (08:49 -0800)]
Removed code_generators.cpp from library targets

Change-Id: Ia6e032a77983bf1838b8675f51d1c910acc991d8

4 years ago[rust] Make enum names public (#5690)
Max Burke [Tue, 31 Dec 2019 18:28:58 +0000 (10:28 -0800)]
[rust] Make enum names public (#5690)

* 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 d554d79fecf5afd6da6fb993b30b4cd523a5889a.

* Address comments raised in PR

* Update documentation comments per feedback

* Fix typo

* [rust] Make enum variant names public.

* Update generated test files

* Add test for public enum names

4 years agoCorrect inverted logic around include prefixes. (#5689)
Michael Beardsworth [Mon, 30 Dec 2019 18:34:01 +0000 (10:34 -0800)]
Correct inverted logic around include prefixes. (#5689)

4d1a9f8d9eab9fc6762e03cd862576965a0c6920 inverted the logic around
keeping the include prefix. This change fixes the error.

4 years agoOptimize Pack method using numpy (#5662)
lu-wang-g [Fri, 27 Dec 2019 02:42:11 +0000 (18:42 -0800)]
Optimize Pack method using numpy (#5662)

Add the support to pack using numpy for scalar vectors when numpy is available.

4 years ago[C++] Add Builder and Table typedefs (#5685)
Austin Schuh [Thu, 26 Dec 2019 22:56:46 +0000 (14:56 -0800)]
[C++] Add Builder and Table typedefs (#5685)

* Add Builder and Table typedefs

This gives us a way to use templates to go from a builder to a table
and back again without having to pass both types in.

* Fix tests/cpp17/generated_cpp17/monster_test_generated.h

4 years agoMinor doc updates: FlexBuffers C#, Discord, CppUsage.
Wouter van Oortmerssen [Thu, 26 Dec 2019 20:24:20 +0000 (12:24 -0800)]
Minor doc updates: FlexBuffers C#, Discord, CppUsage.

Change-Id: Ie34ff580eb2f41ff35f85271b10865f4a14d0dca

4 years agoUpgrade rules_go (#5684)
Austin Schuh [Thu, 26 Dec 2019 18:07:15 +0000 (10:07 -0800)]
Upgrade rules_go (#5684)

This should help with #5672 if I'm reading the report back from
buildkite properly.

4 years agoFix --incompatible_load_cc_rules_from_bzl (#5683)
Austin Schuh [Thu, 26 Dec 2019 18:03:22 +0000 (10:03 -0800)]
Fix --incompatible_load_cc_rules_from_bzl (#5683)

Incompatible flag --incompatible_load_cc_rules_from_bzl will break
FlatBuffers once Bazel 1.2.1 is released.

Fixes #5671

4 years agoAdd support for absl::string_view when available (#5682)
Austin Schuh [Thu, 26 Dec 2019 18:02:24 +0000 (10:02 -0800)]
Add support for absl::string_view when available (#5682)

For C++11 platforms, absl::string_view is sometimes available. This can
be used for string_view when std::string_view is not available.

4 years ago[Bazel] Add support for compatible_with and restricted_to (#5681)
Austin Schuh [Thu, 26 Dec 2019 17:58:48 +0000 (09:58 -0800)]
[Bazel] Add support for compatible_with and restricted_to (#5681)

* Add support for compatible_with and restricted_to

These attributes have been available in Bazel for years.  Pass them
through so the flatbuffer rules can be used with them.  They let you
constrain which target platform is used.

While we are here, fix gen_reflections to work with bazel.

* Add docs

4 years agoCI: New Docker tests for Python with numpy (#5677)
Robert Winslow [Tue, 24 Dec 2019 07:14:55 +0000 (02:14 -0500)]
CI: New Docker tests for Python with numpy (#5677)

* New Docker tests for Python with numpy

* print numpy status in test suite

4 years agoFixed struct initialization error on older versions of C#
Wouter van Oortmerssen [Tue, 24 Dec 2019 01:35:54 +0000 (17:35 -0800)]
Fixed struct initialization error on older versions of C#

"'this' object cannot be used before all of its fields are assigned to"

Change-Id: Icccdcc0d0be0fe0b87abe0eb28fe1cc91116fcfb

4 years agoFixed warnings in FlexBuffers.java
Wouter van Oortmerssen [Tue, 24 Dec 2019 01:11:57 +0000 (17:11 -0800)]
Fixed warnings in FlexBuffers.java

- Missing return statement <- bug!
- Missing hashCode function.

Change-Id: I6333cac72adf8ead92ab2e6c7215650ce4571a73

4 years agoFixed out of date licenses on gRPC Python files.
Wouter van Oortmerssen [Mon, 23 Dec 2019 22:01:41 +0000 (14:01 -0800)]
Fixed out of date licenses on gRPC Python files.

Change-Id: Ia6c3bf5d7da795db46c0baa8e9c7591de3400517

4 years agoRemoved test proto output.
Wouter van Oortmerssen [Mon, 23 Dec 2019 20:32:52 +0000 (12:32 -0800)]
Removed test proto output.

Change-Id: Iaf64bec068d03dd1b75670e9a28dde7392ebddb5

4 years agoAdd flatc '--cpp_std' switch (#5656)
Vladimir Glavnyy [Mon, 23 Dec 2019 20:13:48 +0000 (03:13 +0700)]
Add flatc '--cpp_std' switch (#5656)

* Add flatc '--cpp_std' switch and sandbox for C++17 code generator

- Added 'flac --cpp_std legacy' for compatibility with old compilers (VS2010);
- Added experimental switch 'flac --cpp_std c++17' for future development;
- Added C++17 sandbox test_cpp17.cpp;
- C++ code generator generates enums with explicit underlying type to avoid problems with the forward and backward schema compatibility;
- Adjusted CMakeLists.txt, CI and generate code scripts to support of introduced '--cpp_std';

* Fix --cpp_std values: c++0x, c++11, c++17

* Add 'cpp::CppStandard' enum

* Add testing engine into test_cpp17

* Rebase to upstream/master

* Set default '--cpp-std C++0x'

* Fix code generation (--cpp_std C++11) in CMakeLists.txt

- Fix dependency declaration of grpctest target

* Revert --cpp-std for the tests from explicit C++11 to flatc default value (C++0x)

4 years agoFix for FlexBuffers FBT_VECTOR_STRING size bit-width.
Wouter van Oortmerssen [Mon, 23 Dec 2019 19:12:41 +0000 (11:12 -0800)]
Fix for FlexBuffers FBT_VECTOR_STRING size bit-width.

For details, test.cpp/FlexBuffersDeprecatedTest(), and also
https://github.com/google/flatbuffers/issues/5627

Change-Id: I6e86e1138a5777e31055cfa2f79276d44732efbc

4 years agoAdded Check to VerifyAlignment (#5675)
stefan301 [Mon, 23 Dec 2019 17:08:35 +0000 (18:08 +0100)]
Added Check to VerifyAlignment (#5675)

* Added missing EndTable() call to VerifyObject()

VerifyObject called VerifyTableStart() but not EndTable(). This made Verifier::VerifyComplexity() increase depth_ with each table, not with the depth of tables.

https://groups.google.com/forum/#!topic/flatbuffers/OpxtW5UFAdg

* Added Check to VerifyAlignment

https://stackoverflow.com/questions/59376308/flatbuffers-verifier-returns-false-without-any-assertion-flatbuffers-debug-veri

4 years agoImprove import handling for proto conversion (#5673)
Michael Beardsworth [Mon, 23 Dec 2019 16:50:29 +0000 (08:50 -0800)]
Improve import handling for proto conversion (#5673)

* Keep include prefix when converting from proto.

This change preserves the include prefix when generating flatbuffers
from proto (with FBS_GEN_INCLUDES) defined.

* Improve handling of imports in proto conversion.

Previously, there was no runtime flag to make proto->fbs conversion keep
the import structure of a collection of files. This change makes proto
conversion respect the --no-gen-includes flag and skip the output of
"generated" symbols.

4 years ago[Dart] Fix prepare space for writeListInt64 and writeListUint64 (#5654)
Light Lin [Wed, 18 Dec 2019 19:23:54 +0000 (03:23 +0800)]
[Dart] Fix prepare space for writeListInt64 and writeListUint64 (#5654)

* Fix prepare space for writeListInt64 and

writeListUint64

* Fix align issues

4 years agoMake Rust constants public (#5659)
Matt Brubeck [Tue, 17 Dec 2019 20:18:59 +0000 (12:18 -0800)]
Make Rust constants public (#5659)

* Make Rust constants public

Otherwise they cannot be accessed by code that consumes the generated
bindings.

* Re-generate test code

* Add a test for enum constants

4 years agoAdd namespace qualification to union types (#5666)
cryptocode [Tue, 17 Dec 2019 17:11:26 +0000 (18:11 +0100)]
Add namespace qualification to union types (#5666)

4 years agoBugfix for Rust generation of union fields named with language keywords (#5592)
Max Burke [Sun, 15 Dec 2019 23:18:22 +0000 (15:18 -0800)]
Bugfix for Rust generation of union fields named with language keywords (#5592)

* 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 d554d79fecf5afd6da6fb993b30b4cd523a5889a.

* Address comments raised in PR

* Update documentation comments per feedback

* Fix typo

4 years agowrap multiple statements in do {} while(!IsConstTrue(true)) (#5655)
FujiZ [Fri, 13 Dec 2019 18:14:14 +0000 (02:14 +0800)]
wrap multiple statements in do {} while(!IsConstTrue(true)) (#5655)

4 years ago[gRPC] Uncomment MessageBuilder (#5658)
Gautham B A [Mon, 9 Dec 2019 18:28:31 +0000 (23:58 +0530)]
[gRPC] Uncomment MessageBuilder (#5658)

The line where the MessageBuilder was
constructed was commented out (perhaps
an oversight).

4 years agoSupress unsigned-integer-overflow for PaddingBytes (#5647)
Björn Harrtell [Mon, 9 Dec 2019 18:06:04 +0000 (19:06 +0100)]
Supress unsigned-integer-overflow for PaddingBytes (#5647)

4 years agoAdd --force-empty-vectors option (#5653)
cryptocode [Fri, 6 Dec 2019 01:33:45 +0000 (02:33 +0100)]
Add --force-empty-vectors option (#5653)

The rationale for this option is that JSON clients typically want empty arrays (i.e [] in the JSON) instead of missing properties, but not empty strings when the value isn't set.
--force-empty is kept as-is, i.e. it will force both empty strings and vectors.

Closes #5652

4 years agoFixed enum min/max values not properly escaped.
Wouter van Oortmerssen [Thu, 5 Dec 2019 22:28:02 +0000 (14:28 -0800)]
Fixed enum min/max values not properly escaped.

Change-Id: I503fbfaff1d2579807ca71a07cca8363dff75e52

4 years agoSplit Bazel targets into multiple packages (#5640)
bttk [Mon, 2 Dec 2019 22:14:48 +0000 (14:14 -0800)]
Split Bazel targets into multiple packages (#5640)

* Split Bazel targets into multiple packages

* Merge /include/BUILD back into /BUILD

4 years agoRemove a static_assert (#5643)
Google AutoFuzz Team [Mon, 2 Dec 2019 22:13:28 +0000 (17:13 -0500)]
Remove a static_assert (#5643)

Having a static_assert on MSAN and ASAN prevents
the fuzzers from being used with different engines,
like TSAN, UBSAN, … but also with fuzzers that aren't
using MSAN/ASAN like afl for example.

4 years agoFlatbuffers Python Object API (#5616)
lu-wang-g [Mon, 2 Dec 2019 22:11:28 +0000 (14:11 -0800)]
Flatbuffers Python Object API (#5616)

* Flatbuffers Python Object API

Implement the logic to generate the Python object API that can
unpack the data from a buf class into an object class, and pack
the data of an object class to a buf class.

* Fix the build issues

Remove unused parameters and replace auto in the for-loop statement
with std::string to make it compatible with VS2010.

* Fix the build issues.

* Add support for Array type

Added logic to handle Array type in Python Object API. Updated the
generated code accordingly.

* Fix the old style casting from int to char

* Fixed another conversion from int to char

* Fixed the import for typing

Importing typing may cause errors when a machine do not have the
moduel typing installed. This PR fixes the issue by guarding
"import typing" with the "try/except" statement.

* Fix issue of iterating the vector of import list

* Update the generated examples using generate_code.sh

* Fix the import order for typing

The import list was stored in unordered_set, so that each generated
codes may have different import order. Therefore, it failed in the
consistency test where two generated copies need to have exactly the
same apperance.

* Optimize unpack using numpy

Use numpy to unpack vector whenever it is possible to improve unpack
performance.

Also, added codegen command for Python specificly in generate_code.sh,
because --no-includes cannot be turn on for Python.

* Fix the import order

* Update generate_code.bat for windows accordingly

* Replace error message with pass

Avoid printing error message for every Python2 users about typing.
Replace it with pass.

4 years ago[Clang 10]: definition of implicit copy constructor for 'TableKeyComparatoris depreca...
Ivan Shynkarenka [Mon, 2 Dec 2019 22:10:09 +0000 (01:10 +0300)]
[Clang 10]: definition of implicit copy constructor for 'TableKeyComparatoris deprecated #5649 (#5650)

4 years ago[docs]: add missing semicolon (#5648)
nilsocket [Mon, 2 Dec 2019 22:01:25 +0000 (22:01 +0000)]
[docs]: add missing semicolon (#5648)

Add missing semicolon for table field.

4 years ago[GO] Fix support for enums with underscores and Unions with imported members (#5600)
Tiago Silva [Tue, 26 Nov 2019 20:25:36 +0000 (20:25 +0000)]
[GO] Fix support for enums with underscores and Unions with imported members (#5600)

* Fix Enum Stringer method when Enum has underscores

Fixes #5481

* Fix go package importing itself when Union has imported members.

4 years agoFix ambiguity of a type deduction in TEST_EQ macro if arguments have `enum class...
Vladimir Glavnyy [Mon, 25 Nov 2019 20:56:47 +0000 (03:56 +0700)]
Fix ambiguity of a type deduction in TEST_EQ macro if arguments have `enum class` type. (#5630)

4 years agoSimplify declarations of x-macro FLATBUFFERS_TD (#5638)
Vladimir Glavnyy [Mon, 25 Nov 2019 20:54:59 +0000 (03:54 +0700)]
Simplify declarations of x-macro FLATBUFFERS_TD (#5638)

4 years agoread vtable size through ReadScalar() (#5636)
FujiZ [Mon, 25 Nov 2019 20:52:42 +0000 (04:52 +0800)]
read vtable size through ReadScalar() (#5636)

4 years agoChanged null checks in test. Removed verifier pointer usage (#5634)
Derek Bailey [Thu, 21 Nov 2019 18:25:31 +0000 (10:25 -0800)]
Changed null checks in test. Removed verifier pointer usage (#5634)

4 years agoAdd testing of C++ with sanitizers (CI-Docker) (#5631)
Vladimir Glavnyy [Mon, 18 Nov 2019 20:16:41 +0000 (03:16 +0700)]
Add testing of C++ with sanitizers (CI-Docker) (#5631)

* Add C++ build testing with clang and gcc

This adds Dockerfiles which test building flatc and the C++ library against clang
and gcc. See discussion at #5119.  It is derived from the Travis CI tooling.

The GRPC tests are failing due to #5099 so those are commented out.

These are run from the .travis.yml file rather than the tests/docker/languages
folder because the builds may each take longer than 30 minutes and were hitting
Travis timeouts.

Parallel builds and build caching attempt to keep the build times low.

* Add GCC 8.3 and Clang 7.0 with sanitizers into CI (based on #5130)

- Add a docker based on Debian Buster.
- Add C++ building scripts for the docker.
- Leak-sanitizer requires SYS_PTRACE.

4 years agoadd namespace prefix in FLATBUFFERS_MAX_BUFFER_SIZE (#5629)
FujiZ [Mon, 18 Nov 2019 20:02:14 +0000 (04:02 +0800)]
add namespace prefix in FLATBUFFERS_MAX_BUFFER_SIZE (#5629)

4 years agoSupport for python grpc - continuing the work from the pull request #4270 #4705 ...
Malar Kannan [Fri, 15 Nov 2019 00:58:35 +0000 (06:28 +0530)]
Support for python grpc - continuing the work from the pull request #4270 #4705 (#5613)

* Support for python grpc

* add few fixes

* Fixes build

* Fix python generator

* Add tests

* Fix grpc python test

* Fix tests and add incomplete python generator

* Fix python generator

* Add python generator methods

* Fix Appveyor build

* grpc python support v0.1

* Update tests

* update grpctest

* Remove duplicated code and fix a brace

* tests for flatbuffers grpc python

* Updated tests + removed SerializeToString, From String

* remove pickle import

* include missing files in ci - BUILD and generated test result

4 years agoRemoved idl_gen_general.cpp and move contents to code_generators.cpp (#5625)
Derek Bailey [Thu, 14 Nov 2019 23:47:58 +0000 (15:47 -0800)]
Removed idl_gen_general.cpp and move contents to code_generators.cpp (#5625)

4 years agoLua cleanup (#5624)
Derek Bailey [Thu, 14 Nov 2019 23:46:47 +0000 (15:46 -0800)]
Lua cleanup (#5624)

4 years ago[C++] Adds basic schema evolution tests (#5611)
Derek Bailey [Thu, 14 Nov 2019 23:44:18 +0000 (15:44 -0800)]
[C++] Adds basic schema evolution tests (#5611)

* Added basic schema evolution tests

* Add BUILD targets for evolution tests. Added to test/generate_code scripts

* Use vector.front() instead of vector.data()

* Added --scoped-enums option for evolution test

4 years ago[C++, C#, Java] Separated C# and Java generators into their own classes (#5618)
Derek Bailey [Mon, 11 Nov 2019 19:37:55 +0000 (11:37 -0800)]
[C++, C#, Java] Separated C# and Java generators into their own classes (#5618)

* Cloned idl_gen_general.cpp to idl_gen_csharp.cpp and removed java references

* Java generator changes

4 years agoadd check for root_type specified for json schema generation (#5622)
Dmitry [Mon, 11 Nov 2019 19:33:27 +0000 (22:33 +0300)]
add check for root_type specified for json schema generation (#5622)

4 years ago[Rust] Bump smallvec version to 1.0 (#5621)
messense [Mon, 11 Nov 2019 17:52:26 +0000 (01:52 +0800)]
[Rust] Bump smallvec version to 1.0 (#5621)

See https://github.com/servo/rust-smallvec/pull/175 for changelog.

4 years agoRan src/clang-format-all.sh (#5617)
Derek Bailey [Mon, 11 Nov 2019 17:29:37 +0000 (09:29 -0800)]
Ran src/clang-format-all.sh (#5617)

4 years agoImproved pull request & clang-format instructions.
Wouter van Oortmerssen [Thu, 7 Nov 2019 22:35:42 +0000 (14:35 -0800)]
Improved pull request & clang-format instructions.

Change-Id: Ia439bcc61bac5788792244d10e573b1fba54b347

4 years agoChange monster_extra generation to use flatbuffers::unique_ptr (#5612)
Derek Bailey [Thu, 7 Nov 2019 22:10:41 +0000 (14:10 -0800)]
Change monster_extra generation to use flatbuffers::unique_ptr (#5612)