Makes Oid casting consistent

Also fixes uint32 encoding in a few places.
This commit is contained in:
Manni Wood 2016-09-03 18:19:33 -04:00
parent 7dbfd4bf4b
commit 99bfc154f0
2 changed files with 11 additions and 5 deletions

View File

@ -138,6 +138,12 @@ func (wb *WriteBuf) WriteInt32(n int32) {
wb.buf = append(wb.buf, b...)
}
func (wb *WriteBuf) WriteUint32(n uint32) {
b := make([]byte, 4)
binary.BigEndian.PutUint32(b, n)
wb.buf = append(wb.buf, b...)
}
func (wb *WriteBuf) WriteInt64(n int64) {
b := make([]byte, 8)
binary.BigEndian.PutUint64(b, uint64(n))

View File

@ -1299,19 +1299,19 @@ func decodeInt4(vr *ValueReader) int32 {
func decodeOid(vr *ValueReader) Oid {
if vr.Len() == -1 {
vr.Fatal(ProtocolError("Cannot decode null into Oid"))
return 0
return Oid(0)
}
if vr.Type().DataType != OidOid {
vr.Fatal(ProtocolError(fmt.Sprintf("Cannot decode oid %v into pgx.Oid", vr.Type().DataType)))
return 0
return Oid(0)
}
// Oid needs to decode text format because it is used in loadPgTypes
switch vr.Type().FormatCode {
case TextFormatCode:
s := vr.ReadString(vr.Len())
n, err := strconv.ParseInt(s, 10, 32)
n, err := strconv.ParseUint(s, 10, 32)
if err != nil {
vr.Fatal(ProtocolError(fmt.Sprintf("Received invalid Oid: %v", s)))
}
@ -1319,7 +1319,7 @@ func decodeOid(vr *ValueReader) Oid {
case BinaryFormatCode:
if vr.Len() != 4 {
vr.Fatal(ProtocolError(fmt.Sprintf("Received an invalid size for an Oid: %d", vr.Len())))
return 0
return Oid(0)
}
return Oid(vr.ReadInt32())
default:
@ -1334,7 +1334,7 @@ func encodeOid(w *WriteBuf, oid Oid, value Oid) error {
}
w.WriteInt32(4)
w.WriteInt32(int32(value))
w.WriteUint32(uint32(value))
return nil
}