`const data constslice slice append` C++ Examples
13 C++ code examples are found related to "const data constslice slice append".
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
Example 1
Source File: memenv.cc From ndslDB with BSD 3-Clause "New" or "Revised" License | 6 votes |
Status Append(const Slice& data) { const char* src = data.data(); size_t src_len = data.size(); while (src_len > 0) { size_t avail; size_t offset = size_ % kBlockSize; if (offset != 0) { // There is some room in the last block. avail = kBlockSize - offset; } else { // No room in the last block; push new one. blocks_.push_back(new char[kBlockSize]); avail = kBlockSize; } if (avail > src_len) { avail = src_len; } memcpy(blocks_.back() + offset, src, avail); src_len -= avail; src += avail; size_ += avail; }
Example 2
Source File: env_encryption.cc From GrinPlusPlus with MIT License | 6 votes |
Status PositionedAppend(const Slice& data, uint64_t offset) override { AlignedBuffer buf; Status status; Slice dataToAppend(data); offset += prefixLength_; if (data.size() > 0) { // Encrypt in cloned buffer buf.Alignment(GetRequiredBufferAlignment()); buf.AllocateNewBuffer(data.size()); memmove(buf.BufferStart(), data.data(), data.size()); buf.Size(data.size()); status = stream_->Encrypt(offset, buf.BufferStart(), buf.CurrentSize()); if (!status.ok()) { return status; } dataToAppend = Slice(buf.BufferStart(), buf.CurrentSize()); } status = file_->PositionedAppend(dataToAppend, offset); if (!status.ok()) { return status; } return status; }
Example 3
Source File: env_encryption.cc From GrinPlusPlus with MIT License | 6 votes |
Status Append(const Slice& data) override { AlignedBuffer buf; Status status; Slice dataToAppend(data); if (data.size() > 0) { auto offset = file_->GetFileSize(); // size including prefix // Encrypt in cloned buffer buf.Alignment(GetRequiredBufferAlignment()); buf.AllocateNewBuffer(data.size()); // TODO (sagar0): Modify AlignedBuffer.Append to allow doing a memmove // so that the next two lines can be replaced with buf.Append(). memmove(buf.BufferStart(), data.data(), data.size()); buf.Size(data.size()); status = stream_->Encrypt(offset, buf.BufferStart(), buf.CurrentSize()); if (!status.ok()) { return status; } dataToAppend = Slice(buf.BufferStart(), buf.CurrentSize()); } status = file_->Append(dataToAppend); if (!status.ok()) { return status; } return status; }
Example 4
Source File: env_windows.cc From verge with MIT License | 5 votes |
Status Append(const Slice& data) override { size_t write_size = data.size(); const char* write_data = data.data(); // Fit as much as possible into buffer. size_t copy_size = std::min(write_size, kWritableFileBufferSize - pos_); std::memcpy(buf_ + pos_, write_data, copy_size); write_data += copy_size; write_size -= copy_size; pos_ += copy_size; if (write_size == 0) { return Status::OK(); } // Can't fit in buffer, so need to do at least one write. Status status = FlushBuffer(); if (!status.ok()) { return status; } // Small writes go to buffer, large writes are written directly. if (write_size < kWritableFileBufferSize) { std::memcpy(buf_, write_data, write_size); pos_ = write_size; return Status::OK(); } return WriteUnbuffered(write_data, write_size); }