Skip to content
Snippets Groups Projects
Commit ace314fc authored by Udo Eisenbarth's avatar Udo Eisenbarth :speech_balloon:
Browse files

OpticRef deserialization works partly.

No node factory method yet
parent de0c2e95
No related branches found
No related tags found
1 merge request!16Implement basic serialization / deserialization of OPOSSUM models
Pipeline #7559 failed
......@@ -194,31 +194,26 @@ impl<'de> Deserialize<'de> for OpticRef {
where
A: MapAccess<'de>,
{
//let mut node_type = None;
//let mut properties = None;
println!("visit_map");
let mut node_type = None;
let mut properties = None;
while let Some(key) = map.next_key()? {
match key {
Field::NodeType => {
println!("found `type`");
// if node_type.is_some() {
// return Err(de::Error::duplicate_field("type"));
// }
map.next_value::<String>();
// node_type = Some(map.next_value()?);
if node_type.is_some() {
return Err(de::Error::duplicate_field("type"));
}
node_type = Some(map.next_value()?);
}
Field::Properties => {
println!("found `properteis`");
// if properties.is_some() {
// return Err(de::Error::duplicate_field("properties"));
// }
// properties = Some(map.next_value()?);
map.next_value::<String>();
if properties.is_some() {
return Err(de::Error::duplicate_field("properties"));
}
properties = Some(map.next_value::<Properties>()?);
}
}
}
//let _node_type = node_type.ok_or_else(|| de::Error::missing_field("type"))?;
//let _nanos = properties.ok_or_else(|| de::Error::missing_field("properties"))?;
let _node_type = node_type.ok_or_else(|| de::Error::missing_field("type"))?;
let _nanos = properties.ok_or_else(|| de::Error::missing_field("properties"))?;
Ok(OpticRef(Rc::new(RefCell::new(Dummy::default()))))
}
}
......
use std::collections::HashMap;
use serde::Serialize;
use serde_derive::Serialize;
use serde_derive::{Serialize, Deserialize};
use crate::{error::OpossumError, lightdata::LightData, optical::OpticGraph};
#[derive(Default, Debug, Clone)]
#[derive(Default, Serialize, Deserialize, Debug, Clone)]
pub struct Properties {
props: HashMap<String, Property>
}
......@@ -33,32 +33,33 @@ impl Properties {
}
}
}
impl Serialize for Properties {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: serde::Serializer {
serializer.serialize_newtype_struct("properties", &self.props)
}
}
#[derive(Debug, Clone)]
// impl Serialize for Properties {
// fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
// where
// S: serde::Serializer {
// serializer.serialize_newtype_struct("properties", &self.props)
// }
// }
#[derive(Debug, Serialize, Deserialize, Clone)]
pub struct Property {
pub prop: Proptype
}
impl Serialize for Property {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: serde::Serializer {
serializer.serialize_newtype_struct("property", &self.prop)
}
}
// impl Serialize for Property {
// fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
// where
// S: serde::Serializer {
// serializer.serialize_newtype_struct("property", &self.prop)
// }
// }
#[non_exhaustive]
#[derive(Serialize, Debug, Clone)]
#[derive(Serialize, Deserialize, Debug, Clone)]
pub enum Proptype {
String(String),
I32(i32),
F64(f64),
Bool(bool),
LightData(Option<LightData>),
#[serde(skip)]
OpticGraph(OpticGraph)
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment