/
notification.go
44 lines (39 loc) · 973 Bytes
/
notification.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
package rostermodel
import (
"bytes"
"encoding/gob"
"github.com/dantin/cubit/xmpp"
)
// Notification represents a roster subscription pending notification.
type Notification struct {
Contact string
JID string
Presence *xmpp.Presence
}
// FromBytes deserializes a Notification entity from its binary representation.
func (rn *Notification) FromBytes(buf *bytes.Buffer) error {
dec := gob.NewDecoder(buf)
if err := dec.Decode(&rn.Contact); err != nil {
return err
}
if err := dec.Decode(&rn.JID); err != nil {
return err
}
p, err := xmpp.NewPresenceFromBytes(buf)
if err != nil {
return err
}
rn.Presence = p
return nil
}
// ToBytes converts a Notification entity to its binary representation.
func (rn *Notification) ToBytes(buf *bytes.Buffer) error {
enc := gob.NewEncoder(buf)
if err := enc.Encode(&rn.Contact); err != nil {
return err
}
if err := enc.Encode(&rn.JID); err != nil {
return err
}
return rn.Presence.ToBytes(buf)
}