-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathemotesdirection.go
58 lines (44 loc) · 1022 Bytes
/
emotesdirection.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
47
48
49
50
51
52
53
54
55
56
57
58
package msgsvr
import (
"fmt"
"strconv"
"strings"
"github.com/kralamoure/retroproto"
)
type EmotesDirection struct {
Id int
Dir int
}
func NewEmotesDirection(extra string) (EmotesDirection, error) {
var m EmotesDirection
if err := m.Deserialize(extra); err != nil {
return EmotesDirection{}, fmt.Errorf("could not deserialize message: %w", err)
}
return m, nil
}
func (m EmotesDirection) MessageId() retroproto.MsgSvrId {
return retroproto.EmotesDirection
}
func (m EmotesDirection) MessageName() string {
return "EmotesDirection"
}
func (m EmotesDirection) Serialized() (string, error) {
return fmt.Sprintf("%d|%d", m.Id, m.Dir), nil
}
func (m *EmotesDirection) Deserialize(extra string) error {
sli := strings.Split(extra, "|")
if len(sli) < 2 {
return retroproto.ErrInvalidMsg
}
id, err := strconv.ParseInt(sli[0], 10, 32)
if err != nil {
return err
}
m.Id = int(id)
dir, err := strconv.ParseInt(sli[1], 10, 32)
if err != nil {
return err
}
m.Dir = int(dir)
return nil
}