-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcopy_both_response.go
73 lines (59 loc) · 1.41 KB
/
copy_both_response.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
64
65
66
67
68
69
70
71
72
73
package pgproto
import (
"io"
)
type CopyBothResponse struct {
Format Format
ColumnFormats []int
}
func (c *CopyBothResponse) server() {}
func ParseCopyBothResponse(r io.Reader) (*CopyBothResponse, error) {
b := newReadBuffer(r)
// 'W' [int32 - length] [int16 - count] [int16 - format] ...
err := b.ReadTag('W')
if err != nil {
return nil, err
}
buf, err := b.ReadLength()
if err != nil {
return nil, err
}
format, err := buf.ReadByte()
count, err := buf.ReadInt16()
if err != nil {
return nil, err
}
c := &CopyBothResponse{
Format: Format(format),
ColumnFormats: make([]int, count),
}
for i := 0; i < count; i++ {
c.ColumnFormats[i], err = buf.ReadInt16()
if err != nil {
return nil, err
}
}
return c, nil
}
// Encode will return the byte representation of this message
func (c *CopyBothResponse) Encode() []byte {
// 'W' [int32 - length] [int16 - count] [int16 - format] ...
w := newWriteBuffer()
w.WriteByte(byte(c.Format))
w.WriteInt16(len(c.ColumnFormats))
for _, format := range c.ColumnFormats {
w.WriteInt16(format)
}
w.Wrap('W')
return w.Bytes()
}
func (c *CopyBothResponse) AsMap() map[string]interface{} {
return map[string]interface{}{
"Type": "CopyBothResponse",
"Payload": map[string]interface{}{
"Format": c.Format,
"ColumnFormats": c.ColumnFormats,
},
}
}
func (c *CopyBothResponse) String() string { return messageToString(c) }