ECSTASY
All in the name
Loading...
Searching...
No Matches
util::serialization::Serializer Class Reference

Static class. More...

#include <Serializer.hpp>

Static Public Member Functions

template<typename Object >
static std::ostreamserialize (std::ostream &stream, const Object &object)
 Serialize an object in a stream.
 
template<typename Object >
static std::string serialize (const Object &object)
 Serialize an object to a std::string.
 
template<typename Object >
static Object deserialize (std::istream &stream)
 Deserialize an object from an input stream.
 
template<typename Object >
static Object deserialize (std::string_view bytes)
 Deserialize an object from its bytes representation.
 

Private Member Functions

 Serializer ()=default
 

Detailed Description

Static class.

Template Parameters
T
Author
Andréas Leroux (andre.nosp@m.as.l.nosp@m.eroux.nosp@m.@epi.nosp@m.tech..nosp@m.eu)
Since
1.0.0 (2022-12-01)

Definition at line 27 of file Serializer.hpp.

Constructor & Destructor Documentation

◆ Serializer()

util::serialization::Serializer::Serializer ( )
privatedefault

Member Function Documentation

◆ deserialize() [1/2]

template<typename Object >
static Object util::serialization::Serializer::deserialize ( std::istream stream)
inlinestatic

Deserialize an object from an input stream.

Template Parameters
ObjectObject type.
Parameters
[in]streamInput stream containing the serialized object.
Returns
Object Deserialized object.
Author
Andréas Leroux (andre.nosp@m.as.l.nosp@m.eroux.nosp@m.@epi.nosp@m.tech..nosp@m.eu)
Since
1.0.0 (2022-12-01)

Definition at line 82 of file Serializer.hpp.

83 {
84 Object oblect;
85
86 stream >> oblect;
87 return oblect;
88 }

◆ deserialize() [2/2]

template<typename Object >
static Object util::serialization::Serializer::deserialize ( std::string_view  bytes)
inlinestatic

Deserialize an object from its bytes representation.

Template Parameters
ObjectObject type.
Parameters
[in]bytesserialized object.
Returns
Object Deserialized object.
Author
Andréas Leroux (andre.nosp@m.as.l.nosp@m.eroux.nosp@m.@epi.nosp@m.tech..nosp@m.eu)
Since
1.0.0 (2022-12-01)

Definition at line 103 of file Serializer.hpp.

104 {
105 std::istringstream ss(std::string(bytes), std::ios_base::in);
106
107 return deserialize<Object>(ss);
108 }

◆ serialize() [1/2]

template<typename Object >
static std::string util::serialization::Serializer::serialize ( const Object &  object)
inlinestatic

Serialize an object to a std::string.

Template Parameters
ObjectType of the object to serialize.
Parameters
[in]objectObject to serialize.
Returns
std::string seri
Author
Andréas Leroux (andre.nosp@m.as.l.nosp@m.eroux.nosp@m.@epi.nosp@m.tech..nosp@m.eu)
Since
1.0.0 (2022-12-01)

Definition at line 61 of file Serializer.hpp.

62 {
64
65 serialize(ss, object);
66 return ss.str();
67 }
static std::ostream & serialize(std::ostream &stream, const Object &object)
Serialize an object in a stream.
T str(T... args)

◆ serialize() [2/2]

template<typename Object >
static std::ostream & util::serialization::Serializer::serialize ( std::ostream stream,
const Object &  object 
)
inlinestatic

Serialize an object in a stream.

Template Parameters
ObjectType of the object to serialize.
Parameters
[in]streamOutput stream in which the object must be serialized.
[in]objectObject to serialize.
Returns
std::ostream& stream.
Author
Andréas Leroux (andre.nosp@m.as.l.nosp@m.eroux.nosp@m.@epi.nosp@m.tech..nosp@m.eu)
Since
1.0.0 (2022-12-01)

Definition at line 43 of file Serializer.hpp.

44 {
45 return stream << object;
46 }

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