Kotlin wrapper for amazing catid/wirehair
Works under:
linux-x86-64
win32-x86-64
// initializing wirehair
Wirehair.init()
// setting sizes
val kPacketSize = 1400
val kMessageBytes = 1000 * 1000 + 333
// creating the message
val message = ByteBuffer.allocateDirect(kMessageBytes) as DirectBuffer
// creating encoder and decoder and releasing them after all stuff is done
Wirehair.Encoder(message, kMessageBytes, kPacketSize).use { encoder ->
Wirehair.Decoder(kMessageBytes, kPacketSize).use { decoder ->
var blockId = 0
while (true) {
// generating unique blockId
blockId++
// generating repair block
val block = ByteArray(kPacketSize)
val writeLen = encoder.encode(blockId, block, kPacketSize)
// imitating 10 percent packet drop
if (blockId % 10 == 0) continue
// accumulating repair blocks
val enough = decoder.decode(blockId, block, writeLen)
if (enough) break
}
// decoding message from accumulated repair blocks
val decoded = ByteArray(kMessageBytes)
decoder.recover(decoded, kMessageBytes)
}
}
Use Jitpack
Feel free to open an issue or suggest a PR
- Bundle
jar
with binaries for major platforms - Add other functions to the high level wrapper