Bitcoin ABC  0.22.13
P2P Digital Currency
Classes | Macros | Enumerations | Functions | Variables
serialize.h File Reference
#include <compat/endian.h>
#include <prevector.h>
#include <span.h>
#include <algorithm>
#include <array>
#include <cstdint>
#include <cstring>
#include <ios>
#include <limits>
#include <map>
#include <memory>
#include <set>
#include <string>
#include <utility>
#include <vector>
Include dependency graph for serialize.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  deserialize_type
 Dummy data type to identify deserializing constructors. More...
 
struct  CheckVarIntMode< Mode, I >
 
class  Wrapper< Formatter, T >
 Simple wrapper class to serialize objects using a formatter; used by Using(). More...
 
struct  VarIntFormatter< Mode >
 Serialization wrapper class for integers in VarInt format. More...
 
struct  CustomUintFormatter< Bytes >
 
class  BigEndian< I >
 Serialization wrapper class for big-endian integers. More...
 
struct  CompactSizeFormatter
 Formatter for integers in CompactSize format. More...
 
class  LimitedString< Limit >
 
struct  VectorFormatter< Formatter >
 Formatter to serialize/deserialize vector elements using another formatter. More...
 
struct  DefaultFormatter
 Default formatter. More...
 
struct  CSerActionSerialize
 Support for ADD_SERIALIZE_METHODS and READWRITE macro. More...
 
struct  CSerActionUnserialize
 
class  CSizeComputer
 GetSerializeSize implementations More...
 

Macros

#define READWRITE(...)   (::SerReadWriteMany(s, ser_action, __VA_ARGS__))
 
#define READWRITEAS(type, obj)   (::SerReadWriteMany(s, ser_action, ReadWriteAsHelper<type>(obj)))
 
#define ADD_SERIALIZE_METHODS
 Implement three methods for serializable objects. More...
 
#define FORMATTER_METHODS(cls, obj)
 Implement the Ser and Unser methods needed for implementing a formatter (see Using below). More...
 
#define SERIALIZE_METHODS(cls, obj)
 Implement the Serialize and Unserialize methods by delegating to a single templated static method that takes the to-be-(de)serialized object as a parameter. More...
 
#define VARINT_MODE(obj, mode)   Using<VarIntFormatter<mode>>(obj)
 
#define VARINT(obj)   Using<VarIntFormatter<VarIntMode::DEFAULT>>(obj)
 
#define COMPACTSIZE(obj)   Using<CompactSizeFormatter>(obj)
 
#define LIMITED_STRING(obj, n)   LimitedString<n>(REF(obj))
 

Enumerations

enum  { SER_NETWORK = (1 << 0), SER_DISK = (1 << 1), SER_GETHASH = (1 << 2) }
 
enum  VarIntMode { VarIntMode::DEFAULT, VarIntMode::NONNEGATIVE_SIGNED }
 Variable-length integers: bytes are a MSB base-128 encoding of the number. More...
 

Functions

template<typename T >
T & REF (const T &val)
 Used to bypass the rule against non-const reference to temporary where it makes sense with wrappers. More...
 
template<typename T >
T * NCONST_PTR (const T *val)
 Used to acquire a non-const pointer "this" to generate bodies of const serialization operations from a template. More...
 
char * CharCast (char *c)
 Safely convert odd char pointer types to standard ones. More...
 
char * CharCast (uint8_t *c)
 
const char * CharCast (const char *c)
 
const char * CharCast (const uint8_t *c)
 
template<typename Stream >
void ser_writedata8 (Stream &s, uint8_t obj)
 Lowest-level serialization and conversion. More...
 
template<typename Stream >
void ser_writedata16 (Stream &s, uint16_t obj)
 
template<typename Stream >
void ser_writedata16be (Stream &s, uint16_t obj)
 
template<typename Stream >
void ser_writedata32 (Stream &s, uint32_t obj)
 
template<typename Stream >
void ser_writedata32be (Stream &s, uint32_t obj)
 
template<typename Stream >
void ser_writedata64 (Stream &s, uint64_t obj)
 
template<typename Stream >
uint8_t ser_readdata8 (Stream &s)
 
template<typename Stream >
uint16_t ser_readdata16 (Stream &s)
 
template<typename Stream >
uint16_t ser_readdata16be (Stream &s)
 
template<typename Stream >
uint32_t ser_readdata32 (Stream &s)
 
template<typename Stream >
uint32_t ser_readdata32be (Stream &s)
 
template<typename Stream >
uint64_t ser_readdata64 (Stream &s)
 
uint64_t ser_double_to_uint64 (double x)
 
uint32_t ser_float_to_uint32 (float x)
 
double ser_uint64_to_double (uint64_t y)
 
float ser_uint32_to_float (uint32_t y)
 
template<typename X >
X & ReadWriteAsHelper (X &x)
 Convert the reference base type to X, without changing constness or reference type. More...
 
template<typename X >
const X & ReadWriteAsHelper (const X &x)
 
template<typename Stream >
void Serialize (Stream &s, char a)
 
template<typename Stream >
void Serialize (Stream &s, int8_t a)
 
template<typename Stream >
void Serialize (Stream &s, uint8_t a)
 
template<typename Stream >
void Serialize (Stream &s, int16_t a)
 
template<typename Stream >
void Serialize (Stream &s, uint16_t a)
 
template<typename Stream >
void Serialize (Stream &s, int32_t a)
 
template<typename Stream >
void Serialize (Stream &s, uint32_t a)
 
template<typename Stream >
void Serialize (Stream &s, int64_t a)
 
