Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/iseki0/kotlinx-serialization-bencoding
A Kotlin serialization codec used to encode/decode bencoding format.
https://github.com/iseki0/kotlinx-serialization-bencoding
bencode kotlin-mpp kotlin-multiplatform kotlinx-serialization
Last synced: about 2 months ago
JSON representation
A Kotlin serialization codec used to encode/decode bencoding format.
- Host: GitHub
- URL: https://github.com/iseki0/kotlinx-serialization-bencoding
- Owner: iseki0
- License: apache-2.0
- Created: 2023-03-30T11:59:12.000Z (almost 2 years ago)
- Default Branch: master
- Last Pushed: 2024-12-10T16:57:23.000Z (2 months ago)
- Last Synced: 2024-12-10T18:19:10.692Z (2 months ago)
- Topics: bencode, kotlin-mpp, kotlin-multiplatform, kotlinx-serialization
- Language: Kotlin
- Homepage:
- Size: 333 KB
- Stars: 4
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# kotlinx-serialization-bencode
![GitHub Actions Workflow Status](https://img.shields.io/github/actions/workflow/status/iseki0/kotlinx-serialization-bencoding/build.yml)
[![Maven Central Version](https://img.shields.io/maven-central/v/space.iseki.bencoding/kotlinx-serialization-bencoding)](https://central.sonatype.com/artifact/space.iseki.bencoding/kotlinx-serialization-bencoding)
![License](https://img.shields.io/github/license/iseki0/kotlinx-serialization-bencoding)A Kotlin serialization codec for bencoding format. (Bittorrent)
Reference: [https://www.bittorrent.org/beps/bep_0003.html](https://www.bittorrent.org/beps/bep_0003.html)
## Usage
Add the dependency to your `build.gradle.kts`
```kotlin
dependencies {
implementation("space.iseki.bencoding:kotlinx-serialization-bencoding:0.2.+")
}
``````kotlin
@Serialization
data class Meta(val announce: String) // The torrent file formatfun foo(input: InputStream) {
println(Bencode.decodeFromStream(data.inputStream()))
}
```## Bencoding Format
The following content is copied
from [https://www.bittorrent.org/beps/bep_0003.html](https://www.bittorrent.org/beps/bep_0003.html) for a memo.- Strings are length-prefixed base ten followed by a colon and the string. For example `4:spam` corresponds to 'spam'.
- Integers are represented by an 'i' followed by the number in base 10 followed by an 'e'. For example `i3e` corresponds
to 3 and `i-3e` corresponds to -3. Integers have no size limitation. `i-0e` is invalid. All encodings with a leading
zero,
such as `i03e`, are invalid, other than i0e, which of course corresponds to 0.
- Lists are encoded as an 'l' followed by their elements (also bencoded) followed by an 'e'. For
example `l4:spam4:eggse`
corresponds to ['spam', 'eggs'].
- Dictionaries are encoded as a 'd' followed by a list of alternating keys and their corresponding values followed by
an 'e'. For example, `d3:cow3:moo4:spam4:eggse` corresponds to {'cow': 'moo', 'spam': 'eggs'} and `d4:spaml1:a1:bee`
corresponds to {'spam': ['a', 'b']}. Keys must be strings and appear in sorted order (sorted as raw strings, not
alphanumerics).