node-dbus-next icon indicating copy to clipboard operation
node-dbus-next copied to clipboard

Unable to pass numeric values as an object key.

Open LIvvieLynn opened this issue 4 years ago • 4 comments

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

LIvvieLynn avatar Jun 23 '21 04:06 LIvvieLynn

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

Intellithings avatar Jul 26 '21 09:07 Intellithings

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.

acrisci avatar Jul 26 '21 12:07 acrisci

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.

Intellithings avatar Jul 26 '21 13:07 Intellithings

Yeah that would be good.

acrisci avatar Jul 26 '21 13:07 acrisci