Crate torrust_tracker_contrib_bencode

Source
Expand description

Library for parsing and converting bencoded data.

§Examples

Decoding bencoded data:

    extern crate bencode;

    use bencode::{BencodeRef, BRefAccess, BDecodeOpt};

    fn main() {
        let data = b"d12:lucky_numberi7ee"; // cspell:disable-line
        let bencode = BencodeRef::decode(data, BDecodeOpt::default()).unwrap();

        assert_eq!(7, bencode.dict().unwrap().lookup("lucky_number".as_bytes())
            .unwrap().int().unwrap());
    }

Encoding bencoded data:

    #[macro_use]
    extern crate bencode;

    fn main() {
        let message = (ben_map!{
            "lucky_number" => ben_int!(7),
            "lucky_string" => ben_bytes!("7")
        }).encode();

        let data = b"d12:lucky_numberi7e12:lucky_string1:7e"; // cspell:disable-line
        assert_eq!(&data[..], &message[..]);
    }

Modules§

ext
Traits for extended functionality.
inner
Traits for implementation functionality.

Macros§

ben_bytes
Construct BencodeMut bytes by supplying a type convertible to Vec<u8>.
ben_int
Construct a BencodeMut integer by supplying an i64.
ben_list
Construct a BencodeMut list by supplying a list of BencodeMut values.
ben_map
Construct a BencodeMut map by supplying string references as keys and BencodeMut as values.

Structs§

BDecodeOpt
Stores decoding options for modifying decode behavior.
BencodeMut
BencodeMut object that stores references to some data.
BencodeRef
BencodeRef object that stores references to some buffer.

Enums§

BencodeConvertError
BencodeMutKind
Abstract representation of a BencodeMut object.
BencodeParseError
BencodeRefKind
Abstract representation of a BencodeRef object.
MutKind
Abstract representation of a BencodeMut object.
RefKind
Abstract representation of a BencodeRef object.

Traits§

BConvert
Trait for casting bencode objects and converting conversion errors into application specific errors.
BDictAccess
Trait for working with generic map data structures.
BListAccess
Trait for working with generic list data structures.
BMutAccess
Trait for write access to some bencode type.
BRefAccess
Trait for read access to some bencode type.

Type Aliases§

BencodeConvertResult
BencodeParseResult