Skip to content

Commit

Permalink
Receive Array (#1294)
Browse files Browse the repository at this point in the history
* array msg deserializer

* obj support
  • Loading branch information
dragazo authored Dec 11, 2024
1 parent caeca15 commit aa09c16
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions src/websockets.js
Original file line number Diff line number Diff line change
Expand Up @@ -501,6 +501,19 @@ WebSocketManager.prototype.deserializeMessage = function(message) {
return message.content;
};

function snapify(x) {
if (Array.isArray(x)) {
return new List(x.map(y => snapify(y)));
} else if (typeof(x) === 'object') {
const res = [];
for (const k in x) {
res.push(new List([k, snapify(x[k])]));
}
return new List(res);
} else {
return value;
}
}
WebSocketManager.prototype.deserializeData = function(dataList) {
var project,
model;
Expand All @@ -511,7 +524,9 @@ WebSocketManager.prototype.deserializeData = function(dataList) {
};

return dataList.map(function(value) {
if (value[0] === '<') {
value = snapify(value);

if (typeof(value) === 'string' && value[0] === '<') {
try {
console.log('Received serialized format:', value.length);
model = SnapActions.serializer.parse(value);
Expand All @@ -526,9 +541,9 @@ WebSocketManager.prototype.deserializeData = function(dataList) {
return SnapActions.serializer.loadValue(model);
} catch(e) { // must not have been XML
console.error('Could not deserialize!', e);
return value;
}
}

return value;
});
};
Expand Down

0 comments on commit aa09c16

Please sign in to comment.