blob: 593b0f0d2ec5c6bf8c89db581679180a4bce9374 [file] [log] [blame]
Abhay Kumar40252eb2025-10-13 13:25:53 +00001package sarama
2
3const defaultClientSoftwareName = "sarama"
4
5type ApiVersionsRequest struct {
6 // Version defines the protocol version to use for encode and decode
7 Version int16
8 // ClientSoftwareName contains the name of the client.
9 ClientSoftwareName string
10 // ClientSoftwareVersion contains the version of the client.
11 ClientSoftwareVersion string
12}
13
14func (r *ApiVersionsRequest) setVersion(v int16) {
15 r.Version = v
16}
17
18func (r *ApiVersionsRequest) encode(pe packetEncoder) (err error) {
19 if r.Version >= 3 {
20 if err := pe.putString(r.ClientSoftwareName); err != nil {
21 return err
22 }
23 if err := pe.putString(r.ClientSoftwareVersion); err != nil {
24 return err
25 }
26 pe.putEmptyTaggedFieldArray()
27 }
28
29 return nil
30}
31
32func (r *ApiVersionsRequest) decode(pd packetDecoder, version int16) (err error) {
33 r.Version = version
34 if r.Version >= 3 {
35 if r.ClientSoftwareName, err = pd.getString(); err != nil {
36 return err
37 }
38 if r.ClientSoftwareVersion, err = pd.getString(); err != nil {
39 return err
40 }
41 }
42
43 _, err = pd.getEmptyTaggedFieldArray()
44 return err
45}
46
47func (r *ApiVersionsRequest) key() int16 {
48 return apiKeyApiVersions
49}
50
51func (r *ApiVersionsRequest) version() int16 {
52 return r.Version
53}
54
55func (r *ApiVersionsRequest) headerVersion() int16 {
56 if r.Version >= 3 {
57 return 2
58 }
59 return 1
60}
61
62func (r *ApiVersionsRequest) isValidVersion() bool {
63 return r.Version >= 0 && r.Version <= 3
64}
65
66func (r *ApiVersionsRequest) isFlexible() bool {
67 return r.isFlexibleVersion(r.Version)
68}
69
70func (r *ApiVersionsRequest) isFlexibleVersion(version int16) bool {
71 return version >= 3
72}
73
74func (r *ApiVersionsRequest) requiredVersion() KafkaVersion {
75 switch r.Version {
76 case 3:
77 return V2_4_0_0
78 case 2:
79 return V2_0_0_0
80 case 1:
81 return V0_11_0_0
82 case 0:
83 return V0_10_0_0
84 default:
85 return V2_4_0_0
86 }
87}