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