khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 1 | package sarama |
| 2 | |
| 3 | // DescribeLogDirsRequest is a describe request to get partitions' log size |
| 4 | type DescribeLogDirsRequest struct { |
| 5 | // Version 0 and 1 are equal |
| 6 | // The version number is bumped to indicate that on quota violation brokers send out responses before throttling. |
| 7 | Version int16 |
| 8 | |
| 9 | // If this is an empty array, all topics will be queried |
| 10 | DescribeTopics []DescribeLogDirsRequestTopic |
| 11 | } |
| 12 | |
| 13 | // DescribeLogDirsRequestTopic is a describe request about the log dir of one or more partitions within a Topic |
| 14 | type DescribeLogDirsRequestTopic struct { |
| 15 | Topic string |
| 16 | PartitionIDs []int32 |
| 17 | } |
| 18 | |
| 19 | func (r *DescribeLogDirsRequest) encode(pe packetEncoder) error { |
| 20 | length := len(r.DescribeTopics) |
| 21 | if length == 0 { |
| 22 | // In order to query all topics we must send null |
| 23 | length = -1 |
| 24 | } |
| 25 | |
| 26 | if err := pe.putArrayLength(length); err != nil { |
| 27 | return err |
| 28 | } |
| 29 | |
| 30 | for _, d := range r.DescribeTopics { |
| 31 | if err := pe.putString(d.Topic); err != nil { |
| 32 | return err |
| 33 | } |
| 34 | |
| 35 | if err := pe.putInt32Array(d.PartitionIDs); err != nil { |
| 36 | return err |
| 37 | } |
| 38 | } |
| 39 | |
| 40 | return nil |
| 41 | } |
| 42 | |
| 43 | func (r *DescribeLogDirsRequest) decode(pd packetDecoder, version int16) error { |
| 44 | n, err := pd.getArrayLength() |
| 45 | if err != nil { |
| 46 | return err |
| 47 | } |
| 48 | if n == -1 { |
| 49 | n = 0 |
| 50 | } |
| 51 | |
| 52 | topics := make([]DescribeLogDirsRequestTopic, n) |
| 53 | for i := 0; i < n; i++ { |
| 54 | topics[i] = DescribeLogDirsRequestTopic{} |
| 55 | |
| 56 | topic, err := pd.getString() |
| 57 | if err != nil { |
| 58 | return err |
| 59 | } |
| 60 | topics[i].Topic = topic |
| 61 | |
| 62 | pIDs, err := pd.getInt32Array() |
| 63 | if err != nil { |
| 64 | return err |
| 65 | } |
| 66 | topics[i].PartitionIDs = pIDs |
| 67 | } |
| 68 | r.DescribeTopics = topics |
| 69 | |
| 70 | return nil |
| 71 | } |
| 72 | |
| 73 | func (r *DescribeLogDirsRequest) key() int16 { |
| 74 | return 35 |
| 75 | } |
| 76 | |
| 77 | func (r *DescribeLogDirsRequest) version() int16 { |
| 78 | return r.Version |
| 79 | } |
| 80 | |
| 81 | func (r *DescribeLogDirsRequest) headerVersion() int16 { |
| 82 | return 1 |
| 83 | } |
| 84 | |
| 85 | func (r *DescribeLogDirsRequest) requiredVersion() KafkaVersion { |
| 86 | return V1_0_0_0 |
| 87 | } |