delete_offsets_request.go 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. package sarama
  2. type DeleteOffsetsRequest struct {
  3. Version int16
  4. Group string
  5. partitions map[string][]int32
  6. }
  7. func (r *DeleteOffsetsRequest) encode(pe packetEncoder) (err error) {
  8. err = pe.putString(r.Group)
  9. if err != nil {
  10. return err
  11. }
  12. if r.partitions == nil {
  13. pe.putInt32(0)
  14. } else {
  15. if err = pe.putArrayLength(len(r.partitions)); err != nil {
  16. return err
  17. }
  18. }
  19. for topic, partitions := range r.partitions {
  20. err = pe.putString(topic)
  21. if err != nil {
  22. return err
  23. }
  24. err = pe.putInt32Array(partitions)
  25. if err != nil {
  26. return err
  27. }
  28. }
  29. return
  30. }
  31. func (r *DeleteOffsetsRequest) decode(pd packetDecoder, version int16) (err error) {
  32. r.Group, err = pd.getString()
  33. if err != nil {
  34. return err
  35. }
  36. var partitionCount int
  37. partitionCount, err = pd.getArrayLength()
  38. if err != nil {
  39. return err
  40. }
  41. if (partitionCount == 0 && version < 2) || partitionCount < 0 {
  42. return nil
  43. }
  44. r.partitions = make(map[string][]int32, partitionCount)
  45. for i := 0; i < partitionCount; i++ {
  46. var topic string
  47. topic, err = pd.getString()
  48. if err != nil {
  49. return err
  50. }
  51. var partitions []int32
  52. partitions, err = pd.getInt32Array()
  53. if err != nil {
  54. return err
  55. }
  56. r.partitions[topic] = partitions
  57. }
  58. return nil
  59. }
  60. func (r *DeleteOffsetsRequest) key() int16 {
  61. return 47
  62. }
  63. func (r *DeleteOffsetsRequest) version() int16 {
  64. return r.Version
  65. }
  66. func (r *DeleteOffsetsRequest) headerVersion() int16 {
  67. return 1
  68. }
  69. func (r *DeleteOffsetsRequest) isValidVersion() bool {
  70. return r.Version == 0
  71. }
  72. func (r *DeleteOffsetsRequest) requiredVersion() KafkaVersion {
  73. return V2_4_0_0
  74. }
  75. func (r *DeleteOffsetsRequest) AddPartition(topic string, partitionID int32) {
  76. if r.partitions == nil {
  77. r.partitions = make(map[string][]int32)
  78. }
  79. r.partitions[topic] = append(r.partitions[topic], partitionID)
  80. }