mirror of
https://github.com/vee1e/flatbuffers.git
synced 2026-09-01 17:57:25 +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:
parent
cbdf82e2fb
commit
0798b7b698
3 changed files with 43 additions and 3 deletions
|
|
@ -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.
|
||||
*/
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue