Skip to content

Wirehair wrapper for Kotlin - O(N) Fountain Code for Large Data

Notifications You must be signed in to change notification settings

seniorjoinu/wirehair-wrapper

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

24 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Wirehair Kotlin Wrapper

Kotlin wrapper for amazing catid/wirehair

Works under:

  • linux-x86-64
  • win32-x86-64

Example

// 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)
    }
}

Install

Use Jitpack

Help

Feel free to open an issue or suggest a PR

TODO

  • Bundle jar with binaries for major platforms
  • Add other functions to the high level wrapper