@@ -0,0 +1,54 @@
1+{-# LANGUAGE TypeFamilies #-}
2+module Data.UUID.Util (
11+import Prelude hiding (null)
15+import Data.UUID.Internal
17+import Data.Int (Int64)
19+version :: UUID -> Int
21+ fromEnum ((time_hi_and_version unpacked `shiftR` 12) .&. 0xF)
23+ unpacked = unpack uuid
25+-- Note UUID time is in 10^-7 seconds.
26+setTime :: (Integral a, Bits a) => UUID -> a -> Maybe UUID
29+ then Just $ pack $ (unpack uuid){time_low = new_low_bits, time_mid = new_mid_bits, time_hi_and_version = new_hi_and_version_bits}
31+ where new_low_bits = fromIntegral $ t .&. 0xFFFFFFFF
32+ new_mid_bits = fromIntegral $ (t `shiftR` 32) .&. 0xFFFF
33+ new_hi_and_version_bits = fromIntegral $ 0x1000 .|. ((t `shiftR` 48) .&. 0x0FFF)
35+extractTime :: UUID -> Maybe Int64
38+ then Just $ fromIntegral $ w32to64 (w16to32 (timeAndVersionToTime $ time_hi_and_version unpacked) $ time_mid unpacked) (time_low unpacked)
41+ unpacked = unpack uuid
43+timeAndVersionToTime :: Word16 -> Word16
44+timeAndVersionToTime tv = tv .&. 0x0FFF
46+extractMac :: UUID -> Maybe MAC
50+ MAC (node_0 unpacked) (node_1 unpacked) (node_2 unpacked) (node_3 unpacked) (node_4 unpacked) (node_5 unpacked)
53+ unpacked = unpack uuid