From 12ac0c33b826d29ea5b3375d70771e42ac758538 Mon Sep 17 00:00:00 2001 From: Jack Christensen Date: Sat, 4 Mar 2017 21:23:57 -0600 Subject: [PATCH] Remove unused array code from pgx --- values.go | 555 ------------------------------------------------------ 1 file changed, 555 deletions(-) diff --git a/values.go b/values.go index c011c8cf..f050726e 100644 --- a/values.go +++ b/values.go @@ -2021,65 +2021,6 @@ func decode1dArrayHeader(vr *ValueReader) (length int32, err error) { return length, nil } -func decodeBoolArray(vr *ValueReader) []bool { - if vr.Len() == -1 { - return nil - } - - if vr.Type().DataType != BoolArrayOID { - vr.Fatal(ProtocolError(fmt.Sprintf("Cannot decode oid %v into []bool", vr.Type().DataType))) - return nil - } - - if vr.Type().FormatCode != BinaryFormatCode { - vr.Fatal(ProtocolError(fmt.Sprintf("Unknown field description format code: %v", vr.Type().FormatCode))) - return nil - } - - numElems, err := decode1dArrayHeader(vr) - if err != nil { - vr.Fatal(err) - return nil - } - - a := make([]bool, int(numElems)) - for i := 0; i < len(a); i++ { - elSize := vr.ReadInt32() - switch elSize { - case 1: - if vr.ReadByte() == 1 { - a[i] = true - } - case -1: - vr.Fatal(ProtocolError("Cannot decode null element")) - return nil - default: - vr.Fatal(ProtocolError(fmt.Sprintf("Received an invalid size for an bool element: %d", elSize))) - return nil - } - } - - return a -} - -func encodeBoolSlice(w *WriteBuf, oid OID, slice []bool) error { - if oid != BoolArrayOID { - return fmt.Errorf("cannot encode Go %s into oid %d", "[]bool", oid) - } - - encodeArrayHeader(w, BoolOID, len(slice), 5) - for _, v := range slice { - w.WriteInt32(1) - var b byte - if v { - b = 1 - } - w.WriteByte(b) - } - - return nil -} - func decodeByteaArray(vr *ValueReader) [][]byte { if vr.Len() == -1 { return nil @@ -2141,430 +2082,6 @@ func encodeByteSliceSlice(w *WriteBuf, oid OID, value [][]byte) error { return nil } -func decodeInt2Array(vr *ValueReader) []int16 { - if vr.Type().DataType != Int2ArrayOID { - vr.Fatal(ProtocolError(fmt.Sprintf("Cannot decode oid %v into []int16", vr.Type().DataType))) - return nil - } - - vr.err = errRewoundLen - - var a pgtype.Int2Array - var err error - switch vr.Type().FormatCode { - case TextFormatCode: - err = a.DecodeText(&valueReader2{vr}) - case BinaryFormatCode: - err = a.DecodeBinary(&valueReader2{vr}) - default: - vr.Fatal(ProtocolError(fmt.Sprintf("Unknown field description format code: %v", vr.Type().FormatCode))) - return nil - } - - if err != nil { - vr.Fatal(err) - return nil - } - - if a.Status == pgtype.Null { - return nil - } - - rawArray := make([]int16, len(a.Elements)) - for i := range a.Elements { - if a.Elements[i].Status == pgtype.Present { - rawArray[i] = a.Elements[i].Int - } else { - vr.Fatal(ProtocolError("Cannot decode null element")) - return nil - } - } - - return rawArray -} - -func decodeInt2ArrayToUInt(vr *ValueReader) []uint16 { - if vr.Len() == -1 { - return nil - } - - if vr.Type().DataType != Int2ArrayOID { - vr.Fatal(ProtocolError(fmt.Sprintf("Cannot decode oid %v into []uint16", vr.Type().DataType))) - return nil - } - - if vr.Type().FormatCode != BinaryFormatCode { - vr.Fatal(ProtocolError(fmt.Sprintf("Unknown field description format code: %v", vr.Type().FormatCode))) - return nil - } - - numElems, err := decode1dArrayHeader(vr) - if err != nil { - vr.Fatal(err) - return nil - } - - a := make([]uint16, int(numElems)) - for i := 0; i < len(a); i++ { - elSize := vr.ReadInt32() - switch elSize { - case 2: - tmp := vr.ReadInt16() - if tmp < 0 { - vr.Fatal(ProtocolError(fmt.Sprintf("%d is less than zero for uint16", tmp))) - return nil - } - a[i] = uint16(tmp) - case -1: - vr.Fatal(ProtocolError("Cannot decode null element")) - return nil - default: - vr.Fatal(ProtocolError(fmt.Sprintf("Received an invalid size for an int2 element: %d", elSize))) - return nil - } - } - - return a -} - -func decodeInt4Array(vr *ValueReader) []int32 { - if vr.Len() == -1 { - return nil - } - - if vr.Type().DataType != Int4ArrayOID { - vr.Fatal(ProtocolError(fmt.Sprintf("Cannot decode oid %v into []int32", vr.Type().DataType))) - return nil - } - - if vr.Type().FormatCode != BinaryFormatCode { - vr.Fatal(ProtocolError(fmt.Sprintf("Unknown field description format code: %v", vr.Type().FormatCode))) - return nil - } - - numElems, err := decode1dArrayHeader(vr) - if err != nil { - vr.Fatal(err) - return nil - } - - a := make([]int32, int(numElems)) - for i := 0; i < len(a); i++ { - elSize := vr.ReadInt32() - switch elSize { - case 4: - a[i] = vr.ReadInt32() - case -1: - vr.Fatal(ProtocolError("Cannot decode null element")) - return nil - default: - vr.Fatal(ProtocolError(fmt.Sprintf("Received an invalid size for an int4 element: %d", elSize))) - return nil - } - } - - return a -} - -func decodeInt4ArrayToUInt(vr *ValueReader) []uint32 { - if vr.Len() == -1 { - return nil - } - - if vr.Type().DataType != Int4ArrayOID { - vr.Fatal(ProtocolError(fmt.Sprintf("Cannot decode oid %v into []uint32", vr.Type().DataType))) - return nil - } - - if vr.Type().FormatCode != BinaryFormatCode { - vr.Fatal(ProtocolError(fmt.Sprintf("Unknown field description format code: %v", vr.Type().FormatCode))) - return nil - } - - numElems, err := decode1dArrayHeader(vr) - if err != nil { - vr.Fatal(err) - return nil - } - - a := make([]uint32, int(numElems)) - for i := 0; i < len(a); i++ { - elSize := vr.ReadInt32() - switch elSize { - case 4: - tmp := vr.ReadInt32() - if tmp < 0 { - vr.Fatal(ProtocolError(fmt.Sprintf("%d is less than zero for uint32", tmp))) - return nil - } - a[i] = uint32(tmp) - case -1: - vr.Fatal(ProtocolError("Cannot decode null element")) - return nil - default: - vr.Fatal(ProtocolError(fmt.Sprintf("Received an invalid size for an int4 element: %d", elSize))) - return nil - } - } - - return a -} - -func encodeInt32Slice(w *WriteBuf, oid OID, slice []int32) error { - if oid != Int4ArrayOID { - return fmt.Errorf("cannot encode Go %s into oid %d", "[]int32", oid) - } - - encodeArrayHeader(w, Int4OID, len(slice), 8) - for _, v := range slice { - w.WriteInt32(4) - w.WriteInt32(v) - } - - return nil -} - -func encodeUInt32Slice(w *WriteBuf, oid OID, slice []uint32) error { - if oid != Int4ArrayOID { - return fmt.Errorf("cannot encode Go %s into oid %d", "[]uint32", oid) - } - - encodeArrayHeader(w, Int4OID, len(slice), 8) - for _, v := range slice { - if v <= math.MaxInt32 { - w.WriteInt32(4) - w.WriteInt32(int32(v)) - } else { - return fmt.Errorf("%d is greater than max integer %d", v, math.MaxInt32) - } - } - - return nil -} - -func decodeInt8Array(vr *ValueReader) []int64 { - if vr.Len() == -1 { - return nil - } - - if vr.Type().DataType != Int8ArrayOID { - vr.Fatal(ProtocolError(fmt.Sprintf("Cannot decode oid %v into []int64", vr.Type().DataType))) - return nil - } - - if vr.Type().FormatCode != BinaryFormatCode { - vr.Fatal(ProtocolError(fmt.Sprintf("Unknown field description format code: %v", vr.Type().FormatCode))) - return nil - } - - numElems, err := decode1dArrayHeader(vr) - if err != nil { - vr.Fatal(err) - return nil - } - - a := make([]int64, int(numElems)) - for i := 0; i < len(a); i++ { - elSize := vr.ReadInt32() - switch elSize { - case 8: - a[i] = vr.ReadInt64() - case -1: - vr.Fatal(ProtocolError("Cannot decode null element")) - return nil - default: - vr.Fatal(ProtocolError(fmt.Sprintf("Received an invalid size for an int8 element: %d", elSize))) - return nil - } - } - - return a -} - -func decodeInt8ArrayToUInt(vr *ValueReader) []uint64 { - if vr.Len() == -1 { - return nil - } - - if vr.Type().DataType != Int8ArrayOID { - vr.Fatal(ProtocolError(fmt.Sprintf("Cannot decode oid %v into []uint64", vr.Type().DataType))) - return nil - } - - if vr.Type().FormatCode != BinaryFormatCode { - vr.Fatal(ProtocolError(fmt.Sprintf("Unknown field description format code: %v", vr.Type().FormatCode))) - return nil - } - - numElems, err := decode1dArrayHeader(vr) - if err != nil { - vr.Fatal(err) - return nil - } - - a := make([]uint64, int(numElems)) - for i := 0; i < len(a); i++ { - elSize := vr.ReadInt32() - switch elSize { - case 8: - tmp := vr.ReadInt64() - if tmp < 0 { - vr.Fatal(ProtocolError(fmt.Sprintf("%d is less than zero for uint64", tmp))) - return nil - } - a[i] = uint64(tmp) - case -1: - vr.Fatal(ProtocolError("Cannot decode null element")) - return nil - default: - vr.Fatal(ProtocolError(fmt.Sprintf("Received an invalid size for an int8 element: %d", elSize))) - return nil - } - } - - return a -} - -func encodeInt64Slice(w *WriteBuf, oid OID, slice []int64) error { - if oid != Int8ArrayOID { - return fmt.Errorf("cannot encode Go %s into oid %d", "[]int64", oid) - } - - encodeArrayHeader(w, Int8OID, len(slice), 12) - for _, v := range slice { - w.WriteInt32(8) - w.WriteInt64(v) - } - - return nil -} - -func encodeUInt64Slice(w *WriteBuf, oid OID, slice []uint64) error { - if oid != Int8ArrayOID { - return fmt.Errorf("cannot encode Go %s into oid %d", "[]uint64", oid) - } - - encodeArrayHeader(w, Int8OID, len(slice), 12) - for _, v := range slice { - if v <= math.MaxInt64 { - w.WriteInt32(8) - w.WriteInt64(int64(v)) - } else { - return fmt.Errorf("%d is greater than max bigint %d", v, int64(math.MaxInt64)) - } - } - - return nil -} - -func decodeFloat4Array(vr *ValueReader) []float32 { - if vr.Len() == -1 { - return nil - } - - if vr.Type().DataType != Float4ArrayOID { - vr.Fatal(ProtocolError(fmt.Sprintf("Cannot decode oid %v into []float32", vr.Type().DataType))) - return nil - } - - if vr.Type().FormatCode != BinaryFormatCode { - vr.Fatal(ProtocolError(fmt.Sprintf("Unknown field description format code: %v", vr.Type().FormatCode))) - return nil - } - - numElems, err := decode1dArrayHeader(vr) - if err != nil { - vr.Fatal(err) - return nil - } - - a := make([]float32, int(numElems)) - for i := 0; i < len(a); i++ { - elSize := vr.ReadInt32() - switch elSize { - case 4: - n := vr.ReadInt32() - a[i] = math.Float32frombits(uint32(n)) - case -1: - vr.Fatal(ProtocolError("Cannot decode null element")) - return nil - default: - vr.Fatal(ProtocolError(fmt.Sprintf("Received an invalid size for an float4 element: %d", elSize))) - return nil - } - } - - return a -} - -func encodeFloat32Slice(w *WriteBuf, oid OID, slice []float32) error { - if oid != Float4ArrayOID { - return fmt.Errorf("cannot encode Go %s into oid %d", "[]float32", oid) - } - - encodeArrayHeader(w, Float4OID, len(slice), 8) - for _, v := range slice { - w.WriteInt32(4) - w.WriteInt32(int32(math.Float32bits(v))) - } - - return nil -} - -func decodeFloat8Array(vr *ValueReader) []float64 { - if vr.Len() == -1 { - return nil - } - - if vr.Type().DataType != Float8ArrayOID { - vr.Fatal(ProtocolError(fmt.Sprintf("Cannot decode oid %v into []float64", vr.Type().DataType))) - return nil - } - - if vr.Type().FormatCode != BinaryFormatCode { - vr.Fatal(ProtocolError(fmt.Sprintf("Unknown field description format code: %v", vr.Type().FormatCode))) - return nil - } - - numElems, err := decode1dArrayHeader(vr) - if err != nil { - vr.Fatal(err) - return nil - } - - a := make([]float64, int(numElems)) - for i := 0; i < len(a); i++ { - elSize := vr.ReadInt32() - switch elSize { - case 8: - n := vr.ReadInt64() - a[i] = math.Float64frombits(uint64(n)) - case -1: - vr.Fatal(ProtocolError("Cannot decode null element")) - return nil - default: - vr.Fatal(ProtocolError(fmt.Sprintf("Received an invalid size for an float4 element: %d", elSize))) - return nil - } - } - - return a -} - -func encodeFloat64Slice(w *WriteBuf, oid OID, slice []float64) error { - if oid != Float8ArrayOID { - return fmt.Errorf("cannot encode Go %s into oid %d", "[]float64", oid) - } - - encodeArrayHeader(w, Float8OID, len(slice), 12) - for _, v := range slice { - w.WriteInt32(8) - w.WriteInt64(int64(math.Float64bits(v))) - } - - return nil -} - // escapeAclItem escapes an AclItem before it is added to // its aclitem[] string representation. The PostgreSQL aclitem // datatype itself can need escapes because it follows the @@ -2768,75 +2285,3 @@ func decodeAclItemArray(vr *ValueReader) []AclItem { } return aclItems } - -func decodeTimestampArray(vr *ValueReader) []time.Time { - if vr.Len() == -1 { - return nil - } - - if vr.Type().DataType != TimestampArrayOID && vr.Type().DataType != TimestampTzArrayOID { - vr.Fatal(ProtocolError(fmt.Sprintf("Cannot decode oid %v into []time.Time", vr.Type().DataType))) - return nil - } - - if vr.Type().FormatCode != BinaryFormatCode { - vr.Fatal(ProtocolError(fmt.Sprintf("Unknown field description format code: %v", vr.Type().FormatCode))) - return nil - } - - numElems, err := decode1dArrayHeader(vr) - if err != nil { - vr.Fatal(err) - return nil - } - - a := make([]time.Time, int(numElems)) - for i := 0; i < len(a); i++ { - elSize := vr.ReadInt32() - switch elSize { - case 8: - microsecSinceY2K := vr.ReadInt64() - microsecSinceUnixEpoch := microsecFromUnixEpochToY2K + microsecSinceY2K - a[i] = time.Unix(microsecSinceUnixEpoch/1000000, (microsecSinceUnixEpoch%1000000)*1000) - case -1: - vr.Fatal(ProtocolError("Cannot decode null element")) - return nil - default: - vr.Fatal(ProtocolError(fmt.Sprintf("Received an invalid size for an time.Time element: %d", elSize))) - return nil - } - } - - return a -} - -func encodeTimeSlice(w *WriteBuf, oid OID, slice []time.Time) error { - var elOID OID - switch oid { - case TimestampArrayOID: - elOID = TimestampOID - case TimestampTzArrayOID: - elOID = TimestampTzOID - default: - return fmt.Errorf("cannot encode Go %s into oid %d", "[]time.Time", oid) - } - - encodeArrayHeader(w, int(elOID), len(slice), 12) - for _, t := range slice { - w.WriteInt32(8) - microsecSinceUnixEpoch := t.Unix()*1000000 + int64(t.Nanosecond())/1000 - microsecSinceY2K := microsecSinceUnixEpoch - microsecFromUnixEpochToY2K - w.WriteInt64(microsecSinceY2K) - } - - return nil -} - -func encodeArrayHeader(w *WriteBuf, oid, length, sizePerItem int) { - w.WriteInt32(int32(20 + length*sizePerItem)) - w.WriteInt32(1) // number of dimensions - w.WriteInt32(0) // no nulls - w.WriteInt32(int32(oid)) // type of elements - w.WriteInt32(int32(length)) // number of elements - w.WriteInt32(1) // index of first element -}