template<typename Stream >
void Serialize (Stream &s, uint64_t a)
 
template<typename Stream >
void Serialize (Stream &s, float a)
 
template<typename Stream >
void Serialize (Stream &s, double a)
 
template<typename Stream , size_t N>
void Serialize (Stream &s, const int8_t(&a)[N])
 
template<typename Stream , size_t N>
void Serialize (Stream &s, const uint8_t(&a)[N])
 
template<typename Stream , size_t N>
void Serialize (Stream &s, const std::array< int8_t, N > &a)
 
template<typename Stream , size_t N>
void Serialize (Stream &s, const std::array< uint8_t, N > &a)
 
template<typename Stream >
void Unserialize (Stream &s, char &a)
 
template<typename Stream , size_t N>
void Serialize (Stream &s, const char(&a)[N])
 
template<typename Stream , size_t N>
void Serialize (Stream &s, const std::array< char, N > &a)
 
template<typename Stream >
void Serialize (Stream &s, const Span< const uint8_t > &span)
 
template<typename Stream >
void Serialize (Stream &s, const Span< uint8_t > &span)
 
template<typename Stream >
void Unserialize (Stream &s, int8_t &a)
 
template<typename Stream >
void Unserialize (Stream &s, uint8_t &a)
 
template<typename Stream >
void Unserialize (Stream &s, int16_t &a)
 
template<typename Stream >
void Unserialize (Stream &s, uint16_t &a)
 
template<typename Stream >
void Unserialize (Stream &s, int32_t &a)
 
template<typename Stream >
void Unserialize (Stream &s, uint32_t &a)
 
template<typename Stream >
void Unserialize (Stream &s, int64_t &a)
 
template<typename Stream >
void Unserialize (Stream &s, uint64_t &a)
 
template<typename Stream >
void Unserialize (Stream &s, float &a)
 
template<typename Stream >
void Unserialize (Stream &s, double &a)
 
template<typename Stream , size_t N>
void Unserialize (Stream &s, int8_t(&a)[N])
 
template<typename Stream , size_t N>
void Unserialize (Stream &s, uint8_t(&a)[N])
 
template<typename Stream , size_t N>
void Unserialize (Stream &s, std::array< int8_t, N > &a)
 
template<typename Stream , size_t N>
void Unserialize (Stream &s, std::array< uint8_t, N > &a)
 
template<typename Stream , size_t N>
void Unserialize (Stream &s, char(&a)[N])
 
template<typename Stream , size_t N>
void Unserialize (Stream &s, std::array< char, N > &a)
 
template<typename Stream >
void Serialize (Stream &s, bool a)
 
template<typename Stream >
void Unserialize (Stream &s, bool &a)
 
template<typename Stream >
void Unserialize (Stream &s, Span< uint8_t > &span)
 
uint32_t GetSizeOfCompactSize (uint64_t nSize)
 Compact Size size < 253 – 1 byte size <= USHRT_MAX – 3 bytes (253 + 2 bytes) size <= UINT_MAX – 5 bytes (254 + 4 bytes) size > UINT_MAX – 9 bytes (255 + 8 bytes) More...
 
void WriteCompactSize (CSizeComputer &os, uint64_t nSize)
 
template<typename Stream >
void WriteCompactSize (Stream &os, uint64_t nSize)
 
template<typename Stream >
uint64_t ReadCompactSize (Stream &is)
 
template<VarIntMode Mode, typename I >
unsigned int GetSizeOfVarInt (I n)
 
template<typename I >
void WriteVarInt (CSizeComputer &os, I n)
 
template<typename Stream , VarIntMode Mode, typename I >
void WriteVarInt (Stream &os, I n)
 
template<typename Stream , VarIntMode Mode, typename I >
ReadVarInt (Stream &is)
 
template<typename Formatter , typename T >
static Wrapper< Formatter, T & > Using (T &&t)
 Cause serialization/deserialization of an object to be done using a specified formatter class. More...
 
template<typename I >
BigEndian< I > WrapBigEndian (I &n)
 
template<typename Stream , typename C >
void Serialize (Stream &os, const std::basic_string< C > &str)
 Forward declarations. More...
 
template<typename Stream , typename C >
void Unserialize (Stream &is, std::basic_string< C > &str)
 
template<typename Stream , unsigned int N, typename T >
void Serialize_impl (Stream &os, const prevector< N, T > &v, const uint8_t &)
 prevector prevectors of uint8_t are a special case and are intended to be serialized as a single opaque blob. More...
 
template<typename Stream , unsigned int N, typename T , typename V >
void Serialize_impl (Stream &os, const prevector< N, T > &v, const V &)
 
template<typename Stream , unsigned int N, typename T >
void Serialize (Stream &os, const prevector< N, T > &v)
 
template<typename Stream , unsigned int N, typename T >
void Unserialize_impl (Stream &is, prevector< N, T > &v, const uint8_t &)
 
template<typename Stream , unsigned int N, typename T , typename V >
void Unserialize_impl (Stream &is, prevector< N, T > &v, const V &)
 
template<typename Stream , unsigned int N, typename T >
void Unserialize (Stream &is, prevector< N, T > &v)
 
template<typename Stream , typename T , typename A >
void Serialize_impl (Stream &os, const std::vector< T, A > &v, const uint8_t &)
 vector vectors of uint8_t are a special case and are intended to be serialized as a single opaque blob. More...
 
template<typename Stream , typename T , typename A >
void Serialize_impl (Stream &os, const std::vector< T, A > &v, const bool &)
 
template<typename Stream , typename T , typename A , typename V >
void Serialize_impl (Stream &os, const std::vector< T, A > &v, const V &)
 
