本文整理汇总了C++中blob类的典型用法代码示例。如果您正苦于以下问题:C++ blob类的具体用法?C++ blob怎么用?C++ blob使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了blob类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: init
void binary_reader::init(blob& bb)
{
_blob = bb;
_size = bb.length();
_ptr = bb.data();
_remaining_size = _size;
}
示例2: buffer
int binary_reader::read(blob& blob)
{
int len;
if (0 == read(len))
return 0;
if (len <= get_remaining_size())
{
blob = _blob.range(static_cast<int>(_ptr - _blob.data()), len);
// optimization: zero-copy
if (!blob.buffer_ptr())
{
std::shared_ptr<char> buffer(new char[len]);
memcpy(buffer.get(), blob.data(), blob.length());
blob = ::dsn::blob(buffer, 0, blob.length());
}
_ptr += len;
_remaining_size -= len;
return len + sizeof(len);
}
else
{
dassert(false, "read beyond the end of buffer");
return 0;
}
}
示例3:
binary_reader::binary_reader(blob& blob)
{
_blob = blob;
_size = blob.length();
_ptr = blob.data();
_remaining_size = _size;
}
示例4: blob
blob Base64::from(const blob& data) const {
std::string transformed;
CryptoPP::StringSource(data.data(), data.size(), true,
new CryptoPP::Base64Decoder(
new CryptoPP::StringSink(transformed)
)
);
return blob(std::make_move_iterator(transformed.begin()), std::make_move_iterator(transformed.end()));
}
示例5:
binary_writer::binary_writer(blob& buffer)
{
_total_size = 0;
_buffers.reserve(1);
_reserved_size_per_buffer = _reserved_size_per_buffer_static;
_buffers.push_back(buffer);
_current_buffer = (char*)buffer.data();
_current_offset = 0;
_current_buffer_length = buffer.length();
}
示例6:
void Downloader::NeededChunk::put_block(uint32_t offset, const blob& content) {
auto inserted = file_map_.insert({offset, content.size()}).second;
if(inserted) {
#ifndef FOPEN_BACKEND
std::copy(content.begin(), content.end(), mapped_file_.data()+offset);
#else
if(wrapped_file_.ios().tellp() != offset)
wrapped_file_.ios().seekp(offset);
wrapped_file_.ios().write((char*)content.data(), content.size());
#endif
}
}
示例7: release
port& operator= (const port& rhs) {
if (this != &rhs) {
release(); m_blob = rhs.m_blob;
if (m_blob) m_blob->inc_rc();
}
return *this;
}
示例8:
void P2PFolder::handle_message(const blob& message_raw) {
V1Parser::message_type message_type = parser_.parse_MessageType(message_raw);
counter_.add_down(message_raw.size());
if(ready()) {
switch(message_type) {
case V1Parser::CHOKE: handle_Choke(message_raw); break;
case V1Parser::UNCHOKE: handle_Unchoke(message_raw); break;
case V1Parser::INTERESTED: handle_Interested(message_raw); break;
case V1Parser::NOT_INTERESTED: handle_NotInterested(message_raw); break;
case V1Parser::HAVE_META: handle_HaveMeta(message_raw); break;
case V1Parser::HAVE_CHUNK: handle_HaveChunk(message_raw); break;
case V1Parser::META_REQUEST: handle_MetaRequest(message_raw); break;
case V1Parser::META_REPLY: handle_MetaReply(message_raw); break;
case V1Parser::META_CANCEL: handle_MetaCancel(message_raw); break;
case V1Parser::BLOCK_REQUEST: handle_BlockRequest(message_raw); break;
case V1Parser::BLOCK_REPLY: handle_BlockReply(message_raw); break;
case V1Parser::BLOCK_CANCEL: handle_BlockCancel(message_raw); break;
default: throw protocol_error();
}
}else{
handle_Handshake(message_raw);
}
}
示例9: on_log_completed
void meta_service::on_log_completed(error_code err, size_t size,
blob buffer,
std::shared_ptr<configuration_update_request> req, dsn_message_t resp)
{
dassert(err == ERR_OK, "log operation failed, cannot proceed, err = %s", err.to_string());
dassert(buffer.length() == size, "log size must equal to the specified buffer size");
configuration_update_response response;
update_configuration(*req, response);
if (resp != nullptr)
{
meta_response_header rhdr;
rhdr.err = err;
rhdr.primary_address = primary_address();
marshall(resp, rhdr);
marshall(resp, response);
dsn_rpc_reply(resp);
}
else
{
err.end_tracking();
}
}
示例10: put_block
void Downloader::put_block(const blob& ct_hash, uint32_t offset, const blob& data, std::shared_ptr<RemoteFolder> from) {
log_->trace() << log_tag() << BOOST_CURRENT_FUNCTION;
auto needed_block_it = needed_chunks_.find(ct_hash);
if(needed_block_it == needed_chunks_.end()) return;
auto& requests = needed_block_it->second->requests;
for(auto request_it = requests.begin(); request_it != requests.end();) {
bool incremented_already = false;
if(request_it->second.offset == offset // Chunk position incorrect
&& request_it->second.size == data.size() // Chunk size incorrect
&& request_it->first == from) { // Requested node != replied. Well, it isn't critical, but will be useful to ban "fake" peers
incremented_already = true;
request_it = requests.erase(request_it);
needed_block_it->second->put_block(offset, data);
if(needed_block_it->second->full()) {
exchange_group_.fs_dir()->put_chunk(ct_hash, needed_block_it->second->get_chunk());
} // TODO: catch "invalid hash" exception here
periodic_maintain_.invoke_post();
}
if(!incremented_already) ++request_it;
}
}
示例11: reject_iter
inline reject_iter(dtable::iter * base, dtable * rejects, blob reject_value)
: dtable_wrap_iter(base), rejects(rejects), reject_value(reject_value)
{
/* the reject value must exist, because nonexistent values
* can get pruned out if the shadow does not require them */
assert(reject_value.exists());
}
示例12: base
index_blob::index_blob(size_t count, const blob & x)
: base(x), modified(false), resized(false), count(count)
{
indices = new sub[count];
if(!x.exists())
{
/* same as default constructor */
modified = true;
resized = true;
return;
}
size_t offset = count * sizeof(uint32_t);
for(size_t i = 0; i < count; i++)
{
uint32_t size = base.index<uint32_t>(i);
if(size)
{
indices[i].delayed = true;
indices[i]._size = --size;
indices[i]._offset = offset;
offset += size;
}
else
assert(!indices[i].value.exists());
}
}
示例13:
binary& operator= (const binary& rhs) {
if (this != &rhs) {
m_blob = rhs.m_blob;
if (m_blob) m_blob->inc_rc();
}
return *this;
}
示例14: binary
/**
* Create a binary from the given data.
* Data is shared between all cloned binaries by using reference counting.
* @param data pointer to data.
* @param size binary size in bytes
* @param a_alloc is the allocator to use
**/
binary(const char* data, size_t size, const Alloc& a_alloc = Alloc()) {
if (size == 0) {
m_blob = nullptr;
return;
}
m_blob = new blob<char, Alloc>(size, a_alloc);
memcpy(m_blob->data(), data, size);
}
示例15: print
void print(const blob & x, const char * prefix, ...)
{
va_list ap;
va_start(ap, prefix);
if(!x.exists())
{
if(prefix)
vprintf(prefix, ap);
printf("(non-existent)\n");
va_end(ap);
return;
}
for(size_t i = 0; i < x.size(); i += 16)
{
size_t m = i + 16;
if(prefix)
vprintf(prefix, ap);
for(size_t j = i; j < m; j++)
{
if(j < x.size())
printf("%02x ", x[j]);
else
printf(" ");
if((i % 16) == 8)
printf(" ");
}
printf(" |");
for(size_t j = i; j < m; j++)
{
if(j < x.size())
printf("%c", isprint(x[j]) ? x[j] : '.');
else
printf(" ");
}
printf("|\n");
}
va_end(ap);
}