StormByte 2.0.0
C++26 foundation of the StormByte suite
 
Loading...
Searching...
No Matches
StormByte::Serializable< T > Class Template Reference

Encodes and decodes one value of type T. More...

#include <StormByte/serializable.hxx>

Public Member Functions

 Serializable (const DecayedT &data) noexcept
 Binds data for a later StormByte::Serializable::Serialize.
 
 Serializable (const Serializable &other) noexcept=delete
 Copy is deleted: the wrapper only holds a reference.
 
 Serializable (Serializable &&other) noexcept=delete
 Move is deleted: the wrapper only holds a reference.
 
 ~Serializable () noexcept=default
 Destructor.
 
Serializable & operator= (const Serializable &other) noexcept=delete
 Copy assignment is deleted.
 
Serializable & operator= (Serializable &&other) noexcept=delete
 Move assignment is deleted.
 
BinaryData Serialize () const noexcept
 Encodes the bound value to a little-endian blob.
 

Static Public Member Functions

static Expected< T, DeserializeError > Deserialize (std::span< const std::byte > data) noexcept
 Decodes one T from the start of data.
 
static Expected< T, DeserializeError > Deserialize (const BinaryData &data) noexcept
 Decodes one T from a StormByte::BinaryData.
 
static ByteSize Size (const DecayedT &data) noexcept
 Serialized size of data.
 

Detailed Description

template<typename T>
class StormByte::Serializable< T >

Encodes and decodes one value of type T.

Template Parameters
TType to serialize. Dispatch uses the undecayed T.

Dispatch order is intentional: optional / pair / container run before trivially-copyable. std::optional<U> with trivial U may report is_trivially_copyable and copying its object representation includes padding (observed on MSVC).

Custom types: specialize StormByte::Detail::Codec, then this class routes them through the “complex” path automatically.

The blob is a StormByte::BinaryData. The wire layout is unchanged.

Note
Type::String (string / wstring / u16string / u32string) is excluded from StormByte::Type::Container so those types hit Codec instead of being encoded as a sequence of code units. StormByte::CString and StormByte::WCString are not containers; they hit StormByte::Detail::Codec from the fallback in serializable.txx.

Constructor & Destructor Documentation

◆ Serializable() [1/3]

template<typename T >
StormByte::Serializable< T >::Serializable ( const DecayedT &  data)
inlinenoexcept

Binds data for a later StormByte::Serializable::Serialize.

Parameters
[in]dataValue to encode. Must outlive this object.

◆ Serializable() [2/3]

template<typename T >
StormByte::Serializable< T >::Serializable ( const Serializable< T > &  other)
deletenoexcept

Copy is deleted: the wrapper only holds a reference.

◆ Serializable() [3/3]

template<typename T >
StormByte::Serializable< T >::Serializable ( Serializable< T > &&  other)
deletenoexcept

Move is deleted: the wrapper only holds a reference.

◆ ~Serializable()

template<typename T >
StormByte::Serializable< T >::~Serializable ( )
defaultnoexcept

Destructor.

Member Function Documentation

◆ Deserialize() [1/2]

template<typename T >
static Expected< T, DeserializeError > StormByte::Serializable< T >::Deserialize ( const BinaryData &  data)
staticnoexcept

Decodes one T from a StormByte::BinaryData.

Parameters
[in]dataInput blob.
Returns
Value, or StormByte::DeserializeError.

◆ Deserialize() [2/2]

template<typename T >
static Expected< T, DeserializeError > StormByte::Serializable< T >::Deserialize ( std::span< const std::byte >  data)
staticnoexcept

Decodes one T from the start of data.

Parameters
[in]dataInput span; may be longer than one value.
Returns
Value, or StormByte::DeserializeError.

◆ operator=() [1/2]

template<typename T >
Serializable & StormByte::Serializable< T >::operator= ( const Serializable< T > &  other)
deletenoexcept

Copy assignment is deleted.

◆ operator=() [2/2]

template<typename T >
Serializable & StormByte::Serializable< T >::operator= ( Serializable< T > &&  other)
deletenoexcept

Move assignment is deleted.

◆ Serialize()

template<typename T >
BinaryData StormByte::Serializable< T >::Serialize ( ) const
noexcept

Encodes the bound value to a little-endian blob.

Returns
Blob for this one value, owned by Base. No outer framing.

◆ Size()

template<typename T >
static ByteSize StormByte::Serializable< T >::Size ( const DecayedT &  data)
staticnoexcept

Serialized size of data.

Parameters
[in]dataValue to measure.
Returns
ByteSize of StormByte::Serializable::Serialize for the same value.

The documentation for this class was generated from the following file: