-
Notifications
You must be signed in to change notification settings - Fork 0
/
message.go
46 lines (37 loc) · 973 Bytes
/
message.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package message
import "sync"
// Message represents a Blink message and contains raw data object
// linked to the data stream and event.
type Message struct {
lock sync.RWMutex
Event Event `json:"event" yaml:"event"`
SourceType string `json:"sourceType" yaml:"sourceType"`
Stream string `json:"stream" yaml:"stream"`
Data Data `json:"data" yaml:"data"`
}
func NewMessage(event Event, sourceType, stream string, data []byte) *Message {
return &Message{
Event: event,
Stream: stream,
SourceType: sourceType,
Data: NewData(data),
}
}
func (m *Message) SetStream(stream string) {
m.Stream = stream
}
func (m *Message) GetStream() string {
return m.Stream
}
func (m *Message) GetSourceType() string {
return m.SourceType
}
func (m *Message) SetEvent(event Event) {
m.Event = event
}
func (m *Message) GetEvent() Event {
return m.Event
}
func (m *Message) AsJSONString() string {
return m.Data.packet.JSON()
}