blob: ab74eb987e4774bb154c127a684a67a2441ae9e2 (
plain)
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
|
package pubsub
import (
json "github.com/json-iterator/go"
)
type Msg struct {
// Topic message been pushed into.
T []string `json:"topic"`
// Command (join, leave, headers)
C string `json:"command"`
// Broker (redis, memory)
B string `json:"broker"`
// Payload to be broadcasted
P []byte `json:"payload"`
}
//func (m Msg) UnmarshalBinary(data []byte) error {
// //Use default gob decoder
// reader := bytes.NewReader(data)
// dec := gob.NewDecoder(reader)
// if err := dec.Decode(&m); err != nil {
// return err
// }
//
// return nil
//}
func (m *Msg) MarshalBinary() ([]byte, error) {
//buf := new(bytes.Buffer)
//
//for i := 0; i < len(m.T); i++ {
// buf.WriteString(m.T[i])
//}
//
//buf.WriteString(m.C)
//buf.WriteString(m.B)
//buf.Write(m.P)
return json.Marshal(m)
}
// Payload in raw bytes
func (m *Msg) Payload() []byte {
return m.P
}
// Command for the connection
func (m *Msg) Command() string {
return m.C
}
// Topics to subscribe
func (m *Msg) Topics() []string {
return m.T
}
func (m *Msg) Broker() string {
return m.B
}
|