Crate bip_bencode

Source
Expand description

Library for parsing and converting bencoded data.

§Examples

Decoding bencoded data:

    extern crate bip_bencode;

    use std::default::Default;
    use bip_bencode::{BencodeRef, BRefAccess, BDecodeOpt};

    fn main() {
        let data = b"d12:lucky_numberi7ee";
        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 bip_bencode;

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

        assert_eq!(&b"d12:lucky_numberi7e12:lucky_string1:7e"[..], &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.
BencodeConvertError
The Error type.
BencodeMut
BencodeMut object that stores references to some data.
BencodeParseError
The Error type.
BencodeRef
BencodeRef object that stores references to some buffer.

Enums§

BencodeConvertErrorKind
The kind of an error.
BencodeMutKind
Abstract representation of a BencodeMut object.
BencodeParseErrorKind
The kind of an error.
BencodeRefKind
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
Convenient wrapper around std::Result.
BencodeParseResult
Convenient wrapper around std::Result.