mirror of
https://github.com/Xahau/xahaud.git
synced 2026-06-04 09:16:36 +00:00
Eliminate dead bytes from nodestore encoding:
The legacy nodestore encoding for blobs had an 8 byte prefix. Originally the first 4 bytes stored the sequence number of the ledger to which the encoded object belogned; the next 4 bytes were never specified rigidly and some versions stored a redundant copy of the ledger sequence while others simply set the bytes to 0. Eventually that scheme was abandoned, and the first 8 bytes were just set to 0 and ignored when reloading a blob. This commit removes the unusued 8 byte legacy prefix. The change is makes it impossible to load old databases with this code and for old versions to load databases created with this code.
This commit is contained in:
@@ -30,10 +30,8 @@ DecodedBlob::DecodedBlob(void const* key, void const* value, int valueBytes)
|
||||
/* Data format:
|
||||
|
||||
Bytes
|
||||
|
||||
0...7 Unused
|
||||
8 char One of NodeObjectType
|
||||
9...end The body of the object data
|
||||
0 uint8 One of NodeObjectType
|
||||
1...end The body of the object data
|
||||
*/
|
||||
|
||||
m_success = false;
|
||||
@@ -41,19 +39,17 @@ DecodedBlob::DecodedBlob(void const* key, void const* value, int valueBytes)
|
||||
// VFALCO NOTE Ledger indexes should have started at 1
|
||||
m_objectType = hotUNKNOWN;
|
||||
m_objectData = nullptr;
|
||||
m_dataBytes = std::max(0, valueBytes - 9);
|
||||
m_dataBytes = std::max(0, valueBytes - 1);
|
||||
|
||||
// VFALCO NOTE What about bytes 4 through 7 inclusive?
|
||||
|
||||
if (valueBytes > 8)
|
||||
if (valueBytes != 0)
|
||||
{
|
||||
unsigned char const* byte = static_cast<unsigned char const*>(value);
|
||||
m_objectType = safe_cast<NodeObjectType>(byte[8]);
|
||||
m_objectType = safe_cast<NodeObjectType>(byte[0]);
|
||||
}
|
||||
|
||||
if (valueBytes > 9)
|
||||
if (valueBytes > 1)
|
||||
{
|
||||
m_objectData = static_cast<unsigned char const*>(value) + 9;
|
||||
m_objectData = static_cast<unsigned char const*>(value) + 1;
|
||||
|
||||
switch (m_objectType)
|
||||
{
|
||||
|
||||
@@ -28,14 +28,11 @@ EncodedBlob::prepare(std::shared_ptr<NodeObject> const& object)
|
||||
{
|
||||
m_key = object->getHash().begin();
|
||||
|
||||
auto ret = m_data.alloc(object->getData().size() + 9);
|
||||
auto ret = m_data.alloc(object->getData().size() + 1);
|
||||
|
||||
// the first 8 bytes are unused
|
||||
std::memset(ret, 0, 8);
|
||||
ret[0] = static_cast<std::uint8_t>(object->getType());
|
||||
|
||||
ret[8] = static_cast<std::uint8_t>(object->getType());
|
||||
|
||||
std::memcpy(ret + 9, object->getData().data(), object->getData().size());
|
||||
std::memcpy(ret + 1, object->getData().data(), object->getData().size());
|
||||
}
|
||||
|
||||
} // namespace NodeStore
|
||||
|
||||
Reference in New Issue
Block a user