reorganize numcopies code (no behavior changes)
Move stuff into Logs.NumCopies. Add a NumCopies newtype. Better names for various serialization classes that are specific to one thing or another.
This commit is contained in:
parent
e38a21a768
commit
b40df4f0d0
20 changed files with 137 additions and 98 deletions
|
@ -106,34 +106,34 @@ readResponse h = fromMaybe False . deserialize <$> hGetLine h
|
|||
fieldSep :: String
|
||||
fieldSep = "\0"
|
||||
|
||||
class Serialized a where
|
||||
class TCSerialized a where
|
||||
serialize :: a -> String
|
||||
deserialize :: String -> Maybe a
|
||||
|
||||
instance Serialized Bool where
|
||||
instance TCSerialized Bool where
|
||||
serialize True = "1"
|
||||
serialize False = "0"
|
||||
deserialize "1" = Just True
|
||||
deserialize "0" = Just False
|
||||
deserialize _ = Nothing
|
||||
|
||||
instance Serialized Direction where
|
||||
instance TCSerialized Direction where
|
||||
serialize Upload = "u"
|
||||
serialize Download = "d"
|
||||
deserialize "u" = Just Upload
|
||||
deserialize "d" = Just Download
|
||||
deserialize _ = Nothing
|
||||
|
||||
instance Serialized AssociatedFile where
|
||||
instance TCSerialized AssociatedFile where
|
||||
serialize (Just f) = f
|
||||
serialize Nothing = ""
|
||||
deserialize "" = Just Nothing
|
||||
deserialize f = Just $ Just f
|
||||
|
||||
instance Serialized UUID where
|
||||
instance TCSerialized UUID where
|
||||
serialize = fromUUID
|
||||
deserialize = Just . toUUID
|
||||
|
||||
instance Serialized Key where
|
||||
instance TCSerialized Key where
|
||||
serialize = key2file
|
||||
deserialize = file2key
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue