-
-
Notifications
You must be signed in to change notification settings - Fork 46
Expand file tree
/
Copy pathssops.h
More file actions
40 lines (28 loc) · 684 Bytes
/
ssops.h
File metadata and controls
40 lines (28 loc) · 684 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
/* SPDX-License-Identifier: Apache-2.0 */
/* Based on https://github.com/osy/ThunderboltPatcher */
#include <cstddef>
#include <cstdlib>
#include <sstream>
template <typename T> std::stringstream &put(std::stringstream &str, const T &value)
{
union coercion {
T value;
char data[sizeof(T)];
};
coercion c;
c.value = value;
str.write(c.data, sizeof(T));
return str;
}
template <typename T> std::stringstream &get(std::stringstream &str, T &value)
{
union coercion {
T value;
char data[sizeof(T)];
};
coercion c;
c.value = value;
str.read(c.data, sizeof(T));
value = c.value;
return str;
}