1 #include <marnav/ais/message_12.hpp>
7 constexpr message_id
message_12::ID
;
8 constexpr std::size_t message_12::SIZE_BITS_HEAD
;
9 constexpr std::size_t message_12::SIZE_BITS_MAX
;
10 constexpr std::size_t message_12::SIZE_TEXT_MAX
;
12 message_12::message_12()
17 message_12::message_12(const raw
& bits
)
20 if ((bits
.size() < SIZE_BITS_HEAD
) || (bits
.size() > SIZE_BITS_MAX
))
21 throw std::invalid_argument
{"invalid number of bits in ais/message_12"};
25 void message_12::read_data(const raw
& bits
)
27 get(bits
, repeat_indicator
);
31 get(bits
, retransmit
);
33 auto rest
= bits
.size() - SIZE_BITS_HEAD
;
35 rest
= std::min(rest
, SIZE_BITS_MAX
- SIZE_BITS_HEAD
);
36 text
= read_string(bits
, 72, rest
/ 6);
40 raw
message_12::get_data() const
42 raw
bits(SIZE_BITS_HEAD
);
44 bits
.set(type(), 0, 6);
45 set(bits
, repeat_indicator
);
49 set(bits
, retransmit
);
51 if (text
.size() > 0) {
52 // compute number of bits, must be on a 8-bit boundary
53 auto size
= text
.size() * 6;
55 size
+= 8 - (size
% 8);
57 if (size
<= SIZE_BITS_MAX
- SIZE_BITS_HEAD
) {
58 // append a temporary bitset to the real one
60 write_string(t
, 0, text
.size(), text
);
68 void message_12::set_seqno(uint32_t t
)
71 throw std::invalid_argument
{"set_seqno out of range [0..3]"};
75 void message_12::set_text(const std::string
& t
)
77 text
= t
.substr(0, std::min(t
.size(), SIZE_TEXT_MAX
));