...

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

Documentation: github.com/jackc/pgproto3/v2

     1  package pgproto3
     2  
     3  import (
     4  	"bytes"
     5  	"encoding/binary"
     6  	"encoding/json"
     7  
     8  	"github.com/jackc/pgio"
     9  )
    10  
    11  type Execute struct {
    12  	Portal  string
    13  	MaxRows uint32
    14  }
    15  
    16  // Frontend identifies this message as sendable by a PostgreSQL frontend.
    17  func (*Execute) Frontend() {}
    18  
    19  // Decode decodes src into dst. src must contain the complete message with the exception of the initial 1 byte message
    20  // type identifier and 4 byte message length.
    21  func (dst *Execute) Decode(src []byte) error {
    22  	buf := bytes.NewBuffer(src)
    23  
    24  	b, err := buf.ReadBytes(0)
    25  	if err != nil {
    26  		return err
    27  	}
    28  	dst.Portal = string(b[:len(b)-1])
    29  
    30  	if buf.Len() < 4 {
    31  		return &invalidMessageFormatErr{messageType: "Execute"}
    32  	}
    33  	dst.MaxRows = binary.BigEndian.Uint32(buf.Next(4))
    34  
    35  	return nil
    36  }
    37  
    38  // Encode encodes src into dst. dst will include the 1 byte message type identifier and the 4 byte message length.
    39  func (src *Execute) Encode(dst []byte) ([]byte, error) {
    40  	dst, sp := beginMessage(dst, 'E')
    41  	dst = append(dst, src.Portal...)
    42  	dst = append(dst, 0)
    43  	dst = pgio.AppendUint32(dst, src.MaxRows)
    44  	return finishMessage(dst, sp)
    45  }
    46  
    47  // MarshalJSON implements encoding/json.Marshaler.
    48  func (src Execute) MarshalJSON() ([]byte, error) {
    49  	return json.Marshal(struct {
    50  		Type    string
    51  		Portal  string
    52  		MaxRows uint32
    53  	}{
    54  		Type:    "Execute",
    55  		Portal:  src.Portal,
    56  		MaxRows: src.MaxRows,
    57  	})
    58  }
    59  

View as plain text