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§
Macros§
- ben_
bytes - Construct
BencodeMutbytes by supplying a type convertible toVec<u8>. - ben_int
- Construct a
BencodeMutinteger by supplying ani64. - ben_
list - Construct a
BencodeMutlist by supplying a list ofBencodeMutvalues. - ben_map
- Construct a
BencodeMutmap by supplying string references as keys andBencodeMutas values.
Structs§
- BDecode
Opt - Stores decoding options for modifying decode behavior.
- Bencode
Convert Error - The Error type.
- Bencode
Mut BencodeMutobject that stores references to some data.- Bencode
Parse Error - The Error type.
- Bencode
Ref BencodeRefobject that stores references to some buffer.
Enums§
- Bencode
Convert Error Kind - The kind of an error.
- Bencode
MutKind - Abstract representation of a
BencodeMutobject. - Bencode
Parse Error Kind - The kind of an error.
- Bencode
RefKind - Abstract representation of a
BencodeRefobject.
Traits§
- BConvert
- Trait for casting bencode objects and converting conversion errors into application specific errors.
- BDict
Access - Trait for working with generic map data structures.
- BList
Access - Trait for working with generic list data structures.
- BMut
Access - Trait for write access to some bencode type.
- BRef
Access - Trait for read access to some bencode type.
Type Aliases§
- Bencode
Convert Result - Convenient wrapper around
std::Result. - Bencode
Parse Result - Convenient wrapper around
std::Result.