RESTinio
Loading...
Searching...
No Matches
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(
94 "unable to make a chunk (started_at:{}, size: {}) "
95 "from a body with length:{}" ),
97 m_size,
98 full_body.size() )
99 };
100 }
101
102 return make_string_view_nonchecked( full_body );
103 }
104};
105
106namespace impl
107{
108
109//
110// chunked_input_info_block_t
111//
118{
120 std::vector< chunk_info_t > m_chunks;
121
123
128};
129
130} /* namespace impl */
131
132//
133// chunked_input_info_t
134//
145{
148
149public:
153
160 : m_info{ std::move(info) }
161 {}
162
164
168 std::size_t
169 chunk_count() const noexcept { return m_info.m_chunks.size(); }
170
172
178 const chunk_info_t &
179 chunk_at_nochecked( std::size_t index ) const noexcept
180 {
181 return m_info.m_chunks[ index ];
182 }
183
185
189 const chunk_info_t &
190 chunk_at( std::size_t index ) const
191 {
192 return m_info.m_chunks.at( index );
193 }
194
196
203 const auto &
204 chunks() const noexcept
205 {
206 return m_info.m_chunks;
207 }
208
210
218 {
220 }
221};
222
223//
224// chunked_input_info_unique_ptr_t
225//
232 std::unique_ptr< chunked_input_info_t >;
233
234} /* namespace restinio */
235
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.
#define RESTINIO_FMT_FORMAT_STRING(s)
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