RESTinio
chunked_input_info.hpp
Go to the documentation of this file.
1/*
2 restinio
3*/
4
11#pragma once
12
15
17
18#include <vector>
19#include <memory>
20
21namespace restinio
22{
23
24//
25// chunk_info_t
26//
41{
42 std::size_t m_started_at;
43 std::size_t m_size;
44
45public:
48 std::size_t started_at,
49 std::size_t size )
51 , m_size{ size }
52 {}
53
56 std::size_t
57 started_at() const noexcept { return m_started_at; }
58
61 std::size_t
62 size() const noexcept { return m_size; }
63
65
73 make_string_view_nonchecked( string_view_t full_body ) const noexcept
74 {
75 return full_body.substr( m_started_at, m_size );
76 }
77
79
87 {
88 if( m_started_at >= full_body.size() ||
89 m_started_at + m_size > full_body.size() )
90 {
91 throw exception_t{
92 fmt::format( "unable to make a chunk (started_at:{}, size: {}) "
93 "from a body with length:{}",
95 m_size,
96 full_body.size() )
97 };
98 }
99
100 return make_string_view_nonchecked( full_body );
101 }
102};
103
104namespace impl
105{
106
107//
108// chunked_input_info_block_t
109//
116{
118 std::vector< chunk_info_t > m_chunks;
119
121
126};
127
128} /* namespace impl */
129
130//
131// chunked_input_info_t
132//
143{
146
147public:
151
158 : m_info{ std::move(info) }
159 {}
160
162
166 std::size_t
167 chunk_count() const noexcept { return m_info.m_chunks.size(); }
168
170
176 const chunk_info_t &
177 chunk_at_nochecked( std::size_t index ) const noexcept
178 {
179 return m_info.m_chunks[ index ];
180 }
181
183
187 const chunk_info_t &
188 chunk_at( std::size_t index ) const
189 {
190 return m_info.m_chunks.at( index );
191 }
192
194
201 const auto &
202 chunks() const noexcept
203 {
204 return m_info.m_chunks;
205 }
206
208
216 {
218 }
219};
220
221//
222// chunked_input_info_unique_ptr_t
223//
230 std::unique_ptr< chunked_input_info_t >;
231
232} /* namespace restinio */
233
Information about one chunk in an incoming request with chunked encoding.
RESTINIO_NODISCARD string_view_t make_string_view(string_view_t full_body) const
Extract the chunk value from the whole body.
chunk_info_t(std::size_t started_at, std::size_t size)
Initializing constructor.
RESTINIO_NODISCARD std::size_t started_at() const noexcept
Get the starting offset of chunk.
RESTINIO_NODISCARD std::size_t size() const noexcept
Get the size of chunk.
RESTINIO_NODISCARD string_view_t make_string_view_nonchecked(string_view_t full_body) const noexcept
Extract the chunk value from the whole body.
An information about chunks and trailing fields in the incoming request.
RESTINIO_NODISCARD const chunk_info_t & chunk_at(std::size_t index) const
Get reference to the description of a chunk by index.
RESTINIO_NODISCARD std::size_t chunk_count() const noexcept
Get the count of chunks.
RESTINIO_NODISCARD const chunk_info_t & chunk_at_nochecked(std::size_t index) const noexcept
Get reference to the description of a chunk by index.
impl::chunked_input_info_block_t m_info
Actual data.
RESTINIO_NODISCARD const auto & chunks() const noexcept
Get access to the container with description of chunks.
chunked_input_info_t(impl::chunked_input_info_block_t info)
Initializing constructor.
chunked_input_info_t()=default
Default constructor. Makes empty object.
RESTINIO_NODISCARD const http_header_fields_t & trailing_fields() const noexcept
Get access to the container with trailing fields.
Exception class for all exceptions thrown by RESTinio.
Definition: exception.hpp:26
#define RESTINIO_NODISCARD
A special wrapper around fmtlib include files.
std::unique_ptr< chunked_input_info_t > chunked_input_info_unique_ptr_t
Alias of unique_ptr for chunked_input_info.
nonstd::string_view string_view_t
Definition: string_view.hpp:19
STL namespace.
Bunch of data related to chunked input.
std::vector< chunk_info_t > m_chunks
All non-empty chunks from the input.
http_header_fields_t m_trailing_fields
Trailing fields found in the input.
#define const
Definition: zconf.h:230