Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Use ByteBuffer for int serialization into bytes.
This proves to be more reliable than Agreno's UnsafeBuffers.
  • Loading branch information
LambdAurora committed Jul 9, 2025
commit 236b7c9b912e271bfd6a57c612d12ca641b91d13
3 changes: 1 addition & 2 deletions src/test/java/org/lmdbjava/DbiTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@
import java.util.concurrent.TimeoutException;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.function.*;
import org.agrona.concurrent.UnsafeBuffer;
import org.hamcrest.Matchers;
import org.junit.After;
import org.junit.Before;
Expand Down Expand Up @@ -381,7 +380,7 @@ public void putCommitGetByteArray() throws IOException {
try (Txn<byte[]> txn = envBa.txnWrite()) {
final byte[] found = db.get(txn, ba(5));
assertNotNull(found);
assertThat(new UnsafeBuffer(txn.val()).getInt(0), is(5));
assertThat(fromBa(txn.val()), is(5));
}
}
}
Expand Down
9 changes: 4 additions & 5 deletions src/test/java/org/lmdbjava/TestUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,13 @@ final class TestUtils {
private TestUtils() {}

static byte[] ba(final int value) {
final MutableDirectBuffer b = new UnsafeBuffer(new byte[4]);
b.putInt(0, value);
return b.byteArray();
byte[] bytes = new byte[4];
ByteBuffer.wrap(bytes).putInt(value);
return bytes;
}

static int fromBa(final byte[] ba) {
final MutableDirectBuffer b = new UnsafeBuffer(ba);
return b.getInt(0);
return ByteBuffer.wrap(ba).getInt();
}

static ByteBuffer bb(final int value) {
Expand Down