Commit Graph

673 Commits

Author SHA1 Message Date
belldon d5a113e5bf Update C# FlatBufferBuilder to reuse vtable array
This commit updates the FlatBufferBuilder class to reuse the vtable
array instead of creating a new array with every StartObject() call.
2015-12-07 16:42:21 -05:00
Wouter van Oortmerssen 8e6758d205 Merge pull request #608 from evolutional/master
Fix to #360 - Fully qualified names outside of current NS
2015-12-07 10:33:38 -08:00
Wouter van Oortmerssen 163d04a5d2 Merge pull request #778 from armen/master
Correct the max/min signed/unsigned 32-bit int
2015-12-07 10:27:27 -08:00
Wouter van Oortmerssen b0d5bb1c4b Fixed language for generators not being set correctly.
Change-Id: I36c1f05efa836b32635e3274ac0ba976a8961bdd
Tested: on Linux.
2015-12-07 09:53:04 -08:00
Armen Baghumian f622e5996c Optimize get* operation
It's slightly faster to convert the value to signed value in PHP as
opposed to use pack and unpack.

For 1M get operation the difference is:

    getShort in 3.3272678852081 seconds
    getInt in 3.8338589668274 seconds
    getLong in 5.6381590366364 seconds
    getLong (neg) in 5.6149101257324 seconds

vs

    getShort in 2.7564418315887 seconds
    getInt in 3.1612701416016 seconds
    getLong in 3.1369340419769 seconds
    getLong (neg) in 3.1478710174561 seconds

And since pack("P") and unpack("q") has been removed now ByteBuffer
works for PHP >= 5.4
2015-12-05 23:32:35 +00:00
Armen Baghumian 77fbdd28e2 Correct the max/min signed/unsigned 32-bit int
The test was trying to pack an unsigned int which couldn't fit as a
signed int and putInt() wasn't doing the validation in the correct range
2015-12-05 23:32:35 +00:00
Oli Wilkinson c9ad6d5496 Fix to #360 - Updated the general generator (Java/C#) to emit fully qualified names where the referenced object isn't directly in this namespace. Added test fbs files to verify compilation. 2015-12-05 13:42:09 -05:00
Michael Collins e083e466b8 Add Get Bytes Method Generator for C#
I updated idl_gen_general.cpp to add support for generating a Get Bytes
method for a vector to the generated C# source code. Given a byte vector
field named Foo, a method named GetFooBytes() will be generated in the
C# source code that will return an ArraySegment<byte> value referencing
the vector data in the underlying ByteBuffer.

I added a method to Table.cs named __vector_as_arraysegment that is used
by the code generated by the change to the C# generator.
__vector_as_arraysegment will take the offset of the vector and will
return the ArraySegment<byte> value corresponding to the bytes that
store the vector data.

I updated FlatBuffersExampleTests.cs to add tests to validate my
implementation of Table.__vector_as_arraysegment. I added tests to
demonstrate that the bytes for the monster's name can be extracted from
the underlying byte array. I also added tests to show that
Table.__vector_as_arraysegment returns a null value if the vector is not
present in the FlatBuffer.

I used the updated flatc.exe program to regenerate the C# source files
for the MyGame example. The new Monster class includes the GetXXXBytes
methods to return the byte arrays containing data for vectors.
2015-12-04 11:44:43 -07:00
Jason Sanmiya fe2f8d32aa Do not create empty enums.
Mac build issued a warning for enum{}.

Change-Id: I9cab958538ac3cec61aeae289d1da0118ecac15f
Tested: Mac build no longer issues warnings.
2015-12-04 09:45:44 -08:00
Wouter van Oortmerssen 45bda6e08d Added --gen-all to generate code for a schema and all its includes.
Also refactored the way options are stored.

Change-Id: I709ac908cd2aba396c9c282725cf1d42ccce0882
Tested: on Linux.
2015-12-04 09:44:31 -08:00
Wouter van Oortmerssen 47478117d8 Fixed implicit dereference in flatc.
Change-Id: If2e62a325b47399561b4c20d2def55ede4831d19
Tested: on Linux.
2015-12-02 11:12:39 -08:00
Perry Hung d7f2488099 Link clang builds against libc++abi on Linux
Simply running clang with -stdlib=libc++ requires a manual link against
libc++abi on Linux. This is documented in the libc++ documentation:
    http://libcxx.llvm.org/

