Bitcoin Core  27.99.0
P2P Digital Currency
Classes | Macros | Typedefs | Enumerations | Functions | Variables
serialize.h File Reference
#include <attributes.h>
#include <compat/assumptions.h>
#include <compat/endian.h>
#include <prevector.h>
#include <span.h>
#include <algorithm>
#include <concepts>
#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:

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, BigEndian >
 Serialization wrapper class for custom integers and enums. More...
 
struct  CompactSizeFormatter< RangeCheck >
 Formatter for integers in CompactSize format. More...
 
struct  ChronoFormatter< U, LOSSY >
 
class  CompactSizeWriter
 
struct  LimitedStringFormatter< Limit >
 
struct  VectorFormatter< Formatter >
 Formatter to serialize/deserialize vector elements using another formatter. More...
 
struct  DefaultFormatter
 Default formatter. More...
 
struct  ActionSerialize
 Support for all macros providing or using the ser_action parameter of the SerializationOps method. More...
 
struct  ActionUnserialize
 
class  SizeComputer
 
class  ParamsStream< Params, SubStream >
 Wrapper that overrides the GetParams() function of a stream (and hides GetVersion/GetType). More...
 
class  ParamsWrapper< Params, T >
 Wrapper that serializes objects with the specified parameters. More...
 

Macros

#define READWRITE(...)   (ser_action.SerReadWriteMany(s, __VA_ARGS__))
 
#define SER_READ(obj, code)   ser_action.SerRead(s, obj, [&](Stream& s, typename std::remove_const<Type>::type& obj) { code; })
 
#define SER_WRITE(obj, code)   ser_action.SerWrite(s, obj, [&](Stream& s, const Type& obj) { code; })
 
#define FORMATTER_METHODS(cls, obj)
 Implement the Ser and Unser methods needed for implementing a formatter (see Using below). More...
 
#define FORMATTER_METHODS_PARAMS(cls, obj, paramcls, paramobj)
 Variant of FORMATTER_METHODS that supports a declared parameter type. More...
 
#define BASE_SERIALIZE_METHODS(cls)
 
#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 SERIALIZE_METHODS_PARAMS(cls, obj, paramcls, paramobj)
 Variant of SERIALIZE_METHODS that supports a declared parameter type. More...
 
#define VARINT_MODE(obj, mode)   Using<VarIntFormatter<mode>>(obj)
 
#define VARINT(obj)   Using<VarIntFormatter<VarIntMode::DEFAULT>>(obj)
 
#define COMPACTSIZE(obj)   Using<CompactSizeFormatter<true>>(obj)
 
#define LIMITED_STRING(obj, n)   Using<LimitedStringFormatter<n>>(obj)
 
#define SER_PARAMS_OPFUNC
 Helper macro for SerParams structs. More...
 

Typedefs

template<int Bytes>
using BigEndianFormatter = CustomUintFormatter< Bytes, true >
 
template<typename U >
using LossyChronoFormatter = ChronoFormatter< U, true >
 

Enumerations

enum class  VarIntMode { DEFAULT , NONNEGATIVE_SIGNED }
 Variable-length integers: bytes are a MSB base-128 encoding of the number. More...
 

Functions

template<typename Stream >
void ser_writedata8 (Stream &s, uint8_t obj)
 
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)
 
template<class Out , class In >
Out & AsBase (In &x)
 Convert any argument to a reference to X, maintaining constness. More...
 
template<class Out , class In >
const Out & AsBase (const In &x)
 
template<typename Stream , CharNotInt8 V>
void Serialize (Stream &, V)=delete
 
