use arrow_array::{Array, ArrayRef, UInt32Array};
use async_trait::async_trait;
pub mod binary;
pub mod dictionary;
pub mod plain;
pub mod rle;
use crate::error::Result;
use crate::format::pb;
use crate::io::ReadBatchParams;
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum Encoding {
Plain,
VarBinary,
Dictionary,
RLE,
}
impl From<Encoding> for pb::Encoding {
fn from(e: Encoding) -> Self {
match e {
Encoding::Plain => Self::Plain,
Encoding::VarBinary => Self::VarBinary,
Encoding::Dictionary => Self::Dictionary,
Encoding::RLE => Self::Rle,
}
}
}
#[async_trait]
pub trait Encoder {
async fn encode(&mut self, array: &dyn Array) -> Result<usize>;
}
#[async_trait]
pub(crate) trait Decoder: Send + AsyncIndex<ReadBatchParams> {
async fn decode(&self) -> Result<ArrayRef>;
async fn take(&self, indices: &UInt32Array) -> Result<ArrayRef>;
}
#[async_trait]
pub trait AsyncIndex<IndexType> {
type Output: Send + Sync;
async fn get(&self, index: IndexType) -> Self::Output;
}