summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoman Smrž <roman.smrz@seznam.cz>2024-10-09 20:59:35 +0200
committerRoman Smrž <roman.smrz@seznam.cz>2024-10-09 20:59:35 +0200
commit4a45d282d9b76d5858fe8df3dcd02b227e1e3f23 (patch)
tree96f6dca7665f0be409e5b7656c3d27213044cdd5
parent52c874ab42cd266d1b26ce1c045fcaf8eb410b32 (diff)
Handle unknown record item types
Changelog: Handle unknown record item types
-rw-r--r--src/Erebos/Storage.hs6
-rw-r--r--test/network.test19
-rw-r--r--test/storage.test22
3 files changed, 46 insertions, 1 deletions
diff --git a/src/Erebos/Storage.hs b/src/Erebos/Storage.hs
index 65210f9..cae333d 100644
--- a/src/Erebos/Storage.hs
+++ b/src/Erebos/Storage.hs
@@ -221,6 +221,7 @@ copyRecItem' st = \case
RecDate x -> return $ return $ RecDate x
RecUUID x -> return $ return $ RecUUID x
RecRef x -> fmap RecRef <$> copyRef' st x
+ RecUnknown t x -> return $ return $ RecUnknown t x
copyObject' :: forall c c'. (StorageCompleteness c, StorageCompleteness c') => Storage' c' -> Object' c -> IO (c (Object' c'))
copyObject' _ (Blob bs) = return $ return $ Blob bs
@@ -263,6 +264,7 @@ data RecItem' c
| RecDate ZonedTime
| RecUUID UUID
| RecRef (Ref' c)
+ | RecUnknown ByteString ByteString
deriving (Show)
type RecItem = RecItem' Complete
@@ -300,6 +302,7 @@ serializeRecItem name (RecBinary x) = [name, BC.pack ":b ", showHex x, BC.single
serializeRecItem name (RecDate x) = [name, BC.pack ":d", BC.singleton ' ', BC.pack (formatTime defaultTimeLocale "%s %z" x), BC.singleton '\n']
serializeRecItem name (RecUUID x) = [name, BC.pack ":u", BC.singleton ' ', U.toASCIIBytes x, BC.singleton '\n']
serializeRecItem name (RecRef x) = [name, BC.pack ":r ", showRef x, BC.singleton '\n']
+serializeRecItem name (RecUnknown t x) = [ name, BC.singleton ':', t, BC.singleton ' ', x, BC.singleton '\n' ]
lazyLoadObject :: forall c. StorageCompleteness c => Ref' c -> LoadResult c (Object' c)
lazyLoadObject = returnLoadResult . unsafePerformIO . ioLoadObject
@@ -352,7 +355,8 @@ unsafeDeserializeObject st bytes =
itype = B.take (space-colon-1) $ B.drop (colon+1) line
content = B.drop (space+1) line
- val <- case BC.unpack itype of
+ let val = fromMaybe (RecUnknown itype content) $
+ case BC.unpack itype of
"e" -> do guard $ B.null content
return RecEmpty
"i" -> do (num, rest) <- BC.readInteger content
diff --git a/test/network.test b/test/network.test
index 6f16f7d..40190f4 100644
--- a/test/network.test
+++ b/test/network.test
@@ -409,6 +409,12 @@ test SendUnknownObjectType:
""
expect /store-done ($refpat)/ capture r1
+ send:
+ "store rec"
+ "test:unknown TEST"
+ ""
+ expect /store-done ($refpat)/ capture r2
+
send "test-message-send 1 $r1"
expect /test-message-send done/
@@ -421,3 +427,16 @@ test SendUnknownObjectType:
local:
expect /load-(.*)/ capture done
guard (done == "done")
+
+ send "test-message-send 1 $r2"
+ expect /test-message-send done/
+
+ with p2:
+ expect /test-message-received rec [0-9]+ $r2/
+
+ send "load $r2"
+ expect /load-type rec [0-9]+/
+ expect /load-line test:unknown TEST/
+ local:
+ expect /load-(.*)/ capture done
+ guard (done == "done")
diff --git a/test/storage.test b/test/storage.test
index 2a53bb8..db9e0a1 100644
--- a/test/storage.test
+++ b/test/storage.test
@@ -496,3 +496,25 @@ test UnknownObjectType:
local:
expect /load-(.*)/ capture done
guard (done == "done")
+
+
+test UnknownRecordItemType:
+ let refpat = /blake2#[0-9a-f]*/
+
+ spawn as p
+ spawn as p2 on p.node
+
+ with p:
+ send:
+ "store rec"
+ "test:unknown TEST"
+ ""
+ expect /store-done ($refpat)/ capture r1
+
+ with p2:
+ send "load $r1"
+ expect /load-type rec [0-9]+/
+ expect /load-line test:unknown TEST/
+ local:
+ expect /load-(.*)/ capture done
+ guard (done == "done")