8 #ifndef BENCODING_DECODER_H 9 #define BENCODING_DECODER_H 43 static std::unique_ptr<Decoder>
create();
45 std::unique_ptr<BItem>
decode(
const std::string &data);
46 std::unique_ptr<BItem>
decode(std::istream &input);
64 std::unique_ptr<BInteger>
decodeInteger(std::istream &input)
const;
67 const std::string &encodedInteger)
const;
72 std::unique_ptr<BList>
decodeList(std::istream &input);
78 std::unique_ptr<BString>
decodeString(std::istream &input)
const;
81 std::string::size_type length)
const;
89 std::unique_ptr<BItem>
decode(
const std::string &data);
90 std::unique_ptr<BItem>
decode(std::istream &input);
std::unique_ptr< BItem > decodeDictionaryValue(std::istream &input)
Decodes a dictionary value from input.
Definition: Decoder.cpp:160
std::unique_ptr< BInteger > decodeInteger(std::istream &input) const
Decodes an integer from input.
Definition: Decoder.cpp:182
std::unique_ptr< BItem > decode(const std::string &data)
Decodes the given bencoded data and returns them.
Definition: Decoder.cpp:46
std::unique_ptr< BList > decodeList(std::istream &input)
Decodes a list from input.
Definition: Decoder.cpp:233
Decoder of bencoded data.
Definition: Decoder.h:41
std::unique_ptr< BItem > decode(const std::string &data)
Decodes the given bencoded data and returns them.
Definition: Decoder.cpp:325
static std::unique_ptr< Decoder > create()
Creates a new decoder.
Definition: Decoder.cpp:36
std::unique_ptr< BString > decodeString(std::istream &input) const
Decodes a string from input.
Definition: Decoder.cpp:265
Main namespace of the bencoding library.
std::unique_ptr< BInteger > decodeEncodedInteger(const std::string &encodedInteger) const
Decodes the given encoded integer.
Definition: Decoder.cpp:204
Base class for all items (integers, strings, etc.).
void readExpectedChar(std::istream &input, char expected_char) const
Reads expected_char from input and discards it.
Definition: Decoder.cpp:91
std::string readStringOfGivenLength(std::istream &input, std::string::size_type length) const
Reads a string of the given length from input and returns it.
Definition: Decoder.cpp:295
Exception thrown when there is an error during the decoding.
Definition: Decoder.h:27
DecodingError(const std::string &what)
Constructs a new exception with the given message.
Definition: Decoder.cpp:25
std::unique_ptr< BList > decodeListItemsIntoList(std::istream &input)
Decodes items from input, appends them to a list, and returns that list.
Definition: Decoder.cpp:244
std::unique_ptr< BDictionary > decodeDictionaryItemsIntoDictionary(std::istream &input)
Decodes items from input, adds them to a dictionary, and returns that dictionary. ...
Definition: Decoder.cpp:131
std::string::size_type readStringLength(std::istream &input) const
Reads the string length from input, validates it, and returns it.
Definition: Decoder.cpp:275
void validateInputDoesNotContainUndecodedCharacters(std::istream &input)
Throws DecodingError if input has not been completely read.
Definition: Decoder.cpp:311
std::string readEncodedInteger(std::istream &input) const
Reads an encoded integer from input.
Definition: Decoder.cpp:189
std::unique_ptr< BDictionary > decodeDictionary(std::istream &input)
Decodes a dictionary from input.
Definition: Decoder.cpp:120
std::shared_ptr< BString > decodeDictionaryKey(std::istream &input)
Decodes a dictionary key from input.
Definition: Decoder.cpp:145
Decoder()
Constructs a decoder.
Definition: Decoder.cpp:31