#bencode #serde #deserialization #serialization #torrent

serde_bencoded

Yet another encoding/decoding library for bencode

2 releases

0.3.1 Jun 16, 2021
0.3.0 Jan 30, 2021
0.2.2 Jan 25, 2021
0.1.2 Dec 24, 2020

#546 in Encoding

45 downloads per month

MIT/Apache

60KB
1.5K SLoC

crates.io Docs dependency status

Crate for encoding/decoding bencode

What is bencode? It's the encoding mostly used in .torrent files and BitTorrent protocol. For more info see BitTorrentSpecification#Bencoding.

Quick example

See examples directory

#[derive(Debug, Serialize, Deserialize)]
struct MetaInfo {
    info: Info,
    announce: String,
    #[serde(rename = "announce-list")]
    announce_list: Option<Vec<Vec<String>>>,
    #[serde(rename = "creation date")]
    creation_date: Option<u64>,
    comment: Option<String>,
    #[serde(rename = "created by")]
    created_by: Option<String>,
    encoding: Option<String>,
}

fn main(){
    let string = serde_bencoded::to_string(&MetaInfo{...}).unwrap;
    let mi: MetaInfo = serde_bencoded::from_str(&string).unwrap();
}

Dependencies

~275–450KB