...
1 package pgproto3
2
3 import (
4 "bytes"
5 "encoding/binary"
6 "encoding/json"
7
8 "github.com/jackc/pgio"
9 )
10
11 type Execute struct {
12 Portal string
13 MaxRows uint32
14 }
15
16
17 func (*Execute) Frontend() {}
18
19
20
21 func (dst *Execute) Decode(src []byte) error {
22 buf := bytes.NewBuffer(src)
23
24 b, err := buf.ReadBytes(0)
25 if err != nil {
26 return err
27 }
28 dst.Portal = string(b[:len(b)-1])
29
30 if buf.Len() < 4 {
31 return &invalidMessageFormatErr{messageType: "Execute"}
32 }
33 dst.MaxRows = binary.BigEndian.Uint32(buf.Next(4))
34
35 return nil
36 }
37
38
39 func (src *Execute) Encode(dst []byte) ([]byte, error) {
40 dst, sp := beginMessage(dst, 'E')
41 dst = append(dst, src.Portal...)
42 dst = append(dst, 0)
43 dst = pgio.AppendUint32(dst, src.MaxRows)
44 return finishMessage(dst, sp)
45 }
46
47
48 func (src Execute) MarshalJSON() ([]byte, error) {
49 return json.Marshal(struct {
50 Type string
51 Portal string
52 MaxRows uint32
53 }{
54 Type: "Execute",
55 Portal: src.Portal,
56 MaxRows: src.MaxRows,
57 })
58 }
59
View as plain text