Boost.Redis
1.84.0
A redis client library
Loading...
Searching...
No Matches
type.hpp
1
/* Copyright (c) 2018-2024 Marcelo Zimbres Silva (mzimbres@gmail.com)
2
*
3
* Distributed under the Boost Software License, Version 1.0. (See
4
* accompanying file LICENSE.txt)
5
*/
6
7
#ifndef BOOST_REDIS_RESP3_TYPE_HPP
8
#define BOOST_REDIS_RESP3_TYPE_HPP
9
10
#include <boost/assert.hpp>
11
12
#include <ostream>
13
#include <string>
14
#include <vector>
15
16
namespace
boost::redis::resp3 {
17
23
enum class
type
24
{
25
array
,
27
push
,
29
set
,
31
map
,
33
attribute
,
35
simple_string
,
37
simple_error
,
39
number
,
41
doublean
,
43
boolean
,
45
big_number
,
47
null
,
49
blob_error
,
51
verbatim_string
,
53
blob_string
,
55
streamed_string
,
57
streamed_string_part
,
59
invalid
60
};
61
66
auto
to_string
(
type
t)
noexcept
->
char
const
*;
67
73
auto
operator<<
(std::ostream& os,
type
t) -> std::ostream&;
74
75
/* Checks whether the data type is an aggregate.
76
*/
77
constexpr
auto
is_aggregate(
type
t)
noexcept
->
bool
78
{
79
switch
(t) {
80
case
type::array
:
81
case
type::push
:
82
case
type::set
:
83
case
type::map
:
84
case
type::attribute
:
return
true
;
85
default
:
return
false
;
86
}
87
}
88
89
// For map and attribute data types this function returns 2. All
90
// other types have value 1.
91
constexpr
auto
element_multiplicity(
type
t)
noexcept
-> std::size_t
92
{
93
switch
(t) {
94
case
type::map
:
95
case
type::attribute
:
return
2ULL;
96
default
:
return
1ULL;
97
}
98
}
99
100
// Returns the wire code of a given type.
101
constexpr
auto
to_code(
type
t)
noexcept
->
char
102
{
103
switch
(t) {
104
case
type::blob_error
:
return
'!'
;
105
case
type::verbatim_string
:
return
'='
;
106
case
type::blob_string
:
return
'$'
;
107
case
type::streamed_string_part
:
return
';'
;
108
case
type::simple_error
:
return
'-'
;
109
case
type::number
:
return
':'
;
110
case
type::doublean
:
return
','
;
111
case
type::boolean
:
return
'#'
;
112
case
type::big_number
:
return
'('
;
113
case
type::simple_string
:
return
'+'
;
114
case
type::null
:
return
'_'
;
115
case
type::push
:
return
'>'
;
116
case
type::set
:
return
'~'
;
117
case
type::array
:
return
'*'
;
118
case
type::attribute
:
return
'|'
;
119
case
type::map
:
return
'%'
;
120
121
default
: BOOST_ASSERT(
false
);
return
' '
;
122
}
123
}
124
125
// Converts a wire-format RESP3 type (char) to a resp3 type.
126
constexpr
auto
to_type(
char
c)
noexcept
->
type
127
{
128
switch
(c) {
129
case
'!'
:
return
type::blob_error
;
130
case
'='
:
return
type::verbatim_string
;
131
case
'$'
:
return
type::blob_string
;
132
case
';'
:
return
type::streamed_string_part
;
133
case
'-'
:
return
type::simple_error
;
134
case
':'
:
return
type::number
;
135
case
','
:
return
type::doublean
;
136
case
'#'
:
return
type::boolean
;
137
case
'('
:
return
type::big_number
;
138
case
'+'
:
return
type::simple_string
;
139
case
'_'
:
return
type::null
;
140
case
'>'
:
return
type::push
;
141
case
'~'
:
return
type::set
;
142
case
'*'
:
return
type::array
;
143
case
'|'
:
return
type::attribute
;
144
case
'%'
:
return
type::map
;
145
default
:
return
type::invalid
;
146
}
147
}
148
149
}
// namespace boost::redis::resp3
150
151
#endif
// BOOST_REDIS_RESP3_TYPE_HPP
boost::redis::resp3::to_string
auto to_string(type t) noexcept -> char const *
Converts the data type to a string.
boost::redis::resp3::type
type
RESP3 data types.
Definition
type.hpp:24
boost::redis::resp3::operator<<
auto operator<<(std::ostream &os, type t) -> std::ostream &
Writes the type to the output stream.
boost::redis::resp3::type::streamed_string_part
@ streamed_string_part
Simple.
boost::redis::resp3::type::map
@ map
Aggregate.
boost::redis::resp3::type::push
@ push
Aaggregate.
boost::redis::resp3::type::blob_string
@ blob_string
Simple.
boost::redis::resp3::type::streamed_string
@ streamed_string
Simple.
boost::redis::resp3::type::null
@ null
Simple.
boost::redis::resp3::type::simple_string
@ simple_string
Simple.
boost::redis::resp3::type::boolean
@ boolean
Simple.
boost::redis::resp3::type::verbatim_string
@ verbatim_string
Simple.
boost::redis::resp3::type::simple_error
@ simple_error
Simple.
boost::redis::resp3::type::big_number
@ big_number
Simple.
boost::redis::resp3::type::number
@ number
Simple.
boost::redis::resp3::type::blob_error
@ blob_error
Simple.
boost::redis::resp3::type::doublean
@ doublean
Simple.
boost::redis::resp3::type::set
@ set
Aggregate.
boost::redis::resp3::type::attribute
@ attribute
Aggregate.
boost::redis::resp3::type::array
@ array
Aggregate.
boost::redis::resp3::type::invalid
@ invalid
Invalid.
include
boost
redis
resp3
type.hpp
Generated on Thu Jul 3 2025 21:13:05 for Boost.Redis by
1.12.0