summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreyMulik <>2021-02-23 07:59:00 (GMT)
committerhdiff <hdiff@hdiff.luite.com>2021-02-23 07:59:00 (GMT)
commit8263583d8e17978996b43a428b21acf09a2667c4 (patch)
tree93aa5af51ecc674bb2687dcf2d6c7e1dfe9fdd40
version 0.2HEAD0.2master
-rw-r--r--LICENSE30
-rw-r--r--Setup.hs2
-rw-r--r--sdp-binary.cabal45
-rw-r--r--src/SDP/Binary.hs55
4 files changed, 132 insertions, 0 deletions
diff --git a/LICENSE b/LICENSE
new file mode 100644
index 0000000..819ce9a
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,30 @@
+Copyright Andrey Mulik (c) 2020
+
+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 Andrey Mulik 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.
diff --git a/Setup.hs b/Setup.hs
new file mode 100644
index 0000000..9a994af
--- /dev/null
+++ b/Setup.hs
@@ -0,0 +1,2 @@
+import Distribution.Simple
+main = defaultMain
diff --git a/sdp-binary.cabal b/sdp-binary.cabal
new file mode 100644
index 0000000..d0e7dea
--- /dev/null
+++ b/sdp-binary.cabal
@@ -0,0 +1,45 @@
+name: sdp-binary
+version: 0.2
+category: Data Structures
+
+synopsis: Binary instances for SDP
+description: SDP extension for binary serialisation.
+
+author: Andrey Mulik
+maintainer: work.a.mulik@gmail.com
+bug-reports: https://github.com/andreymulik/sdp-binary/issues
+
+copyright: 2020 Andrey Mulik
+license-file: LICENSE
+license: BSD3
+
+build-type: Simple
+cabal-version: >=1.10
+
+source-repository head
+ type: git
+ location: https://github.com/andreymulik/sdp-binary
+
+--- _ _____ ______ ______ ___ ______ __ __ ---
+--- | | |_ _|| ___ \| ___ \ / _ \ | ___ \\ \ / / ---
+--- | | | | | |_/ /| |_/ // /_\ \| |_/ / \ V / ---
+--- | | | | | ___ \| / | _ || / \ / ---
+--- | |____ _| |_ | |_/ /| |\ \ | | | || |\ \ | | ---
+--- \_____/ \___/ \____/ \_| \_|\_| |_/\_| \_| \_/ ---
+
+Library
+ default-language: Haskell2010
+ hs-source-dirs: src
+
+ build-depends:
+ base >= 4.12 && < 5,
+ sdp >= 0.2 && < 1,
+ binary >= 0.8 && < 1
+
+ ghc-options: -Wall -Wno-orphans -Wcompat
+
+ exposed-modules:
+ SDP.Binary
+
+
+
diff --git a/src/SDP/Binary.hs b/src/SDP/Binary.hs
new file mode 100644
index 0000000..99a53ae
--- /dev/null
+++ b/src/SDP/Binary.hs
@@ -0,0 +1,55 @@
+{-# LANGUAGE FlexibleInstances, MagicHash #-}
+
+{- |
+ Module : SDP.Binary
+ Copyright : (c) Andrey Mulik 2020
+ License : BSD-style
+ Maintainer : work.a.mulik@gmail.com
+ Portability : portable
+
+ @SDP.Binary@ provides @sdp@ instances for binary.
+-}
+module SDP.Binary
+(
+ -- * Export
+ module Data.Binary
+)
+where
+
+import Prelude ()
+import SDP.SafePrelude
+import SDP.Unboxed
+import SDP.Linear
+
+import SDP.Templates.AnyBorder
+import SDP.Templates.AnyChunks
+
+import SDP.Prim.SArray
+import SDP.Prim.SBytes
+
+import Data.Binary
+
+default ()
+
+--------------------------------------------------------------------------------
+
+instance (Binary e) => Binary (SArray# e)
+ where
+ get = do n <- get; fromListN n <$> replicateM n get
+ put = putList . listL
+
+instance (Binary e, Unboxed e) => Binary (SBytes# e)
+ where
+ get = do n <- get; fromListN n <$> replicateM n get
+ put = putList . listL
+
+instance (Nullable (rep e), Binary (rep e)) => Binary (AnyChunks rep e)
+ where
+ put = \ es -> let cs = toChunks es in do put (sizeOf cs); putList cs
+ get = do n <- get; fromChunks <$> replicateM n get
+
+instance (Binary i, Index i, Binary (rep e)) => Binary (AnyBorder rep i e)
+ where
+ put = \ (AnyBorder l u es) -> do put l; put u; put es
+ get = liftA3 AnyBorder get get get
+