-
Notifications
You must be signed in to change notification settings - Fork 1.8k
/
Copy pathdescribe_client_quotas_request.go
146 lines (125 loc) · 3.14 KB
/
describe_client_quotas_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
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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
package sarama
// DescribeClientQuotas Request (Version: 0) => [components] strict
// components => entity_type match_type match
// entity_type => STRING
// match_type => INT8
// match => NULLABLE_STRING
// strict => BOOLEAN
// A filter to be applied to matching client quotas.
// Components: the components to filter on
// Strict: whether the filter only includes specified components
type DescribeClientQuotasRequest struct {
Version int16
Components []QuotaFilterComponent
Strict bool
}
// Describe a component for applying a client quota filter.
// EntityType: the entity type the filter component applies to ("user", "client-id", "ip")
// MatchType: the match type of the filter component (any, exact, default)
// Match: the name that's matched exactly (used when MatchType is QuotaMatchExact)
type QuotaFilterComponent struct {
EntityType QuotaEntityType
MatchType QuotaMatchType
Match string
}
func (d *DescribeClientQuotasRequest) encode(pe packetEncoder) error {
// Components
if err := pe.putArrayLength(len(d.Components)); err != nil {
return err
}
for _, c := range d.Components {
if err := c.encode(pe); err != nil {
return err
}
}
// Strict
pe.putBool(d.Strict)
return nil
}
func (d *DescribeClientQuotasRequest) decode(pd packetDecoder, version int16) error {
// Components
componentCount, err := pd.getArrayLength()
if err != nil {
return err
}
if componentCount > 0 {
d.Components = make([]QuotaFilterComponent, componentCount)
for i := range d.Components {
c := QuotaFilterComponent{}
if err = c.decode(pd, version); err != nil {
return err
}
d.Components[i] = c
}
} else {
d.Components = []QuotaFilterComponent{}
}
// Strict
strict, err := pd.getBool()
if err != nil {
return err
}
d.Strict = strict
return nil
}
func (d *QuotaFilterComponent) encode(pe packetEncoder) error {
// EntityType
if err := pe.putString(string(d.EntityType)); err != nil {
return err
}
// MatchType
pe.putInt8(int8(d.MatchType))
// Match
if d.MatchType == QuotaMatchAny {
if err := pe.putNullableString(nil); err != nil {
return err
}
} else if d.MatchType == QuotaMatchDefault {
if err := pe.putString(""); err != nil {
return err
}
} else {
if err := pe.putString(d.Match); err != nil {
return err
}
}
return nil
}
func (d *QuotaFilterComponent) decode(pd packetDecoder, version int16) error {
// EntityType
entityType, err := pd.getString()
if err != nil {
return err
}
d.EntityType = QuotaEntityType(entityType)
// MatchType
matchType, err := pd.getInt8()
if err != nil {
return err
}
d.MatchType = QuotaMatchType(matchType)
// Match
match, err := pd.getNullableString()
if err != nil {
return err
}
if match != nil {
d.Match = *match
}
return nil
}
func (d *DescribeClientQuotasRequest) key() int16 {
return 48
}
func (d *DescribeClientQuotasRequest) version() int16 {
return d.Version
}
func (d *DescribeClientQuotasRequest) headerVersion() int16 {
return 1
}
func (d *DescribeClientQuotasRequest) isValidVersion() bool {
return d.Version == 0
}
func (d *DescribeClientQuotasRequest) requiredVersion() KafkaVersion {
return V2_6_0_0
}