AntiTopQuark commented on code in PR #2277:
URL: https://github.com/apache/kvrocks/pull/2277#discussion_r1582194527
##########
src/storage/rdb.cc:
##########
@@ -1005,3 +1000,35 @@ Status RDB::rdbSaveBinaryDoubleValue(double val) {
memrev64ifbe(&val);
return stream_->Write((const char *)(&val), sizeof(val));
}
+
+Status RDB::rdbSaveZipListObject(const std::string &elem) {
+ // calc total ziplist size
+ uint prevlen = 0;
+ const size_t ziplist_size = zlHeaderSize + zlEndSize + elem.length() +
+ ZipList::ZipStorePrevEntryLength(nullptr,
prevlen) +
+ ZipList::ZipStoreEntryEncoding(nullptr,
elem.length());
+ auto zl = std::make_unique<unsigned char[]>(ziplist_size);
Review Comment:
thank you very much, done
##########
src/storage/rdb_ziplist.cc:
##########
@@ -152,3 +148,65 @@ Status ZipList::peekOK(size_t n) {
}
uint32_t ZipList::getEncodedLengthSize(uint32_t len) { return len <
ZipListBigLen ? 1 : 5; }
+
+uint32_t ZipList::ZipStorePrevEntryLengthLarge(unsigned char *p, unsigned int
len) {
+ uint32_t u32 = 0;
+ if (p != nullptr) {
+ p[0] = ZipListBigLen;
+ u32 = len;
+ memcpy(p + 1, &u32, sizeof(u32));
+ memrev32ifbe(p + 1);
+ }
+ return 1 + sizeof(uint32_t);
+}
+
+uint32_t ZipList::ZipStorePrevEntryLength(unsigned char *p, unsigned int len) {
+ if (p == nullptr) {
+ return (len < ZipListBigLen) ? 1 : sizeof(uint32_t) + 1;
+ } else {
+ if (len < ZipListBigLen) {
+ p[0] = len;
+ return 1;
+ } else {
+ return ZipStorePrevEntryLengthLarge(p, len);
+ }
+ }
+}
Review Comment:
done
##########
src/storage/rdb_ziplist.h:
##########
@@ -41,4 +53,4 @@ class ZipList {
Status peekOK(size_t n);
void setPreEntryLen(uint32_t len) { pre_entry_len_ = len; }
static uint32_t getEncodedLengthSize(uint32_t len);
-};
+};
Review Comment:
done
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]