1package pgproto3
2
3import (
4	"encoding/hex"
5	"encoding/json"
6
7	"github.com/jackc/pgx/pgio"
8)
9
10type CopyData struct {
11	Data []byte
12}
13
14func (*CopyData) Backend()  {}
15func (*CopyData) Frontend() {}
16
17func (dst *CopyData) Decode(src []byte) error {
18	dst.Data = src
19	return nil
20}
21
22func (src *CopyData) Encode(dst []byte) []byte {
23	dst = append(dst, 'd')
24	dst = pgio.AppendInt32(dst, int32(4+len(src.Data)))
25	dst = append(dst, src.Data...)
26	return dst
27}
28
29func (src *CopyData) MarshalJSON() ([]byte, error) {
30	return json.Marshal(struct {
31		Type string
32		Data string
33	}{
34		Type: "CopyData",
35		Data: hex.EncodeToString(src.Data),
36	})
37}
38