Added a method FlatBufferBuilder::createSharedString that
enable string sharing for building messages on java.
The shared pool will only contains strings inserted by
this methods.
* [Java] Grow ArrayReadWriteBuf enough to match requested capacity.
Also handle requested capacity overflowing.
* [Java] Improve readability of ArrayReadWriteBuf.requestCapacity()
* [Java] prepare testBuilderGrowth() to fail again once FlexBuffersBuilder uses ByteBufferReadWriteBuf internally, add TestFail() as a better alternative to a plain "assert false"
* [Java] Revert some test changes and extract a small string that was used more than once; one could say three times, however, it might be worthy of a discussion if the third occasion also falls into this category, as it is an independent use case and thus would work in the same way even if the value changed.
Co-authored-by: Markus <markus@greenrobot>
The original implementation of map access is very naive:
- Encode String to UTF8 byte[]
- Creates a new KeyVector
- Performs a binary search to find the key
- return value
So every access to the Map there was useless allocations of Keys and KeyVector
and complete encoding of the search key, which for most comparisons would be wasteful.
This changes completely removes the use of KeyVector and compute the key
positions on the spot. Besides that, it compares keys codepoint-by-codepoint,
avoiding unnecessary allocations and reducing encoding for most cases.
Some benchmarks result in a 2.75x speedup.
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.
* [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.
Empty objects that inherit from Sized would try to access internal
ByteBuffer when Sized::size was called. So we add a single byte in
the empty buffer, so when size() is called it would return 0
The real position of a string is calculated by using the indirect() method,
which should be based on parentWidth and not byteWidth, as it was implemented.
We are also fixing the flag BUILDER_FLAG_SHARE_STRINGS on FlexBuffersBuilder
that was set as '1', same value as BUILDER_FLAG_SHARE_KEYS.
* [FlexBuffers][Java] Implementation of FlexBuffers API
This is the initial attemp to implement FlexBuffer on Java.
There is some limitations as compared to the C++ implementation:
1 - No mutations implemented yet
2 - Does not parse from json
Also, this initial implementation is not focused and performance, but
get the basics write. So there is many opportunities for optimization, for instance,
remove all enums, return CharSequence instead of Strings and object pooling.
* [FlexBuffers][Java] Optimizations and simplification of the Builder API.
This change removes BitWidth enum in favor of static ints. Also
make all "reads" APIs closer to C++ implementation (try to cast or convert
as much as possible, assuming user knows what he is doing). Finally,
we remove the helper classes for building vectors and maps.
There is no official benchmarks, but the unit tests are running in less
than 50% for previous runs, which mean those optimizations are worth it.
* [FlexBuffers][Java] Fix Reference::asString behavior
There was a incorrect assumption that strings would be null-terminated, which
could lead to truncated strings. S now it relies size instead of null-termination.
Other minor improvements
- 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
Introduce a HeapByteBufferFactory singleton instance in order to reduce allocations.
Clarify the usage of LITTLE_ENDIAN ByteBuffers in ByteBufferFactory.
* 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 68be4420dd.
* Revert "generate size-prefixed monster binary as well"
This reverts commit 2939516fdf.
* 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
The ByteBufferFactory interface gives the user an option to specify
the method in which the internal ByteBuffer is allocated. This provides
flexibility in the type of ByteBuffer that can be used.
The sizedInputStream method is an alternative to sizedByteArray that
does not make a copy of the data in memory.
Accessors and constructors now take enum types rather than ints.
Bug: 16570507
Change-Id: I4b50fd64ad2e662ea2481bc0ccea784326fb31c0
Tested: on Linux and Windows.
Also cleaned up ByteBuffer usage in general: ByteBuffer.position
now universally indicates the start of a ByteBuffer.
Change-Id: Ic4bfb98f9df9501b8fc82de2c45db7d7311135ac
Tested: on Linux.
Also fixed flatc not outputting these identifiers for files
compiled on the command-line.
Bug: 16983987
Change-Id: I8b714cfea3a8e144fa52133f62b2f7eda6eb044a
Tested: on Linux
Also removed it appending _wire to filenames, renamed the json golden
file to .golden to not clash with generated files.
Bug: 15781201
Change-Id: I8322861e50d1e5b6a5ab5e4b5e5d8ae13c356eb2
Tested: on Windows and Linux