Commit Graph

121 Commits

Author SHA1 Message Date
Maor Itzkovitch c23c620d26 applied struct parameter fix to Go and Python generated classes 2015-07-13 22:53:59 +03:00
Maor Itzkovitch 147fbb4285 builder.put statements now use correct argument names 2015-07-13 20:00:48 +03:00
Wouter van Oortmerssen cb2b2be54e Reflection: generically copy (parts of) FlatBuffers.
Change-Id: Ief3f1507c003079eac90c2bb6c2abd64a80a0a34
Tested: on Linux.
2015-06-29 15:18:51 -07:00
rw 4d305f5922 Panic when nesting strings. Test panic scenarios.
Also add a new `insideObject` boolean to the Builder to track whether an
object is currently being constructed. This fixes a bug with objects
that have zero fields.
2015-06-24 11:53:44 -04:00
Wouter van Oortmerssen 622b8d05cf Fixed warnings on Windows 2015-06-15 17:35:07 -07:00
Wouter van Oortmerssen 81312c2128 Initial reflection and resizing functionality.
Tested: on Linux.

Change-Id: I8f7bccf9b1ad87fea788f85e23fa69435758feca
2015-06-15 15:53:10 -07:00
Wouter van Oortmerssen 1808337adc Make generating dependent include files for C++ the default.
--gen-includes is now deprecate but still accepted.
--no-includes can be used instead when needed.

Change-Id: I2cd46d193032b9b7c31c76c6f655e9333d3a393a
Tested: on Linux.
2015-06-15 13:09:22 -07:00
Wouter van Oortmerssen ddb1d5ffe4 Added a #define for running tests without file access.
Change-Id: Ib2b7aa8a5641cf73fa0d6f2000db7fdd1aabab66
Tested: on Linux.
2015-05-27 14:00:08 -07:00
rw 0894c25f2c Improve comment for unicode check. 2015-05-20 14:19:49 -07:00
rw 7810fb9ce4 use escape codes here for non-unicode editors 2015-05-20 13:42:51 -07:00
rw c127cf78c2 Go: CreateString now needs zero allocs.
Big speed boost for the typical use case of building with strings.
2015-05-20 12:00:44 -07:00
rw 2746aabcf1 fix string catenation 2015-05-13 10:50:47 -07:00
rw 48dfc69ee6 Port FlatBuffers to Python.
Implement code generation and self-contained runtime library for Python.

The test suite verifies:
  - Correctness of generated Python code by comparing output to that of
    the other language ports.
  - The exact bytes in the Builder buffer during many scenarios.
  - Vtable deduplication correctness.
  - Edge cases for table construction, via a fuzzer derived from the Go
    implementation.
  - All code is simultaneously valid in Python 2.6, 2.7, and 3.4.

The test suite includes benchmarks for:
  - Building 'gold' data.
  - Parsing 'gold' data.
  - Deduplicating vtables.

All tests pass on this author's system for the following Python
implementations:
  - CPython 2.6.7
  - CPython 2.7.8
  - CPython 3.4.2
  - PyPy 2.5.0 (CPython 2.7.8 compatible)
2015-05-12 15:40:29 -07:00
Robert 4d213c2d06 Merge pull request #165 from rw/go-faster
Go speed improvements
2015-05-12 14:53:31 -07:00
rw 3dd54424c0 remove remaining allocs during build 2015-05-09 16:07:11 -07:00
Mormegil 221193eaa2 Union accessors in C# should use generic type for the table
When accessing a union field, we should return the same object type
as was given to the method, i.e. the parameter should have a generic
type for any Table-derived type. This way, we do not need to make
superfluous casts (which also reduce type safety) like

var myUnionType = (MyUnionType)buff.GetUnionField(new MyUnionType());

when we can do just
var myUnionType = buff.GetUnionField(new MyUnionType());

Change-Id: Idac1b638e46cc50b1f2dc19f10741481202b1515
2015-05-08 16:21:54 -07:00
Wouter van Oortmerssen 39833d7cf0 Added namespaced way to refer to types in schemas.
Also made proper namespacing work for enums.

You can now say namespace.MyTable as the type when declaring
a field that refers to a type in a different namespace.

Previously, it would work just referring to MyTable, however
with the recent commit fixing namespaced types this now
is ambiguous.

Change-Id: Ieaa3f4ac1662b8c4dc1f16e1898ea3cdb02e10fd
Tested: on Linux.
2015-05-08 16:21:53 -07:00
Brett Cooley ecb27817ca Merge "Initial support for propagating namespaces from schema files to generated code" into ub-games-master 2015-05-08 19:52:54 +00:00
Mormegil 0ee1b99c5d [BREAKING CHANGE] Field accessors should use property getters in C#
In C#, plain field accessors should not be nonparametric methods
but should be standard property getters.

The accessor methods with parameters were renamed to `GetXxx`
because a method cannot be named identically to a property.

Also, `ByteBuffer.Position`, `FlatBufferBuilder.Offset` and
`FlatBufferBuilder.DataBuffer` are now properties instead
of nonparametric accessor methods, for more idiomatic C# style.

This is a breaking change, all client C# code accessing these
fields needs to be changed (i.e. remove those `()` or add the
`Get` prefix).

Issue: #77
Change-Id: Iaabe9ada076e5ea2c69911cf6170fdda2df3487e
2015-05-06 11:55:07 -07:00
Brett Cooley 249f71a12b Initial support for propagating namespaces from schema files to generated code
Change-Id: Ifc10c54845ea7553586d1896d509314d68e9ab0f
2015-05-05 17:10:53 -07:00
Wouter van Oortmerssen 37e6efe1f9 Added accessor for file_extension in generated code.
Change-Id: I2de7d14dbb1f7b8f81022dd2c9da65060ae49300
Tested: on Linux.
2015-05-04 13:38:20 -07:00
Wouter van Oortmerssen 3ec5dddb00 Mutable FlatBuffers: in-place updates.
This commit contains the first step in providing mutable FlatBuffers,
non-const accessors and mutation functions for existing fields generated
from --gen-mutable.

Change-Id: Iebee3975f05c1001f8e22824725edeaa6d85fbee
Tested: on Linux.
Bug: 15777024
2015-04-29 10:58:45 -07:00
Mormegil e3b432cba8 Enums use native enums in C#
Enums should not be (badly) emulated with classes in C# but should
use native C# enums instead. Java implementation made an explicit
choice not to use the (more complex) Java enums, but C# enums are
just light-weight syntactic coating over integral types.

Fixes issue #171.

Change-Id: I9f4d6ba5324400a1e52982e49b58603cb7d7cca7
2015-04-13 10:40:30 -07:00
Advay Mengle 557c57eb9d Seal all classes in Java/C#
Makes enums/structs/tables unsubclassable (final or sealed) and
prevents instantiation of enum classes (which are solely static
constants).

Tested (Mac OS 10.10.2):
1. run flattests
2. cd tests && ../flatc -c monster_test.fbs && ../flatc -j
monster_test.fbs && ../flatc -g monster_test.fbs && ../flatc -n
monster_test.fbs  # Note deltas for C# and Java.
3. ./JavaTest.sh

**Breaking api change**

Change-Id: Ie008c941c36d212690da58ddc72c9b228eb7a093
2015-04-10 11:20:19 -07:00
Ben Harper 8b99bf614c Add byte slice accessor to Go code
Change-Id: I15cc8924d6607bd93068c762fd67e6088cfd9789
2015-04-06 11:44:22 -07:00
Kyle Jones c4a3e2f6bd Always add additional space if no more is available
Change-Id: If08b2d839489d40e977de794b13584fa66ff32c1
2015-04-06 11:44:22 -07:00
rw d756efbf76 Reduce allocations when reusing a Builder.
Add the function `Reset` to the Builder, which facilitates reuse of the
underlying byte slice.
2015-04-02 19:33:00 -07:00
rw ace7fa8094 Reduce allocations when building strings.
Builder has a new CreateByteString function that writes a
null-terimnated byte slice to the buffer. This results in zero
allocations for writing strings.
2015-04-02 18:22:13 -07:00
rw f02646e357 Remove all string allocations during parsing.
Change the signature for 'string' getters and settings to use byte
slices instead of strings.
2015-04-02 11:56:55 -07:00
rw 0a3a09aaf3 Merge branch 'go-bytevector-getter' of github.com:benharper123/flatbuffers into go-faster 2015-04-02 11:47:17 -07:00
rw 796be3282c Benchmarks for building and parsing 'gold' data.
Identifies alloc-heavy codepaths.
2015-04-02 11:26:00 -07:00
rw 468124fb9b chmod GoTest.sh +x 2015-04-02 11:25:48 -07:00
Advay Mengle 3ad853630c Generate appropriate schema doc comments from .proto files
- Add parse handling of .proto struct and field doc comments (enums and
their values were already handled)
- Add FBS generation handling of doc comments for structs, their
fields, enums, and their values (requires linking idl_gen_general in
the test binary build)
- Tested using test.proto|golden with doc comments added.  Xcode run of
flattest passes.

Change-Id: Idff64dd8064afba227174ab77d2c7be22d006628
2015-04-01 17:17:39 -07:00
Advay Mengle b8708beeec Generate Java doc comments in JavaDoc style
Tested by regenerating all tests/ generated sources; note that only
Monster.java changes.  Ran flattests as well.

