|
2 | 2 | #include <stdint.h>
|
3 | 3 | #include <vector>
|
4 | 4 | #include <iostream>
|
| 5 | +#include <sstream> |
5 | 6 | #include <system_error>
|
6 | 7 | #include <functional>
|
7 | 8 |
|
@@ -158,7 +159,7 @@ void RedisReply::checkReplyType(int expectedType)
|
158 | 159 | const char *err = (m_reply->type == REDIS_REPLY_STRING || m_reply->type == REDIS_REPLY_ERROR) ?
|
159 | 160 | m_reply->str : "NON-STRING-REPLY";
|
160 | 161 |
|
161 |
| - string errmsg = "Expected to get redis type " + to_string(expectedType) + " got type " + to_string(m_reply->type) + ", err: " + err; |
| 162 | + string errmsg = "Expected to get redis type " + std::to_string(expectedType) + " got type " + std::to_string(m_reply->type) + ", err: " + err; |
162 | 163 | SWSS_LOG_ERROR("%s", errmsg.c_str());
|
163 | 164 | throw system_error(make_error_code(errc::io_error), errmsg);
|
164 | 165 | }
|
@@ -225,4 +226,44 @@ template<> RedisMessage RedisReply::getReply<RedisMessage>()
|
225 | 226 | return ret;
|
226 | 227 | }
|
227 | 228 |
|
| 229 | + |
| 230 | +string RedisReply::to_string() |
| 231 | +{ |
| 232 | + return to_string(getContext()); |
| 233 | +} |
| 234 | + |
| 235 | +string RedisReply::to_string(redisReply *reply) |
| 236 | +{ |
| 237 | + switch(reply->type) |
| 238 | + { |
| 239 | + case REDIS_REPLY_INTEGER: |
| 240 | + return std::to_string(reply->integer); |
| 241 | + |
| 242 | + case REDIS_REPLY_STRING: |
| 243 | + case REDIS_REPLY_ERROR: |
| 244 | + case REDIS_REPLY_STATUS: |
| 245 | + case REDIS_REPLY_NIL: |
| 246 | + return string(reply->str, reply->len); |
| 247 | + |
| 248 | + case REDIS_REPLY_ARRAY: |
| 249 | + { |
| 250 | + stringstream result; |
| 251 | + for (size_t i = 0; i < reply->elements; i++) |
| 252 | + { |
| 253 | + result << to_string(reply->element[i]); |
| 254 | + |
| 255 | + if (i < reply->elements - 1) |
| 256 | + { |
| 257 | + result << endl; |
| 258 | + } |
| 259 | + } |
| 260 | + return result.str(); |
| 261 | + } |
| 262 | + |
| 263 | + default: |
| 264 | + SWSS_LOG_ERROR("invalid type %d for message", reply->type); |
| 265 | + return string(); |
| 266 | + } |
| 267 | +} |
| 268 | + |
228 | 269 | }
|
0 commit comments