template<typename Stream >
void Serialize (Stream &s, std::byte 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 , BasicByte B, int N>
void Serialize (Stream &s, const B(&a)[N])
 
template<typename Stream , BasicByte B, std::size_t N>
void Serialize (Stream &s, const std::array< B, N > &a)
 
template<typename Stream , BasicByte B>
void Serialize (Stream &s, Span< B > span)
 
template<typename Stream , CharNotInt8 V>
void Unserialize (Stream &, V)=delete
 
template<typename Stream >
void Unserialize (Stream &s, std::byte &a)
 
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 , BasicByte B, int N>
void Unserialize (Stream &s, B(&a)[N])
 
template<typename Stream , BasicByte B, std::size_t N>
void Unserialize (Stream &s, std::array< B, N > &a)
 
template<typename Stream , BasicByte B>
void Unserialize (Stream &s, Span< B > span)
 
template<typename Stream >
void Serialize (Stream &s, bool a)
 
template<typename Stream >
void Unserialize (Stream &s, bool &a)
 
constexpr unsigned int 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 (SizeComputer &os, uint64_t nSize)
 
template<typename Stream >
void WriteCompactSize (Stream &os, uint64_t nSize)
 
template<typename Stream >
uint64_t ReadCompactSize (Stream &is, bool range_check=true)
 Decode a CompactSize-encoded variable-length integer. More...
 
template<VarIntMode Mode, typename I >
unsigned int GetSizeOfVarInt (I n)
 
template<typename I >
void WriteVarInt (SizeComputer &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 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 (Stream &os, const prevector< N, T > &v)
 prevector More...
 
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 (Stream &os, const std::vector< T, A > &v)
 vector More...
 
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 >
requires Serializable< T, Stream > void Serialize (Stream &os, const T &a)
 
template<typename Stream , typename T >
requires Unserializable< T, Stream > void Unserialize (Stream &is, T &&a)
 
template<typename Stream , typename... Args>
void SerializeMany (Stream &s, const Args &... args)
 Support for (un)serializing many things at once. More...
 
template<typename Stream , typename... Args>
void UnserializeMany (Stream &s, Args &&... args)
 
template<typename T >
size_t GetSerializeSize (const T &t)
 

Variables

static constexpr uint64_t MAX_SIZE = 0x02000000
 The maximum size of a serialized object in bytes or number of elements (for eg vectors) when the size is encoded as CompactSize. More...
 
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 {}
 
template<class T >
concept CharNotInt8 = std::same_as<T, char> && !std::same_as<T, int8_t>
 
template<class T , class Stream >
concept Serializable = requires(T a, Stream s) { a.Serialize(s); }
 If none of the specialized versions above matched, default to calling member function. More...
 
template<class T , class Stream >
concept Unserializable = requires(T a, Stream s) { a.Unserialize(s); }
 

Macro Definition Documentation

◆ BASE_SERIALIZE_METHODS

#define BASE_SERIALIZE_METHODS (   cls)
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); \
}
void Serialize(Stream &, V)=delete
void Unserialize(Stream &, V)=delete

Definition at line 225 of file serialize.h.

◆ COMPACTSIZE

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

Definition at line 514 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, ActionSerialize{}); } \
template<typename Stream> \
static void Unser(Stream& s, cls& obj) { SerializationOps(obj, s, ActionUnserialize{}); } \
template<typename Stream, typename Type, typename Operation> \
static void SerializationOps(Type& obj, Stream& s, Operation ser_action)
Support for all macros providing or using the ser_action parameter of the SerializationOps method.
Definition: serialize.h:1021

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 176 of file serialize.h.

◆ FORMATTER_METHODS_PARAMS

#define FORMATTER_METHODS_PARAMS (   cls,
  obj,
  paramcls,
  paramobj 
)
Value:
template <typename Stream> \
static void Ser(Stream& s, const cls& obj) { SerializationOps(obj, s, ActionSerialize{}, s.GetParams()); } \
template <typename Stream> \
static void Unser(Stream& s, cls& obj) { SerializationOps(obj, s, ActionUnserialize{}, s.GetParams()); } \
template <typename Stream, typename Type, typename Operation> \
static void SerializationOps(Type& obj, Stream& s, Operation ser_action, const paramcls& paramobj)

Variant of FORMATTER_METHODS that supports a declared parameter type.

If a formatter has a declared parameter type, it must be invoked directly or indirectly with a parameter of that type. This permits making serialization depend on run-time context in a type-safe way.

Example use: struct BarParameter { bool fancy; ... }; struct Bar { ... }; struct FooFormatter { FORMATTER_METHODS(Bar, obj, BarParameter, param) { if (param.fancy) { READWRITE(VARINT(obj.value)); } else { READWRITE(obj.value); } } }; which would then be invoked as READWRITE(BarParameter{...}(Using<FooFormatter>(obj.foo)))

