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