Skip to content

Commit 89096dc

Browse files
committed
Make anything falsy treat void as a mising field
1 parent 75b0b04 commit 89096dc

3 files changed

Lines changed: 31 additions & 11 deletions

File tree

dist/flybrix-serialization.js

Lines changed: 15 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/flybrix-serialization.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/handlers.js

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,19 @@
99
return [];
1010
};
1111

12-
function Handler(descriptor, byteCount, empty, encode, decode, fullMask, maskArray) {
12+
var defaultIsNull = function (val) {
13+
return val === null || val === undefined;
14+
};
15+
16+
function Handler(descriptor, byteCount, empty, encode, decode, fullMask, maskArray, isNull) {
1317
this.descriptor = descriptor;
1418
this.byteCount = byteCount;
1519
this.encode = encode;
1620
this.decode = decode;
1721
this.empty = empty;
1822
this.fullMask = fullMask || nullMask;
1923
this.maskArray = maskArray || nullMaskArray;
24+
this.isNull = isNull || defaultIsNull;
2025
}
2126

2227
var handlers = {};
@@ -89,6 +94,11 @@
8994
},
9095
function () {
9196
return true;
97+
},
98+
null,
99+
null,
100+
function (val) {
101+
return !val;
92102
});
93103
handlers.void.isBasic = true;
94104

@@ -236,12 +246,12 @@
236246
if (masks && ('MASK' in masks)) {
237247
extraMask = masks.MASK;
238248
}
239-
children.forEach(function (_, idx) {
249+
children.forEach(function (child, idx) {
240250
var value = data[idx];
241251
if (extraMask && !extraMask[idx]) {
242252
return;
243253
}
244-
if (value !== null && value !== undefined) {
254+
if (!child.isNull(value)) {
245255
mask[Math.floor(idx / 8)] |= 1 << (idx % 8);
246256
}
247257
});
@@ -364,7 +374,7 @@
364374
if (extraMask && !extraMask[child.key]) {
365375
return;
366376
}
367-
if (value !== null && value !== undefined) {
377+
if (!child.handler.isNull(value)) {
368378
mask[Math.floor(idx / 8)] |= 1 << (idx % 8);
369379
}
370380
});

0 commit comments

Comments
 (0)