@@ -2,6 +2,8 @@ module Database.PostgreSQL.Protocol.Codecs.Decoders where
2
2
3
3
import Data.Word
4
4
import Data.Int
5
+ import Data.Maybe
6
+ import Data.Fixed
5
7
import Data.Char
6
8
import Data.UUID (UUID , fromWords )
7
9
import Data.Time (Day , UTCTime , LocalTime , DiffTime )
@@ -14,6 +16,7 @@ import Prelude hiding (bool)
14
16
import Database.PostgreSQL.Protocol.Store.Decode
15
17
import Database.PostgreSQL.Protocol.Types
16
18
import Database.PostgreSQL.Protocol.Codecs.Time
19
+ import Database.PostgreSQL.Protocol.Codecs.Numeric
17
20
18
21
-- | Decodes DataRow header.
19
22
-- 1 byte - Message Header
@@ -62,15 +65,15 @@ arrayHeader = skipBytes 12
62
65
arrayDimensions :: Int -> Decode (V. Vector Int )
63
66
arrayDimensions dims = V. reverse <$> V. replicateM dims arrayDimSize
64
67
where
65
- -- 4 bytes - count of elements in dimension
68
+ -- 4 bytes - count of elements in the dimension
66
69
-- 4 bytes - lower bound
67
70
arrayDimSize = (fromIntegral <$> getWord32BE) <* getWord32BE
68
71
69
72
{-# INLINE arrayFieldDecoder #-}
70
73
arrayFieldDecoder :: Int -> (V. Vector Int -> Decode a ) -> FieldDecoder a
71
74
arrayFieldDecoder dims f _ = arrayHeader *> arrayDimensions dims >>= f
72
75
73
- -- | Decodes only content of a field.
76
+ -- | Decodes only a content of the field.
74
77
type FieldDecoder a = Int -> Decode a
75
78
76
79
--
@@ -103,15 +106,15 @@ float8 _ = getFloat64BE
103
106
104
107
{-# INLINE int2 #-}
105
108
int2 :: FieldDecoder Int16
106
- int2 _ = getInt16BE
109
+ int2 _ = getInt16BE
107
110
108
111
{-# INLINE int4 #-}
109
112
int4 :: FieldDecoder Int32
110
- int4 _ = getInt32BE
113
+ int4 _ = getInt32BE
111
114
112
115
{-# INLINE int8 #-}
113
116
int8 :: FieldDecoder Int64
114
- int8 _ = getInt64BE
117
+ int8 _ = getInt64BE
115
118
116
119
{-# INLINE interval #-}
117
120
interval :: FieldDecoder DiffTime
@@ -127,8 +130,15 @@ bsJsonText = getByteString
127
130
bsJsonBytes :: FieldDecoder B. ByteString
128
131
bsJsonBytes len = getWord8 *> getByteString (len - 1 )
129
132
130
- -- numeric :: FieldDecoder Scientific
131
- -- numeric = undefined
133
+ numeric :: HasResolution a => FieldDecoder (Fixed a )
134
+ numeric _ = do
135
+ ndigits <- getWord16BE
136
+ weight <- getInt16BE
137
+ msign <- numericSign <$> getWord16BE
138
+ sign <- maybe (fail " unknown numeric" ) pure msign
139
+ dscale <- getWord16BE
140
+ digits <- replicateM (fromIntegral ndigits) getWord16BE
141
+ pure $ undefined
132
142
133
143
-- | Decodes text without applying encoding.
134
144
{-# INLINE bsText #-}
0 commit comments