-
Notifications
You must be signed in to change notification settings - Fork 0
/
api_versions_response.go
77 lines (66 loc) · 1.37 KB
/
api_versions_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
package protocol
import "time"
type APIVersionsResponse struct {
APIVersion int16
ErrorCode int16
APIVersions []APIVersion
ThrottleTime time.Duration
}
type APIVersion struct {
APIKey int16
MinVersion int16
MaxVersion int16
}
func (c *APIVersionsResponse) Encode(e PacketEncoder) error {
e.PutInt16(c.ErrorCode)
if err := e.PutArrayLength(len(c.APIVersions)); err != nil {
return err
}
for _, av := range c.APIVersions {
e.PutInt16(av.APIKey)
e.PutInt16(av.MinVersion)
e.PutInt16(av.MaxVersion)
}
if c.APIVersion >= 1 {
e.PutInt32(int32(c.ThrottleTime / time.Millisecond))
}
return nil
}
func (c *APIVersionsResponse) Decode(d PacketDecoder, version int16) error {
c.APIVersion = version
l, err := d.ArrayLength()
if err != nil {
return err
}
c.APIVersions = make([]APIVersion, l)
for i := range c.APIVersions {
key, err := d.Int16()
if err != nil {
return err
}
minVersion, err := d.Int16()
if err != nil {
return err
}
maxVersion, err := d.Int16()
if err != nil {
return err
}
c.APIVersions[i] = APIVersion{
APIKey: key,
MinVersion: minVersion,
MaxVersion: maxVersion,
}
}
if version >= 1 {
throttle, err := d.Int32()
if err != nil {
return err
}
c.ThrottleTime = time.Duration(throttle) * time.Millisecond
}
return nil
}
func (r *APIVersionsResponse) Version() int16 {
return r.APIVersion
}