summaryrefslogtreecommitdiffhomepage
path: root/Types.hs
diff options
context:
space:
mode:
Diffstat (limited to 'Types.hs')
-rw-r--r--Types.hs23
1 files changed, 23 insertions, 0 deletions
diff --git a/Types.hs b/Types.hs
index c3b5340..ec21254 100644
--- a/Types.hs
+++ b/Types.hs
@@ -12,6 +12,7 @@ module Types (
) where
import Val
+import Memory
import GHC.Generics (Generic)
import Data.Aeson
@@ -23,6 +24,9 @@ data Seen = Seen
}
deriving (Show, Generic)
+instance DataSize Seen where
+ dataSize = dataSize . seenData
+
-- | Things that the developer enters.
data Entered = Entered
{ enteredData :: Val
@@ -32,6 +36,9 @@ data Entered = Entered
}
deriving (Show, Generic)
+instance DataSize Entered where
+ dataSize e = dataSize (enteredData e) + dataSize (echoData e)
+
-- | High level protocol.
data Proto a
= Proto a
@@ -40,6 +47,10 @@ data Proto a
-- ^ sent by user to indicate when an Entered value was rejected.
deriving (Show, Generic)
+instance DataSize a => DataSize (Proto a) where
+ dataSize (Proto a) = dataSize a
+ dataSize (Rejected a) = dataSize a
+
-- | A Proto activity (either Entered or Seen) with a pointer
-- to the Activity before this one.
--
@@ -51,15 +62,27 @@ data Activity a = Activity
}
deriving (Show, Generic)
+instance DataSize a => DataSize (Activity a) where
+ dataSize a = dataSize (activity a)
+ + maybe 0 dataSize (prevActivity a)
+ + dataSize (signature a)
+
newtype Signature = Signature Val
deriving (Show, Generic)
+instance DataSize Signature where
+ dataSize _ = 42 -- FIXME real size here
+
data Hash = Hash
{ hashMethod :: HashMethod
, hashValue :: Val
}
deriving (Show, Generic, Eq)
+instance DataSize Hash where
+ dataSize (Hash { hashMethod = SHA256 }) = 64
+ dataSize (Hash { hashMethod = SHA3 }) = 56
+
-- | We use SHA256. (SHA3 is included to future proof, and because it
-- improves the generated JSON.)
data HashMethod = SHA256 | SHA3