MCPcopy Create free account
hub / github.com/FoundationDB/fdb-document-layer / peekExact

Method peekExact

src/BufferedConnection.actor.cpp:168–193  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

166}
167
168StringRef BufferedConnection::peekExact(int count) {
169 ASSERT(count <= self->total_bytes.get());
170
171 if (self->buffer_begin_offset + count <= BCBlock::DATA_SIZE) {
172 /* requested byte range is in a single block */
173 return {self->buffer.front()->data + self->buffer_begin_offset, count};
174 } else {
175 /* find the _last_ block containing data for this range */
176 int remaining = count - (BCBlock::DATA_SIZE - self->buffer_begin_offset);
177
178 auto it = ++(self->buffer.begin());
179
180 while (remaining > BCBlock::DATA_SIZE) {
181 ++it;
182 remaining -= BCBlock::DATA_SIZE;
183 }
184
185 /* Allocate memory in the arena of the last block from which we are copying, and copy the requested range into
186 * the newly allocated memory */
187 auto* buf = new ((*it)->arena) uint8_t[count];
188
189 self->copyInto(buf, count);
190
191 return {buf, count};
192 }
193}
194
195void BufferedConnection::advance(int count) {
196 ASSERT(count <= self->total_bytes.get());

Callers 2

DocLayer.actor.cppFile · 0.80

Calls 3

beginMethod · 0.80
copyIntoMethod · 0.80
getMethod · 0.45

Tested by

no test coverage detected