forked from IBM/sarama
-
Notifications
You must be signed in to change notification settings - Fork 0
/
api_versions_request.go
69 lines (59 loc) · 1.43 KB
/
api_versions_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
package sarama
const defaultClientSoftwareName = "sarama"
type ApiVersionsRequest struct {
// Version defines the protocol version to use for encode and decode
Version int16
// ClientSoftwareName contains the name of the client.
ClientSoftwareName string
// ClientSoftwareVersion contains the version of the client.
ClientSoftwareVersion string
}
func (r *ApiVersionsRequest) encode(pe packetEncoder) (err error) {
if r.Version >= 3 {
if err := pe.putCompactString(r.ClientSoftwareName); err != nil {
return err
}
if err := pe.putCompactString(r.ClientSoftwareVersion); err != nil {
return err
}
pe.putEmptyTaggedFieldArray()
}
return nil
}
func (r *ApiVersionsRequest) decode(pd packetDecoder, version int16) (err error) {
r.Version = version
if r.Version >= 3 {
if r.ClientSoftwareName, err = pd.getCompactString(); err != nil {
return err
}
if r.ClientSoftwareVersion, err = pd.getCompactString(); err != nil {
return err
}
if _, err := pd.getEmptyTaggedFieldArray(); err != nil {
return err
}
}
return nil
}
func (r *ApiVersionsRequest) key() int16 {
return 18
}
func (r *ApiVersionsRequest) version() int16 {
return r.Version
}
func (r *ApiVersionsRequest) headerVersion() int16 {
if r.Version >= 3 {
return 2
}
return 1
}
func (r *ApiVersionsRequest) requiredVersion() KafkaVersion {
switch r.Version {
case 0:
return V0_10_0_0
case 3:
return V2_4_0_0
default:
return V0_10_0_0
}
}