1#include <xrpl/basics/Buffer.h>
2#include <xrpl/basics/Slice.h>
3#include <xrpl/basics/base_uint.h>
4#include <xrpl/basics/contract.h>
5#include <xrpl/basics/safe_cast.h>
6#include <xrpl/beast/utility/instrumentation.h>
7#include <xrpl/protocol/HashPrefix.h>
8#include <xrpl/protocol/Serializer.h>
9#include <xrpl/protocol/digest.h>
11#include <boost/endian/conversion.hpp>
39 return add32(safe_cast<std::uint32_t>(p));
110 (type > 0) && (type < 256) && (name > 0) && (name < 256),
111 "xrpl::Serializer::addFieldID : inputs inside range");
157 byte =
mData[offset];
184 "xrpl::Serializer::addVL : size matches expected");
216 bytes[0] =
static_cast<unsigned char>(length);
219 else if (length <= 12480)
222 bytes[0] = 193 +
static_cast<unsigned char>(length >> 8);
223 bytes[1] =
static_cast<unsigned char>(length & 0xff);
226 else if (length <= 918744)
229 bytes[0] = 241 +
static_cast<unsigned char>(length >> 16);
230 bytes[1] =
static_cast<unsigned char>((length >> 8) & 0xff);
231 bytes[2] =
static_cast<unsigned char>(length & 0xff);
236 Throw<std::overflow_error>(
"lenlen");
239 return addRaw(&bytes[0], numBytes);
246 Throw<std::overflow_error>(
"len<0");
254 if (length <= 918744)
257 Throw<std::overflow_error>(
"len>918744");
265 Throw<std::overflow_error>(
"b1<0");
276 Throw<std::overflow_error>(
"b1>254");
284 Throw<std::overflow_error>(
"b1<0");
287 Throw<std::overflow_error>(
"b1>254");
296 Throw<std::overflow_error>(
"b1<193");
299 Throw<std::overflow_error>(
"b1>240");
301 return 193 + ((b1 - 193) * 256) + b2;
308 Throw<std::overflow_error>(
"b1<241");
311 Throw<std::overflow_error>(
"b1>254");
313 return 12481 + ((b1 - 241) * 65536) + (b2 * 256) + b3;
319 : p_(
reinterpret_cast<std::uint8_t const*
>(data)), remain_(size)
335 Throw<std::runtime_error>(
"invalid SerialIter skip");
345 Throw<std::runtime_error>(
"invalid SerialIter get8");
346 unsigned char const t = *
p_;
357 Throw<std::runtime_error>(
"invalid SerialIter get16");
369 Throw<std::runtime_error>(
"invalid SerialIter get32");
382 Throw<std::runtime_error>(
"invalid SerialIter get64");
396 Throw<std::runtime_error>(
"invalid SerialIter geti32");
401 return boost::endian::load_big_s32(t);
408 Throw<std::runtime_error>(
"invalid SerialIter geti64");
413 return boost::endian::load_big_s64(t);
428 Throw<std::runtime_error>(
"gFID: uncommon type out of range " +
std::to_string(type));
436 Throw<std::runtime_error>(
"gFID: uncommon name out of range " +
std::to_string(name));
447 Throw<std::runtime_error>(
"invalid SerialIter getRaw");
466 return getRawHelper<Blob>(size);
472 int const b1 =
get8();
479 else if (lenLen == 2)
481 int const b2 =
get8();
486 XRPL_ASSERT(lenLen == 3,
"xrpl::SerialIter::getVLDataLength : lenLen is 3");
487 int const b2 =
get8();
488 int const b3 =
get8();
498 Throw<std::runtime_error>(
"invalid SerialIter getSlice");
Like std::vector<char> but better.
Slice getSlice(std::size_t bytes)
void getFieldID(int &type, int &name)
SerialIter(void const *data, std::size_t size) noexcept
int addFieldID(int type, int name)
static int decodeVLLength(int b1)
int add16(std::uint16_t i)
uint256 getSHA512Half() const
int addVL(Blob const &vector)
static int decodeLengthLength(int b1)
int addEncoded(int length)
int addRaw(Blob const &vector)
Slice slice() const noexcept
int add8(unsigned char i)
bool get8(int &, int offset) const
static int encodeLengthLength(int length)
An immutable linear range of bytes.
const_iterator begin() const noexcept
bool empty() const noexcept
Return true if the byte range is empty.
std::uint8_t const * data() const noexcept
Return a pointer to beginning of the storage.
std::size_t size() const noexcept
Returns the number of bytes in the storage.
const_iterator end() const noexcept
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
sha512_half_hasher::result_type sha512Half(Args const &... args)
Returns the SHA512-Half of a series of objects.
HashPrefix
Prefix for hashing functions.
std::enable_if_t< std::is_same< T, char >::value||std::is_same< T, unsigned char >::value, Slice > makeSlice(std::array< T, N > const &a)