本文整理汇总了C++中boost::asio::streambuf::data方法的典型用法代码示例。如果您正苦于以下问题:C++ streambuf::data方法的具体用法?C++ streambuf::data怎么用?C++ streambuf::data使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类boost::asio::streambuf
的用法示例。
在下文中一共展示了streambuf::data方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: log_request_helper
std::string log_request_helper(const boost::asio::streambuf& buf)
{
boost::asio::const_buffers_1 b = static_cast<boost::asio::const_buffers_1>(buf.data());
boost::iterator_range<const char*> ib(buffer_cast<const char*>(b),
buffer_cast<const char*>(b) + buffer_size(b));
return string(ib.begin(), ib.end());
}
示例2: make_string
/// @brief Helper function that extracts a string from a streambuf.
std::string make_string(
boost::asio::streambuf& streambuf,
std::size_t n)
{
return std::string(buffers_begin(streambuf.data()),
buffers_begin(streambuf.data()) + n);
}
示例3: parse_body
// STEP 3: parse the body
size_t Frame::parse_body(boost::asio::streambuf& _response)
{
std::size_t _content_length = 0, bytecount = 0;
string _str;
//debug_print("Frame parser phase 3");
// special case: content-length
if (m_headers.find("content-length") != m_headers.end()) {
string& val = m_headers["content-length"];
//debug_print(boost::format("phase 3: body content-length==%1%") % val);
_content_length = lexical_cast<size_t>(val);
}
if (_content_length > 0) {
bytecount += _content_length;
// read back the body byte by byte
const char* rawdata = boost::asio::buffer_cast<const char*>(_response.data());
for (size_t i = 0; i < _content_length; i++ ) {
m_body << rawdata[i];
}
} else {
// read all bytes until the first NULL
mygetline(_response, _str, '\0');
bytecount += _str.size();
m_body << _str;
}
bytecount += 1; // for the final frame-terminating NULL
//debug_print(boost::format("phase 3: consumed %1% bytes, BODY(%2% bytes)==%3%") % bytecount % _str.size() % _str);
_response.consume(bytecount);
return(bytecount);
}
示例4: data
static std::string to_string(boost::asio::streambuf& buffer)
{
boost::asio::streambuf::const_buffers_type bufs = buffer.data();
std::string data(
boost::asio::buffers_begin(bufs),
boost::asio::buffers_begin(bufs) + buffer.size());
return std::move(data);
}
示例5: Fill
bool ConstByte::Fill(boost::asio::streambuf& buf)
{
const char* cp = boost::asio::buffer_cast<const char*>(buf.data());
if (static_cast<const char>(_expectedValue) != *cp) {
return false;
}
return FixedSizeData<1>::Fill(buf);
}
示例6: async_fetch_cface_std_saver
void webqq::async_fetch_cface_std_saver( boost::system::error_code ec, boost::asio::streambuf& buf, std::string cface, boost::filesystem::path parent_path)
{
if (!fs::exists(parent_path)){
fs::create_directories(parent_path);
}
if (!ec || ec == boost::asio::error::eof){
std::string imgfilename = (parent_path / cface).string();
std::ofstream cfaceimg(imgfilename.c_str(), std::ofstream::binary|std::ofstream::out);
cfaceimg.write(boost::asio::buffer_cast<const char*>(buf.data()), boost::asio::buffer_size(buf.data()));
}
}
示例7: on_recv_
void on_recv_(const boost::system::error_code& error, size_t bytes_transferred)
{
if(error && error != boost::asio::error::eof) {
std::cout << "receive failed: " << error.message() << std::endl;
} else {
const char* data = asio::buffer_cast<const char*>(recv_.data());
std::cout << "response(" << bytes_transferred << "): ";
std::cout << data << std::endl;
recv_.consume(recv_.size());
read_trg_ = true;
}
}
示例8: mygetline
// my own version of getline for an asio streambuf
inline void mygetline (boost::asio::streambuf& sb, string& _str, char delim = '\n') {
const char* line = boost::asio::buffer_cast<const char*>(sb.data());
char _c;
size_t i;
_str.clear();
for( i = 0;
((i < sb.size()) && ((_c = line[i]) != delim));
i++
) _str += _c;
//debug_print( boost::format("mygetline: i=%1%, sb.size()==%2%") % i % sb.size() );
//hexdump(_str.c_str(), _str.size());
}
示例9: operator
void operator()( boost::system::error_code ec, boost::asio::streambuf & buf, std::string cface )
{
using namespace boost::asio::detail;
if( !ec || ec == boost::asio::error::eof )
{
std::ofstream cfaceimg( ( std::string( "images/" ) + cface ).c_str(), std::ofstream::openmode(std::ofstream::binary | std::ofstream::out) );
cfaceimg.write( boost::asio::buffer_cast<const char*>( buf.data() ), boost::asio::buffer_size( buf.data() ) );
ec = boost::system::error_code();
}
io_service.post( bind_handler( handler, ec));
}
示例10: handle_line
void handle_line(const boost::system::error_code& error, size_t bytes_received) {
if(!error) {
boost::asio::streambuf::const_buffers_type bufs = m_buffer.data();
std::string line(boost::asio::buffers_begin(bufs),
boost::asio::buffers_begin(bufs) + bytes_received);
std::cerr << "Sentence: " << line << std::endl;
m_buffer.consume(bytes_received);
read_next();
} else {
std::cerr << "Error: " << error << std::endl;
}
}
示例11: iss
boost::optional<rc_result> parse_rc_response(const boost::asio::streambuf& buf)
{
typedef boost::asio::streambuf::const_buffers_type const_buffers_type;
typedef boost::asio::buffers_iterator<const_buffers_type> iterator;
const_buffers_type buffers = buf.data();
iterator begin = iterator::begin(buffers);
iterator end = iterator::end(buffers);
// Look for the start of the body of the response
boost::iterator_range<const char*> delim = boost::as_literal("\r\n\r\n");
std::pair<iterator, bool> result = boost::asio::detail::partial_search(
begin, end, delim.begin(), delim.end());
if (result.first != end && result.second)
{
iterator start = result.first + delim.size();
// Skip a line
delim = boost::as_literal("\r\n");
result = boost::asio::detail::partial_search(start, end,
delim.begin(), delim.end());
if (result.first != end && result.second)
{
// todo: we can optimise parsing here
std::string d;
start = result.first + delim.size();
std::copy(start, end, std::back_inserter(d));
rc_result res;
try
{
std::istringstream iss(d);
iss >> res.ok;
iss >> res.sum1;
iss >> res.sum2;
iss >> res.sum3;
iss >> res.sum4;
}
catch (...)
{
return boost::optional<rc_result>();
}
return boost::optional<rc_result>(res);
}
示例12: make_string
/// @brief Convert a streambuf to a string.
std::string make_string(boost::asio::streambuf& streambuf)
{
return std::string(buffers_begin(streambuf.data()),
buffers_end(streambuf.data()));
}