Skip to content

Commit 236b7c9

Browse files
committed
Use ByteBuffer for int serialization into bytes.
This proves to be more reliable than Agreno's UnsafeBuffers.
1 parent ddca4bd commit 236b7c9

File tree

2 files changed

+5
-7
lines changed

2 files changed

+5
-7
lines changed

src/test/java/org/lmdbjava/DbiTest.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@
6262
import java.util.concurrent.TimeoutException;
6363
import java.util.concurrent.atomic.AtomicBoolean;
6464
import java.util.function.*;
65-
import org.agrona.concurrent.UnsafeBuffer;
6665
import org.hamcrest.Matchers;
6766
import org.junit.After;
6867
import org.junit.Before;
@@ -381,7 +380,7 @@ public void putCommitGetByteArray() throws IOException {
381380
try (Txn<byte[]> txn = envBa.txnWrite()) {
382381
final byte[] found = db.get(txn, ba(5));
383382
assertNotNull(found);
384-
assertThat(new UnsafeBuffer(txn.val()).getInt(0), is(5));
383+
assertThat(fromBa(txn.val()), is(5));
385384
}
386385
}
387386
}

src/test/java/org/lmdbjava/TestUtils.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,13 @@ final class TestUtils {
3636
private TestUtils() {}
3737

3838
static byte[] ba(final int value) {
39-
final MutableDirectBuffer b = new UnsafeBuffer(new byte[4]);
40-
b.putInt(0, value);
41-
return b.byteArray();
39+
byte[] bytes = new byte[4];
40+
ByteBuffer.wrap(bytes).putInt(value);
41+
return bytes;
4242
}
4343

4444
static int fromBa(final byte[] ba) {
45-
final MutableDirectBuffer b = new UnsafeBuffer(ba);
46-
return b.getInt(0);
45+
return ByteBuffer.wrap(ba).getInt();
4746
}
4847

4948
static ByteBuffer bb(final int value) {

0 commit comments

Comments
 (0)