summaryrefslogtreecommitdiffhomepage
path: root/Serialization.hs
diff options
context:
space:
mode:
authorJoey Hess <joeyh@joeyh.name>2017-04-21 12:16:38 -0400
committerJoey Hess <joeyh@joeyh.name>2017-04-21 13:19:06 -0400
commite336a4fdf3d55f01b8c2871ceb906544a493eeb7 (patch)
treeb3af043b4323b0f353baef44439d786ae6d55bd2 /Serialization.hs
parentc4a04ead453bf783b79c5c0b263f657275794b25 (diff)
downloaddebug-me-e336a4fdf3d55f01b8c2871ceb906544a493eeb7.tar.gz
use cereal for efficient serialization for wire format
I tried both binary and cereal. For a ActivityMessage that takes 341 bytes in JSON and has a dataSize of 129, both used 165 bytes. Went with cereal since lazy bytestrings are not needed, and I might want to use https://hackage.haskell.org/package/safecopy later. (Perhaps I should be using protocol buffers or something to make it easier for non-haskell implementations? But that would complicate things a lot.)
Diffstat (limited to 'Serialization.hs')
-rw-r--r--Serialization.hs15
1 files changed, 15 insertions, 0 deletions
diff --git a/Serialization.hs b/Serialization.hs
new file mode 100644
index 0000000..6940550
--- /dev/null
+++ b/Serialization.hs
@@ -0,0 +1,15 @@
+module Serialization (
+ module Data.Aeson,
+ Serialize,
+ Generic,
+ sumOptions
+) where
+
+import GHC.Generics (Generic)
+import Data.Serialize
+import Data.Aeson
+import qualified Data.Aeson.Types as Aeson
+
+-- | Nicer JSON encoding for sum types.
+sumOptions :: Aeson.Options
+sumOptions = defaultOptions { Aeson.sumEncoding = Aeson.ObjectWithSingleField }