BSON.hs: docs for functions missing such

This commit is contained in:
Scott R. Parish 2010-03-15 07:17:57 -05:00
parent 5b8b7b5dce
commit e76012d227

View file

@ -67,7 +67,7 @@ import Numeric
import System.IO.Unsafe import System.IO.Unsafe
import System.Posix.Process import System.Posix.Process
-- | BsonValue is the type that can be used as a key in a 'BsonDoc'. -- | BsonValue is the type that can be used as a value in a 'BsonDoc'.
data BsonValue data BsonValue
= BsonDouble Double = BsonDouble Double
| BsonString L8.ByteString | BsonString L8.ByteString
@ -155,12 +155,15 @@ globalObjectIdInc :: IORef Integer
{-# NOINLINE globalObjectIdInc #-} {-# NOINLINE globalObjectIdInc #-}
globalObjectIdInc = unsafePerformIO (newIORef 0) globalObjectIdInc = unsafePerformIO (newIORef 0)
-- | Create a new 'ObjectIdGen', the structure that must be passed to
-- genObjectId to create a 'ObjectId'.
mkObjectIdGen :: IO ObjectIdGen mkObjectIdGen :: IO ObjectIdGen
mkObjectIdGen = do mkObjectIdGen = do
host <- liftM (fst . (!! 0) . readHex . List.take 6 . md5sum . C8.pack) host <- liftM (fst . (!! 0) . readHex . List.take 6 . md5sum . C8.pack)
getHostName getHostName
return ObjectIdGen {oigMachine = host, oigInc = globalObjectIdInc} return ObjectIdGen {oigMachine = host, oigInc = globalObjectIdInc}
-- | Create a new 'ObjectId'.
genObjectId :: ObjectIdGen -> IO BsonValue genObjectId :: ObjectIdGen -> IO BsonValue
genObjectId oig = do genObjectId oig = do
now <- liftM (truncate . (realToFrac :: POSIXTime -> Double)) getPOSIXTime now <- liftM (truncate . (realToFrac :: POSIXTime -> Double)) getPOSIXTime
@ -172,9 +175,11 @@ genObjectId oig = do
(0xffff .&. pid) `shiftL` 24 .|. (0xffff .&. pid) `shiftL` 24 .|.
(inc `div` 0x100) `shiftL` 8 .|. (inc `rem` 0x100)) (inc `div` 0x100) `shiftL` 8 .|. (inc `rem` 0x100))
-- | Decode binary bytes into 'BsonDoc'.
getBsonDoc :: Get BsonDoc getBsonDoc :: Get BsonDoc
getBsonDoc = liftM snd getDoc getBsonDoc = liftM snd getDoc
-- | Encode 'BsonDoc' into binary bytes.
putBsonDoc :: BsonDoc -> Put putBsonDoc :: BsonDoc -> Put
putBsonDoc = putObj putBsonDoc = putObj