BitPacker¶
class nmeasim::core::ais::BitPacker · Library API
Accumulates the bit fields of one AIS message, most significant bit first.
#include <nmeasim/core/ais/sixbit.hpp>
Declared in src/core/include/nmeasim/core/ais/sixbit.hpp (line 29)
Fields are appended in message order; the packer knows nothing of the message layout, so the caller is responsible for the field widths. A default-constructed packer is empty.
See also
Summary¶
Public member functions
| Name | Description |
|---|---|
append_unsigned() |
Appends the low bits bits of an unsigned value, most significant bit first. |
append_signed() |
Appends a signed value in two's complement on bits bits. |
append_text() |
Appends a text field of exactly length six-bit characters. |
append_bool() |
Appends one bit: 1 for true, 0 for false. |
size() |
Returns the number of bits appended so far. |
bits() |
Returns the appended bits, most significant bit of the first field first. |
Private data members
| Name | Description |
|---|---|
bits_ |
The message bits in transmission order. |
Public member functions¶
append_unsigned()¶
void append_unsigned(std::uint32_t value, int bits)
Appends the low bits bits of an unsigned value, most significant bit first.
Bits of value above the field width are dropped, so a value that does not fit is silently truncated; callers clamp first.
Parameters
| Name | Type | Description |
|---|---|---|
value |
std::uint32_t |
Field value. |
bits |
int |
Field width in bits; 0 or a negative width appends nothing, and a field wider than 32 bits gets zeros above the value's 32 bits. |
Declared in src/core/include/nmeasim/core/ais/sixbit.hpp:39 · defined in src/core/src/ais/sixbit.cpp:12
append_signed()¶
void append_signed(std::int32_t value, int bits)
Appends a signed value in two's complement on bits bits.
A value outside the range of the field, [-2^(bits-1), 2^(bits-1) - 1], is clamped to its nearest end rather than wrapped. A field of 32 bits or more holds every value; a field wider than 32 bits repeats the sign bit above the value's 32 bits.
Parameters
| Name | Type | Description |
|---|---|---|
value |
std::int32_t |
Field value. |
bits |
int |
Field width in bits; 0 or a negative width appends nothing. |
Declared in src/core/include/nmeasim/core/ais/sixbit.hpp:49 · defined in src/core/src/ais/sixbit.cpp:19
append_text()¶
void append_text(std::string_view text, std::size_t length)
Appends a text field of exactly length six-bit characters.
Lower-case letters are sent upper-case, characters outside the six-bit text alphabet become ?, a shorter text is padded with @ (the AIS "not available" character) and a longer one is truncated. The field is 6 * length bits wide.
Parameters
| Name | Type | Description |
|---|---|---|
text |
std::string_view |
Text to send, one character per byte. |
length |
std::size_t |
Number of characters in the field, for example 20 for the vessel name. |
See also
sixbit_codefor the character mapping.
Declared in src/core/include/nmeasim/core/ais/sixbit.hpp:60 · defined in src/core/src/ais/sixbit.cpp:39
append_bool()¶
void append_bool(bool value)
Appends one bit: 1 for true, 0 for false.
Parameters
| Name | Type | Description |
|---|---|---|
value |
bool |
Flag to append. |
Declared in src/core/include/nmeasim/core/ais/sixbit.hpp:65
size()¶
std::size_t size() const noexcept
Returns the number of bits appended so far.
Returns std::size_t: Message length in bits.
Declared in src/core/include/nmeasim/core/ais/sixbit.hpp:70
bits()¶
const std::vector<bool>& bits() const noexcept
Returns the appended bits, most significant bit of the first field first.
Returns const std::vector<bool>&: The bit string, ready for armor. The reference stays valid until the next append or the packer's destruction.
Declared in src/core/include/nmeasim/core/ais/sixbit.hpp:76
Private data members¶
bits_¶
std::vector<bool> bits_
The message bits in transmission order.
Declared in src/core/include/nmeasim/core/ais/sixbit.hpp:80