cpp-bencoding
cpp-bencoding Documentation

This is an automatically generated API documentation for the cpp-bencoding project.

Namespaces

The base namespace is bencoding. All the classes and functions provided by the library are part of this namespace. Unit tests are placed in the bencoding::tests namespace, which is not included in this API documentation.

Directories

The project files are situated in five directories:

For a more detailed list, see the Files tab in this page's header.

Main Classes

For a more detailed list, see the Classes tab in this page's header.

Example: Creating Data
// To create an integer:
// To create a string:
auto s = bencoding::BString::create("test");
// To create a list:
l->push_back(bencoding::BInteger::create(1));
l->push_back(bencoding::BInteger::create(2));
// To create a dictionary:
Example: Encoding
std::string encodedData = bencoding::encode(data);
Example: Decoding
auto data = bencoding::decode(stream);
if (auto i = data->as<bencoding::BInteger>()) {
std::cout << i->value() << "\n";
} else if (auto s = data->as<bencoding::BString>()) {
std::cout << s->value() << "\n";
} else if (auto l = data->as<bencoding::BList>()) {
for (auto e : l) {
// ...
}
} else if (auto d = data->as<bencoding::BDictionary>()) {
for (auto e : d) {
// ...
}
}

A better way of traversing the decoded data is to use bencoding::BItemVisitor. For an example, see the implementation of bencoding::PrettyPrinter.

Example: Pretty Printing
auto data = bencoding::decode(stream);
std::string repr = bencoding::getPrettyRepr(data);
std::cout << repr << "\n";