metadata_request.go 778 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. package sarama
  2. type MetadataRequest struct {
  3. Topics []string
  4. }
  5. func (mr *MetadataRequest) encode(pe packetEncoder) error {
  6. err := pe.putArrayLength(len(mr.Topics))
  7. if err != nil {
  8. return err
  9. }
  10. for i := range mr.Topics {
  11. err = pe.putString(mr.Topics[i])
  12. if err != nil {
  13. return err
  14. }
  15. }
  16. return nil
  17. }
  18. func (mr *MetadataRequest) decode(pd packetDecoder) error {
  19. topicCount, err := pd.getArrayLength()
  20. if err != nil {
  21. return err
  22. }
  23. if topicCount == 0 {
  24. return nil
  25. }
  26. mr.Topics = make([]string, topicCount)
  27. for i := range mr.Topics {
  28. topic, err := pd.getString()
  29. if err != nil {
  30. return err
  31. }
  32. mr.Topics[i] = topic
  33. }
  34. return nil
  35. }
  36. func (mr *MetadataRequest) key() int16 {
  37. return 3
  38. }
  39. func (mr *MetadataRequest) version() int16 {
  40. return 0
  41. }