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