2#include "serialization.hpp"
3#include <boost/functional/hash.hpp>
10constexpr std::size_t Address::length_bytes;
14constexpr uint16_t manually_configured_mask = 0x8000;
15constexpr uint16_t station_type_mask = 0x7c00;
16constexpr uint16_t country_code_mask = 0x03ff;
17constexpr unsigned station_type_shift = 10;
21 m_manually_configured(false),
22 m_station_type(StationType::Unknown),
27Address::Address(
const MacAddress& addr) :
28 m_manually_configured(false),
29 m_station_type(StationType::Unknown),
35bool Address::operator==(
const Address& other)
const
37 return (this->m_manually_configured == other.m_manually_configured &&
38 this->m_station_type == other.m_station_type &&
39 this->m_country_code == other.m_country_code &&
40 this->m_mid == other.m_mid);
43bool Address::operator!=(
const Address& other)
const
45 return !(*
this == other);
48void serialize(
const Address& addr, OutputArchive& ar)
50 uint16_t manuallyConfiguredAndTypeAndCountryCode = addr.country_code().raw();
51 manuallyConfiguredAndTypeAndCountryCode |=
52 (
static_cast<uint16_t
>(addr.station_type()) << station_type_shift) & station_type_mask;
53 manuallyConfiguredAndTypeAndCountryCode |=
54 addr.is_manually_configured() ? manually_configured_mask : 0x0000;
55 serialize(host_cast(manuallyConfiguredAndTypeAndCountryCode), ar);
56 serialize(ar, addr.mid());
59void deserialize(Address& addr, InputArchive& ar)
63 addr.is_manually_configured((tmp & manually_configured_mask) != 0);
64 addr.country_code(tmp & country_code_mask);
65 addr.station_type(
static_cast<StationType
>((tmp & station_type_mask) >> station_type_shift));
77namespace gn = vanetza::geonet;
78size_t hash<gn::Address>::operator()(
const gn::Address& addr)
const
81 boost::hash_combine(seed, addr.is_manually_configured());
82 boost::hash_combine(seed, addr.station_type());
83 boost::hash_combine(seed, addr.country_code().raw());
84 boost::hash_range(seed, addr.mid().octets.begin(), addr.mid().octets.end());