// Copyright (C) 2022 Soni L. // SPDX-License-Identifier: MIT OR Apache-2.0 //! Deserialization-related parts of the VM. use serde::Serialize; use serde::de::Error as _; use super::PatternConstants; use super::PatternElement; use super::Pack; /// A `DeserializeSeed` for Datafu input. /// /// This converts from Serde to Datafu's internal representation (a "pack"). pub struct Packer<'pat, O: Serialize> { /// The pattern currently being processed. pat: &'pat PatternConstants, /// The instructions/function currently being processed. ops: &'pat [PatternElement], /// Maximum number of calls. call_limit: usize, } impl<'pat, O: Serialize> Packer<'pat, O> { pub(crate) fn new( pat: &'pat PatternConstants, call_limit: usize, ) -> Self { Self { pat, call_limit, ops: &pat.protos.last().unwrap()[..], } } } impl<'pat, 'de, O> serde::de::DeserializeSeed<'de> for Packer<'pat, O> where O: Serialize, { type Value = Pack; fn deserialize(self, deserializer: D) -> Result where D: serde::Deserializer<'de> { // check the first op let first = self.ops.first(); match first { Some(PatternElement::ApplyPredicate(id, skippable)) => { let predicate = &self.pat.predicates[*id]; let ok = predicate(todo!()); match (ok, skippable) { (true, _) => { todo!() }, (false, false) => { return Err(D::Error::custom("predicate didn't match")); }, (false, true) => { todo!() }, } }, _ => { dbg!(first); todo!() }, } } } /// A `Deserializer` for Datafu output. /// /// This converts from Datafu's internal representation (a "pack") into the /// desired output type. pub struct Unpacker { pack: Pack, call_limit: usize, } impl Unpacker { /// Unpacks a Datafu "pack". pub fn new(pack: Pack, call_limit: usize) -> Self { Self { pack, call_limit, } } } impl<'de> serde::Deserializer<'de> for Unpacker { // TODO datafu errors type Error = serde::de::value::Error; fn deserialize_any(self, _: V) -> Result where V: serde::de::Visitor<'de> { todo!() } fn deserialize_bool(self, _: V) -> Result where V: serde::de::Visitor<'de> { todo!() } fn deserialize_i8(self, _: V) -> Result where V: serde::de::Visitor<'de> { todo!() } fn deserialize_i16(self, _: V) -> Result where V: serde::de::Visitor<'de> { todo!() } fn deserialize_i32(self, _: V) -> Result where V: serde::de::Visitor<'de> { todo!() } fn deserialize_i64(self, _: V) -> Result where V: serde::de::Visitor<'de> { todo!() } fn deserialize_u8(self, _: V) -> Result where V: serde::de::Visitor<'de> { todo!() } fn deserialize_u16(self, _: V) -> Result where V: serde::de::Visitor<'de> { todo!() } fn deserialize_u32(self, _: V) -> Result where V: serde::de::Visitor<'de> { todo!() } fn deserialize_u64(self, _: V) -> Result where V: serde::de::Visitor<'de> { todo!() } fn deserialize_f32(self, _: V) -> Result where V: serde::de::Visitor<'de> { todo!() } fn deserialize_f64(self, _: V) -> Result where V: serde::de::Visitor<'de> { todo!() } fn deserialize_char(self, _: V) -> Result where V: serde::de::Visitor<'de> { todo!() } fn deserialize_str(self, _: V) -> Result where V: serde::de::Visitor<'de> { todo!() } fn deserialize_string(self, _: V) -> Result where V: serde::de::Visitor<'de> { todo!() } fn deserialize_bytes(self, _: V) -> Result where V: serde::de::Visitor<'de> { todo!() } fn deserialize_byte_buf(self, _: V) -> Result where V: serde::de::Visitor<'de> { todo!() } fn deserialize_option(self, _: V) -> Result where V: serde::de::Visitor<'de> { todo!() } fn deserialize_unit(self, _: V) -> Result where V: serde::de::Visitor<'de> { todo!() } fn deserialize_unit_struct(self, _: &'static str, _: V) -> Result where V: serde::de::Visitor<'de> { todo!() } fn deserialize_newtype_struct(self, _: &'static str, _: V) -> Result where V: serde::de::Visitor<'de> { todo!() } fn deserialize_seq(self, _: V) -> Result where V: serde::de::Visitor<'de> { todo!() } fn deserialize_tuple(self, _: usize, _: V) -> Result where V: serde::de::Visitor<'de> { todo!() } fn deserialize_tuple_struct(self, _: &'static str, _: usize, _: V) -> Result where V: serde::de::Visitor<'de> { todo!() } fn deserialize_map(self, _: V) -> Result where V: serde::de::Visitor<'de> { todo!() } fn deserialize_struct( self, _: &'static str, fields: &'static [&'static str], visitor: V, ) -> Result where V: serde::de::Visitor<'de>, { todo!() } fn deserialize_enum(self, _: &'static str, _: &'static [&'static str], _: V) -> Result where V: serde::de::Visitor<'de> { todo!() } fn deserialize_identifier(self, _: V) -> Result where V: serde::de::Visitor<'de> { todo!() } fn deserialize_ignored_any(self, _: V) -> Result where V: serde::de::Visitor<'de> { todo!() } } /// A Deserializer for collecting matches from [`crate::Predicate`]s. /// /// What are we doing? /// /// We certainly have regrets. pub struct PredicateCollector { }