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

Function serializeExpire

src/db.cpp:3190–3217  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3188}
3189
3190sds serializeExpire(const expireEntry *pexpire)
3191{
3192 sds str = sdsnewlen(nullptr, sizeof(unsigned));
3193
3194 if (pexpire == nullptr)
3195 {
3196 unsigned zero = 0;
3197 memcpy(str, &zero, sizeof(unsigned));
3198 return str;
3199 }
3200
3201 auto &e = *pexpire;
3202 unsigned celem = (unsigned)e.size();
3203 memcpy(str, &celem, sizeof(unsigned));
3204
3205 for (auto itr = e.begin(); itr != e.end(); ++itr)
3206 {
3207 unsigned subkeylen = itr.subkey() ? (unsigned)sdslen(itr.subkey()) : 0;
3208 size_t strOffset = sdslen(str);
3209 str = sdsgrowzero(str, sdslen(str) + sizeof(unsigned) + subkeylen + sizeof(long long));
3210 memcpy(str + strOffset, &subkeylen, sizeof(unsigned));
3211 if (itr.subkey())
3212 memcpy(str + strOffset + sizeof(unsigned), itr.subkey(), subkeylen);
3213 long long when = itr.when();
3214 memcpy(str + strOffset + sizeof(unsigned) + subkeylen, &when, sizeof(when));
3215 }
3216 return str;
3217}
3218
3219std::unique_ptr<expireEntry> deserializeExpire(const char *str, size_t cch, size_t *poffset)
3220{

Callers 1

Calls 8

sdsnewlenFunction · 0.85
sdslenFunction · 0.85
sdsgrowzeroFunction · 0.85
subkeyMethod · 0.80
sizeMethod · 0.45
beginMethod · 0.45
endMethod · 0.45
whenMethod · 0.45

Tested by

no test coverage detected