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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
|
package proto
import "github.com/go-faster/errors"
// ClientHello represents ClientCodeHello message.
type ClientHello struct {
Name string
Major int // client major version
Minor int // client minor version
// ProtocolVersion is TCP protocol version of client.
//
// Usually it is equal to the latest compatible server revision, but
// should not be confused with it.
ProtocolVersion int
Database string
User string
Password string
}
// Encode to Buffer.
func (c ClientHello) Encode(b *Buffer) {
ClientCodeHello.Encode(b)
b.PutString(c.Name)
b.PutInt(c.Major)
b.PutInt(c.Minor)
b.PutInt(c.ProtocolVersion)
b.PutString(c.Database)
b.PutString(c.User)
b.PutString(c.Password)
}
func (c *ClientHello) Decode(r *Reader) error {
{
v, err := r.Str()
if err != nil {
return errors.Wrap(err, "name")
}
c.Name = v
}
{
v, err := r.Int()
if err != nil {
return errors.Wrap(err, "major")
}
c.Major = v
}
{
v, err := r.Int()
if err != nil {
return errors.Wrap(err, "minor")
}
c.Minor = v
}
{
v, err := r.Int()
if err != nil {
return errors.Wrap(err, "protocol version")
}
c.ProtocolVersion = v
}
{
v, err := r.Str()
if err != nil {
return errors.Wrap(err, "database")
}
c.Database = v
}
{
v, err := r.Str()
if err != nil {
return errors.Wrap(err, "user")
}
c.User = v
}
{
v, err := r.Str()
if err != nil {
return errors.Wrap(err, "password")
}
c.Password = v
}
return nil
}
|