19 #ifndef TYPESERIALIZER_H
20 #define TYPESERIALIZER_H
25 #include "Serialization_internal.hpp"
27 namespace FotoSHOCKcore {
32 static xmlNodePtr serialize(T value) {
36 static const T deserialize(
const xmlNodePtr value) {
37 return Serialization_internal::deserializeGeneral<T>(value);
44 static xmlNodePtr serialize(
const char* value) {
45 return xmlNewText(BAD_CAST value);
50 std::size_t len = strlen(reinterpret_cast<const char*>(value->content));
51 char* tmp =
new char[len + 1];
52 std::memcpy(tmp, value->content, len);
61 static xmlNodePtr serialize(
float value) {
62 char* tmp =
new char[9];
63 uint32_t i = *
reinterpret_cast<uint32_t*
>(&value);
64 std::sprintf(tmp,
"%X", htonl(i));
67 xmlNodePtr node = xmlNewText(BAD_CAST tmp);
72 static const float deserialize(
const xmlNodePtr value) {
73 uint32_t i =
static_cast<uint32_t
>(std::strtol(reinterpret_cast<const char*>(value->content), 0, 16));
75 float retVal = *
reinterpret_cast<float*
>(&i);
83 static xmlNodePtr serialize(
double value) {
84 char* tmp =
new char[17];
85 uint64_t i = *
reinterpret_cast<uint64_t*
>(&value);
86 std::sprintf(tmp,
"%lX", Serialization_internal::htonll(i));
89 xmlNodePtr node = xmlNewText(BAD_CAST tmp);
94 static const double deserialize(
const xmlNodePtr value) {
95 uint64_t i = std::strtol(reinterpret_cast<const char*>(value->content), 0, 16);
96 i = Serialization_internal::ntohll(i);
97 double retVal = *
reinterpret_cast<double*
>(&i);