create and use putNothing instead of using flush as a no-op
This commit is contained in:
parent
41b9c8d139
commit
d1cccd075d
2 changed files with 8 additions and 5 deletions
|
@ -181,20 +181,20 @@ putVal (BSBinary t bs)= do putI32 $ fromIntegral $ 4 + L.length bs
|
|||
putI8 $ fromBinarySubType t
|
||||
putI32 $ fromIntegral $ L.length bs
|
||||
putLazyByteString bs
|
||||
putVal BSUndefined = flush
|
||||
putVal BSUndefined = putNothing
|
||||
putVal (BSObjectId o) = putLazyByteString o
|
||||
putVal (BSBool False) = putI8 0
|
||||
putVal (BSBool True) = putI8 1
|
||||
putVal (BSDate pt) = putI64 $ round $ 1000 * realToFrac pt
|
||||
putVal BSNull = flush
|
||||
putVal BSNull = putNothing
|
||||
putVal (BSRegex r opt)= do putS r
|
||||
putByteString $ pack $ List.sort opt
|
||||
putNull
|
||||
putVal (BSSymbol s) = putI32 (fromIntegral $ 1 + L8.length s) >> putS s
|
||||
putVal (BSInt32 i) = putI32 i
|
||||
putVal (BSInt64 i) = putI64 i
|
||||
putVal BSMinKey = flush
|
||||
putVal BSMaxKey = flush
|
||||
putVal BSMinKey = putNothing
|
||||
putVal BSMaxKey = putNothing
|
||||
|
||||
putObj obj = putOutterObj bs
|
||||
where bs = runPut $ forM_ (Map.toList (fromBSONObject obj)) $ \(k, v) ->
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
module Database.MongoDB.Util
|
||||
(
|
||||
putI8, putI32, putI64, putNull, putS,
|
||||
putI8, putI32, putI64, putNothing, putNull, putS,
|
||||
getI8, getI32, getI64, getC, getS, getNull,
|
||||
)
|
||||
where
|
||||
|
@ -8,6 +8,7 @@ import Control.Monad
|
|||
import Data.Binary
|
||||
import Data.Binary.Get
|
||||
import Data.Binary.Put
|
||||
import Data.ByteString.Char8
|
||||
import qualified Data.ByteString.Lazy as L
|
||||
import qualified Data.ByteString.Lazy.UTF8 as L8
|
||||
import Data.Char (chr, ord)
|
||||
|
@ -36,6 +37,8 @@ putI32 = putWord32le . fromIntegral
|
|||
putI64 :: Int64 -> Put
|
||||
putI64 = putWord64le . fromIntegral
|
||||
|
||||
putNothing = putByteString $ pack ""
|
||||
|
||||
putNull = putI8 0
|
||||
|
||||
putS :: L8.ByteString -> Put
|
||||
|
|
Loading…
Reference in a new issue