From 10bd1ee8237ca9ec25ade471c4705d5510da47f3 Mon Sep 17 00:00:00 2001 From: Noah Metz Date: Mon, 26 Jun 2023 22:06:09 -0600 Subject: [PATCH] Change BaseSignal.String() to use json.Marshal --- graph.go | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/graph.go b/graph.go index edf0e97..7db6e47 100644 --- a/graph.go +++ b/graph.go @@ -118,9 +118,17 @@ type GraphSignal interface { // BaseSignal is the most basic type of signal, it has no additional data type BaseSignal struct { - direction SignalDirection - source NodeID - _type string + direction SignalDirection `json:"direction"` + source NodeID `json:"source"` + _type string `json:"type"` +} + +func (state BaseSignal) String() string { + ser, err := json.Marshal(state) + if err != nil { + return "STATE_SER_ERR" + } + return string(ser) } func (signal BaseSignal) Direction() SignalDirection { @@ -135,10 +143,6 @@ func (signal BaseSignal) Type() string { return signal._type } -func (signal BaseSignal) String() string { - return fmt.Sprintf("{direction: %d, source: %s, type: %s}", signal.direction, signal.source, signal._type) -} - func NewBaseSignal(source GraphNode, _type string, direction SignalDirection) BaseSignal { var source_id NodeID = "" if source != nil {