Devel Lib
Devel::Serializing Namespace Reference

The namespace encapsulating serializing related functionality in the Devel framework. More...

Classes

struct  SCompareData
 Structure for comparing serialized data. More...
 
class  IStruct
 
class  IField
 Base class for fields. More...
 
class  IValue
 Template class representing a value. More...
 
class  IData
 Template class representing a data field. More...
 
class  IArithmetic
 Class representing an arithmetic value for serialization. More...
 
class  IBool
 A class representing a boolean value for serialization. More...
 
class  ICharArray
 A class representing a fixed-size character array for serialization. More...
 
class  IString
 A class representing a string value for serialization. More...
 
class  IVector
 A class representing a vector for serialization. More...
 
class  IWString
 A class representing a wide string value for serialization. More...
 
class  CJsonFieldName
 A class representing a JSON field name. More...
 
class  IJsonType
 Represents a JSON data type with serialization and deserialization functionality. More...
 
class  IJsonArray
 Represents a JSON array of a specific type. More...
 
class  IJsonBool
 Represents a JSON boolean data type for serialization and deserialization. More...
 
class  IJsonNumber
 Represents a JSON number data type and provides serialization and deserialization functionality for arithmetic types. More...
 
class  IJsonString
 Represents a JSON string data type and provides serialization and deserialization functionality. More...
 
class  IJsonStruct
 Represents a JSON structure data type and provides serialization and deserialization functionality. More...
 

Typedefs

template<typename T >
using is_data_class = decltype(is_data_class_impl(std::declval< T * >()))
 
template<bool IsHidden = false>
using IChar = IArithmetic< char, IsHidden >
 Alias for IArithmetic<char> representing a character value.
 
template<bool IsHidden = false>
using IByte = IArithmetic< byte, IsHidden >
 Alias for IArithmetic<byte> representing a byte value.
 
template<bool IsHidden = false>
using IShort = IArithmetic< short, IsHidden >
 Alias for IArithmetic<short> representing a short integer value.
 
template<bool IsHidden = false>
using IUShort = IArithmetic< ushort, IsHidden >
 Alias for IArithmetic<ushort> representing an unsigned short integer value.
 
template<bool IsHidden = false>
using IInt = IArithmetic< int, IsHidden >
 Alias for IArithmetic<int> representing an integer value.
 
template<bool IsHidden = false>
using IUInt = IArithmetic< uint, IsHidden >
 Alias for IArithmetic<uint> representing an unsigned integer value.
 
template<bool IsHidden = false>
using IInt64 = IArithmetic< int64, IsHidden >
 Alias for IArithmetic<int64> representing a 64-bit integer value.
 
template<bool IsHidden = false>
using IUInt64 = IArithmetic< uint64, IsHidden >
 Alias for IArithmetic<int64> representing a 64-bit integer value.
 
template<typename T , bool IsHidden = false>
using IEnum = Devel::Serializing::IArithmetic< T, IsHidden >
 Alias for IArithmetic representing an enumeration value.
 
template<typename T >
using is_json_type_class = decltype(is_json_type_class_impl(std::declval< T * >()))
 Checks if a type is a JSON type class. More...
 
typedef IJsonNumber< char > IJsonChar
 Typedef for IJsonNumber<char>
 
typedef IJsonNumber< byteIJsonByte
 Typedef for IJsonNumber<byte>.
 
typedef IJsonNumber< short > IJsonShort
 Typedef for IJsonNumber<short>.
 
typedef IJsonNumber< ushortIJsonUShort
 Typedef for IJsonNumber<ushort>.
 
typedef IJsonNumber< int > IJsonInt
 Typedef for IJsonNumber<int>.
 
typedef IJsonNumber< uintIJsonUInt
 Typedef for IJsonNumber<uint>.
 
typedef IJsonNumber< int64IJsonInt64
 Typedef for IJsonNumber<int64>.
 
typedef IJsonNumber< uint64IJsonUInt64
 Typedef for IJsonNumber<uint64>.
 
typedef IJsonNumber< float > IJsonFloat
 Typedef for IJsonNumber<float>.
 
typedef IJsonNumber< double > IJsonDouble
 Typedef for IJsonNumber<double>.
 

Functions

template<typename T >
std::ostream & operator<< (std::ostream &i_oStream, const IValue< T > &i_tData)
 Output stream operator for IValue. More...
 
template<typename T >
std::istream & operator>> (std::istream &i_oStream, const IValue< T > &i_tData)
 Input stream operator for IValue. More...
 