template<typename Stream , typename T , typename A >
void Serialize (Stream &os, const std::vector< T, A > &v)
 
template<typename Stream , typename T , typename A >
void Unserialize_impl (Stream &is, std::vector< T, A > &v, const uint8_t &)
 
template<typename Stream , typename T , typename A , typename V >
void Unserialize_impl (Stream &is, std::vector< T, A > &v, const V &)
 
template<typename Stream , typename T , typename A >
void Unserialize (Stream &is, std::vector< T, A > &v)
 
template<typename Stream , typename K , typename T >
void Serialize (Stream &os, const std::pair< K, T > &item)
 pair More...
 
template<typename Stream , typename K , typename T >
void Unserialize (Stream &is, std::pair< K, T > &item)
 
template<typename Stream , typename K , typename T , typename Pred , typename A >
void Serialize (Stream &os, const std::map< K, T, Pred, A > &m)
 map More...
 
template<typename Stream , typename K , typename T , typename Pred , typename A >
void Unserialize (Stream &is, std::map< K, T, Pred, A > &m)
 
template<typename Stream , typename K , typename Pred , typename A >
void Serialize (Stream &os, const std::set< K, Pred, A > &m)
 set More...
 
template<typename Stream , typename K , typename Pred , typename A >
void Unserialize (Stream &is, std::set< K, Pred, A > &m)
 
template<typename Stream , typename T >
void Serialize (Stream &os, const std::shared_ptr< const T > &p)
 shared_ptr More...
 
template<typename Stream , typename T >
void Unserialize (Stream &os, std::shared_ptr< const T > &p)
 
template<typename Stream , typename T >
void Serialize (Stream &os, const std::unique_ptr< const T > &p)
 unique_ptr More...
 
template<typename Stream , typename T >
void Unserialize (Stream &os, std::unique_ptr< const T > &p)
 
template<typename Stream , typename T >
void Serialize (Stream &os, const T &a)
 If none of the specialized versions above matched, default to calling member function. More...
 
template<typename Stream , typename T >
void Unserialize (Stream &is, T &&a)
 
template<typename Stream >
void SerializeMany (Stream &s)
 
template<typename Stream , typename Arg , typename... Args>
void SerializeMany (Stream &s, const Arg &arg, const Args &... args)
 
template<typename Stream >
void UnserializeMany (Stream &s)
 
template<typename Stream , typename Arg , typename... Args>
void UnserializeMany (Stream &s, Arg &&arg, Args &&... args)
 
template<typename Stream , typename... Args>
void SerReadWriteMany (Stream &s, CSerActionSerialize ser_action, const Args &... args)
 
template<typename Stream , typename... Args>
void SerReadWriteMany (Stream &s, CSerActionUnserialize ser_action, Args &&... args)
 
template<typename T >
size_t GetSerializeSize (const T &t, int nVersion=0)
 
template<typename... T>
size_t GetSerializeSizeMany (int nVersion, const T &... t)
 

Variables

static const uint64_t MAX_SIZE = 0x02000000
 
static const unsigned int MAX_VECTOR_ALLOCATE = 5000000
 Maximum amount of memory (in bytes) to allocate at once when deserializing vectors. More...
 
constexpr deserialize_type deserialize {}
 

Macro Definition Documentation

◆ ADD_SERIALIZE_METHODS

#define ADD_SERIALIZE_METHODS
Value:
template <typename Stream> void Serialize(Stream &s) const { \
NCONST_PTR(this)->SerializationOp(s, CSerActionSerialize()); \
} \
template <typename Stream> void Unserialize(Stream &s) { \
SerializationOp(s, CSerActionUnserialize()); \
}
void Serialize(Stream &s, char a)
Definition: serialize.h:261
Support for ADD_SERIALIZE_METHODS and READWRITE macro.
Definition: serialize.h:1114
void Unserialize(Stream &s, char &a)
Definition: serialize.h:313

Implement three methods for serializable objects.

These are actually wrappers over "SerializationOp" template, which implements the body of each class' serialization code. Adding "ADD_SERIALIZE_METHODS" in the body of the class causes these wrappers to be added as members.

Definition at line 201 of file serialize.h.

◆ COMPACTSIZE

#define COMPACTSIZE (   obj)    Using<CompactSizeFormatter>(obj)

Definition at line 609 of file serialize.h.

◆ FORMATTER_METHODS

#define FORMATTER_METHODS (   cls,
  obj 
)
Value:
template <typename Stream> static void Ser(Stream &s, const cls &obj) { \
SerializationOps(obj, s, CSerActionSerialize()); \
} \
template <typename Stream> static void Unser(Stream &s, cls &obj) { \
SerializationOps(obj, s, CSerActionUnserialize()); \
} \
template <typename Stream, typename Type, typename Operation> \
static inline void SerializationOps(Type &obj, Stream &s, \
Operation ser_action)
Support for ADD_SERIALIZE_METHODS and READWRITE macro.
Definition: serialize.h:1114

Implement the Ser and Unser methods needed for implementing a formatter (see Using below).

Both Ser and Unser are delegated to a single static method SerializationOps, which is polymorphic in the serialized/deserialized type (allowing it to be const when serializing, and non-const when deserializing).

Example use: struct FooFormatter { FORMATTER_METHODS(Class, obj) { READWRITE(obj.val1, VARINT(obj.val2)); } } would define a class FooFormatter that defines a serialization of Class objects consisting of serializing its val1 member using the default serialization, and its val2 member using VARINT serialization. That FooFormatter can then be used in statements like READWRITE(Using<FooFormatter>(obj.bla)).

