gtsocial-umbx

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

gss_response.go (953B)


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