use serde::{Deserialize, Serialize};
use std::collections::BTreeMap;
use crate::dtype::Dtype;
pub use tensogram_encodings::ByteOrder;
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct HashDescriptor {
#[serde(rename = "type")]
pub hash_type: String,
pub value: String,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct DataObjectDescriptor {
#[serde(rename = "type")]
pub obj_type: String,
pub ndim: u64,
pub shape: Vec<u64>,
pub strides: Vec<u64>,
pub dtype: Dtype,
pub byte_order: ByteOrder,
pub encoding: String,
pub filter: String,
pub compression: String,
#[serde(flatten)]
pub params: BTreeMap<String, ciborium::Value>,
#[serde(skip_serializing_if = "Option::is_none")]
pub hash: Option<HashDescriptor>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct GlobalMetadata {
pub version: u16,
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub base: Vec<BTreeMap<String, ciborium::Value>>,
#[serde(
rename = "_reserved_",
default,
skip_serializing_if = "BTreeMap::is_empty"
)]
pub reserved: BTreeMap<String, ciborium::Value>,
#[serde(
rename = "_extra_",
default,
skip_serializing_if = "BTreeMap::is_empty"
)]
pub extra: BTreeMap<String, ciborium::Value>,
}
#[derive(Debug, Clone, Default)]
pub struct IndexFrame {
pub object_count: u64,
pub offsets: Vec<u64>,
pub lengths: Vec<u64>,
}
#[derive(Debug, Clone)]
pub struct HashFrame {
pub object_count: u64,
pub hash_type: String,
pub hashes: Vec<String>,
}
impl Default for GlobalMetadata {
fn default() -> Self {
Self {
version: 2,
base: Vec::new(),
reserved: BTreeMap::new(),
extra: BTreeMap::new(),
}
}
}
pub type DecodedObject = (DataObjectDescriptor, Vec<u8>);