parameter(obj) can be invoked anywhere in the call stack; it is passed down recursively into all serialization code, until another serialization parameter overrides it.

Parameters will be implicitly converted where appropriate. This means that "parent" serialization code can use a parameter that derives from, or is convertible to, a "child" formatter's parameter type.

Compilation will fail in any context where serialization is invoked but no parameter of a type convertible to BarParameter is provided.

Definition at line 217 of file serialize.h.

◆ LIMITED_STRING

#define LIMITED_STRING (   obj,
 
)    Using<LimitedStringFormatter<n>>(obj)

Definition at line 515 of file serialize.h.

◆ READWRITE

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

Definition at line 156 of file serialize.h.

◆ SER_PARAMS_OPFUNC

#define SER_PARAMS_OPFUNC
Value:
\
template <typename T> \
auto operator()(T&& t) const \
{ \
return ParamsWrapper{*this, t}; \
}
Wrapper that serializes objects with the specified parameters.
Definition: serialize.h:1145

Helper macro for SerParams structs.

Allows you define SerParams instances and then apply them directly to an object via function call syntax, eg:

constexpr SerParams FOO{....}; ss << FOO(obj);

Definition at line 1175 of file serialize.h.

◆ SER_READ

#define SER_READ (   obj,
  code 
)    ser_action.SerRead(s, obj, [&](Stream& s, typename std::remove_const<Type>::type& obj) { code; })

Definition at line 157 of file serialize.h.

◆ SER_WRITE

#define SER_WRITE (   obj,
  code 
)    ser_action.SerWrite(s, obj, [&](Stream& s, const Type& obj) { code; })

Definition at line 158 of file serialize.h.

◆ SERIALIZE_METHODS

#define SERIALIZE_METHODS (   cls,
  obj 
)
Value:
FORMATTER_METHODS(cls, obj)
#define BASE_SERIALIZE_METHODS(cls)
Definition: serialize.h:225

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.

◆ SERIALIZE_METHODS_PARAMS

#define SERIALIZE_METHODS_PARAMS (   cls,
  obj,
  paramcls,
  paramobj 
)
Value:
FORMATTER_METHODS_PARAMS(cls, obj, paramcls, paramobj)

Variant of SERIALIZE_METHODS that supports a declared parameter type.

See FORMATTER_METHODS_PARAMS for more information on parameters.

Definition at line 255 of file serialize.h.

◆ VARINT

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

Definition at line 513 of file serialize.h.

◆ VARINT_MODE

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

Definition at line 512 of file serialize.h.

Typedef Documentation

◆ BigEndianFormatter

template<int Bytes>
using BigEndianFormatter = CustomUintFormatter<Bytes, true>

Definition at line 574 of file serialize.h.

◆ LossyChronoFormatter

template<typename U >
using LossyChronoFormatter = ChronoFormatter<U, true>

Definition at line 621 of file serialize.h.

Enumeration Type Documentation

◆ 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 418 of file serialize.h.

Function Documentation

◆ AsBase() [1/2]

template<class Out , class In >
const Out& AsBase ( const In &  x)

Definition at line 150 of file serialize.h.

◆ AsBase() [2/2]

template<class Out , class In >
Out& AsBase ( In &  x)

Convert any argument to a reference to X, maintaining constness.

This can be used in serialization code to invoke a base class's serialization routines.

Example use: class Base { ... }; class Child : public Base { int m_data; public: SERIALIZE_METHODS(Child, obj) { READWRITE(AsBase<Base>(obj), obj.m_data); } };

static_cast cannot easily be used here, as the type of Obj will be const Child& during serialization and Child& during deserialization. AsBase will convert to const Base& and Base& appropriately.

Definition at line 144 of file serialize.h.

◆ GetSerializeSize()

template<typename T >
size_t GetSerializeSize ( const T &  t)

Definition at line 1116 of file serialize.h.

Here is the caller graph for this function:

◆ GetSizeOfCompactSize()

constexpr unsigned int GetSizeOfCompactSize ( uint64_t  nSize)
inlineconstexpr

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 310 of file serialize.h.

Here is the caller graph for this function:

◆ GetSizeOfVarInt()

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

Definition at line 430 of file serialize.h.

◆ ReadCompactSize()

