Bencode
object Bencode
Bencode encoder, the port of libtorrent's bencode() and bencode_recursive (bencode.hpp). Turns an Entry tree into canonical bencoded bytes.
Dictionary keys are emitted in ascending raw-byte order. This is mandatory: the info-hash of a torrent is the SHA-1/SHA-256 of its bencoded info dictionary, so any client that sorts keys differently would compute a different hash and fail to find peers. libtorrent gets canonical order for free because its entry dict is a std::map; we sort explicitly here.