vortex_zigzag/
serde.rs

1use vortex_array::serde::ArrayParts;
2use vortex_array::vtable::SerdeVTable;
3use vortex_array::{
4    Array, ArrayChildVisitor, ArrayContext, ArrayRef, ArrayVisitorImpl, EmptyMetadata,
5};
6use vortex_dtype::{DType, PType};
7use vortex_error::{VortexResult, vortex_bail};
8
9use crate::{ZigZagArray, ZigZagEncoding};
10
11impl ArrayVisitorImpl for ZigZagArray {
12    fn _children(&self, visitor: &mut dyn ArrayChildVisitor) {
13        visitor.visit_child("encoded", self.encoded())
14    }
15
16    fn _metadata(&self) -> EmptyMetadata {
17        EmptyMetadata
18    }
19}
20
21impl SerdeVTable<&ZigZagArray> for ZigZagEncoding {
22    fn decode(
23        &self,
24        parts: &ArrayParts,
25        ctx: &ArrayContext,
26        dtype: DType,
27        len: usize,
28    ) -> VortexResult<ArrayRef> {
29        if parts.nchildren() != 1 {
30            vortex_bail!("Expected 1 child, got {}", parts.nchildren());
31        }
32
33        let ptype = PType::try_from(&dtype)?;
34        let encoded_type = DType::Primitive(ptype.to_unsigned(), dtype.nullability());
35
36        let encoded = parts.child(0).decode(ctx, encoded_type, len)?;
37        Ok(ZigZagArray::try_new(encoded)?.into_array())
38    }
39}