pub mod asciitable;
pub mod bintable;
pub mod image;
use std::io::Read;
use async_trait::async_trait;
use futures::AsyncRead;
use crate::card::Value;
use crate::error::Error;
use crate::hdu::primary::check_card_keyword;
use std::collections::HashMap;
#[derive(Debug)]
pub enum XtensionType {
Image,
BinTable,
AsciiTable,
}
pub fn parse_xtension_card(card: &[u8; 80]) -> Result<XtensionType, Error> {
let xtension = check_card_keyword(card, b"XTENSION")?.check_for_string()?;
match xtension.as_bytes() {
b"IMAGE " | b"IUEIMAGE" => Ok(XtensionType::Image),
b"TABLE " => Ok(XtensionType::AsciiTable),
b"BINTABLE" => Ok(XtensionType::BinTable),
_ => Err(Error::NotSupportedXtensionType(xtension)),
}
}
#[async_trait(?Send)]
pub trait Xtension {
fn get_num_bytes_data_block(&self) -> u64;
fn update_with_parsed_header(&mut self, cards: &HashMap<[u8; 8], Value>) -> Result<(), Error>;
fn parse<R: Read>(
reader: &mut R,
num_bytes_read: &mut u64,
card_80_bytes_buf: &mut [u8; 80],
) -> Result<Self, Error>
where
Self: Sized;
async fn parse_async<R>(
reader: &mut R,
num_bytes_read: &mut u64,
card_80_bytes_buf: &mut [u8; 80],
) -> Result<Self, Error>
where
Self: Sized,
R: AsyncRead + std::marker::Unpin;
}