BtBencode
BtBencode is a library which can help with Bencode encoding/decoding. Bencode is primarily used in BitTorrent related applications.
It uses the Serde library to serialize and deserialize Bencode data. It is similar to Serde JSON in terms of functionality and implementation.
Examples
An example serializing a standard Rust collection type and then deserializing into a custom type:
use BTreeMap;
use Deserialize;
let mut dict: = new;
dict.insert;
let serialized_bytes = to_vec?;
let info: Info = from_slice?;
assert_eq!;
An example deserializing from a slice of bytes into a general Value
representation and then from the Value instance into a more strongly typed
data structure.
use ;
use Value;
let serialized_bytes = to_vec?;
let value: Value = from_slice?;
assert_eq!;
assert_eq!;
let info: Info = from_value?;
assert_eq!;
assert_eq!;
Installation
By default, the std feature is enabled.
Alloc only
If the host environment has an allocator but does not have access to the Rust
std library:
License
Licensed under either of Apache License, Version 2.0 or MIT License at your option.
Contributions
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.