Chops Net IP
Loading...
Searching...
No Matches
io_buf.hpp
Go to the documentation of this file.
1
17#ifndef IO_BUF_HPP_INCLUDED
18#define IO_BUF_HPP_INCLUDED
19
20#include <cstddef> // std::size_t, std::byte
21#include <numeric> // std::accumulate
22#include <vector>
23
24#include "buffer/shared_buffer.hpp"
25#include "utility/byte_array.hpp"
26
27
28namespace chops {
29namespace test {
30
31constexpr int Answer = 42;
32
34 chops::const_shared_buffer m_buf;
35 int m_num;
36
37 io_buf_and_int (const chops::const_shared_buffer& buf) : m_buf(buf), m_num(Answer) { }
38
39 std::size_t size() const noexcept { return m_buf.size(); }
40
41};
42
43auto make_io_buf1() {
44 auto ba = chops::make_byte_array(0x20, 0x21, 0x22, 0x23, 0x24);
45 return chops::const_shared_buffer(ba.data(), ba.size());
46}
47
48auto make_io_buf2() {
49 auto ba = chops::make_byte_array(0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46);
50 return chops::const_shared_buffer(ba.data(), ba.size());
51}
52
53auto make_io_buf_vec() {
54 return std::vector<chops::const_shared_buffer> { make_io_buf1(), make_io_buf2() };
55}
56
57auto make_io_buf_and_int_vec() {
58 return std::vector<io_buf_and_int> { io_buf_and_int(make_io_buf1()), io_buf_and_int(make_io_buf2()) };
59}
60
61template <typename E>
62std::size_t accum_io_buf_size (const std::vector<E>& data_vec) {
63 return std::accumulate (data_vec.cbegin(), data_vec.cend(), static_cast<std::size_t>(0u),
64 [] (std::size_t sum, const E& elem) { return sum += elem.size(); } );
65}
66
67
68} // end namespace test
69} // end namespace chops
70
71#endif
72
Definition io_buf.hpp:33