binary-orphans-1.0.5/0000755000000000000000000000000007346545000012642 5ustar0000000000000000binary-orphans-1.0.5/CHANGELOG.md0000644000000000000000000000076607346545000014464 0ustar0000000000000000# 1.0.5 - Support GHC-8.6.5..GHC-9.10.1 # 1.0.4.1 - Support OneTuple-0.4 # 1.0.4 - Depend on `data-byte-array` to provide `Data.Array.Byte` instance # 1.0.3 - Add `ByteArray` (from `Data.Array.Byte` instance) # 1.0.2 - Add `Solo` instance # 1.0.1 - Fix `MonadFail` instances shim - `NonEmpty` doesn't fail on empty list # 1 Stripped down the package to only shim `binary` orphans. For more instances check [binary-instances](https://hackage.haskell.org/package/binary-instances) package. binary-orphans-1.0.5/LICENSE0000644000000000000000000000267407346545000013660 0ustar0000000000000000Copyright © 2019 @binary@-contributors, Oleg Grenrus 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 Mark Karpov nor the names of 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 “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 HOLDERS 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. binary-orphans-1.0.5/binary-orphans.cabal0000644000000000000000000000365007346545000016566 0ustar0000000000000000cabal-version: 1.12 name: binary-orphans version: 1.0.5 synopsis: Compatibility package for binary; provides instances category: Data, Binary, Parsing, Compatibility description: This package provides instances defined in later versions of @binary@ package . Prior version 1 this packages provided instances for other packages. That functionality is moved to [binary-instances](https://hackage.haskell.org/package/binary-instances) package. build-type: Simple maintainer: Oleg Grenrus author: Oleg Grenrus license: BSD3 license-file: LICENSE tested-with: GHC ==8.6.5 || ==8.8.4 || ==8.10.7 || ==9.0.2 || ==9.2.8 || ==9.4.8 || ==9.6.5 || ==9.8.2 || ==9.10.1 extra-source-files: CHANGELOG.md source-repository head type: git location: https://github.com/phadej/binary-orphans.git library default-language: Haskell2010 hs-source-dirs: src ghc-options: -Wall exposed-modules: Data.Binary.Orphans other-extensions: CPP build-depends: base >=4.12.0.0 && <4.21 , binary >=0.8.6.0 && <0.8.10 if !impl(ghc >=9.2) build-depends: OneTuple >=0.4.2 && <0.5 if impl(ghc >=8.0 && <9.4) build-depends: data-array-byte >=0.1.0.1 && <0.2 test-suite binary-orphans-test default-language: Haskell2010 type: exitcode-stdio-1.0 main-is: Tests.hs hs-source-dirs: test ghc-options: -Wall build-depends: base , binary , binary-orphans , OneTuple >=0.3 && <0.5 , QuickCheck >=2.13.1 && <2.16 , quickcheck-instances >=0.3.28 && <0.4 , tagged >=0.8.6 && <0.9 , tasty >=0.10.1.2 && <1.6 , tasty-quickcheck >=0.8.3.2 && <0.11 if impl(ghc >=8.0 && <9.4) build-depends: data-array-byte binary-orphans-1.0.5/src/Data/Binary/0000755000000000000000000000000007346545000015526 5ustar0000000000000000binary-orphans-1.0.5/src/Data/Binary/Orphans.hs0000644000000000000000000000552307346545000017501 0ustar0000000000000000{-# LANGUAGE CPP #-} {-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE FlexibleInstances #-} {-# LANGUAGE MagicHash #-} {-# LANGUAGE ScopedTypeVariables #-} {-# LANGUAGE UnboxedTuples #-} {-# LANGUAGE PolyKinds #-} {-# OPTIONS_GHC -Wno-orphans #-} module Data.Binary.Orphans () where import Data.Binary import Control.Monad (replicateM) #if MIN_VERSION_base(4,18,0) import Data.Tuple (Solo (MkSolo)) #elif MIN_VERSION_base(4,16,0) import Data.Tuple (Solo (Solo)) #define MkSolo Solo #else import Data.Tuple.Solo (Solo (MkSolo)) #endif import Data.Array.Byte (ByteArray (..), MutableByteArray (..)) import GHC.Exts (Int (..), indexWord8Array#, newByteArray#, sizeofByteArray#, unsafeFreezeByteArray#, writeWord8Array#) import GHC.ST (ST (..), runST) import GHC.Word (Word8 (..)) ------------------------------------------------------------------------------- -- future-binary ------------------------------------------------------------------------------- -- | @since 1.0.2 instance Binary a => Binary (Solo a) where put (MkSolo x) = put x get = fmap MkSolo get -- | @since 1.0.3 instance Binary ByteArray where put ba = put maxI >> go 0 where maxI :: Int maxI = sizeofByteArray ba go :: Int -> Put go i | i < maxI = put (indexByteArray ba i) >> go (i + 1) | otherwise = return () get = do len <- get xs <- replicateM len get return (byteArrayFromListN len xs) {-# INLINE sizeofByteArray #-} sizeofByteArray :: ByteArray -> Int sizeofByteArray (ByteArray ba) = I# (sizeofByteArray# ba) {-# INLINE indexByteArray #-} indexByteArray :: ByteArray -> Int -> Word8 indexByteArray (ByteArray ba) (I# i) = W8# (indexWord8Array# ba i) {-# INLINE byteArrayFromListN #-} byteArrayFromListN :: Int -> [Word8] -> ByteArray byteArrayFromListN len xs = runST $ do mba <- newByteArray len go mba 0 xs unsafeFreezeByteArray mba where go :: MutableByteArray s -> Int -> [Word8] -> ST s () go mba i ys | i < len = case ys of [] -> writeWord8Array mba i 0 >> go mba (i + 1) ys z:zs -> writeWord8Array mba i z >> go mba (i + 1) zs | otherwise = return () {-# INLINE newByteArray #-} newByteArray :: Int -> ST s (MutableByteArray s) newByteArray (I# len) = ST $ \s -> case newByteArray# len s of (# s', mba #) -> (# s', MutableByteArray mba #) {-# INLINE unsafeFreezeByteArray #-} unsafeFreezeByteArray :: MutableByteArray s -> ST s ByteArray unsafeFreezeByteArray (MutableByteArray mba) = ST $ \s -> case unsafeFreezeByteArray# mba s of (# s', ba #) -> (# s', ByteArray ba #) {-# INLINE writeWord8Array #-} writeWord8Array :: MutableByteArray s -> Int -> Word8 -> ST s () writeWord8Array (MutableByteArray mba) (I# i) (W8# w) = ST $ \s -> case writeWord8Array# mba i w s of s' -> (# s', () #) binary-orphans-1.0.5/test/0000755000000000000000000000000007346545000013621 5ustar0000000000000000binary-orphans-1.0.5/test/Tests.hs0000644000000000000000000000217407346545000015263 0ustar0000000000000000module Main (main) where import Data.Array.Byte (ByteArray) import Data.Binary (Binary, decode, encode) import Data.Binary.Orphans () import Data.Monoid (Sum) import Data.Proxy (Proxy (..)) import Data.Semigroup (Min (..)) import Data.Tuple.Solo (Solo (..)) import Numeric.Natural (Natural) import Test.QuickCheck (Property, (===)) import Test.QuickCheck.Instances () import Test.Tasty (TestTree, defaultMain, testGroup) import Test.Tasty.QuickCheck (testProperty) main :: IO () main = defaultMain tests tests :: TestTree tests = testGroup "Roundtrip" [ testProperty "Natural" $ roundtrip (Proxy :: Proxy Natural) , testProperty "Sum Int" $ roundtrip (Proxy :: Proxy (Sum Int)) , testProperty "Min Int" $ roundtrip (Proxy :: Proxy (Min Int)) , testProperty "Solo Int" $ roundtrip (Proxy :: Proxy (Solo Int)) , testProperty "ByteArray" $ roundtrip (Proxy :: Proxy ByteArray) ] roundtrip :: (Eq a, Show a, Binary a) => Proxy a -> a -> Property roundtrip _ x = x === decode (encode x)