liukun4515 commented on code in PR #1855: URL: https://github.com/apache/arrow-rs/pull/1855#discussion_r934103867
########## arrow/src/ipc/reader.rs: ########## @@ -32,15 +32,78 @@ use crate::error::{ArrowError, Result}; use crate::ipc; use crate::record_batch::{RecordBatch, RecordBatchOptions, RecordBatchReader}; +use crate::ipc::compression::ipc_compression::CompressionCodecType; +use crate::ipc::compression::{ + LENGTH_EMPTY_COMPRESSED_DATA, LENGTH_NO_COMPRESSED_DATA, LENGTH_OF_PREFIX_DATA, +}; +use crate::ipc::CompressionType; use ipc::CONTINUATION_MARKER; use DataType::*; /// Read a buffer based on offset and length -fn read_buffer(buf: &ipc::Buffer, a_data: &[u8]) -> Buffer { +/// From <https://github.com/apache/arrow/blob/6a936c4ff5007045e86f65f1a6b6c3c955ad5103/format/Message.fbs#L58> +/// Each constituent buffer is first compressed with the indicated +/// compressor, and then written with the uncompressed length in the first 8 +/// bytes as a 64-bit little-endian signed integer followed by the compressed +/// buffer bytes (and then padding as required by the protocol). The +/// uncompressed length may be set to -1 to indicate that the data that +/// follows is not compressed, which can be useful for cases where +/// compression does not yield appreciable savings. +fn read_buffer( + buf: &ipc::Buffer, + a_data: &[u8], + compression_codec: &CompressionCodecType, +) -> Buffer { let start_offset = buf.offset() as usize; let end_offset = start_offset + buf.length() as usize; let buf_data = &a_data[start_offset..end_offset]; - Buffer::from(&buf_data) + // corner case: empty buffer + if buf_data.is_empty() { + return Buffer::from(buf_data); + } + match compression_codec { + CompressionCodecType::Lz4Frame | CompressionCodecType::Zstd + if cfg!(feature = "ipc_compression") || cfg!(test) => Review Comment: need to check the compile options, if receive a message or ipc message with the compression feature. -- 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. To unsubscribe, e-mail: github-unsubscr...@arrow.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org