2
0

Refactor pgio and types to append buffers

This commit is contained in:
Jack Christensen
2017-05-02 20:38:26 -05:00
parent ee001a7cae
commit 6e64a0c867
78 changed files with 1551 additions and 2627 deletions
+12 -17
View File
@@ -3,7 +3,6 @@ package pgtype
import (
"database/sql/driver"
"fmt"
"io"
"strconv"
)
@@ -90,42 +89,38 @@ func (dst *Bool) DecodeBinary(ci *ConnInfo, src []byte) error {
return nil
}
func (src *Bool) EncodeText(ci *ConnInfo, w io.Writer) (bool, error) {
func (src *Bool) EncodeText(ci *ConnInfo, buf []byte) ([]byte, error) {
switch src.Status {
case Null:
return true, nil
return nil, nil
case Undefined:
return false, errUndefined
return nil, errUndefined
}
var buf []byte
if src.Bool {
buf = []byte{'t'}
buf = append(buf, 't')
} else {
buf = []byte{'f'}
buf = append(buf, 'f')
}
_, err := w.Write(buf)
return false, err
return buf, nil
}
func (src *Bool) EncodeBinary(ci *ConnInfo, w io.Writer) (bool, error) {
func (src *Bool) EncodeBinary(ci *ConnInfo, buf []byte) ([]byte, error) {
switch src.Status {
case Null:
return true, nil
return nil, nil
case Undefined:
return false, errUndefined
return nil, errUndefined
}
var buf []byte
if src.Bool {
buf = []byte{1}
buf = append(buf, 1)
} else {
buf = []byte{0}
buf = append(buf, 0)
}
_, err := w.Write(buf)
return false, err
return buf, nil
}
// Scan implements the database/sql Scanner interface.