github.com/15mga/kiwi@v0.0.2-0.20240324021231-b95d5c3ac751/graph/msg.go (about)

     1  package graph
     2  
     3  import (
     4  	"github.com/15mga/kiwi/util"
     5  )
     6  
     7  type Msg struct {
     8  	typ      TPoint
     9  	outNode  string
    10  	outPoint string
    11  	inNode   INode
    12  	inPoint  string
    13  	data     any
    14  }
    15  
    16  func (m *Msg) Type() TPoint {
    17  	return m.typ
    18  }
    19  
    20  func (m *Msg) OutNode() string {
    21  	return m.outNode
    22  }
    23  
    24  func (m *Msg) OutPoint() string {
    25  	return m.outPoint
    26  }
    27  
    28  func (m *Msg) InNode() INode {
    29  	return m.inNode
    30  }
    31  
    32  func (m *Msg) SetInNode(inNode INode) {
    33  	m.inNode = inNode
    34  }
    35  
    36  func (m *Msg) InPoint() string {
    37  	return m.inPoint
    38  }
    39  
    40  func (m *Msg) SetInPoint(inPoint string) {
    41  	m.inPoint = inPoint
    42  }
    43  
    44  func (m *Msg) Data() any {
    45  	return m.data
    46  }
    47  
    48  func (m *Msg) ToJson() ([]byte, *util.Err) {
    49  	return util.JsonMarshal(util.M{
    50  		"InNode":   m.inNode,
    51  		"InPoint":  m.inPoint,
    52  		"OutNode":  m.outNode,
    53  		"OutPoint": m.outPoint,
    54  		"Data":     m.data,
    55  	})
    56  }
    57  
    58  func (m *Msg) ToM() util.M {
    59  	return util.M{
    60  		"InNode":   m.inNode,
    61  		"InPoint":  m.inPoint,
    62  		"OutNode":  m.outNode,
    63  		"OutPoint": m.outPoint,
    64  		"Data":     m.data,
    65  	}
    66  }
    67  
    68  var (
    69  	_MsgProcessors map[string]MsgToErr
    70  )
    71  
    72  func InitMsgProcessor(m map[string]MsgToErr) {
    73  	_MsgProcessors = m
    74  }
    75  
    76  func GetMsgProcessor(t string) MsgToErr {
    77  	return _MsgProcessors[t]
    78  }