Descriptors

enum class bencode::descriptor_type : std::uint8_t

Enumeration type specifying the data stored in a descriptor.

Values:

enumerator integer

descriptor holds integer data

enumerator string

descriptor holds string data

enumerator list

descriptor holds list data

enumerator dict

descriptor holds dict data

enumerator none

object has no modifiers

enumerator list_value

value is a list item

enumerator dict_key

value is a dict key

enumerator dict_value

value is a dict value

enumerator end

list or dict descriptor is end descriptor

enumerator stop

placholder type for the end of a sequence of descriptors

class descriptor

class describing the value and metadata contained in bencode tokens.

Public Functions

inline constexpr bencode_type type() const noexcept

Returns the type of the bencode data.

Returns

the type of the bencode data

inline constexpr bool is_integer() const noexcept

Returns true if the descriptor describes an integer, false otherwise.

inline constexpr bool is_string() const noexcept

Returns true if the descriptor describes a string, false otherwise.

inline constexpr bool is_list_begin() const noexcept

Returns true if the descriptor describes a list start token.

inline constexpr bool is_list_end() const noexcept

Returns true if the descriptor describes a list end token, false otherwise.

inline constexpr bool is_dict_begin() const noexcept

Returns true if the descriptor describes a dict start token, false otherwise.

inline constexpr bool is_dict_end() const noexcept

Returns true if the descriptor describes a dict end token, false otherwise.

inline constexpr bool is_list() const noexcept

Returns true if the descriptor describes a list start or end token, false otherwise.

inline constexpr bool is_dict() const noexcept

Returns true if the descriptor describes a dict start or end token, false otherwise.

inline constexpr bool is_list_value() const noexcept

Returns true if the descriptor describes a value of a list, false otherwise.

inline constexpr bool is_dict_key() const noexcept

Returns true if the descriptor describes a dict key, false otherwise.

inline constexpr bool is_dict_value() const noexcept

Returns true if the descriptor describes a dict value, false otherwise.

inline constexpr auto position() const noexcept -> std::uint32_t

Returns the position in the bencoded buffer of the start of the token.

inline constexpr auto value() const noexcept -> std::int64_t

Returns the value of an integer token, Behavior is undefined if the data type is not an integer.

inline constexpr void set_value(std::int64_t v) noexcept

Sets the value of an integer token, Behavior is undefined if the data type is not an integer.

Parameters

v – the value to set

inline constexpr auto size() const noexcept -> std::uint32_t

Returns the size of a string, list or dict data type. Behavior is undefined if the data type is an integer.

inline constexpr void set_size(std::uint32_t v) noexcept

Sets the size of a string, list or dict data type. Behavior is undefined if the data type is an integer.

Parameters

v – the size to set

inline constexpr auto offset() const noexcept -> std::uint32_t

Returns the offset to matching begin/end token for list/dict, or the offset to the string data for strings. Behavior is undefined if the data type is an integer.

inline constexpr void set_offset(std::uint32_t v) noexcept

Sets the offset to matching begin/end token for list/dict, or the offset to the string data for strings. Behavior is undefined if the data type is an integer.

Parameters

v – the offset to set

inline constexpr void set_stop_flag(bool flag = true) noexcept

Set this descriptor to be the last one in a sequence of descriptors.

Parameters

flag – whether to enable or disable the stop flag

inline constexpr bool operator==(const descriptor &that) const noexcept

Compare equality

Parameters

that – the descriptor to compare with

class descriptor_table

Data structure that hold a contiguous sequence of descriptors and a pointer to the bencoded data they describe.

A descriptor_table instance is the result parsing bencoded data with a descriptor_parser. The bencoded data can be accessed using a bview instance with get_bview().

See also

descriptor_parser

Public Functions

inline bview get_root(std::size_t pos = 0) const noexcept

Returns a bview instance for to the data described by the descriptor at pos.

inline std::vector<descriptor> &descriptors() noexcept

Returns a reference to a std::vector storing the descriptors.

inline const std::vector<descriptor> &descriptors() const noexcept

Returns a reference to a std::vector storing the descriptors.