-
Notifications
You must be signed in to change notification settings - Fork 18
/
sasl_handshake_response.go
54 lines (44 loc) · 1.31 KB
/
sasl_handshake_response.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
54
package healer
import (
"encoding/binary"
"fmt"
)
// SaslHandshakeResponse is the response of saslhandshake request
type SaslHandshakeResponse struct {
CorrelationID uint32
ErrorCode int16
EnabledMechanisms []string
}
func (r SaslHandshakeResponse) Error() error {
if r.ErrorCode != 0 {
return KafkaError(r.ErrorCode)
}
return nil
}
// NewSaslHandshakeResponse create a NewSaslHandshakeResponse instance from response payload bytes
func NewSaslHandshakeResponse(payload []byte) (r SaslHandshakeResponse, err error) {
var offset = 0
responseLength := int(binary.BigEndian.Uint32(payload))
if responseLength+4 != len(payload) {
return r, fmt.Errorf("SaslHandshakeResponse length did not match: %d!=%d", responseLength+4, len(payload))
}
offset += 4
r.CorrelationID = uint32(binary.BigEndian.Uint32(payload[offset:]))
offset += 4
r.ErrorCode = int16(uint16(binary.BigEndian.Uint32(payload[offset:])))
offset += 2
if r.ErrorCode != 0 {
err = KafkaError(r.ErrorCode)
}
count := int(binary.BigEndian.Uint32(payload[offset:]))
offset += 4
r.EnabledMechanisms = make([]string, count)
for i := 0; i < count; i++ {
l := int(binary.BigEndian.Uint16(payload[offset:]))
offset += 2
mechanism := string(payload[offset : offset+l])
r.EnabledMechanisms[i] = mechanism
offset += l
}
return r, err
}