mirror of
https://github.com/Xahau/xahaud.git
synced 2025-12-06 17:27:52 +00:00
Simplify blob encoding
This commit is contained in:
@@ -19,36 +19,27 @@
|
|||||||
|
|
||||||
#include <BeastConfig.h>
|
#include <BeastConfig.h>
|
||||||
#include <ripple/nodestore/impl/EncodedBlob.h>
|
#include <ripple/nodestore/impl/EncodedBlob.h>
|
||||||
#include <beast/ByteOrder.h>
|
#include <cstring>
|
||||||
|
|
||||||
namespace ripple {
|
namespace ripple {
|
||||||
namespace NodeStore {
|
namespace NodeStore {
|
||||||
|
|
||||||
void
|
void
|
||||||
EncodedBlob::prepare (std::shared_ptr<NodeObject> const& object)
|
EncodedBlob::prepare (
|
||||||
|
std::shared_ptr<NodeObject> const& object)
|
||||||
{
|
{
|
||||||
m_key = object->getHash().begin ();
|
m_key = object->getHash().begin ();
|
||||||
|
|
||||||
// This is how many bytes we need in the flat data
|
auto ret = m_data.alloc(object->getData ().size () + 9);
|
||||||
m_size = object->getData ().size () + 9;
|
|
||||||
|
|
||||||
m_data.ensureSize(m_size);
|
// the first 8 bytes are unused
|
||||||
|
memset (ret, 0, 8);
|
||||||
|
|
||||||
{
|
ret[8] = static_cast<std::uint8_t> (object->getType ());
|
||||||
// these 8 bytes are unused
|
|
||||||
std::uint64_t* buf = static_cast <
|
|
||||||
std::uint64_t*>(m_data.getData ());
|
|
||||||
*buf = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
{
|
memcpy (ret + 9,
|
||||||
unsigned char* buf = static_cast <
|
object->getData ().data(),
|
||||||
unsigned char*> (m_data.getData ());
|
|
||||||
buf [8] = static_cast <
|
|
||||||
unsigned char> (object->getType ());
|
|
||||||
memcpy (&buf [9], object->getData ().data(),
|
|
||||||
object->getData ().size());
|
object->getData ().size());
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,8 +20,8 @@
|
|||||||
#ifndef RIPPLE_NODESTORE_ENCODEDBLOB_H_INCLUDED
|
#ifndef RIPPLE_NODESTORE_ENCODEDBLOB_H_INCLUDED
|
||||||
#define RIPPLE_NODESTORE_ENCODEDBLOB_H_INCLUDED
|
#define RIPPLE_NODESTORE_ENCODEDBLOB_H_INCLUDED
|
||||||
|
|
||||||
|
#include <ripple/basics/Buffer.h>
|
||||||
#include <ripple/nodestore/NodeObject.h>
|
#include <ripple/nodestore/NodeObject.h>
|
||||||
#include <beast/module/core/memory/MemoryBlock.h>
|
|
||||||
#include <cstddef>
|
#include <cstddef>
|
||||||
|
|
||||||
namespace ripple {
|
namespace ripple {
|
||||||
@@ -35,14 +35,25 @@ struct EncodedBlob
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
void prepare (std::shared_ptr<NodeObject> const& object);
|
void prepare (std::shared_ptr<NodeObject> const& object);
|
||||||
void const* getKey () const noexcept { return m_key; }
|
|
||||||
std::size_t getSize () const noexcept { return m_size; }
|
void const* getKey () const noexcept
|
||||||
void const* getData () const noexcept { return m_data.getData (); }
|
{
|
||||||
|
return m_key;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::size_t getSize () const noexcept
|
||||||
|
{
|
||||||
|
return m_data.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
void const* getData () const noexcept
|
||||||
|
{
|
||||||
|
return reinterpret_cast<void const*>(m_data.data());
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void const* m_key;
|
void const* m_key;
|
||||||
beast::MemoryBlock m_data;
|
Buffer m_data;
|
||||||
std::size_t m_size;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user