pub fn read_batch<R: Read + Seek>(
    reader: &mut R,
    metadata: &FileMetadata,
    block: usize,
) -> Result<Option<RecordBatch>> {
    let block = metadata.blocks[block];

    // read length
    reader.seek(SeekFrom::Start(block.offset() as u64))?;
    let mut meta_buf = [0; 4];
    reader.read_exact(&mut meta_buf)?;
    if meta_buf == CONTINUATION_MARKER {
        // continuation marker encountered, read message next
        reader.read_exact(&mut meta_buf)?;
    }
    let meta_len = i32::from_le_bytes(meta_buf);

    let mut block_data = vec![0; meta_len as usize];
    reader.read_exact(&mut block_data)?;

    let message = gen::Message::root_as_message(&block_data[..])
        .map_err(|err| ArrowError::Ipc(format!("Unable to get root as footer: {:?}", err)))?;

    // some old test data's footer metadata is not set, so we account for that
    if metadata.version != gen::Schema::MetadataVersion::V1 && message.version() != metadata.version
    {
        return Err(ArrowError::Ipc(
            "Could not read IPC message as metadata versions mismatch".to_string(),
        ));
    }

    match message.header_type() {
        gen::Message::MessageHeader::Schema => Err(ArrowError::Ipc(
            "Not expecting a schema when messages are read".to_string(),
        )),
        gen::Message::MessageHeader::RecordBatch => {
            let batch = message.header_as_record_batch().ok_or_else(|| {
                ArrowError::Ipc("Unable to read IPC message as record batch".to_string())
            })?;
            read_record_batch(
                batch,
                metadata.schema.clone(),
                metadata.is_little_endian,
                &metadata.dictionaries_by_field,
                reader,
                block.offset() as u64 + block.metaDataLength() as u64,
            )
            .map(Some)
        }
        gen::Message::MessageHeader::NONE => Ok(None),
        t => Err(ArrowError::Ipc(format!(
            "Reading types other than record batches not yet supported, unable to read {:?}",
            t
        ))),
    }
}
/// Read the IPC file's metadata
Read the IPC file's metadata
Read the IPC file ' s metadata
pub fn read_batch<R: Read + Seek>(
    reader: &mut R,
    metadata: &FileMetadata,
    block: usize,
) -> Result<Option<RecordBatch>> {
    let block = metadata.blocks[block];
    // read length
    reader.seek(SeekFrom::Start(block.offset() as u64))?;
    let mut meta_buf = [0; 4];
    reader.read_exact(&mut meta_buf)?;
    if meta_buf == CONTINUATION_MARKER {
        // continuation marker encountered, read message next
        reader.read_exact(&mut meta_buf)?;
    }
    let meta_len = i32::from_le_bytes(meta_buf);
    let mut block_data = vec![0; meta_len as usize];
    reader.read_exact(&mut block_data)?;
    let message = gen::Message::root_as_message(&block_data[..])
        .map_err(|err| ArrowError::Ipc(format!("Unable to get root as footer: {:?}", err)))?;
    // some old test data's footer metadata is not set, so we account for that
    if metadata.version != gen::Schema::MetadataVersion::V1 && message.version() != metadata.version
    {
        return Err(ArrowError::Ipc(
            "Could not read IPC message as metadata versions mismatch".to_string(),
        ));
    }
    match message.header_type() {
        gen::Message::MessageHeader::Schema => Err(ArrowError::Ipc(
            "Not expecting a schema when messages are read".to_string(),
        )),
        gen::Message::MessageHeader::RecordBatch => {
            let batch = message.header_as_record_batch().ok_or_else(|| {
                ArrowError::Ipc("Unable to read IPC message as record batch".to_string())
            })?;
            read_record_batch(
                batch,
                metadata.schema.clone(),
                metadata.is_little_endian,
                &metadata.dictionaries_by_field,
                reader,
                block.offset() as u64 + block.metaDataLength() as u64,
            )
            .map(Some)
        }
        gen::Message::MessageHeader::NONE => Ok(None),
        t => Err(ArrowError::Ipc(format!(
            "Reading types other than record batches not yet supported, unable to read {:?}",
            t
        ))),
    }
}
pub fn read_batch < R : Read + Seek > ( reader : & mut R , metadata : & FileMetadata , block : usize , ) -> Result < Option < RecordBatch > > { let block = metadata . blocks [ block ] ; // read length reader . seek ( SeekFrom :: Start ( block . offset ( ) as u64 ) ) ? ; let mut meta_buf = [ 0 ; 4 ] ; reader . read_exact ( & mut meta_buf ) ? ; if meta_buf == CONTINUATION_MARKER { // continuation marker encountered, read message next reader . read_exact ( & mut meta_buf ) ? ; } let meta_len = i32 :: from_le_bytes ( meta_buf ) ; let mut block_data = vec ! [ 0 meta_len as usize ] ; reader . read_exact ( & mut block_data ) ? ; let message = gen :: Message :: root_as_message ( & block_data [ .. ] ) . map_err ( | err | ArrowError :: Ipc ( format ! ( " " err ) ) ) ? ; // some old test data's footer metadata is not set, so we account for that if metadata . version != gen :: Schema :: MetadataVersion :: V1 && message . version ( ) != metadata . version { return Err ( ArrowError :: Ipc ( " " . to_string ( ) , ) ) ; } match message . header_type ( ) { gen :: Message :: MessageHeader :: Schema => Err ( ArrowError :: Ipc ( " " . to_string ( ) , ) ) , gen :: Message :: MessageHeader :: RecordBatch => { let batch = message . header_as_record_batch ( ) . ok_or_else ( | | { ArrowError :: Ipc ( " " . to_string ( ) ) } ) ? ; read_record_batch ( batch , metadata . schema . clone ( ) , metadata . is_little_endian , & metadata . dictionaries_by_field , reader , block . offset ( ) as u64 + block . metaDataLength ( ) as u64 , ) . map ( Some ) } gen :: Message :: MessageHeader :: NONE => Ok ( None ) , t => Err ( ArrowError :: Ipc ( format ! ( " " t ) ) ) , } }
Read the IPC file's metadata
Read the IPC file ' s metadata
reader
&mut R
metadata
&FileMetadata
block
usize