github.com/GeniusesGroup/libgo@v0.0.0-20220929090155-5ff932cb408e/event/event.go (about) 1 /* For license and copyright information please see LEGAL file in repository */ 2 3 package event 4 5 import ( 6 "github.com/GeniusesGroup/libgo/protocol" 7 "github.com/GeniusesGroup/libgo/time/unix" 8 ) 9 10 // Event implement protocol.LogEvent 11 type Event struct { 12 subType protocol.EventSubType 13 domain string 14 nodeID protocol.NodeID 15 time unix.Time 16 } 17 18 func (e *Event) Init(subType protocol.EventSubType, domain string, nodeID [16]byte, time unix.Time) { 19 e.subType = subType 20 e.domain = domain 21 e.nodeID = nodeID 22 e.time = time 23 } 24 25 func (e *Event) MainType() protocol.EventMainType { return protocol.EventMainType_Unset } 26 func (e *Event) SubType() protocol.EventSubType { return e.subType } 27 func (e *Event) Domain() string { return e.domain } 28 func (e *Event) NodeID() protocol.NodeID { return e.nodeID } 29 func (e *Event) Time() protocol.Time { return &e.time } 30 func (e *Event) Cancelable() bool { return false } 31 func (e *Event) DefaultPrevented() bool { return false } 32 func (e *Event) Bubbles() bool { return false } 33 func (e *Event) PreventDefault() {} 34 35 func (e *Event) SetSubType(subType protocol.EventSubType) { e.subType = subType } 36 func (e *Event) SetDomain(domain string) { e.domain = domain } 37 func (e *Event) SetNodeID(nodeID protocol.NodeID) { e.nodeID = nodeID } 38 func (e *Event) SetTime(time unix.Time) { e.time = time } 39 40 /* 41 -- protocol.Syllab interface Encoder & Decoder -- 42 */ 43 func (e *Event) CheckSyllab(payload []byte) (err protocol.Error) { 44 if len(payload) < int(e.LenOfSyllabStack()) { 45 // err = syllab.ErrShortArrayDecode 46 } 47 return 48 } 49 func (e *Event) FromSyllab(payload []byte, stackIndex uint32) { 50 } 51 func (e *Event) ToSyllab(payload []byte, stackIndex, heapIndex uint32) (freeHeapIndex uint32) { 52 return 53 } 54 func (e *Event) LenAsSyllab() uint64 { return uint64(e.LenOfSyllabStack() + e.LenOfSyllabHeap()) } 55 func (e *Event) LenOfSyllabStack() uint32 { return 33 } 56 func (e *Event) LenOfSyllabHeap() (ln uint32) { 57 return uint32(len(e.domain)) 58 }