armor-0.1: Armor data structures against serialization backwards compatibility problems

Safe HaskellSafe




newtype Version a Source #

Version numbers are simple monotonically increasing positive integers.





Eq (Version a) Source # 


(==) :: Version a -> Version a -> Bool #

(/=) :: Version a -> Version a -> Bool #

Ord (Version a) Source # 


compare :: Version a -> Version a -> Ordering #

(<) :: Version a -> Version a -> Bool #

(<=) :: Version a -> Version a -> Bool #

(>) :: Version a -> Version a -> Bool #

(>=) :: Version a -> Version a -> Bool #

max :: Version a -> Version a -> Version a #

min :: Version a -> Version a -> Version a #

Read (Version a) Source # 
Show (Version a) Source # 


showsPrec :: Int -> Version a -> ShowS #

show :: Version a -> String #

showList :: [Version a] -> ShowS #

class Armored a where Source #

Core type class for armoring types. Includes a version and all the type's serializations that you want to armor.

Minimal complete definition

version, serializations


version :: Version a Source #

Current version number for the data type.

serializations :: Map String (APrism' ByteString a) Source #

Map of serializations keyed by a unique ID used to refer to each serialization. A serialization is a tuple of (a -> ByteString) and (ByteString -> Maybe a). Represented here as a prism.

data ArmorConfig Source #

Config data for armor tests.




  • acArmorMode :: ArmorMode
  • acStoreDir :: FilePath

    Directory where all the test serializations are stored.

  • acNumVersions :: Maybe Word

    How many versions back to test for backwards compatibility. A value of Just 0 means that it only tests that the current version satisfies parse . render == id. Just 1 means that it will verify that the previous version can still be parse. Just 2 the previous two versions, etc. Nothing means that all versions will be tested.

defArmorConfig :: ArmorConfig Source #

Default value for ArmorConfig.

testArmor :: (Eq a, Show a, Typeable a, Armored a) => ArmorConfig -> String -> a -> Test Source #

Tests the serialization backwards compatibility of a data type by storing serialized representations in .test files to be checked into your project's version control.

First, this function checks the directory acStoreDir for the existence of a file foo-000.test. If it doesn't exist, it creates it for each serialization with the serialized representation of the val parameter.

Next, it checks that the serialized formats in the most recent acNumVersions of the stored .test files are parsable by the current version of the serialization.