Line data Source code
1 : #ifndef OUT_CHUNK_HPP
2 : #define OUT_CHUNK_HPP
3 :
4 : #include <sstream>
5 : #include <iomanip>
6 : #include "out_data.hpp"
7 :
8 : namespace thinger::http::data{
9 :
10 : class out_chunk : public out_data{
11 :
12 : public:
13 503 : explicit out_chunk(std::string str) : str_(std::move(str)){
14 503 : std::ostringstream ss;
15 503 : ss << std::hex << str_.size();
16 503 : size_ = ss.str();
17 503 : }
18 :
19 668 : out_chunk() : size_("0"){
20 334 : }
21 :
22 837 : ~out_chunk() override = default;
23 :
24 0 : size_t get_size() override{
25 0 : return str_.size();
26 : }
27 :
28 837 : void to_buffer(std::vector<boost::asio::const_buffer>& buffer) const override{
29 837 : static const std::string crlf = "\r\n";
30 837 : buffer.emplace_back(boost::asio::buffer(size_));
31 837 : buffer.emplace_back(boost::asio::buffer(crlf));
32 837 : buffer.emplace_back(boost::asio::buffer(str_));
33 837 : buffer.emplace_back(boost::asio::buffer(crlf));
34 837 : }
35 :
36 : private:
37 : std::string str_;
38 : std::string size_;
39 : };
40 :
41 : }
42 :
43 : #endif
|