Generates a DUMP-format representation of the object 'o', adding it to the * io stream pointed by 'rio'. This function can't fail. */
| 5123 | /* Generates a DUMP-format representation of the object 'o', adding it to the |
| 5124 | * io stream pointed by 'rio'. This function can't fail. */ |
| 5125 | void createDumpPayload(rio *payload, robj_roptr o, robj *key) { |
| 5126 | unsigned char buf[2]; |
| 5127 | uint64_t crc; |
| 5128 | |
| 5129 | /* Serialize the object in an RDB-like format. It consist of an object type |
| 5130 | * byte followed by the serialized object. This is understood by RESTORE. */ |
| 5131 | rioInitWithBuffer(payload,sdsempty()); |
| 5132 | serverAssert(rdbSaveObjectType(payload,o)); |
| 5133 | serverAssert(rdbSaveObject(payload,o,key)); |
| 5134 | char szT[32]; |
| 5135 | uint64_t mvcc = mvccFromObj(o); |
| 5136 | snprintf(szT, sizeof(szT), "%" PRIu64, mvcc); |
| 5137 | serverAssert(rdbSaveAuxFieldStrStr(payload,"mvcc-tstamp", szT) != -1); |
| 5138 | |
| 5139 | /* Write the footer, this is how it looks like: |
| 5140 | * ----------------+---------------------+---------------+ |
| 5141 | * ... RDB payload | 2 bytes RDB version | 8 bytes CRC64 | |
| 5142 | * ----------------+---------------------+---------------+ |
| 5143 | * RDB version and CRC are both in little endian. |
| 5144 | */ |
| 5145 | |
| 5146 | /* RDB version */ |
| 5147 | buf[0] = RDB_VERSION & 0xff; |
| 5148 | buf[1] = (RDB_VERSION >> 8) & 0xff; |
| 5149 | payload->io.buffer.ptr = sdscatlen(payload->io.buffer.ptr,buf,2); |
| 5150 | |
| 5151 | /* CRC64 */ |
| 5152 | crc = crc64(0,(unsigned char*)payload->io.buffer.ptr, |
| 5153 | sdslen(payload->io.buffer.ptr)); |
| 5154 | memrev64ifbe(&crc); |
| 5155 | payload->io.buffer.ptr = sdscatlen(payload->io.buffer.ptr,&crc,8); |
| 5156 | } |
| 5157 | |
| 5158 | /* Verify that the RDB version of the dump payload matches the one of this Redis |
| 5159 | * instance and that the checksum is ok. |
no test coverage detected