...

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

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

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

View as plain text