-
Notifications
You must be signed in to change notification settings - Fork 3
Open
Description
Round-trip encoding/decoding with js-bson works great, but I am having a rough time trying to exchange data with a client written in C using libbson from the MongoDB C driver.
According to the spec the first 4 bytes in a BSON document must be interpreted as an int32 with the total number of bytes comprising the document.
js-bson writes this header by taking the serialized string length:
Line 664 in 77d3b53
| return readAsInt32LE( bson.length + 5 ) + bson + '\x00'; |
The string's length property value is not necessarily equal to the number of bytes comprising the string:
console.log('\80\00'.length)
>> 3
console.log('\00\00'.length)
>> 2When string length == string byte count libbson correctly deserializes documents, otherwise deserialization fails due to a validation check.
Does this make sense?
Metadata
Metadata
Assignees
Labels
No labels