api_versions_response.go 1.8 KB

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