gdritter repos tansu / c723d8e
Added RawString wrapper Getty Ritter 8 years ago
2 changed file(s) with 31 addition(s) and 0 deletion(s). Collapse all Expand all
1 {-# LANGUAGE GeneralizedNewtypeDeriving #-}
2
3 module Database.Tansu.RawString ( RawString(..) ) where
4
5 import Control.DeepSeq ( NFData )
6 import Data.ByteString ( ByteString )
7 import Data.Serialize ( Serialize(..)
8 , getByteString
9 , putByteString
10 , remaining
11 )
12 import GHC.Exts ( IsString )
13
14 -- | A wrapper over 'ByteString' with a serialize instance
15 -- that just passes the bytestring on unchanged. It will
16 -- always be the case that
17 --
18 -- > encode bs == bs
19 --
20 -- and that
21 --
22 -- > decode bs == Right bs
23 newtype RawString =
24 RawString { toByteString :: ByteString }
25 deriving (Eq, Show, Ord, Read, IsString, Monoid, NFData)
26
27 instance Serialize RawString where
28 put = putByteString . toByteString
29 get = RawString `fmap` (getByteString =<< remaining)
1515 library
1616 exposed-modules: Database.Tansu,
1717 Database.Tansu.Internal,
18 Database.Tansu.RawString,
1819 Database.Tansu.Backend.Filesystem,
1920 Database.Tansu.Backend.Ephemeral
2021 build-depends: base >=4.8 && <4.9,
2122 bytestring,
2223 cereal,
24 deepseq,
2325 monadLib,
2426 directory,
2527 filepath,