-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Start of the work on #174
- Loading branch information
Showing
16 changed files
with
258 additions
and
144 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
use std::fmt::{Display, Formatter}; | ||
use std::sync::Arc; | ||
|
||
#[derive(Debug, Clone, PartialEq, Eq, Ord, PartialOrd, Hash)] | ||
#[cfg_attr(feature = "serde", derive(::serde::Serialize, ::serde::Deserialize))] | ||
pub struct ExtID(Arc<str>); | ||
|
||
impl Display for ExtID { | ||
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { | ||
write!(f, "{}", self.0) | ||
} | ||
} | ||
|
||
impl AsRef<str> for ExtID { | ||
fn as_ref(&self) -> &str { | ||
self.0.as_ref() | ||
} | ||
} | ||
|
||
impl From<&str> for ExtID { | ||
fn from(value: &str) -> Self { | ||
ExtID(value.into()) | ||
} | ||
} | ||
|
||
#[derive(Debug, Clone, PartialEq, Eq, Hash)] | ||
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] | ||
pub struct ExtMetadata(Arc<[u8]>); | ||
|
||
impl AsRef<[u8]> for ExtMetadata { | ||
fn as_ref(&self) -> &[u8] { | ||
self.0.as_ref() | ||
} | ||
} | ||
|
||
impl From<Arc<[u8]>> for ExtMetadata { | ||
fn from(value: Arc<[u8]>) -> Self { | ||
ExtMetadata(value) | ||
} | ||
} | ||
|
||
impl From<&[u8]> for ExtMetadata { | ||
fn from(value: &[u8]) -> Self { | ||
ExtMetadata(value.into()) | ||
} | ||
} | ||
|
||
#[derive(Debug, Clone, PartialEq, Eq, Hash)] | ||
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] | ||
pub struct ExtDType { | ||
id: ExtID, | ||
metadata: Option<ExtMetadata>, | ||
} | ||
|
||
impl ExtDType { | ||
pub fn new(id: ExtID, metadata: Option<ExtMetadata>) -> Self { | ||
Self { id, metadata } | ||
} | ||
|
||
#[inline] | ||
pub fn id(&self) -> &ExtID { | ||
&self.id | ||
} | ||
|
||
#[inline] | ||
pub fn metadata(&self) -> Option<&ExtMetadata> { | ||
self.metadata.as_ref() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,59 +1 @@ | ||
#![cfg(feature = "serde")] | ||
|
||
use flatbuffers::root; | ||
use serde::de::{DeserializeSeed, Visitor}; | ||
use serde::{Deserialize, Deserializer, Serialize, Serializer}; | ||
use vortex_flatbuffers::{FlatBufferToBytes, ReadFlatBuffer}; | ||
|
||
use crate::DType; | ||
use crate::{flatbuffers as fb, DTypeSerdeContext}; | ||
|
||
impl Serialize for DType { | ||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> | ||
where | ||
S: Serializer, | ||
{ | ||
self.with_flatbuffer_bytes(|bytes| serializer.serialize_bytes(bytes)) | ||
} | ||
} | ||
|
||
struct DTypeDeserializer(DTypeSerdeContext); | ||
|
||
impl<'de> Visitor<'de> for DTypeDeserializer { | ||
type Value = DType; | ||
|
||
fn expecting(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result { | ||
formatter.write_str("a vortex dtype") | ||
} | ||
|
||
fn visit_bytes<E>(self, v: &[u8]) -> Result<Self::Value, E> | ||
where | ||
E: serde::de::Error, | ||
{ | ||
let fb = root::<fb::DType>(v).map_err(E::custom)?; | ||
DType::read_flatbuffer(&self.0, &fb).map_err(E::custom) | ||
} | ||
} | ||
|
||
impl<'de> DeserializeSeed<'de> for DTypeSerdeContext { | ||
type Value = DType; | ||
|
||
fn deserialize<D>(self, deserializer: D) -> Result<Self::Value, D::Error> | ||
where | ||
D: Deserializer<'de>, | ||
{ | ||
deserializer.deserialize_bytes(DTypeDeserializer(self)) | ||
} | ||
} | ||
|
||
// TODO(ngates): Remove this trait in favour of storing e.g. IdxType which doesn't require | ||
// the context for composite types. | ||
impl<'de> Deserialize<'de> for DType { | ||
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> | ||
where | ||
D: Deserializer<'de>, | ||
{ | ||
let ctx = DTypeSerdeContext::new(vec![]); | ||
deserializer.deserialize_bytes(DTypeDeserializer(ctx)) | ||
} | ||
} |
Oops, something went wrong.