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