summaryrefslogtreecommitdiff
path: root/Coolbal/DataVersionTag.hs
diff options
context:
space:
mode:
Diffstat (limited to 'Coolbal/DataVersionTag.hs')
-rw-r--r--Coolbal/DataVersionTag.hs22
1 files changed, 22 insertions, 0 deletions
diff --git a/Coolbal/DataVersionTag.hs b/Coolbal/DataVersionTag.hs
new file mode 100644
index 0000000..a994e90
--- /dev/null
+++ b/Coolbal/DataVersionTag.hs
@@ -0,0 +1,22 @@
+{-# LANGUAGE DataKinds #-}
+{-# LANGUAGE KindSignatures #-}
+{-# LANGUAGE ScopedTypeVariables #-}
+{-# LANGUAGE TypeFamilies #-}
+{-# LANGUAGE TypeOperators #-}
+module Coolbal.DataVersionTag where
+
+import Data.Binary
+import GHC.TypeNats
+
+
+data DataVersionTag (n :: Nat) = DataVersionTag
+ deriving (Show, Eq, Ord)
+
+instance (KnownNat n, n <= 255) => Binary (DataVersionTag n) where
+ put v = putWord8 (fromIntegral (natVal v))
+ get = do
+ b <- getWord8
+ let result = DataVersionTag :: DataVersionTag n
+ if b == fromIntegral (natVal result)
+ then return result
+ else fail ("DataVersionTag: read version " ++ show b ++ ", application expects version " ++ show (natVal result))