-
Notifications
You must be signed in to change notification settings - Fork 2
/
command.go
63 lines (52 loc) · 1.33 KB
/
command.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
60
61
62
63
package pgproto
import (
"io"
)
// CommandCompletion represents a server response message
type CommandCompletion struct {
Tag []byte
}
func (c *CommandCompletion) server() {}
// ParseCommandCompletion will attempt to read a CommandCompletion message from the io.Reader
func ParseCommandCompletion(r io.Reader) (*CommandCompletion, error) {
b := newReadBuffer(r)
// 'C' [int32 - length] [bytes - tag] \0
err := b.ReadTag('C')
if err != nil {
return nil, err
}
b, err = b.ReadLength()
if err != nil {
return nil, err
}
c := &CommandCompletion{}
c.Tag, err = b.ReadString(stripNull)
if err != nil {
return nil, err
}
return c, nil
}
// Encode will return the byte representation of this message
func (c *CommandCompletion) Encode() []byte {
b := newWriteBuffer()
b.WriteString(c.Tag, writeNull)
b.Wrap('C')
return b.Bytes()
}
// AsMap method returns a common map representation of this message:
//
// map[string]interface{}{
// "Type": "CommandCompletion",
// "Payload": map[string]interface{}{
// "Tag": <CommandCompletion.Tag>,
// },
// }
func (c *CommandCompletion) AsMap() map[string]interface{} {
return map[string]interface{}{
"Type": "CommandCompletion",
"Payload": map[string]string{
"Tag": string(c.Tag),
},
}
}
func (c *CommandCompletion) String() string { return messageToString(c) }