gss_response.go 899 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. package pgproto3
  2. import (
  3. "encoding/json"
  4. )
  5. type GSSResponse struct {
  6. Data []byte
  7. }
  8. // Frontend identifies this message as sendable by a PostgreSQL frontend.
  9. func (g *GSSResponse) Frontend() {}
  10. func (g *GSSResponse) Decode(data []byte) error {
  11. g.Data = data
  12. return nil
  13. }
  14. func (g *GSSResponse) Encode(dst []byte) ([]byte, error) {
  15. dst, sp := beginMessage(dst, 'p')
  16. dst = append(dst, g.Data...)
  17. return finishMessage(dst, sp)
  18. }
  19. // MarshalJSON implements encoding/json.Marshaler.
  20. func (g *GSSResponse) MarshalJSON() ([]byte, error) {
  21. return json.Marshal(struct {
  22. Type string
  23. Data []byte
  24. }{
  25. Type: "GSSResponse",
  26. Data: g.Data,
  27. })
  28. }
  29. // UnmarshalJSON implements encoding/json.Unmarshaler.
  30. func (g *GSSResponse) UnmarshalJSON(data []byte) error {
  31. var msg struct {
  32. Data []byte
  33. }
  34. if err := json.Unmarshal(data, &msg); err != nil {
  35. return err
  36. }
  37. g.Data = msg.Data
  38. return nil
  39. }