cubefs

Форк
0
/
api_versions_response.go 
156 строк · 3.3 Кб
1
package sarama
2

3
// ApiVersionsResponseKey contains the APIs supported by the broker.
4
type ApiVersionsResponseKey struct {
5
	// Version defines the protocol version to use for encode and decode
6
	Version int16
7
	// ApiKey contains the API index.
8
	ApiKey int16
9
	// MinVersion contains the minimum supported version, inclusive.
10
	MinVersion int16
11
	// MaxVersion contains the maximum supported version, inclusive.
12
	MaxVersion int16
13
}
14

15
func (a *ApiVersionsResponseKey) encode(pe packetEncoder, version int16) (err error) {
16
	a.Version = version
17
	pe.putInt16(a.ApiKey)
18

19
	pe.putInt16(a.MinVersion)
20

21
	pe.putInt16(a.MaxVersion)
22

23
	if version >= 3 {
24
		pe.putEmptyTaggedFieldArray()
25
	}
26

27
	return nil
28
}
29

30
func (a *ApiVersionsResponseKey) decode(pd packetDecoder, version int16) (err error) {
31
	a.Version = version
32
	if a.ApiKey, err = pd.getInt16(); err != nil {
33
		return err
34
	}
35

36
	if a.MinVersion, err = pd.getInt16(); err != nil {
37
		return err
38
	}
39

40
	if a.MaxVersion, err = pd.getInt16(); err != nil {
41
		return err
42
	}
43

44
	if version >= 3 {
45
		if _, err := pd.getEmptyTaggedFieldArray(); err != nil {
46
			return err
47
		}
48
	}
49

50
	return nil
51
}
52

53
type ApiVersionsResponse struct {
54
	// Version defines the protocol version to use for encode and decode
55
	Version int16
56
	// ErrorCode contains the top-level error code.
57
	ErrorCode int16
58
	// ApiKeys contains the APIs supported by the broker.
59
	ApiKeys []ApiVersionsResponseKey
60
	// ThrottleTimeMs contains 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.
61
	ThrottleTimeMs int32
62
}
63

64
func (r *ApiVersionsResponse) encode(pe packetEncoder) (err error) {
65
	pe.putInt16(r.ErrorCode)
66

67
	if r.Version >= 3 {
68
		pe.putCompactArrayLength(len(r.ApiKeys))
69
	} else {
70
		if err := pe.putArrayLength(len(r.ApiKeys)); err != nil {
71
			return err
72
		}
73
	}
74
	for _, block := range r.ApiKeys {
75
		if err := block.encode(pe, r.Version); err != nil {
76
			return err
77
		}
78
	}
79

80
	if r.Version >= 1 {
81
		pe.putInt32(r.ThrottleTimeMs)
82
	}
83

84
	if r.Version >= 3 {
85
		pe.putEmptyTaggedFieldArray()
86
	}
87

88
	return nil
89
}
90

91
func (r *ApiVersionsResponse) decode(pd packetDecoder, version int16) (err error) {
92
	r.Version = version
93
	if r.ErrorCode, err = pd.getInt16(); err != nil {
94
		return err
95
	}
96

97
	var numApiKeys int
98
	if r.Version >= 3 {
99
		numApiKeys, err = pd.getCompactArrayLength()
100
		if err != nil {
101
			return err
102
		}
103
	} else {
104
		numApiKeys, err = pd.getArrayLength()
105
		if err != nil {
106
			return err
107
		}
108
	}
109
	r.ApiKeys = make([]ApiVersionsResponseKey, numApiKeys)
110
	for i := 0; i < numApiKeys; i++ {
111
		var block ApiVersionsResponseKey
112
		if err = block.decode(pd, r.Version); err != nil {
113
			return err
114
		}
115
		r.ApiKeys[i] = block
116
	}
117

118
	if r.Version >= 1 {
119
		if r.ThrottleTimeMs, err = pd.getInt32(); err != nil {
120
			return err
121
		}
122
	}
123

124
	if r.Version >= 3 {
125
		if _, err = pd.getEmptyTaggedFieldArray(); err != nil {
126
			return err
127
		}
128
	}
129

130
	return nil
131
}
132

133
func (r *ApiVersionsResponse) key() int16 {
134
	return 18
135
}
136

137
func (r *ApiVersionsResponse) version() int16 {
138
	return r.Version
139
}
140

141
func (r *ApiVersionsResponse) headerVersion() int16 {
142
	// ApiVersionsResponse always includes a v0 header.
143
	// See KIP-511 for details
144
	return 0
145
}
146

147
func (r *ApiVersionsResponse) requiredVersion() KafkaVersion {
148
	switch r.Version {
149
	case 0:
150
		return V0_10_0_0
151
	case 3:
152
		return V2_4_0_0
153
	default:
154
		return V0_10_0_0
155
	}
156
}
157

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.