gtsocial-umbx

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

gss_response.go (936B)


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