
Facilitates encoding and decoding using the bencoding format, as described in BitTorrent's specification. Supports list encoding, decoding, and validation with simple API methods for seamless integration.
Bencode Library
The bencoding format is described in https://www.bittorrent.org/beps/bep_0003.html
kotlin {
sourceSets {
commonMain.dependencies {
...
implementation("io.github.remmerw:buri:0.0.6")
}
...
}
}
@Test
fun examplesList() {
// prepare data
val value: List<BEObject> = listOf(
555L.bencode(), "hello".bencode()
)
val buffer = Buffer()
// encode
value.encodeBencodeTo(buffer)
// decode
val list = (buffer.decodeBencode() as BEList).toList()
// testing
assertEquals(value.size, list.size)
val a = value.first() as BEInteger
assertEquals(a.toInt(), 555)
val b = value.last() as BEString
assertContentEquals(b.toByteArray(), "hello".encodeToByteArray())
}
Bencode Library
The bencoding format is described in https://www.bittorrent.org/beps/bep_0003.html
kotlin {
sourceSets {
commonMain.dependencies {
...
implementation("io.github.remmerw:buri:0.0.6")
}
...
}
}
@Test
fun examplesList() {
// prepare data
val value: List<BEObject> = listOf(
555L.bencode(), "hello".bencode()
)
val buffer = Buffer()
// encode
value.encodeBencodeTo(buffer)
// decode
val list = (buffer.decodeBencode() as BEList).toList()
// testing
assertEquals(value.size, list.size)
val a = value.first() as BEInteger
assertEquals(a.toInt(), 555)
val b = value.last() as BEString
assertContentEquals(b.toByteArray(), "hello".encodeToByteArray())
}