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.) --- Types.hs | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) (limited to 'Types.hs') diff --git a/Types.hs b/Types.hs index e20228d..699fa59 100644 --- a/Types.hs +++ b/Types.hs @@ -2,8 +2,9 @@ {- | Main types for debug-me - - - Note that changing types in ways that change the JSON serialization - - changes debug-me's wire format. + - Note that changing types in ways that change the cereal serialization + - changes debug-me's wire format. Changing types in ways that change the + - aeson serialization changes debug-me's log format. -} module Types ( @@ -13,7 +14,7 @@ module Types ( import Val import Memory -import Json +import Serialization -- | Things that the developer sees. data Seen = Seen @@ -135,43 +136,56 @@ newtype GpgSig = GpgSig Val instance DataSize GpgSig where dataSize (GpgSig s) = dataSize s +instance Serialize Seen instance ToJSON Seen instance FromJSON Seen +instance Serialize Entered instance ToJSON Entered instance FromJSON Entered +instance Serialize (Activity Seen) instance ToJSON (Activity Seen) instance FromJSON (Activity Seen) +instance Serialize (Activity Entered) instance ToJSON (Activity Entered) instance FromJSON (Activity Entered) +instance Serialize Control instance ToJSON Control instance FromJSON Control +instance Serialize Hash instance ToJSON Hash instance FromJSON Hash +instance Serialize HashMethod instance ToJSON HashMethod instance FromJSON HashMethod +instance Serialize PublicKey instance ToJSON PublicKey instance FromJSON PublicKey +instance Serialize GpgSig instance ToJSON GpgSig instance FromJSON GpgSig +instance Serialize (Message Seen) instance ToJSON (Message Seen) where toJSON = genericToJSON sumOptions toEncoding = genericToEncoding sumOptions instance FromJSON (Message Seen) where parseJSON = genericParseJSON sumOptions +instance Serialize (Message Entered) instance ToJSON (Message Entered) where toJSON = genericToJSON sumOptions toEncoding = genericToEncoding sumOptions instance FromJSON (Message Entered) where parseJSON = genericParseJSON sumOptions +instance Serialize Signature instance ToJSON Signature where toJSON = genericToJSON sumOptions toEncoding = genericToEncoding sumOptions instance FromJSON Signature where parseJSON = genericParseJSON sumOptions +instance Serialize ControlAction instance ToJSON ControlAction where toJSON = genericToJSON sumOptions toEncoding = genericToEncoding sumOptions -- cgit v1.2.3