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

     1  package core
     2  
     3  import (
     4  	"github.com/15mga/kiwi"
     5  )
     6  
     7  func InitNodeLocal() {
     8  	kiwi.SetNode(NewNodeLocal())
     9  }
    10  
    11  func NewNodeLocal() kiwi.INode {
    12  	return &nodeLocal{
    13  		nodeBase: newNodeBase(),
    14  	}
    15  }
    16  
    17  type nodeLocal struct {
    18  	nodeBase
    19  }
    20  
    21  func (n *nodeLocal) Push(pus kiwi.ISndPush) {
    22  	pkt := NewRcvPusPkt()
    23  	msg := pus.Msg()
    24  	if msg != nil {
    25  		pkt.InitWithMsg(HdPush, pus.Tid(), pus.Head(), pus.Json(), pus.Msg())
    26  	} else {
    27  		err := pkt.InitWithBytes(HdPush, pus.Tid(), pus.Head(), pus.Json(), pus.Payload())
    28  		if err != nil {
    29  			kiwi.Error(err)
    30  			return
    31  		}
    32  	}
    33  	kiwi.Router().OnPush(pkt)
    34  }
    35  
    36  func (n *nodeLocal) PushNode(nodeId int64, pus kiwi.ISndPush) {
    37  	n.Push(pus)
    38  }
    39  
    40  func (n *nodeLocal) Request(req kiwi.ISndRequest) {
    41  	pkt := NewRcvReqPkt()
    42  	msg := req.Msg()
    43  	if msg != nil {
    44  		pkt.InitWithMsg(HdRequest, req.Tid(), req.Head(), req.Json(), req.Msg())
    45  	} else {
    46  		err := pkt.InitWithBytes(HdRequest, req.Tid(), req.Head(), req.Json(), req.Payload())
    47  		if err != nil {
    48  			kiwi.Error(err)
    49  			return
    50  		}
    51  	}
    52  	kiwi.Router().OnRequest(pkt)
    53  }
    54  
    55  func (n *nodeLocal) RequestNode(nodeId int64, req kiwi.ISndRequest) {
    56  	n.Request(req)
    57  }
    58  
    59  func (n *nodeLocal) Notify(ntf kiwi.ISndNotice) {
    60  	pkt := NewRcvNtfPkt()
    61  	msg := ntf.Msg()
    62  	if msg != nil {
    63  		pkt.InitWithMsg(HdNotify, ntf.Tid(), ntf.Head(), ntf.Json(), ntf.Msg())
    64  	} else {
    65  		err := pkt.InitWithBytes(HdNotify, ntf.Tid(), ntf.Head(), ntf.Json(), ntf.Payload())
    66  		if err != nil {
    67  			kiwi.Error(err)
    68  			return
    69  		}
    70  	}
    71  	kiwi.Router().OnNotice(pkt)
    72  }
    73  
    74  func (n *nodeLocal) ReceiveWatchNotice(nodeId int64, codes []kiwi.TCode) {
    75  }