2
0

Update pgproto3 to enable pgmock

This commit is contained in:
Jack Christensen
2017-05-06 08:48:40 -05:00
parent eb9fc6e7a5
commit 61d4386931
3 changed files with 130 additions and 4 deletions
+28 -2
View File
@@ -2,7 +2,6 @@ package pgproto3
import (
"encoding/binary"
"errors"
"fmt"
"io"
@@ -20,6 +19,7 @@ type Backend struct {
parse Parse
passwordMessage PasswordMessage
query Query
startupMessage StartupMessage
sync Sync
terminate Terminate
}
@@ -30,7 +30,33 @@ func NewBackend(r io.Reader, w io.Writer) (*Backend, error) {
}
func (b *Backend) Send(msg BackendMessage) error {
return errors.New("not implemented")
buf, err := msg.MarshalBinary()
if err != nil {
return nil
}
_, err = b.w.Write(buf)
return err
}
func (b *Backend) ReceiveStartupMessage() (*StartupMessage, error) {
buf, err := b.cr.Next(4)
if err != nil {
return nil, err
}
msgSize := int(binary.BigEndian.Uint32(buf) - 4)
buf, err = b.cr.Next(msgSize)
if err != nil {
return nil, err
}
err = b.startupMessage.Decode(buf)
if err != nil {
return nil, err
}
return &b.startupMessage, nil
}
func (b *Backend) Receive() (FrontendMessage, error) {