1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
//! 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);
//! ```
pub use Deserializer;
pub use ;
pub use Serializer;
pub use find_dict_key_span;
pub use BencodeValue;
/// Serialize a value to bencode bytes.
Sized>
/// Deserialize a value from bencode bytes.
///
/// Enforces BEP 3 dictionary key ordering. Use [`from_bytes_lenient`] for
/// peer wire messages where real-world clients may send unsorted keys.
/// Deserialize a value from bencode bytes, accepting unsorted dictionary keys.
///
/// Many real-world BitTorrent clients send extension handshakes and other
/// messages with unsorted dictionary keys. This function accepts such input
/// while still correctly parsing all bencode types.