Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Interoperability with libbson #2

Open
lucianoiam opened this issue Jan 13, 2023 · 0 comments
Open

Interoperability with libbson #2

lucianoiam opened this issue Jan 13, 2023 · 0 comments

Comments

@lucianoiam
Copy link

lucianoiam commented Jan 13, 2023

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:

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)
>> 2

When string length == string byte count libbson correctly deserializes documents, otherwise deserialization fails due to a validation check.

Does this make sense?

lucianoiam added a commit to lucianoiam/dpfwebui that referenced this issue Jan 14, 2023
- Optional feature, only enabled for example telecomp.

- Switch to MongoDB js-bson library https://github.com/mongodb/js-bson

- Previous library is broken dptole/js-bson#2

- Since bson.min.js is quite big (~100KiB) it is handled separately,
ie. not embedded into dpf.js

- TODO: add a binary data type to JSValue that fallbacks to Base64
when the protocol is JSON based.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant