mirror of
https://github.com/XRPLF/rippled.git
synced 2025-12-06 17:27:55 +00:00
Use Boost.Endian instead of custom wrappers
This commit is contained in:
committed by
Nik Bougalis
parent
11ab98cced
commit
3aaf6d7857
@@ -1,77 +0,0 @@
|
||||
//------------------------------------------------------------------------------
|
||||
/*
|
||||
This file is part of rippled: https://github.com/ripple/rippled
|
||||
Copyright (c) 2012, 2013 Ripple Labs Inc.
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
purpose with or without fee is hereby granted, provided that the above
|
||||
copyright notice and this permission notice appear in all copies.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
//==============================================================================
|
||||
|
||||
#ifndef RIPPLE_BASICS_BYTEORDER_H_INCLUDED
|
||||
#define RIPPLE_BASICS_BYTEORDER_H_INCLUDED
|
||||
|
||||
#include <ripple/beast/core/Config.h>
|
||||
|
||||
// For ByteOrder
|
||||
#if BEAST_WIN32
|
||||
// (nothing)
|
||||
#elif __APPLE__
|
||||
#include <libkern/OSByteOrder.h>
|
||||
#elif defined(__FreeBSD__) || defined(__NetBSD__)
|
||||
#include <sys/endian.h>
|
||||
#elif defined(__OpenBSD__)
|
||||
#include <sys/types.h>
|
||||
#endif
|
||||
#include <cstdint>
|
||||
|
||||
namespace ripple {
|
||||
|
||||
// VFALCO These are all deprecated please use the ones in <ripple/beast/core/ByteOrder.h>
|
||||
// Routines for converting endianness
|
||||
|
||||
// Reference: http://www.mail-archive.com/licq-commits@googlegroups.com/msg02334.html
|
||||
|
||||
#ifdef _MSC_VER
|
||||
extern std::uint64_t htobe64 (uint64_t value);
|
||||
extern std::uint64_t be64toh (uint64_t value);
|
||||
extern std::uint32_t htobe32 (uint32_t value);
|
||||
extern std::uint32_t be32toh (uint32_t value);
|
||||
|
||||
#elif __APPLE__
|
||||
#define htobe16(x) OSSwapHostToBigInt16(x)
|
||||
#define htole16(x) OSSwapHostToLittleInt16(x)
|
||||
#define be16toh(x) OSSwapBigToHostInt16(x)
|
||||
#define le16toh(x) OSSwapLittleToHostInt16(x)
|
||||
|
||||
#define htobe32(x) OSSwapHostToBigInt32(x)
|
||||
#define htole32(x) OSSwapHostToLittleInt32(x)
|
||||
#define be32toh(x) OSSwapBigToHostInt32(x)
|
||||
#define le32toh(x) OSSwapLittleToHostInt32(x)
|
||||
|
||||
#define htobe64(x) OSSwapHostToBigInt64(x)
|
||||
#define htole64(x) OSSwapHostToLittleInt64(x)
|
||||
#define be64toh(x) OSSwapBigToHostInt64(x)
|
||||
#define le64toh(x) OSSwapLittleToHostInt64(x)
|
||||
|
||||
#elif defined(__FreeBSD__) || defined(__NetBSD__)
|
||||
|
||||
#elif defined(__OpenBSD__)
|
||||
#define be16toh(x) betoh16(x)
|
||||
#define be32toh(x) betoh32(x)
|
||||
#define be64toh(x) betoh64(x)
|
||||
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -20,9 +20,9 @@
|
||||
#ifndef RIPPLE_BASICS_STRINGUTILITIES_H_INCLUDED
|
||||
#define RIPPLE_BASICS_STRINGUTILITIES_H_INCLUDED
|
||||
|
||||
#include <ripple/basics/ByteOrder.h>
|
||||
#include <ripple/basics/Blob.h>
|
||||
#include <ripple/basics/strHex.h>
|
||||
#include <boost/endian/conversion.hpp>
|
||||
#include <boost/format.hpp>
|
||||
#include <boost/optional.hpp>
|
||||
#include <sstream>
|
||||
@@ -43,7 +43,7 @@ inline std::string strHex (Blob const& vucData)
|
||||
|
||||
inline std::string strHex (const std::uint64_t uiHost)
|
||||
{
|
||||
uint64_t uBig = htobe64 (uiHost);
|
||||
uint64_t uBig = boost::endian::native_to_big (uiHost);
|
||||
|
||||
return strHex ((unsigned char*) &uBig, sizeof (uBig));
|
||||
}
|
||||
|
||||
@@ -25,11 +25,11 @@
|
||||
#ifndef RIPPLE_BASICS_BASE_UINT_H_INCLUDED
|
||||
#define RIPPLE_BASICS_BASE_UINT_H_INCLUDED
|
||||
|
||||
#include <ripple/basics/ByteOrder.h>
|
||||
#include <ripple/basics/Blob.h>
|
||||
#include <ripple/basics/strHex.h>
|
||||
#include <ripple/basics/hardened_hash.h>
|
||||
#include <ripple/beast/utility/Zero.h>
|
||||
#include <boost/endian/conversion.hpp>
|
||||
#include <boost/functional/hash.hpp>
|
||||
#include <array>
|
||||
#include <functional>
|
||||
@@ -85,6 +85,7 @@ public:
|
||||
pointer data() { return reinterpret_cast<pointer>(pn.data ()); }
|
||||
const_pointer data() const { return reinterpret_cast<const_pointer>(pn.data ()); }
|
||||
|
||||
|
||||
iterator begin() { return data(); }
|
||||
iterator end() { return data()+bytes; }
|
||||
const_iterator begin() const { return data(); }
|
||||
@@ -97,18 +98,6 @@ public:
|
||||
*/
|
||||
using hasher = hardened_hash <>;
|
||||
|
||||
/** Container equality testing function. */
|
||||
class key_equal
|
||||
{
|
||||
public:
|
||||
explicit key_equal() = default;
|
||||
|
||||
bool operator() (base_uint const& lhs, base_uint const& rhs) const
|
||||
{
|
||||
return lhs == rhs;
|
||||
}
|
||||
};
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
|
||||
private:
|
||||
@@ -203,7 +192,7 @@ public:
|
||||
std::uint64_t ul;
|
||||
};
|
||||
// Put in least significant bits.
|
||||
ul = htobe64 (uHost);
|
||||
ul = boost::endian::native_to_big(uHost);
|
||||
pn[WIDTH-2] = u[0];
|
||||
pn[WIDTH-1] = u[1];
|
||||
return *this;
|
||||
@@ -233,17 +222,12 @@ public:
|
||||
return *this;
|
||||
}
|
||||
|
||||
// be32toh and htobe32 are macros that somehow cause shadowing
|
||||
// warnings in this header file, so we hide them...
|
||||
static uint32_t bigendToHost (uint32_t x) { return be32toh(x); }
|
||||
static uint32_t hostToBigend (uint32_t x) { return htobe32(x); }
|
||||
|
||||
base_uint& operator++ ()
|
||||
{
|
||||
// prefix operator
|
||||
for (int i = WIDTH - 1; i >= 0; --i)
|
||||
{
|
||||
pn[i] = hostToBigend (bigendToHost (pn[i]) + 1);
|
||||
pn[i] = boost::endian::native_to_big (boost::endian::big_to_native(pn[i]) + 1);
|
||||
|
||||
if (pn[i] != 0)
|
||||
break;
|
||||
@@ -266,7 +250,7 @@ public:
|
||||
for (int i = WIDTH - 1; i >= 0; --i)
|
||||
{
|
||||
auto prev = pn[i];
|
||||
pn[i] = hostToBigend (bigendToHost (pn[i]) - 1);
|
||||
pn[i] = boost::endian::native_to_big (boost::endian::big_to_native(pn[i]) - 1);
|
||||
|
||||
if (prev != 0)
|
||||
break;
|
||||
@@ -290,10 +274,10 @@ public:
|
||||
|
||||
for (int i = WIDTH; i--;)
|
||||
{
|
||||
std::uint64_t n = carry + bigendToHost (pn[i]) +
|
||||
bigendToHost (b.pn[i]);
|
||||
std::uint64_t n = carry + boost::endian::big_to_native(pn[i]) +
|
||||
boost::endian::big_to_native(b.pn[i]);
|
||||
|
||||
pn[i] = hostToBigend (n & 0xffffffff);
|
||||
pn[i] = boost::endian::native_to_big (static_cast<std::uint32_t>(n));
|
||||
carry = n >> 32;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user