Definition at line 227 of file serialize.h.

◆ LIMITED_STRING

#define LIMITED_STRING (   obj,
 
)    LimitedString<n>(REF(obj))

Definition at line 610 of file serialize.h.

◆ READWRITE

#define READWRITE (   ...)    (::SerReadWriteMany(s, ser_action, __VA_ARGS__))

Definition at line 191 of file serialize.h.

◆ READWRITEAS

#define READWRITEAS (   type,
  obj 
)    (::SerReadWriteMany(s, ser_action, ReadWriteAsHelper<type>(obj)))

Definition at line 192 of file serialize.h.

◆ SERIALIZE_METHODS

#define SERIALIZE_METHODS (   cls,
  obj 
)
Value:
template <typename Stream> void Serialize(Stream &s) const { \
static_assert(std::is_same<const cls &, decltype(*this)>::value, \
"Serialize type mismatch"); \
Ser(s, *this); \
} \
template <typename Stream> void Unserialize(Stream &s) { \
static_assert(std::is_same<cls &, decltype(*this)>::value, \
"Unserialize type mismatch"); \
Unser(s, *this); \
} \
FORMATTER_METHODS(cls, obj)
void Serialize(Stream &s, char a)
Definition: serialize.h:261
void Unserialize(Stream &s, char &a)
Definition: serialize.h:313

Implement the Serialize and Unserialize methods by delegating to a single templated static method that takes the to-be-(de)serialized object as a parameter.

This approach has the advantage that the constness of the object becomes a template parameter, and thus allows a single implementation that sees the object as const for serializing and non-const for deserializing, without casts.

Definition at line 246 of file serialize.h.

◆ VARINT

#define VARINT (   obj)    Using<VarIntFormatter<VarIntMode::DEFAULT>>(obj)

Definition at line 608 of file serialize.h.

◆ VARINT_MODE

#define VARINT_MODE (   obj,
  mode 
)    Using<VarIntFormatter<mode>>(obj)

Definition at line 607 of file serialize.h.

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
SER_NETWORK 
SER_DISK 
SER_GETHASH 

Definition at line 175 of file serialize.h.

◆ VarIntMode

enum VarIntMode
strong

Variable-length integers: bytes are a MSB base-128 encoding of the number.

The high bit in each byte signifies whether another digit follows. To make sure the encoding is one-to-one, one is subtracted from all but the last digit. Thus, the byte sequence a[] with length len, where all but the last byte has bit 128 set, encodes the number:

(a[len-1] & 0x7F) + sum(i=1..len-1, 128^i*((a[len-i-1] & 0x7F)+1))

Properties:

  • Very small (0-127: 1 byte, 128-16511: 2 bytes, 16512-2113663: 3 bytes)
  • Every integer has exactly one encoding
  • Encoding does not depend on size of original integer type
  • No redundancy: every (infinite) byte sequence corresponds to a list of encoded integers.

0: [0x00] 256: [0x81 0x00] 1: [0x01] 16383: [0xFE 0x7F] 127: [0x7F] 16384: [0xFF 0x00] 128: [0x80 0x00] 16511: [0xFF 0x7F] 255: [0x80 0x7F] 65535: [0x82 0xFE 0x7F] 2^32: [0x8E 0xFE 0xFE 0xFF 0x00] Mode for encoding VarInts.

Currently there is no support for signed encodings. The default mode will not compile with signed values, and the legacy "nonnegative signed" mode will accept signed values, but improperly encode and decode them if they are negative. In the future, the DEFAULT mode could be extended to support negative numbers in a backwards compatible way, and additional modes could be added to support different varint formats (e.g. zigzag encoding).

Enumerator
DEFAULT 
NONNEGATIVE_SIGNED 

Definition at line 503 of file serialize.h.

Function Documentation

◆ CharCast() [1/4]

char* CharCast ( char *  c)
inline

Safely convert odd char pointer types to standard ones.

Definition at line 64 of file serialize.h.

Here is the caller graph for this function:

◆ CharCast() [2/4]

char* CharCast ( uint8_t *  c)
inline

Definition at line 67 of file serialize.h.

◆ CharCast() [3/4]

const char* CharCast ( const char *  c)
inline

Definition at line 70 of file serialize.h.

◆ CharCast() [4/4]

const char* CharCast ( const uint8_t *  c)
inline

Definition at line 73 of file serialize.h.

◆ GetSerializeSize()

template<typename T >
size_t GetSerializeSize ( const T &  t,
int  nVersion = 0 
)

Definition at line 1193 of file serialize.h.

Here is the caller graph for this function:

◆ GetSerializeSizeMany()

template<typename... T>
size_t GetSerializeSizeMany ( int  nVersion,
const T &...  t 
)

Definition at line 1198 of file serialize.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetSizeOfCompactSize()

uint32_t GetSizeOfCompactSize ( uint64_t  nSize)
inline

Compact Size size < 253 – 1 byte size <= USHRT_MAX – 3 bytes (253 + 2 bytes) size <= UINT_MAX – 5 bytes (254 + 4 bytes) size > UINT_MAX – 9 bytes (255 + 8 bytes)

Definition at line 410 of file serialize.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetSizeOfVarInt()

template<VarIntMode Mode, typename I >
unsigned int GetSizeOfVarInt ( n)
inline

Definition at line 516 of file serialize.h.

Here is the call graph for this function:

◆ NCONST_PTR()

template<typename T >
T* NCONST_PTR ( const T *  val)
inline

Used to acquire a non-const pointer "this" to generate bodies of const serialization operations from a template.

