pitrou commented on a change in pull request #9656: URL: https://github.com/apache/arrow/pull/9656#discussion_r590513132
########## File path: cpp/src/arrow/ipc/reader.cc ########## @@ -958,10 +959,196 @@ Result<std::shared_ptr<RecordBatchStreamReader>> RecordBatchStreamReader::Open( // ---------------------------------------------------------------------- // Reader implementation +// Common functions used in both the random-access file reader and the +// asynchronous generator static inline FileBlock FileBlockFromFlatbuffer(const flatbuf::Block* block) { return FileBlock{block->offset(), block->metaDataLength(), block->bodyLength()}; } +Result<std::unique_ptr<Message>> ReadMessageFromBlock(const FileBlock& block, + io::RandomAccessFile* file) { + if (!BitUtil::IsMultipleOf8(block.offset) || + !BitUtil::IsMultipleOf8(block.metadata_length) || + !BitUtil::IsMultipleOf8(block.body_length)) { + return Status::Invalid("Unaligned block in IPC file"); + } + + // TODO(wesm): this breaks integration tests, see ARROW-3256 + // DCHECK_EQ((*out)->body_length(), block.body_length); + + ARROW_ASSIGN_OR_RAISE(auto message, + ReadMessage(block.offset, block.metadata_length, file)); + return std::move(message); +} + +Status ReadOneDictionary(Message* message, const IpcReadContext& context) { + CHECK_HAS_BODY(*message); + ARROW_ASSIGN_OR_RAISE(auto reader, Buffer::GetReader(message->body())); + DictionaryKind kind; + RETURN_NOT_OK(ReadDictionary(*message->metadata(), context, &kind, reader.get())); + if (kind != DictionaryKind::New) { + return Status::Invalid( + "Unsupported dictionary replacement or " + "dictionary delta in IPC file"); + } + return Status::OK(); +} + +/// Common state used by the IPC message generator and record batch generator. +struct ARROW_EXPORT IpcFileRecordBatchGeneratorState { Review comment: You could also avoid the "state" struct and put the desired fields directly in the generator classes (I'm not sure why you need two of them, by the way, unless you plan to do something else later with the IPC message generator). ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org