本文整理汇总了C++中BString::reserveBuffer方法的典型用法代码示例。如果您正苦于以下问题:C++ BString::reserveBuffer方法的具体用法?C++ BString::reserveBuffer怎么用?C++ BString::reserveBuffer使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BString
的用法示例。
在下文中一共展示了BString::reserveBuffer方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: get
bool Slice::get(BString &data, const ItemRequest &item)
{
AutoReadWriteLockRead autoSyncRead(&_sync);
if (item.pointer.seek >= _size) {
log::Fatal::L("Can't get out of range sliceID %u, seek %u\n", _sliceID, item.pointer.seek);
return false;
}
ssize_t readSize = item.size + sizeof(ItemHeader);
if (_dataFd.pread(data.reserveBuffer(readSize), readSize, item.pointer.seek) != readSize) {
log::Fatal::L("Can't read data file from seek sliceID %u, seek %u\n", _sliceID, item.pointer.seek);
return false;
}
return true;
}
示例2: getItems
bool Range::getItems(const TRangeID rangeID, BString &data)
{
AutoMutex autoSync(&_sync);
RangeItemsHeader &header = *(RangeItemsHeader*)data.reserveBuffer(sizeof(RangeItemsHeader));
header.rangeID = rangeID;
header.count = _items.size();
RangeItemEntry itemEntry;
for (auto item = _items.begin(); item != _items.end(); item++) {
itemEntry.itemKey = item->first;
itemEntry.size = item->second.size;
itemEntry.timeTag = item->second.timeTag;
data.add((char*)&itemEntry, sizeof(itemEntry));
}
return true;
}
示例3: _writeItem
bool Slice::_writeItem(File &putTmpFile, BString &buf, IndexEntry &ie)
{
if (_dataFd.seek(_size, SEEK_SET) != (off_t)_size) {
log::Fatal::L("Can't seek slice dataFile %u\n", _sliceID);
return false;
}
const ItemHeader &itemHeader = ie.header;
if (_dataFd.write(&itemHeader, sizeof(itemHeader)) != sizeof(itemHeader)) {
log::Fatal::L("Can't write header to slice dataFile %u\n", _sliceID);
return false;
}
auto leftSize = ie.header.size;
while (leftSize > 0) {
TItemSize chunkSize = MAX_BUF_SIZE;
if (chunkSize > leftSize)
chunkSize = leftSize;
buf.clear();
if (putTmpFile.read(buf.reserveBuffer(chunkSize), chunkSize) != (ssize_t)chunkSize) {
log::Fatal::L("Can't read data from put tmp file %u\n", _sliceID);
return false;
}
if (_dataFd.write(buf.c_str(), buf.size()) != (ssize_t)buf.size()) {
log::Fatal::L("Can't write data to slice dataFile %u\n", _sliceID);
return false;
}
leftSize -= chunkSize;
}
ie.pointer.sliceID = _sliceID;
ie.pointer.seek = _size;
if (_indexFd.write(&ie, sizeof(ie)) != sizeof(ie)) {
log::Fatal::L("Can't write index entry to slice indexFile %u\n", _sliceID);
return false;
}
_size = _dataFd.seek(0, SEEK_CUR);
return true;
}
示例4: addRealEscape
void Mysql::addRealEscape(BString &buf, const char *value, const long length)
{
auto currentSize = buf.size();
currentSize += mysql_real_escape_string(_mysql.get(), buf.reserveBuffer(length * 2 + 1), value, length);
buf.trim(currentSize);
}