binary-tagged

Tagged binary serialisation.

Version on this page:0.3.1@rev:3
LTS Haskell 22.39:0.3.1@rev:4
Stackage Nightly 2024-10-31:0.3.1@rev:4
Latest on Hackage:0.3.1@rev:4

See all snapshots binary-tagged appears in

BSD-3-Clause licensed and maintained by Oleg Grenrus
This version can be pinned in stack with:binary-tagged-0.3.1@sha256:38b438815eb11d9b0180fbcf4d51d3887da7ed4c707de8ebf387ca29d3e60be5,3281

Module documentation for 0.3.1

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)

Changes

  • 0.3.1 (2021-10-10)

    • Support aeson-2.0.0.0
  • 0.3 (2020-05-16)

    • Major rewrite: use structured.
  • 0.2 (2019-05-14)

    • use cryptohash-sha1, types of structuralInfoSha1Digest and structuralInfoSha1Digest are changed.
    • Use binary-instances in tests
  • 0.1.5.2 (2019-05-10)

    • generics-sop-0.5
  • 0.1.5.1 (2018-09-24)

    • GHC-8.6.1
  • 0.1.5 (2018-05-20)

    • GHC-8.4.2
    • Don’t depend on nats and semigroups on newer GHC
  • 0.1.4.2 (2016-12-05)

    • Fix compilation with generics-sop-0.2.3.0
  • 0.1.4.1 (2016-09-20)

    • Print mismatching hashes in base16 encoding
  • 0.1.4.0 (2016-04-12)

    • Add semigroups types
    • Add Natural
  • 0.1.3.1 (2016-02-10)

    • Support GHC 8.0
  • 0.1.3.0 (2015-10-24)

    • Support generics-sop-0.2
  • 0.1.2.0 (2015-10-06)

    • Add tuple HasSemanticVersion instances
    • Add instances for
      • ()
      • Float
      • Double
      • Version`
      • Fixed
      • Ordering
    • Fix Interleave & SumUpTo, introduce Div2
  • 0.1.1.0

    • Add instances
      • Ratio
      • Word
      • HasSemanticVersion for primitive types