waterlinkedsonar
C++ client library for the Water Linked Sonar 3D-15
Loading...
Searching...
No Matches
decoder.hpp
Go to the documentation of this file.
1
3
4#ifndef WATERLINKEDSONAR_RIP_DECODER_HPP
5#define WATERLINKEDSONAR_RIP_DECODER_HPP
6
7#include <cstddef>
8#include <cstdint>
9#include <memory>
10#include <string_view>
11#include <variant>
14
15namespace waterlinked::sonar::rip {
16
18inline constexpr std::size_t MAX_PACKET_SIZE = 65507;
19
21enum class DecodeStatus : std::uint8_t {
22 OK,
26 BAD_MAGIC,
33};
34
36const char* to_string(DecodeStatus status) noexcept;
37
39struct Decoded {
40 DecodeStatus status{DecodeStatus::PARSE_FAILED};
42 std::variant<std::monostate, RangeImageView, BitmapImageView, ImuBatchView>
45 std::string_view unknown_type_url;
46};
47
59class Decoder {
60 public:
67 Decoder(Decoder&& other) noexcept;
69 Decoder& operator=(Decoder&& other) noexcept;
70 Decoder(const Decoder&) = delete;
71 Decoder& operator=(const Decoder&) = delete;
72
75
76 private:
77 struct Impl;
78 std::unique_ptr<Impl> impl_;
79};
80
81} // namespace waterlinked::sonar::rip
82
83#endif // WATERLINKEDSONAR_RIP_DECODER_HPP
Decodes Range Image Protocol packets (https://docs.waterlinked.com/sonar-3d/sonar-3d-15-api/).
Definition decoder.hpp:59
~Decoder()
Frees the buffers, invalidating the views returned by decode().
Decoder & operator=(Decoder &&other) noexcept
Same as the move constructor.
Decoded decode(Span< const std::uint8_t > packet)
Decodes one packet that spans all of packet.
Decoder(Decoder &&other) noexcept
Takes over the buffers of other, which may only be destroyed or assigned to afterwards.
Decoder()
Creates a decoder; buffers are allocated on first use.
constexpr std::size_t MAX_PACKET_SIZE
Largest packet the sonar sends: the maximum UDP payload.
Definition decoder.hpp:18
DecodeStatus
Outcome of decoding one packet.
Definition decoder.hpp:21
@ PARSE_FAILED
Invalid protobuf data.
@ DECOMPRESS_FAILED
Invalid snappy data.
@ UNKNOWN_TYPE
Valid packet with a message type other than the published ones.
@ BAD_LENGTH
Packet shorter than its framing or longer than MAX_PACKET_SIZE, or length field different from the pa...
@ BAD_MAGIC
Neither "RIP2" nor "RIP1".
@ OK
Decoded a published message type.
Views of the messages carried by the Range Image Protocol.
Non-owning view over a contiguous sequence.
tcb::span< T > Span
Non-owning view over a contiguous sequence, with the interface of C++20 std::span.
Definition span.hpp:17
Result of Decoder::decode().
Definition decoder.hpp:39
DecodeStatus status
Outcome.
Definition decoder.hpp:40
std::variant< std::monostate, RangeImageView, BitmapImageView, ImuBatchView > message
The message when status is OK; std::monostate otherwise.
Definition decoder.hpp:43
std::string_view unknown_type_url
Type URL of the message when status is UNKNOWN_TYPE.
Definition decoder.hpp:45
const char * to_string(AcousticsMode mode) noexcept
API name of mode: "low-frequency" or "high-frequency".