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");
155 byte =
mData[offset];
182 "xrpl::Serializer::addVL : size matches expected");
214 bytes[0] =
static_cast<unsigned char>(length);
217 else if (length <= 12480)
220 bytes[0] = 193 +
static_cast<unsigned char>(length >> 8);
221 bytes[1] =
static_cast<unsigned char>(length & 0xff);
224 else if (length <= 918744)
227 bytes[0] = 241 +
static_cast<unsigned char>(length >> 16);
228 bytes[1] =
static_cast<unsigned char>((length >> 8) & 0xff);
229 bytes[2] =
static_cast<unsigned char>(length & 0xff);
233 Throw<std::overflow_error>(
"lenlen");
235 return addRaw(&bytes[0], numBytes);
242 Throw<std::overflow_error>(
"len<0");
250 if (length <= 918744)
253 Throw<std::overflow_error>(
"len>918744");
261 Throw<std::overflow_error>(
"b1<0");
272 Throw<std::overflow_error>(
"b1>254");
280 Throw<std::overflow_error>(
"b1<0");
283 Throw<std::overflow_error>(
"b1>254");
292 Throw<std::overflow_error>(
"b1<193");
295 Throw<std::overflow_error>(
"b1>240");
297 return 193 + (b1 - 193) * 256 + b2;
304 Throw<std::overflow_error>(
"b1<241");
307 Throw<std::overflow_error>(
"b1>254");
309 return 12481 + (b1 - 241) * 65536 + b2 * 256 + b3;
315 : p_(
reinterpret_cast<std::uint8_t const*
>(data)), remain_(size)
331 Throw<std::runtime_error>(
"invalid SerialIter skip");
341 Throw<std::runtime_error>(
"invalid SerialIter get8");
342 unsigned char t = *
p_;
353 Throw<std::runtime_error>(
"invalid SerialIter get16");
365 Throw<std::runtime_error>(
"invalid SerialIter get32");
378 Throw<std::runtime_error>(
"invalid SerialIter get64");
392 Throw<std::runtime_error>(
"invalid SerialIter geti32");
397 return boost::endian::load_big_s32(t);
404 Throw<std::runtime_error>(
"invalid SerialIter geti64");
409 return boost::endian::load_big_s64(t);
424 Throw<std::runtime_error>(
"gFID: uncommon type out of range " +
std::to_string(type));
432 Throw<std::runtime_error>(
"gFID: uncommon name out of range " +
std::to_string(name));
443 Throw<std::runtime_error>(
"invalid SerialIter getRaw");
462 return getRawHelper<Blob>(size);
475 else if (lenLen == 2)
482 XRPL_ASSERT(lenLen == 3,
"xrpl::SerialIter::getVLDataLength : lenLen is 3");
494 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
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)