binf.cljc
binf.cljc copied to clipboard
Absolute read/write fails for offset views in java implementation
The following:
(let [view (-> (binf.buffer/alloc 64)
(binf/view 32 16)
(binf/endian-set :little-endian))]
(binf/wa-b8 view 0 42)
(t/is (= 42 (binf/ra-u8 view 0))))
Works in clojurescript but fails in clojure with the exception:
Unhandled java.lang.IndexOutOfBoundsException 32
HeapByteBuffer.java: 171 java.nio.HeapByteBuffer/get
impl.clj: 89 helins.binf.protocol.impl/eval17986/fn
protocol.cljc: 24 helins.binf.protocol$eval11976$fn__12035$G__11961__12042/invoke
binf.cljc: 69 helins.binf$ra_u8/invokeStatic
binf.cljc: 63 helins.binf$ra_u8/invoke
REPL: 66 helins.binf.test/eval18113
Fix:
(extend-type ByteBuffer
binf.protocol/-IByteBuffer
(-array-index [this position]
position))
This is the same the existing implementation for DirectByteBuffer.
Latest commit on main has fixed this (not yet released) if you fancy giving it a go.
I rewrote the tests using test.check so hopefully there won't be anymore edge cases. But I'll wait a bit before cutting a release.