template<typename T >
std::wostream & operator<< (std::wostream &i_oStream, const IValue< T > &i_tData)
 Wide output stream operator for IValue. More...
 
template<typename T >
std::wistream & operator>> (std::wistream &i_oStream, const IValue< T > &i_tData)
 Wide input stream operator for IValue. More...
 
template<typename TStructFieldType = IData<>, typename TStruct >
bool IterateSerializableStruct (const TStruct *i_pStruct, std::function< bool(const TStructFieldType *)> i_pCallback, const size_t i_nStructSize=sizeof(TStruct))
 Iterates over a serializable struct and applies a callback function to each field. More...
 
template<typename TStructFieldType = IData<>, typename TStruct >
bool IterateSerializableStruct (const TStruct &i_oStruct, std::function< bool(const TStructFieldType *)> i_pCallback, const size_t i_nStructSize=sizeof(TStruct))
 Iterates over a serializable struct and applies a callback function to each field. More...
 
template<typename TStructFieldType = IData<>, typename TStruct >
bool IterateDeserializableStruct (TStruct *i_pStruct, std::function< bool(TStructFieldType *)> i_pCallback, const size_t i_nStructSize=sizeof(TStruct))
 Iterates over a deserializable struct and applies a callback function to each field. More...
 
template<typename TStructFieldType = IData<>, typename TStruct >
bool IterateDeserializableStruct (TStruct &i_oStruct, std::function< bool(TStructFieldType *)> i_pCallback, const size_t i_nStructSize=sizeof(TStruct))
 Iterates over a deserializable struct and applies a callback function to each field. More...
 
template<typename TStructFieldType = IData<>, typename TStruct >
std::vector< size_t > GetSerializableFieldOffsets (const TStruct *i_pStruct, const bool i_fIncludeHidden=true, const size_t i_nStructSize=sizeof(TStruct))
 Gets the offsets of the serializable fields in a struct. More...
 
template<typename TStructFieldType = IData<>, typename TStruct >
std::vector< size_t > GetSerializableFieldOffsets (const TStruct &i_oStruct, const bool i_fIncludeHidden=true, const size_t i_nStructSize=sizeof(TStruct))
 Gets the offsets of the serializable fields in a struct. More...
 
template<typename TStructFieldType = IData<>, typename TStruct >
TStructFieldType * GetSerializableFieldByIndex (const TStruct *i_pStruct, const size_t i_nIndex)
 Gets the offsets of the serializable fields in a struct. More...
 
template<typename TStructFieldType = IData<>, typename TStruct >
TStructFieldType * GetSerializableFieldByIndex (const TStruct &i_oStruct, const size_t i_nIndex)
 Gets a serializable field in a struct by index. More...
 
template<typename TStructFieldType = IData<>, typename TStruct >
bool CompareSerializableStruct (TStruct *i_pStruct, TStruct *i_pCompareStruct, const bool i_fIncludeHidden=false)
 Compares two serializable structs for equality. More...
 
template<typename TStructFieldType = IData<>, typename TStruct >
bool CompareSerializableStruct (TStruct &i_oStruct, TStruct &i_oCompareStruct, const bool i_fIncludeHidden=false)
 Compares two serializable structs for equality. More...
 
std::false_type is_data_class_impl (...)
 Check if a type is a data class. More...
 
template<typename T = int, bool IsHidden = false>
std::true_type is_data_class_impl (IData< T, IsHidden > *)
 
template<typename T >
bool SerializeStream (const T &i_oStruct, IO::CWriteStream &i_oStream)
 Serializes a struct to a write stream. More...
 
template<typename T >
bool DeserializeStream (T &i_oStruct, IO::CReadStream &i_oStream, size_t i_nStructSize=sizeof(T))
 Deserializes a struct from a read stream. More...
 
template<typename TField , typename TStruct >
TField * GetJsonFieldByName (TStruct &i_oStruct, const std::string_view i_sName)
 Retrieves a JSON field by name from a struct. More...
 
std::false_type is_json_type_class_impl (...)
 
template<typename T = int, typename TData = IData<T>>
std::true_type is_json_type_class_impl (IJsonType< T, TData > *)
 
template<typename T >
bool DeserializeObject (T &i_oStruct, IO::CJsonObject &i_oObject, const bool i_bIsStrict=false, size_t i_nStructSize=sizeof(T))
 Deserializes a JSON object into a struct. More...
 
template<typename T >
bool DeserializeDocument (T &i_oStruct, IO::CJsonDocument &i_oDocument, const bool i_bIsStrict=false, size_t i_nStructSize=sizeof(T))
 Deserializes a JSON document into a struct. More...
 
