Permalink
Browse files

Added a reference writer to the Database class.

  • Loading branch information...
1 parent e9ccfb9 commit a351468704949b23084c5e251b8a2034740a4f63 @luqui committed Nov 17, 2008
Showing with 12 additions and 2 deletions.
  1. +12 −2 Udon/Database.hs
View
@@ -1,12 +1,14 @@
module Udon.Database
( Data(..)
, Database(..)
+ , writeRoot
)
where
import Udon.Hash
import Udon.Chunk
import Udon.DataDesc
+import Udon.DynRef
import Data.Binary
data Database m
@@ -23,8 +25,11 @@ writeChunk db chunk = store db (hashBlob enc) enc
where
enc = encode chunk
-writeDump :: (Monad m) => Database m -> Dump -> m ()
-writeDump db = \dump@(Dump rput _) -> go (hashBinary . snd . runChunkPut $ rput) dump
+writeDump :: (Monad m) => Database m -> Dump -> m Hash
+writeDump db = \dump@(Dump rput _) -> do
+ let hash = hashBinary . snd . runChunkPut $ rput
+ go hash dump
+ return hash
where
go hash (Dump rput subs) = do
exists <- fetch db hash
@@ -33,3 +38,8 @@ writeDump db = \dump@(Dump rput _) -> go (hashBinary . snd . runChunkPut $ rput)
Nothing -> do
store db hash (encode . snd . runChunkPut $ rput)
mapM_ (uncurry go) subs
+
+writeRoot :: (Monad m, Data a) => Database m -> DynType a -> ExtRef a -> m DynRef
+writeRoot db dyntype ref = do
+ hash <- writeDump db $ ddDump desc ref
+ return $ unsafeExtRefToDynRef dyntype ref

0 comments on commit a351468

Please sign in to comment.