Commit Graph

170 Commits

Author SHA1 Message Date
dreifachstein 35daaf83d3 [Java] Replace Table.UTF8_CHARSET with StandardCharsets.UTF_8 (#5696)
StandardCharsets.UTF_8 is already used in FlexBuffersBuilder.
2020-01-06 09:28:19 -08:00
lu-wang-g a2c12900aa Optimize Pack method using numpy (#5662)
Add the support to pack using numpy for scalar vectors when numpy is available.
2019-12-26 21:42:11 -05:00
lu-wang-g 65f8703572 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.
2019-12-02 14:11:28 -08:00
Tiago Silva 3c964e10ab [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.
2019-11-26 12:25:36 -08:00
Malar Kannan 6beb9f49cb 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
2019-11-14 16:58:35 -08:00
Derek Bailey 46ae3f80a6 [C++, Java, C#, TypeScript, JavaScript] Skip generation of mutable union types (#5599)
* Skip generation of mutable union types

* Removed C# and Java unit tests that mutated a Union type
2019-11-04 14:54:44 -08:00
Paulo Pinheiro 8526e12d73 [Kotlin] Fix union vector accessor after change in Java API (#5605)
Kolin uses java library as dependency, which changed the way it access union vector recently
(e365c502ff).

This changes updates kotlin code generation to match Java's changes.
2019-11-04 14:25:07 -08:00
Lawrence Chan 964365ba69 [Go] Add UnPackTo functions (#5598) 2019-11-04 12:12:25 -08:00
iceboy 32254b7acd [Go] Object API support (#5339)
* start

* works for current usages!

* unpack: vector of struct

* optimize byte slice

* support nested struct

* support null table

* support struct

* support union

* update generated code

* grumble

* fix compiler warning

* update generated code

* wrap type in namespace

* bug

* wrap in namespace

* enum byte arrays

* generate struct for unions

* basic testing

* remove branching

* fix assert

* pack vector of fixed structs correctly

* omit null vectors

* Refactor Union Pack and UnPack methods

Remove append usage to increase code efficiency when dealing with large vectors

* generate goldens
2019-10-31 11:13:45 -07:00
Derek Bailey 8d5e424c65 Add ByteBuffer copy for vector of bytes in Java (#5587) 2019-10-28 09:30:31 -07:00
Kulikov Alexey e365c502ff Java: Added access object for vector of struct and vector of tables. (#5233)
* Java: Added access object for vector of struct and vector of tables.

* Java: Workarounds removed when accessing the union vector.
2019-09-23 09:22:43 -07:00
Kevin Fort 2706381eef Add element size parameter to __vector_as_arraysegment [c#] (#5512)
* Add element size parameter to __vector_as_arraysegment

Add element size parameter to __vector_as_arraysegment fixing issue where VectorAsBytes returns incorrect size span for multibyte element types.

* Update codegen

Update codegen and Table to return typed span.

* update test files

update test files
2019-09-10 17:07:46 -07:00
Jaemin Park 4b870aca98 [Javascript] Fix syntax error for signed enum (#5503)
* wrap quotes to enum name map to prevent syntax errorn when enum value is negative

* Add a test that covers signed enum case
2019-09-05 10:22:04 -07:00
Nathan Williams d0e3870c0f [C#] Fix retrieving enumeration vectors as arrays (#5457)
* [C#] Fix retrieving enumeration vectors as arrays

* [C#] Don't generate CreateVectorBlock for enums
2019-09-03 14:10:54 -07:00
svenk177 4525c91be3 Fix incorrect padding in arrays of structs (Issue #5484) (#5491) 2019-08-23 10:46:47 -07:00
Joseph Pyott 9fa8245e81 Python: Added support for file_identifiers (#5123)
* Python: Added support for file_identifiers

* Added tests. Fixed file_identifier code.

* Python: Fixed excessive padding of file_identifier. Repaired tests.

* Python: Made code compatible with python2.7

* Python: Typo fix in @endcond

* whitespace normaalization

* Stylistic change from if(not X is None) to if(X is not None). Added comment to type string.

* Python: Added support for automatic code generation of file_identifiers. Added tests for said code generation.

* converted sprintf to snprintf

* Bugfix, added snprint deffinition for MSVC

* changed snprint deffinition for MSVC to sprint_s

* changed scanf to IntToStringHex. Renamed HasFileIdentifier to GenHasFileIdentifier.

* Added updated genereated code to commit

* Python bugix: flatc no longer produces HasFileIdentfier for shcemas with no file identifier

* Added tests to verify `MonsterBufferHasIdentifier` returns false on no Identifier

* Python: added tests for GetBufferIdentifier and BufferHasIdentifier
Python: removed unessasary parenethesis in if statements
Minor format changes.

* Python : correceted instances of keyword arguments being called as positional arguments

* fixed typos and grammer in comments

* Minor style fixes

* Indentation fix

* Equals style changes

* Python: Fixed Alignment Issues. Changed test code to test against atual output

* Ran make(forgot to run make last commit)

* Python: Style changes

* Style changes

* indentation and style

* readded CONTRIBUTING.md

* Formatting tweak

Mostly to make CI run again

* More formatting fixes

* More formatting fixes

* More formatting fixes

* More formatting fixes

* Formatting fix

* More formatting fixes

* Formatting

* ran generate_code.sh
2019-07-26 11:06:25 -07:00
Paulo Pinheiro de9aa0cdee Add basic Kotlin support (#5409)
* [Kotlin] Add kotlin generate code for tests and add
kotlin test to TestAll.sh

* [Kotlin] Add Kotlin generator

This change adds support for generating Kotlin classes.

The approach of this generator is to keep it as close
as possible to the java generator for now, in order
to keep the change simple.

It uses the already implemented java runtime,
so we don't support cross-platform nor js Kotlin yet.

Kotlin tests are just a copy of the java tests.

* Add optional ident support for CodeWriter

Identation is important for some languages and
different projects have different ways of ident
code, e.g. tabs vs spaces, so we are adding optional
support on CodeWriter for identation.

* [Kotlin] Add Documentation for Kotlin

* [Kotlin] Modify generated code to use experimental Unsigned types.
2019-07-22 16:05:15 -07:00
Wouter van Oortmerssen 123c7a4890 Updated missing generated code for PR #5313 (fixed arrays)
Change-Id: I249140119e6241beb5aec5670d0e5ccddc8f5251
2019-06-20 10:21:10 -07:00
svenk177 e635141d5b Add support for fixed-size arrays (#5313) 2019-06-18 00:15:13 +02:00
Vladimir Glavnyy 0d2cebccfe Add FLATBUFFERS_COMPATIBILITY string (#5381)
* Add FLATBUFFERS_COMPATIBILITY string

- Add a new __reset method NET/JAVA which hides internal state

* Resolve PR notes

* Use operator new() to __init of Struct and Table

* Restrict visibility of C# Table/Struct to internal level
2019-06-17 19:16:21 +02:00
John Luxford a80db8538c [C#, Java, C++] Fixes issue #5399 by always including namespaces (#5404)
* [C#] Fixes issue #5399 by always including namespaces

* Updated tests for code generator changes

* Fixed 'As' method names
2019-06-14 17:47:07 +02:00
Vladimir Glavnyy 95004218f7 Fix multi-line comments for cpp enums (#5345) (#5346)
- fix CSharp comments generation
- fix Python comments generation
- fix Lua comments generation
- fix PHP comments generation
- fix Dart comments generation
- add brief description of Color enum
- add multi-line comments to the Monster:Color
2019-06-02 12:36:49 -07:00
Wouter van Oortmerssen b652fcc3a7 Break internal Java/C# APIs
This is done on purpose, to avoid API version mismatches that
can cause bad decoding results, see:
https://github.com/google/flatbuffers/issues/5368

Change-Id: I2c857438377e080caad0e2d8bcc758c9b19bd6ec
2019-05-31 13:00:55 -07:00
Wouter van Oortmerssen c978b9ef1f Enforce matching version in Java and C#.
Change-Id: I7f1f12f2f97e5227e0dabc2965ce66a6d41c229c
2019-05-31 12:15:19 -07:00
iceboy 9d92fd92e1 Rename AnyUniqueAliases.T to AnyUniqueAliases.TS to avoid naming conflict (#5362) 2019-05-30 16:02:57 -07:00
Marc Butler 93f74c0363 Generate FlagsAttribute for Csharp (#5370)
For schema enums with the bit_flags attribute, generate the
corresponding System.FlagsAttribute in generated Csharp code.
2019-05-30 15:57:41 -07:00
David Reiss c5e2d37337 [Go] Change two more sites to use enum types (#5359)
Fixes #5357 (regression introduced by #5235)
2019-05-20 14:46:36 -07:00
David Reiss 718ddea558 [Go] Make enums into real types, add String() (#5235)
* [Go] Make enums into real types, add String()

This changes the generated code for enums: instead of type aliases,
they're now distinct types, allowing for better type-checking. Some
client code may have to be changed to add casts.

Enum types now have a String() method, so they implement fmt.Stringer.

An EnumValues map is now generated, in addition to the existing
EnumNames map, to easily map strings to values.

Generated enum files are now gofmt-clean.

Fixes #5207

* use example.ColorGreen explicitly

* use valid enum value in mutation test, add new test for "invalid" enum

* add length check and comment
2019-05-17 12:41:39 -07:00
Vladimir Glavnyy f9ebfcb9c4 Make Monster's Color unsigned (#5318)
- update C++ monster_test::Color to unsigned type
- update Go Color:ubyte in the go_test.go
- add workaround for unsigned enum in java test
- sync generate.bat and generate.sh
2019-05-09 10:07:38 -07:00
Wouter van Oortmerssen ac14c8906f Update GRPC Java generated file.
Change-Id: I57ccbe0b9ccbbec65ca04f9db3cbd62243480d92
2019-04-24 12:34:42 -07:00
David Reiss bfa430309a [Go] Add mutation functions for vector elements (#5221)
Fixes #5206
2019-03-05 21:16:26 -08:00
Kulikov Alexey 4e5152d886 Java: Calculation of vtable and vtable size moved to the __init method. (#5210)
vtable and vtable size depends only on `Table#bb_pos` but calculated in
`Table#_offset` method on each field lookup.
Doing this with every call of `Table#__offset` is redundant.

These values can be read once with change of `Table#bb_pos` and reused
for any field lookup.
2019-02-25 23:45:29 +01:00
Kamil Rojewski 8f8fb2b367 Fixed vector of unions crash in java (#5190)
* Fixed vector of unions crash in java

* Regenerated test code

* Fixed windows tests
2019-02-21 19:50:13 +01:00
Wouter van Oortmerssen 600f3fbcd4 Reduced `force_align` in tests to 8, to work with --object-api.
More detail:
https://github.com/google/flatbuffers/projects/6#card-17401359

See also the .md changes in this commit.

Change-Id: Idfa68b2fd3bdb19979833737d3a3cf83ec1d6775
2019-02-07 14:51:04 -08:00
Travis Staley 31e34faa15 Changing array to be an associative array so that the Name function can work with non-sequential enums as well as those beginning at something other than zero. (#5151)
Also including the resulting changes in php files.
2019-02-04 23:33:57 +01:00
Robert 0eb7b3beb0
[Go] Namespaced imports fix (#5097)
Track and emit required FlatBuffers namespace imports in generated Go code.

Update Go code generator by moving most functionality into the generator class, to facilitate namespace tracking. (Note that the git diff in this combined commit may appear large due to this refactoring, but very little code was actually changed.)
Update Go code generator by tracking namespace imports when generating FlatBuffers code.
Update Go code generator by emitting package imports to correctly reference code in other FlatBuffers namespaces.
Create Go test that checks the usage of InParentNamespace objects (as defined in the example schema).
Create Docker test that checks the Go language port.
Fixes #4883
Fixes #3927

Individual commits:

* remove "static" from soon-to-be method functions
* move almost all functions into class as methods
* set current namespace and emit package names if needed
* track imported namespaces
* parent namespaces work
* docker test for go ^1.11
* update base image name for go docker test
* remove cerr debugging
* formatting fixes
* re-run generate_code.sh
* explicitly test namespace imports and usage
2018-12-27 20:57:19 -05:00
Peter Dillinger 87704e987e Performance improvement to generated+supporting PHP (#5080)
By avoiding redundant alignment+alloc checks (startVector does prep) and virtual calls
(by making the class final) in inner loops.
2018-12-20 16:10:20 -08:00
Sumant Tambe 9635d494b3 Fix Java generator bug that ignores bidi streaming attribute (#5063)
* Fix Java generator bug that ignores streaming: bidi attribute
Tests

* Java gRPC client streaming test

* Java gRPC Bidi Streaming Test
2018-11-29 10:33:17 -08:00
Wouter van Oortmerssen 980a6d66d3 Fixed vectors of enums in object API serialized incorrectly.
And also added tests for them.

Change-Id: I91af1904105435601287291412e82d5066f476a5
Tested: on Linux.
2018-11-05 14:33:36 -08:00
Wouter van Oortmerssen 21591916af Fixed missing code from @javax.annotation PR.
https://github.com/google/flatbuffers/pull/4986 missed part of the
implementation.

Change-Id: Ie41771eb018a550c289c77ebe9ef5c50d1ad6751
2018-11-02 11:40:21 -07:00
Frank Benkstein 91fe9ba93f make unions with type aliases more usable (#5019)
Some generic C++ and Rust code is not generated when unions use type
aliases because of potential ambiguity. Actually check for this
ambiguity and only disable offending code only if it is found.
2018-11-01 12:51:25 -07:00
Felix Hanley 560718e976 Use stdlib context in generated Go files (#4904) 2018-10-22 16:28:58 -07:00
kostya-sh 76d31e1b5e Go - Use Go bool type for bool fields (#4962)
* Use Go bool type for bool fields, and store non-default bool field to test data
2018-10-15 16:55:59 -07:00
Rikard Lundmark 233976c821 Add @javax.annotation.Generated to generated flatbuffer Java types (#4986)
* Add @javax.annotation.Generated to generated flatbuffer Java types.

* Updating test goldens.
2018-10-08 15:29:22 -07:00
kostya-sh a4c362a1ba Use enum types in generated read/mutate methods for Go (#4978) 2018-10-08 14:25:37 -07:00
Wouter van Oortmerssen c0698cc33f Bumped version to 1.10.1 for all languages.
Change-Id: I9a6256d90ea800834a887afdcf888df412018933
2018-10-03 12:48:47 -07:00
kostya-sh 062dcf7007 Use standard header for generated Go files (#4961)
As recommended by https://golang.org/pkg/cmd/go/internal/generate/:

  To convey to humans and machine tools that code is generated,
  generated source should have a line early in the file that
  matches the following regular expression (in Go syntax):

        ^// Code generated .* DO NOT EDIT\.$
2018-10-03 11:19:40 -07:00
Christopher Cifra d0321df8cf C# support for directly reading and writting to memory other than byte[]. For example, ByteBuffer can be initialized with a custom allocator which uses shared memory / memory mapped files. (#4886)
Public access to the backing buffer uses Span<T> instead of ArraySegment<T>.

Writing to the buffer now supports Span<T> in addition to T[].

To maintain backwards compatibility ENABLE_SPAN_T must be defined.
2018-08-23 10:05:31 -07:00
Derek Bailey d8f49e18d7 Mono Fix for Unsafe Mode (#4887)
* Added preprocessor define for C++ if Template Aliases are supported by the compiler

* Revert "Revert "Performance Increase of Vector of Structures using .NET BlockCopy (#4830)""

This reverts commit 1f5eae5d6a.

* Put<T> method was inside #if UNSAFE_BYTEBUFFER which caused compilation failure when building in unsafe mode

* Revert "Added preprocessor define for C++ if Template Aliases are supported by the compiler"

This reverts commit a75af73521.
2018-08-20 16:31:44 -07:00
Wouter van Oortmerssen 1f5eae5d6a Revert "Performance Increase of Vector of Structures using .NET BlockCopy (#4830)"
This reverts commit 7b50004ec9.

Change-Id: I09d6869c16aa3c7fadc537fc9c76eaa3cf7ee7ea
2018-08-20 12:08:21 -07:00