20 #ifndef RIPPLE_PROTOCOL_SERIALIZER_H_INCLUDED
21 #define RIPPLE_PROTOCOL_SERIALIZER_H_INCLUDED
23 #include <ripple/basics/Blob.h>
24 #include <ripple/basics/Buffer.h>
25 #include <ripple/basics/Slice.h>
26 #include <ripple/basics/base_uint.h>
27 #include <ripple/basics/contract.h>
28 #include <ripple/basics/safe_cast.h>
29 #include <ripple/beast/crypto/secure_erase.h>
30 #include <ripple/protocol/HashPrefix.h>
31 #include <ripple/protocol/SField.h>
61 assert(
data !=
nullptr);
86 add8(
unsigned char byte);
96 template <
typename Integer>
99 template <
int Bits,
class Tag>
113 return addBitString<160, Tag>(i);
119 addRaw(
const void* ptr,
int len);
129 template <
class Iter>
133 addVL(
const void* ptr,
int len);
137 get8(
int&,
int offset)
const;
141 template <
typename Integer>
145 static const auto bytes =
sizeof(Integer);
150 auto ptr = &
mData[offset];
151 for (
auto i = 0; i < bytes; ++i)
160 template <
int Bits,
typename Tag =
void>
164 auto success = (offset + (Bits / 8)) <=
mData.
size();
175 return getBitString<160, Tag>(o, offset);
181 getRaw(
int offset,
int length)
const;
184 getVL(
Blob& objectVL,
int offset,
int& length)
const;
193 return addFieldID(safe_cast<int>(type), name);
267 Blob ::const_iterator
272 Blob ::const_iterator
319 for (
unsigned char const& element :
mData)
322 << safe_cast<unsigned int>(element);
348 template <
class Iter>
386 static_assert(N > 0,
"");
401 return static_cast<int>(
remain_);
417 template <
int Bits,
class Tag =
void>
424 return getBitString<128>();
430 return getBitString<160>();
436 return getBitString<256>();
470 template <
int Bits,
class Tag>
475 auto const n = Bits / 8;
477 Throw<std::runtime_error>(
"invalid SerialIter getBitString");
int add8(unsigned char byte)
SerialIter(Slice const &slice)
int addFieldID(int type, int name)
bool getVLLength(int &length, int offset) const
An immutable linear range of bytes.
bool getVL(Blob &objectVL, int offset, int &length) const
std::string getHex() const
bool operator==(Blob const &v)
std::string getString() const
void getFieldID(int &type, int &name)
static int decodeVLLength(int b1)
Like std::vector<char> but better.
uint256 getSHA512Half() const
static int decodeLengthLength(int b1)
bool get256(uint256 &, int offset) const
SerialIter(void const *data, std::size_t size) noexcept
void const * data() const noexcept
bool getInteger(Integer &number, int offset)
int getDataLength() const
bool operator!=(Blob const &v)
HashPrefix
Prefix for hashing functions.
bool operator!=(const Serializer &v)
bool getRaw(Blob &, int offset, int length) const
static int lengthVL(int length)
const void * getDataPtr() const
std::size_t empty() const noexcept
int addRaw(Blob const &vector)
bool get8(int &, int offset) const
Slice slice() const noexcept
int add128(const uint128 &)
void secure_erase(void *dest, std::size_t bytes)
Guaranteed to fill memory with zeroes.
int addEncoded(int length)
Blob ::const_iterator end() const
bool get160(base_uint< 160, Tag > &o, int offset) const
base_uint< Bits, Tag > getBitString()
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
int addBitString(base_uint< Bits, Tag > const &v)
bool getBitString(base_uint< Bits, Tag > &data, int offset) const
int addZeros(size_t uBytes)
int getBytesLeft() const noexcept
std::size_t size() const noexcept
Blob const & peekData() const
Serializer(void const *data, std::size_t size)
int addVL(Blob const &vector)
Blob ::const_iterator begin() const
int add160(base_uint< 160, Tag > const &i)
static int encodeLengthLength(int length)
int addFieldID(SerializedTypeID type, int name)
bool operator==(const Serializer &v)
Slice getSlice(std::size_t bytes)
SerialIter(std::uint8_t const (&data)[N])
int add256(uint256 const &)