Expand description
Serde-based bencode codec for BitTorrent.
Bencode is the serialization format used throughout BitTorrent for .torrent
files, tracker responses, and DHT messages. It has four types:
- Integers:
i42e,i-1e,i0e - Byte strings:
4:spam(length-prefixed) - Lists:
l<values>e - Dictionaries:
d<key><value>...e(keys are byte strings, sorted)
§Usage
use serde::{Serialize, Deserialize};
use irontide_bencode::{to_bytes, from_bytes};
#[derive(Serialize, Deserialize, PartialEq, Debug)]
struct Torrent {
announce: String,
#[serde(rename = "piece length")]
piece_length: i64,
}
let torrent = Torrent {
announce: "http://tracker.example.com/announce".into(),
piece_length: 262144,
};
let encoded = to_bytes(&torrent).unwrap();
let decoded: Torrent = from_bytes(&encoded).unwrap();
assert_eq!(torrent, decoded);Structs§
- Deserializer
- Bencode deserializer.
- Serializer
- Bencode serializer.
Enums§
- Bencode
Value - A dynamically-typed bencode value.
- Error
- Errors that can occur during bencode serialization or deserialization.
Functions§
- find_
dict_ key_ span - Find the raw byte span of a value for a given key in a bencoded dictionary.
- from_
bytes - Deserialize a value from bencode bytes.
- from_
bytes_ lenient - Deserialize a value from bencode bytes, accepting unsorted dictionary keys.
- to_
bytes - Serialize a value to bencode bytes.
Type Aliases§
- Result
- Result type alias for bencode operations.