use arrow::{
datatypes::{Schema as ArrowSchema, SchemaRef as ArrowSchemaRef},
error::ArrowError,
};
pub fn ipc_from_schema(schema: &ArrowSchema) -> Result<Vec<u8>, ArrowError> {
let mut ipc_bytes = Vec::<u8>::new();
#[allow(clippy::disallowed_types)] let mut writer = arrow::ipc::writer::StreamWriter::try_new(&mut ipc_bytes, schema)?;
writer.finish()?;
Ok(ipc_bytes)
}
pub fn schema_from_ipc(ipc_bytes: &[u8]) -> Result<ArrowSchemaRef, ArrowError> {
let cursor = std::io::Cursor::new(ipc_bytes);
let stream = arrow::ipc::reader::StreamReader::try_new(cursor, None)?;
Ok(stream.schema())
}