@@ -1,84 +1,86 @@
1−{-# LANGUAGE DeriveDataTypeable, TypeFamilies, CPP #-}
1+{-# LANGUAGE CPP #-}
2+{-# LANGUAGE DeriveDataTypeable #-}
3+{-# LANGUAGE TypeFamilies #-}
4+{-# LANGUAGE ViewPatterns #-}
5+{-# LANGUAGE Unsafe #-}
6+{-# LANGUAGE DeriveLift #-}
7+{-# LANGUAGE StandaloneDeriving #-}
8+{-# OPTIONS_HADDOCK hide #-}
29
310-- |
4−-- Module : Data.UUID
5−-- Copyright : (c) 2008-2009, 2012 Antoine Latter
11+-- Module : Data.UUID.Types.Internal
12+-- Copyright : (c) 2017-2018 Herbert Valerio Riedel
13+-- (c) 2008-2009, 2012 Antoine Latter
614-- (c) 2009 Mark Lentczner
715--
816-- License : BSD-style
917--
10−-- Maintainer : aslatter@gmail.com
11−-- Stability : experimental
18+-- Maintainer : hvr@gnu.org
1219-- Portability : portable
1320
14−module Data.UUID.Internal
15− (UUID(..)
16− ,null
17− ,nil
18− ,fromByteString
19− ,toByteString
20− ,fromString
21− ,toString
22− ,fromWords
23− ,toWords
24− ,toList
25− ,buildFromBytes
26− ,buildFromWords
27− ,fromASCIIBytes
28− ,toASCIIBytes
29− ,fromLazyASCIIBytes
30− ,toLazyASCIIBytes
31− ,UnpackedUUID(..)
32− ,pack
33− ,unpack
21+module Data.UUID.Types.Internal
22+ ( UUID(..)
23+ , null
24+ , nil
25+ , fromByteString
26+ , toByteString
27+ , fromString
28+ , toString
29+ , fromText
30+ , toText
31+ , fromWords
32+ , toWords
33+ , fromWords64
34+ , toWords64
35+ , toList
36+ , buildFromBytes
37+ , buildFromWords
38+ , fromASCIIBytes
39+ , toASCIIBytes
40+ , fromLazyASCIIBytes
41+ , toLazyASCIIBytes
42+ , UnpackedUUID(..)
43+ , pack
44+ , unpack
3445 ) where
3546
36−import Prelude hiding (null)
37−
38−import Control.Applicative ((<*>))
39−import Control.DeepSeq (NFData(..))
40−import Control.Monad (liftM4, guard)
41−import Data.Functor ((<$>))
42−import Data.Char
43−import Data.Bits
44−import Data.Hashable
45−import Data.List (elemIndices)
46−import Foreign.Ptr (Ptr)
47−
48−#if MIN_VERSION_base(4,0,0)
49−import Data.Data
50−#else
51−import Data.Generics.Basics
52−#endif
53−
54−import Foreign.Storable
55−
56−import Data.Binary
57−import Data.Binary.Put
58−import Data.Binary.Get
59−import qualified Data.ByteString as B
60−import qualified Data.ByteString.Internal as BI
61−import qualified Data.ByteString.Lazy as BL
62−import qualified Data.ByteString.Unsafe as BU
63−
64−import Data.UUID.Builder
65−import Data.Word.Util
66−
67−import System.Random
68−
69−
70−-- |The UUID type. A 'Random' instance is provided which produces
71−-- version 4 UUIDs as specified in RFC 4122. The 'Storable' and
72−-- 'Binary' instances are compatible with RFC 4122, storing the fields
73−-- in network order as 16 bytes.
74−data UUID
75− = UUID
76− {-# UNPACK #-} !Word32
77− {-# UNPACK #-} !Word32
78− {-# UNPACK #-} !Word32
79− {-# UNPACK #-} !Word32
80− deriving (Eq, Ord, Typeable)
47+import Prelude hiding (null)
48+
49+import Control.DeepSeq (NFData (..))
50+import Control.Monad (guard, liftM2)
51+import Data.Bits
52+import Data.Char
53+import Data.Data
54+import Data.Hashable
55+import Data.List (elemIndices)
56+import Foreign.Ptr (Ptr)
57+
58+import Foreign.Storable
59+
60+import Data.Binary
61+import Data.Binary.Get
62+import Data.Binary.Put
63+import qualified Data.ByteString as B
64+import qualified Data.ByteString.Internal as BI
65+import qualified Data.ByteString.Lazy as BL
66+import qualified Data.ByteString.Unsafe as BU
67+import Data.Text (Text)
68+import qualified Data.Text.Encoding as T
69+
70+import Data.UUID.Types.Internal.Builder
71+
72+import System.Random (Random (..), uniform)
73+import System.Random.Stateful (Uniform (..), uniformWord64)
74+
75+import Language.Haskell.TH.Syntax (Lift)
76+
77+-- | Type representing <https://en.wikipedia.org/wiki/UUID Universally Unique Identifiers (UUID)> as specified in
78+-- <http://tools.ietf.org/html/rfc4122 RFC 4122>.
79+data UUID = UUID {-# UNPACK #-} !Word64 {-# UNPACK #-} !Word64
80+ deriving (Eq, Ord)
8181{-
82+ Prior to uuid-types-1.0.4:
83+ !Word32 !Word32 !Word32 !Word32
8284 Other representations that we tried are:
8385 Mimic V1 structure: !Word32 !Word16 !Word16 !Word16
8486 !Word8 !Word8 !Word8 !Word8 !Word8 !Word8
@@ -90,40 +92,75 @@ data UUID
9092 None was as fast, overall, as the representation used here.
9193-}
9294
93−-- | Covert a 'UUID' into a sequence of 'Word32' values.
94−-- Usefull for when you need to serialize a UUID and
95+-- | Convert a 'UUID' into a sequence of 'Word32' values.
96+-- Useful for when you need to serialize a UUID and
9597-- neither 'Storable' nor 'Binary' are appropriate.
96−-- Introduced in version 1.2.2.
98+--
99+-- >>> toWords <$> fromString "550e8400-e29b-41d4-a716-446655440000"
100+-- Just (1427014656,3801825748,2803254374,1430519808)
101+--
102+-- See also 'toWords64'.
103+--
104+-- /Since: @uuid-1.2.2@/
105+--
106+-- @since 1.0.0
97107toWords :: UUID -> (Word32, Word32, Word32, Word32)
98−toWords (UUID w1 w2 w3 w4) = (w1, w2, w3, w4)
108+toWords (UUID w12 w34) = (w1, w2, w3, w4)
109+ where
110+ w1 = fromIntegral (w12 `unsafeShiftR` 32)
111+ w2 = fromIntegral w12
112+ w3 = fromIntegral (w34 `unsafeShiftR` 32)
113+ w4 = fromIntegral w34
99114
100115-- | Create a 'UUID' from a sequence of 'Word32'. The
101−-- opposite of 'toWords'. Useful when you need a total
116+-- inverse of 'toWords'. Useful when you need a total
102117-- function for constructing 'UUID' values.
103−-- Introduced in version 1.2.2.
118+--
119+-- See also 'fromWords64'.
120+--
121+-- /Since: @uuid-1.2.2@/
122+--
123+-- @since 1.0.0
104124fromWords :: Word32 -> Word32 -> Word32 -> Word32 -> UUID
105−fromWords = UUID
125+fromWords w1 w2 w3 w4 = UUID (w32to64 w1 w2) (w32to64 w3 w4)
126+
127+-- | Convert a 'UUID' into a pair of 'Word64's.
128+--
129+-- >>> toWords64 <$> fromString "550e8400-e29b-41d4-a716-446655440000"
130+-- Just (6128981282234515924,12039885860129472512)
131+--
132+-- See also 'toWords'.
133+--
134+-- @since 1.0.4
135+toWords64 :: UUID -> (Word64, Word64)
136+toWords64 (UUID w12 w34) = (w12,w34)
137+
138+-- | Create a 'UUID' from a pair of 'Word64's.
139+--
140+-- Inverse of 'toWords64'. See also 'fromWords'.
141+--
142+-- @since 1.0.4
143+fromWords64 :: Word64 -> Word64 -> UUID
144+fromWords64 = UUID
106145
107146data UnpackedUUID =
108147 UnpackedUUID {
109− time_low :: Word32 -- 0-3
110− , time_mid :: Word16 -- 4-5
148+ time_low :: Word32 -- 0-3
149+ , time_mid :: Word16 -- 4-5
111150 , time_hi_and_version :: Word16 -- 6-7
112− , clock_seq_hi_res :: Word8 -- 8
113− , clock_seq_low :: Word8 -- 9
114− , node_0 :: Word8
115− , node_1 :: Word8
116− , node_2 :: Word8
117− , node_3 :: Word8
118− , node_4 :: Word8
119− , node_5 :: Word8
151+ , clock_seq_hi_res :: Word8 -- 8
152+ , clock_seq_low :: Word8 -- 9
153+ , node_0 :: Word8
154+ , node_1 :: Word8
155+ , node_2 :: Word8
156+ , node_3 :: Word8
157+ , node_4 :: Word8
158+ , node_5 :: Word8
120159 }
121160 deriving (Read, Show, Eq, Ord)
122161
123162unpack :: UUID -> UnpackedUUID
124−unpack (UUID w0 w1 w2 w3) =
125− build /-/ w0 /-/ w1 /-/ w2 /-/ w3
126−
163+unpack (UUID w0 w1) = build /-/ w0 /-/ w1
127164 where
128165 build x0 x1 x2 x3 x4 x5 x6 x7 x8 x9 xA xB xC xD xE xF =
129166 UnpackedUUID {
@@ -142,13 +179,13 @@ unpack (UUID w0 w1 w2 w3) =
142179
143180pack :: UnpackedUUID -> UUID
144181pack unpacked =
145− makeFromBytes /-/ (time_low unpacked)
146− /-/ (time_mid unpacked)
147− /-/ (time_hi_and_version unpacked)
148− /-/ (clock_seq_hi_res unpacked)
182+ makeFromBytes /-/ (time_low unpacked)
183+ /-/ (time_mid unpacked)
184+ /-/ (time_hi_and_version unpacked)
185+ /-/ (clock_seq_hi_res unpacked)
149186 /-/ (clock_seq_low unpacked)
150− /-/ (node_0 unpacked) /-/ (node_1 unpacked)
151− /-/ (node_2 unpacked) /-/ (node_3 unpacked)
187+ /-/ (node_0 unpacked) /-/ (node_1 unpacked)
188+ /-/ (node_2 unpacked) /-/ (node_3 unpacked)
152189 /-/ (node_4 unpacked) /-/ (node_5 unpacked)
153190
154191
@@ -158,15 +195,26 @@ pack unpacked =
158195
159196-- |Build a Word32 from four Word8 values, presented in big-endian order
160197word :: Word8 -> Word8 -> Word8 -> Word8 -> Word32
161−word a b c d = (fromIntegral a `shiftL` 24)
162− .|. (fromIntegral b `shiftL` 16)
163− .|. (fromIntegral c `shiftL` 8)
164− .|. (fromIntegral d )
198+word a b c d = (fromIntegral a `unsafeShiftL` 24)
199+ .|. (fromIntegral b `unsafeShiftL` 16)
200+ .|. (fromIntegral c `unsafeShiftL` 8)
201+ .|. (fromIntegral d )
165202
166−-- |Extract a Word8 from a Word32. Bytes, high to low, are numbered from 3 to 0,
167−byte :: Int -> Word32 -> Word8
203+-- |Extract a Word8 from a Word64. Bytes, high to low, are numbered from 7 to 0,
204+byte :: Int -> Word64 -> Word8
168205byte i w = fromIntegral (w `shiftR` (i * 8))
169206
207+-- |Build a Word16 from two Word8 values, presented in big-endian order.
208+w8to16 :: Word8 -> Word8 -> Word16
209+w8to16 w0s w1s =
210+ (w0 `unsafeShiftL` 8) .|. w1
211+ where
212+ w0 = fromIntegral w0s
213+ w1 = fromIntegral w1s
214+
215+-- | Construct 'Word64' from low/high 'Word32's
216+w32to64 :: Word32 -> Word32 -> Word64
217+w32to64 w0 w1 = (fromIntegral w0 `unsafeShiftL` 32) .|. (fromIntegral w1)
170218
171219-- |Make a UUID from sixteen Word8 values
172220makeFromBytes :: Word8 -> Word8 -> Word8 -> Word8
@@ -175,16 +223,12 @@ makeFromBytes :: Word8 -> Word8 -> Word8 -> Word8
175223 -> Word8 -> Word8 -> Word8 -> Word8
176224 -> UUID
177225makeFromBytes b0 b1 b2 b3 b4 b5 b6 b7 b8 b9 ba bb bc bd be bf
178− = UUID w0 w1 w2 w3
226+ = fromWords w0 w1 w2 w3
179227 where w0 = word b0 b1 b2 b3
180228 w1 = word b4 b5 b6 b7
181229 w2 = word b8 b9 ba bb
182230 w3 = word bc bd be bf
183231
184−-- |Make a UUID from four Word32 values
185−makeFromWords :: Word32 -> Word32 -> Word32 -> Word32 -> UUID
186−makeFromWords = UUID
187−
188232-- |A Builder for constructing a UUID of a given version.
189233buildFromBytes :: Word8
190234 -> Word8 -> Word8 -> Word8 -> Word8
@@ -197,20 +241,20 @@ buildFromBytes v b0 b1 b2 b3 b4 b5 b6 b7 b8 b9 ba bb bc bd be bf =
197241 where b6' = b6 .&. 0x0f .|. (v `shiftL` 4)
198242 b8' = b8 .&. 0x3f .|. 0x80
199243
200−-- |Build a UUID of a given version from Word32 values.
244+-- |Build a UUID of a given version from 'Word32' values.
201245buildFromWords :: Word8 -> Word32 -> Word32 -> Word32 -> Word32 -> UUID
202−buildFromWords v w0 w1 w2 w3 = makeFromWords w0 w1' w2' w3
246+buildFromWords v w0 w1 w2 w3 = fromWords w0 w1' w2' w3
203247 where w1' = w1 .&. 0xffff0fff .|. ((fromIntegral v) `shiftL` 12)
204248 w2' = w2 .&. 0x3fffffff .|. 0x80000000
205249
206250
207251-- |Return the bytes that make up the UUID
208252toList :: UUID -> [Word8]
209−toList (UUID w0 w1 w2 w3) =
210− [byte 3 w0, byte 2 w0, byte 1 w0, byte 0 w0,
211− byte 3 w1, byte 2 w1, byte 1 w1, byte 0 w1,
212− byte 3 w2, byte 2 w2, byte 1 w2, byte 0 w2,
213− byte 3 w3, byte 2 w3, byte 1 w3, byte 0 w3]
253+toList (UUID w0 w1) =
254+ [byte 7 w0, byte 6 w0, byte 5 w0, byte 4 w0,
255+ byte 3 w0, byte 2 w0, byte 1 w0, byte 0 w0,
256+ byte 7 w1, byte 6 w1, byte 5 w1, byte 4 w1,
257+ byte 3 w1, byte 2 w1, byte 1 w1, byte 0 w1]
214258
215259-- |Construct a UUID from a list of Word8. Returns Nothing if the list isn't
216260-- exactly sixteen bytes long
@@ -231,10 +275,10 @@ null = (== nil)
231275 -- null (UUID 0 0 0 0) = True
232276 -- null _ = False
233277
234−-- |The nil UUID, as defined in RFC 4122.
235−-- It is a UUID of all zeros. @'null' u@ iff @'u' == 'nil'@.
278+-- |The 'nil' UUID, as defined in <http://tools.ietf.org/html/rfc4122 RFC 4122>.
279+-- It is a UUID of all zeros. @'null' u@ /iff/ @'u' == 'nil'@.
236280nil :: UUID
237−nil = UUID 0 0 0 0
281+nil = UUID 0 0
238282
239283-- |Extract a UUID from a 'ByteString' in network byte order.
240284-- The argument must be 16 bytes long, otherwise 'Nothing' is returned.
@@ -242,6 +286,8 @@ fromByteString :: BL.ByteString -> Maybe UUID
242286fromByteString = fromList . BL.unpack
243287
244288-- |Encode a UUID into a 'ByteString' in network order.
289+--
290+-- This uses the same encoding as the 'Binary' instance.
245291toByteString :: UUID -> BL.ByteString
246292toByteString = BL.pack . toList
247293
@@ -249,9 +295,8 @@ toByteString = BL.pack . toList
249295-- The hyphens may not be omitted.
250296-- Example:
251297--
252−-- @
253−-- fromString \"c2cc10e1-57d6-4b6f-9899-38d972112d8c\"
254−-- @
298+-- >>> fromString "c2cc10e1-57d6-4b6f-9899-38d972112d8c"
299+-- Just c2cc10e1-57d6-4b6f-9899-38d972112d8c
255300--
256301-- Hex digits may be upper or lower-case.
257302fromString :: String -> Maybe UUID
@@ -266,7 +311,7 @@ fromString' s0 = do
266311 (w2, s3) <- hexWord s2
267312 (w3, s4) <- hexWord s3
268313 if s4 /= "" then Nothing
269− else Just $ UUID w0 w1 w2 w3
314+ else Just $ fromWords w0 w1 w2 w3
270315 where hexWord :: String -> Maybe (Word32, String)
271316 hexWord s = Just (0, s) >>= hexByte >>= hexByte
272317 >>= hexByte >>= hexByte
@@ -283,21 +328,39 @@ fromString' s0 = do
283328-- | Convert a UUID into a hypenated string using lower-case letters.
284329-- Example:
285330--
286−-- @
287−-- toString \<$\> fromString \"550e8400-e29b-41d4-a716-446655440000\"
288−-- @
331+-- >>> toString <$> fromString "550e8400-e29b-41d4-a716-446655440000"
332+-- Just "550e8400-e29b-41d4-a716-446655440000"
333+--
334+--
289335toString :: UUID -> String
290−toString (UUID w0 w1 w2 w3) = hexw w0 $ hexw' w1 $ hexw' w2 $ hexw w3 ""
291− where hexw :: Word32 -> String -> String
292− hexw w s = hexn w 28 : hexn w 24 : hexn w 20 : hexn w 16
293− : hexn w 12 : hexn w 8 : hexn w 4 : hexn w 0 : s
336+toString uuid = hexw0 w0 $ hexw1 w1 ""
337+ where hexw0 :: Word64 -> String -> String
338+ hexw0 w s = hexn w 60 : hexn w 56 : hexn w 52 : hexn w 48
339+ : hexn w 44 : hexn w 40 : hexn w 36 : hexn w 32
340+ : '-' : hexn w 28 : hexn w 24 : hexn w 20 : hexn w 16
341+ : '-' : hexn w 12 : hexn w 8 : hexn w 4 : hexn w 0
342+ : s
343+
344+ hexw1 :: Word64 -> String -> String
345+ hexw1 w s = '-' : hexn w 60 : hexn w 56 : hexn w 52 : hexn w 48
346+ : '-' : hexn w 44 : hexn w 40 : hexn w 36 : hexn w 32
347+ : hexn w 28 : hexn w 24 : hexn w 20 : hexn w 16
348+ : hexn w 12 : hexn w 8 : hexn w 4 : hexn w 0
349+ : s
350+
351+ hexn :: Word64 -> Int -> Char
352+ hexn w r = intToDigit $ fromIntegral ((w `shiftR` r) .&. 0xf)
294353
295− hexw' :: Word32 -> String -> String
296− hexw' w s = '-' : hexn w 28 : hexn w 24 : hexn w 20 : hexn w 16
297− : '-' : hexn w 12 : hexn w 8 : hexn w 4 : hexn w 0 : s
354+ (w0,w1) = toWords64 uuid
298355
299− hexn :: Word32 -> Int -> Char
300− hexn w r = intToDigit $ fromIntegral ((w `shiftR` r) .&. 0xf)
356+-- | If the passed in `Text` can be parsed as an ASCII representation of
357+-- a `UUID`, it will be. The hyphens may not be omitted.
358+fromText :: Text -> Maybe UUID
359+fromText = fromASCIIBytes . T.encodeUtf8
360+
361+-- | Convert a UUID into a hyphentated string using lower-case letters.
362+toText :: UUID -> Text
363+toText = T.decodeLatin1 . toASCIIBytes
301364
302365-- | Convert a UUID into a hyphentated string using lower-case letters, packed
303366-- as ASCII bytes into `B.ByteString`.
@@ -392,49 +455,30 @@ fromASCIIBytes bs = do
392455-- | Similar to `toASCIIBytes` except we produce a lazy `BL.ByteString`.
393456toLazyASCIIBytes :: UUID -> BL.ByteString
394457toLazyASCIIBytes =
395−#if MIN_VERSION_bytestring(0,10,0)
396458 BL.fromStrict
397−#else
398− BL.fromChunks . return
399−#endif
400459 . toASCIIBytes
401460
402461-- | Similar to `fromASCIIBytes` except parses from a lazy `BL.ByteString`.
403462fromLazyASCIIBytes :: BL.ByteString -> Maybe UUID
404463fromLazyASCIIBytes bs =
405− if BL.length bs == 36 then fromASCIIBytes (
406−#if MIN_VERSION_bytestring(0,10,0)
407− BL.toStrict bs
408−#else
409− B.concat $ BL.toChunks bs
410−#endif
411− ) else Nothing
464+ if BL.length bs == 36 then fromASCIIBytes (BL.toStrict bs) else Nothing
412465
413466--
414467-- Class Instances
415468--
416469
470+-- | This 'Random' instance produces __insecure__ version 4 UUIDs as
471+-- specified in <http://tools.ietf.org/html/rfc4122 RFC 4122>.
417472instance Random UUID where
418− random g = (fromGenNext w0 w1 w2 w3 w4, g4)
419− where (w0, g0) = next g
420− (w1, g1) = next g0
421− (w2, g2) = next g1
422− (w3, g3) = next g2
423− (w4, g4) = next g3
473+ random = uniform
424474 randomR _ = random -- range is ignored
425475
426−-- |Build a UUID from the results of five calls to next on a StdGen.
427−-- While next on StdGet returns an Int, it doesn't provide 32 bits of
428−-- randomness. This code relies on at last 28 bits of randomness in the
429−-- and optimizes its use so as to make only five random values, not six.
430−fromGenNext :: Int -> Int -> Int -> Int -> Int -> UUID
431−fromGenNext w0 w1 w2 w3 w4 =
432− buildFromBytes 4 /-/ (ThreeByte w0)
433− /-/ (ThreeByte w1)
434− /-/ w2 -- use all 4 bytes because we know the version
435− -- field will "cover" the upper, non-random bits
436− /-/ (ThreeByte w3)
437− /-/ (ThreeByte w4)
476+-- @since 1.0.4
477+instance Uniform UUID where
478+ uniformM gen = do
479+ w0 <- uniformWord64 gen
480+ w1 <- uniformWord64 gen
481+ pure $ buildFromBytes 4 /-/ w0 /-/ w1
438482
439483-- |A ByteSource to extract only three bytes from an Int, since next on StdGet
440484-- only returns 31 bits of randomness.
@@ -442,24 +486,29 @@ type instance ByteSink ThreeByte g = Takes3Bytes g
442486newtype ThreeByte = ThreeByte Int
443487instance ByteSource ThreeByte where
444488 f /-/ (ThreeByte w) = f b1 b2 b3
445− where b1 = fromIntegral (w `shiftR` 16)
446− b2 = fromIntegral (w `shiftR` 8)
489+ where b1 = fromIntegral (w `unsafeShiftR` 16)
490+ b2 = fromIntegral (w `unsafeShiftR` 8)
447491 b3 = fromIntegral w
448492
449493instance NFData UUID where
450− rnf = rnf . toWords
494+ rnf = flip seq ()
451495
452496instance Hashable UUID where
453− hash (UUID w0 w1 w2 w3) =
497+ hash (toWords -> (w0,w1,w2,w3)) =
454498 hash w0 `hashWithSalt` w1
455499 `hashWithSalt` w2
456500 `hashWithSalt` w3
457− hashWithSalt s (UUID w0 w1 w2 w3) =
501+ hashWithSalt s (toWords -> (w0,w1,w2,w3)) =
458502 s `hashWithSalt` w0
459503 `hashWithSalt` w1
460504 `hashWithSalt` w2
461505 `hashWithSalt` w3
462506
507+-- | Pretty prints a 'UUID' (without quotation marks). See also 'toString'.
508+--
509+-- >>> show nil
510+-- "00000000-0000-0000-0000-000000000000"
511+--
463512instance Show UUID where
464513 show = toString
465514
@@ -470,7 +519,7 @@ instance Read UUID where
470519 Nothing -> []
471520 Just u -> [(u,drop 36 noSpaces)]
472521
473−
522+-- | This 'Storable' instance uses the memory layout as described in <http://tools.ietf.org/html/rfc4122 RFC 4122>, but in contrast to the 'Binary' instance, __the fields are stored in host byte order__.
474523instance Storable UUID where
475524 sizeOf _ = 16
476525 alignment _ = 4
@@ -507,10 +556,10 @@ instance Storable UUID where
507556 pokeByteOff p (off+14) x9
508557 pokeByteOff p (off+15) x10
509558
559+-- | This 'Binary' instance is compatible with <http://tools.ietf.org/html/rfc4122 RFC 4122>, storing the fields in network order as 16 bytes.
510560instance Binary UUID where
511− put (UUID w0 w1 w2 w3) =
512− putWord32be w0 >> putWord32be w1 >> putWord32be w2 >> putWord32be w3
513− get = liftM4 UUID getWord32be getWord32be getWord32be getWord32be
561+ put (UUID w0 w1) = putWord64be w0 >> putWord64be w1
562+ get = liftM2 UUID getWord64be getWord64be
514563
515564
516565-- My goal with this instance was to make it work just enough to do what
@@ -521,10 +570,6 @@ instance Data UUID where
521570 dataTypeOf _ = uuidType
522571
523572uuidType :: DataType
524−uuidType = mkNoRepType "Data.UUID.UUID"
525−
526−#if !(MIN_VERSION_base(4,2,0))
527−mkNoRepType :: String -> DataType
528−mkNoRepType = mkNorepType
529−#endif
573+uuidType = mkNoRepType "Data.UUID.Types.UUID"
530574
575+deriving instance Lift UUID