Tested on Arch Linux, using clang 3.7.0 RELEASE.

Signed-off-by: Perry Hung <iperry@gmail.com>
2015-12-02 11:12:39 -08:00
Wouter van Oortmerssen 3881bbd651 Multiple schemas parsed by flatc are now parsed independently.
It used to be such that later schemas could depend on earlier
schemas. This was a convenience from days before include files
were implemented. Nowadays they cause subtle bugs rather than being
useful, so this functionality has been removed.

You now need to explicitly include files you depend upon.

Change-Id: Id8292c3c621fc38fbd796da2d2cbdd63efc230d1
Tested: on Linux.
2015-12-02 11:12:39 -08:00
Wouter van Oortmerssen 7b06041a7c C++ generated code now has constants for vtable offsets.
Besides making the generated code looking a lot more readable,
it also allows you to use these offsets in calls to
Table::CheckField, to see if a field is present in a table.

Change-Id: I1b4cc350c4f27c4e474c31add40c701ef4ae63b2
Tested: On Linux.
2015-12-02 11:12:39 -08:00
Wouter van Oortmerssen 3fc5387db7 Made C++ generated code use "bool" instead of uint8_t wire type.
Change-Id: I5756d15a758429ca67456264842017063d1f755e
Tested: on Linux.
2015-12-02 11:12:39 -08:00
Wouter van Oortmerssen fc1cfd287a Allow vectors to be aligned beyond their natural type.
Change-Id: I09ade6b688a6b97d65fd832558917225d86c9118
2015-12-02 11:12:39 -08:00
Wouter van Oortmerssen 54dc4395b9 Java builder now checks if buffer was finished upon access.
Also checks for nesting of objects in vector construction.

This avoids common errors in FlatBuffer construction.

Change-Id: I5507c5d767684e20e94883a92448f05acefba4d6
Tested: on Linux.
2015-12-02 11:12:39 -08:00
Chris 1d457a0271 Fix use of std::max when Windows.h is imported. 2015-12-02 11:12:39 -08:00
Chris 671c9495d9 Return the full string when requested from a flatbuffers::String, even if it contains a NULL byte. 2015-12-02 11:12:39 -08:00
Wouter van Oortmerssen d7b4a31e93 Added long form options for all generators (--cpp etc.)
Short-form versions are still supported, but are deprecated.

Change-Id: I15f70ca8d69ba5790368205caa9603b65e1b7fff
Tested: on Linux.
2015-12-02 11:12:39 -08:00
Wouter van Oortmerssen b7d8c2af1a Made generated C++ code respect gcc -Werror=shadow.
Change-Id: I17de0bcc462770124227a9967e2aab620467f6eb
Tested: on Linux.
2015-12-02 11:12:39 -08:00
Wouter van Oortmerssen 1075c80e8a Fixed crash related to flatc parsing duplicate input files.
Thanks @Chaosvex for reporting.

Change-Id: I73f60ab0bf875a3e0849eaec5f42f6d036881094
Tested: on Linux.
2015-12-02 11:12:39 -08:00
Wouter van Oortmerssen 947a5b4ea3 Merge pull request #353 from takaken1994/master
C++: Fixed generated header file cannot be compiled when the type of key is enum class
2015-11-25 13:40:00 -08:00
Wouter van Oortmerssen e10b8d6f2a Merge pull request #349 from belldon/enum-fix
Fixes issue #348: C# vector of enums doesn't compile
2015-11-25 13:14:28 -08:00
Donnell 644bcbde91 Fix C# vector of enum code generation
Fixes a bug where the logic to determine when to use a C# enum flags
both enums and vectors of enums.  This causes the C# generator to
generate code that doesn't compile for tables that contain vectors of
enums.

The fix also consolidates type generation functions a bit and adds
some additional casting functions for clarity.
2015-11-23 09:19:43 -05:00
Wouter van Oortmerssen 6775a0a941 Merge pull request #362 from chobie/fix-projectfile
Fix projectfile (VisualStudio, XCode) for development
2015-11-20 13:43:57 -08:00
Shuhei Tanuma 20c712f31b also, fix xcode project 2015-11-21 05:38:57 +09:00
Shuhei Tanuma e6d51b54b6 Add missing idl_gen_php.cpp to VisualStudio project 2015-11-21 05:33:30 +09:00
Stewart Miles c7482832b8 Merge remote-tracking branch internal into fb_upstream 2015-11-19 03:07:49 -08:00
Stewart Miles 6fe6532673 Fixed typo in cmake build rule for Linux.
Tested:
Verified it's possible to build generated headers on Linux for Android.

