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>
40 return add32(safe_cast<std::uint32_t>(p));
111 (type > 0) && (type < 256) && (name > 0) && (name < 256),
112 "ripple::Serializer::addFieldID : inputs inside range");
156 byte =
mData[offset];
184 "ripple::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);
235 Throw<std::overflow_error>(
"lenlen");
237 return addRaw(&bytes[0], numBytes);
244 Throw<std::overflow_error>(
"len<0");
252 if (length <= 918744)
255 Throw<std::overflow_error>(
"len>918744");
263 Throw<std::overflow_error>(
"b1<0");
274 Throw<std::overflow_error>(
"b1>254");
282 Throw<std::overflow_error>(
"b1<0");
285 Throw<std::overflow_error>(
"b1>254");
294 Throw<std::overflow_error>(
"b1<193");
297 Throw<std::overflow_error>(
"b1>240");
299 return 193 + (b1 - 193) * 256 + b2;
306 Throw<std::overflow_error>(
"b1<241");
309 Throw<std::overflow_error>(
"b1>254");
311 return 12481 + (b1 - 241) * 65536 + b2 * 256 + b3;
317 : p_(
reinterpret_cast<std::uint8_t const*
>(data)), remain_(size)
333 Throw<std::runtime_error>(
"invalid SerialIter skip");
343 Throw<std::runtime_error>(
"invalid SerialIter get8");
344 unsigned char t = *
p_;
355 Throw<std::runtime_error>(
"invalid SerialIter get16");
367 Throw<std::runtime_error>(
"invalid SerialIter get32");
380 Throw<std::runtime_error>(
"invalid SerialIter get64");
395 Throw<std::runtime_error>(
"invalid SerialIter geti32");
400 return boost::endian::load_big_s32(t);
407 Throw<std::runtime_error>(
"invalid SerialIter geti64");
412 return boost::endian::load_big_s64(t);
427 Throw<std::runtime_error>(
436 Throw<std::runtime_error>(
449 Throw<std::runtime_error>(
"invalid SerialIter getRaw");
468 return getRawHelper<Blob>(size);
481 else if (lenLen == 2)
489 lenLen == 3,
"ripple::SerialIter::getVLDataLength : lenLen is 3");
501 Throw<std::runtime_error>(
"invalid SerialIter getSlice");
Like std::vector<char> but better.
SerialIter(void const *data, std::size_t size) noexcept
Slice getSlice(std::size_t bytes)
void getFieldID(int &type, int &name)
int addFieldID(int type, int name)
Slice slice() const noexcept
bool get8(int &, int offset) const
uint256 getSHA512Half() const
static int encodeLengthLength(int length)
int addEncoded(int length)
int addRaw(Blob const &vector)
int addVL(Blob const &vector)
static int decodeLengthLength(int b1)
int add16(std::uint16_t i)
int add8(unsigned char i)
static int decodeVLLength(int b1)
An immutable linear range of bytes.
const_iterator begin() const noexcept
const_iterator end() 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.
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
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)
HashPrefix
Prefix for hashing functions.
sha512_half_hasher::result_type sha512Half(Args const &... args)
Returns the SHA512-Half of a series of objects.