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