template<typename T >
bool SerializeObject (const T &i_oStruct, IO::CJsonObject &i_oObject, const bool i_bIsStrict=false, size_t i_nStructSize=sizeof(T))
 Serializes a struct into a JSON object. More...
 
template<typename T >
bool SerializeDocument (const T &i_oStruct, IO::CJsonDocument &i_oDocument, const bool i_bIsStrict=false, size_t i_nStructSize=sizeof(T))
 Serializes a struct into a JSON document. More...
 

Detailed Description

The namespace encapsulating serializing related functionality in the Devel framework.

Typedef Documentation

◆ is_json_type_class

template<typename T >
using Devel::Serializing::is_json_type_class = typedef decltype(is_json_type_class_impl(std::declval<T *>()))

Checks if a type is a JSON type class.

Template Parameters
TThe type to check.

Function Documentation

◆ CompareSerializableStruct() [1/2]

template<typename TStructFieldType = IData<>, typename TStruct >
bool Devel::Serializing::CompareSerializableStruct ( TStruct &  i_oStruct,
TStruct &  i_oCompareStruct,
const bool  i_fIncludeHidden = false 
)

Compares two serializable structs for equality.

Template Parameters
TStructFieldTypeThe type of the struct field.
TStructThe type of the struct.
Parameters
i_oStructThe first struct object.
i_oCompareStructThe second struct object.
i_fIncludeHiddenFlag indicating whether to include hidden fields in the comparison.
Returns
true if the structs are equal, false otherwise.

◆ CompareSerializableStruct() [2/2]

template<typename TStructFieldType = IData<>, typename TStruct >
bool Devel::Serializing::CompareSerializableStruct ( TStruct *  i_pStruct,
TStruct *  i_pCompareStruct,
const bool  i_fIncludeHidden = false 
)

Compares two serializable structs for equality.

Template Parameters
TStructFieldTypeThe type of the struct field.
TStructThe type of the struct.
Parameters
i_pStructPointer to the first struct object.
i_pCompareStructPointer to the second struct object.
i_fIncludeHiddenFlag indicating whether to include hidden fields in the comparison.
Returns
true if the structs are equal, false otherwise.

◆ DeserializeDocument()

template<typename T >
bool Devel::Serializing::DeserializeDocument ( T &  i_oStruct,
IO::CJsonDocument i_oDocument,
const bool  i_bIsStrict = false,
size_t  i_nStructSize = sizeof(T) 
)

Deserializes a JSON document into a struct.

Template Parameters
TThe type of the struct.
Parameters
i_oStructThe struct to deserialize into.
i_oDocumentThe JSON document to deserialize.
i_bIsStrictDetermines if strict deserialization should be used.
i_nStructSizeThe size of the struct in bytes.
Returns
True if deserialization is successful, false otherwise.

◆ DeserializeObject()

template<typename T >
bool Devel::Serializing::DeserializeObject ( T &  i_oStruct,
IO::CJsonObject i_oObject,
const bool  i_bIsStrict = false,
size_t  i_nStructSize = sizeof(T) 
)

Deserializes a JSON object into a struct.

Template Parameters
TThe type of the struct.
Parameters
i_oStructThe struct to deserialize into.
i_oObjectThe JSON object to deserialize.
i_bIsStrictDetermines if strict deserialization should be used.
i_nStructSizeThe size of the struct in bytes.
Returns
True if deserialization is successful, false otherwise.

◆ DeserializeStream()

template<typename T >
bool Devel::Serializing::DeserializeStream ( T &  i_oStruct,
IO::CReadStream i_oStream,
size_t  i_nStructSize = sizeof(T) 
)

Deserializes a struct from a read stream.

Template Parameters
TThe type of the struct.
Parameters
i_oStructThe struct object to deserialize into.
i_oStreamThe read stream to deserialize from.
i_nStructSizeThe size of the struct in bytes.
Returns
true if deserialization was successful, false otherwise.
Exceptions
TooLessDataInPacketExceptionIf there is not enough data in the packet to deserialize into the struct.
IO::NoBufferExceptionIf the read stream has no buffer.

◆ GetJsonFieldByName()

template<typename TField , typename TStruct >
TField* Devel::Serializing::GetJsonFieldByName ( TStruct &  i_oStruct,
const std::string_view  i_sName 
)

Retrieves a JSON field by name from a struct.

Template Parameters
TFieldThe type of the JSON field.
TStructThe type of the struct.
Parameters
i_oStructThe struct to search within.
i_sNameThe name of the JSON field to retrieve.
Returns
A pointer to the JSON field if found, nullptr otherwise.

◆ GetSerializableFieldByIndex() [1/2]

template<typename TStructFieldType = IData<>, typename TStruct >
TStructFieldType* Devel::Serializing::GetSerializableFieldByIndex ( const TStruct &  i_oStruct,
const size_t  i_nIndex 
)

Gets a serializable field in a struct by index.

Template Parameters
TStructFieldTypeThe type of the struct field.
TStructThe type of the struct.
Parameters
i_pStructPointer to the struct object.
i_nIndexThe index of the field.
Returns
A pointer to the serializable field, or nullptr if not found.

◆ GetSerializableFieldByIndex() [2/2]

template<typename TStructFieldType = IData<>, typename TStruct >
TStructFieldType* Devel::Serializing::GetSerializableFieldByIndex ( const TStruct *  i_pStruct,
const size_t  i_nIndex 
)

Gets the offsets of the serializable fields in a struct.

Template Parameters
TStructFieldTypeThe type of the struct field.
TStructThe type of the struct.
Parameters
i_oStructThe struct object.
i_fIncludeHiddenFlag indicating whether to include hidden fields.
i_nStructSizeThe size of the struct in bytes.
Returns
A vector containing the offsets of the serializable fields.

◆ GetSerializableFieldOffsets() [1/2]

template<typename TStructFieldType = IData<>, typename TStruct >
std::vector<size_t> Devel::Serializing::GetSerializableFieldOffsets ( const TStruct &  i_oStruct,
const bool  i_fIncludeHidden = true,
const size_t  i_nStructSize = sizeof(TStruct) 
)

Gets the offsets of the serializable fields in a struct.

Template Parameters
TStructFieldTypeThe type of the struct field.
TStructThe type of the struct.
Parameters
i_pStructPointer to the struct object.
i_fIncludeHiddenFlag indicating whether to include hidden fields.
i_nStructSizeThe size of the struct in bytes.
Returns
A vector containing the offsets of the serializable fields.

◆ GetSerializableFieldOffsets() [2/2]

template<typename TStructFieldType = IData<>, typename TStruct >
std::vector<size_t> Devel::Serializing::GetSerializableFieldOffsets ( const TStruct *  i_pStruct,
const bool  i_fIncludeHidden = true,
const size_t  i_nStructSize = sizeof(TStruct) 
)

Gets the offsets of the serializable fields in a struct.

Template Parameters
TStructFieldTypeThe type of the struct field.
TStructThe type of the struct.
Parameters
i_pStructPointer to the struct object.
i_fIncludeHiddenFlag indicating whether to include hidden fields.
i_nStructSizeThe size of the struct in bytes.
Returns
A vector containing the offsets of the serializable fields.

◆ is_data_class_impl()

std::false_type Devel::Serializing::is_data_class_impl (   ...)

Check if a type is a data class.

Template Parameters
TThe type to check.
Returns
true if the type is a data class, false otherwise.

◆ IterateDeserializableStruct() [1/2]

template<typename TStructFieldType = IData<>, typename TStruct >
bool Devel::Serializing::IterateDeserializableStruct ( TStruct &  i_oStruct,
std::function< bool(TStructFieldType *)>  i_pCallback,
const size_t  i_nStructSize = sizeof(TStruct) 
)

Iterates over a deserializable struct and applies a callback function to each field.

Template Parameters
TStructFieldTypeThe type of the struct field.
TStructThe type of the struct.
Parameters
i_oStructThe struct object.
i_pCallbackThe callback function to apply to each field.
i_nStructSizeThe size of the struct in bytes.
Returns
true if the iteration was completed without early termination, false otherwise.

◆ IterateDeserializableStruct() [2/2]

template<typename TStructFieldType = IData<>, typename TStruct >
bool Devel::Serializing::IterateDeserializableStruct ( TStruct *  i_pStruct,
std::function< bool(TStructFieldType *)>  i_pCallback,
const size_t  i_nStructSize = sizeof(TStruct) 
)

Iterates over a deserializable struct and applies a callback function to each field.

Template Parameters
TStructFieldTypeThe type of the struct field.
TStructThe type of the struct.
Parameters
i_pStructPointer to the struct object.
i_pCallbackThe callback function to apply to each field.
i_nStructSizeThe size of the struct in bytes.
Returns
true if the iteration was completed without early termination, false otherwise.

