From 5f39bbaf35772562b62214493b9d56b9f59439f4 Mon Sep 17 00:00:00 2001 From: Murat Kabilov Date: Mon, 30 Jul 2018 17:29:26 +0200 Subject: [PATCH] Add *Conn. CopyFromTextual, CopyToTextual, which use textual format for copying data --- copy_done.go | 30 ++++++++++++++++++++++++++++++ frontend.go | 3 +++ 2 files changed, 33 insertions(+) create mode 100644 copy_done.go diff --git a/copy_done.go b/copy_done.go new file mode 100644 index 00000000..92481908 --- /dev/null +++ b/copy_done.go @@ -0,0 +1,30 @@ +package pgproto3 + +import ( + "encoding/json" +) + +type CopyDone struct { +} + +func (*CopyDone) Backend() {} + +func (dst *CopyDone) Decode(src []byte) error { + if len(src) != 0 { + return &invalidMessageLenErr{messageType: "CopyDone", expectedLen: 0, actualLen: len(src)} + } + + return nil +} + +func (src *CopyDone) Encode(dst []byte) []byte { + return append(dst, 'c', 0, 0, 0, 4) +} + +func (src *CopyDone) MarshalJSON() ([]byte, error) { + return json.Marshal(struct { + Type string + }{ + Type: "CopyDone", + }) +} diff --git a/frontend.go b/frontend.go index d803d362..d1541c74 100644 --- a/frontend.go +++ b/frontend.go @@ -22,6 +22,7 @@ type Frontend struct { copyData CopyData copyInResponse CopyInResponse copyOutResponse CopyOutResponse + copyDone CopyDone dataRow DataRow emptyQueryResponse EmptyQueryResponse errorResponse ErrorResponse @@ -72,6 +73,8 @@ func (b *Frontend) Receive() (BackendMessage, error) { msg = &b.closeComplete case 'A': msg = &b.notificationResponse + case 'c': + msg = &b.copyDone case 'C': msg = &b.commandComplete case 'd':