template<typename Stream >
uint64_t ReadCompactSize ( Stream &  is,
bool  range_check = true 
)

Decode a CompactSize-encoded variable-length integer.

As these are primarily used to encode the size of vector-like serializations, by default a range check is performed. When used as a generic number encoding, range_check should be set to false.

Definition at line 352 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 465 of file serialize.h.

Here is the call graph for this function:

◆ ser_readdata16()

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

Definition at line 89 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 95 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 101 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 107 of file serialize.h.

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

◆ ser_readdata64()

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

Definition at line 113 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 83 of file serialize.h.

Here is the call graph for this function:
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 58 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 63 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 68 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 73 of file serialize.h.

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

◆ ser_writedata64()

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

Definition at line 78 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

Definition at line 54 of file serialize.h.

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

◆ Serialize() [1/23]

template<typename Stream , CharNotInt8 V>
void Serialize ( Stream &  ,
 
)
delete
Here is the caller graph for this function:

◆ Serialize() [2/23]

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

prevector

Definition at line 823 of file serialize.h.

Here is the call graph for this function:

◆ Serialize() [3/23]

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

Forward declarations.

string

Definition at line 801 of file serialize.h.

Here is the call graph for this function:

◆ Serialize() [4/23]

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 920 of file serialize.h.

Here is the call graph for this function:

◆ Serialize() [5/23]

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

pair

Definition at line 901 of file serialize.h.

Here is the call graph for this function:

◆ Serialize() [6/23]

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

set

Definition at line 947 of file serialize.h.

Here is the call graph for this function:

◆ Serialize() [7/23]

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

shared_ptr

Definition at line 991 of file serialize.h.

Here is the call graph for this function:

◆ Serialize() [8/23]

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

unique_ptr

Definition at line 974 of file serialize.h.

Here is the call graph for this function:

◆ Serialize() [9/23]

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

vector

Definition at line 858 of file serialize.h.

Here is the call graph for this function:

◆ Serialize() [10/23]

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

Definition at line 765 of file serialize.h.

◆ Serialize() [11/23]

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

Definition at line 298 of file serialize.h.

Here is the call graph for this function:

◆ Serialize() [12/23]

template<typename Stream , BasicByte B, int N>
void Serialize ( Stream &  s,
const B(&)  a[N] 
)

Definition at line 280 of file serialize.h.

Here is the call graph for this function:

◆ Serialize() [13/23]

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

Definition at line 281 of file serialize.h.

Here is the call graph for this function:

◆ Serialize() [14/23]

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

Definition at line 274 of file serialize.h.

Here is the call graph for this function:

◆ Serialize() [15/23]

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

Definition at line 276 of file serialize.h.

Here is the call graph for this function:

◆ Serialize() [16/23]

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

Definition at line 278 of file serialize.h.

Here is the call graph for this function:

◆ Serialize() [17/23]

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

Definition at line 272 of file serialize.h.

Here is the call graph for this function:

◆ Serialize() [18/23]

template<typename Stream , BasicByte B>
void Serialize ( Stream &  s,
Span< B span 
)

Definition at line 282 of file serialize.h.

Here is the call graph for this function:

◆ Serialize() [19/23]

template<typename Stream >
void Serialize ( Stream &  s,
std::byte  a 
)

Definition at line 271 of file serialize.h.

Here is the call graph for this function:

◆ Serialize() [20/23]

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

Definition at line 275 of file serialize.h.

Here is the call graph for this function:

◆ Serialize() [21/23]

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

Definition at line 277 of file serialize.h.

Here is the call graph for this function:

◆ Serialize() [22/23]

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

Definition at line 279 of file serialize.h.

Here is the call graph for this function:

◆ Serialize() [23/23]

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

Definition at line 273 of file serialize.h.

Here is the call graph for this function:

◆ SerializeMany()

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

Support for (un)serializing many things at once.

Definition at line 1007 of file serialize.h.

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

◆ Unserialize() [1/23]

template<typename Stream , CharNotInt8 V>
void Unserialize ( Stream &  ,
 
)
delete
Here is the caller graph for this function:

◆ Unserialize() [2/23]

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

Definition at line 835 of file serialize.h.

Here is the call graph for this function:

