Change BaseSignal.String() to use json.Marshal

graph-rework-2
noah metz 2023-06-26 22:06:09 -06:00
parent 62d56f208a
commit 10bd1ee823
1 changed files with 11 additions and 7 deletions

@ -118,9 +118,17 @@ type GraphSignal interface {
// BaseSignal is the most basic type of signal, it has no additional data // BaseSignal is the most basic type of signal, it has no additional data
type BaseSignal struct { type BaseSignal struct {
direction SignalDirection direction SignalDirection `json:"direction"`
source NodeID source NodeID `json:"source"`
_type string _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 { func (signal BaseSignal) Direction() SignalDirection {
@ -135,10 +143,6 @@ func (signal BaseSignal) Type() string {
return signal._type 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 { func NewBaseSignal(source GraphNode, _type string, direction SignalDirection) BaseSignal {
var source_id NodeID = "" var source_id NodeID = ""
if source != nil { if source != nil {