summaryrefslogtreecommitdiff
path: root/Types/UUID.hs
diff options
context:
space:
mode:
authorJoey Hess <joeyh@joeyh.name>2019-01-01 15:39:45 -0400
committerJoey Hess <joeyh@joeyh.name>2019-01-01 16:17:54 -0400
commit894716512d7dd7fde7932cab48c17becb86c67d3 (patch)
treebcc7b9571393386667bab93d3f0eb0deb603a353 /Types/UUID.hs
parentb781fbcccfc3d3d11a523dc83c8664ee41bf62f0 (diff)
add a UUIDDesc type containing a ByteString
Groundwork for handling uuid.log using ByteString
Diffstat (limited to 'Types/UUID.hs')
-rw-r--r--Types/UUID.hs15
1 files changed, 13 insertions, 2 deletions
diff --git a/Types/UUID.hs b/Types/UUID.hs
index 5efc26dd0b..443cbb1e57 100644
--- a/Types/UUID.hs
+++ b/Types/UUID.hs
@@ -5,7 +5,7 @@
- Licensed under the GNU GPL version 3 or higher.
-}
-{-# LANGUAGE TypeSynonymInstances, FlexibleInstances #-}
+{-# LANGUAGE TypeSynonymInstances, FlexibleInstances, GeneralizedNewtypeDeriving #-}
module Types.UUID where
@@ -13,6 +13,7 @@ import qualified Data.ByteString as B
import qualified Data.Map as M
import qualified Data.UUID as U
import Data.Maybe
+import Data.String
import Utility.FileSystemEncoding
import qualified Utility.SimpleProtocol as Proto
@@ -56,7 +57,17 @@ instance ToUUID U.UUID where
isUUID :: String -> Bool
isUUID = isJust . U.fromString
-type UUIDMap = M.Map UUID String
+-- A description of a UUID.
+newtype UUIDDesc = UUIDDesc B.ByteString
+ deriving (Eq, Monoid, Semigroup, IsString)
+
+fromUUIDDesc :: UUIDDesc -> String
+fromUUIDDesc (UUIDDesc d) = decodeBS d
+
+toUUIDDesc :: String -> UUIDDesc
+toUUIDDesc = UUIDDesc . encodeBS
+
+type UUIDDescMap = M.Map UUID UUIDDesc
instance Proto.Serializable UUID where
serialize = fromUUID