| 166 | } |
| 167 | |
| 168 | StringRef 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 | |
| 195 | void BufferedConnection::advance(int count) { |
| 196 | ASSERT(count <= self->total_bytes.get()); |
no test coverage detected