1#ifndef SERIALIZATION_HPP_U2YGHSPB
2#define SERIALIZATION_HPP_U2YGHSPB
4#include <vanetza/common/archives.hpp>
5#include <vanetza/common/byte_order.hpp>
6#include <boost/units/quantity.hpp>
12template<
typename T, ByteOrder ORDER>
13void serialize(OutputArchive& ar, EndianType<T, ORDER> value)
15 typedef typename decltype(value)::network_type network_type;
16 T tmp =
static_cast<network_type
>(value).get();
20template<
typename T, ByteOrder ORDER>
21void deserialize(InputArchive& ar, EndianType<T, ORDER>& value)
25 value = network_cast<T>(tmp);
29typename std::enable_if<std::is_integral<T>::value>::type
30serialize(OutputArchive& ar, T value)
32 auto tmp = hton(value);
37typename std::enable_if<std::is_integral<T>::value>::type
38deserialize(InputArchive& ar, T& value)
45template<
typename U,
typename T>
46void serialize(OutputArchive& ar, boost::units::quantity<U, T> q)
48 static_assert(std::is_integral<T>::value,
49 "Only integral based quantities are supported");
50 auto tmp = hton(q.value());
54template<
typename U,
typename T>
55void deserialize(InputArchive& ar, boost::units::quantity<U, T>& q)
57 static_assert(std::is_integral<T>::value,
58 "Only integral based quantities are supported");
61 q = boost::units::quantity<U, T>::from_value(ntoh(tmp));
65typename std::enable_if<std::is_enum<T>::value>::type
66serialize(OutputArchive& ar,
const T& t)
68 serialize(ar, host_cast(
static_cast<typename std::underlying_type<T>::type const
>(t)));
72typename std::enable_if<std::is_enum<T>::value>::type
73deserialize(InputArchive& ar, T& t)
75 typename std::underlying_type<T>::type tmp;
77 t =
static_cast<T
>(tmp);