sasl_authenticate_response.go 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. package sarama
  2. type SaslAuthenticateResponse struct {
  3. // Version defines the protocol version to use for encode and decode
  4. Version int16
  5. Err KError
  6. ErrorMessage *string
  7. SaslAuthBytes []byte
  8. SessionLifetimeMs int64
  9. }
  10. func (r *SaslAuthenticateResponse) encode(pe packetEncoder) error {
  11. pe.putInt16(int16(r.Err))
  12. if err := pe.putNullableString(r.ErrorMessage); err != nil {
  13. return err
  14. }
  15. if err := pe.putBytes(r.SaslAuthBytes); err != nil {
  16. return err
  17. }
  18. if r.Version > 0 {
  19. pe.putInt64(r.SessionLifetimeMs)
  20. }
  21. return nil
  22. }
  23. func (r *SaslAuthenticateResponse) decode(pd packetDecoder, version int16) error {
  24. r.Version = version
  25. kerr, err := pd.getInt16()
  26. if err != nil {
  27. return err
  28. }
  29. r.Err = KError(kerr)
  30. if r.ErrorMessage, err = pd.getNullableString(); err != nil {
  31. return err
  32. }
  33. if r.SaslAuthBytes, err = pd.getBytes(); err != nil {
  34. return err
  35. }
  36. if version > 0 {
  37. r.SessionLifetimeMs, err = pd.getInt64()
  38. }
  39. return err
  40. }
  41. func (r *SaslAuthenticateResponse) key() int16 {
  42. return APIKeySASLAuth
  43. }
  44. func (r *SaslAuthenticateResponse) version() int16 {
  45. return r.Version
  46. }
  47. func (r *SaslAuthenticateResponse) headerVersion() int16 {
  48. return 0
  49. }
  50. func (r *SaslAuthenticateResponse) isValidVersion() bool {
  51. return r.Version >= 0 && r.Version <= 1
  52. }
  53. func (r *SaslAuthenticateResponse) requiredVersion() KafkaVersion {
  54. switch r.Version {
  55. case 1:
  56. return V2_2_0_0
  57. default:
  58. return V1_0_0_0
  59. }
  60. }