fixed_buffer.hpp
Go to the documentation of this file.
/*
restinio
*/
#pragma once
#include <vector>
#include <restinio/asio_include.hpp>
namespace restinio
{
namespace impl
{
//
// fixed_buffer_t
//
class fixed_buffer_t
{
public:
fixed_buffer_t( const fixed_buffer_t & ) = delete;
fixed_buffer_t & operator = ( const fixed_buffer_t & ) = delete;
fixed_buffer_t( fixed_buffer_t && ) = delete;
fixed_buffer_t & operator = ( fixed_buffer_t && ) = delete;
explicit fixed_buffer_t( std::size_t size )
{
m_buf.resize( size );
}
auto
make_asio_buffer() noexcept
{
return asio_ns::buffer( m_buf.data(), m_buf.size() );
}
void
obtained_bytes( std::size_t length ) noexcept
{
m_ready_length = length; // Current bytes in buffer.
m_ready_pos = 0; // Reset current pos.
}
void
consumed_bytes( std::size_t length ) noexcept
{
m_ready_length -= length; // decrement buffer length.
m_ready_pos += length; // Shift current pos.
}
std::size_t length() const noexcept { return m_ready_length; }
const char * bytes() const noexcept { return m_buf.data() + m_ready_pos; }
private:
std::vector< char > m_buf;
std::size_t m_ready_pos{0};
std::size_t m_ready_length{0};
};
} /* namespace impl */
} /* namespace restinio */
asio_include.hpp
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::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
Definition: asio_include.hpp:21
const
#define const
Definition: zconf.h:230