5#include <unordered_map>
11#ifndef LIBRATS_USE_SHARED_PTR_VARIANT
12#if defined(__GNUC__) && (__GNUC__ <= 11)
13#define LIBRATS_USE_SHARED_PTR_VARIANT 1
15#define LIBRATS_USE_SHARED_PTR_VARIANT 0
23using BencodeDict = std::unordered_map<std::string, BencodeValue>;
76 bool has_key(
const std::string& key)
const;
98#if LIBRATS_USE_SHARED_PTR_VARIANT
99 std::variant<int64_t, std::string, std::shared_ptr<BencodeList>, std::shared_ptr<BencodeDict>> value_;
101 std::variant<int64_t, std::string, BencodeList, BencodeDict> value_;
104 void encode_to_buffer(std::vector<uint8_t>& buffer)
const;
117 const uint8_t* data_;
129 bool has_more()
const {
return pos_ < size_; }
130 uint8_t current_byte()
const;
131 uint8_t consume_byte();
132 std::string consume_string(
size_t length);
static BencodeValue decode(const std::vector< uint8_t > &data)
static BencodeValue decode(const std::string &data)
static BencodeValue decode(const uint8_t *data, size_t size)
Represents a bencoded value which can be:
BencodeValue & operator[](size_t index)
const BencodeValue & operator[](size_t index) const
static BencodeValue create_dict()
bool has_key(const std::string &key) const
const BencodeValue & operator[](const std::string &key) const
BencodeValue(const std::string &value)
static BencodeValue create_string(const std::string &value)
std::vector< uint8_t > encode() const
std::string encode_string() const
BencodeValue(const BencodeDict &value)
static BencodeValue create_list()
BencodeValue(const char *value)
const std::string & as_string() const
BencodeValue & operator=(BencodeValue &&other) noexcept
BencodeValue(const BencodeList &value)
BencodeValue(int64_t value)
BencodeValue & operator=(const BencodeValue &other)
BencodeValue & operator[](const std::string &key)
BencodeValue(const BencodeValue &other)
const BencodeDict & as_dict() const
BencodeValue(BencodeValue &&other) noexcept
static BencodeValue create_integer(int64_t value)
void push_back(const BencodeValue &value)
int64_t as_integer() const
const BencodeList & as_list() const
std::unordered_map< std::string, BencodeValue > BencodeDict
std::vector< BencodeValue > BencodeList