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