-
Notifications
You must be signed in to change notification settings - Fork 2
/
copy_data.go
57 lines (46 loc) · 1008 Bytes
/
copy_data.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
package pgproto
import (
"fmt"
"io"
)
type CopyData struct {
Data []byte
}
func (c *CopyData) server() {}
func ParseCopyData(r io.Reader) (*CopyData, error) {
b := newReadBuffer(r)
// 'd' [int32 - length] [bytes - data]
err := b.ReadTag('d')
if err != nil {
return nil, err
}
l, err := b.ReadInt()
if err != nil {
return nil, err
}
c := &CopyData{
Data: make([]byte, l),
}
n, err := b.Read(c.Data)
if n != l && err == nil {
return nil, fmt.Errorf("expected to read length %d, instead read %d", l, n)
}
return c, err
}
// Encode will return the byte representation of this message
func (c *CopyData) Encode() []byte {
// 'd' [int32 - length] [bytes - data]
w := newWriteBuffer()
w.WriteBytes(c.Data)
w.Wrap('d')
return w.Bytes()
}
func (c *CopyData) AsMap() map[string]interface{} {
return map[string]interface{}{
"Type": "CopyData",
"Payload": map[string]interface{}{
"Data": c.Data,
},
}
}
func (c *CopyData) String() string { return messageToString(c) }