Vanetza
 
Loading...
Searching...
No Matches
header.cpp
1#include "header.hpp"
2#include <vanetza/common/serialization.hpp>
3#include <vanetza/common/serialization_buffer.hpp>
4
5namespace vanetza
6{
7namespace btp
8{
9
10using vanetza::serialize;
11using vanetza::deserialize;
12
13constexpr std::size_t HeaderA::length_bytes;
14constexpr std::size_t HeaderB::length_bytes;
15
16void serialize(OutputArchive& ar, const HeaderA& hdr)
17{
18 serialize(ar, hdr.destination_port);
19 serialize(ar, hdr.source_port);
20}
21
22void deserialize(InputArchive& ar, HeaderA& hdr)
23{
24 deserialize(ar, hdr.destination_port);
25 deserialize(ar, hdr.source_port);
26}
27
28void serialize(OutputArchive& ar, const HeaderB& hdr)
29{
30 serialize(ar, hdr.destination_port);
31 serialize(ar, hdr.destination_port_info);
32}
33
34void deserialize(InputArchive& ar, HeaderB& hdr)
35{
36 deserialize(ar, hdr.destination_port);
37 deserialize(ar, hdr.destination_port_info);
38}
39
40HeaderA parse_btp_a(CohesivePacket& packet)
41{
42 HeaderA hdr;
43 deserialize_from_range(hdr, packet[OsiLayer::Transport]);
44 packet.set_boundary(OsiLayer::Transport, btp::HeaderA::length_bytes);
45 return hdr;
46}
47
48HeaderA parse_btp_a(ChunkPacket& packet)
49{
50 HeaderA hdr;
51 ByteBuffer tmp;
52 packet[OsiLayer::Transport].convert(tmp);
53 deserialize_from_buffer(hdr, tmp);
54 return hdr;
55}
56
57HeaderA parse_btp_a(PacketVariant& packet)
58{
59 struct parse_btp_visitor : public boost::static_visitor<HeaderA>
60 {
61 HeaderA operator()(CohesivePacket& packet) {
62 return parse_btp_a(packet);
63 }
64
65 HeaderA operator()(ChunkPacket& packet) {
66 return parse_btp_a(packet);
67 }
68 };
69
70 parse_btp_visitor visitor;
71 return boost::apply_visitor(visitor, packet);
72}
73
74HeaderB parse_btp_b(CohesivePacket& packet)
75{
76 HeaderB hdr;
77 deserialize_from_range(hdr, packet[OsiLayer::Transport]);
78 packet.set_boundary(OsiLayer::Transport, btp::HeaderB::length_bytes);
79 return hdr;
80}
81
82HeaderB parse_btp_b(ChunkPacket& packet)
83{
84 HeaderB hdr;
85 ByteBuffer tmp;
86 packet[OsiLayer::Transport].convert(tmp);
87 deserialize_from_buffer(hdr, tmp);
88 return hdr;
89}
90
91HeaderB parse_btp_b(PacketVariant& packet)
92{
93 struct parse_btp_visitor : public boost::static_visitor<HeaderB>
94 {
95 HeaderB operator()(CohesivePacket& packet) {
96 return parse_btp_b(packet);
97 }
98
99 HeaderB operator()(ChunkPacket& packet) {
100 return parse_btp_b(packet);
101 }
102 };
103
104 parse_btp_visitor visitor;
105 return boost::apply_visitor(visitor, packet);
106}
107
108} // namespace btp
109} // namespace vanetza