Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions Data/Bson/Binary.hs
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,12 @@ putCString x = do
putWord8 0

getCString :: Get Text
getCString = TE.decodeUtf8 . SC.concat . LC.toChunks <$> getLazyByteStringNul
getCString = do
b <- SC.concat . LC.toChunks <$> getLazyByteStringNul
case TE.decodeUtf8' b of
Left err ->
fail $ "Data.Bson.Binary.getCString: decodeUtf8 failed: " ++ show err
Right x -> return x

putString :: Text -> Put
putString x = let b = TE.encodeUtf8 x in do
Expand All @@ -152,7 +157,10 @@ getString = do
len <- subtract 1 <$> getInt32
b <- getByteString (fromIntegral len)
getWord8
return $ TE.decodeUtf8 b
case TE.decodeUtf8' b of
Left err ->
fail $ "Data.Bson.Binary.getString: decodeUtf8 failed: " ++ show err
Right x -> return x

putDocument :: Document -> Put
putDocument es = let b = runPut (mapM_ putField es) in do
Expand Down