MCPcopy
hub / github.com/segmentio/kafka-go / makeTypes

Function makeTypes

protocol/protocol.go:251–289  ·  view source on GitHub ↗
(t reflect.Type)

Source from the content-addressed store, hash-verified

249}
250
251func makeTypes(t reflect.Type) []messageType {
252 minVersion := int16(-1)
253 maxVersion := int16(-1)
254
255 // All future versions will be flexible (according to spec), so don't need to
256 // worry about maxes here.
257 minFlexibleVersion := int16(-1)
258
259 forEachStructField(t, func(_ reflect.Type, _ index, tag string) {
260 forEachStructTag(tag, func(tag structTag) bool {
261 if minVersion < 0 || tag.MinVersion < minVersion {
262 minVersion = tag.MinVersion
263 }
264 if maxVersion < 0 || tag.MaxVersion > maxVersion {
265 maxVersion = tag.MaxVersion
266 }
267 if tag.TagID > -2 && (minFlexibleVersion < 0 || tag.MinVersion < minFlexibleVersion) {
268 minFlexibleVersion = tag.MinVersion
269 }
270 return true
271 })
272 })
273
274 types := make([]messageType, 0, (maxVersion-minVersion)+1)
275
276 for v := minVersion; v <= maxVersion; v++ {
277 flexible := minFlexibleVersion >= 0 && v >= minFlexibleVersion
278
279 types = append(types, messageType{
280 version: v,
281 gotype: t,
282 flexible: flexible,
283 decode: decodeFuncOf(t, v, flexible, structTag{}),
284 encode: encodeFuncOf(t, v, flexible, structTag{}),
285 })
286 }
287
288 return types
289}
290
291type structTag struct {
292 MinVersion int16

Callers 3

TestMakeFlexibleTypesFunction · 0.85
typesOfFunction · 0.85

Calls 4

forEachStructFieldFunction · 0.85
forEachStructTagFunction · 0.85
decodeFuncOfFunction · 0.85
encodeFuncOfFunction · 0.85

Tested by 2

TestMakeFlexibleTypesFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…