...
1 package pgproto3
2
3 import (
4 "encoding/binary"
5 "encoding/json"
6 "errors"
7
8 "github.com/jackc/pgx/v5/internal/pgio"
9 )
10
11
12 type AuthenticationOk struct {
13 }
14
15
16 func (*AuthenticationOk) Backend() {}
17
18
19 func (*AuthenticationOk) AuthenticationResponse() {}
20
21
22
23 func (dst *AuthenticationOk) Decode(src []byte) error {
24 if len(src) != 4 {
25 return errors.New("bad authentication message size")
26 }
27
28 authType := binary.BigEndian.Uint32(src)
29
30 if authType != AuthTypeOk {
31 return errors.New("bad auth type")
32 }
33
34 return nil
35 }
36
37
38 func (src *AuthenticationOk) Encode(dst []byte) ([]byte, error) {
39 dst, sp := beginMessage(dst, 'R')
40 dst = pgio.AppendUint32(dst, AuthTypeOk)
41 return finishMessage(dst, sp)
42 }
43
44
45 func (src AuthenticationOk) MarshalJSON() ([]byte, error) {
46 return json.Marshal(struct {
47 Type string
48 }{
49 Type: "AuthenticationOK",
50 })
51 }
52
View as plain text