View Project


This is an implementation of Bencode for Rust. Bencode is used for DHTs, Torrents, and Google DataServers. Its a lightweight fast data serialization. Wikipedia

I have also made an implementation of Bencode with Java, JavaScript and PHP.

Implemented Types

Data Structure Default Impl
Vec X Defines own ordering
VecDeque X Defines own ordering
LinkedList X Defines own ordering
HashMap X Ordering missing but content is ordered by key byte representation.
BTreeMap X Defines own ordering
Every Number Type i8-64 u8-64 f32-64 usize
String Types Premitive & Object & u8 array


Here are some examples of how to use the Bencode library.


use crate::variables::bencode_variable::Bencode;
use crate::variables::bencode_object::{BencodeObject, PutObject};

fn main() {
    let mut original = BencodeObject::new();
    original.put("a", "foo");
    original.put("b", "bar");
    original.put("c", 456.78);
    let encoded = original.encode();
    println!("{:?}", encoded);

    let decoded = BencodeObject::decode(encoded);
    println!("{}", decoded.to_string());


Languages used: Rust