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

Allow non-string dict key types #115

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/bus.js
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@ class MessageBus extends EventEmitter {
try {
await this._addMatch(nameOwnerMatchRule);
} catch (error) {
this.emit("error", error);
this.emit('error', error);
return;
}

Expand Down
19 changes: 18 additions & 1 deletion lib/marshall-compat.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,25 @@ function jsToMarshalFmt (signature, value) {
if (value.constructor !== Object) {
throw new Error(`expecting an object for signature '${signatureStr}' (got ${typeof value})`);
}
for (const k of Object.keys(value)) {
for (let k of Object.keys(value)) {
const v = value[k];
// js always converts keys of objects to string
// convert them back if the signature requires it
keyType = signature.child[0]?.child[0]?.type;
QuadratClown marked this conversation as resolved.
Show resolved Hide resolved
if (['y', 'n', 'q', 'i', 'x', 't'].includes(keyType)) {
// key should be integer
try {
k = parseInt(k);
} catch (e) {
throw new Error(`error parsing dict key for signature '${signatureStr}' (key: ${key})`);
}
} else if (['b'].includes(keyType)) {
// key should be boolean
if (!(k === 'true' || k === 'false')) {
throw new Error(`error parsing dict key for signature '${signatureStr}' (key: ${key})`);
}
k = k === 'true';
}
if (v.constructor === Variant) {
result.push([k, jsToMarshalFmt(v.signature, v.value)]);
} else {
Expand Down
Loading