-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutility.hpp
56 lines (47 loc) · 1.29 KB
/
utility.hpp
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#pragma once
#include <cstddef>
#include <cstdint>
#include "handler/communication_handler.hpp"
// helper type for the visitor
template<class... Ts>
struct overloaded : Ts ... {
using Ts::operator()...;
};
// explicit deduction guide (not needed as of C++20)
template<class... Ts>
overloaded(Ts...) -> overloaded<Ts...>;
namespace ipc {
/**
* Print byte array to console.
*
* @param data Byte array to print.
* @param size Size of array.
*/
void print_array(const std::byte *data, unsigned int size);
/**
* Get the current timestamp since epoch in nanoseconds.
*
* @return Timestamp in nanoseconds.
*/
std::int64_t get_timestamp();
/**
* Poll data from file descriptor.
*
* @param fd File descriptor to poll from.
* @param timeout Time in milliseconds to wait while polling, or -1 for infinite.
*
* @return Returns 1 if successful, zero if timed out, or -1 for errors.
*/
int poll(int fd, int timeout);
/**
* Deserialize a DataObject from a buffer with given size.
*
* @param type Type of the object.
* @param buffer Buffer with serialized object data.
* @param size Size of the buffer.
*
* @return Deserialized object or error.
*/
std::variant<DataObject, CommunicationError> deserialize_data_object(
DataType type, const std::byte *buffer, unsigned int size);
}