2
0

Introduce pgproto3 package

pgproto3 will wrap the message encoding and decoding for the PostgreSQL
frontend/backend protocol version 3.
This commit is contained in:
Jack Christensen
2017-04-29 10:02:38 -05:00
parent e305ece410
commit f04c58338b
34 changed files with 1676 additions and 262 deletions
+10 -12
View File
@@ -3,6 +3,7 @@ package pgx
import (
"encoding/binary"
"github.com/jackc/pgx/pgproto3"
"github.com/jackc/pgx/pgtype"
)
@@ -71,23 +72,20 @@ func (f *fastpath) Call(oid pgtype.Oid, args []fpArg) (res []byte, err error) {
}
for {
var t byte
var r *msgReader
t, r, err = f.cn.rxMsg()
msg, err := f.cn.rxMsg()
if err != nil {
return nil, err
}
switch t {
case 'V': // FunctionCallResponse
data := r.readBytes(r.readInt32())
res = make([]byte, len(data))
copy(res, data)
case 'Z': // Ready for query
f.cn.rxReadyForQuery(r)
switch msg := msg.(type) {
case *pgproto3.FunctionCallResponse:
res = make([]byte, len(msg.Result))
copy(res, msg.Result)
case *pgproto3.ReadyForQuery:
f.cn.rxReadyForQuery(msg)
// done
return
return res, err
default:
if err := f.cn.processContextFreeMsg(t, r); err != nil {
if err := f.cn.processContextFreeMsg(msg); err != nil {
return nil, err
}
}