2
0

Import fixes from pgx/pgproto3

Import and adapt commit: fbb8cce
This commit is contained in:
Jack Christensen
2019-05-03 14:07:55 -05:00
parent c116219b62
commit 4acc0f54c6
3 changed files with 11 additions and 13 deletions
-3
View File
@@ -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':
+9 -10
View File
@@ -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,
})
}
+2
View File
@@ -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)