...
1 package pgproto3
2
3 import (
4 "bytes"
5 "encoding/json"
6 )
7
8 type CommandComplete struct {
9 CommandTag []byte
10 }
11
12
13 func (*CommandComplete) Backend() {}
14
15
16
17 func (dst *CommandComplete) Decode(src []byte) error {
18 idx := bytes.IndexByte(src, 0)
19 if idx != len(src)-1 {
20 return &invalidMessageFormatErr{messageType: "CommandComplete"}
21 }
22
23 dst.CommandTag = src[:idx]
24
25 return nil
26 }
27
28
29 func (src *CommandComplete) Encode(dst []byte) ([]byte, error) {
30 dst, sp := beginMessage(dst, 'C')
31 dst = append(dst, src.CommandTag...)
32 dst = append(dst, 0)
33 return finishMessage(dst, sp)
34 }
35
36
37 func (src CommandComplete) MarshalJSON() ([]byte, error) {
38 return json.Marshal(struct {
39 Type string
40 CommandTag string
41 }{
42 Type: "CommandComplete",
43 CommandTag: string(src.CommandTag),
44 })
45 }
46
47
48 func (dst *CommandComplete) UnmarshalJSON(data []byte) error {
49
50 if string(data) == "null" {
51 return nil
52 }
53
54 var msg struct {
55 CommandTag string
56 }
57 if err := json.Unmarshal(data, &msg); err != nil {
58 return err
59 }
60
61 dst.CommandTag = []byte(msg.CommandTag)
62 return nil
63 }
64
View as plain text