vortex_array/vtable/
serde.rs

1use vortex_dtype::DType;
2use vortex_error::{VortexExpect, VortexResult, vortex_bail};
3
4use crate::serde::ArrayParts;
5use crate::{Array, ArrayContext, ArrayRef, Encoding};
6
7// TODO(ngates): need a new name for this VTable.
8pub trait SerdeVTable<Array> {
9    /// Decode an [`ArrayParts`] into an [`ArrayRef`] of this encoding.
10    fn decode(
11        &self,
12        parts: &ArrayParts,
13        ctx: &ArrayContext,
14        _dtype: DType,
15        _len: usize,
16    ) -> VortexResult<ArrayRef> {
17        vortex_bail!(
18            "Decoding not supported for encoding {}",
19            ctx.lookup_encoding(parts.encoding_id())
20                .vortex_expect("Encoding already validated")
21                .id()
22        )
23    }
24}
25
26impl<'a, E: Encoding> SerdeVTable<&'a dyn Array> for E
27where
28    E: SerdeVTable<&'a E::Array>,
29{
30    fn decode(
31        &self,
32        parts: &ArrayParts,
33        ctx: &ArrayContext,
34        dtype: DType,
35        len: usize,
36    ) -> VortexResult<ArrayRef> {
37        <E as SerdeVTable<&'a E::Array>>::decode(self, parts, ctx, dtype, len)
38    }
39}