Definition at line 59 of file serialize.h.

◆ ReadCompactSize()

template<typename Stream >
uint64_t ReadCompactSize ( Stream &  is)

Definition at line 442 of file serialize.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ReadVarInt()

template<typename Stream , VarIntMode Mode, typename I >
I ReadVarInt ( Stream &  is)

Definition at line 549 of file serialize.h.

Here is the call graph for this function:

◆ ReadWriteAsHelper() [1/2]

template<typename X >
X& ReadWriteAsHelper ( X &  x)

Convert the reference base type to X, without changing constness or reference type.

Definition at line 184 of file serialize.h.

◆ ReadWriteAsHelper() [2/2]

template<typename X >
const X& ReadWriteAsHelper ( const X &  x)

Definition at line 187 of file serialize.h.

◆ REF()

template<typename T >
T& REF ( const T &  val)
inline

Used to bypass the rule against non-const reference to temporary where it makes sense with wrappers.

Definition at line 51 of file serialize.h.

◆ ser_double_to_uint64()

uint64_t ser_double_to_uint64 ( double  x)
inline

Definition at line 139 of file serialize.h.

Here is the caller graph for this function:

◆ ser_float_to_uint32()

uint32_t ser_float_to_uint32 ( float  x)
inline

Definition at line 146 of file serialize.h.

Here is the caller graph for this function:

◆ ser_readdata16()

template<typename Stream >
uint16_t ser_readdata16 ( Stream &  s)
inline

Definition at line 114 of file serialize.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ser_readdata16be()

template<typename Stream >
uint16_t ser_readdata16be ( Stream &  s)
inline

Definition at line 119 of file serialize.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ser_readdata32()

template<typename Stream >
uint32_t ser_readdata32 ( Stream &  s)
inline

Definition at line 124 of file serialize.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ser_readdata32be()

template<typename Stream >
uint32_t ser_readdata32be ( Stream &  s)
inline

Definition at line 129 of file serialize.h.

Here is the call graph for this function:

◆ ser_readdata64()

template<typename Stream >
uint64_t ser_readdata64 ( Stream &  s)
inline

Definition at line 134 of file serialize.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ser_readdata8()

template<typename Stream >
uint8_t ser_readdata8 ( Stream &  s)
inline

Definition at line 109 of file serialize.h.

Here is the caller graph for this function:

◆ ser_uint32_to_float()

float ser_uint32_to_float ( uint32_t  y)
inline

Definition at line 160 of file serialize.h.

Here is the caller graph for this function:

◆ ser_uint64_to_double()

double ser_uint64_to_double ( uint64_t  y)
inline

Definition at line 153 of file serialize.h.

Here is the caller graph for this function:

◆ ser_writedata16()

template<typename Stream >
void ser_writedata16 ( Stream &  s,
uint16_t  obj 
)
inline

Definition at line 85 of file serialize.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ser_writedata16be()

template<typename Stream >
void ser_writedata16be ( Stream &  s,
uint16_t  obj 
)
inline

Definition at line 90 of file serialize.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ser_writedata32()

template<typename Stream >
void ser_writedata32 ( Stream &  s,
uint32_t  obj 
)
inline

Definition at line 95 of file serialize.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ser_writedata32be()

template<typename Stream >
void ser_writedata32be ( Stream &  s,
uint32_t  obj 
)
inline

Definition at line 100 of file serialize.h.

Here is the call graph for this function:

◆ ser_writedata64()

template<typename Stream >
void ser_writedata64 ( Stream &  s,
uint64_t  obj 
)
inline

Definition at line 105 of file serialize.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ser_writedata8()

template<typename Stream >
void ser_writedata8 ( Stream &  s,
uint8_t  obj 
)
inline

Lowest-level serialization and conversion.

Note
Sizes of these types are verified in the tests

Definition at line 81 of file serialize.h.

Here is the caller graph for this function:

◆ Serialize() [1/29]

template<typename Stream >
void Serialize ( Stream &  s,
char  a 
)
inline

Definition at line 261 of file serialize.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ Serialize() [2/29]

template<typename Stream >
void Serialize ( Stream &  s,
int8_t  a 
)
inline

Definition at line 265 of file serialize.h.

Here is the call graph for this function:

◆ Serialize() [3/29]

template<typename Stream >
void Serialize ( Stream &  s,
uint8_t  a 
)
inline

Definition at line 268 of file serialize.h.

Here is the call graph for this function:

◆ Serialize() [4/29]

template<typename Stream >
void Serialize ( Stream &  s,
int16_t  a 
)
inline

Definition at line 271 of file serialize.h.

Here is the call graph for this function:

◆ Serialize() [5/29]

template<typename Stream >
void Serialize ( Stream &  s,
uint16_t  a 
)
inline

Definition at line 274 of file serialize.h.

Here is the call graph for this function:

◆ Serialize() [6/29]

template<typename Stream >
void Serialize ( Stream &  s,
int32_t  a 
)
inline

Definition at line 277 of file serialize.h.

Here is the call graph for this function:

◆ Serialize() [7/29]

template<typename Stream >
void Serialize ( Stream &  s,
uint32_t  a 
)
inline

Definition at line 280 of file serialize.h.

Here is the call graph for this function:

◆ Serialize() [8/29]

template<typename Stream >
void Serialize ( Stream &  s,
int64_t  a 
)
inline

Definition at line 283 of file serialize.h.

Here is the call graph for this function:

◆ Serialize() [9/29]

template<typename Stream >
void Serialize ( Stream &  s,
uint64_t  a 
)
inline

Definition at line 286 of file serialize.h.

Here is the call graph for this function:

