1#include "common_header.hpp"
2#include "data_request.hpp"
3#include "serialization.hpp"
11constexpr std::size_t CommonHeader::length_bytes;
13CommonHeader::CommonHeader() :
14 next_header(NextHeaderCommon::Any),
16 header_type(HeaderType::Any),
24CommonHeader::CommonHeader(
const MIB& mib) :
25 next_header(NextHeaderCommon::Any),
27 header_type(HeaderType::Any),
28 traffic_class(mib.itsGnDefaultTrafficClass),
29 flags(mib.itsGnIsMobile ? 0x80 : 0x00),
31 maximum_hop_limit(mib.itsGnDefaultHopLimit),
36CommonHeader::CommonHeader(
const DataRequest& request,
const MIB& mib) :
39 switch (request.upper_protocol) {
40 case UpperProtocol::BTP_A:
41 next_header = NextHeaderCommon::BTP_A;
43 case UpperProtocol::BTP_B:
44 next_header = NextHeaderCommon::BTP_B;
46 case UpperProtocol::IPv6:
47 next_header = NextHeaderCommon::IPv6;
50 throw std::runtime_error(
"Unhandled upper protocol");
54 traffic_class = request.traffic_class;
55 maximum_hop_limit = request.max_hop_limit;
58CommonHeader::CommonHeader(
const ShbDataRequest& request,
const MIB& mib) :
59 CommonHeader(static_cast<const DataRequest&>(request), mib)
61 header_type = HeaderType::TSB_Single_Hop;
62 maximum_hop_limit = 1;
65void serialize(
const CommonHeader& hdr, OutputArchive& ar)
67 uint8_t nextHeaderAndReserved =
static_cast<uint8_t
>(hdr.next_header);
68 nextHeaderAndReserved <<= 4;
69 nextHeaderAndReserved |= hdr.reserved1.raw();
70 serialize(host_cast(nextHeaderAndReserved), ar);
71 serialize(host_cast(
static_cast<std::underlying_type<HeaderType>::type
>(hdr.header_type)), ar);
72 serialize(hdr.traffic_class, ar);
73 serialize(host_cast(hdr.flags), ar);
74 serialize(host_cast(hdr.payload), ar);
75 serialize(host_cast(hdr.maximum_hop_limit), ar);
76 serialize(host_cast(hdr.reserved2), ar);
79void deserialize(CommonHeader& hdr, InputArchive& ar)
81 uint8_t nextHeaderAndReserved;
82 deserialize(nextHeaderAndReserved, ar);
83 hdr.next_header =
static_cast<NextHeaderCommon
>(nextHeaderAndReserved >> 4);
84 hdr.reserved1 = nextHeaderAndReserved & 0x0f;
85 typename std::underlying_type<HeaderType>::type headerType;
86 deserialize(headerType, ar);
87 hdr.header_type =
static_cast<HeaderType
>(headerType);
88 deserialize(hdr.traffic_class, ar);
89 deserialize(hdr.flags, ar);
90 deserialize(hdr.payload, ar);
91 deserialize(hdr.maximum_hop_limit, ar);
92 deserialize(hdr.reserved2, ar);