...

Source file src/github.com/jackc/pgx/v5/pgproto3/password_message.go

Documentation: github.com/jackc/pgx/v5/pgproto3

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

View as plain text