Skip to content

Commit

Permalink
fix(java): Fix header offset issue in MetaStringBytes hashcode (#1668)
Browse files Browse the repository at this point in the history

## What does this PR do?

<!-- Describe the purpose of this PR. -->
MetaStringBytes `hashcode & 0xff`, that is, header, represents the
encoding

## Related issues

<!--
Is there any related issue? Please attach here.

- #xxxx0
- #xxxx1
- #xxxx2
-->


## Does this PR introduce any user-facing change?

<!--
If any user-facing interface changes, please [open an
issue](https://github.com/apache/incubator-fury/issues/new/choose)
describing the need to do so and update the document if necessary.
-->

- [ ] Does this PR introduce any public API change?
- [ ] Does this PR introduce any binary protocol compatibility change?


## Benchmark

<!--
When the PR has an impact on performance (if you don't know whether the
PR will have an impact on performance, you can submit the PR first, and
if it will have impact on performance, the code reviewer will explain
it), be sure to attach a benchmark data here.
-->

---------

Signed-off-by: LiangliangSui <coolsui.coding@gmail.com>
  • Loading branch information
LiangliangSui committed Jun 3, 2024
1 parent da5f847 commit a2515a9
Showing 1 changed file with 4 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
@Internal
final class MetaStringBytes {
static final short DEFAULT_DYNAMIC_WRITE_STRING_ID = -1;
private static final int HEADER_MASK = 0xff;

final byte[] bytes;
final long hashCode;
Expand Down Expand Up @@ -55,7 +56,7 @@ public MetaStringBytes(MetaString metaString) {
hashCode += 256; // last byte is reserved for header.
}
hashCode &= 0xffffffffffffff00L;
int header = metaString.getEncoding().getValue();
int header = metaString.getEncoding().getValue() & HEADER_MASK;
this.hashCode = hashCode | header;
}

Expand All @@ -64,9 +65,8 @@ public String decode(char specialChar1, char specialChar2) {
}

public String decode(MetaStringDecoder decoder) {
int header = (int) (hashCode & 0xff);
int encodingFlags = header & 0b111;
MetaString.Encoding encoding = MetaString.Encoding.values()[encodingFlags];
int header = (int) (hashCode & HEADER_MASK);
MetaString.Encoding encoding = MetaString.Encoding.values()[header];
return decoder.decode(bytes, encoding);
}

Expand Down

0 comments on commit a2515a9

Please sign in to comment.