Serialization#
Here shows functions and classes to serialize data.
Contents#
Functions to serialize data
-
Serialize data in memory and return the resulting binary data.
-
Serialize data to an output stream implementing
msgpack_light::output_stream
interface.
-
Output streams
-
Interface of output streams used in
msgpack_light::serialize_to()
function andmsgpack_light::serialization_buffer
class. Write a class implementing this interface if a stream not implemented in this library is needed.
msgpack_light::memory_output_stream
An implementation of
msgpack_light::output_stream
which writes data to buffers in memory.
msgpack_light::file_output_stream
An implementation of
msgpack_light::output_stream
which writes data to files.
-
Reference#
-
template<typename T>
inline binary msgpack_light::serialize(const T &data)# Serialize data to an output stream.
- Template Parameters:
T – Type of data to serialize.
- Parameters:
data – [in] Data to serialize.
- Returns:
Serialized binary data.
-
template<typename T>
inline void msgpack_light::serialize_to(output_stream &stream, const T &data)# Serialize data in memory and return the resulting binary data.
- Template Parameters:
T – Type of data.
- Parameters:
stream – [out] Stream to write serialized data.
data – [in] Data.
-
class output_stream#
Interface of streams to write data.
Note
Users can write a class implementing this interface to create a stream not implemented in this library.
Subclassed by msgpack_light::file_output_stream, msgpack_light::memory_output_stream
Public Functions
-
output_stream() = default#
Constructor.
-
virtual void write(const unsigned char *data, std::size_t size) = 0#
Write data.
- Parameters:
data – [in] Pointer to the data.
size – [in] Size of the data.
Protected Functions
-
output_stream(const output_stream&) = default#
Copy constructor.
-
output_stream(output_stream&&) = default#
Move constructor.
-
~output_stream() = default#
Destructor.
-
output_stream &operator=(const output_stream&) = default#
Copy assignment operator.
- Returns:
This.
-
output_stream &operator=(output_stream&&) = default#
Move assignment operator.
- Returns:
This.
-
output_stream() = default#
-
class memory_output_stream : public msgpack_light::output_stream#
Class of streams to write data to memory.
Public Functions
-
inline memory_output_stream()#
Constructor.
-
inline const binary &as_binary() const#
Get the data as msgpack_light::binary instance.
- Returns:
Data.
-
inline void clear()#
Clear data.
-
inline const unsigned char *data() const noexcept#
Get the pointer to the written data.
- Returns:
Pointer to the written data.
-
inline std::size_t size() const noexcept#
Get the size of the written data.
- Returns:
Size of the written data.
-
inline virtual void write(const unsigned char *data, std::size_t size) override#
Write data.
- Parameters:
data – [in] Pointer to the data.
size – [in] Size of the data.
-
inline memory_output_stream()#
-
class file_output_stream : public msgpack_light::output_stream#
Class of streams to write data to files.
Public Functions
-
inline explicit file_output_stream(const char *file_path)#
Constructor.
- Parameters:
file_path – [in] File path.
-
file_output_stream(const file_output_stream&) = delete#
-
inline explicit file_output_stream(const std::string &file_path)#
Constructor.
- Parameters:
file_path – [in] File path.
-
file_output_stream(file_output_stream&&) = delete#
-
inline ~file_output_stream()#
Destructor.
-
file_output_stream &operator=(const file_output_stream&) = delete#
-
file_output_stream &operator=(file_output_stream&&) = delete#
-
inline virtual void write(const unsigned char *data, std::size_t size) override#
Write data.
- Parameters:
data – [in] Pointer to the data.
size – [in] Size of the data.
-
inline explicit file_output_stream(const char *file_path)#