From d1cccd075dc00dcbbed739cdaa5fa85a249b0b2d Mon Sep 17 00:00:00 2001 From: "Scott R. Parish" Date: Tue, 12 Jan 2010 19:59:52 -0600 Subject: [PATCH] create and use putNothing instead of using flush as a no-op --- Database/MongoDB/BSON.hs | 8 ++++---- Database/MongoDB/Util.hs | 5 ++++- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/Database/MongoDB/BSON.hs b/Database/MongoDB/BSON.hs index 14c8dfd..83cbf43 100644 --- a/Database/MongoDB/BSON.hs +++ b/Database/MongoDB/BSON.hs @@ -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) -> diff --git a/Database/MongoDB/Util.hs b/Database/MongoDB/Util.hs index e9b64df..b57809d 100644 --- a/Database/MongoDB/Util.hs +++ b/Database/MongoDB/Util.hs @@ -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