Fix output to include message size and add some docs
This commit is contained in:
@@ -1,4 +1,11 @@
|
|||||||
// Package pgproto3 is a encoder and decoder of the PostgreSQL wire protocol version 3.
|
// Package pgproto3 is a encoder and decoder of the PostgreSQL wire protocol version 3.
|
||||||
//
|
//
|
||||||
|
// The primary interfaces are Frontend and Backend. They correspond to a client and server respectively. Messages are
|
||||||
|
// sent with Send (or a specialized Send variant). Messages are automatically bufferred to minimize small writes. Call
|
||||||
|
// Flush to ensure a message has actually been sent.
|
||||||
|
//
|
||||||
|
// The Trace method of Frontend and Backend can be used to examine the wire-level message traffic. It outputs in a
|
||||||
|
// similar format to the PQtrace function in libpq.
|
||||||
|
//
|
||||||
// See https://www.postgresql.org/docs/current/protocol-message-formats.html for meanings of the different messages.
|
// See https://www.postgresql.org/docs/current/protocol-message-formats.html for meanings of the different messages.
|
||||||
package pgproto3
|
package pgproto3
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import (
|
|||||||
"bytes"
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
@@ -399,6 +400,8 @@ func (t *tracer) beginTrace(sender byte, encodedLen int32, msgType string) {
|
|||||||
t.buf.WriteByte(sender)
|
t.buf.WriteByte(sender)
|
||||||
t.buf.WriteByte('\t')
|
t.buf.WriteByte('\t')
|
||||||
t.buf.WriteString(msgType)
|
t.buf.WriteString(msgType)
|
||||||
|
t.buf.WriteByte('\t')
|
||||||
|
t.buf.WriteString(strconv.FormatInt(int64(encodedLen), 10))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *tracer) finishTrace() {
|
func (t *tracer) finishTrace() {
|
||||||
|
|||||||
+32
-32
@@ -40,38 +40,38 @@ func TestTrace(t *testing.T) {
|
|||||||
result := conn.ExecParams(ctx, "select n from generate_series(1,5) n", nil, nil, nil, nil).Read()
|
result := conn.ExecParams(ctx, "select n from generate_series(1,5) n", nil, nil, nil, nil).Read()
|
||||||
require.NoError(t, result.Err)
|
require.NoError(t, result.Err)
|
||||||
|
|
||||||
expected := `F StartupMessage
|
expected := `F StartupMessage 37
|
||||||
B AuthenticationOk
|
B AuthenticationOk 9
|
||||||
B ParameterStatus "application_name" ""
|
B ParameterStatus 23 "application_name" ""
|
||||||
B ParameterStatus "client_encoding" "UTF8"
|
B ParameterStatus 26 "client_encoding" "UTF8"
|
||||||
B ParameterStatus "DateStyle" "ISO, MDY"
|
B ParameterStatus 24 "DateStyle" "ISO, MDY"
|
||||||
B ParameterStatus "default_transaction_read_only" "off"
|
B ParameterStatus 39 "default_transaction_read_only" "off"
|
||||||
B ParameterStatus "in_hot_standby" "off"
|
B ParameterStatus 24 "in_hot_standby" "off"
|
||||||
B ParameterStatus "integer_datetimes" "on"
|
B ParameterStatus 26 "integer_datetimes" "on"
|
||||||
B ParameterStatus "IntervalStyle" "postgres"
|
B ParameterStatus 28 "IntervalStyle" "postgres"
|
||||||
B ParameterStatus "is_superuser" "on"
|
B ParameterStatus 21 "is_superuser" "on"
|
||||||
B ParameterStatus "server_encoding" "UTF8"
|
B ParameterStatus 26 "server_encoding" "UTF8"
|
||||||
B ParameterStatus "server_version" "14.3"
|
B ParameterStatus 25 "server_version" "14.3"
|
||||||
B ParameterStatus "session_authorization" "jack"
|
B ParameterStatus 32 "session_authorization" "jack"
|
||||||
B ParameterStatus "standard_conforming_strings" "on"
|
B ParameterStatus 36 "standard_conforming_strings" "on"
|
||||||
B ParameterStatus "TimeZone" "America/Chicago"
|
B ParameterStatus 30 "TimeZone" "America/Chicago"
|
||||||
B BackendKeyData NNNN NNNN
|
B BackendKeyData 13 NNNN NNNN
|
||||||
B ReadyForQuery I
|
B ReadyForQuery 6 I
|
||||||
F Parse "" "select n from generate_series(1,5) n" 0
|
F Parse 45 "" "select n from generate_series(1,5) n" 0
|
||||||
F Bind "" "" 0 0 0
|
F Bind 13 "" "" 0 0 0
|
||||||
F Describe P ""
|
F Describe 7 P ""
|
||||||
F Execute "" 0
|
F Execute 10 "" 0
|
||||||
F Sync
|
F Sync 5
|
||||||
B ParseComplete
|
B ParseComplete 5
|
||||||
B BindComplete
|
B BindComplete 5
|
||||||
B RowDescription 1 "n" 0 0 23 4 -1 0
|
B RowDescription 27 1 "n" 0 0 23 4 -1 0
|
||||||
B DataRow 1 1 '1'
|
B DataRow 12 1 1 '1'
|
||||||
B DataRow 1 1 '2'
|
B DataRow 12 1 1 '2'
|
||||||
B DataRow 1 1 '3'
|
B DataRow 12 1 1 '3'
|
||||||
B DataRow 1 1 '4'
|
B DataRow 12 1 1 '4'
|
||||||
B DataRow 1 1 '5'
|
B DataRow 12 1 1 '5'
|
||||||
B CommandComplete "SELECT 5"
|
B CommandComplete 14 "SELECT 5"
|
||||||
B ReadyForQuery I
|
B ReadyForQuery 6 I
|
||||||
`
|
`
|
||||||
|
|
||||||
require.Equal(t, expected, traceOutput.String())
|
require.Equal(t, expected, traceOutput.String())
|
||||||
|
|||||||
Reference in New Issue
Block a user