◆ IterateSerializableStruct() [1/2]

template<typename TStructFieldType = IData<>, typename TStruct >
bool Devel::Serializing::IterateSerializableStruct ( const TStruct &  i_oStruct,
std::function< bool(const TStructFieldType *)>  i_pCallback,
const size_t  i_nStructSize = sizeof(TStruct) 
)

Iterates over a serializable struct and applies a callback function to each field.

Template Parameters
TStructFieldTypeThe type of the struct field.
TStructThe type of the struct.
Parameters
i_oStructThe struct object.
i_pCallbackThe callback function to apply to each field.
i_nStructSizeThe size of the struct in bytes.
Returns
true if the iteration was completed without early termination, false otherwise.

◆ IterateSerializableStruct() [2/2]

template<typename TStructFieldType = IData<>, typename TStruct >
bool Devel::Serializing::IterateSerializableStruct ( const TStruct *  i_pStruct,
std::function< bool(const TStructFieldType *)>  i_pCallback,
const size_t  i_nStructSize = sizeof(TStruct) 
)

Iterates over a serializable struct and applies a callback function to each field.

Template Parameters
TStructFieldTypeThe type of the struct field.
TStructThe type of the struct.
Parameters
i_pStructPointer to the struct object.
i_pCallbackThe callback function to apply to each field.
i_nStructSizeThe size of the struct in bytes.
Returns
true if the iteration was completed without early termination, false otherwise.

◆ operator<<() [1/2]

template<typename T >
std::ostream& Devel::Serializing::operator<< ( std::ostream &  i_oStream,
const IValue< T > &  i_tData 
)

Output stream operator for IValue.

Template Parameters
TThe type of the value.
Parameters
i_oStreamThe output stream.
i_tDataThe IValue object.
Returns
The modified output stream

◆ operator<<() [2/2]

template<typename T >
std::wostream& Devel::Serializing::operator<< ( std::wostream &  i_oStream,
const IValue< T > &  i_tData 
)

Wide output stream operator for IValue.

Template Parameters
TThe type of the value.
Parameters
i_oStreamThe wide output stream.
i_tDataThe IValue object.
Returns
The modified wide output stream.

◆ operator>>() [1/2]

template<typename T >
std::istream& Devel::Serializing::operator>> ( std::istream &  i_oStream,
const IValue< T > &  i_tData 
)

Input stream operator for IValue.

Template Parameters
TThe type of the value.
Parameters
i_oStreamThe input stream.
i_tDataThe IValue object.
Returns
The modified input stream.

◆ operator>>() [2/2]

template<typename T >
std::wistream& Devel::Serializing::operator>> ( std::wistream &  i_oStream,
const IValue< T > &  i_tData 
)

Wide input stream operator for IValue.

Template Parameters
TThe type of the value.
Parameters
i_oStreamThe wide input stream.
i_tDataThe IValue object.
Returns
The modified wide input stream.

◆ SerializeDocument()

template<typename T >
bool Devel::Serializing::SerializeDocument ( const T &  i_oStruct,
IO::CJsonDocument i_oDocument,
const bool  i_bIsStrict = false,
size_t  i_nStructSize = sizeof(T) 
)

Serializes a struct into a JSON document.

Template Parameters
TThe type of the struct.
Parameters
i_oStructThe struct to serialize.
i_oDocumentThe JSON document to serialize into.
i_bIsStrictDetermines if strict serialization should be used.
i_nStructSizeThe size of the struct in bytes.
Returns
True if serialization is successful, false otherwise.

◆ SerializeObject()

template<typename T >
bool Devel::Serializing::SerializeObject ( const T &  i_oStruct,
IO::CJsonObject i_oObject,
const bool  i_bIsStrict = false,
size_t  i_nStructSize = sizeof(T) 
)

Serializes a struct into a JSON object.

Template Parameters
TThe type of the struct.
Parameters
i_oStructThe struct to serialize.
i_oObjectThe JSON object to serialize into.
i_bIsStrictDetermines if strict serialization should be used.
i_nStructSizeThe size of the struct in bytes.
Returns
True if serialization is successful, false otherwise.

◆ SerializeStream()

template<typename T >
bool Devel::Serializing::SerializeStream ( const T &  i_oStruct,
IO::CWriteStream i_oStream 
)

Serializes a struct to a write stream.

Template Parameters
TThe type of the struct.
Parameters
i_oStructThe struct object to serialize.
i_oStreamThe write stream to serialize to.
Returns
true if serialization was successful, false otherwise.