gss_enc_request.go 1.0 KB

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