diff options
| author | Felix Hanley <felix@userspace.com.au> | 2019-10-29 10:58:47 +0000 |
|---|---|---|
| committer | Felix Hanley <felix@userspace.com.au> | 2019-10-29 10:58:47 +0000 |
| commit | eda2530094e72463f6aef6e7f9bf524002e248fa (patch) | |
| tree | 66e987a6229a159c0eb19c448b3af04db5f56733 /vendor/github.com/jackc/pgx/pgproto3 | |
| parent | fbc564026fa84c7f9142cdcf60accdf6b5bdaeaf (diff) | |
| download | dhtsearch-eda2530094e72463f6aef6e7f9bf524002e248fa.tar.gz dhtsearch-eda2530094e72463f6aef6e7f9bf524002e248fa.tar.bz2 | |
Remove vendored files and create go.mod
Diffstat (limited to 'vendor/github.com/jackc/pgx/pgproto3')
36 files changed, 0 insertions, 2267 deletions
diff --git a/vendor/github.com/jackc/pgx/pgproto3/authentication.go b/vendor/github.com/jackc/pgx/pgproto3/authentication.go deleted file mode 100644 index 77750b8..0000000 --- a/vendor/github.com/jackc/pgx/pgproto3/authentication.go +++ /dev/null @@ -1,54 +0,0 @@ -package pgproto3 - -import ( - "encoding/binary" - - "github.com/jackc/pgx/pgio" - "github.com/pkg/errors" -) - -const ( - AuthTypeOk = 0 - AuthTypeCleartextPassword = 3 - AuthTypeMD5Password = 5 -) - -type Authentication struct { - Type uint32 - - // MD5Password fields - Salt [4]byte -} - -func (*Authentication) Backend() {} - -func (dst *Authentication) Decode(src []byte) error { - *dst = Authentication{Type: binary.BigEndian.Uint32(src[:4])} - - switch dst.Type { - case AuthTypeOk: - case AuthTypeCleartextPassword: - case AuthTypeMD5Password: - copy(dst.Salt[:], src[4:8]) - default: - return errors.Errorf("unknown authentication type: %d", dst.Type) - } - - return nil -} - -func (src *Authentication) Encode(dst []byte) []byte { - dst = append(dst, 'R') - sp := len(dst) - dst = pgio.AppendInt32(dst, -1) - dst = pgio.AppendUint32(dst, src.Type) - - switch src.Type { - case AuthTypeMD5Password: - dst = append(dst, src.Salt[:]...) - } - - pgio.SetInt32(dst[sp:], int32(len(dst[sp:]))) - - return dst -} diff --git a/vendor/github.com/jackc/pgx/pgproto3/backend.go b/vendor/github.com/jackc/pgx/pgproto3/backend.go deleted file mode 100644 index 8f3c347..0000000 --- a/vendor/github.com/jackc/pgx/pgproto3/backend.go +++ /dev/null @@ -1,110 +0,0 @@ -package pgproto3 - -import ( - "encoding/binary" - "io" - - "github.com/jackc/pgx/chunkreader" - "github.com/pkg/errors" -) - -type Backend struct { - cr *chunkreader.ChunkReader - w io.Writer - - // Frontend message flyweights - bind Bind - _close Close - describe Describe - execute Execute - flush Flush - parse Parse - passwordMessage PasswordMessage - query Query - startupMessage StartupMessage - sync Sync - terminate Terminate - - bodyLen int - msgType byte - partialMsg bool -} - -func NewBackend(r io.Reader, w io.Writer) (*Backend, error) { - cr := chunkreader.NewChunkReader(r) - return &Backend{cr: cr, w: w}, nil -} - -func (b *Backend) Send(msg BackendMessage) error { - _, err := b.w.Write(msg.Encode(nil)) - return err -} - -func (b *Backend) ReceiveStartupMessage() (*StartupMessage, error) { - buf, err := b.cr.Next(4) - if err != nil { - return nil, err - } - msgSize := int(binary.BigEndian.Uint32(buf) - 4) - - buf, err = b.cr.Next(msgSize) - if err != nil { - return nil, err - } - - err = b.startupMessage.Decode(buf) - if err != nil { - return nil, err - } - - return &b.startupMessage, nil -} - -func (b *Backend) Receive() (FrontendMessage, error) { - if !b.partialMsg { - header, err := b.cr.Next(5) - if err != nil { - return nil, err - } - - b.msgType = header[0] - b.bodyLen = int(binary.BigEndian.Uint32(header[1:])) - 4 - b.partialMsg = true - } - - var msg FrontendMessage - switch b.msgType { - case 'B': - msg = &b.bind - case 'C': - msg = &b._close - case 'D': - msg = &b.describe - case 'E': - msg = &b.execute - case 'H': - msg = &b.flush - case 'P': - msg = &b.parse - case 'p': - msg = &b.passwordMessage - case 'Q': - msg = &b.query - case 'S': - msg = &b.sync - case 'X': - msg = &b.terminate - default: - return nil, errors.Errorf("unknown message type: %c", b.msgType) - } - - msgBody, err := b.cr.Next(b.bodyLen) - if err != nil { - return nil, err - } - - b.partialMsg = false - - err = msg.Decode(msgBody) - return msg, err -} diff --git a/vendor/github.com/jackc/pgx/pgproto3/backend_key_data.go b/vendor/github.com/jackc/pgx/pgproto3/backend_key_data.go deleted file mode 100644 index 5a478f1..0000000 --- a/vendor/github.com/jackc/pgx/pgproto3/backend_key_data.go +++ /dev/null @@ -1,46 +0,0 @@ -package pgproto3 - -import ( - "encoding/binary" - "encoding/json" - - "github.com/jackc/pgx/pgio" -) - -type BackendKeyData struct { - ProcessID uint32 - SecretKey uint32 -} - -func (*BackendKeyData) Backend() {} - -func (dst *BackendKeyData) Decode(src []byte) error { - if len(src) != 8 { - return &invalidMessageLenErr{messageType: "BackendKeyData", expectedLen: 8, actualLen: len(src)} - } - - dst.ProcessID = binary.BigEndian.Uint32(src[:4]) - dst.SecretKey = binary.BigEndian.Uint32(src[4:]) - - return nil -} - -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 dst -} - -func (src *BackendKeyData) MarshalJSON() ([]byte, error) { - return json.Marshal(struct { - Type string - ProcessID uint32 - SecretKey uint32 - }{ - Type: "BackendKeyData", - ProcessID: src.ProcessID, - SecretKey: src.SecretKey, - }) -} diff --git a/vendor/github.com/jackc/pgx/pgproto3/big_endian.go b/vendor/github.com/jackc/pgx/pgproto3/big_endian.go deleted file mode 100644 index f7bdb97..0000000 --- a/vendor/github.com/jackc/pgx/pgproto3/big_endian.go +++ /dev/null @@ -1,37 +0,0 @@ -package pgproto3 - -import ( - "encoding/binary" -) - -type BigEndianBuf [8]byte - -func (b BigEndianBuf) Int16(n int16) []byte { - buf := b[0:2] - binary.BigEndian.PutUint16(buf, uint16(n)) - return buf -} - -func (b BigEndianBuf) Uint16(n uint16) []byte { - buf := b[0:2] - binary.BigEndian.PutUint16(buf, n) - return buf -} - -func (b BigEndianBuf) Int32(n int32) []byte { - buf := b[0:4] - binary.BigEndian.PutUint32(buf, uint32(n)) - return buf -} - -func (b BigEndianBuf) Uint32(n uint32) []byte { - buf := b[0:4] - binary.BigEndian.PutUint32(buf, n) - return buf -} - -func (b BigEndianBuf) Int64(n int64) []byte { - buf := b[0:8] - binary.BigEndian.PutUint64(buf, uint64(n)) - return buf -} diff --git a/vendor/github.com/jackc/pgx/pgproto3/bind.go b/vendor/github.com/jackc/pgx/pgproto3/bind.go deleted file mode 100644 index cceee6a..0000000 --- a/vendor/github.com/jackc/pgx/pgproto3/bind.go +++ /dev/null @@ -1,171 +0,0 @@ -package pgproto3 - -import ( - "bytes" - "encoding/binary" - "encoding/hex" - "encoding/json" - - "github.com/jackc/pgx/pgio" -) - -type Bind struct { - DestinationPortal string - PreparedStatement string - ParameterFormatCodes []int16 - Parameters [][]byte - ResultFormatCodes []int16 -} - -func (*Bind) Frontend() {} - -func (dst *Bind) Decode(src []byte) error { - *dst = Bind{} - - idx := bytes.IndexByte(src, 0) - if idx < 0 { - return &invalidMessageFormatErr{messageType: "Bind"} - } - dst.DestinationPortal = string(src[:idx]) - rp := idx + 1 - - idx = bytes.IndexByte(src[rp:], 0) - if idx < 0 { - return &invalidMessageFormatErr{messageType: "Bind"} - } - dst.PreparedStatement = string(src[rp : rp+idx]) - rp += idx + 1 - - if len(src[rp:]) < 2 { - return &invalidMessageFormatErr{messageType: "Bind"} - } - parameterFormatCodeCount := int(binary.BigEndian.Uint16(src[rp:])) - rp += 2 - - if parameterFormatCodeCount > 0 { - dst.ParameterFormatCodes = make([]int16, parameterFormatCodeCount) - - if len(src[rp:]) < len(dst.ParameterFormatCodes)*2 { - return &invalidMessageFormatErr{messageType: "Bind"} - } - for i := 0; i < parameterFormatCodeCount; i++ { - dst.ParameterFormatCodes[i] = int16(binary.BigEndian.Uint16(src[rp:])) - rp += 2 - } - } - - if len(src[rp:]) < 2 { - return &invalidMessageFormatErr{messageType: "Bind"} - } - parameterCount := int(binary.BigEndian.Uint16(src[rp:])) - rp += 2 - - if parameterCount > 0 { - dst.Parameters = make([][]byte, parameterCount) - - for i := 0; i < parameterCount; i++ { - if len(src[rp:]) < 4 { - return &invalidMessageFormatErr{messageType: "Bind"} - } - - msgSize := int(int32(binary.BigEndian.Uint32(src[rp:]))) - rp += 4 - - // null - if msgSize == -1 { - continue - } - - if len(src[rp:]) < msgSize { - return &invalidMessageFormatErr{messageType: "Bind"} - } - - dst.Parameters[i] = src[rp : rp+msgSize] - rp += msgSize - } - } - - if len(src[rp:]) < 2 { - return &invalidMessageFormatErr{messageType: "Bind"} - } - resultFormatCodeCount := int(binary.BigEndian.Uint16(src[rp:])) - rp += 2 - - dst.ResultFormatCodes = make([]int16, resultFormatCodeCount) - if len(src[rp:]) < len(dst.ResultFormatCodes)*2 { - return &invalidMessageFormatErr{messageType: "Bind"} - } - for i := 0; i < resultFormatCodeCount; i++ { - dst.ResultFormatCodes[i] = int16(binary.BigEndian.Uint16(src[rp:])) - rp += 2 - } - - return nil -} - -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) - - dst = pgio.AppendUint16(dst, uint16(len(src.ParameterFormatCodes))) - for _, fc := range src.ParameterFormatCodes { - dst = pgio.AppendInt16(dst, fc) - } - - dst = pgio.AppendUint16(dst, uint16(len(src.Parameters))) - for _, p := range src.Parameters { - if p == nil { - dst = pgio.AppendInt32(dst, -1) - continue - } - - dst = pgio.AppendInt32(dst, int32(len(p))) - dst = append(dst, p...) - } - - dst = pgio.AppendUint16(dst, uint16(len(src.ResultFormatCodes))) - for _, fc := range src.ResultFormatCodes { - dst = pgio.AppendInt16(dst, fc) - } - - pgio.SetInt32(dst[sp:], int32(len(dst[sp:]))) - - return dst -} - -func (src *Bind) MarshalJSON() ([]byte, error) { - formattedParameters := make([]map[string]string, len(src.Parameters)) - for i, p := range src.Parameters { - if p == nil { - continue - } - - if src.ParameterFormatCodes[i] == 0 { - formattedParameters[i] = map[string]string{"text": string(p)} - } else { - formattedParameters[i] = map[string]string{"binary": hex.EncodeToString(p)} - } - } - - return json.Marshal(struct { - Type string - DestinationPortal string - PreparedStatement string - ParameterFormatCodes []int16 - Parameters []map[string]string - ResultFormatCodes []int16 - }{ - Type: "Bind", - DestinationPortal: src.DestinationPortal, - PreparedStatement: src.PreparedStatement, - ParameterFormatCodes: src.ParameterFormatCodes, - Parameters: formattedParameters, - ResultFormatCodes: src.ResultFormatCodes, - }) -} diff --git a/vendor/github.com/jackc/pgx/pgproto3/bind_complete.go b/vendor/github.com/jackc/pgx/pgproto3/bind_complete.go deleted file mode 100644 index 6036051..0000000 --- a/vendor/github.com/jackc/pgx/pgproto3/bind_complete.go +++ /dev/null @@ -1,29 +0,0 @@ -package pgproto3 - -import ( - "encoding/json" -) - -type BindComplete struct{} - -func (*BindComplete) Backend() {} - -func (dst *BindComplete) Decode(src []byte) error { - if len(src) != 0 { - return &invalidMessageLenErr{messageType: "BindComplete", expectedLen: 0, actualLen: len(src)} - } - - return nil -} - -func (src *BindComplete) Encode(dst []byte) []byte { - return append(dst, '2', 0, 0, 0, 4) -} - -func (src *BindComplete) MarshalJSON() ([]byte, error) { - return json.Marshal(struct { - Type string - }{ - Type: "BindComplete", - }) -} diff --git a/vendor/github.com/jackc/pgx/pgproto3/close.go b/vendor/github.com/jackc/pgx/pgproto3/close.go deleted file mode 100644 index 5ff4c88..0000000 --- a/vendor/github.com/jackc/pgx/pgproto3/close.go +++ /dev/null @@ -1,59 +0,0 @@ -package pgproto3 - -import ( - "bytes" - "encoding/json" - - "github.com/jackc/pgx/pgio" -) - -type Close struct { - ObjectType byte // 'S' = prepared statement, 'P' = portal - Name string -} - -func (*Close) Frontend() {} - -func (dst *Close) Decode(src []byte) error { - if len(src) < 2 { - return &invalidMessageFormatErr{messageType: "Close"} - } - - dst.ObjectType = src[0] - rp := 1 - - idx := bytes.IndexByte(src[rp:], 0) - if idx != len(src[rp:])-1 { - return &invalidMessageFormatErr{messageType: "Close"} - } - - dst.Name = string(src[rp : len(src)-1]) - - return nil -} - -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) - - pgio.SetInt32(dst[sp:], int32(len(dst[sp:]))) - - return dst -} - -func (src *Close) MarshalJSON() ([]byte, error) { - return json.Marshal(struct { - Type string - ObjectType string - Name string - }{ - Type: "Close", - ObjectType: string(src.ObjectType), - Name: src.Name, - }) -} diff --git a/vendor/github.com/jackc/pgx/pgproto3/close_complete.go b/vendor/github.com/jackc/pgx/pgproto3/close_complete.go deleted file mode 100644 index db793c9..0000000 --- a/vendor/github.com/jackc/pgx/pgproto3/close_complete.go +++ /dev/null @@ -1,29 +0,0 @@ -package pgproto3 - -import ( - "encoding/json" -) - -type CloseComplete struct{} - -func (*CloseComplete) Backend() {} - -func (dst *CloseComplete) Decode(src []byte) error { - if len(src) != 0 { - return &invalidMessageLenErr{messageType: "CloseComplete", expectedLen: 0, actualLen: len(src)} - } - - return nil -} - -func (src *CloseComplete) Encode(dst []byte) []byte { - return append(dst, '3', 0, 0, 0, 4) -} - -func (src *CloseComplete) MarshalJSON() ([]byte, error) { - return json.Marshal(struct { - Type string - }{ - Type: "CloseComplete", - }) -} diff --git a/vendor/github.com/jackc/pgx/pgproto3/command_complete.go b/vendor/github.com/jackc/pgx/pgproto3/command_complete.go deleted file mode 100644 index 8584853..0000000 --- a/vendor/github.com/jackc/pgx/pgproto3/command_complete.go +++ /dev/null @@ -1,48 +0,0 @@ -package pgproto3 - -import ( - "bytes" - "encoding/json" - - "github.com/jackc/pgx/pgio" -) - -type CommandComplete struct { - CommandTag string -} - -func (*CommandComplete) Backend() {} - -func (dst *CommandComplete) Decode(src []byte) error { - idx := bytes.IndexByte(src, 0) - if idx != len(src)-1 { - return &invalidMessageFormatErr{messageType: "CommandComplete"} - } - - dst.CommandTag = string(src[:idx]) - - return nil -} - -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) - - pgio.SetInt32(dst[sp:], int32(len(dst[sp:]))) - - return dst -} - -func (src *CommandComplete) MarshalJSON() ([]byte, error) { - return json.Marshal(struct { - Type string - CommandTag string - }{ - Type: "CommandComplete", - CommandTag: src.CommandTag, - }) -} diff --git a/vendor/github.com/jackc/pgx/pgproto3/copy_both_response.go b/vendor/github.com/jackc/pgx/pgproto3/copy_both_response.go deleted file mode 100644 index 2862a34..0000000 --- a/vendor/github.com/jackc/pgx/pgproto3/copy_both_response.go +++ /dev/null @@ -1,65 +0,0 @@ -package pgproto3 - -import ( - "bytes" - "encoding/binary" - "encoding/json" - - "github.com/jackc/pgx/pgio" -) - -type CopyBothResponse struct { - OverallFormat byte - ColumnFormatCodes []uint16 -} - -func (*CopyBothResponse) Backend() {} - -func (dst *CopyBothResponse) Decode(src []byte) error { - buf := bytes.NewBuffer(src) - - if buf.Len() < 3 { - return &invalidMessageFormatErr{messageType: "CopyBothResponse"} - } - - overallFormat := buf.Next(1)[0] - - columnCount := int(binary.BigEndian.Uint16(buf.Next(2))) - if buf.Len() != columnCount*2 { - return &invalidMessageFormatErr{messageType: "CopyBothResponse"} - } - - columnFormatCodes := make([]uint16, columnCount) - for i := 0; i < columnCount; i++ { - columnFormatCodes[i] = binary.BigEndian.Uint16(buf.Next(2)) - } - - *dst = CopyBothResponse{OverallFormat: overallFormat, ColumnFormatCodes: columnFormatCodes} - - return nil -} - -func (src *CopyBothResponse) Encode(dst []byte) []byte { - dst = append(dst, 'W') - sp := len(dst) - dst = pgio.AppendInt32(dst, -1) - - dst = pgio.AppendUint16(dst, uint16(len(src.ColumnFormatCodes))) - for _, fc := range src.ColumnFormatCodes { - dst = pgio.AppendUint16(dst, fc) - } - - pgio.SetInt32(dst[sp:], int32(len(dst[sp:]))) - - return dst -} - -func (src *CopyBothResponse) MarshalJSON() ([]byte, error) { - return json.Marshal(struct { - Type string - ColumnFormatCodes []uint16 - }{ - Type: "CopyBothResponse", - ColumnFormatCodes: src.ColumnFormatCodes, - }) -} diff --git a/vendor/github.com/jackc/pgx/pgproto3/copy_data.go b/vendor/github.com/jackc/pgx/pgproto3/copy_data.go deleted file mode 100644 index fab139e..0000000 --- a/vendor/github.com/jackc/pgx/pgproto3/copy_data.go +++ /dev/null @@ -1,37 +0,0 @@ -package pgproto3 - -import ( - "encoding/hex" - "encoding/json" - - "github.com/jackc/pgx/pgio" -) - -type CopyData struct { - Data []byte -} - -func (*CopyData) Backend() {} -func (*CopyData) Frontend() {} - -func (dst *CopyData) Decode(src []byte) error { - dst.Data = src - return nil -} - -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 dst -} - -func (src *CopyData) MarshalJSON() ([]byte, error) { - return json.Marshal(struct { - Type string - Data string - }{ - Type: "CopyData", - Data: hex.EncodeToString(src.Data), - }) -} diff --git a/vendor/github.com/jackc/pgx/pgproto3/copy_in_response.go b/vendor/github.com/jackc/pgx/pgproto3/copy_in_response.go deleted file mode 100644 index 54083cd..0000000 --- a/vendor/github.com/jackc/pgx/pgproto3/copy_in_response.go +++ /dev/null @@ -1,65 +0,0 @@ -package pgproto3 - -import ( - "bytes" - "encoding/binary" - "encoding/json" - - "github.com/jackc/pgx/pgio" -) - -type CopyInResponse struct { - OverallFormat byte - ColumnFormatCodes []uint16 -} - -func (*CopyInResponse) Backend() {} - -func (dst *CopyInResponse) Decode(src []byte) error { - buf := bytes.NewBuffer(src) - - if buf.Len() < 3 { - return &invalidMessageFormatErr{messageType: "CopyInResponse"} - } - - overallFormat := buf.Next(1)[0] - - columnCount := int(binary.BigEndian.Uint16(buf.Next(2))) - if buf.Len() != columnCount*2 { - return &invalidMessageFormatErr{messageType: "CopyInResponse"} - } - - columnFormatCodes := make([]uint16, columnCount) - for i := 0; i < columnCount; i++ { - columnFormatCodes[i] = binary.BigEndian.Uint16(buf.Next(2)) - } - - *dst = CopyInResponse{OverallFormat: overallFormat, ColumnFormatCodes: columnFormatCodes} - - return nil -} - -func (src *CopyInResponse) Encode(dst []byte) []byte { - dst = append(dst, 'G') - sp := len(dst) - dst = pgio.AppendInt32(dst, -1) - - dst = pgio.AppendUint16(dst, uint16(len(src.ColumnFormatCodes))) - for _, fc := range src.ColumnFormatCodes { - dst = pgio.AppendUint16(dst, fc) - } - - pgio.SetInt32(dst[sp:], int32(len(dst[sp:]))) - - return dst -} - -func (src *CopyInResponse) MarshalJSON() ([]byte, error) { - return json.Marshal(struct { - Type string - ColumnFormatCodes []uint16 - }{ - Type: "CopyInResponse", - ColumnFormatCodes: src.ColumnFormatCodes, - }) -} diff --git a/vendor/github.com/jackc/pgx/pgproto3/copy_out_response.go b/vendor/github.com/jackc/pgx/pgproto3/copy_out_response.go deleted file mode 100644 index eaa33b8..0000000 --- a/vendor/github.com/jackc/pgx/pgproto3/copy_out_response.go +++ /dev/null @@ -1,65 +0,0 @@ -package pgproto3 - -import ( - "bytes" - "encoding/binary" - "encoding/json" - - "github.com/jackc/pgx/pgio" -) - -type CopyOutResponse struct { - OverallFormat byte - ColumnFormatCodes []uint16 -} - -func (*CopyOutResponse) Backend() {} - -func (dst *CopyOutResponse) Decode(src []byte) error { - buf := bytes.NewBuffer(src) - - if buf.Len() < 3 { - return &invalidMessageFormatErr{messageType: "CopyOutResponse"} - } - - overallFormat := buf.Next(1)[0] - - columnCount := int(binary.BigEndian.Uint16(buf.Next(2))) - if buf.Len() != columnCount*2 { - return &invalidMessageFormatErr{messageType: "CopyOutResponse"} - } - - columnFormatCodes := make([]uint16, columnCount) - for i := 0; i < columnCount; i++ { - columnFormatCodes[i] = binary.BigEndian.Uint16(buf.Next(2)) - } - - *dst = CopyOutResponse{OverallFormat: overallFormat, ColumnFormatCodes: columnFormatCodes} - - return nil -} - -func (src *CopyOutResponse) Encode(dst []byte) []byte { - dst = append(dst, 'H') - sp := len(dst) - dst = pgio.AppendInt32(dst, -1) - - dst = pgio.AppendUint16(dst, uint16(len(src.ColumnFormatCodes))) - for _, fc := range src.ColumnFormatCodes { - dst = pgio.AppendUint16(dst, fc) - } - - pgio.SetInt32(dst[sp:], int32(len(dst[sp:]))) - - return dst -} - -func (src *CopyOutResponse) MarshalJSON() ([]byte, error) { - return json.Marshal(struct { - Type string - ColumnFormatCodes []uint16 - }{ - Type: "CopyOutResponse", - ColumnFormatCodes: src.ColumnFormatCodes, - }) -} diff --git a/vendor/github.com/jackc/pgx/pgproto3/data_row.go b/vendor/github.com/jackc/pgx/pgproto3/data_row.go deleted file mode 100644 index e46d3cc..0000000 --- a/vendor/github.com/jackc/pgx/pgproto3/data_row.go +++ /dev/null @@ -1,112 +0,0 @@ -package pgproto3 - -import ( - "encoding/binary" - "encoding/hex" - "encoding/json" - - "github.com/jackc/pgx/pgio" -) - -type DataRow struct { - Values [][]byte -} - -func (*DataRow) Backend() {} - -func (dst *DataRow) Decode(src []byte) error { - if len(src) < 2 { - return &invalidMessageFormatErr{messageType: "DataRow"} - } - rp := 0 - fieldCount := int(binary.BigEndian.Uint16(src[rp:])) - rp += 2 - - // If the capacity of the values slice is too small OR substantially too - // large reallocate. This is too avoid one row with many columns from - // permanently allocating memory. - if cap(dst.Values) < fieldCount || cap(dst.Values)-fieldCount > 32 { - newCap := 32 - if newCap < fieldCount { - newCap = fieldCount - } - dst.Values = make([][]byte, fieldCount, newCap) - } else { - dst.Values = dst.Values[:fieldCount] - } - - for i := 0; i < fieldCount; i++ { - if len(src[rp:]) < 4 { - return &invalidMessageFormatErr{messageType: "DataRow"} - } - - msgSize := int(int32(binary.BigEndian.Uint32(src[rp:]))) - rp += 4 - - // null - if msgSize == -1 { - dst.Values[i] = nil - } else { - if len(src[rp:]) < msgSize { - return &invalidMessageFormatErr{messageType: "DataRow"} - } - - dst.Values[i] = src[rp : rp+msgSize] - rp += msgSize - } - } - - return nil -} - -func (src *DataRow) Encode(dst []byte) []byte { - dst = append(dst, 'D') - sp := len(dst) - dst = pgio.AppendInt32(dst, -1) - - dst = pgio.AppendUint16(dst, uint16(len(src.Values))) - for _, v := range src.Values { - if v == nil { - dst = pgio.AppendInt32(dst, -1) - continue - } - - dst = pgio.AppendInt32(dst, int32(len(v))) - dst = append(dst, v...) - } - - pgio.SetInt32(dst[sp:], int32(len(dst[sp:]))) - - return dst -} - -func (src *DataRow) MarshalJSON() ([]byte, error) { - formattedValues := make([]map[string]string, len(src.Values)) - for i, v := range src.Values { - if v == nil { - continue - } - - var hasNonPrintable bool - for _, b := range v { - if b < 32 { - hasNonPrintable = true - break - } - } - - if hasNonPrintable { - formattedValues[i] = map[string]string{"binary": hex.EncodeToString(v)} - } else { - formattedValues[i] = map[string]string{"text": string(v)} - } - } - - return json.Marshal(struct { - Type string - Values []map[string]string - }{ - Type: "DataRow", - Values: formattedValues, - }) -} diff --git a/vendor/github.com/jackc/pgx/pgproto3/describe.go b/vendor/github.com/jackc/pgx/pgproto3/describe.go deleted file mode 100644 index bb7bc05..0000000 --- a/vendor/github.com/jackc/pgx/pgproto3/describe.go +++ /dev/null @@ -1,59 +0,0 @@ -package pgproto3 - -import ( - "bytes" - "encoding/json" - - "github.com/jackc/pgx/pgio" -) - -type Describe struct { - ObjectType byte // 'S' = prepared statement, 'P' = portal - Name string -} - -func (*Describe) Frontend() {} - -func (dst *Describe) Decode(src []byte) error { - if len(src) < 2 { - return &invalidMessageFormatErr{messageType: "Describe"} - } - - dst.ObjectType = src[0] - rp := 1 - - idx := bytes.IndexByte(src[rp:], 0) - if idx != len(src[rp:])-1 { - return &invalidMessageFormatErr{messageType: "Describe"} - } - - dst.Name = string(src[rp : len(src)-1]) - - return nil -} - -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) - - pgio.SetInt32(dst[sp:], int32(len(dst[sp:]))) - - return dst -} - -func (src *Describe) MarshalJSON() ([]byte, error) { - return json.Marshal(struct { - Type string - ObjectType string - Name string - }{ - Type: "Describe", - ObjectType: string(src.ObjectType), - Name: src.Name, - }) -} diff --git a/vendor/github.com/jackc/pgx/pgproto3/empty_query_response.go b/vendor/github.com/jackc/pgx/pgproto3/empty_query_response.go deleted file mode 100644 index d283b06..0000000 --- a/vendor/github.com/jackc/pgx/pgproto3/empty_query_response.go +++ /dev/null @@ -1,29 +0,0 @@ -package pgproto3 - -import ( - "encoding/json" -) - -type EmptyQueryResponse struct{} - -func (*EmptyQueryResponse) Backend() {} - -func (dst *EmptyQueryResponse) Decode(src []byte) error { - if len(src) != 0 { - return &invalidMessageLenErr{messageType: "EmptyQueryResponse", expectedLen: 0, actualLen: len(src)} - } - - return nil -} - -func (src *EmptyQueryResponse) Encode(dst []byte) []byte { - return append(dst, 'I', 0, 0, 0, 4) -} - -func (src *EmptyQueryResponse) MarshalJSON() ([]byte, error) { - return json.Marshal(struct { - Type string - }{ - Type: "EmptyQueryResponse", - }) -} diff --git a/vendor/github.com/jackc/pgx/pgproto3/error_response.go b/vendor/github.com/jackc/pgx/pgproto3/error_response.go deleted file mode 100644 index 160234f..0000000 --- a/vendor/github.com/jackc/pgx/pgproto3/error_response.go +++ /dev/null @@ -1,197 +0,0 @@ -package pgproto3 - -import ( - "bytes" - "encoding/binary" - "strconv" -) - -type ErrorResponse struct { - Severity string - Code string - Message string - Detail string - Hint string - Position int32 - InternalPosition int32 - InternalQuery string - Where string - SchemaName string - TableName string - ColumnName string - DataTypeName string - ConstraintName string - File string - Line int32 - Routine string - - UnknownFields map[byte]string -} - -func (*ErrorResponse) Backend() {} - -func (dst *ErrorResponse) Decode(src []byte) error { - *dst = ErrorResponse{} - - buf := bytes.NewBuffer(src) - - for { - k, err := buf.ReadByte() - if err != nil { - return err - } - if k == 0 { - break - } - - vb, err := buf.ReadBytes(0) - if err != nil { - return err - } - v := string(vb[:len(vb)-1]) - - switch k { - case 'S': - dst.Severity = v - case 'C': - dst.Code = v - case 'M': - dst.Message = v - case 'D': - dst.Detail = v - case 'H': - dst.Hint = v - case 'P': - s := v - n, _ := strconv.ParseInt(s, 10, 32) - dst.Position = int32(n) - case 'p': - s := v - n, _ := strconv.ParseInt(s, 10, 32) - dst.InternalPosition = int32(n) - case 'q': - dst.InternalQuery = v - case 'W': - dst.Where = v - case 's': - dst.SchemaName = v - case 't': - dst.TableName = v - case 'c': - dst.ColumnName = v - case 'd': - dst.DataTypeName = v - case 'n': - dst.ConstraintName = v - case 'F': - dst.File = v - case 'L': - s := v - n, _ := strconv.ParseInt(s, 10, 32) - dst.Line = int32(n) - case 'R': - dst.Routine = v - - default: - if dst.UnknownFields == nil { - dst.UnknownFields = make(map[byte]string) - } - dst.UnknownFields[k] = v - } - } - - return nil -} - -func (src *ErrorResponse) Encode(dst []byte) []byte { - return append(dst, src.marshalBinary('E')...) -} - -func (src *ErrorResponse) marshalBinary(typeByte byte) []byte { - var bigEndian BigEndianBuf - buf := &bytes.Buffer{} - - buf.WriteByte(typeByte) - buf.Write(bigEndian.Uint32(0)) - - if src.Severity != "" { - buf.WriteString(src.Severity) - buf.WriteByte(0) - } - if src.Code != "" { - buf.WriteString(src.Code) - buf.WriteByte(0) - } - if src.Message != "" { - buf.WriteString(src.Message) - buf.WriteByte(0) - } - if src.Detail != "" { - buf.WriteString(src.Detail) - buf.WriteByte(0) - } - if src.Hint != "" { - buf.WriteString(src.Hint) - buf.WriteByte(0) - } - if src.Position != 0 { - buf.WriteString(strconv.Itoa(int(src.Position))) - buf.WriteByte(0) - } - if src.InternalPosition != 0 { - buf.WriteString(strconv.Itoa(int(src.InternalPosition))) - buf.WriteByte(0) - } - if src.InternalQuery != "" { - buf.WriteString(src.InternalQuery) - buf.WriteByte(0) - } - if src.Where != "" { - buf.WriteString(src.Where) - buf.WriteByte(0) - } - if src.SchemaName != "" { - buf.WriteString(src.SchemaName) - buf.WriteByte(0) - } - if src.TableName != "" { - buf.WriteString(src.TableName) - buf.WriteByte(0) - } - if src.ColumnName != "" { - buf.WriteString(src.ColumnName) - buf.WriteByte(0) - } - if src.DataTypeName != "" { - buf.WriteString(src.DataTypeName) - buf.WriteByte(0) - } - if src.ConstraintName != "" { - buf.WriteString(src.ConstraintName) - buf.WriteByte(0) - } - if src.File != "" { - buf.WriteString(src.File) - buf.WriteByte(0) - } - if src.Line != 0 { - buf.WriteString(strconv.Itoa(int(src.Line))) - buf.WriteByte(0) - } - if src.Routine != "" { - buf.WriteString(src.Routine) - buf.WriteByte(0) - } - - for k, v := range src.UnknownFields { - buf.WriteByte(k) - buf.WriteByte(0) - buf.WriteString(v) - buf.WriteByte(0) - } - buf.WriteByte(0) - - binary.BigEndian.PutUint32(buf.Bytes()[1:5], uint32(buf.Len()-1)) - - return buf.Bytes() -} diff --git a/vendor/github.com/jackc/pgx/pgproto3/execute.go b/vendor/github.com/jackc/pgx/pgproto3/execute.go deleted file mode 100644 index 76da994..0000000 --- a/vendor/github.com/jackc/pgx/pgproto3/execute.go +++ /dev/null @@ -1,60 +0,0 @@ -package pgproto3 - -import ( - "bytes" - "encoding/binary" - "encoding/json" - - "github.com/jackc/pgx/pgio" -) - -type Execute struct { - Portal string - MaxRows uint32 -} - -func (*Execute) Frontend() {} - -func (dst *Execute) Decode(src []byte) error { - buf := bytes.NewBuffer(src) - - b, err := buf.ReadBytes(0) - if err != nil { - return err - } - dst.Portal = string(b[:len(b)-1]) - - if buf.Len() < 4 { - return &invalidMessageFormatErr{messageType: "Execute"} - } - dst.MaxRows = binary.BigEndian.Uint32(buf.Next(4)) - - return nil -} - -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) - - pgio.SetInt32(dst[sp:], int32(len(dst[sp:]))) - - return dst -} - -func (src *Execute) MarshalJSON() ([]byte, error) { - return json.Marshal(struct { - Type string - Portal string - MaxRows uint32 - }{ - Type: "Execute", - Portal: src.Portal, - MaxRows: src.MaxRows, - }) -} diff --git a/vendor/github.com/jackc/pgx/pgproto3/flush.go b/vendor/github.com/jackc/pgx/pgproto3/flush.go deleted file mode 100644 index 7fd5e98..0000000 --- a/vendor/github.com/jackc/pgx/pgproto3/flush.go +++ /dev/null @@ -1,29 +0,0 @@ -package pgproto3 - -import ( - "encoding/json" -) - -type Flush struct{} - -func (*Flush) Frontend() {} - -func (dst *Flush) Decode(src []byte) error { - if len(src) != 0 { - return &invalidMessageLenErr{messageType: "Flush", expectedLen: 0, actualLen: len(src)} - } - - return nil -} - -func (src *Flush) Encode(dst []byte) []byte { - return append(dst, 'H', 0, 0, 0, 4) -} - -func (src *Flush) MarshalJSON() ([]byte, error) { - return json.Marshal(struct { - Type string - }{ - Type: "Flush", - }) -} diff --git a/vendor/github.com/jackc/pgx/pgproto3/frontend.go b/vendor/github.com/jackc/pgx/pgproto3/frontend.go deleted file mode 100644 index d803d36..0000000 --- a/vendor/github.com/jackc/pgx/pgproto3/frontend.go +++ /dev/null @@ -1,122 +0,0 @@ -package pgproto3 - -import ( - "encoding/binary" - "io" - - "github.com/jackc/pgx/chunkreader" - "github.com/pkg/errors" -) - -type Frontend struct { - cr *chunkreader.ChunkReader - w io.Writer - - // Backend message flyweights - authentication Authentication - backendKeyData BackendKeyData - bindComplete BindComplete - closeComplete CloseComplete - commandComplete CommandComplete - copyBothResponse CopyBothResponse - copyData CopyData - copyInResponse CopyInResponse - copyOutResponse CopyOutResponse - dataRow DataRow - emptyQueryResponse EmptyQueryResponse - errorResponse ErrorResponse - functionCallResponse FunctionCallResponse - noData NoData - noticeResponse NoticeResponse - notificationResponse NotificationResponse - parameterDescription ParameterDescription - parameterStatus ParameterStatus - parseComplete ParseComplete - readyForQuery ReadyForQuery - rowDescription RowDescription - - bodyLen int - msgType byte - partialMsg bool -} - -func NewFrontend(r io.Reader, w io.Writer) (*Frontend, error) { - cr := chunkreader.NewChunkReader(r) - return &Frontend{cr: cr, w: w}, nil -} - -func (b *Frontend) Send(msg FrontendMessage) error { - _, err := b.w.Write(msg.Encode(nil)) - return err -} - -func (b *Frontend) Receive() (BackendMessage, error) { - if !b.partialMsg { - header, err := b.cr.Next(5) - if err != nil { - return nil, err - } - - b.msgType = header[0] - b.bodyLen = int(binary.BigEndian.Uint32(header[1:])) - 4 - b.partialMsg = true - } - - var msg BackendMessage - switch b.msgType { - case '1': - msg = &b.parseComplete - case '2': - msg = &b.bindComplete - case '3': - msg = &b.closeComplete - case 'A': - msg = &b.notificationResponse - case 'C': - msg = &b.commandComplete - case 'd': - msg = &b.copyData - case 'D': - msg = &b.dataRow - case 'E': - msg = &b.errorResponse - case 'G': - msg = &b.copyInResponse - case 'H': - msg = &b.copyOutResponse - case 'I': - msg = &b.emptyQueryResponse - case 'K': - msg = &b.backendKeyData - case 'n': - msg = &b.noData - case 'N': - msg = &b.noticeResponse - case 'R': - msg = &b.authentication - case 'S': - msg = &b.parameterStatus - case 't': - msg = &b.parameterDescription - case 'T': - msg = &b.rowDescription - case 'V': - msg = &b.functionCallResponse - case 'W': - msg = &b.copyBothResponse - case 'Z': - msg = &b.readyForQuery - default: - return nil, errors.Errorf("unknown message type: %c", b.msgType) - } - - msgBody, err := b.cr.Next(b.bodyLen) - if err != nil { - return nil, err - } - - b.partialMsg = false - - err = msg.Decode(msgBody) - return msg, err -} diff --git a/vendor/github.com/jackc/pgx/pgproto3/function_call_response.go b/vendor/github.com/jackc/pgx/pgproto3/function_call_response.go deleted file mode 100644 index bb325b6..0000000 --- a/vendor/github.com/jackc/pgx/pgproto3/function_call_response.go +++ /dev/null @@ -1,78 +0,0 @@ -package pgproto3 - -import ( - "encoding/binary" - "encoding/hex" - "encoding/json" - - "github.com/jackc/pgx/pgio" -) - -type FunctionCallResponse struct { - Result []byte -} - -func (*FunctionCallResponse) Backend() {} - -func (dst *FunctionCallResponse) Decode(src []byte) error { - if len(src) < 4 { - return &invalidMessageFormatErr{messageType: "FunctionCallResponse"} - } - rp := 0 - resultSize := int(binary.BigEndian.Uint32(src[rp:])) - rp += 4 - - if resultSize == -1 { - dst.Result = nil - return nil - } - - if len(src[rp:]) != resultSize { - return &invalidMessageFormatErr{messageType: "FunctionCallResponse"} - } - - dst.Result = src[rp:] - return nil -} - -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) - } else { - dst = pgio.AppendInt32(dst, int32(len(src.Result))) - dst = append(dst, src.Result...) - } - - pgio.SetInt32(dst[sp:], int32(len(dst[sp:]))) - - return dst -} - -func (src *FunctionCallResponse) MarshalJSON() ([]byte, error) { - var formattedValue map[string]string - var hasNonPrintable bool - for _, b := range src.Result { - if b < 32 { - hasNonPrintable = true - break - } - } - - if hasNonPrintable { - formattedValue = map[string]string{"binary": hex.EncodeToString(src.Result)} - } else { - formattedValue = map[string]string{"text": string(src.Result)} - } - - return json.Marshal(struct { - Type string - Result map[string]string - }{ - Type: "FunctionCallResponse", - Result: formattedValue, - }) -} diff --git a/vendor/github.com/jackc/pgx/pgproto3/no_data.go b/vendor/github.com/jackc/pgx/pgproto3/no_data.go deleted file mode 100644 index 1fb47c2..0000000 --- a/vendor/github.com/jackc/pgx/pgproto3/no_data.go +++ /dev/null @@ -1,29 +0,0 @@ -package pgproto3 - -import ( - "encoding/json" -) - -type NoData struct{} - -func (*NoData) Backend() {} - -func (dst *NoData) Decode(src []byte) error { - if len(src) != 0 { - return &invalidMessageLenErr{messageType: "NoData", expectedLen: 0, actualLen: len(src)} - } - - return nil -} - -func (src *NoData) Encode(dst []byte) []byte { - return append(dst, 'n', 0, 0, 0, 4) -} - -func (src *NoData) MarshalJSON() ([]byte, error) { - return json.Marshal(struct { - Type string - }{ - Type: "NoData", - }) -} diff --git a/vendor/github.com/jackc/pgx/pgproto3/notice_response.go b/vendor/github.com/jackc/pgx/pgproto3/notice_response.go deleted file mode 100644 index e4595aa..0000000 --- a/vendor/github.com/jackc/pgx/pgproto3/notice_response.go +++ /dev/null @@ -1,13 +0,0 @@ -package pgproto3 - -type NoticeResponse ErrorResponse - -func (*NoticeResponse) Backend() {} - -func (dst *NoticeResponse) Decode(src []byte) error { - return (*ErrorResponse)(dst).Decode(src) -} - -func (src *NoticeResponse) Encode(dst []byte) []byte { - return append(dst, (*ErrorResponse)(src).marshalBinary('N')...) -} diff --git a/vendor/github.com/jackc/pgx/pgproto3/notification_response.go b/vendor/github.com/jackc/pgx/pgproto3/notification_response.go deleted file mode 100644 index b14007b..0000000 --- a/vendor/github.com/jackc/pgx/pgproto3/notification_response.go +++ /dev/null @@ -1,67 +0,0 @@ -package pgproto3 - -import ( - "bytes" - "encoding/binary" - "encoding/json" - - "github.com/jackc/pgx/pgio" -) - -type NotificationResponse struct { - PID uint32 - Channel string - Payload string -} - -func (*NotificationResponse) Backend() {} - -func (dst *NotificationResponse) Decode(src []byte) error { - buf := bytes.NewBuffer(src) - - pid := binary.BigEndian.Uint32(buf.Next(4)) - - b, err := buf.ReadBytes(0) - if err != nil { - return err - } - channel := string(b[:len(b)-1]) - - b, err = buf.ReadBytes(0) - if err != nil { - return err - } - payload := string(b[:len(b)-1]) - - *dst = NotificationResponse{PID: pid, Channel: channel, Payload: payload} - return nil -} - -func (src *NotificationResponse) Encode(dst []byte) []byte { - dst = append(dst, 'A') - sp := len(dst) - dst = pgio.AppendInt32(dst, -1) - - dst = append(dst, src.Channel...) - dst = append(dst, 0) - dst = append(dst, src.Payload...) - dst = append(dst, 0) - - pgio.SetInt32(dst[sp:], int32(len(dst[sp:]))) - - return dst -} - -func (src *NotificationResponse) MarshalJSON() ([]byte, error) { - return json.Marshal(struct { - Type string - PID uint32 - Channel string - Payload string - }{ - Type: "NotificationResponse", - PID: src.PID, - Channel: src.Channel, - Payload: src.Payload, - }) -} diff --git a/vendor/github.com/jackc/pgx/pgproto3/parameter_description.go b/vendor/github.com/jackc/pgx/pgproto3/parameter_description.go deleted file mode 100644 index 1fa3c92..0000000 --- a/vendor/github.com/jackc/pgx/pgproto3/parameter_description.go +++ /dev/null @@ -1,61 +0,0 @@ -package pgproto3 - -import ( - "bytes" - "encoding/binary" - "encoding/json" - - "github.com/jackc/pgx/pgio" -) - -type ParameterDescription struct { - ParameterOIDs []uint32 -} - -func (*ParameterDescription) Backend() {} - -func (dst *ParameterDescription) Decode(src []byte) error { - buf := bytes.NewBuffer(src) - - if buf.Len() < 2 { - return &invalidMessageFormatErr{messageType: "ParameterDescription"} - } - - // Reported parameter count will be incorrect when number of args is greater than uint16 - buf.Next(2) - // Instead infer parameter count by remaining size of message - parameterCount := buf.Len() / 4 - - *dst = ParameterDescription{ParameterOIDs: make([]uint32, parameterCount)} - - for i := 0; i < parameterCount; i++ { - dst.ParameterOIDs[i] = binary.BigEndian.Uint32(buf.Next(4)) - } - - return nil -} - -func (src *ParameterDescription) Encode(dst []byte) []byte { - dst = append(dst, 't') - sp := len(dst) - dst = pgio.AppendInt32(dst, -1) - - dst = pgio.AppendUint16(dst, uint16(len(src.ParameterOIDs))) - for _, oid := range src.ParameterOIDs { - dst = pgio.AppendUint32(dst, oid) - } - - pgio.SetInt32(dst[sp:], int32(len(dst[sp:]))) - - return dst -} - -func (src *ParameterDescription) MarshalJSON() ([]byte, error) { - return json.Marshal(struct { - Type string - ParameterOIDs []uint32 - }{ - Type: "ParameterDescription", - ParameterOIDs: src.ParameterOIDs, - }) -} diff --git a/vendor/github.com/jackc/pgx/pgproto3/parameter_status.go b/vendor/github.com/jackc/pgx/pgproto3/parameter_status.go deleted file mode 100644 index b3bac33..0000000 --- a/vendor/github.com/jackc/pgx/pgproto3/parameter_status.go +++ /dev/null @@ -1,61 +0,0 @@ -package pgproto3 - -import ( - "bytes" - "encoding/json" - - "github.com/jackc/pgx/pgio" -) - -type ParameterStatus struct { - Name string - Value string -} - -func (*ParameterStatus) Backend() {} - -func (dst *ParameterStatus) Decode(src []byte) error { - buf := bytes.NewBuffer(src) - - b, err := buf.ReadBytes(0) - if err != nil { - return err - } - name := string(b[:len(b)-1]) - - b, err = buf.ReadBytes(0) - if err != nil { - return err - } - value := string(b[:len(b)-1]) - - *dst = ParameterStatus{Name: name, Value: value} - return nil -} - -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) - - pgio.SetInt32(dst[sp:], int32(len(dst[sp:]))) - - return dst -} - -func (ps *ParameterStatus) MarshalJSON() ([]byte, error) { - return json.Marshal(struct { - Type string - Name string - Value string - }{ - Type: "ParameterStatus", - Name: ps.Name, - Value: ps.Value, - }) -} diff --git a/vendor/github.com/jackc/pgx/pgproto3/parse.go b/vendor/github.com/jackc/pgx/pgproto3/parse.go deleted file mode 100644 index ca4834c..0000000 --- a/vendor/github.com/jackc/pgx/pgproto3/parse.go +++ /dev/null @@ -1,83 +0,0 @@ -package pgproto3 - -import ( - "bytes" - "encoding/binary" - "encoding/json" - - "github.com/jackc/pgx/pgio" -) - -type Parse struct { - Name string - Query string - ParameterOIDs []uint32 -} - -func (*Parse) Frontend() {} - -func (dst *Parse) Decode(src []byte) error { - *dst = Parse{} - - buf := bytes.NewBuffer(src) - - b, err := buf.ReadBytes(0) - if err != nil { - return err - } - dst.Name = string(b[:len(b)-1]) - - b, err = buf.ReadBytes(0) - if err != nil { - return err - } - dst.Query = string(b[:len(b)-1]) - - if buf.Len() < 2 { - return &invalidMessageFormatErr{messageType: "Parse"} - } - parameterOIDCount := int(binary.BigEndian.Uint16(buf.Next(2))) - - for i := 0; i < parameterOIDCount; i++ { - if buf.Len() < 4 { - return &invalidMessageFormatErr{messageType: "Parse"} - } - dst.ParameterOIDs = append(dst.ParameterOIDs, binary.BigEndian.Uint32(buf.Next(4))) - } - - return nil -} - -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) - - dst = pgio.AppendUint16(dst, uint16(len(src.ParameterOIDs))) - for _, oid := range src.ParameterOIDs { - dst = pgio.AppendUint32(dst, oid) - } - - pgio.SetInt32(dst[sp:], int32(len(dst[sp:]))) - - return dst -} - -func (src *Parse) MarshalJSON() ([]byte, error) { - return json.Marshal(struct { - Type string - Name string - Query string - ParameterOIDs []uint32 - }{ - Type: "Parse", - Name: src.Name, - Query: src.Query, - ParameterOIDs: src.ParameterOIDs, - }) -} diff --git a/vendor/github.com/jackc/pgx/pgproto3/parse_complete.go b/vendor/github.com/jackc/pgx/pgproto3/parse_complete.go deleted file mode 100644 index 462a89b..0000000 --- a/vendor/github.com/jackc/pgx/pgproto3/parse_complete.go +++ /dev/null @@ -1,29 +0,0 @@ -package pgproto3 - -import ( - "encoding/json" -) - -type ParseComplete struct{} - -func (*ParseComplete) Backend() {} - -func (dst *ParseComplete) Decode(src []byte) error { - if len(src) != 0 { - return &invalidMessageLenErr{messageType: "ParseComplete", expectedLen: 0, actualLen: len(src)} - } - - return nil -} - -func (src *ParseComplete) Encode(dst []byte) []byte { - return append(dst, '1', 0, 0, 0, 4) -} - -func (src *ParseComplete) MarshalJSON() ([]byte, error) { - return json.Marshal(struct { - Type string - }{ - Type: "ParseComplete", - }) -} diff --git a/vendor/github.com/jackc/pgx/pgproto3/password_message.go b/vendor/github.com/jackc/pgx/pgproto3/password_message.go deleted file mode 100644 index 2ad3fe4..0000000 --- a/vendor/github.com/jackc/pgx/pgproto3/password_message.go +++ /dev/null @@ -1,46 +0,0 @@ -package pgproto3 - -import ( - "bytes" - "encoding/json" - - "github.com/jackc/pgx/pgio" -) - -type PasswordMessage struct { - Password string -} - -func (*PasswordMessage) Frontend() {} - -func (dst *PasswordMessage) Decode(src []byte) error { - buf := bytes.NewBuffer(src) - - b, err := buf.ReadBytes(0) - if err != nil { - return err - } - dst.Password = string(b[:len(b)-1]) - - return nil -} - -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 dst -} - -func (src *PasswordMessage) MarshalJSON() ([]byte, error) { - return json.Marshal(struct { - Type string - Password string - }{ - Type: "PasswordMessage", - Password: src.Password, - }) -} diff --git a/vendor/github.com/jackc/pgx/pgproto3/pgproto3.go b/vendor/github.com/jackc/pgx/pgproto3/pgproto3.go deleted file mode 100644 index fe7b085..0000000 --- a/vendor/github.com/jackc/pgx/pgproto3/pgproto3.go +++ /dev/null @@ -1,42 +0,0 @@ -package pgproto3 - -import "fmt" - -// Message is the interface implemented by an object that can decode and encode -// a particular PostgreSQL message. -type Message interface { - // Decode is allowed and expected to retain a reference to data after - // returning (unlike encoding.BinaryUnmarshaler). - Decode(data []byte) error - - // Encode appends itself to dst and returns the new buffer. - Encode(dst []byte) []byte -} - -type FrontendMessage interface { - Message - Frontend() // no-op method to distinguish frontend from backend methods -} - -type BackendMessage interface { - Message - Backend() // no-op method to distinguish frontend from backend methods -} - -type invalidMessageLenErr struct { - messageType string - expectedLen int - actualLen int -} - -func (e *invalidMessageLenErr) Error() string { - return fmt.Sprintf("%s body must have length of %d, but it is %d", e.messageType, e.expectedLen, e.actualLen) -} - -type invalidMessageFormatErr struct { - messageType string -} - -func (e *invalidMessageFormatErr) Error() string { - return fmt.Sprintf("%s body is invalid", e.messageType) -} diff --git a/vendor/github.com/jackc/pgx/pgproto3/query.go b/vendor/github.com/jackc/pgx/pgproto3/query.go deleted file mode 100644 index d80c0fb..0000000 --- a/vendor/github.com/jackc/pgx/pgproto3/query.go +++ /dev/null @@ -1,45 +0,0 @@ -package pgproto3 - -import ( - "bytes" - "encoding/json" - - "github.com/jackc/pgx/pgio" -) - -type Query struct { - String string -} - -func (*Query) Frontend() {} - -func (dst *Query) Decode(src []byte) error { - i := bytes.IndexByte(src, 0) - if i != len(src)-1 { - return &invalidMessageFormatErr{messageType: "Query"} - } - - dst.String = string(src[:i]) - - return nil -} - -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 dst -} - -func (src *Query) MarshalJSON() ([]byte, error) { - return json.Marshal(struct { - Type string - String string - }{ - Type: "Query", - String: src.String, - }) -} diff --git a/vendor/github.com/jackc/pgx/pgproto3/ready_for_query.go b/vendor/github.com/jackc/pgx/pgproto3/ready_for_query.go deleted file mode 100644 index 63b902b..0000000 --- a/vendor/github.com/jackc/pgx/pgproto3/ready_for_query.go +++ /dev/null @@ -1,35 +0,0 @@ -package pgproto3 - -import ( - "encoding/json" -) - -type ReadyForQuery struct { - TxStatus byte -} - -func (*ReadyForQuery) Backend() {} - -func (dst *ReadyForQuery) Decode(src []byte) error { - if len(src) != 1 { - return &invalidMessageLenErr{messageType: "ReadyForQuery", expectedLen: 1, actualLen: len(src)} - } - - dst.TxStatus = src[0] - - return nil -} - -func (src *ReadyForQuery) Encode(dst []byte) []byte { - return append(dst, 'Z', 0, 0, 0, 5, src.TxStatus) -} - -func (src *ReadyForQuery) MarshalJSON() ([]byte, error) { - return json.Marshal(struct { - Type string - TxStatus string - }{ - Type: "ReadyForQuery", - TxStatus: string(src.TxStatus), - }) -} diff --git a/vendor/github.com/jackc/pgx/pgproto3/row_description.go b/vendor/github.com/jackc/pgx/pgproto3/row_description.go deleted file mode 100644 index d0df11b..0000000 --- a/vendor/github.com/jackc/pgx/pgproto3/row_description.go +++ /dev/null @@ -1,100 +0,0 @@ -package pgproto3 - -import ( - "bytes" - "encoding/binary" - "encoding/json" - - "github.com/jackc/pgx/pgio" -) - -const ( - TextFormat = 0 - BinaryFormat = 1 -) - -type FieldDescription struct { - Name string - TableOID uint32 - TableAttributeNumber uint16 - DataTypeOID uint32 - DataTypeSize int16 - TypeModifier uint32 - Format int16 -} - -type RowDescription struct { - Fields []FieldDescription -} - -func (*RowDescription) Backend() {} - -func (dst *RowDescription) Decode(src []byte) error { - buf := bytes.NewBuffer(src) - - if buf.Len() < 2 { - return &invalidMessageFormatErr{messageType: "RowDescription"} - } - fieldCount := int(binary.BigEndian.Uint16(buf.Next(2))) - - *dst = RowDescription{Fields: make([]FieldDescription, fieldCount)} - - for i := 0; i < fieldCount; i++ { - var fd FieldDescription - bName, err := buf.ReadBytes(0) - if err != nil { - return err - } - fd.Name = string(bName[:len(bName)-1]) - - // Since buf.Next() doesn't return an error if we hit the end of the buffer - // check Len ahead of time - if buf.Len() < 18 { - return &invalidMessageFormatErr{messageType: "RowDescription"} - } - - fd.TableOID = binary.BigEndian.Uint32(buf.Next(4)) - fd.TableAttributeNumber = binary.BigEndian.Uint16(buf.Next(2)) - fd.DataTypeOID = binary.BigEndian.Uint32(buf.Next(4)) - fd.DataTypeSize = int16(binary.BigEndian.Uint16(buf.Next(2))) - fd.TypeModifier = binary.BigEndian.Uint32(buf.Next(4)) - fd.Format = int16(binary.BigEndian.Uint16(buf.Next(2))) - - dst.Fields[i] = fd - } - - return nil -} - -func (src *RowDescription) Encode(dst []byte) []byte { - dst = append(dst, 'T') - sp := len(dst) - dst = pgio.AppendInt32(dst, -1) - - dst = pgio.AppendUint16(dst, uint16(len(src.Fields))) - for _, fd := range src.Fields { - dst = append(dst, fd.Name...) - dst = append(dst, 0) - - dst = pgio.AppendUint32(dst, fd.TableOID) - dst = pgio.AppendUint16(dst, fd.TableAttributeNumber) - dst = pgio.AppendUint32(dst, fd.DataTypeOID) - dst = pgio.AppendInt16(dst, fd.DataTypeSize) - dst = pgio.AppendUint32(dst, fd.TypeModifier) - dst = pgio.AppendInt16(dst, fd.Format) - } - - pgio.SetInt32(dst[sp:], int32(len(dst[sp:]))) - - return dst -} - -func (src *RowDescription) MarshalJSON() ([]byte, error) { - return json.Marshal(struct { - Type string - Fields []FieldDescription - }{ - Type: "RowDescription", - Fields: src.Fields, - }) -} diff --git a/vendor/github.com/jackc/pgx/pgproto3/startup_message.go b/vendor/github.com/jackc/pgx/pgproto3/startup_message.go deleted file mode 100644 index 6c5d4f9..0000000 --- a/vendor/github.com/jackc/pgx/pgproto3/startup_message.go +++ /dev/null @@ -1,97 +0,0 @@ -package pgproto3 - -import ( - "bytes" - "encoding/binary" - "encoding/json" - - "github.com/jackc/pgx/pgio" - "github.com/pkg/errors" -) - -const ( - ProtocolVersionNumber = 196608 // 3.0 - sslRequestNumber = 80877103 -) - -type StartupMessage struct { - ProtocolVersion uint32 - Parameters map[string]string -} - -func (*StartupMessage) Frontend() {} - -func (dst *StartupMessage) Decode(src []byte) error { - if len(src) < 4 { - return errors.Errorf("startup message too short") - } - - dst.ProtocolVersion = binary.BigEndian.Uint32(src) - rp := 4 - - if dst.ProtocolVersion == sslRequestNumber { - return errors.Errorf("can't handle ssl connection request") - } - - if dst.ProtocolVersion != ProtocolVersionNumber { - return errors.Errorf("Bad startup message version number. Expected %d, got %d", ProtocolVersionNumber, dst.ProtocolVersion) - } - - dst.Parameters = make(map[string]string) - for { - idx := bytes.IndexByte(src[rp:], 0) - if idx < 0 { - 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: "StartupMesage"} - } - value := string(src[rp : rp+idx]) - rp += idx + 1 - - dst.Parameters[key] = value - - if len(src[rp:]) == 1 { - if src[rp] != 0 { - return errors.Errorf("Bad startup message last byte. Expected 0, got %d", src[rp]) - } - break - } - } - - return nil -} - -func (src *StartupMessage) Encode(dst []byte) []byte { - sp := len(dst) - dst = pgio.AppendInt32(dst, -1) - - dst = pgio.AppendUint32(dst, src.ProtocolVersion) - for k, v := range src.Parameters { - dst = append(dst, k...) - dst = append(dst, 0) - dst = append(dst, v...) - dst = append(dst, 0) - } - dst = append(dst, 0) - - pgio.SetInt32(dst[sp:], int32(len(dst[sp:]))) - - return dst -} - -func (src *StartupMessage) MarshalJSON() ([]byte, error) { - return json.Marshal(struct { - Type string - ProtocolVersion uint32 - Parameters map[string]string - }{ - Type: "StartupMessage", - ProtocolVersion: src.ProtocolVersion, - Parameters: src.Parameters, - }) -} diff --git a/vendor/github.com/jackc/pgx/pgproto3/sync.go b/vendor/github.com/jackc/pgx/pgproto3/sync.go deleted file mode 100644 index 85f4749..0000000 --- a/vendor/github.com/jackc/pgx/pgproto3/sync.go +++ /dev/null @@ -1,29 +0,0 @@ -package pgproto3 - -import ( - "encoding/json" -) - -type Sync struct{} - -func (*Sync) Frontend() {} - -func (dst *Sync) Decode(src []byte) error { - if len(src) != 0 { - return &invalidMessageLenErr{messageType: "Sync", expectedLen: 0, actualLen: len(src)} - } - - return nil -} - -func (src *Sync) Encode(dst []byte) []byte { - return append(dst, 'S', 0, 0, 0, 4) -} - -func (src *Sync) MarshalJSON() ([]byte, error) { - return json.Marshal(struct { - Type string - }{ - Type: "Sync", - }) -} diff --git a/vendor/github.com/jackc/pgx/pgproto3/terminate.go b/vendor/github.com/jackc/pgx/pgproto3/terminate.go deleted file mode 100644 index 0a3310d..0000000 --- a/vendor/github.com/jackc/pgx/pgproto3/terminate.go +++ /dev/null @@ -1,29 +0,0 @@ -package pgproto3 - -import ( - "encoding/json" -) - -type Terminate struct{} - -func (*Terminate) Frontend() {} - -func (dst *Terminate) Decode(src []byte) error { - if len(src) != 0 { - return &invalidMessageLenErr{messageType: "Terminate", expectedLen: 0, actualLen: len(src)} - } - - return nil -} - -func (src *Terminate) Encode(dst []byte) []byte { - return append(dst, 'X', 0, 0, 0, 4) -} - -func (src *Terminate) MarshalJSON() ([]byte, error) { - return json.Marshal(struct { - Type string - }{ - Type: "Terminate", - }) -} |