◆ Serialize() [10/29]

template<typename Stream >
void Serialize ( Stream &  s,
float  a 
)
inline

Definition at line 289 of file serialize.h.

Here is the call graph for this function:

◆ Serialize() [11/29]

template<typename Stream >
void Serialize ( Stream &  s,
double  a 
)
inline

Definition at line 292 of file serialize.h.

Here is the call graph for this function:

◆ Serialize() [12/29]

template<typename Stream , size_t N>
void Serialize ( Stream &  s,
const int8_t(&)  a[N] 
)
inline

Definition at line 296 of file serialize.h.

◆ Serialize() [13/29]

template<typename Stream , size_t N>
void Serialize ( Stream &  s,
const uint8_t(&)  a[N] 
)
inline

Definition at line 300 of file serialize.h.

Here is the call graph for this function:

◆ Serialize() [14/29]

template<typename Stream , size_t N>
void Serialize ( Stream &  s,
const std::array< int8_t, N > &  a 
)
inline

Definition at line 304 of file serialize.h.

◆ Serialize() [15/29]

template<typename Stream , size_t N>
void Serialize ( Stream &  s,
const std::array< uint8_t, N > &  a 
)
inline

Definition at line 308 of file serialize.h.

Here is the call graph for this function:

◆ Serialize() [16/29]

template<typename Stream , size_t N>
void Serialize ( Stream &  s,
const char(&)  a[N] 
)
inline

Definition at line 317 of file serialize.h.

◆ Serialize() [17/29]

template<typename Stream , size_t N>
void Serialize ( Stream &  s,
const std::array< char, N > &  a 
)
inline

Definition at line 321 of file serialize.h.

◆ Serialize() [18/29]

template<typename Stream >
void Serialize ( Stream &  s,
const Span< const uint8_t > &  span 
)
inline

Definition at line 326 of file serialize.h.

Here is the call graph for this function:

◆ Serialize() [19/29]

template<typename Stream >
void Serialize ( Stream &  s,
const Span< uint8_t > &  span 
)
inline

Definition at line 330 of file serialize.h.

Here is the call graph for this function:

◆ Serialize() [20/29]

template<typename Stream >
void Serialize ( Stream &  s,
bool  a 
)
inline

Definition at line 390 of file serialize.h.

Here is the call graph for this function:

◆ Serialize() [21/29]

template<typename Stream , typename C >
void Serialize ( Stream &  os,
const std::basic_string< C > &  str 
)

Forward declarations.

string

Definition at line 907 of file serialize.h.

Here is the call graph for this function:

◆ Serialize() [22/29]

template<typename Stream , unsigned int N, typename T >
void Serialize ( Stream &  os,
const prevector< N, T > &  v 
)
inline

Definition at line 940 of file serialize.h.

Here is the call graph for this function:

◆ Serialize() [23/29]

template<typename Stream , typename T , typename A >
void Serialize ( Stream &  os,
const std::vector< T, A > &  v 
)
inline

Definition at line 996 of file serialize.h.

Here is the call graph for this function:

◆ Serialize() [24/29]

template<typename Stream , typename K , typename T >
void Serialize ( Stream &  os,
const std::pair< K, T > &  item 
)

pair

Definition at line 1028 of file serialize.h.

Here is the call graph for this function:

◆ Serialize() [25/29]

template<typename Stream , typename K , typename T , typename Pred , typename A >
void Serialize ( Stream &  os,
const std::map< K, T, Pred, A > &  m 
)

map

Definition at line 1043 of file serialize.h.

Here is the call graph for this function:

◆ Serialize() [26/29]

template<typename Stream , typename K , typename Pred , typename A >
void Serialize ( Stream &  os,
const std::set< K, Pred, A > &  m 
)

set

Definition at line 1066 of file serialize.h.

Here is the call graph for this function:

◆ Serialize() [27/29]

template<typename Stream , typename T >
void Serialize ( Stream &  os,
const std::shared_ptr< const T > &  p 
)

shared_ptr

Definition at line 1102 of file serialize.h.

Here is the call graph for this function:

◆ Serialize() [28/29]

template<typename Stream , typename T >
void Serialize ( Stream &  os,
const std::unique_ptr< const T > &  p 
)

unique_ptr

Definition at line 1089 of file serialize.h.

Here is the call graph for this function:

◆ Serialize() [29/29]

template<typename Stream , typename T >
void Serialize ( Stream &  os,
const T &  a 
)
inline

If none of the specialized versions above matched, default to calling member function.

Definition at line 877 of file serialize.h.

◆ Serialize_impl() [1/5]

template<typename Stream , unsigned int N, typename T >
void Serialize_impl ( Stream &  os,
const prevector< N, T > &  v,
const uint8_t &   
)

prevector prevectors of uint8_t are a special case and are intended to be serialized as a single opaque blob.

prevector

Definition at line 927 of file serialize.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ Serialize_impl() [2/5]

template<typename Stream , unsigned int N, typename T , typename V >
void Serialize_impl ( Stream &  os,
const prevector< N, T > &  v,
const V &   
)

Definition at line 935 of file serialize.h.

Here is the call graph for this function:

◆ Serialize_impl() [3/5]

template<typename Stream , typename T , typename A >
void Serialize_impl ( Stream &  os,
const std::vector< T, A > &  v,
const uint8_t &   
)

vector vectors of uint8_t are a special case and are intended to be serialized as a single opaque blob.

vector

Definition at line 972 of file serialize.h.

Here is the call graph for this function:

◆ Serialize_impl() [4/5]

