Size / write / read for one type T.
More...
#include <StormByte/serializable.hxx>
|
| static std::size_t | Size (const T &data) noexcept |
| | Serialized size of data.
|
| |
| static std::vector< std::byte > | Write (const T &data) noexcept |
| | Encodes data to a little-endian blob.
|
| |
| static Expected< T, DeserializeError > | Read (std::span< const std::byte > data) noexcept |
| | Decodes T from the start of data.
|
| |
template<typename T>
struct StormByte::Detail::Codec< T >
Size / write / read for one type T.
- Template Parameters
-
Primary template is intentionally unusable. Specialize the whole struct (all three members) for a type that is not optional, pair, container or trivially copyable.
template<>
static std::size_t
Size(
const MyType& v)
noexcept;
static std::vector<std::byte>
Write(
const MyType& v)
noexcept;
};
std::conditional_t< Type::Reference< T >, std::expected< std::reference_wrapper< std::remove_reference_t< T > >, std::shared_ptr< E > >, std::expected< T, std::shared_ptr< E > > > Expected
std::expected alias with reference and shared-error handling.
Definition expected.hxx:45
Size / write / read for one type T.
Definition serializable.hxx:96
static std::size_t Size(const T &data) noexcept
Serialized size of data.
Definition serializable.hxx:102
static std::vector< std::byte > Write(const T &data) noexcept
Encodes data to a little-endian blob.
Definition serializable.hxx:114
static Expected< T, DeserializeError > Read(std::span< const std::byte > data) noexcept
Decodes T from the start of data.
Definition serializable.hxx:126
- Note
- The three members must agree with each other.
Size(v) must equal Write(v).size(). Read consumes a prefix of that length; leftover bytes belong to the caller.
◆ Read()
Decodes T from the start of data.
- Parameters
-
| [in] | data | Input span; may be longer than one value. |
- Returns
- Value, or DeserializeError.
◆ Size()
Serialized size of data.
- Parameters
-
| [in] | data | Value to measure. |
- Returns
- Size in bytes.
◆ Write()
Encodes data to a little-endian blob.
- Parameters
-
- Returns
- Blob. No framing beyond what
T itself needs.
The documentation for this struct was generated from the following file: