forked from Philipp15b/go-steam
-
Notifications
You must be signed in to change notification settings - Fork 0
/
msg.go
132 lines (108 loc) · 2.4 KB
/
msg.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
package gamecoordinator
import (
"io"
. "github.com/Philipp15b/go-steam/protocol"
. "github.com/Philipp15b/go-steam/protocol/steamlang"
"github.com/golang/protobuf/proto"
)
// An outgoing message to the Game Coordinator.
type IGCMsg interface {
Serializer
IsProto() bool
GetAppId() uint32
GetMsgType() uint32
GetTargetJobId() JobId
SetTargetJobId(JobId)
GetSourceJobId() JobId
SetSourceJobId(JobId)
}
type GCMsgProtobuf struct {
AppId uint32
Header *MsgGCHdrProtoBuf
Body proto.Message
}
func NewGCMsgProtobuf(appId, msgType uint32, body proto.Message) *GCMsgProtobuf {
hdr := NewMsgGCHdrProtoBuf()
hdr.Msg = msgType
return &GCMsgProtobuf{
AppId: appId,
Header: hdr,
Body: body,
}
}
func (g *GCMsgProtobuf) IsProto() bool {
return true
}
func (g *GCMsgProtobuf) GetAppId() uint32 {
return g.AppId
}
func (g *GCMsgProtobuf) GetMsgType() uint32 {
return g.Header.Msg
}
func (g *GCMsgProtobuf) GetTargetJobId() JobId {
return JobId(g.Header.Proto.GetJobidTarget())
}
func (g *GCMsgProtobuf) SetTargetJobId(job JobId) {
g.Header.Proto.JobidTarget = proto.Uint64(uint64(job))
}
func (g *GCMsgProtobuf) GetSourceJobId() JobId {
return JobId(g.Header.Proto.GetJobidSource())
}
func (g *GCMsgProtobuf) SetSourceJobId(job JobId) {
g.Header.Proto.JobidSource = proto.Uint64(uint64(job))
}
func (g *GCMsgProtobuf) Serialize(w io.Writer) error {
err := g.Header.Serialize(w)
if err != nil {
return err
}
body, err := proto.Marshal(g.Body)
if err != nil {
return err
}
_, err = w.Write(body)
return err
}
type GCMsg struct {
AppId uint32
MsgType uint32
Header *MsgGCHdr
Body Serializer
}
func NewGCMsg(appId, msgType uint32, body Serializer) *GCMsg {
return &GCMsg{
AppId: appId,
MsgType: msgType,
Header: NewMsgGCHdr(),
Body: body,
}
}
func (g *GCMsg) GetMsgType() uint32 {
return g.MsgType
}
func (g *GCMsg) GetAppId() uint32 {
return g.AppId
}
func (g *GCMsg) IsProto() bool {
return false
}
func (g *GCMsg) GetTargetJobId() JobId {
return JobId(g.Header.TargetJobID)
}
func (g *GCMsg) SetTargetJobId(job JobId) {
g.Header.TargetJobID = uint64(job)
}
func (g *GCMsg) GetSourceJobId() JobId {
return JobId(g.Header.SourceJobID)
}
func (g *GCMsg) SetSourceJobId(job JobId) {
g.Header.SourceJobID = uint64(job)
}
func (g *GCMsg) Serialize(w io.Writer) error {
err := g.Header.Serialize(w)
if err != nil {
return err
}
err = g.Body.Serialize(w)
return err
}