| 1155 | } |
| 1156 | |
| 1157 | const char *RedisProtocolToLuaTypeAggregate(lua_State *lua, const char *reply, int atype) { |
| 1158 | const char *p = strchr(reply + 1, '\r'); |
| 1159 | int64_t mbulklen = ParseInt<int64_t>(std::string(reply + 1, p - reply - 1), 10).ValueOr(0); |
| 1160 | int j = 0; |
| 1161 | |
| 1162 | p += 2; |
| 1163 | if (mbulklen == -1) { |
| 1164 | lua_pushboolean(lua, 0); |
| 1165 | return p; |
| 1166 | } |
| 1167 | if (atype == '*') { |
| 1168 | lua_newtable(lua); |
| 1169 | for (j = 0; j < mbulklen; j++) { |
| 1170 | lua_pushnumber(lua, j + 1); |
| 1171 | p = RedisProtocolToLuaType(lua, p); |
| 1172 | lua_settable(lua, -3); |
| 1173 | } |
| 1174 | return p; |
| 1175 | } |
| 1176 | |
| 1177 | CHECK(atype == '%' || atype == '~'); |
| 1178 | if (atype == '%' || atype == '~') { |
| 1179 | lua_newtable(lua); |
| 1180 | lua_pushstring(lua, atype == '%' ? "map" : "set"); |
| 1181 | lua_newtable(lua); |
| 1182 | for (j = 0; j < mbulklen; j++) { |
| 1183 | p = RedisProtocolToLuaType(lua, p); |
| 1184 | if (atype == '%') { // map |
| 1185 | p = RedisProtocolToLuaType(lua, p); |
| 1186 | } else { // set |
| 1187 | lua_pushboolean(lua, 1); |
| 1188 | } |
| 1189 | lua_settable(lua, -3); |
| 1190 | } |
| 1191 | lua_settable(lua, -3); |
| 1192 | return p; |
| 1193 | } |
| 1194 | |
| 1195 | // Unreachable, return the original position if it did reach here. |
| 1196 | return reply; |
| 1197 | } |
| 1198 | |
| 1199 | const char *RedisProtocolToLuaTypeNull(lua_State *lua, const char *reply) { |
| 1200 | const char *p = strchr(reply + 1, '\r'); |
no test coverage detected