TooTallNate / ref-struct

Create ABI-compliant "struct" instances on top of Buffers

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

BSON compatibility

pfgarvin opened this issue · comments

Howdy,

An error was observed While trying out a module (happens to be the pigsty-mongodb) which requires ref-struct and indirectly requires another module named bson.

The actual error thrown by the bson module is:

[Error: key ref.buffer must not contain '.']

I think a similar error could occur with anyone using both the ref-struct module and the bson module. It turns out that BSON documents do not allow dots(.) in their field names. However, ref-struct uses a field name of ref.buffer

This is NOT a bug in ref-struct. Forking ref-struct or some other workaround is possible to meet this specific requriement. However, if you would consider an enhancement of changing ref.buffer to ref_buffer, then the ref-struct module would be compatible for use with the bson module. There might be other field names within ref-struct with the same characteristic - I haven't checked. But the field name currently being bumped into is ref.buffer.

Thanks,
Pete

So, are you serializing Struct instances as BSON? I chose the ref.buffer name specifically because it's an invalid struct property name in C. Perhaps you can call .toObject()/.toJSON() on the struct instance before handing it off to the BSON library?

Understood - that will work. Thanks for clarifying.