本文整理汇总了C++中DynamicBuffer类的典型用法代码示例。如果您正苦于以下问题:C++ DynamicBuffer类的具体用法?C++ DynamicBuffer怎么用?C++ DynamicBuffer使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了DynamicBuffer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: sizeof
void DynamicBufferConverter<DataType, ConvertTo>::convert(std::vector<ConvertTo> & ConvertedVector, DynamicBuffer<DataType> const & Buffer) {
int NumItems = Buffer.length() / sizeof(ConvertTo);
ConvertedVector.resize(NumItems);
const char * tBuf = Buffer.getBuffer();
for (int lp = 0; lp < NumItems; lp ++)
memcpy(&ConvertedVector[lp], tBuf + (lp * sizeof(ConvertTo)), sizeof(ConvertTo));
}
示例2: write_buffer
void
write_buffer(DynamicBuffer& b, string_view s)
{
b.commit(boost::asio::buffer_copy(
b.prepare(s.size()), boost::asio::buffer(
s.data(), s.size())));
}
示例3: get
void get(DynamicBuffer & outData) const
{
outData.clear();
outData.reserve(getTotalSize());
for (const auto & str : mParts)
{
outData.insert(outData.end(), str.begin(), str.end());
}
}
示例4: decode_pcm8s_codec
static Ref<Sound> decode_pcm8s_codec (const Buffer * buf, ALint channel_count, ALint bits_per_sample, ALfloat sample_frequency)
{
DynamicBuffer copy;
copy.assign(*buf);
int8_t *d = (int8_t *)copy.begin();
std::size_t i;
for (i = 0; i < copy.size(); i++)
d[i] += (int8_t) 128;
return new Sound(data_format(channel_count, bits_per_sample), sample_frequency, ©);
}
示例5: read_fh2
void
read_fh2(frame_header& fh, DynamicBuffer& db,
role_type role, close_code::value& code)
{
using boost::asio::buffer;
using boost::asio::buffer_copy;
using boost::asio::buffer_size;
using namespace boost::endian;
switch(fh.len)
{
case 126:
{
std::uint8_t b[2];
assert(buffer_size(db.data()) >= sizeof(b));
db.consume(buffer_copy(buffer(b), db.data()));
fh.len = big_uint16_to_native(&b[0]);
// length not canonical
if(fh.len < 126)
{
code = close_code::protocol_error;
return;
}
break;
}
case 127:
{
std::uint8_t b[8];
assert(buffer_size(db.data()) >= sizeof(b));
db.consume(buffer_copy(buffer(b), db.data()));
fh.len = big_uint64_to_native(&b[0]);
// length not canonical
if(fh.len < 65536)
{
code = close_code::protocol_error;
return;
}
break;
}
}
if(fh.mask)
{
std::uint8_t b[4];
assert(buffer_size(db.data()) >= sizeof(b));
db.consume(buffer_copy(buffer(b), db.data()));
fh.key = little_uint32_to_native(&b[0]);
}
else
{
// initialize this otherwise operator== breaks
fh.key = 0;
}
code = close_code::none;
}
示例6: do_prepares
size_type
do_prepares(std::size_t repeat,
std::size_t count, std::size_t size)
{
timer t;
size_type total = 0;
for(auto i = repeat; i--;)
{
DynamicBuffer b;
for(auto j = count; j--;)
{
auto const n = fill(b.prepare(size));
b.commit(n);
total += n;
}
}
return throughput(t.elapsed(), total);
}
示例7: body
void
body(DynamicBuffer& db)
{
if(! rand(4))
{
write(db, "Content-Length: 0\r\n\r\n");
return;
}
if(rand(2))
{
auto const len = rand(500);
write(db, "Content-Length: ", len, "\r\n\r\n");
for(auto const& b : db.prepare(len))
{
auto p = boost::asio::buffer_cast<char*>(b);
auto n = boost::asio::buffer_size(b);
while(n--)
*p++ = static_cast<char>(32 + rand(26+26+10+6));
}
db.commit(len);
}
else
{
auto len = rand(500);
write(db, "Transfer-Encoding: chunked\r\n\r\n");
while(len > 0)
{
auto n = (std::min)(1 + rand(300), len);
len -= n;
write(db, to_hex(n), "\r\n");
for(auto const& b : db.prepare(n))
{
auto p = boost::asio::buffer_cast<char*>(b);
auto m = boost::asio::buffer_size(b);
while(m--)
*p++ = static_cast<char>(32 + rand(26+26+10+6));
}
db.commit(n);
write(db, "\r\n");
}
write(db, "0\r\n\r\n");
}
}
示例8: write
void
write(DynamicBuffer& db, frame_header const& fh)
{
using boost::asio::buffer;
using boost::asio::buffer_copy;
using namespace boost::endian;
std::size_t n;
std::uint8_t b[14];
b[0] = (fh.fin ? 0x80 : 0x00) | static_cast<std::uint8_t>(fh.op);
if(fh.rsv1)
b[0] |= 0x40;
if(fh.rsv2)
b[0] |= 0x20;
if(fh.rsv3)
b[0] |= 0x10;
b[1] = fh.mask ? 0x80 : 0x00;
if(fh.len <= 125)
{
b[1] |= fh.len;
n = 2;
}
else if(fh.len <= 65535)
{
b[1] |= 126;
::new(&b[2]) big_uint16_buf_t{
(std::uint16_t)fh.len};
n = 4;
}
else
{
b[1] |= 127;
::new(&b[2]) big_uint64_buf_t{fh.len};
n = 10;
}
if(fh.mask)
{
native_to_little_uint32(fh.key, &b[n]);
n += 4;
}
db.commit(buffer_copy(
db.prepare(n), buffer(b)));
}
示例9: makeWriter
void ChunkFile::Chunk::write()
{
DynamicBuffer<uint8_t> buffer;
auto writer = makeWriter(buffer, 1024);
XOR_CHUNKFILE_OP("Writing subchunk count: %zu\n", m_chunks.size());
writer.writeLength(static_cast<uint>(m_chunks.size()));
XOR_CHUNKFILE_OP("Writing chunk data size: %zu\n", m_data.sizeBytes());
writer.writeLength(static_cast<uint>(m_data.sizeBytes()));
for (auto &&kv : m_chunks)
{
kv.second->write();
XOR_CHUNKFILE_OP("Writing subchunk name: %s\n", kv.first.cStr());
writer.writeString(kv.first);
XOR_CHUNKFILE_OP("Writing subchunk block: (%lld, %lld)\n",
static_cast<lld>(kv.second->m_block.begin),
static_cast<lld>(kv.second->m_block.end));
writer.write(FileBlock(kv.second->m_block));
}
auto totalBytes = buffer.sizeBytes() + m_data.sizeBytes();
m_file->obtainBlock(m_block, totalBytes);
m_dataBlock.begin = m_block.end - static_cast<int64_t>(m_data.sizeBytes());
m_dataBlock.end = m_block.end;
auto dst = m_file->span(m_block);
XOR_CHUNKFILE_OP("Writing chunk header: %zu bytes\n", buffer.sizeBytes());
memcpy(dst.data(), buffer.data(), buffer.sizeBytes());
XOR_CHUNKFILE_OP("Writing chunk data: %zu bytes\n", m_data.sizeBytes());
memcpy(dst.data() + buffer.sizeBytes(), m_data.data(), m_data.sizeBytes());
}
示例10: do_hints
size_type
do_hints(std::size_t repeat,
std::size_t count, std::size_t size)
{
timer t;
size_type total = 0;
for(auto i = repeat; i--;)
{
DynamicBuffer b;
for(auto j = count; j--;)
{
for(auto remain = size; remain;)
{
auto const n = fill(b.prepare(
read_size(b, remain)));
b.commit(n);
remain -= n;
total += n;
}
}
}
return throughput(t.elapsed(), total);
}
示例11: testNeedMore
void
testNeedMore()
{
error_code ec;
std::size_t used;
{
DynamicBuffer b;
parser_type<true> p;
ostream(b) <<
"GET / HTTP/1.1\r\n";
used = p.put(b.data(), ec);
BEAST_EXPECTS(ec == error::need_more, ec.message());
b.consume(used);
ec.assign(0, ec.category());
ostream(b) <<
"User-Agent: test\r\n"
"\r\n";
used = p.put(b.data(), ec);
BEAST_EXPECTS(! ec, ec.message());
b.consume(used);
BEAST_EXPECT(p.is_done());
BEAST_EXPECT(p.is_header_done());
}
}
示例12: readIntoBuffer
/**
* \brief Read from the socket, info a buffer
* \param Buffer The buffer to read into
* \return Number of bytes read from socket
**/
int Socket::readIntoBuffer(DynamicBuffer<char> & Buffer) {
char Packet[PACKET_SIZE];
int TotalBytesRead = 0;
int BytesRead;
do {
if ((BytesRead = read(Packet, PACKET_SIZE)) == -1) {
#ifndef WIN32
switch (errno) {
case EINPROGRESS:
case EALREADY:
case EAGAIN:
#else
switch (WSAGetLastError()) {
case WSAEINPROGRESS:
case WSAEALREADY:
case WSAEWOULDBLOCK:
#endif
// this is just fine
return TotalBytesRead;
default:
cdbg << "Socket Read Error -- " << strerror(errno) << endl;
handleSocketDisconnect();
return TotalBytesRead;
}
}
if (BytesRead > 0) {
Buffer.addToBuffer(Packet, BytesRead);
addToMessageBuffer(Packet, BytesRead);
TotalBytesRead += BytesRead;
}
} while ( (BytesRead == PACKET_SIZE) && (BytesRead > 0) );
return TotalBytesRead;
}
/**
* \brief Set the socket's address from internal structures
**/
void Socket::setAddress() {
mAddress = inet_ntoa(mSockAddr.sin_addr);
}
示例13: new
status_t
BHttpRequest::_MakeRequest()
{
delete fSocket;
if (fSSL)
fSocket = new(std::nothrow) CheckedSecureSocket(this);
else
fSocket = new(std::nothrow) BSocket();
if (fSocket == NULL)
return B_NO_MEMORY;
_EmitDebug(B_URL_PROTOCOL_DEBUG_TEXT, "Connection to %s on port %d.",
fUrl.Authority().String(), fRemoteAddr.Port());
status_t connectError = fSocket->Connect(fRemoteAddr);
if (connectError != B_OK) {
_EmitDebug(B_URL_PROTOCOL_DEBUG_ERROR, "Socket connection error %s",
strerror(connectError));
return connectError;
}
//! ProtocolHook:ConnectionOpened
if (fListener != NULL)
fListener->ConnectionOpened(this);
_EmitDebug(B_URL_PROTOCOL_DEBUG_TEXT,
"Connection opened, sending request.");
_SendRequest();
_SendHeaders();
fSocket->Write("\r\n", 2);
_EmitDebug(B_URL_PROTOCOL_DEBUG_TEXT, "Request sent.");
_SendPostData();
fRequestStatus = kRequestInitialState;
// Receive loop
bool receiveEnd = false;
bool parseEnd = false;
bool readByChunks = false;
bool decompress = false;
status_t readError = B_OK;
ssize_t bytesRead = 0;
ssize_t bytesReceived = 0;
ssize_t bytesTotal = 0;
off_t bytesUnpacked = 0;
char* inputTempBuffer = new(std::nothrow) char[kHttpBufferSize];
ssize_t inputTempSize = kHttpBufferSize;
ssize_t chunkSize = -1;
DynamicBuffer decompressorStorage;
BDataIO* decompressingStream;
ObjectDeleter<BDataIO> decompressingStreamDeleter;
while (!fQuit && !(receiveEnd && parseEnd)) {
if (!receiveEnd) {
fSocket->WaitForReadable();
BStackOrHeapArray<char, 4096> chunk(kHttpBufferSize);
bytesRead = fSocket->Read(chunk, kHttpBufferSize);
if (bytesRead < 0) {
readError = bytesRead;
break;
} else if (bytesRead == 0)
receiveEnd = true;
fInputBuffer.AppendData(chunk, bytesRead);
} else
bytesRead = 0;
if (fRequestStatus < kRequestStatusReceived) {
_ParseStatus();
//! ProtocolHook:ResponseStarted
if (fRequestStatus >= kRequestStatusReceived && fListener != NULL)
fListener->ResponseStarted(this);
}
if (fRequestStatus < kRequestHeadersReceived) {
_ParseHeaders();
if (fRequestStatus >= kRequestHeadersReceived) {
_ResultHeaders() = fHeaders;
//! ProtocolHook:HeadersReceived
if (fListener != NULL)
fListener->HeadersReceived(this);
// Parse received cookies
if (fContext != NULL) {
for (int32 i = 0; i < fHeaders.CountHeaders(); i++) {
if (fHeaders.HeaderAt(i).NameIs("Set-Cookie")) {
fContext->GetCookieJar().AddCookie(
fHeaders.HeaderAt(i).Value(), fUrl);
}
}
}
//.........这里部分代码省略.........
示例14: _EmitDebug
//.........这里部分代码省略.........
// Chunked transfer
char hexSize[16];
size_t hexLength = sprintf(hexSize, "%ld", read);
fSocket->Write(hexSize, hexLength);
fSocket->Write("\r\n", 2);
fSocket->Write(outputTempBuffer, read);
fSocket->Write("\r\n", 2);
} else {
fSocket->Write(outputTempBuffer, read);
}
}
if (fOptInputDataSize < 0) {
// Chunked transfer terminating sequence
fSocket->Write("0\r\n\r\n", 5);
}
}
fRequestStatus = kRequestInitialState;
// Receive loop
bool receiveEnd = false;
bool parseEnd = false;
bool readByChunks = false;
bool decompress = false;
status_t readError = B_OK;
ssize_t bytesRead = 0;
ssize_t bytesReceived = 0;
ssize_t bytesTotal = 0;
char* inputTempBuffer = new(std::nothrow) char[kHttpBufferSize];
ssize_t inputTempSize = kHttpBufferSize;
ssize_t chunkSize = -1;
DynamicBuffer decompressorStorage;
BPrivate::ZlibDecompressor decompressor(&decompressorStorage);
while (!fQuit && !(receiveEnd && parseEnd)) {
if (!receiveEnd) {
fSocket->WaitForReadable();
BNetBuffer chunk(kHttpBufferSize);
bytesRead = fSocket->Read(chunk.Data(), kHttpBufferSize);
if (bytesRead < 0) {
readError = bytesRead;
break;
} else if (bytesRead == 0)
receiveEnd = true;
fInputBuffer.AppendData(chunk.Data(), bytesRead);
} else
bytesRead = 0;
if (fRequestStatus < kRequestStatusReceived) {
_ParseStatus();
//! ProtocolHook:ResponseStarted
if (fRequestStatus >= kRequestStatusReceived && fListener != NULL)
fListener->ResponseStarted(this);
}
if (fRequestStatus < kRequestHeadersReceived) {
_ParseHeaders();
if (fRequestStatus >= kRequestHeadersReceived) {
_ResultHeaders() = fHeaders;
示例15: png_write_to_buffer
static void png_write_to_buffer (png_structp png_writer, png_bytep data, png_size_t length)
{
DynamicBuffer * buffer = (DynamicBuffer*)png_get_io_ptr(png_writer);
buffer->append(length, data);
}