...

Source file src/github.com/jackc/pgproto3/v2/gss_response.go

Documentation: github.com/jackc/pgproto3/v2

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

View as plain text