|
xrpld
|
#include <Serializer.h>

Public Member Functions | |
| Serializer (int n=256) | |
| Serializer (void const *data, std::size_t size) | |
| Slice | slice () const noexcept |
| std::size_t | size () const noexcept |
| void const * | data () const noexcept |
| int | add8 (unsigned char byteValue) |
| int | add16 (std::uint16_t i) |
| template<typename T> requires (std::is_same_v<std::make_unsigned_t<std::remove_cv_t<T>>, std::uint32_t>) | |
| int | add32 (T i) |
| int | add32 (HashPrefix p) |
| template<typename T> requires (std::is_same_v<std::make_unsigned_t<std::remove_cv_t<T>>, std::uint64_t>) | |
| int | add64 (T i) |
| template<typename Integer> | |
| int | addInteger (Integer) |
| template<std::size_t Bits, class Tag> | |
| int | addBitString (BaseUInt< Bits, Tag > const &v) |
| int | addRaw (Blob const &vector) |
| int | addRaw (Slice slice) |
| int | addRaw (void const *ptr, int len) |
| int | addRaw (Serializer const &s) |
| int | addVL (Blob const &vector) |
| int | addVL (Slice const &slice) |
| template<class Iter> | |
| int | addVL (Iter begin, Iter end, int len) |
| int | addVL (void const *ptr, int len) |
| bool | get8 (int &, int offset) const |
| template<typename Integer> | |
| bool | getInteger (Integer &number, int offset) |
| template<std::size_t Bits, typename Tag = void> | |
| bool | getBitString (BaseUInt< Bits, Tag > &data, int offset) const |
| int | addFieldID (int type, int name) |
| int | addFieldID (SerializedTypeID type, int name) |
| UInt256 | getSHA512Half () const |
| Blob const & | peekData () const |
| Blob | getData () const |
| Blob & | modData () |
| int | getDataLength () const |
| void const * | getDataPtr () const |
| void * | getDataPtr () |
| int | getLength () const |
| std::string | getString () const |
| void | erase () |
| bool | chop (int num) |
| Blob::iterator | begin () |
| Blob::iterator | end () |
| Blob::const_iterator | begin () const |
| Blob::const_iterator | end () const |
| void | reserve (size_t n) |
| void | resize (size_t n) |
| size_t | capacity () const |
| bool | operator== (Blob const &v) const |
| bool | operator== (Serializer const &v) const |
| template<> | |
| int | addInteger (unsigned char i) |
| template<> | |
| int | addInteger (std::uint16_t i) |
| template<> | |
| int | addInteger (std::uint32_t i) |
| template<> | |
| int | addInteger (std::uint64_t i) |
| template<> | |
| int | addInteger (std::int32_t i) |
Static Public Member Functions | |
| static int | decodeLengthLength (std::byte firstByte) |
| Works out how long a header is, from its first byte. | |
| static int | decodeVLLength (std::byte firstByte) |
| Reads the field length out of a 1 byte header. | |
| static int | decodeVLLength (std::byte firstByte, std::byte secondByte) |
| Reads the field length out of a 2 byte header. | |
| static int | decodeVLLength (std::byte firstByte, std::byte secondByte, std::byte thirdByte) |
| Reads the field length out of a 3 byte header. | |
Static Public Attributes | |
| static constexpr int | kMaxNumberOfBytesInHeader = 3 |
| A header is never longer than this. | |
| static constexpr int | kMinValueOfFirstByteFor1ByteHeader = 0 |
| static constexpr int | kMaxValueOfFirstByteFor1ByteHeader = 192 |
| static constexpr int | kMinValueOfFirstByteFor2ByteHeader |
| static constexpr int | kMaxValueOfFirstByteFor2ByteHeader = 240 |
| static constexpr int | kMinValueOfFirstByteFor3ByteHeader |
| static constexpr int | kMaxValueOfFirstByteFor3ByteHeader = 254 |
| static constexpr int | kNumberOfValuesInOneByte = 256 |
| static constexpr int | kNumberOfValuesInTwoBytes |
| static constexpr int | kMinValueOfLengthFor1ByteHeader = kMinValueOfFirstByteFor1ByteHeader |
| A 1 byte header holds the length in the byte itself, so both ends of this range are the same numbers as the first byte's own range. | |
| static constexpr int | kMaxValueOfLengthFor1ByteHeader = kMaxValueOfFirstByteFor1ByteHeader |
| static constexpr int | kMinValueOfLengthFor2ByteHeader = kMaxValueOfLengthFor1ByteHeader + 1 |
| 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 | kMinValueOfLengthFor3ByteHeader = kMaxValueOfLengthFor2ByteHeader + 1 |
| static constexpr int | kMaxRepresentableLength |
| 14 values of the first byte mean a 3 byte header, and each of them covers 65,536 lengths. | |
| static constexpr int | kMaxValueOfLengthFor3ByteHeader = 918744 |
| The largest length the encoder will write. | |
Private Member Functions | |
| int | addEncoded (int length) |
| Appends the length header for a field of the given length. | |
Static Private Member Functions | |
| static int | encodeLengthLength (int length) |
| Works out how many bytes the header needs for the given length. | |
Private Attributes | |
| Blob | data_ |
Definition at line 22 of file Serializer.h.
|
explicit |
Definition at line 124 of file Serializer.h.
| xrpl::Serializer::Serializer | ( | void const * | data, |
| std::size_t | size ) |
Definition at line 129 of file Serializer.h.
|
nodiscardnoexcept |
Definition at line 141 of file Serializer.h.
|
nodiscardnoexcept |
Definition at line 147 of file Serializer.h.
|
nodiscardnoexcept |
Definition at line 153 of file Serializer.h.
| int xrpl::Serializer::add8 | ( | unsigned char | byteValue | ) |
Definition at line 146 of file libxrpl/protocol/Serializer.cpp.
| int xrpl::Serializer::add16 | ( | std::uint16_t | i | ) |
Definition at line 25 of file libxrpl/protocol/Serializer.cpp.
| int xrpl::Serializer::add32 | ( | T | i | ) |
Definition at line 167 of file Serializer.h.
| int xrpl::Serializer::add32 | ( | HashPrefix | p | ) |
Definition at line 34 of file libxrpl/protocol/Serializer.cpp.
| int xrpl::Serializer::add64 | ( | T | i | ) |
Definition at line 183 of file Serializer.h.
| int xrpl::Serializer::addInteger | ( | Integer | ) |
| int xrpl::Serializer::addBitString | ( | BaseUInt< Bits, Tag > const & | v | ) |
Definition at line 202 of file Serializer.h.
| int xrpl::Serializer::addRaw | ( | Blob const & | vector | ) |
Definition at line 75 of file libxrpl/protocol/Serializer.cpp.
| int xrpl::Serializer::addRaw | ( | Slice | slice | ) |
Definition at line 83 of file libxrpl/protocol/Serializer.cpp.
| int xrpl::Serializer::addRaw | ( | void const * | ptr, |
| int | len ) |
Definition at line 99 of file libxrpl/protocol/Serializer.cpp.
| int xrpl::Serializer::addRaw | ( | Serializer const & | s | ) |
Definition at line 91 of file libxrpl/protocol/Serializer.cpp.
| int xrpl::Serializer::addVL | ( | Blob const & | vector | ) |
Definition at line 180 of file libxrpl/protocol/Serializer.cpp.
| int xrpl::Serializer::addVL | ( | Slice const & | slice | ) |
Definition at line 191 of file libxrpl/protocol/Serializer.cpp.
| int xrpl::Serializer::addVL | ( | Iter | begin, |
| Iter | end, | ||
| int | len ) |
Definition at line 459 of file Serializer.h.
| int xrpl::Serializer::addVL | ( | void const * | ptr, |
| int | len ) |
Definition at line 200 of file libxrpl/protocol/Serializer.cpp.
| bool xrpl::Serializer::get8 | ( | int & | byte, |
| int | offset ) const |
Definition at line 154 of file libxrpl/protocol/Serializer.cpp.
| bool xrpl::Serializer::getInteger | ( | Integer & | number, |
| int | offset ) |
Definition at line 232 of file Serializer.h.
| bool xrpl::Serializer::getBitString | ( | BaseUInt< Bits, Tag > & | data, |
| int | offset ) const |
Definition at line 251 of file Serializer.h.
| int xrpl::Serializer::addFieldID | ( | int | type, |
| int | name ) |
Definition at line 107 of file libxrpl/protocol/Serializer.cpp.
| int xrpl::Serializer::addFieldID | ( | SerializedTypeID | type, |
| int | name ) |
Definition at line 262 of file Serializer.h.
|
nodiscard |
Definition at line 174 of file libxrpl/protocol/Serializer.cpp.
|
nodiscard |
Definition at line 273 of file Serializer.h.
|
nodiscard |
Definition at line 278 of file Serializer.h.
| Blob & xrpl::Serializer::modData | ( | ) |
Definition at line 283 of file Serializer.h.
|
nodiscard |
Definition at line 289 of file Serializer.h.
|
nodiscard |
Definition at line 294 of file Serializer.h.
| void * xrpl::Serializer::getDataPtr | ( | ) |
Definition at line 299 of file Serializer.h.
|
nodiscard |
Definition at line 304 of file Serializer.h.
|
nodiscard |
Definition at line 309 of file Serializer.h.
| void xrpl::Serializer::erase | ( | ) |
Definition at line 314 of file Serializer.h.
| bool xrpl::Serializer::chop | ( | int | num | ) |
Definition at line 164 of file libxrpl/protocol/Serializer.cpp.
| Blob::iterator xrpl::Serializer::begin | ( | ) |
Definition at line 323 of file Serializer.h.
| Blob::iterator xrpl::Serializer::end | ( | ) |
Definition at line 328 of file Serializer.h.
|
nodiscard |
Definition at line 333 of file Serializer.h.
|
nodiscard |
Definition at line 338 of file Serializer.h.
| void xrpl::Serializer::reserve | ( | size_t | n | ) |
Definition at line 343 of file Serializer.h.
| void xrpl::Serializer::resize | ( | size_t | n | ) |
Definition at line 348 of file Serializer.h.
|
nodiscard |
Definition at line 353 of file Serializer.h.
| bool xrpl::Serializer::operator== | ( | Blob const & | v | ) | const |
Definition at line 359 of file Serializer.h.
| bool xrpl::Serializer::operator== | ( | Serializer const & | v | ) | const |
Definition at line 364 of file Serializer.h.
|
static |
Works out how long a header is, from its first byte.
Each overload of decodeVLLength below reads one header length, so call this first to learn which of them to call.
| firstByte | First byte of the header, as read from the stream. |
| std::overflow_error | if firstByte is the one value that starts no header. |
Definition at line 276 of file libxrpl/protocol/Serializer.cpp.
|
static |
Reads the field length out of a 1 byte header.
| firstByte | The single header byte, which is the length itself. |
| std::overflow_error | if firstByte is big enough to mean a longer header, in which case it is not a length by itself. |
Definition at line 293 of file libxrpl/protocol/Serializer.cpp.
Reads the field length out of a 2 byte header.
| firstByte | First header byte. Its value means a 2 byte header, and how far it sits into that range gives the top part of the length. |
| secondByte | Second header byte, holding the rest of the length. |
| std::overflow_error | if firstByte is outside the range that means a 2 byte header. |
Definition at line 305 of file libxrpl/protocol/Serializer.cpp.
|
static |
Reads the field length out of a 3 byte header.
| firstByte | First header byte. Its value means a 3 byte header, and how far it sits into that range gives the top part of the length. |
| secondByte | Second header byte, holding the middle part of the length. |
| thirdByte | Third header byte, holding the low part. |
| std::overflow_error | if firstByte is outside the range that means a 3 byte header, or if the three bytes together state a length above kMaxValueOfLengthFor3ByteHeader, which the encoder would not write back. |
Definition at line 323 of file libxrpl/protocol/Serializer.cpp.
|
staticprivate |
Works out how many bytes the header needs for the given length.
This deliberately repeats the width choice addEncoded makes, so that addVL's assertion can compare the two. It has no other caller; do not reach for it as a utility.
| length | Field length in bytes. |
| std::overflow_error | if length is negative, or above kMaxValueOfLengthFor3ByteHeader. |
Definition at line 255 of file libxrpl/protocol/Serializer.cpp.
|
private |
Appends the length header for a field of the given length.
The field's own data is not written; the caller appends it next.
| length | Field length in bytes. |
| std::overflow_error | if length is negative, or above kMaxValueOfLengthFor3ByteHeader. |
Definition at line 211 of file libxrpl/protocol/Serializer.cpp.
| int xrpl::Serializer::addInteger | ( | unsigned char | i | ) |
Definition at line 45 of file libxrpl/protocol/Serializer.cpp.
| int xrpl::Serializer::addInteger | ( | std::uint16_t | i | ) |
Definition at line 51 of file libxrpl/protocol/Serializer.cpp.
| int xrpl::Serializer::addInteger | ( | std::uint32_t | i | ) |
Definition at line 57 of file libxrpl/protocol/Serializer.cpp.
| int xrpl::Serializer::addInteger | ( | std::uint64_t | i | ) |
Definition at line 63 of file libxrpl/protocol/Serializer.cpp.
| int xrpl::Serializer::addInteger | ( | std::int32_t | i | ) |
Definition at line 69 of file libxrpl/protocol/Serializer.cpp.
|
private |
Definition at line 26 of file Serializer.h.
|
staticconstexpr |
A header is never longer than this.
The encoder fills a buffer of this size and writes only the bytes it used.
Definition at line 33 of file Serializer.h.
|
staticconstexpr |
Definition at line 47 of file Serializer.h.
|
staticconstexpr |
Definition at line 48 of file Serializer.h.
|
staticconstexpr |
Definition at line 50 of file Serializer.h.
|
staticconstexpr |
Definition at line 52 of file Serializer.h.
|
staticconstexpr |
Definition at line 54 of file Serializer.h.
|
staticconstexpr |
Definition at line 57 of file Serializer.h.
|
staticconstexpr |
Definition at line 67 of file Serializer.h.
|
staticconstexpr |
Definition at line 68 of file Serializer.h.
|
staticconstexpr |
A 1 byte header holds the length in the byte itself, so both ends of this range are the same numbers as the first byte's own range.
Definition at line 83 of file Serializer.h.
|
staticconstexpr |
Definition at line 84 of file Serializer.h.
|
staticconstexpr |
Definition at line 86 of file Serializer.h.
|
staticconstexpr |
48 values of the first byte mean a 2 byte header, and each of them covers 256 lengths.
The 48 is worked out from the two range ends above, so it stays right if either of them changes.
Definition at line 93 of file Serializer.h.
|
staticconstexpr |
Definition at line 98 of file Serializer.h.
|
staticconstexpr |
14 values of the first byte mean a 3 byte header, and each of them covers 65,536 lengths.
Counted the same way, that gives the largest length any header can state.
Nothing is accepted or rejected against this. The assertion below uses it to check that every length the encoder writes is one a header can state.
Definition at line 108 of file Serializer.h.
|
staticconstexpr |
The largest length the encoder will write.
This is the one number here that is picked rather than worked out. The decoder accepts nothing above it, so both sides agree on the same set of lengths.
Definition at line 118 of file Serializer.h.