vortex_array/vtable/
serde.rs1use std::fmt::Debug;
2
3use vortex_buffer::ByteBuffer;
4use vortex_dtype::DType;
5use vortex_error::{VortexResult, vortex_bail};
6
7use crate::serde::ArrayChildren;
8use crate::vtable::{NotSupported, VTable};
9use crate::{DeserializeMetadata, EmptyMetadata, SerializeMetadata};
10
11pub trait SerdeVTable<V: VTable> {
17 type Metadata: Debug + SerializeMetadata + DeserializeMetadata;
18
19 fn metadata(array: &V::Array) -> VortexResult<Option<Self::Metadata>>;
27
28 fn build(
30 encoding: &V::Encoding,
31 dtype: &DType,
32 len: usize,
33 metadata: &<Self::Metadata as DeserializeMetadata>::Output,
34 buffers: &[ByteBuffer],
35 children: &dyn ArrayChildren,
36 ) -> VortexResult<V::Array>;
37}
38
39impl<V: VTable> SerdeVTable<V> for NotSupported {
40 type Metadata = EmptyMetadata;
41
42 fn metadata(_array: &V::Array) -> VortexResult<Option<Self::Metadata>> {
43 Ok(None)
44 }
45
46 fn build(
47 encoding: &V::Encoding,
48 _dtype: &DType,
49 _len: usize,
50 _metadata: &Self::Metadata,
51 _buffers: &[ByteBuffer],
52 _children: &dyn ArrayChildren,
53 ) -> VortexResult<V::Array> {
54 vortex_bail!("Serde not supported by {} encoding", V::id(encoding));
55 }
56}