...
1 package pgproto3
2
3 import (
4 "bytes"
5 "encoding/json"
6 )
7
8 type CopyFail struct {
9 Message string
10 }
11
12
13 func (*CopyFail) Frontend() {}
14
15
16
17 func (dst *CopyFail) Decode(src []byte) error {
18 idx := bytes.IndexByte(src, 0)
19 if idx != len(src)-1 {
20 return &invalidMessageFormatErr{messageType: "CopyFail"}
21 }
22
23 dst.Message = string(src[:idx])
24
25 return nil
26 }
27
28
29 func (src *CopyFail) Encode(dst []byte) ([]byte, error) {
30 dst, sp := beginMessage(dst, 'f')
31 dst = append(dst, src.Message...)
32 dst = append(dst, 0)
33 return finishMessage(dst, sp)
34 }
35
36
37 func (src CopyFail) MarshalJSON() ([]byte, error) {
38 return json.Marshal(struct {
39 Type string
40 Message string
41 }{
42 Type: "CopyFail",
43 Message: src.Message,
44 })
45 }
46
View as plain text