Change-Id: I82249a252cb851b978a177f4a4b92b527cc2bfd9
2015-11-19 03:02:58 -08:00
Stewart Miles 8212da5d5d Workaround broken gnumake realpath on Windows.
Also, added missing build scripts for flatc on Windows and fixed
numerous issues in the flatbuffers/android/jni/include.mk makefile.

Tested:
Verified dependent project (motive) can generate flatbuffers headers
with these changes on Android.

Bug: 25780616

Change-Id: I73f0dec8f7a6a7eb4e71951a8f1cd3e0d343a9ff
2015-11-19 02:44:56 -08:00
Wouter van Oortmerssen a7b5f92f51 Merge pull request #359 from proppy/move-build-fb
flatbuffers/cmake: move build_flatbuffers to a standalone file
2015-11-18 10:10:07 -08:00
Wouter van Oortmerssen 6266b4f122 Merge pull request #308 from chobie/php
Add support for PHP code.
2015-11-18 09:31:17 -08:00
Wouter van Oortmerssen e4eb286483 Merge pull request #312 from chobie/unity-fix
C# Unity (.NET 3.5) can't cast enum default value.
2015-11-18 09:28:00 -08:00
Johan Euphrosine 331d2d835c flatbuffers/cmake: move build_flatbuffers to a standalone file
So that it could be included from both flatbuffers CMakeLists.txt and
FindFlatBuffers.cmake.

Change-Id: Ie16a879beef9367cd6fd9b2d2157044841a7cdbc
2015-11-17 13:52:41 -08:00
Shuhei Taunma 5ce8682671 (PHP) add experimental support for PHP language.
* codegen for all basic features: WIP (probably implemented all basic feature)
* JSON parsing: NO
* Simple mutation: NO
* Reflection: NO
* Buffer verifier: NO (will be add later)
* Testing: basic: Yes
* Testing: fuzz: Yes
* Performance: Not bad
* Platform: Supported Linux, OS X, Windows (has 32bit integer limitation)
* Engine Unity: No

flatc --php monster_test.fbs

  <?php
  //include neccessary files.
  $fbb = new Google\FlatBuffers\FlatBufferBuilder(1);
  $str = $fbb->createString("monster");
  \MyGame\Example\Monster::startMonster($fbb);
  \MyGame\Example\Monster::addHp($fbb, 80);
  \MyGame\Example\Monster::addName($fbb, $str);
  $mon = \MyGame\Example\Monster::endMonster($fbb);
  $fbb->finish($mon);
  echo $fbb->sizedByteArray();

PHP 5.4 higher

Currently, we do not register this library to packagist as still experimental and versioning problem.
If you intended to use flatbuffers with composer. add repostiories section to composer.json like below.

  "repositories": [{
    "type": "vcs",
    "url": "https://github.com/google/flatbuffers"
  }],

 and just put google/flatbuffers.

  "require": {
    "google/flatbuffers": "*"
  }

* PHP's integer is platform dependant. we strongly recommend use 64bit machine
  and don't use uint, ulong types as prevent overflow issue.
  ref: http://php.net/manual/en/language.types.integer.php

* php don't support float type. floating point numbers are always parsed as double precision internally.
  ref: http://php.net/manual/en/language.types.float.php

* ByteBuffer is little bit slow implemnentation due to many chr/ord function calls. Especially encoding objects.
  This is expected performance as PHP5 has parsing arguments overhead. probably we'll add C-extension.

Basically, PHP implementation respects Java and C# implementation.

Note: ByteBuffer and FlatBuffersBuilder class are not intended to use other purposes.
      we may change internal API foreseeable future.

PSR-2, PSR-4 standards.

Implemented simple assertion class (respect JavaScript testcase implementation) as we prefer small code base.
this also keeps CI iteration speed.

we'll choose phpunit or something when the test cases grown.
2015-11-18 00:26:39 +09:00
Shuhei Tanuma 37e28d98ea C# Unity can't cast integer represented enum value.
```
namespace MyGame;

enum CommandType : byte {
	None = 0,
}

table Command {
	id:int;
	type:CommandType;
}
```

then generate c# files. it'll output compile error like these.

