github.com/segmentio/kafka-go@v0.4.48-0.20240318174348-3f6244eb34fd/protocol/describeconfigs/describeconfigs.go (about) 1 package describeconfigs 2 3 import ( 4 "strconv" 5 6 "github.com/segmentio/kafka-go/protocol" 7 ) 8 9 const ( 10 resourceTypeBroker int8 = 4 11 ) 12 13 func init() { 14 protocol.Register(&Request{}, &Response{}) 15 } 16 17 // Detailed API definition: https://kafka.apache.org/protocol#The_Messages_DescribeConfigs 18 type Request struct { 19 Resources []RequestResource `kafka:"min=v0,max=v3"` 20 IncludeSynonyms bool `kafka:"min=v1,max=v3"` 21 IncludeDocumentation bool `kafka:"min=v3,max=v3"` 22 } 23 24 func (r *Request) ApiKey() protocol.ApiKey { return protocol.DescribeConfigs } 25 26 func (r *Request) Broker(cluster protocol.Cluster) (protocol.Broker, error) { 27 // Broker metadata requests must be sent to the associated broker 28 for _, resource := range r.Resources { 29 if resource.ResourceType == resourceTypeBroker { 30 brokerID, err := strconv.Atoi(resource.ResourceName) 31 if err != nil { 32 return protocol.Broker{}, err 33 } 34 35 return cluster.Brokers[int32(brokerID)], nil 36 } 37 } 38 39 return cluster.Brokers[cluster.Controller], nil 40 } 41 42 func (r *Request) Split(cluster protocol.Cluster) ( 43 []protocol.Message, 44 protocol.Merger, 45 error, 46 ) { 47 messages := []protocol.Message{} 48 topicsMessage := Request{} 49 50 for _, resource := range r.Resources { 51 // Split out broker requests to separate brokers 52 if resource.ResourceType == resourceTypeBroker { 53 messages = append(messages, &Request{ 54 Resources: []RequestResource{resource}, 55 }) 56 } else { 57 topicsMessage.Resources = append( 58 topicsMessage.Resources, resource, 59 ) 60 } 61 } 62 63 if len(topicsMessage.Resources) > 0 { 64 messages = append(messages, &topicsMessage) 65 } 66 67 return messages, new(Response), nil 68 } 69 70 type RequestResource struct { 71 ResourceType int8 `kafka:"min=v0,max=v3"` 72 ResourceName string `kafka:"min=v0,max=v3"` 73 ConfigNames []string `kafka:"min=v0,max=v3,nullable"` 74 } 75 76 type Response struct { 77 ThrottleTimeMs int32 `kafka:"min=v0,max=v3"` 78 Resources []ResponseResource `kafka:"min=v0,max=v3"` 79 } 80 81 func (r *Response) ApiKey() protocol.ApiKey { return protocol.DescribeConfigs } 82 83 func (r *Response) Merge(requests []protocol.Message, results []interface{}) ( 84 protocol.Message, 85 error, 86 ) { 87 response := &Response{} 88 89 for _, result := range results { 90 m, err := protocol.Result(result) 91 if err != nil { 92 return nil, err 93 } 94 response.Resources = append( 95 response.Resources, 96 m.(*Response).Resources..., 97 ) 98 } 99 100 return response, nil 101 } 102 103 type ResponseResource struct { 104 ErrorCode int16 `kafka:"min=v0,max=v3"` 105 ErrorMessage string `kafka:"min=v0,max=v3,nullable"` 106 ResourceType int8 `kafka:"min=v0,max=v3"` 107 ResourceName string `kafka:"min=v0,max=v3"` 108 ConfigEntries []ResponseConfigEntry `kafka:"min=v0,max=v3"` 109 } 110 111 type ResponseConfigEntry struct { 112 ConfigName string `kafka:"min=v0,max=v3"` 113 ConfigValue string `kafka:"min=v0,max=v3,nullable"` 114 ReadOnly bool `kafka:"min=v0,max=v3"` 115 IsDefault bool `kafka:"min=v0,max=v0"` 116 ConfigSource int8 `kafka:"min=v1,max=v3"` 117 IsSensitive bool `kafka:"min=v0,max=v3"` 118 ConfigSynonyms []ResponseConfigSynonym `kafka:"min=v1,max=v3"` 119 ConfigType int8 `kafka:"min=v3,max=v3"` 120 ConfigDocumentation string `kafka:"min=v3,max=v3,nullable"` 121 } 122 123 type ResponseConfigSynonym struct { 124 ConfigName string `kafka:"min=v1,max=v3"` 125 ConfigValue string `kafka:"min=v1,max=v3,nullable"` 126 ConfigSource int8 `kafka:"min=v1,max=v3"` 127 } 128 129 var _ protocol.BrokerMessage = (*Request)(nil)