Skip to content

Commit 0e85b91

Browse files
committed
buffers changes
1 parent 5917736 commit 0e85b91

8 files changed

Lines changed: 36 additions & 45 deletions

File tree

src/detail/array_of_const_buffers.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ consume(std::size_t n)
3838
auto* p = base_ + pos_;
3939
if(n < p->size())
4040
{
41-
buffers::trim_front(*p, n);
41+
buffers::remove_prefix(*p, n);
4242
return;
4343
}
4444
n -= p->size();

src/detail/buffer_utils.hpp

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,30 +11,20 @@
1111
#define BOOST_HTTP_PROTO_DETAIL_BUFFER_UTILS_HPP
1212

1313
#include <boost/buffers/buffer.hpp>
14-
#include <boost/buffers/slice.hpp>
1514
#include <boost/core/span.hpp>
15+
#include <iterator>
1616

1717
namespace boost {
1818
namespace http_proto {
1919
namespace detail {
2020

21-
template<
22-
typename BufferSequence,
23-
typename Buffer = typename BufferSequence::value_type>
24-
boost::span<Buffer const>
25-
make_span(BufferSequence const& mbp)
26-
{
27-
return { mbp.begin(), mbp.end() };
28-
}
29-
3021
template<typename BufferSequence>
31-
BufferSequence
32-
prefix(
33-
BufferSequence cbp,
34-
std::size_t n)
22+
auto
23+
make_span(BufferSequence const& bs) ->
24+
boost::span<typename std::iterator_traits<decltype(buffers::begin(bs))>::value_type const>
3525
{
36-
buffers::keep_front(cbp, n);
37-
return cbp;
26+
return { &*buffers::begin(bs),
27+
std::size_t(std::distance(buffers::begin(bs), buffers::end(bs))) };
3828
}
3929

4030
} // detail

src/detail/filter.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ process(
5757
return rv;
5858
}
5959

60-
buffers::trim_front(out, rs.out_bytes);
61-
buffers::trim_front(in, rs.in_bytes);
60+
buffers::remove_prefix(out, rs.out_bytes);
61+
buffers::remove_prefix(in, rs.in_bytes);
6262

6363
if(buffers::size(out) == 0)
6464
return rv;

src/parser.cpp

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,12 @@
1212
#include <boost/http_proto/error.hpp>
1313
#include <boost/http_proto/parser.hpp>
1414

15-
#include "src/detail/brotli_filter_base.hpp"
16-
#include "src/detail/buffer_utils.hpp"
17-
#include "src/detail/zlib_filter_base.hpp"
18-
1915
#include <boost/assert.hpp>
2016
#include <boost/buffers/circular_buffer.hpp>
2117
#include <boost/buffers/copy.hpp>
2218
#include <boost/buffers/flat_buffer.hpp>
2319
#include <boost/buffers/front.hpp>
20+
#include <boost/buffers/slice.hpp>
2421
#include <boost/rts/brotli/decode.hpp>
2522
#include <boost/rts/context.hpp>
2623
#include <boost/rts/zlib/error.hpp>
@@ -29,6 +26,10 @@
2926
#include <boost/url/grammar/error.hpp>
3027
#include <boost/url/grammar/hexdig_chars.hpp>
3128

29+
#include "src/detail/brotli_filter_base.hpp"
30+
#include "src/detail/buffer_utils.hpp"
31+
#include "src/detail/zlib_filter_base.hpp"
32+
3233
namespace boost {
3334
namespace http_proto {
3435

@@ -1317,7 +1318,7 @@ class parser::impl
13171318
const std::size_t chunk_avail =
13181319
clamp(chunk_remain_, cb0_.size());
13191320
const auto chunk =
1320-
detail::prefix(cb0_.data(), chunk_avail);
1321+
buffers::prefix(cb0_.data(), chunk_avail);
13211322

13221323
if(body_limit_remain() < chunk_avail)
13231324
{
@@ -1459,7 +1460,7 @@ class parser::impl
14591460
payload_remain_ -= payload_avail;
14601461
body_total_ += payload_avail;
14611462
auto sink_rs = sink_->write(
1462-
detail::prefix(cb0_.data(), payload_avail),
1463+
buffers::prefix(cb0_.data(), payload_avail),
14631464
!is_complete);
14641465
cb0_.consume(sink_rs.bytes);
14651466
if(sink_rs.ec.failed())
@@ -1537,7 +1538,7 @@ class parser::impl
15371538
case style::sink:
15381539
{
15391540
auto rs = sink_->write(
1540-
detail::prefix(body_buf.data(), body_avail_),
1541+
buffers::prefix(body_buf.data(), body_avail_),
15411542
state_ == state::set_body);
15421543
body_buf.consume(rs.bytes);
15431544
body_avail_ -= rs.bytes;
@@ -1594,7 +1595,7 @@ class parser::impl
15941595
return {};
15951596
case state::body:
15961597
case state::complete_in_place:
1597-
cbp_ = detail::prefix(
1598+
cbp_ = buffers::prefix(
15981599
(is_plain() ? cb0_ : cb1_).data(),
15991600
body_avail_);
16001601
return detail::make_span(cbp_);
@@ -1730,7 +1731,7 @@ class parser::impl
17301731

17311732
return filter_->process(
17321733
eb_->prepare(n),
1733-
detail::prefix(cb0_.data(), payload_avail),
1734+
buffers::prefix(cb0_.data(), payload_avail),
17341735
more);
17351736
}
17361737
else // in-place and sink
@@ -1740,7 +1741,7 @@ class parser::impl
17401741

17411742
return filter_->process(
17421743
detail::make_span(cb1_.prepare(n)),
1743-
detail::prefix(cb0_.data(), payload_avail),
1744+
buffers::prefix(cb0_.data(), payload_avail),
17441745
more);
17451746
}
17461747
}();

src/serializer.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -474,7 +474,7 @@ class serializer::impl
474474

475475
const auto rs = filter_->process(
476476
detail::make_span(out_prepare()),
477-
{ tmp_, {} },
477+
{{ {tmp_}, {} }},
478478
more_input_);
479479

480480
if(rs.ec.failed())
@@ -484,7 +484,7 @@ class serializer::impl
484484
return rs.ec;
485485
}
486486

487-
buffers::trim_front(tmp_, rs.in_bytes);
487+
buffers::remove_prefix(tmp_, rs.in_bytes);
488488
out_commit(rs.out_bytes);
489489

490490
if(rs.out_short)
@@ -752,7 +752,7 @@ class serializer::impl
752752
auto h_len = chunk_header_len(stats.size);
753753
buffers::mutable_buffer mb(
754754
ws_.reserve_front(h_len), h_len);
755-
write_chunk_header({ mb, {} }, stats.size);
755+
write_chunk_header({{ {mb}, {} }}, stats.size);
756756
prepped_.append(mb);
757757
}
758758
}
@@ -870,9 +870,9 @@ class serializer::impl
870870
auto mbp = out_.prepare(out_.capacity());
871871
if(is_chunked_)
872872
{
873-
buffers::trim_front(
873+
buffers::remove_prefix(
874874
mbp, chunk_header_len_);
875-
buffers::trim_back(
875+
buffers::remove_suffix(
876876
mbp, crlf_and_final_chunk.size());
877877
}
878878
return mbp;

test/unit/compression.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ struct zlib_test
261261

262262
results rs;
263263
auto n = buffers::copy(b, body_);
264-
buffers::trim_front(body_, n);
264+
buffers::remove_prefix(body_, n);
265265
rs.bytes = n;
266266
rs.finished = (body_.size() == 0);
267267
done_ = rs.finished;
@@ -296,7 +296,7 @@ struct zlib_test
296296
{
297297
auto mbs = stream.prepare();
298298
auto n = buffers::copy(mbs, body);
299-
buffers::trim_front(body, n);
299+
buffers::remove_prefix(body, n);
300300
stream.commit(n);
301301
if(body.size() == 0)
302302
stream.close();
@@ -336,7 +336,7 @@ struct zlib_test
336336
buf_seq.emplace_back(
337337
body.data(),
338338
body.size() ? buf_size : 0);
339-
buffers::trim_front(body, buf_size);
339+
buffers::remove_prefix(body, buf_size);
340340
} while(body.size() != 0);
341341

342342
sr.start(res, buf_seq);
@@ -483,7 +483,7 @@ struct zlib_test
483483
if(input.size() != 0)
484484
{
485485
auto n1 = buffers::copy(pr.prepare(), input);
486-
buffers::trim_front(input, n1);
486+
buffers::remove_prefix(input, n1);
487487
pr.commit(n1);
488488
}
489489

@@ -522,7 +522,7 @@ struct zlib_test
522522
{
523523
std::string rs;
524524
auto n1 = buffers::copy(pr.prepare(), input);
525-
buffers::trim_front(input, n1);
525+
buffers::remove_prefix(input, n1);
526526
pr.commit(n1);
527527
system::error_code ec;
528528
pr.parse(ec);
@@ -535,7 +535,7 @@ struct zlib_test
535535
while(ec == error::need_data)
536536
{
537537
auto n2 = buffers::copy(pr.prepare(), input);
538-
buffers::trim_front(input, n2);
538+
buffers::remove_prefix(input, n2);
539539
pr.commit(n2);
540540
pr.parse(ec);
541541
if(n2 == 0)
@@ -555,7 +555,7 @@ struct zlib_test
555555
buffers::const_buffer input)
556556
{
557557
auto n1 = buffers::copy(pr.prepare(), input);
558-
buffers::trim_front(input, n1);
558+
buffers::remove_prefix(input, n1);
559559
pr.commit(n1);
560560
system::error_code ec;
561561
pr.parse(ec);
@@ -596,7 +596,7 @@ struct zlib_test
596596
while(ec == error::need_data)
597597
{
598598
auto n2 = buffers::copy(pr.prepare(), input);
599-
buffers::trim_front(input, n2);
599+
buffers::remove_prefix(input, n2);
600600
pr.commit(n2);
601601
pr.parse(ec);
602602
if(n2 == 0)

test/unit/serializer.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ struct serializer_test
120120
// serializer::consume(), allowing tests to cover
121121
// state management within these functions
122122
std::string s;
123-
buffers::keep_front(cbs, 256);
123+
buffers::keep_prefix(cbs, 256);
124124
for( auto buf : cbs)
125125
{
126126
s.append(
@@ -411,7 +411,7 @@ struct serializer_test
411411
while( buf.size() > 0 )
412412
{
413413
auto n = buffers::copy(out_buf, buf);
414-
buffers::trim_front(buf, n);
414+
buffers::remove_prefix(buf, n);
415415

416416
s.insert(
417417
s.end(),

test/unit/source.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ struct source_test
4747
return rv;
4848
}
4949
auto n = buffers::copy(b, cb_);
50-
buffers::trim_front(cb_, n);
50+
buffers::remove_prefix(cb_, n);
5151
rv.bytes += n;
5252
rv.finished = cb_.size() == 0;
5353
return rv;

0 commit comments

Comments
 (0)