Crate juicy_bencode
source · [−]Expand description
A little parser for bencode using the Nom library. Nom eats input byte by byte, and bencode is such juicy input!
Bencode allows for 4 kinds of values:
- integers
- byte strings
- lists
- dictionaries
Unlike JSON, bencode doesn’t say how to encode stuff in general, but in practice, you should just//! parse a bencode blob as a dictionary (just like JSON). Although, the individual parsing functions are provided.
For more information about bencode, you’re encourage to read the specification. It’s less than 200 words long!
Enums
Representation of bencode blobs as a tree. The lifetime is tied to the text in memory, achieving almost zero copy. This is perhaps unsuitable for large bencode blobs since the entire blob may not fit inside the memory.
Functions
Main entry for the parser (for all practical purposes, a blob of bencode is consist of key value pairs). It parses out a bencode dictionary, bencode places no restriction on the homogeneity of dictionary pairs.
Parse out bencode list, technically, bencode places not restriction on if the list items are homogeneous, meaning a list could contain both integers and strings.
Parse out a bencode integer, conforming to bencode specification, leading 0s and negative 0 are rejected. Since the bencode specification places no limit on the range of the integers, the function will only give out string slices and leave the conversion choice to the user.`
Parse out a bencode string, note that bencode strings are not equivalent to Rust strings since bencode places no limit what encoding it uses, hence it’s more appreciate to call them byte strings