Skip to content

Commit

Permalink
Print ObjectId numbers as hex instead of decimal
Browse files Browse the repository at this point in the history
  • Loading branch information
Tony Hannan committed May 23, 2010
1 parent a3975aa commit 673ed98
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions Data/Bson.hs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import Data.List (find)
import Data.Bits (shift, (.|.))
import Data.ByteString.Char8 (ByteString, pack)
import Data.Digest.OpenSSL.MD5 (md5sum)
import Numeric (readHex)
import Numeric (readHex, showHex)
import Network.BSD (getHostName)
import System.Posix.Process (getProcessID)
import System.IO.Unsafe (unsafePerformIO)
Expand Down Expand Up @@ -302,9 +302,12 @@ data MinMaxKey = MinKey | MaxKey deriving (Typeable, Show, Read, Eq)

-- * ObjectId

data ObjectId = Oid Word32 Word64 deriving (Typeable, Show, Read, Eq, Ord)
data ObjectId = Oid Word32 Word64 deriving (Typeable, Eq, Ord)
-- ^ A BSON ObjectID is a 12-byte value consisting of a 4-byte timestamp (seconds since epoch), a 3-byte machine id, a 2-byte process id, and a 3-byte counter. Note that the timestamp and counter fields must be stored big endian unlike the rest of BSON. This is because they are compared byte-by-byte and we want to ensure a mostly increasing order.

instance Show ObjectId where
showsPrec d (Oid x y) = showParen (d > 10) $ showString "Oid " . showHex x . showChar ' ' . showHex y

timestamp :: ObjectId -> UTCTime
timestamp (Oid time _) = posixSecondsToUTCTime (fromIntegral time)

Expand Down

0 comments on commit 673ed98

Please sign in to comment.