Check if the object is a String with a valid HLL representation. * Return C_OK if this is true, otherwise reply to the client * with an error and return C_ERR. */
| 1157 | * Return C_OK if this is true, otherwise reply to the client |
| 1158 | * with an error and return C_ERR. */ |
| 1159 | int isHLLObjectOrReply(client *c, robj_roptr o) { |
| 1160 | struct hllhdr *hdr; |
| 1161 | |
| 1162 | /* Key exists, check type */ |
| 1163 | if (checkType(c,o,OBJ_STRING)) |
| 1164 | return C_ERR; /* Error already sent. */ |
| 1165 | |
| 1166 | if (!sdsEncodedObject(o)) goto invalid; |
| 1167 | if (stringObjectLen(o) < sizeof(*hdr)) goto invalid; |
| 1168 | hdr = (hllhdr*)ptrFromObj(o); |
| 1169 | |
| 1170 | /* Magic should be "HYLL". */ |
| 1171 | if (hdr->magic[0] != 'H' || hdr->magic[1] != 'Y' || |
| 1172 | hdr->magic[2] != 'L' || hdr->magic[3] != 'L') goto invalid; |
| 1173 | |
| 1174 | if (hdr->encoding > HLL_MAX_ENCODING) goto invalid; |
| 1175 | |
| 1176 | /* Dense representation string length should match exactly. */ |
| 1177 | if (hdr->encoding == HLL_DENSE && |
| 1178 | stringObjectLen(o) != HLL_DENSE_SIZE) goto invalid; |
| 1179 | |
| 1180 | /* All tests passed. */ |
| 1181 | return C_OK; |
| 1182 | |
| 1183 | invalid: |
| 1184 | addReplyError(c,"-WRONGTYPE Key is not a valid " |
| 1185 | "HyperLogLog string value."); |
| 1186 | return C_ERR; |
| 1187 | } |
| 1188 | |
| 1189 | /* PFADD var ele ele ele ... ele => :0 or :1 */ |
| 1190 | void pfaddCommand(client *c) { |
no test coverage detected