alter_partition_reassignments_response.go 3.9 KB

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