serokell-util 0.1.5.3 → 0.2.0.0
raw patch · 4 files changed
+2/−63 lines, 4 filesdep −data-msgpackPVP ok
version bump matches the API change (PVP)
Dependencies removed: data-msgpack
API changes (from Hackage documentation)
Files
- serokell-util.cabal +1/−3
- src/Serokell/Data/Variant/Serialization.hs +0/−39
- test/Test/Serokell/Data/Variant/VariantSpec.hs +1/−18
- test/Test/Serokell/Util/ByteStringSpec.hs +0/−3
serokell-util.cabal view
@@ -1,5 +1,5 @@ name: serokell-util-version: 0.1.5.3+version: 0.2.0.0 synopsis: General-purpose functions by Serokell homepage: https://github.com/serokell/serokell-util license: MIT@@ -68,7 +68,6 @@ , cereal-vector , clock , containers- , data-msgpack >= 0.0.8 , deepseq , directory , either@@ -122,7 +121,6 @@ , bytestring , cereal , hspec >= 2.1.10- , data-msgpack >= 0.0.8 , QuickCheck >= 2.8.1 , quickcheck-instances , safecopy >= 0.9.0.1
src/Serokell/Data/Variant/Serialization.hs view
@@ -14,13 +14,11 @@ import Data.Hashable (Hashable) import Data.HashMap.Strict (HashMap) import qualified Data.HashMap.Strict as HM hiding (HashMap)-import qualified Data.MessagePack as MP import Data.SafeCopy (SafeCopy) import Data.Scientific (floatingOrInteger) import qualified Data.Serialize as Cereal import Data.Text (Text) import qualified Data.Text.Encoding as TE-import qualified Data.Vector as V import Data.Vector.Serialize () import Serokell.Data.Variant.Variant (VarMap, Variant (..))@@ -101,43 +99,6 @@ instance Cereal.Serialize Variant instance SafeCopy Variant---- —————————MessagePack serialization————————— ----- MessagePack data structure is very close to Variant. However, note that:--- 1. MessagePack distinguishes between Float and Double while we don't.--- 2. ObjectExt can't be decoded.--instance MP.MessagePack Variant where- toObject VarNone = MP.ObjectNil- toObject (VarBool v) = MP.ObjectBool v- toObject (VarInt v) = MP.ObjectInt $ fromIntegral v- toObject (VarUInt v) = MP.ObjectWord $ fromIntegral v- toObject (VarFloat v) = MP.ObjectDouble v- toObject (VarBytes v) = MP.ObjectBin v- toObject (VarString v) = MP.ObjectStr v- toObject (VarList v) = MP.ObjectArray . fmap MP.toObject . V.toList $ v- toObject (VarMap v) =- MP.ObjectMap .- fmap (bimap MP.toObject MP.toObject) . HM.toList $- v- fromObject MP.ObjectNil = pure VarNone- fromObject (MP.ObjectBool v) = pure . VarBool $ v- fromObject (MP.ObjectInt v) = pure . VarInt $ v- fromObject (MP.ObjectWord v) = pure . VarUInt $ v- fromObject (MP.ObjectFloat v) = pure . VarFloat . realToFrac $ v- fromObject (MP.ObjectDouble v) = pure . VarFloat $ v- fromObject (MP.ObjectStr v) = pure . VarString $ v- fromObject (MP.ObjectBin v) = pure . VarBytes $ v- fromObject (MP.ObjectArray v) = fmap (VarList . V.fromList)- . mapM MP.fromObject- $ v- fromObject (MP.ObjectMap v) =- fmap (VarMap . HM.fromList) .- mapM- (\(a,b) ->- (,) <$> MP.fromObject a <*> MP.fromObject b) $- v- fromObject (MP.ObjectExt _ _) = fail "Can't deserialize ObjectExt" -- —————————Binary serialization————————— -- -- Here we use Generic support, it should be good enough.
test/Test/Serokell/Data/Variant/VariantSpec.hs view
@@ -8,7 +8,6 @@ import qualified Data.Aeson as A (decode, encode) import qualified Data.Binary as B (decode, encode) import qualified Data.HashMap.Lazy as HM (elems, fromList, keys)-import Data.MessagePack (fromObject, toObject) import qualified Data.SafeCopy as SC (safeGet, safePut) import Data.Scientific (floatingOrInteger, fromFloatDigits) import qualified Data.Serialize as C (decode, encode, runGet, runPut)@@ -18,8 +17,7 @@ import Test.Hspec.QuickCheck (prop) import Test.QuickCheck ((===)) -import Serokell.Arbitrary (VariantNoBytes (..),- VariantOnlyBytes (..))+import Serokell.Arbitrary (VariantNoBytes (..), VariantOnlyBytes (..)) import qualified Serokell.Data.Variant as S import qualified Serokell.Util.Base64 as S import Serokell.Util.Text (show')@@ -32,8 +30,6 @@ \(getVariant -> a) -> (jsonFixer a) === jsonMid a prop "Variant (Only VarBytes)" $ \(getVarBytes -> a) -> a === (bytesFun $ jsonMid a)- prop "MessagePack" $- \(a :: S.Variant) -> (msgPkFixer a) === msgPkMid a prop "Binary" $ \(a :: S.Variant) -> a === binMid a prop "SafeCopy" $@@ -73,19 +69,6 @@ where right = either (error . unpack) id $ S.decode s bytesFun _ = error "[bytesFun:] called with Variant that was not VarBytes"--msgPkFixer :: S.Variant -> S.Variant-msgPkFixer (S.VarMap m) = let ks = map msgPkFixer $ HM.keys m- vs = map msgPkFixer $ HM.elems m- m' = HM.fromList $ zip ks vs- in S.VarMap m'-msgPkFixer (S.VarList l) = S.VarList $ V.map msgPkFixer l-msgPkFixer v = v--msgPkMid :: S.Variant -> S.Variant-msgPkMid = maybe err id . fromObject . toObject- where- err = error "[VariantSpec] Failed MessagePack decoding" binMid :: S.Variant -> S.Variant binMid = B.decode . B.encode
test/Test/Serokell/Util/ByteStringSpec.hs view
@@ -17,9 +17,6 @@ import qualified Serokell.Util.Base16 as C16 import qualified Serokell.Util.Base64 as C64 -deriving instance Eq C64.JsonByteString-deriving instance Show C64.JsonByteString- spec :: Spec spec = describe "Serialization" $ do