Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -538,7 +538,7 @@ boolean equals(byte[] other, int otherOffset, int otherLength) {

@Override
boolean equals(ByteBuffer otherBytes, int otherOffset, int otherLength) {
return Binary.equals(value, 0, length, otherBytes, otherOffset, otherLength);
return Binary.equals(value, offset, length, otherBytes, otherOffset, otherLength);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,29 @@ public void testEqualityMethods() throws Exception {
assertThat(bin2).isEqualTo(bin1);
}

@Test
public void testDirectByteBufferEqualityWithOffset() {
ByteBuffer slicedBuffer = ByteBuffer.allocateDirect(3);
slicedBuffer.put(new byte[] {9, 1, 2});
slicedBuffer.position(1);
Binary sliced = Binary.fromConstantByteBuffer(slicedBuffer);

ByteBuffer equalBuffer = ByteBuffer.allocateDirect(2);
equalBuffer.put(new byte[] {1, 2});
equalBuffer.flip();
Binary equal = Binary.fromConstantByteBuffer(equalBuffer);

ByteBuffer differentBuffer = ByteBuffer.allocateDirect(2);
differentBuffer.put(new byte[] {9, 1});
differentBuffer.flip();
Binary different = Binary.fromConstantByteBuffer(differentBuffer);

assertThat(sliced).isEqualTo(equal);
assertThat(equal).isEqualTo(sliced);
assertThat(sliced.hashCode()).isEqualTo(equal.hashCode());
assertThat(different).isNotEqualTo(sliced);
}

@Test
public void testWriteAllTo() throws Exception {
byte[] orig = {10, 9, 8, 7, 6, 5, 4, 3, 2, 1};
Expand Down