Encoding and decoding

namespace bencode

Functions

template<event_producer T>
inline std::string encode(const T &value)

Write bencoded representation of value to a string.

Parameters

value – the value to encode

Returns

a string with the bencoded representation of value.

template<event_producer T>
inline void encode_to(std::ostream &os, const T &value)

Writes the bencoded representation of value to os.

Parameters
  • os – an output stream to write to

  • value – the value to encode

template<std::output_iterator<char> OutputIt, event_producer T>
inline void encode_to(OutputIt it, const T &value)

Writes the bencoded representation of value to it.

Parameters
  • it – output iterator to write to

  • value – the value to encode

namespace bencode

Functions

template<typename Policy = default_bvalue_policy>
inline basic_bvalue<Policy> decode_value(std::istream &is)

Reads bencoded data from the input stream and decodes it to a basic_bvalue.

Template Parameters

Policy – the policy template argument for basic_bvalue, defaults to default_bvalue_policy.

Parameters

is – the input stream to read from

Throws

parse_error – when the bencoded data is malformed.

Returns

the decoded data as a basic_bvalue instantiation.

template<typename Policy = default_bvalue_policy>
inline basic_bvalue<Policy> decode_value(std::string_view sv)

Reads bencoded data from a std::string_view and decodes it to a it to a basic_bvalue.

Template Parameters

Policy – the policy template argument for basic_bvalue, defaults to default_bvalue_policy.

Parameters

sv – the string_view to read from

Throws

parse_error – when the bencoded data is malformed.

Returns

the decoded data as a basic_bvalue instantiation.

template<typename Policy = default_bvalue_policy, rng::input_range Rng>
inline basic_bvalue<Policy> decode_value(const Rng &range)

Reads bencoded data from a range and decodes it to a it basic_bvalue.

Template Parameters

Policy – the policy template argument for basic_bvalue, defaults to default_bvalue_policy.

Parameters

range – the input range to read from

Throws

parse_error – when the bencoded data is malformed.

Returns

the decoded data as a basic_bvalue instantiation.

template<typename Policy = default_bvalue_policy, std::input_iterator InputIterator>
inline basic_bvalue<Policy> decode_value(InputIterator first, InputIterator last)

Reads bencoded data from a pair of iterators to a basic_bvalue.

Template Parameters

Policy – the policy template argument for basic_bvalue, defaults to default_bvalue_policy.

Parameters
  • first – an iterator pointing to the start of the bencoded data

  • last – an iterator pointing one past the end of the bencoded data

Throws

parse_error – when the bencoded data is malformed.

Returns

the decoded data as a basic_bvalue instantiation.

template<typename Policy>
inline std::istream &operator>>(std::istream &is, basic_bvalue<Policy> &value)

Read a basic_bvalue from an input stream.

Parameters

is – the input stream to read data from

Returns

A basic_bvalue instance with data from is.

namespace literals

Functions

inline bencode::bvalue operator""_bvalue(const char *str, std::size_t len)

Construct a bvalue from a bencoded string.

namespace bencode

Functions

inline descriptor_table decode_view(std::string_view view)

Reads bencoded data from a std::string_view and decodes it to a it to a descriptor_table.

Parameters

view – the bencoded data

Throws

parse_error – when the bencoded data is malformed.

Returns

the decoded data as a descriptor table.

template<rng::contiguous_range Rng>
inline descriptor_table decode_view(Rng &&range)

Reads bencoded data from a contiguous range and decodes it to a it to a descriptor_table.

Parameters

range – the range of bencoded data

Throws

parse_error – when the bencoded data is malformed.

Returns

the decoded data as a descriptor_table.

template<std::input_iterator InputIterator>
inline descriptor_table decode_view(InputIterator first, InputIterator last)

Reads bencoded data from a pair of iterators and decodes it to a descriptor_table.

Parameters

first, last – the range of characters to decode

Throws

parse_error – when the bencoded data is malformed.

Returns

the decoded data as a descriptor table.