Lilly
03/25/2021, 3:03 PMval buffer = Buffer() // gets filled until a specific condition
val packetList = listOf(/*a list of bytearrays aka packets*)
packetList.forEach { packet ->
fun parse(buffer, packet) {
buffer.write(packet)
while (size != 0L) {
// do some read and skip operations
// need to remove 4 bytes from end of buffer, then return from parse and write the next packet until specific condition occurs
}
}
}
What I could do:
while (size != 0L) {
...
val tmpBuffer = Buffer()
buffer.copyTo(tmpBuffer, consumableRestOfBytes)
buffer.clear()
buffer.write(tmpBuffer.readByteArray())
return
...
But this might happen multiple times and it doesn't seem done properly.
Maybe I could achieve this in a different way. Could you or someone else have a look please?