diff --git a/lib/protoflow-core/src/block_descriptor.rs b/lib/protoflow-core/src/block_descriptor.rs index 55dddfd1..56b440eb 100644 --- a/lib/protoflow-core/src/block_descriptor.rs +++ b/lib/protoflow-core/src/block_descriptor.rs @@ -47,9 +47,12 @@ impl serde::Serialize for &dyn BlockDescriptor { S: serde::Serializer, { use serde::ser::SerializeStruct; - let mut state = serializer.serialize_struct("BlockDescriptor", 1)?; + let mut state = serializer.serialize_struct("BlockDescriptor", 5)?; state.serialize_field("name", &self.name())?; - // TODO: add more fields + state.serialize_field("label", &self.label())?; + state.serialize_field("parameters", &self.parameters())?; + state.serialize_field("inputs", &self.inputs())?; + state.serialize_field("outputs", &self.outputs())?; state.end() } } diff --git a/lib/protoflow-core/src/parameter_descriptor.rs b/lib/protoflow-core/src/parameter_descriptor.rs index 12e14476..3bde1700 100644 --- a/lib/protoflow-core/src/parameter_descriptor.rs +++ b/lib/protoflow-core/src/parameter_descriptor.rs @@ -4,17 +4,21 @@ use crate::prelude::{Cow, MaybeLabeled, Named, String}; /// A descriptor for a block parameter. #[derive(Clone, Default, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub struct ParameterDescriptor { /// The machine-readable name of this parameter. pub name: String, /// A human-readable label, if any, for this parameter. + #[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))] pub label: Option, /// The data type, if known, of this parameter. + #[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))] pub r#type: Option, /// A default value, if any, for this parameter. + #[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))] pub default_value: Option, } diff --git a/lib/protoflow-core/src/port_descriptor.rs b/lib/protoflow-core/src/port_descriptor.rs index 0baf04bd..02a4d2a9 100644 --- a/lib/protoflow-core/src/port_descriptor.rs +++ b/lib/protoflow-core/src/port_descriptor.rs @@ -7,6 +7,8 @@ use crate::{ /// The dataflow direction of a port. #[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] +#[cfg_attr(feature = "serde", serde(rename_all = "lowercase"))] pub enum PortDirection { Input, Output, @@ -14,23 +16,29 @@ pub enum PortDirection { /// A descriptor for a block port. #[derive(Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)] +#[cfg_attr(feature = "serde", derive(serde::Serialize))] pub struct PortDescriptor { /// The dataflow direction of this port. pub direction: PortDirection, /// The machine-readable name of this port, if any. + #[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))] pub name: Option, /// A human-readable label for this port, if any. + #[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))] pub label: Option, /// The data type for messages on this port. + #[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))] pub r#type: Option, /// The unique identifier for this port. + #[cfg_attr(feature = "serde", serde(skip))] pub id: PortID, /// The current state of this port. + #[cfg_attr(feature = "serde", serde(skip))] pub state: PortState, } diff --git a/lib/protoflow-core/src/port_id.rs b/lib/protoflow-core/src/port_id.rs index 0175df6b..f740e4d5 100644 --- a/lib/protoflow-core/src/port_id.rs +++ b/lib/protoflow-core/src/port_id.rs @@ -3,6 +3,8 @@ use crate::prelude::{fmt, TryFrom}; #[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] +#[cfg_attr(feature = "serde", serde(rename_all = "lowercase"))] pub enum PortID { Input(InputPortID), Output(OutputPortID), @@ -69,6 +71,7 @@ impl fmt::Display for PortID { } #[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub struct InputPortID(pub(crate) isize); impl InputPortID { @@ -109,6 +112,7 @@ impl fmt::Display for InputPortID { } #[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub struct OutputPortID(pub(crate) isize); impl OutputPortID { diff --git a/lib/protoflow-core/src/port_state.rs b/lib/protoflow-core/src/port_state.rs index 7b902a92..3ef813eb 100644 --- a/lib/protoflow-core/src/port_state.rs +++ b/lib/protoflow-core/src/port_state.rs @@ -1,6 +1,8 @@ // This is free and unencumbered software released into the public domain. #[derive(Clone, Copy, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] +#[cfg_attr(feature = "serde", serde(rename_all = "lowercase"))] pub enum PortState { #[default] Closed,