-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathready.go
More file actions
71 lines (57 loc) · 1.11 KB
/
ready.go
File metadata and controls
71 lines (57 loc) · 1.11 KB
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
package pgproto
import (
"fmt"
"io"
)
type ReadyStatus int
const (
READY_IDLE ReadyStatus = 73
)
func (r ReadyStatus) String() string {
switch r {
case READY_IDLE:
return "Idle"
}
return "Unknown"
}
type ReadyForQuery struct {
Status ReadyStatus
}
func (r *ReadyForQuery) server() {}
func ParseReadyForQuery(r io.Reader) (*ReadyForQuery, error) {
b := newReadBuffer(r)
// 'Z' [int32 - length] [byte - status]
err := b.ReadTag('Z')
if err != nil {
return nil, err
}
l, err := b.ReadInt()
if err != nil {
return nil, err
}
if l != 5 {
return nil, fmt.Errorf("unexpected message length")
}
i, err := b.ReadByte()
if err != nil {
return nil, err
}
return &ReadyForQuery{
Status: ReadyStatus(i),
}, nil
}
func (r *ReadyForQuery) Encode() []byte {
b := newWriteBuffer()
b.WriteByte(byte(r.Status))
b.Wrap('Z')
return b.Bytes()
}
func (r *ReadyForQuery) AsMap() map[string]interface{} {
return map[string]interface{}{
"Type": "ReadyForQuery",
"Payload": map[string]interface{}{
"Status": r.Status,
},
}
}
func (r *ReadyForQuery) String() string { return messageToString(r) }