dbusjs / node-dbus-next

🚌 The next great dbus library for node
https://www.npmjs.com/package/dbus-next
155 stars 52 forks source link

Unable to pass numeric values as an object key. #79

Open LIvvieLynn opened 3 years ago

LIvvieLynn commented 3 years ago

There appears to currently be no way to use a numeric key for a dict variant.

I'm trying to add BlueZ manufacture data which requires the signature "a{qay}". E.g. {0xFFFF, [0x70, 0x74]}

When attempting to pass a variant of {0xFFFF, [0x70, 0x74]}, dbus-next converts it to { '65535': [ 112, 116 ] }. Where Object.keys converts 0xFFF to a string '65535'. Is there anyway to allow non-string keys for dict entries? (Possibly parsing strings for numeric signature types or allowing arrays in addition to objects. e.g. [[Key,Value],[Key,[Key,Value]]] for {Key:Value, Key:{Key:Value}}.)

Thanks

Intellithings commented 2 years ago

I'm having the same problem. In fact, the problem is coming from JavaScript converting object numeric keys to string.

acrisci commented 2 years ago

This shouldn't be a limitation of the library since marshalling and unmarshalling values always requires a signature that will indicate the keys are numeric. So the solution would be to parse strings for numeric signature types like you said. It shouldn't be a hard fix. Any help on this would be appreciated.

Intellithings commented 2 years ago

well, I see marshallers.js has checkInteger if (typeof data !== 'number') we can try to parse int it instead of throwing exception. perhaps return something back. in the 'q' switch case, we should convert data to int in case the check function fail.

acrisci commented 2 years ago

Yeah that would be good.