mirror of
https://github.com/XRPLF/rippled.git
synced 2025-12-06 17:27:55 +00:00
WriteBatch::Put() overload that gathers key and value from arrays of slices
Summary: In our project, when writing to the database, we want to form the value as the concatenation of a small header and a larger payload. It's a shame to have to copy the payload just so we can give RocksDB API a linear view of the value. Since RocksDB makes a copy internally, it's easy to support gather writes. Test Plan: write_batch_test, new test case Reviewers: dhruba CC: leveldb Differential Revision: https://reviews.facebook.net/D13947
This commit is contained in:
@@ -107,6 +107,18 @@ void PutLengthPrefixedSlice(std::string* dst, const Slice& value) {
|
||||
dst->append(value.data(), value.size());
|
||||
}
|
||||
|
||||
void PutLengthPrefixedSliceParts(std::string* dst,
|
||||
const SliceParts& slice_parts) {
|
||||
uint32_t total_bytes = 0;
|
||||
for (int i = 0; i < slice_parts.num_parts; ++i) {
|
||||
total_bytes += slice_parts.parts[i].size();
|
||||
}
|
||||
PutVarint32(dst, total_bytes);
|
||||
for (int i = 0; i < slice_parts.num_parts; ++i) {
|
||||
dst->append(slice_parts.parts[i].data(), slice_parts.parts[i].size());
|
||||
}
|
||||
}
|
||||
|
||||
int VarintLength(uint64_t v) {
|
||||
int len = 1;
|
||||
while (v >= 128) {
|
||||
|
||||
@@ -30,6 +30,8 @@ extern void PutFixed64(std::string* dst, uint64_t value);
|
||||
extern void PutVarint32(std::string* dst, uint32_t value);
|
||||
extern void PutVarint64(std::string* dst, uint64_t value);
|
||||
extern void PutLengthPrefixedSlice(std::string* dst, const Slice& value);
|
||||
extern void PutLengthPrefixedSliceParts(std::string* dst,
|
||||
const SliceParts& slice_parts);
|
||||
|
||||
// Standard Get... routines parse a value from the beginning of a Slice
|
||||
// and advance the slice past the parsed value.
|
||||
|
||||
Reference in New Issue
Block a user