From 6760e911755d64ec878b9c50dfc7bbf965aa6e05 Mon Sep 17 00:00:00 2001 From: Jeremy Wall Date: Wed, 24 Aug 2022 12:56:40 -0400 Subject: [PATCH] Only serialize non derived fields --- src/node.rs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/node.rs b/src/node.rs index 5d6a760..13e2113 100644 --- a/src/node.rs +++ b/src/node.rs @@ -17,6 +17,21 @@ use serde::{Deserialize, Serialize}; use crate::hash::HashWriter; +#[derive(Serialize, Deserialize)] +struct NodeSerde { + item: Vec, + dependency_ids: BTreeSet>, +} + +impl From for Node +where + HW: HashWriter, +{ + fn from(ns: NodeSerde) -> Self { + Self::new(ns.item, ns.dependency_ids) + } +} + /// A node in a merkle DAG. Nodes are composed of a payload item and a set of dependency_ids. /// They provide a unique identifier that is formed from the bytes of the payload as well /// as the bytes of the dependency_ids. This is guaranteed to be the id for the same payload @@ -28,6 +43,7 @@ use crate::hash::HashWriter; /// to the DAG they are stored in guaranteeing that the same Hashing implementation is used /// for each node in the DAG. #[derive(Debug, PartialEq, Eq, Serialize, Deserialize)] +#[serde(from = "NodeSerde")] pub struct Node where HW: HashWriter,