From e40f08e1076338ada8017bc08b619bc1bfffebac Mon Sep 17 00:00:00 2001 From: Nick K Date: Fri, 4 Mar 2016 11:25:28 +0300 Subject: [PATCH] Added uint encoder/decoder --- values.go | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/values.go b/values.go index 662499d0..1b37c200 100644 --- a/values.go +++ b/values.go @@ -686,6 +686,26 @@ func Decode(vr *ValueReader, d interface{}) error { *v = decodeInt2(vr) case *int32: *v = decodeInt4(vr) + case *uint32: + switch vr.Type().DataType { + case Int2Oid: + *v = uint32(decodeInt2(vr)) + case Int4Oid: + *v = uint32(decodeInt4(vr)) + default: + return fmt.Errorf("Can't convert OID %v to uint32", vr.Type().DataType) + } + case *uint64: + switch vr.Type().DataType { + case Int2Oid: + *v = uint64(decodeInt2(vr)) + case Int4Oid: + *v = uint64(decodeInt4(vr)) + case Int8Oid: + *v = uint64(decodeInt8(vr)) + default: + return fmt.Errorf("Can't convert OID %v to uint64", vr.Type().DataType) + } case *Oid: *v = decodeOid(vr) case *string: @@ -1009,6 +1029,7 @@ func encodeUInt64(w *WriteBuf, oid Oid, value uint64) error { return fmt.Errorf("%d is larger than max int32 %d", value, math.MaxInt32) } case Int8Oid: + if value <= math.MaxInt64 { w.WriteInt32(8) w.WriteInt64(int64(value))