acl_describe_response.go 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. package sarama
  2. import "time"
  3. //DescribeAclsResponse is a describe acl response type
  4. type DescribeAclsResponse struct {
  5. Version int16
  6. ThrottleTime time.Duration
  7. Err KError
  8. ErrMsg *string
  9. ResourceAcls []*ResourceAcls
  10. }
  11. func (d *DescribeAclsResponse) encode(pe packetEncoder) error {
  12. pe.putInt32(int32(d.ThrottleTime / time.Millisecond))
  13. pe.putInt16(int16(d.Err))
  14. if err := pe.putNullableString(d.ErrMsg); err != nil {
  15. return err
  16. }
  17. if err := pe.putArrayLength(len(d.ResourceAcls)); err != nil {
  18. return err
  19. }
  20. for _, resourceAcl := range d.ResourceAcls {
  21. if err := resourceAcl.encode(pe, d.Version); err != nil {
  22. return err
  23. }
  24. }
  25. return nil
  26. }
  27. func (d *DescribeAclsResponse) decode(pd packetDecoder, version int16) (err error) {
  28. throttleTime, err := pd.getInt32()
  29. if err != nil {
  30. return err
  31. }
  32. d.ThrottleTime = time.Duration(throttleTime) * time.Millisecond
  33. kerr, err := pd.getInt16()
  34. if err != nil {
  35. return err
  36. }
  37. d.Err = KError(kerr)
  38. errmsg, err := pd.getString()
  39. if err != nil {
  40. return err
  41. }
  42. if errmsg != "" {
  43. d.ErrMsg = &errmsg
  44. }
  45. n, err := pd.getArrayLength()
  46. if err != nil {
  47. return err
  48. }
  49. d.ResourceAcls = make([]*ResourceAcls, n)
  50. for i := 0; i < n; i++ {
  51. d.ResourceAcls[i] = new(ResourceAcls)
  52. if err := d.ResourceAcls[i].decode(pd, version); err != nil {
  53. return err
  54. }
  55. }
  56. return nil
  57. }
  58. func (d *DescribeAclsResponse) key() int16 {
  59. return 29
  60. }
  61. func (d *DescribeAclsResponse) version() int16 {
  62. return int16(d.Version)
  63. }
  64. func (d *DescribeAclsResponse) requiredVersion() KafkaVersion {
  65. switch d.Version {
  66. case 1:
  67. return V2_0_0_0
  68. default:
  69. return V0_11_0_0
  70. }
  71. }