◆ Unserialize() [3/23]

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

Definition at line 809 of file serialize.h.

Here is the call graph for this function:

◆ Unserialize() [4/23]

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 928 of file serialize.h.

Here is the call graph for this function:

◆ Unserialize() [5/23]

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

Definition at line 908 of file serialize.h.

Here is the call graph for this function:

◆ Unserialize() [6/23]

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

Definition at line 955 of file serialize.h.

Here is the call graph for this function:

◆ Unserialize() [7/23]

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

Definition at line 878 of file serialize.h.

Here is the call graph for this function:

◆ Unserialize() [8/23]

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

Definition at line 774 of file serialize.h.

◆ Unserialize() [9/23]

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

Definition at line 997 of file serialize.h.

◆ Unserialize() [10/23]

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

Definition at line 980 of file serialize.h.

◆ Unserialize() [11/23]

template<typename Stream , BasicByte B, int N>
void Unserialize ( Stream &  s,
B(&)  a[N] 
)

Definition at line 294 of file serialize.h.

Here is the call graph for this function:

◆ Unserialize() [12/23]

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

Definition at line 299 of file serialize.h.

Here is the call graph for this function:

◆ Unserialize() [13/23]

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

Definition at line 288 of file serialize.h.

Here is the call graph for this function:

◆ Unserialize() [14/23]

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

Definition at line 290 of file serialize.h.

Here is the call graph for this function:

◆ Unserialize() [15/23]

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

Definition at line 292 of file serialize.h.

Here is the call graph for this function:

◆ Unserialize() [16/23]

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

Definition at line 286 of file serialize.h.

Here is the call graph for this function:

◆ Unserialize() [17/23]

template<typename Stream , BasicByte B>
void Unserialize ( Stream &  s,
Span< B span 
)

Definition at line 296 of file serialize.h.

Here is the call graph for this function:

◆ Unserialize() [18/23]

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

Definition at line 295 of file serialize.h.

Here is the call graph for this function:

◆ Unserialize() [19/23]

template<typename Stream >
void Unserialize ( Stream &  s,
std::byte &  a 
)

Definition at line 285 of file serialize.h.

Here is the call graph for this function:

◆ Unserialize() [20/23]

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

Definition at line 289 of file serialize.h.

Here is the call graph for this function:

◆ Unserialize() [21/23]

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

Definition at line 291 of file serialize.h.

Here is the call graph for this function:

◆ Unserialize() [22/23]

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

Definition at line 293 of file serialize.h.

Here is the call graph for this function:

◆ Unserialize() [23/23]

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

Definition at line 287 of file serialize.h.

Here is the call graph for this function:

◆ UnserializeMany()

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

Definition at line 1013 of file serialize.h.

Here is the call graph for this function:
Here is the caller 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 510 of file serialize.h.

Here is the caller graph for this function:

◆ WriteCompactSize() [1/2]

void WriteCompactSize ( SizeComputer os,
uint64_t  nSize 
)
inline

Definition at line 1110 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 321 of file serialize.h.

Here is the call graph for this function:

◆ WriteVarInt() [1/2]

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

Definition at line 1105 of file serialize.h.

Here is the call graph for this function:

◆ WriteVarInt() [2/2]

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

Definition at line 447 of file serialize.h.

Here is the call graph for this function:

Variable Documentation

◆ CharNotInt8

template<class T >
concept CharNotInt8 = std::same_as<T, char> && !std::same_as<T, int8_t>

Definition at line 268 of file serialize.h.

◆ deserialize

constexpr deserialize_type deserialize {}
constexpr

Definition at line 49 of file serialize.h.

◆ MAX_SIZE

constexpr uint64_t MAX_SIZE = 0x02000000
staticconstexpr

The maximum size of a serialized object in bytes or number of elements (for eg vectors) when the size is encoded as CompactSize.

Definition at line 32 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 35 of file serialize.h.

◆ Serializable

template<class T , class Stream >
concept Serializable = requires(T a, Stream s) { a.Serialize(s); }

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

Definition at line 762 of file serialize.h.

◆ Unserializable

template<class T , class Stream >
concept Unserializable = requires(T a, Stream s) { a.Unserialize(s); }

Definition at line 771 of file serialize.h.