saslhandshake.go 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. package kafka
  2. import (
  3. "bufio"
  4. )
  5. // saslHandshakeRequestV0 implements the format for V0 and V1 SASL
  6. // requests (they are identical)
  7. type saslHandshakeRequestV0 struct {
  8. // Mechanism holds the SASL Mechanism chosen by the client.
  9. Mechanism string
  10. }
  11. func (t saslHandshakeRequestV0) size() int32 {
  12. return sizeofString(t.Mechanism)
  13. }
  14. func (t *saslHandshakeRequestV0) readFrom(r *bufio.Reader, sz int) (remain int, err error) {
  15. return readString(r, sz, &t.Mechanism)
  16. }
  17. func (t saslHandshakeRequestV0) writeTo(wb *writeBuffer) {
  18. wb.writeString(t.Mechanism)
  19. }
  20. // saslHandshakeResponseV0 implements the format for V0 and V1 SASL
  21. // responses (they are identical)
  22. type saslHandshakeResponseV0 struct {
  23. // ErrorCode holds response error code
  24. ErrorCode int16
  25. // Array of mechanisms enabled in the server
  26. EnabledMechanisms []string
  27. }
  28. func (t saslHandshakeResponseV0) size() int32 {
  29. return sizeofInt16(t.ErrorCode) + sizeofStringArray(t.EnabledMechanisms)
  30. }
  31. func (t saslHandshakeResponseV0) writeTo(wb *writeBuffer) {
  32. wb.writeInt16(t.ErrorCode)
  33. wb.writeStringArray(t.EnabledMechanisms)
  34. }
  35. func (t *saslHandshakeResponseV0) readFrom(r *bufio.Reader, sz int) (remain int, err error) {
  36. if remain, err = readInt16(r, sz, &t.ErrorCode); err != nil {
  37. return
  38. }
  39. if remain, err = readStringArray(r, remain, &t.EnabledMechanisms); err != nil {
  40. return
  41. }
  42. return
  43. }