use serde::{Deserialize, Serialize};
#[non_exhaustive]
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub enum ZarrDataType {
Float32,
Float64,
Int32,
Int64,
UInt8,
UInt16,
UInt32,
}
impl ZarrDataType {
pub fn byte_size(&self) -> usize {
match self {
ZarrDataType::Float32 => 4,
ZarrDataType::Float64 => 8,
ZarrDataType::Int32 => 4,
ZarrDataType::Int64 => 8,
ZarrDataType::UInt8 => 1,
ZarrDataType::UInt16 => 2,
ZarrDataType::UInt32 => 4,
}
}
pub fn as_str(&self) -> &'static str {
match self {
ZarrDataType::Float32 => "float32",
ZarrDataType::Float64 => "float64",
ZarrDataType::Int32 => "int32",
ZarrDataType::Int64 => "int64",
ZarrDataType::UInt8 => "uint8",
ZarrDataType::UInt16 => "uint16",
ZarrDataType::UInt32 => "uint32",
}
}
}
#[non_exhaustive]
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub enum ZarrCompressor {
None,
Blosc {
cname: String,
clevel: u8,
},
GZip {
level: u8,
},
Zstd {
level: u8,
},
}
#[non_exhaustive]
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ZarrArrayMeta {
pub shape: Vec<usize>,
pub chunks: Vec<usize>,
pub dtype: ZarrDataType,
pub compressor: ZarrCompressor,
pub fill_value: f64,
pub zarr_format: u8,
pub dimension_separator: char,
}
impl Default for ZarrArrayMeta {
fn default() -> Self {
Self {
shape: vec![],
chunks: vec![],
dtype: ZarrDataType::Float64,
compressor: ZarrCompressor::None,
fill_value: 0.0,
zarr_format: 3,
dimension_separator: '/',
}
}
}
pub struct ZarrArray {
pub meta: ZarrArrayMeta,
pub(crate) data: Vec<f64>,
}
impl ZarrArray {
pub fn new(meta: ZarrArrayMeta, data: Vec<f64>) -> Self {
Self { meta, data }
}
pub fn len(&self) -> usize {
self.data.len()
}
pub fn is_empty(&self) -> bool {
self.data.is_empty()
}
pub fn as_slice(&self) -> &[f64] {
&self.data
}
}