File indexing completed on 2025-12-16 10:08:24
0001
0002
0003
0004
0005
0006
0007 #ifndef BOOST_REDIS_RESP3_TYPE_HPP
0008 #define BOOST_REDIS_RESP3_TYPE_HPP
0009
0010 #include <boost/assert.hpp>
0011 #include <ostream>
0012 #include <vector>
0013 #include <string>
0014
0015 namespace boost::redis::resp3 {
0016
0017
0018
0019
0020
0021
0022 enum class type
0023 {
0024 array,
0025
0026 push,
0027
0028 set,
0029
0030 map,
0031
0032 attribute,
0033
0034 simple_string,
0035
0036 simple_error,
0037
0038 number,
0039
0040 doublean,
0041
0042 boolean,
0043
0044 big_number,
0045
0046 null,
0047
0048 blob_error,
0049
0050 verbatim_string,
0051
0052 blob_string,
0053
0054 streamed_string,
0055
0056 streamed_string_part,
0057
0058 invalid
0059 };
0060
0061
0062
0063
0064
0065 auto to_string(type t) noexcept -> char const*;
0066
0067
0068
0069
0070
0071
0072 auto operator<<(std::ostream& os, type t) -> std::ostream&;
0073
0074
0075
0076 constexpr auto is_aggregate(type t) noexcept -> bool
0077 {
0078 switch (t) {
0079 case type::array:
0080 case type::push:
0081 case type::set:
0082 case type::map:
0083 case type::attribute: return true;
0084 default: return false;
0085 }
0086 }
0087
0088
0089
0090 constexpr auto element_multiplicity(type t) noexcept -> std::size_t
0091 {
0092 switch (t) {
0093 case type::map:
0094 case type::attribute: return 2ULL;
0095 default: return 1ULL;
0096 }
0097 }
0098
0099
0100 constexpr auto to_code(type t) noexcept -> char
0101 {
0102 switch (t) {
0103 case type::blob_error: return '!';
0104 case type::verbatim_string: return '=';
0105 case type::blob_string: return '$';
0106 case type::streamed_string_part: return ';';
0107 case type::simple_error: return '-';
0108 case type::number: return ':';
0109 case type::doublean: return ',';
0110 case type::boolean: return '#';
0111 case type::big_number: return '(';
0112 case type::simple_string: return '+';
0113 case type::null: return '_';
0114 case type::push: return '>';
0115 case type::set: return '~';
0116 case type::array: return '*';
0117 case type::attribute: return '|';
0118 case type::map: return '%';
0119
0120 default: BOOST_ASSERT(false); return ' ';
0121 }
0122 }
0123
0124
0125 constexpr auto to_type(char c) noexcept -> type
0126 {
0127 switch (c) {
0128 case '!': return type::blob_error;
0129 case '=': return type::verbatim_string;
0130 case '$': return type::blob_string;
0131 case ';': return type::streamed_string_part;
0132 case '-': return type::simple_error;
0133 case ':': return type::number;
0134 case ',': return type::doublean;
0135 case '#': return type::boolean;
0136 case '(': return type::big_number;
0137 case '+': return type::simple_string;
0138 case '_': return type::null;
0139 case '>': return type::push;
0140 case '~': return type::set;
0141 case '*': return type::array;
0142 case '|': return type::attribute;
0143 case '%': return type::map;
0144 default: return type::invalid;
0145 }
0146 }
0147
0148 }
0149
0150 #endif