RESTinio
fixed_buffer.hpp
Go to the documentation of this file.
1/*
2 restinio
3*/
4
9#pragma once
10
11#include <vector>
12
14
15namespace restinio
16{
17
18namespace impl
19{
20
21//
22// fixed_buffer_t
23//
24
27{
28 public:
29 fixed_buffer_t( const fixed_buffer_t & ) = delete;
33
34 explicit fixed_buffer_t( std::size_t size )
35 {
36 m_buf.resize( size );
37 }
38
40 auto
42 {
43 return asio_ns::buffer( m_buf.data(), m_buf.size() );
44 }
45
47 void
48 obtained_bytes( std::size_t length ) noexcept
49 {
50 m_ready_length = length; // Current bytes in buffer.
51 m_ready_pos = 0; // Reset current pos.
52 }
53
55 void
56 consumed_bytes( std::size_t length ) noexcept
57 {
58 m_ready_length -= length; // decrement buffer length.
59 m_ready_pos += length; // Shift current pos.
60 }
61
63 std::size_t length() const noexcept { return m_ready_length; }
64
66
69 const char * bytes() const noexcept { return m_buf.data() + m_ready_pos; }
70
71 private:
73 std::vector< char > m_buf;
74
78 std::size_t m_ready_pos{0};
79
81 std::size_t m_ready_length{0};
83};
84
85} /* namespace impl */
86
87} /* namespace restinio */
Helper class for reading bytes and feeding them to parser.
std::size_t length() const noexcept
How many unconsumed bytes are there in buffer.
std::size_t m_ready_pos
unconsumed data left in buffer:Start of data in buffer.
fixed_buffer_t & operator=(const fixed_buffer_t &)=delete
void consumed_bytes(std::size_t length) noexcept
Mark how many bytes were obtained.
void obtained_bytes(std::size_t length) noexcept
Mark how many bytes were obtained.
auto make_asio_buffer() noexcept
Make asio buffer for reading bytes from socket.
const char * bytes() const noexcept
Get pointer to unconsumed bytes.
fixed_buffer_t(std::size_t size)
std::size_t m_ready_length
Data size.
std::vector< char > m_buf
Buffer for io operation.
fixed_buffer_t(fixed_buffer_t &&)=delete
fixed_buffer_t(const fixed_buffer_t &)=delete
#define const
Definition: zconf.h:230