|
1 | 1 | package protocol
|
2 | 2 |
|
3 |
| -type SaslHandshakeRequestV0 struct { |
| 3 | +import "github.com/pkg/errors" |
| 4 | + |
| 5 | +type SaslHandshakeRequestV0orV1 struct { |
| 6 | + Version int16 // not encoded / decoded |
4 | 7 | Mechanism string
|
5 | 8 | }
|
6 | 9 |
|
7 |
| -func (r *SaslHandshakeRequestV0) encode(pe packetEncoder) error { |
| 10 | +func (r *SaslHandshakeRequestV0orV1) encode(pe packetEncoder) error { |
| 11 | + if r.Version != 0 && r.Version != 1 { |
| 12 | + return errors.New("SaslHandshakeRequestV0orV1 expects version 0 or 1") |
| 13 | + } |
| 14 | + |
8 | 15 | if err := pe.putString(r.Mechanism); err != nil {
|
9 | 16 | return err
|
10 | 17 | }
|
11 | 18 | return nil
|
12 | 19 | }
|
13 |
| -func (r *SaslHandshakeRequestV0) decode(pd packetDecoder) (err error) { |
| 20 | +func (r *SaslHandshakeRequestV0orV1) decode(pd packetDecoder) (err error) { |
| 21 | + if r.Version != 0 && r.Version != 1 { |
| 22 | + return errors.New("SaslHandshakeRequestV0orV1 expects version 0 or 1") |
| 23 | + } |
14 | 24 | if r.Mechanism, err = pd.getString(); err != nil {
|
15 | 25 | return err
|
16 | 26 | }
|
17 | 27 |
|
18 | 28 | return nil
|
19 | 29 | }
|
20 | 30 |
|
21 |
| -func (r *SaslHandshakeRequestV0) key() int16 { |
| 31 | +func (r *SaslHandshakeRequestV0orV1) key() int16 { |
22 | 32 | return 17
|
23 | 33 | }
|
24 | 34 |
|
25 |
| -func (r *SaslHandshakeRequestV0) version() int16 { |
26 |
| - return 0 |
| 35 | +func (r *SaslHandshakeRequestV0orV1) version() int16 { |
| 36 | + return r.Version |
27 | 37 | }
|
28 | 38 |
|
29 |
| -type SaslHandshakeResponseV0 struct { |
| 39 | +type SaslHandshakeResponseV0orV1 struct { |
30 | 40 | Err KError
|
31 | 41 | EnabledMechanisms []string
|
32 | 42 | }
|
33 | 43 |
|
34 |
| -func (r *SaslHandshakeResponseV0) encode(pe packetEncoder) error { |
| 44 | +func (r *SaslHandshakeResponseV0orV1) encode(pe packetEncoder) error { |
35 | 45 | pe.putInt16(int16(r.Err))
|
36 | 46 | return pe.putStringArray(r.EnabledMechanisms)
|
37 | 47 | }
|
38 | 48 |
|
39 |
| -func (r *SaslHandshakeResponseV0) decode(pd packetDecoder) error { |
| 49 | +func (r *SaslHandshakeResponseV0orV1) decode(pd packetDecoder) error { |
40 | 50 | kerr, err := pd.getInt16()
|
41 | 51 | if err != nil {
|
42 | 52 | return err
|
|
0 commit comments