-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathbackend.go
More file actions
73 lines (62 loc) · 1.43 KB
/
backend.go
File metadata and controls
73 lines (62 loc) · 1.43 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
72
73
package pgproto
import (
"io"
)
// BackendKeyData is a server response message
type BackendKeyData struct {
PID int
Key int
}
func (b *BackendKeyData) server() {}
// ParseBackendKeyData is used to parse a BackendKeyData message from an io.Reader
func ParseBackendKeyData(r io.Reader) (*BackendKeyData, error) {
buf := newReadBuffer(r)
// 'K' [int32 - length] [int32 - pid] [in32 - key]
err := buf.ReadTag('K')
if err != nil {
return nil, err
}
buf, err = buf.ReadLength()
if err != nil {
return nil, err
}
pid, err := buf.ReadInt()
if err != nil {
return nil, err
}
key, err := buf.ReadInt()
if err != nil {
return nil, err
}
return &BackendKeyData{
PID: pid,
Key: key,
}, nil
}
// Encode will return the byte representation of this message
func (b *BackendKeyData) Encode() []byte {
buf := newWriteBuffer()
buf.WriteInt(b.PID)
buf.WriteInt(b.Key)
buf.Wrap('K')
return buf.Bytes()
}
// AsMap method returns a common map representation of this message:
//
// map[string]interface{}{
// "Type": "BackendKeyData",
// "Payload": map[string]interface{}{
// "PID": <BackendKeyData.PID>,
// "Key": <BackendKeyData.Key>,
// },
// }
func (b *BackendKeyData) AsMap() map[string]interface{} {
return map[string]interface{}{
"Type": "BackendKeyData",
"Payload": map[string]interface{}{
"PID": b.PID,
"Key": b.Key,
},
}
}
func (b *BackendKeyData) String() string { return messageToString(b) }