Skip to content

Commit

Permalink
Updated 'getDocument' implementation to match BSON spec -- closes mon…
Browse files Browse the repository at this point in the history
…godb-haskell#4

  A BSON document *must* end with a trailing '\x00', which was ignored
  by the previous 'getDocument' implementation; see http://bsonspec.org
  for details.

  Patch provided by @savask
  • Loading branch information
superbobry committed Jul 11, 2012
1 parent 226133e commit fc08ba5
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
dist/
dist
cabal-dev
7 changes: 3 additions & 4 deletions Data/Bson/Binary.hs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import Control.Applicative ((<$>), (<*>))
import Control.Monad (when)
import Data.Binary.Get (Get, runGet, getWord8, getWord32be, getWord64be,
getWord32le, getWord64le, getLazyByteStringNul,
getLazyByteString, getByteString, isEmpty)
getLazyByteString, getByteString, lookAhead)
import Data.Binary.Put (Put, runPut, putWord8, putWord32le, putWord64le,
putWord32be, putWord64be, putLazyByteString,
putByteString)
Expand Down Expand Up @@ -148,12 +148,11 @@ putDocument es = let b = runPut (mapM_ putField es) in do

getDocument :: Get Document
getDocument = do
len <- subtract 5 <$> getInt32
len <- subtract 4 <$> getInt32
b <- getLazyByteString (fromIntegral len)
getWord8
return (runGet getFields b)
where
getFields = isEmpty >>= \done -> if done
getFields = lookAhead getWord8 >>= \done -> if done == 0
then return []
else (:) <$> getField <*> getFields

Expand Down

0 comments on commit fc08ba5

Please sign in to comment.