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 <ripple/nodestore/impl/EncodedBlob.h>
|
||||
#include <beast/ByteOrder.h>
|
||||
#include <cstring>
|
||||
|
||||
namespace ripple {
|
||||
namespace NodeStore {
|
||||
|
||||
void
|
||||
EncodedBlob::prepare (std::shared_ptr<NodeObject> const& object)
|
||||
EncodedBlob::prepare (
|
||||
std::shared_ptr<NodeObject> const& object)
|
||||
{
|
||||
m_key = object->getHash().begin ();
|
||||
|
||||
// This is how many bytes we need in the flat data
|
||||
m_size = object->getData ().size () + 9;
|
||||
auto ret = m_data.alloc(object->getData ().size () + 9);
|
||||
|
||||
m_data.ensureSize(m_size);
|
||||
// the first 8 bytes are unused
|
||||
memset (ret, 0, 8);
|
||||
|
||||
{
|
||||
// these 8 bytes are unused
|
||||
std::uint64_t* buf = static_cast <
|
||||
std::uint64_t*>(m_data.getData ());
|
||||
*buf = 0;
|
||||
}
|
||||
ret[8] = static_cast<std::uint8_t> (object->getType ());
|
||||
|
||||
{
|
||||
unsigned char* buf = static_cast <
|
||||
unsigned char*> (m_data.getData ());
|
||||
buf [8] = static_cast <
|
||||
unsigned char> (object->getType ());
|
||||
memcpy (&buf [9], object->getData ().data(),
|
||||
object->getData ().size());
|
||||
}
|
||||
memcpy (ret + 9,
|
||||
object->getData ().data(),
|
||||
object->getData ().size());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -20,8 +20,8 @@
|
||||
#ifndef RIPPLE_NODESTORE_ENCODEDBLOB_H_INCLUDED
|
||||
#define RIPPLE_NODESTORE_ENCODEDBLOB_H_INCLUDED
|
||||
|
||||
#include <ripple/basics/Buffer.h>
|
||||
#include <ripple/nodestore/NodeObject.h>
|
||||
#include <beast/module/core/memory/MemoryBlock.h>
|
||||
#include <cstddef>
|
||||
|
||||
namespace ripple {
|
||||
@@ -35,14 +35,25 @@ struct EncodedBlob
|
||||
{
|
||||
public:
|
||||
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* getData () const noexcept { return m_data.getData (); }
|
||||
|
||||
void const* getKey () const noexcept
|
||||
{
|
||||
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:
|
||||
void const* m_key;
|
||||
beast::MemoryBlock m_data;
|
||||
std::size_t m_size;
|
||||
Buffer m_data;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user