summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEdwardKmett <>2013-05-11 05:49:20 (GMT)
committerhdiff <hdiff@hdiff.luite.com>2013-05-11 05:49:20 (GMT)
commitb82755b6cf07250c2c9d55a6125455310a522fd4 (patch)
treed8eb069e773305dde4331165e4184e21b58380c8
parent92ef0117dd9e3ba4cf9857c97827cc88902d8359 (diff)
version 0.70.7
-rw-r--r--bytes.cabal5
-rw-r--r--src/Data/Bytes/Get.hs92
-rw-r--r--src/Data/Bytes/Serial.hs12
3 files changed, 15 insertions, 94 deletions
diff --git a/bytes.cabal b/bytes.cabal
index 869785d..dd573ad 100644
--- a/bytes.cabal
+++ b/bytes.cabal
@@ -1,6 +1,6 @@
name: bytes
category: Data, Serialization
-version: 0.6
+version: 0.7
license: BSD3
cabal-version: >= 1.8
license-file: LICENSE
@@ -42,11 +42,12 @@ flag lib-Werror
library
build-depends:
base >= 4.3 && < 5,
- binary >= 0.5 && < 0.6,
+ binary >= 0.5 && < 0.8,
bytestring >= 0.9 && < 0.11,
cereal >= 0.3.5 && < 0.4,
ghc-prim,
mtl >= 2.0 && < 2.2,
+ text >= 0.2 && < 1,
transformers >= 0.2 && < 0.4,
transformers-compat >= 0.1 && < 1,
void >= 0.6 && < 0.7
diff --git a/src/Data/Bytes/Get.hs b/src/Data/Bytes/Get.hs
index 5aaf36e..f9a4c69 100644
--- a/src/Data/Bytes/Get.hs
+++ b/src/Data/Bytes/Get.hs
@@ -69,14 +69,6 @@ class (Integral (Unchecked m), Monad m, Applicative m) => MonadGet m where
-- Fails if @ga@ fails.
lookAhead :: m a -> m a
- -- | Like 'lookAhead', but consume the input if @gma@ returns 'Just _'.
- -- Fails if @gma@ fails.
- lookAheadM :: m (Maybe a) -> m (Maybe a)
-
- -- | Like 'lookAhead', but consume the input if @gea@ returns 'Right _'.
- -- Fails if @gea@ fails.
- lookAheadE :: m (Either a b) -> m (Either a b)
-
-- | Get the next up to @n@ bytes as a lazy ByteString, without consuming them.
uncheckedLookAhead :: Unchecked m -> m (Bytes m)
#ifndef HLINT
@@ -213,10 +205,6 @@ instance MonadGet B.Get where
{-# INLINE uncheckedSkip #-}
lookAhead = B.lookAhead
{-# INLINE lookAhead #-}
- lookAheadM = B.lookAheadM
- {-# INLINE lookAheadM #-}
- lookAheadE = B.lookAheadE
- {-# INLINE lookAheadE #-}
uncheckedLookAhead = B.uncheckedLookAhead
{-# INLINE uncheckedLookAhead #-}
ensure n = do
@@ -266,10 +254,6 @@ instance MonadGet S.Get where
{-# INLINE uncheckedSkip #-}
lookAhead = S.lookAhead
{-# INLINE lookAhead #-}
- lookAheadM = S.lookAheadM
- {-# INLINE lookAheadM #-}
- lookAheadE = S.lookAheadE
- {-# INLINE lookAheadE #-}
uncheckedLookAhead = S.uncheckedLookAhead
{-# INLINE uncheckedLookAhead #-}
getBytes = S.getBytes
@@ -312,115 +296,39 @@ instance MonadGet m => MonadGet (Lazy.StateT s m) where
type Bytes (Lazy.StateT s m) = Bytes m
lookAhead (Lazy.StateT m) = Lazy.StateT (lookAhead . m)
{-# INLINE lookAhead #-}
- lookAheadM (Lazy.StateT m) = Lazy.StateT (liftM factor . lookAheadE . liftM distribute . m)
- where
- distribute (Nothing, s') = Left (Nothing, s')
- distribute (Just a, s') = Right (Just a, s')
- factor = either id id
- {-# INLINE lookAheadM #-}
- lookAheadE (Lazy.StateT m) = Lazy.StateT (liftM factor . lookAheadE . liftM distribute . m)
- where
- distribute (Left a, s') = Left (Left a, s')
- distribute (Right b, s') = Right (Right b, s')
- factor = either id id
- {-# INLINE lookAheadE #-}
instance MonadGet m => MonadGet (Strict.StateT s m) where
type Unchecked (Strict.StateT s m) = Unchecked m
type Bytes (Strict.StateT s m) = Bytes m
lookAhead (Strict.StateT m) = Strict.StateT (lookAhead . m)
{-# INLINE lookAhead #-}
- lookAheadM (Strict.StateT m) = Strict.StateT (liftM factor . lookAheadE . liftM distribute . m)
- where
- distribute (Nothing, s') = Left (Nothing, s')
- distribute (Just a, s') = Right (Just a, s')
- factor = either id id
- {-# INLINE lookAheadM #-}
- lookAheadE (Strict.StateT m) = Strict.StateT (liftM factor . lookAheadE . liftM distribute . m)
- where
- distribute (Left a, s') = Left (Left a, s')
- distribute (Right b, s') = Right (Right b, s')
- factor = either id id
- {-# INLINE lookAheadE #-}
instance MonadGet m => MonadGet (ReaderT e m) where
type Unchecked (ReaderT e m) = Unchecked m
type Bytes (ReaderT e m) = Bytes m
lookAhead (ReaderT m) = ReaderT (lookAhead . m)
{-# INLINE lookAhead #-}
- lookAheadM (ReaderT m) = ReaderT (lookAheadM . m)
- {-# INLINE lookAheadM #-}
- lookAheadE (ReaderT m) = ReaderT (lookAheadE . m)
- {-# INLINE lookAheadE #-}
instance (MonadGet m, Monoid w) => MonadGet (Lazy.WriterT w m) where
type Unchecked (Lazy.WriterT w m) = Unchecked m
type Bytes (Lazy.WriterT w m) = Bytes m
lookAhead (Lazy.WriterT m) = Lazy.WriterT (lookAhead m)
{-# INLINE lookAhead #-}
- lookAheadM (Lazy.WriterT m) = Lazy.WriterT (liftM factor $ lookAheadE $ liftM distribute m)
- where
- distribute (Nothing, s') = Left (Nothing, s')
- distribute (Just a, s') = Right (Just a, s')
- factor = either id id
- {-# INLINE lookAheadM #-}
- lookAheadE (Lazy.WriterT m) = Lazy.WriterT (liftM factor $ lookAheadE $ liftM distribute m)
- where
- distribute (Left a, s') = Left (Left a, s')
- distribute (Right b, s') = Right (Right b, s')
- factor = either id id
- {-# INLINE lookAheadE #-}
instance (MonadGet m, Monoid w) => MonadGet (Strict.WriterT w m) where
type Unchecked (Strict.WriterT w m) = Unchecked m
type Bytes (Strict.WriterT w m) = Bytes m
lookAhead (Strict.WriterT m) = Strict.WriterT (lookAhead m)
{-# INLINE lookAhead #-}
- lookAheadM (Strict.WriterT m) = Strict.WriterT (liftM factor $ lookAheadE $ liftM distribute m)
- where
- distribute (Nothing, s') = Left (Nothing, s')
- distribute (Just a, s') = Right (Just a, s')
- factor = either id id
- {-# INLINE lookAheadM #-}
- lookAheadE (Strict.WriterT m) = Strict.WriterT (liftM factor $ lookAheadE $ liftM distribute m)
- where
- distribute (Left a, s') = Left (Left a, s')
- distribute (Right b, s') = Right (Right b, s')
- factor = either id id
- {-# INLINE lookAheadE #-}
instance (MonadGet m, Monoid w) => MonadGet (Strict.RWST r w s m) where
type Unchecked (Strict.RWST r w s m) = Unchecked m
type Bytes (Strict.RWST r w s m) = Bytes m
lookAhead (Strict.RWST m) = Strict.RWST $ \r s -> lookAhead (m r s)
{-# INLINE lookAhead #-}
- lookAheadM (Strict.RWST m) = Strict.RWST (\r s -> liftM factor $ lookAheadE $ liftM distribute $ m r s )
- where
- distribute (Nothing, s',w') = Left (Nothing, s', w')
- distribute (Just a, s',w') = Right (Just a, s', w')
- factor = either id id
- {-# INLINE lookAheadM #-}
- lookAheadE (Strict.RWST m) = Strict.RWST (\r s -> liftM factor $ lookAheadE $ liftM distribute $ m r s)
- where
- distribute (Left a, s', w') = Left (Left a, s', w')
- distribute (Right b, s', w') = Right (Right b, s', w')
- factor = either id id
- {-# INLINE lookAheadE #-}
instance (MonadGet m, Monoid w) => MonadGet (Lazy.RWST r w s m) where
type Unchecked (Lazy.RWST r w s m) = Unchecked m
type Bytes (Lazy.RWST r w s m) = Bytes m
lookAhead (Lazy.RWST m) = Lazy.RWST $ \r s -> lookAhead (m r s)
{-# INLINE lookAhead #-}
- lookAheadM (Lazy.RWST m) = Lazy.RWST (\r s -> liftM factor $ lookAheadE $ liftM distribute $ m r s )
- where
- distribute (Nothing, s',w') = Left (Nothing, s', w')
- distribute (Just a, s',w') = Right (Just a, s', w')
- factor = either id id
- {-# INLINE lookAheadM #-}
- lookAheadE (Lazy.RWST m) = Lazy.RWST (\r s -> liftM factor $ lookAheadE $ liftM distribute $ m r s)
- where
- distribute (Left a, s', w') = Left (Left a, s', w')
- distribute (Right b, s', w') = Right (Right b, s', w')
- factor = either id id
- {-# INLINE lookAheadE #-}
diff --git a/src/Data/Bytes/Serial.hs b/src/Data/Bytes/Serial.hs
index f00e31b..1139c04 100644
--- a/src/Data/Bytes/Serial.hs
+++ b/src/Data/Bytes/Serial.hs
@@ -40,6 +40,10 @@ import Data.ByteString.Internal
import Data.ByteString.Lazy as Lazy
import Data.ByteString as Strict
import Data.Int
+import Data.Text as SText
+import Data.Text.Encoding as SText
+import Data.Text.Lazy as LText
+import Data.Text.Lazy.Encoding as LText
import Data.Void
import Data.Word
import Foreign.ForeignPtr
@@ -77,6 +81,14 @@ instance Serial Lazy.ByteString where
n <- getWord64host
getLazyByteString (fromIntegral n)
+instance Serial SText.Text where
+ serialize = serialize . SText.encodeUtf8
+ deserialize = SText.decodeUtf8 `fmap` deserialize
+
+instance Serial LText.Text where
+ serialize = serialize . LText.encodeUtf8
+ deserialize = LText.decodeUtf8 `fmap` deserialize
+
instance Serial ()
instance Serial a => Serial [a]
instance Serial a => Serial (Maybe a)