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

Function lpEncodeString

src/listpack.c:384–400  ·  view source on GitHub ↗

Encode the string element pointed by 's' of size 'len' in the target * buffer 's'. The function should be called with 'buf' having always enough * space for encoding the string. This is done by calling lpEncodeGetType() * before calling this function. */

Source from the content-addressed store, hash-verified

382 * space for encoding the string. This is done by calling lpEncodeGetType()
383 * before calling this function. */
384void lpEncodeString(unsigned char *buf, unsigned char *s, uint32_t len) {
385 if (len < 64) {
386 buf[0] = len | LP_ENCODING_6BIT_STR;
387 memcpy(buf+1,s,len);
388 } else if (len < 4096) {
389 buf[0] = (len >> 8) | LP_ENCODING_12BIT_STR;
390 buf[1] = len & 0xff;
391 memcpy(buf+2,s,len);
392 } else {
393 buf[0] = LP_ENCODING_32BIT_STR;
394 buf[1] = len & 0xff;
395 buf[2] = (len >> 8) & 0xff;
396 buf[3] = (len >> 16) & 0xff;
397 buf[4] = (len >> 24) & 0xff;
398 memcpy(buf+5,s,len);
399 }
400}
401
402/* Return the encoded length of the listpack element pointed by 'p'.
403 * This includes the encoding byte, length bytes, and the element data itself.

Callers 1

lpInsertFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected