Chops Net IP
Loading...
Searching...
No Matches
simple_variable_len_msg_frame.hpp
Go to the documentation of this file.
1
17#ifndef SIMPLE_VARIABLE_LEN_MSG_FRAME_HPP_INCLUDED
18#define SIMPLE_VARIABLE_LEN_MSG_FRAME_HPP_INCLUDED
19
20#include "asio/buffer.hpp"
21
22#include <cstddef> // std::size_t, std::byte
23
24namespace chops {
25namespace net {
26
51using hdr_decoder_func = std::size_t (*)(const std::byte* ptr, std::size_t sz);
52
53
60private:
61 hdr_decoder_func m_hdr_decoder_func;
62 bool m_hdr_processed;
63public:
64 simple_variable_len_msg_frame(hdr_decoder_func func) noexcept :
65 m_hdr_decoder_func(func), m_hdr_processed(false) { }
66
67 std::size_t operator() (asio::mutable_buffer buf) noexcept {
68 if (!m_hdr_processed) {
69 auto sz = m_hdr_decoder_func(static_cast<const std::byte*>(buf.data()), buf.size());
70 m_hdr_processed = (sz != 0u);
71 return sz;
72 }
73 m_hdr_processed = false;
74 return 0u;
75 }
76};
77
78} // end net namespace
79} // end chops namespace
80
81#endif
82
std::size_t(*)(const std::byte *ptr, std::size_t sz) hdr_decoder_func
Signature for a variable length message header decoder function, used in one of the basic_io_interfac...
Definition simple_variable_len_msg_frame.hpp:51
Function object class used in the basic_io_interface start_io methods, implements a common message fr...
Definition simple_variable_len_msg_frame.hpp:59