-
Notifications
You must be signed in to change notification settings - Fork 1
/
service.go
55 lines (47 loc) · 1.12 KB
/
service.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
package sturdyengine
import (
"github.com/golang/protobuf/proto"
krpc "github.com/jwuensche/sturdyengine/internal/krpcproto"
)
//GetStatus calls remote procedure `GetStatus` and returns the response in form of the proto buffer message
func (conn *Connection) GetStatus() (res krpc.Status, e error) {
pc := krpc.ProcedureCall{
Service: "KRPC",
Procedure: "GetStatus",
}
pr := krpc.Request{
Calls: []*krpc.ProcedureCall{&pc},
}
p, e := conn.sendMessage(&pr)
if e != nil {
return
}
r := krpc.Response{}
e = proto.Unmarshal(p, &r)
if e != nil {
return
}
e = proto.Unmarshal(r.GetResults()[0].GetValue(), &res)
return
}
//GetServices calls KRPC remote procedure `GetServices` and returns Service Structure
func (conn *Connection) GetServices() (res krpc.Services, e error) {
pc := krpc.ProcedureCall{
Service: "KRPC",
Procedure: "GetServices",
}
pr := krpc.Request{
Calls: []*krpc.ProcedureCall{&pc},
}
p, e := conn.sendMessage(&pr)
if e != nil {
return
}
r := &krpc.Response{}
e = proto.Unmarshal(p, r)
if e != nil {
return
}
e = proto.Unmarshal(r.GetResults()[0].GetValue(), &res)
return
}