123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104 |
- #ifndef BOOST_REDIS_RESP3_PARSER_HPP
- #define BOOST_REDIS_RESP3_PARSER_HPP
- #include <boost/redis/resp3/node.hpp>
- #include <boost/system/error_code.hpp>
- #include <array>
- #include <string_view>
- #include <cstdint>
- #include <optional>
- namespace boost::redis::resp3 {
- class parser {
- public:
- using node_type = basic_node<std::string_view>;
- using result = std::optional<node_type>;
- static constexpr std::size_t max_embedded_depth = 5;
- static constexpr std::string_view sep = "\r\n";
- private:
-
-
-
- std::size_t depth_;
-
-
-
- std::array<std::size_t, max_embedded_depth + 1> sizes_;
-
- std::size_t bulk_length_;
-
-
- type bulk_;
-
- std::size_t consumed_;
-
- auto consume_impl(type t, std::string_view elem, system::error_code& ec) -> node_type;
- void commit_elem() noexcept;
-
-
- [[nodiscard]]
- auto bulk_expected() const noexcept -> bool
- { return bulk_ != type::invalid; }
- public:
- parser();
-
- [[nodiscard]]
- auto done() const noexcept -> bool;
- auto get_suggested_buffer_growth(std::size_t hint) const noexcept -> std::size_t;
- auto get_consumed() const noexcept -> std::size_t;
- auto consume(std::string_view view, system::error_code& ec) noexcept -> result;
- void reset();
- };
- template <class Adapter>
- bool
- parse(
- resp3::parser& p,
- std::string_view const& msg,
- Adapter& adapter,
- system::error_code& ec)
- {
- while (!p.done()) {
- auto const res = p.consume(msg, ec);
- if (ec)
- return true;
- if (!res)
- return false;
- adapter(res.value(), ec);
- if (ec)
- return true;
- }
- return true;
- }
- }
- #endif
|