template<typename Stream , typename T , typename A >
void Serialize_impl ( Stream &  os,
const std::vector< T, A > &  v,
const bool &   
)

Definition at line 980 of file serialize.h.

Here is the call graph for this function:

◆ Serialize_impl() [5/5]

template<typename Stream , typename T , typename A , typename V >
void Serialize_impl ( Stream &  os,
const std::vector< T, A > &  v,
const V &   
)

Definition at line 991 of file serialize.h.

Here is the call graph for this function:

◆ SerializeMany() [1/2]

template<typename Stream >
void SerializeMany ( Stream &  s)

Definition at line 1157 of file serialize.h.

Here is the caller graph for this function:

◆ SerializeMany() [2/2]

template<typename Stream , typename Arg , typename... Args>
void SerializeMany ( Stream &  s,
const Arg &  arg,
const Args &...  args 
)

Definition at line 1160 of file serialize.h.

Here is the call graph for this function:

◆ SerReadWriteMany() [1/2]

template<typename Stream , typename... Args>
void SerReadWriteMany ( Stream &  s,
CSerActionSerialize  ser_action,
const Args &...  args 
)
inline

Definition at line 1174 of file serialize.h.

Here is the call graph for this function:

◆ SerReadWriteMany() [2/2]

template<typename Stream , typename... Args>
void SerReadWriteMany ( Stream &  s,
CSerActionUnserialize  ser_action,
Args &&...  args 
)
inline

Definition at line 1180 of file serialize.h.

Here is the call graph for this function:

◆ Unserialize() [1/28]

template<typename Stream >
void Unserialize ( Stream &  s,
char &  a 
)
inline

Definition at line 313 of file serialize.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ Unserialize() [2/28]

template<typename Stream >
void Unserialize ( Stream &  s,
int8_t &  a 
)
inline

Definition at line 333 of file serialize.h.

Here is the call graph for this function:

◆ Unserialize() [3/28]

template<typename Stream >
void Unserialize ( Stream &  s,
uint8_t &  a 
)
inline

Definition at line 336 of file serialize.h.

Here is the call graph for this function:

◆ Unserialize() [4/28]

template<typename Stream >
void Unserialize ( Stream &  s,
int16_t &  a 
)
inline

Definition at line 339 of file serialize.h.

Here is the call graph for this function:

◆ Unserialize() [5/28]

template<typename Stream >
void Unserialize ( Stream &  s,
uint16_t &  a 
)
inline

Definition at line 342 of file serialize.h.

Here is the call graph for this function:

◆ Unserialize() [6/28]

template<typename Stream >
void Unserialize ( Stream &  s,
int32_t &  a 
)
inline

Definition at line 345 of file serialize.h.

Here is the call graph for this function:

◆ Unserialize() [7/28]

template<typename Stream >
void Unserialize ( Stream &  s,
uint32_t &  a 
)
inline

Definition at line 348 of file serialize.h.

Here is the call graph for this function:

◆ Unserialize() [8/28]

template<typename Stream >
void Unserialize ( Stream &  s,
int64_t &  a 
)
inline

Definition at line 351 of file serialize.h.

Here is the call graph for this function:

◆ Unserialize() [9/28]

template<typename Stream >
void Unserialize ( Stream &  s,
uint64_t &  a 
)
inline

Definition at line 354 of file serialize.h.

Here is the call graph for this function:

◆ Unserialize() [10/28]

template<typename Stream >
void Unserialize ( Stream &  s,
float &  a 
)
inline

Definition at line 357 of file serialize.h.

Here is the call graph for this function:

◆ Unserialize() [11/28]

template<typename Stream >
void Unserialize ( Stream &  s,
double &  a 
)
inline

Definition at line 360 of file serialize.h.

Here is the call graph for this function:

◆ Unserialize() [12/28]

template<typename Stream , size_t N>
void Unserialize ( Stream &  s,
int8_t(&)  a[N] 
)
inline

Definition at line 364 of file serialize.h.

◆ Unserialize() [13/28]

template<typename Stream , size_t N>
void Unserialize ( Stream &  s,
uint8_t(&)  a[N] 
)
inline

Definition at line 368 of file serialize.h.

Here is the call graph for this function:

◆ Unserialize() [14/28]

template<typename Stream , size_t N>
void Unserialize ( Stream &  s,
std::array< int8_t, N > &  a 
)
inline

Definition at line 372 of file serialize.h.

◆ Unserialize() [15/28]

template<typename Stream , size_t N>
void Unserialize ( Stream &  s,
std::array< uint8_t, N > &  a 
)
inline

Definition at line 376 of file serialize.h.

Here is the call graph for this function:

◆ Unserialize() [16/28]

template<typename Stream , size_t N>
void Unserialize ( Stream &  s,
char(&)  a[N] 
)
inline

Definition at line 381 of file serialize.h.

Here is the call graph for this function:

◆ Unserialize() [17/28]

template<typename Stream , size_t N>
void Unserialize ( Stream &  s,
std::array< char, N > &  a 
)
inline

Definition at line 385 of file serialize.h.

Here is the call graph for this function:

◆ Unserialize() [18/28]

template<typename Stream >
void Unserialize ( Stream &  s,
bool &  a 
)
inline

Definition at line 394 of file serialize.h.

Here is the call graph for this function:

◆ Unserialize() [19/28]

template<typename Stream >
void Unserialize ( Stream &  s,
Span< uint8_t > &  span 
)
inline

Definition at line 399 of file serialize.h.

Here is the call graph for this function:

◆ Unserialize() [20/28]

template<typename Stream , typename C >
void Unserialize ( Stream &  is,
std::basic_string< C > &  str 
)

