api_versions_response.go 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. package sarama
  2. type ApiVersionsResponseBlock struct {
  3. ApiKey int16
  4. MinVersion int16
  5. MaxVersion int16
  6. }
  7. func (b *ApiVersionsResponseBlock) encode(pe packetEncoder) error {
  8. pe.putInt16(b.ApiKey)
  9. pe.putInt16(b.MinVersion)
  10. pe.putInt16(b.MaxVersion)
  11. return nil
  12. }
  13. func (b *ApiVersionsResponseBlock) decode(pd packetDecoder) error {
  14. var err error
  15. if b.ApiKey, err = pd.getInt16(); err != nil {
  16. return err
  17. }
  18. if b.MinVersion, err = pd.getInt16(); err != nil {
  19. return err
  20. }
  21. if b.MaxVersion, err = pd.getInt16(); err != nil {
  22. return err
  23. }
  24. return nil
  25. }
  26. type ApiVersionsResponse struct {
  27. Err KError
  28. ApiVersions []*ApiVersionsResponseBlock
  29. }
  30. func (r *ApiVersionsResponse) encode(pe packetEncoder) error {
  31. pe.putInt16(int16(r.Err))
  32. if err := pe.putArrayLength(len(r.ApiVersions)); err != nil {
  33. return err
  34. }
  35. for _, apiVersion := range r.ApiVersions {
  36. if err := apiVersion.encode(pe); err != nil {
  37. return err
  38. }
  39. }
  40. return nil
  41. }
  42. func (r *ApiVersionsResponse) decode(pd packetDecoder, version int16) error {
  43. kerr, err := pd.getInt16()
  44. if err != nil {
  45. return err
  46. }
  47. r.Err = KError(kerr)
  48. numBlocks, err := pd.getArrayLength()
  49. if err != nil {
  50. return err
  51. }
  52. r.ApiVersions = make([]*ApiVersionsResponseBlock, numBlocks)
  53. for i := 0; i < numBlocks; i++ {
  54. block := new(ApiVersionsResponseBlock)
  55. if err := block.decode(pd); err != nil {
  56. return err
  57. }
  58. r.ApiVersions[i] = block
  59. }
  60. return nil
  61. }
  62. func (r *ApiVersionsResponse) key() int16 {
  63. return 18
  64. }
  65. func (r *ApiVersionsResponse) version() int16 {
  66. return 0
  67. }
  68. func (r *ApiVersionsResponse) requiredVersion() KafkaVersion {
  69. return V0_10_0_0
  70. }