git.iko.soy/typeable/flat-instances
on master help sign in
3 files changed+35−1
since splitsnapshots
unifiedsplit
flat-instances.cabal+13 src/Flat/Orphans.hs+3−1 src/Flat/Servant.hs+19
flat-instances.cabal+13
@@ -4,6 +4,11 @@ name: flat-instances
44version: 0.1.0.0
55license-file: LICENSE
66
7+Flag flat-servant
8+ Description: Enable Flat serialization support
9+ Default: True
10+ Manual: False
11+
712library
813 exposed-modules:
914 Flat.Orphans
@@ -11,6 +16,14 @@ library
1116 base,
1217 flat,
1318 time,
19+ vector
20+ if flag(flat-servant)
21+ exposed-modules:
22+ Flat.Servant
23+ build-depends:
24+ bytestring,
25+ servant
26+
1427 hs-source-dirs:
1528 src
1629 default-language:
src/Flat/Orphans.hs+3−1
@@ -3,11 +3,11 @@
33{-# LANGUAGE StandaloneDeriving #-}
44{-# OPTIONS_GHC -fno-warn-orphans #-}
55
6−
76module Flat.Orphans where
87
98import Data.Fixed
109import Data.Time
10+import Data.Vector
1111import Flat as F
1212
1313
@@ -65,3 +65,5 @@ instance Flat ZonedTime where
6565 size = F.size . zonedTimeToTuple
6666 encode = F.encode . zonedTimeToTuple
6767 decode = uncurry ZonedTime <$> F.decode
68+
69+deriving via (AsArray (Vector a)) instance Flat a => Flat (Vector a)
src/Flat/Servant.hsnew file+19
@@ -0,0 +1,19 @@
1+{-# LANGUAGE FlexibleInstances, MultiParamTypeClasses, OverloadedStrings #-}
2+module Flat.Servant where
3+
4+import Data.Bifunctor
5+import Data.ByteString.Lazy
6+import Flat as F
7+import Servant.API
8+
9+
10+data FlatBinary
11+
12+instance Accept FlatBinary where
13+ contentType _ = "application/octet-stream"
14+
15+instance Flat a => MimeRender FlatBinary a where
16+ mimeRender _ = fromStrict . F.flat
17+
18+instance Flat a => MimeUnrender FlatBinary a where
19+ mimeUnrender _ = first show . F.unflat