@@ -310,9 +310,16 @@ openLevels reg hfs hbio conf@TableConfig{..} uc sessionRoot resolve levels =
310310class Encode a where
311311 encode :: a -> Encoding
312312
313+ -- | Decoder that is not parameterised by a 'SnapshotVersion'.
314+ --
315+ -- Used only for 'SnapshotVersion' and 'Versioned', which live outside the
316+ -- 'SnapshotMetaData' type hierachy.
313317class Decode a where
314318 decode :: Decoder s a
315319
320+ -- | Decoder parameterised by a 'SnapshotVersion'.
321+ --
322+ -- Used for every type in the 'SnapshotMetaData' type hierarchy.
316323class DecodeVersioned a where
317324 decodeVersioned :: SnapshotVersion -> Decoder s a
318325
@@ -331,6 +338,8 @@ instance Encode a => Encode (Versioned a) where
331338 <> encode currentSnapshotVersion
332339 <> encode x
333340
341+ -- | Decodes a 'SnapshotVersion' first, and then passes that into the versioned
342+ -- decoder for @a@.
334343instance DecodeVersioned a => Decode (Versioned a ) where
335344 decode = do
336345 _ <- decodeListLenOf 2
@@ -339,8 +348,8 @@ instance DecodeVersioned a => Decode (Versioned a) where
339348 Right () -> pure ()
340349 Left errMsg ->
341350 fail $
342- printf " Incompatible version found. Version %s is not backwards \
343- \compatible with version %s : %s"
351+ printf " Incompatible snapshot format version found. Version %s \
352+ \is not backwards compatible with version %s : %s"
344353 (prettySnapshotVersion currentSnapshotVersion)
345354 (prettySnapshotVersion version)
346355 errMsg
@@ -362,7 +371,7 @@ instance Decode SnapshotVersion where
362371 ver <- decodeWord
363372 case ver of
364373 0 -> pure V0
365- _ -> fail (" Unknown version number: " <> show ver)
374+ _ -> fail (" Unknown snapshot format version number: " <> show ver)
366375
367376{- ------------------------------------------------------------------------------
368377 Encoding and decoding: SnapshotMetaData
@@ -396,12 +405,11 @@ instance DecodeVersioned SnapshotLabel where
396405-- TableType
397406
398407instance Encode SnapshotTableType where
399- encode SnapNormalTable = encodeListLen 1 <> encodeWord 0
400- encode SnapMonoidalTable = encodeListLen 1 <> encodeWord 1
408+ encode SnapNormalTable = encodeWord 0
409+ encode SnapMonoidalTable = encodeWord 1
401410
402411instance DecodeVersioned SnapshotTableType where
403412 decodeVersioned V0 = do
404- _ <- decodeListLenOf 1
405413 tag <- decodeWord
406414 case tag of
407415 0 -> pure SnapNormalTable
@@ -446,12 +454,10 @@ instance DecodeVersioned TableConfig where
446454-- MergePolicy
447455
448456instance Encode MergePolicy where
449- encode MergePolicyLazyLevelling =
450- encodeListLen 1 <> encodeWord 0
457+ encode MergePolicyLazyLevelling = encodeWord 0
451458
452459instance DecodeVersioned MergePolicy where
453460 decodeVersioned V0 = do
454- _ <- decodeListLenOf 1
455461 tag <- decodeWord
456462 case tag of
457463 0 -> pure MergePolicyLazyLevelling
@@ -460,7 +466,7 @@ instance DecodeVersioned MergePolicy where
460466-- SizeRatio
461467
462468instance Encode SizeRatio where
463- encode Four = encodeWord64 4
469+ encode Four = encodeInt 4
464470
465471instance DecodeVersioned SizeRatio where
466472 decodeVersioned V0 = do
@@ -523,12 +529,11 @@ instance DecodeVersioned BloomFilterAlloc where
523529-- FencePointerIndex
524530
525531instance Encode FencePointerIndex where
526- encode CompactIndex = encodeListLen 1 <> encodeWord 0
527- encode OrdinaryIndex = encodeListLen 1 <> encodeWord 1
532+ encode CompactIndex = encodeWord 0
533+ encode OrdinaryIndex = encodeWord 1
528534
529535instance DecodeVersioned FencePointerIndex where
530536 decodeVersioned V0 = do
531- _ <- decodeListLenOf 1
532537 tag <- decodeWord
533538 case tag of
534539 0 -> pure CompactIndex
@@ -562,12 +567,11 @@ instance DecodeVersioned DiskCachePolicy where
562567-- MergeSchedule
563568
564569instance Encode MergeSchedule where
565- encode OneShot = encodeListLen 1 <> encodeWord 0
566- encode Incremental = encodeListLen 1 <> encodeWord 1
570+ encode OneShot = encodeWord 0
571+ encode Incremental = encodeWord 1
567572
568573instance DecodeVersioned MergeSchedule where
569574 decodeVersioned V0 = do
570- _ <- decodeListLenOf 1
571575 tag <- decodeWord
572576 case tag of
573577 0 -> pure OneShot
@@ -659,12 +663,11 @@ instance DecodeVersioned NumRuns where
659663-- MergePolicyForLevel
660664
661665instance Encode MergePolicyForLevel where
662- encode LevelTiering = encodeListLen 1 <> encodeWord 0
663- encode LevelLevelling = encodeListLen 1 <> encodeWord 1
666+ encode LevelTiering = encodeWord 0
667+ encode LevelLevelling = encodeWord 1
664668
665669instance DecodeVersioned MergePolicyForLevel where
666670 decodeVersioned V0 = do
667- _ <- decodeListLenOf 1
668671 tag <- decodeWord
669672 case tag of
670673 0 -> pure LevelTiering
@@ -706,12 +709,11 @@ instance DecodeVersioned TotalCredits where
706709 -- Merge.Level
707710
708711instance Encode Merge. Level where
709- encode Merge. MidLevel = encodeListLen 1 <> encodeWord 0
710- encode Merge. LastLevel = encodeListLen 1 <> encodeWord 1
712+ encode Merge. MidLevel = encodeWord 0
713+ encode Merge. LastLevel = encodeWord 1
711714
712715instance DecodeVersioned Merge. Level where
713716 decodeVersioned V0 = do
714- _ <- decodeListLenOf 1
715717 tag <- decodeWord
716718 case tag of
717719 0 -> pure Merge. MidLevel
0 commit comments