Definition at line 915 of file serialize.h.

Here is the call graph for this function:

◆ Unserialize() [21/28]

template<typename Stream , unsigned int N, typename T >
void Unserialize ( Stream &  is,
prevector< N, T > &  v 
)
inline

Definition at line 964 of file serialize.h.

Here is the call graph for this function:

◆ Unserialize() [22/28]

template<typename Stream , typename T , typename A >
void Unserialize ( Stream &  is,
std::vector< T, A > &  v 
)
inline

Definition at line 1020 of file serialize.h.

Here is the call graph for this function:

◆ Unserialize() [23/28]

template<typename Stream , typename K , typename T >
void Unserialize ( Stream &  is,
std::pair< K, T > &  item 
)

Definition at line 1034 of file serialize.h.

Here is the call graph for this function:

◆ Unserialize() [24/28]

template<typename Stream , typename K , typename T , typename Pred , typename A >
void Unserialize ( Stream &  is,
std::map< K, T, Pred, A > &  m 
)

Definition at line 1051 of file serialize.h.

Here is the call graph for this function:

◆ Unserialize() [25/28]

template<typename Stream , typename K , typename Pred , typename A >
void Unserialize ( Stream &  is,
std::set< K, Pred, A > &  m 
)

Definition at line 1074 of file serialize.h.

Here is the call graph for this function:

◆ Unserialize() [26/28]

template<typename Stream , typename T >
void Unserialize ( Stream &  os,
std::shared_ptr< const T > &  p 
)

Definition at line 1107 of file serialize.h.

◆ Unserialize() [27/28]

template<typename Stream , typename T >
void Unserialize ( Stream &  os,
std::unique_ptr< const T > &  p 
)

Definition at line 1094 of file serialize.h.

◆ Unserialize() [28/28]

template<typename Stream , typename T >
void Unserialize ( Stream &  is,
T &&  a 
)
inline

Definition at line 882 of file serialize.h.

◆ Unserialize_impl() [1/4]

template<typename Stream , unsigned int N, typename T >
void Unserialize_impl ( Stream &  is,
prevector< N, T > &  v,
const uint8_t &   
)

Definition at line 945 of file serialize.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ Unserialize_impl() [2/4]

template<typename Stream , unsigned int N, typename T , typename V >
void Unserialize_impl ( Stream &  is,
prevector< N, T > &  v,
const V &   
)

Definition at line 959 of file serialize.h.

Here is the call graph for this function:

◆ Unserialize_impl() [3/4]

template<typename Stream , typename T , typename A >
void Unserialize_impl ( Stream &  is,
std::vector< T, A > &  v,
const uint8_t &   
)

Definition at line 1001 of file serialize.h.

Here is the call graph for this function:

◆ Unserialize_impl() [4/4]

template<typename Stream , typename T , typename A , typename V >
void Unserialize_impl ( Stream &  is,
std::vector< T, A > &  v,
const V &   
)

Definition at line 1015 of file serialize.h.

Here is the call graph for this function:

◆ UnserializeMany() [1/2]

template<typename Stream >
void UnserializeMany ( Stream &  s)
inline

Definition at line 1165 of file serialize.h.

Here is the caller graph for this function:

◆ UnserializeMany() [2/2]

template<typename Stream , typename Arg , typename... Args>
void UnserializeMany ( Stream &  s,
Arg &&  arg,
Args &&...  args 
)
inline

Definition at line 1168 of file serialize.h.

Here is the call graph for this function:

◆ Using()

template<typename Formatter , typename T >
static Wrapper<Formatter, T &> Using ( T &&  t)
inlinestatic

Cause serialization/deserialization of an object to be done using a specified formatter class.

To use this, you need a class Formatter that has public functions Ser(stream, const object&) for serialization, and Unser(stream, object&) for deserialization. Serialization routines (inside READWRITE, or directly with << and >> operators), can then use Using<Formatter>(object).

This works by constructing a Wrapper<Formatter, T>-wrapped version of object, where T is const during serialization, and non-const during deserialization, which maintains const correctness.

Definition at line 603 of file serialize.h.

Here is the caller graph for this function:

◆ WrapBigEndian()

template<typename I >
BigEndian<I> WrapBigEndian ( I &  n)

Definition at line 729 of file serialize.h.

Here is the caller graph for this function:

◆ WriteCompactSize() [1/2]

void WriteCompactSize ( CSizeComputer os,
uint64_t  nSize 
)
inline

Definition at line 1189 of file serialize.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ WriteCompactSize() [2/2]

template<typename Stream >
void WriteCompactSize ( Stream &  os,
uint64_t  nSize 
)

Definition at line 426 of file serialize.h.

Here is the call graph for this function:

◆ WriteVarInt() [1/2]

template<typename I >
void WriteVarInt ( CSizeComputer os,
n 
)
inline

Definition at line 1185 of file serialize.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ WriteVarInt() [2/2]

template<typename Stream , VarIntMode Mode, typename I >
void WriteVarInt ( Stream &  os,
n 
)

Definition at line 531 of file serialize.h.

Here is the call graph for this function:

Variable Documentation

◆ deserialize

constexpr deserialize_type deserialize {}

Definition at line 45 of file serialize.h.

◆ MAX_SIZE

const uint64_t MAX_SIZE = 0x02000000
static

Definition at line 26 of file serialize.h.

◆ MAX_VECTOR_ALLOCATE

const unsigned int MAX_VECTOR_ALLOCATE = 5000000
static

Maximum amount of memory (in bytes) to allocate at once when deserializing vectors.

Definition at line 32 of file serialize.h.