BdecodeNode

A node in the tree produced by Bdecode.decode. The port of libtorrent's bdecode_node (bdecode.hpp). Every node keeps a reference to the original parsed buffer plus the byte span it occupies, so dataSection can hand back the exact bytes a node was parsed from. That is what makes correct info-hashing possible: the v1 info-hash is SHA-1(info-dict's dataSection).

libtorrent stores the whole tree as a flat array of 8-byte tokens that index back into the buffer (a neat allocation-free trick). This port uses an ordinary object tree with the same public API; the flat-token representation is a future optimization that would not change a single call site.

Types

Link copied to clipboard
object Companion
Link copied to clipboard
class DictEntry(val key: ByteArray, val value: BdecodeNode)

A key→value pair inside a dictionary node. Keys are raw bytes (usually ASCII).

Link copied to clipboard

Properties

Link copied to clipboard

True if this is a real node (not the none sentinel / a failed lookup).

Link copied to clipboard

Functions

Link copied to clipboard

Byte offset of this node in the originally parsed buffer.

Link copied to clipboard

The exact bytes this node was parsed from, including the framing characters (d…e, l…e, i…e, <len>:<bytes>). For the info dictionary this is the preimage of the info-hash.

Link copied to clipboard

The i-th (key, value) pair, in parse order.

Link copied to clipboard

Look up key; returns the none sentinel if absent or this isn't a dict.

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
fun dictFindIntValue(key: String, default: Long = 0): Long
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
fun dictFindStringValue(key: String, default: String = ""): String
Link copied to clipboard
fun dictSize(): Int
Link copied to clipboard
fun intValue(): Long
Link copied to clipboard
Link copied to clipboard
fun listIntValueAt(i: Int, default: Long = 0): Long
Link copied to clipboard
fun listSize(): Int
Link copied to clipboard
fun listStringValueAt(i: Int, default: String = ""): String
Link copied to clipboard

Raw string bytes (not NUL-terminated, may be binary).

Link copied to clipboard
Link copied to clipboard

Byte offset of the string content (after the <len>:) in the buffer.

Link copied to clipboard

String value decoded as UTF-8, for text fields.

Link copied to clipboard
open override fun toString(): String