About

Metadata

  • Last updated , by phadej
  • License BSD-3-Clause
  • Categories Web Development
  • Maintained by: Oleg Grenrus <oleg.grenrus@iki.fi>

  • Lottery factor: 0

Links

Installation

Tested Compilers

  1. 9.8.1
  2. 9.6.3
  3. 9.4.7
  4. 9.2.8
  5. 9.0.2
  6. 8.10.7
  7. 8.8.4
  8. 8.6.5
  9. 8.4.4
  10. 8.2.2
  11. 8.0.2
  12. 7.10.3

Readme

Structurally tag binary serialisation stream.

Say you have:

Say you have a data type

data Record = Record
  { _recordFields  :: HM.HashMap Text (Integer, ByteString)
  , _recordEnabled :: Bool
  }
  deriving (Eq, Show, Generic)

instance Binary Record
instance Structured Record

then you can serialise and deserialise Record values with a structure tag by simply

structuredEncode record :: LBS.ByteString
structuredDecode lbs    :: IO Record

If structure of Record changes in between, deserialisation will fail early.

The overhead is next to non-observable.

benchmarking encode/Binary
time                 352.8 μs   (349.5 μs .. 355.9 μs)

benchmarking encode/Tagged
time                 350.8 μs   (349.0 μs .. 353.1 μs)

benchmarking decode/Binary
time                 346.8 μs   (344.7 μs .. 349.9 μs)

benchmarking decode/Tagged
time                 353.8 μs   (352.0 μs .. 355.8 μs)