```
Assets/MyGame/Command.cs(18,39): error CS1041: Identifier expected
Assets/MyGame/Command.cs(18,39): error CS1737: Optional parameter cannot precede required parameters

16:   public static Offset<Command> CreateCommand(FlatBufferBuilder builder,
17:   int id = 0,
18:   CommandType type = (CommandType)0) {
```
2015-11-17 18:02:59 +09:00
Wouter van Oortmerssen 097797bf9f Merge branch 'master' of https://github.com/google/flatbuffers 2015-11-16 14:10:16 -08:00
Robert 4725be015d Merge pull request #343 from rw/go-builder-ergonomics
Go: Improve Builder user interface.
2015-11-16 12:18:30 -08:00
Wouter van Oortmerssen f7d465f990 Merge pull request #344 from rw/py-builder-ergonomics
Python: Improve Builder user interface.
2015-11-16 09:07:31 -08:00
takaken1994 c4966370e2 C++: Fixed generated header file cannot be compiled when the type of key is enum class 2015-11-15 21:24:08 +09:00
Jon Simantov 65c9b355c1 Store the dirs you pass into build_flatbuffers as properties.
This allows you to query the generated target for those properties
later, so dependent modules can refer to the directories to, for example,
add them to the include_directories.

Change-Id: I7a6bd34c5c1d08e2ea69b5ad845223297cad1159
2015-11-13 18:04:41 -08:00
Jon Simantov f2949c3fb1 Added build_flatbuffers function to CMake.
This function is designed to be called by projects that use FlatBuffers.
It takes a list of FlatBuffers schemas and a list of schema include
directories, and generates build rules to create generated headers
and/or binary schemas for those files, as well as optionally copying
all of the text schemas into a directory for your use (for example if
you need to parse text schemas within your app).

See function comments for more details.

Change-Id: I181684b916e91d965e14849d8f83ec2c83e9a4a4
2015-11-13 16:24:20 -08:00
Stewart Miles ef53aebf9e Expand local file path to allow users to fix ndk-build
local-source-file-path does not expand to correct file paths in
some circumstances so some users override it.  Therefore
flatbuffers_header_build_rules has been modified to generate rules
that expand LOCAL_SRC_FILES values with flatbuffers_header_build_rules.

Also, this overrides local-source-file-path to allow nest projects
to build when NDK_OUT is set.

Tested:
Verified a dependent project continues to build.

Bug: 25673744
Change-Id: Ic90186fe96d6e4533f9f3b7ca9ef78084de08a7e
2015-11-13 08:49:00 -08:00
Stewart Miles 4f96603e12 Pass job server arguments (-jX) to make.
When $(MAKE) is expanded via a macro "make" doesn't know whether
$(MAKE) refers to an instance of the make app and therefore doesn't
pass job server arguments down.  This change adds the + prefix to the
command in the receipe in order to indicate $(MAKE) is another instance of
make.

Tested:
Verified flatc builds in parallel from Android builds.

Change-Id: I9f2f4f9680b818fdda7420a75a8bfa995b4644db
2015-11-12 18:25:24 -08:00
rw 3232727ace Python: Improve Builder user interface.
+ Add state to the Builder object to track if we are inside a table,
  and if we are finished building the buffer.
+ Use this data to check that a buffer is being built correctly.
+ Raise an exception if a buffer is not being built correctly.
+ Test that the exceptions happen as expected.

Based on d236dea.
2015-11-11 19:43:53 -08:00
rw 2dfff15a9d Improve Builder user interface.
+ Add state to the Builder object to track if we are inside a table,
  and if we are finished building the buffer.
+ Use this data to check that a buffer is being built correctly.
+ Panic if a buffer is not being built correctly.
+ Test that the panics happen as expected.

Based on d236dea13d.
2015-11-11 17:08:16 -08:00
Wouter van Oortmerssen 3f1c4b41f6 Merge pull request #339 from chobie/net-add-bytebuffer-property-to-table
(C#) Add ByteBuffer property to Table
2015-11-11 10:07:51 -08:00
Shuhei Taunma b98f526b8a (C#) Add ByteBuffer property to Table 2015-11-10 14:32:31 +09:00
Wouter van Oortmerssen 9dc5d378b1 Updated supported languages in the docs.
Change-Id: I607f5f33b609c47fe32342f5e9d066f61f5546cd
2015-11-09 17:25:17 -08:00