Skip to content

Commit 4123d96

Browse files
committed
remote: delete obsolete serialization prims and instances
1 parent 28d279b commit 4123d96

File tree

5 files changed

+48
-508
lines changed

5 files changed

+48
-508
lines changed

hnix-store-remote/hnix-store-remote.cabal

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,6 @@ library
8181
, System.Nix.Store.Remote.Client.Core
8282
, System.Nix.Store.Remote.Logger
8383
, System.Nix.Store.Remote.MonadStore
84-
, System.Nix.Store.Remote.Serialize
85-
, System.Nix.Store.Remote.Serialize.Prim
8684
, System.Nix.Store.Remote.Serializer
8785
, System.Nix.Store.Remote.Server
8886
, System.Nix.Store.Remote.Socket
@@ -174,7 +172,6 @@ test-suite remote
174172
Data.SerializerSpec
175173
EnumSpec
176174
NixSerializerSpec
177-
SerializeSpec
178175
build-tool-depends:
179176
hspec-discover:hspec-discover
180177
build-depends:
@@ -183,14 +180,11 @@ test-suite remote
183180
, hnix-store-remote
184181
, hnix-store-tests
185182
, bytestring
186-
, cereal
187183
, crypton
188184
, some > 1.0.5 && < 2
189-
, text
190185
, time
191186
, hspec
192187
, QuickCheck
193-
, unordered-containers
194188

195189
test-suite remote-io
196190
import: tests

hnix-store-remote/src/Data/Serializer/Example.hs

Lines changed: 48 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,19 @@ import Data.ByteString (ByteString)
3939
import Data.Int (Int8)
4040
import Data.GADT.Show (GShow(..), defaultGshowsPrec)
4141
import Data.Kind (Type)
42-
import Data.Type.Equality
43-
import Data.Serialize.Get (getInt8)
44-
import Data.Serialize.Put (putInt8)
42+
import Data.Type.Equality (TestEquality(..), (:~:)(Refl))
43+
import Data.Serialize.Get (Get, getInt8)
44+
import Data.Serialize.Put (Putter, PutM, putInt8)
4545
import Data.Serializer
46+
( Serializer(..)
47+
, GetSerializerError
48+
, runGetS
49+
, runPutS
50+
, transformGetError
51+
, transformPutError
52+
)
4653
import Data.Some (Some(..))
47-
import GHC.Generics
48-
import System.Nix.Store.Remote.Serialize.Prim (getBool, putBool, getEnum, putEnum)
54+
import GHC.Generics (Generic)
4955

5056
import Test.QuickCheck (Arbitrary(..), oneof)
5157

@@ -274,3 +280,40 @@ cmdSRest = Serializer
274280
else lift (putInt8 i)
275281
Some (Cmd_Bool b) -> putS opcode OpCode_Bool >> lift (putBool b)
276282
}
283+
284+
-- Primitives helpers
285+
286+
getInt :: Integral a => Get a
287+
getInt = fromIntegral <$> getInt8
288+
289+
putInt :: Integral a => Putter a
290+
putInt = putInt8 . fromIntegral
291+
292+
-- | Deserialize @Bool@ from integer
293+
getBool :: Get Bool
294+
getBool = (getInt :: Get Int8) >>= \case
295+
0 -> pure False
296+
1 -> pure True
297+
x -> fail $ "illegal bool value " ++ show x
298+
299+
-- | Serialize @Bool@ into integer
300+
putBool :: Putter Bool
301+
putBool True = putInt (1 :: Int8)
302+
putBool False = putInt (0 :: Int8)
303+
304+
-- | Utility toEnum version checking bounds using Bounded class
305+
toEnumCheckBounds :: Enum a => Int -> Either String a
306+
toEnumCheckBounds = \case
307+
x | x < minBound -> Left $ "enum out of min bound " ++ show x
308+
x | x > maxBound -> Left $ "enum out of max bound " ++ show x
309+
x | otherwise -> Right $ toEnum x
310+
311+
-- | Deserialize @Enum@ to integer
312+
getEnum :: Enum a => Get a
313+
getEnum =
314+
toEnumCheckBounds <$> getInt
315+
>>= either fail pure
316+
317+
-- | Serialize @Enum@ to integer
318+
putEnum :: Enum a => Putter a
319+
putEnum = putInt . fromEnum

hnix-store-remote/src/System/Nix/Store/Remote/Serialize.hs

Lines changed: 0 additions & 185 deletions
This file was deleted.

0 commit comments

Comments
 (0)