TRIQS/h5
2.0.0
C++ interface to HDF5
Toggle main menu visibility
Loading...
Searching...
No Matches
serialization.hpp
Go to the documentation of this file.
1
// Copyright (c) 2019-2024 Simons Foundation
2
//
3
// Licensed under the Apache License, Version 2.0 (the "License");
4
// you may not use this file except in compliance with the License.
5
// You may obtain a copy of the License at
6
//
7
// http://www.apache.org/licenses/LICENSE-2.0.txt
8
//
9
// Unless required by applicable law or agreed to in writing, software
10
// distributed under the License is distributed on an "AS IS" BASIS,
11
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
// See the License for the specific language governing permissions and
13
// limitations under the License.
14
//
15
// Authors: Thomas Hahn, Olivier Parcollet, Nils Wentzell
16
21
22
#ifndef LIBH5_SERIALIZATION_HPP
23
#define LIBH5_SERIALIZATION_HPP
24
25
#include "
./file.hpp
"
26
#include "
./generic.hpp
"
27
28
#include <cstddef>
29
#include <vector>
30
31
namespace
h5 {
32
37
47
template
<
typename
T>
48
[[nodiscard]] std::vector<std::byte>
serialize
(T
const
&x) {
49
file
f{};
50
h5_write
(f,
"object"
, x);
51
return
f.
as_buffer
();
52
}
53
64
template
<
typename
T>
65
[[nodiscard]] T
deserialize
(std::vector<std::byte>
const
&buf) {
66
file
f{buf};
67
return
h5_read<T>
(f,
"object"
);
68
}
69
71
72
}
// namespace h5
73
74
#endif
// LIBH5_SERIALIZATION_HPP
h5::file
A handle to an HDF5 file.
Definition
file.hpp:43
h5::file::as_buffer
std::vector< std::byte > as_buffer() const
Get a copy of the associated byte buffer.
Definition
file.cpp:123
file.hpp
Provides a handle to an HDF5 file.
generic.hpp
Provides a generic interface for reading/writing data from/to various HDF5 objects.
h5::h5_read
T h5_read(group g, std::string const &key)
Generic implementation for reading from an HDF5 dataset/subgroup.
Definition
generic.hpp:53
h5::h5_write
void h5_write(group g, std::string const &name, T const &x)
Write a scalar to an HDF5 dataset.
Definition
scalar.hpp:71
h5::deserialize
T deserialize(std::vector< std::byte > const &buf)
Deserialize an object from a byte buffer.
Definition
serialization.hpp:65
h5::serialize
std::vector< std::byte > serialize(T const &x)
Serialize an object to a byte buffer.
Definition
serialization.hpp:48
h5
serialization.hpp
Generated by
1.17.0