MCPcopy Create free account
hub / github.com/apache/impala / BitFlipFileByteRange

Method BitFlipFileByteRange

be/src/kudu/util/pb_util-test.cc:158–190  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

156}
157
158Status TestPBUtil::BitFlipFileByteRange(const string& path, uint64_t offset, uint64_t length) {
159 faststring buf;
160 // Read the data from disk.
161 {
162 unique_ptr<RandomAccessFile> file;
163 RandomAccessFileOptions opts;
164 opts.is_sensitive = false;
165 RETURN_NOT_OK(env_->NewRandomAccessFile(opts, path, &file));
166 uint64_t size;
167 RETURN_NOT_OK(file->Size(&size));
168 faststring scratch;
169 scratch.resize(size);
170 Slice slice(scratch.data(), size);
171 RETURN_NOT_OK(file->Read(0, slice));
172 buf.append(slice.data(), slice.size());
173 }
174
175 // Flip the bits.
176 for (uint64_t i = 0; i < length; i++) {
177 uint8_t* addr = buf.data() + offset + i;
178 *addr = ~*addr;
179 }
180
181 // Write the data back to disk.
182 unique_ptr<WritableFile> file;
183 WritableFileOptions opts;
184 opts.is_sensitive = false;
185 RETURN_NOT_OK(env_->NewWritableFile(opts, path, &file));
186 RETURN_NOT_OK(file->Append(buf));
187 RETURN_NOT_OK(file->Close());
188
189 return Status::OK();
190}
191
192Status TestPBUtil::TruncateFile(const string& path, uint64_t size) {
193 unique_ptr<RWFile> file;

Callers

nothing calls this directly

Calls 11

OKFunction · 0.85
NewRandomAccessFileMethod · 0.80
resizeMethod · 0.80
NewWritableFileMethod · 0.80
SizeMethod · 0.45
dataMethod · 0.45
ReadMethod · 0.45
appendMethod · 0.45
sizeMethod · 0.45
AppendMethod · 0.45
CloseMethod · 0.45

Tested by

no test coverage detected