-
Notifications
You must be signed in to change notification settings - Fork 18
/
describe_groups_request.go
56 lines (45 loc) · 1.31 KB
/
describe_groups_request.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
package healer
import (
"encoding/binary"
)
// DescribeGroupsRequest holds the parameters for the DescribeGroups request API
type DescribeGroupsRequest struct {
*RequestHeader
Groups []string
}
// NewDescribeGroupsRequest creates a new DescribeGroupsRequest
func NewDescribeGroupsRequest(clientID string, groups []string) *DescribeGroupsRequest {
requestHeader := &RequestHeader{
APIKey: API_DescribeGroups,
APIVersion: 0,
ClientID: &clientID,
}
return &DescribeGroupsRequest{requestHeader, groups}
}
func (r *DescribeGroupsRequest) length() int {
l := r.RequestHeader.length()
l += 4
for _, group := range r.Groups {
l += 2 + len(group)
}
return l
}
// Encode encodes the request into byte array, this implements the Request interface
func (r *DescribeGroupsRequest) Encode(version uint16) []byte {
requestLength := r.length()
payload := make([]byte, requestLength+4)
offset := 0
binary.BigEndian.PutUint32(payload[offset:], uint32(requestLength))
offset += 4
offset += r.RequestHeader.EncodeTo(payload[offset:])
binary.BigEndian.PutUint32(payload[offset:], uint32(len(r.Groups)))
offset += 4
for _, group := range r.Groups {
l := len(group)
binary.BigEndian.PutUint16(payload[offset:], uint16(l))
offset += 2
copy(payload[offset:offset+l], group)
offset += l
}
return payload
}