use arrow::{
datatypes::{Schema as ArrowSchema, SchemaRef as ArrowSchemaRef},
error::ArrowError,
};
pub fn ipc_from_schema(schema: &ArrowSchema) -> Result<Vec<u8>, ArrowError> {
re_tracing::profile_function!();
let mut ipc_bytes = Vec::<u8>::new();
let mut writer = arrow::ipc::writer::StreamWriter::try_new(&mut ipc_bytes, schema)?;
writer.finish()?;
Ok(ipc_bytes)
}
pub fn raw_schema_from_ipc(ipc_bytes: &[u8]) -> Result<ArrowSchemaRef, ArrowError> {
re_tracing::profile_function!();
let cursor = std::io::Cursor::new(ipc_bytes);
let stream = arrow::ipc::reader::StreamReader::try_new(cursor, None)?;
Ok(stream.schema())
}
pub fn migrated_schema_from_ipc(ipc_bytes: &[u8]) -> Result<ArrowSchemaRef, ArrowError> {
re_tracing::profile_function!();
raw_schema_from_ipc(ipc_bytes).map(crate::migrate_schema_ref)
}