From 4acc0f54c6ba565535ed46a21891b9c9f377be11 Mon Sep 17 00:00:00 2001 From: Jack Christensen Date: Fri, 3 May 2019 14:07:55 -0500 Subject: [PATCH] Import fixes from pgx/pgproto3 Import and adapt commit: fbb8cce --- backend.go | 3 --- copy_fail.go | 19 +++++++++---------- copy_out_response.go | 2 ++ 3 files changed, 11 insertions(+), 13 deletions(-) diff --git a/backend.go b/backend.go index 7f11bc7f..1121c550 100644 --- a/backend.go +++ b/backend.go @@ -14,7 +14,6 @@ type Backend struct { // Frontend message flyweights bind Bind _close Close - copyFail CopyFail describe Describe execute Execute flush Flush @@ -81,8 +80,6 @@ func (b *Backend) Receive() (FrontendMessage, error) { msg = &b.describe case 'E': msg = &b.execute - case 'f': - msg = &b.copyFail case 'H': msg = &b.flush case 'P': diff --git a/copy_fail.go b/copy_fail.go index e086207a..eadffa9c 100644 --- a/copy_fail.go +++ b/copy_fail.go @@ -8,11 +8,10 @@ import ( ) type CopyFail struct { - Error string + Message string } -func (*CopyFail) Frontend() {} -func (*CopyFail) Backend() {} +func (*CopyFail) Backend() {} func (dst *CopyFail) Decode(src []byte) error { idx := bytes.IndexByte(src, 0) @@ -20,17 +19,17 @@ func (dst *CopyFail) Decode(src []byte) error { return &invalidMessageFormatErr{messageType: "CopyFail"} } - dst.Error = string(src[:idx]) + dst.Message = string(src[:idx]) return nil } func (src *CopyFail) Encode(dst []byte) []byte { - dst = append(dst, 'C') + dst = append(dst, 'f') sp := len(dst) dst = pgio.AppendInt32(dst, -1) - dst = append(dst, src.Error...) + dst = append(dst, src.Message...) dst = append(dst, 0) pgio.SetInt32(dst[sp:], int32(len(dst[sp:]))) @@ -40,10 +39,10 @@ func (src *CopyFail) Encode(dst []byte) []byte { func (src *CopyFail) MarshalJSON() ([]byte, error) { return json.Marshal(struct { - Type string - Error string + Type string + Message string }{ - Type: "CopyFail", - Error: src.Error, + Type: "CopyFail", + Message: src.Message, }) } diff --git a/copy_out_response.go b/copy_out_response.go index 01a64228..eb6fb50e 100644 --- a/copy_out_response.go +++ b/copy_out_response.go @@ -44,6 +44,8 @@ func (src *CopyOutResponse) Encode(dst []byte) []byte { sp := len(dst) dst = pgio.AppendInt32(dst, -1) + dst = append(dst, src.OverallFormat) + dst = pgio.AppendUint16(dst, uint16(len(src.ColumnFormatCodes))) for _, fc := range src.ColumnFormatCodes { dst = pgio.AppendUint16(dst, fc)