DataBinary's subtype ByteArray alone has an extra length
ByteArray has the extra length, aparently as a historical artifact, requiring it to be special cased. Thanks to Mathias Stearn for pointing this out!
This commit is contained in:
parent
697c370dea
commit
8e035fded4
1 changed files with 11 additions and 5 deletions
|
@ -156,11 +156,17 @@ getVal DataArray = do
|
||||||
getNull
|
getNull
|
||||||
return (fromIntegral bytes, BsonArray arr)
|
return (fromIntegral bytes, BsonArray arr)
|
||||||
getVal DataBinary = do
|
getVal DataBinary = do
|
||||||
skip 4
|
len1 <- getI32
|
||||||
st <- getI8
|
st <- getI8
|
||||||
len2 <- getI32
|
(len, hdrLen) <- if toBinarySubType st == BSTByteArray
|
||||||
bs <- getLazyByteString $ fromIntegral len2
|
then do
|
||||||
return (4 + 1 + 4 + fromIntegral len2, BsonBinary (toBinarySubType st) bs)
|
len2 <- getI32
|
||||||
|
assert (len1 - 4 == len2) $ return ()
|
||||||
|
return (len2, 4 + 1 + 4)
|
||||||
|
else return (len1, 4 + 1)
|
||||||
|
bs <- getLazyByteString $ fromIntegral len
|
||||||
|
return (hdrLen + fromIntegral len, BsonBinary (toBinarySubType st) bs)
|
||||||
|
|
||||||
getVal DataUndefined = return (1, BsonUndefined)
|
getVal DataUndefined = return (1, BsonUndefined)
|
||||||
getVal DataOid = liftM ((,) 12 . BsonObjectId) $ getLazyByteString 12
|
getVal DataOid = liftM ((,) 12 . BsonObjectId) $ getLazyByteString 12
|
||||||
getVal DataBoolean = liftM ((,) (1::Integer) . BsonBool . (/= (0::Int))) getI8
|
getVal DataBoolean = liftM ((,) (1::Integer) . BsonBool . (/= (0::Int))) getI8
|
||||||
|
|
Loading…
Reference in a new issue