list_partition_reassignments_response.go 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. package sarama
  2. type PartitionReplicaReassignmentsStatus struct {
  3. Replicas []int32
  4. AddingReplicas []int32
  5. RemovingReplicas []int32
  6. }
  7. func (b *PartitionReplicaReassignmentsStatus) encode(pe packetEncoder) error {
  8. if err := pe.putCompactInt32Array(b.Replicas); err != nil {
  9. return err
  10. }
  11. if err := pe.putCompactInt32Array(b.AddingReplicas); err != nil {
  12. return err
  13. }
  14. if err := pe.putCompactInt32Array(b.RemovingReplicas); err != nil {
  15. return err
  16. }
  17. pe.putEmptyTaggedFieldArray()
  18. return nil
  19. }
  20. func (b *PartitionReplicaReassignmentsStatus) decode(pd packetDecoder) (err error) {
  21. if b.Replicas, err = pd.getCompactInt32Array(); err != nil {
  22. return err
  23. }
  24. if b.AddingReplicas, err = pd.getCompactInt32Array(); err != nil {
  25. return err
  26. }
  27. if b.RemovingReplicas, err = pd.getCompactInt32Array(); err != nil {
  28. return err
  29. }
  30. if _, err := pd.getEmptyTaggedFieldArray(); err != nil {
  31. return err
  32. }
  33. return err
  34. }
  35. type ListPartitionReassignmentsResponse struct {
  36. Version int16
  37. ThrottleTimeMs int32
  38. ErrorCode KError
  39. ErrorMessage *string
  40. TopicStatus map[string]map[int32]*PartitionReplicaReassignmentsStatus
  41. }
  42. func (r *ListPartitionReassignmentsResponse) AddBlock(topic string, partition int32, replicas, addingReplicas, removingReplicas []int32) {
  43. if r.TopicStatus == nil {
  44. r.TopicStatus = make(map[string]map[int32]*PartitionReplicaReassignmentsStatus)
  45. }
  46. partitions := r.TopicStatus[topic]
  47. if partitions == nil {
  48. partitions = make(map[int32]*PartitionReplicaReassignmentsStatus)
  49. r.TopicStatus[topic] = partitions
  50. }
  51. partitions[partition] = &PartitionReplicaReassignmentsStatus{Replicas: replicas, AddingReplicas: addingReplicas, RemovingReplicas: removingReplicas}
  52. }
  53. func (r *ListPartitionReassignmentsResponse) encode(pe packetEncoder) error {
  54. pe.putInt32(r.ThrottleTimeMs)
  55. pe.putInt16(int16(r.ErrorCode))
  56. if err := pe.putNullableCompactString(r.ErrorMessage); err != nil {
  57. return err
  58. }
  59. pe.putCompactArrayLength(len(r.TopicStatus))
  60. for topic, partitions := range r.TopicStatus {
  61. if err := pe.putCompactString(topic); err != nil {
  62. return err
  63. }
  64. pe.putCompactArrayLength(len(partitions))
  65. for partition, block := range partitions {
  66. pe.putInt32(partition)
  67. if err := block.encode(pe); err != nil {
  68. return err
  69. }
  70. }
  71. pe.putEmptyTaggedFieldArray()
  72. }
  73. pe.putEmptyTaggedFieldArray()
  74. return nil
  75. }
  76. func (r *ListPartitionReassignmentsResponse) decode(pd packetDecoder, version int16) (err error) {
  77. r.Version = version
  78. if r.ThrottleTimeMs, err = pd.getInt32(); err != nil {
  79. return err
  80. }
  81. kerr, err := pd.getInt16()
  82. if err != nil {
  83. return err
  84. }
  85. r.ErrorCode = KError(kerr)
  86. if r.ErrorMessage, err = pd.getCompactNullableString(); err != nil {
  87. return err
  88. }
  89. numTopics, err := pd.getCompactArrayLength()
  90. if err != nil {
  91. return err
  92. }
  93. r.TopicStatus = make(map[string]map[int32]*PartitionReplicaReassignmentsStatus, numTopics)
  94. for i := 0; i < numTopics; i++ {
  95. topic, err := pd.getCompactString()
  96. if err != nil {
  97. return err
  98. }
  99. ongoingPartitionReassignments, err := pd.getCompactArrayLength()
  100. if err != nil {
  101. return err
  102. }
  103. r.TopicStatus[topic] = make(map[int32]*PartitionReplicaReassignmentsStatus, ongoingPartitionReassignments)
  104. for j := 0; j < ongoingPartitionReassignments; j++ {
  105. partition, err := pd.getInt32()
  106. if err != nil {
  107. return err
  108. }
  109. block := &PartitionReplicaReassignmentsStatus{}
  110. if err := block.decode(pd); err != nil {
  111. return err
  112. }
  113. r.TopicStatus[topic][partition] = block
  114. }
  115. if _, err := pd.getEmptyTaggedFieldArray(); err != nil {
  116. return err
  117. }
  118. }
  119. if _, err := pd.getEmptyTaggedFieldArray(); err != nil {
  120. return err
  121. }
  122. return nil
  123. }
  124. func (r *ListPartitionReassignmentsResponse) key() int16 {
  125. return 46
  126. }
  127. func (r *ListPartitionReassignmentsResponse) version() int16 {
  128. return r.Version
  129. }
  130. func (r *ListPartitionReassignmentsResponse) headerVersion() int16 {
  131. return 1
  132. }
  133. func (r *ListPartitionReassignmentsResponse) requiredVersion() KafkaVersion {
  134. return V2_4_0_0
  135. }