diff options
author | Joey Hess <joeyh@joeyh.name> | 2019-01-01 15:39:45 -0400 |
---|---|---|
committer | Joey Hess <joeyh@joeyh.name> | 2019-01-01 16:17:54 -0400 |
commit | 894716512d7dd7fde7932cab48c17becb86c67d3 (patch) | |
tree | bcc7b9571393386667bab93d3f0eb0deb603a353 /Types/UUID.hs | |
parent | b781fbcccfc3d3d11a523dc83c8664ee41bf62f0 (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.hs | 15 |
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 |