增加websocket支持
This commit is contained in:
2
vendor/github.com/jackc/pgx/v5/pgproto3/README.md
generated
vendored
2
vendor/github.com/jackc/pgx/v5/pgproto3/README.md
generated
vendored
@@ -1,6 +1,6 @@
|
||||
# pgproto3
|
||||
|
||||
Package pgproto3 is an encoder and decoder of the PostgreSQL wire protocol version 3.
|
||||
Package pgproto3 is a encoder and decoder of the PostgreSQL wire protocol version 3.
|
||||
|
||||
pgproto3 can be used as a foundation for PostgreSQL drivers, proxies, mock servers, load balancers and more.
|
||||
|
||||
|
||||
7
vendor/github.com/jackc/pgx/v5/pgproto3/authentication_cleartext_password.go
generated
vendored
7
vendor/github.com/jackc/pgx/v5/pgproto3/authentication_cleartext_password.go
generated
vendored
@@ -35,10 +35,11 @@ func (dst *AuthenticationCleartextPassword) Decode(src []byte) error {
|
||||
}
|
||||
|
||||
// Encode encodes src into dst. dst will include the 1 byte message type identifier and the 4 byte message length.
|
||||
func (src *AuthenticationCleartextPassword) Encode(dst []byte) ([]byte, error) {
|
||||
dst, sp := beginMessage(dst, 'R')
|
||||
func (src *AuthenticationCleartextPassword) Encode(dst []byte) []byte {
|
||||
dst = append(dst, 'R')
|
||||
dst = pgio.AppendInt32(dst, 8)
|
||||
dst = pgio.AppendUint32(dst, AuthTypeCleartextPassword)
|
||||
return finishMessage(dst, sp)
|
||||
return dst
|
||||
}
|
||||
|
||||
// MarshalJSON implements encoding/json.Marshaler.
|
||||
|
||||
7
vendor/github.com/jackc/pgx/v5/pgproto3/authentication_gss.go
generated
vendored
7
vendor/github.com/jackc/pgx/v5/pgproto3/authentication_gss.go
generated
vendored
@@ -27,10 +27,11 @@ func (a *AuthenticationGSS) Decode(src []byte) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (a *AuthenticationGSS) Encode(dst []byte) ([]byte, error) {
|
||||
dst, sp := beginMessage(dst, 'R')
|
||||
func (a *AuthenticationGSS) Encode(dst []byte) []byte {
|
||||
dst = append(dst, 'R')
|
||||
dst = pgio.AppendInt32(dst, 4)
|
||||
dst = pgio.AppendUint32(dst, AuthTypeGSS)
|
||||
return finishMessage(dst, sp)
|
||||
return dst
|
||||
}
|
||||
|
||||
func (a *AuthenticationGSS) MarshalJSON() ([]byte, error) {
|
||||
|
||||
7
vendor/github.com/jackc/pgx/v5/pgproto3/authentication_gss_continue.go
generated
vendored
7
vendor/github.com/jackc/pgx/v5/pgproto3/authentication_gss_continue.go
generated
vendored
@@ -31,11 +31,12 @@ func (a *AuthenticationGSSContinue) Decode(src []byte) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (a *AuthenticationGSSContinue) Encode(dst []byte) ([]byte, error) {
|
||||
dst, sp := beginMessage(dst, 'R')
|
||||
func (a *AuthenticationGSSContinue) Encode(dst []byte) []byte {
|
||||
dst = append(dst, 'R')
|
||||
dst = pgio.AppendInt32(dst, int32(len(a.Data))+8)
|
||||
dst = pgio.AppendUint32(dst, AuthTypeGSSCont)
|
||||
dst = append(dst, a.Data...)
|
||||
return finishMessage(dst, sp)
|
||||
return dst
|
||||
}
|
||||
|
||||
func (a *AuthenticationGSSContinue) MarshalJSON() ([]byte, error) {
|
||||
|
||||
7
vendor/github.com/jackc/pgx/v5/pgproto3/authentication_md5_password.go
generated
vendored
7
vendor/github.com/jackc/pgx/v5/pgproto3/authentication_md5_password.go
generated
vendored
@@ -38,11 +38,12 @@ func (dst *AuthenticationMD5Password) Decode(src []byte) error {
|
||||
}
|
||||
|
||||
// Encode encodes src into dst. dst will include the 1 byte message type identifier and the 4 byte message length.
|
||||
func (src *AuthenticationMD5Password) Encode(dst []byte) ([]byte, error) {
|
||||
dst, sp := beginMessage(dst, 'R')
|
||||
func (src *AuthenticationMD5Password) Encode(dst []byte) []byte {
|
||||
dst = append(dst, 'R')
|
||||
dst = pgio.AppendInt32(dst, 12)
|
||||
dst = pgio.AppendUint32(dst, AuthTypeMD5Password)
|
||||
dst = append(dst, src.Salt[:]...)
|
||||
return finishMessage(dst, sp)
|
||||
return dst
|
||||
}
|
||||
|
||||
// MarshalJSON implements encoding/json.Marshaler.
|
||||
|
||||
7
vendor/github.com/jackc/pgx/v5/pgproto3/authentication_ok.go
generated
vendored
7
vendor/github.com/jackc/pgx/v5/pgproto3/authentication_ok.go
generated
vendored
@@ -35,10 +35,11 @@ func (dst *AuthenticationOk) Decode(src []byte) error {
|
||||
}
|
||||
|
||||
// Encode encodes src into dst. dst will include the 1 byte message type identifier and the 4 byte message length.
|
||||
func (src *AuthenticationOk) Encode(dst []byte) ([]byte, error) {
|
||||
dst, sp := beginMessage(dst, 'R')
|
||||
func (src *AuthenticationOk) Encode(dst []byte) []byte {
|
||||
dst = append(dst, 'R')
|
||||
dst = pgio.AppendInt32(dst, 8)
|
||||
dst = pgio.AppendUint32(dst, AuthTypeOk)
|
||||
return finishMessage(dst, sp)
|
||||
return dst
|
||||
}
|
||||
|
||||
// MarshalJSON implements encoding/json.Marshaler.
|
||||
|
||||
10
vendor/github.com/jackc/pgx/v5/pgproto3/authentication_sasl.go
generated
vendored
10
vendor/github.com/jackc/pgx/v5/pgproto3/authentication_sasl.go
generated
vendored
@@ -47,8 +47,10 @@ func (dst *AuthenticationSASL) Decode(src []byte) error {
|
||||
}
|
||||
|
||||
// Encode encodes src into dst. dst will include the 1 byte message type identifier and the 4 byte message length.
|
||||
func (src *AuthenticationSASL) Encode(dst []byte) ([]byte, error) {
|
||||
dst, sp := beginMessage(dst, 'R')
|
||||
func (src *AuthenticationSASL) Encode(dst []byte) []byte {
|
||||
dst = append(dst, 'R')
|
||||
sp := len(dst)
|
||||
dst = pgio.AppendInt32(dst, -1)
|
||||
dst = pgio.AppendUint32(dst, AuthTypeSASL)
|
||||
|
||||
for _, s := range src.AuthMechanisms {
|
||||
@@ -57,7 +59,9 @@ func (src *AuthenticationSASL) Encode(dst []byte) ([]byte, error) {
|
||||
}
|
||||
dst = append(dst, 0)
|
||||
|
||||
return finishMessage(dst, sp)
|
||||
pgio.SetInt32(dst[sp:], int32(len(dst[sp:])))
|
||||
|
||||
return dst
|
||||
}
|
||||
|
||||
// MarshalJSON implements encoding/json.Marshaler.
|
||||
|
||||
12
vendor/github.com/jackc/pgx/v5/pgproto3/authentication_sasl_continue.go
generated
vendored
12
vendor/github.com/jackc/pgx/v5/pgproto3/authentication_sasl_continue.go
generated
vendored
@@ -38,11 +38,17 @@ func (dst *AuthenticationSASLContinue) Decode(src []byte) error {
|
||||
}
|
||||
|
||||
// Encode encodes src into dst. dst will include the 1 byte message type identifier and the 4 byte message length.
|
||||
func (src *AuthenticationSASLContinue) Encode(dst []byte) ([]byte, error) {
|
||||
dst, sp := beginMessage(dst, 'R')
|
||||
func (src *AuthenticationSASLContinue) Encode(dst []byte) []byte {
|
||||
dst = append(dst, 'R')
|
||||
sp := len(dst)
|
||||
dst = pgio.AppendInt32(dst, -1)
|
||||
dst = pgio.AppendUint32(dst, AuthTypeSASLContinue)
|
||||
|
||||
dst = append(dst, src.Data...)
|
||||
return finishMessage(dst, sp)
|
||||
|
||||
pgio.SetInt32(dst[sp:], int32(len(dst[sp:])))
|
||||
|
||||
return dst
|
||||
}
|
||||
|
||||
// MarshalJSON implements encoding/json.Marshaler.
|
||||
|
||||
12
vendor/github.com/jackc/pgx/v5/pgproto3/authentication_sasl_final.go
generated
vendored
12
vendor/github.com/jackc/pgx/v5/pgproto3/authentication_sasl_final.go
generated
vendored
@@ -38,11 +38,17 @@ func (dst *AuthenticationSASLFinal) Decode(src []byte) error {
|
||||
}
|
||||
|
||||
// Encode encodes src into dst. dst will include the 1 byte message type identifier and the 4 byte message length.
|
||||
func (src *AuthenticationSASLFinal) Encode(dst []byte) ([]byte, error) {
|
||||
dst, sp := beginMessage(dst, 'R')
|
||||
func (src *AuthenticationSASLFinal) Encode(dst []byte) []byte {
|
||||
dst = append(dst, 'R')
|
||||
sp := len(dst)
|
||||
dst = pgio.AppendInt32(dst, -1)
|
||||
dst = pgio.AppendUint32(dst, AuthTypeSASLFinal)
|
||||
|
||||
dst = append(dst, src.Data...)
|
||||
return finishMessage(dst, sp)
|
||||
|
||||
pgio.SetInt32(dst[sp:], int32(len(dst[sp:])))
|
||||
|
||||
return dst
|
||||
}
|
||||
|
||||
// MarshalJSON implements encoding/json.Unmarshaler.
|
||||
|
||||
38
vendor/github.com/jackc/pgx/v5/pgproto3/backend.go
generated
vendored
38
vendor/github.com/jackc/pgx/v5/pgproto3/backend.go
generated
vendored
@@ -16,8 +16,7 @@ type Backend struct {
|
||||
// before it is actually transmitted (i.e. before Flush).
|
||||
tracer *tracer
|
||||
|
||||
wbuf []byte
|
||||
encodeError error
|
||||
wbuf []byte
|
||||
|
||||
// Frontend message flyweights
|
||||
bind Bind
|
||||
@@ -39,7 +38,6 @@ type Backend struct {
|
||||
terminate Terminate
|
||||
|
||||
bodyLen int
|
||||
maxBodyLen int // maxBodyLen is the maximum length of a message body in octets. If a message body exceeds this length, Receive will return an error.
|
||||
msgType byte
|
||||
partialMsg bool
|
||||
authType uint32
|
||||
@@ -56,21 +54,11 @@ func NewBackend(r io.Reader, w io.Writer) *Backend {
|
||||
return &Backend{cr: cr, w: w}
|
||||
}
|
||||
|
||||
// Send sends a message to the frontend (i.e. the client). The message is buffered until Flush is called. Any error
|
||||
// encountered will be returned from Flush.
|
||||
// Send sends a message to the frontend (i.e. the client). The message is not guaranteed to be written until Flush is
|
||||
// called.
|
||||
func (b *Backend) Send(msg BackendMessage) {
|
||||
if b.encodeError != nil {
|
||||
return
|
||||
}
|
||||
|
||||
prevLen := len(b.wbuf)
|
||||
newBuf, err := msg.Encode(b.wbuf)
|
||||
if err != nil {
|
||||
b.encodeError = err
|
||||
return
|
||||
}
|
||||
b.wbuf = newBuf
|
||||
|
||||
b.wbuf = msg.Encode(b.wbuf)
|
||||
if b.tracer != nil {
|
||||
b.tracer.traceMessage('B', int32(len(b.wbuf)-prevLen), msg)
|
||||
}
|
||||
@@ -78,12 +66,6 @@ func (b *Backend) Send(msg BackendMessage) {
|
||||
|
||||
// Flush writes any pending messages to the frontend (i.e. the client).
|
||||
func (b *Backend) Flush() error {
|
||||
if err := b.encodeError; err != nil {
|
||||
b.encodeError = nil
|
||||
b.wbuf = b.wbuf[:0]
|
||||
return &writeError{err: err, safeToRetry: true}
|
||||
}
|
||||
|
||||
n, err := b.w.Write(b.wbuf)
|
||||
|
||||
const maxLen = 1024
|
||||
@@ -176,9 +158,6 @@ func (b *Backend) Receive() (FrontendMessage, error) {
|
||||
|
||||
b.msgType = header[0]
|
||||
b.bodyLen = int(binary.BigEndian.Uint32(header[1:])) - 4
|
||||
if b.maxBodyLen > 0 && b.bodyLen > b.maxBodyLen {
|
||||
return nil, &ExceededMaxBodyLenErr{b.maxBodyLen, b.bodyLen}
|
||||
}
|
||||
b.partialMsg = true
|
||||
}
|
||||
|
||||
@@ -281,12 +260,3 @@ func (b *Backend) SetAuthType(authType uint32) error {
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// SetMaxBodyLen sets the maximum length of a message body in octets. If a message body exceeds this length, Receive will return
|
||||
// an error. This is useful for protecting against malicious clients that send large messages with the intent of
|
||||
// causing memory exhaustion.
|
||||
// The default value is 0.
|
||||
// If maxBodyLen is 0, then no maximum is enforced.
|
||||
func (b *Backend) SetMaxBodyLen(maxBodyLen int) {
|
||||
b.maxBodyLen = maxBodyLen
|
||||
}
|
||||
|
||||
7
vendor/github.com/jackc/pgx/v5/pgproto3/backend_key_data.go
generated
vendored
7
vendor/github.com/jackc/pgx/v5/pgproto3/backend_key_data.go
generated
vendored
@@ -29,11 +29,12 @@ func (dst *BackendKeyData) Decode(src []byte) error {
|
||||
}
|
||||
|
||||
// Encode encodes src into dst. dst will include the 1 byte message type identifier and the 4 byte message length.
|
||||
func (src *BackendKeyData) Encode(dst []byte) ([]byte, error) {
|
||||
dst, sp := beginMessage(dst, 'K')
|
||||
func (src *BackendKeyData) Encode(dst []byte) []byte {
|
||||
dst = append(dst, 'K')
|
||||
dst = pgio.AppendUint32(dst, 12)
|
||||
dst = pgio.AppendUint32(dst, src.ProcessID)
|
||||
dst = pgio.AppendUint32(dst, src.SecretKey)
|
||||
return finishMessage(dst, sp)
|
||||
return dst
|
||||
}
|
||||
|
||||
// MarshalJSON implements encoding/json.Marshaler.
|
||||
|
||||
21
vendor/github.com/jackc/pgx/v5/pgproto3/bind.go
generated
vendored
21
vendor/github.com/jackc/pgx/v5/pgproto3/bind.go
generated
vendored
@@ -5,9 +5,7 @@ import (
|
||||
"encoding/binary"
|
||||
"encoding/hex"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"math"
|
||||
|
||||
"github.com/jackc/pgx/v5/internal/pgio"
|
||||
)
|
||||
@@ -110,25 +108,21 @@ func (dst *Bind) Decode(src []byte) error {
|
||||
}
|
||||
|
||||
// Encode encodes src into dst. dst will include the 1 byte message type identifier and the 4 byte message length.
|
||||
func (src *Bind) Encode(dst []byte) ([]byte, error) {
|
||||
dst, sp := beginMessage(dst, 'B')
|
||||
func (src *Bind) Encode(dst []byte) []byte {
|
||||
dst = append(dst, 'B')
|
||||
sp := len(dst)
|
||||
dst = pgio.AppendInt32(dst, -1)
|
||||
|
||||
dst = append(dst, src.DestinationPortal...)
|
||||
dst = append(dst, 0)
|
||||
dst = append(dst, src.PreparedStatement...)
|
||||
dst = append(dst, 0)
|
||||
|
||||
if len(src.ParameterFormatCodes) > math.MaxUint16 {
|
||||
return nil, errors.New("too many parameter format codes")
|
||||
}
|
||||
dst = pgio.AppendUint16(dst, uint16(len(src.ParameterFormatCodes)))
|
||||
for _, fc := range src.ParameterFormatCodes {
|
||||
dst = pgio.AppendInt16(dst, fc)
|
||||
}
|
||||
|
||||
if len(src.Parameters) > math.MaxUint16 {
|
||||
return nil, errors.New("too many parameters")
|
||||
}
|
||||
dst = pgio.AppendUint16(dst, uint16(len(src.Parameters)))
|
||||
for _, p := range src.Parameters {
|
||||
if p == nil {
|
||||
@@ -140,15 +134,14 @@ func (src *Bind) Encode(dst []byte) ([]byte, error) {
|
||||
dst = append(dst, p...)
|
||||
}
|
||||
|
||||
if len(src.ResultFormatCodes) > math.MaxUint16 {
|
||||
return nil, errors.New("too many result format codes")
|
||||
}
|
||||
dst = pgio.AppendUint16(dst, uint16(len(src.ResultFormatCodes)))
|
||||
for _, fc := range src.ResultFormatCodes {
|
||||
dst = pgio.AppendInt16(dst, fc)
|
||||
}
|
||||
|
||||
return finishMessage(dst, sp)
|
||||
pgio.SetInt32(dst[sp:], int32(len(dst[sp:])))
|
||||
|
||||
return dst
|
||||
}
|
||||
|
||||
// MarshalJSON implements encoding/json.Marshaler.
|
||||
|
||||
4
vendor/github.com/jackc/pgx/v5/pgproto3/bind_complete.go
generated
vendored
4
vendor/github.com/jackc/pgx/v5/pgproto3/bind_complete.go
generated
vendored
@@ -20,8 +20,8 @@ func (dst *BindComplete) Decode(src []byte) error {
|
||||
}
|
||||
|
||||
// Encode encodes src into dst. dst will include the 1 byte message type identifier and the 4 byte message length.
|
||||
func (src *BindComplete) Encode(dst []byte) ([]byte, error) {
|
||||
return append(dst, '2', 0, 0, 0, 4), nil
|
||||
func (src *BindComplete) Encode(dst []byte) []byte {
|
||||
return append(dst, '2', 0, 0, 0, 4)
|
||||
}
|
||||
|
||||
// MarshalJSON implements encoding/json.Marshaler.
|
||||
|
||||
4
vendor/github.com/jackc/pgx/v5/pgproto3/cancel_request.go
generated
vendored
4
vendor/github.com/jackc/pgx/v5/pgproto3/cancel_request.go
generated
vendored
@@ -36,12 +36,12 @@ func (dst *CancelRequest) Decode(src []byte) error {
|
||||
}
|
||||
|
||||
// Encode encodes src into dst. dst will include the 4 byte message length.
|
||||
func (src *CancelRequest) Encode(dst []byte) ([]byte, error) {
|
||||
func (src *CancelRequest) Encode(dst []byte) []byte {
|
||||
dst = pgio.AppendInt32(dst, 16)
|
||||
dst = pgio.AppendInt32(dst, cancelRequestCode)
|
||||
dst = pgio.AppendUint32(dst, src.ProcessID)
|
||||
dst = pgio.AppendUint32(dst, src.SecretKey)
|
||||
return dst, nil
|
||||
return dst
|
||||
}
|
||||
|
||||
// MarshalJSON implements encoding/json.Marshaler.
|
||||
|
||||
14
vendor/github.com/jackc/pgx/v5/pgproto3/close.go
generated
vendored
14
vendor/github.com/jackc/pgx/v5/pgproto3/close.go
generated
vendored
@@ -4,6 +4,8 @@ import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
|
||||
"github.com/jackc/pgx/v5/internal/pgio"
|
||||
)
|
||||
|
||||
type Close struct {
|
||||
@@ -35,12 +37,18 @@ func (dst *Close) Decode(src []byte) error {
|
||||
}
|
||||
|
||||
// Encode encodes src into dst. dst will include the 1 byte message type identifier and the 4 byte message length.
|
||||
func (src *Close) Encode(dst []byte) ([]byte, error) {
|
||||
dst, sp := beginMessage(dst, 'C')
|
||||
func (src *Close) Encode(dst []byte) []byte {
|
||||
dst = append(dst, 'C')
|
||||
sp := len(dst)
|
||||
dst = pgio.AppendInt32(dst, -1)
|
||||
|
||||
dst = append(dst, src.ObjectType)
|
||||
dst = append(dst, src.Name...)
|
||||
dst = append(dst, 0)
|
||||
return finishMessage(dst, sp)
|
||||
|
||||
pgio.SetInt32(dst[sp:], int32(len(dst[sp:])))
|
||||
|
||||
return dst
|
||||
}
|
||||
|
||||
// MarshalJSON implements encoding/json.Marshaler.
|
||||
|
||||
4
vendor/github.com/jackc/pgx/v5/pgproto3/close_complete.go
generated
vendored
4
vendor/github.com/jackc/pgx/v5/pgproto3/close_complete.go
generated
vendored
@@ -20,8 +20,8 @@ func (dst *CloseComplete) Decode(src []byte) error {
|
||||
}
|
||||
|
||||
// Encode encodes src into dst. dst will include the 1 byte message type identifier and the 4 byte message length.
|
||||
func (src *CloseComplete) Encode(dst []byte) ([]byte, error) {
|
||||
return append(dst, '3', 0, 0, 0, 4), nil
|
||||
func (src *CloseComplete) Encode(dst []byte) []byte {
|
||||
return append(dst, '3', 0, 0, 0, 4)
|
||||
}
|
||||
|
||||
// MarshalJSON implements encoding/json.Marshaler.
|
||||
|
||||
14
vendor/github.com/jackc/pgx/v5/pgproto3/command_complete.go
generated
vendored
14
vendor/github.com/jackc/pgx/v5/pgproto3/command_complete.go
generated
vendored
@@ -3,6 +3,8 @@ package pgproto3
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
|
||||
"github.com/jackc/pgx/v5/internal/pgio"
|
||||
)
|
||||
|
||||
type CommandComplete struct {
|
||||
@@ -29,11 +31,17 @@ func (dst *CommandComplete) Decode(src []byte) error {
|
||||
}
|
||||
|
||||
// Encode encodes src into dst. dst will include the 1 byte message type identifier and the 4 byte message length.
|
||||
func (src *CommandComplete) Encode(dst []byte) ([]byte, error) {
|
||||
dst, sp := beginMessage(dst, 'C')
|
||||
func (src *CommandComplete) Encode(dst []byte) []byte {
|
||||
dst = append(dst, 'C')
|
||||
sp := len(dst)
|
||||
dst = pgio.AppendInt32(dst, -1)
|
||||
|
||||
dst = append(dst, src.CommandTag...)
|
||||
dst = append(dst, 0)
|
||||
return finishMessage(dst, sp)
|
||||
|
||||
pgio.SetInt32(dst[sp:], int32(len(dst[sp:])))
|
||||
|
||||
return dst
|
||||
}
|
||||
|
||||
// MarshalJSON implements encoding/json.Marshaler.
|
||||
|
||||
14
vendor/github.com/jackc/pgx/v5/pgproto3/copy_both_response.go
generated
vendored
14
vendor/github.com/jackc/pgx/v5/pgproto3/copy_both_response.go
generated
vendored
@@ -5,7 +5,6 @@ import (
|
||||
"encoding/binary"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"math"
|
||||
|
||||
"github.com/jackc/pgx/v5/internal/pgio"
|
||||
)
|
||||
@@ -45,18 +44,19 @@ func (dst *CopyBothResponse) Decode(src []byte) error {
|
||||
}
|
||||
|
||||
// Encode encodes src into dst. dst will include the 1 byte message type identifier and the 4 byte message length.
|
||||
func (src *CopyBothResponse) Encode(dst []byte) ([]byte, error) {
|
||||
dst, sp := beginMessage(dst, 'W')
|
||||
func (src *CopyBothResponse) Encode(dst []byte) []byte {
|
||||
dst = append(dst, 'W')
|
||||
sp := len(dst)
|
||||
dst = pgio.AppendInt32(dst, -1)
|
||||
dst = append(dst, src.OverallFormat)
|
||||
if len(src.ColumnFormatCodes) > math.MaxUint16 {
|
||||
return nil, errors.New("too many column format codes")
|
||||
}
|
||||
dst = pgio.AppendUint16(dst, uint16(len(src.ColumnFormatCodes)))
|
||||
for _, fc := range src.ColumnFormatCodes {
|
||||
dst = pgio.AppendUint16(dst, fc)
|
||||
}
|
||||
|
||||
return finishMessage(dst, sp)
|
||||
pgio.SetInt32(dst[sp:], int32(len(dst[sp:])))
|
||||
|
||||
return dst
|
||||
}
|
||||
|
||||
// MarshalJSON implements encoding/json.Marshaler.
|
||||
|
||||
9
vendor/github.com/jackc/pgx/v5/pgproto3/copy_data.go
generated
vendored
9
vendor/github.com/jackc/pgx/v5/pgproto3/copy_data.go
generated
vendored
@@ -3,6 +3,8 @@ package pgproto3
|
||||
import (
|
||||
"encoding/hex"
|
||||
"encoding/json"
|
||||
|
||||
"github.com/jackc/pgx/v5/internal/pgio"
|
||||
)
|
||||
|
||||
type CopyData struct {
|
||||
@@ -23,10 +25,11 @@ func (dst *CopyData) Decode(src []byte) error {
|
||||
}
|
||||
|
||||
// Encode encodes src into dst. dst will include the 1 byte message type identifier and the 4 byte message length.
|
||||
func (src *CopyData) Encode(dst []byte) ([]byte, error) {
|
||||
dst, sp := beginMessage(dst, 'd')
|
||||
func (src *CopyData) Encode(dst []byte) []byte {
|
||||
dst = append(dst, 'd')
|
||||
dst = pgio.AppendInt32(dst, int32(4+len(src.Data)))
|
||||
dst = append(dst, src.Data...)
|
||||
return finishMessage(dst, sp)
|
||||
return dst
|
||||
}
|
||||
|
||||
// MarshalJSON implements encoding/json.Marshaler.
|
||||
|
||||
4
vendor/github.com/jackc/pgx/v5/pgproto3/copy_done.go
generated
vendored
4
vendor/github.com/jackc/pgx/v5/pgproto3/copy_done.go
generated
vendored
@@ -24,8 +24,8 @@ func (dst *CopyDone) Decode(src []byte) error {
|
||||
}
|
||||
|
||||
// Encode encodes src into dst. dst will include the 1 byte message type identifier and the 4 byte message length.
|
||||
func (src *CopyDone) Encode(dst []byte) ([]byte, error) {
|
||||
return append(dst, 'c', 0, 0, 0, 4), nil
|
||||
func (src *CopyDone) Encode(dst []byte) []byte {
|
||||
return append(dst, 'c', 0, 0, 0, 4)
|
||||
}
|
||||
|
||||
// MarshalJSON implements encoding/json.Marshaler.
|
||||
|
||||
14
vendor/github.com/jackc/pgx/v5/pgproto3/copy_fail.go
generated
vendored
14
vendor/github.com/jackc/pgx/v5/pgproto3/copy_fail.go
generated
vendored
@@ -3,6 +3,8 @@ package pgproto3
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
|
||||
"github.com/jackc/pgx/v5/internal/pgio"
|
||||
)
|
||||
|
||||
type CopyFail struct {
|
||||
@@ -26,11 +28,17 @@ func (dst *CopyFail) Decode(src []byte) error {
|
||||
}
|
||||
|
||||
// Encode encodes src into dst. dst will include the 1 byte message type identifier and the 4 byte message length.
|
||||
func (src *CopyFail) Encode(dst []byte) ([]byte, error) {
|
||||
dst, sp := beginMessage(dst, 'f')
|
||||
func (src *CopyFail) Encode(dst []byte) []byte {
|
||||
dst = append(dst, 'f')
|
||||
sp := len(dst)
|
||||
dst = pgio.AppendInt32(dst, -1)
|
||||
|
||||
dst = append(dst, src.Message...)
|
||||
dst = append(dst, 0)
|
||||
return finishMessage(dst, sp)
|
||||
|
||||
pgio.SetInt32(dst[sp:], int32(len(dst[sp:])))
|
||||
|
||||
return dst
|
||||
}
|
||||
|
||||
// MarshalJSON implements encoding/json.Marshaler.
|
||||
|
||||
14
vendor/github.com/jackc/pgx/v5/pgproto3/copy_in_response.go
generated
vendored
14
vendor/github.com/jackc/pgx/v5/pgproto3/copy_in_response.go
generated
vendored
@@ -5,7 +5,6 @@ import (
|
||||
"encoding/binary"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"math"
|
||||
|
||||
"github.com/jackc/pgx/v5/internal/pgio"
|
||||
)
|
||||
@@ -45,19 +44,20 @@ func (dst *CopyInResponse) Decode(src []byte) error {
|
||||
}
|
||||
|
||||
// Encode encodes src into dst. dst will include the 1 byte message type identifier and the 4 byte message length.
|
||||
func (src *CopyInResponse) Encode(dst []byte) ([]byte, error) {
|
||||
dst, sp := beginMessage(dst, 'G')
|
||||
func (src *CopyInResponse) Encode(dst []byte) []byte {
|
||||
dst = append(dst, 'G')
|
||||
sp := len(dst)
|
||||
dst = pgio.AppendInt32(dst, -1)
|
||||
|
||||
dst = append(dst, src.OverallFormat)
|
||||
if len(src.ColumnFormatCodes) > math.MaxUint16 {
|
||||
return nil, errors.New("too many column format codes")
|
||||
}
|
||||
dst = pgio.AppendUint16(dst, uint16(len(src.ColumnFormatCodes)))
|
||||
for _, fc := range src.ColumnFormatCodes {
|
||||
dst = pgio.AppendUint16(dst, fc)
|
||||
}
|
||||
|
||||
return finishMessage(dst, sp)
|
||||
pgio.SetInt32(dst[sp:], int32(len(dst[sp:])))
|
||||
|
||||
return dst
|
||||
}
|
||||
|
||||
// MarshalJSON implements encoding/json.Marshaler.
|
||||
|
||||
14
vendor/github.com/jackc/pgx/v5/pgproto3/copy_out_response.go
generated
vendored
14
vendor/github.com/jackc/pgx/v5/pgproto3/copy_out_response.go
generated
vendored
@@ -5,7 +5,6 @@ import (
|
||||
"encoding/binary"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"math"
|
||||
|
||||
"github.com/jackc/pgx/v5/internal/pgio"
|
||||
)
|
||||
@@ -44,20 +43,21 @@ func (dst *CopyOutResponse) Decode(src []byte) error {
|
||||
}
|
||||
|
||||
// Encode encodes src into dst. dst will include the 1 byte message type identifier and the 4 byte message length.
|
||||
func (src *CopyOutResponse) Encode(dst []byte) ([]byte, error) {
|
||||
dst, sp := beginMessage(dst, 'H')
|
||||
func (src *CopyOutResponse) Encode(dst []byte) []byte {
|
||||
dst = append(dst, 'H')
|
||||
sp := len(dst)
|
||||
dst = pgio.AppendInt32(dst, -1)
|
||||
|
||||
dst = append(dst, src.OverallFormat)
|
||||
|
||||
if len(src.ColumnFormatCodes) > math.MaxUint16 {
|
||||
return nil, errors.New("too many column format codes")
|
||||
}
|
||||
dst = pgio.AppendUint16(dst, uint16(len(src.ColumnFormatCodes)))
|
||||
for _, fc := range src.ColumnFormatCodes {
|
||||
dst = pgio.AppendUint16(dst, fc)
|
||||
}
|
||||
|
||||
return finishMessage(dst, sp)
|
||||
pgio.SetInt32(dst[sp:], int32(len(dst[sp:])))
|
||||
|
||||
return dst
|
||||
}
|
||||
|
||||
// MarshalJSON implements encoding/json.Marshaler.
|
||||
|
||||
15
vendor/github.com/jackc/pgx/v5/pgproto3/data_row.go
generated
vendored
15
vendor/github.com/jackc/pgx/v5/pgproto3/data_row.go
generated
vendored
@@ -4,8 +4,6 @@ import (
|
||||
"encoding/binary"
|
||||
"encoding/hex"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"math"
|
||||
|
||||
"github.com/jackc/pgx/v5/internal/pgio"
|
||||
)
|
||||
@@ -65,12 +63,11 @@ func (dst *DataRow) Decode(src []byte) error {
|
||||
}
|
||||
|
||||
// Encode encodes src into dst. dst will include the 1 byte message type identifier and the 4 byte message length.
|
||||
func (src *DataRow) Encode(dst []byte) ([]byte, error) {
|
||||
dst, sp := beginMessage(dst, 'D')
|
||||
func (src *DataRow) Encode(dst []byte) []byte {
|
||||
dst = append(dst, 'D')
|
||||
sp := len(dst)
|
||||
dst = pgio.AppendInt32(dst, -1)
|
||||
|
||||
if len(src.Values) > math.MaxUint16 {
|
||||
return nil, errors.New("too many values")
|
||||
}
|
||||
dst = pgio.AppendUint16(dst, uint16(len(src.Values)))
|
||||
for _, v := range src.Values {
|
||||
if v == nil {
|
||||
@@ -82,7 +79,9 @@ func (src *DataRow) Encode(dst []byte) ([]byte, error) {
|
||||
dst = append(dst, v...)
|
||||
}
|
||||
|
||||
return finishMessage(dst, sp)
|
||||
pgio.SetInt32(dst[sp:], int32(len(dst[sp:])))
|
||||
|
||||
return dst
|
||||
}
|
||||
|
||||
// MarshalJSON implements encoding/json.Marshaler.
|
||||
|
||||
14
vendor/github.com/jackc/pgx/v5/pgproto3/describe.go
generated
vendored
14
vendor/github.com/jackc/pgx/v5/pgproto3/describe.go
generated
vendored
@@ -4,6 +4,8 @@ import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
|
||||
"github.com/jackc/pgx/v5/internal/pgio"
|
||||
)
|
||||
|
||||
type Describe struct {
|
||||
@@ -35,12 +37,18 @@ func (dst *Describe) Decode(src []byte) error {
|
||||
}
|
||||
|
||||
// Encode encodes src into dst. dst will include the 1 byte message type identifier and the 4 byte message length.
|
||||
func (src *Describe) Encode(dst []byte) ([]byte, error) {
|
||||
dst, sp := beginMessage(dst, 'D')
|
||||
func (src *Describe) Encode(dst []byte) []byte {
|
||||
dst = append(dst, 'D')
|
||||
sp := len(dst)
|
||||
dst = pgio.AppendInt32(dst, -1)
|
||||
|
||||
dst = append(dst, src.ObjectType)
|
||||
dst = append(dst, src.Name...)
|
||||
dst = append(dst, 0)
|
||||
return finishMessage(dst, sp)
|
||||
|
||||
pgio.SetInt32(dst[sp:], int32(len(dst[sp:])))
|
||||
|
||||
return dst
|
||||
}
|
||||
|
||||
// MarshalJSON implements encoding/json.Marshaler.
|
||||
|
||||
4
vendor/github.com/jackc/pgx/v5/pgproto3/doc.go
generated
vendored
4
vendor/github.com/jackc/pgx/v5/pgproto3/doc.go
generated
vendored
@@ -1,7 +1,7 @@
|
||||
// Package pgproto3 is an encoder and decoder of the PostgreSQL wire protocol version 3.
|
||||
// Package pgproto3 is a encoder and decoder of the PostgreSQL wire protocol version 3.
|
||||
//
|
||||
// The primary interfaces are Frontend and Backend. They correspond to a client and server respectively. Messages are
|
||||
// sent with Send (or a specialized Send variant). Messages are automatically buffered to minimize small writes. Call
|
||||
// sent with Send (or a specialized Send variant). Messages are automatically bufferred to minimize small writes. Call
|
||||
// Flush to ensure a message has actually been sent.
|
||||
//
|
||||
// The Trace method of Frontend and Backend can be used to examine the wire-level message traffic. It outputs in a
|
||||
|
||||
4
vendor/github.com/jackc/pgx/v5/pgproto3/empty_query_response.go
generated
vendored
4
vendor/github.com/jackc/pgx/v5/pgproto3/empty_query_response.go
generated
vendored
@@ -20,8 +20,8 @@ func (dst *EmptyQueryResponse) Decode(src []byte) error {
|
||||
}
|
||||
|
||||
// Encode encodes src into dst. dst will include the 1 byte message type identifier and the 4 byte message length.
|
||||
func (src *EmptyQueryResponse) Encode(dst []byte) ([]byte, error) {
|
||||
return append(dst, 'I', 0, 0, 0, 4), nil
|
||||
func (src *EmptyQueryResponse) Encode(dst []byte) []byte {
|
||||
return append(dst, 'I', 0, 0, 0, 4)
|
||||
}
|
||||
|
||||
// MarshalJSON implements encoding/json.Marshaler.
|
||||
|
||||
135
vendor/github.com/jackc/pgx/v5/pgproto3/error_response.go
generated
vendored
135
vendor/github.com/jackc/pgx/v5/pgproto3/error_response.go
generated
vendored
@@ -2,6 +2,7 @@ package pgproto3
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/binary"
|
||||
"encoding/json"
|
||||
"strconv"
|
||||
)
|
||||
@@ -110,113 +111,119 @@ func (dst *ErrorResponse) Decode(src []byte) error {
|
||||
}
|
||||
|
||||
// Encode encodes src into dst. dst will include the 1 byte message type identifier and the 4 byte message length.
|
||||
func (src *ErrorResponse) Encode(dst []byte) ([]byte, error) {
|
||||
dst, sp := beginMessage(dst, 'E')
|
||||
dst = src.appendFields(dst)
|
||||
return finishMessage(dst, sp)
|
||||
func (src *ErrorResponse) Encode(dst []byte) []byte {
|
||||
return append(dst, src.marshalBinary('E')...)
|
||||
}
|
||||
|
||||
func (src *ErrorResponse) appendFields(dst []byte) []byte {
|
||||
func (src *ErrorResponse) marshalBinary(typeByte byte) []byte {
|
||||
var bigEndian BigEndianBuf
|
||||
buf := &bytes.Buffer{}
|
||||
|
||||
buf.WriteByte(typeByte)
|
||||
buf.Write(bigEndian.Uint32(0))
|
||||
|
||||
if src.Severity != "" {
|
||||
dst = append(dst, 'S')
|
||||
dst = append(dst, src.Severity...)
|
||||
dst = append(dst, 0)
|
||||
buf.WriteByte('S')
|
||||
buf.WriteString(src.Severity)
|
||||
buf.WriteByte(0)
|
||||
}
|
||||
if src.SeverityUnlocalized != "" {
|
||||
dst = append(dst, 'V')
|
||||
dst = append(dst, src.SeverityUnlocalized...)
|
||||
dst = append(dst, 0)
|
||||
buf.WriteByte('V')
|
||||
buf.WriteString(src.SeverityUnlocalized)
|
||||
buf.WriteByte(0)
|
||||
}
|
||||
if src.Code != "" {
|
||||
dst = append(dst, 'C')
|
||||
dst = append(dst, src.Code...)
|
||||
dst = append(dst, 0)
|
||||
buf.WriteByte('C')
|
||||
buf.WriteString(src.Code)
|
||||
buf.WriteByte(0)
|
||||
}
|
||||
if src.Message != "" {
|
||||
dst = append(dst, 'M')
|
||||
dst = append(dst, src.Message...)
|
||||
dst = append(dst, 0)
|
||||
buf.WriteByte('M')
|
||||
buf.WriteString(src.Message)
|
||||
buf.WriteByte(0)
|
||||
}
|
||||
if src.Detail != "" {
|
||||
dst = append(dst, 'D')
|
||||
dst = append(dst, src.Detail...)
|
||||
dst = append(dst, 0)
|
||||
buf.WriteByte('D')
|
||||
buf.WriteString(src.Detail)
|
||||
buf.WriteByte(0)
|
||||
}
|
||||
if src.Hint != "" {
|
||||
dst = append(dst, 'H')
|
||||
dst = append(dst, src.Hint...)
|
||||
dst = append(dst, 0)
|
||||
buf.WriteByte('H')
|
||||
buf.WriteString(src.Hint)
|
||||
buf.WriteByte(0)
|
||||
}
|
||||
if src.Position != 0 {
|
||||
dst = append(dst, 'P')
|
||||
dst = append(dst, strconv.Itoa(int(src.Position))...)
|
||||
dst = append(dst, 0)
|
||||
buf.WriteByte('P')
|
||||
buf.WriteString(strconv.Itoa(int(src.Position)))
|
||||
buf.WriteByte(0)
|
||||
}
|
||||
if src.InternalPosition != 0 {
|
||||
dst = append(dst, 'p')
|
||||
dst = append(dst, strconv.Itoa(int(src.InternalPosition))...)
|
||||
dst = append(dst, 0)
|
||||
buf.WriteByte('p')
|
||||
buf.WriteString(strconv.Itoa(int(src.InternalPosition)))
|
||||
buf.WriteByte(0)
|
||||
}
|
||||
if src.InternalQuery != "" {
|
||||
dst = append(dst, 'q')
|
||||
dst = append(dst, src.InternalQuery...)
|
||||
dst = append(dst, 0)
|
||||
buf.WriteByte('q')
|
||||
buf.WriteString(src.InternalQuery)
|
||||
buf.WriteByte(0)
|
||||
}
|
||||
if src.Where != "" {
|
||||
dst = append(dst, 'W')
|
||||
dst = append(dst, src.Where...)
|
||||
dst = append(dst, 0)
|
||||
buf.WriteByte('W')
|
||||
buf.WriteString(src.Where)
|
||||
buf.WriteByte(0)
|
||||
}
|
||||
if src.SchemaName != "" {
|
||||
dst = append(dst, 's')
|
||||
dst = append(dst, src.SchemaName...)
|
||||
dst = append(dst, 0)
|
||||
buf.WriteByte('s')
|
||||
buf.WriteString(src.SchemaName)
|
||||
buf.WriteByte(0)
|
||||
}
|
||||
if src.TableName != "" {
|
||||
dst = append(dst, 't')
|
||||
dst = append(dst, src.TableName...)
|
||||
dst = append(dst, 0)
|
||||
buf.WriteByte('t')
|
||||
buf.WriteString(src.TableName)
|
||||
buf.WriteByte(0)
|
||||
}
|
||||
if src.ColumnName != "" {
|
||||
dst = append(dst, 'c')
|
||||
dst = append(dst, src.ColumnName...)
|
||||
dst = append(dst, 0)
|
||||
buf.WriteByte('c')
|
||||
buf.WriteString(src.ColumnName)
|
||||
buf.WriteByte(0)
|
||||
}
|
||||
if src.DataTypeName != "" {
|
||||
dst = append(dst, 'd')
|
||||
dst = append(dst, src.DataTypeName...)
|
||||
dst = append(dst, 0)
|
||||
buf.WriteByte('d')
|
||||
buf.WriteString(src.DataTypeName)
|
||||
buf.WriteByte(0)
|
||||
}
|
||||
if src.ConstraintName != "" {
|
||||
dst = append(dst, 'n')
|
||||
dst = append(dst, src.ConstraintName...)
|
||||
dst = append(dst, 0)
|
||||
buf.WriteByte('n')
|
||||
buf.WriteString(src.ConstraintName)
|
||||
buf.WriteByte(0)
|
||||
}
|
||||
if src.File != "" {
|
||||
dst = append(dst, 'F')
|
||||
dst = append(dst, src.File...)
|
||||
dst = append(dst, 0)
|
||||
buf.WriteByte('F')
|
||||
buf.WriteString(src.File)
|
||||
buf.WriteByte(0)
|
||||
}
|
||||
if src.Line != 0 {
|
||||
dst = append(dst, 'L')
|
||||
dst = append(dst, strconv.Itoa(int(src.Line))...)
|
||||
dst = append(dst, 0)
|
||||
buf.WriteByte('L')
|
||||
buf.WriteString(strconv.Itoa(int(src.Line)))
|
||||
buf.WriteByte(0)
|
||||
}
|
||||
if src.Routine != "" {
|
||||
dst = append(dst, 'R')
|
||||
dst = append(dst, src.Routine...)
|
||||
dst = append(dst, 0)
|
||||
buf.WriteByte('R')
|
||||
buf.WriteString(src.Routine)
|
||||
buf.WriteByte(0)
|
||||
}
|
||||
|
||||
for k, v := range src.UnknownFields {
|
||||
dst = append(dst, k)
|
||||
dst = append(dst, v...)
|
||||
dst = append(dst, 0)
|
||||
buf.WriteByte(k)
|
||||
buf.WriteString(v)
|
||||
buf.WriteByte(0)
|
||||
}
|
||||
|
||||
dst = append(dst, 0)
|
||||
buf.WriteByte(0)
|
||||
|
||||
return dst
|
||||
binary.BigEndian.PutUint32(buf.Bytes()[1:5], uint32(buf.Len()-1))
|
||||
|
||||
return buf.Bytes()
|
||||
}
|
||||
|
||||
// MarshalJSON implements encoding/json.Marshaler.
|
||||
|
||||
13
vendor/github.com/jackc/pgx/v5/pgproto3/execute.go
generated
vendored
13
vendor/github.com/jackc/pgx/v5/pgproto3/execute.go
generated
vendored
@@ -36,12 +36,19 @@ func (dst *Execute) Decode(src []byte) error {
|
||||
}
|
||||
|
||||
// Encode encodes src into dst. dst will include the 1 byte message type identifier and the 4 byte message length.
|
||||
func (src *Execute) Encode(dst []byte) ([]byte, error) {
|
||||
dst, sp := beginMessage(dst, 'E')
|
||||
func (src *Execute) Encode(dst []byte) []byte {
|
||||
dst = append(dst, 'E')
|
||||
sp := len(dst)
|
||||
dst = pgio.AppendInt32(dst, -1)
|
||||
|
||||
dst = append(dst, src.Portal...)
|
||||
dst = append(dst, 0)
|
||||
|
||||
dst = pgio.AppendUint32(dst, src.MaxRows)
|
||||
return finishMessage(dst, sp)
|
||||
|
||||
pgio.SetInt32(dst[sp:], int32(len(dst[sp:])))
|
||||
|
||||
return dst
|
||||
}
|
||||
|
||||
// MarshalJSON implements encoding/json.Marshaler.
|
||||
|
||||
4
vendor/github.com/jackc/pgx/v5/pgproto3/flush.go
generated
vendored
4
vendor/github.com/jackc/pgx/v5/pgproto3/flush.go
generated
vendored
@@ -20,8 +20,8 @@ func (dst *Flush) Decode(src []byte) error {
|
||||
}
|
||||
|
||||
// Encode encodes src into dst. dst will include the 1 byte message type identifier and the 4 byte message length.
|
||||
func (src *Flush) Encode(dst []byte) ([]byte, error) {
|
||||
return append(dst, 'H', 0, 0, 0, 4), nil
|
||||
func (src *Flush) Encode(dst []byte) []byte {
|
||||
return append(dst, 'H', 0, 0, 0, 4)
|
||||
}
|
||||
|
||||
// MarshalJSON implements encoding/json.Marshaler.
|
||||
|
||||
137
vendor/github.com/jackc/pgx/v5/pgproto3/frontend.go
generated
vendored
137
vendor/github.com/jackc/pgx/v5/pgproto3/frontend.go
generated
vendored
@@ -18,8 +18,7 @@ type Frontend struct {
|
||||
// idle. Setting and unsetting tracer provides equivalent functionality to PQtrace and PQuntrace in libpq.
|
||||
tracer *tracer
|
||||
|
||||
wbuf []byte
|
||||
encodeError error
|
||||
wbuf []byte
|
||||
|
||||
// Backend message flyweights
|
||||
authenticationOk AuthenticationOk
|
||||
@@ -65,26 +64,16 @@ func NewFrontend(r io.Reader, w io.Writer) *Frontend {
|
||||
return &Frontend{cr: cr, w: w}
|
||||
}
|
||||
|
||||
// Send sends a message to the backend (i.e. the server). The message is buffered until Flush is called. Any error
|
||||
// encountered will be returned from Flush.
|
||||
// Send sends a message to the backend (i.e. the server). The message is not guaranteed to be written until Flush is
|
||||
// called.
|
||||
//
|
||||
// Send can work with any FrontendMessage. Some commonly used message types such as Bind have specialized send methods
|
||||
// such as SendBind. These methods should be preferred when the type of message is known up front (e.g. when building an
|
||||
// extended query protocol query) as they may be faster due to knowing the type of msg rather than it being hidden
|
||||
// behind an interface.
|
||||
func (f *Frontend) Send(msg FrontendMessage) {
|
||||
if f.encodeError != nil {
|
||||
return
|
||||
}
|
||||
|
||||
prevLen := len(f.wbuf)
|
||||
newBuf, err := msg.Encode(f.wbuf)
|
||||
if err != nil {
|
||||
f.encodeError = err
|
||||
return
|
||||
}
|
||||
f.wbuf = newBuf
|
||||
|
||||
f.wbuf = msg.Encode(f.wbuf)
|
||||
if f.tracer != nil {
|
||||
f.tracer.traceMessage('F', int32(len(f.wbuf)-prevLen), msg)
|
||||
}
|
||||
@@ -92,12 +81,6 @@ func (f *Frontend) Send(msg FrontendMessage) {
|
||||
|
||||
// Flush writes any pending messages to the backend (i.e. the server).
|
||||
func (f *Frontend) Flush() error {
|
||||
if err := f.encodeError; err != nil {
|
||||
f.encodeError = nil
|
||||
f.wbuf = f.wbuf[:0]
|
||||
return &writeError{err: err, safeToRetry: true}
|
||||
}
|
||||
|
||||
if len(f.wbuf) == 0 {
|
||||
return nil
|
||||
}
|
||||
@@ -133,141 +116,71 @@ func (f *Frontend) Untrace() {
|
||||
f.tracer = nil
|
||||
}
|
||||
|
||||
// SendBind sends a Bind message to the backend (i.e. the server). The message is buffered until Flush is called. Any
|
||||
// error encountered will be returned from Flush.
|
||||
// SendBind sends a Bind message to the backend (i.e. the server). The message is not guaranteed to be written until
|
||||
// Flush is called.
|
||||
func (f *Frontend) SendBind(msg *Bind) {
|
||||
if f.encodeError != nil {
|
||||
return
|
||||
}
|
||||
|
||||
prevLen := len(f.wbuf)
|
||||
newBuf, err := msg.Encode(f.wbuf)
|
||||
if err != nil {
|
||||
f.encodeError = err
|
||||
return
|
||||
}
|
||||
f.wbuf = newBuf
|
||||
|
||||
f.wbuf = msg.Encode(f.wbuf)
|
||||
if f.tracer != nil {
|
||||
f.tracer.traceBind('F', int32(len(f.wbuf)-prevLen), msg)
|
||||
}
|
||||
}
|
||||
|
||||
// SendParse sends a Parse message to the backend (i.e. the server). The message is buffered until Flush is called. Any
|
||||
// error encountered will be returned from Flush.
|
||||
// SendParse sends a Parse message to the backend (i.e. the server). The message is not guaranteed to be written until
|
||||
// Flush is called.
|
||||
func (f *Frontend) SendParse(msg *Parse) {
|
||||
if f.encodeError != nil {
|
||||
return
|
||||
}
|
||||
|
||||
prevLen := len(f.wbuf)
|
||||
newBuf, err := msg.Encode(f.wbuf)
|
||||
if err != nil {
|
||||
f.encodeError = err
|
||||
return
|
||||
}
|
||||
f.wbuf = newBuf
|
||||
|
||||
f.wbuf = msg.Encode(f.wbuf)
|
||||
if f.tracer != nil {
|
||||
f.tracer.traceParse('F', int32(len(f.wbuf)-prevLen), msg)
|
||||
}
|
||||
}
|
||||
|
||||
// SendClose sends a Close message to the backend (i.e. the server). The message is buffered until Flush is called. Any
|
||||
// error encountered will be returned from Flush.
|
||||
// SendClose sends a Close message to the backend (i.e. the server). The message is not guaranteed to be written until
|
||||
// Flush is called.
|
||||
func (f *Frontend) SendClose(msg *Close) {
|
||||
if f.encodeError != nil {
|
||||
return
|
||||
}
|
||||
|
||||
prevLen := len(f.wbuf)
|
||||
newBuf, err := msg.Encode(f.wbuf)
|
||||
if err != nil {
|
||||
f.encodeError = err
|
||||
return
|
||||
}
|
||||
f.wbuf = newBuf
|
||||
|
||||
f.wbuf = msg.Encode(f.wbuf)
|
||||
if f.tracer != nil {
|
||||
f.tracer.traceClose('F', int32(len(f.wbuf)-prevLen), msg)
|
||||
}
|
||||
}
|
||||
|
||||
// SendDescribe sends a Describe message to the backend (i.e. the server). The message is buffered until Flush is
|
||||
// called. Any error encountered will be returned from Flush.
|
||||
// SendDescribe sends a Describe message to the backend (i.e. the server). The message is not guaranteed to be written until
|
||||
// Flush is called.
|
||||
func (f *Frontend) SendDescribe(msg *Describe) {
|
||||
if f.encodeError != nil {
|
||||
return
|
||||
}
|
||||
|
||||
prevLen := len(f.wbuf)
|
||||
newBuf, err := msg.Encode(f.wbuf)
|
||||
if err != nil {
|
||||
f.encodeError = err
|
||||
return
|
||||
}
|
||||
f.wbuf = newBuf
|
||||
|
||||
f.wbuf = msg.Encode(f.wbuf)
|
||||
if f.tracer != nil {
|
||||
f.tracer.traceDescribe('F', int32(len(f.wbuf)-prevLen), msg)
|
||||
}
|
||||
}
|
||||
|
||||
// SendExecute sends an Execute message to the backend (i.e. the server). The message is buffered until Flush is called.
|
||||
// Any error encountered will be returned from Flush.
|
||||
// SendExecute sends a Execute message to the backend (i.e. the server). The message is not guaranteed to be written until
|
||||
// Flush is called.
|
||||
func (f *Frontend) SendExecute(msg *Execute) {
|
||||
if f.encodeError != nil {
|
||||
return
|
||||
}
|
||||
|
||||
prevLen := len(f.wbuf)
|
||||
newBuf, err := msg.Encode(f.wbuf)
|
||||
if err != nil {
|
||||
f.encodeError = err
|
||||
return
|
||||
}
|
||||
f.wbuf = newBuf
|
||||
|
||||
f.wbuf = msg.Encode(f.wbuf)
|
||||
if f.tracer != nil {
|
||||
f.tracer.TraceQueryute('F', int32(len(f.wbuf)-prevLen), msg)
|
||||
}
|
||||
}
|
||||
|
||||
// SendSync sends a Sync message to the backend (i.e. the server). The message is buffered until Flush is called. Any
|
||||
// error encountered will be returned from Flush.
|
||||
// SendSync sends a Sync message to the backend (i.e. the server). The message is not guaranteed to be written until
|
||||
// Flush is called.
|
||||
func (f *Frontend) SendSync(msg *Sync) {
|
||||
if f.encodeError != nil {
|
||||
return
|
||||
}
|
||||
|
||||
prevLen := len(f.wbuf)
|
||||
newBuf, err := msg.Encode(f.wbuf)
|
||||
if err != nil {
|
||||
f.encodeError = err
|
||||
return
|
||||
}
|
||||
f.wbuf = newBuf
|
||||
|
||||
f.wbuf = msg.Encode(f.wbuf)
|
||||
if f.tracer != nil {
|
||||
f.tracer.traceSync('F', int32(len(f.wbuf)-prevLen), msg)
|
||||
}
|
||||
}
|
||||
|
||||
// SendQuery sends a Query message to the backend (i.e. the server). The message is buffered until Flush is called. Any
|
||||
// error encountered will be returned from Flush.
|
||||
// SendQuery sends a Query message to the backend (i.e. the server). The message is not guaranteed to be written until
|
||||
// Flush is called.
|
||||
func (f *Frontend) SendQuery(msg *Query) {
|
||||
if f.encodeError != nil {
|
||||
return
|
||||
}
|
||||
|
||||
prevLen := len(f.wbuf)
|
||||
newBuf, err := msg.Encode(f.wbuf)
|
||||
if err != nil {
|
||||
f.encodeError = err
|
||||
return
|
||||
}
|
||||
f.wbuf = newBuf
|
||||
|
||||
f.wbuf = msg.Encode(f.wbuf)
|
||||
if f.tracer != nil {
|
||||
f.tracer.traceQuery('F', int32(len(f.wbuf)-prevLen), msg)
|
||||
}
|
||||
|
||||
19
vendor/github.com/jackc/pgx/v5/pgproto3/function_call.go
generated
vendored
19
vendor/github.com/jackc/pgx/v5/pgproto3/function_call.go
generated
vendored
@@ -2,8 +2,6 @@ package pgproto3
|
||||
|
||||
import (
|
||||
"encoding/binary"
|
||||
"errors"
|
||||
"math"
|
||||
|
||||
"github.com/jackc/pgx/v5/internal/pgio"
|
||||
)
|
||||
@@ -73,21 +71,15 @@ func (dst *FunctionCall) Decode(src []byte) error {
|
||||
}
|
||||
|
||||
// Encode encodes src into dst. dst will include the 1 byte message type identifier and the 4 byte message length.
|
||||
func (src *FunctionCall) Encode(dst []byte) ([]byte, error) {
|
||||
dst, sp := beginMessage(dst, 'F')
|
||||
func (src *FunctionCall) Encode(dst []byte) []byte {
|
||||
dst = append(dst, 'F')
|
||||
sp := len(dst)
|
||||
dst = pgio.AppendUint32(dst, 0) // Unknown length, set it at the end
|
||||
dst = pgio.AppendUint32(dst, src.Function)
|
||||
|
||||
if len(src.ArgFormatCodes) > math.MaxUint16 {
|
||||
return nil, errors.New("too many arg format codes")
|
||||
}
|
||||
dst = pgio.AppendUint16(dst, uint16(len(src.ArgFormatCodes)))
|
||||
for _, argFormatCode := range src.ArgFormatCodes {
|
||||
dst = pgio.AppendUint16(dst, argFormatCode)
|
||||
}
|
||||
|
||||
if len(src.Arguments) > math.MaxUint16 {
|
||||
return nil, errors.New("too many arguments")
|
||||
}
|
||||
dst = pgio.AppendUint16(dst, uint16(len(src.Arguments)))
|
||||
for _, argument := range src.Arguments {
|
||||
if argument == nil {
|
||||
@@ -98,5 +90,6 @@ func (src *FunctionCall) Encode(dst []byte) ([]byte, error) {
|
||||
}
|
||||
}
|
||||
dst = pgio.AppendUint16(dst, src.ResultFormatCode)
|
||||
return finishMessage(dst, sp)
|
||||
pgio.SetInt32(dst[sp:], int32(len(dst[sp:])))
|
||||
return dst
|
||||
}
|
||||
|
||||
10
vendor/github.com/jackc/pgx/v5/pgproto3/function_call_response.go
generated
vendored
10
vendor/github.com/jackc/pgx/v5/pgproto3/function_call_response.go
generated
vendored
@@ -39,8 +39,10 @@ func (dst *FunctionCallResponse) Decode(src []byte) error {
|
||||
}
|
||||
|
||||
// Encode encodes src into dst. dst will include the 1 byte message type identifier and the 4 byte message length.
|
||||
func (src *FunctionCallResponse) Encode(dst []byte) ([]byte, error) {
|
||||
dst, sp := beginMessage(dst, 'V')
|
||||
func (src *FunctionCallResponse) Encode(dst []byte) []byte {
|
||||
dst = append(dst, 'V')
|
||||
sp := len(dst)
|
||||
dst = pgio.AppendInt32(dst, -1)
|
||||
|
||||
if src.Result == nil {
|
||||
dst = pgio.AppendInt32(dst, -1)
|
||||
@@ -49,7 +51,9 @@ func (src *FunctionCallResponse) Encode(dst []byte) ([]byte, error) {
|
||||
dst = append(dst, src.Result...)
|
||||
}
|
||||
|
||||
return finishMessage(dst, sp)
|
||||
pgio.SetInt32(dst[sp:], int32(len(dst[sp:])))
|
||||
|
||||
return dst
|
||||
}
|
||||
|
||||
// MarshalJSON implements encoding/json.Marshaler.
|
||||
|
||||
4
vendor/github.com/jackc/pgx/v5/pgproto3/gss_enc_request.go
generated
vendored
4
vendor/github.com/jackc/pgx/v5/pgproto3/gss_enc_request.go
generated
vendored
@@ -31,10 +31,10 @@ func (dst *GSSEncRequest) Decode(src []byte) error {
|
||||
}
|
||||
|
||||
// Encode encodes src into dst. dst will include the 4 byte message length.
|
||||
func (src *GSSEncRequest) Encode(dst []byte) ([]byte, error) {
|
||||
func (src *GSSEncRequest) Encode(dst []byte) []byte {
|
||||
dst = pgio.AppendInt32(dst, 8)
|
||||
dst = pgio.AppendInt32(dst, gssEncReqNumber)
|
||||
return dst, nil
|
||||
return dst
|
||||
}
|
||||
|
||||
// MarshalJSON implements encoding/json.Marshaler.
|
||||
|
||||
9
vendor/github.com/jackc/pgx/v5/pgproto3/gss_response.go
generated
vendored
9
vendor/github.com/jackc/pgx/v5/pgproto3/gss_response.go
generated
vendored
@@ -2,6 +2,8 @@ package pgproto3
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
|
||||
"github.com/jackc/pgx/v5/internal/pgio"
|
||||
)
|
||||
|
||||
type GSSResponse struct {
|
||||
@@ -16,10 +18,11 @@ func (g *GSSResponse) Decode(data []byte) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (g *GSSResponse) Encode(dst []byte) ([]byte, error) {
|
||||
dst, sp := beginMessage(dst, 'p')
|
||||
func (g *GSSResponse) Encode(dst []byte) []byte {
|
||||
dst = append(dst, 'p')
|
||||
dst = pgio.AppendInt32(dst, int32(4+len(g.Data)))
|
||||
dst = append(dst, g.Data...)
|
||||
return finishMessage(dst, sp)
|
||||
return dst
|
||||
}
|
||||
|
||||
// MarshalJSON implements encoding/json.Marshaler.
|
||||
|
||||
4
vendor/github.com/jackc/pgx/v5/pgproto3/no_data.go
generated
vendored
4
vendor/github.com/jackc/pgx/v5/pgproto3/no_data.go
generated
vendored
@@ -20,8 +20,8 @@ func (dst *NoData) Decode(src []byte) error {
|
||||
}
|
||||
|
||||
// Encode encodes src into dst. dst will include the 1 byte message type identifier and the 4 byte message length.
|
||||
func (src *NoData) Encode(dst []byte) ([]byte, error) {
|
||||
return append(dst, 'n', 0, 0, 0, 4), nil
|
||||
func (src *NoData) Encode(dst []byte) []byte {
|
||||
return append(dst, 'n', 0, 0, 0, 4)
|
||||
}
|
||||
|
||||
// MarshalJSON implements encoding/json.Marshaler.
|
||||
|
||||
6
vendor/github.com/jackc/pgx/v5/pgproto3/notice_response.go
generated
vendored
6
vendor/github.com/jackc/pgx/v5/pgproto3/notice_response.go
generated
vendored
@@ -12,8 +12,6 @@ func (dst *NoticeResponse) Decode(src []byte) error {
|
||||
}
|
||||
|
||||
// Encode encodes src into dst. dst will include the 1 byte message type identifier and the 4 byte message length.
|
||||
func (src *NoticeResponse) Encode(dst []byte) ([]byte, error) {
|
||||
dst, sp := beginMessage(dst, 'N')
|
||||
dst = (*ErrorResponse)(src).appendFields(dst)
|
||||
return finishMessage(dst, sp)
|
||||
func (src *NoticeResponse) Encode(dst []byte) []byte {
|
||||
return append(dst, (*ErrorResponse)(src).marshalBinary('N')...)
|
||||
}
|
||||
|
||||
12
vendor/github.com/jackc/pgx/v5/pgproto3/notification_response.go
generated
vendored
12
vendor/github.com/jackc/pgx/v5/pgproto3/notification_response.go
generated
vendored
@@ -45,14 +45,20 @@ func (dst *NotificationResponse) Decode(src []byte) error {
|
||||
}
|
||||
|
||||
// Encode encodes src into dst. dst will include the 1 byte message type identifier and the 4 byte message length.
|
||||
func (src *NotificationResponse) Encode(dst []byte) ([]byte, error) {
|
||||
dst, sp := beginMessage(dst, 'A')
|
||||
func (src *NotificationResponse) Encode(dst []byte) []byte {
|
||||
dst = append(dst, 'A')
|
||||
sp := len(dst)
|
||||
dst = pgio.AppendInt32(dst, -1)
|
||||
|
||||
dst = pgio.AppendUint32(dst, src.PID)
|
||||
dst = append(dst, src.Channel...)
|
||||
dst = append(dst, 0)
|
||||
dst = append(dst, src.Payload...)
|
||||
dst = append(dst, 0)
|
||||
return finishMessage(dst, sp)
|
||||
|
||||
pgio.SetInt32(dst[sp:], int32(len(dst[sp:])))
|
||||
|
||||
return dst
|
||||
}
|
||||
|
||||
// MarshalJSON implements encoding/json.Marshaler.
|
||||
|
||||
15
vendor/github.com/jackc/pgx/v5/pgproto3/parameter_description.go
generated
vendored
15
vendor/github.com/jackc/pgx/v5/pgproto3/parameter_description.go
generated
vendored
@@ -4,8 +4,6 @@ import (
|
||||
"bytes"
|
||||
"encoding/binary"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"math"
|
||||
|
||||
"github.com/jackc/pgx/v5/internal/pgio"
|
||||
)
|
||||
@@ -41,18 +39,19 @@ func (dst *ParameterDescription) Decode(src []byte) error {
|
||||
}
|
||||
|
||||
// Encode encodes src into dst. dst will include the 1 byte message type identifier and the 4 byte message length.
|
||||
func (src *ParameterDescription) Encode(dst []byte) ([]byte, error) {
|
||||
dst, sp := beginMessage(dst, 't')
|
||||
func (src *ParameterDescription) Encode(dst []byte) []byte {
|
||||
dst = append(dst, 't')
|
||||
sp := len(dst)
|
||||
dst = pgio.AppendInt32(dst, -1)
|
||||
|
||||
if len(src.ParameterOIDs) > math.MaxUint16 {
|
||||
return nil, errors.New("too many parameter oids")
|
||||
}
|
||||
dst = pgio.AppendUint16(dst, uint16(len(src.ParameterOIDs)))
|
||||
for _, oid := range src.ParameterOIDs {
|
||||
dst = pgio.AppendUint32(dst, oid)
|
||||
}
|
||||
|
||||
return finishMessage(dst, sp)
|
||||
pgio.SetInt32(dst[sp:], int32(len(dst[sp:])))
|
||||
|
||||
return dst
|
||||
}
|
||||
|
||||
// MarshalJSON implements encoding/json.Marshaler.
|
||||
|
||||
14
vendor/github.com/jackc/pgx/v5/pgproto3/parameter_status.go
generated
vendored
14
vendor/github.com/jackc/pgx/v5/pgproto3/parameter_status.go
generated
vendored
@@ -3,6 +3,8 @@ package pgproto3
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
|
||||
"github.com/jackc/pgx/v5/internal/pgio"
|
||||
)
|
||||
|
||||
type ParameterStatus struct {
|
||||
@@ -35,13 +37,19 @@ func (dst *ParameterStatus) Decode(src []byte) error {
|
||||
}
|
||||
|
||||
// Encode encodes src into dst. dst will include the 1 byte message type identifier and the 4 byte message length.
|
||||
func (src *ParameterStatus) Encode(dst []byte) ([]byte, error) {
|
||||
dst, sp := beginMessage(dst, 'S')
|
||||
func (src *ParameterStatus) Encode(dst []byte) []byte {
|
||||
dst = append(dst, 'S')
|
||||
sp := len(dst)
|
||||
dst = pgio.AppendInt32(dst, -1)
|
||||
|
||||
dst = append(dst, src.Name...)
|
||||
dst = append(dst, 0)
|
||||
dst = append(dst, src.Value...)
|
||||
dst = append(dst, 0)
|
||||
return finishMessage(dst, sp)
|
||||
|
||||
pgio.SetInt32(dst[sp:], int32(len(dst[sp:])))
|
||||
|
||||
return dst
|
||||
}
|
||||
|
||||
// MarshalJSON implements encoding/json.Marshaler.
|
||||
|
||||
15
vendor/github.com/jackc/pgx/v5/pgproto3/parse.go
generated
vendored
15
vendor/github.com/jackc/pgx/v5/pgproto3/parse.go
generated
vendored
@@ -4,8 +4,6 @@ import (
|
||||
"bytes"
|
||||
"encoding/binary"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"math"
|
||||
|
||||
"github.com/jackc/pgx/v5/internal/pgio"
|
||||
)
|
||||
@@ -54,23 +52,24 @@ func (dst *Parse) Decode(src []byte) error {
|
||||
}
|
||||
|
||||
// Encode encodes src into dst. dst will include the 1 byte message type identifier and the 4 byte message length.
|
||||
func (src *Parse) Encode(dst []byte) ([]byte, error) {
|
||||
dst, sp := beginMessage(dst, 'P')
|
||||
func (src *Parse) Encode(dst []byte) []byte {
|
||||
dst = append(dst, 'P')
|
||||
sp := len(dst)
|
||||
dst = pgio.AppendInt32(dst, -1)
|
||||
|
||||
dst = append(dst, src.Name...)
|
||||
dst = append(dst, 0)
|
||||
dst = append(dst, src.Query...)
|
||||
dst = append(dst, 0)
|
||||
|
||||
if len(src.ParameterOIDs) > math.MaxUint16 {
|
||||
return nil, errors.New("too many parameter oids")
|
||||
}
|
||||
dst = pgio.AppendUint16(dst, uint16(len(src.ParameterOIDs)))
|
||||
for _, oid := range src.ParameterOIDs {
|
||||
dst = pgio.AppendUint32(dst, oid)
|
||||
}
|
||||
|
||||
return finishMessage(dst, sp)
|
||||
pgio.SetInt32(dst[sp:], int32(len(dst[sp:])))
|
||||
|
||||
return dst
|
||||
}
|
||||
|
||||
// MarshalJSON implements encoding/json.Marshaler.
|
||||
|
||||
4
vendor/github.com/jackc/pgx/v5/pgproto3/parse_complete.go
generated
vendored
4
vendor/github.com/jackc/pgx/v5/pgproto3/parse_complete.go
generated
vendored
@@ -20,8 +20,8 @@ func (dst *ParseComplete) Decode(src []byte) error {
|
||||
}
|
||||
|
||||
// Encode encodes src into dst. dst will include the 1 byte message type identifier and the 4 byte message length.
|
||||
func (src *ParseComplete) Encode(dst []byte) ([]byte, error) {
|
||||
return append(dst, '1', 0, 0, 0, 4), nil
|
||||
func (src *ParseComplete) Encode(dst []byte) []byte {
|
||||
return append(dst, '1', 0, 0, 0, 4)
|
||||
}
|
||||
|
||||
// MarshalJSON implements encoding/json.Marshaler.
|
||||
|
||||
11
vendor/github.com/jackc/pgx/v5/pgproto3/password_message.go
generated
vendored
11
vendor/github.com/jackc/pgx/v5/pgproto3/password_message.go
generated
vendored
@@ -3,6 +3,8 @@ package pgproto3
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
|
||||
"github.com/jackc/pgx/v5/internal/pgio"
|
||||
)
|
||||
|
||||
type PasswordMessage struct {
|
||||
@@ -30,11 +32,14 @@ func (dst *PasswordMessage) Decode(src []byte) error {
|
||||
}
|
||||
|
||||
// Encode encodes src into dst. dst will include the 1 byte message type identifier and the 4 byte message length.
|
||||
func (src *PasswordMessage) Encode(dst []byte) ([]byte, error) {
|
||||
dst, sp := beginMessage(dst, 'p')
|
||||
func (src *PasswordMessage) Encode(dst []byte) []byte {
|
||||
dst = append(dst, 'p')
|
||||
dst = pgio.AppendInt32(dst, int32(4+len(src.Password)+1))
|
||||
|
||||
dst = append(dst, src.Password...)
|
||||
dst = append(dst, 0)
|
||||
return finishMessage(dst, sp)
|
||||
|
||||
return dst
|
||||
}
|
||||
|
||||
// MarshalJSON implements encoding/json.Marshaler.
|
||||
|
||||
37
vendor/github.com/jackc/pgx/v5/pgproto3/pgproto3.go
generated
vendored
37
vendor/github.com/jackc/pgx/v5/pgproto3/pgproto3.go
generated
vendored
@@ -4,14 +4,8 @@ import (
|
||||
"encoding/hex"
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"github.com/jackc/pgx/v5/internal/pgio"
|
||||
)
|
||||
|
||||
// maxMessageBodyLen is the maximum length of a message body in bytes. See PG_LARGE_MESSAGE_LIMIT in the PostgreSQL
|
||||
// source. It is defined as (MaxAllocSize - 1). MaxAllocSize is defined as 0x3fffffff.
|
||||
const maxMessageBodyLen = (0x3fffffff - 1)
|
||||
|
||||
// Message is the interface implemented by an object that can decode and encode
|
||||
// a particular PostgreSQL message.
|
||||
type Message interface {
|
||||
@@ -20,7 +14,7 @@ type Message interface {
|
||||
Decode(data []byte) error
|
||||
|
||||
// Encode appends itself to dst and returns the new buffer.
|
||||
Encode(dst []byte) ([]byte, error)
|
||||
Encode(dst []byte) []byte
|
||||
}
|
||||
|
||||
// FrontendMessage is a message sent by the frontend (i.e. the client).
|
||||
@@ -76,15 +70,6 @@ func (e *writeError) Unwrap() error {
|
||||
return e.err
|
||||
}
|
||||
|
||||
type ExceededMaxBodyLenErr struct {
|
||||
MaxExpectedBodyLen int
|
||||
ActualBodyLen int
|
||||
}
|
||||
|
||||
func (e *ExceededMaxBodyLenErr) Error() string {
|
||||
return fmt.Sprintf("invalid body length: expected at most %d, but got %d", e.MaxExpectedBodyLen, e.ActualBodyLen)
|
||||
}
|
||||
|
||||
// getValueFromJSON gets the value from a protocol message representation in JSON.
|
||||
func getValueFromJSON(v map[string]string) ([]byte, error) {
|
||||
if v == nil {
|
||||
@@ -98,23 +83,3 @@ func getValueFromJSON(v map[string]string) ([]byte, error) {
|
||||
}
|
||||
return nil, errors.New("unknown protocol representation")
|
||||
}
|
||||
|
||||
// beginMessage begins a new message of type t. It appends the message type and a placeholder for the message length to
|
||||
// dst. It returns the new buffer and the position of the message length placeholder.
|
||||
func beginMessage(dst []byte, t byte) ([]byte, int) {
|
||||
dst = append(dst, t)
|
||||
sp := len(dst)
|
||||
dst = pgio.AppendInt32(dst, -1)
|
||||
return dst, sp
|
||||
}
|
||||
|
||||
// finishMessage finishes a message that was started with beginMessage. It computes the message length and writes it to
|
||||
// dst[sp]. If the message length is too large it returns an error. Otherwise it returns the final message buffer.
|
||||
func finishMessage(dst []byte, sp int) ([]byte, error) {
|
||||
messageBodyLen := len(dst[sp:])
|
||||
if messageBodyLen > maxMessageBodyLen {
|
||||
return nil, errors.New("message body too large")
|
||||
}
|
||||
pgio.SetInt32(dst[sp:], int32(messageBodyLen))
|
||||
return dst, nil
|
||||
}
|
||||
|
||||
4
vendor/github.com/jackc/pgx/v5/pgproto3/portal_suspended.go
generated
vendored
4
vendor/github.com/jackc/pgx/v5/pgproto3/portal_suspended.go
generated
vendored
@@ -20,8 +20,8 @@ func (dst *PortalSuspended) Decode(src []byte) error {
|
||||
}
|
||||
|
||||
// Encode encodes src into dst. dst will include the 1 byte message type identifier and the 4 byte message length.
|
||||
func (src *PortalSuspended) Encode(dst []byte) ([]byte, error) {
|
||||
return append(dst, 's', 0, 0, 0, 4), nil
|
||||
func (src *PortalSuspended) Encode(dst []byte) []byte {
|
||||
return append(dst, 's', 0, 0, 0, 4)
|
||||
}
|
||||
|
||||
// MarshalJSON implements encoding/json.Marshaler.
|
||||
|
||||
11
vendor/github.com/jackc/pgx/v5/pgproto3/query.go
generated
vendored
11
vendor/github.com/jackc/pgx/v5/pgproto3/query.go
generated
vendored
@@ -3,6 +3,8 @@ package pgproto3
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
|
||||
"github.com/jackc/pgx/v5/internal/pgio"
|
||||
)
|
||||
|
||||
type Query struct {
|
||||
@@ -26,11 +28,14 @@ func (dst *Query) Decode(src []byte) error {
|
||||
}
|
||||
|
||||
// Encode encodes src into dst. dst will include the 1 byte message type identifier and the 4 byte message length.
|
||||
func (src *Query) Encode(dst []byte) ([]byte, error) {
|
||||
dst, sp := beginMessage(dst, 'Q')
|
||||
func (src *Query) Encode(dst []byte) []byte {
|
||||
dst = append(dst, 'Q')
|
||||
dst = pgio.AppendInt32(dst, int32(4+len(src.String)+1))
|
||||
|
||||
dst = append(dst, src.String...)
|
||||
dst = append(dst, 0)
|
||||
return finishMessage(dst, sp)
|
||||
|
||||
return dst
|
||||
}
|
||||
|
||||
// MarshalJSON implements encoding/json.Marshaler.
|
||||
|
||||
4
vendor/github.com/jackc/pgx/v5/pgproto3/ready_for_query.go
generated
vendored
4
vendor/github.com/jackc/pgx/v5/pgproto3/ready_for_query.go
generated
vendored
@@ -25,8 +25,8 @@ func (dst *ReadyForQuery) Decode(src []byte) error {
|
||||
}
|
||||
|
||||
// Encode encodes src into dst. dst will include the 1 byte message type identifier and the 4 byte message length.
|
||||
func (src *ReadyForQuery) Encode(dst []byte) ([]byte, error) {
|
||||
return append(dst, 'Z', 0, 0, 0, 5, src.TxStatus), nil
|
||||
func (src *ReadyForQuery) Encode(dst []byte) []byte {
|
||||
return append(dst, 'Z', 0, 0, 0, 5, src.TxStatus)
|
||||
}
|
||||
|
||||
// MarshalJSON implements encoding/json.Marshaler.
|
||||
|
||||
15
vendor/github.com/jackc/pgx/v5/pgproto3/row_description.go
generated
vendored
15
vendor/github.com/jackc/pgx/v5/pgproto3/row_description.go
generated
vendored
@@ -4,8 +4,6 @@ import (
|
||||
"bytes"
|
||||
"encoding/binary"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"math"
|
||||
|
||||
"github.com/jackc/pgx/v5/internal/pgio"
|
||||
)
|
||||
@@ -101,12 +99,11 @@ func (dst *RowDescription) Decode(src []byte) error {
|
||||
}
|
||||
|
||||
// Encode encodes src into dst. dst will include the 1 byte message type identifier and the 4 byte message length.
|
||||
func (src *RowDescription) Encode(dst []byte) ([]byte, error) {
|
||||
dst, sp := beginMessage(dst, 'T')
|
||||
func (src *RowDescription) Encode(dst []byte) []byte {
|
||||
dst = append(dst, 'T')
|
||||
sp := len(dst)
|
||||
dst = pgio.AppendInt32(dst, -1)
|
||||
|
||||
if len(src.Fields) > math.MaxUint16 {
|
||||
return nil, errors.New("too many fields")
|
||||
}
|
||||
dst = pgio.AppendUint16(dst, uint16(len(src.Fields)))
|
||||
for _, fd := range src.Fields {
|
||||
dst = append(dst, fd.Name...)
|
||||
@@ -120,7 +117,9 @@ func (src *RowDescription) Encode(dst []byte) ([]byte, error) {
|
||||
dst = pgio.AppendInt16(dst, fd.Format)
|
||||
}
|
||||
|
||||
return finishMessage(dst, sp)
|
||||
pgio.SetInt32(dst[sp:], int32(len(dst[sp:])))
|
||||
|
||||
return dst
|
||||
}
|
||||
|
||||
// MarshalJSON implements encoding/json.Marshaler.
|
||||
|
||||
10
vendor/github.com/jackc/pgx/v5/pgproto3/sasl_initial_response.go
generated
vendored
10
vendor/github.com/jackc/pgx/v5/pgproto3/sasl_initial_response.go
generated
vendored
@@ -39,8 +39,10 @@ func (dst *SASLInitialResponse) Decode(src []byte) error {
|
||||
}
|
||||
|
||||
// Encode encodes src into dst. dst will include the 1 byte message type identifier and the 4 byte message length.
|
||||
func (src *SASLInitialResponse) Encode(dst []byte) ([]byte, error) {
|
||||
dst, sp := beginMessage(dst, 'p')
|
||||
func (src *SASLInitialResponse) Encode(dst []byte) []byte {
|
||||
dst = append(dst, 'p')
|
||||
sp := len(dst)
|
||||
dst = pgio.AppendInt32(dst, -1)
|
||||
|
||||
dst = append(dst, []byte(src.AuthMechanism)...)
|
||||
dst = append(dst, 0)
|
||||
@@ -48,7 +50,9 @@ func (src *SASLInitialResponse) Encode(dst []byte) ([]byte, error) {
|
||||
dst = pgio.AppendInt32(dst, int32(len(src.Data)))
|
||||
dst = append(dst, src.Data...)
|
||||
|
||||
return finishMessage(dst, sp)
|
||||
pgio.SetInt32(dst[sp:], int32(len(dst[sp:])))
|
||||
|
||||
return dst
|
||||
}
|
||||
|
||||
// MarshalJSON implements encoding/json.Marshaler.
|
||||
|
||||
11
vendor/github.com/jackc/pgx/v5/pgproto3/sasl_response.go
generated
vendored
11
vendor/github.com/jackc/pgx/v5/pgproto3/sasl_response.go
generated
vendored
@@ -3,6 +3,8 @@ package pgproto3
|
||||
import (
|
||||
"encoding/hex"
|
||||
"encoding/json"
|
||||
|
||||
"github.com/jackc/pgx/v5/internal/pgio"
|
||||
)
|
||||
|
||||
type SASLResponse struct {
|
||||
@@ -20,10 +22,13 @@ func (dst *SASLResponse) Decode(src []byte) error {
|
||||
}
|
||||
|
||||
// Encode encodes src into dst. dst will include the 1 byte message type identifier and the 4 byte message length.
|
||||
func (src *SASLResponse) Encode(dst []byte) ([]byte, error) {
|
||||
dst, sp := beginMessage(dst, 'p')
|
||||
func (src *SASLResponse) Encode(dst []byte) []byte {
|
||||
dst = append(dst, 'p')
|
||||
dst = pgio.AppendInt32(dst, int32(4+len(src.Data)))
|
||||
|
||||
dst = append(dst, src.Data...)
|
||||
return finishMessage(dst, sp)
|
||||
|
||||
return dst
|
||||
}
|
||||
|
||||
// MarshalJSON implements encoding/json.Marshaler.
|
||||
|
||||
4
vendor/github.com/jackc/pgx/v5/pgproto3/ssl_request.go
generated
vendored
4
vendor/github.com/jackc/pgx/v5/pgproto3/ssl_request.go
generated
vendored
@@ -31,10 +31,10 @@ func (dst *SSLRequest) Decode(src []byte) error {
|
||||
}
|
||||
|
||||
// Encode encodes src into dst. dst will include the 4 byte message length.
|
||||
func (src *SSLRequest) Encode(dst []byte) ([]byte, error) {
|
||||
func (src *SSLRequest) Encode(dst []byte) []byte {
|
||||
dst = pgio.AppendInt32(dst, 8)
|
||||
dst = pgio.AppendInt32(dst, sslRequestNumber)
|
||||
return dst, nil
|
||||
return dst
|
||||
}
|
||||
|
||||
// MarshalJSON implements encoding/json.Marshaler.
|
||||
|
||||
10
vendor/github.com/jackc/pgx/v5/pgproto3/startup_message.go
generated
vendored
10
vendor/github.com/jackc/pgx/v5/pgproto3/startup_message.go
generated
vendored
@@ -38,14 +38,14 @@ func (dst *StartupMessage) Decode(src []byte) error {
|
||||
for {
|
||||
idx := bytes.IndexByte(src[rp:], 0)
|
||||
if idx < 0 {
|
||||
return &invalidMessageFormatErr{messageType: "StartupMessage"}
|
||||
return &invalidMessageFormatErr{messageType: "StartupMesage"}
|
||||
}
|
||||
key := string(src[rp : rp+idx])
|
||||
rp += idx + 1
|
||||
|
||||
idx = bytes.IndexByte(src[rp:], 0)
|
||||
if idx < 0 {
|
||||
return &invalidMessageFormatErr{messageType: "StartupMessage"}
|
||||
return &invalidMessageFormatErr{messageType: "StartupMesage"}
|
||||
}
|
||||
value := string(src[rp : rp+idx])
|
||||
rp += idx + 1
|
||||
@@ -64,7 +64,7 @@ func (dst *StartupMessage) Decode(src []byte) error {
|
||||
}
|
||||
|
||||
// Encode encodes src into dst. dst will include the 1 byte message type identifier and the 4 byte message length.
|
||||
func (src *StartupMessage) Encode(dst []byte) ([]byte, error) {
|
||||
func (src *StartupMessage) Encode(dst []byte) []byte {
|
||||
sp := len(dst)
|
||||
dst = pgio.AppendInt32(dst, -1)
|
||||
|
||||
@@ -77,7 +77,9 @@ func (src *StartupMessage) Encode(dst []byte) ([]byte, error) {
|
||||
}
|
||||
dst = append(dst, 0)
|
||||
|
||||
return finishMessage(dst, sp)
|
||||
pgio.SetInt32(dst[sp:], int32(len(dst[sp:])))
|
||||
|
||||
return dst
|
||||
}
|
||||
|
||||
// MarshalJSON implements encoding/json.Marshaler.
|
||||
|
||||
4
vendor/github.com/jackc/pgx/v5/pgproto3/sync.go
generated
vendored
4
vendor/github.com/jackc/pgx/v5/pgproto3/sync.go
generated
vendored
@@ -20,8 +20,8 @@ func (dst *Sync) Decode(src []byte) error {
|
||||
}
|
||||
|
||||
// Encode encodes src into dst. dst will include the 1 byte message type identifier and the 4 byte message length.
|
||||
func (src *Sync) Encode(dst []byte) ([]byte, error) {
|
||||
return append(dst, 'S', 0, 0, 0, 4), nil
|
||||
func (src *Sync) Encode(dst []byte) []byte {
|
||||
return append(dst, 'S', 0, 0, 0, 4)
|
||||
}
|
||||
|
||||
// MarshalJSON implements encoding/json.Marshaler.
|
||||
|
||||
4
vendor/github.com/jackc/pgx/v5/pgproto3/terminate.go
generated
vendored
4
vendor/github.com/jackc/pgx/v5/pgproto3/terminate.go
generated
vendored
@@ -20,8 +20,8 @@ func (dst *Terminate) Decode(src []byte) error {
|
||||
}
|
||||
|
||||
// Encode encodes src into dst. dst will include the 1 byte message type identifier and the 4 byte message length.
|
||||
func (src *Terminate) Encode(dst []byte) ([]byte, error) {
|
||||
return append(dst, 'X', 0, 0, 0, 4), nil
|
||||
func (src *Terminate) Encode(dst []byte) []byte {
|
||||
return append(dst, 'X', 0, 0, 0, 4)
|
||||
}
|
||||
|
||||
// MarshalJSON implements encoding/json.Marshaler.
|
||||
|
||||
Reference in New Issue
Block a user