In <kotlinx.io> Buffer().get(Long) - returns byte ...
# io
c
In kotlinx.io Buffer().get(Long) - returns byte at position (Long) Not sure if I'm missing something, but is there any way to read short at desired position in Kotlinx.io Buffer?
e
okio.Buffer
doesn't have that either. in general
Buffer
is used for moving segments of bytes from a source to a sink, so the design is to receive and consume sequentially, not act as a persistent array
(which makes it different from
java.nio.Buffer
, but there's only so many names…)
c
Hm. maybe i didn't realize that it is indeed different from java's Buffer
e
nio buffer owns a fixed amount of storage, its position/limit are used to guide where to copy data into/out of it okio buffer (and kotlinx.io) enables *non*copying transfers, by taking ownership of received segments and giving away segments to consumers so while both have some overlapping use cases, position-based access makes more sense in nio (since the storage is always fixed) than okio/kotlinx.io (since storage and indices can change). I think the existing operators are mostly used for being able to "peek" ahead a bit…
c
gotcha. okay. maybe i gotta rethink this/reread this for it to click. FWIW, my use case is pretty small at the moment but just migrating a few kotlin/jvm classes to kmp. so ive been trying to look for 1:1 api swaps in this migration.
FWIW. Think im gonna go this route: https://github.com/DitchOoM/buffer