Change-Id: I65b6ea7d208b0ccd6a0b34761162fed6ba391fc5
2015-04-01 17:10:52 -07:00
Ben Harper 8fb6c4f764 Add byte slice accessor to Go code 2015-04-01 16:47:10 +02:00
Wouter van Oortmerssen ca5c9e7496 Unsigned types in Java now return bigger size signed types.
(Java doesn't support unsigned types).

ubyte/ushort return as int
uint returns as long
(all with correct masking)

ulong still returns as long, as before.

Tested: on Linux & Windows.
Bug 17521464

Change-Id: Id6bc8f38fc8c1a2f4e6733c6980dc6b6e322b452
2015-03-23 17:01:33 -07:00
Wouter van Oortmerssen 7ef2fc2517 Regenerated test code + fixed typo in C# FlatBufferBuilder
Change-Id: Ifa6d9459c53ae60b9bf936d9468ec971ee282f14
Tested: on Linux and Windows.
2015-03-13 13:05:28 -07:00
Ben Harper 6a0126340a Add CreateByteVector function to Go's builder
This function gets around the inefficiency of populating a [ubyte] vector
byte by byte. Since ubyte vectors are probably the most commonly used type
of generic byte buffer, this seems like a worthwhile thing to create a
fast path for.

Benchmarks show a 6x improvement in throughput on x64.

There is a new test verifying the functionality of the function.

Change-Id: I82e0228ae0f815dd7ea89bf168b8c1925f3ce0d7
2015-03-11 17:27:39 -07:00
Max Galkin 4464405250 Make FuzzTest2 fuzzier.
1. Random table fields are now marked deprecated. The deprecation rate is adjustable, default is ~10% of fields.
2. Vector type previously produced a dummy field, now a trivial ubyte vector is generated instead.
3. The fuzzed "instances" were previously generated with identical data, now they are randomized: I suppose such was the intent from the beginning, just wasn't implemented.

I ran the new test with a few different settings and random seeds (but only on Windows + VS2015), and it always passed.

Change-Id: I2014686b6680aec24049ccda3f6deffe5205a83e
2015-03-11 17:27:39 -07:00
gregoire-astruc a360958be3 Implementation of a buffer release strategy.
* Tests for Release feature.
* Check vector_downward.buf_ before passing to deallocator.
* Assertions.
* Shared test between unique_ptr and GetBufferPointer()
* Unnecessary using directives.
* Reallocate vector if released on clear operation.
* Use allocator attribute.
* Renamed `Release()` to `ReleaseBufferPointer()`
* For consistency with `GetBufferPointer()`
* Updated documentation for ReleaseBuffer.

Change-Id: I108527778e56ae5127abf9e5b1be6b445ad75cb7
2015-03-11 17:27:38 -07:00
loverszhaokai 432f3f26a4 Added Copyright headers
Change-Id: I106de8985cea572590d49c896b72c54f33e73bd2
2015-03-11 17:27:38 -07:00
Alex Ames c243aa4e15 Merge "Added the hash attribute to ints and longs." into ub-games-master 2015-02-17 22:58:04 +00:00
Alex Ames d575321eba Added the hash attribute to ints and longs.
FlatBuffer schema files can now optionally specify a hash attribute that
will allow someone writing json files to enter a string to be hashed
rather than a specific value. The hashing algorithm to use is specified
by the schema.

Currently the only algorithms are fnv1 and fnv1a. There are 32 bit and
64 variatns for each. Additionally, a hashing command line tool was
added so that you can see what a string will hash to without needing to
inspect the flatbuffer binary blob.

Change-Id: I0cb359d0e2dc7d2dc1874b446dc19a17cc77109d
2015-02-17 14:10:18 -08:00
Hyungjin Kim c9a840e935 Change nested_root accessor to be const function.
The `<field>_nested_root()` is not viable from const object. (We usually get `const Monster *`.)

Change-Id: I0d0adcb38dd974318608417ee3094c34fb9c480d
2015-02-11 10:54:03 -08:00
Florian Enner b0910e75e0 added reuse option for root objects
getRootAs..() function now has a second implementation that
accepts an existing object to allow object reuse, much like
all other methods that refer to objects.

Change-Id: Iffef567c903a130761ef7de98867e5465d29a04d
2015-02-04 15:30:07 -08:00
Wouter van Oortmerssen 4fb5a764df Support for booleans in the Java/C# API
Change-Id: I72e92183a7b5f4145ea51fcec29257dc9553a461
2015-01-26 13:08:44 -08:00
Wouter van Oortmerssen 6c2dc41e0d Parser will allow a table or vector to have a trailing comma.
Unless in --strict-json mode.
Also added strict_json option to the parser, which in
addition controls if field names without quotes are allowed.

Change-Id: Id56fe5c780bdb9170958050ffa8fa23cf2babe95
Tested: on Linux.
2015-01-21 11:18:01 -08:00
Wouter van Oortmerssen e568f17096 Fixed C# SizedByteArray copying leading bytes of ByteBuffer.
Tested: on Windows.

Change-Id: I946dacf799eae835ec041ea759622f74b0384937
2015-01-16 15:36:25 -08:00
Wouter van Oortmerssen 3550899987 Sorted Vector & binary search functionality.
Bug: 16659276
Tested: on Linux & Windows.

Change-Id: Ie7a73810345fad4cf0a3ad03dfaa5464e3ed5ac8
2015-01-16 10:59:52 -08:00
Wouter van Oortmerssen b7cb91c34e Made CreateUninitializedVector return the buffer.
Previously, obtaining the buffer was unclear and required multiple
casts.

Change-Id: I18e01c9e669886ac250e83aad10623cbddd629b6
Tested: on Linux.
2015-01-07 13:37:25 -08:00