-
Notifications
You must be signed in to change notification settings - Fork 18
/
describe_configs_request.go
105 lines (83 loc) · 2.39 KB
/
describe_configs_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
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
package healer
import "encoding/binary"
// ConvertConfigResourceType convert string to uint8 that's used in DescribeConfigsRequest
func ConvertConfigResourceType(resourceType string) uint8 {
switch resourceType {
case "topic":
return 2
case "broker":
return 4
case "broker_logger":
return 8
default:
return 0
}
}
// DescribeConfigsRequest holds the request parameters for DescribeConfigsRequest
type DescribeConfigsRequest struct {
*RequestHeader
Resources []*DescribeConfigsRequestResource
}
// DescribeConfigsRequestResource is part of DescribeConfigsRequest
type DescribeConfigsRequestResource struct {
ResourceType uint8
ResourceName string
ConfigNames []string
}
func (r *DescribeConfigsRequestResource) encode(payload []byte) (offset int) {
payload[offset] = r.ResourceType
offset++
binary.BigEndian.PutUint16(payload[offset:], uint16(len(r.ResourceName)))
offset += 2
offset += copy(payload[offset:], r.ResourceName)
if r.ConfigNames == nil {
binary.BigEndian.PutUint32(payload[offset:], 0xffffffff)
} else {
binary.BigEndian.PutUint32(payload[offset:], uint32(len(r.ConfigNames)))
}
offset += 4
for _, configName := range r.ConfigNames {
binary.BigEndian.PutUint16(payload[offset:], uint16(len(configName)))
offset += 2
offset += copy(payload[offset:], configName)
}
return
}
func NewDescribeConfigsRequest(clientID string, resources []*DescribeConfigsRequestResource) *DescribeConfigsRequest {
requestHeader := &RequestHeader{
APIKey: API_DescribeConfigs,
APIVersion: 0,
ClientID: &clientID,
}
if resources == nil {
resources = make([]*DescribeConfigsRequestResource, 0)
}
return &DescribeConfigsRequest{requestHeader, resources}
}
func (r *DescribeConfigsRequest) Length() int {
l := r.RequestHeader.length()
l += 4
for _, resource := range r.Resources {
l++
l += 2 + len(resource.ResourceName)
l += 4
for _, c := range resource.ConfigNames {
l += 2 + len(c)
}
}
return l
}
func (r *DescribeConfigsRequest) 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.Resources)))
offset += 4
for _, r := range r.Resources {
offset += r.encode(payload[offset:])
}
return payload
}