1#include <xrpl/protocol/Serializer.h>
3#include <xrpl/basics/Buffer.h>
4#include <xrpl/basics/Slice.h>
5#include <xrpl/basics/base_uint.h>
6#include <xrpl/basics/contract.h>
7#include <xrpl/basics/safe_cast.h>
8#include <xrpl/beast/utility/instrumentation.h>
9#include <xrpl/protocol/HashPrefix.h>
10#include <xrpl/protocol/digest.h>
12#include <boost/endian/conversion.hpp>
27 int const ret =
data_.size();
28 data_.push_back(
static_cast<unsigned char>(i >> 8));
29 data_.push_back(
static_cast<unsigned char>(i & 0xff));
77 int const ret =
data_.size();
85 int const ret =
data_.size();
93 int const ret =
data_.size();
101 int const ret =
data_.size();
102 data_.insert(
data_.end(),
static_cast<char const*
>(ptr),
static_cast<char const*
>(ptr) + len);
109 int const ret =
data_.size();
111 (type > 0) && (type < 256) && (name > 0) && (name < 256),
112 "xrpl::Serializer::addFieldID : inputs inside range");
119 data_.push_back(
static_cast<unsigned char>((type << 4) | name));
124 data_.push_back(
static_cast<unsigned char>(type << 4));
125 data_.push_back(
static_cast<unsigned char>(name));
131 data_.push_back(
static_cast<unsigned char>(name));
132 data_.push_back(
static_cast<unsigned char>(type));
137 data_.push_back(
static_cast<unsigned char>(0));
138 data_.push_back(
static_cast<unsigned char>(type));
139 data_.push_back(
static_cast<unsigned char>(name));
148 int const ret =
data_.size();
149 data_.push_back(byteValue);
156 if (offset >=
data_.size())
159 byte =
data_[offset];
166 if (bytes >
data_.size())
186 "xrpl::Serializer::addVL : size matches expected");
224 bytes[0] =
static_cast<std::byte>(length);
260 "encodeLengthLength: length is negative or did not fit in an int");
278 int const firstByteValue = std::to_integer<int>(firstByte);
295 int const length = std::to_integer<int>(firstByte);
307 int const firstByteValue = std::to_integer<int>(firstByte);
319 std::to_integer<int>(secondByte);
325 int const firstByteValue = std::to_integer<int>(firstByte);
336 std::to_integer<int>(thirdByte);
377 unsigned char const t = *
p_;
432 return boost::endian::load_big_s32(t);
444 return boost::endian::load_big_s64(t);
510 else if (lenLen == 2)
517 XRPL_ASSERT(lenLen == 3,
"xrpl::SerialIter::getVLDataLength : lenLen is 3");
Like std::vector<char> but better.
int getVLDataLength()
Reads the length header at the read position and steps past it.
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 decodeLengthLength(std::byte firstByte)
Works out how long a header is, from its first byte.
static constexpr int kMaxValueOfFirstByteFor1ByteHeader
static constexpr int kMaxValueOfFirstByteFor2ByteHeader
static constexpr int kMinValueOfLengthFor2ByteHeader
static constexpr int kMaxValueOfLengthFor1ByteHeader
int add16(std::uint16_t i)
static constexpr int kMinValueOfLengthFor1ByteHeader
A 1 byte header holds the length in the byte itself, so both ends of this range are the same numbers ...
static constexpr int kMaxValueOfLengthFor3ByteHeader
The largest length the encoder will write.
static constexpr int kMaxValueOfLengthFor2ByteHeader
48 values of the first byte mean a 2 byte header, and each of them covers 256 lengths.
static constexpr int kNumberOfValuesInOneByte
UInt256 getSHA512Half() const
int addVL(Blob const &vector)
int add8(unsigned char byteValue)
static constexpr int kMinValueOfFirstByteFor2ByteHeader
int addEncoded(int length)
Appends the length header for a field of the given length.
int addRaw(Blob const &vector)
Slice slice() const noexcept
static constexpr int kNumberOfValuesInTwoBytes
static int decodeVLLength(std::byte firstByte)
Reads the field length out of a 1 byte header.
static constexpr int kMaxValueOfFirstByteFor3ByteHeader
bool get8(int &, int offset) const
static int encodeLengthLength(int length)
Works out how many bytes the header needs for the given length.
static constexpr int kMinValueOfFirstByteFor3ByteHeader
static constexpr int kMinValueOfLengthFor3ByteHeader
An immutable linear range of bytes.
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
constexpr Dest safeCast(Src s) noexcept
Slice makeSlice(std::array< T, N > const &a)
HashPrefix
Prefix for hashing functions.
std::vector< unsigned char > Blob
Storage for linear binary data.
XRPL_NO_SANITIZE_ADDRESS void Throw(Args &&... args)
Sha512HalfHasher::result_type sha512Half(Args const &... args)
Returns the SHA512-Half of a series of objects.