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