MCPcopy Create free account
hub / github.com/cc20110101/RedisView / parseRespArrayLength

Method parseRespArrayLength

src/RedisView/RedisLib/RedisRespParser.cpp:258–296  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

256}
257
258bool RedisRespParser::parseRespArrayLength(const QByteArray &data, int &pos) {
259
260 if(data.isEmpty())
261 return false;
262
263 if (data.at(0) == '*') {
264 int ilen = -1;
265 int index = data.indexOf("\r\n");
266 int iResult = data.mid(1, index - 1).toInt(); // 列表中元素个数
267 pos = index + 2; // 第一个元素索引
268
269 for (int i = 0; i < iResult; i++)
270 {
271 if(data[pos] == '$') {
272 index = data.indexOf("\r\n", pos);
273 ilen = data.mid(pos + 1, index - pos - 1).toInt();
274 if (ilen == -1) {
275 pos = index + 2; // 下一个元素索引
276 } else if (ilen == 0) {
277 pos = index + 4; // 下一个元素索引
278 } else {
279 pos = index + 2 + ilen + 2; // 下一个元素索引
280 }
281 } else if(data[pos] == ':' ||
282 data[pos] == '+' ||
283 data[pos] == '-') {
284 index = data.indexOf("\r\n", pos);
285 pos = index + 2;
286 } else if(data[pos] == '*') {
287 int iArrayLength = 0;
288 parseRespArrayLength(data.mid(pos),iArrayLength);
289 pos = pos + iArrayLength;
290 }
291 }
292 } else
293 return false;
294
295 return true;
296}
297
298bool RedisRespParser::parseRespSingelArray(const QByteArray &data, QList<QByteArray> &vResult, int &iResult) {
299 if(data.isEmpty())

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected