RESTinio
Toggle main menu visibility
Loading...
Searching...
No Matches
restinio
impl
fixed_buffer.hpp
Go to the documentation of this file.
1
/*
2
restinio
3
*/
4
5
/*!
6
Fixed size buffer.
7
*/
8
9
#
pragma
once
10
11
#
include
<
vector
>
12
13
#
include
<
restinio
/
asio_include
.
hpp
>
14
15
namespace
restinio
16
{
17
18
namespace
impl
19
{
20
21
//
22
// fixed_buffer_t
23
//
24
25
//! Helper class for reading bytes and feeding them to parser.
26
class
fixed_buffer_t
27
{
28
public
:
29
fixed_buffer_t
(
const
fixed_buffer_t
& ) =
delete
;
30
fixed_buffer_t
&
operator
= (
const
fixed_buffer_t
& ) =
delete
;
31
fixed_buffer_t
(
fixed_buffer_t
&& ) =
delete
;
32
fixed_buffer_t
&
operator
= (
fixed_buffer_t
&& ) =
delete
;
33
34
explicit
fixed_buffer_t
( std::size_t size )
35
{
36
m_buf.resize( size );
37
}
38
39
//! Make asio buffer for reading bytes from socket.
40
auto
41
make_asio_buffer
()
noexcept
42
{
43
return
asio_ns::buffer( m_buf.data(), m_buf.size() );
44
}
45
46
//! Mark how many bytes were obtained.
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
54
//! Mark how many bytes were obtained.
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
62
//! How many unconsumed bytes are there in buffer.
63
std::size_t
length
()
const
noexcept
{
return
m_ready_length
; }
64
65
//! Get pointer to unconsumed bytes.
66
/*!
67
\note To check that buffer has unconsumed bytes use length().
68
*/
69
const
char
*
bytes
()
const
noexcept
{
return
m_buf.data() + m_ready_pos; }
70
71
private
:
72
//! Buffer for io operation.
73
std
::
vector
<
char
>
m_buf
;
74
75
//! unconsumed data left in buffer:
76
//! \{
77
//! Start of data in buffer.
78
std::size_t
m_ready_pos
{0};
79
80
//! Data size.
81
std::size_t
m_ready_length
{0};
82
//! \}
83
};
84
85
}
/* namespace impl */
86
87
}
/* namespace restinio */
restinio::impl::fixed_buffer_t
Helper class for reading bytes and feeding them to parser.
Definition
fixed_buffer.hpp:27
restinio::impl::fixed_buffer_t::length
std::size_t length() const noexcept
How many unconsumed bytes are there in buffer.
Definition
fixed_buffer.hpp:63
restinio::impl::fixed_buffer_t::m_ready_pos
std::size_t m_ready_pos
unconsumed data left in buffer:Start of data in buffer.
Definition
fixed_buffer.hpp:78
restinio::impl::fixed_buffer_t::operator=
fixed_buffer_t & operator=(const fixed_buffer_t &)=delete
restinio::impl::fixed_buffer_t::consumed_bytes
void consumed_bytes(std::size_t length) noexcept
Mark how many bytes were obtained.
Definition
fixed_buffer.hpp:56
restinio::impl::fixed_buffer_t::obtained_bytes
void obtained_bytes(std::size_t length) noexcept
Mark how many bytes were obtained.
Definition
fixed_buffer.hpp:48
restinio::impl::fixed_buffer_t::make_asio_buffer
auto make_asio_buffer() noexcept
Make asio buffer for reading bytes from socket.
Definition
fixed_buffer.hpp:41
restinio::impl::fixed_buffer_t::bytes
const char * bytes() const noexcept
Get pointer to unconsumed bytes.
Definition
fixed_buffer.hpp:69
restinio::impl::fixed_buffer_t::fixed_buffer_t
fixed_buffer_t(std::size_t size)
Definition
fixed_buffer.hpp:34
restinio::impl::fixed_buffer_t::operator=
fixed_buffer_t & operator=(fixed_buffer_t &&)=delete
restinio::impl::fixed_buffer_t::m_ready_length
std::size_t m_ready_length
Data size.
Definition
fixed_buffer.hpp:81
restinio::impl::fixed_buffer_t::m_buf
std::vector< char > m_buf
Buffer for io operation.
Definition
fixed_buffer.hpp:73
restinio::impl::fixed_buffer_t::fixed_buffer_t
fixed_buffer_t(fixed_buffer_t &&)=delete
restinio::impl::fixed_buffer_t::fixed_buffer_t
fixed_buffer_t(const fixed_buffer_t &)=delete
restinio::impl
Definition
sendfile_operation_default.ipp:15
restinio
Definition
sendfile_operation_default.ipp:12
Generated by
1.17.0