| 3188 | } |
| 3189 | |
| 3190 | sds 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 | |
| 3219 | std::unique_ptr<expireEntry> deserializeExpire(const char *str, size_t cch, size_t *poffset) |
| 3220 | { |
no test coverage detected