| Formatter for integers in CompactSize
| format.
|
| Serialization wrapper class for custom
| integers and enums.
|
| It permits specifying the serialized
| size (1 to 8 bytes) and endianness.
|
| Use the big endian mode for values that
| are stored in memory in native byte order,
| but serialized in big endian notation.
| This is only intended to implement serializers
| that are compatible with existing formats,
| and its use is not recommended for new
| data structures.
|
| If none of the specialized versions
| above matched, default to calling member
| function.
|
| Support for SERIALIZE_METHODS and
| READWRITE macro.
|
| ::GetSerializeSize implementations
|
| Computing the serialized size of objects
| is done through a special stream object
| of type CSizeComputer, which only records
| the number of bytes written to it.
|
| If your Serialize or SerializationOp
| method has non-trivial overhead for
| serialization, it may be worthwhile
| to implement a specialized version
| for
|
| CSizeComputer, which uses the s.seek()
| method to record bytes that would be
| written instead.
|
| Serialization wrapper class for integers
| in VarInt format.
|
| Formatter to serialize/deserialize
| vector elements using another formatter
|
| Example:
|
| ———–
| @code
|
| struct X {
| std::vector<uint64_t> v;
| SERIALIZE_METHODS(X, obj) { READWRITE(Using<VectorFormatter>(obj.v)); }
| };
|
| will define a struct that contains a
| vector of uint64_t, which is serialized
| as a vector of VarInt-encoded integers.
|
| V is not required to be an std::vector
| type. It works for any class that exposes
| a value_type, size, reserve, emplace_back,
| back, and const iterators.
|
| Simple wrapper class to serialize objects
| using a formatter; used by Using().
|
| Safely convert odd char pointer types
| to standard ones.
|
| 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)
|
| Map a value x that is uniformly distributed in
| the range [0, 2^64) to a value uniformly
| distributed in [0, n) by returning the upper 64
| bits of x * n.
|
| See:
| https://lemire.me/blog/2016/06/27/a-fast-alternative-to-the-modulo-reduction/
| 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.
|
| Convert the reference base type to X,
| without changing constness or reference
| type.
|
| Lowest-level serialization and conversion.
|
| ———–
| @note
|
| Sizes of these types are verified in
| the tests
|
| 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(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.
|