TRIQS/h5 1.3.0
C++ interface to HDF5
Loading...
Searching...
No Matches
Example 3: Serialization

This example shows how to use h5 to serialize/deserialize a std::complex<double> object to/from a byte buffer.

#include <h5/h5.hpp>
#include <iostream>
int main() {
// serialize a complex number
std::complex<double> original { 1.0, 2.0 };
auto buffer = h5::serialize(original);
// deserialize the complex number
auto restored = h5::deserialize<std::complex<double>>(buffer);
std::cout << original << " == " << restored << "\n";
}
T deserialize(std::vector< std::byte > const &buf)
Deserialize an object from a byte buffer.
std::vector< std::byte > serialize(T const &x)
Serialize an object to a byte buffer.
Includes all relevant h5 headers.
Provides generic serialize and deserialize functions for types that can be read/written from/to HDF5.

Output:

(1,2) == (1,2)