acl_describe_response.go 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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 d.Version
  63. }
  64. func (d *DescribeAclsResponse) headerVersion() int16 {
  65. return 0
  66. }
  67. func (d *DescribeAclsResponse) requiredVersion() KafkaVersion {
  68. switch d.Version {
  69. case 1:
  70. return V2_0_0_0
  71. default:
  72. return V0_11_0_0
  73. }
  74. }