acl_filter.go 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. package sarama
  2. type AclFilter struct {
  3. Version int
  4. ResourceType AclResourceType
  5. ResourceName *string
  6. ResourcePatternTypeFilter AclResourcePatternType
  7. Principal *string
  8. Host *string
  9. Operation AclOperation
  10. PermissionType AclPermissionType
  11. }
  12. func (a *AclFilter) encode(pe packetEncoder) error {
  13. pe.putInt8(int8(a.ResourceType))
  14. if err := pe.putNullableString(a.ResourceName); err != nil {
  15. return err
  16. }
  17. if a.Version == 1 {
  18. pe.putInt8(int8(a.ResourcePatternTypeFilter))
  19. }
  20. if err := pe.putNullableString(a.Principal); err != nil {
  21. return err
  22. }
  23. if err := pe.putNullableString(a.Host); err != nil {
  24. return err
  25. }
  26. pe.putInt8(int8(a.Operation))
  27. pe.putInt8(int8(a.PermissionType))
  28. return nil
  29. }
  30. func (a *AclFilter) decode(pd packetDecoder, version int16) (err error) {
  31. resourceType, err := pd.getInt8()
  32. if err != nil {
  33. return err
  34. }
  35. a.ResourceType = AclResourceType(resourceType)
  36. if a.ResourceName, err = pd.getNullableString(); err != nil {
  37. return err
  38. }
  39. if a.Version == 1 {
  40. pattern, err := pd.getInt8()
  41. if err != nil {
  42. return err
  43. }
  44. a.ResourcePatternTypeFilter = AclResourcePatternType(pattern)
  45. }
  46. if a.Principal, err = pd.getNullableString(); err != nil {
  47. return err
  48. }
  49. if a.Host, err = pd.getNullableString(); err != nil {
  50. return err
  51. }
  52. operation, err := pd.getInt8()
  53. if err != nil {
  54. return err
  55. }
  56. a.Operation = AclOperation(operation)
  57. permissionType, err := pd.getInt8()
  58. if err != nil {
  59. return err
  60. }
  61. a.PermissionType = AclPermissionType(permissionType)
  62. return nil
  63. }