17#ifndef TOOLBOX_RESP_PARSER_HPP
18#define TOOLBOX_RESP_PARSER_HPP
25#include <boost/container/small_vector.hpp>
31inline namespace resp {
50template <
typename DerivedT>
52 using Stack = std::stack<int, boost::container::small_vector<int, 8>>;
107 void put_command_line(
char c)
111 void put_simple_string(
char c)
115 void put_error(
char c)
119 void put_integer(
char c)
138 if (
c <
'0' ||
c >
'9') {
140 throw Exception{
"invalid integer"};
142 num_ = num_ * 10 + (
c -
'0');
147 void put_bulk_string(
char c)
159 if (
c <
'0' ||
c >
'9') {
161 throw Exception{
"invalid length"};
163 num_ = num_ * 10 + (
c -
'0');
180 throw Exception{
"invalid bulk string"};
184 void put_array(
char c)
191 if (
c <
'0' ||
c >
'9') {
193 throw Exception{
"invalid length"};
195 num_ = num_ * 10 + (
c -
'0');
203 popped = 1 + pop_if_end();
207 if (!is_top_level()) {
219 if (is_top_level() &&
popped > 0) {
231 template <
typename FnT>
232 void put_string(
char c,
FnT fn)
238 if (!tok_.empty() && tok_.back() ==
'\r') {
243 template <
typename FnT>
247 const int popped{pop_if_end()};
250 if (!is_top_level()) {
262 if (is_top_level() &&
popped > 0) {
274 bool is_top_level()
const noexcept {
return stack_.empty(); }
286 while (!stack_.empty() && --stack_.top() == 0) {
297 std::int64_t num_{0};