void buffer::append_from(network::input_stream* istream) { CPPA_REQUIRE(remaining() > 0); auto num_bytes = istream->read_some(wr_ptr(), remaining()); if (num_bytes > 0) { inc_size(num_bytes); } }
void buffer::write(size_t num_bytes, const void* data, buffer_write_policy wp) { if (wp == grow_if_needed) { acquire(num_bytes); } else if (num_bytes > remaining()) { throw std::ios_base::failure("final buffer size exceeded"); } memcpy(wr_ptr(), data, num_bytes); inc_size(num_bytes); }
int MessageBuffer::put(const char* buf,int size) { if ( space() < size || size == 0 ) { return 0; } if( size < wr_ptr_tail()-wr_ptr() ) { memcpy(wr_ptr(),buf,size); wr_ptr_inc(size); } else { int len0 = wr_ptr_tail()-wr_ptr(); int len1 = size-len0; memcpy(wr_ptr(),buf,len0); wr_ptr_inc(len0); memcpy(wr_ptr(),buf+len0,len1); wr_ptr_inc(len1); } return size; }
//! ���ۿ� ������ ��� std::size_t memory_block::write( void* buf , std::size_t write_size ) { reserve( _write_pos + write_size ); write_size = std::min( space() , write_size ); memcpy( wr_ptr() , buf , write_size ); return wr_ptr( static_cast<int>(write_size)); }
/// Advance the write pointer by \a n records. This doesn't /// actually modify the data in the buffer, but adjusts the /// position of wr_ptr(). T* write(size_t n = 1) { super::commit(n*sizeof(T)); return wr_ptr(); }
/// Write a given record to the buffer. /// @return pointer to the next possible buffer write location. T* write(const T& a_src) { BOOST_ASSERT(capacity() > 0); *wr_ptr() = a_src; return write(1); }
/// Current number of bytes available to write. size_t capacity() const { return end() - wr_ptr(); }
/// Current number of bytes available to read. size_t size() const { return wr_ptr() - rd_ptr(); }
std::size_t byte_buffer::write(void* src, const std::size_t sz){ std::size_t cpysize = std::min(sz, space()); memcpy( wr_ptr() , src , cpysize ); return wr_ptr(static_cast<int>(cpysize)); }