forked from IBM/sarama
-
Notifications
You must be signed in to change notification settings - Fork 0
/
alter_client_quotas_response.go
154 lines (130 loc) · 3.55 KB
/
alter_client_quotas_response.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
147
148
149
150
151
152
153
154
package sarama
import (
"time"
)
// AlterClientQuotas Response (Version: 0) => throttle_time_ms [entries]
// throttle_time_ms => INT32
// entries => error_code error_message [entity]
// error_code => INT16
// error_message => NULLABLE_STRING
// entity => entity_type entity_name
// entity_type => STRING
// entity_name => NULLABLE_STRING
type AlterClientQuotasResponse struct {
Version int16
ThrottleTime time.Duration // The duration in milliseconds for which the request was throttled due to a quota violation, or zero if the request did not violate any quota.
Entries []AlterClientQuotasEntryResponse // The quota configuration entries altered.
}
type AlterClientQuotasEntryResponse struct {
ErrorCode KError // The error code, or `0` if the quota alteration succeeded.
ErrorMsg *string // The error message, or `null` if the quota alteration succeeded.
Entity []QuotaEntityComponent // The quota entity altered.
}
func (a *AlterClientQuotasResponse) encode(pe packetEncoder) error {
// ThrottleTime
pe.putInt32(int32(a.ThrottleTime / time.Millisecond))
// Entries
if err := pe.putArrayLength(len(a.Entries)); err != nil {
return err
}
for _, e := range a.Entries {
if err := e.encode(pe); err != nil {
return err
}
}
return nil
}
func (a *AlterClientQuotasResponse) decode(pd packetDecoder, version int16) error {
// ThrottleTime
throttleTime, err := pd.getInt32()
if err != nil {
return err
}
a.ThrottleTime = time.Duration(throttleTime) * time.Millisecond
// Entries
entryCount, err := pd.getArrayLength()
if err != nil {
return err
}
if entryCount > 0 {
a.Entries = make([]AlterClientQuotasEntryResponse, entryCount)
for i := range a.Entries {
e := AlterClientQuotasEntryResponse{}
if err = e.decode(pd, version); err != nil {
return err
}
a.Entries[i] = e
}
} else {
a.Entries = []AlterClientQuotasEntryResponse{}
}
return nil
}
func (a *AlterClientQuotasEntryResponse) encode(pe packetEncoder) error {
// ErrorCode
pe.putInt16(int16(a.ErrorCode))
// ErrorMsg
if err := pe.putNullableString(a.ErrorMsg); err != nil {
return err
}
// Entity
if err := pe.putArrayLength(len(a.Entity)); err != nil {
return err
}
for _, component := range a.Entity {
if err := component.encode(pe); err != nil {
return err
}
}
return nil
}
func (a *AlterClientQuotasEntryResponse) decode(pd packetDecoder, version int16) error {
// ErrorCode
errCode, err := pd.getInt16()
if err != nil {
return err
}
a.ErrorCode = KError(errCode)
// ErrorMsg
errMsg, err := pd.getNullableString()
if err != nil {
return err
}
a.ErrorMsg = errMsg
// Entity
componentCount, err := pd.getArrayLength()
if err != nil {
return err
}
if componentCount > 0 {
a.Entity = make([]QuotaEntityComponent, componentCount)
for i := 0; i < componentCount; i++ {
component := QuotaEntityComponent{}
if err := component.decode(pd, version); err != nil {
return err
}
a.Entity[i] = component
}
} else {
a.Entity = []QuotaEntityComponent{}
}
return nil
}
func (a *AlterClientQuotasResponse) key() int16 {
return 49
}
func (a *AlterClientQuotasResponse) version() int16 {
return a.Version
}
func (a *AlterClientQuotasResponse) headerVersion() int16 {
return 0
}
func (a *AlterClientQuotasResponse) isValidVersion() bool {
return a.Version == 0
}
func (a *AlterClientQuotasResponse) requiredVersion() KafkaVersion {
return V2_6_0_0
}
func (r *AlterClientQuotasResponse) throttleTime() time.Duration {
return r.ThrottleTime
}