| 214 | } |
| 215 | |
| 216 | Status ScannerContext::Stream::GetBuffer(bool peek, uint8_t** out_buffer, int64_t* len) { |
| 217 | *out_buffer = nullptr; |
| 218 | *len = 0; |
| 219 | if (eosr()) return Status::OK(); |
| 220 | |
| 221 | if (UNLIKELY(parent_->cancelled())) { |
| 222 | DCHECK(*out_buffer == nullptr); |
| 223 | return CONTEXT_CANCELLED; |
| 224 | } |
| 225 | |
| 226 | if (boundary_buffer_bytes_left_ > 0) { |
| 227 | DCHECK(ValidateBufferPointers()); |
| 228 | DCHECK_EQ(output_buffer_bytes_left_, &boundary_buffer_bytes_left_); |
| 229 | *out_buffer = boundary_buffer_pos_; |
| 230 | // Don't return more bytes past eosr |
| 231 | *len = min(boundary_buffer_bytes_left_, bytes_left()); |
| 232 | DCHECK_GE(*len, 0); |
| 233 | if (!peek) { |
| 234 | AdvanceBufferPos(*len, &boundary_buffer_pos_, &boundary_buffer_bytes_left_); |
| 235 | total_bytes_returned_ += *len; |
| 236 | } |
| 237 | return Status::OK(); |
| 238 | } |
| 239 | |
| 240 | if (io_buffer_bytes_left_ == 0) { |
| 241 | // We're at the end of the boundary buffer and the current IO buffer. Get a new IO |
| 242 | // buffer and set the current buffer to it. |
| 243 | RETURN_IF_ERROR(GetNextBuffer()); |
| 244 | // Check that we're not pointing to the IO buffer if there are bytes left in the |
| 245 | // boundary buffer. |
| 246 | DCHECK_EQ(boundary_buffer_bytes_left_, 0); |
| 247 | output_buffer_pos_ = &io_buffer_pos_; |
| 248 | output_buffer_bytes_left_ = &io_buffer_bytes_left_; |
| 249 | } |
| 250 | DCHECK(io_buffer_ != nullptr); |
| 251 | |
| 252 | *out_buffer = io_buffer_pos_; |
| 253 | *len = io_buffer_bytes_left_; |
| 254 | if (!peek) { |
| 255 | AdvanceBufferPos(*len, &io_buffer_pos_, &io_buffer_bytes_left_); |
| 256 | total_bytes_returned_ += *len; |
| 257 | } |
| 258 | DCHECK_GE(bytes_left(), 0); |
| 259 | DCHECK(ValidateBufferPointers()); |
| 260 | return Status::OK(); |
| 261 | } |
| 262 | |
| 263 | Status ScannerContext::Stream::GetBytesInternal(int64_t requested_len, |
| 264 | uint8_t** out_buffer, bool peek, int64_t* out_len) { |
no test coverage detected