Common helper for the two ReadMessage overloads that take a file + offset. When body_length is provided, metadata and body are read in a single IO. When body_length is absent, metadata is read first, then the body is read separately.
| 453 | // When body_length is absent, metadata is read first, then the body is read |
| 454 | // separately. |
| 455 | static Result<std::unique_ptr<Message>> ReadMessageInternal( |
| 456 | int64_t offset, int32_t metadata_length, std::optional<int64_t> body_length, |
| 457 | io::RandomAccessFile* file, const FieldsLoaderFunction& fields_loader) { |
| 458 | ReadMessageState state; |
| 459 | |
| 460 | if (metadata_length < state.decoder->next_required_size()) { |
| 461 | return Status::Invalid("metadata_length should be at least ", |
| 462 | state.decoder->next_required_size()); |
| 463 | } |
| 464 | // When body_length is known, read metadata + body in one IO call. |
| 465 | // Otherwise, read only metadata first. |
| 466 | ARROW_ASSIGN_OR_RAISE(std::shared_ptr<Buffer> metadata, |
| 467 | file->ReadAt(offset, metadata_length + body_length.value_or(0), |
| 468 | /*allow_short_read=*/false)); |
| 469 | |
| 470 | return ReadMessageContinued(offset, metadata_length, body_length, metadata, file, |
| 471 | fields_loader, &state); |
| 472 | } |
| 473 | |
| 474 | Result<std::unique_ptr<Message>> ReadMessage(int64_t offset, int32_t metadata_length, |
| 475 | io::RandomAccessFile* file, |
no test coverage detected