Build: add test presets
[marnav.git] / src / marnav / ais / message_08.cpp
blob7f7877a4b30638a10a2d59889bda2f5040598a01
1 #include <marnav/ais/message_08.hpp>
2 #include <marnav/ais/binary_001_11.hpp>
3 #include <marnav/ais/binary_200_10.hpp>
5 namespace marnav
7 namespace ais
9 constexpr message_id message_08::ID;
10 constexpr std::size_t message_08::SIZE_BITS_HEAD;
11 constexpr std::size_t message_08::SIZE_BITS_MAX;
13 message_08::message_08()
14 : message(ID)
18 message_08::message_08(const raw & bits)
19 : message(ID)
21 if ((bits.size() < SIZE_BITS_HEAD) || (bits.size() > SIZE_BITS_MAX))
22 throw std::invalid_argument{"invalid number of bits in ais/message_08"};
23 read_data(bits);
26 void message_08::read_data(const raw & bits)
28 get(bits, repeat_indicator);
29 get(bits, mmsi);
30 get(bits, dac);
31 get(bits, fid);
33 payload = raw{bits.begin() + SIZE_BITS_HEAD, bits.end()};
36 raw message_08::get_data() const
38 raw bits(SIZE_BITS_HEAD);
40 bits.set(type(), 0, 6);
41 set(bits, repeat_indicator);
42 set(bits, mmsi);
43 set(bits, dac);
44 set(bits, fid);
46 bits.append(payload);
48 return bits;
51 void message_08::read_binary(binary_001_11 & m) const
53 if (std::make_tuple(1, 11) != std::tie(dac, fid))
54 throw std::invalid_argument{"invalid DAC/FID for Meteo/Hydro IMO236"};
55 m.read_from(payload);
58 void message_08::write_binary(const binary_001_11 & m)
60 m.write_to(payload);
63 void message_08::read_binary(binary_200_10 & m) const
65 if (std::make_tuple(200, 10) != std::tie(dac, fid))
66 throw std::invalid_argument{
67 "invalid DAC/FID for Inland ship static voyage related data"};
68 m.read_from(payload);
71 void message_08::write_binary(const binary_200_10 & m)
73 m.write_to(payload);