mirror of
https://github.com/Xahau/xahaud.git
synced 2025-12-06 17:27:52 +00:00
Use Boost.Endian instead of custom wrappers
This commit is contained in:
committed by
Nik Bougalis
parent
11ab98cced
commit
3aaf6d7857
@@ -41,7 +41,7 @@
|
||||
#include <ripple/beast/utility/PropertyStream.h>
|
||||
#include <mutex>
|
||||
|
||||
#include "ripple.pb.h"
|
||||
#include <ripple/protocol/messages.h>
|
||||
|
||||
namespace ripple {
|
||||
|
||||
|
||||
@@ -32,7 +32,7 @@
|
||||
#include <deque>
|
||||
#include <tuple>
|
||||
|
||||
#include "ripple.pb.h"
|
||||
#include <ripple/protocol/messages.h>
|
||||
|
||||
namespace ripple {
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,306 +0,0 @@
|
||||
//------------------------------------------------------------------------------
|
||||
/*
|
||||
This file is part of Beast: https://github.com/vinniefalco/Beast
|
||||
Copyright 2013, Vinnie Falco <vinnie.falco@gmail.com>
|
||||
|
||||
Portions of this file are from JUCE.
|
||||
Copyright (c) 2013 - Raw Material Software Ltd.
|
||||
Please visit http://www.juce.com
|
||||
|
||||
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 BEAST_BYTEORDER_H_INCLUDED
|
||||
#define BEAST_BYTEORDER_H_INCLUDED
|
||||
|
||||
#include <ripple/beast/core/Config.h>
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
namespace beast {
|
||||
|
||||
//==============================================================================
|
||||
/** Contains static methods for converting the byte order between different
|
||||
endiannesses.
|
||||
*/
|
||||
class ByteOrder
|
||||
{
|
||||
public:
|
||||
//==============================================================================
|
||||
/** Swaps the upper and lower bytes of a 16-bit integer. */
|
||||
static std::uint16_t swap (std::uint16_t value);
|
||||
|
||||
/** Reverses the order of the 4 bytes in a 32-bit integer. */
|
||||
static std::uint32_t swap (std::uint32_t value);
|
||||
|
||||
/** Reverses the order of the 8 bytes in a 64-bit integer. */
|
||||
static std::uint64_t swap (std::uint64_t value);
|
||||
|
||||
//==============================================================================
|
||||
/** Swaps the byte order of a 16-bit int if the CPU is big-endian */
|
||||
static std::uint16_t swapIfBigEndian (std::uint16_t value);
|
||||
|
||||
/** Swaps the byte order of a 32-bit int if the CPU is big-endian */
|
||||
static std::uint32_t swapIfBigEndian (std::uint32_t value);
|
||||
|
||||
/** Swaps the byte order of a 64-bit int if the CPU is big-endian */
|
||||
static std::uint64_t swapIfBigEndian (std::uint64_t value);
|
||||
|
||||
/** Swaps the byte order of a 16-bit int if the CPU is little-endian */
|
||||
static std::uint16_t swapIfLittleEndian (std::uint16_t value);
|
||||
|
||||
/** Swaps the byte order of a 32-bit int if the CPU is little-endian */
|
||||
static std::uint32_t swapIfLittleEndian (std::uint32_t value);
|
||||
|
||||
/** Swaps the byte order of a 64-bit int if the CPU is little-endian */
|
||||
static std::uint64_t swapIfLittleEndian (std::uint64_t value);
|
||||
|
||||
//==============================================================================
|
||||
/** Turns 2 bytes into a little-endian integer. */
|
||||
static std::uint16_t littleEndianShort (const void* bytes);
|
||||
|
||||
/** Turns 4 bytes into a little-endian integer. */
|
||||
static std::uint32_t littleEndianInt (const void* bytes);
|
||||
|
||||
/** Turns 4 bytes into a little-endian integer. */
|
||||
static std::uint64_t littleEndianInt64 (const void* bytes);
|
||||
|
||||
/** Turns 2 bytes into a big-endian integer. */
|
||||
static std::uint16_t bigEndianShort (const void* bytes);
|
||||
|
||||
/** Turns 4 bytes into a big-endian integer. */
|
||||
static std::uint32_t bigEndianInt (const void* bytes);
|
||||
|
||||
/** Turns 4 bytes into a big-endian integer. */
|
||||
static std::uint64_t bigEndianInt64 (const void* bytes);
|
||||
|
||||
//==============================================================================
|
||||
/** Converts 3 little-endian bytes into a signed 24-bit value (which is sign-extended to 32 bits). */
|
||||
static int littleEndian24Bit (const char* bytes);
|
||||
|
||||
/** Converts 3 big-endian bytes into a signed 24-bit value (which is sign-extended to 32 bits). */
|
||||
static int bigEndian24Bit (const char* bytes);
|
||||
|
||||
/** Copies a 24-bit number to 3 little-endian bytes. */
|
||||
static void littleEndian24BitToChars (int value, char* destBytes);
|
||||
|
||||
/** Copies a 24-bit number to 3 big-endian bytes. */
|
||||
static void bigEndian24BitToChars (int value, char* destBytes);
|
||||
|
||||
//==============================================================================
|
||||
/** Returns true if the current CPU is big-endian. */
|
||||
static bool isBigEndian();
|
||||
|
||||
private:
|
||||
ByteOrder();
|
||||
ByteOrder(ByteOrder const&) = delete;
|
||||
ByteOrder& operator= (ByteOrder const&) = delete;
|
||||
};
|
||||
|
||||
//==============================================================================
|
||||
#if BEAST_USE_INTRINSICS && ! defined (__INTEL_COMPILER)
|
||||
#pragma intrinsic (_byteswap_ulong)
|
||||
#endif
|
||||
|
||||
inline std::uint16_t ByteOrder::swap (std::uint16_t n)
|
||||
{
|
||||
#if BEAST_USE_INTRINSICSxxx // agh - the MS compiler has an internal error when you try to use this intrinsic!
|
||||
return static_cast <std::uint16_t> (_byteswap_ushort (n));
|
||||
#else
|
||||
return static_cast <std::uint16_t> ((n << 8) | (n >> 8));
|
||||
#endif
|
||||
}
|
||||
|
||||
inline std::uint32_t ByteOrder::swap (std::uint32_t n)
|
||||
{
|
||||
#if BEAST_MAC || BEAST_IOS
|
||||
return OSSwapInt32 (n);
|
||||
#elif BEAST_GCC && BEAST_INTEL && ! BEAST_NO_INLINE_ASM
|
||||
asm("bswap %%eax" : "=a"(n) : "a"(n));
|
||||
return n;
|
||||
#elif BEAST_USE_INTRINSICS
|
||||
return _byteswap_ulong (n);
|
||||
#elif BEAST_MSVC && ! BEAST_NO_INLINE_ASM
|
||||
__asm {
|
||||
mov eax, n
|
||||
bswap eax
|
||||
mov n, eax
|
||||
}
|
||||
return n;
|
||||
#elif BEAST_ANDROID
|
||||
return bswap_32 (n);
|
||||
#else
|
||||
return (n << 24) | (n >> 24) | ((n & 0xff00) << 8) | ((n & 0xff0000) >> 8);
|
||||
#endif
|
||||
}
|
||||
|
||||
inline std::uint64_t ByteOrder::swap (std::uint64_t value)
|
||||
{
|
||||
#if BEAST_MAC || BEAST_IOS
|
||||
return OSSwapInt64 (value);
|
||||
#elif BEAST_USE_INTRINSICS
|
||||
return _byteswap_uint64 (value);
|
||||
#else
|
||||
return (((std::int64_t) swap ((std::uint32_t) value)) << 32) | swap ((std::uint32_t) (value >> 32));
|
||||
#endif
|
||||
}
|
||||
|
||||
#if BEAST_LITTLE_ENDIAN
|
||||
inline std::uint16_t ByteOrder::swapIfBigEndian (const std::uint16_t v) { return v; }
|
||||
inline std::uint32_t ByteOrder::swapIfBigEndian (const std::uint32_t v) { return v; }
|
||||
inline std::uint64_t ByteOrder::swapIfBigEndian (const std::uint64_t v) { return v; }
|
||||
inline std::uint16_t ByteOrder::swapIfLittleEndian (const std::uint16_t v) { return swap (v); }
|
||||
inline std::uint32_t ByteOrder::swapIfLittleEndian (const std::uint32_t v) { return swap (v); }
|
||||
inline std::uint64_t ByteOrder::swapIfLittleEndian (const std::uint64_t v) { return swap (v); }
|
||||
inline std::uint16_t ByteOrder::littleEndianShort (const void* const bytes) { return *static_cast <const std::uint16_t*> (bytes); }
|
||||
inline std::uint32_t ByteOrder::littleEndianInt (const void* const bytes) { return *static_cast <const std::uint32_t*> (bytes); }
|
||||
inline std::uint64_t ByteOrder::littleEndianInt64 (const void* const bytes) { return *static_cast <const std::uint64_t*> (bytes); }
|
||||
inline std::uint16_t ByteOrder::bigEndianShort (const void* const bytes) { return swap (*static_cast <const std::uint16_t*> (bytes)); }
|
||||
inline std::uint32_t ByteOrder::bigEndianInt (const void* const bytes) { return swap (*static_cast <const std::uint32_t*> (bytes)); }
|
||||
inline std::uint64_t ByteOrder::bigEndianInt64 (const void* const bytes) { return swap (*static_cast <const std::uint64_t*> (bytes)); }
|
||||
inline bool ByteOrder::isBigEndian() { return false; }
|
||||
#else
|
||||
inline std::uint16_t ByteOrder::swapIfBigEndian (const std::uint16_t v) { return swap (v); }
|
||||
inline std::uint32_t ByteOrder::swapIfBigEndian (const std::uint32_t v) { return swap (v); }
|
||||
inline std::uint64_t ByteOrder::swapIfBigEndian (const std::uint64_t v) { return swap (v); }
|
||||
inline std::uint16_t ByteOrder::swapIfLittleEndian (const std::uint16_t v) { return v; }
|
||||
inline std::uint32_t ByteOrder::swapIfLittleEndian (const std::uint32_t v) { return v; }
|
||||
inline std::uint64_t ByteOrder::swapIfLittleEndian (const std::uint64_t v) { return v; }
|
||||
inline std::uint32_t ByteOrder::littleEndianInt (const void* const bytes) { return swap (*static_cast <const std::uint32_t*> (bytes)); }
|
||||
inline std::uint16_t ByteOrder::littleEndianShort (const void* const bytes) { return swap (*static_cast <const std::uint16_t*> (bytes)); }
|
||||
inline std::uint16_t ByteOrder::bigEndianShort (const void* const bytes) { return *static_cast <const std::uint16_t*> (bytes); }
|
||||
inline std::uint32_t ByteOrder::bigEndianInt (const void* const bytes) { return *static_cast <const std::uint32_t*> (bytes); }
|
||||
inline std::uint64_t ByteOrder::bigEndianInt64 (const void* const bytes) { return *static_cast <const std::uint64_t*> (bytes); }
|
||||
inline bool ByteOrder::isBigEndian() { return true; }
|
||||
#endif
|
||||
|
||||
inline int ByteOrder::littleEndian24Bit (const char* const bytes) { return (((int) bytes[2]) << 16) | (((int) (std::uint8_t) bytes[1]) << 8) | ((int) (std::uint8_t) bytes[0]); }
|
||||
inline int ByteOrder::bigEndian24Bit (const char* const bytes) { return (((int) bytes[0]) << 16) | (((int) (std::uint8_t) bytes[1]) << 8) | ((int) (std::uint8_t) bytes[2]); }
|
||||
inline void ByteOrder::littleEndian24BitToChars (const int value, char* const destBytes) { destBytes[0] = (char)(value & 0xff); destBytes[1] = (char)((value >> 8) & 0xff); destBytes[2] = (char)((value >> 16) & 0xff); }
|
||||
inline void ByteOrder::bigEndian24BitToChars (const int value, char* const destBytes) { destBytes[0] = (char)((value >> 16) & 0xff); destBytes[1] = (char)((value >> 8) & 0xff); destBytes[2] = (char)(value & 0xff); }
|
||||
|
||||
namespace detail
|
||||
{
|
||||
|
||||
/** Specialized helper class template for swapping bytes.
|
||||
|
||||
Normally you won't use this directly, use the helper function
|
||||
byteSwap instead. You can specialize this class for your
|
||||
own user defined types, as was done for uint24.
|
||||
|
||||
@see swapBytes, uint24
|
||||
*/
|
||||
template <typename IntegralType>
|
||||
struct SwapBytes
|
||||
{
|
||||
explicit SwapBytes() = default;
|
||||
|
||||
inline IntegralType operator() (IntegralType value) const noexcept
|
||||
{
|
||||
return ByteOrder::swap (value);
|
||||
}
|
||||
};
|
||||
|
||||
// Specializations for signed integers
|
||||
|
||||
template <>
|
||||
struct SwapBytes <std::int16_t>
|
||||
{
|
||||
explicit SwapBytes() = default;
|
||||
|
||||
inline std::int16_t operator() (std::int16_t value) const noexcept
|
||||
{
|
||||
return static_cast <std::int16_t> (ByteOrder::swap (static_cast <std::uint16_t> (value)));
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct SwapBytes <std::int32_t>
|
||||
{
|
||||
explicit SwapBytes() = default;
|
||||
|
||||
inline std::int32_t operator() (std::int32_t value) const noexcept
|
||||
{
|
||||
return static_cast <std::int32_t> (ByteOrder::swap (static_cast <std::uint32_t> (value)));
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct SwapBytes <std::int64_t>
|
||||
{
|
||||
explicit SwapBytes() = default;
|
||||
|
||||
inline std::int64_t operator() (std::int64_t value) const noexcept
|
||||
{
|
||||
return static_cast <std::int64_t> (ByteOrder::swap (static_cast <std::uint64_t> (value)));
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
/** Returns a type with the bytes swapped.
|
||||
Little endian becomes big endian and vice versa. The underlying
|
||||
type must be an integral type or behave like one.
|
||||
*/
|
||||
template <class IntegralType>
|
||||
inline IntegralType swapBytes (IntegralType value) noexcept
|
||||
{
|
||||
return detail::SwapBytes <IntegralType> () (value);
|
||||
}
|
||||
|
||||
/** Returns the machine byte-order value to little-endian byte order. */
|
||||
template <typename IntegralType>
|
||||
inline IntegralType toLittleEndian (IntegralType value) noexcept
|
||||
{
|
||||
#if BEAST_LITTLE_ENDIAN
|
||||
return value;
|
||||
#else
|
||||
return swapBytes (value);
|
||||
#endif
|
||||
}
|
||||
|
||||
/** Returns the machine byte-order value to big-endian byte order. */
|
||||
template <typename IntegralType>
|
||||
inline IntegralType toBigEndian (IntegralType value) noexcept
|
||||
{
|
||||
#if BEAST_LITTLE_ENDIAN
|
||||
return swapBytes (value);
|
||||
#else
|
||||
return value;
|
||||
#endif
|
||||
}
|
||||
|
||||
/** Returns the machine byte-order value to network byte order. */
|
||||
template <typename IntegralType>
|
||||
inline IntegralType toNetworkByteOrder (IntegralType value) noexcept
|
||||
{
|
||||
return toBigEndian (value);
|
||||
}
|
||||
|
||||
/** Converts from network byte order to machine byte order. */
|
||||
template <typename IntegralType>
|
||||
inline IntegralType fromNetworkByteOrder (IntegralType value) noexcept
|
||||
{
|
||||
#if BEAST_LITTLE_ENDIAN
|
||||
return swapBytes (value);
|
||||
#else
|
||||
return value;
|
||||
#endif
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -41,9 +41,6 @@
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
// New header-only library modeled more closely according to boost
|
||||
#include <ripple/beast/core/ByteOrder.h>
|
||||
|
||||
#include <ripple/beast/core/StandardIncludes.h>
|
||||
|
||||
// Order matters, since headers don't have their own #include lines.
|
||||
|
||||
@@ -18,7 +18,6 @@
|
||||
//==============================================================================
|
||||
|
||||
#include <ripple/nodestore/impl/DecodedBlob.h>
|
||||
#include <ripple/beast/core/ByteOrder.h>
|
||||
#include <algorithm>
|
||||
#include <cassert>
|
||||
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
#ifndef RIPPLE_OVERLAY_MESSAGE_H_INCLUDED
|
||||
#define RIPPLE_OVERLAY_MESSAGE_H_INCLUDED
|
||||
|
||||
#include "ripple.pb.h"
|
||||
#include <ripple/protocol/messages.h>
|
||||
#include <boost/asio/buffer.hpp>
|
||||
#include <boost/asio/buffers_iterator.hpp>
|
||||
#include <algorithm>
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
#ifndef RIPPLE_OVERLAY_CONNECTATTEMPT_H_INCLUDED
|
||||
#define RIPPLE_OVERLAY_CONNECTATTEMPT_H_INCLUDED
|
||||
|
||||
#include "ripple.pb.h"
|
||||
#include <ripple/protocol/messages.h>
|
||||
#include <ripple/overlay/impl/OverlayImpl.h>
|
||||
#include <ripple/overlay/impl/Tuning.h>
|
||||
|
||||
|
||||
@@ -22,7 +22,6 @@
|
||||
|
||||
#include <ripple/app/consensus/RCLCxPeerPos.h>
|
||||
#include <ripple/basics/Log.h>
|
||||
#include <ripple/beast/core/ByteOrder.h>
|
||||
#include <ripple/beast/utility/WrappedSink.h>
|
||||
#include <ripple/basics/RangeSet.h>
|
||||
#include <ripple/overlay/impl/ProtocolMessage.h>
|
||||
@@ -32,6 +31,7 @@
|
||||
#include <ripple/protocol/STValidation.h>
|
||||
#include <ripple/resource/Fees.h>
|
||||
|
||||
#include <boost/endian/conversion.hpp>
|
||||
#include <cstdint>
|
||||
#include <deque>
|
||||
#include <queue>
|
||||
@@ -519,8 +519,8 @@ PeerImp::sendEndpoints (FwdIt first, FwdIt last)
|
||||
protocol::TMEndpoint& tme (*tm.add_endpoints());
|
||||
if (ep.address.is_v4())
|
||||
tme.mutable_ipv4()->set_ipv4(
|
||||
beast::toNetworkByteOrder<std::uint32_t> (
|
||||
ep.address.to_v4().to_ulong()));
|
||||
boost::endian::native_to_big(
|
||||
static_cast<std::uint32_t>(ep.address.to_v4().to_ulong())));
|
||||
else
|
||||
tme.mutable_ipv4()->set_ipv4(0);
|
||||
tme.mutable_ipv4()->set_ipv4port (ep.address.port());
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
#ifndef RIPPLE_OVERLAY_PROTOCOLMESSAGE_H_INCLUDED
|
||||
#define RIPPLE_OVERLAY_PROTOCOLMESSAGE_H_INCLUDED
|
||||
|
||||
#include "ripple.pb.h"
|
||||
#include <ripple/protocol/messages.h>
|
||||
#include <ripple/overlay/Message.h>
|
||||
#include <ripple/overlay/impl/ZeroCopyStream.h>
|
||||
#include <boost/asio/buffer.hpp>
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
#ifndef RIPPLE_OVERLAY_TMHELLO_H_INCLUDED
|
||||
#define RIPPLE_OVERLAY_TMHELLO_H_INCLUDED
|
||||
|
||||
#include "ripple.pb.h"
|
||||
#include <ripple/protocol/messages.h>
|
||||
#include <ripple/app/main/Application.h>
|
||||
#include <ripple/beast/utility/Journal.h>
|
||||
#include <ripple/protocol/BuildInfo.h>
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
#ifndef RIPPLE_OVERLAY_TRAFFIC_H_INCLUDED
|
||||
#define RIPPLE_OVERLAY_TRAFFIC_H_INCLUDED
|
||||
|
||||
#include "ripple.pb.h"
|
||||
#include <ripple/protocol/messages.h>
|
||||
|
||||
#include <atomic>
|
||||
#include <map>
|
||||
|
||||
@@ -1,74 +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.
|
||||
*/
|
||||
//==============================================================================
|
||||
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#include <cstdint>
|
||||
#include <Winsock2.h>
|
||||
// <Winsock2.h> defines min, max and does other stupid things
|
||||
# ifdef max
|
||||
# undef max
|
||||
# endif
|
||||
# ifdef min
|
||||
# undef min
|
||||
# endif
|
||||
#endif
|
||||
|
||||
namespace ripple {
|
||||
|
||||
#if _MSC_VER
|
||||
|
||||
// from: http://stackoverflow.com/questions/3022552/is-there-any-standard-htonl-like-function-for-64-bits-integers-in-c
|
||||
// but we don't need to check the endianness
|
||||
std::uint64_t htobe64 (uint64_t value)
|
||||
{
|
||||
// The answer is 42
|
||||
//static const int num = 42;
|
||||
|
||||
// Check the endianness
|
||||
//if (*reinterpret_cast<const char*>(&num) == num)
|
||||
//{
|
||||
const uint32_t high_part = htonl (static_cast<uint32_t> (value >> 32));
|
||||
const uint32_t low_part = htonl (static_cast<uint32_t> (value & 0xFFFFFFFFLL));
|
||||
|
||||
return (static_cast<uint64_t> (low_part) << 32) | high_part;
|
||||
//} else
|
||||
//{
|
||||
// return value;
|
||||
//}
|
||||
}
|
||||
|
||||
std::uint64_t be64toh (uint64_t value)
|
||||
{
|
||||
return (_byteswap_uint64 (value));
|
||||
}
|
||||
|
||||
std::uint32_t htobe32 (uint32_t value)
|
||||
{
|
||||
return (htonl (value));
|
||||
}
|
||||
|
||||
std::uint32_t be32toh (uint32_t value)
|
||||
{
|
||||
return ( _byteswap_ulong (value));
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
}
|
||||
@@ -19,6 +19,7 @@
|
||||
|
||||
#include <ripple/protocol/digest.h>
|
||||
#include <ripple/protocol/Indexes.h>
|
||||
#include <boost/endian/conversion.hpp>
|
||||
#include <cassert>
|
||||
|
||||
namespace ripple {
|
||||
@@ -125,7 +126,7 @@ getQualityIndex (uint256 const& uBase, const std::uint64_t uNodeDir)
|
||||
|
||||
// TODO(tom): there must be a better way.
|
||||
// VFALCO [base_uint] This assumes a certain storage format
|
||||
((std::uint64_t*) uNode.end ())[-1] = htobe64 (uNodeDir);
|
||||
((std::uint64_t*) uNode.end ())[-1] = boost::endian::native_to_big (uNodeDir);
|
||||
|
||||
return uNode;
|
||||
}
|
||||
@@ -142,7 +143,7 @@ std::uint64_t
|
||||
getQuality (uint256 const& uBase)
|
||||
{
|
||||
// VFALCO [base_uint] This assumes a certain storage format
|
||||
return be64toh (((std::uint64_t*) uBase.end ())[-1]);
|
||||
return boost::endian::big_to_native (((std::uint64_t*) uBase.end ())[-1]);
|
||||
}
|
||||
|
||||
uint256
|
||||
|
||||
@@ -22,7 +22,6 @@
|
||||
#include <ripple/protocol/impl/secp256k1.h>
|
||||
#include <ripple/basics/contract.h>
|
||||
#include <ripple/basics/strHex.h>
|
||||
#include <ripple/beast/core/ByteOrder.h>
|
||||
#include <boost/multiprecision/cpp_int.hpp>
|
||||
#include <ed25519-donna/ed25519.h>
|
||||
#include <type_traits>
|
||||
|
||||
37
src/ripple/protocol/messages.h
Normal file
37
src/ripple/protocol/messages.h
Normal file
@@ -0,0 +1,37 @@
|
||||
//------------------------------------------------------------------------------
|
||||
/*
|
||||
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_PROTOCOL_MESSAGES_H_INCLUDED
|
||||
#define RIPPLE_PROTOCOL_MESSAGES_H_INCLUDED
|
||||
|
||||
// Some versions of protobuf generate code that will produce errors during
|
||||
// compilation. See https://github.com/google/protobuf/issues/549 for more
|
||||
// details. We work around this by undefining this macro.
|
||||
//
|
||||
// TODO: Remove this after the protoc we use is upgraded to not generate
|
||||
// code that conflicts with the TYPE_BOOL macro.
|
||||
|
||||
#ifdef TYPE_BOOL
|
||||
#undef TYPE_BOOL
|
||||
#endif
|
||||
|
||||
#include "ripple.pb.h"
|
||||
|
||||
#endif
|
||||
|
||||
@@ -21,7 +21,6 @@
|
||||
#include <ripple/protocol/impl/AccountID.cpp>
|
||||
#include <ripple/protocol/impl/Book.cpp>
|
||||
#include <ripple/protocol/impl/BuildInfo.cpp>
|
||||
#include <ripple/protocol/impl/ByteOrder.cpp>
|
||||
#include <ripple/protocol/impl/digest.cpp>
|
||||
#include <ripple/protocol/impl/ErrorCodes.cpp>
|
||||
#include <ripple/protocol/impl/Feature.cpp>
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
#include <ripple/json/to_string.h>
|
||||
#include <ripple/beast/unit_test.h>
|
||||
#include <ripple/basics/Slice.h>
|
||||
#include "ripple.pb.h"
|
||||
#include <ripple/protocol/messages.h>
|
||||
|
||||
namespace ripple {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user