| 285 | namespace { |
| 286 | |
| 287 | Status ReadFieldsSubset(int64_t offset, io::RandomAccessFile* file, |
| 288 | const FieldsLoaderFunction& fields_loader, |
| 289 | const std::shared_ptr<Buffer>& metadata, int64_t required_size, |
| 290 | std::shared_ptr<Buffer>& body) { |
| 291 | DCHECK_GE(static_cast<size_t>(metadata->size()), sizeof(int32_t)); |
| 292 | const auto continuation = util::SafeLoadAs<int32_t>(metadata->data()); |
| 293 | // Either 8 bytes (32-bit continuation indicator + 32-bit little-endian length prefix) |
| 294 | // or 4 bytes for legacy IPC without continuation indicator |
| 295 | const auto continuation_size = (continuation == internal::kIpcContinuationToken) |
| 296 | ? 2 * sizeof(int32_t) |
| 297 | : sizeof(int32_t); |
| 298 | |
| 299 | const flatbuf::Message* message = nullptr; |
| 300 | RETURN_NOT_OK(internal::VerifyMessage(metadata->data() + continuation_size, |
| 301 | metadata->size() - continuation_size, &message)); |
| 302 | auto batch = message->header_as_RecordBatch(); |
| 303 | if (batch == nullptr) { |
| 304 | return Status::IOError( |
| 305 | "Header-type of flatbuffer-encoded Message is not RecordBatch."); |
| 306 | } |
| 307 | internal::IoRecordedRandomAccessFile io_recorded_random_access_file(required_size); |
| 308 | RETURN_NOT_OK(fields_loader(batch, &io_recorded_random_access_file)); |
| 309 | const auto& read_ranges = io_recorded_random_access_file.GetReadRanges(); |
| 310 | for (const auto& range : read_ranges) { |
| 311 | auto read_result = file->ReadAt(offset + metadata->size() + range.offset, |
| 312 | range.length, body->mutable_data() + range.offset); |
| 313 | if (!read_result.ok()) { |
| 314 | return Status::IOError("Failed to read message body, error ", |
| 315 | read_result.status().ToString()); |
| 316 | } |
| 317 | } |
| 318 | return Status::OK(); |
| 319 | } |
| 320 | |
| 321 | struct ReadMessageState { |
| 322 | std::unique_ptr<Message> result; |
no test coverage detected