...

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

Documentation: github.com/jackc/pgproto3/v2

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

View as plain text