util: type putI8 like the other putI* functions

This commit is contained in:
Scott R. Parish 2010-03-12 23:03:37 -06:00
parent 8e035fded4
commit ab3b73b9ac
2 changed files with 8 additions and 8 deletions

View file

@ -114,10 +114,10 @@ toDataType (-1) = DataMinKey
toDataType 127 = DataMaxKey toDataType 127 = DataMaxKey
toDataType d = toEnum d toDataType d = toEnum d
fromDataType :: DataType -> Int fromDataType :: DataType -> Int8
fromDataType DataMinKey = - 1 fromDataType DataMinKey = - 1
fromDataType DataMaxKey = 127 fromDataType DataMaxKey = 127
fromDataType d = fromEnum d fromDataType d = fromIntegral $ fromEnum d
data BinarySubType = data BinarySubType =
BSTUNDEFINED1 | BSTUNDEFINED1 |
@ -133,9 +133,9 @@ toBinarySubType :: Int -> BinarySubType
toBinarySubType 0x80 = BSTUserDefined toBinarySubType 0x80 = BSTUserDefined
toBinarySubType d = toEnum d toBinarySubType d = toEnum d
fromBinarySubType :: BinarySubType -> Int fromBinarySubType :: BinarySubType -> Int8
fromBinarySubType BSTUserDefined = 0x80 fromBinarySubType BSTUserDefined = 0x80
fromBinarySubType d = fromEnum d fromBinarySubType d = fromIntegral $ fromEnum d
getBsonDoc :: Get BsonDoc getBsonDoc :: Get BsonDoc
getBsonDoc = liftM snd getDoc getBsonDoc = liftM snd getDoc
@ -261,8 +261,8 @@ putVal (BsonBinary t bs)= do putI32 $ fromIntegral $ 4 + L.length bs
putLazyByteString bs putLazyByteString bs
putVal BsonUndefined = putNothing putVal BsonUndefined = putNothing
putVal (BsonObjectId o) = putLazyByteString o putVal (BsonObjectId o) = putLazyByteString o
putVal (BsonBool False) = putI8 (0::Int) putVal (BsonBool False) = putI8 0
putVal (BsonBool True) = putI8 (1::Int) putVal (BsonBool True) = putI8 1
putVal (BsonDate pt) = putI64 $ round $ 1000 * (realToFrac pt :: Double) putVal (BsonDate pt) = putI64 $ round $ 1000 * (realToFrac pt :: Double)
putVal BsonNull = putNothing putVal BsonNull = putNothing
putVal (BsonRegex r opt)= do putS r putVal (BsonRegex r opt)= do putS r

View file

@ -58,7 +58,7 @@ getS = getLazyByteStringNul >>= \s -> return (fromIntegral $ L.length s + 1, s)
getNull :: Get () getNull :: Get ()
getNull = do {c <- getC; assert (c == '\0') $ return ()} getNull = do {c <- getC; assert (c == '\0') $ return ()}
putI8 :: (Integral i) => i -> Put putI8 :: Int8 -> Put
putI8 = putWord8 . fromIntegral putI8 = putWord8 . fromIntegral
putI32 :: Int32 -> Put putI32 :: Int32 -> Put
@ -71,7 +71,7 @@ putNothing :: Put
putNothing = putByteString $ pack "" putNothing = putByteString $ pack ""
putNull :: Put putNull :: Put
putNull = putI8 (0::Int) putNull = putI8 0
putS :: L8.ByteString -> Put putS :: L8.ByteString -> Put
putS s = putLazyByteString s >> putNull putS s = putLazyByteString s >> putNull