mirror of
https://github.com/Xahau/xahaud.git
synced 2025-12-06 17:27:52 +00:00
Reduce RippleD dependencies on Beast:
* Use static_assert where appropriate * Use std::min and std::max where appropriate * Simplify RippleD error reporting * Remove use of beast::RandomAccessFile
This commit is contained in:
committed by
Vinnie Falco
parent
e005cfd70e
commit
f9fc9a3518
@@ -33,11 +33,6 @@ FatalErrorReporter::~FatalErrorReporter ()
|
||||
beast::FatalError::setReporter (m_savedReporter);
|
||||
}
|
||||
|
||||
void FatalErrorReporter::reportMessage (beast::String& formattedMessage)
|
||||
{
|
||||
std::cerr << formattedMessage.toRawUTF8 () << std::endl;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
class FatalErrorReporter_test : public beast::unit_test::suite
|
||||
@@ -50,7 +45,8 @@ public:
|
||||
// We don't really expect the program to run after this
|
||||
// but the unit test is here so you can manually test it.
|
||||
|
||||
beast::FatalError ("The unit test intentionally failed", __FILE__, __LINE__);
|
||||
beast::FatalError ("The unit test intentionally failed",
|
||||
__FILE__, __LINE__);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -35,14 +35,13 @@ namespace ripple {
|
||||
constructors that can report a fatal error. Also, the Log would need
|
||||
to be guaranteed to be set up for this handler to work.
|
||||
*/
|
||||
class FatalErrorReporter : public beast::FatalError::Reporter
|
||||
class FatalErrorReporter
|
||||
: public beast::FatalError::Reporter
|
||||
{
|
||||
public:
|
||||
FatalErrorReporter ();
|
||||
~FatalErrorReporter ();
|
||||
|
||||
void reportMessage (beast::String& formattedMessage);
|
||||
|
||||
private:
|
||||
beast::FatalError::Reporter* m_savedReporter;
|
||||
};
|
||||
|
||||
@@ -17,6 +17,8 @@
|
||||
*/
|
||||
//==============================================================================
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
namespace ripple {
|
||||
namespace NodeStore {
|
||||
|
||||
@@ -38,7 +40,7 @@ DecodedBlob::DecodedBlob (void const* key, void const* value, int valueBytes)
|
||||
m_ledgerIndex = LedgerIndex (-1);
|
||||
m_objectType = hotUNKNOWN;
|
||||
m_objectData = nullptr;
|
||||
m_dataBytes = beast::bmax (0, valueBytes - 9);
|
||||
m_dataBytes = std::max (0, valueBytes - 9);
|
||||
|
||||
if (valueBytes > 4)
|
||||
{
|
||||
|
||||
@@ -31,7 +31,8 @@ EncodedBlob::prepare (NodeObject::Ptr const& object)
|
||||
m_data.ensureSize (m_size);
|
||||
|
||||
// These sizes must be the same!
|
||||
static_bassert (sizeof (std::uint32_t) == sizeof (object->getLedgerIndex ()));
|
||||
static_assert (sizeof (std::uint32_t) == sizeof (object->getLedgerIndex ()),
|
||||
"Ledger Indices must be exactly 32-bits long.");
|
||||
|
||||
{
|
||||
std::uint32_t* buf = static_cast <std::uint32_t*> (m_data.getData ());
|
||||
|
||||
@@ -18,7 +18,9 @@
|
||||
//==============================================================================
|
||||
|
||||
#include <ripple/validators/impl/Utilities.h>
|
||||
#include <beast/module/core/files/RandomAccessFile.h>
|
||||
|
||||
#include <fstream>
|
||||
#include <string>
|
||||
|
||||
namespace ripple {
|
||||
namespace Validators {
|
||||
@@ -54,28 +56,21 @@ public:
|
||||
|
||||
void fetch (Results& results, beast::Journal journal)
|
||||
{
|
||||
std::int64_t const fileSize (m_file.getSize ());
|
||||
// 8MB is a somewhat arbitrary maximum file size, but it should be
|
||||
// enough to cover all cases in the foreseeable future.
|
||||
|
||||
if (fileSize != 0)
|
||||
std::int64_t const maxFileSize = 8 * 1024 * 1024;
|
||||
std::int64_t const fileSize = m_file.getSize ();
|
||||
|
||||
if (fileSize != 0 && (fileSize < maxFileSize))
|
||||
{
|
||||
if (fileSize < std::numeric_limits<std::int32_t>::max())
|
||||
{
|
||||
beast::MemoryBlock buffer (fileSize);
|
||||
beast::RandomAccessFile f;
|
||||
beast::RandomAccessFile::ByteCount amountRead;
|
||||
std::ifstream datafile (m_file.getFullPathName().toStdString ());
|
||||
std::string line;
|
||||
|
||||
f.open (m_file, beast::RandomAccessFile::readOnly);
|
||||
f.read (buffer.begin(), fileSize, &amountRead);
|
||||
|
||||
if (amountRead == fileSize)
|
||||
{
|
||||
Utilities::ParseResultLine lineFunction (results, journal);
|
||||
Utilities::processLines (buffer.begin(), buffer.end(), lineFunction);
|
||||
}
|
||||
}
|
||||
else
|
||||
if (datafile.is_open ())
|
||||
{
|
||||
// too big!
|
||||
while (std::getline(datafile, line))
|
||||
Utilities::parseResultLine (results, line, journal);
|
||||
}
|
||||
}
|
||||
else
|
||||
|
||||
Reference in New Issue
Block a user