| 296 | } |
| 297 | |
| 298 | bool RedisRespParser::parseRespSingelArray(const QByteArray &data, QList<QByteArray> &vResult, int &iResult) { |
| 299 | if(data.isEmpty()) |
| 300 | return false; |
| 301 | |
| 302 | if (data.at(0) == '*') { |
| 303 | int ilen = -1; |
| 304 | int index = data.indexOf("\r\n"); |
| 305 | iResult = data.mid(1, index - 1).toInt(); // 列表中元素个数 |
| 306 | int pos = index + 2; // 第一个元素索引 |
| 307 | |
| 308 | for (int i = 0; i < iResult; i++) |
| 309 | { |
| 310 | if(data[pos] == '$') { |
| 311 | index = data.indexOf("\r\n", pos); |
| 312 | ilen = data.mid(pos + 1, index - pos - 1).toInt(); |
| 313 | if (ilen == -1) { |
| 314 | vResult << "nil"; |
| 315 | pos = index + 2; // 下一个元素索引 |
| 316 | } else if (ilen == 0) { |
| 317 | vResult << ""; |
| 318 | pos = index + 4; // 下一个元素索引 |
| 319 | } else { |
| 320 | vResult << data.mid(index + 2, ilen); // 提取并追加元素 |
| 321 | pos = index + 2 + ilen + 2; // 下一个元素索引 |
| 322 | } |
| 323 | } else if(data[pos] == ':' || |
| 324 | data[pos] == '+' || |
| 325 | data[pos] == '-') { |
| 326 | index = data.indexOf("\r\n", pos); |
| 327 | vResult << data.mid(pos + 1, index - pos - 1); |
| 328 | pos = index + 2; |
| 329 | } |
| 330 | } |
| 331 | } else |
| 332 | return false; |
| 333 | |
| 334 | return true; |
| 335 | } |
| 336 | |
| 337 | bool RedisRespParser::parseResp(const QByteArray &data, RespType &rResult) { |
| 338 | if(data.isEmpty()) |
nothing calls this directly
no outgoing calls
no test coverage detected