From e336a4fdf3d55f01b8c2871ceb906544a493eeb7 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Fri, 21 Apr 2017 12:16:38 -0400 Subject: 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.) --- Val.hs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'Val.hs') diff --git a/Val.hs b/Val.hs index 40e718b..80ab8ed 100644 --- a/Val.hs +++ b/Val.hs @@ -3,9 +3,9 @@ module Val where import Memory +import Serialization import GHC.Generics (Generic) -import Data.Aeson import Data.Aeson.Types import qualified Codec.Binary.Base64 as B64 import qualified Data.Text as T @@ -19,6 +19,8 @@ newtype Val = Val { val :: B.ByteString } instance DataSize Val where dataSize (Val b) = fromIntegral (B.length b) +instance Serialize Val + -- | JSON instances for Val, using base64 encoding when the value -- is not utf-8 encoded, and otherwise using a more efficient encoding. instance ToJSON Val where -- cgit v1.2.3