SRS-control 0.1.4
Loading...
Searching...
No Matches
SerializableBuffer.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <algorithm>
4#include <boost/asio/buffer.hpp>
5#include <iterator>
6#include <span>
8#include <string_view>
9#include <zpp_bits.h>
10
11namespace srs::process
12{
14 {
15 public:
17 explicit SerializableMsgBuffer(std::span<BufferElementType> read_data)
18 {
19 data_.reserve(read_data.size());
20 std::ranges::copy(read_data, std::back_inserter(data_));
21 }
22
23 auto serialize(auto&&... structs)
24 {
25 auto serialize_to = zpp::bits::out{ data_, zpp::bits::endian::network{}, zpp::bits::no_size{} };
26 auto size = data_.size();
27 serialize_to.position() += sizeof(BufferElementType) * size;
28
29 // cista::buf<WriteBufferType&> serializer{ buffer };
30 // serialize_multi(serialize_to, std::forward<decltype(structs)>(structs)...);
31 serialize_to(std::forward<decltype(structs)>(structs)...).or_throw();
32 return asio::buffer(data_);
33 }
34
35 auto operator==(std::span<char> msg) const -> bool { return std::string_view{ msg } == *this; }
36
37 auto operator==(std::string_view msg) const -> bool { return msg == data(); }
38
39 [[nodiscard]] auto data() const -> std::string_view { return std::string_view{ data_.data(), data_.size() }; }
40 [[nodiscard]] auto empty() const -> bool { return data_.empty(); }
41
42 void clear() { data_.clear(); }
43
44 private:
46 };
47} // namespace srs::process
SerializableMsgBuffer(std::span< BufferElementType > read_data)
auto operator==(std::span< char > msg) const -> bool
auto operator==(std::string_view msg) const -> bool
auto data() const -> std::string_view
char BufferElementType
std::vector< BufferElementType > BinaryData