mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-02 12:05:50 +00:00
[FlexBuffers][Java] Fix wrong access to a string using Reference::asString(). (#5532)
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.
This commit is contained in:
committed by
Wouter van Oortmerssen
parent
cbdf82e2fb
commit
0798b7b698
@@ -481,7 +481,7 @@ public class FlexBuffers {
|
||||
*/
|
||||
public String asString() {
|
||||
if (isString()) {
|
||||
int start = indirect(bb, end, byteWidth);
|
||||
int start = indirect(bb, end, parentWidth);
|
||||
int size = readInt(bb, start - byteWidth, byteWidth);
|
||||
return Utf8.getDefault().decodeUtf8(bb, start, size);
|
||||
}
|
||||
|
||||
@@ -64,7 +64,7 @@ public class FlexBuffersBuilder {
|
||||
* But serialization performance might be slower and consumes more memory. This is ideal if you expect many repeated
|
||||
* strings on the message.
|
||||
*/
|
||||
public static final int BUILDER_FLAG_SHARE_STRINGS = 1;
|
||||
public static final int BUILDER_FLAG_SHARE_STRINGS = 2;
|
||||
/**
|
||||
* Strings and keys will be shared between elements.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user