cpp-bencoding
|
Decoder of bencoded data. More...
#include <Decoder.h>
Public Member Functions | |
std::unique_ptr< BItem > | decode (const std::string &data) |
Decodes the given bencoded data and returns them. More... | |
std::unique_ptr< BItem > | decode (std::istream &input) |
Reads the data from the given input, decodes them and returns them. More... | |
Static Public Member Functions | |
static std::unique_ptr< Decoder > | create () |
Creates a new decoder. More... | |
Private Member Functions | |
Decoder () | |
Constructs a decoder. More... | |
void | readExpectedChar (std::istream &input, char expected_char) const |
Reads expected_char from input and discards it. More... | |
void | validateInputDoesNotContainUndecodedCharacters (std::istream &input) |
Throws DecodingError if input has not been completely read. More... | |
Integer Decoding | |
std::unique_ptr< BDictionary > | decodeDictionary (std::istream &input) |
Decodes a dictionary from input. More... | |
std::unique_ptr< BDictionary > | decodeDictionaryItemsIntoDictionary (std::istream &input) |
Decodes items from input, adds them to a dictionary, and returns that dictionary. More... | |
std::shared_ptr< BString > | decodeDictionaryKey (std::istream &input) |
Decodes a dictionary key from input. More... | |
std::unique_ptr< BItem > | decodeDictionaryValue (std::istream &input) |
Decodes a dictionary value from input. More... | |
std::unique_ptr< BInteger > | decodeInteger (std::istream &input) const |
Decodes an integer from input. More... | |
std::string | readEncodedInteger (std::istream &input) const |
Reads an encoded integer from input. More... | |
std::unique_ptr< BInteger > | decodeEncodedInteger (const std::string &encodedInteger) const |
Decodes the given encoded integer. More... | |
List Decoding | |
std::unique_ptr< BList > | decodeList (std::istream &input) |
Decodes a list from input. More... | |
std::unique_ptr< BList > | decodeListItemsIntoList (std::istream &input) |
Decodes items from input, appends them to a list, and returns that list. More... | |
String Decoding | |
std::unique_ptr< BString > | decodeString (std::istream &input) const |
Decodes a string from input. More... | |
std::string::size_type | readStringLength (std::istream &input) const |
Reads the string length from input, validates it, and returns it. More... | |
std::string | readStringOfGivenLength (std::istream &input, std::string::size_type length) const |
Reads a string of the given length from input and returns it. More... | |
Decoder of bencoded data.
The format is based on the BitTorrent specification.
Use create() to create instances.
|
private |
Constructs a decoder.
|
static |
Creates a new decoder.
std::unique_ptr< BItem > bencoding::Decoder::decode | ( | const std::string & | data | ) |
Decodes the given bencoded data and returns them.
If there are some characters left after the decoded data, this function throws DecodingError.
std::unique_ptr< BItem > bencoding::Decoder::decode | ( | std::istream & | input | ) |
Reads the data from the given input, decodes them and returns them.
If there are some characters left after the decoding, they are left in input, i.e. they are not read. This behavior differs for the overload of decode() that takes std::string
as the input.
|
private |
Decodes a dictionary from input.
The keys must be bencoded strings. The values may be any bencoded type, including integers, strings, lists, and other dictionaries. This function supports decoding of dictionaries whose keys are not lexicographically sorted (according to the specification, they must be sorted).
|
private |
Decodes items from input, adds them to a dictionary, and returns that dictionary.
|
private |
Decodes a dictionary key from input.
|
private |
Decodes a dictionary value from input.
|
private |
Decodes the given encoded integer.
|
private |
Decodes an integer from input.
Moreover, only the significant digits should be used, one cannot pad the integer with zeroes, such as i04e
(see the specification).
|
private |
Decodes a list from input.
|
private |
Decodes items from input, appends them to a list, and returns that list.
|
private |
Decodes a string from input.
|
private |
Reads an encoded integer from input.
|
private |
Reads expected_char from input and discards it.
|
private |
Reads the string length from input, validates it, and returns it.
|
private |
Reads a string of the given length from input and returns it.
|
private |
Throws DecodingError if input has not been completely read.