pipes-cereal (empty) → 0.1.0
raw patch · 4 files changed
+104/−0 lines, 4 filesdep +basedep +bytestringdep +cerealsetup-changed
Dependencies added: base, bytestring, cereal, mtl, pipes, pipes-bytestring, pipes-parse
Files
- LICENSE +30/−0
- Setup.hs +2/−0
- pipes-cereal.cabal +33/−0
- src/Pipes/Cereal.hs +39/−0
+ LICENSE view
@@ -0,0 +1,30 @@+Copyright (c) 2015, Ian Milligan++All rights reserved.++Redistribution and use in source and binary forms, with or without+modification, are permitted provided that the following conditions are met:++ * Redistributions of source code must retain the above copyright+ notice, this list of conditions and the following disclaimer.++ * Redistributions in binary form must reproduce the above+ copyright notice, this list of conditions and the following+ disclaimer in the documentation and/or other materials provided+ with the distribution.++ * Neither the name of Ian Milligan nor the names of other+ contributors may be used to endorse or promote products derived+ from this software without specific prior written permission.++THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT+OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ pipes-cereal.cabal view
@@ -0,0 +1,33 @@+-- Initial pipes-cereal.cabal generated by cabal init. For further +-- documentation, see http://haskell.org/cabal/users-guide/++name: pipes-cereal+version: 0.1.0+synopsis: Encode and decode binary streams using the pipes and cereal libraries.+-- description: +license: BSD3+license-file: LICENSE+author: Ian Milligan+maintainer: ianmllgn@gmail.com+category: Pipes+build-type: Simple+-- extra-source-files: +cabal-version: >=1.10++source-repository head+ Type: git+ Location: https://github.com/ian-mi/pipes-cereal++library+ exposed-modules: Pipes.Cereal+ -- other-modules: + other-extensions: Rank2Types+ build-depends: base >=4.7 && <5+ , bytestring >= 0.10+ , cereal >=0.4 && <0.5+ , mtl >= 2 && < 3+ , pipes >=4 && <5+ , pipes-bytestring >=2 && <3+ , pipes-parse >= 3 && <4+ hs-source-dirs: src+ default-language: Haskell2010
+ src/Pipes/Cereal.hs view
@@ -0,0 +1,39 @@+{-# LANGUAGE FlexibleContexts #-}+{-# LANGUAGE Rank2Types #-}++module Pipes.Cereal ( encode,+ encodePut,+ decode,+ decodeGet,+ Put,+ Get,+ Serialize ) where++import Control.Monad.Error.Class+import Data.Maybe+import Data.Monoid+import Data.Serialize hiding ( encode, decode )+import Pipes+import Pipes.ByteString+import Pipes.Parse++-- |Encode a value to a byte stream.+encode :: (Serialize a, Monad m) => a -> Producer' ByteString m ()+encode = encodePut . put++-- |Encode an explicit 'Put'.+encodePut :: Monad m => Put -> Producer' ByteString m ()+encodePut = Pipes.ByteString.fromLazy . runPutLazy++-- |Decode a value from a byte stream.+decode :: (Serialize a, Monad m) => Parser ByteString m (Either String a)+decode = decodeGet get++-- |Decode a value using an explicit 'Get'.+decodeGet :: Monad m => Get a -> Parser ByteString m (Either String a)+decodeGet = go . runGetPartial+ where go f = do next <- draw+ case f (fromMaybe mempty next) of+ Fail e bs -> unDraw bs >> return (Left e)+ Partial f' -> go f'+ Done a bs -> unDraw bs >> return (Right a)