consumer_metadata_request.go 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. package sarama
  2. // ConsumerMetadataRequest is used for metadata requests
  3. type ConsumerMetadataRequest struct {
  4. Version int16
  5. ConsumerGroup string
  6. }
  7. func (r *ConsumerMetadataRequest) encode(pe packetEncoder) error {
  8. tmp := new(FindCoordinatorRequest)
  9. tmp.CoordinatorKey = r.ConsumerGroup
  10. tmp.CoordinatorType = CoordinatorGroup
  11. tmp.Version = r.Version
  12. return tmp.encode(pe)
  13. }
  14. func (r *ConsumerMetadataRequest) decode(pd packetDecoder, version int16) (err error) {
  15. tmp := new(FindCoordinatorRequest)
  16. if err := tmp.decode(pd, version); err != nil {
  17. return err
  18. }
  19. r.ConsumerGroup = tmp.CoordinatorKey
  20. return nil
  21. }
  22. func (r *ConsumerMetadataRequest) key() int16 {
  23. return 10
  24. }
  25. func (r *ConsumerMetadataRequest) version() int16 {
  26. return r.Version
  27. }
  28. func (r *ConsumerMetadataRequest) headerVersion() int16 {
  29. return 1
  30. }
  31. func (r *ConsumerMetadataRequest) isValidVersion() bool {
  32. return r.Version >= 0 && r.Version <= 2
  33. }
  34. func (r *ConsumerMetadataRequest) requiredVersion() KafkaVersion {
  35. switch r.Version {
  36. case 2:
  37. return V2_0_0_0
  38. case 1:
  39. return V0_11_0_0
  40. default:
  41. return V0_8_2_0
  42. }
  43. }