Use message names matching PostgreSQL docs
This commit is contained in:
+7
-4
@@ -1,26 +1,29 @@
|
|||||||
package pqx
|
package pqx
|
||||||
|
|
||||||
import (
|
import (
|
||||||
// "encoding/binary"
|
"encoding/binary"
|
||||||
"net"
|
"net"
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestXxx(t *testing.T) {
|
func TestXxx(t *testing.T) {
|
||||||
conn, err := net.Dial("tcp", "localhost:5432")
|
conn, err := net.Dial("unix", "/private/tmp/.s.PGSQL.5432")
|
||||||
|
// conn, err := net.Dial("tcp", "localhost:5432")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// handle error
|
// handle error
|
||||||
}
|
}
|
||||||
|
|
||||||
msg := newStartupMsg()
|
msg := newStartupMessage()
|
||||||
msg.options["user"] = "jack"
|
msg.options["user"] = "jack"
|
||||||
|
|
||||||
msg.WriteTo(conn)
|
msg.WriteTo(conn)
|
||||||
|
|
||||||
|
|
||||||
buf := make([]byte, 128)
|
buf := make([]byte, 512)
|
||||||
|
|
||||||
num, _ := conn.Read(buf)
|
num, _ := conn.Read(buf)
|
||||||
println(string(buf[0:1]))
|
println(string(buf[0:1]))
|
||||||
|
println(binary.BigEndian.Uint32(buf[1:5]))
|
||||||
|
println(binary.BigEndian.Uint32(buf[5:9]))
|
||||||
println(num)
|
println(num)
|
||||||
}
|
}
|
||||||
|
|||||||
+5
-5
@@ -9,15 +9,15 @@ const (
|
|||||||
protocolVersionNumber = 196608 // 3.0
|
protocolVersionNumber = 196608 // 3.0
|
||||||
)
|
)
|
||||||
|
|
||||||
type startupMsg struct {
|
type startupMessage struct {
|
||||||
options map[string] string
|
options map[string] string
|
||||||
}
|
}
|
||||||
|
|
||||||
func newStartupMsg() *startupMsg {
|
func newStartupMessage() *startupMessage {
|
||||||
return &startupMsg{map[string] string{}}
|
return &startupMessage{map[string] string{}}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *startupMsg) WriteTo(w io.Writer) (n int64, err error) {
|
func (self *startupMessage) WriteTo(w io.Writer) (n int64, err error) {
|
||||||
buf := make([]byte, 8, 128)
|
buf := make([]byte, 8, 128)
|
||||||
binary.BigEndian.PutUint32(buf[4:8], uint32(protocolVersionNumber))
|
binary.BigEndian.PutUint32(buf[4:8], uint32(protocolVersionNumber))
|
||||||
for key, value := range self.options {
|
for key, value := range self.options {
|
||||||
@@ -32,4 +32,4 @@ func (self *startupMsg) WriteTo(w io.Writer) (n int64, err error) {
|
|||||||
var n32 int
|
var n32 int
|
||||||
n32, err = w.Write(buf)
|
n32, err = w.Write(buf)
|
||||||
return int64(n32), err
|
return int64(n32), err
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user