| ... |
... |
@@ -31,8 +31,8 @@ import qualified GHC.Exts.Heap as Heap |
|
31
|
31
|
import Data.Word (Word16)
|
|
32
|
32
|
import Data.ByteString.Short (ShortByteString (SBS), toShort)
|
|
33
|
33
|
import Data.Array.Base (UArray (UArray))
|
|
34
|
|
-import Data.Binary.Builder (putWord64le, fromShortByteString)
|
|
35
|
|
-import Data.Binary.Put (Put, putWord8, putBuilder)
|
|
|
34
|
+import Data.Binary.Builder (fromShortByteString)
|
|
|
35
|
+import Data.Binary.Put (Put, putWord8, putWord64le, putBuilder)
|
|
36
|
36
|
import Data.Binary.Get (Get, getWord8, getWord64le, getByteString)
|
|
37
|
37
|
import Data.Binary (Binary (put, get))
|
|
38
|
38
|
import Foreign.Storable (Storable, sizeOf)
|
| ... |
... |
@@ -40,13 +40,13 @@ import GHC.Data.SmallArray (SmallArray) |
|
40
|
40
|
import GHC.Generics (Generic)
|
|
41
|
41
|
|
|
42
|
42
|
#if defined(WORDS_BIGENDIAN)
|
|
43
|
|
-import Data.Binary.Builder (putWord16le)
|
|
44
|
|
-import Data.Binary.Get (getWord16)
|
|
|
43
|
+import Data.Binary.Put (putWord16le)
|
|
|
44
|
+import Data.Binary.Get (getWord16le)
|
|
45
|
45
|
#endif
|
|
46
|
46
|
|
|
47
|
47
|
#if defined(WORDS_BIGENDIAN) || SIZEOF_HSWORD == 4
|
|
48
|
48
|
import Control.Monad (replicateM)
|
|
49
|
|
-import Data.Array.Base (listArray, numElements, elems)
|
|
|
49
|
+import Data.Array.Base (IArray, listArray, numElements, elems)
|
|
50
|
50
|
#endif
|
|
51
|
51
|
|
|
52
|
52
|
isLittleEndian :: Bool
|
| ... |
... |
@@ -160,8 +160,8 @@ instance Binary ResolvedBCO where |
|
160
|
160
|
-- array is the one that is used for the serialized form of elements.
|
|
161
|
161
|
putBCOByteArrayDirectly :: Storable a => BCOByteArray a -> Put
|
|
162
|
162
|
putBCOByteArrayDirectly @a (BCOByteArray byteArray#)
|
|
163
|
|
- = putBuilder $
|
|
164
|
|
- putWord64le (fromIntegral size) <> fromShortByteString (SBS byteArray#)
|
|
|
163
|
+ = putWord64le (fromIntegral size) <>
|
|
|
164
|
+ putBuilder (fromShortByteString (SBS byteArray#))
|
|
165
|
165
|
where
|
|
166
|
166
|
|
|
167
|
167
|
size :: Int
|
| ... |
... |
@@ -185,13 +185,13 @@ getBCOByteArrayDirectly @a = do |
|
185
|
185
|
-- | Serialize a 'BCOByteArray', not writing the payload verbatim but
|
|
186
|
186
|
-- serializing the individual elements. This can be used with any host
|
|
187
|
187
|
-- platform and element type.
|
|
188
|
|
-putBCOByteArrayPortably :: (a -> Put)
|
|
|
188
|
+putBCOByteArrayPortably :: (Storable a, IArray UArray a)
|
|
|
189
|
+ => (a -> Put)
|
|
189
|
190
|
-- ^ The serializer to use for each element
|
|
190
|
191
|
-> (BCOByteArray a -> Put)
|
|
191
|
192
|
-- ^ The 'BCOByteArray' serializer
|
|
192
|
|
-putBCOByteArrayPortably putElement bcoByteArray
|
|
193
|
|
- = putBuilder $
|
|
194
|
|
- putWord64le (fromIntegral size) <> foldMap putElement (elems array)
|
|
|
193
|
+putBCOByteArrayPortably @a putElement bcoByteArray
|
|
|
194
|
+ = putWord64le (fromIntegral size) <> foldMap putElement (elems array)
|
|
195
|
195
|
where
|
|
196
|
196
|
|
|
197
|
197
|
array :: UArray Int a
|
| ... |
... |
@@ -203,7 +203,8 @@ putBCOByteArrayPortably putElement bcoByteArray |
|
203
|
203
|
-- | Deserialize a 'BCOByteArray', not reading the payload verbatim but
|
|
204
|
204
|
-- deserializing the individual elements. This can be used with any host
|
|
205
|
205
|
-- platform and element type.
|
|
206
|
|
-getBCOByteArrayPortably :: Get a
|
|
|
206
|
+getBCOByteArrayPortably :: IArray UArray a
|
|
|
207
|
+ => Get a
|
|
207
|
208
|
-- ^ The deserializer to use for each element
|
|
208
|
209
|
-> Get (BCOByteArray a)
|
|
209
|
210
|
-- ^ The 'BCOByteArray' deserializer
|