Skip to content

Commit

Permalink
[mmzk] (refactor)
Browse files Browse the repository at this point in the history
  • Loading branch information
MMZK1526 committed Apr 18, 2024
1 parent ee4e02f commit ef6177b
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Revision history for mmzk-typeid


## 0.6.0.2 -- Unreleased
## 0.6.0.0 -- Unreleased

* Update implementation to conform with specification v0.3.0.
* Allow `TypeID` prefix to contain underscores.
Expand Down
4 changes: 2 additions & 2 deletions mmzk-typeid.cabal
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
cabal-version: 2.4
name: mmzk-typeid
version: 0.5.0.2
version: 0.6.0.0

synopsis: A TypeID implementation for Haskell
description:
Expand Down Expand Up @@ -98,7 +98,7 @@ library
aeson >=2.1 && <3,
array ^>=0.5,
binary >=0.8.5 && <0.9,
bytestring ^>= 0.11,
bytestring ^>=0.11,
entropy ^>=0.4,
hashable ^>=1.4,
random ^>=1.2,
Expand Down
14 changes: 7 additions & 7 deletions src/Data/TypeID/Internal.hs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
{-# LANGUAGE UndecidableInstances #-}
-- |
-- Module : Data.TypeID.Internal
-- License : MIT
Expand Down Expand Up @@ -121,9 +120,9 @@ instance Binary (TypeID' version) where
uuid <- get
len <- getWord8
encodedPrefix <- separate5BitInts <$> replicateM (fromIntegral len) getWord8
when (length encodedPrefix > 63) $ fail "Binary: Prefix too long"
when (any (liftM2 (&&) (< 1) (> 26)) encodedPrefix)
(fail "Binary: Invalid prefix")
when (length encodedPrefix > 63) do fail "Binary: Prefix too long"
when (any (liftM2 (&&) (< 1) (> 26)) encodedPrefix) do
fail "Binary: Invalid prefix"
let back 27 = 95
back a = a + 96
pure $ TypeID' (decodeUtf8 . BS.pack $ fmap back encodedPrefix) uuid
Expand All @@ -146,8 +145,8 @@ instance Storable (TypeID' version) where
encodedPrefix <- separate5BitInts
<$> forM [1..len] \ix -> peekByteOff @Word8 ptr (16 + ix)
when (length encodedPrefix > 63) $ fail "Storable: Prefix too long"
when (any (liftM2 (&&) (< 1) (> 26)) encodedPrefix)
(fail "Storable: Invalid prefix")
when (any (liftM2 (&&) (< 1) (> 26)) encodedPrefix) do
fail "Storable: Invalid prefix"
let back 27 = 95
back a = a + 96
pure $ TypeID' (decodeUtf8 . BS.pack $ fmap back encodedPrefix) uuid
Expand Down Expand Up @@ -761,7 +760,8 @@ decodeUUID :: ByteString -> Either TypeIDError UUID
decodeUUID bs = do
unless (BSL.length bs == 26) $ Left TypeIDErrorUUIDError
unless (bs `BSL.index` 0 <= 55) $ Left TypeIDErrorUUIDError
when (any ((== 0xFF) . (base32Table !)) $ BSL.unpack bs) $ Left TypeIDErrorUUIDError
when (any ((== 0xFF) . (base32Table !)) $ BSL.unpack bs) do
Left TypeIDErrorUUIDError
pure $ unsafeDecodeUUID bs
{-# INLINE decodeUUID #-}

Expand Down

0 comments on commit ef6177b

Please sign in to comment.