version 3.11-dev
Loading...
Searching...
No Matches
packing.hh
Go to the documentation of this file.
1// -*- mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2// vi: set et ts=4 sw=4 sts=4:
3//
4// SPDX-FileCopyrightText: Copyright © DuMux Project contributors, see AUTHORS.md in root folder
5// SPDX-License-Identifier: GPL-3.0-or-later
6//
13#ifndef DUMUX_PARALLEL_PACKING_HH
14#define DUMUX_PARALLEL_PACKING_HH
15
16#include <vector>
17#include <cstring>
18#include <type_traits>
19
20namespace Dumux::Detail {
21
23template<class T>
24 requires std::is_trivially_copyable_v<T>
25void packValue(std::vector<char>& buf, const T& value)
26{
27 const auto* p = reinterpret_cast<const char*>(&value);
28 buf.insert(buf.end(), p, p + sizeof(T));
29}
30
32template<class T>
33 requires std::is_trivially_copyable_v<T>
34T unpackValue(const char*& cursor)
35{
36 T value;
37 std::memcpy(&value, cursor, sizeof(T));
38 cursor += sizeof(T);
39 return value;
40}
41
42} // end namespace Dumux::Detail
43
44#endif
Definition cvfelocalresidual.hh:25
void packValue(std::vector< char > &buf, const T &value)
Append the raw bytes of a trivially-copyable value to a byte buffer.
Definition packing.hh:25
T unpackValue(const char *&cursor)
Read a trivially-copyable value from a byte buffer and advance the cursor.
Definition packing.hh:34