68 Commits

Author SHA1 Message Date
Derek Bailey
6ff9e90e7e FlatBuffers Version v24.3.7 2024-03-07 15:16:33 -08:00
Derek Bailey
7cd216c51e FlatBuffers Version v24.3.6 2024-03-07 06:52:51 +00:00
razvanalex
d47cd10d77
Add Clear() for python Builder (#8186)
Co-authored-by: Derek Bailey <derekbailey@google.com>
2023-12-17 22:18:11 -08:00
Aaron Barany
5ba80c24e0
Fix python type annotation output when not enabled (#7983)
Fixes #7971

Co-authored-by: Derek Bailey <derekbailey@google.com>
2023-11-29 09:58:21 -08:00
Derek Bailey
0100f6a577
FlatBuffers Version 23.5.26 (#7976) 2023-05-26 10:33:09 -07:00
Chih-Hsuan Yen
a352bdbc34
Fix python tests (#7960)
* Don't generate types unless --python-typing specified

Fixes https://github.com/google/flatbuffers/issues/7944

* Fix incorrect import statements

Fixes https://github.com/google/flatbuffers/issues/7951

* Fix $PYTHONPATH in PythonTest.sh

Regressed from https://github.com/google/flatbuffers/pull/7529

* PythonTest: fail if something goes wrong

GitHub Actions runs `bash PythonTest.sh`, and thus failures were not
visible.

* Build flatc for Python tests

* Regenerate codes

---------

Co-authored-by: Derek Bailey <derekbailey@google.com>
2023-05-17 13:10:51 -07:00
Derek Bailey
72b56fd081
FlatBuffers Version 23.5.9 (#7945) 2023-05-09 09:33:30 -07:00
Derek Bailey
63b7b25289
FlatBuffers 64 for C++ (#7935)
* First working hack of adding 64-bit. Don't judge :)

* Made vector_downward work on 64 bit types

* vector_downward uses size_t, added offset64 to reflection

* cleaned up adding offset64 in parser

* Add C++ testing skeleton for 64-bit

* working test for CreateVector64

* working >2 GiB buffers

* support for large strings

* simplified CreateString<> to just provide the offset type

* generalize CreateVector template

* update test_64.afb due to upstream format change

* Added Vector64 type, which is just an alias for vector ATM

* Switch to Offset64 for Vector64

* Update for reflection bfbs output change

* Starting to add support for vector64 type in C++

* made a generic CreateVector that can handle different offsets and vector types

* Support for 32-vector with 64-addressing

* Vector64 basic builder + tests working

* basic support for json vector64 support

* renamed fields in test_64bit.fbs to better reflect their use

* working C++ vector64 builder

* Apply --annotate-sparse-vector to 64-bit tests

* Enable Vector64 for --annotate-sparse-vectors

* Merged from upstream

* Add `near_string` field for testing 32-bit offsets alongside

* keep track of where the 32-bit and 64-bit regions are for flatbufferbuilder

* move template<> outside class body for GCC

* update run.sh to build and run tests

* basic assertion for adding 64-bit offset at the wrong time

* started to separate `FlatBufferBuilder` into two classes, 1 64-bit aware, the other not

* add test for nested flatbuffer vector64, fix bug in alignment of big vectors

* fixed CreateDirect method by iterating by Offset64 first

* internal refactoring of flatbufferbuilder

* block not supported languages in the parser from using 64-bit

* evolution tests for adding a vector64 field

* conformity tests for adding/removing offset64 attributes

* ensure test is for a big buffer

* add parser error tests for `offset64` and `vector64` attributes

* add missing static that GCC only complains about

* remove stdint-uintn.h header that gets automatically added

* move 64-bit CalculateOffset internal

* fixed return size of EndVector

* various fixes on windows

* add SizeT to vector_downward

* minimze range of size changes in vector and builder

* reworked how tracking if 64-offsets are added

* Add ReturnT to EndVector

* small cleanups

* remove need for second Array definition

* combine IndirectHelpers into one definition

* started support for vector of struct

* Support for 32/64-vectors of structs + Offset64

* small cleanups

* add verification for vector64

* add sized prefix for 64-bit buffers

* add fuzzer for 64-bit

* add example of adding many vectors using a wrapper table

* run the new -bfbs-gen-embed logic on the 64-bit tests

* remove run.sh and fix cmakelist issue

* fixed bazel rules

* fixed some PR comments

* add 64-bit tests to cmakelist
2023-05-09 09:16:30 -07:00
RishabhDeep Singh
13fc75cb6b
FlatBuffers Version 23.5.8 (#7943) 2023-05-09 08:05:25 -07:00
Max Burke
a397dd7e8c
Optionally generate Python type annotations (#7858)
* optionally generate type prefixes and suffixes for python code

* fix codegen error when qualified name is empty

* WIP: Python typing

* more progress towards python typing

* Further iterate on Python generated code typing

* clang-format

* Regenerate code

* add documentation for Python type annotations option

* generate code with Python type annotations

* handle forward references

* clang-format
2023-04-28 09:38:29 -07:00
Max Burke
56ecc1f548
Optionally generate type prefixes and suffixes for python code (#7857)
* optionally generate type prefixes and suffixes for python code

* fix codegen error when qualified name is empty

* generated code updated
2023-04-25 21:38:16 -07:00
Derek Bailey
d44ce00af1 Updated remaining usages of LICENSE.txt 2023-03-03 12:01:08 -08:00
Derek Bailey
01834de25e
FlatBuffers Version 23.3.3 (#7852) 2023-03-03 11:46:55 -08:00
Derek Bailey
ee848a02e1
FlatBuffers Version 23.1.21 (#7796) 2023-01-21 12:46:57 -08:00
Michael Le
1703662285
Flatbuffers Version 23.1.20 (#7794)
* Flatbuffers Version 23.1.20

* Fix warnings

* Fix warnings
2023-01-21 12:03:17 -08:00
Ben Beasley
b23493a7d2
Fix Python host-endianness dependencies (#7773)
* In Python tests, use host-endian-independent dtypes

* Fix host endianness dependence in Python flexbuffers

Co-authored-by: Derek Bailey <derekbailey@google.com>
2023-01-10 10:20:08 -08:00
Derek Bailey
af9ceabeef
FlatBuffers Version 23.1.4 (#7758) 2023-01-04 15:22:46 -08:00
Jared Junyoung Lim
40aa964057
Add Ref.AsStringBytes to flatbuffers.flexbuffers Python API (#7713)
* Add Ref.AsStringBytes to flatbuffers.flexbuffers Python API

* Append Bytes to AsStringBytes return value

Co-authored-by: Jared Junyoung Lim <jaredlim@google.com>
2022-12-14 14:42:56 -08:00
Derek Bailey
acf39ff056
FlatBuffers Version 22.12.06 (#7702) 2022-12-06 22:54:49 -08:00
RishabhDeep Singh
a8d49f2972
Add LICENSE.txt to python (#7692)
* Add LICENSE.txt to python

* Remove LICENSE.txt from python path and used the root LICENSE.txt file
2022-12-05 16:37:21 -08:00
Derek Bailey
8f625561d0
FlatBuffers Version 22.11.23 (#7662) 2022-11-23 11:32:19 -08:00
Derek Bailey
9d2c04d629 FlatBuffers Version 22.11.22 2022-11-22 14:40:01 -08:00
Michael Le
051afd8825
Add CreateSharedString to python builder (#7608)
Co-authored-by: Derek Bailey <derekbailey@google.com>
2022-10-29 00:28:35 +00:00
Derek Bailey
203241ed32
FlatBuffers Version 22.10.26 (#7607) 2022-10-26 16:02:38 -07:00
Derek Bailey
ac485609c4
setup.py: Define version directly
Define the version directly instead of loading from an environment variable and writing to a file.
2022-10-26 15:31:02 -07:00
Derek Bailey
a54ca1e759
FlatBuffers Version 22.10.25 (#7604) 2022-10-26 00:03:49 -07:00
Piotr Dziwiński
54418f371b
Add support for metadata attributes for enum values (#7567) (#7568)
* Add support for metadata attributes for enum values (#7567)

* Fix path lookup in flatc test

* Try a fix for Windows paths

* Convert path to string to fix Windows error
2022-10-06 20:18:00 -04:00
Derek Bailey
c92e78a9f8
FlatBuffers Version 22.9.29 (#7557) 2022-09-29 22:12:07 -07:00
Derek Bailey
76ddae006f
FlatBuffers Version 22.9.24 (#7547) 2022-09-27 11:55:25 -07:00
Joshua Smith
413115858c
[Python] Python fixed size array (#7529)
* feat: Added support for fixed sized arrays to python

Problem:
We encountered that using fixed arrays from C++ to python that python would
not read those arrays correctly due to no size information being encoded in the byte
array itself.

Fix:
Encode the sizes within the generated python file during code generation.
Specfically we add GetArrayAsNumpy to the python version of table, which takes as input
the length of the vector. When generating the python message files we include this length
from the VectorType().fixed_length.

* fix: added digit support for camel case to snake case conversion

Problem:
When including a number in the message name we would encounter cases where SnakeCase would
not add the appropirate breaks. e.g. Int32Stamped -> int_32stamped rather than int_32_stamped.

Fix:
To fix this we can add the condition that we check if the current character is not lower and
not a digit, that we check if the previous character was a lower or digit. If it was a lower
or digit then we add the break.

* fix: Array support for structures

Problem:
The python generated code for handling non-struct and struct vectors
and arrays was inconsistent. The calls to populate the obj api was
creating incorrect code.

Solution:
To fix this the VectorOfStruct and VectorOfNonStruct was rewritten
to handle array cases and bring the two methods in line which each
other.

Testing:
PythonTesting.sh now correctly runs and generates the code for
array_test.fbs.
Minor modifications were done on the test to use the new index
accessor for struct arrays and the script correctly sources the
location of the python code.

* chore: clang format changes

* Added code generated by scripts/generate_code. Modified GetArrayOfNonStruct slightly
to allow for function overloading allowing the user to get a single element of an array
or the whole array.

* Added new_line parameter to OffsetPrefix to allow optional new lines to be added.
This allows us to use the GenIndents method that automatically adds new lines instead.

* Reupload of generated code from the scripts/generate_code.py

* Removed new line in GetVectorAsNumpy.

* Updated Array lengths to use Length methods where possible. Added fallthrough for GenTypePointer. Added digit check to CamelToSnake method. Added and modified tests for ToSnakeCase and CamelToSnake.

* Added range check on the getter methods for vector and array types. Renamed == as is for python
2022-09-22 11:08:09 -07:00
Derek Bailey
06c5c7ed0b
FlatBuffers Version 2.0.8 (#7492) 2022-08-29 20:43:36 -07:00
Caleb Zulawski
49e1ea3335
Implement optional scalars for Python (#7318)
* Implement optional scalars for Python

* Use == for integer comparison, remove empty line

* Fix optional type hint

Co-authored-by: Caleb Zulawski <caleb.zulawski@caci.com>
2022-06-13 09:16:00 -04:00
Derek Bailey
9d1ce9a100
Add parameter back to EndVector (#7246) 2022-04-15 11:24:05 -07:00
qazwsxedcrfvtg14
b300691336
Add reflection support for python (#7026)
We already have the reflection.fbs file and the flatbuffers
python language support.

Adding this feature would give the python developers the
ability to parse the flatbuffers schema and write some tools.

Co-authored-by: Derek Bailey <derekbailey@google.com>
2022-02-10 11:10:47 -08:00
Neil Girdhar
8fd7861b75
Fix warning about deprecated module: imp (#6362) 2021-06-17 13:02:22 -07:00
Richard A Hofer
f8b203c9c4
Add vectorNumElements attribute to Builder for simpler vector creation. (#6328)
* Add vectorNumElements attribute to Builder for simpler vector creation.

This adds a default to EndVector which should simplify its use.

* Update tutorial to reflect new default arg in Python EndVector.

* Remove optional argument to Python EndVector.

* Add generated files.

* Unset Builder.vectorNumElems when not in use.
2020-12-14 12:00:28 -08:00
Richard A Hofer
aafc5dc950
Set default initialSize for Builder to 0 (#6310)
* Set default initialSize for Builder to 0

* Change default size of builder to 1024.

This matches what the C++ and Java versions do.
2020-12-07 16:20:26 -08:00
Omer Akram
77c18c1d69
export a __version__ variable for python module (#5309)
* export a __version__ variable for python module

* assign version to be used below

* better support python2

* Add copyright header
2020-07-30 15:56:21 -07:00
Dmitriy Kovalev
de89bd1933
Implement flexbuffers in python (#5880) 2020-05-07 14:26:33 -07:00
Wouter van Oortmerssen
89b6183ee9 Fix Python min alignment
This was accidentally deleted in:
9fa8245e81

Change-Id: I8cad721e075279f6a67aca81259f73fb75aba482
2020-03-09 16:46:41 -07:00
Joseph Pyott
cc08c0835b
[Python] Fixed potential allignment issue (#5768) 2020-02-12 13:53:09 -08:00
Joseph Pyott
17557f9131
[Python] Fixed issue #5499 (#5764) 2020-02-11 15:02:21 -08:00
Bharat Tak
e9d29c21a7 Python: Add forceDefaults opt to python Builder (#5564)
* Add forceDefaults opt to python Builder

* Add test functions for force_default option for python builder

* Simplify

* Add force default test for UOffsetTFlags
2019-10-17 15:25:05 -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
Will Stott
103f61b685 [Python PyPI] Added classifiers and more links. Fixes typo and #5215 (#5272) 2019-05-08 12:42:20 -07:00
Malthe Borch
e47ca7ab40 Use a hash table to index existing vtables (#5314)
* Use a hash table to index existing vtables

This allows for quick deduplication even in situations where there
might be thousands of vtables due to 'combinatoric explosion'.

This fixes issue #5301.

* Refactor 0-offset trimming

* Improve deduplication benchmark

The routine now generates a set of realistic logical layouts and
uses a timer function that randomly picks a layout for each iteration.

The benchmark runs in batches of # of logical layouts = 1, 10, 100, 1000.

(Note that due to alignment, the actual number of vtables is usually slightly
higher.)
2019-05-06 15:00:02 -07:00
Felix Frank
ad8b1e5dbd [Python] Fast serialization of numpy vectors (#4829)
[Python] Fast serialization of numpy vectors (#4829)
2018-10-15 17:07:08 -07:00
Robert
e1d5fda5d4 python: do not clobber minalign when we create objects (#4833) 2018-07-23 16:29:45 -07:00
Wouter van Oortmerssen
e9912e9298 Added setup.cfg to default to python 2/3 wheels for pypi.
Change-Id: I64cf42aca79c32d21cd15c1415125ba97665d134
2018-06-25 15:08:06 -07:00
Robert Schmidtke
08cf50c54a Java/C#/Python prefixed size support (#4445)
* initial changes to support size prefixed buffers in Java

* add slice equivalent to CSharp ByteBuffer

* resolve TODO for slicing in CSharp code generation

* add newly generated Java and CSharp test sources

* fix typo in comment

* add FinishSizePrefixed methods to CSharp FlatBufferBuilder as well

* add option to allow writing the prefix as well

* generate size-prefixed monster binary as well

* extend JavaTest to test the size prefixed binary as well

* use constants for size prefix length

* fuse common code for getRootAs and getSizePrefixedRootAs

* pulled file identifier out of if

* add FinishSizePrefixed, GetSizePrefixedRootAs support for Python

* Revert "extend JavaTest to test the size prefixed binary as well"

This reverts commit 68be4420dda47e8d0600bb19691f03be71503a68.

* Revert "generate size-prefixed monster binary as well"

This reverts commit 2939516fdf78df4f061c627221e232b312301417.

* fix ByteBuffer.cs Slice() method; add proper CSharp and Java tests

* fix unused parameter

* increment version number

* pulled out generated methods into separate utility class

* pulled out generated methods into separate utility class for Python

* fix indentation

* remove unnecessary comment

* fix newline and copyright

* add ByteBufferUtil to csproj compilation

* hide ByteBuffer's internal data; track offset into parent's array

* test unsafe versions as well; compile and run in debug mode

* clarify help text for size prefix

* move ByteBuffer slicing behavior to subclass

* fix protection levels

* add size prefix support for text generation

* add ByteBufferSlice to csproj compilation

* revert size prefix handling for nested buffers

* use duplicate instead of slice for removing size prefix

* remove slice subclass and use duplicate for removing size prefix

* remove slice specific tests

* remove superfluous command line option
2018-03-12 11:30:46 -07:00