-
Notifications
You must be signed in to change notification settings - Fork 2
/
bind_complete.go
59 lines (48 loc) · 1.21 KB
/
bind_complete.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
55
56
57
58
59
package pgproto
import (
"bytes"
"fmt"
"io"
)
// '2' [int32 - length]
var rawBindCompleteMessage = [5]byte{
// Tag
'2',
// Length
'\x00', '\x00', '\x00', '\x04',
}
// BindComplete represents a server response message
type BindComplete struct{}
func (b *BindComplete) server() {}
// ParseBindComplete will attempt to read an BindComplete message from the io.Reader
func ParseBindComplete(r io.Reader) (*BindComplete, error) {
b := newReadBuffer(r)
var msg [5]byte
_, err := b.Read(msg[:])
if err != nil {
return nil, err
}
if !bytes.Equal(msg[:], rawBindCompleteMessage[:]) {
return nil, fmt.Errorf("invalid bind complete message")
}
return &BindComplete{}, nil
}
// Encode will return the byte representation of this message
func (b *BindComplete) Encode() []byte {
// '2' [int32 - length]
return rawBindCompleteMessage[:]
}
// AsMap method returns a common map representation of this message:
//
// map[string]interface{}{
// "Type": "BindComplete",
// "Payload": nil,
// },
// }
func (b *BindComplete) AsMap() map[string]interface{} {
return map[string]interface{}{
"Type": "BindComplete",
"Payload": nil,
}
}
func (b *BindComplete) String() string { return messageToString(b) }