Skip to content

Commit

Permalink
Merge pull request #237 from input-output-hk/serialise_packed_bytes
Browse files Browse the repository at this point in the history
Serialise packed bytes
  • Loading branch information
nc6 committed Sep 16, 2021
2 parents 39f9cf0 + bb35fcc commit 592aa61
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
1 change: 1 addition & 0 deletions cardano-crypto-class/cardano-crypto-class.cabal
Expand Up @@ -103,6 +103,7 @@ library
, memory
, nothunks
, primitive
, serialise
, text
, transformers
, vector
Expand Down
7 changes: 7 additions & 0 deletions cardano-crypto-class/src/Cardano/Crypto/PackedBytes.hs
Expand Up @@ -20,6 +20,9 @@ module Cardano.Crypto.PackedBytes
, xorPackedBytes
) where

import Codec.Serialise (Serialise(..))
import Codec.Serialise.Decoding (decodeBytes)
import Codec.Serialise.Encoding (encodeBytes)
import Control.DeepSeq
import Control.Monad.Primitive
import Data.Bits
Expand Down Expand Up @@ -84,6 +87,10 @@ instance NFData (PackedBytes n) where
rnf PackedBytes32 {} = ()
rnf PackedBytes# {} = ()

instance Serialise (PackedBytes n) where
encode = encodeBytes . unpackPinnedBytes
decode = packPinnedBytesN <$> decodeBytes

xorPackedBytes :: PackedBytes n -> PackedBytes n -> PackedBytes n
xorPackedBytes (PackedBytes8 x) (PackedBytes8 y) = PackedBytes8 (x `xor` y)
xorPackedBytes (PackedBytes28 x0 x1 x2 x3) (PackedBytes28 y0 y1 y2 y3) =
Expand Down

0 comments on commit 592aa61

Please sign in to comment.