bencodex-rs
The Rust implementation of Bencodex.
- Correctness - Implement Bencodex spec and passed tests with its testsuites.
- Bencodex JSON - Support encoding Bencodex to JSON and decoding JSON to Bencodex.
- Feature flags - Support
json,json-clifeature flags to minimize binary size in use.
Bencodex JSON feature
bencodex-rs implements Bencodex JSON feature, encoding and decoding both.
To use Bencodex JSON feature, you should enable json feature.
= { = "<VERSION>", = ["json"] }
Encoding to JSON
To encode from Bencodex to JSON, you can use to_json function.
use ;
let json = to_json;
println!;
There are two ways to encode BencodexValue::Binary type, Hex and Base64. You can choose one way with bencodex::json::BinaryEncoding. And you can pass it with bencodex::json::JsonEncodeOptions to bencodex::json::to_json_with_options.
use BencodexValue;
use ;
let json = to_json_with_options;
println!;
Decoding from JSON
To decode from JSON to Bencodex, you can use from_json_string and from_json function.
// from_json_string
use ;
let result = from_json_string;
assert!;
assert_eq!;
// from_json
use from_str;
use ;
let json = from_str.unwrap;
let result = from_json;
assert!;
assert_eq!;
CLI Tool
Also, it provides a CLI tool to encode from Bencodex to JSON and to decode from JSON to Bencodex. You can install it with json-cli feature like the below line:
You can use like the below:
# encode
|
|
|
|
"b64:Eg=="
# decode
|
|