1package pgproto3
2
3import (
4	"encoding/binary"
5	"encoding/json"
6	"errors"
7
8	"github.com/jackc/pgio"
9)
10
11const gssEncReqNumber = 80877104
12
13type GSSEncRequest struct {
14}
15
16// Frontend identifies this message as sendable by a PostgreSQL frontend.
17func (*GSSEncRequest) Frontend() {}
18
19func (dst *GSSEncRequest) Decode(src []byte) error {
20	if len(src) < 4 {
21		return errors.New("gss encoding request too short")
22	}
23
24	requestCode := binary.BigEndian.Uint32(src)
25
26	if requestCode != gssEncReqNumber {
27		return errors.New("bad gss encoding request code")
28	}
29
30	return nil
31}
32
33// Encode encodes src into dst. dst will include the 4 byte message length.
34func (src *GSSEncRequest) Encode(dst []byte) []byte {
35	dst = pgio.AppendInt32(dst, 8)
36	dst = pgio.AppendInt32(dst, gssEncReqNumber)
37	return dst
38}
39
40// MarshalJSON implements encoding/json.Marshaler.
41func (src GSSEncRequest) MarshalJSON() ([]byte, error) {
42	return json.Marshal(struct {
43		Type            string
44		ProtocolVersion uint32
45		Parameters      map[string]string
46	}{
47		Type: "GSSEncRequest",
48	})
49}
50