Midnight Sun Firmware
Loading...
Searching...
No Matches
serialization.h
1#pragma once
2
3/************************************************************************************************
4 * @file serialization.h
5 *
6 * @brief Header file defining the serialization helper functions
7 *
8 * @date 2025-01-04
9 * @author Aryan Kashem
10 ************************************************************************************************/
11
12/* Standard library Headers */
13#include <cstring>
14#include <string>
15
16/* Inter-component Headers */
17
18/* Intra-component Headers */
19
34template <typename T>
35void serializeInteger(std::string &target, T value) {
36 target.append(reinterpret_cast<const char *>(&value), sizeof(T));
37}
38
47void serializeString(std::string &target, const std::string &str);
48
56template <typename T>
57T deserializeInteger(const std::string &source, size_t &offset) {
58 T value;
59 std::memcpy(&value, source.data() + offset, sizeof(T));
60 offset += sizeof(T);
61 return value;
62}
63
72std::string deserializeString(std::string &source, size_t &offset);
73
void serializeString(std::string &target, const std::string &str)
Serialize a string value.
Definition: serialization.cc:18
void serializeInteger(std::string &target, T value)
Serialize an integer value.
Definition: serialization.h:35
T deserializeInteger(const std::string &source, size_t &offset)
Deserialize an integer value.
Definition: serialization.h:57
std::string deserializeString(std::string &source, size_t &offset)
Deserialize a string value.
Definition: serialization.cc:24