MCPcopy Create free account
hub / github.com/Snapchat/KeyDB / isHLLObjectOrReply

Function isHLLObjectOrReply

src/hyperloglog.cpp:1159–1187  ·  view source on GitHub ↗

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. */

Source from the content-addressed store, hash-verified

1157 * Return C_OK if this is true, otherwise reply to the client
1158 * with an error and return C_ERR. */
1159int 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
1183invalid:
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 */
1190void pfaddCommand(client *c) {

Callers 4

pfaddCommandFunction · 0.85
pfcountCommandFunction · 0.85
pfmergeCommandFunction · 0.85
pfdebugCommandFunction · 0.85

Calls 4

checkTypeFunction · 0.85
stringObjectLenFunction · 0.85
ptrFromObjFunction · 0.85
addReplyErrorFunction · 0.85

Tested by

no test coverage detected