20 #ifndef RIPPLE_PROTOCOL_SERIALIZER_H_INCLUDED
21 #define RIPPLE_PROTOCOL_SERIALIZER_H_INCLUDED
23 #include <ripple/basics/base_uint.h>
24 #include <ripple/basics/Blob.h>
25 #include <ripple/basics/contract.h>
26 #include <ripple/basics/Buffer.h>
27 #include <ripple/basics/safe_cast.h>
28 #include <ripple/basics/Slice.h>
29 #include <ripple/beast/crypto/secure_erase.h>
30 #include <ripple/protocol/HashPrefix.h>
31 #include <ripple/protocol/SField.h>
62 assert(
data !=
nullptr);
85 int add8 (
unsigned char byte);
93 template <
typename Integer>
96 template <
int Bits,
class Tag>
107 return addBitString<160, Tag>(i);
111 int addRaw (
const void* ptr,
int len);
119 int addVL (
const void* ptr,
int len);
122 bool get8 (
int&,
int offset)
const;
125 template <
typename Integer>
127 static const auto bytes =
sizeof(Integer);
132 auto ptr = &
mData[offset];
133 for (
auto i = 0; i < bytes; ++i)
142 template <
int Bits,
typename Tag =
void>
144 auto success = (offset + (Bits / 8)) <=
mData.
size ();
154 return getBitString<160, Tag>(o, offset);
157 bool getRaw (
Blob&,
int offset,
int length)
const;
160 bool getVL (
Blob& objectVL,
int offset,
int& length)
const;
166 return addFieldID (safe_cast<int> (type), name);
226 Blob ::const_iterator
begin ()
const
230 Blob ::const_iterator
end ()
const
268 for (
unsigned char const& element :
mData)
274 safe_cast<unsigned int>(element);
332 static_assert (N > 0,
"");
347 return static_cast<int>(
remain_);
363 template <
int Bits,
class Tag =
void>
370 return getBitString<128>();
376 return getBitString<160>();
382 return getBitString<256>();
415 template <
int Bits,
class Tag>
420 auto const n = Bits/8;
422 Throw<std::runtime_error> (
423 "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 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)
Slice getSlice(std::size_t bytes)
SerialIter(std::uint8_t const (&data)[N])
int add256(uint256 const &)