github.com/15mga/kiwi@v0.0.2-0.20240324021231-b95d5c3ac751/core/snd_pkt.go (about) 1 package core 2 3 import ( 4 "github.com/15mga/kiwi" 5 "github.com/15mga/kiwi/util" 6 "strconv" 7 "time" 8 ) 9 10 const ( 11 HeadId = "id" 12 HeadSvc = "svc" 13 HeadCode = "cod" 14 HeadSndId = "snd_id" 15 HeadSndTs = "snd_ts" 16 ) 17 18 type sndPkt struct { 19 pid int64 20 tid int64 21 sndTs int64 22 json bool 23 svc kiwi.TSvc 24 code kiwi.TCode 25 head util.M 26 payload []byte 27 msg util.IMsg 28 } 29 30 func (p *sndPkt) InitHead() { 31 p.head.Set(HeadSvc, p.svc) 32 p.head.Set(HeadCode, p.code) 33 ni := kiwi.GetNodeMeta() 34 p.head.Set(HeadSndId, ni.NodeId) 35 p.head.Set(HeadSndTs, time.Now().UnixMilli()) 36 } 37 38 func (p *sndPkt) Pid() int64 { 39 return p.pid 40 } 41 42 func (p *sndPkt) Tid() int64 { 43 return p.tid 44 } 45 46 func (p *sndPkt) Json() bool { 47 return p.json 48 } 49 50 func (p *sndPkt) Svc() kiwi.TSvc { 51 return p.svc 52 } 53 54 func (p *sndPkt) Code() kiwi.TCode { 55 return p.code 56 } 57 58 func (p *sndPkt) Head() util.M { 59 return p.head 60 } 61 62 func (p *sndPkt) GetSvcNodeId() (int64, bool) { 63 id, ok := util.MGet[int64](p.head, strconv.Itoa(int(p.svc))) 64 return id, ok 65 } 66 67 func (p *sndPkt) Payload() []byte { 68 return p.payload 69 } 70 71 func (p *sndPkt) Msg() util.IMsg { 72 return p.msg 73 } 74 75 func (p *sndPkt) Dispose() { 76 p.msg = nil 77 }