benc0de

Crates.iobenc0de
lib.rsbenc0de
version0.2.0
sourcesrc
created_at2020-10-23 14:09:32.246205
updated_at2020-10-23 19:03:00.371116
descriptionA super-faster bencode parser
homepage
repository
max_upload_size
id304677
size14,769
Marcel (oompf)

documentation

README

bencode

Super-fast, zero-allocation bencode parser written in Rust.

How fast is it?

Very fast! You can expect to parse AND extract data at a rate of 0.5 GB/s.

Quick start

let bs = "d4:listli1ei2ee4:ping4:ponge".as_bytes(); // Bencode data to parse.

let parser = BenParser::new();

let mut root = parser.parse(bs);

// Iterate through list of numbers
for item in root.get("list").iter_numbers() {
  // ...
}

// Get byte value from dict
let val = root.get("ping").bytes().unwrap();

// The parser is fault tolerant.
let val = root.get("ping").get("some_other").bytes(); // --> Returns None.

Performance tip

This library is especially fast, if you query dict entries alphabetically.

root.get("a").bytes().unwrap(); // Query bytes
root.get("b").number().unwrap(); // Query number (isize)
root.get("c").get("nested_entry").iter_bytes();

// Caching is also useful.
let c = root.get("c");

c.get("nested_entry1");
c.get("nested_entry2");
// ...

Comments

  • This is my first Rust project, so feel free to comment on this.
Commit count: 0

cargo fmt