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>
6#include <zpp_bits.h>
7
8namespace srs::process
9{
11 {
12 public:
14 explicit SerializableMsgBuffer(std::span<BufferElementType> read_data)
15 {
16 data_.reserve(read_data.size());
17 std::ranges::copy(read_data, std::back_inserter(data_));
18 }
19
20 auto serialize(auto&&... structs)
21 {
22 auto serialize_to = zpp::bits::out{ data_, zpp::bits::endian::network{}, zpp::bits::no_size{} };
23 auto size = data_.size();
24 serialize_to.position() += sizeof(BufferElementType) * size;
25
26 // cista::buf<WriteBufferType&> serializer{ buffer };
27 // serialize_multi(serialize_to, std::forward<decltype(structs)>(structs)...);
28 serialize_to(std::forward<decltype(structs)>(structs)...).or_throw();
29 return asio::buffer(data_);
30 }
31
32 [[nodiscard]] auto data() const -> std::string_view { return std::string_view{ data_.data(), data_.size() }; }
33
34 void clear() { data_.clear(); }
35
36 private:
38 };
39} // namespace srs
SerializableMsgBuffer(std::span< BufferElementType > read_data)
auto data() const -> std::string_view
char BufferElementType
std::vector< BufferElementType > BinaryData