File: saslhandshake.go

package info (click to toggle)
golang-github-segmentio-kafka-go 0.4.49%2Bds1-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 2,292 kB
  • sloc: sh: 17; makefile: 10
file content (53 lines) | stat: -rw-r--r-- 1,373 bytes parent folder | download
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
}